ILIAS  release_8 Revision v8.24
class.ilContentStyleImageGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
23
30{
32 protected ilLanguage $lng;
38 protected ?string $current_image = null;
42 protected array $current_images = [];
43
44 public function __construct(
45 Content\InternalDomainService $domain_service,
46 Content\InternalGUIService $gui_service,
49 ) {
50 $this->access_manager = $access_manager;
51
52 $this->lng = $domain_service->lng();
53 $this->lng->loadLanguageModule("content");
54
55 $this->request = $gui_service
56 ->standardRequest();
57 $this->gui = $gui_service;
58
59 $images = $this->request->getFiles();
60 if (count($images) == 1 && $manager->filenameExists(current($images))) {
61 $this->current_image = current($images);
62 $this->current_images = $images;
63 } else {
64 $this->current_images = array_filter($images, function ($i) use ($manager) {
65 return $manager->filenameExists($i);
66 });
67 }
68
69 $this->manager = $manager;
70 $this->tpl = $gui_service->mainTemplate();
71 }
72
73 public function executeCommand(): void
74 {
75 $ctrl = $this->gui->ctrl();
76
77 $next_class = $ctrl->getNextClass($this);
78 $cmd = $ctrl->getCmd("listImages");
79
80 switch ($next_class) {
81 default:
82 if (in_array($cmd, [
83 "listImages", "addImage", "cancelUpload", "uploadImage", "deleteImage",
84 "resizeImageForm", "resizeImage"
85 ])) {
86 $this->$cmd();
87 }
88 }
89 }
90
91 public function listImages(): void
92 {
93 $tpl = $this->gui->mainTemplate();
94 $ilToolbar = $this->gui->toolbar();
95 $ilCtrl = $this->gui->ctrl();
97
98 if ($this->access_manager->checkWrite()) {
99 $ilToolbar->addButton(
100 $lng->txt("sty_add_image"),
101 $ilCtrl->getLinkTarget($this, "addImage")
102 );
103 }
104
105 $table_gui = new ilStyleImageTableGUI(
106 $this,
107 "listImages",
108 $this->access_manager,
109 $this->manager
110 );
111 $tpl->setContent($table_gui->getHTML());
112 }
113
114 public function addImage(): void
115 {
116 $tpl = $this->gui->mainTemplate();
117
118 $form = $this->getImageForm();
119 $tpl->setContent($form->getHTML());
120 }
121
122 public function cancelUpload(): void
123 {
124 $ilCtrl = $this->gui->ctrl();
125
126 $ilCtrl->redirect($this, "listImages");
127 }
128
129 public function uploadImage(): void
130 {
131 $tpl = $this->gui->mainTemplate();
132 $ilCtrl = $this->gui->ctrl();
133
134 $form = $this->getImageForm();
135
136 if ($form->checkInput()) {
137 $this->manager->uploadImage();
138 $ilCtrl->redirect($this, "listImages");
139 } else {
140 //$this->form_gui->setImageFormValuesByPost();
141 $tpl->setContent($form->getHTML());
142 }
143 }
144
145 protected function getImageForm(): ilPropertyFormGUI
146 {
148 $ilCtrl = $this->gui->ctrl();
149
150 $form_gui = new ilPropertyFormGUI();
151
152 $form_gui->setTitle($lng->txt("sty_add_image"));
153
154 $file_input = new ilImageFileInputGUI($lng->txt("sty_image_file"), "image_file");
155 $file_input->setSuffixes(["jpg","jpeg","png","gif","svg"]);
156 $file_input->setRequired(true);
157 $form_gui->addItem($file_input);
158
159 $form_gui->addCommandButton("uploadImage", $lng->txt("upload"));
160 $form_gui->addCommandButton("cancelUpload", $lng->txt("cancel"));
161 $form_gui->setFormAction($ilCtrl->getFormAction($this));
162
163 return $form_gui;
164 }
165
166 public function deleteImage(): void
167 {
168 $ilCtrl = $this->gui->ctrl();
169 foreach ($this->current_images as $i) {
170 $this->manager->deleteByFilename($i);
171 }
172 $ilCtrl->redirect($this, "listImages");
173 }
174
175 protected function resizeImageForm(): void
176 {
177 $this->tpl->setContent($this->getResizeImageForm()->getHTML());
178 }
179
181 {
182 $ctrl = $this->gui->ctrl();
184
185 $form = new ilPropertyFormGUI();
186
187 $image = $this->manager->getByFilename($this->current_image);
188
189 // width height
190 $width_height = new ilWidthHeightInputGUI($lng->txt("cont_width") .
191 " / " . $lng->txt("cont_height"), "width_height");
192 $width_height->setConstrainProportions(true);
193 $width_height->setHeight($image->getHeight());
194 $width_height->setWidth($image->getWidth());
195 $form->addItem($width_height);
196
197 // file
198 $hi = new ilHiddenInputGUI("file");
199 $hi->setValue($this->current_image);
200 $form->addItem($hi);
201
202 $form->addCommandButton("resizeImage", $lng->txt("sty_resize"));
203
204 $form->setTitle($lng->txt("sty_resize_image"));
205 $form->setFormAction($ctrl->getFormAction($this));
206
207 return $form;
208 }
209
210 public function resizeImage(): void
211 {
212 $ctrl = $this->gui->ctrl();
214 $main_tpl = $this->gui->mainTemplate();
215
216 $form = $this->getResizeImageForm();
217 if ($form->checkInput()) {
218 $wh = $form->getInput("width_height");
219
220 $this->manager->resizeImage(
221 $this->current_image,
222 (int) ($wh["width"] ?? 0),
223 (int) ($wh["height"] ?? 0),
224 (bool) ($wh["const_prop"] ?? false)
225 );
226
227 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
228 $ctrl->redirect($this, "listImages");
229 } else {
230 $form->setValuesByPost();
231 $main_tpl->setContent($form->getHTML());
232 }
233 }
234}
Manages access to content style editing.
Main business logic for content style images.
Content style internal ui factory.
ilGlobalTemplateInterface $tpl
Content InternalGUIService $gui
__construct(Content\InternalDomainService $domain_service, Content\InternalGUIService $gui_service, Access\StyleAccessManager $access_manager, Content\ImageManager $manager)
Content StandardGUIRequest $request
Access StyleAccessManager $access_manager
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...
language handling
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a property form user interface.
TableGUI class for style editor (image list)
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...
setContent(string $a_html)
Sets content for standard template.
$i
Definition: metadata.php:41
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...