ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
ilBadgeProfileGUI Class Reference
+ Inheritance diagram for ilBadgeProfileGUI:
+ Collaboration diagram for ilBadgeProfileGUI:

Public Member Functions

 __construct ()
 
 executeCommand ()
 
 getSafePostCommands ()
 This method must return a list of safe POST commands. More...
 
 getUnsafeGetCommands ()
 This method must return a list of unsafe GET commands. More...
 
 getUnsafeGetCommands ()
 This method must return a list of unsafe GET commands. More...
 
 getSafePostCommands ()
 This method must return a list of safe POST commands. More...
 

Data Fields

const string TABLE_ALL_OBJECTS_ACTION = 'ALL_OBJECTS'
 
final const string BACKPACK_EMAIL = 'badge_mozilla_bp'
 

Private Member Functions

 getTableAction ()
 
 handleTableActionsCmd ()
 
 listBadgesCmd ()
 
 renderDeck (string $deck)
 
 manageBadgesCmd ()
 
 getMultiSelection ()
 
 activate ()
 
 deactivate ()
 
 activateInCardCmd ()
 
 deactivateInCardCmd ()
 
 setBackpackSubTabs ()
 
 listBackpackGroupsCmd ()
 
 getBackpackMail ()
 
 initSettingsForm ()
 
 editSettingsCmd (?ilPropertyFormGUI $a_form=null)
 
 saveSettingsCmd ()
 

Private Attributes

const string LIST_BADGES_ACTION = 'listBadges'
 
const string MANAGE_BADGES_ACTION = 'manageBadges'
 
const string TABLE_ACTIONS = 'handleTableActions'
 
const string DEFAULT_ACTION = self::LIST_BADGES_ACTION
 
readonly ilBadgeGUIRequest $request
 
readonly ilCtrlInterface $ctrl
 
readonly ilLanguage $lng
 
readonly ilGlobalTemplateInterface $tpl
 
readonly ilTabsGUI $tabs
 
readonly ilObjUser $user
 
readonly ILIAS Refinery Factory $refinery
 
readonly ILIAS HTTP GlobalHttpState $http
 
readonly BadgeNotificationPrefRepository $noti_repo
 
readonly TileView $tile_view
 

Detailed Description

Definition at line 24 of file class.ilBadgeProfileGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilBadgeProfileGUI::__construct ( )

Definition at line 46 of file class.ilBadgeProfileGUI.php.

47 {
48 global $DIC;
49
50 $this->ctrl = $DIC->ctrl();
51 $this->lng = $DIC->language();
52 $this->tpl = $DIC['tpl'];
53 $this->tabs = $DIC->tabs();
54 $this->user = $DIC->user();
55 $this->refinery = $DIC->refinery();
56 $this->http = $DIC->http();
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 }
Badge notification repository (using user preferences.
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26

References $DIC, ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), ILIAS\Repository\tabs(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

Member Function Documentation

◆ activate()

ilBadgeProfileGUI::activate ( )
private

Definition at line 176 of file class.ilBadgeProfileGUI.php.

176 : void
177 {
178 foreach ($this->getMultiSelection() as $ass) {
179 // already active?
180 if (!$ass->getPosition()) {
181 $ass->setPosition(999);
182 $ass->store();
183 }
184 }
185
186 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('position_updated'), true);
187 $this->ctrl->redirect($this, self::MANAGE_BADGES_ACTION);
188 }

References ILIAS\Repository\ctrl(), getMultiSelection(), and ILIAS\Repository\lng().

Referenced by handleTableActionsCmd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ activateInCardCmd()

ilBadgeProfileGUI::activateInCardCmd ( )
private

Definition at line 204 of file class.ilBadgeProfileGUI.php.

204 : void
205 {
206 foreach ($this->getMultiSelection() as $ass) {
207 // already active?
208 if (!$ass->getPosition()) {
209 $ass->setPosition(999);
210 $ass->store();
211 }
212 }
213
214 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('position_updated'), true);
215 $this->ctrl->redirect($this, self::LIST_BADGES_ACTION);
216 }

