Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * Action for processing page answers by users
  20   *
  21   * @package mod_lesson
  22   * @copyright  2009 Sam Hemelryk
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   **/
  25  
  26  /** Require the specific libraries */
  27  require_once("../../config.php");
  28  require_once($CFG->dirroot.'/mod/lesson/locallib.php');
  29  
  30  $id = required_param('id', PARAM_INT);
  31  
  32  $cm = get_coursemodule_from_id('lesson', $id, 0, false, MUST_EXIST);
  33  $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
  34  $lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST), $cm, $course);
  35  
  36  require_login($course, false, $cm);
  37  require_sesskey();
  38  
  39  // Apply overrides.
  40  $lesson->update_effective_access($USER->id);
  41  
  42  $context = $lesson->context;
  43  $canmanage = $lesson->can_manage();
  44  $lessonoutput = $PAGE->get_renderer('mod_lesson');
  45  
  46  $url = new moodle_url('/mod/lesson/continue.php', array('id'=>$cm->id));
  47  $PAGE->set_url($url);
  48  $PAGE->set_pagetype('mod-lesson-view');
  49  $PAGE->navbar->add(get_string('continue', 'lesson'));
  50  
  51  // This is the code updates the lesson time for a timed test
  52  // get time information for this user
  53  if (!$canmanage) {
  54      $lesson->displayleft = lesson_displayleftif($lesson);
  55      $timer = $lesson->update_timer();
  56      if (!$lesson->check_time($timer)) {
  57          redirect(new moodle_url('/mod/lesson/view.php', array('id' => $cm->id, 'pageid' => LESSON_EOL, 'outoftime' => 'normal')));
  58          die; // Shouldn't be reached, but make sure.
  59      }
  60  } else {
  61      $timer = new stdClass;
  62  }
  63  
  64  // record answer (if necessary) and show response (if none say if answer is correct or not)
  65  $page = $lesson->load_page(required_param('pageid', PARAM_INT));
  66  
  67  $reviewmode = $lesson->is_in_review_mode();
  68  
  69  // Process the page responses.
  70  $result = $lesson->process_page_responses($page);
  71  
  72  if ($result->nodefaultresponse || $result->inmediatejump) {
  73      // Don't display feedback or force a redirecto to newpageid.
  74      redirect(new moodle_url('/mod/lesson/view.php', array('id'=>$cm->id,'pageid'=>$result->newpageid)));
  75  }
  76  
  77  // Set Messages.
  78  $lesson->add_messages_on_page_process($page, $result, $reviewmode);
  79  
  80  $PAGE->set_url('/mod/lesson/view.php', array('id' => $cm->id, 'pageid' => $page->id));
  81  $PAGE->set_subpage($page->id);
  82  
  83  /// Print the header, heading and tabs
  84  lesson_add_fake_blocks($PAGE, $cm, $lesson, $timer);
  85  echo $lessonoutput->header($lesson, $cm, 'view', true, $page->id, get_string('continue', 'lesson'));
  86  
  87  if ($lesson->displayleft) {
  88      echo '<a name="maincontent" id="maincontent" title="'.get_string('anchortitle', 'lesson').'"></a>';
  89  }
  90  // This calculates and prints the ongoing score message
  91  if ($lesson->ongoing && !$reviewmode) {
  92      echo $lessonoutput->ongoing_score($lesson);
  93  }
  94  if (!$reviewmode) {
  95      echo format_text($result->feedback, FORMAT_MOODLE, array('context' => $context, 'noclean' => true));
  96  }
  97  
  98  // User is modifying attempts - save button and some instructions
  99  if (isset($USER->modattempts[$lesson->id])) {
 100      $content = $OUTPUT->box(get_string("gotoendoflesson", "lesson"), 'center');
 101      $content .= $OUTPUT->box(get_string("or", "lesson"), 'center');
 102      $content .= $OUTPUT->box(get_string("continuetonextpage", "lesson"), 'center');
 103      $url = new moodle_url('/mod/lesson/view.php', array('id' => $cm->id, 'pageid' => LESSON_EOL));
 104      echo $content . $OUTPUT->single_button($url, get_string('finish', 'lesson'));
 105  }
 106  
 107  // Review button back
 108  if (!$result->correctanswer && !$result->noanswer && !$result->isessayquestion && !$reviewmode && $lesson->review && !$result->maxattemptsreached) {
 109      $url = new moodle_url('/mod/lesson/view.php', array('id' => $cm->id, 'pageid' => $page->id));
 110      echo $OUTPUT->single_button($url, get_string('reviewquestionback', 'lesson'));
 111  }
 112  
 113  $url = new moodle_url('/mod/lesson/view.php', array('id'=>$cm->id, 'pageid'=>$result->newpageid));
 114  
 115  if ($lesson->review && !$result->correctanswer && !$result->noanswer && !$result->isessayquestion && !$result->maxattemptsreached) {
 116      // If both the "Yes, I'd like to try again" and "No, I just want to go on  to the next question" point to the same
 117      // page then don't show the "No, I just want to go on to the next question" button. It's confusing.
 118      if ($page->id != $result->newpageid) {
 119          // Button to continue the lesson (the page to go is configured by the teacher).
 120          echo $OUTPUT->single_button($url, get_string('reviewquestioncontinue', 'lesson'));
 121      }
 122  } else {
 123      // Normal continue button
 124      echo $OUTPUT->single_button($url, get_string('continue', 'lesson'));
 125  }
 126  
 127  echo $lessonoutput->footer();