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; } }
public function loginAction() { // action body if (isset($this->authUser_NameSpace->user->id)) { $this->_redirect('/'); } if ($this->_request->isXmlHttpRequest() && $this->_request->isPost()) { $username = $this->_request->getParam('inputEmail'); $password = $this->_request->getParam('inputPassword'); $userUtil = new Myblog_Model_Utils_User(); $userModel = $userUtil->authenticate($username, $password); $response = array('status' => true); if ($userModel) { $this->authUser_NameSpace->user = $userModel->toObject(); $this->authUser_NameSpace->acl = new Myblog_Model_Utils_Acl(); } else { $response['status'] = false; $response['message'] = 'Login failed'; } echo json_encode($response); exit; } }