From de5284f26dd876f200b917e8945a22f38e3a8f0e Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Fri, 1 Jun 2007 08:01:47 +0000 Subject: [PATCH] MDL-9137 Almost finished the edit category page. The only remaining issue is some sort of endless loop starting in grade_category::set_as_parent. Big issue... --- grade/report/grader/category.php | 77 ++++++++++++++++++---- lib/grade/grade_tree.php | 106 +++++++++++++++++++++++-------- lib/weblib.php | 3 +- theme/standard/styles_layout.css | 10 +++ 4 files changed, 155 insertions(+), 41 deletions(-) diff --git a/grade/report/grader/category.php b/grade/report/grader/category.php index fa59939a0b..c0289b96d5 100644 --- a/grade/report/grader/category.php +++ b/grade/report/grader/category.php @@ -29,15 +29,19 @@ require_once $CFG->libdir . '/gradelib.php'; print_header('Edit categories'); $param = new stdClass(); -$param->courseid = optional_param('courseid', 0 , PARAM_INT); -$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); -$param->type = optional_param('type', 0, PARAM_ALPHA); -$param->target = optional_param('target', 0, PARAM_INT); -$param->confirm = optional_param('confirm', 0, PARAM_INT); +$param->courseid = optional_param('courseid', 0 , PARAM_INT); +$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); +$param->type = optional_param('type', 0, PARAM_ALPHA); +$param->target = optional_param('target', 0, PARAM_INT); +$param->confirm = optional_param('confirm', 0, PARAM_INT); +$param->items = optional_param('items', 0, PARAM_INT); +$param->categories = optional_param('categories', 0, PARAM_INT); +$param->element_type = optional_param('element_type', 0, PARAM_ALPHA); +$param->category_name= optional_param('category_name', 0, PARAM_ALPHA); $tree = new grade_tree($param->courseid); $select_source = false; @@ -79,11 +83,9 @@ if (!empty($param->action) && !empty($param->source) && confirm_sesskey()) { } else { // Print confirmation dialog $strdeletecheckfull = get_string('deletecheck', '', $element->element['object']->get_name()); - print_simple_box_start('center', '60%', '#FFAAAA', 20, 'noticebox'); - print_heading($strdeletecheckfull); - include_once('category_delete.html'); - print_simple_box_end(); - exit(); + $linkyes = "category.php?target=$param->target&action=delete&confirm=1$tree->commonvars"; + $linkno = "category.php?$tree->commonvars"; + notice_yesno($strdeletecheckfull, $linkyes, $linkno); } break; @@ -121,6 +123,53 @@ if (!empty($param->action) && !empty($param->source) && confirm_sesskey()) { break; } unset($param->target); +} elseif (!empty($param->element_type) && !empty($param->action) && $param->action == 'create' && confirm_sesskey() && !empty($param->category_name)) { + if ($param->element_type == 'items') { + if (!empty($param->items)) { + $category = new grade_category(); + $category->fullname = $param->category_name; + $category->courseid = $tree->courseid; + $items = array(); + foreach ($param->items as $sortorder => $useless_var) { + $element = $tree->locate_element($sortorder); + $items[$element->element['object']->id] = $element->element['object']; + } + print_object($items); + /* + if ($category->set_as_parent($items) && $category->update()) { + $tree = new grade_tree($param->courseid); + } else { // creation of category didn't work, print a message + debugging("Could not create a parent category over the items you selected.."); + } + */ + + } else { // No items selected. Can't create a category over them... + notice("Couldn't create a category, you did not select any grade items."); + } + } elseif ($param->element_type == 'categories') { + if (!empty($param->categories)) { + $category = new grade_category(); + $category->fullname = $param->category_name; + $category->courseid = $tree->courseid; + $categories = array(); + foreach ($param->categories as $sortorder => $useless_var) { + $element = $tree->locate_element($sortorder); + $categories[$element->element['object']->id] = $element->element['object']; + } + + if ($category->set_as_parent($categories) && $category->update()) { + $tree = new grade_tree($param->courseid); + } else { // creation of category didn't work, print a message + debugging("Could not create a parent category over the categories you selected.."); + } + + } else { // No categories selected. Can't create a category over them... + notice("Couldn't create a category, you did not select any sub-categories."); + } + + } else { // The element_type wasn't set properly, throw up an error + + } } echo $tree->get_edit_tree(1, null, $param->source, $param->action, $param->type); diff --git a/lib/grade/grade_tree.php b/lib/grade/grade_tree.php index bc5904274d..f2bb8818aa 100644 --- a/lib/grade/grade_tree.php +++ b/lib/grade/grade_tree.php @@ -942,24 +942,50 @@ class grade_tree { return null; } else { global $CFG; - - $strmove = get_string("move"); - $strmoveup = get_string("moveup"); - $strmovedown = get_string("movedown"); - $strmovehere = get_string("movehere"); - $strcancel = get_string("cancel"); - $stredit = get_string("edit"); - $strdelete = get_string("delete"); - $strhide = get_string("hide"); - $strshow = get_string("show"); - $strlock = get_string("lock", 'grades'); - $strunlock = get_string("unlock", 'grades'); + global $USER; + + $strmove = get_string("move"); + $strmoveup = get_string("moveup"); + $strmovedown = get_string("movedown"); + $strmovehere = get_string("movehere"); + $strcancel = get_string("cancel"); + $stredit = get_string("edit"); + $strdelete = get_string("delete"); + $strhide = get_string("hide"); + $strshow = get_string("show"); + $strlock = get_string("lock", 'grades'); + $strunlock = get_string("unlock", 'grades'); + $strnewcategory = get_string("newcategory", 'grades'); + $strcategoryname = get_string("categoryname", 'grades'); + $strcreatecategory = get_string("createcategory", 'grades'); + $strsubcategory = get_string("subcategory", 'grades'); + $stritems = get_string("items", 'grades'); + $strcategories = get_string("categories", 'grades'); $list = ''; - + $closing_form_tags = ''; + if (empty($elements)) { + $list .= '
' . "\n"; $list .= '
' . "\n$closing_form_tags"; + return $list; } diff --git a/lib/weblib.php b/lib/weblib.php index b1e92cb5aa..4a560613b9 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -5342,6 +5342,7 @@ function notice ($message, $link='', $course=NULL) { * @param string $message The text to display * @param string $linkyes The link to take the user to if they choose "Yes" * @param string $linkno The link to take the user to if they choose "No" + * TODO Document remaining arguments */ function notice_yesno ($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=NULL, $methodyes='post', $methodno='post') { @@ -6241,4 +6242,4 @@ function print_location_comment($file, $line, $return = false) } // vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140: -?> \ No newline at end of file +?> diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css index 0638f43088..087e120cda 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -2023,6 +2023,16 @@ body#grade-index .grades .weighted { margin-top: 8px; } +#grade_edit_tree li div.moduleicon { + margin-right: 5px; + display: inline; +} + +#grade_edit_tree li div.select_checkbox { + margin-right: 5px; + display: inline; +} + #grade_edit_tree li.insertion { cursor: pointer; } -- 2.39.5