Tsugi

GoogleClassroom extends Tool
in package

Google Classroom pages. Public URLs stay /gclass/login, /gclass/assign, /gclass/launch, and /gclass/share.

Table of Contents

Constants

ROUTE  : mixed = '/gclass'
SESSION_LESSONS_GRADE_REFRESH_AFTER_LAUNCH  : mixed = 'tsugi_lessons_refresh_grades_on_view'
When set after an outbound LTI 1.1 launch, the next {@see \Tsugi\Controllers\Lessons::get()} or {@see \Tsugi\Controllers\LaunchController::returnFromTool()} run clears the grade cache via {@see applyGradeRefreshAfterLaunchReturn()}.

Methods

applyGradeRefreshAfterLaunchReturn()  : mixed
After an outbound LTI launch, if {@see SESSION_LESSONS_GRADE_REFRESH_AFTER_LAUNCH} is set, invalidate the current user's grade cache and clear the flag (next page load / return handler).
assign()  : mixed
Pick a Classroom course and create the coursework link.
checkCsrf()  : bool
True when the CSRF token is valid (fail closed). Flashes on failure.
configuredHomeUrl()  : string
Site home for redirects: {@see ConfigInfo::$apphome} when set and non-empty, else {@see ConfigInfo::$wwwroot}.
course()  : mixed
Queue, reset, send, and the log for one Classroom course.
courseLocalPrefixes()  : array<string|int, string>
First path segments under the course base that are course content.
courses()  : mixed
Classroom courses this teacher installed.
courseSummary()  : mixed
csrfField()  : string
Hidden CSRF_TOKEN input for cookie-session HTML forms that POST to Tsugi.
csrfOk()  : bool
True when POST CSRF_TOKEN (or X-CSRF-TOKEN) matches the session token, or the browser marks this POST as same-origin.
csrfRedirect()  : bool
For classic PHP tools that redirect with header('Location').
determineParentPath()  : string
Static helper to determine the parent path dynamically from the request
determineToolHome()  : string
Static form of {@see toolHome()} for launch methods that have no instance.
exitPlusLeftCourse()  : mixed
Stop a Plus launch that opened a site tool.
googleEmail()  : mixed
isCourseRoute()  : mixed
True when this request is /courses/{id}{route}... (not the unprefixed tool URL).
joinToolHome()  : string
Join a mounted tool home and a suffix without producing `//path`.
launch()  : mixed
Student launch stored on the Classroom assignment.
launchCourse()  : mixed
Open the course from a Classroom material. The student is logged in and joined. No resource link is created.
launchLesson()  : mixed
Open a lesson from a Classroom material. The signature is the course, not a resource link, and no link row is created.
login()  : mixed
OAuth return URL for a Classroom token. Same path Google has registered.
outboundContextTitle()  : mixed
Course title for an outbound LTI launch.
plusLeftCourseApplies()  : mixed
True when this request is a Plus launch on a site URL.
reconnect()  : mixed
rememberCourseCount()  : mixed
After a site login, a stored Classroom token means this person already connected. Count the classes they teach and remember it for this session.
requestPath()  : string
REQUEST_URI path with query stripped and a single leading slash.
requireCsrf()  : RedirectResponse|null
Redirect back to $redirect when the CSRF token is missing or invalid.
requireCsrfJson()  : JsonResponse|null
JSON 403 when the CSRF token is missing or invalid (no flash).
requireOutboundLti11LaunchSession()  : RedirectResponse|null
Require LTI consumer session fields needed to sign an outbound LTI 1.1 launch.
resetQueue()  : mixed
routes()  : mixed
sameOriginPost()  : bool
True when this request is a same-origin navigation (not a cross-site CSRF POST).
sendLti11LaunchFromContent()  : RedirectResponse|string
Sign a lesson launch from an lti_content row.
sendLti11LaunchFromLessonsItem()  : RedirectResponse|string
Build and print the auto-submit HTML for an LTI 1.1 basic-lti-launch-request to a tool URL described by a lessons.json / lessons-items item (same shape as {@see \Tsugi\Services\Lessons\LessonsService::getLtiByRlid()}).
sendQueue()  : mixed
share()  : mixed
teacherCourses()  : array<int, Google_Service_Classroom_Course>
Active classes the connected Google account teaches.
useAccount()  : mixed
Ask Google which account to use, then come back to the install page.
appHomeUrl()  : string
App home (home_path, else apphome, else wwwroot).
assetUrl()  : mixed
Alias for staticUrl() for backward compatibility
controllerUrl()  : string
Generate URL to another controller
courseFileBaseUrl()  : string
Current course base URL for Common Cartridge file-base rewriting.
courseRequiredHtml()  : string
exitCourseRequired()  : mixed
A site tool such as grades was opened with no course.
externalLinkAttrs()  : array<string|int, mixed>
Get link attributes for external vs same-site URLs
isAdmin()  : bool
Check if the current user is a site administrator
isInstructor()  : bool
Check if the current logged-in user is an instructor/admin for the current context
leavePageReturnScript()  : string
Point Continue at this tab's launch return before footer scripts replace TSUGI_SESSION_DATA with the current page.
lmsAnalyticsKey()  : string
Build a stable key for LMS analytics, distinct from LTI resource_link_id values.
lmsAnalyticsPath()  : string
Build a stable path identifier for LMS tools (no query/session params).
lmsEnsureAnalyticsLink()  : int|false
Ensure there is an `lti_link` row for a local LMS page/tool and return link_id.
lmsRecordLaunchAnalytics()  : int|false
Record LMS page/tool "launch" into Tsugi internal analytics, mirroring LTIX behavior.
plusLeftCourseHtml()  : string
renderLeavePage()  : string
Error page with Close Tab and Continue.
requireAuth()  : mixed
Check authentication and context
requireGlobalRoute()  : RedirectResponse|null
Bounce a course-mounted URL to a global (unprefixed) URL.
requireInstructor()  : bool
Check if user is instructor/admin, redirect if not
showAnalytics()  : string
Display analytics for an LMS tool
staticUrl()  : string
Generate URL for a controller-specific static file (JS, CSS, etc.)
toolHome()  : string
Get the base path for this tool (e.g., '/py4e/pages' or '/courses/2/pages')
toolParent()  : string
Get the parent path one level above the tool home
viewDueDates()  : bool
Whether the current user may see due dates in this context (lti_membership.viewDueDates).
absoluteLaunchUrl()  : mixed
A stored link path may be a full URL or a tool-relative path.
acceptClassroomStudent()  : true|string
The signed-in user may open this course from Classroom.
assignCourse()  : Response
Install the whole course as a Classroom material. Opening it joins the course. No resource link is created.
assignLesson()  : Response
Install a lesson page as a Classroom material. No resource link is created.
bindQuizEndpoint()  : string|null
A Quiz1 take URL has to name a link in the course being installed.
clientOrRedirect()  : Google_Client|Response
courseLessonLaunch()  : mixed
courseMaterialSig()  : mixed
Signature for a lesson or course material. The Google class is part of the signature so one class cannot be paired with another course.
coursesUrl()  : mixed
courseUrl()  : mixed
currentRequestPath()  : mixed
Path of this request, without the query string, for the post-login return.
discussionLaunchUrl()  : mixed
Discussion URL inside this course, matching the lessons page.
endpointForResource()  : array{url: string, title: string}|null
Launch URL and title for a lesson resource id.
endpointFromLessonItem()  : array{url: string, title: string}|null
endpointFromStoredPath()  : array{url: string, title: string}|null
existingCourseLinkId()  : mixed
The lesson resource's own link in this course, or 0 when this install still needs a new link. A manifest quiz already has that link.
fileCoursePlacement()  : array{context_id: int, gc_secret: string, sig_user: int}
findResourceNode()  : array<string, mixed>|null
googleCourseId()  : mixed
Google course id stored in gclass:{id}:{sig}.
inheritedGradeLink()  : array{link_id: int, title: string}|null
A Classroom link whose path says inherit= the quiz. The session should be the quiz link. The coursework id stays on the Classroom link.
launchPieces()  : mixed
lessonAnchor()  : mixed
A lesson anchor safe to put in a signed Classroom URL.
loginRedirect()  : RedirectResponse
manifestPlacement()  : array{context_id: int, gc_secret: string, sig_user: int}|string
materialsConsent()  : Response|null
The stored Classroom connection can install assignments. Lesson and course links need a newer permission, so send the teacher through consent once.
openSignedCourse()  : mixed
ownedClassroom()  : array<string, mixed>|null
placementForInstall()  : array{context_id: int, gc_secret: string, sig_user: int}|string
Course that owns the new Classroom link.
postMaterial()  : Response
Class picker and Classroom material. $urlFor builds the signed launch URL.
reenterCourseFromQuery()  : mixed
/gclass/assign is a site URL, so the session is put back on the global course before this runs. The lesson that opened the installer names its course. Come back to that course before resolving the resource.
rememberCourse()  : mixed
Remember which Google course this column grades, so a course-page submit can send the score without the Classroom launch session.
renderCourse()  : mixed
requireLoggedIn()  : RedirectResponse|null
sameSig()  : mixed
Constant-time compare for the 6-character Classroom signatures.
sanityCheck()  : RedirectResponse|null
scopeDenied()  : mixed
takePanelReturn()  : string|null
Post-login return when it points at a Classroom page.
toolLaunchUrl()  : mixed
Hand the quiz a cookieless tool session. The site login is a cookie.

