]> git.mjollnir.org Git - moodle.git/commitdiff
Trying a different tack for recent_activity since the old way was
authormoodler <moodler>
Sat, 26 Apr 2003 15:08:34 +0000 (15:08 +0000)
committermoodler <moodler>
Sat, 26 Apr 2003 15:08:34 +0000 (15:08 +0000)
still producing too much data and overflowing PHP memory on busier
sites (eg moodle.org).

Now, there are more database queries, which is unfortunate, but the
data is much more specific, and no sorting needs to be done, so
this is a performance boost.

I don't know how these will cancel out ... my guess is that very
small sites may be very slightly slower on the course page, but
that large sites will be much faster.

Let's see.

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

index 5a68d463670fc56777bae49a60bf09faa788987e..4f975d375e9cf3fbdac9393eac26bbe212fa397b 100644 (file)
@@ -322,21 +322,17 @@ function print_recent_activity($course) {
         $timestart = $timemaxrecent;
     }
 
-    if (! $logs = get_records_select("log", "time > '$timestart' AND ".
-                                            "course = '$course->id' AND ".
-                                            "module <> 'user' AND ".
-                                            "action <> 'view' AND ".
-                                            "action <> 'view all' ", "time ASC")) {
-        return;
-    }
-
 
     // Firstly, have there been any new enrolments?
 
     $heading = false;
     $content = false;
-    foreach ($logs as $key => $log) {
-        if ($log->module == "course" and $log->action == "enrol") {
+
+    $logs = get_records_select("log", "time > '$timestart' AND course = '$course->id' AND 
+                                       module = 'course' AND action = 'enrol'", "time ASC");
+
+    if ($logs) {
+        foreach ($logs as $key => $log) {
             if (! $heading) {
                 print_headline(get_string("newusers").":");
                 $heading = true;
@@ -346,53 +342,48 @@ function print_recent_activity($course) {
             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>";
             }
-            unset($logs[$key]);  // No further need for it
         }
     }
 
-    if (! $logs) {
-        return;
-    }
+    // Next, have there been any modifications to the course structure?
 
-    // Next, have there been any changes to the course structure?
-
-    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);
-                $modname = get_field($info[0], "name", "id", $info[1]);
-                //Create a temp valid module structure (course,id)
-                $tempmod->course = $log->course;
-                $tempmod->id = $info[1];
-                //Obtain the visible property from the instance
-                $modvisible = instance_is_visible($info[0],$tempmod);
-                
-                //Only if the mod is visible
-                if ($modvisible) {
-                    switch ($log->action) {
-                        case "add mod":
-                            $stradded = get_string("added", "moodle", get_string("modulename", $info[0]));
-                            $changelist["$log->info"] = array ("operation" => "add", "text" => "$stradded:<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>");
-                        break;
-                        case "update mod":
-                           $strupdated = get_string("updated", "moodle", get_string("modulename", $info[0]));
-                           if (empty($changelist["$log->info"])) {
-                               $changelist["$log->info"] = array ("operation" => "update", "text" => "$strupdated:<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>");
-                           }
-                        break;
-                        case "delete mod":
-                           if (!empty($changelist["$log->info"]["operation"]) and 
-                                      $changelist["$log->info"]["operation"] == "add") {
-                               $changelist["$log->info"] = NULL;
-                           } else {
-                               $strdeleted = get_string("deletedactivity", "moodle", get_string("modulename", $info[0]));
-                               $changelist["$log->info"] = array ("operation" => "delete", "text" => $strdeleted);
-                           }
-                        break;
-                    }
+    $logs = get_records_select("log", "time > '$timestart' AND course = '$course->id' AND 
+                                       module = 'course' AND action LIKE '% mod'", "time ASC");
+
+    if ($logs) {
+        foreach ($logs as $key => $log) {
+            $info = split(" ", $log->info);
+            $modname = get_field($info[0], "name", "id", $info[1]);
+            //Create a temp valid module structure (course,id)
+            $tempmod->course = $log->course;
+            $tempmod->id = $info[1];
+            //Obtain the visible property from the instance
+            $modvisible = instance_is_visible($info[0],$tempmod);
+            
+            //Only if the mod is visible
+            if ($modvisible) {
+                switch ($log->action) {
+                    case "add mod":
+                        $stradded = get_string("added", "moodle", get_string("modulename", $info[0]));
+                        $changelist["$log->info"] = array ("operation" => "add", "text" => "$stradded:<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>");
+                    break;
+                    case "update mod":
+                       $strupdated = get_string("updated", "moodle", get_string("modulename", $info[0]));
+                       if (empty($changelist["$log->info"])) {
+                           $changelist["$log->info"] = array ("operation" => "update", "text" => "$strupdated:<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>");
+                       }
+                    break;
+                    case "delete mod":
+                       if (!empty($changelist["$log->info"]["operation"]) and 
+                                  $changelist["$log->info"]["operation"] == "add") {
+                           $changelist["$log->info"] = NULL;
+                       } else {
+                           $strdeleted = get_string("deletedactivity", "moodle", get_string("modulename", $info[0]));
+                           $changelist["$log->info"] = array ("operation" => "delete", "text" => $strdeleted);
+                       }
+                    break;
                 }
             }
-            unset($logs[$key]);  // No further need for it
         }
     }
 
@@ -411,19 +402,17 @@ function print_recent_activity($course) {
         }
     }
 
-    if (! $logs) {
-        return;
-    }
-
     // Now display new things from each module
 
     $mods = get_list_of_plugins("mod");
 
-    foreach ($mods as $mod) {
+    $isteacher = isteacher($course->id);
+
+    foreach ($mods as $mod) {      // Each module gets it's own logs and prints them
         include_once("$CFG->dirroot/mod/$mod/lib.php");
         $print_recent_activity = $mod."_print_recent_activity";
-        if ($logs and function_exists($print_recent_activity)) {
-            $modcontent = $print_recent_activity($logs, isteacher($course->id));
+        if (function_exists($print_recent_activity)) {
+            $modcontent = $print_recent_activity($course, $isteacher, $timestart);
             if ($modcontent) {
                 $content = true;
             }
index 3f3031d7e65dc1d26dd09cb563a55fe1ede2d909..100a3d23861916f8c45c0da83b1e05727296b847 100644 (file)
@@ -183,29 +183,31 @@ function assignment_cron () {
     return true;
 }
 
-function assignment_print_recent_activity(&$logs, $isteacher=false) {
+function assignment_print_recent_activity($course, $isteacher, $timestart) {
     global $CFG;
 
     $content = false;
     $assignments = NULL;
 
-    foreach ($logs as $key => $log) {
-        if ($log->module == "assignment") {
-            if ($log->action == "upload") {
-                //Create a temp valid module structure (course,id)
-                $tempmod->course = $log->course;
-                $tempmod->id = $log->info;
-                //Obtain the visible property from the instance
-                $modvisible = instance_is_visible($log->module,$tempmod);
-    
-                //Only if the mod is visible
-                if ($modvisible) {
-                    $assignments[$log->info] = assignment_log_info($log);
-                    $assignments[$log->info]->time = $log->time;
-                    $assignments[$log->info]->url  = $log->url;
-                }
-            }
-            unset($logs[$key]);  // No longer need this record
+    if (!$logs = get_records_select("log", "time > '$timestart' AND ".
+                                           "course = '$course->id' AND ".
+                                           "module = 'assignment' AND ".
+                                           "action = 'upload' ", "time ASC")) {
+        return false;
+    }
+
+    foreach ($logs as $log) {
+        //Create a temp valid module structure (course,id)
+        $tempmod->course = $log->course;
+        $tempmod->id = $log->info;
+        //Obtain the visible property from the instance
+        $modvisible = instance_is_visible($log->module,$tempmod);
+   
+        //Only if the mod is visible
+        if ($modvisible) {
+            $assignments[$log->info] = assignment_log_info($log);
+            $assignments[$log->info]->time = $log->time;
+            $assignments[$log->info]->url  = $log->url;
         }
     }
 
@@ -215,10 +217,10 @@ function assignment_print_recent_activity(&$logs, $isteacher=false) {
         print_headline(get_string("newsubmissions", "assignment").":");
         foreach ($assignments as $assignment) {
             $date = userdate($assignment->time, $strftimerecent);
-            echo "<P><FONT SIZE=1>$date - $assignment->firstname $assignment->lastname<BR>";
-            echo "\"<A HREF=\"$CFG->wwwroot/mod/assignment/$assignment->url\">";
+            echo "<p><font size=1>$date - $assignment->firstname $assignment->lastname<br>";
+            echo "\"<a href=\"$CFG->wwwroot/mod/assignment/$assignment->url\">";
             echo "$assignment->name";
-            echo "</A>\"</FONT></P>";
+            echo "</a>\"</font></p>";
         }
     }
  
index 72ada4c436105cb7df7b578b5a3db2b7f2c45c2f..d8a8c58a3394508228ad5cb5f06ae0667aba01bd 100644 (file)
@@ -296,59 +296,62 @@ function forum_user_complete($course, $user, $mod, $forum) {
     }
 }
 
-function forum_print_recent_activity(&$logs, $isteacher=false) {
+function forum_print_recent_activity($course, $isteacher, $timestart) {
     global $CFG;
 
     $heading = false;
     $content = false;
 
+    if (!$logs = get_records_select("log", "time > '$timestart' AND ".
+                                           "course = '$course->id' AND ".
+                                           "module = 'forum' AND ".
+                                           "action LIKE 'add %' ", "time ASC")){
+        return false;
+    }
+
     $strftimerecent = get_string("strftimerecent");
 
-    foreach ($logs as $key => $log) {
-        if ($log->module == "forum") {
-            if ($log->action == "add post" or $log->action == "add discussion") {
-                //Get post info, I'll need it later
-                $post = forum_get_post_from_log($log);
-    
-                //Create a temp valid module structure (course,id)
-                $tempmod->course = $log->course;
-                $tempmod->id = $post->forum;
-                //Obtain the visible property from the instance
-                $modvisible = instance_is_visible($log->module,$tempmod);
-    
-                //Only if the mod is visible
-                if ($modvisible) {
-                    if ($post) {
-                        $teacheronly = "";
-                        if ($forum = get_record("forum", "id", $post->forum) ) {
-                            if ($forum->type == "teacher") {
-                                if ($isteacher) {
-                                    $teacheronly = "class=\"teacheronly\"";
-                                } else {
-                                    continue;
-                                }
-                            }
-                        }
-                        if (! $heading) {
-                            print_headline(get_string("newforumposts", "forum").":");
-                            $heading = true;
-                            $content = true;
-                        }
-                        $date = userdate($post->modified, $strftimerecent);
-                        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 discussion") {
-                            echo "<b>$post->subject</b>";
+    foreach ($logs as $log) {
+        //Get post info, I'll need it later
+        $post = forum_get_post_from_log($log);
+   
+        //Create a temp valid module structure (course,id)
+        $tempmod->course = $log->course;
+        $tempmod->id = $post->forum;
+        //Obtain the visible property from the instance
+        $modvisible = instance_is_visible($log->module,$tempmod);
+  
+        //Only if the mod is visible
+        if ($modvisible) {
+            if ($post) {
+                $teacheronly = "";
+                if ($forum = get_record("forum", "id", $post->forum) ) {
+                    if ($forum->type == "teacher") {
+                        if ($isteacher) {
+                            $teacheronly = "class=\"teacheronly\"";
                         } else {
-                            echo "$post->subject";
+                            continue;
                         }
-                        echo "</a>\"</font></p>";
                     }
                 }
+                if (! $heading) {
+                    print_headline(get_string("newforumposts", "forum").":");
+                    $heading = true;
+                    $content = true;
+                }
+                $date = userdate($post->modified, $strftimerecent);
+                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 discussion") {
+                    echo "<b>$post->subject</b>";
+                } else {
+                    echo "$post->subject";
+                }
+                echo "</a>\"</font></p>";
             }
-            unset($logs[$key]);  // No longer need this record
         }
     }
+
     return $content;
 }
 
index f932e27a682b849aa266d6e38d0d1d8663ae6041..0826c3b70677543f6c3eedab8cf4c91b6416a975 100644 (file)
@@ -119,34 +119,36 @@ function journal_cron () {
     return true;
 }
 
-function journal_print_recent_activity(&$logs, $isteacher=false) {
+function journal_print_recent_activity($course, $isteacher, $timestart) {
     global $CFG;
 
     $content = false;
     $journals = NULL;
 
-    foreach ($logs as $key => $log) {
-        if ($log->module == "journal") {
-            if ($log->action == "add entry" or $log->action == "update entry") {
-                ///Get journal info.  I'll need it later
-                $j_log_info = journal_log_info($log);
-
-                //Create a temp valid module structure (course,id)
-                $tempmod->course = $log->course;
-                $tempmod->id = $j_log_info->id;
-                //Obtain the visible property from the instance
-                $modvisible = instance_is_visible($log->module,$tempmod);
-
-                //Only if the mod is visible
-                if ($modvisible) {
-                    if (!isset($journals[$log->info])) {
-                        $journals[$log->info] = $j_log_info;
-                        $journals[$log->info]->time = $log->time;
-                        $journals[$log->info]->url = $log->url;
-                    }
-                }
+    if (!$logs = get_records_select("log", "time > '$timestart' AND ".
+                                           "course = '$course->id' AND ".
+                                           "module = 'journal' AND ".
+                                           "(action = 'add entry' OR action = 'update entry')", "time ASC")){
+        return false;
+    }
+
+    foreach ($logs as $log) {
+        ///Get journal info.  I'll need it later
+        $j_log_info = journal_log_info($log);
+
+        //Create a temp valid module structure (course,id)
+        $tempmod->course = $log->course;
+        $tempmod->id = $j_log_info->id;
+        //Obtain the visible property from the instance
+        $modvisible = instance_is_visible($log->module,$tempmod);
+
+        //Only if the mod is visible
+        if ($modvisible) {
+            if (!isset($journals[$log->info])) {
+                $journals[$log->info] = $j_log_info;
+                $journals[$log->info]->time = $log->time;
+                $journals[$log->info]->url = $log->url;
             }
-            unset($logs[$key]);  // No longer need this record
         }
     }
 
@@ -156,10 +158,10 @@ function journal_print_recent_activity(&$logs, $isteacher=false) {
         print_headline(get_string("newjournalentries", "journal").":");
         foreach ($journals as $journal) {
             $date = userdate($journal->time, $strftimerecent);
-            echo "<P><FONT SIZE=1>$date - $journal->firstname $journal->lastname<BR>";
-            echo "\"<A HREF=\"$CFG->wwwroot/mod/journal/$journal->url\">";
+            echo "<p><font size=1>$date - $journal->firstname $journal->lastname<br>";
+            echo "\"<a href=\"$CFG->wwwroot/mod/journal/$journal->url\">";
             echo "$journal->name";
-            echo "</A>\"</FONT></P>";
+            echo "</a>\"</font></p>";
         }
     }
  
index aefe826e698f115697c53e740be798fb2fba1a93..effd244ef1ae9873b2d1a9e273c206b5ff657f1c 100644 (file)
@@ -187,19 +187,6 @@ function quiz_user_complete($course, $user, $mod, $quiz) {
     return true;
 }
 
-function quiz_print_recent_activity(&$logs, $isteacher=false) {
-/// Given a list of logs, assumed to be those since the last login 
-/// this function prints a short list of changes related to this module
-/// If isteacher is true then perhaps additional information is printed.
-/// This function is called from course/lib.php: print_recent_activity()
-
-    global $CFG;
-
-    $content = "";
-
-    return $content;  // True if anything was printed, otherwise false
-}
-
 function quiz_cron () {
 /// Function to be run periodically according to the moodle cron
 /// This function searches for things that need to be done, such 
index 406d51d2e284f8ab8829b765fea045cf501f8ced..119c7e4efa2b522fde9f3ee9214da7693ed3f9d4 100644 (file)
@@ -100,29 +100,31 @@ function survey_user_complete($course, $user, $mod, $survey) {
     }
 }
 
-function survey_print_recent_activity(&$logs, $isteacher=false) {
+function survey_print_recent_activity($course, $isteacher, $timestart) {
     global $CFG;
 
     $content = false;
     $surveys = NULL;
 
-    foreach ($logs as $key => $log) {
-        if ($log->module == "survey") {
-            if ($log->action == "submit") {
-                //Create a temp valid module structure (course,id)
-                $tempmod->course = $log->course;
-                $tempmod->id = $log->info;
-                //Obtain the visible property from the instance
-                $modvisible = instance_is_visible($log->module,$tempmod);
-    
-                //Only if the mod is visible
-                if ($modvisible) {
-                    $surveys[$log->id] = survey_log_info($log);
-                    $surveys[$log->id]->time = $log->time;
-                    $surveys[$log->id]->url = $log->url;
-                }
-            }
-            unset($logs[$key]);  // No longer need this record
+    if (!$logs = get_records_select("log", "time > '$timestart' AND ".
+                                           "course = '$course->id' AND ".
+                                           "module = 'survey' AND ".
+                                           "action = 'submit' ", "time ASC")) {
+        return false;
+    }
+
+    foreach ($logs as $log) {
+        //Create a temp valid module structure (course,id)
+        $tempmod->course = $log->course;
+        $tempmod->id = $log->info;
+        //Obtain the visible property from the instance
+        $modvisible = instance_is_visible($log->module,$tempmod);
+   
+        //Only if the mod is visible
+        if ($modvisible) {
+            $surveys[$log->id] = survey_log_info($log);
+            $surveys[$log->id]->time = $log->time;
+            $surveys[$log->id]->url = $log->url;
         }
     }
 
@@ -132,10 +134,10 @@ function survey_print_recent_activity(&$logs, $isteacher=false) {
         print_headline(get_string("newsurveyresponses", "survey").":");
         foreach ($surveys as $survey) {
             $date = userdate($survey->time, $strftimerecent);
-            echo "<P><FONT SIZE=1>$date - $survey->firstname $survey->lastname<BR>";
-            echo "\"<A HREF=\"$CFG->wwwroot/mod/survey/$survey->url\">";
+            echo "<p><font size=1>$date - $survey->firstname $survey->lastname<br>";
+            echo "\"<a href=\"$CFG->wwwroot/mod/survey/$survey->url\">";
             echo "$survey->name";
-            echo "</A>\"</FONT></P>";
+            echo "</a>\"</font></p>";
         }
     }