We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13697
    • 19 Posts
    I had PrevJumpNext working but have now updated my site to 2.1.1 and it has stopped working.

    A quick look and it seems getActiveChildren has been depreciated and removed and thats causing the problem.

    I have read I can replace getActiveChildren with getCollection but how do I get it to return the same as getActiveChildren so the snippet will work again?

    I have added

    $children = modX->getCollection(’modResource’, $criteria);

    but don’t know how to get the $criteria setup to create the required output.

    Any help much appreciated.

    thanks

    J

      • 26903
      • 1,336 Posts
      From the original GetActiveChildren :-

      $fields='id, pagetitle, description, parent, alias, menutitle, class_key, context_key';
      $columns = explode(',', $fields);
      foreach ($columns as $colKey => $column) $columns[$colKey] = trim($column);
      
      $criteria = $this->newQuery('modResource');
              $criteria->setClassAlias('sc');
              $criteria->select('id');
              $criteria->select($columns);
              $criteria->where(array(
                  'sc.parent' => $id,
                  'sc.published' => '1',
                  'sc.deleted' => '0'
              ));


      There may be a better way to do this now in the 2.1 API.

        Use MODx, or the cat gets it!
        • 13697
        • 19 Posts
        Thanks for the quick response.

        Is that the actual code from getactivechildren, or have you modified it to work.

        I have tried implementing it by adding it to the prevjumpnext snippet but just get a blank page.

        am I missing something?

        Cheers

        J
          • 26903
          • 1,336 Posts
          Its from the code base, so you need to set the $id, in the line ’sc.parent => $id’ substitute the id passed in the snippet for $id. I’ve not looked at the snippet itself but you should be able to blend this into it.
            Use MODx, or the cat gets it!
            • 13697
            • 19 Posts
            Hi,

            I have replaced

            $children = $modx->getActiveChildren($startID, $sortBy, $sortHow, $fields);

            with


            $fields=’id, pagetitle, description, parent, alias, menutitle, class_key, context_key’;
            $columns = explode(’,’, $fields);
            foreach ($columns as $colKey => $column) $columns[$colKey] = trim($column);

            $criteria = $this->newQuery(’modResource’);
            $criteria->setClassAlias(’sc’);
            $criteria->select(’id’);
            $criteria->select($columns);
            $criteria->where(array(
            ’sc.parent’ => $startID,
            ’sc.published’ => ’1’,
            ’sc.deleted’ => ’0’
            ));

            $children = $modx->getCollection(’modResource’,$criteria);


            But this just gives me a blank white page

            If I comment out

            //$children = $modx->getCollection(’modResource’,$criteria);

            the page will display but the prevjumpnext function outputs no links

            am I missing something, I have followed it through and it all seems to make sense

            Cheers

            J

              • 26903
              • 1,336 Posts
              The ’$criteria = $this-’ should be $modx, not $this, try that.
                Use MODx, or the cat gets it!
                • 13697
                • 19 Posts
                Hi, Thanks for the suggestion,

                have updated the $this to $modx but I am still getting a blank page when I remove the // from the line below

                //$children = $modx->getCollection(’modResource’,$criteria);

                is there a problem with getCollection, how would I check this?

                Many Thanks

                J
                  • 21838
                  • 284 Posts
                  I use selfLink instead of PrevJumpNext.
                  It has been developed very simple but I asked Bruno17 to extend it so this came out:


                  <?php
                  /**
                  * selfLink
                  * To navigate up, next or previous from the current resource or from the given resource
                  *
                  * Options
                  *
                  * id - The id where the direction is from. Default the current resource id
                  * direction - To create a link in the direction up, previous or next
                  * tpl - The chunkname wich is used for the view of the link
                  * linktext - The text used for the link instead of the pagetitle
                  *
                  * Example usage:
                  * [[!selfLink? &id=`[[*id]]` &direction=`next` &tpl=`commonName`]]
                  *
                  * @author Bert Oost <[email protected]>
                  * @author Bruno Perner <[email protected]>
                  * @version 0.2-rc1
                  */
                  $resource = $modx->getOption(’id’, $scriptProperties, $modx->resource->get(’id’));
                  $direction = $modx->getOption(’direction’, $scriptProperties, false);
                  $tpl = $modx->getOption(’tpl’, $scriptProperties, false);
                  $linktxt = $modx->getOption(’linktext’, $scriptProperties, false);

                  if ($res = $modx->getObject(’modResource’, $resource)) {
                  $menuindex = $res->get(’menuindex’);
                  $parentid = $res->get(’parent’);
                  $c = $modx->newQuery(’modResource’);
                  $c->limit(1);

                  switch ($direction) {

                  case ’up’:
                  case ’parent’:
                  $c->where(array(’id’ => $parentid));
                  break;

                  case ’next’:
                  case ’prev’:
                  case ’previous’:
                  $c->where(array(’published’ => ’1’));
                  $c->where(array(’deleted’ => ’0’));
                  $c->where(array(’parent’ => $parentid));
                  $c->where(array(’id:!=’ => $resource));
                  break;
                  }
                  switch ($direction) {

                  case ’next’:
                  $c->where("IF(menuindex = ". $menuindex .",id > ". $resource .",menuindex >". $menuindex . ")" , xPDOQuery::SQL_AND);
                  //$c->where(array(’menuindex:>=’ => $menuindex));
                  $c->sortby(’menuindex,id’,’ASC’);
                  break;

                  case ’prev’:
                  case ’previous’:
                  $c->where("IF(menuindex = ". $menuindex .",id < ". $resource .",menuindex <". $menuindex . ")" , xPDOQuery::SQL_AND);
                  //$c->where(array(’menuindex:<=’ => $menuindex));
                  $c->sortby(’menuindex’,’DESC’);
                  $c->sortby(’id’,’DESC’);
                  break;
                  }
                  if ($linkResource = $modx->getObject(’modResource’, $c)) {

                  // build placeholders
                  $placeholders = array(
                  ’id’ => $linkResource->get(’id’),
                  ’pagetitle’ => (!empty($linktxt)) ? $linktxt : $linkResource->get(’pagetitle’),
                  ’longtitle’ => (!empty($linktxt)) ? $linktxt : $linkResource->get(’longtitle’),
                  ’menutitle’ => (!empty($linktxt)) ?
                  $linktxt : $linkResource->get(’menutitle’)
                  );

                  // parse chunk
                  $chunk = $modx->getObject(’modChunk’, array(’name’ => $tpl));

                  if (!$chunk) {

                  $useChunk = ’<a href="[[~[[+id]]]]">[[+menutitle]]</a>’;
                  $chunk = $modx->newObject(’modChunk’);
                  $chunk->setCacheable(false);

                  return $chunk->process($placeholders, $useChunk);
                  }

                  return $chunk->process($placeholders);
                  }
                  }
                    MODX Free Template Base: MODX-Boilerplate | my blog (lots of MODX stuff) | my gitHub (translations) | MODX User Groups Germany (Facebook)