From 50df2264252cbbdbf3cad1895fc6b183e764e2ff Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Tue, 14 Oct 2008 17:15:52 +0000 Subject: [PATCH] MDL-15680 merged in all the functionality of the Edit categories and items page --- grade/edit/weights/index.php | 148 ++++++++++++++++++++++++++++++----- grade/edit/weights/lib.php | 135 +++++++++++++++++++++----------- grade/edit/weights/tree.css | 43 ++++++++-- 3 files changed, 256 insertions(+), 70 deletions(-) diff --git a/grade/edit/weights/index.php b/grade/edit/weights/index.php index afa8dcb139..5fb49be4b1 100755 --- a/grade/edit/weights/index.php +++ b/grade/edit/weights/index.php @@ -35,6 +35,7 @@ $action = optional_param('action', 0, PARAM_ALPHA); $eid = optional_param('eid', 0, PARAM_ALPHANUM); $category = optional_param('category', null, PARAM_INT); $aggregationtype = optional_param('aggregationtype', null, PARAM_INT); +$showadvanced = optional_param('showadvanced', false, PARAM_BOOL); /// Make sure they can even access this course @@ -67,6 +68,17 @@ grade_regrade_final_grades($courseid); // note: total must be first for moving to work correctly, if you want it last moving code must be rewritten! $gtree = new grade_tree($courseid, false, false); +if (empty($eid)) { + $element = null; + $object = null; + +} else { + if (!$element = $gtree->locate_element($eid)) { + print_error('invalidelementid', '', $returnurl); + } + $object = $element['object']; +} + $switch = grade_get_setting($course->id, 'aggregationposition', $CFG->grade_aggregationposition); $strgrades = get_string('grades'); @@ -77,6 +89,72 @@ $strcategoriesanditems = get_string('categoriesanditems', 'grades'); $navigation = grade_build_nav(__FILE__, $strcategoriesanditems, array('courseid' => $courseid)); $moving = false; +switch ($action) { + case 'delete': + if ($eid) { + if (!element_deletable($element)) { + // no deleting of external activities - they would be recreated anyway! + // exception is activity without grading or misconfigured activities + break; + } + $confirm = optional_param('confirm', 0, PARAM_BOOL); + + if ($confirm and confirm_sesskey()) { + $object->delete('grade/report/grader/category'); + redirect($returnurl); + + } else { + print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course)); + $strdeletecheckfull = get_string('deletecheck', '', $object->get_name()); + $optionsyes = array('eid'=>$eid, 'confirm'=>1, 'sesskey'=>sesskey(), 'id'=>$course->id, 'action'=>'delete'); + $optionsno = array('id'=>$course->id); + notice_yesno($strdeletecheckfull, 'index.php', 'index.php', $optionsyes, $optionsno, 'post', 'get'); + print_footer($course); + die; + } + } + break; + + case 'autosort': + //TODO: implement autosorting based on order of mods on course page, categories first, manual items last + break; + + case 'synclegacy': + grade_grab_legacy_grades($course->id); + redirect($returnurl); + + case 'move': + if ($eid and confirm_sesskey()) { + $moveafter = required_param('moveafter', PARAM_ALPHANUM); + if(!$after_el = $gtree->locate_element($moveafter)) { + print_error('invalidelementid', '', $returnurl); + } + $after = $after_el['object']; + $parent = $after->get_parent_category(); + $sortorder = $after->get_sortorder(); + + $object->set_parent($parent->id); + $object->move_after_sortorder($sortorder); + + redirect($returnurl); + } + break; + + case 'moveselect': + if ($eid and confirm_sesskey()) { + $moving = $eid; + } + break; + + default: + break; +} + +// Hide advanced columns if moving +if ($moving) { + $showadvanced = false; +} + $CFG->stylesheets[] = $CFG->wwwroot.'/grade/edit/weights/tree.css'; print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course)); @@ -90,22 +168,27 @@ $form_key = optional_param('sesskey', null, PARAM_ALPHANUM); if ($form_key && $data = data_submitted()) { foreach ($data as $key => $value) { - if (preg_match('/aggregation_type_([0-9]*)/', $key, $matches)) { - $aggtype = required_param($matches[0], PARAM_INT); - $a->id = $matches[1]; + // Grade category text inputs + if (preg_match('/(aggregation|droplow|keephigh)_([0-9]*)/', $key, $matches)) { + $value = required_param($matches[0], PARAM_INT); + $param = $matches[1]; + $a->id = $matches[2]; - if (!$DB->update_record('grade_categories', array('id' => $matches[1], 'aggregation' => $aggtype))) { + if (!$DB->update_record('grade_categories', array('id' => $matches[2], $param => $value))) { print_error('errorupdatinggradecategoryaggregation', 'grades', $a); } - } elseif (preg_match('/weight_([0-9]*)/', $key, $matches)) { - $weight = required_param($matches[0], PARAM_NUMBER); - $a->id = $matches[1]; + // Grade item text inputs + } elseif (preg_match('/(aggregationcoef|multfactor|plusfactor)_([0-9]*)/', $key, $matches)) { + $value = required_param($matches[0], PARAM_NUMBER); + $param = $matches[1]; + $a->id = $matches[2]; - if (!$DB->update_record('grade_items', array('id' => $matches[1], 'aggregationcoef' => $weight))) { + if (!$DB->update_record('grade_items', array('id' => $matches[2], $param => $value))) { print_error('errorupdatinggradeitemaggregationcoef', 'grades', $a); } + // Grade item checkbox inputs } elseif (preg_match('/extracredit_original_([0-9]*)/', $key, $matches)) { // Sum extra credit checkbox $extracredit = optional_param("extracredit_{$matches[1]}", null, PARAM_BOOL); $original_value = required_param($matches[0], PARAM_BOOL); @@ -124,6 +207,7 @@ if ($form_key && $data = data_submitted()) { print_error('errorupdatinggradeitemaggregationcoef', 'grades', $a); } + // Grade category checkbox inputs } elseif (preg_match('/aggregate(onlygraded|subcats|outcomes)_original_([0-9]*)/', $key, $matches)) { $setting = optional_param('aggregate'.$matches[1].'_'.$matches[2], null, PARAM_BOOL); $original_value = required_param($matches[0], PARAM_BOOL); @@ -147,19 +231,46 @@ if ($form_key && $data = data_submitted()) { // echo '
Expand all Collapse all
'; -echo ''; +print_box_start('gradetreebox generalbox'); + echo '
'; -echo '
'; +echo '
'; echo ''; -echo build_html_tree(get_tree_json($gtree, $gtree->top_element, 0, $gpr), null, $returnurl); +echo build_html_tree(get_tree_json($gtree, $gtree->top_element, 0, $gpr), null, $returnurl, $moving, $eid); -// print_grade_tree($gtree, $gtree->top_element, $gpr, $switch); -// -echo '
'; +if ($showadvanced && !$moving) { + echo ''; +} -echo ''; -echo '
+echo '
+'; + +print_box_end(); + +echo '
'; +if ($moving) { + print_single_button('index.php', array('id'=>$course->id), get_string('cancel'), 'get'); +} else { + $strshowhideadvanced = get_string('showadvancedcolumns', 'grades'); + + if ($showadvanced) { + $strshowhideadvanced = get_string('hideadvancedcolumns', 'grades'); + } + + print_single_button('index.php', array('id'=>$course->id, 'showadvanced' => !$showadvanced), $strshowhideadvanced, 'get'); + print_single_button('category.php', array('courseid'=>$course->id), get_string('addcategory', 'grades'), 'get'); + print_single_button('item.php', array('courseid'=>$course->id), get_string('additem', 'grades'), 'get'); + + if (!empty($CFG->enableoutcomes)) { + print_single_button('outcomeitem.php', array('courseid'=>$course->id), get_string('addoutcomeitem', 'grades'), 'get'); + } + + //print_single_button('index.php', array('id'=>$course->id, 'action'=>'autosort'), get_string('autosort', 'grades'), 'get'); + print_single_button('index.php', array('id'=>$course->id, 'action'=>'synclegacy'), get_string('synclegacygrades', 'grades'), 'get'); +} +echo '
'; +echo ' -'; +'; print_footer($course); die; diff --git a/grade/edit/weights/lib.php b/grade/edit/weights/lib.php index 96149b0e0e..871f4c6d8a 100644 --- a/grade/edit/weights/lib.php +++ b/grade/edit/weights/lib.php @@ -50,6 +50,8 @@ function get_tree_json(&$gtree, $element, $totals=false, $gpr) { $return_array['item']->actions .= $gtree->get_hiding_icon($element, $gpr); $return_array['item']->actions .= $gtree->get_locking_icon($element, $gpr); + $return_array['item']->eid = $element['eid']; + $return_array['item']->type = $element['type']; if ($element['type'] == 'category') { foreach($element['children'] as $child_el) { @@ -63,8 +65,11 @@ function get_tree_json(&$gtree, $element, $totals=false, $gpr) { return $return_array; } -function build_html_tree($tree, $element=null, $level=0) { - global $CFG; +function build_html_tree($tree, $element=null, $level=0, $moving=false, $eid) { + global $CFG, $COURSE; + + $showadvanced = optional_param('showadvanced', false, PARAM_BOOL); + $advclass = ($showadvanced) ? 'shown' : 'hidden'; $options = array(GRADE_AGGREGATE_MEAN => get_string('aggregatemean', 'grades'), GRADE_AGGREGATE_WEIGHTED_MEAN => get_string('aggregateweightedmean', 'grades'), @@ -82,19 +87,24 @@ function build_html_tree($tree, $element=null, $level=0) { if (is_null($element)) { $html .= ' - - - - - - - - - - - + '; + if (!$moving) { + $html .= ' + + + + + + + + + + - '; + '; + } + + $html .= ''; $element = $tree; $root = true; } @@ -102,12 +112,33 @@ function build_html_tree($tree, $element=null, $level=0) { $id = required_param('id', PARAM_INT); + /// prepare move target if needed + $last = ''; + $moveto = ''; + + if ($moving) { + $strmove = get_string('move'); + $strmovehere = get_string('movehere'); + $element['item']->actions = ''; // no action icons when moving + $moveto = ''; + } + + /// print the list items now + if ($moving == $element['item']->eid) { + + // do not diplay children + return ''; + + } + if (!empty($element['children'])) { // Grade category $category = grade_category::fetch(array('id' => $element['item']->id)); $item = $category->get_grade_item(); $script = "window.location='index.php?id=$id&category={$category->id}&aggregationtype='+this.value"; - $aggregation_type = choose_from_menu($options, 'aggregation_type_'.$category->id, $category->aggregation, get_string('choose'), $script, 0, true); + $aggregation = choose_from_menu($options, 'aggregation_'.$category->id, $category->aggregation, get_string('choose'), $script, 0, true); $onlygradedcheck = ($category->aggregateonlygraded == 1) ? 'checked="checked"' : ''; $subcatscheck = ($category->aggregatesubcats == 1) ? 'checked="checked"' : ''; @@ -126,27 +157,34 @@ function build_html_tree($tree, $element=null, $level=0) { // Add aggregation coef input if not a course item and if parent category has correct aggregation type $aggcoef_input = get_weight_input($item); + $dimmed = ($item->hidden) ? " dimmed " : ""; $html .= ' - + - - - - - - - - - - - + . 'px; background: #DDDDDD url(img/ln.gif) no-repeat scroll ' . (($level - 1) * 20) . 'px 8px">' . $element['item']->name . $hidden . ''; + + if (!$moving) { + $html .= ' + + + + + + + + + + + '; + } + + $html .= ' - '; + '.$moveto; foreach ($element['children'] as $child) { - $html .= build_html_tree($tree, $child, $level+1); + $html .= build_html_tree($tree, $child, $level+1, $moving, $eid); } } else { // Dealing with a grade item @@ -175,23 +213,30 @@ function build_html_tree($tree, $element=null, $level=0) { $multfactor = ''; $plusfactor = ''; + $dimmed = ($item->hidden) ? " dimmed_text " : ""; $html .= ' - + - - - - - - - - - - - + . 'px; background: #FFFFFF url(img/ln.gif) no-repeat scroll ' . (($level - 1) * 20) . 'px 8px">' . $element['item']->name . ''; + + if (!$moving) { + $html .= ' + + + + + + + + + + + '; + } + + $html .= ' - '; + '.$moveto; } @@ -232,7 +277,7 @@ function get_weight_input($item) { } if ($aggcoef == 'aggregationcoefweight' || $aggcoef == 'aggregationcoefextra') { - return ''; + return ''; } elseif ($aggcoef == 'aggregationcoefextrasum' ) { $checked = ($item->aggregationcoef > 0) ? 'checked="checked"' : ''; $extracredit = ($item->aggregationcoef > 0) ? 1 : 0; diff --git a/grade/edit/weights/tree.css b/grade/edit/weights/tree.css index c56a7006ee..24c750965b 100644 --- a/grade/edit/weights/tree.css +++ b/grade/edit/weights/tree.css @@ -1,16 +1,16 @@ -#gradetree tr.category td { +.gradetreebox tr.category td { background-color: #DDDDDD; } -#gradetree .category td.name { +.gradetreebox .category td.name { font-weight: bold; } -#gradetree td.name { +.gradetreebox td.name { } -#gradetree th.actions { +.gradetreebox th.actions { width: 80px; } @@ -18,6 +18,39 @@ background-image: url(img/ln.gif); } -.advanced { +.hidden { display: none; } +.shown { +} + +img.iconsmall { + margin-left: 4px; +} + +img.icon { + margin-right: 5px; +} + +.gradetreebox { + margin-left: auto; + margin-right: auto; + margin-top: 10px; + padding-bottom: 15px; +} + +.gradetreebox table { + margin-left: auto; + margin-right: auto; +} + +.buttons { + margin: 20px; + text-align: center; + width: 100%; +} + +.buttons .singlebutton { + display: inline; + padding: 5px; +} -- 2.39.5
'.get_string('name').''.get_string('aggregation', 'grades').''.get_string('weightorextracredit', 'grades').''.get_string('range', 'grades').''.get_string('aggregateonlygraded', 'grades').''.get_string('aggregatesubcats', 'grades').''.get_string('aggregateoutcomes', 'grades').''.get_string('droplow', 'grades').''.get_string('keephigh', 'grades').''.get_string('multfactor', 'grades').''.get_string('plusfactor', 'grades').''.get_string('name').''.get_string('aggregation', 'grades').''.get_string('weightorextracredit', 'grades').''.get_string('range', 'grades').''.get_string('aggregateonlygraded', 'grades').''.get_string('aggregatesubcats', 'grades').''.get_string('aggregateoutcomes', 'grades').''.get_string('droplow', 'grades').''.get_string('keephigh', 'grades').''.get_string('multfactor', 'grades').''.get_string('plusfactor', 'grades').' '.get_string('actions').'
'
+                . $strmovehere.'
'.$element['item']->name.' ('.get_string('move').')
' . $element['item']->name . $hidden . '' . $aggregation_type . '' . $aggcoef_input . '' . $item->get_formatted_range() . '' . $aggregateonlygraded . '' . $aggregatesubcats . '' . $aggregateoutcomes . '' . $droplow . '' . $keephigh . ' - - ' . $element['item']->actions . '' . $aggregation . '' . $aggcoef_input . '' . $item->get_formatted_range() . '' . $aggregateonlygraded . '' . $aggregatesubcats . '' . $aggregateoutcomes . '' . $droplow . '' . $keephigh . ' - - ' . $element['item']->actions . '
' . $element['item']->name . ' - ' . $aggcoef_input . '' . $item->get_formatted_range() . ' - - - - - '.$multfactor.''.$plusfactor.'' . $element['item']->actions . ' - ' . $aggcoef_input . '' . $item->get_formatted_range() . ' - - - - - '.$multfactor.''.$plusfactor.'' . $element['item']->actions . '