We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6949 ☆ A M B ☆
    • 19 Posts
    Hi,

    I've been banging my head against the wall for a few days trying to solve this problem and I just can't find the answer. Here's what I'm trying to do:

    I'm building a conference website. I have a resource template named "Speaker", and a resource template named "Session". The session template has a TV named "session_speaker" that contains the resource id for the speaker.

    On the session resource template, it's easy enough to list all the speakers. However, I'm stuck on the speaker resource template as to how to display the sessions that that speaker is speaking at.

    I've looked at the getResources code as it appears to do the same thing as well as a bunch of XPDO topics, but I just don't think I have the database knowledge to make that leap into implementing this myself. If I could go back and take that databases class in uni instead of simulations, I probably would do so (simulations are cool and all, but...).

    Here is as far as I've got (this doesn't work, but I have to at least show something here):

    	$c = $modx->newQuery('modResource');
    	$c->innerJoin('modResource','res',array("modTemplateVarResource.contentid = res.id"));
    	$c->leftJoin('modTemplateVar', 'tvDefault', array(
    		"tvDefault.name" => ''
    	));
    	$c->leftJoin('modTemplateVarResource', 'tvSort', array(
    		"tvSort.contentid = modResource.id",
    		"tvSort.tmplvarid = tvDefault.id"
    	));
    	$sessions = $modx->getCollection('modResource', $c);
    


    Any help would be much appreciated! I feel like I've been trying to write this same code snippet on every second site I'm working on these days, and once I see it once, I will be golden.

    Thanks!

    Scott
      • 37619
      • 79 Posts
      You should look into the add-on called "Rowboat" http://rtfm.modx.com/display/addon/Rowboat/

      Maybe you'll find your solution there. Hope that helps!
        Jean-Marc Buytaert (@jmbuytaert)

        MODX truly is the greatest thing that's ever happened to the Internet.
        • 6949 ☆ A M B ☆
        • 19 Posts
        Thanks for the reply, jmbuy! I took a look through the source of that addon, and I'm not sure that that will do the trick. It does seem like a useful addon though -- I'll keep it in the toolbox.
          • 6949 ☆ A M B ☆
          • 19 Posts
          Okay all, looks like I'm keeping my kingdom (and hugs if you were following your tweets today) for another day. Here's what I ended up doing. I'd like to learn these join things some day, but I didn't manage to climb up that curve today:

          <?php
          	$result           = false;
          	$id               = $input;
          	$SESSION_TEMPLATE = 9;
          	$SPEAKER1_TPL     = 39;
          	$SPEAKER2_TPL     = 40;
          	$SPEAKER3_TPL     = 41;
          	$SPEAKER4_TPL     = 42;
          	$SPEAKER5_TPL     = 43;
          
          	$c = $modx->newQuery('modTemplateVarResource');
          	$c->where(array(
          		array(
          			'value' =>  $id
          			,array(
          				array(
          					'tmplvarid:=' => $SPEAKER1_TPL
          				),
          				array(
          					'OR:tmplvarid:=' => $SPEAKER2_TPL
          				),
          				array(
          					'OR:tmplvarid:=' => $SPEAKER1_TPL
          				),
          				array(
          					'OR:tmplvarid:=' => $SPEAKER1_TPL
          				),
          				array(
          					'OR:tmplvarid:=' => $SPEAKER1_TPL
          				)
          			)
          		)
          	));
          	$sessionTVs = $modx->getCollection('modTemplateVarResource',$c);
          	if ( true === is_array($sessionTVs) ) {
          		foreach( $sessionTVs as $sessionTV ) {
          			$cid     = $sessionTV->get('contentid');
          			$session = $modx->getObject('modResource',$cid);
          			if ( true === is_object($session) ) {
          				$name    = $session->get('pagetitle');
          				$alias   = $session->get('alias');
                          $time    = $session->getTVValue('time_start');
                          $result .= $modx->getChunk($chunk,array(
          					'name'   => $name 
          					,'alias' => $alias
                              ,'time'  => $time
                          ));
          			}    
          		}
          	} else {
          		$modx->log('','getSessions: $sessions is not an array');
          	}
          	return $result;
          ?>
          


          Thanks all for reading!

          Scott