-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.ao_service_size_card.php
85 lines (51 loc) · 2.18 KB
/
class.ao_service_size_card.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
class AOServiceSizeCard {
protected $response;
protected $form;
public function __construct ( $request = null ) {
$this->response = new AOModelResponse();
$this->form = new AOFormSizeCard();
if ( ! empty( $request['method'] ) && method_exists( $this, $request['method'], ) ){
$this->{$request['method']}( $request );
}
}
public function getResponse ( ) {
return $this->response;
}
public function save ( $request )
{
// Unset boilerplate vars
$data = $request['data'];
if ( $this->form->isValid( $data ) ) {
$userId = get_current_user_id(); // int
$formName = $this->form->getName(); // string
$cleanData = $this->form->getValues(); // array
$jsonData = json_encode( $cleanData, JSON_HEX_QUOT ); // string
update_user_meta( $userId, $formName, $jsonData );
// Sends a success response //
$this->response->result = 1;
$this->response->form = $this->form->getName();
$this->response->setTextMessage( 'Your size card has been saved.', 'success' );
$this->response->messages = [];
} else {
// Invalid Entry //
$this->response->result = 0;
$this->response->form = $this->form->getName();
$this->response->setTextMessage( 'There are errors on your form.', 'error' );
$this->response->messages = $this->form->getMessages();
}
}
protected function setElementMessages ( Zend_Form_Element $element ) {
$messages = $element->getMessages();
foreach ( $messages as $error => $message ) {
$this->response->setTextMessage( $message, 'error' );
}
}
public function getFormData ( $request ) {
$userId = get_current_user_id(); // int
$data = get_user_meta( $userId, 'AOFormSizeCard', true );
$this->response->result = 1;
$this->response->form = $this->form->getName();
$this->response->data = json_decode( $data );
}
}