ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilOrgUnitGlobalSettings.php
Go to the documentation of this file.
1 <?php
19 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
20 
26 {
27  private static ?ilOrgUnitGlobalSettings $instance = null;
30  private array $position_settings = [];
35  private array $object_position_cache = [];
36 
37  private function __construct()
38  {
39  $this->object_definition = $GLOBALS['DIC']['objDefinition'];
40  $this->readSettings();
41  }
42 
43  public static function getInstance(): self
44  {
45  if (!self::$instance) {
46  self::$instance = new self();
47  }
48 
49  return self::$instance;
50  }
51 
53  {
54  if (!isset($this->position_settings[$a_obj_type])) {
55  throw new \InvalidArgumentException('Object type passed does not support position settings: '
56  . $a_obj_type);
57  }
58 
59  return $this->position_settings[$a_obj_type];
60  }
61 
65  public function isPositionAccessActiveForObject(int $a_obj_id): bool
66  {
67  if (isset($this->object_position_cache[$a_obj_id])) {
68  return $this->object_position_cache[$a_obj_id];
69  }
70  $type = ilObject::_lookupType($a_obj_id);
71  try {
72  $type_settings = $this->getObjectPositionSettingsByType($type);
73  } catch (\InvalidArgumentException $invalid_type_exception) {
74  $this->object_position_cache[$a_obj_id] = false;
75 
76  return false;
77  }
78 
79  if (!$type_settings->isActive()) {
80  $this->object_position_cache[$a_obj_id] = false;
81 
82  return false;
83  }
84  if (!$type_settings->isChangeableForObject()) {
85  $this->object_position_cache[$a_obj_id] = true;
86 
87  return true;
88  }
89  $object_position = new ilOrgUnitObjectPositionSetting($a_obj_id);
90 
91  if ($object_position->hasObjectSpecificActivation()) {
92  $this->object_position_cache[$a_obj_id] = $object_position->isActive();
93  } else {
94  $this->object_position_cache[$a_obj_id] = (bool) $type_settings->getActivationDefault();
95  }
96 
97  return $this->object_position_cache[$a_obj_id];
98  }
99 
104  public function saveDefaultPositionActivationStatus(int $a_obj_id): void
105  {
106  $type = ilObject::_lookupType($a_obj_id);
107  try {
108  $type_settings = $this->getObjectPositionSettingsByType($type);
109  } catch (\InvalidArgumentException $ex) {
110  return;
111  }
112  if ($type_settings->isActive()) {
113  $object_setting = new ilOrgUnitObjectTypePositionSetting($a_obj_id);
114  $object_setting->setActive($type_settings->getActivationDefault());
115  $object_setting->update();
116  }
117  }
118 
119  private function readSettings(): void
120  {
121  foreach ($this->object_definition->getOrgUnitPermissionTypes() as $type) {
122  $this->position_settings[$type] = new ilOrgUnitObjectTypePositionSetting($type);
123  }
124  }
125 
129  public function getPositionSettings(): array
130  {
132  }
133 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$type
isPositionAccessActiveForObject(int $a_obj_id)
Check of position access is activate for object.
static ilOrgUnitGlobalSettings $instance
parses the objects.xml it handles the xml-description of all ilias objects
getObjectPositionSettingsByType(string $a_obj_type)
array $object_position_cache
Array with key obj_id => active status.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
saveDefaultPositionActivationStatus(int $a_obj_id)
Set and save the default activation status according to settings.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...