X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=RooGetTrait.php;fp=RooGetTrait.php;h=e47155c6c6d80f7710f37e91cd45db6c8614492b;hb=e569c736395279f67f2c140a9a55d65ee7d20429;hp=8aa6536ed7e559455185c33f5150745623a86e54;hpb=1528ffa098783910063e8875ff9fd98f6744c004;p=Pman.Core diff --git a/RooGetTrait.php b/RooGetTrait.php index 8aa6536e..e47155c6 100644 --- a/RooGetTrait.php +++ b/RooGetTrait.php @@ -464,4 +464,39 @@ trait Pman_Core_RooGetTrait { } + + function multiSort($x) + { + $ms = json_decode($_REQUEST['_multisort']); + if (!isset($ms->order) || !is_array($ms->order)) { + return; + } + $sort_str = array(); + + $cols = $x->table(); + + foreach($ms->order as $col) { + if (!isset($ms->sort->{$col})) { + continue; // no direction.. + } + $ms->sort->{$col} = $ms->sort->{$col} == 'ASC' ? 'ASC' : 'DESC'; + + if (strlen($col) && isset($cols[$col]) ) { + $sort_str[] = $x->tableName() .'.'.$col . ' ' . $ms->sort->{$col}; + continue; + } + + if (in_array($col, array_keys($this->cols))) { + $sort_str[] = $col. ' ' . $ms->sort->{$col}; + continue; + } + if (isset($x->_extra_cols) && in_array($col, $x->_extra_cols)) { + $sort_str[] = $col. ' ' . $ms->sort->{$col}; + } + } + + if ($sort_str) { + $x->orderBy(implode(', ', $sort_str )); + } + } }