コード例 #1
0
 /**
  * Obtains the next post in current forum.
  * @param forum_post &$post Output variable: Receives the post object
  * @param forum_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 forum_exception("Cannot call next_post when not inside\n                forum and discussion");
     }
     // Get record
     if ($this->storedrecord) {
         $record = $this->storedrecord;
         $this->storedrecord = null;
     } else {
         $record = rs_fetch_next_record($this->rs);
         if (!$record) {
             // End of the line. Mark everything as mailed
             $this->mark_mailed($this->time);
             rs_close($this->rs);
             $this->rs = null;
             $this->discussion = null;
             return false;
         }
     }
     // 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 = forum_utils::extract_subobject($record, 'fp_');
     forum_utils::copy_subobject($postfields, $record, 'u_');
     forum_utils::copy_subobject($postfields, $record, 'eu_');
     $post = new forum_post($this->discussion, $postfields);
     if ($record->reply_id) {
         $postfields = forum_utils::extract_subobject($record, 'reply_');
         forum_utils::copy_subobject($postfields, $record, 'replyu_', 'u_');
         forum_utils::copy_subobject($postfields, $record, 'replyeu_', 'eu_');
         $inreplyto = new forum_post($this->discussion, $postfields);
     } else {
         $inreplyto = null;
     }
     $this->postcount++;
     return true;
 }