ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilBadgeHandler Class Reference
+ Collaboration diagram for ilBadgeHandler:

Public Member Functions

 isActive ()
 
 setActive ($a_value)
 
 isObiActive ()
 
 setObiActive ($a_value)
 
 getObiOrganistation ()
 
 setObiOrganisation ($a_value)
 
 getObiContact ()
 
 setObiContact ($a_value)
 
 getObiSalt ()
 
 setObiSalt ($a_value)
 
 getComponents ()
 
 setComponents (array $a_components=null)
 
 getProviderInstance ($a_component_id)
 Get provider instance. More...
 
 getComponentCaption ($a_component_id)
 
 getUniqueTypeId ($a_component_id, ilBadgeType $a_badge)
 
 getTypeInstanceByUniqueId ($a_id)
 Get type instance by unique id (component, type) More...
 
 getInactiveTypes ()
 
 setInactiveTypes (array $a_types=null)
 
 getAvailableTypes ()
 Get badges types. More...
 
 getAvailableTypesForObjType ($a_object_type)
 Get valid badges types for object type. More...
 
 getAvailableManualBadges ($a_parent_obj_id, $a_parent_obj_type=null)
 Get available manual badges for object id. More...
 
 isObjectActive ($a_obj_id, $a_obj_type=null)
 
 triggerEvaluation ($a_type_id, $a_user_id, array $a_params=null)
 
 getUserIds ($a_parent_ref_id, $a_parent_obj_id=null, $a_parent_type=null)
 
 getInstancePath (ilBadgeAssignment $a_ass)
 
 countStaticBadgeInstances (ilBadge $a_badge)
 
 getBadgePath (ilBadge $a_badge)
 
 getIssuerStaticUrl ()
 
 rebuildIssuerStaticUrl ()
 
 sendNotification (array $a_user_map, $a_parent_ref_id=null)
 

Static Public Member Functions

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

Protected Member Functions

 __construct ()
 Constructor. More...
 
 getComponent ($a_id)
 
 getBasePath ()
 
 countStaticBadgeInstancesHelper (&$a_cnt, $a_path)
 
 prepareIssuerJson ($a_url)
 

Protected Attributes

 $settings
 

Static Protected Attributes

static $instance
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilBadgeHandler::__construct ( )
protected

Constructor.

Returns
self

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

References settings().

24  {
25  $this->settings = new ilSetting("bdga");
26  }
ILIAS Setting Class.
settings()
Definition: settings.php:2
+ Here is the call graph for this function:

Member Function Documentation

◆ clearFromXML()

static ilBadgeHandler::clearFromXML (   $a_component_id)
static

Remove component definition.

Parameters
string$a_component_id

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

341  {
342  $handler = self::getInstance();
343  $components = $handler->getComponents();
344  foreach($components as $idx => $component)
345  {
346  if($component == $a_component_id)
347  {
348  unset($components[$idx]);
349  }
350  }
351  $handler->setComponents($components);
352  }

◆ countStaticBadgeInstances()

ilBadgeHandler::countStaticBadgeInstances ( ilBadge  $a_badge)

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

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

494  {
495  $path = $this->getBasePath()."instances/".$a_badge->getId();
496  $cnt = 0;
497  if(is_dir($path))
498  {
500  }
501  return $cnt;
502  }
$path
Definition: aliased.php:25
countStaticBadgeInstancesHelper(&$a_cnt, $a_path)
+ Here is the call graph for this function:

◆ countStaticBadgeInstancesHelper()

ilBadgeHandler::countStaticBadgeInstancesHelper ( $a_cnt,
  $a_path 
)
protected

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

Referenced by countStaticBadgeInstances().

505  {
506  foreach(glob($a_path."/*") as $item)
507  {
508  if(is_dir($item))
509  {
510  $this->countStaticBadgeInstancesHelper($a_cnt, $item);
511  }
512  else if(substr($item, -5) == ".json")
513  {
514  $a_cnt++;
515  }
516  }
517  }
countStaticBadgeInstancesHelper(&$a_cnt, $a_path)
+ Here is the caller graph for this function:

