ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPCMediaObjectQuickEdit.php
Go to the documentation of this file.
1<?php
2
25{
28 protected int $usage_cnt;
29
30 public function __construct(
32 ) {
33 $this->pcmedia = $pcmedia;
34 $this->mob = $pcmedia->getMediaObject();
35 $this->usage_cnt = count($this->mob->getUsages());
36 }
37
38 // TITLE
39
43 public function getTitle(): string
44 {
45 return $this->mob->getTitle();
46 }
47
51 public function isTitleReadOnly(): bool
52 {
53 return ($this->usage_cnt > 1);
54 }
55
59 public function setTitle(string $title): void
60 {
61 if (!$this->isTitleReadOnly()) {
62 $this->mob->setTitle($title);
63 }
64 }
65
66 // STYLE CLASS (always from pc)
67
71 public function getClass(): string
72 {
73 $selected = $this->pcmedia->getClass();
74 if ($selected == "") {
75 $selected = "MediaContainer";
76 }
77 return $selected;
78 }
79
83 public function setClass(string $class): void
84 {
85 $this->pcmedia->setClass($class);
86 }
87
88
89 // HORIZONTAL ALIGNMENT (from pc standard alias)
90
94 public function getHorizontalAlign(): string
95 {
96 return $this->pcmedia->getStandardMediaAliasItem()->getHorizontalAlign();
97 }
98
102 public function setHorizontalAlign(string $align): void
103 {
104 $this->pcmedia->getStandardMediaAliasItem()->setHorizontalAlign($align);
105 }
106
107 // USE FULLSCREEN
108
112 public function getUseFullscreen(): bool
113 {
114 return ($this->mob->hasFullscreenItem() && $this->pcmedia->getFullscreenMediaAliasItem()->exists());
115 }
116
117 public function setUseFullscreen(bool $use_fullscreen): void
118 {
119 $full_alias = $this->pcmedia->getFullscreenMediaAliasItem();
120 // if fullscreen should be used...
121 if ($use_fullscreen) {
122 //... ensure mob has fullscreen
123 if (!$this->mob->hasFullscreenItem()) {
124 $std_item = $this->mob->getMediaItem("Standard");
125 $full_item = new ilMediaItem();
126 $this->mob->addMediaItem($full_item);
127 $full_item->setPurpose("Fullscreen");
128 $full_item->setLocationType($std_item->getLocationType());
129 $full_item->setFormat($std_item->getFormat());
130 $full_item->setLocation($std_item->getLocation());
131 }
132
133 //... ensure fullscreen alias exists
134 if (!$full_alias->exists()) {
135 $full_alias->insert();
136 $full_alias->deriveSize();
137 $full_alias->deriveCaption();
138 $full_alias->deriveTextRepresentation();
139 $full_alias->deriveParameters();
140 }
141 } else {
142 if ($this->pcmedia->checkInstanceEditing()) {
143 if ($full_alias->exists()) {
144 $full_alias->delete();
145 }
146 } else {
147 if ($this->mob->hasFullscreenItem()) {
148 $this->mob->removeMediaItem("Fullscreen");
149 }
150 }
151 }
152 }
153
154 // CAPTION
155
159 public function getCaption(): string
160 {
161 $std_alias = $this->pcmedia->getStandardMediaAliasItem();
162 $std_item = $this->mob->getMediaItem("Standard");
163
164 if (trim($std_alias->getCaption()) == "") {
165 return trim($std_item->getCaption());
166 }
167 return trim($std_alias->getCaption());
168 }
169
173 public function setCaption(string $caption): void
174 {
175 $std_alias = $this->pcmedia->getStandardMediaAliasItem();
176 $std_item = $this->mob->getMediaItem("Standard");
177 if ($this->pcmedia->checkInstanceEditing()) {
178 if ($caption !== $std_item->getCaption()) { // in quick edit we derive if the value is equal to the item caption
179 $std_alias->setCaption($caption);
180 } else {
181 $std_alias->deriveCaption();
182 }
183 } else {
184 $std_alias->deriveCaption();
185 $std_item->setCaption($caption);
186 }
187 }
188
189 // ALT TEXT
190
194 public function getTextRepresentation(): string
195 {
196 $std_alias = $this->pcmedia->getStandardMediaAliasItem();
197 $std_item = $this->mob->getMediaItem("Standard");
198
199 if (trim($std_alias->getTextRepresentation()) == "") {
200 return trim($std_item->getTextRepresentation());
201 }
202 return trim($std_alias->getTextRepresentation());
203 }
204
208 public function setTextRepresentation(string $alt_text): void
209 {
210 $std_alias = $this->pcmedia->getStandardMediaAliasItem();
211 $std_item = $this->mob->getMediaItem("Standard");
212 if ($this->pcmedia->checkInstanceEditing()) {
213 if ($alt_text !== $std_item->getTextRepresentation()) { // in quick edit we derive if the value is equal to the item caption
214 $std_alias->setTextRepresentation($alt_text);
215 } else {
216 $std_alias->deriveTextRepresentation();
217 }
218 } else {
219 $std_alias->deriveTextRepresentation();
220 $std_item->setTextRepresentation($alt_text);
221 }
222 }
223}
Class ilMediaItem Media Item, component of a media object (file or reference)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isTitleReadOnly()
Is title read only? (If more than one usage exists)
setCaption(string $caption)
Set caption (pc if more usages, otherwise mob)
getTitle()
Get title (always from mob)
__construct(ilPCMediaObject $pcmedia)
setHorizontalAlign(string $align)
Set horizontal alignment.
getHorizontalAlign()
Get horizontal alignment.
setClass(string $class)
Set style class.
setTextRepresentation(string $alt_text)
Set text representation (pc if more usages, otherwise mob)
getUseFullscreen()
Using fullscreen? Yes, if mob has fullscreen item and fullscreen alias exists.
getCaption()
Get caption from pc, if set, from mob otherwise.
getTextRepresentation()
Get text representation from pc, if set, from mob otherwise.
Class ilPCMediaObject Media content object (see ILIAS DTD)