forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComment.php
More file actions
106 lines (95 loc) · 2.9 KB
/
Comment.php
File metadata and controls
106 lines (95 loc) · 2.9 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
98
99
100
101
102
103
104
105
106
<?php
namespace ProcessMaker\Models;
use Illuminate\Database\Eloquent\Model;
use ProcessMaker\Traits\SerializeToIso8601;
use ProcessMaker\Traits\SqlsrvSupportTrait;
/**
* Represents a business process definition.
*
* @property integer 'id',
* @property integer 'user_id',
* @property integer 'commentable_id',
* @property string 'commentable_type',
* @property string 'subject',
* @property string 'body',
* @property boolean 'hidden',
* @property string 'type',
* @property \Carbon\Carbon $updated_at
* @property \Carbon\Carbon $created_at
*
* @OA\Schema(
* schema="commentsEditable",
* @OA\Property(property="id", type="string", format="id"),
* @OA\Property(property="user_id", type="string", format="id"),
* @OA\Property(property="commentable_id", type="string", format="id"),
* @OA\Property(property="commentable_type", type="string"),
* @OA\Property(property="subject", type="string"),
* @OA\Property(property="body", type="string"),
* @OA\Property(property="hidden", type="boolean"),
* @OA\Property(property="type", type="string", enum={"LOG", "MESSAGE"}),
* ),
* @OA\Schema(
* schema="comments",
* allOf={@OA\Schema(ref="#/components/schemas/commentsEditable")},
* @OA\Property(property="created_at", type="string", format="date-time"),
* @OA\Property(property="updated_at", type="string", format="date-time"),
* )
*
*/
class Comment extends Model
{
use SerializeToIso8601;
use SqlsrvSupportTrait;
protected $connection = 'data';
protected $fillable = [
'user_id', 'commentable_id', 'commentable_type', 'subject', 'body', 'hidden', 'type'
];
public static function rules()
{
return [
'user_id' => 'required',
'commentable_id' => 'required',
'commentable_type' => 'required|in:' . ProcessRequestToken::class . ',' . ProcessRequest::class,
'subject' => 'required',
'body' => 'required',
'hidden' => 'required|boolean',
'type' => 'required|in:LOG,MESSAGE',
];
}
/**
* Scope comments hidden
*
* @param $query
* @param $parameter hidden, visible, all
*
* @return mixed
*/
public function scopeHidden($query, $parameter)
{
switch ($parameter) {
case 'visible':
return $query->where('hidden', false);
break;
case 'hidden':
return $query->where('hidden', true);
break;
case 'ALL':
return $query;
break;
}
}
/**
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function commentable()
{
return $this->morphTo(null, null, 'commentable_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class);
}
}