ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjectDefinition.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
34 //class ilObjectDefinition extends ilSaxParser
36 {
43  var $obj_id;
44 
50  var $parent;
51 
57  var $obj_data;
58 
65  function ilObjectDefinition()
66  {
67  global $ilias;
68 
69  $this->readDefinitionData();
70  $this->ilias = $ilias;
71 
73 
74  // removing this line leads to segmentation faults in
75  // learning module editor with
76  // - PHP 5.2.1, libxml 2.6.22, libxslt 1.1.15 (MacOsX)
77  // - PHP 5.2.1, libxml 2.6.31, libxslt 1.1.22 (MacOsX)
78  // - PHP 5.2.5, libxml 2.6.31, libxslt 1.1.22 (MacOsX)
79  // - PHP 5.2.0-8+etch7, libxml 2.6.27, libxslt 1.1.19
80  // - PHP 5.2.0, libxml, libxml 2.6.26, libxslt 1.1.17 (OpenSuse 10.2)
81  // (needs further investigation)
82  // OK with:
83  // - PHP 5.1.2, libxml 2.6.24, libxslt 1.1.15
84 
85  //
86  // Replacing all "=&" with "=" in xml5compliance seems to solve the problem
87  //
88 
89 // $this->startParsing();
90  }
91 
92 
93 /*
94  function startParsing()
95  {
96  global $ilDB;
97 
98  $ret = parent::startParsing();
99 
100  // checked:
101  // - location: ok
102  // - class_name: ok
103  // - checkbox: ok
104  // - inherit: ok
105  // - translate: ok
106  // - devmode: ok
107  // - allow_link: ok
108  // - allow_copy: ok
109  // - rbac: ok
110  // - system: ok
111  // - sideblock: ok
112  // - subobj/max: ok
113 
114  return $ret;
115  }
116 */
117 
122  {
123  global $ilDB;
124 
125  $this->obj_data = array();
126 
127 
128  // Select all object_definitions and collect the definition id's in
129  // this array.
130  $defIds = array();
131  $set = $ilDB->query("SELECT * FROM il_object_def");
132  while ($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
133  {
134  $this->obj_data[$rec["id"]] = array(
135  "name" => $rec["id"],
136  "class_name" => $rec["class_name"],
137  "location" => $rec["location"],
138  "checkbox" => $rec["checkbox"],
139  "inherit" => $rec["inherit"],
140  "component" => $rec["component"],
141  "translate" => $rec["translate"],
142  "devmode" => $rec["devmode"],
143  "allow_link" => $rec["allow_link"],
144  "allow_copy" => $rec["allow_copy"],
145  "rbac" => $rec["rbac"],
146  "group" => $rec["grp"],
147  "system" => $rec["system"],
148  "default_pos" => $rec["default_pos"],
149  "sideblock" => $rec["sideblock"]);
150  $this->obj_data[$rec["id"]]["subobjects"] = array();
151 
152  $defIds[] = $rec["id"];
153  }
154  // get all subobject definitions in a single query
155  $set2 = $ilDB->query("SELECT * FROM il_object_subobj WHERE ".
156  "parent IN ('".implode("','",$defIds)."')");
157  while ($rec2 = $set2->fetchRow(DB_FETCHMODE_ASSOC))
158  {
159  $max = $rec2["max"];
160  if ($max <= 0) // for backward compliance
161  {
162  $max = "";
163  }
164  $this->obj_data[$rec2["parent"]]["subobjects"][$rec2["subobj"]] = array(
165  "name" => $rec2["subobj"],
166  "max" => $max,
167  "lng" => $rec2["subobj"]
168  );
169  }
170 
171  $set = $ilDB->query("SELECT * FROM il_object_group");
172  $this->obj_group = array();
173  while ($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
174  {
175  $this->obj_group[$rec["id"]] = $rec;
176  }
177 
178 //var_dump($this->obj_data["root"]);
179 //var_dump($this->obj_data2["root"]);
180 
181  }
182 
183 
184 // PUBLIC METHODS
185 
192 /* Deprecated, use more specialized functions instead
193  function getDefinition($a_obj_name)
194  {
195  return $this->obj_data[$a_obj_name];
196  }
197 */
198 
205  function getClassName($a_obj_name)
206  {
207  return $this->obj_data[$a_obj_name]["class_name"];
208  }
209 
210 
217  function getLocation($a_obj_name)
218  {
219  return $this->obj_data[$a_obj_name]["location"];
220  }
221 
222 
229 /* Deprecated, use getLocation instead
230  function getModule($a_obj_name)
231  {
232  return $this->obj_data[$a_obj_name]["module"];
233  }
234 */
235 
239  function getGroup($a_id)
240  {
241  return $this->obj_group[$a_id];
242  }
243 
247  function getGroupOfObj($a_obj_name)
248  {
249  return $this->obj_data[$a_obj_name]["group"];
250  }
251 
258  function hasCheckbox($a_obj_name)
259  {
260  return (bool) $this->obj_data[$a_obj_name]["checkbox"];
261  }
262 
269  function getTranslationType($a_obj_name)
270  {
271  global $ilDB;
272 
273  if ($a_obj_name == "root")
274  {
275  if (!isset($this->root_trans_type))
276  {
277  $q = "SELECT count(*) as cnt FROM object_translation WHERE obj_id = ".
278  $ilDB->quote(ROOT_FOLDER_ID);
279  $set = $ilDB->query($q);
280  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
281  if($rec["cnt"] > 0)
282  {
283  $this->root_trans_type = "db";
284  }
285  else
286  {
287  $this->root_trans_type = $this->obj_data[$a_obj_name]["translate"];
288  }
289  }
290  return $this->root_trans_type;
291  }
292 
293  return $this->obj_data[$a_obj_name]["translate"];
294  }
295 
296 
303  function stopInheritance($a_obj_name)
304  {
305  return (bool) $this->obj_data[$a_obj_name]["inherit"];
306  }
307 
314 /* Deprecated
315  function getProperties($a_obj_name)
316  {
317  // dirty hack, has to be implemented better, if ilias.php
318  // is established
319  if (defined("ILIAS_MODULE") || $_GET["baseClass"] != "")
320  {
321  $props = array();
322  if (is_array($this->obj_data[$a_obj_name]["properties"]))
323  {
324  foreach ($this->obj_data[$a_obj_name]["properties"] as $data => $prop)
325  {
326  if ($prop["module"] != "n")
327  {
328  $props[$data] = $prop;
329  }
330  }
331  }
332  return $props;
333  }
334  else
335  {
336  $props = array();
337  if (is_array($this->obj_data[$a_obj_name]["properties"]))
338  {
339  foreach ($this->obj_data[$a_obj_name]["properties"] as $data => $prop)
340  {
341  if ($prop["module"] != 1)
342  {
343  $props[$data] = $prop;
344  }
345  }
346  }
347  return $props;
348  }
349  }
350 */
351 
358  function getDevMode($a_obj_name)
359  {
360  return (bool) $this->obj_data[$a_obj_name]["devmode"];
361  }
362 
369  function getDevModeAll()
370  {
371  $types = array_keys($this->obj_data);
372 
373  foreach ($types as $type)
374  {
375  if ($this->getDevMode($type))
376  {
377  $devtypes[] = $type;
378  }
379  }
380 
381  return $devtypes ? $devtypes : array();
382  }
383 
391  function isRBACObject($a_obj_name)
392  {
393  return (bool) $this->obj_data[$a_obj_name]["rbac"];
394  }
395 
402  function getAllRBACObjects()
403  {
404  $types = array_keys($this->obj_data);
405 
406  foreach ($types as $type)
407  {
408  if ($this->isRBACObject($type))
409  {
410  $rbactypes[] = $type;
411  }
412  }
413 
414  return $rbactypes ? $rbactypes : array();
415  }
416 
423  function getAllObjects()
424  {
425  return array_keys($this->obj_data);
426  }
427 
434  function allowLink($a_obj_name)
435  {
436  return (bool) $this->obj_data[$a_obj_name]["allow_link"];
437  }
438 
445  function allowCopy($a_obj_name)
446  {
447  return (bool) $this->obj_data[$a_obj_name]["allow_copy"];
448  }
449 
457  public function getContentItemSortingModes($a_obj_name)
458  {
459  if(isset($this->obj_data[$a_obj_name]['sorting']))
460  {
461  return $this->obj_data[$a_obj_name]['sorting']['modes'] ? $this->obj_data[$a_obj_name]['sorting']['modes'] : array();
462  }
463  return array();
464  }
465 
466 
475  function getSubObjects($a_obj_type,$a_filter = true)
476  {
477  global $ilSetting;
478 
479  $subs = array();
480 
481  if ($subobjects = $this->obj_data[$a_obj_type]["subobjects"])
482  {
483  // Filter some objects e.g chat object are creatable if chat is active
484  if ($a_filter)
485  {
486  $this->__filterObjects($subobjects);
487  }
488 
489  foreach ($subobjects as $data => $sub)
490  {
491  if ($sub["module"] != "n")
492  {
493  if (!($ilSetting->get("obj_dis_creation_".$data)))
494  {
495  $subs[$data] = $sub;
496 
497  // determine position
498  $pos = ($ilSetting->get("obj_add_new_pos_".$data) > 0)
499  ? (int) $ilSetting->get("obj_add_new_pos_".$data)
500  : (int) $this->obj_data[$data]["default_pos"];
501  $subs[$data]["pos"] = $pos;
502  }
503  }
504  }
505 
506  $subs2 = ilUtil::sortArray($subs, "pos", ASC, true, true);
507 
508  return $subs2;
509  }
510 
511  return $subs;
512  }
513 
527  function getSubObjectsRecursively($a_obj_type)
528  {
529  // This associative array is used to collect all subobject types.
530  // key=>type, value=data
531  $recursivesubs = array();
532 
533  // This array is used to keep track of the object types, we
534  // need to call function getSubobjects() for.
535  $to_do = array($a_obj_type);
536 
537  // This array is used to keep track of the object types, we
538  // have called function getSubobjects() already. This is to
539  // prevent endless loops, for object types that support
540  // themselves as subobject types either directly or indirectly.
541  $done = array();
542 
543  while (count($to_do) > 0)
544  {
545  $type = array_pop($to_do);
546  $done[] = $type;
547  $subs = $this->getSubObjects($type);
548  foreach ($subs as $subtype => $data)
549  {
550  $recursivesubs[$subtype] = $data;
551  if (! in_array($subtype, $done)
552  && ! in_array($subtype, $to_do))
553  {
554  $to_do[] = $subtype;
555  }
556  }
557  }
558 
559  return $recursivesubs;
560  }
561 
571  function getSubobjectsToFilter($a_obj_type = "adm")
572  {
573  foreach($this->obj_data[$a_obj_type]["subobjects"] as $key => $value)
574  {
575  switch($key)
576  {
577  case "rolf":
578  // DO NOTHING
579  break;
580 
581  default:
582  $tmp_subs[] = $key;
583  }
584  }
585  // ADD adm and root object
586  $tmp_subs[] = "adm";
587  #$tmp_subs[] = "root";
588 
589  return $tmp_subs ? $tmp_subs : array();
590  }
591 
599  function getCreatableSubObjects($a_obj_type)
600  {
601  $subobjects = $this->getSubObjects($a_obj_type);
602 
603  // remove role folder object from list
604  unset($subobjects["rolf"]);
605  unset($subobjects['rcrs']);
606 
607  $sub_types = array_keys($subobjects);
608 
609  // remove object types in development from list
610  foreach ($sub_types as $type)
611  {
612 
613  if ($this->getDevMode($type) || $this->isSystemObject($type))
614  {
615  unset($subobjects[$type]);
616  }
617  }
618 
619  return $subobjects;
620  }
621 
622 /* function getCreatableObjectTypes()
623  {
624  $s1 = $this->getSubObjects("cat");
625  $s2 = $this->getSubObjects("grp");
626  $s3 = $this->getSubObjects("fold");
627 
628 //var_dump($s1);
629 //var_dump($s2);
630  }
631 */
638 /* Deprecated, derive from ilObjectGUI->getActions() instead
639  function getActions($a_obj_name)
640  {
641  $ret = (is_array($this->obj_data[$a_obj_name]["actions"])) ?
642  $this->obj_data[$a_obj_name]["actions"] :
643  array();
644  return $ret;
645  }
646 */
647 
654 /* Deprecated
655  function getFirstProperty($a_obj_name)
656  {
657  if (defined("ILIAS_MODULE"))
658  {
659  foreach ($this->obj_data[$a_obj_name]["properties"] as $data => $prop)
660  {
661  if($prop["module"] != "n")
662  {
663  return $data;
664  }
665  }
666  }
667  else
668  {
669  foreach ($this->obj_data[$a_obj_name]["properties"] as $data => $prop)
670  {
671  if ($prop["module"] != 1)
672  {
673  return $data;
674  }
675  }
676  }
677  }
678 */
679 
686 /* Deprecated
687  function getPropertyName($a_cmd, $a_obj_name)
688  {
689  return $this->obj_data[$a_obj_name]["properties"][$a_cmd]["lng"];
690  }
691 */
692 
699  function getSubObjectsAsString($a_obj_type)
700  {
701  $string = "";
702 
703  if (is_array($this->obj_data[$a_obj_type]["subobjects"]))
704  {
705  $data = array_keys($this->obj_data[$a_obj_type]["subobjects"]);
706 
707  $string = "'".implode("','", $data)."'";
708  }
709 
710  return $string;
711  }
712 
719 /* Deprecated
720  function getImportObjects($a_obj_type)
721  {
722  $imp = array();
723 
724  if (is_array($this->obj_data[$a_obj_type]["subobjects"]))
725  {
726  foreach ($this->obj_data[$a_obj_type]["subobjects"] as $sub)
727  {
728  if ($sub["import"] == 1)
729  {
730  $imp[] = $sub["name"];
731  }
732  }
733  }
734 
735  return $imp;
736  }
737 */
738 
747  public function isContainer($a_obj_name)
748  {
749  if(!is_array($this->obj_data[$a_obj_name]['subobjects']))
750  {
751  return false;
752  }
753  return count($this->obj_data[$a_obj_name]['subobjects']) > 1 ? true : false;
754  }
755 
756 // PRIVATE METHODS
757 
764  function setHandlers($a_xml_parser)
765  {
766  xml_set_object($a_xml_parser,$this);
767  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
768  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
769  }
770 
779  function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
780  {
781  switch ($a_name)
782  {
783  case 'object':
784  $this->parent_tag_name = $a_attribs["name"];
785  break;
786  case 'property':
787  $this->current_tag = "property";
788  $this->current_tag_name = $a_attribs["name"];
789 // $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["name"] = $a_attribs["name"];
790  $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["module"] = $a_attribs["module"];
791 //echo '<br>$this->obj_data["'.$this->parent_tag_name.'"]["properties"]["'.$this->current_tag_name.'"]["module"] = "'.$a_attribs["module"].'";';
792  break;
793  }
794  }
795 
803  function handlerCharacterData($a_xml_parser,$a_data)
804  {
805  }
806 
814  function handlerEndTag($a_xml_parser,$a_name)
815  {
816  $this->current_tag = '';
817  $this->current_tag_name = '';
818  }
819 
820 
821  function __filterObjects(&$subobjects)
822  {
823  foreach($subobjects as $type => $data)
824  {
825  switch($type)
826  {
827  case "chat":
828  if(!$this->ilias->getSetting("chat_active"))
829  {
830  unset($subobjects[$type]);
831  }
832  break;
833 
834  case "icrs":
835  if(!$this->ilias->getSetting("ilinc_active"))
836  {
837  unset($subobjects[$type]);
838  }
839  break;
840 
841  default:
842  // DO NOTHING
843  }
844  }
845  }
846 
860  function isSystemObject($a_obj_name)
861  {
862  return (bool) $this->obj_data[$a_obj_name]["system"];
863  }
864 
871  function isSideBlock($a_obj_name)
872  {
873  return (bool) $this->obj_data[$a_obj_name]["sideblock"];
874  }
875 
879  static function getRepositoryObjectTypesForComponent($a_component_type,
880  $a_component_name)
881  {
882  global $ilDB;
883 
884  $set = $ilDB->query("SELECT * FROM il_object_def WHERE component = ".
885  $ilDB->quote($a_component_type."/".$a_component_name));
886 
887  $types = array();
888  while($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
889  {
890  if ($rec["system"] != 1)
891  {
892  $types[] = $rec;
893  }
894  }
895 
896  return $types;
897  }
898 
902  static function getGroupedRepositoryObjectTypes($a_parent_obj_type)
903  {
904  global $ilDB;
905 
906  $set = $ilDB->query("SELECT * FROM il_object_group");
907  $groups = array();
908  while ($gr_rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
909  {
910  $groups[$gr_rec["id"]] = $gr_rec;
911  }
912 
913  if (!is_array($a_parent_obj_type))
914  {
915  $set = $ilDB->query("SELECT il_object_def.* FROM il_object_def, il_object_subobj ".
916  " WHERE NOT (system = 1) AND NOT (sideblock = 1) AND ".
917  " parent = ".$ilDB->quote($a_parent_obj_type).
918  " AND subobj = id ");
919  }
920  else
921  {
922  $set = $ilDB->query("SELECT DISTINCT (id) as sid, il_object_def.* FROM il_object_def, il_object_subobj ".
923  " WHERE NOT (system = 1) AND NOT (sideblock = 1) AND ".
924  " parent IN (".implode(",",ilUtil::quoteArray($a_parent_obj_type)).") ".
925  " AND subobj = id ");
926  }
927 
928  $grouped_obj = array();
929  while($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
930  {
931  if ($rec["grp"] != "")
932  {
933  $grouped_obj[$rec["grp"]]["pos"] = (int) $groups[$rec["grp"]]["default_pres_pos"];
934  $grouped_obj[$rec["grp"]]["objs"][] = $rec["id"];
935  }
936  else
937  {
938  $grouped_obj[$rec["id"]]["pos"] = (int) $rec["default_pres_pos"];
939  $grouped_obj[$rec["id"]]["objs"][] = $rec["id"];
940  }
941  }
942 //var_dump($grouped_obj);
943  $ret = ilUtil::sortArray($grouped_obj, "pos", "asc", true, true);
944 //var_dump($ret);
945  return $ret;
946  }
947 
948 }
949 ?>