/**
  * Insert resources
  *
  * @param
  * @return
  */
 static function insertResourcesIntoPageContent($a_content)
 {
     global $objDefinition, $tree, $lng;
     $ref_id = (int) $_GET["ref_id"];
     $obj_id = (int) ilObject::_lookupObjId($ref_id);
     $obj_type = ilObject::_lookupType($obj_id);
     // determine type -> group
     $type_to_grp = array();
     $type_grps = $objDefinition->getGroupedRepositoryObjectTypes($obj_type);
     foreach ($type_grps as $grp => $def) {
         foreach ($def["objs"] as $t) {
             $type_to_grp[$t] = $grp;
         }
     }
     $childs = $tree->getChilds($ref_id);
     $childs_by_type = array();
     $item_groups = array();
     foreach ($childs as $child) {
         $childs_by_type[$type_to_grp[$child["type"]]][] = $child;
         if ($child["type"] == "itgr") {
             $item_groups[(int) $child["ref_id"]] = $child["title"];
         }
     }
     // handle "by type" lists
     foreach ($type_grps as $type => $v) {
         if (is_int(strpos($a_content, "[list-" . $type . "]"))) {
             // render block
             $tpl = new ilTemplate("tpl.resource_block.html", true, true, "Services/COPage");
             $cnt = 0;
             if (is_array($childs_by_type[$type]) && count($childs_by_type[$type]) > 0) {
                 foreach ($childs_by_type[$type] as $child) {
                     $tpl->setCurrentBlock("row");
                     $tpl->setVariable("IMG", ilUtil::img(ilObject::_getIcon($child["obj_id"], "small")));
                     $tpl->setVariable("TITLE", $child["title"]);
                     $tpl->parseCurrentBlock();
                     $cnt++;
                 }
                 $tpl->setVariable("HEADER", $lng->txt("objs_" . $type));
                 $a_content = str_replace("[list-" . $type . "]", $tpl->get(), $a_content);
             } else {
                 $tpl->setCurrentBlock("row");
                 $tpl->setVariable("TITLE", $lng->txt("no_items"));
                 $tpl->parseCurrentBlock();
                 $tpl->setVariable("HEADER", $lng->txt("objs_" . $type));
                 $a_content = str_replace("[list-" . $type . "]", $tpl->get(), $a_content);
             }
         }
     }
     // handle item groups
     while (eregi("\\[(item-group-([0-9]*))\\]", $a_content, $found)) {
         $itgr_ref_id = (int) $found[2];
         // check whether this item group is child -> insert editing html
         if (isset($item_groups[$itgr_ref_id])) {
             include_once "./Modules/ItemGroup/classes/class.ilItemGroupItems.php";
             $itgr_items = new ilItemGroupItems($itgr_ref_id);
             $items = $itgr_items->getValidItems();
             // render block
             $tpl = new ilTemplate("tpl.resource_block.html", true, true, "Services/COPage");
             foreach ($items as $it_ref_id) {
                 $it_obj_id = ilObject::_lookupObjId($it_ref_id);
                 $it_title = ilObject::_lookupTitle($it_obj_id);
                 $tpl->setCurrentBlock("row");
                 $tpl->setVariable("IMG", ilUtil::img(ilObject::_getIcon($it_obj_id, "small")));
                 $tpl->setVariable("TITLE", $it_title);
                 $tpl->parseCurrentBlock();
             }
             $tpl->setVariable("HEADER", $item_groups[$itgr_ref_id]);
             $html = $tpl->get();
         } else {
             $html = "<i>" . $lng->txt("cont_element_refers_removed_itgr") . "</i>";
         }
         $a_content = eregi_replace("\\[" . $found[1] . "\\]", $html, $a_content);
     }
     return $a_content;
 }
 /**
  * Clone dependencies
  *
  * @param
  * @return
  */
 function cloneDependencies($a_target_id, $a_copy_id)
 {
     global $ilLog;
     $ilLog->write(__METHOD__ . ': Cloning item group dependencies -' . $a_source_id . '-');
     parent::cloneDependencies($a_target_id, $a_copy_id);
     include_once './Modules/ItemGroup/classes/class.ilItemGroupItems.php';
     $ig_items = new ilItemGroupItems($a_target_id);
     $ig_items->cloneItems($this->getRefId(), $a_copy_id);
     return true;
 }
 /**
  * Custom callback after object is created (in parent containert
  * 
  * @param ilObject $a_obj 
  */
 public function afterSaveCallback(ilObject $a_obj)
 {
     // add new object to materials
     include_once './Modules/ItemGroup/classes/class.ilItemGroupItems.php';
     $items = new ilItemGroupItems($this->object->getRefId());
     $items->addItem($a_obj->getRefId());
     $items->update();
 }
 /**
  * Get materials of item group
  * 
  * @param int $a_item_group_id (object id)
  * @return array 
  */
 public static function getItemsByItemGroup($a_item_group_ref_id)
 {
     include_once 'Modules/ItemGroup/classes/class.ilItemGroupItems.php';
     $ig_items = new ilItemGroupItems($a_item_group_ref_id);
     $items = $ig_items->getValidItems();
     return self::processListItems($items);
 }
 /**
  * Import record
  *
  * @param
  * @return
  */
 function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
 {
     global $ilLog;
     //echo $a_entity;
     //var_dump($a_rec);
     switch ($a_entity) {
         case "itgr":
             include_once "./Modules/ItemGroup/classes/class.ilObjItemGroup.php";
             if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
                 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
             } else {
                 $newObj = new ilObjItemGroup();
                 $newObj->setType("itgr");
                 $newObj->create(true);
             }
             $newObj->setTitle($a_rec["Title"]);
             $newObj->setDescription($a_rec["Description"]);
             $newObj->update(true);
             $this->current_obj = $newObj;
             $a_mapping->addMapping("Modules/ItemGroup", "itgr", $a_rec["Id"], $newObj->getId());
             break;
         case "itgr_item":
             if ($obj_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['ItemId'])) {
                 $ref_id = current(ilObject::_getAllReferences($obj_id));
                 include_once './Modules/ItemGroup/classes/class.ilItemGroupItems.php';
                 $itgri = new ilItemGroupItems();
                 $itgri->setItemGroupId($this->current_obj->getId());
                 $itgri->read();
                 $itgri->addItem($ref_id);
                 //$ilLog->write("Adding item with ref id -".$ref_id."- to group with id -".$this->current_obj->getId()."-.");
                 $itgri->update();
             }
             break;
     }
 }
 /**
  * Clone items
  *
  * @access public
  *
  * @param int source event id
  * @param int copy id
  */
 public function cloneItems($a_source_id, $a_copy_id)
 {
     global $ilObjDataCache, $ilLog;
     $ilLog->write(__METHOD__ . ': Begin cloning item group materials ... -' . $a_source_id . '-');
     include_once 'Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
     $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
     $mappings = $cwo->getMappings();
     $new_items = array();
     // check: is this a ref id!?
     $source_ig = new ilItemGroupItems($a_source_id);
     foreach ($source_ig->getItems() as $item_ref_id) {
         if (isset($mappings[$item_ref_id]) and $mappings[$item_ref_id]) {
             $ilLog->write(__METHOD__ . ': Clone item group item nr. ' . $item_ref_id);
             $new_items[] = $mappings[$item_ref_id];
         } else {
             $ilLog->write(__METHOD__ . ': No mapping found for item group item nr. ' . $item_ref_id);
         }
     }
     $this->setItems($new_items);
     $this->update();
     $ilLog->write(__METHOD__ . ': Finished cloning item group items ...');
     return true;
 }
 function isVisible($a_ref_id, $a_type)
 {
     global $ilAccess, $tree, $ilSetting;
     if (!$ilAccess->checkAccess('visible', '', $a_ref_id)) {
         return false;
     }
     $is_course = false;
     $container_parent_id = $tree->checkForParentType($a_ref_id, 'grp');
     if (!$container_parent_id) {
         $is_course = true;
         $container_parent_id = $tree->checkForParentType($a_ref_id, 'crs');
     }
     if ($container_parent_id) {
         // do not display session materials for container course/group
         if ($ilSetting->get("repository_tree_pres") == "all_types" && $container_parent_id != $a_ref_id) {
             // get container event items only once
             if (!isset($this->session_materials[$container_parent_id])) {
                 include_once './Modules/Session/classes/class.ilEventItems.php';
                 $this->session_materials[$container_parent_id] = ilEventItems::_getItemsOfContainer($container_parent_id);
             }
             // get item group items only once
             if (!isset($this->item_group_items[$container_parent_id])) {
                 include_once './Modules/ItemGroup/classes/class.ilItemGroupItems.php';
                 $this->item_group_items[$container_parent_id] = ilItemGroupItems::_getItemsOfContainer($container_parent_id);
             }
             if (in_array($a_ref_id, $this->session_materials[$container_parent_id])) {
                 return false;
             }
             if (in_array($a_ref_id, $this->item_group_items[$container_parent_id])) {
                 return false;
             }
         }
     }
     return true;
 }
 /**
  * Clone dependencies
  *
  * @param
  * @return
  */
 function cloneDependencies($a_target_id, $a_copy_id)
 {
     parent::cloneDependencies($a_target_id, $a_copy_id);
     include_once './Modules/ItemGroup/classes/class.ilItemGroupItems.php';
     $ig_items = new ilItemGroupItems($a_target_id);
     $ig_items->cloneItems($this->getRefId(), $a_copy_id);
     return true;
 }