This repository has been archived by the owner on Aug 24, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added commenting backend to post module
- Loading branch information
Showing
10 changed files
with
587 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
/** | ||
* Epixa - Forum | ||
*/ | ||
|
||
namespace Post\Controller; | ||
|
||
use Epixa\Controller\AbstractController, | ||
Post\Service\Post as PostService, | ||
Post\Service\Comment as CommentService, | ||
Post\Model\Comment as CommentModel, | ||
Post\Form\Comment as CommentForm; | ||
|
||
/** | ||
* Manage comment functionality | ||
* | ||
* @category Module | ||
* @package Post | ||
* @subpackage Controller | ||
* @copyright 2011 epixa.com - Court Ewing | ||
* @license http://github.com/epixa/Forum/blob/master/LICENSE New BSD | ||
* @author Court Ewing (court@epixa.com) | ||
*/ | ||
class CommentController extends AbstractController | ||
{ | ||
/** | ||
* Create a new comment | ||
*/ | ||
public function addAction() | ||
{ | ||
$request = $this->getRequest(); | ||
|
||
$this->_helper->assert->isAjax($request); | ||
$this->_helper->assert->isPost($request); | ||
|
||
$form = new CommentForm(); | ||
if (!$form->isValid($request->getPost())) { | ||
$this->_helper->ajax->invalid($form); | ||
return; | ||
} | ||
|
||
$service = new PostService(); | ||
$post = $service->get($request->getPost('id', null)); | ||
$this->_helper->assert->isset($post); | ||
|
||
$comment = $service->add($form->getValues(), $post); | ||
|
||
$this->_helper->ajax->success(array( | ||
'comment' => array( | ||
'id' => $comment->id | ||
) | ||
)); | ||
} | ||
|
||
/** | ||
* Edit an existing comment | ||
*/ | ||
public function editAction() | ||
{ | ||
$request = $this->getRequest(); | ||
|
||
$this->_helper->assert->isAjax($request); | ||
$this->_helper->assert->isPost($request); | ||
|
||
$comment = $this->getCurrentComment(); | ||
|
||
$form = new CommentForm(); | ||
if (!$form->isValid($request->getPost())) { | ||
$this->_helper->ajax->invalid($form); | ||
return; | ||
} | ||
|
||
$service = new CommentService(); | ||
$service->edit($comment, $form->getValues()); | ||
|
||
$this->_helper->ajax->success(array( | ||
'comment' => array( | ||
'id' => $comment->id | ||
) | ||
)); | ||
} | ||
|
||
/** | ||
* Delete an existing comment | ||
*/ | ||
public function deleteAction() | ||
{ | ||
$comment = $this->getCurrentComment(); | ||
|
||
$request = $this->getRequest(); | ||
|
||
$this->_helper->assert->isAjax($request); | ||
$this->_helper->assert->isPost($request); | ||
|
||
$service = new CommentService(); | ||
$service->delete($comment); | ||
|
||
$this->_helper->ajax->success(); | ||
} | ||
|
||
|
||
/** | ||
* Get the current comment by the id from the request | ||
* | ||
* @return CommentModel | ||
*/ | ||
public function getCurrentComment() | ||
{ | ||
$service = new CommentService(); | ||
$post = $service->get($this->getRequest()->getParam('id', null)); | ||
|
||
$this->_helper->assert->isset($post, 'Epixa\Exception\NotFoundException'); | ||
|
||
return $post; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* Epixa - Forum | ||
*/ | ||
|
||
namespace Post\Form; | ||
|
||
use Epixa\Form\BaseForm; | ||
|
||
/** | ||
* @category Module | ||
* @package Post | ||
* @subpackage Form | ||
* @copyright 2011 epixa.com - Court Ewing | ||
* @license http://github.com/epixa/Epixa/blob/master/LICENSE New BSD | ||
* @author Court Ewing (court@epixa.com) | ||
*/ | ||
class Comment extends BaseForm | ||
{ | ||
public function init() | ||
{ | ||
$this->addElement('textarea', 'content', array( | ||
'required' => true, | ||
'label' => 'Comment' | ||
)); | ||
|
||
$this->addElement('submit', 'submit', array( | ||
'ignore' => true, | ||
'label' => 'Save', | ||
'order' => 99999 | ||
)); | ||
} | ||
} |
Oops, something went wrong.