/** * List all comment by document id * * @return array */ public function documentCommentAction() { $documentId = $this->params()->fromRoute('id'); $document = DocumentModel::fromId($documentId); if (empty($document)) { return $this->redirect()->toRoute('module/blog'); } $model = new Model\Comment(); $commentList = $model->getList($documentId, null); if ($this->getRequest()->isPost()) { $comments = $this->getRequest()->getPost()->get('comment'); foreach ($comments as $commentId => $data) { if (!empty($data['delete'])) { $model->delete(array('id' => $commentId)); continue; } foreach ($data as $k => $v) { if (!in_array($k, $this->whiteList)) { unset($data[$k]); } } $data['show_email'] = empty($data['show_email']) ? 0 : 1; $data['is_active'] = empty($data['is_active']) ? 0 : 1; $model->update($data, array('id' => $commentId)); } return $this->redirect()->toRoute('module/blog/document-comment', array('id' => $documentId)); } return array('comment_list' => $commentList, 'document' => $document); }