/** * Obtains the next post in current forum. * @param mod_forumng_post &$post Output variable: Receives the post object * @param mod_forumng_post &$inreplyto Output variable: Receives the post this one was * replying to * @return bool True if a post could be retrieved, false if there are * no more posts in this forum (call next_forum) */ function next_post(&$post, &$inreplyto) { // Make sure we have a forum/discussion setup if ($this->forum == null || $this->discussion == null) { throw new coding_exception("Cannot call next_post when not inside\n forum and discussion"); } // Get record if ($this->storedrecord) { $record = $this->storedrecord; $this->storedrecord = null; } else { if (!$this->rs->valid()) { // End of the line. Mark everything as mailed $this->mark_mailed($this->time); $this->rs->close(); $this->rs = null; $this->discussion = null; return false; } $record = $this->rs->current(); $this->rs->next(); } // If record discussion is not the same as current discussion if ($record->fd_id != $this->discussion->get_id() || $record->cloneid != $this->forum->get_course_module_id()) { $this->storedrecord = $record; $this->discussion = null; return false; } // Get post details including the joined user info $postfields = mod_forumng_utils::extract_subobject($record, 'fp_'); mod_forumng_utils::copy_subobject($postfields, $record, 'u_'); mod_forumng_utils::copy_subobject($postfields, $record, 'eu_'); $post = new mod_forumng_post($this->discussion, $postfields); if ($record->reply_id) { $postfields = mod_forumng_utils::extract_subobject($record, 'reply_'); mod_forumng_utils::copy_subobject($postfields, $record, 'replyu_', 'u_'); mod_forumng_utils::copy_subobject($postfields, $record, 'replyeu_', 'eu_'); $inreplyto = new mod_forumng_post($this->discussion, $postfields); } else { $inreplyto = null; } $this->postcount++; return true; }