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.
/mod/choice/ -> lib.php (source)

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]

(no description)

Copyright: 1999 onwards Martin Dougiamas {@link http://moodle.com}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1372 lines (48 kb)
Included or required: 3 times
Referenced: 4 times
Includes or requires: 1 file
 mod/choice/deprecatedlib.php

Defines 38 functions


Functions that are not part of a class:

choice_user_outline($course, $user, $mod, $choice)   X-Ref

return: object|null
param: object $course
param: object $user
param: object $mod
param: object $choice

choice_user_complete($course, $user, $mod, $choice)   X-Ref
Callback for the "Complete" report - prints the activity summary for the given user

param: object $course
param: object $user
param: object $mod
param: object $choice

choice_add_instance($choice)   X-Ref
Given an object containing all the necessary data,
(defined by the form in mod_form.php) this function
will create a new instance and return the id number
of the new instance.

return: int
param: object $choice

choice_update_instance($choice)   X-Ref
Given an object containing all the necessary data,
(defined by the form in mod_form.php) this function
will update an existing instance with new data.

return: bool
param: object $choice

choice_prepare_options($choice, $user, $coursemodule, $allresponses)   X-Ref

return: array
param: object $choice
param: object $user
param: object $coursemodule
param: array $allresponses

choice_modify_responses($userids, $answerids, $newoptionid, $choice, $cm, $course)   X-Ref
Modifies responses of other users adding the option $newoptionid to them

param: array $userids list of users to add option to (must be users without any answers yet)
param: array $answerids list of existing attempt ids of users (will be either appended or
param: int $newoptionid
param: stdClass $choice choice object, result of {@link choice_get_choice()}
param: stdClass $cm
param: stdClass $course

choice_user_submit_response($formanswer, $choice, $userid, $course, $cm)   X-Ref
Process user submitted answers for a choice,
and either updating them or saving new answers.

return: void
param: int|array $formanswer the id(s) of the user submitted choice options.
param: object $choice the selected choice.
param: int $userid user identifier.
param: object $course current course.
param: object $cm course context.

choice_show_reportlink($user, $cm)   X-Ref

return: void Output is echo'd
param: array $user
param: object $cm

prepare_choice_show_results($choice, $course, $cm, $allresponses)   X-Ref

return: object
param: object $choice
param: object $course
param: object $coursemodule
param: array $allresponses

choice_delete_responses($attemptids, $choice, $cm, $course)   X-Ref

return: bool
param: array $attemptids
param: object $choice Choice main table row
param: object $cm Course-module object
param: object $course Course object

choice_delete_instance($id)   X-Ref
Given an ID of an instance of this module,
this function will permanently delete the instance
and any data that depends on it.

return: bool
param: int $id

choice_get_option_text($choice, $id)   X-Ref
Returns text string which is the answer that matches the id

return: string
param: object $choice
param: int $id

choice_get_choice($choiceid)   X-Ref
Gets a full choice record

return: object|bool The choice or false
param: int $choiceid

choice_get_view_actions()   X-Ref
List the actions that correspond to a view of this module.
This is used by the participation report.

Note: This is not used by new logging system. Event with
crud = 'r' and edulevel = LEVEL_PARTICIPATING will
be considered as view action.

return: array

choice_get_post_actions()   X-Ref
List the actions that correspond to a post of this module.
This is used by the participation report.

Note: This is not used by new logging system. Event with
crud = ('c' || 'u' || 'd') and edulevel = LEVEL_PARTICIPATING
will be considered as post action.

return: array

choice_reset_course_form_definition(&$mform)   X-Ref
Implementation of the function for printing the form elements that control
whether the course reset functionality affects the choice.

param: object $mform form passed by reference

choice_reset_course_form_defaults($course)   X-Ref
Course reset form defaults.

return: array

choice_reset_userdata($data)   X-Ref
Actual implementation of the reset course functionality, delete all the
choice responses for course $data->courseid.

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

choice_get_response_data($choice, $cm, $groupmode, $onlyactive)   X-Ref

return: array
param: object $choice
param: object $cm
param: int $groupmode
param: bool $onlyactive Whether to get response data for active users only.

choice_supports($feature)   X-Ref

return: mixed True if module supports feature, false if not, null if doesn't know or string for the module purpose.
param: string $feature FEATURE_xx constant for requested feature

choice_extend_settings_navigation(settings_navigation $settings, navigation_node $choicenode)   X-Ref
Adds module specific settings to the settings block

param: settings_navigation $settings The settings navigation object
param: navigation_node $choicenode The node to add module settings to

choice_page_type_list($pagetype, $parentcontext, $currentcontext)   X-Ref
Return a list of page types

param: string $pagetype current page type
param: stdClass $parentcontext Block's parent context
param: stdClass $currentcontext Current context of block

choice_print_overview()   X-Ref


choice_get_user_response($choice, $userid)   X-Ref
Get responses of a given user on a given choice.

return: array of choice answers records
param: stdClass $choice Choice record
param: int $userid User id

choice_get_my_response($choice)   X-Ref
Get my responses on a given choice.

return: array of choice answers records
param: stdClass $choice Choice record

choice_get_all_responses($choice)   X-Ref
Get all the responses on a given choice.

return: array of choice answers records
param: stdClass $choice Choice record

choice_can_view_results($choice, $current = null, $choiceopen = null)   X-Ref
Return true if we are allowd to view the choice results.

return: bool true if we can view the results, false otherwise.
param: stdClass $choice Choice record
param: rows|null $current my choice responses
param: bool|null $choiceopen if the choice is open

choice_view($choice, $course, $cm, $context)   X-Ref
Mark the activity completed (if required) and trigger the course_module_viewed event.

param: stdClass $choice     choice object
param: stdClass $course     course object
param: stdClass $cm         course module object
param: stdClass $context    context object

choice_get_availability_status($choice)   X-Ref
Check if a choice is available for the current user.

return: array                       status (available or not and possible warnings)
param: stdClass  $choice            choice record

choice_refresh_events($courseid = 0, $instance = null, $cm = null)   X-Ref
This standard function will check all instances of this module
and make sure there are up-to-date events created for each of them.
If courseid = 0, then every choice event in the site is checked, else
only choice events belonging to the course specified are checked.
This function is used, in its new format, by restore_refresh_events()

return: bool
param: int $courseid
param: int|stdClass $instance Choice module instance or ID.
param: int|stdClass $cm Course module object or ID (not used in this module).

choice_check_updates_since(cm_info $cm, $from, $filter = array()   X-Ref
Check if the module has any update that affects the current user since a given time.

return: stdClass an object with the different type of areas indicating if they were updated or not
param: cm_info $cm course module data
param: int $from the time to check updates from
param: array $filter  if we need to check only specific updates

mod_choice_core_calendar_provide_event_action(calendar_event $event,\core_calendar\action_factory $factory,int $userid = 0)   X-Ref
This function receives a calendar event and returns the action associated with it, or null if there is none.

This is used by block_myoverview in order to display the event appropriately. If null is returned then the event
is not displayed on the block.

return: \core_calendar\local\event\entities\action_interface|null
param: calendar_event $event
param: \core_calendar\action_factory $factory
param: int $userid User id to use for all capability checks, etc. Set to 0 for current user (default).

mod_choice_core_calendar_get_valid_event_timestart_range(\calendar_event $event, \stdClass $choice)   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 date must be after this date'],
[1506741172, 'The date must be before this date']
]

param: calendar_event $event The calendar event to get the time range for
param: stdClass $choice The module instance to get the range from

mod_choice_core_calendar_event_timestart_updated(\calendar_event $event, \stdClass $choice)   X-Ref
This function will update the choice module according to the
event that has been modified.

It will set the timeopen or timeclose value of the choice instance
according to the type of event provided.

param: \calendar_event $event
param: stdClass $choice The module instance to get the range from

mod_choice_get_fontawesome_icon_map()   X-Ref
Get icon mapping for font-awesome.


choice_get_coursemodule_info($coursemodule)   X-Ref
Add a get_coursemodule_info function in case any choice type wants to add 'extra' information
for the course (see resource).

Given a course_module object, this function returns any "extra" information that may be needed
when printing this activity in a course listing.  See get_array_of_activities() in course/lib.php.

return: cached_cm_info An object on information that the courses
param: stdClass $coursemodule The coursemodule object (record).

mod_choice_get_completion_active_rule_descriptions($cm)   X-Ref
Callback which returns human-readable strings describing the active completion custom rules for the module instance.

return: array $descriptions the array of descriptions for the custom rules.
param: cm_info|stdClass $cm object with fields ->completion and ->customdata['customcompletionrules']

mod_choice_core_calendar_get_event_action_string(string $eventtype)   X-Ref
Callback to fetch the activity event type lang string.

return: lang_string The event type lang string.
param: string $eventtype The event type.