Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
mod_choice

Namespaces

namespace  mod_choice
  
 
namespace  mod_choice\analytics\indicator
  
 
namespace  mod_choice\completion
  
 
namespace  mod_choice\event
  
 
namespace  mod_choice\privacy
  
 
namespace  mod_choice\search
  
 

Classes

class  backup_choice_activity_structure_step
 Define all the backup steps that will be used by the backup_choice_activity_task. More...
 
class  backup_choice_activity_task
 Provides the steps to perform one complete backup of the Choice instance. More...
 
class  behat_mod_choice
 Choice activity definitions. More...
 
class  mod_choice\analytics\indicator\activity_base
 Activity base class. More...
 
class  mod_choice\analytics\indicator\cognitive_depth
 Cognitive depth indicator - choice. More...
 
class  mod_choice\analytics\indicator\social_breadth
 Social breadth indicator - choice. More...
 
class  mod_choice\completion\custom_completion
 
class  mod_choice\dates
 Class for fetching the important dates in mod_choice for a given module instance and a user. More...
 
class  mod_choice\event\answer_created
 
class  mod_choice\event\answer_deleted
 
class  mod_choice\event\course_module_instance_list_viewed
 The mod_choice instance list viewed event class. More...
 
class  mod_choice\event\course_module_viewed
 The mod_choice course module viewed event class. More...
 
class  mod_choice\event\report_viewed
 
class  mod_choice\privacy\provider
 Implementation of the privacy subsystem plugin provider for the choice activity module. More...
 
class  mod_choice\search\activity
 Search area for mod_choice activities. More...
 
class  mod_choice_external
 Choice module external functions. More...
 
class  mod_choice_generator
 mod_choice data generator class. More...
 
class  mod_choice_renderer
 
class  moodle1_mod_choice_handler
 Choice conversion handler. More...
 
class  restore_choice_activity_structure_step
 Define all the restore steps that will be used by the restore_choice_activity_task. More...
 
class  restore_choice_activity_task
 choice restore task that provides all the settings and steps to perform one complete restore of the activity More...
 

Functions

object choice_add_instance ($choice)
 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.
 
 choice_can_view_results ($choice, $current=null, $choiceopen=null)
 Return true if we are allowd to view the choice results.
 
 choice_check_updates_since (cm_info $cm, $from, $filter=array())
 Check if the module has any update that affects the current user since a given time.
 
object choice_delete_instance ($id)
 Given an ID of an instance of this module, this function will permanently delete the instance and any data that depends on it.
 
object choice_delete_responses ($attemptids, $choice, $cm, $course)
 
 choice_extend_settings_navigation (settings_navigation $settings, navigation_node $choicenode)
 Adds module specific settings to the settings block.
 
 choice_get_all_responses ($choice)
 Get all the responses on a given choice.
 
 choice_get_availability_status ($choice)
 Check if a choice is available for the current user.
 
object choice_get_choice ($choiceid)
 Gets a full choice record.
 
 choice_get_completion_state ()
 
 choice_get_coursemodule_info ($coursemodule)
 Add a get_coursemodule_info function in case any choice type wants to add 'extra' information for the course (see resource).
 
 choice_get_my_response ($choice)
 Get my responses on a given choice.
 
object choice_get_option_text ($choice, $id)
 Returns text string which is the answer that matches the id.
 
 choice_get_post_actions ()
 List the actions that correspond to a post of this module.
 
object choice_get_response_data ($choice, $cm, $groupmode, $onlyactive)
 @global object @global object @uses CONTEXT_MODULE
 
 choice_get_user_response ($choice, $userid)
 Get responses of a given user on a given choice.
 
 choice_get_view_actions ()
 List the actions that correspond to a view of this module.
 
 choice_modify_responses ($userids, $answerids, $newoptionid, $choice, $cm, $course)
 Modifies responses of other users adding the option $newoptionid to them.
 
 choice_page_type_list ($pagetype, $parentcontext, $currentcontext)
 Return a list of page types.
 
