add registrations to customer gui

This commit is contained in:
2020-01-01 21:05:37 +01:00
committed by Roland Schneider
parent 2c5db234ce
commit 753cd46b2c
34 changed files with 473 additions and 98 deletions

View File

@@ -13,8 +13,11 @@ use common\models\Event;
use customerapi\models\available\EventInterval;
use customerapi\models\available\EventAvailable;
use customerapi\models\DayToDisplay;
use customerapi\models\details\EventDetailsView;
use DateTime;
use Exception;
use yii\db\Query;
use yii\web\Response;
/** @noinspection PhpUnused */
@@ -82,7 +85,6 @@ class EventController extends CustomerApiController
}
}
return
$this->asJson([
'interval' => $interval,
@@ -90,4 +92,41 @@ class EventController extends CustomerApiController
]);
}
/**
* @param Query $query
* @param $interval
* @return the query with the added conditions
*/
private function buildEventQuery($query, $interval)
{
return $query
->innerJoinWith('trainer')
->innerJoinWith('eventType')
->innerJoinWith('room')
->joinWith('activeEventRegistrations')
->andWhere(['>=', 'event.start', $interval->firstActiveDate->getTimestamp()])
->andWhere(['<', 'event.start', (clone $interval->lastActiveDate)->modify('+1 day')->getTimestamp()])
->andWhere(['event.active' => '1']);
}
/**
* @param integer $id_event the id of the event
* @return Response the response
* @throws \yii\base\Exception on any error
* @throws Exception
*/
public function actionEvent($id_event)
{
$interval = EventInterval::createInterval();
try {
$query = EventDetailsView::find();
$query = $this->buildEventQuery($query, $interval);
$query = $query->andWhere(['event.id' => $id_event]);
$event = $query->one();
return $this->asJson($event);
} catch (Exception $e) {
throw new \yii\base\Exception($e->getMessage());
}
}
}

View File

@@ -13,9 +13,12 @@ use common\manager\EventRegistrationManager;
use common\models\CardEventRegistrationForm;
use common\models\Customer;
use customerapi\models\available\EventInterval;
use customerapi\models\available\EventRegistrationAvailable;
use customerapi\models\registrations\EventRegistrationAvailable;
use Exception;
use Throwable;
use Yii;
use yii\db\ActiveQuery;
use yii\web\Response;
/** @noinspection PhpUnused */
@@ -23,37 +26,62 @@ class EventRegistrationController extends CustomerApiController
{
/** @noinspection PhpUnused */
/**
* @return Response
* @throws Exception
*/
public function actionIndex()
{
$interval = EventInterval::createInterval();
$registrations = EventRegistrationAvailable::find()
->innerJoinWith('event')
->andWhere(['and',
['>=', 'event.start', $interval->firstActiveDate->getTimestamp()],
['<', 'event.start', $interval->lastActiveDate->getTimestamp()],
['id_customer' => Yii::$app->user->getId()]
])->all();
$registrations =$this->prepareQueryFindRegistrationsForCustomer()->all();
return $this->asJson( $registrations );
}
/** @noinspection PhpUnused */
/***
* @param $id_registration
* @return Response
* @throws Exception
*/
public function actionRegistration($id_registration)
{
$registrations = $this->prepareQueryFindRegistrationsForCustomer()
->andWhere(['id_event_registration' => $id_registration])
->one();
return $this->asJson(
$registrations
);
}
/**
* Prepare a query to get registrations for customer
*
* @return ActiveQuery
* @throws Exception
*/
private function prepareQueryFindRegistrationsForCustomer(){
$interval = EventInterval::createInterval();
return EventRegistrationAvailable::find()
->innerJoinWith('event')
->andWhere(['and',
['>=', 'event.start', $interval->firstActiveDate->getTimestamp()],
['id_customer' => Yii::$app->user->getId()]
]);
}
/**
* @noinspection PhpUnused
* @param $idEvent
* @param $id_event
* @throws Throwable
*/
public function actionRegister($idEvent) {
public function actionRegister($id_event) {
/** @var Customer $customer */
$customer = Yii::$app->user->getIdentity();
$card =$customer->card;
$form = new CardEventRegistrationForm();
$form->event_id = $idEvent;
$form->event_id = $id_event;
$form->card_number = $card->number;
$manager = new EventRegistrationManager();

View File

@@ -5,7 +5,6 @@ namespace customerapi\models\available;
use common\models\Event;
use common\models\EventType;
class EventAvailable extends Event
{

View File

@@ -1,13 +0,0 @@
<?php
namespace customerapi\models\available;
use common\models\EventRegistration;
class EventRegistrationAvailable extends EventRegistration
{
}

View File

@@ -0,0 +1,56 @@
<?php
namespace customerapi\models\details;
use common\models\Event;
class EventDetailsView extends Event
{
public $reservationCount;
/**
* @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;
}
/**
* @Override
* @return array|false
*/
function fields()
{
$fields = [
"id" => "id",
"start" => "start",
"end" => "end",
"seat_count" => "seat_count",
"active" => "active",
// "reservationCount" => "reservationCount"
];
$fields['trainer'] = 'trainer';
$fields['eventType'] = 'eventType';
$fields['room'] = 'room';
return $fields;
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace customerapi\models\details;
use common\models\EventType;
class EventTypeDetailsView extends EventType
{
function fields()
{
return [
'id' => 'id',
'name' => 'name'
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace customerapi\models\details;
use common\models\Room;
class RoomDetailsView extends Room
{
function fields()
{
return [
'id' => 'id',
'name' => 'name',
'seat_count' => 'seat_count'
];
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace customerapi\models\details;
use common\models\Trainer;
class TrainerDetailsView extends Trainer
{
public function fields()
{
return [
'id' => 'id',
'name' => 'name'
];
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace customerapi\models\registrations;
use common\models\EventRegistration;
use customerapi\models\available\EventAvailable;
class EventRegistrationAvailable extends EventRegistration
{
function fields()
{
$fields = [
"id" => "id",
"created_at" => "created_at",
"updated_at" => "updated_at",
];
$fields['event'] = 'event';
return $fields;
}
public function getEventClass()
{
return EventAvailable::class;
}
}