Esempio n. 1
0
 /**
  * Delete elements and linked data.
  *      If the process is called from the section each element will
  *      be processed and linked data will be deleted too.
  *
  * @param int     $id  Id of the section or the element itself.
  * @param boolean $all Set the process to use.
  *
  * @return boolean
  */
 public function deleteAll($id, $all = false)
 {
     $deleted = true;
     $oQuestion = new FormQuestionObject();
     $oText = new FormTextObject();
     // If the method is called with wrong parameters
     // If the method is called with wrong parameters
     if (!$all && empty($id)) {
         throw new Exception('Erreur de paramètres');
     }
     // If deletion is called by section deletion
     if ($all) {
         //Select all the elements of the section
         $elements = $this->_selectElements($id, $all);
         if (count($elements) > 0) {
             //Call elements in section to delete them too
             foreach ($elements as $element) {
                 if ($element['FE_TypeID'] == '2') {
                     $delElem = $oQuestion->deleteAll($element[$this->_dataId], $all);
                 } elseif ($element['FE_TypeID'] == '1') {
                     $delElem = $oText->deleteAll($element[$this->_dataId], $all);
                 }
                 if ($delElem) {
                     $this->delete($element[$this->_dataId]);
                 } else {
                     $deleted = false;
                     break;
                 }
             }
         }
         // If deletion is done for only a defined section
     } else {
         // call the elements to be deleted
         $element = $this->_selectElements($id);
         if (count($element) && $element[0]['FE_TypeID'] == '2') {
             $deleted = $oQuestion->deleteAll($id, true);
         } elseif (count($element) && $element[0]['FE_TypeID'] == '1') {
             $deleted = $oText->deleteAll($element[0][$this->_dataId], true);
         }
         if ($deleted) {
             $this->delete($id);
         }
     }
     return $deleted;
 }