public function get_unread_count_for_discussion_ids(stdClass $user, array $discussionids, bool $canseeprivatereplies) : array {
        global $CFG;

        if (empty($discussionids)) {
            return [];
        }

        [
            'where' => $privatewhere,
            'params' => $privateparams,
        ] = $this->get_private_reply_sql($user, $canseeprivatereplies);

        $alias = $this->get_table_alias();
        list($insql, $params) = $this->get_db()->get_in_or_equal($discussionids, SQL_PARAMS_NAMED);
        $sql = "SELECT p.discussion, COUNT(p.id) FROM {" . self::TABLE . "} p
             LEFT JOIN {forum_read} r ON r.postid = p.id AND r.userid = :userid
                 WHERE p.discussion {$insql} AND p.modified > :cutofftime AND r.id IS NULL {$privatewhere}
              GROUP BY p.discussion";

        $params['userid'] = $user->id;
        $params['cutofftime'] = floor((new \DateTime())
            ->sub(new \DateInterval("P{$CFG->forum_oldpostdays}D"))
            ->format('U') / 60) * 60;

        return $this->get_db()->get_records_sql_menu($sql, array_merge($params, $privateparams));
    }
public function get_unread_count_for_discussion_ids(stdClass $user, array $discussionids, bool $canseeprivatereplies) : array {
        global $CFG;

        if (empty($discussionids)) {
            return [];
        }

        [
            'where' => $privatewhere,
            'params' => $privateparams,
        ] = $this->get_private_reply_sql($user, $canseeprivatereplies);

        $alias = $this->get_table_alias();
        list($insql, $params) = $this->get_db()->get_in_or_equal($discussionids, SQL_PARAMS_NAMED);
        $sql = "SELECT p.discussion, COUNT(p.id) FROM {" . self::TABLE . "} p
             LEFT JOIN {forum_read} r ON r.postid = p.id AND r.userid = :userid
                 WHERE p.discussion {$insql} AND p.modified > :cutofftime AND r.id IS NULL {$privatewhere}
              GROUP BY p.discussion";

        $params['userid'] = $user->id;
        $params['cutofftime'] = floor((new \DateTime())
            ->sub(new \DateInterval("P{$CFG->forum_oldpostdays}D"))
            ->format('U') / 60) * 60;

        return $this->get_db()->get_records_sql_menu($sql, array_merge($params, $privateparams));
    }
public function get_unread_count_for_discussion_ids ( stdClass $ user , array $ discussionids , bool $ canseeprivatereplies ) : array { global $ CFG ; if ( empty ( $ discussionids ) ) { return [ ] ; } [ 'where' => $ privatewhere , 'params' => $ privateparams , ] = $ this -> get_private_reply_sql ( $ user , $ canseeprivatereplies ) ; $ alias = $ this -> get_table_alias ( ) ; list ( $ insql , $ params ) = $ this -> get_db ( ) -> get_in_or_equal ( $ discussionids , SQL_PARAMS_NAMED ) ; $ sql = "SELECT p.discussion, COUNT(p.id) FROM {" . self :: TABLE . "} p
             LEFT JOIN {forum_read} r ON r.postid = p.id AND r.userid = :userid
                 WHERE p.discussion {$insql} AND p.modified > :cutofftime AND r.id IS NULL {$privatewhere}
              GROUP BY p.discussion" ; $ params [ 'userid' ] = $ user -> id ; $ params [ 'cutofftime' ] = floor ( ( new \ DateTime ( ) ) -> sub ( new \ DateInterval ( "P{$CFG->forum_oldpostdays}D" ) ) -> format ( 'U' ) / 60 ) * 60 ; return $ this -> get_db ( ) -> get_records_sql_menu ( $ sql , array_merge ( $ params , $ privateparams ) ) ; }
Get a mapping of unread post counts for the specified discussions.

@param   stdClass    $user The user to fetch counts for
@param   int[]       $discussionids The list of discussions to fetch counts for
@param   bool        $canseeprivatereplies Whether this user can see all private replies or not
@return  int[]       The count of unread posts for each discussion returned in an associative array
Get a mapping of unread post counts for the specified discussions .