Пример #1
0
 /**
  * actionEvaQuestionWizard
  */
 public function actionEvaQuestionWizard()
 {
     Yii::log("actionEvaQuestionWizard called", "trace", self::LOG_CAT);
     $this->setPageTitle('Evaluation question wizard');
     $this->layout = '//layouts/column3';
     $model = new EvaluationQuestion('wizard');
     $elements = ContextController::getDefaultElements();
     $questionId = '';
     $menu = [];
     if (empty($_POST['EvaluationQuestion'])) {
         $questions = $model->with('evalQuestionAnswers')->find("flag='primary'");
         unset(Yii::app()->session['leftMenu']);
         $menu[$questions->evalQuestionId]['label'] = $questions->question;
         //var_dump($questions); die;
     } else {
         //print_r($_POST); die;
         $answerId = $_POST['EvaluationQuestion']['answer'];
         $rsAnswers = EvalQuestionAnswers::model()->with('evalQuestion')->findByPk($answerId);
         $questionId = $rsAnswers->nextQuestion;
         $questions = $model->with('evalQuestionAnswers')->findByPk($questionId);
         //var_dump($questions); die();
         if ($questions->flag !== 'final') {
             //print_r($rsMenu); die;
             $menu = CHtml::tag('li', [], "Q: " . addslashes($rsAnswers->evalQuestion->question) . "<br /> A: " . $rsAnswers->optionName);
             Yii::app()->session['leftMenu'] .= $menu;
             if (isset($rsAnswers->flashQuestion)) {
                 Yii::app()->user->setFlash('notice', $rsAnswers->flashQuestion);
             }
         }
         //print_r(Yii::app()->session['leftMenu']); die;
     }
     if (isset($questions->flag) && 'final' == $questions->flag) {
         Yii::app()->user->setFlash('success', 'A question has been selected as per your previous choices');
         $this->redirect(['evaluation/evalQuestionList', 'questionId' => $questionId]);
     }
     $link = '';
     //var_dump($questions[0]['evalQuestionAnswers'], 'fdsf'); //die;
     foreach ($questions->evalQuestionAnswers as $answerKey => $answer) {
         if (!empty($answer->url)) {
             $link = CHtml::link($answer->optionName, $this->createUrl($answer->url));
             if ($answer->url == 'epitools') {
                 $link = CHtml::link($answer->optionName, Yii::app()->params['other']['epitoolsUrl'], ['target' => '_blank']);
             }
             //$questions[0]['evalQuestionAnswers'][$answerKey]->unsetAttributes();
         }
     }
     $elements['elements'] = ['<h4>' . $questions->question . '</h4>', 'answer' => ['type' => 'radiolist', 'style' => 'width:1em;', 'labelOptions' => ['style' => 'display:inline'], 'items' => $model->getItems($questions['evalQuestionAnswers']), 'label' => '', 'afterRequiredLabel' => '']];
     $elements['buttons'] = ['back' => ['type' => 'button', 'label' => 'Back', 'onClick' => 'history.go(-1)'], 'submit' => ['type' => 'submit', 'label' => 'Next']];
     if (isset($questions->flag) && 'end' == $questions->flag) {
         unset($elements['elements']['question']);
         unset($elements['buttons']);
         $link = '<br />' . CHtml::link('Click here to select an evaluation question', $this->createUrl('evalQuestionList'));
     }
     if (!empty($link)) {
         array_push($elements['elements'], $link);
     }
     //print_r($questions[0]['evalQuestionAnswers']); die('pooop');
     $form = new CForm($elements, $model);
     $this->render('evalQuestion', compact('form'));
 }