Formbuilder   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 46
c 1
b 0
f 0
dl 0
loc 94
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A translation() 0 4 1
A entriesList() 0 3 1
A getTranslatedTitleAttribute() 0 3 1
A steps() 0 3 1
A getActivitylogOptions() 0 38 1
A entries() 0 3 1
A form_edit() 0 3 1
A translations() 0 3 1
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;
0 ignored issues
show
introduced by
The trait Backpack\CRUD\app\Models\Traits\CrudTrait requires some properties which are not provided by MedianetDev\BackpackForm\Models\Formbuilder: $fakeColumns, $identifiableAttribute, $Type
Loading history...
introduced by
The trait Spatie\Activitylog\Traits\LogsActivity requires some properties which are not provided by MedianetDev\BackpackForm\Models\Formbuilder: $submitEmptyLogs, $logExceptAttributes, $attributeRawValues, $logName, $dontLogIfAttributesChangedOnly, $descriptionForEvent, $logOnlyDirty, $logFillable, $logUnguarded, $logAttributes
Loading history...
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>';
0 ignored issues
show
Bug introduced by
Are you sure __('medianet-dev.backpac...r.labels.view_entries') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
        return '<a href="' . backpack_url('formbuilder/' . $this->id . '/formbuilderentry') . '" class="btn btn-sm btn-link"><i class="la la-bar-chart"></i> ' . /** @scrutinizer ignore-type */ __('medianet-dev.backpack-form::formbuilder.labels.view_entries') . '</a>';
Loading history...
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