implement registration in backend

This commit is contained in:
Roland Schneider
2018-12-30 23:04:06 +01:00
parent b2bb210cee
commit e3b6bc08a7
32 changed files with 794 additions and 276 deletions

View File

@@ -2,10 +2,7 @@
namespace backend\components;
use Yii;
use common\models\Order;
use yii\helpers\Html;
use common\components\RoleDefinition;
use common\components\Helper;
class AdminMenuStructure{
@@ -23,12 +20,12 @@ class AdminMenuStructure{
}
return $result;
}
protected function addUserMainMenu(){
/**
* @throws \yii\base\InvalidConfigException
*/
protected function addUserMainMenu(){
$userMainMenu = null;
$items = [];
@@ -173,7 +170,6 @@ class AdminMenuStructure{
$items[] = ['label' => 'Termek', 'url' => ['/room' ] ];
$items[] = ['label' => 'Esemény típusok', 'url' => ['/event-type' ] ];
$items[] = ['label' => 'Események', 'url' => ['/event' ] ];
$items[] = ['label' => 'Esemény regisztrációk', 'url' => ['/event-registration' ] ];
$this->menuItems[] = ['label' => 'Csoportos edzés', 'url' => $this->emptyUrl,
'items' => $items
];
@@ -199,7 +195,8 @@ class AdminMenuStructure{
if (Yii::$app->user->isGuest) {
$mainMenuItem= ['label' => Yii::t('common/site','Login'), 'url' => ['/site/login']];
} else {
$mainMenuItem= [
/** @noinspection PhpUndefinedFieldInspection */
$mainMenuItem= [
'label' => Yii::t('common/site','Logout') . '(' . Yii::$app->user->identity->username . ')',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']
@@ -207,9 +204,13 @@ class AdminMenuStructure{
}
$this->menuItems[] = $mainMenuItem;
}
public function run(){
/**
* @return array
* @throws \yii\base\InvalidConfigException
*/
public function run(){
$this->addUserMainMenu();
// $this->addLoginMainMenu();
return $this->menuItems;

View File

@@ -7,6 +7,7 @@ use common\models\CardEventRegistrationForm;
use Yii;
use common\models\Event;
use backend\models\EventSearch;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\HttpException;
use yii\web\NotFoundHttpException;
@@ -48,11 +49,20 @@ class EventController extends Controller
* Displays a single Event model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException
*/
public function actionView($id)
{
$eventRegistrationManager = new EventRegistrationManager();
$dataProvider = new ActiveDataProvider([
'query' => $eventRegistrationManager->createFindRegistrationsQuery($id),
]
);
return $this->render('view', [
'model' => $this->findModel($id),
'dataProvider' => $dataProvider
]);
}
@@ -79,6 +89,7 @@ class EventController extends Controller
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException
*/
public function actionUpdate($id)
{
@@ -109,28 +120,65 @@ class EventController extends Controller
}
public function actionRegisterCard($id){
/**
* @param $id
* @return \yii\web\Response
* @throws \yii\db\Exception
* @throws \Exception
*/
public function actionCancelRegistration($id)
{
$eventRegistrationManager = new EventRegistrationManager();
$db = \Yii::$app->db;
$tx = $db->beginTransaction();
try{
$registration = $eventRegistrationManager->loadRegistration($id);
$eventRegistrationManager->cancelRegistration($registration);
$tx->commit();
return $this->redirect(['view', 'id' => $registration->id_event]);
}catch (\Exception $ex){
$tx->rollBack();
throw $ex;
}
}
/**
* @param $id
* @return string|\yii\web\Response
* @throws NotFoundHttpException
*/
public function actionRegisterCard($id)
{
$event = $this->findModel($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->load(Yii::$app->request->post())) {
if ($model->validate()) {
$manager = new EventRegistrationManager();
try {
$manager->registerCard($model);
} catch (HttpException $e) {
if (array_key_exists($e->getCode(), EventRegistrationManager::$STATES)) {
$model->addError("card_number", Yii::t('event-registration', EventRegistrationManager::$STATES[$e->getCode()]));
} else {
$model->addError("card_number", Yii::t('event-registration', "Unknown Error"));
}
}
}
if ($model->hasErrors()) {
return $this->render('register_card', [
'model' => $model,
'event' => $event,
]);
} else {
return $this->redirect(['view', 'id' => $id]);
}
}
if ( $model->hasErrors() ){
return $this->redirect(['view', 'id' => $model->registration->id]);
} else {
return $this->render('register_card', [
'model' => $model,
]);
}
return $this->render('register_card', [
'model' => $model,
'event' => $event,
]);
}
/**

View File

@@ -5,15 +5,13 @@ namespace backend\controllers;
use Yii;
use common\models\TicketType;
use backend\models\TicketTypeSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\models\Account;
/**
* TicketTypeController implements the CRUD actions for TicketType model.
*/
class TicketTypeController extends \backend\controllers\BackendController
class TicketTypeController extends BackendController
{
@@ -60,6 +58,7 @@ class TicketTypeController extends \backend\controllers\BackendController
* Displays a single TicketType model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException
*/
public function actionView($id)
{
@@ -82,6 +81,7 @@ class TicketTypeController extends \backend\controllers\BackendController
$model->time_unit_type = TicketType::TIME_UNIT_MONTH;
$model->time_unit_count = 1;
$model->max_usage_count = 0;
$model->max_reservation_count = 0;
$accounts = Account::find()->andWhere(['status' => Account::STATUS_ACTIVE])->all();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
@@ -99,6 +99,7 @@ class TicketTypeController extends \backend\controllers\BackendController
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException
*/
public function actionUpdate($id)
{

View File

@@ -8,7 +8,6 @@ use yii\data\ActiveDataProvider;
use common\models\Transfer;
use yii\db\Expression;
use yii\db\Query;
use yii\helpers\ArrayHelper;
use common\models\Account;
use common\components\Helper;
use common\components\RoleDefinition;
@@ -167,8 +166,6 @@ class TransferSearch extends Transfer
}
}
['like', 'name', ['test', 'sample']]
$query->andFilterWhere([
'transfer.id_account' => $this->id_account,
'transfer.status' => $this->status,
@@ -280,11 +277,12 @@ class TransferSearch extends Transfer
}
/**
* @throws \yii\db\Exception
*/
public function totalsTransfers()
{
$accounts = Account::read();
$accountMap = ArrayHelper::map($accounts, 'id_account', 'name');
$idUser = $this->id_user;
/**mk totals need date time format*/
@@ -293,8 +291,7 @@ class TransferSearch extends Transfer
$start .= ' 00:00';
}
$this->totals = Transfer::mkTotals($start, $this->timestampEnd, $idUser, $this->types, $this->id_account, $accounts, $accountMap);
$this->totals = Transfer::mkTotals($start, $this->timestampEnd, $idUser, $this->types, $this->id_account, $accounts);
}

View File

@@ -9,41 +9,46 @@ use yii\widgets\ActiveForm;
?>
<div class="event-form">
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
<?php $form = ActiveForm::begin(); ?>
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'startDateString')->widget(\kartik\widgets\DateTimePicker::classname(), [
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy.mm.dd hh:ii'
],
'options' => [
'autocomplete' => 'off'
]
]);
?>
<?= $form->field($model, 'startDateString')->widget(\kartik\widgets\DateTimePicker::classname(), [
'pluginOptions' => [
'autoclose' => true,
'format' => 'yyyy.mm.dd hh:ii'
],
'options' => [
'autocomplete' => 'off'
]
]);
?>
<?= $form->field($model, 'endDateString')->widget(\kartik\widgets\DateTimePicker::classname(), [
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy.mm.dd hh:ii'
],
'options' => [
'autocomplete' => 'off'
]
])
?>
<?= $form->field($model, 'endDateString')->widget(\kartik\widgets\DateTimePicker::classname(), [
'pluginOptions' => [
'autoclose' => true,
'format' => 'yyyy.mm.dd hh:ii'
],
'options' => [
'autocomplete' => 'off'
]
])
?>
<?= $form->field($model, 'seat_count')->textInput() ?>
<?= $form->field($model, 'id_room')->dropDownList(\common\models\Room::roomOptions(false, true) ) ?>
<?= $form->field($model, 'id_room')->dropDownList(\common\models\Room::roomOptions(false, true)) ?>
<?= $form->field($model, 'id_trainer')->dropDownList(\common\models\Trainer::trainerOptions(false, true) ) ?>
<?= $form->field($model, 'id_trainer')->dropDownList(\common\models\Trainer::trainerOptions(false, true)) ?>
<?= $form->field($model, 'id_event_type')->dropDownList(\common\models\EventType::eventTypeOptions(false, true) ) ?>
<?= $form->field($model, 'id_event_type')->dropDownList(\common\models\EventType::eventTypeOptions(false, true)) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('event', 'Create') : Yii::t('event', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('event', 'Create') : Yii::t('event', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@@ -14,6 +14,31 @@ $this->params['breadcrumbs'][] = $this->title;
<h1><?= Html::encode($this->title) ?></h1>
<h2>Esemény</h2>
<?= /** @var \common\models\Event $event */
/** @noinspection PhpUnhandledExceptionInspection */
\yii\widgets\DetailView::widget([
'model' => $event,
'attributes' => [
'id',
'start:datetime',
'end:datetime',
[
'attribute' => 'room.name',
'label' => $model->getAttributeLabel('id_room')
],
[
'attribute' => 'trainer.name',
'label' => $model->getAttributeLabel('id_trainer')
],
[
'attribute' => 'eventType.name',
'label' => $model->getAttributeLabel('id_event_type')
],
'seat_count',
],
]) ?>
<?= $this->render('_form_register_card', [
'model' => $model,
]) ?>

View File

@@ -16,8 +16,9 @@ $this->params['breadcrumbs'][] = $this->title;
<p>
<?= Html::a(Yii::t('event', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a(Yii::t('event', 'Register'), ['register-card', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a(Yii::t('event', 'Delete'), ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'class' => 'btn btn-danger pull-right',
'data' => [
'confirm' => Yii::t('event', 'Are you sure you want to delete this item?'),
'method' => 'post',
@@ -25,27 +26,144 @@ $this->params['breadcrumbs'][] = $this->title;
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'start:datetime',
'end:datetime',
[
'attribute' => 'room.name',
'label' => $model->getAttributeLabel('id_room')
],
[
'attribute' => 'trainer.name',
'label' => $model->getAttributeLabel('id_trainer')
],
[
'attribute' => 'eventType.name',
'label' => $model->getAttributeLabel('id_event_type')
],
'created_at:datetime',
'updated_at:datetime',
],
]) ?>
<div class="row">
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
<?php try {
echo DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'start:datetime',
'end:datetime',
[
'attribute' => 'room.name',
'label' => $model->getAttributeLabel('id_room')
],
[
'attribute' => 'trainer.name',
'label' => $model->getAttributeLabel('id_trainer')
],
],
]);
} catch (Exception $e) {
echo "failed to render event details ";
} ?>
</div>
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
<?php try {
echo DetailView::widget([
'model' => $model,
'attributes' => [
[
'attribute' => 'eventType.name',
'label' => $model->getAttributeLabel('id_event_type')
],
'seat_count',
'created_at:datetime',
'updated_at:datetime',
],
]);
} catch (Exception $e) {
echo "Failed to render view";
} ?>
</div>
</div>
<h2>Regisztrációk</h2>
<?php try {
echo \yii\grid\GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
[
'attribute' => 'card_number',
'label' => \Yii::t('event', 'Card Number'),
'contentOptions' => function ($model ) {
$options = [];
if (isset($model['event_registration_canceled_at'])) {
$options['style'] = 'text-decoration: line-through;';
}
return $options;
}
],
[
'attribute' => 'customer_name',
'label' => \Yii::t('event', 'Customer Name'),
'contentOptions' => function ($model ) {
$options = [];
if (isset($model['event_registration_canceled_at'])) {
$options['style'] = 'text-decoration: line-through;';
}
return $options;
}
],
[
'attribute' => 'customer_email',
'label' => \Yii::t('event', 'Customer Email'),
'contentOptions' => function ($model ) {
$options = [];
if (isset($model['event_registration_canceled_at'])) {
$options['style'] = 'text-decoration: line-through;';
}
return $options;
}
],
[
'attribute' => 'event_registration_created_at',
'label' => \Yii::t('event', 'Event Registration Created At'),
'contentOptions' => function ($model) {
$options = [];
if (isset($model['event_registration_canceled_at'])) {
$options['style'] = 'text-decoration: line-through;';
}
return $options;
}
],
[
'attribute' => 'event_registration_canceled_at',
'label' => \Yii::t('event', 'Canceled At'),
'contentOptions' => function () {
$options = [];
return $options;
}
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{cancel-registration}',
'urlCreator' => function ($action, $model) {
$params = ['id' => $model['event_registration_id']];
$params[0] = "event" . '/' . $action;
return \yii\helpers\Url::toRoute($params);
},
'buttons' => [
'cancel-registration' => function ($url, $model) {
if (isset($model['event_registration_canceled_at'])) {
return "";
}
$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-ban-circle"></span>', $url, $options);
},
]
],
]
]);
} catch (Exception $e) {
echo "Failed to render registrations";
}
?>
</div>

View File

@@ -33,6 +33,7 @@ use yii\helpers\ArrayHelper;
<?= mkTitle("Alkalmak")?>
<?= $form->field($model, 'max_usage_count')->textInput() ?>
<?= $form->field($model, 'max_reservation_count')->textInput() ?>
<?= mkTitle("Érvényességi idő belállítások")?>
<div class="row">

View File

@@ -21,49 +21,54 @@ $this->params['breadcrumbs'][] = $this->title;
</p>
<?php }?>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'name',
[
'attribute' => 'type',
'value' => $model->typeHuman
],
'max_usage_count',
[
'attribute' => 'time_unit_count',
],
[
'attribute' => 'time_unit_type',
'value' => $model->timeUnitHuman
],
'price_brutto',
[
'attribute' => 'id_account',
'value' => $model->accountName,
],
[
'attribute' => 'flag_student',
'value' => ( $model->isStudent() ? Yii::t('common', 'Yes' ) : Yii::t('common', 'No' ) ),
],
[
'attribute' => 'status',
'value' => $model->statusHuman
],
[
'attribute' => 'door_allowed',
'value' => ( $model->isDoor() ? Yii::t('common', 'Yes' ) : Yii::t('common', 'No' ) ),
//'visible' => \common\components\Helper::isTicketTypeDoorAllowedCheckOn()
<?php try {
echo DetailView::widget([
'model' => $model,
'attributes' => [
'name',
[
'attribute' => 'type',
'value' => $model->typeHuman
],
'max_usage_count',
'max_reservation_count',
[
'attribute' => 'time_unit_count',
],
[
'attribute' => 'time_unit_type',
'value' => $model->timeUnitHuman
],
'price_brutto',
[
'attribute' => 'id_account',
'value' => $model->accountName,
],
[
'attribute' => 'flag_student',
'value' => ($model->isStudent() ? Yii::t('common', 'Yes') : Yii::t('common', 'No')),
],
[
'attribute' => 'status',
'value' => $model->statusHuman
],
[
'attribute' => 'door_allowed',
'value' => ($model->isDoor() ? Yii::t('common', 'Yes') : Yii::t('common', 'No')),
//'visible' => \common\components\Helper::isTicketTypeDoorAllowedCheckOn()
],
'created_at:datetime',
'updated_at:datetime',
[
'attribute' => 'installment_enabled',
'value' => ($model->isInstallment() ? Yii::t('common', 'Yes') : Yii::t('common', 'No')),
],
'installment_money',
'installment_count',
],
'created_at:datetime',
'updated_at:datetime',
[
'attribute' => 'installment_enabled',
'value' => ( $model->isInstallment() ? Yii::t('common', 'Yes' ) : Yii::t('common', 'No' ) ),
],
'installment_money',
'installment_count',
],
]) ?>
]);
} catch (Exception $e) {
echo "Failed to render ticket type";
} ?>
</div>