-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.ao_service_profile.php
147 lines (91 loc) · 3.97 KB
/
class.ao_service_profile.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
class AOServiceProfile {
protected $response;
protected $form;
protected $AOModelUserMeta;
public function __construct ( $request = null ) {
$this->response = new AOModelResponse();
$this->form = new AOFormProfile();
$this->AOModelUserMeta = new AOModelUserMeta([
'db' => 'db',
'name'=> $GLOBALS['wpdb']->prefix . 'usermeta',
'primary' => 'umeta_id'
]);
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 profile 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, 'AOFormProfile', true );
$this->response->result = 1;
$this->response->form = $this->form->getName();
$this->response->data = json_decode( $data );
}
public function saveResume ( $request ) {
try{
$this->form = new AOFormResume();
$data = $request['data'];
if ( $this->form->isValid( $data ) ) {
$userId = get_current_user_id(); // int
$formName = $this->form->getName(); // string
$cleanData = $this->form->getValues(); // array
$html = $cleanData['resume'];
$this->AOModelUserMeta->updateUserMeta( $userId, $formName, $html );
// Sends a success response //
$this->response->result = 1;
$this->response->form = $this->form->getName();
$this->response->setTextMessage( 'Your resume 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();
}
}
catch( Exception | Error $e ){
pr( $e->getMessage() );
}
}
public function getResumeData ( $request ) {
$userId = get_current_user_id(); // int
$html = get_user_meta( $userId, 'AOFormResume', true );
$this->response->result = 1;
$this->response->form = 'AOFormResume';
$this->response->data = $html;
}
}