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\Relations; |
15
|
|
|
use Tinyissue\Contracts\Model\UserInterface; |
16
|
|
|
use Tinyissue\Model\Permission; |
17
|
|
|
use Tinyissue\Model\Project; |
18
|
|
|
use Tinyissue\Repository\Repository; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class Counter. |
22
|
|
|
* |
23
|
|
|
* @package Tinyissue\\User |
24
|
|
|
*/ |
25
|
|
|
class Counter extends Repository |
26
|
|
|
{ |
27
|
|
|
public function __construct(UserInterface $model) |
28
|
|
|
{ |
29
|
|
|
$this->model = $model; |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param int $deleted |
|
|
|
|
34
|
|
|
* |
35
|
|
|
* @return int |
36
|
|
|
*/ |
37
|
|
|
public function countNotDeleted() |
38
|
|
|
{ |
39
|
|
|
return $this->model->notDeleted()->count(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param int $deleted |
|
|
|
|
44
|
|
|
* |
45
|
|
|
* @return int |
46
|
|
|
*/ |
47
|
|
|
public function countDeleted() |
48
|
|
|
{ |
49
|
|
|
return $this->model->deleted()->count(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Count number of created issues in a project. |
54
|
|
|
* |
55
|
|
|
* @param int $projectId |
56
|
|
|
* |
57
|
|
|
* @return int |
58
|
|
|
*/ |
59
|
|
View Code Duplication |
public function createdIssuesCount($projectId = 0) |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$issues = $this->model->issuesCreatedBy(); |
62
|
|
|
|
63
|
|
|
if (0 < $projectId) { |
64
|
|
|
$issues = $issues->where('project_id', '=', $projectId); |
65
|
|
|
} |
66
|
|
|
$issues->where('status', '=', Project\Issue::STATUS_OPEN); |
67
|
|
|
|
68
|
|
|
return $issues->count(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Returns all projects with open issue count. |
73
|
|
|
* |
74
|
|
|
* @param int $status |
75
|
|
|
* |
76
|
|
|
* @return Builder|Relations\BelongsToMany |
77
|
|
|
*/ |
78
|
|
|
public function projectsWithCountOpenIssues($status = Project::STATUS_OPEN) |
79
|
|
|
{ |
80
|
|
|
// TODO not nice |
81
|
|
|
if ($this->model->isManager() || $this->model->isAdmin()) { |
82
|
|
|
$project = new Project(); |
83
|
|
|
|
84
|
|
|
return $project->projectsWithOpenIssuesCount($status, Project::PRIVATE_ALL); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $this->model->projects($status)->with('openIssuesCount'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Count number of archived projects. |
92
|
|
|
* |
93
|
|
|
* @return int |
94
|
|
|
*/ |
95
|
|
|
public function countProjectsByStatus($status) |
96
|
|
|
{ |
97
|
|
View Code Duplication |
if ($this->model->isManager() || $this->model->isAdmin()) { |
|
|
|
|
98
|
|
|
return app()->make(Project::class)->countProjectsByStatus($status); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return $this->model->projects()->status($status)->count(); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
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..