ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjPDFGenerationGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
26  private string $active_tab = '';
28 
29  public function __construct(int $a_id = 0, int $a_id_type = self::REPOSITORY_NODE_ID, int $a_parent_node_id = 0)
30  {
31  global $DIC;
32  parent::__construct($a_id, $a_id_type, $a_parent_node_id);
33  $this->lng->loadLanguageModule('pdfgen');
34  $this->pdfRequest = new ilPDFGenerationRequest($this->refinery, $DIC->http());
35  }
36 
37  protected function hasWritePermission(): bool
38  {
39  return $this->checkPermissionBool('write');
40  }
41 
42  public function getType(): string
43  {
44  return 'pdfg';
45  }
46 
47  public function executeCommand(): void
48  {
49  $next_class = $this->ctrl->getNextClass();
50  $cmd = $this->ctrl->getCmd();
51  $this->prepareOutput();
52 
53  switch (strtolower($next_class)) {
54  case strtolower(ilPermissionGUI::class):
55  $this->tabs_gui->setTabActive('perm_settings');
56  $perm_gui = new ilPermissionGUI($this);
57  $this->ctrl->forwardCommand($perm_gui);
58  break;
59 
60  default:
61  if ($cmd === null || $cmd === '' || $cmd === 'view') {
62  $cmd = 'configForm';
63  }
64 
65  if (strpos($cmd, 'saveandconf_selected_') === 0) {
66  $this->handleSaveAndConf(substr($cmd, 21));
67  } else {
68  $this->$cmd();
69  }
70  break;
71  }
72  }
73 
74  public function configForm(): void
75  {
76  $form = new ilPropertyFormGUI();
77  $form->setFormAction($this->ctrl->getFormAction($this, 'view'));
78  $purpose_map = ilPDFGeneratorUtils::getPurposeMap();
79  $selection_map = ilPDFGeneratorUtils::getSelectionMap();
80  $renderers = ilPDFGeneratorUtils::getRenderers();
81  foreach ($purpose_map as $service => $purposes) {
82  foreach ($purposes as $purpose) {
83  $section = new ilFormSectionHeaderGUI();
84  $section->setTitle(ucfirst($service) . ' / ' . ucfirst($purpose));
85  $form->addItem($section);
86 
87  $preferred = new ilTextInputGUI($this->lng->txt('preferred_renderer'));
88  $preferred->setValue($selection_map[$service][$purpose]['preferred']);
89  $preferred->setDisabled(true);
90  $form->addItem($preferred);
91 
92  $selected = new ilSelectInputGUI($this->lng->txt('selected_renderer'), 'selected_' . $service . '::' . $purpose);
93  $selected->setOptions($renderers[$service][$purpose]);
94  $selected_renderer = $selection_map[$service][$purpose]['selected'];
95  $selected_index = 0;
96  foreach ($renderers[$service][$purpose] as $key => $value) {
97  if ($value === $selected_renderer) {
98  $selected_index = $key;
99  }
100  }
101  $selected->setValue($selected_index);
102  $form->addItem($selected);
103 
104  $s_button = ilSubmitButton::getInstance();
105  $s_button->setCaption('configure');
106  $s_button->setCommand('saveandconf_selected_' . $service . '::' . $purpose);
107  if (!$this->hasWritePermission()) {
108  $s_button->setDisabled(true);
109  }
110  $input_selected = new ilCustomInputGUI($this->lng->txt('configure'));
111  $input_selected->setHtml($s_button->getToolbarHTML());
112  $form->addItem($input_selected);
113  }
114  }
115 
116  if ($this->hasWritePermission()) {
117  $form->addCommandButton("saveSettings", $this->lng->txt("save"));
118  }
119 
121  $this->tpl->setOnScreenMessage('info', $this->lng->txt('problem_with_purposes'));
122  $clean_btn = ilLinkButton::getInstance();
123  $clean_btn->setCaption('cleanup');
124  $clean_btn->setUrl($this->ctrl->getLinkTarget($this, 'doCleanUp'));
125  $this->toolbar->addButtonInstance($clean_btn);
126  }
127  $this->tpl->setContent($form->getHTML());
128  $this->setActiveTab('settings');
129  }
130 
131  public function saveSettings(bool $redirect_after = true): void
132  {
133  if (!$this->hasWritePermission()) {
134  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('no_permission'), true);
135  $this->ctrl->redirect($this, "view");
136  }
137 
138  $purpose_map = ilPDFGeneratorUtils::getPurposeMap();
139  $selection_map = ilPDFGeneratorUtils::getSelectionMap();
140  $renderers = ilPDFGeneratorUtils::getRenderers();
141 
142  foreach ($purpose_map as $service => $purposes) {
143  foreach ($purposes as $purpose) {
144  $selected = $this->pdfRequest->securedString('selected_' . $service . '::' . $purpose);
145  $posted_renderer = $renderers[$service][$purpose][$selected] ?? null;
146  if ($posted_renderer === null) {
147  continue;
148  }
149 
150  $selected_renderer = $selection_map[$service][$purpose]['selected'];
151  if ($posted_renderer !== $selected_renderer) {
152  ilPDFGeneratorUtils::updateRendererSelection($service, $purpose, $posted_renderer);
153  }
154  }
155  }
156 
157  if ($redirect_after) {
158  $this->tpl->setOnScreenMessage('success', $this->lng->txt('config_saved'), true);
159  $this->ctrl->redirect($this, "view");
160  }
161  }
162 
163  protected function handleSaveAndConf(string $command): void
164  {
165  if (!$this->checkPermissionBool('edit')) {
166  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('no_permission'), true);
167  $this->ctrl->redirect($this, "view");
168  }
169 
170  $this->saveSettings(false);
171 
172  $form = $this->buildConfigForm($command);
173  $this->tpl->setContent($form->getHTML());
174  $this->setActiveTab('settings');
175  }
176 
177  public function resetSettings(): void
178  {
179  $renderer = $this->pdfRequest->securedString('renderer');
180  $service = $this->pdfRequest->securedString('service');
181  $purpose = $this->pdfRequest->securedString('purpose');
182 
184  $this->ctrl->redirect($this, "view");
185  }
186 
187  private function buildConfigForm(string $command, bool $populate = true): ilPropertyFormGUI
188  {
189  $parts = explode('::', $command);
190  $service = $parts[0];
191  $purpose = $parts[1];
192 
193  $renderers = ilPDFGeneratorUtils::getRenderers();
194 
195  $selected = $this->pdfRequest->securedString('selected_' . $service . '::' . $purpose);
196  $posted_renderer = $renderers[$service][$purpose][$selected];
197 
198  $form = new ilPropertyFormGUI();
199  $form->setFormAction($this->ctrl->getFormAction($this, 'view'));
200 
201  $form->setTitle($this->lng->txt('settings') . ' ' . $posted_renderer . ' / ' . $service . ' / ' . $purpose);
202  $service_hidden = new ilHiddenInputGUI('service');
203  $service_hidden->setValue($service);
204  $form->addItem($service_hidden);
205 
206  $purpose_hidden = new ilHiddenInputGUI('purpose');
207  $purpose_hidden->setValue($purpose);
208  $form->addItem($purpose_hidden);
209 
210  $renderer_hidden = new ilHiddenInputGUI('renderer');
211  $renderer_hidden->setValue($posted_renderer);
212  $form->addItem($renderer_hidden);
213 
214  $renderer_hidden = new ilHiddenInputGUI(
215  ilLegacyFormElementsUtil::prepareFormOutput('selected_' . $service . '::' . $purpose)
216  );
217  $renderer_hidden->setValue($selected);
218  $form->addItem($renderer_hidden);
219 
220  // Add In RendererConfig
221  $renderer = ilPDFGeneratorUtils::getRendererInstance($posted_renderer);
222  $renderer->addConfigElementsToForm($form, $service, $purpose);
223 
224  if ($populate) {
225  $config = ilPDFGeneratorUtils::getRendererConfig($service, $purpose, $posted_renderer);
226  $renderer->populateConfigElementsInForm($form, $service, $purpose, $config);
227  }
228 
229  $form->addCommandButton('saveConfig', $this->lng->txt('save'));
230  $form->addCommandButton('view', $this->lng->txt('cancel'));
231  $form->addCommandButton('resetSettings', $this->lng->txt('reset_to_default'));
232 
233  return $form;
234  }
235 
236  protected function saveConfig(): void
237  {
238  $renderer = $this->pdfRequest->securedString('renderer');
239  $service = $this->pdfRequest->securedString('service');
240  $purpose = $this->pdfRequest->securedString('purpose');
241 
242  $form = $this->buildConfigForm($service . '::' . $purpose, false);
243 
244  $renderer_obj = ilPDFGeneratorUtils::getRendererInstance($renderer);
245 
246  $valid_renderer_config = false;
247  if ($form->checkInput() &&
248  ($valid_renderer_config = $renderer_obj->validateConfigInForm($form, $service, $purpose))) {
249  $config = $renderer_obj->getConfigFromForm($form, $service, $purpose);
251  $this->tpl->setOnScreenMessage('success', $this->lng->txt('config_saved'), true);
252  $this->ctrl->redirect($this, 'view');
253  }
254 
255  if (!$valid_renderer_config) {
256  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
257  }
258 
259  $form->setValuesByPost();
260 
261  $this->tpl->setContent($form->getHTML());
262  $this->setActiveTab('settings');
263  }
264 
265  protected function doCleanUp(): void
266  {
268  $this->tpl->setOnScreenMessage('success', $this->lng->txt('config_saved'), true);
269  $this->ctrl->redirect($this, "view");
270  }
271 
275  public function getAdminTabs(): void
276  {
277  if (strpos($this->ctrl->getCmd(), 'saveandconf') !== 0) {
278  if ($this->checkPermissionBool('read')) {
279  $this->tabs_gui->addTarget('settings', $this->ctrl->getLinkTarget($this, 'view'), [], __CLASS__);
280  }
281 
282  if ($this->checkPermissionBool('edit_permission')) {
283  $this->tabs_gui->addTarget(
284  'perm_settings',
285  $this->ctrl->getLinkTargetByClass('ilpermissiongui', 'perm'),
286  [],
287  'ilpermissiongui'
288  );
289  }
290  } else {
291  $this->tabs_gui->setBackTarget(
292  $this->lng->txt("back"),
293  $this->ctrl->getLinkTargetByClass("ilobjpdfgenerationgui", "view")
294  );
295  }
296  }
297 
298  protected function setActiveTab(string $tab = ''): void
299  {
300  $this->tabs_gui->setTabActive($tab === '' ? $this->active_tab : $tab);
301  }
302 }
ilPDFGenerationRequest $pdfRequest
New implementation of ilObjectGUI.
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:64
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:85
static saveRendererPurposeConfig(string $service, string $purpose, string $renderer, array $config)
static getRendererConfig(string $service, string $purpose, string $renderer)
static getRendererInstance(string $renderer)
prepareOutput(bool $show_sub_objects=true)
static prepareFormOutput($a_str, bool $a_strip=false)
buildConfigForm(string $command, bool $populate=true)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $node_id=null)
saveSettings(bool $redirect_after=true)
string $key
Consumer key/client ID value.
Definition: System.php:193
static removeRendererConfig(string $service, string $purpose, string $renderer)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
__construct(int $a_id=0, int $a_id_type=self::REPOSITORY_NODE_ID, int $a_parent_node_id=0)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
static updateRendererSelection(string $service, string $purpose, string $renderer)
$service
Definition: ltiservices.php:43
static checkForMultipleServiceAndPurposeCombination()