I would like to apply multiple sort criteria to a DataObjectSet... here is what I have so far:
public function getAllChildren_FeaturedOrNewestFirst()
{
$dos = $this->AllChildren();
$dos->sort('Created', 'DESC');
$dos->sort('Date', 'DESC');
$dos->sort('Featured', 'DESC');
return $dos;
}
So a few questions:
- Is this the "most correct" way to do this? Is there maybe an alternative way of calling this method with arrays so that it's only one statement? (if not, there should be) :-)
- Is the processing effort of these 3 statements 3x the effort of one statement? Or is there some kind of precompiling step which takes all these into account and does one sort, for better performance?
- If this *is* the way to do this, then am I doing it in the right sequence -- I assume that the later statement will have the more residual result -- so the above would return a result set that looks like (Featured then Date then Created).
By the way, if it seems odd that I would sort Date *and* Created ... this is because Date is a user field with default=Now, but only granular to the day, and we might be entering multiple items per day.
Thanks for any and all help,
-John