Esempio n. 1
0
 /**
  * Sorts items by a value of "position" attribute
  *
  * @param array $items The array to be processed
  */
 protected function sortItemsByPosition(array &$items)
 {
     ArrayUtils::sortBy($items, false, 'position');
     foreach ($items as &$item) {
         unset($item['position']);
     }
 }
Esempio n. 2
0
 /**
  * Sorts an array by specified property.
  *
  * This method uses the stable sorting algorithm. See http://en.wikipedia.org/wiki/Sorting_algorithm#Stability
  *
  * Supported options:
  *  property     [string]  The path of the property by which the array should be sorted. Defaults to 'priority'
  *  reverse      [boolean] Indicates whether the sorting should be performed in reverse order. Defaults to FALSE
  *  sorting-type [string]  number, string or string-case (for case-insensitive sorting). Defaults to 'number'
  *
  * @param array $array   The array to be sorted
  * @param array $options The sorting options
  *
  * @return array The sorted array
  */
 public function sortBy(array $array, array $options = [])
 {
     $sortingType = self::getOption($options, 'sorting-type', 'number');
     if ($sortingType === 'number') {
         $sortingFlags = SORT_NUMERIC;
     } else {
         $sortingFlags = SORT_STRING;
         if ($sortingType === 'string-case') {
             $sortingFlags |= SORT_FLAG_CASE;
         }
     }
     ArrayUtils::sortBy($array, self::getOption($options, 'reverse', false), self::getOption($options, 'property', 'priority'), $sortingFlags);
     return $array;
 }
Esempio n. 3
0
 /**
  * Sorts the given items by 'order' attribute
  *
  * @param array $items
  * @return mixed
  */
 protected function sortItems($items)
 {
     ArrayUtils::sortBy($items, false, 'order');
     return array_keys($items);
 }
Esempio n. 4
0
 protected function sortBlocks()
 {
     ArrayUtils::sortBy($this->blocks, true);
 }
Esempio n. 5
0
 /**
  * @param array $calendars
  */
 protected function normalizeCalendarData(array &$calendars)
 {
     // apply default values and remove redundant properties
     $defaultValues = $this->getCalendarDefaultValues();
     foreach ($calendars as &$calendar) {
         $this->applyCalendarDefaultValues($calendar, $defaultValues);
     }
     ArrayUtils::sortBy($calendars, false, 'position');
 }
Esempio n. 6
0
 public function testSortByObjectPath()
 {
     $obj1 = $this->createObject(['name' => '1', 'child' => $this->createObject(['priority' => null])]);
     $obj2 = $this->createObject(['name' => '2', 'child' => $this->createObject(['priority' => 100])]);
     $obj3 = $this->createObject(['name' => '3', 'child' => $this->createObject(['priority' => 0])]);
     $array = [$obj1, $obj2, $obj3];
     ArrayUtils::sortBy($array, false, 'child.priority');
     $this->assertSame([$obj1, $obj3, $obj2], $array);
 }