Guest User

Untitled

a guest
Jun 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. <?php
  2.  
  3. namespace app\controllers;
  4.  
  5. use app\models\Result;
  6. use app\models\Signup;
  7. use Yii;
  8. use DateTime;
  9. use yii\web\Controller;
  10. use app\models\Login;
  11. use app\models\User;
  12. use app\models\Otchet;
  13. use app\models\Member;
  14. use app\models\Personal;
  15. use yii\web\IdentityInterface;
  16.  
  17.  
  18. class SiteController extends Controller
  19. {
  20.  
  21. public function actionTest1() {
  22. $name = Yii::$app->user->identity->name;
  23. $last_name = Yii::$app->user->identity->last_name;
  24. $groups = Yii::$app->user->identity->groups;
  25.  
  26.  
  27.  
  28. $model = Result::find()->where( [
  29. 'name' => $name,
  30. 'last_name' => $last_name,
  31. 'groups' => $groups,
  32. ] )->one();
  33.  
  34. if ( ! $model ) {
  35. $model = new Result( [
  36. 'name' => $name,
  37. 'last_name' => $last_name,
  38. 'groups' => $groups,
  39. ] );
  40. // $model->save( false );
  41. }
  42.  
  43.  
  44. $balls = [
  45. 'q1' => [ 1, 2, 3, 4, 5 ],
  46. 'q2' => [ 1, 2, 3, 4, 5 ],
  47. 'q3' => [ 1, 2, 3, 4, 5 ],
  48. 'q4' => [ 1, 2, 3, 4, 5 ],
  49. 'q5' => [ 1, 2, 3, 4, 5 ],
  50. 'q6' => [ 1, 2, 3, 4, 5 ],
  51. 'q7' => [ 1, 2, 3, 4, 5 ],
  52. 'q8' => [ 1, 2, 3, 4, 5 ],
  53. 'q9' => [ 1, 2, 3, 4, 5 ],
  54. 'q10' => [ 1, 2, 3, 4, 5 ]
  55. /// ...
  56. ];
  57.  
  58.  
  59. if ( isset( $_POST['Result'] ) ) {
  60.  
  61. $resultBalls = 0;
  62. foreach ( $_POST['Result'] as $q => $variant ) {
  63. $resultBalls += $balls[ $q ][ $variant - 1 ];
  64. }
  65. if ($model->isNewRecord) {
  66. $model->save(false);
  67. }
  68.  
  69.  
  70. $attributes = ['time' => new \yii\db\Expression("NOW()"),
  71. 'test1' => $resultBalls
  72. ];
  73.  
  74. Result::updateAll($attributes, ['id' => $model->id]);
  75.  
  76.  
  77. return $this->redirect( [ 'site/otchet' ] );
  78. }
  79.  
  80. return $this->render( 'test1', [ 'model' => $model ] );
  81. }
Add Comment
Please, Sign In to add comment