1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class CatalogProductInquiry |
5
|
|
|
*/ |
6
|
|
|
class CatalogProductInquiry extends DataObject implements PermissionProvider |
7
|
|
|
{ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @var string |
11
|
|
|
*/ |
12
|
|
|
private static $singular_name = 'Product Inquiry'; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
private static $plural_name = 'Product Inquiries'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var array |
21
|
|
|
*/ |
22
|
|
|
private static $db = [ |
23
|
|
|
'Name' => 'Varchar(255)', |
24
|
|
|
'Phone' => 'Varchar', |
25
|
|
|
'Email' => 'Varchar(255)', |
26
|
|
|
'Comment' => 'Text', |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
private static $has_one = [ |
33
|
|
|
'Product' => 'CatalogProduct', |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var array |
38
|
|
|
*/ |
39
|
|
|
private static $summary_fields = [ |
40
|
|
|
'Created.Nice' => 'Inquiry Date', |
41
|
|
|
'Name' => 'Name', |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return FieldList |
46
|
|
|
*/ |
47
|
|
|
public function getCMSFields() |
48
|
|
|
{ |
49
|
|
|
$fields = parent::getCMSFields(); |
50
|
|
|
|
51
|
|
|
$fields->transform(new ReadonlyTransformation()); |
52
|
|
|
|
53
|
|
|
return $fields; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param null $params |
58
|
|
|
* |
59
|
|
|
* @return FieldList |
60
|
|
|
*/ |
61
|
|
|
public function getFrontEndFields($params = null) |
62
|
|
|
{ |
63
|
|
|
$fields = parent::getFrontEndFields($params); |
64
|
|
|
|
65
|
|
|
$value = (Controller::curr()->hasMethod('getProduct')) |
66
|
|
|
? Controller::curr()->getProduct()->ID |
67
|
|
|
: 0; |
68
|
|
|
|
69
|
|
|
$fields->replaceField( |
70
|
|
|
'ProductID', |
71
|
|
|
HiddenField::create('ProductID') |
72
|
|
|
->setValue($value) |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
return $fields; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return FieldList |
80
|
|
|
*/ |
81
|
|
|
public function getFrontEndActions() |
82
|
|
|
{ |
83
|
|
|
$actions = FieldList::create( |
84
|
|
|
FormAction::create('doProductInquiry') |
85
|
|
|
->setTitle('Send Inquiry') |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
$this->extend('updateFrontEndActions', $actions); |
89
|
|
|
|
90
|
|
|
return $actions; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function getFrontEndRequiredFields() |
94
|
|
|
{ |
95
|
|
|
$required = RequiredFields::create( |
96
|
|
|
'Name', |
97
|
|
|
'Email' |
98
|
|
|
); |
99
|
|
|
|
100
|
|
|
$this->extend('updateFrontEndRequiredFields', $required); |
101
|
|
|
|
102
|
|
|
return $required; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return array |
107
|
|
|
*/ |
108
|
|
|
public function providePermissions() |
109
|
|
|
{ |
110
|
|
|
return [ |
111
|
|
|
'CatalogProductInquiry_delete' => [ |
112
|
|
|
'name' => 'Delete a Product Inquiry', |
113
|
|
|
'category' => 'Product InquiryPermissions', |
114
|
|
|
], |
115
|
|
|
'CatalogProductInquiry_view' => [ |
116
|
|
|
'name' => 'View a Product Inquiry', |
117
|
|
|
'category' => 'Product InquiryPermissions', |
118
|
|
|
], |
119
|
|
|
]; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param null $member |
124
|
|
|
* |
125
|
|
|
* @return bool |
126
|
|
|
*/ |
127
|
|
|
public function canCreate($member = null) |
128
|
|
|
{ |
129
|
|
|
return true; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param null $member |
134
|
|
|
* |
135
|
|
|
* @return bool |
136
|
|
|
*/ |
137
|
|
|
public function canEdit($member = null) |
138
|
|
|
{ |
139
|
|
|
return false; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param null $member |
144
|
|
|
* |
145
|
|
|
* @return bool|int |
146
|
|
|
*/ |
147
|
|
|
public function canDelete($member = null) |
148
|
|
|
{ |
149
|
|
|
$member = $member === null ? Member::currentUser() : $member; |
150
|
|
|
|
151
|
|
|
return Permission::checkMember($member, 'CatalogProductInquiry_delete'); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @param null $member |
156
|
|
|
* |
157
|
|
|
* @return bool|int |
158
|
|
|
*/ |
159
|
|
|
public function canView($member = null) |
160
|
|
|
{ |
161
|
|
|
$member = $member === null ? Member::currentUser() : $member; |
162
|
|
|
|
163
|
|
|
return Permission::checkMember($member, 'CatalogProductInquiry_view'); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
} |