Search code examples
phpforeachnested-loopsodt

Nested foreach in odt Templates


I am reworking a time management tool which creates Reports. The data is written to an .odt file. The Data looks something like this:

Projects Array holds a Users Array. Users Array holds a days Array, days Array holds a times Array.

I have a report that outputs

ProjectName

Date User time comment
$time['date'] $user['name'] $time['sum'] foreach($time as $t){$t['comment']}

This works via multiple foreach loops in an .odt table

{foreach($projects as $project):}
    {$project['name']}
    {foreach($aProject['users'] as $aUser):}
        {foreach( $aUser['days'] as $aDay ):}
            {$aDay['date']}  | {$aUser['name']} |{$aDay['sum']} h | 
            {foreach($aDay['comment'] as $comment):}
                {$comment['comment']}
            {endforeach}    
        {endforeach}
    {endforeach}
{endforeach}

The Output looks something like this: ProjectName

Date User time comment
Day1 User1 sum of times comment from each time entry on Day1
Day2 User1 sum of times comment from each time entry on Day2
Day3 User1 sum of times comment from each time entry on Day3
Day1 User2 sum of times comment from each time entry on Day1

I would like the Output to look like this:

ProjectName

Date User time comment
Day1 User1 sum of times comment from each time entry on Day1
Day1 User2 sum of times comment from each time entry on Day1
Day2 User1 sum of times comment from each time entry on Day2
Day2 User2 sum of times comment from each time entry on Day2

Is there an easy way to accomplish this inside the .odt foreach loops? I would rather avoid reworking the whole data setup for this specific report.


Solution

  • I accomplished it by adding an additional subarray which holds the needed data on basis of date. In there i had a WokingUsers array for each Day, with the corresponding times.