/**
  * Insert into database data of the new validator
  *
  * @param array $data Data of the new validator
  * @param int   $lang Langauge id
  *
  * @return integer
  */
 public function insert($data, $lang)
 {
     if (empty($data)) {
         throw new Exception('Parameter data is empty.');
     }
     // Creates the data entry in the ObjectData Table
     $dataObject = new FormQuestionValidation();
     $_row = $dataObject->createRow($data);
     $_row->save();
     $_dataId = $this->_dataId;
     $_insertedId = $_row->{$_dataId};
     return $_insertedId;
 }
Ejemplo n.º 2
0
 /**
  * Delete questions and linked data.
  *      If the process is called from the element each question will
  *      be processed and relateded data will be deleted too.
  *
  * @param int     $id  Id of the element or of the question itself.
  * @param boolean $all Set the process to use.
  *                     If false then id = question id.
  *
  * @return boolean
  */
 public function deleteAll($id, $all = false)
 {
     $deleted = true;
     $del = 0;
     $oOptions = new FormQuestionOption();
     $oValidation = new FormQuestionValidation();
     $oRespOption = new FormResponseOptionObject();
     // If the method is called with wrong parameters
     if (!$all && empty($id)) {
         throw new Exception('Erreur de paramètres');
     }
     // If deletion is called by deletion of element
     if ($all) {
         //Select all the elements of the section
         $questions = $this->_selectQuestions($id);
         if (count($questions) > 0) {
             //Delete linked data
             foreach ($questions as $question) {
                 //options
                 $del += $oOptions->delete('FQO_QuestionID = "' . $question['FQ_ID'] . '"');
                 //Validation
                 $del += $oValidation->delete('FQV_QuestionID = "' . $question['FQ_ID'] . '"');
                 //ResponseOption
                 $del += $oRespOption->deleteAll($question['FQ_ID']);
                 if ($del == 0) {
                     $deleted = false;
                     break;
                 } else {
                     $this->delete($question['FQ_ID']);
                 }
             }
         }
         // If deletion is done for only a defined section
     } else {
         // call the elements to be deleted
         $delOpt = $oOptions->delete('FQO_QuestionID = "' . $id . '"');
         //Validation
         $delVal = $oValidation->delete('FQV_QuestionID = "' . $id . '"');
         //ResponseOption
         //            $delRespOpt = $oRespOption->delete($id);
         if ($delOpt == 0 || $delVal == 0) {
             $deleted = false;
             break;
         } else {
             $this->delete($id);
         }
     }
     return $deleted;
 }