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