kalenjordan/magehero

View on GitHub
code/Controller/PostCommentNotify.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

class Controller_PostCommentNotify extends Controller_Abstract
{
    public function post($postId)
    {
        $post = $this->_getContainer()->Post()->load($postId);
        $user = $post->getUser();
        if (! $user->getEmail()) {
            $this->_jsonResponse(array(
                'success'   => false,
                'message'   => "Can't notify because they don't have an email (user ID: " . $user->getId() . ")",
            ));
            return $this;
        }

        mail($user->getEmail(), "MageHero Comment: " . $post->getSubject(), "See comment here:\r\n" . $post->getUrl(), "From: comments@magehero.com");

        $this->_jsonResponse(array(
            'success' => true,
            'message'   => "Notified " . $user->getName(),
        ));

        return $this;
    }
}