-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathMeasure.php
More file actions
76 lines (66 loc) · 1.79 KB
/
Measure.php
File metadata and controls
76 lines (66 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace App\Models;
use App\Traits\Auditable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Support\Facades\DB;
class Measure extends Model
{
use Auditable;
public static $searchable = [
'name',
'clause',
'objective',
'input',
'attributes',
'model',
];
protected $dates = [
'created_at',
'updated_at',
'deleted_at',
];
protected $fillable = [
'domain_id',
'clause',
'name',
'objective',
'attributes',
'input',
'model',
'indicator',
'action_plan',
];
// Return the domain associated to this measure
public function domain(): BelongsTo
{
return $this->belongsTo(Domain::class, 'domain_id');
}
// Return the controls associated to this measure
public function controls(): BelongsToMany
{
return $this->belongsToMany(Control::class)
->whereNotNull('realisation_date')->orderBy('realisation_date');
}
// Check if there is an empty control associated with this measure
public function isActive(): bool
{
return DB::table('controls')
->where('measure_id', $this->id)
->whereNull('realisation_date')
->exists();
}
// check if there is an empty control associated with this measure
public function isDisabled(): bool
{
return DB::table('controls')
->where('measure_id', $this->id)
->exists()
&&
! DB::table('controls')
->where('measure_id', $this->id)
->whereNull('realisation_date')
->exists();
}
}