public function viewAction() { // action body $postid = (int) $this->_getParam('id'); if (empty($postid)) { } $post = new Model_DbTable_Posts(); $result = $post->getPost($postid); $this->view->post = $result; $commentsObj = new Model_DbTable_Comments(); $request = $this->getRequest(); $commentsForm = new Form_Comments(); /* * Check the comment form has been posted */ if ($this->getRequest()->isPost()) { if ($commentsForm->isValid($request->getPost())) { $model = new Model_DbTable_Comments(); $model->saveComment($commentsForm->getValues()); $commentsForm->reset(); } } $data = array('id' => $postid); $commentsForm->populate($data); $this->view->commentsForm = $commentsForm; $comments = $commentsObj->getComments($postid); $this->view->comments = $comments; $this->view->edit = '/posts/edit/id/' . $postid; }
public function getComments() { $table = new Model_DbTable_Comments(); $select = $table->select(); $select->where('object_id = ?', $this->id); $select->where('model = ?', $this->_table->info('name')); $select->order('path ASC'); return $table->fetchAll($select); }
public function postAction() { if (!$this->view->authenticated && !$request->isXmlHttpRequest()) { $this->_redirector->gotoRoute(array(), 'login'); } $request = $this->getRequest(); $form = new Form_Comment(); if ($request->isPost() && $form->isValid($request->getPost())) { $model = 'Model_DbTable_' . ucfirst($form->getValue('model')); $table = new Model_DbTable_Comments(); $comment = $table->addComment($model, $form->getValue('oid'), $this->view->identity->id, $form->getValue('comment'), $form->getValue('parent')); } if ($request->isXmlHttpRequest()) { $this->_helper->layout()->disableLayout(); if (!isset($comment)) { $this->getResponse()->sendResponse(); exit; } $this->view->comment = $comment; $this->render('/partials/comment', null, true); } else { $this->_redirector->gotoRoute(array('controller' => substr($form->getValue('model'), 0, -1), 'id' => $form->getValue('oid')), 'view'); } }
/** * Make widget content available for the view * * Implements {@link iPMS_Widget_Interface::widget()} * * @return array array of comments */ public function widget() { $model = new Model_DbTable_Comments(); $comments = $model->fetchAll(null, 'id', 5)->toArray(); return $comments; }