• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Modules/MediaPool/classes/class.ilObjMediaPool.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00025 require_once "classes/class.ilObject.php";
00026 require_once "Services/MetaData/classes/class.ilMDLanguageItem.php";
00027 require_once("classes/class.ilObjFolder.php");
00028 
00041 class ilObjMediaPool extends ilObject
00042 {
00043         var $tree;
00044 
00051         function ilObjMediaPool($a_id = 0,$a_call_by_reference = true)
00052         {
00053                 // this also calls read() method! (if $a_id is set)
00054                 $this->type = "mep";
00055                 $this->ilObject($a_id,$a_call_by_reference);
00056         }
00057 
00058         function read()
00059         {
00060                 parent::read();
00061 
00062                 $this->tree =& new ilTree($this->getId());
00063                 $this->tree->setTreeTablePK("mep_id");
00064                 $this->tree->setTableNames('mep_tree','object_data');
00065         }
00066 
00067 
00071         function create()
00072         {
00073                 parent::create();
00074 
00075                 // create media pool tree
00076                 $this->tree =& new ilTree($this->getId());
00077                 $this->tree->setTreeTablePK("mep_id");
00078                 $this->tree->setTableNames('mep_tree','object_data');
00079                 $this->tree->addTree($this->getId(), 1);
00080 
00081         }
00082 
00086         function &getTree()
00087         {
00088                 return $this->tree;
00089         }
00090 
00097         function update()
00098         {
00099                 if (!parent::update())
00100                 {
00101                         return false;
00102                 }
00103 
00104                 // put here object specific stuff
00105 
00106                 return true;
00107         }
00108 
00109 
00120         function delete()
00121         {
00122                 // always call parent delete function first!!
00123                 if (!parent::delete())
00124                 {
00125                         return false;
00126                 }
00127 
00128                 // get childs
00129                 $childs = $this->tree->getSubTree($this->tree->getNodeData($this->tree->readRootId()));
00130 
00131                 // delete tree
00132                 $this->tree->removeTree($this->tree->getTreeId());
00133 
00134                 // delete childs
00135                 foreach ($childs as $child)
00136                 {
00137                         switch ($child["type"])
00138                         {
00139                                 case "mob":
00140                                         include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
00141                                         $mob = new ilObjMediaObject($child["obj_id"]);
00142                                         $mob->delete();
00143                                         break;
00144 
00145                                 case "fold":
00146                                         include_once("classes/class.ilObjFolder.php");
00147                                         $fold = new ilObjFolder($child["obj_id"], false);
00148                                         $fold->delete();
00149                                         break;
00150                         }
00151                 }
00152 
00153 
00154 
00155                 return true;
00156         }
00157 
00167         function initDefaultRoles()
00168         {
00169                 global $rbacadmin;
00170 
00171                 // create a local role folder
00172                 //$rfoldObj = $this->createRoleFolder("Local roles","Role Folder of forum obj_no.".$this->getId());
00173 
00174                 // create moderator role and assign role to rolefolder...
00175                 //$roleObj = $rfoldObj->createRole("Moderator","Moderator of forum obj_no.".$this->getId());
00176                 //$roles[] = $roleObj->getId();
00177 
00178                 //unset($rfoldObj);
00179                 //unset($roleObj);
00180 
00181                 return $roles ? $roles : array();
00182         }
00183 
00197         function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
00198         {
00199                 global $tree;
00200 
00201                 switch ($a_event)
00202                 {
00203                         case "link":
00204 
00205                                 //var_dump("<pre>",$a_params,"</pre>");
00206                                 //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
00207                                 //exit;
00208                                 break;
00209 
00210                         case "cut":
00211 
00212                                 //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
00213                                 //exit;
00214                                 break;
00215 
00216                         case "copy":
00217 
00218                                 //var_dump("<pre>",$a_params,"</pre>");
00219                                 //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
00220                                 //exit;
00221                                 break;
00222 
00223                         case "paste":
00224 
00225                                 //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
00226                                 //exit;
00227                                 break;
00228 
00229                         case "new":
00230 
00231                                 //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
00232                                 //exit;
00233                                 break;
00234                 }
00235 
00236                 // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
00237                 if ($a_node_id==$_GET["ref_id"])
00238                 {
00239                         $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
00240                         $parent_type = $parent_obj->getType();
00241                         if($parent_type == $this->getType())
00242                         {
00243                                 $a_node_id = (int) $tree->getParentId($a_node_id);
00244                         }
00245                 }
00246 
00247                 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
00248         }
00249 
00250 
00254         function getChilds($obj_id = "", $a_type = "")
00255         {
00256                 $objs = array();
00257                 $mobs = array();
00258                 if ($obj_id == "")
00259                 {
00260                         $obj_id = $this->tree->getRootId();
00261                 }
00262 
00263                 if ($a_type != "mob")
00264                 {
00265                         $objs = $this->tree->getChildsByType($obj_id, "fold");
00266                 }
00267                 if ($a_type != "fold")
00268                 {               
00269                         $mobs = $this->tree->getChildsByType($obj_id, "mob");
00270                 }
00271                 foreach($mobs as $key => $mob)
00272                 {
00273                         $objs[] = $mob;
00274                 }
00275 
00276                 return $objs;
00277         }
00278 
00279         function getParentId($obj_id = "")
00280         {
00281                 if ($obj_id == "")
00282                 {
00283                         return false;
00284                 }
00285                 if ($obj_id == $this->tree->getRootId())
00286                 {
00287                         return false;
00288                 }
00289 
00290                 return $this->tree->getParentId($obj_id);
00291         }
00292         
00293         function insertInTree($a_obj_id, $a_parent = "")
00294         {
00295                 if (!$this->tree->isInTree($a_obj_id))
00296                 {
00297                         $parent = ($a_parent == "")
00298                                 ? $this->tree->getRootId()
00299                                 : $a_parent;
00300                         $this->tree->insertNode($a_obj_id, $parent);
00301                         return true;
00302                 }
00303                 else
00304                 {
00305                         return false;
00306                 }
00307         }
00308 
00309 
00310         function deleteChild($obj_id)
00311         {
00312                 $type = ilObject::_lookupType($obj_id);
00313                 $title = ilObject::_lookupTitle($obj_id);
00314 
00315 
00316                 $node_data = $this->tree->getNodeData($obj_id);
00317                 $subtree = $this->tree->getSubtree($node_data);
00318 
00319                 // delete tree
00320                 if($this->tree->isInTree($obj_id))
00321                 {
00322                         $this->tree->deleteTree($node_data);
00323                 }
00324 
00325                 // delete objects
00326                 foreach ($subtree as $node)
00327                 {
00328                         if ($node["type"] == "mob")
00329                         {
00330                                 $obj =& new ilObjMediaObject($node["child"]);
00331                                 $obj->delete();
00332                         }
00333 
00334                         if ($node["type"] == "fold")
00335                         {
00336                                 $obj =& new ilObjFolder($node["child"], false);
00337                                 $obj->delete();
00338                         }
00339                 }
00340         }
00341 }
00342 ?>

Generated on Fri Dec 13 2013 17:56:52 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1