unread posts in moodle

unread posts in moodle

by Leen Q. -
Number of replies: 4
Hello all, 

I'm trying to get the unread posts of each enrolled course (Since last login) and found the unread posts in the forum inside  that course  (new and old unread posts )

I used the following functions:

1. to get the unread posts in course: 
forum_tp_get_course_unread_posts($userid, $courseid);

2. to get the unread posts for forum in that course:
forum_tp_is_post_read($userid, $post);

but after the testing I found that they are not accurate
are there better functions for this target? 

what about forum_tp_count_forum_unread_posts($cm, $course); ? 
I couldn't use it because I don't know how I can get $cm object  :'(

Waiting for your help shy

Best regards, 



Average of ratings: -
In reply to Leen Q.

Re: unread posts in moodle

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

In what way is the forum posts count not accurate? 

Does it miss out some posts? 

Does it fail to take into account some posts that have been read?

$cm objects are easy to get:

$modinfo = get_fast_modinfo($course);

$forumcms = $modinfo->get_instances_of('forum');

foreach ($forumcms as $cm) {

// Do something with each forum $cm

}

Average of ratings: Useful (2)
In reply to Davo Smith

Re: unread posts in moodle

by Leen Q. -
Ok, thanks a lot

about your question,  it's not accurate in sometimes only

especially when I try to display unread or read posts

it view some posts (not all) as unread while its read or vice versa  (when I check by forum_tp_is_post_read($userid, $post);)

and display the counter less than that appears on moodle system (when I used forum_tp_get_course_unread_posts($userid, $courseid);)

for example the unread posts in news and common forums was 4, this method returned 3 only

I'm trying to find another way to discover the problem , I checked my code it's ok

but I think to rewrite it again to fix this error

so, I need your help