MDL-14967 Upgraded gradebook code and unit tests. 4 failing tests in grade_item to fix.
This commit is contained in:
@@ -30,13 +30,13 @@ class grade_category extends grade_object {
|
||||
* The DB table.
|
||||
* @var string $table
|
||||
*/
|
||||
var $table = 'grade_categories';
|
||||
public $table = 'grade_categories';
|
||||
|
||||
/**
|
||||
* Array of required table fields, must start with 'id'.
|
||||
* @var array $required_fields
|
||||
*/
|
||||
var $required_fields = array('id', 'courseid', 'parent', 'depth', 'path', 'fullname', 'aggregation',
|
||||
public $required_fields = array('id', 'courseid', 'parent', 'depth', 'path', 'fullname', 'aggregation',
|
||||
'keephigh', 'droplow', 'aggregateonlygraded', 'aggregateoutcomes',
|
||||
'aggregatesubcats', 'timecreated', 'timemodified');
|
||||
|
||||
@@ -44,104 +44,104 @@ class grade_category extends grade_object {
|
||||
* The course this category belongs to.
|
||||
* @var int $courseid
|
||||
*/
|
||||
var $courseid;
|
||||
public $courseid;
|
||||
|
||||
/**
|
||||
* The category this category belongs to (optional).
|
||||
* @var int $parent
|
||||
*/
|
||||
var $parent;
|
||||
public $parent;
|
||||
|
||||
/**
|
||||
* The grade_category object referenced by $this->parent (PK).
|
||||
* @var object $parent_category
|
||||
*/
|
||||
var $parent_category;
|
||||
public $parent_category;
|
||||
|
||||
/**
|
||||
* The number of parents this category has.
|
||||
* @var int $depth
|
||||
*/
|
||||
var $depth = 0;
|
||||
public $depth = 0;
|
||||
|
||||
/**
|
||||
* Shows the hierarchical path for this category as /1/2/3/ (like course_categories), the last number being
|
||||
* this category's autoincrement ID number.
|
||||
* @var string $path
|
||||
*/
|
||||
var $path;
|
||||
public $path;
|
||||
|
||||
/**
|
||||
* The name of this category.
|
||||
* @var string $fullname
|
||||
*/
|
||||
var $fullname;
|
||||
public $fullname;
|
||||
|
||||
/**
|
||||
* A constant pointing to one of the predefined aggregation strategies (none, mean, median, sum etc) .
|
||||
* @var int $aggregation
|
||||
*/
|
||||
var $aggregation = GRADE_AGGREGATE_MEAN;
|
||||
public $aggregation = GRADE_AGGREGATE_MEAN;
|
||||
|
||||
/**
|
||||
* Keep only the X highest items.
|
||||
* @var int $keephigh
|
||||
*/
|
||||
var $keephigh = 0;
|
||||
public $keephigh = 0;
|
||||
|
||||
/**
|
||||
* Drop the X lowest items.
|
||||
* @var int $droplow
|
||||
*/
|
||||
var $droplow = 0;
|
||||
public $droplow = 0;
|
||||
|
||||
/**
|
||||
* Aggregate only graded items
|
||||
* @var int $aggregateonlygraded
|
||||
*/
|
||||
var $aggregateonlygraded = 0;
|
||||
public $aggregateonlygraded = 0;
|
||||
|
||||
/**
|
||||
* Aggregate outcomes together with normal items
|
||||
* @var int $aggregateoutcomes
|
||||
*/
|
||||
var $aggregateoutcomes = 0;
|
||||
public $aggregateoutcomes = 0;
|
||||
|
||||
/**
|
||||
* Ignore subcategories when aggregating
|
||||
* @var int $aggregatesubcats
|
||||
*/
|
||||
var $aggregatesubcats = 0;
|
||||
public $aggregatesubcats = 0;
|
||||
|
||||
/**
|
||||
* Array of grade_items or grade_categories nested exactly 1 level below this category
|
||||
* @var array $children
|
||||
*/
|
||||
var $children;
|
||||
public $children;
|
||||
|
||||
/**
|
||||
* A hierarchical array of all children below this category. This is stored separately from
|
||||
* $children because it is more memory-intensive and may not be used as often.
|
||||
* @var array $all_children
|
||||
*/
|
||||
var $all_children;
|
||||
public $all_children;
|
||||
|
||||
/**
|
||||
* An associated grade_item object, with itemtype=category, used to calculate and cache a set of grade values
|
||||
* for this category.
|
||||
* @var object $grade_item
|
||||
*/
|
||||
var $grade_item;
|
||||
public $grade_item;
|
||||
|
||||
/**
|
||||
* Temporary sortorder for speedup of children resorting
|
||||
*/
|
||||
var $sortorder;
|
||||
public $sortorder;
|
||||
|
||||
/**
|
||||
* List of options which can be "forced" from site settings.
|
||||
*/
|
||||
var $forceable = array('aggregation', 'keephigh', 'droplow', 'aggregateonlygraded', 'aggregateoutcomes', 'aggregatesubcats');
|
||||
public $forceable = array('aggregation', 'keephigh', 'droplow', 'aggregateonlygraded', 'aggregateoutcomes', 'aggregatesubcats');
|
||||
|
||||
/**
|
||||
* Builds this category's path string based on its parents (if any) and its own id number.
|
||||
@@ -153,11 +153,13 @@ class grade_category extends grade_object {
|
||||
* @param object $grade_category
|
||||
* @return int The depth of this category (2 means there is one parent)
|
||||
*/
|
||||
function build_path($grade_category) {
|
||||
public function build_path($grade_category) {
|
||||
global $DB;
|
||||
|
||||
if (empty($grade_category->parent)) {
|
||||
return '/'.$grade_category->id.'/';
|
||||
} else {
|
||||
$parent = get_record('grade_categories', 'id', $grade_category->parent);
|
||||
$parent = $DB->get_record('grade_categories', array('id' => $grade_category->parent));
|
||||
return grade_category::build_path($parent).$grade_category->id.'/';
|
||||
}
|
||||
}
|
||||
@@ -169,7 +171,7 @@ class grade_category extends grade_object {
|
||||
* @param array $params associative arrays varname=>value
|
||||
* @return object grade_category instance or false if none found.
|
||||
*/
|
||||
function fetch($params) {
|
||||
public static function fetch($params) {
|
||||
return grade_object::fetch_helper('grade_categories', 'grade_category', $params);
|
||||
}
|
||||
|
||||
@@ -180,7 +182,7 @@ class grade_category extends grade_object {
|
||||
* @param array $params associative arrays varname=>value
|
||||
* @return array array of grade_category insatnces or false if none found.
|
||||
*/
|
||||
function fetch_all($params) {
|
||||
public static function fetch_all($params) {
|
||||
return grade_object::fetch_all_helper('grade_categories', 'grade_category', $params);
|
||||
}
|
||||
|
||||
@@ -189,7 +191,7 @@ class grade_category extends grade_object {
|
||||
* @param string $source from where was the object updated (mod/forum, manual, etc.)
|
||||
* @return boolean success
|
||||
*/
|
||||
function update($source=null) {
|
||||
public function update($source=null) {
|
||||
// load the grade item or create a new one
|
||||
$this->load_grade_item();
|
||||
|
||||
@@ -227,7 +229,7 @@ class grade_category extends grade_object {
|
||||
$child->path = null;
|
||||
$child->depth = 0;
|
||||
$child->update($source);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +241,7 @@ class grade_category extends grade_object {
|
||||
* @param string $source from where was the object deleted (mod/forum, manual, etc.)
|
||||
* @return boolean success
|
||||
*/
|
||||
function delete($source=null) {
|
||||
public function delete($source=null) {
|
||||
$grade_item = $this->load_grade_item();
|
||||
|
||||
if ($this->is_course_category()) {
|
||||
@@ -295,7 +297,7 @@ class grade_category 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) {
|
||||
|
||||
if (empty($this->courseid)) {
|
||||
print_error('cannotinsertgrade');
|
||||
@@ -329,7 +331,7 @@ class grade_category extends grade_object {
|
||||
* @param int $courseid
|
||||
* @return bool success
|
||||
*/
|
||||
function insert_course_category($courseid) {
|
||||
public function insert_course_category($courseid) {
|
||||
$this->courseid = $courseid;
|
||||
$this->fullname = '?';
|
||||
$this->path = null;
|
||||
@@ -358,7 +360,7 @@ class grade_category extends grade_object {
|
||||
* This assumes that this object has an id number and a matching record in DB. If not, it will return false.
|
||||
* @return boolean
|
||||
*/
|
||||
function qualifies_for_regrading() {
|
||||
public function qualifies_for_regrading() {
|
||||
if (empty($this->id)) {
|
||||
debugging("Can not regrade non existing category");
|
||||
return false;
|
||||
@@ -380,7 +382,7 @@ class grade_category extends grade_object {
|
||||
* Marks the category and course item as needing update - categories are always regraded.
|
||||
* @return void
|
||||
*/
|
||||
function force_regrading() {
|
||||
public function force_regrading() {
|
||||
$grade_item = $this->load_grade_item();
|
||||
$grade_item->force_regrading();
|
||||
}
|
||||
@@ -400,8 +402,8 @@ class grade_category extends grade_object {
|
||||
* 3. Aggregate these grades
|
||||
* 4. Save them in final grades of associated category grade item
|
||||
*/
|
||||
function generate_grades($userid=null) {
|
||||
global $CFG;
|
||||
public function generate_grades($userid=null) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$this->load_grade_item();
|
||||
|
||||
@@ -419,7 +421,7 @@ class grade_category extends grade_object {
|
||||
$sql = "SELECT *
|
||||
FROM {$CFG->prefix}grade_items
|
||||
WHERE id IN ($gis)";
|
||||
$items = get_records_sql($sql);
|
||||
$items = $DB->get_records_sql($sql);
|
||||
}
|
||||
|
||||
if ($userid) {
|
||||
@@ -439,12 +441,12 @@ class grade_category extends grade_object {
|
||||
ORDER BY g.userid";
|
||||
|
||||
// group the results by userid and aggregate the grades for this user
|
||||
if ($rs = get_recordset_sql($sql)) {
|
||||
if ($rs = $DB->get_recordset_sql($sql)) {
|
||||
$prevuser = 0;
|
||||
$grade_values = array();
|
||||
$excluded = array();
|
||||
$oldgrade = null;
|
||||
while ($used = rs_fetch_next_record($rs)) {
|
||||
foreach ($rs as $used) {
|
||||
if ($used->userid != $prevuser) {
|
||||
$this->aggregate_grades($prevuser, $items, $grade_values, $oldgrade, $excluded);
|
||||
$prevuser = $used->userid;
|
||||
@@ -460,8 +462,8 @@ class grade_category extends grade_object {
|
||||
$oldgrade = $used;
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
$this->aggregate_grades($prevuser, $items, $grade_values, $oldgrade, $excluded);//the last one
|
||||
rs_close($rs);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -477,7 +479,7 @@ class grade_category extends grade_object {
|
||||
* @param bool $excluded
|
||||
* @return boolean (just plain return;)
|
||||
*/
|
||||
function aggregate_grades($userid, $items, $grade_values, $oldgrade, $excluded) {
|
||||
private function aggregate_grades($userid, $items, $grade_values, $oldgrade, $excluded) {
|
||||
global $CFG;
|
||||
if (empty($userid)) {
|
||||
//ignore first call
|
||||
@@ -581,7 +583,7 @@ class grade_category extends grade_object {
|
||||
/**
|
||||
* Internal function - aggregation maths.
|
||||
*/
|
||||
function aggregate_values($grade_values, $items) {
|
||||
private function aggregate_values($grade_values, $items) {
|
||||
switch ($this->aggregation) {
|
||||
case GRADE_AGGREGATE_MEDIAN: // Middle point value in the set: ignores frequencies
|
||||
$num = count($grade_values);
|
||||
@@ -685,7 +687,7 @@ class grade_category extends grade_object {
|
||||
* @param bool $excluded
|
||||
* @return boolean (just plain return;)
|
||||
*/
|
||||
function sum_grades(&$grade, $oldfinalgrade, $items, $grade_values, $excluded) {
|
||||
private function sum_grades(&$grade, $oldfinalgrade, $items, $grade_values, $excluded) {
|
||||
// ungraded and exluded items are not used in aggregation
|
||||
foreach ($grade_values as $itemid=>$v) {
|
||||
if (is_null($v)) {
|
||||
@@ -745,7 +747,7 @@ class grade_category extends grade_object {
|
||||
* @param array $grade_values
|
||||
* @return array Limited grades.
|
||||
*/
|
||||
function apply_limit_rules(&$grade_values) {
|
||||
public function apply_limit_rules(&$grade_values) {
|
||||
arsort($grade_values, SORT_NUMERIC);
|
||||
if (!empty($this->droplow)) {
|
||||
for ($i = 0; $i < $this->droplow; $i++) {
|
||||
@@ -763,7 +765,7 @@ class grade_category extends grade_object {
|
||||
* Returns true if category uses special aggregation coeficient
|
||||
* @return boolean true if coeficient used
|
||||
*/
|
||||
function is_aggregationcoef_used() {
|
||||
private function is_aggregationcoef_used() {
|
||||
return ($this->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN
|
||||
or $this->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN
|
||||
or $this->aggregation == GRADE_AGGREGATE_SUM);
|
||||
@@ -777,7 +779,7 @@ class grade_category extends grade_object {
|
||||
* @param boolean $include_category_items as category children
|
||||
* @return array
|
||||
*/
|
||||
function fetch_course_tree($courseid, $include_category_items=false) {
|
||||
public static function fetch_course_tree($courseid, $include_category_items=false) {
|
||||
$course_category = grade_category::fetch_course_category($courseid);
|
||||
$category_array = array('object'=>$course_category, 'type'=>'category', 'depth'=>1,
|
||||
'children'=>$course_category->get_children($include_category_items));
|
||||
@@ -787,7 +789,7 @@ class grade_category extends grade_object {
|
||||
return grade_category::_fetch_course_tree_recursion($category_array, $sortorder);
|
||||
}
|
||||
|
||||
function _fetch_course_tree_recursion($category_array, &$sortorder) {
|
||||
private function _fetch_course_tree_recursion($category_array, &$sortorder) {
|
||||
// update the sortorder in db if needed
|
||||
if ($category_array['object']->sortorder != $sortorder) {
|
||||
$category_array['object']->set_sortorder($sortorder);
|
||||
@@ -827,14 +829,15 @@ class grade_category extends grade_object {
|
||||
* as well as all levels (0). The elements are indexed by sort order.
|
||||
* @return array Array of child objects (grade_category and grade_item).
|
||||
*/
|
||||
function get_children($include_category_items=false) {
|
||||
public function get_children($include_category_items=false) {
|
||||
global $DB;
|
||||
|
||||
// This function must be as fast as possible ;-)
|
||||
// fetch all course grade items and categories into memory - we do not expect hundreds of these in course
|
||||
// we have to limit the number of queries though, because it will be used often in grade reports
|
||||
|
||||
$cats = get_records('grade_categories', 'courseid', $this->courseid);
|
||||
$items = get_records('grade_items', 'courseid', $this->courseid);
|
||||
$cats = $DB->get_records('grade_categories', array('courseid' => $this->courseid));
|
||||
$items = $DB->get_records('grade_items', array('courseid' => $this->courseid));
|
||||
|
||||
// init children array first
|
||||
foreach ($cats as $catid=>$cat) {
|
||||
@@ -881,7 +884,7 @@ class grade_category extends grade_object {
|
||||
//fix paths and depts
|
||||
static $recursioncounter = 0; // prevents infinite recursion
|
||||
$recursioncounter++;
|
||||
if ($recursioncounter < 5) {
|
||||
if ($recursioncounter < 5) {
|
||||
// fix paths and depths!
|
||||
$grade_category = new grade_category($cat, false);
|
||||
$grade_category->depth = 0;
|
||||
@@ -889,7 +892,7 @@ class grade_category extends grade_object {
|
||||
$grade_category->update('system');
|
||||
return $this->get_children($include_category_items);
|
||||
}
|
||||
}
|
||||
}
|
||||
// prevent problems with duplicate sortorders in db
|
||||
$sortorder = $cat->sortorder;
|
||||
while(array_key_exists($sortorder, $cats[$cat->parent]->children)) {
|
||||
@@ -916,7 +919,7 @@ class grade_category extends grade_object {
|
||||
|
||||
}
|
||||
|
||||
function _get_children_recursion($category) {
|
||||
private function _get_children_recursion($category) {
|
||||
|
||||
$children_array = array();
|
||||
foreach($category->children as $sortorder=>$child) {
|
||||
@@ -951,7 +954,7 @@ class grade_category extends grade_object {
|
||||
* Uses get_grade_item to load or create a grade_item, then saves it as $this->grade_item.
|
||||
* @return object Grade_item
|
||||
*/
|
||||
function load_grade_item() {
|
||||
public function load_grade_item() {
|
||||
if (empty($this->grade_item)) {
|
||||
$this->grade_item = $this->get_grade_item();
|
||||
}
|
||||
@@ -963,7 +966,7 @@ class grade_category extends grade_object {
|
||||
* If no grade_item exists yet, create one.
|
||||
* @return object Grade_item
|
||||
*/
|
||||
function get_grade_item() {
|
||||
public function get_grade_item() {
|
||||
if (empty($this->id)) {
|
||||
debugging("Attempt to obtain a grade_category's associated grade_item without the category's ID being set.");
|
||||
return false;
|
||||
@@ -1000,7 +1003,7 @@ class grade_category extends grade_object {
|
||||
* referenced record in the DB.
|
||||
* @return object Parent_category
|
||||
*/
|
||||
function load_parent_category() {
|
||||
public function load_parent_category() {
|
||||
if (empty($this->parent_category) && !empty($this->parent)) {
|
||||
$this->parent_category = $this->get_parent_category();
|
||||
}
|
||||
@@ -1011,7 +1014,7 @@ class grade_category extends grade_object {
|
||||
* Uses $this->parent to instantiate and return a grade_category object.
|
||||
* @return object Parent_category
|
||||
*/
|
||||
function get_parent_category() {
|
||||
public function get_parent_category() {
|
||||
if (!empty($this->parent)) {
|
||||
$parent_category = new grade_category(array('id' => $this->parent));
|
||||
return $parent_category;
|
||||
@@ -1025,10 +1028,11 @@ class grade_category extends grade_object {
|
||||
* when we do not know the exact type of an object.
|
||||
* @return string name
|
||||
*/
|
||||
function get_name() {
|
||||
public function get_name() {
|
||||
global $DB;
|
||||
// For a course category, we return the course name if the fullname is set to '?' in the DB (empty in the category edit form)
|
||||
if (empty($this->parent) && $this->fullname == '?') {
|
||||
$course = get_record('course', 'id', $this->courseid);
|
||||
$course = $DB->get_record('course', array('id'=> $this->courseid));
|
||||
return format_string($course->fullname);
|
||||
} else {
|
||||
return $this->fullname;
|
||||
@@ -1040,7 +1044,7 @@ class grade_category extends grade_object {
|
||||
* @param int parentid
|
||||
* @return boolean success
|
||||
*/
|
||||
function set_parent($parentid, $source=null) {
|
||||
public function set_parent($parentid, $source=null) {
|
||||
if ($this->parent == $parentid) {
|
||||
return true;
|
||||
}
|
||||
@@ -1075,7 +1079,7 @@ class grade_category extends grade_object {
|
||||
* @param int $userid Optional: to retrieve a single final grade
|
||||
* @return mixed An array of all final_grades (stdClass objects) for this grade_item, or a single final_grade.
|
||||
*/
|
||||
function get_final($userid=NULL) {
|
||||
public function get_final($userid=NULL) {
|
||||
$this->load_grade_item();
|
||||
return $this->grade_item->get_final($userid);
|
||||
}
|
||||
@@ -1085,7 +1089,7 @@ class grade_category extends grade_object {
|
||||
* grade_item, for cases where the object type is not known.
|
||||
* @return int Sort order
|
||||
*/
|
||||
function get_sortorder() {
|
||||
public function get_sortorder() {
|
||||
$this->load_grade_item();
|
||||
return $this->grade_item->get_sortorder();
|
||||
}
|
||||
@@ -1095,7 +1099,7 @@ class grade_category extends grade_object {
|
||||
* grade_item, for cases where the object type is not known.
|
||||
* @return string idnumber
|
||||
*/
|
||||
function get_idnumber() {
|
||||
public function get_idnumber() {
|
||||
$this->load_grade_item();
|
||||
return $this->grade_item->get_idnumber();
|
||||
}
|
||||
@@ -1106,7 +1110,7 @@ class grade_category extends grade_object {
|
||||
* @param int $sortorder
|
||||
* @return void
|
||||
*/
|
||||
function set_sortorder($sortorder) {
|
||||
public function set_sortorder($sortorder) {
|
||||
$this->load_grade_item();
|
||||
$this->grade_item->set_sortorder($sortorder);
|
||||
}
|
||||
@@ -1115,7 +1119,7 @@ class grade_category extends grade_object {
|
||||
* Move this category after the given sortorder - does not change the parent
|
||||
* @param int $sortorder to place after
|
||||
*/
|
||||
function move_after_sortorder($sortorder) {
|
||||
public function move_after_sortorder($sortorder) {
|
||||
$this->load_grade_item();
|
||||
$this->grade_item->move_after_sortorder($sortorder);
|
||||
}
|
||||
@@ -1124,7 +1128,7 @@ class grade_category extends grade_object {
|
||||
* Return true if this is the top most category that represents the total course grade.
|
||||
* @return boolean
|
||||
*/
|
||||
function is_course_category() {
|
||||
public function is_course_category() {
|
||||
$this->load_grade_item();
|
||||
return $this->grade_item->is_course_item();
|
||||
}
|
||||
@@ -1134,7 +1138,7 @@ class grade_category extends grade_object {
|
||||
* @static
|
||||
* @return object grade_category instance for course grade
|
||||
*/
|
||||
function fetch_course_category($courseid) {
|
||||
public function fetch_course_category($courseid) {
|
||||
if (empty($courseid)) {
|
||||
debugging('Missing course id!');
|
||||
return false;
|
||||
@@ -1156,7 +1160,7 @@ class grade_category extends grade_object {
|
||||
* Is grading object editable?
|
||||
* @return boolean
|
||||
*/
|
||||
function is_editable() {
|
||||
public function is_editable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1165,7 +1169,7 @@ class grade_category extends grade_object {
|
||||
* grade_item, for cases where the object type is not known.
|
||||
* @return boolean
|
||||
*/
|
||||
function is_locked() {
|
||||
public function is_locked() {
|
||||
$this->load_grade_item();
|
||||
return $this->grade_item->is_locked();
|
||||
}
|
||||
@@ -1178,7 +1182,7 @@ class grade_category extends grade_object {
|
||||
* @param boolean $refresh refresh grades when unlocking
|
||||
* @return boolean success if category locked (not all children mayb be locked though)
|
||||
*/
|
||||
function set_locked($lockedstate, $cascade=false, $refresh=true) {
|
||||
public function set_locked($lockedstate, $cascade=false, $refresh=true) {
|
||||
$this->load_grade_item();
|
||||
|
||||
$result = $this->grade_item->set_locked($lockedstate, $cascade, true);
|
||||
@@ -1209,7 +1213,7 @@ class grade_category extends grade_object {
|
||||
* grade_item.
|
||||
* @return boolean
|
||||
*/
|
||||
function is_hidden() {
|
||||
public function is_hidden() {
|
||||
$this->load_grade_item();
|
||||
return $this->grade_item->is_hidden();
|
||||
}
|
||||
@@ -1218,7 +1222,7 @@ class grade_category extends grade_object {
|
||||
* Check grade hidden status. Uses data from both grade item and grade.
|
||||
* @return boolean true if hiddenuntil, false if not
|
||||
*/
|
||||
function is_hiddenuntil() {
|
||||
public function is_hiddenuntil() {
|
||||
$this->load_grade_item();
|
||||
return $this->grade_item->is_hiddenuntil();
|
||||
}
|
||||
@@ -1230,7 +1234,7 @@ class grade_category extends grade_object {
|
||||
* @param boolean $cascade apply to child objects too
|
||||
* @return void
|
||||
*/
|
||||
function set_hidden($hidden, $cascade=false) {
|
||||
public function set_hidden($hidden, $cascade=false) {
|
||||
$this->load_grade_item();
|
||||
$this->grade_item->set_hidden($hidden);
|
||||
if ($cascade) {
|
||||
@@ -1251,7 +1255,7 @@ class grade_category extends grade_object {
|
||||
* Applies default settings on this category
|
||||
* @return bool true if anything changed
|
||||
*/
|
||||
function apply_default_settings() {
|
||||
public function apply_default_settings() {
|
||||
global $CFG;
|
||||
|
||||
foreach ($this->forceable as $property) {
|
||||
@@ -1268,7 +1272,7 @@ class grade_category extends grade_object {
|
||||
* Applies forced settings on this category
|
||||
* @return bool true if anything changed
|
||||
*/
|
||||
function apply_forced_settings() {
|
||||
public function apply_forced_settings() {
|
||||
global $CFG;
|
||||
|
||||
$updated = false;
|
||||
@@ -1289,7 +1293,7 @@ class grade_category extends grade_object {
|
||||
* Notification of change in forced category settings.
|
||||
* @static
|
||||
*/
|
||||
function updated_forced_settings() {
|
||||
public static function updated_forced_settings() {
|
||||
global $CFG;
|
||||
$sql = "UPDATE {$CFG->prefix}grade_items SET needsupdate=1 WHERE itemtype='course' or itemtype='category'";
|
||||
execute_sql($sql, false);
|
||||
|
||||
+54
-53
@@ -31,13 +31,13 @@ class grade_grade extends grade_object {
|
||||
* The DB table.
|
||||
* @var string $table
|
||||
*/
|
||||
var $table = 'grade_grades';
|
||||
public $table = 'grade_grades';
|
||||
|
||||
/**
|
||||
* Array of required table fields, must start with 'id'.
|
||||
* @var array $required_fields
|
||||
*/
|
||||
var $required_fields = array('id', 'itemid', 'userid', 'rawgrade', 'rawgrademax', 'rawgrademin',
|
||||
public $required_fields = array('id', 'itemid', 'userid', 'rawgrade', 'rawgrademax', 'rawgrademin',
|
||||
'rawscaleid', 'usermodified', 'finalgrade', 'hidden', 'locked',
|
||||
'locktime', 'exported', 'overridden', 'excluded', 'timecreated', 'timemodified');
|
||||
|
||||
@@ -45,109 +45,109 @@ class grade_grade extends grade_object {
|
||||
* Array of optional fields with default values (these should match db defaults)
|
||||
* @var array $optional_fields
|
||||
*/
|
||||
var $optional_fields = array('feedback'=>null, 'feedbackformat'=>0, 'information'=>null, 'informationformat'=>0);
|
||||
public $optional_fields = array('feedback'=>null, 'feedbackformat'=>0, 'information'=>null, 'informationformat'=>0);
|
||||
|
||||
/**
|
||||
* The id of the grade_item this grade belongs to.
|
||||
* @var int $itemid
|
||||
*/
|
||||
var $itemid;
|
||||
public $itemid;
|
||||
|
||||
/**
|
||||
* The grade_item object referenced by $this->itemid.
|
||||
* @var object $grade_item
|
||||
*/
|
||||
var $grade_item;
|
||||
public $grade_item;
|
||||
|
||||
/**
|
||||
* The id of the user this grade belongs to.
|
||||
* @var int $userid
|
||||
*/
|
||||
var $userid;
|
||||
public $userid;
|
||||
|
||||
/**
|
||||
* The grade value of this raw grade, if such was provided by the module.
|
||||
* @var float $rawgrade
|
||||
*/
|
||||
var $rawgrade;
|
||||
public $rawgrade;
|
||||
|
||||
/**
|
||||
* The maximum allowable grade when this grade was created.
|
||||
* @var float $rawgrademax
|
||||
*/
|
||||
var $rawgrademax = 100;
|
||||
public $rawgrademax = 100;
|
||||
|
||||
/**
|
||||
* The minimum allowable grade when this grade was created.
|
||||
* @var float $rawgrademin
|
||||
*/
|
||||
var $rawgrademin = 0;
|
||||
public $rawgrademin = 0;
|
||||
|
||||
/**
|
||||
* id of the scale, if this grade is based on a scale.
|
||||
* @var int $rawscaleid
|
||||
*/
|
||||
var $rawscaleid;
|
||||
public $rawscaleid;
|
||||
|
||||
/**
|
||||
* The userid of the person who last modified this grade.
|
||||
* @var int $usermodified
|
||||
*/
|
||||
var $usermodified;
|
||||
public $usermodified;
|
||||
|
||||
/**
|
||||
* The final value of this grade.
|
||||
* @var float $finalgrade
|
||||
*/
|
||||
var $finalgrade;
|
||||
public $finalgrade;
|
||||
|
||||
/**
|
||||
* 0 if visible, 1 always hidden or date not visible until
|
||||
* @var float $hidden
|
||||
*/
|
||||
var $hidden = 0;
|
||||
public $hidden = 0;
|
||||
|
||||
/**
|
||||
* 0 not locked, date when the item was locked
|
||||
* @var float locked
|
||||
*/
|
||||
var $locked = 0;
|
||||
public $locked = 0;
|
||||
|
||||
/**
|
||||
* 0 no automatic locking, date when to lock the grade automatically
|
||||
* @var float $locktime
|
||||
*/
|
||||
var $locktime = 0;
|
||||
public $locktime = 0;
|
||||
|
||||
/**
|
||||
* Exported flag
|
||||
* @var boolean $exported
|
||||
*/
|
||||
var $exported = 0;
|
||||
public $exported = 0;
|
||||
|
||||
/**
|
||||
* Overridden flag
|
||||
* @var boolean $overridden
|
||||
*/
|
||||
var $overridden = 0;
|
||||
public $overridden = 0;
|
||||
|
||||
/**
|
||||
* Grade excluded from aggregation functions
|
||||
* @var boolean $excluded
|
||||
*/
|
||||
var $excluded = 0;
|
||||
public $excluded = 0;
|
||||
|
||||
/**
|
||||
* TODO: HACK: create a new field datesubmitted - the date of submission if any
|
||||
* @var boolean $timecreated
|
||||
*/
|
||||
var $timecreated = null;
|
||||
public $timecreated = null;
|
||||
|
||||
/**
|
||||
* TODO: HACK: create a new field dategraded - the date of grading
|
||||
* @var boolean $timemodified
|
||||
*/
|
||||
var $timemodified = null;
|
||||
public $timemodified = null;
|
||||
|
||||
|
||||
/**
|
||||
@@ -157,7 +157,8 @@ class grade_grade extends grade_object {
|
||||
* @param bool $include_missing include grades that do not exist yet
|
||||
* @return array userid=>grade_grade array
|
||||
*/
|
||||
function fetch_users_grades($grade_item, $userids, $include_missing=true) {
|
||||
public function fetch_users_grades($grade_item, $userids, $include_missing=true) {
|
||||
global $DB;
|
||||
|
||||
// hmm, there might be a problem with length of sql query
|
||||
// if there are too many users requested - we might run out of memory anyway
|
||||
@@ -172,7 +173,7 @@ class grade_grade extends grade_object {
|
||||
|
||||
$user_ids_cvs = implode(',', $userids);
|
||||
$result = array();
|
||||
if ($grade_records = get_records_select('grade_grades', "itemid={$grade_item->id} AND userid IN ($user_ids_cvs)")) {
|
||||
if ($grade_records = $DB->get_records_select('grade_grades', "itemid={$grade_item->id} AND userid IN ($user_ids_cvs)")) {
|
||||
foreach ($grade_records as $record) {
|
||||
$result[$record->userid] = new grade_grade($record, false);
|
||||
}
|
||||
@@ -195,7 +196,7 @@ class grade_grade extends grade_object {
|
||||
* Loads the grade_item object referenced by $this->itemid and saves it as $this->grade_item for easy access.
|
||||
* @return object grade_item.
|
||||
*/
|
||||
function load_grade_item() {
|
||||
public function load_grade_item() {
|
||||
if (empty($this->itemid)) {
|
||||
debugging('Missing itemid');
|
||||
$this->grade_item = null;
|
||||
@@ -217,7 +218,7 @@ class grade_grade extends grade_object {
|
||||
* Is grading object editable?
|
||||
* @return boolean
|
||||
*/
|
||||
function is_editable() {
|
||||
public function is_editable() {
|
||||
if ($this->is_locked()) {
|
||||
return false;
|
||||
}
|
||||
@@ -238,7 +239,7 @@ class grade_grade extends grade_object {
|
||||
*
|
||||
* @return boolean true if locked, false if not
|
||||
*/
|
||||
function is_locked() {
|
||||
public function is_locked() {
|
||||
$this->load_grade_item();
|
||||
if (empty($this->grade_item)) {
|
||||
return !empty($this->locked);
|
||||
@@ -251,7 +252,7 @@ class grade_grade extends grade_object {
|
||||
* Checks if grade overridden
|
||||
* @return boolean
|
||||
*/
|
||||
function is_overridden() {
|
||||
public function is_overridden() {
|
||||
return !empty($this->overridden);
|
||||
}
|
||||
|
||||
@@ -260,7 +261,7 @@ class grade_grade extends grade_object {
|
||||
* might be null if not submitted.
|
||||
* @return int
|
||||
*/
|
||||
function get_datesubmitted() {
|
||||
public function get_datesubmitted() {
|
||||
//TODO: HACK - create new fields in 2.0
|
||||
return $this->timecreated;
|
||||
}
|
||||
@@ -270,7 +271,7 @@ class grade_grade extends grade_object {
|
||||
* might be null if no grade present.
|
||||
* @return int
|
||||
*/
|
||||
function get_dategraded() {
|
||||
public function get_dategraded() {
|
||||
//TODO: HACK - create new fields in 2.0
|
||||
if (is_null($this->finalgrade) and is_null($this->feedback)) {
|
||||
return null; // no grade == no date
|
||||
@@ -287,7 +288,7 @@ class grade_grade extends grade_object {
|
||||
* @param boolean $refresh refresh grades from external activities if needed
|
||||
* @return boolean true is db state changed
|
||||
*/
|
||||
function set_overridden($state, $refresh = true) {
|
||||
public function set_overridden($state, $refresh = true) {
|
||||
if (empty($this->overridden) and $state) {
|
||||
$this->overridden = time();
|
||||
$this->update();
|
||||
@@ -311,7 +312,7 @@ class grade_grade extends grade_object {
|
||||
* Checks if grade excluded from aggregation functions
|
||||
* @return boolean
|
||||
*/
|
||||
function is_excluded() {
|
||||
public function is_excluded() {
|
||||
return !empty($this->excluded);
|
||||
}
|
||||
|
||||
@@ -320,7 +321,7 @@ class grade_grade extends grade_object {
|
||||
* @param boolean $state requested excluded state
|
||||
* @return boolean true is db state changed
|
||||
*/
|
||||
function set_excluded($state) {
|
||||
public function set_excluded($state) {
|
||||
if (empty($this->excluded) and $state) {
|
||||
$this->excluded = time();
|
||||
$this->update();
|
||||
@@ -342,7 +343,7 @@ class grade_grade extends grade_object {
|
||||
* @param boolean $refresh refresh grades when unlocking
|
||||
* @return boolean true if sucessful, false if can not set new lock state for grade
|
||||
*/
|
||||
function set_locked($lockedstate, $cascade=false, $refresh=true) {
|
||||
public function set_locked($lockedstate, $cascade=false, $refresh=true) {
|
||||
$this->load_grade_item();
|
||||
|
||||
if ($lockedstate) {
|
||||
@@ -380,20 +381,20 @@ class grade_grade extends grade_object {
|
||||
* @param array $items array of all grade item ids
|
||||
* @return void
|
||||
*/
|
||||
function check_locktime_all($items) {
|
||||
global $CFG;
|
||||
public function check_locktime_all($items) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$items_sql = implode(',', $items);
|
||||
|
||||
$now = time(); // no rounding needed, this is not supposed to be called every 10 seconds
|
||||
|
||||
if ($rs = get_recordset_select('grade_grades', "itemid IN ($items_sql) AND locked = 0 AND locktime > 0 AND locktime < $now")) {
|
||||
while ($grade = rs_fetch_next_record($rs)) {
|
||||
if ($rs = $DB->get_recordset_select('grade_grades', "itemid IN ($items_sql) AND locked = 0 AND locktime > 0 AND locktime < $now")) {
|
||||
foreach ($rs as $grade) {
|
||||
$grade_grade = new grade_grade($grade, false);
|
||||
$grade_grade->locked = time();
|
||||
$grade_grade->update('locktime');
|
||||
}
|
||||
rs_close($rs);
|
||||
$rs->close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -403,7 +404,7 @@ class grade_grade extends grade_object {
|
||||
* @param int $locktime timestamp for lock to activate
|
||||
* @return void
|
||||
*/
|
||||
function set_locktime($locktime) {
|
||||
public function set_locktime($locktime) {
|
||||
$this->locktime = $locktime;
|
||||
$this->update();
|
||||
}
|
||||
@@ -413,7 +414,7 @@ class grade_grade extends grade_object {
|
||||
*
|
||||
* @return int $locktime timestamp for lock to activate
|
||||
*/
|
||||
function get_locktime() {
|
||||
public function get_locktime() {
|
||||
$this->load_grade_item();
|
||||
|
||||
$item_locktime = $this->grade_item->get_locktime();
|
||||
@@ -430,20 +431,20 @@ class grade_grade extends grade_object {
|
||||
* Check grade hidden status. Uses data from both grade item and grade.
|
||||
* @return boolean true if hidden, false if not
|
||||
*/
|
||||
function is_hidden() {
|
||||
public function is_hidden() {
|
||||
$this->load_grade_item();
|
||||
if (empty($this->grade_item)) {
|
||||
return $this->hidden == 1 or ($this->hidden != 0 and $this->hidden > time());
|
||||
} else {
|
||||
return $this->hidden == 1 or ($this->hidden != 0 and $this->hidden > time()) or $this->grade_item->is_hidden();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check grade hidden status. Uses data from both grade item and grade.
|
||||
* @return boolean true if hiddenuntil, false if not
|
||||
*/
|
||||
function is_hiddenuntil() {
|
||||
public function is_hiddenuntil() {
|
||||
$this->load_grade_item();
|
||||
|
||||
if ($this->hidden == 1 or $this->grade_item->hidden == 1) {
|
||||
@@ -461,7 +462,7 @@ class grade_grade extends grade_object {
|
||||
* Check grade hidden status. Uses data from both grade item and grade.
|
||||
* @return int 0 means visible, 1 hidden always, timestamp hidden until
|
||||
*/
|
||||
function get_hidden() {
|
||||
public function get_hidden() {
|
||||
$this->load_grade_item();
|
||||
|
||||
$item_hidden = $this->grade_item->get_hidden();
|
||||
@@ -490,7 +491,7 @@ class grade_grade extends grade_object {
|
||||
* @param boolean $cascade ignored
|
||||
* @param int $hidden new hidden status
|
||||
*/
|
||||
function set_hidden($hidden, $cascade=false) {
|
||||
public function set_hidden($hidden, $cascade=false) {
|
||||
$this->hidden = $hidden;
|
||||
$this->update();
|
||||
}
|
||||
@@ -502,7 +503,7 @@ class grade_grade extends grade_object {
|
||||
* @param array $params associative arrays varname=>value
|
||||
* @return object grade_grade instance or false if none found.
|
||||
*/
|
||||
function fetch($params) {
|
||||
public static function fetch($params) {
|
||||
return grade_object::fetch_helper('grade_grades', 'grade_grade', $params);
|
||||
}
|
||||
|
||||
@@ -513,7 +514,7 @@ class grade_grade extends grade_object {
|
||||
* @param array $params associative arrays varname=>value
|
||||
* @return array array of grade_grade insatnces or false if none found.
|
||||
*/
|
||||
function fetch_all($params) {
|
||||
public static function fetch_all($params) {
|
||||
return grade_object::fetch_all_helper('grade_grades', 'grade_grade', $params);
|
||||
}
|
||||
|
||||
@@ -530,7 +531,7 @@ class grade_grade extends grade_object {
|
||||
* @param float $target_max
|
||||
* @return float Converted value
|
||||
*/
|
||||
function standardise_score($rawgrade, $source_min, $source_max, $target_min, $target_max) {
|
||||
public static function standardise_score($rawgrade, $source_min, $source_max, $target_min, $target_max) {
|
||||
if (is_null($rawgrade)) {
|
||||
return null;
|
||||
}
|
||||
@@ -556,7 +557,7 @@ class grade_grade extends grade_object {
|
||||
* @param array $items $grade_items array of grade items, & used for better internal caching
|
||||
* @return array
|
||||
*/
|
||||
function get_hiding_affected(&$grade_grades, &$grade_items) {
|
||||
public static function get_hiding_affected(&$grade_grades, &$grade_items) {
|
||||
global $CFG;
|
||||
|
||||
if (count($grade_grades) !== count($grade_items)) {
|
||||
@@ -692,7 +693,7 @@ class grade_grade extends grade_object {
|
||||
* @param object $grade_item An optional grade_item of which gradepass value we can use, saves having to load the grade_grade's grade_item
|
||||
* @return boolean
|
||||
*/
|
||||
function is_passed($grade_item = null) {
|
||||
public function is_passed($grade_item = null) {
|
||||
if (empty($grade_item)) {
|
||||
if (!isset($this->grade_item)) {
|
||||
$this->load_grade_item();
|
||||
@@ -715,9 +716,9 @@ class grade_grade extends grade_object {
|
||||
return $this->finalgrade >= $this->grade_item->gradepass;
|
||||
}
|
||||
|
||||
function insert($source=null) {
|
||||
// TODO: dategraded hack - do not update times, they are used for submission and grading
|
||||
//$this->timecreated = $this->timemodified = time();
|
||||
public function insert($source=null) {
|
||||
// TODO: dategraded hack - do not update times, they are used for submission and grading
|
||||
//$this->timecreated = $this->timemodified = time();
|
||||
return parent::insert($source);
|
||||
}
|
||||
|
||||
@@ -727,7 +728,7 @@ class grade_grade extends grade_object {
|
||||
* @param string $source from where was the object inserted (mod/forum, manual, etc.)
|
||||
* @return boolean success
|
||||
*/
|
||||
function update($source=null) {
|
||||
public function update($source=null) {
|
||||
$this->rawgrade = grade_floatval($this->rawgrade);
|
||||
$this->finalgrade = grade_floatval($this->finalgrade);
|
||||
$this->rawgrademin = grade_floatval($this->rawgrademin);
|
||||
|
||||
+123
-119
@@ -34,13 +34,13 @@ class grade_item extends grade_object {
|
||||
* DB Table (used by grade_object).
|
||||
* @var string $table
|
||||
*/
|
||||
var $table = 'grade_items';
|
||||
public $table = 'grade_items';
|
||||
|
||||
/**
|
||||
* Array of required table fields, must start with 'id'.
|
||||
* @var array $required_fields
|
||||
*/
|
||||
var $required_fields = array('id', 'courseid', 'categoryid', 'itemname', 'itemtype', 'itemmodule', 'iteminstance',
|
||||
public $required_fields = array('id', 'courseid', 'categoryid', 'itemname', 'itemtype', 'itemmodule', 'iteminstance',
|
||||
'itemnumber', 'iteminfo', 'idnumber', 'calculation', 'gradetype', 'grademax', 'grademin',
|
||||
'scaleid', 'outcomeid', 'gradepass', 'multfactor', 'plusfactor', 'aggregationcoef',
|
||||
'sortorder', 'display', 'decimals', 'hidden', 'locked', 'locktime', 'needsupdate', 'timecreated',
|
||||
@@ -50,198 +50,198 @@ class grade_item extends grade_object {
|
||||
* The course this grade_item belongs to.
|
||||
* @var int $courseid
|
||||
*/
|
||||
var $courseid;
|
||||
public $courseid;
|
||||
|
||||
/**
|
||||
* The category this grade_item belongs to (optional).
|
||||
* @var int $categoryid
|
||||
*/
|
||||
var $categoryid;
|
||||
public $categoryid;
|
||||
|
||||
/**
|
||||
* The grade_category object referenced $this->iteminstance (itemtype must be == 'category' or == 'course' in that case).
|
||||
* @var object $item_category
|
||||
*/
|
||||
var $item_category;
|
||||
public $item_category;
|
||||
|
||||
/**
|
||||
* The grade_category object referenced by $this->categoryid.
|
||||
* @var object $parent_category
|
||||
*/
|
||||
var $parent_category;
|
||||
public $parent_category;
|
||||
|
||||
|
||||
/**
|
||||
* The name of this grade_item (pushed by the module).
|
||||
* @var string $itemname
|
||||
*/
|
||||
var $itemname;
|
||||
public $itemname;
|
||||
|
||||
/**
|
||||
* e.g. 'category', 'course' and 'mod', 'blocks', 'import', etc...
|
||||
* @var string $itemtype
|
||||
*/
|
||||
var $itemtype;
|
||||
public $itemtype;
|
||||
|
||||
/**
|
||||
* The module pushing this grade (e.g. 'forum', 'quiz', 'assignment' etc).
|
||||
* @var string $itemmodule
|
||||
*/
|
||||
var $itemmodule;
|
||||
public $itemmodule;
|
||||
|
||||
/**
|
||||
* ID of the item module
|
||||
* @var int $iteminstance
|
||||
*/
|
||||
var $iteminstance;
|
||||
public $iteminstance;
|
||||
|
||||
/**
|
||||
* Number of the item in a series of multiple grades pushed by an activity.
|
||||
* @var int $itemnumber
|
||||
*/
|
||||
var $itemnumber;
|
||||
public $itemnumber;
|
||||
|
||||
/**
|
||||
* Info and notes about this item.
|
||||
* @var string $iteminfo
|
||||
*/
|
||||
var $iteminfo;
|
||||
public $iteminfo;
|
||||
|
||||
/**
|
||||
* Arbitrary idnumber provided by the module responsible.
|
||||
* @var string $idnumber
|
||||
*/
|
||||
var $idnumber;
|
||||
public $idnumber;
|
||||
|
||||
/**
|
||||
* Calculation string used for this item.
|
||||
* @var string $calculation
|
||||
*/
|
||||
var $calculation;
|
||||
public $calculation;
|
||||
|
||||
/**
|
||||
* Indicates if we already tried to normalize the grade calculation formula.
|
||||
* This flag helps to minimize db access when broken formulas used in calculation.
|
||||
* @var boolean
|
||||
*/
|
||||
var $calculation_normalized;
|
||||
public $calculation_normalized;
|
||||
/**
|
||||
* Math evaluation object
|
||||
*/
|
||||
var $formula;
|
||||
public $formula;
|
||||
|
||||
/**
|
||||
* The type of grade (0 = none, 1 = value, 2 = scale, 3 = text)
|
||||
* @var int $gradetype
|
||||
*/
|
||||
var $gradetype = GRADE_TYPE_VALUE;
|
||||
public $gradetype = GRADE_TYPE_VALUE;
|
||||
|
||||
/**
|
||||
* Maximum allowable grade.
|
||||
* @var float $grademax
|
||||
*/
|
||||
var $grademax = 100;
|
||||
public $grademax = 100;
|
||||
|
||||
/**
|
||||
* Minimum allowable grade.
|
||||
* @var float $grademin
|
||||
*/
|
||||
var $grademin = 0;
|
||||
public $grademin = 0;
|
||||
|
||||
/**
|
||||
* id of the scale, if this grade is based on a scale.
|
||||
* @var int $scaleid
|
||||
*/
|
||||
var $scaleid;
|
||||
public $scaleid;
|
||||
|
||||
/**
|
||||
* A grade_scale object (referenced by $this->scaleid).
|
||||
* @var object $scale
|
||||
*/
|
||||
var $scale;
|
||||
public $scale;
|
||||
|
||||
/**
|
||||
* The id of the optional grade_outcome associated with this grade_item.
|
||||
* @var int $outcomeid
|
||||
*/
|
||||
var $outcomeid;
|
||||
public $outcomeid;
|
||||
|
||||
/**
|
||||
* The grade_outcome this grade is associated with, if applicable.
|
||||
* @var object $outcome
|
||||
*/
|
||||
var $outcome;
|
||||
public $outcome;
|
||||
|
||||
/**
|
||||
* grade required to pass. (grademin <= gradepass <= grademax)
|
||||
* @var float $gradepass
|
||||
*/
|
||||
var $gradepass = 0;
|
||||
public $gradepass = 0;
|
||||
|
||||
/**
|
||||
* Multiply all grades by this number.
|
||||
* @var float $multfactor
|
||||
*/
|
||||
var $multfactor = 1.0;
|
||||
public $multfactor = 1.0;
|
||||
|
||||
/**
|
||||
* Add this to all grades.
|
||||
* @var float $plusfactor
|
||||
*/
|
||||
var $plusfactor = 0;
|
||||
public $plusfactor = 0;
|
||||
|
||||
/**
|
||||
* Aggregation coeficient used for weighted averages
|
||||
* @var float $aggregationcoef
|
||||
*/
|
||||
var $aggregationcoef = 0;
|
||||
public $aggregationcoef = 0;
|
||||
|
||||
/**
|
||||
* Sorting order of the columns.
|
||||
* @var int $sortorder
|
||||
*/
|
||||
var $sortorder = 0;
|
||||
public $sortorder = 0;
|
||||
|
||||
/**
|
||||
* Display type of the grades (Real, Percentage, Letter, or default).
|
||||
* @var int $display
|
||||
*/
|
||||
var $display = GRADE_DISPLAY_TYPE_DEFAULT;
|
||||
public $display = GRADE_DISPLAY_TYPE_DEFAULT;
|
||||
|
||||
/**
|
||||
* The number of digits after the decimal point symbol. Applies only to REAL and PERCENTAGE grade display types.
|
||||
* @var int $decimals
|
||||
*/
|
||||
var $decimals = null;
|
||||
public $decimals = null;
|
||||
|
||||
/**
|
||||
* 0 if visible, 1 always hidden or date not visible until
|
||||
* @var int $hidden
|
||||
*/
|
||||
var $hidden = 0;
|
||||
public $hidden = 0;
|
||||
|
||||
/**
|
||||
* Grade item lock flag. Empty if not locked, locked if any value present, usually date when item was locked. Locking prevents updating.
|
||||
* @var int $locked
|
||||
*/
|
||||
var $locked = 0;
|
||||
public $locked = 0;
|
||||
|
||||
/**
|
||||
* Date after which the grade will be locked. Empty means no automatic locking.
|
||||
* @var int $locktime
|
||||
*/
|
||||
var $locktime = 0;
|
||||
public $locktime = 0;
|
||||
|
||||
/**
|
||||
* If set, the whole column will be recalculated, then this flag will be switched off.
|
||||
* @var boolean $needsupdate
|
||||
*/
|
||||
var $needsupdate = 1;
|
||||
public $needsupdate = 1;
|
||||
|
||||
/**
|
||||
* Cached dependson array
|
||||
*/
|
||||
var $dependson_cache = null;
|
||||
public $dependson_cache = null;
|
||||
|
||||
/**
|
||||
* In addition to update() as defined in grade_object, handle the grade_outcome and grade_scale objects.
|
||||
@@ -250,7 +250,7 @@ class grade_item extends grade_object {
|
||||
* @param string $source from where was the object inserted (mod/forum, manual, etc.)
|
||||
* @return boolean success
|
||||
*/
|
||||
function update($source=null) {
|
||||
public function update($source=null) {
|
||||
// reset caches
|
||||
$this->dependson_cache = null;
|
||||
|
||||
@@ -283,7 +283,7 @@ class grade_item extends grade_object {
|
||||
* This assumes that this object has an id number and a matching record in DB. If not, it will return false.
|
||||
* @return boolean
|
||||
*/
|
||||
function qualifies_for_regrading() {
|
||||
public function qualifies_for_regrading() {
|
||||
if (empty($this->id)) {
|
||||
return false;
|
||||
}
|
||||
@@ -317,7 +317,7 @@ class grade_item extends grade_object {
|
||||
* @param array $params associative arrays varname=>value
|
||||
* @return object grade_item instance or false if none found.
|
||||
*/
|
||||
function fetch($params) {
|
||||
public static function fetch($params) {
|
||||
return grade_object::fetch_helper('grade_items', 'grade_item', $params);
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ class grade_item extends grade_object {
|
||||
* @param array $params associative arrays varname=>value
|
||||
* @return array array of grade_item insatnces or false if none found.
|
||||
*/
|
||||
function fetch_all($params) {
|
||||
public static function fetch_all($params) {
|
||||
return grade_object::fetch_all_helper('grade_items', 'grade_item', $params);
|
||||
}
|
||||
|
||||
@@ -337,7 +337,7 @@ class grade_item extends grade_object {
|
||||
* @param string $source from where was the object deleted (mod/forum, manual, etc.)
|
||||
* @return boolean success
|
||||
*/
|
||||
function delete($source=null) {
|
||||
public function delete($source=null) {
|
||||
$this->delete_all_grades($source);
|
||||
return parent::delete($source);
|
||||
}
|
||||
@@ -347,7 +347,7 @@ class grade_item extends grade_object {
|
||||
* @param string $source from where was the object deleted (mod/forum, manual, etc.)
|
||||
* @return boolean success
|
||||
*/
|
||||
function delete_all_grades($source=null) {
|
||||
public function delete_all_grades($source=null) {
|
||||
if (!$this->is_course_item()) {
|
||||
$this->force_regrading();
|
||||
}
|
||||
@@ -366,8 +366,8 @@ class grade_item 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) {
|
||||
global $CFG;
|
||||
public function insert($source=null) {
|
||||
global $CFG, $DB;
|
||||
|
||||
if (empty($this->courseid)) {
|
||||
print_error('cannotinsertgrade');
|
||||
@@ -384,7 +384,7 @@ class grade_item extends grade_object {
|
||||
}
|
||||
|
||||
// always place the new items at the end, move them after insert if needed
|
||||
$last_sortorder = get_field_select('grade_items', 'MAX(sortorder)', "courseid = {$this->courseid}");
|
||||
$last_sortorder = $DB->get_field_select('grade_items', 'MAX(sortorder)', "courseid = {$this->courseid}");
|
||||
if (!empty($last_sortorder)) {
|
||||
$this->sortorder = $last_sortorder + 1;
|
||||
} else {
|
||||
@@ -421,7 +421,8 @@ class grade_item extends grade_object {
|
||||
* @param string $idnumber (without magic quotes)
|
||||
* @return boolean success
|
||||
*/
|
||||
function add_idnumber($idnumber) {
|
||||
public function add_idnumber($idnumber) {
|
||||
global $DB;
|
||||
if (!empty($this->idnumber)) {
|
||||
return false;
|
||||
}
|
||||
@@ -433,7 +434,7 @@ class grade_item extends grade_object {
|
||||
if (!empty($cm->idnumber)) {
|
||||
return false;
|
||||
}
|
||||
if (set_field('course_modules', 'idnumber', addslashes($idnumber), 'id', $cm->id)) {
|
||||
if ($DB->set_field('course_modules', 'idnumber', addslashes($idnumber), array('id' => $cm->id))) {
|
||||
$this->idnumber = $idnumber;
|
||||
return $this->update();
|
||||
}
|
||||
@@ -453,7 +454,7 @@ class grade_item extends grade_object {
|
||||
* @param int $userid
|
||||
* @return boolean Locked state
|
||||
*/
|
||||
function is_locked($userid=NULL) {
|
||||
public function is_locked($userid=NULL) {
|
||||
if (!empty($this->locked)) {
|
||||
return true;
|
||||
}
|
||||
@@ -475,7 +476,7 @@ class grade_item extends grade_object {
|
||||
* @param boolean $refresh refresh grades when unlocking
|
||||
* @return boolean true if grade_item all grades updated, false if at least one update fails
|
||||
*/
|
||||
function set_locked($lockedstate, $cascade=false, $refresh=true) {
|
||||
public function set_locked($lockedstate, $cascade=false, $refresh=true) {
|
||||
if ($lockedstate) {
|
||||
/// setting lock
|
||||
if ($this->needsupdate) {
|
||||
@@ -527,7 +528,7 @@ class grade_item extends grade_object {
|
||||
/**
|
||||
* Lock the grade if needed - make sure this is called only when final grades are valid
|
||||
*/
|
||||
function check_locktime() {
|
||||
public function check_locktime() {
|
||||
if (!empty($this->locked)) {
|
||||
return; // already locked
|
||||
}
|
||||
@@ -544,7 +545,7 @@ class grade_item extends grade_object {
|
||||
* @param int $locktime timestamp for lock to activate
|
||||
* @return void
|
||||
*/
|
||||
function set_locktime($locktime) {
|
||||
public function set_locktime($locktime) {
|
||||
$this->locktime = $locktime;
|
||||
$this->update();
|
||||
}
|
||||
@@ -554,7 +555,7 @@ class grade_item extends grade_object {
|
||||
*
|
||||
* @return int $locktime timestamp for lock to activate
|
||||
*/
|
||||
function get_locktime() {
|
||||
public function get_locktime() {
|
||||
return $this->locktime;
|
||||
}
|
||||
|
||||
@@ -562,7 +563,7 @@ class grade_item extends grade_object {
|
||||
* Returns the hidden state of this grade_item
|
||||
* @return boolean hidden state
|
||||
*/
|
||||
function is_hidden() {
|
||||
public function is_hidden() {
|
||||
return ($this->hidden == 1 or ($this->hidden != 0 and $this->hidden > time()));
|
||||
}
|
||||
|
||||
@@ -570,7 +571,7 @@ class grade_item extends grade_object {
|
||||
* Check grade hidden status. Uses data from both grade item and grade.
|
||||
* @return boolean true if hiddenuntil, false if not
|
||||
*/
|
||||
function is_hiddenuntil() {
|
||||
public function is_hiddenuntil() {
|
||||
return $this->hidden > 1;
|
||||
}
|
||||
|
||||
@@ -578,7 +579,7 @@ class grade_item extends grade_object {
|
||||
* Check grade item hidden status.
|
||||
* @return int 0 means visible, 1 hidden always, timestamp hidden until
|
||||
*/
|
||||
function get_hidden() {
|
||||
public function get_hidden() {
|
||||
return $this->hidden;
|
||||
}
|
||||
|
||||
@@ -588,7 +589,7 @@ class grade_item extends grade_object {
|
||||
* @param boolean $cascade apply to child objects too
|
||||
* @return void
|
||||
*/
|
||||
function set_hidden($hidden, $cascade=false) {
|
||||
public function set_hidden($hidden, $cascade=false) {
|
||||
$this->hidden = $hidden;
|
||||
$this->update();
|
||||
|
||||
@@ -606,19 +607,20 @@ class grade_item extends grade_object {
|
||||
* Returns the number of grades that are hidden.
|
||||
* @param return int Number of hidden grades
|
||||
*/
|
||||
function has_hidden_grades($groupsql="", $groupwheresql="") {
|
||||
global $CFG;
|
||||
return get_field_sql("SELECT COUNT(*) FROM {$CFG->prefix}grade_grades g LEFT JOIN "
|
||||
public function has_hidden_grades($groupsql="", $groupwheresql="") {
|
||||
global $CFG, $DB;
|
||||
return $DB->get_field_sql("SELECT COUNT(*) FROM {$CFG->prefix}grade_grades g LEFT JOIN "
|
||||
."{$CFG->prefix}user u ON g.userid = u.id $groupsql WHERE itemid = $this->id AND hidden = 1 $groupwheresql");
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark regrading as finished successfully.
|
||||
*/
|
||||
function regrading_finished() {
|
||||
public function regrading_finished() {
|
||||
global $DB;
|
||||
$this->needsupdate = 0;
|
||||
//do not use $this->update() because we do not want this logged in grade_item_history
|
||||
set_field('grade_items', 'needsupdate', 0, 'id', $this->id);
|
||||
$DB->set_field('grade_items', 'needsupdate', 0, array('id' => $this->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -630,8 +632,8 @@ class grade_item extends grade_object {
|
||||
*
|
||||
* @return boolean true if ok, error string otherwise
|
||||
*/
|
||||
function regrade_final_grades($userid=null) {
|
||||
global $CFG;
|
||||
public function regrade_final_grades($userid=null) {
|
||||
global $CFG, $DB;
|
||||
|
||||
// locked grade items already have correct final grades
|
||||
if ($this->is_locked()) {
|
||||
@@ -675,12 +677,12 @@ class grade_item extends grade_object {
|
||||
$grade_inst = new grade_grade();
|
||||
$fields = implode(',', $grade_inst->required_fields);
|
||||
if ($userid) {
|
||||
$rs = get_recordset_select('grade_grades', "itemid={$this->id} AND userid=$userid", '', $fields);
|
||||
$rs = $DB->get_recordset_select('grade_grades', "itemid={$this->id} AND userid=$userid", null, '', $fields);
|
||||
} else {
|
||||
$rs = get_recordset('grade_grades', 'itemid', $this->id, '', $fields);
|
||||
$rs = $DB->get_recordset('grade_grades', array('itemid' => $this->id), '', $fields);
|
||||
}
|
||||
if ($rs) {
|
||||
while ($grade_record = rs_fetch_next_record($rs)) {
|
||||
foreach ($rs as $grade_record) {
|
||||
$grade = new grade_grade($grade_record, false);
|
||||
|
||||
if (!empty($grade_record->locked) or !empty($grade_record->overridden)) {
|
||||
@@ -696,7 +698,7 @@ class grade_item extends grade_object {
|
||||
}
|
||||
}
|
||||
}
|
||||
rs_close($rs);
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
return $result;
|
||||
@@ -710,7 +712,7 @@ class grade_item extends grade_object {
|
||||
* @param float $rawmax original rawmax
|
||||
* @return mixed
|
||||
*/
|
||||
function adjust_raw_grade($rawgrade, $rawmin, $rawmax) {
|
||||
public function adjust_raw_grade($rawgrade, $rawmin, $rawmax) {
|
||||
if (is_null($rawgrade)) {
|
||||
return null;
|
||||
}
|
||||
@@ -773,7 +775,7 @@ class grade_item extends grade_object {
|
||||
* Sets this grade_item's needsupdate to true. Also marks the course item as needing update.
|
||||
* @return void
|
||||
*/
|
||||
function force_regrading() {
|
||||
public function force_regrading() {
|
||||
global $DB;
|
||||
$this->needsupdate = 1;
|
||||
//mark this item and course item only - categories and calculated items are always regraded
|
||||
@@ -787,7 +789,7 @@ class grade_item extends grade_object {
|
||||
* if this item's scaleid variable is set.
|
||||
* @return object grade_scale or null if no scale used
|
||||
*/
|
||||
function load_scale() {
|
||||
public function load_scale() {
|
||||
if ($this->gradetype != GRADE_TYPE_SCALE) {
|
||||
$this->scaleid = null;
|
||||
}
|
||||
@@ -821,7 +823,7 @@ class grade_item extends grade_object {
|
||||
* if this item's outcomeid variable is set.
|
||||
* @return object grade_outcome
|
||||
*/
|
||||
function load_outcome() {
|
||||
public function load_outcome() {
|
||||
if (!empty($this->outcomeid)) {
|
||||
$this->outcome = grade_outcome::fetch(array('id'=>$this->outcomeid));
|
||||
}
|
||||
@@ -834,7 +836,7 @@ class grade_item extends grade_object {
|
||||
*
|
||||
* @return mixed grade_category object if applicable, false if course item
|
||||
*/
|
||||
function get_parent_category() {
|
||||
public function get_parent_category() {
|
||||
if ($this->is_category_item() or $this->is_course_item()) {
|
||||
return $this->get_item_category();
|
||||
|
||||
@@ -848,7 +850,7 @@ class grade_item extends grade_object {
|
||||
* from the DB and assigns it to $this->parent_category. It also returns the object.
|
||||
* @return object Grade_category
|
||||
*/
|
||||
function load_parent_category() {
|
||||
public function load_parent_category() {
|
||||
if (empty($this->parent_category->id)) {
|
||||
$this->parent_category = $this->get_parent_category();
|
||||
}
|
||||
@@ -860,7 +862,7 @@ class grade_item extends grade_object {
|
||||
*
|
||||
* @return mixed grade_category object if applicable, false otherwise
|
||||
*/
|
||||
function get_item_category() {
|
||||
public function get_item_category() {
|
||||
if (!$this->is_course_item() and !$this->is_category_item()) {
|
||||
return false;
|
||||
}
|
||||
@@ -872,7 +874,7 @@ class grade_item extends grade_object {
|
||||
* from the DB and assigns it to $this->item_category. It also returns the object.
|
||||
* @return object Grade_category
|
||||
*/
|
||||
function load_item_category() {
|
||||
public function load_item_category() {
|
||||
if (empty($this->category->id)) {
|
||||
$this->item_category = $this->get_item_category();
|
||||
}
|
||||
@@ -883,7 +885,7 @@ class grade_item extends grade_object {
|
||||
* Is the grade item associated with category?
|
||||
* @return boolean
|
||||
*/
|
||||
function is_category_item() {
|
||||
public function is_category_item() {
|
||||
return ($this->itemtype == 'category');
|
||||
}
|
||||
|
||||
@@ -891,7 +893,7 @@ class grade_item extends grade_object {
|
||||
* Is the grade item associated with course?
|
||||
* @return boolean
|
||||
*/
|
||||
function is_course_item() {
|
||||
public function is_course_item() {
|
||||
return ($this->itemtype == 'course');
|
||||
}
|
||||
|
||||
@@ -899,7 +901,7 @@ class grade_item extends grade_object {
|
||||
* Is this a manualy graded item?
|
||||
* @return boolean
|
||||
*/
|
||||
function is_manual_item() {
|
||||
public function is_manual_item() {
|
||||
return ($this->itemtype == 'manual');
|
||||
}
|
||||
|
||||
@@ -907,7 +909,7 @@ class grade_item extends grade_object {
|
||||
* Is this an outcome item?
|
||||
* @return boolean
|
||||
*/
|
||||
function is_outcome_item() {
|
||||
public function is_outcome_item() {
|
||||
return !empty($this->outcomeid);
|
||||
}
|
||||
|
||||
@@ -915,7 +917,7 @@ class grade_item extends grade_object {
|
||||
* Is the grade item external - associated with module, plugin or something else?
|
||||
* @return boolean
|
||||
*/
|
||||
function is_external_item() {
|
||||
public function is_external_item() {
|
||||
return ($this->itemtype == 'mod');
|
||||
}
|
||||
|
||||
@@ -923,7 +925,7 @@ class grade_item extends grade_object {
|
||||
* Is the grade item overridable
|
||||
* @return boolean
|
||||
*/
|
||||
function is_overridable_item() {
|
||||
public function is_overridable_item() {
|
||||
return !$this->is_outcome_item() and ($this->is_external_item() or $this->is_calculated() or $this->is_course_item() or $this->is_category_item());
|
||||
}
|
||||
|
||||
@@ -931,7 +933,7 @@ class grade_item extends grade_object {
|
||||
* Is the grade item feedback overridable
|
||||
* @return boolean
|
||||
*/
|
||||
function is_overridable_item_feedback() {
|
||||
public function is_overridable_item_feedback() {
|
||||
return !$this->is_outcome_item() and $this->is_external_item();
|
||||
}
|
||||
|
||||
@@ -939,7 +941,7 @@ class grade_item extends grade_object {
|
||||
* Returns true if grade items uses raw grades
|
||||
* @return boolean
|
||||
*/
|
||||
function is_raw_used() {
|
||||
public function is_raw_used() {
|
||||
return ($this->is_external_item() and !$this->is_calculated() and !$this->is_outcome_item());
|
||||
}
|
||||
|
||||
@@ -948,7 +950,7 @@ class grade_item extends grade_object {
|
||||
* @param int $courseid
|
||||
* @return course item object
|
||||
*/
|
||||
function fetch_course_item($courseid) {
|
||||
public function fetch_course_item($courseid) {
|
||||
if ($course_item = grade_item::fetch(array('courseid'=>$courseid, 'itemtype'=>'course'))) {
|
||||
return $course_item;
|
||||
}
|
||||
@@ -962,7 +964,7 @@ class grade_item extends grade_object {
|
||||
* Is grading object editable?
|
||||
* @return boolean
|
||||
*/
|
||||
function is_editable() {
|
||||
public function is_editable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -970,7 +972,7 @@ class grade_item extends grade_object {
|
||||
* Checks if grade calculated. Returns this object's calculation.
|
||||
* @return boolean true if grade item calculated.
|
||||
*/
|
||||
function is_calculated() {
|
||||
public function is_calculated() {
|
||||
if (empty($this->calculation)) {
|
||||
return false;
|
||||
}
|
||||
@@ -993,7 +995,7 @@ class grade_item extends grade_object {
|
||||
* Returns calculation string if grade calculated.
|
||||
* @return mixed string if calculation used, null if not
|
||||
*/
|
||||
function get_calculation() {
|
||||
public function get_calculation() {
|
||||
if ($this->is_calculated()) {
|
||||
return grade_item::denormalize_formula($this->calculation, $this->courseid);
|
||||
|
||||
@@ -1009,7 +1011,7 @@ class grade_item extends grade_object {
|
||||
* @param string $formula string representation of formula used for calculation
|
||||
* @return boolean success
|
||||
*/
|
||||
function set_calculation($formula) {
|
||||
public function set_calculation($formula) {
|
||||
$this->calculation = grade_item::normalize_formula($formula, $this->courseid);
|
||||
$this->calculation_normalized = true;
|
||||
return $this->update();
|
||||
@@ -1021,7 +1023,7 @@ class grade_item extends grade_object {
|
||||
* @param string $formula
|
||||
* @return string denormalized string
|
||||
*/
|
||||
function denormalize_formula($formula, $courseid) {
|
||||
public static function denormalize_formula($formula, $courseid) {
|
||||
if (empty($formula)) {
|
||||
return '';
|
||||
}
|
||||
@@ -1047,7 +1049,7 @@ class grade_item extends grade_object {
|
||||
* @param string $formula
|
||||
* @return string normalized string
|
||||
*/
|
||||
function normalize_formula($formula, $courseid) {
|
||||
public static function normalize_formula($formula, $courseid) {
|
||||
$formula = trim($formula);
|
||||
|
||||
if (empty($formula)) {
|
||||
@@ -1070,14 +1072,15 @@ class grade_item extends grade_object {
|
||||
* @param int $userid Optional: to retrieve a single final grade
|
||||
* @return mixed An array of all final_grades (stdClass objects) for this grade_item, or a single final_grade.
|
||||
*/
|
||||
function get_final($userid=NULL) {
|
||||
public function get_final($userid=NULL) {
|
||||
global $DB;
|
||||
if ($userid) {
|
||||
if ($user = get_record('grade_grades', 'itemid', $this->id, 'userid', $userid)) {
|
||||
if ($user = $DB->get_record('grade_grades', array('itemid' => $this->id, 'userid' => $userid))) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
} else {
|
||||
if ($grades = get_records('grade_grades', 'itemid', $this->id)) {
|
||||
if ($grades = $DB->get_records('grade_grades', array('itemid' => $this->id))) {
|
||||
//TODO: speed up with better SQL
|
||||
$result = array();
|
||||
foreach ($grades as $grade) {
|
||||
@@ -1095,7 +1098,7 @@ class grade_item extends grade_object {
|
||||
* @param int $userid
|
||||
* @return object grade_grade object instance
|
||||
*/
|
||||
function get_grade($userid, $create=true) {
|
||||
public function get_grade($userid, $create=true) {
|
||||
if (empty($this->id)) {
|
||||
debugging('Can not use before insert');
|
||||
return false;
|
||||
@@ -1114,7 +1117,7 @@ class grade_item extends grade_object {
|
||||
* grade_category, for cases where the object type is not know.
|
||||
* @return int Sort order
|
||||
*/
|
||||
function get_sortorder() {
|
||||
public function get_sortorder() {
|
||||
return $this->sortorder;
|
||||
}
|
||||
|
||||
@@ -1123,7 +1126,7 @@ class grade_item extends grade_object {
|
||||
* grade_category, for cases where the object type is not know.
|
||||
* @return string idnumber
|
||||
*/
|
||||
function get_idnumber() {
|
||||
public function get_idnumber() {
|
||||
return $this->idnumber;
|
||||
}
|
||||
|
||||
@@ -1132,7 +1135,7 @@ class grade_item extends grade_object {
|
||||
* grade_category, for cases where the object type is not know.
|
||||
* @return string idnumber
|
||||
*/
|
||||
function get_grade_item() {
|
||||
public function get_grade_item() {
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -1142,7 +1145,7 @@ class grade_item extends grade_object {
|
||||
* @param int $sortorder
|
||||
* @return void
|
||||
*/
|
||||
function set_sortorder($sortorder) {
|
||||
public function set_sortorder($sortorder) {
|
||||
if ($this->sortorder == $sortorder) {
|
||||
return;
|
||||
}
|
||||
@@ -1150,7 +1153,7 @@ class grade_item extends grade_object {
|
||||
$this->update();
|
||||
}
|
||||
|
||||
function move_after_sortorder($sortorder) {
|
||||
public function move_after_sortorder($sortorder) {
|
||||
global $CFG;
|
||||
|
||||
//make some room first
|
||||
@@ -1167,7 +1170,7 @@ class grade_item extends grade_object {
|
||||
* when we do not know the exact type of an object.
|
||||
* @return string name
|
||||
*/
|
||||
function get_name() {
|
||||
public function get_name() {
|
||||
if (!empty($this->itemname)) {
|
||||
// MDL-10557
|
||||
return format_string($this->itemname);
|
||||
@@ -1188,7 +1191,7 @@ class grade_item extends grade_object {
|
||||
* @param int $parentid
|
||||
* @return boolean success;
|
||||
*/
|
||||
function set_parent($parentid) {
|
||||
public function set_parent($parentid) {
|
||||
if ($this->is_course_item() or $this->is_category_item()) {
|
||||
print_error('cannotsetparentforcatoritem');
|
||||
}
|
||||
@@ -1216,8 +1219,8 @@ class grade_item extends grade_object {
|
||||
* @param bool $reset_cache
|
||||
* @return array of grade_item ids this one depends on
|
||||
*/
|
||||
function depends_on($reset_cache=false) {
|
||||
global $CFG;
|
||||
public function depends_on($reset_cache=false) {
|
||||
global $CFG, $DB;
|
||||
|
||||
if ($reset_cache) {
|
||||
$this->dependson_cache = null;
|
||||
@@ -1289,7 +1292,7 @@ class grade_item extends grade_object {
|
||||
$outcomes_sql";
|
||||
}
|
||||
|
||||
if ($children = get_records_sql($sql)) {
|
||||
if ($children = $DB->get_records_sql($sql)) {
|
||||
$this->dependson_cache = array_keys($children);
|
||||
return $this->dependson_cache;
|
||||
} else {
|
||||
@@ -1307,14 +1310,15 @@ class grade_item extends grade_object {
|
||||
* Refetch grades from modules, plugins.
|
||||
* @param int $userid optional, one user only
|
||||
*/
|
||||
function refresh_grades($userid=0) {
|
||||
public function refresh_grades($userid=0) {
|
||||
global $DB;
|
||||
if ($this->itemtype == 'mod') {
|
||||
if ($this->is_outcome_item()) {
|
||||
//nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$activity = get_record($this->itemmodule, 'id', $this->iteminstance)) {
|
||||
if (!$activity = $DB->get_record($this->itemmodule, array('id' => $this->iteminstance))) {
|
||||
debugging("Can not find $this->itemmodule activity with id $this->iteminstance");
|
||||
return;
|
||||
}
|
||||
@@ -1345,7 +1349,7 @@ class grade_item extends grade_object {
|
||||
* @param int $feedbackformat
|
||||
* @return boolean success
|
||||
*/
|
||||
function update_final_grade($userid, $finalgrade=false, $source=NULL, $feedback=false, $feedbackformat=FORMAT_MOODLE, $usermodified=null) {
|
||||
public function update_final_grade($userid, $finalgrade=false, $source=NULL, $feedback=false, $feedbackformat=FORMAT_MOODLE, $usermodified=null) {
|
||||
global $USER, $CFG;
|
||||
|
||||
$result = true;
|
||||
@@ -1465,7 +1469,7 @@ class grade_item extends grade_object {
|
||||
* @param object $grade object - usefull for bulk upgrades
|
||||
* @return boolean success
|
||||
*/
|
||||
function update_raw_grade($userid, $rawgrade=false, $source=NULL, $feedback=false, $feedbackformat=FORMAT_MOODLE, $usermodified=null, $dategraded=null, $datesubmitted=null, $grade=null) {
|
||||
public function update_raw_grade($userid, $rawgrade=false, $source=NULL, $feedback=false, $feedbackformat=FORMAT_MOODLE, $usermodified=null, $dategraded=null, $datesubmitted=null, $grade=null) {
|
||||
global $USER;
|
||||
|
||||
$result = true;
|
||||
@@ -1601,8 +1605,8 @@ class grade_item extends grade_object {
|
||||
* The parameters are taken from final grades of grade items in current course only.
|
||||
* @return boolean false if error
|
||||
*/
|
||||
function compute($userid=null) {
|
||||
global $CFG;
|
||||
public function compute($userid=null) {
|
||||
global $CFG, $DB;
|
||||
|
||||
if (!$this->is_calculated()) {
|
||||
return false;
|
||||
@@ -1622,7 +1626,7 @@ class grade_item extends grade_object {
|
||||
LEFT OUTER JOIN {$CFG->prefix}grade_grades g
|
||||
ON (g.userid = go.userid AND g.itemid = $this->id)
|
||||
WHERE gi.id <> $this->id AND g.id IS NULL";
|
||||
if ($missing = get_records_sql($sql)) {
|
||||
if ($missing = $DB->get_records_sql($sql)) {
|
||||
foreach ($missing as $m) {
|
||||
$grade = new grade_grade(array('itemid'=>$this->id, 'userid'=>$m->userid), false);
|
||||
$grade->grade_item =& $this;
|
||||
@@ -1662,11 +1666,11 @@ class grade_item extends grade_object {
|
||||
$return = true;
|
||||
|
||||
// group the grades by userid and use formula on the group
|
||||
if ($rs = get_recordset_sql($sql)) {
|
||||
if ($rs = $DB->get_recordset_sql($sql)) {
|
||||
$prevuser = 0;
|
||||
$grade_records = array();
|
||||
$oldgrade = null;
|
||||
while ($used = rs_fetch_next_record($rs)) {
|
||||
foreach ($rs as $used) {
|
||||
if ($used->userid != $prevuser) {
|
||||
if (!$this->use_formula($prevuser, $grade_records, $useditems, $oldgrade)) {
|
||||
$return = false;
|
||||
@@ -1680,11 +1684,11 @@ class grade_item extends grade_object {
|
||||
}
|
||||
$grade_records['gi'.$used->itemid] = $used->finalgrade;
|
||||
}
|
||||
$rs->close();
|
||||
if (!$this->use_formula($prevuser, $grade_records, $useditems, $oldgrade)) {
|
||||
$return = false;
|
||||
}
|
||||
}
|
||||
rs_close($rs);
|
||||
|
||||
return $return;
|
||||
}
|
||||
@@ -1692,7 +1696,7 @@ class grade_item extends grade_object {
|
||||
/**
|
||||
* internal function - does the final grade calculation
|
||||
*/
|
||||
function use_formula($userid, $params, $useditems, $oldgrade) {
|
||||
public function use_formula($userid, $params, $useditems, $oldgrade) {
|
||||
if (empty($userid)) {
|
||||
return true;
|
||||
}
|
||||
@@ -1766,8 +1770,8 @@ class grade_item extends grade_object {
|
||||
* @param string $formula
|
||||
* @return boolean true if calculation possible, false otherwise
|
||||
*/
|
||||
function validate_formula($formulastr) {
|
||||
global $CFG;
|
||||
public function validate_formula($formulastr) {
|
||||
global $CFG, $DB;
|
||||
require_once($CFG->libdir.'/mathslib.php');
|
||||
|
||||
$formulastr = grade_item::normalize_formula($formulastr, $this->courseid);
|
||||
@@ -1810,7 +1814,7 @@ class grade_item extends grade_object {
|
||||
FROM {$CFG->prefix}grade_items gi
|
||||
WHERE gi.id IN ($gis) and gi.courseid={$this->courseid}"; // from the same course only!
|
||||
|
||||
if (!$grade_items = get_records_sql($sql)) {
|
||||
if (!$grade_items = $DB->get_records_sql($sql)) {
|
||||
$grade_items = array();
|
||||
}
|
||||
}
|
||||
@@ -1843,7 +1847,7 @@ class grade_item extends grade_object {
|
||||
* Returns the value of the display type. It can be set at 3 levels: grade_item, course setting and site. The lowest level overrides the higher ones.
|
||||
* @return int Display type
|
||||
*/
|
||||
function get_displaytype() {
|
||||
public function get_displaytype() {
|
||||
global $CFG;
|
||||
|
||||
if ($this->display == GRADE_DISPLAY_TYPE_DEFAULT) {
|
||||
@@ -1858,7 +1862,7 @@ class grade_item extends grade_object {
|
||||
* Returns the value of the decimals field. It can be set at 3 levels: grade_item, course setting and site. The lowest level overrides the higher ones.
|
||||
* @return int Decimals (0 - 5)
|
||||
*/
|
||||
function get_decimals() {
|
||||
public function get_decimals() {
|
||||
global $CFG;
|
||||
|
||||
if (is_null($this->decimals)) {
|
||||
|
||||
+34
-34
@@ -27,37 +27,39 @@
|
||||
* An abstract object that holds methods and attributes common to all grade_* objects defined here.
|
||||
* @abstract
|
||||
*/
|
||||
class grade_object {
|
||||
abstract class grade_object {
|
||||
public $table;
|
||||
|
||||
/**
|
||||
* Array of required table fields, must start with 'id'.
|
||||
* @var array $required_fields
|
||||
*/
|
||||
var $required_fields = array('id', 'timecreated', 'timemodified');
|
||||
public $required_fields = array('id', 'timecreated', 'timemodified');
|
||||
|
||||
/**
|
||||
* Array of optional fields with default values - usually long text information that is not always needed.
|
||||
* If you want to create an instance without optional fields use: new grade_object($only_required_fields, false);
|
||||
* @var array $optional_fields
|
||||
*/
|
||||
var $optional_fields = array();
|
||||
public $optional_fields = array();
|
||||
|
||||
/**
|
||||
* The PK.
|
||||
* @var int $id
|
||||
*/
|
||||
var $id;
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* The first time this grade_object was created.
|
||||
* @var int $timecreated
|
||||
*/
|
||||
var $timecreated;
|
||||
public $timecreated;
|
||||
|
||||
/**
|
||||
* The last time this grade_object was modified.
|
||||
* @var int $timemodified
|
||||
*/
|
||||
var $timemodified;
|
||||
public $timemodified;
|
||||
|
||||
/**
|
||||
* Constructor. Optionally (and by default) attempts to fetch corresponding row from DB.
|
||||
@@ -65,7 +67,7 @@ class grade_object {
|
||||
* @param boolean $fetch Whether to fetch corresponding row from DB or not,
|
||||
* optional fields might not be defined if false used
|
||||
*/
|
||||
function grade_object($params=NULL, $fetch=true) {
|
||||
public function __construct($params=NULL, $fetch=true) {
|
||||
if (!empty($params) and (is_array($params) or is_object($params))) {
|
||||
if ($fetch) {
|
||||
if ($data = $this->fetch($params)) {
|
||||
@@ -89,7 +91,8 @@ class grade_object {
|
||||
* If id present (==instance exists in db) fetches data from db.
|
||||
* Defaults are used for new instances.
|
||||
*/
|
||||
function load_optional_fields() {
|
||||
public function load_optional_fields() {
|
||||
global $DB;
|
||||
foreach ($this->optional_fields as $field=>$default) {
|
||||
if (array_key_exists($field, $this)) {
|
||||
continue;
|
||||
@@ -97,7 +100,7 @@ class grade_object {
|
||||
if (empty($this->id)) {
|
||||
$this->$field = $default;
|
||||
} else {
|
||||
$this->$field = get_field($this->table, $field, 'id', $this->id);
|
||||
$this->$field = $DB->get_field($this->table, $field, array('id', $this->id));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,9 +112,7 @@ class grade_object {
|
||||
* @param array $params associative arrays varname=>value
|
||||
* @return object grade_object instance or false if none found.
|
||||
*/
|
||||
function fetch($params) {
|
||||
print_error('mustbeoveride', 'debug', '', 'fetch()');
|
||||
}
|
||||
public static abstract function fetch($params);
|
||||
|
||||
/**
|
||||
* Finds and returns all grade_object instances based on params.
|
||||
@@ -120,16 +121,14 @@ class grade_object {
|
||||
* @param array $params associative arrays varname=>value
|
||||
* @return array array of grade_object insatnces or false if none found.
|
||||
*/
|
||||
function fetch_all($params) {
|
||||
print_error('mustbeoveride', 'debug', '', 'fetch_all()');
|
||||
}
|
||||
public static abstract function fetch_all($params);
|
||||
|
||||
/**
|
||||
* Factory method - uses the parameters to retrieve matching instance from the DB.
|
||||
* @static final protected
|
||||
* @return mixed object instance or false if not found
|
||||
*/
|
||||
function fetch_helper($table, $classname, $params) {
|
||||
protected static function fetch_helper($table, $classname, $params) {
|
||||
if ($instances = grade_object::fetch_all_helper($table, $classname, $params)) {
|
||||
if (count($instances) > 1) {
|
||||
// we should not tolerate any errors here - problems might appear later
|
||||
@@ -146,7 +145,7 @@ class grade_object {
|
||||
* @static final protected
|
||||
* @return mixed array of object instances or false if not found
|
||||
*/
|
||||
function fetch_all_helper($table, $classname, $params) {
|
||||
protected static function fetch_all_helper($table, $classname, $params) {
|
||||
$instance = new $classname();
|
||||
|
||||
$classvars = (array)$instance;
|
||||
@@ -173,7 +172,8 @@ class grade_object {
|
||||
$wheresql = implode("AND", $wheresql);
|
||||
}
|
||||
|
||||
if ($datas = get_records_select($table, $wheresql, 'id')) {
|
||||
global $DB;
|
||||
if ($datas = $DB->get_records_select($table, $wheresql, array('id'))) {
|
||||
$result = array();
|
||||
foreach($datas as $data) {
|
||||
$instance = new $classname();
|
||||
@@ -192,8 +192,8 @@ class grade_object {
|
||||
* @param string $source from where was the object updated (mod/forum, manual, etc.)
|
||||
* @return boolean success
|
||||
*/
|
||||
function update($source=null) {
|
||||
global $USER, $CFG;
|
||||
public function update($source=null) {
|
||||
global $USER, $CFG, $DB;
|
||||
|
||||
if (empty($this->id)) {
|
||||
debugging('Can not update grade object, no id!');
|
||||
@@ -202,7 +202,7 @@ class grade_object {
|
||||
|
||||
$data = $this->get_record_data();
|
||||
|
||||
if (!update_record($this->table, addslashes_recursive($data))) {
|
||||
if (!$DB->update_record($this->table, addslashes_recursive($data))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ class grade_object {
|
||||
$data->source = $source;
|
||||
$data->timemodified = time();
|
||||
$data->userlogged = $USER->id;
|
||||
insert_record($this->table.'_history', addslashes_recursive($data));
|
||||
$DB->insert_record($this->table.'_history', addslashes_recursive($data));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -224,8 +224,8 @@ class grade_object {
|
||||
* @param string $source from where was the object deleted (mod/forum, manual, etc.)
|
||||
* @return boolean success
|
||||
*/
|
||||
function delete($source=null) {
|
||||
global $USER, $CFG;
|
||||
public function delete($source=null) {
|
||||
global $USER, $CFG, $DB;
|
||||
|
||||
if (empty($this->id)) {
|
||||
debugging('Can not delete grade object, no id!');
|
||||
@@ -243,7 +243,7 @@ class grade_object {
|
||||
$data->source = $source;
|
||||
$data->timemodified = time();
|
||||
$data->userlogged = $USER->id;
|
||||
insert_record($this->table.'_history', addslashes_recursive($data));
|
||||
$DB->insert_record($this->table.'_history', addslashes_recursive($data));
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -255,7 +255,7 @@ class grade_object {
|
||||
/**
|
||||
* Returns object with fields and values that are defined in database
|
||||
*/
|
||||
function get_record_data() {
|
||||
public function get_record_data() {
|
||||
$data = new object();
|
||||
// we need to do this to prevent infinite loops in addslashes_recursive - grade_item -> category ->grade_item
|
||||
foreach ($this as $var=>$value) {
|
||||
@@ -277,8 +277,8 @@ class 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) {
|
||||
global $USER, $CFG;
|
||||
public function insert($source=null) {
|
||||
global $USER, $CFG, $DB;
|
||||
|
||||
if (!empty($this->id)) {
|
||||
debugging("Grade object already exists!");
|
||||
@@ -287,7 +287,7 @@ class grade_object {
|
||||
|
||||
$data = $this->get_record_data();
|
||||
|
||||
if (!$this->id = insert_record($this->table, addslashes_recursive($data))) {
|
||||
if (!$this->id = $DB->insert_record($this->table, addslashes_recursive($data))) {
|
||||
debugging("Could not insert object into db");
|
||||
return false;
|
||||
}
|
||||
@@ -304,7 +304,7 @@ class grade_object {
|
||||
$data->source = $source;
|
||||
$data->timemodified = time();
|
||||
$data->userlogged = $USER->id;
|
||||
insert_record($this->table.'_history', addslashes_recursive($data));
|
||||
$DB->insert_record($this->table.'_history', addslashes_recursive($data));
|
||||
}
|
||||
|
||||
return $this->id;
|
||||
@@ -316,13 +316,13 @@ class grade_object {
|
||||
* the object. This is different from the update() function, which acts on the DB record
|
||||
* based on the object.
|
||||
*/
|
||||
function update_from_db() {
|
||||
public function update_from_db() {
|
||||
if (empty($this->id)) {
|
||||
debugging("The object could not be used in its state to retrieve a matching record from the DB, because its id field is not set.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$params = get_record($this->table, 'id', $this->id)) {
|
||||
global $DB;
|
||||
if (!$params = $DB->get_record($this->table, array('id' => $this->id))) {
|
||||
debugging("Object with this id:{$this->id} does not exist in table:{$this->table}, can not update from db!");
|
||||
return false;
|
||||
}
|
||||
@@ -337,7 +337,7 @@ class grade_object {
|
||||
* and assigns the value to the corresponding variable in this object.
|
||||
* @static final
|
||||
*/
|
||||
function set_properties(&$instance, $params) {
|
||||
public static function set_properties(&$instance, $params) {
|
||||
$params = (array) $params;
|
||||
foreach ($params as $var => $value) {
|
||||
if (in_array($var, $instance->required_fields) or array_key_exists($var, $instance->optional_fields)) {
|
||||
|
||||
+33
-31
@@ -34,63 +34,63 @@ class grade_outcome extends grade_object {
|
||||
* DB Table (used by grade_object).
|
||||
* @var string $table
|
||||
*/
|
||||
var $table = 'grade_outcomes';
|
||||
public $table = 'grade_outcomes';
|
||||
|
||||
/**
|
||||
* Array of required table fields, must start with 'id'.
|
||||
* @var array $required_fields
|
||||
*/
|
||||
var $required_fields = array('id', 'courseid', 'shortname', 'fullname', 'scaleid',
|
||||
public $required_fields = array('id', 'courseid', 'shortname', 'fullname', 'scaleid',
|
||||
'description', 'timecreated', 'timemodified', 'usermodified');
|
||||
|
||||
/**
|
||||
* The course this outcome belongs to.
|
||||
* @var int $courseid
|
||||
*/
|
||||
var $courseid;
|
||||
public $courseid;
|
||||
|
||||
/**
|
||||
* The shortname of the outcome.
|
||||
* @var string $shortname
|
||||
*/
|
||||
var $shortname;
|
||||
public $shortname;
|
||||
|
||||
/**
|
||||
* The fullname of the outcome.
|
||||
* @var string $fullname
|
||||
*/
|
||||
var $fullname;
|
||||
public $fullname;
|
||||
|
||||
/**
|
||||
* A full grade_scale object referenced by $this->scaleid.
|
||||
* @var object $scale
|
||||
*/
|
||||
var $scale;
|
||||
public $scale;
|
||||
|
||||
/**
|
||||
* The id of the scale referenced by this outcome.
|
||||
* @var int $scaleid
|
||||
*/
|
||||
var $scaleid;
|
||||
public $scaleid;
|
||||
|
||||
/**
|
||||
* The description of this outcome - FORMAT_MOODLE.
|
||||
* @var string $description
|
||||
*/
|
||||
var $description;
|
||||
public $description;
|
||||
|
||||
/**
|
||||
* The userid of the person who last modified this outcome.
|
||||
* @var int $usermodified
|
||||
*/
|
||||
var $usermodified;
|
||||
public $usermodified;
|
||||
|
||||
/**
|
||||
* Deletes this outcome from the database.
|
||||
* @param string $source from where was the object deleted (mod/forum, manual, etc.)
|
||||
* @return boolean success
|
||||
*/
|
||||
function delete($source=null) {
|
||||
public function delete($source=null) {
|
||||
if (!empty($this->courseid)) {
|
||||
delete_records('grade_outcomes_courses', 'outcomeid', $this->id, 'courseid', $this->courseid);
|
||||
}
|
||||
@@ -104,7 +104,8 @@ class grade_outcome 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) {
|
||||
global $DB;
|
||||
|
||||
$this->timecreated = $this->timemodified = time();
|
||||
|
||||
@@ -113,7 +114,7 @@ class grade_outcome extends grade_object {
|
||||
$goc = new object();
|
||||
$goc->courseid = $this->courseid;
|
||||
$goc->outcomeid = $this->id;
|
||||
insert_record('grade_outcomes_courses', $goc);
|
||||
$DB->insert_record('grade_outcomes_courses', $goc);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
@@ -124,7 +125,7 @@ class grade_outcome 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();
|
||||
|
||||
if ($result = parent::update($source)) {
|
||||
@@ -140,7 +141,8 @@ class grade_outcome extends grade_object {
|
||||
* @param int $courseid
|
||||
* @return succes - false if incorrect courseid requested
|
||||
*/
|
||||
function use_in($courseid) {
|
||||
public function use_in($courseid) {
|
||||
global $DB;
|
||||
if (!empty($this->courseid) and $courseid != $this->courseid) {
|
||||
return false;
|
||||
}
|
||||
@@ -149,7 +151,7 @@ class grade_outcome extends grade_object {
|
||||
$goc = new object();
|
||||
$goc->courseid = $courseid;
|
||||
$goc->outcomeid = $this->id;
|
||||
return (bool)insert_record('grade_outcomes_courses', $goc);
|
||||
return (bool)$DB->insert_record('grade_outcomes_courses', $goc);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -161,7 +163,7 @@ class grade_outcome extends grade_object {
|
||||
* @param array $params associative arrays varname=>value
|
||||
* @return object grade_outcome instance or false if none found.
|
||||
*/
|
||||
function fetch($params) {
|
||||
public static function fetch($params) {
|
||||
return grade_object::fetch_helper('grade_outcomes', 'grade_outcome', $params);
|
||||
}
|
||||
|
||||
@@ -172,7 +174,7 @@ class grade_outcome extends grade_object {
|
||||
* @param array $params associative arrays varname=>value
|
||||
* @return array array of grade_outcome insatnces or false if none found.
|
||||
*/
|
||||
function fetch_all($params) {
|
||||
public static function fetch_all($params) {
|
||||
return grade_object::fetch_all_helper('grade_outcomes', 'grade_outcome', $params);
|
||||
}
|
||||
|
||||
@@ -180,7 +182,7 @@ class grade_outcome extends grade_object {
|
||||
* Instantiates a grade_scale object whose data is retrieved from the
|
||||
* @return object grade_scale
|
||||
*/
|
||||
function load_scale() {
|
||||
public function load_scale() {
|
||||
if (empty($this->scale->id) or $this->scale->id != $this->scaleid) {
|
||||
$this->scale = grade_scale::fetch(array('id'=>$this->scaleid));
|
||||
$this->scale->load_items();
|
||||
@@ -193,7 +195,7 @@ class grade_outcome extends grade_object {
|
||||
* @static
|
||||
* @return object
|
||||
*/
|
||||
function fetch_all_global() {
|
||||
public static function fetch_all_global() {
|
||||
if (!$outcomes = grade_outcome::fetch_all(array('courseid'=>null))) {
|
||||
$outcomes = array();
|
||||
}
|
||||
@@ -206,7 +208,7 @@ class grade_outcome extends grade_object {
|
||||
* @param int $courseid
|
||||
* @return object
|
||||
*/
|
||||
function fetch_all_local($courseid) {
|
||||
public static function fetch_all_local($courseid) {
|
||||
if (!$outcomes =grade_outcome::fetch_all(array('courseid'=>$courseid))) {
|
||||
$outcomes = array();
|
||||
}
|
||||
@@ -219,8 +221,8 @@ class grade_outcome extends grade_object {
|
||||
* @param int $courseid
|
||||
* @return array
|
||||
*/
|
||||
function fetch_all_available($courseid) {
|
||||
global $CFG;
|
||||
public static function fetch_all_available($courseid) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$result = array();
|
||||
$sql = "SELECT go.*
|
||||
@@ -228,7 +230,7 @@ class grade_outcome extends grade_object {
|
||||
WHERE go.id = goc.outcomeid AND goc.courseid = {$courseid}
|
||||
ORDER BY go.id ASC";
|
||||
|
||||
if ($datas = get_records_sql($sql)) {
|
||||
if ($datas = $DB->get_records_sql($sql)) {
|
||||
foreach($datas as $data) {
|
||||
$instance = new grade_outcome();
|
||||
grade_object::set_properties($instance, $data);
|
||||
@@ -244,7 +246,7 @@ class grade_outcome 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->fullname);
|
||||
}
|
||||
|
||||
@@ -252,7 +254,7 @@ class grade_outcome extends grade_object {
|
||||
* Returns unique outcome short name.
|
||||
* @return string name
|
||||
*/
|
||||
function get_shortname() {
|
||||
public function get_shortname() {
|
||||
return $this->shortname;
|
||||
}
|
||||
|
||||
@@ -260,7 +262,7 @@ class grade_outcome extends grade_object {
|
||||
* Checks if outcome can be deleted.
|
||||
* @return boolean
|
||||
*/
|
||||
function can_delete() {
|
||||
public function can_delete() {
|
||||
if ($this->get_item_uses_count()) {
|
||||
return false;
|
||||
}
|
||||
@@ -276,7 +278,7 @@ class grade_outcome extends grade_object {
|
||||
* Returns the number of places where outcome is used.
|
||||
* @return int
|
||||
*/
|
||||
function get_course_uses_count() {
|
||||
public function get_course_uses_count() {
|
||||
global $CFG;
|
||||
|
||||
if (!empty($this->courseid)) {
|
||||
@@ -290,7 +292,7 @@ class grade_outcome extends grade_object {
|
||||
* Returns the number of places where outcome is used.
|
||||
* @return int
|
||||
*/
|
||||
function get_item_uses_count() {
|
||||
public function get_item_uses_count() {
|
||||
return count_records('grade_items', 'outcomeid', $this->id);
|
||||
}
|
||||
|
||||
@@ -306,8 +308,8 @@ class grade_outcome extends grade_object {
|
||||
* @param bool $items Whether or not to return the list of items using this outcome
|
||||
* @return float
|
||||
*/
|
||||
function get_grade_info($courseid=null, $average=true, $items=false) {
|
||||
global $CFG;
|
||||
public function get_grade_info($courseid=null, $average=true, $items=false) {
|
||||
global $CFG, $DB;
|
||||
|
||||
if (!isset($this->id)) {
|
||||
debugging("You must setup the outcome's id before calling its get_grade_info() method!");
|
||||
@@ -336,7 +338,7 @@ class grade_outcome extends grade_object {
|
||||
AND {$CFG->prefix}grade_outcomes.id = $this->id
|
||||
$wheresql";
|
||||
|
||||
$grades = get_records_sql($sql);
|
||||
$grades = $DB->get_records_sql($sql);
|
||||
$retval = array();
|
||||
|
||||
if ($average !== false && count($grades) > 0) {
|
||||
|
||||
+24
-22
@@ -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')) {
|
||||
|
||||
@@ -100,6 +100,7 @@ class grade_category_test extends grade_test {
|
||||
}
|
||||
|
||||
function test_grade_category_update() {
|
||||
global $DB;
|
||||
$grade_category = new grade_category($this->grade_categories[0]);
|
||||
$this->assertTrue(method_exists($grade_category, 'update'));
|
||||
|
||||
@@ -113,13 +114,13 @@ class grade_category_test extends grade_test {
|
||||
|
||||
$this->assertTrue($grade_category->update());
|
||||
|
||||
$fullname = get_field('grade_categories', 'fullname', 'id', $this->grade_categories[0]->id);
|
||||
$fullname = $DB->get_field('grade_categories', 'fullname', array('id' => $this->grade_categories[0]->id));
|
||||
$this->assertEqual($grade_category->fullname, $fullname);
|
||||
|
||||
$path = get_field('grade_categories', 'path', 'id', $this->grade_categories[0]->id);
|
||||
$path = $DB->get_field('grade_categories', 'path', array('id' => $this->grade_categories[0]->id));
|
||||
$this->assertEqual($grade_category->path, $path);
|
||||
|
||||
$depth = get_field('grade_categories', 'depth', 'id', $this->grade_categories[0]->id);
|
||||
$depth = $DB->get_field('grade_categories', 'depth', array('id' => $this->grade_categories[0]->id));
|
||||
$this->assertEqual($grade_category->depth, $depth);
|
||||
|
||||
$grade_item = $grade_category->get_grade_item();
|
||||
@@ -127,11 +128,12 @@ class grade_category_test extends grade_test {
|
||||
}
|
||||
|
||||
function test_grade_category_delete() {
|
||||
global $DB;
|
||||
$grade_category = new grade_category($this->grade_categories[0]);
|
||||
$this->assertTrue(method_exists($grade_category, 'delete'));
|
||||
|
||||
$this->assertTrue($grade_category->delete());
|
||||
$this->assertFalse(get_record('grade_categories', 'id', $grade_category->id));
|
||||
$this->assertFalse($DB->get_record('grade_categories', array('id' => $grade_category->id)));
|
||||
}
|
||||
|
||||
function test_grade_category_insert() {
|
||||
|
||||
@@ -42,7 +42,7 @@ Mock::generatePartial('grade_item', 'mock_grade_item_for_test_is_calculated', ar
|
||||
@set_time_limit(0);
|
||||
|
||||
class grade_item_test extends grade_test {
|
||||
|
||||
|
||||
function test_grade_item_construct() {
|
||||
$params = new stdClass();
|
||||
|
||||
@@ -80,15 +80,17 @@ class grade_item_test extends grade_test {
|
||||
}
|
||||
|
||||
function test_grade_item_delete() {
|
||||
global $DB;
|
||||
$grade_item = new grade_item($this->grade_items[0]);
|
||||
$this->assertTrue(method_exists($grade_item, 'delete'));
|
||||
|
||||
$this->assertTrue($grade_item->delete());
|
||||
|
||||
$this->assertFalse(get_record('grade_items', 'id', $grade_item->id));
|
||||
$this->assertFalse($DB->get_record('grade_items', array('id' => $grade_item->id)));
|
||||
}
|
||||
|
||||
function test_grade_item_update() {
|
||||
global $DB;
|
||||
$grade_item = new grade_item($this->grade_items[0]);
|
||||
$this->assertTrue(method_exists($grade_item, 'update'));
|
||||
|
||||
@@ -100,7 +102,7 @@ class grade_item_test extends grade_test {
|
||||
$this->assertTrue($grade_item->qualifies_for_regrading());
|
||||
$this->assertTrue($grade_item->update());
|
||||
|
||||
$iteminfo = get_field('grade_items', 'iteminfo', 'id', $this->grade_items[0]->id);
|
||||
$iteminfo = $DB->get_field('grade_items', 'iteminfo', array('id' => $this->grade_items[0]->id));
|
||||
$this->assertEqual($grade_item->iteminfo, $iteminfo);
|
||||
}
|
||||
|
||||
@@ -208,7 +210,7 @@ class grade_item_test extends grade_test {
|
||||
$this->assertEqual($grade_item->sortorder, 6);
|
||||
|
||||
$after = grade_item::fetch(array('id'=>$this->grade_items[6]->id));
|
||||
$this->assertEqual($after->sortorder, 8);
|
||||
$this->assertEqual($after->sortorder, 7);
|
||||
}
|
||||
|
||||
function test_grade_item_get_name() {
|
||||
@@ -447,14 +449,14 @@ class grade_item_test extends grade_test {
|
||||
$res = array($this->grade_items[4]->id, $this->grade_items[5]->id);
|
||||
$this->assertEqual($res, $deps);
|
||||
}
|
||||
|
||||
|
||||
function test_grade_item_is_calculated() {
|
||||
$grade_item = new mock_grade_item_for_test_is_calculated($this);
|
||||
$grade_item->set_properties($grade_item, $this->grade_items[1]);
|
||||
$this->assertTrue(method_exists($grade_item, 'is_calculated'));
|
||||
$grade_itemsource = new grade_item($this->grade_items[0]);
|
||||
$normalizedformula = str_replace("[[$grade_itemsource->idnumber]]", "##gi$grade_itemsource->id##", $this->grade_items[1]->calculation);
|
||||
|
||||
|
||||
$grade_item->expectOnce('set_calculation', array($grade_item->calculation));
|
||||
$grade_item->setReturnValue('set_calculation', $normalizedformula);
|
||||
$this->assertTrue($grade_item->is_calculated());
|
||||
@@ -495,13 +497,13 @@ class grade_item_test extends grade_test {
|
||||
$grade_grade->delete();
|
||||
|
||||
$grade_item->compute();
|
||||
|
||||
$grade_grade = grade_grade::fetch(array('userid'=>$this->grade_grades[3]->userid, 'itemid'=>$this->grade_grades[3]->itemid));
|
||||
$this->assertEqual($this->grade_grades[3]->finalgrade, $grade_grade->finalgrade);
|
||||
$grade_grade = grade_grade::fetch(array('userid'=>$this->grade_grades[4]->userid, 'itemid'=>$this->grade_grades[4]->itemid));
|
||||
$this->assertEqual($this->grade_grades[4]->finalgrade, $grade_grade->finalgrade);
|
||||
$grade_grade = grade_grade::fetch(array('userid'=>$this->grade_grades[5]->userid, 'itemid'=>$this->grade_grades[5]->itemid));
|
||||
$this->assertEqual($this->grade_grades[5]->finalgrade, $grade_grade->finalgrade);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -68,20 +68,22 @@ class grade_outcome_test extends grade_test {
|
||||
}
|
||||
|
||||
function test_grade_outcome_update() {
|
||||
global $DB;
|
||||
$grade_outcome = new grade_outcome($this->grade_outcomes[0]);
|
||||
$this->assertTrue(method_exists($grade_outcome, 'update'));
|
||||
$grade_outcome->shortname = 'Team work';
|
||||
$this->assertTrue($grade_outcome->update());
|
||||
$shortname = get_field('grade_outcomes', 'shortname', 'id', $this->grade_outcomes[0]->id);
|
||||
$shortname = $DB->get_field('grade_outcomes', 'shortname', array('id' => $this->grade_outcomes[0]->id));
|
||||
$this->assertEqual($grade_outcome->shortname, $shortname);
|
||||
}
|
||||
|
||||
function test_grade_outcome_delete() {
|
||||
global $DB;
|
||||
$grade_outcome = new grade_outcome($this->grade_outcomes[0]);
|
||||
$this->assertTrue(method_exists($grade_outcome, 'delete'));
|
||||
|
||||
$this->assertTrue($grade_outcome->delete());
|
||||
$this->assertFalse(get_record('grade_outcomes', 'id', $grade_outcome->id));
|
||||
$this->assertFalse($DB->get_record('grade_outcomes', array('id' => $grade_outcome->id)));
|
||||
}
|
||||
|
||||
function test_grade_outcome_fetch() {
|
||||
|
||||
@@ -77,21 +77,23 @@ class grade_scale_test extends grade_test {
|
||||
}
|
||||
|
||||
function test_grade_scale_update() {
|
||||
global $DB;
|
||||
$grade_scale = new grade_scale($this->scale[0]);
|
||||
$this->assertTrue(method_exists($grade_scale, 'update'));
|
||||
|
||||
|
||||
$grade_scale->name = 'Updated info for this unittest grade_scale';
|
||||
$this->assertTrue($grade_scale->update());
|
||||
$name = get_field('scale', 'name', 'id', $this->scale[0]->id);
|
||||
$name = $DB->get_field('scale', 'name', array('id' => $this->scale[0]->id));
|
||||
$this->assertEqual($grade_scale->name, $name);
|
||||
}
|
||||
|
||||
function test_grade_scale_delete() {
|
||||
global $DB;
|
||||
$grade_scale = new grade_scale($this->scale[0]);
|
||||
$this->assertTrue(method_exists($grade_scale, 'delete'));
|
||||
|
||||
$this->assertTrue($grade_scale->delete());
|
||||
$this->assertFalse(get_record('scale', 'id', $grade_scale->id));
|
||||
$this->assertFalse($DB->get_record('scale', array('id' => $grade_scale->id)));
|
||||
}
|
||||
|
||||
function test_grade_scale_fetch() {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,7 @@
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.org //
|
||||
// //
|
||||
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
|
||||
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
|
||||
Reference in New Issue
Block a user