Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
mod_feedback_completion Class Reference

Collects information and methods about feedback completion (either complete.php or show_entries.php) More...

Inheritance diagram for mod_feedback_completion:
mod_feedback_structure

Public Member Functions

 __construct ($feedback, $cm, $courseid, $iscompleted=false, $completedid=null, $nonanonymouseuserid=null, $userid=0)
 Constructor. More...
 
 can_complete ()
 Checks if user has capability to submit the feedback. More...
 
 can_submit ()
 Checks if user is prevented from re-submission. More...
 
 can_view_analysis ()
 Checks if current user is able to view feedback on this course. More...
 
 check_course_is_mapped ()
 Check whether the feedback is mapped to the given courseid.
 
 count_completed_responses ($groupid=0)
 Counts records from {feedback_completed} table for a given feedback. More...
 
 create_completed_tmp_from_last_completed ()
 If user has already completed the feedback, create the temproray values from last completed attempt. More...
 
 find_last_completed ()
 Retrieves the last completion record for the current user. More...
 
 get_cm ()
 Current course module. More...
 
 get_completed ()
 Returns a record from 'feedback_completed' table. More...
 
 get_completed_courses ()
 For the frontpage feedback returns the list of courses with at least one completed feedback. More...
 
 get_courseid ()
 Id of the current course (for site feedbacks only) More...
 
 get_current_completed_tmp ()
 Returns the temporary completion record for the current user or guest session. More...
 
 get_feedback ()
 Current feedback. More...
 
 get_finished_responses ()
 Retrieves responses from an finished attempt. More...
 
 get_item_value ($item)
 Returns a value stored for this item in the feedback (temporary or not, depending on the mode) More...
 
 get_items ($hasvalueonly=false)
 Get all items in this feedback or this template. More...
 
 get_jumpto ()
 Return the jumpto property. More...
 
 get_next_page ($gopage, $strictcheck=true)
 Get the next page for the feedback. More...
 
 get_pages ()
 Splits the feedback items into pages. More...
 
 get_previous_page ($gopage, $strictcheck=true)
 Get the previous page for the feedback. More...
 
 get_resume_page ()
 Page index to resume the feedback. More...
 
 get_templateid ()
 Template id. More...
 
 get_unfinished_responses ()
 Retrieves responses from an unfinished attempt. More...
 
 is_already_submitted ($anycourseid=false)
 check for multiple_submit = false. More...
 
 is_anonymous ()
 Is this feedback anonymous? More...
 
 is_empty ()
 Is the items list empty? More...
 
 is_open ()
 Is this feedback open (check timeopen and timeclose) More...
 
 just_completed ()
 Check if the feedback was just completed. More...
 
 page_after_submit ()
 Returns the formatted text of the page after submit or null if it is not set. More...
 
 process_page ($gopage, $gopreviouspage=false)
 Process a page jump via the mod_feedback_complete_form. More...
 
 render_items ()
 Render the form with the questions. More...
 
 save_response ()
 Saves the response. More...
 
 save_response_tmp ($data)
 Saves unfinished response to the temporary table. More...
 
 set_module_viewed ()
 Mark activity viewed for completion-tracking. More...
 
 shuffle_anonym_responses ()
 If there are any new responses to the anonymous feedback, re-shuffle all responses and assign response number to each of them.
 
 trigger_module_viewed ()
 Trigger module viewed event. More...
 

