ILIAS  Release_4_0_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  +-----------------------------------------------------------------------------+
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 
35 {
42  var $obj_id;
43 
49  var $parent;
50 
56  var $obj_data;
57 
64  function ilObjectDefinition()
65  {
66  global $ilias;
67 
68  $this->readDefinitionData();
69  $this->ilias = $ilias;
70 
72 
73  // removing this line leads to segmentation faults in
74  // learning module editor with
75  // - PHP 5.2.1, libxml 2.6.22, libxslt 1.1.15 (MacOsX)
76  // - PHP 5.2.1, libxml 2.6.31, libxslt 1.1.22 (MacOsX)
77  // - PHP 5.2.5, libxml 2.6.31, libxslt 1.1.22 (MacOsX)
78  // - PHP 5.2.0-8+etch7, libxml 2.6.27, libxslt 1.1.19
79  // - PHP 5.2.0, libxml, libxml 2.6.26, libxslt 1.1.17 (OpenSuse 10.2)
80  // (needs further investigation)
81  // OK with:
82  // - PHP 5.1.2, libxml 2.6.24, libxslt 1.1.15
83 
84  //
85  // Replacing all "=&" with "=" in xml5compliance seems to solve the problem
86  //
87 
88 // $this->startParsing();
89  }
90 
91 
95  function readDefinitionData()
96  {
97  global $ilDB, $ilPluginAdmin;
98 
99  $this->obj_data = array();
100 
101 
102  // Select all object_definitions and collect the definition id's in
103  // this array.
104  $defIds = array();
105  $set = $ilDB->query("SELECT * FROM il_object_def");
106  while ($rec = $ilDB->fetchAssoc($set))
107  {
108  $this->obj_data[$rec["id"]] = array(
109  "name" => $rec["id"],
110  "class_name" => $rec["class_name"],
111  "location" => $rec["location"],
112  "checkbox" => $rec["checkbox"],
113  "inherit" => $rec["inherit"],
114  "component" => $rec["component"],
115  "translate" => $rec["translate"],
116  "devmode" => $rec["devmode"],
117  "allow_link" => $rec["allow_link"],
118  "allow_copy" => $rec["allow_copy"],
119  "rbac" => $rec["rbac"],
120  "group" => $rec["grp"],
121  "system" => $rec["system"],
122  "default_pos" => $rec["default_pos"],
123  "sideblock" => $rec["sideblock"]);
124  $this->obj_data[$rec["id"]]["subobjects"] = array();
125 
126  $defIds[] = $rec["id"];
127  }
128  // get all subobject definitions in a single query
129  $set2 = $ilDB->query("SELECT * FROM il_object_subobj WHERE ".
130  $ilDB->in('parent', $defIds, false, 'text'));
131  while ($rec2 = $ilDB->fetchAssoc($set2))
132  {
133  $max = $rec2["mmax"];
134  if ($max <= 0) // for backward compliance
135  {
136  $max = "";
137  }
138  $this->obj_data[$rec2["parent"]]["subobjects"][$rec2["subobj"]] = array(
139  "name" => $rec2["subobj"],
140  "max" => $max,
141  "lng" => $rec2["subobj"]
142  );
143  }
144 
145  $set = $ilDB->query("SELECT * FROM il_object_group");
146  $this->obj_group = array();
147  while ($rec = $ilDB->fetchAssoc($set))
148  {
149  $this->obj_group[$rec["id"]] = $rec;
150  }
151 
152  // now get objects from repository plugin
153  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "Repository", "robj");
154  foreach ($pl_names as $pl_name)
155  {
156  include_once("./Services/Component/classes/class.ilPlugin.php");
157  $pl_id = ilPlugin::lookupIdForName(IL_COMP_SERVICE, "Repository", "robj", $pl_name);
158  if ($pl_id != "" && !isset($this->obj_data[$pl_id]))
159  {
160  include_once("./Services/Repository/classes/class.ilRepositoryObjectPlugin.php");
161  $loc = ilPlugin::_getDirectory(IL_COMP_SERVICE, "Repository", "robj",
162  $pl_name)."/classes";
163 
164  $this->obj_data[$pl_id] = array(
165  "name" => $pl_id,
166  "class_name" => $pl_name,
167  "plugin" => "1",
168  "location" => $loc,
169  "checkbox" => "1",
170  "inherit" => "0",
171  "component" => "",
172  "translate" => "0",
173  "devmode" => "0",
174  "allow_link" => "1",
175  "allow_copy" => "0",
176  "rbac" => "1",
177  "group" => null,
178  "system" => "0",
179  "default_pos" => "2000",
180  "sideblock" => "0");
181  $this->obj_data[$rec["id"]]["subobjects"] = array();
182 
183  $this->obj_data["crs"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id);
184  $this->obj_data["grp"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id);
185  $this->obj_data["cat"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id);
186  $this->obj_data["root"]["subobjects"][$pl_id] = array("name" => $pl_id, "max" => "", "lng" => $pl_id);
187  }
188  }
189 //var_dump($this->obj_data["root"]["subobjects"]);
190 //var_dump($this->obj_data2["root"]);
191 
192  }
193 
194 
195 // PUBLIC METHODS
196 
203  function getClassName($a_obj_name)
204  {
205  return $this->obj_data[$a_obj_name]["class_name"];
206  }
207 
208 
215  function getLocation($a_obj_name)
216  {
217  return $this->obj_data[$a_obj_name]["location"];
218  }
219 
223  function getGroup($a_id)
224  {
225  return $this->obj_group[$a_id];
226  }
227 
231  function getGroupOfObj($a_obj_name)
232  {
233  return $this->obj_data[$a_obj_name]["group"];
234  }
235 
242  function hasCheckbox($a_obj_name)
243  {
244  return (bool) $this->obj_data[$a_obj_name]["checkbox"];
245  }
246 
253  function getTranslationType($a_obj_name)
254  {
255  global $ilDB;
256 
257  if ($a_obj_name == "root")
258  {
259  if (!isset($this->root_trans_type))
260  {
261  $q = "SELECT count(obj_id) cnt FROM object_translation WHERE obj_id = ".
262  $ilDB->quote(ROOT_FOLDER_ID,'integer')." ";
263  $set = $ilDB->query($q);
264  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
265  if($rec["cnt"] > 0)
266  {
267  $this->root_trans_type = "db";
268  }
269  else
270  {
271  $this->root_trans_type = $this->obj_data[$a_obj_name]["translate"];
272  }
273  }
274  return $this->root_trans_type;
275  }
276 
277  return $this->obj_data[$a_obj_name]["translate"];
278  }
279 
280 
287  function stopInheritance($a_obj_name)
288  {
289  return (bool) $this->obj_data[$a_obj_name]["inherit"];
290  }
291 
298  function getDevMode($a_obj_name)
299  {
300  return (bool) $this->obj_data[$a_obj_name]["devmode"];
301  }
302 
309  function getDevModeAll()
310  {
311  $types = array_keys($this->obj_data);
312 
313  foreach ($types as $type)
314  {
315  if ($this->getDevMode($type))
316  {
317  $devtypes[] = $type;
318  }
319  }
320 
321  return $devtypes ? $devtypes : array();
322  }
323 
331  function isRBACObject($a_obj_name)
332  {
333  return (bool) $this->obj_data[$a_obj_name]["rbac"];
334  }
335 
343  function isPlugin($a_obj_name)
344  {
345  return (bool) $this->obj_data[$a_obj_name]["plugin"];
346  }
347 
354  function getAllRBACObjects()
355  {
356  $types = array_keys($this->obj_data);
357 
358  foreach ($types as $type)
359  {
360  if ($this->isRBACObject($type))
361  {
362  $rbactypes[] = $type;
363  }
364  }
365 
366  return $rbactypes ? $rbactypes : array();
367  }
368 
375  function getAllObjects()
376  {
377  return array_keys($this->obj_data);
378  }
379 
386  public function allowLink($a_obj_name)
387  {
388  return (bool) $this->obj_data[$a_obj_name]["allow_link"];
389  }
390 
397  public function allowCopy($a_obj_name)
398  {
399  return (bool) $this->obj_data[$a_obj_name]["allow_copy"];
400  }
401 
410  function getSubObjects($a_obj_type,$a_filter = true)
411  {
412  global $ilSetting;
413 
414  $subs = array();
415 
416  if ($subobjects = $this->obj_data[$a_obj_type]["subobjects"])
417  {
418  // Filter some objects e.g chat object are creatable if chat is active
419  if ($a_filter)
420  {
421  $this->__filterObjects($subobjects);
422  }
423 
424  foreach ($subobjects as $data => $sub)
425  {
426  if ($sub["module"] != "n")
427  {
428  if (!($ilSetting->get("obj_dis_creation_".$data)))
429  {
430  $subs[$data] = $sub;
431 
432  // determine position
433  $pos = ($ilSetting->get("obj_add_new_pos_".$data) > 0)
434  ? (int) $ilSetting->get("obj_add_new_pos_".$data)
435  : (int) $this->obj_data[$data]["default_pos"];
436  $subs[$data]["pos"] = $pos;
437  }
438  }
439  }
440 
441  $subs2 = ilUtil::sortArray($subs, "pos", ASC, true, true);
442 
443  return $subs2;
444  }
445 
446  return $subs;
447  }
448 
462  function getSubObjectsRecursively($a_obj_type)
463  {
464  // This associative array is used to collect all subobject types.
465  // key=>type, value=data
466  $recursivesubs = array();
467 
468  // This array is used to keep track of the object types, we
469  // need to call function getSubobjects() for.
470  $to_do = array($a_obj_type);
471 
472  // This array is used to keep track of the object types, we
473  // have called function getSubobjects() already. This is to
474  // prevent endless loops, for object types that support
475  // themselves as subobject types either directly or indirectly.
476  $done = array();
477 
478  while (count($to_do) > 0)
479  {
480  $type = array_pop($to_do);
481  $done[] = $type;
482  $subs = $this->getSubObjects($type);
483  foreach ($subs as $subtype => $data)
484  {
485  $recursivesubs[$subtype] = $data;
486  if (! in_array($subtype, $done)
487  && ! in_array($subtype, $to_do))
488  {
489  $to_do[] = $subtype;
490  }
491  }
492  }
493 
494  return $recursivesubs;
495  }
496 
506  function getSubobjectsToFilter($a_obj_type = "adm")
507  {
508  foreach($this->obj_data[$a_obj_type]["subobjects"] as $key => $value)
509  {
510  switch($key)
511  {
512  case "rolf":
513  // DO NOTHING
514  break;
515 
516  default:
517  $tmp_subs[] = $key;
518  }
519  }
520  // ADD adm and root object
521  $tmp_subs[] = "adm";
522  #$tmp_subs[] = "root";
523 
524  return $tmp_subs ? $tmp_subs : array();
525  }
526 
534  function getCreatableSubObjects($a_obj_type)
535  {
536  $subobjects = $this->getSubObjects($a_obj_type);
537 
538  // remove role folder object from list
539  unset($subobjects["rolf"]);
540  unset($subobjects['rcrs']);
541 
542  $sub_types = array_keys($subobjects);
543 
544  // remove object types in development from list
545  foreach ($sub_types as $type)
546  {
547 
548  if ($this->getDevMode($type) || $this->isSystemObject($type))
549  {
550  unset($subobjects[$type]);
551  }
552  }
553 
554  return $subobjects;
555  }
556 
563  function getSubObjectsAsString($a_obj_type)
564  {
565  $string = "";
566 
567  if (is_array($this->obj_data[$a_obj_type]["subobjects"]))
568  {
569  $data = array_keys($this->obj_data[$a_obj_type]["subobjects"]);
570 
571  $string = "'".implode("','", $data)."'";
572  }
573 
574  return $string;
575  }
576 
585  public function isContainer($a_obj_name)
586  {
587  if(!is_array($this->obj_data[$a_obj_name]['subobjects']))
588  {
589  return false;
590  }
591  return count($this->obj_data[$a_obj_name]['subobjects']) > 1 ? true : false;
592  }
593 
594 // PRIVATE METHODS
595 
602  function setHandlers($a_xml_parser)
603  {
604  xml_set_object($a_xml_parser,$this);
605  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
606  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
607  }
608 
617  function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
618  {
619  switch ($a_name)
620  {
621  case 'object':
622  $this->parent_tag_name = $a_attribs["name"];
623  break;
624  case 'property':
625  $this->current_tag = "property";
626  $this->current_tag_name = $a_attribs["name"];
627 // $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["name"] = $a_attribs["name"];
628  $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["module"] = $a_attribs["module"];
629 //echo '<br>$this->obj_data["'.$this->parent_tag_name.'"]["properties"]["'.$this->current_tag_name.'"]["module"] = "'.$a_attribs["module"].'";';
630  break;
631  }
632  }
633 
641  function handlerCharacterData($a_xml_parser,$a_data)
642  {
643  }
644 
652  function handlerEndTag($a_xml_parser,$a_name)
653  {
654  $this->current_tag = '';
655  $this->current_tag_name = '';
656  }
657 
658 
659  function __filterObjects(&$subobjects)
660  {
661  foreach($subobjects as $type => $data)
662  {
663  switch($type)
664  {
665  case "chat":
666  if(!$this->ilias->getSetting("chat_active"))
667  {
668  unset($subobjects[$type]);
669  }
670  break;
671 
672  case "icrs":
673  if(!$this->ilias->getSetting("ilinc_active"))
674  {
675  unset($subobjects[$type]);
676  }
677  break;
678 
679  default:
680  // DO NOTHING
681  }
682  }
683  }
684 
698  function isSystemObject($a_obj_name)
699  {
700  return (bool) $this->obj_data[$a_obj_name]["system"];
701  }
702 
709  function isSideBlock($a_obj_name)
710  {
711  return (bool) $this->obj_data[$a_obj_name]["sideblock"];
712  }
713 
717  static function getRepositoryObjectTypesForComponent($a_component_type,
718  $a_component_name)
719  {
720  global $ilDB;
721 
722  $set = $ilDB->queryF("SELECT * FROM il_object_def WHERE component = %s",
723  array("text"), array($a_component_type."/".$a_component_name));
724 
725  $types = array();
726  while($rec = $ilDB->fetchAssoc($set))
727  {
728  if ($rec["system"] != 1)
729  {
730  $types[] = $rec;
731  }
732  }
733 
734  return $types;
735  }
736 
740  static function getGroupedRepositoryObjectTypes($a_parent_obj_type)
741  {
742  global $ilDB, $ilPluginAdmin;
743 
744  $set = $ilDB->query("SELECT * FROM il_object_group");
745  $groups = array();
746  while ($gr_rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
747  {
748  $groups[$gr_rec["id"]] = $gr_rec;
749  }
750 
751  if (!is_array($a_parent_obj_type))
752  {
753  $set = $ilDB->queryF("SELECT il_object_def.* FROM il_object_def, il_object_subobj ".
754  " WHERE NOT (system = 1) AND NOT (sideblock = 1) AND ".
755  " parent = %s ".
756  " AND subobj = id ", array("text"), array($a_parent_obj_type));
757  }
758  else
759  {
760  $q = "SELECT DISTINCT (id) as sid, il_object_def.* FROM il_object_def, il_object_subobj ".
761  " WHERE NOT (system = 1) AND NOT (sideblock = 1) AND ".
762  $ilDB->in("parent", $a_parent_obj_type, false, "text").
763  " AND subobj = id ";
764  $set = $ilDB->query($q);
765  }
766 
767  $grouped_obj = array();
768  while($rec = $ilDB->fetchAssoc($set))
769  {
770  if ($rec["grp"] != "")
771  {
772  $grouped_obj[$rec["grp"]]["pos"] = (int) $groups[$rec["grp"]]["default_pres_pos"];
773  $grouped_obj[$rec["grp"]]["objs"][] = $rec["id"];
774  }
775  else
776  {
777  $grouped_obj[$rec["id"]]["pos"] = (int) $rec["default_pres_pos"];
778  $grouped_obj[$rec["id"]]["objs"][] = $rec["id"];
779  }
780  }
781 //var_dump($grouped_obj);
782  // now get objects from repository plugin
783  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "Repository", "robj");
784  foreach ($pl_names as $pl_name)
785  {
786  include_once("./Services/Component/classes/class.ilPlugin.php");
787  $pl_id = ilPlugin::lookupIdForName(IL_COMP_SERVICE, "Repository", "robj", $pl_name);
788  if (!isset($grouped_obj[$pl_id]))
789  {
790  $grouped_obj[$pl_id] = array(
791  "pos" => 2000,
792  "objs" => array(0 => $pl_id)
793  );
794  }
795  }
796 
797 //var_dump($grouped_obj);
798 
799  $ret = ilUtil::sortArray($grouped_obj, "pos", "asc", true, true);
800 //var_dump($ret);
801  return $ret;
802  }
803 
804 }
805 ?>