Created
June 16, 2018 09:52
-
-
Save AndrewKotin/dcbb0bc51fa804d5d35963227c7a1bd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app\controllers; | |
use app\models\Result; | |
use app\models\Signup; | |
use Yii; | |
use DateTime; | |
use yii\web\Controller; | |
use app\models\Login; | |
use app\models\User; | |
use app\models\Otchet; | |
use app\models\Member; | |
use app\models\Personal; | |
use yii\web\IdentityInterface; | |
class SiteController extends Controller | |
{ | |
public function actionTest1() { | |
$name = Yii::$app->user->identity->name; | |
$last_name = Yii::$app->user->identity->last_name; | |
$groups = Yii::$app->user->identity->groups; | |
$model = Result::find()->where( [ | |
'name' => $name, | |
'last_name' => $last_name, | |
'groups' => $groups, | |
] )->one(); | |
if ( ! $model ) { | |
$model = new Result( [ | |
'name' => $name, | |
'last_name' => $last_name, | |
'groups' => $groups, | |
] ); | |
// $model->save( false ); | |
} | |
$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 ( isset( $_POST['Result'] ) ) { | |
$resultBalls = 0; | |
foreach ( $_POST['Result'] as $q => $variant ) { | |
$resultBalls += $balls[ $q ][ $variant - 1 ]; | |
} | |
if ($model->isNewRecord) { | |
$model->save(false); | |
} | |
$attributes = ['time' => new \yii\db\Expression("NOW()"), | |
'test1' => $resultBalls | |
]; | |
Result::updateAll($attributes, ['id' => $model->id]); | |
return $this->redirect( [ 'site/otchet' ] ); | |
} | |
return $this->render( 'test1', [ 'model' => $model ] ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment