<![CDATA[ Show Sorting Option - My Forums]]> https://forums.modx.com/thread/?thread=28883 <![CDATA[Re: Show Sorting Option]]> https://forums.modx.com/thread/28883/show-sorting-option?page=2#dis-post-155532 http://www.3eimpact.org/index.php?id=38&tab=categories). I was just wanting to understand what was going on in the last line of code so I’ll be able to adapt it as needed for other situations. It looks like its going to take a bit more research before I can get my mind wrapped around some of these concepts. Thanks again for the pointers and helpful links.

]]>
mattcdavis1 Sep 14, 2009, 01:25 AM https://forums.modx.com/thread/28883/show-sorting-option?page=2#dis-post-155532
<![CDATA[Re: Show Sorting Option]]> https://forums.modx.com/thread/28883/show-sorting-option?page=2#dis-post-155531 http://modxcms.com/forums/index.php/topic,12122.msg80929.html#msg80929 for a little more information on what can be passed as a "criteria".]]> opengeek Sep 14, 2009, 12:54 AM https://forums.modx.com/thread/28883/show-sorting-option?page=2#dis-post-155531 <![CDATA[Re: Show Sorting Option]]> https://forums.modx.com/thread/28883/show-sorting-option#dis-post-155530
At any rate, here’s the deal as I understand it. The first argument is the class name of the object you want. In your case, ’Children’ which is an alias (kind of a pseudo-class).

It’s the optional *second* argument that contains the criteria ($c in this case), which is a query object, built over several lines, that ends up being decoded as a query string when passed to getOne() or getMany().

Hope this makes sense. smiley

BTW: I tested Shaun’s code and it definitely works. If you add this to it, it should display the children (sorted):

foreach($children as $child) {

   $output .= $child->get('pagetitle') . '<br />';
}
return $output;
]]>
BobRay Sep 14, 2009, 12:20 AM https://forums.modx.com/thread/28883/show-sorting-option#dis-post-155530
<![CDATA[Re: Show Sorting Option]]> https://forums.modx.com/thread/28883/show-sorting-option#dis-post-155529
1. Create a new query object with criteria "modResource" which returns an array of all modResource objects.
2. Filter query object-array using "where" method so that only items meeting criteria remain in object array.
3. Sort query object-array using "sortby" method.
4. Here’s where I’m having trouble:

$children = $modx->resource->getMany(’Children’,$c);

I think I understand that what we’re saying here is let’s call the "getMany" method of the current object with the criteria of "Children" - but what’s throwing me off is the second parameter. I don’t understand how that fits into things. I was reading Bob’s guides, for example, and he writes "Remember that getOne() and getMany() always take a single argument" which obviously is not the case here.

I can see in the API docs that: "void getMany ( $class, [ $criteria = null], [ $cacheFlag = false])"

From this I understand that there are two additional, optional parameters, but I can’t seem to find any more info on how these parameters (particularly the second one which is what is used here) fit into the equation. Any help would be appreciated. Perhaps there is some additional info on this somewhere and I’m just not finding it?

Thanks,

-matt]]>
mattcdavis1 Sep 13, 2009, 09:29 PM https://forums.modx.com/thread/28883/show-sorting-option#dis-post-155529
<![CDATA[Re: Show Sorting Option]]> https://forums.modx.com/thread/28883/show-sorting-option#dis-post-155528
http://svn.modxcms.com/docs/display/XPDO10/Home

and you can find API docs here:

http://api.modxcms.com/]]>
splittingred Sep 13, 2009, 09:00 PM https://forums.modx.com/thread/28883/show-sorting-option#dis-post-155528
<![CDATA[Re: Show Sorting Option]]> https://forums.modx.com/thread/28883/show-sorting-option#dis-post-155527 mattcdavis1 Sep 13, 2009, 07:54 PM https://forums.modx.com/thread/28883/show-sorting-option#dis-post-155527 <![CDATA[Re: Show Sorting Option]]> https://forums.modx.com/thread/28883/show-sorting-option#dis-post-155526 Quote from: mattcdavis1 at Sep 13, 2009, 09:54 PM

Basically, I want to get all children of a document by using getMany and then sort the objects by ’pagetitle’ property. Here’s what I’ve got:

$int_pageId = $modx->resource->get(’id’); //gets id of current page
$obj_currentPage = $modx->getObject(’modResource’,$int_pageId); //get’s current page as an object
$children = $obj_currentPage->getMany(’Children’); //gets object array of current object’s children for menu.
//now I just need to figure out how to sort the array and then I can output ’link’ and ’pagetitle’ properites using a foreach loop with parseChunk

Try this:

$c = $modx->newQuery('modResource');
$c->where(array(
   'parent' => $modx->resource->get('id'),
));
$c->sortby('pagetitle','ASC');
$children = $modx->resource->getMany('Children',$c);

By the way - you don’t need to getObject the current resource as an object; $modx->resource is exactly that.]]>
splittingred Sep 13, 2009, 04:57 PM https://forums.modx.com/thread/28883/show-sorting-option#dis-post-155526
<![CDATA[Re: Show Sorting Option]]> https://forums.modx.com/thread/28883/show-sorting-option#dis-post-155525
In the meantime, I was trying to figure out the best way to sort an array of objects returned by getMany to create and alphabetize a menu.

Basically, I want to get all children of a document by using getMany and then sort the objects by ’pagetitle’ property. Here’s what I’ve got:

$int_pageId = $modx->resource->get(’id’); //gets id of current page
$obj_currentPage = $modx->getObject(’modResource’,$int_pageId); //get’s current page as an object
$children = $obj_currentPage->getMany(’Children’); //gets object array of current object’s children for menu.
//now I just need to figure out how to sort the array by the pagetitle property of each object and then I can output ’link’ and ’pagetitle’ properites using a foreach loop with parseChunk]]>
mattcdavis1 Sep 13, 2009, 04:54 PM https://forums.modx.com/thread/28883/show-sorting-option#dis-post-155525
<![CDATA[Re: Show Sorting Option]]> https://forums.modx.com/thread/28883/show-sorting-option#dis-post-155524
This was fixed in post-beta3 commit of SVN.]]>
splittingred Sep 13, 2009, 02:14 PM https://forums.modx.com/thread/28883/show-sorting-option#dis-post-155524
<![CDATA[Re: Show Sorting Option]]> https://forums.modx.com/thread/28883/show-sorting-option#dis-post-155523
Thanks, matt]]>
mattcdavis1 Sep 13, 2009, 12:53 PM https://forums.modx.com/thread/28883/show-sorting-option#dis-post-155523