My content looks like this:
page A
structure field
entry 1
...
page B
structure field
entry 1
entry 2
...
page C
structure field
entry 1
...
page D
structure field
entry 1
entry 2
entry 3
...
Every ‘entry’ has an ‘uploadDate’ field.
Now I want to extract all entries from all pages into a $allEntries collection, and sort them according to the following rules:
- each Page contributes one entry to $allEntries
- when all Pages contributed an entry, then each Page can contribute an entry again (unless it has no more entries)
- step 2 repeats until all Pages contributed all their entries
- within each iteration, entries need to be sorted by ‘uploadDate’ field, ‘asc’
(think of a playlist where artists shouldn’t repeat, until all artists have a song in it; then each artist can have a second song; then a third, etc)
Using the pseudocontent above the result would be something like:
PageA entry1, PageB entry1, PageC entry1, PageD entry1 ; PageB entry2, PageD entry2 ; PageD entry3
…I separated each iteration with semicolons. As said above, within each iteration, entries should be sorted by ‘uploadDate’ field ‘asc’.
I tried to solve this with loops, but using something like:
$allEntries = new Structure();
some kind of loop
$allEntries->add($entry);
I am getting that entries that are [0] in their respective structure fields, overwrite each other, getting only the last entry of each index among all Pages, such as, using the pseudoContent above:
PageD entry1 ; PageD entry2 ; PageD entry3
Adding the whole structure objects of each page to $allEntries $allEntries->add($myPage->myStructure())
works, but creates problems down the line when wanting to treat each entry separately and at the same level as the rest.
I am also not sure at which point should I call toStructure(), on each entry before adding it to $allEntries? on $allEntries after adding everything? on each structure field when adding it to $allEntries?
I am hitting roadblocks that I usually do not encounter when working with pages collections. I did not find too much documentation on the particularities of the Structure object either.
I would appreciate some directions, thanks