Drupal investigation

SiteController.php 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. namespace app\controllers;
  3. use Drupal\Core\Database\Query\Update;
  4. use Yii;
  5. use yii\filters\AccessControl;
  6. use yii\web\Controller;
  7. use yii\web\Response;
  8. use yii\filters\VerbFilter;
  9. use app\models\LoginForm;
  10. use app\models\ContactForm;
  11. use app\models\UpdateForm;
  12. use app\models\TestUsers;
  13. use \yii\helpers\Url;
  14. class SiteController extends Controller
  15. {
  16. /**
  17. * @inheritdoc
  18. */
  19. public function behaviors()
  20. {
  21. return [
  22. 'access' => [
  23. 'class' => AccessControl::className(),
  24. //'only' => ['logout'],
  25. 'rules' => [
  26. [
  27. 'actions' => ['login','error'],
  28. 'allow' => true,
  29. ],
  30. [
  31. 'actions' => ['logout','index','account','settings','organigram','workflow','about','contact'],
  32. 'allow' => true,
  33. 'roles' => ['@'],
  34. ],
  35. ],
  36. ],
  37. 'verbs' => [
  38. 'class' => VerbFilter::className(),
  39. 'actions' => [
  40. 'logout' => ['post'],
  41. ],
  42. ],
  43. ];
  44. }
  45. //This method should be in every controller
  46. public function init(){
  47. if (!Yii::$app->user->isGuest){
  48. Yii::$app->language = Yii::$app->user->identity->lang;
  49. }
  50. }
  51. /**
  52. * @inheritdoc
  53. */
  54. public function actions()
  55. {
  56. return [
  57. 'error' => [
  58. 'class' => 'yii\web\ErrorAction',
  59. ],
  60. 'captcha' => [
  61. 'class' => 'yii\captcha\CaptchaAction',
  62. 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
  63. ],
  64. ];
  65. }
  66. /**
  67. * Displays homepage.
  68. *
  69. * @return string
  70. */
  71. public function actionIndex()
  72. {
  73. return $this->render('index');
  74. }
  75. /**
  76. * Login action.
  77. *
  78. * @return Response|string
  79. */
  80. public function actionLogin()
  81. {
  82. if (!Yii::$app->user->isGuest) {
  83. return $this->goHome();
  84. }
  85. $model = new LoginForm();
  86. if ($model->load(Yii::$app->request->post()) && $model->login()) {
  87. return $this->goBack();
  88. }
  89. return $this->render('login', [
  90. 'model' => $model,
  91. ]);
  92. }
  93. /**
  94. * Logout action.
  95. *
  96. * @return Response
  97. */
  98. public function actionLogout()
  99. {
  100. Yii::$app->user->logout();
  101. return $this->goHome();
  102. }
  103. /**
  104. * Displays contact page.
  105. *
  106. * @return Response|string
  107. */
  108. public function actionContact()
  109. {
  110. $model = new ContactForm();
  111. if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
  112. Yii::$app->session->setFlash('contactFormSubmitted');
  113. return $this->refresh();
  114. }
  115. return $this->render('contact', [
  116. 'model' => $model,
  117. ]);
  118. }
  119. /**
  120. * Displays about page.
  121. *
  122. * @return string
  123. */
  124. public function actionAbout()
  125. {
  126. return $this->render('about');
  127. }
  128. public function actionWorkflow()
  129. {
  130. return $this->render('workflow');
  131. }
  132. public function actionOrganigram()
  133. {
  134. $rows = (new \yii\db\Query())
  135. ->select(['id', 'username','surname', 'forename'])
  136. ->from('testUsers')
  137. ->all();
  138. return $this->render('organigram', ['users' => $rows]);
  139. }
  140. public function actionAccount()
  141. {
  142. return $this->render('account');
  143. }
  144. public function actionSettings()
  145. {
  146. $model = new UpdateForm;
  147. $languages = ['en' => 'English', 'de' => 'Deutsch'];
  148. if ($model->load(Yii::$app->request->post()) && $model->update()) {
  149. Yii::$app->session->setFlash('success','Your data was successfully submitted!');
  150. return $this->refresh();
  151. }
  152. return $this->render('settings', ['model' => $model, 'languages' => $languages]);
  153. }
  154. }