-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathRecommendation.php
More file actions
68 lines (53 loc) · 1.77 KB
/
Recommendation.php
File metadata and controls
68 lines (53 loc) · 1.77 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
<?php
namespace ProcessMaker\Models;
use Illuminate\Database\Eloquent\Builder;
use ProcessMaker\Filters\Filter;
class Recommendation extends ProcessMakerModel
{
protected $connection = 'processmaker';
protected $guarded = [];
protected $casts = [
'min_matches' => 'integer',
'dismiss_for_secs' => 'integer',
'actions' => 'array',
'advanced_filter' => 'array',
];
protected $attributes = [
'status' => 'ACTIVE',
'actions' => '[]',
'min_matches' => 1,
'dismiss_for_secs' => 604800,
];
protected static function boot(): void
{
// Default to an empty array for available actions
static::saving(static function ($recommendation) {
$recommendation->actions = $recommendation->actions ?? [];
});
static::deleting(function (Recommendation $recommendation) {
$recommendation->recommendationUsers()->delete();
});
parent::boot();
}
public function recommendationUsers()
{
return $this->hasMany(RecommendationUser::class, 'recommendation_id');
}
public function scopeActive(Builder $query): void
{
$query->where('status', '=', 'ACTIVE');
}
public function baseQuery(User $user)
{
// Build the base query
$query = ProcessRequestToken::query();
// Scope the query to active (in progress) tasks for the user
// who just completed/started the task triggering this job
$query->where('user_id', '=', $user->id)
->where('status', '=', 'ACTIVE');
// Use the Filter class to refine the query with
// the recommendations advanced filter
Filter::filter($query, $this->advanced_filter);
return $query;
}
}