Constants

SESSION_LESSONS_GRADE_REFRESH_AFTER_LAUNCH

When set after an outbound LTI 1.1 launch, the next {@see \Tsugi\Controllers\Lessons::get()} or {@see \Tsugi\Controllers\LaunchController::returnFromTool()} run clears the grade cache via {@see applyGradeRefreshAfterLaunchReturn()}.

public mixed SESSION_LESSONS_GRADE_REFRESH_AFTER_LAUNCH = 'tsugi_lessons_refresh_grades_on_view'

Methods

applyGradeRefreshAfterLaunchReturn()

After an outbound LTI launch, if {@see SESSION_LESSONS_GRADE_REFRESH_AFTER_LAUNCH} is set, invalidate the current user's grade cache and clear the flag (next page load / return handler).

public static applyGradeRefreshAfterLaunchReturn() : mixed

assign()

Pick a Classroom course and create the coursework link.

public assign(Request $request) : mixed
Parameters
$request : Request

checkCsrf()

True when the CSRF token is valid (fail closed). Flashes on failure.

public static checkCsrf() : bool
Return values
bool

configuredHomeUrl()

Site home for redirects: {@see ConfigInfo::$apphome} when set and non-empty, else {@see ConfigInfo::$wwwroot}.

public static configuredHomeUrl() : string
Return values
string —

