/** * @inheritdoc */ public function run() { if ($this->user->isCurrentUser() || \Yii::$app->user->isGuest) { return; } if (Yii::$app->getModule('friendship')->getIsEnabled()) { // Don't show follow button, when friends if (Friendship::getFriendsQuery($this->user)->one() !== null) { return; } } // Add class for javascript handling $this->followOptions['class'] .= ' followButton'; $this->unfollowOptions['class'] .= ' unfollowButton'; // Hide inactive button if ($this->user->isFollowedByUser()) { $this->followOptions['style'] .= ' display:none;'; } else { $this->unfollowOptions['style'] .= ' display:none;'; } // Add UserId Buttons $this->followOptions['data-userid'] = $this->user->id; $this->unfollowOptions['data-userid'] = $this->user->id; $this->view->registerJsFile('@web/resources/user/followButton.js'); return Html::a($this->unfollowLabel, $this->user->createUrl('/user/profile/unfollow'), $this->unfollowOptions) . Html::a($this->followLabel, $this->user->createUrl('/user/profile/follow'), $this->followOptions); }
/** * @inheritdoc */ public function init() { $friendCount = Friendship::getFriendsQuery($this->user)->count(); $this->addItem(array('label' => Yii::t('FriendshipModule.base', 'Friends') . ' (' . $friendCount . ')', 'url' => Url::toRoute(['/friendship/manage/list']), 'sortOrder' => 100, 'isActive' => Yii::$app->controller->id == 'manage' && Yii::$app->controller->action->id == 'list')); $receivedRequestsCount = Friendship::getReceivedRequestsQuery($this->user)->count(); $this->addItem(array('label' => Yii::t('FriendshipModule.base', 'Requests' . ' (' . $receivedRequestsCount . ')'), 'url' => Url::toRoute(['/friendship/manage/requests']), 'sortOrder' => 200, 'isActive' => Yii::$app->controller->id == 'manage' && Yii::$app->controller->action->id == 'requests')); $sentRequestsCount = Friendship::getSentRequestsQuery($this->user)->count(); $this->addItem(array('label' => Yii::t('FriendshipModule.base', 'Sent requests' . ' (' . $sentRequestsCount . ')'), 'url' => Url::toRoute(['/friendship/manage/sent-requests']), 'sortOrder' => 300, 'isActive' => Yii::$app->controller->id == 'manage' && Yii::$app->controller->action->id == 'sent-requests')); parent::init(); }
/** * @inheritdoc */ public function run() { if (!Yii::$app->getModule('friendship')->getIsEnabled()) { return; } $querz = Friendship::getFriendsQuery($this->user); $totalCount = $querz->count(); $friends = $querz->limit($this->limit)->all(); return $this->render('friendsPanel', array('friends' => $friends, 'friendsShowLimit' => $this->limit, 'totalCount' => $totalCount, 'limit' => $this->limit, 'user' => $this->user)); }
/** * Returns an list of all friends of a user */ public function actionPopup() { $user = User::findOne(['id' => Yii::$app->request->get('userId')]); if ($user === null) { throw new \yii\web\HttpException(404, 'Could not find user!'); } $query = Friendship::getFriendsQuery($user); $title = '<strong>' . Yii::t('FriendshipModule.base', "Friends") . '</strong>'; return $this->renderAjaxContent(UserListBox::widget(['query' => $query, 'title' => $title])); }
/** * Declines or Deletes Friendship */ public function actionDelete() { $this->forcePostRequest(); $friend = User::findOne(['id' => Yii::$app->request->get('userId')]); if ($friend === null) { throw new \yii\web\HttpException(404, 'User not found!'); } Friendship::cancel(Yii::$app->user->getIdentity(), $friend); return $this->redirect($friend->getUrl()); }
/** * @inheritdoc */ public function run() { $friendshipsEnabled = Yii::$app->getModule('friendship')->getIsEnabled(); $countFriends = 0; if ($friendshipsEnabled) { $countFriends = Friendship::getFriendsQuery($this->user)->count(); } $countFollowing = $this->user->getFollowingCount(User::className()) + $this->user->getFollowingCount(Space::className()); $countUserSpaces = Membership::getUserSpaceQuery($this->user)->andWhere(['!=', 'space.visibility', Space::VISIBILITY_NONE])->andWhere(['space.status' => Space::STATUS_ENABLED])->count(); return $this->render('profileHeader', array('user' => $this->user, 'isProfileOwner' => $this->isProfileOwner, 'friendshipsEnabled' => $friendshipsEnabled, 'countFriends' => $countFriends, 'countFollowers' => $this->user->getFollowerCount(), 'countFollowing' => $countFollowing, 'countSpaces' => $countUserSpaces)); }
/** * @inheritdoc */ public function run() { if (!Yii::$app->getModule('friendship')->getIsEnabled()) { return; } // Do not display a buttton if user is it self or guest if ($this->user->isCurrentUser() || \Yii::$app->user->isGuest) { return; } return $this->render('friendshipButton', array('user' => $this->user, 'friendshipState' => Friendship::getStateForUser(Yii::$app->user->getIdentity(), $this->user))); }
/** * TODO: deprecated * @inheritdoc */ public function getUserGroup() { if (Yii::$app->user->isGuest) { return self::USERGROUP_GUEST; } elseif (Yii::$app->user->getIdentity()->id === $this->id) { return self::USERGROUP_SELF; } if (Yii::$app->getModule('friendship')->getIsEnabled()) { if (Friendship::getStateForUser($this, Yii::$app->user->getIdentity()) === Friendship::STATE_FRIENDS) { return self::USERGROUP_FRIEND; } } return self::USERGROUP_USER; }
<!-- BEGIN: Results --> <?php foreach ($users as $user) { ?> <li> <div class="media"> <!-- Follow Handling --> <div class="pull-right"> <?php echo \humhub\modules\user\widgets\UserFollowButton::widget(['user' => $user, 'followOptions' => ['class' => 'btn btn-primary btn-sm'], 'unfollowOptions' => ['class' => 'btn btn-info btn-sm']]); ?> <?php if (!Yii::$app->user->isGuest && !$user->isCurrentUser() && Yii::$app->getModule('friendship')->getIsEnabled()) { $friendShipState = Friendship::getStateForUser(Yii::$app->user->getIdentity(), $user); if ($friendShipState === Friendship::STATE_NONE) { echo Html::a('<span class="glyphicon glyphicon-plus"></span> ' . Yii::t("FriendshipModule.base", "Add Friend"), Url::to(['/friendship/request/add', 'userId' => $user->id]), array('class' => 'btn btn-primary btn-sm', 'data-method' => 'POST')); } elseif ($friendShipState === Friendship::STATE_FRIENDS) { echo Html::a('<span class="glyphicon glyphicon-ok"></span> ' . Yii::t("FriendshipModule.base", "Friends"), $user->getUrl(), ['class' => 'btn btn-info btn-sm']); } } ?> </div> <a href="<?php echo $user->getUrl(); ?> " class="pull-left"> <img class="media-object img-rounded" src="<?php
/** * Cancels a friendship or request to a friend * * @param User $user * @param User $friend */ public static function cancel($user, $friend) { // Delete friends entry $myFriendship = Friendship::findOne(['user_id' => $user->id, 'friend_user_id' => $friend->id]); $friendsFriendship = Friendship::findOne(['user_id' => $friend->id, 'friend_user_id' => $user->id]); if ($friendsFriendship !== null) { $friendsFriendship->delete(); } if ($myFriendship !== null) { $myFriendship->delete(); } elseif ($friendsFriendship !== null) { // Is declined friendship request - send declined notification $notification = new \humhub\modules\friendship\notifications\RequestDeclined(); $notification->originator = $user; $notification->send($friend); } }
public function actionSentRequests() { $dataProvider = new ActiveDataProvider(['query' => Friendship::getSentRequestsQuery($this->getUser()), 'pagination' => ['pageSize' => 20]]); return $this->render('sent-requests', ['user' => $this->getUser(), 'dataProvider' => $dataProvider]); }