add event module

This commit is contained in:
Roland Schneider 2019-01-16 17:34:58 +01:00
parent 8decd1bc79
commit 8967445a28
18 changed files with 1151 additions and 2 deletions

View File

@ -125,6 +125,13 @@ class Event extends \yii\db\ActiveRecord
return $this->hasOne(Room::className(),['id' => 'id_room']);
}
/**
* @return Card|\yii\db\ActiveQuery
*/
public function getCard() {
return $this->hasOne(Card::className(),['id_card' => 'id_card']);
}
/**
* @return \common\models\EventRegistration[]|\yii\db\ActiveQuery
*/

View File

@ -0,0 +1,16 @@
<?php
namespace common\modules\event;
class EventModule extends \yii\base\Module
{
public $controllerNamespace = 'common\modules\event\controllers';
public $mode;
public function init()
{
parent::init();
// custom initialization code goes here
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace common\modules\event\controllers;
use yii\web\Controller;
class DefaultController extends Controller
{
public function actionIndex()
{
return $this->render('index');
}
}

View File

@ -0,0 +1,251 @@
<?php
namespace common\modules\event\controllers;
use common\manager\EventRegistrationManager;
use common\models\CardEventRegistrationForm;
use common\modules\event\EventModule;
use common\modules\event\models\EventPermissions;
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;
use yii\filters\VerbFilter;
/**
* EventController implements the CRUD actions for Event model.
*/
class EventController extends Controller
{
public function behaviors()
{
$behaviors = [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
$module = EventModule::getInstance();
$allowedActions = [ 'index','view', 'reserve-card','cancel-registration','delete-registration' ];
if ( $module->mode == 'admin' ){
$allowedActions[] = 'create';
$allowedActions[] = 'update';
$allowedActions[] = 'delete';
}
$behaviors['access'] = [
'class' => \yii\filters\AccessControl::className(),
'rules' => [
// allow authenticated users
[
'actions' =>$allowedActions,
'allow' => true,
'roles' => ['@'],
],
// everything else is denied
],
];
return $behaviors;
}
/**
* Lists all Event models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new EventSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$permissions = new EventPermissions();
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'permissions' => $permissions
]);
}
/**
* 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,
'permissions' => new EventPermissions()
]);
}
/**
* Creates a new Event model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Event();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing Event model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing Event model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException
* @throws \yii\db\Exception
*/
public function actionDelete($id)
{
$manager = new EventRegistrationManager();
$manager->deleteEvent($this->findModel($id));
return $this->redirect(['index']);
}
/**
* @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 \yii\web\Response
* @throws \yii\db\Exception
* @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;
}
}
/**
* @param $id
* @return string|\yii\web\Response
* @throws NotFoundHttpException
* @throws \yii\db\Exception
*/
public function actionReserveCard($id)
{
$event = $this->findModel($id);
$model = new CardEventRegistrationForm();
$model->event_id = $id;
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]);
}
}
return $this->render('register_card', [
'model' => $model,
'event' => $event,
]);
}
/**
* Finds the Event model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Event the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Event::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}

View File

@ -0,0 +1,42 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: rocho
* Date: 2019.01.15.
* Time: 8:29
*/
namespace common\modules\event\models;
use common\modules\event\EventModule;
/**
* Class EventPermissions
* @package common\modules\event\models
*
* @property boolean $allowCreate
* @property boolean $allowDelete
* @property boolean $allowEdit
*/
class EventPermissions
{
public $allowCreate = false;
public $allowDelete = false;
public $allowEdit = false;
public $allowIndexCreatedAt = false;
public function __construct()
{
$moduleMode = EventModule::getInstance()->mode;
if ( $moduleMode == 'admin'){
$this->allowCreate = true;
$this->allowDelete = true;
$this->allowEdit = true;
$this->allowIndexCreatedAt = true;
}
}
}

View File

