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