Jump to content

Same Find request with different results ?


celfred
 Share

Recommended Posts

Hello !

I have somehting I don't understand here... Here's my code :

$allPlayers = $pages->find("parent.name=players, team=$selectedTeam");
$allTrains = $allPlayers->find("template=event, task.name~=ut-action, refPage!='', date>=$startDate, date<=$endDate, sort=refPage, sort=date");
bd('$allTrains:'.$allTrains->count()); // DISPLAYS 0 ????
foreach($allPlayers as $p) {
  $allTrainings = $p->find("template=event, task.name~=ut-action, refPage!='', date>=$startDate, date<=$endDate, sort=refPage, sort=date");
  $test += $allTrainings->count();
}
bd('$test:'.$test); // DISPLAYS 883 pages (normal)
	

As you can read from my comments, I have no idea why my first $allTrains stays at 0 while the second request actually finds the corresponding pages. If someone could explain I'd appreciate a lot. I have been struggling with this for hours now... For your information, my pages having template 'event' are in a subtree like so :

- player 01

  - history-1

    - event 01

   - event 02

   - event ...

  - history-2

    - event 01

    - event ...

- player 02

  - history-1

    - event 01

   - event 02

   - event ...

  - history-2

    - event 01

    - event ...

- player ...

  - history-1

    - event 01

   - event 02

   - event ...

  - history-2

    - event 01

    - event ...

 

Thanks in advance. (sorry for my preceding 'tree' which doesn't look like much. I need to find a way to output this better ? )

Edited by celfred
Code was on one line.
Link to comment
Share on other sites

I think I am not wrong saying that actually its not the same request.  On the first time you are calling find() on a PageArray and in the second time, find() on a Page object.

 

1 hour ago, celfred said:

$allPlayers = $pages->find("parent.name=players, team=$selectedTeam");

$allPlayers is now a PageArray and contain only pages with the ~history~ template.

When you call find() on a PageArray, you are searching for pages matching your selector that are actually in the PageArray (their children are not in this array!) and that why you get a result of 0 page found.

Try to call $allPlayers->children("template=event") on the PageArray to get an imploded IDs string of all the children of the pages that are in the PageArray.

 

1 hour ago, celfred said:

$allTrainings = $p->find("template=event, task.name~=ut-action, refPage!='', date>=$startDate, date<=$endDate, sort=refPage, sort=date");

Here you are calling find() on a Page object. When you call find() on a Page object, you are searching Pages anywhere below this page object (children, grandchildren, etc.) that are matching the selector.

 

  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...

Hey,

Sorry to come back on this, but I'm still struggling...

Why is this working as expected ?

$notTeacherActions = $pages->find("template=task, owner.singleTeacher=$user"); // Returns 2 pages having the $user in the owner repeater singleTeacher field

Whereas this is not :

$notTeacherActions = $pages->find("template=task, owner.singleTeacher!=$user"); // Returns nothing where it should return all tasks NOT having this particular user in the singleTeacher owner repeater ? 

I have a feeling this has to do with my misunderstanding in the previous posts... So I continue here ?

By the way, still in this issue, I'm stuck with :

$globalActions = $pages->get("name=tasks")->children(); // I have 62 tasks pages
$adminActions = $globalActions->find("adminOnly=1"); // I have 10 adminActions
$allActions = $globalActions->find("adminOnly=0"); // I have 45 non admin (available to the logged-in user
bd($allActions->count()); // This shows me the 45

// The following are my tests to understand... Which I don't :(
// First tests from $pages
$teacherActions = $pages->get("name=tasks")->children("owner.singleTeacher=$user"); // This returns 2
$notTeacherActions = $pages->find("template=task, owner.singleTeacher!=$user"); // This returns nothing...
$notTeacherActions = $pages->get("name=tasks")->children("adminOnly=0")->not("owner.singleTeacher=$user")->sort("category.title"); // This actually returns 45 ($allActions, including the 2 returned in $teacherActions...)
bd('from $pages:'.$teacherActions->count().'/'.$notTeacherActions->count()); // I get 2 and 45

// Second test from $allActions
// THIS SEEMS LINKED TO MY ORIGINAL REQUEST (AND I'M STILL LOST !)
$teacherActions = $allActions->find("owner.singleTeacher=$user");
$notTeacherActions = $allActions->not("owner.singleTeacher=$user")->sort("category.title");
bd('from $allActions:'.$teacherActions->count().'/'.$notTeacherActions->count()); // Returns 0 and 45

As you can see, I still have a long way to go tu understand all this... Sorry if I'm being hard to follow, but I am indeed confused on this issue...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...