ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilRecommendedContentRoleConfigGUI.php
Go to the documentation of this file.
1 <?php
2 
25 {
27  protected array $requested_item_ref_ids;
30  protected ilLanguage $lng;
31  protected int $role_id;
32  protected int $node_ref_id;
33  protected ilCtrl $ctrl;
37  protected int $requested_item_ref_id;
38 
39  public function __construct(int $role_id, int $node_ref_id)
40  {
42  global $DIC;
43 
44  $this->role_id = $role_id;
45  $this->node_ref_id = $node_ref_id;
46  $this->rbacsystem = $DIC->rbac()->system();
47  $this->rbacreview = $DIC->rbac()->review();
48  $this->lng = $DIC->language();
49  $this->ctrl = $DIC->ctrl();
50  $this->toolbar = $DIC->toolbar();
51  $this->main_tpl = $DIC->ui()->mainTemplate();
52  $this->manager = new ilRecommendedContentManager();
53  $request = $DIC->repository()->internal()->gui()->standardRequest();
54  $this->requested_item_ref_id = $request->getItemRefId();
55  $this->requested_item_ref_ids = $request->getItemRefIds();
56  }
57 
58  public function executeCommand(): void
59  {
60  $ctrl = $this->ctrl;
61 
62  $next_class = $ctrl->getNextClass($this);
63  $cmd = $ctrl->getCmd("listItems");
64 
65  switch ($next_class) {
66  default:
67  if (in_array($cmd, ["listItems", "selectItem", "assignItem", "confirmRemoveItems", "removeItems"])) {
68  $this->$cmd();
69  }
70  break;
71  }
72  }
73 
74  public function listItems(): void
75  {
76  $rbacreview = $this->rbacreview;
77  $rbacsystem = $this->rbacsystem;
78  $toolbar = $this->toolbar;
79  $lng = $this->lng;
80  $main_tpl = $this->main_tpl;
81  $ctrl = $this->ctrl;
82 
83  if ($this->node_ref_id !== ROLE_FOLDER_ID && !$rbacreview->isAssignable($this->role_id, $this->node_ref_id)) {
84  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt('rep_no_assign_rec_content_to_role'));
85  } else {
86  if ($rbacsystem->checkAccess('push_desktop_items', USER_FOLDER_ID)) {
87  $toolbar->addButton($lng->txt('add'), $ctrl->getLinkTarget(
88  $this,
89  'selectItem'
90  ));
91  }
93  $this,
94  'listItems',
95  $this->role_id,
96  $this->manager
97  );
98  $main_tpl->setContent($tbl->getHTML());
99  }
100  }
101 
102  public function confirmRemoveItems(): void
103  {
104  $this->checkPushPermission();
105 
106  $main_tpl = $this->main_tpl;
107 
108  if (count($this->requested_item_ref_ids) === 0) {
109  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'));
110  $this->listItems();
111  return;
112  }
113 
114  $confirmation_gui = new ilConfirmationGUI();
115  $confirmation_gui->setFormAction($this->ctrl->getFormAction($this));
116  $confirmation_gui->setHeaderText($this->lng->txt('rep_remove_rec_content'));
117  $confirmation_gui->setCancel($this->lng->txt("cancel"), "listItems");
118  $confirmation_gui->setConfirm($this->lng->txt("remove"), "removeItems");
119 
120  foreach ($this->requested_item_ref_ids as $item_ref_id) {
121  $confirmation_gui->addItem(
122  "item_ref_ids[]",
123  (string) $item_ref_id,
125  );
126  }
127 
128  $main_tpl->setContent($confirmation_gui->getHTML());
129  }
130 
131  public function removeItems(): void
132  {
133  $this->checkPushPermission();
134  if (count($this->requested_item_ref_ids) > 0) {
135  foreach ($this->requested_item_ref_ids as $item_ref_id) {
136  $this->manager->removeRoleRecommendation($this->role_id, $item_ref_id);
137  }
138  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('rep_rec_content_removed'));
139  }
140  $this->listItems();
141  }
142 
143  protected function checkPushPermission(): void
144  {
145  $ctrl = $this->ctrl;
146  $rbacsystem = $this->rbacsystem;
147 
148  if (!$rbacsystem->checkAccess('write', $this->node_ref_id) ||
149  !$rbacsystem->checkAccess('push_desktop_items', USER_FOLDER_ID)) {
150  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
151  $ctrl->redirect($this, "listItems");
152  }
153  }
154 
155  protected function selectItem(): void
156  {
157  $this->checkPushPermission();
158 
159  $main_tpl = $this->main_tpl;
161  $this,
162  "selectItem",
163  $this,
164  "assignItem",
165  "item_ref_id"
166  );
167  $exp->setSkipRootNode(true);
168  if (!$exp->handleCommand()) {
169  $main_tpl->setContent($exp->getHTML());
170  }
171  }
172 
173  protected function assignItem(): void
174  {
175  $ctrl = $this->ctrl;
176  $this->checkPushPermission();
177  if ($this->requested_item_ref_id > 0) {
178  $this->manager->addRoleRecommendation($this->role_id, $this->requested_item_ref_id);
179  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('rep_added_rec_content'), true);
180  }
181  $ctrl->redirect($this, 'listItems');
182  }
183 }
const USER_FOLDER_ID
Definition: constants.php:33
Explorer for selecting repository items.
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...
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
setOnScreenMessage(string $type, string $a_txt, bool $a_keep=false)
Set a message to be displayed to the user.
getCmd(string $fallback_command=null)
global $DIC
Definition: feed.php:28
checkAccess(string $a_operations, int $a_ref_id, string $a_type="")
checkAccess represents the main method of the RBAC-system in ILIAS3 developers want to use With this ...
getNextClass($a_gui_class=null)
addButton(string $a_txt, string $a_cmd, string $a_target="", ?int $a_acc_key=null, string $a_additional_attrs='', string $a_id="", string $a_class='submit')
static _lookupTitle(int $obj_id)
setContent(string $a_html)
Sets content for standard template.
static _lookupObjectId(int $ref_id)
const ROLE_FOLDER_ID
Definition: constants.php:34
getLinkTarget(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
__construct(Container $dic, ilPlugin $plugin)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isAssignable(int $a_rol_id, int $a_ref_id)
Check if its possible to assign users.
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...