Completed
Branch dependabot/npm_and_yarn/wordpr... (7a0faf)
by
unknown
143:21 queued 132:30
created
core/db_classes/EE_CPT_Base.class.php 2 patches
Indentation   +425 added lines, -425 removed lines patch added patch discarded remove patch
@@ -14,429 +14,429 @@
 block discarded – undo
14 14
 abstract class EE_CPT_Base extends EE_Soft_Delete_Base_Class
15 15
 {
16 16
 
17
-    /**
18
-     * This is a property for holding cached feature images on CPT objects.  Cache's are set on the first
19
-     * "feature_image()" method call.  Each key in the array corresponds to the requested size.
20
-     *
21
-     * @var array
22
-     */
23
-    protected $_feature_image = array();
24
-
25
-    /**
26
-     * @var WP_Post the WP_Post that corresponds with this CPT model object
27
-     */
28
-    protected $_wp_post;
29
-
30
-
31
-    abstract public function wp_user();
32
-
33
-
34
-    /**
35
-     * Returns the WP post associated with this CPT model object. If this CPT is saved, fetches it
36
-     * from the DB. Otherwise, create an unsaved WP_POst object. Caches the post internally.
37
-     *
38
-     * @return WP_Post
39
-     */
40
-    public function wp_post()
41
-    {
42
-        global $wpdb;
43
-        if (! $this->_wp_post instanceof WP_Post) {
44
-            if ($this->ID()) {
45
-                $this->_wp_post = get_post($this->ID());
46
-            } else {
47
-                $simulated_db_result = new stdClass();
48
-                foreach ($this->get_model()->field_settings(true) as $field_name => $field_obj) {
49
-                    if ($this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name()
50
-                        === $wpdb->posts
51
-                    ) {
52
-                        $column = $field_obj->get_table_column();
53
-
54
-                        if ($field_obj instanceof EE_Datetime_Field) {
55
-                            $value_on_model_obj = $this->get_DateTime_object($field_name);
56
-                        } elseif ($field_obj->is_db_only_field()) {
57
-                            $value_on_model_obj = $field_obj->get_default_value();
58
-                        } else {
59
-                            $value_on_model_obj = $this->get_raw($field_name);
60
-                        }
61
-                        $simulated_db_result->{$column} = $field_obj->prepare_for_use_in_db($value_on_model_obj);
62
-                    }
63
-                }
64
-                $this->_wp_post = new WP_Post($simulated_db_result);
65
-            }
66
-            // and let's make retrieving the EE CPT object easy too
67
-            $classname = get_class($this);
68
-            if (! isset($this->_wp_post->{$classname})) {
69
-                $this->_wp_post->{$classname} = $this;
70
-            }
71
-        }
72
-        return $this->_wp_post;
73
-    }
74
-
75
-    /**
76
-     * When fetching a new value for a post field that uses the global $post for rendering,
77
-     * set the global $post temporarily to be this model object; and afterwards restore it
78
-     *
79
-     * @param string $fieldname
80
-     * @param bool   $pretty
81
-     * @param string $extra_cache_ref
82
-     * @return mixed
83
-     */
84
-    protected function _get_fresh_property($fieldname, $pretty = false, $extra_cache_ref = null)
85
-    {
86
-        global $post;
87
-
88
-        if ($pretty
89
-            && (
90
-                ! (
91
-                    $post instanceof WP_Post
92
-                    && $post->ID
93
-                )
94
-                || (int) $post->ID !== $this->ID()
95
-            )
96
-            && $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field) {
97
-            $old_post = $post;
98
-            $post = $this->wp_post();
99
-            $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref);
100
-            $post = $old_post;
101
-        } else {
102
-            $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref);
103
-        }
104
-        return $return_value;
105
-    }
106
-
107
-    /**
108
-     * Adds to the specified event category. If it category doesn't exist, creates it.
109
-     *
110
-     * @param string $category_name
111
-     * @param string $category_description    optional
112
-     * @param int    $parent_term_taxonomy_id optional
113
-     * @return EE_Term_Taxonomy
114
-     */
115
-    public function add_event_category($category_name, $category_description = null, $parent_term_taxonomy_id = null)
116
-    {
117
-        return $this->get_model()->add_event_category(
118
-            $this,
119
-            $category_name,
120
-            $category_description,
121
-            $parent_term_taxonomy_id
122
-        );
123
-    }
124
-
125
-
126
-    /**
127
-     * Removes the event category by specified name from being related ot this event
128
-     *
129
-     * @param string $category_name
130
-     * @return bool
131
-     */
132
-    public function remove_event_category($category_name)
133
-    {
134
-        return $this->get_model()->remove_event_category($this, $category_name);
135
-    }
136
-
137
-
138
-    /**
139
-     * Removes the relation to the specified term taxonomy, and maintains the
140
-     * data integrity of the term taxonomy provided
141
-     *
142
-     * @param EE_Term_Taxonomy $term_taxonomy
143
-     * @return EE_Base_Class the relation was removed from
144
-     */
145
-    public function remove_relation_to_term_taxonomy($term_taxonomy)
146
-    {
147
-        if (! $term_taxonomy) {
148
-            EE_Error::add_error(
149
-                sprintf(
150
-                    __(
151
-                        "No Term_Taxonomy provided which to remove from model object of type %s and id %d",
152
-                        "event_espresso"
153
-                    ),
154
-                    get_class($this),
155
-                    $this->ID()
156
-                ),
157
-                __FILE__,
158
-                __FUNCTION__,
159
-                __LINE__
160
-            );
161
-            return null;
162
-        }
163
-        $term_taxonomy->set_count($term_taxonomy->count() - 1);
164
-        $term_taxonomy->save();
165
-        return $this->_remove_relation_to($term_taxonomy, 'Term_Taxonomy');
166
-    }
167
-
168
-
169
-    /**
170
-     * The main purpose of this method is to return the post type for the model object
171
-     *
172
-     * @access public
173
-     * @return string
174
-     */
175
-    public function post_type()
176
-    {
177
-        return $this->get_model()->post_type();
178
-    }
179
-
180
-
181
-    /**
182
-     * The main purpose of this method is to return the parent for the model object
183
-     *
184
-     * @access public
185
-     * @return int
186
-     */
187
-    public function parent()
188
-    {
189
-        return $this->get('parent');
190
-    }
191
-
192
-
193
-    /**
194
-     * return the _status property
195
-     *
196
-     * @return string
197
-     */
198
-    public function status()
199
-    {
200
-        return $this->get('status');
201
-    }
202
-
203
-
204
-    /**
205
-     * @param string $status
206
-     */
207
-    public function set_status($status)
208
-    {
209
-        $this->set('status', $status);
210
-    }
211
-
212
-
213
-    /**
214
-     * This calls the equivalent model method for retrieving the feature image which in turn is a wrapper for
215
-     * WordPress' get_the_post_thumbnail() function.
216
-     *
217
-     * @link   http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
218
-     * @access protected
219
-     * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array
220
-     *                           representing width and height in pixels (i.e. array(32,32) ).
221
-     * @param string|array $attr Optional. Query string or array of attributes.
222
-     * @return string HTML image element
223
-     */
224
-    protected function _get_feature_image($size, $attr)
225
-    {
226
-        // first let's see if we already have the _feature_image property set AND if it has a cached element on it FOR the given size
227
-        $attr_key = is_array($attr) ? implode('_', $attr) : $attr;
228
-        $cache_key = is_array($size) ? implode('_', $size) . $attr_key : $size . $attr_key;
229
-        $this->_feature_image[ $cache_key ] = isset($this->_feature_image[ $cache_key ])
230
-            ? $this->_feature_image[ $cache_key ] : $this->get_model()->get_feature_image($this->ID(), $size, $attr);
231
-        return $this->_feature_image[ $cache_key ];
232
-    }
233
-
234
-
235
-    /**
236
-     * See _get_feature_image. Returns the HTML to display a featured image
237
-     *
238
-     * @param string       $size
239
-     * @param string|array $attr
240
-     * @return string of html
241
-     */
242
-    public function feature_image($size = 'thumbnail', $attr = '')
243
-    {
244
-        return $this->_get_feature_image($size, $attr);
245
-    }
246
-
247
-
248
-    /**
249
-     * This uses the wp "wp_get_attachment_image_src()" function to return the feature image for the current class
250
-     * using the given size params.
251
-     *
252
-     * @param  string|array $size can either be a string: 'thumbnail', 'medium', 'large', 'full' OR 2-item array
253
-     *                            representing width and height in pixels eg. array(32,32).
254
-     * @return string|boolean          the url of the image or false if not found
255
-     */
256
-    public function feature_image_url($size = 'thumbnail')
257
-    {
258
-        $attachment = wp_get_attachment_image_src(get_post_thumbnail_id($this->ID()), $size);
259
-        return ! empty($attachment) ? $attachment[0] : false;
260
-    }
261
-
262
-
263
-    /**
264
-     * This is a method for restoring this_obj using details from the given $revision_id
265
-     *
266
-     * @param int   $revision_id       ID of the revision we're getting data from
267
-     * @param array $related_obj_names if included this will be used to restore for related obj
268
-     *                                 if not included then we just do restore on the meta.
269
-     *                                 We will accept an array of related_obj_names for restoration here.
270
-     * @param array $where_query       You can optionally include an array of key=>value pairs
271
-     *                                 that allow you to further constrict the relation to being added.
272
-     *                                 However, keep in mind that the columns (keys) given
273
-     *                                 must match a column on the JOIN table and currently
274
-     *                                 only the HABTM models accept these additional conditions.
275
-     *                                 Also remember that if an exact match isn't found for these extra cols/val pairs,
276
-     *                                 then a NEW row is created in the join table.
277
-     *                                 This array is INDEXED by RELATED OBJ NAME (so it corresponds with the obj_names
278
-     *                                 sent);
279
-     * @return void
280
-     */
281
-    public function restore_revision($revision_id, $related_obj_names = array(), $where_query = array())
282
-    {
283
-        // get revision object
284
-        $revision_obj = $this->get_model()->get_one_by_ID($revision_id);
285
-        if ($revision_obj instanceof EE_CPT_Base) {
286
-            // no related_obj_name so we assume we're saving a revision on this object.
287
-            if (empty($related_obj_names)) {
288
-                $fields = $this->get_model()->get_meta_table_fields();
289
-                foreach ($fields as $field) {
290
-                    $this->set($field, $revision_obj->get($field));
291
-                }
292
-                $this->save();
293
-            }
294
-            $related_obj_names = (array) $related_obj_names;
295
-            foreach ($related_obj_names as $related_name) {
296
-                // related_obj_name so we're saving a revision on an object related to this object
297
-                // do we have $where_query params for this related object?  If we do then we include that.
298
-                $cols_n_values = isset($where_query[ $related_name ]) ? $where_query[ $related_name ] : array();
299
-                $where_params = ! empty($cols_n_values) ? array($cols_n_values) : array();
300
-                $related_objs = $this->get_many_related($related_name, $where_params);
301
-                $revision_related_objs = $revision_obj->get_many_related($related_name, $where_params);
302
-                // load helper
303
-                // remove related objs from this object that are not in revision
304
-                // array_diff *should* work cause I think objects are indexed by ID?
305
-                $related_to_remove = EEH_Array::object_array_diff($related_objs, $revision_related_objs);
306
-                foreach ($related_to_remove as $rr) {
307
-                    $this->_remove_relation_to($rr, $related_name, $cols_n_values);
308
-                }
309
-                // add all related objs attached to revision to this object
310
-                foreach ($revision_related_objs as $r_obj) {
311
-                    $this->_add_relation_to($r_obj, $related_name, $cols_n_values);
312
-                }
313
-            }
314
-        }
315
-    }
316
-
317
-
318
-    /**
319
-     * Wrapper for get_post_meta, http://codex.wordpress.org/Function_Reference/get_post_meta
320
-     *
321
-     * @param string  $meta_key
322
-     * @param boolean $single
323
-     * @return mixed <ul><li>If only $id is set it will return all meta values in an associative array.</li>
324
-     * <li>If $single is set to false, or left blank, the function returns an array containing all values of the
325
-     * specified key.</li>
326
-     * <li>If $single is set to true, the function returns the first value of the specified key (not in an
327
-     * array</li></ul>
328
-     */
329
-    public function get_post_meta($meta_key = null, $single = false)
330
-    {
331
-        return get_post_meta($this->ID(), $meta_key, $single);
332
-    }
333
-
334
-
335
-    /**
336
-     * Wrapper for update_post_meta, http://codex.wordpress.org/Function_Reference/update_post_meta
337
-     *
338
-     * @param string $meta_key
339
-     * @param mixed  $meta_value
340
-     * @param mixed  $prev_value
341
-     * @return mixed Returns meta_id if the meta doesn't exist, otherwise returns true on success and false on failure.
342
-     *               NOTE: If the meta_value passed to this function is the same as the value that is already in the
343
-     *               database, this function returns false.
344
-     */
345
-    public function update_post_meta($meta_key, $meta_value, $prev_value = null)
346
-    {
347
-        if (! $this->ID()) {
348
-            $this->save();
349
-        }
350
-        return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value);
351
-    }
352
-
353
-
354
-    /**
355
-     * Wrapper for add_post_meta, http://codex.wordpress.org/Function_Reference/add_post_meta
356
-     *
357
-     * @param mixed $meta_key
358
-     * @param mixed $meta_value
359
-     * @param bool  $unique . If postmeta for this $meta_key already exists, whether to add an additional item or not
360
-     * @return boolean Boolean true, except if the $unique argument was set to true and a custom field with the given
361
-     *                 key already exists, in which case false is returned.
362
-     */
363
-    public function add_post_meta($meta_key, $meta_value, $unique = false)
364
-    {
365
-        if ($this->ID()) {
366
-            $this->save();
367
-        }
368
-        return add_post_meta($this->ID(), $meta_key, $meta_value, $unique);
369
-    }
370
-
371
-
372
-    /**
373
-     * Wrapper for delete_post_meta, http://codex.wordpress.org/Function_Reference/delete_post_meta
374
-     *
375
-     * @param mixed $meta_key
376
-     * @param mixed $meta_value
377
-     * @return boolean False for failure. True for success.
378
-     */
379
-    public function delete_post_meta($meta_key, $meta_value = '')
380
-    {
381
-        if (! $this->ID()) {
382
-            // there are obviously no postmetas for this if it's not saved
383
-            // so let's just report this as a success
384
-            return true;
385
-        }
386
-        return delete_post_meta($this->ID(), $meta_key, $meta_value);
387
-    }
388
-
389
-
390
-    /**
391
-     * Gets the URL for viewing this event on the front-end
392
-     *
393
-     * @return string
394
-     */
395
-    public function get_permalink()
396
-    {
397
-        return get_permalink($this->ID());
398
-    }
399
-
400
-
401
-    /**
402
-     * Gets all the term-taxonomies for this CPT
403
-     *
404
-     * @param array $query_params
405
-     * @return EE_Term_Taxonomy
406
-     */
407
-    public function term_taxonomies($query_params = array())
408
-    {
409
-        return $this->get_many_related('Term_Taxonomy', $query_params);
410
-    }
411
-
412
-
413
-    /**
414
-     * @return mixed
415
-     */
416
-    public function get_custom_post_statuses()
417
-    {
418
-        return $this->get_model()->get_custom_post_statuses();
419
-    }
420
-
421
-
422
-    /**
423
-     * @return mixed
424
-     */
425
-    public function get_all_post_statuses()
426
-    {
427
-        return $this->get_model()->get_status_array();
428
-    }
429
-
430
-
431
-    /**
432
-     * Don't serialize the WP Post. That's just duplicate data and we want to avoid recursion
433
-     *
434
-     * @return array
435
-     */
436
-    public function __sleep()
437
-    {
438
-        $properties_to_serialize = parent::__sleep();
439
-        $properties_to_serialize = array_diff($properties_to_serialize, array('_wp_post'));
440
-        return $properties_to_serialize;
441
-    }
17
+	/**
18
+	 * This is a property for holding cached feature images on CPT objects.  Cache's are set on the first
19
+	 * "feature_image()" method call.  Each key in the array corresponds to the requested size.
20
+	 *
21
+	 * @var array
22
+	 */
23
+	protected $_feature_image = array();
24
+
25
+	/**
26
+	 * @var WP_Post the WP_Post that corresponds with this CPT model object
27
+	 */
28
+	protected $_wp_post;
29
+
30
+
31
+	abstract public function wp_user();
32
+
33
+
34
+	/**
35
+	 * Returns the WP post associated with this CPT model object. If this CPT is saved, fetches it
36
+	 * from the DB. Otherwise, create an unsaved WP_POst object. Caches the post internally.
37
+	 *
38
+	 * @return WP_Post
39
+	 */
40
+	public function wp_post()
41
+	{
42
+		global $wpdb;
43
+		if (! $this->_wp_post instanceof WP_Post) {
44
+			if ($this->ID()) {
45
+				$this->_wp_post = get_post($this->ID());
46
+			} else {
47
+				$simulated_db_result = new stdClass();
48
+				foreach ($this->get_model()->field_settings(true) as $field_name => $field_obj) {
49
+					if ($this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name()
50
+						=== $wpdb->posts
51
+					) {
52
+						$column = $field_obj->get_table_column();
53
+
54
+						if ($field_obj instanceof EE_Datetime_Field) {
55
+							$value_on_model_obj = $this->get_DateTime_object($field_name);
56
+						} elseif ($field_obj->is_db_only_field()) {
57
+							$value_on_model_obj = $field_obj->get_default_value();
58
+						} else {
59
+							$value_on_model_obj = $this->get_raw($field_name);
60
+						}
61
+						$simulated_db_result->{$column} = $field_obj->prepare_for_use_in_db($value_on_model_obj);
62
+					}
63
+				}
64
+				$this->_wp_post = new WP_Post($simulated_db_result);
65
+			}
66
+			// and let's make retrieving the EE CPT object easy too
67
+			$classname = get_class($this);
68
+			if (! isset($this->_wp_post->{$classname})) {
69
+				$this->_wp_post->{$classname} = $this;
70
+			}
71
+		}
72
+		return $this->_wp_post;
73
+	}
74
+
75
+	/**
76
+	 * When fetching a new value for a post field that uses the global $post for rendering,
77
+	 * set the global $post temporarily to be this model object; and afterwards restore it
78
+	 *
79
+	 * @param string $fieldname
80
+	 * @param bool   $pretty
81
+	 * @param string $extra_cache_ref
82
+	 * @return mixed
83
+	 */
84
+	protected function _get_fresh_property($fieldname, $pretty = false, $extra_cache_ref = null)
85
+	{
86
+		global $post;
87
+
88
+		if ($pretty
89
+			&& (
90
+				! (
91
+					$post instanceof WP_Post
92
+					&& $post->ID
93
+				)
94
+				|| (int) $post->ID !== $this->ID()
95
+			)
96
+			&& $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field) {
97
+			$old_post = $post;
98
+			$post = $this->wp_post();
99
+			$return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref);
100
+			$post = $old_post;
101
+		} else {
102
+			$return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref);
103
+		}
104
+		return $return_value;
105
+	}
106
+
107
+	/**
108
+	 * Adds to the specified event category. If it category doesn't exist, creates it.
109
+	 *
110
+	 * @param string $category_name
111
+	 * @param string $category_description    optional
112
+	 * @param int    $parent_term_taxonomy_id optional
113
+	 * @return EE_Term_Taxonomy
114
+	 */
115
+	public function add_event_category($category_name, $category_description = null, $parent_term_taxonomy_id = null)
116
+	{
117
+		return $this->get_model()->add_event_category(
118
+			$this,
119
+			$category_name,
120
+			$category_description,
121
+			$parent_term_taxonomy_id
122
+		);
123
+	}
124
+
125
+
126
+	/**
127
+	 * Removes the event category by specified name from being related ot this event
128
+	 *
129
+	 * @param string $category_name
130
+	 * @return bool
131
+	 */
132
+	public function remove_event_category($category_name)
133
+	{
134
+		return $this->get_model()->remove_event_category($this, $category_name);
135
+	}
136
+
137
+
138
+	/**
139
+	 * Removes the relation to the specified term taxonomy, and maintains the
140
+	 * data integrity of the term taxonomy provided
141
+	 *
142
+	 * @param EE_Term_Taxonomy $term_taxonomy
143
+	 * @return EE_Base_Class the relation was removed from
144
+	 */
145
+	public function remove_relation_to_term_taxonomy($term_taxonomy)
146
+	{
147
+		if (! $term_taxonomy) {
148
+			EE_Error::add_error(
149
+				sprintf(
150
+					__(
151
+						"No Term_Taxonomy provided which to remove from model object of type %s and id %d",
152
+						"event_espresso"
153
+					),
154
+					get_class($this),
155
+					$this->ID()
156
+				),
157
+				__FILE__,
158
+				__FUNCTION__,
159
+				__LINE__
160
+			);
161
+			return null;
162
+		}
163
+		$term_taxonomy->set_count($term_taxonomy->count() - 1);
164
+		$term_taxonomy->save();
165
+		return $this->_remove_relation_to($term_taxonomy, 'Term_Taxonomy');
166
+	}
167
+
168
+
169
+	/**
170
+	 * The main purpose of this method is to return the post type for the model object
171
+	 *
172
+	 * @access public
173
+	 * @return string
174
+	 */
175
+	public function post_type()
176
+	{
177
+		return $this->get_model()->post_type();
178
+	}
179
+
180
+
181
+	/**
182
+	 * The main purpose of this method is to return the parent for the model object
183
+	 *
184
+	 * @access public
185
+	 * @return int
186
+	 */
187
+	public function parent()
188
+	{
189
+		return $this->get('parent');
190
+	}
191
+
192
+
193
+	/**
194
+	 * return the _status property
195
+	 *
196
+	 * @return string
197
+	 */
198
+	public function status()
199
+	{
200
+		return $this->get('status');
201
+	}
202
+
203
+
204
+	/**
205
+	 * @param string $status
206
+	 */
207
+	public function set_status($status)
208
+	{
209
+		$this->set('status', $status);
210
+	}
211
+
212
+
213
+	/**
214
+	 * This calls the equivalent model method for retrieving the feature image which in turn is a wrapper for
215
+	 * WordPress' get_the_post_thumbnail() function.
216
+	 *
217
+	 * @link   http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
218
+	 * @access protected
219
+	 * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array
220
+	 *                           representing width and height in pixels (i.e. array(32,32) ).
221
+	 * @param string|array $attr Optional. Query string or array of attributes.
222
+	 * @return string HTML image element
223
+	 */
224
+	protected function _get_feature_image($size, $attr)
225
+	{
226
+		// first let's see if we already have the _feature_image property set AND if it has a cached element on it FOR the given size
227
+		$attr_key = is_array($attr) ? implode('_', $attr) : $attr;
228
+		$cache_key = is_array($size) ? implode('_', $size) . $attr_key : $size . $attr_key;
229
+		$this->_feature_image[ $cache_key ] = isset($this->_feature_image[ $cache_key ])
230
+			? $this->_feature_image[ $cache_key ] : $this->get_model()->get_feature_image($this->ID(), $size, $attr);
231
+		return $this->_feature_image[ $cache_key ];
232
+	}
233
+
234
+
235
+	/**
236
+	 * See _get_feature_image. Returns the HTML to display a featured image
237
+	 *
238
+	 * @param string       $size
239
+	 * @param string|array $attr
240
+	 * @return string of html
241
+	 */
242
+	public function feature_image($size = 'thumbnail', $attr = '')
243
+	{
244
+		return $this->_get_feature_image($size, $attr);
245
+	}
246
+
247
+
248
+	/**
249
+	 * This uses the wp "wp_get_attachment_image_src()" function to return the feature image for the current class
250
+	 * using the given size params.
251
+	 *
252
+	 * @param  string|array $size can either be a string: 'thumbnail', 'medium', 'large', 'full' OR 2-item array
253
+	 *                            representing width and height in pixels eg. array(32,32).
254
+	 * @return string|boolean          the url of the image or false if not found
255
+	 */
256
+	public function feature_image_url($size = 'thumbnail')
257
+	{
258
+		$attachment = wp_get_attachment_image_src(get_post_thumbnail_id($this->ID()), $size);
259
+		return ! empty($attachment) ? $attachment[0] : false;
260
+	}
261
+
262
+
263
+	/**
264
+	 * This is a method for restoring this_obj using details from the given $revision_id
265
+	 *
266
+	 * @param int   $revision_id       ID of the revision we're getting data from
267
+	 * @param array $related_obj_names if included this will be used to restore for related obj
268
+	 *                                 if not included then we just do restore on the meta.
269
+	 *                                 We will accept an array of related_obj_names for restoration here.
270
+	 * @param array $where_query       You can optionally include an array of key=>value pairs
271
+	 *                                 that allow you to further constrict the relation to being added.
272
+	 *                                 However, keep in mind that the columns (keys) given
273
+	 *                                 must match a column on the JOIN table and currently
274
+	 *                                 only the HABTM models accept these additional conditions.
275
+	 *                                 Also remember that if an exact match isn't found for these extra cols/val pairs,
276
+	 *                                 then a NEW row is created in the join table.
277
+	 *                                 This array is INDEXED by RELATED OBJ NAME (so it corresponds with the obj_names
278
+	 *                                 sent);
279
+	 * @return void
280
+	 */
281
+	public function restore_revision($revision_id, $related_obj_names = array(), $where_query = array())
282
+	{
283
+		// get revision object
284
+		$revision_obj = $this->get_model()->get_one_by_ID($revision_id);
285
+		if ($revision_obj instanceof EE_CPT_Base) {
286
+			// no related_obj_name so we assume we're saving a revision on this object.
287
+			if (empty($related_obj_names)) {
288
+				$fields = $this->get_model()->get_meta_table_fields();
289
+				foreach ($fields as $field) {
290
+					$this->set($field, $revision_obj->get($field));
291
+				}
292
+				$this->save();
293
+			}
294
+			$related_obj_names = (array) $related_obj_names;
295
+			foreach ($related_obj_names as $related_name) {
296
+				// related_obj_name so we're saving a revision on an object related to this object
297
+				// do we have $where_query params for this related object?  If we do then we include that.
298
+				$cols_n_values = isset($where_query[ $related_name ]) ? $where_query[ $related_name ] : array();
299
+				$where_params = ! empty($cols_n_values) ? array($cols_n_values) : array();
300
+				$related_objs = $this->get_many_related($related_name, $where_params);
301
+				$revision_related_objs = $revision_obj->get_many_related($related_name, $where_params);
302
+				// load helper
303
+				// remove related objs from this object that are not in revision
304
+				// array_diff *should* work cause I think objects are indexed by ID?
305
+				$related_to_remove = EEH_Array::object_array_diff($related_objs, $revision_related_objs);
306
+				foreach ($related_to_remove as $rr) {
307
+					$this->_remove_relation_to($rr, $related_name, $cols_n_values);
308
+				}
309
+				// add all related objs attached to revision to this object
310
+				foreach ($revision_related_objs as $r_obj) {
311
+					$this->_add_relation_to($r_obj, $related_name, $cols_n_values);
312
+				}
313
+			}
314
+		}
315
+	}
316
+
317
+
318
+	/**
319
+	 * Wrapper for get_post_meta, http://codex.wordpress.org/Function_Reference/get_post_meta
320
+	 *
321
+	 * @param string  $meta_key
322
+	 * @param boolean $single
323
+	 * @return mixed <ul><li>If only $id is set it will return all meta values in an associative array.</li>
324
+	 * <li>If $single is set to false, or left blank, the function returns an array containing all values of the
325
+	 * specified key.</li>
326
+	 * <li>If $single is set to true, the function returns the first value of the specified key (not in an
327
+	 * array</li></ul>
328
+	 */
329
+	public function get_post_meta($meta_key = null, $single = false)
330
+	{
331
+		return get_post_meta($this->ID(), $meta_key, $single);
332
+	}
333
+
334
+
335
+	/**
336
+	 * Wrapper for update_post_meta, http://codex.wordpress.org/Function_Reference/update_post_meta
337
+	 *
338
+	 * @param string $meta_key
339
+	 * @param mixed  $meta_value
340
+	 * @param mixed  $prev_value
341
+	 * @return mixed Returns meta_id if the meta doesn't exist, otherwise returns true on success and false on failure.
342
+	 *               NOTE: If the meta_value passed to this function is the same as the value that is already in the
343
+	 *               database, this function returns false.
344
+	 */
345
+	public function update_post_meta($meta_key, $meta_value, $prev_value = null)
346
+	{
347
+		if (! $this->ID()) {
348
+			$this->save();
349
+		}
350
+		return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value);
351
+	}
352
+
353
+
354
+	/**
355
+	 * Wrapper for add_post_meta, http://codex.wordpress.org/Function_Reference/add_post_meta
356
+	 *
357
+	 * @param mixed $meta_key
358
+	 * @param mixed $meta_value
359
+	 * @param bool  $unique . If postmeta for this $meta_key already exists, whether to add an additional item or not
360
+	 * @return boolean Boolean true, except if the $unique argument was set to true and a custom field with the given
361
+	 *                 key already exists, in which case false is returned.
362
+	 */
363
+	public function add_post_meta($meta_key, $meta_value, $unique = false)
364
+	{
365
+		if ($this->ID()) {
366
+			$this->save();
367
+		}
368
+		return add_post_meta($this->ID(), $meta_key, $meta_value, $unique);
369
+	}
370
+
371
+
372
+	/**
373
+	 * Wrapper for delete_post_meta, http://codex.wordpress.org/Function_Reference/delete_post_meta
374
+	 *
375
+	 * @param mixed $meta_key
376
+	 * @param mixed $meta_value
377
+	 * @return boolean False for failure. True for success.
378
+	 */
379
+	public function delete_post_meta($meta_key, $meta_value = '')
380
+	{
381
+		if (! $this->ID()) {
382
+			// there are obviously no postmetas for this if it's not saved
383
+			// so let's just report this as a success
384
+			return true;
385
+		}
386
+		return delete_post_meta($this->ID(), $meta_key, $meta_value);
387
+	}
388
+
389
+
390
+	/**
391
+	 * Gets the URL for viewing this event on the front-end
392
+	 *
393
+	 * @return string
394
+	 */
395
+	public function get_permalink()
396
+	{
397
+		return get_permalink($this->ID());
398
+	}
399
+
400
+
401
+	/**
402
+	 * Gets all the term-taxonomies for this CPT
403
+	 *
404
+	 * @param array $query_params
405
+	 * @return EE_Term_Taxonomy
406
+	 */
407
+	public function term_taxonomies($query_params = array())
408
+	{
409
+		return $this->get_many_related('Term_Taxonomy', $query_params);
410
+	}
411
+
412
+
413
+	/**
414
+	 * @return mixed
415
+	 */
416
+	public function get_custom_post_statuses()
417
+	{
418
+		return $this->get_model()->get_custom_post_statuses();
419
+	}
420
+
421
+
422
+	/**
423
+	 * @return mixed
424
+	 */
425
+	public function get_all_post_statuses()
426
+	{
427
+		return $this->get_model()->get_status_array();
428
+	}
429
+
430
+
431
+	/**
432
+	 * Don't serialize the WP Post. That's just duplicate data and we want to avoid recursion
433
+	 *
434
+	 * @return array
435
+	 */
436
+	public function __sleep()
437
+	{
438
+		$properties_to_serialize = parent::__sleep();
439
+		$properties_to_serialize = array_diff($properties_to_serialize, array('_wp_post'));
440
+		return $properties_to_serialize;
441
+	}
442 442
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
     public function wp_post()
