MidgardQueryBuilder method add_order
Description:
bool add_order(string property, [string order])
Minimum version: Midgard 1.7.1
add_order is a method for the Query Builder for sorting the result list in desired way.
The method takes two arguments:
propertyis the name of a property in the MgdSchema type being queriedorderis optional, and is eitherASCfor ascending, orDESCfor descending order. If it is omittedASCwill be used.
This method returns TRUE when order was succesfully added to query generated by Query Builder, FALSE otherwise.
Midgard 1.8: Advanced ordering may be used for metadata objects or for referenced link types.
Usage:
<?php
$qb = new MidgardQueryBuilder("midgard_article");
// These two lines are equivalent (so specifying both in real-life
// wouldn't make sense of course :))
$qb->add_order('name');
$qb->add_order('name', 'ASC');
// This would list the last-created article first.
$qb->add_order('created', 'DESC');
?>
Note for Midgard 1.7 users without MidCOM
Due to a Zend-related bug in the PHP Binding, Midgard 1.7 crashes when you call $qb->add_order(false);. Unfortunalety, this cannot be easily circumvented, for dynamic assignments like $qb->add_order($some_var); you should therefore take some care to check against empty values first.
MidCOM 2.5 CVS users (as of 2006-02-22) do not have to worry about this, as the MidCOM level QB Wrapper midcom_core_querybuilder implicitly checks against this case when adding an ordering constraint.
