ILIAS  eassessment Revision 61809
 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["grp"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id);
166  $this->obj_data["cat"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id);
167  $this->obj_data["root"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id);
168  }
169  }
170 //var_dump($this->obj_data["root"]["subobjects"]);
171 //var_dump($this->obj_data2["root"]);
172 
173  }
174 
175 
176 // PUBLIC METHODS
177 
184  function getClassName($a_obj_name)
185  {
186  return $this->obj_data[$a_obj_name]["class_name"];
187  }
188 
189 
196  function getLocation($a_obj_name)
197  {
198  return $this->obj_data[$a_obj_name]["location"];
199  }
200 
204  function getGroup($a_id)
205  {
206  return $this->obj_group[$a_id];
207  }
208 
212  function getGroupOfObj($a_obj_name)
213  {
214  return $this->obj_data[$a_obj_name]["group"];
215  }
216 
223  function hasCheckbox($a_obj_name)
224  {
225  return (bool) $this->obj_data[$a_obj_name]["checkbox"];
226  }
227 
234  function getTranslationType($a_obj_name)
235  {
236  global $ilDB;
237 
238  if ($a_obj_name == "root")
239  {
240  if (!isset($this->root_trans_type))
241  {
242  $q = "SELECT count(obj_id) cnt FROM object_translation WHERE obj_id = ".
243  $ilDB->quote(ROOT_FOLDER_ID,'integer')." ";
244  $set = $ilDB->query($q);
245  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
246  if($rec["cnt"] > 0)
247  {
248  $this->root_trans_type = "db";
249  }
250  else
251  {
252  $this->root_trans_type = $this->obj_data[$a_obj_name]["translate"];
253  }
254  }
255  return $this->root_trans_type;
256  }
257 
258  if (isset($this->obj_data[$a_obj_name]))
259  {
260  return $this->obj_data[$a_obj_name]["translate"];
261  }
262 
263  return "";
264  }
265 
266 
273  function stopInheritance($a_obj_name)
274  {
275  return (bool) $this->obj_data[$a_obj_name]["inherit"];
276  }
277 
284  function getDevMode($a_obj_name)
285  {
286  return (bool) $this->obj_data[$a_obj_name]["devmode"];
287  }
288 
295  function getDevModeAll()
296  {
297  $types = array_keys($this->obj_data);
298 
299  foreach ($types as $type)
300  {
301  if ($this->getDevMode($type))
302  {
303  $devtypes[] = $type;
304  }
305  }
306 
307  return $devtypes ? $devtypes : array();
308  }
309 
317  function isRBACObject($a_obj_name)
318  {
319  return (bool) $this->obj_data[$a_obj_name]["rbac"];
320  }
321 
329  function isPlugin($a_obj_name)
330  {
331  return (bool) isset($this->obj_data[$a_obj_name]["plugin"]);
332  }
333 
340  function isPluginTypeName($a_str)
341  {
342  return (substr($a_str, 0, 1) == "x");
343  }
344 
351  function getAllRBACObjects()
352  {
353  $types = array_keys($this->obj_data);
354 
355  foreach ($types as $type)
356  {
357  if ($this->isRBACObject($type))
358  {
359  $rbactypes[] = $type;
360  }
361  }
362 
363  return $rbactypes ? $rbactypes : array();
364  }
365 
372  function getAllObjects()
373  {
374  return array_keys($this->obj_data);
375  }
376 
383  public function allowLink($a_obj_name)
384  {
385  return (bool) $this->obj_data[$a_obj_name]["allow_link"];
386  }
387 
394  public function allowCopy($a_obj_name)
395  {
396  return (bool) $this->obj_data[$a_obj_name]["allow_copy"];
397  }
398 
399  public function allowExport($a_obj_name)
400  {
401  return (bool) $this->obj_data[$a_obj_name]['export'];
402  }
403 
409  public function hasLocalRoles($a_obj_type)
410  {
411  return isset($this->obj_data[$a_obj_type]['subobjects']['rolf']);
412  }
413 
422  function getSubObjects($a_obj_type,$a_filter = true)
423  {
424  global $ilSetting;
425 
426  $subs = array();
427 
428  if ($subobjects = $this->obj_data[$a_obj_type]["subobjects"])
429  {
430  // Filter some objects
431  if ($a_filter)
432  {
433  $this->__filterObjects($subobjects);
434  }
435  foreach ($subobjects as $data => $sub)
436  {
437  if ($sub["module"] != "n")
438  {
439  if (!($ilSetting->get("obj_dis_creation_".$data)))
440  {
441  $subs[$data] = $sub;
442 
443  // determine position
444  $pos = ($ilSetting->get("obj_add_new_pos_".$data) > 0)
445  ? (int) $ilSetting->get("obj_add_new_pos_".$data)
446  : (int) $this->obj_data[$data]["default_pos"];
447  $subs[$data]["pos"] = $pos;
448  }
449  }
450  }
451 
452  $subs2 = ilUtil::sortArray($subs, "pos", ASC, true, true);
453 
454  return $subs2;
455  }
456 
457  return $subs;
458  }
459 
473  function getSubObjectsRecursively($a_obj_type,$a_include_source_obj = true, $a_add_admin_objects = false)
474  {
475  global $ilSetting;
476 
477  // This associative array is used to collect all subobject types.
478  // key=>type, value=data
479  $recursivesubs = array();
480 
481  // This array is used to keep track of the object types, we
482  // need to call function getSubobjects() for.
483  $to_do = array($a_obj_type);
484 
485  // This array is used to keep track of the object types, we
486  // have called function getSubobjects() already. This is to
487  // prevent endless loops, for object types that support
488  // themselves as subobject types either directly or indirectly.
489  $done = array();
490 
491  while (count($to_do) > 0)
492  {
493  $type = array_pop($to_do);
494  $done[] = $type;
495 
496  // no recovery folder subitems
497  if($type == 'recf')
498  {
499  continue;
500  }
501 
502  // Hide administration if desired
503  if(!$a_add_admin_objects and $type == 'adm')
504  {
505  $subs = array();
506  }
507  else
508  {
509  $subs = $this->getSubObjects($type);
510  }
511  #vd('xxxxxxxxxxxxx'.$type);
512  foreach ($subs as $subtype => $data)
513  {
514  #vd('------------------------->'.$subtype);
515 
516  // Hide role templates and folder from view
517  if($this->getDevMode($subtype) or !$this->isRBACObject($subtype))
518  {
519  continue;
520  }
521  if($subtype == 'rolf' or $subtype == 'rolt')
522  {
523  continue;
524  }
525  if(!$a_add_admin_objects and $subtype == 'adm')
526  {
527  continue;
528  }
529 
530  $recursivesubs[$subtype] = $data;
531  if (! in_array($subtype, $done)
532  && ! in_array($subtype, $to_do))
533  {
534  $to_do[] = $subtype;
535  }
536  }
537  }
538 
539  if($a_include_source_obj)
540  {
541  if(!isset($recursivesubs[$a_obj_type]))
542  {
543  $recursivesubs[$a_obj_type]['name'] = $a_obj_type;
544  $recursivesubs[$a_obj_type]['lng'] = $a_obj_type;
545  $recursivesubs[$a_obj_type]['max'] = 0;
546  $recursivesubs[$a_obj_type]['pos'] = -1;
547  }
548  }
549 
550  return ilUtil::sortArray($recursivesubs, "pos", ASC, true, true);
551  }
552 
553 
563  function getSubobjectsToFilter($a_obj_type = "adm")
564  {
565  foreach($this->obj_data[$a_obj_type]["subobjects"] as $key => $value)
566  {
567  switch($key)
568  {
569  case "rolf":
570  // DO NOTHING
571  break;
572 
573  default:
574  $tmp_subs[] = $key;
575  }
576  }
577  // ADD adm and root object
578  $tmp_subs[] = "adm";
579  #$tmp_subs[] = "root";
580 
581  return $tmp_subs ? $tmp_subs : array();
582  }
583 
591  function getCreatableSubObjects($a_obj_type)
592  {
593  $subobjects = $this->getSubObjects($a_obj_type);
594 
595  // remove role folder object from list
596  unset($subobjects["rolf"]);
597  unset($subobjects['rcrs']);
598 
599  $sub_types = array_keys($subobjects);
600 
601  // remove object types in development from list
602  foreach ($sub_types as $type)
603  {
604 
605  if ($this->getDevMode($type) || $this->isSystemObject($type))
606  {
607  unset($subobjects[$type]);
608  }
609  }
610 
611  return $subobjects;
612  }
613 
620  function getSubObjectsAsString($a_obj_type)
621  {
622  $string = "";
623 
624  if (is_array($this->obj_data[$a_obj_type]["subobjects"]))
625  {
626  $data = array_keys($this->obj_data[$a_obj_type]["subobjects"]);
627 
628  $string = "'".implode("','", $data)."'";
629  }
630 
631  return $string;
632  }
633 
642  public function isContainer($a_obj_name)
643  {
644  if(!is_array($this->obj_data[$a_obj_name]['subobjects']))
645  {
646  return false;
647  }
648  return count($this->obj_data[$a_obj_name]['subobjects']) > 1 ? true : false;
649  }
650 
651 // PRIVATE METHODS
652 
659  function setHandlers($a_xml_parser)
660  {
661  xml_set_object($a_xml_parser,$this);
662  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
663  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
664  }
665 
674  function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
675  {
676  switch ($a_name)
677  {
678  case 'object':
679  $this->parent_tag_name = $a_attribs["name"];
680  break;
681  case 'property':
682  $this->current_tag = "property";
683  $this->current_tag_name = $a_attribs["name"];
684 // $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["name"] = $a_attribs["name"];
685  $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["module"] = $a_attribs["module"];
686 //echo '<br>$this->obj_data["'.$this->parent_tag_name.'"]["properties"]["'.$this->current_tag_name.'"]["module"] = "'.$a_attribs["module"].'";';
687  break;
688  }
689  }
690 
698  function handlerCharacterData($a_xml_parser,$a_data)
699  {
700  }
701 
709  function handlerEndTag($a_xml_parser,$a_name)
710  {
711  $this->current_tag = '';
712  $this->current_tag_name = '';
713  }
714 
715 
716  function __filterObjects(&$subobjects)
717  {
718  foreach($subobjects as $type => $data)
719  {
720  switch($type)
721  {
722 
723  case "icrs":
724  if(!$this->ilias->getSetting("ilinc_active"))
725  {
726  unset($subobjects[$type]);
727  }
728  break;
729 
730  default:
731  // DO NOTHING
732  }
733  }
734  }
735 
749  function isSystemObject($a_obj_name)
750  {
751  return (bool) $this->obj_data[$a_obj_name]["system"];
752  }
753 
760  function isSideBlock($a_obj_name)
761  {
762  return (bool) $this->obj_data[$a_obj_name]["sideblock"];
763  }
764 
768  static function getRepositoryObjectTypesForComponent($a_component_type,
769  $a_component_name)
770  {
771  global $ilDB;
772 
773  $set = $ilDB->queryF("SELECT * FROM il_object_def WHERE component = %s",
774  array("text"), array($a_component_type."/".$a_component_name));
775 
776  $types = array();
777  while($rec = $ilDB->fetchAssoc($set))
778  {
779  if ($rec["system"] != 1)
780  {
781  $types[] = $rec;
782  }
783  }
784 
785  return $types;
786  }
787 
791  static function getComponentForType($a_obj_type)
792  {
793  global $ilDB;
794 
795  $set = $ilDB->queryF("SELECT component FROM il_object_def WHERE id = %s",
796  array("text"), array($a_obj_type));
797 
798  if ($rec = $ilDB->fetchAssoc($set))
799  {
800  return $rec["component"];
801  }
802 
803  return "";
804  }
805 
809  static function getGroupedRepositoryObjectTypes($a_parent_obj_type)
810  {
811  global $ilDB, $ilPluginAdmin;
812 
813  $set = $ilDB->query("SELECT * FROM il_object_group");
814  $groups = array();
815  while ($gr_rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
816  {
817  $groups[$gr_rec["id"]] = $gr_rec;
818  }
819 
820  if (!is_array($a_parent_obj_type))
821  {
822  $set = $ilDB->queryF("SELECT il_object_def.* FROM il_object_def, il_object_subobj ".
823  " WHERE NOT (system = 1) AND NOT (sideblock = 1) AND ".
824  " parent = %s ".
825  " AND subobj = id ", array("text"), array($a_parent_obj_type));
826  }
827  else
828  {
829  $q = "SELECT DISTINCT (id) as sid, il_object_def.* FROM il_object_def, il_object_subobj ".
830  " WHERE NOT (system = 1) AND NOT (sideblock = 1) AND ".
831  $ilDB->in("parent", $a_parent_obj_type, false, "text").
832  " AND subobj = id ";
833  $set = $ilDB->query($q);
834  }
835 
836  $grouped_obj = array();
837  while($rec = $ilDB->fetchAssoc($set))
838  {
839  if ($rec["grp"] != "")
840  {
841  $grouped_obj[$rec["grp"]]["pos"] = (int) $groups[$rec["grp"]]["default_pres_pos"];
842  $grouped_obj[$rec["grp"]]["objs"][] = $rec["id"];
843  }
844  else
845  {
846  $grouped_obj[$rec["id"]]["pos"] = (int) $rec["default_pres_pos"];
847  $grouped_obj[$rec["id"]]["objs"][] = $rec["id"];
848  }
849  }
850 //var_dump($grouped_obj);
851  // now get objects from repository plugin
852  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "Repository", "robj");
853  foreach ($pl_names as $pl_name)
854  {
855  include_once("./Services/Component/classes/class.ilPlugin.php");
856  $pl_id = ilPlugin::lookupIdForName(IL_COMP_SERVICE, "Repository", "robj", $pl_name);
857  if (!isset($grouped_obj[$pl_id]))
858  {
859  $grouped_obj[$pl_id] = array(
860  "pos" => 2000,
861  "objs" => array(0 => $pl_id)
862  );
863  }
864  }
865 
866 //var_dump($grouped_obj);
867 
868  $ret = ilUtil::sortArray($grouped_obj, "pos", "asc", true, true);
869 //var_dump($ret);
870  return $ret;
871  }
872 
873 }
874 ?>