Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
core_badges\badge Class Reference

Class that represents badge. More...

Public Member Functions

 __construct ($badgeid)
 Constructs with badge details.
 
 add_related_badges ($relatedids)
 Add multiple related badges.
 
 calculate_expiry ($timestamp)
 Calculates badge expiry date based on either expirydate or expiryperiod.
 
 can_expire ()
 Checks if badge has expiry period or date set up.
 
 delete ($archive=true)
 Fully deletes the badge or marks it as archived.
 
 delete_alignment ($alignmentid)
 Delete a alignment of badge.
 
 delete_related_badge ($relatedid)
 Delete an related badge.
 
 get_accepted_criteria ()
 Return array of accepted criteria types for this badge.
 
 get_aggregation_method ($criteriatype=0)
 Get aggregation method for badge criteria.
 
 get_alignments ()
 Get alignments of badge.
 
 get_awards ()
 Gets list of users who have earned an instance of this badge.
 
 get_badge_issuer (?int $obversion=null)
 Define issuer information by format Open Badges specification version 2.
 
 get_badge_tags ()
 Get tags of badge.
 
 get_context ()
 Use to get context instance of a badge.
 
 get_criteria ()
 Returns badge award criteria.
 
 get_criteria_completions ($userid)
 Gets an array of completed criteria from 'badge_criteria_met' table.
 
 get_endorsement ()
 Get endorsement of badge.
 
 get_related_badges ($activeonly=false)
 Get related badges of badge.
 
 get_status_name ()
 Use to get the name of badge status.
 
 has_awards ()
 Checks if badge has been awarded to users.
 
 has_criteria ()
 Checks if badges has award criteria set up.
 
 has_manual_award_criteria ()
 Checks if badge has manual award criteria set.
 
 has_related ()
 Checks if badge has related badges.
 
 is_active ()
 Checks if badges is active.
 
 is_issued ($userid)
 Indicates whether badge has already been issued to a user.
 
 is_locked ()
 Checks if badges is locked.
 
 issue ($userid, $nobake=false)
 Issue a badge to user.
 
 make_clone ()
 Creates and saves a clone of badge with all its properties.
 
 markdown_badge_criteria ()
 Markdown language support for criteria.
 
 review_all_criteria ()
 Reviews all badge criteria and checks if badge can be instantly awarded.
 
 save ()
 Save/update badge information in 'badge' table only.
 
 save_alignment ($alignment, $alignmentid=0)
 Insert/update alignment information of badge.
 
 save_endorsement ($endorsement)
 Insert/update Endorsement information of badge.
 
 set_status ($status=0)
 Use to set badge status.
 

Static Public Member Functions

static get_aggregation_methods ()
 Return array of aggregation methods.
 

Public Attributes

int $attachment
 Is this badge image baked.
 
int null $awards
 Total users which have the award.
 
integer $courseid
 The course this badge belongs to.
 
array $criteria = array()
 Badge criteria.
 
int null $dateissued
 The date the badges were issued.
 
string $description
 Badge description.
 
integer $expiredate
 Timestamp this badge will expire.
 
integer $expireperiod
 Duration this badge is valid for.
 
int $id
 Badge id.
 
string $imageauthoremail
 The email of the author of the image for this badge.
 
string $imageauthorname
 The author of the image for this badge.
 
string $imageauthorurl
 The url of the author of the image for this badge.
 
string $imagecaption
 The caption of the image for this badge.
 
string $issuercontact
 The email of the issuer of this badge.
 
string $issuername
 The name of the issuer of this badge.
 
string $issuerurl
 The url of the issuer of this badge.
 
string $language
 What language is this badge written in.
 
string $message
 The message this badge includes.
 
array $message_editor = []
 Message editor.
 
string null $messageformat
 Message format.
 
string $messagesubject
 The subject of the message for this badge.
 
string $name
 Badge name.
 
int $nextcron
 Timestamp to next run cron for this badge.
 
int $notification
 Send a message when this badge is awarded.
 
string null $statstring
 The name of badge status.
 
int $status = 0
 Lifecycle status for this badge.
 
integer $timecreated
 Timestamp this badge was created.
 
integer $timemodified
 Timestamp this badge was modified.
 
integer $type
 Site or course badge.
 
string null $uniquehash
 Unique hash.
 
int $usercreated
 The user who created this badge.
 
int $usermodified
 The user who modified this badge.
 
int $version
 What backpack api version to use for this badge.
 

Detailed Description

Class that represents badge.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

core_badges\badge::__construct ( $badgeid)

Constructs with badge details.

Parameters
int$badgeidbadge ID.

Member Function Documentation

◆ add_related_badges()

core_badges\badge::add_related_badges ( $relatedids)

Add multiple related badges.

Parameters
array$relatedidsId of badges.

◆ calculate_expiry()

core_badges\badge::calculate_expiry ( $timestamp)

Calculates badge expiry date based on either expirydate or expiryperiod.

Parameters
int$timestampTime of badge issue
Return values
intA timestamp

◆ can_expire()

core_badges\badge::can_expire ( )

Checks if badge has expiry period or date set up.

Return values
booleanA status indicating badge can expire

◆ delete()

core_badges\badge::delete ( $archive = true)

Fully deletes the badge or marks it as archived.

Parameters
boolean$archiveAchive a badge without actual deleting of any data.

◆ delete_alignment()

core_badges\badge::delete_alignment ( $alignmentid)

Delete a alignment of badge.

Parameters
int$alignmentidID alignment.
Return values
booleanA status for delete a alignment.

◆ delete_related_badge()

core_badges\badge::delete_related_badge ( $relatedid)

Delete an related badge.

Parameters
int$relatedidId related badge.
Return values
booleanA status for delete an related badge.

◆ get_accepted_criteria()

