|
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\Project; |
|
13
|
|
|
|
|
14
|
|
|
use Tinyissue\Contracts\Model\UserInterface; |
|
15
|
|
|
use Tinyissue\Model\Project; |
|
16
|
|
|
use Tinyissue\Model\User; |
|
17
|
|
|
use Tinyissue\Repository\Repository; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class Counter. |
|
21
|
|
|
* |
|
22
|
|
|
* @package Tinyissue\\User |
|
23
|
|
|
*/ |
|
24
|
|
|
class Counter extends Repository |
|
25
|
|
|
{ |
|
26
|
|
|
public function __construct(Project $model) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->model = $model; |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Count number of open issue in the project. |
|
33
|
|
|
* |
|
34
|
|
|
* @return int |
|
35
|
|
|
*/ |
|
36
|
|
|
public function countOpenIssues(UserInterface $limitByUser = null) |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->model->openIssues()->limitByCreatedForInternalProject($this->model, $limitByUser)->count(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Count number of closed issue in the project. |
|
43
|
|
|
* |
|
44
|
|
|
* @return int |
|
45
|
|
|
*/ |
|
46
|
|
|
public function countClosedIssues(UserInterface $limitByUser = null) |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->model->closedIssues()->limitByCreatedForInternalProject($this->model, $limitByUser)->count(); |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
return Project\Issue::join('projects', 'projects.id', '=', 'projects_issues.project_id') |
|
|
|
|
|
|
52
|
|
|
// ->where(function (Eloquent\Builder $query) { |
|
53
|
|
|
// $query->where('projects.status', '=', Project::STATUS_OPEN); |
|
54
|
|
|
// $query->where('projects_issues.status', '=', Project\Issue::STATUS_CLOSED); |
|
55
|
|
|
// }) |
|
56
|
|
|
->closed() |
|
57
|
|
|
// ->orWhere('projects_issues.status', '=', Project\Issue::STATUS_CLOSED) |
|
58
|
|
|
->count(); |
|
59
|
|
|
// if ($limitByUser && $limitByUser->isUser() && $this->isPrivateInternal()) { |
|
60
|
|
|
// $query->where('created_by', '=', $limitByUser->id); |
|
61
|
|
|
// } |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function countNotes() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->model->notes()->count(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Count number of assigned issues in a project. |
|
71
|
|
|
* |
|
72
|
|
|
* @param UserInterface $forUser |
|
73
|
|
|
* |
|
74
|
|
|
* @return int |
|
75
|
|
|
*/ |
|
76
|
|
|
public function countAssignedIssues(UserInterface $forUser) |
|
77
|
|
|
{ |
|
78
|
|
|
// return $this->issues()->open()->with('updatedBy'); |
|
79
|
|
|
|
|
80
|
|
|
return $this->model->openIssues()->assignedTo($forUser)->count(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Count number of private projects. |
|
85
|
|
|
* |
|
86
|
|
|
* @return int |
|
87
|
|
|
*/ |
|
88
|
|
|
public function countPrivateProjects() |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->model->notPublic()->count(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Count number of open projects. |
|
95
|
|
|
* |
|
96
|
|
|
* @return int |
|
97
|
|
|
*/ |
|
98
|
|
|
public function countActiveProjects() |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->model->active()->count(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Count number of archived projects. |
|
105
|
|
|
* |
|
106
|
|
|
* @return int |
|
107
|
|
|
*/ |
|
108
|
|
|
public function countArchivedProjects() |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->model->archived()->count(); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Count number of archived projects. |
|
115
|
|
|
* |
|
116
|
|
|
* @return int |
|
117
|
|
|
*/ |
|
118
|
|
|
public function countProjectsByStatus($status) |
|
119
|
|
|
{ |
|
120
|
|
|
if ($status === Project::STATUS_OPEN) { |
|
121
|
|
|
return $this->countActiveProjects(); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
return $this->countArchivedProjects(); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
//'active_projects' => $project->countActiveProjects(), |
|
128
|
|
|
//'archived_projects' => $project->countArchivedProjects(), |
|
129
|
|
|
// |
|
130
|
|
|
|
|
131
|
|
|
// |
|
132
|
|
|
|
|
133
|
|
|
// /** |
|
134
|
|
|
// * For eager loading: count number of issues. |
|
135
|
|
|
// * |
|
136
|
|
|
// * @return Eloquent\Relations\HasOne |
|
137
|
|
|
// */ |
|
138
|
|
|
// public function issuesCount() |
|
139
|
|
|
// { |
|
140
|
|
|
// return $this->issues() |
|
141
|
|
|
// ->selectRaw('project_id, count(*) as aggregate') |
|
142
|
|
|
// ->groupBy('project_id'); |
|
143
|
|
|
// } |
|
144
|
|
|
// |
|
145
|
|
|
|
|
146
|
|
|
// |
|
147
|
|
|
// |
|
148
|
|
|
// |
|
149
|
|
|
// /** |
|
150
|
|
|
// * Return projects with count of open & closed issues. |
|
151
|
|
|
// * |
|
152
|
|
|
// * @param array $projectIds |
|
153
|
|
|
// * |
|
154
|
|
|
// * @return Eloquent\Collection |
|
155
|
|
|
// */ |
|
156
|
|
|
// public function projectsWithCountIssues(array $projectIds) |
|
157
|
|
|
// { |
|
158
|
|
|
// return $this |
|
159
|
|
|
// ->with('openIssuesCount', 'closedIssuesCount') |
|
160
|
|
|
// ->whereIn('id', $projectIds) |
|
161
|
|
|
// ->get(); |
|
162
|
|
|
// } |
|
163
|
|
|
} |
|
164
|
|
|
|
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..