]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9137 Added the overview report
authornicolasconnault <nicolasconnault>
Fri, 10 Aug 2007 09:34:50 +0000 (09:34 +0000)
committernicolasconnault <nicolasconnault>
Fri, 10 Aug 2007 09:34:50 +0000 (09:34 +0000)
grade/report/overview/db/access.php [new file with mode: 0644]
grade/report/overview/index.php [new file with mode: 0644]
grade/report/overview/lib.php [new file with mode: 0644]
grade/report/overview/version.php [new file with mode: 0644]

diff --git a/grade/report/overview/db/access.php b/grade/report/overview/db/access.php
new file mode 100644 (file)
index 0000000..e2a2e24
--- /dev/null
@@ -0,0 +1,18 @@
+<?php  // $Id$
+
+$gradereport_overview_capabilities = array(
+
+    'gradereport/outcomes:view' => array(
+        'riskbitmask' => RISK_PERSONAL,
+        'captype' => 'read',
+        'contextlevel' => CONTEXT_COURSE,
+        'legacy' => array(
+            'teacher' => CAP_ALLOW,
+            'editingteacher' => CAP_ALLOW,
+            'admin' => CAP_ALLOW
+        )
+    )
+
+);
+
+?>
diff --git a/grade/report/overview/index.php b/grade/report/overview/index.php
new file mode 100644 (file)
index 0000000..6ec4446
--- /dev/null
@@ -0,0 +1,106 @@
+<?php // $Id$
+
+///////////////////////////////////////////////////////////////////////////
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.org                                            //
+//                                                                       //
+// 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->libdir.'/gradelib.php';
+require_once $CFG->dirroot.'/grade/lib.php';
+require_once $CFG->dirroot.'/grade/report/overview/lib.php';
+
+$userid   = optional_param('userid', $USER->id, PARAM_INT);
+
+/// basic access checks
+if (!$course = get_record('course', 'id', $COURSE->id)) {
+    print_error('nocourseid');
+}
+require_login($course);
+
+if (!$user = get_complete_user_data('id', $userid)) {
+    error("Incorrect userid");
+}
+
+$context     = get_context_instance(CONTEXT_COURSE, $course->id);
+$usercontext = get_context_instance(CONTEXT_PERSONAL, $user->id);
+require_capability('gradereport/overview:view', $context);
+
+$access = true;
+if (has_capability('moodle/grade:viewall', $context)) {
+    //ok - can view all course grades
+
+} else if ($user->id == $USER->id and has_capability('moodle/grade:view', $context) and $course->showgrades) {
+    //ok - can view own grades
+
+} else if (has_capability('moodle/grade:view', $usercontext) and $course->showgrades) {
+    // ok - can view grades of this user- parent most probably
+
+} else {
+    $acces = false;
+}
+
+/// return tracking object
+$gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'user', 'courseid'=>$course->id, 'userid'=>$userid));
+
+/// last selected report session tracking
+if (!isset($USER->grade_last_report)) {
+    $USER->grade_last_report = array();
+}
+$USER->grade_last_report[$course->id] = 'user';
+
+/// Build navigation
+$strgrades  = get_string('grades');
+$reportname = get_string('modulename', 'gradereport_overview');
+
+$navigation = grade_build_nav(__FILE__, $reportname, $course->id);
+
+/// Print header
+print_header_simple($strgrades.': '.$reportname, ': '.$strgrades, $navigation,
+                    '', '', true, '', navmenu($course));
+
+/// Print the plugin selector at the top
+print_grade_plugin_selector($course->id, 'report', 'user');
+
+if ($access) {
+
+    //first make sure we have proper final grades - this must be done before constructing of the grade tree
+    grade_regrade_final_grades($course->id);
+
+    // Create a report instance
+    $report = new grade_report_overview($userid, $gpr, $context);
+
+    $gradetotal = 0;
+    $gradesum = 0;
+
+    // print the page
+    print_heading(get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user));
+
+    if ($report->fill_table()) {
+        echo $report->print_table(true);
+    }
+
+} else {
+    // no access to grades!
+    echo "Can not view grades."; //TODO: localize
+}
+print_footer($course);
+
+?>
diff --git a/grade/report/overview/lib.php b/grade/report/overview/lib.php
new file mode 100644 (file)
index 0000000..82f36cb
--- /dev/null
@@ -0,0 +1,139 @@
+<?php // $Id$
+/**
+ * File in which the overview_report class is defined.
+ * @package gradebook
+ */
+
+require_once($CFG->dirroot . '/grade/report/lib.php');
+require_once($CFG->libdir.'/tablelib.php');
+
+/**
+ * Class providing an API for the overview report building and displaying.
+ * @uses grade_report
+ * @package gradebook
+ */
+class grade_report_overview extends grade_report {
+
+    /**
+     * The user.
+     * @var object $user
+     */
+    var $user;
+
+    /**
+     * A flexitable to hold the data.
+     * @var object $table
+     */
+    var $table;
+
+    /**
+     * Constructor. Sets local copies of user preferences and initialises grade_tree.
+     * @param int $userid
+     * @param object $gpr grade plugin return tracking object
+     * @param string $context
+     */
+    function grade_report_overview($userid, $gpr, $context) {
+        global $CFG, $COURSE;
+        parent::grade_report($COURSE->id, $gpr, $context);
+
+        // get the user (for full name)
+        $this->user = get_record('user', 'id', $userid);
+
+        // base url for sorting by first/last name
+        $this->baseurl = $CFG->wwwroot.'/grade/overview/index.php?id='.$userid;
+        $this->pbarurl = $this->baseurl;
+
+        $this->setup_table();
+    }
+
+    /**
+     * Prepares the headers and attributes of the flexitable.
+     */
+    function setup_table() {
+        /*
+        * Table has 3 columns
+        *| course  | final grade | rank |
+        */
+
+        // setting up table headers
+        $tablecolumns = array('coursename', 'grade', 'rank');
+        $tableheaders = array($this->get_lang_string('coursename', 'grades'),
+                              $this->get_lang_string('grade'),
+                              $this->get_lang_string('rank', 'grades'));
+
+        $this->table = new flexible_table('grade-report-overview-'.$this->user->id);
+
+        $this->table->define_columns($tablecolumns);
+        $this->table->define_headers($tableheaders);
+        $this->table->define_baseurl($this->baseurl);
+
+        $this->table->set_attribute('cellspacing', '0');
+        $this->table->set_attribute('id', 'overview-grade');
+        $this->table->set_attribute('class', 'boxaligncenter generaltable');
+
+        $this->table->setup();
+    }
+
+    function fill_table() {
+        global $CFG;
+        $numusers = $this->get_numusers();
+
+        if ($courses = get_courses('all', null, 'c.id, c.shortname')) {
+            foreach ($courses as $course) {
+                // Get course grade_item
+                $grade_item_id = get_field('grade_items', 'id', 'itemtype', 'course', 'courseid', $course->id);
+
+                // Get the grade
+                $finalgrade = get_field('grade_grades', 'finalgrade', 'itemid', $grade_item_id, 'userid', $this->user->id);
+
+                /// prints rank
+                if ($finalgrade) {
+                    /// find the number of users with a higher grade
+                    $sql = "SELECT COUNT(DISTINCT(userid))
+                            FROM {$CFG->prefix}grade_grades
+                            WHERE finalgrade > $finalgrade
+                            AND itemid = $grade_item_id";
+                    $rank = count_records_sql($sql) + 1;
+
+                    $rankdata = "$rank/$numusers";
+                } else {
+                    // no grade, no rank
+                    $rankdata = "-";
+                }
+
+                $this->table->add_data(array($course->shortname, $finalgrade, $rankdata));
+            }
+
+            return true;
+        } else {
+            notify(get_string('nocourses', 'grades'));
+            return false;
+        }
+    }
+
+    /**
+     * Prints or returns the HTML from the flexitable.
+     * @param bool $return Whether or not to return the data instead of printing it directly.
+     * @return string
+     */
+    function print_table($return=false) {
+        ob_start();
+        $this->table->print_html();
+        $html = ob_get_clean();
+        if ($return) {
+            return $html;
+        } else {
+            echo $html;
+        }
+    }
+
+    /**
+     * Processes the data sent by the form (grades and feedbacks).
+     * @var array $data
+     * @return bool Success or Failure (array of errors).
+     */
+    function process_data($data) {
+    }
+
+}
+?>
diff --git a/grade/report/overview/version.php b/grade/report/overview/version.php
new file mode 100644 (file)
index 0000000..83613c9
--- /dev/null
@@ -0,0 +1,6 @@
+<?PHP // $Id$
+
+$plugin->version  = 2007073000;
+$plugin->requires = 2007072402;
+
+?>