ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilOrgUnitGlobalSettings.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 
12 {
13 
17  private static $instance = null;
21  protected $object_definition = null;
25  private $position_settings = [];
31  private $object_position_cache = [];
32 
33 
37  protected function __construct()
38  {
39  $this->object_definition = $GLOBALS['DIC']['objDefinition'];
40  $this->readSettings();
41  }
42 
43 
49  public static function getInstance()
50  {
51  if (!self::$instance) {
52  self::$instance = new self();
53  }
54 
55  return self::$instance;
56  }
57 
58 
67  public function getObjectPositionSettingsByType($a_obj_type)
68  {
69  if (!isset($this->position_settings[$a_obj_type])) {
70  throw new \InvalidArgumentException('Object type passed does not support position settings: '
71  . $a_obj_type);
72  }
73 
74  return $this->position_settings[$a_obj_type];
75  }
76 
77 
85  public function isPositionAccessActiveForObject($a_obj_id)
86  {
87  if (isset($this->object_position_cache[$a_obj_id])) {
88  return $this->object_position_cache[$a_obj_id];
89  }
90  $type = ilObject::_lookupType($a_obj_id);
91  try {
92  $type_settings = $this->getObjectPositionSettingsByType($type);
93  } catch (\InvalidArgumentException $invalid_type_exception) {
94  $this->object_position_cache[$a_obj_id] = false;
95 
96  return false;
97  }
98 
99  if (!$type_settings->isActive()) {
100  $this->object_position_cache[$a_obj_id] = false;
101 
102  return false;
103  }
104  if (!$type_settings->isChangeableForObject()) {
105  $this->object_position_cache[$a_obj_id] = true;
106 
107  return true;
108  }
109  $object_position = new ilOrgUnitObjectPositionSetting($a_obj_id);
110 
111  if ($object_position->hasObjectSpecificActivation()) {
112  $this->object_position_cache[$a_obj_id] = $object_position->isActive();
113  } else {
114  $this->object_position_cache[$a_obj_id] = (bool) $type_settings->getActivationDefault();
115  }
116 
117  return $this->object_position_cache[$a_obj_id];
118  }
119 
120 
126  public function saveDefaultPositionActivationStatus($a_obj_id)
127  {
128  $type = ilObject::_lookupType($a_obj_id);
129  try {
130  $type_settings = $this->getObjectPositionSettingsByType($type);
131  } catch (\InvalidArgumentException $ex) {
132  return;
133  }
134  if ($type_settings->isActive()) {
135  $object_setting = new ilOrgUnitObjectTypePositionSetting($a_obj_id);
136  $object_setting->setActive($type_settings->getActivationDefault());
137  $object_setting->update();
138  }
139 
140  return;
141  }
142 
143 
147  protected function readSettings()
148  {
149  foreach ($this->object_definition->getOrgUnitPermissionTypes() as $type) {
150  $this->position_settings[$type] = new ilOrgUnitObjectTypePositionSetting($type);
151  }
152  }
153 
154 
158  public function getPositionSettings()
159  {
161  }
162 }
Stores object activation status of orgunit position settings.
__construct()
Singelton constructor.
$type
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
saveDefaultPositionActivationStatus($a_obj_id)
Set and save the default activation status according to settings.
static _lookupType($a_id, $a_reference=false)
lookup object type
getObjectPositionSettingsByType($a_obj_type)
Get object position settings by type.
isPositionAccessActiveForObject($a_obj_id)
Check of position access is activate for object.
Object settings regarding position permissions.
Global settings for org units.