Frontend\Modules\Blog\Engine\Model::getComments PHP Method

getComments() public static method

Get the comments for an item
public static getComments ( integer $id ) : array
$id integer The ID of the item to get the comments for.
return array
    public static function getComments($id)
    {
        // get the comments
        $comments = (array) FrontendModel::getContainer()->get('database')->getRecords('SELECT c.id, UNIX_TIMESTAMP(c.created_on) AS created_on, c.text, c.data,
             c.author, c.email, c.website
             FROM blog_comments AS c
             WHERE c.post_id = ? AND c.status = ? AND c.language = ?
             ORDER BY c.id ASC', array((int) $id, 'published', LANGUAGE));
        // loop comments and create gravatar id
        foreach ($comments as &$row) {
            $row['gravatar_id'] = md5($row['email']);
        }
        // return
        return $comments;
    }

Usage Example

Example #1
0
 /**
  * Load the data, don't forget to validate the incoming data
  */
 private function getData()
 {
     // validate incoming parameters
     if ($this->URL->getParameter(1) === null) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // get record
     $this->record = FrontendBlogModel::get($this->URL->getParameter(1));
     // anything found?
     if (empty($this->record)) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // get articles
     $this->items = FrontendBlogModel::getComments($this->record['id']);
 }
All Usage Examples Of Frontend\Modules\Blog\Engine\Model::getComments