ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilBadgeHandler Class Reference

Class ilBadgeHandler. More...

+ Collaboration diagram for ilBadgeHandler:

Public Member Functions

 isActive ()
 
 setActive (bool $a_value)
 
 getComponents ()
 
 setComponents (array $a_components=null)
 
 getProviderInstance (string $a_component_id)
 
 getComponentCaption (string $a_component_id)
 
 getUniqueTypeId (string $a_component_id, ilBadgeType $a_badge)
 
 getTypeInstanceByUniqueId (string $a_id)
 Get type instance by unique id (component, type) More...
 
 getInactiveTypes ()
 
 setInactiveTypes (array $a_types=null)
 
 getAvailableTypes (bool $exclude_inactive=true)
 Get badges types. More...
 
 getAvailableTypesForObjType (string $a_object_type)
 Get valid badges types for object type. More...
 
 getAvailableManualBadges (int $a_parent_obj_id, string $a_parent_obj_type=null)
 Get available manual badges for object id. More...
 
 isObjectActive (int $a_obj_id, ?string $a_obj_type=null)
 
 triggerEvaluation (string $a_type_id, int $a_user_id, array $a_params=null)
 
 getUserIds (int $a_parent_ref_id, int $a_parent_obj_id=null, string $a_parent_type=null)
 
 getInstancePath (ilBadgeAssignment $a_ass)
 
 countStaticBadgeInstances (ilBadge $a_badge)
 
 getBadgePath (ilBadge $a_badge)
 
 sendNotification (array $a_user_map, int $a_parent_ref_id=null)
 

Static Public Member Functions

static getInstance ()
 
static updateFromXML (string $a_component_id)
 Import component definition. More...
 
static clearFromXML (string $a_component_id)
 Remove component definition. More...
 

Data Fields

const GENERAL_INFO = 'inform_about_badges'
 

Protected Member Functions

 __construct ()
 
 getComponent (string $a_id)
 
 getBasePath ()
 
 countStaticBadgeInstancesHelper (int &$a_cnt, string $a_path)
 

Protected Attributes

ilComponentRepository $component_repository
 
ilDBInterface $db
 
ilTree $tree
 
ilLanguage $lng
 
ilSetting $settings
 

Static Protected Attributes

static ilBadgeHandler $instance = null
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilBadgeHandler::__construct ( )
protected

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

References $DIC, and ILIAS\Repository\settings().

