/**
  * MOB/File fieldtypes objects are head dependencies
  * They must be exported and imported first, so the new DC has the new IDs of those objects available
  *
  * @param $a_entity
  * @param $a_target_release
  * @param $a_ids
  *
  * @return array
  */
 public function getXmlExportHeadDependencies($a_entity, $a_target_release, $a_ids)
 {
     foreach ($a_ids as $id) {
         $m_ids = ilObjMediaPool::getAllMobIds($id);
         foreach ($m_ids as $m) {
             $mob_ids[] = $m;
         }
     }
     $dependencies = array(ilDataCollectionDatatype::INPUTFORMAT_FILE => array('component' => 'Modules/File', 'entity' => 'file', 'ids' => array()), ilDataCollectionDatatype::INPUTFORMAT_MOB => array('component' => 'Services/MediaObjects', 'entity' => 'mob', 'ids' => array()));
     // Direct SQL query is faster than looping over objects
     $page_object_ids = array();
     foreach ($a_ids as $dcl_obj_id) {
         $sql = "SELECT stloc2.value AS ext_id, f.`datatype_id` FROM il_dcl_stloc2_value AS stloc2 " . "INNER JOIN il_dcl_record_field AS rf ON (rf.`id` = stloc2.`record_field_id`) " . "INNER JOIN il_dcl_field AS f ON (rf.`field_id` = f.`id`) " . "INNER JOIN il_dcl_table AS t ON (t.`id` = f.`table_id`) " . "WHERE t.`obj_id` = " . $this->db->quote($dcl_obj_id, 'integer') . " " . "AND f.datatype_id IN (" . implode(',', array_keys($dependencies)) . ") AND stloc2.`value` IS NOT NULL";
         $set = $this->db->query($sql);
         while ($rec = $this->db->fetchObject($set)) {
             $dependencies[$rec->datatype_id]['ids'][] = (int) $rec->ext_id;
         }
     }
     // Return external dependencies/IDs if there are any
     $return = array();
     if (count($dependencies[ilDataCollectionDatatype::INPUTFORMAT_FILE]['ids'])) {
         $return[] = $dependencies[ilDataCollectionDatatype::INPUTFORMAT_FILE];
     }
     if (count($dependencies[ilDataCollectionDatatype::INPUTFORMAT_MOB]['ids'])) {
         $return[] = $dependencies[ilDataCollectionDatatype::INPUTFORMAT_MOB];
     }
     return $return;
 }
 /**
  * Read pool data
  */
 function read()
 {
     global $ilDB;
     parent::read();
     $set = $ilDB->query("SELECT * FROM mep_data " . " WHERE id = " . $ilDB->quote($this->getId(), "integer"));
     if ($rec = $ilDB->fetchAssoc($set)) {
         $this->setDefaultWidth($rec["default_width"]);
         $this->setDefaultHeight($rec["default_height"]);
     }
     $this->tree = ilObjMediaPool::getPoolTree($this->getId());
 }
 /**
  * Constructor
  */
 function __construct($a_parent_obj, $a_parent_cmd, $a_media_pool, $a_folder_par = "obj_id", $a_mode = ilMediaPoolTableGUI::IL_MEP_EDIT, $a_all_objects = false, $a_parent_tpl = null)
 {
     global $ilCtrl, $lng, $ilAccess, $lng;
     if ($a_parent_tpl == null) {
         $a_parent_tpl = $GLOBALS["tpl"];
     }
     $this->parent_tpl = $a_parent_tpl;
     if ($a_all_objects) {
         $this->setId("mepall" . $a_parent_obj->object->getId());
     } else {
         if (is_object($a_parent_obj->object)) {
             $this->setId("mepfold" . $a_parent_obj->object->getId());
         }
     }
     parent::__construct($a_parent_obj, $a_parent_cmd);
     $this->setMode($a_mode);
     $this->all_objects = $a_all_objects;
     $lng->loadLanguageModule("mep");
     $this->media_pool = $a_media_pool;
     $this->tree = ilObjMediaPool::getPoolTree($this->media_pool->getId());
     $this->folder_par = $a_folder_par;
     if ($this->all_objects) {
         $this->setExternalSorting(true);
         $this->initFilter();
     }
     // folder determination
     if ($_GET[$this->folder_par] > 0) {
         $this->current_folder = $_GET[$this->folder_par];
     } else {
         if ($_SESSION["mep_pool_folder"] > 0 && $this->tree->isInTree($_SESSION["mep_pool_folder"])) {
             $this->current_folder = $_SESSION["mep_pool_folder"];
         } else {
             $this->current_folder = $this->tree->getRootId();
         }
     }
     $_SESSION["mep_pool_folder"] = $this->current_folder;
     $this->addColumn("", "", "1");
     // checkbox
     $this->addColumn($lng->txt("mep_thumbnail"), "", "1");
     $this->addColumn($lng->txt("mep_title_and_description"), "", "100%");
     $this->setEnableHeader(true);
     $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
     $this->setRowTemplate("tpl.mep_list_row.html", "Modules/MediaPool");
     $this->getItems();
     // title
     if ($this->current_folder != $this->tree->getRootId() && !$this->all_objects) {
         $node = $this->tree->getNodeData($this->current_folder);
         $this->setTitle($lng->txt("mep_choose_from_folder") . ": " . $node["title"], "icon_fold.svg", $node["title"]);
     } else {
         $this->setTitle($lng->txt("mep_choose_from_mep") . ": " . ilObject::_lookupTitle($this->media_pool->getId()), "icon_mep.svg", ilObject::_lookupTitle($this->media_pool->getId()));
     }
     // action commands
     if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) && $this->getMode() == ilMediaPoolTableGUI::IL_MEP_EDIT) {
         $this->addMultiCommand("copyToClipboard", $lng->txt("cont_copy_to_clipboard"));
         $this->addMultiCommand("confirmRemove", $lng->txt("remove"));
         if (!$this->all_objects) {
             /*				$this->addCommandButton("createFolderForm", $lng->txt("mep_create_folder"));
             				$this->addCommandButton("createMediaObject", $lng->txt("mep_create_mob"));
             				
             				$mset = new ilSetting("mobs");
             				if ($mset->get("mep_activate_pages"))
             				{
             					$this->addCommandButton("createMediaPoolPage", $lng->txt("mep_create_content_snippet"));
             				}*/
         }
     }
     if ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT_SINGLE) {
         // ... even more coupling with ilpcmediaobjectgui
         $this->addMultiCommand("selectObjectReference", $lng->txt("cont_select"));
     }
     if ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_EDIT && $ilAccess->checkAccess("write", "", $this->media_pool->getRefId())) {
         $this->setSelectAllCheckbox("id");
     }
 }
 /**
  * Import record
  *
  * @param
  * @return
  */
 function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
 {
     //echo $a_entity;
     //var_dump($a_rec);
     switch ($a_entity) {
         case "mep":
             include_once "./Modules/MediaPool/classes/class.ilObjMediaPool.php";
             if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
                 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
             } else {
                 $newObj = new ilObjMediaPool();
                 $newObj->setType("mep");
                 $newObj->create(true);
             }
             $newObj->setTitle($a_rec["Title"]);
             $newObj->setDescription($a_rec["Description"]);
             $newObj->setDefaultWidth($a_rec["DefaultWidth"]);
             $newObj->setDefaultHeight($a_rec["DefaultHeight"]);
             $newObj->update();
             $this->current_obj = $newObj;
             $a_mapping->addMapping("Modules/MediaPool", "mep", $a_rec["Id"], $newObj->getId());
             break;
         case "mep_tree":
             switch ($a_rec["Type"]) {
                 case "fold":
                     $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
                     $fold_id = $this->current_obj->createFolder($a_rec["Title"], $parent);
                     $a_mapping->addMapping("Modules/MediaPool", "mep_tree", $a_rec["Child"], $fold_id);
                     break;
                 case "mob":
                     $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
                     $mob_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob", $a_rec["ForeignId"]);
                     $item = new ilMediaPoolItem();
                     $item->setType("mob");
                     $item->setForeignId($mob_id);
                     $item->setTitle($a_rec["Title"]);
                     $item->create();
                     if ($item->getId() > 0) {
                         $this->current_obj->insertInTree($item->getId(), $parent);
                     }
                     break;
                 case "pg":
                     $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
                     $item = new ilMediaPoolItem();
                     $item->setType("pg");
                     $item->setTitle($a_rec["Title"]);
                     $item->create();
                     $a_mapping->addMapping("Services/COPage", "pg", "mep:" . $a_rec["Child"], "mep:" . $item->getId());
                     if ($item->getId() > 0) {
                         $this->current_obj->insertInTree($item->getId(), $parent);
                     }
                     break;
             }
     }
 }