@@ -111,22 +111,22 @@ public function denyFriendRequest(Model $recipient)
111
111
112
112
/**
113
113
* @param Model $friend
114
- * @param $groupSlug
114
+ * @param string $group
115
115
* @return bool
116
116
*/
117
- public function groupFriend (Model $ friend , $ groupSlug )
117
+ public function groupFriend (Model $ friend , $ group )
118
118
{
119
119
120
120
$ friendship = $ this ->findFriendship ($ friend )->whereStatus (Status::ACCEPTED )->first ();
121
- $ groupsAvailable = config ('friendships.groups ' , []);
121
+ $ groupsAvailable = config ('friendships.groups ' , []);
122
122
123
- if (!isset ($ groupsAvailable [$ groupSlug ]) || empty ($ friendship )) {
124
- return false ;
123
+ if (!isset ($ groupsAvailable [$ group ]) || empty ($ friendship )) {
124
+ return false ;
125
125
}
126
126
127
127
$ group = $ friendship ->groups ()->firstOrCreate ([
128
128
'friendship_id ' => $ friendship ->id ,
129
- 'group_id ' => $ groupsAvailable [ $ groupSlug ] ,
129
+ 'group_slug ' => $ group ,
130
130
'friend_id ' => $ friend ->getKey (),
131
131
'friend_type ' => $ friend ->getMorphClass (),
132
132
]);
@@ -137,10 +137,10 @@ public function groupFriend(Model $friend, $groupSlug)
137
137
138
138
/**
139
139
* @param Model $friend
140
- * @param $groupSlug
140
+ * @param string $group
141
141
* @return bool
142
142
*/
143
- public function ungroupFriend (Model $ friend , $ groupSlug = '' )
143
+ public function ungroupFriend (Model $ friend , $ group = "" )
144
144
{
145
145
146
146
$ friendship = $ this ->findFriendship ($ friend )->first ();
@@ -156,8 +156,8 @@ public function ungroupFriend(Model $friend, $groupSlug = '')
156
156
'friend_type ' => $ friend ->getMorphClass (),
157
157
];
158
158
159
- if ('' !== $ groupSlug && isset ($ groupsAvailable [$ groupSlug ])) {
160
- $ where ['group_id ' ] = $ groupsAvailable [ $ groupSlug ] ;
159
+ if ('' !== $ group && isset ($ groupsAvailable [$ group ])) {
160
+ $ where ['group_slug ' ] = $ group ;
161
161
}
162
162
163
163
$ result = $ friendship ->groups ()->where ($ where )->delete ();
@@ -213,34 +213,34 @@ public function getFriendship(Model $recipient)
213
213
/**
214
214
* @return \Illuminate\Database\Eloquent\Collection
215
215
*
216
- * @param string $groupSlug
216
+ * @param string $group
217
217
*
218
218
*/
219
- public function getAllFriendships ($ groupSlug = '' )
219
+ public function getAllFriendships ($ group = '' )
220
220
{
221
- return $ this ->findFriendships (null , $ groupSlug )->get ();
221
+ return $ this ->findFriendships (null , $ group )->get ();
222
222
}
223
223
224
224
/**
225
225
* @return \Illuminate\Database\Eloquent\Collection
226
226
*
227
- * @param string $groupSlug
227
+ * @param string $group
228
228
*
229
229
*/
230
- public function getPendingFriendships ($ groupSlug = '' )
230
+ public function getPendingFriendships ($ group = '' )
231
231
{
232
- return $ this ->findFriendships (Status::PENDING , $ groupSlug )->get ();
232
+ return $ this ->findFriendships (Status::PENDING , $ group )->get ();
233
233
}
234
234
235
235
/**
236
236
* @return \Illuminate\Database\Eloquent\Collection
237
237
*
238
- * @param string $groupSlug
238
+ * @param string $group
239
239
*
240
240
*/
241
- public function getAcceptedFriendships ($ groupSlug = '' )
241
+ public function getAcceptedFriendships ($ group = '' )
242
242
{
243
- return $ this ->findFriendships (Status::ACCEPTED , $ groupSlug )->get ();
243
+ return $ this ->findFriendships (Status::ACCEPTED , $ group )->get ();
244
244
}
245
245
246
246
/**
@@ -294,13 +294,13 @@ public function getFriendRequests()
294
294
* It will return the 'friends' models. ex: App\User
295
295
*
296
296
* @param int $perPage Number
297
- * @param string $groupSlug
297
+ * @param string $group
298
298
*
299
299
* @return \Illuminate\Database\Eloquent\Collection
300
300
*/
301
- public function getFriends ($ perPage = 0 , $ groupSlug = '' )
301
+ public function getFriends ($ perPage = 0 , $ group = '' )
302
302
{
303
- return $ this ->getOrPaginate ($ this ->getFriendsQueryBuilder ($ groupSlug ), $ perPage );
303
+ return $ this ->getOrPaginate ($ this ->getFriendsQueryBuilder ($ group ), $ perPage );
304
304
}
305
305
306
306
/**
@@ -343,13 +343,13 @@ public function getFriendsOfFriends($perPage = 0)
343
343
/**
344
344
* Get the number of friends
345
345
*
346
- * @param string $groupSlug
346
+ * @param string $group
347
347
*
348
348
* @return integer
349
349
*/
350
- public function getFriendsCount ($ groupSlug = '' )
350
+ public function getFriendsCount ($ group = '' )
351
351
{
352
- $ friendsCount = $ this ->findFriendships (Status::ACCEPTED , $ groupSlug )->count ();
352
+ $ friendsCount = $ this ->findFriendships (Status::ACCEPTED , $ group )->count ();
353
353
return $ friendsCount ;
354
354
}
355
355
@@ -413,11 +413,11 @@ private function findFriendship(Model $recipient)
413
413
414
414
/**
415
415
* @param $status
416
- * @param string $groupSlug
416
+ * @param string $group
417
417
*
418
418
* @return \Illuminate\Database\Eloquent\Collection
419
419
*/
420
- private function findFriendships ($ status = null , $ groupSlug = '' )
420
+ private function findFriendships ($ status = null , $ group = '' )
421
421
{
422
422
423
423
$ query = Friendship::where (function ($ query ) {
@@ -426,7 +426,7 @@ private function findFriendships($status = null, $groupSlug = '')
426
426
})->orWhere (function ($ q ) {
427
427
$ q ->whereRecipient ($ this );
428
428
});
429
- })->whereGroup ($ this , $ groupSlug );
429
+ })->whereGroup ($ this , $ group );
430
430
431
431
//if $status is passed, add where clause
432
432
if (!is_null ($ status )) {
@@ -439,14 +439,14 @@ private function findFriendships($status = null, $groupSlug = '')
439
439
/**
440
440
* Get the query builder of the 'friend' model
441
441
*
442
- * @param string $groupSlug
442
+ * @param string $group
443
443
*
444
444
* @return \Illuminate\Database\Eloquent\Builder
445
445
*/
446
- private function getFriendsQueryBuilder ($ groupSlug = '' )
446
+ private function getFriendsQueryBuilder ($ group = '' )
447
447
{
448
448
449
- $ friendships = $ this ->findFriendships (Status::ACCEPTED , $ groupSlug )->get (['sender_id ' , 'recipient_id ' ]);
449
+ $ friendships = $ this ->findFriendships (Status::ACCEPTED , $ group )->get (['sender_id ' , 'recipient_id ' ]);
450
450
$ recipients = $ friendships ->pluck ('recipient_id ' )->all ();
451
451
$ senders = $ friendships ->pluck ('sender_id ' )->all ();
452
452
@@ -481,11 +481,11 @@ private function getMutualFriendsQueryBuilder(Model $other)
481
481
/**
482
482
* Get the query builder for friendsOfFriends ('friend' model)
483
483
*
484
- * @param string $groupSlug
484
+ * @param string $group
485
485
*
486
486
* @return \Illuminate\Database\Eloquent\Builder
487
487
*/
488
- private function friendsOfFriendsQueryBuilder ($ groupSlug = '' )
488
+ private function friendsOfFriendsQueryBuilder ($ group = '' )
489
489
{
490
490
$ friendships = $ this ->findFriendships (Status::ACCEPTED )->get (['sender_id ' , 'recipient_id ' ]);
491
491
$ recipients = $ friendships ->pluck ('recipient_id ' )->all ();
@@ -502,7 +502,7 @@ private function friendsOfFriendsQueryBuilder($groupSlug = '')
502
502
$ q ->whereIn ('recipient_id ' , $ friendIds );
503
503
});
504
504
})
505
- ->whereGroup ($ this , $ groupSlug )
505
+ ->whereGroup ($ this , $ group )
506
506
->get (['sender_id ' , 'recipient_id ' ]);
507
507
508
508
$ fofIds = array_unique (
@@ -535,12 +535,18 @@ public function groups()
535
535
{
536
536
return $ this ->morphMany (FriendFriendshipGroups::class, 'friend ' );
537
537
}
538
-
538
+
539
+ /**
540
+ * @param $builder
541
+ * @param $perPage
542
+ * @return mixed
543
+ */
539
544
protected function getOrPaginate ($ builder , $ perPage )
540
545
{
541
546
if ($ perPage == 0 ) {
542
547
return $ builder ->get ();
543
548
}
544
549
return $ builder ->paginate ($ perPage );
545
550
}
551
+
546
552
}
0 commit comments