public function deleteAction() { // action body if ($this->_request->isXmlHttpRequest()) { $commentModel = new Myblog_Model_Comment(); $id = $this->_request->getParam('id'); $response = array('status' => true); if ($id) { $response['status'] = boolval($commentModel->deleteRowByPrimaryKey($id)); } echo json_encode($response); exit; } }
public function viewAction() { // action body $id = $this->_request->getParam('id'); $post = $this->postModel->find($id); if ($post) { $userUtil = new Myblog_Model_Utils_User(); $commentModel = new Myblog_Model_Comment(); $this->view->post = $post->toObject(); $this->view->post->author = $userUtil->getNameById($post->getCreatedBy()); $this->view->post->commentsCount = $commentModel->getMapper()->countByQuery('post = ' . $id . ' AND parent = 0'); } else { $this->view->post = null; } }
protected function getChildren($post, $parent) { try { $response = array(); $commentModel = new Myblog_Model_Comment(); $comments = $commentModel->getMapper()->findByField(array('post', 'parent'), array('post' => $post, 'parent' => $parent)); if ($comments) { $userUtils = new Myblog_Model_Utils_User(); foreach ($comments as $comment) { $comment = $comment->toArray(); $comment['author'] = $userUtils->getNameById($comment['created_by']); $comment['children'] = $this->getChildren($post, $comment['id']); $response[] = $comment; } } return $response; } catch (Exception $ex) { echo $post, ' # ', $parent; exit; } }
/** * Loads the model specific data into the model object * * @param Zend_Db_Table_Row_Abstract|array $data The data as returned from a Zend_Db query * @param Myblog_Model_Comment|null $entry The object to load the data into, or null to have one created * @return Myblog_Model_Comment The model with the data provided */ public function loadModel($data, $entry) { if ($entry === null) { $entry = new Myblog_Model_Comment(); } if (is_array($data)) { $entry->setId($data['id'])->setPost($data['post'])->setParent($data['parent'])->setContent($data['content'])->setCreatedOn($data['created_on'])->setCreatedBy($data['created_by']); } elseif ($data instanceof Zend_Db_Table_Row_Abstract || $data instanceof stdClass) { $entry->setId($data->id)->setPost($data->post)->setParent($data->parent)->setContent($data->content)->setCreatedOn($data->created_on)->setCreatedBy($data->created_by); } $entry->setMapper($this); return $entry; }