\Comment\ControllerCommentUIControllerTrait

Comment UI Trait.

Other plugins may extends Comment plugin by using this trait in their controllers.

With this trait, Comment plugin provides an user friendly UI for manage entity's comments. It provides a comment-manager user interface (UI) by attaching a series of actions over a clean controller.

Usage:

Beside adding use CommentUIControllerTrait; to your controller you MUST also indicate the name of the Table being managed. Example:

uses Comment\Controller\CommentUIControllerTrait;

class MyCleanController extends AppController {
    use CommentUIControllerTrait;
    // underscored table alias. e.g.: "user_photos"
    protected $_manageTable = 'contents';
}

In order to avoid trait collision you should always extend Comment UI using this trait over a clean controller. This is, an empty controller class with no methods defined. For instance, create a new controller class MyPlugin\Controller\MyTableCommentManagerController and use this trait to handle comments for "MyTable" database table.

_inResponseTo() method

Also, your controller must implement the _inResponseTo() method. This method must return a string value describing the entity that the given comment is attached to. For example:


protected function _inResponseTo(\Comment\Model\Entity\Comment $comment) {
    $this->loadModel('MyPlugin.Persons');
    $person = $this->Persons->get($comment->entity_id);
    return "{$person->name}<br />{$person->email}";
}
```php

# Requirements

- This trait should only be used over a clean controller.
- You must define `$_manageTable` property in your controller.
- Your Controller must be a backend-controller (under `Controller\Admin` namespace).
- Your Controller must implement the `_inResponseTo()` method described above.

Summary

Methods
Properties
Constants
beforeFilter()
beforeRender()
index()
edit()
status()
delete()
emptyTrash()
No public properties found
No constants found
_setCounters()
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

beforeFilter()

beforeFilter(\Cake\Event\Event $event) : void

Validation rules.

Parameters

\Cake\Event\Event $event

The event instance.

Throws

\Cake\Network\Exception\ForbiddenException

When

  • $_manageTable is not defined.
  • trait is used in non-controller classes.
  • the controller is not a backend controller.
  • the "_inResponseTo()" is not implemented.

beforeRender()

beforeRender(\Cake\Event\Event $event) : void

Fallback for template location when extending Comment UI API.

If controller tries to render an unexisting template under its Template directory, then we try to find that view under Comment/Template/CommentUI directory.

Example:

Suppose you are using this trait to manage comments attached to Persons entities. You would probably have a Person plugin and a clean controller as follow:

// http://example.com/admin/person/comments_manager
Person\Controller\CommentsManagerController::index()

The above controller action will try to render /plugins/Person/Template/CommentsManager/index.ctp. But if does not exists then <QuickAppsCorePath>/plugins/Comment/Template/CommentUI/index.ctp will be used instead.

Of course you may create your own template and skip this fallback functionality.

Parameters

\Cake\Event\Event $event

the event instance.

index()

index(string $status) : void

Field UI main action.

Shows all the comments attached to the Table being managed. Possibles values for status are:

  • all: Comments marked as pending or approved. (by default)
  • pending: Comments awaiting for moderation.
  • approved: Comments approved and published.
  • spam: Comments marked as SPAM by Akismet.
  • trash: Comments that were sent to trash bin.

Parameters

string $status

Filter comments by status, see list above

edit()

edit(integer $id) : void

Edit form for given comment.

Parameters

integer $id

Comment id

Throws

\Cake\ORM\Exception\RecordNotFoundException

When comment was not found

status()

status(integer $id, string $status) : void

Changes the status of the given comment.

Parameters

integer $id

Comment id

string $status

New status for the comment

delete()

delete(integer $id) : void

Permanently deletes the given comment.

Parameters

integer $id

Comment id

emptyTrash()

emptyTrash() : void

Permanently deletes all comments marked as "trash".

_setCounters()

_setCounters() : void

Sets a few view-variables holding counters for each status ("pending", "approved", "spam" or "trash").