@ -0,0 +1,157 @@
<?php
namespace common\modules\event\models;
use common\components\Helper;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Event;
use yii\db\Expression;
use yii\db\Query;
/**
* EventSearch represents the model behind the search form about `common\models\Event`.
*/
class EventSearch extends Event
{
public $roomName;
public $trainerName;
public $eventTypeName;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'roomName', 'trainerName', 'eventTypeName'], 'string', 'max' => 250],
[['startDateString',], 'date', 'format' => Yii::$app->formatter->datetimeFormat, 'timestampAttribute' => 'start', 'timeZone' => 'UTC'],
[['endDateString',], 'date', 'format' => Yii::$app->formatter->datetimeFormat, 'timestampAttribute' => 'end', 'timeZone' => 'UTC'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = new Query();
$query->select([
'event.id as event_id',
'event.start as event_start',
'event.end as event_end',
'event.created_at as event_created_at',
'event.updated_at as event_updated_at',
'event.deleted_at as event_deleted_at',
'event.seat_count as event_seat_count',
'trainer.name as trainer_name',
'room.name as room_name',
'event_type.name as event_type_name',
new Expression('count(event_registration.id) as registration_count')
]);
$query->from("event");
$query->innerJoin('trainer', 'event.id_trainer = trainer.id');
$query->innerJoin('room', 'event.id_room = room.id');
$query->innerJoin('event_type', 'event_type.id = event.id_event_type');
$query->leftJoin('event_registration', 'event_registration.id_event = event.id');
$query->groupBy(
[
'event_id',
'event_start',
'event_end',
'event_created_at',
'event_updated_at',
'event_deleted_at',
'trainer_name',
'room_name',
'event_type_name',
]
);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => [
'defaultOrder' => [
'event_start' => SORT_DESC
],
'attributes' => Helper::mkYiiSortItems([
['event_id'],
['event_start'],
['event_end'],
['trainer_name'],
['room_name'],
['event_type_name'],
['customer_name'],
['event_created_at'],
['event_updated_at'],
['event_deleted_at'],
['registration_count'],
['event_seat_count'],
]),
]
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
'event.id' => $this->id,
]);
$query->andFilterWhere(
['room.id' => $this->roomName]
);
$query->andFilterWhere(
['trainer.id' => $this->trainerName]
);
$query->andFilterWhere(
['event_type.id' => $this->eventTypeName]
);
if (isset($this->start)) {
$query->andWhere(
[
'>=',
'start',
$this->start
]
);
}
if (isset($this->end)) {
$query->andWhere(
[
'<=',
'end',
$this->end
]
);
}
return $dataProvider;
}
}

View File

@ -0,0 +1,12 @@
<div class="event-default-index">
<h1><?= $this->context->action->uniqueId ?></h1>
<p>
This is the view content for action "<?= $this->context->action->id ?>".
The action belongs to the controller "<?= get_class($this->context) ?>"
in the "<?= $this->context->module->id ?>" module.
</p>
<p>
You may customize this page by editing the following file:<br>
<code><?= __FILE__ ?></code>
</p>
</div>

View File

