ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilBadgeProfileGUI.php
Go to the documentation of this file.
1<?php
2
23
25{
26 final public const BACKPACK_EMAIL = 'badge_mozilla_bp';
27
29 protected ilCtrl $ctrl;
30 protected ilLanguage $lng;
32 protected ilTabsGUI $tabs;
33 protected ilObjUser $user;
35 protected \ILIAS\UI\Factory $factory;
36 protected \ILIAS\UI\Renderer $renderer;
38 private readonly TileView $tile_view;
39
40 public function __construct()
41 {
42 global $DIC;
43
44 $this->ctrl = $DIC->ctrl();
45 $this->lng = $DIC->language();
46 $this->tpl = $DIC['tpl'];
47 $this->tabs = $DIC->tabs();
48 $this->user = $DIC->user();
49 $this->access = $DIC->access();
50 $this->factory = $DIC->ui()->factory();
51 $this->renderer = $DIC->ui()->renderer();
52 $this->request = new ilBadgeGUIRequest(
53 $DIC->http(),
54 $DIC->refinery()
55 );
56
57 $this->noti_repo = new BadgeNotificationPrefRepository();
58
59 $this->tile_view = new TileView(
60 $DIC,
61 self::class,
62 new Tile($DIC),
63 new PresentationHeader($DIC, self::class)
64 );
65 }
66
67 public function executeCommand(): void
68 {
69 $ilCtrl = $this->ctrl;
71
72 $lng->loadLanguageModule('badge');
73
74 switch ($ilCtrl->getNextClass()) {
75 default:
76 $cmd = $ilCtrl->getCmd('listBadges');
77
78 global $DIC;
79 $query = $DIC->http()->wrapper()->query();
80 $action = '';
81 $parameter = 'badge_table_action';
82 if ($cmd === 'action' && $this->query->has($parameter)) {
83 $action = $this->query->retrieve($parameter, $DIC->refinery()->kindlyTo()->string());
84 $cmd = 'listBadges';
85 }
86 if ($action === 'obj_badge_activate') {
87 $this->activate();
88 } elseif ($action === 'obj_badge_deactivate') {
89 $this->deactivate();
90 }
91 $this->$cmd();
92 break;
93 }
94 }
95
96 public function getSafePostCommands(): array
97 {
98 return [];
99 }
100
101 public function getUnsafeGetCommands(): array
102 {
103 return ['action'];
104 }
105
106 protected function listBadges(): void
107 {
108 $this->tpl->setContent($this->renderDeck($this->tile_view->show()));
109 $this->noti_repo->updateLastCheckedTimestamp();
110 }
111
112 private function renderDeck(string $deck): string
113 {
114 $template = new ilTemplate('tpl.badge_backpack.html', true, true, 'components/ILIAS/Badge/');
115 $template->setVariable('DECK', $deck);
116 return $template->get();
117 }
118
119 protected function manageBadges(): void
120 {
122 $tpl->renderTable(ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTarget($this, 'action'));
123 }
124
125 protected function getMultiSelection(): array
126 {
127 $ids = $this->request->getBadgeIds();
128 if (count($ids) > 0) {
129 $res = [];
130 foreach ($ids as $id) {
131 $ass = new ilBadgeAssignment($id, $this->user->getId());
132 if ($ass->getTimestamp()) {
133 $res[] = $ass;
134 }
135 }
136
137 return $res;
138 }
139
140 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'), true);
141 $this->ctrl->redirect($this, 'manageBadges');
142 }
143
144 protected function activate(): void
145 {
147 $ilCtrl = $this->ctrl;
148
149 foreach ($this->getMultiSelection() as $ass) {
150 // already active?
151 if (!$ass->getPosition()) {
152 $ass->setPosition(999);
153 $ass->store();
154 }
155 }
156
157 $this->tpl->setOnScreenMessage('success', $lng->txt('position_updated'), true);
158 $ilCtrl->redirect($this, 'manageBadges');
159 }
160
161 protected function deactivate(): void
162 {
164 $ilCtrl = $this->ctrl;
165
166 foreach ($this->getMultiSelection() as $ass) {
167 // already inactive?
168 if ($ass->getPosition()) {
169 $ass->setPosition(null);
170 $ass->store();
171 }
172 }
173
174 $this->tpl->setOnScreenMessage('success', $lng->txt('position_updated'), true);
175 $ilCtrl->redirect($this, 'manageBadges');
176 }
177
178 protected function activateInCard(): void
179 {
181 $ilCtrl = $this->ctrl;
182
183 foreach ($this->getMultiSelection() as $ass) {
184 // already active?
185 if (!$ass->getPosition()) {
186 $ass->setPosition(999);
187 $ass->store();
188 }
189 }
190
191 $this->tpl->setOnScreenMessage('success', $lng->txt('position_updated'), true);
192 $ilCtrl->redirect($this, 'listBadges');
193 }
194
195 protected function deactivateInCard(): void
196 {
198 $ilCtrl = $this->ctrl;
199
200 foreach ($this->getMultiSelection() as $ass) {
201 // already inactive?
202 if ($ass->getPosition()) {
203 $ass->setPosition(null);
204 $ass->store();
205 }
206 }
207
208 $this->tpl->setOnScreenMessage('success', $lng->txt('position_updated'), true);
209 $ilCtrl->redirect($this, 'listBadges');
210 }
211
212 protected function setBackpackSubTabs(): void
213 {
214 $ilTabs = $this->tabs;
216 $ilCtrl = $this->ctrl;
217
218 $ilTabs->addSubTab(
219 'backpack_badges',
220 $lng->txt('obj_bdga'),
221 $ilCtrl->getLinkTarget($this, 'listBackpackGroups')
222 );
223
224 $ilTabs->addSubTab(
225 'backpack_settings',
226 $lng->txt('settings'),
227 $ilCtrl->getLinkTarget($this, 'editSettings')
228 );
229
230 $ilTabs->activateTab('backpack_badges');
231 }
232
233 protected function listBackpackGroups(): void
234 {
237 $ilCtrl = $this->ctrl;
238 $ilTabs = $this->tabs;
239
240 $this->setBackpackSubTabs();
241 $ilTabs->activateSubTab('backpack_badges');
242
243 $this->tpl->setOnScreenMessage('info', $lng->txt('badge_backpack_gallery_info'));
244
245 $bp = new ilBadgeBackpack($this->getBackpackMail());
246 $bp_groups = $bp->getGroups();
247
248 if (!count($bp_groups)) {
249 $this->tpl->setOnScreenMessage('info', $lng->txt('badge_backpack_no_groups'));
250 return;
251 }
252
253 $tmpl = new ilTemplate('tpl.badge_backpack.html', true, true, 'components/ILIAS/Badge/');
254
255 $tmpl->setVariable('BACKPACK_TITLE', $lng->txt('badge_backpack_list'));
256
258
259 foreach ($bp_groups as $group_id => $group) {
260 $bp_badges = $bp->getBadges($group_id);
261 if (count($bp_badges)) {
262 foreach ($bp_badges as $idx => $badge) {
263 $tmpl->setCurrentBlock('badge_bl');
264 $tmpl->setVariable('BADGE_TITLE', $badge['title']);
265 $tmpl->setVariable('BADGE_DESC', $badge['description']);
266 $tmpl->setVariable('BADGE_IMAGE', $badge['image_url']);
267 $tmpl->setVariable('BADGE_CRITERIA', $badge['criteria_url']);
268 $tmpl->setVariable('BADGE_ISSUER', $badge['issuer_name']);
269 $tmpl->setVariable('BADGE_ISSUER_URL', $badge['issuer_url']);
270 $tmpl->setVariable('BADGE_DATE', ilDatePresentation::formatDate($badge['issued_on']));
271 $tmpl->parseCurrentBlock();
272 }
273 }
274
275 $tmpl->setCurrentBlock('group_bl');
276 $tmpl->setVariable('GROUP_TITLE', $group['title']);
277 $tmpl->parseCurrentBlock();
278 }
279
280 $tpl->setContent($tmpl->get());
281 }
282
283 //
284 // settings
285 //
286
287 protected function getBackpackMail(): string
288 {
289 $ilUser = $this->user;
290
291 $mail = $ilUser->getPref(self::BACKPACK_EMAIL);
292 if (!$mail) {
293 $mail = $ilUser->getEmail();
294 }
295 return $mail;
296 }
297
299 {
301 $ilCtrl = $this->ctrl;
302
303 $form = new ilPropertyFormGUI();
304 $form->setFormAction($ilCtrl->getFormAction($this, 'saveSettings'));
305 $form->setTitle($lng->txt('settings'));
306
307 $email = new ilEMailInputGUI($lng->txt('badge_backpack_email'), 'email');
308 // $email->setRequired(true);
309 $email->setInfo($lng->txt('badge_backpack_email_info'));
310 $email->setValue($this->getBackpackMail());
311 $form->addItem($email);
312
313 $form->addCommandButton('saveSettings', $lng->txt('save'));
314
315 return $form;
316 }
317
318 protected function editSettings(?ilPropertyFormGUI $a_form = null): void
319 {
321 $ilCtrl = $this->ctrl;
322 $ilTabs = $this->tabs;
323
324 $ilCtrl->redirect($this, 'listBadges');
325 }
326
327 protected function saveSettings(): void
328 {
329 $ilUser = $this->user;
331 $ilCtrl = $this->ctrl;
332
333 $form = $this->initSettingsForm();
334 if ($form->checkInput()) {
335 $new_email = $form->getInput('email');
336 $old_email = $this->getBackpackMail();
337
338 $ilUser->writePref(self::BACKPACK_EMAIL, $new_email);
339
340 // if email was changed: delete badge files
341 if ($new_email != $old_email) {
342 ilBadgeAssignment::clearBadgeCache($ilUser->getId());
343 }
344
345 $this->tpl->setOnScreenMessage('success', $lng->txt('settings_saved'), true);
346 $ilCtrl->redirect($this, 'editSettings');
347 }
348
349 $form->setValuesByPost();
350 $this->editSettings($form);
351 }
352}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
renderer()
factory()
Badge notification repository (using user preferences.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static clearBadgeCache(int $a_user_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getSafePostCommands()
This method must return a list of safe POST commands.
getUnsafeGetCommands()
This method must return a list of unsafe GET commands.
BadgeNotificationPrefRepository $noti_repo
editSettings(?ilPropertyFormGUI $a_form=null)
readonly TileView $tile_view
ILIAS UI Renderer $renderer
ilGlobalTemplateInterface $tpl
ilBadgeGUIRequest $request
Class ilCtrl provides processing control methods.
redirect(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
@inheritDoc
static setUseRelativeDates(bool $a_status)
set use relative dates
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
This class represents a email property in a property form.
language handling
loadLanguageModule(string $a_module)
Load language module.
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...
User class.
getPref(string $a_keyword)
This class represents a property form user interface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
setContent(string $a_html)
Sets content for standard template.
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26