Completed
Push — develop-3.0 ( 360277...bd5ff0 )
by Mohamed
06:52
created

ProjectScopes::scopeNotPublic()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
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;
13
14
use Illuminate\Database\Eloquent\Builder;
15
16
/**
17
 * ProjectScopes is trait class containing the model scope methods.
18
 *
19
 * @author Mohamed Alsharaf <[email protected]>
20
 *
21
 * @property static $this
22
 */
23
trait ProjectScopes
24
{
25
    /**
26
     * Filter project by status.
27
     *
28
     * @param Builder $query
29
     * @param int     $status
30
     *
31
     * @return Builder
32
     */
33
    public function scopeStatus(Builder $query, $status = Project::STATUS_OPEN)
34
    {
35
        return $query->where('status', '=', $status);
36
    }
37
38
    /**
39
     * Filter project to active status.
40
     *
41
     * @param Builder $query
42
     *
43
     * @return Builder
44
     */
45
    public function scopeActive(Builder $query)
46
    {
47
        return $this->scopeStatus($query, Project::STATUS_OPEN);
48
    }
49
50
    /**
51
     * Filter project to archived status.
52
     *
53
     * @param Builder $query
54
     *
55
     * @return Builder
56
     */
57
    public function scopeArchived(Builder $query)
58
    {
59
        return $this->scopeStatus($query, Project::STATUS_ARCHIVED);
60
    }
61
62
    /**
63
     * Filter project to public project.
64
     *
65
     * @param Builder $query
66
     *
67
     * @return Builder
68
     */
69
    public function scopePublic(Builder $query)
70
    {
71
        return $query->where('private', '=', Project::PRIVATE_NO);
72
    }
73
74
    /**
75
     * Filter project to public not project.
76
     *
77
     * @param Builder $query
78
     *
79
     * @return Builder
80
     */
81
    public function scopeNotPublic(Builder $query)
82
    {
83
        return $query->where(function (Builder $query) {
84
            $query
85
                ->where('private', '=', static::PRIVATE_YES)
86
                ->orWhere('private', '=', static::INTERNAL_YES);
87
        });
88
    }
89
}
90