示例#1
0
 /**
  * @param Collection $collection
  * @param $orderBy
  * @param string $orderDir
  * @param null $orderManual
  * @return array
  * @internal
  */
 public function sortCollection(Collection $collection, $orderBy, $orderDir = 'asc', $orderManual = null)
 {
     $items = $collection->toArray();
     if (!$items) {
         return [];
     }
     $lookup = md5(json_encode($items));
     if (!isset($this->sort[$lookup][$orderBy])) {
         $this->buildSort($lookup, $items, $orderBy, $orderManual);
     }
     $sort = $this->sort[$lookup][$orderBy];
     if ($orderDir != 'asc') {
         $sort = array_reverse($sort);
     }
     return $sort;
 }