mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 09:26:35 +02:00
MDL-22999 core_grades: Added ability to configure maximum grade value both globally and for each graded-activity.
This commit is contained in:
parent
1a727e121e
commit
597662335d
7 changed files with 369 additions and 36 deletions
123
lib/adminlib.php
123
lib/adminlib.php
|
@ -4799,6 +4799,129 @@ class admin_setting_special_gradeexport extends admin_setting_configmulticheckbo
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* A setting for setting the default grade point value. Must be an integer between 1 and $CFG->gradepointmax.
|
||||
*
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class admin_setting_special_gradepointdefault extends admin_setting_configtext {
|
||||
/**
|
||||
* Config gradepointmax constructor
|
||||
*
|
||||
* @param string $name Overidden by "gradepointmax"
|
||||
* @param string $visiblename Overridden by "gradepointmax" language string.
|
||||
* @param string $description Overridden by "gradepointmax_help" language string.
|
||||
* @param string $defaultsetting Not used, overridden by 100.
|
||||
* @param mixed $paramtype Overridden by PARAM_INT.
|
||||
* @param int $size Overridden by 5.
|
||||
*/
|
||||
public function __construct($name = '', $visiblename = '', $description = '', $defaultsetting = '', $paramtype = PARAM_INT, $size = 5) {
|
||||
$name = 'gradepointdefault';
|
||||
$visiblename = get_string('gradepointdefault', 'grades');
|
||||
$description = get_string('gradepointdefault_help', 'grades');
|
||||
$defaultsetting = 100;
|
||||
$paramtype = PARAM_INT;
|
||||
$size = 5;
|
||||
parent::__construct($name, $visiblename, $description, $defaultsetting, $paramtype, $size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate data before storage
|
||||
* @param string $data The submitted data
|
||||
* @return bool|string true if ok, string if error found
|
||||
*/
|
||||
public function validate($data) {
|
||||
global $CFG;
|
||||
if (((string)(int)$data === (string)$data && $data > 0 && $data <= $CFG->gradepointmax)) {
|
||||
return true;
|
||||
} else {
|
||||
return get_string('gradepointdefault_validateerror', 'grades');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A setting for setting the maximum grade value. Must be an integer between 1 and 10000.
|
||||
*
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class admin_setting_special_gradepointmax extends admin_setting_configtext {
|
||||
|
||||
/**
|
||||
* Config gradepointmax constructor
|
||||
*
|
||||
* @param string $name Overidden by "gradepointmax"
|
||||
* @param string $visiblename Overridden by "gradepointmax" language string.
|
||||
* @param string $description Overridden by "gradepointmax_help" language string.
|
||||
* @param string $defaultsetting Not used, overridden by 100.
|
||||
* @param mixed $paramtype Overridden by PARAM_INT.
|
||||
* @param int $size Overridden by 5.
|
||||
*/
|
||||
public function __construct($name = '', $visiblename = '', $description = '', $defaultsetting = '', $paramtype = PARAM_INT, $size = 5) {
|
||||
$name = 'gradepointmax';
|
||||
$visiblename = get_string('gradepointmax', 'grades');
|
||||
$description = get_string('gradepointmax_help', 'grades');
|
||||
$defaultsetting = 100;
|
||||
$paramtype = PARAM_INT;
|
||||
$size = 5;
|
||||
parent::__construct($name, $visiblename, $description, $defaultsetting, $paramtype, $size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the selected setting
|
||||
*
|
||||
* @param string $data The selected site
|
||||
* @return string empty string or error message
|
||||
*/
|
||||
public function write_setting($data) {
|
||||
if ($data === '') {
|
||||
$data = (int)$this->defaultsetting;
|
||||
} else {
|
||||
$data = $data;
|
||||
}
|
||||
return parent::write_setting($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate data before storage
|
||||
* @param string $data The submitted data
|
||||
* @return bool|string true if ok, string if error found
|
||||
*/
|
||||
public function validate($data) {
|
||||
if (((string)(int)$data === (string)$data && $data > 0 && $data <= 10000)) {
|
||||
return true;
|
||||
} else {
|
||||
return get_string('gradepointmax_validateerror', 'grades');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an XHTML string for the setting
|
||||
* @param array $data Associative array of value=>xx, forced=>xx, adv=>xx
|
||||
* @param string $query search query to be highlighted
|
||||
* @return string XHTML to display control
|
||||
*/
|
||||
public function output_html($data, $query = '') {
|
||||
$default = $this->get_defaultsetting();
|
||||
|
||||
$attr = array(
|
||||
'type' => 'text',
|
||||
'size' => $this->size,
|
||||
'id' => $this->get_id(),
|
||||
'name' => $this->get_full_name(),
|
||||
'value' => s($data),
|
||||
'maxlength' => '5'
|
||||
);
|
||||
$input = html_writer::empty_tag('input', $attr);
|
||||
|
||||
$attr = array('class' => 'form-text defaultsnext');
|
||||
$div = html_writer::tag('div', $input, $attr);
|
||||
return format_admin_setting($this, $this->visiblename, $div, $this->description, true, '', $default, $query);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Grade category settings
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue