|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\UserForms\Model\Submission; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\ORM\DataObject; |
|
6
|
|
|
use SilverStripe\UserForms\Model\Submission\SubmittedForm; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Data received from a UserDefinedForm submission |
|
10
|
|
|
* |
|
11
|
|
|
* @package userforms |
|
12
|
|
|
*/ |
|
13
|
|
|
class SubmittedFormField extends DataObject |
|
14
|
|
|
{ |
|
15
|
|
|
private static $db = [ |
|
|
|
|
|
|
16
|
|
|
'Name' => 'Varchar', |
|
17
|
|
|
'Value' => 'Text', |
|
18
|
|
|
'Title' => 'Varchar(255)' |
|
19
|
|
|
]; |
|
20
|
|
|
|
|
21
|
|
|
private static $has_one = [ |
|
|
|
|
|
|
22
|
|
|
'Parent' => SubmittedForm::class |
|
23
|
|
|
]; |
|
24
|
|
|
|
|
25
|
|
|
private static $summary_fields = [ |
|
|
|
|
|
|
26
|
|
|
'Title' => 'Title', |
|
27
|
|
|
'CleanValue' => 'Value' |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
private static $casting = [ |
|
|
|
|
|
|
31
|
|
|
'CleanValue' => 'HTMLFragment' |
|
32
|
|
|
]; |
|
33
|
|
|
|
|
34
|
|
|
private static $table_name = 'SubmittedFormField'; |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param Member $member |
|
|
|
|
|
|
38
|
|
|
* @param array $context |
|
39
|
|
|
* @return boolean |
|
40
|
|
|
*/ |
|
41
|
|
|
public function canCreate($member = null, $context = []) |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->Parent()->canCreate(); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param Member $member |
|
48
|
|
|
* |
|
49
|
|
|
* @return boolean |
|
50
|
|
|
*/ |
|
51
|
|
|
public function canView($member = null) |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->Parent()->canView(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param Member $member |
|
58
|
|
|
* |
|
59
|
|
|
* @return boolean |
|
60
|
|
|
*/ |
|
61
|
|
|
public function canEdit($member = null) |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->Parent()->canEdit(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param Member $member |
|
68
|
|
|
* |
|
69
|
|
|
* @return boolean |
|
70
|
|
|
*/ |
|
71
|
|
|
public function canDelete($member = null) |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->Parent()->canDelete(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Generate a clean value for the reports and email notifications. |
|
78
|
|
|
* |
|
79
|
|
|
* @return string |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getCleanValue() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->dbObject('Value')->RAW(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Return the value of this submitted form field suitable for inclusion |
|
88
|
|
|
* into the CSV |
|
89
|
|
|
* |
|
90
|
|
|
* @return Text |
|
|
|
|
|
|
91
|
|
|
*/ |
|
92
|
|
|
public function getExportValue() |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->Value; |
|
|
|
|
|
|
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 |
|
|
|
|
|
|
111
|
|
|
])->First(); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|