@ -0,0 +1,54 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model common\models\Event */
/* @var $form 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(); ?>
<?= $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, 'seat_count')->textInput() ?>
<?= $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_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>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>

View 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>

View File

@ -0,0 +1,74 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\models\EventSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="event-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Keresés</h3>
</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, 'startDateString')->widget(\kartik\widgets\DateTimePicker::classname(), [
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy.mm.dd hh:ii'
],
'options' => [
'autocomplete' => 'off'
]
]); ?>
</div>
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
<?= $form->field($model, 'endDateString')->widget(\kartik\widgets\DateTimePicker::classname(), [
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy.mm.dd hh:ii'
],
'options' => [
'autocomplete' => 'off'
]
])
?>
</div>
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
<?= $form->field($model, 'roomName')->dropDownList(\common\models\Room::roomOptions(true)) ?>
</div>
</div>
<div class="row">
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
<?= $form->field($model, 'trainerName')->dropDownList(\common\models\Trainer::trainerOptions(true)) ?>
</div>
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
<?php echo $form->field($model, 'eventTypeName')->dropDownList(\common\models\EventType::eventTypeOptions(true)) ?>
</div>
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
</div>
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
</div>
</div>
</div>
<div class="panel-footer">
<?= Html::submitButton(Yii::t('event', 'Search'), ['class' => 'btn btn-primary']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,73 @@
<?php
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model common\models\Event */
?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Esemény</h3>
</div>
<div class="panel-body">
<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',
'created_at:datetime',
'updated_at:datetime',
'deleted_at:datetime',
],
]);
} 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')
],
'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 view";
} ?>
</div>
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
<?php try {
echo DetailView::widget([
'model' => $model,
'attributes' => [
'seat_count',
'eventRegistrationCount',
'openSeatCount',
],
]);
} catch (Exception $e) {
echo "Failed to render view";
} ?>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,21 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model common\models\Event */
$this->title = Yii::t('event', 'Create Event');
$this->params['breadcrumbs'][] = ['label' => Yii::t('event', 'Events'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="event-create">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,162 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel common\modules\event\models\EventSearch */
/* @var $permissions common\modules\event\models\EventPermissions */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('event', 'Events');
$this->params['breadcrumbs'][] = $this->title;
$indexTableTemplateButtons = ['{view}']; // '{view} {update} {reserve-card}';
if ( $permissions->allowCreate ){
$indexTableTemplateButtons[] = '{update}';
}
$indexTableTemplateButtons[] = '{reserve-card}';
?>
<div class="event-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?php
if ( $permissions->allowCreate ){
echo Html::a(Yii::t('event', 'Create Event'), ['create'], ['class' => 'btn btn-success']);
}
?>
</p>
<?php
/**
* Filter array of menu config by the 'allowed' property.
* If property not set , it means it is allowed ( allowed boolean default true)
* @param $array array of menu configs
* @return array the filtered array of menu configs
*/
function buildColumns($array){
$result = [];
foreach ($array as $item){
$allow = true;
if ( isset($item['allow'])){
$allow = $item['allow'];
}
if ( $allow ){
$result[] = $item;
}
}
return $result;
}
$columns = buildColumns([
[
'attribute' => 'event_id',
'label' => \Yii::t('event', 'ID')
],
[
'attribute' => 'event_type_name',
'label' => \Yii::t('event', 'Id Event Type')
],
[
'attribute' => 'event_start',
'label' => \Yii::t('event', 'Start'),
'format' => 'datetime'
],
[
'attribute' => 'event_end',
'label' => \Yii::t('event', 'End'),
'format' => 'time'
],
[
'attribute' => 'event_seat_count',
'label' => \Yii::t('event', 'Seat Count')
],
[
'attribute' => 'registration_count',
'label' => \Yii::t('event', 'Registration Count')
],
[
'attribute' => 'room_name',
'label' => \Yii::t('event', 'Room Name')
],
[
'attribute' => 'trainer_name',
'label' => \Yii::t('event', 'Trainer Name')
],
[
'attribute' => 'event_created_at',
'label' => \Yii::t('event', 'Created At'),
'format' => 'datetime',
'allow' => $permissions->allowIndexCreatedAt
],
[
'attribute' => 'event_updated_at',
'label' => \Yii::t('event', 'Updated At'),
'format' => 'datetime'
],
[
'attribute' => 'event_deleted_at',
'label' => \Yii::t('event', 'Deleted At'),
'format' => 'datetime'
],
[
'class' => 'yii\grid\ActionColumn',
'template' => join("",$indexTableTemplateButtons),
'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);
},
'reserve-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);
}
]
],
]);
?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => $columns
]); ?>
</div>

View File

