|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00025 global $CFG; 00026 require_once("HTML/QuickForm/element.php"); 00027 require_once($CFG->dirroot.'/grade/grading/form/lib.php'); 00028 00029 if (class_exists('HTML_QuickForm')) { 00030 HTML_QuickForm::registerRule('gradingvalidated', 'callback', '_validate', 'MoodleQuickForm_grading'); 00031 } 00032 00043 class MoodleQuickForm_grading extends HTML_QuickForm_input{ 00049 var $_helpbutton=''; 00050 00055 private $gradingattributes; 00056 00065 public function MoodleQuickForm_grading($elementName=null, $elementLabel=null, $attributes=null) { 00066 parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes); 00067 $this->gradingattributes = $attributes; 00068 } 00069 00075 public function get_gradinginstance() { 00076 if (is_array($this->gradingattributes) && array_key_exists('gradinginstance', $this->gradingattributes)) { 00077 return $this->gradingattributes['gradinginstance']; 00078 } else { 00079 return null; 00080 } 00081 } 00082 00088 public function toHtml(){ 00089 global $PAGE; 00090 return $this->get_gradinginstance()->render_grading_element($PAGE, $this); 00091 } 00092 00100 public function setHelpButton($helpbuttonargs, $function='helpbutton'){ 00101 debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead'); 00102 } 00103 00110 public function getHelpButton(){ 00111 return $this->_helpbutton; 00112 } 00113 00120 public function getElementTemplateType(){ 00121 return 'default'; 00122 } 00123 00135 public function onQuickFormEvent($event, $arg, &$caller) { 00136 if ($event == 'createElement') { 00137 $attributes = $arg[2]; 00138 if (!is_array($attributes) || !array_key_exists('gradinginstance', $attributes) || !($attributes['gradinginstance'] instanceof gradingform_instance)) { 00139 throw new moodle_exception('exc_gradingformelement', 'grading'); 00140 } 00141 } 00142 00143 $name = $this->getName(); 00144 if ($name && $caller->elementExists($name)) { 00145 $caller->addRule($name, $this->get_gradinginstance()->default_validation_error_message(), 'gradingvalidated', $this->gradingattributes); 00146 } 00147 return parent::onQuickFormEvent($event, $arg, $caller); 00148 } 00149 00157 static function _validate($elementValue, $attributes = null) { 00158 return $attributes['gradinginstance']->validate_grading_element($elementValue); 00159 } 00160 }