]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15680 Began implementing a simple YUI treeview of the grade items in their catego...
authornicolasconnault <nicolasconnault>
Mon, 22 Sep 2008 15:51:27 +0000 (15:51 +0000)
committernicolasconnault <nicolasconnault>
Mon, 22 Sep 2008 15:51:27 +0000 (15:51 +0000)
16 files changed:
grade/edit/weights/ajax.php [new file with mode: 0755]
grade/edit/weights/img/lm.gif [new file with mode: 0644]
grade/edit/weights/img/lmh.gif [new file with mode: 0644]
grade/edit/weights/img/ln.gif [new file with mode: 0644]
grade/edit/weights/img/loading.gif [new file with mode: 0644]
grade/edit/weights/img/lp.gif [new file with mode: 0644]
grade/edit/weights/img/lph.gif [new file with mode: 0644]
grade/edit/weights/img/tm.gif [new file with mode: 0644]
grade/edit/weights/img/tmh.gif [new file with mode: 0644]
grade/edit/weights/img/tn.gif [new file with mode: 0644]
grade/edit/weights/img/tp.gif [new file with mode: 0644]
grade/edit/weights/img/tph.gif [new file with mode: 0644]
grade/edit/weights/img/vline.gif [new file with mode: 0644]
grade/edit/weights/index.php [new file with mode: 0755]
grade/edit/weights/tree.css [new file with mode: 0644]
grade/lib.php

diff --git a/grade/edit/weights/ajax.php b/grade/edit/weights/ajax.php
new file mode 100755 (executable)
index 0000000..393a48f
--- /dev/null
@@ -0,0 +1,60 @@
+<script type="text/javascript">
+//<![CDATA[
+
+// If the mouse is clicked outside this element, the edit is CANCELLED (even if the mouse clicks another grade/feedback cell)
+// If ctrl-arrow is used, or if [tab] or [enter] are pressed, the edit is RECORDED and the row is updated. The previous element returns to normal
+
+YAHOO.namespace("grade_edit_weights");
+YAHOO.grade_edit_weights.courseid = <?php echo $COURSE->id; ?>;
+YAHOO.grade_edit_weights.wwwroot = '<?php echo $CFG->wwwroot; ?>';
+YAHOO.grade_edit_weights.tree = null;
+YAHOO.grade_edit_weights.treedata = <?php echo $tree_json; ?>;
+
+YAHOO.grade_edit_weights.buildTreeNode = function(element, parentNode) {
+    var gew = YAHOO.grade_edit_weights;
+
+    if (parentNode === undefined) {
+        parentNode = gew.tree.getRoot();
+    }
+
+    if (element === undefined) {
+        element = gew.treedata;
+    }
+
+    if (element.item.table == 'grade_categories') {
+        var tmpNode = new YAHOO.widget.TextNode(element.item.name, parentNode, parentNode.isRoot());
+        for (var i = 0; i < element.children.length; i++) {
+            gew.buildTreeNode(element.children[i], tmpNode, false);
+        }
+    } else if (element.item.itemtype == 'mod') {
+        var tmpNode = new YAHOO.widget.TextNode(element.item.name, parentNode, false);
+    }
+};
+
+YAHOO.grade_edit_weights.init = function() {
+    var gew = YAHOO.grade_edit_weights;
+    var div = document.getElementById('weightstree');
+    gew.tree = new YAHOO.widget.TreeView('weightstree');
+
+     //handler for expanding all nodes
+     YAHOO.util.Event.on("expand", "click", function(e) {
+         YAHOO.log("Expanding all TreeView  nodes.", "info", "example");
+         gew.tree.expandAll();
+         YAHOO.util.Event.preventDefault(e);
+     });
+
+     //handler for collapsing all nodes
+     YAHOO.util.Event.on("collapse", "click", function(e) {
+         YAHOO.log("Collapsing all TreeView  nodes.", "info", "example");
+         gew.tree.collapseAll();
+         YAHOO.util.Event.preventDefault(e);
+     });
+
+     gew.buildTreeNode();
+     gew.tree.draw();
+};
+
+YAHOO.util.Event.onDOMReady(YAHOO.grade_edit_weights.init);
+
+// ]]>
+</script>
diff --git a/grade/edit/weights/img/lm.gif b/grade/edit/weights/img/lm.gif
new file mode 100644 (file)
index 0000000..b562300
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 (file)
index 0000000..a17fe23
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 (file)
index 0000000..b7b3e55
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 (file)
index 0000000..0bbf3bc
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 (file)
index 0000000..b9f5485
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 (file)
index 0000000..f663714
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 (file)
index 0000000..56622cc
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 (file)
index 0000000..e42349e
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 (file)
index 0000000..4a28039
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 (file)
index 0000000..906e8c4
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 (file)
index 0000000..8aa7c25
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 (file)
index 0000000..1fb0de8
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 (executable)
index 0000000..6a1ec11
--- /dev/null
@@ -0,0 +1,120 @@
+<?php  // $Id$
+
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.com                                            //
+//                                                                       //
+// Copyright (C) 1999 onwards  Martin Dougiamas  http://moodle.com       //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+require_once '../../../config.php';
+require_once $CFG->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 '<div id="expandcontractdiv">
+       <a id="expand" href="#">Expand all</a>
+           <a id="collapse" href="#">Collapse all</a>
+       </div> ';
+
+echo '<form method="post" action="'.$returnurl.'">';
+echo '<div id="weightstree">';
+
+// print_grade_tree($gtree, $gtree->top_element, $gpr, $switch);
+//
+echo '</div>';
+echo '</form>';
+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 (file)
index 0000000..d704219
--- /dev/null
@@ -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;
+}
index 21234a35881532f171da91d29aacdaee47f57660..319b49aa1a26a09183b33ebd363690060b196cda 100644 (file)
@@ -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