public function getFriends($pageNumber, $pageSize) { $mutualFriendships = Friendship::find()->where(['user_id' => $this->id, 'mutual' => true])->offset($pageNumber * $pageSize)->limit($pageSize)->all(); $friends = []; foreach ($mutualFriendships as $friendship) { $friend = $friendship->friend; $friends[] = $friend; } return $friends; }
public function actionDelete($userId, $friendId) { $friendship = Friendship::findOne(['user_id' => $userId, 'friend_id' => $friendId]); if ($friendship === null) { throw new Exception('Friendship was not found'); } $friendshipSummary = $friendship->jsonSummary; $transaction = Yii::$app->db->beginTransaction(); try { // Mutuality update is handled in Friendship EVENT_AFTER_DELETE if (!$friendship->delete()) { throw new DbException('Could not delete friendship'); } $transaction->commit(); } catch (Exception $exception) { $transaction->rollBack(); throw $exception; } return $friendshipSummary; }
/** * @return \yii\db\ActiveQuery */ public function getFriendships() { return $this->hasMany(Friendship::className(), ['whom_profile_id' => 'id', 'agg_whom_user_id' => 'user_id', 'agg_circle_id' => 'circle_id']); }
public function getRelatedFriendship() { $relatedFriendship = Friendship::findOne(['user_id' => $this->friend_id, 'friend_id' => $this->user_id]); return $relatedFriendship; }
public function isFriendsWith(User $user) { return Friendship::where(['recipient_id' => $this->id, 'accepted' => true, 'sender_id' => $user->id])->orWhere(['sender_id' => $this->id, 'accepted' => true, 'recipient_id' => $user->id])->get(); }