improve customer timetable
This commit is contained in:
@@ -9,13 +9,19 @@
|
||||
namespace customerapi\controllers;
|
||||
|
||||
|
||||
use common\models\Event;
|
||||
use common\models\EventRegistration;
|
||||
use customerapi\manager\EventRegistrationManager;
|
||||
use customerapi\models\available\EventInterval;
|
||||
use customerapi\models\available\EventAvailable;
|
||||
use customerapi\models\DayToDisplay;
|
||||
use customerapi\models\details\EventDetailsView;
|
||||
use customerapi\models\details\EventRegistrationView;
|
||||
use customerapi\models\details\EventTypeDetailsView;
|
||||
use customerapi\models\details\RoomDetailsView;
|
||||
use customerapi\models\details\TrainerDetailsView;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use yii\db\ActiveRecord;
|
||||
use yii\db\Query;
|
||||
use yii\web\Response;
|
||||
|
||||
@@ -63,7 +69,7 @@ class EventController extends CustomerApiController
|
||||
->innerJoinWith('trainer')
|
||||
->innerJoinWith('eventType')
|
||||
->innerJoinWith('room')
|
||||
->joinWith('activeEventRegistrationsForCustomer')
|
||||
// ->leftJoin('activeEventRegistrationsForCustomer')
|
||||
->andWhere(['>=', 'event.start', $interval->firstActiveDate->getTimestamp()])
|
||||
->andWhere(['<', 'event.start', (clone $interval->lastActiveDate)->modify('+1 day')->getTimestamp()])
|
||||
->andWhere(['event.active' => '1'])
|
||||
@@ -77,6 +83,7 @@ class EventController extends CustomerApiController
|
||||
$eventDay->setTime(0, 0);
|
||||
|
||||
$event->reservationCount = $event->getEventRegistrationCount();
|
||||
$event->hasFreeSeats = $event->reservationCount < $event->seat_count;
|
||||
|
||||
/** @var DayToDisplay $date */
|
||||
foreach ($dates as $date) {
|
||||
@@ -105,7 +112,7 @@ class EventController extends CustomerApiController
|
||||
->innerJoinWith('trainer')
|
||||
->innerJoinWith('eventType')
|
||||
->innerJoinWith('room')
|
||||
->joinWith('activeEventRegistrations')
|
||||
->joinWith('activeEventRegistrations','event.id = activeEventRegistrations.id_event')
|
||||
->andWhere(['>=', 'event.start', $interval->firstActiveDate->getTimestamp()])
|
||||
->andWhere(['<', 'event.start', (clone $interval->lastActiveDate)->modify('+1 day')->getTimestamp()])
|
||||
->andWhere(['event.active' => '1']);
|
||||
@@ -121,11 +128,32 @@ class EventController extends CustomerApiController
|
||||
{
|
||||
$interval = EventInterval::createInterval();
|
||||
try {
|
||||
$query = EventDetailsView::find();
|
||||
$query = Event::find();
|
||||
$query = $this->buildEventQuery($query, $interval);
|
||||
$query = $query->andWhere(['event.id' => $id_event]);
|
||||
|
||||
/** @var Event $event */
|
||||
$event = $query->one();
|
||||
return $this->asJson($event);
|
||||
|
||||
|
||||
$result = new EventDetailsView();
|
||||
$result->id = $event->id;
|
||||
$result->start = $event->start;
|
||||
$result->end = $event->end;
|
||||
$result->seatCount = $event->seat_count;
|
||||
$result->trainer = TrainerDetailsView::findOne($event->id_trainer);
|
||||
$result->room = RoomDetailsView::findOne($event->id_room);
|
||||
$result->eventType = EventTypeDetailsView::findOne($event->id_event_type);
|
||||
$registrations = EventRegistrationView::find()->all();
|
||||
$allActiveRegistrations = EventRegistration::filterActive($registrations);
|
||||
$customerActiveRegistrations = EventRegistration::filterForCustomer($allActiveRegistrations,\Yii::$app->user->id);
|
||||
$result->reservationCount = count($allActiveRegistrations);
|
||||
$result->registrations = $customerActiveRegistrations;
|
||||
$result->hasFreeSeats = $event->seat_count > count($allActiveRegistrations);
|
||||
|
||||
|
||||
|
||||
return $this->asJson($result);
|
||||
} catch (Exception $e) {
|
||||
throw new \yii\base\Exception($e->getMessage());
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class EventRegistrationController extends CustomerApiController
|
||||
$form->event_id = $id_event;
|
||||
$form->card_number = $card->number;
|
||||
|
||||
$manager = new EventRegistrationManager();
|
||||
$manager = new \common\manager\EventRegistrationManager();
|
||||
$manager->registerCard($form);
|
||||
|
||||
return $form->registration;
|
||||
|
||||
@@ -17,7 +17,7 @@ class EventRegistrationManager
|
||||
return $this->prepareQueryFindRegistrationsForCustomer()->all();
|
||||
}
|
||||
|
||||
public function findCustomerRegistrations()
|
||||
public function findCustomerRegistrations($clazz= EventRegistration::class )
|
||||
{
|
||||
$interval = EventInterval::createInterval();
|
||||
return EventRegistration::find()
|
||||
|
||||
@@ -10,6 +10,7 @@ class EventAvailable extends Event
|
||||
{
|
||||
|
||||
public $reservationCount;
|
||||
public $hasFreeSeats;
|
||||
|
||||
protected function getTrainerClass()
|
||||
{
|
||||
@@ -39,6 +40,7 @@ class EventAvailable extends Event
|
||||
"seat_count" => "seat_count",
|
||||
"active" => "active",
|
||||
"reservationCount" => "reservationCount",
|
||||
"hasFreeSeats" => "hasFreeSeats",
|
||||
];
|
||||
$fields['trainer'] = 'trainer';
|
||||
$fields['eventType'] = 'eventType';
|
||||
|
||||
@@ -5,37 +5,37 @@ namespace customerapi\models\details;
|
||||
|
||||
|
||||
use common\models\Event;
|
||||
use yii\base\Model;
|
||||
|
||||
class EventDetailsView extends Event
|
||||
/**
|
||||
$property string $eventName;
|
||||
$property string $start;
|
||||
$property string $end;
|
||||
$property string $seatCount;
|
||||
$property string $reservationCount;
|
||||
$property customerapi\models\details\EventDetailsView $room;
|
||||
$property customerapi\models\details\TrainerDetailsView $trainer;
|
||||
$property customerapi\models\details\EventTypeDetailsView $eventType;
|
||||
$property string $registrations;
|
||||
*/
|
||||
class EventDetailsView extends Model // extends Event
|
||||
{
|
||||
|
||||
public $id;
|
||||
public $start;
|
||||
public $end;
|
||||
public $seatCount;
|
||||
// total count of registrations
|
||||
public $reservationCount;
|
||||
public $room;
|
||||
public $trainer;
|
||||
public $eventType;
|
||||
// registrations for current user
|
||||
public $registrations;
|
||||
|
||||
public $hasFreeSeats;
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getTrainerClass()
|
||||
{
|
||||
// override trainer class to have more control
|
||||
// about json fields
|
||||
return TrainerDetailsView::class;
|
||||
}
|
||||
|
||||
protected function getEventTypeClass()
|
||||
{
|
||||
return EventTypeDetailsView::class;
|
||||
}
|
||||
|
||||
protected function getRoomClass()
|
||||
{
|
||||
return RoomDetailsView::class;
|
||||
}
|
||||
|
||||
protected function getEquipmentTypeAssignmentsClass()
|
||||
{
|
||||
return EventEquipmentTypeAssignmentView::class;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -49,15 +49,17 @@ class EventDetailsView extends Event
|
||||
"id" => "id",
|
||||
"start" => "start",
|
||||
"end" => "end",
|
||||
"seat_count" => "seat_count",
|
||||
"active" => "active",
|
||||
// "reservationCount" => "reservationCount"
|
||||
"seat_count" => "seatCount",
|
||||
"reservationCount" => "reservationCount",
|
||||
"registrations" => "registrations",
|
||||
"hasFreeSeats" => "hasFreeSeats"
|
||||
];
|
||||
$fields['trainer'] = 'trainer';
|
||||
$fields['eventType'] = 'eventType';
|
||||
$fields['room'] = 'room';
|
||||
$fields['equipmentTypeAssignments'] = 'equipmentTypeAssignments';
|
||||
return $fields;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
17
customerapi/models/details/EventRegistrationView.php
Normal file
17
customerapi/models/details/EventRegistrationView.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace customerapi\models\details;
|
||||
|
||||
use common\models\EventRegistration;
|
||||
|
||||
class EventRegistrationView extends EventRegistration
|
||||
{
|
||||
|
||||
public function fields()
|
||||
{
|
||||
return [
|
||||
'id' => 'id',
|
||||
'created_at' => 'created_at',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user