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.
This commit is contained in:
@@ -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 . ' (<a href="category.php?cancelmove=true' . $tree->commonvars . '">' . $strcancel . '</a>)' . "\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);
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
+59
-14
@@ -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 .= '<a href="category.php?cancelmove=true' . $commonvars . '">' . $strcancel . '</a>)' . "\n";
|
||||
}
|
||||
|
||||
$list .= '<ul id="grade_edit_tree">' . "\n";
|
||||
$elements = $this->tree_array;
|
||||
} else {
|
||||
@@ -981,14 +988,31 @@ class grade_tree {
|
||||
if ($source_sortorder == $sortorder && !empty($action)) {
|
||||
$highlight_class = ' selected_element ';
|
||||
}
|
||||
|
||||
// Add dimmed_text span around object name if set to hidden
|
||||
$hide_show = 'hide';
|
||||
if ($element['object']->get_hidden()) {
|
||||
$object_name = '<span class="dimmed_text">' . $object_name . '</span>';
|
||||
$hide_show = 'show';
|
||||
}
|
||||
|
||||
// Prepare lock/unlock string
|
||||
$lock_unlock = 'lock';
|
||||
if ($element['object']->get_locked()) {
|
||||
$lock_unlock = 'unlock';
|
||||
}
|
||||
|
||||
// Print activity icon
|
||||
|
||||
$list .= '<li class="level' . $level . 'element sortorder'
|
||||
. $element['object']->get_sortorder() . $highlight_class . '">' . "\n"
|
||||
. $object_name;
|
||||
|
||||
$list .= '<div class="icons">';
|
||||
|
||||
// Print up arrow
|
||||
if (!$first) {
|
||||
$list .= '<a href="category.php?'."source=$sortorder&moveup={$element['object']->previous_sortorder}$commonvars\">\n";
|
||||
$list .= '<a href="category.php?'."source=$sortorder&moveup={$element['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";
|
||||
@@ -996,7 +1020,7 @@ class grade_tree {
|
||||
|
||||
// Print down arrow
|
||||
if (!$last) {
|
||||
$list .= '<a href="category.php?'."source=$sortorder&movedown={$element['object']->next_sortorder}$commonvars\">\n";
|
||||
$list .= '<a href="category.php?'."source=$sortorder&movedown={$element['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";
|
||||
@@ -1004,11 +1028,32 @@ class grade_tree {
|
||||
|
||||
// Print move icon
|
||||
if ($element_type != 'topcat') {
|
||||
$list .= '<a href="category.php?'."source=$sortorder&action=move&type=$element_type&sesskey=$commonvars\">\n";
|
||||
$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";
|
||||
} 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";
|
||||
|
||||
// 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";
|
||||
|
||||
// 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";
|
||||
// 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";
|
||||
|
||||
$list .= '</div> <!-- end icons div -->';
|
||||
|
||||
if (!empty($element['children'])) {
|
||||
$list .= $this->get_edit_tree($level + 1, $element['children'], $source_sortorder, $action, $source_type);
|
||||
@@ -1034,7 +1079,7 @@ class grade_tree {
|
||||
|
||||
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$commonvars\">\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";
|
||||
$list .= "</a>\n</li>";
|
||||
}
|
||||
|
||||
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 274 B |
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 269 B |
@@ -2007,14 +2007,20 @@ body#grade-index .grades .weighted {
|
||||
margin:0px 20px 0px 20px;
|
||||
}
|
||||
|
||||
/* gradebook edit tree */
|
||||
#grade_edit_tree .movetarget {
|
||||
position: relative;
|
||||
width: 80px;
|
||||
height: 16px;
|
||||
}
|
||||
|
||||
#content ul#grade_edit_tree {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
#grade_edit_tree li {
|
||||
list-style: none;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
#grade_edit_tree li.insertion {
|
||||
@@ -2040,6 +2046,12 @@ body#grade-index .grades .weighted {
|
||||
#grade_edit_tree .selected_element {
|
||||
background-color: #E8EEF7;
|
||||
}
|
||||
|
||||
#grade_edit_tree .icons {
|
||||
position: relative;
|
||||
display: inline;
|
||||
margin-left: 10px;
|
||||
}
|
||||
/***
|
||||
*** Login
|
||||
***/
|
||||
|
||||
Reference in New Issue
Block a user