Updates to ORM sub records and change Sort::MAsort, sortby is now an array
This commit is contained in:
parent
9a41635025
commit
69c8052b53
@ -125,8 +125,11 @@ abstract class lnApp_ORM extends Kohana_ORM {
|
||||
protected function _load_values(array $values) {
|
||||
parent::_load_values($values);
|
||||
|
||||
$sort = FALSE;
|
||||
if ($this->_loaded AND $this->_sub_items_load AND count($this->_sub_items_load) == 1)
|
||||
if ($this->_sub_items_load AND count($this->_sub_items_load) > 1)
|
||||
throw HTTP_Exception::factory('501','Sub Items doesnt support more than 1 load');
|
||||
|
||||
$sort = array();
|
||||
if ($this->_loaded AND $this->_sub_items_load)
|
||||
foreach ($this->_sub_items_load as $item => $sort)
|
||||
$this->_sub_items = $this->$item->find_all()->as_array();
|
||||
|
||||
@ -337,6 +340,21 @@ abstract class lnApp_ORM extends Kohana_ORM {
|
||||
array_push($this->_sub_items,$item);
|
||||
}
|
||||
|
||||
public function subitem_get($key,$value) {
|
||||
foreach ($this->_sub_items as $o)
|
||||
if ($o->{$key} == $value)
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Since DB records are stored as strings, this function enables us to convert
|
||||
* values back to strings, primarily so they dont trigger being changed if they
|
||||
* havent.
|
||||
*/
|
||||
public static function tostring($value) {
|
||||
return (string)$value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the Kohana processing so we can null values if required.
|
||||
* We override this function, because we do set our own primary key value
|
||||
|
@ -19,9 +19,9 @@ abstract class lnApp_Sort {
|
||||
* @param boolean Whether to reverse sort.
|
||||
* @return array Sorted multi demension array.
|
||||
*/
|
||||
public static function MAsort(&$data,$sortby,$rev=0) {
|
||||
public static function MAsort(&$data,array $sortby=array(),$rev=0) {
|
||||
// if the array to sort is null
|
||||
if (! $data)
|
||||
if (! $data OR ! $sortby)
|
||||
return;
|
||||
// if the array to sort is null or empty, or our sortby is bad
|
||||
# if (! preg_match('/^([a-zA-Z0-9_]+(\([a-zA-Z0-9_,]*\)(->[a-zA-Z0-9])?)?,?)+$/',$sortby) || ! $data)
|
||||
@ -29,7 +29,7 @@ abstract class lnApp_Sort {
|
||||
|
||||
$code = '$c=0;';
|
||||
|
||||
foreach (explode(',',$sortby) as $key) {
|
||||
foreach ($sortby as $key) {
|
||||
$code .= 'if (is_object($a) || is_object($b)) {';
|
||||
foreach (array('a','b') as $x) {
|
||||
$code .= 'if (is_array($'.$x.'->'.$key.')) {';
|
||||
|
Reference in New Issue
Block a user