Tsugi

CCIdentifier
in package

Utility class for generating deterministic, hash-based identifiers for IMS Common Cartridge exports.

This ensures idempotency: the same logical content always produces the same identifier, regardless of ordering changes or later additions.

Usage: $idgen = new CCIdentifier(); $identifier = $idgen->makeIdentifier('module', 'Week 1', ''); $identifier = $idgen->makeIdentifier('lti', 'Assignment 1', 'Week 1', ['url' => 'https://...']);

Table of Contents

Properties

$existingIds  : array<string|int, mixed>
Set of identifiers already generated in this export run (for collision detection)
$hashLength  : int
Length of hash to use (truncated from SHA1)
$typePrefixes  : array<string|int, mixed>
Prefix for different types of identifiers

Methods

getCount()  : int
Get the number of identifiers generated so far
makeIdentifier()  : string
Generate a deterministic identifier based on stable properties.
reset()  : mixed
Reset the collision tracking (useful for testing or if starting a new export)
wikiIdentifier()  : string
Stable wiki item identifier from the page logical_key (not title or module).
wikiMigrationId()  : string
Manifest resource identifier / Canvas wiki migration id (identifier + _R).
normalizeString()  : string
Normalize a string for consistent hashing.

Properties

$existingIds

Set of identifiers already generated in this export run (for collision detection)

private array<string|int, mixed> $existingIds = array()

$hashLength

Length of hash to use (truncated from SHA1)

private int $hashLength = 16

$typePrefixes

Prefix for different types of identifiers

private array<string|int, mixed> $typePrefixes = array('module' => 'M', 'submodule' => 'S', 'weblink' => 'WL', 'lti' => 'LT', 'topic' => 'TO', 'header' => 'H', 'qti' => 'Q1', 'file' => 'F', 'wiki' => 'WP')

Methods

getCount()

Get the number of identifiers generated so far

public getCount() : int
Return values
int

makeIdentifier()

Generate a deterministic identifier based on stable properties.

public makeIdentifier(string $type, string $title[, string $parentPath = '' ][, array<string|int, mixed> $additionalProps = array() ]) : string
Parameters
$type : string

The type of item (module, submodule, weblink, lti, topic, header)

$title : string

The title/name of the item

$parentPath : string = ''

The path of parent modules (e.g., "Week 1|Part 1")

$additionalProps : array<string|int, mixed> = array()

Additional stable properties (e.g., ['url' => '...', 'resource_link_id' => '...'])

Return values
string —

A deterministic identifier (e.g., "M_a1b2c3d4e5f6g7h8")

reset()

Reset the collision tracking (useful for testing or if starting a new export)

public reset() : mixed

wikiIdentifier()

Stable wiki item identifier from the page logical_key (not title or module).

public static wikiIdentifier(mixed $logicalKey) : string
Parameters
$logicalKey : mixed
Return values
string

wikiMigrationId()

Manifest resource identifier / Canvas wiki migration id (identifier + _R).

public static wikiMigrationId(mixed $logicalKey) : string
Parameters
$logicalKey : mixed
Return values
string

normalizeString()

Normalize a string for consistent hashing.

private normalizeString(string $str) : string

Removes extra whitespace, converts to lowercase, and trims.

Parameters
$str : string

The string to normalize

Return values
string —

Normalized string


        
On this page

Search results