ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilRecommendedContentRoleConfigGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
11{
15 protected $rbacsystem;
16
20 protected $rbacreview;
21
25 protected $lng;
26
30 protected $role_id;
31
35 protected $node_ref_id;
36
40 protected $ctrl;
41
45 protected $toolbar;
46
50 protected $main_tpl;
51
55 protected $manager;
56
61
65 public function __construct(int $role_id, int $node_ref_id)
66 {
67 global $DIC;
68
69 $this->role_id = $role_id;
70 $this->node_ref_id = $node_ref_id;
71 $this->rbacsystem = $DIC->rbac()->system();
72 $this->rbacreview = $DIC->rbac()->review();
73 $this->lng = $DIC->language();
74 $this->ctrl = $DIC->ctrl();
75 $this->toolbar = $DIC->toolbar();
76 $this->main_tpl = $DIC->ui()->mainTemplate();
77 $this->manager = new ilRecommendedContentManager();
78 $this->requested_item_ref_id = (int) $_GET['item_ref_id'];
79 $this->requested_item_ref_ids = is_array($_POST["item_ref_id"])
80 ? array_map(function ($i) {
81 return (int) $i;
82 }, $_POST["item_ref_id"])
83 : [];
84 }
85
89 public function executeCommand()
90 {
92
93 $next_class = $ctrl->getNextClass($this);
94 $cmd = $ctrl->getCmd("listItems");
95
96 switch ($next_class) {
97 default:
98 if (in_array($cmd, ["listItems", "selectItem", "assignItem", "confirmRemoveItems", "removeItems"])) {
99 $this->$cmd();
100 }
101 break;
102 }
103 }
104
108 public function listItems()
109 {
116
117 if (!$rbacreview->isAssignable($this->role_id, $this->node_ref_id) &&
118 $this->node_ref_id != ROLE_FOLDER_ID) {
119 ilUtil::sendInfo($this->lng->txt('rep_no_assign_rec_content_to_role'));
120 } else {
121 if ($rbacsystem->checkAccess('push_desktop_items', USER_FOLDER_ID)) {
122 $toolbar->addButton($lng->txt('add'), $ctrl->getLinkTarget(
123 $this,
124 'selectItem'
125 ));
126 }
128 $this,
129 'listItems',
130 $this->role_id,
131 $this->manager
132 );
133 $main_tpl->setContent($tbl->getHTML());
134 }
135 }
136
140 public function confirmRemoveItems()
141 {
142 $this->checkPushPermission();
143
145
146 if (count($this->requested_item_ref_ids) == 0) {
147 ilUtil::sendFailure($this->lng->txt('select_one'));
148 $this->listItems();
149 return;
150 }
151
152 $confirmation_gui = new ilConfirmationGUI();
153 $confirmation_gui->setFormAction($this->ctrl->getFormAction($this));
154 $confirmation_gui->setHeaderText($this->lng->txt('rep_remove_rec_content'));
155 $confirmation_gui->setCancel($this->lng->txt("cancel"), "listItems");
156 $confirmation_gui->setConfirm($this->lng->txt("remove"), "removeItems");
157
158 foreach ($this->requested_item_ref_ids as $item_ref_id) {
159 $confirmation_gui->addItem(
160 "item_ref_id[]",
161 $item_ref_id,
163 );
164 }
165
166 $main_tpl->setContent($confirmation_gui->getHTML());
167 }
168
172 public function removeItems()
173 {
174 $this->checkPushPermission();
175
176 if (count($this->requested_item_ref_ids) > 0) {
177 foreach ($this->requested_item_ref_ids as $item_ref_id) {
178 $this->manager->removeRoleRecommendation($this->role_id, $item_ref_id);
179 }
180 ilUtil::sendSuccess($this->lng->txt('rep_rec_content_removed'));
181 }
182 $this->listItems();
183 }
184
188 protected function checkPushPermission()
189 {
192
193 if (!$rbacsystem->checkAccess('write', $this->node_ref_id) ||
194 !$rbacsystem->checkAccess('push_desktop_items', USER_FOLDER_ID)) {
195 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
196 $ctrl->redirect($this, "listItems");
197 }
198 }
199
203 protected function selectItem()
204 {
205 $this->checkPushPermission();
206
209 $this,
210 "selectItem",
211 $this,
212 "assignItem",
213 "item_ref_id"
214 );
215 $exp->setSkipRootNode(true);
216 if (!$exp->handleCommand()) {
217 $main_tpl->setContent($exp->getHTML());
218 }
219 }
220
224 protected function assignItem()
225 {
227 $this->checkPushPermission();
228 if ($this->requested_item_ref_id > 0) {
229 $this->manager->addRoleRecommendation($this->role_id, $this->requested_item_ref_id);
230 ilUtil::sendSuccess($this->lng->txt('rep_added_rec_content'), true);
231 }
232 $ctrl->redirect($this, 'listItems');
233 }
234}
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const USER_FOLDER_ID
Class ilObjUserFolder.
Confirmation screen class.
static _lookupTitle($a_id)
lookup object title
static _lookupObjectId($a_ref_id)
lookup object id
Recommended content manager (business logic)
Recommended content configuration for roles.
__construct(int $role_id, int $node_ref_id)
Constructor.
checkPushPermission()
Check permission to push recommended content.
Explorer for selecting repository items.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$i
Definition: metadata.php:24
$DIC
Definition: xapitoken.php:46