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.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user