implement registration in backend
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
<?php
|
||||
namespace common\manager;
|
||||
use common\models\Card;
|
||||
use common\models\Customer;
|
||||
use common\models\Event;
|
||||
use common\models\EventRegistration;
|
||||
use common\models\Ticket;
|
||||
use yii\db\Query;
|
||||
use yii\web\BadRequestHttpException;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\web\ServerErrorHttpException;
|
||||
@@ -22,6 +25,8 @@ class EventRegistrationManager extends \yii\base\Object
|
||||
const NO_FREE_SEATS = 4;
|
||||
const EVENT_TYPE_NOT_FOUND = 5;
|
||||
const TICKET_INSUFFICIENT = 6;
|
||||
const UNKNOWN_ERROR = 7;
|
||||
const MAX_SEAT_COUNT_EXCEEDED = 8;
|
||||
|
||||
public static $STATES = [
|
||||
self::CARD_NOT_FOUND => "CARD_NOT_FOUND",
|
||||
@@ -30,6 +35,8 @@ class EventRegistrationManager extends \yii\base\Object
|
||||
self::NO_FREE_SEATS => "NO_FREE_SEATS",
|
||||
self::EVENT_TYPE_NOT_FOUND => "EVENT_TYPE_NOT_FOUND",
|
||||
self::TICKET_INSUFFICIENT => "TICKET_INSUFFICIENT",
|
||||
self::UNKNOWN_ERROR => "UNKNOWN_ERROR",
|
||||
self::MAX_SEAT_COUNT_EXCEEDED => "MAX_SEAT_COUNT_EXCEEDED",
|
||||
|
||||
|
||||
];
|
||||
@@ -39,6 +46,7 @@ class EventRegistrationManager extends \yii\base\Object
|
||||
* @throws NotFoundHttpException
|
||||
* @throws BadRequestHttpException
|
||||
* @throws ServerErrorHttpException
|
||||
* @throws \yii\web\HttpException
|
||||
*/
|
||||
public function registerCard($cardEventForm){
|
||||
|
||||
@@ -77,21 +85,85 @@ class EventRegistrationManager extends \yii\base\Object
|
||||
|
||||
$selectedTicket = $eventType->findTicketAllowingEventType($activeTickets);
|
||||
|
||||
|
||||
if ( !isset($selectedTicket) ){
|
||||
throw new NotFoundHttpException("Ticket not found", self::TICKET_INSUFFICIENT);
|
||||
}
|
||||
|
||||
if ( $selectedTicket->hasOpenReservationCount() ){
|
||||
$selectedTicket->consumeReservationCount(1);
|
||||
}
|
||||
$selectedTicket->save();
|
||||
|
||||
$registration = new EventRegistration();
|
||||
$registration->id_event = $event->id;
|
||||
$registration->id_card = $card->id_card;
|
||||
$registration->id_ticket = $selectedTicket->id_ticket;
|
||||
$registration->save(false);
|
||||
try{
|
||||
$registration->save(false);
|
||||
}catch (\Throwable $exception){
|
||||
throw new ServerErrorHttpException("Failed to save", self::UNKNOWN_ERROR);
|
||||
}
|
||||
|
||||
$cardEventForm->registration = $registration;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function createFindRegistrationsQuery($idEvent){
|
||||
$query = new Query();
|
||||
$query->select([
|
||||
"event_registration.id as event_registration_id",
|
||||
"event_registration.created_at as event_registration_created_at",
|
||||
"event_registration.canceled_at as event_registration_canceled_at",
|
||||
"card.number as card_number",
|
||||
"card.number as card_number",
|
||||
"customer.name as customer_name",
|
||||
"customer.email as customer_email",
|
||||
]);
|
||||
$query->from(EventRegistration::tableName());
|
||||
$query->innerJoin(Event::tableName(), "event_registration.id_event = event.id");
|
||||
$query->innerJoin(Card::tableName(), "event_registration.id_card = card.id_card");
|
||||
$query->innerJoin(Customer::tableName(), "customer.id_customer_card = card.id_card");
|
||||
$query->andWhere(["event_registration.id_event" => $idEvent ]);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $idRegistration
|
||||
* @return array|EventRegistration|\yii\db\ActiveRecord|null
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function loadRegistration($idRegistration) {
|
||||
|
||||
$registration = EventRegistration::find()->andWhere(['id' => $idRegistration ])->one();
|
||||
if ($registration == null) {
|
||||
throw new NotFoundHttpException('The requested registration does not exist.');
|
||||
}
|
||||
return $registration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \common\models\EventRegistration $registration
|
||||
* @throws ServerErrorHttpException
|
||||
*/
|
||||
public function cancelRegistration($registration){
|
||||
if ( isset($registration->canceled_at)){
|
||||
throw new ServerErrorHttpException('The registration is already canceled');
|
||||
}
|
||||
|
||||
$ticket = Ticket::findOne(['id' => $registration->id_ticket ]);
|
||||
|
||||
$ticket->restoreReservationCount(1);
|
||||
$ticket->save(false);
|
||||
|
||||
$registration->canceled_at = date('Y-m-d H:i:s' );
|
||||
$registration->save(false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user