-
Notifications
You must be signed in to change notification settings - Fork 248
Expand file tree
/
Copy pathInboxRule.php
More file actions
89 lines (77 loc) · 2.26 KB
/
InboxRule.php
File metadata and controls
89 lines (77 loc) · 2.26 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
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace ProcessMaker\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use ProcessMaker\Jobs\SmartInboxExistingTasks;
use ProcessMaker\Models\ProcessMakerModel;
use ProcessMaker\Models\ProcessRequestToken;
use ProcessMaker\Package\SavedSearch\Models\SavedSearch;
class InboxRule extends ProcessMakerModel
{
use HasFactory;
protected $table = 'inbox_rules';
protected $casts = [
'data' => 'array',
'submit_button' => 'array',
'end_date' => 'datetime',
'active' => 'boolean',
'mark_as_priority' => 'boolean',
'make_draft' => 'boolean',
'submit_data' => 'boolean',
];
protected $guarded = ['id', 'created_at', 'updated_at'];
/**
* Delete the saved search when deleting an inbox rule
*
* @return void
*/
protected static function booted()
{
static::deleting(function (InboxRule $inboxRule) {
if (class_exists(SavedSearch::class)) {
$inboxRule->savedSearch()->delete();
}
});
}
/**
* Define the relationship with ProcessRequestToken model
*
* @return BelongsTo
*/
public function task(): BelongsTo
{
return $this->belongsTo(ProcessRequestToken::class, 'process_request_token_id');
}
/**
* Define the relationship with SavedSearch model
*
* @return BelongsTo
*/
public function savedSearch(): BelongsTo
{
return $this->belongsTo(SavedSearch::class, 'saved_search_id');
}
/**
* Start a job to apply actions to all in-progress tasks
*
* @return void
*/
public function applyToExistingTasks()
{
SmartInboxExistingTasks::dispatch($this->id);
}
public static function createSavedSearch(array $data)
{
$userId = $data['user_id'];
return SavedSearch::create([
'user_id' => $userId,
'title' => 'Inbox Rule Saved Search',
'meta' => ['columns' => $data['columns']],
'pmql' => $data['pmql'],
'type' => 'task',
'advanced_filter' => $data['advanced_filter'],
'is_system' => true,
'key' => 'inbox-rule',
]);
}
}