/**
  * Called when a post is deleted or undeleted or modified, or there is a
  * larger change to the discussion
  * @param mod_forumng_post $post Post that has changed; null to always recalculate
  */
 function possible_lastpost_change($post = null)
 {
     $recalculate = false;
     if (!$post) {
         $recalculate = true;
     } else {
         if ($post->get_deleted()) {
             // For deleted posts, recalculate if this was previously
             // considered the latest post
             $recalculate = $this->discussionfields->lastpostid == $post->get_id();
         } else {
             // For other posts, recalculate if this is now newer than the
             // stored last post
             $recalculate = $post->get_modified() > $this->discussionfields->timemodified;
         }
     }
     // If necessary, recalculate the date
     if ($recalculate) {
         global $DB;
         $change = new stdClass();
         $change->id = $this->get_id();
         $records = $DB->get_records_sql("SELECT id " . "FROM {forumng_posts} WHERE discussionid = ? AND deleted = 0 AND oldversion = 0 " . "ORDER BY modified DESC", array($this->get_id()), 0, 1);
         if (count($records) == 0) {
             throw new moodle_exception('errorfindinglastpost', 'forumng');
         }
         $rec = reset($records);
         $change->lastpostid = $rec->id;
         if ($change->lastpostid != $this->discussionfields->lastpostid) {
             $DB->update_record('forumng_discussions', $change);
         }
     }
 }
 /**
  * Renders the expand link for each post.
  * @param string $linkprefix prefix of the expand link url
  * @param mod_forumng_discussion $discussion object
  * @param mod_forumng_post $post object
  * @return string HTML code for the expand link
  */
 public function render_expand_link($linkprefix, $discussion, $post)
 {
     $out = '&nbsp;<span class="forumng-expandcontainer">[<a class="forumng-expandlink" ' . 'href="' . $linkprefix . 'discuss.php?' . $discussion->get_link_params(mod_forumng::PARAM_HTML) . '&amp;expand=1#p' . $post->get_id() . '"><span class="forumng-expandtext">' . get_string('expandall', 'forumng') . '</span></a>] <img src="' . $this->pix_url('spacer') . '" width="16" height="16" alt="" /></span>';
     return $out;
 }