1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MedianetDev\BackpackForm\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
use Backpack\CRUD\app\Models\Traits\CrudTrait; |
7
|
|
|
use Illuminate\Support\Facades\App; |
8
|
|
|
use Spatie\Activitylog\LogOptions; |
9
|
|
|
use Spatie\Activitylog\Traits\LogsActivity; |
10
|
|
|
|
11
|
|
|
class Formbuilder extends Model |
12
|
|
|
{ |
13
|
|
|
use CrudTrait, LogsActivity; |
|
|
|
|
14
|
|
|
|
15
|
|
|
/* |
16
|
|
|
|-------------------------------------------------------------------------- |
17
|
|
|
| GLOBAL VARIABLES |
18
|
|
|
|-------------------------------------------------------------------------- |
19
|
|
|
*/ |
20
|
|
|
protected $table = 'med_forms'; |
21
|
|
|
protected $guarded = ['id']; |
22
|
|
|
|
23
|
|
|
/* |
24
|
|
|
|-------------------------------------------------------------------------- |
25
|
|
|
| FUNCTIONS |
26
|
|
|
|-------------------------------------------------------------------------- |
27
|
|
|
*/ |
28
|
|
|
public function entriesList() |
29
|
|
|
{ |
30
|
|
|
return '<a href="' . backpack_url('formbuilder/' . $this->id . '/formbuilderentry') . '" class="btn btn-sm btn-link"><i class="la la-bar-chart"></i> ' . __('medianet-dev.backpack-form::formbuilder.labels.view_entries') . '</a>'; |
|
|
|
|
31
|
|
|
} |
32
|
|
|
public function form_edit() |
33
|
|
|
{ |
34
|
|
|
return '<a href="' . backpack_url('form-fields/create') . '" class="btn btn-sm btn-link open-popup-link"><i class="la la-bar-chart"></i> EDIT</a>'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/* |
38
|
|
|
|-------------------------------------------------------------------------- |
39
|
|
|
| RELATIONS |
40
|
|
|
|-------------------------------------------------------------------------- |
41
|
|
|
*/ |
42
|
|
|
public function entries() |
43
|
|
|
{ |
44
|
|
|
return $this->hasMany(FormbuilderEntry::class); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function translation() |
48
|
|
|
{ |
49
|
|
|
return $this->hasOne(FormbuilderTranslation::class, 'form_id') |
50
|
|
|
->where('locale', App::getLocale()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function translations() |
54
|
|
|
{ |
55
|
|
|
return $this->hasMany(FormbuilderTranslation::class, 'form_id'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function steps() |
59
|
|
|
{ |
60
|
|
|
return $this->hasMany(FormStep::class, 'form_id'); |
61
|
|
|
} |
62
|
|
|
public function getTranslatedTitleAttribute() |
63
|
|
|
{ |
64
|
|
|
return optional($this->translation)->title ?? $this->id; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getActivitylogOptions(): LogOptions |
68
|
|
|
{ |
69
|
|
|
return LogOptions::defaults() |
70
|
|
|
->logOnly([ |
71
|
|
|
'id', |
72
|
|
|
'display_intro', |
73
|
|
|
'display_title', |
74
|
|
|
'display_header', |
75
|
|
|
'display_footer', |
76
|
|
|
'uniq_id', |
77
|
|
|
'intro', |
78
|
|
|
'text_button', |
79
|
|
|
'form', |
80
|
|
|
'in_database', |
81
|
|
|
'by_mail', |
82
|
|
|
'display_captcha', |
83
|
|
|
'mail_to', |
84
|
|
|
'include_data', |
85
|
|
|
'subject_admin', |
86
|
|
|
'message_admin', |
87
|
|
|
'copy_user', |
88
|
|
|
'field_mail_name', |
89
|
|
|
'subject_user', |
90
|
|
|
'message_user', |
91
|
|
|
'multiple_steps', |
92
|
|
|
'formio_component', |
93
|
|
|
'validation_rules', |
94
|
|
|
'created_by', |
95
|
|
|
'updated_by', |
96
|
|
|
'created_at', |
97
|
|
|
'updated_at' |
98
|
|
|
]) |
99
|
|
|
->logOnlyDirty() |
100
|
|
|
->dontSubmitEmptyLogs() |
101
|
|
|
->setDescriptionForEvent( |
102
|
|
|
fn(string $eventName) => ("activity.action.{$eventName}") |
103
|
|
|
) |
104
|
|
|
->useLogName('form'); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|