SubmittedFormField   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 20
c 2
b 1
f 0
dl 0
loc 97
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getExportValue() 0 3 1
A canEdit() 0 3 1
A getEditableField() 0 5 1
A canCreate() 0 3 1
A canDelete() 0 3 1
A canView() 0 3 1
A getFormattedValue() 0 3 1
1
<?php
2
3
namespace SilverStripe\UserForms\Model\Submission;
4
5
use SilverStripe\ORM\DataObject;
6
use SilverStripe\ORM\FieldType\DBField;
7
use SilverStripe\Security\Member;
8
use SilverStripe\UserForms\Model\EditableFormField;
9
10
/**
11
 * Data received from a UserDefinedForm submission
12
 *
13
 * @package userforms
14
 */
15
class SubmittedFormField extends DataObject
16
{
17
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
18
        'Name' => 'Varchar',
19
        'Value' => 'Text',
20
        'Title' => 'Varchar(255)'
21
    ];
22
23
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
24
        'Parent' => SubmittedForm::class
25
    ];
26
27
    private static $summary_fields = [
0 ignored issues
show
introduced by
The private property $summary_fields is not used, and could be removed.
Loading history...
28
        'Title' => 'Title',
29
        'FormattedValue' => 'Value'
30
    ];
31
32
    private static $table_name = 'SubmittedFormField';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
33
34
    /**
35
     * @param Member $member
36
     * @param array $context
37
     * @return boolean
38
     */
39
    public function canCreate($member = null, $context = [])
40
    {
41
        return $this->Parent()->canCreate();
0 ignored issues
show
Bug introduced by
The method Parent() does not exist on SilverStripe\UserForms\M...sion\SubmittedFormField. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

41
        return $this->/** @scrutinizer ignore-call */ Parent()->canCreate();
Loading history...
42
    }
43
44
    /**
45
     * @param Member $member
46
     *
47
     * @return boolean
48
     */
49
    public function canView($member = null)
50
    {
51
        return $this->Parent()->canView();
52
    }
53
54
    /**
55
     * @param Member $member
56
     *
57
     * @return boolean
58
     */
59
    public function canEdit($member = null)
60
    {
61
        return $this->Parent()->canEdit();
62
    }
63
64
    /**
65
     * @param Member $member
66
     *
67
     * @return boolean
68
     */
69
    public function canDelete($member = null)
70
    {
71
        return $this->Parent()->canDelete();
72
    }
73
74
    /**
75
     * Generate a formatted value for the reports and email notifications.
76
     * Converts new lines (which are stored in the database text field) as
77
     * <brs> so they will output as newlines in the reports.
78
     *
79
     * @return DBField
80
     */
81
    public function getFormattedValue()
82
    {
83
        return $this->dbObject('Value');
84
    }
85
86
    /**
87
     * Return the value of this submitted form field suitable for inclusion
88
     * into the CSV
89
     *
90
     * @return DBField
91
     */
92
    public function getExportValue()
93
    {
94
        return $this->Value;
0 ignored issues
show
Bug Best Practice introduced by
The property Value does not exist on SilverStripe\UserForms\M...sion\SubmittedFormField. Since you implemented __get, consider adding a @property annotation.
Loading history...
95
    }
96
97
    /**
98
     * Find equivalent editable field for this submission.
99
     *
100
     * Note the field may have been modified or deleted from the original form
101
     * so this may not always return the data you expect. If you need to save
102
     * a particular state of editable form field at time of submission, copy
103
     * that value to the submission.
104
     *
105
     * @return EditableFormField
106
     */
107
    public function getEditableField()
108
    {
109
        return $this->Parent()->Parent()->Fields()->filter([
110
            'Name' => $this->Name
0 ignored issues
show
Bug Best Practice introduced by
The property Name does not exist on SilverStripe\UserForms\M...sion\SubmittedFormField. Since you implemented __get, consider adding a @property annotation.
Loading history...
111
        ])->First();
112
    }
113
}
114