ILIAS  release_8 Revision v8.24
class.ilObjContactAdministrationGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
30{
31 public function __construct(int $a_id = 0, int $a_id_type = self::REPOSITORY_NODE_ID, int $a_parent_node_id = 0)
32 {
33 parent::__construct($a_id, $a_id_type, $a_parent_node_id);
34 $this->lng->loadLanguageModule('buddysystem');
35 }
36
37 public function getType(): string
38 {
39 return 'cadm';
40 }
41
42 public function getAdminTabs(): void
43 {
44 if ($this->checkPermissionBool('read')) {
45 $this->tabs_gui->addTarget(
46 'settings',
47 $this->ctrl->getLinkTarget($this, 'showConfigurationForm'),
48 ['', 'view', 'showConfigurationForm', 'saveConfigurationForm'],
49 self::class
50 );
51 }
52
53 if ($this->checkPermissionBool('edit_permission')) {
54 $this->tabs_gui->addTarget(
55 'perm_settings',
56 $this->ctrl->getLinkTargetByClass([self::class, ilPermissionGUI::class], 'perm'),
57 ['perm', 'info', 'owner'],
58 ilPermissionGUI::class
59 );
60 }
61 }
62
63 public function executeCommand(): void
64 {
65 $next_class = $this->ctrl->getNextClass($this);
66 $cmd = $this->ctrl->getCmd();
67 $this->prepareOutput();
68
69 switch (strtolower($next_class)) {
70 case strtolower(ilPermissionGUI::class):
71 $perm_gui = new ilPermissionGUI($this);
72 $this->ctrl->forwardCommand($perm_gui);
73 break;
74
75 default:
76 if ($cmd === '' || $cmd === 'view') {
77 $cmd = 'showConfigurationForm';
78 }
79 $this->$cmd();
80 break;
81 }
82 }
83
84
86 {
87 $form = new ilPropertyFormGUI();
88 $form->setTitle($this->lng->txt('settings'));
89 $form->setFormAction($this->ctrl->getFormAction($this, 'saveConfigurationForm'));
90
91 $enabled = new ilCheckboxInputGUI($this->lng->txt('buddy_enable'), 'enable');
92 $enabled->setValue('1');
93 $enabled->setInfo($this->lng->txt('buddy_enable_info'));
94 $enabled->setDisabled(!$this->checkPermissionBool('write'));
95
96 $notification = new ilCheckboxInputGUI($this->lng->txt('buddy_use_osd'), 'use_osd');
97 $notification->setValue('1');
98 $notification->setInfo($this->lng->txt('buddy_use_osd_info'));
99 $notification->setDisabled(!$this->checkPermissionBool('write'));
100 $enabled->addSubItem($notification);
101
102 $form->addItem($enabled);
103
104 if ($this->checkPermissionBool('write')) {
105 $form->addCommandButton('saveConfigurationForm', $this->lng->txt('save'));
106 }
107
108 return $form;
109 }
110
111
112 protected function showConfigurationForm(ilPropertyFormGUI $form = null): void
113 {
114 if (!$this->rbac_system->checkAccess('visible,read', $this->object->getRefId())) {
115 $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
116 }
117
118 if (!($form instanceof ilPropertyFormGUI)) {
119 $cfg = ilNotificationDatabaseHandler::loadUserConfig(-1);
120
121 $form = $this->getConfigurationForm();
122 $form->setValuesByArray([
123 'enable' => (bool) ilBuddySystem::getInstance()->getSetting('enabled', '0'),
124 'use_osd' => isset($cfg['buddysystem_request']) && in_array('osd', $cfg['buddysystem_request'], true)
125 ]);
126 }
127
128 $this->tpl->setContent($form->getHTML());
129 }
130
131
132 protected function saveConfigurationForm(): void
133 {
134 $this->checkPermission('write');
135
136 $form = $this->getConfigurationForm();
137 if (!$form->checkInput()) {
138 $form->setValuesByPost();
139 $this->showConfigurationForm($form);
140 return;
141 }
142
143 ilBuddySystem::getInstance()->setSetting('enabled', (string) ($form->getInput('enable') ? 1 : 0));
144
145 $cfg = ilNotificationDatabaseHandler::loadUserConfig(-1);
146
147 $new_cfg = [];
148 foreach ($cfg as $type => $channels) {
149 $new_cfg[$type] = [];
150 foreach ($channels as $channel) {
151 $new_cfg[$type][$channel] = true;
152 }
153 }
154
155 if (!isset($new_cfg['buddysystem_request']) || !is_array($new_cfg['buddysystem_request'])) {
156 $new_cfg['buddysystem_request'] = [];
157 }
158
159 if (!array_key_exists('osd', $new_cfg['buddysystem_request']) && $form->getInput('use_osd')) {
160 $new_cfg['buddysystem_request']['osd'] = true;
161 } elseif (array_key_exists('osd', $new_cfg['buddysystem_request']) && !(bool) $form->getInput('use_osd')) {
162 $new_cfg['buddysystem_request']['osd'] = false;
163 }
164
165 ilNotificationDatabaseHandler::setUserConfig(-1, $new_cfg);
166
167 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
168 $this->ctrl->redirect($this);
169 }
170}
error(string $a_errmsg)
This class represents a checkbox property in a property form.
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.
showConfigurationForm(ilPropertyFormGUI $form=null)
getAdminTabs()
administration tabs show only permissions and trash folder
New implementation of ilObjectGUI.
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $node_id=null)
prepareOutput(bool $show_sub_objects=true)
checkPermission(string $perm, string $cmd="", string $type="", int $ref_id=null)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
This class represents a property form user interface.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
bool $enabled
Whether the system instance is enabled to accept connection requests.
Definition: System.php:123
getSetting(string $name, string $default='')
Get a setting value.
Definition: System.php:253