|
Moodle
2.2.1
http://www.collinsharper.com
|
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 00027 defined('MOODLE_INTERNAL') || die(); 00028 00029 00039 abstract class question_state { 00043 public static $notstarted; 00044 public static $unprocessed; 00045 public static $todo; 00046 public static $invalid; 00047 public static $complete; 00048 public static $needsgrading; 00049 public static $finished; 00050 public static $gaveup; 00051 public static $gradedwrong; 00052 public static $gradedpartial; 00053 public static $gradedright; 00054 public static $manfinished; 00055 public static $mangaveup; 00056 public static $mangrwrong; 00057 public static $mangrpartial; 00058 public static $mangrright; 00061 protected function __construct() { 00062 } 00063 00064 public static function init() { 00065 $us = new ReflectionClass('question_state'); 00066 foreach ($us->getStaticProperties() as $name => $notused) { 00067 $class = 'question_state_' . $name; 00068 $states[$name] = new $class(); 00069 self::$$name = $states[$name]; 00070 } 00071 } 00072 00077 public static function get_all() { 00078 $states = array(); 00079 $us = new ReflectionClass('question_state'); 00080 foreach ($us->getStaticProperties() as $name => $notused) { 00081 $states[] = self::$$name; 00082 } 00083 return $states; 00084 } 00085 00092 public static function get_all_for_summary_state($summarystate) { 00093 $states = array(); 00094 foreach (self::get_all() as $state) { 00095 if ($state->get_summary_state() == $summarystate) { 00096 $states[] = $state; 00097 } 00098 } 00099 if (empty($states)) { 00100 throw new coding_exception('unknown summary state ' . $summarystate); 00101 } 00102 return $states; 00103 } 00104 00108 public function __toString() { 00109 return substr(get_class($this), 15); 00110 } 00111 00116 public static function get($name) { 00117 return self::$$name; 00118 } 00119 00125 public function is_active() { 00126 return false; 00127 } 00128 00134 public function is_finished() { 00135 return true; 00136 } 00137 00142 public function is_graded() { 00143 return false; 00144 } 00145 00150 public function is_correct() { 00151 return false; 00152 } 00153 00158 public function is_partially_correct() { 00159 return false; 00160 } 00161 00166 public function is_incorrect() { 00167 return false; 00168 } 00169 00174 public function is_gave_up() { 00175 return false; 00176 } 00177 00182 public function is_commented() { 00183 return false; 00184 } 00185 00191 public function get_summary_state() { 00192 if (!$this->is_finished()) { 00193 return 'inprogress'; 00194 } else if ($this == self::$needsgrading) { 00195 return 'needsgrading'; 00196 } else if ($this->is_commented()) { 00197 return 'manuallygraded'; 00198 } else { 00199 return 'autograded'; 00200 } 00201 } 00202 00211 public static function graded_state_for_fraction($fraction) { 00212 if ($fraction < 0.000001) { 00213 return self::$gradedwrong; 00214 } else if ($fraction > 0.999999) { 00215 return self::$gradedright; 00216 } else { 00217 return self::$gradedpartial; 00218 } 00219 } 00220 00229 public static function manually_graded_state_for_fraction($fraction) { 00230 if (is_null($fraction)) { 00231 return self::$needsgrading; 00232 } else if ($fraction < 0.000001) { 00233 return self::$mangrwrong; 00234 } else if ($fraction > 0.999999) { 00235 return self::$mangrright; 00236 } else { 00237 return self::$mangrpartial; 00238 } 00239 } 00240 00247 public function corresponding_commented_state($fraction) { 00248 throw new coding_exception('Unexpected question state.'); 00249 } 00250 00256 public function get_feedback_class() { 00257 return ''; 00258 } 00259 00271 public abstract function get_state_class($showcorrectness); 00272 00280 public function default_string($showcorrectness) { 00281 return get_string($this->get_state_class($showcorrectness), 'question'); 00282 } 00283 } 00284 00285 00292 class question_state_notstarted extends question_state { 00293 public function is_finished() { 00294 return false; 00295 } 00296 public function get_state_class($showcorrectness) { 00297 throw new coding_exception('Unexpected question state.'); 00298 } 00299 } 00300 class question_state_unprocessed extends question_state { 00301 public function is_finished() { 00302 return false; 00303 } 00304 public function get_state_class($showcorrectness) { 00305 throw new coding_exception('Unexpected question state.'); 00306 } 00307 } 00308 class question_state_todo extends question_state { 00309 public function is_active() { 00310 return true; 00311 } 00312 public function is_finished() { 00313 return false; 00314 } 00315 public function get_state_class($showcorrectness) { 00316 return 'notyetanswered'; 00317 } 00318 } 00319 class question_state_invalid extends question_state { 00320 public function is_active() { 00321 return true; 00322 } 00323 public function is_finished() { 00324 return false; 00325 } 00326 public function get_state_class($showcorrectness) { 00327 return 'invalidanswer'; 00328 } 00329 } 00330 class question_state_complete extends question_state { 00331 public function is_active() { 00332 return true; 00333 } 00334 public function is_finished() { 00335 return false; 00336 } 00337 public function get_state_class($showcorrectness) { 00338 return 'answersaved'; 00339 } 00340 } 00341 class question_state_needsgrading extends question_state { 00342 public function get_state_class($showcorrectness) { 00343 if ($showcorrectness) { 00344 return 'requiresgrading'; 00345 } else { 00346 return 'complete'; 00347 } 00348 } 00349 public function corresponding_commented_state($fraction) { 00350 return self::manually_graded_state_for_fraction($fraction); 00351 } 00352 } 00353 class question_state_finished extends question_state { 00354 public function get_state_class($showcorrectness) { 00355 return 'complete'; 00356 } 00357 public function corresponding_commented_state($fraction) { 00358 return self::$manfinished; 00359 } 00360 } 00361 class question_state_gaveup extends question_state { 00362 public function is_gave_up() { 00363 return true; 00364 } 00365 public function get_feedback_class() { 00366 return 'incorrect'; 00367 } 00368 public function get_state_class($showcorrectness) { 00369 return 'notanswered'; 00370 } 00371 public function corresponding_commented_state($fraction) { 00372 if (is_null($fraction)) { 00373 return self::$mangaveup; 00374 } else { 00375 return self::manually_graded_state_for_fraction($fraction); 00376 } 00377 } 00378 } 00379 abstract class question_state_graded extends question_state { 00380 public function is_graded() { 00381 return true; 00382 } 00383 public function get_state_class($showcorrectness) { 00384 if ($showcorrectness) { 00385 return $this->get_feedback_class(); 00386 } else { 00387 return 'complete'; 00388 } 00389 } 00390 public function corresponding_commented_state($fraction) { 00391 return self::manually_graded_state_for_fraction($fraction); 00392 } 00393 } 00394 class question_state_gradedwrong extends question_state_graded { 00395 public function is_incorrect() { 00396 return true; 00397 } 00398 public function get_feedback_class() { 00399 return 'incorrect'; 00400 } 00401 } 00402 class question_state_gradedpartial extends question_state_graded { 00403 public function is_graded() { 00404 return true; 00405 } 00406 public function is_partially_correct() { 00407 return true; 00408 } 00409 public function get_feedback_class() { 00410 return 'partiallycorrect'; 00411 } 00412 } 00413 class question_state_gradedright extends question_state_graded { 00414 public function is_graded() { 00415 return true; 00416 } 00417 public function is_correct() { 00418 return true; 00419 } 00420 public function get_feedback_class() { 00421 return 'correct'; 00422 } 00423 } 00424 class question_state_manfinished extends question_state_finished { 00425 public function is_commented() { 00426 return true; 00427 } 00428 } 00429 class question_state_mangaveup extends question_state_gaveup { 00430 public function is_commented() { 00431 return true; 00432 } 00433 } 00434 abstract class question_state_manuallygraded extends question_state_graded { 00435 public function is_commented() { 00436 return true; 00437 } 00438 } 00439 class question_state_mangrwrong extends question_state_manuallygraded { 00440 public function is_incorrect() { 00441 return false; 00442 } 00443 public function get_feedback_class() { 00444 return 'incorrect'; 00445 } 00446 } 00447 class question_state_mangrpartial extends question_state_manuallygraded { 00448 public function is_partially_correct() { 00449 return true; 00450 } 00451 public function get_feedback_class() { 00452 return 'partiallycorrect'; 00453 } 00454 } 00455 class question_state_mangrright extends question_state_manuallygraded { 00456 public function is_correct() { 00457 return true; 00458 } 00459 public function get_feedback_class() { 00460 return 'correct'; 00461 } 00462 } 00464 question_state::init();