public function actionDeleteFriend()
 {
     $a = array();
     if (Yii::app()->request->isAjaxRequest) {
         $post = $_POST['UserFriends'];
         $model = UserFriends::model()->findByAttributes(array('user_id' => Yii::app()->user->id, 'friend_id' => $post['friend_id']));
         if (isset($model)) {
             $model->attributes = $post;
             if ($model->validate()) {
                 $model->status = 1;
                 if ($model->delete()) {
                     $a = array('message' => 'Пользователь успешно удален из друзей', 'errorCode' => 0);
                 } else {
                     $a = array('message' => Yii::t('core', 'ERROR'), 'errorCode' => 1);
                 }
             } else {
                 $a = array('message' => $model->errors['user_id'], 'errorCode' => 2);
             }
         } else {
             $a = array('message' => Yii::t('core', 'ERROR'), 'errorCode' => 3);
         }
     } else {
         $a = array('message' => Yii::t('core', 'ERROR'), 'errorCode' => 4);
     }
     echo CJSON::encode($a);
 }
 public function run()
 {
     $friends = UserFriends::model()->getFriends($this->user_id);
     $friends_count = UserFriends::model()->getFriendsCount($this->user_id);
     if ($friends_count != null && $friends_count > 0) {
         $this->render('userfriends', array('friends' => $friends, 'friends_count' => $friends_count));
     }
 }
 public function run()
 {
     /** user friends query **/
     $criteria = new CDbCriteria();
     $criteria->condition = 'user_id=:id';
     $criteria->limit = $this->count;
     $criteria->order = 'RAND()';
     $user_id = $this->user_id;
     $criteria->params = array(':id' => $user_id);
     $guests = UserFriends::model()->findAll($criteria);
     $guests_count = UserFriends::model()->count($criteria);
     /** user friends query **/
     if ($guests_count != null && $guests_count > 0) {
         $this->render('userguests', array('guests' => $guests, 'guests_count' => $guests_count));
     }
 }
 public function actionIndex()
 {
     Yii::app()->clientScript->registerScript('global_user_id', 'var glUserId = ' . $id . ';', CClientScript::POS_HEAD);
     // хуй знает что это
     $myFriends = UserFriends::model()->getFriends($this->myProfile->user_id);
     foreach ($myFriends as $key => $item) {
         $friends .= ', ' . $item->friend_id;
     }
     $friends = trim($friends, ',');
     $wall = new Posts();
     // Получаем последние 10 постов
     $wall->_limit = Yii::app()->params->maxPostPerRequest;
     // Количество получаемых постов
     Yii::app()->clientScript->registerPackage('profile-index');
     $this->render('index', array('myProfile' => $this->myProfile, 'wall' => $wall->getMyFeed($friends)));
 }
 public function actionDeleteFriendship()
 {
     $id = Yii::app()->user->id;
     if (!$id > 0) {
         throw new CException('Not Found', 404);
     }
     $u_id = $_GET['id'];
     $f_id = $_GET['f_id'];
     $is_my_request_a = UserFriends::model()->find('status = 1 and user_id = ' . $f_id . ' and friend_id = ' . $u_id);
     $is_my_request_b = UserFriends::model()->find('status = 1 and user_id = ' . $u_id . ' and friend_id = ' . $f_id);
     if ($is_my_request_a && $is_my_request_b) {
         $reject_request_a = UserFriends::model()->find('user_id = ' . $f_id . ' and friend_id = ' . $u_id);
         $reject_request_a->status = '2';
         $reject_request_a->save();
         $reject_request_b = UserFriends::model()->find('user_id = ' . $u_id . ' and friend_id = ' . $f_id);
         $reject_request_b->status = '3';
         $reject_request_b->save();
         echo json_encode(array('status' => 'ok', 'data' => '<a onclick="confirmRequest(this, \'' . $this->createUrl('profile/profile/ConfirmRequest', array('id' => $u_id, 'f_id' => $f_id)) . '\')" href="#" class="blue">' . Yii::t('site', 'Принять заявку') . '</a>' . ' ' . '<a onclick="rejectRequest(this, \'' . $this->createUrl('profile/profile/RejectRequest', array('id' => $u_id, 'f_id' => $f_id)) . '\')" href="#" class="blue">' . Yii::t('site', 'Удалить заявку') . '</a>'));
     }
 }
 public function run($args)
 {
     $userfriend = UserFriends::model()->find("id=5", array(":USERID" => 5, ":FRIENDID" => 6));
     print $userfriend->id;
 }
Exemple #7
0
 * @var UserProfile $profile
 * @var User $user
 * @var Controller $this
 */
$this->pageTitle = Yii::t('usersModule.site', 'Profile ' . $user->username);
?>

