ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ObjectManager.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
26 use ilSetting;
27 use ilObject;
28 use ilObjStyleSheet;
29 use ilObjectFactory;
30 
36 {
37  protected \ilLogger $log;
38  protected ilSetting $settings;
40  protected int $obj_id;
42  protected int $ref_id;
45 
46  public function __construct(
47  InternalRepoService $repo_service,
48  InternalDomainService $domain_service,
49  int $ref_id,
50  int $obj_id = 0
51  ) {
52  $this->settings = $domain_service->settings();
53  $this->ref_id = $ref_id;
54  $this->obj_id = ($obj_id > 0)
55  ? $obj_id
56  : ilObject::_lookupObjId($ref_id);
57  $this->repo_service = $repo_service;
58  $this->domain_service = $domain_service;
59  $this->container_repo = $repo_service->repositoryContainer();
60  $this->object_repo = $repo_service->object();
61  $this->log = $this->domain_service->log();
62  }
63 
69  public function getSelectableStyles(): array
70  {
71  $settings = $this->settings;
72  $tree = $this->domain_service->repositoryTree();
73  $container_repo = $this->container_repo;
74 
75  $fixed_style = $settings->get("fixed_content_style_id");
76  if ($fixed_style > 0) {
77  return [];
78  } else {
80  true,
81  false,
82  $this->ref_id
83  );
84 
85  if ($this->ref_id > 0) {
86  $path = $tree->getPathId($this->ref_id);
87  $reuse_ref_ids = $container_repo->filterByReuse($path);
88  $container_obj_ids = array_map(function ($ref_id) {
89  return ilObject::_lookupObjId($ref_id);
90  }, $reuse_ref_ids);
91  foreach ($this->object_repo->getOwnedStyles($container_obj_ids) as $obj_id => $style_id) {
92  $st_styles[$style_id] =
93  ilObject::_lookupTitle($style_id) .
94  " (" . ilObject::_lookupTitle($obj_id) . ")";
95  }
96  }
97  }
98  ksort($st_styles);
99  return $st_styles;
100  }
101 
102  protected function isSelectable(int $style_id): bool
103  {
104  $sel_types = $this->getSelectableStyles();
105  if (isset($sel_types[$style_id])) {
106  return true;
107  }
108  return false;
109  }
110 
111  public function updateStyleId(int $style_id): void
112  {
113  ilObjStyleSheet::writeStyleUsage($this->obj_id, $style_id);
114  }
115 
116  public function setOwnerOfStyle(int $style_id): void
117  {
118  ilObjStyleSheet::writeOwner($this->obj_id, $style_id);
119  }
120 
121  public function getStyleId(): int
122  {
123  return ilObjStyleSheet::lookupObjectStyle($this->obj_id);
124  }
125 
129  public function cloneTo(int $obj_id): void
130  {
131  $this->log->debug("Cloning style from ref id: " . $this->ref_id .
132  ", obj id: " . $this->obj_id . ", style id: " . $this->getStyleId() . ", to new obj id: " .
133  $obj_id);
134  $style_id = $this->getStyleId();
135  if ($style_id > 0 && !ilObjStyleSheet::_lookupStandard($style_id)) {
136  $style_obj = ilObjectFactory::getInstanceByObjId($style_id);
137  $new_id = $style_obj->ilClone();
138  ilObjStyleSheet::writeStyleUsage($obj_id, $new_id);
139  ilObjStyleSheet::writeOwner($obj_id, $new_id);
140  } else {
141  ilObjStyleSheet::writeStyleUsage($obj_id, $style_id);
142  }
143  }
144 
148  public function inheritFromParent(): void
149  {
150  if ($this->ref_id > 0) {
151  $tree = $this->domain_service->repositoryTree();
152  $parent_ref_id = $tree->getParentId($this->ref_id);
153  $parent_id = ilObject::_lookupObjId((int) $parent_ref_id);
154  $obj_id = ilObject::_lookupObjId($this->ref_id);
155  $style_id = ilObjStyleSheet::lookupObjectStyle($parent_id);
156  if ($style_id > 0) {
157  if (ilObjStyleSheet::_lookupStandard($style_id)) {
158  ilObjStyleSheet::writeStyleUsage($obj_id, $style_id);
159  }
160  }
161  }
162  }
163 
164  public function getEffectiveStyleId(): int
165  {
166  $settings = $this->settings;
167 
168  // the currently set/stored style for the object
169  $style_id = $this->getStyleId();
170 
171  // the set style must either be owned or be selectable
172  if (!$this->isOwned($style_id) && !$this->isSelectable($style_id)) {
173  $style_id = 0;
174  }
175 
176  // check global fixed content style, which overwrites anything
177  $fixed_style = (int) $settings->get("fixed_content_style_id");
178  if ($fixed_style > 0) {
179  $style_id = $fixed_style;
180  }
181 
182  // if no style id is set up to this point, check/use global default style
183  if ($style_id <= 0) {
184  $style_id = (int) $settings->get("default_content_style_id");
185  }
186 
187  if ($style_id > 0 && ilObject::_lookupType($style_id) === "sty") {
188  return $style_id;
189  }
190  return 0;
191  }
192 
193  // is a style owned by an object?
194  public function isOwned(int $style_id): bool
195  {
196  return $this->object_repo->isOwned($this->obj_id, $style_id);
197  }
198 
199  public function globalFixed(): bool
200  {
201  $fixed_style = (int) $this->settings->get("fixed_content_style_id");
202  if ($fixed_style > 0) {
203  return true;
204  }
205  return false;
206  }
207 
208  public function getGlobalFixedTitle(): string
209  {
210  if ($this->globalFixed()) {
211  $fixed_style = (int) $this->settings->get("fixed_content_style_id");
212  return ilObject::_lookupTitle($fixed_style);
213  }
214  return "";
215  }
216 
217  public function hasEffectiveIndividualStyle(int $current_style): bool
218  {
219  if ($this->globalFixed()) {
220  return false;
221  }
222  if ($current_style > 0 && $this->isOwned($current_style)) {
223  return true;
224  }
225  return false;
226  }
227 
228  public function canSelectStyle(int $current_style): bool
229  {
230  if ($this->globalFixed() || $this->hasEffectiveIndividualStyle($current_style)) {
231  return false;
232  }
233  return true;
234  }
235 
236 }
cloneTo(int $obj_id)
Clones a style to a new object (or references the same standard style)
get(string $a_keyword, ?string $a_default_value=null)
get setting
__construct(InternalRepoService $repo_service, InternalDomainService $domain_service, int $ref_id, int $obj_id=0)
static _getStandardStyles(bool $a_exclude_default_style=false, bool $a_include_deactivated=false, int $a_scope=0)
Get standard styles.
This repo stores infos on repository objects that are using booking managers as a service (resource m...
Manages repository object related content style behaviour.
$path
Definition: ltiservices.php:32
static _lookupObjId(int $ref_id)
static writeOwner($obj_id, $style_id)
Content style internal repo service.
static _lookupTitle(int $obj_id)
static _lookupStandard(int $a_id)
Lookup standard flag.
getSelectableStyles()
Get all selectable styles.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
filterByReuse(array $ref_ids)
For an array of ref ids, return only the ref ids that have the reuse flag set.
static writeStyleUsage(int $a_obj_id, int $a_style_id)
Write style usage.
static lookupObjectStyle(int $a_obj_id)
Lookup object style.
This repo stores infos on repository objects that are using booking managers as a service (resource m...
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...
inheritFromParent()
Inherits a non local style from the parent container.