|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Tinyissue package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Mohamed Alsharaf <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Tinyissue\Repository\User; |
|
13
|
|
|
|
|
14
|
|
|
use Illuminate\Database\Eloquent; |
|
15
|
|
|
use Illuminate\Database\Eloquent\Relations; |
|
16
|
|
|
use Tinyissue\Contracts\Model\UserInterface; |
|
17
|
|
|
use Tinyissue\Model\Permission; |
|
18
|
|
|
use Tinyissue\Model\Project; |
|
19
|
|
|
use Tinyissue\Model\User; |
|
20
|
|
|
use Tinyissue\Repository\Repository; |
|
21
|
|
|
|
|
22
|
|
|
class Fetcher extends Repository |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var User |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $model; |
|
28
|
|
|
|
|
29
|
|
|
public function __construct(UserInterface $model) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->model = $model; |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Returns projects the user member of. |
|
36
|
|
|
* |
|
37
|
|
|
* @return Eloquent\Collection |
|
38
|
|
|
*/ |
|
39
|
|
|
public function getProjects() |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->model->projects()->get(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function getProjectsWithSettings() |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->model->projects()->with('projectUsers')->get(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Returns public users. |
|
51
|
|
|
* |
|
52
|
|
|
* @return Eloquent\Collection |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getActiveUsers() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->model->with('role')->private()->orderBy('firstname')->get(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Returns user projects with activities details eager loaded. |
|
61
|
|
|
* |
|
62
|
|
|
* @param int $status |
|
63
|
|
|
* @done |
|
64
|
|
|
* |
|
65
|
|
|
* @return Relations\HasMany |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getProjectsWithRecentActivities($status = Project::STATUS_OPEN) |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->model->projects($status)->with('recentActivities')->get(); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Returns projects with issues details eager loaded. |
|
74
|
|
|
* |
|
75
|
|
|
* @return Relations\HasMany |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getProjectsWithRecentIssues() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->model |
|
|
|
|
|
|
80
|
|
|
->active() |
|
81
|
|
|
->with('issues.user', 'issues.countComments') |
|
82
|
|
|
->with([ |
|
83
|
|
|
'openIssuesWithUpdater' => function (Relations\Relation $query) { |
|
84
|
|
|
$assignedOrCreate = $this->model->isUser() ? 'createdBy' : 'assignedTo'; |
|
85
|
|
|
$query->$assignedOrCreate($this->id); |
|
|
|
|
|
|
86
|
|
|
}, |
|
87
|
|
|
]) |
|
88
|
|
|
->orderBy('name') |
|
89
|
|
|
->get(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function getIssuesGroupByTags(Eloquent\Collection $tagIds, $projectId = null) |
|
93
|
|
|
{ |
|
94
|
|
|
$tagIds = $tagIds->pluck('id')->all(); |
|
95
|
|
|
|
|
96
|
|
|
$assignedOrCreate = $this->model->isUser() ? 'issuesCreatedBy' : 'issues'; |
|
97
|
|
|
$issues = $this->model->$assignedOrCreate() |
|
98
|
|
|
->with('user', 'tags') |
|
99
|
|
|
->open() |
|
100
|
|
|
->forProject($projectId) |
|
101
|
|
|
->join('projects_issues_tags', 'issue_id', '=', 'id') |
|
102
|
|
|
->whereIn('projects_issues_tags.tag_id', $tagIds) |
|
103
|
|
|
->orderBy('id') |
|
104
|
|
|
->get() |
|
105
|
|
|
->groupBy(function (Project\Issue $issue) { |
|
106
|
|
|
return $issue->getStatusTag()->name; |
|
|
|
|
|
|
107
|
|
|
}) |
|
108
|
|
|
// ->get() |
|
109
|
|
|
; |
|
110
|
|
|
|
|
111
|
|
|
return $issues; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Returns all projects with open issue count. |
|
116
|
|
|
* |
|
117
|
|
|
* @param int $status |
|
118
|
|
|
* |
|
119
|
|
|
* @return Builder|Relations\BelongsToMany |
|
120
|
|
|
*/ |
|
121
|
|
|
public function getProjectsWithOpenIssuesCount($status = Project::STATUS_OPEN) |
|
122
|
|
|
{ |
|
123
|
|
View Code Duplication |
if ($this->model->isManager() || $this->model->isAdmin()) { |
|
|
|
|
|
|
124
|
|
|
return app()->make(Project::class)->getProjectsWithOpenIssuesCount($status, Project::PRIVATE_ALL); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
return $this->model->projects()->status($status)->with('openIssuesCount')->get(); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.