minor changes
This commit is contained in:
parent
677166224b
commit
09f329050f
@ -195,10 +195,12 @@ class EventRegistrationManager extends BaseObject
|
||||
public function loadRegistration($idRegistration, $idCustomer)
|
||||
{
|
||||
|
||||
$registration = EventRegistration::find()
|
||||
->andWhere(['id' => $idRegistration])
|
||||
->andWhere(['id_customer' => $idCustomer])
|
||||
->one();
|
||||
$query = EventRegistration::find()
|
||||
->andWhere(['id' => $idRegistration]);
|
||||
if ( isset($idCustomer)){
|
||||
$query->andWhere(['id_customer' => $idCustomer])
|
||||
}
|
||||
$registration = $query->one();
|
||||
if ($registration === null) {
|
||||
throw new NotFoundHttpException('The requested registration does not exist.');
|
||||
}
|
||||
@ -209,9 +211,9 @@ class EventRegistrationManager extends BaseObject
|
||||
* @param EventRegistration $registration
|
||||
* @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.');
|
||||
}
|
||||
|
||||
@ -229,13 +231,16 @@ class EventRegistrationManager extends BaseObject
|
||||
throw new BadRequestHttpException('The reservation is already deleted', self::EVENT_NOT_FOUND);
|
||||
}
|
||||
$tx = \Yii::$app->db->beginTransaction();
|
||||
try {
|
||||
$now = strtotime("now UTC");
|
||||
|
||||
if ($reason != EventRegistration::CANCEL_REASON_CUSTOMER) {
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$registration->canceled_at = date('Y-m-d H:i:s', $now);
|
||||
$registration->save(false);
|
||||
@ -310,7 +315,7 @@ class EventRegistrationManager extends BaseObject
|
||||
foreach ($registrations as $registration) {
|
||||
if (!isset($registration->deleted_at)) {
|
||||
/** @var EventRegistration $registration */
|
||||
$this->deleteRegistration($registration);
|
||||
$this->cancelRegistration($registration, null, EventRegistration::CANCEL_REASON_EVENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,9 @@ use yii\helpers\ArrayHelper;
|
||||
*/
|
||||
class EventRegistration extends \yii\db\ActiveRecord
|
||||
{
|
||||
const CANCEL_REASON_CUSTOMER = "customer";
|
||||
const CANCEL_REASON_EVENT = "event";
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
||||
@ -7,6 +7,7 @@ use common\manager\EventRegistrationManager;
|
||||
use common\models\CardEventRegistrationForm;
|
||||
use common\models\EventEquipmentType;
|
||||
use common\models\EventEquipmentTypeAssignment;
|
||||
use common\models\EventRegistration;
|
||||
use common\models\EventRegistrationEquipmentTypeAssignment;
|
||||
use common\models\Trainer;
|
||||
use common\modules\event\EventModule;
|
||||
@ -31,6 +32,7 @@ use yii\web\HttpException;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\web\Response;
|
||||
use yii\web\UnauthorizedHttpException;
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
|
||||
@ -127,6 +129,10 @@ class EventController extends Controller
|
||||
*/
|
||||
public function actionCreate()
|
||||
{
|
||||
if ( !RoleDefinition::canAny([RoleDefinition::$ROLE_TRAINER, RoleDefinition::$ROLE_ADMIN])){
|
||||
throw new UnauthorizedHttpException();
|
||||
}
|
||||
|
||||
$modelAndView = new CreateEventModelAndView();
|
||||
|
||||
$event = new EventCreate();
|
||||
@ -166,6 +172,9 @@ class EventController extends Controller
|
||||
*/
|
||||
public function actionUpdate($id)
|
||||
{
|
||||
if ( !RoleDefinition::canAny([RoleDefinition::$ROLE_TRAINER, RoleDefinition::$ROLE_ADMIN])){
|
||||
throw new UnauthorizedHttpException();
|
||||
}
|
||||
$modelAndView = new CreateEventModelAndView();
|
||||
$event = EventCreate::findOne($id);
|
||||
if ( !isset($event)){
|
||||
@ -220,8 +229,8 @@ class EventController extends Controller
|
||||
$db = Yii::$app->db;
|
||||
$tx = $db->beginTransaction();
|
||||
try {
|
||||
$registration = $eventRegistrationManager->loadRegistration($id);
|
||||
$eventRegistrationManager->cancelRegistration($registration);
|
||||
$registration = $eventRegistrationManager->loadRegistration($id,null);
|
||||
$eventRegistrationManager->cancelRegistration($registration,null,EventRegistration::CANCEL_REASON_CUSTOMER);
|
||||
$tx->commit();
|
||||
return $this->redirect(['view', 'id' => $registration->id_event]);
|
||||
} catch (Exception $ex) {
|
||||
@ -230,26 +239,26 @@ class EventController extends Controller
|
||||
}
|
||||
}/** @noinspection PhpUnused */
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return Response
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionDeleteRegistration($id)
|
||||
{
|
||||
$eventRegistrationManager = new EventRegistrationManager();
|
||||
$db = Yii::$app->db;
|
||||
$tx = $db->beginTransaction();
|
||||
try {
|
||||
$registration = $eventRegistrationManager->loadRegistration($id);
|
||||
$eventRegistrationManager->deleteRegistration($registration);
|
||||
$tx->commit();
|
||||
return $this->redirect(['view', 'id' => $registration->id_event]);
|
||||
} catch (Exception $ex) {
|
||||
$tx->rollBack();
|
||||
throw $ex;
|
||||
}
|
||||
}/** @noinspection PhpUnused */
|
||||
// /**
|
||||
// * @param $id
|
||||
// * @return Response
|
||||
// * @throws Exception
|
||||
// */
|
||||
// public function actionDeleteRegistration($id)
|
||||
// {
|
||||
// $eventRegistrationManager = new EventRegistrationManager();
|
||||
// $db = Yii::$app->db;
|
||||
// $tx = $db->beginTransaction();
|
||||
// try {
|
||||
// $registration = $eventRegistrationManager->loadRegistration($id);
|
||||
// $eventRegistrationManager->deleteRegistration($registration);
|
||||
// $tx->commit();
|
||||
// return $this->redirect(['view', 'id' => $registration->id_event]);
|
||||
// } catch (Exception $ex) {
|
||||
// $tx->rollBack();
|
||||
// throw $ex;
|
||||
// }
|
||||
// }/** @noinspection PhpUnused */
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
namespace customerapi\controllers;
|
||||
|
||||
|
||||
use common\models\EventRegistration;
|
||||
use customerapi\manager\EventRegistrationManager;
|
||||
use common\models\CardEventRegistrationForm;
|
||||
use common\models\Customer;
|
||||
@ -77,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);
|
||||
$manager->cancelRegistration($registration,\Yii::$app->user->id, EventRegistration::CANCEL_REASON_CUSTOMER);
|
||||
$registration = $manager->loadRegistration($idRegistration,\Yii::$app->user->id);
|
||||
return $this->asJson($registration);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user