Example #1
0
 /**
  * Paste item (tree) from clipboard to current lm
  */
 static function pasteTree($a_target_lm, $a_item_id, $a_parent_id, $a_target, $a_insert_time, &$a_copied_nodes, $a_as_copy = false, $a_source_lm = null)
 {
     global $ilUser, $ilias, $ilLog;
     include_once "./Modules/LearningModule/classes/class.ilStructureObject.php";
     include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
     $item_lm_id = ilLMObject::_lookupContObjID($a_item_id);
     $item_type = ilLMObject::_lookupType($a_item_id);
     $lm_obj = $ilias->obj_factory->getInstanceByObjId($item_lm_id);
     if ($item_type == "st") {
         $item = new ilStructureObject($lm_obj, $a_item_id);
     } else {
         if ($item_type == "pg") {
             $item = new ilLMPageObject($lm_obj, $a_item_id);
         }
     }
     $ilLog->write("Getting from clipboard type " . $item_type . ", " . "Item ID: " . $a_item_id . ", of original LM: " . $item_lm_id);
     if ($item_lm_id != $a_target_lm->getId() && !$a_as_copy) {
         // @todo: check whether st is NOT in tree
         // "move" metadata to new lm
         include_once "Services/MetaData/classes/class.ilMD.php";
         $md = new ilMD($item_lm_id, $item->getId(), $item->getType());
         $new_md = $md->cloneMD($a_target_lm->getId(), $item->getId(), $item->getType());
         // update lm object
         $item->setLMId($a_target_lm->getId());
         $item->setContentObject($a_target_lm);
         $item->update();
         // delete old meta data set
         $md->deleteAll();
         if ($item_type == "pg") {
             $page = $item->getPageObject();
             $page->buildDom();
             $page->setParentId($a_target_lm->getId());
             $page->update();
         }
     }
     if ($a_as_copy) {
         $target_item = $item->copy($a_target_lm);
         $a_copied_nodes[$item->getId()] = $target_item->getId();
     } else {
         $target_item = $item;
     }
     $ilLog->write("Putting into tree type " . $target_item->getType() . "Item ID: " . $target_item->getId() . ", Parent: " . $a_parent_id . ", " . "Target: " . $a_target . ", Item LM:" . $target_item->getContentObject()->getId());
     ilLMObject::putInTree($target_item, $a_parent_id, $a_target);
     if ($a_source_lm == null) {
         $childs = $ilUser->getClipboardChilds($item->getId(), $a_insert_time);
     } else {
         $childs = $a_source_lm->lm_tree->getChilds($item->getId());
         foreach ($childs as $k => $child) {
             $childs[$k]["id"] = $childs[$k]["child"];
         }
     }
     foreach ($childs as $child) {
         ilLMObject::pasteTree($a_target_lm, $child["id"], $target_item->getId(), IL_LAST_NODE, $a_insert_time, $a_copied_nodes, $a_as_copy, $a_source_lm);
     }
     return $target_item->getId();
     // @todo: write history (see pastePage)
 }
 /**
  * Paste item (tree) from clipboard or other learning module to target scorm learning module
  *
  * @param object $a_target_slm target scorm 2004 learning module object
  * @param int $a_item_id id of item that should be pasted
  * @param int $a_parent_id parent id in target tree,
  * @param int $a_target predecessor target node, no ID means: last child
  * @param string $a_insert_time cliboard insert time (not needed, if $a_from_cliboard is false)
  * @param array $a_copied_nodes array of IDs od copied nodes, key is ID of source node, value is ID of copied node
  * @param bool $a_as_copy if true, items are copied otherwise they are moved
  * @param bool $a_from_clipboard if true, child node information is read from clipboard, otherwise from source tree
  */
 static function pasteTree($a_target_slm, $a_item_id, $a_parent_id, $a_target, $a_insert_time, &$a_copied_nodes, $a_as_copy = false, $a_from_clipboard = true)
 {
     global $ilUser, $ilias, $ilLog;
     // source lm id, item type and lm object
     $item_slm_id = ilSCORM2004Node::_lookupSLMID($a_item_id);
     $item_type = ilSCORM2004Node::_lookupType($a_item_id);
     //$slm_obj = $ilias->obj_factory->getInstanceByObjId($item_slm_id);
     include_once "./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php";
     $slm_obj = new ilObjSCORM2004LearningModule($item_slm_id, false);
     if ($item_type == "chap") {
         include_once "./Modules/Scorm2004/classes/class.ilSCORM2004Chapter.php";
         $item = new ilSCORM2004Chapter($slm_obj, $a_item_id);
     } else {
         if ($item_type == "page") {
             include_once "./Modules/Scorm2004/classes/class.ilSCORM2004PageNode.php";
             $item = new ilSCORM2004PageNode($slm_obj, $a_item_id);
         } else {
             if ($item_type == "sco") {
                 include_once "./Modules/Scorm2004/classes/class.ilSCORM2004Sco.php";
                 $item = new ilSCORM2004Sco($slm_obj, $a_item_id);
             } else {
                 if ($item_type == "ass") {
                     include_once "./Modules/Scorm2004/classes/class.ilSCORM2004Asset.php";
                     $item = new ilSCORM2004Asset($slm_obj, $a_item_id);
                 }
             }
         }
     }
     $ilLog->write("Getting from clipboard type " . $item_type . ", " . "Item ID: " . $a_item_id . ", of original SLM: " . $item_slm_id);
     if ($item_slm_id != $a_target_slm->getId() && !$a_as_copy) {
         // @todo: check whether st is NOT in tree
         // "move" metadata to new lm
         include_once "Services/MetaData/classes/class.ilMD.php";
         $md = new ilMD($item_slm_id, $item->getId(), $item->getType());
         $new_md = $md->cloneMD($a_target_slm->getId(), $item->getId(), $item->getType());
         // update lm object
         $item->setSLMId($a_target_slm->getId());
         $item->setSLMObject($a_target_slm);
         $item->update();
         // delete old meta data set
         $md->deleteAll();
         if ($item_type == "page") {
             $page = $item->getPageObject();
             $page->buildDom($a_from_clipboard);
             $page->setParentId($a_target_slm->getId());
             $page->update();
         }
     }
     if ($a_as_copy) {
         $target_item = $item->copy($a_target_slm);
         $a_copied_nodes[$item->getId()] = $target_item->getId();
     } else {
         $target_item = $item;
     }
     $ilLog->write("Putting into tree type " . $target_item->getType() . "Item ID: " . $target_item->getId() . ", Parent: " . $a_parent_id . ", " . "Target: " . $a_target . ", Item LM:" . $target_item->getContentObject()->getId());
     ilSCORM2004Node::putInTree($target_item, $a_parent_id, $a_target);
     if ($a_from_clipboard) {
         $childs = $ilUser->getClipboardChilds($item->getId(), $a_insert_time);
     } else {
         // get childs of source tree
         $source_tree = $slm_obj->getTree();
         $childs = $source_tree->getChilds($a_item_id);
     }
     foreach ($childs as $child) {
         $child_id = $a_from_clipboard ? $child["id"] : $child["child"];
         ilSCORM2004Node::pasteTree($a_target_slm, $child_id, $target_item->getId(), IL_LAST_NODE, $a_insert_time, $a_copied_nodes, $a_as_copy);
     }
     return $target_item->getId();
 }
 /**
  * delete meta data entry
  */
 function deleteMetaData()
 {
     // Delete meta data
     include_once 'Services/MetaData/classes/class.ilMD.php';
     $glo_id = ilGlossaryTerm::_lookGlossaryID($this->getTermId());
     $md = new ilMD($glo_id, $this->getId(), $this->getType());
     $md->deleteAll();
 }
 /**
  * delete meta data entry
  */
 function deleteMetaData()
 {
     // Delete meta data
     include_once 'Services/MetaData/classes/class.ilMD.php';
     $md = new ilMD(0, $this->getId(), $this->getType());
     $md->deleteAll();
 }
 /**
  * handler for begin of element
  *
  * @param	resource	$a_xml_parser		xml parser
  * @param	string		$a_name				element name
  * @param	array		$a_attribs			element attributes array
  */
 public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
 {
     global $ilErr;
     if ($this->in_metadata) {
         parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
         return;
     }
     switch ($a_name) {
         case "MetaData":
             $this->in_metadata = true;
             // Delete old meta data
             $md = new ilMD($this->getWebLink()->getId(), 0, 'webr');
             $md->deleteAll();
             parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
             break;
         case 'WebLink':
             $this->current_link_update = false;
             $this->current_link_delete = false;
             $this->current_parameters = array();
             if ($this->getMode() == self::MODE_CREATE or isset($a_attribs['action']) and $a_attribs['action'] == 'Create') {
                 // New weblink
                 $this->current_link = new ilLinkResourceItems($this->getWebLink()->getId());
             } elseif ($this->getMode() == self::MODE_UPDATE and $a_attribs['action'] == 'Delete') {
                 $this->current_link_delete = true;
                 $this->current_link = new ilLinkResourceItems($this->getWebLink()->getId());
                 $this->current_link->delete($a_attribs['id']);
                 break;
             } elseif ($this->getMode() == self::MODE_UPDATE and ($a_attribs['action'] == 'Update' or !isset($a_attribs['action']))) {
                 $this->current_link = new ilLinkResourceItems($this->getWebLink()->getId());
                 $this->current_link->readItem($a_attribs['id']);
                 $this->current_link_update = true;
                 // Delete all dynamic parameter
                 include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
                 foreach (ilParameterAppender::getParameterIds($this->getWebLink()->getId(), $a_attribs['id']) as $param_id) {
                     $param = new ilParameterAppender($this->getWebLink()->getId());
                     $param->delete($param_id);
                 }
             } else {
                 throw new ilWebLinkXmlParserException('Invalid action given for element "Weblink"');
             }
             // Active
             $this->current_link->setActiveStatus($a_attribs['active'] ? 1 : 0);
             // Valid
             if (!isset($a_attribs['valid'])) {
                 $valid = 1;
             } else {
                 $valid = $a_attribs['valid'] ? 1 : 0;
             }
             $this->current_link->setValidStatus($valid);
             // Disable check
             $this->current_link->setDisableCheckStatus($a_attribs['disableValidation'] ? 1 : 0);
             break;
         case 'Sorting':
             include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
             $sort = new ilContainerSortingSettings($this->getWebLink()->getId());
             $sort->delete();
             switch ($a_attribs['type']) {
                 case 'Manual':
                     $sort->setSortMode(ilContainer::SORT_MANUAL);
                     break;
                 case 'Title':
                 default:
                     $sort->setSortMode(ilContainer::SORT_TITLE);
             }
             $sort->save();
             break;
         case 'WebLinks':
         case 'Title':
         case 'Description':
         case 'Target':
             // Nothing to do
             break;
         case 'DynamicParameter':
             $param = new ilParameterAppender($this->getWebLink()->getId());
             $param->setName($a_attribs['name']);
             switch ($a_attribs['type']) {
                 case 'userName':
                     #						$GLOBALS['ilLog']->write("VALUE: ".LINKS_LOGIN);
                     $param->setValue(LINKS_LOGIN);
                     break;
                 case 'userId':
                     #						$GLOBALS['ilLog']->write("VALUE: ".LINKS_USER_ID);
                     $param->setValue(LINKS_USER_ID);
                     break;
                 case 'matriculation':
                     #						$GLOBALS['ilLog']->write("VALUE: ".LINKS_MATRICULATION);
                     $param->setValue(LINKS_MATRICULATION);
                     break;
                 default:
                     throw new ilWebLinkXmlParserException('Invalid attribute "type" given for element "Dynamic parameter". Aborting');
                     break;
             }
             $this->current_parameters[] = $param;
             break;
     }
 }
 function updateCourse($sid, $course_id, $xml)
 {
     $this->initAuth($sid);
     $this->initIlias();
     if (!$this->__checkSession($sid)) {
         return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
     }
     if (!is_numeric($course_id)) {
         return $this->__raiseError('No valid course id given. Please choose an existing reference id of an ILIAS course', 'Client');
     }
     global $rbacsystem;
     if (($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs') {
         $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
         if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs') {
             return $this->__raiseError('Invalid course id. Object with id "' . $course_id . '" is not of type "course"', 'Client');
         }
     }
     if (!($tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false))) {
         return $this->__raiseError('Cannot create course instance!', 'Server');
     }
     if (!$rbacsystem->checkAccess('write', $course_id)) {
         return $this->__raiseError('Check access failed. No permission to write course', 'Server');
     }
     // First delete old meta data
     include_once 'Services/MetaData/classes/class.ilMD.php';
     $md = new ilMD($tmp_course->getId(), 0, 'crs');
     $md->deleteAll();
     include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
     ilCourseParticipants::_deleteAllEntries($tmp_course->getId());
     include_once 'Modules/Course/classes/class.ilCourseWaitingList.php';
     ilCourseWaitingList::_deleteAll($tmp_course->getId());
     include_once 'Modules/Course/classes/class.ilCourseXMLParser.php';
     $xml_parser = new ilCourseXMLParser($tmp_course);
     $xml_parser->setXMLContent($xml);
     $xml_parser->startParsing();
     $tmp_course->MDUpdateListener('General');
     return true;
 }