public function handleRequest() { $arr = array('idusers' => $_SESSION['UID']); $content = Place::findMyPlaces($arr); $friend = Friend::find($arr); render('home', array('title' => "" . $_SESSION['UNAME'] . ' Welcome to the Places', 'content' => $content, 'friend' => $friend)); }
public function run() { $uid = Yii::app()->user->id; $ret = array(); if (!$uid) { $ret = array('state' => 'error', 'message' => Yii::t('common', 'You Need Login')); } else { $act = Yii::app()->request->getParam('act'); $friendid = Yii::app()->request->getParam('id'); $friend = User::model()->findByPk($friendid); if (!$friend) { $ret = array('state' => 'error', 'message' => Yii::t('common', 'Add Friend Failed')); } else { $friend_mod = new Friend(); if ($act == 'friend') { $exist_friend = $friend_mod->find('user_id = :uid AND friend_user_id = :friendid', array(':uid' => $uid, ':friendid' => $friendid)); if ($exist_friend) { $ret = array('state' => 'error', 'message' => Yii::t('common', 'You are Friend')); } else { //添加好友 $friend_mod->user_id = $uid; $friend_mod->friend_user_id = $friendid; if ($friend_mod->save()) { $ret = array('state' => 'success', 'message' => Yii::t('common', 'Add Friend Success')); } else { $ret = array('state' => 'error', 'message' => Yii::t('common', 'Add Friend Failed')); } } } else { $ret = array('state' => 'error', 'message' => Yii::t('common', 'Operation Failed')); } } } exit(CJSON::encode($ret)); }
public function run($id) { $controller = $this->getController(); $this->_setting = $controller->_setting; $this->_stylePath = $controller->_stylePath; $this->_static_public = $controller->_static_public; $myself = false; //加载css,js Yii::app()->clientScript->registerCssFile($this->_stylePath . "/css/user.css"); Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/jquery/jquery.js"); //用户信息 $user = User::model()->findByPk($id); //当前登录用户 $uid = Yii::app()->user->id; if (!$user) { throw new CHttpException(404, Yii::t('common', 'The requested page does not exist.')); exit; } else { $data = array(); $group = UserGroup::model()->findByPk($user->groupid); $data['uid'] = $user->uid; $data['username'] = $user->username; $data['email'] = $user->email; $data['register_ip'] = $user->register_ip; $data['last_login_ip'] = $user->last_login_ip; $data['group_name'] = $group->group_name; $data['mobile'] = $user->mobile; $data['web'] = $user->web; $data['qq'] = $user->qq; $data['addtime'] = $user->addtime; $data['avatar'] = $user->avatar; $data['sign'] = $user->sign; //SEO $controller->_seoTitle = $user->username . ' - ' . Yii::t('common', 'User Space') . ' - ' . $this->_setting['site_name']; //判断是否是自己 if ($uid == $user->uid) { $myself = true; } //判断是否是好友 $friend_mod = new Friend(); $friend = $friend_mod->find('uid1=:uid AND uid2=:friendid', array(':uid' => $uid, ':friendid' => $user->uid)); if (!$friend) { $friend = $friend_mod->find('uid1=:uid AND uid2=:friendid', array(':uid' => $user->uid, ':friendid' => $uid)); } } $controller->render('user_space', array('user' => $data, 'myself' => $myself, 'friend' => $friend)); }
public function friendAction() { $friendRequestID = Input::get('request_id'); $isAccept = Input::get('approve_function'); if ($isAccept) { $friendModel = new Friend(); $friendModel->acceptRequest($friendRequestID); return Redirect::to('friends')->with('message', 'Request Accepted'); } else { $friendModel = Friend::find($friendRequestID); $friendModel->delete(); return Redirect::to('friends')->with('message', 'Request Declined'); } }
public function acceptRequest($requestID) { DB::transaction(function () use($requestID) { $friendModel = Friend::find($requestID); $requestingUserID = $friendModel->user_id; $acceptingUserID = $friendModel->friend_user_id; $friendModel->isAccepted = 1; $friendModel->save(); $newFriendModel = new Friend(); $newFriendModel->user_id = $acceptingUserID; $newFriendModel->friend_user_id = $requestingUserID; $newFriendModel->isAccepted = 1; $newFriendModel->save(); }); return true; }
public function getFriendsToInvite($uid, $groupId, $start = 0, $limit = 0) { $groupUsers = GroupUser::find("groupId", $groupId)->all(); $result = Friend::find("uid", $uid)->join("user"); if ($groupUsers != null && !empty($groupUsers)) { $where = "[fid] not in("; $args = []; for ($count = count($groupUsers), $i = 0; $i < $count; $i++) { $where .= "?" . ($i < $count - 1 ? "," : ""); $args[] = $groupUsers[$i]->userId; } unset($groupUsers); $where .= ")"; $result = $result->where($where, $args); } return $limit != 0 || $start != 0 ? $result->range($start, $limit) : $result->all(); }
public function handleRequest() { // Fetch all the places: $friends = Friend::find(array('idusers' => $_SESSION['UID'])); render('friend', array('title' => 'Browsing friends', 'friends' => $friends)); }
public function actionCancel($userId = null) { $uid = Rays::user()->id; $friend = Friend::find(['uid', $uid, 'fid', $userId])->first(); if ($friend != null) { $friend->delete(); } $friend = Friend::find(['fid', $uid, 'uid', $userId])->first(); if ($friend != null) { $friend->delete(); } $this->redirectAction('user', 'view', $userId); }
/** * User home page */ public function actionHome() { $this->layout = 'user'; $user = Rays::user(); $data = array('user' => $user); $defaultSize = 10; $friends = Friend::find("uid", $user->id)->all(); foreach ($friends as $friend) { $ids[] = $friend->fid; } $ids[] = $user->id; $query = Topic::find()->join("user")->join("group")->join("rating")->in("User.id", $ids)->order_desc("id"); // ajax request // load more posts if (Rays::isAjax()) { $lastLoadedTime = @$_POST['lastLoadedTime']; $lastLoadedTime = $lastLoadedTime != '' ? $lastLoadedTime : null; $topics = $query->where("[createdTime] < ?", $lastLoadedTime)->range(0, $defaultSize); $result = array(); if (count($topics) > 0) { $result['content'] = $this->renderPartial('_posts_list', array('topics' => $topics), true); $result['lastLoadTime'] = $topics[count($topics) - 1]->createdTime; echo json_encode($result); } else { echo json_encode(['content' => '']); } exit; } $data['topics'] = $query->range(0, $defaultSize); $this->setHeaderTitle($user->name); $this->addCss('/public/css/post.css'); $this->render('home', $data, false); }