39 $this->db = $DIC->database();
40 if (isset($DIC[
"tree"])) {
41 $this->tree = $DIC->repositoryTree();
53 if (!self::$instance) {
54 self::$instance =
new self();
56 return self::$instance;
66 return $this->
settings->get(
"active",
false);
71 $this->
settings->set(
"active", (
bool) $a_value);
79 return $this->
settings->get(
"obi_active",
false);
84 $this->
settings->set(
"obi_active", (
bool) $a_value);
89 return $this->
settings->get(
"obi_organisation", null);
94 $this->
settings->set(
"obi_organisation", trim($a_value));
99 return $this->
settings->get(
"obi_contact", null);
104 $this->
settings->set(
"obi_contact", trim($a_value));
109 return $this->
settings->get(
"obi_salt", null);
114 $this->
settings->set(
"obi_salt", trim($a_value));
119 $components = $this->
settings->get(
"components", null);
121 return unserialize($components);
128 if (is_array($a_components) &&
129 !
sizeof($a_components)) {
130 $a_components = null;
132 $this->
settings->set(
"components", $a_components !== null
133 ? serialize(array_unique($a_components))
147 $set =
$ilDB->query(
"SELECT * FROM il_component" .
148 " WHERE id = " .
$ilDB->quote($a_id,
"text"));
149 $rec =
$ilDB->fetchAssoc($set);
165 $class =
"il" . $comp[
"name"] .
"BadgeProvider";
166 $file = $comp[
"type"] .
"/" . $comp[
"name"] .
"/classes/class." . $class .
".php";
167 if (file_exists($file)) {
180 return $comp[
"type"] .
"/" . $comp[
"name"];
190 return $a_component_id .
"/" . $a_badge->
getId();
200 $parts = explode(
"/", $a_id);
201 $comp_id = $parts[0];
202 $type_id = $parts[1];
205 foreach ($provider->getBadgeTypes() as
$type) {
206 if (
$type->getId() == $type_id) {
215 $types = $this->
settings->get(
"inactive_types", null);
217 return unserialize($types);
224 if (is_array($a_types) &&
228 $this->
settings->set(
"inactive_types", $a_types !== null
229 ? serialize(array_unique($a_types))
246 foreach ($provider->getBadgeTypes() as
$type) {
248 if (!in_array($id, $inactive)) {
269 if (in_array($a_object_type,
$type->getValidObjectTypes())) {
288 if (!$a_parent_obj_type) {
295 foreach ($badges as $badge) {
296 if ($badge->getTypeId() == $type_id &&
297 $badge->isActive()) {
298 $res[$badge->getId()] = $badge->getTitle();
321 $handler = self::getInstance();
322 $components = $handler->getComponents();
323 $components[] = $a_component_id;
324 $handler->setComponents($components);
334 $handler = self::getInstance();
335 $components = $handler->getComponents();
336 foreach ($components as $idx => $component) {
337 if ($component == $a_component_id) {
338 unset($components[$idx]);
341 $handler->setComponents($components);
359 if ($a_obj_type !=
"bdga") {
385 $new_badges = array();
387 if ($badge->isActive()) {
390 if ((
bool)
$type->evaluate($a_user_id, (array) $a_params, (array) $badge->getConfiguration())) {
394 $new_badges[$a_user_id][] = $badge->getId();
403 public function getUserIds($a_parent_ref_id, $a_parent_obj_id = null, $a_parent_type = null)
407 if (!$a_parent_obj_id) {
410 if (!$a_parent_type) {
415 switch ($a_parent_type) {
418 return $member_obj->getMembers();
422 return $member_obj->getMembers();
426 $path =
$tree->getPathId($a_parent_ref_id);
428 foreach (array_reverse($path) as $path_ref_id) {
431 return $this->getParticipantsForObject($path_ref_id, null,
$type);
458 $path .= $hash .
".json";
475 foreach (glob($a_path .
"/*") as $item) {
478 } elseif (substr($item, -5) ==
".json") {
486 $hash = md5($a_badge->
getId());
489 floor($a_badge->
getId() / 100) .
"/" .
500 $json->{
"@context"} =
"https://w3id.org/openbadges/v1";
501 $json->type =
"Issuer";
504 $json->url = ILIAS_HTTP_PATH .
"/";
514 $path .=
"issuer.json";
516 $url = ILIAS_HTTP_PATH . substr($path, 1);
518 if (!file_exists($path)) {
520 file_put_contents($path, $json);
528 $path = $this->
getBasePath() .
"issuer/issuer.json";
529 if (file_exists($path)) {
544 foreach ($a_user_map as $user_id => $badge_ids) {
545 $user_badges = array();
547 foreach ($badge_ids as $badge_id) {
553 if (!array_key_exists($badge_id, $badges)) {
554 $badges[$badge_id] =
new ilBadge($badge_id);
557 $badge = $badges[$badge_id];
559 $user_badges[] = $badge->getTitle();
562 if (
sizeof($user_badges)) {
566 $ntf->setLangModules(array(
"badge"));
568 $ntf->setRefId($a_parent_ref_id);
569 $ntf->setGotoLangId(
"badge_notification_parent_goto");
572 $lng = $ntf->getUserLanguage($user_id);
574 $ntf->setIntroductionLangId(
"badge_notification_body");
576 $ntf->addAdditionalInfo(
"badge_notification_badges", implode(
"\n", $user_badges),
true);
579 $ntf->addAdditionalInfo(
"badge_notification_badges_goto",
$url);
581 $ntf->setReasonLangId(
"badge_notification_reason");
589 $lng->txt(
"badge_notification_subject"),
590 $ntf->composeAndGetMessage($user_id, null,
"read",
true),
598 $osd_params = array(
"badge_list" =>
"<br />" . implode(
"<br />", $user_badges));
600 require_once
"Services/Notifications/classes/class.ilNotificationConfig.php";
602 $notification->setTitleVar(
"badge_notification_subject", array(),
"badge");
603 $notification->setShortDescriptionVar(
"badge_notification_osd", $osd_params,
"badge");
604 $notification->setLongDescriptionVar(
"", $osd_params,
"");
605 $notification->setAutoDisable(
false);
606 $notification->setLink(
$url);
610 $notification->notifyByUsers(array($user_id));
Badge Provider interface.
static makeDirParents($a_dir)
Create a new directory and all parent directories.
prepareIssuerJson($a_url)
getAvailableTypesForObjType($a_object_type)
Get valid badges types for object type.
isObjectActive($a_obj_id, $a_obj_type=null)
static exists($a_badge_id, $a_user_id)
getAvailableTypes()
Get badges types.
getTypeInstanceByUniqueId($a_id)
Get type instance by unique id (component, type)
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static updateFromXML($a_component_id)
Import component definition.
getProviderInstance($a_component_id)
Get provider instance.
sendNotification(array $a_user_map, $a_parent_ref_id=null)
getInstancePath(ilBadgeAssignment $a_ass)
static _lookupObjectId($a_ref_id)
lookup object id
Describes a notification and provides methods for publishing this notification.
static clearFromXML($a_component_id)
Remove component definition.
static getInstancesByParentId($a_parent_id, array $a_filter=null)
foreach($_POST as $key=> $value) $res
triggerEvaluation($a_type_id, $a_user_id, array $a_params=null)
getId()
Get typ id (unique for component)
setComponents(array $a_components=null)
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static hasHTML()
Has HTML output.
__construct()
Constructor.
setInactiveTypes(array $a_types=null)
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static _lookupType($a_id, $a_reference=false)
lookup object type
getUniqueTypeId($a_component_id, ilBadgeType $a_badge)
getComponentCaption($a_component_id)
static _lookupEmail($a_user_id)
Lookup email.
getBadgePath(ilBadge $a_badge)
getAvailableManualBadges($a_parent_obj_id, $a_parent_obj_type=null)
Get available manual badges for object id.
countStaticBadgeInstancesHelper(&$a_cnt, $a_path)
setObiOrganisation($a_value)
countStaticBadgeInstances(ilBadge $a_badge)
getUserIds($a_parent_ref_id, $a_parent_obj_id=null, $a_parent_type=null)
static getWebspaceDir($mode="filesystem")
get webspace directory
Wrapper classes for system notifications.
static getInstancesByType($a_type_id)
static _getLink($a_ref_id, $a_type='', $a_params=array(), $append="")
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=null)
Lookup a container setting.
static getInstance()
Constructor.