Esempio n. 1
0
 function addFriend()
 {
     $id = max(0, (int) $_POST['id']);
     $current_user = new CurrentUser();
     if ($current_user->authorized) {
         if ($current_user->id != $id) {
             $user_following = $current_user->getFollowing();
             $friend = Users::getById($id);
             /* @var $friend User */
             $friend_followers = $friend->getFollowers();
             $user_following[$id] = $id;
             $friend_followers[$current_user->id] = $current_user->id;
             $current_user->setFollowing($user_following);
             $friend->setFollowers($friend_followers);
             $friend->onNewFollower($current_user->id);
             $current_user->onNewFollowing($id);
             $friend->save();
             $current_user->save();
         }
     }
 }