public function allFriendsAction() { $userNs = new Zend_Session_Namespace('members'); $userId = $userNs->userId; $where = "1=1 AND id!='{$userId}'"; $where .= " AND status = 'active'"; $name = ""; if ($this->getRequest()->isPost()) { $params = $this->getRequest()->getParams(); $name = $params['nickname']; } if ($name != "") { //$where .= " AND (username LIKE '%{$name}%' OR first_name LIKE '%{$name}%' OR last_name LIKE '%{$name}%')"; //$where .= " AND (CONCAT(first_name,' ',last_name ) LIKE '%$name%' OR username LIKE '%$name%')"; $where .= " AND (CONCAT(first_name,' ',last_name ) LIKE '%{$name}%' )"; $this->view->param = array('nickname' => $name); } $friendM = new Application_Model_Friend(); $frienddata = $friendM->fetchAll("user_id = {$userId} AND status = 'accept'"); if (count($frienddata) > 0) { foreach ($frienddata as $friend) { $friendids[] = $friend->getFriendId(); } $friend_str = implode(',', $friendids); $where .= " AND id NOT IN({$friend_str})"; } $userM = new Application_Model_User(); $settings = new Admin_Model_GlobalSettings(); $page_size = $settings->settingValue('pagination_size'); $page = $this->_getParam('page', 1); $pageObj = new Base_Paginator(); $paginator = $pageObj->fetchPageData($userM, $page, $page_size, $where); $this->view->total = $pageObj->getTotalCount(); $this->view->paginator = $paginator; }
public function autoFriendNameAction() { $this->view->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $userNs = new Zend_Session_Namespace('members'); $userId = $userNs->userId; $friendM = new Application_Model_Friend(); $frienddata = $friendM->fetchAll(); $friendids = array(); foreach ($frienddata as $friend) { $friendids[] = $friend->getFriendId(); } $q = strtolower($this->_getParam('term')); if (!$q) { return; } $where = "status='active'"; //$where = "first_name like '%{$q}%' "; $where .= " AND (CONCAT(first_name,' ',last_name ) LIKE '%{$q}%' OR username LIKE '%{$q}%')"; $userM = new Application_Model_User(); $res = $userM->fetchAll($where, null, 11); $result = array(); foreach ($res as $row) { if (in_array($row->getId(), $friendids)) { //array_push($result, array("id"=>$row->getId(), "value" => $row->getFirstName())); $name = $row->getFirstName() . " " . $row->getLastName(); array_push($result, array("id" => $row->getId(), "value" => $name)); } } echo Zend_Json::encode($result); }
public function getUserFriend($user_id, $detail = false) { $arrFriend = array(); $friendM = new Application_Model_Friend(); $friends = $friendM->fetchAll("user_id='{$user_id}' and status='accept'"); if (count($friends) > 0) { foreach ($friends as $friend) { if ($detail == false) { $arrFriend[] = $friend->getFriendId(); } else { //send friend detail } } } else { return false; } return $arrFriend; }