Non-empty path or URL (defaults to '/')

course()

Queue, reset, send, and the log for one Classroom course.

public course(Request $request[, string|int $context = null ]) : mixed
Parameters
$request : Request
$context : string|int = null

courseLocalPrefixes()

First path segments under the course base that are course content.

public static courseLocalPrefixes() : array<string|int, string>

Passed into CCFileBase so that util does not know about controllers. Login, logout, admin, profile, and similar non-content routes are omitted.

Return values
array<string|int, string>

courses()

Classroom courses this teacher installed.

public courses(Request $request) : mixed
Parameters
$request : Request

courseSummary()

public static courseSummary(string $email, array<int, Google_Service_Classroom_Course> $courses) : mixed
Parameters
$email : string
$courses : array<int, Google_Service_Classroom_Course>

csrfField()

Hidden CSRF_TOKEN input for cookie-session HTML forms that POST to Tsugi.

public static csrfField() : string

Mints a session token if the current session does not have one yet (Google site login historically did not set CSRF_TOKEN; LTI launch does). Do not use this on LTI launches or signed webhooks.

Return values
string

csrfOk()

True when POST CSRF_TOKEN (or X-CSRF-TOKEN) matches the session token, or the browser marks this POST as same-origin.

public static csrfOk() : bool

Cookie-session pages (admin unlock) can lose the GET session cookie on the following POST; Chrome still sends Sec-Fetch-Site/Origin, which is enough to reject cross-site CSRF. LTI launches must not use this helper.

Return values
bool

csrfRedirect()

For classic PHP tools that redirect with header('Location').

public static csrfRedirect(string $url) : bool
Parameters
$url : string

Already session-bearing Location target.

Return values
bool —

True when the caller should return (token was bad).

determineParentPath()

Static helper to determine the parent path dynamically from the request

public static determineParentPath([string|null $route = null ]) : string

This is useful for static methods that need to determine the base path without having a Tool instance. It uses the same logic as toolParent() but works as a static method.

Parameters
$route : string|null = null

Optional route to look for (if null, tries to detect from request)

Return values
string —

The parent path (e.g., '/py4e' or '/ca4e/tsugi')

determineToolHome()

Static form of {@see toolHome()} for launch methods that have no instance.

public static determineToolHome(string $route) : string

On a course-mounted page, a sibling tool keeps /courses/{id} even when $route is not in this REQUEST_URI (Lessons → Quiz1).

Parameters
$route : string

The route constant (e.g., '/discussions')

Return values
string —

The mounted tool path (e.g., '/courses/2/discussions')

exitPlusLeftCourse()

Stop a Plus launch that opened a site tool.

public static exitPlusLeftCourse() : mixed

