ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjCertificateSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
30 {
31  protected \ILIAS\HTTP\GlobalHttpState $httpState;
32  protected \ILIAS\FileUpload\FileUpload $upload;
33 
34  public function __construct($data, int $id = 0, bool $call_by_reference = true, bool $prepare_output = true)
35  {
36  global $DIC;
37 
39 
40  $this->httpState = $DIC->http();
41  $this->upload = $DIC->upload();
42  $this->type = 'cert';
43  $this->lng->loadLanguageModule('certificate');
44  $this->lng->loadLanguageModule('trac');
45  }
46 
47  public function executeCommand(): void
48  {
49  $next_class = $this->ctrl->getNextClass($this);
50  $cmd = $this->ctrl->getCmd();
51 
52  $this->prepareOutput();
53 
54  if (!$this->rbac_system->checkAccess('read', $this->object->getRefId())) {
55  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
56  }
57 
58  switch (strtolower($next_class)) {
59  case strtolower(ilPermissionGUI::class):
60  $this->tabs_gui->setTabActive('perm_settings');
61  $perm_gui = new ilPermissionGUI($this);
62  $this->ctrl->forwardCommand($perm_gui);
63  break;
64 
65  default:
66  if (!$cmd || $cmd === 'view') {
67  $cmd = 'settings';
68  }
69 
70  $this->$cmd();
71  break;
72  }
73  }
74 
75  public function getAdminTabs(): void
76  {
77  if ($this->rbac_system->checkAccess('visible,read', $this->object->getRefId())) {
78  $this->tabs_gui->addTarget(
79  'settings',
80  $this->ctrl->getLinkTarget($this, 'settings'),
81  ['settings', 'view']
82  );
83  }
84 
85  if ($this->rbac_system->checkAccess('edit_permission', $this->object->getRefId())) {
86  $this->tabs_gui->addTarget(
87  'perm_settings',
88  $this->ctrl->getLinkTargetByClass(ilPermissionGUI::class, 'perm'),
89  [],
90  strtolower(ilPermissionGUI::class)
91  );
92  }
93  }
94 
95  public function settings(): void
96  {
97  $this->tabs_gui->setTabActive('settings');
98  $form_settings = new ilSetting('certificate');
99 
100  $form = new ilPropertyFormGUI();
101  $form->setFormAction($this->ctrl->getFormAction($this));
102  $form->setTitle($this->lng->txt('certificate_settings'));
103 
104  $active = new ilCheckboxInputGUI($this->lng->txt('active'), 'active');
105  $active->setChecked((bool) $form_settings->get('active', '0'));
106  $form->addItem($active);
107 
108  $info = new ilNonEditableValueGUI($this->lng->txt('info'), 'info');
109  $info->setValue($this->lng->txt('certificate_usage'));
110  $form->addItem($info);
111 
112  $bgimage = new ilImageFileInputGUI($this->lng->txt('certificate_background_image'), 'background');
113  $bgimage->setRequired(false);
114 
115  if (strcmp($this->ctrl->getCmd(), 'save') === 0) {
116  $backgroundDelete = $this->httpState->wrapper()->post()->has('background_delete') && $this->httpState->wrapper()->post()->retrieve(
117  'background_delete',
118  $this->refinery->kindlyTo()->bool()
119  );
120  if ($backgroundDelete) {
121  $this->object->deleteBackgroundImage();
122  }
123  }
124 
125  if (
126  $this->upload->hasUploads() &&
127  $this->httpState->request()->getMethod() === 'POST' &&
128  $bgimage->checkInput()
129  ) {
130  if (!$this->upload->hasBeenProcessed()) {
131  $this->upload->process();
132  }
133 
134  if (is_array($this->upload->getResults()) && $this->upload->getResults() !== []) {
135  $results = $this->upload->getResults();
136  $file = array_pop($results);
137  if ($file->isOK()) {
138  $result = $this->object->uploadBackgroundImage($file);
139  if ($result === false) {
140  $bgimage->setAlert($this->lng->txt('certificate_error_upload_bgimage'));
141  }
142  }
143  }
144  }
145 
146  if ($this->object->hasBackgroundImage()) {
148  $bgimage->setImage(ilWACSignedPath::signFile($this->object->getDefaultBackgroundImagePathWeb()));
149  }
150  $bgimage->setInfo($this->lng->txt('default_background_info'));
151  $form->addItem($bgimage);
152  $format = new ilSelectInputGUI($this->lng->txt('certificate_page_format'), 'pageformat');
153  $defaultformats = [
154  'a4' => $this->lng->txt('certificate_a4'), // (297 mm x 210 mm)
155  'a4landscape' => $this->lng->txt('certificate_a4_landscape'), // (210 mm x 297 mm)',
156  'a5' => $this->lng->txt('certificate_a5'), // (210 mm x 148.5 mm)
157  'a5landscape' => $this->lng->txt('certificate_a5_landscape'), // (148.5 mm x 210 mm)
158  'letter' => $this->lng->txt('certificate_letter'), // (11 inch x 8.5 inch)
159  'letterlandscape' => $this->lng->txt('certificate_letter_landscape') // (11 inch x 8.5 inch)
160  ];
161  $format->setOptions($defaultformats);
162  $format->setValue($form_settings->get("pageformat", ''));
163  $format->setInfo($this->lng->txt("certificate_page_format_info"));
164  $form->addItem($format);
165 
166  if ($this->rbac_system->checkAccess('write', $this->object->getRefId())) {
167  $form->addCommandButton('save', $this->lng->txt('save'));
168  }
169 
173  $form,
174  $this
175  );
176  }
177 
178  $persistentCertificateMode = new ilRadioGroupInputGUI(
179  $this->lng->txt('persistent_certificate_mode'),
180  'persistent_certificate_mode'
181  );
182  $persistentCertificateMode->setRequired(true);
183 
184  $cronJobMode = new ilRadioOption(
185  $this->lng->txt('persistent_certificate_mode_cron'),
186  'persistent_certificate_mode_cron'
187  );
188  $cronJobMode->setInfo($this->lng->txt('persistent_certificate_mode_cron_info'));
189 
190  $instantMode = new ilRadioOption(
191  $this->lng->txt('persistent_certificate_mode_instant'),
192  'persistent_certificate_mode_instant'
193  );
194  $instantMode->setInfo($this->lng->txt('persistent_certificate_mode_instant_info'));
195 
196  $persistentCertificateMode->addOption($cronJobMode);
197  $persistentCertificateMode->addOption($instantMode);
198 
199  $persistentCertificateMode->setValue($form_settings->get(
200  'persistent_certificate_mode',
201  'persistent_certificate_mode_cron'
202  ));
203 
204  $form->addItem($persistentCertificateMode);
205 
206  $this->tpl->setContent($form->getHTML());
207  }
208 
209  public function save(): void
210  {
211  $form_settings = new ilSetting("certificate");
212 
213  $mode = $this->httpState->wrapper()->post()->retrieve(
214  'persistent_certificate_mode',
215  $this->refinery->kindlyTo()->string()
216  );
217  $previousMode = $form_settings->get('persistent_certificate_mode', 'persistent_certificate_mode_cron');
218  if ($mode !== $previousMode && $mode === 'persistent_certificate_mode_instant') {
219  $cron = new ilCertificateCron();
220  $cron->init();
221  $cron->run();
222  }
223 
224  $form_settings->set(
225  'pageformat',
226  $this->httpState->wrapper()->post()->retrieve('pageformat', $this->refinery->kindlyTo()->string())
227  );
228  $form_settings->set(
229  'active',
230  (string) ($this->httpState->wrapper()->post()->has('active') && $this->httpState->wrapper()->post()->retrieve(
231  'active',
232  $this->refinery->kindlyTo()->bool()
233  ))
234  );
235  $form_settings->set('persistent_certificate_mode', $mode);
236 
237  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'));
238  $this->settings();
239  }
240 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
prepareOutput(bool $show_sub_objects=true)
setInfo(string $a_info)
This class represents a checkbox property in a property form.
static setTokenMaxLifetimeInSeconds(int $token_max_lifetime_in_seconds)
global $DIC
Definition: feed.php:28
This class represents a property in a property form.
Class ilObjectGUI Basic methods of all Output classes.
$format
Definition: metadata.php:235
$cron
Definition: cron.php:17
$results
setRequired(bool $a_required)
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...
__construct(Container $dic, ilPlugin $plugin)
static addFieldsToForm(int $a_form_id, ilPropertyFormGUI $a_form, ilObjectGUI $a_parent_gui)
static signFile(string $path_to_file)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
__construct($data, int $id=0, bool $call_by_reference=true, bool $prepare_output=true)