1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class ContactUsFormEntry extends DataObject |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
|
6
|
|
|
private static $db = array( |
|
|
|
|
7
|
|
|
'AdminEmail' => 'Varchar(255)', |
8
|
|
|
'Email' => 'Varchar(255)', |
9
|
|
|
'FirstName' => 'Varchar(255)', |
10
|
|
|
'Surname' => 'Varchar(255)', |
11
|
|
|
'Phone' => 'Varchar(255)', |
12
|
|
|
'Enquiry' => 'Text', |
13
|
|
|
'Data' => 'Text', |
14
|
|
|
'Responded' => 'Boolean', |
15
|
|
|
'SentToAdmin' => 'Boolean', |
16
|
|
|
'SentToCustomer' => 'Boolean' |
17
|
|
|
); |
18
|
|
|
|
19
|
|
|
private static $has_one = array( |
|
|
|
|
20
|
|
|
'Page' => 'SiteTree' |
21
|
|
|
); |
22
|
|
|
|
23
|
|
|
private static $casting = array( |
|
|
|
|
24
|
|
|
'NiceData' => 'HTMLText' |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
public static function create_enquiry($sqlSafeData, $page) |
28
|
|
|
{ |
29
|
|
|
$obj = ContactUsFormEntry::create( |
30
|
|
|
array( |
31
|
|
|
'Email'=> ($sqlSafeData['Email']), |
32
|
|
|
'FirstName' => ($sqlSafeData['FirstName']), |
33
|
|
|
'Surname' => ($sqlSafeData['Surname']), |
34
|
|
|
'Phone' => ($sqlSafeData['Phone']), |
35
|
|
|
'Enquiry' => ($sqlSafeData['Enquiry']), |
36
|
|
|
//data is a backup for any additional fields in the form... |
37
|
|
|
"PageID" => $page->ID |
38
|
|
|
) |
39
|
|
|
); |
40
|
|
|
unset($sqlSafeData['url']); |
41
|
|
|
unset($sqlSafeData['action_docontactusform']); |
42
|
|
|
unset($sqlSafeData['SecurityID']); |
43
|
|
|
unset($sqlSafeData['Enquiry']); |
44
|
|
|
unset($sqlSafeData['Phone']); |
45
|
|
|
unset($sqlSafeData['FirstName']); |
46
|
|
|
unset($sqlSafeData['Surname']); |
47
|
|
|
unset($sqlSafeData['Email']); |
48
|
|
|
$obj->Data = serialize($sqlSafeData); |
|
|
|
|
49
|
|
|
$obj->write(); |
50
|
|
|
|
51
|
|
|
return $obj; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
private static $singular_name = "Customer Enquiry"; |
|
|
|
|
55
|
|
|
function i18n_singular_name() { return self::$singular_name;} |
|
|
|
|
56
|
|
|
|
57
|
|
|
private static $plural_name = "Customer Enquiries"; |
|
|
|
|
58
|
|
|
function i18n_plural_name() { return self::$plural_name;} |
|
|
|
|
59
|
|
|
|
60
|
|
|
private static $indexes = array( |
|
|
|
|
61
|
|
|
"Email" => true |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
private static $default_sort = array( |
|
|
|
|
65
|
|
|
'Created' => 'Desc' |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
private static $summary_fields = array( |
|
|
|
|
69
|
|
|
'Email' => 'From', |
70
|
|
|
'AdminEmail' => 'To', |
71
|
|
|
'Created' => 'Created', |
72
|
|
|
'SentToAdmin.Nice' => 'Sent to Admin', |
73
|
|
|
'SentToCustomer.Nice' => 'Sent to Customer', |
74
|
|
|
'Enquiry' => 'Enquiry', |
75
|
|
|
'Responded.Nice' => 'Replied', |
76
|
|
|
'Page.Title' => 'Page' |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
private static $field_labes = array( |
|
|
|
|
80
|
|
|
'Email' => 'From', |
81
|
|
|
'AdminEmail' => 'To' |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
public function canCreate($member = null) { |
85
|
|
|
return false; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function canDelete($member = null) { |
89
|
|
|
return false; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function getCMSFields() |
93
|
|
|
{ |
94
|
|
|
$fields = parent::getCMSFields(); |
95
|
|
|
$fields->replaceField( |
96
|
|
|
'Data', |
97
|
|
|
LiteralField::create('NiceData', $this->getNiceData()) |
98
|
|
|
); |
99
|
|
|
$fixedFields = array( |
100
|
|
|
'AdminEmail', |
101
|
|
|
'SentToCustomer', |
102
|
|
|
'SentToAdmin', |
103
|
|
|
'FirstName', |
104
|
|
|
'Email', |
105
|
|
|
'Surname', |
106
|
|
|
'Phone', |
107
|
|
|
'Enquiry' |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
$labels = $this->FieldLabels(); |
111
|
|
|
foreach($fixedFields as $fixedField) { |
112
|
|
|
$fields->replaceField( |
113
|
|
|
$fixedField, |
114
|
|
|
ReadonlyField::create($fixedField, $labels[$fixedField]) |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
$fields->removeByName('PageID'); |
118
|
|
|
|
119
|
|
|
return $fields; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* returns list of fields as they are exported |
124
|
|
|
* @return array |
125
|
|
|
* Field => Label |
126
|
|
|
*/ |
127
|
|
|
// public function getExportFields(); |
|
|
|
|
128
|
|
|
|
129
|
|
|
function getNiceData() |
|
|
|
|
130
|
|
|
{ |
131
|
|
|
$array = unserialize($this->Data); |
|
|
|
|
132
|
|
|
$html = '<ul>'; |
133
|
|
|
if(is_array($array)){ |
134
|
|
|
foreach($array as $field => $value){ |
135
|
|
|
$html .= '<li><strong>'.$field.':</strong> '.$value; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
$html .= '</ul>'; |
139
|
|
|
|
140
|
|
|
return $html; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
} |
144
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.