StudentView
in package
Instructor "view as student" for one manifest course.
Four named learners live on this course's tenant key. The user_key includes the course id, so Nancy Drew in another course is a different account. Entering creates the user, enrolls them as a learner, and swaps the session onto that account. The instructor identity stays in the session so Leave Student View can put it back.
Reset deletes that lti_user row. Foreign keys cascade the membership, results, discussion posts, and the other linked rows. Badges have no foreign key, so those rows are deleted first. A test student is never the course owner: lti_context.user_id cascades the whole course.
Table of Contents
Constants
- ROUTE : mixed = '/student'
- SESSION_KEY : mixed = 'tsugi_student_view'
Methods
- activeContextId() : int
- activeName() : string
- avatarDataUri() : string
- Circle with the student's initials on the same art as an empty course hero.
- barHtml() : string
- Bottom bar for the swapped-in student. Empty when student view is off.
- bodyAttribute() : string
- css() : string
- enter() : array{ok: bool, error?: string, name?: string}
- Create the learner if needed, enroll them, and swap the session.
- initials() : string
- Two-letter mark for a display name: Nancy Drew is ND.
- isActive() : bool
- nameFor() : string
- reset() : array{ok: bool, error?: string, name?: string}
- Delete the test student. Linked rows cascade with the user.
- restoreInstructor() : bool
- Put the instructor session back. False when student view is not on.
- roster() : array<string, string>
- rows() : array<int, array{slug: string, name: string, user_id: int}>
- One row per test student for the instructor page.
- switchTo() : bool
- userKey() : string
- applyKeys() : mixed
- avatarSeed() : int
- Seeds chosen so the four students get different hero palettes and patterns.
- captureKeys() : array<string, array{set: bool, value?: mixed}>
- courseRow() : array{key_id: int, manifest_id: int}|null
- current() : array<string, mixed>|null
- enrollLearner() : int
- Learner membership. A roster soft-delete is cleared so Enter puts them back.
- ensureLearner() : array{ok: bool, error?: string, user_id?: int, user_key?: string, email?: string, name?: string, membership_id?: int, context_id?: int, slug?: string}
- findUser() : array{user_id: int, key_id: int, user_sha256: string, user_key: string}|null
- firstLetter() : string
- insertUser() : array{user_id: int, key_id: int, user_sha256: string, user_key: string}|null
- ltiIdentityKeys() : array<int, string>
- ltiKey() : string
- ownsCourseOrKey() : bool
- True when deleting this user would take a course or tenant key with it.
- refreshUser() : mixed
- sessionIdentityKeys() : array<int, string>
Constants
ROUTE
public
mixed
ROUTE
= '/student'
SESSION_KEY
public
mixed
SESSION_KEY
= 'tsugi_student_view'
Methods
activeContextId()
public
static activeContextId() : int
Return values
intactiveName()
public
static activeName() : string
Return values
stringavatarDataUri()
Circle with the student's initials on the same art as an empty course hero.
public
static avatarDataUri(mixed $name[, mixed $slug = '' ]) : string
A data URI stays inside the session, so the menu does not need another request.
Parameters
- $name : mixed
- $slug : mixed = ''
Return values
stringbarHtml()
Bottom bar for the swapped-in student. Empty when student view is off.
public
static barHtml() : string
Return values
stringbodyAttribute()
public
static bodyAttribute() : string
Return values
string — class="tsugi-student-view" or empty
css()
public
static css() : string
Return values
stringenter()
Create the learner if needed, enroll them, and swap the session.
public
static enter(int $contextId, string $slug) : array{ok: bool, error?: string, name?: string}
A nested swap is refused by restoring the instructor first, so the saved identity is always the real login.
Parameters
- $contextId : int
- $slug : string
Return values
array{ok: bool, error?: string, name?: string}initials()
Two-letter mark for a display name: Nancy Drew is ND.
public
static initials(mixed $name) : string
Parameters
- $name : mixed
Return values
stringisActive()
public
static isActive() : bool
Return values
boolnameFor()
public
static nameFor(mixed $slug) : string
Parameters
- $slug : mixed
Return values
stringreset()
Delete the test student. Linked rows cascade with the user.
public
static reset(int $contextId, string $slug) : array{ok: bool, error?: string, name?: string}
Parameters
- $contextId : int
- $slug : string
Return values
array{ok: bool, error?: string, name?: string}restoreInstructor()
Put the instructor session back. False when student view is not on.
public
static restoreInstructor() : bool
Return values
boolroster()
public
static roster() : array<string, string>
Return values
array<string, string> —slug => display name
rows()
One row per test student for the instructor page.
public
static rows(int $contextId) : array<int, array{slug: string, name: string, user_id: int}>
Parameters
- $contextId : int
Return values
array<int, array{slug: string, name: string, user_id: int}>switchTo()
public
static switchTo(array{user_id: int, user_key: string, email: string, name: string, membership_id: int, context_id: int, slug: string} $ready) : bool
Parameters
- $ready : array{user_id: int, user_key: string, email: string, name: string, membership_id: int, context_id: int, slug: string}
Return values
booluserKey()
public
static userKey(int $contextId, string $slug) : string
Parameters
- $contextId : int
- $slug : string
Return values
stringapplyKeys()
private
static applyKeys(array<string, mixed> &$target, array<string, array{set: bool, value?: mixed}> $captured) : mixed
Parameters
- $target : array<string, mixed>
- $captured : array<string, array{set: bool, value?: mixed}>
avatarSeed()
Seeds chosen so the four students get different hero palettes and patterns.
private
static avatarSeed(string $slug) : int
Parameters
- $slug : string
Return values
intcaptureKeys()
private
static captureKeys(array<string, mixed> $source, array<int, string> $keys) : array<string, array{set: bool, value?: mixed}>
Parameters
- $source : array<string, mixed>
- $keys : array<int, string>
Return values
array<string, array{set: bool, value?: mixed}>courseRow()
private
static courseRow(int $contextId) : array{key_id: int, manifest_id: int}|null
Parameters
- $contextId : int
Return values
array{key_id: int, manifest_id: int}|nullcurrent()
private
static current() : array<string, mixed>|null
Return values
array<string, mixed>|nullenrollLearner()
Learner membership. A roster soft-delete is cleared so Enter puts them back.
private
static enrollLearner(int $contextId, int $userId) : int
Parameters
- $contextId : int
- $userId : int
Return values
int —membership_id, or 0
ensureLearner()
private
static ensureLearner(int $contextId, string $slug) : array{ok: bool, error?: string, user_id?: int, user_key?: string, email?: string, name?: string, membership_id?: int, context_id?: int, slug?: string}
Parameters
- $contextId : int
- $slug : string
Return values
array{ok: bool, error?: string, user_id?: int, user_key?: string, email?: string, name?: string, membership_id?: int, context_id?: int, slug?: string}findUser()
private
static findUser(int $contextId, string $slug) : array{user_id: int, key_id: int, user_sha256: string, user_key: string}|null
Parameters
- $contextId : int
- $slug : string
Return values
array{user_id: int, key_id: int, user_sha256: string, user_key: string}|nullfirstLetter()
private
static firstLetter(string $word) : string
Parameters
- $word : string
Return values
stringinsertUser()
private
static insertUser(int $keyId, string $userKey, string $name, string $email) : array{user_id: int, key_id: int, user_sha256: string, user_key: string}|null
Parameters
- $keyId : int
- $userKey : string
- $name : string
- $email : string
Return values
array{user_id: int, key_id: int, user_sha256: string, user_key: string}|nullltiIdentityKeys()
private
static ltiIdentityKeys() : array<int, string>
Return values
array<int, string>ltiKey()
private
static ltiKey() : string
Return values
stringownsCourseOrKey()
True when deleting this user would take a course or tenant key with it.
private
static ownsCourseOrKey(int $userId) : bool
Parameters
- $userId : int
Return values
boolrefreshUser()
private
static refreshUser(int $userId, string $name, string $email) : mixed
Parameters
- $userId : int
- $name : string
- $email : string
sessionIdentityKeys()
private
static sessionIdentityKeys() : array<int, string>