object choice_prepare_options ($choice, $user, $coursemodule, $allresponses)
 
 choice_print_overview ()
 
 choice_refresh_events ($courseid=0, $instance=null, $cm=null)
 This standard function will check all instances of this module and make sure there are up-to-date events created for each of them.
 
 choice_reset_course_form_defaults ($course)
 Course reset form defaults.
 
 choice_reset_course_form_definition (&$mform)
 Implementation of the function for printing the form elements that control whether the course reset functionality affects the choice.
 
object choice_reset_userdata ($data)
 Actual implementation of the reset course functionality, delete all the choice responses for course $data->courseid.
 
 choice_set_events ($choice)
 This creates new calendar events given as timeopen and timeclose by $choice.
 
 choice_show_reportlink ($user, $cm)
 
 choice_supports ($feature)
 @uses FEATURE_GROUPS @uses FEATURE_GROUPINGS @uses FEATURE_MOD_INTRO @uses FEATURE_COMPLETION_TRACKS_VIEWS @uses FEATURE_GRADE_HAS_GRADE @uses FEATURE_GRADE_OUTCOMES
 
object choice_update_instance ($choice)
 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.
 
 choice_user_complete ($course, $user, $mod, $choice)
 Callback for the "Complete" report - prints the activity summary for the given user.
 
object choice_user_outline ($course, $user, $mod, $choice)
 Standard functions /////////////////////////////////////////////////////////.
 
 choice_user_submit_response ($formanswer, $choice, $userid, $course, $cm)
 Process user submitted answers for a choice, and either updating them or saving new answers.
 
 choice_view ($choice, $course, $cm, $context)
 Mark the activity completed (if required) and trigger the course_module_viewed event.
 
 mod_choice_core_calendar_event_timestart_updated (\calendar_event $event, stdClass $choice)
 This function will update the choice module according to the event that has been modified.
 
 mod_choice_core_calendar_get_event_action_string (string $eventtype)
 Callback to fetch the activity event type lang string.
 
 mod_choice_core_calendar_get_valid_event_timestart_range (\calendar_event $event, stdClass $choice)
 This function calculates the minimum and maximum cutoff values for the timestart of the given event.
 
 mod_choice_core_calendar_provide_event_action (calendar_event $event, core_calendar\action_factory $factory, int $userid=0)
 This function receives a calendar event and returns the action associated with it, or null if there is none.
 
 mod_choice_get_completion_active_rule_descriptions ($cm)
 Callback which returns human-readable strings describing the active completion custom rules for the module instance.
 
 mod_choice_get_fontawesome_icon_map ()
 Get icon mapping for font-awesome.
 
object prepare_choice_show_results ($choice, $course, $cm, $allresponses)
 
 xmldb_choice_upgrade ($oldversion)
 

Variables

 $capabilities
 
global int $CHOICE_COLUMN_HEIGHT = 300
 $CHOICE_COLUMN_HEIGHT
 
global int $CHOICE_COLUMN_WIDTH = 300
 $CHOICE_COLUMN_WIDTH
 
global array $CHOICE_DISPLAY
 $CHOICE_DISPLAY
 
global array $CHOICE_PUBLISH
 $CHOICE_PUBLISH
 
global array $CHOICE_SHOWRESULTS
 $CHOICE_SHOWRESULTS
 
 $functions
 
 $logs
 
 $plugin = 2024041600
 
const CHOICE_DISPLAY_HORIZONTAL '0'
 
const CHOICE_DISPLAY_VERTICAL '1'
 
const CHOICE_EVENT_TYPE_CLOSE 'close'
 
const CHOICE_EVENT_TYPE_OPEN 'open'
 
const CHOICE_PUBLISH_ANONYMOUS '0'
 
const CHOICE_PUBLISH_NAMES '1'
 
const CHOICE_SHOWRESULTS_AFTER_ANSWER '1'
 
const CHOICE_SHOWRESULTS_AFTER_CLOSE '2'
 