<h2><?php 
echo Yii::t('usersModule.site', 'Profile ' . $user->username);
?>
</h2>
<?php 
$label = $user->attributeLabels();
echo UserFriends::addFriendButton($user->id);
echo UserFriends::activeFriendButton($user->id);
echo UserFriends::deleteFriendButton($user->id);
if (!$user->banned) {
    ?>
<table border="1" width="100%">

        <tr>
        <td><?php 
    echo $label['username'];
    ?>
</td>
        <td><?php 
    echo $user->username;
    ?>
</td>
    </tr>
    <tr>
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = UserFriends::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
<div class="list_box_other">
    <div class="users_list">
        <div class="users_list_inner">
            <?php 
if (empty($item['avatar']) || !is_file(Yii::app()->request->baseUrl . '/photos/' . $item['avatar'])) {
    $item['avatar'] = '/images/avatar/default_profile.png';
} else {
    $item['avatar'] = '/images/small/' . $item['avatar'];
}
$current_loged_user = Yii::app()->user->id;
$man_id = $item['user_id'];
$mutual_friends = UserMutualFriends::model()->getMutualFriends($current_loged_user, $man_id);
$count_mutual_friends = count($mutual_friends);
$are_friends = UserFriends::model()->areFriends($current_loged_user, $man_id);
//echo 'words'.$words;
//$words=array();
echo '<div class="list_avatar_other"><a href="/id' . $item['user_id'] . '"><img width="150" src="' . Yii::app()->request->baseUrl . $item['avatar'] . '" alt="" title="' . $item['first_name'] . ' ' . $item['second_name'] . '" /></a></div>';
echo '<div class="f_name"><a class="grey" href="/id' . $item['user_id'] . '">' . $this->highlightMatch($words, $item['first_name']) . ' ' . $this->highlightMatch($words, $item['second_name']) . '</a></div>';
if ($man_id === $current_loged_user) {
    echo '<a class="blue_little">Это Вы</a>';
} elseif ($count_mutual_friends != null) {
    echo '<div class="mutual_friends_link"><a class="blue_little" href="/id' . $current_loged_user . '/mutual/fid' . $man_id . '">Общих друзей: ' . $count_mutual_friends . '</a></div>';
} else {
    echo '<a class="blue_little">У вас нету общих друзей.</a>';
}
if ($man_id !== $current_loged_user) {
    echo '<div class="uf_links_block">';
    echo '<div class="uf_links"><a class="grey_little" href="#">Написать сообщение</a></div>';
    echo '<div class="uf_links"><a class="grey_little" href="/id' . $man_id . '/myfriends">Показать друзей</a></div>';
    if ($are_friends == 'friends') {
        echo '<div class="uf_links"><a class="grey_little" href="#">Убрать из друзей</a></div>';
Exemple #10
0
<?php

$partname = CHtml::encode($profile->first_name) . " " . CHtml::encode($profile->second_name);
/* проверка на взаимосвязь дружбы */
$u_id = Yii::app()->user->id;
$c_u_id = $_GET['id'];
$are_friends = UserFriends::model()->areFriends($u_id, $c_u_id);
$pos = explode(' ', $profile->bgposition);
$pos = count($pos) == 2 ? $pos : array(0, 0);
?>
<div class="userName">
    <h1><?php 
echo $partname;
?>
 
        <?php 
if ($profile->user_id == Yii::app()->user->id) {
    ?>
            <a href="<?php 
    echo $this->createUrl('profile/profile/edit', array('id' => $profile->user_id));
    ?>
"><?php 
    echo Yii::t('site', 'изменить');
    ?>
</a>

        <?php 
} elseif ($are_friends == 'friends') {
    ?>
            <span><a onclick="deleteFriendship(this,'<?php 
    echo $this->createUrl('profile/profile/DeleteFriendship', array('id' => $u_id, 'f_id' => $c_u_id));
Exemple #11
0
 public function getFriends($everything = false)
 {
     if ($everything) {
         $condition = 'user_id = :uid';
     } else {
         $condition = 'user_id = :uid and status = 2';
     }
     $friends = array();
     Yii::import('application.models.UserFriends');
     $friendships = UserFriends::model()->findAll($condition, array(':uid' => $this->id));
     if ($friendships != NULL && !is_array($friendships)) {
         $friendships = array($friendships);
     }
     if ($friendships) {
         foreach ($friendships as $friendship) {
             $friends[] = User::model()->findByPk($friendship->friend_id);
         }
     }
     if ($everything) {
         $condition = 'friend_id = :uid';
     } else {
         $condition = 'friend_id = :uid and status = 2';
     }
     $friendships = UserFriends::model()->findAll($condition, array(':uid' => $this->id));
     if ($friendships != NULL && !is_array($friendships)) {
         $friendships = array($friendships);
     }
     if ($friendships) {
         foreach ($friendships as $friendship) {
             $friends[] = User::model()->findByPk($friendship->user_id);
         }
     }
     return $friends;
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUserFriends0()
 {
     return $this->hasMany(UserFriends::className(), ['user_id' => 'id']);
 }
 public static function areFriends($uid1, $uid2)
 {
     if (is_numeric($uid1) && is_numeric($uid2)) {
         $friendship = UserFriends::model()->find('status = 1 and user_id = ' . $uid1 . ' and friend_id = ' . $uid2);
         if ($friendship) {
             return 'friends';
         }
         $friendship = UserFriends::model()->find('status = 1 and user_id = ' . $uid2 . ' and friend_id = ' . $uid1);
         if ($friendship) {
             return 'friends';
         }
         $friendship = UserFriends::model()->find('status = 2 and user_id = ' . $uid1 . ' and friend_id = ' . $uid2);
         if ($friendship) {
             return 'myrequest';
         }
         $friendship = UserFriends::model()->find('status = 3 and user_id = ' . $uid1 . ' and friend_id = ' . $uid2);
         if ($friendship) {
             return 'request';
         }
     }
     return 'false';
 }