Name = self::getTranslation( $categoryRecord->Name, 'CalendarGroup.Name' ); $this->ID = $categoryRecord->ID; $this->Priority = $categoryRecord->Priority; $this->Calendars = array_map( function(Calendar $calendarRecord) { $dto = new CalendarDTO(); $dto->loadRecord($calendarRecord); return $dto; }, array_filter( $calendars, function(Calendar $calendarRecord) use($categoryRecord) { return $categoryRecord->ID == $calendarRecord->CategoryID; } ) ); usort($this->Calendars, ['CalendarDTO', '__compare']); } public static function __compare(CalendarGroupDTO $cat1, CalendarGroupDTO $cat2) { $cmp = ($cat1->Priority ?: PHP_MAX_INT) - ($cat2->Priority ?: PHP_MAX_INT); if ($cmp !== 0) { return $cmp; } return strcmp($cat1->Name, $cat2->Name); } } ?>