/** * check if values $_REQUEST[''] exist - then get friend by id (existing friend) * if values not exist then create a new friend (new friend) * @return array */ protected function run() { if (array_key_exists('id', $_REQUEST) and $_REQUEST['id'] > 0) { $friend = Friends::getFriendByID($_REQUEST['id']); } else { $friend = new Friend(); } /** * if $_POST_[""] is not empty then set the values into the template * else set error massage if one of the $_POST[""] is empty */ if (!empty($_POST["name"]) and !empty($_POST["adress"]) and !empty($_POST["email"])) { $friend->setName($_POST["name"]); $friend->setAdress($_POST["adress"]); $friend->setEmail($_POST["email"]); /** * records can be saved after editing or creating * exit the program after a successful storage * error massage when email address exists because email address is unique */ if ($friend->save()) { header('location:index.php?module=listoffriends'); exit; } else { $var = array('fehler' => "Die Person existiert bereits in der Datenbank"); } } elseif (!empty($_POST["name"]) or !empty($_POST["adress"]) or !empty($_POST["email"])) { $var = array('fehler' => "Es sind nicht alle Datenfelder ausgefüllt"); } $var['friend'] = $friend; return $var; }
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 actionConfirm($userId = null) { $uid = Rays::user()->id; $userName = Rays::user()->name; $friend = Friend::find(['fid', $userId, 'uid', $uid])->first(); //only request exist can friendship be built $censor = (new Censor())->addFriendExist($userId, $uid); if ($censor === null) { $this->flash('warning', 'Request already processed'); } else { $censor->pass(); if ($friend == null) { //bug fixed by songrenchu: only new relationship need to be inserted $friend = new Friend(); $friend->fid = $userId; $friend->uid = $uid; $friend->save(); $friend = new Friend(); $friend->uid = $userId; $friend->fid = $uid; $friend->save(); $content = RHtml::linkAction('user', $userName, 'view', $uid) . " has accepted your friend request."; Message::sendMessage("system", $uid, $userId, "Friend confirmed", $content, ''); $this->flash('message', 'Friends confirmed.'); } else { $this->flash('warning', 'You two are already friends.'); } } $this->redirectAction('message', 'view', null); }
public function addFriendAction() { $prospectFriendUserID = Input::get('user_id'); $friendModel = new Friend(); $friendModel->user_id = Auth::user()->id; $friendModel->friend_user_id = $prospectFriendUserID; $friendModel->save(); return Redirect::to('home')->with('message', 'Friend Request Sent'); }
public function actionCreate() { $user = User::model()->throw404IfNull()->findByPk($_POST['friend_id']); $friend = new Friend(); $friend->user_a_id = Yii::app()->user->id; $friend->user_b_id = $user->id; if ($friend->save()) { if (isset($_POST['return']) && $_POST['return'] == 'user_view_item') { $this->renderPartial('application.modules.users.views.user._view', array('data' => $user)); } } else { echo CJSON::encode(array('errors' => $friend->errors_flat_array)); } }
public function executeAccept(sfWebRequest $request) { $friendRequest = new FriendRequest(); $friendRequest->uid_to = $this->getUser()->getAttribute('id'); $friendRequest->uid_from = $request->getParameter('uid'); $profile = Doctrine_Core::getTable('Profile')->findOneByUid($friendRequest->uid_from); $x = Doctrine_Core::getTable('FriendRequest')->createQuery('a')->where("uid_from = {$friendRequest->uid_from} AND uid_to = {$friendRequest->uid_to}")->execute(); $x->delete(); $friend = new Friend(); $friend->uid1 = $this->getUser()->getAttribute('id'); $friend->uid2 = $request->getParameter('uid'); $friend->save(); $this->getUser()->setFlash('info', "You successfully accepted {$profile->first_name}'s friend request."); $this->redirect($this->getUser()->getAttribute('redirect_back')); }
public function executeAdd() { $touserid = $this->getRequestParameter('id'); $touser = UserPeer::retrieveByPK($touserid); $fromuserid = $this->getUser()->getAttribute('userid'); $friend = new Friend(); $friend->setUserId($touserid); $friend->save(); $userfriend = new Userfriend(); $userfriend->setUserId($fromuserid); $userfriend->setFriendId($friend->getId()); $userfriend->save(); $this->setFlash('notice', '<font style="background-color: yellow"><b>' . $touser->getFullname() . '</b>has been marked as friend.</font>'); $this->redirect('search/result?page=' . $this->getUser()->getAttribute('srpage')); }
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 static function followPrestiges($userid) { try { $prestiges = CacheManager::getPrestigeCache(1000, 0); if (isset($prestiges) && is_array($prestiges)) { foreach ($prestiges as $prestige) { $friend = new Friend(); $friend->author_id = $userid; $friend->friend_id = $prestige['id']; $friend->friend_photo_url = $prestige['user_pic_url']; $friend->friend_username = $prestige['nickname']; $friend->create_date = new CDbExpression('NOW()'); $friend->status = Constants::OBJECT_APPROVAL; $friend->save(); User::model()->updateFanCount($prestige['id'], 1); } User::model()->updateFollowUserCount($userid, count($prestiges)); } } catch (Exception $e) { } }
public function __construct() { if (!pageArray(2)) { return false; } gateKeeper(); $user1 = getLoggedInUser(); $guid = pageArray(2); $user2 = getEntity($guid); if (!FriendsPlugin::friends($user1->guid, $user2->guid)) { // First check if the other user has already initiated a friend request $request = getEntity(array("type" => "Friend", "metadata_name_value_pairs" => array(array("name" => "guid_one", "value" => $guid), array("name" => "guid_two", "value" => $user1->guid), array("name" => "status", "value" => "new")))); if ($request) { FriendsPlugin::addFriend($user1->guid, $guid); forward(); } // Make sure there isn't already a friend request in the system $test = getEntities(array("type" => "Friend", "metadata_name_value_pairs" => array(array("name" => "guid_one", "value" => $user1->guid), array("name" => "guid_two", "value" => $guid)))); if (!$test) { $friend_request = new Friend(); $friend_request->guid_one = $user1->guid; $friend_request->guid_two = $guid; $friend_request->status = "requested"; $friend_request->requested_by = getLoggedInUserGuid(); $friend_request->save(); $friend_request = new Friend(); $friend_request->guid_one = $guid; $friend_request->guid_two = $user1->guid; $friend_request->status = "requested"; $friend_request->requested_by = getLoggedInUserGuid(); $friend_request->save(); new SystemMessage("Your friend request has been sent."); notifyUser("friend", $user2->guid, $user1->guid, $user2->guid); } forward(); } forward(); }
/** * 好友添加 */ public function actionAdd() { $model = new Friend(); $uid = Yii::app()->user->id; $fuid = Yii::app()->request->getParam('id'); $msg = ''; //不允许加自己好友 if ($fuid == $uid) { $msg = '不允许自己加自己好友'; } $t = Yii::app()->request->getParam('t'); //加好友的权限设置 if ($t != "agree") { //$model->__checkeFriendPrivacy($fuid); } //检查好友状态 $is_add = $model->checkFriendStatus($uid, $fuid); if ("1" === $is_add) { $msg = '你们已经是好友了'; } elseif ("0" === $is_add) { $msg = '等待验证中'; } //对方已经发过请求了,直接就加为好友 if ("0" === $model->checkFriendStatus($fuid, $uid)) { //并且弹出好友分组页面 //$model->__straightAddFrends($fuid,intval($_GET['nid'])); } $model->fuid = $fuid; if (isset($_POST['Friend'])) { $model->attributes = $_POST['Friend']; if ($model->save()) { $this->redirect(array('list')); } } $data = array('model' => $model, 'msg' => $msg); if (Yii::app()->request->isAjaxRequest) { $this->renderPartial('create', $data); } else { $this->render('create', $data); } }
public function actionSendFriendRequest() { if (isset($_POST['idUser'])) { if (!Friend::areFriendsOrFriendRequest(Yii::app()->user->getId(), $_POST['idUser'])) { $friendRequest = new Friend(); $friendRequest->idUserFrom = Yii::app()->user->getId(); $friendRequest->idUserTo = $_POST['idUser']; $friendRequest->createDate = date('Y-m-d, H:i:s'); if ($friendRequest->save()) { echo "A friend request has been sent!"; } return; } echo "You are already friends or have a Friend Request processing"; return; } }
public function postSendFriendRequest() { $user_id = Auth::user()->id; $friend_id = Input::get('friend_id'); if ($user_id === $friend_id) { return Response::json(array('status' => 'failed')); } try { $friend = User::findOrFail($friend_id); if (Auth::user()->friendship($friend) != Friend::STRANGER) { throw new Exception("Already friend or waiting request"); } $friendship = new Friend(); $friendship->user_id = $friend_id; $friendship->friend_id = $user_id; $friendship->type = Friend::REQUESTING; $friendship->save(); return Response::json(array('status' => 'requested')); } catch (Exception $e) { return Response::json(array('status' => 'failed')); } }
public function add_friend($friend, $group) { if (!$this->username) { return array('r' => 'error', 'e' => 'no session found'); } $friend = new Friend($this->username, $friend, $group); $friend_obj_id = $friend->save(); if ($friend_obj_id) { $friend_arr = Friend::get($friend_obj_id); $this->memcache->set('user/' . $this->username . '/friends/add', json_encode($friend_arr)); return array('r' => 'added'); } else { return array('r' => 'error', 'e' => 'invalid user'); } }
public static function CreateRequest($from, $to, $message) { $request = new Friend(); $request->User_ID = $from; $request->Friend_User_ID = $to; $request->Status = FriendStatus::AwaitingApproval; $request->RequestMessage = $message; if ($request->save()) { $fromUser = User::model()->findByPk($from); $fromLink = CHtml::link($fromUser->fullName, array('/user/view', 'id' => $from)); Message::SendNotification($to, "Friend request from {$fromLink}", $message, $from, MessageType::FriendRequest); } return $request; }
public function followFriends($friends) { if (isset($friends) && is_array($friends)) { $transaction = Yii::app()->db->beginTransaction(); try { $userid = Yii::app()->user->id; $count = 0; foreach ($friends as $id) { if ($id === $userid) { continue; } $user = User::model()->findByPk($id); if (isset($user) && !is_null($user)) { $friendt = $this->getFriend($userid, $id); if (!(isset($friendt) && !is_null($friendt) && $friendt->status == Constants::OBJECT_APPROVAL)) { if (isset($friendt) && !is_null($friendt)) { $friendt->status = Constants::OBJECT_APPROVAL; $friendt->save(); } else { $friend = new Friend(); $friend->author_id = $userid; $friend->friend_id = $id; $friend->friend_photo_url = $user->user_photo_url; $friend->friend_username = $user->nickname; $friend->create_date = new CDbExpression('NOW()'); $friend->status = Constants::OBJECT_APPROVAL; $friend->save(); } $count++; $user->fan_number = $user->fan_number + 1; $user->save(); //add dynamic $dynamic = new Dynamic(); $dynamic->author_id = $userid; $dynamic->content_id = $id; $dynamic->status = Constants::OBJECT_APPROVAL; $dynamic->create_date = new CDbExpression('NOW()'); $dynamic->content_name = $user->nickname; $dynamic->dynamic_type = Constants::DYNAMIC_TYPE_FOLLOW; $dynamic->content_pic_url = $user->user_photo_url; $dynamic->save(); //ADD NOTIFY MSG $msg = new NotifyMsg(); $msg->author_id = $id; $msg->nofity_user_id = Yii::app()->user->id; $msg->notify_user_name = Yii::app()->user->getState("nickname"); $msg->notify_user_pic_url = Yii::app()->user->getState("pic_url"); $msg->created_date = new CDbExpression('NOW()'); $msg->status = Constants::OBJECT_APPROVAL; $msg->notify_type = Constants::NOTIFY_TYPE_FOLLOW; $msg->save(); } } } if ($count > 0) { User::model()->updateFollowUserCount($userid, $count); } $transaction->commit(); return true; } catch (Exception $e) { $transaction->rollback(); return false; } } return true; }
function addFriend($params) { $guid1 = $params['guid1']; $user1 = getEntity($guid1); $guid2 = $params['guid2']; $user2 = getEntity($guid2); if (!FriendsPlugin::friends($user1->guid, $user2->guid)) { // First check if the other user has already initiated a friend request $request = getEntity(array("type" => "Friend", "metadata_name_value_pairs" => array(array("name" => "guid_one", "value" => $guid1), array("name" => "guid_two", "value" => $user1->guid), array("name" => "status", "value" => "new")))); if ($request) { FriendsPlugin::addFriend($guid1, $guid2); return; } // Make sure there isn't already a friend request in the system $test = getEntities(array("type" => "Friend", "metadata_name_value_pairs" => array(array("name" => "guid_one", "value" => $guid1), array("name" => "guid_two", "value" => $guid2)))); if (!$test) { $friend_request = new Friend(); $friend_request->guid_one = $guid1; $friend_request->guid_two = $guid2; $friend_request->status = "requested"; $friend_request->requested_by = $guid1; $friend_request->save(); $friend_request = new Friend(); $friend_request->guid_one = $guid2; $friend_request->guid_two = $guid1; $friend_request->status = "requested"; $friend_request->requested_by = $guid1; $friend_request->save(); } notifyUser("friend", $guid2, $guid1, $guid2); } return "success"; }
static function addFriend($guid_one, $guid_two) { $friendship = getEntity(array("type" => "Friend", "metadata_name_value_pairs" => array(array("name" => "guid_one", "value" => $guid_one), array("name" => "guid_two", "value" => $guid_two)))); if ($friendship) { $friendship->status = "accepted"; $friendship->save(); $friendship_two = getEntity(array("type" => "Friend", "metadata_name_value_pairs" => array(array("name" => "guid_one", "value" => $guid_two), array("name" => "guid_two", "value" => $guid_one)))); $friendship_two->status = "accepted"; $friendship_two->save(); } else { $friendship = new Friend(); $friendship->guid_one = $guid_one; $friendship->guid_two = $guid_two; $friendship->status = "accepted"; $friendship->save(); $friendship = new Friend(); $friendship->guid_one = $guid_two; $friendship->guid_two = $guid_one; $friendship->status = "accepted"; $friendship->save(); } $user1 = getEntity($guid_one); $user2 = getEntity($guid_two); new Activity(getLoggedInUserGuid(), translate("activity_feed:friend:add", array($user1->getURL(), $user1->full_name, $user2->getURL(), $user2->full_name))); new SystemMessage(translate("add:friend:success", $user2->first_name . " " . $user2->last_name)); return; }
public function addFriend($profile) { if ($this->isFriend($profile)) { $friend = Doctrine_Query::create()->from('Friend f')->where('f.requester_id = ? and f.accepter_id = ?', array($profile->id, $this->id))->fetchOne(); if (!$friend) { return false; } $friend->accepted = true; } else { $friend = new Friend(); $friend->requester_id = $this->id; $friend->accepter_id = $profile->id; $friend->accepted = false; } $friend->save(); }
public function collectInfo() { $cmd_count = 0; // $categories = array('1' => 'check-in', '2' => 'link', '3' => 'status','4'=>'photo', '5' => 'video', '6' => 'comment', '7' => 'others',); $categories = array('2' => 'link', '3' => 'status', '5' => 'video', '4' => 'photo'); $facebook = $_SESSION['facebook']; //***************Set Times*********** $all_friends = $facebook->api('/me/friends'); $days_threshold = 3; ini_set('max_execution_time', 60 * 60); $start_time = mktime(0, 0, 0, date("m"), date("d") - $days_threshold, date("Y")); $end_time = time(); $time_step = 4 * 60 * 60; //for when FB did not return the posts for a whole period of time and we had to make sub-queries //***************Set User Attributes & Save in DB**************** $user = $facebook->getUser(); if ($user) { $this->fbid = $user; $this->start_time = date("Y-m-d H:i:s", $start_time); $this->end_time = date("Y-m-d H:i:s", $end_time); $this->created_at = new CDbExpression('NOW()'); if ($this->save()) { // Yii::log('success'); // echo 'success'; } else { print_r($this->getErrors()); } } else { // echo 'cannot save user in DB!'; } $cmd_count++; $i = 0; //****************Save All Friends' Basic information in DB******************* for ($f = 0; $f < sizeof($all_friends['data']); $f++) { $fbid = $all_friends['data'][$f]['id']; $friend = new Friend(); $friend->fbid = $fbid; $friend->name = $all_friends['data'][$f]['name']; $friend->user = $this->id; if ($friend->save()) { //Yii::log('success'); // echo 'success'; } else { Yii::log($this->getErrors()); print_r($this->getErrors()); } } //*************************************Fetch News Feed (Shown Stories)********************************* //******Before, querying the whole time period did not retreive the NewsFeed Posts => // I made it to time-slots using $time_step variable => // but now, it does not work! and querying over the whole period works well! So, I came back to the first method!******** // for ($ctime = $start_time; $ctime < $end_time; $ctime += $time_step) { // $accesToken = Yii::app()->facebook->getAccessToken(); // $cmd = "me/home?fields=id,from,type,link,story,picture,source,name,description,message&limit=500&since=" . $ctime . "&until=" . ($ctime + $time_step); $cmd = "me/home?fields=id,from,type,link,story,picture,source,name,description,message,created_time&limit=500&since=" . $start_time . "&until=" . $end_time; // $cmd = "me/home?fields=id,from,type,link,story,picture,source,name,description,message&limit=500"; $me = $facebook->api($cmd); echo "cmd: " . $cmd . "<br>"; echo "size of data: " . sizeof($me['data']) . '<br>'; $cmd_count++; //************Save News Feed Stories at DB************ $saved_shown_posts_count = 0; for ($j = 0; $j < sizeof($me['data']); $j++) { $postdata = new PostData(); $postdata->user = $this->id; if (isset($me['data'][$j]['id'])) { $postdata->post_id = $me['data'][$j]['id']; // echo 'post_id(all): '. $postdata->post_id. '<br>'; } if (isset($me['data'][$i]['from'])) { //Save post's authors' attributes if (isset($me['data'][$i]['from']['id'])) { $postdata->from_id = $me['data'][$j]['from']['id']; // this is the author's Facebook ID. } if (isset($me['data'][$j]['from']['name'])) { $postdata->from_name = $me['data'][$j]['from']['name']; } if (isset($postdata->from_id)) { // $friend_id = Friend::model()->find('fbid=:fbid AND user=:user', array(':fbid' => $postdata->from_id, ':user' => $this->id)); $friend_obj = Friend::model()->find(array('select' => 'id', 'condition' => 'fbid=:fbid AND user=:user', 'params' => array(':fbid' => $postdata->from_id, ':user' => $this->id))); //echo $friend_id['id'] . '<br>'; if (isset($friend_obj['id'])) { $postdata->friend = $friend_obj['id']; //this is the autor's Database ID and it needs to be saved! } } } if (isset($me['data'][$j]['description'])) { $postdata->description = $me['data'][$j]['description']; } if (isset($me['data'][$j]['name'])) { $postdata->name = $me['data'][$j]['name']; } if (isset($me['data'][$j]['story'])) { $postdata->story = $me['data'][$j]['story']; } if (isset($me['data'][$j]['link'])) { $postdata->link = $me['data'][$j]['link']; } if (isset($me['data'][$j]['picture'])) { $postdata->picture = $me['data'][$j]['picture']; } if (isset($me['data'][$j]['message'])) { $postdata->message = $me['data'][$j]['message']; } if (isset($me['data'][$j]['source'])) { $postdata->source = $me['data'][$j]['source']; } if (isset($me['data'][$j]['created_time'])) { echo "time: " . $me['data'][$j]['created_time'] . '<br>'; $timestamp = strtotime($me['data'][$j]['created_time']); $postdata->created_time = date($timestamp); } if (isset($me['data'][$j]['type'])) { $postdata->type = $me['data'][$j]['type']; } //*****Save postdata***** if ($postdata->save()) { } else { //Yii::log($postdata->getErrors()); //echo 'cannot save this post since:<br>'; //print_r($postdata->getErrors()); return; } } }
private function updateBot(Bot $bot) { if (rand(0, 100) < 20) { $f = new Friend(); $f->setAccepter($bot->getProfile()); $f->setRequester($this->getRandomBot()->getProfile()); if (rand(0, 100) < 85) { $f->setAccepted(1); } try { $f->save(); } catch (Exception $e) { fb($e->getMessage()); } } $maxVoters = rand(0, 2); $voters = $maxVoters - round(atan(sqrt(rand(0, 10000) / 10000)) * $maxVoters); for ($i = 0; $i < $voters; $i++) { $v = new VoteProfile(); $v->setProfile($bot->getProfile()); $v->setValue($this->getRandomBot()->getProfile()->getForce()); $v->setVoter($this->getRandomBot()->getProfile()); $v->save(); } }
public function actionAddFriend($id) { $friends = Friend::model()->findByAttributes(array('from_id' => $id, 'to_id' => Yii::app()->user->getId())); if ($friends == null) { $friends_rec = new Friend(); $friends_rec->from_id = Yii::app()->user->getId(); $friends_rec->to_id = $id; $friends_rec->save(); $friends_rec = new Friend(); $friends_rec->to_id = Yii::app()->user->getId(); $friends_rec->from_id = $id; $friends_rec->save(); } $this->redirect(array("user/profile", "id" => $id)); }