ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilGroupAddToGroupActionGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
4
12{
16 protected $ctrl;
17
21 protected $tpl;
22
26 protected $ui;
27
31 protected $lng;
32
36 protected $tree;
37
43 public function __construct()
44 {
45 global $DIC;
46
47 $this->ctrl = $DIC->ctrl();
48 $this->tpl = $DIC["tpl"];
49 $this->ui = $DIC->ui();
50 $this->lng = $DIC->language();
51 $this->tree = $DIC->repositoryTree();
52 $this->user = $DIC->user();
53
54 $this->lng->loadLanguageModule("grp");
55 $this->ctrl->saveParameter($this, array("user_id", "modal_exists"));
56 }
57
61 public function executeCommand()
62 {
64 $user = $this->user;
65
66 $next_class = $ctrl->getNextClass($this);
67 $cmd = $ctrl->getCmd("show");
68
69 if ($cmd == "show") {
70 include_once("./Modules/Group/UserActions/classes/class.ilGroupUserActionProvider.php");
72 if (count($ca) == 0) {
73 return;
74 }
75 if (count($ca) == 1) {
76 switch (current($ca)) {
77 case "create_grp":
78 $cmd = "selectParent";
79 break;
80
81 case "manage_members":
82 $cmd = "selectGroup";
83 break;
84
85 default:
86 return;
87 }
88 }
89 }
90
91 switch ($next_class) {
92 default:
93 if (in_array($cmd, array("show", "selectGroup", "confirmAddUser", "addUser",
94 "selectParent", "createGroup", "confirmCreateGroupAndAddUser", "createGroupAndAddUser"))) {
95 $ctrl->setParameter($this, "modal_exists", 1);
96 $this->$cmd();
97 }
98 }
99 }
100
104 public function show()
105 {
109
110 $toolbar = new ilToolbarGUI();
111
112 // button use existing group
113 $url1 = $ctrl->getLinkTarget($this, "selectGroup", "", true, false);
114 $button1 = $this->ui->factory()->button()->standard($lng->txt("grp_use_existing"), "#")
115 ->withOnLoadCode(function ($id) use ($url1) {
116 return "$('#$id').on('click', function() {il.Util.ajaxReplaceInner('$url1', 'il_grp_action_modal_content'); return false;})";
117 });
118 $toolbar->addComponent($button1);
119
120 // button create new group
121 $url2 = $ctrl->getLinkTarget($this, "selectParent", "", true, false);
122 $button2 = $this->ui->factory()->button()->standard($lng->txt("grp_create_new"), "#")
123 ->withOnLoadCode(function ($id) use ($url2) {
124 return "$('#$id').on('click', function() {il.Util.ajaxReplaceInner('$url2', 'il_grp_action_modal_content'); return false;})";
125 });
126 $toolbar->addComponent($button2);
127
128 $this->sendResponse(
129 $tpl->getMessageHTML($lng->txt("grp_create_or_use_existing"), "question") .
130 $toolbar->getHTML()
131 );
132 }
133
139 public function sendResponse($a_content)
140 {
142
143 if ($_GET["modal_exists"] == 1) {
144 echo $this->ui->renderer()->renderAsync($this->ui->factory()->legacy($a_content));
145 } else {
146 $mtpl = new ilTemplate("tpl.grp_add_to_grp_modal_content.html", true, true, "./Modules/Group/UserActions");
147 $mtpl->setVariable("CONTENT", $a_content);
148 $content = $this->ui->factory()->legacy($mtpl->get());
149 $modal = $this->ui->factory()->modal()->roundtrip(
150 $lng->txt("grp_add_user_to_group"),
151 $content
152 )->withOnLoadCode(function ($id) {
153 return "il.UI.modal.showModal('$id', {'ajaxRenderUrl':'','keyboard':true});";
154 });
155 echo $this->ui->renderer()->renderAsync($modal);
156 }
157 exit;
158 }
159
160
167 public function selectGroup()
168 {
170
171 include_once("./Modules/Group/UserActions/classes/class.ilGroupActionTargetExplorerGUI.php");
172 $exp = new ilGroupActionTargetExplorerGUI($this, "selectGroup");
173
174 $exp->setClickableType("grp");
175 $exp->setTypeWhiteList(array("root", "cat", "crs", "fold", "grp"));
176 $exp->setPathOpen((int) $tree->readRootId());
177
178 if (!$exp->handleCommand()) {
179 $this->sendResponse($exp->getHTML());
180 }
181
182 exit;
183 }
184
191 public function confirmAddUser()
192 {
196
197 include_once("./Services/Membership/classes/class.ilParticipants.php");
198 include_once './Services/Membership/classes/class.ilParticipants.php';
199 $participants = ilParticipants::getInstanceByObjId(ilObject::_lookupObjId((int) $_GET["grp_act_ref_id"]));
200 if ($participants->isMember((int) $_GET["user_id"])) {
201 $url = $ctrl->getLinkTarget($this, "selectGroup", "", true, false);
202 $button = $this->ui->factory()->button()->standard($lng->txt("back"), "#")
203 ->withOnLoadCode(function ($id) use ($url) {
204 return "$('#$id').on('click', function() {il.Util.ajaxReplaceInner('$url', 'il_grp_action_modal_content'); return false;})";
205 });
206
207 echo
208 $tpl->getMessageHTML($lng->txt("grp_user_already_in_group") . "<br>" .
209 $lng->txt("obj_user") . ": " . ilUserUtil::getNamePresentation((int) $_GET["user_id"]) . "<br>" .
210 $lng->txt("obj_grp") . ": " . ilObject::_lookupTitle(ilObject::_lookupObjId($_GET["grp_act_ref_id"])), "failure") .
211 $this->ui->renderer()->renderAsync($button);
212 exit;
213 }
214
215
216 // button create new group
217 $ctrl->setParameter($this, "grp_act_ref_id", $_GET["grp_act_ref_id"]);
218 $url = $ctrl->getLinkTarget($this, "addUser", "", true, false);
219 $button = $this->ui->factory()->button()->standard($lng->txt("grp_add_user"), "#")
220 ->withOnLoadCode(function ($id) use ($url) {
221 return "$('#$id').on('click', function() {il.Util.ajaxReplaceInner('$url', 'il_grp_action_modal_content'); return false;})";
222 });
223
224 echo
225 $tpl->getMessageHTML($lng->txt("grp_sure_add_user_to_group") . "<br>" .
226 $lng->txt("obj_user") . ": " . ilUserUtil::getNamePresentation((int) $_GET["user_id"]) . "<br>" .
227 $lng->txt("obj_grp") . ": " . ilObject::_lookupTitle(ilObject::_lookupObjId($_GET["grp_act_ref_id"])), "question") .
228 $this->ui->renderer()->renderAsync($button);
229 exit;
230 }
231
237 public function addUser()
238 {
241
242 $user_id = (int) $_GET["user_id"];
243
244 // @todo: check permission
245
246 include_once("./Modules/Group/classes/class.ilObjGroup.php");
247 $group = new ilObjGroup((int) $_GET["grp_act_ref_id"]);
248
249 include_once './Services/Membership/classes/class.ilParticipants.php';
250 $participants = ilParticipants::getInstanceByObjId($group->getId());
251
252 $participants->add($user_id, IL_GRP_MEMBER);
253
254 include_once './Modules/Group/classes/class.ilGroupMembershipMailNotification.php';
255 $participants->sendNotification(
257 $user_id
258 );
259
260 echo $tpl->getMessageHTML($lng->txt("grp_user_been_added"), "success");
261 echo "<script>setTimeout(function (){ il.Group.UserActions.closeModal();}, 1000);</script>";
262 exit;
263 }
264
271 public function selectParent()
272 {
276
277 include_once("./Modules/Group/UserActions/classes/class.ilGroupActionTargetExplorerGUI.php");
278 $exp = new ilGroupActionTargetExplorerGUI($this, "selectParent", true);
279
280 $exp->setTypeWhiteList(array("root", "cat", "crs"));
281 $exp->setPathOpen((int) $tree->readRootId());
282
283 if (!$exp->handleCommand()) {
284 $this->sendResponse($tpl->getMessageHTML($lng->txt("grp_no_perm_to_add_create_first"), "info") .
285 $exp->getHTML());
286 }
287
288 exit;
289 }
290
297 public function createGroup($form = null)
298 {
301
302 if ($form == null) {
303 $form = $this->getGroupCreationForm();
304 }
305 $this->ctrl->saveParameter($this, "grp_act_par_ref_id");
306 $form->setFormAction($this->ctrl->getLinkTarget($this, "confirmCreateGroupAndAddUser", "", true, false));
307
308 echo $tpl->getMessageHTML(str_replace("%1", ilObject::_lookupTitle(ilObject::_lookupObjId($_GET["grp_act_par_ref_id"])), $lng->txt("grp_create_new_grp_in")), "info") .
309 $form->getHTML();
310 exit;
311 }
312
313 protected function getGroupCreationForm()
314 {
316
317 $group_gui = new ilObjGroupGUI("", 0, true);
318 $group_gui->setCreationMode(true);
319 // workaround for bug #22748 (which is triggered, if a didactic template for groups exist which is limited to a rep node)
320 $ref_id = $_GET["ref_id"];
321 $_GET["ref_id"] = $_GET["grp_act_par_ref_id"];
322 $form = $group_gui->initForm("create", true);
323 $_GET["ref_id"] = $ref_id;
324 $form->clearCommandButtons();
325 $form->addCommandButton("save", $lng->txt("grp_next"));
326 $form->setShowTopButtons(false);
327 return $form;
328 }
329
337 {
341
342 $form = $this->getGroupCreationForm();
343 if (!$form->checkInput()) {
344 $this->createGroup($form);
345 return;
346 }
347
348 $this->ctrl->saveParameter($this, "grp_act_par_ref_id");
349 $form->setFormAction($this->ctrl->getLinkTarget($this, "createGroupAndAddUser", "", true, false));
350 $form->setValuesByPost();
351
352 $button = $this->ui->factory()->button()->standard($lng->txt("grp_create_and_add_user"), "#")
353 ->withOnLoadCode(function ($id) {
354 return "$('#$id').on('click', function(e) {il.Group.UserActions.createGroup(e);})";
355 });
356
357 echo
358 $tpl->getMessageHTML($lng->txt("grp_sure_create_group_add_user") . "<br>" .
359 $lng->txt("obj_user") . ": " . ilUserUtil::getNamePresentation($_GET["user_id"]) . "<br>" .
360 $lng->txt("obj_grp") . ": " . $_POST["title"], "question") .
361 "<div class='ilNoDisplay'>" . $form->getHTML() . "</div>" .
362 $this->ui->renderer()->renderAsync($button);
363
364 exit;
365 }
366
373 public function createGroupAndAddUser()
374 {
377
378 $user_id = (int) $_GET["user_id"];
379 $form = $this->getGroupCreationForm();
380
381 $form->checkInput();
382
383 $group_gui = new ilObjGroupGUI("", 0, true);
384
385 // create instance
386 include_once("./Modules/Group/classes/class.ilObjGroup.php");
387 $newObj = new ilObjGroup();
388 $newObj->setType("grp");
389 $newObj->setTitle($form->getInput("title"));
390 $newObj->setDescription($form->getInput("desc"));
391 $newObj->create();
392
393 $group_gui->putObjectInTree($newObj, (int) $_GET["grp_act_par_ref_id"]);
394
395 // apply didactic template?
396 $dtpl = $group_gui->getDidacticTemplateVar("dtpl");
397 if ($dtpl) {
398 $newObj->applyDidacticTemplate($dtpl);
399 }
400
401 $group_gui->afterSave($newObj, false);
402
403
404 include_once './Services/Membership/classes/class.ilParticipants.php';
405 $participants = ilParticipants::getInstanceByObjId($newObj->getId());
406
407 $participants->add($user_id, IL_GRP_MEMBER);
408
409 include_once './Modules/Group/classes/class.ilGroupMembershipMailNotification.php';
410 $participants->sendNotification(
412 $user_id
413 );
414
415
416 include_once("./Services/Link/classes/class.ilLink.php");
417 $url = ilLink::_getLink($newObj->getRefId());
418 echo $tpl->getMessageHTML($lng->txt("grp_created_and_user_been_added"), "success");
419 echo "<script>setTimeout(function (){ window.location.replace('$url');}, 1000);</script>";
420 exit;
421 }
422}
user()
Definition: user.php:4
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_GRP_MEMBER
Add user to group from awareness tool.
confirmAddUser()
Confirm add user to group.
createGroupAndAddUser()
Create group and add user.
static getCommandAccess($a_user_id)
Get command access for user.
Class ilObjGroupGUI.
Class ilObjGroup.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static getInstanceByObjId($a_obj_id)
Get instance by obj type.
special template class to simplify handling of ITX/PEAR
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
if(!array_key_exists('StateId', $_REQUEST)) $id
$url
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
$a_content
Definition: workflow.php:93