[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/question/behaviour/immediatefeedback/ -> behaviour.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  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/>.
  16  
  17  /**
  18   * Question behaviour where the student can submit questions one at a
  19   * time for immediate feedback.
  20   *
  21   * @package    qbehaviour
  22   * @subpackage immediatefeedback
  23   * @copyright  2009 The Open University
  24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  
  28  defined('MOODLE_INTERNAL') || die();
  29  
  30  
  31  /**
  32   * Question behaviour for immediate feedback.
  33   *
  34   * Each question has a submit button next to it which the student can use to
  35   * submit it. Once the qustion is submitted, it is not possible for the
  36   * student to change their answer any more, but the student gets full feedback
  37   * straight away.
  38   *
  39   * @copyright  2009 The Open University
  40   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  41   */
  42  class qbehaviour_immediatefeedback extends question_behaviour_with_save {
  43      const IS_ARCHETYPAL = true;
  44  
  45      public function is_compatible_question(question_definition $question) {
  46          return $question instanceof question_automatically_gradable;
  47      }
  48  
  49      public function get_min_fraction() {
  50          return $this->question->get_min_fraction();
  51      }
  52  
  53      public function get_expected_data() {
  54          if ($this->qa->get_state()->is_active()) {
  55              return array(
  56                  'submit' => PARAM_BOOL,
  57              );
  58          }
  59          return parent::get_expected_data();
  60      }
  61  
  62      public function get_state_string($showcorrectness) {
  63          $state = $this->qa->get_state();
  64          if ($state == question_state::$todo) {
  65              return get_string('notcomplete', 'qbehaviour_immediatefeedback');
  66          } else {
  67              return parent::get_state_string($showcorrectness);
  68          }
  69      }
  70  
  71      public function get_right_answer_summary() {
  72          return $this->question->get_right_answer_summary();
  73      }
  74  
  75      public function process_action(question_attempt_pending_step $pendingstep) {
  76          if ($pendingstep->has_behaviour_var('comment')) {
  77              return $this->process_comment($pendingstep);
  78          } else if ($pendingstep->has_behaviour_var('submit')) {
  79              return $this->process_submit($pendingstep);
  80          } else if ($pendingstep->has_behaviour_var('finish')) {
  81              return $this->process_finish($pendingstep);
  82          } else {
  83              return $this->process_save($pendingstep);
  84          }
  85      }
  86  
  87      public function summarise_action(question_attempt_step $step) {
  88          if ($step->has_behaviour_var('comment')) {
  89              return $this->summarise_manual_comment($step);
  90          } else if ($step->has_behaviour_var('finish')) {
  91              return $this->summarise_finish($step);
  92          } else if ($step->has_behaviour_var('submit')) {
  93              return $this->summarise_submit($step);
  94          } else {
  95              return $this->summarise_save($step);
  96          }
  97      }
  98  
  99      public function process_submit(question_attempt_pending_step $pendingstep) {
 100          if ($this->qa->get_state()->is_finished()) {
 101              return question_attempt::DISCARD;
 102          }
 103  
 104          if (!$this->is_complete_response($pendingstep)) {
 105              $pendingstep->set_state(question_state::$invalid);
 106  
 107          } else {
 108              $response = $pendingstep->get_qt_data();
 109              list($fraction, $state) = $this->question->grade_response($response);
 110              $pendingstep->set_fraction($fraction);
 111              $pendingstep->set_state($state);
 112              $pendingstep->set_new_response_summary($this->question->summarise_response($response));
 113          }
 114          return question_attempt::KEEP;
 115      }
 116  
 117      public function process_finish(question_attempt_pending_step $pendingstep) {
 118          if ($this->qa->get_state()->is_finished()) {
 119              return question_attempt::DISCARD;
 120          }
 121  
 122          $response = $this->qa->get_last_step()->get_qt_data();
 123          if (!$this->question->is_gradable_response($response)) {
 124              $pendingstep->set_state(question_state::$gaveup);
 125  
 126          } else {
 127              list($fraction, $state) = $this->question->grade_response($response);
 128              $pendingstep->set_fraction($fraction);
 129              $pendingstep->set_state($state);
 130          }
 131          $pendingstep->set_new_response_summary($this->question->summarise_response($response));
 132          return question_attempt::KEEP;
 133      }
 134  
 135      public function process_save(question_attempt_pending_step $pendingstep) {
 136          $status = parent::process_save($pendingstep);
 137          if ($status == question_attempt::KEEP &&
 138                  $pendingstep->get_state() == question_state::$complete) {
 139              $pendingstep->set_state(question_state::$todo);
 140          }
 141          return $status;
 142      }
 143  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1