improve event deletion and event registration cancelation
This commit is contained in:
parent
09f329050f
commit
f0bf8684e4
@ -194,11 +194,10 @@ class EventRegistrationManager extends BaseObject
|
|||||||
*/
|
*/
|
||||||
public function loadRegistration($idRegistration, $idCustomer)
|
public function loadRegistration($idRegistration, $idCustomer)
|
||||||
{
|
{
|
||||||
|
|
||||||
$query = EventRegistration::find()
|
$query = EventRegistration::find()
|
||||||
->andWhere(['id' => $idRegistration]);
|
->andWhere(['id' => $idRegistration]);
|
||||||
if ( isset($idCustomer)){
|
if (isset($idCustomer)) {
|
||||||
$query->andWhere(['id_customer' => $idCustomer])
|
$query->andWhere(['id_customer' => $idCustomer]);
|
||||||
}
|
}
|
||||||
$registration = $query->one();
|
$registration = $query->one();
|
||||||
if ($registration === null) {
|
if ($registration === null) {
|
||||||
@ -207,6 +206,18 @@ class EventRegistrationManager extends BaseObject
|
|||||||
return $registration;
|
return $registration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function cancelRegistrationTX($registration, $idCustomer, $reason)
|
||||||
|
{
|
||||||
|
$tx = \Yii::$app->db->beginTransaction();
|
||||||
|
try {
|
||||||
|
$this->cancelRegistration($registration, $idCustomer, $reason);
|
||||||
|
$tx->commit();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$tx->rollBack();
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param EventRegistration $registration
|
* @param EventRegistration $registration
|
||||||
* @throws ServerErrorHttpException
|
* @throws ServerErrorHttpException
|
||||||
@ -230,7 +241,7 @@ class EventRegistrationManager extends BaseObject
|
|||||||
if (!isset($event)) {
|
if (!isset($event)) {
|
||||||
throw new BadRequestHttpException('The reservation is already deleted', self::EVENT_NOT_FOUND);
|
throw new BadRequestHttpException('The reservation is already deleted', self::EVENT_NOT_FOUND);
|
||||||
}
|
}
|
||||||
$tx = \Yii::$app->db->beginTransaction();
|
|
||||||
$now = strtotime("now UTC");
|
$now = strtotime("now UTC");
|
||||||
|
|
||||||
if ($reason != EventRegistration::CANCEL_REASON_CUSTOMER) {
|
if ($reason != EventRegistration::CANCEL_REASON_CUSTOMER) {
|
||||||
@ -240,11 +251,16 @@ class EventRegistrationManager extends BaseObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
$now = strtotime("now");
|
||||||
|
// if user cancels then cancel_at will be set
|
||||||
|
if ( $reason == EventRegistration::CANCEL_REASON_CUSTOMER){
|
||||||
$registration->canceled_at = date('Y-m-d H:i:s', $now);
|
$registration->canceled_at = date('Y-m-d H:i:s', $now);
|
||||||
$registration->save(false);
|
}else{
|
||||||
|
// otherwise ( e.g. event is deleted ) the delete_at will be set
|
||||||
|
$registration->deleted_at = date('Y-m-d H:i:s', $now);
|
||||||
|
}
|
||||||
|
|
||||||
|
$registration->save(false);
|
||||||
$ticket = Ticket::findOne($registration->id_ticket);
|
$ticket = Ticket::findOne($registration->id_ticket);
|
||||||
|
|
||||||
if (!isset($ticket)) {
|
if (!isset($ticket)) {
|
||||||
@ -254,37 +270,24 @@ class EventRegistrationManager extends BaseObject
|
|||||||
$ticket->restoreReservationCount(1);
|
$ticket->restoreReservationCount(1);
|
||||||
$ticket->save(false);
|
$ticket->save(false);
|
||||||
|
|
||||||
$tx->commit();
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$tx->rollBack();
|
|
||||||
throw $e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function findAllRegistrations($idEvent, $idCustomer = null)
|
||||||
|
{
|
||||||
|
$registrations =
|
||||||
|
EventRegistration::find()
|
||||||
|
->andWhere(['id_event' => $idEvent])->all();
|
||||||
|
if (isset($idCustomer)) {
|
||||||
|
$registrations = EventRegistration::filterForCustomer($registrations, $idCustomer);
|
||||||
|
}
|
||||||
|
return $registrations;
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
public function findActiveRegistrations($idEvent, $idCustomer = null)
|
||||||
// * @param EventRegistration $registration
|
{
|
||||||
// * @return bool
|
$registrations = $this->findAllRegistrations($idEvent, $idCustomer);
|
||||||
// * @throws \yii\base\Exception
|
return EventRegistration::filterActive($registrations);
|
||||||
// */
|
}
|
||||||
// public function deleteRegistration($registration)
|
|
||||||
// {
|
|
||||||
// if (isset($registration->deleted_at)) {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//// $ticket = Ticket::findOne(['id_ticket' => $registration->id_ticket]);
|
|
||||||
//// if( !isset($ticket ) ) {
|
|
||||||
//// throw new \yii\base\Exception('Ticket not found: ' . $registration->id_ticket);
|
|
||||||
//// }
|
|
||||||
////
|
|
||||||
//// $ticket->restoreReservationCount(1);
|
|
||||||
//// $ticket->save(false);
|
|
||||||
//
|
|
||||||
// $registration->deleted_at = date('Y-m-d H:i:s');
|
|
||||||
// return $registration->save(false);
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete an event
|
* Delete an event
|
||||||
@ -298,12 +301,15 @@ class EventRegistrationManager extends BaseObject
|
|||||||
$tx = $db->beginTransaction();
|
$tx = $db->beginTransaction();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$registrations = $event->getEventRegistrations()->all();
|
$eventRegistrationManager = new EventRegistrationManager();
|
||||||
|
$allRegistrations = $eventRegistrationManager->findAllRegistrations($event->id);
|
||||||
|
$activeRegistrations = $eventRegistrationManager->findActiveRegistrations($event->id);
|
||||||
|
|
||||||
// ////////////////////////////////
|
// ////////////////////////////////
|
||||||
// if event has no registrations
|
// if event has no registrations
|
||||||
// we can simply delete it from db
|
// we can simply delete it from db
|
||||||
// ////////////////////////////////
|
// ////////////////////////////////
|
||||||
if (count($registrations) === 0) {
|
if (count($allRegistrations) === 0) {
|
||||||
$event->delete();
|
$event->delete();
|
||||||
} else {
|
} else {
|
||||||
// /////////////////////////////
|
// /////////////////////////////
|
||||||
@ -312,7 +318,7 @@ class EventRegistrationManager extends BaseObject
|
|||||||
// /////////////////////////////
|
// /////////////////////////////
|
||||||
$event->deleted_at = date('Y-m-d H:i:s');
|
$event->deleted_at = date('Y-m-d H:i:s');
|
||||||
$event->save(false);
|
$event->save(false);
|
||||||
foreach ($registrations as $registration) {
|
foreach ($activeRegistrations as $registration) {
|
||||||
if (!isset($registration->deleted_at)) {
|
if (!isset($registration->deleted_at)) {
|
||||||
/** @var EventRegistration $registration */
|
/** @var EventRegistration $registration */
|
||||||
$this->cancelRegistration($registration, null, EventRegistration::CANCEL_REASON_EVENT);
|
$this->cancelRegistration($registration, null, EventRegistration::CANCEL_REASON_EVENT);
|
||||||
|
|||||||
@ -230,7 +230,7 @@ class EventController extends Controller
|
|||||||
$tx = $db->beginTransaction();
|
$tx = $db->beginTransaction();
|
||||||
try {
|
try {
|
||||||
$registration = $eventRegistrationManager->loadRegistration($id,null);
|
$registration = $eventRegistrationManager->loadRegistration($id,null);
|
||||||
$eventRegistrationManager->cancelRegistration($registration,null,EventRegistration::CANCEL_REASON_CUSTOMER);
|
$eventRegistrationManager->cancelRegistrationTX($registration,null,EventRegistration::CANCEL_REASON_CUSTOMER);
|
||||||
$tx->commit();
|
$tx->commit();
|
||||||
return $this->redirect(['view', 'id' => $registration->id_event]);
|
return $this->redirect(['view', 'id' => $registration->id_event]);
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
|
|||||||
@ -153,6 +153,9 @@ $indexTableTemplateButtons[] = '{reserve-card}';
|
|||||||
'aria-label' => Yii::t('yii', 'Register'),
|
'aria-label' => Yii::t('yii', 'Register'),
|
||||||
'data-pjax' => '0',
|
'data-pjax' => '0',
|
||||||
];
|
];
|
||||||
|
if ( isset($model['event_deleted_at']) ){
|
||||||
|
return "";
|
||||||
|
}
|
||||||
return Html::a('<span class="glyphicon glyphicon-user"></span>', $url, $options);
|
return Html::a('<span class="glyphicon glyphicon-user"></span>', $url, $options);
|
||||||
},
|
},
|
||||||
// 'equipment-types-assignment' => function ($url, $model, $key) {
|
// 'equipment-types-assignment' => function ($url, $model, $key) {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
|
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
|
||||||
import {Event} from "../../services/event.service";
|
import {Event} from "../../services/event.service";
|
||||||
import { MonthCalendarEvent} from "../month-calendar/month-calendar.component";
|
import {MonthCalendarEvent} from "../month-calendar/month-calendar.component";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-month-calendar-event',
|
selector: 'app-month-calendar-event',
|
||||||
@ -53,6 +53,10 @@ export class MonthCalendarEventComponent implements OnInit {
|
|||||||
|
|
||||||
const theme = this.event?.eventType?.theme;
|
const theme = this.event?.eventType?.theme;
|
||||||
let styleClass = "bg-dark";
|
let styleClass = "bg-dark";
|
||||||
|
if (this.event.deleted_at) {
|
||||||
|
styleClass = "bg-secondary";
|
||||||
|
} else {
|
||||||
|
|
||||||
if (this.isDisabled()) {
|
if (this.isDisabled()) {
|
||||||
styleClass = "bg-secondary";
|
styleClass = "bg-secondary";
|
||||||
} else {
|
} else {
|
||||||
@ -70,6 +74,7 @@ export class MonthCalendarEventComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return styleClass;
|
return styleClass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,10 @@
|
|||||||
<div class="col-lg-3 col-12 app-font-weight-bold"><span class="title">Terem</span></div>
|
<div class="col-lg-3 col-12 app-font-weight-bold"><span class="title">Terem</span></div>
|
||||||
<div class="col-lg-6 col-12"><span>{{event?.room?.name }}</span></div>
|
<div class="col-lg-6 col-12"><span>{{event?.room?.name }}</span></div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row" *ngIf="event?.deleted_at">
|
||||||
|
<div class="col-lg-3 col-12 app-font-weight-bold"><span class="title">Törölve</span></div>
|
||||||
|
<div class="col-lg-6 col-12"><span>{{ event.deleted_at | eventDate:'datetime' }}</span></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class=" col-lg-6 col-sm-12 pt-2">
|
<div class=" col-lg-6 col-sm-12 pt-2">
|
||||||
|
|||||||
@ -49,7 +49,7 @@ export class EventDetailsComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mayRegister(event: Event) {
|
mayRegister(event: Event) {
|
||||||
return event.hasFreeSeats && event.registrations.length == 0;
|
return event.hasFreeSeats && !event.deleted_at && event.registrations.length == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
mayCancel(event: Event) {
|
mayCancel(event: Event) {
|
||||||
|
|||||||
@ -58,6 +58,7 @@ export interface Event {
|
|||||||
name: string;
|
name: string;
|
||||||
start: number;
|
start: number;
|
||||||
end: number;
|
end: number;
|
||||||
|
deleted_at?: number;
|
||||||
trainer?: Trainer;
|
trainer?: Trainer;
|
||||||
seat_count: number;
|
seat_count: number;
|
||||||
reservationCount: number;
|
reservationCount: number;
|
||||||
|
|||||||
@ -10,6 +10,7 @@ namespace customerapi\controllers;
|
|||||||
|
|
||||||
|
|
||||||
use common\helpers\AppArrayHelper;
|
use common\helpers\AppArrayHelper;
|
||||||
|
use common\helpers\AppDateTimeHelper;
|
||||||
use common\models\Event;
|
use common\models\Event;
|
||||||
use common\models\EventRegistration;
|
use common\models\EventRegistration;
|
||||||
use common\models\EventType;
|
use common\models\EventType;
|
||||||
@ -140,6 +141,7 @@ class EventController extends \customerapi\controllers\CustomerApiController
|
|||||||
$result->id = $event->id;
|
$result->id = $event->id;
|
||||||
$result->start = $event->start;
|
$result->start = $event->start;
|
||||||
$result->end = $event->end;
|
$result->end = $event->end;
|
||||||
|
$result->deleted_at =AppDateTimeHelper::convertMySqlDatetimeToPhpInteger( $event->deleted_at);
|
||||||
$result->seatCount = $event->seat_count;
|
$result->seatCount = $event->seat_count;
|
||||||
$result->trainer = TrainerDetailsView::findOne($event->id_trainer);
|
$result->trainer = TrainerDetailsView::findOne($event->id_trainer);
|
||||||
$result->room = RoomDetailsView::findOne($event->id_room);
|
$result->room = RoomDetailsView::findOne($event->id_room);
|
||||||
|
|||||||
@ -78,7 +78,7 @@ class EventRegistrationController extends CustomerApiController
|
|||||||
public function actionCancel($idRegistration) {
|
public function actionCancel($idRegistration) {
|
||||||
$manager = new \common\manager\EventRegistrationManager();
|
$manager = new \common\manager\EventRegistrationManager();
|
||||||
$registration = $manager->loadRegistration($idRegistration,\Yii::$app->user->id);
|
$registration = $manager->loadRegistration($idRegistration,\Yii::$app->user->id);
|
||||||
$manager->cancelRegistration($registration,\Yii::$app->user->id, EventRegistration::CANCEL_REASON_CUSTOMER);
|
$manager->cancelRegistrationTX($registration,\Yii::$app->user->id, EventRegistration::CANCEL_REASON_CUSTOMER);
|
||||||
$registration = $manager->loadRegistration($idRegistration,\Yii::$app->user->id);
|
$registration = $manager->loadRegistration($idRegistration,\Yii::$app->user->id);
|
||||||
return $this->asJson($registration);
|
return $this->asJson($registration);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
namespace customerapi\models\available;
|
namespace customerapi\models\available;
|
||||||
|
|
||||||
|
|
||||||
|
use common\helpers\AppDateTimeHelper;
|
||||||
use common\models\Event;
|
use common\models\Event;
|
||||||
use common\models\EventRegistration;
|
use common\models\EventRegistration;
|
||||||
use common\models\EventType;
|
use common\models\EventType;
|
||||||
@ -41,8 +42,8 @@ class EventAvailable extends Model
|
|||||||
$available->end = $event->end;
|
$available->end = $event->end;
|
||||||
$available->seat_count = $event->seat_count;
|
$available->seat_count = $event->seat_count;
|
||||||
$available->created_at = $event->created_at;
|
$available->created_at = $event->created_at;
|
||||||
$available->updated_at = $event->updated_at;
|
$available->updated_at = AppDateTimeHelper::convertMySqlDatetimeToPhpInteger($event->updated_at);
|
||||||
$available->deleted_at = $event->deleted_at;
|
$available->deleted_at = AppDateTimeHelper::convertMySqlDatetimeToPhpInteger($event->deleted_at);
|
||||||
$available->active = $event->active;
|
$available->active = $event->active;
|
||||||
|
|
||||||
return $available;
|
return $available;
|
||||||
@ -55,6 +56,7 @@ class EventAvailable extends Model
|
|||||||
"id" => "id",
|
"id" => "id",
|
||||||
"start" => "start",
|
"start" => "start",
|
||||||
"end" => "end",
|
"end" => "end",
|
||||||
|
"deleted_at" => "deleted_at",
|
||||||
"seat_count" => "seat_count",
|
"seat_count" => "seat_count",
|
||||||
"active" => "active",
|
"active" => "active",
|
||||||
"reservationCount" => "registrationCount",
|
"reservationCount" => "registrationCount",
|
||||||
|
|||||||
@ -24,6 +24,7 @@ class EventDetailsView extends Model // extends Event
|
|||||||
public $id;
|
public $id;
|
||||||
public $start;
|
public $start;
|
||||||
public $end;
|
public $end;
|
||||||
|
public $deleted_at;
|
||||||
public $seatCount;
|
public $seatCount;
|
||||||
// total count of registrations
|
// total count of registrations
|
||||||
public $reservationCount;
|
public $reservationCount;
|
||||||
@ -50,6 +51,7 @@ class EventDetailsView extends Model // extends Event
|
|||||||
"start" => "start",
|
"start" => "start",
|
||||||
"end" => "end",
|
"end" => "end",
|
||||||
"seat_count" => "seatCount",
|
"seat_count" => "seatCount",
|
||||||
|
"deleted_at" =>"deleted_at",
|
||||||
"reservationCount" => "reservationCount",
|
"reservationCount" => "reservationCount",
|
||||||
"registrations" => "registrations",
|
"registrations" => "registrations",
|
||||||
"hasFreeSeats" => "hasFreeSeats"
|
"hasFreeSeats" => "hasFreeSeats"
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace customerapi\models\dto;
|
namespace customerapi\models\dto;
|
||||||
|
|
||||||
|
use common\helpers\AppDateTimeHelper;
|
||||||
use customerapi\models\available\EventAvailable;
|
use customerapi\models\available\EventAvailable;
|
||||||
|
|
||||||
class EventDTO extends \yii\base\Model
|
class EventDTO extends \yii\base\Model
|
||||||
@ -28,6 +29,7 @@ class EventDTO extends \yii\base\Model
|
|||||||
"id" => "id",
|
"id" => "id",
|
||||||
"start" => "start",
|
"start" => "start",
|
||||||
"end" => "end",
|
"end" => "end",
|
||||||
|
"deleted_at" => "deleted_at",
|
||||||
"seat_count" => "seat_count",
|
"seat_count" => "seat_count",
|
||||||
"active" => "active",
|
"active" => "active",
|
||||||
"reservationCount" => "registrationCount",
|
"reservationCount" => "registrationCount",
|
||||||
@ -53,7 +55,8 @@ class EventDTO extends \yii\base\Model
|
|||||||
$dto->seat_count = $event->seat_count;
|
$dto->seat_count = $event->seat_count;
|
||||||
$dto->created_at = $event->created_at;
|
$dto->created_at = $event->created_at;
|
||||||
$dto->updated_at = $event->updated_at;
|
$dto->updated_at = $event->updated_at;
|
||||||
$dto->deleted_at = $event->deleted_at;
|
$dto->deleted_at = AppDateTimeHelper::convertMySqlDatetimeToPhpInteger($event->deleted_at);
|
||||||
|
|
||||||
$dto->active = $event->active;
|
$dto->active = $event->active;
|
||||||
|
|
||||||
return $dto;
|
return $dto;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user