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

    Apologies if this is in the wrong place. I did try to search for what I am after first but didn’t manage to find anything.

    I am beginning to work on converting a sitemap snippet so it will work with revolution (Snippet I am editing is Sitemap 1.0.8 originally by Grad. )

    I am working my way through it and am of course discovering lots of depreciated tags which have been used, for instance:
    getActiveChildren()

    I am wondering if something like the following would suit:

    $docList = $modx->getChildIDs($startid);
    $docs = $modx->getDocuments($docList,'1','0','id,editedon,template,published,searchable,pagetitle,type','','menuindex','asc'); 
    


    The source code in modx.class.php says that getDocuments is now depreciated (as of October last year) Is there a more appropriate way to fetch the necessary metadata required to generate a sitemap under revo - or is getDocuments() most suitable for now?

    Regards,
    Dave
      • 28215
      • 4,149 Posts
      Technically getDocuments will work for Revolution 2.0.0, but will be phased out in 2.1.0.

      This will work just as well, and will be compatible with 2.1:
      $c = $modx->newQuery('modResource');
      $c->where(array(
      	'parent' => $startid,
      	'published' => true,
      	'deleted' => false,
      ));
      $c->sortby('menuindex','ASC');
      $resources = $modx->getCollection('modResource',$c);
      


      Note that this will get you a collection of modResource objects, not the arrays. You can always $resource->toArray() to get them as arrays; but it’s best to leave them as objects, so you can use their functions. To get a field of the object:

      $resource->get('pagetitle');


      And so forth. Welcome to xPDO. smiley
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 4883
        • 3 Posts
        Thanks Shaun, I’ll let people know when I have finished a beta (Hopefully in a few days time)
          • 22303 MODX Staff
          • 10,725 Posts
          FWIW, there is also a new function in 2.0.0 that provides an array representing the entire site tree. Not that it will necessarily be useful for your specific purposes, but just wanted to mention it:
          <?php
          $siteTree = $modx->getTree(0, 10);
          ?>

          The first parameter is the Resource id to start the tree from, and the second is the depth to render.

          This is just Resource id’s, similar to getChildIds() and getParentIds(), but may be useful for various purposes when you need to get the all the id’s organized as they are in each context. Note that this always pulls the Resources in the current context.
            • 4883
            • 3 Posts
            Quote from: splittingred at May 31, 2009, 09:55 AM

            -- cut --
            $c = $modx->newQuery('modResource');
            $c->where(array(
            	'parent' => $startid,
            	'published' => true,
            	'deleted' => false,
            ));
            $c->sortby('menuindex','ASC');
            $resources = $modx->getCollection('modResource',$c);
            


            -- cut --

            Shaun,

            I ran the above however it does not seem to process the where filter, as I received too much information (IE unpublished pages). I appreciate there is no select section however I am yet to refine exactly the parts I need. Also I adjust the where to start at parent id 2 (A valid parent folder) I get article with parentid 0. Is there any documetnation I can look at explaining how the where in xPDO differs from a where in PDO ?

            Thanks
              • 28215
              • 4,149 Posts
              Quote from: splittingred at May 31, 2009, 09:55 AM

              $c = $modx->newQuery('modResource');
              $c->where(array(
              	'parent' => $startid,
              	'published' => true,
              	'deleted' => false,
              ));
              $c->sortby('menuindex','ASC');
              $resources = $modx->getCollection('modResource',$c);
              



              Shaun,
              I ran the above however it does not seem to process the where filter, as I received too much information (IE unpublished pages).
              There should be no reason that the query wouldn’t work. Try 1 instead of true, and 0 instead of false.

              If that doesn’t work, could you run those queries with:

              $modx->setDebug(true);
              $modx->setLogTarget('ECHO');


              then paste that into dpaste.com or somewhere so we can take a look? The query works no problem on my installs.

                I appreciate there is no select section however I am yet to refine exactly the parts I need.  Also I adjust the where to start at parent id 2 (A valid parent folder) I get article with parentid 0.  Is there any documetnation I can look at explaining how the where in xPDO differs from a where in PDO ?

              It’s very similar to PDO; I know Jason is working on some xPDO docs, but you can find what’s there either:

              http://xpdo.org/documentation.html
              http://docs.modxcms.com/
                shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com