1 | <?php |
||
43 | trait CrudTagTrait |
||
44 | { |
||
45 | /** |
||
46 | * Change the status of an issue. |
||
47 | * |
||
48 | * @param int $status |
||
49 | * @param int $userId |
||
50 | * |
||
51 | * @return Eloquent\Model |
||
52 | */ |
||
53 | 5 | public function changeStatus($status, $userId) |
|
76 | |||
77 | /** |
||
78 | * Sync the issue tags. |
||
79 | * |
||
80 | * @param array $input |
||
81 | * @param Collection $currentTags |
||
82 | * |
||
83 | * @return bool |
||
84 | */ |
||
85 | 28 | public function syncTags(array $input, Collection $currentTags = null) |
|
86 | { |
||
87 | 28 | $tagIds = array_only($input, [ |
|
88 | 28 | 'tag_type', 'tag_status', 'tag_resolution', |
|
89 | ]); |
||
90 | 28 | $tags = (new Tag())->whereIn('id', $tagIds)->get(); |
|
91 | |||
92 | 28 | $removedTags = []; |
|
93 | 28 | if (null === $currentTags) { |
|
94 | // Add the following tags except for open status |
||
95 | $addedTags = $tags |
||
96 | ->map(function (Tag $tag) { |
||
97 | 2 | return $tag->toShortArray(); |
|
98 | 28 | }) |
|
99 | 28 | ->toArray(); |
|
100 | } else { |
||
101 | // Tags remove from the issue |
||
102 | $removedTags = $currentTags |
||
103 | 1 | ->diff($tags) |
|
104 | ->map(function (Tag $tag) { |
||
105 | return $tag->toShortArray(); |
||
106 | 1 | }) |
|
107 | 1 | ->toArray(); |
|
108 | |||
109 | // Check if we are adding new tags |
||
110 | $addedTags = $tags |
||
111 | ->filter(function (Tag $tag) use ($currentTags) { |
||
112 | return $currentTags->where('id', $tag->id)->count() === 0; |
||
113 | 1 | }) |
|
114 | 1 | ->map(function (Tag $tag) { |
|
115 | return $tag->toShortArray(); |
||
116 | 1 | }) |
|
117 | 1 | ->toArray(); |
|
118 | |||
119 | // No new tags to add or remove |
||
120 | 1 | if (empty($removedTags) && empty($addedTags)) { |
|
121 | 1 | return true; |
|
122 | } |
||
123 | } |
||
124 | |||
125 | // Save relation |
||
126 | 28 | $this->tags()->sync($tags->lists('id')->all()); |
|
127 | |||
128 | // Activity is added when new issue create with tags or updated with tags excluding the open status tag |
||
129 | 28 | if (!empty($removedTags) || !empty($addedTags)) { |
|
130 | // Add to activity log for tags if changed |
||
131 | 2 | $this->activities()->save(new User\Activity([ |
|
132 | 2 | 'type_id' => Activity::TYPE_ISSUE_TAG, |
|
133 | 2 | 'parent_id' => $this->project->id, |
|
134 | 2 | 'user_id' => $this->user->id, |
|
135 | 2 | 'data' => ['added_tags' => $addedTags, 'removed_tags' => $removedTags], |
|
136 | ])); |
||
137 | } |
||
138 | |||
139 | 28 | return true; |
|
140 | } |
||
141 | |||
142 | /** |
||
143 | * Add tag to the issue & close issue if added tag is Closed. |
||
144 | * |
||
145 | * @param Tag $newTag |
||
146 | * @param Tag $oldTag |
||
147 | * |
||
148 | * @return $this |
||
149 | */ |
||
150 | public function changeKanbanTag(Tag $newTag, Tag $oldTag) |
||
183 | } |
||
184 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.