References ILIAS\Repository\ctrl(), getMultiSelection(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ deactivate()

ilBadgeProfileGUI::deactivate ( )
private

Definition at line 190 of file class.ilBadgeProfileGUI.php.

190 : void
191 {
192 foreach ($this->getMultiSelection() as $ass) {
193 // already inactive?
194 if ($ass->getPosition()) {
195 $ass->setPosition(null);
196 $ass->store();
197 }
198 }
199
200 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('position_updated'), true);
201 $this->ctrl->redirect($this, self::MANAGE_BADGES_ACTION);
202 }

References ILIAS\Repository\ctrl(), getMultiSelection(), and ILIAS\Repository\lng().

Referenced by handleTableActionsCmd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deactivateInCardCmd()

ilBadgeProfileGUI::deactivateInCardCmd ( )
private

Definition at line 218 of file class.ilBadgeProfileGUI.php.

218 : void
219 {
220 foreach ($this->getMultiSelection() as $ass) {
221 // already inactive?
222 if ($ass->getPosition()) {
223 $ass->setPosition(null);
224 $ass->store();
225 }
226 }
227
228 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('position_updated'), true);
229 $this->ctrl->redirect($this, self::LIST_BADGES_ACTION);
230 }

References ILIAS\Repository\ctrl(), getMultiSelection(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ editSettingsCmd()

ilBadgeProfileGUI::editSettingsCmd ( ?ilPropertyFormGUI  $a_form = null)
private

Definition at line 324 of file class.ilBadgeProfileGUI.php.

324 : void
325 {
326 $this->ctrl->redirect($this, self::LIST_BADGES_ACTION);
327 }

References ILIAS\Repository\ctrl().

Referenced by saveSettingsCmd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilBadgeProfileGUI::executeCommand ( )

Definition at line 72 of file class.ilBadgeProfileGUI.php.

72 : void
73 {
74 $this->lng->loadLanguageModule('badge');
75
76 switch ($this->ctrl->getNextClass()) {
77 default:
78 $cmd = $this->ctrl->getCmd(self::DEFAULT_ACTION);
79 if ($cmd === '' || $cmd === null || !method_exists($this, $cmd . 'Cmd')) {
81 }
82 $cmd .= 'Cmd';
83
84 $this->$cmd();
85 break;
86 }
87 }

References ILIAS\Repository\ctrl(), DEFAULT_ACTION, and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getBackpackMail()

ilBadgeProfileGUI::getBackpackMail ( )
private

Definition at line 298 of file class.ilBadgeProfileGUI.php.

298 : string
299 {
300 $mail = $this->user->getPref(self::BACKPACK_EMAIL);
301 if (!$mail) {
302 $mail = $this->user->getEmail();
303 }
304
305 return $mail;
306 }

References ILIAS\Repository\user().

Referenced by initSettingsForm(), listBackpackGroupsCmd(), and saveSettingsCmd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMultiSelection()

ilBadgeProfileGUI::getMultiSelection ( )
private

Definition at line 138 of file class.ilBadgeProfileGUI.php.

138 : array
139 {
140 $badge_ids = array_filter(
141 $this->http->wrapper()->query()->retrieve(
142 'badge_id',
143 $this->refinery->byTrying([
144 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()),
145 $this->refinery->always([])
146 ])
147 )
148 );
149
150 if ($badge_ids === [self::TABLE_ALL_OBJECTS_ACTION]) {
151 $badge_assignments = array_filter(
153 static fn(ilBadgeAssignment $ass): bool => (bool) $ass->getTimestamp()
154 );
155 } else {
156 $badge_assignments = array_filter(
157 array_map(
158 fn(int $badge_id): ilBadgeAssignment => new ilBadgeAssignment(
159 $badge_id,
160 $this->user->getId()
161 ),
162 $this->request->getBadgeIds()
163 ),
164 static fn(ilBadgeAssignment $ass): bool => (bool) $ass->getTimestamp()
165 );
166 }
167
168 if (!empty($badge_assignments)) {
169 return $badge_assignments;
170 }
171
172 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_FAILURE, $this->lng->txt('select_one'), true);
173 $this->ctrl->redirect($this, self::MANAGE_BADGES_ACTION);
174 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstancesByUserId(int $a_user_id)

