/** * @Created By : Mahipal Singh Adhikari * @Created On : 2-Nov-2010 * @Description: This function is used to like/unlike comment by blog owner */ public function likeCommentAction() { $this->view->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $usersNs = new Zend_Session_Namespace('members'); $user_id = $usersNs->userId; if ($user_id == "" || $user_id == 0) { $JsonResultArray = array('error' => 1, 'response' => "Please login to vote."); echo Zend_Json::encode($JsonResultArray); exit; } $vote = $this->_getParam('vote'); $item_id = $this->_getParam('item_id'); $item_type = $this->_getParam('item_type'); $voteM = new Application_Model_Vote(); $voteM = $voteM->fetchRow("user_id='{$user_id}' AND item_type='{$item_type}' AND item_id='{$item_id}' "); if (false === $voteM) { $voteM = new Application_Model_Vote(); $voteM->setVote($vote); $voteM->setItemId($item_id); $voteM->setItemType($item_type); $voteM->setUserId($user_id); } else { $voteM->setVote($vote); } $savevote = $voteM->save(); if ($savevote) { $response = ""; if ($vote == 1) { $response = "<a href='javascript://' title='Unlike Comment' onclick='likeComment(" . $item_id . ", -1)'>Unlike</a>"; } else { $response = "<a href='javascript://' title='Like Comment' onclick='likeComment(" . $item_id . ", 1)'>Like</a>"; } $JsonResultArray = array('error' => 0, 'response' => $response); } else { $JsonResultArray = array('error' => 1, 'response' => "Error occured please try again later."); } echo Zend_Json::encode($JsonResultArray); exit; }
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 getVideosCommentsUser($id, $limit = null, $user_id = null, $sort = null) { //$id = picture id $arrayVId = array(); $order = "id desc"; $commentM = new Application_Model_Comment(); $where = "item_id ='{$id}' and item_type='movie_user_video' and parent_id='0'"; if (!is_null($user_id)) { $where .= " and user_id='{$user_id}'"; } if (!is_null($sort)) { if ($sort != "recent") { $comments = $commentM->fetchAll($where, $order); foreach ($comments as $row) { $arrayVId[] = $row->getId(); } } else { $comments = $commentM->fetchAll($where, $order, $limit); } //$strPicId=implode(",",$arrayPicId); $voteM = new Application_Model_Vote(); $res = array(); if ($sort == "up") { $res = $voteM->getTotalVotesGroup($arrayVId, 'movie', 'user_movie_videos_comments', 1, null); } else { if ($sort == "down") { $res = $voteM->getTotalVotesGroup($arrayVId, 'movie', 'user_movie_videos_comments', -1, null); } else { if ($sort == "sum") { $res = $voteM->getTotalVotesSum($arrayVId, 'movie', 'user_movie_videos_comments'); } } } if (count($res) > 0 && $sort != "recent") { unset($comments); $ctr = 0; foreach ($res as $row) { $ctr++; if (!is_null($limit)) { if ($limit < $ctr) { break; } } $comments[] = $commentM->find($row->item_id); $usedIds[] = $row->item_id; } $remain = array_diff($arrayVId, $usedIds); foreach ($remain as $comment_id) { $ctr++; if (!is_null($limit)) { if ($limit < $ctr) { break; } } $comments[] = $commentM->find($comment_id); } } } else { $comments = $commentM->fetchAll($where, $order, $limit); } return $comments; }
private function setModel($row) { $model = new Application_Model_Vote(); $model->setId($row->id)->setVote($row->vote)->setItemType($row->item_type)->setItemId($row->item_id)->setAddedon($row->addedon)->setUpdatedon($row->updatedon)->setUserId($row->user_id); return $model; }
public function removeTravelWallPostCommentAction() { $this->_helper->layout->disableLayout(); $params = $this->getRequest()->getParams(); $postId = $params['postId']; $objModelVote = new Application_Model_Vote(); $objModelComment = new Application_Model_Comment(); $whereVote = "item_id='{$postId}' AND item_type='status_comment'"; $whereComment = "id='{$postId}'"; $objModelVote->delete($whereVote); $objModelComment->delete($whereComment); exit; }
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; } }