The Tsugi router calls this before every Tool action. A route that is a closure has to call it itself. The page offers the launch course, Log out, and Close Tab. Close Tab is disabled while the browser tries to close the window. If the tab is still open after three seconds, that button is removed and the page says it could not close.

googleEmail()

public static googleEmail(Google_Service_Classroom $service) : mixed
Parameters
$service : Google_Service_Classroom

isCourseRoute()

True when this request is /courses/{id}{route}... (not the unprefixed tool URL).

public static isCourseRoute([string|null $route = null ]) : mixed

Nested course dispatch rewrites pathInfo to $route but leaves REQUEST_URI unchanged, so this is the reliable split between a global tool URL and a course-mounted one. Do not use ReqScope::currentContextId() here — a global visit can still have a course in session.

Uses static::ROUTE unless $route is passed. Controllers without ROUTE return false unless $route is given.

Parameters
$route : string|null = null

Tool path including leading slash (e.g. '/settings')

joinToolHome()

Join a mounted tool home and a suffix without producing `//path`.

public static joinToolHome(string $home, string $suffix) : string
Parameters
$home : string

toolHome() result

$suffix : string

id or extra path (leading slash optional)

Return values
string

launch()

Student launch stored on the Classroom assignment.

public launch(Request $request[, string|null $resource = null ]) : mixed
Parameters
$request : Request
$resource : string|null = null

course:sig:link:sig

launchCourse()

Open the course from a Classroom material. The student is logged in and joined. No resource link is created.

public launchCourse(Request $request[, string|null $sig = null ]) : mixed
Parameters
$request : Request
$sig : string|null = null

launchLesson()

Open a lesson from a Classroom material. The signature is the course, not a resource link, and no link row is created.

public launchLesson(Request $request[, string|null $sig = null ][, string|null $anchor = null ]) : mixed
Parameters
$request : Request
$sig : string|null = null
$anchor : string|null = null

login()

OAuth return URL for a Classroom token. Same path Google has registered.

public login(Request $request) : mixed
Parameters
$request : Request

outboundContextTitle()

Course title for an outbound LTI launch.

public static outboundContextTitle() : mixed

Precedence: $_SESSION['context_title'], then the LTI session context_title, then $CFG->context_title.

Sending the site default here used to overwrite lti_context.title via adjustData.

plusLeftCourseApplies()

True when this request is a Plus launch on a site URL.

public static plusLeftCourseApplies() : mixed

/courses/{id}/… still belongs to the launch. The course id stays in the session. A site tool that needs a course does not use it.

reconnect()

public reconnect(Request $request[, string|int $context = null ]) : mixed
Parameters
$request : Request
$context : string|int = null

rememberCourseCount()

After a site login, a stored Classroom token means this person already connected. Count the classes they teach and remember it for this session.

public static rememberCourseCount(int $userId) : mixed
Parameters
$userId : int

requestPath()

REQUEST_URI path with query stripped and a single leading slash.

public static requestPath() : string

//courses is a protocol-relative URL (host "courses"). Apache/proxies sometimes leave a doubled slash in REQUEST_URI; collapse it so tool links stay /courses/123 instead of //courses/123.

Return values
string

requireCsrf()

Redirect back to $redirect when the CSRF token is missing or invalid.

public static requireCsrf(string $redirect) : RedirectResponse|null
Parameters
$redirect : string
Return values
RedirectResponse|null —

Null when the token is valid.

requireCsrfJson()

JSON 403 when the CSRF token is missing or invalid (no flash).

public static requireCsrfJson([array<string|int, mixed>|null $payload = null ]) : JsonResponse|null
Parameters
$payload : array<string|int, mixed>|null = null
Return values
JsonResponse|null —

Null when the token is valid.

requireOutboundLti11LaunchSession()

Require LTI consumer session fields needed to sign an outbound LTI 1.1 launch.

public static requireOutboundLti11LaunchSession(Application $app, mixed $redirect_path) : RedirectResponse|null
Parameters
$app : Application
$redirect_path : mixed
Return values
RedirectResponse|null —

Null if session is sufficient; redirect with flash otherwise.

resetQueue()

public resetQueue(Request $request[, string|int $context = null ]) : mixed
Parameters
$request : Request
$context : string|int = null

sameOriginPost()

True when this request is a same-origin navigation (not a cross-site CSRF POST).

public static sameOriginPost() : bool
Return values
bool

sendLti11LaunchFromContent()

Sign a lesson launch from an lti_content row.

