ILIAS  release_8 Revision v8.24
class.ilGroupAddToGroupActionGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
8
9/* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
10
18{
19 protected ilCtrl $ctrl;
21 protected UIServices $ui;
22 protected ilLanguage $lng;
23 protected ilTree $tree;
24 protected ilObjUser $user;
25
26
28 protected Factory $refinery;
29
30
31
32 public function __construct()
33 {
34 global $DIC;
35
36 $this->ctrl = $DIC->ctrl();
37 $this->tpl = $DIC->ui()->mainTemplate();
38 $this->ui = $DIC->ui();
39 $this->lng = $DIC->language();
40 $this->tree = $DIC->repositoryTree();
41 $this->user = $DIC->user();
42 $this->http = $DIC->http();
43 $this->refinery = $DIC->refinery();
44
45
46 $this->lng->loadLanguageModule("grp");
47 $this->ctrl->saveParameter($this, array("user_id", "modal_exists"));
48 }
49
50 protected function initGroupRefIdFromQuery(): int
51 {
52 $ref_id = 0;
53 if ($this->http->wrapper()->query()->has('grp_act_ref_id')) {
54 $ref_id = $this->http->wrapper()->query()->retrieve(
55 'grp_act_ref_id',
56 $this->refinery->kindlyTo()->int()
57 );
58 }
59 return $ref_id;
60 }
61
62 protected function initGroupParentRefIdFromQuery(): int
63 {
64 $ref_id = 0;
65 if ($this->http->wrapper()->query()->has('grp_act_par_ref_id')) {
66 $ref_id = $this->http->wrapper()->query()->retrieve(
67 'grp_act_par_ref_id',
68 $this->refinery->kindlyTo()->int()
69 );
70 }
71 return $ref_id;
72 }
73
74 protected function initUserIdFromQuery(): int
75 {
76 $user_id = 0;
77 if ($this->http->wrapper()->query()->has('user_id')) {
78 $user_id = $this->http->wrapper()->query()->retrieve(
79 'user_id',
80 $this->refinery->kindlyTo()->int()
81 );
82 }
83 return $user_id;
84 }
85
86 public function executeCommand(): void
87 {
90
91 $next_class = $ctrl->getNextClass($this);
92 $cmd = $ctrl->getCmd("show");
93
94 if ($cmd == "show") {
96 if (count($ca) == 0) {
97 return;
98 }
99 if (count($ca) == 1) {
100 switch (current($ca)) {
101 case "create_grp":
102 $cmd = "selectParent";
103 break;
104
105 case "manage_members":
106 $cmd = "selectGroup";
107 break;
108
109 default:
110 return;
111 }
112 }
113 }
114
115 switch ($next_class) {
116 default:
117 if (in_array($cmd, array("show", "selectGroup", "confirmAddUser", "addUser",
118 "selectParent", "createGroup", "confirmCreateGroupAndAddUser", "createGroupAndAddUser"))) {
119 $ctrl->setParameter($this, "modal_exists", 1);
120 $this->$cmd();
121 }
122 }
123 }
124 public function show(): void
125 {
128
129 $toolbar = new ilToolbarGUI();
130
131 // button use existing group
132 $url1 = $ctrl->getLinkTarget($this, "selectGroup", "", true);
133 $button1 = $this->ui->factory()->button()->standard($lng->txt("grp_use_existing"), "#")
134 ->withOnLoadCode(function ($id) use ($url1) {
135 return "$('#$id').on('click', function() {il.Util.ajaxReplaceInner('$url1', 'il_grp_action_modal_content'); return false;})";
136 });
137 $toolbar->addComponent($button1);
138
139 // button create new group
140 $url2 = $ctrl->getLinkTarget($this, "selectParent", "", true);
141 $button2 = $this->ui->factory()->button()->standard($lng->txt("grp_create_new"), "#")
142 ->withOnLoadCode(function ($id) use ($url2) {
143 return "$('#$id').on('click', function() {il.Util.ajaxReplaceInner('$url2', 'il_grp_action_modal_content'); return false;})";
144 });
145 $toolbar->addComponent($button2);
146
147 $this->sendResponse(
148 ilUtil::getSystemMessageHTML($lng->txt("grp_create_or_use_existing"), "question") .
149 $toolbar->getHTML()
150 );
151 }
152
153 public function sendResponse(string $a_content): void
154 {
156
157 $modal_exists = false;
158 if ($this->http->wrapper()->query()->has('modal_exists')) {
159 $modal_exists = (bool) $this->http->wrapper()->query()->retrieve(
160 'modal_exists',
161 $this->refinery->kindlyTo()->int()
162 );
163 }
164 if ($modal_exists) {
165 echo $this->ui->renderer()->renderAsync($this->ui->factory()->legacy($a_content));
166 } else {
167 $mtpl = new ilTemplate("tpl.grp_add_to_grp_modal_content.html", true, true, "./Modules/Group/UserActions");
168 $mtpl->setVariable("CONTENT", $a_content);
169 $content = $this->ui->factory()->legacy($mtpl->get());
170 $modal = $this->ui->factory()->modal()->roundtrip(
171 $lng->txt("grp_add_user_to_group"),
172 $content
173 )->withOnLoadCode(function ($id) {
174 return "il.UI.modal.showModal('$id', {'ajaxRenderUrl':'','keyboard':true}, {id: '$id'});";
175 });
176 echo $this->ui->renderer()->renderAsync($modal);
177 }
178 exit;
179 }
180
181
182 public function selectGroup(): void
183 {
185
186 $exp = new ilGroupActionTargetExplorerGUI($this, "selectGroup");
187
188 $exp->setClickableType("grp");
189 $exp->setTypeWhiteList(array("root", "cat", "crs", "fold", "grp"));
190 $exp->setPathOpen($tree->readRootId());
191
192 if (!$exp->handleCommand()) {
193 $this->sendResponse($exp->getHTML());
194 }
195 exit;
196 }
197
198 public function confirmAddUser(): void
199 {
202
204 $user_id = $this->initUserIdFromQuery();
206 if ($participants->isMember($user_id)) {
207 $url = $ctrl->getLinkTarget($this, "selectGroup", "", true);
208 $button = $this->ui->factory()->button()->standard($lng->txt("back"), "#")
209 ->withOnLoadCode(function ($id) use ($url) {
210 return "$('#$id').on('click', function() {il.Util.ajaxReplaceInner('$url', 'il_grp_action_modal_content'); return false;})";
211 });
212
213 echo
214 ilUtil::getSystemMessageHTML($lng->txt("grp_user_already_in_group") . "<br>" .
215 $lng->txt("obj_user") . ": " . ilUserUtil::getNamePresentation($user_id) . "<br>" .
216 $lng->txt("obj_grp") . ": " . ilObject::_lookupTitle(ilObject::_lookupObjId($ref_id)), "failure") .
217 $this->ui->renderer()->renderAsync($button);
218 exit;
219 }
220
221
222 // button create new group
223 $ctrl->setParameter($this, "grp_act_ref_id", $ref_id);
224 $url = $ctrl->getLinkTarget($this, "addUser", "", true);
225 $button = $this->ui->factory()->button()->standard($lng->txt("grp_add_user"), "#")
226 ->withOnLoadCode(function ($id) use ($url) {
227 return "$('#$id').on('click', function() {il.Util.ajaxReplaceInner('$url', 'il_grp_action_modal_content'); return false;})";
228 });
229
230 echo
231 ilUtil::getSystemMessageHTML($lng->txt("grp_sure_add_user_to_group") . "<br>" .
232 $lng->txt("obj_user") . ": " . ilUserUtil::getNamePresentation($user_id) . "<br>" .
233 $lng->txt("obj_grp") . ": " . ilObject::_lookupTitle(ilObject::_lookupObjId($ref_id)), "question") .
234 $this->ui->renderer()->renderAsync($button);
235 exit;
236 }
237
238 public function addUser(): void
239 {
241
243 $user_id = $this->initUserIdFromQuery();
244
245 // @todo: check permission
246
247 $group = new ilObjGroup($ref_id);
248 $participants = ilParticipants::getInstanceByObjId($group->getId());
249
250 $participants->add($user_id, ilParticipants::IL_GRP_MEMBER);
251
252 $participants->sendNotification(
254 $user_id
255 );
256
257 echo ilUtil::getSystemMessageHTML($lng->txt("grp_user_been_added"), "success");
258 echo "<script>setTimeout(function (){ il.Group.UserActions.closeModal();}, 1000);</script>";
259 exit;
260 }
261
262 public function selectParent(): void
263 {
266
267 $exp = new ilGroupActionTargetExplorerGUI($this, "selectParent", true);
268
269 $exp->setTypeWhiteList(array("root", "cat", "crs"));
270 $exp->setPathOpen($tree->readRootId());
271
272 if (!$exp->handleCommand()) {
273 $this->sendResponse(ilUtil::getSystemMessageHTML($lng->txt("grp_no_perm_to_add_create_first")) .
274 $exp->getHTML());
275 }
276
277 exit;
278 }
279
280 public function createGroup($form = null): void
281 {
283
285
286 if ($form == null) {
287 $form = $this->getGroupCreationForm();
288 }
289 $this->ctrl->saveParameter($this, "grp_act_par_ref_id");
290 $form->setFormAction($this->ctrl->getLinkTarget($this, "confirmCreateGroupAndAddUser", "", true));
291
292 echo ilUtil::getSystemMessageHTML(str_replace("%1", ilObject::_lookupTitle(ilObject::_lookupObjId($ref_id)), $lng->txt("grp_create_new_grp_in")), "info") .
293 $form->getHTML();
294 exit;
295 }
296
297
299 {
301
303
304 $group_gui = new ilObjGroupGUI("", 0, true);
305 $group_gui->setCreationMode();
306 $form = $group_gui->initForm("create", true);
307 $form->clearCommandButtons();
308 $form->addCommandButton("save", $lng->txt("grp_next"));
309 $form->setShowTopButtons(false);
310 return $form;
311 }
312
313 public function confirmCreateGroupAndAddUser(): void
314 {
316
317 $user_id = $this->initUserIdFromQuery();
318 $title = '';
319 if ($this->http->wrapper()->post()->has('title')) {
320 $title = $this->http->wrapper()->post()->retrieve(
321 'title',
322 $this->refinery->kindlyTo()->string()
323 );
324 }
325 $form = $this->getGroupCreationForm();
326
327
328
329 if (!$form->checkInput()) {
330 $this->createGroup($form);
331 return;
332 }
333
334 $this->ctrl->saveParameter($this, "grp_act_par_ref_id");
335 $form->setFormAction($this->ctrl->getLinkTarget($this, "createGroupAndAddUser", "", true));
336 $form->setValuesByPost();
337
338 $button = $this->ui->factory()->button()->standard($lng->txt("grp_create_and_add_user"), "#")
339 ->withOnLoadCode(function ($id) {
340 return "$('#$id').on('click', function(e) {il.Group.UserActions.createGroup(e);})";
341 });
342
343 echo
344 ilUtil::getSystemMessageHTML($lng->txt("grp_sure_create_group_add_user") . "<br>" .
345 $lng->txt("obj_user") . ": " . ilUserUtil::getNamePresentation($user_id) . "<br>" .
346 $lng->txt("obj_grp") . ": " . $title, "question") .
347 "<div class='ilNoDisplay'>" . $form->getHTML() . "</div>" .
348 "<div class='ilRight'>" . $this->ui->renderer()->renderAsync($button) . "</div>";
349
350 exit;
351 }
352
353 public function createGroupAndAddUser(): void
354 {
356
357 $user_id = $this->initUserIdFromQuery();
359 $form = $this->getGroupCreationForm();
360
361 $form->checkInput();
362
363 $group_gui = new ilObjGroupGUI("", 0, true);
364
365 // create instance
366 $newObj = new ilObjGroup();
367 $newObj->setType("grp");
368 $newObj->setTitle($form->getInput("title"));
369 $newObj->setDescription($form->getInput("desc"));
370 $newObj->create();
371
372 $group_gui->putObjectInTree($newObj, $ref_id);
373
374 // apply didactic template?
375 $dtpl = $group_gui->getDidacticTemplateVar("dtpl");
376 if ($dtpl) {
377 $newObj->applyDidacticTemplate($dtpl);
378 }
379
380 $group_gui->afterSave($newObj, false);
381
382
383 $participants = ilParticipants::getInstanceByObjId($newObj->getId());
384
385 $participants->add($user_id, ilParticipants::IL_GRP_MEMBER);
386
387 $participants->sendNotification(
389 $user_id
390 );
391
392
393 $url = ilLink::_getLink($newObj->getRefId());
394 echo ilUtil::getSystemMessageHTML($lng->txt("grp_created_and_user_been_added"), "success");
395 echo "<script>setTimeout(function (){ window.location.replace('$url');}, 1500);</script>";
396 exit;
397 }
398}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Provides fluid interface to RBAC services.
Definition: UIServices.php:24
Builds data types.
Definition: Factory.php:21
Class ilCtrl provides processing control methods.
getNextClass($a_gui_class=null)
@inheritDoc
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
getCmd(string $fallback_command=null)
@inheritDoc
getLinkTarget(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
Add user to group from awareness tool.
language handling
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
Class ilObjGroupGUI.
Class ilObjGroup.
User class.
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
static getInstanceByObjId(int $a_obj_id)
Get instance by obj type.
This class represents a property form user interface.
special template class to simplify handling of ITX/PEAR
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 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 getSystemMessageHTML(string $a_txt, string $a_type="info")
Get HTML for a system message.
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...
exit
Definition: login.php:28
$ref_id
Definition: ltiauth.php:67
static http()
Fetches the global http state from ILIAS.
$url