Page List Sort

I'm trying to figure out a way to change the sort order of a page list block via a url (preferably something like or something like that) or via a drop down and cant figure out how. Does anyone know how to do that? I've attached a mockup so you can see a visual of what I need.

1 Attachment

View Replies:
TheRealSean replied on at Permalink Reply
Without looking in the code an immediate thought would be to have to page list on the page and in the view show either one depending on the query string sortBy
c5mix replied on at Permalink Reply
Yeah that's what I want, but how do I create a link (or drop down) to switch the sort order of that page list block?
TheRealSean replied on at Permalink Reply
When you set up a page list block you choose the order pages are displayed (I dont know if reverse alpha is there?)

in the block view you could have something like
//im not sure of the syntax here
$controller->sortBy = 'ASC';
$controller->sortBy = 'DESC';

Ill double check this tomorrow but bed first :)
hmm thinking about it alphabetical might not even be an option?

in which case maybe asort/arsort
the pagelist results may need tweaking as I think they are an object when output? but I could be getting confused with the autonav? one is $cArray
TheRealSean replied on at Permalink Reply
Ok Coffee drank, ready to go.

In your view if you add the switch? I dont know if you want to to it with request/get

I have not tested this, but looking in the controller the If the Block ID exists it grabs it from the DB, but we want to be able to over ride the orderby.

So if we move away from the getPages function and do it ourselves, the query I imagine could probably be moved to its own function so that we could change the variable on view? but for now this should replicate it
$bID = $controller->bID;
if ($bID) {
   $q = "select num, cParentID, cThis, orderBy, ctID, displayAliases, rss from btPageList where bID = '$bID'";
   $r = $db->query($q);
   if ($r) {
      $row = $r->fetchRow();
$pl = new PageList();
$pl->setNameSpace('b' . $bID);
//we dont need the switch so instead, lets just order the pl here.
//$row->orderBy = 'alpha_desc';

Hopefully that should do it?
joseajohnson replied on at Permalink Reply
I believe the databaselistitem (ItemList) is the parent of the pagelist item class, so the former's methods should work on the latter's.

Check the bottom of the page for inheritace:
Here's the usage:

Had to accomplish a similar feat recently, but with multiple parameters, using both name and parentID:
$PageList->sortByMultiple('cvName asc', 'p1.cParentID asc');

Pretty sure that to just use one parameter is something like:
$PageList->sortBy('cvName', 'asc');

So by creating a 'sortBy' function in your block's controller (in which the above would reside, and would presumably duplicate the 'view' function) to handle the passed parameter, you can slip this string into the view:
<A href="<?php   echo $this->url('/yourdir/yourpage', 'sortBy', 'asc')?>"><?php   echo t('Ascending')?></a>

to generate the link, or maybe use a form with the action pointing to the page:
form action="<?php   echo $this->action('sortBy')?>"

so your controller's 'sortBy' event handler can work from the request, like TheRealSean pointed out. The name of the form's control (like say, a dropdown select) would match the request var, and the action pulls the named function.