ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPCMediaObjectQuickEdit.php
Go to the documentation of this file.
1 <?php
2 
25 {
27  protected ?ilObjMediaObject $mob;
28  protected int $usage_cnt;
29 
30  public function __construct(
31  ilPCMediaObject $pcmedia
32  ) {
33  $this->pcmedia = $pcmedia;
34  $this->mob = $pcmedia->getMediaObject();
35  if (!is_null($this->mob)) {
36  $this->usage_cnt = count($this->mob->getUsages());
37  }
38  }
39 
40  // TITLE
41 
45  public function getTitle(): string
46  {
47  return $this->mob->getTitle();
48  }
49 
53  public function isTitleReadOnly(): bool
54  {
55  return ($this->usage_cnt > 1);
56  }
57 
61  public function setTitle(string $title): void
62  {
63  if (!$this->isTitleReadOnly()) {
64  $this->mob->setTitle($title);
65  }
66  }
67 
68  // STYLE CLASS (always from pc)
69 
73  public function getClass(): string
74  {
75  $selected = $this->pcmedia->getClass();
76  if ($selected == "") {
77  $selected = "MediaContainer";
78  }
79  return $selected;
80  }
81 
85  public function setClass(string $class): void
86  {
87  $this->pcmedia->setClass($class);
88  }
89 
90 
91  // HORIZONTAL ALIGNMENT (from pc standard alias)
92 
96  public function getHorizontalAlign(): string
97  {
98  return $this->pcmedia->getStandardMediaAliasItem()->getHorizontalAlign();
99  }
100 
104  public function setHorizontalAlign(string $align): void
105  {
106  $this->pcmedia->getStandardMediaAliasItem()->setHorizontalAlign($align);
107  }
108 
109  // USE FULLSCREEN
110 
114  public function getUseFullscreen(): bool
115  {
116  return ($this->mob->hasFullscreenItem() && $this->pcmedia->getFullscreenMediaAliasItem()->exists());
117  }
118 
119  public function setUseFullscreen(bool $use_fullscreen): void
120  {
121  $full_alias = $this->pcmedia->getFullscreenMediaAliasItem();
122  // if fullscreen should be used...
123  if ($use_fullscreen) {
124 
125  //... ensure mob has fullscreen
126  if (!$this->mob->hasFullscreenItem()) {
127  $std_item = $this->mob->getMediaItem("Standard");
128  $full_item = new ilMediaItem();
129  $this->mob->addMediaItem($full_item);
130  $full_item->setPurpose("Fullscreen");
131  $full_item->setLocationType($std_item->getLocationType());
132  $full_item->setFormat($std_item->getFormat());
133  $full_item->setLocation($std_item->getLocation());
134  }
135 
136  //... ensure fullscreen alias exists
137  if (!$full_alias->exists()) {
138  $full_alias->insert();
139  $full_alias->deriveSize();
140  $full_alias->deriveCaption();
141  $full_alias->deriveTextRepresentation();
142  $full_alias->deriveParameters();
143  }
144  } else {
145  if ($this->pcmedia->checkInstanceEditing()) {
146  if ($full_alias->exists()) {
147  $full_alias->delete();
148  }
149  } else {
150  if ($this->mob->hasFullscreenItem()) {
151  $this->mob->removeMediaItem("Fullscreen");
152  }
153  }
154  }
155  }
156 
157  // CAPTION
158 
162  public function getCaption(): string
163  {
164  $std_alias = $this->pcmedia->getStandardMediaAliasItem();
165  $std_item = $this->mob->getMediaItem("Standard");
166 
167  if (trim($std_alias->getCaption()) == "") {
168  return trim($std_item->getCaption());
169  }
170  return trim($std_alias->getCaption());
171  }
172 
176  public function setCaption(string $caption): void
177  {
178  $std_alias = $this->pcmedia->getStandardMediaAliasItem();
179  $std_item = $this->mob->getMediaItem("Standard");
180  if ($this->pcmedia->checkInstanceEditing()) {
181  $std_alias->setCaption($caption);
182  } else {
183  $std_alias->deriveCaption();
184  $std_item->setCaption($caption);
185  }
186  }
187 
188  // ALT TEXT
189 
193  public function getTextRepresentation(): string
194  {
195  $std_alias = $this->pcmedia->getStandardMediaAliasItem();
196  $std_item = $this->mob->getMediaItem("Standard");
197 
198  if (trim($std_alias->getTextRepresentation()) == "") {
199  return trim($std_item->getTextRepresentation());
200  }
201  return trim($std_alias->getTextRepresentation());
202  }
203 
207  public function setTextRepresentation(string $alt_text): void
208  {
209  $std_alias = $this->pcmedia->getStandardMediaAliasItem();
210  $std_item = $this->mob->getMediaItem("Standard");
211  if ($this->pcmedia->checkInstanceEditing()) {
212  $std_alias->setTextRepresentation($alt_text);
213  } else {
214  $std_alias->deriveTextRepresentation();
215  $std_item->setTextRepresentation($alt_text);
216  }
217  }
218 }
getUseFullscreen()
Using fullscreen? Yes, if mob has fullscreen item and fullscreen alias exists.
getTitle()
Get title (always from mob)
setClass(string $class)
Set style class.
getHorizontalAlign()
Get horizontal alignment.
isTitleReadOnly()
Is title read only? (If more than one usage exists)
setCaption(string $caption)
Set caption (pc if more usages, otherwise mob)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getCaption()
Get caption from pc, if set, from mob otherwise.
getTextRepresentation()
Get text representation from pc, if set, from mob otherwise.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilPCMediaObject Media content object (see ILIAS DTD)
setTextRepresentation(string $alt_text)
Set text representation (pc if more usages, otherwise mob)
setHorizontalAlign(string $align)
Set horizontal alignment.
__construct(ilPCMediaObject $pcmedia)