/** * Paste from clipboard * * @param int $a_id target position */ protected function paste($a_id) { $data = $_SESSION["survey_page_view"][$this->ref_id]["clipboard"]; $pages = $this->object->getSurveyPages(); $source = $pages[$data["source"] - 1]; $target = $pages[$this->current_page - 1]; $nodes = $data["nodes"]; // append to last position? $pos = 0; if ($_REQUEST["il_hform_node"] == "page_end") { $a_id = $target; $a_id = array_pop($a_id); $a_id = $a_id["question_id"]; $pos = 1; } // cut if ($data["mode"] == "cut") { // special case: paste cut on same page (no block handling needed) if ($data["source"] == $this->current_page) { // re-order nodes in page if (sizeof($nodes) <= sizeof($source)) { $this->object->moveQuestions($nodes, $a_id, $pos); } $this->clearClipboard(); return; } else { // only if source has block $source_block_id = false; if (sizeof($source) > 1) { $source_block_id = $source; $source_block_id = array_shift($source_block_id); $source_block_id = $source_block_id["questionblock_id"]; // remove from block if (sizeof($source) > sizeof($nodes)) { foreach ($nodes as $qid) { $this->object->removeQuestionFromBlock($qid, $source_block_id); } } else { $this->object->unfoldQuestionblocks(array($source_block_id)); } } // page will be "deleted" by operation if (sizeof($source) == sizeof($nodes) && $data["source"] < $this->current_page) { $this->current_page--; } } } else { if ($data["mode"] == "copy") { $titles = array(); foreach ($this->object->getSurveyPages() as $page) { foreach ($page as $question) { $titles[] = $question["title"]; } } // copy questions $question_pointer = array(); foreach ($nodes as $qid) { // create new questions $question = ilObjSurvey::_instanciateQuestion($qid); // handle exisiting copies $title = $question->getTitle(); $max = 0; foreach ($titles as $existing_title) { if (preg_match("/" . preg_quote($title) . " \\(([0-9]+)\\)\$/", $existing_title, $match)) { $max = max($match[1], $max); } } if ($max) { $title .= " (" . ($max + 1) . ")"; } else { $title .= " (2)"; } $titles[] = $title; $question->setTitle($title); $question->id = -1; $question->saveToDb(); $question_pointer[$qid] = $question->getId(); $this->appendNewQuestionToSurvey($question->getId(), false); } // copy textblocks $this->object->cloneTextblocks($question_pointer); $this->object->loadQuestionsFromDb(); $nodes = array_values($question_pointer); } } // paste // create new block if (sizeof($target) == 1) { $nodes = array_merge(array($a_id), $nodes); // moveQuestions() is called within $this->object->createQuestionblock($this->getAutoBlockTitle(), true, false, $nodes); } else { $target_block_id = $target; $target_block_id = array_shift($target_block_id); $target_block_id = $target_block_id["questionblock_id"]; foreach ($nodes as $qid) { $this->object->addQuestionToBlock($qid, $target_block_id); } // move to new position $this->object->moveQuestions($nodes, $a_id, $pos); } $this->clearClipboard(); }
public function executeCopyQuestionsToPoolObject() { $question_ids = explode(";", $_POST["question_ids"]); $pool_id = ilObject::_lookupObjId($_POST["sel_spl"]); foreach ($question_ids as $qid) { // create copy (== pool "original") $new_question = ilObjSurvey::_instanciateQuestion($qid); $new_question->setId(); $new_question->setObjId($pool_id); $new_question->saveToDb(); // link "source" (survey) to copy (pool) SurveyQuestion::_changeOriginalId($qid, $new_question->getId(), $pool_id); } ilUtil::sendSuccess($this->lng->txt("survey_copy_to_questionpool_success"), true); $this->ctrl->redirect($this, "questions"); }
/** * Clone object * * @access public * @param int ref_id of target container * @param int copy id * @return object new svy object */ public function cloneObject($a_target_id, $a_copy_id = 0) { global $ilDB; $this->loadFromDb(); // Copy settings $newObj = parent::cloneObject($a_target_id, $a_copy_id); $this->cloneMetaData($newObj); $newObj->updateMetaData(); $newObj->setAuthor($this->getAuthor()); $newObj->setIntroduction($this->getIntroduction()); $newObj->setOutro($this->getOutro()); $newObj->setStatus($this->getStatus()); $newObj->setEvaluationAccess($this->getEvaluationAccess()); $newObj->setStartDate($this->getStartDate()); $newObj->setEndDate($this->getEndDate()); $newObj->setInvitation($this->getInvitation()); $newObj->setInvitationMode($this->getInvitationMode()); $newObj->setAnonymize($this->getAnonymize()); $newObj->setShowQuestionTitles($this->getShowQuestionTitles()); $newObj->setTemplate($this->getTemplate()); // :;TODO: 360° ?! // reminder/notification $newObj->setReminderStatus($this->getReminderStatus()); $newObj->setReminderStart($this->getReminderStart()); $newObj->setReminderEnd($this->getReminderEnd()); $newObj->setReminderFrequency($this->getReminderFrequency()); $newObj->setReminderTarget($this->getReminderTarget()); // reminder_last_sent must not be copied! $newObj->setTutorNotificationStatus($this->getTutorNotificationStatus()); $newObj->setTutorNotificationRecipients($this->getTutorNotificationRecipients()); $newObj->setTutorNotificationTarget($this->getTutorNotificationTarget()); $question_pointer = array(); // clone the questions $mapping = array(); include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php"; foreach ($this->questions as $key => $question_id) { $question = ilObjSurvey::_instanciateQuestion($question_id); if ($question) { $question->id = -1; $original_id = SurveyQuestion::_getOriginalId($question_id); $question->saveToDb($original_id); $newObj->questions[$key] = $question->getId(); $question_pointer[$question_id] = $question->getId(); $mapping[$question_id] = $question->getId(); } } $newObj->saveToDb(); $newObj->cloneTextblocks($mapping); // clone the questionblocks $questionblocks = array(); $questionblock_questions = array(); $result = $ilDB->queryF("SELECT * FROM svy_qblk_qst WHERE survey_fi = %s", array('integer'), array($this->getSurveyId())); if ($result->numRows() > 0) { while ($row = $ilDB->fetchAssoc($result)) { array_push($questionblock_questions, $row); $questionblocks[$row["questionblock_fi"]] = $row["questionblock_fi"]; } } // create new questionblocks foreach ($questionblocks as $key => $value) { $questionblock = ilObjSurvey::_getQuestionblock($key); $questionblock_id = ilObjSurvey::_addQuestionblock($questionblock["title"], $questionblock["owner_fi"]); $questionblocks[$key] = $questionblock_id; } // create new questionblock questions foreach ($questionblock_questions as $key => $value) { if ($questionblocks[$value["questionblock_fi"]] && $question_pointer[$value["question_fi"]]) { $next_id = $ilDB->nextId('svy_qblk_qst'); $affectedRows = $ilDB->manipulateF("INSERT INTO svy_qblk_qst (qblk_qst_id, survey_fi, questionblock_fi, question_fi) " . "VALUES (%s, %s, %s, %s)", array('integer', 'integer', 'integer', 'integer'), array($next_id, $newObj->getSurveyId(), $questionblocks[$value["questionblock_fi"]], $question_pointer[$value["question_fi"]])); } } // clone the constraints $constraints = ilObjSurvey::_getConstraints($this->getSurveyId()); $newConstraints = array(); foreach ($constraints as $key => $constraint) { if ($question_pointer[$constraint["for_question"]] && $question_pointer[$constraint["question"]]) { if (!array_key_exists($constraint['id'], $newConstraints)) { $constraint_id = $newObj->addConstraint($question_pointer[$constraint["question"]], $constraint["relation_id"], $constraint["value"], $constraint['conjunction']); $newConstraints[$constraint['id']] = $constraint_id; } $newObj->addConstraintToQuestion($question_pointer[$constraint["for_question"]], $newConstraints[$constraint['id']]); } } // clone the obligatory states $result = $ilDB->queryF("SELECT * FROM svy_qst_oblig WHERE survey_fi = %s", array('integer'), array($this->getSurveyId())); if ($result->numRows() > 0) { while ($row = $ilDB->fetchAssoc($result)) { if ($question_pointer[$row["question_fi"]]) { $next_id = $ilDB->nextId('svy_qst_oblig'); $affectedRows = $ilDB->manipulateF("INSERT INTO svy_qst_oblig (question_obligatory_id, survey_fi, question_fi, " . "obligatory, tstamp) VALUES (%s, %s, %s, %s, %s)", array('integer', 'integer', 'integer', 'text', 'integer'), array($next_id, $newObj->getSurveyId(), $question_pointer[$row["question_fi"]], $row["obligatory"], time())); } } } return $newObj; }
/** * Clone object * * @access public * @param int ref_id of target container * @param int copy id * @return object new svy object */ public function cloneObject($a_target_id, $a_copy_id = 0) { global $ilDB; $this->loadFromDb(); // Copy settings $newObj = parent::cloneObject($a_target_id, $a_copy_id); $this->cloneMetaData($newObj); $newObj->updateMetaData(); $newObj->setAuthor($this->getAuthor()); $newObj->setIntroduction($this->getIntroduction()); $newObj->setOutro($this->getOutro()); $newObj->setEvaluationAccess($this->getEvaluationAccess()); $newObj->setStartDate($this->getStartDate()); $newObj->setEndDate($this->getEndDate()); $newObj->setInvitation($this->getInvitation()); $newObj->setInvitationMode($this->getInvitationMode()); $newObj->setAnonymize($this->getAnonymize()); $newObj->setShowQuestionTitles($this->getShowQuestionTitles()); $newObj->setTemplate($this->getTemplate()); $newObj->setPoolUsage($this->getPoolUsage()); $newObj->setViewOwnResults($this->hasViewOwnResults()); $newObj->setMailOwnResults($this->hasMailOwnResults()); // #12661 if ($this->get360Mode()) { $newObj->set360Mode(true); $newObj->set360SelfEvaluation($this->get360SelfEvaluation()); $newObj->set360SelfAppraisee($this->get360SelfAppraisee()); $newObj->set360SelfRaters($this->get360SelfRaters()); $newObj->set360Results($this->get360Results()); $newObj->set360SkillService($this->get360SkillService()); } // reminder/notification $newObj->setReminderStatus($this->getReminderStatus()); $newObj->setReminderStart($this->getReminderStart()); $newObj->setReminderEnd($this->getReminderEnd()); $newObj->setReminderFrequency($this->getReminderFrequency()); $newObj->setReminderTarget($this->getReminderTarget()); // reminder_last_sent must not be copied! $newObj->setTutorNotificationStatus($this->getTutorNotificationStatus()); $newObj->setTutorNotificationRecipients($this->getTutorNotificationRecipients()); $newObj->setTutorNotificationTarget($this->getTutorNotificationTarget()); $question_pointer = array(); // clone the questions $mapping = array(); include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php"; foreach ($this->questions as $key => $question_id) { $question = ilObjSurvey::_instanciateQuestion($question_id); if ($question) { $question->id = -1; $original_id = SurveyQuestion::_getOriginalId($question_id, false); $question->saveToDb($original_id); $newObj->questions[$key] = $question->getId(); $question_pointer[$question_id] = $question->getId(); $mapping[$question_id] = $question->getId(); } } //copy online status if object is not the root copy object $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id); if (!$cp_options->isRootNode($this->getRefId())) { $newObj->setStatus($this->isOnline() ? self::STATUS_ONLINE : self::STATUS_OFFLINE); } $newObj->saveToDb(); $newObj->cloneTextblocks($mapping); // #14929 if ($this->get360Mode() && $this->get360SkillService()) { include_once "./Modules/Survey/classes/class.ilSurveySkill.php"; $src_skills = new ilSurveySkill($this); $tgt_skills = new ilSurveySkill($newObj); foreach ($mapping as $src_qst_id => $tgt_qst_id) { $qst_skill = $src_skills->getSkillForQuestion($src_qst_id); if ($qst_skill) { $tgt_skills->addQuestionSkillAssignment($tgt_qst_id, $qst_skill["base_skill_id"], $qst_skill["tref_id"]); } } } // clone the questionblocks $questionblocks = array(); $questionblock_questions = array(); $result = $ilDB->queryF("SELECT * FROM svy_qblk_qst WHERE survey_fi = %s", array('integer'), array($this->getSurveyId())); if ($result->numRows() > 0) { while ($row = $ilDB->fetchAssoc($result)) { array_push($questionblock_questions, $row); $questionblocks[$row["questionblock_fi"]] = $row["questionblock_fi"]; } } // create new questionblocks foreach ($questionblocks as $key => $value) { $questionblock = ilObjSurvey::_getQuestionblock($key); $questionblock_id = ilObjSurvey::_addQuestionblock($questionblock["title"], $questionblock["owner_fi"], $questionblock["show_questiontext"], $questionblock["show_blocktitle"]); $questionblocks[$key] = $questionblock_id; } // create new questionblock questions foreach ($questionblock_questions as $key => $value) { if ($questionblocks[$value["questionblock_fi"]] && $question_pointer[$value["question_fi"]]) { $next_id = $ilDB->nextId('svy_qblk_qst'); $affectedRows = $ilDB->manipulateF("INSERT INTO svy_qblk_qst (qblk_qst_id, survey_fi, questionblock_fi, question_fi) " . "VALUES (%s, %s, %s, %s)", array('integer', 'integer', 'integer', 'integer'), array($next_id, $newObj->getSurveyId(), $questionblocks[$value["questionblock_fi"]], $question_pointer[$value["question_fi"]])); } } // clone the constraints $constraints = ilObjSurvey::_getConstraints($this->getSurveyId()); $newConstraints = array(); foreach ($constraints as $key => $constraint) { if ($question_pointer[$constraint["for_question"]] && $question_pointer[$constraint["question"]]) { if (!array_key_exists($constraint['id'], $newConstraints)) { $constraint_id = $newObj->addConstraint($question_pointer[$constraint["question"]], $constraint["relation_id"], $constraint["value"], $constraint['conjunction']); $newConstraints[$constraint['id']] = $constraint_id; } $newObj->addConstraintToQuestion($question_pointer[$constraint["for_question"]], $newConstraints[$constraint['id']]); } } // clone the obligatory states $result = $ilDB->queryF("SELECT * FROM svy_qst_oblig WHERE survey_fi = %s", array('integer'), array($this->getSurveyId())); if ($result->numRows() > 0) { while ($row = $ilDB->fetchAssoc($result)) { if ($question_pointer[$row["question_fi"]]) { $next_id = $ilDB->nextId('svy_qst_oblig'); $affectedRows = $ilDB->manipulateF("INSERT INTO svy_qst_oblig (question_obligatory_id, survey_fi, question_fi, " . "obligatory, tstamp) VALUES (%s, %s, %s, %s, %s)", array('integer', 'integer', 'integer', 'text', 'integer'), array($next_id, $newObj->getSurveyId(), $question_pointer[$row["question_fi"]], $row["obligatory"], time())); } } } return $newObj; }