ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilObjLearningSequenceAdminGUI.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
4
11{
12 const CMD_VIEW = 'view';
13 const CMD_EDIT = 'edit';
14 const CMD_SAVE = 'save';
15 const F_POLL_INTERVAL = 'polling';
16
20 protected $settings_db;
21
22 public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
23 {
24 $this->type = 'lsos';
25
26 global $DIC;
27 $this->ctrl = $DIC['ilCtrl'];
28 $this->rbacsystem = $DIC['rbacsystem'];
29 parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
30
31 $this->settings_db = new ilLSGlobalSettingsDB($DIC['ilSetting']);
32 $this->ui_factory = $DIC['ui.factory'];
33 $this->ui_renderer = $DIC['ui.renderer'];
34 $this->request = $DIC->http()->request();
35 $this->validation_factory = new \ILIAS\Validation\Factory(
36 new \ILIAS\Data\Factory(),
37 $this->lng
38 );
39 $this->transformation_factory = new \ILIAS\Transformation\Factory();
40 }
41
42 public function getAdminTabs()
43 {
44 $this->tabs_gui->addTarget('settings', $this->ctrl->getLinkTargetByClass(self::class, self::CMD_EDIT));
45 if ($this->rbacsystem->checkAccess('edit_permission', $this->object->getRefId())) {
46 $this->tabs_gui->addTarget('perm_settings', $this->ctrl->getLinkTargetByClass('ilpermissiongui', 'perm'), array(), 'ilpermissiongui');
47 }
48 }
49
50 public function executeCommand()
51 {
52 $this->checkPermission('read');
53 $next_class = $this->ctrl->getNextClass($this);
54 $cmd = $this->ctrl->getCmd();
55 $this->prepareOutput();
56
57 switch ($next_class) {
58 case 'ilpermissiongui':
59 $this->tabs_gui->setTabActive('perm_settings');
60 $perm_gui = new ilPermissionGUI($this);
61 $this->ctrl->forwardCommand($perm_gui);
62 break;
63
64 default:
65 switch ($cmd) {
66 case self::CMD_VIEW:
67 case self::CMD_EDIT:
68 $this->edit();
69 break;
70 case self::CMD_SAVE:
71 $this->save();
72 break;
73 default:
74 throw new Exception(__METHOD__ . " :: Unknown command " . $cmd);
75 }
76 }
77 }
78
79 protected function getForm(array $values = []) : Input\Container\Form\Form
80 {
81 $target = $this->ctrl->getLinkTargetByClass(self::class, self::CMD_SAVE);
82 $poll_interval = $this->ui_factory->input()->field()->numeric(
83 $this->lng->txt("lso_admin_interval_label"),
84 $this->lng->txt("lso_admin_interval_byline")
85 )
86 ->withAdditionalConstraint($this->validation_factory->greaterThan(0))
87 ->withAdditionalTransformation(
88 $this->transformation_factory->custom(
89 function ($v) {
90 return (float) $v;
91 }
92 )
93 );
94
95 if (isset($values[self::F_POLL_INTERVAL])) {
96 $poll_interval = $poll_interval->withValue($values[self::F_POLL_INTERVAL]);
97 }
98
99 $section = $this->ui_factory->input()->field()->section(
100 [self::F_POLL_INTERVAL => $poll_interval],
101 $this->lng->txt("lso_admin_form_title"),
102 $this->lng->txt("lso_admin_form_byline")
103 );
104 $form = $this->ui_factory->input()->container()->form()
105 ->standard($target, [$section])
106 ->withAdditionalTransformation(
107 $this->transformation_factory->custom(
108 function ($data) {
109 return array_shift($data);
110 }
111 )
112 );
113
114 return $form;
115 }
116
117 protected function show(Input\Container\Form\Form $form)
118 {
119 $this->tpl->setContent(
120 $this->ui_renderer->render($form)
121 );
122 }
123
124 protected function edit()
125 {
126 $values = [
127 self::F_POLL_INTERVAL => $this->settings_db->getSettings()->getPollingIntervalSeconds()
128 ];
129 $form = $this->getForm($values);
130 $this->show($form);
131 }
132
133 protected function save()
134 {
135 $form = $this->getForm()->withRequest($this->request);
136 $data = $form->getData();
137 if ($data) {
138 $settings = $this->settings_db->getSettings()
139 ->withPollingIntervalSeconds($data[self::F_POLL_INTERVAL]);
140 $this->settings_db->storeSettings($settings);
141 }
142 $this->show($form);
143 }
144}
$section
Definition: Utf8Test.php:83
An exception for terminatinating execution or to throw for unit testing.
Repository for LSGlobalSettings over ILIAS global settings.
LearningSequence Administration Settings.
__construct($a_data, $a_id, $a_call_by_reference=true, $a_prepare_output=true)
getAdminTabs()
administration tabs show only permissions and trash folder
Class ilObjectGUI Basic methods of all Output classes.
checkPermission($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission and redirect on error.
prepareOutput($a_show_subobjects=true)
prepare output
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
This is how a factory for inputs looks like.
Definition: Factory.php:11
$target
Definition: test.php:19
Class BaseForm.
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
$values