ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjectDefinition.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
15 {
22  var $obj_id;
23 
29  var $parent;
30 
36  var $obj_data;
37 
38  const MODE_REPOSITORY = 1;
39  const MODE_WORKSPACE = 2;
40 
47  function ilObjectDefinition()
48  {
49  global $ilias;
50 
51  $this->readDefinitionData();
52  $this->ilias = $ilias;
53 
54 
56 
57  // removing this line leads to segmentation faults in
58  // learning module editor with
59  // - PHP 5.2.1, libxml 2.6.22, libxslt 1.1.15 (MacOsX)
60  // - PHP 5.2.1, libxml 2.6.31, libxslt 1.1.22 (MacOsX)
61  // - PHP 5.2.5, libxml 2.6.31, libxslt 1.1.22 (MacOsX)
62  // - PHP 5.2.0-8+etch7, libxml 2.6.27, libxslt 1.1.19
63  // - PHP 5.2.0, libxml, libxml 2.6.26, libxslt 1.1.17 (OpenSuse 10.2)
64  // (needs further investigation)
65  // OK with:
66  // - PHP 5.1.2, libxml 2.6.24, libxslt 1.1.15
67 
68  //
69  // Replacing all "=&" with "=" in xml5compliance seems to solve the problem
70  //
71 
72 // $this->startParsing();
73  }
74 
75 
79  function readDefinitionData()
80  {
81  global $ilDB, $ilPluginAdmin;
82 
83  $this->obj_data = array();
84 
85 
86  // Select all object_definitions and collect the definition id's in
87  // this array.
88  $defIds = array();
89  $set = $ilDB->query("SELECT * FROM il_object_def");
90  while ($rec = $ilDB->fetchAssoc($set))
91  {
92  $this->obj_data[$rec["id"]] = array(
93  "name" => $rec["id"],
94  "class_name" => $rec["class_name"],
95  "location" => $rec["location"],
96  "checkbox" => $rec["checkbox"],
97  "inherit" => $rec["inherit"],
98  "component" => $rec["component"],
99  "translate" => $rec["translate"],
100  "devmode" => $rec["devmode"],
101  "allow_link" => $rec["allow_link"],
102  "allow_copy" => $rec["allow_copy"],
103  "rbac" => $rec["rbac"],
104  "group" => $rec["grp"],
105  "system" => $rec["system"],
106  "default_pos" => $rec["default_pos"],
107  "sideblock" => $rec["sideblock"],
108  'export' => $rec['export'],
109  'repository' => $rec['repository'],
110  'workspace' => $rec['workspace'],
111  'administration' => $rec['administration']
112  );
113  $this->obj_data[$rec["id"]]["subobjects"] = array();
114 
115  $defIds[] = $rec["id"];
116  }
117 
118  // get all subobject definitions in a single query
119  $set2 = $ilDB->query("SELECT * FROM il_object_subobj WHERE ".
120  $ilDB->in('parent', $defIds, false, 'text'));
121  while ($rec2 = $ilDB->fetchAssoc($set2))
122  {
123  $max = $rec2["mmax"];
124  if ($max <= 0) // for backward compliance
125  {
126  $max = "";
127  }
128  $this->obj_data[$rec2["parent"]]["subobjects"][$rec2["subobj"]] = array(
129  "name" => $rec2["subobj"],
130  "max" => $max,
131  "lng" => $rec2["subobj"]
132  );
133  }
134 
135  $set = $ilDB->query("SELECT * FROM il_object_group");
136  $this->obj_group = array();
137  while ($rec = $ilDB->fetchAssoc($set))
138  {
139  $this->obj_group[$rec["id"]] = $rec;
140  }
141 
142  // now get objects from repository plugin
143  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "Repository", "robj");
144  foreach ($pl_names as $pl_name)
145  {
146  include_once("./Services/Component/classes/class.ilPlugin.php");
147  $pl_id = ilPlugin::lookupIdForName(IL_COMP_SERVICE, "Repository", "robj", $pl_name);
148  if ($pl_id != "" && !isset($this->obj_data[$pl_id]))
149  {
150  include_once("./Services/Repository/classes/class.ilRepositoryObjectPlugin.php");
151  $loc = ilPlugin::_getDirectory(IL_COMP_SERVICE, "Repository", "robj",
152  $pl_name)."/classes";
153 
154  $this->obj_data[$pl_id] = array(
155  "name" => $pl_id,
156  "class_name" => $pl_name,
157  "plugin" => "1",
158  "location" => $loc,
159  "checkbox" => "1",
160  "inherit" => "0",
161  "component" => "",
162  "translate" => "0",
163  "devmode" => "0",
164  "allow_link" => "1",
165  "allow_copy" => "0",
166  "rbac" => "1",
167  "group" => null,
168  "system" => "0",
169  "default_pos" => "2000",
170  'repository' => '1',
171  'workspace' => '0',
172  'administration' => '0',
173  "sideblock" => "0");
174  $this->obj_data[$rec["id"]]["subobjects"] = array();
175 
176  // plugins have to be marked as such - see ilContainerGUI::showPossibleSubObjects()
177  $this->obj_data["crs"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id, "plugin" => true);
178  $this->obj_data["fold"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id, "plugin" => true);
179  $this->obj_data["grp"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id, "plugin" => true);
180  $this->obj_data["cat"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id, "plugin" => true);
181  $this->obj_data["root"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id, "plugin" => true);
182  }
183  }
184 //var_dump($this->obj_data["root"]["subobjects"]);
185 //var_dump($this->obj_data2["root"]);
186 
187  }
188 
189 
190 // PUBLIC METHODS
191 
198  function getClassName($a_obj_name)
199  {
200  return $this->obj_data[$a_obj_name]["class_name"];
201  }
202 
203 
210  function getLocation($a_obj_name)
211  {
212  return $this->obj_data[$a_obj_name]["location"];
213  }
214 
218  function getGroup($a_id)
219  {
220  return $this->obj_group[$a_id];
221  }
222 
226  function getGroupOfObj($a_obj_name)
227  {
228  return $this->obj_data[$a_obj_name]["group"];
229  }
230 
237  function hasCheckbox($a_obj_name)
238  {
239  return (bool) $this->obj_data[$a_obj_name]["checkbox"];
240  }
241 
248  function getTranslationType($a_obj_name)
249  {
250  global $ilDB;
251 
252  if ($a_obj_name == "root")
253  {
254  if (!isset($this->root_trans_type))
255  {
256  $q = "SELECT count(obj_id) cnt FROM object_translation WHERE obj_id = ".
257  $ilDB->quote(ROOT_FOLDER_ID,'integer')." ";
258  $set = $ilDB->query($q);
259  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
260  if($rec["cnt"] > 0)
261  {
262  $this->root_trans_type = "db";
263  }
264  else
265  {
266  $this->root_trans_type = $this->obj_data[$a_obj_name]["translate"];
267  }
268  }
269  return $this->root_trans_type;
270  }
271 
272  if (isset($this->obj_data[$a_obj_name]))
273  {
274  return $this->obj_data[$a_obj_name]["translate"];
275  }
276 
277  return "";
278  }
279 
280 
287  function stopInheritance($a_obj_name)
288  {
289  return (bool) $this->obj_data[$a_obj_name]["inherit"];
290  }
291 
298  function getDevMode($a_obj_name)
299  {
300  return (bool) $this->obj_data[$a_obj_name]["devmode"];
301  }
302 
309  function getDevModeAll()
310  {
311  $types = array_keys($this->obj_data);
312 
313  foreach ($types as $type)
314  {
315  if ($this->getDevMode($type))
316  {
317  $devtypes[] = $type;
318  }
319  }
320 
321  return $devtypes ? $devtypes : array();
322  }
323 
331  function isRBACObject($a_obj_name)
332  {
333  return (bool) $this->obj_data[$a_obj_name]["rbac"];
334  }
335 
343  function isPlugin($a_obj_name)
344  {
345  return (bool) isset($this->obj_data[$a_obj_name]["plugin"]);
346  }
347 
354  function isPluginTypeName($a_str)
355  {
356  return (substr($a_str, 0, 1) == "x");
357  }
358 
365  function getAllRBACObjects()
366  {
367  $types = array_keys($this->obj_data);
368 
369  foreach ($types as $type)
370  {
371  if ($this->isRBACObject($type))
372  {
373  $rbactypes[] = $type;
374  }
375  }
376 
377  return $rbactypes ? $rbactypes : array();
378  }
379 
386  function getAllObjects()
387  {
388  return array_keys($this->obj_data);
389  }
390 
397  public function allowLink($a_obj_name)
398  {
399  return (bool) $this->obj_data[$a_obj_name]["allow_link"];
400  }
401 
408  public function allowCopy($a_obj_name)
409  {
410  return (bool) $this->obj_data[$a_obj_name]["allow_copy"];
411  }
412 
413  public function allowExport($a_obj_name)
414  {
415  return (bool) $this->obj_data[$a_obj_name]['export'];
416  }
417 
423  public function hasLocalRoles($a_obj_type)
424  {
425  return isset($this->obj_data[$a_obj_type]['subobjects']['rolf']);
426  }
427 
436  function getSubObjects($a_obj_type,$a_filter = true)
437  {
438  global $ilSetting;
439 
440  $subs = array();
441 
442  if ($subobjects = $this->obj_data[$a_obj_type]["subobjects"])
443  {
444  // Filter some objects e.g chat object are creatable if chat is active
445  if ($a_filter)
446  {
447  $this->__filterObjects($subobjects);
448  }
449  foreach ($subobjects as $data => $sub)
450  {
451  if ($sub["module"] != "n")
452  {
453  if (!($ilSetting->get("obj_dis_creation_".$data)))
454  {
455  $subs[$data] = $sub;
456 
457  // determine position
458  $pos = ($ilSetting->get("obj_add_new_pos_".$data) > 0)
459  ? (int) $ilSetting->get("obj_add_new_pos_".$data)
460  : (int) $this->obj_data[$data]["default_pos"];
461  $subs[$data]["pos"] = $pos;
462  }
463  }
464  }
465 
466  $subs2 = ilUtil::sortArray($subs, "pos", ASC, true, true);
467 
468  return $subs2;
469  }
470 
471  return $subs;
472  }
473 
487  function getSubObjectsRecursively($a_obj_type,$a_include_source_obj = true, $a_add_admin_objects = false)
488  {
489  global $ilSetting;
490 
491  // This associative array is used to collect all subobject types.
492  // key=>type, value=data
493  $recursivesubs = array();
494 
495  // This array is used to keep track of the object types, we
496  // need to call function getSubobjects() for.
497  $to_do = array($a_obj_type);
498 
499  // This array is used to keep track of the object types, we
500  // have called function getSubobjects() already. This is to
501  // prevent endless loops, for object types that support
502  // themselves as subobject types either directly or indirectly.
503  $done = array();
504 
505  while (count($to_do) > 0)
506  {
507  $type = array_pop($to_do);
508  $done[] = $type;
509 
510  // no recovery folder subitems
511  if($type == 'recf')
512  {
513  continue;
514  }
515 
516  // Hide administration if desired
517  if(!$a_add_admin_objects and $type == 'adm')
518  {
519  $subs = array();
520  }
521  else
522  {
523  $subs = $this->getSubObjects($type);
524  }
525  #vd('xxxxxxxxxxxxx'.$type);
526  foreach ($subs as $subtype => $data)
527  {
528  #vd('------------------------->'.$subtype);
529 
530  // Hide role templates and folder from view
531  if($this->getDevMode($subtype) or !$this->isRBACObject($subtype))
532  {
533  continue;
534  }
535  if($subtype == 'rolf' or $subtype == 'rolt')
536  {
537  continue;
538  }
539  if(!$a_add_admin_objects and $subtype == 'adm')
540  {
541  continue;
542  }
543 
544  $recursivesubs[$subtype] = $data;
545  if (! in_array($subtype, $done)
546  && ! in_array($subtype, $to_do))
547  {
548  $to_do[] = $subtype;
549  }
550  }
551  }
552 
553  if($a_include_source_obj)
554  {
555  if(!isset($recursivesubs[$a_obj_type]))
556  {
557  $recursivesubs[$a_obj_type]['name'] = $a_obj_type;
558  $recursivesubs[$a_obj_type]['lng'] = $a_obj_type;
559  $recursivesubs[$a_obj_type]['max'] = 0;
560  $recursivesubs[$a_obj_type]['pos'] = -1;
561  }
562  }
563  return ilUtil::sortArray($recursivesubs, "pos", ASC, true, true);
564  }
565 
566 
576  function getSubobjectsToFilter($a_obj_type = "adm")
577  {
578  foreach($this->obj_data[$a_obj_type]["subobjects"] as $key => $value)
579  {
580  switch($key)
581  {
582  case "rolf":
583  // DO NOTHING
584  break;
585 
586  default:
587  $tmp_subs[] = $key;
588  }
589  }
590  // ADD adm and root object
591  $tmp_subs[] = "adm";
592  #$tmp_subs[] = "root";
593 
594  return $tmp_subs ? $tmp_subs : array();
595  }
596 
605  function getCreatableSubObjects($a_obj_type, $a_context = self::MODE_REPOSITORY)
606  {
607  $subobjects = $this->getSubObjects($a_obj_type);
608 
609  // remove role folder object from list
610  unset($subobjects["rolf"]);
611 
612  $sub_types = array_keys($subobjects);
613 
614  // remove object types in development from list
615  foreach ($sub_types as $type)
616  {
617  if ($this->getDevMode($type) || $this->isSystemObject($type))
618  {
619  unset($subobjects[$type]);
620  }
621  if ($a_context == self::MODE_REPOSITORY && !$this->isAllowedInRepository($type))
622  {
623  unset($subobjects[$type]);
624  }
625  if ($a_context == self::MODE_WORKSPACE && !$this->isAllowedInWorkspace($type))
626  {
627  unset($subobjects[$type]);
628  }
629  }
630 
631  return $subobjects;
632  }
633 
640  function getSubObjectsAsString($a_obj_type)
641  {
642  $string = "";
643 
644  if (is_array($this->obj_data[$a_obj_type]["subobjects"]))
645  {
646  $data = array_keys($this->obj_data[$a_obj_type]["subobjects"]);
647 
648  $string = "'".implode("','", $data)."'";
649  }
650 
651  return $string;
652  }
653 
662  public function isContainer($a_obj_name)
663  {
664  if(!is_array($this->obj_data[$a_obj_name]['subobjects']))
665  {
666  return false;
667  }
668  return count($this->obj_data[$a_obj_name]['subobjects']) > 1 ? true : false;
669  }
670 
671 // PRIVATE METHODS
672 
679  function setHandlers($a_xml_parser)
680  {
681  xml_set_object($a_xml_parser,$this);
682  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
683  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
684  }
685 
694  function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
695  {
696  switch ($a_name)
697  {
698  case 'object':
699  $this->parent_tag_name = $a_attribs["name"];
700  break;
701  case 'property':
702  $this->current_tag = "property";
703  $this->current_tag_name = $a_attribs["name"];
704 // $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["name"] = $a_attribs["name"];
705  $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["module"] = $a_attribs["module"];
706 //echo '<br>$this->obj_data["'.$this->parent_tag_name.'"]["properties"]["'.$this->current_tag_name.'"]["module"] = "'.$a_attribs["module"].'";';
707  break;
708  }
709  }
710 
718  function handlerCharacterData($a_xml_parser,$a_data)
719  {
720  }
721 
729  function handlerEndTag($a_xml_parser,$a_name)
730  {
731  $this->current_tag = '';
732  $this->current_tag_name = '';
733  }
734 
735 
736  function __filterObjects(&$subobjects)
737  {
738  foreach($subobjects as $type => $data)
739  {
740  switch($type)
741  {
742  case "chat":
743  if(!$this->ilias->getSetting("chat_active"))
744  {
745  unset($subobjects[$type]);
746  }
747  break;
748 
749  case "icrs":
750  if(!$this->ilias->getSetting("ilinc_active"))
751  {
752  unset($subobjects[$type]);
753  }
754  break;
755 
756  default:
757  // DO NOTHING
758  }
759  }
760  }
761 
775  function isSystemObject($a_obj_name)
776  {
777  return (bool) $this->obj_data[$a_obj_name]["system"];
778  }
779 
786  function isSideBlock($a_obj_name)
787  {
788  return (bool) $this->obj_data[$a_obj_name]["sideblock"];
789  }
790 
794  static function getRepositoryObjectTypesForComponent($a_component_type,
795  $a_component_name)
796  {
797  global $ilDB;
798 
799  $set = $ilDB->queryF("SELECT * FROM il_object_def WHERE component = %s",
800  array("text"), array($a_component_type."/".$a_component_name));
801 
802  $types = array();
803  while($rec = $ilDB->fetchAssoc($set))
804  {
805  if ($rec["system"] != 1)
806  {
807  $types[] = $rec;
808  }
809  }
810 
811  return $types;
812  }
813 
817  static function getComponentForType($a_obj_type)
818  {
819  global $ilDB;
820 
821  $set = $ilDB->queryF("SELECT component FROM il_object_def WHERE id = %s",
822  array("text"), array($a_obj_type));
823 
824  if ($rec = $ilDB->fetchAssoc($set))
825  {
826  return $rec["component"];
827  }
828 
829  return "";
830  }
831 
835  static function getGroupedRepositoryObjectTypes($a_parent_obj_type)
836  {
837  global $ilDB, $ilPluginAdmin;
838 
839  $set = $ilDB->query("SELECT * FROM il_object_group");
840  $groups = array();
841  while ($gr_rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
842  {
843  $groups[$gr_rec["id"]] = $gr_rec;
844  }
845 
846  if (!is_array($a_parent_obj_type))
847  {
848  $set = $ilDB->queryF("SELECT il_object_def.* FROM il_object_def, il_object_subobj ".
849  " WHERE NOT (system = 1) AND NOT (sideblock = 1) AND ".
850  " parent = %s ".
851  " AND subobj = id ", array("text"), array($a_parent_obj_type));
852  }
853  else
854  {
855  $q = "SELECT DISTINCT (id) as sid, il_object_def.* FROM il_object_def, il_object_subobj ".
856  " WHERE NOT (system = 1) AND NOT (sideblock = 1) AND ".
857  $ilDB->in("parent", $a_parent_obj_type, false, "text").
858  " AND subobj = id ";
859  $set = $ilDB->query($q);
860  }
861 
862  $grouped_obj = array();
863  while($rec = $ilDB->fetchAssoc($set))
864  {
865  if ($rec["grp"] != "")
866  {
867  $grouped_obj[$rec["grp"]]["pos"] = (int) $groups[$rec["grp"]]["default_pres_pos"];
868  $grouped_obj[$rec["grp"]]["objs"][] = $rec["id"];
869  }
870  else
871  {
872  $grouped_obj[$rec["id"]]["pos"] = (int) $rec["default_pres_pos"];
873  $grouped_obj[$rec["id"]]["objs"][] = $rec["id"];
874  }
875  }
876 //var_dump($grouped_obj);
877  // now get objects from repository plugin
878  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "Repository", "robj");
879  foreach ($pl_names as $pl_name)
880  {
881  include_once("./Services/Component/classes/class.ilPlugin.php");
882  $pl_id = ilPlugin::lookupIdForName(IL_COMP_SERVICE, "Repository", "robj", $pl_name);
883  if (!isset($grouped_obj[$pl_id]))
884  {
885  $grouped_obj[$pl_id] = array(
886  "pos" => 2000,
887  "objs" => array(0 => $pl_id)
888  );
889  }
890  }
891 
892 //var_dump($grouped_obj);
893 
894  $ret = ilUtil::sortArray($grouped_obj, "pos", "asc", true, true);
895 //var_dump($ret);
896  return $ret;
897  }
898 
906  function isAllowedInRepository($a_obj_name)
907  {
908  return (bool) $this->obj_data[$a_obj_name]["repository"];
909  }
910 
918  function isAllowedInWorkspace($a_obj_name)
919  {
920  return (bool) $this->obj_data[$a_obj_name]["workspace"];
921  }
922 
928  public function isAdministrationObject($a_obj_name)
929  {
930  return (bool) $this->obj_data[$a_obj_name]['administration'];
931  }
932 
939  public function isInactivePlugin($a_type)
940  {
941  if (substr($a_type, 0, 1) == "x" && !$this->isPlugin($a_type))
942  {
943  return true;
944  }
945  return false;
946  }
947 }
948 ?>