pseudocode for counting "new" posts

pseudocode for counting "new" posts

by Scott Krajewski -
Number of replies: 3
We're going to pull the number of new posts in moodle for a given user to our portal (so that people can see there is activity going on which will entice them too click in to moodle).  Here is what I did in case others want to use it (or to correct me).  I did it in zope since that's what I know best (I don't really know PHP well enough yet).  Here's essentially what happens:

With username
postcount
=0
Loop through
SELECT DISTINCT(mdl_course_display.course)
FROM mdl_course_display,mdl_user
WHERE mdl_user.username=username
AND
mdl_course_display.userid=mdl_user.id

Loop through
SELECT DISTINCT (mdl_forum_posts.id)
FROM mdl_forum_posts,mdl_forum_discussions,mdl_user
WHERE
mdl_forum_posts.discussion=mdl_forum_discussions.id
AND
mdl_user.username=username
mdl_user.lastlogin < mdl_forum_posts.modified
AND
mdl_forum_discussions.course = courseid

If at endofloop
If lengthofloop > 0
postcount = postcount + lengthofloop
End loop
End loop
If postcount > 0, output postcount, else output 0

End With

My actual code looks a little different (the SQL calls are functions) but this gives the general idea.  So far in my testing this outputs the right total.
Average of ratings: -
In reply to Scott Krajewski

Re: pseudocode for counting "new" posts

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Moodle 1.5 has a new feature that keeps track of unread posts ... see the forum_read table.

Simple Moodle code:

$user = get_record('user', 'username', 'fred');
$count = count_records('forum_read', 'userid', $user->id);
In reply to Martin Dougiamas

Re: pseudocode for counting "new" posts

by Colleen McDermid -

I'm using moodle 1.4 is there anyway I can add just the forum_read table without losing any of my previous modifications? As my users are requesting functions that let them see the posts they haven't read.

Thanks, Colleen

In reply to Colleen McDermid

Re: pseudocode for counting "new" posts

by Bill Burgos -
Hi Colleen,

If I am not mistaken, the unread forum post notification will be coming out in version 1.5.