123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
- namespace app\controllers;
- use Drupal\Core\Database\Query\Update;
- use Yii;
- use yii\filters\AccessControl;
- use yii\web\Controller;
- use yii\web\Response;
- use yii\filters\VerbFilter;
- use app\models\LoginForm;
- use app\models\ContactForm;
- use app\models\UpdateForm;
- use app\models\TestUsers;
- use \yii\helpers\Url;
- class SiteController extends Controller
- {
- /**
- * @inheritdoc
- */
- public function behaviors()
- {
- return [
- 'access' => [
- 'class' => AccessControl::className(),
- //'only' => ['logout'],
- 'rules' => [
- [
- 'actions' => ['login','error'],
- 'allow' => true,
- ],
- [
- 'actions' => ['logout','index','account','settings','organigram','workflow','about','contact'],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- ],
- ],
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'logout' => ['post'],
- ],
- ],
- ];
- }
- //This method should be in every controller
- public function init(){
- if (!Yii::$app->user->isGuest){
- Yii::$app->language = Yii::$app->user->identity->lang;
- }
- }
- /**
- * @inheritdoc
- */
- public function actions()
- {
- return [
- 'error' => [
- 'class' => 'yii\web\ErrorAction',
- ],
- 'captcha' => [
- 'class' => 'yii\captcha\CaptchaAction',
- 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
- ],
- ];
- }
- /**
- * Displays homepage.
- *
- * @return string
- */
- public function actionIndex()
- {
- return $this->render('index');
- }
- /**
- * Login action.
- *
- * @return Response|string
- */
- public function actionLogin()
- {
- if (!Yii::$app->user->isGuest) {
- return $this->goHome();
- }
- $model = new LoginForm();
- if ($model->load(Yii::$app->request->post()) && $model->login()) {
- return $this->goBack();
- }
- return $this->render('login', [
- 'model' => $model,
- ]);
- }
- /**
- * Logout action.
- *
- * @return Response
- */
- public function actionLogout()
- {
- Yii::$app->user->logout();
- return $this->goHome();
- }
- /**
- * Displays contact page.
- *
- * @return Response|string
- */
- public function actionContact()
- {
- $model = new ContactForm();
- if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
- Yii::$app->session->setFlash('contactFormSubmitted');
- return $this->refresh();
- }
- return $this->render('contact', [
- 'model' => $model,
- ]);
- }
- /**
- * Displays about page.
- *
- * @return string
- */
- public function actionAbout()
- {
- return $this->render('about');
- }
- public function actionWorkflow()
- {
- return $this->render('workflow');
- }
- public function actionOrganigram()
- {
- $rows = (new \yii\db\Query())
- ->select(['id', 'username','surname', 'forename'])
- ->from('testUsers')
- ->all();
- return $this->render('organigram', ['users' => $rows]);
- }
- public function actionAccount()
- {
- return $this->render('account');
- }
- public function actionSettings()
- {
- $model = new UpdateForm;
- $languages = ['en' => 'English', 'de' => 'Deutsch'];
- if ($model->load(Yii::$app->request->post()) && $model->update()) {
- Yii::$app->session->setFlash('success','Your data was successfully submitted!');
- return $this->refresh();
- }
- return $this->render('settings', ['model' => $model, 'languages' => $languages]);
- }
- }
|