public function exportQuestion($a_ref_id, $a_image_path = null, $a_output_mode = "presentation")
 {
     if ($a_ref_id != "") {
         $inst_id = ilInternalLink::_extractInstOfTarget($a_ref_id);
         if (!($inst_id > 0)) {
             $q_id = ilInternalLink::_extractObjIdOfTarget($a_ref_id);
         }
     }
     $this->q_gui = assQuestionGUI::_getQuestionGUI("", $q_id);
     if (!is_object($this->q_gui->object)) {
         return "Error: Question not found.";
     }
     $type = $this->q_gui->object->getQuestionType();
     if (method_exists($this, $type)) {
         $this->q_gui->object->setExportImagePath($a_image_path);
         $this->q_gui->object->feedbackOBJ->setPageObjectOutputMode($a_output_mode);
         $this->json = $this->q_gui->object->toJSON();
         $this->json_decoded = json_decode($this->json);
         self::$exported[$this->json_decoded->id] = $this->json;
         self::$mobs[$this->json_decoded->id] = $this->json_decoded->mobs;
         return $this->{$type}();
     } else {
         return "Error: Question Type not implemented/Question editing not finished";
     }
 }
Example #2
0
 /**
  * Update internal links, after multiple pages have been copied
  */
 static function updateInternalLinks($a_copied_nodes, $a_parent_type = "lm")
 {
     $all_fixes = array();
     foreach ($a_copied_nodes as $original_id => $copied_id) {
         $copied_type = ilLMObject::_lookupType($copied_id);
         $copy_lm = ilLMObject::_lookupContObjID($copied_id);
         if ($copied_type == "pg") {
             //
             // 1. Outgoing links from the copied page.
             //
             //$targets = ilInternalLink::_getTargetsOfSource($a_parent_type.":pg", $copied_id);
             include_once "./Modules/LearningModule/classes/class.ilLMPage.php";
             $tpg = new ilLMPage($copied_id);
             $tpg->buildDom();
             $il = $tpg->getInternalLinks();
             $targets = array();
             foreach ($il as $l) {
                 $targets[] = array("type" => ilInternalLink::_extractTypeOfTarget($l["Target"]), "id" => (int) ilInternalLink::_extractObjIdOfTarget($l["Target"]), "inst" => (int) ilInternalLink::_extractInstOfTarget($l["Target"]));
             }
             $fix = array();
             foreach ($targets as $target) {
                 if (($target["inst"] == 0 || ($target["inst"] = IL_INST_ID)) && ($target["type"] == "pg" || $target["type"] == "st")) {
                     // first check, whether target is also within the copied set
                     if ($a_copied_nodes[$target["id"]] > 0) {
                         $fix[$target["id"]] = $a_copied_nodes[$target["id"]];
                     } else {
                         // now check, if a copy if the target is already in the same lm
                         // only if target is not already in the same lm!
                         $trg_lm = ilLMObject::_lookupContObjID($target["id"]);
                         if ($trg_lm != $copy_lm) {
                             $lm_data = ilLMObject::_getAllObjectsForImportId("il__" . $target["type"] . "_" . $target["id"]);
                             $found = false;
                             foreach ($lm_data as $item) {
                                 if (!$found && $item["lm_id"] == $copy_lm) {
                                     $fix[$target["id"]] = $item["obj_id"];
                                     $found = true;
                                 }
                             }
                         }
                     }
                 }
             }
             // outgoing links to be fixed
             if (count($fix) > 0) {
                 //echo "<br>--".$copied_id;
                 //var_dump($fix);
                 $t = ilObject::_lookupType($copy_lm);
                 if (is_array($all_fixes[$t . ":" . $copied_id])) {
                     $all_fixes[$t . ":" . $copied_id] += $fix;
                 } else {
                     $all_fixes[$t . ":" . $copied_id] = $fix;
                 }
             }
         }
         if ($copied_type == "pg" || $copied_type == "st") {
             //
             // 2. Incoming links to the original pages
             //
             // A->B			A2			(A+B currently copied)
             // A->C			B2
             // B->A
             // C->A			C2->A		(C already copied)
             $original_lm = ilLMObject::_lookupContObjID($original_id);
             $original_type = ilObject::_lookupType($original_lm);
             if ($original_lm != $copy_lm) {
                 // This gets sources that link to A+B (so we have C here)
                 // (this also does already the trick when instance map areas are given in C)
                 // int_link, where target_type, target_id, target_inst -> ok
                 $sources = ilInternalLink::_getSourcesOfTarget($copied_type, $original_id, 0);
                 // mobs linking to $original_id
                 // map_area, where link_type, target -> ok
                 $mobs = ilMapArea::_getMobsForTarget("int", "il__" . $copied_type . "_" . $original_id);
                 // pages using these mobs
                 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
                 foreach ($mobs as $mob) {
                     // mob_usage, where id -> ok
                     // mep_item, where foreign_id, type -> ok
                     // mep_tree, where child -> already existed
                     // il_news_item, where mob_id -> ok
                     // map_area, where link_type, target -> aready existed
                     // media_item, where id -> already existed
                     // personal_clipboard, where item_id, type -> ok
                     $usages = ilObjMediaObject::lookupUsages($mob);
                     foreach ($usages as $usage) {
                         if ($usage["type"] == "lm:pg" | $usage["type"] == "lm:st") {
                             $sources[] = $usage;
                         }
                     }
                 }
                 $fix = array();
                 foreach ($sources as $source) {
                     $stype = explode(":", $source["type"]);
                     $source_type = $stype[1];
                     if ($source_type == "pg" || $source_type == "st") {
                         // first of all: source must be in original lm
                         $src_lm = ilLMObject::_lookupContObjID($source["id"]);
                         if ($src_lm == $original_lm) {
                             // check, if a copy if the source is already in the same lm
                             // now we look for the latest copy of C in LM2
                             $lm_data = ilLMObject::_getAllObjectsForImportId("il__" . $source_type . "_" . $source["id"], $copy_lm);
                             $found = false;
                             foreach ($lm_data as $item) {
                                 if (!$found) {
                                     $fix[$item["obj_id"]][$original_id] = $copied_id;
                                     $found = true;
                                 }
                             }
                         }
                     }
                 }
                 // outgoing links to be fixed
                 if (count($fix) > 0) {
                     foreach ($fix as $page_id => $fix_array) {
                         $t = ilObject::_lookupType($copy_lm);
                         if (is_array($all_fixes[$t . ":" . $page_id])) {
                             $all_fixes[$t . ":" . $page_id] += $fix_array;
                         } else {
                             $all_fixes[$t . ":" . $page_id] = $fix_array;
                         }
                     }
                 }
             }
         }
     }
     foreach ($all_fixes as $pg => $fixes) {
         $pg = explode(":", $pg);
         include_once "./Services/COPage/classes/class.ilPageObjectFactory.php";
         $page = ilPageObjectFactory::getInstance($pg[0], $pg[1]);
         if ($page->moveIntLinks($fixes)) {
             $page->update(true, true);
         }
     }
 }
 /**
  * Set tabs
  */
 function setTabs()
 {
     if ($this->getSelfAssessmentMode()) {
         return;
     }
     global $ilTabs, $ilCtrl, $lng;
     include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
     if ($this->content_obj != "") {
         $q_ref = $this->content_obj->getQuestionReference();
     }
     if ($q_ref != "") {
         $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
         if (!($inst_id > 0)) {
             $q_id = ilInternalLink::_extractObjIdOfTarget($q_ref);
         }
     }
     $ilTabs->addTarget("question", $ilCtrl->getLinkTarget($this, "edit"), array("editQuestion", "save", "cancel", "addSuggestedSolution", "cancelExplorer", "linkChilds", "removeSuggestedSolution", "addPair", "addTerm", "delete", "deleteTerms", "editMode", "upload", "saveEdit", "uploadingImage", "uploadingImagemap", "addArea", "deletearea", "saveShape", "back", "saveEdit", "changeGapType", "createGaps", "addItem", "addYesNo", "addTrueFalse", "toggleGraphicalAnswers", "setMediaMode"), "");
     if ($q_id > 0) {
         if (assQuestion::_getQuestionType($q_id) != "assTextQuestion") {
             require_once 'Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
             require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionFeedbackEditingGUI.php';
             $tabCommands = assQuestionGUI::getCommandsFromClassConstants('ilAssQuestionFeedbackEditingGUI');
             $tabLink = ilUtil::appendUrlParameterString($ilCtrl->getLinkTargetByClass('ilAssQuestionFeedbackEditingGUI', ilAssQuestionFeedbackEditingGUI::CMD_SHOW), "q_id=" . (int) $q_id);
             $ilTabs->addTarget('feedback', $tabLink, $tabCommands, $ilCtrl->getCmdClass(), '');
         }
     }
 }
Example #4
0
 function getQuestionIds()
 {
     $this->builddom();
     $mydom = $this->dom;
     // Get question IDs
     $path = "//Question";
     $xpc = xpath_new_context($mydom);
     $res =& xpath_eval($xpc, $path);
     $q_ids = array();
     include_once "./Services/Link/classes/class.ilInternalLink.php";
     for ($i = 0; $i < count($res->nodeset); $i++) {
         $qref = $res->nodeset[$i]->get_attribute("QRef");
         $inst_id = ilInternalLink::_extractInstOfTarget($qref);
         $obj_id = ilInternalLink::_extractObjIdOfTarget($qref);
         if (!($inst_id > 0)) {
             if ($obj_id > 0) {
                 $q_ids[] = $obj_id;
             }
         }
     }
     return $q_ids;
 }
 /**
  * Get current id for an import id
  *
  * @param	string		$a_type			target type ("PageObject" | "StructureObject" |
  *										"GlossaryItem" | "MediaObject")
  * @param	string		$a_target		import target id (e.g. "il_2_pg_22")
  *
  * @return	string		current target id (e.g. "il__pg_244")
  */
 function _getIdForImportId($a_type, $a_target)
 {
     switch ($a_type) {
         case "PageObject":
             $id = ilLMObject::_getIdForImportId($a_target);
             if ($id > 0) {
                 return "il__pg_" . $id;
             }
             break;
         case "StructureObject":
             $id = ilLMObject::_getIdForImportId($a_target);
             if ($id > 0) {
                 return "il__st_" . $id;
             }
             break;
         case "GlossaryItem":
             $id = ilGlossaryTerm::_getIdForImportId($a_target);
             if ($id > 0) {
                 return "il__git_" . $id;
             }
             break;
         case "WikiPage":
             // no import IDs for wiki pages (yet)
             //$id = ilGlossaryTerm::_getIdForImportId($a_target);
             $id = 0;
             if ($id > 0) {
                 return "il__wpage_" . $id;
             }
             break;
         case "MediaObject":
             $id = ilObjMediaObject::_getIdForImportId($a_target);
             if ($id > 0) {
                 return "il__mob_" . $id;
             }
             break;
         case "RepositoryItem":
             $tarr = explode("_", $a_target);
             $import_id = $a_target;
             // if a ref id part is given, strip this
             // since this will not be part of an import id
             if ($tarr[4] != "") {
                 $import_id = $tarr[0] . "_" . $tarr[1] . "_" . $tarr[2] . "_" . $tarr[3];
             }
             if (ilInternalLink::_extractInstOfTarget($a_target) == IL_INST_ID && IL_INST_ID > 0) {
                 // does it have a ref id part?
                 if ($tarr[4] != "") {
                     return "il__obj_" . $tarr[4];
                 }
             }
             $id = ilObject::_getIdForImportId($import_id);
             //echo "-$a_target-$id-";
             // get ref id for object id
             // (see ilPageObject::insertInstIntoIDs for the export procedure)
             if ($id > 0) {
                 $refs = ilObject::_getAllReferences($id);
                 //var_dump($refs);
                 foreach ($refs as $ref) {
                     return "il__obj_" . $ref;
                 }
             }
             break;
     }
     return false;
 }
