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\Model\Traits\User; |
13
|
|
|
|
14
|
|
|
use Illuminate\Database\Eloquent\Builder; |
15
|
|
|
use Illuminate\Database\Eloquent\Relations; |
16
|
|
|
use Tinyissue\Model\Project; |
17
|
|
|
use Tinyissue\Model\User; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* CountTrait is trait class containing the methods for counting database records for the User model. |
21
|
|
|
* |
22
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
23
|
|
|
* |
24
|
|
|
* @property static $this |
25
|
|
|
*/ |
26
|
|
|
trait CountTrait |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @param int $deleted |
30
|
|
|
* |
31
|
|
|
* @return int |
32
|
|
|
*/ |
33
|
2 |
|
public static function countUsers($deleted = User::NOT_DELETED_USERS) |
34
|
|
|
{ |
35
|
2 |
|
return User::where('deleted', '=', $deleted)->count(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Count number of assigned issues in a project. |
40
|
|
|
* |
41
|
|
|
* @param int $projectId |
42
|
|
|
* |
43
|
|
|
* @return int |
44
|
|
|
*/ |
45
|
20 |
|
public function assignedIssuesCount($projectId = 0) |
|
|
|
|
46
|
|
|
{ |
47
|
20 |
|
$issues = $this->issues(); |
|
|
|
|
48
|
|
|
|
49
|
20 |
|
if (0 < $projectId) { |
50
|
20 |
|
$issues = $issues->where('project_id', '=', $projectId); |
51
|
|
|
} |
52
|
20 |
|
$issues->where('status', '=', Project\Issue::STATUS_OPEN); |
53
|
|
|
|
54
|
20 |
|
return $issues->count(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Count number of created issues in a project. |
59
|
|
|
* |
60
|
|
|
* @param int $projectId |
61
|
|
|
* |
62
|
|
|
* @return int |
63
|
|
|
*/ |
64
|
2 |
|
public function createdIssuesCount($projectId = 0) |
|
|
|
|
65
|
|
|
{ |
66
|
2 |
|
$issues = $this->issuesCreatedBy(); |
67
|
|
|
|
68
|
2 |
|
if (0 < $projectId) { |
69
|
2 |
|
$issues = $issues->where('project_id', '=', $projectId); |
70
|
|
|
} |
71
|
2 |
|
$issues->where('status', '=', Project\Issue::STATUS_OPEN); |
72
|
|
|
|
73
|
2 |
|
return $issues->count(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Returns all projects with open issue count. |
78
|
|
|
* |
79
|
|
|
* @param int $status |
80
|
|
|
* |
81
|
|
|
* @return Builder|Relations\BelongsToMany |
82
|
|
|
*/ |
83
|
3 |
|
public function projectsWithCountOpenIssues($status = Project::STATUS_OPEN) |
84
|
|
|
{ |
85
|
3 |
|
if ($this->permission('project-all')) { |
86
|
3 |
|
$project = new Project(); |
87
|
|
|
|
88
|
3 |
|
return $project->projectsWithOpenIssuesCount($status, Project::PRIVATE_ALL); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return $this->projects($status)->with('openIssuesCount'); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
abstract public function issuesCreatedBy(); |
95
|
|
|
|
96
|
|
|
abstract public function permission($key); |
97
|
|
|
} |
98
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.