Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
mod_survey

Namespaces

namespace  mod_survey\analytics\indicator
  
 
namespace  mod_survey\completion
  
 
namespace  mod_survey\event
  
 
namespace  mod_survey\output
  
 
namespace  mod_survey\privacy
  
 
namespace  mod_survey\search
  
 

Classes

class  backup_survey_activity_structure_step
 Define all the backup steps that will be used by the backup_survey_activity_task. More...
 
class  backup_survey_activity_task
 Provides all the settings and steps to perform one complete backup of the activity. More...
 
class  mod_survey\analytics\indicator\activity_base
 Activity base class. More...
 
class  mod_survey\analytics\indicator\cognitive_depth
 Cognitive depth indicator - survey. More...
 
class  mod_survey\analytics\indicator\social_breadth
 Social breadth indicator - survey. More...
 
class  mod_survey\completion\custom_completion
 
class  mod_survey\event\course_module_instance_list_viewed
 The mod_survey instance list viewed event class. More...
 
class  mod_survey\event\course_module_viewed
 
class  mod_survey\event\report_viewed
 
class  mod_survey\output\actionbar
 
class  mod_survey\privacy\provider
 Data provider class. More...
 
class  mod_survey\search\activity
 Search area for mod_survey activities. More...
 
class  mod_survey_external
 Survey external functions. More...
 
class  mod_survey_generator
 mod_survey data generator class. More...
 
class  mod_survey_renderer
 Renderer for the mod_survey tertiary nav. More...
 
class  moodle1_mod_survey_handler
 Survey conversion handler. More...
 
class  restore_survey_activity_structure_step
 Define all the restore steps that will be used by the restore_survey_activity_task. More...
 
class  restore_survey_activity_task
 survey restore task that provides all the settings and steps to perform one complete restore of the activity More...
 

Functions

 mod_survey_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_survey_get_completion_active_rule_descriptions ($cm)
 Callback which returns human-readable strings describing the active completion custom rules for the module instance.
 
object survey_add_analysis ($survey, $user, $notes)
 
object survey_add_instance ($survey)
 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.
 
object survey_already_done ($survey, $user)
 
 survey_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.
 
 survey_count_responses ($surveyid, $groupid, $groupingid)
 
object survey_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.
 
 survey_extend_settings_navigation (settings_navigation $settings, navigation_node $surveynode)
 This function extends the settings navigation block for the site.
 
object survey_get_analysis ($survey, $user)
 
 survey_get_completion_state ($course, $cm, $userid, $type)
 Obtains the automatic completion state for this survey based on the condition in feedback settings.
 
 survey_get_coursemodule_info ($coursemodule)
 Add a get_coursemodule_info function in case any survey type wants to add 'extra' information for the course (see resource).
 
 survey_get_post_actions ()
 List the actions that correspond to a post of this module.
 
 survey_get_questions ($survey)
 Returns the questions for a survey (ordered).
 
object survey_get_responses ($surveyid, $groupid, $groupingid)
 
 survey_get_subquestions ($question)
 Returns subquestions for a given question (ordered).
 
object survey_get_template_name ($templateid)
 
object survey_get_user_answer ($surveyid, $questionid, $userid)
 
object survey_get_user_answers ($surveyid, $questionid, $groupid, $sort="sa.answer1,sa.answer2 ASC")
 
 survey_get_view_actions ()
 List the actions that correspond to a view of this module.
 
object survey_log_info ($log)
 
 survey_order_questions ($questions, $questionorder)
 Helper function for ordering a set of questions by the given ids.
 
 survey_page_type_list ($pagetype, $parentcontext, $currentcontext)
 Return a list of page types.
 
 survey_print_all_responses ($cmid, $results, $courseid)
 
object survey_print_graph ($url)
 @global int @global int
 
object survey_print_multi ($question)
 
stdClass survey_print_recent_activity ($course, $viewfullnames, $timestart)
 @global object
 
object survey_print_single ($question)
 @global int
 
 survey_question_rowclass ($qnum)
 
 survey_reset_course_form_defaults ($course)
 Course reset form defaults.
 
 survey_reset_course_form_definition (&$mform)
 Implementation of the function for printing the form elements that control whether the course reset functionality affects the survey.
 
object survey_reset_userdata ($data)
 Actual implementation of the reset course functionality, delete all the survey responses for course $data->courseid.
 
 survey_save_answers ($survey, $answersrawdata, $course, $context)
 Save the answer for the given survey.
 
 survey_shorten_name ($name, $numwords)
 
 survey_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
 
 survey_translate_question ($question)
 Translate the question texts and options.
 
object survey_update_analysis ($survey, $user, $notes)
 
object survey_update_instance ($survey)
 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.
 
stdObject survey_user_complete ($course, $user, $mod, $survey)
 @global object @uses SURVEY_CIQ
 
object survey_user_outline ($course, $user, $mod, $survey)
 
 survey_view ($survey, $course, $cm, $context, $viewed)
 Mark the activity completed (if required) and trigger the course_module_viewed event.
 

Variables

 $capabilities
 
 $functions
 
 $logs
 
 $plugin = 2023041800
 
global int $SURVEY_GHEIGHT = 500
 Graph size $SURVEY_GHEIGHT.
 
global int $SURVEY_GWIDTH = 900
 Graph size $SURVEY_GWIDTH.
 
global array $SURVEY_QTYPE
 Question Type $SURVEY_QTYPE.
 
$plugin component = 'mod_survey'
 
$plugin cron = 0
 
const SURVEY_ATTLS "4"
 
const SURVEY_CIQ "5"
 
const SURVEY_COLLES_ACTUAL "1"
 
const SURVEY_COLLES_PREFERRED "2"
 
const SURVEY_COLLES_PREFERRED_ACTUAL "3"
 
const SURVEY_QLENGTH_WRAP "80"
 
$plugin version = 2023042400
 

Detailed Description

Function Documentation

◆ mod_survey_core_calendar_provide_event_action()

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

mod_survey_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.

◆ survey_add_analysis()

object survey_add_analysis ( $survey,
$user,
$notes )
Parameters
int$survey
int$user
string$notes
Return values
bool|int

◆ survey_add_instance()

object survey_add_instance ( $survey)

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$survey
Return values
int|bool

◆ survey_already_done()

object survey_already_done ( $survey,
$user )
Parameters
int$survey
int$user
Return values
bool

◆ survey_check_updates_since()

survey_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

◆ survey_count_responses()

survey_count_responses ( $surveyid,
$groupid,
$groupingid )
Parameters
int$surveyid
int$groupid
int$groupingid
Return values
int

◆ survey_delete_instance()

object survey_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

◆ survey_extend_settings_navigation()

survey_extend_settings_navigation ( settings_navigation $settings,
navigation_node $surveynode )

This function extends the settings navigation block for the site.

It is safe to rely on PAGE here as we will only ever be within the module context when this is called

Parameters
settings_navigation$settings
navigation_node$surveynode

◆ survey_get_analysis()

object survey_get_analysis ( $survey,
$user )
Parameters
int$survey
int$user
Return values
array

◆ survey_get_completion_state()

survey_get_completion_state ( $course,
$cm,
$userid,
$type )

Obtains the automatic completion state for this survey based on the condition in feedback settings.

Deprecated
since Moodle 3.11
Todo
MDL-71196 Final deprecation in Moodle 4.3
See also
mod_survey\completion\custom_completion
Parameters
stdClass$courseCourse
cm_info | stdClass$cmCourse-module
int$useridUser ID
bool$typeType of comparison (or/and; can be used as return value if no conditions)
Return values
boolTrue if completed, false if not, $type if conditions not set.

◆ survey_get_coursemodule_info()

survey_get_coursemodule_info ( $coursemodule)

Add a get_coursemodule_info function in case any survey 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).

◆ survey_get_post_actions()

survey_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

◆ survey_get_questions()

survey_get_questions ( $survey)

Returns the questions for a survey (ordered).

Parameters
stdClass$surveysurvey object
Return values
arraylist of questions ordered
Since
Moodle 3.0
Exceptions
moodle_exception

◆ survey_get_responses()

object survey_get_responses ( $surveyid,
$groupid,
$groupingid )
Parameters
int$surveyid
int$groupid
int$groupingid
Return values
array

◆ survey_get_subquestions()

survey_get_subquestions ( $question)

Returns subquestions for a given question (ordered).

Parameters
stdClass$questionquestin object
Return values
arraylist of subquestions ordered
Since
Moodle 3.0

◆ survey_get_template_name()

object survey_get_template_name ( $templateid)
Parameters
int$templateid
Return values
string

◆ survey_get_user_answer()

object survey_get_user_answer ( $surveyid,
$questionid,
$userid )
Parameters
int$surveyid
int$questionid
int$userid
Return values
stdClass|false

◆ survey_get_user_answers()

object survey_get_user_answers ( $surveyid,
$questionid,
$groupid,
$sort = "sa.answer1,sa.answer2 ASC" )
Parameters
int$surveyid
int$groupid
string$sort
Return values
array

◆ survey_get_view_actions()

survey_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

◆ survey_log_info()

object survey_log_info ( $log)
Parameters
sting$log
Return values
array

◆ survey_order_questions()

survey_order_questions ( $questions,
$questionorder )

Helper function for ordering a set of questions by the given ids.

Parameters
array$questionsarray of questions objects
array$questionorderarray of questions ids indicating the correct order
Return values
arraylist of questions ordered
Since
Moodle 3.0

◆ survey_page_type_list()

survey_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

◆ survey_print_all_responses()

survey_print_all_responses ( $cmid,
$results,
$courseid )
Parameters
int$cmid
array$results
int$courseid

◆ survey_print_graph()

object survey_print_graph ( $url)

@global int @global int

Parameters
string$url

◆ survey_print_multi()

object survey_print_multi ( $question)
Todo
Check this function

@global object @global int @global void This is never defined @global object This is defined twice?

Parameters
object$question

◆ survey_print_recent_activity()

stdClass survey_print_recent_activity ( $course,
$viewfullnames,
$timestart )

@global object

Parameters
object$course
mixed$viewfullnames
int$timestamp
Return values
bool

◆ survey_print_single()

object survey_print_single ( $question)

@global int

Parameters
object$question

◆ survey_question_rowclass()

survey_question_rowclass ( $qnum)
Parameters
int$qnum
Return values
string

◆ survey_reset_course_form_defaults()

survey_reset_course_form_defaults ( $course)

Course reset form defaults.

Return values
array

◆ survey_reset_course_form_definition()

survey_reset_course_form_definition ( & $mform)

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

Parameters
MoodleQuickForm$mformform passed by reference

◆ survey_reset_userdata()

object survey_reset_userdata ( $data)

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

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

◆ survey_save_answers()

survey_save_answers ( $survey,
$answersrawdata,
$course,
$context )

Save the answer for the given survey.

Parameters
stdClass$surveya survey object
array$answersrawdatathe answers to be saved
stdClass$coursea course object (required for trigger the submitted event)
stdClass$contexta context object (required for trigger the submitted event)
Since
Moodle 3.0

◆ survey_shorten_name()

survey_shorten_name ( $name,
$numwords )
Parameters
string$name
array$numwords
Return values
string

◆ survey_supports()

survey_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.

◆ survey_translate_question()

survey_translate_question ( $question)

Translate the question texts and options.

Parameters
stdClass$questionquestion object
Return values
stdClassquestion object with all the text fields translated
Since
Moodle 3.0

◆ survey_update_analysis()

object survey_update_analysis ( $survey,
$user,
$notes )
Parameters
int$survey
int$user
string$notes

◆ survey_update_instance()

object survey_update_instance ( $survey)

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$survey
Return values
bool

◆ survey_user_complete()

stdObject survey_user_complete ( $course,
$user,
$mod,
$survey )

@global object @uses SURVEY_CIQ

Parameters
object$course
object$user
object$mod
object$survey

◆ survey_user_outline()

object survey_user_outline ( $course,
$user,
$mod,
$survey )
Parameters
object$course
object$user
object$mod
object$survey
Return values
$result

◆ survey_view()

survey_view ( $survey,
$course,
$cm,
$context,
$viewed )

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

Parameters
stdClass$surveysurvey object
stdClass$coursecourse object
stdClass$cmcourse module object
stdClass$contextcontext object
string$viewedwhich page viewed
Since
Moodle 3.0

Variable Documentation

◆ $logs

$logs
Initial value:
= array(
array('module'=>'survey', 'action'=>'add', 'mtable'=>'survey', 'field'=>'name'),
array('module'=>'survey', 'action'=>'update', 'mtable'=>'survey', 'field'=>'name'),
array('module'=>'survey', 'action'=>'download', 'mtable'=>'survey', 'field'=>'name'),
array('module'=>'survey', 'action'=>'view form', 'mtable'=>'survey', 'field'=>'name'),
array('module'=>'survey', 'action'=>'view graph', 'mtable'=>'survey', 'field'=>'name'),
array('module'=>'survey', 'action'=>'view report', 'mtable'=>'survey', 'field'=>'name'),
array('module'=>'survey', 'action'=>'submit', 'mtable'=>'survey', 'field'=>'name'),
)

◆ $SURVEY_QTYPE

$SURVEY_QTYPE
Initial value:
= array (
"-3" => "Virtual Actual and Preferred",
"-2" => "Virtual Preferred",
"-1" => "Virtual Actual",
"0" => "Text",
"1" => "Actual",
"2" => "Preferred",
"3" => "Actual and Preferred",
)

Question Type $SURVEY_QTYPE.