Issues (215)

src/Model/Round.php (4 issues)

1
<?php
2
3
namespace Siak\Tontine\Model;
4
5
use Illuminate\Database\Eloquent\Casts\Attribute;
6
7
class Round extends Base
8
{
9
    use Traits\DateFormatter;
10
    use Traits\HasProperty;
0 ignored issues
show
The trait Siak\Tontine\Model\Traits\HasProperty requires some properties which are not provided by Siak\Tontine\Model\Round: $property, $content
Loading history...
11
12
    /**
13
     * @const
14
     */
15
    const STATUS_PENDING = 0;
16
17
    /**
18
     * @const
19
     */
20
    const STATUS_OPENED = 1;
21
22
    /**
23
     * @const
24
     */
25
    const STATUS_CLOSED = 2;
26
27
    /**
28
     * Indicates if the model should be timestamped.
29
     *
30
     * @var bool
31
     */
32
    public $timestamps = false;
33
34
    /**
35
     * The attributes that are mass assignable.
36
     *
37
     * @var array
38
     */
39
    protected $fillable = [
40
        'title',
41
        'status',
42
        'notes',
43
    ];
44
45
    public function start(): Attribute
46
    {
47
        return Attribute::make(
48
            get: fn() => $this->sessions()->orderBy('day_date')->first(),
49
        );
50
    }
51
52
    public function startDate(): Attribute
53
    {
54
        return Attribute::make(
55
            get: fn() => $this->start?->day_date ?? null,
0 ignored issues
show
The property start does not seem to exist on Siak\Tontine\Model\Round. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
56
        );
57
    }
58
59
    public function end(): Attribute
60
    {
61
        return Attribute::make(
62
            get: fn() => $this->sessions()->orderByDesc('day_date')->first(),
63
        );
64
    }
65
66
    public function endDate(): Attribute
67
    {
68
        return Attribute::make(
69
            get: fn() => $this->end?->day_date ?? null,
0 ignored issues
show
The property end does not seem to exist on Siak\Tontine\Model\Round. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
70
        );
71
    }
72
73
    public function pending(): Attribute
74
    {
75
        return Attribute::make(
76
            get: fn() => $this->status === self::STATUS_PENDING,
77
        );
78
    }
79
80
    public function opened(): Attribute
81
    {
82
        return Attribute::make(
83
            get: fn() => $this->status === self::STATUS_OPENED,
84
        );
85
    }
86
87
    public function closed(): Attribute
88
    {
89
        return Attribute::make(
90
            get: fn() => $this->status === self::STATUS_CLOSED,
91
        );
92
    }
93
94
    public function addDefaultFund(): Attribute
95
    {
96
        return Attribute::make(
97
            get: fn() => $this->properties['savings']['fund']['default'] ?? false,
0 ignored issues
show
The property properties does not seem to exist on Siak\Tontine\Model\Round. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
98
        );
99
    }
100
101
    public function guild()
102
    {
103
        return $this->belongsTo(Guild::class);
104
    }
105
106
    public function funds()
107
    {
108
        return $this->hasMany(Fund::class);
109
    }
110
111
    public function charges()
112
    {
113
        return $this->hasMany(Charge::class);
114
    }
115
116
    public function members()
117
    {
118
        return $this->hasMany(Member::class);
119
    }
120
121
    public function pools()
122
    {
123
        return $this->hasMany(Pool::class);
124
    }
125
126
    public function sessions()
127
    {
128
        return $this->hasMany(Session::class);
129
    }
130
131
    public function bills()
132
    {
133
        return $this->hasMany(RoundBill::class);
134
    }
135
}
136