Completed
Push — master ( 12981b...2f1b03 )
by Robbie
14s
created

code/model/submissions/SubmittedFormField.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Data received from a UserDefinedForm submission
4
 *
5
 * @package userforms
6
 */
7
8
class SubmittedFormField extends DataObject
9
{
10
11
    private static $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
12
        "Name" => "Varchar",
13
        "Value" => "Text",
14
        "Title" => "Varchar(255)"
15
    );
16
17
    private static $has_one = array(
18
        "Parent" => "SubmittedForm"
19
    );
20
21
    private static $summary_fields = array(
22
        'Title' => 'Title',
23
        'FormattedValue' => 'Value'
24
    );
25
26
    /**
27
     * @param Member
28
     *
29
     * @return boolean
30
     */
31
    public function canCreate($member = null)
32
    {
33
        return $this->Parent()->canCreate();
34
    }
35
36
    /**
37
     * @param Member
38
     *
39
     * @return boolean
40
     */
41
    public function canView($member = null)
42
    {
43
        return $this->Parent()->canView();
44
    }
45
46
    /**
47
     * @param Member
48
     *
49
     * @return boolean
50
     */
51
    public function canEdit($member = null)
52
    {
53
        return $this->Parent()->canEdit();
54
    }
55
56
    /**
57
     * @param Member
58
     *
59
     * @return boolean
60
     */
61
    public function canDelete($member = null)
62
    {
63
        return $this->Parent()->canDelete();
64
    }
65
66
    /**
67
     * Generate a formatted value for the reports and email notifications.
68
     * Converts new lines (which are stored in the database text field) as
69
     * <brs> so they will output as newlines in the reports
70
     *
71
     * @return string
72
     */
73 1
    public function getFormattedValue()
74
    {
75 1
        return nl2br($this->dbObject('Value')->ATT());
76
    }
77
78
    /**
79
     * Return the value of this submitted form field suitable for inclusion
80
     * into the CSV
81
     *
82
     * @return Text
83
     */
84
    public function getExportValue()
85
    {
86
        return $this->Value;
87
    }
88
89
    /**
90
     * Find equivalent editable field for this submission.
91
     *
92
     * Note the field may have been modified or deleted from the original form
93
     * so this may not always return the data you expect. If you need to save
94
     * a particular state of editable form field at time of submission, copy
95
     * that value to the submission.
96
     *
97
     * @return EditableFormField
98
     */
99
    public function getEditableField()
100
    {
101
        return $this->Parent()->Parent()->Fields()->filter(array(
102
            'Name' => $this->Name
103
        ))->First();
104
    }
105
}
106