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