implement registration
This commit is contained in:
parent
b6e590f196
commit
b2bb210cee
@ -2,10 +2,13 @@
|
|||||||
|
|
||||||
namespace backend\controllers;
|
namespace backend\controllers;
|
||||||
|
|
||||||
|
use common\manager\EventRegistrationManager;
|
||||||
|
use common\models\CardEventRegistrationForm;
|
||||||
use Yii;
|
use Yii;
|
||||||
use common\models\Event;
|
use common\models\Event;
|
||||||
use backend\models\EventSearch;
|
use backend\models\EventSearch;
|
||||||
use yii\web\Controller;
|
use yii\web\Controller;
|
||||||
|
use yii\web\HttpException;
|
||||||
use yii\web\NotFoundHttpException;
|
use yii\web\NotFoundHttpException;
|
||||||
use yii\filters\VerbFilter;
|
use yii\filters\VerbFilter;
|
||||||
|
|
||||||
@ -95,6 +98,8 @@ class EventController extends Controller
|
|||||||
* If deletion is successful, the browser will be redirected to the 'index' page.
|
* If deletion is successful, the browser will be redirected to the 'index' page.
|
||||||
* @param integer $id
|
* @param integer $id
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
* @throws NotFoundHttpException
|
||||||
|
* @throws \yii\db\StaleObjectException
|
||||||
*/
|
*/
|
||||||
public function actionDelete($id)
|
public function actionDelete($id)
|
||||||
{
|
{
|
||||||
@ -103,6 +108,31 @@ class EventController extends Controller
|
|||||||
return $this->redirect(['index']);
|
return $this->redirect(['index']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function actionRegisterCard($id){
|
||||||
|
$model = new CardEventRegistrationForm();
|
||||||
|
$model->event_id = $id;
|
||||||
|
if ($model->load(Yii::$app->request->post()) && $model->validate() ) {
|
||||||
|
$manager = new EventRegistrationManager();
|
||||||
|
try {
|
||||||
|
$manager->registerCard($model);
|
||||||
|
} catch (HttpException $e) {
|
||||||
|
if ( array_key_exists($e->getCode(),EventRegistrationManager::$STATES)) {
|
||||||
|
$model->addError("id_event", Yii::t('event-registration', EventRegistrationManager::$STATES[$e->getCode()]));
|
||||||
|
} else {
|
||||||
|
$model->addError("id_event", Yii::t('event-registration', "Unknown Error"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( $model->hasErrors() ){
|
||||||
|
return $this->redirect(['view', 'id' => $model->registration->id]);
|
||||||
|
} else {
|
||||||
|
return $this->render('register_card', [
|
||||||
|
'model' => $model,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the Event model based on its primary key value.
|
* Finds the Event model based on its primary key value.
|
||||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||||
|
|||||||
@ -2,12 +2,17 @@
|
|||||||
|
|
||||||
namespace backend\controllers;
|
namespace backend\controllers;
|
||||||
|
|
||||||
|
use common\manager\EventRegistrationManager;
|
||||||
|
use common\models\CardEventRegistrationForm;
|
||||||
use Yii;
|
use Yii;
|
||||||
use common\models\EventRegistration;
|
use common\models\EventRegistration;
|
||||||
use backend\models\EventRegistrationSearch;
|
use backend\models\EventRegistrationSearch;
|
||||||
|
use yii\web\BadRequestHttpException;
|
||||||
use yii\web\Controller;
|
use yii\web\Controller;
|
||||||
|
use yii\web\HttpException;
|
||||||
use yii\web\NotFoundHttpException;
|
use yii\web\NotFoundHttpException;
|
||||||
use yii\filters\VerbFilter;
|
use yii\filters\VerbFilter;
|
||||||
|
use yii\web\ServerErrorHttpException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EventRegistrationController implements the CRUD actions for EventRegistration model.
|
* EventRegistrationController implements the CRUD actions for EventRegistration model.
|
||||||
@ -95,6 +100,8 @@ class EventRegistrationController extends Controller
|
|||||||
* If deletion is successful, the browser will be redirected to the 'index' page.
|
* If deletion is successful, the browser will be redirected to the 'index' page.
|
||||||
* @param integer $id
|
* @param integer $id
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
* @throws NotFoundHttpException
|
||||||
|
* @throws \yii\db\StaleObjectException
|
||||||
*/
|
*/
|
||||||
public function actionDelete($id)
|
public function actionDelete($id)
|
||||||
{
|
{
|
||||||
@ -103,6 +110,29 @@ class EventRegistrationController extends Controller
|
|||||||
return $this->redirect(['index']);
|
return $this->redirect(['index']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function actionRegisterCard(){
|
||||||
|
$model = new CardEventRegistrationForm();
|
||||||
|
if ($model->load(Yii::$app->request->post()) && $model->validate() ) {
|
||||||
|
$manager = new EventRegistrationManager();
|
||||||
|
try {
|
||||||
|
$manager->registerCard($model);
|
||||||
|
} catch (HttpException $e) {
|
||||||
|
if ( array_key_exists($e->getCode(),EventRegistrationManager::$STATES)) {
|
||||||
|
$model->addError("id_event", Yii::t('event-registration', EventRegistrationManager::$STATES[$e->getCode()]));
|
||||||
|
}else {
|
||||||
|
$model->addError("id_event", Yii::t('event-registration', "Unknown Error"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( $model->hasErrors() ){
|
||||||
|
return $this->redirect(['view', 'id' => $model->registration->id]);
|
||||||
|
} else {
|
||||||
|
return $this->render('register_card', [
|
||||||
|
'model' => $model,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the EventRegistration model based on its primary key value.
|
* Finds the EventRegistration model based on its primary key value.
|
||||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||||
|
|||||||
@ -13,15 +13,8 @@ use yii\widgets\ActiveForm;
|
|||||||
<?php $form = ActiveForm::begin(); ?>
|
<?php $form = ActiveForm::begin(); ?>
|
||||||
|
|
||||||
<?= $form->field($model, 'id_event')->textInput() ?>
|
<?= $form->field($model, 'id_event')->textInput() ?>
|
||||||
|
|
||||||
<?= $form->field($model, 'id_customer')->textInput() ?>
|
<?= $form->field($model, 'id_customer')->textInput() ?>
|
||||||
|
|
||||||
<?= $form->field($model, 'created_at')->textInput() ?>
|
|
||||||
|
|
||||||
<?= $form->field($model, 'updated_at')->textInput() ?>
|
|
||||||
|
|
||||||
<?= $form->field($model, 'canceled_at')->textInput() ?>
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<?= Html::submitButton($model->isNewRecord ? Yii::t('event-registration', 'Create') : Yii::t('event-registration', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
|
<?= Html::submitButton($model->isNewRecord ? Yii::t('event-registration', 'Create') : Yii::t('event-registration', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
24
backend/views/event-registration/_form_register_card.php
Normal file
24
backend/views/event-registration/_form_register_card.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
use yii\widgets\ActiveForm;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model common\models\CardEventRegistrationForm */
|
||||||
|
/* @var $form yii\widgets\ActiveForm */
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="event-registration-form">
|
||||||
|
|
||||||
|
<?php $form = ActiveForm::begin(); ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'card_number')->textInput() ?>
|
||||||
|
<?= $form->field($model, 'event_id')->textInput() ?>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<?= Html::submitButton($model->isNewRecord ? Yii::t('event-registration', 'Create') : Yii::t('event-registration', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php ActiveForm::end(); ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
@ -15,21 +15,35 @@ use yii\widgets\ActiveForm;
|
|||||||
'method' => 'get',
|
'method' => 'get',
|
||||||
]); ?>
|
]); ?>
|
||||||
|
|
||||||
<?= $form->field($model, 'id') ?>
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">
|
||||||
|
Keresés
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
|
||||||
|
<?= $form->field($model, 'id') ?>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
|
||||||
|
<?= $form->field($model, 'id_event') ?>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
|
||||||
|
<?= $form->field($model, 'id_customer') ?>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<?= $form->field($model, 'id_event') ?>
|
|
||||||
|
|
||||||
<?= $form->field($model, 'id_customer') ?>
|
|
||||||
|
|
||||||
<?= $form->field($model, 'created_at') ?>
|
|
||||||
|
|
||||||
<?= $form->field($model, 'updated_at') ?>
|
|
||||||
|
|
||||||
<?php // echo $form->field($model, 'canceled_at') ?>
|
<?php // echo $form->field($model, 'canceled_at') ?>
|
||||||
|
|
||||||
<div class="form-group">
|
</div>
|
||||||
<?= Html::submitButton(Yii::t('event-registration', 'Search'), ['class' => 'btn btn-primary']) ?>
|
<div class="panel-footer">
|
||||||
<?= Html::resetButton(Yii::t('event-registration', 'Reset'), ['class' => 'btn btn-default']) ?>
|
<?= Html::submitButton(Yii::t('event-registration', 'Search'), ['class' => 'btn btn-primary']) ?>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php ActiveForm::end(); ?>
|
<?php ActiveForm::end(); ?>
|
||||||
|
|||||||
@ -13,7 +13,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
<div class="event-registration-index">
|
<div class="event-registration-index">
|
||||||
|
|
||||||
<h1><?= Html::encode($this->title) ?></h1>
|
<h1><?= Html::encode($this->title) ?></h1>
|
||||||
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
|
<?php echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<?= Html::a(Yii::t('event-registration', 'Create Event Registration'), ['create'], ['class' => 'btn btn-success']) ?>
|
<?= Html::a(Yii::t('event-registration', 'Create Event Registration'), ['create'], ['class' => 'btn btn-success']) ?>
|
||||||
@ -21,16 +21,15 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
|
|
||||||
<?= GridView::widget([
|
<?= GridView::widget([
|
||||||
'dataProvider' => $dataProvider,
|
'dataProvider' => $dataProvider,
|
||||||
'filterModel' => $searchModel,
|
|
||||||
'columns' => [
|
'columns' => [
|
||||||
['class' => 'yii\grid\SerialColumn'],
|
['class' => 'yii\grid\SerialColumn'],
|
||||||
|
|
||||||
'id',
|
'id',
|
||||||
'id_event',
|
'id_event',
|
||||||
'id_customer',
|
'id_customer',
|
||||||
'created_at',
|
'created_at:datetime',
|
||||||
'updated_at',
|
'updated_at:datetime',
|
||||||
// 'canceled_at',
|
'canceled_at:datetime',
|
||||||
|
|
||||||
['class' => 'yii\grid\ActionColumn'],
|
['class' => 'yii\grid\ActionColumn'],
|
||||||
],
|
],
|
||||||
|
|||||||
21
backend/views/event-registration/register_card.php
Normal file
21
backend/views/event-registration/register_card.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model common\models\CardEventRegistrationForm */
|
||||||
|
|
||||||
|
$this->title = Yii::t('event-registration', 'Create Event Registration');
|
||||||
|
$this->params['breadcrumbs'][] = ['label' => Yii::t('event-registration', 'Event Registrations'), 'url' => ['index']];
|
||||||
|
$this->params['breadcrumbs'][] = $this->title;
|
||||||
|
?>
|
||||||
|
<div class="event-registration-create">
|
||||||
|
|
||||||
|
<h1><?= Html::encode($this->title) ?></h1>
|
||||||
|
|
||||||
|
<?= $this->render('_form_register_card', [
|
||||||
|
'model' => $model,
|
||||||
|
]) ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
23
backend/views/event/_form_register_card.php
Normal file
23
backend/views/event/_form_register_card.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
use yii\widgets\ActiveForm;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model common\models\CardEventRegistrationForm */
|
||||||
|
/* @var $form yii\widgets\ActiveForm */
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="event-registration-form">
|
||||||
|
|
||||||
|
<?php $form = ActiveForm::begin(); ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'card_number')->textInput() ?>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<?= Html::submitButton($model->isNewRecord ? Yii::t('event-registration', 'Create') : Yii::t('event-registration', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php ActiveForm::end(); ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
@ -62,8 +62,52 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
'label' => \Yii::t('event', 'Updated At'),
|
'label' => \Yii::t('event', 'Updated At'),
|
||||||
'format' => 'datetime'
|
'format' => 'datetime'
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'class' => 'yii\grid\ActionColumn',
|
||||||
|
'template' => '{view} {update} {delete} {register-card}',
|
||||||
|
'urlCreator' => function ($action, $model, $key, $index) {
|
||||||
|
$params = ['id' => $model['event_id']];
|
||||||
|
$params[0] = "event" . '/' . $action;
|
||||||
|
return \yii\helpers\Url::toRoute($params);
|
||||||
|
},
|
||||||
|
'buttons' => [
|
||||||
|
'view' => function ($url, $model, $key) {
|
||||||
|
$options = [
|
||||||
|
'title' => Yii::t('yii', 'View'),
|
||||||
|
'aria-label' => Yii::t('yii', 'View'),
|
||||||
|
'data-pjax' => '0',
|
||||||
|
];
|
||||||
|
return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, $options);
|
||||||
|
},
|
||||||
|
'update' => function ($url, $model, $key) {
|
||||||
|
$options = [
|
||||||
|
'title' => Yii::t('yii', 'Update'),
|
||||||
|
'aria-label' => Yii::t('yii', 'Update'),
|
||||||
|
'data-pjax' => '0',
|
||||||
|
];
|
||||||
|
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, $options);
|
||||||
|
},
|
||||||
|
'delete' => function ($url, $model, $key) {
|
||||||
|
$options = [
|
||||||
|
'title' => Yii::t('yii', 'Delete'),
|
||||||
|
'aria-label' => Yii::t('yii', 'Delete'),
|
||||||
|
'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
|
||||||
|
'data-method' => 'post',
|
||||||
|
'data-pjax' => '0',
|
||||||
|
];
|
||||||
|
return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, $options);
|
||||||
|
},
|
||||||
|
'register-card' => function ($url, $model, $key) {
|
||||||
|
$options = [
|
||||||
|
'title' => Yii::t('yii', 'Register'),
|
||||||
|
'aria-label' => Yii::t('yii', 'Register'),
|
||||||
|
'data-pjax' => '0',
|
||||||
|
];
|
||||||
|
return Html::a('<span class="glyphicon glyphicon-user"></span>', $url, $options);
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
['class' => 'yii\grid\ActionColumn'],
|
],
|
||||||
],
|
],
|
||||||
]); ?>
|
]); ?>
|
||||||
|
|
||||||
|
|||||||
21
backend/views/event/register_card.php
Normal file
21
backend/views/event/register_card.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model common\models\CardEventRegistrationForm */
|
||||||
|
|
||||||
|
$this->title = Yii::t('event-registration', 'Create Event Registration');
|
||||||
|
$this->params['breadcrumbs'][] = ['label' => Yii::t('event-registration', 'Event Registrations'), 'url' => ['index']];
|
||||||
|
$this->params['breadcrumbs'][] = $this->title;
|
||||||
|
?>
|
||||||
|
<div class="event-registration-create">
|
||||||
|
|
||||||
|
<h1><?= Html::encode($this->title) ?></h1>
|
||||||
|
|
||||||
|
<?= $this->render('_form_register_card', [
|
||||||
|
'model' => $model,
|
||||||
|
]) ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
97
common/manager/EventRegistrationManager.php
Normal file
97
common/manager/EventRegistrationManager.php
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
namespace common\manager;
|
||||||
|
use common\models\Card;
|
||||||
|
use common\models\Event;
|
||||||
|
use common\models\EventRegistration;
|
||||||
|
use yii\web\BadRequestHttpException;
|
||||||
|
use yii\web\NotFoundHttpException;
|
||||||
|
use yii\web\ServerErrorHttpException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by IntelliJ IDEA.
|
||||||
|
* User: rocho
|
||||||
|
* Date: 2018.12.17.
|
||||||
|
* Time: 6:12
|
||||||
|
*/
|
||||||
|
|
||||||
|
class EventRegistrationManager extends \yii\base\Object
|
||||||
|
{
|
||||||
|
const CARD_NOT_FOUND = 1;
|
||||||
|
const CUSTOMER_NOT_FOUND = 2;
|
||||||
|
const TICKET_NOT_FOUND = 3;
|
||||||
|
const NO_FREE_SEATS = 4;
|
||||||
|
const EVENT_TYPE_NOT_FOUND = 5;
|
||||||
|
const TICKET_INSUFFICIENT = 6;
|
||||||
|
|
||||||
|
public static $STATES = [
|
||||||
|
self::CARD_NOT_FOUND => "CARD_NOT_FOUND",
|
||||||
|
self::CUSTOMER_NOT_FOUND => "CUSTOMER_NOT_FOUND",
|
||||||
|
self::TICKET_NOT_FOUND => "TICKET_NOT_FOUND",
|
||||||
|
self::NO_FREE_SEATS => "NO_FREE_SEATS",
|
||||||
|
self::EVENT_TYPE_NOT_FOUND => "EVENT_TYPE_NOT_FOUND",
|
||||||
|
self::TICKET_INSUFFICIENT => "TICKET_INSUFFICIENT",
|
||||||
|
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \common\models\CardEventRegistrationForm $cardEventForm
|
||||||
|
* @throws NotFoundHttpException
|
||||||
|
* @throws BadRequestHttpException
|
||||||
|
* @throws ServerErrorHttpException
|
||||||
|
*/
|
||||||
|
public function registerCard($cardEventForm){
|
||||||
|
|
||||||
|
if ( $cardEventForm->validate() ){
|
||||||
|
|
||||||
|
/** @var \common\models\Card $card */
|
||||||
|
$card = Card::readCard($cardEventForm->card_number,false);
|
||||||
|
if ( !isset($card )){
|
||||||
|
throw new NotFoundHttpException("Card not found: " . $cardEventForm->card_number,self::CARD_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $card->isFree() ){
|
||||||
|
throw new NotFoundHttpException("Customer not found", self::CUSTOMER_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
$activeTickets = $card->getActiveTickets();
|
||||||
|
if ( sizeof($activeTickets) == 0 ){
|
||||||
|
throw new NotFoundHttpException("Ticket not found", self::TICKET_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \common\models\Event $event */
|
||||||
|
$event = Event::find()->andWhere(['id' => $cardEventForm->event_id])->one();
|
||||||
|
if ( !isset($event)){
|
||||||
|
throw new NotFoundHttpException("Event not found: " . $cardEventForm->event_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !$event->hasFreeSeats() ){
|
||||||
|
throw new BadRequestHttpException("No free seats", self::NO_FREE_SEATS);
|
||||||
|
}
|
||||||
|
|
||||||
|
$eventType = $event->eventType;
|
||||||
|
|
||||||
|
if ( !isset($eventType) ){
|
||||||
|
throw new ServerErrorHttpException("Event type not found", self::EVENT_TYPE_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
$selectedTicket = $eventType->findTicketAllowingEventType($activeTickets);
|
||||||
|
|
||||||
|
if ( !isset($selectedTicket) ){
|
||||||
|
throw new NotFoundHttpException("Ticket not found", self::TICKET_INSUFFICIENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
$registration = new EventRegistration();
|
||||||
|
$registration->id_event = $event->id;
|
||||||
|
$registration->id_card = $card->id_card;
|
||||||
|
$registration->id_ticket = $selectedTicket->id_ticket;
|
||||||
|
$registration->save(false);
|
||||||
|
|
||||||
|
$cardEventForm->registration = $registration;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
32
common/messages/hu/event-registration.php
Normal file
32
common/messages/hu/event-registration.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by IntelliJ IDEA.
|
||||||
|
* User: rocho
|
||||||
|
* Date: 2018.12.06.
|
||||||
|
* Time: 7:55
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
return [
|
||||||
|
'ID' => 'ID',
|
||||||
|
'Name' => 'Név',
|
||||||
|
'Seat Count' => 'Férőhelyek száma',
|
||||||
|
'Create Event Registration' => 'Új regisztráció',
|
||||||
|
'Update Event Registration:' => 'Regisztráció módosítása:',
|
||||||
|
|
||||||
|
'Event Registrations' => 'Regisztrációk',
|
||||||
|
'Created At' => 'Létrehozási dátum, idő',
|
||||||
|
'Updated At' => 'Módosítási dátum, idő',
|
||||||
|
'Search' => 'Keres',
|
||||||
|
'Create' => 'Mentés',
|
||||||
|
'Update' => 'Módosít',
|
||||||
|
'Delete' => 'Törlés',
|
||||||
|
'All' => 'Mind',
|
||||||
|
'Unknown Error' => "Ismeretlen Hiba",
|
||||||
|
'CARD_NOT_FOUND' => 'Kártya nem található',
|
||||||
|
'CUSTOMER_NOT_FOUND' => 'Vendég nem található',
|
||||||
|
'TICKET_NOT_FOUND' => 'Nincs aktív bérlet',
|
||||||
|
'NO_FREE_SEATS' => 'Nincs szabad hely',
|
||||||
|
'EVENT_TYPE_NOT_FOUND' => 'Az esemény típusa ismereten',
|
||||||
|
'TICKET_INSUFFICIENT' => 'Nem található az eseményre jogosító aktív bérlet',
|
||||||
|
];
|
||||||
@ -24,7 +24,7 @@ use common\components\Helper;
|
|||||||
*/
|
*/
|
||||||
class Card extends \common\models\BaseFitnessActiveRecord
|
class Card extends \common\models\BaseFitnessActiveRecord
|
||||||
{
|
{
|
||||||
|
|
||||||
const STATUS_DELETED = 0;
|
const STATUS_DELETED = 0;
|
||||||
const STATUS_ACTIVE = 10;
|
const STATUS_ACTIVE = 10;
|
||||||
const STATUS_INACTIVE = 20;
|
const STATUS_INACTIVE = 20;
|
||||||
@ -34,8 +34,8 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
|||||||
const TYPE_BARCODE = 30;
|
const TYPE_BARCODE = 30;
|
||||||
const TYPE_OLD = 40;
|
const TYPE_OLD = 40;
|
||||||
const TYPE_EMPLOYEE = 50;
|
const TYPE_EMPLOYEE = 50;
|
||||||
|
|
||||||
|
|
||||||
public static $FLAG_TICKET = 0; //has valid ticket
|
public static $FLAG_TICKET = 0; //has valid ticket
|
||||||
public static $FLAG_DOOR = 1; //door in/out order
|
public static $FLAG_DOOR = 1; //door in/out order
|
||||||
public static $FLAG_KEY = 2; //key status
|
public static $FLAG_KEY = 2; //key status
|
||||||
@ -121,8 +121,8 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
|||||||
'updated_at' => Yii::t('common/card', 'Updated At'),
|
'updated_at' => Yii::t('common/card', 'Updated At'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function validateAscii($attribute, /** @noinspection PhpUnusedParameterInspection */
|
public function validateAscii($attribute, /** @noinspection PhpUnusedParameterInspection */
|
||||||
$params){
|
$params){
|
||||||
if ( !$this->hasErrors($this->$attribute)){
|
if ( !$this->hasErrors($this->$attribute)){
|
||||||
@ -131,7 +131,7 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
|||||||
Yii::info(" $attribute converted to: " . $this->$attribute);
|
Yii::info(" $attribute converted to: " . $this->$attribute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static function statuses() {
|
static function statuses() {
|
||||||
/** @noinspection PhpUndefinedClassInspection */
|
/** @noinspection PhpUndefinedClassInspection */
|
||||||
return [
|
return [
|
||||||
@ -140,7 +140,7 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
|||||||
self::STATUS_INACTIVE => 'Inaktív',
|
self::STATUS_INACTIVE => 'Inaktív',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getStatusHuman(){
|
public function getStatusHuman(){
|
||||||
$result = null;
|
$result = null;
|
||||||
$s = self::statuses();
|
$s = self::statuses();
|
||||||
@ -155,7 +155,7 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
|||||||
public static function toTypeName($type , $def = ""){
|
public static function toTypeName($type , $def = ""){
|
||||||
return Helper::getArrayValue(self::types(), $type, $def);
|
return Helper::getArrayValue(self::types(), $type, $def);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function types() {
|
static function types() {
|
||||||
/** @noinspection PhpUndefinedClassInspection */
|
/** @noinspection PhpUndefinedClassInspection */
|
||||||
return [
|
return [
|
||||||
@ -166,7 +166,7 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
|||||||
self::TYPE_EMPLOYEE => Yii::t('common/card', 'Munkatárs'),
|
self::TYPE_EMPLOYEE => Yii::t('common/card', 'Munkatárs'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTypeHuman(){
|
public function getTypeHuman(){
|
||||||
$result = null;
|
$result = null;
|
||||||
$s = self::types();
|
$s = self::types();
|
||||||
@ -175,20 +175,24 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
|||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isInactive(){
|
public function isInactive(){
|
||||||
return $this->status == self::STATUS_DELETED;
|
return $this->status == self::STATUS_DELETED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load card from the DB , where the number equals with card number or RFID number
|
||||||
|
* @param number|string $number the card number or the RFID number
|
||||||
|
* @param null|boolean $free optional. if set, append free or not free condition.
|
||||||
|
* @return \common\models\Card|null the card or null, if not found with given conditions
|
||||||
|
*/
|
||||||
public static function readCard($number,$free = null){
|
public static function readCard($number,$free = null){
|
||||||
$card = null;
|
$card = null;
|
||||||
$query = Card::find()
|
$query = Card::find()
|
||||||
->leftJoin(Customer::tableName(), 'card.id_card = customer.id_customer_card ' );
|
->leftJoin(Customer::tableName(), 'card.id_card = customer.id_customer_card ' );
|
||||||
// ->andWhere(['number'=>$number ]);
|
|
||||||
|
|
||||||
Card::addCardNumberCondition($query, $number);
|
Card::addCardNumberCondition($query, $number);
|
||||||
|
|
||||||
|
|
||||||
if ( isset($free) ){
|
if ( isset($free) ){
|
||||||
if ( $free == true){
|
if ( $free == true){
|
||||||
$query->andWhere('customer.id_customer is null');
|
$query->andWhere('customer.id_customer is null');
|
||||||
@ -196,20 +200,20 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
|||||||
$query->andWhere('customer.id_customer is not null');
|
$query->andWhere('customer.id_customer is not null');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$cards = $query->all();
|
$cards = $query->all();
|
||||||
|
|
||||||
if ( count($cards) == 1){
|
if ( count($cards) == 1){
|
||||||
$card = $cards[0];
|
$card = $cards[0];
|
||||||
}
|
}
|
||||||
return $card;
|
return $card;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getCustomer(){
|
public function getCustomer(){
|
||||||
return $this->hasOne(Customer::className(), ['id_customer_card' => 'id_card']);
|
return $this->hasOne(Customer::className(), ['id_customer_card' => 'id_card']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCustomerName(){
|
public function getCustomerName(){
|
||||||
$name = null;
|
$name = null;
|
||||||
if ( $this->customer != null){
|
if ( $this->customer != null){
|
||||||
@ -232,7 +236,7 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
|||||||
['and', ['in',$field_rfid_key ,[ $number ] ],"trim(coalesce(card.rfid_key, '')) <>'' "],
|
['and', ['in',$field_rfid_key ,[ $number ] ],"trim(coalesce(card.rfid_key, '')) <>'' "],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function updateCardFlagTicket($id){
|
public static function updateCardFlagTicket($id){
|
||||||
if ( !isset($id)){
|
if ( !isset($id)){
|
||||||
return ;
|
return ;
|
||||||
@ -255,7 +259,7 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function beforeSave($insert) {
|
public function beforeSave($insert) {
|
||||||
if (parent::beforeSave($insert)){
|
if (parent::beforeSave($insert)){
|
||||||
$this->flag = Helper::setBit( $this->flag , Card::$FLAG_STATUS, ( $this->status != Card::STATUS_ACTIVE ) );
|
$this->flag = Helper::setBit( $this->flag , Card::$FLAG_STATUS, ( $this->status != Card::STATUS_ACTIVE ) );
|
||||||
@ -263,8 +267,8 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getFlagText(){
|
public function getFlagText(){
|
||||||
return Helper::getArrayValue(DoorLog::getCardFlagTexts(), $this->validity, "Ismeretlen");
|
return Helper::getArrayValue(DoorLog::getCardFlagTexts(), $this->validity, "Ismeretlen");
|
||||||
}
|
}
|
||||||
@ -317,4 +321,12 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
|||||||
\Yii::$app->db->createCommand(self::$SQL_UPDATE_FLAG_STATUS_ACTIVE)->execute();
|
\Yii::$app->db->createCommand(self::$SQL_UPDATE_FLAG_STATUS_ACTIVE)->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isFree(){
|
||||||
|
return !isset($this->customer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getActiveTickets(){
|
||||||
|
return Ticket::readActive($this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
33
common/models/CardEventRegistrationForm.php
Normal file
33
common/models/CardEventRegistrationForm.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
namespace common\models;
|
||||||
|
use common\components\Helper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by IntelliJ IDEA.
|
||||||
|
* User: rocho
|
||||||
|
* Date: 2018.12.17.
|
||||||
|
* Time: 6:14
|
||||||
|
*/
|
||||||
|
|
||||||
|
class CardEventRegistrationForm extends \yii\base\Model
|
||||||
|
{
|
||||||
|
public $card_number;
|
||||||
|
public $event_id;
|
||||||
|
public $registration;
|
||||||
|
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[['card_number'], 'validateFormat' ]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateFormat(){
|
||||||
|
$this->card_number = Helper::fixAsciiChars( $this->card_number );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIsNewRecord(){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -9,14 +9,16 @@ use yii\helpers\ArrayHelper;
|
|||||||
/**
|
/**
|
||||||
* This is the model class for table "event".
|
* This is the model class for table "event".
|
||||||
*
|
*
|
||||||
// * @property integer $id
|
* @property integer $id
|
||||||
* @property integer $start
|
* @property integer $start
|
||||||
* @property integer $end
|
* @property integer $end
|
||||||
* @property integer $id_room
|
* @property integer $id_room
|
||||||
* @property integer $id_trainer
|
* @property integer $id_trainer
|
||||||
* @property integer $id_event_type
|
* @property integer $id_event_type
|
||||||
|
* @property integer $seat_count
|
||||||
* @property string $created_at
|
* @property string $created_at
|
||||||
* @property string $updated_at
|
* @property string $updated_at
|
||||||
|
* @property \common\models\EventType eventType
|
||||||
*/
|
*/
|
||||||
class Event extends \yii\db\ActiveRecord
|
class Event extends \yii\db\ActiveRecord
|
||||||
{
|
{
|
||||||
@ -73,6 +75,9 @@ class Event extends \yii\db\ActiveRecord
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
public function afterFind()
|
public function afterFind()
|
||||||
{
|
{
|
||||||
parent::afterFind(); // TODO: Change the autogenerated stub
|
parent::afterFind(); // TODO: Change the autogenerated stub
|
||||||
@ -104,8 +109,31 @@ class Event extends \yii\db\ActiveRecord
|
|||||||
return $this->hasOne(Trainer::className(),['id' => 'id_trainer']);
|
return $this->hasOne(Trainer::className(),['id' => 'id_trainer']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRoom(){
|
/**
|
||||||
|
* @return Room|\yii\db\ActiveQuery
|
||||||
|
*/
|
||||||
|
public function getRoom() {
|
||||||
return $this->hasOne(Room::className(),['id' => 'id_room']);
|
return $this->hasOne(Room::className(),['id' => 'id_room']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \common\models\EventRegistration[]|\yii\db\ActiveQuery
|
||||||
|
*/
|
||||||
|
public function getEventRegistrations(){
|
||||||
|
return $this->hasMany(EventRegistration::className(),['id_event' => 'id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \common\models\EventRegistration[]|\yii\db\ActiveQuery
|
||||||
|
*/
|
||||||
|
public function getEventRegistrationCount(){
|
||||||
|
return sizeof($this->getEventRegistrations());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasFreeSeats(){
|
||||||
|
$registrationCount = $this->getEventRegistrations() ;
|
||||||
|
|
||||||
|
return $registrationCount < $this->seat_count ;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,8 @@ use Yii;
|
|||||||
* @property integer $id
|
* @property integer $id
|
||||||
* @property integer $id_event
|
* @property integer $id_event
|
||||||
* @property integer $id_customer
|
* @property integer $id_customer
|
||||||
|
* @property integer $id_card
|
||||||
|
* @property integer $id_ticket
|
||||||
* @property string $created_at
|
* @property string $created_at
|
||||||
* @property string $updated_at
|
* @property string $updated_at
|
||||||
* @property string $canceled_at
|
* @property string $canceled_at
|
||||||
@ -25,14 +27,12 @@ class EventRegistration extends \yii\db\ActiveRecord
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdocd
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[['id_event', 'id_customer'], 'integer'],
|
[['id_event', 'id_customer'], 'integer'],
|
||||||
[['created_at', 'updated_at', 'canceled_at'], 'required'],
|
|
||||||
[['created_at', 'updated_at', 'canceled_at'], 'safe']
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -76,4 +76,20 @@ class EventType extends \yii\db\ActiveRecord
|
|||||||
}
|
}
|
||||||
return ArrayHelper::merge($extra,$items);
|
return ArrayHelper::merge($extra,$items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the first ticket, which allows this event type
|
||||||
|
* @param \common\models\Ticket[] $tickets the list of active tickets
|
||||||
|
* @return Ticket|null
|
||||||
|
*/
|
||||||
|
public function findTicketAllowingEventType($tickets){
|
||||||
|
if (!isset($tickets)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if ( sizeof($tickets) == 0 ){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// TODO: implement bossiness logic to select ticket
|
||||||
|
return $tickets[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\db\Schema;
|
||||||
|
use yii\db\Migration;
|
||||||
|
|
||||||
|
class m181219_063217_alter_table_EVENT_REGISTRATION_add_column_ID_TICKET extends Migration
|
||||||
|
{
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$this->addColumn("event_registration", "id_ticket", $this->integer() );
|
||||||
|
$this->addColumn("event_registration", "id_card", $this->integer() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Use safeUp/safeDown to run migration code within a transaction
|
||||||
|
public function safeUp()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function safeDown()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user