|
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\User; |
|
13
|
|
|
|
|
14
|
|
|
use Illuminate\Database\Eloquent\Builder; |
|
15
|
|
|
use Tinyissue\Model\Project; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* RelationTrait is trait class containing the relationship method for the User\Activity model. |
|
19
|
|
|
* |
|
20
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
|
21
|
|
|
* |
|
22
|
|
|
* @property static $this |
|
23
|
|
|
*/ |
|
24
|
|
View Code Duplication |
trait ActivityScopes |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
public function scopeLoadRelatedDetails(Builder $query) |
|
27
|
|
|
{ |
|
28
|
|
|
return $query->with('activity', 'issue', 'user', 'assignTo', 'comment', 'note') |
|
29
|
|
|
->orderBy('users_activity.created_at', 'DESC'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function scopeLimitResultForUserRole(Builder $query) |
|
33
|
|
|
{ |
|
34
|
|
|
// For logged users with role User, show issues that are created by them in internal projects |
|
35
|
|
|
// of issue create by any for other project statuses |
|
36
|
|
|
$user = $this->getLoggedUser(); |
|
|
|
|
|
|
37
|
|
|
if (!is_null($user) && !$user->isUser()) { |
|
38
|
|
|
$query->join('projects_issues', 'projects_issues.id', '=', 'item_id'); |
|
39
|
|
|
$query->join('projects', 'projects.id', '=', 'parent_id'); |
|
40
|
|
|
$query->where(function (Builder $query) use ($user) { |
|
41
|
|
|
$query->where(function (Builder $query) use ($user) { |
|
42
|
|
|
$query->where('created_by', '=', $user->id); |
|
43
|
|
|
$query->where('private', '=', Project::INTERNAL_YES); |
|
44
|
|
|
}); |
|
45
|
|
|
$query->orWhere('private', '<>', Project::INTERNAL_YES); |
|
46
|
|
|
}); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
return $query; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
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.