Ejemplo n.º 1
0
 /**
  * Get the sort order of an item in the items array.
  * This function looks at the following keys:
  * - **sort (numeric)**: A specific numeric sort was provided.
  * - **sort array('before|after', 'key')**: You can specify that the item is before or after another item.
  * - **_sort**: The order the item was added is used.
  *
  * @param array $item The item to get the sort order from.
  * @param array $items The entire list of items.
  * @param int $depth The current recursive depth used to prevent inifinite recursion.
  * @return number
  */
 public static function sortItemsOrder($item, $items, $depth = 0)
 {
     $default_sort = val('_sort', $item, 100);
     // Check to see if a custom sort has been specified.
     if (isset($item['sort'])) {
         if (is_numeric($item['sort'])) {
             // This is a numeric sort
             return $item['sort'] * 10000 + $default_sort;
         } elseif (is_array($item['sort']) && $depth < 10) {
             // This sort is before or after another depth.
             list($op, $key) = $item['sort'];
             if (array_key_exists($key, $items)) {
                 switch ($op) {
                     case 'after':
                         return NavModule::sortItemsOrder($items[$key], $items, $depth + 1) + 1000;
                     case 'before':
                     default:
                         return NavModule::sortItemsOrder($items[$key], $items, $depth + 1) - 1000;
                 }
             }
         }
     }
     return $default_sort * 10000 + $default_sort;
 }