public static sendLti11LaunchFromContent(Application $app, array<string, mixed> $row, string $launch_presentation_return_url, string $redirect_path_on_error[, string|null $grade_refresh_session_key = null ]) : RedirectResponse|string
Parameters
$app : Application
$row : array<string, mixed>
$launch_presentation_return_url : string
$redirect_path_on_error : string
$grade_refresh_session_key : string|null = null
Return values
RedirectResponse|string

sendLti11LaunchFromLessonsItem()

Build and print the auto-submit HTML for an LTI 1.1 basic-lti-launch-request to a tool URL described by a lessons.json / lessons-items item (same shape as {@see \Tsugi\Services\Lessons\LessonsService::getLtiByRlid()}).

public static sendLti11LaunchFromLessonsItem(Application $app, object $lti, string $launch_presentation_return_url, string $redirect_path_on_error[, string $fallback_resource_link_title = '' ][, string|null $grade_refresh_session_key = null ]) : RedirectResponse|string
Parameters
$app : Application
$lti : object

Must have resource_link_id; launch is required for LTI tools (discussions POST to {wwwroot}/tool/tdiscus)

$launch_presentation_return_url : string

Return URL after the external tool

$redirect_path_on_error : string

Session addSession path for flash+redirect on failure

$fallback_resource_link_title : string = ''

Used when $lti->title is missing

$grade_refresh_session_key : string|null = null

If non-null, GradeUtil::invalidateGradesCurrentUser() and set this session key (typically self::SESSION_LESSONS_GRADE_REFRESH_AFTER_LAUNCH)

Return values
RedirectResponse|string —

Empty string after HTML is printed; RedirectResponse on session failure only (caller handles other errors)

sendQueue()

public sendQueue(Request $request[, string|int $context = null ]) : mixed
Parameters
$request : Request
$context : string|int = null

share()

public share(Request $request) : mixed
Parameters
$request : Request

teacherCourses()

Active classes the connected Google account teaches.

public static teacherCourses(Google_Service_Classroom $service[, int $maxPages = 0 ]) : array<int, Google_Service_Classroom_Course>
Parameters
$service : Google_Service_Classroom
$maxPages : int = 0

0 reads every page

Return values
array<int, Google_Service_Classroom_Course>

useAccount()

Ask Google which account to use, then come back to the install page.

public useAccount(Request $request) : mixed
Parameters
$request : Request

appHomeUrl()

App home (home_path, else apphome, else wwwroot).

protected static appHomeUrl() : string
Return values
string

assetUrl()

Alias for staticUrl() for backward compatibility

protected assetUrl(mixed $filename[, mixed $controllerName = null ]) : mixed

Use staticUrl() instead

Parameters
$filename : mixed
$controllerName : mixed = null

controllerUrl()

Generate URL to another controller

protected controllerUrl(string $controllerRoute[, string|null $currentRoute = null ]) : string
Parameters
$controllerRoute : string

The route of the target controller (e.g., '/pages', '/announcements')

$currentRoute : string|null = null

Optional current route (defaults to detecting from context)

Return values
string —

Full URL to the controller

courseFileBaseUrl()

Current course base URL for Common Cartridge file-base rewriting.

protected courseFileBaseUrl(string $route) : string

Example: https://host/py4e or https://host/courses/2

Parameters
$route : string

The route constant for this tool (e.g. '/pages')

Return values
string —

Course base with no trailing slash

courseRequiredHtml()

protected courseRequiredHtml() : string
Return values
string

exitCourseRequired()

A site tool such as grades was opened with no course.

protected exitCourseRequired() : mixed

Continue uses this tab's LTI return URL when one is stored, and the app home when it is not. A Plus launch never reaches this: the router stops it before the tool action.

externalLinkAttrs()

Get link attributes for external vs same-site URLs

protected externalLinkAttrs(string $url[, string $linkLabel = 'Learn more' ]) : array<string|int, mixed>

Same-site links open in the current tab; external links get target="_blank" and rel="noopener noreferrer". Uses $CFG->apphome to determine same-site.

Parameters
$url : string

The link URL

$linkLabel : string = 'Learn more'

Optional label for aria-label (default: 'Learn more')

Return values
array<string|int, mixed> —

['attrs' => string, 'aria_label' => string, 'external' => bool]

isAdmin()

Check if the current user is a site administrator

protected isAdmin() : bool
Return values
bool —

True if user is admin, false otherwise

isInstructor()

Check if the current logged-in user is an instructor/admin for the current context

protected isInstructor() : bool

This method checks:

  1. If user is site admin (passphrase session)
  2. If user has instructor role or role_override in lti_membership table
  3. If user owns the context or its key

