/** * Inserts a question in the survey and saves the relation to the database * * @access public */ function insertQuestion($question_id) { global $ilDB; include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php"; if (!SurveyQuestion::_isComplete($question_id)) { return FALSE; } else { // get maximum sequence index in test $result = $ilDB->queryF("SELECT survey_question_id FROM svy_svy_qst WHERE survey_fi = %s", array('integer'), array($this->getSurveyId())); $sequence = $result->numRows(); $duplicate_id = $this->duplicateQuestionForSurvey($question_id); $next_id = $ilDB->nextId('svy_svy_qst'); $affectedRows = $ilDB->manipulateF("INSERT INTO svy_svy_qst (survey_question_id, survey_fi, question_fi, sequence, tstamp) VALUES (%s, %s, %s, %s, %s)", array('integer', 'integer', 'integer', 'integer', 'integer'), array($next_id, $this->getSurveyId(), $duplicate_id, $sequence, time())); $this->loadQuestionsFromDb(); return TRUE; } }
/** * Add new question to survey * * @param int $a_new_id */ public function insertNewQuestion($a_new_id) { global $rbacsystem, $ilDB, $lng; include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php"; if (!SurveyQuestion::_isComplete($a_new_id)) { ilUtil::sendFailure($lng->txt("survey_error_insert_incomplete_question")); } else { $a_new_id = $this->appendNewQuestionToSurvey($a_new_id); $this->object->loadQuestionsFromDb(); $pos = $_REQUEST["pgov_pos"]; // a[fter]/b[efore] on same page if (substr($pos, -1) != "c") { // block handling $current = $this->object->getSurveyPages(); $current = $current[$this->current_page - 1]; if (sizeof($current) == 1) { // as questions are moved to first block question // always use existing as first // the new question is moved later on (see below) $this->object->createQuestionblock($this->getAutoBlockTitle(), true, false, array((int) $pos, $a_new_id)); } else { $block_id = array_pop($current); $block_id = $block_id["questionblock_id"]; $this->object->addQuestionToBlock($a_new_id, $block_id); } } else { // after given question if ((int) $pos) { $pos = (int) $pos . "a"; $this->current_page++; } else { $first = $this->object->getSurveyPages(); $first = $first[0]; $first = array_shift($first); $pos = $first["question_id"] . "b"; $this->current_page = 1; } } // move to target position $this->object->moveQuestions(array($a_new_id), (int) $pos, substr($pos, -1) == "a" ? 1 : 0); } }
protected function save($a_return = false, $a_sync = false) { global $ilUser; if ($this->saveForm()) { // #13784 if ($a_return && !SurveyQuestion::_isComplete($this->object->getId())) { ilUtil::sendFailure($this->lng->txt("survey_error_insert_incomplete_question")); return $this->editQuestion(); } $ilUser->setPref("svy_lastquestiontype", $this->object->getQuestionType()); $ilUser->writePref("svy_lastquestiontype", $this->object->getQuestionType()); $originalexists = $this->object->_questionExists($this->object->original_id); $this->ctrl->setParameter($this, "q_id", $this->object->getId()); include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php"; // pool question? if ($a_sync) { ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true); $this->ctrl->redirect($this, 'copySyncForm'); } else { // form: update original pool question, too? if ($originalexists && SurveyQuestion::_isWriteable($this->object->original_id, $ilUser->getId())) { if ($a_return) { $this->ctrl->setParameter($this, 'rtrn', 1); } $this->ctrl->redirect($this, 'originalSyncForm'); } } ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true); $this->redirectAfterSaving($a_return); } }