ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
ContributorGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27use ilObjUser;
29
34{
35 public function __construct(
36 protected InternalDataService $data,
37 protected InternalDomainService $domain,
38 protected InternalGUIService $gui,
39 protected int $node_id,
40 protected \ilObjBlog $blog
41 ) {
42 }
43
44 public function executeCommand(): void
45 {
46 $ctrl = $this->gui->ctrl();
47 $next_class = $ctrl->getNextClass($this);
48 $cmd = $ctrl->getCmd("contributors");
49
50 switch ($next_class) {
51 case strtolower(\ilRepositorySearchGUI::class):
52 $rep_search = new \ilRepositorySearchGUI();
53 $rep_search->setTitle($this->domain->lng()->txt("blog_add_contributor"));
54 $rep_search->setCallback($this, 'addContributor', $this->blog->getAllLocalRoles($this->node_id));
55 $ctrl->setReturn($this, 'contributors');
56 $ctrl->forwardCommand($rep_search);
57 break;
58
59 default:
60 if (method_exists($this, $cmd)) {
61 $this->$cmd();
62 }
63 break;
64 }
65 }
66
67 public function contributors(): void
68 {
69 $ilTabs = $this->gui->tabs();
70 $ilToolbar = $this->gui->toolbar();
71 $ilCtrl = $this->gui->ctrl();
72 $lng = $this->domain->lng();
73 $tpl = $this->gui->ui()->mainTemplate();
74
75 $ilTabs->activateTab("contributors");
76
77 $local_roles = $this->blog->getAllLocalRoles($this->node_id);
78
79 // add member
81 $this,
82 $ilToolbar,
83 array(
84 'auto_complete_name' => $lng->txt('user'),
85 'submit_name' => $lng->txt('add'),
86 'add_search' => true,
87 'add_from_container' => $this->node_id,
88 'user_type' => $local_roles
89 ),
90 true
91 );
92
93 $other_roles = $this->blog->getRolesWithContributeOrRedact($this->node_id);
94 if ($other_roles) {
95 $tpl->setOnScreenMessage('info', sprintf($lng->txt("blog_contribute_other_roles"), implode(", ", $other_roles)));
96 }
97
98 $table = $this->gui->contributor()->contributorTableBuilder(
99 $this->blog->getAllLocalRoles($this->node_id),
100 $this,
101 "contributors"
102 )->getTable();
103
104 if ($table->handleCommand()) {
105 return;
106 }
107
108 $tpl->setContent($table->render());
109 }
110
114 public function addUserFromAutoComplete(): void
115 {
116 $lng = $this->domain->lng();
117 $req = $this->gui->standardRequest();
118
119 $user_login = $req->getUserLogin();
120 $user_type = $req->getUserType();
121
122 if (trim($user_login) === '') {
123 $this->gui->ui()->mainTemplate()->setOnScreenMessage('failure', $lng->txt('msg_no_search_string'));
124 $this->contributors();
125 return;
126 }
127 $users = explode(',', $user_login);
128
129 $user_ids = array();
130 foreach ($users as $user) {
132
133 if (!$user_id) {
134 $this->gui->ui()->mainTemplate()->setOnScreenMessage('failure', $lng->txt('user_not_known'));
135 $this->contributors();
136 return;
137 }
138
139 $user_ids[] = (int) $user_id;
140 }
141
142 $this->addContributor($user_ids, $user_type);
143 }
144
148 public function addContributor(
149 array $a_user_ids = array(),
150 ?string $a_user_type = null
151 ): void {
152 $ilCtrl = $this->gui->ctrl();
153 $lng = $this->domain->lng();
154 $rbacreview = $this->domain->rbac()->review();
155 $rbacadmin = $this->domain->rbac()->admin();
156 $a_user_type = (int) $a_user_type;
157
158 if (empty($a_user_ids)) {
159 $a_user_ids = $this->gui->standardRequest()->getIds();
160 }
161
162 if (!count($a_user_ids) || !$a_user_type) {
163 $this->gui->ui()->mainTemplate()->setOnScreenMessage('failure', $lng->txt("no_checkbox"));
164 $this->contributors();
165 return;
166 }
167
168 // get contributor role
169 $local_roles = array_keys($this->blog->getAllLocalRoles($this->node_id));
170 if (!in_array($a_user_type, $local_roles)) {
171 $this->gui->ui()->mainTemplate()->setOnScreenMessage('failure', $lng->txt("missing_perm"));
172 $this->contributors();
173 return;
174 }
175
176 foreach ($a_user_ids as $user_id) {
178 $a_user_type = (int) $a_user_type;
179 if (!$rbacreview->isAssigned($user_id, $a_user_type)) {
180 $rbacadmin->assignUser($a_user_type, $user_id);
181 }
182 }
183
184 $this->gui->ui()->mainTemplate()->setOnScreenMessage('success', $lng->txt("settings_saved"), true);
185 $ilCtrl->redirect($this, "contributors");
186 }
187
191 public function confirmRemoveContributor(array $ids = []): void
192 {
193 if (empty($ids)) {
194 $ids = $this->gui->standardRequest()->getIds();
195 }
196 if (count($ids) === 0) {
197 $this->gui->ui()->mainTemplate()->setOnScreenMessage('failure', $this->domain->lng()->txt("select_one"), true);
198 $this->gui->ctrl()->redirect($this, "contributors");
199 }
200
201 $confirm = new ilConfirmationGUI();
202 $confirm->setHeaderText($this->domain->lng()->txt('blog_confirm_delete_contributors'));
203 $confirm->setFormAction($this->gui->ctrl()->getFormAction($this, 'removeContributor'));
204 $confirm->setConfirm($this->domain->lng()->txt('delete'), 'removeContributor');
205 $confirm->setCancel($this->domain->lng()->txt('cancel'), 'contributors');
206
207 foreach ($ids as $user_id) {
208 $confirm->addItem(
209 'id[]',
210 (string) $user_id,
211 \ilUserUtil::getNamePresentation($user_id, false, false, "", true)
212 );
213 }
214
215 $this->gui->ui()->mainTemplate()->setContent($confirm->getHTML());
216 }
217
218 public function removeContributor(): void
219 {
220 $ilCtrl = $this->gui->ctrl();
221 $lng = $this->domain->lng();
222 $rbacadmin = $this->domain->rbac()->admin();
223
224 $ids = $this->gui->standardRequest()->getIds();
225
226 if (count($ids) === 0) {
227 $this->gui->ui()->mainTemplate()->setOnScreenMessage('failure', $lng->txt("select_one"), true);
228 $ilCtrl->redirect($this, "contributors");
229 }
230
231 // get contributor role
232 $local_roles = array_keys($this->blog->getAllLocalRoles($this->node_id));
233 if (!$local_roles) {
234 $this->gui->ui()->mainTemplate()->setOnScreenMessage('failure', $lng->txt("missing_perm"));
235 $this->contributors();
236 return;
237 }
238
239 foreach ($ids as $user_id) {
240 foreach ($local_roles as $role_id) {
241 $rbacadmin->deassignUser($role_id, $user_id);
242 }
243 }
244
245 $this->gui->ui()->mainTemplate()->setOnScreenMessage('success', $lng->txt("settings_saved"), true);
246 $this->gui->ctrl()->redirect($this, "contributors");
247 }
248
252 public function addContributorContainerAction(array $ids = []): void
253 {
254 if (empty($ids)) {
255 $ids = $this->gui->standardRequest()->getIds();
256 }
257
258 // This would typically add contributors from a container
259 // For now, redirecting back to contributors as this seems to be a placeholder action
260 $this->gui->ctrl()->redirect($this, "contributors");
261 }
262}
@ilCtrl_Calls ILIAS\Blog\Contributor\ContributorGUI: ilRepositorySearchGUI
addContributorContainerAction(array $ids=[])
Used in ContributorTableBuilder.
addContributor(array $a_user_ids=array(), ?string $a_user_type=null)
Centralized method to add contributors.
confirmRemoveContributor(array $ids=[])
Used in ContributorTableBuilder.
addUserFromAutoComplete()
Autocomplete submit.
__construct(protected InternalDataService $data, protected InternalDomainService $domain, protected InternalGUIService $gui, protected int $node_id, protected \ilObjBlog $blog)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
static _lookupId(string|array $a_user_str)
static fillAutoCompleteToolbar(object $parent_object, ?ilToolbarGUI $toolbar=null, array $a_options=[], bool $a_sticky=false)
array( auto_complete_name = $lng->txt('user'), auto_complete_size = 15, user_type = array(ilCoursePar...
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=null)
Default behaviour is:
setOnScreenMessage(string $type, string $a_txt, bool $a_keep=false)
Set a message to be displayed to the user.
setContent(string $a_html)
Sets content for standard template.
readonly ilGlobalTemplateInterface $tpl
catch(\Exception $e) $req
Definition: xapiproxy.php:81
global $lng
Definition: privfeed.php:26
$data
Definition: storeScorm.php:45