ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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  $resource = $mob->getStandardSrc();
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  $items = $this->media_cast->getSortedItemsArray();
136  $total = count($items);
137  foreach ($items as $item) {
138  $mob = new \ilObjMediaObject($item["mob_id"]);
139  $med = $mob->getMediaItem("Standard");
140 
141  if (!in_array($med->getFormat(), iterator_to_array($this->media_types->getAllowedImageMimeTypes()), true)) {
142  continue;
143  }
144 
145  $resource = $mob->getStandardSrc();
146 
147  $preview_resource = $resource;
148  if ($mob->getVideoPreviewPic() != "") {
149  // $preview_resource = $mob->getVideoPreviewPic();
150  }
151 
152 
153  $preview_image = $f->image()->responsive(
154  $preview_resource,
155  $mob->getTitle()
156  );
157 
158  $image = $f->image()->responsive(
159  $resource,
160  $mob->getTitle()
161  );
162 
163  if (!$lp_collection_mode) {
164  $modal = $main_modal;
165  } else {
166  $modal = $mob_modals[$mob->getId()];
167  }
168 
169  $card_image = $preview_image->withAction($modal->getShowSignal());
170  $slide_to = "";
171  $completed_cb = "";
172  if (!$lp_collection_mode) {
173  if ($total > 1) {
174  $slide_to = "document.querySelector('.modal-body .carousel [data-slide-to=\"" . $cnt . "\"]').click();";
175  }
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()->content($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  // comments
200  if ($this->mc_manager->commentsActive()) {
201  $comments_gui = $this->gui->comments()->commentGUI(
202  $this->media_cast->getRefId(),
203  (int) $item["id"]
204  );
205  $sections[] = $f->legacy()->content($comments_gui->getGlyph());
206  }
207 
208  //$title_button = $f->button()->shy($mob->getTitle(), $modal->getShowSignal());
209  $title = $mob->getTitle();
210 
211  $card = $f->card()->standard(
212  $title,
213  $card_image
214  )->withSections(
215  $sections
216  )->withTitleAction($modal->getShowSignal());
217 
218 
219  $cards[] = $card;
220  $modals[] = $modal;
221  }
222 
223  $deck = $f->deck($cards);
224 
225  if (count($pages) === 0 && count($mob_modals) === 0) {
226  return "";
227  }
228  if (!$lp_collection_mode) {
229  $modals = [$main_modal];
230  } else {
231  $modals = $mob_modals;
232  }
233  return "<div id='il-mcst-img-gallery'>" . $renderer->render(array_merge([$deck], $modals)) . "</div>";
234  }
235 
236  protected function downloadAll(): void
237  {
238  if (!$this->media_cast->getDownloadable() ||
239  !$this->access->checkAccess('read', '', $this->media_cast->getRefId())) {
240  $this->tpl->setOnScreenMessage(
241  $this->tpl::MESSAGE_TYPE_FAILURE,
242  $this->lng->txt('permission_denied'),
243  true
244  );
245  $this->ctrl->redirectByClass(ilObjMediaCastGUI::class);
246  }
247 
248  $user = $this->user;
249  $download_task = new \ILIAS\MediaCast\BackgroundTasks\DownloadAllBackgroundTask(
250  (int) $user->getId(),
251  (int) $this->media_cast->getRefId(),
252  (int) $this->media_cast->getId()
253  );
254 
255  if ($download_task->run()) {
256  $this->tpl->setOnScreenMessage(
257  'success',
258  $this->lng->txt('mcst_download_started_bg'),
259  true
260  );
261  }
262 
263  $this->ctrl->redirectByClass("ilobjmediacastgui", "showContent");
264  }
265 
266  public function setCompletedCallback(string $completed_callback): void
267  {
268  $this->completed_callback = $completed_callback;
269  }
270 }
$renderer
__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
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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...
global $DIC
Definition: shib_login.php:26
ILIAS MediaObjects MediaType MediaTypeManager $media_types
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
ILIAS MediaCast InternalDomainService $domain
setCompletedCallback(string $completed_callback)
ILIAS MediaCast InternalGUIService $gui