◆ getAvailableManualBadges()

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

Get available manual badges for object id.

Parameters
int$a_parent_obj_id
string$a_parent_obj_type
Returns
array id,title

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

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

287  {
288  $res = array();
289 
290  if(!$a_parent_obj_type)
291  {
292  $a_parent_obj_type = ilObject::_lookupType($a_parent_obj_id);
293  }
294 
295  include_once "./Services/Badge/classes/class.ilBadge.php";
296  $badges = ilBadge::getInstancesByParentId($a_parent_obj_id);
297  foreach(ilBadgeHandler::getInstance()->getAvailableTypesForObjType($a_parent_obj_type) as $type_id => $type)
298  {
299  if(!$type instanceof ilBadgeAuto)
300  {
301  foreach($badges as $badge)
302  {
303  if($badge->getTypeId() == $type_id &&
304  $badge->isActive())
305  {
306  $res[$badge->getId()] = $badge->getTitle();
307  }
308  }
309  }
310  }
311 
312  asort($res);
313  return $res;
314  }
getAvailableTypesForObjType($a_object_type)
Get valid badges types for object type.
Manual Badge Auto.
static getInstancesByParentId($a_parent_id, array $a_filter=null)
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static getInstance()
Constructor.
+ Here is the call graph for this function:

◆ getAvailableTypes()

ilBadgeHandler::getAvailableTypes ( )

Get badges types.

Returns
ilBadgeType[]

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

References League\OAuth2\Client\Provider\$provider, $res, array, getComponents(), getInactiveTypes(), getProviderInstance(), and getUniqueTypeId().

Referenced by getAvailableTypesForObjType().

235  {
236  $res = array();
237 
238  $inactive = $this->getInactiveTypes();
239  foreach($this->getComponents() as $component_id)
240  {
241  $provider = $this->getProviderInstance($component_id);
242  if($provider)
243  {
244  foreach($provider->getBadgeTypes() as $type)
245  {
246  $id = $this->getUniqueTypeId($component_id, $type);
247  if(!in_array($id, $inactive))
248  {
249  $res[$id] = $type;
250  }
251  }
252  }
253  }
254 
255  return $res;
256  }
getProviderInstance($a_component_id)
Get provider instance.
Create styles array
The data for the language used.
getUniqueTypeId($a_component_id, ilBadgeType $a_badge)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAvailableTypesForObjType()

ilBadgeHandler::getAvailableTypesForObjType (   $a_object_type)

Get valid badges types for object type.

Parameters
string$a_object_type
Returns
ilBadgeType[]

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

References $res, array, and getAvailableTypes().

Referenced by getAvailableManualBadges().

265  {
266  $res = array();
267 
268  foreach($this->getAvailableTypes() as $id => $type)
269  {
270  if(in_array($a_object_type, $type->getValidObjectTypes()))
271  {
272  $res[$id] = $type;
273  }
274  }
275 
276  return $res;
277  }
getAvailableTypes()
Get badges types.
Create styles array
The data for the language used.
+ 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 519 of file class.ilBadgeHandler.php.

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

520  {
521  $hash = md5($a_badge->getId());
522 
523  $path = $this->getBasePath()."badges/".
524  floor($a_badge->getId()/100)."/".
525  $hash."/";
526 
527  ilUtil::makeDirParents($path);
528 
529  return $path;
530  }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$path
Definition: aliased.php:25
+ Here is the call graph for this function:

◆ getBasePath()

ilBadgeHandler::getBasePath ( )
protected

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

References ilUtil\getWebspaceDir().

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

474  {
475  return ilUtil::getWebspaceDir()."/pub_badges/";
476  }
static getWebspaceDir($mode="filesystem")
get webspace directory
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getComponent()

ilBadgeHandler::getComponent (   $a_id)
protected

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

References $ilDB.

Referenced by getComponentCaption(), and getProviderInstance().

