ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilAssOrderingElement.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
29 {
30  public const EXPORT_IDENT_PROPERTY_SEPARATOR = '_';
31 
32  public static $objectInstanceCounter = 0;
34 
39  public int $id;
40 
48  protected ?int $random_identifier = null;
49 
60  protected ?int $solution_identifier = null;
61 
65  protected int $indentation = 0;
66 
70  protected ?int $position = null;
71  protected ?string $content = null;
72  protected ?string $uploadImageName = null;
73  protected ?string $uploadImageFile = null;
74  protected bool $imageRemovalRequest = false;
75  protected ?string $imagePathWeb = null;
76  protected ?string $image_path_fs = null;
78 
82  public function __construct(int $id = -1)
83  {
84  $this->id = $id;
85  $this->objectInstanceId = ++self::$objectInstanceCounter;
86  }
87 
91  public function __clone()
92  {
93  $this->objectInstanceId = ++self::$objectInstanceCounter;
94  }
95 
96  public function getClone(): ilAssOrderingElement
97  {
98  return clone $this;
99  }
100 
101  public function getId(): int
102  {
103  return $this->id;
104  }
105 
106  public function setId(int $id): void
107  {
108  $this->id = $id;
109  }
110 
111  public function getRandomIdentifier(): ?int
112  {
114  }
115 
116  public function setRandomIdentifier(int $random_identifier): void
117  {
118  $this->random_identifier = $random_identifier;
119  }
120 
124  public function getSolutionIdentifier(): ?int
125  {
127  }
128 
129  public function setSolutionIdentifier(int $solution_identifier): void
130  {
131  $this->solution_identifier = $solution_identifier;
132  }
133 
134  public function setIndentation(int $indentation): void
135  {
136  $this->indentation = $indentation;
137  }
138 
139  public function getIndentation(): int
140  {
141  return $this->indentation;
142  }
143 
144  public function getPosition(): ?int
145  {
146  return $this->position;
147  }
148 
149  public function setPosition(int $position): void
150  {
151  $this->position = $position;
152  }
153 
157  public function getContent(): ?string
158  {
159  return $this->content;
160  }
161 
162 
163  public function setContent($content): void
164  {
165  if (is_array($content)) {
166  $content = array_shift($content);
167  }
168  $this->content = $content;
169  }
170 
171  public function getUploadImageFile(): ?string
172  {
173  return $this->uploadImageFile;
174  }
175 
179  public function setUploadImageFile($uploadImageFile): void
180  {
181  if (is_array($uploadImageFile)) {
182  $uploadImageFile = array_shift($uploadImageFile);
183  }
184  $this->uploadImageFile = $uploadImageFile;
185  }
186 
190  public function getUploadImageName(): ?string
191  {
192  return $this->uploadImageName;
193  }
194 
198  public function setUploadImageName($uploadImageName): void
199  {
200  if (is_array($uploadImageName)) {
201  $uploadImageName = array_shift($uploadImageName);
202  }
203  $this->uploadImageName = $uploadImageName;
204  }
205 
209  public function isImageUploadAvailable(): bool
210  {
211  return $this->getUploadImageFile() !== null
212  && $this->getUploadImageFile() !== '';
213  }
214 
218  public function isImageRemovalRequest(): ?bool
219  {
221  }
222 
226  public function setImageRemovalRequest($imageRemovalRequest): void
227  {
228  $this->imageRemovalRequest = $imageRemovalRequest;
229  }
230 
234  public function getImagePathWeb(): ?string
235  {
236  return $this->imagePathWeb;
237  }
238 
242  public function setImagePathWeb($imagePathWeb): void
243  {
244  $this->imagePathWeb = $imagePathWeb;
245  }
246 
250  public function getImagePathFs(): ?string
251  {
252  return $this->image_path_fs;
253  }
254 
255  public function setImagePathFs(string $image_path_fs): void
256  {
257  $this->image_path_fs = $image_path_fs;
258  }
259 
260  public function getImageThumbnailPrefix()
261  {
263  }
264 
266  {
267  $this->imageThumbnailPrefix = $imageThumbnailPrefix;
268  }
269 
270  public function isSameElement(ilAssOrderingElement $element): bool
271  {
272  return [
273  $this->getRandomIdentifier(),
274  $this->getSolutionIdentifier(),
275  $this->getPosition(),
276  $this->getIndentation(),
277  ] == [
278  $element->getRandomIdentifier(),
279  $element->getSolutionIdentifier(),
280  $element->getPosition(),
281  $element->getIndentation()
282  ];
283  }
284 
285  public function getStorageValue1(int $ordering_type): int|string
286  {
287  switch ($ordering_type) {
290 
291  return $this->getPosition();
292 
295  default:
296  return $this->getSolutionIdentifier();
297  }
298  }
299 
300  public function getStorageValue2(int $ordering_type): int|string
301  {
302  switch ($ordering_type) {
305 
306  return $this->getRandomIdentifier() . ':' . $this->getIndentation();
307 
310  default:
311  return $this->getPosition() + 1;
312  }
313  }
314 
315  public function __toString(): string
316  {
317  return $this->getContent() ?? '';
318  }
319 
320  protected function thumbnailFileExists(): bool
321  {
322  if (!$this->getContent()) {
323  return false;
324  }
325 
326  return file_exists($this->getThumbnailFilePath());
327  }
328 
329  protected function getThumbnailFilePath(): string
330  {
331  return $this->getImagePathFs() . $this->getImageThumbnailPrefix() . $this->getContent();
332  }
333 
334  protected function getThumbnailFileUrl(): string
335  {
336  return $this->getImagePathWeb() . $this->getImageThumbnailPrefix() . $this->getContent();
337  }
338 
339  protected function imageFileExists(): bool
340  {
341  if (!$this->getContent()) {
342  return false;
343  }
344 
345  return file_exists($this->getImageFilePath());
346  }
347 
348  protected function getImageFilePath(): string
349  {
350  return $this->getImagePathFs() . $this->getContent();
351  }
352 
353  protected function getImageFileUrl(): string
354  {
355  return $this->getImagePathWeb() . $this->getContent();
356  }
357 
358  public function getPresentationImageUrl(): string
359  {
360  if ($this->thumbnailFileExists()) {
361  return $this->getThumbnailFileUrl();
362  }
363 
364  if ($this->imageFileExists()) {
365  return $this->getImageFileUrl();
366  }
367 
368  return '';
369  }
370 
371  public function getExportIdent(): string
372  {
373  $ident = [
374  $this->getRandomIdentifier(),
375  $this->getSolutionIdentifier(),
376  $this->getPosition(),
377  $this->getIndentation()
378  ];
379 
380  return implode(self::EXPORT_IDENT_PROPERTY_SEPARATOR, $ident);
381  }
382 
383  public function isExportIdent(string $ident): bool
384  {
385  if (!strlen($ident)) {
386  return false;
387  }
388 
389  $parts = explode(self::EXPORT_IDENT_PROPERTY_SEPARATOR, $ident);
390  return
391  count($parts) == 4
396  }
397 
398  public function setExportIdent($ident): void
399  {
400  if ($this->isExportIdent($ident)) {
401  list($randomId, $solutionId, $pos, $indent) = explode(
402  self::EXPORT_IDENT_PROPERTY_SEPARATOR,
403  $ident
404  );
405  $this->setRandomIdentifier((int) $randomId);
406  $this->setSolutionIdentifier((int) $solutionId);
407  $this->setPosition((int) $pos);
408  $this->setIndentation((int) $indent);
409  }
410  }
411 
412 
413  public function withRandomIdentifier(int $id): self
414  {
415  $clone = clone $this;
416  $clone->random_identifier = $id;
417  return $clone;
418  }
419  public function withSolutionIdentifier(int $id): self
420  {
421  $clone = clone $this;
422  $clone->solution_identifier = $id;
423  return $clone;
424  }
425  public function withPosition(int $position): self
426  {
427  $clone = clone $this;
428  $clone->position = $position;
429  return $clone;
430  }
431  public function withIndentation(int $indentation): self
432  {
433  $clone = clone $this;
434  $clone->indentation = $indentation;
435  return $clone;
436  }
437  public function withContent(string $content): self
438  {
439  $clone = clone $this;
440  $clone->content = $content;
441  return $clone;
442  }
443 }
getStorageValue1(int $ordering_type)
isSameElement(ilAssOrderingElement $element)
setRandomIdentifier(int $random_identifier)
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
int $indentation
the correct width of indentation for the element
int $random_identifier
this identifier is generated randomly it is recycled for known elements
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getStorageValue2(int $ordering_type)
__construct(int $id=-1)
ilAssOrderingElement constructor.
setImageRemovalRequest($imageRemovalRequest)
setImagePathFs(string $image_path_fs)
int $position
the correct position in the ordering sequence
setImageThumbnailPrefix($imageThumbnailPrefix)
setSolutionIdentifier(int $solution_identifier)
int $solution_identifier
this identifier is used to identify elements and is stored together with the set position and indenta...