Quiz App Integration
Quizzes are ProjectForm resources with form_type=quiz. The current model/service implementation uses QuizSettings, QuizAttempt and app/Services/Quiz/QuizService.php. Configure the actual form's question/settings and project audience before wiring an attendee app.
App setup
Before writing quiz calls, complete the resource, installation and login setup:
- Create a project quiz form and configure its questions, banks, scoring, disclosure and attempt settings using the Forms Guide. Confirm the saved form is a quiz and belongs to the intended project.
- Create or select the attendee App using the plugin development workflow. For local Vue work, start with toolkit setup; a local scaffold does not create a project form or grant platform permissions.
- Declare the supported form/quiz dependencies and actions using Permissions and Dependencies, then expose the matching resource selectors through App Configuration. Resolve those selectors to this project's quiz form in the installed App.
- Configure the portal, referencing page, audience and supported attendee login using Portals and Authentication. Test the page with an intended attendee before connecting attempt operations.
- Select the exact operations and request schemas from the REST API reference and API Catalog. Keep portal-bound quiz calls on the serving portal hostname; using a different API host does not supply its page or attendee context. See API integration (repository reference:
/api-integration) for principal and host selection.
Use the GxP runtime store for API calls so the page token and principal context are preserved.
import { useGxpStore } from '@/stores/gxpPortalConfigStore'
const store = useGxpStore()
async function callQuizOperation(operationId, dependencyIdentifier, data = {}) {
return await store.callApi(operationId, dependencyIdentifier, data)
}
Choose the exact quiz operation IDs, path bindings and request fields from the deployed REST catalog. The older raw-fetch sequence is not a substitute for installed dependency authorization. A generic attendee bearer token alone is not the whole page-context authorization contract.
Page context and attendee identity
For attendee-app calls, the v1 /quiz/{form} route group uses enforce.form.page.context, even though it removes the ordinary Sanctum-auth middleware. The form slug must resolve within the current project, and the page context must pass its audience gate and reference that form. Missing or mismatched context is a 404; a page key from another resource is not a substitute. Use the runtime's supported page-token transport and installed dependency configuration rather than copying a token from a different portal.
The quiz controller separately resolves an attendee from portal_auth.attendee or the portal auth guard. State/start/answer operations return 401 when that attendee is absent. A public page key, reader credential or server API key does not by itself create an attendee quiz session. Test the intended supported attendee login flow; do not interpret the route's withoutMiddleware(auth:sanctum) as anonymous quiz-attempt support.
Operation sequence and response diagnosis
Operation suffix under /quiz/{form} | Method | Purpose |
|---|---|---|
state | GET | Reconcile quiz/attempt state for the current attendee |
subjects | GET | Resolve eligible subject-linked choices when configured |
start / restart | POST | Begin or restart through the server's attempt rules |
questions | GET | Retrieve the currently available question representation |
answer | POST | Submit type-specific answer data |
answer/{elementId}/status | GET | Inspect answer/scoring state |
complete / timeout | POST | Apply the corresponding server lifecycle action |
leaderboard | GET | Read the supported leaderboard response |
These suffixes describe the current route group, not standalone URLs or permission grants. Choose operation IDs and parameter names from the deployed catalog. The host store can resolve operation IDs against its operation map and uses the exact dependency identifier to obtain route bindings; arbitrary placeholder names do not establish a form binding.
Answer submission uses element_id, answer and optional nonnegative integer time_spent; answer shape depends on the configured question type, so one generic string payload is not correct for every type. Consult the actual handler/catalog and verify invalid input is rejected in your target route; request-time type-specific rules are conditional on a resolved ProjectForm, not merely a form slug string. Subject-linked forms also have subject selection/concurrency rules. An answer with no active matching attempt returns 409; multiple open subject attempts can require an explicit subject rather than an arbitrary first match.
Banks are server form/section configuration. The reviewed public start handler calls startAttempt with a null bank argument; do not invent a bank_slug request field or assume passing one selects a bank. Configure and verify the form's active-bank settings against actual returned questions.
Bank status and question-order checks
A section with no custom_settings.quiz_bank.status is treated as active; explicit draft and archived statuses are excluded by the active-bank scope. Review the saved settings as well as the builder's labels.
The ordinary question-order helper first selects active quiz fields. With a resolved bank ID it filters to that bank; without one, it filters to active bank IDs only when that set is nonempty. If every bank is draft/archived, it omits the bank constraint and can still return active fields from those banks. Do not interpret “no active banks” as a reliable empty-question or access-control state. Verify the actual question response and form/page access before opening a quiz.
The helper's explicit-bank argument also does not independently validate that bank's status; the caller's selection/validation path matters. The public start handler does not expose that argument as a bank-slug selector. Free-play answer submission has an additional active-bank check, so do not extrapolate one helper result to every quiz operation.
For ordinary attempts, question order is prepared on the server and stored with the attempt. Section progression locks, randomization and the question limit affect preparation; changing client order alone does not change that stored selection. Free play deliberately starts without a locked question order and uses its own submission rules. Test the configured mode rather than sharing one client assumption across both.
Subject-linked attempts
A subject-linked quiz records an attempt against a configured subject, such as an entry in a linked collection. Retrieve eligible choices through subjects, retain the selected subject ID, and send subject_id with start/restart and subsequent attempt operations. Use the server's eligible choices rather than accepting an arbitrary collection entry ID.
Start/restart require a subject when the form is linked. Supplying a subject to an unlinked form returns 422; an unavailable or ineligible subject returns 404. Where an operation resolves open attempts, multiple open attempts without a subject return 422 with an open_attempts list. Supply the intended subject and reconcile that attempt instead of selecting an arbitrary list item. A resolved subject with no matching active attempt is a different condition: operations such as question retrieval return 409.
Attempt limits and numbering are scoped to the attendee and subject. An in-progress attempt contributes to the next attempt number but does not itself consume the attempt allowance. This does not permit duplicate open attempts: the service rejects a second open attempt for the same subject. Opening another subject while an attempt is active is also rejected unless allow_concurrent_subject_attempts is enabled; it defaults to false. Persist the subject alongside client attempt state when supporting concurrency.
Collection subjects require the configured collection to belong to the project, be active and pass attendee access checks. Entry eligibility includes configured tag filters and attendee tag visibility, but intentionally does not filter entry status: a draft entry can still be eligible. Do not use entry publication status to hide a subject. The attempt stores a subject reference and display snapshot so later edits do not remove its historical label.
Scores are selected using the configured attempt-scoring policy per subject, then summed for the attendee aggregate. For example, with highest scoring, subject A attempts scoring 10 and 30 contribute 30; subject B scoring 50 produces an aggregate of 80. Avoid treating that aggregate as one subject's score or one attempt's percentage.
Lifecycle
Read the current state, confirm eligibility, start an allowed attempt, submit answers through the supported operation, complete it and reconcile the server result. Handle pending/live state, retry/attempt restrictions, invalid answers and server errors. Do not award authoritative scores solely in the browser.
Question-specific settings belong to the relevant fields; quiz settings specialize the project form. Check actual schema_version before treating a v2 layout as a legacy field list.
Timing, restart and response recovery
For timed quizzes, display the server's remaining time and reconcile after reconnect. Open-attempt resolution checks elapsed server time and marks an attempt timed out only when elapsed time is greater than the configured limit; at the exact limit it remains open. This is request-time reconciliation, not evidence of a continuously running server timer. Answer processing also checks the limit. A browser countdown is useful feedback, but does not establish the stored attempt status.
A timeout updates stored totals and marks the attempt timed_out. An expired attempt is removed from the open-attempt result, so a subsequent operation can report 409 because no active attempt remains. The explicit timeout operation acts on the resolved active attempt; the reviewed handler does not require the countdown to have reached zero. Treat it as a state-changing action, rather than a harmless time check.
Restart is also a state-changing action. It first abandons the matching open attempt, then checks whether another attempt is allowed. Completed, timed-out and abandoned attempts all count toward max_attempts; an in-progress attempt alone does not. With a one-attempt allowance, restarting an open attempt can leave it abandoned and return 422 without starting a replacement. Explain this consequence before offering restart, and reconcile state after a rejected request instead of repeatedly retrying it.
If a completion reply is lost, inspect current state before beginning another attempt. When no open attempt is found, the completion handler can return results from the latest completed attempt for the form and attendee, narrowed to the subject when one is supplied. That fallback does not recover an arbitrary historical attempt ID or turn a timed-out attempt into a completed one. Keep subject context when recovering concurrent subject attempts, and distinguish pending AI scoring from completion itself.
Asynchronous scoring and final results
Question handlers can use synchronous, asynchronous or accumulative submission strategies. AI-analysis questions use asynchronous scoring. Their successful submission reply includes status: scoring and an answer ID; it is not a final correctness/points result. The stored answer begins pending before the scoring job runs.
| AI answer state | Client interpretation |
|---|---|
pending | Recorded and awaiting scoring work; reconcile rather than immediately resubmitting |
scoring | Processing is in progress; keep a bounded waiting/error UI |
scored | Read the server's correctness/points result and refresh the relevant totals |
failed | Inspect the supported retry response and current limits; do not invent a score locally |
Use the supported answer-status operation and deployed event contract to reconcile after reconnect or a lost reply. A submitted answer, a completed attempt record and completed AI scoring are different milestones. The scoring job updates attempt totals after scoring; do not treat an attempt-completion event alone as proof that every outstanding provider result is final.
Failed AI scoring rows are excluded from the handler's submission-limit count, while their submission numbers remain part of the history. Read the current can_retry/submission state rather than subtracting the displayed submission number from a maximum yourself. A queued/pending row still counts until its state changes.
A direct-handler test also confirms a partial-write boundary: the AI handler records its pending answer before rejecting a non-file input. Request validation can reject an input earlier, so this does not mean every invalid HTTP request writes a row. It does mean an error is not a general rollback guarantee. Inspect the attempt/answer before retrying an errored submission.
The platform has an operator backstop for stale pending/scoring rows that marks eligible rows failed based on their last-progress timestamp. Its existence is not proof the job is scheduled or ran in a deployment; use the private recovery procedure for stuck processing. Do not leave the learner in an endless spinner or retry provider work blindly.
Verify
Test a correct and incorrect answer, invalid/missing input, allowed and excluded attendees, duplicate submissions, attempt completion and inaccessible cross-project/other-attendee attempts. For live operation, verify the deployed event contract and reconnect behavior. See Forms Guide and Quiz Architecture.
For failures, inspect the selected form, installed app version, binding, principal, attempt state and actual server response. Do not create a second attempt simply because a prior response was lost.