const CHOICE_SHOWRESULTS_ALWAYS '3'
 
const CHOICE_SHOWRESULTS_NOT '0'
 
$plugin component = 'mod_choice'
 
$plugin cron = 0
 
$plugin version = 2024042200
 

Detailed Description

Function Documentation

◆ choice_add_instance()

object choice_add_instance ( $choice)

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.

Parameters
object$choice
Return values
int

◆ choice_can_view_results()

choice_can_view_results ( $choice,
$current = null,
$choiceopen = null )

Return true if we are allowd to view the choice results.

Parameters
stdClass$choiceChoice record
rows | null$currentmy choice responses
bool | null$choiceopenif the choice is open
Return values
booltrue if we can view the results, false otherwise.
Since
Moodle 3.0

◆ choice_check_updates_since()

choice_check_updates_since ( cm_info $cm,
$from,
$filter = array() )

Check if the module has any update that affects the current user since a given time.

Parameters
cm_info$cmcourse module data
int$fromthe time to check updates from
array$filterif we need to check only specific updates
Return values
stdClassan object with the different type of areas indicating if they were updated or not
Since
Moodle 3.2

◆ choice_delete_instance()

object choice_delete_instance ( $id)

Given an ID of an instance of this module, this function will permanently delete the instance and any data that depends on it.

Parameters
int$id
Return values
bool

◆ choice_delete_responses()

object choice_delete_responses ( $attemptids,
$choice,
$cm,
$course )
Parameters
array$attemptids
object$choiceChoice main table row
object$cmCourse-module object
object$courseCourse object
Return values
bool

◆ choice_extend_settings_navigation()

choice_extend_settings_navigation ( settings_navigation $settings,
navigation_node $choicenode )

Adds module specific settings to the settings block.

Parameters
settings_navigation$settingsThe settings navigation object
navigation_node$choicenodeThe node to add module settings to

◆ choice_get_all_responses()

choice_get_all_responses ( $choice)

Get all the responses on a given choice.

Parameters
stdClass$choiceChoice record
Return values
arrayof choice answers records
Since
Moodle 3.0

◆ choice_get_availability_status()

choice_get_availability_status ( $choice)

Check if a choice is available for the current user.

Parameters
stdClass$choicechoice record
Return values
arraystatus (available or not and possible warnings)

◆ choice_get_choice()

object choice_get_choice ( $choiceid)

Gets a full choice record.

Parameters
int$choiceid
Return values
object|boolThe choice or false

◆ choice_get_completion_state()

choice_get_completion_state ( )
Deprecated
since Moodle 3.11

◆ choice_get_coursemodule_info()

choice_get_coursemodule_info ( $coursemodule)

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.

Parameters
stdClass$coursemoduleThe coursemodule object (record).
Return values
cached_cm_infoAn object on information that the courses will know about (most noticeably, an icon).

◆ choice_get_my_response()

choice_get_my_response ( $choice)

Get my responses on a given choice.

Parameters
stdClass$choiceChoice record
Return values
arrayof choice answers records
Since
Moodle 3.0

◆ choice_get_option_text()

object choice_get_option_text ( $choice,
$id )

Returns text string which is the answer that matches the id.

Parameters
object$choice
int$id
Return values
string

◆ choice_get_post_actions()

choice_get_post_actions ( )

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 values
array

◆ choice_get_response_data()

object choice_get_response_data ( $choice,
$cm,
$groupmode,
$onlyactive )

@global object @global object @uses CONTEXT_MODULE

Parameters
object$choice
object$cm
int$groupmode
bool$onlyactiveWhether to get response data for active users only.
Return values
array

◆ choice_get_user_response()

choice_get_user_response ( $choice,
$userid )

Get responses of a given user on a given choice.

Parameters
stdClass$choiceChoice record
int$useridUser id
Return values
arrayof choice answers records
Since
Moodle 3.6

◆ choice_get_view_actions()

choice_get_view_actions ( )

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 values
array

◆ choice_modify_responses()

