bug fixing
This commit is contained in:
@@ -2,14 +2,18 @@
|
||||
|
||||
namespace common\modules\event\controllers;
|
||||
|
||||
use common\components\RoleDefinition;
|
||||
use common\manager\EventRegistrationManager;
|
||||
use common\models\CardEventRegistrationForm;
|
||||
use common\models\EventEquipmentType;
|
||||
use common\models\EventEquipmentTypeAssignment;
|
||||
use common\models\EventRegistrationEquipmentTypeAssignment;
|
||||
use common\models\Trainer;
|
||||
use common\modules\event\EventModule;
|
||||
use common\modules\event\modelAndView\CreateEventModelAndView;
|
||||
use common\modules\event\models\copy\ClearWeekForm;
|
||||
use common\modules\event\models\copy\CopyWeekSearch;
|
||||
use common\modules\event\models\EventCreate;
|
||||
use common\modules\event\models\EventEquipmentTypeForm;
|
||||
use common\modules\event\models\EventPermissions;
|
||||
use common\modules\event\models\timetable\TimeTableSearch;
|
||||
@@ -21,6 +25,7 @@ use common\models\Event;
|
||||
use common\modules\event\models\EventSearch;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\web\BadRequestHttpException;
|
||||
use yii\web\Controller;
|
||||
use yii\web\HttpException;
|
||||
use yii\web\NotFoundHttpException;
|
||||
@@ -47,7 +52,7 @@ class EventController extends Controller
|
||||
|
||||
$module = EventModule::getInstance();
|
||||
assert(isset($module), 'event module not set');
|
||||
$allowedActions = ['index', 'view', 'reserve-card', 'cancel-registration', 'delete-registration', 'timetable', 'copy-week','clear-week',];
|
||||
$allowedActions = ['index', 'view', 'reserve-card', 'cancel-registration', 'delete-registration', 'timetable', 'copy-week', 'clear-week',];
|
||||
if ($module->mode === 'backend') {
|
||||
$allowedActions[] = 'create';
|
||||
$allowedActions[] = 'update';
|
||||
@@ -122,15 +127,33 @@ class EventController extends Controller
|
||||
*/
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = new Event();
|
||||
$modelAndView = new CreateEventModelAndView();
|
||||
|
||||
$event = new EventCreate();
|
||||
$event->id_user = \Yii::$app->user->id;
|
||||
|
||||
$modelAndView->event = $event;
|
||||
|
||||
$query = Trainer::find();
|
||||
if (RoleDefinition::isAdmin() == false) {
|
||||
$query = $query->innerJoinWith('userTrainerAssignments')
|
||||
->andWhere(
|
||||
[
|
||||
'user_trainer_assignment.id_user' => \Yii::$app->user->id
|
||||
]
|
||||
);
|
||||
}
|
||||
$trainers = $query->all();
|
||||
|
||||
$modelAndView->trainers = $trainers;
|
||||
|
||||
/** @noinspection NotOptimalIfConditionsInspection */
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
if ($event->load(Yii::$app->request->post()) && $event->save()) {
|
||||
return $this->redirect(['view', 'id' => $event->id]);
|
||||
}
|
||||
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
'modelAndView' => $modelAndView
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -143,15 +166,30 @@ class EventController extends Controller
|
||||
*/
|
||||
public function actionUpdate($id)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
$modelAndView = new CreateEventModelAndView();
|
||||
$event = EventCreate::findOne($id);
|
||||
if ( !isset($event)){
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
$modelAndView->event = $event;
|
||||
|
||||
$trainers = Trainer::getTrainersAllowed(\Yii::$app->user->id);
|
||||
|
||||
if ( !Trainer::isTrainerAllowed($trainers,\Yii::$app->user->id, $event->id_trainer)){
|
||||
throw new BadRequestHttpException("Ön nem jogosult az esemény módosítására");
|
||||
}
|
||||
|
||||
$modelAndView->trainers = $trainers;
|
||||
|
||||
|
||||
/** @noinspection NotOptimalIfConditionsInspection */
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
if ($event->load(Yii::$app->request->post()) && $event->save()) {
|
||||
return $this->redirect(['view', 'id' => $event->id]);
|
||||
}
|
||||
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
'modelAndView' => $modelAndView
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -284,7 +322,7 @@ class EventController extends Controller
|
||||
$model->search(Yii::$app->request->post());
|
||||
if (count($model->getErrors()) === 0) {
|
||||
$model->save();
|
||||
$this->redirect(['copy-week', $model->formName() . '[sourceDateString]'=> $model->sourceDateString, $model->formName() . '[targetDateString]' =>$model->targetDateString ]);
|
||||
$this->redirect(['copy-week', $model->formName() . '[sourceDateString]' => $model->sourceDateString, $model->formName() . '[targetDateString]' => $model->targetDateString]);
|
||||
}
|
||||
} else {
|
||||
$model->search(Yii::$app->request->get());
|
||||
@@ -298,7 +336,8 @@ class EventController extends Controller
|
||||
* @return Response
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function actionClearWeek(){
|
||||
public function actionClearWeek()
|
||||
{
|
||||
|
||||
$clearWeekForm = new ClearWeekForm();
|
||||
$clearWeekForm->clear(Yii::$app->request->get());
|
||||
@@ -320,10 +359,10 @@ class EventController extends Controller
|
||||
$formModel->loadAssignedEquipment();
|
||||
if (Yii::$app->request->isPost) {
|
||||
if ($formModel->load(Yii::$app->request->post()) && $formModel->save()) {
|
||||
$this->redirect(['view','id' => $formModel->event->id]);
|
||||
$this->redirect(['view', 'id' => $formModel->event->id]);
|
||||
}
|
||||
}else{
|
||||
if ( !isset($formModel->event) ){
|
||||
} else {
|
||||
if (!isset($formModel->event)) {
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
namespace common\modules\event\modelAndView;
|
||||
|
||||
use common\models\Trainer;
|
||||
|
||||
/**
|
||||
* @property \common\models\Event $event
|
||||
* @property Trainer[] $trainers
|
||||
*/
|
||||
class CreateEventModelAndView
|
||||
{
|
||||
public $event;
|
||||
public $trainers;
|
||||
}
|
||||
49
common/modules/event/models/EventCreate.php
Normal file
49
common/modules/event/models/EventCreate.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace common\modules\event\models;
|
||||
|
||||
use common\components\RoleDefinition;
|
||||
use common\models\Event;
|
||||
use common\models\Trainer;
|
||||
|
||||
class EventCreate extends Event
|
||||
{
|
||||
|
||||
public function rules()
|
||||
{
|
||||
$basicRules = parent::rules();
|
||||
$basicRules[] = [
|
||||
['id_trainer'] ,'validateTrainers'
|
||||
];
|
||||
return $basicRules;
|
||||
}
|
||||
|
||||
|
||||
public function validateTrainers($attribute, $params){
|
||||
|
||||
$query = Trainer::find();
|
||||
if (RoleDefinition::isAdmin() == false) {
|
||||
$query = $query->innerJoinWith('userTrainerAssignments')
|
||||
->andWhere(
|
||||
[
|
||||
'user_trainer_assignment.id_user' => \Yii::$app->user->id
|
||||
]
|
||||
);
|
||||
}
|
||||
$trainers = $query->all();
|
||||
|
||||
$trainerAllowed = false;
|
||||
foreach ($trainers as $trainer){
|
||||
if ( $trainer->id == $this->id_trainer){
|
||||
$trainerAllowed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$trainerAllowed ){
|
||||
$this->addError($attribute,"Hibás paraméter: edző");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -65,6 +65,7 @@ class EventSearch extends Event
|
||||
'trainer.name as trainer_name',
|
||||
'room.name as room_name',
|
||||
'event_type.name as event_type_name',
|
||||
'event_type.theme as event_type_theme',
|
||||
new Expression('count(event_registration.id) as registration_count')
|
||||
]);
|
||||
|
||||
@@ -87,6 +88,11 @@ class EventSearch extends Event
|
||||
]
|
||||
);
|
||||
|
||||
if ( !RoleDefinition::isAdmin()){
|
||||
$query->innerJoin('user_trainer_assignment', 'user_trainer_assignment.id_trainer = trainer.id' );
|
||||
$query->andWhere(['user_trainer_assignment.id_user' => \Yii::$app->user->id ]);
|
||||
}
|
||||
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
<?php
|
||||
|
||||
use common\modules\event\modelAndView\CreateEventModelAndView;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\Event */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
/* @var $modelAndView CreateEventModelAndView */
|
||||
|
||||
$event = $modelAndView->event;
|
||||
?>
|
||||
|
||||
<div class="event-form">
|
||||
@@ -14,7 +18,7 @@ use yii\widgets\ActiveForm;
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'startDateString')->widget(\kartik\widgets\DateTimePicker::classname(), [
|
||||
<?= $form->field($event, 'startDateString')->widget(\kartik\widgets\DateTimePicker::class, [
|
||||
'pluginOptions' => [
|
||||
'autoclose' => true,
|
||||
'format' => 'yyyy.mm.dd hh:ii'
|
||||
@@ -25,7 +29,7 @@ use yii\widgets\ActiveForm;
|
||||
]);
|
||||
?>
|
||||
|
||||
<?= $form->field($model, 'endDateString')->widget(\kartik\widgets\DateTimePicker::classname(), [
|
||||
<?= $form->field($event, 'endDateString')->widget(\kartik\widgets\DateTimePicker::class, [
|
||||
'pluginOptions' => [
|
||||
'autoclose' => true,
|
||||
'format' => 'yyyy.mm.dd hh:ii'
|
||||
@@ -35,16 +39,16 @@ use yii\widgets\ActiveForm;
|
||||
]
|
||||
])
|
||||
?>
|
||||
<?= $form->field($model, 'seat_count')->textInput() ?>
|
||||
<?= $form->field($event, 'seat_count')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'id_room')->dropDownList(\common\models\Room::roomOptions(false, true)) ?>
|
||||
<?= $form->field($event, 'id_room')->dropDownList(\common\models\Room::roomOptions(false, true)) ?>
|
||||
|
||||
<?= $form->field($model, 'id_trainer')->dropDownList(\common\models\Trainer::trainerOptions(false, true)) ?>
|
||||
<?= $form->field($event, 'id_trainer')->dropDownList(\common\models\Trainer::trainerOptions(false, true, $modelAndView->trainers)) ?>
|
||||
|
||||
<?= $form->field($model, 'id_event_type')->dropDownList(\common\models\EventType::eventTypeOptions(false, true)) ?>
|
||||
<?= $form->field($event, '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']) ?>
|
||||
<?= Html::submitButton($event->isNewRecord ? Yii::t('event', 'Create') : Yii::t('event', 'Update'), ['class' => $event->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
@@ -4,7 +4,7 @@ use yii\helpers\Html;
|
||||
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\Event */
|
||||
/* @var $modelAndView common\modules\event\modelAndView\CreateEventModelAndView */
|
||||
|
||||
$this->title = Yii::t('event', 'Create Event');
|
||||
$this->params['breadcrumbs'][] = ['label' => Yii::t('event', 'Events'), 'url' => ['index']];
|
||||
@@ -15,7 +15,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
'modelAndView' => $modelAndView,
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -63,7 +63,12 @@ $indexTableTemplateButtons[] = '{equipment-types-assignment}';
|
||||
],
|
||||
[
|
||||
'attribute' => 'event_type_name',
|
||||
'label' => \Yii::t('event', 'Id Event Type')
|
||||
'label' => \Yii::t('event', 'Id Event Type'),
|
||||
'value' => function ($model, $key, $index, $column){
|
||||
return "<span style='margin-right: 3px; display: inline-block; width: 1rem; height: 1rem;' class='event-theme-active-". $model['event_type_theme']."'></span>".$model['event_type_name'] ;
|
||||
}
|
||||
,
|
||||
'format' => 'raw'
|
||||
],
|
||||
[
|
||||
'attribute' => 'event_start',
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
<?php
|
||||
|
||||
use common\modules\event\modelAndView\CreateEventModelAndView;
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\Event */
|
||||
/* @var $modelAndView CreateEventModelAndView */
|
||||
|
||||
$this->title = Yii::t('event', 'Update Event:') . ' #' . $model->id;
|
||||
$this->title = Yii::t('event', 'Update Event:') . ' #' . $modelAndView->event->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'][] = ['label' => $modelAndView->event->id, 'url' => ['view', 'id' => $modelAndView->event->id]];
|
||||
$this->params['breadcrumbs'][] = Yii::t('event', 'Update');
|
||||
?>
|
||||
<div class="event-update">
|
||||
@@ -15,7 +16,7 @@ $this->params['breadcrumbs'][] = Yii::t('event', 'Update');
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
'modelAndView' => $modelAndView
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -17,7 +17,12 @@ if (!isset($event)) {
|
||||
<div class="alert alert-success">
|
||||
<?= Html::a( $start->format('H:i') .'-' . $end->format('H:i') , Url::toRoute(['event/update', 'id' => $event->id ] ) ) ?>
|
||||
<br>
|
||||
<?= Html::a( $event->eventType->name , Url::toRoute(['/event-type/view', 'id'=> $event->eventType->id])) ?>
|
||||
<?= Html::a( $event->eventType->name ,
|
||||
Url::toRoute(['/event-type/view', 'id'=> $event->eventType->id]),
|
||||
[
|
||||
'class' => 'event-theme-active-' . $event->eventType->theme,
|
||||
'style' => 'padding: 3px 6px; border-radius: 1rem;'
|
||||
]) ?>
|
||||
<br>
|
||||
<?= Html::a( $event->room->name , Url::toRoute(['/room/view', 'id' => $event->room->id]) )?>
|
||||
<br>
|
||||
|
||||
Reference in New Issue
Block a user