1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Fenos\Notifynder\Groups; |
4
|
|
|
|
5
|
|
|
use Fenos\Notifynder\Contracts\NotifynderCategory; |
6
|
|
|
use Fenos\Notifynder\Contracts\NotifynderGroupCategoryDB; |
7
|
|
|
use Fenos\Notifynder\Models\NotificationCategory; |
8
|
|
|
use Fenos\Notifynder\Models\NotificationGroup; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class NotificationGroupCategoryRepository. |
12
|
|
|
*/ |
13
|
|
|
class GroupCategoryRepository implements NotifynderGroupCategoryDB |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var NotificationGroup |
17
|
|
|
*/ |
18
|
|
|
protected $notificationGroup; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var NotificationCategory |
22
|
|
|
*/ |
23
|
|
|
protected $notificationCategory; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param NotifynderCategory $notificationCategory |
27
|
|
|
* @param NotificationGroup $notificationGroup |
28
|
|
|
*/ |
29
|
|
|
public function __construct(NotifynderCategory $notificationCategory, |
30
|
|
|
NotificationGroup $notificationGroup) |
31
|
|
|
{ |
32
|
|
|
$this->notificationCategory = $notificationCategory; |
|
|
|
|
33
|
|
|
$this->notificationGroup = $notificationGroup; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Add a category in a group. |
38
|
|
|
* |
39
|
|
|
* @param $groupId |
40
|
|
|
* @param $categoryId |
41
|
|
|
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|static |
42
|
|
|
*/ |
43
|
|
|
public function addCategoryToGroupById($groupId, $categoryId) |
44
|
|
|
{ |
45
|
|
|
$group = $this->notificationGroup->find($groupId); |
|
|
|
|
46
|
|
|
$group->categories()->attach($categoryId); |
47
|
|
|
|
48
|
|
|
return $group; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Add a category in a group |
53
|
|
|
* by names given. |
54
|
|
|
* |
55
|
|
|
* @param $groupName |
56
|
|
|
* @param $categoryName |
57
|
|
|
* @return mixed |
58
|
|
|
*/ |
59
|
|
View Code Duplication |
public function addCategoryToGroupByName($groupName, $categoryName) |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$group = $this->notificationGroup->where('name', $groupName)->first(); |
|
|
|
|
62
|
|
|
|
63
|
|
|
$category = $this->notificationCategory->findByName($categoryName); |
|
|
|
|
64
|
|
|
|
65
|
|
|
$group->categories()->attach($category->id); |
66
|
|
|
|
67
|
|
|
return $group; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Add multiple categories by them names |
72
|
|
|
* to a group. |
73
|
|
|
* |
74
|
|
|
* @param $groupName |
75
|
|
|
* @param $names |
76
|
|
|
* @return mixed |
77
|
|
|
*/ |
78
|
|
View Code Duplication |
public function addMultipleCategoriesToGroup($groupName, array $names) |
|
|
|
|
79
|
|
|
{ |
80
|
|
|
$group = $this->notificationGroup->where('name', $groupName)->first(); |
|
|
|
|
81
|
|
|
|
82
|
|
|
$categories = $this->notificationCategory->findByNames($names); |
|
|
|
|
83
|
|
|
|
84
|
|
|
foreach ($categories as $category) { |
85
|
|
|
$group->categories()->attach($category->id); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $group; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..