trailing whitespace cleanup in new grade libraries
This commit is contained in:
+19
-19
@@ -39,43 +39,43 @@ class grade_object {
|
||||
* @var array $required_fields
|
||||
*/
|
||||
var $required_fields = array();
|
||||
|
||||
|
||||
/**
|
||||
* The PK.
|
||||
* @var int $id
|
||||
* @var int $id
|
||||
*/
|
||||
var $id;
|
||||
|
||||
|
||||
/**
|
||||
* The first time this grade_calculation was created.
|
||||
* @var int $timecreated
|
||||
*/
|
||||
var $timecreated;
|
||||
|
||||
|
||||
/**
|
||||
* The last time this grade_calculation was modified.
|
||||
* @var int $timemodified
|
||||
*/
|
||||
var $timemodified;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor. Optionally (and by default) attempts to fetch corresponding row from DB.
|
||||
* @param object $params an object with named parameters for this grade item.
|
||||
* @param boolean $fetch Whether to fetch corresponding row from DB or not.
|
||||
*/
|
||||
*/
|
||||
function grade_object($params=NULL, $fetch = true) {
|
||||
if (!empty($params) && (is_array($params) || is_object($params))) {
|
||||
$this->assign_to_this($params);
|
||||
|
||||
|
||||
if ($fetch) {
|
||||
$records = $this->fetch_all_using_this();
|
||||
if ($records && count($records) > 0) {
|
||||
$this->assign_to_this(current($records));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates this object in the Database, based on its object variables. ID must be set.
|
||||
*
|
||||
@@ -85,7 +85,7 @@ class grade_object {
|
||||
global $USER;
|
||||
|
||||
$this->timemodified = time();
|
||||
|
||||
|
||||
if (empty($this->usermodified)) {
|
||||
$this->usermodified = $USER->id;
|
||||
}
|
||||
@@ -99,7 +99,7 @@ class grade_object {
|
||||
function delete() {
|
||||
return delete_records($this->table, 'id', $this->id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Records this object in the Database, sets its id to the returned value, and returns that value.
|
||||
* If successful this function also fetches the new object data from database and stores it
|
||||
@@ -115,7 +115,7 @@ class grade_object {
|
||||
}
|
||||
|
||||
$this->timecreated = $this->timemodified = time();
|
||||
|
||||
|
||||
if (empty($this->usermodified)) {
|
||||
$this->usermodified = $USER->id;
|
||||
}
|
||||
@@ -128,7 +128,7 @@ class grade_object {
|
||||
unset($clonethis->$var);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!$this->id = insert_record($this->table, addslashes_recursive($clonethis), true)) {
|
||||
debugging("Could not insert object into db");
|
||||
return false;
|
||||
@@ -161,7 +161,7 @@ class grade_object {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Uses the variables of this object to retrieve all matching objects from the DB.
|
||||
* @return array $objects
|
||||
@@ -169,19 +169,19 @@ class grade_object {
|
||||
function fetch_all_using_this() {
|
||||
$variables = get_object_vars($this);
|
||||
$wheresql = '';
|
||||
|
||||
|
||||
foreach ($variables as $var => $value) {
|
||||
if (!empty($value) && !in_array($var, $this->nonfields)) {
|
||||
$value = addslashes($value);
|
||||
$wheresql .= " $var = '$value' AND ";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Trim trailing AND
|
||||
$wheresql = substr($wheresql, 0, strrpos($wheresql, 'AND'));
|
||||
|
||||
$objects = get_records_select($this->table, $wheresql, 'id');
|
||||
|
||||
|
||||
if (!empty($objects)) {
|
||||
$full_objects = array();
|
||||
|
||||
@@ -195,7 +195,7 @@ class grade_object {
|
||||
return $objects;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Given an associated array or object, cycles through each key/variable
|
||||
@@ -206,7 +206,7 @@ class grade_object {
|
||||
if (in_object_vars($param, $this)) {
|
||||
$this->$param = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,19 +35,19 @@ class grade_outcome extends grade_object {
|
||||
* @var string $table
|
||||
*/
|
||||
var $table = 'grade_outcomes';
|
||||
|
||||
|
||||
/**
|
||||
* Array of class variables that are not part of the DB table fields
|
||||
* @var array $nonfields
|
||||
*/
|
||||
var $nonfields = array('table', 'nonfields', 'scale');
|
||||
|
||||
|
||||
/**
|
||||
* The course this outcome belongs to.
|
||||
* @var int $courseid
|
||||
*/
|
||||
var $courseid;
|
||||
|
||||
|
||||
/**
|
||||
* The shortname of the outcome.
|
||||
* @var string $shortname
|
||||
@@ -71,13 +71,13 @@ class grade_outcome extends grade_object {
|
||||
* @var int $scaleid
|
||||
*/
|
||||
var $scaleid;
|
||||
|
||||
|
||||
/**
|
||||
* The userid of the person who last modified this outcome.
|
||||
* @var int $usermodified
|
||||
*/
|
||||
var $usermodified;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor. Extends the basic functionality defined in grade_object.
|
||||
* @param array $params Can also be a standard object.
|
||||
@@ -90,7 +90,7 @@ class grade_outcome extends grade_object {
|
||||
$this->scale->load_items();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds and returns a grade_outcome object based on 1-3 field values.
|
||||
* @static
|
||||
@@ -105,7 +105,7 @@ class grade_outcome extends grade_object {
|
||||
* @param string $fields
|
||||
* @return object grade_outcome object or false if none found.
|
||||
*/
|
||||
function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") {
|
||||
function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") {
|
||||
if ($grade_outcome = get_record('grade_outcomes', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
|
||||
$grade_outcome = new grade_outcome($grade_outcome);
|
||||
return $grade_outcome;
|
||||
@@ -116,12 +116,12 @@ class grade_outcome extends grade_object {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the most descriptive field for this object. This is a standard method used
|
||||
* Returns the most descriptive field for this object. This is a standard method used
|
||||
* when we do not know the exact type of an object.
|
||||
* @return string name
|
||||
*/
|
||||
function get_name() {
|
||||
return $this->shortname;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
+10
-10
@@ -35,19 +35,19 @@ class grade_scale extends grade_object {
|
||||
* @var string $table
|
||||
*/
|
||||
var $table = 'scale';
|
||||
|
||||
|
||||
/**
|
||||
* Array of class variables that are not part of the DB table fields
|
||||
* @var array $nonfields
|
||||
*/
|
||||
var $nonfields = array('table', 'nonfields', 'scale_items');
|
||||
|
||||
|
||||
/**
|
||||
* The course this scale belongs to.
|
||||
* @var int $courseid
|
||||
*/
|
||||
var $courseid;
|
||||
|
||||
|
||||
/**
|
||||
* The name of the scale.
|
||||
* @var string $name
|
||||
@@ -71,7 +71,7 @@ class grade_scale extends grade_object {
|
||||
* @var string $description
|
||||
*/
|
||||
var $description;
|
||||
|
||||
|
||||
/**
|
||||
* Finds and returns a grade_scale object based on 1-3 field values.
|
||||
* @static
|
||||
@@ -85,7 +85,7 @@ class grade_scale extends grade_object {
|
||||
* @param string $fields
|
||||
* @return object grade_scale object or false if none found.
|
||||
*/
|
||||
function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") {
|
||||
function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") {
|
||||
if ($grade_scale = get_record('scale', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
|
||||
$grade_scale = new grade_scale($grade_scale);
|
||||
return $grade_scale;
|
||||
@@ -94,9 +94,9 @@ class grade_scale extends grade_object {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads the scale's items into the $scale_items array.
|
||||
* Loads the scale's items into the $scale_items array.
|
||||
* There are three ways to achieve this:
|
||||
* 1. No argument given: The $scale string is already loaded and exploded to an array of items.
|
||||
* 2. A string is given: A comma-separated list of items is exploded into an array of items.
|
||||
@@ -113,7 +113,7 @@ class grade_scale extends grade_object {
|
||||
} else {
|
||||
$this->scale_items = explode(',', $items);
|
||||
}
|
||||
|
||||
|
||||
// Trim whitespace around each value
|
||||
foreach ($this->scale_items as $key => $val) {
|
||||
$this->scale_items[$key] = trim($val);
|
||||
@@ -144,7 +144,7 @@ class grade_scale extends grade_object {
|
||||
$this->scale = $items;
|
||||
}
|
||||
|
||||
return $this->scale;
|
||||
}
|
||||
return $this->scale;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
+186
-186
@@ -32,7 +32,7 @@ require_once $CFG->libdir . '/grade/grade_grades.php';
|
||||
* organises as an array primarily, but which can also be converted to other formats.
|
||||
* It has simple method calls with complex implementations, allowing for easy insertion,
|
||||
* deletion and moving of items and categories within the tree.
|
||||
*/
|
||||
*/
|
||||
class grade_tree {
|
||||
/**
|
||||
* The first sortorder for this tree, before any changes were made.
|
||||
@@ -52,7 +52,7 @@ class grade_tree {
|
||||
* @var array $tree_filled
|
||||
*/
|
||||
var $tree_filled = array();
|
||||
|
||||
|
||||
/**
|
||||
* An array of grade_items and grade_categories that have no parent and are not top-categories.
|
||||
* @var arra $fillers
|
||||
@@ -64,7 +64,7 @@ class grade_tree {
|
||||
* @var array $need_update
|
||||
*/
|
||||
var $need_update = array();
|
||||
|
||||
|
||||
/**
|
||||
* An array of objects that need inserting in the DB.
|
||||
* @var array $need_insert
|
||||
@@ -92,7 +92,7 @@ class grade_tree {
|
||||
/**
|
||||
* A string of GET URL variables, namely courseid and sesskey, used in most URLs built by this class.
|
||||
* @var string $commonvars
|
||||
*/
|
||||
*/
|
||||
var $commonvars;
|
||||
|
||||
/**
|
||||
@@ -115,7 +115,7 @@ class grade_tree {
|
||||
global $USER;
|
||||
|
||||
$this->courseid = $courseid;
|
||||
$this->include_grades = $include_grades;
|
||||
$this->include_grades = $include_grades;
|
||||
$this->commonvars = "&sesskey=$USER->sesskey&courseid=$this->courseid";
|
||||
|
||||
if (!empty($tree)) {
|
||||
@@ -123,7 +123,7 @@ class grade_tree {
|
||||
} else {
|
||||
$this->tree_array = $this->get_tree();
|
||||
}
|
||||
|
||||
|
||||
if (!empty($this->tree_array)) {
|
||||
$this->first_sortorder = key($this->tree_array);
|
||||
$this->renumber();
|
||||
@@ -132,8 +132,8 @@ class grade_tree {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the array in search of a given sort order (the elements are indexed by
|
||||
* sortorder), and returns a stdClass object with vital information about the
|
||||
* Parses the array in search of a given sort order (the elements are indexed by
|
||||
* sortorder), and returns a stdClass object with vital information about the
|
||||
* element it has found.
|
||||
* @param int $sortorder
|
||||
* @return object element
|
||||
@@ -141,12 +141,12 @@ class grade_tree {
|
||||
function locate_element($sortorder) {
|
||||
$topcatcount = 0;
|
||||
$retval = false;
|
||||
|
||||
|
||||
if (empty($this->tree_array)) {
|
||||
debugging("grade_tree->tree_array was empty, I could not locate the element at sortorder $sortorder");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$level1count = 0;
|
||||
foreach ($this->tree_array as $level1key => $level1) {
|
||||
$level1count++;
|
||||
@@ -171,27 +171,27 @@ class grade_tree {
|
||||
$retval->position = $level2count;
|
||||
return $retval;
|
||||
}
|
||||
|
||||
|
||||
if (!empty($level2['children'])) {
|
||||
foreach ($level2['children'] as $level3key => $level3) {
|
||||
$level3count++;
|
||||
$retval->index = "$level1key/$level2key/$level3key";
|
||||
|
||||
|
||||
if ($level3key == $sortorder) {
|
||||
$retval->element = $level3;
|
||||
$retval->position = $level3count;
|
||||
return $retval;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an element object, returns its type (topcat, subcat or item).
|
||||
* Given an element object, returns its type (topcat, subcat or item).
|
||||
* The $element can be a straight object (fully instantiated), an array of 'object' and 'children'/'final_grades', or a stdClass element
|
||||
* as produced by grade_tree::locate_element(). This method supports all three types of inputs.
|
||||
* @param object $element
|
||||
@@ -199,7 +199,7 @@ class grade_tree {
|
||||
*/
|
||||
function get_element_type($element) {
|
||||
$object = $this->get_object_from_element($element);
|
||||
|
||||
|
||||
if (empty($object)) {
|
||||
debugging("Invalid element given to grade_tree::get_element_type.");
|
||||
return false;
|
||||
@@ -226,7 +226,7 @@ class grade_tree {
|
||||
} else {
|
||||
debugging("Invalid element given to grade_tree::get_element_type.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
debugging("Could not determine the type of the given element.");
|
||||
return false;
|
||||
@@ -234,25 +234,25 @@ class grade_tree {
|
||||
|
||||
/**
|
||||
* Removes the given element (a stdClass object or a sortorder), remove_elements
|
||||
* it from the tree. This does not renumber the tree. If a sortorder (int) is given, this
|
||||
* it from the tree. This does not renumber the tree. If a sortorder (int) is given, this
|
||||
* method will first retrieve the referenced element from the tree, then re-run the method with that object.
|
||||
* @var object $element An stdClass object typically returned by $this->locate(), or a sortorder (int)
|
||||
* @return boolean
|
||||
*/
|
||||
function remove_element($element) {
|
||||
if (empty($this->first_sortorder)) {
|
||||
if (empty($this->first_sortorder)) {
|
||||
$this->reset_first_sortorder();
|
||||
}
|
||||
|
||||
if (isset($element->index)) {
|
||||
}
|
||||
|
||||
if (isset($element->index)) {
|
||||
// Decompose the element's index and build string for eval(unset) statement to follow
|
||||
$indices = explode('/', $element->index);
|
||||
$element_to_unset = '$this->tree_array[' . $indices[0] . ']';
|
||||
|
||||
|
||||
if (isset($indices[1])) {
|
||||
$element_to_unset .= "['children'][" . $indices[1] . ']';
|
||||
$element_to_unset .= "['children'][" . $indices[1] . ']';
|
||||
}
|
||||
|
||||
|
||||
if (isset($indices[2])) {
|
||||
$element_to_unset .= "['children'][" . $indices[2] . ']';
|
||||
}
|
||||
@@ -276,11 +276,11 @@ class grade_tree {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
debugging("Unable to remove an element from the grade_tree.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inserts an element in the tree. This can be either an array as returned by the grade_category methods, or
|
||||
* an element object returned by grade_tree.
|
||||
@@ -290,10 +290,10 @@ class grade_tree {
|
||||
* @param boolean
|
||||
*/
|
||||
function insert_element($element, $destination_sortorder, $position='before') {
|
||||
if (empty($this->first_sortorder)) {
|
||||
if (empty($this->first_sortorder)) {
|
||||
$this->reset_first_sortorder();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($position == 'before') {
|
||||
$offset = -1;
|
||||
} elseif ($position == 'after') {
|
||||
@@ -302,17 +302,17 @@ class grade_tree {
|
||||
debugging('move_element(..... $position) can only be "before" or "after", you gave ' . $position);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (is_array($element)) {
|
||||
$new_element = new stdClass();
|
||||
$new_element->element = $element;
|
||||
} elseif (is_object($element)) {
|
||||
$new_element = $element;
|
||||
}
|
||||
|
||||
|
||||
$new_element_class = get_class($new_element->element['object']);
|
||||
$has_final_grades = !empty($new_element->element['final_grades']);
|
||||
|
||||
|
||||
// If the object is a grade_item, but the final_grades index isn't yet loaded, make the switch now. Same for grade_category and children
|
||||
if ($new_element_class == 'grade_item' && !$has_final_grades && $this->include_grades) {
|
||||
$new_element->element['final_grades'] = $new_element->element['object']->get_final();
|
||||
@@ -327,25 +327,25 @@ class grade_tree {
|
||||
// Get the position of the destination element
|
||||
$destination_element = $this->locate_element($destination_sortorder);
|
||||
$position = $destination_element->position;
|
||||
|
||||
|
||||
// Decompose the element's index and build string for eval(array_splice) statement to follow
|
||||
$indices = explode('/', $destination_element->index);
|
||||
|
||||
|
||||
if (empty($indices)) {
|
||||
debugging("The destination element did not have a valid index (as assigned by grade_tree::locate_element).");
|
||||
return false;
|
||||
}
|
||||
|
||||
$element_to_splice = '$this->tree_array';
|
||||
|
||||
|
||||
if (isset($indices[1])) {
|
||||
$element_to_splice .= '[' . $indices[0] . "]['children']";
|
||||
$element_to_splice .= '[' . $indices[0] . "]['children']";
|
||||
}
|
||||
|
||||
|
||||
if (isset($indices[2])) {
|
||||
$element_to_splice .= '[' . $indices[1] . "]['children']";
|
||||
}
|
||||
|
||||
|
||||
eval("array_splice($element_to_splice, \$position + \$offset, 0, \$destination_array);");
|
||||
|
||||
if (!is_object($new_element)) {
|
||||
@@ -354,23 +354,23 @@ class grade_tree {
|
||||
}
|
||||
|
||||
$this->need_insert[$new_element->element['object']->id] = $new_element->element['object'];
|
||||
|
||||
return true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves an existing element in the tree to another position OF EQUAL LEVEL. This
|
||||
* constraint is essential and very important.
|
||||
* Moves an existing element in the tree to another position OF EQUAL LEVEL. This
|
||||
* constraint is essential and very important.
|
||||
* @param int $source_sortorder The sortorder of the element to move
|
||||
* @param int $destination_sortorder The sortorder where the element will go
|
||||
* @param string $position Either 'before' the destination_sortorder or 'after' it
|
||||
* @return boolean
|
||||
*/
|
||||
*/
|
||||
function move_element($source_sortorder, $destination_sortorder, $position='before') {
|
||||
if (empty($this->first_sortorder)) {
|
||||
if (empty($this->first_sortorder)) {
|
||||
$this->reset_first_sortorder();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Locate the position of the source element in the tree
|
||||
$source = $this->locate_element($source_sortorder);
|
||||
|
||||
@@ -378,25 +378,25 @@ class grade_tree {
|
||||
$this->remove_element($source);
|
||||
|
||||
$destination = $this->locate_element($destination_sortorder);
|
||||
|
||||
|
||||
// Insert the element before the destination sortorder
|
||||
$this->insert_element($source, $destination_sortorder, $position);
|
||||
$this->insert_element($source, $destination_sortorder, $position);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Uses the key of the first entry in this->tree_array to reset the first_sortorder of this tree. Essential
|
||||
* Uses the key of the first entry in this->tree_array to reset the first_sortorder of this tree. Essential
|
||||
* after each renumbering.
|
||||
*/
|
||||
function reset_first_sortorder() {
|
||||
function reset_first_sortorder() {
|
||||
if (count($this->tree_array) < 1) {
|
||||
debugging("Cannot reset the grade_tree's first_sortorder because the tree_array hasn't been loaded or is empty.");
|
||||
return false;
|
||||
}
|
||||
reset($this->tree_array);
|
||||
$this->first_sortorder = key($this->tree_array);
|
||||
|
||||
|
||||
return $this->first_sortorder;
|
||||
}
|
||||
|
||||
@@ -411,13 +411,13 @@ class grade_tree {
|
||||
*/
|
||||
function renumber($starting_sortorder=NULL, $elements=NULL, $parentid=NULL) {
|
||||
$sortorder = $starting_sortorder;
|
||||
|
||||
|
||||
if (empty($elements) && empty($starting_sortorder)) {
|
||||
if (!isset($this->first_sortorder)) {
|
||||
debugging("The tree's first_order variable isn't set, you must provide a starting_sortorder to the renumber method.");
|
||||
return false;
|
||||
}
|
||||
$sortorder = $this->first_sortorder - 1;
|
||||
$sortorder = $this->first_sortorder - 1;
|
||||
$elements = $this->tree_array;
|
||||
} elseif(!empty($elements) && empty($starting_sortorder)) {
|
||||
debugging("Entered second level of recursion without a starting_sortorder.");
|
||||
@@ -427,35 +427,35 @@ class grade_tree {
|
||||
$this->first_sortorder = $sortorder;
|
||||
|
||||
foreach ($elements as $key => $element) {
|
||||
$this->first_sortorder++;
|
||||
$this->first_sortorder++;
|
||||
$new_sortorder = $this->first_sortorder;
|
||||
$old_sortorder = $element['object']->get_sortorder();
|
||||
|
||||
// Assign new sortorder
|
||||
$element['object']->sortorder = $new_sortorder;
|
||||
|
||||
|
||||
$element['object']->previous_sortorder = $this->get_neighbour_sortorder($element, 'previous');
|
||||
$element['object']->next_sortorder = $this->get_neighbour_sortorder($element, 'next');
|
||||
|
||||
if (!empty($element['children'])) {
|
||||
$newtree[$this->first_sortorder] = $element;
|
||||
$newtree[$this->first_sortorder]['children'] = $this->renumber($this->first_sortorder, $element['children'], $element['object']->id);
|
||||
} else {
|
||||
$newtree[$this->first_sortorder] = $element;
|
||||
}
|
||||
|
||||
$newtree[$this->first_sortorder]['children'] = $this->renumber($this->first_sortorder, $element['children'], $element['object']->id);
|
||||
} else {
|
||||
$newtree[$this->first_sortorder] = $element;
|
||||
}
|
||||
|
||||
if ($new_sortorder != $old_sortorder) {
|
||||
$element['object']->set_parent_id($parentid);
|
||||
$element['object']->set_sortorder($new_sortorder);
|
||||
$this->need_update[] = $element['object'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If no starting sortorder was given, it means we have finished building the tree, so assign it to this->tree_array. Otherwise return the new tree.
|
||||
if (empty($starting_sortorder)) {
|
||||
$this->tree_array = $newtree;
|
||||
unset($this->first_sortorder);
|
||||
$this->build_tree_filled();
|
||||
$this->build_tree_filled();
|
||||
return true;
|
||||
} else {
|
||||
return $newtree;
|
||||
@@ -463,7 +463,7 @@ class grade_tree {
|
||||
}
|
||||
|
||||
/**
|
||||
* Because the $element referred to in this class is rather loosely defined, it
|
||||
* Because the $element referred to in this class is rather loosely defined, it
|
||||
* may come in different flavours and forms. However, it will almost always contain
|
||||
* an object (or be an object). This method takes care of type checking and returns
|
||||
* the object within the $element, if present.
|
||||
@@ -474,7 +474,7 @@ class grade_tree {
|
||||
if (is_object($element) && get_class($element) != 'stdClass') {
|
||||
return $element;
|
||||
} elseif (!empty($element->element['object'])) {
|
||||
return $element->element['object'];
|
||||
return $element->element['object'];
|
||||
} elseif (!empty($element['object'])) {
|
||||
return $element['object'];
|
||||
} elseif (!method_exists($object, 'get_sortorder')) {
|
||||
@@ -485,8 +485,8 @@ class grade_tree {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given an element array ('object' => object, 'children' => array),
|
||||
/**
|
||||
* Given an element array ('object' => object, 'children' => array),
|
||||
* searches for the element at the same level placed immediately before this one
|
||||
* in sortorder, and returns its sortorder if found. Recursive function.
|
||||
* @param array $element
|
||||
@@ -498,18 +498,18 @@ class grade_tree {
|
||||
if (empty($this->tree_array) || empty($element) || empty($position) || !in_array($position, array('previous', 'next'))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
$object = $this->get_object_from_element($element);
|
||||
|
||||
|
||||
if (empty($object)) {
|
||||
debugging("Invalid element given to grade_tree::get_neighbour_sortorder.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (empty($array)) {
|
||||
$array = $this->tree_array;
|
||||
}
|
||||
}
|
||||
$result = null;
|
||||
|
||||
|
||||
$returnnextelement = false;
|
||||
$count = 0;
|
||||
|
||||
@@ -518,18 +518,18 @@ class grade_tree {
|
||||
if ($returnnextelement) {
|
||||
return $sortorder;
|
||||
}
|
||||
|
||||
|
||||
if ($object->get_sortorder() == $sortorder) {
|
||||
if ($position == 'previous') {
|
||||
if ($count > 0) {
|
||||
return $lastsortorder;
|
||||
}
|
||||
}
|
||||
} elseif ($position == 'next') {
|
||||
$returnnextelement = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$lastsortorder = $sortorder;
|
||||
|
||||
if (!empty($child['children'])) {
|
||||
@@ -537,7 +537,7 @@ class grade_tree {
|
||||
if ($result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$count++;
|
||||
}
|
||||
@@ -545,12 +545,12 @@ class grade_tree {
|
||||
}
|
||||
|
||||
/**
|
||||
* Provided $this->fillers is ready, and given a $tree array and a grade_category or grade_item,
|
||||
* Provided $this->fillers is ready, and given a $tree array and a grade_category or grade_item,
|
||||
* checks the fillers array to see if the current element needs to be included before the given
|
||||
* object, and includes it if needed, or appends the filler to the tree if no object is given.
|
||||
* object, and includes it if needed, or appends the filler to the tree if no object is given.
|
||||
* The inserted filler is then deleted from the fillers array. The tree array is then returned.
|
||||
* @param array $tree
|
||||
* @param object $object Optional object before which to insert any fillers with a lower sortorder.
|
||||
* @param object $object Optional object before which to insert any fillers with a lower sortorder.
|
||||
* If null, the current filler is appended to the tree.
|
||||
* @return array $tree
|
||||
*/
|
||||
@@ -566,16 +566,16 @@ class grade_tree {
|
||||
|
||||
// Remove filler so it doesn't get included again later
|
||||
unset($this->fillers[$sortorder]);
|
||||
|
||||
|
||||
$element = array();
|
||||
|
||||
if (get_class($filler_object) == 'grade_category') {
|
||||
$children = $filler_object->get_children(1);
|
||||
unset($filler_object->children);
|
||||
|
||||
|
||||
$itemtree = array();
|
||||
|
||||
foreach ($children as $element) {
|
||||
foreach ($children as $element) {
|
||||
$finals = array();
|
||||
|
||||
if ($this->include_grades) {
|
||||
@@ -584,9 +584,9 @@ class grade_tree {
|
||||
$finals = $final->fetch_all_using_this();
|
||||
}
|
||||
|
||||
$itemtree[$element['object']->sortorder] = array('object' => $element['object'], 'finalgrades' => $finals);
|
||||
$itemtree[$element['object']->sortorder] = array('object' => $element['object'], 'finalgrades' => $finals);
|
||||
}
|
||||
|
||||
|
||||
ksort($itemtree);
|
||||
$element['children'] = $itemtree;
|
||||
} elseif (get_class($filler_object) == 'grade_item' && $this->include_grades) {
|
||||
@@ -595,42 +595,42 @@ class grade_tree {
|
||||
}
|
||||
|
||||
$filler_object->sortorder = $sortorder;
|
||||
|
||||
|
||||
$element['object'] = $filler_object;
|
||||
$tree[$sortorder] = $element;
|
||||
$tree[$sortorder] = $element;
|
||||
}
|
||||
|
||||
return $tree;
|
||||
return $tree;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Given an array of grade_categories or a grade_items, guesses whether each needs to be added to the fillers
|
||||
* array or not (by checking children if a category, or checking parents if an item). It then
|
||||
* array or not (by checking children if a category, or checking parents if an item). It then
|
||||
* instantiates the objects if needed and adds them to the fillers array. The element is then
|
||||
* removed from the given array of objects, and the array is returned.
|
||||
* @param array $object array of stdClass objects or grade_categories or grade_items
|
||||
*/
|
||||
function add_fillers($objects) {
|
||||
foreach ($objects as $key => $object) {
|
||||
|
||||
|
||||
if (get_class($object) == 'grade_item' || !empty($object->itemname)) {
|
||||
|
||||
|
||||
if (empty($object->categoryid)) {
|
||||
$item = new grade_item($object);
|
||||
$sortorder = $item->get_sortorder();
|
||||
if (!empty($sortorder)) {
|
||||
$this->fillers[$sortorder] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} elseif (get_class($object) == 'grade_category' || !empty($object->fullname)) {
|
||||
$topcatobject = new grade_category($object, false);
|
||||
|
||||
|
||||
if ($topcatobject->get_childrentype() == 'grade_item' && empty($topcatobject->parent)) {
|
||||
$topcatobject->childrencount = $topcatobject->has_children();
|
||||
$this->fillers[$object->sortorder] = $topcatobject;
|
||||
unset($objects[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $objects;
|
||||
@@ -657,7 +657,7 @@ class grade_tree {
|
||||
if (!empty($level1['finalgrades'])) {
|
||||
foreach ($level1['finalgrades'] as $final_grade) {
|
||||
$this->grades[$final_grade->userid][$final_grade->itemid] = $final_grade->finalgrade;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -669,7 +669,7 @@ class grade_tree {
|
||||
|
||||
|
||||
/**
|
||||
* Static method that returns a sorted, nested array of all grade_categories and grade_items for
|
||||
* Static method that returns a sorted, nested array of all grade_categories and grade_items for
|
||||
* a given course, or for the entire site if no courseid is given. This method is not recursive
|
||||
* by design, because we want to limit the layers to 3, and because we want to avoid accessing
|
||||
* the DB with recursive methods.
|
||||
@@ -689,7 +689,7 @@ class grade_tree {
|
||||
$catconstraint = " AND $category_table.courseid = $this->courseid ";
|
||||
$itemconstraint = " AND $items_table.courseid = $this->courseid ";
|
||||
}
|
||||
|
||||
|
||||
// Get ordered list of grade_items (not category type)
|
||||
$query = "SELECT * FROM $items_table WHERE itemtype <> 'category' $itemconstraint ORDER BY sortorder";
|
||||
$grade_items = get_records_sql($query);
|
||||
@@ -697,16 +697,16 @@ class grade_tree {
|
||||
if (empty($grade_items)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// For every grade_item that doesn't have a parent category, create category fillers
|
||||
$grade_items = $this->add_fillers($grade_items);
|
||||
|
||||
|
||||
// Get all top categories
|
||||
$query = "SELECT $category_table.*, sortorder FROM $category_table, $items_table
|
||||
$query = "SELECT $category_table.*, sortorder FROM $category_table, $items_table
|
||||
WHERE iteminstance = $category_table.id AND itemtype = 'category' $catconstraint ORDER BY sortorder";
|
||||
|
||||
|
||||
$topcats = get_records_sql($query);
|
||||
|
||||
|
||||
if (empty($topcats)) {
|
||||
$topcats = $grade_items;
|
||||
$topcats[0] = new stdClass();
|
||||
@@ -720,13 +720,13 @@ class grade_tree {
|
||||
foreach ($topcats as $topcatid => $topcat) {
|
||||
|
||||
// Check the fillers array, see if one must be inserted before this topcat
|
||||
$tree = $this->include_fillers($tree, $topcat);
|
||||
$tree = $this->include_fillers($tree, $topcat);
|
||||
|
||||
$query = "SELECT $category_table.*, sortorder FROM $category_table, $items_table
|
||||
$query = "SELECT $category_table.*, sortorder FROM $category_table, $items_table
|
||||
WHERE iteminstance = $category_table.id AND parent = $topcatid $catconstraint ORDER BY sortorder";
|
||||
$subcats = get_records_sql($query);
|
||||
$subcattree = array();
|
||||
|
||||
|
||||
if (empty($subcats)) {
|
||||
continue;
|
||||
}
|
||||
@@ -734,12 +734,12 @@ class grade_tree {
|
||||
foreach ($subcats as $subcatid => $subcat) {
|
||||
$itemtree = array();
|
||||
$items = get_records('grade_items', 'categoryid', $subcatid, 'sortorder');
|
||||
|
||||
|
||||
if (empty($items)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($items as $itemid => $item) {
|
||||
|
||||
foreach ($items as $itemid => $item) {
|
||||
$finals = array();
|
||||
|
||||
if ($this->include_grades) {
|
||||
@@ -754,29 +754,29 @@ class grade_tree {
|
||||
|
||||
$itemtree[$item->sortorder] = array('object' => $item, 'finalgrades' => $finals);
|
||||
}
|
||||
|
||||
|
||||
ksort($itemtree);
|
||||
$sortorder = $subcat->sortorder;
|
||||
$subcat = new grade_category($subcat, false);
|
||||
$subcat->sortorder = $sortorder;
|
||||
$subcattree[$subcat->sortorder] = array('object' => $subcat, 'children' => $itemtree);
|
||||
$subcattree[$subcat->sortorder] = array('object' => $subcat, 'children' => $itemtree);
|
||||
}
|
||||
|
||||
ksort($subcattree);
|
||||
$sortorder = $topcat->sortorder;
|
||||
$topcat = new grade_category($topcat, false);
|
||||
$topcat->sortorder = $sortorder;
|
||||
$tree[$topcat->sortorder] = array('object' => $topcat, 'children' => $subcattree);
|
||||
$tree[$topcat->sortorder] = array('object' => $topcat, 'children' => $subcattree);
|
||||
}
|
||||
|
||||
|
||||
// If there are still grade_items or grade_categories without a top category, add another filler
|
||||
if (!empty($this->fillers)) {
|
||||
ksort($this->fillers);
|
||||
foreach ($this->fillers as $sortorder => $object) {
|
||||
$tree = $this->include_fillers($tree);
|
||||
foreach ($this->fillers as $sortorder => $object) {
|
||||
$tree = $this->include_fillers($tree);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$db->debug = false;
|
||||
ksort($tree);
|
||||
return $tree;
|
||||
@@ -784,12 +784,12 @@ class grade_tree {
|
||||
|
||||
/**
|
||||
* Returns a hierarchical array, prefilled with the values needed to populate
|
||||
* the tree of grade_items in the cases where a grade_item or grade_category doesn't have a
|
||||
* the tree of grade_items in the cases where a grade_item or grade_category doesn't have a
|
||||
* 2nd level topcategory.
|
||||
* @param object $object A grade_item or a grade_category object
|
||||
* @return array
|
||||
*/
|
||||
function get_filler($object) {
|
||||
function get_filler($object) {
|
||||
$filler_array = array();
|
||||
|
||||
// Depending on whether the filler is for a grade_item or a category...
|
||||
@@ -804,16 +804,16 @@ class grade_tree {
|
||||
}
|
||||
}
|
||||
|
||||
$filler_array = array('object' => 'filler', 'children' =>
|
||||
array(0 => array('object' => 'filler', 'children' =>
|
||||
array(0 => array('object' => $object, 'finalgrades' => $finals)))));
|
||||
$filler_array = array('object' => 'filler', 'children' =>
|
||||
array(0 => array('object' => 'filler', 'children' =>
|
||||
array(0 => array('object' => $object, 'finalgrades' => $finals)))));
|
||||
} elseif (method_exists($object, 'get_children')) {
|
||||
|
||||
$subcat_children = $object->get_children(0, 'flat');
|
||||
$children_for_tree = array();
|
||||
foreach ($subcat_children as $itemid => $item) {
|
||||
$finals = array();
|
||||
|
||||
|
||||
if ($this->include_grades) {
|
||||
if (get_class($item) == 'grade_item') {
|
||||
$finals = $item->get_final();
|
||||
@@ -824,21 +824,21 @@ class grade_tree {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$children_for_tree[$itemid] = array('object' => $item, 'finalgrades' => $finals);
|
||||
|
||||
$children_for_tree[$itemid] = array('object' => $item, 'finalgrades' => $finals);
|
||||
}
|
||||
|
||||
|
||||
if (empty($object->childrencount)) {
|
||||
$object->childrencount = 1;
|
||||
}
|
||||
|
||||
|
||||
$filler_array = array('object' => 'filler', 'colspan' => $object->childrencount, 'children' =>
|
||||
array(0 => array('object' => $object, 'children' => $children_for_tree)));
|
||||
}
|
||||
}
|
||||
|
||||
return $filler_array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a HTML table with all the grades in the course requested, or all the grades in the site.
|
||||
* IMPORTANT: This method (and its associated methods) assumes that we are using only 2 levels of categories (topcat and subcat)
|
||||
@@ -860,12 +860,12 @@ class grade_tree {
|
||||
debugging("The tree_filled array wasn't initialised, grade_tree could not display the grades correctly.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Fetch array of students enroled in this course
|
||||
if (!$context = get_context_instance(CONTEXT_COURSE, $this->courseid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$users = get_role_users(@implode(',', $CFG->gradebookroles), $context);
|
||||
|
||||
$topcathtml = '<tr><td class="filler"> </td>';
|
||||
@@ -875,17 +875,17 @@ class grade_tree {
|
||||
|
||||
foreach ($tree as $topcat) {
|
||||
$itemcount = 0;
|
||||
|
||||
|
||||
foreach ($topcat['children'] as $catkey => $cat) {
|
||||
$catitemcount = 0;
|
||||
|
||||
foreach ($cat['children'] as $item) {
|
||||
$itemcount++;
|
||||
$catitemcount++;
|
||||
$itemhtml .= '<td>' . $item['object']->itemname . '</td>';
|
||||
$itemhtml .= '<td>' . $item['object']->itemname . '</td>';
|
||||
$items[] = $item;
|
||||
}
|
||||
|
||||
|
||||
if ($cat['object'] == 'filler') {
|
||||
$cathtml .= '<td class="subfiller"> </td>';
|
||||
} else {
|
||||
@@ -905,31 +905,31 @@ class grade_tree {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
$studentshtml = '';
|
||||
|
||||
foreach ($users as $userid => $user) {
|
||||
$studentshtml .= '<tr><th>' . $user->firstname . ' ' . $user->lastname . '</th>';
|
||||
foreach ($items as $item) {
|
||||
if (!empty($this->grades[$userid][$item['object']->id])) {
|
||||
$studentshtml .= '<td>' . $this->grades[$userid][$item['object']->id] . '</td>' . "\n";
|
||||
$studentshtml .= '<td>' . $this->grades[$userid][$item['object']->id] . '</td>' . "\n";
|
||||
} else {
|
||||
$studentshtml .= '<td>0</td>' . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
$studentshtml .= '</tr>';
|
||||
}
|
||||
|
||||
|
||||
$itemhtml .= '</tr>';
|
||||
$cathtml .= '</tr>';
|
||||
$topcathtml .= '</tr>';
|
||||
|
||||
|
||||
$reporthtml = "<table style=\"text-align: center\" border=\"1\">$topcathtml$cathtml$itemhtml";
|
||||
$reporthtml .= $studentshtml;
|
||||
$reporthtml .= $studentshtml;
|
||||
$reporthtml .= "</table>";
|
||||
return $reporthtml;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Using $this->tree_array, builds $this->tree_filled, which is the same array but with fake categories as
|
||||
@@ -942,9 +942,9 @@ class grade_tree {
|
||||
debugging("You cannot build the tree_filled array until the tree_array is filled.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$this->tree_filled = array();
|
||||
|
||||
|
||||
// Detect any category that is now child-less and delete it
|
||||
foreach ($this->tree_array as $level1order => $level1) {
|
||||
if ($this->get_element_type($level1) == 'item' || $this->get_element_type($level1) == 'subcat') {
|
||||
@@ -969,12 +969,12 @@ class grade_tree {
|
||||
foreach ($this->need_update as $object) {
|
||||
if (!$object->update()) {
|
||||
debugging("Could not update the object in DB.");
|
||||
} elseif ($object->is_old_parent_childless()) {
|
||||
} elseif ($object->is_old_parent_childless()) {
|
||||
$this->need_delete[$object->old_parent->id] = $object->old_parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Deletions
|
||||
// Deletions
|
||||
foreach ($this->need_delete as $id => $object) {
|
||||
// If an item is both in the delete AND insert arrays, it must be an existing object that only needs updating, so ignore it.
|
||||
if (empty($this->need_insert[$id])) {
|
||||
@@ -1042,13 +1042,13 @@ class grade_tree {
|
||||
$list .= '<form action="category.php" method="post">' . "\n";
|
||||
$list .= '<ul id="grade_edit_tree">' . "\n";
|
||||
$elements = $this->tree_array;
|
||||
|
||||
|
||||
$element_type_options = '<select name="element_type">' . "\n";
|
||||
$element_type_options .= "<option value=\"items\">$stritems</option><option value=\"categories\">$strcategories</option>\n";
|
||||
$element_type_options .= "</select>\n";
|
||||
|
||||
|
||||
$strforelementtypes= get_string("forelementtypes", 'grades', $element_type_options);
|
||||
|
||||
|
||||
$closing_form_tags .= '<fieldset><legend>' . $strnewcategory . '</legend>' . "\n";
|
||||
$closing_form_tags .= '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />' . "\n";
|
||||
$closing_form_tags .= '<input type="hidden" name="courseid" value="' . $this->courseid . '" />' . "\n";
|
||||
@@ -1061,13 +1061,13 @@ class grade_tree {
|
||||
$closing_form_tags .= "</form>\n";
|
||||
} else {
|
||||
$list = '<ul class="level' . $level . 'children">' . "\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$first = true;
|
||||
$count = 1;
|
||||
$last = false;
|
||||
$last_sortorder = null;
|
||||
|
||||
|
||||
if (count($elements) == 1) {
|
||||
$last = true;
|
||||
}
|
||||
@@ -1076,25 +1076,25 @@ class grade_tree {
|
||||
$object = $element['object'];
|
||||
|
||||
$object_name = $object->get_name();
|
||||
$object_class = get_class($object);
|
||||
$object_class = get_class($object);
|
||||
$object_parent = $object->get_parent_id();
|
||||
$element_type = $this->get_element_type($element);
|
||||
|
||||
|
||||
$highlight_class = '';
|
||||
|
||||
|
||||
if ($source_sortorder == $sortorder && !empty($action)) {
|
||||
$highlight_class = ' selected_element ';
|
||||
}
|
||||
|
||||
|
||||
// Prepare item icon if appropriate
|
||||
$module_icon = '';
|
||||
if (!empty($object->itemmodule)) {
|
||||
$module_icon = '<div class="moduleicon">'
|
||||
. '<label for="checkbox_select_' . $sortorder . '">'
|
||||
. '<img src="'
|
||||
. '<img src="'
|
||||
. $CFG->modpixpath . '/' . $object->itemmodule . '/icon.gif" alt="'
|
||||
. $object->itemmodule . '" title="' . $object->itemmodule . '" /></label></div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Add dimmed_text span around object name if set to hidden
|
||||
$hide_show = 'hide';
|
||||
@@ -1102,7 +1102,7 @@ class grade_tree {
|
||||
$object_name = '<span class="dimmed_text">' . $object_name . '</span>';
|
||||
$hide_show = 'show';
|
||||
}
|
||||
|
||||
|
||||
// Prepare lock/unlock string
|
||||
$lock_unlock = 'lock';
|
||||
if ($object->is_locked()) {
|
||||
@@ -1117,89 +1117,89 @@ class grade_tree {
|
||||
$group = 'categories';
|
||||
}
|
||||
|
||||
$select_checkbox = '<div class="select_checkbox">' . "\n"
|
||||
$select_checkbox = '<div class="select_checkbox">' . "\n"
|
||||
. '<input id="checkbox_select_' . $sortorder . '" type="checkbox" name="' . $group . '[' . $sortorder . ']" />' . "\n"
|
||||
. '</div>' . "\n";
|
||||
|
||||
// Add a label around the object name to trigger the checkbox
|
||||
$object_name = '<label for="checkbox_select_' . $sortorder . '">' . $object_name . '</label>';
|
||||
$object_name = '<label for="checkbox_select_' . $sortorder . '">' . $object_name . '</label>';
|
||||
}
|
||||
|
||||
$list .= '<li class="level' . $level . 'element sortorder'
|
||||
. $object->get_sortorder() . $highlight_class . '">' . "\n"
|
||||
$list .= '<li class="level' . $level . 'element sortorder'
|
||||
. $object->get_sortorder() . $highlight_class . '">' . "\n"
|
||||
. $select_checkbox . $module_icon . $object_name;
|
||||
|
||||
|
||||
|
||||
|
||||
$list .= '<div class="icons">' . "\n";
|
||||
|
||||
// Print up arrow
|
||||
if (!$first) {
|
||||
$list .= '<a href="category.php?'."source=$sortorder&moveup={$object->previous_sortorder}$this->commonvars\">\n";
|
||||
$list .= '<img src="'.$CFG->pixpath.'/t/up.gif" class="iconsmall" ' . 'alt="'.$strmoveup.'" title="'.$strmoveup.'" /></a>'. "\n";
|
||||
$list .= '<a href="category.php?'."source=$sortorder&moveup={$object->previous_sortorder}$this->commonvars\">\n";
|
||||
$list .= '<img src="'.$CFG->pixpath.'/t/up.gif" class="iconsmall" ' . 'alt="'.$strmoveup.'" title="'.$strmoveup.'" /></a>'. "\n";
|
||||
} else {
|
||||
$list .= '<img src="'.$CFG->wwwroot.'/pix/spacer.gif" class="iconsmall" alt="" /> '. "\n";
|
||||
}
|
||||
|
||||
// Print down arrow
|
||||
if (!$last) {
|
||||
$list .= '<a href="category.php?'."source=$sortorder&movedown={$object->next_sortorder}$this->commonvars\">\n";
|
||||
$list .= '<img src="'.$CFG->pixpath.'/t/down.gif" class="iconsmall" ' . 'alt="'.$strmovedown.'" title="'.$strmovedown.'" /></a>'. "\n";
|
||||
$list .= '<a href="category.php?'."source=$sortorder&movedown={$object->next_sortorder}$this->commonvars\">\n";
|
||||
$list .= '<img src="'.$CFG->pixpath.'/t/down.gif" class="iconsmall" ' . 'alt="'.$strmovedown.'" title="'.$strmovedown.'" /></a>'. "\n";
|
||||
} else {
|
||||
$list .= '<img src="'.$CFG->wwwroot.'/pix/spacer.gif" class="iconsmall" alt="" /> ' . "\n";
|
||||
}
|
||||
|
||||
|
||||
// Print move icon
|
||||
if ($element_type != 'topcat') {
|
||||
if ($element_type != 'topcat') {
|
||||
$list .= '<a href="category.php?'."source=$sortorder&action=move&type=$element_type$this->commonvars\">\n";
|
||||
$list .= '<img src="'.$CFG->pixpath.'/t/move.gif" class="iconsmall" alt="'.$strmove.'" title="'.$strmove.'" /></a>'. "\n";
|
||||
$list .= '<img src="'.$CFG->pixpath.'/t/move.gif" class="iconsmall" alt="'.$strmove.'" title="'.$strmove.'" /></a>'. "\n";
|
||||
} else {
|
||||
$list .= '<img src="'.$CFG->wwwroot.'/pix/spacer.gif" class="iconsmall" alt="" /> ' . "\n";
|
||||
}
|
||||
|
||||
|
||||
// Print edit icon
|
||||
$list .= '<a href="category.php?'."target=$sortorder&action=edit$this->commonvars\">\n";
|
||||
$list .= '<img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'
|
||||
.$stredit.'" title="'.$stredit.'" /></a>'. "\n";
|
||||
|
||||
.$stredit.'" title="'.$stredit.'" /></a>'. "\n";
|
||||
|
||||
// Print delete icon
|
||||
$list .= '<a href="category.php?'."target=$sortorder&action=delete$this->commonvars\">\n";
|
||||
$list .= '<img src="'.$CFG->pixpath.'/t/delete.gif" class="iconsmall" alt="'
|
||||
.$strdelete.'" title="'.$strdelete.'" /></a>'. "\n";
|
||||
.$strdelete.'" title="'.$strdelete.'" /></a>'. "\n";
|
||||
|
||||
// Print hide/show icon
|
||||
$list .= '<a href="category.php?'."target=$sortorder&action=$hide_show$this->commonvars\">\n";
|
||||
$list .= '<img src="'.$CFG->pixpath.'/t/'.$hide_show.'.gif" class="iconsmall" alt="'
|
||||
.${'str' . $hide_show}.'" title="'.${'str' . $hide_show}.'" /></a>'. "\n";
|
||||
.${'str' . $hide_show}.'" title="'.${'str' . $hide_show}.'" /></a>'. "\n";
|
||||
// Print lock/unlock icon
|
||||
$list .= '<a href="category.php?'."target=$sortorder&action=$lock_unlock$this->commonvars\">\n";
|
||||
$list .= '<img src="'.$CFG->pixpath.'/t/'.$lock_unlock.'.gif" class="iconsmall" alt="'
|
||||
.${'str' . $lock_unlock}.'" title="'.${'str' . $lock_unlock}.'" /></a>'. "\n";
|
||||
|
||||
.${'str' . $lock_unlock}.'" title="'.${'str' . $lock_unlock}.'" /></a>'. "\n";
|
||||
|
||||
$list .= '</div> <!-- end icons div -->';
|
||||
|
||||
if (!empty($element['children'])) {
|
||||
$list .= $this->get_edit_tree($level + 1, $element['children'], $source_sortorder, $action, $source_type);
|
||||
}
|
||||
|
||||
|
||||
$list .= '</li>' . "\n";
|
||||
|
||||
$first = false;
|
||||
$count++;
|
||||
if ($count == count($elements)) {
|
||||
$last = true;
|
||||
}
|
||||
}
|
||||
|
||||
$last_sortorder = $sortorder;
|
||||
}
|
||||
|
||||
|
||||
// Add an insertion box if source_sortorder is given and a few other constraints are satisfied
|
||||
if ($source_sortorder && !empty($action)) {
|
||||
$moving_item_near_subcat = $element_type == 'subcat' && $source_type == 'item' && $level > 1;
|
||||
$moving_cat_to_lower_level = ($level == 2 && $source_type == 'topcat') || ($level > 2 && $source_type == 'subcat');
|
||||
$moving_subcat_near_item_in_cat = $element_type == 'item' && $source_type == 'subcat' && $level > 1;
|
||||
$moving_element_near_itself = $sortorder == $source_sortorder;
|
||||
|
||||
if (!$moving_item_near_subcat && !$moving_cat_to_lower_level && !$moving_subcat_near_item_in_cat && !$moving_element_near_itself) {
|
||||
|
||||
if (!$moving_item_near_subcat && !$moving_cat_to_lower_level && !$moving_subcat_near_item_in_cat && !$moving_element_near_itself) {
|
||||
$list .= '<li class="insertion">' . "\n";
|
||||
$list .= '<a href="category.php?' . "source=$source_sortorder&$action=$last_sortorder$this->commonvars\">\n";
|
||||
$list .= '<img class="movetarget" src="'.$CFG->wwwroot.'/pix/movehere.gif" alt="'.$strmovehere.'" title="'.$strmovehere.'" />' . "\n";
|
||||
|
||||
+6
-6
@@ -116,7 +116,7 @@ function grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance,
|
||||
if ($itemdetails) {
|
||||
$itemdetails = (array)$itemdetails;
|
||||
|
||||
// grademin and grademax ignored when scale specified
|
||||
// grademin and grademax ignored when scale specified
|
||||
if (array_key_exists('scaleid', $itemdetails)) {
|
||||
if ($itemdetails['scaleid']) {
|
||||
unset($itemdetails['grademin']);
|
||||
@@ -204,7 +204,7 @@ function grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance,
|
||||
$rawgrade = false;
|
||||
$feedback = false;
|
||||
$feedbackformat = FORMAT_MOODLE;
|
||||
|
||||
|
||||
if (array_key_exists('rawgrade', $grade)) {
|
||||
$rawgrade = $grade['rawgrade'];
|
||||
}
|
||||
@@ -356,11 +356,11 @@ function grade_update_final_grades($courseid, $regradeall=false) {
|
||||
$calculated = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!$needsupdate) {
|
||||
// no update needed
|
||||
return true;
|
||||
|
||||
|
||||
} else if ($calculated) {
|
||||
// flag all calculated grade items with needsupdate
|
||||
// we want to make sure all are ok, this can be improved later with proper dependency calculation
|
||||
@@ -374,8 +374,8 @@ function grade_update_final_grades($courseid, $regradeall=false) {
|
||||
//force recalculation and forced update of all parents
|
||||
$grade_item->force_regrading();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// again make sure all date is up-to-date - the needsupdate flag might have changed
|
||||
foreach ($grade_items as $gid=>$gitem) {
|
||||
$grade_item =& $grade_items[$gid];
|
||||
|
||||
@@ -44,11 +44,11 @@ require_once($CFG->libdir . '/ddllib.php');
|
||||
* 3 users for 3 grade_items
|
||||
*/
|
||||
class grade_test extends UnitTestCase {
|
||||
|
||||
|
||||
/**
|
||||
* Each database table receives a number of test entries. These are saved as
|
||||
* arrays of stcClass objects available to this class. This means that
|
||||
* every test has access to these test data. The order of the following array is
|
||||
* every test has access to these test data. The order of the following array is
|
||||
* crucial, because of the interrelationships between objects.
|
||||
*/
|
||||
var $tables = array('grade_categories',
|
||||
@@ -72,7 +72,7 @@ class grade_test extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Create temporary test tables and entries in the database for these tests.
|
||||
* These tests have to work on a brand new site.
|
||||
* These tests have to work on a brand new site.
|
||||
* Override $CFG->prefix while these tests run.
|
||||
*/
|
||||
function setUp() {
|
||||
@@ -82,7 +82,7 @@ class grade_test extends UnitTestCase {
|
||||
if (!$this->create_test_tables()) {
|
||||
die("Could not create all the test tables!");
|
||||
}
|
||||
|
||||
|
||||
foreach ($this->tables as $table) {
|
||||
$function = "load_$table";
|
||||
$this->$function();
|
||||
@@ -91,10 +91,10 @@ class grade_test extends UnitTestCase {
|
||||
|
||||
function create_test_tables() {
|
||||
$result = true;
|
||||
|
||||
|
||||
/// Define table grade_items to be created
|
||||
$table = new XMLDBTable('grade_items');
|
||||
|
||||
|
||||
if (!table_exists($table)) {
|
||||
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
|
||||
$table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
|
||||
@@ -132,10 +132,10 @@ class grade_test extends UnitTestCase {
|
||||
/// Launch create table for grade_items
|
||||
$result = $result && create_table($table, true, false);
|
||||
}
|
||||
|
||||
|
||||
/// Define table grade_categories to be created
|
||||
$table = new XMLDBTable('grade_categories');
|
||||
|
||||
|
||||
if ($result && !table_exists($table)) {
|
||||
|
||||
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
|
||||
@@ -159,7 +159,7 @@ class grade_test extends UnitTestCase {
|
||||
|
||||
/// Define table grade_grades_text to be created
|
||||
$table = new XMLDBTable('grade_grades_text');
|
||||
|
||||
|
||||
if ($result && !table_exists($table)) {
|
||||
|
||||
/// Adding fields to table grade_grades_text
|
||||
@@ -255,7 +255,7 @@ class grade_test extends UnitTestCase {
|
||||
$table->addFieldInfo('exported', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
|
||||
$table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
|
||||
|
||||
|
||||
/// Adding keys to table grade_grades
|
||||
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN, array('itemid'), 'grade_items', array('id'));
|
||||
@@ -285,10 +285,10 @@ class grade_test extends UnitTestCase {
|
||||
/// Launch create table for scale
|
||||
$result = $result && create_table($table, true, false);
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Drop test tables from DB.
|
||||
* Restore original $CFG->prefix.
|
||||
@@ -300,16 +300,16 @@ class grade_test extends UnitTestCase {
|
||||
if (count($this->$table) > 0) {
|
||||
unset ($this->$table);
|
||||
}
|
||||
}
|
||||
}
|
||||
$CFG->prefix = $CFG->old_prefix;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load scale data into the database, and adds the corresponding objects to this class' variable.
|
||||
*/
|
||||
function load_scale() {
|
||||
$scale = new stdClass();
|
||||
|
||||
|
||||
$scale->name = 'unittestscale1';
|
||||
$scale->courseid = $this->courseid;
|
||||
$scale->userid = $this->userid;
|
||||
@@ -318,13 +318,13 @@ class grade_test extends UnitTestCase {
|
||||
$scale->timemodified = mktime();
|
||||
$temp = explode(',', $scale->scale);
|
||||
$scale->max = count($temp) -1;
|
||||
|
||||
|
||||
if ($scale->id = insert_record('scale', $scale)) {
|
||||
$this->scale[0] = $scale;
|
||||
}
|
||||
}
|
||||
|
||||
$scale = new stdClass();
|
||||
|
||||
|
||||
$scale->name = 'unittestscale2';
|
||||
$scale->courseid = $this->courseid;
|
||||
$scale->userid = $this->userid;
|
||||
@@ -333,13 +333,13 @@ class grade_test extends UnitTestCase {
|
||||
$scale->timemodified = mktime();
|
||||
$temp = explode(',', $scale->scale);
|
||||
$scale->max = count($temp) -1;
|
||||
|
||||
|
||||
if ($scale->id = insert_record('scale', $scale)) {
|
||||
$this->scale[1] = $scale;
|
||||
}
|
||||
}
|
||||
|
||||
$scale = new stdClass();
|
||||
|
||||
|
||||
$scale->name = 'unittestscale3';
|
||||
$scale->courseid = $this->courseid;
|
||||
$scale->userid = $this->userid;
|
||||
@@ -348,10 +348,10 @@ class grade_test extends UnitTestCase {
|
||||
$scale->timemodified = mktime();
|
||||
$temp = explode(',', $scale->scale);
|
||||
$scale->max = count($temp) -1;
|
||||
|
||||
|
||||
if ($scale->id = insert_record('scale', $scale)) {
|
||||
$this->scale[2] = $scale;
|
||||
}
|
||||
}
|
||||
|
||||
$scale->name = 'unittestscale4';
|
||||
$scale->courseid = $this->courseid;
|
||||
@@ -361,7 +361,7 @@ class grade_test extends UnitTestCase {
|
||||
$scale->timemodified = mktime();
|
||||
$temp = explode(',', $scale->scale);
|
||||
$scale->max = count($temp) -1;
|
||||
|
||||
|
||||
if ($scale->id = insert_record('scale', $scale)) {
|
||||
$this->scale[3] = $scale;
|
||||
}
|
||||
@@ -374,7 +374,7 @@ class grade_test extends UnitTestCase {
|
||||
$scale->timemodified = mktime();
|
||||
$temp = explode(',', $scale->scale);
|
||||
$scale->max = count($temp) -1;
|
||||
|
||||
|
||||
if ($scale->id = insert_record('scale', $scale)) {
|
||||
$this->scale[4] = $scale;
|
||||
}
|
||||
@@ -385,7 +385,7 @@ class grade_test extends UnitTestCase {
|
||||
*/
|
||||
function load_grade_categories() {
|
||||
$grade_category = new stdClass();
|
||||
|
||||
|
||||
$grade_category->fullname = 'unittestcategory1';
|
||||
$grade_category->courseid = $this->courseid;
|
||||
$grade_category->aggregation = GRADE_AGGREGATE_MEAN_GRADED;
|
||||
@@ -395,13 +395,13 @@ class grade_test extends UnitTestCase {
|
||||
$grade_category->timecreated = mktime();
|
||||
$grade_category->timemodified = mktime();
|
||||
$grade_category->depth = 1;
|
||||
|
||||
|
||||
if ($grade_category->id = insert_record('grade_categories', $grade_category)) {
|
||||
$this->grade_categories[0] = $grade_category;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$grade_category = new stdClass();
|
||||
|
||||
|
||||
$grade_category->fullname = 'unittestcategory2';
|
||||
$grade_category->courseid = $this->courseid;
|
||||
$grade_category->aggregation = GRADE_AGGREGATE_MEAN_GRADED;
|
||||
@@ -412,13 +412,13 @@ class grade_test extends UnitTestCase {
|
||||
$grade_category->timecreated = mktime();
|
||||
$grade_category->timemodified = mktime();
|
||||
$grade_category->depth = 2;
|
||||
|
||||
|
||||
if ($grade_category->id = insert_record('grade_categories', $grade_category)) {
|
||||
$this->grade_categories[1] = $grade_category;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$grade_category = new stdClass();
|
||||
|
||||
|
||||
$grade_category->fullname = 'unittestcategory3';
|
||||
$grade_category->courseid = $this->courseid;
|
||||
$grade_category->aggregation = GRADE_AGGREGATE_MEAN_GRADED;
|
||||
@@ -429,15 +429,15 @@ class grade_test extends UnitTestCase {
|
||||
$grade_category->timecreated = mktime();
|
||||
$grade_category->timemodified = mktime();
|
||||
$grade_category->depth = 2;
|
||||
|
||||
|
||||
if ($grade_category->id = insert_record('grade_categories', $grade_category)) {
|
||||
$this->grade_categories[2] = $grade_category;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// A category with no parent, but grade_items as children
|
||||
|
||||
$grade_category = new stdClass();
|
||||
|
||||
|
||||
$grade_category->fullname = 'level1category';
|
||||
$grade_category->courseid = $this->courseid;
|
||||
$grade_category->aggregation = GRADE_AGGREGATE_MEAN_GRADED;
|
||||
@@ -447,10 +447,10 @@ class grade_test extends UnitTestCase {
|
||||
$grade_category->timecreated = mktime();
|
||||
$grade_category->timemodified = mktime();
|
||||
$grade_category->depth = 1;
|
||||
|
||||
|
||||
if ($grade_category->id = insert_record('grade_categories', $grade_category)) {
|
||||
$this->grade_categories[3] = $grade_category;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -479,7 +479,7 @@ class grade_test extends UnitTestCase {
|
||||
if ($grade_item->id = insert_record('grade_items', $grade_item)) {
|
||||
$this->grade_items[0] = $grade_item;
|
||||
}
|
||||
|
||||
|
||||
// id = 1
|
||||
$grade_item = new stdClass();
|
||||
|
||||
@@ -498,7 +498,7 @@ class grade_test extends UnitTestCase {
|
||||
$grade_item->timecreated = mktime();
|
||||
$grade_item->timemodified = mktime();
|
||||
$grade_item->sortorder = 4;
|
||||
|
||||
|
||||
if ($grade_item->id = insert_record('grade_items', $grade_item)) {
|
||||
$this->grade_items[1] = $grade_item;
|
||||
}
|
||||
@@ -545,7 +545,7 @@ class grade_test extends UnitTestCase {
|
||||
if ($grade_item->id = insert_record('grade_items', $grade_item)) {
|
||||
$this->grade_items[3] = $grade_item;
|
||||
}
|
||||
|
||||
|
||||
// id = 4
|
||||
$grade_item = new stdClass();
|
||||
|
||||
@@ -631,7 +631,7 @@ class grade_test extends UnitTestCase {
|
||||
if ($grade_item->id = insert_record('grade_items', $grade_item)) {
|
||||
$this->grade_items[7] = $grade_item;
|
||||
}
|
||||
|
||||
|
||||
// id = 8
|
||||
$grade_item = new stdClass();
|
||||
|
||||
@@ -652,7 +652,7 @@ class grade_test extends UnitTestCase {
|
||||
if ($grade_item->id = insert_record('grade_items', $grade_item)) {
|
||||
$this->grade_items[8] = $grade_item;
|
||||
}
|
||||
|
||||
|
||||
// Grade_item for level1category
|
||||
// id = 9
|
||||
$grade_item = new stdClass();
|
||||
@@ -693,7 +693,7 @@ class grade_test extends UnitTestCase {
|
||||
if ($grade->id = insert_record('grade_grades', $grade)) {
|
||||
$this->grade_grades[0] = $grade;
|
||||
}
|
||||
|
||||
|
||||
$grade = new stdClass();
|
||||
$grade->itemid = $this->grade_items[0]->id;
|
||||
$grade->userid = 2;
|
||||
@@ -705,7 +705,7 @@ class grade_test extends UnitTestCase {
|
||||
if ($grade->id = insert_record('grade_grades', $grade)) {
|
||||
$this->grade_grades[1] = $grade;
|
||||
}
|
||||
|
||||
|
||||
$grade = new stdClass();
|
||||
$grade->itemid = $this->grade_items[0]->id;
|
||||
$grade->userid = 3;
|
||||
@@ -730,8 +730,8 @@ class grade_test extends UnitTestCase {
|
||||
|
||||
if ($grade->id = insert_record('grade_grades', $grade)) {
|
||||
$this->grade_grades[3] = $grade;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$grade = new stdClass();
|
||||
$grade->itemid = $this->grade_items[1]->id;
|
||||
$grade->userid = 2;
|
||||
@@ -752,7 +752,7 @@ class grade_test extends UnitTestCase {
|
||||
|
||||
if ($grade->id = insert_record('grade_grades', $grade)) {
|
||||
$this->grade_grades[5] = $grade;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Grades for grade_item 3
|
||||
@@ -769,7 +769,7 @@ class grade_test extends UnitTestCase {
|
||||
if ($grade->id = insert_record('grade_grades', $grade)) {
|
||||
$this->grade_grades[6] = $grade;
|
||||
}
|
||||
|
||||
|
||||
$grade = new stdClass();
|
||||
$grade->itemid = $this->grade_items[2]->id;
|
||||
$grade->userid = 2;
|
||||
@@ -782,7 +782,7 @@ class grade_test extends UnitTestCase {
|
||||
if ($grade->id = insert_record('grade_grades', $grade)) {
|
||||
$this->grade_grades[] = $grade;
|
||||
}
|
||||
|
||||
|
||||
$grade = new stdClass();
|
||||
$grade->itemid = $this->grade_items[2]->id;
|
||||
$grade->userid = 3;
|
||||
@@ -795,7 +795,7 @@ class grade_test extends UnitTestCase {
|
||||
if ($grade->id = insert_record('grade_grades', $grade)) {
|
||||
$this->grade_grades[] = $grade;
|
||||
}
|
||||
|
||||
|
||||
// Grades for grade_item 7
|
||||
|
||||
$grade = new stdClass();
|
||||
@@ -809,7 +809,7 @@ class grade_test extends UnitTestCase {
|
||||
if ($grade->id = insert_record('grade_grades', $grade)) {
|
||||
$this->grade_grades[] = $grade;
|
||||
}
|
||||
|
||||
|
||||
$grade = new stdClass();
|
||||
$grade->itemid = $this->grade_items[6]->id;
|
||||
$grade->userid = 2;
|
||||
@@ -821,7 +821,7 @@ class grade_test extends UnitTestCase {
|
||||
if ($grade->id = insert_record('grade_grades', $grade)) {
|
||||
$this->grade_grades[] = $grade;
|
||||
}
|
||||
|
||||
|
||||
$grade = new stdClass();
|
||||
$grade->itemid = $this->grade_items[6]->id;
|
||||
$grade->userid = 3;
|
||||
@@ -847,7 +847,7 @@ class grade_test extends UnitTestCase {
|
||||
if ($grade->id = insert_record('grade_grades', $grade)) {
|
||||
$this->grade_grades[] = $grade;
|
||||
}
|
||||
|
||||
|
||||
$grade = new stdClass();
|
||||
$grade->itemid = $this->grade_items[7]->id;
|
||||
$grade->userid = 3;
|
||||
@@ -859,7 +859,7 @@ class grade_test extends UnitTestCase {
|
||||
if ($grade->id = insert_record('grade_grades', $grade)) {
|
||||
$this->grade_grades[] = $grade;
|
||||
}
|
||||
|
||||
|
||||
// Grades for grade_item 9
|
||||
|
||||
$grade = new stdClass();
|
||||
@@ -873,7 +873,7 @@ class grade_test extends UnitTestCase {
|
||||
if ($grade->id = insert_record('grade_grades', $grade)) {
|
||||
$this->grade_grades[] = $grade;
|
||||
}
|
||||
|
||||
|
||||
$grade = new stdClass();
|
||||
$grade->itemid = $this->grade_items[8]->id;
|
||||
$grade->userid = 2;
|
||||
@@ -885,7 +885,7 @@ class grade_test extends UnitTestCase {
|
||||
if ($grade->id = insert_record('grade_grades', $grade)) {
|
||||
$this->grade_grades[] = $grade;
|
||||
}
|
||||
|
||||
|
||||
$grade = new stdClass();
|
||||
$grade->itemid = $this->grade_items[7]->id;
|
||||
$grade->userid = 3;
|
||||
@@ -898,7 +898,7 @@ class grade_test extends UnitTestCase {
|
||||
$this->grade_grades[] = $grade;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load grade_grades_text data into the database, and adds the corresponding objects to this class' variable.
|
||||
*/
|
||||
@@ -911,12 +911,12 @@ class grade_test extends UnitTestCase {
|
||||
$grade_grades_text->informationformat = FORMAT_PLAIN;
|
||||
$grade_grades_text->feedback = 'Good, but not good enough..';
|
||||
$grade_grades_text->feedbackformat = FORMAT_PLAIN;
|
||||
|
||||
|
||||
if ($grade_grades_text->id = insert_record('grade_grades_text', $grade_grades_text)) {
|
||||
$this->grade_grades_text[] = $grade_grades_text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load grade_outcome data into the database, and adds the corresponding objects to this class' variable.
|
||||
*/
|
||||
@@ -928,11 +928,11 @@ class grade_test extends UnitTestCase {
|
||||
$grade_outcome->timecreated = mktime();
|
||||
$grade_outcome->timemodified = mktime();
|
||||
$grade_outcome->scaleid = $this->scale[2]->id;
|
||||
|
||||
|
||||
if ($grade_outcome->id = insert_record('grade_outcomes', $grade_outcome)) {
|
||||
$this->grade_outcomes[] = $grade_outcome;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Calculation for grade_item 2
|
||||
$grade_outcome = new stdClass();
|
||||
$grade_outcome->itemid = $this->grade_items[1]->id;
|
||||
@@ -940,11 +940,11 @@ class grade_test extends UnitTestCase {
|
||||
$grade_outcome->timecreated = mktime();
|
||||
$grade_outcome->timemodified = mktime();
|
||||
$grade_outcome->scaleid = $this->scale[3]->id;
|
||||
|
||||
|
||||
if ($grade_outcome->id = insert_record('grade_outcomes', $grade_outcome)) {
|
||||
$this->grade_outcomes[] = $grade_outcome;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Calculation for grade_item 3
|
||||
$grade_outcome = new stdClass();
|
||||
$grade_outcome->itemid = $this->grade_items[2]->id;
|
||||
@@ -952,10 +952,10 @@ class grade_test extends UnitTestCase {
|
||||
$grade_outcome->timecreated = mktime();
|
||||
$grade_outcome->timemodified = mktime();
|
||||
$grade_outcome->scaleid = $this->scale[4]->id;
|
||||
|
||||
|
||||
if ($grade_outcome->id = insert_record('grade_outcomes', $grade_outcome)) {
|
||||
$this->grade_outcomes[] = $grade_outcome;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -963,7 +963,7 @@ class grade_test extends UnitTestCase {
|
||||
*/
|
||||
function load_grade_history() {
|
||||
$grade_history = new stdClass();
|
||||
|
||||
|
||||
$grade_history->itemid = $this->grade_items[0]->id;
|
||||
$grade_history->userid = 1;
|
||||
$grade_history->oldgrade = 88;
|
||||
@@ -973,9 +973,9 @@ class grade_test extends UnitTestCase {
|
||||
|
||||
if ($grade_history->id = insert_record('grade_history', $grade_history)) {
|
||||
$this->grade_history[] = $grade_history;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
/**
|
||||
* No unit tests here
|
||||
*/
|
||||
|
||||
|
||||
@@ -59,24 +59,24 @@ class grade_category_test extends grade_test {
|
||||
$params->fullname = 'unittestcategory5';
|
||||
$grade_category = new grade_category($params, false);
|
||||
$grade_category->insert();
|
||||
|
||||
|
||||
$this->assertEqual(2, $grade_category->depth);
|
||||
$this->assertEqual("$parentpath/$grade_category->id", $grade_category->path);
|
||||
$this->assertEqual("$parentpath/$grade_category->id", $grade_category->path);
|
||||
$parentpath = $grade_category->path;
|
||||
|
||||
|
||||
// Test a third depth category
|
||||
$params->parent = $grade_category->id;
|
||||
$params->fullname = 'unittestcategory6';
|
||||
$grade_category = new grade_category($params, false);
|
||||
$grade_category->insert();
|
||||
$this->assertEqual(3, $grade_category->depth);
|
||||
$this->assertEqual("$parentpath/$grade_category->id", $grade_category->path);
|
||||
$this->assertEqual("$parentpath/$grade_category->id", $grade_category->path);
|
||||
}
|
||||
|
||||
function test_grade_category_insert() {
|
||||
$grade_category = new grade_category();
|
||||
$this->assertTrue(method_exists($grade_category, 'insert'));
|
||||
|
||||
|
||||
$grade_category->fullname = 'unittestcategory4';
|
||||
$grade_category->courseid = $this->courseid;
|
||||
$grade_category->aggregation = GRADE_AGGREGATE_MEAN_GRADED;
|
||||
@@ -86,9 +86,9 @@ class grade_category_test extends grade_test {
|
||||
$grade_category->parent = $this->grade_categories[0]->id;
|
||||
|
||||
$grade_category->insert();
|
||||
|
||||
|
||||
$last_grade_category = end($this->grade_categories);
|
||||
|
||||
|
||||
$this->assertFalse(empty($grade_category->grade_item));
|
||||
$this->assertEqual($grade_category->id, $grade_category->grade_item->iteminstance);
|
||||
$this->assertEqual('category', $grade_category->grade_item->itemtype);
|
||||
@@ -101,30 +101,30 @@ class grade_category_test extends grade_test {
|
||||
function test_grade_category_update() {
|
||||
$grade_category = new grade_category($this->grade_categories[0]);
|
||||
$this->assertTrue(method_exists($grade_category, 'update'));
|
||||
|
||||
|
||||
$grade_category->fullname = 'Updated info for this unittest grade_category';
|
||||
$this->assertTrue($grade_category->update());
|
||||
$fullname = get_field('grade_categories', 'fullname', 'id', $this->grade_categories[0]->id);
|
||||
$this->assertEqual($grade_category->fullname, $fullname);
|
||||
$this->assertEqual($grade_category->fullname, $fullname);
|
||||
|
||||
}
|
||||
|
||||
function test_grade_category_delete() {
|
||||
$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(get_record('grade_categories', 'id', $grade_category->id));
|
||||
}
|
||||
|
||||
function test_grade_category_fetch() {
|
||||
$grade_category = new grade_category();
|
||||
$grade_category = new grade_category();
|
||||
$this->assertTrue(method_exists($grade_category, 'fetch'));
|
||||
|
||||
$grade_category = grade_category::fetch('id', $this->grade_categories[0]->id);
|
||||
$this->assertEqual($this->grade_categories[0]->id, $grade_category->id);
|
||||
$this->assertEqual($this->grade_categories[0]->fullname, $grade_category->fullname);
|
||||
}
|
||||
$this->assertEqual($this->grade_categories[0]->fullname, $grade_category->fullname);
|
||||
}
|
||||
|
||||
function test_grade_category_get_children() {
|
||||
$category = new grade_category($this->grade_categories[0]);
|
||||
@@ -143,7 +143,7 @@ class grade_category_test extends grade_test {
|
||||
|
||||
$children_array = $category->get_children(0, 'flat');
|
||||
$this->assertEqual(5, count($children_array));
|
||||
|
||||
|
||||
$children_array = $category->get_children(1, 'flat');
|
||||
$this->assertEqual(2, count($children_array));
|
||||
}
|
||||
@@ -154,17 +154,17 @@ class grade_category_test extends grade_test {
|
||||
$this->assertTrue(is_array($children_array));
|
||||
$this->assertTrue(isset($children_array[3]));
|
||||
$this->assertTrue(isset($children_array[3]['object']));
|
||||
$this->assertEqual($this->grade_items[0]->id, $children_array[3]['object']->id);
|
||||
$this->assertEqual($this->grade_items[0]->id, $children_array[3]['object']->id);
|
||||
}
|
||||
|
||||
|
||||
function test_grade_category_has_children() {
|
||||
$category = new grade_category($this->grade_categories[0]);
|
||||
$this->assertTrue(method_exists($category, 'has_children'));
|
||||
$this->assertTrue(method_exists($category, 'has_children'));
|
||||
$this->assertTrue($category->has_children());
|
||||
$category = new grade_category();
|
||||
$this->assertFalse($category->has_children());
|
||||
$this->assertFalse($category->has_children());
|
||||
}
|
||||
|
||||
|
||||
function test_grade_category_generate_grades() {
|
||||
$category = new grade_category($this->grade_categories[3]);
|
||||
$this->assertTrue(method_exists($category, 'generate_grades'));
|
||||
@@ -186,13 +186,13 @@ class grade_category_test extends grade_test {
|
||||
// calculated mean results
|
||||
$this->assertEqual($rawvalues, array(20,50,100));
|
||||
}
|
||||
|
||||
|
||||
function test_grade_category_aggregate_grades() {
|
||||
$category = new grade_category($this->grade_categories[0]);
|
||||
$this->assertTrue(method_exists($category, 'aggregate_grades'));
|
||||
$this->assertTrue(method_exists($category, 'aggregate_grades'));
|
||||
// tested above in test_grade_category_generate_grades()
|
||||
}
|
||||
|
||||
|
||||
function generate_random_raw_grade($item, $userid) {
|
||||
$grade = new grade_grades();
|
||||
$grade->itemid = $item->id;
|
||||
@@ -203,7 +203,7 @@ class grade_category_test extends grade_test {
|
||||
$grade->rawgrade = rand(0, 1000) / 1000;
|
||||
$grade->insert();
|
||||
return $grade->rawgrade;
|
||||
}
|
||||
}
|
||||
|
||||
function test_grade_category_set_as_parent() {
|
||||
global $CFG;
|
||||
@@ -256,7 +256,7 @@ class grade_category_test extends grade_test {
|
||||
function test_grade_category_apply_limit_rules() {
|
||||
$category = new grade_category();
|
||||
$grades = array(5.374, 9.4743, 2.5474, 7.3754);
|
||||
|
||||
|
||||
$category->droplow = 2;
|
||||
$category->apply_limit_rules($grades);
|
||||
sort($grades, SORT_NUMERIC);
|
||||
@@ -268,7 +268,7 @@ class grade_category_test extends grade_test {
|
||||
$category->keephigh = 1;
|
||||
$category->droplow = 0;
|
||||
$category->apply_limit_rules($grades);
|
||||
$this->assertEqual(array(9.4743), $grades);
|
||||
$this->assertEqual(array(9.4743), $grades);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -53,18 +53,18 @@ class grade_history_test extends grade_test {
|
||||
$this->assertEqual($params->itemid, $grade_history->itemid);
|
||||
$this->assertEqual($params->note, $grade_history->note);
|
||||
}
|
||||
|
||||
|
||||
function test_grade_history_insert() {
|
||||
$grade_history = new grade_history();
|
||||
$this->assertTrue(method_exists($grade_history, 'insert'));
|
||||
|
||||
|
||||
$grade_history->itemid = $this->grade_items[0]->id;
|
||||
$grade_history->userid = 1;
|
||||
$grade_history->oldgrade = 88;
|
||||
$grade_history->newgrade = 90;
|
||||
$grade_history->note = 'Modified manually in testgradehistory.php';
|
||||
$grade_history->howmodified = 'manual';
|
||||
|
||||
|
||||
$grade_history->insert();
|
||||
|
||||
$last_grade_history = end($this->grade_history);
|
||||
@@ -77,27 +77,27 @@ class grade_history_test extends grade_test {
|
||||
function test_grade_history_update() {
|
||||
$grade_history = new grade_history($this->grade_history[0]);
|
||||
$this->assertTrue(method_exists($grade_history, 'update'));
|
||||
$grade_history->note = 'Modified manually in testgradehistory.php';
|
||||
$grade_history->note = 'Modified manually in testgradehistory.php';
|
||||
$this->assertTrue($grade_history->update());
|
||||
$note = get_field('grade_history', 'note', 'id', $this->grade_history[0]->id);
|
||||
$this->assertEqual($grade_history->note, $note);
|
||||
$this->assertEqual($grade_history->note, $note);
|
||||
}
|
||||
|
||||
function test_grade_history_delete() {
|
||||
$grade_history = new grade_history($this->grade_history[0]);
|
||||
$this->assertTrue(method_exists($grade_history, 'delete'));
|
||||
|
||||
|
||||
$this->assertTrue($grade_history->delete());
|
||||
$this->assertFalse(get_record('grade_history', 'id', $grade_history->id));
|
||||
$this->assertFalse(get_record('grade_history', 'id', $grade_history->id));
|
||||
}
|
||||
|
||||
function test_grade_history_fetch() {
|
||||
$grade_history = new grade_history();
|
||||
$grade_history = new grade_history();
|
||||
$this->assertTrue(method_exists($grade_history, 'fetch'));
|
||||
|
||||
$grade_history = grade_history::fetch('id', $this->grade_history[0]->id);
|
||||
$this->assertEqual($this->grade_history[0]->id, $grade_history->id);
|
||||
$this->assertEqual($this->grade_history[0]->note, $grade_history->note);
|
||||
}
|
||||
}
|
||||
$this->assertEqual($this->grade_history[0]->note, $grade_history->note);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -53,7 +53,7 @@ class grade_outcome_test extends grade_test {
|
||||
function test_grade_outcome_insert() {
|
||||
$grade_outcome = new grade_outcome();
|
||||
$this->assertTrue(method_exists($grade_outcome, 'insert'));
|
||||
|
||||
|
||||
$grade_outcome->courseid = $this->courseid;
|
||||
$grade_outcome->shortname = 'Team work';
|
||||
|
||||
@@ -69,27 +69,27 @@ class grade_outcome_test extends grade_test {
|
||||
function test_grade_outcome_update() {
|
||||
$grade_outcome = new grade_outcome($this->grade_outcomes[0]);
|
||||
$this->assertTrue(method_exists($grade_outcome, 'update'));
|
||||
$grade_outcome->shortname = 'Team work';
|
||||
$grade_outcome->shortname = 'Team work';
|
||||
$this->assertTrue($grade_outcome->update());
|
||||
$shortname = get_field('grade_outcomes', 'shortname', 'id', $this->grade_outcomes[0]->id);
|
||||
$this->assertEqual($grade_outcome->shortname, $shortname);
|
||||
$this->assertEqual($grade_outcome->shortname, $shortname);
|
||||
}
|
||||
|
||||
function test_grade_outcome_delete() {
|
||||
$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(get_record('grade_outcomes', 'id', $grade_outcome->id));
|
||||
}
|
||||
|
||||
function test_grade_outcome_fetch() {
|
||||
$grade_outcome = new grade_outcome();
|
||||
$grade_outcome = new grade_outcome();
|
||||
$this->assertTrue(method_exists($grade_outcome, 'fetch'));
|
||||
|
||||
$grade_outcome = grade_outcome::fetch('id', $this->grade_outcomes[0]->id);
|
||||
$this->assertEqual($this->grade_outcomes[0]->id, $grade_outcome->id);
|
||||
$this->assertEqual($this->grade_outcomes[0]->shortname, $grade_outcome->shortname);
|
||||
}
|
||||
}
|
||||
$this->assertEqual($this->grade_outcomes[0]->shortname, $grade_outcome->shortname);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -41,14 +41,14 @@ class grade_scale_test extends grade_test {
|
||||
|
||||
function test_scale_construct() {
|
||||
$params = new stdClass();
|
||||
|
||||
|
||||
$params->name = 'unittestscale3';
|
||||
$params->courseid = $this->courseid;
|
||||
$params->userid = $this->userid;
|
||||
$params->scale = 'Distinction, Very Good, Good, Pass, Fail';
|
||||
$params->description = 'This scale is used to mark standard assignments.';
|
||||
$params->timemodified = mktime();
|
||||
|
||||
|
||||
$scale = new grade_scale($params, false);
|
||||
|
||||
$this->assertEqual($params->name, $scale->name);
|
||||
@@ -56,11 +56,11 @@ class grade_scale_test extends grade_test {
|
||||
$this->assertEqual($params->description, $scale->description);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_grade_scale_insert() {
|
||||
$grade_scale = new grade_scale();
|
||||
$this->assertTrue(method_exists($grade_scale, 'insert'));
|
||||
|
||||
|
||||
$grade_scale->name = 'unittestscale3';
|
||||
$grade_scale->courseid = $this->courseid;
|
||||
$grade_scale->userid = $this->userid;
|
||||
@@ -79,30 +79,30 @@ class grade_scale_test extends grade_test {
|
||||
function test_grade_scale_update() {
|
||||
$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);
|
||||
$this->assertEqual($grade_scale->name, $name);
|
||||
$this->assertEqual($grade_scale->name, $name);
|
||||
}
|
||||
|
||||
function test_grade_scale_delete() {
|
||||
$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(get_record('scale', 'id', $grade_scale->id));
|
||||
}
|
||||
|
||||
function test_grade_scale_fetch() {
|
||||
$grade_scale = new grade_scale();
|
||||
$grade_scale = new grade_scale();
|
||||
$this->assertTrue(method_exists($grade_scale, 'fetch'));
|
||||
|
||||
$grade_scale = grade_scale::fetch('id', $this->scale[0]->id);
|
||||
$this->assertEqual($this->scale[0]->id, $grade_scale->id);
|
||||
$this->assertEqual($this->scale[0]->name, $grade_scale->name);
|
||||
}
|
||||
|
||||
$this->assertEqual($this->scale[0]->name, $grade_scale->name);
|
||||
}
|
||||
|
||||
function test_scale_load_items() {
|
||||
$scale = new grade_scale($this->scale[0]);
|
||||
$this->assertTrue(method_exists($scale, 'load_items'));
|
||||
@@ -119,10 +119,10 @@ class grade_scale_test extends grade_test {
|
||||
$scale->load_items();
|
||||
$scale->scale = null;
|
||||
$scale->compact_items();
|
||||
|
||||
// The original string and the new string may have differences in whitespace around the delimiter, and that's OK
|
||||
|
||||
// The original string and the new string may have differences in whitespace around the delimiter, and that's OK
|
||||
$this->assertEqual(preg_replace('/\s*,\s*/', ',', $this->scale[0]->scale), $scale->scale);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -61,7 +61,7 @@ class grade_text_test extends grade_test {
|
||||
function test_grade_grades_text_insert() {
|
||||
$grade_grades_text = new grade_grades_text();
|
||||
$this->assertTrue(method_exists($grade_grades_text, 'insert'));
|
||||
|
||||
|
||||
$grade_grades_text->itemid = $this->grade_grades[0]->itemid;
|
||||
$grade_grades_text->userid = $this->grade_grades[0]->userid;
|
||||
$grade_grades_text->information = 'Thumbs down';
|
||||
@@ -74,7 +74,7 @@ class grade_text_test extends grade_test {
|
||||
$last_grade_grades_text = end($this->grade_grades_text);
|
||||
|
||||
global $USER;
|
||||
|
||||
|
||||
$this->assertEqual($grade_grades_text->id, $last_grade_grades_text->id + 1);
|
||||
$this->assertFalse(empty($grade_grades_text->timecreated));
|
||||
$this->assertFalse(empty($grade_grades_text->timemodified));
|
||||
@@ -84,28 +84,28 @@ class grade_text_test extends grade_test {
|
||||
function test_grade_grades_text_update() {
|
||||
$grade_grades_text = new grade_grades_text($this->grade_grades_text[0]);
|
||||
$this->assertTrue(method_exists($grade_grades_text, 'update'));
|
||||
|
||||
|
||||
$this->assertTrue($grade_grades_text->update(89));
|
||||
$information = get_field('grade_grades_text', 'information', 'id', $this->grade_grades_text[0]->id);
|
||||
$this->assertEqual($grade_grades_text->information, $information);
|
||||
$this->assertEqual($grade_grades_text->information, $information);
|
||||
}
|
||||
|
||||
function test_grade_grades_text_delete() {
|
||||
$grade_grades_text = new grade_grades_text($this->grade_grades_text[0]);
|
||||
$this->assertTrue(method_exists($grade_grades_text, 'delete'));
|
||||
|
||||
|
||||
$this->assertTrue($grade_grades_text->delete());
|
||||
$this->assertFalse(get_record('grade_grades_text', 'id', $grade_grades_text->id));
|
||||
$this->assertFalse(get_record('grade_grades_text', 'id', $grade_grades_text->id));
|
||||
}
|
||||
|
||||
function test_grade_grades_text_fetch() {
|
||||
$grade_grades_text = new grade_grades_text();
|
||||
$grade_grades_text = new grade_grades_text();
|
||||
$this->assertTrue(method_exists($grade_grades_text, 'fetch'));
|
||||
|
||||
$grade_grades_text = grade_grades_text::fetch('id', $this->grade_grades_text[0]->id);
|
||||
$this->assertEqual($this->grade_grades_text[0]->id, $grade_grades_text->id);
|
||||
$this->assertEqual($this->grade_grades_text[0]->information, $grade_grades_text->information);
|
||||
}
|
||||
$this->assertEqual($this->grade_grades_text[0]->information, $grade_grades_text->information);
|
||||
}
|
||||
|
||||
function test_grade_grades_text_load_grade_item() {
|
||||
$grade_grades_text = new grade_grades_text($this->grade_grades_text[0]);
|
||||
@@ -116,5 +116,5 @@ class grade_text_test extends grade_test {
|
||||
$this->assertNotNull($grade_grades_text->grade_item);
|
||||
$this->assertEqual($this->grade_items[0]->id, $grade_grades_text->grade_item->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -38,20 +38,20 @@ if (!defined('MOODLE_INTERNAL')) {
|
||||
require_once($CFG->libdir.'/simpletest/fixtures/gradetest.php');
|
||||
|
||||
class grade_tree_test extends grade_test {
|
||||
|
||||
|
||||
function test_grade_tree_move_element() {
|
||||
/* 0.
|
||||
* Starting layout:
|
||||
/* 0.
|
||||
* Starting layout:
|
||||
*__________________
|
||||
*|_________1_______| ____________
|
||||
*|_________1_______| ____________
|
||||
*|_____2_____|__5__|_____|_____8____|
|
||||
*|__3__|__4__|__6__|__7__|__9__|_10_|
|
||||
*/
|
||||
$tree = new grade_tree($this->courseid);
|
||||
/* 1.
|
||||
* Desired result:
|
||||
/* 1.
|
||||
* Desired result:
|
||||
*_____________
|
||||
*|_____1_____| _________________
|
||||
*|_____1_____| _________________
|
||||
*|__2__|__4__|_____|________7_______|
|
||||
*|__3__|__5__|__6__|__8__|__9__|_10_|
|
||||
*/
|
||||
@@ -65,7 +65,7 @@ class grade_tree_test extends grade_test {
|
||||
$this->assertEqual(6, count($tree->need_update));
|
||||
$this->assertEqual(1, count($tree->need_delete));
|
||||
$this->assertEqual(1, count($tree->need_insert));
|
||||
|
||||
|
||||
// Check sortorders
|
||||
$this->assertEqual(1, $tree->tree_array[1]['object']->sortorder);
|
||||
$this->assertEqual(2, $tree->tree_array[1]['children'][2]['object']->sortorder);
|
||||
@@ -82,10 +82,10 @@ class grade_tree_test extends grade_test {
|
||||
$this->assertEqual('unittestgradeitem3', $tree->tree_array[1]['children'][4]['children'][5]['object']->itemname);
|
||||
$tree->need_update = array();
|
||||
|
||||
/* 2.
|
||||
* Desired result:
|
||||
/* 2.
|
||||
* Desired result:
|
||||
*___________________
|
||||
*|________1________|_________________
|
||||
*|________1________|_________________
|
||||
*|_____2_____|__5__|________7_______|
|
||||
*|__3__|__4__|__6__|__8__|__9__|_10_|
|
||||
*/
|
||||
@@ -105,12 +105,12 @@ class grade_tree_test extends grade_test {
|
||||
$this->assertEqual(8, $tree->tree_array[7]['children'][8]['object']->sortorder);
|
||||
$this->assertEqual(9, $tree->tree_array[7]['children'][9]['object']->sortorder);
|
||||
$this->assertEqual(10, $tree->tree_array[7]['children'][10]['object']->sortorder);
|
||||
|
||||
|
||||
// Try moving a subcategory
|
||||
/* 3.
|
||||
* Desired result:
|
||||
/* 3.
|
||||
* Desired result:
|
||||
*___________________
|
||||
*|________1________|_________________
|
||||
*|________1________|_________________
|
||||
*|__2__|_____4_____|________7_______|
|
||||
*|__3__|__5__|__6__|__8__|__9__|_10_|
|
||||
*/
|
||||
@@ -118,7 +118,7 @@ class grade_tree_test extends grade_test {
|
||||
$tree->renumber();
|
||||
$this->assertEqual(5, count($tree->need_update));
|
||||
$tree->need_update = array();
|
||||
|
||||
|
||||
// Check sortorders
|
||||
$this->assertEqual(1, $tree->tree_array[1]['object']->sortorder);
|
||||
$this->assertEqual(2, $tree->tree_array[1]['children'][2]['object']->sortorder);
|
||||
@@ -131,16 +131,16 @@ class grade_tree_test extends grade_test {
|
||||
$this->assertEqual(9, $tree->tree_array[7]['children'][9]['object']->sortorder);
|
||||
$this->assertEqual(10, $tree->tree_array[7]['children'][10]['object']->sortorder);
|
||||
|
||||
/* 4.
|
||||
* Desired result:
|
||||
/* 4.
|
||||
* Desired result:
|
||||
*_________________________
|
||||
*|___________1___________|____________
|
||||
*|___________1___________|____________
|
||||
*|__2__|________4________|_____8_____|
|
||||
*|__3__|__5__|__6__|__7__|__9__|_10__|
|
||||
*/
|
||||
$tree->move_element(8, 6);
|
||||
$tree->renumber();
|
||||
$this->assertEqual(3, count($tree->need_update));
|
||||
$this->assertEqual(3, count($tree->need_update));
|
||||
$tree->need_update = array();
|
||||
|
||||
// Check sortorders
|
||||
@@ -154,12 +154,12 @@ class grade_tree_test extends grade_test {
|
||||
$this->assertEqual(8, $tree->tree_array[8]['object']->sortorder);
|
||||
$this->assertEqual(9, $tree->tree_array[8]['children'][9]['object']->sortorder);
|
||||
$this->assertEqual(10, $tree->tree_array[8]['children'][10]['object']->sortorder);
|
||||
|
||||
|
||||
// Try moving a top category
|
||||
/* 5.
|
||||
* Desired result:
|
||||
/* 5.
|
||||
* Desired result:
|
||||
* ___________________
|
||||
* |_________2_______|___________
|
||||
* |_________2_______|___________
|
||||
*______|_____3_____|__6__|_____8____|
|
||||
*|__1__|__4__|__5__|__7__|__9__|_10_|
|
||||
*/
|
||||
@@ -167,7 +167,7 @@ class grade_tree_test extends grade_test {
|
||||
$tree->move_element(1, 8);
|
||||
$tree->renumber();
|
||||
$this->assertEqual(7, count($tree->need_update));
|
||||
|
||||
|
||||
// Check sortorders
|
||||
$this->assertEqual(1, $tree->tree_array[1]['object']->sortorder);
|
||||
$this->assertEqual(2, $tree->tree_array[2]['object']->sortorder);
|
||||
@@ -180,32 +180,32 @@ class grade_tree_test extends grade_test {
|
||||
$this->assertEqual(9, $tree->tree_array[8]['children'][9]['object']->sortorder);
|
||||
$this->assertEqual(10, $tree->tree_array[8]['children'][10]['object']->sortorder);
|
||||
}
|
||||
|
||||
|
||||
function test_grade_tree_get_neighbour_sortorder() {
|
||||
$tree = new grade_tree($this->courseid);
|
||||
|
||||
$element = $tree->locate_element(4);
|
||||
$this->assertEqual(3, $tree->get_neighbour_sortorder($element, 'previous'));
|
||||
$this->assertNull($tree->get_neighbour_sortorder($element, 'next'));
|
||||
|
||||
|
||||
$element = $tree->locate_element(3);
|
||||
$this->assertEqual(4, $tree->get_neighbour_sortorder($element, 'next'));
|
||||
$this->assertNull($tree->get_neighbour_sortorder($element, 'previous'));
|
||||
|
||||
|
||||
$element = $tree->locate_element(1);
|
||||
$this->assertNull($tree->get_neighbour_sortorder($element, 'previous'));
|
||||
$this->assertEqual(7, $tree->get_neighbour_sortorder($element, 'next'));
|
||||
|
||||
|
||||
$element = $tree->locate_element(7);
|
||||
$this->assertEqual(1, $tree->get_neighbour_sortorder($element, 'previous'));
|
||||
$this->assertEqual(8, $tree->get_neighbour_sortorder($element, 'next'));
|
||||
|
||||
|
||||
$element = $tree->locate_element(8);
|
||||
$this->assertEqual(7, $tree->get_neighbour_sortorder($element, 'previous'));
|
||||
$this->assertNull($tree->get_neighbour_sortorder($element, 'next'));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// TODO write more thorough and useful tests here. The renumber method assigns previous_sortorder and next_sortorder variables
|
||||
function test_grade_tree_renumber() {
|
||||
$tree = new grade_tree($this->courseid);
|
||||
@@ -213,7 +213,7 @@ class grade_tree_test extends grade_test {
|
||||
|
||||
$this->assertTrue(empty($tree->need_update));
|
||||
}
|
||||
|
||||
|
||||
function test_grade_tree_locate_element() {
|
||||
$tree = new grade_tree($this->courseid);
|
||||
$element = $tree->locate_element(5);
|
||||
@@ -226,14 +226,14 @@ class grade_tree_test extends grade_test {
|
||||
$element = $tree->locate_element(9);
|
||||
$this->assertEqual('8/9', $element->index);
|
||||
$this->assertNotNull($element->element);
|
||||
$this->assertEqual('singleparentitem1', $element->element['object']->itemname);
|
||||
$this->assertEqual('singleparentitem1', $element->element['object']->itemname);
|
||||
}
|
||||
|
||||
|
||||
function test_grade_tree_insert_grade_subcategory() {
|
||||
$tree = new grade_tree($this->courseid);
|
||||
$grade_category = new grade_category($this->grade_categories[3]);
|
||||
$element = array('object' => $grade_category);
|
||||
|
||||
|
||||
$tree->insert_element($element, 5);
|
||||
$this->assertFalse(empty($tree->tree_array[1]['children'][1]['object']->fullname));
|
||||
$this->assertEqual($this->grade_categories[3]->fullname, $tree->tree_array[1]['children'][1]['object']->fullname);
|
||||
@@ -245,7 +245,7 @@ class grade_tree_test extends grade_test {
|
||||
$tree = new grade_tree($this->courseid);
|
||||
$grade_category = new grade_category($this->grade_categories[0]);
|
||||
$element = array('object' => $grade_category);
|
||||
|
||||
|
||||
$tree->insert_element($element, 8);
|
||||
|
||||
$this->assertFalse(empty($tree->tree_array[2]['object']->fullname));
|
||||
@@ -253,7 +253,7 @@ class grade_tree_test extends grade_test {
|
||||
$this->assertFalse(empty($tree->tree_array[2]['children'][2]['object']->fullname));
|
||||
$this->assertEqual($this->grade_categories[1]->fullname, $tree->tree_array[2]['children'][2]['object']->fullname);
|
||||
}
|
||||
|
||||
|
||||
function test_grade_tree_insert_grade_item() {
|
||||
$tree = new grade_tree($this->courseid, true);
|
||||
$grade_item = new grade_item($this->grade_items[2]);
|
||||
@@ -263,7 +263,7 @@ class grade_tree_test extends grade_test {
|
||||
$this->assertEqual($this->grade_items[2]->itemname, $tree->tree_array[1]['children'][2]['children'][1]['object']->itemname);
|
||||
$this->assertFalse(empty($tree->tree_array[1]['children'][2]['children'][1]['final_grades'][1]));
|
||||
$this->assertEqual($this->grade_grades[6]->finalgrade, $tree->tree_array[1]['children'][2]['children'][1]['final_grades'][1]->finalgrade);
|
||||
|
||||
|
||||
// Check the need_insert array
|
||||
$this->assertEqual(1, count($tree->need_insert));
|
||||
}
|
||||
@@ -287,7 +287,7 @@ class grade_tree_test extends grade_test {
|
||||
$tree = new grade_tree($this->courseid, true);
|
||||
$this->assertEqual(47, count($tree->tree_array, COUNT_RECURSIVE));
|
||||
}
|
||||
|
||||
|
||||
function test_grade_tree_remove_element() {
|
||||
$tree = new grade_tree($this->courseid);
|
||||
|
||||
@@ -300,7 +300,7 @@ class grade_tree_test extends grade_test {
|
||||
$this->assertFalse(empty($tree->tree_array[7]));
|
||||
$this->assertFalse(empty($tree->tree_array[1]));
|
||||
$this->assertTrue(empty($tree->tree_array[8]));
|
||||
|
||||
|
||||
// Removing a grade_item with only 1 parent
|
||||
$tree->remove_element(8);
|
||||
$this->assertTrue(empty($tree->tree_array[7]['children'][8]));
|
||||
@@ -312,7 +312,7 @@ class grade_tree_test extends grade_test {
|
||||
// Now remove this sub-category (the one without a topcat)
|
||||
$tree->remove_element(7);
|
||||
$this->assertTrue(empty($tree->tree_array[7]));
|
||||
|
||||
|
||||
// At this point we're left with a topcat, 2 subcats and 3 items, so try removing an item first
|
||||
$tree->remove_element(4);
|
||||
$this->assertTrue(empty($tree->tree_array[1]['children'][2]['children'][4]));
|
||||
@@ -324,10 +324,10 @@ class grade_tree_test extends grade_test {
|
||||
$tree->remove_element(4);
|
||||
$this->assertTrue(empty($tree->tree_array[1]['children'][4]));
|
||||
$tree->renumber();
|
||||
$this->assertTrue(empty($tree->tree_array[1]['children'][4]));
|
||||
|
||||
$this->assertTrue(empty($tree->tree_array[1]['children'][4]));
|
||||
|
||||
$this->assertEqual(9, count($tree->tree_array, COUNT_RECURSIVE));
|
||||
|
||||
|
||||
// Check the need_delete array
|
||||
$this->assertEqual(5, count($tree->need_delete));
|
||||
}
|
||||
@@ -338,7 +338,7 @@ class grade_tree_test extends grade_test {
|
||||
$this->assertEqual('filler', $filler['object']);
|
||||
$this->assertEqual('filler', $filler['children'][0]['object']);
|
||||
$this->assertEqual($this->grade_items[6]->itemname, $filler['children'][0]['children'][0]['object']->itemname);
|
||||
}
|
||||
}
|
||||
|
||||
function test_grade_tree_build_tree_filled() {
|
||||
$tree = new grade_tree($this->courseid);
|
||||
@@ -358,19 +358,19 @@ class grade_tree_test extends grade_test {
|
||||
$tree->update_db();
|
||||
$item = grade_item::fetch('id', $this->grade_items[6]->id);
|
||||
$this->assertTrue(empty($item->id));
|
||||
|
||||
|
||||
$tree->move_element(4, 9);
|
||||
$tree->renumber();
|
||||
$tree->update_db();
|
||||
$item = grade_item::fetch('id', $this->grade_items[1]->id);
|
||||
$this->assertFalse(empty($item->id));
|
||||
$this->assertEqual(8, $item->sortorder);
|
||||
|
||||
|
||||
$grade_item = new grade_item($this->grade_items[2]);
|
||||
$element = array('object' => $grade_item);
|
||||
$tree->insert_element($element, 9);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function test_grade_tree_load_without_finals() {
|
||||
$tree = new grade_tree($this->courseid);
|
||||
|
||||
Reference in New Issue
Block a user