ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
class.ilMDPublishingSettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\MetaData\Copyright\RepositoryInterface as CopyrightRepository;
25use ILIAS\Cron\Job\JobManager as CronJobManager;
26use ILIAS\UI\Factory as UIFactory;
27use ILIAS\UI\Renderer as UIRenderer;
28
33{
34 protected ilCtrl $ctrl;
36 protected ilLanguage $lng;
37 protected CronJobManager $cron_manager;
40
41 protected ?ilMDSettings $md_settings = null;
42 protected PublishingSettings $publishing_settings;
43 protected CopyrightRepository $copyright_repo;
44 protected UIFactory $ui_factory;
45 protected UIRenderer $ui_renderer;
46
48 {
49 global $DIC;
50
51 $this->ctrl = $DIC->ctrl();
52 $this->lng = $DIC->language();
53 $this->tpl = $DIC->ui()->mainTemplate();
54 $this->cron_manager = $DIC->cron()->manager();
55 $this->ui_factory = $DIC->ui()->factory();
56 $this->ui_renderer = $DIC->ui()->renderer();
57
58 $this->parent_obj_gui = $parent_obj_gui;
59 $this->access_service = new ilMDSettingsAccessService(
60 $this->parent_obj_gui->getRefId(),
61 $DIC->access()
62 );
63
64 // TODO service structure for md admin!
65 $internal = new InternalServices($DIC);
66 $this->publishing_settings = $internal->OERHarvester()->settings();
67 $this->copyright_repo = $internal->copyright()->repository();
68
69 $this->lng->loadLanguageModule("meta");
70 }
71
72 public function executeCommand(): void
73 {
74 $next_class = $this->ctrl->getNextClass($this);
75 $cmd = $this->ctrl->getCmd();
76
77 if (
78 !$this->access_service->hasCurrentUserReadAccess()
79 ) {
80 throw new ilPermissionException($this->lng->txt('no_permission'));
81 }
82
83 switch ($next_class) {
84 case strtolower(ilPropertyFormGUI::class):
85 $form = $this->initSettingsForm();
86 $this->ctrl->forwardCommand($form);
87 break;
88
89 default:
90 if (!$cmd || $cmd === 'view') {
91 $cmd = 'showPublishingSettings';
92 }
93 switch ($cmd) {
94 case 'showPublishingSettings':
96 break;
97
98 case 'savePublishingSettings':
100 break;
101
102 default:
103 throw new ilPermissionException($this->lng->txt('no_permission'));
104 }
105 break;
106 }
107 }
108
109 public function showPublishingSettings(?ilPropertyFormGUI $form = null): void
110 {
111 $message_box = $this->getConfigStatusMessageBox();
112 if (!$form instanceof ilPropertyFormGUI) {
113 $form = $this->initSettingsForm();
114 }
115 $this->tpl->setContent(
116 $this->ui_renderer->render($message_box) .
117 $form->getHTML()
118 );
119 }
120
121 public function savePublishingSettings(): void
122 {
123 if (!$this->access_service->hasCurrentUserWriteAccess()) {
124 $this->ctrl->redirect($this, 'showPublishingSettings');
125 }
126 $form = $this->initSettingsForm();
127 if ($form->checkInput()) {
128 $copyrights = [];
129 foreach ($form->getInput('copyright') as $id) {
130 $copyrights[] = (int) $id;
131 }
132
133 $modes = $form->getInput('mode');
134 $this->publishing_settings->saveManualPublishingEnabled(in_array('manual', $modes));
135 $this->publishing_settings->saveAutomaticPublishingEnabled(in_array('automatic', $modes));
136
137 $editorial_step_enabled = (bool) $form->getInput('editorial_step');
138 $this->publishing_settings->saveEditorialStepEnabled($editorial_step_enabled);
139 if ($editorial_step_enabled) {
140 $this->publishing_settings->saveContainerRefIDForEditorialStep((int) $form->getInput('target'));
141 }
142
143 $this->publishing_settings->saveContainerRefIDForPublishing((int) $form->getInput('exposed_source'));
144 $this->publishing_settings->saveCopyrightEntryIDsSelectedForPublishing(...$copyrights);
145 $this->publishing_settings->saveObjectTypesSelectedForPublishing(...$form->getInput('object_type'));
146 $this->MDSettings()->activateOAIPMH((bool) $form->getInput('oai_active'));
147 $this->MDSettings()->saveOAIRepositoryName((string) $form->getInput('oai_repository_name'));
148 $this->MDSettings()->saveOAIIdentifierPrefix((string) $form->getInput('oai_identifier_prefix'));
149 $this->MDSettings()->saveOAIContactMail((string) $form->getInput('oai_contact_mail'));
150 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
151 $this->ctrl->redirect($this, 'showPublishingSettings');
152 }
153 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'), true);
154 $form->setValuesByPost();
155 $this->showPublishingSettings($form);
156 }
157
162 {
163 $form = new ilPropertyFormGUI();
164 $form->setFormAction($this->ctrl->getFormAction($this));
165
166 if ($this->access_service->hasCurrentUserWriteAccess()) {
167 $form->addCommandButton('savePublishingSettings', $this->lng->txt('save'));
168 }
169
170 $this->addPublishingWorkflowSection($form);
171 $this->addCopyrightSection($form);
172 $this->addObjectTypeSection($form);
173 $this->addOAIPMHSection($form);
174
175 return $form;
176 }
177
182 protected function addPublishingWorkflowSection(ilPropertyFormGUI $form): void
183 {
184 $header = new ilFormSectionHeaderGUI();
185 $header->setTitle($this->lng->txt('md_publishing_workflow'));
186 $form->addItem($header);
187
188 // publishing mode
189 $mode = new ilCheckboxGroupInputGUI(
190 $this->lng->txt('md_publishing_workflow_mode'),
191 'mode'
192 );
193 $mode->setInfo($this->lng->txt('md_publishing_workflow_mode_info'));
194 $checked = [];
195 $manual_checkbox = new ilCheckboxOption(
196 $this->lng->txt('md_publishing_workflow_manual'),
197 'manual',
198 $this->lng->txt('md_publishing_workflow_manual_info')
199 );
200 if ($this->publishing_settings->isManualPublishingEnabled()) {
201 $checked[] = 'manual';
202 }
203 $mode->addOption($manual_checkbox);
204 $automatic_checkbox = new ilCheckboxOption(
205 $this->lng->txt('md_publishing_workflow_automatic'),
206 'automatic',
207 $this->lng->txt('md_publishing_workflow_automatic_info')
208 );
209 if ($this->publishing_settings->isAutomaticPublishingEnabled()) {
210 $checked[] = 'automatic';
211 }
212 $mode->addOption($automatic_checkbox);
213 $mode->setValue($checked);
214 $form->addItem($mode);
215
216 // source for exposing
217 $ex_target = new ilRepositorySelector2InputGUI(
218 $this->lng->txt('meta_oer_exposed_source'),
219 'exposed_source',
220 false,
221 $form
222 );
223
224 $ex_explorer = $ex_target->getExplorerGUI();
225 $ex_explorer->setRootId(ROOT_FOLDER_ID);
226 $ex_explorer->setTypeWhiteList(['cat']);
227
228 $ex_target_ref_id = $this->publishing_settings->getContainerRefIDForPublishing();
229 if ($ex_target_ref_id) {
230 $ex_explorer->setPathOpen($ex_target_ref_id);
231 $ex_target->setValue($ex_target_ref_id);
232 }
233
234 $ex_target->setRequired(true);
235 $form->addItem($ex_target);
236
237 // target selection
238 $checkbox = new ilCheckboxInputGUI(
239 $this->lng->txt('meta_oer_editorial_step_toggle'),
240 'editorial_step'
241 );
242 $checkbox->setInfo($this->lng->txt('meta_oer_editorial_step_info'));
243 $checkbox->setChecked($this->publishing_settings->isEditorialStepEnabled());
244 $form->addItem($checkbox);
245
246 $target = new ilRepositorySelector2InputGUI(
247 $this->lng->txt('meta_oer_editorial_category'),
248 'target',
249 false,
250 $form
251 );
252
253 $explorer = $target->getExplorerGUI();
254 $explorer->setRootId(ROOT_FOLDER_ID);
255 $explorer->setTypeWhiteList(['cat']);
256
257 $target_ref_id = $this->publishing_settings->getContainerRefIDForEditorialStep();
258 if ($target_ref_id) {
259 $explorer->setPathOpen($target_ref_id);
260 $target->setValue($target_ref_id);
261 }
262
263 $target->setRequired(true);
264 $checkbox->addSubItem($target);
265 }
266
267 protected function addCopyrightSection(ilPropertyFormGUI $form): void
268 {
269 $header = new ilFormSectionHeaderGUI();
270 $header->setTitle($this->lng->txt('meta_oer_harvested_licences'));
271 $form->addItem($header);
272
273 $checkbox_group = new ilCheckboxGroupInputGUI(
274 $this->lng->txt('meta_oer_copyright_selection'),
275 'copyright'
276 );
277 $checkbox_group->setValue($this->publishing_settings->getCopyrightEntryIDsSelectedForPublishing());
278 $checkbox_group->setInfo(
279 $this->lng->txt('meta_oer_copyright_selection_info')
280 );
281
282 foreach ($this->copyright_repo->getAllEntries() as $copyright_entry) {
283 if ($copyright_entry->isDefault()) {
284 continue;
285 }
286 $copyright_checkbox = new ilCheckboxOption(
287 $copyright_entry->title(),
288 (string) $copyright_entry->id(),
289 $copyright_entry->description()
290 );
291 $checkbox_group->addOption($copyright_checkbox);
292 }
293 $checkbox_group->setRequired(true);
294 $form->addItem($checkbox_group);
295 }
296
297 protected function addObjectTypeSection(ilPropertyFormGUI $form): void
298 {
299 $header = new ilFormSectionHeaderGUI();
300 $header->setTitle($this->lng->txt('meta_oer_harvested_types'));
301 $form->addItem($header);
302
303 $checkbox_group = new ilCheckboxGroupInputGUI(
304 $this->lng->txt('meta_oer_object_type_selection'),
305 'object_type'
306 );
307 $checkbox_group->setRequired(true);
308 $checkbox_group->setValue($this->publishing_settings->getObjectTypesSelectedForPublishing());
309
310 foreach ($this->publishing_settings->getObjectTypesEligibleForPublishing() as $type) {
311 $type_checkbox = new ilCheckboxOption(
312 $this->lng->txt('objs_' . $type),
313 $type
314 );
315 $checkbox_group->addOption($type_checkbox);
316 }
317 $form->addItem($checkbox_group);
318 }
319
320 protected function addOAIPMHSection(ilPropertyFormGUI $form): void
321 {
322 $header = new ilFormSectionHeaderGUI();
323 $header->setTitle($this->lng->txt('md_settings_publishing'));
324 $form->addItem($header);
325
326 $oai_check = new ilCheckboxInputGUI($this->lng->txt('md_oai_pmh_enabled'), 'oai_active');
327 $oai_check->setChecked($this->MDSettings()->isOAIPMHActive());
328 $oai_check->setValue('1');
329 $oai_check->setInfo($this->lng->txt('md_oai_pmh_enabled_info'));
330 $form->addItem($oai_check);
331
332 $oai_repo_name = new ilTextInputGUI($this->lng->txt('md_oai_repository_name'), 'oai_repository_name');
333 $oai_repo_name->setValue($this->MDSettings()->getOAIRepositoryName());
334 $oai_repo_name->setInfo($this->lng->txt('md_oai_repository_name_info'));
335 $oai_repo_name->setRequired(true);
336 $oai_check->addSubItem($oai_repo_name);
337
338 $oai_id_prefix = new ilTextInputGUI($this->lng->txt('md_oai_identifier_prefix'), 'oai_identifier_prefix');
339 $oai_id_prefix->setValue($this->MDSettings()->getOAIIdentifierPrefix());
340 $oai_id_prefix->setInfo($this->lng->txt('md_oai_identifier_prefix_info'));
341 $oai_id_prefix->setRequired(true);
342 $oai_check->addSubItem($oai_id_prefix);
343
344 $oai_contact_mail = new ilTextInputGUI($this->lng->txt('md_oai_contact_mail'), 'oai_contact_mail');
345 $oai_contact_mail->setValue($this->MDSettings()->getOAIContactMail());
346 $oai_contact_mail->setRequired(true);
347 $oai_check->addSubItem($oai_contact_mail);
348 }
349
351 {
352 $enabled = $this->lng->txt('meta_publishing_config_enabled');
353 $disabled = $this->lng->txt('meta_publishing_config_disabled');
354
355 $text = $this->lng->txt('meta_publishing_config_status') . '<br/>' .
356 sprintf(
357 $this->lng->txt('meta_publishing_config_cp'),
358 $this->MDSettings()->isCopyrightSelectionActive() ? $enabled : $disabled
359 ) . '<br/>' .
360 sprintf(
361 $this->lng->txt('meta_publishing_config_harvester'),
362 $this->isOERHarvesterActive() ? $enabled : $disabled
363 );
364
365 $url = $this->ctrl->getLinkTargetByClass(
366 [ilAdministrationGUI::class, ilObjCronGUI::class],
367 );
368 $link = $this->ui_factory->link()->standard(
369 $this->lng->txt('meta_publishing_config_cron_job_admin'),
370 $url,
371 );
372
373 return $this->ui_factory->messageBox()->info($text)->withLinks([$link]);
374 }
375
376 protected function isOERHarvesterActive(): bool
377 {
378 return $this->cron_manager->isJobActive(ilCronOerHarvester::CRON_JOB_IDENTIFIER);
379 }
380
381 protected function MDSettings(): ilMDSettings
382 {
383 if (!isset($this->md_settings)) {
384 $this->md_settings = ilMDSettings::_getInstance();
385 }
386 return $this->md_settings;
387 }
388}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
This class represents a property in a property form.
This class represents a checkbox property in a property form.
This class represents an option in a checkbox group.
Class ilCtrl provides processing control methods.
This class represents a section header in a property form.
language handling
@ilCtrl_Calls ilMDPublishingSettingsGUI: ilPropertyFormGUI
addObjectTypeSection(ilPropertyFormGUI $form)
initSettingsForm()
TODO move to KS when repository picker is available there.
__construct(ilObjMDSettingsGUI $parent_obj_gui)
ilMDSettingsAccessService $access_service
addPublishingWorkflowSection(ilPropertyFormGUI $form)
addCopyrightSection(ilPropertyFormGUI $form)
showPublishingSettings(?ilPropertyFormGUI $form=null)
This class represents a property form user interface.
This class represents a text property in a property form.
const ROOT_FOLDER_ID
Definition: constants.php:32
An entity that renders components to a string output.
Definition: Renderer.php:31
global $DIC
Definition: shib_login.php:26
$url
Definition: shib_logout.php:70
$text
Definition: xapiexit.php:21