forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecommendationUser.php
More file actions
62 lines (48 loc) · 1.26 KB
/
RecommendationUser.php
File metadata and controls
62 lines (48 loc) · 1.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
<?php
namespace ProcessMaker\Models;
use Illuminate\Support\Carbon;
class RecommendationUser extends ProcessMakerModel
{
protected $connection = 'processmaker';
protected $guarded = [];
protected $casts = [
'dismissed_until' => 'datetime',
'count' => 'integer',
];
public function recommendation()
{
return $this->belongsTo(Recommendation::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
/**
* Checks of the dismissed_until timestamp has passed
*
* @return bool
*/
public function isExpired(): bool
{
if (null === $this->dismissed_until) {
return false;
}
return Carbon::parse($this->dismissed_until)->isPast();
}
/**
* Dismiss this user's recommendation for the given amount of time
*
* @return void
*/
public function dismiss(): void
{
$dismissFor = $this->recommendation->dismiss_for_secs;
$dismissUntil = Carbon::now()->addSeconds($dismissFor);
$this->dismissed_until = $dismissUntil;
$this->saveOrFail();
}
public static function deleteFor(User $user): void
{
static::where('user_id', $user->id)->delete();
}
}