function _resolveIntLinks($question_id)
 {
     global $ilDB;
     $resolvedlinks = 0;
     $result = $ilDB->queryF("SELECT * FROM svy_material WHERE question_fi = %s", array('integer'), array($question_id));
     if ($result->numRows()) {
         while ($row = $ilDB->fetchAssoc($result)) {
             $internal_link = $row["internal_link"];
             include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
             $resolved_link = SurveyQuestion::_resolveInternalLink($internal_link);
             if (strcmp($internal_link, $resolved_link) != 0) {
                 // internal link was resolved successfully
                 $affectedRows = $ilDB->manipulateF("UPDATE svy_material SET internal_link = %s, tstamp = %s WHERE material_id = %s", array('text', 'integer', 'integer'), array($resolved_link, time(), $row["material_id"]));
                 $resolvedlinks++;
             }
         }
     }
     if ($resolvedlinks) {
         // there are resolved links -> reenter theses links to the database
         // delete all internal links from the database
         include_once "./Services/Link/classes/class.ilInternalLink.php";
         ilInternalLink::_deleteAllLinksOfSource("sqst", $question_id);
         $result = $ilDB->queryF("SELECT * FROM svy_material WHERE question_fi = %s", array('integer'), array($question_id));
         if ($result->numRows()) {
             while ($row = $ilDB->fetchAssoc($result)) {
                 if (preg_match("/il_(\\d*?)_(\\w+)_(\\d+)/", $row["internal_link"], $matches)) {
                     ilInternalLink::_saveLink("sqst", $question_id, $matches[2], $matches[3], $matches[1]);
                 }
             }
         }
     }
 }
Example #2
0
 /**
  * Delete internal links
  *
  * @param
  * @return
  */
 function deleteInternalLinks()
 {
     include_once "./Services/Link/classes/class.ilInternalLink.php";
     ilInternalLink::_deleteAllLinksOfSource($this->getParentType() . ":pg", $this->getId(), $this->getLanguage());
 }
 /**
  * save internal links of page
  *
  * @param	string		xml page code
  */
 function saveInternalLinks($a_xml)
 {
     global $ilDB;
     //echo "<br>PageObject::saveInternalLinks[".$this->getId()."]";
     $doc = domxml_open_mem($a_xml);
     include_once "./Services/COPage/classes/class.ilInternalLink.php";
     ilInternalLink::_deleteAllLinksOfSource($this->getParentType() . ":pg", $this->getId());
     // get all internal links
     $xpc = xpath_new_context($doc);
     $path = "//IntLink";
     $res =& xpath_eval($xpc, $path);
     for ($i = 0; $i < count($res->nodeset); $i++) {
         $link_type = $res->nodeset[$i]->get_attribute("Type");
         switch ($link_type) {
             case "StructureObject":
                 $t_type = "st";
                 break;
             case "PageObject":
                 $t_type = "pg";
                 break;
             case "GlossaryItem":
                 $t_type = "git";
                 break;
             case "MediaObject":
                 $t_type = "mob";
                 break;
             case "RepositoryItem":
                 $t_type = "obj";
                 break;
             case "File":
                 $t_type = "file";
                 break;
         }
         $target = $res->nodeset[$i]->get_attribute("Target");
         $target_arr = explode("_", $target);
         $t_id = $target_arr[count($target_arr) - 1];
         // link to other internal object
         if (is_int(strpos($target, "__"))) {
             $t_inst = 0;
         } else {
             $t_inst = $target_arr[1];
         }
         if ($t_id > 0) {
             ilInternalLink::_saveLink($this->getParentType() . ":pg", $this->getId(), $t_type, $t_id, $t_inst);
         }
     }
     // *** STEP 2: Save question references of page ***
     // delete all reference records
     $ilDB->manipulateF("DELETE FROM page_question WHERE page_parent_type = %s " . " AND page_id = %s", array("text", "integer"), array($this->getParentType(), $this->getId()));
     // save question references of page
     $doc = domxml_open_mem($a_xml);
     $xpc = xpath_new_context($doc);
     $path = "//Question";
     $res = xpath_eval($xpc, $path);
     $q_ids = array();
     for ($i = 0; $i < count($res->nodeset); $i++) {
         $q_ref = $res->nodeset[$i]->get_attribute("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, question_id)" . " VALUES (%s,%s,%s)", array("text", "integer", "integer"), array($this->getParentType(), $this->getId(), $qid));
     }
 }