ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.McstImageGalleryGUI.php
Go to the documentation of this file.
1 <?php
2 
25 {
26  protected \ILIAS\MediaObjects\MediaType\MediaTypeManager $media_types;
27  protected \ILIAS\MediaCast\InternalGUIService $gui;
28  protected \ILIAS\MediaCast\MediaCastManager $mc_manager;
29  protected \ILIAS\MediaCast\InternalDomainService $domain;
30  protected string $completed_callback;
31  protected string $rss_link;
32  protected \ilObjMediaCast $media_cast;
34  protected \ILIAS\DI\UIServices $ui;
35  protected \ilLanguage $lng;
36  protected \ilObjUser $user;
37  protected \ilCtrl $ctrl;
38  protected \ilToolbarGUI $toolbar;
40 
41  public function __construct(
42  \ilObjMediaCast $obj,
43  $tpl = null,
44  string $rss_link = ""
45  ) {
46  global $DIC;
47 
48  $this->ui = $DIC->ui();
49  $this->rss_link = $rss_link;
50  $this->lng = $DIC->language();
51  $this->media_cast = $obj;
52  $this->tpl = $tpl;
53  $this->user = $DIC->user();
54  $this->ctrl = $DIC->ctrl();
55  $this->access = $DIC->access();
56  $this->toolbar = $DIC->toolbar();
57  $this->media_types = $DIC->mediaObjects()->internal()->domain()->mediaType();
58  $this->mc_manager = $DIC->mediaCast()->internal()->domain()->mediaCast($this->media_cast);
59  $this->gui = $DIC->mediaCast()->internal()->gui();
60  $this->domain = $DIC->mediaCast()->internal()->domain();
61  }
62 
63  public function executeCommand(): void
64  {
65  $ctrl = $this->ctrl;
66 
67  $next_class = $ctrl->getNextClass($this);
68  $cmd = $ctrl->getCmd();
69 
70  switch ($next_class) {
71  default:
72  if (in_array($cmd, array("downloadAll"))) {
73  $this->$cmd();
74  }
75  }
76  }
77 
78  public function getHTML(): string
79  {
80  $f = $this->ui->factory();
81  $renderer = $this->ui->renderer();
82  $ctrl = $this->ctrl;
83  $lng = $this->lng;
84  $toolbar = $this->toolbar;
85 
86  // toolbar
87  $toolbar->setFormAction($ctrl->getFormAction($this));
88  if ($this->media_cast->getDownloadable()) {
89  $toolbar->addFormButton($lng->txt("mcst_download_all"), "downloadAll");
90  }
91 
92  if ($this->rss_link !== "") {
93  $b = $f->link()->standard(
94  $lng->txt("mcst_webfeed"),
96  )->withOpenInNewViewport(true);
97  $toolbar->addComponent($b);
98  }
99 
100  // cards and modals
101  $cards = [];
102  $modals = [];
103 
104  $pages = [];
105 
106  $lp_collection_mode = $this->domain->learningProgress($this->media_cast)->isCollectionMode();
107 
108  $mob_modals = [];
109  foreach ($this->media_cast->getSortedItemsArray() as $item) {
110  $mob = new \ilObjMediaObject($item["mob_id"]);
111  $med = $mob->getMediaItem("Standard");
112  if (!in_array($med->getFormat(), iterator_to_array($this->media_types->getAllowedImageMimeTypes()), true)) {
113  continue;
114  }
115 
116  if (strcasecmp("Reference", $med->getLocationType()) == 0) {
117  $resource = $med->getLocation();
118  } else {
119  $path_to_file = \ilObjMediaObject::_getURL($mob->getId()) . "/" . $med->getLocation();
120  $resource = ilWACSignedPath::signFile($path_to_file);
121  }
122 
123  $image = $f->image()->responsive(
124  $resource,
125  $mob->getTitle()
126  );
127 
128  $pages[] = $f->modal()->lightboxImagePage($image, $mob->getTitle());
129  if ($lp_collection_mode) {
130  $mob_modals[$mob->getId()] = $f->modal()->lightbox($pages);
131  $pages = [];
132  }
133  }
134  $main_modal = null;
135  if (!$lp_collection_mode) {
136  $main_modal = $f->modal()->lightbox($pages);
137  }
138 
139  $cnt = 0;
140  foreach ($this->media_cast->getSortedItemsArray() as $item) {
141  $mob = new \ilObjMediaObject($item["mob_id"]);
142  $med = $mob->getMediaItem("Standard");
143 
144  if (!in_array($med->getFormat(), iterator_to_array($this->media_types->getAllowedImageMimeTypes()), true)) {
145  continue;
146  }
147 
148  if (strcasecmp("Reference", $med->getLocationType()) == 0) {
149  $resource = $med->getLocation();
150  } else {
151  $path_to_file = \ilObjMediaObject::_getURL($mob->getId()) . "/" . $med->getLocation();
152  $resource = ilWACSignedPath::signFile($path_to_file);
153  }
154  $preview_resource = $resource;
155  if ($mob->getVideoPreviewPic() != "") {
156  $preview_resource = ilWACSignedPath::signFile($mob->getVideoPreviewPic());
157  }
158 
159 
160  $preview_image = $f->image()->responsive(
161  $preview_resource,
162  $mob->getTitle()
163  );
164 
165  $image = $f->image()->responsive(
166  $resource,
167  $mob->getTitle()
168  );
169 
170  if (!$lp_collection_mode) {
171  $modal = $main_modal;
172  } else {
173  $modal = $mob_modals[$mob->getId()];
174  }
175 
176  $card_image = $preview_image->withAction($modal->getShowSignal());
177  $slide_to = "";
178  $completed_cb = "";
179  if (!$lp_collection_mode) {
180  $slide_to = "document.querySelector('.modal-body .carousel [data-slide-to=\"" . $cnt . "\"]').click();";
181  } else {
182  $completed_cb = $this->completed_callback . '&mob_id=' . $mob->getId();
183  $completed_cb = "$.ajax({type:'GET', url: '$completed_cb'});";
184  }
185 
186  $card_image = $card_image->withAdditionalOnLoadCode(function ($id) use ($slide_to, $completed_cb) {
187  return "$('#$id').click(function(e) { $slide_to $completed_cb });";
188  });
189  if (!$lp_collection_mode) {
190  $cnt++;
191  }
192 
193  $sections = ($mob->getDescription())
194  ? [$f->legacy($mob->getDescription())]
195  : [];
196 
197  if ($this->media_cast->getDownloadable()) {
198  $ctrl->setParameterByClass("ilobjmediacastgui", "item_id", $item["id"]);
199  $ctrl->setParameterByClass("ilobjmediacastgui", "purpose", "Standard");
200  $download = $ctrl->getLinkTargetByClass("ilobjmediacastgui", "downloadItem");
201  $sections[] = $f->button()->standard($lng->txt("download"), $download);
202  }
203 
204  // comments
205  if ($this->mc_manager->commentsActive()) {
206  $comments_gui = $this->gui->comments()->commentGUI(
207  $this->media_cast->getRefId(),
208  (int) $item["id"]
209  );
210  $sections[] = $f->legacy($comments_gui->getGlyph());
211  }
212 
213  //$title_button = $f->button()->shy($mob->getTitle(), $modal->getShowSignal());
214  $title = $mob->getTitle();
215 
216  $card = $f->card()->standard(
217  $title,
218  $card_image
219  )->withSections(
220  $sections
221  )->withTitleAction($modal->getShowSignal());
222 
223  $cards[] = $card;
224  $modals[] = $modal;
225  }
226 
227  $deck = $f->deck($cards);
228 
229  if (count($pages) === 0 && count($mob_modals) === 0) {
230  return "";
231  }
232  if (!$lp_collection_mode) {
233  $modals = [$main_modal];
234  } else {
235  $modals = $mob_modals;
236  }
237  return "<div id='il-mcst-img-gallery'>" . $renderer->render(array_merge([$deck], $modals)) . "</div>";
238  }
239 
240  protected function downloadAll(): void
241  {
242  if (!$this->media_cast->getDownloadable() ||
243  !$this->access->checkAccess('read', '', $this->media_cast->getRefId())) {
244  $this->tpl->setOnScreenMessage(
245  $this->tpl::MESSAGE_TYPE_FAILURE,
246  $this->lng->txt('permission_denied'),
247  true
248  );
249  $this->ctrl->redirectByClass(ilObjMediaCastGUI::class);
250  }
251 
252  $user = $this->user;
253  $download_task = new \ILIAS\MediaCast\BackgroundTasks\DownloadAllBackgroundTask(
254  (int) $user->getId(),
255  (int) $this->media_cast->getRefId(),
256  (int) $this->media_cast->getId()
257  );
258 
259  if ($download_task->run()) {
260  $this->tpl->setOnScreenMessage(
261  'success',
262  $this->lng->txt('mcst_download_started_bg'),
263  true
264  );
265  }
266 
267  $this->ctrl->redirectByClass("ilobjmediacastgui", "showContent");
268  }
269 
270  public function setCompletedCallback(string $completed_callback): void
271  {
272  $this->completed_callback = $completed_callback;
273  }
274 }
__construct(\ilObjMediaCast $obj, $tpl=null, string $rss_link="")
setFormAction(string $a_val, bool $a_multipart=false, string $a_target="")
Set form action (if form action is set, toolbar is wrapped into form tags)
ilGlobalTemplateInterface $tpl
global $DIC
Definition: feed.php:28
ILIAS MediaCast MediaCastManager $mc_manager
getNextClass($a_gui_class=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS MediaObjects MediaType MediaTypeManager $media_types
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS MediaCast InternalDomainService $domain
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static signFile(string $path_to_file)
static _getURL(int $a_mob_id)
get directory for files of media object
setCompletedCallback(string $completed_callback)
ILIAS MediaCast InternalGUIService $gui