@@ -15,21 +15,21 @@ |
||
15 | 15 | */ |
16 | 16 | interface JsonSerializableAndUnserializable |
17 | 17 | { |
18 | - /** |
|
19 | - * Creates a simple PHP array or stdClass from this object's properties, which can be easily serialized using |
|
20 | - * wp_json_serialize(). |
|
21 | - * @since 4.9.80.p |
|
22 | - * @return mixed |
|
23 | - */ |
|
24 | - public function toJsonSerializableData(); |
|
18 | + /** |
|
19 | + * Creates a simple PHP array or stdClass from this object's properties, which can be easily serialized using |
|
20 | + * wp_json_serialize(). |
|
21 | + * @since 4.9.80.p |
|
22 | + * @return mixed |
|
23 | + */ |
|
24 | + public function toJsonSerializableData(); |
|
25 | 25 | |
26 | - /** |
|
27 | - * Initializes this object from data |
|
28 | - * @since 4.9.80.p |
|
29 | - * @param mixed $data |
|
30 | - * @return boolean success |
|
31 | - */ |
|
32 | - public function fromJsonSerializedData($data); |
|
26 | + /** |
|
27 | + * Initializes this object from data |
|
28 | + * @since 4.9.80.p |
|
29 | + * @param mixed $data |
|
30 | + * @return boolean success |
|
31 | + */ |
|
32 | + public function fromJsonSerializedData($data); |
|
33 | 33 | } |
34 | 34 | // End of file JsonSerializableAndUnserializable.php |
35 | 35 | // Location: EventEspresso\core\services\json/JsonSerializableAndUnserializable.php |
@@ -15,37 +15,37 @@ |
||
15 | 15 | interface FileSubmissionInterface |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @return string |
|
20 | - */ |
|
21 | - public function getName(); |
|
22 | - |
|
23 | - /** |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function getType(); |
|
27 | - |
|
28 | - /** |
|
29 | - * @return int |
|
30 | - */ |
|
31 | - public function getSize(); |
|
32 | - |
|
33 | - /** |
|
34 | - * @return string |
|
35 | - */ |
|
36 | - public function getTmpFile(); |
|
37 | - |
|
38 | - /** |
|
39 | - * Should just return the filename. |
|
40 | - * @since 4.9.80.p |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public function __toString(); |
|
44 | - |
|
45 | - /** |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public function getErrorCode(); |
|
18 | + /** |
|
19 | + * @return string |
|
20 | + */ |
|
21 | + public function getName(); |
|
22 | + |
|
23 | + /** |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function getType(); |
|
27 | + |
|
28 | + /** |
|
29 | + * @return int |
|
30 | + */ |
|
31 | + public function getSize(); |
|
32 | + |
|
33 | + /** |
|
34 | + * @return string |
|
35 | + */ |
|
36 | + public function getTmpFile(); |
|
37 | + |
|
38 | + /** |
|
39 | + * Should just return the filename. |
|
40 | + * @since 4.9.80.p |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public function __toString(); |
|
44 | + |
|
45 | + /** |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public function getErrorCode(); |
|
49 | 49 | } |
50 | 50 | // End of file FileSubmissionInterface.php |
51 | 51 | // Location: EventEspresso\core\services\request\files/FileSubmissionInterface.php |
@@ -38,264 +38,264 @@ |
||
38 | 38 | */ |
39 | 39 | class FilesDataHandler |
40 | 40 | { |
41 | - /** |
|
42 | - * @var Request |
|
43 | - */ |
|
44 | - protected $request; |
|
41 | + /** |
|
42 | + * @var Request |
|
43 | + */ |
|
44 | + protected $request; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @var CollectionInterface | FileSubmissionInterface[] |
|
48 | - */ |
|
49 | - protected $file_objects; |
|
46 | + /** |
|
47 | + * @var CollectionInterface | FileSubmissionInterface[] |
|
48 | + */ |
|
49 | + protected $file_objects; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @var bool |
|
53 | - */ |
|
54 | - protected $initialized = false; |
|
51 | + /** |
|
52 | + * @var bool |
|
53 | + */ |
|
54 | + protected $initialized = false; |
|
55 | 55 | |
56 | - /** |
|
57 | - * FilesDataHandler constructor. |
|
58 | - * @param Request $request |
|
59 | - */ |
|
60 | - public function __construct(Request $request) |
|
61 | - { |
|
62 | - $this->request = $request; |
|
63 | - } |
|
56 | + /** |
|
57 | + * FilesDataHandler constructor. |
|
58 | + * @param Request $request |
|
59 | + */ |
|
60 | + public function __construct(Request $request) |
|
61 | + { |
|
62 | + $this->request = $request; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @since 4.9.80.p |
|
67 | - * @return CollectionInterface | FileSubmissionInterface[] |
|
68 | - * @throws UnexpectedValueException |
|
69 | - * @throws InvalidArgumentException |
|
70 | - */ |
|
71 | - protected function getFileObjects() |
|
72 | - { |
|
73 | - $this->initialize(); |
|
74 | - return $this->file_objects; |
|
75 | - } |
|
65 | + /** |
|
66 | + * @since 4.9.80.p |
|
67 | + * @return CollectionInterface | FileSubmissionInterface[] |
|
68 | + * @throws UnexpectedValueException |
|
69 | + * @throws InvalidArgumentException |
|
70 | + */ |
|
71 | + protected function getFileObjects() |
|
72 | + { |
|
73 | + $this->initialize(); |
|
74 | + return $this->file_objects; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Sets up the file objects from the request's $_FILES data. |
|
79 | - * @since 4.9.80.p |
|
80 | - * @throws UnexpectedValueException |
|
81 | - * @throws InvalidArgumentException |
|
82 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
83 | - */ |
|
84 | - protected function initialize() |
|
85 | - { |
|
86 | - if ($this->initialized) { |
|
87 | - return; |
|
88 | - } |
|
89 | - $this->file_objects = new Collection( |
|
90 | - // collection interface |
|
91 | - 'EventEspresso\core\services\request\files\FileSubmissionInterface', |
|
92 | - // collection name |
|
93 | - 'submitted_files' |
|
94 | - ); |
|
95 | - $files_raw_data = $this->request->filesParams(); |
|
96 | - if (empty($files_raw_data)) { |
|
97 | - return; |
|
98 | - } |
|
99 | - if ($this->isStrangeFilesArray($files_raw_data)) { |
|
100 | - $data = $this->fixFilesDataArray($files_raw_data); |
|
101 | - } else { |
|
102 | - $data = $files_raw_data; |
|
103 | - } |
|
104 | - $this->createFileObjects($data); |
|
105 | - $this->initialized = true; |
|
106 | - } |
|
77 | + /** |
|
78 | + * Sets up the file objects from the request's $_FILES data. |
|
79 | + * @since 4.9.80.p |
|
80 | + * @throws UnexpectedValueException |
|
81 | + * @throws InvalidArgumentException |
|
82 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
83 | + */ |
|
84 | + protected function initialize() |
|
85 | + { |
|
86 | + if ($this->initialized) { |
|
87 | + return; |
|
88 | + } |
|
89 | + $this->file_objects = new Collection( |
|
90 | + // collection interface |
|
91 | + 'EventEspresso\core\services\request\files\FileSubmissionInterface', |
|
92 | + // collection name |
|
93 | + 'submitted_files' |
|
94 | + ); |
|
95 | + $files_raw_data = $this->request->filesParams(); |
|
96 | + if (empty($files_raw_data)) { |
|
97 | + return; |
|
98 | + } |
|
99 | + if ($this->isStrangeFilesArray($files_raw_data)) { |
|
100 | + $data = $this->fixFilesDataArray($files_raw_data); |
|
101 | + } else { |
|
102 | + $data = $files_raw_data; |
|
103 | + } |
|
104 | + $this->createFileObjects($data); |
|
105 | + $this->initialized = true; |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Detects if $_FILES is a weird multi-dimensional array that needs fixing or not. |
|
110 | - * @since 4.9.80.p |
|
111 | - * @param $files_data |
|
112 | - * @return bool |
|
113 | - * @throws UnexpectedValueException |
|
114 | - */ |
|
115 | - protected function isStrangeFilesArray($files_data) |
|
116 | - { |
|
117 | - if (!is_array($files_data)) { |
|
118 | - throw new UnexpectedValueException( |
|
119 | - sprintf( |
|
120 | - esc_html__( |
|
121 | - 'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.', |
|
122 | - 'event_espresso' |
|
123 | - ), |
|
124 | - (string) $files_data |
|
125 | - ) |
|
126 | - ); |
|
127 | - } |
|
128 | - $first_value = reset($files_data); |
|
129 | - if (!is_array($first_value)) { |
|
130 | - throw new UnexpectedValueException( |
|
131 | - sprintf( |
|
132 | - esc_html__( |
|
133 | - 'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.', |
|
134 | - 'event_espresso' |
|
135 | - ), |
|
136 | - (string) $first_value |
|
137 | - ) |
|
138 | - ); |
|
139 | - } |
|
140 | - $first_sub_array_item = reset($first_value); |
|
141 | - if (is_array($first_sub_array_item)) { |
|
142 | - // not just a 2d array |
|
143 | - return true; |
|
144 | - } |
|
145 | - // yep, just 2d array |
|
146 | - return false; |
|
147 | - } |
|
108 | + /** |
|
109 | + * Detects if $_FILES is a weird multi-dimensional array that needs fixing or not. |
|
110 | + * @since 4.9.80.p |
|
111 | + * @param $files_data |
|
112 | + * @return bool |
|
113 | + * @throws UnexpectedValueException |
|
114 | + */ |
|
115 | + protected function isStrangeFilesArray($files_data) |
|
116 | + { |
|
117 | + if (!is_array($files_data)) { |
|
118 | + throw new UnexpectedValueException( |
|
119 | + sprintf( |
|
120 | + esc_html__( |
|
121 | + 'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.', |
|
122 | + 'event_espresso' |
|
123 | + ), |
|
124 | + (string) $files_data |
|
125 | + ) |
|
126 | + ); |
|
127 | + } |
|
128 | + $first_value = reset($files_data); |
|
129 | + if (!is_array($first_value)) { |
|
130 | + throw new UnexpectedValueException( |
|
131 | + sprintf( |
|
132 | + esc_html__( |
|
133 | + 'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.', |
|
134 | + 'event_espresso' |
|
135 | + ), |
|
136 | + (string) $first_value |
|
137 | + ) |
|
138 | + ); |
|
139 | + } |
|
140 | + $first_sub_array_item = reset($first_value); |
|
141 | + if (is_array($first_sub_array_item)) { |
|
142 | + // not just a 2d array |
|
143 | + return true; |
|
144 | + } |
|
145 | + // yep, just 2d array |
|
146 | + return false; |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * Takes into account that $_FILES does a weird thing when you have hierarchical form names (eg `<input type="file" |
|
151 | - * name="my[hierarchical][form]">`): it leaves the top-level form part alone, but replaces the SECOND part with |
|
152 | - * "name", "size", "tmp_name", etc. So that file's data is located at "my[name][hierarchical][form]", |
|
153 | - * "my[size][hierarchical][form]", "my[tmp_name][hierarchical][form]", etc. It's really weird. |
|
154 | - * @since 4.9.80.p |
|
155 | - * @param $files_data |
|
156 | - * @return array |
|
157 | - */ |
|
158 | - protected function fixFilesDataArray($files_data) |
|
159 | - { |
|
160 | - $sane_files_array = []; |
|
161 | - foreach ($files_data as $top_level_name => $top_level_children) { |
|
162 | - $sub_array = []; |
|
163 | - $sane_files_array[ $top_level_name ] = []; |
|
164 | - foreach ($top_level_children as $file_data_part => $second_level_children) { |
|
165 | - foreach ($second_level_children as $next_level_name => $sub_values) { |
|
166 | - $sub_array[ $next_level_name ] = $this->organizeFilesData($sub_values, $file_data_part); |
|
167 | - } |
|
168 | - $sane_files_array[ $top_level_name ] = array_replace_recursive( |
|
169 | - $sub_array, |
|
170 | - $sane_files_array[ $top_level_name ] |
|
171 | - ); |
|
172 | - } |
|
173 | - } |
|
174 | - return $sane_files_array; |
|
175 | - } |
|
149 | + /** |
|
150 | + * Takes into account that $_FILES does a weird thing when you have hierarchical form names (eg `<input type="file" |
|
151 | + * name="my[hierarchical][form]">`): it leaves the top-level form part alone, but replaces the SECOND part with |
|
152 | + * "name", "size", "tmp_name", etc. So that file's data is located at "my[name][hierarchical][form]", |
|
153 | + * "my[size][hierarchical][form]", "my[tmp_name][hierarchical][form]", etc. It's really weird. |
|
154 | + * @since 4.9.80.p |
|
155 | + * @param $files_data |
|
156 | + * @return array |
|
157 | + */ |
|
158 | + protected function fixFilesDataArray($files_data) |
|
159 | + { |
|
160 | + $sane_files_array = []; |
|
161 | + foreach ($files_data as $top_level_name => $top_level_children) { |
|
162 | + $sub_array = []; |
|
163 | + $sane_files_array[ $top_level_name ] = []; |
|
164 | + foreach ($top_level_children as $file_data_part => $second_level_children) { |
|
165 | + foreach ($second_level_children as $next_level_name => $sub_values) { |
|
166 | + $sub_array[ $next_level_name ] = $this->organizeFilesData($sub_values, $file_data_part); |
|
167 | + } |
|
168 | + $sane_files_array[ $top_level_name ] = array_replace_recursive( |
|
169 | + $sub_array, |
|
170 | + $sane_files_array[ $top_level_name ] |
|
171 | + ); |
|
172 | + } |
|
173 | + } |
|
174 | + return $sane_files_array; |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * Recursively explores the array until it finds a leaf node, and tacks `$type` as a final index in front of it. |
|
179 | - * @since 4.9.80.p |
|
180 | - * @param $data array|string |
|
181 | - * @param $type 'name', 'tmp_name', 'size', or 'error' |
|
182 | - * @param $name string |
|
183 | - * @return array|string |
|
184 | - */ |
|
185 | - protected function organizeFilesData($data, $type) |
|
186 | - { |
|
187 | - if (! is_array($data)) { |
|
188 | - return [ |
|
189 | - $type => $data |
|
190 | - ]; |
|
191 | - } |
|
192 | - $organized_data = []; |
|
193 | - foreach ($data as $input_name_part => $sub_inputs_or_value) { |
|
194 | - if (is_array($sub_inputs_or_value)) { |
|
195 | - $organized_data[ $input_name_part ] = $this->organizeFilesData($sub_inputs_or_value, $type); |
|
196 | - } else { |
|
197 | - $organized_data[ $input_name_part ][ $type ] = $sub_inputs_or_value; |
|
198 | - } |
|
199 | - } |
|
200 | - return $organized_data; |
|
201 | - } |
|
177 | + /** |
|
178 | + * Recursively explores the array until it finds a leaf node, and tacks `$type` as a final index in front of it. |
|
179 | + * @since 4.9.80.p |
|
180 | + * @param $data array|string |
|
181 | + * @param $type 'name', 'tmp_name', 'size', or 'error' |
|
182 | + * @param $name string |
|
183 | + * @return array|string |
|
184 | + */ |
|
185 | + protected function organizeFilesData($data, $type) |
|
186 | + { |
|
187 | + if (! is_array($data)) { |
|
188 | + return [ |
|
189 | + $type => $data |
|
190 | + ]; |
|
191 | + } |
|
192 | + $organized_data = []; |
|
193 | + foreach ($data as $input_name_part => $sub_inputs_or_value) { |
|
194 | + if (is_array($sub_inputs_or_value)) { |
|
195 | + $organized_data[ $input_name_part ] = $this->organizeFilesData($sub_inputs_or_value, $type); |
|
196 | + } else { |
|
197 | + $organized_data[ $input_name_part ][ $type ] = $sub_inputs_or_value; |
|
198 | + } |
|
199 | + } |
|
200 | + return $organized_data; |
|
201 | + } |
|
202 | 202 | |
203 | - /** |
|
204 | - * Takes the organized $_FILES array (where all file info is located at the same spot as you'd expect an input |
|
205 | - * to be in $_GET or $_POST, with all the file's data located side-by-side in an array) and creates a |
|
206 | - * multi-dimensional array of FileSubmissionInterface objects. Stores it in `$this->file_objects`. |
|
207 | - * @since 4.9.80.p |
|
208 | - * @param array $organized_files $_FILES but organized like $_POST |
|
209 | - * @param array $name_parts_so_far for multidimensional HTML form names, |
|
210 | - * @throws UnexpectedValueException |
|
211 | - * @throws InvalidArgumentException |
|
212 | - */ |
|
213 | - protected function createFileObjects($organized_files, $name_parts_so_far = []) |
|
214 | - { |
|
215 | - if (!is_array($organized_files)) { |
|
216 | - throw new UnexpectedValueException( |
|
217 | - sprintf( |
|
218 | - esc_html__( |
|
219 | - 'Unexpected PHP $organized_files data format. "%1$s" was expected to be an array.', |
|
220 | - 'event_espresso' |
|
221 | - ), |
|
222 | - (string) $organized_files |
|
223 | - ) |
|
224 | - ); |
|
225 | - } |
|
226 | - foreach ($organized_files as $key => $value) { |
|
227 | - $this_input_name_parts = $name_parts_so_far; |
|
228 | - array_push( |
|
229 | - $this_input_name_parts, |
|
230 | - $key |
|
231 | - ); |
|
232 | - if (isset($value['name'], $value['tmp_name'], $value['size'])) { |
|
233 | - $html_name = $this->inputNameFromParts($this_input_name_parts); |
|
234 | - $this->file_objects->add( |
|
235 | - new FileSubmission( |
|
236 | - $value['name'], |
|
237 | - $value['tmp_name'], |
|
238 | - $value['size'], |
|
239 | - $value['error'] |
|
240 | - ), |
|
241 | - $html_name |
|
242 | - ); |
|
243 | - } else { |
|
244 | - $this->createFileObjects($value, $this_input_name_parts); |
|
245 | - } |
|
246 | - } |
|
247 | - } |
|
203 | + /** |
|
204 | + * Takes the organized $_FILES array (where all file info is located at the same spot as you'd expect an input |
|
205 | + * to be in $_GET or $_POST, with all the file's data located side-by-side in an array) and creates a |
|
206 | + * multi-dimensional array of FileSubmissionInterface objects. Stores it in `$this->file_objects`. |
|
207 | + * @since 4.9.80.p |
|
208 | + * @param array $organized_files $_FILES but organized like $_POST |
|
209 | + * @param array $name_parts_so_far for multidimensional HTML form names, |
|
210 | + * @throws UnexpectedValueException |
|
211 | + * @throws InvalidArgumentException |
|
212 | + */ |
|
213 | + protected function createFileObjects($organized_files, $name_parts_so_far = []) |
|
214 | + { |
|
215 | + if (!is_array($organized_files)) { |
|
216 | + throw new UnexpectedValueException( |
|
217 | + sprintf( |
|
218 | + esc_html__( |
|
219 | + 'Unexpected PHP $organized_files data format. "%1$s" was expected to be an array.', |
|
220 | + 'event_espresso' |
|
221 | + ), |
|
222 | + (string) $organized_files |
|
223 | + ) |
|
224 | + ); |
|
225 | + } |
|
226 | + foreach ($organized_files as $key => $value) { |
|
227 | + $this_input_name_parts = $name_parts_so_far; |
|
228 | + array_push( |
|
229 | + $this_input_name_parts, |
|
230 | + $key |
|
231 | + ); |
|
232 | + if (isset($value['name'], $value['tmp_name'], $value['size'])) { |
|
233 | + $html_name = $this->inputNameFromParts($this_input_name_parts); |
|
234 | + $this->file_objects->add( |
|
235 | + new FileSubmission( |
|
236 | + $value['name'], |
|
237 | + $value['tmp_name'], |
|
238 | + $value['size'], |
|
239 | + $value['error'] |
|
240 | + ), |
|
241 | + $html_name |
|
242 | + ); |
|
243 | + } else { |
|
244 | + $this->createFileObjects($value, $this_input_name_parts); |
|
245 | + } |
|
246 | + } |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * Takes the input name parts, like `['my', 'great', 'file', 'input1']` |
|
251 | - * and returns the HTML name for it, "my[great][file][input1]" |
|
252 | - * @since 4.9.80.p |
|
253 | - * @param $parts |
|
254 | - * @throws UnexpectedValueException |
|
255 | - */ |
|
256 | - protected function inputNameFromParts($parts) |
|
257 | - { |
|
258 | - if (!is_array($parts)) { |
|
259 | - throw new UnexpectedValueException(esc_html__('Name parts should be an array.', 'event_espresso')); |
|
260 | - } |
|
261 | - $generated_string = ''; |
|
262 | - foreach ($parts as $part) { |
|
263 | - if ($generated_string === '') { |
|
264 | - $generated_string = (string) $part; |
|
265 | - } else { |
|
266 | - $generated_string .= '[' . (string) $part . ']'; |
|
267 | - } |
|
268 | - } |
|
269 | - return $generated_string; |
|
270 | - } |
|
249 | + /** |
|
250 | + * Takes the input name parts, like `['my', 'great', 'file', 'input1']` |
|
251 | + * and returns the HTML name for it, "my[great][file][input1]" |
|
252 | + * @since 4.9.80.p |
|
253 | + * @param $parts |
|
254 | + * @throws UnexpectedValueException |
|
255 | + */ |
|
256 | + protected function inputNameFromParts($parts) |
|
257 | + { |
|
258 | + if (!is_array($parts)) { |
|
259 | + throw new UnexpectedValueException(esc_html__('Name parts should be an array.', 'event_espresso')); |
|
260 | + } |
|
261 | + $generated_string = ''; |
|
262 | + foreach ($parts as $part) { |
|
263 | + if ($generated_string === '') { |
|
264 | + $generated_string = (string) $part; |
|
265 | + } else { |
|
266 | + $generated_string .= '[' . (string) $part . ']'; |
|
267 | + } |
|
268 | + } |
|
269 | + return $generated_string; |
|
270 | + } |
|
271 | 271 | |
272 | - /** |
|
273 | - * Gets the input by the indicated $name_parts. |
|
274 | - * Eg if you're looking for an input named "my[great][file][input1]", $name_parts |
|
275 | - * should be `['my', 'great', 'file', 'input1']`. |
|
276 | - * Alternatively, you could use `FileDataHandler::getFileObject('my[great][file][input1]');` |
|
277 | - * @since 4.9.80.p |
|
278 | - * @param $name_parts |
|
279 | - * @throws UnexpectedValueException |
|
280 | - * @return FileSubmissionInterface |
|
281 | - */ |
|
282 | - public function getFileObjectFromNameParts($name_parts) |
|
283 | - { |
|
284 | - return $this->getFileObjects()->get($this->inputNameFromParts($name_parts)); |
|
285 | - } |
|
272 | + /** |
|
273 | + * Gets the input by the indicated $name_parts. |
|
274 | + * Eg if you're looking for an input named "my[great][file][input1]", $name_parts |
|
275 | + * should be `['my', 'great', 'file', 'input1']`. |
|
276 | + * Alternatively, you could use `FileDataHandler::getFileObject('my[great][file][input1]');` |
|
277 | + * @since 4.9.80.p |
|
278 | + * @param $name_parts |
|
279 | + * @throws UnexpectedValueException |
|
280 | + * @return FileSubmissionInterface |
|
281 | + */ |
|
282 | + public function getFileObjectFromNameParts($name_parts) |
|
283 | + { |
|
284 | + return $this->getFileObjects()->get($this->inputNameFromParts($name_parts)); |
|
285 | + } |
|
286 | 286 | |
287 | - /** |
|
288 | - * Gets the FileSubmissionInterface corresponding to the HTML name provided. |
|
289 | - * @since 4.9.80.p |
|
290 | - * @param $html_name |
|
291 | - * @return mixed |
|
292 | - * @throws InvalidArgumentException |
|
293 | - * @throws UnexpectedValueException |
|
294 | - */ |
|
295 | - public function getFileObject($html_name) |
|
296 | - { |
|
297 | - return $this->getFileObjects()->get($html_name); |
|
298 | - } |
|
287 | + /** |
|
288 | + * Gets the FileSubmissionInterface corresponding to the HTML name provided. |
|
289 | + * @since 4.9.80.p |
|
290 | + * @param $html_name |
|
291 | + * @return mixed |
|
292 | + * @throws InvalidArgumentException |
|
293 | + * @throws UnexpectedValueException |
|
294 | + */ |
|
295 | + public function getFileObject($html_name) |
|
296 | + { |
|
297 | + return $this->getFileObjects()->get($html_name); |
|
298 | + } |
|
299 | 299 | } |
300 | 300 | // End of file FilesDataHandler.php |
301 | 301 | // Location: EventEspresso\core\services\request\files/FilesDataHandler.php |
@@ -19,164 +19,164 @@ |
||
19 | 19 | */ |
20 | 20 | class FileSubmission implements FileSubmissionInterface |
21 | 21 | { |
22 | - /** |
|
23 | - * @var string original name on the client machine |
|
24 | - */ |
|
25 | - protected $name; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var string mime type |
|
29 | - */ |
|
30 | - protected $type; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var string file extension |
|
34 | - */ |
|
35 | - protected $extension; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var int in bytes |
|
39 | - */ |
|
40 | - protected $size; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var string local filepath to the temporary file |
|
44 | - */ |
|
45 | - protected $tmp_file; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var int one of UPLOAD_ERR_OK, UPLOAD_ERR_NO_FILE, UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE or other values |
|
49 | - * although those aren't expected. |
|
50 | - */ |
|
51 | - protected $error_code; |
|
52 | - |
|
53 | - /** |
|
54 | - * FileSubmission constructor. |
|
55 | - * @param $name |
|
56 | - * @param $tmp_file |
|
57 | - * @param $size |
|
58 | - * @param null $error_code |
|
59 | - * @throws InvalidArgumentException |
|
60 | - */ |
|
61 | - public function __construct($name, $tmp_file, $size, $error_code = null) |
|
62 | - { |
|
63 | - $this->name = basename($name); |
|
64 | - $scheme = parse_url($tmp_file, PHP_URL_SCHEME); |
|
65 | - if (in_array($scheme, ['http', 'https'])) { |
|
66 | - // Wait a minute- just local filepaths please, no URL schemes allowed! |
|
67 | - throw new InvalidArgumentException( |
|
68 | - sprintf( |
|
69 | - // @codingStandardsIgnoreStart |
|
70 | - esc_html__('The scheme ("%1$s") on the temporary file ("%2$s") indicates is located elsewhere, that’s not ok!', 'event_espresso'), |
|
71 | - // @codingStandardsIgnoreEnd |
|
72 | - $scheme, |
|
73 | - $tmp_file |
|
74 | - ) |
|
75 | - ); |
|
76 | - } |
|
77 | - $this->tmp_file = (string) $tmp_file; |
|
78 | - $this->size = (int) $size; |
|
79 | - $this->error_code = (int) $error_code; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public function getName() |
|
86 | - { |
|
87 | - return $this->name; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Gets the file's mime type |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function getType() |
|
95 | - { |
|
96 | - if (!$this->type) { |
|
97 | - $this->type = $this->determineType(); |
|
98 | - } |
|
99 | - return $this->type; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @since 4.9.80.p |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - protected function determineType() |
|
107 | - { |
|
108 | - if (!$this->getTmpFile()) { |
|
109 | - return ''; |
|
110 | - } |
|
111 | - $finfo = new finfo(FILEINFO_MIME_TYPE); |
|
112 | - return $finfo->file($this->getTmpFile()); |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Gets the file's extension. |
|
117 | - * @since 4.9.80.p |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - public function getExtension() |
|
121 | - { |
|
122 | - if (!$this->extension) { |
|
123 | - $this->extension = $this->determineExtension(); |
|
124 | - } |
|
125 | - return $this->extension; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Determine's the file's extension given the temporary file. |
|
130 | - * @since 4.9.80.p |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - protected function determineExtension() |
|
134 | - { |
|
135 | - $position_of_period = strrpos($this->getName(), '.'); |
|
136 | - if ($position_of_period === false) { |
|
137 | - return ''; |
|
138 | - } |
|
139 | - return mb_substr( |
|
140 | - $this->getName(), |
|
141 | - $position_of_period + 1 |
|
142 | - ); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Gets the size of the file |
|
147 | - * @return int |
|
148 | - */ |
|
149 | - public function getSize() |
|
150 | - { |
|
151 | - return $this->size; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Gets the path to the temporary file which was uploaded. |
|
156 | - * @return string |
|
157 | - */ |
|
158 | - public function getTmpFile() |
|
159 | - { |
|
160 | - return $this->tmp_file; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * @since 4.9.80.p |
|
165 | - * @return string |
|
166 | - */ |
|
167 | - public function __toString() |
|
168 | - { |
|
169 | - return $this->getName(); |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Gets the error code PHP reported for the file upload. |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - public function getErrorCode() |
|
177 | - { |
|
178 | - return $this->error_code; |
|
179 | - } |
|
22 | + /** |
|
23 | + * @var string original name on the client machine |
|
24 | + */ |
|
25 | + protected $name; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var string mime type |
|
29 | + */ |
|
30 | + protected $type; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var string file extension |
|
34 | + */ |
|
35 | + protected $extension; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var int in bytes |
|
39 | + */ |
|
40 | + protected $size; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var string local filepath to the temporary file |
|
44 | + */ |
|
45 | + protected $tmp_file; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var int one of UPLOAD_ERR_OK, UPLOAD_ERR_NO_FILE, UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE or other values |
|
49 | + * although those aren't expected. |
|
50 | + */ |
|
51 | + protected $error_code; |
|
52 | + |
|
53 | + /** |
|
54 | + * FileSubmission constructor. |
|
55 | + * @param $name |
|
56 | + * @param $tmp_file |
|
57 | + * @param $size |
|
58 | + * @param null $error_code |
|
59 | + * @throws InvalidArgumentException |
|
60 | + */ |
|
61 | + public function __construct($name, $tmp_file, $size, $error_code = null) |
|
62 | + { |
|
63 | + $this->name = basename($name); |
|
64 | + $scheme = parse_url($tmp_file, PHP_URL_SCHEME); |
|
65 | + if (in_array($scheme, ['http', 'https'])) { |
|
66 | + // Wait a minute- just local filepaths please, no URL schemes allowed! |
|
67 | + throw new InvalidArgumentException( |
|
68 | + sprintf( |
|
69 | + // @codingStandardsIgnoreStart |
|
70 | + esc_html__('The scheme ("%1$s") on the temporary file ("%2$s") indicates is located elsewhere, that’s not ok!', 'event_espresso'), |
|
71 | + // @codingStandardsIgnoreEnd |
|
72 | + $scheme, |
|
73 | + $tmp_file |
|
74 | + ) |
|
75 | + ); |
|
76 | + } |
|
77 | + $this->tmp_file = (string) $tmp_file; |
|
78 | + $this->size = (int) $size; |
|
79 | + $this->error_code = (int) $error_code; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public function getName() |
|
86 | + { |
|
87 | + return $this->name; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Gets the file's mime type |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function getType() |
|
95 | + { |
|
96 | + if (!$this->type) { |
|
97 | + $this->type = $this->determineType(); |
|
98 | + } |
|
99 | + return $this->type; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @since 4.9.80.p |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + protected function determineType() |
|
107 | + { |
|
108 | + if (!$this->getTmpFile()) { |
|
109 | + return ''; |
|
110 | + } |
|
111 | + $finfo = new finfo(FILEINFO_MIME_TYPE); |
|
112 | + return $finfo->file($this->getTmpFile()); |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Gets the file's extension. |
|
117 | + * @since 4.9.80.p |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + public function getExtension() |
|
121 | + { |
|
122 | + if (!$this->extension) { |
|
123 | + $this->extension = $this->determineExtension(); |
|
124 | + } |
|
125 | + return $this->extension; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Determine's the file's extension given the temporary file. |
|
130 | + * @since 4.9.80.p |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + protected function determineExtension() |
|
134 | + { |
|
135 | + $position_of_period = strrpos($this->getName(), '.'); |
|
136 | + if ($position_of_period === false) { |
|
137 | + return ''; |
|
138 | + } |
|
139 | + return mb_substr( |
|
140 | + $this->getName(), |
|
141 | + $position_of_period + 1 |
|
142 | + ); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Gets the size of the file |
|
147 | + * @return int |
|
148 | + */ |
|
149 | + public function getSize() |
|
150 | + { |
|
151 | + return $this->size; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Gets the path to the temporary file which was uploaded. |
|
156 | + * @return string |
|
157 | + */ |
|
158 | + public function getTmpFile() |
|
159 | + { |
|
160 | + return $this->tmp_file; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * @since 4.9.80.p |
|
165 | + * @return string |
|
166 | + */ |
|
167 | + public function __toString() |
|
168 | + { |
|
169 | + return $this->getName(); |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Gets the error code PHP reported for the file upload. |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + public function getErrorCode() |
|
177 | + { |
|
178 | + return $this->error_code; |
|
179 | + } |
|
180 | 180 | } |
181 | 181 | // End of file FileSubmission.php |
182 | 182 | // Location: EventEspresso\core\services\request\files/FileSubmission.php |
@@ -16,39 +16,39 @@ |
||
16 | 16 | */ |
17 | 17 | class JsonWpOptionManager |
18 | 18 | { |
19 | - /** |
|
20 | - * Updates the object with what's in the DB (specifically, the wp_options table). If nothing is in the DB, leaves |
|
21 | - * the object alone and returns false. |
|
22 | - * @since 4.9.80.p |
|
23 | - * @param JsonWpOptionSerializableInterface $obj |
|
24 | - * @return bool |
|
25 | - */ |
|
26 | - public function populateFromDb(JsonWpOptionSerializableInterface $obj) |
|
27 | - { |
|
28 | - $option = get_option($obj->getWpOptionName()); |
|
29 | - if ($option) { |
|
30 | - $json = json_decode($option); |
|
31 | - if (is_array($json) || $json instanceof stdClass) { |
|
32 | - return $obj->fromJsonSerializedData($json); |
|
33 | - } |
|
34 | - } |
|
35 | - return false; |
|
36 | - } |
|
19 | + /** |
|
20 | + * Updates the object with what's in the DB (specifically, the wp_options table). If nothing is in the DB, leaves |
|
21 | + * the object alone and returns false. |
|
22 | + * @since 4.9.80.p |
|
23 | + * @param JsonWpOptionSerializableInterface $obj |
|
24 | + * @return bool |
|
25 | + */ |
|
26 | + public function populateFromDb(JsonWpOptionSerializableInterface $obj) |
|
27 | + { |
|
28 | + $option = get_option($obj->getWpOptionName()); |
|
29 | + if ($option) { |
|
30 | + $json = json_decode($option); |
|
31 | + if (is_array($json) || $json instanceof stdClass) { |
|
32 | + return $obj->fromJsonSerializedData($json); |
|
33 | + } |
|
34 | + } |
|
35 | + return false; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Saves the object's data to the wp_options table for later use. |
|
40 | - * @since 4.9.80.p |
|
41 | - * @param JsonWpOptionSerializableInterface $obj |
|
42 | - * @return bool |
|
43 | - */ |
|
44 | - public function saveToDb(JsonWpOptionSerializableInterface $obj) |
|
45 | - { |
|
46 | - return update_option( |
|
47 | - $obj->getWpOptionName(), |
|
48 | - wp_json_encode($obj->toJsonSerializableData()), |
|
49 | - false |
|
50 | - ); |
|
51 | - } |
|
38 | + /** |
|
39 | + * Saves the object's data to the wp_options table for later use. |
|
40 | + * @since 4.9.80.p |
|
41 | + * @param JsonWpOptionSerializableInterface $obj |
|
42 | + * @return bool |
|
43 | + */ |
|
44 | + public function saveToDb(JsonWpOptionSerializableInterface $obj) |
|
45 | + { |
|
46 | + return update_option( |
|
47 | + $obj->getWpOptionName(), |
|
48 | + wp_json_encode($obj->toJsonSerializableData()), |
|
49 | + false |
|
50 | + ); |
|
51 | + } |
|
52 | 52 | } |
53 | 53 | // End of file JsonWpOptionManager.php |
54 | 54 | // Location: EventEspresso\core\services\options/JsonWpOptionManager.php |
@@ -17,13 +17,13 @@ |
||
17 | 17 | */ |
18 | 18 | interface JsonWpOptionSerializableInterface extends JsonSerializableAndUnserializable |
19 | 19 | { |
20 | - /** |
|
21 | - * Gets the value to use for wp_options.option_name. Note this is not static, so it can use object properties to |
|
22 | - * determine what option name to use. |
|
23 | - * @since 4.9.80.p |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function getWpOptionName(); |
|
20 | + /** |
|
21 | + * Gets the value to use for wp_options.option_name. Note this is not static, so it can use object properties to |
|
22 | + * determine what option name to use. |
|
23 | + * @since 4.9.80.p |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function getWpOptionName(); |
|
27 | 27 | } |
28 | 28 | // End of file JsonWpOptionSerializableInterface.php |
29 | 29 | // Location: EventEspresso\core\services\options/JsonWpOptionSerializableInterface.php |
@@ -28,356 +28,356 @@ |
||
28 | 28 | class EED_Batch extends EED_Module |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
33 | - * processes data only |
|
34 | - */ |
|
35 | - const batch_job = 'job'; |
|
36 | - /** |
|
37 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
38 | - * produces a file for download |
|
39 | - */ |
|
40 | - const batch_file_job = 'file'; |
|
41 | - /** |
|
42 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT |
|
43 | - * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ] |
|
44 | - * at all |
|
45 | - */ |
|
46 | - const batch_not_job = 'none'; |
|
31 | + /** |
|
32 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
33 | + * processes data only |
|
34 | + */ |
|
35 | + const batch_job = 'job'; |
|
36 | + /** |
|
37 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
38 | + * produces a file for download |
|
39 | + */ |
|
40 | + const batch_file_job = 'file'; |
|
41 | + /** |
|
42 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT |
|
43 | + * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ] |
|
44 | + * at all |
|
45 | + */ |
|
46 | + const batch_not_job = 'none'; |
|
47 | 47 | |
48 | - /** |
|
49 | - * |
|
50 | - * @var string 'file', or 'job', or false to indicate its not a batch request at all |
|
51 | - */ |
|
52 | - protected $_batch_request_type = null; |
|
48 | + /** |
|
49 | + * |
|
50 | + * @var string 'file', or 'job', or false to indicate its not a batch request at all |
|
51 | + */ |
|
52 | + protected $_batch_request_type = null; |
|
53 | 53 | |
54 | - /** |
|
55 | - * Because we want to use the response in both the localized JS and in the body |
|
56 | - * we need to make this response available between method calls |
|
57 | - * |
|
58 | - * @var \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
59 | - */ |
|
60 | - protected $_job_step_response = null; |
|
54 | + /** |
|
55 | + * Because we want to use the response in both the localized JS and in the body |
|
56 | + * we need to make this response available between method calls |
|
57 | + * |
|
58 | + * @var \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
59 | + */ |
|
60 | + protected $_job_step_response = null; |
|
61 | 61 | |
62 | - /** |
|
63 | - * @var LoaderInterface |
|
64 | - */ |
|
65 | - protected $loader; |
|
62 | + /** |
|
63 | + * @var LoaderInterface |
|
64 | + */ |
|
65 | + protected $loader; |
|
66 | 66 | |
67 | - /** |
|
68 | - * Gets the batch instance |
|
69 | - * |
|
70 | - * @return EED_Batch |
|
71 | - */ |
|
72 | - public static function instance() |
|
73 | - { |
|
74 | - return self::get_instance(); |
|
75 | - } |
|
67 | + /** |
|
68 | + * Gets the batch instance |
|
69 | + * |
|
70 | + * @return EED_Batch |
|
71 | + */ |
|
72 | + public static function instance() |
|
73 | + { |
|
74 | + return self::get_instance(); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Sets hooks to enable batch jobs on the frontend. Disabled by default |
|
79 | - * because it's an attack vector and there are currently no implementations |
|
80 | - */ |
|
81 | - public static function set_hooks() |
|
82 | - { |
|
83 | - // because this is a possibel attack vector, let's have this disabled until |
|
84 | - // we at least have a real use for it on the frontend |
|
85 | - if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) { |
|
86 | - add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
87 | - add_filter('template_include', array(self::instance(), 'override_template'), 99); |
|
88 | - } |
|
89 | - } |
|
77 | + /** |
|
78 | + * Sets hooks to enable batch jobs on the frontend. Disabled by default |
|
79 | + * because it's an attack vector and there are currently no implementations |
|
80 | + */ |
|
81 | + public static function set_hooks() |
|
82 | + { |
|
83 | + // because this is a possibel attack vector, let's have this disabled until |
|
84 | + // we at least have a real use for it on the frontend |
|
85 | + if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) { |
|
86 | + add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
87 | + add_filter('template_include', array(self::instance(), 'override_template'), 99); |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Initializes some hooks for the admin in order to run batch jobs |
|
93 | - */ |
|
94 | - public static function set_hooks_admin() |
|
95 | - { |
|
96 | - add_action('admin_menu', array(self::instance(), 'register_admin_pages')); |
|
97 | - add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
91 | + /** |
|
92 | + * Initializes some hooks for the admin in order to run batch jobs |
|
93 | + */ |
|
94 | + public static function set_hooks_admin() |
|
95 | + { |
|
96 | + add_action('admin_menu', array(self::instance(), 'register_admin_pages')); |
|
97 | + add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
98 | 98 | |
99 | - // ajax |
|
100 | - add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
101 | - add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
102 | - add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
103 | - add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
104 | - } |
|
99 | + // ajax |
|
100 | + add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
101 | + add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
102 | + add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
103 | + add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * @since 4.9.80.p |
|
108 | - * @return LoaderInterface |
|
109 | - * @throws InvalidArgumentException |
|
110 | - * @throws InvalidDataTypeException |
|
111 | - * @throws InvalidInterfaceException |
|
112 | - */ |
|
113 | - protected function getLoader() |
|
114 | - { |
|
115 | - if (!$this->loader instanceof LoaderInterface) { |
|
116 | - $this->loader = LoaderFactory::getLoader(); |
|
117 | - } |
|
118 | - return $this->loader; |
|
119 | - } |
|
106 | + /** |
|
107 | + * @since 4.9.80.p |
|
108 | + * @return LoaderInterface |
|
109 | + * @throws InvalidArgumentException |
|
110 | + * @throws InvalidDataTypeException |
|
111 | + * @throws InvalidInterfaceException |
|
112 | + */ |
|
113 | + protected function getLoader() |
|
114 | + { |
|
115 | + if (!$this->loader instanceof LoaderInterface) { |
|
116 | + $this->loader = LoaderFactory::getLoader(); |
|
117 | + } |
|
118 | + return $this->loader; |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * Enqueues batch scripts on the frontend or admin, and creates a job |
|
123 | - */ |
|
124 | - public function enqueue_scripts() |
|
125 | - { |
|
126 | - if (isset($_REQUEST['espresso_batch']) |
|
127 | - || |
|
128 | - ( |
|
129 | - isset($_REQUEST['page']) |
|
130 | - && $_REQUEST['page'] == 'espresso_batch' |
|
131 | - ) |
|
132 | - ) { |
|
133 | - switch ($this->batch_request_type()) { |
|
134 | - case self::batch_job: |
|
135 | - $this->enqueue_scripts_styles_batch_create(); |
|
136 | - break; |
|
137 | - case self::batch_file_job: |
|
138 | - $this->enqueue_scripts_styles_batch_file_create(); |
|
139 | - break; |
|
140 | - } |
|
141 | - } |
|
142 | - } |
|
121 | + /** |
|
122 | + * Enqueues batch scripts on the frontend or admin, and creates a job |
|
123 | + */ |
|
124 | + public function enqueue_scripts() |
|
125 | + { |
|
126 | + if (isset($_REQUEST['espresso_batch']) |
|
127 | + || |
|
128 | + ( |
|
129 | + isset($_REQUEST['page']) |
|
130 | + && $_REQUEST['page'] == 'espresso_batch' |
|
131 | + ) |
|
132 | + ) { |
|
133 | + switch ($this->batch_request_type()) { |
|
134 | + case self::batch_job: |
|
135 | + $this->enqueue_scripts_styles_batch_create(); |
|
136 | + break; |
|
137 | + case self::batch_file_job: |
|
138 | + $this->enqueue_scripts_styles_batch_file_create(); |
|
139 | + break; |
|
140 | + } |
|
141 | + } |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * Create a batch job, enqueues a script to run it, and localizes some data for it |
|
146 | - */ |
|
147 | - public function enqueue_scripts_styles_batch_create() |
|
148 | - { |
|
149 | - $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
150 | - wp_enqueue_script( |
|
151 | - 'batch_runner_init', |
|
152 | - BATCH_URL . 'assets/batch_runner_init.js', |
|
153 | - array('batch_runner'), |
|
154 | - EVENT_ESPRESSO_VERSION, |
|
155 | - true |
|
156 | - ); |
|
157 | - wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array()); |
|
158 | - wp_localize_script( |
|
159 | - 'batch_runner_init', |
|
160 | - 'ee_job_i18n', |
|
161 | - array( |
|
162 | - 'return_url' => $_REQUEST['return_url'], |
|
163 | - ) |
|
164 | - ); |
|
165 | - } |
|
144 | + /** |
|
145 | + * Create a batch job, enqueues a script to run it, and localizes some data for it |
|
146 | + */ |
|
147 | + public function enqueue_scripts_styles_batch_create() |
|
148 | + { |
|
149 | + $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
150 | + wp_enqueue_script( |
|
151 | + 'batch_runner_init', |
|
152 | + BATCH_URL . 'assets/batch_runner_init.js', |
|
153 | + array('batch_runner'), |
|
154 | + EVENT_ESPRESSO_VERSION, |
|
155 | + true |
|
156 | + ); |
|
157 | + wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array()); |
|
158 | + wp_localize_script( |
|
159 | + 'batch_runner_init', |
|
160 | + 'ee_job_i18n', |
|
161 | + array( |
|
162 | + 'return_url' => $_REQUEST['return_url'], |
|
163 | + ) |
|
164 | + ); |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it |
|
169 | - */ |
|
170 | - public function enqueue_scripts_styles_batch_file_create() |
|
171 | - { |
|
172 | - // creates a job based on the request variable |
|
173 | - $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
174 | - wp_enqueue_script( |
|
175 | - 'batch_file_runner_init', |
|
176 | - BATCH_URL . 'assets/batch_file_runner_init.js', |
|
177 | - array('batch_runner'), |
|
178 | - EVENT_ESPRESSO_VERSION, |
|
179 | - true |
|
180 | - ); |
|
181 | - wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array()); |
|
182 | - wp_localize_script( |
|
183 | - 'batch_file_runner_init', |
|
184 | - 'ee_job_i18n', |
|
185 | - array( |
|
186 | - 'download_and_redirecting' => sprintf( |
|
187 | - __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
|
188 | - '<a href="' . $_REQUEST['return_url'] . '">', |
|
189 | - '</a>' |
|
190 | - ), |
|
191 | - 'return_url' => $_REQUEST['return_url'], |
|
192 | - ) |
|
193 | - ); |
|
194 | - } |
|
167 | + /** |
|
168 | + * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it |
|
169 | + */ |
|
170 | + public function enqueue_scripts_styles_batch_file_create() |
|
171 | + { |
|
172 | + // creates a job based on the request variable |
|
173 | + $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
174 | + wp_enqueue_script( |
|
175 | + 'batch_file_runner_init', |
|
176 | + BATCH_URL . 'assets/batch_file_runner_init.js', |
|
177 | + array('batch_runner'), |
|
178 | + EVENT_ESPRESSO_VERSION, |
|
179 | + true |
|
180 | + ); |
|
181 | + wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array()); |
|
182 | + wp_localize_script( |
|
183 | + 'batch_file_runner_init', |
|
184 | + 'ee_job_i18n', |
|
185 | + array( |
|
186 | + 'download_and_redirecting' => sprintf( |
|
187 | + __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
|
188 | + '<a href="' . $_REQUEST['return_url'] . '">', |
|
189 | + '</a>' |
|
190 | + ), |
|
191 | + 'return_url' => $_REQUEST['return_url'], |
|
192 | + ) |
|
193 | + ); |
|
194 | + } |
|
195 | 195 | |
196 | - /** |
|
197 | - * Enqueues scripts and styles common to any batch job, and creates |
|
198 | - * a job from the request data, and stores the response in the |
|
199 | - * $this->_job_step_response property |
|
200 | - * |
|
201 | - * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
202 | - */ |
|
203 | - protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
|
204 | - { |
|
205 | - wp_register_script( |
|
206 | - 'progress_bar', |
|
207 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
208 | - array('jquery') |
|
209 | - ); |
|
210 | - wp_enqueue_style( |
|
211 | - 'progress_bar', |
|
212 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
213 | - array(), |
|
214 | - EVENT_ESPRESSO_VERSION |
|
215 | - ); |
|
216 | - wp_enqueue_script( |
|
217 | - 'batch_runner', |
|
218 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
219 | - array('progress_bar') |
|
220 | - ); |
|
221 | - // just copy the bits of EE admin's eei18n that we need in the JS |
|
222 | - wp_localize_script( |
|
223 | - 'batch_runner', |
|
224 | - 'eei18n', |
|
225 | - array( |
|
226 | - 'ajax_url' => WP_AJAX_URL, |
|
227 | - 'is_admin' => (bool) is_admin(), |
|
228 | - 'error_message' => esc_html__('An error occurred and the job has been stopped. Please refresh the page to try again.', 'event_espresso'), |
|
229 | - ) |
|
230 | - ); |
|
231 | - $job_handler_classname = stripslashes($_GET['job_handler']); |
|
232 | - $request_data = array_diff_key( |
|
233 | - $_REQUEST, |
|
234 | - array_flip(array('action', 'page', 'ee', 'batch')) |
|
235 | - ); |
|
236 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
237 | - // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' |
|
238 | - $job_response = $batch_runner->create_job($job_handler_classname, $request_data); |
|
239 | - // remember the response for later. We need it to display the page body |
|
240 | - $this->_job_step_response = $job_response; |
|
241 | - return $job_response; |
|
242 | - } |
|
196 | + /** |
|
197 | + * Enqueues scripts and styles common to any batch job, and creates |
|
198 | + * a job from the request data, and stores the response in the |
|
199 | + * $this->_job_step_response property |
|
200 | + * |
|
201 | + * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
202 | + */ |
|
203 | + protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
|
204 | + { |
|
205 | + wp_register_script( |
|
206 | + 'progress_bar', |
|
207 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
208 | + array('jquery') |
|
209 | + ); |
|
210 | + wp_enqueue_style( |
|
211 | + 'progress_bar', |
|
212 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
213 | + array(), |
|
214 | + EVENT_ESPRESSO_VERSION |
|
215 | + ); |
|
216 | + wp_enqueue_script( |
|
217 | + 'batch_runner', |
|
218 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
219 | + array('progress_bar') |
|
220 | + ); |
|
221 | + // just copy the bits of EE admin's eei18n that we need in the JS |
|
222 | + wp_localize_script( |
|
223 | + 'batch_runner', |
|
224 | + 'eei18n', |
|
225 | + array( |
|
226 | + 'ajax_url' => WP_AJAX_URL, |
|
227 | + 'is_admin' => (bool) is_admin(), |
|
228 | + 'error_message' => esc_html__('An error occurred and the job has been stopped. Please refresh the page to try again.', 'event_espresso'), |
|
229 | + ) |
|
230 | + ); |
|
231 | + $job_handler_classname = stripslashes($_GET['job_handler']); |
|
232 | + $request_data = array_diff_key( |
|
233 | + $_REQUEST, |
|
234 | + array_flip(array('action', 'page', 'ee', 'batch')) |
|
235 | + ); |
|
236 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
237 | + // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' |
|
238 | + $job_response = $batch_runner->create_job($job_handler_classname, $request_data); |
|
239 | + // remember the response for later. We need it to display the page body |
|
240 | + $this->_job_step_response = $job_response; |
|
241 | + return $job_response; |
|
242 | + } |
|
243 | 243 | |
244 | - /** |
|
245 | - * If we are doing a frontend batch job, this makes it so WP shows our template's HTML |
|
246 | - * |
|
247 | - * @param string $template |
|
248 | - * @return string |
|
249 | - */ |
|
250 | - public function override_template($template) |
|
251 | - { |
|
252 | - if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
|
253 | - return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html'; |
|
254 | - } |
|
255 | - return $template; |
|
256 | - } |
|
244 | + /** |
|
245 | + * If we are doing a frontend batch job, this makes it so WP shows our template's HTML |
|
246 | + * |
|
247 | + * @param string $template |
|
248 | + * @return string |
|
249 | + */ |
|
250 | + public function override_template($template) |
|
251 | + { |
|
252 | + if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
|
253 | + return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html'; |
|
254 | + } |
|
255 | + return $template; |
|
256 | + } |
|
257 | 257 | |
258 | - /** |
|
259 | - * Adds an admin page which doesn't appear in the admin menu |
|
260 | - */ |
|
261 | - public function register_admin_pages() |
|
262 | - { |
|
263 | - add_submenu_page( |
|
264 | - '', // parent slug. we don't want this to actually appear in the menu |
|
265 | - __('Batch Job', 'event_espresso'), // page title |
|
266 | - 'n/a', // menu title |
|
267 | - 'read', // we want this page to actually be accessible to anyone, |
|
268 | - 'espresso_batch', // menu slug |
|
269 | - array(self::instance(), 'show_admin_page') |
|
270 | - ); |
|
271 | - } |
|
258 | + /** |
|
259 | + * Adds an admin page which doesn't appear in the admin menu |
|
260 | + */ |
|
261 | + public function register_admin_pages() |
|
262 | + { |
|
263 | + add_submenu_page( |
|
264 | + '', // parent slug. we don't want this to actually appear in the menu |
|
265 | + __('Batch Job', 'event_espresso'), // page title |
|
266 | + 'n/a', // menu title |
|
267 | + 'read', // we want this page to actually be accessible to anyone, |
|
268 | + 'espresso_batch', // menu slug |
|
269 | + array(self::instance(), 'show_admin_page') |
|
270 | + ); |
|
271 | + } |
|
272 | 272 | |
273 | - /** |
|
274 | - * Renders the admin page, after most of the work was already done during enqueuing scripts |
|
275 | - * of creating the job and localizing some data |
|
276 | - */ |
|
277 | - public function show_admin_page() |
|
278 | - { |
|
279 | - echo EEH_Template::locate_template( |
|
280 | - EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', |
|
281 | - array('batch_request_type' => $this->batch_request_type()) |
|
282 | - ); |
|
283 | - } |
|
273 | + /** |
|
274 | + * Renders the admin page, after most of the work was already done during enqueuing scripts |
|
275 | + * of creating the job and localizing some data |
|
276 | + */ |
|
277 | + public function show_admin_page() |
|
278 | + { |
|
279 | + echo EEH_Template::locate_template( |
|
280 | + EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', |
|
281 | + array('batch_request_type' => $this->batch_request_type()) |
|
282 | + ); |
|
283 | + } |
|
284 | 284 | |
285 | - /** |
|
286 | - * Receives ajax calls for continuing a job |
|
287 | - */ |
|
288 | - public function batch_continue() |
|
289 | - { |
|
290 | - $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
291 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
292 | - $response_obj = $batch_runner->continue_job($job_id); |
|
293 | - $this->_return_json($response_obj->to_array()); |
|
294 | - } |
|
285 | + /** |
|
286 | + * Receives ajax calls for continuing a job |
|
287 | + */ |
|
288 | + public function batch_continue() |
|
289 | + { |
|
290 | + $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
291 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
292 | + $response_obj = $batch_runner->continue_job($job_id); |
|
293 | + $this->_return_json($response_obj->to_array()); |
|
294 | + } |
|
295 | 295 | |
296 | - /** |
|
297 | - * Receives the ajax call to cleanup a job |
|
298 | - * |
|
299 | - * @return type |
|
300 | - */ |
|
301 | - public function batch_cleanup() |
|
302 | - { |
|
303 | - $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
304 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
305 | - $response_obj = $batch_runner->cleanup_job($job_id); |
|
306 | - $this->_return_json($response_obj->to_array()); |
|
307 | - } |
|
296 | + /** |
|
297 | + * Receives the ajax call to cleanup a job |
|
298 | + * |
|
299 | + * @return type |
|
300 | + */ |
|
301 | + public function batch_cleanup() |
|
302 | + { |
|
303 | + $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
304 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
305 | + $response_obj = $batch_runner->cleanup_job($job_id); |
|
306 | + $this->_return_json($response_obj->to_array()); |
|
307 | + } |
|
308 | 308 | |
309 | 309 | |
310 | - /** |
|
311 | - * Returns a json response |
|
312 | - * |
|
313 | - * @param array $data The data we want to send echo via in the JSON response's "data" element |
|
314 | - * |
|
315 | - * The returned json object is created from an array in the following format: |
|
316 | - * array( |
|
317 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
318 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
319 | - * We're also going to include the template args with every package (so js can pick out any specific template |
|
320 | - * args that might be included in here) |
|
321 | - * 'isEEajax' => true,//indicates this is a response from EE |
|
322 | - * ) |
|
323 | - */ |
|
324 | - protected function _return_json($data) |
|
325 | - { |
|
326 | - $json = array( |
|
327 | - 'notices' => EE_Error::get_notices(), |
|
328 | - 'data' => $data, |
|
329 | - 'isEEajax' => true |
|
330 | - // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
331 | - ); |
|
310 | + /** |
|
311 | + * Returns a json response |
|
312 | + * |
|
313 | + * @param array $data The data we want to send echo via in the JSON response's "data" element |
|
314 | + * |
|
315 | + * The returned json object is created from an array in the following format: |
|
316 | + * array( |
|
317 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
318 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
319 | + * We're also going to include the template args with every package (so js can pick out any specific template |
|
320 | + * args that might be included in here) |
|
321 | + * 'isEEajax' => true,//indicates this is a response from EE |
|
322 | + * ) |
|
323 | + */ |
|
324 | + protected function _return_json($data) |
|
325 | + { |
|
326 | + $json = array( |
|
327 | + 'notices' => EE_Error::get_notices(), |
|
328 | + 'data' => $data, |
|
329 | + 'isEEajax' => true |
|
330 | + // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
331 | + ); |
|
332 | 332 | |
333 | 333 | |
334 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
335 | - if (null === error_get_last() || ! headers_sent()) { |
|
336 | - header('Content-Type: application/json; charset=UTF-8'); |
|
337 | - } |
|
338 | - echo wp_json_encode($json); |
|
339 | - exit(); |
|
340 | - } |
|
334 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
335 | + if (null === error_get_last() || ! headers_sent()) { |
|
336 | + header('Content-Type: application/json; charset=UTF-8'); |
|
337 | + } |
|
338 | + echo wp_json_encode($json); |
|
339 | + exit(); |
|
340 | + } |
|
341 | 341 | |
342 | - /** |
|
343 | - * Gets the job step response which was done during the enqueuing of scripts |
|
344 | - * |
|
345 | - * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
346 | - */ |
|
347 | - public function job_step_response() |
|
348 | - { |
|
349 | - return $this->_job_step_response; |
|
350 | - } |
|
342 | + /** |
|
343 | + * Gets the job step response which was done during the enqueuing of scripts |
|
344 | + * |
|
345 | + * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
346 | + */ |
|
347 | + public function job_step_response() |
|
348 | + { |
|
349 | + return $this->_job_step_response; |
|
350 | + } |
|
351 | 351 | |
352 | - /** |
|
353 | - * Gets the batch request type indicated in the $_REQUEST |
|
354 | - * |
|
355 | - * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job |
|
356 | - */ |
|
357 | - public function batch_request_type() |
|
358 | - { |
|
359 | - if ($this->_batch_request_type === null) { |
|
360 | - if (isset($_GET['batch'])) { |
|
361 | - if ($_GET['batch'] == self::batch_job) { |
|
362 | - $this->_batch_request_type = self::batch_job; |
|
363 | - } elseif ($_GET['batch'] == self::batch_file_job) { |
|
364 | - $this->_batch_request_type = self::batch_file_job; |
|
365 | - } |
|
366 | - } |
|
367 | - // if we didn't find that it was a batch request, indicate it wasn't |
|
368 | - if ($this->_batch_request_type === null) { |
|
369 | - $this->_batch_request_type = self::batch_not_job; |
|
370 | - } |
|
371 | - } |
|
372 | - return $this->_batch_request_type; |
|
373 | - } |
|
352 | + /** |
|
353 | + * Gets the batch request type indicated in the $_REQUEST |
|
354 | + * |
|
355 | + * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job |
|
356 | + */ |
|
357 | + public function batch_request_type() |
|
358 | + { |
|
359 | + if ($this->_batch_request_type === null) { |
|
360 | + if (isset($_GET['batch'])) { |
|
361 | + if ($_GET['batch'] == self::batch_job) { |
|
362 | + $this->_batch_request_type = self::batch_job; |
|
363 | + } elseif ($_GET['batch'] == self::batch_file_job) { |
|
364 | + $this->_batch_request_type = self::batch_file_job; |
|
365 | + } |
|
366 | + } |
|
367 | + // if we didn't find that it was a batch request, indicate it wasn't |
|
368 | + if ($this->_batch_request_type === null) { |
|
369 | + $this->_batch_request_type = self::batch_not_job; |
|
370 | + } |
|
371 | + } |
|
372 | + return $this->_batch_request_type; |
|
373 | + } |
|
374 | 374 | |
375 | - /** |
|
376 | - * Unnecessary |
|
377 | - * |
|
378 | - * @param type $WP |
|
379 | - */ |
|
380 | - public function run($WP) |
|
381 | - { |
|
382 | - } |
|
375 | + /** |
|
376 | + * Unnecessary |
|
377 | + * |
|
378 | + * @param type $WP |
|
379 | + */ |
|
380 | + public function run($WP) |
|
381 | + { |
|
382 | + } |
|
383 | 383 | } |
@@ -31,530 +31,530 @@ |
||
31 | 31 | */ |
32 | 32 | class RegistrationsReport extends JobHandlerFile |
33 | 33 | { |
34 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
35 | - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
36 | - /** |
|
37 | - * Performs any necessary setup for starting the job. This is also a good |
|
38 | - * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
39 | - * when continue_job will be called |
|
40 | - * |
|
41 | - * @param JobParameters $job_parameters |
|
42 | - * @throws BatchRequestException |
|
43 | - * @return JobStepResponse |
|
44 | - */ |
|
45 | - public function create_job(JobParameters $job_parameters) |
|
46 | - { |
|
47 | - $event_id = intval($job_parameters->request_datum('EVT_ID', '0')); |
|
48 | - if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
49 | - throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso')); |
|
50 | - } |
|
51 | - $filepath = $this->create_file_from_job_with_name( |
|
52 | - $job_parameters->job_id(), |
|
53 | - $this->get_filename($event_id) |
|
54 | - ); |
|
55 | - $job_parameters->add_extra_data('filepath', $filepath); |
|
56 | - if ($job_parameters->request_datum('use_filters', false)) { |
|
57 | - $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array()))); |
|
58 | - } else { |
|
59 | - $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array( |
|
60 | - array( |
|
61 | - 'OR' => array( |
|
62 | - // don't include registrations from failed or abandoned transactions... |
|
63 | - 'Transaction.STS_ID' => array( |
|
64 | - 'NOT IN', |
|
65 | - array( |
|
66 | - EEM_Transaction::failed_status_code, |
|
67 | - EEM_Transaction::abandoned_status_code, |
|
68 | - ), |
|
69 | - ), |
|
70 | - // unless the registration is approved, in which case include it regardless of transaction status |
|
71 | - 'STS_ID' => \EEM_Registration::status_id_approved, |
|
72 | - ), |
|
73 | - 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
74 | - ), |
|
75 | - 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
76 | - 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
77 | - 'caps' => \EEM_Base::caps_read_admin, |
|
78 | - ), $event_id); |
|
79 | - if ($event_id) { |
|
80 | - $query_params[0]['EVT_ID'] = $event_id; |
|
81 | - } else { |
|
82 | - $query_params['force_join'][] = 'Event'; |
|
83 | - } |
|
84 | - } |
|
85 | - if (! isset($query_params['force_join'])) { |
|
86 | - $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
|
87 | - } |
|
88 | - $job_parameters->add_extra_data('query_params', $query_params); |
|
89 | - $question_labels = $this->_get_question_labels($query_params); |
|
90 | - $job_parameters->add_extra_data('question_labels', $question_labels); |
|
91 | - $job_parameters->set_job_size( |
|
92 | - \EEM_Registration::instance()->count( |
|
93 | - array_diff_key( |
|
94 | - $query_params, |
|
95 | - array_flip( |
|
96 | - array('limit') |
|
97 | - ) |
|
98 | - ) |
|
99 | - ) |
|
100 | - ); |
|
101 | - // we should also set the header columns |
|
102 | - $csv_data_for_row = $this->get_csv_data_for( |
|
103 | - $event_id, |
|
104 | - 0, |
|
105 | - 1, |
|
106 | - $job_parameters->extra_datum('question_labels'), |
|
107 | - $job_parameters->extra_datum('query_params') |
|
108 | - ); |
|
109 | - EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
110 | - // if we actually processed a row there, record it |
|
111 | - if ($job_parameters->job_size()) { |
|
112 | - $job_parameters->mark_processed(1); |
|
113 | - } |
|
114 | - return new JobStepResponse( |
|
115 | - $job_parameters, |
|
116 | - __('Registrations report started successfully...', 'event_espresso') |
|
117 | - ); |
|
118 | - } |
|
34 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
35 | + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
36 | + /** |
|
37 | + * Performs any necessary setup for starting the job. This is also a good |
|
38 | + * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
39 | + * when continue_job will be called |
|
40 | + * |
|
41 | + * @param JobParameters $job_parameters |
|
42 | + * @throws BatchRequestException |
|
43 | + * @return JobStepResponse |
|
44 | + */ |
|
45 | + public function create_job(JobParameters $job_parameters) |
|
46 | + { |
|
47 | + $event_id = intval($job_parameters->request_datum('EVT_ID', '0')); |
|
48 | + if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
49 | + throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso')); |
|
50 | + } |
|
51 | + $filepath = $this->create_file_from_job_with_name( |
|
52 | + $job_parameters->job_id(), |
|
53 | + $this->get_filename($event_id) |
|
54 | + ); |
|
55 | + $job_parameters->add_extra_data('filepath', $filepath); |
|
56 | + if ($job_parameters->request_datum('use_filters', false)) { |
|
57 | + $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array()))); |
|
58 | + } else { |
|
59 | + $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array( |
|
60 | + array( |
|
61 | + 'OR' => array( |
|
62 | + // don't include registrations from failed or abandoned transactions... |
|
63 | + 'Transaction.STS_ID' => array( |
|
64 | + 'NOT IN', |
|
65 | + array( |
|
66 | + EEM_Transaction::failed_status_code, |
|
67 | + EEM_Transaction::abandoned_status_code, |
|
68 | + ), |
|
69 | + ), |
|
70 | + // unless the registration is approved, in which case include it regardless of transaction status |
|
71 | + 'STS_ID' => \EEM_Registration::status_id_approved, |
|
72 | + ), |
|
73 | + 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
74 | + ), |
|
75 | + 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
76 | + 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
77 | + 'caps' => \EEM_Base::caps_read_admin, |
|
78 | + ), $event_id); |
|
79 | + if ($event_id) { |
|
80 | + $query_params[0]['EVT_ID'] = $event_id; |
|
81 | + } else { |
|
82 | + $query_params['force_join'][] = 'Event'; |
|
83 | + } |
|
84 | + } |
|
85 | + if (! isset($query_params['force_join'])) { |
|
86 | + $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
|
87 | + } |
|
88 | + $job_parameters->add_extra_data('query_params', $query_params); |
|
89 | + $question_labels = $this->_get_question_labels($query_params); |
|
90 | + $job_parameters->add_extra_data('question_labels', $question_labels); |
|
91 | + $job_parameters->set_job_size( |
|
92 | + \EEM_Registration::instance()->count( |
|
93 | + array_diff_key( |
|
94 | + $query_params, |
|
95 | + array_flip( |
|
96 | + array('limit') |
|
97 | + ) |
|
98 | + ) |
|
99 | + ) |
|
100 | + ); |
|
101 | + // we should also set the header columns |
|
102 | + $csv_data_for_row = $this->get_csv_data_for( |
|
103 | + $event_id, |
|
104 | + 0, |
|
105 | + 1, |
|
106 | + $job_parameters->extra_datum('question_labels'), |
|
107 | + $job_parameters->extra_datum('query_params') |
|
108 | + ); |
|
109 | + EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
110 | + // if we actually processed a row there, record it |
|
111 | + if ($job_parameters->job_size()) { |
|
112 | + $job_parameters->mark_processed(1); |
|
113 | + } |
|
114 | + return new JobStepResponse( |
|
115 | + $job_parameters, |
|
116 | + __('Registrations report started successfully...', 'event_espresso') |
|
117 | + ); |
|
118 | + } |
|
119 | 119 | |
120 | 120 | |
121 | - /** |
|
122 | - * Gets the filename |
|
123 | - * |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - protected function get_filename() |
|
127 | - { |
|
128 | - return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql'))); |
|
129 | - } |
|
121 | + /** |
|
122 | + * Gets the filename |
|
123 | + * |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + protected function get_filename() |
|
127 | + { |
|
128 | + return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql'))); |
|
129 | + } |
|
130 | 130 | |
131 | 131 | |
132 | - /** |
|
133 | - * Gets the questions which are to be used for this report, so they |
|
134 | - * can be remembered for later |
|
135 | - * |
|
136 | - * @param array $registration_query_params |
|
137 | - * @return array question admin labels to be used for this report |
|
138 | - */ |
|
139 | - protected function _get_question_labels($registration_query_params) |
|
140 | - { |
|
141 | - $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null; |
|
142 | - $question_query_params = array(); |
|
143 | - if ($where !== null) { |
|
144 | - $question_query_params = array( |
|
145 | - $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
146 | - ); |
|
147 | - } |
|
148 | - // Make sure it's not a system question |
|
149 | - $question_query_params[0]['OR*not-system-questions'] = [ |
|
150 | - 'QST_system' => '', |
|
151 | - 'QST_system*null' => ['IS_NULL'] |
|
152 | - ]; |
|
153 | - if (apply_filters( |
|
154 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', |
|
155 | - false, |
|
156 | - $registration_query_params |
|
157 | - )) { |
|
158 | - $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL'); |
|
159 | - } |
|
160 | - $question_query_params['group_by'] = array('QST_ID'); |
|
161 | - return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label')); |
|
162 | - } |
|
132 | + /** |
|
133 | + * Gets the questions which are to be used for this report, so they |
|
134 | + * can be remembered for later |
|
135 | + * |
|
136 | + * @param array $registration_query_params |
|
137 | + * @return array question admin labels to be used for this report |
|
138 | + */ |
|
139 | + protected function _get_question_labels($registration_query_params) |
|
140 | + { |
|
141 | + $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null; |
|
142 | + $question_query_params = array(); |
|
143 | + if ($where !== null) { |
|
144 | + $question_query_params = array( |
|
145 | + $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
146 | + ); |
|
147 | + } |
|
148 | + // Make sure it's not a system question |
|
149 | + $question_query_params[0]['OR*not-system-questions'] = [ |
|
150 | + 'QST_system' => '', |
|
151 | + 'QST_system*null' => ['IS_NULL'] |
|
152 | + ]; |
|
153 | + if (apply_filters( |
|
154 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', |
|
155 | + false, |
|
156 | + $registration_query_params |
|
157 | + )) { |
|
158 | + $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL'); |
|
159 | + } |
|
160 | + $question_query_params['group_by'] = array('QST_ID'); |
|
161 | + return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label')); |
|
162 | + } |
|
163 | 163 | |
164 | 164 | |
165 | - /** |
|
166 | - * Takes where params meant for registrations and changes them to work for questions |
|
167 | - * |
|
168 | - * @param array $reg_where_params |
|
169 | - * @return array |
|
170 | - */ |
|
171 | - protected function _change_registration_where_params_to_question_where_params($reg_where_params) |
|
172 | - { |
|
173 | - $question_where_params = array(); |
|
174 | - foreach ($reg_where_params as $key => $val) { |
|
175 | - if (\EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
176 | - $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val); |
|
177 | - } else { |
|
178 | - // it's a normal where condition |
|
179 | - $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
180 | - } |
|
181 | - } |
|
182 | - return $question_where_params; |
|
183 | - } |
|
165 | + /** |
|
166 | + * Takes where params meant for registrations and changes them to work for questions |
|
167 | + * |
|
168 | + * @param array $reg_where_params |
|
169 | + * @return array |
|
170 | + */ |
|
171 | + protected function _change_registration_where_params_to_question_where_params($reg_where_params) |
|
172 | + { |
|
173 | + $question_where_params = array(); |
|
174 | + foreach ($reg_where_params as $key => $val) { |
|
175 | + if (\EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
176 | + $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val); |
|
177 | + } else { |
|
178 | + // it's a normal where condition |
|
179 | + $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
180 | + } |
|
181 | + } |
|
182 | + return $question_where_params; |
|
183 | + } |
|
184 | 184 | |
185 | 185 | |
186 | - /** |
|
187 | - * Performs another step of the job |
|
188 | - * |
|
189 | - * @param JobParameters $job_parameters |
|
190 | - * @param int $batch_size |
|
191 | - * @return JobStepResponse |
|
192 | - * @throws \EE_Error |
|
193 | - */ |
|
194 | - public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
195 | - { |
|
196 | - if ($job_parameters->units_processed() < $job_parameters->job_size()) { |
|
197 | - $csv_data = $this->get_csv_data_for( |
|
198 | - $job_parameters->request_datum('EVT_ID', '0'), |
|
199 | - $job_parameters->units_processed(), |
|
200 | - $batch_size, |
|
201 | - $job_parameters->extra_datum('question_labels'), |
|
202 | - $job_parameters->extra_datum('query_params') |
|
203 | - ); |
|
204 | - EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
|
205 | - $units_processed = count($csv_data); |
|
206 | - } else { |
|
207 | - $csv_data = array(); |
|
208 | - $units_processed = 0; |
|
209 | - } |
|
210 | - $job_parameters->mark_processed($units_processed); |
|
211 | - $extra_response_data = array( |
|
212 | - 'file_url' => '', |
|
213 | - ); |
|
214 | - if ($units_processed < $batch_size) { |
|
215 | - $job_parameters->set_status(JobParameters::status_complete); |
|
216 | - $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
217 | - } |
|
186 | + /** |
|
187 | + * Performs another step of the job |
|
188 | + * |
|
189 | + * @param JobParameters $job_parameters |
|
190 | + * @param int $batch_size |
|
191 | + * @return JobStepResponse |
|
192 | + * @throws \EE_Error |
|
193 | + */ |
|
194 | + public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
195 | + { |
|
196 | + if ($job_parameters->units_processed() < $job_parameters->job_size()) { |
|
197 | + $csv_data = $this->get_csv_data_for( |
|
198 | + $job_parameters->request_datum('EVT_ID', '0'), |
|
199 | + $job_parameters->units_processed(), |
|
200 | + $batch_size, |
|
201 | + $job_parameters->extra_datum('question_labels'), |
|
202 | + $job_parameters->extra_datum('query_params') |
|
203 | + ); |
|
204 | + EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
|
205 | + $units_processed = count($csv_data); |
|
206 | + } else { |
|
207 | + $csv_data = array(); |
|
208 | + $units_processed = 0; |
|
209 | + } |
|
210 | + $job_parameters->mark_processed($units_processed); |
|
211 | + $extra_response_data = array( |
|
212 | + 'file_url' => '', |
|
213 | + ); |
|
214 | + if ($units_processed < $batch_size) { |
|
215 | + $job_parameters->set_status(JobParameters::status_complete); |
|
216 | + $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
217 | + } |
|
218 | 218 | |
219 | - return new JobStepResponse( |
|
220 | - $job_parameters, |
|
221 | - sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)), |
|
222 | - $extra_response_data |
|
223 | - ); |
|
224 | - } |
|
219 | + return new JobStepResponse( |
|
220 | + $job_parameters, |
|
221 | + sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)), |
|
222 | + $extra_response_data |
|
223 | + ); |
|
224 | + } |
|
225 | 225 | |
226 | 226 | |
227 | - /** |
|
228 | - * Gets the csv data for a batch of registrations |
|
229 | - * |
|
230 | - * @param int|null $event_id |
|
231 | - * @param int $offset |
|
232 | - * @param int $limit |
|
233 | - * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
234 | - * @param array $query_params for using where querying the model |
|
235 | - * @return array top-level keys are numeric, next-level keys are column headers |
|
236 | - * @throws \EE_Error |
|
237 | - */ |
|
238 | - public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params) |
|
239 | - { |
|
240 | - $reg_fields_to_include = array( |
|
241 | - 'TXN_ID', |
|
242 | - 'ATT_ID', |
|
243 | - 'REG_ID', |
|
244 | - 'REG_date', |
|
245 | - 'REG_code', |
|
246 | - 'REG_count', |
|
247 | - 'REG_final_price', |
|
248 | - ); |
|
249 | - $att_fields_to_include = array( |
|
250 | - 'ATT_fname', |
|
251 | - 'ATT_lname', |
|
252 | - 'ATT_email', |
|
253 | - 'ATT_address', |
|
254 | - 'ATT_address2', |
|
255 | - 'ATT_city', |
|
256 | - 'STA_ID', |
|
257 | - 'CNT_ISO', |
|
258 | - 'ATT_zip', |
|
259 | - 'ATT_phone', |
|
260 | - ); |
|
261 | - $registrations_csv_ready_array = array(); |
|
262 | - $reg_model = EE_Registry::instance()->load_model('Registration'); |
|
263 | - $query_params['limit'] = array($offset, $limit); |
|
264 | - $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
265 | - $registration_ids = array(); |
|
266 | - foreach ($registration_rows as $reg_row) { |
|
267 | - $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
268 | - } |
|
269 | - foreach ($registration_rows as $reg_row) { |
|
270 | - if (is_array($reg_row)) { |
|
271 | - $reg_csv_array = array(); |
|
272 | - if (! $event_id) { |
|
273 | - // get the event's name and Id |
|
274 | - $reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf( |
|
275 | - /* translators: 1: event name, 2: event ID */ |
|
276 | - __('%1$s (%2$s)', 'event_espresso'), |
|
277 | - EEH_Export::prepare_value_from_db_for_display( |
|
278 | - EEM_Event::instance(), |
|
279 | - 'EVT_name', |
|
280 | - $reg_row['Event_CPT.post_title'] |
|
281 | - ), |
|
282 | - $reg_row['Event_CPT.ID'] |
|
283 | - ); |
|
284 | - } |
|
285 | - $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
286 | - /*@var $reg_row EE_Registration */ |
|
287 | - foreach ($reg_fields_to_include as $field_name) { |
|
288 | - $field = $reg_model->field_settings_for($field_name); |
|
289 | - if ($field_name == 'REG_final_price') { |
|
290 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
291 | - $reg_model, |
|
292 | - $field_name, |
|
293 | - $reg_row['Registration.REG_final_price'], |
|
294 | - 'localized_float' |
|
295 | - ); |
|
296 | - } elseif ($field_name == 'REG_count') { |
|
297 | - $value = sprintf( |
|
298 | - /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */ |
|
299 | - __('%1$s of %2$s', 'event_espresso'), |
|
300 | - EEH_Export::prepare_value_from_db_for_display( |
|
301 | - $reg_model, |
|
302 | - 'REG_count', |
|
303 | - $reg_row['Registration.REG_count'] |
|
304 | - ), |
|
305 | - EEH_Export::prepare_value_from_db_for_display( |
|
306 | - $reg_model, |
|
307 | - 'REG_group_size', |
|
308 | - $reg_row['Registration.REG_group_size'] |
|
309 | - ) |
|
310 | - ); |
|
311 | - } elseif ($field_name == 'REG_date') { |
|
312 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
313 | - $reg_model, |
|
314 | - $field_name, |
|
315 | - $reg_row['Registration.REG_date'], |
|
316 | - 'no_html' |
|
317 | - ); |
|
318 | - } else { |
|
319 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
320 | - $reg_model, |
|
321 | - $field_name, |
|
322 | - $reg_row[ $field->get_qualified_column() ] |
|
323 | - ); |
|
324 | - } |
|
325 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value; |
|
326 | - if ($field_name == 'REG_final_price') { |
|
327 | - // add a column named Currency after the final price |
|
328 | - $reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code; |
|
329 | - } |
|
330 | - } |
|
331 | - // get pretty status |
|
332 | - $stati = EEM_Status::instance()->localized_status( |
|
333 | - array( |
|
334 | - $reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), |
|
335 | - $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'), |
|
336 | - ), |
|
337 | - false, |
|
338 | - 'sentence' |
|
339 | - ); |
|
340 | - $reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
341 | - // get pretty transaction status |
|
342 | - $reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
343 | - $reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
344 | - ? EEH_Export::prepare_value_from_db_for_display( |
|
345 | - EEM_Transaction::instance(), |
|
346 | - 'TXN_total', |
|
347 | - $reg_row['TransactionTable.TXN_total'], |
|
348 | - 'localized_float' |
|
349 | - ) : '0.00'; |
|
350 | - $reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
351 | - ? EEH_Export::prepare_value_from_db_for_display( |
|
352 | - EEM_Transaction::instance(), |
|
353 | - 'TXN_paid', |
|
354 | - $reg_row['TransactionTable.TXN_paid'], |
|
355 | - 'localized_float' |
|
356 | - ) : '0.00'; |
|
357 | - $payment_methods = array(); |
|
358 | - $gateway_txn_ids_etc = array(); |
|
359 | - $payment_times = array(); |
|
360 | - if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
361 | - $payments_info = EEM_Payment::instance()->get_all_wpdb_results( |
|
362 | - array( |
|
363 | - array( |
|
364 | - 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
365 | - 'STS_ID' => EEM_Payment::status_id_approved, |
|
366 | - ), |
|
367 | - 'force_join' => array('Payment_Method'), |
|
368 | - ), |
|
369 | - ARRAY_A, |
|
370 | - 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
371 | - ); |
|
372 | - foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
373 | - $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
374 | - ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); |
|
375 | - $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
376 | - ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
377 | - $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
378 | - ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
379 | - } |
|
380 | - } |
|
381 | - $reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
382 | - $reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
383 | - $reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
384 | - ',', |
|
385 | - $gateway_txn_ids_etc |
|
386 | - ); |
|
387 | - // get whether or not the user has checked in |
|
388 | - $reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
389 | - $reg_row['Registration.REG_ID'], |
|
390 | - 'Checkin' |
|
391 | - ); |
|
392 | - // get ticket of registration and its price |
|
393 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
394 | - if ($reg_row['Ticket.TKT_ID']) { |
|
395 | - $ticket_name = EEH_Export::prepare_value_from_db_for_display( |
|
396 | - $ticket_model, |
|
397 | - 'TKT_name', |
|
398 | - $reg_row['Ticket.TKT_name'] |
|
399 | - ); |
|
400 | - $datetimes_strings = array(); |
|
401 | - foreach (EEM_Datetime::instance()->get_all_wpdb_results( |
|
402 | - array( |
|
403 | - array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
404 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
405 | - 'default_where_conditions' => 'none', |
|
406 | - ) |
|
407 | - ) as $datetime) { |
|
408 | - $datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display( |
|
409 | - EEM_Datetime::instance(), |
|
410 | - 'DTT_EVT_start', |
|
411 | - $datetime['Datetime.DTT_EVT_start'] |
|
412 | - ); |
|
413 | - } |
|
414 | - } else { |
|
415 | - $ticket_name = __('Unknown', 'event_espresso'); |
|
416 | - $datetimes_strings = array(__('Unknown', 'event_espresso')); |
|
417 | - } |
|
418 | - $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
419 | - $reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
420 | - // get datetime(s) of registration |
|
421 | - // add attendee columns |
|
422 | - foreach ($att_fields_to_include as $att_field_name) { |
|
423 | - $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
424 | - if ($reg_row['Attendee_CPT.ID']) { |
|
425 | - if ($att_field_name == 'STA_ID') { |
|
426 | - $value = EEM_State::instance()->get_var( |
|
427 | - array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
428 | - 'STA_name' |
|
429 | - ); |
|
430 | - } elseif ($att_field_name == 'CNT_ISO') { |
|
431 | - $value = EEM_Country::instance()->get_var( |
|
432 | - array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
433 | - 'CNT_name' |
|
434 | - ); |
|
435 | - } else { |
|
436 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
437 | - EEM_Attendee::instance(), |
|
438 | - $att_field_name, |
|
439 | - $reg_row[ $field_obj->get_qualified_column() ] |
|
440 | - ); |
|
441 | - } |
|
442 | - } else { |
|
443 | - $value = ''; |
|
444 | - } |
|
445 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value; |
|
446 | - } |
|
447 | - // make sure each registration has the same questions in the same order |
|
448 | - foreach ($question_labels as $question_label) { |
|
449 | - if (! isset($reg_csv_array[ $question_label ])) { |
|
450 | - $reg_csv_array[ $question_label ] = null; |
|
451 | - } |
|
452 | - } |
|
453 | - $answers = EEM_Answer::instance()->get_all_wpdb_results(array( |
|
454 | - array('REG_ID' => $reg_row['Registration.REG_ID']), |
|
455 | - 'force_join' => array('Question'), |
|
456 | - )); |
|
457 | - // now fill out the questions THEY answered |
|
458 | - foreach ($answers as $answer_row) { |
|
459 | - if ($answer_row['Question.QST_system']) { |
|
460 | - // it's an answer to a system question. That was already displayed as part of the attendee |
|
461 | - // fields, so don't write it out again thanks. |
|
462 | - continue; |
|
463 | - } |
|
464 | - if ($answer_row['Question.QST_ID']) { |
|
465 | - $question_label = EEH_Export::prepare_value_from_db_for_display( |
|
466 | - EEM_Question::instance(), |
|
467 | - 'QST_admin_label', |
|
468 | - $answer_row['Question.QST_admin_label'] |
|
469 | - ); |
|
470 | - } else { |
|
471 | - $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
472 | - } |
|
473 | - if (isset($answer_row['Question.QST_type']) |
|
474 | - && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state |
|
475 | - ) { |
|
476 | - $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
477 | - $answer_row['Answer.ANS_value'] |
|
478 | - ); |
|
479 | - } else { |
|
480 | - // this isn't for html, so don't show html entities |
|
481 | - $reg_csv_array[ $question_label ] = html_entity_decode( |
|
482 | - EEH_Export::prepare_value_from_db_for_display( |
|
483 | - EEM_Answer::instance(), |
|
484 | - 'ANS_value', |
|
485 | - $answer_row['Answer.ANS_value'] |
|
486 | - ) |
|
487 | - ); |
|
488 | - } |
|
489 | - } |
|
227 | + /** |
|
228 | + * Gets the csv data for a batch of registrations |
|
229 | + * |
|
230 | + * @param int|null $event_id |
|
231 | + * @param int $offset |
|
232 | + * @param int $limit |
|
233 | + * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
234 | + * @param array $query_params for using where querying the model |
|
235 | + * @return array top-level keys are numeric, next-level keys are column headers |
|
236 | + * @throws \EE_Error |
|
237 | + */ |
|
238 | + public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params) |
|
239 | + { |
|
240 | + $reg_fields_to_include = array( |
|
241 | + 'TXN_ID', |
|
242 | + 'ATT_ID', |
|
243 | + 'REG_ID', |
|
244 | + 'REG_date', |
|
245 | + 'REG_code', |
|
246 | + 'REG_count', |
|
247 | + 'REG_final_price', |
|
248 | + ); |
|
249 | + $att_fields_to_include = array( |
|
250 | + 'ATT_fname', |
|
251 | + 'ATT_lname', |
|
252 | + 'ATT_email', |
|
253 | + 'ATT_address', |
|
254 | + 'ATT_address2', |
|
255 | + 'ATT_city', |
|
256 | + 'STA_ID', |
|
257 | + 'CNT_ISO', |
|
258 | + 'ATT_zip', |
|
259 | + 'ATT_phone', |
|
260 | + ); |
|
261 | + $registrations_csv_ready_array = array(); |
|
262 | + $reg_model = EE_Registry::instance()->load_model('Registration'); |
|
263 | + $query_params['limit'] = array($offset, $limit); |
|
264 | + $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
265 | + $registration_ids = array(); |
|
266 | + foreach ($registration_rows as $reg_row) { |
|
267 | + $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
268 | + } |
|
269 | + foreach ($registration_rows as $reg_row) { |
|
270 | + if (is_array($reg_row)) { |
|
271 | + $reg_csv_array = array(); |
|
272 | + if (! $event_id) { |
|
273 | + // get the event's name and Id |
|
274 | + $reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf( |
|
275 | + /* translators: 1: event name, 2: event ID */ |
|
276 | + __('%1$s (%2$s)', 'event_espresso'), |
|
277 | + EEH_Export::prepare_value_from_db_for_display( |
|
278 | + EEM_Event::instance(), |
|
279 | + 'EVT_name', |
|
280 | + $reg_row['Event_CPT.post_title'] |
|
281 | + ), |
|
282 | + $reg_row['Event_CPT.ID'] |
|
283 | + ); |
|
284 | + } |
|
285 | + $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
286 | + /*@var $reg_row EE_Registration */ |
|
287 | + foreach ($reg_fields_to_include as $field_name) { |
|
288 | + $field = $reg_model->field_settings_for($field_name); |
|
289 | + if ($field_name == 'REG_final_price') { |
|
290 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
291 | + $reg_model, |
|
292 | + $field_name, |
|
293 | + $reg_row['Registration.REG_final_price'], |
|
294 | + 'localized_float' |
|
295 | + ); |
|
296 | + } elseif ($field_name == 'REG_count') { |
|
297 | + $value = sprintf( |
|
298 | + /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */ |
|
299 | + __('%1$s of %2$s', 'event_espresso'), |
|
300 | + EEH_Export::prepare_value_from_db_for_display( |
|
301 | + $reg_model, |
|
302 | + 'REG_count', |
|
303 | + $reg_row['Registration.REG_count'] |
|
304 | + ), |
|
305 | + EEH_Export::prepare_value_from_db_for_display( |
|
306 | + $reg_model, |
|
307 | + 'REG_group_size', |
|
308 | + $reg_row['Registration.REG_group_size'] |
|
309 | + ) |
|
310 | + ); |
|
311 | + } elseif ($field_name == 'REG_date') { |
|
312 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
313 | + $reg_model, |
|
314 | + $field_name, |
|
315 | + $reg_row['Registration.REG_date'], |
|
316 | + 'no_html' |
|
317 | + ); |
|
318 | + } else { |
|
319 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
320 | + $reg_model, |
|
321 | + $field_name, |
|
322 | + $reg_row[ $field->get_qualified_column() ] |
|
323 | + ); |
|
324 | + } |
|
325 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value; |
|
326 | + if ($field_name == 'REG_final_price') { |
|
327 | + // add a column named Currency after the final price |
|
328 | + $reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code; |
|
329 | + } |
|
330 | + } |
|
331 | + // get pretty status |
|
332 | + $stati = EEM_Status::instance()->localized_status( |
|
333 | + array( |
|
334 | + $reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), |
|
335 | + $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'), |
|
336 | + ), |
|
337 | + false, |
|
338 | + 'sentence' |
|
339 | + ); |
|
340 | + $reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
341 | + // get pretty transaction status |
|
342 | + $reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
343 | + $reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
344 | + ? EEH_Export::prepare_value_from_db_for_display( |
|
345 | + EEM_Transaction::instance(), |
|
346 | + 'TXN_total', |
|
347 | + $reg_row['TransactionTable.TXN_total'], |
|
348 | + 'localized_float' |
|
349 | + ) : '0.00'; |
|
350 | + $reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
351 | + ? EEH_Export::prepare_value_from_db_for_display( |
|
352 | + EEM_Transaction::instance(), |
|
353 | + 'TXN_paid', |
|
354 | + $reg_row['TransactionTable.TXN_paid'], |
|
355 | + 'localized_float' |
|
356 | + ) : '0.00'; |
|
357 | + $payment_methods = array(); |
|
358 | + $gateway_txn_ids_etc = array(); |
|
359 | + $payment_times = array(); |
|
360 | + if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
361 | + $payments_info = EEM_Payment::instance()->get_all_wpdb_results( |
|
362 | + array( |
|
363 | + array( |
|
364 | + 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
365 | + 'STS_ID' => EEM_Payment::status_id_approved, |
|
366 | + ), |
|
367 | + 'force_join' => array('Payment_Method'), |
|
368 | + ), |
|
369 | + ARRAY_A, |
|
370 | + 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
371 | + ); |
|
372 | + foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
373 | + $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
374 | + ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); |
|
375 | + $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
376 | + ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
377 | + $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
378 | + ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
379 | + } |
|
380 | + } |
|
381 | + $reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
382 | + $reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
383 | + $reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
384 | + ',', |
|
385 | + $gateway_txn_ids_etc |
|
386 | + ); |
|
387 | + // get whether or not the user has checked in |
|
388 | + $reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
389 | + $reg_row['Registration.REG_ID'], |
|
390 | + 'Checkin' |
|
391 | + ); |
|
392 | + // get ticket of registration and its price |
|
393 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
394 | + if ($reg_row['Ticket.TKT_ID']) { |
|
395 | + $ticket_name = EEH_Export::prepare_value_from_db_for_display( |
|
396 | + $ticket_model, |
|
397 | + 'TKT_name', |
|
398 | + $reg_row['Ticket.TKT_name'] |
|
399 | + ); |
|
400 | + $datetimes_strings = array(); |
|
401 | + foreach (EEM_Datetime::instance()->get_all_wpdb_results( |
|
402 | + array( |
|
403 | + array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
404 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
405 | + 'default_where_conditions' => 'none', |
|
406 | + ) |
|
407 | + ) as $datetime) { |
|
408 | + $datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display( |
|
409 | + EEM_Datetime::instance(), |
|
410 | + 'DTT_EVT_start', |
|
411 | + $datetime['Datetime.DTT_EVT_start'] |
|
412 | + ); |
|
413 | + } |
|
414 | + } else { |
|
415 | + $ticket_name = __('Unknown', 'event_espresso'); |
|
416 | + $datetimes_strings = array(__('Unknown', 'event_espresso')); |
|
417 | + } |
|
418 | + $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
419 | + $reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
420 | + // get datetime(s) of registration |
|
421 | + // add attendee columns |
|
422 | + foreach ($att_fields_to_include as $att_field_name) { |
|
423 | + $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
424 | + if ($reg_row['Attendee_CPT.ID']) { |
|
425 | + if ($att_field_name == 'STA_ID') { |
|
426 | + $value = EEM_State::instance()->get_var( |
|
427 | + array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
428 | + 'STA_name' |
|
429 | + ); |
|
430 | + } elseif ($att_field_name == 'CNT_ISO') { |
|
431 | + $value = EEM_Country::instance()->get_var( |
|
432 | + array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
433 | + 'CNT_name' |
|
434 | + ); |
|
435 | + } else { |
|
436 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
437 | + EEM_Attendee::instance(), |
|
438 | + $att_field_name, |
|
439 | + $reg_row[ $field_obj->get_qualified_column() ] |
|
440 | + ); |
|
441 | + } |
|
442 | + } else { |
|
443 | + $value = ''; |
|
444 | + } |
|
445 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value; |
|
446 | + } |
|
447 | + // make sure each registration has the same questions in the same order |
|
448 | + foreach ($question_labels as $question_label) { |
|
449 | + if (! isset($reg_csv_array[ $question_label ])) { |
|
450 | + $reg_csv_array[ $question_label ] = null; |
|
451 | + } |
|
452 | + } |
|
453 | + $answers = EEM_Answer::instance()->get_all_wpdb_results(array( |
|
454 | + array('REG_ID' => $reg_row['Registration.REG_ID']), |
|
455 | + 'force_join' => array('Question'), |
|
456 | + )); |
|
457 | + // now fill out the questions THEY answered |
|
458 | + foreach ($answers as $answer_row) { |
|
459 | + if ($answer_row['Question.QST_system']) { |
|
460 | + // it's an answer to a system question. That was already displayed as part of the attendee |
|
461 | + // fields, so don't write it out again thanks. |
|
462 | + continue; |
|
463 | + } |
|
464 | + if ($answer_row['Question.QST_ID']) { |
|
465 | + $question_label = EEH_Export::prepare_value_from_db_for_display( |
|
466 | + EEM_Question::instance(), |
|
467 | + 'QST_admin_label', |
|
468 | + $answer_row['Question.QST_admin_label'] |
|
469 | + ); |
|
470 | + } else { |
|
471 | + $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
472 | + } |
|
473 | + if (isset($answer_row['Question.QST_type']) |
|
474 | + && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state |
|
475 | + ) { |
|
476 | + $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
477 | + $answer_row['Answer.ANS_value'] |
|
478 | + ); |
|
479 | + } else { |
|
480 | + // this isn't for html, so don't show html entities |
|
481 | + $reg_csv_array[ $question_label ] = html_entity_decode( |
|
482 | + EEH_Export::prepare_value_from_db_for_display( |
|
483 | + EEM_Answer::instance(), |
|
484 | + 'ANS_value', |
|
485 | + $answer_row['Answer.ANS_value'] |
|
486 | + ) |
|
487 | + ); |
|
488 | + } |
|
489 | + } |
|
490 | 490 | |
491 | - /** |
|
492 | - * Filter to change the contents of each row of the registrations report CSV file. |
|
493 | - * This can be used to add or remote columns from the CSV file, or change their values. |
|
494 | - * Note when using: all rows in the CSV should have the same columns. |
|
495 | - * @param array $reg_csv_array keys are the column names, values are their cell values |
|
496 | - * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results() |
|
497 | - */ |
|
498 | - $registrations_csv_ready_array[] = apply_filters( |
|
499 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', |
|
500 | - $reg_csv_array, |
|
501 | - $reg_row |
|
502 | - ); |
|
503 | - } |
|
504 | - } |
|
505 | - // if we couldn't export anything, we want to at least show the column headers |
|
506 | - if (empty($registrations_csv_ready_array)) { |
|
507 | - $reg_csv_array = array(); |
|
508 | - $model_and_fields_to_include = array( |
|
509 | - 'Registration' => $reg_fields_to_include, |
|
510 | - 'Attendee' => $att_fields_to_include, |
|
511 | - ); |
|
512 | - foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
513 | - $model = EE_Registry::instance()->load_model($model_name); |
|
514 | - foreach ($field_list as $field_name) { |
|
515 | - $field = $model->field_settings_for($field_name); |
|
516 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
517 | - } |
|
518 | - } |
|
519 | - $registrations_csv_ready_array[] = $reg_csv_array; |
|
520 | - } |
|
521 | - return $registrations_csv_ready_array; |
|
522 | - } |
|
491 | + /** |
|
492 | + * Filter to change the contents of each row of the registrations report CSV file. |
|
493 | + * This can be used to add or remote columns from the CSV file, or change their values. |
|
494 | + * Note when using: all rows in the CSV should have the same columns. |
|
495 | + * @param array $reg_csv_array keys are the column names, values are their cell values |
|
496 | + * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results() |
|
497 | + */ |
|
498 | + $registrations_csv_ready_array[] = apply_filters( |
|
499 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', |
|
500 | + $reg_csv_array, |
|
501 | + $reg_row |
|
502 | + ); |
|
503 | + } |
|
504 | + } |
|
505 | + // if we couldn't export anything, we want to at least show the column headers |
|
506 | + if (empty($registrations_csv_ready_array)) { |
|
507 | + $reg_csv_array = array(); |
|
508 | + $model_and_fields_to_include = array( |
|
509 | + 'Registration' => $reg_fields_to_include, |
|
510 | + 'Attendee' => $att_fields_to_include, |
|
511 | + ); |
|
512 | + foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
513 | + $model = EE_Registry::instance()->load_model($model_name); |
|
514 | + foreach ($field_list as $field_name) { |
|
515 | + $field = $model->field_settings_for($field_name); |
|
516 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
517 | + } |
|
518 | + } |
|
519 | + $registrations_csv_ready_array[] = $reg_csv_array; |
|
520 | + } |
|
521 | + return $registrations_csv_ready_array; |
|
522 | + } |
|
523 | 523 | |
524 | 524 | |
525 | - /** |
|
526 | - * Counts total unit to process |
|
527 | - * |
|
528 | - * @deprecated since 4.9.19 |
|
529 | - * @param int|array $event_id |
|
530 | - * @return int |
|
531 | - */ |
|
532 | - public function count_units_to_process($event_id) |
|
533 | - { |
|
534 | - // use the legacy filter |
|
535 | - if ($event_id) { |
|
536 | - $query_params[0]['EVT_ID'] = $event_id; |
|
537 | - } else { |
|
538 | - $query_params['force_join'][] = 'Event'; |
|
539 | - } |
|
540 | - return \EEM_Registration::instance()->count($query_params); |
|
541 | - } |
|
525 | + /** |
|
526 | + * Counts total unit to process |
|
527 | + * |
|
528 | + * @deprecated since 4.9.19 |
|
529 | + * @param int|array $event_id |
|
530 | + * @return int |
|
531 | + */ |
|
532 | + public function count_units_to_process($event_id) |
|
533 | + { |
|
534 | + // use the legacy filter |
|
535 | + if ($event_id) { |
|
536 | + $query_params[0]['EVT_ID'] = $event_id; |
|
537 | + } else { |
|
538 | + $query_params['force_join'][] = 'Event'; |
|
539 | + } |
|
540 | + return \EEM_Registration::instance()->count($query_params); |
|
541 | + } |
|
542 | 542 | |
543 | 543 | |
544 | - /** |
|
545 | - * Performs any clean-up logic when we know the job is completed. |
|
546 | - * In this case, we delete the temporary file |
|
547 | - * |
|
548 | - * @param JobParameters $job_parameters |
|
549 | - * @return boolean |
|
550 | - */ |
|
551 | - public function cleanup_job(JobParameters $job_parameters) |
|
552 | - { |
|
553 | - $this->_file_helper->delete( |
|
554 | - \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
555 | - true, |
|
556 | - 'd' |
|
557 | - ); |
|
558 | - return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso')); |
|
559 | - } |
|
544 | + /** |
|
545 | + * Performs any clean-up logic when we know the job is completed. |
|
546 | + * In this case, we delete the temporary file |
|
547 | + * |
|
548 | + * @param JobParameters $job_parameters |
|
549 | + * @return boolean |
|
550 | + */ |
|
551 | + public function cleanup_job(JobParameters $job_parameters) |
|
552 | + { |
|
553 | + $this->_file_helper->delete( |
|
554 | + \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
555 | + true, |
|
556 | + 'd' |
|
557 | + ); |
|
558 | + return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso')); |
|
559 | + } |
|
560 | 560 | } |
@@ -32,102 +32,102 @@ |
||
32 | 32 | |
33 | 33 | class EE_DMS_4_1_0_answers extends EE_Data_Migration_Script_Stage_Table |
34 | 34 | { |
35 | - private $_new_answer_table; |
|
36 | - private $_new_question_table; |
|
37 | - public function __construct() |
|
38 | - { |
|
39 | - global $wpdb; |
|
40 | - $this->_pretty_name = __("Answers", "event_espresso"); |
|
41 | - $this->_old_table = $wpdb->prefix."events_answer"; |
|
42 | - // join to attendee and then join to events table |
|
43 | - $this->select_expression = 'ans.*, e.event_status'; |
|
44 | - $this->_extra_where_sql = ' AS ans |
|
35 | + private $_new_answer_table; |
|
36 | + private $_new_question_table; |
|
37 | + public function __construct() |
|
38 | + { |
|
39 | + global $wpdb; |
|
40 | + $this->_pretty_name = __("Answers", "event_espresso"); |
|
41 | + $this->_old_table = $wpdb->prefix."events_answer"; |
|
42 | + // join to attendee and then join to events table |
|
43 | + $this->select_expression = 'ans.*, e.event_status'; |
|
44 | + $this->_extra_where_sql = ' AS ans |
|
45 | 45 | INNER JOIN ' . $wpdb->prefix . 'events_attendee AS att ON ans.attendee_id = att.id |
46 | 46 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id = e.id |
47 | 47 | WHERE e.event_status !="D"'; |
48 | - $this->_new_answer_table = $wpdb->prefix."esp_answer"; |
|
49 | - $this->_new_question_table = $wpdb->prefix."esp_question"; |
|
50 | - parent::__construct(); |
|
51 | - } |
|
52 | - protected function _migrate_old_row($old_row) |
|
53 | - { |
|
54 | - // get the new REGs for the old answer |
|
55 | - global $wpdb; |
|
56 | - $old_attendee_table = $wpdb->prefix."events_attendee"; |
|
57 | - $new_reg_table = $wpdb->prefix."esp_registration"; |
|
58 | - $regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table); |
|
59 | - if (! $regs) { |
|
60 | - $this->add_error(sprintf(__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row))); |
|
61 | - return false; |
|
62 | - } |
|
63 | - // as inefficient as this sounds, we create an answer per REGISTRATION, (even if the registrations use the same attendee) |
|
64 | - foreach ($regs as $new_reg_id) { |
|
65 | - $this->_insert_new_answer($old_row, $new_reg_id); |
|
66 | - } |
|
67 | - } |
|
68 | - /** |
|
69 | - * Creates a 4.1 price base type |
|
70 | - * @global type $wpdb |
|
71 | - * @param array $old_price |
|
72 | - * @param int $new_reg_id |
|
73 | - * @return int |
|
74 | - */ |
|
75 | - private function _insert_new_answer($old_answer, $new_reg_id) |
|
76 | - { |
|
77 | - global $wpdb; |
|
78 | - $old_question_table = $wpdb->prefix."events_question"; |
|
79 | - $new_question_id = $this->get_migration_script()->get_mapping_new_pk($old_question_table, $old_answer['question_id'], $this->_new_question_table); |
|
48 | + $this->_new_answer_table = $wpdb->prefix."esp_answer"; |
|
49 | + $this->_new_question_table = $wpdb->prefix."esp_question"; |
|
50 | + parent::__construct(); |
|
51 | + } |
|
52 | + protected function _migrate_old_row($old_row) |
|
53 | + { |
|
54 | + // get the new REGs for the old answer |
|
55 | + global $wpdb; |
|
56 | + $old_attendee_table = $wpdb->prefix."events_attendee"; |
|
57 | + $new_reg_table = $wpdb->prefix."esp_registration"; |
|
58 | + $regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table); |
|
59 | + if (! $regs) { |
|
60 | + $this->add_error(sprintf(__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row))); |
|
61 | + return false; |
|
62 | + } |
|
63 | + // as inefficient as this sounds, we create an answer per REGISTRATION, (even if the registrations use the same attendee) |
|
64 | + foreach ($regs as $new_reg_id) { |
|
65 | + $this->_insert_new_answer($old_row, $new_reg_id); |
|
66 | + } |
|
67 | + } |
|
68 | + /** |
|
69 | + * Creates a 4.1 price base type |
|
70 | + * @global type $wpdb |
|
71 | + * @param array $old_price |
|
72 | + * @param int $new_reg_id |
|
73 | + * @return int |
|
74 | + */ |
|
75 | + private function _insert_new_answer($old_answer, $new_reg_id) |
|
76 | + { |
|
77 | + global $wpdb; |
|
78 | + $old_question_table = $wpdb->prefix."events_question"; |
|
79 | + $new_question_id = $this->get_migration_script()->get_mapping_new_pk($old_question_table, $old_answer['question_id'], $this->_new_question_table); |
|
80 | 80 | |
81 | - $question_row = $this->_get_question_type_and_system($new_question_id); |
|
82 | - if ($question_row['QST_system']) { |
|
83 | - // It's an answer to a system question? EE3 used to store that on both the attendee and the answers column, |
|
84 | - // but not EE4! It's just stored in the attendee meta table. The answers table is ONLY for answers to custom |
|
85 | - // questions. |
|
86 | - return 0; |
|
87 | - } |
|
88 | - if (in_array($question_row['QST_type'], array('MULTIPLE'))) { |
|
89 | - $ans_value = serialize(explode(",", stripslashes($old_answer['answer']))); |
|
90 | - } else { |
|
91 | - $ans_value = stripslashes($old_answer['answer']); |
|
92 | - } |
|
93 | - $cols_n_values = array( |
|
94 | - 'REG_ID'=>$new_reg_id, |
|
95 | - 'QST_ID'=>$new_question_id, |
|
96 | - 'ANS_value'=>$ans_value |
|
97 | - ); |
|
98 | - $datatypes = array( |
|
99 | - '%d',// REG_ID |
|
100 | - '%d',// QST_ID |
|
101 | - '%s',// ANS_value |
|
102 | - ); |
|
103 | - $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes); |
|
104 | - if (! $success) { |
|
105 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes)); |
|
106 | - return 0; |
|
107 | - } |
|
108 | - $new_id = $wpdb->insert_id; |
|
109 | - return $new_id; |
|
110 | - } |
|
81 | + $question_row = $this->_get_question_type_and_system($new_question_id); |
|
82 | + if ($question_row['QST_system']) { |
|
83 | + // It's an answer to a system question? EE3 used to store that on both the attendee and the answers column, |
|
84 | + // but not EE4! It's just stored in the attendee meta table. The answers table is ONLY for answers to custom |
|
85 | + // questions. |
|
86 | + return 0; |
|
87 | + } |
|
88 | + if (in_array($question_row['QST_type'], array('MULTIPLE'))) { |
|
89 | + $ans_value = serialize(explode(",", stripslashes($old_answer['answer']))); |
|
90 | + } else { |
|
91 | + $ans_value = stripslashes($old_answer['answer']); |
|
92 | + } |
|
93 | + $cols_n_values = array( |
|
94 | + 'REG_ID'=>$new_reg_id, |
|
95 | + 'QST_ID'=>$new_question_id, |
|
96 | + 'ANS_value'=>$ans_value |
|
97 | + ); |
|
98 | + $datatypes = array( |
|
99 | + '%d',// REG_ID |
|
100 | + '%d',// QST_ID |
|
101 | + '%s',// ANS_value |
|
102 | + ); |
|
103 | + $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes); |
|
104 | + if (! $success) { |
|
105 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes)); |
|
106 | + return 0; |
|
107 | + } |
|
108 | + $new_id = $wpdb->insert_id; |
|
109 | + return $new_id; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Gets the question's type |
|
114 | - * @global type $wpdb |
|
115 | - * @param type $question_id |
|
116 | - * @return array { |
|
117 | - * @type string $QST_type |
|
118 | - * @type string $QST_system |
|
119 | - * } |
|
120 | - */ |
|
121 | - private function _get_question_type_and_system($question_id) |
|
122 | - { |
|
123 | - global $wpdb; |
|
124 | - $row = $wpdb->get_row( |
|
125 | - $wpdb->prepare( |
|
126 | - "SELECT QST_type, QST_system FROM ".$this->_new_question_table." WHERE QST_ID=%d LIMIT 1", |
|
127 | - $question_id |
|
128 | - ), |
|
129 | - ARRAY_A |
|
130 | - ); |
|
131 | - return $row; |
|
132 | - } |
|
112 | + /** |
|
113 | + * Gets the question's type |
|
114 | + * @global type $wpdb |
|
115 | + * @param type $question_id |
|
116 | + * @return array { |
|
117 | + * @type string $QST_type |
|
118 | + * @type string $QST_system |
|
119 | + * } |
|
120 | + */ |
|
121 | + private function _get_question_type_and_system($question_id) |
|
122 | + { |
|
123 | + global $wpdb; |
|
124 | + $row = $wpdb->get_row( |
|
125 | + $wpdb->prepare( |
|
126 | + "SELECT QST_type, QST_system FROM ".$this->_new_question_table." WHERE QST_ID=%d LIMIT 1", |
|
127 | + $question_id |
|
128 | + ), |
|
129 | + ARRAY_A |
|
130 | + ); |
|
131 | + return $row; |
|
132 | + } |
|
133 | 133 | } |