ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilMediaObjectsPlayerWrapperGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
28 {
29  protected \ILIAS\MediaObjects\Tracking\TrackingManager $tracking;
30  protected \ILIAS\MediaObjects\Player\PlayerGUIRequest $request;
31  protected \ILIAS\MediaObjects\MediaType\MediaTypeManager $media_type;
34 
35  public function __construct(
36  InternalDomainService $domain_service,
37  InternalGUIService $gui_service
38  ) {
39  $this->gui = $gui_service;
40  $this->domain = $domain_service;
41  $this->media_type = $this->domain->mediaType();
42  $this->request = $gui_service->player()->request();
43  $this->tracking = $this->domain->tracking();
44  }
45 
46  public function executeCommand(): void
47  {
48  $ctrl = $this->gui->ctrl();
49 
50  $next_class = $ctrl->getNextClass($this);
51  $cmd = $ctrl->getCmd();
52 
53  switch ($next_class) {
54  default:
55  if (in_array($cmd, array("saveCompletion"))) {
56  $this->$cmd();
57  }
58  }
59  }
60 
61  public function renderComponent(
62  ilObjMediaObject $mob,
63  int $tracking_container_ref_id = 0) : string
64  {
65  $comp = $this->getComponent($mob, $tracking_container_ref_id);
66  if ($comp) {
67  return $this->gui->ui()->renderer()->render($comp);
68  }
69  return "";
70  }
71  public function getComponent(
72  ilObjMediaObject $mob,
73  int $tracking_container_ref_id = 0): ILIAS\UI\Component\Component
74  {
75  $med = $mob->getMediaItem("Standard");
76  $comp = null;
77  if (!is_null($med)) {
78  if ($this->media_type->isAudio($med->getFormat())) {
79  $comp = $this->audio(
80  $mob,
81  $tracking_container_ref_id
82  );
83  } elseif ($this->media_type->isVideo($med->getFormat())) {
84  $comp = $this->video(
85  $mob,
86  $tracking_container_ref_id
87  );
88  } elseif ($this->media_type->isImage($med->getFormat())) {
89  $comp = $this->image(
90  $mob,
91  $tracking_container_ref_id
92  );
93  }
94  }
95  return $comp;
96  }
97 
101  public function audio(
102  ilObjMediaObject $mob,
103  int $tracking_container_ref_id = 0
104  ): ?\ILIAS\UI\Component\Player\Audio {
105  $main_tpl = $this->gui->ui()->mainTemplate();
106 
107  $ctrl = $this->gui->ctrl();
108 
109  $med = $mob->getMediaItem("Standard");
110 
111  if (is_null($med) || !$this->media_type->isAudio($med->getFormat())) {
112  return null;
113  }
114  $resource = $mob->getStandardSrc();
115  $audio = $this->gui->ui()->factory()->player()->audio(
116  $resource,
117  ""
118  );
119 
120  if ($tracking_container_ref_id > 0) {
121  // @todo: make this a media object general setting
122  $mcst_settings = ilMediaCastSettings::_getInstance();
123  $treshold = (int) $mcst_settings->getVideoCompletionThreshold();
124 
125  $main_tpl->addJavaScript("assets/js/MediaObjectsCompletion.js");
126  $ctrl->setParameter($this, "mob_tracking_ref_id", $tracking_container_ref_id);
127  $ctrl->setParameter($this, "mob_tracking_mob_id", $mob->getId());
128  $url = $ctrl->getLinkTarget($this, "saveCompletion");
129  $audio = $audio->withAdditionalOnLoadCode(function ($id) use ($url, $treshold) {
130  $js = <<<EOT
131  document.getElementById('$id').dataset.mobCompletionCallback = '$url';
132  document.getElementById('$id').dataset.mobCompletionThreshold = '$treshold';
133  il.MediaObjectsCompletion.init();
134 EOT;
135  return $js;
136  });
137  }
138  return $audio;
139  }
140 
144  public function image(
145  ilObjMediaObject $mob,
146  int $tracking_container_ref_id = 0
147  ): ?\ILIAS\UI\Component\Image\Image {
148  $main_tpl = $this->gui->ui()->mainTemplate();
149 
150  $ctrl = $this->gui->ctrl();
151 
152  $med = $mob->getMediaItem("Standard");
153 
154  if (is_null($med) || !$this->media_type->isImage($med->getFormat())) {
155  return null;
156  }
157 
158  $source = $mob->getStandardSrc();
159 
160  $image = $this->gui->ui()->factory()->image()->responsive($source, $mob->getTitle());
161 
162  if ($tracking_container_ref_id > 0) {
163  // @todo: make this a media object general setting
164  $mcst_settings = ilMediaCastSettings::_getInstance();
165  $treshold = (int) $mcst_settings->getVideoCompletionThreshold();
166 
167  $main_tpl->addJavaScript("assets/js/MediaObjectsCompletion.js");
168  $ctrl->setParameter($this, "mob_tracking_ref_id", $tracking_container_ref_id);
169  $ctrl->setParameter($this, "mob_tracking_mob_id", $mob->getId());
170  $url = $ctrl->getLinkTarget($this, "saveCompletion");
171  $audio = $image->withAdditionalOnLoadCode(function ($id) use ($url, $treshold) {
172  $js = <<<EOT
173  document.getElementById('$id').dataset.mobCompletionCallback = '$url';
174  document.getElementById('$id').dataset.mobCompletionThreshold = '$treshold';
175  il.MediaObjectsCompletion.init();
176 EOT;
177  return $js;
178  });
179  }
180  return $image;
181  }
182 
186  public function video(
187  ilObjMediaObject $mob,
188  int $tracking_container_ref_id = 0
189  ): ?\ILIAS\UI\Component\Player\Video {
190  $main_tpl = $this->gui->ui()->mainTemplate();
191 
192  $ctrl = $this->gui->ctrl();
193 
194  $med = $mob->getMediaItem("Standard");
195 
196  if (is_null($med) || !$this->media_type->isVideo($med->getFormat())) {
197  return null;
198  }
199 
200  $source = $mob->getStandardSrc();
201 
202  $video = $this->gui->ui()->factory()->player()->video(
203  $source,
204  ""
205  );
206 
207  if ($tracking_container_ref_id > 0) {
208  // @todo: make this a media object general setting
209  $mcst_settings = ilMediaCastSettings::_getInstance();
210  $treshold = (int) $mcst_settings->getVideoCompletionThreshold();
211 
212  $main_tpl->addJavaScript("assets/js/MediaObjectsCompletion.js");
213  $ctrl->setParameter($this, "mob_tracking_ref_id", $tracking_container_ref_id);
214  $ctrl->setParameter($this, "mob_tracking_mob_id", $mob->getId());
215  $url = $ctrl->getLinkTarget($this, "saveCompletion");
216  $audio = $video->withAdditionalOnLoadCode(function ($id) use ($url, $treshold) {
217  $js = <<<EOT
218  document.getElementById('$id').dataset.mobCompletionCallback = '$url';
219  document.getElementById('$id').dataset.mobCompletionThreshold = '$treshold';
220  il.MediaObjectsCompletion.init();
221 EOT;
222  return $js;
223  });
224  }
225  return $video;
226  }
227 
228  protected function saveCompletion(): void
229  {
230  $ref_id = $this->request->getTrackingRefId();
231  $mob_id = $this->request->getTrackingMobId();
232  $this->tracking->saveCompletion($mob_id, $ref_id);
233  }
234 }
ILIAS MediaObjects Player PlayerGUIRequest $request
Interface Observer Contains several chained tasks and infos about them.
$url
Definition: shib_logout.php:66
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
audio(ilObjMediaObject $mob, int $tracking_container_ref_id=0)
$ref_id
Definition: ltiauth.php:65
ILIAS MediaObjects MediaType MediaTypeManager $media_type
getMediaItem(string $a_purpose)
get item for media purpose
image(ilObjMediaObject $mob, int $tracking_container_ref_id=0)
video(ilObjMediaObject $mob, int $tracking_container_ref_id=0)
__construct(InternalDomainService $domain_service, InternalGUIService $gui_service)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
ILIAS MediaObjects Tracking TrackingManager $tracking
getComponent(ilObjMediaObject $mob, int $tracking_container_ref_id=0)
renderComponent(ilObjMediaObject $mob, int $tracking_container_ref_id=0)