Completed
Branch FET/extract-activation-detecti... (0caf02)
by
unknown
07:41 queued 05:25
created
core/db_classes/EE_Message_Template.class.php 2 patches
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -13,173 +13,173 @@
 block discarded – undo
13 13
 class EE_Message_Template extends EE_Base_Class
14 14
 {
15 15
 
16
-    /**
17
-     * @param array  $props_n_values
18
-     * @param string $timezone
19
-     * @return EE_Message_Template|mixed
20
-     */
21
-    public static function new_instance($props_n_values = array(), $timezone = '')
22
-    {
23
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone);
24
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone);
25
-    }
26
-
27
-
28
-    /**
29
-     * @param array  $props_n_values
30
-     * @param string $timezone
31
-     * @return EE_Message_Template
32
-     */
33
-    public static function new_instance_from_db($props_n_values = array(), $timezone = '')
34
-    {
35
-        return new self($props_n_values, true, $timezone);
36
-    }
37
-
38
-
39
-    /**
40
-     * @param bool $GRP_ID
41
-     * @throws EE_Error
42
-     */
43
-    public function set_group_template_id($GRP_ID = false)
44
-    {
45
-        if (! $GRP_ID) {
46
-            throw new EE_Error(__('Missing required value for the message template group id', 'event_espresso'));
47
-        }
48
-        $this->set('GRP_ID', $GRP_ID);
49
-    }
50
-
51
-
52
-    /**
53
-     * get Group ID
54
-     *
55
-     * @access public
56
-     * @return int
57
-     */
58
-    public function GRP_ID()
59
-    {
60
-        return $this->get('GRP_ID');
61
-    }
62
-
63
-
64
-    /**
65
-     * get User ID
66
-     *
67
-     * @access public
68
-     * @return int
69
-     */
70
-    public function user()
71
-    {
72
-        return $this->get_first_related('Message_Template_Group')->get('MTP_user_id');
73
-    }
74
-
75
-
76
-    /**
77
-     * get Message Messenger
78
-     *
79
-     * @access public
80
-     * @return string
81
-     */
82
-    public function messenger()
83
-    {
84
-        return $this->get_first_related('Message_Template_Group')->messenger();
85
-    }
86
-
87
-
88
-    /**
89
-     * get Message Messenger OBJECT
90
-     *
91
-     * @access public
92
-     * @return object Messenger Object for the given messenger
93
-     */
94
-    public function messenger_obj()
95
-    {
96
-        return $this->get_first_related('Message_Template_Group')->messenger_obj();
97
-    }
98
-
99
-
100
-    /**
101
-     * get Message Type
102
-     *
103
-     * @access public
104
-     * @return string
105
-     */
106
-    public function message_type()
107
-    {
108
-        return $this->get_first_related('Message_Template_Group')->message_type();
109
-    }
110
-
111
-
112
-    /**
113
-     * get Message type OBJECT
114
-     *
115
-     * @access public
116
-     * @return object  Message Type object for the given message type
117
-     */
118
-    public function message_type_obj()
119
-    {
120
-        return $this->get_first_related('Message_Template_Group')->message_type_obj();
121
-    }
122
-
123
-
124
-    /**
125
-     * This returns the set context array configured in the message type object
126
-     *
127
-     * @access public
128
-     * @return array array of contexts and their configuration.
129
-     */
130
-    public function contexts_config()
131
-    {
132
-        return $this->get_first_related('Message_Template_Group')->contexts_config();
133
-    }
134
-
135
-
136
-    /**
137
-     * This returns the context_label for contexts as set in the message type object
138
-     *
139
-     * @access public
140
-     * @return string label for "context"
141
-     */
142
-    public function context_label()
143
-    {
144
-        return $this->get_first_related('Message_Template_Group')->context_label();
145
-    }
146
-
147
-
148
-    /**
149
-     * this returns if the template group this template belongs to is global
150
-     *
151
-     * @return boolean true if it is, false if it isn't
152
-     */
153
-    public function is_global()
154
-    {
155
-        return $this->get_first_related('Message_Template_Group')->is_global();
156
-    }
157
-
158
-
159
-    /**
160
-     * this returns if the template group this template belongs to is active (i.e. turned "on" or not)
161
-     *
162
-     * @return boolean true if it is, false if it isn't
163
-     */
164
-    public function is_active()
165
-    {
166
-        return $this->get_first_related('Message_Template_Group')->is_active();
167
-    }
168
-
169
-
170
-    /**
171
-     * This will return an array of shortcodes => labels from the messenger and message_type objects associated with
172
-     * this template.
173
-     *
174
-     * @access public
175
-     * @param string $context what context we're going to return shortcodes for
176
-     * @param array  $fields  what fields we're returning valid shortcodes for.  If empty then we assume all fields are
177
-     *                        to be merged and returned.
178
-     * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no
179
-     *               shortcodes found.
180
-     */
181
-    public function get_shortcodes($context, $fields = array())
182
-    {
183
-        return $this->get_first_related('Message_Template_Group')->get_shortcodes($context, $fields);
184
-    }
16
+	/**
17
+	 * @param array  $props_n_values
18
+	 * @param string $timezone
19
+	 * @return EE_Message_Template|mixed
20
+	 */
21
+	public static function new_instance($props_n_values = array(), $timezone = '')
22
+	{
23
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone);
24
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone);
25
+	}
26
+
27
+
28
+	/**
29
+	 * @param array  $props_n_values
30
+	 * @param string $timezone
31
+	 * @return EE_Message_Template
32
+	 */
33
+	public static function new_instance_from_db($props_n_values = array(), $timezone = '')
34
+	{
35
+		return new self($props_n_values, true, $timezone);
36
+	}
37
+
38
+
39
+	/**
40
+	 * @param bool $GRP_ID
41
+	 * @throws EE_Error
42
+	 */
43
+	public function set_group_template_id($GRP_ID = false)
44
+	{
45
+		if (! $GRP_ID) {
46
+			throw new EE_Error(__('Missing required value for the message template group id', 'event_espresso'));
47
+		}
48
+		$this->set('GRP_ID', $GRP_ID);
49
+	}
50
+
51
+
52
+	/**
53
+	 * get Group ID
54
+	 *
55
+	 * @access public
56
+	 * @return int
57
+	 */
58
+	public function GRP_ID()
59
+	{
60
+		return $this->get('GRP_ID');
61
+	}
62
+
63
+
64
+	/**
65
+	 * get User ID
66
+	 *
67
+	 * @access public
68
+	 * @return int
69
+	 */
70
+	public function user()
71
+	{
72
+		return $this->get_first_related('Message_Template_Group')->get('MTP_user_id');
73
+	}
74
+
75
+
76
+	/**
77
+	 * get Message Messenger
78
+	 *
79
+	 * @access public
80
+	 * @return string
81
+	 */
82
+	public function messenger()
83
+	{
84
+		return $this->get_first_related('Message_Template_Group')->messenger();
85
+	}
86
+
87
+
88
+	/**
89
+	 * get Message Messenger OBJECT
90
+	 *
91
+	 * @access public
92
+	 * @return object Messenger Object for the given messenger
93
+	 */
94
+	public function messenger_obj()
95
+	{
96
+		return $this->get_first_related('Message_Template_Group')->messenger_obj();
97
+	}
98
+
99
+
100
+	/**
101
+	 * get Message Type
102
+	 *
103
+	 * @access public
104
+	 * @return string
105
+	 */
106
+	public function message_type()
107
+	{
108
+		return $this->get_first_related('Message_Template_Group')->message_type();
109
+	}
110
+
111
+
112
+	/**
113
+	 * get Message type OBJECT
114
+	 *
115
+	 * @access public
116
+	 * @return object  Message Type object for the given message type
117
+	 */
118
+	public function message_type_obj()
119
+	{
120
+		return $this->get_first_related('Message_Template_Group')->message_type_obj();
121
+	}
122
+
123
+
124
+	/**
125
+	 * This returns the set context array configured in the message type object
126
+	 *
127
+	 * @access public
128
+	 * @return array array of contexts and their configuration.
129
+	 */
130
+	public function contexts_config()
131
+	{
132
+		return $this->get_first_related('Message_Template_Group')->contexts_config();
133
+	}
134
+
135
+
136
+	/**
137
+	 * This returns the context_label for contexts as set in the message type object
138
+	 *
139
+	 * @access public
140
+	 * @return string label for "context"
141
+	 */
142
+	public function context_label()
143
+	{
144
+		return $this->get_first_related('Message_Template_Group')->context_label();
145
+	}
146
+
147
+
148
+	/**
149
+	 * this returns if the template group this template belongs to is global
150
+	 *
151
+	 * @return boolean true if it is, false if it isn't
152
+	 */
153
+	public function is_global()
154
+	{
155
+		return $this->get_first_related('Message_Template_Group')->is_global();
156
+	}
157
+
158
+
159
+	/**
160
+	 * this returns if the template group this template belongs to is active (i.e. turned "on" or not)
161
+	 *
162
+	 * @return boolean true if it is, false if it isn't
163
+	 */
164
+	public function is_active()
165
+	{
166
+		return $this->get_first_related('Message_Template_Group')->is_active();
167
+	}
168
+
169
+
170
+	/**
171
+	 * This will return an array of shortcodes => labels from the messenger and message_type objects associated with
172
+	 * this template.
173
+	 *
174
+	 * @access public
175
+	 * @param string $context what context we're going to return shortcodes for
176
+	 * @param array  $fields  what fields we're returning valid shortcodes for.  If empty then we assume all fields are
177
+	 *                        to be merged and returned.
178
+	 * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no
179
+	 *               shortcodes found.
180
+	 */
181
+	public function get_shortcodes($context, $fields = array())
182
+	{
183
+		return $this->get_first_related('Message_Template_Group')->get_shortcodes($context, $fields);
184
+	}
185 185
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@
 block discarded – undo
42 42
      */
43 43
     public function set_group_template_id($GRP_ID = false)
44 44
     {
45
-        if (! $GRP_ID) {
45
+        if ( ! $GRP_ID) {
46 46
             throw new EE_Error(__('Missing required value for the message template group id', 'event_espresso'));
47 47
         }
48 48
         $this->set('GRP_ID', $GRP_ID);
Please login to merge, or discard this patch.
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.