migxLoopCollection output depending on DynamicDropdownTV

I’m working on a website for a sports club and they have lots of different categories and teams:

* Category 1
  * Team 1
   - Reports
  * Team 2
    - Reports

* Category 2
  * Sub-Category 1
    * Team 1
      - Reports
    * Team 2
      - Reports

Every team has a Reports resource where match reports should be displayed. In order so users don’t have to navigate through the resource tree, I have created a custom package with MIGXdb to outsource all the reports into their own menu. Within that package, I let the user create reports and select the Category, Sub-Category and Team for it through resource related DynamicDropdownTVs.

Now, ideally I would like to have just one template to display the reports for the currently visited Reports-resource of any Team. I’ve started using [[migxLoopCollection]] to get those reports to the front-end and I guess I need to specify the &where property in that call to get only the reports for the selected Team. I’m a little stuck here though.

If I’m not mistaken &where needs JSON format, which I’m not yet too familiar with. How would I only get the reports shown, which have been selected for that Team while creating it?

If there is any other, easier solution to my process, I would love to hear it as well!
Thanks alot for any help!

1 Like

the reports are in a custom-table or are this resources, too?
Then, how did you store the team-info into the reports?

1 Like

The reports are in the custom table, correct. (I followed this video and applied it to my needs.) And my thought was, to let the user select the Team to which the report belongs through the DDDTVs and fetch that field later in the templates [[migxLoopCollection]] call to only show the reports for the currently selected Team.

1 Like

sounds like you have a field with the team resource ID, then, right?

lets say the name of this field is team_id, then you would filter with:

&where=`{"team_id":"[[*parent]]"}` at the report - resource of each team

2 Likes

Yes and No, my issue is the difference in levels here, because some Team container pages are at level 2 and others at level 3.

I have the 3 DDDTvs (resource_level1, resource_level2, resource_level3) and in some reports the needed Team resource will be in resource_level2 and in others in resource_level3. So maybe is there a way to check if resource_level3 is empty and if so use resource_level2?

Theoretically speaking with modifiers I would need [[resource_level3:default='resource_level2']]

Is there something similar in JSON?

I really would try to store the team ID, where the report belongs to, into one specific field named team_id, independent of the level. That would simplify things alot.

1 Like

The reason I’m doing the level thing is, so users can easily find and select the desired Team. In total there are atleast 5 Categories with each up to 4 Sub-Categories, which contain up to 7 Teams atm. The thing is, the Teams under Sub-Category 1 are called exactly the same as under Sub-Category 2 (e.g. A-Jugend, B-Jugend, etc.).

Is there any better alternative to get the team names listed in a userfriendly way?

1 Like

you can create another field with name team_id and have an aftersave - hooksnippet like that:

<?php
$object = & $scriptProperties['object'];

$team_template_id = 1;//change this to the template - id of your Team - Resources

$ddd2 = $object->get('resource_level2');
$ddd3 = $object->get('resource_level3');

$object->set('team_id',0);//reset team_id to 0, before checking the dynamicdropdowns

if (!empty($ddd3) && $res = $modx->getObject('modResource',array('id'=>$ddd3,'template'=>$team_template_id))){
    //check, if level3 is selected and if it is a Team - Resource
	$object->set('team_id',$ddd3);
} elseif (!empty($ddd2) && $res = $modx->getObject('modResource',array('id'=>$ddd2,'template'=>$team_template_id))){
    // otherwise check, if level2 is selected and if it is a Team - Resource
	$object->set('team_id',$ddd2);
}
$object->save();

then you would allways have the team_id within that field, no matter at which level (2 or 3) the team-resource is

2 Likes

That works great! Thank you so much @bruno17, you helped me out a ton and MIGX is just awesome!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.