| @@ 222-244 (lines=23) @@ | ||
| 219 | * |
|
| 220 | * @return Eloquent\Collection |
|
| 221 | */ |
|
| 222 | protected function sortByTag(HasMany $query, $tagGroup, $order = 'asc') |
|
| 223 | { |
|
| 224 | // If tag group is string prefixed with tag: |
|
| 225 | if (!is_numeric($tagGroup)) { |
|
| 226 | $tagGroup = substr($tagGroup, strlen('tag:')); |
|
| 227 | } |
|
| 228 | ||
| 229 | $results = $query->get() |
|
| 230 | ->sort(function (Project\Issue $issue1, Project\Issue $issue2) use ($tagGroup, $order) { |
|
| 231 | $tag1 = $issue1->tags->where('parent.id', $tagGroup, false)->first(); |
|
| 232 | $tag2 = $issue2->tags->where('parent.id', $tagGroup, false)->first(); |
|
| 233 | $tag1 = $tag1 ? $tag1->name : ''; |
|
| 234 | $tag2 = $tag2 ? $tag2->name : ''; |
|
| 235 | ||
| 236 | if ($order === 'asc') { |
|
| 237 | return strcmp($tag1, $tag2); |
|
| 238 | } |
|
| 239 | ||
| 240 | return strcmp($tag2, $tag1); |
|
| 241 | }); |
|
| 242 | ||
| 243 | return $results; |
|
| 244 | } |
|
| 245 | ||
| 246 | /** |
|
| 247 | * Returns projects with open issue count. |
|
| @@ 50-72 (lines=23) @@ | ||
| 47 | * |
|
| 48 | * @return Eloquent\Collection |
|
| 49 | */ |
|
| 50 | public function sortByTag(HasMany $query, $tagGroup, $order = 'asc') |
|
| 51 | { |
|
| 52 | // If tag group is string prefixed with tag: |
|
| 53 | if (!is_numeric($tagGroup)) { |
|
| 54 | $tagGroup = substr($tagGroup, strlen('tag:')); |
|
| 55 | } |
|
| 56 | ||
| 57 | $results = $query->get() |
|
| 58 | ->sort(function (Project\Issue $issue1, Project\Issue $issue2) use ($tagGroup, $order) { |
|
| 59 | $tag1 = $issue1->tags->where('parent.id', $tagGroup, false)->first(); |
|
| 60 | $tag2 = $issue2->tags->where('parent.id', $tagGroup, false)->first(); |
|
| 61 | $tag1 = $tag1 ? $tag1->name : ''; |
|
| 62 | $tag2 = $tag2 ? $tag2->name : ''; |
|
| 63 | ||
| 64 | if ($order === 'asc') { |
|
| 65 | return strcmp($tag1, $tag2); |
|
| 66 | } |
|
| 67 | ||
| 68 | return strcmp($tag2, $tag1); |
|
| 69 | }); |
|
| 70 | ||
| 71 | return $results; |
|
| 72 | } |
|
| 73 | } |
|
| 74 | ||