ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.GUIService.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
27{
28 protected \ilGlobalTemplateInterface $tpl;
31
32 public function __construct(
35 ) {
36 $this->gui_service = $gui_service;
37 $this->domain_service = $domain_service;
38 $this->tpl = $gui_service->ui()->mainTemplate();
39 $lng = $this->domain_service->lng();
40 $lng->loadLanguageModule("mob");
41 }
42
44 int $mob_id,
45 string $gui_class,
46 string $extract_cmd = "extractPreviewImage"
47 ): void {
48 $toolbar = $this->gui_service->toolbar();
49 $ctrl = $this->gui_service->ctrl();
50 $lng = $this->domain_service->lng();
51
52 if (\ilFFmpeg::enabled()) {
53 $mob = new \ilObjMediaObject($mob_id);
54
55 $conv_cnt = 0;
56 // we had other purposes as source as well, but
57 // currently only "Standard" is implemented in the convertFile method
58 $p = "Standard";
59 $med = $mob->getMediaItem($p);
60 if (is_object($med)) {
61 if (\ilFFmpeg::supportsImageExtraction($med->getFormat())) {
62 // second
63 $ni = new \ilTextInputGUI($lng->txt("mob_second"), "sec");
64 $ni->setMaxLength(4);
65 $ni->setSize(4);
66 $ni->setValue(1);
67 $toolbar->addInputItem($ni, true);
68
69 $toolbar->addFormButton($lng->txt("mob_extract_preview_image"), "extractPreviewImage");
70 $toolbar->setFormAction($ctrl->getFormActionByClass($gui_class));
71 }
72 }
73 }
74 }
75
76 public function handleExtractionRequest(
77 int $mob_id
78 ): void {
79 $mob = new \ilObjMediaObject($mob_id);
80 $lng = $this->domain_service->lng();
81 $add = "";
82 try {
83 $sec = $this->gui_service->standardRequest()->getSeconds();
84 if ($sec < 0) {
85 $sec = 0;
86 }
87
88 $mob->generatePreviewPic(320, 240, $sec);
89 if ($mob->getVideoPreviewPic() !== "") {
90 $this->tpl->setOnScreenMessage('info', $lng->txt("mob_image_extracted"), true);
91 } else {
92 $this->tpl->setOnScreenMessage('failure', $lng->txt("mob_no_extraction_possible"), true);
93 }
94 } catch (\ilException $e) {
95 if (DEVMODE === 1) {
97 $add = (is_array($ret) && count($ret) > 0)
98 ? "<br />" . implode("<br />", $ret)
99 : "";
100 }
101 $this->tpl->setOnScreenMessage('failure', $e->getMessage() . $add, true);
102 }
103 }
104
105 protected function checkPreviewPossible(int $mob_id): bool
106 {
107 if ($mob_id === 0) {
108 return false;
109 }
110 $mob = new \ilObjMediaObject($mob_id);
111 $med = $mob->getMediaItem("Standard");
112 if (is_object($med)) {
113 if (\ilFFmpeg::supportsImageExtraction($med->getFormat())) {
114 return true;
115 }
116 }
117 return false;
118 }
119
120 public function addPreviewInput(\ilPropertyFormGUI $form, int $mob_id = 0): void
121 {
122 if (!$this->checkPreviewPossible($mob_id)) {
123 return;
124 }
125 $lng = $this->domain_service->lng();
126 $pp = new \ilImageFileInputGUI($lng->txt("mob_preview_picture"), "preview_pic");
127 $pp->setSuffixes(array("png", "jpeg", "jpg"));
128 $form->addItem($pp);
129
130 if ($mob_id > 0) {
131 $mob = new \ilObjMediaObject($mob_id);
132 // preview
133 $ppic = $mob->getVideoPreviewPic();
134 if ($ppic !== "") {
135 $pp->setImage($ppic . "?rand=" . rand(0, 1000));
136 }
137 }
138 }
139
140 public function savePreviewInput(\ilPropertyFormGUI $form, int $mob_id): void
141 {
142 if (!$this->checkPreviewPossible($mob_id)) {
143 return;
144 }
145 $prevpic = $form->getInput("preview_pic");
146 if ($prevpic["size"] > 0) {
147 $mob = new \ilObjMediaObject($mob_id);
148 $mob->uploadVideoPreviewPic($prevpic);
149 } else {
150 $prevpici = $form->getItemByPostVar("preview_pic");
151 if ($prevpici->getDeletionFlag()) {
152 $mob = new \ilObjMediaObject($mob_id);
153 $mob->removeAdditionalFile($mob->getVideoPreviewPic(true));
154 }
155 }
156
157 }
158}
addPreviewExtractionToToolbar(int $mob_id, string $gui_class, string $extract_cmd="extractPreviewImage")
addPreviewInput(\ilPropertyFormGUI $form, int $mob_id=0)
__construct(InternalDomainService $domain_service, InternalGUIService $gui_service)
ilGlobalTemplateInterface $tpl
savePreviewInput(\ilPropertyFormGUI $form, int $mob_id)
Base class for ILIAS Exception handling.
static enabled()
Checks, whether FFmpeg support is enabled (path is set in the setup)
static getLastReturnValues()
Get last return values.
static supportsImageExtraction(string $a_mime)
Check if mime type supports image extraction.
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
getItemByPostVar(string $a_post_var)
global $lng
Definition: privfeed.php:31