Nested MIGXdb @EVAL

Hey everyone, looking for a little help on something that has gotten me stumped. I am coming back to an old bit of code that @bruno17 helped me with a long time ago and I am attempting to make it more functional.

The old bit of code lived here - GitHub - Bruno17/sriagenda: manage agendas

Since then I have made a number of adjustments. The main thing I wanted to do was to nest the speakers and locations into the agenda like the sessions themselves so that when I create a new agenda, it does not pull from a list of every speaker and every location, they are unique to the agenda. Everything seems to be working with my schema which is below, my main issue comes in when I have the Location listbox or Speaker listbox and I need to figure out what to do with my input option values @EVAL.

<model package="modx-conference" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
	  
	<object class="agenda" table="agenda" extends="xPDOSimpleObject">
		<field key="conf_year" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="conf_theme" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="conf_start" dbtype="datetime" phptype="datetime" null="false"/>
		<field key="conf_end" dbtype="datetime" phptype="datetime" null="false"/>
		<field key="conf_status" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="createdon" dbtype="datetime" phptype="datetime" null="true"/>
		<field key="deleted" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0"/>
		<field key="published" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="1"/>
	
		<composite alias="Sessions" class="agenda_ses" local="id" foreign="agenda_id" cardinality="many" owner="local" />
		<composite alias="Speakers" class="agenda_spk" local="id" foreign="agenda_id" cardinality="many" owner="local" />
		<composite alias="Locations" class="agenda_loc" local="id" foreign="agenda_id" cardinality="many" owner="local" />
		 
	</object>
	  
	<object class="agenda_spk" table="agenda_spk" extends="xPDOSimpleObject">
		<field key="agenda_id" dbtype="int" phptype="integer" precision="10" null="false" default="" index="index" /> 
		<field key="spk_salutation" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="spk_fname" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="spk_mname" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="spk_lname" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="spk_suffix" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="spk_credentials" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="spk_affiliation1" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="spk_affiliation2" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="spk_title1" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="spk_title2" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="spk_twitter" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="spk_twitter2" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="spk_photo" dbtype="text" phptype="string" null="false" default=""/>
		<field key="spk_cphoto" dbtype="text" phptype="string" null="false" default=""/>
		<field key="spk_bio" dbtype="text" phptype="string" null="false" default=""/>
		<field key="spk_phone" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="spk_email" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="spk_type" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="spk_carousel" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="spk_notes" dbtype="text" phptype="string" null="false" default=""/>
		<field key="createdon" dbtype="datetime" phptype="datetime" null="true"/>
		<field key="deleted" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0"/>
		<field key="published" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="1"/>
		 
		<aggregate alias="Agenda" class="agenda" local="agenda_id" foreign="id" cardinality="one" owner="foreign" />
		<composite alias="Sessions" class="agenda_ses_spk" local="id" foreign="ses_id" cardinality="many" owner="local" />        
	</object>
	   
	<object class="agenda_loc" table="agenda_loc" extends="xPDOSimpleObject">
		<field key="agenda_id" dbtype="int" phptype="integer" precision="10" null="false" default="" index="index" /> 
		<field key="loc_building" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="loc_room" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="createdon" dbtype="datetime" phptype="datetime" null="true"/>
		<field key="deleted" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0"/>
		<field key="published" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="1"/>
		 
		<aggregate alias="Agenda" class="agenda" local="agenda_id" foreign="id" cardinality="one" owner="foreign" />
		<composite alias="Sessions" class="agenda_ses" local="id" foreign="loc_id" cardinality="many" owner="local" />
	</object>
	 
	<object class="agenda_ses" table="agenda_ses" extends="xPDOSimpleObject">
		<field key="agenda_id" dbtype="int" phptype="integer" precision="10" null="false" default="" index="index" />       
		<field key="loc_id" dbtype="int" phptype="integer" precision="10" null="false" default="" index="index" />
		<field key="ses_title" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="ses_number" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="ses_type" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="ses_track" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="ses_start" dbtype="datetime" phptype="datetime" null="false"/>
		<field key="ses_end" dbtype="datetime" phptype="datetime" null="false"/>
		<field key="ses_desc" dbtype="text" phptype="string" null="false" default=""/>
		<field key="ses_cecredit" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="speakers" dbtype="text" phptype="string" null="false" default=""/>
		<field key="ses_sponsor" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="ses_preslive" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="ses_pres1" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="ses_pres2" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="ses_pres3" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="ses_pres4" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="ses_pres5" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="ses_audio" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="ses_video" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="ses_notes" dbtype="text" phptype="string" null="false" default=""/>
		<field key="ses_linkoverride" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="createdon" dbtype="datetime" phptype="datetime" null="true"/>
		<field key="deleted" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0"/>
		<field key="ses_publish" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="published" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0"/>
		 
		<aggregate alias="Agenda" class="agenda" local="agenda_id" foreign="id" cardinality="one" owner="foreign" />
		<aggregate alias="Location" class="agenda_loc" local="loc_id" foreign="id" cardinality="one" owner="foreign" />            
		<composite alias="Speakers" class="agenda_ses_spk" local="id" foreign="ses_id" cardinality="many" owner="local" />
		   
	</object>
	 
	<object class="agenda_ses_spk" table="agenda_ses_spk" extends="xPDOSimpleObject">
		<field key="ses_id" dbtype="int" phptype="integer" precision="10" null="false" default="" index="index" />
		<field key="spk_id" dbtype="int" phptype="integer" precision="10" null="false" default="" index="index" />
		<field key="order" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="moderator" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
		<field key="notes" dbtype="text" phptype="string" null="false" default=""/>
		<field key="MIGX_id" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>  
		 
		<aggregate alias="Session" class="agenda_ses" local="ses_id" foreign="id" cardinality="one" owner="foreign" />
		<aggregate alias="Speaker" class="agenda_spk" local="spk_id" foreign="id" cardinality="one" owner="foreign" />        
	</object>   
	 
	 
	  