128  {
129  global $ilDB;
130 
131  // see ilCtrl
132  $set = $ilDB->query("SELECT * FROM il_component".
133  " WHERE id = ".$ilDB->quote($a_id, "text"));
134  $rec = $ilDB->fetchAssoc($set);
135  if($rec["type"])
136  {
137  return $rec;
138  }
139  }
global $ilDB
+ Here is the caller graph for this function:

◆ getComponentCaption()

ilBadgeHandler::getComponentCaption (   $a_component_id)

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

References getComponent().

167  {
168  $comp = $this->getComponent($a_component_id);
169  if($comp)
170  {
171  return $comp["type"]."/".$comp["name"];
172  }
173  }
+ Here is the call graph for this function:

◆ getComponents()

ilBadgeHandler::getComponents ( )

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

References array, and settings().

Referenced by getAvailableTypes().

101  {
102  $components = $this->settings->get("components", null);
103  if($components)
104  {
105  return unserialize($components);
106  }
107  return array();
108  }
Create styles array
The data for the language used.
settings()
Definition: settings.php:2
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInactiveTypes()

ilBadgeHandler::getInactiveTypes ( )

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

References array, and settings().

Referenced by getAvailableTypes(), and triggerEvaluation().

208  {
209  $types = $this->settings->get("inactive_types", null);
210  if($types)
211  {
212  return unserialize($types);
213  }
214  return array();
215  }
Create styles array
The data for the language used.
settings()
Definition: settings.php:2
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInstance()

static ilBadgeHandler::getInstance ( )
static

Constructor.

Returns
self

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

Referenced by ilBadgePersonalTableGUI\__construct(), ilBadgeManagementGUI\__construct(), ilObjBadgeAdministrationGUI\activateTypes(), ilBadgeManagementGUI\addBadge(), ilBadgeProfileGUI\addToBackpack(), ilObjBadgeAdministrationGUI\assertActive(), ilBadgeManagementGUI\assignBadge(), ilBadgeManagementGUI\awardBadgeUserSelection(), ilObjBadgeAdministrationGUI\deactivateTypes(), ilBadgeAssignment\deleteStaticFiles(), ilBadge\deleteStaticFiles(), ilBadgeManagementGUI\editBadge(), ilBadgeProfileGUI\editSettings(), ilBadgeManagementGUI\executeCommand(), ilBadgePersonalTableGUI\fillRow(), ilObjBadgeAdministrationGUI\getAdminTabs(), getAvailableManualBadges(), ilBadgeAssignment\getImagePath(), ilBadgeTypesTableGUI\getItems(), ilObjectBadgeTableGUI\getItems(), ilBadgeUserTableGUI\getItems(), ilBadgeAssignment\getStaticUrl(), ilBadge\getStaticUrl(), ilBadgeProfileGUI\getSubTabs(), ilObjGroupGUI\getTabs(), ilObjCourseGUI\getTabs(), ilBadge\getTypeInstance(), ilBadgeManagementGUI\getValidBadgesFromClipboard(), ilBadgeAppEventListener\handleEvent(), ilObjectBadgeTableGUI\initFilter(), ilBadgeTableGUI\initFilter(), ilObjBadgeAdministrationGUI\initFormSettings(), ilObjBadgeAdministrationGUI\initImageTemplateForm(), ilObjectServiceSettingsGUI\initServiceSettingsForm(), ilBadgeProfileGUI\listBackpackGroups(), ilBadgeManagementGUI\listBadges(), ilBadgeManagementGUI\listUsers(), ilBadgeAssignment\prepareJson(), ilBadge\prepareJson(), ilMainMenuGUI\renderEntry(), ilBadgeManagementGUI\saveBadge(), ilPersonalProfileGUI\savePublicProfile(), ilObjBadgeAdministrationGUI\saveSettings(), ilBadgeProfileGUI\setTabs(), ilPersonalProfileGUI\showPublicProfileFields(), and ilObjectServiceSettingsGUI\updateServiceSettingsForm().

