/** * @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])); }
/** * @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)); }
/** * Returns all user this user is related as friend as ActiveQuery. * Returns null if the friendship module is deactivated. * @return ActiveQuery */ public function getFriends() { if (Yii::$app->getModule('friendship')->getIsEnabled()) { return \humhub\modules\friendship\models\Friendship::getFriendsQuery($this); } return null; }
public function actionList() { $dataProvider = new ActiveDataProvider(['query' => Friendship::getFriendsQuery($this->getUser()), 'pagination' => ['pageSize' => 20]]); return $this->render('list', ['user' => $this->getUser(), 'dataProvider' => $dataProvider]); }