Permalink
Browse files

Changes to print_recent_activity in course/lib.php. It is now more

modular (at slight cost to performance) and every modules can now
have a module_print_recent_activity() function.  This function
takes a list of logs, searches for things to display and does so.

So far I've done forum and journal functions
  • Loading branch information...
1 parent 20aa225 commit 3869a2ac3d0c48ae227c2c40611629528abbc08f martin committed Sep 21, 2002
Showing with 105 additions and 47 deletions.
  1. +10 −46 course/lib.php
  2. +1 −0 lang/en/forum.php
  3. +1 −0 lang/en/journal.php
  4. +1 −1 lang/en/moodle.php
  5. +54 −0 mod/forum/lib.php
  6. +38 −0 mod/journal/lib.php
View
@@ -360,58 +360,22 @@ function print_recent_activity($course) {
}
- // Now all we need to know are the new posts.
+ // Now display new things from each module
- $heading = false;
- foreach ($logs as $log) {
-
- if ($log->module == "forum") {
- $post = NULL;
-
- if ($log->action == "add post") {
- $post = get_record_sql("SELECT p.*, d.forum, u.firstname, u.lastname,
- u.email, u.picture, u.id as userid
- FROM forum_discussions d, forum_posts p, user u
- WHERE p.id = '$log->info' AND d.id = p.discussion AND p.user = u.id");
-
- } else if ($log->action == "add discussion") {
- $post = get_record_sql("SELECT p.*, d.forum, u.firstname, u.lastname,
- u.email, u.picture, u.id as userid
- FROM forum_discussions d, forum_posts p, user u
- WHERE d.id = '$log->info' AND d.firstpost = p.id AND p.user = u.id");
- }
+ $mods = get_list_of_plugins("mod");
- if ($post) {
-
- $teacherpost = "";
- if ($forum = get_record("forum", "id", $post->forum) ) {
- if ($forum->type == "teacher") {
- if (!isteacher($course->id)) {
- continue;
- } else {
- $teacherpost = "COLOR=$COURSE_TEACHER_COLOR";
- }
- }
- }
- if (! $heading) {
- print_headline(get_string("newforumposts").":");
- $heading = true;
- $content = true;
- }
- $date = userdate($post->modified, "%e %b, %H:%M");
- echo "<P><FONT SIZE=1 $teacherpost>$date - $post->firstname $post->lastname<BR>";
- echo "\"<A HREF=\"$CFG->wwwroot/mod/forum/$log->url\">";
- if ($log->action == "add") {
- echo "<B>$post->subject</B>";
- } else {
- echo "$post->subject";
- }
- echo "</A>\"</FONT></P>";
+ 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)) {
+ $modcontent = $print_recent_activity($logs, isteacher($course->id));
+ if ($modcontent) {
+ $content = true;
}
-
}
}
+
if (! $content) {
echo "<FONT SIZE=2>".get_string("nothingnew")."</FONT>";
}
View
@@ -56,6 +56,7 @@
$string['namenews'] = "News forum";
$string['namesocial'] = "Social forum";
$string['nameteacher'] = "Teacher forum";
+$string['newforumposts'] = "New forum posts";
$string['nodiscussions'] = "There are no discussion topics yet in this forum";
$string['noguestpost'] = "Sorry, guests are not allowed to post";
$string['noposts'] = "No posts";
View
@@ -16,6 +16,7 @@
$string['journalrating1'] = "Not satisfactory";
$string['journalrating2'] = "Satisfactory";
$string['journalrating3'] = "Outstanding";
+$string['newjournalentries'] = "New journal entries";
$string['noentry'] = "No entry";
$string['notopenuntil'] = "This journal won't be open until";
$string['notstarted'] = "You have not started this journal yet";
View
@@ -277,7 +277,6 @@
$string['nametopics'] = "topic";
$string['nameweeks'] = "week";
$string['newaccount'] = "New account";
-$string['newforumposts'] = "New forum posts";
$string['newpassword'] = "New password";
$string['newpasswordtext'] = "Hi \$a->firstname,
@@ -423,6 +422,7 @@
$string['upload'] = "Upload";
$string['uploadafile'] = "Upload a file";
$string['uploadthisfile'] = "Upload this file";
+$string['userdeleted'] = "This user account has been deleted";
$string['userdescription'] = "Description";
$string['username'] = "Username";
$string['usernameexists'] = "This username already exists, choose another";
View
@@ -1283,4 +1283,58 @@ function forum_set_display_mode($mode=0) {
}
}
+function forum_print_recent_activity(&$logs, $isteacher=false) {
+ global $CFG, $COURSE_TEACHER_COLOR;
+
+ $heading = false;
+ $content = false;
+
+ foreach ($logs as $log) {
+ if ($log->module == "forum") {
+ $post = NULL;
+
+ if ($log->action == "add post") {
+ $post = get_record_sql("SELECT p.*, d.forum, u.firstname, u.lastname,
+ u.email, u.picture, u.id as userid
+ FROM forum_discussions d, forum_posts p, user u
+ WHERE p.id = '$log->info' AND d.id = p.discussion AND p.user = u.id");
+
+ } else if ($log->action == "add discussion") {
+ $post = get_record_sql("SELECT p.*, d.forum, u.firstname, u.lastname,
+ u.email, u.picture, u.id as userid
+ FROM forum_discussions d, forum_posts p, user u
+ WHERE d.id = '$log->info' AND d.firstpost = p.id AND p.user = u.id");
+ }
+
+ if ($post) {
+ $teacherpost = "";
+ if ($forum = get_record("forum", "id", $post->forum) ) {
+ if ($forum->type == "teacher") {
+ if ($isteacher) {
+ continue;
+ } else {
+ $teacherpost = "COLOR=$COURSE_TEACHER_COLOR";
+ }
+ }
+ }
+ if (! $heading) {
+ print_headline(get_string("newforumposts", "forum").":");
+ $heading = true;
+ $content = true;
+ }
+ $date = userdate($post->modified, "%e %b, %H:%M");
+ echo "<P><FONT SIZE=1 $teacherpost>$date - $post->firstname $post->lastname<BR>";
+ echo "\"<A HREF=\"$CFG->wwwroot/mod/forum/$log->url\">";
+ if ($log->action == "add") {
+ echo "<B>$post->subject</B>";
+ } else {
+ echo "$post->subject";
+ }
+ echo "</A>\"</FONT></P>";
+ }
+ }
+ }
+ return $content;
+}
+
?>
View
@@ -123,6 +123,44 @@ function journal_cron () {
return true;
}
+function journal_print_recent_activity(&$logs, $isteacher=false) {
+ global $CFG, $COURSE_TEACHER_COLOR;
+
+ $content = false;
+ $journals = NULL;
+
+ foreach ($logs as $log) {
+ if ($log->module == "journal") {
+ if ($log->action == "add entry" or $log->action == "update entry") {
+ if (!isset($journals[$log->info])) {
+ $journals[$log->info] = get_record_sql("SELECT j.*, u.firstname, u.lastname
+ FROM journal j, journal_entries e, user u
+ WHERE e.id = '$log->info' AND e.journal = j.id
+ AND e.user = u.id");
+ $journals[$log->info]->time = $log->time;
+ }
+ }
+ }
+ }
+
+ if ($journals) {
+ $content = true;
+ print_headline(get_string("newjournalentries", "journal").":");
+ foreach ($journals as $journal) {
+ $date = userdate($journal->time, "%e %b, %H:%M");
+ echo "<P><FONT SIZE=1>$date - $journal->firstname $journal->lastname<BR>";
+ echo "\"<A HREF=\"$CFG->wwwroot/mod/journal/view.php?id=$journal->id\">";
+ echo "$journal->name";
+ echo "</A>\"</FONT></P>";
+ }
+ }
+
+ return $content;
+}
+
+// End of standard module functions
+
+
function journal_get_users_done($journal) {
return get_records_sql("SELECT u.* FROM user u, user_students s, user_teachers t, journal_entries j
WHERE ((s.course = '$journal->course' AND s.user = u.id) OR

0 comments on commit 3869a2a

Please sign in to comment.