Reads context via ReqScope::currentContextId(); user id via ReqScope::loggedInUserId() (session or globals). Delegates to Membership::ensureInSession(), which caches a Membership instance in context-scoped session cache via Membership::ensureInSession() (single lti_membership SELECT when missing; ownership query only when role must be resolved).

Return values
bool —

True if user is instructor/admin for the context, false otherwise

leavePageReturnScript()

Point Continue at this tab's launch return before footer scripts replace TSUGI_SESSION_DATA with the current page.

protected static leavePageReturnScript(string $detail) : string

Same read and preference as Output::htmlError: error return, then return URL.

Parameters
$detail : string
Return values
string

lmsAnalyticsKey()

Build a stable key for LMS analytics, distinct from LTI resource_link_id values.

protected lmsAnalyticsKey([string|null $path = null ]) : string
Parameters
$path : string|null = null
Return values
string

lmsAnalyticsPath()

Build a stable path identifier for LMS tools (no query/session params).

protected lmsAnalyticsPath() : string

Examples:

  • /lms/pages
  • /lms/assignments
Return values
string

Ensure there is an `lti_link` row for a local LMS page/tool and return link_id.

protected lmsEnsureAnalyticsLink(int $context_id, string $link_key[, string|null $title = null ][, string|null $path = null ]) : int|false

We intentionally store LMS "tools" as synthetic lti_link records scoped to the already-selected lti_context, so we can reuse the existing analytics tables (lti_link_activity, lti_link_user_activity) without schema changes.

Parameters
$context_id : int
$link_key : string
$title : string|null = null
$path : string|null = null
Return values
int|false

lmsRecordLaunchAnalytics()

Record LMS page/tool "launch" into Tsugi internal analytics, mirroring LTIX behavior.

protected lmsRecordLaunchAnalytics(string $analytics_path[, string|null $title = null ]) : int|false
  • Only records for learners (i.e., not instructors/admins)
  • Stores data in lti_link_activity / lti_link_user_activity with event=0
Parameters
$analytics_path : string

Required stable path for this tool (e.g., '/lms/pages')

$title : string|null = null

Optional display title for this synthetic link

Return values
int|false —

The link_id if successful, false otherwise

plusLeftCourseHtml()

protected static plusLeftCourseHtml() : string
Return values
string

renderLeavePage()

Error page with Close Tab and Continue.

protected static renderLeavePage(array{title: string, paragraphs: array, home: string} $copy) : string

Continue starts at the app home. The page script points it at this tab's launch return when session storage has one.

Parameters
$copy : array{title: string, paragraphs: array, home: string}
Return values
string

requireAuth()

Check authentication and context

protected requireAuth() : mixed
Tags
throws
Exception

If user is not logged in or context is missing

requireGlobalRoute()

Bounce a course-mounted URL to a global (unprefixed) URL.

protected requireGlobalRoute(string $globalUrl) : RedirectResponse|null
Parameters
$globalUrl : string

Already session-bearing when the caller wants a session cookie

Return values
RedirectResponse|null

requireInstructor()

Check if user is instructor/admin, redirect if not

protected requireInstructor([string $redirectUrl = null ]) : bool
Parameters
$redirectUrl : string = null

URL to redirect to if not authorized

Return values
bool —

True if user is instructor/admin, false otherwise (and redirects)

showAnalytics()

Display analytics for an LMS tool

protected showAnalytics(string $route[, string|null $title = null ]) : string

Automatically derives back_url and stable_path from the route.

Parameters
$route : string

The route constant (e.g., '/pages', '/announcements')

$title : string|null = null

Optional display title (defaults to route without leading slash, capitalized)

Return values
string —

Empty string (outputs HTML directly)

staticUrl()

Generate URL for a controller-specific static file (JS, CSS, etc.)

protected staticUrl(string $filename[, string|null $controllerName = null ]) : string

Static files are served from tsugi/lib/src/Controllers/static/{ControllerName}/ This method generates the proper URL for accessing these static files.

Parameters
$filename : string

Static filename (e.g., 'tsugi-announce.js')

$controllerName : string|null = null

Optional controller name (defaults to current controller)

Return values
string —

Full URL to the static file

toolHome()

Get the base path for this tool (e.g., '/py4e/pages' or '/courses/2/pages')

protected toolHome(string $route) : string

Looks at the current request URI and finds the tool's route within it, so nested mounts keep generating nested URLs.

Parameters
$route : string

The route constant for this tool (e.g., '/pages', '/announcements')

Return values
string —

The base path including the route (e.g., '/py4e/pages')

toolParent()

Get the parent path one level above the tool home

