From 5bfa0d793a0fb1bec948c0c7cde992d7f088cb7f Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Wed, 30 May 2007 08:48:11 +0000 Subject: [PATCH] Implemented a test version of the gradebook category edit page, and developed the get_edit_tree method in grade_tree. Items can be successfully moved up and down, and a "move" button lets the user select a source element, then a destination box. All actions use POST. --- grade/report/grader/category.php | 72 ++++++++++++++++++++++++ lib/grade/grade_tree.php | 94 ++++++++++++++++++++++++-------- 2 files changed, 144 insertions(+), 22 deletions(-) create mode 100644 grade/report/grader/category.php diff --git a/grade/report/grader/category.php b/grade/report/grader/category.php new file mode 100644 index 00000000000..851350035d3 --- /dev/null +++ b/grade/report/grader/category.php @@ -0,0 +1,72 @@ +libdir . '/grade/grade_tree.php'; +require_once $CFG->libdir . '/gradelib.php'; +print_header('Edit categories'); + +$param = new stdClass(); +$param->moveup = optional_param('moveup', 0, PARAM_INT); +$param->movedown = optional_param('movedown', 0, PARAM_INT); +$param->source = optional_param('source', 0, PARAM_INT); +$param->action = optional_param('action', 0, PARAM_ALPHA); +$param->move = optional_param('move', 0, PARAM_INT); + +$tree = new grade_tree(641); +$select_source = false; + +if (!empty($param->action)) { + if (empty($param->source)) { + $select_source = true; + } else { + print_heading("Select the destination for the selected element."); + } +} elseif (!empty($param->source)) { + if (!empty($param->moveup)) { + $tree->move_element($param->source, $param->moveup); + } elseif(!empty($param->movedown)) { + $tree->move_element($param->source, $param->movedown, 'after'); + } elseif(!empty($param->move)) { + $tree->move_element($param->source, $param->move, 'after'); + } + + $tree->renumber(); + $tree->update_db(); +} + +if ($select_source) { + print_heading("Select an element to move"); +} + +echo $tree->get_edit_tree($select_source, 1, null, $param->source, $param->action); + +echo '
' . "\n"; +echo '' . "\n"; +echo '' . "\n"; +echo '
'; + +print_footer(); +?> diff --git a/lib/grade/grade_tree.php b/lib/grade/grade_tree.php index 8a86944e603..641a101e781 100644 --- a/lib/grade/grade_tree.php +++ b/lib/grade/grade_tree.php @@ -404,7 +404,7 @@ 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']->sortorder; @@ -439,7 +439,7 @@ class grade_tree { return $newtree; } } - + /** * 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 @@ -912,9 +912,14 @@ class grade_tree { /** * Returns a HTML list with sorting arrows and insert boxes. This is a recursive method. + * @param boolean $select_source Whether or not to display each element as a link to be selected as a source for an action + * @param int $level The level of recursion + * @param array $elements The elements to display in a list. Defaults to this->tree_array + * @param int $source_sortorder A source sortorder, given when an element needs to be moved or inserted. + * @param string $action 'move' or 'insert' * @return string HTML code */ - function get_edit_tree($level=1, $elements=null) { + function get_edit_tree($select_source=false, $level=1, $elements=NULL, $source_sortorder=NULL, $action=NULL) { if (empty($this->tree_array)) { return null; } else { @@ -923,17 +928,21 @@ class grade_tree { $strmoveup = get_string("moveup"); $strmovedown = get_string("movedown"); + + $sesskey_input = ''; + $courseid_input = ''; if (empty($elements)) { - $list = '