• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Calc Element to sum repeatable rows acts odd with only 1 row

kdiamond

Member
I have a calc element that calulates the total from repeatable rows. Very odd thing is when there is only ONE row, it takes the amount entered on that row and it does a divide by 4. Example, if the row is 12, the calc total is 3. If the row is 24, the total displayed is 6. It works fine when there are >1 rows.

Here is the calc:

$sold = FabrikWorker::JSONtoData($data['pet_event_report_products___format_sold_raw'], true);
$total= implode(',', $sold);
return array_sum(str_split($total));


On further testing it's not always /4. I'm not sure what it is. Some small number are not affected.
 

Attachments

  • Capture.JPG
    Capture.JPG
    65.8 KB · Views: 30
Last edited:
Not sure why you are doing an implode() and then a str_split(). The return from JSONtoData() for a repeat element should already be an array of values. And str_split() will split on individual characters (unless you give it a length to split on), so the number (say) 24 will get split into an array of [2,4], so yes, the sum is 6.

You should just be able to do ...

Code:
$sold = FabrikWorker::JSONtoData($data['pet_event_report_products___format_sold_raw'], true);
return array_sum($sold);

-- hugh
 
That got it - thank you. I think I did that because in testing the result was coming back and a comma string, 2,5,7 as example. Clearly it wasn't needed.
 
I think it would only be comma separated if you used a placeholder.

And just for future reference, even if it was comma separated, you wouldn't need the implode or str_split. Just explode() the string into an array, then array_sum() that.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top