]> git.mjollnir.org Git - moodle.git/commitdiff
Cleaned up definition of constant COURSE_* values in course/lib.php
authormoodler <moodler>
Sat, 26 Apr 2003 12:17:30 +0000 (12:17 +0000)
committermoodler <moodler>
Sat, 26 Apr 2003 12:17:30 +0000 (12:17 +0000)
Moved COURSE_TEACHER_COLOR out to style sheets where it belongs (.teacheronly)

Added some efficiency when printing recent activity

 - don't print more than one weeks worth of updates
  - don't keep re-parsing logs once they've been used

course/lib.php
course/loggraph.php
course/loglive.php
mod/assignment/lib.php
mod/forum/lib.php
mod/journal/lib.php
mod/quiz/lib.php
mod/survey/lib.php

index c869bc056191663e281fa4ebd646d5677f191028..46c2776aa7d93a9790a5b3699a84f2a4fce7c107 100644 (file)
@@ -2,17 +2,17 @@
    // Library of useful functions
 
 
-if (isset($COURSE_MAX_LOG_DISPLAY)) {  // Being included again - should never happen!!
+if (defined('COURSE_MAX_LOG_DISPLAY')) {  // Being included again - should never happen!!
     return;
 }
 
-$COURSE_MAX_LOG_DISPLAY = 150;       // days
+define('COURSE_MAX_LOG_DISPLAY', 150);       // days
 
-$COURSE_MAX_LOGS_PER_PAGE = 1000;    // records
+define('COURSE_MAX_LOGS_PER_PAGE', 1000);    // records
 
-$COURSE_TEACHER_COLOR = "#990000";   // To hilight certain items that are teacher-only
+define('COURSE_LIVELOG_REFRESH', 60);        // Seconds
 
-$COURSE_LIVELOG_REFRESH = 60;        // Seconds
+define('COURSE_MAX_RECENT_PERIOD', 60480);   // A week, in seconds
 
 
 
@@ -118,7 +118,7 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
 // It is assumed that $date is the GMT time of midnight for that day, 
 // and so the next 86400 seconds worth of logs are printed.
 
-    global $CFG, $COURSE_MAX_LOGS_PER_PAGE;
+    global $CFG;
 
     if ($course->category) {
         $selector = "WHERE l.course='$course->id' AND l.userid = u.id";
@@ -150,8 +150,8 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
     $count=0;
     $tt = getdate(time());
     $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
-    if (($totalcountlogs = count($logs)) > $COURSE_MAX_LOGS_PER_PAGE) {
-        $totalcountlogs = "$COURSE_MAX_LOGS_PER_PAGE/$totalcountlogs";
+    if (($totalcountlogs = count($logs)) > COURSE_MAX_LOGS_PER_PAGE) {
+        $totalcountlogs = COURSE_MAX_LOGS_PER_PAGE."/$totalcountlogs";
     }
 
     $strftimedatetime = get_string("strftimedatetime");
@@ -166,7 +166,7 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
 
         $countlogs++;
 
-        if ($countlogs > $COURSE_MAX_LOGS_PER_PAGE) {
+        if ($countlogs > COURSE_MAX_LOGS_PER_PAGE) {
             break;
         }
 
@@ -302,18 +302,23 @@ function print_recent_activity($course) {
     // This function trawls through the logs looking for 
     // anything new since the user's last login
 
-    global $CFG, $USER, $COURSE_TEACHER_COLOR;
+    global $CFG, $USER;
 
     if (! $USER->lastlogin ) {
-        echo "<P ALIGN=CENTER><FONT SIZE=1>";
+        echo "<p align=center><font size=1>";
         print_string("welcometocourse", "", $course->shortname);
-        echo "</FONT></P>";
+        echo "</font></p>";
         return;
     } else {
-        echo "<P ALIGN=CENTER><FONT SIZE=1>";
+        echo "<p align=center><font size=1>";
         echo get_string("yourlastlogin").":<BR>"; 
         echo userdate($USER->lastlogin, get_string("strftimerecentfull"));
-        echo "</FONT></P>";
+        echo "</font></p>";
+    }
+  
+    $timestart = $USER->lastlogin;
+    if (time() - $timestart > COURSE_MAX_RECENT_PERIOD) {
+        $timestart = time() - COURSE_MAX_RECENT_PERIOD;
     }
 
     if (! $logs = get_records_select("log", "time > '$USER->lastlogin' AND course = '$course->id'", "time ASC")) {
@@ -325,7 +330,7 @@ function print_recent_activity($course) {
 
     $heading = false;
     $content = false;
-    foreach ($logs as $log) {
+    foreach ($logs as $key => $log) {
         if ($log->module == "course" and $log->action == "enrol") {
             if (! $heading) {
                 print_headline(get_string("newusers").":");
@@ -334,14 +339,19 @@ function print_recent_activity($course) {
             }
             $user = get_record("user", "id", $log->info);
             if (isstudent($course->id, $user->id)) {
-                echo "<P><FONT SIZE=1><A HREF=\"../user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</A></FONT></P>";
+                echo "<p><font size=1><a href=\"../user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</a></font></p>";
             }
+            unset($logs[$key]);  // No further need for it
         }
     }
 
+    if (! $logs) {
+        return;
+    }
+
     // Next, have there been any changes to the course structure?
 
-    foreach ($logs as $log) {
+    foreach ($logs as $key => $log) {
         if ($log->module == "course") {
             if ($log->action == "add mod" or $log->action == "update mod" or $log->action == "delete mod") {
                 $info = split(" ", $log->info);
@@ -377,6 +387,7 @@ function print_recent_activity($course) {
                     }
                 }
             }
+            unset($logs[$key]);  // No further need for it
         }
     }
 
@@ -390,11 +401,14 @@ function print_recent_activity($course) {
             print_headline(get_string("courseupdates").":");
             $content = true;
             foreach ($changes as $changeinfo => $change) {
-                echo "<P><FONT SIZE=1>".$change["text"]."</FONT></P>";
+                echo "<p><font size=1>".$change["text"]."</font></p>";
             }
         }
     }
 
+    if (! $logs) {
+        return;
+    }
 
     // Now display new things from each module
 
@@ -403,7 +417,7 @@ function print_recent_activity($course) {
     foreach ($mods as $mod) {
         include_once("$CFG->dirroot/mod/$mod/lib.php");
         $print_recent_activity = $mod."_print_recent_activity";
-        if (function_exists($print_recent_activity)) {
+        if ($logs and function_exists($print_recent_activity)) {
             $modcontent = $print_recent_activity($logs, isteacher($course->id));
             if ($modcontent) {
                 $content = true;
@@ -411,9 +425,8 @@ function print_recent_activity($course) {
         }
     }
 
-
     if (! $content) {
-        echo "<FONT SIZE=2>".get_string("nothingnew")."</FONT>";
+        echo "<font size=2>".get_string("nothingnew")."</font>";
     }
 }
 
index ca050de71cfa9778f2e5ff292135f286b9a0bda9..83c3a88e2fde924c893dabcd1b02ac23b87e7d9a 100644 (file)
@@ -34,9 +34,9 @@
     switch ($type) {
      case "usercourse.png":
 
-       $COURSE_MAX_LOG_DISPLAY = $COURSE_MAX_LOG_DISPLAY * 3600 * 24;  // seconds
-       if ($timenow - $course->startdate > $COURSE_MAX_LOG_DISPLAY) {
-           $course->startdate = $timenow - $COURSE_MAX_LOG_DISPLAY;
+       $maxseconds = COURSE_MAX_LOG_DISPLAY * 3600 * 24;  // seconds
+       if ($timenow - $course->startdate > $maxseconds) {
+           $course->startdate = $timenow - $maxseconds;
        }
        $timestart = $coursestart = usergetmidnight($course->startdate);
 
index fd9f8191ecb964fcd8291fa36da4e7629f68b48c..d2a8354760dcded8852c1729264bfa6c637c9f3c 100644 (file)
     }
 
     $strlivelogs = get_string("livelogs");
-    $strupdatesevery = get_string("updatesevery", "moodle", $COURSE_LIVELOG_REFRESH);
+    $strupdatesevery = get_string("updatesevery", "moodle", COURSE_LIVELOG_REFRESH);
 
     print_header("$strlivelogs ($strupdatesevery)", "$strlivelogs", "", "", 
-                 "<META HTTP-EQUIV='Refresh' CONTENT='$COURSE_LIVELOG_REFRESH; URL=loglive.php?id=$id'>");
+                 "<META HTTP-EQUIV='Refresh' CONTENT='".COURSE_LIVELOG_REFRESH."; URL=loglive.php?id=$id'>");
 
     $user=0;
     $date=time() - 3600;
index 5ad21cf8800fa08fa8ca98710707568f5f769571..b5e68c867367271d7f10ef2d558c7164e4bf5f32 100644 (file)
@@ -184,7 +184,7 @@ function assignment_cron () {
 }
 
 function assignment_print_recent_activity(&$logs, $isteacher=false) {
-    global $CFG, $COURSE_TEACHER_COLOR;
+    global $CFG;
 
     $content = false;
     $assignments = NULL;
index 2559d5cd43045cf465d7ce9a997fb530bc085c47..967a3f10f64384c2b5ca3d64de2039a65fb6f46c 100644 (file)
@@ -297,7 +297,7 @@ function forum_user_complete($course, $user, $mod, $forum) {
 }
 
 function forum_print_recent_activity(&$logs, $isteacher=false) {
-    global $CFG, $COURSE_TEACHER_COLOR;
+    global $CFG;
 
     $heading = false;
     $content = false;
@@ -322,7 +322,7 @@ function forum_print_recent_activity(&$logs, $isteacher=false) {
                     if ($forum = get_record("forum", "id", $post->forum) ) {
                         if ($forum->type == "teacher") {
                             if ($isteacher) {
-                                $teacherpost = "COLOR=$COURSE_TEACHER_COLOR";
+                                $teacheronly = "class=\"teacheronly\"";
                             } else {
                                 continue;
                             }
@@ -334,14 +334,14 @@ function forum_print_recent_activity(&$logs, $isteacher=false) {
                         $content = true;
                     }
                     $date = userdate($post->modified, $strftimerecent);
-                    echo "<P><FONT SIZE=1 $teacherpost>$date - $post->firstname $post->lastname<BR>";
-                    echo "\"<A HREF=\"$CFG->wwwroot/mod/forum/$log->url\">";
+                    echo "<p $teacheronly><font size=1>$date - $post->firstname $post->lastname<br>";
+                    echo "\"<a href=\"$CFG->wwwroot/mod/forum/$log->url\">";
                     if ($log->action == "add") {
-                        echo "<B>$post->subject</B>";
+                        echo "<b>$post->subject</b>";
                     } else {
                         echo "$post->subject";
                     }
-                    echo "</A>\"</FONT></P>";
+                    echo "</a>\"</font></p>";
                 }
             }
         }
index 67ed4d4027c4486d180eebfd7fc65d01871067a7..0be5d42d71076a58ddaa26ca61e1327330766276 100644 (file)
@@ -120,7 +120,7 @@ function journal_cron () {
 }
 
 function journal_print_recent_activity(&$logs, $isteacher=false) {
-    global $CFG, $COURSE_TEACHER_COLOR;
+    global $CFG;
 
     $content = false;
     $journals = NULL;
index 5c108b46aab616216f295dbaca27c6e0ed18e659..aefe826e698f115697c53e740be798fb2fba1a93 100644 (file)
@@ -193,7 +193,7 @@ function quiz_print_recent_activity(&$logs, $isteacher=false) {
 /// If isteacher is true then perhaps additional information is printed.
 /// This function is called from course/lib.php: print_recent_activity()
 
-    global $CFG, $COURSE_TEACHER_COLOR;
+    global $CFG;
 
     $content = "";
 
index 5d8143e28cf0fc5ed6c771f9720f77865c6683d7..83b865288cd67e306d7f233c3f8e25daae4b6ecc 100644 (file)
@@ -101,7 +101,7 @@ function survey_user_complete($course, $user, $mod, $survey) {
 }
 
 function survey_print_recent_activity(&$logs, $isteacher=false) {
-    global $CFG, $COURSE_TEACHER_COLOR;
+    global $CFG;
 
     $content = false;
     $surveys = NULL;