/** * Obtain all flagged discussions in the forum by the given or current user, * The results should be ordered by the last post modified date (fplast.modified DESC) * @param int $userid User whose flags will be retrieved; 0 = current * @return array Array of mod_forumng_discussion objects */ public function get_flagged_discussions($userid = 0) { global $USER; if ($userid != -1) { if ($userid == 0) { $userid = $USER->id; } $records = mod_forumng_discussion::query_discussions('fd.forumngid = ? AND ff.flagged IS NOT NULL AND ff.discussionid = fd.id AND ff.userid = ?', array($this->get_id(), $userid), $userid, 'x.flagged DESC', '', '', $this, true); } $result = array(); foreach ($records as $record) { // Get discussion details from record and create discussionfields. $discussion = new mod_forumng_discussion($this, $record, true, $userid); $result[$record->id] = $discussion; } return $result; }
/** * Obtains list of posts to include in an Atom/RSS feed. * @param int $groupid Group ID (may be ALL_GROUPS) * @param int $userid User ID * @param mod_forumng_discussion $discussion Discussion object (intended only * for calls via the mod_forumng_discussion method) * @return array Array of mod_forumng_post objects */ public function get_feed_posts($groupid, $userid, $discussion = null) { // Don't let user view any posts in a discussion feed they can't see // (I don't think they should be given a key in this case, but just // to be sure). if ($discussion && !$this->get_type()->can_view_discussion($discussion, $userid)) { return array(); } // Number of items to output $items = $this->get_effective_feed_items(); // Get most recent N posts from db $whereparams = array(); if ($discussion) { $where = 'fd.id = ?'; $whereparams[] = $discussion->get_id(); } else { $where = 'fd.forumngid = ?'; $whereparams[] = $this->get_id(); if ($this->get_group_mode() && $groupid != self::ALL_GROUPS) { $where .= ' AND fd.groupid = ?'; $whereparams[] = $groupid; } } // Don't include deleted or old-version posts $where .= ' AND fp.oldversion = 0 AND fp.deleted = 0 AND fd.deleted = 0'; // Or ones out of time $now = time(); $where .= " AND (fd.timestart < ?)" . " AND (fd.timeend = 0 OR fd.timeend > ?)"; $whereparams[] = $now; $whereparams[] = $now; $postrecs = mod_forumng_post::query_posts($where, $whereparams, 'GREATEST(fp.created, fd.timestart) DESC', false, false, false, $userid, true, false, 0, $items); if (count($postrecs) == 0) { // No posts! return array(); } $result = array(); if ($discussion) { foreach ($postrecs as $rec) { $post = new mod_forumng_post($discussion, $rec, null); $result[$rec->id] = $post; } } else { // Based on these posts, get all mentioned discussions $discussionids = array(); $discussionposts = array(); foreach ($postrecs as $rec) { $discussionids[] = $rec->discussionid; $discussionposts[$rec->discussionid][] = $rec->id; } list($discussionpart, $discussionpartparams) = mod_forumng_utils::get_in_array_sql('fd.id', $discussionids); $rs = mod_forumng_discussion::query_discussions($discussionpart, $discussionpartparams, -1, 'id'); // Build the discussion and post objects $posts = array(); foreach ($rs as $rec) { $discussion = new mod_forumng_discussion($this, $rec, true, -1); if ($discussion->can_view($userid)) { foreach ($discussionposts[$discussion->get_id()] as $postid) { $post = new mod_forumng_post($discussion, $postrecs[$postid], null); $posts[$postid] = $post; } } } $rs->close(); // Put them back in order of the post records, and return foreach ($postrecs as $rec) { // Records might be excluded if user can't view discussion if (array_key_exists($rec->id, $posts)) { $result[$rec->id] = $posts[$rec->id]; } } } return $result; }