コード例 #1
0
ファイル: User.php プロジェクト: Kolyunya/friends
 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;
 }
コード例 #2
0
 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;
 }
コード例 #3
0
ファイル: Profile.php プロジェクト: playdayteam/jdocgen
 /**
  * @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']);
 }
コード例 #4
0
ファイル: Friendship.php プロジェクト: Kolyunya/friends
 public function getRelatedFriendship()
 {
     $relatedFriendship = Friendship::findOne(['user_id' => $this->friend_id, 'friend_id' => $this->user_id]);
     return $relatedFriendship;
 }
コード例 #5
0
 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();
 }