/**
  * testing method return array type
  */
 public function testTypeFunction()
 {
     $model = new Question();
     $questionForm = new QuestionForm();
     $questionForm->id = "q1";
     $questionForm->label = "Question 1";
     $questionForm->type = "input";
     $questionForm->style = "";
     $questionForm->values = "";
     $questionForm->precomment = "";
     $questionForm->precomment_fr = $questionForm->precomment;
     $questionForm->help = "";
     $model->setAttributesByQuestionForm($questionForm);
     $this->assertInternalType('object', $model->model());
     $this->assertInternalType('array', $model->rules());
     $this->assertInternalType('array', $model->attributeLabels());
     $this->assertInternalType('object', $model);
 }
 public function saveBlocNewQuestion($bloc, $questionForm)
 {
     var_dump($bloc);
     $cquestion = new Question();
     $cquestion->setAttributesByQuestionForm($questionForm);
     $bloc->questions = $questionForm->id;
     if ($bloc->save()) {
         Yii::app()->user->setFlash('success', Yii::t('common', 'questionBlockSaved'));
     } else {
         Yii::app()->user->setFlash('error', Yii::t('common', 'questionBlockNotSaved'));
     }
     return $bloc;
 }
 /**
  * save a new question into the questionnaire
  * si pas de positionnement on ajoute la questionen au debut du  groupe
  * @param questionnaire
  */
 public function saveQuestionnaireNewQuestion($questionnaire, $questionForm)
 {
     $questionnaire->last_modified = DateTime::createFromFormat('d/m/Y', date('d/m/Y'));
     $cquestion = new Question();
     $cquestion->setAttributesByQuestionForm($questionForm);
     Yii::log("save questionnaire", CLogger::LEVEL_TRACE);
     //si pas de position fournie, on ajoute la question a la fin, dans le premier groupe de question
     if (!isset($questionForm->idQuestionBefore) || empty($questionForm->idQuestionBefore)) {
         if ($questionnaire->questions_group != null && count($questionnaire->questions_group) > 0) {
             foreach ($questionnaire->questions_group as $group) {
                 if ($group->id == $questionForm->idQuestionGroup) {
                     if ($group->questions == null) {
                         $group->questions = array();
                         $group->questions[] = $cquestion;
                     } else {
                         array_unshift($group->questions, $cquestion);
                     }
                 }
             }
         }
     } else {
         //sinon positionnement relatif
         if ($questionnaire->questions_group != null) {
             foreach ($questionnaire->questions_group as $group) {
                 if ($group->questions != null) {
                     foreach ($group->questions as $key => $question) {
                         if ($question->id == $questionForm->idQuestionBefore) {
                             array_splice($group->questions, $key + 1, 0, array($cquestion));
                         }
                     }
                 }
             }
         }
     }
     if ($questionnaire->save()) {
         Yii::app()->user->setFlash('success', Yii::t('common', 'questionDeleted'));
     } else {
         Yii::app()->user->setFlash('error', Yii::t('common', 'questionNotDeleted'));
         Yii::log("pb save answer" . print_r($answer->getErrors()), CLogger::LEVEL_ERROR);
     }
     return $questionnaire;
 }