41  {
42  global $DIC;
43 
44  if (isset($DIC["component.repository"])) {
45  $this->component_repository = $DIC["component.repository"];
46  }
47  $this->db = $DIC->database();
48  if (isset($DIC["tree"])) {
49  $this->tree = $DIC->repositoryTree();
50  }
51  $this->settings = new ilSetting("bdga");
52  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ clearFromXML()

static ilBadgeHandler::clearFromXML ( string  $a_component_id)
static

Remove component definition.

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

298  : void
299  {
300  $handler = self::getInstance();
301  $components = $handler->getComponents();
302  foreach ($components as $idx => $component) {
303  if ($component === $a_component_id) {
304  unset($components[$idx]);
305  }
306  }
307  $handler->setComponents($components);
308  }

◆ countStaticBadgeInstances()

ilBadgeHandler::countStaticBadgeInstances ( ilBadge  $a_badge)

Definition at line 441 of file class.ilBadgeHandler.php.

References $path, countStaticBadgeInstancesHelper(), getBasePath(), and ilBadge\getId().

441  : int
442  {
443  $path = $this->getBasePath() . "instances/" . $a_badge->getId();
444  $cnt = 0;
445  if (is_dir($path)) {
447  }
448  return $cnt;
449  }
$path
Definition: ltiservices.php:32
countStaticBadgeInstancesHelper(int &$a_cnt, string $a_path)
+ Here is the call graph for this function:

◆ countStaticBadgeInstancesHelper()

ilBadgeHandler::countStaticBadgeInstancesHelper ( int &  $a_cnt,
string  $a_path 
)
protected

Definition at line 451 of file class.ilBadgeHandler.php.

Referenced by countStaticBadgeInstances().

454  : void {
455  foreach (glob($a_path . "/*") as $item) {
456  if (is_dir($item)) {
457  $this->countStaticBadgeInstancesHelper($a_cnt, $item);
458  } elseif (substr($item, -5) === ".json") {
459  $a_cnt++;
460  }
461  }
462  }
countStaticBadgeInstancesHelper(int &$a_cnt, string $a_path)
+ Here is the caller graph for this function:

◆ getAvailableManualBadges()

ilBadgeHandler::getAvailableManualBadges ( int  $a_parent_obj_id,
string  $a_parent_obj_type = null 
)

Get available manual badges for object id.

Returns
array<int, string>

Definition at line 252 of file class.ilBadgeHandler.php.

References $res, $type, ilObject\_lookupType(), getAvailableTypesForObjType(), and ilBadge\getInstancesByParentId().

255  : array {
256  $res = [];
257 
258  if (!$a_parent_obj_type) {
259  $a_parent_obj_type = ilObject::_lookupType($a_parent_obj_id);
260  }
261 
262  $badges = ilBadge::getInstancesByParentId($a_parent_obj_id);
263  foreach (self::getInstance()->getAvailableTypesForObjType($a_parent_obj_type) as $type_id => $type) {
264  if (!$type instanceof ilBadgeAuto) {
265  foreach ($badges as $badge) {
266  if ($badge->getTypeId() === $type_id &&
267  $badge->isActive()) {
268  $res[$badge->getId()] = $badge->getTitle();
269  }
270  }
271  }
272  }
273 
274  asort($res);
275  return $res;
276  }
$res
Definition: ltiservices.php:69
$type
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getAvailableTypesForObjType(string $a_object_type)
Get valid badges types for object type.
static getInstancesByParentId(int $a_parent_id, array $a_filter=null)
static _lookupType(int $id, bool $reference=false)
+ Here is the call graph for this function:

◆ getAvailableTypes()

ilBadgeHandler::getAvailableTypes ( bool  $exclude_inactive = true)

Get badges types.

Returns
array<string, ilBadgeType>

Definition at line 211 of file class.ilBadgeHandler.php.

References $id, $provider, $res, $type, getComponents(), getInactiveTypes(), getProviderInstance(), and getUniqueTypeId().

Referenced by getAvailableTypesForObjType().

211  : array
212  {
213  $res = [];
214 
215  $inactive = $this->getInactiveTypes();
216  foreach ($this->getComponents() as $component_id) {
217  $provider = $this->getProviderInstance($component_id);
218  if ($provider) {
219  foreach ($provider->getBadgeTypes() as $type) {
220  $id = $this->getUniqueTypeId($component_id, $type);
221  if (!$exclude_inactive || !in_array($id, $inactive, true)) {
222  $res[$id] = $type;
223  }
224  }
225  }
226  }
227 
228  return $res;
229  }
$res
Definition: ltiservices.php:69
$type
getUniqueTypeId(string $a_component_id, ilBadgeType $a_badge)
$provider
Definition: ltitoken.php:83
getProviderInstance(string $a_component_id)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAvailableTypesForObjType()

ilBadgeHandler::getAvailableTypesForObjType ( string  $a_object_type)

Get valid badges types for object type.

Returns
array<string, ilBadgeType>

Definition at line 235 of file class.ilBadgeHandler.php.

References $id, $res, $type, and getAvailableTypes().

Referenced by getAvailableManualBadges().

235  : array
236  {
237  $res = [];
238 
239  foreach ($this->getAvailableTypes() as $id => $type) {
240  if (in_array($a_object_type, $type->getValidObjectTypes(), true)) {
241  $res[$id] = $type;
242  }
243  }
244 
245  return $res;
246  }
$res
Definition: ltiservices.php:69
$type
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getAvailableTypes(bool $exclude_inactive=true)
Get badges types.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getBadgePath()

ilBadgeHandler::getBadgePath ( ilBadge  $a_badge)

Definition at line 464 of file class.ilBadgeHandler.php.

References $path, getBasePath(), ilBadge\getId(), and ilFileUtils\makeDirParents().

464  : string
465  {
466  $hash = md5($a_badge->getId());
467 
468  $path = $this->getBasePath() . "badges/" .
469  floor($a_badge->getId() / 100) . "/" .
470  $hash . "/";
471 
473 
474  return $path;
475  }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
$path
Definition: ltiservices.php:32
+ Here is the call graph for this function:

◆ getBasePath()

ilBadgeHandler::getBasePath ( )
protected

Definition at line 421 of file class.ilBadgeHandler.php.

References ilFileUtils\getWebspaceDir().

Referenced by countStaticBadgeInstances(), getBadgePath(), and getInstancePath().

421  : string
422  {
423  return ilFileUtils::getWebspaceDir() . "/pub_badges/";
424  }
static getWebspaceDir(string $mode="filesystem")
get webspace directory
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getComponent()

ilBadgeHandler::getComponent ( string  $a_id)
protected

Definition at line 110 of file class.ilBadgeHandler.php.

Referenced by getComponentCaption(), and getProviderInstance().

110  : ?array
111  {
112  if (!$this->component_repository->hasComponentId($a_id)) {
113  return null;
114  }
115  $component = $this->component_repository->getComponentById($a_id);
116  return [
117  "type" => $component->getType(),
118  "name" => $component->getName()
119  ];
120  }
+ Here is the caller graph for this function:

◆ getComponentCaption()

ilBadgeHandler::getComponentCaption ( string  $a_component_id)

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

References getComponent().

138  : string
139  {
140  $comp = $this->getComponent($a_component_id);
141  if ($comp) {
142  return $comp["type"] . "/" . $comp["name"];
143  }
144  return "";
145  }
getComponent(string $a_id)
+ Here is the call graph for this function:

◆ getComponents()

ilBadgeHandler::getComponents ( )
Returns
string[]

Definition at line 80 of file class.ilBadgeHandler.php.

References ILIAS\Repository\settings().

Referenced by getAvailableTypes().

80  : array
81  {
82  $components = $this->settings->get("components", null);
83  if ($components) {
84  return unserialize($components, ["allowed_classes" => false]);
85  }
86 
87  return [];
88  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInactiveTypes()

ilBadgeHandler::getInactiveTypes ( )
Returns
string[]

Definition at line 182 of file class.ilBadgeHandler.php.

References ILIAS\Repository\settings().

Referenced by getAvailableTypes(), and triggerEvaluation().

182  : array
183  {
184  $types = $this->settings->get("inactive_types", null);
185  if ($types) {
186  return unserialize($types, ["allowed_classes" => false]);
187  }
188 
189  return [];
190  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInstance()

static ilBadgeHandler::getInstance ( )
static

Definition at line 54 of file class.ilBadgeHandler.php.

Referenced by ilBadgeManagementGUI\__construct(), ilObjBadgeAdministrationGUI\activateTypes(), ilBadgeManagementGUI\addBadge(), ilObjBadgeAdministrationGUI\assertActive(), ilBadgeManagementGUI\assignBadge(), ilBadgeManagementGUI\awardBadgeUserSelection(), ilObjBadgeAdministrationGUI\deactivateTypes(), ilBadgeAssignment\deleteStaticFiles(), ilBadge\deleteStaticFiles(), ilBadgeManagementGUI\editBadge(), ilBadgeManagementGUI\executeCommand(), ilObjBadgeAdministrationGUI\getAdminTabs(), ilBadgeTypesTableGUI\getItems(), ilObjectBadgeTableGUI\getItems(), ilBadgeUserTableGUI\getItems(), ILIAS\Badge\Provider\BadgeMainBarProvider\getStaticSubItems(), ilObjGroupGUI\getTabs(), ilObjCourseGUI\getTabs(), ilBadge\getTypeInstance(), ilBadgeManagementGUI\getValidBadgesFromClipboard(), ilBadgeAppEventListener\handleEvent(), ilBadgeWAC\hasAccessToBadgeParentIdNode(), ilObjectBadgeTableGUI\initFilter(), ilBadgeTableGUI\initFilter(), ilObjBadgeAdministrationGUI\initFormSettings(), ilObjBadgeAdministrationGUI\initImageTemplateForm(), ilObjectServiceSettingsGUI\initServiceSettingsForm(), ilBadgeLearningHistoryProvider\isActive(), ilAchievements\isActive(), ilBadgeManagementGUI\listBadges(), ilBadgeManagementGUI\listUsers(), ilBadge\prepareJson(), ilBadgeDefinitionProcessor\purge(), ilBadgeManagementGUI\saveBadge(), ilPersonalProfileGUI\savePublicProfile(), ilObjBadgeAdministrationGUI\saveSettings(), ilPersonalProfileGUI\showPublicProfileFields(), and ilObjectServiceSettingsGUI\updateServiceSettingsForm().

54  : self
55  {
56  if (!self::$instance) {
57  self::$instance = new self();
58  }
59  return self::$instance;
60  }
+ Here is the caller graph for this function:

◆ getInstancePath()

ilBadgeHandler::getInstancePath ( ilBadgeAssignment  $a_ass)

Definition at line 426 of file class.ilBadgeHandler.php.

References $path, ilBadgeAssignment\getBadgeId(), getBasePath(), ilBadgeAssignment\getUserId(), and ilFileUtils\makeDirParents().

426  : string
427  {
428  $hash = md5($a_ass->getBadgeId() . "_" . $a_ass->getUserId());
429 
430  $path = $this->getBasePath() . "instances/" .
431  $a_ass->getBadgeId() . "/" .
432  floor($a_ass->getUserId() / 1000) . "/";
433 
435 
436  $path .= $hash . ".json";
437 
438  return $path;
439  }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
$path
Definition: ltiservices.php:32
+ Here is the call graph for this function:

◆ getProviderInstance()

ilBadgeHandler::getProviderInstance ( string  $a_component_id)

Definition at line 122 of file class.ilBadgeHandler.php.

References getComponent().

Referenced by getAvailableTypes(), and getTypeInstanceByUniqueId().

122  : ?ilBadgeProvider
123  {
124  $comp = $this->getComponent($a_component_id);
125  if ($comp) {
126  $class = "il" . $comp["name"] . "BadgeProvider";
127  $file = $comp["type"] . "/" . $comp["name"] . "/classes/class." . $class . ".php";
128  if (file_exists($file)) {
129  $obj = new $class();
130  if ($obj instanceof ilBadgeProvider) {
131  return $obj;
132  }
133  }
134  }
135  return null;
136  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getComponent(string $a_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTypeInstanceByUniqueId()

ilBadgeHandler::getTypeInstanceByUniqueId ( string  $a_id)

Get type instance by unique id (component, type)

Definition at line 161 of file class.ilBadgeHandler.php.

References $parts, $provider, $type, and getProviderInstance().

Referenced by triggerEvaluation().

163  : ?ilBadgeType {
164  $parts = explode("/", $a_id);
165  $comp_id = $parts[0];
166  $type_id = $parts[1];
167 
168  $provider = $this->getProviderInstance($comp_id);
169  if ($provider) {
170  foreach ($provider->getBadgeTypes() as $type) {
171  if ($type->getId() === $type_id) {
172  return $type;
173  }
174  }
175  }
176  return null;
177  }
$type
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:64
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$provider
Definition: ltitoken.php:83
getProviderInstance(string $a_component_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUniqueTypeId()

ilBadgeHandler::getUniqueTypeId ( string  $a_component_id,
ilBadgeType  $a_badge 
)

Definition at line 151 of file class.ilBadgeHandler.php.

References ilBadgeType\getId().

Referenced by getAvailableTypes().

154  : string {
155  return $a_component_id . "/" . $a_badge->getId();
156  }
getId()
Get typ id (unique for component)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUserIds()

ilBadgeHandler::getUserIds ( int  $a_parent_ref_id,
int  $a_parent_obj_id = null,
string  $a_parent_type = null 
)
Parameters
int$a_parent_ref_id
int | null$a_parent_obj_id
string | null$a_parent_type
Returns
int[]

Definition at line 376 of file class.ilBadgeHandler.php.

References $tree, ilCourseParticipants\_getInstanceByObjId(), ilGroupParticipants\_getInstanceByObjId(), ilObject\_lookupObjectId(), and ilObject\_lookupType().

380  : array {
381  $tree = $this->tree;
382 
383  if (!$a_parent_obj_id) {
384  $a_parent_obj_id = ilObject::_lookupObjectId($a_parent_ref_id);
385  }
386  if (!$a_parent_type) {
387  $a_parent_type = ilObject::_lookupType($a_parent_obj_id);
388  }
389 
390  // try to get participants from (parent) course/group
391  switch ($a_parent_type) {
392  case "crs":
393  $member_obj = ilCourseParticipants::_getInstanceByObjId($a_parent_obj_id);
394  return $member_obj->getMembers();
395 
396  case "grp":
397  $member_obj = ilGroupParticipants::_getInstanceByObjId($a_parent_obj_id);
398  return $member_obj->getMembers();
399 
400  default:
401  // walk path to find course or group object and use members of that object
402  /* this does not work since getParticipantsForObject does not exist
403  $path = $tree->getPathId($a_parent_ref_id);
404  array_pop($path);
405  foreach (array_reverse($path) as $path_ref_id) {
406  $type = ilObject::_lookupType($path_ref_id, true);
407  if ($type == "crs" || $type == "grp") {
408  return $this->getParticipantsForObject($path_ref_id, null, $type);
409  }
410  }*/
411  break;
412  }
413  return [];
414  }
static _getInstanceByObjId(int $a_obj_id)
static _lookupObjectId(int $ref_id)
static _getInstanceByObjId(int $a_obj_id)
Get singleton instance.
static _lookupType(int $id, bool $reference=false)
+ Here is the call graph for this function:

◆ isActive()

ilBadgeHandler::isActive ( )

Definition at line 67 of file class.ilBadgeHandler.php.

References ILIAS\Repository\settings().

Referenced by isObjectActive(), and triggerEvaluation().

67  : bool
68  {
69  return (bool) $this->settings->get("active", "");
70  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isObjectActive()

ilBadgeHandler::isObjectActive ( int  $a_obj_id,
?string  $a_obj_type = null 
)

Definition at line 315 of file class.ilBadgeHandler.php.

References ilContainer\_lookupContainerSetting(), ilObject\_lookupType(), ilObjectServiceSettingsGUI\BADGES, and isActive().

318  : bool {
319  if (!$this->isActive()) {
320  return false;
321  }
322 
323  if (!$a_obj_type) {
324  $a_obj_type = ilObject::_lookupType($a_obj_id);
325  }
326 
327  if ($a_obj_type !== "bdga" && !ilContainer::_lookupContainerSetting(
328  $a_obj_id,
330  false
331  )) {
332  return false;
333  }
334 
335  return true;
336  }
static _lookupContainerSetting(int $a_id, string $a_keyword, string $a_default_value=null)
static _lookupType(int $id, bool $reference=false)
+ Here is the call graph for this function:

◆ sendNotification()

ilBadgeHandler::sendNotification ( array  $a_user_map,
int  $a_parent_ref_id = null 
)

Definition at line 482 of file class.ilBadgeHandler.php.

References $url, ilLink\_getLink(), ilObjUser\_lookupEmail(), ANONYMOUS_USER_ID, ilBadgeAssignment\exists(), ilUtil\getImagePath(), ilLanguage\getUserLanguage(), ilContext\hasHTML(), and ilLanguage\txt().

Referenced by triggerEvaluation().

485  : void {
486  $badges = [];
487 
488  foreach ($a_user_map as $user_id => $badge_ids) {
489  $user_badges = [];
490 
491  foreach ($badge_ids as $badge_id) {
492  // making extra sure
493  if (!ilBadgeAssignment::exists($badge_id, $user_id)) {
494  continue;
495  }
496 
497  if (!array_key_exists($badge_id, $badges)) {
498  $badges[$badge_id] = new ilBadge($badge_id);
499  }
500 
501  $badge = $badges[$badge_id];
502 
503  $user_badges[] = $badge->getTitle();
504  }
505 
506  if (count($user_badges)) {
507  // compose and send mail
508 
509  $ntf = new ilSystemNotification(false);
510  $ntf->setLangModules(["badge"]);
511 
512  if (isset($a_parent_ref_id)) {
513  $ntf->setRefId($a_parent_ref_id);
514  }
515  $ntf->setGotoLangId("badge_notification_parent_goto");
516 
517  // user specific language
518  $lng = $ntf->getUserLanguage($user_id);
519 
520  $ntf->setIntroductionLangId("badge_notification_body");
521 
522  $ntf->addAdditionalInfo("badge_notification_badges", implode("\n", $user_badges), true);
523 
524  $url = ilLink::_getLink($user_id, "usr", [], "_bdg");
525  $ntf->addAdditionalInfo("badge_notification_badges_goto", $url);
526 
527  $ntf->setReasonLangId("badge_notification_reason");
528 
529  // force email
530  $mail = new ilMail(ANONYMOUS_USER_ID);
531  $mail->enqueue(
532  ilObjUser::_lookupEmail($user_id),
533  "",
534  "",
535  $lng->txt("badge_notification_subject"),
536  $ntf->composeAndGetMessage($user_id, null, "read", true),
537  []
538  );
539 
540 
541  // osd
542  // bug #24562
543  if (ilContext::hasHTML()) {
544  $url = new ilNotificationLink(new ilNotificationParameter('badge_notification_badges_goto', [], 'badge'), $url);
545  $osd_params = ["badge_list" => implode(", ", $user_badges)];
546 
547  $notification = new ilNotificationConfig(BadgeNotificationProvider::NOTIFICATION_TYPE);
548  $notification->setTitleVar("badge_notification_subject", [], "badge");
549  $notification->setShortDescriptionVar("badge_notification_osd", $osd_params, "badge");
550  $notification->setLongDescriptionVar("");
551  $notification->setLinks([$url]);
552  $notification->setIconPath(ilUtil::getImagePath('icon_bdga.svg'));
553  $notification->setValidForSeconds(ilNotificationConfig::TTL_SHORT);
554  $notification->setVisibleForSeconds(ilNotificationConfig::DEFAULT_TTS);
555  $notification->setIdentification(new NotificationIdentification(
556  BadgeNotificationProvider::NOTIFICATION_TYPE,
557  self::GENERAL_INFO
558  ));
559  $notification->notifyByUsers([$user_id]);
560  }
561  }
562  }
563  }
const ANONYMOUS_USER_ID
Definition: constants.php:27
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...
getUserLanguage()
Return language of user.
description of a localized parameter this information is used locate translations while processing no...
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static hasHTML()
Has HTML output.
static exists(int $a_badge_id, int $a_user_id)
$url
static _lookupEmail(int $a_user_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setActive()

ilBadgeHandler::setActive ( bool  $a_value)

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

References ILIAS\Repository\settings().

72  : void
73  {
74  $this->settings->set("active", (string) $a_value);
75  }
+ Here is the call graph for this function:

◆ setComponents()

ilBadgeHandler::setComponents ( array  $a_components = null)
Parameters
string[]|null$a_components
Returns
void

Definition at line 95 of file class.ilBadgeHandler.php.

References ILIAS\Repository\settings().

95  : void
96  {
97  if (isset($a_components) && count($a_components) === 0) {
98  $a_components = null;
99  }
100  $this->settings->set("components", $a_components !== null
101  ? serialize(array_unique($a_components))
102  : "");
103  }
+ Here is the call graph for this function:

◆ setInactiveTypes()

ilBadgeHandler::setInactiveTypes ( array  $a_types = null)
Parameters
string[]|null$a_types
Returns
void

Definition at line 196 of file class.ilBadgeHandler.php.

References ILIAS\Repository\settings().

196  : void
197  {
198  if (is_array($a_types) &&
199  !count($a_types)) {
200  $a_types = null;
201  }
202  $this->settings->set("inactive_types", $a_types !== null
203  ? serialize(array_unique($a_types))
204  : "");
205  }
+ Here is the call graph for this function:

◆ triggerEvaluation()

ilBadgeHandler::triggerEvaluation ( string  $a_type_id,
int  $a_user_id,
array  $a_params = null 
)

Definition at line 338 of file class.ilBadgeHandler.php.

References $type, ilBadgeAssignment\exists(), getInactiveTypes(), ilBadge\getInstancesByType(), getTypeInstanceByUniqueId(), isActive(), sendNotification(), and ilBadgeAssignment\store().

342  : void {
343  if (!$this->isActive() || in_array($a_type_id, $this->getInactiveTypes(), true)) {
344  return;
345  }
346 
347  $type = $this->getTypeInstanceByUniqueId($a_type_id);
348  if (!$type instanceof ilBadgeAuto) {
349  return;
350  }
351 
352  $new_badges = [];
353  foreach (ilBadge::getInstancesByType($a_type_id) as $badge) {
354  if ($badge->isActive()) {
355  // already assigned?
356  if (!ilBadgeAssignment::exists($badge->getId(), $a_user_id)) {
357  if ($type->evaluate($a_user_id, (array) $a_params, $badge->getConfiguration())) {
358  $ass = new ilBadgeAssignment($badge->getId(), $a_user_id);
359  $ass->store();
360 
361  $new_badges[$a_user_id][] = $badge->getId();
362  }
363  }
364  }
365  }
366 
367  $this->sendNotification($new_badges);
368  }
static getInstancesByType(string $a_type_id)
getTypeInstanceByUniqueId(string $a_id)
Get type instance by unique id (component, type)
$type
sendNotification(array $a_user_map, int $a_parent_ref_id=null)
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...
static exists(int $a_badge_id, int $a_user_id)
+ Here is the call graph for this function:

◆ updateFromXML()

static ilBadgeHandler::updateFromXML ( string  $a_component_id)
static

Import component definition.

Definition at line 287 of file class.ilBadgeHandler.php.

Referenced by ilBadgeDefinitionProcessor\beginTag().

287  : void
288  {
289  $handler = self::getInstance();
290  $components = $handler->getComponents();
291  $components[] = $a_component_id;
292  $handler->setComponents($components);
293  }
+ Here is the caller graph for this function:

Field Documentation

◆ $component_repository

ilComponentRepository ilBadgeHandler::$component_repository
protected

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

◆ $db

ilDBInterface ilBadgeHandler::$db
protected

Definition at line 34 of file class.ilBadgeHandler.php.

◆ $instance

ilBadgeHandler ilBadgeHandler::$instance = null
staticprotected

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

◆ $lng

ilLanguage ilBadgeHandler::$lng
protected

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

◆ $settings

ilSetting ilBadgeHandler::$settings
protected

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

◆ $tree

ilTree ilBadgeHandler::$tree
protected

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

Referenced by getUserIds().

◆ GENERAL_INFO

const ilBadgeHandler::GENERAL_INFO = 'inform_about_badges'

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


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