References ILIAS\Repository\ctrl(), ilBadgeAssignment\getInstancesByUserId(), ilBadgeAssignment\getTimestamp(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), and ILIAS\Repository\user().

Referenced by activate(), activateInCardCmd(), deactivate(), and deactivateInCardCmd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSafePostCommands()

ilBadgeProfileGUI::getSafePostCommands ( )

This method must return a list of safe POST commands.

Safe post commands returned by this method will no longer be CSRF protected and will NOT be appended by an ilCtrlToken.

Returns
string[]

Implements ilCtrlSecurityInterface.

Definition at line 89 of file class.ilBadgeProfileGUI.php.

89 : array
90 {
91 return [];
92 }

◆ getTableAction()

ilBadgeProfileGUI::getTableAction ( )
private

Definition at line 94 of file class.ilBadgeProfileGUI.php.

94 : ?string
95 {
96 return $this->http->wrapper()->query()->retrieve(
97 'badge_table_action',
98 $this->refinery->byTrying([
99 $this->refinery->kindlyTo()->string(),
100 $this->refinery->always(null)
101 ])
102 );
103 }

References ILIAS\FileDelivery\http(), and ILIAS\Repository\refinery().

Referenced by handleTableActionsCmd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUnsafeGetCommands()

ilBadgeProfileGUI::getUnsafeGetCommands ( )

This method must return a list of unsafe GET commands.

Unsafe get commands returned by this method will now be CSRF protected, which means an ilCtrlToken is appended each time a link-target is generated to the class implementing this interface with a command from that list.

Tokens will be validated in

See also
ilCtrlInterface::getCmd(), whereas the fallback command will be used if the CSRF validation fails.
Returns
string[]

Implements ilCtrlSecurityInterface.

Definition at line 114 of file class.ilBadgeProfileGUI.php.

114 : array
115 {
116 return [self::TABLE_ACTIONS];
117 }

References TABLE_ACTIONS.

◆ handleTableActionsCmd()

ilBadgeProfileGUI::handleTableActionsCmd ( )
private

Definition at line 105 of file class.ilBadgeProfileGUI.php.

105 : void
106 {
107 match ($this->getTableAction()) {
108 'obj_badge_activate' => $this->activate(),
109 'obj_badge_deactivate' => $this->deactivate(),
110 default => $this->ctrl->redirect($this, self::DEFAULT_ACTION),
111 };
112 }

References activate(), ILIAS\Repository\ctrl(), deactivate(), and getTableAction().

+ Here is the call graph for this function:

◆ initSettingsForm()

ilBadgeProfileGUI::initSettingsForm ( )
private

Definition at line 308 of file class.ilBadgeProfileGUI.php.

309 {
310 $form = new ilPropertyFormGUI();
311 $form->setFormAction($this->ctrl->getFormAction($this, 'saveSettings'));
312 $form->setTitle($this->lng->txt('settings'));
313
314 $email = new ilEMailInputGUI($this->lng->txt('badge_backpack_email'), 'email');
315 $email->setInfo($this->lng->txt('badge_backpack_email_info'));
316 $email->setValue($this->getBackpackMail());
317 $form->addItem($email);
318
319 $form->addCommandButton('saveSettings', $this->lng->txt('save'));
320
321 return $form;
322 }
This class represents a email property in a property form.
This class represents a property form user interface.

References ILIAS\Repository\ctrl(), getBackpackMail(), and ILIAS\Repository\lng().

Referenced by saveSettingsCmd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ listBackpackGroupsCmd()

ilBadgeProfileGUI::listBackpackGroupsCmd ( )
private

Definition at line 249 of file class.ilBadgeProfileGUI.php.