choice_modify_responses ( $userids,
$answerids,
$newoptionid,
$choice,
$cm,
$course )

Modifies responses of other users adding the option $newoptionid to them.

Parameters
array$useridslist of users to add option to (must be users without any answers yet)
array$answeridslist of existing attempt ids of users (will be either appended or substituted with the newoptionid, depending on $choice->allowmultiple)
int$newoptionid
stdClass$choicechoice object, result of choice_get_choice()
stdClass$cm
stdClass$course

◆ choice_page_type_list()

choice_page_type_list ( $pagetype,
$parentcontext,
$currentcontext )

Return a list of page types.

Parameters
string$pagetypecurrent page type
stdClass$parentcontextBlock's parent context
stdClass$currentcontextCurrent context of block

◆ choice_prepare_options()

object choice_prepare_options ( $choice,
$user,
$coursemodule,
$allresponses )
Parameters
object$choice
object$user
object$coursemodule
array$allresponses
Return values
array

◆ choice_print_overview()

choice_print_overview ( )
Deprecated
since Moodle 3.3, when the block_course_overview block was removed.

◆ choice_refresh_events()

choice_refresh_events ( $courseid = 0,
$instance = null,
$cm = null )

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()

Parameters
int$courseid
int | stdClass$instanceChoice module instance or ID.
int | stdClass$cmCourse module object or ID (not used in this module).
Return values
bool

◆ choice_reset_course_form_defaults()

choice_reset_course_form_defaults ( $course)

Course reset form defaults.

Return values
array

◆ choice_reset_course_form_definition()

choice_reset_course_form_definition ( & $mform)

Implementation of the function for printing the form elements that control whether the course reset functionality affects the choice.

Parameters
MoodleQuickForm$mformform passed by reference

◆ choice_reset_userdata()

object choice_reset_userdata ( $data)

Actual implementation of the reset course functionality, delete all the choice responses for course $data->courseid.

@global object

Parameters
object$datathe data submitted from the reset course.
Return values
arraystatus array

◆ choice_set_events()

choice_set_events ( $choice)

This creates new calendar events given as timeopen and timeclose by $choice.

Parameters
stdClass$choice
Return values
void

◆ choice_show_reportlink()

choice_show_reportlink ( $user,
$cm )
Parameters
array$user
object$cm
Return values
voidOutput is echo'd

◆ choice_supports()

choice_supports ( $feature)

@uses FEATURE_GROUPS @uses FEATURE_GROUPINGS @uses FEATURE_MOD_INTRO @uses FEATURE_COMPLETION_TRACKS_VIEWS @uses FEATURE_GRADE_HAS_GRADE @uses FEATURE_GRADE_OUTCOMES

Parameters
string$featureFEATURE_xx constant for requested feature
Return values
mixedTrue if module supports feature, false if not, null if doesn't know or string for the module purpose.

◆ choice_update_instance()

object choice_update_instance ( $choice)

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.

Parameters
object$choice
Return values
bool

◆ choice_user_complete()

choice_user_complete ( $course,
$user,
$mod,
$choice )

Callback for the "Complete" report - prints the activity summary for the given user.

Parameters
object$course
object$user
object$mod
object$choice

◆ choice_user_outline()

object choice_user_outline ( $course,
$user,
$mod,
$choice )

Standard functions /////////////////////////////////////////////////////////.

Parameters
object$course
object$user
object$mod
object$choice
Return values
object|null

◆ choice_user_submit_response()

choice_user_submit_response ( $formanswer,
$choice,
$userid,
$course,
$cm )

Process user submitted answers for a choice, and either updating them or saving new answers.

Parameters
int | array$formanswerthe id(s) of the user submitted choice options.
object$choicethe selected choice.
int$useriduser identifier.
object$coursecurrent course.
object$cmcourse context.
Return values
void

◆ choice_view()

choice_view ( $choice,
$course,
$cm,
$context )

Mark the activity completed (if required) and trigger the course_module_viewed event.

Parameters
stdClass$choicechoice object
stdClass$coursecourse object
stdClass$cmcourse module object
stdClass$contextcontext object
Since
Moodle 3.0

◆ mod_choice_core_calendar_event_timestart_updated()

mod_choice_core_calendar_event_timestart_updated ( \calendar_event $event,
stdClass $choice )

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.

Exceptions
moodle_exception
Parameters
calendar_event$event
stdClass$choiceThe module instance to get the range from

◆ mod_choice_core_calendar_get_event_action_string()

mod_choice_core_calendar_get_event_action_string ( string $eventtype)

Callback to fetch the activity event type lang string.

Parameters
string$eventtypeThe event type.
Return values
lang_stringThe event type lang string.

◆ mod_choice_core_calendar_get_valid_event_timestart_range()

mod_choice_core_calendar_get_valid_event_timestart_range ( \calendar_event $event,
stdClass $choice )

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'] ]

Parameters
calendar_event$eventThe calendar event to get the time range for
stdClass$choiceThe module instance to get the range from

◆ mod_choice_core_calendar_provide_event_action()

mod_choice_core_calendar_provide_event_action ( calendar_event $event,
core_calendar\action_factory $factory,
int $userid = 0 )

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.

Parameters
calendar_event$event
core_calendar\action_factory$factory
int$useridUser id to use for all capability checks, etc. Set to 0 for current user (default).
Return values
core_calendar\local\event\entities\action_interface|null

◆ mod_choice_get_completion_active_rule_descriptions()

mod_choice_get_completion_active_rule_descriptions ( $cm)

Callback which returns human-readable strings describing the active completion custom rules for the module instance.

Parameters
cm_info | stdClass$cmobject with fields ->completion and ->customdata['customcompletionrules']
Return values
array\$descriptionsthe array of descriptions for the custom rules.

◆ prepare_choice_show_results()

object prepare_choice_show_results ( $choice,
$course,
$cm,
$allresponses )
Parameters
object$choice
object$course
object$coursemodule
array$allresponses
  • Parameters
    bool$allresponses
    Return values
    object

Variable Documentation

◆ $CHOICE_DISPLAY

$CHOICE_DISPLAY
Initial value:
= array (CHOICE_DISPLAY_HORIZONTAL => get_string('displayhorizontal', 'choice'),
CHOICE_DISPLAY_VERTICAL => get_string('displayvertical','choice'))

$CHOICE_DISPLAY

◆ $CHOICE_PUBLISH

$CHOICE_PUBLISH
Initial value:
= array (CHOICE_PUBLISH_ANONYMOUS => get_string('publishanonymous', 'choice'),
CHOICE_PUBLISH_NAMES => get_string('publishnames', 'choice'))

$CHOICE_PUBLISH

◆ $CHOICE_SHOWRESULTS

$CHOICE_SHOWRESULTS
Initial value:
= array (CHOICE_SHOWRESULTS_NOT => get_string('publishnot', 'choice'),
CHOICE_SHOWRESULTS_AFTER_ANSWER => get_string('publishafteranswer', 'choice'),
CHOICE_SHOWRESULTS_AFTER_CLOSE => get_string('publishafterclose', 'choice'),
CHOICE_SHOWRESULTS_ALWAYS => get_string('publishalways', 'choice'))

$CHOICE_SHOWRESULTS

◆ $logs

$logs
Initial value:
= array(
array('module'=>'choice', 'action'=>'view', 'mtable'=>'choice', 'field'=>'name'),
array('module'=>'choice', 'action'=>'update', 'mtable'=>'choice', 'field'=>'name'),
array('module'=>'choice', 'action'=>'add', 'mtable'=>'choice', 'field'=>'name'),
array('module'=>'choice', 'action'=>'report', 'mtable'=>'choice', 'field'=>'name'),
array('module'=>'choice', 'action'=>'choose', 'mtable'=>'choice', 'field'=>'name'),
array('module'=>'choice', 'action'=>'choose again', 'mtable'=>'choice', 'field'=>'name'),
)