ILIAS  Release_4_1_x_branch Revision 61804
 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 
44  function ilObjectDefinition()
45  {
46  global $ilias;
47 
48  $this->readDefinitionData();
49  $this->ilias = $ilias;
50 
52 
53  // removing this line leads to segmentation faults in
54  // learning module editor with
55  // - PHP 5.2.1, libxml 2.6.22, libxslt 1.1.15 (MacOsX)
56  // - PHP 5.2.1, libxml 2.6.31, libxslt 1.1.22 (MacOsX)
57  // - PHP 5.2.5, libxml 2.6.31, libxslt 1.1.22 (MacOsX)
58  // - PHP 5.2.0-8+etch7, libxml 2.6.27, libxslt 1.1.19
59  // - PHP 5.2.0, libxml, libxml 2.6.26, libxslt 1.1.17 (OpenSuse 10.2)
60  // (needs further investigation)
61  // OK with:
62  // - PHP 5.1.2, libxml 2.6.24, libxslt 1.1.15
63 
64  //
65  // Replacing all "=&" with "=" in xml5compliance seems to solve the problem
66  //
67 
68 // $this->startParsing();
69  }
70 
71 
75  function readDefinitionData()
76  {
77  global $ilDB, $ilPluginAdmin;
78 
79  $this->obj_data = array();
80 
81 
82  // Select all object_definitions and collect the definition id's in
83  // this array.
84  $defIds = array();
85  $set = $ilDB->query("SELECT * FROM il_object_def");
86  while ($rec = $ilDB->fetchAssoc($set))
87  {
88  $this->obj_data[$rec["id"]] = array(
89  "name" => $rec["id"],
90  "class_name" => $rec["class_name"],
91  "location" => $rec["location"],
92  "checkbox" => $rec["checkbox"],
93  "inherit" => $rec["inherit"],
94  "component" => $rec["component"],
95  "translate" => $rec["translate"],
96  "devmode" => $rec["devmode"],
97  "allow_link" => $rec["allow_link"],
98  "allow_copy" => $rec["allow_copy"],
99  "rbac" => $rec["rbac"],
100  "group" => $rec["grp"],
101  "system" => $rec["system"],
102  "default_pos" => $rec["default_pos"],
103  "sideblock" => $rec["sideblock"],
104  'export' => $rec['export']);
105  $this->obj_data[$rec["id"]]["subobjects"] = array();
106 
107  $defIds[] = $rec["id"];
108  }
109  // get all subobject definitions in a single query
110  $set2 = $ilDB->query("SELECT * FROM il_object_subobj WHERE ".
111  $ilDB->in('parent', $defIds, false, 'text'));
112  while ($rec2 = $ilDB->fetchAssoc($set2))
113  {
114  $max = $rec2["mmax"];
115  if ($max <= 0) // for backward compliance
116  {
117  $max = "";
118  }
119  $this->obj_data[$rec2["parent"]]["subobjects"][$rec2["subobj"]] = array(
120  "name" => $rec2["subobj"],
121  "max" => $max,
122  "lng" => $rec2["subobj"]
123  );
124  }
125 
126  $set = $ilDB->query("SELECT * FROM il_object_group");
127  $this->obj_group = array();
128  while ($rec = $ilDB->fetchAssoc($set))
129  {
130  $this->obj_group[$rec["id"]] = $rec;
131  }
132 
133  // now get objects from repository plugin
134  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "Repository", "robj");
135  foreach ($pl_names as $pl_name)
136  {
137  include_once("./Services/Component/classes/class.ilPlugin.php");
138  $pl_id = ilPlugin::lookupIdForName(IL_COMP_SERVICE, "Repository", "robj", $pl_name);
139  if ($pl_id != "" && !isset($this->obj_data[$pl_id]))
140  {
141  include_once("./Services/Repository/classes/class.ilRepositoryObjectPlugin.php");
142  $loc = ilPlugin::_getDirectory(IL_COMP_SERVICE, "Repository", "robj",
143  $pl_name)."/classes";
144 
145  $this->obj_data[$pl_id] = array(
146  "name" => $pl_id,
147  "class_name" => $pl_name,
148  "plugin" => "1",
149  "location" => $loc,
150  "checkbox" => "1",
151  "inherit" => "0",
152  "component" => "",
153  "translate" => "0",
154  "devmode" => "0",
155  "allow_link" => "1",
156  "allow_copy" => "0",
157  "rbac" => "1",
158  "group" => null,
159  "system" => "0",
160  "default_pos" => "2000",
161  "sideblock" => "0");
162  $this->obj_data[$rec["id"]]["subobjects"] = array();
163 
164  $this->obj_data["crs"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id);
165  $this->obj_data["fold"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id);
166  $this->obj_data["grp"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id);
167  $this->obj_data["cat"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id);
168  $this->obj_data["root"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id);
169  }
170  }
171 //var_dump($this->obj_data["root"]["subobjects"]);
172 //var_dump($this->obj_data2["root"]);
173 
174  }
175 
176 
177 // PUBLIC METHODS
178 
185  function getClassName($a_obj_name)
186  {
187  return $this->obj_data[$a_obj_name]["class_name"];
188  }
189 
190 
197  function getLocation($a_obj_name)
198  {
199  return $this->obj_data[$a_obj_name]["location"];
200  }
201 
205  function getGroup($a_id)
206  {
207  return $this->obj_group[$a_id];
208  }
209 
213  function getGroupOfObj($a_obj_name)
214  {
215  return $this->obj_data[$a_obj_name]["group"];
216  }
217 
224  function hasCheckbox($a_obj_name)
225  {
226  return (bool) $this->obj_data[$a_obj_name]["checkbox"];
227  }
228 
235  function getTranslationType($a_obj_name)
236  {
237  global $ilDB;
238 
239  if ($a_obj_name == "root")
240  {
241  if (!isset($this->root_trans_type))
242  {
243  $q = "SELECT count(obj_id) cnt FROM object_translation WHERE obj_id = ".
244  $ilDB->quote(ROOT_FOLDER_ID,'integer')." ";
245  $set = $ilDB->query($q);
246  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
247  if($rec["cnt"] > 0)
248  {
249  $this->root_trans_type = "db";
250  }
251  else
252  {
253  $this->root_trans_type = $this->obj_data[$a_obj_name]["translate"];
254  }
255  }
256  return $this->root_trans_type;
257  }
258 
259  if (isset($this->obj_data[$a_obj_name]))
260  {
261  return $this->obj_data[$a_obj_name]["translate"];
262  }
263 
264  return "";
265  }
266 
267 
274  function stopInheritance($a_obj_name)
275  {
276  return (bool) $this->obj_data[$a_obj_name]["inherit"];
277  }
278 
285  function getDevMode($a_obj_name)
286  {
287  return (bool) $this->obj_data[$a_obj_name]["devmode"];
288  }
289 
296  function getDevModeAll()
297  {
298  $types = array_keys($this->obj_data);
299 
300  foreach ($types as $type)
301  {
302  if ($this->getDevMode($type))
303  {
304  $devtypes[] = $type;
305  }
306  }
307 
308  return $devtypes ? $devtypes : array();
309  }
310 
318  function isRBACObject($a_obj_name)
319  {
320  return (bool) $this->obj_data[$a_obj_name]["rbac"];
321  }
322 
330  function isPlugin($a_obj_name)
331  {
332  return (bool) isset($this->obj_data[$a_obj_name]["plugin"]);
333  }
334 
341  function isPluginTypeName($a_str)
342  {
343  return (substr($a_str, 0, 1) == "x");
344  }
345 
352  function getAllRBACObjects()
353  {
354  $types = array_keys($this->obj_data);
355 
356  foreach ($types as $type)
357  {
358  if ($this->isRBACObject($type))
359  {
360  $rbactypes[] = $type;
361  }
362  }
363 
364  return $rbactypes ? $rbactypes : array();
365  }
366 
373  function getAllObjects()
374  {
375  return array_keys($this->obj_data);
376  }
377 
384  public function allowLink($a_obj_name)
385  {
386  return (bool) $this->obj_data[$a_obj_name]["allow_link"];
387  }
388 
395  public function allowCopy($a_obj_name)
396  {
397  return (bool) $this->obj_data[$a_obj_name]["allow_copy"];
398  }
399 
400  public function allowExport($a_obj_name)
401  {
402  return (bool) $this->obj_data[$a_obj_name]['export'];
403  }
404 
410  public function hasLocalRoles($a_obj_type)
411  {
412  return isset($this->obj_data[$a_obj_type]['subobjects']['rolf']);
413  }
414 
423  function getSubObjects($a_obj_type,$a_filter = true)
424  {
425  global $ilSetting;
426 
427  $subs = array();
428 
429  if ($subobjects = $this->obj_data[$a_obj_type]["subobjects"])
430  {
431  // Filter some objects e.g chat object are creatable if chat is active
432  if ($a_filter)
433  {
434  $this->__filterObjects($subobjects);
435  }
436  foreach ($subobjects as $data => $sub)
437  {
438  if ($sub["module"] != "n")
439  {
440  if (!($ilSetting->get("obj_dis_creation_".$data)))
441  {
442  $subs[$data] = $sub;
443 
444  // determine position
445  $pos = ($ilSetting->get("obj_add_new_pos_".$data) > 0)
446  ? (int) $ilSetting->get("obj_add_new_pos_".$data)
447  : (int) $this->obj_data[$data]["default_pos"];
448  $subs[$data]["pos"] = $pos;
449  }
450  }
451  }
452 
453  $subs2 = ilUtil::sortArray($subs, "pos", ASC, true, true);
454 
455  return $subs2;
456  }
457 
458  return $subs;
459  }
460 
474  function getSubObjectsRecursively($a_obj_type,$a_include_source_obj = true, $a_add_admin_objects = false)
475  {
476  global $ilSetting;
477 
478  // This associative array is used to collect all subobject types.
479  // key=>type, value=data
480  $recursivesubs = array();
481 
482  // This array is used to keep track of the object types, we
483  // need to call function getSubobjects() for.
484  $to_do = array($a_obj_type);
485 
486  // This array is used to keep track of the object types, we
487  // have called function getSubobjects() already. This is to
488  // prevent endless loops, for object types that support
489  // themselves as subobject types either directly or indirectly.
490  $done = array();
491 
492  while (count($to_do) > 0)
493  {
494  $type = array_pop($to_do);
495  $done[] = $type;
496 
497  // no recovery folder subitems
498  if($type == 'recf')
499  {
500  continue;
501  }
502 
503  // Hide administration if desired
504  if(!$a_add_admin_objects and $type == 'adm')
505  {
506  $subs = array();
507  }
508  else
509  {
510  $subs = $this->getSubObjects($type);
511  }
512  #vd('xxxxxxxxxxxxx'.$type);
513  foreach ($subs as $subtype => $data)
514  {
515  #vd('------------------------->'.$subtype);
516 
517  // Hide role templates and folder from view
518  if($this->getDevMode($subtype) or !$this->isRBACObject($subtype))
519  {
520  continue;
521  }
522  if($subtype == 'rolf' or $subtype == 'rolt')
523  {
524  continue;
525  }
526  if(!$a_add_admin_objects and $subtype == 'adm')
527  {
528  continue;
529  }
530 
531  $recursivesubs[$subtype] = $data;
532  if (! in_array($subtype, $done)
533  && ! in_array($subtype, $to_do))
534  {
535  $to_do[] = $subtype;
536  }
537  }
538  }
539 
540  if($a_include_source_obj)
541  {
542  if(!isset($recursivesubs[$a_obj_type]))
543  {
544  $recursivesubs[$a_obj_type]['name'] = $a_obj_type;
545  $recursivesubs[$a_obj_type]['lng'] = $a_obj_type;
546  $recursivesubs[$a_obj_type]['max'] = 0;
547  $recursivesubs[$a_obj_type]['pos'] = -1;
548  }
549  }
550 
551  return ilUtil::sortArray($recursivesubs, "pos", ASC, true, true);
552  }
553 
554 
564  function getSubobjectsToFilter($a_obj_type = "adm")
565  {
566  foreach($this->obj_data[$a_obj_type]["subobjects"] as $key => $value)
567  {
568  switch($key)
569  {
570  case "rolf":
571  // DO NOTHING
572  break;
573 
574  default:
575  $tmp_subs[] = $key;
576  }
577  }
578  // ADD adm and root object
579  $tmp_subs[] = "adm";
580  #$tmp_subs[] = "root";
581 
582  return $tmp_subs ? $tmp_subs : array();
583  }
584 
592  function getCreatableSubObjects($a_obj_type)
593  {
594  $subobjects = $this->getSubObjects($a_obj_type);
595 
596  // remove role folder object from list
597  unset($subobjects["rolf"]);
598  unset($subobjects['rcrs']);
599 
600  $sub_types = array_keys($subobjects);
601 
602  // remove object types in development from list
603  foreach ($sub_types as $type)
604  {
605 
606  if ($this->getDevMode($type) || $this->isSystemObject($type))
607  {
608  unset($subobjects[$type]);
609  }
610  }
611 
612  return $subobjects;
613  }
614 
621  function getSubObjectsAsString($a_obj_type)
622  {
623  $string = "";
624 
625  if (is_array($this->obj_data[$a_obj_type]["subobjects"]))
626  {
627  $data = array_keys($this->obj_data[$a_obj_type]["subobjects"]);
628 
629  $string = "'".implode("','", $data)."'";
630  }
631 
632  return $string;
633  }
634 
643  public function isContainer($a_obj_name)
644  {
645  if(!is_array($this->obj_data[$a_obj_name]['subobjects']))
646  {
647  return false;
648  }
649  return count($this->obj_data[$a_obj_name]['subobjects']) > 1 ? true : false;
650  }
651 
652 // PRIVATE METHODS
653 
660  function setHandlers($a_xml_parser)
661  {
662  xml_set_object($a_xml_parser,$this);
663  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
664  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
665  }
666 
675  function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
676  {
677  switch ($a_name)
678  {
679  case 'object':
680  $this->parent_tag_name = $a_attribs["name"];
681  break;
682  case 'property':
683  $this->current_tag = "property";
684  $this->current_tag_name = $a_attribs["name"];
685 // $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["name"] = $a_attribs["name"];
686  $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["module"] = $a_attribs["module"];
687 //echo '<br>$this->obj_data["'.$this->parent_tag_name.'"]["properties"]["'.$this->current_tag_name.'"]["module"] = "'.$a_attribs["module"].'";';
688  break;
689  }
690  }
691 
699  function handlerCharacterData($a_xml_parser,$a_data)
700  {
701  }
702 
710  function handlerEndTag($a_xml_parser,$a_name)
711  {
712  $this->current_tag = '';
713  $this->current_tag_name = '';
714  }
715 
716 
717  function __filterObjects(&$subobjects)
718  {
719  foreach($subobjects as $type => $data)
720  {
721  switch($type)
722  {
723  case "chat":
724  if(!$this->ilias->getSetting("chat_active"))
725  {
726  unset($subobjects[$type]);
727  }
728  break;
729 
730  case "icrs":
731  if(!$this->ilias->getSetting("ilinc_active"))
732  {
733  unset($subobjects[$type]);
734  }
735  break;
736 
737  default:
738  // DO NOTHING
739  }
740  }
741  }
742 
756  function isSystemObject($a_obj_name)
757  {
758  return (bool) $this->obj_data[$a_obj_name]["system"];
759  }
760 
767  function isSideBlock($a_obj_name)
768  {
769  return (bool) $this->obj_data[$a_obj_name]["sideblock"];
770  }
771 
775  static function getRepositoryObjectTypesForComponent($a_component_type,
776  $a_component_name)
777  {
778  global $ilDB;
779 
780  $set = $ilDB->queryF("SELECT * FROM il_object_def WHERE component = %s",
781  array("text"), array($a_component_type."/".$a_component_name));
782 
783  $types = array();
784  while($rec = $ilDB->fetchAssoc($set))
785  {
786  if ($rec["system"] != 1)
787  {
788  $types[] = $rec;
789  }
790  }
791 
792  return $types;
793  }
794 
798  static function getComponentForType($a_obj_type)
799  {
800  global $ilDB;
801 
802  $set = $ilDB->queryF("SELECT component FROM il_object_def WHERE id = %s",
803  array("text"), array($a_obj_type));
804 
805  if ($rec = $ilDB->fetchAssoc($set))
806  {
807  return $rec["component"];
808  }
809 
810  return "";
811  }
812 
816  static function getGroupedRepositoryObjectTypes($a_parent_obj_type)
817  {
818  global $ilDB, $ilPluginAdmin;
819 
820  $set = $ilDB->query("SELECT * FROM il_object_group");
821  $groups = array();
822  while ($gr_rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
823  {
824  $groups[$gr_rec["id"]] = $gr_rec;
825  }
826 
827  if (!is_array($a_parent_obj_type))
828  {
829  $set = $ilDB->queryF("SELECT il_object_def.* FROM il_object_def, il_object_subobj ".
830  " WHERE NOT (system = 1) AND NOT (sideblock = 1) AND ".
831  " parent = %s ".
832  " AND subobj = id ", array("text"), array($a_parent_obj_type));
833  }
834  else
835  {
836  $q = "SELECT DISTINCT (id) as sid, il_object_def.* FROM il_object_def, il_object_subobj ".
837  " WHERE NOT (system = 1) AND NOT (sideblock = 1) AND ".
838  $ilDB->in("parent", $a_parent_obj_type, false, "text").
839  " AND subobj = id ";
840  $set = $ilDB->query($q);
841  }
842 
843  $grouped_obj = array();
844  while($rec = $ilDB->fetchAssoc($set))
845  {
846  if ($rec["grp"] != "")
847  {
848  $grouped_obj[$rec["grp"]]["pos"] = (int) $groups[$rec["grp"]]["default_pres_pos"];
849  $grouped_obj[$rec["grp"]]["objs"][] = $rec["id"];
850  }
851  else
852  {
853  $grouped_obj[$rec["id"]]["pos"] = (int) $rec["default_pres_pos"];
854  $grouped_obj[$rec["id"]]["objs"][] = $rec["id"];
855  }
856  }
857 //var_dump($grouped_obj);
858  // now get objects from repository plugin
859  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "Repository", "robj");
860  foreach ($pl_names as $pl_name)
861  {
862  include_once("./Services/Component/classes/class.ilPlugin.php");
863  $pl_id = ilPlugin::lookupIdForName(IL_COMP_SERVICE, "Repository", "robj", $pl_name);
864  if (!isset($grouped_obj[$pl_id]))
865  {
866  $grouped_obj[$pl_id] = array(
867  "pos" => 2000,
868  "objs" => array(0 => $pl_id)
869  );
870  }
871  }
872 
873 //var_dump($grouped_obj);
874 
875  $ret = ilUtil::sortArray($grouped_obj, "pos", "asc", true, true);
876 //var_dump($ret);
877  return $ret;
878  }
879 
880 }
881 ?>