function unlike($item_id, $item_type) { $objModelVote = new Application_Model_Vote(); $usersNs = new Zend_Session_Namespace("members"); $userId = $usersNs->userId; $whereVote = "item_type='{$item_type}' AND item_id='{$item_id}' AND user_id='{$userId}'"; $arrVote = $objModelVote->fetchAll($whereVote); if (count($arrVote) > 0) { $option['id'] = $arrVote[0]->id; } $option['vote'] = -1; $option['itemType'] = $item_type; $option['itemId'] = $item_id; $option['addedon'] = time(); $option['updatedon'] = time(); $option['userId'] = $userId; $objModelVote->setOptions($option); $id = $objModelVote->save(); return $id; }
public function userLikeThisAction() { $this->_helper->layout->setLayout('journal-layout-2column'); //$item_id = $this->_getParam("blog_id"); $item_id = $this->_getParam("item_id"); $item_type = $this->_getParam("type"); //$userNs = new Zend_Session_Namespace('members'); //$this->view->userId = $userNs->userId; $item = false; $itemTypeText = ""; if ($item_type != "") { if ($item_type == 'blog') { $blogM = new Application_Model_Blog(); $this->view->blog = $item = $blogM->find($item_id); $itemTypeText = "Journal Post"; } if ($item_type == 'status_comment' || $item_type == 'blog_comment') { $commentM = new Application_Model_Comment(); $item = $commentM->find($item_id); $itemTypeText = "Comment"; $item_type = "comment"; } if ($item_type == 'status') { $wallM = new Application_Model_Wall(); $item = $wallM->find($item_id); $itemTypeText = "Wall Post"; } $this->view->itemTypeText = $itemTypeText; } //if item is not exists then redirect to Journal home page if (false === $item) { $this->_helper->redirector()->gotoUrl('/journal/index/'); exit; } //Now get all positive votes of item //$where = "item_id = $item_id AND vote=1 AND item_type='blog'"; $where = "item_id = {$item_id} AND vote=1"; if ($item_type == 'comment') { $where .= " AND (item_type='status_comment' OR item_type='blog_comment')"; } else { $where .= " AND item_type='{$item_type}'"; } $voteM = new Application_Model_Vote(); $rawdata = $voteM->fetchAll($where); //Get all users ID voted on an item if (false !== $rawdata) { $user_array = array(); foreach ($rawdata as $row) { $user_array[] = $row->getUserId(); } } //get all users information from above User Ids $this->view->totalUsers = 0; if (count($user_array) > 0) { $usrstr = implode(",", $user_array); $userM = new Application_Model_User(); $whereuser = "******"; $userData = $userM->fetchAll($whereuser, "first_name ASC"); $this->view->userData = $userData; $settings = new Admin_Model_GlobalSettings(); $page_size = $settings->settingValue('pagination_size'); //$page_size = 1; $page = $this->_getParam('page', 1); $pageObj = new Base_Paginator(); $paginator = $pageObj->fetchPageData($userM, $page, $page_size, $whereuser); $this->view->totalUsers = $pageObj->getTotalCount(); $this->view->paginator = $paginator; } }