minor changes

This commit is contained in:
Roland Schneider 2021-10-08 16:59:20 +02:00
parent 677166224b
commit 09f329050f
4 changed files with 66 additions and 48 deletions

View File

@ -46,22 +46,22 @@ class EventRegistrationManager extends BaseObject
const CANCEL_TIME_LIMIT_REACHED = 15; const CANCEL_TIME_LIMIT_REACHED = 15;
public static $STATES = [ public static $STATES = [
self::CARD_NOT_FOUND => "Kártya nem található", self::CARD_NOT_FOUND => "Kártya nem található",
self::CUSTOMER_NOT_FOUND => "Vendég nem található", self::CUSTOMER_NOT_FOUND => "Vendég nem található",
self::TICKET_NOT_FOUND => "Bérlet nem található", self::TICKET_NOT_FOUND => "Bérlet nem található",
self::NO_FREE_SEATS => "Nincs szabad hely", self::NO_FREE_SEATS => "Nincs szabad hely",
self::EVENT_TYPE_NOT_FOUND => "Esemény típus nem található", self::EVENT_TYPE_NOT_FOUND => "Esemény típus nem található",
self::TICKET_INSUFFICIENT => "Bérlet nem található", self::TICKET_INSUFFICIENT => "Bérlet nem található",
self::UNKNOWN_ERROR => "Ismeretlen hiba", self::UNKNOWN_ERROR => "Ismeretlen hiba",
self::MAX_SEAT_COUNT_EXCEEDED => "Nincs szabad hely", self::MAX_SEAT_COUNT_EXCEEDED => "Nincs szabad hely",
self::EVENT_UNAVAILABLE => "Esemény nem elérhető", self::EVENT_UNAVAILABLE => "Esemény nem elérhető",
self::ALREADY_REGISTERED => "Már regisztrálva van", self::ALREADY_REGISTERED => "Már regisztrálva van",
self::EVENT_START_DATE_IN_PAST => "Az esemény már elkezdődött", self::EVENT_START_DATE_IN_PAST => "Az esemény már elkezdődött",
self::EVENT_NOT_FOUND => "Esemény tnem található", self::EVENT_NOT_FOUND => "Esemény tnem található",
self::ALREADY_CANCELLED => "Ez a regisztráció már lemndásra került", self::ALREADY_CANCELLED => "Ez a regisztráció már lemndásra került",
self::ALREADY_DELETED => "Ez a regisztráció már törlésre került", self::ALREADY_DELETED => "Ez a regisztráció már törlésre került",
self::CANCEL_TIME_LIMIT_REACHED => "Ez a regisztráció már nem mondható le", self::CANCEL_TIME_LIMIT_REACHED => "Ez a regisztráció már nem mondható le",
]; ];
/** /**
@ -195,10 +195,12 @@ class EventRegistrationManager extends BaseObject
public function loadRegistration($idRegistration, $idCustomer) public function loadRegistration($idRegistration, $idCustomer)
{ {
$registration = EventRegistration::find() $query = EventRegistration::find()
->andWhere(['id' => $idRegistration]) ->andWhere(['id' => $idRegistration]);
->andWhere(['id_customer' => $idCustomer]) if ( isset($idCustomer)){
->one(); $query->andWhere(['id_customer' => $idCustomer])
}
$registration = $query->one();
if ($registration === null) { if ($registration === null) {
throw new NotFoundHttpException('The requested registration does not exist.'); throw new NotFoundHttpException('The requested registration does not exist.');
} }
@ -209,9 +211,9 @@ class EventRegistrationManager extends BaseObject
* @param EventRegistration $registration * @param EventRegistration $registration
* @throws ServerErrorHttpException * @throws ServerErrorHttpException
*/ */
public function cancelRegistration($registration, $idCustomer) public function cancelRegistration($registration, $idCustomer, $reason)
{ {
if ( $registration->id_customer != $idCustomer){ if (isset($idCustomer) && $registration->id_customer != $idCustomer) {
throw new NotFoundHttpException('The requested registration does not exist.'); throw new NotFoundHttpException('The requested registration does not exist.');
} }
@ -229,13 +231,16 @@ class EventRegistrationManager extends BaseObject
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(); $tx = \Yii::$app->db->beginTransaction();
try { $now = strtotime("now UTC");
$now = strtotime("now UTC");
if ($reason != EventRegistration::CANCEL_REASON_CUSTOMER) {
$timeUntilEventStart = $event->start - $now; $timeUntilEventStart = $event->start - $now;
if ( $timeUntilEventStart < 30 * 60){ if ($timeUntilEventStart < 30 * 60) {
throw new BadRequestHttpException('The reservation is already deleted', self::CANCEL_TIME_LIMIT_REACHED); throw new BadRequestHttpException('The reservation is already deleted', self::CANCEL_TIME_LIMIT_REACHED);
} }
}
try {
$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); $registration->save(false);
@ -310,7 +315,7 @@ class EventRegistrationManager extends BaseObject
foreach ($registrations as $registration) { foreach ($registrations as $registration) {
if (!isset($registration->deleted_at)) { if (!isset($registration->deleted_at)) {
/** @var EventRegistration $registration */ /** @var EventRegistration $registration */
$this->deleteRegistration($registration); $this->cancelRegistration($registration, null, EventRegistration::CANCEL_REASON_EVENT);
} }
} }
} }

View File

@ -21,6 +21,9 @@ use yii\helpers\ArrayHelper;
*/ */
class EventRegistration extends \yii\db\ActiveRecord class EventRegistration extends \yii\db\ActiveRecord
{ {
const CANCEL_REASON_CUSTOMER = "customer";
const CANCEL_REASON_EVENT = "event";
/** /**
* @inheritdoc * @inheritdoc
*/ */

View File

@ -7,6 +7,7 @@ use common\manager\EventRegistrationManager;
use common\models\CardEventRegistrationForm; use common\models\CardEventRegistrationForm;
use common\models\EventEquipmentType; use common\models\EventEquipmentType;
use common\models\EventEquipmentTypeAssignment; use common\models\EventEquipmentTypeAssignment;
use common\models\EventRegistration;
use common\models\EventRegistrationEquipmentTypeAssignment; use common\models\EventRegistrationEquipmentTypeAssignment;
use common\models\Trainer; use common\models\Trainer;
use common\modules\event\EventModule; use common\modules\event\EventModule;
@ -31,6 +32,7 @@ use yii\web\HttpException;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use yii\web\Response; use yii\web\Response;
use yii\web\UnauthorizedHttpException;
/** @noinspection PhpUnused */ /** @noinspection PhpUnused */
@ -127,6 +129,10 @@ class EventController extends Controller
*/ */
public function actionCreate() public function actionCreate()
{ {
if ( !RoleDefinition::canAny([RoleDefinition::$ROLE_TRAINER, RoleDefinition::$ROLE_ADMIN])){
throw new UnauthorizedHttpException();
}
$modelAndView = new CreateEventModelAndView(); $modelAndView = new CreateEventModelAndView();
$event = new EventCreate(); $event = new EventCreate();
@ -166,6 +172,9 @@ class EventController extends Controller
*/ */
public function actionUpdate($id) public function actionUpdate($id)
{ {
if ( !RoleDefinition::canAny([RoleDefinition::$ROLE_TRAINER, RoleDefinition::$ROLE_ADMIN])){
throw new UnauthorizedHttpException();
}
$modelAndView = new CreateEventModelAndView(); $modelAndView = new CreateEventModelAndView();
$event = EventCreate::findOne($id); $event = EventCreate::findOne($id);
if ( !isset($event)){ if ( !isset($event)){
@ -220,8 +229,8 @@ class EventController extends Controller
$db = Yii::$app->db; $db = Yii::$app->db;
$tx = $db->beginTransaction(); $tx = $db->beginTransaction();
try { try {
$registration = $eventRegistrationManager->loadRegistration($id); $registration = $eventRegistrationManager->loadRegistration($id,null);
$eventRegistrationManager->cancelRegistration($registration); $eventRegistrationManager->cancelRegistration($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) {
@ -230,26 +239,26 @@ class EventController extends Controller
} }
}/** @noinspection PhpUnused */ }/** @noinspection PhpUnused */
/** // /**
* @param $id // * @param $id
* @return Response // * @return Response
* @throws Exception // * @throws Exception
*/ // */
public function actionDeleteRegistration($id) // public function actionDeleteRegistration($id)
{ // {
$eventRegistrationManager = new EventRegistrationManager(); // $eventRegistrationManager = new EventRegistrationManager();
$db = Yii::$app->db; // $db = Yii::$app->db;
$tx = $db->beginTransaction(); // $tx = $db->beginTransaction();
try { // try {
$registration = $eventRegistrationManager->loadRegistration($id); // $registration = $eventRegistrationManager->loadRegistration($id);
$eventRegistrationManager->deleteRegistration($registration); // $eventRegistrationManager->deleteRegistration($registration);
$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) {
$tx->rollBack(); // $tx->rollBack();
throw $ex; // throw $ex;
} // }
}/** @noinspection PhpUnused */ // }/** @noinspection PhpUnused */
/** /**
* @param $id * @param $id

View File

@ -9,6 +9,7 @@
namespace customerapi\controllers; namespace customerapi\controllers;
use common\models\EventRegistration;
use customerapi\manager\EventRegistrationManager; use customerapi\manager\EventRegistrationManager;
use common\models\CardEventRegistrationForm; use common\models\CardEventRegistrationForm;
use common\models\Customer; use common\models\Customer;
@ -77,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); $manager->cancelRegistration($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);
} }