protected ForumManager::getLastPost($tid)
Provides the last post information for the given forum tid.
Parameters
int $tid: The forum tid.
Return value
\stdClass The last post for the given forum.
File
- core/modules/forum/src/ForumManager.php, line 331
Class
- ForumManager
- Provides forum manager service.
Namespace
Drupal\forum
Code
protected function getLastPost($tid) { if (!empty($this->lastPostData[$tid])) { return $this->lastPostData[$tid]; } // Query "Last Post" information for this forum. $query = $this->connection->select('node_field_data', 'n'); $query->join('forum', 'f', 'n.vid = f.vid AND f.tid = :tid', array(':tid' => $tid)); $query->join('comment_entity_statistics', 'ces', "n.nid = ces.entity_id AND ces.field_name = 'comment_forum' AND ces.entity_type = 'node'"); $query->join('users_field_data', 'u', 'ces.last_comment_uid = u.uid AND u.default_langcode = 1'); $query->addExpression('CASE ces.last_comment_uid WHEN 0 THEN ces.last_comment_name ELSE u.name END', 'last_comment_name'); $topic = $query ->fields('ces', array('last_comment_timestamp', 'last_comment_uid')) ->condition('n.status', 1) ->orderBy('last_comment_timestamp', 'DESC') ->range(0, 1) ->addTag('node_access') ->execute() ->fetchObject(); // Build the last post information. $last_post = new \stdClass(); if (!empty($topic->last_comment_timestamp)) { $last_post->created = $topic->last_comment_timestamp; $last_post->name = $topic->last_comment_name; $last_post->uid = $topic->last_comment_uid; } $this->lastPostData[$tid] = $last_post; return $last_post; }
Please login to continue.