/** * @Created By : Mahipal Singh Adhikari * @Created On : 3-Nov-2010 * @Description : Count number of post for a particular category with permission check * @Input : int - category id * @Return : Int - number of post */ public function countCategoryPosts($category_id) { //create database object $db = Zend_Registry::get('db'); $db->setFetchMode(Zend_Db::FETCH_OBJ); $total_blogs = 0; $sql = "SELECT b.id, b.user_id, b.status FROM blog AS b"; $sql .= " JOIN journal AS j ON j.id = b.journal_id"; //$sql .= " WHERE b.status = 5 AND b.publish = 'published'"; $sql .= " WHERE b.publish = 'published'"; $sql .= " AND j.status = 'public' AND j.publish = 'published'"; $sql .= " AND b.category_id={$category_id}"; $blogs = $db->fetchAll($sql); if (count($blogs) > 0) { $userNs = new Zend_Session_Namespace('members'); $loggedin_id = $userNs->userId; foreach ($blogs as $blog) { $view_my_journal = false; $blogM = new Application_Model_Blog(); $view_my_journal = $blogM->checkBlogPrivacySettings($blog->user_id, $loggedin_id, $blog->status); if ($view_my_journal) { $total_blogs = $total_blogs + 1; } } } return $total_blogs; }
public function viewPostAction() { $this->_helper->layout->setLayout('journal-layout-2column'); $blog_id = $this->_getParam("blog_id"); $blogM = new Application_Model_Blog(); //$whereCond = "id={$blog_id} AND status=5 AND publish='published'"; $whereCond = "id={$blog_id} AND publish='published'"; $blog = $blogM->fetchRow($whereCond); $this->view->blog = $blog; //get logged in user session User ID $userNs = new Zend_Session_Namespace('members'); $this->view->userId = $loggedin_id = $userNs->userId; if ($blog) { //get blog Journal public/published information $journalM = new Application_Model_Journal(); $journalM = $journalM->find($blog->getJournalId()); if ($journalM) { $this->view->jStatus = $jStatus = $journalM->getStatus(); $this->view->jPublish = $jPublish = $journalM->getPublish(); if ($jStatus != "public" || $jPublish != "published") { $this->view->message = "Post journal is either private or not published."; $this->render('error'); } else { //now check logged in user connection, permission from user to logged in user $blogUserId = $blog->getUserId(); /* $userM = new Application_Model_User(); $view_my_journal = $userM->checkUserPrivacySettings($blogUserId, $loggedin_id, 4); */ //above code is commented by Mahipal on 19-jan-2011 as we don't need to check user permissions $blogM = new Application_Model_Blog(); $view_my_journal = $blogM->checkBlogPrivacySettings($blogUserId, $loggedin_id, $blog->getStatus()); if (!$view_my_journal) { $this->view->message = "You are not authorised to view this post."; $this->render('error'); } } } else { $this->view->message = "Journal is either not created OR not published by user."; $this->render('error'); } } //end of if //if not blog found then redirect user to Journal page if (false === $blog) { $this->_helper->redirector()->gotoUrl('/journal/index/'); exit; } }