ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilAssOrderingElement.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
29 {
31 
32  public static $objectInstanceCounter = 0;
34 
39  public $id;
40 
50  protected $random_identifier = null;
51 
64  protected $solution_identifier = null;
65 
70  protected $indentation = 0;
71 
76  protected $position = null;
77 
81  protected $content = null;
82 
86  protected $uploadImageName = null;
87 
91  protected $uploadImageFile = null;
92 
96  protected $imageRemovalRequest = false;
97 
101  protected $imagePathWeb = null;
102 
106  protected $imagePathFs = null;
107  protected $imageThumbnailPrefix = null;
108 
112  public function __construct(int $id = -1)
113  {
114  $this->id = $id;
115  $this->objectInstanceId = ++self::$objectInstanceCounter;
116  }
117 
121  public function __clone()
122  {
123  $this->objectInstanceId = ++self::$objectInstanceCounter;
124  }
125 
126  public function getClone() : ilAssOrderingElement
127  {
128  return clone $this;
129  }
130 
131  public function getId() : int
132  {
133  return $this->id;
134  }
135 
136  public function setId(int $id) : void
137  {
138  $this->id = $id;
139  }
140 
141  public function getRandomIdentifier() : int
142  {
144  }
145 
146  public function setRandomIdentifier(int $random_identifier) : void
147  {
148  $this->random_identifier = $random_identifier;
149  }
150 
154  public function getSolutionIdentifier()
155  {
157  }
158 
163  {
164  $this->solution_identifier = $solution_identifier;
165  }
166 
170  public function setIndentation($indentation)
171  {
172  $this->indentation = $indentation;
173  }
174 
178  public function getIndentation()
179  {
180  return $this->indentation;
181  }
182 
186  public function getPosition()
187  {
188  return $this->position;
189  }
190 
194  public function setPosition($position)
195  {
196  $this->position = $position;
197  }
198 
202  public function getContent()
203  {
204  return $this->content;
205  }
206 
207  public function setContent($content)
208  {
209  if (is_array($content)) {
210  $content = array_shift($content);
211  }
212  $this->content = $content;
213  }
214 
215  public function getUploadImageFile() : ?string
216  {
217  return $this->uploadImageFile;
218  }
219 
224  {
225  if (is_array($uploadImageFile)) {
226  $uploadImageFile = array_shift($uploadImageFile);
227  }
228  $this->uploadImageFile = $uploadImageFile;
229  }
230 
234  public function getUploadImageName()
235  {
236  return $this->uploadImageName;
237  }
238 
243  {
244  if (is_array($uploadImageName)) {
245  $uploadImageName = array_shift($uploadImageName);
246  }
247  $this->uploadImageName = $uploadImageName;
248  }
249 
253  public function isImageUploadAvailable()
254  {
255  return (bool) strlen($this->getUploadImageFile());
256  }
257 
261  public function isImageRemovalRequest()
262  {
264  }
265 
270  {
271  $this->imageRemovalRequest = $imageRemovalRequest;
272  }
273 
277  public function getImagePathWeb()
278  {
279  return $this->imagePathWeb;
280  }
281 
286  {
287  $this->imagePathWeb = $imagePathWeb;
288  }
289 
293  public function getImagePathFs()
294  {
295  return $this->imagePathFs;
296  }
297 
301  public function setImagePathFs($imagePathFs)
302  {
303  $this->imagePathFs = $imagePathFs;
304  }
305 
309  public function getImageThumbnailPrefix()
310  {
312  }
313 
318  {
319  $this->imageThumbnailPrefix = $imageThumbnailPrefix;
320  }
321 
326  public function isSameElement(ilAssOrderingElement $element) : bool
327  {
328  return [
329  $this->getRandomIdentifier(),
330  $this->getSolutionIdentifier(),
331  $this->getPosition(),
332  $this->getIndentation(),
333  ] == [
334  $element->getRandomIdentifier(),
335  $element->getSolutionIdentifier(),
336  $element->getPosition(),
337  $element->getIndentation()
338  ];
339  }
340 
341  public function getStorageValue1($orderingType)
342  {
343  switch ($orderingType) {
346 
347  return $this->getPosition();
348 
351 
352  return $this->getSolutionIdentifier();
353  }
354  }
355 
356  public function getStorageValue2($orderingType)
357  {
358  switch ($orderingType) {
361 
362  return $this->getRandomIdentifier() . ':' . $this->getIndentation();
363 
366 
367  return $this->getPosition() + 1;
368  }
369  }
370 
371  public function __toString()
372  {
373  return $this->getContent();
374  }
375 
376  protected function thumbnailFileExists()
377  {
378  if (!$this->getContent()) {
379  return false;
380  }
381 
382  return file_exists($this->getThumbnailFilePath());
383  }
384 
385  protected function getThumbnailFilePath()
386  {
387  return $this->getImagePathFs() . $this->getImageThumbnailPrefix() . $this->getContent();
388  }
389 
390  protected function getThumbnailFileUrl()
391  {
392  return $this->getImagePathWeb() . $this->getImageThumbnailPrefix() . $this->getContent();
393  }
394 
395  protected function imageFileExists()
396  {
397  if (!$this->getContent()) {
398  return false;
399  }
400 
401  return file_exists($this->getImageFilePath());
402  }
403 
404  protected function getImageFilePath()
405  {
406  return $this->getImagePathFs() . $this->getContent();
407  }
408 
409  protected function getImageFileUrl()
410  {
411  return $this->getImagePathWeb() . $this->getContent();
412  }
413 
414  public function getPresentationImageUrl()
415  {
416  if ($this->thumbnailFileExists()) {
417  return $this->getThumbnailFileUrl();
418  }
419 
420  if ($this->imageFileExists()) {
421  return $this->getImageFileUrl();
422  }
423 
424  return '';
425  }
426 
427  public function getExportIdent()
428  {
429  $ident = array(
430  $this->getRandomIdentifier(),
431  $this->getSolutionIdentifier(),
432  $this->getPosition(),
433  $this->getIndentation()
434  );
435 
436  return implode(self::EXPORT_IDENT_PROPERTY_SEPARATOR, $ident);
437  }
438 
439  public function isExportIdent(string $ident) : bool
440  {
441  if (!strlen($ident)) {
442  return false;
443  }
444 
445  $parts = explode(self::EXPORT_IDENT_PROPERTY_SEPARATOR, $ident);
446  return
447  count($parts) == 4
452  }
453 
454  public function setExportIdent($ident)
455  {
456  if ($this->isExportIdent($ident)) {
457  list($randomId, $solutionId, $pos, $indent) = explode(
458  self::EXPORT_IDENT_PROPERTY_SEPARATOR,
459  $ident
460  );
461  $this->setRandomIdentifier((int) $randomId);
462  $this->setSolutionIdentifier($solutionId);
463  $this->setPosition($pos);
464  $this->setIndentation($indent);
465  }
466  }
467 
468 
469  public function withRandomIdentifier(int $id) : self
470  {
471  $clone = clone $this;
472  $clone->random_identifier = $id;
473  return $clone;
474  }
475  public function withSolutionIdentifier(int $id) : self
476  {
477  $clone = clone $this;
478  $clone->solution_identifier = $id;
479  return $clone;
480  }
481  public function withPosition(int $position) : self
482  {
483  $clone = clone $this;
484  $clone->position = $position;
485  return $clone;
486  }
487  public function withIndentation(int $indentation) : self
488  {
489  $clone = clone $this;
490  $clone->indentation = $indentation;
491  return $clone;
492  }
493  public function withContent(string $content) : self
494  {
495  $clone = clone $this;
496  $clone->content = $content;
497  return $clone;
498  }
499 }
$random_identifier
this identifier is generated randomly it is recycled for known elements
isSameElement(ilAssOrderingElement $element)
setRandomIdentifier(int $random_identifier)
setSolutionIdentifier($solution_identifier)
$id
this identifier equals the database&#39;s row id
$position
the correct position in the ordering sequence
__construct(int $id=-1)
ilAssOrderingElement constructor.
setImageRemovalRequest($imageRemovalRequest)
setImageThumbnailPrefix($imageThumbnailPrefix)
$solution_identifier
this identifier is used to identify elements and is stored together with the set position and indenta...
$indentation
the correct width of indentation for the element