protected toolParent([string $route = null ]) : string

This is useful for shared resources like static files that are mounted at a common path above individual controllers.

Parameters
$route : string = null

The route constant for this tool (e.g., '/pages', '/announcements')

Return values
string —

The parent path (e.g., '/py4e' if toolHome is '/py4e/pages')

viewDueDates()

Whether the current user may see due dates in this context (lti_membership.viewDueDates).

protected viewDueDates() : bool

Loads Membership via ensureInSession(); for non-admins also calls isInstructor() so the same cached object is used for role checks in mixed call order.

Return values
bool

absoluteLaunchUrl()

A stored link path may be a full URL or a tool-relative path.

private absoluteLaunchUrl(string $path, int $linkId[, int $contextId = 0 ]) : mixed

A quiz path is the take page for that link, so the Classroom launch opens the quiz that lives on the course. The redirect must be absolute: a short path is resolved against /gclass/launch/ and never reaches the quiz.

Parameters
$path : string
$linkId : int
$contextId : int = 0

Course that owns the link. The launch request is not under /courses.

acceptClassroomStudent()

The signed-in user may open this course from Classroom.

private acceptClassroomStudent(int $contextId, string $gcCourse, int $ownerId, string $ownerEmail) : true|string

A person who is already a member is not checked again.

Parameters
$contextId : int
$gcCourse : string
$ownerId : int
$ownerEmail : string
Return values
true|string

assignCourse()

Install the whole course as a Classroom material. Opening it joins the course. No resource link is created.

private assignCourse() : Response
Return values
Response

assignLesson()

Install a lesson page as a Classroom material. No resource link is created.

private assignLesson(string $anchor) : Response
Parameters
$anchor : string
Return values
Response

bindQuizEndpoint()

A Quiz1 take URL has to name a link in the course being installed.

private bindQuizEndpoint(string $endpoint, int $contextId) : string|null

The stored path records that course and link. Other tools are unchanged.

Parameters
$endpoint : string
$contextId : int
Return values
string|null

clientOrRedirect()

private clientOrRedirect(mixed $accessTokenStr[, mixed $user_id = false ]) : Google_Client|Response
Parameters
$accessTokenStr : mixed
$user_id : mixed = false
Return values
Google_Client|Response

courseLessonLaunch()

private courseLessonLaunch(int $contextId, string $rlid) : mixed
Parameters
$contextId : int
$rlid : string

courseMaterialSig()

Signature for a lesson or course material. The Google class is part of the signature so one class cannot be paired with another course.

private courseMaterialSig(string $gcSecret, string $gcCourse, int|string $contextId, string $bound) : mixed
Parameters
$gcSecret : string
$gcCourse : string
$contextId : int|string
$bound : string

Lesson anchor, or course

courseUrl()

private courseUrl(int $contextId) : mixed
Parameters
$contextId : int

currentRequestPath()

Path of this request, without the query string, for the post-login return.

private currentRequestPath(Request $request) : mixed
Parameters
$request : Request

discussionLaunchUrl()

Discussion URL inside this course, matching the lessons page.

private discussionLaunchUrl(int $contextId, string $rlid) : mixed
Parameters
$contextId : int
$rlid : string

endpointForResource()

Launch URL and title for a lesson resource id.

private endpointForResource(string $rlid) : array{url: string, title: string}|null

File lessons resolve through the lesson JSON. A manifest tool, quiz, or discussion resolves through this course's manifest and its links.

Parameters
$rlid : string
Return values
array{url: string, title: string}|null

endpointFromLessonItem()

private endpointFromLessonItem(object|array<string, mixed> $item, string $rlid, int $contextId, bool $manifest) : array{url: string, title: string}|null
Parameters
$item : object|array<string, mixed>
$rlid : string
$contextId : int
$manifest : bool
Return values
array{url: string, title: string}|null

endpointFromStoredPath()

private endpointFromStoredPath(string $path, int $linkId, string $title, string $rlid) : array{url: string, title: string}|null
Parameters
$path : string
$linkId : int
$title : string
$rlid : string
Return values
array{url: string, title: string}|null

existingCourseLinkId()

The lesson resource's own link in this course, or 0 when this install still needs a new link. A manifest quiz already has that link.

private existingCourseLinkId(int $contextId, string $rlid) : mixed
Parameters
$contextId : int
$rlid : string

fileCoursePlacement()

private fileCoursePlacement(string $googleCourseId, string $googleTitle, int $userId, mixed $keyId) : array{context_id: int, gc_secret: string, sig_user: int}
Parameters
$googleCourseId : string
$googleTitle : string
$userId : int
$keyId : mixed
Return values
array{context_id: int, gc_secret: string, sig_user: int}

