improve customer api & gui
This commit is contained in:
70
customerapi/models/dto/EventDTO.php
Normal file
70
customerapi/models/dto/EventDTO.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
namespace customerapi\models\dto;
|
||||
|
||||
use customerapi\models\available\EventAvailable;
|
||||
|
||||
class EventDTO extends \yii\base\Model
|
||||
{
|
||||
|
||||
public $id;
|
||||
public $start;
|
||||
public $end;
|
||||
public $seat_count;
|
||||
public $created_at;
|
||||
public $updated_at;
|
||||
public $deleted_at;
|
||||
public $active;
|
||||
public $eventType;
|
||||
public $trainer;
|
||||
public $room;
|
||||
public $eventRegistrations;
|
||||
|
||||
public $registrationCount;
|
||||
public $hasFreeSeats;
|
||||
|
||||
function fields()
|
||||
{
|
||||
$fields = [
|
||||
"id" => "id",
|
||||
"start" => "start",
|
||||
"end" => "end",
|
||||
"seat_count" => "seat_count",
|
||||
"active" => "active",
|
||||
"reservationCount" => "registrationCount",
|
||||
"hasFreeSeats" => "hasFreeSeats",
|
||||
"registrations" => "eventRegistrations",
|
||||
];
|
||||
$fields['trainer'] = 'trainer';
|
||||
$fields['eventType'] = 'eventType';
|
||||
$fields['room'] = 'room';
|
||||
// $fields['registrations'] = 'eventRegistrations';
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $event /common/models/Event
|
||||
*/
|
||||
public static function fromEvent($event)
|
||||
{
|
||||
$dto = new EventDTO();
|
||||
$dto->id = $event->id;
|
||||
$dto->start = $event->start;
|
||||
$dto->end = $event->end;
|
||||
$dto->seat_count = $event->seat_count;
|
||||
$dto->created_at = $event->created_at;
|
||||
$dto->updated_at = $event->updated_at;
|
||||
$dto->deleted_at = $event->deleted_at;
|
||||
$dto->active = $event->active;
|
||||
|
||||
return $dto;
|
||||
}
|
||||
|
||||
public static function fromEventWithRelatedObjects($event){
|
||||
$eventDto = EventDTO::fromEvent($event);
|
||||
$eventDto->trainer = TrainerDTO::fromTrainer($event->trainer);
|
||||
$eventDto->room = RoomDTO::fromRoom($event->room);
|
||||
$eventDto->eventType = EventTypeDTO::fromEventType($event->eventType);
|
||||
return $eventDto;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user