From: nicolasconnault Date: Mon, 22 Sep 2008 15:51:27 +0000 (+0000) Subject: MDL-15680 Began implementing a simple YUI treeview of the grade items in their catego... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e58fcb3517aeaac364f2768594c5f792173c517d;p=moodle.git MDL-15680 Began implementing a simple YUI treeview of the grade items in their categories. Will tweak this to become a form with weights in input fields, and possible drag and drop also --- diff --git a/grade/edit/weights/ajax.php b/grade/edit/weights/ajax.php new file mode 100755 index 0000000000..393a48fba6 --- /dev/null +++ b/grade/edit/weights/ajax.php @@ -0,0 +1,60 @@ + diff --git a/grade/edit/weights/img/lm.gif b/grade/edit/weights/img/lm.gif new file mode 100644 index 0000000000..b5623002a6 Binary files /dev/null and b/grade/edit/weights/img/lm.gif differ diff --git a/grade/edit/weights/img/lmh.gif b/grade/edit/weights/img/lmh.gif new file mode 100644 index 0000000000..a17fe233c1 Binary files /dev/null and b/grade/edit/weights/img/lmh.gif differ diff --git a/grade/edit/weights/img/ln.gif b/grade/edit/weights/img/ln.gif new file mode 100644 index 0000000000..b7b3e55cd0 Binary files /dev/null and b/grade/edit/weights/img/ln.gif differ diff --git a/grade/edit/weights/img/loading.gif b/grade/edit/weights/img/loading.gif new file mode 100644 index 0000000000..0bbf3bc0c0 Binary files /dev/null and b/grade/edit/weights/img/loading.gif differ diff --git a/grade/edit/weights/img/lp.gif b/grade/edit/weights/img/lp.gif new file mode 100644 index 0000000000..b9f5485670 Binary files /dev/null and b/grade/edit/weights/img/lp.gif differ diff --git a/grade/edit/weights/img/lph.gif b/grade/edit/weights/img/lph.gif new file mode 100644 index 0000000000..f663714f49 Binary files /dev/null and b/grade/edit/weights/img/lph.gif differ diff --git a/grade/edit/weights/img/tm.gif b/grade/edit/weights/img/tm.gif new file mode 100644 index 0000000000..56622cc305 Binary files /dev/null and b/grade/edit/weights/img/tm.gif differ diff --git a/grade/edit/weights/img/tmh.gif b/grade/edit/weights/img/tmh.gif new file mode 100644 index 0000000000..e42349e406 Binary files /dev/null and b/grade/edit/weights/img/tmh.gif differ diff --git a/grade/edit/weights/img/tn.gif b/grade/edit/weights/img/tn.gif new file mode 100644 index 0000000000..4a280397de Binary files /dev/null and b/grade/edit/weights/img/tn.gif differ diff --git a/grade/edit/weights/img/tp.gif b/grade/edit/weights/img/tp.gif new file mode 100644 index 0000000000..906e8c46e4 Binary files /dev/null and b/grade/edit/weights/img/tp.gif differ diff --git a/grade/edit/weights/img/tph.gif b/grade/edit/weights/img/tph.gif new file mode 100644 index 0000000000..8aa7c2504b Binary files /dev/null and b/grade/edit/weights/img/tph.gif differ diff --git a/grade/edit/weights/img/vline.gif b/grade/edit/weights/img/vline.gif new file mode 100644 index 0000000000..1fb0de8bb2 Binary files /dev/null and b/grade/edit/weights/img/vline.gif differ diff --git a/grade/edit/weights/index.php b/grade/edit/weights/index.php new file mode 100755 index 0000000000..6a1ec1143f --- /dev/null +++ b/grade/edit/weights/index.php @@ -0,0 +1,120 @@ +dirroot.'/grade/lib.php'; +require_once $CFG->dirroot.'/grade/report/lib.php'; // for preferences + +$courseid = required_param('id', PARAM_INT); +$action = optional_param('action', 0, PARAM_ALPHA); +$eid = optional_param('eid', 0, PARAM_ALPHANUM); + +require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_json', 'yui_connection', 'yui_dragdrop', 'yui_treeview')); + +/// Make sure they can even access this course + +if (!$course = $DB->get_record('course', array('id' => $courseid))) { + print_error('nocourseid'); +} + +require_login($course); +$context = get_context_instance(CONTEXT_COURSE, $course->id); +require_capability('moodle/grade:manage', $context); + +/// return tracking object +$gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'weight', 'courseid'=>$courseid)); +$returnurl = $gpr->get_return_url(null); + +//first make sure we have proper final grades - we need it for locking changes +grade_regrade_final_grades($courseid); + +// get the grading tree object +// 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); + +$switch = grade_get_setting($course->id, 'aggregationposition', $CFG->grade_aggregationposition); + +$strgrades = get_string('grades'); +$strgraderreport = get_string('graderreport', 'grades'); +$strcategoriesedit = get_string('categoriesedit', 'grades'); +$strcategoriesanditems = get_string('categoriesanditems', 'grades'); + +$navigation = grade_build_nav(__FILE__, $strcategoriesanditems, array('courseid' => $courseid)); +$moving = false; + +switch ($action) { + default: + break; +} + +$CFG->stylesheets[] = $CFG->wwwroot.'/grade/edit/weights/tree.css'; +print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course)); + +/// Print the plugin selector at the top +print_grade_plugin_selector($courseid, 'edit', 'tree'); + +print_heading(get_string('categoriesedit', 'grades')); +$tree_json = json_encode(get_tree_json($gtree, $gtree->top_element)); + +require_once('ajax.php'); + +print_box_start('gradetreebox generalbox'); + +echo '
+ Expand all + Collapse all +
'; + +echo '
'; +echo '
'; + +// print_grade_tree($gtree, $gtree->top_element, $gpr, $switch); +// +echo '
'; +echo '
'; +print_box_end(); + +print_footer($course); +die; + +function get_tree_json(&$gtree, $element) { + + $return_array = array(); + + $object = $element['object']; + $eid = $element['eid']; + $object->name = $gtree->get_element_header($element, false, false, false); + + $return_array['item'] = $object; + + if ($element['type'] == 'category') { + foreach($element['children'] as $child_el) { + $return_array['children'][] = get_tree_json($gtree, $child_el); + } + } + + return $return_array; +} +?> diff --git a/grade/edit/weights/tree.css b/grade/edit/weights/tree.css new file mode 100644 index 0000000000..d70421942f --- /dev/null +++ b/grade/edit/weights/tree.css @@ -0,0 +1,136 @@ +/* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */ + +/* first or middle sibling, no children */ +.ygtvtn { + background: url(img/tn.gif) 0 0 no-repeat; + width:17px; + height:22px; +} + +/* first or middle sibling, collapsable */ +.ygtvtm { + background: url(img/tm.gif) 0 0 no-repeat; + width:34px; + height:22px; cursor:pointer +} + +/* first or middle sibling, collapsable, hover */ +.ygtvtmh { + background: url(img/tmh.gif) 0 0 no-repeat; + width:34px; + height:22px; + cursor:pointer +} + +/* first or middle sibling, expandable */ +.ygtvtp { + background: url(img/tp.gif) 0 0 no-repeat; + width:34px; + height:22px; + cursor:pointer +} + +/* first or middle sibling, expandable, hover */ +.ygtvtph { + background: url(img/tph.gif) 0 0 no-repeat; + width:34px; + height:22px; + cursor:pointer +} + +/* last sibling, no children */ +.ygtvln { + background: url(img/ln.gif) 0 0 no-repeat; + width:17px; + height:22px; +} + +/* Last sibling, collapsable */ +.ygtvlm { + background: url(img/lm.gif) 0 0 no-repeat; + + width:34px; + height:22px; + cursor:pointer +} + +/* Last sibling, collapsable, hover */ +.ygtvlmh { + background: url(img/lmh.gif) 0 0 no-repeat; + width:34px; + height:22px; + cursor:pointer +} + +/* Last sibling, expandable */ +.ygtvlp { + background: url(img/lp.gif) 0 0 no-repeat; + width:34px; + height:22px; + cursor:pointer +} + +/* Last sibling, expandable, hover */ +.ygtvlph { + background: url(img/lph.gif) 0 0 no-repeat; + width:34px; + height:22px; + cursor:pointer +} + +/* Loading icon */ +.ygtvloading { + background: url(img/loading.gif) 0 0 no-repeat; + width:16px; + height:22px; +} + +/* the style for the empty cells that are used for rendering the depth + * of the node */ +.ygtvdepthcell { + background: url(img/vline.gif) 0 0 no-repeat; + width:17px; + height:22px; +} + +.ygtvblankdepthcell { + width:17px; + height:22px; +} + +/* the style of the div around each node */ +.ygtvitem { } + +.ygtvitem table{ + margin-bottom:0; +} +.ygtvitem td { + border:none;padding:0; +} + + + +/* the style of the div around each node's collection of children */ +.ygtvchildren { } +* html .ygtvchildren { + height:1%; +} + +/* the style of the text label in ygTextNode */ +.ygtvlabel, .ygtvlabel:link, .ygtvlabel:visited, .ygtvlabel:hover { + margin-left:2px; + text-decoration: none; +} + +#expandcontractdiv { + border:1px dotted #dedede; + background-color:#EBE4F2; + margin:0 0 .5em 0; + padding:0.4em; +} + +#weightstree { + background: #fff; + padding:1em; + margin-top:1em; +} diff --git a/grade/lib.php b/grade/lib.php index 21234a3588..319b49aa1a 100644 --- a/grade/lib.php +++ b/grade/lib.php @@ -79,15 +79,15 @@ class graded_users_iterator { return false; } - list($gradebookroles_sql, $params) = $DB->get_in_or_equal(explode(',', $CFG->gradebookroles)); + list($gradebookroles_sql, $params) = $DB->get_in_or_equal(explode(',', $CFG->gradebookroles), SQL_PARAMS_NAMED, 'grbr0'); $relatedcontexts = get_related_contexts_string(get_context_instance(CONTEXT_COURSE, $this->course->id)); if ($this->groupid) { $groupsql = "INNER JOIN {groups_members} gm ON gm.userid = u.id"; - $groupwheresql = "AND gm.groupid = ?"; + $groupwheresql = "AND gm.groupid = :groupid"; // $params contents: gradebookroles - $params[] = $this->groupid; + $params['groupid'] = $this->groupid; } else { $groupsql = ""; $groupwheresql = ""; @@ -126,7 +126,7 @@ class graded_users_iterator { if (!empty($this->grade_items)) { $itemids = array_keys($this->grade_items); - list($itemidsql, $grades_params) = $DB->get_in_or_equal($itemids); + list($itemidsql, $grades_params) = $DB->get_in_or_equal($itemids, SQL_PARAMS_NAMED, 'items0'); $params = array_merge($params, $grades_params); // $params contents: gradebookroles, groupid (for $groupwheresql) and itemids @@ -453,6 +453,14 @@ function print_grade_plugin_selector($courseid, $active_type, $active_plugin, $r $count++; } + if (has_capability('moodle/grade:manage', $context)) { + $url = 'edit/weights/index.php?id='.$courseid; + if ($active_type == 'edit' and $active_plugin == 'weights' ) { + $active = $url; + } + $menu[$url] = get_string('weights', 'grades'); + $count++; + } } /// finally print/return the popup form