@ -0,0 +1,23 @@
<?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>
<?php echo $this->render('_view', ['model' => $event]); ?>
<?= $this->render('_form_register_card', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,21 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model common\models\Event */
$this->title = Yii::t('event', 'Update Event:') . ' ' . $model->id;
$this->params['breadcrumbs'][] = ['label' => Yii::t('event', 'Events'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = Yii::t('event', 'Update');
?>
<div class="event-update">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,187 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model common\models\Event */
/* @var $permissions common\modules\event\models\EventPermissions */
$this->title = \Yii::t('event', 'Event Details');
$this->params['breadcrumbs'][] = ['label' => Yii::t('event', 'Events'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
/**
* @var \common\modules\event\EventModule
*/
$module = \common\modules\event\EventModule::getInstance();
function isReservationOpen($model)
{
$canceled = isset($model['event_registration_canceled_at']);
$deleted = isset($model['event_registration_deleted_at']);
return !$canceled && !$deleted;
}
function getCommonColumnsHtmlOptions($model)
{
$options = [];
if (!isReservationOpen($model)) {
$options['style'] = 'text-decoration: line-through;';
}
return $options;
}
?>
<div class="event-view">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?php
if ($permissions->allowEdit) {
echo Html::a(Yii::t('event', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
}
if ($model->canReserve()) {
echo Html::a(Yii::t('event', 'Reservation'), ['reserve-card', 'id' => $model->id], ['class' => 'btn btn-primary']);
}
?>
<?php
if ($permissions->allowDelete) {
if ($model->canDelete()) {
echo Html::a(Yii::t('event', 'Delete'), ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger pull-right',
'data' => [
'confirm' => Yii::t('event', 'Are you sure you want to delete this item?'),
'method' => 'post',
],
]);
}
}
?>
</p>
<?php echo $this->render('_view', ['model' => $model]); ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Foglalások</h3>
</div>
<div class="panel-body">
<?php try {
echo \yii\grid\GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
[
'attribute' => 'card_number',
'label' => \Yii::t('event', 'Card Number'),
'contentOptions' => function ($model) {
return getCommonColumnsHtmlOptions($model);
},
'format' => 'raw',
'value' => function ($model, $key, $index, $column) {
if ( \common\modules\event\EventModule::getInstance()->mode =='frontend' ){
return Html::a($model['card_number'], ['/ticket/create', 'number' => $model['card_number']]);
}else{
return Html::a($model['card_number'], ['card/view', 'id' => $model['card_id_card']]);
}
}
],
[
'attribute' => 'customer_name',
'label' => \Yii::t('event', 'Customer Name'),
'contentOptions' => function ($model) {
return getCommonColumnsHtmlOptions($model);
},
'format' => 'raw',
'value' => function ($model, $key, $index, $column) {
if ( \common\modules\event\EventModule::getInstance()->mode =='frontend' ) {
return Html::a($model['customer_name'], ['/ticket/create', 'number' => $model['card_number']]);
}else{
return Html::a($model['customer_name'], ['customer/view', 'id' => $model['customer_id_customer']]);
}
}
],
[
'attribute' => 'customer_email',
'label' => \Yii::t('event', 'Customer Email'),
'contentOptions' => function ($model) {
return getCommonColumnsHtmlOptions($model);
}
],
[
'attribute' => 'event_registration_created_at',
'label' => \Yii::t('event', 'Event Registration Created At'),
'contentOptions' => function ($model) {
return getCommonColumnsHtmlOptions($model);
}
],
[
'attribute' => 'event_registration_canceled_at',
'format' => 'datetime',
'label' => \Yii::t('event', 'Canceled At'),
'contentOptions' => function () {
$options = [];
return $options;
}
],
[
'attribute' => 'event_registration_deleted_at',
'format' => 'datetime',
'label' => \Yii::t('event', 'Deleted At'),
'contentOptions' => function () {
$options = [];
return $options;
},
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{cancel-registration} {delete-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('event', 'Cancel'),
'aria-label' => Yii::t('event', 'Cancel'),
'data-confirm' => Yii::t('event', 'Are you sure you want to cancel this item? Usage count won\'t be restored!'),
'data-method' => 'post',
'data-pjax' => '0',
];
return Html::a('<span class="glyphicon glyphicon-ban-circle"></span>', $url, $options);
},
'delete-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('event', 'Are you sure you want to delete this item? Usage count will be restored!'),
'data-method' => 'post',
'data-pjax' => '0',
];
return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, $options);
},
]
],
]
]);
} catch (Exception $e) {
echo "Failed to render registrations";
}
?>
</div>
</div>
</div>

View File

@ -104,9 +104,16 @@ class FrontendMenuStructure
$this->menuItems[] = ['label' => Yii::t('frontend/account', 'Account'),
'items' => $items
];
$items = [];
$this->menuItems[] = ['label' => Yii::t('event', 'Events'),
'url' => ["event/event/index"]
// 'items' => $items
];
}
}

View File

@ -49,5 +49,11 @@ return [
'errorAction' => 'site/error',
],
],
'modules' => [
'event' => [
'class' => 'common\modules\event\EventModule',
'mode' => 'frontend'
],
],
'params' => $params,
];