Completed
Push — master ( 28284e...eaa9bf )
by
unknown
12:07
created

Lot   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 173
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 3
dl 0
loc 173
rs 10
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A vendor() 0 4 1
A currency() 0 4 1
A specPrice() 0 4 1
A involved() 0 4 1
A category() 0 4 1
A products() 0 4 1
A lotDeliveryPayment() 0 4 1
A subCategories() 0 7 1
A scopeDrafted() 0 4 1
A scopeCompleted() 0 4 1
A scopeVerified() 0 4 1
A scopeDeclined() 0 4 1
A scopePending() 0 4 1
A scopePublic() 0 6 1
1
<?php
2
3
namespace App;
4
5
use App\Libraries\Presenterable\Presenterable;
6
use App\Libraries\Presenterable\Presenters\LotPresenter;
7
use App\Traits\ActivateableTrait;
8
use Keyhunter\Administrator\Repository;
9
10
class Lot extends Repository
11
{
12
    use ActivateableTrait, Presenterable;
13
14
    /** `status` field options */
15
    const STATUS_DRAFTED = 'drafted';
16
    const STATUS_COMPLETE = 'complete';
17
    const STATUS_DELETED = 'deleted';
18
    
19
20
    /** `verify_status` field options */
21
    const STATUS_VERIFY_ACCEPTED = 'verified';
22
    const STATUS_VERIFY_DECLINED = 'declined';
23
    const STATUS_VERIFY_PENDING = 'pending';
24
25
    /**
26
     * @var string
27
     */
28
    protected $table = 'lots';
29
30
    /**
31
     * @var LotPresenter
32
     */
33
    public $presenter = LotPresenter::class;
34
35
    /**
36
     * @var array
37
     */
38
    protected $fillable = [
39
        'vendor_id',
40
        'category_id',
41
        'currency_id',
42
        'name',
43
        'yield_amount',
44
        'description',
45
        'public_date',
46
        'expire_date',
47
        'status',
48
        'verify_status',
49
        'active',
50
        'comision',
51
        'description_delivery',
52
        'description_payment'
53
    ];
54
55
    protected $dates = [
56
        'public_date',
57
        'expire_date',
58
    ];
59
60
    /**
61
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
62
     */
63
    public function vendor()
64
    {
65
        return $this->belongsTo(Vendor::class, 'vendor_id', 'id');
66
    }
67
68
    /**
69
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
70
     */
71
    public function currency()
72
    {
73
        return $this->hasOne(Currency::class, 'id', 'currency_id');
74
    }
75
76
    public function specPrice()
77
    {
78
        return $this->hasMany(SpecPrice::class, 'lot_id', 'id');
79
    }
80
81
    public function involved()
82
    {
83
        return $this->hasMany(Involved::class, 'lot_id', 'id')->active();
84
    }
85
86
    /**
87
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
88
     */
89
    public function category()
90
    {
91
        return $this->hasOne(Category::class, 'id', 'category_id');
92
    }
93
94
    /**
95
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
96
     */
97
    public function products()
98
    {
99
        return $this->hasMany(Product::class, 'lot_id', 'id');
100
    }
101
102
    public function lotDeliveryPayment()
103
    {
104
        return $this->hasMany(LotDeliveryPayment::class, 'lot_id', 'id');
105
    }
106
107
    public function subCategories()
108
    {
109
        return $this->hasManyThrough(
110
            SubCategory::class, Category::class,
111
            'id', 'category_id', 'category_id'
112
        );
113
    }
114
115
    /**
116
     * Query scope if lot is drafted.
117
     *
118
     * @param $query
119
     * @return mixed
120
     */
121
    public function scopeDrafted($query)
122
    {
123
        return $query->where('status', self::STATUS_DRAFTED);
124
    }
125
126
    /**
127
     * Query scope if lot is completed.
128
     *
129
     * @param $query
130
     * @return mixed
131
     */
132
    public function scopeCompleted($query)
133
    {
134
        return $query->where('status', self::STATUS_COMPLETE);
135
    }
136
137
    /**
138
     * Query scope if lot is verified.
139
     *
140
     * @param $query
141
     * @return mixed
142
     */
143
    public function scopeVerified($query)
144
    {
145
        return $query->where('verify_status', self::STATUS_VERIFY_ACCEPTED);
146
    }
147
148
    /**
149
     * Query scope if lot is declined.
150
     *
151
     * @param $query
152
     * @return mixed
153
     */
154
    public function scopeDeclined($query)
155
    {
156
        return $query->where('verify_status', self::STATUS_VERIFY_DECLINED);
157
    }
158
159
    /**
160
     * Query scope if lot is pending.
161
     *
162
     * @param $query
163
     * @return mixed
164
     */
165
    public function scopePending($query)
166
    {
167
        return $query->where('verify_status', self::STATUS_VERIFY_PENDING);
168
    }
169
170
    /**
171
     * Query scope if lot is published.
172
     *
173
     * @param $query
174
     * @return mixed
175
     */
176
    public function scopePublic($query)
177
    {
178
        return $query
179
            ->where('status', self::STATUS_COMPLETE)
180
            ->where('verify_status', self::STATUS_VERIFY_ACCEPTED);
181
    }
182
}