Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/quiz/settingslib.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00028 defined('MOODLE_INTERNAL') || die();
00029 
00030 
00037 class mod_quiz_admin_review_setting extends admin_setting {
00042     const DURING =            0x10000;
00043     const IMMEDIATELY_AFTER = 0x01000;
00044     const LATER_WHILE_OPEN =  0x00100;
00045     const AFTER_CLOSE =       0x00010;
00051     protected $duringstate;
00052 
00058     public static function fields() {
00059         return array(
00060             'attempt' => get_string('theattempt', 'quiz'),
00061             'correctness' => get_string('whethercorrect', 'question'),
00062             'marks' => get_string('marks', 'question'),
00063             'specificfeedback' => get_string('specificfeedback', 'question'),
00064             'generalfeedback' => get_string('generalfeedback', 'question'),
00065             'rightanswer' => get_string('rightanswer', 'question'),
00066             'overallfeedback' => get_string('overallfeedback', 'quiz'),
00067         );
00068     }
00069 
00070     public function __construct($name, $visiblename, $description,
00071             $defaultsetting, $duringstate = null) {
00072         $this->duringstate = $duringstate;
00073         parent::__construct($name, $visiblename, $description, $defaultsetting);
00074     }
00075 
00079     public static function all_on() {
00080         return self::DURING | self::IMMEDIATELY_AFTER | self::LATER_WHILE_OPEN |
00081                 self::AFTER_CLOSE;
00082     }
00083 
00084     protected static function times() {
00085         return array(
00086             self::DURING => get_string('reviewduring', 'quiz'),
00087             self::IMMEDIATELY_AFTER => get_string('reviewimmediately', 'quiz'),
00088             self::LATER_WHILE_OPEN => get_string('reviewopen', 'quiz'),
00089             self::AFTER_CLOSE => get_string('reviewclosed', 'quiz'),
00090         );
00091     }
00092 
00093     protected function normalise_data($data) {
00094         $times = self::times();
00095         $value = 0;
00096         foreach ($times as $timemask => $name) {
00097             if ($timemask == self::DURING && !is_null($this->duringstate)) {
00098                 if ($this->duringstate) {
00099                     $value += $timemask;
00100                 }
00101             } else if (!empty($data[$timemask])) {
00102                 $value += $timemask;
00103             }
00104         }
00105         return $value;
00106     }
00107 
00108     public function get_setting() {
00109         return $this->config_read($this->name);
00110     }
00111 
00112     public function write_setting($data) {
00113         if (is_array($data) || empty($data)) {
00114             $data = $this->normalise_data($data);
00115         }
00116         $this->config_write($this->name, $data);
00117         return '';
00118     }
00119 
00120     public function output_html($data, $query = '') {
00121         if (is_array($data) || empty($data)) {
00122             $data = $this->normalise_data($data);
00123         }
00124 
00125         $return = '<div class="group"><input type="hidden" name="' .
00126                     $this->get_full_name() . '[' . self::DURING . ']" value="0" />';
00127         foreach (self::times() as $timemask => $namestring) {
00128             $id = $this->get_id(). '_' . $timemask;
00129             $state = '';
00130             if ($data & $timemask) {
00131                 $state = 'checked="checked" ';
00132             }
00133             if ($timemask == self::DURING && !is_null($this->duringstate)) {
00134                 $state = 'disabled="disabled" ';
00135                 if ($this->duringstate) {
00136                     $state .= 'checked="checked" ';
00137                 }
00138             }
00139             $return .= '<span><input type="checkbox" name="' .
00140                     $this->get_full_name() . '[' . $timemask . ']" value="1" id="' . $id .
00141                     '" ' . $state . '/> <label for="' . $id . '">' .
00142                     $namestring . "</label></span>\n";
00143         }
00144         $return .= "</div>\n";
00145 
00146         return format_admin_setting($this, $this->visiblename, $return,
00147                 $this->description, true, '', get_string('everythingon', 'quiz'), $query);
00148     }
00149 }
00150 
00151 
00160 class mod_quiz_admin_setting_grademethod extends admin_setting_configselect_with_advanced {
00161     public function load_choices() {
00162         global $CFG;
00163 
00164         if (is_array($this->choices)) {
00165             return true;
00166         }
00167 
00168         require_once($CFG->dirroot . '/mod/quiz/locallib.php');
00169         $this->choices = quiz_get_grading_options();
00170 
00171         return true;
00172     }
00173 }
00174 
00175 
00184 class mod_quiz_admin_setting_browsersecurity extends admin_setting_configselect_with_advanced {
00185     public function load_choices() {
00186         global $CFG;
00187 
00188         if (is_array($this->choices)) {
00189             return true;
00190         }
00191 
00192         require_once($CFG->dirroot . '/mod/quiz/locallib.php');
00193         $this->choices = quiz_access_manager::get_browser_security_choices();
00194 
00195         return true;
00196     }
00197 }
 All Data Structures Namespaces Files Functions Variables Enumerations