forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInboxRuleLog.php
More file actions
64 lines (52 loc) · 1.7 KB
/
InboxRuleLog.php
File metadata and controls
64 lines (52 loc) · 1.7 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
<?php
namespace ProcessMaker\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use ProcessMaker\Models\ProcessMakerModel;
class InboxRuleLog extends ProcessMakerModel
{
use HasFactory;
protected $guarded = [];
protected $casts = [
'inbox_rule_attributes' => 'array',
];
public function task(): BelongsTo
{
return $this->belongsTo(ProcessRequestToken::class, 'process_request_token_id');
}
public static function changesSinceQuery($userId, $timestamp)
{
return self::where('user_id', $userId)
->where('created_at', '>=', $timestamp);
}
public static function hasChangesSince($userId, $timestamp)
{
return self::changesSinceQuery($userId, $timestamp)->exists();
}
public static function changesSince($userId, $timestamp)
{
$total = 0;
$priority = 0;
$reassigned = 0;
$draft = 0;
$submit = 0;
$logs = self::changesSinceQuery($userId, $timestamp)->limit(10000)->get();
foreach ($logs as $log) {
$total++;
if ($log['inbox_rule_attributes']['make_draft']) {
$draft++;
}
if ($log['inbox_rule_attributes']['submit_data']) {
$submit++;
}
if ($log['inbox_rule_attributes']['mark_as_priority']) {
$priority++;
}
if ($log['inbox_rule_attributes']['reassign_to_user_id']) {
$reassigned++;
}
}
return compact('total', 'priority', 'reassigned', 'draft', 'submit');
}
}