* @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.
*
global $USER;
$this->timemodified = time();
-
+
if (empty($this->usermodified)) {
$this->usermodified = $USER->id;
}
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
}
$this->timecreated = $this->timemodified = time();
-
+
if (empty($this->usermodified)) {
$this->usermodified = $USER->id;
}
unset($clonethis->$var);
}
}
-
+
if (!$this->id = insert_record($this->table, addslashes_recursive($clonethis), true)) {
debugging("Could not insert object into db");
return false;
return true;
}
-
+
/**
* Uses the variables of this object to retrieve all matching objects from the DB.
* @return array $objects
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();
return $objects;
}
}
-
+
/**
* Given an associated array or object, cycles through each key/variable
if (in_object_vars($param, $this)) {
$this->$param = $value;
}
- }
+ }
}
}
* @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
* @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.
$this->scale->load_items();
}
}
-
+
/**
* Finds and returns a grade_outcome object based on 1-3 field values.
* @static
* @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;
}
/**
- * 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;
- }
+ }
}
?>
* @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
* @var string $description
*/
var $description;
-
+
/**
* Finds and returns a grade_scale object based on 1-3 field values.
* @static
* @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;
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.
} else {
$this->scale_items = explode(',', $items);
}
-
+
// Trim whitespace around each value
foreach ($this->scale_items as $key => $val) {
$this->scale_items[$key] = trim($val);
$this->scale = $items;
}
- return $this->scale;
- }
+ return $this->scale;
+ }
}
?>
* 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.
* @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
* @var array $need_update
*/
var $need_update = array();
-
+
/**
* An array of objects that need inserting in the DB.
* @var array $need_insert
/**
* A string of GET URL variables, namely courseid and sesskey, used in most URLs built by this class.
* @var string $commonvars
- */
+ */
var $commonvars;
/**
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)) {
} else {
$this->tree_array = $this->get_tree();
}
-
+
if (!empty($this->tree_array)) {
$this->first_sortorder = key($this->tree_array);
$this->renumber();
}
/**
- * 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
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++;
$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
*/
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;
} 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;
/**
* 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] . ']';
}
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.
* @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') {
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();
// 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)) {
}
$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);
$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;
}
*/
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.");
$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;
}
/**
- * 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.
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')) {
}
- /**
- * 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
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;
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'])) {
if ($result) {
break;
}
- }
+ }
$count++;
}
}
/**
- * 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
*/
// 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) {
$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) {
}
$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;
if (!empty($level1['finalgrades'])) {
foreach ($level1['finalgrades'] as $final_grade) {
$this->grades[$final_grade->userid][$final_grade->itemid] = $final_grade->finalgrade;
- }
+ }
}
}
}
/**
- * 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.
$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);
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();
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;
}
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) {
$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;
/**
* 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...
}
}
- $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();
}
}
}
-
- $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)
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>';
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 {
}
}
-
+
$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
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') {
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])) {
$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";
$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;
}
$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';
$object_name = '<span class="dimmed_text">' . $object_name . '</span>';
$hide_show = 'show';
}
-
+
// Prepare lock/unlock string
$lock_unlock = 'lock';
if ($object->is_locked()) {
$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";
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']);
$rawgrade = false;
$feedback = false;
$feedbackformat = FORMAT_MOODLE;
-
+
if (array_key_exists('rawgrade', $grade)) {
$rawgrade = $grade['rawgrade'];
}
$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
//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];
* 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',
/**
* 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() {
if (!$this->create_test_tables()) {
die("Could not create all the test tables!");
}
-
+
foreach ($this->tables as $table) {
$function = "load_$table";
$this->$function();
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);
/// 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);
/// 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
$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'));
/// 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.
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;
$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;
$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;
$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;
$scale->timemodified = mktime();
$temp = explode(',', $scale->scale);
$scale->max = count($temp) -1;
-
+
if ($scale->id = insert_record('scale', $scale)) {
$this->scale[3] = $scale;
}
$scale->timemodified = mktime();
$temp = explode(',', $scale->scale);
$scale->max = count($temp) -1;
-
+
if ($scale->id = insert_record('scale', $scale)) {
$this->scale[4] = $scale;
}
*/
function load_grade_categories() {
$grade_category = new stdClass();
-
+
$grade_category->fullname = 'unittestcategory1';
$grade_category->courseid = $this->courseid;
$grade_category->aggregation = GRADE_AGGREGATE_MEAN_GRADED;
$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;
$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;
$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;
$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;
- }
+ }
}
/**
if ($grade_item->id = insert_record('grade_items', $grade_item)) {
$this->grade_items[0] = $grade_item;
}
-
+
// id = 1
$grade_item = new stdClass();
$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;
}
if ($grade_item->id = insert_record('grade_items', $grade_item)) {
$this->grade_items[3] = $grade_item;
}
-
+
// id = 4
$grade_item = new stdClass();
if ($grade_item->id = insert_record('grade_items', $grade_item)) {
$this->grade_items[7] = $grade_item;
}
-
+
// id = 8
$grade_item = new stdClass();
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();
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;
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;
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;
if ($grade->id = insert_record('grade_grades', $grade)) {
$this->grade_grades[5] = $grade;
- }
+ }
// Grades for grade_item 3
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;
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;
if ($grade->id = insert_record('grade_grades', $grade)) {
$this->grade_grades[] = $grade;
}
-
+
// Grades for grade_item 7
$grade = new stdClass();
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;
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;
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;
if ($grade->id = insert_record('grade_grades', $grade)) {
$this->grade_grades[] = $grade;
}
-
+
// Grades for grade_item 9
$grade = new stdClass();
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;
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;
$this->grade_grades[] = $grade;
}
}
-
+
/**
* Load grade_grades_text data into the database, and adds the corresponding objects to this class' variable.
*/
$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.
*/
$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;
$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;
$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;
- }
+ }
}
/**
*/
function load_grade_history() {
$grade_history = new stdClass();
-
+
$grade_history->itemid = $this->grade_items[0]->id;
$grade_history->userid = 1;
$grade_history->oldgrade = 88;
if ($grade_history->id = insert_record('grade_history', $grade_history)) {
$this->grade_history[] = $grade_history;
- }
+ }
}
-/**
+/**
* No unit tests here
*/
$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;
$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);
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]);
$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));
}
$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'));
// 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;
$grade->rawgrade = rand(0, 1000) / 1000;
$grade->insert();
return $grade->rawgrade;
- }
+ }
function test_grade_category_set_as_parent() {
global $CFG;
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);
$category->keephigh = 1;
$category->droplow = 0;
$category->apply_limit_rules($grades);
- $this->assertEqual(array(9.4743), $grades);
+ $this->assertEqual(array(9.4743), $grades);
}
-}
+}
?>
$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);
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);
+ }
+}
?>
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';
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);
+ }
+}
?>
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);
$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;
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'));
$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);
}
-}
+}
?>
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';
$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));
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]);
$this->assertNotNull($grade_grades_text->grade_item);
$this->assertEqual($this->grade_items[0]->id, $grade_grades_text->grade_item->id);
}
-}
+}
?>
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_|
*/
$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);
$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_|
*/
$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_|
*/
$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);
$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
$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_|
*/
$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);
$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);
$this->assertTrue(empty($tree->need_update));
}
-
+
function test_grade_tree_locate_element() {
$tree = new grade_tree($this->courseid);
$element = $tree->locate_element(5);
$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);
$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));
$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]);
$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));
}
$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);
$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]));
// 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]));
$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));
}
$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);
$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);