/**
  * testing method return array type
  */
 public function testTypeFunction()
 {
     $model = new QuestionBlocForm();
     $criteria = new EMongoCriteria();
     $criteria->id = "demenceform";
     $questionnaire = Questionnaire::model()->find($criteria);
     $this->assertInternalType('array', $model->rules());
     $this->assertInternalType('array', $model->attributeLabels());
     $this->assertFalse($model->validatewithId($questionnaire));
 }
 /**
  * Mise  àjour d un formulaire /mode edition
  * @param $id the ID of the model to be displayed
  */
 public function actionUpdate($id)
 {
     $model = Questionnaire::model()->findByPk(new MongoID($id));
     $questionBlocForm = new QuestionBlocForm();
     $questionForm = new QuestionForm();
     $questionGroup = new QuestionGroup();
     // collect user input data
     if (isset($_POST['QuestionForm'])) {
         $questionForm->attributes = $_POST['QuestionForm'];
         if ($questionForm->validatewithId($model)) {
             if ($questionForm->help == "") {
                 $questionForm->help = null;
             }
             //traitement ajout de question
             if ($questionForm->validate()) {
                 $model = $model->saveQuestionnaireNewQuestion($questionForm);
             } else {
                 Yii::app()->user->setFlash('error', Yii::t('common', 'questionNotAdded'));
             }
         } else {
             Yii::app()->user->setFlash('error', Yii::t('common', 'questionNotAdded'));
         }
     }
     if (isset($_POST['QuestionGroup'])) {
         $questionGroup->attributes = $_POST['QuestionGroup'];
         if ($questionGroup->validatewithId($model)) {
             //copie du titre sur l option fr
             $questionGroup->title_fr = $questionGroup->title;
             if ($questionGroup->validate()) {
                 $model = $model->saveQuestionnaireNewGroup($questionGroup);
             }
         } else {
             Yii::app()->user->setFlash('error', Yii::t('common', 'tabNotAdded'));
         }
     }
     if (isset($_POST['QuestionBlocForm'])) {
         $questionBlocForm->attributes = $_POST['QuestionBlocForm'];
         if ($questionBlocForm->validatewithId($model)) {
             $questionBloc = QuestionBloc::model()->findByPk(new MongoId($questionBlocForm->title));
             $questionBlocForm->title_fr = $questionBlocForm->title;
             $computedGroup = new QuestionGroup();
             $computedGroup->copy($questionBlocForm, $questionBloc);
             if ($computedGroup->validate()) {
                 $model = $model->saveQuestionnaireNewGroup($computedGroup);
             }
             if (isset($questionBloc->questions) && $questionBloc->questions != null && count($questionBloc->questions) > 0) {
                 foreach ($questionBloc->questions as $question => $value) {
                     $currentQuestion = Question::model()->findByPk(new MongoId($value));
                     $questionForm->copy($currentQuestion, $computedGroup);
                     $model->saveQuestionnaireNewQuestionBloc($questionForm);
                 }
             }
         } else {
             Yii::app()->user->setFlash('error', Yii::t('common', 'tabNotAdded'));
         }
     }
     if (isset($_POST['old_onglet'])) {
         foreach ($model->questions_group as $onglet) {
             if ($onglet->id == $_POST['old_onglet']) {
                 $onglet->title = $_POST['new_onglet'];
                 $onglet->title_fr = $_POST['new_onglet'];
                 if ($model->save()) {
                     Yii::app()->user->setFlash('success', Yii::t('common', 'tabUpdated'));
                 } else {
                     Yii::app()->user->setFlash('error', Yii::t('common', 'tabNotUpdated'));
                 }
             }
         }
     }
     if (isset($_POST['old_question'])) {
         foreach ($model->questions_group as $onglet) {
             foreach ($onglet->questions as $question) {
                 if ($question->id == $_POST['old_question']) {
                     $question->label = $_POST['new_question'];
                     $question->label_fr = $_POST['new_question'];
                     if ($model->save()) {
                         Yii::app()->user->setFlash('success', Yii::t('common', 'questionUpdated'));
                     } else {
                         Yii::app()->user->setFlash('error', Yii::t('common', 'questionNotUpdated'));
                     }
                 }
             }
         }
     }
     //  set du model sur la questionForm pour generer l arborescende de position de question
     $questionForm->questionnaire = $model;
     $questionGroup->questionnaire = $model;
     $this->render('update', array('model' => $model, 'questionForm' => $questionForm, 'questionGroup' => $questionGroup, 'questionBloc' => $questionBlocForm));
 }