Example #6
0
 /**
  * After page has been updated (or created)
  *
  * @param object page object
  * @param DOMDocument $a_domdoc dom document
  * @param string xml
  * @param bool true on creation, otherwise false
  */
 static function afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
 {
     global $ilDB;
     include_once "./Services/Link/classes/class.ilInternalLink.php";
     $ilDB->manipulateF("DELETE FROM page_question WHERE page_parent_type = %s " . " AND page_id = %s AND page_lang = %s", array("text", "integer", "text"), array($a_page->getParentType(), $a_page->getId(), $a_page->getLanguage()));
     $xpath = new DOMXPath($a_domdoc);
     $nodes = $xpath->query('//Question');
     $q_ids = array();
     foreach ($nodes as $node) {
         $q_ref = $node->getAttribute("QRef");
         $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
         if (!($inst_id > 0)) {
             $q_id = ilInternalLink::_extractObjIdOfTarget($q_ref);
             if ($q_id > 0) {
                 $q_ids[$q_id] = $q_id;
             }
         }
     }
     foreach ($q_ids as $qid) {
         $ilDB->manipulateF("INSERT INTO page_question (page_parent_type, page_id, page_lang, question_id)" . " VALUES (%s,%s,%s,%s)", array("text", "integer", "text", "integer"), array($a_page->getParentType(), $a_page->getId(), $a_page->getLanguage(), $qid));
     }
 }
 /**
  * Set tabs
  */
 function setTabs()
 {
     global $ilTabs, $ilCtrl, $lng;
     include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
     if ($this->content_obj != "") {
         $q_ref = $this->content_obj->getQuestionReference();
     }
     if ($q_ref != "") {
         $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
         if (!($inst_id > 0)) {
             $q_id = ilInternalLink::_extractObjIdOfTarget($q_ref);
         }
     }
     $ilTabs->addTarget("question", $ilCtrl->getLinkTarget($this, "edit"), array("editQuestion", "save", "cancel", "addSuggestedSolution", "cancelExplorer", "linkChilds", "removeSuggestedSolution", "addPair", "addTerm", "delete", "deleteTerms", "editMode", "upload", "saveEdit", "uploadingImage", "uploadingImagemap", "addArea", "deletearea", "saveShape", "back", "saveEdit", "changeGapType", "createGaps", "addItem", "addYesNo", "addTrueFalse", "toggleGraphicalAnswers", "setMediaMode"), "");
     if ($q_id > 0) {
         if (assQuestion::_getQuestionType($q_id) != "assTextQuestion") {
             $ilTabs->addTarget("feedback", $ilCtrl->getLinkTarget($this, "feedback"), array("feedback", "saveFeedback"), "");
         }
     }
 }