Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save exileed/3b6ece45875170eae3b8afc14b139189 to your computer and use it in GitHub Desktop.
Save exileed/3b6ece45875170eae3b8afc14b139189 to your computer and use it in GitHub Desktop.
<?php
namespace app\controllers;
use app\models\Login;
use app\models\Otchet;
use app\models\Result;
use app\models\Signup;
use Yii;
use yii\web\Controller;
class SiteController extends Controller
{
/**
* @inheritdoc
*/
// public function behaviors()
// {
// return [
// 'access' => [
// 'class' => AccessControl::className(),
// 'only' => ['logout'],
// 'rules' => [
// [
// 'actions' => ['logout'],
// 'allow' => true,
// 'roles' => ['@'],
// ],
// ],
// ],
// 'verbs' => [
// 'class' => VerbFilter::className(),
// 'actions' => [
// 'logout' => ['post'],
// ],
// ],
// ];
// }
/**
* @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 string
*/
public function actionLogin()
{
if ( ! Yii::$app->user->isGuest) {
return $this->goHome();
}
$login_model = new Login();
if (Yii::$app->request->post('Login')) {
$login_model->attributes = Yii::$app->request->post('Login');
if ($login_model->validate()) {
Yii::$app->user->login($login_model->getUser());
return $this->goHome();
}
}
return $this->render('login', ['login_model' => $login_model]);
// if (!Yii::$app->user->isGuest) {
// return $this->goHome();
// }
//
// $model = new Login();
// if ($model->load(Yii::$app->request->post()) && $model->login()) {
// return $this->goBack();
// }
// return $this->render('login', [
// 'model' => $model,
// ]);
}
/**
* Logout action.
*
* @return string
*/
public function actionLogout()
{
if ( ! Yii::$app->user->isGuest) {
Yii::$app->user->logout();
return $this->redirect(['login']);
}
}
public function actionAbout()
{
return $this->render('about');
}
/**
* Displays about page.
*
* @return string
*/
public function actionNews()
{
return $this->render('news');
}
public function actionOtchet()
{
$array = Otchet::getAll();
return $this->render('otchet', ['arrayInView' => $array]);
}
public function actionList()
{
return $this->render('list');
}
public function actionTests()
{
return $this->render('tests');
}
public function actionTest1()
{
$model = new Result();
$balls = [
'q1' => [1, 2, 3, 4, 5],
'q2' => [1, 2, 3, 4, 5],
'q3' => [1, 2, 3, 4, 5],
'q4' => [1, 2, 3, 4, 5],
'q5' => [1, 2, 3, 4, 5],
'q6' => [1, 2, 3, 4, 5],
'q7' => [1, 2, 3, 4, 5],
'q8' => [1, 2, 3, 4, 5],
'q9' => [1, 2, 3, 4, 5],
'q10' => [1, 2, 3, 4, 5]
/// ...
];
if (Yii::$app->request->post('Result')) {
$resultBalls = 0;
foreach (Yii::$app->request->post('Result') as $q => $variant) {
$resultBalls += $balls[ $q ][ $variant - 1 ];
}
$model->name = Yii::$app->user->identity->name;
$model->last_name = Yii::$app->user->identity->last_name;
$model->groups = Yii::$app->user->identity->groups;
$model->test1 = $resultBalls;
$model->save(false);
return $this->redirect(['site/index']);
}
//ниже этого кода будешь сохранять результат:
// тут может быть редирект если надо
//$this->redirect(['index']);
return $this->render('test1', ['model' => $model]);
}
public function actionTest2()
{
return $this->render('test2');
}
public function actionTest3()
{
return $this->render('test3');
}
public function actionResult()
{
// $array = Result::getAll();
// return $this->render('result',['arrayInView' => $array ]);
return $this->render('result');
}
public function actionSignup()
{
$model = new Signup();
if (isset($_POST[ 'Signup' ])) {
//var_dump($_POST['Signup']); die();
$model->attributes = Yii::$app->request->post('Signup');
if ($model->validate()) {
$model->signup();
return $this->goHome();
}
}
return $this->render('signup', ['model' => $model]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment