backend - replace event controller with module
This commit is contained in:
parent
8967445a28
commit
fc11ccc923
@ -169,7 +169,7 @@ class AdminMenuStructure{
|
|||||||
$items[] = ['label' => 'Edzők', 'url' => ['/trainer' ] ];
|
$items[] = ['label' => 'Edzők', 'url' => ['/trainer' ] ];
|
||||||
$items[] = ['label' => 'Termek', 'url' => ['/room' ] ];
|
$items[] = ['label' => 'Termek', 'url' => ['/room' ] ];
|
||||||
$items[] = ['label' => 'Esemény típusok', 'url' => ['/event-type' ] ];
|
$items[] = ['label' => 'Esemény típusok', 'url' => ['/event-type' ] ];
|
||||||
$items[] = ['label' => 'Események', 'url' => ['/event' ] ];
|
$items[] = ['label' => 'Események', 'url' => ['/event/event/index' ] ];
|
||||||
$this->menuItems[] = ['label' => 'Csoportos edzés', 'url' => $this->emptyUrl,
|
$this->menuItems[] = ['label' => 'Csoportos edzés', 'url' => $this->emptyUrl,
|
||||||
'items' => $items
|
'items' => $items
|
||||||
];
|
];
|
||||||
|
|||||||
@ -12,7 +12,6 @@ return [
|
|||||||
'basePath' => dirname(__DIR__),
|
'basePath' => dirname(__DIR__),
|
||||||
'controllerNamespace' => 'backend\controllers',
|
'controllerNamespace' => 'backend\controllers',
|
||||||
'bootstrap' => ['log'],
|
'bootstrap' => ['log'],
|
||||||
'modules' => [],
|
|
||||||
'components' => [
|
'components' => [
|
||||||
'request' => [
|
'request' => [
|
||||||
'enableCsrfValidation'=>false,
|
'enableCsrfValidation'=>false,
|
||||||
@ -46,5 +45,11 @@ return [
|
|||||||
'errorAction' => 'site/error',
|
'errorAction' => 'site/error',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
'modules' => [
|
||||||
|
'event' => [
|
||||||
|
'class' => 'common\modules\event\EventModule',
|
||||||
|
'mode' => 'backend'
|
||||||
|
],
|
||||||
|
],
|
||||||
'params' => $params,
|
'params' => $params,
|
||||||
];
|
];
|
||||||
|
|||||||
@ -1,222 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace backend\controllers;
|
|
||||||
|
|
||||||
use common\manager\EventRegistrationManager;
|
|
||||||
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;
|
|
||||||
use yii\filters\VerbFilter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* EventController implements the CRUD actions for Event model.
|
|
||||||
*/
|
|
||||||
class EventController extends Controller
|
|
||||||
{
|
|
||||||
public function behaviors()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'verbs' => [
|
|
||||||
'class' => VerbFilter::className(),
|
|
||||||
'actions' => [
|
|
||||||
'delete' => ['post'],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Lists all Event models.
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function actionIndex()
|
|
||||||
{
|
|
||||||
$searchModel = new EventSearch();
|
|
||||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
|
||||||
|
|
||||||
return $this->render('index', [
|
|
||||||
'searchModel' => $searchModel,
|
|
||||||
'dataProvider' => $dataProvider,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
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.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,157 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace backend\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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -8,7 +8,7 @@ use common\modules\event\EventModule;
|
|||||||
use common\modules\event\models\EventPermissions;
|
use common\modules\event\models\EventPermissions;
|
||||||
use Yii;
|
use Yii;
|
||||||
use common\models\Event;
|
use common\models\Event;
|
||||||
use backend\models\EventSearch;
|
use common\modules\event\models\EventSearch;
|
||||||
use yii\data\ActiveDataProvider;
|
use yii\data\ActiveDataProvider;
|
||||||
use yii\web\Controller;
|
use yii\web\Controller;
|
||||||
use yii\web\HttpException;
|
use yii\web\HttpException;
|
||||||
@ -33,7 +33,7 @@ class EventController extends Controller
|
|||||||
|
|
||||||
$module = EventModule::getInstance();
|
$module = EventModule::getInstance();
|
||||||
$allowedActions = [ 'index','view', 'reserve-card','cancel-registration','delete-registration' ];
|
$allowedActions = [ 'index','view', 'reserve-card','cancel-registration','delete-registration' ];
|
||||||
if ( $module->mode == 'admin' ){
|
if ( $module->mode == 'backend' ){
|
||||||
$allowedActions[] = 'create';
|
$allowedActions[] = 'create';
|
||||||
$allowedActions[] = 'update';
|
$allowedActions[] = 'update';
|
||||||
$allowedActions[] = 'delete';
|
$allowedActions[] = 'delete';
|
||||||
|
|||||||
@ -31,7 +31,7 @@ class EventPermissions
|
|||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$moduleMode = EventModule::getInstance()->mode;
|
$moduleMode = EventModule::getInstance()->mode;
|
||||||
if ( $moduleMode == 'admin'){
|
if ( $moduleMode == 'backend'){
|
||||||
$this->allowCreate = true;
|
$this->allowCreate = true;
|
||||||
$this->allowDelete = true;
|
$this->allowDelete = true;
|
||||||
$this->allowEdit = true;
|
$this->allowEdit = true;
|
||||||
|
|||||||
@ -46,6 +46,7 @@ $indexTableTemplateButtons[] = '{reserve-card}';
|
|||||||
$allow = true;
|
$allow = true;
|
||||||
if ( isset($item['allow'])){
|
if ( isset($item['allow'])){
|
||||||
$allow = $item['allow'];
|
$allow = $item['allow'];
|
||||||
|
unset($item['allow']);
|
||||||
}
|
}
|
||||||
if ( $allow ){
|
if ( $allow ){
|
||||||
$result[] = $item;
|
$result[] = $item;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user