Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
core_badges\badge Class Reference

Class that represents badge. More...

Public Member Functions

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

Static Public Member Functions

static get_aggregation_methods ()
 Return array of aggregation methods. More...
 

Public Attributes

int $attachment
 Is this badge image baked.
 
integer $courseid
 The course this badge belongs to.
 
array $criteria = array()
 Badge criteria.
 
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.
 
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.
 
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.
 
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_context()

core_badges\badge::get_context ( )

Use to get context instance of a badge.

Return values
contextinstance.

◆ 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

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