34  {
35  if(!self::$instance)
36  {
37  self::$instance = new self();
38  }
39  return self::$instance;
40  }
+ Here is the caller graph for this function:

◆ getInstancePath()

ilBadgeHandler::getInstancePath ( ilBadgeAssignment  $a_ass)

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

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

479  {
480  $hash = md5($a_ass->getBadgeId()."_".$a_ass->getUserId());
481 
482  $path = $this->getBasePath()."instances/".
483  $a_ass->getBadgeId()."/".
484  floor($a_ass->getUserId()/1000)."/";
485 
486  ilUtil::makeDirParents($path);
487 
488  $path .= $hash.".json";
489 
490  return $path;
491  }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$path
Definition: aliased.php:25
+ Here is the call graph for this function:

◆ getIssuerStaticUrl()

ilBadgeHandler::getIssuerStaticUrl ( )

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

References $path, $url, getBasePath(), ilUtil\makeDirParents(), and prepareIssuerJson().

Referenced by rebuildIssuerStaticUrl().

546  {
547  $path = $this->getBasePath()."issuer/";
549  $path .= "issuer.json";
550 
551  $url = ILIAS_HTTP_PATH.substr($path, 1);
552 
553  if(!file_exists($path))
554  {
555  $json = json_encode($this->prepareIssuerJson($url));
556  file_put_contents($path, $json);
557  }
558 
559  return $url;
560  }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$path
Definition: aliased.php:25
$url
Definition: shib_logout.php:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getObiContact()

ilBadgeHandler::getObiContact ( )

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

References settings().

Referenced by prepareIssuerJson().

81  {
82  return $this->settings->get("obi_contact", null);
83  }
settings()
Definition: settings.php:2
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getObiOrganistation()

ilBadgeHandler::getObiOrganistation ( )

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

References settings().

Referenced by prepareIssuerJson().

71  {
72  return $this->settings->get("obi_organisation", null);
73  }
settings()
Definition: settings.php:2
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getObiSalt()

ilBadgeHandler::getObiSalt ( )

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

References settings().

91  {
92  return $this->settings->get("obi_salt", null);
93  }
settings()
Definition: settings.php:2
+ Here is the call graph for this function:

◆ getProviderInstance()

ilBadgeHandler::getProviderInstance (   $a_component_id)

Get provider instance.

Parameters
string$a_component_id
Returns
ilBadgeProvider

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

References $file, and getComponent().

Referenced by getAvailableTypes(), and getTypeInstanceByUniqueId().

148  {
149  $comp = $this->getComponent($a_component_id);
150  if($comp)
151  {
152  $class = "il".$comp["name"]."BadgeProvider";
153  $file = $comp["type"]."/".$comp["name"]."/classes/class.".$class.".php";
154  if(file_exists($file))
155  {
156  include_once $file;
157  $obj = new $class;
158  if($obj instanceof ilBadgeProvider)
159  {
160  return $obj;
161  }
162  }
163  }
164  }
Badge Provider interface.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTypeInstanceByUniqueId()

ilBadgeHandler::getTypeInstanceByUniqueId (   $a_id)

Get type instance by unique id (component, type)

Parameters
string$a_id
Returns
ilBadgeType

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

References League\OAuth2\Client\Provider\$provider, and getProviderInstance().

Referenced by triggerEvaluation().

190  {
191  $parts = explode("/", $a_id);
192  $comp_id = $parts[0];
193  $type_id = $parts[1];
194  $provider = $this->getProviderInstance($comp_id);
195  if($provider)
196  {
197  foreach($provider->getBadgeTypes() as $type)
198  {
199  if($type->getId() == $type_id)
200  {
201  return $type;
202  }
203  }
204  }
205  }
getProviderInstance($a_component_id)
Get provider instance.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUniqueTypeId()

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

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

References ilBadgeType\getId().

Referenced by getAvailableTypes().

180  {
181  return $a_component_id."/".$a_badge->getId();
182  }
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 (   $a_parent_ref_id,
  $a_parent_obj_id = null,
  $a_parent_type = null 
)

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

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

