1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
class OrderForm_Feedback extends Form |
|
|
|
|
5
|
|
|
{ |
6
|
|
|
|
7
|
|
|
protected $order = null; |
8
|
|
|
|
9
|
|
|
public function __construct(Controller $controller, $name, Order $order) |
10
|
|
|
{ |
11
|
|
|
$this->order = $order; |
12
|
|
|
$values = $this->getValueFromOrderConfirmationPage('FeedbackValuesOptions'); |
13
|
|
|
$values = explode(',', $values); |
14
|
|
|
$newValues = array(); |
15
|
|
|
foreach($values as $value) { |
16
|
|
|
$value = trim($value); |
17
|
|
|
$newValues[Convert::raw2att($value)] = $value; |
18
|
|
|
} |
19
|
|
|
$fields = FieldList::create( |
20
|
|
|
array( |
21
|
|
|
HeaderField::create('FeedbackHeading', $this->getValueFromOrderConfirmationPage('FeedbackHeader'), 3), |
22
|
|
|
OptionsetField::create( |
23
|
|
|
'Rating', |
24
|
|
|
$this->getValueFromOrderConfirmationPage('FeedbackValuesFieldLabel'), |
25
|
|
|
$newValues |
26
|
|
|
), |
27
|
|
|
TextareaField::create('Note', $this->getValueFromOrderConfirmationPage('FeedbackNotesFieldLabel')) |
28
|
|
|
) |
29
|
|
|
); |
30
|
|
|
$actions = FieldList::create( |
31
|
|
|
FormAction::create('dofeedback', $this->getValueFromOrderConfirmationPage('FeedbackFormSubmitLabel')) |
32
|
|
|
); |
33
|
|
|
$requiredFields = array( |
34
|
|
|
'FeedbackValue' |
35
|
|
|
); |
36
|
|
|
$validator = OrderForm_Feedback_Validator::create($requiredFields); |
37
|
|
|
parent::__construct($controller, $name, $fields, $actions, $validator); |
38
|
|
|
|
39
|
|
|
$oldData = Session::get("FormInfo.{$this->FormName()}.data"); |
40
|
|
|
if ($oldData && (is_array($oldData) || is_object($oldData))) { |
41
|
|
|
$this->loadDataFrom($oldData); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
$this->extend('updateOrderForm_Feedback', $this); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param array $data The form request data submitted |
48
|
|
|
* @param Form $form The {@link Form} this was submitted on |
49
|
|
|
* @param HTTPRequest $request The {@link Form} this was submitted on |
|
|
|
|
50
|
|
|
*/ |
51
|
|
|
public function dofeedback(array $data, Form $form, SS_HTTPRequest $request) |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
$SQLData = Convert::raw2sql($data); |
54
|
|
|
if ($this->order) { |
55
|
|
|
$object = OrderFeedback::create($SQLData); |
56
|
|
|
$object->OrderID = $this->order->ID; |
|
|
|
|
57
|
|
|
$objet->write(); |
|
|
|
|
58
|
|
|
$form->sessionMessage( |
59
|
|
|
$this->getValueFromOrderConfirmationPage('FeedbackFormThankYou'), |
60
|
|
|
'good' |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
return $this->controller->redirectBack(); |
64
|
|
|
} |
65
|
|
|
$form->sessionMessage( |
66
|
|
|
_t( |
67
|
|
|
'OrderForm_Feedback.COULD_NOT_RECORD_FEEDBACK', |
68
|
|
|
'Sorry, order feedback could not be recorded.' |
69
|
|
|
), |
70
|
|
|
'bad' |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
return $this->controller->redirectBack(); |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* saves the form into session. |
79
|
|
|
* |
80
|
|
|
* @param array $data - data from form. |
|
|
|
|
81
|
|
|
*/ |
82
|
|
|
public function saveDataToSession() |
83
|
|
|
{ |
84
|
|
|
$data = $this->getData(); |
85
|
|
|
Session::set("FormInfo.{$this->FormName()}.data", $data); |
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
protected function getValueFromOrderConfirmationPage($value) |
|
|
|
|
89
|
|
|
{ |
90
|
|
|
if($page = $this->getOrderConfirmationPage()) { |
|
|
|
|
91
|
|
|
return $page->$value; |
92
|
|
|
} else { |
93
|
|
|
$defaults = Config::inst()->get('OrderConfirmationPage', 'defaults'); |
94
|
|
|
if($defaults && is_array($defaults) && isset($defaults[$value])) { |
95
|
|
|
return $defaults[$value]; |
96
|
|
|
} |
97
|
|
|
return _t('OrderForm_Feedback.'.$value, 'OrderForm_Feedback.'.$value.' value not set in translations'); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
protected $_orderConfirmationPage = null; |
102
|
|
|
|
103
|
|
|
protected function getOrderConfirmationPage() |
104
|
|
|
{ |
105
|
|
|
if(! $this->_orderConfirmationPage) { |
106
|
|
|
$this->_orderConfirmationPage = OrderConfirmationPage::get()->first(); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
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.