Protected Member Functions

 can_see_item ($item)
 Can the current user see the item, if dependency is met? More...
 
 create_current_completed_tmp ()
 Creates a new record in the 'feedback_completedtmp' table for the current user/guest session. More...
 
 delete_completedtmp ()
 Deletes the temporary completed and all related temporary values.
 
 dependency_has_error ($item)
 Dependency condition has an error. More...
 
 get_last_completed_page ()
 Returns the last page that has items with the value (i.e. More...
 
 get_values ($item=null)
 Returns all completed values for this feedback or just a value for an item. More...
 
 get_values_tmp ($item=null)
 Returns all temporary values for this feedback or just a value for an item. More...
 

Protected Attributes

array $allcourses
 
array $allitems
 
cm_info $cm
 
stdClass $completed
 
stdClass $completedtmp = null
 
int $courseid = 0
 course where the feedback is filled. More...
 
stdClass $feedback
 record from 'feedback' table. More...
 
mod_feedback_complete_form $form = null
 the form used for completing the feedback
 
bool $iscompleted = false
 
int $jumpto = null
 the next page the user should jump after processing the form
 
bool $justcompleted = false
 true when the feedback has been completed during the request
 
int $templateid
 
int $userid
 
stdClass[] $values = null
 
stdClass[] $valuestmp = null
 

Detailed Description

Collects information and methods about feedback completion (either complete.php or show_entries.php)

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

mod_feedback_completion::__construct (   $feedback,
  $cm,
  $courseid,
  $iscompleted = false,
  $completedid = null,
  $nonanonymouseuserid = null,
  $userid = 0 
)

Constructor.

Parameters
stdClass$feedbackfeedback object
cm_info$cmcourse module object corresponding to the $feedback (at least one of $feedback or $cm is required)
int$courseidcurrent course (for site feedbacks only)
bool$iscompletedhas feedback been already completed? If yes either completedid or userid must be specified.
int$completedidid in the table feedback_completed, may be omitted if userid is specified but it is highly recommended because the same user may have multiple responses to the same feedback for different courses
int$nonanonymouseuserid- Return only anonymous results or specified user's results. If null only anonymous replies will be returned and the $completedid is mandatory. If specified only non-anonymous replies of $nonanonymouseuserid will be returned.
int$useridUser id to use for all capability checks, etc. Set to 0 for current user (default).

Member Function Documentation

◆ can_complete()

mod_feedback_completion::can_complete ( )

Checks if user has capability to submit the feedback.

There is an exception for fully anonymous feedbacks when guests can complete feedback without the proper capability.

This should be followed by checking can_submit() because even if user has capablity to complete, they may have already submitted feedback and can not re-submit

Return values
bool

◆ can_see_item()

mod_feedback_completion::can_see_item (   $item)
protected

Can the current user see the item, if dependency is met?

Parameters
stdClass$item
Return values
boolwhether user can see item or not, true if there is no dependency or dependency is met, false if dependent question is visible or broken and further it is either not answered or the dependency is not met, null if dependency is broken.

◆ can_submit()

mod_feedback_completion::can_submit ( )

Checks if user is prevented from re-submission.

This must be called after can_complete()

Return values
bool

◆ can_view_analysis()

mod_feedback_structure::can_view_analysis ( )
inherited

Checks if current user is able to view feedback on this course.

Return values
bool

◆ count_completed_responses()

mod_feedback_structure::count_completed_responses (   $groupid = 0)
inherited

Counts records from {feedback_completed} table for a given feedback.

If $groupid or $this->courseid is set, the records are filtered by the group/course

Parameters
int$groupid
Return values
mixedarray of found completeds otherwise false

◆ create_completed_tmp_from_last_completed()

mod_feedback_completion::create_completed_tmp_from_last_completed ( )

If user has already completed the feedback, create the temproray values from last completed attempt.

Return values
stdClassrecord from feedback_completedtmp or false if not found

◆ create_current_completed_tmp()

mod_feedback_completion::create_current_completed_tmp ( )
protected

Creates a new record in the 'feedback_completedtmp' table for the current user/guest session.

Return values
stdClassrecord from feedback_completedtmp or false if not found

◆ dependency_has_error()

mod_feedback_completion::dependency_has_error (   $item)
protected

Dependency condition has an error.

Parameters
stdClass$item
Return values
bool

◆ find_last_completed()

mod_feedback_completion::find_last_completed ( )

Retrieves the last completion record for the current user.

Return values
stdClassrecord from feedback_completed or false if not found

◆ get_cm()

mod_feedback_structure::get_cm ( )
inherited

Current course module.

Return values
stdClass

◆ get_completed()

mod_feedback_completion::get_completed ( )

Returns a record from 'feedback_completed' table.

Return values
stdClass

◆ get_completed_courses()

mod_feedback_structure::get_completed_courses ( )
inherited

For the frontpage feedback returns the list of courses with at least one completed feedback.

Return values
arrayid=>name pairs of courses

◆ get_courseid()

mod_feedback_structure::get_courseid ( )
inherited

Id of the current course (for site feedbacks only)

Return values
stdClass

◆ get_current_completed_tmp()

mod_feedback_completion::get_current_completed_tmp ( )

Returns the temporary completion record for the current user or guest session.

Return values
stdClass|falserecord from feedback_completedtmp or false if not found

◆ get_feedback()

mod_feedback_structure::get_feedback ( )
inherited

Current feedback.

Return values
stdClass

◆ get_finished_responses()

mod_feedback_completion::get_finished_responses ( )

Retrieves responses from an finished attempt.

Return values
arraythe responses (from the feedback_value table)
Since
Moodle 3.3

◆ get_item_value()

mod_feedback_completion::get_item_value (   $item)

Returns a value stored for this item in the feedback (temporary or not, depending on the mode)

Parameters
stdClass$item
Return values
string

◆ get_items()

mod_feedback_structure::get_items (   $hasvalueonly = false)
inherited

Get all items in this feedback or this template.

Parameters
bool$hasvalueonlyonly count items with a value.
Return values
arrayof objects from feedback_item with an additional attribute 'itemnr'

◆ get_jumpto()

mod_feedback_completion::get_jumpto ( )

Return the jumpto property.

Return values
intthe next page to jump.
Since
Moodle 3.3

◆ get_last_completed_page()

mod_feedback_completion::get_last_completed_page ( )
protected

Returns the last page that has items with the value (i.e.

not label) which have been answered as well as the first page that has items with the values that have not been answered.

Either of the two return values may be null if there are no answered page or there are no unanswered pages left respectively.

Two pages may not be directly following each other because there may be empty pages or pages with information texts only between them

Return values
arrayarray of two elements [$lastcompleted, $firstincompleted]

◆ get_next_page()

mod_feedback_completion::get_next_page (   $gopage,
  $strictcheck = true 
)

Get the next page for the feedback.

This is normally $gopage+1 but may be bigger if there are empty pages or pages without visible questions.

This method can only be called when questions on the current page are already answered, otherwise it may be inaccurate.

Parameters
int$gopagecurrent page
bool$strictcheckwhen gopage is the user-input value, make sure we do not jump over unanswered questions
Return values
int|nullthe index of the next page or null if this is the last page

◆ get_pages()

mod_feedback_completion::get_pages ( )

Splits the feedback items into pages.

Items that we definitely know at this stage as not applicable are excluded. Items that are dependent on something that has not yet been answered are still present, as well as items with broken dependencies.

Return values
arrayarray of arrays of items

◆ get_previous_page()

mod_feedback_completion::get_previous_page (   $gopage,
  $strictcheck = true 
)

Get the previous page for the feedback.

This is normally $gopage-1 but may be smaller if there are empty pages or pages without visible questions.

Parameters
int$gopagecurrent page
bool$strictcheckwhen gopage is the user-input value, make sure we do not jump over unanswered questions
Return values
int|nullthe index of the next page or null if this is the first page with items

◆ get_resume_page()

mod_feedback_completion::get_resume_page ( )

Page index to resume the feedback.

When user abandones answering feedback and then comes back to it we should send him to the first page after the last page he fully completed.

Return values
int

◆ get_templateid()

mod_feedback_structure::get_templateid ( )
inherited

Template id.

Return values
int

◆ get_unfinished_responses()

mod_feedback_completion::get_unfinished_responses ( )

Retrieves responses from an unfinished attempt.

Return values
arraythe responses (from the feedback_valuetmp table)
Since
Moodle 3.3

◆ get_values()

mod_feedback_completion::get_values (   $item = null)
protected

Returns all completed values for this feedback or just a value for an item.

Parameters
stdClass$item
Return values
array

◆ get_values_tmp()

mod_feedback_completion::get_values_tmp (   $item = null)
protected

Returns all temporary values for this feedback or just a value for an item.

Parameters
stdClass$item
Return values
array

◆ is_already_submitted()

mod_feedback_structure::is_already_submitted (   $anycourseid = false)
inherited

check for multiple_submit = false.

if the feedback is global so the courseid must be given

Parameters
bool$anycourseidif true checks if this feedback was submitted in any course, otherwise checks $this->courseid . Applicable to frontpage feedbacks only
Return values
booltrue if the feedback already is submitted otherwise false

◆ is_anonymous()

mod_feedback_structure::is_anonymous ( )
inherited

Is this feedback anonymous?

Return values
bool

◆ is_empty()

mod_feedback_structure::is_empty ( )
inherited

Is the items list empty?

Return values
bool

◆ is_open()

mod_feedback_structure::is_open ( )
inherited

Is this feedback open (check timeopen and timeclose)

Return values
bool

◆ just_completed()

mod_feedback_completion::just_completed ( )

Check if the feedback was just completed.

Return values
booltrue if the feedback was just completed.
Since
Moodle 3.3

◆ page_after_submit()

mod_feedback_structure::page_after_submit ( )
inherited

Returns the formatted text of the page after submit or null if it is not set.

Return values
string|null

◆ process_page()

mod_feedback_completion::process_page (   $gopage,
  $gopreviouspage = false 
)

Process a page jump via the mod_feedback_complete_form.

This function initializes the form and process the submission.

Parameters
int$gopagethe current page
int$gopreviouspageif the user chose to go to the previous page
Return values
stringthe url to redirect the user (if any)
Since
Moodle 3.3

◆ render_items()

mod_feedback_completion::render_items ( )

Render the form with the questions.

Return values
stringthe form rendered
Since
Moodle 3.3

◆ save_response()

mod_feedback_completion::save_response ( )

Saves the response.

The form data has already been stored in the temporary table in save_response_tmp(). This function copies the values from the temporary table to the completion table. It is also responsible for sending email notifications when applicable.

◆ save_response_tmp()

mod_feedback_completion::save_response_tmp (   $data)

Saves unfinished response to the temporary table.

This is called when user proceeds to the next/previous page in the complete form and also right after the form submit. After the form submit the save_response() is called to move response from temporary table to completion table.

Parameters
stdClass$datadata from the form mod_feedback_complete_form

◆ set_module_viewed()

mod_feedback_completion::set_module_viewed ( )

Mark activity viewed for completion-tracking.

Since
Moodle 3.3

◆ trigger_module_viewed()

mod_feedback_completion::trigger_module_viewed ( )

Trigger module viewed event.

Since
Moodle 3.3

Member Data Documentation

◆ $courseid

int mod_feedback_structure::$courseid = 0
protectedinherited

course where the feedback is filled.

For feedbacks that are NOT on the front page this is 0

◆ $feedback

stdClass mod_feedback_structure::$feedback
protectedinherited

record from 'feedback' table.

Reliably has fields: id, course, timeopen, timeclose, anonymous, completionsubmit. For full object or to access any other field use $this->get_feedback()


The documentation for this class was generated from the following file: