public function run()
 {
     if (isset($_GET['id'])) {
         $id = $_GET['id'];
         $oneTest = Teaching::model()->findByPk($id);
         if (isset($oneTest['help']) && !empty($oneTest['help'])) {
             $information = json_decode($oneTest['help'], true);
             $this->render('informationPanel', array('information' => $information, 'id' => $id, 'oneTest' => $oneTest));
         }
     }
 }
 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 actionTimeEnd()
 {
     if (isset($_POST['id'])) {
         $id = (int) $_POST['id'];
         $oneTest = Teaching::model()->findByPk($id);
         if ($oneTest) {
             $questions = json_decode($oneTest->question, true);
             //$timeStart = Yii::app()->session['dateStart'][$id];
             //$timer = $oneTest->duration*60-(time()-$timeStart);
             Yii::app()->session->add('timer', array($id => $oneTest->duration * 60));
             Yii::app()->session->add('step', array($id => sizeof($questions) + 1));
             header('Content-type: application/json');
             echo json_encode(array('ok' => 1));
             Yii::app()->end();
         }
     }
 }
 public function actionEdit()
 {
     Yii::import('admin.forms.*');
     $form = new BasicSettingsForm();
     $page = Teaching::model()->findByPk(Yii::app()->request->getParam('id'));
     if ($page === null) {
         $page = new Teaching();
         $questions_json = json_encode("");
         $help_json = json_encode("");
     } else {
         $questions_json = $page->question;
         $help_json = $page->help;
     }
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'page-edit-form') {
         echo CActiveForm::validate($page);
         Yii::app()->end();
     }
     if (isset($_POST['Teaching']) && $_POST['BasicSettingsForm']) {
         $_POST['BasicSettingsForm'] = Yii::app()->input->stripClean($_POST['BasicSettingsForm']);
         $_POST['Teaching'] = Yii::app()->input->stripClean($_POST['Teaching']);
         //$_POST['Help'] = Yii::app()->input->stripClean($_POST['Help']);
         $typeQuestion = $_POST['Teaching']['type_question'];
         unset($typeQuestion['question']);
         unset($typeQuestion['question_type']);
         unset($typeQuestion['question_type_text']);
         unset($typeQuestion['answer']);
         //typeQuestion = array_chunk($typeQuestion, 5, true);
         $i = 1;
         $array = array();
         foreach ($typeQuestion as $key => $item) {
             $index = preg_replace("/(\\D)/", "", $key);
             $array[$index][$key] = $item;
         }
         $questions_data = array();
         foreach ($array as $k => $v) {
             $question = preg_replace("/(\\d)/", "", 'question' . $k);
             $question_type = preg_replace("/(\\d)/", "", 'question_type' . $k);
             $question_type_text = preg_replace("/(\\d)/", "", 'question_type_text' . $k);
             $answer = preg_replace("/(\\d)/", "", 'answer' . $k);
             $question_type_radio = preg_replace("/(\\d)/", "", 'question_type_radio' . $k);
             $question_type_checkbox = preg_replace("/(\\d)/", "", 'question_type_checkbox' . $k);
             if ($question == 'question') {
                 $questions_data[$k]['question'] = $v['question' . $k][0];
             }
             if ($question_type == 'question_type') {
                 $questions_data[$k]['type'] = $v['question_type' . $k][0];
             }
             //print_r($v['question_type_radio'.$k]);
             if ($question_type_radio == 'question_type_radio') {
                 if ($v['question_type' . $k][0] == 0) {
                     $questions_data[$k]['selected'] = $v['question_type_radio' . $k];
                 }
             }
             if ($question_type_checkbox == 'question_type_checkbox') {
                 if ($v['question_type' . $k][0] == 1) {
                     $questions_data[$k]['selected'] = implode(',', $v['question_type_checkbox' . $k]);
                 }
             }
             if ($question_type_text == 'question_type_text') {
                 if ($v['question_type' . $k][0] == 2) {
                     $questions_data[$k]['selected'] = implode(',', $v['question_type_text' . $k]);
                 }
             }
             if ($answer == 'answer') {
                 $questions_data[$k]['answers'] = $v['answer' . $k];
             }
         }
         $questions_data = array_values($questions_data);
         $questions_json = json_encode($questions_data);
         $page->question = $questions_json;
         /*Help informations*/
         $help = $_POST['Help'];
         $help_data = array();
         if (isset($help['name'])) {
             foreach ($help['name'] as $key => $item) {
                 if (isset($help['text'][$key])) {
                     $help_data[$key]['name'] = $item;
                     $help_data[$key]['text'] = htmlspecialchars(addslashes($help['text'][$key]));
                 }
             }
             $help_data = array_values($help_data);
             $help_json = json_encode($help_data);
             $page->help = $help_json;
         }
         /*Help informations*/
         $page->name = $_POST['Teaching']['name'];
         $page->date_start = $_POST['Teaching']['date_start'];
         $page->date_end = $_POST['Teaching']['date_end'];
         $page->duration = $_POST['Teaching']['duration'];
         $page->visibility = $_POST['Teaching']['visibility'];
         $page->many = $_POST['Teaching']['many'];
         $page->space_id = $_POST['BasicSettingsForm']['defaultSpaceGuid'];
         $page->description = $_POST['description'];
         //$page->attributes = $_POST['Teaching'];
         if ($page->validate()) {
             if ($page->save()) {
                 $this->redirect(Yii::app()->createUrl('//teaching/admin'));
             } else {
                 echo "<pre>";
                 print_r($page->getErrors());
             }
         }
     }
     $root = array();
     //$pages = Teaching::model()->findAll();
     $space_id = explode(",", $page->space_id);
     foreach ($space_id as $key => $item) {
         if (empty($item)) {
             unset($space_id[$key]);
         }
     }
     foreach (Space::model()->findAllByAttributes(array('guid' => $space_id)) as $defaultSpace) {
         $form->defaultSpaceGuid .= $defaultSpace->guid . ",";
     }
     $this->render('edit', array('page' => $page, 'model' => $form, 'root' => $root, 'questions_json' => $questions_json, 'help_json' => $help_json));
 }