findResourceNode()

private findResourceNode(array<string, mixed> $node, string $rlid) : array<string, mixed>|null
Parameters
$node : array<string, mixed>
$rlid : string
Return values
array<string, mixed>|null

googleCourseId()

Google course id stored in gclass:{id}:{sig}.

private static googleCourseId(mixed $contextKey) : mixed
Parameters
$contextKey : mixed

A Classroom link whose path says inherit= the quiz. The session should be the quiz link. The coursework id stays on the Classroom link.

private inheritedGradeLink(int $contextId, string $path, int $fromLinkId) : array{link_id: int, title: string}|null
Parameters
$contextId : int
$path : string
$fromLinkId : int
Return values
array{link_id: int, title: string}|null

launchPieces()

private launchPieces(mixed $resource) : mixed
Parameters
$resource : mixed

lessonAnchor()

A lesson anchor safe to put in a signed Classroom URL.

private lessonAnchor(mixed $raw) : mixed
Parameters
$raw : mixed

loginRedirect()

private loginRedirect([string|false $path = false ]) : RedirectResponse
Parameters
$path : string|false = false
Return values
RedirectResponse

manifestPlacement()

private manifestPlacement(int $contextId, int $userId) : array{context_id: int, gc_secret: string, sig_user: int}|string
Parameters
$contextId : int
$userId : int
Return values
array{context_id: int, gc_secret: string, sig_user: int}|string

materialsConsent()

The stored Classroom connection can install assignments. Lesson and course links need a newer permission, so send the teacher through consent once.

private materialsConsent(string $title, string $gcCourse, array<string, string> $keep) : Response|null
Parameters
$title : string
$gcCourse : string
$keep : array<string, string>
Return values
Response|null

openSignedCourse()

private openSignedCourse(Request $request, string|null $sig, string|null $anchor) : mixed
Parameters
$request : Request
$sig : string|null
$anchor : string|null

Null opens the course itself.

ownedClassroom()

private ownedClassroom(int $contextId) : array<string, mixed>|null
Parameters
$contextId : int
Return values
array<string, mixed>|null

placementForInstall()

Course that owns the new Classroom link.

private placementForInstall(string $googleCourseId, string $googleTitle, int $userId, mixed $keyId) : array{context_id: int, gc_secret: string, sig_user: int}|string

A manifest course stays that course. A file-based course gets one Tsugi course per Google class, created on the first install.

Parameters
$googleCourseId : string
$googleTitle : string
$userId : int
$keyId : mixed
Return values
array{context_id: int, gc_secret: string, sig_user: int}|string

postMaterial()

Class picker and Classroom material. $urlFor builds the signed launch URL.

private postMaterial(string $endpoint_title, array<string, string> $keep, callable $urlFor, string $kind, string $detail) : Response
Parameters
$endpoint_title : string
$keep : array<string, string>
$urlFor : callable
$kind : string
$detail : string
Return values
Response

reenterCourseFromQuery()

/gclass/assign is a site URL, so the session is put back on the global course before this runs. The lesson that opened the installer names its course. Come back to that course before resolving the resource.

private reenterCourseFromQuery() : mixed

rememberCourse()

Remember which Google course this column grades, so a course-page submit can send the score without the Classroom launch session.

private rememberCourse(int $linkId, string $courseId) : mixed
Parameters
$linkId : int
$courseId : string

renderCourse()

private renderCourse(array<string, mixed> $row) : mixed
Parameters
$row : array<string, mixed>

requireLoggedIn()

private requireLoggedIn() : RedirectResponse|null
Return values
RedirectResponse|null

sameSig()

Constant-time compare for the 6-character Classroom signatures.

private sameSig(mixed $expected, mixed $given) : mixed
Parameters
$expected : mixed
$given : mixed

sanityCheck()

private sanityCheck() : RedirectResponse|null
Return values
RedirectResponse|null

scopeDenied()

private scopeDenied(Throwable $e) : mixed
Parameters
$e : Throwable

takePanelReturn()

Post-login return when it points at a Classroom page.

private takePanelReturn() : string|null
Return values
string|null

toolLaunchUrl()

Hand the quiz a cookieless tool session. The site login is a cookie.

private toolLaunchUrl(string $path, array<string, mixed> $lti) : mixed

tool/gift starts with cookies off and only resumes _LTI_TSUGI.

Parameters
$path : string
$lti : array<string, mixed>

        
On this page

Search results