public function showQuestion($data, $elemId = '', $elemSeq = null, $type = array(), $langId = '') { $html = ''; $htmlVal = ''; $htmlOpt = ''; $params = array(); $oValidation = new FormQuestionValidationTypeObject(); $oOptionsList = new FormResponseOptionObject(); // If loading an existing element (page loading) if (count($data) > 0) { // To simplify when settings registred values $question = $data[0]; //Load data for validation $valOpt = $this->_getValidator($question['FQ_ID'], $langId); $htmlVal = $valOpt['htmlVal']; $htmlOpt = $valOpt['htmlOpt']; // Load data for response options $this->_htmlList = $oOptionsList->getOptionsList($question['FQ_ID'], $langId); // set values from db to build the question $this->_formElemId = "element_" . $question['FQ_ElementID']; $this->_qTextId = "question_" . $question['FQ_ID']; $this->_qValidId = "questionValidation_" . $question['FQ_ID']; $this->_title = $question['FQTI_Title']; $this->_descr = $question['FQTI_Description']; $this->_icon = $this->_baseUrl . $question['FQT_ImageLink']; $this->_htmlVal = $htmlVal; $this->_htmlOpt = $htmlOpt; $this->_elemSeq = $elemSeq; $this->_label = $question['FQI_Title']; $this->_checked = ''; // render the question $html = $this->_render(); } else { $db = Zend_Registry::get('db'); $tableElem = new FormElement(); $tableQst = new FormQuestion(); // Set values to build the new question // Defined default values $this->_title = $type['FQTI_Title']; $this->_descr = $type['FQTI_Description']; $this->_icon = $this->_baseUrl . $type['FQT_ImageLink']; $this->_formElemId = "element_" . $this->_currentElmId; $this->_qTextId = "question_" . $this->_currentQstId; $this->_qValidId = "questionValidation_" . $this->_currentQstId; // Set the validation type for this type of question $this->_htmlVal = $oValidation->getValidationType(1, $langId); // Set the option for this question type // $this->_htmlOpt = $oValidation->getValidationType(2, $langId); // $this->_htmlOpt .= $oValidation->getValidationType(3, $langId); // Set the list to create options $this->_htmlList = $oOptionsList->selectValuesList(); // render the new question $html = $this->_render(); } return $html; }
/** * 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; }
/** * Get the list of vlaues for select list or multi choices. * * @param int $optionId * @param int $langId * * @return array */ protected function _getResponseOption($optionId, $langId = 1) { $oResponseoption = new FormResponseOptionObject(); $optionsList = $oResponseoption->getOptionsList($optionId, $langId); return $optionsList; }