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