Categories > TinyButStrong general >

issue with [fld;frm=000... in tinybutstrong_class_php5.php

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Bruce Decker
Date: 2013-11-26
Time: 23:49

issue with [fld;frm=000... in tinybutstrong_class_php5.php

Hello:
I am using 3.5.2 base with Joomla plug-in and encountered an issue where a tag reference in this format:

[myblock.myfield;fmt='$ 0,000.00']

In my example, I was passing the value 123.45 into myblock.myfield

Was not working.  I tried a variety of formats and re-read docs but finally started to debug the class to see where I was going wrong.  I found the numeric formatter in tinybutstrong_class_php5.php and specifically, the function meth_Misc_Format.

upon debugging, I think that there may be an error in the code around line 5765 in the case 'num' logic (code below compressed):

    case 'num' :
        // NUMERIC
        if ($CheckNumeric) {
            if (is_numeric($Value)) {
                if (is_string($Value)) $Value = 0.0 + $Value;
            } else {

It appears that the instruction on the 4th line of the above snippett (if (is_numeric($Value)) { is evaluating to boolean FALSE.

To remedy, I modified this code as:

    case 'num' :
        // NUMERIC
     
               $Value = (string)$Value;// <--- my added instruction to cast $Value as a string

        if ($CheckNumeric) {
            if (is_numeric($Value)) {
                if (is_string($Value)) $Value = 0.0 + $Value;
            } else {

With this modification, the passed valued of 123.45 does apply the conversion as (I) expected.

Perhaps there is a more proper fix and perhaps my fix will introduce other errors but I wanted to pass this along in case anyone else is experiencing issues with decimal values and the frm param.

Last point.  I downloaded and checked the source for the latest joomla plug-in which is based on tbs 3.7 and this section of code appears to be unchanged from the version I made.  However, due to time constraints, I didn't have time to setup a test site to try-out the new version of the Joomla plug-in to see if it contains another (better) fix that resolves this issue.  I will try to get to that test in the coming weeks unless someone replies here indicating that I have, indeed, uncovered a bug.
By: Bruce Decker
Date: 2013-11-27
Time: 04:36

Re: issue with [fld;frm=000... in tinybutstrong_class_php5.php

Adding a bit more, the numeric value I was loading into a TBS mergeblock array came from a simpleXML parse like this>

$xml_object = simplexml_load_string($row->doc_xml);
foreach ( $xml_object->bpi_edoc_document->hdr as $xml_hdr) {
    // next, we'll iterate through each line in the 'invlines' section
   $hdr[] = array(         
       'stmtNo'         => $xml_hdr->stmtNo,
       'stmtDate'      => strtotime($xml_hdr->stmtDate),
       'acctNo'         => $xml_hdr->acctNo,
       'ttlDue'         => $xml_hdr->ttlDue)
...
     $bpiedoc->MergeBlock('hdr',$hdr) ;

I'm wondering if instead placing the raw value of $xml_hdr->ttlDue into my $hdr['ttlDue'] array, if I need to cast the value for TBS maybe like:
       'ttlDue'         => (string)$xml_hdr->ttlDue,

So that when the value arrives into the template and referenced as: [hdr.ttlDue] that it's already a string?  The only oddity I've seen when casting as a string in the class library mod above is that sometimes it throws a very large integer value as if we have typecasting issue.

So, given the above example as the source of my data and assuming that the xml node ttdDue looks like this <ttlDue>123.45</ttlDue>, do you think it should be up to my script (code fragement in this reply) to cast the value and if so, what would be the appropriate cast so that the [hdr.ttlDue] tbs tag plays nicely with the fmt param?