Skip to content
Snippets Groups Projects
Commit 0b119477 authored by Tim Steiner's avatar Tim Steiner
Browse files

Added some unility methods to Unl_Model_Collection

parent 2f5e71d1
No related branches found
No related tags found
No related merge requests found
...@@ -113,5 +113,33 @@ class Unl_Model_Collection implements Iterator, Countable, ArrayAccess ...@@ -113,5 +113,33 @@ class Unl_Model_Collection implements Iterator, Countable, ArrayAccess
} }
return $ids; return $ids;
} }
public function orderBy($method)
{
$valuesToSortOn = array();
$modelKeys = array();
foreach ($this->_models as $key => $model)
{
$valuesToSortOn[] = $model->$method();
$modelKeys[] = $key;
}
$valuesToSortOn = array_map('strtolower', $valuesToSortOn);
array_multisort($valuesToSortOn, $modelKeys);
$sortedModels = array();
foreach ($modelKeys as $modelKey) {
$sortedModels[$modelKey] = $this->_models[$modelKey];
}
$this->_models = $sortedModels;
}
public function arrayFromMethod($method)
{
$data = array();
foreach ($this->_models as $model)
{
$data[$model->getId()] = $model->$method();
}
return $data;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment