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]

Library of functions and constants for module feedback includes the main-part of feedback-functions

Copyright: Andreas Grabs
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 3268 lines (113 kb)
Included or required: 15 times
Referenced: 4 times
Includes or requires: 1 file
 mod/feedback/deprecatedlib.php

Defines 98 functions

  feedback_supports()
  feedback_add_instance()
  feedback_update_instance()
  feedback_pluginfile()
  feedback_delete_instance()
  feedback_user_outline()
  feedback_get_recent_mod_activity()
  feedback_print_recent_mod_activity()
  feedback_user_complete()
  feedback_cron()
  feedback_scale_used()
  feedback_scale_used_anywhere()
  feedback_get_view_actions()
  feedback_get_post_actions()
  feedback_reset_userdata()
  feedback_reset_course_form_definition()
  feedback_reset_course_form_defaults()
  feedback_reset_course_form()
  feedback_get_editor_options()
  feedback_set_events()
  feedback_refresh_events()
  feedback_delete_course_module()
  feedback_get_context()
  feedback_check_is_switchrole()
  feedback_get_incomplete_users()
  feedback_count_incomplete_users()
  feedback_count_complete_users()
  feedback_get_complete_users()
  feedback_get_viewreports_users()
  feedback_get_receivemail_users()
  feedback_create_template()
  feedback_save_as_template()
  feedback_delete_template()
  feedback_items_from_template()
  feedback_get_template_list()
  feedback_get_item_class()
  feedback_load_feedback_items()
  feedback_load_feedback_items_options()
  feedback_get_depend_candidates_for_item()
  feedback_create_item()
  feedback_update_item()
  feedback_delete_item()
  feedback_delete_all_items()
  feedback_switch_item_required()
  feedback_renumber_items()
  feedback_moveup_item()
  feedback_movedown_item()
  feedback_move_item()
  feedback_print_item_preview()
  feedback_print_item_complete()
  feedback_print_item_show_value()
  feedback_set_tmp_values()
  feedback_save_tmp_values()
  feedback_delete_completedtmp()
  feedback_create_pagebreak()
  feedback_get_all_break_positions()
  feedback_get_last_break_position()
  feedback_get_page_to_continue()
  feedback_clean_input_value()
  feedback_save_values()
  feedback_save_guest_values()
  feedback_get_item_value()
  feedback_compare_item_value()
  feedback_check_values()
  feedback_create_values()
  feedback_update_values()
  feedback_get_group_values()
  feedback_is_already_submitted()
  feedback_get_current_completed()
  feedback_get_completeds_group()
  feedback_get_completeds_group_count()
  feedback_delete_all_completeds()
  feedback_delete_completed()
  feedback_is_course_in_sitecourse_map()
  feedback_is_feedback_in_sitecourse_map()
  feedback_get_feedbacks_from_sitecourse_map()
  feedback_get_courses_from_sitecourse_map()
  feedback_update_sitecourse_map()
  feedback_clean_up_sitecourse_map()
  feedback_print_numeric_option_list()
  feedback_send_email()
  feedback_send_email_anonym()
  feedback_send_email_text()
  feedback_send_email_html()
  feedback_encode_target_url()
  feedback_extend_settings_navigation()
  feedback_init_feedback_session()
  feedback_page_type_list()
  feedback_ajax_saveitemorder()
  feedback_can_view_analysis()
  mod_feedback_get_fontawesome_icon_map()
  feedback_check_updates_since()
  mod_feedback_core_calendar_provide_event_action()
  feedback_get_coursemodule_info()
  mod_feedback_get_completion_active_rule_descriptions()
  mod_feedback_core_calendar_get_valid_event_timestart_range()
  mod_feedback_core_calendar_event_timestart_updated()
  mod_feedback_core_calendar_get_event_action_string()

Functions that are not part of a class:

feedback_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

feedback_add_instance($feedback)   X-Ref
this will create a new instance and return the id number
of the new instance.

return: int
param: object $feedback the object given by mod_feedback_mod_form

feedback_update_instance($feedback)   X-Ref
this will update a given instance

return: boolean
param: object $feedback the object given by mod_feedback_mod_form

feedback_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()   X-Ref
Serves the files included in feedback items like label. Implements needed access control ;-)

There are two situations in general where the files will be sent.
1) filearea = item, 2) filearea = template

return: bool false if file not found, does not return if found - justsend the file
param: stdClass $course course object
param: stdClass $cm course module object
param: stdClass $context context object
param: string $filearea file area
param: array $args extra arguments
param: bool $forcedownload whether or not force download
param: array $options additional options affecting the file serving

feedback_delete_instance($id)   X-Ref
this will delete a given instance.
all referenced data also will be deleted

return: boolean
param: int $id the instanceid of feedback

feedback_user_outline($course, $user, $mod, $feedback)   X-Ref
Return a small object with summary information about what a
user has done with a given particular instance of this module
Used for user activity reports.
$return->time = the time they did it
$return->info = a short text description

return: stdClass
param: stdClass $course
param: stdClass $user
param: cm_info|stdClass $mod
param: stdClass $feedback

feedback_get_recent_mod_activity(&$activities, &$index,$timemodified, $courseid,$cmid, $userid="", $groupid="")   X-Ref
Returns all users who has completed a specified feedback since a given time
many thanks to Manolescu Dorel, who contributed these two functions

return: void
param: array $activities Passed by reference
param: int $index Passed by reference
param: int $timemodified Timestamp
param: int $courseid
param: int $cmid
param: int $userid
param: int $groupid

feedback_print_recent_mod_activity($activity, $courseid, $detail, $modnames)   X-Ref
Prints all users who has completed a specified feedback since a given time
many thanks to Manolescu Dorel, who contributed these two functions

return: void Output is echo'd
param: object $activity
param: int $courseid
param: string $detail
param: array $modnames

feedback_user_complete($course, $user, $mod, $feedback)   X-Ref
Print a detailed representation of what a  user has done with
a given particular instance of this module, for user activity reports.

param: stdClass $course
param: stdClass $user
param: cm_info|stdClass $mod
param: stdClass $feedback

feedback_cron()   X-Ref

return: bool true

feedback_scale_used()   X-Ref


feedback_scale_used_anywhere($scaleid)   X-Ref
Checks if scale is being used by any instance of feedback

This is used to find out if scale used anywhere
return: boolean True if the scale is used by any assignment
param: $scaleid int

feedback_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

feedback_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

feedback_reset_userdata($data)   X-Ref
This function is used by the reset_course_userdata function in moodlelib.
This function will remove all responses from the specified feedback
and clean up any related data.

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

feedback_reset_course_form_definition(&$mform)   X-Ref
Called by course/reset.php

param: object $mform form passed by reference

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

param: object $course

feedback_reset_course_form($course)   X-Ref
Called by course/reset.php and shows the formdata by coursereset.
it prints checkboxes for each feedback available at the given course
there are two checkboxes:
1) delete userdata and keep the feedback
2) delete userdata and drop the feedback

return: void
param: object $course

feedback_get_editor_options()   X-Ref
This gets an array with default options for the editor

return: array the options

feedback_set_events($feedback)   X-Ref
This creates new events given as timeopen and closeopen by $feedback.

return: void
param: object $feedback

feedback_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 feedback event in the site is checked, else
only feedback 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 Feedback module instance or ID.
param: int|stdClass $cm Course module object or ID (not used in this module).

feedback_delete_course_module($id)   X-Ref
this function is called by {@link feedback_delete_userdata()}
it drops the feedback-instance from the course_module table

return: boolean
param: int $id the id from the coursemodule

feedback_get_context()   X-Ref


feedback_check_is_switchrole()   X-Ref
returns true if the current role is faked by switching role feature

return: boolean

feedback_get_incomplete_users(cm_info $cm,$group = false,$sort = '',$startpage = false,$pagecount = false,$includestatus = false)   X-Ref
count users which have not completed the feedback

return: array array of user ids or user objects when $includestatus set to true
param: cm_info $cm Course-module object
param: int $group single groupid
param: string $sort
param: int $startpage
param: int $pagecount
param: bool $includestatus to return if the user started or not the feedback among the complete user record

feedback_count_incomplete_users($cm, $group = false)   X-Ref
count users which have not completed the feedback

return: int count of userrecords
param: object $cm
param: int $group single groupid

feedback_count_complete_users($cm, $group = false)   X-Ref
count users which have completed a feedback

return: int count of userrecords
param: object $cm
param: int $group single groupid

feedback_get_complete_users($cm,$group = false,$where = '',array $params = null,$sort = '',$startpage = false,$pagecount = false)   X-Ref
get users which have completed a feedback

return: object the userrecords
param: object $cm
param: int $group single groupid
param: string $where a sql where condition (must end with " AND ")
param: array parameters used in $where
param: string $sort a table field
param: int $startpage
param: int $pagecount

feedback_get_viewreports_users($cmid, $groups = false)   X-Ref
get users which have the viewreports-capability

return: object the userrecords
param: int $cmid
param: mixed $groups single groupid or array of groupids - group(s) user is in

feedback_get_receivemail_users($cmid, $groups = false)   X-Ref
get users which have the receivemail-capability

return: object the userrecords
param: int $cmid
param: mixed $groups single groupid or array of groupids - group(s) user is in

feedback_create_template($courseid, $name, $ispublic = 0)   X-Ref
creates a new template-record.

return: int the new templateid
param: int $courseid
param: string $name the name of template shown in the templatelist
param: int $ispublic 0:privat 1:public

feedback_save_as_template($feedback, $name, $ispublic = 0)   X-Ref
creates new template items.
all items will be copied and the attribute feedback will be set to 0
and the attribute template will be set to the new templateid

return: boolean
param: object $feedback
param: string $name the name of template shown in the templatelist
param: int $ispublic 0:privat 1:public

feedback_delete_template($template)   X-Ref
deletes all feedback_items related to the given template id

return: void
param: object $template the template

feedback_items_from_template($feedback, $templateid, $deleteold = false)   X-Ref
creates new feedback_item-records from template.
if $deleteold is set true so the existing items of the given feedback will be deleted
if $deleteold is set false so the new items will be appanded to the old items

param: object $feedback
param: int $templateid
param: boolean $deleteold

feedback_get_template_list($course, $onlyownorpublic = '')   X-Ref
get the list of available templates.
if the $onlyown param is set true so only templates from own course will be served
this is important for droping templates

return: array the template recordsets
param: object $course
param: string $onlyownorpublic

feedback_get_item_class($typ)   X-Ref
load the lib.php from item-plugin-dir and returns the instance of the itemclass

return: feedback_item_base the instance of itemclass
param: string $typ

feedback_load_feedback_items($dir = 'mod/feedback/item')   X-Ref
load the available item plugins from given subdirectory of $CFG->dirroot
the default is "mod/feedback/item"

return: array pluginnames as string
param: string $dir the subdir

feedback_load_feedback_items_options()   X-Ref
load the available item plugins to use as dropdown-options

return: array pluginnames as string

feedback_get_depend_candidates_for_item($feedback, $item)   X-Ref
load the available items for the depend item dropdown list shown in the edit_item form

return: array all items except the item $item, labels and pagebreaks
param: object $feedback
param: object $item the item of the edit_item form

feedback_create_item()   X-Ref


feedback_update_item($item)   X-Ref
save the changes of a given item.

return: boolean
param: object $item

feedback_delete_item($itemid, $renumber = true, $template = false)   X-Ref
deletes an item and also deletes all related values

return: void
param: int $itemid
param: boolean $renumber should the kept items renumbered Yes/No
param: object $template if the template is given so the items are bound to it

feedback_delete_all_items($feedbackid)   X-Ref
deletes all items of the given feedbackid

return: void
param: int $feedbackid

feedback_switch_item_required($item)   X-Ref
this function toggled the item-attribute required (yes/no)

return: boolean
param: object $item

feedback_renumber_items($feedbackid)   X-Ref
renumbers all items of the given feedbackid

return: void
param: int $feedbackid

feedback_moveup_item($item)   X-Ref
this decreases the position of the given item

return: bool
param: object $item

feedback_movedown_item($item)   X-Ref
this increased the position of the given item

return: bool
param: object $item

feedback_move_item($moveitem, $pos)   X-Ref
here the position of the given item will be set to the value in $pos

return: boolean
param: object $moveitem
param: int $pos

feedback_print_item_preview()   X-Ref


feedback_print_item_complete()   X-Ref


feedback_print_item_show_value()   X-Ref


feedback_set_tmp_values($feedbackcompleted)   X-Ref
if the user completes a feedback and there is a pagebreak so the values are saved temporary.
the values are not saved permanently until the user click on save button

return: object temporary saved completed-record
param: object $feedbackcompleted

feedback_save_tmp_values($feedbackcompletedtmp, $feedbackcompleted)   X-Ref
this saves the temporary saved values permanently

return: int the id of the completed
param: object $feedbackcompletedtmp the temporary completed
param: object $feedbackcompleted the target completed

feedback_delete_completedtmp()   X-Ref


feedback_create_pagebreak($feedbackid)   X-Ref
this creates a pagebreak.
a pagebreak is a special kind of item

return: mixed false if there already is a pagebreak on last position or the id of the pagebreak-item
param: int $feedbackid

feedback_get_all_break_positions($feedbackid)   X-Ref
get all positions of pagebreaks in the given feedback

return: array all ordered pagebreak positions
param: int $feedbackid

feedback_get_last_break_position($feedbackid)   X-Ref
get the position of the last pagebreak

return: int the position of the last pagebreak
param: int $feedbackid

feedback_get_page_to_continue()   X-Ref


feedback_clean_input_value()   X-Ref


feedback_save_values()   X-Ref


feedback_save_guest_values()   X-Ref


feedback_get_item_value($completedid, $itemid, $tmp = false)   X-Ref
get the value from the given item related to the given completed.
the value can come as temporary or as permanently value. the deciding is done by $tmp

return: mixed the value, the type depends on plugin-definition
param: int $completeid
param: int $itemid
param: boolean $tmp

feedback_compare_item_value($completedid, $item, $dependvalue, $tmp = false)   X-Ref
compares the value of the itemid related to the completedid with the dependvalue.
this is used if a depend item is set.
the value can come as temporary or as permanently value. the deciding is done by $tmp.

