General developer forum

unread posts in moodle

 
 
Picture of Leen Q.
unread posts in moodle
 
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: -
Davo
Re: unread posts in moodle
Group DevelopersGroup Particularly helpful Moodlers

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)
Picture of Leen Q.
Re: unread posts in moodle
 
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


 
Average of ratings: -
Picture of Leen Q.
Re: unread posts in moodle
 
Ok,, Done .. thanks a lot smile


 
Average of ratings: -
My ugly mug
Re: unread posts in moodle
Group DevelopersGroup Moodle Course Creator Certificate holdersGroup Moodle HQGroup Particularly helpful MoodlersGroup Testers

You might want to look into the Unanswered Discussions block, or at least the code in that, if you're putting something together yourself.

 
Average of ratings: -