core_badges\badge::get_accepted_criteria ( )

Return array of accepted criteria types for this badge.

Return values
array

◆ get_aggregation_method()

core_badges\badge::get_aggregation_method ( $criteriatype = 0)

Get aggregation method for badge criteria.

Parameters
int$criteriatypeIf none supplied, get overall aggregation method (optional)
Return values
intOne of BADGE_CRITERIA_AGGREGATION_ALL or BADGE_CRITERIA_AGGREGATION_ANY

◆ get_aggregation_methods()

static core_badges\badge::get_aggregation_methods ( )
static

Return array of aggregation methods.

Return values
array

◆ get_alignments()

core_badges\badge::get_alignments ( )

Get alignments of badge.

Return values
arrayList content alignments.

◆ get_awards()

core_badges\badge::get_awards ( )

Gets list of users who have earned an instance of this badge.

Return values
arrayAn array of objects with information about badge awards.

◆ get_badge_issuer()

core_badges\badge::get_badge_issuer ( ?int $obversion = null)

Define issuer information by format Open Badges specification version 2.

Parameters
int$obversionOB version to use.
Return values
arrayIssuer informations of the badge.

◆ get_badge_tags()

core_badges\badge::get_badge_tags ( )

Get tags of badge.

Return values
arrayBadge tags.

◆ get_context()

core_badges\badge::get_context ( )

Use to get context instance of a badge.

Return values
context|voidinstance.

◆ get_criteria()

core_badges\badge::get_criteria ( )

Returns badge award criteria.

Return values
arrayAn array of badge criteria

◆ get_criteria_completions()

core_badges\badge::get_criteria_completions ( $userid)

Gets an array of completed criteria from 'badge_criteria_met' table.

Parameters
int$useridCompletions for a user
Return values
arrayRecords of criteria completions

◆ get_endorsement()

core_badges\badge::get_endorsement ( )

Get endorsement of badge.

Return values
array|stdClassEndorsement information.

◆ get_related_badges()

core_badges\badge::get_related_badges ( $activeonly = false)

Get related badges of badge.

Parameters
boolean$activeonlyDo not get the inactive badges when is true.
Return values
arrayRelated badges information.

◆ get_status_name()

core_badges\badge::get_status_name ( )

Use to get the name of badge status.

Return values
string

◆ has_awards()

core_badges\badge::has_awards ( )

Checks if badge has been awarded to users.

Used in badge editing.

Return values
booleanA status indicating badge has been awarded at least once

◆ has_criteria()

core_badges\badge::has_criteria ( )

Checks if badges has award criteria set up.

Return values
booleanA status indicating badge has at least one criterion

◆ has_manual_award_criteria()

core_badges\badge::has_manual_award_criteria ( )

Checks if badge has manual award criteria set.

Return values
booleanA status indicating badge can be awarded manually

◆ has_related()

core_badges\badge::has_related ( )

Checks if badge has related badges.

Return values
booleanA status related badge.

◆ is_active()

core_badges\badge::is_active ( )

Checks if badges is active.

Used in badge award.

Return values
booleanA status indicating badge is active

◆ is_issued()

core_badges\badge::is_issued ( $userid)

Indicates whether badge has already been issued to a user.

Parameters
int$useridUser to check
Return values
boolean

◆ is_locked()

core_badges\badge::is_locked ( )

Checks if badges is locked.

Used in badge award and editing.

Return values
booleanA status indicating badge is locked

◆ issue()

core_badges\badge::issue ( $userid,
$nobake = false )

Issue a badge to user.

Parameters
int$useridUser who earned the badge
boolean$nobakeNot baking actual badges (for testing purposes)

◆ make_clone()

core_badges\badge::make_clone ( )

Creates and saves a clone of badge with all its properties.

Clone is not active by default and has 'Copy of' attached to its name.

Return values
intID of new badge.

◆ markdown_badge_criteria()

core_badges\badge::markdown_badge_criteria ( )

Markdown language support for criteria.

Return values
string\$outputMarkdown content to output.

◆ review_all_criteria()

core_badges\badge::review_all_criteria ( )

Reviews all badge criteria and checks if badge can be instantly awarded.

Return values
intNumber of awards

◆ save()

core_badges\badge::save ( )

Save/update badge information in 'badge' table only.

Cannot be used for updating awards and criteria settings.

Return values
booleanReturns true on success.

◆ save_alignment()

core_badges\badge::save_alignment ( $alignment,
$alignmentid = 0 )

Insert/update alignment information of badge.

Parameters
stdClass$alignmentData of a alignment.
int$alignmentidID alignment.
Return values
bool|intA status/ID when insert or update data.

◆ save_endorsement()

core_badges\badge::save_endorsement ( $endorsement)

Insert/update Endorsement information of badge.

Parameters
stdClass$endorsementData of an endorsement.
Return values
bool|intA status/ID when insert or update data.

◆ set_status()

core_badges\badge::set_status ( $status = 0)

Use to set badge status.

Only active badges can be earned/awarded/issued.

Parameters
int$statusStatus from BADGE_STATUS constants

Member Data Documentation

◆ $awards

int null core_badges\badge::$awards

Total users which have the award.

Called from badges_get_badges()

◆ $dateissued

int null core_badges\badge::$dateissued

The date the badges were issued.

Called from badges_get_badges()

◆ $message_editor

array core_badges\badge::$message_editor = []

Message editor.

Called from file_prepare_standard_editor()

◆ $messageformat

string null core_badges\badge::$messageformat

Message format.

Called from file_prepare_standard_editor()

◆ $statstring

string null core_badges\badge::$statstring

The name of badge status.

Called from badges_get_badges()

◆ $uniquehash

string null core_badges\badge::$uniquehash

Unique hash.

Called from badges_get_badges()


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