</model>

Current @Eval, It works with the “where” statement but only for the specific agenda #3 and I am wanting it to dynamically switch depending on which agenda I am editing.

@EVAL return 'Select Location==||' . $modx->runSnippet('migxLoopCollection',array('packageName'=>'modx-conference','classname'=>'agenda_loc','tpl'=>'@CODE:[[+loc_building]] [[+loc_room]]==[[+id]]','outputSeparator'=>'||','where'=>'{"agenda_id":"3"}'));

Thanks so much!

The id of the currently edited agenda is sended with the request, when generating the form modal.
So, you should be able to use that to build the query.

Cool! I thought it did, I am just having a hard time figuring out what I would put into the “where” statement to replace the “3”. I am sure it is super simple and I am just having I hard time figuring that out.

does something like that work?

'where'=>'{"agenda_id":"' . $_REQUEST['object_id'] . '"}'

you could also replace the @EVAL binding with a @CHUNK binding and create a chunk with the migxLoopCollections snippet-call. Then you could use fastField - tags or another snippet to get the REQUEST parameters.

Hmm, the code did not seem to work. I just get a blank option under the “Select Location” text.

do you see the object_id sended with the ajax request? Is it the right one?

It appears I am getting a 4 or a 5 for the object_id depending on which session I am editing instead of grabbing the id of the Agenda that the session and location belong to.

you are editing Sessions, not Agendas?
Then, you need to fetch the agenda_id of the current Session, if not provided with the request.

I switched over to using @CHUNK like you recommended, what would be the easiest way to fetch that?

you could try to use
[[migxGetObject? &classname=`agenda_ses` &id=`[[#post.object_id]]` &tpl=`@CODE:[[+agenda_id]]`]]

if you don’t have fastField installed, you could use a simple custom snippet to get the request params
But maybe the agenda_id is allready send with the co_id request param, isn’t it?

That worked perfectly! Thank you so much for all your help on this Bruno!

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.