Skip to content

Commit

Permalink
Changes to print_recent_activity in course/lib.php. It is now more
Browse files Browse the repository at this point in the history
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
martin committed Sep 21, 2002
1 parent 20aa225 commit 3869a2a
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 47 deletions.
56 changes: 10 additions & 46 deletions course/lib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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; $mods = get_list_of_plugins("mod");
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) { foreach ($mods as $mod) {

include_once("$CFG->dirroot/mod/$mod/lib.php");
$teacherpost = ""; $print_recent_activity = $mod."_print_recent_activity";
if ($forum = get_record("forum", "id", $post->forum) ) { if (function_exists($print_recent_activity)) {
if ($forum->type == "teacher") { $modcontent = $print_recent_activity($logs, isteacher($course->id));
if (!isteacher($course->id)) { if ($modcontent) {
continue; $content = true;
} 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>";
} }

} }
} }



if (! $content) { if (! $content) {
echo "<FONT SIZE=2>".get_string("nothingnew")."</FONT>"; echo "<FONT SIZE=2>".get_string("nothingnew")."</FONT>";
} }
Expand Down
1 change: 1 addition & 0 deletions lang/en/forum.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
$string['namenews'] = "News forum"; $string['namenews'] = "News forum";
$string['namesocial'] = "Social forum"; $string['namesocial'] = "Social forum";
$string['nameteacher'] = "Teacher forum"; $string['nameteacher'] = "Teacher forum";
$string['newforumposts'] = "New forum posts";
$string['nodiscussions'] = "There are no discussion topics yet in this forum"; $string['nodiscussions'] = "There are no discussion topics yet in this forum";
$string['noguestpost'] = "Sorry, guests are not allowed to post"; $string['noguestpost'] = "Sorry, guests are not allowed to post";
$string['noposts'] = "No posts"; $string['noposts'] = "No posts";
Expand Down
1 change: 1 addition & 0 deletions lang/en/journal.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
$string['journalrating1'] = "Not satisfactory"; $string['journalrating1'] = "Not satisfactory";
$string['journalrating2'] = "Satisfactory"; $string['journalrating2'] = "Satisfactory";
$string['journalrating3'] = "Outstanding"; $string['journalrating3'] = "Outstanding";
$string['newjournalentries'] = "New journal entries";
$string['noentry'] = "No entry"; $string['noentry'] = "No entry";
$string['notopenuntil'] = "This journal won't be open until"; $string['notopenuntil'] = "This journal won't be open until";
$string['notstarted'] = "You have not started this journal yet"; $string['notstarted'] = "You have not started this journal yet";
Expand Down
2 changes: 1 addition & 1 deletion lang/en/moodle.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@
$string['nametopics'] = "topic"; $string['nametopics'] = "topic";
$string['nameweeks'] = "week"; $string['nameweeks'] = "week";
$string['newaccount'] = "New account"; $string['newaccount'] = "New account";
$string['newforumposts'] = "New forum posts";
$string['newpassword'] = "New password"; $string['newpassword'] = "New password";
$string['newpasswordtext'] = "Hi \$a->firstname, $string['newpasswordtext'] = "Hi \$a->firstname,
Expand Down Expand Up @@ -423,6 +422,7 @@
$string['upload'] = "Upload"; $string['upload'] = "Upload";
$string['uploadafile'] = "Upload a file"; $string['uploadafile'] = "Upload a file";
$string['uploadthisfile'] = "Upload this file"; $string['uploadthisfile'] = "Upload this file";
$string['userdeleted'] = "This user account has been deleted";
$string['userdescription'] = "Description"; $string['userdescription'] = "Description";
$string['username'] = "Username"; $string['username'] = "Username";
$string['usernameexists'] = "This username already exists, choose another"; $string['usernameexists'] = "This username already exists, choose another";
Expand Down
54 changes: 54 additions & 0 deletions mod/forum/lib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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;
}

?> ?>
38 changes: 38 additions & 0 deletions mod/journal/lib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -123,6 +123,44 @@ function journal_cron () {
return true; 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) { function journal_get_users_done($journal) {
return get_records_sql("SELECT u.* FROM user u, user_students s, user_teachers t, journal_entries j 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 WHERE ((s.course = '$journal->course' AND s.user = u.id) OR
Expand Down

0 comments on commit 3869a2a

Please sign in to comment.