ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjContactAdministrationGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
31{
32 public function __construct(int $a_id = 0, int $a_id_type = self::REPOSITORY_NODE_ID, int $a_parent_node_id = 0)
33 {
34 parent::__construct($a_id, $a_id_type, $a_parent_node_id);
35 $this->lng->loadLanguageModule('buddysystem');
36 }
37
38 public function getType(): string
39 {
40 return 'cadm';
41 }
42
43 public function getAdminTabs(): void
44 {
45 if ($this->checkPermissionBool('read')) {
46 $this->tabs_gui->addTarget(
47 'settings',
48 $this->ctrl->getLinkTarget($this, 'showConfigurationForm'),
49 ['', 'view', 'showConfigurationForm', 'saveConfigurationForm'],
50 self::class
51 );
52 }
53
54 if ($this->checkPermissionBool('edit_permission')) {
55 $this->tabs_gui->addTarget(
56 'perm_settings',
57 $this->ctrl->getLinkTargetByClass([self::class, ilPermissionGUI::class], 'perm'),
58 ['perm', 'info', 'owner'],
59 ilPermissionGUI::class
60 );
61 }
62 }
63
64 public function executeCommand(): void
65 {
66 $next_class = $this->ctrl->getNextClass($this) ?? '';
67 $cmd = $this->ctrl->getCmd() ?? '';
68 $this->prepareOutput();
69
70 switch (strtolower($next_class)) {
71 case strtolower(ilPermissionGUI::class):
72 $perm_gui = new ilPermissionGUI($this);
73 $this->ctrl->forwardCommand($perm_gui);
74 break;
75
76 default:
77 if ($cmd === '' || $cmd === 'view') {
78 $cmd = 'showConfigurationForm';
79 }
80 $this->$cmd();
81 break;
82 }
83 }
84
85 protected function getConfigurationForm(): StandardForm
86 {
87 $notification = $this->ui_factory->input()->field()->checkbox(
88 $this->lng->txt('buddy_use_osd'),
89 $this->lng->txt('buddy_use_osd_info')
90 )
91 ->withDisabled(!$this->checkPermissionBool('write'));
92
93 $contact_request_default = $this->ui_factory->input()->field()->select(
94 $this->lng->txt('buddy_allow_to_contact_me'),
95 [
96 'y' => $this->lng->txt('buddy_allow_to_contact_me_yes'),
97 'n' => $this->lng->txt('buddy_allow_to_contact_me_no')
98 ],
99 $this->lng->txt('buddy_allow_to_contact_me_default_info')
100 )
101 ->withRequired(true)
102 ->withDisabled(!$this->checkPermissionBool('write'));
103
104 $cfg = ilNotificationDatabaseHandler::loadUserConfig(-1);
105 $checkbox = $this->ui_factory->input()->field()->optionalGroup(
106 [
107 'use_osd' => $notification,
108 'allow_contact_request_default' => $contact_request_default
109 ],
110 $this->lng->txt('buddy_enable'),
111 $this->lng->txt('buddy_enable_info')
112 )
113 ->withValue(
114 [
115 'use_osd' => isset($cfg['buddysystem_request']) &&
116 in_array('osd', $cfg['buddysystem_request'], true),
117 'allow_contact_request_default' => $this->settings->get('bs_allow_to_contact_me', 'n')
118 ]
119 )
120 ->withDisabled(!$this->checkPermissionBool('write'));
121
122 if (ilBuddySystem::getInstance()->getSetting('enabled', '0') === '0') {
123 $checkbox = $checkbox->withValue(null);
124 }
125
126 return $this->ui_factory->input()->container()->form()->standard(
127 $this->ctrl->getFormAction($this, 'saveConfigurationForm'),
128 [
129 'enable' => $checkbox,
130 ]
131 )->withSubmitLabel(
132 $this->checkPermissionBool('write') ? $this->lng->txt('save') : $this->lng->txt('refresh')
133 );
134 }
135
136 protected function showConfigurationForm(?StandardForm $form = null): void
137 {
138 if (!$this->rbac_system->checkAccess('visible,read', $this->object->getRefId())) {
139 $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
140 }
141
142 if (!$form instanceof StandardForm) {
143 $form = $this->getConfigurationForm();
144 }
145
146 $this->tpl->setContent($this->ui_renderer->render($form));
147 }
148
149 protected function saveConfigurationForm(): void
150 {
151 $this->checkPermission('write');
152
153 $form = $this->getConfigurationForm();
154 $form = $form->withRequest($this->request);
155 if ($form->getError()) {
156 $this->showConfigurationForm($form);
157
158 return;
159 }
160
161 $data = $form->getData();
162
163 ilBuddySystem::getInstance()->setSetting(
164 'enabled',
165 (string) (isset($data['enable']) && $data['enable'] ? 1 : 0)
166 );
167
168 $cfg = ilNotificationDatabaseHandler::loadUserConfig(-1);
169
170 $new_cfg = [];
171 foreach ($cfg as $type => $channels) {
172 $new_cfg[$type] = [];
173 foreach ($channels as $channel) {
174 $new_cfg[$type][$channel] = true;
175 }
176 }
177
178 if (!isset($new_cfg['buddysystem_request']) || !is_array($new_cfg['buddysystem_request'])) {
179 $new_cfg['buddysystem_request'] = [];
180 }
181
182 if (!array_key_exists('osd', $new_cfg['buddysystem_request']) &&
183 isset($data['enable']['use_osd']) && $data['enable']['use_osd'] === true) {
184 $new_cfg['buddysystem_request']['osd'] = true;
185 } elseif (
186 array_key_exists('osd', $new_cfg['buddysystem_request']) &&
187 isset($data['enable']) &&
188 (!isset($data['enable']['use_osd']) || $data['enable']['use_osd'] === false)
189 ) {
190 $new_cfg['buddysystem_request']['osd'] = false;
191 }
192
193 ilNotificationDatabaseHandler::setUserConfig(-1, $new_cfg);
194
195 if (isset($data['enable']['allow_contact_request_default'])
196 && in_array($data['enable']['allow_contact_request_default'], ['y', 'n'])) {
197 $this->settings->set(
198 'bs_allow_to_contact_me',
199 $data['enable']['allow_contact_request_default']
200 );
201 }
202
203 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
204 $this->ctrl->redirect($this);
205 }
206}
error(string $a_errmsg)
Class ilObjContactAdministrationGUI.
__construct(int $a_id=0, int $a_id_type=self::REPOSITORY_NODE_ID, int $a_parent_node_id=0)
getType()
Functions that must be overwritten.
getAdminTabs()
administration tabs show only permissions and trash folder
New implementation of ilObjectGUI.
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $node_id=null)
checkPermission(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
prepareOutput(bool $show_sub_objects=true)
This describes a standard form.
Definition: Standard.php:29
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc