From: martin Date: Sat, 21 Sep 2002 17:11:08 +0000 (+0000) Subject: Changes to print_recent_activity in course/lib.php. It is now more X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=3869a2ac3d0c48ae227c2c40611629528abbc08f;p=moodle.git 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 --- diff --git a/course/lib.php b/course/lib.php index f69d2d0932..519fb077b7 100644 --- a/course/lib.php +++ b/course/lib.php @@ -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 "

$date - $post->firstname $post->lastname
"; - echo "\"wwwroot/mod/forum/$log->url\">"; - if ($log->action == "add") { - echo "$post->subject"; - } else { - echo "$post->subject"; - } - echo "\"

"; + 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 "".get_string("nothingnew").""; } diff --git a/lang/en/forum.php b/lang/en/forum.php index 6b8b9deb7c..80906b5009 100644 --- a/lang/en/forum.php +++ b/lang/en/forum.php @@ -56,6 +56,7 @@ $string['more'] = "more"; $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"; diff --git a/lang/en/journal.php b/lang/en/journal.php index 44f397c2b5..9275c64398 100644 --- a/lang/en/journal.php +++ b/lang/en/journal.php @@ -16,6 +16,7 @@ $string['journalquestion'] = "Journal question"; $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"; diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 23722a1228..a66f5dcdc2 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -277,7 +277,6 @@ $string['namesocial'] = "section"; $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['updatingain'] = "Updating a \$a->what in \$a->in"; $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"; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 0d4fca864e..9ec505d40c 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -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 "

$date - $post->firstname $post->lastname
"; + echo "\"wwwroot/mod/forum/$log->url\">"; + if ($log->action == "add") { + echo "$post->subject"; + } else { + echo "$post->subject"; + } + echo "\"

"; + } + } + } + return $content; +} + ?> diff --git a/mod/journal/lib.php b/mod/journal/lib.php index be3ede06be..3a4dc51cb7 100644 --- a/mod/journal/lib.php +++ b/mod/journal/lib.php @@ -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 "

$date - $journal->firstname $journal->lastname
"; + echo "\"wwwroot/mod/journal/view.php?id=$journal->id\">"; + echo "$journal->name"; + echo "\"

"; + } + } + + 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