Obtain the identifiers of the unread posts

Obtain the identifiers of the unread posts

by David Rodríguez Aguiar -
Number of replies: 0

Hi all:

  First, sorry for my very bad english.

  Looking for in Moodle, I've found a function that returns a array with the number of unread posts to each discussion of a forum. That function is the following:

function forum_count_unread_replies($forum="0") { 

    global $CFG, $USER;

    if ($forum) {
        $forumselect = ' AND d.forum = ''.$forum.''';
    }

    /// First, get a count of all replies to each discussion [of the forum].
    if ($disc_replies = get_records_sql('SELECT p.discussion, (count(*)) as replies '
                                   .'   FROM '.$CFG->prefix.'forum_posts p, '
                                   .'        '.$CFG->prefix.'forum_discussions d '
                                   .'   WHERE p.parent > 0 '
                                   .'       AND p.discussion = d.id '
                                   .$forumselect
                                   .'   GROUP BY p.discussion')) {

        /// Then, go through the logs for each discussion that the user had read, and recount the replies
        /// since that access.
        foreach ($disc_replies as $reply) {
            if ($read_disc = get_record_sql('SELECT l.info AS discussion, MAX(l.time) AS lastread '
                                     .' FROM '.$CFG->prefix.'log l'
                                     .' WHERE l.module = 'forum''
                                     .'     AND l.action =  'view discussion''
                                     .'     AND l.userid = '.$USER->id
                                     .'     AND l.info = ''.$reply->discussion.'''
                                     .' GROUP BY discussion')) {

                $disc_reply = get_record_sql('SELECT p.discussion, (count(*)) as replies '
                                           .'   FROM '.$CFG->prefix.'forum_posts p '
                                           .'   WHERE p.discussion = '.$reply->discussion
                                           .'       AND p.modified > '.$read_disc->lastread
                                           .'   GROUP BY p.discussion');

                $disc_replies[$reply->discussion]->replies = (int)$disc_reply->replies;
            }
        }
    }

 return ($disc_replies);
}

   Right, I'd like someone knows how we can obtain the identifiers of those posts and not only the number. I've tried and I'll come back to try, but it's very complicated for me.

   I'll be always and eternitly thanksful.

David Rguez.

Average of ratings: -