We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14665
    • 3 Posts
    Hi guys

    I am looking to create a training course search that runs off the document tree within modx. Please see below what I am looking to replicate;



    I am a beginner to PHP/MYSQL so this may have to be outsourced. I am on a very tight budget however so thought I would give it ago with your help...

    Is it as simple as creating Template Variables for the template and searching them via PHP/MYSQL.

    PLEASE can you point me towards a script that does this or any advice is welcomed entirely?

    Thanks very much.

    Kind regards

    Jonny
      • 13094
      • 58 Posts
      hi Jonny,
      not sure, if it’s pushing your knwoledge, but maybe you start like this:

      * assuming, all relevant documents are in one container ore be specified in the snippet call, like &startid= `X,Y,Z`
      <?php
      // startid can be provided in snippet parameters and a comma separated list
      $startid = (isset($startid)) ? $startid : $modx->documentIdentifier;
      $sortBy = (isset($sortBy)) ? $sortBy : 'menuindex';
      $sortDirection = (isset($sortDirection)) ? $sortDirection : 'ASC';
      
      $parents = array();
      if(strpos($startid, ',') !== false) {                // if $startid is given check for comma
        $parents = explode(',', $startid);             // explode list to array
      } else {
        $parents[] = $startid;                              // create single-item array  
      }
      
      $children = array();
      foreach($parents as $parent){
        $childArr = $modx->getAllChildren($parent, $sortBy, $sortDirection ,'id,pagetitle,longtitle,parent,content,deleted,published');
        foreach($childArr as $child){
          if(($child['deleted'] == 0 && $child['published'] == 1)){
            $children[] = $child;
          }
        }
      }
      //sort($children); 
      
      if(count($children) > 0){
        $output = '';
        foreach($children as $child){
          $subTV = $modx->getTemplateVarOutput(array("date","location","duration","title"),  $child['id'], $published = 1);
          $output .= 'PLACE YOUR TABLE OUTPUT HERE';
         .....
        }
        echo $output;
      }
      ?>
      

      your table output is normal HTML, while accessing the TVs like subTV["date"]

      for the pulldown-sort-thingys you’ll have to collect the TVs of each first. maybay there is a more elegant way by accessing the DB directly to perform a GROUP or JOIN select...

      cheers
      rolf