249 : void
250 {
251 $this->setBackpackSubTabs();
252 $this->tabs->activateSubTab('backpack_badges');
253
254 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_INFO, $this->lng->txt('badge_backpack_gallery_info'));
255
256 $bp = new ilBadgeBackpack($this->getBackpackMail());
257 $bp_groups = $bp->getGroups();
258
259 if (!count($bp_groups)) {
260 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_INFO, $this->lng->txt('badge_backpack_no_groups'));
261 return;
262 }
263
264 $tmpl = new ilTemplate('tpl.badge_backpack.html', true, true, 'components/ILIAS/Badge/');
265
266 $tmpl->setVariable('BACKPACK_TITLE', $this->lng->txt('badge_backpack_list'));
267
269
270 foreach ($bp_groups as $group_id => $group) {
271 $bp_badges = $bp->getBadges($group_id);
272 if (count($bp_badges)) {
273 foreach ($bp_badges as $badge) {
274 $tmpl->setCurrentBlock('badge_bl');
275 $tmpl->setVariable('BADGE_TITLE', $badge['title']);
276 $tmpl->setVariable('BADGE_DESC', $badge['description']);
277 $tmpl->setVariable('BADGE_IMAGE', $badge['image_url']);
278 $tmpl->setVariable('BADGE_CRITERIA', $badge['criteria_url']);
279 $tmpl->setVariable('BADGE_ISSUER', $badge['issuer_name']);
280 $tmpl->setVariable('BADGE_ISSUER_URL', $badge['issuer_url']);
281 $tmpl->setVariable('BADGE_DATE', ilDatePresentation::formatDate($badge['issued_on']));
282 $tmpl->parseCurrentBlock();
283 }
284 }
285
286 $tmpl->setCurrentBlock('group_bl');
287 $tmpl->setVariable('GROUP_TITLE', $group['title']);
288 $tmpl->parseCurrentBlock();
289 }
290
291 $this->tpl->setContent($tmpl->get());
292 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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,)
special template class to simplify handling of ITX/PEAR

References ilDatePresentation\formatDate(), getBackpackMail(), ILIAS\Repository\lng(), setBackpackSubTabs(), ilDatePresentation\setUseRelativeDates(), and ILIAS\Repository\tabs().

+ Here is the call graph for this function:

◆ listBadgesCmd()

ilBadgeProfileGUI::listBadgesCmd ( )
private

Definition at line 119 of file class.ilBadgeProfileGUI.php.

119 : void
120 {
121 $this->tpl->setContent($this->renderDeck($this->tile_view->show()));
122 $this->noti_repo->updateLastCheckedTimestamp();
123 }

References renderDeck().

+ Here is the call graph for this function:

◆ manageBadgesCmd()

ilBadgeProfileGUI::manageBadgesCmd ( )
private

Definition at line 132 of file class.ilBadgeProfileGUI.php.

132 : void
133 {
135 $tpl->renderTable(ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTarget($this, self::TABLE_ACTIONS));
136 }
readonly ilGlobalTemplateInterface $tpl

References $tpl, and ILIAS\Repository\ctrl().

+ Here is the call graph for this function:

◆ renderDeck()

ilBadgeProfileGUI::renderDeck ( string  $deck)
private

Definition at line 125 of file class.ilBadgeProfileGUI.php.

125 : string
126 {
127 $template = new ilTemplate('tpl.badge_backpack.html', true, true, 'components/ILIAS/Badge/');
128 $template->setVariable('DECK', $deck);
129 return $template->get();
130 }

Referenced by listBadgesCmd().

+ Here is the caller graph for this function:

◆ saveSettingsCmd()

ilBadgeProfileGUI::saveSettingsCmd ( )
private

Definition at line 329 of file class.ilBadgeProfileGUI.php.

329 : void
330 {
331 $form = $this->initSettingsForm();
332 if ($form->checkInput()) {
333 $new_email = $form->getInput('email');
334 $old_email = $this->getBackpackMail();
335
336 $this->user->writePref(self::BACKPACK_EMAIL, $new_email);
337
338 // if email was changed: delete badge files
339 if ($new_email !== $old_email) {
341 }
342
343 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('settings_saved'), true);
344 $this->ctrl->redirect($this, 'editSettings');
345 }
346
347 $form->setValuesByPost();
348 $this->editSettingsCmd($form);
349 }
static clearBadgeCache(int $a_user_id)
editSettingsCmd(?ilPropertyFormGUI $a_form=null)

