Backend\Modules\Blog\Engine\Api::commentsUpdate PHP Method

commentsUpdate() public static method

Update a comment
public static commentsUpdate ( integer $id, string $status = null, string $text = null, string $authorName = null, string $authorEmail = null, string $authorWebsite = null ) : null | boolean
$id integer The id of the comment.
$status string The new status for the comment. Possible values are: published, moderation, spam.
$text string The new text for the comment.
$authorName string The new author for the comment.
$authorEmail string The new email for the comment.
$authorWebsite string The new website for the comment.
return null | boolean
    public static function commentsUpdate($id, $status = null, $text = null, $authorName = null, $authorEmail = null, $authorWebsite = null)
    {
        // authorize
        if (BaseAPI::isAuthorized() && BaseAPI::isValidRequestMethod('POST')) {
            // redefine
            $id = (int) $id;
            if ($status !== null) {
                $status = (string) $status;
            }
            if ($text !== null) {
                $text = (string) $text;
            }
            if ($authorName !== null) {
                $authorName = (string) $authorName;
            }
            if ($authorEmail !== null) {
                $authorEmail = (string) $authorEmail;
            }
            if ($authorWebsite !== null) {
                $authorWebsite = (string) $authorWebsite;
            }
            // validate
            if ($status === null && $text === null && $authorName === null && $authorEmail === null && $authorWebsite === null) {
                return BaseAPI::output(BaseAPI::ERROR, array('message' => 'No data provided.'));
            }
            // update
            if ($text !== null || $authorName !== null || $authorEmail != null || $authorWebsite !== null) {
                $item['id'] = (int) $id;
                if ($text !== null) {
                    $item['text'] = $text;
                }
                if ($authorName !== null) {
                    $item['author'] = $authorName;
                }
                if ($authorEmail !== null) {
                    $item['email'] = $authorEmail;
                }
                if ($authorWebsite !== null) {
                    $item['website'] = $authorWebsite;
                }
                // update the comment
                BackendBlogModel::updateComment($item);
            }
            // change the status if needed
            if ($status !== null) {
                BackendBlogModel::updateCommentStatuses(array($id), $status);
            }
        }
    }