427  {
428  global $tree;
429 
430  if(!$a_parent_obj_id)
431  {
432  $a_parent_obj_id = ilObject::_lookupObjectId($a_parent_ref_id);
433  }
434  if(!$a_parent_type)
435  {
436  $a_parent_type = ilObject::_lookupType($a_parent_obj_id);
437  }
438 
439  // try to get participants from (parent) course/group
440  switch($a_parent_type)
441  {
442  case "crs":
443  include_once "Modules/Course/classes/class.ilCourseParticipants.php";
444  $member_obj = ilCourseParticipants::_getInstanceByObjId($a_parent_obj_id);
445  return $member_obj->getMembers();
446 
447  case "grp":
448  include_once "Modules/Group/classes/class.ilGroupParticipants.php";
449  $member_obj = ilGroupParticipants::_getInstanceByObjId($a_parent_obj_id);
450  return $member_obj->getMembers();
451 
452  default:
453  // walk path to find course or group object and use members of that object
454  $path = $tree->getPathId($a_parent_ref_id);
455  array_pop($path);
456  foreach(array_reverse($path) as $path_ref_id)
457  {
458  $type = ilObject::_lookupType($path_ref_id, true);
459  if($type == "crs" || $type == "grp")
460  {
461  return $this->getParticipantsForObject($path_ref_id, null, $type);
462  }
463  }
464  break;
465  }
466  }
$path
Definition: aliased.php:25
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static _lookupObjectId($a_ref_id)
lookup object id
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static _lookupType($a_id, $a_reference=false)
lookup object type
+ Here is the call graph for this function:

◆ isActive()

ilBadgeHandler::isActive ( )

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

References settings().

Referenced by isObjectActive(), and triggerEvaluation().

48  {
49  return $this->settings->get("active", false);
50  }
settings()
Definition: settings.php:2
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isObiActive()

ilBadgeHandler::isObiActive ( )

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

References settings().

58  {
59  // see bug #20124
60  return false;
61 
62  return $this->settings->get("obi_active", false);
63  }
settings()
Definition: settings.php:2
+ Here is the call graph for this function:

◆ isObjectActive()

ilBadgeHandler::isObjectActive (   $a_obj_id,
  $a_obj_type = null 
)

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

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

360  {
361  if(!$this->isActive())
362  {
363  return false;
364  }
365 
366  if(!$a_obj_type)
367  {
368  $a_obj_type = ilObject::_lookupType($a_obj_id);
369  }
370 
371  if($a_obj_type != "bdga")
372  {
373  include_once 'Services/Container/classes/class.ilContainer.php';
374  include_once 'Services/Object/classes/class.ilObjectServiceSettingsGUI.php';
376  $a_obj_id,
378  false))
379  {
380  return false;
381  }
382  }
383 
384  return true;
385  }
static _lookupType($a_id, $a_reference=false)
lookup object type
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=NULL)
Lookup a container setting.
+ Here is the call graph for this function:

◆ prepareIssuerJson()

ilBadgeHandler::prepareIssuerJson (   $a_url)
protected

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

References getObiContact(), and getObiOrganistation().

Referenced by getIssuerStaticUrl().

