public function run()
 {
     $data = array();
     $data_user = array();
     if ($this->teachingAnswer) {
         foreach ($this->teachingAnswer as $one) {
             $questions = json_decode($this->oneTest->question, true);
             $teach = json_decode($one->answers, true);
             //list($imp) = Yii::app()->createController('TeachingController');
             $answer = Teaching::getAnswers($questions, $teach);
             $answerTrue = array();
             foreach ($answer as $key => $item) {
                 if ($item != 0) {
                     $answerTrue[$key] = $item;
                 }
             }
             $procent = ceil(sizeof($answerTrue) * 100 / sizeof($answer));
             if ($one['time']) {
                 $timer = $one['time'];
                 $timers = array();
                 if ($this->oneTest->duration * 60 - $timer > 0) {
                     $timers['second'] = $this->oneTest->duration * 60 - $timer;
                 } else {
                     $timers['second'] = $this->oneTest->duration * 60;
                 }
                 $timers['h'] = floor($timers['second'] / 3600);
                 $timers['m'] = floor($timers['second'] % 3600 / 60);
                 $timers['s'] = $timers['second'] % 3600 % 60;
             }
             $user = User::model()->findByPk($one->user_id);
             $data['username'] = $user->username;
             $data['created'] = $one->created_at;
             $data['answer'] = $answer;
             $data['procent'] = $procent;
             $data['answerTrue'] = $answerTrue;
             $data['timers'] = $timers;
             array_push($data_user, $data);
         }
     }
     if ($this->in_admin) {
         $this->render('resultAdminUser', array('data_user' => $data_user, 'name' => $this->oneTest->name));
     } else {
         $this->render('resultUser', array('data_user' => $data_user));
     }
 }
 public function actionFinish()
 {
     if (isset($_GET['del']) && $_GET['del'] == 1) {
         Yii::app()->session->remove('step');
     }
     if (isset($_GET['id'])) {
         $id = (int) $_GET['id'];
         $oneTest = Teaching::model()->findByPk($id);
         if (!isset(Yii::app()->session['timer'][$id])) {
             Yii::app()->request->redirect($this->createUrl('//teaching/teaching/test', array('sguid' => Yii::app()->getController()->getSpace()->guid, 'id' => $id)), true);
         }
         $questions = json_decode($oneTest->question, true);
         if (isset(Yii::app()->session['teach'][$id]) && Yii::app()->session['step'][$id] > sizeof($questions)) {
             $teach = Yii::app()->session['teach'][$id];
             $teach = array_values($teach);
             $answer = Teaching::getAnswers($questions, $teach);
             $answerTrue = array();
             foreach ($answer as $key => $item) {
                 if ($item != 0) {
                     $answerTrue[$key] = $item;
                 }
             }
             $procent = ceil(sizeof($answerTrue) * 100 / sizeof($answer));
             $teachingAnswer = new TeachingAnswer();
             //$user = User::model()->findByPk(Yii::app()->user->id);
             $teachingAnswer->user_id = Yii::app()->user->id;
             $teachingAnswer->teaching_id = $id;
             $teachingAnswer->answers = json_encode($teach);
             $teachingAnswer->result = $procent;
             if (isset(Yii::app()->session['timer'][$id])) {
                 $timer = Yii::app()->session['timer'][$id];
                 $timers = array();
                 if ($oneTest->duration * 60 - $timer > 0) {
                     $timers['second'] = $oneTest->duration * 60 - $timer;
                 } else {
                     $timers['second'] = $oneTest->duration * 60;
                 }
                 $timers['h'] = floor($timers['second'] / 3600);
                 $timers['m'] = floor($timers['second'] % 3600 / 60);
                 $timers['s'] = $timers['second'] % 3600 % 60;
                 $teachingAnswer->time = $timer;
             }
             if ($teachingAnswer->validate()) {
                 $teachingAnswer->save();
                 Yii::app()->session->remove('teach');
                 Yii::app()->session->remove('step');
                 Yii::app()->session->remove('timer');
                 Yii::app()->session->remove('dateStart');
             }
             $this->render('finish', array('answer' => $answer, 'answerTrue' => $answerTrue, 'procent' => $procent, 'timers' => $timers, 'oneTest' => $oneTest));
         }
     }
 }