Inheritance: extends Eva\Mvc\Model\AbstractModel
示例#1
0
 /**
  * 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);
 }
示例#2
0
 /**
  * Invoke form
  *
  * @return string
  */
 public function __invoke()
 {
     $commentTable = new Blog\Model\Comment();
     $document = $this->getServiceLocator()->get('Zend\\View\\Renderer\\PhpRenderer')->plugin('CurrentDocument');
     $comments = $commentTable->getList($document()->getId());
     return $this->addPath(__DIR__ . '/../views')->render('plugin/comment-list.phtml', array('comments' => $comments));
 }
示例#3
0
 /**
  * HTML for a single comment
  *
  * @param Comment $comment
  * @param boolean $is_child
  * @return string
  **/
 public function _commentBox(Comment $comment, $is_child = false)
 {
     $extra = $comment->getEmail() == '*****@*****.**' ? ' rob' : '';
     $extra .= $is_child ? ' reply' : '';
     if ($comment->getWebsite()) {
         $author = '<a title="' . $comment->getName() . '\'s website" href="' . $comment->getWebsite() . '">' . $comment->getName() . '</a>';
     } else {
         $author = $comment->getName();
     }
     $string = '<div id="comment-' . $comment->getId() . '" class="comment-container' . $extra . '">';
     $string .= '<h2>' . $author . ' - ' . $comment->getDateAdded()->format("F jS, Y @ g:ia") . ' <a class="reply" title="Reply to this comment" href="javascript:replyToComment(\'' . $comment->getId() . '\')">reply</a></h2>';
     $string .= '<div class="comment">';
     $string .= '<div class="photo">' . '<a title="Get a gravatar" href="http://www.gravatar.com">' . $this->view->gravatar($comment->getEmail(), array('img_size' => 50), array('alt' => 'gravatar', 'title' => 'avatar')) . '</a>' . '</div>';
     $string .= stripslashes($comment->getComment());
     if ($this->_role == UserService::ROLE_ADMIN) {
         $string .= '<p>';
         $string .= sprintf('<a title="edit" href="%s">edit</a> | ', $this->view->myUrl('blog/default/query', array('controller' => 'comment', 'action' => 'edit', 'id' => $comment->getId())));
         $string .= sprintf('<a title="delete" href="javascript:deleteComment(%s)">delete</a>', $comment->getId());
         $string .= '</p>';
     }
     $string .= '<div class="clear"></div>';
     $string .= '</div>';
     $string .= '</div>';
     return $string;
 }
示例#4
0
文件: Module.php 项目: gotcms/gotcms
 /**
  * Display widget dashboard
  *
  * @param \Zend\EventManager\EventInterface $event Event
  *
  * @return void
  */
 public function dashboard(Event $event)
 {
     $commentModel = new Comment();
     $unactiveCommentList = $commentModel->getList(null, false);
     $activeCommentList = $commentModel->getList(null, true);
     $widgets = $event->getParam('widgets');
     $widgets['blog']['id'] = 'blog';
     $widgets['blog']['title'] = 'Blog information';
     $widgets['blog']['content'] = $this->addPath(__DIR__ . '/views')->render('dashboard.phtml', array('unactiveComments' => count($unactiveCommentList), 'activeComments' => count($activeCommentList)));
     $event->setParam('widgets', $widgets);
 }
示例#5
0
 /**
  * Invoke form
  *
  * @return void
  */
 public function __invoke()
 {
     $request = $this->getRequest();
     if ($request->isPost()) {
         $post = $request->getPost();
         $this->getForm()->setData($post);
         if ($this->getForm()->isValid()) {
             $commentTable = new Blog\Model\Comment();
             $document = $this->getServiceLocator()->get('Zend\\View\\Renderer\\PhpRenderer')->plugin('CurrentDocument');
             if ($commentTable->add($this->getForm()->getInputFilter()->getValues(), $document()->getId())) {
                 $this->flashMessenger()->addSuccessMessage('Message sent');
                 return $this->redirect()->toUrl($request->getRequestUri());
             }
         }
     }
     return $this->addPath(__DIR__ . '/../views')->render('plugin/comment-form.phtml', array('form' => $this->getForm(), 'errorMessage' => 'Error'));
 }
示例#6
0
 /**
  * Test
  *
  * @return void
  */
 public function testAddWithWrongValues()
 {
     $data = array('message' => '', 'username' => '', 'email' => '');
     $this->assertFalse($this->object->add($data, $this->document->getId()));
 }
示例#7
0
 /**
  * Removes comment
  *
  * @param Comment $comment
  * @return void
  */
 public function delete(Comment $comment)
 {
     $dql = sprintf('UPDATE %s c SET c.parentId = 0 WHERE c.parentId = %s', self::ENTITY_COMMENT, $comment->getId());
     $query = $this->em->createQuery($dql);
     $query->execute();
     $this->em->remove($comment);
     $this->em->flush();
 }