Overview
The Problem model represents a programming problem with test cases, judging configuration, and metadata. Problems can be attached to assignments or used for practice.Fillable Fields
Unique identifier for the problem
Display name of the problem
Command used to compare output (e.g., ‘diff’, ‘diff -w’, custom script)
Additional arguments passed to the diff command
Whether students can practice this problem outside of assignmentsCast:
booleanInternal notes visible only to administrators and problem owner
Difficulty level (e.g., ‘easy’, ‘medium’, ‘hard’)
ID of the user who created/owns this problem
Whether other instructors can use this problem in their assignmentsCast:
booleanOriginal author or source of the problem
Editorial/solution explanation (HTML supported)
Whether students can download test case input filesCast:
booleanWhether students can download test case output filesCast:
booleanCasts
Relationships
user() / owner()
The user who created this problem (both
user() and owner() return the same relationship)languages()
Programming languages allowed for this problemPivot fields:
time_limit- Execution time limit in seconds for this languagememory_limit- Memory limit in KB for this language
assignments()
Assignments that include this problem
submissions()
All submissions made to this problem
tags()
Tags for categorizing this problem (e.g., ‘dynamic-programming’, ‘graphs’)
Public Methods
get_directory_path()
Returns the filesystem path where problem files are stored.string - Absolute path to problem directory
Example:
can_practice()
Checks if a user has permission to practice this problem.$user(User) - User requesting access
boolean
Permission logic:
- Admin users: Always
true - Problem owner: Always
true - If
allow_practiceis true: Returnstrue - If
sharableis true AND user is head_instructor/instructor: Returnstrue - Otherwise: Returns
false
can_edit()
Checks if a user has permission to edit this problem.$user(User) - User requesting edit access
boolean
Permission logic:
- Admin users: Can edit any problem
- Problem owner: Can edit their own problems
- Others: Cannot edit
delete()
Deletes the problem and all associated data.- Starts database transaction
- Deletes all submissions for this problem
- Detaches all languages
- Detaches from all assignments
- Detaches all tags
- Deletes the model
- Commits transaction
- Deletes problem directory from filesystem using
rm -rf
pdf()
Serves the problem’s PDF file for download.template_path()
Returns the path to the code template file for a specific language.$language_extension(string) - File extension (e.g., ‘cpp’, ‘java’, ‘py’)
array - Array of matching file paths (or empty array)
Priority:
- Checks for
template.public.{extension}first - Falls back to
template.{extension}
template_content()
Returns the content of the code template for a specific language.$language_id(integer) - Language ID
string|null - Template file content or null if not found
Example:
description()
Returns the problem description and metadata.array with keys:
description(string) - HTML description or default messagehas_pdf(boolean) - Whether PDF file existshas_template(boolean) - Whether C++ template exists
available()
Static query scope for problems available to a user.$user_id(integer) - User ID
Builder - Query builder instance
Query logic: Returns problems where:
user_idmatches the given user, ORsharableis true

