ILIAS  release_8 Revision v8.24
class.ilCourseParticipantsGroupsGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=0);
4
23
30{
31 private int $ref_id = 0;
32
34 protected ilLanguage $lng;
40 protected Factory $refinery;
41
42 public function __construct($a_ref_id)
43 {
44 global $DIC;
45
46 $this->access = $DIC->access();
47 $this->ctrl = $DIC->ctrl();
48 $this->lng = $DIC->language();
49 $this->error = $DIC['ilErr'];
50 $this->tpl = $DIC->ui()->mainTemplate();
51 $this->objectDataCache = $DIC['ilObjDataCache'];
52 $this->http = $DIC->http();
53 $this->refinery = $DIC->refinery();
54
55 $this->ref_id = $a_ref_id;
56 }
57
58 public function executeCommand(): void
59 {
60 if (!$this->access->checkRbacOrPositionPermissionAccess('manage_members', 'manage_members', $this->ref_id)) {
61 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->WARNING);
62 }
63 $cmd = $this->ctrl->getCmd();
64 if (!$cmd) {
65 $cmd = "show";
66 }
67 $this->$cmd();
68 }
69
70 public function show(): void
71 {
72 $tbl_gui = new ilCourseParticipantsGroupsTableGUI($this, "show", $this->ref_id);
73 $this->tpl->setContent($tbl_gui->getHTML());
74 }
75
76 public function applyFilter(): void
77 {
78 $tbl_gui = new ilCourseParticipantsGroupsTableGUI($this, "show", $this->ref_id);
79 $tbl_gui->resetOffset();
80 $tbl_gui->writeFilterToSession();
81 $this->show();
82 }
83
84 public function resetFilter(): void
85 {
86 $tbl_gui = new ilCourseParticipantsGroupsTableGUI($this, "show", $this->ref_id);
87 $tbl_gui->resetOffset();
88 $tbl_gui->resetFilter();
89 $this->show();
90 }
91
92 public function confirmRemove(): void
93 {
94 $grp_id = 0;
95 if ($this->http->wrapper()->query()->has('grp_id')) {
96 $grp_id = $this->http->wrapper()->query()->retrieve(
97 'grp_id',
98 $this->refinery->kindlyTo()->int()
99 );
100 }
101 $confirm = new ilConfirmationGUI();
102 $confirm->setFormAction($this->ctrl->getFormAction($this, 'remove'));
103 $confirm->addHiddenItem("grp_id", $grp_id);
104 $confirm->setHeaderText($this->lng->txt('grp_dismiss_member'));
105 $confirm->setConfirm($this->lng->txt('confirm'), 'remove');
106 $confirm->setCancel($this->lng->txt('cancel'), 'show');
107
108 $usr_id = 0;
109 if ($this->http->wrapper()->query()->has('usr_id')) {
110 $usr_id = $this->http->wrapper()->query()->retrieve(
111 'usr_id',
112 $this->refinery->kindlyTo()->int()
113 );
114 }
115 $confirm->addItem(
116 'usr_id',
117 $usr_id,
118 ilUserUtil::getNamePresentation($usr_id, false, false, "", true),
119 ilUtil::getImagePath('icon_usr.svg')
120 );
121
122 $this->tpl->setContent($confirm->getHTML());
123 }
124
125 protected function remove(): void
126 {
127 $grp_id = 0;
128 if ($this->http->wrapper()->post()->has('grp_id')) {
129 $grp_id = $this->http->wrapper()->post()->retrieve(
130 'grp_id',
131 $this->refinery->kindlyTo()->int()
132 );
133 }
134 $usr_id = 0;
135 if ($this->http->wrapper()->post()->has('usr_id')) {
136 $usr_id = $this->http->wrapper()->post()->retrieve(
137 'usr_id',
138 $this->refinery->kindlyTo()->int()
139 );
140 }
141 if (!$this->access->checkRbacOrPositionPermissionAccess('manage_members', 'manage_members', $grp_id)) {
142 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
143 $this->show();
144 return;
145 }
146
147 $members_obj = ilGroupParticipants::_getInstanceByObjId($this->objectDataCache->lookupObjId($grp_id));
148 $members_obj->delete($usr_id);
149
150 // Send notification
151 $members_obj->sendNotification(
153 (int) $usr_id
154 );
155
156 $this->tpl->setOnScreenMessage('success', $this->lng->txt("grp_msg_membership_annulled"), true);
157 $this->ctrl->redirect($this, "show");
158 }
159
160 protected function getMultiCommandGroupID(): int
161 {
162 $grp_id = 0;
163 $table_command = '';
164 if (
165 $this->http->wrapper()->post()->has('cmd') &&
166 $this->http->wrapper()->post()->has('grp_id')
167 ) {
168 $grp_id = $this->http->wrapper()->post()->retrieve(
169 'grp_id',
170 $this->refinery->kindlyTo()->int()
171 );
172 } elseif (
173 $this->http->wrapper()->post()->has('table_top_cmd') &&
174 $this->http->wrapper()->post()->has('grp_id_2')
175 ) {
176 $grp_id = $this->http->wrapper()->post()->retrieve(
177 'grp_id_2',
178 $this->refinery->kindlyTo()->int()
179 );
180 }
181 return $grp_id;
182 }
183
184 protected function add(): void
185 {
186 $grp_id = $this->getMultiCommandGroupID();
187 $usr_ids = [];
188 if ($this->http->wrapper()->post()->has('usrs')) {
189 $usr_ids = $this->http->wrapper()->post()->retrieve(
190 'usrs',
191 $this->refinery->kindlyTo()->dictOf($this->refinery->kindlyTo()->int())
192 );
193 }
194
195 if (count($usr_ids) > 0) {
196 if (!$this->access->checkRbacOrPositionPermissionAccess('manage_members', 'manage_members', $grp_id)) {
197 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
198 $this->show();
199 return;
200 }
201
202 $members_obj = ilGroupParticipants::_getInstanceByObjId($this->objectDataCache->lookupObjId($grp_id));
203 $rejected_count = 0;
204 foreach ($usr_ids as $new_member) {
205 if (!$members_obj->add($new_member, ilParticipants::IL_GRP_MEMBER)) {
206 $rejected_count++;
207 continue;
208 }
209
210 $members_obj->sendNotification(
212 $new_member
213 );
214 }
215
216 if ($rejected_count === 0) {
217 $message = $this->lng->txt('grp_msg_member_assigned');
218 } else {
219 $accepted_count = count($usr_ids) - $rejected_count;
220 $message = sprintf(
221 $this->lng->txt('grp_not_all_users_assigned_msg'),
222 $accepted_count,
223 $rejected_count
224 );
225 }
226 $this->tpl->setOnScreenMessage('success', $message);
227 }
228 $this->show();
229 }
230}
Builds data types.
Definition: Factory.php:21
error(string $a_errmsg)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCourseParticipantsGroupsGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Error Handling & global info handling uses PEAR error class.
static _getInstanceByObjId(int $a_obj_id)
Get singleton instance.
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link="", bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: feed.php:28
Interface GlobalHttpState.
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
$message
Definition: xapiexit.php:32