41 41
     {
42 42
         global $wpdb;
43
-        if (! $this->_wp_post instanceof WP_Post) {
43
+        if ( ! $this->_wp_post instanceof WP_Post) {
44 44
             if ($this->ID()) {
45 45
                 $this->_wp_post = get_post($this->ID());
46 46
             } else {
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
             }
66 66
             // and let's make retrieving the EE CPT object easy too
67 67
             $classname = get_class($this);
68
-            if (! isset($this->_wp_post->{$classname})) {
68
+            if ( ! isset($this->_wp_post->{$classname})) {
69 69
                 $this->_wp_post->{$classname} = $this;
70 70
             }
71 71
         }
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
      */
145 145
     public function remove_relation_to_term_taxonomy($term_taxonomy)
146 146
     {
147
-        if (! $term_taxonomy) {
147
+        if ( ! $term_taxonomy) {
148 148
             EE_Error::add_error(
149 149
                 sprintf(
150 150
                     __(
@@ -225,10 +225,10 @@  discard block
 block discarded – undo
225 225
     {
226 226
         // first let's see if we already have the _feature_image property set AND if it has a cached element on it FOR the given size
227 227
         $attr_key = is_array($attr) ? implode('_', $attr) : $attr;
228
-        $cache_key = is_array($size) ? implode('_', $size) . $attr_key : $size . $attr_key;
229
-        $this->_feature_image[ $cache_key ] = isset($this->_feature_image[ $cache_key ])
230
-            ? $this->_feature_image[ $cache_key ] : $this->get_model()->get_feature_image($this->ID(), $size, $attr);
231
-        return $this->_feature_image[ $cache_key ];
228
+        $cache_key = is_array($size) ? implode('_', $size).$attr_key : $size.$attr_key;
229
+        $this->_feature_image[$cache_key] = isset($this->_feature_image[$cache_key])
230
+            ? $this->_feature_image[$cache_key] : $this->get_model()->get_feature_image($this->ID(), $size, $attr);
231
+        return $this->_feature_image[$cache_key];
232 232
     }
233 233
 
234 234
 
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
             foreach ($related_obj_names as $related_name) {
296 296
                 // related_obj_name so we're saving a revision on an object related to this object
297 297
                 // do we have $where_query params for this related object?  If we do then we include that.
298
-                $cols_n_values = isset($where_query[ $related_name ]) ? $where_query[ $related_name ] : array();
298
+                $cols_n_values = isset($where_query[$related_name]) ? $where_query[$related_name] : array();
299 299
                 $where_params = ! empty($cols_n_values) ? array($cols_n_values) : array();
300 300
                 $related_objs = $this->get_many_related($related_name, $where_params);
301 301
                 $revision_related_objs = $revision_obj->get_many_related($related_name, $where_params);
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
      */
345 345
     public function update_post_meta($meta_key, $meta_value, $prev_value = null)
346 346
     {
347
-        if (! $this->ID()) {
347
+        if ( ! $this->ID()) {
348 348
             $this->save();
349 349
         }
350 350
         return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value);
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
      */
379 379
     public function delete_post_meta($meta_key, $meta_value = '')
380 380
     {
381
-        if (! $this->ID()) {
381
+        if ( ! $this->ID()) {
382 382
             // there are obviously no postmetas for this if it's not saved
383 383
             // so let's just report this as a success
384 384
             return true;
Please login to merge, or discard this patch.
core/db_classes/EE_Ticket_Price.class.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -11,25 +11,25 @@
 block discarded – undo
11 11
 class EE_Ticket_Price extends EE_Base_Class
12 12
 {
13 13
 
14
-    /**
15
-     * @param array  $props_n_values
16
-     * @param string $timezone
17
-     * @return EE_Ticket_Price|mixed
18
-     */
19
-    public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array())
20
-    {
21
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
22
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
23
-    }
14
+	/**
15
+	 * @param array  $props_n_values
16
+	 * @param string $timezone
17
+	 * @return EE_Ticket_Price|mixed
18
+	 */
19
+	public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array())
20
+	{
21
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
22
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
23
+	}
24 24
 
25 25
 
26
-    /**
27
-     * @param array  $props_n_values
28
-     * @param string $timezone
29
-     * @return EE_Ticket_Price
30
-     */
31
-    public static function new_instance_from_db($props_n_values = array(), $timezone = '')
32
-    {
33
-        return new self($props_n_values, true, $timezone);
34
-    }
26
+	/**
27
+	 * @param array  $props_n_values
28
+	 * @param string $timezone
29
+	 * @return EE_Ticket_Price
30
+	 */
31
+	public static function new_instance_from_db($props_n_values = array(), $timezone = '')
32
+	{
33
+		return new self($props_n_values, true, $timezone);
34
+	}
35 35
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Ticket_Template.class.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -12,25 +12,25 @@
 block discarded – undo
12 12
 class EE_Ticket_Template extends EE_Base_Class
13 13
 {
14 14
 
15
-    /**
16
-     * @param array  $props_n_values
17
-     * @param string $timezone
18
-     * @return EE_Ticket_Template|mixed
19
-     */
20
-    public static function new_instance($props_n_values = array(), $timezone = '')
21
-    {
22
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone);
23
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone);
24
-    }
15
+	/**
16
+	 * @param array  $props_n_values
17
+	 * @param string $timezone
18
+	 * @return EE_Ticket_Template|mixed
19
+	 */
20
+	public static function new_instance($props_n_values = array(), $timezone = '')
21
+	{
22
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone);
23
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone);
24
+	}
25 25
 
26 26
 
27
-    /**
28
-     * @param array  $props_n_values
29
-     * @param string $timezone
30
-     * @return EE_Ticket_Template
31
-     */
32
-    public static function new_instance_from_db($props_n_values = array(), $timezone = '')
33
-    {
34
-        return new self($props_n_values, true, $timezone);
35
-    }
27
+	/**
28
+	 * @param array  $props_n_values
29
+	 * @param string $timezone
30
+	 * @return EE_Ticket_Template
31
+	 */
32
+	public static function new_instance_from_db($props_n_values = array(), $timezone = '')
33
+	{
34
+		return new self($props_n_values, true, $timezone);
35
+	}
36 36
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Extra_Meta.class.php 1 patch
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -10,115 +10,115 @@
 block discarded – undo
10 10
 class EE_Extra_Meta extends EE_Base_Class
11 11
 {
12 12
 
13
-    /**
14
-     * @param array $props_n_values
15
-     * @return EE_Extra_Meta|mixed
16
-     */
17
-    public static function new_instance($props_n_values = array())
18
-    {
19
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
20
-        return $has_object ? $has_object : new self($props_n_values);
21
-    }
22
-
23
-
24
-    /**
25
-     * @param array $props_n_values
26
-     * @return EE_Extra_Meta
27
-     */
28
-    public static function new_instance_from_db($props_n_values = array())
29
-    {
30
-        return new self($props_n_values, true);
31
-    }
32
-
33
-
34
-    /**
35
-     * Gets FK_ID
36
-     *
37
-     * @return int
38
-     */
39
-    public function FK_ID()
40
-    {
41
-        return $this->get('FK_ID');
42
-    }
43
-
44
-
45
-    /**
46
-     * Sets FK_ID
47
-     *
48
-     * @param int $FK_ID
49
-     * @return boolean
50
-     */
51
-    public function set_FK_ID($FK_ID)
52
-    {
53
-        $this->set('FK_ID', $FK_ID);
54
-    }
55
-
56
-
57
-    /**
58
-     * Gets model
59
-     *
60
-     * @return string
61
-     */
62
-    public function model()
63
-    {
64
-        return $this->get('EXM_model');
65
-    }
66
-
67
-
68
-    /**
69
-     * Sets model
70
-     *
71
-     * @param string $model
72
-     * @return boolean
73
-     */
74
-    public function set_model($model)
75
-    {
76
-        $this->set('EXM_model', $model);
77
-    }
78
-
79
-
80
-    /**
81
-     * Gets key
82
-     *
83
-     * @return string
84
-     */
85
-    public function key()
86
-    {
87
-        return $this->get('EXM_key');
88
-    }
89
-
90
-
91
-    /**
92
-     * Sets key
93
-     *
94
-     * @param string $key
95
-     * @return boolean
96
-     */
97
-    public function set_key($key)
98
-    {
99
-        $this->set('EXM_key', $key);
100
-    }
101
-
102
-
103
-    /**
104
-     * Gets value
105
-     *
106
-     * @return string
107
-     */
108
-    public function value()
109
-    {
110
-        return $this->get('EXM_value');
111
-    }
112
-
113
-
114
-    /**
115
-     * Sets value
116
-     *
117
-     * @param string $value
118
-     * @return boolean
119
-     */
120
-    public function set_value($value)
121
-    {
122
-        $this->set('EXM_value', $value);
123
-    }
13
+	/**
14
+	 * @param array $props_n_values
15
+	 * @return EE_Extra_Meta|mixed
16
+	 */
17
+	public static function new_instance($props_n_values = array())
18
+	{
19
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
20
+		return $has_object ? $has_object : new self($props_n_values);
21
+	}
22
+
23
+
24
+	/**
25
+	 * @param array $props_n_values
26
+	 * @return EE_Extra_Meta
27
+	 */
28
+	public static function new_instance_from_db($props_n_values = array())
29
+	{
30
+		return new self($props_n_values, true);
31
+	}
32
+
33
+
34
+	/**
35
+	 * Gets FK_ID
36
+	 *
37
+	 * @return int
38
+	 */
39
+	public function FK_ID()
40
+	{
41
+		return $this->get('FK_ID');
42
+	}
43
+
44
+
45
+	/**
46
+	 * Sets FK_ID
47
+	 *
48
+	 * @param int $FK_ID
49
+	 * @return boolean
50
+	 */
51
+	public function set_FK_ID($FK_ID)
52
+	{
53
+		$this->set('FK_ID', $FK_ID);
54
+	}
55
+
56
+
57
+	/**
58
+	 * Gets model
59
+	 *
60
+	 * @return string
61
+	 */
62
+	public function model()
63
+	{
64
+		return $this->get('EXM_model');
65
+	}
66
+
67
+
68
+	/**
69
+	 * Sets model
70
+	 *
71
+	 * @param string $model
72
+	 * @return boolean
73
+	 */
74
+	public function set_model($model)
75
+	{
76
+		$this->set('EXM_model', $model);
77
+	}
78
+
79
+
80
+	/**
81
+	 * Gets key
82
+	 *
83
+	 * @return string
84
+	 */
85
+	public function key()
86
+	{
87
+		return $this->get('EXM_key');
88
+	}
89
+
90
+
91
+	/**
92
+	 * Sets key
93
+	 *
94
+	 * @param string $key
95
+	 * @return boolean
96
+	 */
97
+	public function set_key($key)
98
+	{
99
+		$this->set('EXM_key', $key);
100
+	}
101
+
102
+
103
+	/**
104
+	 * Gets value
105
+	 *
106
+	 * @return string
107
+	 */
108
+	public function value()
109
+	{
110
+		return $this->get('EXM_value');
111
+	}
112
+
113
+
114
+	/**
115
+	 * Sets value
116
+	 *
117
+	 * @param string $value
118
+	 * @return boolean
119
+	 */
120
+	public function set_value($value)
121
+	{
122
+		$this->set('EXM_value', $value);
123
+	}
124 124
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Post_Meta.class.php 1 patch
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -10,112 +10,112 @@
 block discarded – undo
10 10
 class EE_Post_Meta extends EE_Base_Class
11 11
 {
12 12
 
13
-    /**
14
-     * @param array $props_n_values
15
-     * @return EE_Post_Meta|mixed
16
-     */
17
-    public static function new_instance($props_n_values = array())
18
-    {
19
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
20
-        return $has_object ? $has_object : new self($props_n_values);
21
-    }
22
-
23
-
24
-    /**
25
-     * @param array $props_n_values
26
-     * @return EE_Post_Meta
27
-     */
28
-    public static function new_instance_from_db($props_n_values = array())
29
-    {
30
-        return new self($props_n_values, true);
31
-    }
32
-
33
-
34
-    /**
35
-     * Gets meta_id
36
-     *
37
-     * @return int
38
-     */
39
-    public function meta_id()
40
-    {
41
-        return $this->get('meta_id');
42
-    }
43
-
44
-
45
-    /**
46
-     * Sets meta_id
47
-     *
48
-     * @param int $meta_id
49
-     * @return boolean
50
-     */
51
-    public function set_meta_id($meta_id)
52
-    {
53
-        return $this->set('meta_id', $meta_id);
54
-    }
55
-
56
-    /**
57
-     * Gets post_id
58
-     *
59
-     * @return int
60
-     */
61
-    public function post_id()
62
-    {
63
-        return $this->get('post_id');
64
-    }
65
-
66
-
67
-    /**
68
-     * Sets post_id
69
-     *
70
-     * @param int $post_id
71
-     * @return boolean
72
-     */
73
-    public function set_post_id($post_id)
74
-    {
75
-        return $this->set('post_id', $post_id);
76
-    }
77
-
78
-    /**
79
-     * Gets meta_key
80
-     *
81
-     * @return string
82
-     */
83
-    public function meta_key()
84
-    {
85
-        return $this->get('meta_key');
86
-    }
87
-
88
-
89
-    /**
90
-     * Sets meta_key
91
-     *
92
-     * @param string $meta_key
93
-     * @return boolean
94
-     */
95
-    public function set_meta_key($meta_key)
96
-    {
97
-        return $this->set('meta_key', $meta_key);
98
-    }
99
-
100
-    /**
101
-     * Gets meta_value
102
-     *
103
-     * @return mixed
104
-     */
105
-    public function meta_value()
106
-    {
107
-        return $this->get('meta_value');
108
-    }
109
-
110
-
111
-    /**
112
-     * Sets meta_value
113
-     *
114
-     * @param mixed $meta_value
115
-     * @return boolean
116
-     */
117
-    public function set_meta_value($meta_value)
118
-    {
119
-        return $this->set('meta_value', $meta_value);
120
-    }
13
+	/**
14
+	 * @param array $props_n_values
15
+	 * @return EE_Post_Meta|mixed
16
+	 */
17
+	public static function new_instance($props_n_values = array())
18
+	{
19
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
20
+		return $has_object ? $has_object : new self($props_n_values);
21
+	}
22
+
23
+
24
+	/**
25
+	 * @param array $props_n_values
26
+	 * @return EE_Post_Meta
27
+	 */
28
+	public static function new_instance_from_db($props_n_values = array())
29
+	{
30
+		return new self($props_n_values, true);
31
+	}
32
+
33
+
34
+	/**
35
+	 * Gets meta_id
36
+	 *
37
+	 * @return int
38
+	 */
39
+	public function meta_id()
40
+	{
41
+		return $this->get('meta_id');
42
+	}
43
+
44
+
45
+	/**
46
+	 * Sets meta_id
47
+	 *
48
+	 * @param int $meta_id
49
+	 * @return boolean
50
+	 */
51
+	public function set_meta_id($meta_id)
52
+	{
53
+		return $this->set('meta_id', $meta_id);
54
+	}
55
+
56
+	/**
57
+	 * Gets post_id
58
+	 *
59
+	 * @return int
60
+	 */
61
+	public function post_id()
62
+	{
63
+		return $this->get('post_id');
64
+	}
65
+
66
+
67
+	/**
68
+	 * Sets post_id
69
+	 *
70
+	 * @param int $post_id
71
+	 * @return boolean
72
+	 */
73
+	public function set_post_id($post_id)
74
+	{
75
+		return $this->set('post_id', $post_id);
76
+	}
77
+
78
+	/**
79
+	 * Gets meta_key
80
+	 *
81
+	 * @return string
82
+	 */
83
+	public function meta_key()
84
+	{
85
+		return $this->get('meta_key');
86
+	}
87
+
88
+
89
+	/**
90
+	 * Sets meta_key
91
+	 *
92
+	 * @param string $meta_key
93
+	 * @return boolean
94
+	 */
95
+	public function set_meta_key($meta_key)
96
+	{
97
+		return $this->set('meta_key', $meta_key);
98
+	}
99
+
100
+	/**
101
+	 * Gets meta_value
102
+	 *
103
+	 * @return mixed
104
+	 */
105
+	public function meta_value()
106
+	{
107
+		return $this->get('meta_value');
108
+	}
109
+
110
+
111
+	/**
112
+	 * Sets meta_value
113
+	 *
114
+	 * @param mixed $meta_value
115
+	 * @return boolean
116
+	 */
117
+	public function set_meta_value($meta_value)
118
+	{
119
+		return $this->set('meta_value', $meta_value);
120
+	}
121 121
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Question.class.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
      */
336 336
     public function options($notDeletedOptionsOnly = true, $selected_value_to_always_include = null)
337 337
     {
338
-        if (! $this->ID()) {
338
+        if ( ! $this->ID()) {
339 339
             return array();
340 340
         }
341 341
         $query_params = array();
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
             ),
510 510
             $input_constructor_args
511 511
         );
512
-        if (! $answer instanceof EE_Answer && $registration instanceof EE_Registration) {
512
+        if ( ! $answer instanceof EE_Answer && $registration instanceof EE_Registration) {
513 513
             $answer = EEM_Answer::instance()->get_registration_question_answer_object($registration, $this->ID());
514 514
         }
515 515
         // has this question been answered ?
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
                     $this,
648 648
                     $input_constructor_args
649 649
                 );
650
-                if (! $default_input) {
650
+                if ( ! $default_input) {
651 651
                     $default_input = new EE_Text_Input($input_constructor_args);
652 652
                 }
653 653
                 $result = $default_input;
Please login to merge, or discard this patch.
Indentation   +661 added lines, -661 removed lines patch added patch discarded remove patch
@@ -14,665 +14,665 @@
 block discarded – undo
14 14
 class EE_Question extends EE_Soft_Delete_Base_Class implements EEI_Duplicatable
15 15
 {
16 16
 
17
-    /**
18
-     *
19
-     * @param array  $props_n_values          incoming values
20
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
21
-     *                                        used.)
22
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
23
-     *                                        date_format and the second value is the time format
24
-     * @return EE_Question
25
-     */
26
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
27
-    {
28
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
29
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
30
-    }
31
-
32
-
33
-    /**
34
-     * @param array  $props_n_values  incoming values from the database
35
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
36
-     *                                the website will be used.
37
-     * @return EE_Question
38
-     */
39
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
40
-    {
41
-        return new self($props_n_values, true, $timezone);
42
-    }
43
-
44
-
45
-    /**
46
-     *        Set    Question display text
47
-     *
48
-     * @access        public
49
-     * @param string $QST_display_text
50
-     */
51
-    public function set_display_text($QST_display_text = '')
52
-    {
53
-        $this->set('QST_display_text', $QST_display_text);
54
-    }
55
-
56
-
57
-    /**
58
-     *        Set    Question admin text
59
-     *
60
-     * @access        public
61
-     * @param        string $QST_admin_label
62
-     */
63
-    public function set_admin_label($QST_admin_label = '')
64
-    {
65
-        $this->set('QST_admin_label', $QST_admin_label);
66
-    }
67
-
68
-
69
-    /**
70
-     *        Set    system name
71
-     *
72
-     * @access        public
73
-     * @param        mixed $QST_system
74
-     */
75
-    public function set_system_ID($QST_system = '')
76
-    {
77
-        $this->set('QST_system', $QST_system);
78
-    }
79
-
80
-
81
-    /**
82
-     *        Set    question's type
83
-     *
84
-     * @access        public
85
-     * @param        string $QST_type
86
-     */
87
-    public function set_question_type($QST_type = '')
88
-    {
89
-        $this->set('QST_type', $QST_type);
90
-    }
91
-
92
-
93
-    /**
94
-     *        Sets whether this question must be answered when presented in a form
95
-     *
96
-     * @access        public
97
-     * @param        bool $QST_required
98
-     */
99
-    public function set_required($QST_required = false)
100
-    {
101
-        $this->set('QST_required', $QST_required);
102
-    }
103
-
104
-
105
-    /**
106
-     *        Set    Question display text
107
-     *
108
-     * @access        public
109
-     * @param        string $QST_required_text
110
-     */
111
-    public function set_required_text($QST_required_text = '')
112
-    {
113
-        $this->set('QST_required_text', $QST_required_text);
114
-    }
115
-
116
-
117
-    /**
118
-     *        Sets the order of this question when placed in a sequence of questions
119
-     *
120
-     * @access        public
121
-     * @param        int $QST_order
122
-     */
123
-    public function set_order($QST_order = 0)
124
-    {
125
-        $this->set('QST_order', $QST_order);
126
-    }
127
-
128
-
129
-    /**
130
-     *        Sets whether the question is admin-only
131
-     *
132
-     * @access        public
133
-     * @param        bool $QST_admin_only
134
-     */
135
-    public function set_admin_only($QST_admin_only = false)
136
-    {
137
-        $this->set('QST_admin_only', $QST_admin_only);
138
-    }
139
-
140
-
141
-    /**
142
-     *        Sets the wordpress user ID on the question
143
-     *
144
-     * @access        public
145
-     * @param        int $QST_wp_user
146
-     */
147
-    public function set_wp_user($QST_wp_user = 1)
148
-    {
149
-        $this->set('QST_wp_user', $QST_wp_user);
150
-    }
151
-
152
-
153
-    /**
154
-     *        Sets whether the question has been deleted
155
-     *        (we use this boolean instead of actually
156
-     *        deleting it because when users delete this question
157
-     *        they really want to remove the question from future
158
-     *        forms, BUT keep their old answers which depend
159
-     *        on this record actually existing.
160
-     *
161
-     * @access        public
162
-     * @param    bool $QST_deleted
163
-     */
164
-    public function set_deleted($QST_deleted = false)
165
-    {
166
-        $this->set('QST_deleted', $QST_deleted);
167
-    }
168
-
169
-
170
-    /**
171
-     * returns the text for displaying the question to users
172
-     *
173
-     * @access public
174
-     * @return string
175
-     */
176
-    public function display_text()
177
-    {
178
-        return $this->get('QST_display_text');
179
-    }
180
-
181
-
182
-    /**
183
-     * returns the text for the administrative label
184
-     *
185
-     * @access public
186
-     * @return string
187
-     */
188
-    public function admin_label()
189
-    {
190
-        return $this->get('QST_admin_label');
191
-    }
192
-
193
-
194
-    /**
195
-     * returns the attendee column name for this question
196
-     *
197
-     * @access public
198
-     * @return string
199
-     */
200
-    public function system_ID()
201
-    {
202
-        return $this->get('QST_system');
203
-    }
204
-
205
-
206
-    /**
207
-     * returns either a string of 'text', 'textfield', etc.
208
-     *
209
-     * @access public
210
-     * @return boolean
211
-     */
212
-    public function required()
213
-    {
214
-        return $this->get('QST_required');
215
-    }
216
-
217
-
218
-    /**
219
-     * returns the text which should be displayed when a user
220
-     * doesn't answer this question in a form
221
-     *
222
-     * @access public
223
-     * @return string
224
-     */
225
-    public function required_text()
226
-    {
227
-        return $this->get('QST_required_text');
228
-    }
229
-
230
-
231
-    /**
232
-     * returns the type of this question
233
-     *
234
-     * @access public
235
-     * @return string
236
-     */
237
-    public function type()
238
-    {
239
-        return $this->get('QST_type');
240
-    }
241
-
242
-
243
-    /**
244
-     * returns an integer showing where this question should
245
-     * be placed in a sequence of questions
246
-     *
247
-     * @access public
248
-     * @return int
249
-     */
250
-    public function order()
251
-    {
252
-        return $this->get('QST_order');
253
-    }
254
-
255
-
256
-    /**
257
-     * returns whether this question should only appears to admins,
258
-     * or to everyone
259
-     *
260
-     * @access public
261
-     * @return boolean
262
-     */
263
-    public function admin_only()
264
-    {
265
-        return $this->get('QST_admin_only');
266
-    }
267
-
268
-
269
-    /**
270
-     * returns the id the wordpress user who created this question
271
-     *
272
-     * @access public
273
-     * @return int
274
-     */
275
-    public function wp_user()
276
-    {
277
-        return $this->get('QST_wp_user');
278
-    }
279
-
280
-
281
-    /**
282
-     * returns whether this question has been marked as 'deleted'
283
-     *
284
-     * @access public
285
-     * @return boolean
286
-     */
287
-    public function deleted()
288
-    {
289
-        return $this->get('QST_deleted');
290
-    }
291
-
292
-
293
-    /**
294
-     * Gets an array of related EE_Answer  to this EE_Question
295
-     *
296
-     * @return EE_Answer[]
297
-     */
298
-    public function answers()
299
-    {
300
-        return $this->get_many_related('Answer');
301
-    }
302
-
303
-
304
-    /**
305
-     * Boolean check for if there are answers on this question in th db
306
-     *
307
-     * @return boolean true = has answers, false = no answers.
308
-     */
309
-    public function has_answers()
310
-    {
311
-        return $this->count_related('Answer') > 0 ? true : false;
312
-    }
313
-
314
-
315
-    /**
316
-     * gets an array of EE_Question_Group which relate to this question
317
-     *
318
-     * @return EE_Question_Group[]
319
-     */
320
-    public function question_groups()
321
-    {
322
-        return $this->get_many_related('Question_Group');
323
-    }
324
-
325
-
326
-    /**
327
-     * Returns all the options for this question. By default, it returns only the not-yet-deleted ones.
328
-     *
329
-     * @param boolean      $notDeletedOptionsOnly            1
330
-     *                                                       whether to return ALL options, or only the ones which have
331
-     *                                                       not yet been deleleted
332
-     * @param string|array $selected_value_to_always_include , when retrieving options to an ANSWERED question,
333
-     *                                                       we want to usually only show non-deleted options AND the
334
-     *                                                       value that was selected for the answer, whether it was
335
-     *                                                       trashed or not.
336
-     * @return EE_Question_Option[]
337
-     */
338
-    public function options($notDeletedOptionsOnly = true, $selected_value_to_always_include = null)
339
-    {
340
-        if (! $this->ID()) {
341
-            return array();
342
-        }
343
-        $query_params = array();
344
-        if ($selected_value_to_always_include) {
345
-            if (is_array($selected_value_to_always_include)) {
346
-                $query_params[0]['OR*options-query']['QSO_value'] = array('IN', $selected_value_to_always_include);
347
-            } else {
348
-                $query_params[0]['OR*options-query']['QSO_value'] = $selected_value_to_always_include;
349
-            }
350
-        }
351
-        if ($notDeletedOptionsOnly) {
352
-            $query_params[0]['OR*options-query']['QSO_deleted'] = false;
353
-        }
354
-        // order by QSO_order
355
-        $query_params['order_by'] = array('QSO_order' => 'ASC');
356
-        return $this->get_many_related('Question_Option', $query_params);
357
-    }
358
-
359
-
360
-    /**
361
-     * returns an array of EE_Question_Options which relate to this question
362
-     *
363
-     * @return \EE_Question_Option[]
364
-     */
365
-    public function temp_options()
366
-    {
367
-        return $this->_model_relations['Question_Option'];
368
-    }
369
-
370
-
371
-    /**
372
-     * Adds an option for this question. Note: if the option were previously associated with a different
373
-     * Question, that relationship will be overwritten.
374
-     *
375
-     * @param EE_Question_Option $option
376
-     * @return boolean success
377
-     */
378
-    public function add_option(EE_Question_Option $option)
379
-    {
380
-        return $this->_add_relation_to($option, 'Question_Option');
381
-    }
382
-
383
-
384
-    /**
385
-     * Adds an option directly to this question without saving to the db
386
-     *
387
-     * @param EE_Question_Option $option
388
-     * @return boolean success
389
-     */
390
-    public function add_temp_option(EE_Question_Option $option)
391
-    {
392
-        $this->_model_relations['Question_Option'][] = $option;
393
-        return true;
394
-    }
395
-
396
-
397
-    /**
398
-     * Marks the option as deleted.
399
-     *
400
-     * @param EE_Question_Option $option
401
-     * @return boolean success
402
-     */
403
-    public function remove_option(EE_Question_Option $option)
404
-    {
405
-        return $this->_remove_relation_to($option, 'Question_Option');
406
-    }
407
-
408
-
409
-    /**
410
-     * @return bool
411
-     */
412
-    public function is_system_question()
413
-    {
414
-        $system_ID = $this->get('QST_system');
415
-        return ! empty($system_ID) ? true : false;
416
-    }
417
-
418
-
419
-    /**
420
-     * The purpose of this method is set the question order this question order to be the max out of all questions
421
-     *
422
-     * @access public
423
-     * @return void
424
-     */
425
-    public function set_order_to_latest()
426
-    {
427
-        $latest_order = $this->get_model()->get_latest_question_order();
428
-        $latest_order++;
429
-        $this->set('QST_order', $latest_order);
430
-    }
431
-
432
-
433
-    /**
434
-     * Retrieves the list of allowed question types from the model.
435
-     *
436
-     * @return string[]
437
-     */
438
-    private function _allowed_question_types()
439
-    {
440
-        $questionModel = $this->get_model();
441
-        /* @var $questionModel EEM_Question */
442
-        return $questionModel->allowed_question_types();
443
-    }
444
-
445
-    /**
446
-     * Duplicates this question and its question options
447
-     *
448
-     * @return \EE_Question
449
-     */
450
-    public function duplicate($options = array())
451
-    {
452
-        $new_question = clone $this;
453
-        $new_question->set('QST_ID', null);
454
-        $new_question->set_display_text(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->display_text()));
455
-        $new_question->set_admin_label(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->admin_label()));
456
-        $new_question->set_system_ID(null);
457
-        $new_question->set_wp_user(get_current_user_id());
458
-        // if we're duplicating a trashed question, assume we don't want the new one to be trashed
459
-        $new_question->set_deleted(false);
460
-        $success = $new_question->save();
461
-        if ($success) {
462
-            // we don't totally want to duplicate the question options, because we want them to be for the NEW question
463
-            foreach ($this->options() as $question_option) {
464
-                $question_option->duplicate(array('QST_ID' => $new_question->ID()));
465
-            }
466
-            return $new_question;
467
-        } else {
468
-            return null;
469
-        }
470
-    }
471
-
472
-    /**
473
-     * Returns the question's maximum allowed response size
474
-     *
475
-     * @return int|float
476
-     */
477
-    public function max()
478
-    {
479
-        return $this->get('QST_max');
480
-    }
481
-
482
-    /**
483
-     * Sets the question's maximum allowed response size
484
-     *
485
-     * @param int|float $new_max
486
-     * @return void
487
-     */
488
-    public function set_max($new_max)
489
-    {
490
-        $this->set('QST_max', $new_max);
491
-    }
492
-
493
-
494
-    /**
495
-     * Creates a form input from this question which can be used in HTML forms
496
-     *
497
-     * @param EE_Registration $registration
498
-     * @param EE_Answer       $answer
499
-     * @param array           $input_constructor_args
500
-     * @return EE_Form_Input_Base
501
-     */
502
-    public function generate_form_input($registration = null, $answer = null, $input_constructor_args = array())
503
-    {
504
-        $identifier = $this->is_system_question() ? $this->system_ID() : $this->ID();
505
-
506
-        $input_constructor_args = array_merge(
507
-            array(
508
-                'required'                          => $this->required() ? true : false,
509
-                'html_label_text'                   => $this->display_text(),
510
-                'required_validation_error_message' => $this->required_text(),
511
-            ),
512
-            $input_constructor_args
513
-        );
514
-        if (! $answer instanceof EE_Answer && $registration instanceof EE_Registration) {
515
-            $answer = EEM_Answer::instance()->get_registration_question_answer_object($registration, $this->ID());
516
-        }
517
-        // has this question been answered ?
518
-        if ($answer instanceof EE_Answer
519
-            && $answer->value() !== ''
520
-        ) {
521
-            // answer gets htmlspecialchars called on it, undo that please
522
-            // because the form input's display strategy may call esc_attr too
523
-            // which also does html special characters
524
-            $values_with_html_special_chars = $answer->value();
525
-            if (is_array($values_with_html_special_chars)) {
526
-                $default_value = array_map('htmlspecialchars_decode', $values_with_html_special_chars);
527
-            } else {
528
-                $default_value = htmlspecialchars_decode($values_with_html_special_chars);
529
-            }
530
-            $input_constructor_args['default'] = $default_value;
531
-        }
532
-        $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question($this->system_ID());
533
-        if (in_array(
534
-            $this->type(),
535
-            EEM_Question::instance()->questionTypesWithMaxLength(),
536
-            true
537
-        )) {
538
-            $input_constructor_args['validation_strategies'][] = new EE_Max_Length_Validation_Strategy(
539
-                null,
540
-                min($max_max_for_question, $this->max())
541
-            );
542
-        }
543
-        $input_constructor_args = apply_filters(
544
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__input_constructor_args',
545
-            $input_constructor_args,
546
-            $registration,
547
-            $this,
548
-            $answer
549
-        );
550
-
551
-        $result = null;
552
-        switch ($this->type()) {
553
-            // Text
554
-            case EEM_Question::QST_type_text:
555
-                $result = new EE_Text_Input($input_constructor_args);
556
-                break;
557
-            // Textarea
558
-            case EEM_Question::QST_type_textarea:
559
-                $result = new EE_Text_Area_Input($input_constructor_args);
560
-                break;
561
-            // Radio Buttons
562
-            case EEM_Question::QST_type_radio:
563
-                $result = new EE_Radio_Button_Input($this->options(), $input_constructor_args);
564
-                break;
565
-            // Dropdown
566
-            case EEM_Question::QST_type_dropdown:
567
-                $result = new EE_Select_Input($this->options(), $input_constructor_args);
568
-                break;
569
-            // State Dropdown
570
-            case EEM_Question::QST_type_state:
571
-                $state_options = apply_filters(
572
-                    'FHEE__EE_Question__generate_form_input__state_options',
573
-                    null,
574
-                    $this,
575
-                    $registration,
576
-                    $answer
577
-                );
578
-                $result = new EE_State_Select_Input($state_options, $input_constructor_args);
579
-                break;
580
-            // Country Dropdown
581
-            case EEM_Question::QST_type_country:
582
-                $country_options = apply_filters(
583
-                    'FHEE__EE_Question__generate_form_input__country_options',
584
-                    null,
585
-                    $this,
586
-                    $registration,
587
-                    $answer
588
-                );
589
-                $result = new EE_Country_Select_Input($country_options, $input_constructor_args);
590
-                break;
591
-            // Checkboxes
592
-            case EEM_Question::QST_type_checkbox:
593
-                $result = new EE_Checkbox_Multi_Input($this->options(), $input_constructor_args);
594
-                break;
595
-            // Date
596
-            case EEM_Question::QST_type_date:
597
-                $result = new EE_Datepicker_Input($input_constructor_args);
598
-                break;
599
-            case EEM_Question::QST_type_html_textarea:
600
-                $input_constructor_args['validation_strategies'][] = new EE_Simple_HTML_Validation_Strategy();
601
-                $result = new EE_Text_Area_Input($input_constructor_args);
602
-                $result->remove_validation_strategy('EE_Plaintext_Validation_Strategy');
603
-                break;
604
-            case EEM_Question::QST_type_email:
605
-                    $result = new EE_Email_Input($input_constructor_args);
606
-                break;
607
-            // Email confirm
608
-            case EEM_Question::QST_type_email_confirm:
609
-                $result = new EE_Email_Confirm_Input($input_constructor_args);
610
-                break;
611
-            case EEM_Question::QST_type_us_phone:
612
-                $result = new EE_Phone_Input($input_constructor_args);
613
-                break;
614
-            case EEM_Question::QST_type_int:
615
-                $result = new EE_Integer_Input($input_constructor_args);
616
-                break;
617
-            case EEM_Question::QST_type_decimal:
618
-                $result = new EE_Float_Input($input_constructor_args);
619
-                break;
620
-            case EEM_Question::QST_type_url:
621
-                $input_constructor_args['validation_strategies'][] = LoaderFactory::getLoader()->getNew('EE_URL_Validation_Strategy');
622
-                $result = new EE_Text_Input($input_constructor_args);
623
-                break;
624
-            case EEM_Question::QST_type_year:
625
-                $result = new EE_Year_Input(
626
-                    $input_constructor_args,
627
-                    apply_filters(
628
-                        'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit',
629
-                        true,
630
-                        $this
631
-                    ),
632
-                    apply_filters(
633
-                        'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range',
634
-                        100,
635
-                        $this
636
-                    ),
637
-                    apply_filters(
638
-                        'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range',
639
-                        100,
640
-                        $this
641
-                    )
642
-                );
643
-                break;
644
-            case EEM_Question::QST_type_multi_select:
645
-                $result = new EE_Select_Multiple_Input($this->options(), $input_constructor_args);
646
-                break;
647
-            // fallback
648
-            default:
649
-                $default_input = apply_filters(
650
-                    'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__default',
651
-                    null,
652
-                    $this->type(),
653
-                    $this,
654
-                    $input_constructor_args
655
-                );
656
-                if (! $default_input) {
657
-                    $default_input = new EE_Text_Input($input_constructor_args);
658
-                }
659
-                $result = $default_input;
660
-        }
661
-        return apply_filters('FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer);
662
-    }
663
-
664
-
665
-    /**
666
-     * Returns whether or not this question type should have question option entries
667
-     *
668
-     * @return bool
669
-     */
670
-    public function should_have_question_options()
671
-    {
672
-        return in_array(
673
-            $this->type(),
674
-            $this->_model->question_types_with_options(),
675
-            true
676
-        );
677
-    }
17
+	/**
18
+	 *
19
+	 * @param array  $props_n_values          incoming values
20
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
21
+	 *                                        used.)
22
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
23
+	 *                                        date_format and the second value is the time format
24
+	 * @return EE_Question
25
+	 */
26
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
27
+	{
28
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
29
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
30
+	}
31
+
32
+
33
+	/**
34
+	 * @param array  $props_n_values  incoming values from the database
35
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
36
+	 *                                the website will be used.
37
+	 * @return EE_Question
38
+	 */
39
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
40
+	{
41
+		return new self($props_n_values, true, $timezone);
42
+	}
43
+
44
+
45
+	/**
46
+	 *        Set    Question display text
47
+	 *
48
+	 * @access        public
49
+	 * @param string $QST_display_text
50
+	 */
51
+	public function set_display_text($QST_display_text = '')
52
+	{
53
+		$this->set('QST_display_text', $QST_display_text);
54
+	}
55
+
56
+
57
+	/**
58
+	 *        Set    Question admin text
59
+	 *
60
+	 * @access        public
61
+	 * @param        string $QST_admin_label
62
+	 */
63
+	public function set_admin_label($QST_admin_label = '')
64
+	{
65
+		$this->set('QST_admin_label', $QST_admin_label);
66
+	}
67
+
68
+
69
+	/**
70
+	 *        Set    system name
71
+	 *
72
+	 * @access        public
73
+	 * @param        mixed $QST_system
74
+	 */
75
+	public function set_system_ID($QST_system = '')
76
+	{
77
+		$this->set('QST_system', $QST_system);
78
+	}
79
+
80
+
81
+	/**
82
+	 *        Set    question's type
83
+	 *
84
+	 * @access        public
85
+	 * @param        string $QST_type
86
+	 */
87
+	public function set_question_type($QST_type = '')
88
+	{
89
+		$this->set('QST_type', $QST_type);
90
+	}
91
+
92
+
93
+	/**
94
+	 *        Sets whether this question must be answered when presented in a form
95
+	 *
96
+	 * @access        public
97
+	 * @param        bool $QST_required
98
+	 */
99
+	public function set_required($QST_required = false)
100
+	{
101
+		$this->set('QST_required', $QST_required);
102
+	}
103
+
104
+
105
+	/**
106
+	 *        Set    Question display text
107
+	 *
108
+	 * @access        public
109
+	 * @param        string $QST_required_text
110
+	 */
111
+	public function set_required_text($QST_required_text = '')
112
+	{
113
+		$this->set('QST_required_text', $QST_required_text);
114
+	}
115
+
116
+
117
+	/**
118
+	 *        Sets the order of this question when placed in a sequence of questions
119
+	 *
120
+	 * @access        public
121
+	 * @param        int $QST_order
122
+	 */
123
+	public function set_order($QST_order = 0)
124
+	{
125
+		$this->set('QST_order', $QST_order);
126
+	}
127
+
128
+
129
+	/**
130
+	 *        Sets whether the question is admin-only
131
+	 *
132
+	 * @access        public
133
+	 * @param        bool $QST_admin_only
134
+	 */
135
+	public function set_admin_only($QST_admin_only = false)
136
+	{
137
+		$this->set('QST_admin_only', $QST_admin_only);
138
+	}
139
+
140
+
141
+	/**
142
+	 *        Sets the wordpress user ID on the question
143
+	 *
144
+	 * @access        public
145
+	 * @param        int $QST_wp_user
146
+	 */
147
+	public function set_wp_user($QST_wp_user = 1)
148
+	{
149
+		$this->set('QST_wp_user', $QST_wp_user);
150
+	}
151
+
152
+
153
+	/**
154
+	 *        Sets whether the question has been deleted
155
+	 *        (we use this boolean instead of actually
156
+	 *        deleting it because when users delete this question
157
+	 *        they really want to remove the question from future
158
+	 *        forms, BUT keep their old answers which depend
159
+	 *        on this record actually existing.
160
+	 *
161
+	 * @access        public
162
+	 * @param    bool $QST_deleted
163
+	 */
164
+	public function set_deleted($QST_deleted = false)
165
+	{
166
+		$this->set('QST_deleted', $QST_deleted);
167
+	}
168
+
169
+
170
+	/**
171
+	 * returns the text for displaying the question to users
172
+	 *
173
+	 * @access public
174
+	 * @return string
175
+	 */
176
+	public function display_text()
177
+	{
178
+		return $this->get('QST_display_text');
179
+	}
180
+
181
+
182
+	/**
183
+	 * returns the text for the administrative label
184
+	 *
185
+	 * @access public
186
+	 * @return string
187
+	 */
188
+	public function admin_label()
189
+	{
190
+		return $this->get('QST_admin_label');
191
+	}
192
+
193
+
194
+	/**
195
+	 * returns the attendee column name for this question
196
+	 *
197
+	 * @access public
198
+	 * @return string
199
+	 */
200
+	public function system_ID()
201
+	{
202
+		return $this->get('QST_system');
203
+	}
204
+
205
+
206
+	/**
207
+	 * returns either a string of 'text', 'textfield', etc.
208
+	 *
209
+	 * @access public
210
+	 * @return boolean
211
+	 */
212
+	public function required()
213
+	{
214
+		return $this->get('QST_required');
215
+	}
216
+
217
+
218
+	/**
219
+	 * returns the text which should be displayed when a user
220
+	 * doesn't answer this question in a form
221
+	 *
222
+	 * @access public
223
+	 * @return string
224
+	 */
225
+	public function required_text()
226
+	{
227
+		return $this->get('QST_required_text');
228
+	}
229
+
230
+
231
+	/**
232
+	 * returns the type of this question
233
+	 *
234
+	 * @access public
235
+	 * @return string
236
+	 */
237
+	public function type()
238
+	{
239
+		return $this->get('QST_type');
240
+	}
241
+
242
+
243
+	/**
244
+	 * returns an integer showing where this question should
245
+	 * be placed in a sequence of questions
246
+	 *
247
+	 * @access public
248
+	 * @return int
249
+	 */
250
+	public function order()
251
+	{
252
+		return $this->get('QST_order');
253
+	}
254
+
255
+
256
+	/**
257
+	 * returns whether this question should only appears to admins,
258
+	 * or to everyone
259
+	 *
260
+	 * @access public
261
+	 * @return boolean
262
+	 */
263
+	public function admin_only()
264
+	{
265
+		return $this->get('QST_admin_only');
266
+	}
267
+
268
+
269
+	/**
270
+	 * returns the id the wordpress user who created this question
271
+	 *
272
+	 * @access public
273
+	 * @return int
274
+	 */
275
+	public function wp_user()
276
+	{
277
+		return $this->get('QST_wp_user');
278
+	}
279
+
280
+
281
+	/**
282
+	 * returns whether this question has been marked as 'deleted'
283
+	 *
284
+	 * @access public
285
+	 * @return boolean
286
+	 */
287
+	public function deleted()
288
+	{
289
+		return $this->get('QST_deleted');
290
+	}
291
+
292
+
293
+	/**
294
+	 * Gets an array of related EE_Answer  to this EE_Question
295
+	 *
296
+	 * @return EE_Answer[]
297
+	 */
298
+	public function answers()
299
+	{
300
+		return $this->get_many_related('Answer');
301
+	}
302
+
303
+
304
+	/**
305
+	 * Boolean check for if there are answers on this question in th db
306
+	 *
307
+	 * @return boolean true = has answers, false = no answers.
308
+	 */
309
+	public function has_answers()
310
+	{
311
+		return $this->count_related('Answer') > 0 ? true : false;
312
+	}
313
+
314
+
315
+	/**
316
+	 * gets an array of EE_Question_Group which relate to this question
317
+	 *
318
+	 * @return EE_Question_Group[]
319
+	 */
320
+	public function question_groups()
321
+	{
322
+		return $this->get_many_related('Question_Group');
323
+	}
324
+
325
+
326
+	/**
327
+	 * Returns all the options for this question. By default, it returns only the not-yet-deleted ones.
328
+	 *
329
+	 * @param boolean      $notDeletedOptionsOnly            1
330
+	 *                                                       whether to return ALL options, or only the ones which have
331
+	 *                                                       not yet been deleleted
332
+	 * @param string|array $selected_value_to_always_include , when retrieving options to an ANSWERED question,
333
+	 *                                                       we want to usually only show non-deleted options AND the
334
+	 *                                                       value that was selected for the answer, whether it was
335
+	 *                                                       trashed or not.
336
+	 * @return EE_Question_Option[]
337
+	 */
338
+	public function options($notDeletedOptionsOnly = true, $selected_value_to_always_include = null)
339
+	{
340
+		if (! $this->ID()) {
341
+			return array();
342
+		}
343
+		$query_params = array();
344
+		if ($selected_value_to_always_include) {
345
+			if (is_array($selected_value_to_always_include)) {
346
+				$query_params[0]['OR*options-query']['QSO_value'] = array('IN', $selected_value_to_always_include);
347
+			} else {
348
+				$query_params[0]['OR*options-query']['QSO_value'] = $selected_value_to_always_include;
349
+			}
350
+		}
351
+		if ($notDeletedOptionsOnly) {
352
+			$query_params[0]['OR*options-query']['QSO_deleted'] = false;
353
+		}
354
+		// order by QSO_order
355
+		$query_params['order_by'] = array('QSO_order' => 'ASC');
356
+		return $this->get_many_related('Question_Option', $query_params);
357
+	}
358
+
359
+
360
+	/**
361
+	 * returns an array of EE_Question_Options which relate to this question
362
+	 *
363
+	 * @return \EE_Question_Option[]
364
+	 */
365
+	public function temp_options()
366
+	{
367
+		return $this->_model_relations['Question_Option'];
368
+	}
369
+
370
+
371
+	/**
372
+	 * Adds an option for this question. Note: if the option were previously associated with a different
373
+	 * Question, that relationship will be overwritten.
374
+	 *
375
+	 * @param EE_Question_Option $option
376
+	 * @return boolean success
377
+	 */
378
+	public function add_option(EE_Question_Option $option)
379
+	{
380
+		return $this->_add_relation_to($option, 'Question_Option');
381
+	}
382
+
383
+
384
+	/**
385
+	 * Adds an option directly to this question without saving to the db
386
+	 *
387
+	 * @param EE_Question_Option $option
388
+	 * @return boolean success
389
+	 */
390
+	public function add_temp_option(EE_Question_Option $option)
391
+	{
392
+		$this->_model_relations['Question_Option'][] = $option;
393
+		return true;
394
+	}
395
+
396
+
397
+	/**
398
+	 * Marks the option as deleted.
399
+	 *
400
+	 * @param EE_Question_Option $option
401
+	 * @return boolean success
402
+	 */
403
+	public function remove_option(EE_Question_Option $option)
404
+	{
405
+		return $this->_remove_relation_to($option, 'Question_Option');
406
+	}
407
+
408
+
409
+	/**
410
+	 * @return bool
411
+	 */
412
+	public function is_system_question()
413
+	{
414
+		$system_ID = $this->get('QST_system');
415
+		return ! empty($system_ID) ? true : false;
416
+	}
417
+
418
+
419
+	/**
420
+	 * The purpose of this method is set the question order this question order to be the max out of all questions
421
+	 *
422
+	 * @access public
423
+	 * @return void
424
+	 */
425
+	public function set_order_to_latest()
426
+	{
427
+		$latest_order = $this->get_model()->get_latest_question_order();
428
+		$latest_order++;
429
+		$this->set('QST_order', $latest_order);
430
+	}
431
+
432
+
433
+	/**
434
+	 * Retrieves the list of allowed question types from the model.
435
+	 *
436
+	 * @return string[]
437
+	 */
438
+	private function _allowed_question_types()
439
+	{
440
+		$questionModel = $this->get_model();
441
+		/* @var $questionModel EEM_Question */
442
+		return $questionModel->allowed_question_types();
443
+	}
444
+
445
+	/**
446
+	 * Duplicates this question and its question options
447
+	 *
448
+	 * @return \EE_Question
449
+	 */
450
+	public function duplicate($options = array())
451
+	{
452
+		$new_question = clone $this;
453
+		$new_question->set('QST_ID', null);
454
+		$new_question->set_display_text(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->display_text()));
455
+		$new_question->set_admin_label(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->admin_label()));
456
+		$new_question->set_system_ID(null);
457
+		$new_question->set_wp_user(get_current_user_id());
458
+		// if we're duplicating a trashed question, assume we don't want the new one to be trashed
459
+		$new_question->set_deleted(false);
460
+		$success = $new_question->save();
461
+		if ($success) {
462
+			// we don't totally want to duplicate the question options, because we want them to be for the NEW question
463
+			foreach ($this->options() as $question_option) {
464
+				$question_option->duplicate(array('QST_ID' => $new_question->ID()));
465
+			}
466
+			return $new_question;
467
+		} else {
468
+			return null;
469
+		}
470
+	}
471
+
472
+	/**
473
+	 * Returns the question's maximum allowed response size
474
+	 *
475
+	 * @return int|float
476
+	 */
477
+	public function max()
478
+	{
479
+		return $this->get('QST_max');
480
+	}
481
+
482
+	/**
483
+	 * Sets the question's maximum allowed response size
484
+	 *
485
+	 * @param int|float $new_max
486
+	 * @return void
487
+	 */
488
+	public function set_max($new_max)
489
+	{
490
+		$this->set('QST_max', $new_max);
491
+	}
492
+
493
+
494
+	/**
495
+	 * Creates a form input from this question which can be used in HTML forms
496
+	 *
497
+	 * @param EE_Registration $registration
498
+	 * @param EE_Answer       $answer
499
+	 * @param array           $input_constructor_args
500
+	 * @return EE_Form_Input_Base
501
+	 */
502
+	public function generate_form_input($registration = null, $answer = null, $input_constructor_args = array())
503
+	{
504
+		$identifier = $this->is_system_question() ? $this->system_ID() : $this->ID();
505
+
506
+		$input_constructor_args = array_merge(
507
+			array(
508
+				'required'                          => $this->required() ? true : false,
509
+				'html_label_text'                   => $this->display_text(),
510
+				'required_validation_error_message' => $this->required_text(),
511
+			),
512
+			$input_constructor_args
513
+		);
514
+		if (! $answer instanceof EE_Answer && $registration instanceof EE_Registration) {
515
+			$answer = EEM_Answer::instance()->get_registration_question_answer_object($registration, $this->ID());
516
+		}
517
+		// has this question been answered ?
518
+		if ($answer instanceof EE_Answer
519
+			&& $answer->value() !== ''
520
+		) {
521
+			// answer gets htmlspecialchars called on it, undo that please
522
+			// because the form input's display strategy may call esc_attr too
523
+			// which also does html special characters
524
+			$values_with_html_special_chars = $answer->value();
525
+			if (is_array($values_with_html_special_chars)) {
526
+				$default_value = array_map('htmlspecialchars_decode', $values_with_html_special_chars);
527
+			} else {
528
+				$default_value = htmlspecialchars_decode($values_with_html_special_chars);
529
+			}
530
+			$input_constructor_args['default'] = $default_value;
531
+		}
532
+		$max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question($this->system_ID());
533
+		if (in_array(
534
+			$this->type(),
535
+			EEM_Question::instance()->questionTypesWithMaxLength(),
536
+			true
537
+		)) {
538
+			$input_constructor_args['validation_strategies'][] = new EE_Max_Length_Validation_Strategy(
539
+				null,
540
+				min($max_max_for_question, $this->max())
541
+			);
542
+		}
543
+		$input_constructor_args = apply_filters(
544
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__input_constructor_args',
545
+			$input_constructor_args,
546
+			$registration,
547
+			$this,
548
+			$answer
549
+		);
550
+
551
+		$result = null;
552
+		switch ($this->type()) {
553
+			// Text
554
+			case EEM_Question::QST_type_text:
555
+				$result = new EE_Text_Input($input_constructor_args);
556
+				break;
557
+			// Textarea
558
+			case EEM_Question::QST_type_textarea:
559
+				$result = new EE_Text_Area_Input($input_constructor_args);
560
+				break;
561
+			// Radio Buttons
562
+			case EEM_Question::QST_type_radio:
563
+				$result = new EE_Radio_Button_Input($this->options(), $input_constructor_args);
564
+				break;
565
+			// Dropdown
566
+			case EEM_Question::QST_type_dropdown:
567
+				$result = new EE_Select_Input($this->options(), $input_constructor_args);
568
+				break;
569
+			// State Dropdown
570
+			case EEM_Question::QST_type_state:
571
+				$state_options = apply_filters(
572
+					'FHEE__EE_Question__generate_form_input__state_options',
573
+					null,
574
+					$this,
575
+					$registration,
576
+					$answer
577
+				);
578
+				$result = new EE_State_Select_Input($state_options, $input_constructor_args);
579
+				break;
580
+			// Country Dropdown
581
+			case EEM_Question::QST_type_country:
582
+				$country_options = apply_filters(
583
+					'FHEE__EE_Question__generate_form_input__country_options',
584
+					null,
585
+					$this,
586
+					$registration,
587
+					$answer
588
+				);
589
+				$result = new EE_Country_Select_Input($country_options, $input_constructor_args);
590
+				break;
591
+			// Checkboxes
592
+			case EEM_Question::QST_type_checkbox:
593
+				$result = new EE_Checkbox_Multi_Input($this->options(), $input_constructor_args);
594
+				break;
595
+			// Date
596
+			case EEM_Question::QST_type_date:
597
+				$result = new EE_Datepicker_Input($input_constructor_args);
598
+				break;
599
+			case EEM_Question::QST_type_html_textarea:
600
+				$input_constructor_args['validation_strategies'][] = new EE_Simple_HTML_Validation_Strategy();
601
+				$result = new EE_Text_Area_Input($input_constructor_args);
602
+				$result->remove_validation_strategy('EE_Plaintext_Validation_Strategy');
603
+				break;
604
+			case EEM_Question::QST_type_email:
605
+					$result = new EE_Email_Input($input_constructor_args);
606
+				break;
607
+			// Email confirm
608
+			case EEM_Question::QST_type_email_confirm:
609
+				$result = new EE_Email_Confirm_Input($input_constructor_args);
610
+				break;
611
+			case EEM_Question::QST_type_us_phone:
612
+				$result = new EE_Phone_Input($input_constructor_args);
613
+				break;
614
+			case EEM_Question::QST_type_int:
615
+				$result = new EE_Integer_Input($input_constructor_args);
616
+				break;
617
+			case EEM_Question::QST_type_decimal:
618
+				$result = new EE_Float_Input($input_constructor_args);
619
+				break;
620
+			case EEM_Question::QST_type_url:
621
+				$input_constructor_args['validation_strategies'][] = LoaderFactory::getLoader()->getNew('EE_URL_Validation_Strategy');
622
+				$result = new EE_Text_Input($input_constructor_args);
623
+				break;
624
+			case EEM_Question::QST_type_year:
625
+				$result = new EE_Year_Input(
626
+					$input_constructor_args,
627
+					apply_filters(
628
+						'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit',
629
+						true,
630
+						$this
631
+					),
632
+					apply_filters(
633
+						'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range',
634
+						100,
635
+						$this
636
+					),
637
+					apply_filters(
638
+						'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range',
639
+						100,
640
+						$this
641
+					)
642
+				);
643
+				break;
644
+			case EEM_Question::QST_type_multi_select:
645
+				$result = new EE_Select_Multiple_Input($this->options(), $input_constructor_args);
646
+				break;
647
+			// fallback
648
+			default:
649
+				$default_input = apply_filters(
650
+					'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__default',
651
+					null,
652
+					$this->type(),
653
+					$this,
654
+					$input_constructor_args
655
+				);
656
+				if (! $default_input) {
657
+					$default_input = new EE_Text_Input($input_constructor_args);
658
+				}
659
+				$result = $default_input;
660
+		}
661
+		return apply_filters('FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer);
662
+	}
663
+
664
+
665
+	/**
666
+	 * Returns whether or not this question type should have question option entries
667
+	 *
668
+	 * @return bool
669
+	 */
670
+	public function should_have_question_options()
671
+	{
672
+		return in_array(
673
+			$this->type(),
674
+			$this->_model->question_types_with_options(),
675
+			true
676
+		);
677
+	}
678 678
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Price.class.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -285,7 +285,7 @@
 block discarded – undo
285 285
      */
286 286
     public function pretty_price()
287 287
     {
288
-        return ! $this->is_percent() ? $this->get_pretty('PRC_amount') : $this->get('PRC_amount') . '%';
288
+        return ! $this->is_percent() ? $this->get_pretty('PRC_amount') : $this->get('PRC_amount').'%';
289 289
     }
290 290
 
291 291
 
Please login to merge, or discard this patch.
Indentation   +285 added lines, -285 removed lines patch added patch discarded remove patch
@@ -10,289 +10,289 @@
 block discarded – undo
10 10
 class EE_Price extends EE_Soft_Delete_Base_Class
11 11
 {
12 12
 
13
-    /**
14
-     * @param array  $props_n_values          incoming values
15
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
16
-     *                                        used.)
17
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
18
-     *                                        date_format and the second value is the time format
19
-     * @return EE_Price
20
-     */
21
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
22
-    {
23
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
24
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
25
-    }
26
-
27
-
28
-    /**
29
-     * @param array  $props_n_values  incoming values from the database
30
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
31
-     *                                the website will be used.
32
-     * @return EE_Price
33
-     */
34
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
35
-    {
36
-        return new self($props_n_values, true, $timezone);
37
-    }
38
-
39
-
40
-    /**
41
-     *        Set Price type ID
42
-     *
43
-     * @access        public
44
-     * @param        int $PRT_ID
45
-     */
46
-    public function set_type($PRT_ID = 0)
47
-    {
48
-        $this->set('PRT_ID', $PRT_ID);
49
-    }
50
-
51
-
52
-    /**
53
-     *        Set Price Amount
54
-     *
55
-     * @access        public
56
-     * @param        float $PRC_amount
57
-     */
58
-    public function set_amount($PRC_amount = 0.00)
59
-    {
60
-        $this->set('PRC_amount', $PRC_amount);
61
-    }
62
-
63
-
64
-    /**
65
-     *        Set Price Name
66
-     *
67
-     * @access        public
68
-     * @param        string $PRC_name
69
-     */
70
-    public function set_name($PRC_name = '')
71
-    {
72
-        $this->set('PRC_name', $PRC_name);
73
-    }
74
-
75
-
76
-    /**
77
-     *        Set Price Description
78
-     *
79
-     * @access        public
80
-     * @param        string $PRC_desc
81
-     */
82
-    public function set_description($PRC_desc = '')
83
-    {
84
-        $this->Set('PRC_desc', $PRC_desc);
85
-    }
86
-
87
-
88
-    /**
89
-     *        set is_default
90
-     *
91
-     * @access        public
92
-     * @param        bool $PRC_is_default
93
-     */
94
-    public function set_is_default($PRC_is_default = false)
95
-    {
96
-        $this->set('PRC_is_default', $PRC_is_default);
97
-    }
98
-
99
-
100
-    /**
101
-     *        set deleted
102
-     *
103
-     * @access        public
104
-     * @param        bool $PRC_deleted
105
-     */
106
-    public function set_deleted($PRC_deleted = null)
107
-    {
108
-        $this->set('PRC_deleted', $PRC_deleted);
109
-    }
110
-
111
-
112
-    /**
113
-     *    get Price type
114
-     *
115
-     * @access        public
116
-     * @return        int
117
-     */
118
-    public function type()
119
-    {
120
-        return $this->get('PRT_ID');
121
-    }
122
-
123
-
124
-    /**
125
-     *    get Price Amount
126
-     *
127
-     * @access        public
128
-     * @return        float
129
-     */
130
-    public function amount()
131
-    {
132
-        return $this->get('PRC_amount');
133
-    }
134
-
135
-
136
-    /**
137
-     *    get Price Name
138
-     *
139
-     * @access        public
140
-     * @return        string
141
-     */
142
-    public function name()
143
-    {
144
-        return $this->get('PRC_name');
145
-    }
146
-
147
-
148
-    /**
149
-     *    get Price description
150
-     *
151
-     * @access        public
152
-     * @return        string
153
-     */
154
-    public function desc()
155
-    {
156
-        return $this->get('PRC_desc');
157
-    }
158
-
159
-
160
-    /**
161
-     *    get overrides
162
-     *
163
-     * @access        public
164
-     * @return        int
165
-     */
166
-    public function overrides()
167
-    {
168
-        return $this->get('PRC_overrides');
169
-    }
170
-
171
-
172
-    /**
173
-     *    get order
174
-     *
175
-     * @access        public
176
-     * @return        int
177
-     */
178
-    public function order()
179
-    {
180
-        return $this->get('PRC_order');
181
-    }
182
-
183
-
184
-    /**
185
-     * get the author of the price
186
-     *
187
-     * @since 4.5.0
188
-     *
189
-     * @return int
190
-     */
191
-    public function wp_user()
192
-    {
193
-        return $this->get('PRC_wp_user');
194
-    }
195
-
196
-
197
-    /**
198
-     *    get is_default
199
-     *
200
-     * @access        public
201
-     * @return        bool
202
-     */
203
-    public function is_default()
204
-    {
205
-        return $this->get('PRC_is_default');
206
-    }
207
-
208
-
209
-    /**
210
-     *    get deleted
211
-     *
212
-     * @access        public
213
-     * @return        bool
214
-     */
215
-    public function deleted()
216
-    {
217
-        return $this->get('PRC_deleted');
218
-    }
219
-
220
-
221
-    /**
222
-     * @return bool
223
-     */
224
-    public function parent()
225
-    {
226
-        return $this->get('PRC_parent');
227
-    }
228
-
229
-
230
-    // some helper methods for getting info on the price_type for this price
231
-
232
-    /**
233
-     * return whether the price is a base price or not
234
-     *
235
-     * @return boolean
236
-     */
237
-    public function is_base_price()
238
-    {
239
-        $price_type = $this->type_obj();
240
-        return $price_type->base_type() === 1;
241
-    }
242
-
243
-
244
-    /**
245
-     *
246
-     * @return EE_Price_Type
247
-     */
248
-    public function type_obj()
249
-    {
250
-        return $this->get_first_related('Price_Type');
251
-    }
252
-
253
-
254
-    /**
255
-     * Simply indicates whether this price increases or decreases the total
256
-     *
257
-     * @return boolean true = discount, otherwise adds to the total
258
-     */
259
-    public function is_discount()
260
-    {
261
-        $price_type = $this->type_obj();
262
-        return $price_type->is_discount();
263
-    }
264
-
265
-
266
-    /**
267
-     * whether the price is a percentage or not
268
-     *
269
-     * @return boolean
270
-     */
271
-    public function is_percent()
272
-    {
273
-        $price_type = $this->type_obj();
274
-        return $price_type->get('PRT_is_percent');
275
-    }
276
-
277
-
278
-    /**
279
-     * return pretty price dependant on whether its a dollar or percent.
280
-     *
281
-     * @since 4.4.0
282
-     *
283
-     * @return string
284
-     */
285
-    public function pretty_price()
286
-    {
287
-        return ! $this->is_percent() ? $this->get_pretty('PRC_amount') : $this->get('PRC_amount') . '%';
288
-    }
289
-
290
-
291
-    /**
292
-     * @return mixed
293
-     */
294
-    public function get_price_without_currency_symbol()
295
-    {
296
-        return str_replace(EE_Registry::instance()->CFG->currency->sign, '', $this->get_pretty('PRC_amount'));
297
-    }
13
+	/**
14
+	 * @param array  $props_n_values          incoming values
15
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
16
+	 *                                        used.)
17
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
18
+	 *                                        date_format and the second value is the time format
19
+	 * @return EE_Price
20
+	 */
21
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
22
+	{
23
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
24
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
25
+	}
26
+
27
+
28
+	/**
29
+	 * @param array  $props_n_values  incoming values from the database
30
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
31
+	 *                                the website will be used.
32
+	 * @return EE_Price
33
+	 */
34
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
35
+	{
36
+		return new self($props_n_values, true, $timezone);
37
+	}
38
+
39
+
40
+	/**
41
+	 *        Set Price type ID
42
+	 *
43
+	 * @access        public
44
+	 * @param        int $PRT_ID
45
+	 */
46
+	public function set_type($PRT_ID = 0)
47
+	{
48
+		$this->set('PRT_ID', $PRT_ID);
49
+	}
50
+
51
+
52
+	/**
53
+	 *        Set Price Amount
54
+	 *
55
+	 * @access        public
56
+	 * @param        float $PRC_amount
57
+	 */
58
+	public function set_amount($PRC_amount = 0.00)
59
+	{
60
+		$this->set('PRC_amount', $PRC_amount);
61
+	}
62
+
63
+
64
+	/**
65
+	 *        Set Price Name
66
+	 *
67
+	 * @access        public
68
+	 * @param        string $PRC_name
69
+	 */
70
+	public function set_name($PRC_name = '')
71
+	{
72
+		$this->set('PRC_name', $PRC_name);
73
+	}
74
+
75
+
76
+	/**
77
+	 *        Set Price Description
78
+	 *
79
+	 * @access        public
80
+	 * @param        string $PRC_desc
81
+	 */
82
+	public function set_description($PRC_desc = '')
83
+	{
84
+		$this->Set('PRC_desc', $PRC_desc);
85
+	}
86
+
87
+
88
+	/**
89
+	 *        set is_default
90
+	 *
91
+	 * @access        public
92
+	 * @param        bool $PRC_is_default
93
+	 */
94
+	public function set_is_default($PRC_is_default = false)
95
+	{
96
+		$this->set('PRC_is_default', $PRC_is_default);
97
+	}
98
+
99
+
100
+	/**
101
+	 *        set deleted
102
+	 *
103
+	 * @access        public
104
+	 * @param        bool $PRC_deleted
105
+	 */
106
+	public function set_deleted($PRC_deleted = null)
107
+	{
108
+		$this->set('PRC_deleted', $PRC_deleted);
109
+	}
110
+
111
+
112
+	/**
113
+	 *    get Price type
114
+	 *
115
+	 * @access        public
116
+	 * @return        int
117
+	 */
118
+	public function type()
119
+	{
120
+		return $this->get('PRT_ID');
121
+	}
122
+
123
+
124
+	/**
125
+	 *    get Price Amount
126
+	 *
127
+	 * @access        public
128
+	 * @return        float
129
+	 */
130
+	public function amount()
131
+	{
132
+		return $this->get('PRC_amount');
133
+	}
134
+
135
+
136
+	/**
137
+	 *    get Price Name
138
+	 *
139
+	 * @access        public
140
+	 * @return        string
141
+	 */
142
+	public function name()
143
+	{
144
+		return $this->get('PRC_name');
145
+	}
146
+
147
+
148
+	/**
149
+	 *    get Price description
150
+	 *
151
+	 * @access        public
152
+	 * @return        string
153
+	 */
154
+	public function desc()
155
+	{
156
+		return $this->get('PRC_desc');
157
+	}
158
+
159
+
160
+	/**
161
+	 *    get overrides
162
+	 *
163
+	 * @access        public
164
+	 * @return        int
165
+	 */
166
+	public function overrides()
167
+	{
168
+		return $this->get('PRC_overrides');
169
+	}
170
+
171
+
172
+	/**
173
+	 *    get order
174
+	 *
175
+	 * @access        public
176
+	 * @return        int
177
+	 */
178
+	public function order()
179
+	{
180
+		return $this->get('PRC_order');
181
+	}
182
+
183
+
184
+	/**
185
+	 * get the author of the price
186
+	 *
187
+	 * @since 4.5.0
188
+	 *
189
+	 * @return int
190
+	 */
191
+	public function wp_user()
192
+	{
193
+		return $this->get('PRC_wp_user');
194
+	}
195
+
196
+
197
+	/**
198
+	 *    get is_default
199
+	 *
200
+	 * @access        public
201
+	 * @return        bool
202
+	 */
203
+	public function is_default()
204
+	{
205
+		return $this->get('PRC_is_default');
206
+	}
207
+
208
+
209
+	/**
210
+	 *    get deleted
211
+	 *
212
+	 * @access        public
213
+	 * @return        bool
214
+	 */
215
+	public function deleted()
216
+	{
217
+		return $this->get('PRC_deleted');
218
+	}
219
+
220
+
221
+	/**
222
+	 * @return bool
223
+	 */
224
+	public function parent()
225
+	{
226
+		return $this->get('PRC_parent');
227
+	}
228
+
229
+
230
+	// some helper methods for getting info on the price_type for this price
231
+
232
+	/**
233
+	 * return whether the price is a base price or not
234
+	 *
235
+	 * @return boolean
236
+	 */
237
+	public function is_base_price()
238
+	{
239
+		$price_type = $this->type_obj();
240
+		return $price_type->base_type() === 1;
241
+	}
242
+
243
+
244
+	/**
245
+	 *
246
+	 * @return EE_Price_Type
247
+	 */
248
+	public function type_obj()
249
+	{
250
+		return $this->get_first_related('Price_Type');
251
+	}
252
+
253
+
254
+	/**
255
+	 * Simply indicates whether this price increases or decreases the total
256
+	 *
257
+	 * @return boolean true = discount, otherwise adds to the total
258
+	 */
259
+	public function is_discount()
260
+	{
261
+		$price_type = $this->type_obj();
262
+		return $price_type->is_discount();
263
+	}
264
+
265
+
266
+	/**
267
+	 * whether the price is a percentage or not
268
+	 *
269
+	 * @return boolean
270
+	 */
271
+	public function is_percent()
272
+	{
273
+		$price_type = $this->type_obj();
274
+		return $price_type->get('PRT_is_percent');
275
+	}
276
+
277
+
278
+	/**
279
+	 * return pretty price dependant on whether its a dollar or percent.
280
+	 *
281
+	 * @since 4.4.0
282
+	 *
283
+	 * @return string
284
+	 */
285
+	public function pretty_price()
286
+	{
287
+		return ! $this->is_percent() ? $this->get_pretty('PRC_amount') : $this->get('PRC_amount') . '%';
288
+	}
289
+
290
+
291
+	/**
292
+	 * @return mixed
293
+	 */
294
+	public function get_price_without_currency_symbol()
295
+	{
296
+		return str_replace(EE_Registry::instance()->CFG->currency->sign, '', $this->get_pretty('PRC_amount'));
297
+	}
298 298
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Term_Relationship.class.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -10,23 +10,23 @@
 block discarded – undo
10 10
 class EE_Term_Relationship extends EE_Base_Class
11 11
 {
12 12
 
13
-    /**
14
-     * @param array $props_n_values
15
-     * @return EE_Term_Relationship
16
-     */
17
-    public static function new_instance($props_n_values = array())
18
-    {
19
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
20
-        return $has_object ? $has_object : new self($props_n_values);
21
-    }
13
+	/**
14
+	 * @param array $props_n_values
15
+	 * @return EE_Term_Relationship
16
+	 */
17
+	public static function new_instance($props_n_values = array())
18
+	{
19
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
20
+		return $has_object ? $has_object : new self($props_n_values);
21
+	}
22 22
 
23 23
 
24
-    /**
25
-     * @param array $props_n_values
26
-     * @return EE_Term_Relationship
27
-     */
28
-    public static function new_instance_from_db($props_n_values = array())
29
-    {
30
-        return new self($props_n_values, true);
31
-    }
24
+	/**
25
+	 * @param array $props_n_values
26
+	 * @return EE_Term_Relationship
27
+	 */
28
+	public static function new_instance_from_db($props_n_values = array())
29
+	{
30
+		return new self($props_n_values, true);
31
+	}
32 32
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Export.class.php 2 patches
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
     {
45 45
         $this->_req_data = $request_data;
46 46
         $this->today = date("Y-m-d", time());
47
-        require_once(EE_CLASSES . 'EE_CSV.class.php');
47
+        require_once(EE_CLASSES.'EE_CSV.class.php');
48 48
         $this->EE_CSV = EE_CSV::instance();
49 49
     }
50 50
 
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
                 $value_to_equal = $EVT_ID;
168 168
                 $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($EVT_ID);
169 169
 
170
-                $filename = 'event-' . ($event instanceof EE_Event ? $event->slug() : __('unknown', 'event_espresso'));
170
+                $filename = 'event-'.($event instanceof EE_Event ? $event->slug() : __('unknown', 'event_espresso'));
171 171
             }
172 172
             $event_query_params[0]['EVT_ID'] = $value_to_equal;
173 173
             $related_models_query_params[0]['Event.EVT_ID'] = $value_to_equal;
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 
217 217
         $filename = $this->generate_filename($filename);
218 218
 
219
-        if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) {
219
+        if ( ! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) {
220 220
             EE_Error::add_error(
221 221
                 __(
222 222
                     "'An error occurred and the Event details could not be exported from the database.'",
@@ -243,16 +243,16 @@  discard block
 block discarded – undo
243 243
             foreach (EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) {
244 244
                 if ($field_name == 'STA_ID') {
245 245
                     $state_name_field = EEM_State::instance()->field_settings_for('STA_name');
246
-                    $csv_row[ __('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column(
247
-                    ) ];
246
+                    $csv_row[__('State', 'event_espresso')] = $attendee_row[$state_name_field->get_qualified_column(
247
+                    )];
248 248
                 } elseif ($field_name == 'CNT_ISO') {
249 249
                     $country_name_field = EEM_Country::instance()->field_settings_for('CNT_name');
250
-                    $csv_row[ __(
250
+                    $csv_row[__(
251 251
                         'Country',
252 252
                         'event_espresso'
253
-                    ) ] = $attendee_row[ $country_name_field->get_qualified_column() ];
253
+                    )] = $attendee_row[$country_name_field->get_qualified_column()];
254 254
                 } else {
255
-                    $csv_row[ $field_obj->get_nicename() ] = $attendee_row[ $field_obj->get_qualified_column() ];
255
+                    $csv_row[$field_obj->get_nicename()] = $attendee_row[$field_obj->get_qualified_column()];
256 256
                 }
257 257
             }
258 258
             $csv_data[] = $csv_row;
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
         $model_data = $this->_get_export_data_for_models($models_to_export);
292 292
         $filename = $this->generate_filename('all-attendees');
293 293
 
294
-        if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) {
294
+        if ( ! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) {
295 295
             EE_Error::add_error(
296 296
                 __(
297 297
                     'An error occurred and the Attendee data could not be exported from the database.',
@@ -409,9 +409,9 @@  discard block
 block discarded – undo
409 409
         foreach ($registration_rows as $reg_row) {
410 410
             if (is_array($reg_row)) {
411 411
                 $reg_csv_array = array();
412
-                if (! $event_id) {
412
+                if ( ! $event_id) {
413 413
                     // get the event's name and Id
414
-                    $reg_csv_array[ __('Event', 'event_espresso') ] = sprintf(
414
+                    $reg_csv_array[__('Event', 'event_espresso')] = sprintf(
415 415
                         __('%1$s (%2$s)', 'event_espresso'),
416 416
                         $this->_prepare_value_from_db_for_display(
417 417
                             EEM_Event::instance(),
@@ -457,13 +457,13 @@  discard block
 block discarded – undo
457 457
                         $value = $this->_prepare_value_from_db_for_display(
458 458
                             $reg_model,
459 459
                             $field_name,
460
-                            $reg_row[ $field->get_qualified_column() ]
460
+                            $reg_row[$field->get_qualified_column()]
461 461
                         );
462 462
                     }
463
-                    $reg_csv_array[ $this->_get_column_name_for_field($field) ] = $value;
463
+                    $reg_csv_array[$this->_get_column_name_for_field($field)] = $value;
464 464
                     if ($field_name == 'REG_final_price') {
465 465
                         // add a column named Currency after the final price
466
-                        $reg_csv_array[ __("Currency", "event_espresso") ] = EE_Config::instance()->currency->code;
466
+                        $reg_csv_array[__("Currency", "event_espresso")] = EE_Config::instance()->currency->code;
467 467
                     }
468 468
                 }
469 469
                 // get pretty status
@@ -475,23 +475,23 @@  discard block
 block discarded – undo
475 475
                     false,
476 476
                     'sentence'
477 477
                 );
478
-                $reg_csv_array[ __(
478
+                $reg_csv_array[__(
479 479
                     "Registration Status",
480 480
                     'event_espresso'
481
-                ) ] = $stati[ $reg_row['Registration.STS_ID'] ];
481
+                )] = $stati[$reg_row['Registration.STS_ID']];
482 482
                 // get pretty trnasaction status
483
-                $reg_csv_array[ __(
483
+                $reg_csv_array[__(
484 484
                     "Transaction Status",
485 485
                     'event_espresso'
486
-                ) ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
487
-                $reg_csv_array[ __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
486
+                )] = $stati[$reg_row['TransactionTable.STS_ID']];
487
+                $reg_csv_array[__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg
488 488
                     ? $this->_prepare_value_from_db_for_display(
489 489
                         EEM_Transaction::instance(),
490 490
                         'TXN_total',
491 491
                         $reg_row['TransactionTable.TXN_total'],
492 492
                         'localized_float'
493 493
                     ) : '0.00';
494
-                $reg_csv_array[ __('Amount Paid', 'event_espresso') ] = $is_primary_reg
494
+                $reg_csv_array[__('Amount Paid', 'event_espresso')] = $is_primary_reg
495 495
                     ? $this->_prepare_value_from_db_for_display(
496 496
                         EEM_Transaction::instance(),
497 497
                         'TXN_paid',
@@ -523,15 +523,15 @@  discard block
 block discarded – undo
523 523
                             ? $payment_method_and_gateway_txn_id['payment_time'] : '';
524 524
                     }
525 525
                 }
526
-                $reg_csv_array[ __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
527
-                $reg_csv_array[ __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
528
-                $reg_csv_array[ __('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
526
+                $reg_csv_array[__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times);
527
+                $reg_csv_array[__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods);
528
+                $reg_csv_array[__('Gateway Transaction ID(s)', 'event_espresso')] = implode(
529 529
                     ',',
530 530
                     $gateway_txn_ids_etc
531 531
                 );
532 532
 
533 533
                 // get whether or not the user has checked in
534
-                $reg_csv_array[ __("Check-Ins", "event_espresso") ] = $reg_model->count_related(
534
+                $reg_csv_array[__("Check-Ins", "event_espresso")] = $reg_model->count_related(
535 535
                     $reg_row['Registration.REG_ID'],
536 536
                     'Checkin'
537 537
                 );
@@ -561,8 +561,8 @@  discard block
 block discarded – undo
561 561
                     $ticket_name = __('Unknown', 'event_espresso');
562 562
                     $datetimes_strings = array(__('Unknown', 'event_espresso'));
563 563
                 }
564
-                $reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
565
-                $reg_csv_array[ __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
564
+                $reg_csv_array[$ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name;
565
+                $reg_csv_array[__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings);
566 566
                 // get datetime(s) of registration
567 567
 
568 568
                 // add attendee columns
@@ -583,20 +583,20 @@  discard block
 block discarded – undo
583 583
                             $value = $this->_prepare_value_from_db_for_display(
584 584
                                 EEM_Attendee::instance(),
585 585
                                 $att_field_name,
586
-                                $reg_row[ $field_obj->get_qualified_column() ]
586
+                                $reg_row[$field_obj->get_qualified_column()]
587 587
                             );
588 588
                         }
589 589
                     } else {
590 590
                         $value = '';
591 591
                     }
592 592
 
593
-                    $reg_csv_array[ $this->_get_column_name_for_field($field_obj) ] = $value;
593
+                    $reg_csv_array[$this->_get_column_name_for_field($field_obj)] = $value;
594 594
                 }
595 595
 
596 596
                 // make sure each registration has the same questions in the same order
597 597
                 foreach ($questions_for_these_regs_rows as $question_row) {
598
-                    if (! isset($reg_csv_array[ $question_row['Question.QST_admin_label'] ])) {
599
-                        $reg_csv_array[ $question_row['Question.QST_admin_label'] ] = null;
598
+                    if ( ! isset($reg_csv_array[$question_row['Question.QST_admin_label']])) {
599
+                        $reg_csv_array[$question_row['Question.QST_admin_label']] = null;
600 600
                     }
601 601
                 }
602 602
                 // now fill out the questions THEY answered
@@ -614,11 +614,11 @@  discard block
 block discarded – undo
614 614
                         $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
615 615
                     }
616 616
                     if (isset($answer_row['Question.QST_type']) && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state) {
617
-                        $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
617
+                        $reg_csv_array[$question_label] = EEM_State::instance()->get_state_name_by_ID(
618 618
                             $answer_row['Answer.ANS_value']
619 619
                         );
620 620
                     } else {
621
-                        $reg_csv_array[ $question_label ] = $this->_prepare_value_from_db_for_display(
621
+                        $reg_csv_array[$question_label] = $this->_prepare_value_from_db_for_display(
622 622
                             EEM_Answer::instance(),
623 623
                             'ANS_value',
624 624
                             $answer_row['Answer.ANS_value']
@@ -644,16 +644,16 @@  discard block
 block discarded – undo
644 644
                 $model = EE_Registry::instance()->load_model($model_name);
645 645
                 foreach ($field_list as $field_name) {
646 646
                     $field = $model->field_settings_for($field_name);
647
-                    $reg_csv_array[ $this->_get_column_name_for_field(
647
+                    $reg_csv_array[$this->_get_column_name_for_field(
648 648
                         $field
649
-                    ) ] = null;// $registration->get($field->get_name());
649
+                    )] = null; // $registration->get($field->get_name());
650 650
                 }
651 651
             }
652 652
             $registrations_csv_ready_array [] = $reg_csv_array;
653 653
         }
654 654
         if ($event_id) {
655 655
             $event_slug = EEM_Event::instance()->get_var(array(array('EVT_ID' => $event_id)), 'EVT_slug');
656
-            if (! $event_slug) {
656
+            if ( ! $event_slug) {
657 657
                 $event_slug = __('unknown', 'event_espresso');
658 658
             }
659 659
         } else {
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
      */
675 675
     protected function _get_column_name_for_field(EE_Model_Field_Base $field)
676 676
     {
677
-        return $field->get_nicename() . "[" . $field->get_name() . "]";
677
+        return $field->get_nicename()."[".$field->get_name()."]";
678 678
     }
679 679
 
680 680
 
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
             } else {
698 698
                 // generate regular where = clause
699 699
                 $EVT_CAT_ID = absint($this->_req_data['EVT_CAT_ID']);
700
-                $filename = 'event-category#' . $EVT_CAT_ID;
700
+                $filename = 'event-category#'.$EVT_CAT_ID;
701 701
                 $query_params[0]['term_taxonomy_id'] = $EVT_CAT_ID;
702 702
             }
703 703
         } else {
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
         $table_data = $this->_get_export_data_for_models($tables_to_export);
713 713
         $filename = $this->generate_filename($filename);
714 714
 
715
-        if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $table_data)) {
715
+        if ( ! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $table_data)) {
716 716
             EE_Error::add_error(
717 717
                 __(
718 718
                     'An error occurred and the Category details could not be exported from the database.',
@@ -735,8 +735,8 @@  discard block
 block discarded – undo
735 735
     private function generate_filename($export_name = '')
736 736
     {
737 737
         if ($export_name != '') {
738
-            $filename = get_bloginfo('name') . '-' . $export_name;
739
-            $filename = sanitize_key($filename) . '-' . $this->today;
738
+            $filename = get_bloginfo('name').'-'.$export_name;
739
+            $filename = sanitize_key($filename).'-'.$this->today;
740 740
             return $filename;
741 741
         } else {
742 742
             EE_Error::add_error(__("No filename was provided", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
@@ -765,25 +765,25 @@  discard block
 block discarded – undo
765 765
                 $model = EE_Registry::instance()->load_model($model_name);
766 766
                 $model_objects = $model->get_all($query_params);
767 767
 
768
-                $table_data[ $model_name ] = array();
768
+                $table_data[$model_name] = array();
769 769
                 foreach ($model_objects as $model_object) {
770 770
                     $model_data_array = array();
771 771
                     $fields = $model->field_settings();
772 772
                     foreach ($fields as $field) {
773
-                        $column_name = $field->get_nicename() . "[" . $field->get_name() . "]";
773
+                        $column_name = $field->get_nicename()."[".$field->get_name()."]";
774 774
                         if ($field instanceof EE_Datetime_Field) {
775 775
                             // $field->set_date_format('Y-m-d');
776 776
                             // $field->set_time_format('H:i:s');
777
-                            $model_data_array[ $column_name ] = $model_object->get_datetime(
777
+                            $model_data_array[$column_name] = $model_object->get_datetime(
778 778
                                 $field->get_name(),
779 779
                                 'Y-m-d',
780 780
                                 'H:i:s'
781 781
                             );
782 782
                         } else {
783
-                            $model_data_array[ $column_name ] = $model_object->get($field->get_name());
783
+                            $model_data_array[$column_name] = $model_object->get($field->get_name());
784 784
                         }
785 785
                     }
786
-                    $table_data[ $model_name ][] = $model_data_array;
786
+                    $table_data[$model_name][] = $model_data_array;
787 787
                 }
788 788
             }
789 789
         }
Please login to merge, or discard this patch.
Indentation   +773 added lines, -773 removed lines patch added patch discarded remove patch
@@ -16,777 +16,777 @@
 block discarded – undo
16 16
 class EE_Export
17 17
 {
18 18
 
19
-    const option_prefix = 'ee_report_job_';
20
-
21
-
22
-    // instance of the EE_Export object
23
-    private static $_instance = null;
24
-
25
-    // instance of the EE_CSV object
26
-    /**
27
-     *
28
-     * @var EE_CSV
29
-     */
30
-    public $EE_CSV = null;
31
-
32
-
33
-    private $_req_data = array();
34
-
35
-
36
-    /**
37
-     *        private constructor to prevent direct creation
38
-     *
39
-     * @Constructor
40
-     * @access private
41
-     * @param array $request_data
42
-     */
43
-    private function __construct($request_data = array())
44
-    {
45
-        $this->_req_data = $request_data;
46
-        $this->today = date("Y-m-d", time());
47
-        require_once(EE_CLASSES . 'EE_CSV.class.php');
48
-        $this->EE_CSV = EE_CSV::instance();
49
-    }
50
-
51
-
52
-    /**
53
-     *        @ singleton method used to instantiate class object
54
-     *        @ access public
55
-     *
56
-     * @param array $request_data
57
-     * @return \EE_Export
58
-     */
59
-    public static function instance($request_data = array())
60
-    {
61
-        // check if class object is instantiated
62
-        if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Export)) {
63
-            self::$_instance = new self($request_data);
64
-        }
65
-        return self::$_instance;
66
-    }
67
-
68
-
69
-    /**
70
-     * @Export Event Espresso data - routes export requests
71
-     * @access public
72
-     * @return void | bool
73
-     */
74
-    public function export()
75
-    {
76
-        // in case of bulk exports, the "actual" action will be in action2, but first check regular action for "export" keyword
77
-        if (isset($this->_req_data['action']) && strpos($this->_req_data['action'], 'export') === false) {
78
-            // check if action2 has export action
79
-            if (isset($this->_req_data['action2']) && strpos($this->_req_data['action2'], 'export') !== false) {
80
-                // whoop! there it is!
81
-                $this->_req_data['action'] = $this->_req_data['action2'];
82
-            }
83
-        }
84
-
85
-        $this->_req_data['export'] = isset($this->_req_data['export']) ? $this->_req_data['export'] : '';
86
-
87
-        switch ($this->_req_data['export']) {
88
-            case 'report':
89
-                switch ($this->_req_data['action']) {
90
-                    case "event":
91
-                    case "export_events":
92
-                    case 'all_event_data':
93
-                        $this->export_all_event_data();
94
-                        break;
95
-
96
-                    case 'registrations_report_for_event':
97
-                        $this->report_registrations_for_event($this->_req_data['EVT_ID']);
98
-                        break;
99
-
100
-                    case 'attendees':
101
-                        $this->export_attendees();
102
-                        break;
103
-
104
-                    case 'categories':
105
-                        $this->export_categories();
106
-                        break;
107
-
108
-                    default:
109
-                        EE_Error::add_error(
110
-                            __('An error occurred! The requested export report could not be found.', 'event_espresso'),
111
-                            __FILE__,
112
-                            __FUNCTION__,
113
-                            __LINE__
114
-                        );
115
-                        return false;
116
-                        break;
117
-                }
118
-                break; // end of switch export : report
119
-            default:
120
-                break;
121
-        } // end of switch export
122
-
123
-        exit;
124
-    }
125
-
126
-    /**
127
-     * Downloads a CSV file with all the columns, but no data. This should be used for importing
128
-     *
129
-     * @return null kills execution
130
-     */
131
-    public function export_sample()
132
-    {
133
-        $event = EEM_Event::instance()->get_one();
134
-        $this->_req_data['EVT_ID'] = $event->ID();
135
-        $this->export_all_event_data();
136
-    }
137
-
138
-
139
-    /**
140
-     * @Export data for ALL events
141
-     * @access public
142
-     * @return void
143
-     */
144
-    public function export_all_event_data()
145
-    {
146
-        // are any Event IDs set?
147
-        $event_query_params = array();
148
-        $related_models_query_params = array();
149
-        $related_through_reg_query_params = array();
150
-        $datetime_ticket_query_params = array();
151
-        $price_query_params = array();
152
-        $price_type_query_params = array();
153
-        $term_query_params = array();
154
-        $state_country_query_params = array();
155
-        $question_group_query_params = array();
156
-        $question_query_params = array();
157
-        if (isset($this->_req_data['EVT_ID'])) {
158
-            // do we have an array of IDs ?
159
-
160
-            if (is_array($this->_req_data['EVT_ID'])) {
161
-                $EVT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_ID']);
162
-                $value_to_equal = array('IN', $EVT_IDs);
163
-                $filename = 'events';
164
-            } else {
165
-                // generate regular where = clause
166
-                $EVT_ID = absint($this->_req_data['EVT_ID']);
167
-                $value_to_equal = $EVT_ID;
168
-                $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($EVT_ID);
169
-
170
-                $filename = 'event-' . ($event instanceof EE_Event ? $event->slug() : __('unknown', 'event_espresso'));
171
-            }
172
-            $event_query_params[0]['EVT_ID'] = $value_to_equal;
173
-            $related_models_query_params[0]['Event.EVT_ID'] = $value_to_equal;
174
-            $related_through_reg_query_params[0]['Registration.EVT_ID'] = $value_to_equal;
175
-            $datetime_ticket_query_params[0]['Datetime.EVT_ID'] = $value_to_equal;
176
-            $price_query_params[0]['Ticket.Datetime.EVT_ID'] = $value_to_equal;
177
-            $price_type_query_params[0]['Price.Ticket.Datetime.EVT_ID'] = $value_to_equal;
178
-            $term_query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $value_to_equal;
179
-            $state_country_query_params[0]['Venue.Event.EVT_ID'] = $value_to_equal;
180
-            $question_group_query_params[0]['Event.EVT_ID'] = $value_to_equal;
181
-            $question_query_params[0]['Question_Group.Event.EVT_ID'] = $value_to_equal;
182
-        } else {
183
-            $filename = 'all-events';
184
-        }
185
-
186
-
187
-        // array in the format:  table name =>  query where clause
188
-        $models_to_export = array(
189
-            'Event'                   => $event_query_params,
190
-            'Datetime'                => $related_models_query_params,
191
-            'Ticket_Template'         => $price_query_params,
192
-            'Ticket'                  => $datetime_ticket_query_params,
193
-            'Datetime_Ticket'         => $datetime_ticket_query_params,
194
-            'Price_Type'              => $price_type_query_params,
195
-            'Price'                   => $price_query_params,
196
-            'Ticket_Price'            => $price_query_params,
197
-            'Term'                    => $term_query_params,
198
-            'Term_Taxonomy'           => $related_models_query_params,
199
-            'Term_Relationship'       => $related_models_query_params, // model has NO primary key...
200
-            'Country'                 => $state_country_query_params,
201
-            'State'                   => $state_country_query_params,
202
-            'Venue'                   => $related_models_query_params,
203
-            'Event_Venue'             => $related_models_query_params,
204
-            'Question_Group'          => $question_group_query_params,
205
-            'Event_Question_Group'    => $question_group_query_params,
206
-            'Question'                => $question_query_params,
207
-            'Question_Group_Question' => $question_query_params,
208
-            // 'Transaction'=>$related_through_reg_query_params,
209
-            // 'Registration'=>$related_models_query_params,
210
-            // 'Attendee'=>$related_through_reg_query_params,
211
-            // 'Line_Item'=>
212
-
213
-        );
214
-
215
-        $model_data = $this->_get_export_data_for_models($models_to_export);
216
-
217
-        $filename = $this->generate_filename($filename);
218
-
219
-        if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) {
220
-            EE_Error::add_error(
221
-                __(
222
-                    "'An error occurred and the Event details could not be exported from the database.'",
223
-                    "event_espresso"
224
-                ),
225
-                __FILE__,
226
-                __FUNCTION__,
227
-                __LINE__
228
-            );
229
-        }
230
-    }
231
-
232
-    public function report_attendees()
233
-    {
234
-        $attendee_rows = EEM_Attendee::instance()->get_all_wpdb_results(
235
-            array(
236
-                'force_join' => array('State', 'Country'),
237
-                'caps'       => EEM_Base::caps_read_admin,
238
-            )
239
-        );
240
-        $csv_data = array();
241
-        foreach ($attendee_rows as $attendee_row) {
242
-            $csv_row = array();
243
-            foreach (EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) {
244
-                if ($field_name == 'STA_ID') {
245
-                    $state_name_field = EEM_State::instance()->field_settings_for('STA_name');
246
-                    $csv_row[ __('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column(
247
-                    ) ];
248
-                } elseif ($field_name == 'CNT_ISO') {
249
-                    $country_name_field = EEM_Country::instance()->field_settings_for('CNT_name');
250
-                    $csv_row[ __(
251
-                        'Country',
252
-                        'event_espresso'
253
-                    ) ] = $attendee_row[ $country_name_field->get_qualified_column() ];
254
-                } else {
255
-                    $csv_row[ $field_obj->get_nicename() ] = $attendee_row[ $field_obj->get_qualified_column() ];
256
-                }
257
-            }
258
-            $csv_data[] = $csv_row;
259
-        }
260
-
261
-        $filename = $this->generate_filename('contact-list-report');
262
-
263
-        $handle = $this->EE_CSV->begin_sending_csv($filename);
264
-        $this->EE_CSV->write_data_array_to_csv($handle, $csv_data);
265
-        $this->EE_CSV->end_sending_csv($handle);
266
-    }
267
-
268
-
269
-    /**
270
-     * @Export data for ALL attendees
271
-     * @access public
272
-     * @return void
273
-     */
274
-    public function export_attendees()
275
-    {
276
-
277
-        $states_that_have_an_attendee = EEM_State::instance()->get_all(
278
-            array(0 => array('Attendee.ATT_ID' => array('IS NOT NULL')))
279
-        );
280
-        $countries_that_have_an_attendee = EEM_Country::instance()->get_all(
281
-            array(0 => array('Attendee.ATT_ID' => array('IS NOT NULL')))
282
-        );
283
-        // $states_to_export_query_params
284
-        $models_to_export = array(
285
-            'Country'  => array(array('CNT_ISO' => array('IN', array_keys($countries_that_have_an_attendee)))),
286
-            'State'    => array(array('STA_ID' => array('IN', array_keys($states_that_have_an_attendee)))),
287
-            'Attendee' => array(),
288
-        );
289
-
290
-
291
-        $model_data = $this->_get_export_data_for_models($models_to_export);
292
-        $filename = $this->generate_filename('all-attendees');
293
-
294
-        if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) {
295
-            EE_Error::add_error(
296
-                __(
297
-                    'An error occurred and the Attendee data could not be exported from the database.',
298
-                    'event_espresso'
299
-                ),
300
-                __FILE__,
301
-                __FUNCTION__,
302
-                __LINE__
303
-            );
304
-        }
305
-    }
306
-
307
-    /**
308
-     * Shortcut for preparing a database result for display
309
-     *
310
-     * @param EEM_Base       $model
311
-     * @param string         $field_name
312
-     * @param string         $raw_db_value
313
-     * @param boolean|string $pretty_schema true to display pretty, a string to use a specific "Schema", or false to
314
-     *                                      NOT display pretty
315
-     * @return string
316
-     */
317
-    protected function _prepare_value_from_db_for_display($model, $field_name, $raw_db_value, $pretty_schema = true)
318
-    {
319
-        $field_obj = $model->field_settings_for($field_name);
320
-        $value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value);
321
-        if ($field_obj instanceof EE_Datetime_Field) {
322
-            $field_obj->set_date_format(
323
-                EE_CSV::instance()->get_date_format_for_csv($field_obj->get_date_format($pretty_schema)),
324
-                $pretty_schema
325
-            );
326
-            $field_obj->set_time_format(
327
-                EE_CSV::instance()->get_time_format_for_csv($field_obj->get_time_format($pretty_schema)),
328
-                $pretty_schema
329
-            );
330
-        }
331
-        if ($pretty_schema === true) {
332
-            return $field_obj->prepare_for_pretty_echoing($value_on_model_obj);
333
-        } elseif (is_string($pretty_schema)) {
334
-            return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema);
335
-        } else {
336
-            return $field_obj->prepare_for_get($value_on_model_obj);
337
-        }
338
-    }
339
-
340
-    /**
341
-     * Export a custom CSV of registration info including: A bunch of the reg fields, the time of the event, the price
342
-     * name, and the questions associated with the registrations
343
-     *
344
-     * @param int $event_id
345
-     */
346
-    public function report_registrations_for_event($event_id = null)
347
-    {
348
-        $reg_fields_to_include = array(
349
-            'TXN_ID',
350
-            'ATT_ID',
351
-            'REG_ID',
352
-            'REG_date',
353
-            'REG_code',
354
-            'REG_count',
355
-            'REG_final_price',
356
-
357
-        );
358
-        $att_fields_to_include = array(
359
-            'ATT_fname',
360
-            'ATT_lname',
361
-            'ATT_email',
362
-            'ATT_address',
363
-            'ATT_address2',
364
-            'ATT_city',
365
-            'STA_ID',
366
-            'CNT_ISO',
367
-            'ATT_zip',
368
-            'ATT_phone',
369
-        );
370
-
371
-        $registrations_csv_ready_array = array();
372
-        $reg_model = EE_Registry::instance()->load_model('Registration');
373
-        $query_params = apply_filters(
374
-            'FHEE__EE_Export__report_registration_for_event',
375
-            array(
376
-                array(
377
-                    'OR'                 => array(
378
-                        // don't include registrations from failed or abandoned transactions...
379
-                        'Transaction.STS_ID' => array(
380
-                            'NOT IN',
381
-                            array(EEM_Transaction::failed_status_code, EEM_Transaction::abandoned_status_code),
382
-                        ),
383
-                        // unless the registration is approved, in which case include it regardless of transaction status
384
-                        'STS_ID'             => EEM_Registration::status_id_approved,
385
-                    ),
386
-                    'Ticket.TKT_deleted' => array('IN', array(true, false)),
387
-                ),
388
-                'order_by'   => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'),
389
-                'force_join' => array('Transaction', 'Ticket', 'Attendee'),
390
-                'caps'       => EEM_Base::caps_read_admin,
391
-            ),
392
-            $event_id
393
-        );
394
-        if ($event_id) {
395
-            $query_params[0]['EVT_ID'] = $event_id;
396
-        } else {
397
-            $query_params['force_join'][] = 'Event';
398
-        }
399
-        $registration_rows = $reg_model->get_all_wpdb_results($query_params);
400
-        // get all questions which relate to someone in this group
401
-        $registration_ids = array();
402
-        foreach ($registration_rows as $reg_row) {
403
-            $registration_ids[] = intval($reg_row['Registration.REG_ID']);
404
-        }
405
-        // EEM_Question::instance()->show_next_x_db_queries();
406
-        $questions_for_these_regs_rows = EEM_Question::instance()->get_all_wpdb_results(
407
-            array(array('Answer.REG_ID' => array('IN', $registration_ids)))
408
-        );
409
-        foreach ($registration_rows as $reg_row) {
410
-            if (is_array($reg_row)) {
411
-                $reg_csv_array = array();
412
-                if (! $event_id) {
413
-                    // get the event's name and Id
414
-                    $reg_csv_array[ __('Event', 'event_espresso') ] = sprintf(
415
-                        __('%1$s (%2$s)', 'event_espresso'),
416
-                        $this->_prepare_value_from_db_for_display(
417
-                            EEM_Event::instance(),
418
-                            'EVT_name',
419
-                            $reg_row['Event_CPT.post_title']
420
-                        ),
421
-                        $reg_row['Event_CPT.ID']
422
-                    );
423
-                }
424
-                $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
425
-                /*@var $reg_row EE_Registration */
426
-                foreach ($reg_fields_to_include as $field_name) {
427
-                    $field = $reg_model->field_settings_for($field_name);
428
-                    if ($field_name == 'REG_final_price') {
429
-                        $value = $this->_prepare_value_from_db_for_display(
430
-                            $reg_model,
431
-                            $field_name,
432
-                            $reg_row['Registration.REG_final_price'],
433
-                            'localized_float'
434
-                        );
435
-                    } elseif ($field_name == 'REG_count') {
436
-                        $value = sprintf(
437
-                            __('%s of %s', 'event_espresso'),
438
-                            $this->_prepare_value_from_db_for_display(
439
-                                $reg_model,
440
-                                'REG_count',
441
-                                $reg_row['Registration.REG_count']
442
-                            ),
443
-                            $this->_prepare_value_from_db_for_display(
444
-                                $reg_model,
445
-                                'REG_group_size',
446
-                                $reg_row['Registration.REG_group_size']
447
-                            )
448
-                        );
449
-                    } elseif ($field_name == 'REG_date') {
450
-                        $value = $this->_prepare_value_from_db_for_display(
451
-                            $reg_model,
452
-                            $field_name,
453
-                            $reg_row['Registration.REG_date'],
454
-                            'no_html'
455
-                        );
456
-                    } else {
457
-                        $value = $this->_prepare_value_from_db_for_display(
458
-                            $reg_model,
459
-                            $field_name,
460
-                            $reg_row[ $field->get_qualified_column() ]
461
-                        );
462
-                    }
463
-                    $reg_csv_array[ $this->_get_column_name_for_field($field) ] = $value;
464
-                    if ($field_name == 'REG_final_price') {
465
-                        // add a column named Currency after the final price
466
-                        $reg_csv_array[ __("Currency", "event_espresso") ] = EE_Config::instance()->currency->code;
467
-                    }
468
-                }
469
-                // get pretty status
470
-                $stati = EEM_Status::instance()->localized_status(
471
-                    array(
472
-                        $reg_row['Registration.STS_ID']     => __('unknown', 'event_espresso'),
473
-                        $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'),
474
-                    ),
475
-                    false,
476
-                    'sentence'
477
-                );
478
-                $reg_csv_array[ __(
479
-                    "Registration Status",
480
-                    'event_espresso'
481
-                ) ] = $stati[ $reg_row['Registration.STS_ID'] ];
482
-                // get pretty trnasaction status
483
-                $reg_csv_array[ __(
484
-                    "Transaction Status",
485
-                    'event_espresso'
486
-                ) ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
487
-                $reg_csv_array[ __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
488
-                    ? $this->_prepare_value_from_db_for_display(
489
-                        EEM_Transaction::instance(),
490
-                        'TXN_total',
491
-                        $reg_row['TransactionTable.TXN_total'],
492
-                        'localized_float'
493
-                    ) : '0.00';
494
-                $reg_csv_array[ __('Amount Paid', 'event_espresso') ] = $is_primary_reg
495
-                    ? $this->_prepare_value_from_db_for_display(
496
-                        EEM_Transaction::instance(),
497
-                        'TXN_paid',
498
-                        $reg_row['TransactionTable.TXN_paid'],
499
-                        'localized_float'
500
-                    ) : '0.00';
501
-                $payment_methods = array();
502
-                $gateway_txn_ids_etc = array();
503
-                $payment_times = array();
504
-                if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
505
-                    $payments_info = EEM_Payment::instance()->get_all_wpdb_results(
506
-                        array(
507
-                            array(
508
-                                'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
509
-                                'STS_ID' => EEM_Payment::status_id_approved,
510
-                            ),
511
-                            'force_join' => array('Payment_Method'),
512
-                        ),
513
-                        ARRAY_A,
514
-                        'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'
515
-                    );
516
-
517
-                    foreach ($payments_info as $payment_method_and_gateway_txn_id) {
518
-                        $payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
519
-                            ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso');
520
-                        $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
521
-                            ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
522
-                        $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
523
-                            ? $payment_method_and_gateway_txn_id['payment_time'] : '';
524
-                    }
525
-                }
526
-                $reg_csv_array[ __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
527
-                $reg_csv_array[ __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
528
-                $reg_csv_array[ __('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
529
-                    ',',
530
-                    $gateway_txn_ids_etc
531
-                );
532
-
533
-                // get whether or not the user has checked in
534
-                $reg_csv_array[ __("Check-Ins", "event_espresso") ] = $reg_model->count_related(
535
-                    $reg_row['Registration.REG_ID'],
536
-                    'Checkin'
537
-                );
538
-                // get ticket of registration and its price
539
-                $ticket_model = EE_Registry::instance()->load_model('Ticket');
540
-                if ($reg_row['Ticket.TKT_ID']) {
541
-                    $ticket_name = $this->_prepare_value_from_db_for_display(
542
-                        $ticket_model,
543
-                        'TKT_name',
544
-                        $reg_row['Ticket.TKT_name']
545
-                    );
546
-                    $datetimes_strings = array();
547
-                    foreach (EEM_Datetime::instance()->get_all_wpdb_results(
548
-                        array(
549
-                            array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']),
550
-                            'order_by'                 => array('DTT_EVT_start' => 'ASC'),
551
-                            'default_where_conditions' => 'none',
552
-                        )
553
-                    ) as $datetime) {
554
-                        $datetimes_strings[] = $this->_prepare_value_from_db_for_display(
555
-                            EEM_Datetime::instance(),
556
-                            'DTT_EVT_start',
557
-                            $datetime['Datetime.DTT_EVT_start']
558
-                        );
559
-                    }
560
-                } else {
561
-                    $ticket_name = __('Unknown', 'event_espresso');
562
-                    $datetimes_strings = array(__('Unknown', 'event_espresso'));
563
-                }
564
-                $reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
565
-                $reg_csv_array[ __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
566
-                // get datetime(s) of registration
567
-
568
-                // add attendee columns
569
-                foreach ($att_fields_to_include as $att_field_name) {
570
-                    $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name);
571
-                    if ($reg_row['Attendee_CPT.ID']) {
572
-                        if ($att_field_name == 'STA_ID') {
573
-                            $value = EEM_State::instance()->get_var(
574
-                                array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])),
575
-                                'STA_name'
576
-                            );
577
-                        } elseif ($att_field_name == 'CNT_ISO') {
578
-                            $value = EEM_Country::instance()->get_var(
579
-                                array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])),
580
-                                'CNT_name'
581
-                            );
582
-                        } else {
583
-                            $value = $this->_prepare_value_from_db_for_display(
584
-                                EEM_Attendee::instance(),
585
-                                $att_field_name,
586
-                                $reg_row[ $field_obj->get_qualified_column() ]
587
-                            );
588
-                        }
589
-                    } else {
590
-                        $value = '';
591
-                    }
592
-
593
-                    $reg_csv_array[ $this->_get_column_name_for_field($field_obj) ] = $value;
594
-                }
595
-
596
-                // make sure each registration has the same questions in the same order
597
-                foreach ($questions_for_these_regs_rows as $question_row) {
598
-                    if (! isset($reg_csv_array[ $question_row['Question.QST_admin_label'] ])) {
599
-                        $reg_csv_array[ $question_row['Question.QST_admin_label'] ] = null;
600
-                    }
601
-                }
602
-                // now fill out the questions THEY answered
603
-                foreach (EEM_Answer::instance()->get_all_wpdb_results(
604
-                    array(array('REG_ID' => $reg_row['Registration.REG_ID']), 'force_join' => array('Question'))
605
-                ) as $answer_row) {
606
-                    /* @var $answer EE_Answer */
607
-                    if ($answer_row['Question.QST_ID']) {
608
-                        $question_label = $this->_prepare_value_from_db_for_display(
609
-                            EEM_Question::instance(),
610
-                            'QST_admin_label',
611
-                            $answer_row['Question.QST_admin_label']
612
-                        );
613
-                    } else {
614
-                        $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
615
-                    }
616
-                    if (isset($answer_row['Question.QST_type']) && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state) {
617
-                        $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
618
-                            $answer_row['Answer.ANS_value']
619
-                        );
620
-                    } else {
621
-                        $reg_csv_array[ $question_label ] = $this->_prepare_value_from_db_for_display(
622
-                            EEM_Answer::instance(),
623
-                            'ANS_value',
624
-                            $answer_row['Answer.ANS_value']
625
-                        );
626
-                    }
627
-                }
628
-                $registrations_csv_ready_array[] = apply_filters(
629
-                    'FHEE__EE_Export__report_registrations__reg_csv_array',
630
-                    $reg_csv_array,
631
-                    $reg_row
632
-                );
633
-            }
634
-        }
635
-
636
-        // if we couldn't export anything, we want to at least show the column headers
637
-        if (empty($registrations_csv_ready_array)) {
638
-            $reg_csv_array = array();
639
-            $model_and_fields_to_include = array(
640
-                'Registration' => $reg_fields_to_include,
641
-                'Attendee'     => $att_fields_to_include,
642
-            );
643
-            foreach ($model_and_fields_to_include as $model_name => $field_list) {
644
-                $model = EE_Registry::instance()->load_model($model_name);
645
-                foreach ($field_list as $field_name) {
646
-                    $field = $model->field_settings_for($field_name);
647
-                    $reg_csv_array[ $this->_get_column_name_for_field(
648
-                        $field
649
-                    ) ] = null;// $registration->get($field->get_name());
650
-                }
651
-            }
652
-            $registrations_csv_ready_array [] = $reg_csv_array;
653
-        }
654
-        if ($event_id) {
655
-            $event_slug = EEM_Event::instance()->get_var(array(array('EVT_ID' => $event_id)), 'EVT_slug');
656
-            if (! $event_slug) {
657
-                $event_slug = __('unknown', 'event_espresso');
658
-            }
659
-        } else {
660
-            $event_slug = __('all', 'event_espresso');
661
-        }
662
-        $filename = sprintf("registrations-for-%s", $event_slug);
663
-
664
-        $handle = $this->EE_CSV->begin_sending_csv($filename);
665
-        $this->EE_CSV->write_data_array_to_csv($handle, $registrations_csv_ready_array);
666
-        $this->EE_CSV->end_sending_csv($handle);
667
-    }
668
-
669
-    /**
670
-     * Gets the 'normal' column named for fields
671
-     *
672
-     * @param EE_Model_Field_Base $field
673
-     * @return string
674
-     */
675
-    protected function _get_column_name_for_field(EE_Model_Field_Base $field)
676
-    {
677
-        return $field->get_nicename() . "[" . $field->get_name() . "]";
678
-    }
679
-
680
-
681
-    /**
682
-     * @Export data for ALL events
683
-     * @access public
684
-     * @return void
685
-     */
686
-    public function export_categories()
687
-    {
688
-        // are any Event IDs set?
689
-        $query_params = array();
690
-        if (isset($this->_req_data['EVT_CAT_ID'])) {
691
-            // do we have an array of IDs ?
692
-            if (is_array($this->_req_data['EVT_CAT_ID'])) {
693
-                // generate an "IN (CSV)" where clause
694
-                $EVT_CAT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_CAT_ID']);
695
-                $filename = 'event-categories';
696
-                $query_params[0]['term_taxonomy_id'] = array('IN', $EVT_CAT_IDs);
697
-            } else {
698
-                // generate regular where = clause
699
-                $EVT_CAT_ID = absint($this->_req_data['EVT_CAT_ID']);
700
-                $filename = 'event-category#' . $EVT_CAT_ID;
701
-                $query_params[0]['term_taxonomy_id'] = $EVT_CAT_ID;
702
-            }
703
-        } else {
704
-            // no IDs means we will d/l the entire table
705
-            $filename = 'all-categories';
706
-        }
707
-
708
-        $tables_to_export = array(
709
-            'Term_Taxonomy' => $query_params,
710
-        );
711
-
712
-        $table_data = $this->_get_export_data_for_models($tables_to_export);
713
-        $filename = $this->generate_filename($filename);
714
-
715
-        if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $table_data)) {
716
-            EE_Error::add_error(
717
-                __(
718
-                    'An error occurred and the Category details could not be exported from the database.',
719
-                    'event_espresso'
720
-                ),
721
-                __FILE__,
722
-                __FUNCTION__,
723
-                __LINE__
724
-            );
725
-        }
726
-    }
727
-
728
-
729
-    /**
730
-     * @process export name to create a suitable filename
731
-     * @access  private
732
-     * @param string - export_name
733
-     * @return string on success, FALSE on fail
734
-     */
735
-    private function generate_filename($export_name = '')
736
-    {
737
-        if ($export_name != '') {
738
-            $filename = get_bloginfo('name') . '-' . $export_name;
739
-            $filename = sanitize_key($filename) . '-' . $this->today;
740
-            return $filename;
741
-        } else {
742
-            EE_Error::add_error(__("No filename was provided", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
743
-        }
744
-        return false;
745
-    }
746
-
747
-
748
-    /**
749
-     * @recursive function for exporting table data and merging the results with the next results
750
-     * @access    private
751
-     * @param array $models_to_export keys are model names (eg 'Event', 'Attendee', etc.) and values are arrays of
752
-     *                                query params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
753
-     * @return array on success, FALSE on fail
754
-     */
755
-    private function _get_export_data_for_models($models_to_export = array())
756
-    {
757
-        $table_data = false;
758
-        if (is_array($models_to_export)) {
759
-            foreach ($models_to_export as $model_name => $query_params) {
760
-                // check for a numerically-indexed array. in that case, $model_name is the value!!
761
-                if (is_int($model_name)) {
762
-                    $model_name = $query_params;
763
-                    $query_params = array();
764
-                }
765
-                $model = EE_Registry::instance()->load_model($model_name);
766
-                $model_objects = $model->get_all($query_params);
767
-
768
-                $table_data[ $model_name ] = array();
769
-                foreach ($model_objects as $model_object) {
770
-                    $model_data_array = array();
771
-                    $fields = $model->field_settings();
772
-                    foreach ($fields as $field) {
773
-                        $column_name = $field->get_nicename() . "[" . $field->get_name() . "]";
774
-                        if ($field instanceof EE_Datetime_Field) {
775
-                            // $field->set_date_format('Y-m-d');
776
-                            // $field->set_time_format('H:i:s');
777
-                            $model_data_array[ $column_name ] = $model_object->get_datetime(
778
-                                $field->get_name(),
779
-                                'Y-m-d',
780
-                                'H:i:s'
781
-                            );
782
-                        } else {
783
-                            $model_data_array[ $column_name ] = $model_object->get($field->get_name());
784
-                        }
785
-                    }
786
-                    $table_data[ $model_name ][] = $model_data_array;
787
-                }
788
-            }
789
-        }
790
-        return $table_data;
791
-    }
19
+	const option_prefix = 'ee_report_job_';
20
+
21
+
22
+	// instance of the EE_Export object
23
+	private static $_instance = null;
24
+
25
+	// instance of the EE_CSV object
26
+	/**
27
+	 *
28
+	 * @var EE_CSV
29
+	 */
30
+	public $EE_CSV = null;
31
+
32
+
33
+	private $_req_data = array();
34
+
35
+
36
+	/**
37
+	 *        private constructor to prevent direct creation
38
+	 *
39
+	 * @Constructor
40
+	 * @access private
41
+	 * @param array $request_data
42
+	 */
43
+	private function __construct($request_data = array())
44
+	{
45
+		$this->_req_data = $request_data;
46
+		$this->today = date("Y-m-d", time());
47
+		require_once(EE_CLASSES . 'EE_CSV.class.php');
48
+		$this->EE_CSV = EE_CSV::instance();
49
+	}
50
+
51
+
52
+	/**
53
+	 *        @ singleton method used to instantiate class object
54
+	 *        @ access public
55
+	 *
56
+	 * @param array $request_data
57
+	 * @return \EE_Export
58
+	 */
59
+	public static function instance($request_data = array())
60
+	{
61
+		// check if class object is instantiated
62
+		if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Export)) {
63
+			self::$_instance = new self($request_data);
64
+		}
65
+		return self::$_instance;
66
+	}
67
+
68
+
69
+	/**
70
+	 * @Export Event Espresso data - routes export requests
71
+	 * @access public
72
+	 * @return void | bool
73
+	 */
74
+	public function export()
75
+	{
76
+		// in case of bulk exports, the "actual" action will be in action2, but first check regular action for "export" keyword
77
+		if (isset($this->_req_data['action']) && strpos($this->_req_data['action'], 'export') === false) {
78
+			// check if action2 has export action
79
+			if (isset($this->_req_data['action2']) && strpos($this->_req_data['action2'], 'export') !== false) {
80
+				// whoop! there it is!
81
+				$this->_req_data['action'] = $this->_req_data['action2'];
82
+			}
83
+		}
84
+
85
+		$this->_req_data['export'] = isset($this->_req_data['export']) ? $this->_req_data['export'] : '';
86
+
87
+		switch ($this->_req_data['export']) {
88
+			case 'report':
89
+				switch ($this->_req_data['action']) {
90
+					case "event":
91
+					case "export_events":
92
+					case 'all_event_data':
93
+						$this->export_all_event_data();
94
+						break;
95
+
96
+					case 'registrations_report_for_event':
97
+						$this->report_registrations_for_event($this->_req_data['EVT_ID']);
98
+						break;
99
+
100
+					case 'attendees':
101
+						$this->export_attendees();
102
+						break;
103
+
104
+					case 'categories':
105
+						$this->export_categories();
106
+						break;
107
+
108
+					default:
109
+						EE_Error::add_error(
110
+							__('An error occurred! The requested export report could not be found.', 'event_espresso'),
111
+							__FILE__,
112
+							__FUNCTION__,
113
+							__LINE__
114
+						);
115
+						return false;
116
+						break;
117
+				}
118
+				break; // end of switch export : report
119
+			default:
120
+				break;
121
+		} // end of switch export
122
+
123
+		exit;
124
+	}
125
+
126
+	/**
127
+	 * Downloads a CSV file with all the columns, but no data. This should be used for importing
128
+	 *
129
+	 * @return null kills execution
130
+	 */
131
+	public function export_sample()
132
+	{
133
+		$event = EEM_Event::instance()->get_one();
134
+		$this->_req_data['EVT_ID'] = $event->ID();
135
+		$this->export_all_event_data();
136
+	}
137
+
138
+
139
+	/**
140
+	 * @Export data for ALL events
141
+	 * @access public
142
+	 * @return void
143
+	 */
144
+	public function export_all_event_data()
145
+	{
146
+		// are any Event IDs set?
147
+		$event_query_params = array();
148
+		$related_models_query_params = array();
149
+		$related_through_reg_query_params = array();
150
+		$datetime_ticket_query_params = array();
151
+		$price_query_params = array();
152
+		$price_type_query_params = array();
153
+		$term_query_params = array();
154
+		$state_country_query_params = array();
155
+		$question_group_query_params = array();
156
+		$question_query_params = array();
157
+		if (isset($this->_req_data['EVT_ID'])) {
158
+			// do we have an array of IDs ?
159
+
160
+			if (is_array($this->_req_data['EVT_ID'])) {
161
+				$EVT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_ID']);
162
+				$value_to_equal = array('IN', $EVT_IDs);
163
+				$filename = 'events';
164
+			} else {
165
+				// generate regular where = clause
166
+				$EVT_ID = absint($this->_req_data['EVT_ID']);
167
+				$value_to_equal = $EVT_ID;
168
+				$event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($EVT_ID);
169
+
170
+				$filename = 'event-' . ($event instanceof EE_Event ? $event->slug() : __('unknown', 'event_espresso'));
171
+			}
172
+			$event_query_params[0]['EVT_ID'] = $value_to_equal;
173
+			$related_models_query_params[0]['Event.EVT_ID'] = $value_to_equal;
174
+			$related_through_reg_query_params[0]['Registration.EVT_ID'] = $value_to_equal;
175
+			$datetime_ticket_query_params[0]['Datetime.EVT_ID'] = $value_to_equal;
176
+			$price_query_params[0]['Ticket.Datetime.EVT_ID'] = $value_to_equal;
177
+			$price_type_query_params[0]['Price.Ticket.Datetime.EVT_ID'] = $value_to_equal;
178
+			$term_query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $value_to_equal;
179
+			$state_country_query_params[0]['Venue.Event.EVT_ID'] = $value_to_equal;
180
+			$question_group_query_params[0]['Event.EVT_ID'] = $value_to_equal;
181
+			$question_query_params[0]['Question_Group.Event.EVT_ID'] = $value_to_equal;
182
+		} else {
183
+			$filename = 'all-events';
184
+		}
185
+
186
+
187
+		// array in the format:  table name =>  query where clause
188
+		$models_to_export = array(
189
+			'Event'                   => $event_query_params,
190
+			'Datetime'                => $related_models_query_params,
191
+			'Ticket_Template'         => $price_query_params,
192
+			'Ticket'                  => $datetime_ticket_query_params,
193
+			'Datetime_Ticket'         => $datetime_ticket_query_params,
194
+			'Price_Type'              => $price_type_query_params,
195
+			'Price'                   => $price_query_params,
196
+			'Ticket_Price'            => $price_query_params,
197
+			'Term'                    => $term_query_params,
198
+			'Term_Taxonomy'           => $related_models_query_params,
199
+			'Term_Relationship'       => $related_models_query_params, // model has NO primary key...
200
+			'Country'                 => $state_country_query_params,
201
+			'State'                   => $state_country_query_params,
202
+			'Venue'                   => $related_models_query_params,
203
+			'Event_Venue'             => $related_models_query_params,
204
+			'Question_Group'          => $question_group_query_params,
205
+			'Event_Question_Group'    => $question_group_query_params,
206
+			'Question'                => $question_query_params,
207
+			'Question_Group_Question' => $question_query_params,
208
+			// 'Transaction'=>$related_through_reg_query_params,
209
+			// 'Registration'=>$related_models_query_params,
210
+			// 'Attendee'=>$related_through_reg_query_params,
211
+			// 'Line_Item'=>
212
+
213
+		);
214
+
215
+		$model_data = $this->_get_export_data_for_models($models_to_export);
216
+
217
+		$filename = $this->generate_filename($filename);
218
+
219
+		if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) {
220
+			EE_Error::add_error(
221
+				__(
222
+					"'An error occurred and the Event details could not be exported from the database.'",
223
+					"event_espresso"
224
+				),
225
+				__FILE__,
226
+				__FUNCTION__,
227
+				__LINE__
228
+			);
229
+		}
230
+	}
231
+
232
+	public function report_attendees()
233
+	{
234
+		$attendee_rows = EEM_Attendee::instance()->get_all_wpdb_results(
235
+			array(
236
+				'force_join' => array('State', 'Country'),
237
+				'caps'       => EEM_Base::caps_read_admin,
238
+			)
239
+		);
240
+		$csv_data = array();
241
+		foreach ($attendee_rows as $attendee_row) {
242
+			$csv_row = array();
243
+			foreach (EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) {
244
+				if ($field_name == 'STA_ID') {
245
+					$state_name_field = EEM_State::instance()->field_settings_for('STA_name');
246
+					$csv_row[ __('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column(
247
+					) ];
248
+				} elseif ($field_name == 'CNT_ISO') {
249
+					$country_name_field = EEM_Country::instance()->field_settings_for('CNT_name');
250
+					$csv_row[ __(
251
+						'Country',
252
+						'event_espresso'
253
+					) ] = $attendee_row[ $country_name_field->get_qualified_column() ];
254
+				} else {
255
+					$csv_row[ $field_obj->get_nicename() ] = $attendee_row[ $field_obj->get_qualified_column() ];
256
+				}
257
+			}
258
+			$csv_data[] = $csv_row;
259
+		}
260
+
261
+		$filename = $this->generate_filename('contact-list-report');
262
+
263
+		$handle = $this->EE_CSV->begin_sending_csv($filename);
264
+		$this->EE_CSV->write_data_array_to_csv($handle, $csv_data);
265
+		$this->EE_CSV->end_sending_csv($handle);
266
+	}
267
+
268
+
269
+	/**
270
+	 * @Export data for ALL attendees
271
+	 * @access public
272
+	 * @return void
273
+	 */
274
+	public function export_attendees()
275
+	{
276
+
277
+		$states_that_have_an_attendee = EEM_State::instance()->get_all(
278
+			array(0 => array('Attendee.ATT_ID' => array('IS NOT NULL')))
279
+		);
280
+		$countries_that_have_an_attendee = EEM_Country::instance()->get_all(
281
+			array(0 => array('Attendee.ATT_ID' => array('IS NOT NULL')))
282
+		);
283
+		// $states_to_export_query_params
284
+		$models_to_export = array(
285
+			'Country'  => array(array('CNT_ISO' => array('IN', array_keys($countries_that_have_an_attendee)))),
286
+			'State'    => array(array('STA_ID' => array('IN', array_keys($states_that_have_an_attendee)))),
287
+			'Attendee' => array(),
288
+		);
289
+
290
+
291
+		$model_data = $this->_get_export_data_for_models($models_to_export);
292
+		$filename = $this->generate_filename('all-attendees');
293
+
294
+		if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) {
295
+			EE_Error::add_error(
296
+				__(
297
+					'An error occurred and the Attendee data could not be exported from the database.',
298
+					'event_espresso'
299
+				),
300
+				__FILE__,
301
+				__FUNCTION__,
302
+				__LINE__
303
+			);
304
+		}
305
+	}
306
+
307
+	/**
308
+	 * Shortcut for preparing a database result for display
309
+	 *
310
+	 * @param EEM_Base       $model
311
+	 * @param string         $field_name
312
+	 * @param string         $raw_db_value
313
+	 * @param boolean|string $pretty_schema true to display pretty, a string to use a specific "Schema", or false to
314
+	 *                                      NOT display pretty
315
+	 * @return string
316
+	 */
317
+	protected function _prepare_value_from_db_for_display($model, $field_name, $raw_db_value, $pretty_schema = true)
318
+	{
319
+		$field_obj = $model->field_settings_for($field_name);
320
+		$value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value);
321
+		if ($field_obj instanceof EE_Datetime_Field) {
322
+			$field_obj->set_date_format(
323
+				EE_CSV::instance()->get_date_format_for_csv($field_obj->get_date_format($pretty_schema)),
324
+				$pretty_schema
325
+			);
326
+			$field_obj->set_time_format(
327
+				EE_CSV::instance()->get_time_format_for_csv($field_obj->get_time_format($pretty_schema)),
328
+				$pretty_schema
329
+			);
330
+		}
331
+		if ($pretty_schema === true) {
332
+			return $field_obj->prepare_for_pretty_echoing($value_on_model_obj);
333
+		} elseif (is_string($pretty_schema)) {
334
+			return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema);
335
+		} else {
336
+			return $field_obj->prepare_for_get($value_on_model_obj);
337
+		}
338
+	}
339
+
340
+	/**
341
+	 * Export a custom CSV of registration info including: A bunch of the reg fields, the time of the event, the price
342
+	 * name, and the questions associated with the registrations
343
+	 *
344
+	 * @param int $event_id
345
+	 */
346
+	public function report_registrations_for_event($event_id = null)
347
+	{
348
+		$reg_fields_to_include = array(
349
+			'TXN_ID',
350
+			'ATT_ID',
351
+			'REG_ID',
352
+			'REG_date',
353
+			'REG_code',
354
+			'REG_count',
355
+			'REG_final_price',
356
+
357
+		);
358
+		$att_fields_to_include = array(
359
+			'ATT_fname',
360
+			'ATT_lname',
361
+			'ATT_email',
362
+			'ATT_address',
363
+			'ATT_address2',
364
+			'ATT_city',
365
+			'STA_ID',
366
+			'CNT_ISO',
367
+			'ATT_zip',
368
+			'ATT_phone',
369
+		);
370
+
371
+		$registrations_csv_ready_array = array();
372
+		$reg_model = EE_Registry::instance()->load_model('Registration');
373
+		$query_params = apply_filters(
374
+			'FHEE__EE_Export__report_registration_for_event',
375
+			array(
376
+				array(
377
+					'OR'                 => array(
378
+						// don't include registrations from failed or abandoned transactions...
379
+						'Transaction.STS_ID' => array(
380
+							'NOT IN',
381
+							array(EEM_Transaction::failed_status_code, EEM_Transaction::abandoned_status_code),
382
+						),
383
+						// unless the registration is approved, in which case include it regardless of transaction status
384
+						'STS_ID'             => EEM_Registration::status_id_approved,
385
+					),
386
+					'Ticket.TKT_deleted' => array('IN', array(true, false)),
387
+				),
388
+				'order_by'   => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'),
389
+				'force_join' => array('Transaction', 'Ticket', 'Attendee'),
390
+				'caps'       => EEM_Base::caps_read_admin,
391
+			),
392
+			$event_id
393
+		);
394
+		if ($event_id) {
395
+			$query_params[0]['EVT_ID'] = $event_id;
396
+		} else {
397
+			$query_params['force_join'][] = 'Event';
398
+		}
399
+		$registration_rows = $reg_model->get_all_wpdb_results($query_params);
400
+		// get all questions which relate to someone in this group
401
+		$registration_ids = array();
402
+		foreach ($registration_rows as $reg_row) {
403
+			$registration_ids[] = intval($reg_row['Registration.REG_ID']);
404
+		}
405
+		// EEM_Question::instance()->show_next_x_db_queries();
406
+		$questions_for_these_regs_rows = EEM_Question::instance()->get_all_wpdb_results(
407
+			array(array('Answer.REG_ID' => array('IN', $registration_ids)))
408
+		);
409
+		foreach ($registration_rows as $reg_row) {
410
+			if (is_array($reg_row)) {
411
+				$reg_csv_array = array();
412
+				if (! $event_id) {
413
+					// get the event's name and Id
414
+					$reg_csv_array[ __('Event', 'event_espresso') ] = sprintf(
415
+						__('%1$s (%2$s)', 'event_espresso'),
416
+						$this->_prepare_value_from_db_for_display(
417
+							EEM_Event::instance(),
418
+							'EVT_name',
419
+							$reg_row['Event_CPT.post_title']
420
+						),
421
+						$reg_row['Event_CPT.ID']
422
+					);
423
+				}
424
+				$is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
425
+				/*@var $reg_row EE_Registration */
426
+				foreach ($reg_fields_to_include as $field_name) {
427
+					$field = $reg_model->field_settings_for($field_name);
428
+					if ($field_name == 'REG_final_price') {
429
+						$value = $this->_prepare_value_from_db_for_display(
430
+							$reg_model,
431
+							$field_name,
432
+							$reg_row['Registration.REG_final_price'],
433
+							'localized_float'
434
+						);
435
+					} elseif ($field_name == 'REG_count') {
436
+						$value = sprintf(
437
+							__('%s of %s', 'event_espresso'),
438
+							$this->_prepare_value_from_db_for_display(
439
+								$reg_model,
440
+								'REG_count',
441
+								$reg_row['Registration.REG_count']
442
+							),
443
+							$this->_prepare_value_from_db_for_display(
444
+								$reg_model,
445
+								'REG_group_size',
446
+								$reg_row['Registration.REG_group_size']
447
+							)
448
+						);
449
+					} elseif ($field_name == 'REG_date') {
450
+						$value = $this->_prepare_value_from_db_for_display(
451
+							$reg_model,
452
+							$field_name,
453
+							$reg_row['Registration.REG_date'],
454
+							'no_html'
455
+						);
456
+					} else {
457
+						$value = $this->_prepare_value_from_db_for_display(
458
+							$reg_model,
459
+							$field_name,
460
+							$reg_row[ $field->get_qualified_column() ]
461
+						);
462
+					}
463
+					$reg_csv_array[ $this->_get_column_name_for_field($field) ] = $value;
464
+					if ($field_name == 'REG_final_price') {
465
+						// add a column named Currency after the final price
466
+						$reg_csv_array[ __("Currency", "event_espresso") ] = EE_Config::instance()->currency->code;
467
+					}
468
+				}
469
+				// get pretty status
470
+				$stati = EEM_Status::instance()->localized_status(
471
+					array(
472
+						$reg_row['Registration.STS_ID']     => __('unknown', 'event_espresso'),
473
+						$reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'),
474
+					),
475
+					false,
476
+					'sentence'
477
+				);
478
+				$reg_csv_array[ __(
479
+					"Registration Status",
480
+					'event_espresso'
481
+				) ] = $stati[ $reg_row['Registration.STS_ID'] ];
482
+				// get pretty trnasaction status
483
+				$reg_csv_array[ __(
484
+					"Transaction Status",
485
+					'event_espresso'
486
+				) ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
487
+				$reg_csv_array[ __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
488
+					? $this->_prepare_value_from_db_for_display(
489
+						EEM_Transaction::instance(),
490
+						'TXN_total',
491
+						$reg_row['TransactionTable.TXN_total'],
492
+						'localized_float'
493
+					) : '0.00';
494
+				$reg_csv_array[ __('Amount Paid', 'event_espresso') ] = $is_primary_reg
495
+					? $this->_prepare_value_from_db_for_display(
496
+						EEM_Transaction::instance(),
497
+						'TXN_paid',
498
+						$reg_row['TransactionTable.TXN_paid'],
499
+						'localized_float'
500
+					) : '0.00';
501
+				$payment_methods = array();
502
+				$gateway_txn_ids_etc = array();
503
+				$payment_times = array();
504
+				if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
505
+					$payments_info = EEM_Payment::instance()->get_all_wpdb_results(
506
+						array(
507
+							array(
508
+								'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
509
+								'STS_ID' => EEM_Payment::status_id_approved,
510
+							),
511
+							'force_join' => array('Payment_Method'),
512
+						),
513
+						ARRAY_A,
514
+						'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'
515
+					);
516
+
517
+					foreach ($payments_info as $payment_method_and_gateway_txn_id) {
518
+						$payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
519
+							? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso');
520
+						$gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
521
+							? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
522
+						$payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
523
+							? $payment_method_and_gateway_txn_id['payment_time'] : '';
524
+					}
525
+				}
526
+				$reg_csv_array[ __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
527
+				$reg_csv_array[ __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
528
+				$reg_csv_array[ __('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
529
+					',',
530
+					$gateway_txn_ids_etc
531
+				);
532
+
533
+				// get whether or not the user has checked in
534
+				$reg_csv_array[ __("Check-Ins", "event_espresso") ] = $reg_model->count_related(
535
+					$reg_row['Registration.REG_ID'],
536
+					'Checkin'
537
+				);
538
+				// get ticket of registration and its price
539
+				$ticket_model = EE_Registry::instance()->load_model('Ticket');
540
+				if ($reg_row['Ticket.TKT_ID']) {
541
+					$ticket_name = $this->_prepare_value_from_db_for_display(
542
+						$ticket_model,
543
+						'TKT_name',
544
+						$reg_row['Ticket.TKT_name']
545
+					);
546
+					$datetimes_strings = array();
547
+					foreach (EEM_Datetime::instance()->get_all_wpdb_results(
548
+						array(
549
+							array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']),
550
+							'order_by'                 => array('DTT_EVT_start' => 'ASC'),
551
+							'default_where_conditions' => 'none',
552
+						)
553
+					) as $datetime) {
554
+						$datetimes_strings[] = $this->_prepare_value_from_db_for_display(
555
+							EEM_Datetime::instance(),
556
+							'DTT_EVT_start',
557
+							$datetime['Datetime.DTT_EVT_start']
558
+						);
559
+					}
560
+				} else {
561
+					$ticket_name = __('Unknown', 'event_espresso');
562
+					$datetimes_strings = array(__('Unknown', 'event_espresso'));
563
+				}
564
+				$reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
565
+				$reg_csv_array[ __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
566
+				// get datetime(s) of registration
567
+
568
+				// add attendee columns
569
+				foreach ($att_fields_to_include as $att_field_name) {
570
+					$field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name);
571
+					if ($reg_row['Attendee_CPT.ID']) {
572
+						if ($att_field_name == 'STA_ID') {
573
+							$value = EEM_State::instance()->get_var(
574
+								array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])),
575
+								'STA_name'
576
+							);
577
+						} elseif ($att_field_name == 'CNT_ISO') {
578
+							$value = EEM_Country::instance()->get_var(
579
+								array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])),
580
+								'CNT_name'
581
+							);
582
+						} else {
583
+							$value = $this->_prepare_value_from_db_for_display(
584
+								EEM_Attendee::instance(),
585
+								$att_field_name,
586
+								$reg_row[ $field_obj->get_qualified_column() ]
587
+							);
588
+						}
589
+					} else {
590
+						$value = '';
591
+					}
592
+
593
+					$reg_csv_array[ $this->_get_column_name_for_field($field_obj) ] = $value;
594
+				}
595
+
596
+				// make sure each registration has the same questions in the same order
597
+				foreach ($questions_for_these_regs_rows as $question_row) {
598
+					if (! isset($reg_csv_array[ $question_row['Question.QST_admin_label'] ])) {
599
+						$reg_csv_array[ $question_row['Question.QST_admin_label'] ] = null;
600
+					}
601
+				}
602
+				// now fill out the questions THEY answered
603
+				foreach (EEM_Answer::instance()->get_all_wpdb_results(
604
+					array(array('REG_ID' => $reg_row['Registration.REG_ID']), 'force_join' => array('Question'))
605
+				) as $answer_row) {
606
+					/* @var $answer EE_Answer */
607
+					if ($answer_row['Question.QST_ID']) {
608
+						$question_label = $this->_prepare_value_from_db_for_display(
609
+							EEM_Question::instance(),
610
+							'QST_admin_label',
611
+							$answer_row['Question.QST_admin_label']
612
+						);
613
+					} else {
614
+						$question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
615
+					}
616
+					if (isset($answer_row['Question.QST_type']) && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state) {
617
+						$reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
618
+							$answer_row['Answer.ANS_value']
619
+						);
620
+					} else {
621
+						$reg_csv_array[ $question_label ] = $this->_prepare_value_from_db_for_display(
622
+							EEM_Answer::instance(),
623
+							'ANS_value',
624
+							$answer_row['Answer.ANS_value']
625
+						);
626
+					}
627
+				}
628
+				$registrations_csv_ready_array[] = apply_filters(
629
+					'FHEE__EE_Export__report_registrations__reg_csv_array',
630
+					$reg_csv_array,
631
+					$reg_row
632
+				);
633
+			}
634
+		}
635
+
636
+		// if we couldn't export anything, we want to at least show the column headers
637
+		if (empty($registrations_csv_ready_array)) {
638
+			$reg_csv_array = array();
639
+			$model_and_fields_to_include = array(
640
+				'Registration' => $reg_fields_to_include,
641
+				'Attendee'     => $att_fields_to_include,
642
+			);
643
+			foreach ($model_and_fields_to_include as $model_name => $field_list) {
644
+				$model = EE_Registry::instance()->load_model($model_name);
645
+				foreach ($field_list as $field_name) {
646
+					$field = $model->field_settings_for($field_name);
647
+					$reg_csv_array[ $this->_get_column_name_for_field(
648
+						$field
649
+					) ] = null;// $registration->get($field->get_name());
650
+				}
651
+			}
652
+			$registrations_csv_ready_array [] = $reg_csv_array;
653
+		}
654
+		if ($event_id) {
655
+			$event_slug = EEM_Event::instance()->get_var(array(array('EVT_ID' => $event_id)), 'EVT_slug');
656
+			if (! $event_slug) {
657
+				$event_slug = __('unknown', 'event_espresso');
658
+			}
659
+		} else {
660
+			$event_slug = __('all', 'event_espresso');
661
+		}
662
+		$filename = sprintf("registrations-for-%s", $event_slug);
663
+
664
+		$handle = $this->EE_CSV->begin_sending_csv($filename);
665
+		$this->EE_CSV->write_data_array_to_csv($handle, $registrations_csv_ready_array);
666
+		$this->EE_CSV->end_sending_csv($handle);
667
+	}
668
+
669
+	/**
670
+	 * Gets the 'normal' column named for fields
671
+	 *
672
+	 * @param EE_Model_Field_Base $field
673
+	 * @return string
674
+	 */
675
+	protected function _get_column_name_for_field(EE_Model_Field_Base $field)
676
+	{
677
+		return $field->get_nicename() . "[" . $field->get_name() . "]";
678
+	}
679
+
680
+
681
+	/**
682
+	 * @Export data for ALL events
683
+	 * @access public
684
+	 * @return void
685
+	 */
686
+	public function export_categories()
687
+	{
688
+		// are any Event IDs set?
689
+		$query_params = array();
690
+		if (isset($this->_req_data['EVT_CAT_ID'])) {
691
+			// do we have an array of IDs ?
692
+			if (is_array($this->_req_data['EVT_CAT_ID'])) {
693
+				// generate an "IN (CSV)" where clause
694
+				$EVT_CAT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_CAT_ID']);
695
+				$filename = 'event-categories';
696
+				$query_params[0]['term_taxonomy_id'] = array('IN', $EVT_CAT_IDs);
697
+			} else {
698
+				// generate regular where = clause
699
+				$EVT_CAT_ID = absint($this->_req_data['EVT_CAT_ID']);
700
+				$filename = 'event-category#' . $EVT_CAT_ID;
701
+				$query_params[0]['term_taxonomy_id'] = $EVT_CAT_ID;
702
+			}
703
+		} else {
704
+			// no IDs means we will d/l the entire table
705
+			$filename = 'all-categories';
706
+		}
707
+
708
+		$tables_to_export = array(
709
+			'Term_Taxonomy' => $query_params,
710
+		);
711
+
712
+		$table_data = $this->_get_export_data_for_models($tables_to_export);
713
+		$filename = $this->generate_filename($filename);
714
+
715
+		if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $table_data)) {
716
+			EE_Error::add_error(
717
+				__(
718
+					'An error occurred and the Category details could not be exported from the database.',
719
+					'event_espresso'
720
+				),
721
+				__FILE__,
722
+				__FUNCTION__,
723
+				__LINE__
724
+			);
725
+		}
726
+	}
727
+
728
+
729
+	/**
730
+	 * @process export name to create a suitable filename
731
+	 * @access  private
732
+	 * @param string - export_name
733
+	 * @return string on success, FALSE on fail
734
+	 */
735
+	private function generate_filename($export_name = '')
736
+	{
737
+		if ($export_name != '') {
738
+			$filename = get_bloginfo('name') . '-' . $export_name;
739
+			$filename = sanitize_key($filename) . '-' . $this->today;
740
+			return $filename;
741
+		} else {
742
+			EE_Error::add_error(__("No filename was provided", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
743
+		}
744
+		return false;
745
+	}
746
+
747
+
748
+	/**
749
+	 * @recursive function for exporting table data and merging the results with the next results
750
+	 * @access    private
751
+	 * @param array $models_to_export keys are model names (eg 'Event', 'Attendee', etc.) and values are arrays of
752
+	 *                                query params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
753
+	 * @return array on success, FALSE on fail
754
+	 */
755
+	private function _get_export_data_for_models($models_to_export = array())
756
+	{
757
+		$table_data = false;
758
+		if (is_array($models_to_export)) {
759
+			foreach ($models_to_export as $model_name => $query_params) {
760
+				// check for a numerically-indexed array. in that case, $model_name is the value!!
761
+				if (is_int($model_name)) {
762
+					$model_name = $query_params;
763
+					$query_params = array();
764
+				}
765
+				$model = EE_Registry::instance()->load_model($model_name);
766
+				$model_objects = $model->get_all($query_params);
767
+
768
+				$table_data[ $model_name ] = array();
769
+				foreach ($model_objects as $model_object) {
770
+					$model_data_array = array();
771
+					$fields = $model->field_settings();
772
+					foreach ($fields as $field) {
773
+						$column_name = $field->get_nicename() . "[" . $field->get_name() . "]";
774
+						if ($field instanceof EE_Datetime_Field) {
775
+							// $field->set_date_format('Y-m-d');
776
+							// $field->set_time_format('H:i:s');
777
+							$model_data_array[ $column_name ] = $model_object->get_datetime(
778
+								$field->get_name(),
779
+								'Y-m-d',
780
+								'H:i:s'
781
+							);
782
+						} else {
783
+							$model_data_array[ $column_name ] = $model_object->get($field->get_name());
784
+						}
785
+					}
786
+					$table_data[ $model_name ][] = $model_data_array;
787
+				}
788
+			}
789
+		}
790
+		return $table_data;
791
+	}
792 792
 }
Please login to merge, or discard this patch.