References ilBadgeAssignment\clearBadgeCache(), ILIAS\Repository\ctrl(), editSettingsCmd(), getBackpackMail(), initSettingsForm(), ILIAS\Repository\lng(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ setBackpackSubTabs()

ilBadgeProfileGUI::setBackpackSubTabs ( )
private

Definition at line 232 of file class.ilBadgeProfileGUI.php.

232 : void
233 {
234 $this->tabs->addSubTab(
235 'backpack_badges',
236 $this->lng->txt('obj_bdga'),
237 $this->ctrl->getLinkTarget($this, 'listBackpackGroups')
238 );
239
240 $this->tabs->addSubTab(
241 'backpack_settings',
242 $this->lng->txt('settings'),
243 $this->ctrl->getLinkTarget($this, 'editSettings')
244 );
245
246 $this->tabs->activateTab('backpack_badges');
247 }

References ILIAS\Repository\lng(), and ILIAS\Repository\tabs().

Referenced by listBackpackGroupsCmd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $ctrl

readonly ilCtrlInterface ilBadgeProfileGUI::$ctrl
private

Definition at line 36 of file class.ilBadgeProfileGUI.php.

◆ $http

readonly ILIAS HTTP GlobalHttpState ilBadgeProfileGUI::$http
private

Definition at line 42 of file class.ilBadgeProfileGUI.php.

◆ $lng

readonly ilLanguage ilBadgeProfileGUI::$lng
private

Definition at line 37 of file class.ilBadgeProfileGUI.php.

◆ $noti_repo

readonly BadgeNotificationPrefRepository ilBadgeProfileGUI::$noti_repo
private

Definition at line 43 of file class.ilBadgeProfileGUI.php.

◆ $refinery

readonly ILIAS Refinery Factory ilBadgeProfileGUI::$refinery
private

Definition at line 41 of file class.ilBadgeProfileGUI.php.

◆ $request

readonly ilBadgeGUIRequest ilBadgeProfileGUI::$request
private

Definition at line 35 of file class.ilBadgeProfileGUI.php.

◆ $tabs

readonly ilTabsGUI ilBadgeProfileGUI::$tabs
private

Definition at line 39 of file class.ilBadgeProfileGUI.php.

◆ $tile_view

readonly TileView ilBadgeProfileGUI::$tile_view
private

Definition at line 44 of file class.ilBadgeProfileGUI.php.

◆ $tpl

readonly ilGlobalTemplateInterface ilBadgeProfileGUI::$tpl
private

Definition at line 38 of file class.ilBadgeProfileGUI.php.

Referenced by manageBadgesCmd().

◆ $user

readonly ilObjUser ilBadgeProfileGUI::$user
private

Definition at line 40 of file class.ilBadgeProfileGUI.php.

◆ BACKPACK_EMAIL

final const string ilBadgeProfileGUI::BACKPACK_EMAIL = 'badge_mozilla_bp'

Definition at line 33 of file class.ilBadgeProfileGUI.php.

◆ DEFAULT_ACTION

const string ilBadgeProfileGUI::DEFAULT_ACTION = self::LIST_BADGES_ACTION
private

Definition at line 29 of file class.ilBadgeProfileGUI.php.

Referenced by executeCommand().

◆ LIST_BADGES_ACTION

const string ilBadgeProfileGUI::LIST_BADGES_ACTION = 'listBadges'
private

Definition at line 26 of file class.ilBadgeProfileGUI.php.

◆ MANAGE_BADGES_ACTION

const string ilBadgeProfileGUI::MANAGE_BADGES_ACTION = 'manageBadges'
private

Definition at line 27 of file class.ilBadgeProfileGUI.php.

◆ TABLE_ACTIONS

const string ilBadgeProfileGUI::TABLE_ACTIONS = 'handleTableActions'
private

Definition at line 28 of file class.ilBadgeProfileGUI.php.

Referenced by getUnsafeGetCommands().

◆ TABLE_ALL_OBJECTS_ACTION

const string ilBadgeProfileGUI::TABLE_ALL_OBJECTS_ACTION = 'ALL_OBJECTS'

Definition at line 31 of file class.ilBadgeProfileGUI.php.


The documentation for this class was generated from the following file: