diff options
author | emkael <emkael@tlen.pl> | 2016-05-10 00:27:47 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-05-10 00:27:47 +0200 |
commit | a9726eec11d092583242259aea8b88f1085ad922 (patch) | |
tree | 4e234e93857c01c945c74b739f324bd68b228e01 | |
parent | 668ce7487a1c61438213e9efb705c5c804aace8b (diff) |
* switching to DTO in getCategories from CalendarFacade
-rw-r--r-- | app/php/dto/CalendarGroupDTO.php | 2 | ||||
-rw-r--r-- | app/php/facades/CalendarFacade.php | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/app/php/dto/CalendarGroupDTO.php b/app/php/dto/CalendarGroupDTO.php index 5f83a71..7b64c6e 100644 --- a/app/php/dto/CalendarGroupDTO.php +++ b/app/php/dto/CalendarGroupDTO.php @@ -6,11 +6,13 @@ Prado::using('Application.dto.CalendarDTO'); class CalendarGroupDTO { public $Name; + public $ID; public $Priority; public $Calendars = []; public function loadRecord(Category $categoryRecord, array $calendars) { $this->Name = $categoryRecord->Name; + $this->ID = $categoryRecord->ID; $this->Priority = $categoryRecord->Priority; $this->Calendars = array_map( function($calendarRecord) { diff --git a/app/php/facades/CalendarFacade.php b/app/php/facades/CalendarFacade.php index b15eac3..5f24e28 100644 --- a/app/php/facades/CalendarFacade.php +++ b/app/php/facades/CalendarFacade.php @@ -143,7 +143,16 @@ class CalendarFacade extends Facade { } public function getCategories() { - return Category::finder()->findAll('ORDER BY name ASC'); + $categories = array_map( + function($record) { + $dto = new CalendarGroupDTO(); + $dto->loadRecord($record, []); + return $dto; + }, + Category::finder()->findAll() + ); + usort($categories, ['CalendarGroupDTO', '__compare']); + return $categories; } public function get($uid) { |