| Línea 13... |
Línea 13... |
| 13 |
//
|
13 |
//
|
| 14 |
// You should have received a copy of the GNU General Public License
|
14 |
// You should have received a copy of the GNU General Public License
|
| 15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
| Línea 16... |
Línea 16... |
| 16 |
|
16 |
|
| 17 |
/**
|
- |
|
| 18 |
* Contains class mod_feedback_completion
|
- |
|
| 19 |
*
|
- |
|
| 20 |
* @package mod_feedback
|
- |
|
| 21 |
* @copyright 2016 Marina Glancy
|
- |
|
| 22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
- |
|
| 23 |
*/
|
- |
|
| 24 |
|
- |
|
| 25 |
defined('MOODLE_INTERNAL') || die();
|
- |
|
| 26 |
|
- |
|
| 27 |
/**
|
17 |
/**
|
| 28 |
* Collects information and methods about feedback completion (either complete.php or show_entries.php)
|
18 |
* Collects information and methods about feedback completion (either complete.php or show_entries.php)
|
| 29 |
*
|
19 |
*
|
| 30 |
* @package mod_feedback
|
20 |
* @package mod_feedback
|
| 31 |
* @copyright 2016 Marina Glancy
|
21 |
* @copyright 2016 Marina Glancy
|
| Línea 90... |
Línea 80... |
| 90 |
// not the current state that may have been changed later by the teacher.
|
80 |
// not the current state that may have been changed later by the teacher.
|
| 91 |
$params['anonymous_response'] = FEEDBACK_ANONYMOUS_NO;
|
81 |
$params['anonymous_response'] = FEEDBACK_ANONYMOUS_NO;
|
| 92 |
$params['userid'] = $nonanonymouseuserid;
|
82 |
$params['userid'] = $nonanonymouseuserid;
|
| 93 |
}
|
83 |
}
|
| 94 |
$this->completed = $DB->get_record('feedback_completed', $params, '*', MUST_EXIST);
|
84 |
$this->completed = $DB->get_record('feedback_completed', $params, '*', MUST_EXIST);
|
| - |
|
85 |
|
| - |
|
86 |
if (!groups_user_groups_visible($this->feedback->course, $this->completed->userid, $cm)) {
|
| - |
|
87 |
throw new moodle_exception('nopermissiontoshow');
|
| - |
|
88 |
}
|
| - |
|
89 |
|
| 95 |
$this->courseid = $this->completed->courseid;
|
90 |
$this->courseid = $this->completed->courseid;
|
| 96 |
}
|
91 |
}
|
| 97 |
}
|
92 |
}
|
| Línea 98... |
Línea 93... |
| 98 |
|
93 |
|
| Línea 548... |
Línea 543... |
| 548 |
* {@link save_response_tmp()}. This function copies the values
|
543 |
* {@link save_response_tmp()}. This function copies the values
|
| 549 |
* from the temporary table to the completion table.
|
544 |
* from the temporary table to the completion table.
|
| 550 |
* It is also responsible for sending email notifications when applicable.
|
545 |
* It is also responsible for sending email notifications when applicable.
|
| 551 |
*/
|
546 |
*/
|
| 552 |
public function save_response() {
|
547 |
public function save_response() {
|
| 553 |
global $SESSION, $DB, $USER;
|
548 |
global $DB, $USER;
|
| Línea 554... |
Línea 549... |
| 554 |
|
549 |
|
| 555 |
$feedbackcompleted = $this->find_last_completed();
|
550 |
$feedbackcompleted = $this->find_last_completed();
|
| 556 |
// If no record is found, change false to null for safe use in feedback_save_tmp_values.
|
551 |
// If no record is found, change false to null for safe use in feedback_save_tmp_values.
|
| 557 |
$feedbackcompleted = !$feedbackcompleted ? null : $feedbackcompleted;
|
552 |
$feedbackcompleted = !$feedbackcompleted ? null : $feedbackcompleted;
|
| Línea 558... |
Línea -... |
| 558 |
$feedbackcompletedtmp = $this->get_current_completed_tmp();
|
- |
|
| 559 |
|
- |
|
| 560 |
if (feedback_check_is_switchrole()) {
|
- |
|
| 561 |
// We do not actually save anything if the role is switched, just delete temporary values.
|
- |
|
| 562 |
$this->delete_completedtmp();
|
- |
|
| 563 |
return;
|
- |
|
| 564 |
}
|
553 |
$feedbackcompletedtmp = $this->get_current_completed_tmp();
|
| 565 |
|
554 |
|
| 566 |
// Save values.
|
555 |
// Save values.
|
| Línea 567... |
Línea 556... |
| 567 |
$completedid = feedback_save_tmp_values($feedbackcompletedtmp, $feedbackcompleted);
|
556 |
$completedid = feedback_save_tmp_values($feedbackcompletedtmp, $feedbackcompleted);
|
| Línea 572... |
Línea 561... |
| 572 |
feedback_send_email($this->cm, $this->feedback, $this->cm->get_course(), $this->userid, $this->completed);
|
561 |
feedback_send_email($this->cm, $this->feedback, $this->cm->get_course(), $this->userid, $this->completed);
|
| 573 |
} else {
|
562 |
} else {
|
| 574 |
feedback_send_email_anonym($this->cm, $this->feedback, $this->cm->get_course());
|
563 |
feedback_send_email_anonym($this->cm, $this->feedback, $this->cm->get_course());
|
| 575 |
}
|
564 |
}
|
| Línea 576... |
Línea -... |
| 576 |
|
- |
|
| 577 |
unset($SESSION->feedback->is_started);
|
- |
|
| 578 |
|
565 |
|
| 579 |
// Update completion state.
|
566 |
// Update completion state.
|
| 580 |
$completion = new completion_info($this->cm->get_course());
|
567 |
$completion = new completion_info($this->cm->get_course());
|
| 581 |
if ((isloggedin() || $USER->id != $this->userid) && $completion->is_enabled($this->cm) &&
|
568 |
if ((isloggedin() || $USER->id != $this->userid) && $completion->is_enabled($this->cm) &&
|
| 582 |
$this->cm->completion == COMPLETION_TRACKING_AUTOMATIC && $this->feedback->completionsubmit) {
|
569 |
$this->cm->completion == COMPLETION_TRACKING_AUTOMATIC && $this->feedback->completionsubmit) {
|
| 583 |
$completion->update_state($this->cm, COMPLETION_COMPLETE, $this->userid);
|
570 |
$completion->update_state($this->cm, COMPLETION_COMPLETE, $this->userid);
|
| 584 |
}
|
571 |
}
|
| Línea 585... |
Línea 572... |
| 585 |
}
|
572 |
}
|
| 586 |
|
- |
|
| 587 |
/**
|
- |
|
| 588 |
* Deletes the temporary completed and all related temporary values
|
- |
|
| 589 |
*/
|
- |
|
| 590 |
protected function delete_completedtmp() {
|
- |
|
| 591 |
global $DB;
|
- |
|
| 592 |
|
- |
|
| 593 |
if ($completedtmp = $this->get_current_completed_tmp()) {
|
- |
|
| 594 |
$DB->delete_records('feedback_valuetmp', ['completed' => $completedtmp->id]);
|
- |
|
| 595 |
$DB->delete_records('feedback_completedtmp', ['id' => $completedtmp->id]);
|
- |
|
| 596 |
$this->completedtmp = null;
|
- |
|
| 597 |
}
|
- |
|
| 598 |
}
|
- |
|
| 599 |
|
573 |
|
| 600 |
/**
|
574 |
/**
|
| 601 |
* Retrieves the last completion record for the current user
|
575 |
* Retrieves the last completion record for the current user
|
| 602 |
*
|
576 |
*
|
| 603 |
* @return stdClass record from feedback_completed or false if not found
|
577 |
* @return stdClass record from feedback_completed or false if not found
|
| Línea 702... |
Línea 676... |
| 702 |
* @param int $gopreviouspage if the user chose to go to the previous page
|
676 |
* @param int $gopreviouspage if the user chose to go to the previous page
|
| 703 |
* @return string the url to redirect the user (if any)
|
677 |
* @return string the url to redirect the user (if any)
|
| 704 |
* @since Moodle 3.3
|
678 |
* @since Moodle 3.3
|
| 705 |
*/
|
679 |
*/
|
| 706 |
public function process_page($gopage, $gopreviouspage = false) {
|
680 |
public function process_page($gopage, $gopreviouspage = false) {
|
| 707 |
global $CFG, $PAGE, $SESSION;
|
681 |
global $PAGE;
|
| Línea 708... |
Línea 682... |
| 708 |
|
682 |
|
| Línea 709... |
Línea 683... |
| 709 |
$urltogo = null;
|
683 |
$urltogo = null;
|
| 710 |
|
684 |
|
| Línea 718... |
Línea 692... |
| 718 |
$urltogo = new moodle_url('/mod/feedback/view.php', ['id' => $this->get_cm()->id]);
|
692 |
$urltogo = new moodle_url('/mod/feedback/view.php', ['id' => $this->get_cm()->id]);
|
| 719 |
} else if ($this->form->is_submitted() &&
|
693 |
} else if ($this->form->is_submitted() &&
|
| 720 |
($this->form->is_validated() || $gopreviouspage)) {
|
694 |
($this->form->is_validated() || $gopreviouspage)) {
|
| 721 |
// Form was submitted (skip validation for "Previous page" button).
|
695 |
// Form was submitted (skip validation for "Previous page" button).
|
| 722 |
$data = $this->form->get_submitted_data();
|
696 |
$data = $this->form->get_submitted_data();
|
| 723 |
if (!isset($SESSION->feedback->is_started) OR !$SESSION->feedback->is_started == true) {
|
- |
|
| 724 |
throw new \moodle_exception('error', '', $CFG->wwwroot.'/course/view.php?id='.$this->courseid);
|
- |
|
| 725 |
}
|
- |
|
| 726 |
$this->save_response_tmp($data);
|
697 |
$this->save_response_tmp($data);
|
| 727 |
if (!empty($data->savevalues) || !empty($data->gonextpage)) {
|
698 |
if (!empty($data->savevalues) || !empty($data->gonextpage)) {
|
| 728 |
if (($nextpage = $this->get_next_page($gopage)) !== null) {
|
699 |
if (($nextpage = $this->get_next_page($gopage)) !== null) {
|
| 729 |
if ($PAGE->has_set_url()) {
|
700 |
if ($PAGE->has_set_url()) {
|
| 730 |
$urltogo = new moodle_url($PAGE->url, array('gopage' => $nextpage));
|
701 |
$urltogo = new moodle_url($PAGE->url, array('gopage' => $nextpage));
|
| Línea 753... |
Línea 724... |
| 753 |
*
|
724 |
*
|
| 754 |
* @return string the form rendered
|
725 |
* @return string the form rendered
|
| 755 |
* @since Moodle 3.3
|
726 |
* @since Moodle 3.3
|
| 756 |
*/
|
727 |
*/
|
| 757 |
public function render_items() {
|
728 |
public function render_items() {
|
| 758 |
global $SESSION;
|
- |
|
| 759 |
|
- |
|
| 760 |
// Print the items.
|
- |
|
| 761 |
$SESSION->feedback->is_started = true;
|
- |
|
| 762 |
return $this->form->render();
|
729 |
return $this->form->render();
|
| 763 |
}
|
730 |
}
|
| 764 |
}
|
- |
|
| 765 |
|
731 |
}
|
| - |
|
732 |
|