/**
  * 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.
  *
  * @param string $status Filter comments by `status`, see list above
  * @return void
  */
 public function index($status = 'all')
 {
     $this->loadModel('Comment.Comments');
     $this->_setCounters();
     $search = '';
     // fills form's input
     $conditions = ['table_alias' => $this->_manageTable];
     if (in_array($status, ['pending', 'approved', 'spam', 'trash'])) {
         $conditions['Comments.status'] = $status;
     } else {
         $status = 'all';
         $conditions['Comments.status IN'] = ['pending', 'approved'];
     }
     if (!empty($this->request->query['search'])) {
         $search = $this->request->query['search'];
         $conditions['OR'] = ['Comments.subject LIKE' => "%{$this->request->query['search']}%", 'Comments.body LIKE' => "%{$this->request->query['search']}%"];
     }
     $comments = $this->Comments->find()->contain(['Users'])->where($conditions)->order(['Comments.created' => 'DESC'])->formatResults(function ($results) {
         return $results->map(function ($comment) {
             $comment->set('entity', $this->_inResponseTo($comment));
             $comment->set('body', TextToolbox::trimmer(TextToolbox::plainProcessor(TextToolbox::stripHtmlTags($comment->body)), 180));
             return $comment;
         });
     });
     $this->title(__d('comment', 'Comments List'));
     $this->set('search', $search);
     $this->set('filterBy', $status);
     $this->set('comments', $this->paginate($comments));
 }