ILIAS  Release_4_4_x_branch Revision 61816
 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  var $sub_types = array();
39 
40  const MODE_REPOSITORY = 1;
41  const MODE_WORKSPACE = 2;
43 
50  function ilObjectDefinition()
51  {
52  global $ilias;
53 
54  $this->readDefinitionData();
55  $this->ilias = $ilias;
56 
57 
59 
60  // removing this line leads to segmentation faults in
61  // learning module editor with
62  // - PHP 5.2.1, libxml 2.6.22, libxslt 1.1.15 (MacOsX)
63  // - PHP 5.2.1, libxml 2.6.31, libxslt 1.1.22 (MacOsX)
64  // - PHP 5.2.5, libxml 2.6.31, libxslt 1.1.22 (MacOsX)
65  // - PHP 5.2.0-8+etch7, libxml 2.6.27, libxslt 1.1.19
66  // - PHP 5.2.0, libxml, libxml 2.6.26, libxslt 1.1.17 (OpenSuse 10.2)
67  // (needs further investigation)
68  // OK with:
69  // - PHP 5.1.2, libxml 2.6.24, libxslt 1.1.15
70 
71  //
72  // Replacing all "=&" with "=" in xml5compliance seems to solve the problem
73  //
74 
75 // $this->startParsing();
76  }
77 
78 
82  function readDefinitionData()
83  {
84  global $ilDB, $ilPluginAdmin;
85 
86  $this->obj_data = array();
87 
88 
89  // Select all object_definitions and collect the definition id's in
90  // this array.
91  $defIds = array();
92  $set = $ilDB->query("SELECT * FROM il_object_def");
93  while ($rec = $ilDB->fetchAssoc($set))
94  {
95  $this->obj_data[$rec["id"]] = array(
96  "name" => $rec["id"],
97  "class_name" => $rec["class_name"],
98  "location" => $rec["location"],
99  "checkbox" => $rec["checkbox"],
100  "inherit" => $rec["inherit"],
101  "component" => $rec["component"],
102  "translate" => $rec["translate"],
103  "devmode" => $rec["devmode"],
104  "allow_link" => $rec["allow_link"],
105  "allow_copy" => $rec["allow_copy"],
106  "rbac" => $rec["rbac"],
107  "group" => $rec["grp"],
108  "system" => $rec["system"],
109  "default_pos" => "9999".str_pad($rec["default_pos"], 4, "0", STR_PAD_LEFT), // "unassigned" group
110  "sideblock" => $rec["sideblock"],
111  'export' => $rec['export'],
112  'repository' => $rec['repository'],
113  'workspace' => $rec['workspace'],
114  'administration' => $rec['administration'],
115  'amet' => $rec['amet']
116  );
117  $this->obj_data[$rec["id"]]["subobjects"] = array();
118 
119  $defIds[] = $rec["id"];
120  }
121 
122  // get all subobject definitions in a single query
123  $set2 = $ilDB->query("SELECT * FROM il_object_subobj WHERE ".
124  $ilDB->in('parent', $defIds, false, 'text'));
125  while ($rec2 = $ilDB->fetchAssoc($set2))
126  {
127  $max = $rec2["mmax"];
128  if ($max <= 0) // for backward compliance
129  {
130  $max = "";
131  }
132  $this->obj_data[$rec2["parent"]]["subobjects"][$rec2["subobj"]] = array(
133  "name" => $rec2["subobj"],
134  "max" => $max,
135  "lng" => $rec2["subobj"]
136  );
137  }
138 
139  $set = $ilDB->query("SELECT * FROM il_object_group");
140  $this->obj_group = array();
141  while ($rec = $ilDB->fetchAssoc($set))
142  {
143  $this->obj_group[$rec["id"]] = $rec;
144  }
145 
146  // now get objects from repository plugin
147  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "Repository", "robj");
148  foreach ($pl_names as $pl_name)
149  {
150  include_once("./Services/Component/classes/class.ilPlugin.php");
151  $pl_id = ilPlugin::lookupIdForName(IL_COMP_SERVICE, "Repository", "robj", $pl_name);
152  if ($pl_id != "" && !isset($this->obj_data[$pl_id]))
153  {
154  include_once("./Services/Repository/classes/class.ilRepositoryObjectPlugin.php");
155  $loc = ilPlugin::_getDirectory(IL_COMP_SERVICE, "Repository", "robj",
156  $pl_name)."/classes";
157 
158  $this->obj_data[$pl_id] = array(
159  "name" => $pl_id,
160  "class_name" => $pl_name,
161  "plugin" => "1",
162  "location" => $loc,
163  "checkbox" => "1",
164  "inherit" => "0",
165  "component" => "",
166  "translate" => "0",
167  "devmode" => "0",
168  "allow_link" => "1",
169  "allow_copy" => "0",
170  "rbac" => "1",
171  "group" => null,
172  "system" => "0",
173  "default_pos" => "99992000", // "unassigned" group
174  'repository' => '1',
175  'workspace' => '0',
176  'administration' => '0',
177  "sideblock" => "0");
178  $this->obj_data[$rec["id"]]["subobjects"] = array();
179 
180  // plugins have to be marked as such - see ilContainerGUI::showPossibleSubObjects()
181  $this->obj_data["crs"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id, "plugin" => true);
182  $this->obj_data["fold"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id, "plugin" => true);
183  $this->obj_data["grp"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id, "plugin" => true);
184  $this->obj_data["cat"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id, "plugin" => true);
185  $this->obj_data["root"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id, "plugin" => true);
186  }
187  }
188 //var_dump($this->obj_data["root"]["subobjects"]);
189 //var_dump($this->obj_data2["root"]);
190 
191  $set = $ilDB->query("SELECT * FROM il_object_sub_type ");
192  $this->sub_types = array();
193  while ($rec = $ilDB->fetchAssoc($set))
194  {
195  $this->sub_types[$rec["obj_type"]][] = $rec;
196  }
197 
198  }
199 
200 
201 // PUBLIC METHODS
202 
209  function getClassName($a_obj_name)
210  {
211  return $this->obj_data[$a_obj_name]["class_name"];
212  }
213 
214 
221  function getLocation($a_obj_name)
222  {
223  return $this->obj_data[$a_obj_name]["location"];
224  }
225 
229  function getGroup($a_id)
230  {
231  return $this->obj_group[$a_id];
232  }
233 
237  function getGroupOfObj($a_obj_name)
238  {
239  return $this->obj_data[$a_obj_name]["group"];
240  }
241 
248  function hasCheckbox($a_obj_name)
249  {
250  return (bool) $this->obj_data[$a_obj_name]["checkbox"];
251  }
252 
259  function getTranslationType($a_obj_name)
260  {
261  global $ilDB;
262 
263  if ($a_obj_name == "root")
264  {
265  if (!isset($this->root_trans_type))
266  {
267  $q = "SELECT count(obj_id) cnt FROM object_translation WHERE obj_id = ".
268  $ilDB->quote(ROOT_FOLDER_ID,'integer')." ";
269  $set = $ilDB->query($q);
270  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
271  if($rec["cnt"] > 0)
272  {
273  $this->root_trans_type = "db";
274  }
275  else
276  {
277  $this->root_trans_type = $this->obj_data[$a_obj_name]["translate"];
278  }
279  }
280  return $this->root_trans_type;
281  }
282 
283  if (isset($this->obj_data[$a_obj_name]))
284  {
285  return $this->obj_data[$a_obj_name]["translate"];
286  }
287 
288  return "";
289  }
290 
291 
298  function stopInheritance($a_obj_name)
299  {
300  return (bool) $this->obj_data[$a_obj_name]["inherit"];
301  }
302 
309  function getDevMode($a_obj_name)
310  {
311  return (bool) $this->obj_data[$a_obj_name]["devmode"];
312  }
313 
320  function getDevModeAll()
321  {
322  $types = array_keys($this->obj_data);
323 
324  foreach ($types as $type)
325  {
326  if ($this->getDevMode($type))
327  {
328  $devtypes[] = $type;
329  }
330  }
331 
332  return $devtypes ? $devtypes : array();
333  }
334 
342  function isRBACObject($a_obj_name)
343  {
344  return (bool) $this->obj_data[$a_obj_name]["rbac"];
345  }
346 
354  function isPlugin($a_obj_name)
355  {
356  return (bool) isset($this->obj_data[$a_obj_name]["plugin"]);
357  }
358 
365  function isPluginTypeName($a_str)
366  {
367  return (substr($a_str, 0, 1) == "x");
368  }
369 
376  function getAllRBACObjects()
377  {
378  $types = array_keys($this->obj_data);
379 
380  foreach ($types as $type)
381  {
382  if ($this->isRBACObject($type))
383  {
384  $rbactypes[] = $type;
385  }
386  }
387 
388  return $rbactypes ? $rbactypes : array();
389  }
390 
397  function getAllObjects()
398  {
399  return array_keys($this->obj_data);
400  }
401 
408  public function allowLink($a_obj_name)
409  {
410  return (bool) $this->obj_data[$a_obj_name]["allow_link"];
411  }
412 
419  public function allowCopy($a_obj_name)
420  {
421  return (bool) $this->obj_data[$a_obj_name]["allow_copy"];
422  }
423 
424  public function allowExport($a_obj_name)
425  {
426  return (bool) $this->obj_data[$a_obj_name]['export'];
427  }
428 
434  public function hasLocalRoles($a_obj_type)
435  {
436  return isset($this->obj_data[$a_obj_type]['subobjects']['rolf']);
437  }
438 
447  function getSubObjects($a_obj_type,$a_filter = true)
448  {
449  global $ilSetting;
450 
451  $subs = array();
452 
453  if ($subobjects = $this->obj_data[$a_obj_type]["subobjects"])
454  {
455  // Filter some objects e.g chat object are creatable if chat is active
456  if ($a_filter)
457  {
458  $this->__filterObjects($subobjects);
459  }
460  foreach ($subobjects as $data => $sub)
461  {
462  if ($sub["module"] != "n")
463  {
464  if (!($ilSetting->get("obj_dis_creation_".$data)))
465  {
466  $subs[$data] = $sub;
467 
468  // determine position
469  $pos = ($ilSetting->get("obj_add_new_pos_".$data) > 0)
470  ? (int) $ilSetting->get("obj_add_new_pos_".$data)
471  : (int) $this->obj_data[$data]["default_pos"];
472  $subs[$data]["pos"] = $pos;
473  }
474  }
475  }
476 
477  $subs2 = ilUtil::sortArray($subs, "pos", ASC, true, true);
478 
479  return $subs2;
480  }
481 
482  return $subs;
483  }
484 
498  function getSubObjectsRecursively($a_obj_type,$a_include_source_obj = true, $a_add_admin_objects = false)
499  {
500  global $ilSetting;
501 
502  // This associative array is used to collect all subobject types.
503  // key=>type, value=data
504  $recursivesubs = array();
505 
506  // This array is used to keep track of the object types, we
507  // need to call function getSubobjects() for.
508  $to_do = array($a_obj_type);
509 
510  // This array is used to keep track of the object types, we
511  // have called function getSubobjects() already. This is to
512  // prevent endless loops, for object types that support
513  // themselves as subobject types either directly or indirectly.
514  $done = array();
515 
516  while (count($to_do) > 0)
517  {
518  $type = array_pop($to_do);
519  $done[] = $type;
520 
521  // no recovery folder subitems
522  if($type == 'recf')
523  {
524  continue;
525  }
526 
527  // Hide administration if desired
528  if(!$a_add_admin_objects and $type == 'adm')
529  {
530  $subs = array();
531  }
532  else
533  {
534  $subs = $this->getSubObjects($type);
535  }
536  #vd('xxxxxxxxxxxxx'.$type);
537  foreach ($subs as $subtype => $data)
538  {
539  #vd('------------------------->'.$subtype);
540 
541  // Hide role templates and folder from view
542  if($this->getDevMode($subtype) or !$this->isRBACObject($subtype))
543  {
544  continue;
545  }
546  if($subtype == 'rolf' or $subtype == 'rolt')
547  {
548  continue;
549  }
550  if(!$a_add_admin_objects and $subtype == 'adm')
551  {
552  continue;
553  }
554 
555  $recursivesubs[$subtype] = $data;
556  if (! in_array($subtype, $done)
557  && ! in_array($subtype, $to_do))
558  {
559  $to_do[] = $subtype;
560  }
561  }
562  }
563 
564  if($a_include_source_obj)
565  {
566  if(!isset($recursivesubs[$a_obj_type]))
567  {
568  $recursivesubs[$a_obj_type]['name'] = $a_obj_type;
569  $recursivesubs[$a_obj_type]['lng'] = $a_obj_type;
570  $recursivesubs[$a_obj_type]['max'] = 0;
571  $recursivesubs[$a_obj_type]['pos'] = -1;
572  }
573  }
574  return ilUtil::sortArray($recursivesubs, "pos", ASC, true, true);
575  }
576 
577 
587  function getSubobjectsToFilter($a_obj_type = "adm")
588  {
589  foreach($this->obj_data[$a_obj_type]["subobjects"] as $key => $value)
590  {
591  switch($key)
592  {
593  case "rolf":
594  // DO NOTHING
595  break;
596 
597  default:
598  $tmp_subs[] = $key;
599  }
600  }
601  // ADD adm and root object
602  $tmp_subs[] = "adm";
603  #$tmp_subs[] = "root";
604 
605  return $tmp_subs ? $tmp_subs : array();
606  }
607 
616  function getCreatableSubObjects($a_obj_type, $a_context = self::MODE_REPOSITORY)
617  {
618  $subobjects = $this->getSubObjects($a_obj_type);
619 
620  // remove role folder object from list
621  unset($subobjects["rolf"]);
622 
623  $sub_types = array_keys($subobjects);
624 
625  // remove object types in development from list
626  foreach ($sub_types as $type)
627  {
628  if ($this->getDevMode($type) || $this->isSystemObject($type))
629  {
630  unset($subobjects[$type]);
631  }
632  if ($a_context == self::MODE_REPOSITORY && !$this->isAllowedInRepository($type))
633  {
634  unset($subobjects[$type]);
635  }
636  if ($a_context == self::MODE_WORKSPACE && !$this->isAllowedInWorkspace($type))
637  {
638  unset($subobjects[$type]);
639  }
640  if ($a_context == self::MODE_ADMINISTRATION && !$this->isAdministrationObject($type))
641  {
642  unset($subobjects[$type]);
643  }
644  // Filter for iLinc: Delete the following lines after we completely removed the iLinc object in ILIAS 4.5.x
645  if(in_array($type, array('icrs', 'icla')))
646  {
647  unset($subobjects[$type]);
648  }
649  }
650 
651  return $subobjects;
652  }
653 
660  function getSubObjectsAsString($a_obj_type)
661  {
662  $string = "";
663 
664  if (is_array($this->obj_data[$a_obj_type]["subobjects"]))
665  {
666  $data = array_keys($this->obj_data[$a_obj_type]["subobjects"]);
667 
668  $string = "'".implode("','", $data)."'";
669  }
670 
671  return $string;
672  }
673 
682  public function isContainer($a_obj_name)
683  {
684  if(!is_array($this->obj_data[$a_obj_name]['subobjects']))
685  {
686  return false;
687  }
688  return count($this->obj_data[$a_obj_name]['subobjects']) > 1 ? true : false;
689  }
690 
691 // PRIVATE METHODS
692 
699  function setHandlers($a_xml_parser)
700  {
701  xml_set_object($a_xml_parser,$this);
702  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
703  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
704  }
705 
714  function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
715  {
716  switch ($a_name)
717  {
718  case 'object':
719  $this->parent_tag_name = $a_attribs["name"];
720  break;
721  case 'property':
722  $this->current_tag = "property";
723  $this->current_tag_name = $a_attribs["name"];
724 // $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["name"] = $a_attribs["name"];
725  $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["module"] = $a_attribs["module"];
726 //echo '<br>$this->obj_data["'.$this->parent_tag_name.'"]["properties"]["'.$this->current_tag_name.'"]["module"] = "'.$a_attribs["module"].'";';
727  break;
728  }
729  }
730 
738  function handlerCharacterData($a_xml_parser,$a_data)
739  {
740  }
741 
749  function handlerEndTag($a_xml_parser,$a_name)
750  {
751  $this->current_tag = '';
752  $this->current_tag_name = '';
753  }
754 
755 
756  function __filterObjects(&$subobjects)
757  {
758  foreach($subobjects as $type => $data)
759  {
760  switch($type)
761  {
762  case "chat":
763  if(!$this->ilias->getSetting("chat_active"))
764  {
765  unset($subobjects[$type]);
766  }
767  break;
768 
769  case "icrs":
770  if(!$this->ilias->getSetting("ilinc_active"))
771  {
772  unset($subobjects[$type]);
773  }
774  break;
775 
776  default:
777  // DO NOTHING
778  }
779  }
780  }
781 
795  function isSystemObject($a_obj_name)
796  {
797  return (bool) $this->obj_data[$a_obj_name]["system"];
798  }
799 
806  function isSideBlock($a_obj_name)
807  {
808  return (bool) $this->obj_data[$a_obj_name]["sideblock"];
809  }
810 
814  static function getRepositoryObjectTypesForComponent($a_component_type,
815  $a_component_name)
816  {
817  global $ilDB;
818 
819  $set = $ilDB->queryF("SELECT * FROM il_object_def WHERE component = %s",
820  array("text"), array($a_component_type."/".$a_component_name));
821 
822  $types = array();
823  while($rec = $ilDB->fetchAssoc($set))
824  {
825  if ($rec["system"] != 1)
826  {
827  $types[] = $rec;
828  }
829  }
830 
831  return $types;
832  }
833 
837  static function getComponentForType($a_obj_type)
838  {
839  global $ilDB;
840 
841  $set = $ilDB->queryF("SELECT component FROM il_object_def WHERE id = %s",
842  array("text"), array($a_obj_type));
843 
844  if ($rec = $ilDB->fetchAssoc($set))
845  {
846  return $rec["component"];
847  }
848 
849  return "";
850  }
851 
855  static function getGroupedRepositoryObjectTypes($a_parent_obj_type)
856  {
857  global $ilDB, $ilPluginAdmin;
858 
859  $set = $ilDB->query("SELECT * FROM il_object_group");
860  $groups = array();
861  while ($gr_rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
862  {
863  $groups[$gr_rec["id"]] = $gr_rec;
864  }
865 
866  if (!is_array($a_parent_obj_type))
867  {
868  $set = $ilDB->queryF("SELECT il_object_def.* FROM il_object_def, il_object_subobj ".
869  " WHERE NOT (system = 1) AND NOT (sideblock = 1) AND ".
870  " parent = %s ".
871  " AND subobj = id ", array("text"), array($a_parent_obj_type));
872  }
873  else
874  {
875  $q = "SELECT DISTINCT (id) as sid, il_object_def.* FROM il_object_def, il_object_subobj ".
876  " WHERE NOT (system = 1) AND NOT (sideblock = 1) AND ".
877  $ilDB->in("parent", $a_parent_obj_type, false, "text").
878  " AND subobj = id ";
879  $set = $ilDB->query($q);
880  }
881 
882  $grouped_obj = array();
883  while($rec = $ilDB->fetchAssoc($set))
884  {
885  if ($rec["grp"] != "")
886  {
887  $grouped_obj[$rec["grp"]]["pos"] = (int) $groups[$rec["grp"]]["default_pres_pos"];
888  $grouped_obj[$rec["grp"]]["objs"][] = $rec["id"];
889  }
890  else
891  {
892  $grouped_obj[$rec["id"]]["pos"] = (int) $rec["default_pres_pos"];
893  $grouped_obj[$rec["id"]]["objs"][] = $rec["id"];
894  }
895  }
896 //var_dump($grouped_obj);
897  // now get objects from repository plugin
898  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "Repository", "robj");
899  foreach ($pl_names as $pl_name)
900  {
901  include_once("./Services/Component/classes/class.ilPlugin.php");
902  $pl_id = ilPlugin::lookupIdForName(IL_COMP_SERVICE, "Repository", "robj", $pl_name);
903  if (!isset($grouped_obj[$pl_id]))
904  {
905  $grouped_obj[$pl_id] = array(
906  "pos" => "99992000", // "unassigned" group
907  "objs" => array(0 => $pl_id)
908  );
909  }
910  }
911 
912 //var_dump($grouped_obj);
913 
914  $ret = ilUtil::sortArray($grouped_obj, "pos", "asc", true, true);
915 //var_dump($ret);
916  return $ret;
917  }
918 
926  function isAllowedInRepository($a_obj_name)
927  {
928  return (bool) $this->obj_data[$a_obj_name]["repository"];
929  }
930 
937  function getAllRepositoryTypes($a_incl_adm = false)
938  {
939  $types = array_keys($this->obj_data);
940 
941  foreach ($types as $type)
942  {
943  if ($this->isAllowedInRepository($type) &&
944  (!$this->isAdministrationObject($type) || $a_incl_adm))
945  {
946  $rbactypes[] = $type;
947  }
948  }
949 
950  return $rbactypes ? $rbactypes : array();
951  }
952 
953 
961  function isAllowedInWorkspace($a_obj_name)
962  {
963  return (bool) $this->obj_data[$a_obj_name]["workspace"];
964  }
965 
971  public function isAdministrationObject($a_obj_name)
972  {
973  return (bool) $this->obj_data[$a_obj_name]['administration'];
974  }
975 
982  public function isInactivePlugin($a_type)
983  {
984  if (substr($a_type, 0, 1) == "x" && !$this->isPlugin($a_type))
985  {
986  return true;
987  }
988  return false;
989  }
990 
998  {
999  $amet = array();
1000  foreach ($this->obj_data as $k => $v)
1001  {
1002  if ($v["amet"])
1003  {
1004  $amet[] = array("obj_type" => $k, "sub_type" => "");
1005  }
1006  }
1007 
1008  foreach ($this->sub_types as $type => $sub_types)
1009  {
1010  foreach ($sub_types as $t)
1011  {
1012  if ($t["amet"])
1013  {
1014  $amet[] = array("obj_type" => $type, "sub_type" => $t["sub_type"]);
1015  }
1016  }
1017  }
1018 
1019  return $amet;
1020  }
1021 
1022 }
1023 ?>