]> git.mjollnir.org Git - moodle.git/commitdiff
Improvements to user activity report - including graphs
authormartin <martin>
Sat, 27 Jul 2002 08:31:09 +0000 (08:31 +0000)
committermartin <martin>
Sat, 27 Jul 2002 08:31:09 +0000 (08:31 +0000)
course/loggraph.php [new file with mode: 0644]
course/user.php

diff --git a/course/loggraph.php b/course/loggraph.php
new file mode 100644 (file)
index 0000000..2a78bbe
--- /dev/null
@@ -0,0 +1,76 @@
+<?PHP // $Id$
+
+    require("../config.php");
+    require("lib.php");
+    require("$CFG->libdir/graphlib.php");
+
+    require_variable($id);    // Course ID
+    require_variable($type);  // Graph Type
+    optional_variable($user);  // Student ID
+
+    if (! $course = get_record("course", "id", $id)) {
+        error("Course is misconfigured");
+    }
+
+    require_login($course->id);
+
+    if (!isteacher($course->id)) {
+        if (! ($type == "student.png" and $user == $USER->id) ) {
+            error("Sorry, you aren't allowed to see this.");
+        }
+    }
+
+    if ($user) {
+        if (! $user = get_record("user", "id", $user)) {
+            error("Can not find that user");
+        }
+    }
+
+
+    $timenow = time();
+
+    switch ($type) {
+
+     case "user.png":
+
+       $timestart = $course->startdate;
+       $i = 0;
+       while ($timestart < $timenow) {
+           $timefinish = $timestart + (3600 * 24);
+           if (! $logcount = get_record_sql("SELECT COUNT(*) as count FROM log
+                                             WHERE user = '$user->id' AND course = '$course->id'
+                                               AND `time` > '$timestart' AND `time` < '$timefinish'")) {
+               $logs[$i] = 0;
+           }
+           $logs[$i] = $logcount->count;
+           $days[$i] = date("j M", $timestart);
+           $i++;
+           $timestart = $timefinish;
+       }
+
+       $maxlogs = max($logs);
+
+
+       $graph = new graph(600, 300);
+       $graph->parameter['title'] = "Rough usage of $course->shortname by $user->firstname $user->lastname";
+
+       $graph->x_data           = $days;
+
+       $graph->y_data['logs']   = $logs;
+       $graph->y_format['logs'] = array('colour' => 'blue','bar' => 'fill','legend' =>'actual','bar_size' => 0.4);
+       $graph->y_label_left     = "Hits";
+
+       $graph->y_order = array('logs');
+
+       
+       $graph->parameter['shadow']          = 'none';
+
+       $graph->draw_stack();
+
+       break;
+
+     default:
+       break;
+   }
+
+?>
index 3dbbeb3a10be6b9f361b2daf81d9f586c8caeedc..8b36da3e69be1e6f057a602f9a959c2b75612bb1 100644 (file)
 
     switch ($mode) {
         case "summary" :
-            echo "<P>Not done yet</P>";
-            echo "<P>Graph goes here that shows accesses by day over the course</P>";
             echo "<HR>";
-            echo "<P>Table goes here that summarises all activity by this student by module. eg 3/7 journals done, 3/3 surveys, 12 posts in all discussions. Each of these are links so that you can drill down to see all the surveys on one page, or all the posts, or all their journals.";
+            echo "<CENTER><IMG SRC=\"loggraph.php?id=$course->id&user=$user->id&type=user.png\">";
+            echo "<HR>";
             break;
 
         case "outline" :