add admin timetable

This commit is contained in:
2019-10-23 08:49:40 +02:00
committed by Roland Schneider
parent 1300bfc752
commit bf85c737d5
32 changed files with 1037 additions and 120 deletions

View File

@@ -5,15 +5,24 @@ namespace common\modules\event\controllers;
use common\manager\EventRegistrationManager;
use common\models\CardEventRegistrationForm;
use common\modules\event\EventModule;
use common\modules\event\models\copy\CopyWeekSearch;
use common\modules\event\models\EventPermissions;
use common\modules\event\models\timetable\TimeTableSearch;
use DateTime;
use Exception;
use Throwable;
use Yii;
use common\models\Event;
use common\modules\event\models\EventSearch;
use yii\data\ActiveDataProvider;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\HttpException;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\Response;
/** @noinspection PhpUnused */
/**
* EventController implements the CRUD actions for Event model.
@@ -22,9 +31,9 @@ class EventController extends Controller
{
public function behaviors()
{
$behaviors = [
$behaviors = [
'verbs' => [
'class' => VerbFilter::className(),
'class' => VerbFilter::class,
'actions' => [
'delete' => ['post'],
],
@@ -32,24 +41,25 @@ class EventController extends Controller
];
$module = EventModule::getInstance();
$allowedActions = [ 'index','view', 'reserve-card','cancel-registration','delete-registration' ];
if ( $module->mode == 'backend' ){
assert(isset($module), 'event module not set');
$allowedActions = ['index', 'view', 'reserve-card', 'cancel-registration', 'delete-registration', 'timetable','copy-week'];
if ($module->mode === 'backend') {
$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
'class' => AccessControl::class,
'rules' => [
// allow authenticated users
[
'actions' => $allowedActions,
'allow' => true,
'roles' => ['@'],
],
];
// everything else is denied
],
];
return $behaviors;
}
@@ -84,7 +94,7 @@ class EventController extends Controller
$dataProvider = new ActiveDataProvider([
'query' => $eventRegistrationManager->createFindRegistrationsQuery($id),
'query' => $eventRegistrationManager->createFindRegistrationsQuery($id),
]
);
return $this->render('view', [
@@ -103,13 +113,14 @@ class EventController extends Controller
{
$model = new Event();
/** @noinspection NotOptimalIfConditionsInspection */
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
@@ -123,13 +134,14 @@ class EventController extends Controller
{
$model = $this->findModel($id);
/** @noinspection NotOptimalIfConditionsInspection */
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
@@ -138,65 +150,63 @@ class EventController extends Controller
* @param integer $id
* @return mixed
* @throws NotFoundHttpException
* @throws \yii\db\Exception
* @throws Throwable
*/
public function actionDelete($id)
{
$manager = new EventRegistrationManager();
$manager->deleteEvent($this->findModel($id));
return $this->redirect(['index']);
}
}/** @noinspection PhpUnused */
/**
* @param $id
* @return \yii\web\Response
* @throws \yii\db\Exception
* @throws \Exception
* @return Response
* @throws Exception
*/
public function actionCancelRegistration($id)
{
$eventRegistrationManager = new EventRegistrationManager();
$db = \Yii::$app->db;
$db = Yii::$app->db;
$tx = $db->beginTransaction();
try{
try {
$registration = $eventRegistrationManager->loadRegistration($id);
$eventRegistrationManager->cancelRegistration($registration);
$tx->commit();
return $this->redirect(['view', 'id' => $registration->id_event]);
}catch (\Exception $ex){
} catch (Exception $ex) {
$tx->rollBack();
throw $ex;
}
}
}/** @noinspection PhpUnused */
/**
* @param $id
* @return \yii\web\Response
* @throws \yii\db\Exception
* @throws \Exception
* @return Response
* @throws Exception
*/
public function actionDeleteRegistration($id)
{
$eventRegistrationManager = new EventRegistrationManager();
$db = \Yii::$app->db;
$db = Yii::$app->db;
$tx = $db->beginTransaction();
try{
try {
$registration = $eventRegistrationManager->loadRegistration($id);
$eventRegistrationManager->deleteRegistration($registration);
$tx->commit();
return $this->redirect(['view', 'id' => $registration->id_event]);
}catch (\Exception $ex){
} catch (Exception $ex) {
$tx->rollBack();
throw $ex;
}
}
}/** @noinspection PhpUnused */
/**
* @param $id
* @return string|\yii\web\Response
* @return string|Response
* @throws NotFoundHttpException
* @throws \yii\db\Exception
* @throws Exception
*/
public function actionReserveCard($id)
{
@@ -210,11 +220,11 @@ class EventController extends Controller
$manager = new EventRegistrationManager();
try {
$manager->registerCard($model);
} catch (HttpException $e) {
} /** @noinspection PhpRedundantCatchClauseInspection */ catch (HttpException $e) {
if (array_key_exists($e->getCode(), EventRegistrationManager::$STATES)) {
$model->addError("card_number", Yii::t('event-registration', EventRegistrationManager::$STATES[$e->getCode()]));
$model->addError('card_number', Yii::t('event-registration', EventRegistrationManager::$STATES[$e->getCode()]));
} else {
$model->addError("card_number", Yii::t('event-registration', "Unknown Error"));
$model->addError('card_number', Yii::t('event-registration', 'Unknown Error'));
}
}
}
@@ -223,9 +233,9 @@ class EventController extends Controller
'model' => $model,
'event' => $event,
]);
} else {
return $this->redirect(['view', 'id' => $id]);
}
return $this->redirect(['view', 'id' => $id]);
}
return $this->render('register_card', [
'model' => $model,
@@ -233,6 +243,28 @@ class EventController extends Controller
]);
}
/** @noinspection PhpUnused */
/**
* @return string
* @throws Exception
*/
public function actionTimetable()
{
$search = new TimeTableSearch();
$search->startDateString = (new DateTime())->format('Y.m.d');
$dataProvider = $search->search(Yii::$app->request->get());
return $this->render('timetable', array(
'model' => $search,
'dataProvider' => $dataProvider
));
}
public function actionCopyWeek(){
$model = new CopyWeekSearch();
$model->search(\Yii::$app->request->get());
return $this->render('copy_week',['model' => $model]);
}
/**
* Finds the Event model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
@@ -244,8 +276,9 @@ class EventController extends Controller
{
if (($model = Event::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}