return: bool
param: int $completedid
param: stdClass|int $item
param: mixed $dependvalue
param: bool $tmp

feedback_check_values()   X-Ref


feedback_create_values()   X-Ref


feedback_update_values()   X-Ref


feedback_get_group_values($item,$groupid = false,$courseid = false,$ignore_empty = false)   X-Ref
get the values of an item depending on the given groupid.
if the feedback is anonymous so the values are shuffled

return: array the value-records
param: object $item
param: int $groupid
param: int $courseid
param: bool $ignore_empty if this is set true so empty values are not delivered

feedback_is_already_submitted($feedbackid, $courseid = false)   X-Ref
check for multiple_submit = false.
if the feedback is global so the courseid must be given

return: boolean true if the feedback already is submitted otherwise false
param: int $feedbackid
param: int $courseid

feedback_get_current_completed()   X-Ref


feedback_get_completeds_group($feedback, $groupid = false, $courseid = false)   X-Ref
get the completeds depending on the given groupid.

return: mixed array of found completeds otherwise false
param: object $feedback
param: int $groupid
param: int $courseid

feedback_get_completeds_group_count($feedback, $groupid = false, $courseid = false)   X-Ref
get the count of completeds depending on the given groupid.

return: mixed count of completeds or false
param: object $feedback
param: int $groupid
param: int $courseid

feedback_delete_all_completeds($feedback, $cm = null, $course = null)   X-Ref
deletes all completed-recordsets from a feedback.
all related data such as values also will be deleted

return: void
param: stdClass|int $feedback
param: stdClass|cm_info $cm
param: stdClass $course

feedback_delete_completed($completed, $feedback = null, $cm = null, $course = null)   X-Ref
deletes a completed given by completedid.
all related data such values or tracking data also will be deleted

return: boolean
param: int|stdClass $completed
param: stdClass $feedback
param: stdClass|cm_info $cm
param: stdClass $course

feedback_is_course_in_sitecourse_map()   X-Ref


feedback_is_feedback_in_sitecourse_map()   X-Ref


feedback_get_feedbacks_from_sitecourse_map($courseid)   X-Ref
gets the feedbacks from table feedback_sitecourse_map.
this is used to show the global feedbacks on the feedback block
all feedbacks with the following criteria will be selected:<br />

1) all feedbacks which id are listed together with the courseid in sitecoursemap and<br />
2) all feedbacks which not are listed in sitecoursemap

return: array the feedback-records
param: int $courseid

feedback_get_courses_from_sitecourse_map($feedbackid)   X-Ref
Gets the courses from table feedback_sitecourse_map

return: array the course-records
param: int $feedbackid

feedback_update_sitecourse_map($feedback, $courses)   X-Ref
Updates the course mapping for the feedback

param: stdClass $feedback
param: array $courses array of course ids

feedback_clean_up_sitecourse_map()   X-Ref


feedback_print_numeric_option_list()   X-Ref


feedback_send_email($cm, $feedback, $course, $user, $completed = null)   X-Ref
sends an email to the teachers of the course where the given feedback is placed.

return: void
param: object $cm the coursemodule-record
param: object $feedback
param: object $course
param: stdClass|int $user
param: stdClass $completed record from feedback_completed if known

feedback_send_email_anonym($cm, $feedback, $course)   X-Ref
sends an email to the teachers of the course where the given feedback is placed.

return: void
param: object $cm the coursemodule-record
param: object $feedback
param: object $course

feedback_send_email_text($info, $course)   X-Ref
send the text-part of the email

return: string the text you want to post
param: object $info includes some infos about the feedback you want to send
param: object $course

feedback_send_email_html($info, $course, $cm)   X-Ref
send the html-part of the email

return: string the text you want to post
param: object $info includes some infos about the feedback you want to send
param: object $course

feedback_encode_target_url($url)   X-Ref

return: string
param: string $url

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

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

feedback_init_feedback_session()   X-Ref
No description

feedback_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

feedback_ajax_saveitemorder($itemlist, $feedback)   X-Ref
Move save the items of the given $feedback in the order of $itemlist.

return: bool true if success
param: string $itemlist a comma separated list with item ids
param: stdClass $feedback

feedback_can_view_analysis($feedback, $context, $courseid = false)   X-Ref
Checks if current user is able to view feedback on this course.

return: bool
param: stdClass $feedback
param: context_module $context
param: int $courseid

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


feedback_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_feedback_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).

feedback_get_coursemodule_info($coursemodule)   X-Ref
Add a get_coursemodule_info function in case any feedback 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_feedback_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_feedback_core_calendar_get_valid_event_timestart_range(\calendar_event $event, \stdClass $instance)   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']
]

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

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

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

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

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