Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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 ] );
- }
Add Comment
Please, Sign In to add comment