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

deleteComments() public static method

Deletes one or more comments
public static deleteComments ( array $ids )
$ids array The id(s) of the items(s) to delete.
    public static function deleteComments($ids)
    {
        // make sure $ids is an array
        $ids = (array) $ids;
        // loop and cast to integers
        foreach ($ids as &$id) {
            $id = (int) $id;
        }
        // create an array with an equal amount of questionmarks as ids provided
        $idPlaceHolders = array_fill(0, count($ids), '?');
        // get db
        $db = BackendModel::getContainer()->get('database');
        // get ids
        $itemIds = (array) $db->getColumn('SELECT i.post_id
             FROM blog_comments AS i
             WHERE i.id IN (' . implode(', ', $idPlaceHolders) . ')', $ids);
        // update record
        $db->delete('blog_comments', 'id IN (' . implode(', ', $idPlaceHolders) . ')', $ids);
        // recalculate the comment count
        if (!empty($itemIds)) {
            self::reCalculateCommentCount($itemIds);
        }
    }

Usage Example

Beispiel #1
0
 /**
  * Delete comment(s).
  *
  * @param string $id The id/ids of the comment(s) to update.
  */
 public static function commentsDelete($id)
 {
     // authorize
     if (BaseAPI::isAuthorized() && BaseAPI::isValidRequestMethod('POST')) {
         // redefine
         if (!is_array($id)) {
             $id = (array) explode(',', $id);
         }
         // update statuses
         BackendBlogModel::deleteComments($id);
     }
 }
All Usage Examples Of Backend\Modules\Blog\Engine\Model::deleteComments