Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

This file contains the definition for the class assignment This class provides all the functionality for the new assign module.

Copyright: 2012 NetSpot {@link http://www.netspot.com.au}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 10270 lines (425 kb)
Included or required: 2 times
Referenced: 65 times
Includes or requires: 1 file
 mod/assign/locallib.php

Defines 2 classes

assign:: (226 methods):
  __construct()
  register_return_link()
  get_return_action()
  show_intro()
  get_return_params()
  set_instance()
  set_context()
  set_course()
  set_error_message()
  get_error_messages()
  get_feedback_plugins()
  get_submission_plugins()
  is_blind_marking()
  is_hidden_grader()
  has_submissions_or_grades()
  get_plugin_by_type()
  get_feedback_plugin_by_type()
  get_submission_plugin_by_type()
  load_plugins()
  view()
  add_instance()
  delete_grades()
  delete_instance()
  delete_override()
  delete_all_overrides()
  update_effective_access()
  has_overrides()
  override_exists()
  is_override_calendar_event()
  get_valid_calendar_event_timestart_range()
  reset_userdata()
  update_plugin_instance()
  update_gradebook()
  get_assign_perpage()
  get_admin_config()
  update_calendar()
  update_instance()
  save_intro_draft_files()
  save_editor_draft_files()
  add_plugin_grade_elements()
  add_plugin_settings()
  add_all_plugin_settings()
  plugin_data_preprocessing()
  get_module_name()
  get_module_name_plural()
  has_instance()
  get_default_instance()
  get_instance()
  calculate_properties()
  get_grade_item()
  get_course_context()
  get_course_module()
  get_context()
  get_course()
  count_attachments()
  has_visible_attachments()
  should_provide_intro_attachments()
  display_grade()
  get_submission_info_for_participants()
  list_participants_with_filter_status_and_group()
  get_grading_sort_sql()
  get_submitted_sql()
  list_participants()
  get_participant()
  count_teams()
  count_participants()
  count_submissions_need_grading()
  count_grades()
  count_submissions()
  count_submissions_with_status()
  get_grading_userid_list()
  cron()
  notify_grade_modified()
  update_user_flags()
  update_grade()
  view_grant_extension()
  get_submission_group_members()
  get_submission_group_members_who_have_not_submitted()
  get_group_submission()
  view_course_index()
  view_plugin_page()
  get_submission_group()
  get_all_groups()
  view_plugin_content()
  download_rewrite_pluginfile_urls()
  render_editor_content()
  view_savegrading_result()
  view_quickgrading_result()
  view_footer()
  require_view_group_submission()
  require_view_submission()
  require_view_grades()
  can_view_grades()
  can_grade()
  download_submissions()
  add_to_log()
  get_renderer()
  get_user_submission()
  get_submission()
  get_user_flags()
  get_user_grade()
  get_grade()
  view_single_grading_panel()
  view_single_grade_page()
  view_remove_submission_confirm()
  view_reveal_identities_confirm()
  view_return_links()
  view_grading_table()
  view_grader()
  view_grading_page()
  plagiarism_print_disclosure()
  view_notices()
  fullname()
  view_edit_submission_page()
  get_timelimit_panel()
  is_graded()
  can_edit_group_submission()
  can_view_group_submission()
  can_view_submission()
  view_plugin_grading_batch_operation()
  process_grading_batch_operation()
  view_batch_set_workflow_state()
  view_batch_markingallocation()
  check_submit_for_grading()
  get_assign_submission_status_renderable()
  get_assign_feedback_status_renderable()
  get_assign_attempt_history_renderable()
  view_student_summary()
  show_submit_button()
  get_all_grades()
  get_all_submissions()
  get_assign_grading_summary_renderable()
  get_override_data()
  get_duedate()
  get_timelimit()
  get_cutoffdate()
  view_submission_page()
  view_submission_action_bar()
  convert_grade_for_gradebook()
  convert_submission_for_gradebook()
  gradebook_item_update()
  update_team_submission()
  update_submission()
  submissions_open()
  render_area_files()
  can_edit_submission()
  get_shared_group_members()
  get_graders()
  get_notifiable_users()
  format_notification_message_text()
  format_notification_message_html()
  send_assignment_notification()
  send_notification()
  notify_student_submission_copied()
  notify_student_submission_receipt()
  notify_graders()
  submit_for_grading()
  process_submit_other_for_grading()
  process_submit_for_grading()
  save_user_extension()
  process_save_extension()
  process_save_quick_grades()
  reveal_identities()
  process_reveal_identities()
  process_save_grading_options()
  format_grade_for_log()
  format_submission_for_log()
  process_copy_previous_attempt()
  copy_previous_attempt()
  submission_empty()
  new_submission_empty()
  save_submission()
  process_save_submission()
  grading_disabled()
  get_grading_instance()
  add_grade_form_elements()
  add_plugin_submission_elements()
  is_any_feedback_plugin_enabled()
  is_any_submission_plugin_enabled()
  add_submission_form_elements()
  remove_submission()
  revert_to_draft()
  process_remove_submission()
  process_revert_to_draft()
  lock_submission()
  process_set_batch_marking_workflow_state()
  process_set_batch_marking_allocation()
  process_lock_submission()
  unlock_submission()
  process_unlock_submission()
  apply_grade_to_user()
  process_outcomes()
  reopen_submission_if_required()
  save_grade()
  process_save_grade()
  can_upgrade_assignment()
  can_upgrade()
  copy_area_files_for_upgrade()
  process_add_attempt_group()
  process_add_attempt()
  add_attempt()
  get_user_grades_for_gradebook()
  get_uniqueid_for_user()
  allocate_unique_ids()
  get_uniqueid_for_user_static()
  get_user_id_for_uniqueid()
  get_user_id_for_uniqueid_static()
  get_marking_workflow_states_for_current_user()
  show_only_active_users()
  is_active_user()
  is_gradebook_feedback_enabled()
  get_grading_status()
  get_useridlist_key_id()
  get_useridlist_key()
  update_activity_completion_records()
  set_module_viewed()
  add_grade_notices()
  fix_null_grades()
  view_fix_rescaled_null_grades()
  set_most_recent_team_submission()
  get_marking_allocation_filters()
  get_marking_workflow_filters()
  get_filters()
  get_submissionstatement()
  is_time_limit_enabled()
  is_attempt_in_progress()

assign_portfolio_caller:: (14 methods):
  expected_callbackargs()
  __construct()
  load_data()
  prepare_package()
  get_submission_plugin()
  get_sha1()
  expected_time()
  check_permissions()
  display_name()
  base_supported_formats()
  assign_process_group_deleted_in_course()
  move_group_override()
  reorder_group_overrides()
  assign_get_js_module()


Class: assign  - X-Ref

Standard base class for mod_assign (assignment types).

__construct($coursemodulecontext, $coursemodule, $course)   X-Ref
Constructor for the base assign class.

Note: For $coursemodule you can supply a stdclass if you like, but it
will be more efficient to supply a cm_info object.

param: mixed $coursemodulecontext context|null the course module context
param: mixed $coursemodule the current course module if it was already loaded,
param: mixed $course the current course  if it was already loaded,

register_return_link($action, $params)   X-Ref
Set the action and parameters that can be used to return to the current page.

return: void
param: string $action The action for the current page
param: array $params An array of name value pairs which form the parameters

get_return_action()   X-Ref
Return an action that can be used to get back to the current page.

return: string action

show_intro()   X-Ref
Based on the current assignment settings should we display the intro.

return: bool showintro

get_return_params()   X-Ref
Return a list of parameters that can be used to get back to the current page.

return: array params

set_instance(stdClass $data)   X-Ref
Set the submitted form data.

param: stdClass $data The form data (instance)

set_context(context $context)   X-Ref
Set the context.

param: context $context The new context

set_course(stdClass $course)   X-Ref
Set the course data.

param: stdClass $course The course data

set_error_message(string $message)   X-Ref
Set error message.

param: string $message The error message

get_error_messages()   X-Ref
Get error messages.

return: array The array of error messages

get_feedback_plugins()   X-Ref
Get list of feedback plugins installed.

return: array

get_submission_plugins()   X-Ref
Get list of submission plugins installed.

return: array

is_blind_marking()   X-Ref
Is blind marking enabled and reveal identities not set yet?

return: bool

is_hidden_grader()   X-Ref
Is hidden grading enabled?

This just checks the assignment settings. Remember to check
the user has the 'showhiddengrader' capability too

return: bool

has_submissions_or_grades()   X-Ref
Does an assignment have submission(s) or grade(s) already?

return: bool

get_plugin_by_type($subtype, $type)   X-Ref
Get a specific submission plugin by its type.

return: mixed assign_plugin|null
param: string $subtype assignsubmission | assignfeedback
param: string $type

get_feedback_plugin_by_type($type)   X-Ref
Get a feedback plugin by type.

return: mixed assign_feedback_plugin|null
param: string $type - The type of plugin e.g comments

get_submission_plugin_by_type($type)   X-Ref
Get a submission plugin by type.

return: mixed assign_submission_plugin|null
param: string $type - The type of plugin e.g comments

load_plugins($subtype)   X-Ref
Load the plugins from the sub folders under subtype.

return: array - The sorted list of plugins
param: string $subtype - either submission or feedback

view($action='', $args = array()   X-Ref
Display the assignment, used by view.php

The assignment is displayed differently depending on your role,
the settings for the assignment and the status of the assignment.

return: string - The page output.
param: string $action The current action if any.
param: array $args Optional arguments to pass to the view (instead of getting them from GET and POST).

add_instance(stdClass $formdata, $callplugins)   X-Ref
Add this instance to the database.

return: mixed false if an error occurs or the int id of the new instance
param: stdClass $formdata The data submitted from the form
param: bool $callplugins This is used to skip the plugin code

delete_grades()   X-Ref
Delete all grades from the gradebook for this assignment.

return: bool

delete_instance()   X-Ref
Delete this instance from the database.

return: bool false if an error occurs

delete_override($overrideid)   X-Ref
Deletes a assign override from the database and clears any corresponding calendar events

return: bool true on success
param: int $overrideid The id of the override being deleted

delete_all_overrides()   X-Ref
Deletes all assign overrides from the database and clears any corresponding calendar events


update_effective_access($userid)   X-Ref
Updates the assign properties with override information for a user.

Algorithm:  For each assign setting, if there is a matching user-specific override,
then use that otherwise, if there are group-specific overrides, return the most
lenient combination of them.  If neither applies, leave the assign setting unchanged.

param: int $userid The userid.

has_overrides()   X-Ref
Returns whether an assign has any overrides.

return: true if any, false if not

override_exists($userid)   X-Ref
Returns user override

Algorithm:  For each assign setting, if there is a matching user-specific override,
then use that otherwise, if there are group-specific overrides, use the one with the
lowest sort order. If neither applies, leave the assign setting unchanged.

return: stdClass The override
param: int $userid The userid.

is_override_calendar_event(\calendar_event $event)   X-Ref
Check if the given calendar_event is either a user or group override
event.

return: bool

get_valid_calendar_event_timestart_range(\calendar_event $event)   X-Ref
This function calculates the minimum and maximum cutoff values for the timestart of
the given event.

It will return an array with two values, the first being the minimum cutoff value and
the second being the maximum cutoff value. Either or both values can be null, which
indicates there is no minimum or maximum, respectively.

If a cutoff is required then the function must return an array containing the cutoff
timestamp and error string to display to the user if the cutoff value is violated.

A minimum and maximum cutoff return value will look like:
[
[1505704373, 'The due date must be after the sbumission start date'],
[1506741172, 'The due date must be before the cutoff date']
]

If the event does not have a valid timestart range then [false, false] will
be returned.

return: array
param: calendar_event $event The calendar event to get the time range for

reset_userdata($data)   X-Ref
Actual implementation of the reset course functionality, delete all the
assignment submissions for course $data->courseid.

return: array status array
param: stdClass $data the data submitted from the reset course.

update_plugin_instance(assign_plugin $plugin, stdClass $formdata)   X-Ref
Update the settings for a single plugin.

return: bool false if an error occurs
param: assign_plugin $plugin The plugin to update
param: stdClass $formdata The form data

update_gradebook($reset, $coursemoduleid)   X-Ref
Update the gradebook information for this assignment.

return: bool
param: bool $reset If true, will reset all grades in the gradbook for this assignment
param: int $coursemoduleid This is required because it might not exist in the database yet

get_assign_perpage()   X-Ref
Get the marking table page size

return: integer

get_admin_config()   X-Ref
Load and cache the admin config for this module.

return: stdClass the plugin config

update_calendar($coursemoduleid)   X-Ref
Update the calendar entries for this assignment.

return: bool
param: int $coursemoduleid - Required to pass this in because it might

update_instance($formdata)   X-Ref
Update this instance in the database.

return: bool false if an error occurs
param: stdClass $formdata - the data submitted from the form

save_intro_draft_files($formdata)   X-Ref
Save the attachments in the intro description.

param: stdClass $formdata

save_editor_draft_files($formdata)   X-Ref
Save the attachments in the editor description.

param: stdClass $formdata

add_plugin_grade_elements($grade, MoodleQuickForm $mform, stdClass $data, $userid)   X-Ref
Add elements in grading plugin form.

return: void
param: mixed $grade stdClass|null
param: MoodleQuickForm $mform
param: stdClass $data
param: int $userid - The userid we are grading

add_plugin_settings(assign_plugin $plugin, MoodleQuickForm $mform, & $pluginsenabled)   X-Ref
Add one plugins settings to edit plugin form.

return: void
param: assign_plugin $plugin The plugin to add the settings from
param: MoodleQuickForm $mform The form to add the configuration settings to.
param: array $pluginsenabled A list of form elements to be added to a group.

add_all_plugin_settings(MoodleQuickForm $mform)   X-Ref
Add settings to edit plugin form.

return: void
param: MoodleQuickForm $mform The form to add the configuration settings to.

plugin_data_preprocessing(&$defaultvalues)   X-Ref
Allow each plugin an opportunity to update the defaultvalues
passed in to the settings form (needed to set up draft areas for
editor and filemanager elements)

param: array $defaultvalues

get_module_name()   X-Ref
Get the name of the current module.

return: string the module name (Assignment)

get_module_name_plural()   X-Ref
Get the plural name of the current module.

return: string the module name plural (Assignments)

has_instance()   X-Ref
Has this assignment been constructed from an instance?

return: bool

get_default_instance()   X-Ref
Get the settings for the current instance of this assignment.

return: stdClass The settings

get_instance(int $userid = null)   X-Ref
Get the settings for the current instance of this assignment

return: stdClass The settings
param: int|null $userid the id of the user to load the assign instance for.

calculate_properties(\stdClass $record, int $userid)   X-Ref
Calculates and updates various properties based on the specified user.

return: stdClass a new record having calculated properties.
param: stdClass $record the raw assign record.
param: int $userid the id of the user to calculate the properties for.

get_grade_item()   X-Ref
Get the primary grade item for this assign instance.

return: grade_item The grade_item record

get_course_context()   X-Ref
Get the context of the current course.

return: mixed context|null The course context

get_course_module()   X-Ref
Get the current course module.

return: cm_info|null The course module or null if not known

get_context()   X-Ref
Get context module.

return: context

get_course()   X-Ref
Get the current course.

return: mixed stdClass|null The course

count_attachments()   X-Ref
Count the number of intro attachments.

return: int

has_visible_attachments()   X-Ref
Are there any intro attachments to display?

return: boolean

should_provide_intro_attachments(int $userid)   X-Ref
Check if the intro attachments should be provided to the user.

return: bool
param: int $userid User id.

display_grade($grade, $editing, $userid=0, $modified=0)   X-Ref
Return a grade in user-friendly form, whether it's a scale or not.

return: string User-friendly representation of grade
param: mixed $grade int|null
param: boolean $editing Are we allowing changes to this grade?
param: int $userid The user id the grade belongs to
param: int $modified Timestamp from when the grade was last modified

get_submission_info_for_participants($participants)   X-Ref
Get the submission status/grading status for all submissions in this assignment for the
given paticipants.

These statuses match the available filters (requiregrading, submitted, notsubmitted, grantedextension).
If this is a group assignment, group info is also returned.

return: array an associative array where the key is the participant id and the value is
param: array $participants an associative array where the key is the participant id and

list_participants_with_filter_status_and_group($currentgroup, $tablesort = false)   X-Ref
Get the submission status/grading status for all submissions in this assignment.
These statuses match the available filters (requiregrading, submitted, notsubmitted, grantedextension).
If this is a group assignment, group info is also returned.

return: array List of user records with extra fields 'submitted', 'notsubmitted', 'requiregrading', 'grantedextension',
param: int $currentgroup
param: boolean $tablesort Apply current user table sorting preferences.

get_grading_sort_sql()   X-Ref
Return a valid order by segment for list_participants that matches
the sorting of the current grading table. Not every field is supported,
we are only concerned with a list of users so we can't search on anything
that is not part of the user information (like grading statud or last modified stuff).

return: string Order by clause for list_participants

get_submitted_sql($group = 0)   X-Ref
Returns array with sql code and parameters returning all ids of users who have submitted an assignment.

return: array list($sql, $params)
param: int $group The group that the query is for.

list_participants($currentgroup, $idsonly, $tablesort = false)   X-Ref
Load a list of users enrolled in the current course with the specified permission and group.
0 for no group.
Apply any current sort filters from the grading table.

return: array List of user records
param: int $currentgroup
param: bool $idsonly
param: bool $tablesort

get_participant($userid)   X-Ref
Load a user if they are enrolled in the current course. Populated with submission
status for this assignment.

return: null|stdClass user record
param: int $userid

count_teams($activitygroup = 0)   X-Ref
Load a count of valid teams for this assignment.

return: int number of valid teams
param: int $activitygroup Activity active group

count_participants($currentgroup)   X-Ref
Load a count of active users enrolled in the current course with the specified permission and group.
0 for no group.

return: int number of matching users
param: int $currentgroup

count_submissions_need_grading($currentgroup = null)   X-Ref
Load a count of active users submissions in the current module that require grading
This means the submission modification time is more recent than the
grading modification time and the status is SUBMITTED.

return: int number of matching submissions
param: mixed $currentgroup int|null the group for counting (if null the function will determine it)

count_grades()   X-Ref
Load a count of grades.

return: int number of grades

count_submissions($includenew = false)   X-Ref
Load a count of submissions.

return: int number of submissions
param: bool $includenew When true, also counts the submissions with status 'new'.

count_submissions_with_status($status, $currentgroup = null)   X-Ref
Load a count of submissions with a specified status.

return: int number of matching submissions
param: string $status The submission status - should match one of the constants
param: mixed $currentgroup int|null the group for counting (if null the function will determine it)

get_grading_userid_list($cached = false, $useridlistid = '')   X-Ref
Utility function to get the userid for every row in the grading table
so the order can be frozen while we iterate it.

return: array An array of userids
param: boolean $cached If true, the cached list from the session could be returned.
param: string $useridlistid String value used for caching the participant list.

cron()   X-Ref
Finds all assignment notifications that have yet to be mailed out, and mails them.

Cron function to be run periodically according to the moodle cron.

return: bool

notify_grade_modified($grade, $mailedoverride = false)   X-Ref
Mark in the database that this grade record should have an update notification sent by cron.

return: bool true for success
param: stdClass $grade a grade record keyed on id
param: bool $mailedoverride when true, flag notification to be sent again.

update_user_flags($flags)   X-Ref
Update user flags for this user in this assignment.

return: bool true for success
param: stdClass $flags a flags record keyed on id

update_grade($grade, $reopenattempt = false)   X-Ref
Update a grade in the grade table for the assignment and in the gradebook.

return: bool true for success
param: stdClass $grade a grade record keyed on id
param: bool $reopenattempt If the attempt reopen method is manual, allow another attempt at this assignment.

view_grant_extension($mform)   X-Ref
View the grant extension date page.

Uses url parameters 'userid'
or from parameter 'selectedusers'

return: string
param: moodleform $mform - Used for validation of the submitted data

get_submission_group_members($groupid, $onlyids, $excludesuspended = false)   X-Ref
Get a list of the users in the same group as this user.

return: array The users (possibly id's only)
param: int $groupid The id of the group whose members we want or 0 for the default group
param: bool $onlyids Whether to retrieve only the user id's
param: bool $excludesuspended Whether to exclude suspended users

get_submission_group_members_who_have_not_submitted($groupid, $onlyids)   X-Ref
Get a list of the users in the same group as this user that have not submitted the assignment.

return: array The users (possibly id's only)
param: int $groupid The id of the group whose members we want or 0 for the default group
param: bool $onlyids Whether to retrieve only the user id's

get_group_submission($userid, $groupid, $create, $attemptnumber=-1)   X-Ref
Load the group submission object for a particular user, optionally creating it if required.

return: stdClass The submission
param: int $userid The id of the user whose submission we want
param: int $groupid The id of the group for this user - may be 0 in which
param: bool $create If set to true a new submission object will be created in the database
param: int $attemptnumber - -1 means the latest attempt

view_course_index()   X-Ref
View a summary listing of all assignments in the current course.

return: string

view_plugin_page()   X-Ref
View a page rendered by a plugin.

Uses url parameters 'pluginaction', 'pluginsubtype', 'plugin', and 'id'.

return: string

get_submission_group($userid)   X-Ref
This is used for team assignments to get the group for the specified user.
If the user is a member of multiple or no groups this will return false

return: mixed The group or false
param: int $userid The id of the user whose submission we want

get_all_groups($userid)   X-Ref
Gets all groups the user is a member of.

return: array The group objects
param: int $userid Teh id of the user who's groups we are checking

view_plugin_content($pluginsubtype)   X-Ref
Display the submission that is used by a plugin.

Uses url parameters 'sid', 'gid' and 'plugin'.

return: string
param: string $pluginsubtype

download_rewrite_pluginfile_urls($text, $user, $plugin)   X-Ref
Rewrite plugin file urls so they resolve correctly in an exported zip.

param: string $text - The replacement text
param: stdClass $user - The user record
param: assign_plugin $plugin - The assignment plugin

render_editor_content($filearea, $submissionid, $plugintype, $editor, $component, $shortentext = false)   X-Ref
Render the content in editor that is often used by plugin.

return: string
param: string $filearea
param: int $submissionid
param: string $plugintype
param: string $editor
param: string $component
param: bool $shortentext Whether to shorten the text content.

view_savegrading_result($message)   X-Ref
Display a continue page after grading.

return: string
param: string $message - The message to display.

view_quickgrading_result($message)   X-Ref
Display a continue page after quickgrading.

return: string
param: string $message - The message to display.

view_footer()   X-Ref
Display the page footer.

return: string

require_view_group_submission($groupid)   X-Ref
Throw an error if the permissions to view this users' group submission are missing.

param: int $groupid Group id.

require_view_submission($userid)   X-Ref
Throw an error if the permissions to view this users submission are missing.

return: none

require_view_grades()   X-Ref
Throw an error if the permissions to view grades in this assignment are missing.

return: none

can_view_grades($groupid = null)   X-Ref
Does this user have view grade or grade permission for this assignment?

return: bool
param: mixed $groupid int|null when is set to a value, use this group instead calculating it

can_grade($user = null)   X-Ref
Does this user have grade permission for this assignment?

return: bool
param: int|stdClass $user The object or id of the user who will do the editing (default to current user).

download_submissions($userids = false)   X-Ref
Download a zip file of all assignment submissions.

return: string - If an error occurs, this will contain the error page.
param: array $userids Array of user ids to download assignment submissions in a zip file

add_to_log($action = '', $info = '', $url='', $return = false)   X-Ref
Util function to add a message to the log.

return: void|array
param: string $action The current action
param: string $info A detailed description of the change. But no more than 255 characters.
param: string $url The url to the assign module instance.
param: bool $return If true, returns the arguments, else adds to log. The purpose of this is to

get_renderer()   X-Ref
Lazy load the page renderer and expose the renderer to plugins.

return: assign_renderer

get_user_submission($userid, $create, $attemptnumber=-1)   X-Ref
Load the submission object for a particular user, optionally creating it if required.

For team assignments there are 2 submissions - the student submission and the team submission
All files are associated with the team submission but the status of the students contribution is
recorded separately.

return: stdClass The submission
param: int $userid The id of the user whose submission we want or 0 in which case USER->id is used
param: bool $create If set to true a new submission object will be created in the database with the status set to "new".
param: int $attemptnumber - -1 means the latest attempt

get_submission($submissionid)   X-Ref
Load the submission object from it's id.

return: stdClass The submission
param: int $submissionid The id of the submission we want

get_user_flags($userid, $create)   X-Ref
This will retrieve a user flags object from the db optionally creating it if required.
The user flags was split from the user_grades table in 2.5.

return: stdClass The flags record
param: int $userid The user we are getting the flags for.
param: bool $create If true the flags record will be created if it does not exist

get_user_grade($userid, $create, $attemptnumber=-1)   X-Ref
This will retrieve a grade object from the db, optionally creating it if required.

return: stdClass The grade record
param: int $userid The user we are grading
param: bool $create If true the grade will be created if it does not exist
param: int $attemptnumber The attempt number to retrieve the grade for. -1 means the latest submission.

get_grade($gradeid)   X-Ref
This will retrieve a grade object from the db.

return: stdClass The grade record
param: int $gradeid The id of the grade

view_single_grading_panel($args)   X-Ref
Print the grading page for a single user submission.

return: string
param: array $args Optional args array (better than pulling args from _GET and _POST)

view_single_grade_page($mform)   X-Ref
Print the grading page for a single user submission.

return: string
param: moodleform $mform

view_remove_submission_confirm()   X-Ref
Show a confirmation page to make sure they want to remove submission data.

return: string

view_reveal_identities_confirm()   X-Ref
Show a confirmation page to make sure they want to release student identities.

return: string

view_return_links()   X-Ref
View a link to go back to the previous page. Uses url parameters returnaction and returnparams.

return: string

view_grading_table()   X-Ref
View the grading table of all submissions for this assignment.

return: string

view_grader()   X-Ref
View entire grader app.

return: string

view_grading_page()   X-Ref
View entire grading page.

return: string

plagiarism_print_disclosure()   X-Ref
Capture the output of the plagiarism plugins disclosures and return it as a string.

return: string

view_notices($title, $notices)   X-Ref
Message for students when assignment submissions have been closed.

return: string
param: string $title The page title
param: array $notices The array of notices to show.

fullname($user)   X-Ref
Get the name for a user - hiding their real name if blind marking is on.

return: string The name.
param: stdClass $user The user record as required by fullname()

view_edit_submission_page($mform, $notices)   X-Ref
View edit submissions page.

return: string The page output.
param: moodleform $mform
param: array $notices A list of notices to display at the top of the

get_timelimit_panel(stdClass $submission)   X-Ref
Get the time limit panel object for this submission attempt.

return: string the panel output.
param: stdClass $submission assign submission.

is_graded($userid)   X-Ref
See if this assignment has a grade yet.

return: bool
param: int $userid

can_edit_group_submission($groupid)   X-Ref
Perform an access check to see if the current $USER can edit this group submission.

return: bool
param: int $groupid

can_view_group_submission($groupid)   X-Ref
Perform an access check to see if the current $USER can view this group submission.

return: bool
param: int $groupid

can_view_submission($userid)   X-Ref
Perform an access check to see if the current $USER can view this users submission.

return: bool
param: int $userid

view_plugin_grading_batch_operation($mform)   X-Ref
Allows the plugin to show a batch grading operation page.

return: none
param: moodleform $mform

process_grading_batch_operation(& $mform)   X-Ref
Ask the user to confirm they want to perform this batch operation

return: string - the page to view after processing these actions
param: moodleform $mform Set to a grading batch operations form

view_batch_set_workflow_state($mform)   X-Ref
Shows a form that allows the workflow state for selected submissions to be changed.

return: string - the page to view after processing these actions
param: moodleform $mform Set to a grading batch operations form

view_batch_markingallocation($mform)   X-Ref
Shows a form that allows the allocated marker for selected submissions to be changed.

return: string - the page to view after processing these actions
param: moodleform $mform Set to a grading batch operations form

check_submit_for_grading($mform)   X-Ref
Ask the user to confirm they want to submit their work for grading.

return: string
param: moodleform $mform - null unless form validation has failed

get_assign_submission_status_renderable($user, $showlinks)   X-Ref
Creates an assign_submission_status renderable.

return: assign_submission_status renderable object
param: stdClass $user the user to get the report for
param: bool $showlinks return plain text or links to the profile

get_assign_feedback_status_renderable($user)   X-Ref
Creates an assign_feedback_status renderable.

return: assign_feedback_status renderable object
param: stdClass $user the user to get the report for

get_assign_attempt_history_renderable($user)   X-Ref
Creates an assign_attempt_history renderable.

return: assign_attempt_history renderable object
param: stdClass $user the user to get the report for

view_student_summary($user, $showlinks)   X-Ref
Print 2 tables of information with no action links -
the submission summary and the grading summary.

return: string - the html summary
param: stdClass $user the user to print the report for
param: bool $showlinks - Return plain text or links to the profile

show_submit_button($submission = null, $teamsubmission = null, $userid = null)   X-Ref
Returns true if the submit subsission button should be shown to the user.

return: bool
param: stdClass $submission The users own submission record.
param: stdClass $teamsubmission The users team submission record if there is one
param: int $userid The user

get_all_grades($userid)   X-Ref
Get the grades for all previous attempts.
For each grade - the grader is a full user record,
and gradefordisplay is added (rendered from grading manager).

return: array $grades All grade records for this user.
param: int $userid If not set, $USER->id will be used.

get_all_submissions($userid)   X-Ref
Get the submissions for all previous attempts.

return: array $submissions All submission records for this user (or group).
param: int $userid If not set, $USER->id will be used.

get_assign_grading_summary_renderable($activitygroup = null)   X-Ref
Creates an assign_grading_summary renderable.

return: assign_grading_summary renderable object
param: mixed $activitygroup int|null the group for calculating the grading summary (if null the function will determine it)

get_override_data(int $activitygroup)   X-Ref
Helper function to allow up to fetch the group overrides via one query as opposed to many calls.

return: mixed Can return either a fetched DB object, local object or false
param: int $activitygroup The group we want to check the overrides of

get_duedate($activitygroup = null)   X-Ref
Return group override duedate.

return: int $duedate
param: int $activitygroup Activity active group

get_timelimit(?int $activitygroup = null)   X-Ref
Return group override timelimit.

return: int $timelimit
param: null|int $activitygroup Activity active group

get_cutoffdate(?int $activitygroup = null)   X-Ref
Return group override cutoffdate.

return: int $cutoffdate
param: null|int $activitygroup Activity active group

view_submission_page()   X-Ref
View submissions page (contains details of current submission).

return: string

view_submission_action_bar(stdClass $instance, stdClass $user)   X-Ref
The action bar displayed in the submissions page.

return: string
param: stdClass $instance The settings for the current instance of this assignment
param: stdClass $user The user to print the action bar for

convert_grade_for_gradebook(stdClass $grade)   X-Ref
Convert the final raw grade(s) in the grading table for the gradebook.

return: array
param: stdClass $grade

convert_submission_for_gradebook(stdClass $submission)   X-Ref
Convert submission details for the gradebook.

return: array
param: stdClass $submission

gradebook_item_update($submission=null, $grade=null)   X-Ref
Update grades in the gradebook.

return: bool
param: mixed $submission stdClass|null
param: mixed $grade stdClass|null

update_team_submission(stdClass $submission, $userid, $updatetime)   X-Ref
Update team submission.

return: bool
param: stdClass $submission
param: int $userid
param: bool $updatetime

update_submission(stdClass $submission, $userid, $updatetime, $teamsubmission)   X-Ref
Update grades in the gradebook based on submission time.

return: bool
param: stdClass $submission
param: int $userid
param: bool $updatetime
param: bool $teamsubmission

submissions_open($userid = 0,$skipenrolled = false,$submission = false,$flags = false,$gradinginfo = false)   X-Ref
Is this assignment open for submissions?

Check the due date,
prevent late submissions,
has this person already submitted,
is the assignment locked?

return: bool
param: int $userid - Optional userid so we can see if a different user can submit
param: bool $skipenrolled - Skip enrollment checks (because they have been done already)
param: stdClass $submission - Pre-fetched submission record (or false to fetch it)
param: stdClass $flags - Pre-fetched user flags record (or false to fetch it)
param: stdClass $gradinginfo - Pre-fetched user gradinginfo record (or false to fetch it)

render_area_files($component, $area, $submissionid)   X-Ref
Render the files in file area.

return: string
param: string $component
param: string $area
param: int $submissionid

can_edit_submission($userid, $graderid = 0)   X-Ref
Capability check to make sure this grader can edit this submission.

return: bool
param: int $userid - The user whose submission is to be edited
param: int $graderid (optional) - The user who will do the editing (default to $USER->id).

get_shared_group_members($cm, $userid)   X-Ref
Returns IDs of the users who share group membership with the specified user.

return: array An array of ID of users.
param: stdClass|cm_info $cm Course-module
param: int $userid User ID

get_graders($userid)   X-Ref
Returns a list of teachers that should be grading given submission.

return: array
param: int $userid The submission to grade

get_notifiable_users($userid)   X-Ref
Returns a list of users that should receive notification about given submission.

return: array
param: int $userid The submission to grade

format_notification_message_text($messagetype,$info,$course,$context,$modulename,$assignmentname)   X-Ref
Format a notification for plain text.

param: string $messagetype
param: stdClass $info
param: stdClass $course
param: stdClass $context
param: string $modulename
param: string $assignmentname

format_notification_message_html($messagetype,$info,$course,$context,$modulename,$coursemodule,$assignmentname)   X-Ref
Format a notification for HTML.

param: string $messagetype
param: stdClass $info
param: stdClass $course
param: stdClass $context
param: string $modulename
param: stdClass $coursemodule
param: string $assignmentname

send_assignment_notification($userfrom,$userto,$messagetype,$eventtype,$updatetime,$coursemodule,$context,$course,$modulename,$assignmentname,$blindmarking,$uniqueidforuser)   X-Ref
Message someone about something (static so it can be called from cron).

return: void
param: stdClass $userfrom
param: stdClass $userto
param: string $messagetype
param: string $eventtype
param: int $updatetime
param: stdClass $coursemodule
param: stdClass $context
param: stdClass $course
param: string $modulename
param: string $assignmentname
param: bool $blindmarking
param: int $uniqueidforuser

send_notification($userfrom, $userto, $messagetype, $eventtype, $updatetime)   X-Ref
Message someone about something.

return: void
param: stdClass $userfrom
param: stdClass $userto
param: string $messagetype
param: string $eventtype
param: int $updatetime

notify_student_submission_copied(stdClass $submission)   X-Ref
Notify student upon successful submission copy.

return: void
param: stdClass $submission

notify_student_submission_receipt(stdClass $submission)   X-Ref
Notify student upon successful submission.

return: void
param: stdClass $submission

notify_graders(stdClass $submission)   X-Ref
Send notifications to graders upon student submissions.

return: void
param: stdClass $submission

submit_for_grading($data, $notices)   X-Ref
Submit a submission for grading.

return: bool Return false if the submission was not submitted.
param: stdClass $data - The form data
param: array $notices - List of error messages to display on an error condition.

process_submit_other_for_grading($mform, $notices)   X-Ref
A students submission is submitted for grading by a teacher.

return: bool

process_submit_for_grading($mform, $notices)   X-Ref
Assignment submission is processed before grading.

return: bool Return false if the validation fails. This affects which page is displayed next.
param: moodleform|null $mform If validation failed when submitting this form - this is the moodleform.

save_user_extension($userid, $extensionduedate)   X-Ref
Save the extension date for a single user.

return: boolean
param: int $userid The user id
param: mixed $extensionduedate Either an integer date or null

process_save_extension(& $mform)   X-Ref
Save extension date.

return: boolean
param: moodleform $mform The submitted form

process_save_quick_grades()   X-Ref
Save quick grades.

return: string The result of the save operation

reveal_identities()   X-Ref
Reveal student identities to markers (and the gradebook).

return: void

process_reveal_identities()   X-Ref
Reveal student identities to markers (and the gradebook).

return: void

process_save_grading_options()   X-Ref
Save grading options.

return: void

format_grade_for_log(stdClass $grade)   X-Ref
Take a grade object and print a short summary for the log file.
The size limit for the log file is 255 characters, so be careful not
to include too much information.

return: string
param: stdClass $grade

format_submission_for_log(stdClass $submission)   X-Ref
Take a submission object and print a short summary for the log file.
The size limit for the log file is 255 characters, so be careful not
to include too much information.

return: string
param: stdClass $submission

process_copy_previous_attempt(&$notices)   X-Ref
Require a valid sess key and then call copy_previous_attempt.

return: bool
param: array $notices Any error messages that should be shown

copy_previous_attempt(&$notices)   X-Ref
Copy the current assignment submission from the last submitted attempt.

return: bool
param: array $notices Any error messages that should be shown

submission_empty($submission)   X-Ref
Determine if the current submission is empty or not.

return: bool
param: submission $submission the students submission record to check.

new_submission_empty($data)   X-Ref
Determine if a new submission is empty or not

return: bool
param: stdClass $data Submission data

save_submission(stdClass $data, & $notices)   X-Ref
Save assignment submission for the current user.

return: bool
param: stdClass $data
param: array $notices Any error messages that should be shown

process_save_submission(&$mform, &$notices)   X-Ref
Save assignment submission.

return: bool
param: moodleform $mform
param: array $notices Any error messages that should be shown

grading_disabled($userid, $checkworkflow = true, $gradinginfo = null)   X-Ref
Determine if this users grade can be edited.

return: bool $gradingdisabled
param: int $userid - The student userid
param: bool $checkworkflow - whether to include a check for the workflow state.
param: stdClass $gradinginfo - optional, allow gradinginfo to be passed for performance.

get_grading_instance($userid, $grade, $gradingdisabled)   X-Ref
Get an instance of a grading form if advanced grading is enabled.
This is specific to the assignment, marker and student.

return: mixed gradingform_instance|null $gradinginstance
param: int $userid - The student userid
param: stdClass|false $grade - The grade record
param: bool $gradingdisabled

add_grade_form_elements(MoodleQuickForm $mform, stdClass $data, $params)   X-Ref
Add elements to grade form.

return: void
param: MoodleQuickForm $mform
param: stdClass $data
param: array $params

add_plugin_submission_elements($submission,MoodleQuickForm $mform,stdClass $data,$userid)   X-Ref
Add elements in submission plugin form.

return: void
param: mixed $submission stdClass|null
param: MoodleQuickForm $mform
param: stdClass $data
param: int $userid The current userid (same as $USER->id)

is_any_feedback_plugin_enabled()   X-Ref
Check if feedback plugins installed are enabled.

return: bool

is_any_submission_plugin_enabled()   X-Ref
Check if submission plugins installed are enabled.

return: bool

add_submission_form_elements(MoodleQuickForm $mform, stdClass $data)   X-Ref
Add elements to submission form.

return: void
param: MoodleQuickForm $mform
param: stdClass $data

remove_submission($userid)   X-Ref
Remove any data from the current submission.

return: boolean
param: int $userid

revert_to_draft($userid)   X-Ref
Revert to draft.

return: boolean
param: int $userid

process_remove_submission($userid = 0)   X-Ref
Remove the current submission.

return: boolean
param: int $userid

process_revert_to_draft($userid = 0)   X-Ref
Revert to draft.
Uses url parameter userid if userid not supplied as a parameter.

return: boolean
param: int $userid

lock_submission($userid)   X-Ref
Prevent student updates to this submission

return: bool
param: int $userid

process_set_batch_marking_workflow_state()   X-Ref
Set the workflow state for multiple users

return: void

process_set_batch_marking_allocation()   X-Ref
Set the marking allocation for multiple users

return: void

process_lock_submission($userid = 0)   X-Ref
Prevent student updates to this submission.
Uses url parameter userid.

return: void
param: int $userid

unlock_submission($userid)   X-Ref
Unlock the student submission.

return: bool
param: int $userid

process_unlock_submission($userid = 0)   X-Ref
Unlock the student submission.
Uses url parameter userid.

return: bool
param: int $userid

apply_grade_to_user($formdata, $userid, $attemptnumber)   X-Ref
Apply a grade from a grading form to a user (may be called multiple times for a group submission).

return: void
param: stdClass $formdata - the data from the form
param: int $userid - the user to apply the grade to
param: int $attemptnumber - The attempt number to apply the grade to.

process_outcomes($userid, $formdata, $sourceuserid = null)   X-Ref
Save outcomes submitted from grading form.

param: int $userid
param: stdClass $formdata
param: int $sourceuserid The user ID under which the outcome data is accessible. This is relevant

reopen_submission_if_required($userid, $submission, $addattempt)   X-Ref
If the requirements are met - reopen the submission for another attempt.
Only call this function when grading the latest attempt.

return: bool - true if another attempt was added.
param: int $userid The userid.
param: stdClass $submission The submission (may be a group submission).
param: bool $addattempt - True if the "allow another attempt" checkbox was checked.

save_grade($userid, $data)   X-Ref
Save grade update.

return: bool - was the grade saved
param: int $userid
param: stdClass $data

process_save_grade(&$mform)   X-Ref
Save grade.

return: bool - was the grade saved
param: moodleform $mform

can_upgrade_assignment($type, $version)   X-Ref
This function is a static wrapper around can_upgrade.

return: bool
param: string $type The plugin type
param: int $version The plugin version

can_upgrade($type, $version)   X-Ref
This function returns true if it can upgrade an assignment from the 2.2 module.

return: bool
param: string $type The plugin type
param: int $version The plugin version

copy_area_files_for_upgrade($oldcontextid,$oldcomponent,$oldfilearea,$olditemid,$newcontextid,$newcomponent,$newfilearea,$newitemid)   X-Ref
Copy all the files from the old assignment files area to the new one.
This is used by the plugin upgrade code.

return: int The number of files copied
param: int $oldcontextid The old assignment context id
param: int $oldcomponent The old assignment component ('assignment')
param: int $oldfilearea The old assignment filearea ('submissions')
param: int $olditemid The old submissionid (can be null e.g. intro)
param: int $newcontextid The new assignment context id
param: int $newcomponent The new assignment component ('assignment')
param: int $newfilearea The new assignment filearea ('submissions')
param: int $newitemid The new submissionid (can be null e.g. intro)

process_add_attempt_group($useridlist)   X-Ref
Add a new attempt for each user in the list - but reopen each group assignment
at most 1 time.

return: bool
param: array $useridlist Array of userids to reopen.

process_add_attempt($userid)   X-Ref
Check for a sess key and then call add_attempt.

return: bool - true if successful.
param: int $userid int The user to add the attempt for

add_attempt($userid)   X-Ref
Add a new attempt for a user.

return: bool - true if successful.
param: int $userid int The user to add the attempt for

get_user_grades_for_gradebook($userid)   X-Ref
Get an upto date list of user grades and feedback for the gradebook.

return: array of grade data formated for the gradebook api
param: int $userid int or 0 for all users

get_uniqueid_for_user($userid)   X-Ref
Call the static version of this function

return: int The unique id
param: int $userid The userid to lookup

allocate_unique_ids($assignid)   X-Ref
Foreach participant in the course - assign them a random id.

param: int $assignid The assignid to lookup

get_uniqueid_for_user_static($assignid, $userid)   X-Ref
Lookup this user id and return the unique id for this assignment.

return: int The unique id
param: int $assignid The assignment id
param: int $userid The userid to lookup

get_user_id_for_uniqueid($uniqueid)   X-Ref
Call the static version of this function.

return: int The user id or false if they don't exist
param: int $uniqueid The uniqueid to lookup

get_user_id_for_uniqueid_static($assignid, $uniqueid)   X-Ref
Lookup this unique id and return the user id for this assignment.

return: int The user id or false if they don't exist
param: int $assignid The id of the assignment this user mapping is in
param: int $uniqueid The uniqueid to lookup

get_marking_workflow_states_for_current_user()   X-Ref
Get the list of marking_workflow states the current user has permission to transition a grade to.

return: array of state => description

show_only_active_users()   X-Ref
Check is only active users in course should be shown.

return: bool true if only active users should be shown.

is_active_user($userid)   X-Ref
Return true is user is active user in course else false

return: bool true is user is active in course.
param: int $userid

is_gradebook_feedback_enabled()   X-Ref
Returns true if gradebook feedback plugin is enabled

return: bool true if gradebook feedback plugin is enabled and visible else false.

get_grading_status($userid)   X-Ref
Returns the grading status.

return: string returns the grading status
param: int $userid the user id

get_useridlist_key_id()   X-Ref
The id used to uniquily identify the cache for this instance of the assign object.

return: string

get_useridlist_key($id = null)   X-Ref
Generates the key that should be used for an entry in the useridlist cache.

return: string The key for the id, or new entry if no $id is passed.
param: string $id Generate a key for this instance (optional)

update_activity_completion_records($teamsubmission,$requireallteammemberssubmit,$submission,$userid,$complete,$completion)   X-Ref
Updates and creates the completion records in mdl_course_modules_completion.

return: null
param: int $teamsubmission value of 0 or 1 to indicate whether this is a group activity
param: int $requireallteammemberssubmit value of 0 or 1 to indicate whether all group members must click Submit
param: obj $submission the submission
param: int $userid the user id
param: int $complete
param: obj $completion

set_module_viewed()   X-Ref
Update the module completion status (set it viewed) and trigger module viewed event.


add_grade_notices()   X-Ref
Checks for any grade notices, and adds notifications. Will display on assignment main page and grading table.

return: void The notifications API will render the notifications at the appropriate part of the page.

fix_null_grades()   X-Ref
View fix rescaled null grades.

return: bool True if null all grades are now fixed.

view_fix_rescaled_null_grades()   X-Ref
View fix rescaled null grades.

return: void The notifications API will render the notifications at the appropriate part of the page.

set_most_recent_team_submission($submission)   X-Ref
Set the most recent submission for the team.
The most recent team submission is used to determine if another attempt should be created when allowing another
attempt on a group assignment, and whether the gradebook should be updated.

param: stdClass $submission The most recent submission of the group.

get_marking_allocation_filters($export = false)   X-Ref
Return array of valid grading allocation filters for the grading interface.

return: array
param: boolean $export Export the list of filters for a template.

get_marking_workflow_filters($export = false)   X-Ref
Return array of valid grading workflow filters for the grading interface.

return: array
param: boolean $export Export the list of filters for a template.

get_filters()   X-Ref
Return array of valid search filters for the grading interface.

return: array

get_submissionstatement($adminconfig, $instance, $context)   X-Ref
Get the correct submission statement depending on single submisison, team submission or team submission
where all team memebers must submit.

return: string
param: array $adminconfig
param: assign $instance
param: context $context

is_time_limit_enabled(?int $userid = null)   X-Ref
Check if time limit for assignment enabled and set up.

return: bool
param: int|null $userid User ID. If null, use global user.

is_attempt_in_progress(?int $userid = null, int $groupid = 0, int $attemptnumber = -1)   X-Ref
Check if an assignment submission is already started and not yet submitted.

return: bool
param: int|null $userid User ID. If null, use global user.
param: int $groupid Group ID. If 0, use user id to determine group.
param: int $attemptnumber Attempt number. If -1, check latest submission.

Class: assign_portfolio_caller  - X-Ref

Portfolio caller class for mod_assign.

expected_callbackargs()   X-Ref
Callback arg for a single file export.


__construct($callbackargs)   X-Ref
The constructor.

param: array $callbackargs

load_data()   X-Ref
Load data needed for the portfolio export.

If the assignment type implements portfolio_load_data(), the processing is delegated
to it. Otherwise, the caller must provide either fileid (to export single file) or
submissionid and filearea (to export all data attached to the given submission file area)
via callback arguments.


prepare_package()   X-Ref
Prepares the package up before control is passed to the portfolio plugin.

return: mixed

get_submission_plugin()   X-Ref
Fetch the plugin by its type.

return: assign_submission_plugin

get_sha1()   X-Ref
Calculate a sha1 has of either a single file or a list
of files based on the data set by load_data.

return: string

expected_time()   X-Ref
Calculate the time to transfer either a single file or a list
of files based on the data set by load_data.

return: int

check_permissions()   X-Ref
Checking the permissions.

return: bool

display_name()   X-Ref
Display a module name.

return: string

base_supported_formats()   X-Ref
Return array of formats supported by this portfolio call back.

return: array

assign_process_group_deleted_in_course($courseid, $groupid = null)   X-Ref
Logic to happen when a/some group(s) has/have been deleted in a course.

return: void
param: int $courseid The course ID.
param: int $groupid The group id if it is known

move_group_override($id, $move, $assignid)   X-Ref
Change the sort order of an override

return: bool success of operation
param: int $id of the override
param: string $move direction of move
param: int $assignid of the assignment

reorder_group_overrides($assignid)   X-Ref
Reorder the overrides starting at the override at the given startorder.

param: int $assignid of the assigment

assign_get_js_module()   X-Ref
Get the information about the standard assign JavaScript module.

return: array a standard jsmodule structure.