From 5fad506139f97df759a122fdbd65b7c5555d29cb Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Fri, 1 Jun 2007 04:02:37 +0000 Subject: [PATCH] MDL-9629 Category edit page now implements delete, show/hide, lock/unlock, moveup/movedown and move actions. The edit icon is also shown but not yet implemented. --- grade/report/grader/category.php | 91 ++++++++++++++++++++++++++----- lang/en_utf8/grades.php | 4 ++ lib/grade/grade_category.php | 63 ++++++++++++++++++++- lib/grade/grade_item.php | 38 +++++++++++++ lib/grade/grade_tree.php | 73 ++++++++++++++++++++----- pix/t/lock.gif | Bin 0 -> 274 bytes pix/t/unlock.gif | Bin 0 -> 269 bytes theme/standard/styles_layout.css | 12 ++++ 8 files changed, 252 insertions(+), 29 deletions(-) create mode 100755 pix/t/lock.gif create mode 100755 pix/t/unlock.gif diff --git a/grade/report/grader/category.php b/grade/report/grader/category.php index 7f178b03d7..fa59939a0b 100644 --- a/grade/report/grader/category.php +++ b/grade/report/grader/category.php @@ -29,19 +29,31 @@ require_once $CFG->libdir . '/gradelib.php'; print_header('Edit categories'); $param = new stdClass(); -$param->moveup = optional_param('moveup', 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->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); -$tree = new grade_tree(641); +$tree = new grade_tree($param->courseid); $select_source = false; -if (!empty($param->action)) { - print_heading("Select the destination for the selected element."); -} elseif (!empty($param->source)) { +if (!empty($param->action) && !empty($param->source) && confirm_sesskey()) { + $element = $tree->locate_element($param->source); + $element_name = $element->element['object']->get_name(); + + $strselectdestination = get_string('selectdestination', 'grades', $element_name); + $strmovingelement = get_string('movingelement', 'grades', $element_name); + $strcancel = get_string('cancel'); + + print_heading($strselectdestination); + + echo $strmovingelement . ' (' . $strcancel . ')' . "\n"; +} elseif (!empty($param->source) && confirm_sesskey()) { if (!empty($param->moveup)) { $tree->move_element($param->source, $param->moveup); } elseif(!empty($param->movedown)) { @@ -52,10 +64,63 @@ if (!empty($param->action)) { $tree->renumber(); $tree->update_db(); -} - -if ($select_source) { - print_heading("Select an element to move"); +} elseif (!empty($param->target) && !empty($param->action) && confirm_sesskey()) { + $element = $tree->locate_element($param->target); + switch ($param->action) { + case 'edit': + break; + case 'delete': + if ($param->confirm == 1) { + $tree->remove_element($param->target); + $tree->renumber(); + $tree->update_db(); + // Print result message + + } 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(); + } + break; + + case 'hide': + // TODO Implement calendar for selection of a date to hide element until + if (!$element->element['object']->set_hidden(1)) { + debugging("Could not update the element's hidden state!"); + } else { + $tree = new grade_tree($param->courseid); + } + break; + case 'show': + if (!$element->element['object']->set_hidden(0)) { + debugging("Could not update the element's hidden state!"); + } else { + $tree = new grade_tree($param->courseid); + } + break; + case 'lock': + // TODO Implement calendar for selection of a date to lock element after + if (!$element->element['object']->set_locked(1)) { + debugging("Could not update the element's locked state!"); + } else { + $tree = new grade_tree($param->courseid); + } + break; + case 'unlock': + if (!$element->element['object']->set_locked(0)) { + debugging("Could not update the element's locked state!"); + } else { + $tree = new grade_tree($param->courseid); + } + break; + default: + break; + } + unset($param->target); } echo $tree->get_edit_tree(1, null, $param->source, $param->action, $param->type); diff --git a/lang/en_utf8/grades.php b/lang/en_utf8/grades.php index c017017b82..182a5cdc8d 100644 --- a/lang/en_utf8/grades.php +++ b/lang/en_utf8/grades.php @@ -60,6 +60,7 @@ $string['items'] = 'Items'; $string['lettergrade'] = 'Letter Grade'; $string['lettergradenonnumber'] = 'Low and/or High grade were non-numeric for'; $string['letters'] = 'Letters'; +$string['lock'] = 'Lock'; $string['lowest'] = 'Lowest'; $string['lowgradeletter'] = 'Low'; $string['max'] = 'Highest'; @@ -67,6 +68,7 @@ $string['maxgrade'] = 'Max Grade'; $string['median'] = 'Median'; $string['min'] = 'Lowest'; $string['mode'] = 'Mode'; +$string['movingelement'] = 'Moving $a'; $string['no'] = 'No'; $string['nocategories'] = 'Grade categories could not be added or found for this course'; $string['nocategoryview'] = 'No category to view by'; @@ -91,6 +93,7 @@ $string['reprintheaders'] = 'Reprint Headers'; $string['savechanges'] = 'Save Changes'; $string['savepreferences'] = 'Save Preferences'; $string['scaledpct'] = 'Scaled %%'; +$string['selectdestination'] = 'Select destination of $a'; $string['setcategories'] = 'Set Categories'; $string['setcategorieserror'] = 'You must first set the categories for your course before you can give weights to them.'; $string['setgradeletters'] = 'Set Grade Letters'; @@ -111,6 +114,7 @@ $string['total'] = 'Total'; $string['totalweight100'] = 'The total weight is equal to 100'; $string['totalweightnot100'] = 'The total weight is not equal to 100'; $string['uncategorised'] = 'Uncategorised'; +$string['unlock'] = 'Unlock'; $string['useadvanced'] = 'Use Advanced Features'; $string['usepercent'] = 'Use Percent'; $string['useweighted'] = 'Use Weighted'; diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index 9dd1d96997..431767812d 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -858,8 +858,7 @@ class grade_category extends grade_object { /** * Returns the sortorder of the associated grade_item. This method is also available in - * grade_item, for cases where the object type is not know. It will act as a virtual - * variable for a grade_category. + * grade_item, for cases where the object type is not known. * @return int Sort order */ function get_sortorder() { @@ -883,6 +882,66 @@ class grade_category extends grade_object { $this->sortorder = $sortorder; } + /** + * Returns the locked state/date of the associated grade_item. This method is also available in + * grade_item, for cases where the object type is not known. + * @return int 0, 1 or timestamp int(10) + */ + function get_locked() { + $this->load_grade_item(); + if (!empty($this->grade_item)) { + return $this->grade_item->locked; + } else { + return false; + } + } + + /** + * Sets the grade_item's locked variable and updates the grade_item. + * Method named after grade_item::set_locked(). + * @param int $locked 0, 1 or a timestamp int(10) after which date the item will be locked. + * @return void + */ + function set_locked($locked) { + $this->load_grade_item(); + if (!empty($this->grade_item)) { + $this->grade_item->locked = $locked; + return $this->grade_item->update(); + } else { + return false; + } + } + + /** + * Returns the hidden state/date of the associated grade_item. This method is also available in + * grade_item, for cases where the object type is not known. + * @return int 0, 1 or timestamp int(10) + */ + function get_hidden() { + $this->load_grade_item(); + if (!empty($this->grade_item)) { + return $this->grade_item->hidden; + } else { + return false; + } + } + + /** + * Sets the grade_item's hidden variable and updates the grade_item. + * Method named after grade_item::set_hidden(). + * @param int $hidden 0, 1 or a timestamp int(10) after which date the item will be hidden. + * @return void + */ + function set_hidden($hidden) { + $this->load_grade_item(); + if (!empty($this->grade_item)) { + $this->grade_item->hidden = $hidden; + return $this->grade_item->update(); + } else { + return false; + } + } + /** * If the old parent is set (after an update), this checks and returns whether it has any children. Important for * deleting childless categories. diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index f7343cbee0..8b66d4e2b8 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -978,6 +978,44 @@ class grade_item extends grade_object { $this->categoryid = $parentid; } + /** + * Returns the locked state/date of this grade_item. This method is also available in + * grade_category, for cases where the object type is not known. + * @return int 0, 1 or timestamp int(10) + */ + function get_locked() { + return $this->locked; + } + + /** + * Sets the grade_item's locked variable and updates the grade_item. + * @param int $locked 0, 1 or a timestamp int(10) after which date the item will be locked. + * @return success or failure of update() method + */ + function set_locked($locked) { + $this->locked = $locked; + return $this->update(); + } + + /** + * Returns the hidden state/date of this grade_item. This method is also available in + * grade_category, for cases where the object type is not known. + * @return int 0, 1 or timestamp int(10) + */ + function get_hidden() { + return $this->hidden; + } + + /** + * Sets the grade_item's hidden variable and updates the grade_item. + * @param int $hidden 0, 1 or a timestamp int(10) after which date the item will be hidden. + * @return void + */ + function set_hidden($hidden) { + $this->hidden = $hidden; + return $this->update(); + } + /** * If the old parent is set (after an update), this checks and returns whether it has any children. Important for * deleting childless categories. diff --git a/lib/grade/grade_tree.php b/lib/grade/grade_tree.php index fda1951de8..bc5904274d 100644 --- a/lib/grade/grade_tree.php +++ b/lib/grade/grade_tree.php @@ -84,6 +84,12 @@ class grade_tree { */ var $include_grades; + /** + * A string of GET URL variables, namely courseid and sesskey, used in most URLs built by this class. + * @var string $commonvars + */ + var $commonvars; + /** * Constructor, retrieves and stores a hierarchical array of all grade_category and grade_item * objects for the given courseid or the entire site if no courseid given. Full objects are instantiated @@ -94,8 +100,12 @@ class grade_tree { * @param array $tree */ function grade_tree($courseid=NULL, $include_grades=false, $tree=NULL) { + 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)) { $this->tree_array = $tree; } else { @@ -931,7 +941,6 @@ class grade_tree { if (empty($this->tree_array)) { return null; } else { - global $USER; global $CFG; $strmove = get_string("move"); @@ -939,18 +948,16 @@ class grade_tree { $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'); $list = ''; - - $commonvars = "&sesskey=$USER->sesskey&courseid=$this->courseid"; if (empty($elements)) { - if ($source_sortorder && $action) { - $element = $this->locate_element($source_sortorder); - $list .= 'Moving ' . $element->element['object']->get_name() . ' ('; - $list .= '' . $strcancel . ')' . "\n"; - } - $list .= '