fitness-web/customerapi/controllers/EventRegistrationController.php
2021-09-27 20:47:17 +02:00

86 lines
2.1 KiB
PHP

<?php
/**
* Created by IntelliJ IDEA.
* User: rocho
* Date: 2018.08.29.
* Time: 21:58
*/
namespace customerapi\controllers;
use customerapi\manager\EventRegistrationManager;
use common\models\CardEventRegistrationForm;
use common\models\Customer;
use Exception;
use Yii;
use yii\web\Response;
/** @noinspection PhpUnused */
class EventRegistrationController extends CustomerApiController
{
/** @noinspection PhpUnused */
/**
* @return Response
* @throws Exception
*/
public function actionIndex()
{
$registrationManager = new EventRegistrationManager();
return $this->asJson( $registrationManager->findCustomerRegistrationsWithEvent() );
}
/** @noinspection PhpUnused */
/***
* @param $id_registration
* @return Response
* @throws Exception
*/
public function actionRegistration($id_registration)
{
$registrationManager = new EventRegistrationManager();
return $this->asJson(
$registrationManager->findRegistration($id_registration)
);
}
/**
* @noinspection PhpUnused
* @param $id_event
*/
public function actionRegister($id_event) {
/** @var Customer $customer */
$customer = Yii::$app->user->getIdentity();
$card =$customer->card;
$form = new CardEventRegistrationForm();
$form->event_id = $id_event;
$form->card_number = $card->number;
$manager = new \common\manager\EventRegistrationManager();
$manager->registerCard($form);
return $form->registration;
}
/**
* Cancel a registration by id
* @noinspection PhpUnused
* @param $idRegistraton
* @throws Throwable
* @return Response
*/
public function actionCancel($idRegistration) {
$manager = new \common\manager\EventRegistrationManager();
$registration = $manager->loadRegistration($idRegistration);
$manager->deleteRegistration($registration);
$registration = $manager->loadRegistration($idRegistration);
return $this->asJson($registration);
}
}