533  {
534  $json = new stdClass();
535  $json->{"@context"} = "https://w3id.org/openbadges/v1";
536  $json->type = "Issuer";
537  $json->id = $a_url;
538  $json->name = $this->getObiOrganistation();
539  $json->url = ILIAS_HTTP_PATH."/";
540  $json->email = $this->getObiContact();
541 
542  return $json;
543  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rebuildIssuerStaticUrl()

ilBadgeHandler::rebuildIssuerStaticUrl ( )

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

References $path, getBasePath(), and getIssuerStaticUrl().

563  {
564  $path = $this->getBasePath()."issuer/issuer.json";
565  if(file_exists($path))
566  {
567  unlink($path);
568  }
569  $this->getIssuerStaticUrl();
570  }
$path
Definition: aliased.php:25
+ Here is the call graph for this function:

◆ sendNotification()

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

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

References $lng, $url, ilLink\_getLink(), ilObjUser\_lookupEmail(), array, ilNotificationConfig\DEFAULT_TTS, ilBadgeAssignment\exists(), and ilNotificationConfig\TTL_SHORT.

Referenced by triggerEvaluation().

578  {
579  global $lng;
580 
581  $badges = array();
582 
583  include_once "Services/Badge/classes/class.ilBadge.php";
584  include_once "Services/Badge/classes/class.ilBadgeAssignment.php";
585  include_once "Services/Notification/classes/class.ilSystemNotification.php";
586  include_once "Services/Link/classes/class.ilLink.php";
587 
588  foreach($a_user_map as $user_id => $badge_ids)
589  {
590  $user_badges = array();
591 
592  foreach($badge_ids as $badge_id)
593  {
594  // making extra sure
595  if(!ilBadgeAssignment::exists($badge_id, $user_id))
596  {
597  continue;
598  }
599 
600  if(!array_key_exists($badge_id, $badges))
601  {
602  $badges[$badge_id] = new ilBadge($badge_id);
603  }
604 
605  $badge = $badges[$badge_id];
606 
607  $user_badges[] = $badge->getTitle();
608  }
609 
610  if(sizeof($user_badges))
611  {
612  // compose and send mail
613 
614  $ntf = new ilSystemNotification(false);
615  $ntf->setLangModules(array("badge"));
616 
617  $ntf->setRefId($a_parent_ref_id);
618  $ntf->setGotoLangId("badge_notification_parent_goto");
619 
620  // user specific language
621  $lng = $ntf->getUserLanguage($user_id);
622 
623  $ntf->setIntroductionLangId("badge_notification_body");
624 
625  $ntf->addAdditionalInfo("badge_notification_badges", implode("\n", $user_badges), true);
626 
627  $url = ilLink::_getLink($user_id, "usr", array(), "_bdg");
628  $ntf->addAdditionalInfo("badge_notification_badges_goto", $url);
629 
630  $ntf->setReasonLangId("badge_notification_reason");
631 
632  // force email
633  $mail = new ilMail(ANONYMOUS_USER_ID);
634  $mail->enableSOAP(false);
635  $mail->sendMail(ilObjUser::_lookupEmail($user_id),
636  null,
637  null,
638  $lng->txt("badge_notification_subject"),
639  $ntf->composeAndGetMessage($user_id, null, "read", true),
640  null,
641  array("system"));
642 
643 
644  // osd
645 
646  $osd_params = array("badge_list" => "<br />".implode("<br />", $user_badges));
647 
648  require_once "Services/Notifications/classes/class.ilNotificationConfig.php";
649  $notification = new ilNotificationConfig("osd_main");
650  $notification->setTitleVar("badge_notification_subject", array(), "badge");
651  $notification->setShortDescriptionVar("badge_notification_osd", $osd_params, "badge");
652  $notification->setLongDescriptionVar("", $osd_params, "");
653  $notification->setAutoDisable(false);
654  $notification->setLink($url);
655  $notification->setIconPath("templates/default/images/icon_bdga.svg");
656  $notification->setValidForSeconds(ilNotificationConfig::TTL_SHORT);
657  $notification->setVisibleForSeconds(ilNotificationConfig::DEFAULT_TTS);
658  $notification->notifyByUsers(array($user_id));
659  }
660  }
661  }
static exists($a_badge_id, $a_user_id)
$url
Definition: shib_logout.php:72
Describes a notification and provides methods for publishing this notification.
This class handles base functions for mail handling.
Create styles array
The data for the language used.
static _lookupEmail($a_user_id)
Lookup email.
global $lng
Definition: privfeed.php:17
Wrapper classes for system notifications.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setActive()

ilBadgeHandler::setActive (   $a_value)

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

References settings().

53  {
54  $this->settings->set("active", (bool)$a_value);
55  }
settings()
Definition: settings.php:2
+ Here is the call graph for this function:

◆ setComponents()

ilBadgeHandler::setComponents ( array  $a_components = null)

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

References settings().

111  {
112  if(is_array($a_components) &&
113  !sizeof($a_components))
114  {
115  $a_components = null;
116  }
117  $this->settings->set("components", $a_components !== null
118  ? serialize(array_unique($a_components))
119  : null);
120  }
settings()
Definition: settings.php:2
+ Here is the call graph for this function:

◆ setInactiveTypes()

ilBadgeHandler::setInactiveTypes ( array  $a_types = null)

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

References settings().

218  {
219  if(is_array($a_types) &&
220  !sizeof($a_types))
221  {
222  $a_types = null;
223  }
224  $this->settings->set("inactive_types", $a_types !== null
225  ? serialize(array_unique($a_types))
226  : null);
227  }
settings()
Definition: settings.php:2
+ Here is the call graph for this function:

◆ setObiActive()

ilBadgeHandler::setObiActive (   $a_value)

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

References settings().

66  {
67  $this->settings->set("obi_active", (bool)$a_value);
68  }
settings()
Definition: settings.php:2
+ Here is the call graph for this function:

◆ setObiContact()

ilBadgeHandler::setObiContact (   $a_value)

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

References settings().

86  {
87  $this->settings->set("obi_contact", trim($a_value));
88  }
settings()
Definition: settings.php:2
+ Here is the call graph for this function:

◆ setObiOrganisation()

ilBadgeHandler::setObiOrganisation (   $a_value)

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

References settings().

76  {
77  $this->settings->set("obi_organisation", trim($a_value));
78  }
settings()
Definition: settings.php:2
+ Here is the call graph for this function:

◆ setObiSalt()

ilBadgeHandler::setObiSalt (   $a_value)

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

References settings().

96  {
97  $this->settings->set("obi_salt", trim($a_value));
98  }
settings()
Definition: settings.php:2
+ Here is the call graph for this function:

◆ triggerEvaluation()

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

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

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

388  {
389  if(!$this->isActive() ||
390  in_array($a_type_id, $this->getInactiveTypes()))
391  {
392  return;
393  }
394 
395  $type = $this->getTypeInstanceByUniqueId($a_type_id);
396  if(!$type ||
397  !$type instanceof ilBadgeAuto)
398  {
399  return;
400  }
401 
402  include_once "Services/Badge/classes/class.ilBadge.php";
403  include_once "Services/Badge/classes/class.ilBadgeAssignment.php";
404  $new_badges = array();
405  foreach(ilBadge::getInstancesByType($a_type_id) as $badge)
406  {
407  if($badge->isActive())
408  {
409  // already assigned?
410  if(!ilBadgeAssignment::exists($badge->getId(), $a_user_id))
411  {
412  if((bool)$type->evaluate($a_user_id, (array)$a_params, (array)$badge->getConfiguration()))
413  {
414  $ass = new ilBadgeAssignment($badge->getId(), $a_user_id);
415  $ass->store();
416 
417  $new_badges[$a_user_id][] = $badge->getId();
418  }
419  }
420  }
421  }
422 
423  $this->sendNotification($new_badges);
424  }
static exists($a_badge_id, $a_user_id)
getTypeInstanceByUniqueId($a_id)
Get type instance by unique id (component, type)
sendNotification(array $a_user_map, $a_parent_ref_id=null)
Manual Badge Auto.
Create styles array
The data for the language used.
static getInstancesByType($a_type_id)
+ Here is the call graph for this function:

◆ updateFromXML()

static ilBadgeHandler::updateFromXML (   $a_component_id)
static

Import component definition.

Parameters
string$a_component_id

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

Referenced by ilObjDefReader\handlerBeginTag().

328  {
329  $handler = self::getInstance();
330  $components = $handler->getComponents();
331  $components[] = $a_component_id;
332  $handler->setComponents($components);
333  }
+ Here is the caller graph for this function:

Field Documentation

◆ $instance

ilBadgeHandler::$instance
staticprotected

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

◆ $settings

ilBadgeHandler::$settings
protected

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


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