Частичная синхронизация с CMS
This commit is contained in:
parent
312f18a20a
commit
b26e521657
62 changed files with 827 additions and 5992 deletions
58
src/Sort.php
58
src/Sort.php
|
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
|
||||
class SortRecord
|
||||
{
|
||||
function __construct($key, $mode, $order)
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->order = ((boolean)($order) === false) ? 1 : -1;
|
||||
$this->mode = $mode;
|
||||
}
|
||||
|
||||
function compare($a, $b)
|
||||
{
|
||||
if($a[$this->key] == $b[$this->key]) {
|
||||
return 0;
|
||||
}
|
||||
return ($a[$this->key] > $b[$this->key]) ? $this->order : -$this->order;
|
||||
}
|
||||
|
||||
function compareKeys($a, $b)
|
||||
{
|
||||
if($a->{$this->key} == $b->{$this->key}) {
|
||||
return 0;
|
||||
}
|
||||
return ($a->{$this->key} > $b->{$this->key}) ? $this->order : -$this->order;
|
||||
}
|
||||
|
||||
function sort(&$list)
|
||||
{
|
||||
return usort($list, array($this, 'compare'));
|
||||
}
|
||||
|
||||
function sortKeys(&$list)
|
||||
{
|
||||
return usort($list, array($this, 'compareKeys'));
|
||||
}
|
||||
|
||||
function group(&$list, $key, $types)
|
||||
{
|
||||
$groups = array();
|
||||
foreach ($types as $name) {
|
||||
$groups[$name] = array();
|
||||
}
|
||||
$groups['_any_'] = array();
|
||||
foreach ($list as $item) {
|
||||
if (isset($groups[$item[$key]])) {
|
||||
$groups[$item[$key]][] = $item;
|
||||
} else {
|
||||
$groups['_any_'][] = $item;
|
||||
}
|
||||
}
|
||||
$result = array();
|
||||
foreach ($groups as $value) {
|
||||
$result = array_merge($result, $value);
|
||||
}
|
||||
$list = $result;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue