CourseBadges
in package
Badge definitions stored on a course manifest, with pictures in Files Public.
The badge code is the PNG file name without .png. It must match the pattern baked into an assertion id: letters, numbers, and underscores.
Table of Contents
Properties
- $courseItemsCache : array<string, array<int, array{id: string, title: string, anchor: ?string, graded: bool, published: bool}>>
Methods
- apply() : array<int, array<string, mixed>>
- Apply an authoring post to the manifest badges array.
- assignmentChoices() : array<string, string>
- Published graded items a badge can count.
- bytes() : string|null
- PNG bytes for a Public file in this course.
- canonicalPublicPath() : string|null
- Public/hello.png with a canonical Public folder name, or null.
- codeFromImage() : string
- File name without .png. Empty when the name is not a lowercase .png.
- displayUrl() : string
- Absolute URL for a Public file, or the site badge folder for a file name.
- imageMatchesCode() : bool
- isPublicImage() : bool
- isSafeCode() : bool
- listFromDocument() : array<int, array<string, mixed>>
- placement() : array{title: string, anchor: ?string, graded: bool, known: bool}
- Title, module anchor, and whether this id counts toward a badge.
- publicPngs() : array<int, array{path: string, code: string, safe: bool}>
- PNG files already in this course's Public folder.
- storedLink() : array{image_id: ?int, sha256: string}|null
- Copy a Public PNG into badge_images.
- courseItems() : array<int, array{id: string, title: string, anchor: ?string, graded: bool, published: bool}>
- Every gradable lesson item, published or not.
-
fromEditor()
: array{title: string, image: string, threshold: float, assignments: list
, completion?: bool} - itemTitle() : string
- postIndex() : int|null
Properties
$courseItemsCache
private
static array<string, array<int, array{id: string, title: string, anchor: ?string, graded: bool, published: bool}>>
$courseItemsCache
= array()
Methods
apply()
Apply an authoring post to the manifest badges array.
public
static apply(mixed $badges, array<string, mixed> $post, LessonsService $lessons, int $contextId) : array<int, array<string, mixed>>
Parameters
- $badges : mixed
- $post : array<string, mixed>
- $lessons : LessonsService
- $contextId : int
Return values
array<int, array<string, mixed>>assignmentChoices()
Published graded items a badge can count.
public
static assignmentChoices(LessonsService $lessons) : array<string, string>
A native quiz is included once it is published. Its grade is stored under the quiz link key. A content launch is included when students can see it and it records a grade.
Parameters
- $lessons : LessonsService
Return values
array<string, string> —resource_link_id => title
bytes()
PNG bytes for a Public file in this course.
public
static bytes(string $image[, int $contextId = 0 ]) : string|null
A zero context id looks up the public path in any course.
Parameters
- $image : string
- $contextId : int = 0
Return values
string|nullcanonicalPublicPath()
Public/hello.png with a canonical Public folder name, or null.
public
static canonicalPublicPath(mixed $image) : string|null
Parameters
- $image : mixed
Return values
string|nullcodeFromImage()
File name without .png. Empty when the name is not a lowercase .png.
public
static codeFromImage(mixed $image) : string
Parameters
- $image : mixed
Return values
stringdisplayUrl()
Absolute URL for a Public file, or the site badge folder for a file name.
public
static displayUrl(object|string $badge[, int $contextId = 0 ]) : string
A Public path is turned into that course's content hash. The same Public/name.png in two courses must not share one URL.
Parameters
- $badge : object|string
-
Badge object or image path
- $contextId : int = 0
Return values
stringimageMatchesCode()
public
static imageMatchesCode(mixed $image, string $code) : bool
Parameters
- $image : mixed
- $code : string
Return values
boolisPublicImage()
public
static isPublicImage(mixed $image) : bool
Parameters
- $image : mixed
Return values
boolisSafeCode()
public
static isSafeCode(string $code) : bool
Parameters
- $code : string
Return values
boollistFromDocument()
public
static listFromDocument(mixed $badges) : array<int, array<string, mixed>>
Parameters
- $badges : mixed
Return values
array<int, array<string, mixed>>placement()
Title, module anchor, and whether this id counts toward a badge.
public
static placement(LessonsService $lessons, string $id[, int $contextId = 0 ]) : array{title: string, anchor: ?string, graded: bool, known: bool}
An id that is not in the course stays graded so an older badge still reads a stored score.
Parameters
- $lessons : LessonsService
- $id : string
- $contextId : int = 0
Return values
array{title: string, anchor: ?string, graded: bool, known: bool}publicPngs()
PNG files already in this course's Public folder.
public
static publicPngs(int $contextId) : array<int, array{path: string, code: string, safe: bool}>
Parameters
- $contextId : int
Return values
array<int, array{path: string, code: string, safe: bool}>storedLink()
Copy a Public PNG into badge_images.
public
static storedLink(string $image, int $contextId) : array{image_id: ?int, sha256: string}|null
Null means the file is missing. image_id is null when the file is over the cap; sha256 is still set so the row is not retried.
Parameters
- $image : string
- $contextId : int
Return values
array{image_id: ?int, sha256: string}|nullcourseItems()
Every gradable lesson item, published or not.
private
static courseItems(LessonsService $lessons[, int $contextId = 0 ]) : array<int, array{id: string, title: string, anchor: ?string, graded: bool, published: bool}>
Parameters
- $lessons : LessonsService
- $contextId : int = 0
Return values
array<int, array{id: string, title: string, anchor: ?string, graded: bool, published: bool}>fromEditor()
private
static fromEditor(array<string, mixed> $post, LessonsService $lessons, int $contextId) : array{title: string, image: string, threshold: float, assignments: list, completion?: bool}
Parameters
- $post : array<string, mixed>
- $lessons : LessonsService
- $contextId : int
Return values
array{title: string, image: string, threshold: float, assignments: listitemTitle()
private
static itemTitle(object $item) : string
Parameters
- $item : object
Return values
stringpostIndex()
private
static postIndex(array<string, mixed> $post) : int|null
Parameters
- $post : array<string, mixed>