From: skodak Date: Sat, 23 Jun 2007 16:51:09 +0000 (+0000) Subject: trailing whitespace cleanup in new grade libraries X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=772ddfbfce2f2117965a73e52890512784374aa3;p=moodle.git trailing whitespace cleanup in new grade libraries --- diff --git a/lib/grade/grade_object.php b/lib/grade/grade_object.php index 64f771c164..43c40cb3e6 100644 --- a/lib/grade/grade_object.php +++ b/lib/grade/grade_object.php @@ -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; } - } + } } } diff --git a/lib/grade/grade_outcome.php b/lib/grade/grade_outcome.php index c61e680e84..bbda5954a4 100644 --- a/lib/grade/grade_outcome.php +++ b/lib/grade/grade_outcome.php @@ -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; - } + } } ?> diff --git a/lib/grade/grade_scale.php b/lib/grade/grade_scale.php index 82a1d22717..59d6f7999d 100644 --- a/lib/grade/grade_scale.php +++ b/lib/grade/grade_scale.php @@ -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; + } } ?> diff --git a/lib/grade/grade_tree.php b/lib/grade/grade_tree.php index 1dfa860fac..c8dafb4e11 100644 --- a/lib/grade/grade_tree.php +++ b/lib/grade/grade_tree.php @@ -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 = ' '; @@ -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 .= '' . $item['object']->itemname . ''; + $itemhtml .= '' . $item['object']->itemname . ''; $items[] = $item; } - + if ($cat['object'] == 'filler') { $cathtml .= ' '; } else { @@ -905,31 +905,31 @@ class grade_tree { } } - + $studentshtml = ''; foreach ($users as $userid => $user) { $studentshtml .= '' . $user->firstname . ' ' . $user->lastname . ''; foreach ($items as $item) { if (!empty($this->grades[$userid][$item['object']->id])) { - $studentshtml .= '' . $this->grades[$userid][$item['object']->id] . '' . "\n"; + $studentshtml .= '' . $this->grades[$userid][$item['object']->id] . '' . "\n"; } else { $studentshtml .= '0' . "\n"; } - } + } $studentshtml .= ''; } - + $itemhtml .= ''; $cathtml .= ''; $topcathtml .= ''; - + $reporthtml = "$topcathtml$cathtml$itemhtml"; - $reporthtml .= $studentshtml; + $reporthtml .= $studentshtml; $reporthtml .= "
"; 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 .= '
' . "\n"; $list .= '