86 lines
2.1 KiB
PHP
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($idRegistraton) {
|
|
$manager = new EventRegistrationManager();
|
|
$registration = $manager->loadRegistration($idRegistraton);
|
|
$manager->deleteRegistration($registration);
|
|
$registration = $manager->loadRegistration($idRegistraton);
|
|
return $this->asJson($registration);
|
|
}
|
|
|
|
}
|