Example #1
0
 /**
  * Sort sub-pages in a page.
  *
  * @param Page $page
  * @param string $order_by
  * @param string $order_dir
  *
  * @return array
  */
 public function sort(Page $page, $order_by = null, $order_dir = null)
 {
     if ($order_by === null) {
         $order_by = $page->orderBy();
     }
     if ($order_dir === null) {
         $order_dir = $page->orderDir();
     }
     $path = $page->path();
     $children = isset($this->children[$path]) ? $this->children[$path] : array();
     if (!$children) {
         return $children;
     }
     if (!isset($this->sort[$path][$order_by])) {
         $this->buildSort($path, $children, $order_by, $page->orderManual());
     }
     $sort = $this->sort[$path][$order_by];
     if ($order_dir != 'asc') {
         $sort = array_reverse($sort);
     }
     return $sort;
 }