Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE » How To » Format data in a message
Format data in a message [message #2024] Wed, 29 April 2009 12:43 Go to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
Tony,

I have placed some code in the _cm_post_insertRecord method of a class which generates different $this->messages[] depending on the outcome of additional processing following an insert.

The messages include certain fields from the database, including dates. However, I don't seem able to format the dates in the message, or use lookup values. I think the formatting is removed for the DB operations. Is it possible to apply formatting again from within this, and other similar, methods?

Graham
Re: Format data in a message [message #2027 is a reply to message #2024] Wed, 29 April 2009 15:15 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2347
Registered: April 2006
Location: Surrey, UK
Senior Member
Have you tried using the getLanguageText() function?

Re: Format data in a message [message #2028 is a reply to message #2024] Wed, 29 April 2009 17:24 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
Yes, I'm using that already. But I have some strings that are inserted into the text as %1\$s and %2\$s. It is these strings that are not being formatted. (one is a lookup description, and the other is a date).
Re: Format data in a message [message #2029 is a reply to message #2028] Wed, 29 April 2009 18:04 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2347
Registered: April 2006
Location: Surrey, UK
Senior Member
If any arguments passed to getLanguageText need to be formatted then it must be done in your code beforehand. It is not possible for the function to format the data as it does not know what type it is - it is always treated as a string.

Re: Format data in a message [message #2030 is a reply to message #2024] Wed, 29 April 2009 18:55 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
This was my original question really. Because I am within the _cm_post_insertRecord method I'm not sure on the most appropriate way to perform the formatting. For example, the date is showing in the format it will be written to the database 'YYYY-MM-DD'. Normally when I output the date the framework formats according to the date type configured. I'm not sure what functions I should use to perform this formatting 'manually'. Similarly for the field that has an optionlist in the fieldspec - within _cm_post_insertRecord it is formatted as the id and not the corresponding description from the optionlist.

I'm assuming this is because the data at this point has been 'unformatted' for writing to the database.

Hope that explains the question better.

Graham
Re: Format data in a message [message #2031 is a reply to message #2030] Wed, 29 April 2009 19:32 Go to previous message
AJM is currently offline  AJM
Messages: 2347
Registered: April 2006
Location: Surrey, UK
Senior Member
Take a look at the formatData() method inside 'std.table.class.inc' for examples of the standard formatting code for dates and numbers. The values for option lists are manipulated in the XSL transformation, so there is no PHP code. You will have to use something like:
$string = $this->lookup_data['optionlist']['key'];


Previous Topic: Dynamic Task Selection
Next Topic: column heading sorts
Goto Forum:
  


Current Time: Thu Apr 25 18:04:08 EDT 2024

Total time taken to generate the page: 0.00986 seconds