1 | <?php |
||
35 | class PartialFormSubmission extends SubmittedForm |
||
36 | { |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | private static $table_name = 'PartialFormSubmission'; |
||
|
|||
42 | |||
43 | /** |
||
44 | * @var array |
||
45 | */ |
||
46 | private static $db = [ |
||
47 | 'IsSend' => 'Boolean(false)', |
||
48 | 'TokenSalt' => 'Varchar(16)', |
||
49 | 'Token' => 'Varchar(16)', |
||
50 | 'Password' => 'Varchar(64)', |
||
51 | ]; |
||
52 | |||
53 | /** |
||
54 | * @var array |
||
55 | */ |
||
56 | private static $has_one = [ |
||
57 | 'UserDefinedForm' => DataObject::class |
||
58 | ]; |
||
59 | |||
60 | /** |
||
61 | * @var array |
||
62 | */ |
||
63 | private static $has_many = [ |
||
64 | 'PartialFields' => PartialFieldSubmission::class |
||
65 | ]; |
||
66 | |||
67 | private static $cascade_deletes = [ |
||
68 | 'PartialFields' |
||
69 | ]; |
||
70 | |||
71 | /** |
||
72 | * @var array |
||
73 | */ |
||
74 | private static $summary_fields = [ |
||
75 | 'ID' => 'ID', |
||
76 | 'PartialLink' => 'Link', |
||
77 | 'Created' => 'Created', |
||
78 | 'LastEdited' => 'Last Edited', |
||
79 | ]; |
||
80 | |||
81 | private static $special_characters = [ |
||
82 | '!', |
||
83 | '@', |
||
84 | '#', |
||
85 | '$', |
||
86 | '%', |
||
87 | '^', |
||
88 | '&', |
||
89 | '*', |
||
90 | '(', |
||
91 | ')', |
||
92 | '_', |
||
93 | '-', |
||
94 | '=', |
||
95 | '+', |
||
96 | ';', |
||
97 | ':', |
||
98 | ',', |
||
99 | '.', |
||
100 | '?' |
||
101 | ]; |
||
102 | |||
103 | /** |
||
104 | * @return FieldList |
||
105 | * @throws Exception |
||
106 | */ |
||
107 | public function getCMSFields() |
||
108 | { |
||
109 | /** @var FieldList $fields */ |
||
110 | $fields = parent::getCMSFields(); |
||
111 | $fields->removeByName( |
||
112 | [ |
||
113 | 'Values', |
||
114 | 'IsSend', |
||
115 | 'PartialFields', |
||
116 | 'TokenSalt', |
||
117 | 'Token', |
||
118 | 'UserDefinedFormID', |
||
119 | 'Submitter', |
||
120 | 'Password' |
||
121 | ] |
||
122 | ); |
||
123 | |||
124 | $partialFields = GridField::create( |
||
125 | 'PartialFields', |
||
126 | _t(static::class . '.PARTIALFIELDS', 'Partial fields'), |
||
127 | $this->PartialFields()->sort('Created', 'ASC') |
||
128 | ); |
||
129 | |||
130 | $exportColumns = [ |
||
131 | 'Title' => 'Title', |
||
132 | 'ExportValue' => 'Value' |
||
133 | ]; |
||
134 | |||
135 | $config = new GridFieldConfig(); |
||
136 | $config->addComponent(new GridFieldDataColumns()); |
||
137 | $config->addComponent(new GridFieldButtonRow('after')); |
||
138 | $config->addComponent(new GridFieldExportButton('buttons-after-left', $exportColumns)); |
||
139 | $config->addComponent(new GridFieldPrintButton('buttons-after-left')); |
||
140 | $partialFields->setConfig($config); |
||
141 | |||
142 | $fields->addFieldsToTab( |
||
143 | 'Root.Main', |
||
144 | [ |
||
145 | ReadonlyField::create('ReadonlyPartialLink', 'Partial Link', $this->getPartialLink()), |
||
146 | $partialFields |
||
147 | ] |
||
148 | ); |
||
149 | |||
150 | return $fields; |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * Get the share link of the form |
||
155 | * |
||
156 | * @return string |
||
157 | * @throws Exception |
||
158 | */ |
||
159 | public function getPartialLink() |
||
174 | |||
175 | /** |
||
176 | * Generate a key based on the share token salt |
||
177 | * |
||
178 | * @param string $token |
||
179 | * @return mixed |
||
180 | */ |
||
181 | public function generateKey($token) |
||
185 | |||
186 | /** |
||
187 | * Generate the partial tokens |
||
188 | * If the submission is password protected, generate a password. |
||
189 | * @throws Exception |
||
190 | */ |
||
191 | public function onBeforeWrite() |
||
199 | |||
200 | /** |
||
201 | * Get the unique token for the share link |
||
202 | * |
||
203 | * @return bool|string|null |
||
204 | * @throws Exception |
||
205 | */ |
||
206 | protected function getPartialToken() |
||
215 | |||
216 | /** |
||
217 | * Generate a new token |
||
218 | * |
||
219 | * @return bool|string |
||
220 | * @throws Exception |
||
221 | */ |
||
222 | protected function generateToken() |
||
228 | |||
229 | /** |
||
230 | * @return string |
||
231 | */ |
||
232 | protected function generatePassword() |
||
244 | |||
245 | /** |
||
246 | * @return DataObject|UserDefinedForm |
||
247 | */ |
||
248 | public function getParent() |
||
252 | |||
253 | /** |
||
254 | * @param Member |
||
255 | * |
||
256 | * @return boolean|string |
||
257 | */ |
||
258 | public function canCreate($member = null, $context = []) |
||
262 | |||
263 | /** |
||
264 | * @param Member $member |
||
265 | * |
||
266 | * @return boolean|string |
||
267 | */ |
||
268 | public function canView($member = null) |
||
276 | |||
277 | /** |
||
278 | * @param Member $member |
||
279 | * |
||
280 | * @return boolean|string |
||
281 | */ |
||
282 | public function canEdit($member = null) |
||
290 | |||
291 | /** |
||
292 | * @param Member $member |
||
293 | * |
||
294 | * @return boolean|string |
||
295 | */ |
||
296 | public function canDelete($member = null) |
||
304 | } |
||
305 |