Backend\Modules\Blog\Engine\Model::getLatestComments PHP Method

getLatestComments() public static method

Get the latest comments for a given type
public static getLatestComments ( string $status, integer $limit = 10 ) : array
$status string The status for the comments to retrieve.
$limit integer The maximum number of items to retrieve.
return array
    public static function getLatestComments($status, $limit = 10)
    {
        // get the comments (order by id, this is faster then on date, the higher the id, the more recent
        $comments = (array) BackendModel::getContainer()->get('database')->getRecords('SELECT i.id, i.author, i.text, UNIX_TIMESTAMP(i.created_on) AS created_in,
             p.title, p.language, m.url
             FROM blog_comments AS i
             INNER JOIN blog_posts AS p ON i.post_id = p.id AND i.language = p.language
             INNER JOIN meta AS m ON p.meta_id = m.id
             WHERE i.status = ? AND p.status = ? AND i.language = ?
             ORDER BY i.created_on DESC
             LIMIT ?', array((string) $status, 'active', BL::getWorkingLanguage(), (int) $limit));
        // overwrite url
        $baseUrl = BackendModel::getURLForBlock('Blog', 'detail');
        foreach ($comments as &$row) {
            $row['full_url'] = $baseUrl . '/' . $row['url'];
        }
        return $comments;
    }

Usage Example

Beispiel #1
0
 /**
  * Load the data
  */
 private function loadData()
 {
     $this->comments = BackendBlogModel::getLatestComments('published', 5);
     $this->numCommentStatus = BackendBlogModel::getCommentStatusCount();
 }