Backend\Modules\Blog\Engine\Model::insertComment PHP Méthode

insertComment() public static méthode

Inserts a new comment (Taken from FrontendBlogModel)
public static insertComment ( array $comment ) : integer
$comment array The comment to add.
Résultat integer
    public static function insertComment(array $comment)
    {
        // get db
        $db = BackendModel::getContainer()->get('database');
        // insert comment
        $comment['id'] = (int) $db->insert('blog_comments', $comment);
        // recalculate if published
        if ($comment['status'] == 'published') {
            // num comments
            $numComments = (int) BackendModel::getContainer()->get('database')->getVar('SELECT COUNT(i.id) AS comment_count
                 FROM blog_comments AS i
                 INNER JOIN blog_posts AS p ON i.post_id = p.id AND i.language = p.language
                 WHERE i.status = ? AND i.post_id = ? AND i.language = ? AND p.status = ?
                 GROUP BY i.post_id', array('published', $comment['post_id'], BL::getWorkingLanguage(), 'active'));
            // update num comments
            $db->update('blog_posts', array('num_comments' => $numComments), 'id = ?', $comment['post_id']);
        }
        return $comment['id'];
    }