MDL-14967 Upgraded gradebook code and unit tests. 4 failing tests in grade_item to fix.

This commit is contained in:
nicolasconnault
2008-05-23 14:52:50 +00:00
parent 3a4ff63b31
commit da3801e84b
12 changed files with 775 additions and 743 deletions
+24 -22
View File
@@ -34,45 +34,45 @@ class grade_scale extends grade_object {
* DB Table (used by grade_object).
* @var string $table
*/
var $table = 'scale';
public $table = 'scale';
/**
* Array of required table fields, must start with 'id'.
* @var array $required_fields
*/
var $required_fields = array('id', 'courseid', 'userid', 'name', 'scale', 'description', 'timemodified');
public $required_fields = array('id', 'courseid', 'userid', 'name', 'scale', 'description', 'timemodified');
/**
* The course this scale belongs to.
* @var int $courseid
*/
var $courseid;
public $courseid;
var $userid;
public $userid;
/**
* The name of the scale.
* @var string $name
*/
var $name;
public $name;
/**
* The items in this scale.
* @var array $scale_items
*/
var $scale_items = array();
public $scale_items = array();
/**
* A string representatin of the scale items (a comma-separated list).
* @var string $scale
*/
var $scale;
public $scale;
/**
* A description for this scale.
* @var string $description
*/
var $description;
public $description;
/**
* Finds and returns a grade_scale instance based on params.
@@ -81,7 +81,7 @@ class grade_scale extends grade_object {
* @param array $params associative arrays varname=>value
* @return object grade_scale instance or false if none found.
*/
function fetch($params) {
public static function fetch($params) {
return grade_object::fetch_helper('scale', 'grade_scale', $params);
}
@@ -92,7 +92,7 @@ class grade_scale extends grade_object {
* @param array $params associative arrays varname=>value
* @return array array of grade_scale insatnces or false if none found.
*/
function fetch_all($params) {
public static function fetch_all($params) {
return grade_object::fetch_all_helper('scale', 'grade_scale', $params);
}
@@ -103,7 +103,7 @@ class grade_scale extends grade_object {
* @param string $source from where was the object inserted (mod/forum, manual, etc.)
* @return int PK ID if successful, false otherwise
*/
function insert($source=null) {
public function insert($source=null) {
$this->timecreated = time();
$this->timemodified = time();
return parent::insert($source);
@@ -114,7 +114,7 @@ class grade_scale extends grade_object {
* @param string $source from where was the object inserted
* @return boolean success
*/
function update($source=null) {
public function update($source=null) {
$this->timemodified = time();
return parent::update($source);
}
@@ -124,7 +124,7 @@ class grade_scale extends grade_object {
* when we do not know the exact type of an object.
* @return string name
*/
function get_name() {
public function get_name() {
return format_string($this->name);
}
@@ -138,7 +138,7 @@ class grade_scale extends grade_object {
* @param mixed $items Could be null, a string or an array. The method behaves differently for each case.
* @return array The resulting array of scale items or null if the method failed to produce one.
*/
function load_items($items=NULL) {
public function load_items($items=NULL) {
if (empty($items)) {
$this->scale_items = explode(',', $this->scale);
} elseif (is_array($items)) {
@@ -168,7 +168,7 @@ class grade_scale extends grade_object {
* @param mixed $items Could be null, a string or an array. The method behaves differently for each case.
* @return array The resulting string of scale items or null if the method failed to produce one.
*/
function compact_items($items=NULL) {
public function compact_items($items=NULL) {
if (empty($items)) {
$this->scale = implode(',', $this->scale_items);
} elseif (is_array($items)) {
@@ -188,9 +188,10 @@ class grade_scale extends grade_object {
* @param float $grade
* @return string
*/
function get_nearest_item($grade) {
public function get_nearest_item($grade) {
global $DB;
// Obtain nearest scale item from average
$scales_array = get_records_list('scale', 'id', $this->id);
$scales_array = $DB->get_records_list('scale', array('id' => $this->id));
$scale = $scales_array[$this->id];
$scales = explode(",", $scale->scale);
@@ -206,7 +207,7 @@ class grade_scale extends grade_object {
* Static function returning all global scales
* @return object
*/
function fetch_all_global() {
public function fetch_all_global() {
return grade_scale::fetch_all(array('courseid'=>0));
}
@@ -214,7 +215,7 @@ class grade_scale extends grade_object {
* Static function returning all local course scales
* @return object
*/
function fetch_all_local($courseid) {
public static function fetch_all_local($courseid) {
return grade_scale::fetch_all(array('courseid'=>$courseid));
}
@@ -222,7 +223,7 @@ class grade_scale extends grade_object {
* Checks if scale can be deleted.
* @return boolean
*/
function can_delete() {
public function can_delete() {
return !$this->is_used();
}
@@ -230,7 +231,8 @@ class grade_scale extends grade_object {
* Returns if scale used anywhere - activities, grade items, outcomes, etc.
* @return bool
*/
function is_used() {
public function is_used() {
global $DB;
global $CFG;
// count grade items excluding the
@@ -246,7 +248,7 @@ class grade_scale extends grade_object {
}
$legacy_mods = false;
if ($mods = get_records('modules', 'visible', 1)) {
if ($mods = $DB->get_records('modules', array('visible' => 1))) {
foreach ($mods as $mod) {
//Check cm->name/lib.php exists
if (file_exists($CFG->dirroot.'/mod/'.$mod->name.'/lib.php')) {