-
Notifications
You must be signed in to change notification settings - Fork 246
Expand file tree
/
Copy pathNotification.php
More file actions
97 lines (85 loc) · 2.82 KB
/
Notification.php
File metadata and controls
97 lines (85 loc) · 2.82 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
90
91
92
93
94
95
96
97
<?php
namespace ProcessMaker\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Validation\Rule;
use ProcessMaker\Models\Scopes\NotificationWithValidJson;
use ProcessMaker\Traits\SerializeToIso8601;
use Ramsey\Uuid\Uuid;
/**
* Represents a notification definition.
*
* @property string $id
* @property string $type
* @property string $notifiable_type
* @property string $notifiable_id
* @property string $data
* @property \Carbon\Carbon $read_at
* @property \Carbon\Carbon $updated_at
* @property \Carbon\Carbon $created_at
*
* @OA\Schema(
* schema="NotificationEditable",
* @OA\Property(property="type", type="string"),
* @OA\Property(property="notifiable_type", type="string"),
* @OA\Property(property="notifiable_id", type="integer"),
* @OA\Property(property="data", type="string"),
* @OA\Property(property="name", type="string"),
* @OA\Property(property="message", type="string"),
* @OA\Property(property="processName", type="string"),
* @OA\Property(property="userName", type="string"),
* @OA\Property(property="request_id", type="string"),
* @OA\Property(property="url", type="string"),
* ),
* @OA\Schema(
* schema="Notification",
* allOf={
* @OA\Schema(ref="#/components/schemas/NotificationEditable"),
* @OA\Schema(
* @OA\Property(property="id", type="string"),
* @OA\Property(property="read_at", type="string", format="date-time"),
* @OA\Property(property="created_at", type="string", format="date-time"),
* @OA\Property(property="updated_at", type="string", format="date-time"),
* ),
* },
* )
*/
class Notification extends ProcessMakerModel
{
use SerializeToIso8601;
protected $connection = 'processmaker';
public $incrementing = false;
protected $fillable = [
'type',
'notifiable_type',
'notifiable_id',
'data',
'read_at',
'url',
];
/**
* Boot function from laravel.
*/
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->{$model->getKeyName()} = Uuid::uuid4()->toString();
});
// The rest of the app expects that data is a json string, all notification uses this format.
// We need to exclude any spurious notification that does not have a valid json data
static::addGlobalScope(new NotificationWithValidJson);
}
public static function rules($existing = null)
{
$required = Rule::requiredIf(function () use ($existing) {
return $existing === null;
});
$rules = [
'notifiable_id' => [$required, 'integer'],
'notifiable_type' => [$required, 'string'],
'type' => [$required, 'string'],
'data' => [$required, 'string'],
];
return $rules;
}
}