ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilPCMediaObjectQuickEdit.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2020 ILIAS open source, Extended GPL, see docs/LICENSE */
4
11{
15 protected $pcmedia;
16
20 protected $mob;
21
25 protected $usage_cnt;
26
31 {
32 $this->pcmedia = $pcmedia;
33 $this->mob = $pcmedia->getMediaObject();
34 $this->usage_cnt = count($this->mob->getUsages());
35 }
36
37 // TITLE
38
42 public function getTitle() : string
43 {
44 return $this->mob->getTitle();
45 }
46
50 public function isTitleReadOnly() : bool
51 {
52 return ($this->usage_cnt > 1);
53 }
54
58 public function setTitle(string $title)
59 {
60 if (!$this->isTitleReadOnly()) {
61 $this->mob->setTitle($title);
62 }
63 }
64
65 // STYLE CLASS (always from pc)
66
70 public function getClass() : string
71 {
72 $selected = $this->pcmedia->getClass();
73 if ($selected == "") {
74 $selected = "MediaContainer";
75 }
76 return $selected;
77 }
78
82 public function setClass(string $class)
83 {
84 $this->pcmedia->setClass($class);
85 }
86
87
88 // HORIZONTAL ALIGNMENT (from pc standard alias)
89
93 public function getHorizontalAlign() : string
94 {
95 return $this->pcmedia->getStandardMediaAliasItem()->getHorizontalAlign();
96 }
97
101 public function setHorizontalAlign(string $align)
102 {
103 $this->pcmedia->getStandardMediaAliasItem()->setHorizontalAlign($align);
104 }
105
106 // USE FULLSCREEN
107
111 public function getUseFullscreen() : bool
112 {
113 return ($this->mob->hasFullscreenItem() && $this->pcmedia->getFullscreenMediaAliasItem()->exists());
114 }
115
116 public function setUseFullscreen(bool $use_fullscreen)
117 {
118 $full_alias = $this->pcmedia->getFullscreenMediaAliasItem();
119 // if fullscreen should be used...
120 if ($use_fullscreen) {
121
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)
174 {
175 $std_alias = $this->pcmedia->getStandardMediaAliasItem();
176 $std_item = $this->mob->getMediaItem("Standard");
177 if ($this->pcmedia->checkInstanceEditing()) {
178 $std_alias->setCaption($caption);
179 } else {
180 $std_alias->deriveCaption();
181 $std_item->setCaption($caption);
182 }
183 }
184
185 // ALT TEXT
186
190 public function getTextRepresentation() : string
191 {
192 $std_alias = $this->pcmedia->getStandardMediaAliasItem();
193 $std_item = $this->mob->getMediaItem("Standard");
194
195 if (trim($std_alias->getTextRepresentation()) == "") {
196 return trim($std_item->getTextRepresentation());
197 }
198 return trim($std_alias->getTextRepresentation());
199 }
200
204 public function setTextRepresentation(string $alt_text)
205 {
206 $std_alias = $this->pcmedia->getStandardMediaAliasItem();
207 $std_item = $this->mob->getMediaItem("Standard");
208 if ($this->pcmedia->checkInstanceEditing()) {
209 $std_alias->setTextRepresentation($alt_text);
210 } else {
211 $std_alias->deriveTextRepresentation();
212 $std_item->setTextRepresentation($alt_text);
213 }
214 }
215}
An exception for terminatinating execution or to throw for unit testing.
Class ilMediaItem Media Item, component of a media object (file or reference)
Manages business logic in media slate editing.
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)
Constructor.
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.