Completed
Branch FET/update-docs-for-gutenberg-... (4fb018)
by
unknown
71:12 queued 62:03
created
core/db_models/EEM_Payment_Method.model.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
     /**
215 215
      * Overrides parent ot also check by the slug
216 216
      * @see EEM_Base::ensure_is_obj()
217
-     * @param string|int|EE_Payment_Method $base_class_obj_or_id
217
+     * @param EE_Payment_Method $base_class_obj_or_id
218 218
      * @param boolean                      $ensure_is_in_db
219 219
      * @return EE_Payment_Method
220 220
      * @throws EE_Error
@@ -382,8 +382,8 @@  discard block
 block discarded – undo
382 382
      * Note: if an offline payment method was selected on the related transaction then this will have no payment methods returned.
383 383
      * It will ONLY return a payment method for a PAYMENT recorded against the registration.
384 384
      *
385
-     * @param EE_Registration|int $registration_or_reg_id  Either the EE_Registration object or the id for the registration.
386
-     * @return EE_Payment|null
385
+     * @param EE_Registration $registration_or_reg_id  Either the EE_Registration object or the id for the registration.
386
+     * @return null|EE_Base_Class
387 387
      */
388 388
     public function get_last_used_for_registration($registration_or_reg_id)
389 389
     {
Please login to merge, or discard this patch.
Indentation   +376 added lines, -376 removed lines patch added patch discarded remove patch
@@ -20,381 +20,381 @@
 block discarded – undo
20 20
 class EEM_Payment_Method extends EEM_Base
21 21
 {
22 22
 
23
-    const scope_cart = 'CART';
24
-
25
-    const scope_admin = 'ADMIN';
26
-
27
-    const scope_api = 'API';
28
-
29
-    /**
30
-     *
31
-     * @type EEM_Payment_Method
32
-     */
33
-    protected static $_instance = null;
34
-
35
-
36
-
37
-    /**
38
-     * private constructor to prevent direct creation
39
-     * @Constructor
40
-     * @access   protected
41
-     * @return EEM_Payment_Method
42
-     */
43
-    protected function __construct($timezone = null)
44
-    {
45
-        $this->singlular_item = __('Payment Method', 'event_espresso');
46
-        $this->plural_item = __('Payment Methods', 'event_espresso');
47
-        $this->_tables = array( 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID') );
48
-        $this->_fields = array(
49
-            'Payment_Method' => array(
50
-                'PMD_ID' => new EE_Primary_Key_Int_Field('PMD_ID', __("ID", 'event_espresso')),
51
-                'PMD_type' => new EE_Plain_Text_Field('PMD_type', __("Payment Method Type", 'event_espresso'), false, 'Admin_Only'),
52
-                'PMD_name' => new EE_Plain_Text_Field('PMD_name', __("Name", 'event_espresso'), false),
53
-                'PMD_desc' => new EE_Post_Content_Field('PMD_desc', __("Description", 'event_espresso'), false, ''),
54
-                'PMD_admin_name' => new EE_Plain_Text_Field('PMD_admin_name', __("Admin-Only Name", 'event_espresso'), true),
55
-                'PMD_admin_desc' => new EE_Post_Content_Field('PMD_admin_desc', __("Admin-Only Description", 'event_espresso'), true),
56
-                'PMD_slug' => new EE_Slug_Field('PMD_slug', __("Slug", 'event_espresso'), false),
57
-                'PMD_order' => new EE_Integer_Field('PMD_order', __("Order", 'event_espresso'), false, 0),
58
-                'PMD_debug_mode' => new EE_Boolean_Field('PMD_debug_mode', __("Debug Mode On?", 'event_espresso'), false, false),
59
-                'PMD_wp_user' => new EE_WP_User_Field('PMD_wp_user', __("Payment Method Creator ID", 'event_espresso'), false),
60
-                'PMD_open_by_default' => new EE_Boolean_Field('PMD_open_by_default', __("Open by Default?", 'event_espresso'), false, false), 'PMD_button_url' => new EE_Plain_Text_Field('PMD_button_url', __("Button URL", 'event_espresso'), true, ''),
61
-                'PMD_scope' => new EE_Serialized_Text_Field('PMD_scope', __("Usable From?", 'event_espresso'), false, array()), // possible values currently are 'CART','ADMIN','API'
62
-        ) );
63
-        $this->_model_relations = array(
23
+	const scope_cart = 'CART';
24
+
25
+	const scope_admin = 'ADMIN';
26
+
27
+	const scope_api = 'API';
28
+
29
+	/**
30
+	 *
31
+	 * @type EEM_Payment_Method
32
+	 */
33
+	protected static $_instance = null;
34
+
35
+
36
+
37
+	/**
38
+	 * private constructor to prevent direct creation
39
+	 * @Constructor
40
+	 * @access   protected
41
+	 * @return EEM_Payment_Method
42
+	 */
43
+	protected function __construct($timezone = null)
44
+	{
45
+		$this->singlular_item = __('Payment Method', 'event_espresso');
46
+		$this->plural_item = __('Payment Methods', 'event_espresso');
47
+		$this->_tables = array( 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID') );
48
+		$this->_fields = array(
49
+			'Payment_Method' => array(
50
+				'PMD_ID' => new EE_Primary_Key_Int_Field('PMD_ID', __("ID", 'event_espresso')),
51
+				'PMD_type' => new EE_Plain_Text_Field('PMD_type', __("Payment Method Type", 'event_espresso'), false, 'Admin_Only'),
52
+				'PMD_name' => new EE_Plain_Text_Field('PMD_name', __("Name", 'event_espresso'), false),
53
+				'PMD_desc' => new EE_Post_Content_Field('PMD_desc', __("Description", 'event_espresso'), false, ''),
54
+				'PMD_admin_name' => new EE_Plain_Text_Field('PMD_admin_name', __("Admin-Only Name", 'event_espresso'), true),
55
+				'PMD_admin_desc' => new EE_Post_Content_Field('PMD_admin_desc', __("Admin-Only Description", 'event_espresso'), true),
56
+				'PMD_slug' => new EE_Slug_Field('PMD_slug', __("Slug", 'event_espresso'), false),
57
+				'PMD_order' => new EE_Integer_Field('PMD_order', __("Order", 'event_espresso'), false, 0),
58
+				'PMD_debug_mode' => new EE_Boolean_Field('PMD_debug_mode', __("Debug Mode On?", 'event_espresso'), false, false),
59
+				'PMD_wp_user' => new EE_WP_User_Field('PMD_wp_user', __("Payment Method Creator ID", 'event_espresso'), false),
60
+				'PMD_open_by_default' => new EE_Boolean_Field('PMD_open_by_default', __("Open by Default?", 'event_espresso'), false, false), 'PMD_button_url' => new EE_Plain_Text_Field('PMD_button_url', __("Button URL", 'event_espresso'), true, ''),
61
+				'PMD_scope' => new EE_Serialized_Text_Field('PMD_scope', __("Usable From?", 'event_espresso'), false, array()), // possible values currently are 'CART','ADMIN','API'
62
+		) );
63
+		$this->_model_relations = array(
64 64
  //         'Event'=>new EE_HABTM_Relation('Event_Payment_Method'),
65
-            'Payment' => new EE_Has_Many_Relation(),
66
-            'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'),
67
-            'Transaction' => new EE_Has_Many_Relation(),
68
-            'WP_User' => new EE_Belongs_To_Relation(),
69
-        );
70
-        parent::__construct($timezone);
71
-    }
72
-
73
-
74
-
75
-    /**
76
-     * Gets one by the slug provided
77
-     * @param string $slug
78
-     * @return EE_Payment_Method
79
-     */
80
-    public function get_one_by_slug($slug)
81
-    {
82
-        return $this->get_one(array( array( 'PMD_slug' => $slug ) ));
83
-    }
84
-
85
-
86
-
87
-    /**
88
-     * Gets all the acceptable scopes for payment methods.
89
-     * Keys are their names as store din the DB, and values are nice names for displaying them
90
-     * @return array
91
-     */
92
-    public function scopes()
93
-    {
94
-        return apply_filters(
95
-            'FHEE__EEM_Payment_Method__scopes',
96
-            array(
97
-                self::scope_cart        => __("Front-end Registration Page", 'event_espresso'),
98
-                self::scope_admin   => __("Admin Registration Page (no online processing)", 'event_espresso')
99
-            )
100
-        );
101
-    }
102
-
103
-
104
-
105
-    /**
106
-     * Determines if this is an valid scope
107
-     * @param string $scope like one of EEM_Payment_Method::instance()->scopes()
108
-     * @return boolean
109
-     */
110
-    public function is_valid_scope($scope)
111
-    {
112
-        $scopes = $this->scopes();
113
-        if (isset($scopes[ $scope ])) {
114
-            return true;
115
-        } else {
116
-            return false;
117
-        }
118
-    }
119
-
120
-
121
-
122
-    /**
123
-     * Gets all active payment methods
124
-     * @param string $scope one of
125
-     * @param array  $query_params
126
-     * @throws EE_Error
127
-     * @return EE_Payment_Method[]
128
-     */
129
-    public function get_all_active($scope = null, $query_params = array())
130
-    {
131
-        if (! isset($query_params['order_by']) && ! isset($query_params['order'])) {
132
-            $query_params['order_by'] = array( 'PMD_order' => 'ASC', 'PMD_ID' => 'ASC' );
133
-        }
134
-        return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params));
135
-    }
136
-
137
-    /**
138
-     * Counts all active gateways in the specified scope
139
-     * @param string $scope one of EEM_Payment_Method::scope_*
140
-     * @param array $query_params
141
-     * @return int
142
-     */
143
-    public function count_active($scope = null, $query_params = array())
144
-    {
145
-        return $this->count($this->_get_query_params_for_all_active($scope, $query_params));
146
-    }
147
-
148
-    /**
149
-     * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params
150
-     * argument to get all active for a given scope
151
-     * @param string $scope one of the constants EEM_Payment_Method::scope_*
152
-     * @param array $query_params like EEM_Base::get_all.
153
-     * @return array like param of EEM_Base::get_all()
154
-     * @throws EE_Error
155
-     */
156
-    protected function _get_query_params_for_all_active($scope = null, $query_params = array())
157
-    {
158
-        if ($scope) {
159
-            if ($this->is_valid_scope($scope)) {
160
-                return array_replace_recursive(array( array( 'PMD_scope' => array( 'LIKE', "%$scope%" ) ) ), $query_params);
161
-            } else {
162
-                throw new EE_Error(sprintf(__("'%s' is not a valid scope for a payment method", "event_espresso"), $scope));
163
-            }
164
-        } else {
165
-            $acceptable_scopes = array();
166
-            $count = 0;
167
-            foreach ($this->scopes() as $scope_name => $desc) {
168
-                $count++;
169
-                $acceptable_scopes[ 'PMD_scope*' . $count ] = array( 'LIKE', '%' . $scope_name . '%' );
170
-            }
171
-            return array_replace_recursive(array( array( 'OR*active_scope' => $acceptable_scopes ) ), $query_params);
172
-        }
173
-    }
174
-
175
-    /**
176
-     * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params
177
-     * argument to get all active for a given scope
178
-     * @param string $scope one of the constants EEM_Payment_Method::scope_*
179
-     * @param array $query_params like EEM_Base::get_all.
180
-     * @return array like param of EEM_Base::get_all()
181
-     * @throws EE_Error
182
-     */
183
-    public function get_query_params_for_all_active($scope = null, $query_params = array())
184
-    {
185
-        return $this->_get_query_params_for_all_active($scope, $query_params);
186
-    }
187
-
188
-
189
-    /**
190
-     * Gets one active payment method. see @get_all_active for documentation
191
-     * @param string $scope
192
-     * @param array  $query_params
193
-     * @return EE_Payment_Method
194
-     */
195
-    public function get_one_active($scope = null, $query_params = array())
196
-    {
197
-        return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params));
198
-    }
199
-
200
-
201
-
202
-    /**
203
-     * Gets one payment method of that type, regardless of whether its active or not
204
-     * @param string $type
205
-     * @return EE_Payment_Method
206
-     */
207
-    public function get_one_of_type($type)
208
-    {
209
-        return $this->get_one(array( array( 'PMD_type' => $type ) ));
210
-    }
211
-
212
-
213
-
214
-    /**
215
-     * Overrides parent ot also check by the slug
216
-     * @see EEM_Base::ensure_is_obj()
217
-     * @param string|int|EE_Payment_Method $base_class_obj_or_id
218
-     * @param boolean                      $ensure_is_in_db
219
-     * @return EE_Payment_Method
220
-     * @throws EE_Error
221
-     */
222
-    public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false)
223
-    {
224
-        // first: check if it's a slug
225
-        if (is_string($base_class_obj_or_id)) {
226
-            $obj = $this->get_one_by_slug($base_class_obj_or_id);
227
-            if ($obj) {
228
-                return $obj;
229
-            }
230
-        }
231
-        // ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID)
232
-        try {
233
-            return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db);
234
-        } catch (EE_Error $e) {
235
-            // handle it outside the catch
236
-        }
237
-        throw new EE_Error(sprintf(__("'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso"), $base_class_obj_or_id));
238
-    }
239
-
240
-
241
-
242
-    /**
243
-     * Gets the ID of this object, or if its a string finds the object's id
244
-     * associated with that slug
245
-     * @param mixed $base_obj_or_id_or_slug
246
-     * @return int
247
-     */
248
-    public function ensure_is_ID($base_obj_or_id_or_slug)
249
-    {
250
-        if (is_string($base_obj_or_id_or_slug)) {
251
-            // assume it's a slug
252
-            $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug);
253
-        }
254
-        return parent::ensure_is_ID($base_obj_or_id_or_slug);
255
-    }
256
-
257
-
258
-
259
-    /**
260
-     * Verifies the button urls on all the passed payment methods have a valid button url. If not, resets them to their default.
261
-     * @param EE_Payment_Method[] $payment_methods. If NULL is provided defaults to all payment methods active in the cart
262
-     */
263
-    public function verify_button_urls($payment_methods = null)
264
-    {
265
-        $payment_methods = is_array($payment_methods) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart);
266
-        foreach ($payment_methods as $payment_method) {
267
-            try {
268
-                $current_button_url = $payment_method->button_url();
269
-                $buttons_urls_to_try = apply_filters('FHEE__EEM_Payment_Method__verify_button_urls__button_urls_to_try', array(
270
-                    'current_ssl' => str_replace("http://", "https://", $current_button_url),
271
-                    'current' => str_replace("https://", "http://", $current_button_url),
272
-                    'default_ssl' => str_replace("http://", "https://", $payment_method->type_obj()->default_button_url()),
273
-                    'default' => str_replace("https://", "http://", $payment_method->type_obj()->default_button_url()),
274
-                ));
275
-                foreach ($buttons_urls_to_try as $button_url_to_try) {
276
-                    if ((// this is the current url and it exists, regardless of SSL issues
277
-                                $button_url_to_try == $current_button_url &&
278
-                                EEH_URL::remote_file_exists(
279
-                                    $button_url_to_try,
280
-                                    array(
281
-                                            'sslverify' => false,
282
-                                            'limit_response_size' => 4095,// we don't really care for a full response, but we do want headers at least. Lets just ask for a one block
283
-                                            )
284
-                                )
285
-                            )
286
-                            ||
287
-                            (// this is NOT the current url and it exists with a working SSL cert
288
-                                $button_url_to_try != $current_button_url &&
289
-                                EEH_URL::remote_file_exists($button_url_to_try)
290
-                            ) ) {
291
-                        if ($current_button_url != $button_url_to_try) {
292
-                            $payment_method->save(array( 'PMD_button_url' => $button_url_to_try ));
293
-                            EE_Error::add_attention(sprintf(__("Payment Method %s's button url was set to %s, because the old image either didnt exist or SSL was recently enabled.", "event_espresso"), $payment_method->name(), $button_url_to_try));
294
-                        }
295
-                        // this image exists. So if wasn't set before, now it is;
296
-                        // or if it was already set, we have nothing to do
297
-                        break;
298
-                    }
299
-                }
300
-            } catch (EE_Error $e) {
301
-                $payment_method->set_active(false);
302
-            }
303
-        }
304
-    }
305
-
306
-
307
-
308
-    /**
309
-     * Overrides parent to not only turn wpdb results into EE_Payment_Method objects,
310
-     * but also verifies the payment method type of each is a usable object. If not,
311
-     * deactivate it, sets a notification, and deactivates it
312
-     *
313
-     * @param array $rows
314
-     * @return EE_Payment_Method[]
315
-     * @throws InvalidDataTypeException
316
-     */
317
-    protected function _create_objects($rows = array())
318
-    {
319
-        EE_Registry::instance()->load_lib('Payment_Method_Manager');
320
-        $payment_methods = parent::_create_objects($rows);
321
-        /* @var $payment_methods EE_Payment_Method[] */
322
-        $usable_payment_methods = array();
323
-        foreach ($payment_methods as $key => $payment_method) {
324
-            if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) {
325
-                $usable_payment_methods[ $key ] = $payment_method;
326
-                // some payment methods enqueue their scripts in EE_PMT_*::__construct
327
-                // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue
328
-                // its scripts). but for backwards-compat we should continue to do that
329
-                $payment_method->type_obj();
330
-            } elseif ($payment_method->active()) {
331
-                // only deactivate and notify the admin if the payment is active somewhere
332
-                $payment_method->deactivate();
333
-                $payment_method->save();
334
-                do_action(
335
-                    'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method',
336
-                    $payment_method
337
-                );
338
-                new PersistentAdminNotice(
339
-                    'auto-deactivated-' . $payment_method->type(),
340
-                    sprintf(
341
-                        __(
342
-                            'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.',
343
-                            'event_espresso'
344
-                        ),
345
-                        $payment_method->admin_name(),
346
-                        '<br />',
347
-                        '<a href="' . admin_url('plugins.php') . '">',
348
-                        '</a>'
349
-                    ),
350
-                    true
351
-                );
352
-            }
353
-        }
354
-        return $usable_payment_methods;
355
-    }
356
-
357
-
358
-
359
-    /**
360
-     * Gets all the payment methods which can be used for transaction
361
-     * (according to the relations between payment methods and events, and
362
-     * the currencies used for the transaction and their relation to payment methods)
363
-     * @param EE_Transaction $transaction
364
-     * @param string    $scope @see EEM_Payment_Method::get_all_for_events
365
-     * @return EE_Payment_Method[]
366
-     */
367
-    public function get_all_for_transaction($transaction, $scope)
368
-    {
369
-        // give addons a chance to override what payment methods are chosen based on the transaction
370
-        return apply_filters(
371
-            'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods',
372
-            $this->get_all_active($scope, array( 'group_by' => 'PMD_type' )),
373
-            $transaction,
374
-            $scope
375
-        );
376
-    }
377
-
378
-
379
-    /**
380
-     * Returns the payment method used for the last payment made for a registration.
381
-     *
382
-     * Note: if an offline payment method was selected on the related transaction then this will have no payment methods returned.
383
-     * It will ONLY return a payment method for a PAYMENT recorded against the registration.
384
-     *
385
-     * @param EE_Registration|int $registration_or_reg_id  Either the EE_Registration object or the id for the registration.
386
-     * @return EE_Payment|null
387
-     */
388
-    public function get_last_used_for_registration($registration_or_reg_id)
389
-    {
390
-        $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id);
391
-
392
-        $query_params = array(
393
-            0 => array(
394
-                'Payment.Registration.REG_ID' => $registration_id,
395
-            ),
396
-            'order_by' => array( 'Payment.PAY_ID' => 'DESC' )
397
-        );
398
-        return $this->get_one($query_params);
399
-    }
65
+			'Payment' => new EE_Has_Many_Relation(),
66
+			'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'),
67
+			'Transaction' => new EE_Has_Many_Relation(),
68
+			'WP_User' => new EE_Belongs_To_Relation(),
69
+		);
70
+		parent::__construct($timezone);
71
+	}
72
+
73
+
74
+
75
+	/**
76
+	 * Gets one by the slug provided
77
+	 * @param string $slug
78
+	 * @return EE_Payment_Method
79
+	 */
80
+	public function get_one_by_slug($slug)
81
+	{
82
+		return $this->get_one(array( array( 'PMD_slug' => $slug ) ));
83
+	}
84
+
85
+
86
+
87
+	/**
88
+	 * Gets all the acceptable scopes for payment methods.
89
+	 * Keys are their names as store din the DB, and values are nice names for displaying them
90
+	 * @return array
91
+	 */
92
+	public function scopes()
93
+	{
94
+		return apply_filters(
95
+			'FHEE__EEM_Payment_Method__scopes',
96
+			array(
97
+				self::scope_cart        => __("Front-end Registration Page", 'event_espresso'),
98
+				self::scope_admin   => __("Admin Registration Page (no online processing)", 'event_espresso')
99
+			)
100
+		);
101
+	}
102
+
103
+
104
+
105
+	/**
106
+	 * Determines if this is an valid scope
107
+	 * @param string $scope like one of EEM_Payment_Method::instance()->scopes()
108
+	 * @return boolean
109
+	 */
110
+	public function is_valid_scope($scope)
111
+	{
112
+		$scopes = $this->scopes();
113
+		if (isset($scopes[ $scope ])) {
114
+			return true;
115
+		} else {
116
+			return false;
117
+		}
118
+	}
119
+
120
+
121
+
122
+	/**
123
+	 * Gets all active payment methods
124
+	 * @param string $scope one of
125
+	 * @param array  $query_params
126
+	 * @throws EE_Error
127
+	 * @return EE_Payment_Method[]
128
+	 */
129
+	public function get_all_active($scope = null, $query_params = array())
130
+	{
131
+		if (! isset($query_params['order_by']) && ! isset($query_params['order'])) {
132
+			$query_params['order_by'] = array( 'PMD_order' => 'ASC', 'PMD_ID' => 'ASC' );
133
+		}
134
+		return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params));
135
+	}
136
+
137
+	/**
138
+	 * Counts all active gateways in the specified scope
139
+	 * @param string $scope one of EEM_Payment_Method::scope_*
140
+	 * @param array $query_params
141
+	 * @return int
142
+	 */
143
+	public function count_active($scope = null, $query_params = array())
144
+	{
145
+		return $this->count($this->_get_query_params_for_all_active($scope, $query_params));
146
+	}
147
+
148
+	/**
149
+	 * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params
150
+	 * argument to get all active for a given scope
151
+	 * @param string $scope one of the constants EEM_Payment_Method::scope_*
152
+	 * @param array $query_params like EEM_Base::get_all.
153
+	 * @return array like param of EEM_Base::get_all()
154
+	 * @throws EE_Error
155
+	 */
156
+	protected function _get_query_params_for_all_active($scope = null, $query_params = array())
157
+	{
158
+		if ($scope) {
159
+			if ($this->is_valid_scope($scope)) {
160
+				return array_replace_recursive(array( array( 'PMD_scope' => array( 'LIKE', "%$scope%" ) ) ), $query_params);
161
+			} else {
162
+				throw new EE_Error(sprintf(__("'%s' is not a valid scope for a payment method", "event_espresso"), $scope));
163
+			}
164
+		} else {
165
+			$acceptable_scopes = array();
166
+			$count = 0;
167
+			foreach ($this->scopes() as $scope_name => $desc) {
168
+				$count++;
169
+				$acceptable_scopes[ 'PMD_scope*' . $count ] = array( 'LIKE', '%' . $scope_name . '%' );
170
+			}
171
+			return array_replace_recursive(array( array( 'OR*active_scope' => $acceptable_scopes ) ), $query_params);
172
+		}
173
+	}
174
+
175
+	/**
176
+	 * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params
177
+	 * argument to get all active for a given scope
178
+	 * @param string $scope one of the constants EEM_Payment_Method::scope_*
179
+	 * @param array $query_params like EEM_Base::get_all.
180
+	 * @return array like param of EEM_Base::get_all()
181
+	 * @throws EE_Error
182
+	 */
183
+	public function get_query_params_for_all_active($scope = null, $query_params = array())
184
+	{
185
+		return $this->_get_query_params_for_all_active($scope, $query_params);
186
+	}
187
+
188
+
189
+	/**
190
+	 * Gets one active payment method. see @get_all_active for documentation
191
+	 * @param string $scope
192
+	 * @param array  $query_params
193
+	 * @return EE_Payment_Method
194
+	 */
195
+	public function get_one_active($scope = null, $query_params = array())
196
+	{
197
+		return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params));
198
+	}
199
+
200
+
201
+
202
+	/**
203
+	 * Gets one payment method of that type, regardless of whether its active or not
204
+	 * @param string $type
205
+	 * @return EE_Payment_Method
206
+	 */
207
+	public function get_one_of_type($type)
208
+	{
209
+		return $this->get_one(array( array( 'PMD_type' => $type ) ));
210
+	}
211
+
212
+
213
+
214
+	/**
215
+	 * Overrides parent ot also check by the slug
216
+	 * @see EEM_Base::ensure_is_obj()
217
+	 * @param string|int|EE_Payment_Method $base_class_obj_or_id
218
+	 * @param boolean                      $ensure_is_in_db
219
+	 * @return EE_Payment_Method
220
+	 * @throws EE_Error
221
+	 */
222
+	public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false)
223
+	{
224
+		// first: check if it's a slug
225
+		if (is_string($base_class_obj_or_id)) {
226
+			$obj = $this->get_one_by_slug($base_class_obj_or_id);
227
+			if ($obj) {
228
+				return $obj;
229
+			}
230
+		}
231
+		// ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID)
232
+		try {
233
+			return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db);
234
+		} catch (EE_Error $e) {
235
+			// handle it outside the catch
236
+		}
237
+		throw new EE_Error(sprintf(__("'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso"), $base_class_obj_or_id));
238
+	}
239
+
240
+
241
+
242
+	/**
243
+	 * Gets the ID of this object, or if its a string finds the object's id
244
+	 * associated with that slug
245
+	 * @param mixed $base_obj_or_id_or_slug
246
+	 * @return int
247
+	 */
248
+	public function ensure_is_ID($base_obj_or_id_or_slug)
249
+	{
250
+		if (is_string($base_obj_or_id_or_slug)) {
251
+			// assume it's a slug
252
+			$base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug);
253
+		}
254
+		return parent::ensure_is_ID($base_obj_or_id_or_slug);
255
+	}
256
+
257
+
258
+
259
+	/**
260
+	 * Verifies the button urls on all the passed payment methods have a valid button url. If not, resets them to their default.
261
+	 * @param EE_Payment_Method[] $payment_methods. If NULL is provided defaults to all payment methods active in the cart
262
+	 */
263
+	public function verify_button_urls($payment_methods = null)
264
+	{
265
+		$payment_methods = is_array($payment_methods) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart);
266
+		foreach ($payment_methods as $payment_method) {
267
+			try {
268
+				$current_button_url = $payment_method->button_url();
269
+				$buttons_urls_to_try = apply_filters('FHEE__EEM_Payment_Method__verify_button_urls__button_urls_to_try', array(
270
+					'current_ssl' => str_replace("http://", "https://", $current_button_url),
271
+					'current' => str_replace("https://", "http://", $current_button_url),
272
+					'default_ssl' => str_replace("http://", "https://", $payment_method->type_obj()->default_button_url()),
273
+					'default' => str_replace("https://", "http://", $payment_method->type_obj()->default_button_url()),
274
+				));
275
+				foreach ($buttons_urls_to_try as $button_url_to_try) {
276
+					if ((// this is the current url and it exists, regardless of SSL issues
277
+								$button_url_to_try == $current_button_url &&
278
+								EEH_URL::remote_file_exists(
279
+									$button_url_to_try,
280
+									array(
281
+											'sslverify' => false,
282
+											'limit_response_size' => 4095,// we don't really care for a full response, but we do want headers at least. Lets just ask for a one block
283
+											)
284
+								)
285
+							)
286
+							||
287
+							(// this is NOT the current url and it exists with a working SSL cert
288
+								$button_url_to_try != $current_button_url &&
289
+								EEH_URL::remote_file_exists($button_url_to_try)
290
+							) ) {
291
+						if ($current_button_url != $button_url_to_try) {
292
+							$payment_method->save(array( 'PMD_button_url' => $button_url_to_try ));
293
+							EE_Error::add_attention(sprintf(__("Payment Method %s's button url was set to %s, because the old image either didnt exist or SSL was recently enabled.", "event_espresso"), $payment_method->name(), $button_url_to_try));
294
+						}
295
+						// this image exists. So if wasn't set before, now it is;
296
+						// or if it was already set, we have nothing to do
297
+						break;
298
+					}
299
+				}
300
+			} catch (EE_Error $e) {
301
+				$payment_method->set_active(false);
302
+			}
303
+		}
304
+	}
305
+
306
+
307
+
308
+	/**
309
+	 * Overrides parent to not only turn wpdb results into EE_Payment_Method objects,
310
+	 * but also verifies the payment method type of each is a usable object. If not,
311
+	 * deactivate it, sets a notification, and deactivates it
312
+	 *
313
+	 * @param array $rows
314
+	 * @return EE_Payment_Method[]
315
+	 * @throws InvalidDataTypeException
316
+	 */
317
+	protected function _create_objects($rows = array())
318
+	{
319
+		EE_Registry::instance()->load_lib('Payment_Method_Manager');
320
+		$payment_methods = parent::_create_objects($rows);
321
+		/* @var $payment_methods EE_Payment_Method[] */
322
+		$usable_payment_methods = array();
323
+		foreach ($payment_methods as $key => $payment_method) {
324
+			if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) {
325
+				$usable_payment_methods[ $key ] = $payment_method;
326
+				// some payment methods enqueue their scripts in EE_PMT_*::__construct
327
+				// which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue
328
+				// its scripts). but for backwards-compat we should continue to do that
329
+				$payment_method->type_obj();
330
+			} elseif ($payment_method->active()) {
331
+				// only deactivate and notify the admin if the payment is active somewhere
332
+				$payment_method->deactivate();
333
+				$payment_method->save();
334
+				do_action(
335
+					'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method',
336
+					$payment_method
337
+				);
338
+				new PersistentAdminNotice(
339
+					'auto-deactivated-' . $payment_method->type(),
340
+					sprintf(
341
+						__(
342
+							'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.',
343
+							'event_espresso'
344
+						),
345
+						$payment_method->admin_name(),
346
+						'<br />',
347
+						'<a href="' . admin_url('plugins.php') . '">',
348
+						'</a>'
349
+					),
350
+					true
351
+				);
352
+			}
353
+		}
354
+		return $usable_payment_methods;
355
+	}
356
+
357
+
358
+
359
+	/**
360
+	 * Gets all the payment methods which can be used for transaction
361
+	 * (according to the relations between payment methods and events, and
362
+	 * the currencies used for the transaction and their relation to payment methods)
363
+	 * @param EE_Transaction $transaction
364
+	 * @param string    $scope @see EEM_Payment_Method::get_all_for_events
365
+	 * @return EE_Payment_Method[]
366
+	 */
367
+	public function get_all_for_transaction($transaction, $scope)
368
+	{
369
+		// give addons a chance to override what payment methods are chosen based on the transaction
370
+		return apply_filters(
371
+			'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods',
372
+			$this->get_all_active($scope, array( 'group_by' => 'PMD_type' )),
373
+			$transaction,
374
+			$scope
375
+		);
376
+	}
377
+
378
+
379
+	/**
380
+	 * Returns the payment method used for the last payment made for a registration.
381
+	 *
382
+	 * Note: if an offline payment method was selected on the related transaction then this will have no payment methods returned.
383
+	 * It will ONLY return a payment method for a PAYMENT recorded against the registration.
384
+	 *
385
+	 * @param EE_Registration|int $registration_or_reg_id  Either the EE_Registration object or the id for the registration.
386
+	 * @return EE_Payment|null
387
+	 */
388
+	public function get_last_used_for_registration($registration_or_reg_id)
389
+	{
390
+		$registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id);
391
+
392
+		$query_params = array(
393
+			0 => array(
394
+				'Payment.Registration.REG_ID' => $registration_id,
395
+			),
396
+			'order_by' => array( 'Payment.PAY_ID' => 'DESC' )
397
+		);
398
+		return $this->get_one($query_params);
399
+	}
400 400
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
     {
45 45
         $this->singlular_item = __('Payment Method', 'event_espresso');
46 46
         $this->plural_item = __('Payment Methods', 'event_espresso');
47
-        $this->_tables = array( 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID') );
47
+        $this->_tables = array('Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID'));
48 48
         $this->_fields = array(
49 49
             'Payment_Method' => array(
50 50
                 'PMD_ID' => new EE_Primary_Key_Int_Field('PMD_ID', __("ID", 'event_espresso')),
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
      */
80 80
     public function get_one_by_slug($slug)
81 81
     {
82
-        return $this->get_one(array( array( 'PMD_slug' => $slug ) ));
82
+        return $this->get_one(array(array('PMD_slug' => $slug)));
83 83
     }
84 84
 
85 85
 
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
     public function is_valid_scope($scope)
111 111
     {
112 112
         $scopes = $this->scopes();
113
-        if (isset($scopes[ $scope ])) {
113
+        if (isset($scopes[$scope])) {
114 114
             return true;
115 115
         } else {
116 116
             return false;
@@ -128,8 +128,8 @@  discard block
 block discarded – undo
128 128
      */
129 129
     public function get_all_active($scope = null, $query_params = array())
130 130
     {
131
-        if (! isset($query_params['order_by']) && ! isset($query_params['order'])) {
132
-            $query_params['order_by'] = array( 'PMD_order' => 'ASC', 'PMD_ID' => 'ASC' );
131
+        if ( ! isset($query_params['order_by']) && ! isset($query_params['order'])) {
132
+            $query_params['order_by'] = array('PMD_order' => 'ASC', 'PMD_ID' => 'ASC');
133 133
         }
134 134
         return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params));
135 135
     }
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
     {
158 158
         if ($scope) {
159 159
             if ($this->is_valid_scope($scope)) {
160
-                return array_replace_recursive(array( array( 'PMD_scope' => array( 'LIKE', "%$scope%" ) ) ), $query_params);
160
+                return array_replace_recursive(array(array('PMD_scope' => array('LIKE', "%$scope%"))), $query_params);
161 161
             } else {
162 162
                 throw new EE_Error(sprintf(__("'%s' is not a valid scope for a payment method", "event_espresso"), $scope));
163 163
             }
@@ -166,9 +166,9 @@  discard block
 block discarded – undo
166 166
             $count = 0;
167 167
             foreach ($this->scopes() as $scope_name => $desc) {
168 168
                 $count++;
169
-                $acceptable_scopes[ 'PMD_scope*' . $count ] = array( 'LIKE', '%' . $scope_name . '%' );
169
+                $acceptable_scopes['PMD_scope*'.$count] = array('LIKE', '%'.$scope_name.'%');
170 170
             }
171
-            return array_replace_recursive(array( array( 'OR*active_scope' => $acceptable_scopes ) ), $query_params);
171
+            return array_replace_recursive(array(array('OR*active_scope' => $acceptable_scopes)), $query_params);
172 172
         }
173 173
     }
174 174
 
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
      */
207 207
     public function get_one_of_type($type)
208 208
     {
209
-        return $this->get_one(array( array( 'PMD_type' => $type ) ));
209
+        return $this->get_one(array(array('PMD_type' => $type)));
210 210
     }
211 211
 
212 212
 
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
                                     $button_url_to_try,
280 280
                                     array(
281 281
                                             'sslverify' => false,
282
-                                            'limit_response_size' => 4095,// we don't really care for a full response, but we do want headers at least. Lets just ask for a one block
282
+                                            'limit_response_size' => 4095, // we don't really care for a full response, but we do want headers at least. Lets just ask for a one block
283 283
                                             )
284 284
                                 )
285 285
                             )
@@ -287,9 +287,9 @@  discard block
 block discarded – undo
287 287
                             (// this is NOT the current url and it exists with a working SSL cert
288 288
                                 $button_url_to_try != $current_button_url &&
289 289
                                 EEH_URL::remote_file_exists($button_url_to_try)
290
-                            ) ) {
290
+                            )) {
291 291
                         if ($current_button_url != $button_url_to_try) {
292
-                            $payment_method->save(array( 'PMD_button_url' => $button_url_to_try ));
292
+                            $payment_method->save(array('PMD_button_url' => $button_url_to_try));
293 293
                             EE_Error::add_attention(sprintf(__("Payment Method %s's button url was set to %s, because the old image either didnt exist or SSL was recently enabled.", "event_espresso"), $payment_method->name(), $button_url_to_try));
294 294
                         }
295 295
                         // this image exists. So if wasn't set before, now it is;
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
         $usable_payment_methods = array();
323 323
         foreach ($payment_methods as $key => $payment_method) {
324 324
             if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) {
325
-                $usable_payment_methods[ $key ] = $payment_method;
325
+                $usable_payment_methods[$key] = $payment_method;
326 326
                 // some payment methods enqueue their scripts in EE_PMT_*::__construct
327 327
                 // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue
328 328
                 // its scripts). but for backwards-compat we should continue to do that
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
                     $payment_method
337 337
                 );
338 338
                 new PersistentAdminNotice(
339
-                    'auto-deactivated-' . $payment_method->type(),
339
+                    'auto-deactivated-'.$payment_method->type(),
340 340
                     sprintf(
341 341
                         __(
342 342
                             'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.',
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
                         ),
345 345
                         $payment_method->admin_name(),
346 346
                         '<br />',
347
-                        '<a href="' . admin_url('plugins.php') . '">',
347
+                        '<a href="'.admin_url('plugins.php').'">',
348 348
                         '</a>'
349 349
                     ),
350 350
                     true
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
         // give addons a chance to override what payment methods are chosen based on the transaction
370 370
         return apply_filters(
371 371
             'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods',
372
-            $this->get_all_active($scope, array( 'group_by' => 'PMD_type' )),
372
+            $this->get_all_active($scope, array('group_by' => 'PMD_type')),
373 373
             $transaction,
374 374
             $scope
375 375
         );
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
             0 => array(
394 394
                 'Payment.Registration.REG_ID' => $registration_id,
395 395
             ),
396
-            'order_by' => array( 'Payment.PAY_ID' => 'DESC' )
396
+            'order_by' => array('Payment.PAY_ID' => 'DESC')
397 397
         );
398 398
         return $this->get_one($query_params);
399 399
     }
Please login to merge, or discard this patch.
core/db_models/EEM_Price.model.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      *      instantiate a new price object with blank/empty properties
67 67
      *
68 68
      *      @access     public
69
-     *      @return     mixed       array on success, FALSE on fail
69
+     *      @return     EE_Base_Class|null       array on success, FALSE on fail
70 70
      */
71 71
     public function get_new_price()
72 72
     {
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
      *
97 97
      * @access        public
98 98
      * @param int $EVT_ID
99
-     * @return array on success
99
+     * @return EE_Base_Class[] on success
100 100
      */
101 101
     public function get_all_event_prices($EVT_ID = 0)
102 102
     {
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
      * @access public
224 224
      * @param \EE_Price $price_a
225 225
      * @param \EE_Price $price_b
226
-     * @return bool false on fail
226
+     * @return integer false on fail
227 227
      */
228 228
     public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b)
229 229
     {
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
      * @access public
242 242
      * @param \EE_Price $price_a
243 243
      * @param \EE_Price $price_b
244
-     * @return bool false on fail
244
+     * @return integer false on fail
245 245
      */
246 246
     public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b)
247 247
     {
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
      *
259 259
      *      @access     public
260 260
      *      @param      int                 $type - PRT_ID
261
-     *      @return         boolean     false on fail
261
+     *      @return         EE_Base_Class[]     false on fail
262 262
      */
263 263
     public function get_all_prices_that_are_type($type = 0)
264 264
     {
Please login to merge, or discard this patch.
Indentation   +275 added lines, -275 removed lines patch added patch discarded remove patch
@@ -10,279 +10,279 @@
 block discarded – undo
10 10
 class EEM_Price extends EEM_Soft_Delete_Base
11 11
 {
12 12
 
13
-    // private instance of the EEM_Price object
14
-    protected static $_instance = null;
15
-
16
-
17
-
18
-    /**
19
-     *      private constructor to prevent direct creation
20
-     *      @Constructor
21
-     *      @access protected
22
-     *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
23
-     *      @return EEM_Price
24
-     */
25
-    protected function __construct($timezone)
26
-    {
27
-        require_once(EE_MODELS . 'EEM_Price_Type.model.php');
28
-        $this->singular_item = __('Price', 'event_espresso');
29
-        $this->plural_item = __('Prices', 'event_espresso');
30
-
31
-        $this->_tables = array(
32
-            'Price'=>new EE_Primary_Table('esp_price', 'PRC_ID')
33
-        );
34
-        $this->_fields = array(
35
-            'Price'=> array(
36
-                'PRC_ID'=>new EE_Primary_Key_Int_Field('PRC_ID', 'Price ID'),
37
-                'PRT_ID'=>new EE_Foreign_Key_Int_Field('PRT_ID', 'Price type Id', false, null, 'Price_Type'),
38
-                'PRC_amount'=>new EE_Money_Field('PRC_amount', 'Price Amount', false, 0),
39
-                'PRC_name'=>new EE_Plain_Text_Field('PRC_name', 'Name of Price', false, ''),
40
-                'PRC_desc'=>new EE_Post_Content_Field('PRC_desc', 'Price Description', false, ''),
41
-                'PRC_is_default'=>new EE_Boolean_Field('PRC_is_default', 'Flag indicating whether price is a default price', false, false),
42
-                'PRC_overrides'=>new EE_Integer_Field('PRC_overrides', 'Price ID for a global Price that will be overridden by this Price  ( for replacing default prices )', true, 0),
43
-                'PRC_order'=>new EE_Integer_Field('PRC_order', 'Order of Application of Price (lower numbers apply first?)', false, 1),
44
-                'PRC_deleted'=>new EE_Trashed_Flag_Field('PRC_deleted', 'Flag Indicating if this has been deleted or not', false, false),
45
-                'PRC_parent' => new EE_Integer_Field('PRC_parent', __('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), true, 0),
46
-                'PRC_wp_user' => new EE_WP_User_Field('PRC_wp_user', __('Price Creator ID', 'event_espresso'), false),
47
-            )
48
-        );
49
-        $this->_model_relations = array(
50
-            'Ticket'=>new EE_HABTM_Relation('Ticket_Price'),
51
-            'Price_Type'=>new EE_Belongs_To_Relation(),
52
-            'WP_User' => new EE_Belongs_To_Relation(),
53
-        );
54
-        // this model is generally available for reading
55
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event');
56
-        // account for default tickets in the caps
57
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
58
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
59
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
60
-        parent::__construct($timezone);
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     *      instantiate a new price object with blank/empty properties
67
-     *
68
-     *      @access     public
69
-     *      @return     mixed       array on success, FALSE on fail
70
-     */
71
-    public function get_new_price()
72
-    {
73
-        return $this->create_default_object();
74
-    }
75
-
76
-
77
-
78
-
79
-
80
-    /**
81
-     *      retrieve  ALL prices from db
82
-     *
83
-     *      @access     public
84
-     *      @return     EE_PRice[]
85
-     */
86
-    public function get_all_prices()
87
-    {
88
-        // retrieve all prices
89
-        return $this->get_all(array('order_by'=>array('PRC_amount'=>'ASC')));
90
-    }
91
-
92
-
93
-
94
-    /**
95
-     *        retrieve all active prices for a particular event
96
-     *
97
-     * @access        public
98
-     * @param int $EVT_ID
99
-     * @return array on success
100
-     */
101
-    public function get_all_event_prices($EVT_ID = 0)
102
-    {
103
-        return $this->get_all(array(
104
-            array(
105
-                'EVT_ID'=>$EVT_ID,
106
-                'Price_Type.PBT_ID'=>array('!=',  EEM_Price_Type::base_type_tax)
107
-            ),
108
-            'order_by'=>$this->_order_by_array_for_get_all_method()
109
-        ));
110
-    }
111
-
112
-
113
-    /**
114
-     *      retrieve all active global prices (that are not taxes (PBT_ID=4)) for a particular event
115
-     *
116
-     *      @access     public
117
-     *      @param      boolean         $count  return count
118
-     *      @return         array           on success
119
-     *      @return         boolean     false on fail
120
-     */
121
-    public function get_all_default_prices($count = false)
122
-    {
123
-        $_where = array(
124
-            'Price_Type.PBT_ID'=>array('!=',4),
125
-            'PRC_deleted' => 0,
126
-            'PRC_is_default' => 1
127
-        );
128
-        $_query_params = array(
129
-            $_where,
130
-            'order_by'=>$this->_order_by_array_for_get_all_method()
131
-        );
132
-        return $count ? $this->count(array($_where)) : $this->get_all($_query_params);
133
-    }
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-    /**
145
-     *      retrieve all prices that are taxes
146
-     *
147
-     *      @access     public
148
-     *      @return         array               on success
149
-     *      @return         array top-level keys are the price's order and their values are an array,
150
-     *                      next-level keys are the price's ID, and their values are EE_Price objects
151
-     */
152
-    public function get_all_prices_that_are_taxes()
153
-    {
154
-        $taxes = array();
155
-        $all_taxes = $this->get_all(array(
156
-            array( 'Price_Type.PBT_ID'=>  EEM_Price_Type::base_type_tax ),
157
-            'order_by' => array( 'Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC' )
158
-        ));
159
-        foreach ($all_taxes as $tax) {
160
-            if ($tax instanceof EE_Price) {
161
-                $taxes[ $tax->order() ][ $tax->ID() ] = $tax;
162
-            }
163
-        }
164
-        return $taxes;
165
-    }
166
-
167
-
168
-
169
-
170
-
171
-    /**
172
-     *      retrieve all prices for an ticket plus default global prices, but not taxes
173
-     *
174
-     *      @access     public
175
-     *      @param int $TKT_ID          the id of the event.  If not included then we assume that this is a new ticket.
176
-     *      @return         boolean         false on fail
177
-     */
178
-    public function get_all_ticket_prices_for_admin($TKT_ID = 0)
179
-    {
180
-        $array_of_price_objects = array();
181
-        if (empty($TKT_ID)) {
182
-            // if there is no tkt, get prices with no tkt ID, are global, are not a tax, and are active
183
-            // return that list
184
-            $default_prices = $this->get_all_default_prices();
185
-
186
-            if ($default_prices) {
187
-                foreach ($default_prices as $price) {
188
-                    if ($price instanceof EE_Price) {
189
-                        $array_of_price_objects[ $price->type() ][] = $price;
190
-                    }
191
-                }
192
-                return $array_of_price_objects;
193
-            } else {
194
-                return array();
195
-            }
196
-        } else {
197
-            $ticket_prices = $this->get_all(array(
198
-                array(
199
-                    'TKT_ID'=>$TKT_ID,
200
-                    'PRC_deleted' => 0
201
-                    ),
202
-                'order_by'=> array('PRC_order' => 'ASC')
203
-            ));
204
-        }
205
-
206
-        if (!empty($ticket_prices)) {
207
-            foreach ($ticket_prices as $price) {
208
-                if ($price instanceof EE_Price) {
209
-                    $array_of_price_objects[ $price->type() ][] = $price;
210
-                }
211
-            }
212
-            return $array_of_price_objects;
213
-        } else {
214
-            return false;
215
-        }
216
-    }
217
-
218
-
219
-
220
-    /**
221
-     *        _sort_event_prices_by_type
222
-     *
223
-     * @access public
224
-     * @param \EE_Price $price_a
225
-     * @param \EE_Price $price_b
226
-     * @return bool false on fail
227
-     */
228
-    public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b)
229
-    {
230
-        if ($price_a->type_obj()->order() == $price_b->type_obj()->order()) {
231
-            return $this->_sort_event_prices_by_order($price_a, $price_b);
232
-        }
233
-        return $price_a->type_obj()->order() < $price_b->type_obj()->order() ? -1 : 1;
234
-    }
235
-
236
-
237
-
238
-    /**
239
-     *        _sort_event_prices_by_order
240
-     *
241
-     * @access public
242
-     * @param \EE_Price $price_a
243
-     * @param \EE_Price $price_b
244
-     * @return bool false on fail
245
-     */
246
-    public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b)
247
-    {
248
-        if ($price_a->order() == $price_b->order()) {
249
-            return 0;
250
-        }
251
-        return $price_a->order() < $price_b->order() ? -1 : 1;
252
-    }
253
-
254
-
255
-
256
-    /**
257
-     *      get all prices of a specific type
258
-     *
259
-     *      @access     public
260
-     *      @param      int                 $type - PRT_ID
261
-     *      @return         boolean     false on fail
262
-     */
263
-    public function get_all_prices_that_are_type($type = 0)
264
-    {
265
-        return $this->get_all(array(
266
-            array(
267
-                'PRT_ID'=>$type
268
-            ),
269
-            'order_by'=>$this->_order_by_array_for_get_all_method()
270
-        ));
271
-    }
272
-
273
-
274
-
275
-    /**
276
-     * Returns an array of the normal 'order_by' query parameter provided to the get_all query.
277
-     * Of course you don't have to use it, but this is the order we usually want to sort prices by
278
-     * @return array which can be used like so: $this->get_all(array(array(...where stuff...),'order_by'=>$this->_order_by_array_for_get_all_method()));
279
-     */
280
-    public function _order_by_array_for_get_all_method()
281
-    {
282
-        return array(
283
-                'PRC_order'=>'ASC',
284
-                'Price_Type.PRT_order'=>'ASC',
285
-                'PRC_ID'=>'ASC'
286
-        );
287
-    }
13
+	// private instance of the EEM_Price object
14
+	protected static $_instance = null;
15
+
16
+
17
+
18
+	/**
19
+	 *      private constructor to prevent direct creation
20
+	 *      @Constructor
21
+	 *      @access protected
22
+	 *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
23
+	 *      @return EEM_Price
24
+	 */
25
+	protected function __construct($timezone)
26
+	{
27
+		require_once(EE_MODELS . 'EEM_Price_Type.model.php');
28
+		$this->singular_item = __('Price', 'event_espresso');
29
+		$this->plural_item = __('Prices', 'event_espresso');
30
+
31
+		$this->_tables = array(
32
+			'Price'=>new EE_Primary_Table('esp_price', 'PRC_ID')
33
+		);
34
+		$this->_fields = array(
35
+			'Price'=> array(
36
+				'PRC_ID'=>new EE_Primary_Key_Int_Field('PRC_ID', 'Price ID'),
37
+				'PRT_ID'=>new EE_Foreign_Key_Int_Field('PRT_ID', 'Price type Id', false, null, 'Price_Type'),
38
+				'PRC_amount'=>new EE_Money_Field('PRC_amount', 'Price Amount', false, 0),
39
+				'PRC_name'=>new EE_Plain_Text_Field('PRC_name', 'Name of Price', false, ''),
40
+				'PRC_desc'=>new EE_Post_Content_Field('PRC_desc', 'Price Description', false, ''),
41
+				'PRC_is_default'=>new EE_Boolean_Field('PRC_is_default', 'Flag indicating whether price is a default price', false, false),
42
+				'PRC_overrides'=>new EE_Integer_Field('PRC_overrides', 'Price ID for a global Price that will be overridden by this Price  ( for replacing default prices )', true, 0),
43
+				'PRC_order'=>new EE_Integer_Field('PRC_order', 'Order of Application of Price (lower numbers apply first?)', false, 1),
44
+				'PRC_deleted'=>new EE_Trashed_Flag_Field('PRC_deleted', 'Flag Indicating if this has been deleted or not', false, false),
45
+				'PRC_parent' => new EE_Integer_Field('PRC_parent', __('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), true, 0),
46
+				'PRC_wp_user' => new EE_WP_User_Field('PRC_wp_user', __('Price Creator ID', 'event_espresso'), false),
47
+			)
48
+		);
49
+		$this->_model_relations = array(
50
+			'Ticket'=>new EE_HABTM_Relation('Ticket_Price'),
51
+			'Price_Type'=>new EE_Belongs_To_Relation(),
52
+			'WP_User' => new EE_Belongs_To_Relation(),
53
+		);
54
+		// this model is generally available for reading
55
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event');
56
+		// account for default tickets in the caps
57
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
58
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
59
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
60
+		parent::__construct($timezone);
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 *      instantiate a new price object with blank/empty properties
67
+	 *
68
+	 *      @access     public
69
+	 *      @return     mixed       array on success, FALSE on fail
70
+	 */
71
+	public function get_new_price()
72
+	{
73
+		return $this->create_default_object();
74
+	}
75
+
76
+
77
+
78
+
79
+
80
+	/**
81
+	 *      retrieve  ALL prices from db
82
+	 *
83
+	 *      @access     public
84
+	 *      @return     EE_PRice[]
85
+	 */
86
+	public function get_all_prices()
87
+	{
88
+		// retrieve all prices
89
+		return $this->get_all(array('order_by'=>array('PRC_amount'=>'ASC')));
90
+	}
91
+
92
+
93
+
94
+	/**
95
+	 *        retrieve all active prices for a particular event
96
+	 *
97
+	 * @access        public
98
+	 * @param int $EVT_ID
99
+	 * @return array on success
100
+	 */
101
+	public function get_all_event_prices($EVT_ID = 0)
102
+	{
103
+		return $this->get_all(array(
104
+			array(
105
+				'EVT_ID'=>$EVT_ID,
106
+				'Price_Type.PBT_ID'=>array('!=',  EEM_Price_Type::base_type_tax)
107
+			),
108
+			'order_by'=>$this->_order_by_array_for_get_all_method()
109
+		));
110
+	}
111
+
112
+
113
+	/**
114
+	 *      retrieve all active global prices (that are not taxes (PBT_ID=4)) for a particular event
115
+	 *
116
+	 *      @access     public
117
+	 *      @param      boolean         $count  return count
118
+	 *      @return         array           on success
119
+	 *      @return         boolean     false on fail
120
+	 */
121
+	public function get_all_default_prices($count = false)
122
+	{
123
+		$_where = array(
124
+			'Price_Type.PBT_ID'=>array('!=',4),
125
+			'PRC_deleted' => 0,
126
+			'PRC_is_default' => 1
127
+		);
128
+		$_query_params = array(
129
+			$_where,
130
+			'order_by'=>$this->_order_by_array_for_get_all_method()
131
+		);
132
+		return $count ? $this->count(array($_where)) : $this->get_all($_query_params);
133
+	}
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+	/**
145
+	 *      retrieve all prices that are taxes
146
+	 *
147
+	 *      @access     public
148
+	 *      @return         array               on success
149
+	 *      @return         array top-level keys are the price's order and their values are an array,
150
+	 *                      next-level keys are the price's ID, and their values are EE_Price objects
151
+	 */
152
+	public function get_all_prices_that_are_taxes()
153
+	{
154
+		$taxes = array();
155
+		$all_taxes = $this->get_all(array(
156
+			array( 'Price_Type.PBT_ID'=>  EEM_Price_Type::base_type_tax ),
157
+			'order_by' => array( 'Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC' )
158
+		));
159
+		foreach ($all_taxes as $tax) {
160
+			if ($tax instanceof EE_Price) {
161
+				$taxes[ $tax->order() ][ $tax->ID() ] = $tax;
162
+			}
163
+		}
164
+		return $taxes;
165
+	}
166
+
167
+
168
+
169
+
170
+
171
+	/**
172
+	 *      retrieve all prices for an ticket plus default global prices, but not taxes
173
+	 *
174
+	 *      @access     public
175
+	 *      @param int $TKT_ID          the id of the event.  If not included then we assume that this is a new ticket.
176
+	 *      @return         boolean         false on fail
177
+	 */
178
+	public function get_all_ticket_prices_for_admin($TKT_ID = 0)
179
+	{
180
+		$array_of_price_objects = array();
181
+		if (empty($TKT_ID)) {
182
+			// if there is no tkt, get prices with no tkt ID, are global, are not a tax, and are active
183
+			// return that list
184
+			$default_prices = $this->get_all_default_prices();
185
+
186
+			if ($default_prices) {
187
+				foreach ($default_prices as $price) {
188
+					if ($price instanceof EE_Price) {
189
+						$array_of_price_objects[ $price->type() ][] = $price;
190
+					}
191
+				}
192
+				return $array_of_price_objects;
193
+			} else {
194
+				return array();
195
+			}
196
+		} else {
197
+			$ticket_prices = $this->get_all(array(
198
+				array(
199
+					'TKT_ID'=>$TKT_ID,
200
+					'PRC_deleted' => 0
201
+					),
202
+				'order_by'=> array('PRC_order' => 'ASC')
203
+			));
204
+		}
205
+
206
+		if (!empty($ticket_prices)) {
207
+			foreach ($ticket_prices as $price) {
208
+				if ($price instanceof EE_Price) {
209
+					$array_of_price_objects[ $price->type() ][] = $price;
210
+				}
211
+			}
212
+			return $array_of_price_objects;
213
+		} else {
214
+			return false;
215
+		}
216
+	}
217
+
218
+
219
+
220
+	/**
221
+	 *        _sort_event_prices_by_type
222
+	 *
223
+	 * @access public
224
+	 * @param \EE_Price $price_a
225
+	 * @param \EE_Price $price_b
226
+	 * @return bool false on fail
227
+	 */
228
+	public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b)
229
+	{
230
+		if ($price_a->type_obj()->order() == $price_b->type_obj()->order()) {
231
+			return $this->_sort_event_prices_by_order($price_a, $price_b);
232
+		}
233
+		return $price_a->type_obj()->order() < $price_b->type_obj()->order() ? -1 : 1;
234
+	}
235
+
236
+
237
+
238
+	/**
239
+	 *        _sort_event_prices_by_order
240
+	 *
241
+	 * @access public
242
+	 * @param \EE_Price $price_a
243
+	 * @param \EE_Price $price_b
244
+	 * @return bool false on fail
245
+	 */
246
+	public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b)
247
+	{
248
+		if ($price_a->order() == $price_b->order()) {
249
+			return 0;
250
+		}
251
+		return $price_a->order() < $price_b->order() ? -1 : 1;
252
+	}
253
+
254
+
255
+
256
+	/**
257
+	 *      get all prices of a specific type
258
+	 *
259
+	 *      @access     public
260
+	 *      @param      int                 $type - PRT_ID
261
+	 *      @return         boolean     false on fail
262
+	 */
263
+	public function get_all_prices_that_are_type($type = 0)
264
+	{
265
+		return $this->get_all(array(
266
+			array(
267
+				'PRT_ID'=>$type
268
+			),
269
+			'order_by'=>$this->_order_by_array_for_get_all_method()
270
+		));
271
+	}
272
+
273
+
274
+
275
+	/**
276
+	 * Returns an array of the normal 'order_by' query parameter provided to the get_all query.
277
+	 * Of course you don't have to use it, but this is the order we usually want to sort prices by
278
+	 * @return array which can be used like so: $this->get_all(array(array(...where stuff...),'order_by'=>$this->_order_by_array_for_get_all_method()));
279
+	 */
280
+	public function _order_by_array_for_get_all_method()
281
+	{
282
+		return array(
283
+				'PRC_order'=>'ASC',
284
+				'Price_Type.PRT_order'=>'ASC',
285
+				'PRC_ID'=>'ASC'
286
+		);
287
+	}
288 288
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      */
25 25
     protected function __construct($timezone)
26 26
     {
27
-        require_once(EE_MODELS . 'EEM_Price_Type.model.php');
27
+        require_once(EE_MODELS.'EEM_Price_Type.model.php');
28 28
         $this->singular_item = __('Price', 'event_espresso');
29 29
         $this->plural_item = __('Prices', 'event_espresso');
30 30
 
@@ -52,11 +52,11 @@  discard block
 block discarded – undo
52 52
             'WP_User' => new EE_Belongs_To_Relation(),
53 53
         );
54 54
         // this model is generally available for reading
55
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event');
55
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event');
56 56
         // account for default tickets in the caps
57
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
58
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
59
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
57
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
58
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
59
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
60 60
         parent::__construct($timezone);
61 61
     }
62 62
 
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
         return $this->get_all(array(
104 104
             array(
105 105
                 'EVT_ID'=>$EVT_ID,
106
-                'Price_Type.PBT_ID'=>array('!=',  EEM_Price_Type::base_type_tax)
106
+                'Price_Type.PBT_ID'=>array('!=', EEM_Price_Type::base_type_tax)
107 107
             ),
108 108
             'order_by'=>$this->_order_by_array_for_get_all_method()
109 109
         ));
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
     public function get_all_default_prices($count = false)
122 122
     {
123 123
         $_where = array(
124
-            'Price_Type.PBT_ID'=>array('!=',4),
124
+            'Price_Type.PBT_ID'=>array('!=', 4),
125 125
             'PRC_deleted' => 0,
126 126
             'PRC_is_default' => 1
127 127
         );
@@ -153,12 +153,12 @@  discard block
 block discarded – undo
153 153
     {
154 154
         $taxes = array();
155 155
         $all_taxes = $this->get_all(array(
156
-            array( 'Price_Type.PBT_ID'=>  EEM_Price_Type::base_type_tax ),
157
-            'order_by' => array( 'Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC' )
156
+            array('Price_Type.PBT_ID'=>  EEM_Price_Type::base_type_tax),
157
+            'order_by' => array('Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC')
158 158
         ));
159 159
         foreach ($all_taxes as $tax) {
160 160
             if ($tax instanceof EE_Price) {
161
-                $taxes[ $tax->order() ][ $tax->ID() ] = $tax;
161
+                $taxes[$tax->order()][$tax->ID()] = $tax;
162 162
             }
163 163
         }
164 164
         return $taxes;
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
             if ($default_prices) {
187 187
                 foreach ($default_prices as $price) {
188 188
                     if ($price instanceof EE_Price) {
189
-                        $array_of_price_objects[ $price->type() ][] = $price;
189
+                        $array_of_price_objects[$price->type()][] = $price;
190 190
                     }
191 191
                 }
192 192
                 return $array_of_price_objects;
@@ -203,10 +203,10 @@  discard block
 block discarded – undo
203 203
             ));
204 204
         }
205 205
 
206
-        if (!empty($ticket_prices)) {
206
+        if ( ! empty($ticket_prices)) {
207 207
             foreach ($ticket_prices as $price) {
208 208
                 if ($price instanceof EE_Price) {
209
-                    $array_of_price_objects[ $price->type() ][] = $price;
209
+                    $array_of_price_objects[$price->type()][] = $price;
210 210
                 }
211 211
             }
212 212
             return $array_of_price_objects;
Please login to merge, or discard this patch.
core/db_models/EEM_Price_Type.model.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
     /**
28 28
      * return an array of Base types. Keys are INTs which are used in the database,
29 29
      * values are text-representations of the base type.
30
-     * @return array
30
+     * @return integer
31 31
      */
32 32
     public function get_base_types()
33 33
     {
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
      *      instantiate a new price type object with blank/empty properties
108 108
      *
109 109
      *      @access     public
110
-     *      @return     mixed       array on success, FALSE on fail
110
+     *      @return     EE_Price_Type       array on success, FALSE on fail
111 111
      */
112 112
     public function get_new_price_type()
113 113
     {
Please login to merge, or discard this patch.
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -11,108 +11,108 @@  discard block
 block discarded – undo
11 11
 class EEM_Price_Type extends EEM_Soft_Delete_Base
12 12
 {
13 13
 
14
-    // private instance of the Price Type object
15
-    protected static $_instance = null;
16
-    // An array of the price type objects
17
-    public $type = null;
18
-
19
-    /**
20
-    *   Price Base types
21
-    *
22
-    *   @access private
23
-    *   @var int
24
-    */
25
-    public $base_types = null;
26
-
27
-    /**
28
-     * return an array of Base types. Keys are INTs which are used in the database,
29
-     * values are text-representations of the base type.
30
-     * @return array
31
-     */
32
-    public function get_base_types()
33
-    {
34
-        return $this->base_types;
35
-    }
36
-
37
-    /**
38
-     * Gets the name of the base
39
-     * @param type $base_type_int
40
-     * @return type
41
-     */
42
-    public function get_base_type_name($base_type_int)
43
-    {
44
-        return $this->base_types[ $base_type_int ];
45
-    }
46
-
47
-    /**
48
-     * constants for price base types. In the DB, we decided to store the price base type
49
-     * as an integer. So, to avoid just having magic numbers everwhere (eg, querying for
50
-     * all price types with PBT_ID = 2), we define these constants, to make code more understandable.
51
-     * So, as an example, to query for all price types that are a tax, we'd do
52
-     * EEM_PRice_Type::instance()->get_all(array(array('PBT_ID'=>EEM_Price_Type::base_type_tax)))
53
-     * instead of
54
-     * EEM_Price_Type::instance()->get_all(array(array('PBT_ID'=>2)))
55
-     * Although the 2nd is shorter, it's much less obvious what it's doing. Also, should these magic IDs ever
56
-     * change, we can continue to use the constant, by simply change its value.
57
-     */
58
-    const base_type_base_price = 1;
59
-    const base_type_discount = 2;
60
-    const base_type_surcharge = 3;
61
-    const base_type_tax = 4;
62
-    /**
63
-     *      private constructor to prevent direct creation
64
-     *      @Constructor
65
-     *      @access protected
66
-     *      @return void
67
-     */
68
-    protected function __construct($timezone = null)
69
-    {
70
-        $this->base_types = array(
71
-            EEM_Price_Type::base_type_base_price => __('Price', 'event_espresso'),
72
-            EEM_Price_Type::base_type_discount => __('Discount', 'event_espresso'),
73
-            EEM_Price_Type::base_type_surcharge => __('Surcharge', 'event_espresso'),
74
-            EEM_Price_Type::base_type_tax => __('Tax', 'event_espresso') );
75
-        $this->singular_item = __('Price Type', 'event_espresso');
76
-        $this->plural_item = __('Price Types', 'event_espresso');
77
-
78
-        $this->_tables = array(
79
-            'Price_Type'=>new EE_Primary_Table('esp_price_type', 'PRT_ID')
80
-        );
81
-        $this->_fields = array(
82
-            'Price_Type'=>array(
83
-                'PRT_ID'=>new EE_Primary_Key_Int_Field('PRT_ID', __('Price Type ID', 'event_espresso')),
84
-                'PRT_name'=>new EE_Plain_Text_Field('PRT_name', __('Price Type Name', 'event_espresso'), false, ''),
85
-                'PBT_ID'=>new EE_Enum_Integer_Field('PBT_ID', __('Price Base type ID, 1 = Price , 2 = Discount , 3 = Surcharge , 4 = Tax', 'event_espresso'), false, EEM_Price_Type::base_type_base_price, $this->base_types),
86
-                'PRT_is_percent'=>new EE_Boolean_Field('PRT_is_percent', __('Flag indicating price is a percentage', 'event_espresso'), false, false),
87
-                'PRT_order'=>new EE_Integer_Field('PRT_order', __('Order in which price should be applied. ', 'event_espresso'), false, 0),
88
-                'PRT_deleted'=>new EE_Trashed_Flag_Field('PRT_deleted', __('Flag indicating price type has been trashed', 'event_espresso'), false, false),
89
-                'PRT_wp_user' => new EE_WP_User_Field('PRT_wp_user', __('Price Type Creator ID', 'event_espresso'), false),
90
-            )
91
-        );
92
-        $this->_model_relations = array(
93
-            'Price'=>new EE_Has_Many_Relation(),
94
-            'WP_User' => new EE_Belongs_To_Relation(),
95
-        );
96
-        // this model is generally available for reading
97
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
98
-        // all price types are "default" in terms of capability names
99
-        $this->_caps_slug = 'default_price_types';
100
-        parent::__construct($timezone);
101
-    }
102
-
103
-
104
-
105
-
106
-    /**
107
-     *      instantiate a new price type object with blank/empty properties
108
-     *
109
-     *      @access     public
110
-     *      @return     mixed       array on success, FALSE on fail
111
-     */
112
-    public function get_new_price_type()
113
-    {
114
-        return EE_Price_Type::new_instance();
115
-    }
14
+	// private instance of the Price Type object
15
+	protected static $_instance = null;
16
+	// An array of the price type objects
17
+	public $type = null;
18
+
19
+	/**
20
+	 *   Price Base types
21
+	 *
22
+	 *   @access private
23
+	 *   @var int
24
+	 */
25
+	public $base_types = null;
26
+
27
+	/**
28
+	 * return an array of Base types. Keys are INTs which are used in the database,
29
+	 * values are text-representations of the base type.
30
+	 * @return array
31
+	 */
32
+	public function get_base_types()
33
+	{
34
+		return $this->base_types;
35
+	}
36
+
37
+	/**
38
+	 * Gets the name of the base
39
+	 * @param type $base_type_int
40
+	 * @return type
41
+	 */
42
+	public function get_base_type_name($base_type_int)
43
+	{
44
+		return $this->base_types[ $base_type_int ];
45
+	}
46
+
47
+	/**
48
+	 * constants for price base types. In the DB, we decided to store the price base type
49
+	 * as an integer. So, to avoid just having magic numbers everwhere (eg, querying for
50
+	 * all price types with PBT_ID = 2), we define these constants, to make code more understandable.
51
+	 * So, as an example, to query for all price types that are a tax, we'd do
52
+	 * EEM_PRice_Type::instance()->get_all(array(array('PBT_ID'=>EEM_Price_Type::base_type_tax)))
53
+	 * instead of
54
+	 * EEM_Price_Type::instance()->get_all(array(array('PBT_ID'=>2)))
55
+	 * Although the 2nd is shorter, it's much less obvious what it's doing. Also, should these magic IDs ever
56
+	 * change, we can continue to use the constant, by simply change its value.
57
+	 */
58
+	const base_type_base_price = 1;
59
+	const base_type_discount = 2;
60
+	const base_type_surcharge = 3;
61
+	const base_type_tax = 4;
62
+	/**
63
+	 *      private constructor to prevent direct creation
64
+	 *      @Constructor
65
+	 *      @access protected
66
+	 *      @return void
67
+	 */
68
+	protected function __construct($timezone = null)
69
+	{
70
+		$this->base_types = array(
71
+			EEM_Price_Type::base_type_base_price => __('Price', 'event_espresso'),
72
+			EEM_Price_Type::base_type_discount => __('Discount', 'event_espresso'),
73
+			EEM_Price_Type::base_type_surcharge => __('Surcharge', 'event_espresso'),
74
+			EEM_Price_Type::base_type_tax => __('Tax', 'event_espresso') );
75
+		$this->singular_item = __('Price Type', 'event_espresso');
76
+		$this->plural_item = __('Price Types', 'event_espresso');
77
+
78
+		$this->_tables = array(
79
+			'Price_Type'=>new EE_Primary_Table('esp_price_type', 'PRT_ID')
80
+		);
81
+		$this->_fields = array(
82
+			'Price_Type'=>array(
83
+				'PRT_ID'=>new EE_Primary_Key_Int_Field('PRT_ID', __('Price Type ID', 'event_espresso')),
84
+				'PRT_name'=>new EE_Plain_Text_Field('PRT_name', __('Price Type Name', 'event_espresso'), false, ''),
85
+				'PBT_ID'=>new EE_Enum_Integer_Field('PBT_ID', __('Price Base type ID, 1 = Price , 2 = Discount , 3 = Surcharge , 4 = Tax', 'event_espresso'), false, EEM_Price_Type::base_type_base_price, $this->base_types),
86
+				'PRT_is_percent'=>new EE_Boolean_Field('PRT_is_percent', __('Flag indicating price is a percentage', 'event_espresso'), false, false),
87
+				'PRT_order'=>new EE_Integer_Field('PRT_order', __('Order in which price should be applied. ', 'event_espresso'), false, 0),
88
+				'PRT_deleted'=>new EE_Trashed_Flag_Field('PRT_deleted', __('Flag indicating price type has been trashed', 'event_espresso'), false, false),
89
+				'PRT_wp_user' => new EE_WP_User_Field('PRT_wp_user', __('Price Type Creator ID', 'event_espresso'), false),
90
+			)
91
+		);
92
+		$this->_model_relations = array(
93
+			'Price'=>new EE_Has_Many_Relation(),
94
+			'WP_User' => new EE_Belongs_To_Relation(),
95
+		);
96
+		// this model is generally available for reading
97
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
98
+		// all price types are "default" in terms of capability names
99
+		$this->_caps_slug = 'default_price_types';
100
+		parent::__construct($timezone);
101
+	}
102
+
103
+
104
+
105
+
106
+	/**
107
+	 *      instantiate a new price type object with blank/empty properties
108
+	 *
109
+	 *      @access     public
110
+	 *      @return     mixed       array on success, FALSE on fail
111
+	 */
112
+	public function get_new_price_type()
113
+	{
114
+		return EE_Price_Type::new_instance();
115
+	}
116 116
 
117 117
 
118 118
 
@@ -131,33 +131,33 @@  discard block
 block discarded – undo
131 131
  *
132 132
  * @param type $query_params
133 133
  * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
134
-     * that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects
135
-     * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
134
+ * that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects
135
+ * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
136 136
  * @return boolean
137 137
  */
138
-    public function delete_permanently($query_params = array(), $allow_blocking = true)
139
-    {
138
+	public function delete_permanently($query_params = array(), $allow_blocking = true)
139
+	{
140 140
 
141
-        $would_be_deleted_price_types = $this->get_all_deleted_and_undeleted($query_params);
142
-        $would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types);
141
+		$would_be_deleted_price_types = $this->get_all_deleted_and_undeleted($query_params);
142
+		$would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types);
143 143
 
144
-        $ID = $query_params[0][ $this->get_primary_key_field()->get_name() ];
144
+		$ID = $query_params[0][ $this->get_primary_key_field()->get_name() ];
145 145
 
146
-        // check if any prices use this price type
147
-        $prc_query_params = array(array('PRT_ID'=>array('IN',$would_be_deleted_price_type_ids)));
148
-        if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) {
149
-            $prices_names_and_ids = array();
150
-            foreach ($prices as $price) {
151
-                /* @var $price EE_Price */
152
-                $prices_names_and_ids[] = $price->name()."(".$price->ID().")";
153
-            }
154
-            $msg = sprintf(__('The Price Type(s) could not be deleted because there are existing Prices that currently use this Price Type.  If you still wish to delete this Price Type, then either delete those Prices or change them to use other Price Types.The prices are: %s', 'event_espresso'), implode(",", $prices_names_and_ids));
155
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
156
-            return false;
157
-        }
146
+		// check if any prices use this price type
147
+		$prc_query_params = array(array('PRT_ID'=>array('IN',$would_be_deleted_price_type_ids)));
148
+		if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) {
149
+			$prices_names_and_ids = array();
150
+			foreach ($prices as $price) {
151
+				/* @var $price EE_Price */
152
+				$prices_names_and_ids[] = $price->name()."(".$price->ID().")";
153
+			}
154
+			$msg = sprintf(__('The Price Type(s) could not be deleted because there are existing Prices that currently use this Price Type.  If you still wish to delete this Price Type, then either delete those Prices or change them to use other Price Types.The prices are: %s', 'event_espresso'), implode(",", $prices_names_and_ids));
155
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
156
+			return false;
157
+		}
158 158
 
159 159
 
160 160
 
161
-        return parent::delete_permanently($query_params);
162
-    }
161
+		return parent::delete_permanently($query_params);
162
+	}
163 163
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public function get_base_type_name($base_type_int)
43 43
     {
44
-        return $this->base_types[ $base_type_int ];
44
+        return $this->base_types[$base_type_int];
45 45
     }
46 46
 
47 47
     /**
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
             'WP_User' => new EE_Belongs_To_Relation(),
95 95
         );
96 96
         // this model is generally available for reading
97
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
97
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
98 98
         // all price types are "default" in terms of capability names
99 99
         $this->_caps_slug = 'default_price_types';
100 100
         parent::__construct($timezone);
@@ -141,10 +141,10 @@  discard block
 block discarded – undo
141 141
         $would_be_deleted_price_types = $this->get_all_deleted_and_undeleted($query_params);
142 142
         $would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types);
143 143
 
144
-        $ID = $query_params[0][ $this->get_primary_key_field()->get_name() ];
144
+        $ID = $query_params[0][$this->get_primary_key_field()->get_name()];
145 145
 
146 146
         // check if any prices use this price type
147
-        $prc_query_params = array(array('PRT_ID'=>array('IN',$would_be_deleted_price_type_ids)));
147
+        $prc_query_params = array(array('PRT_ID'=>array('IN', $would_be_deleted_price_type_ids)));
148 148
         if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) {
149 149
             $prices_names_and_ids = array();
150 150
             foreach ($prices as $price) {
Please login to merge, or discard this patch.
core/db_models/EEM_System_Status.model.php 3 patches
Doc Comments   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,8 +15,6 @@  discard block
 block discarded – undo
15 15
      *      This function is a singleton method used to instantiate the EEM_Attendee object
16 16
      *
17 17
      *      @access public
18
-     *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
19
-     *      @return EEM_System_Status
20 18
      */
21 19
     public static function instance()
22 20
     {
@@ -157,7 +155,7 @@  discard block
 block discarded – undo
157 155
 
158 156
     /**
159 157
      *
160
-     * @return array like EE_Config class
158
+     * @return EE_Config like EE_Config class
161 159
      */
162 160
     public function get_ee_config()
163 161
     {
@@ -214,7 +212,7 @@  discard block
 block discarded – undo
214 212
 
215 213
     /**
216 214
      * Checks if site responds ot HTTPS
217
-     * @return boolean
215
+     * @return string
218 216
      */
219 217
     public function get_https_enabled()
220 218
     {
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -93,9 +93,9 @@  discard block
 block discarded – undo
93 93
         $active_plugins = array_map('strtolower', $active_plugins);
94 94
         $plugin_info = array();
95 95
         foreach ($active_plugins as $plugin) {
96
-                $plugin_data = @get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin);
96
+                $plugin_data = @get_plugin_data(WP_PLUGIN_DIR.'/'.$plugin);
97 97
 
98
-                $plugin_info[ $plugin ] = $plugin_data;
98
+                $plugin_info[$plugin] = $plugin_data;
99 99
         }
100 100
         return $plugin_info;
101 101
     }
@@ -108,9 +108,9 @@  discard block
 block discarded – undo
108 108
     {
109 109
         $wp_memory_int = $this->let_to_num(WP_MEMORY_LIMIT);
110 110
         if ($wp_memory_int < 67108864) {
111
-            $wp_memory_to_display = '<mark class="error">' . sprintf(__('%s - We recommend setting memory to at least 64MB. See: %s Increasing memory allocated to PHP %s', 'event_espresso'), WP_MEMORY_LIMIT, '<a href="http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP">', '</a>"') . '</mark>';
111
+            $wp_memory_to_display = '<mark class="error">'.sprintf(__('%s - We recommend setting memory to at least 64MB. See: %s Increasing memory allocated to PHP %s', 'event_espresso'), WP_MEMORY_LIMIT, '<a href="http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP">', '</a>"').'</mark>';
112 112
         } else {
113
-            $wp_memory_to_display = '<mark class="yes">' . size_format($wp_memory_int) . '</mark>';
113
+            $wp_memory_to_display = '<mark class="yes">'.size_format($wp_memory_int).'</mark>';
114 114
         }
115 115
         return array(
116 116
             'name'=>get_bloginfo('name', 'display'),
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
         $options = EE_Data_Migration_Manager::instance()->get_all_migration_script_options();
150 150
         $presentable_migration_scripts = array();
151 151
         foreach ($options as $option_array) {
152
-            $presentable_migration_scripts[ str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_array['option_name']) ] = maybe_unserialize($option_array['option_value']);
152
+            $presentable_migration_scripts[str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_array['option_name'])] = maybe_unserialize($option_array['option_value']);
153 153
         }
154 154
         return $presentable_migration_scripts;
155 155
 //      return get_option(EE_Data_Migration_Manager::data_migrations_option_name);//EE_Data_Migration_Manager::instance()->get_data_migrations_ran();
@@ -175,18 +175,18 @@  discard block
 block discarded – undo
175 175
 
176 176
         $pi = preg_replace(
177 177
             array('#^.*<body>(.*)</body>.*$#ms', '#<h2>PHP License</h2>.*$#ms',
178
-            '#<h1>Configuration</h1>#',  "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#',
178
+            '#<h1>Configuration</h1>#', "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#',
179 179
             "#[ \t]+#", '#&nbsp;#', '#  +#', '# class=".*?"#', '%&#039;%',
180 180
             '#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>'
181 181
             .'<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#',
182 182
             '#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#',
183 183
             '#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#',
184 184
             "# +#", '#<tr>#', '#</tr>#'),
185
-            array('$1', '', '', '', '</$1>' . "\n", '<', ' ', ' ', ' ', '', ' ',
185
+            array('$1', '', '', '', '</$1>'."\n", '<', ' ', ' ', ' ', '', ' ',
186 186
             '<h2>PHP Configuration</h2>'."\n".'<tr><td>PHP Version</td><td>$2</td></tr>'.
187 187
             "\n".'<tr><td>PHP Egg</td><td>$1</td></tr>',
188 188
             '<tr><td>PHP Credits Egg</td><td>$1</td></tr>',
189
-            '<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" .
189
+            '<tr><td>Zend Engine</td><td>$2</td></tr>'."\n".
190 190
             '<tr><td>Zend Egg</td><td>$1</td></tr>', ' ', '%S%', '%E%'),
191 191
             ob_get_clean()
192 192
         );
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
             foreach ($askapache as $m) {
207 207
                 $m2 = isset($m[2]) ? $m[2] : null;
208 208
             }
209
-              $pi[ $n ][ $m[1] ]=(!isset($m[3])||$m2==$m[3]) ? $m2 : array_slice($m, 2);
209
+              $pi[$n][$m[1]] = ( ! isset($m[3]) || $m2 == $m[3]) ? $m2 : array_slice($m, 2);
210 210
         }
211 211
 
212 212
         return $pi;
@@ -235,8 +235,8 @@  discard block
 block discarded – undo
235 235
      */
236 236
     public function get_wp_maintenance_mode()
237 237
     {
238
-        $opened = file_exists(ABSPATH . '.maintenance');
239
-        return $opened ? sprintf(__('%s.maintenance file detected.%s Wordpress may have a failed auto-update which could prevent Event Espresso from updating the database correctly.', 'event_espresso'), '<strong>', '</strong>') : __('.maintenance file not detected. WordPress is not in maintenance mode.', 'event_espresso')  ;
238
+        $opened = file_exists(ABSPATH.'.maintenance');
239
+        return $opened ? sprintf(__('%s.maintenance file detected.%s Wordpress may have a failed auto-update which could prevent Event Espresso from updating the database correctly.', 'event_espresso'), '<strong>', '</strong>') : __('.maintenance file not detected. WordPress is not in maintenance mode.', 'event_espresso');
240 240
     }
241 241
     /**
242 242
      * Whether or not logging is enabled
@@ -244,8 +244,8 @@  discard block
 block discarded – undo
244 244
      */
245 245
     public function get_logging_enabled()
246 246
     {
247
-            $opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR . '/logs/espresso_log.txt', 'a');
248
-            return $opened ? __('Log Directory is writable', 'event_espresso') : sprintf(__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>') ;
247
+            $opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR.'/logs/espresso_log.txt', 'a');
248
+            return $opened ? __('Log Directory is writable', 'event_espresso') : sprintf(__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>');
249 249
     }
250 250
     /**
251 251
      *  Whether curl ro fsock works
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
         } elseif ($curl_works) {
263 263
             $status = __('Your server has cURL enabled, fsockopen is disabled.', 'event_espresso');
264 264
         } else {
265
-            $status = __('Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'event_espresso'). '</mark>';
265
+            $status = __('Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'event_espresso').'</mark>';
266 266
         }
267 267
         return $status;
268 268
     }
Please login to merge, or discard this patch.
Indentation   +273 added lines, -273 removed lines patch added patch discarded remove patch
@@ -6,79 +6,79 @@  discard block
 block discarded – undo
6 6
 class EEM_System_Status
7 7
 {
8 8
 
9
-    // private instance of the EEM_System_Status object
10
-    protected static $_instance = null;
9
+	// private instance of the EEM_System_Status object
10
+	protected static $_instance = null;
11 11
 
12 12
 
13 13
 
14
-    /**
15
-     *      This function is a singleton method used to instantiate the EEM_Attendee object
16
-     *
17
-     *      @access public
18
-     *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
19
-     *      @return EEM_System_Status
20
-     */
21
-    public static function instance()
22
-    {
14
+	/**
15
+	 *      This function is a singleton method used to instantiate the EEM_Attendee object
16
+	 *
17
+	 *      @access public
18
+	 *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
19
+	 *      @return EEM_System_Status
20
+	 */
21
+	public static function instance()
22
+	{
23 23
 
24
-        // check if instance of EEM_System_Status already exists
25
-        if (self::$_instance === null) {
26
-            // instantiate EEM_System_Status
27
-            self::$_instance = new self();
28
-        }
29
-        return self::$_instance;
30
-    }
31
-    private function __construct()
32
-    {
33
-    }
34
-    /**
35
-     *
36
-     * @return array where each key is a function name on this class, and each value is SOMETHING--
37
-     * it might be a value, an array, or an object
38
-     */
39
-    public function get_system_stati()
40
-    {
41
-        return apply_filters(
42
-            'FHEE__EEM_System_Status__get_system_stati',
43
-            array(
44
-                'ee_version'=>$this->get_ee_version(),
45
-                'ee_activation_history'=>$this->get_ee_activation_history(),
46
-                'ee_config'=>$this->get_ee_config(),
47
-                'ee_migration_history'=>$this->get_ee_migration_history(),
48
-                'active_plugins'=>$this->get_active_plugins(),
49
-                'wp_settings'=>$this->get_wp_settings(),
50
-                'wp_maintenance_mode' => $this->get_wp_maintenance_mode(),
51
-                'https_enabled'=>$this->get_https_enabled(),
52
-                'logging_enabled' => $this->get_logging_enabled(),
53
-                'remote_posting' => $this->get_remote_posting(),
54
-                'php_version'=>$this->php_version(),
55
-                'php.ini_settings'=>$this->get_php_ini_all(),
56
-                'php_info'=>$this->get_php_info(),
57
-            ),
58
-            $this
59
-        );
60
-    }
61
-    /**
62
-     *
63
-     * @return string
64
-     */
65
-    public function get_ee_version()
66
-    {
67
-        return espresso_version();
68
-    }
69
-    /**
70
-     *
71
-     * @return string
72
-     */
73
-    public function php_version()
74
-    {
75
-        return phpversion();
76
-    }
77
-    /**
78
-     *
79
-     * @return array, where each key is a plugin name (lower-cased), values are sub-arrays.
80
-     * Sub-arrays like described in wp function get_plugin_data. Ie,     *
81
-     *  'Name' => 'Plugin Name',
24
+		// check if instance of EEM_System_Status already exists
25
+		if (self::$_instance === null) {
26
+			// instantiate EEM_System_Status
27
+			self::$_instance = new self();
28
+		}
29
+		return self::$_instance;
30
+	}
31
+	private function __construct()
32
+	{
33
+	}
34
+	/**
35
+	 *
36
+	 * @return array where each key is a function name on this class, and each value is SOMETHING--
37
+	 * it might be a value, an array, or an object
38
+	 */
39
+	public function get_system_stati()
40
+	{
41
+		return apply_filters(
42
+			'FHEE__EEM_System_Status__get_system_stati',
43
+			array(
44
+				'ee_version'=>$this->get_ee_version(),
45
+				'ee_activation_history'=>$this->get_ee_activation_history(),
46
+				'ee_config'=>$this->get_ee_config(),
47
+				'ee_migration_history'=>$this->get_ee_migration_history(),
48
+				'active_plugins'=>$this->get_active_plugins(),
49
+				'wp_settings'=>$this->get_wp_settings(),
50
+				'wp_maintenance_mode' => $this->get_wp_maintenance_mode(),
51
+				'https_enabled'=>$this->get_https_enabled(),
52
+				'logging_enabled' => $this->get_logging_enabled(),
53
+				'remote_posting' => $this->get_remote_posting(),
54
+				'php_version'=>$this->php_version(),
55
+				'php.ini_settings'=>$this->get_php_ini_all(),
56
+				'php_info'=>$this->get_php_info(),
57
+			),
58
+			$this
59
+		);
60
+	}
61
+	/**
62
+	 *
63
+	 * @return string
64
+	 */
65
+	public function get_ee_version()
66
+	{
67
+		return espresso_version();
68
+	}
69
+	/**
70
+	 *
71
+	 * @return string
72
+	 */
73
+	public function php_version()
74
+	{
75
+		return phpversion();
76
+	}
77
+	/**
78
+	 *
79
+	 * @return array, where each key is a plugin name (lower-cased), values are sub-arrays.
80
+	 * Sub-arrays like described in wp function get_plugin_data. Ie,     *
81
+	 *  'Name' => 'Plugin Name',
82 82
         'PluginURI' => 'Plugin URI',
83 83
         'Version' => 'Version',
84 84
         'Description' => 'Description',
@@ -87,221 +87,221 @@  discard block
 block discarded – undo
87 87
         'TextDomain' => 'Text Domain',
88 88
         'DomainPath' => 'Domain Path',
89 89
         'Network' => 'Network',
90
-     */
91
-    public function get_active_plugins()
92
-    {
93
-        $active_plugins = (array) get_option('active_plugins', array());
94
-        if (is_multisite()) {
95
-            $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array()));
96
-        }
97
-        $active_plugins = array_map('strtolower', $active_plugins);
98
-        $plugin_info = array();
99
-        foreach ($active_plugins as $plugin) {
100
-                $plugin_data = @get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin);
90
+	 */
91
+	public function get_active_plugins()
92
+	{
93
+		$active_plugins = (array) get_option('active_plugins', array());
94
+		if (is_multisite()) {
95
+			$active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array()));
96
+		}
97
+		$active_plugins = array_map('strtolower', $active_plugins);
98
+		$plugin_info = array();
99
+		foreach ($active_plugins as $plugin) {
100
+				$plugin_data = @get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin);
101 101
 
102
-                $plugin_info[ $plugin ] = $plugin_data;
103
-        }
104
-        return $plugin_info;
105
-    }
102
+				$plugin_info[ $plugin ] = $plugin_data;
103
+		}
104
+		return $plugin_info;
105
+	}
106 106
 
107
-    /**
108
-     *
109
-     * @return array with keys 'home_url' and 'site_url'
110
-     */
111
-    public function get_wp_settings()
112
-    {
113
-        $wp_memory_int = $this->let_to_num(WP_MEMORY_LIMIT);
114
-        if ($wp_memory_int < 67108864) {
115
-            $wp_memory_to_display = '<mark class="error">' . sprintf(__('%s - We recommend setting memory to at least 64MB. See: %s Increasing memory allocated to PHP %s', 'event_espresso'), WP_MEMORY_LIMIT, '<a href="http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP">', '</a>"') . '</mark>';
116
-        } else {
117
-            $wp_memory_to_display = '<mark class="yes">' . size_format($wp_memory_int) . '</mark>';
118
-        }
119
-        return array(
120
-            'name'=>get_bloginfo('name', 'display'),
121
-            'is_multisite'=>is_multisite(),
122
-            'version'=>  get_bloginfo('version', 'display'),
123
-            'home_url'=>home_url(),
124
-            'site_url'=>site_url(),
125
-            'WP_DEBUG'=>WP_DEBUG,
126
-            'permalink_structure'=>get_option('permalink_structure'),
127
-            'theme'=>wp_get_theme(),
128
-            'gmt_offset'=>get_option('gmt_offset'),
129
-            'timezone_string'=>get_option('timezone_string'),
130
-            'admin_email'=>  get_bloginfo('admin_email', 'display'),
131
-            'language'=>get_bloginfo('language', 'display'),
132
-            'wp_max_upload_size' => size_format(wp_max_upload_size()),
133
-            'wp_memory' => $wp_memory_to_display
134
-            );
135
-    }
107
+	/**
108
+	 *
109
+	 * @return array with keys 'home_url' and 'site_url'
110
+	 */
111
+	public function get_wp_settings()
112
+	{
113
+		$wp_memory_int = $this->let_to_num(WP_MEMORY_LIMIT);
114
+		if ($wp_memory_int < 67108864) {
115
+			$wp_memory_to_display = '<mark class="error">' . sprintf(__('%s - We recommend setting memory to at least 64MB. See: %s Increasing memory allocated to PHP %s', 'event_espresso'), WP_MEMORY_LIMIT, '<a href="http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP">', '</a>"') . '</mark>';
116
+		} else {
117
+			$wp_memory_to_display = '<mark class="yes">' . size_format($wp_memory_int) . '</mark>';
118
+		}
119
+		return array(
120
+			'name'=>get_bloginfo('name', 'display'),
121
+			'is_multisite'=>is_multisite(),
122
+			'version'=>  get_bloginfo('version', 'display'),
123
+			'home_url'=>home_url(),
124
+			'site_url'=>site_url(),
125
+			'WP_DEBUG'=>WP_DEBUG,
126
+			'permalink_structure'=>get_option('permalink_structure'),
127
+			'theme'=>wp_get_theme(),
128
+			'gmt_offset'=>get_option('gmt_offset'),
129
+			'timezone_string'=>get_option('timezone_string'),
130
+			'admin_email'=>  get_bloginfo('admin_email', 'display'),
131
+			'language'=>get_bloginfo('language', 'display'),
132
+			'wp_max_upload_size' => size_format(wp_max_upload_size()),
133
+			'wp_memory' => $wp_memory_to_display
134
+			);
135
+	}
136 136
 
137
-    /**
138
-     * Gets an array of information about the history of ee versions installed
139
-     * @return array
140
-     */
141
-    public function get_ee_activation_history()
142
-    {
143
-        return get_option('espresso_db_update');
144
-    }
137
+	/**
138
+	 * Gets an array of information about the history of ee versions installed
139
+	 * @return array
140
+	 */
141
+	public function get_ee_activation_history()
142
+	{
143
+		return get_option('espresso_db_update');
144
+	}
145 145
 
146 146
 
147
-    /**
148
-     * Gets an array where keys are ee versions, and their values are arrays indicating all the different times that version was installed
149
-     * @return EE_Data_Migration_Script_Base[]
150
-     */
151
-    public function get_ee_migration_history()
152
-    {
153
-        $options = EE_Data_Migration_Manager::instance()->get_all_migration_script_options();
154
-        $presentable_migration_scripts = array();
155
-        foreach ($options as $option_array) {
156
-            $presentable_migration_scripts[ str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_array['option_name']) ] = maybe_unserialize($option_array['option_value']);
157
-        }
158
-        return $presentable_migration_scripts;
147
+	/**
148
+	 * Gets an array where keys are ee versions, and their values are arrays indicating all the different times that version was installed
149
+	 * @return EE_Data_Migration_Script_Base[]
150
+	 */
151
+	public function get_ee_migration_history()
152
+	{
153
+		$options = EE_Data_Migration_Manager::instance()->get_all_migration_script_options();
154
+		$presentable_migration_scripts = array();
155
+		foreach ($options as $option_array) {
156
+			$presentable_migration_scripts[ str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_array['option_name']) ] = maybe_unserialize($option_array['option_value']);
157
+		}
158
+		return $presentable_migration_scripts;
159 159
 //      return get_option(EE_Data_Migration_Manager::data_migrations_option_name);//EE_Data_Migration_Manager::instance()->get_data_migrations_ran();
160
-    }
160
+	}
161 161
 
162
-    /**
163
-     *
164
-     * @return array like EE_Config class
165
-     */
166
-    public function get_ee_config()
167
-    {
168
-        return EE_Config::instance();
169
-    }
162
+	/**
163
+	 *
164
+	 * @return array like EE_Config class
165
+	 */
166
+	public function get_ee_config()
167
+	{
168
+		return EE_Config::instance();
169
+	}
170 170
 
171
-    /**
172
-     * Gets an array of php setup info, pilfered from http://www.php.net/manual/en/function.phpinfo.php#87463
173
-     * @return array like the output of phpinfo(), but in an array
174
-     */
175
-    public function get_php_info()
176
-    {
177
-        ob_start();
178
-        phpinfo(-1);
171
+	/**
172
+	 * Gets an array of php setup info, pilfered from http://www.php.net/manual/en/function.phpinfo.php#87463
173
+	 * @return array like the output of phpinfo(), but in an array
174
+	 */
175
+	public function get_php_info()
176
+	{
177
+		ob_start();
178
+		phpinfo(-1);
179 179
 
180
-        $pi = preg_replace(
181
-            array('#^.*<body>(.*)</body>.*$#ms', '#<h2>PHP License</h2>.*$#ms',
182
-            '#<h1>Configuration</h1>#',  "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#',
183
-            "#[ \t]+#", '#&nbsp;#', '#  +#', '# class=".*?"#', '%&#039;%',
184
-            '#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>'
185
-            .'<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#',
186
-            '#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#',
187
-            '#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#',
188
-            "# +#", '#<tr>#', '#</tr>#'),
189
-            array('$1', '', '', '', '</$1>' . "\n", '<', ' ', ' ', ' ', '', ' ',
190
-            '<h2>PHP Configuration</h2>'."\n".'<tr><td>PHP Version</td><td>$2</td></tr>'.
191
-            "\n".'<tr><td>PHP Egg</td><td>$1</td></tr>',
192
-            '<tr><td>PHP Credits Egg</td><td>$1</td></tr>',
193
-            '<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" .
194
-            '<tr><td>Zend Egg</td><td>$1</td></tr>', ' ', '%S%', '%E%'),
195
-            ob_get_clean()
196
-        );
180
+		$pi = preg_replace(
181
+			array('#^.*<body>(.*)</body>.*$#ms', '#<h2>PHP License</h2>.*$#ms',
182
+			'#<h1>Configuration</h1>#',  "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#',
183
+			"#[ \t]+#", '#&nbsp;#', '#  +#', '# class=".*?"#', '%&#039;%',
184
+			'#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>'
185
+			.'<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#',
186
+			'#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#',
187
+			'#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#',
188
+			"# +#", '#<tr>#', '#</tr>#'),
189
+			array('$1', '', '', '', '</$1>' . "\n", '<', ' ', ' ', ' ', '', ' ',
190
+			'<h2>PHP Configuration</h2>'."\n".'<tr><td>PHP Version</td><td>$2</td></tr>'.
191
+			"\n".'<tr><td>PHP Egg</td><td>$1</td></tr>',
192
+			'<tr><td>PHP Credits Egg</td><td>$1</td></tr>',
193
+			'<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" .
194
+			'<tr><td>Zend Egg</td><td>$1</td></tr>', ' ', '%S%', '%E%'),
195
+			ob_get_clean()
196
+		);
197 197
 
198
-        $sections = explode('<h2>', strip_tags($pi, '<h2><th><td>'));
199
-        unset($sections[0]);
198
+		$sections = explode('<h2>', strip_tags($pi, '<h2><th><td>'));
199
+		unset($sections[0]);
200 200
 
201
-        $pi = array();
202
-        foreach ($sections as $section) {
203
-            $n = substr($section, 0, strpos($section, '</h2>'));
204
-            preg_match_all(
205
-                '#%S%(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?%E%#',
206
-                $section,
207
-                $askapache,
208
-                PREG_SET_ORDER
209
-            );
210
-            foreach ($askapache as $m) {
211
-                $m2 = isset($m[2]) ? $m[2] : null;
212
-            }
213
-              $pi[ $n ][ $m[1] ]=(!isset($m[3])||$m2==$m[3]) ? $m2 : array_slice($m, 2);
214
-        }
201
+		$pi = array();
202
+		foreach ($sections as $section) {
203
+			$n = substr($section, 0, strpos($section, '</h2>'));
204
+			preg_match_all(
205
+				'#%S%(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?%E%#',
206
+				$section,
207
+				$askapache,
208
+				PREG_SET_ORDER
209
+			);
210
+			foreach ($askapache as $m) {
211
+				$m2 = isset($m[2]) ? $m[2] : null;
212
+			}
213
+			  $pi[ $n ][ $m[1] ]=(!isset($m[3])||$m2==$m[3]) ? $m2 : array_slice($m, 2);
214
+		}
215 215
 
216
-        return $pi;
217
-    }
216
+		return $pi;
217
+	}
218 218
 
219
-    /**
220
-     * Checks if site responds ot HTTPS
221
-     * @return boolean
222
-     */
223
-    public function get_https_enabled()
224
-    {
225
-        $home = str_replace("http://", "https://", home_url());
226
-        $response = wp_remote_get($home);
227
-        if ($response instanceof WP_Error) {
228
-            $error_string = '';
229
-            foreach ($response->errors as $short_name => $description_array) {
230
-                $error_string .= "<b>$short_name</b>: ".implode(", ", $description_array);
231
-            }
232
-            return $error_string;
233
-        }
234
-        return "ok!";
235
-    }
236
-    /**
237
-     * Whether or not a .maintenance file is detected
238
-     * @return string descripting wp_maintenance_mode status
239
-     */
240
-    public function get_wp_maintenance_mode()
241
-    {
242
-        $opened = file_exists(ABSPATH . '.maintenance');
243
-        return $opened ? sprintf(__('%s.maintenance file detected.%s Wordpress may have a failed auto-update which could prevent Event Espresso from updating the database correctly.', 'event_espresso'), '<strong>', '</strong>') : __('.maintenance file not detected. WordPress is not in maintenance mode.', 'event_espresso')  ;
244
-    }
245
-    /**
246
-     * Whether or not logging is enabled
247
-     * @return string descripting logging's status
248
-     */
249
-    public function get_logging_enabled()
250
-    {
251
-            $opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR . '/logs/espresso_log.txt', 'a');
252
-            return $opened ? __('Log Directory is writable', 'event_espresso') : sprintf(__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>') ;
253
-    }
254
-    /**
255
-     *  Whether curl ro fsock works
256
-     * @return string describing posting's status
257
-     */
258
-    public function get_remote_posting()
259
-    {
260
-        $fsock_works = function_exists('fsockopen');
261
-        $curl_works = function_exists('curl_init');
262
-        if ($fsock_works && $curl_works) {
263
-            $status = __('Your server has fsockopen and cURL enabled.', 'event_espresso');
264
-        } elseif ($fsock_works) {
265
-            $status = __('Your server has fsockopen enabled, cURL is disabled.', 'event_espresso');
266
-        } elseif ($curl_works) {
267
-            $status = __('Your server has cURL enabled, fsockopen is disabled.', 'event_espresso');
268
-        } else {
269
-            $status = __('Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'event_espresso'). '</mark>';
270
-        }
271
-        return $status;
272
-    }
273
-    /**
274
-     * Gets all the php.ini settings
275
-     * @return array
276
-     */
277
-    public function get_php_ini_all()
278
-    {
279
-        return ini_get_all();
280
-    }
281
-    /**
282
-     * Transforms the php.ini notation for numbers (like '2M') to an integer.
283
-     *
284
-     * @param type $size
285
-     * @return int
286
-     */
287
-    public function let_to_num($size)
288
-    {
289
-        $l      = substr($size, -1);
290
-        $ret    = substr($size, 0, -1);
291
-        // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment
292
-        switch (strtoupper($l)) {
293
-            case 'P':
294
-                $ret *= 1024;
295
-            case 'T':
296
-                $ret *= 1024;
297
-            case 'G':
298
-                $ret *= 1024;
299
-            case 'M':
300
-                $ret *= 1024;
301
-            case 'K':
302
-                $ret *= 1024;
303
-        }
304
-        // phpcs:enable
305
-        return $ret;
306
-    }
219
+	/**
220
+	 * Checks if site responds ot HTTPS
221
+	 * @return boolean
222
+	 */
223
+	public function get_https_enabled()
224
+	{
225
+		$home = str_replace("http://", "https://", home_url());
226
+		$response = wp_remote_get($home);
227
+		if ($response instanceof WP_Error) {
228
+			$error_string = '';
229
+			foreach ($response->errors as $short_name => $description_array) {
230
+				$error_string .= "<b>$short_name</b>: ".implode(", ", $description_array);
231
+			}
232
+			return $error_string;
233
+		}
234
+		return "ok!";
235
+	}
236
+	/**
237
+	 * Whether or not a .maintenance file is detected
238
+	 * @return string descripting wp_maintenance_mode status
239
+	 */
240
+	public function get_wp_maintenance_mode()
241
+	{
242
+		$opened = file_exists(ABSPATH . '.maintenance');
243
+		return $opened ? sprintf(__('%s.maintenance file detected.%s Wordpress may have a failed auto-update which could prevent Event Espresso from updating the database correctly.', 'event_espresso'), '<strong>', '</strong>') : __('.maintenance file not detected. WordPress is not in maintenance mode.', 'event_espresso')  ;
244
+	}
245
+	/**
246
+	 * Whether or not logging is enabled
247
+	 * @return string descripting logging's status
248
+	 */
249
+	public function get_logging_enabled()
250
+	{
251
+			$opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR . '/logs/espresso_log.txt', 'a');
252
+			return $opened ? __('Log Directory is writable', 'event_espresso') : sprintf(__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>') ;
253
+	}
254
+	/**
255
+	 *  Whether curl ro fsock works
256
+	 * @return string describing posting's status
257
+	 */
258
+	public function get_remote_posting()
259
+	{
260
+		$fsock_works = function_exists('fsockopen');
261
+		$curl_works = function_exists('curl_init');
262
+		if ($fsock_works && $curl_works) {
263
+			$status = __('Your server has fsockopen and cURL enabled.', 'event_espresso');
264
+		} elseif ($fsock_works) {
265
+			$status = __('Your server has fsockopen enabled, cURL is disabled.', 'event_espresso');
266
+		} elseif ($curl_works) {
267
+			$status = __('Your server has cURL enabled, fsockopen is disabled.', 'event_espresso');
268
+		} else {
269
+			$status = __('Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'event_espresso'). '</mark>';
270
+		}
271
+		return $status;
272
+	}
273
+	/**
274
+	 * Gets all the php.ini settings
275
+	 * @return array
276
+	 */
277
+	public function get_php_ini_all()
278
+	{
279
+		return ini_get_all();
280
+	}
281
+	/**
282
+	 * Transforms the php.ini notation for numbers (like '2M') to an integer.
283
+	 *
284
+	 * @param type $size
285
+	 * @return int
286
+	 */
287
+	public function let_to_num($size)
288
+	{
289
+		$l      = substr($size, -1);
290
+		$ret    = substr($size, 0, -1);
291
+		// phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment
292
+		switch (strtoupper($l)) {
293
+			case 'P':
294
+				$ret *= 1024;
295
+			case 'T':
296
+				$ret *= 1024;
297
+			case 'G':
298
+				$ret *= 1024;
299
+			case 'M':
300
+				$ret *= 1024;
301
+			case 'K':
302
+				$ret *= 1024;
303
+		}
304
+		// phpcs:enable
305
+		return $ret;
306
+	}
307 307
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_WP_Post_Status_Field.php 3 patches
Doc Comments   -2 removed lines patch added patch discarded remove patch
@@ -32,8 +32,6 @@
 block discarded – undo
32 32
      *                                    )
33 33
      *                                    )
34 34
      * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
35
-     * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is
36
-     *                                    set to true, it will be stored as an INT
37 35
      */
38 36
     public function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array())
39 37
     {
Please login to merge, or discard this patch.
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -3,114 +3,114 @@
 block discarded – undo
3 3
 class EE_WP_Post_Status_Field extends EE_Enum_Text_Field
4 4
 {
5 5
 
6
-    protected $_wp_post_stati;
6
+	protected $_wp_post_stati;
7 7
 
8 8
 
9
-    /**
10
-     * constructor
11
-     *
12
-     * @param string  $table_column       column on table
13
-     * @param string  $nicename           nice name for column(field)
14
-     * @param bool    $nullable           is this field nullable
15
-     * @param string  $default_value      default status
16
-     * @param array   $new_stati          If additional stati are to be used other than the default WP statuses then
17
-     *                                    they can be registered via this property.  The format of the array should be
18
-     *                                    as follows: array(
19
-     *                                    'status_reference' => array(
20
-     *                                    'label' => __('Status Reference Label', 'event_espresso')
21
-     *                                    'public' => true, //'Whether posts of this status should be shown on the
22
-     *                                    frontend of the site'
23
-     *                                    'exclude_from_search' => false, //'Whether posts of this status should be
24
-     *                                    excluded from wp searches'
25
-     *                                    'show_in_admin_all_list' => true, //whether posts of this status are included
26
-     *                                    in queries for the admin "all" view in list table views.
27
-     *                                    'show_in_admin_status_list' => true, //Show in the list of statuses with post
28
-     *                                    counts at the top of the admin list tables (i.e. Status Reference(2) )
29
-     *                                    'label_count' => _n_noop( 'Status Reference <span class="count">(%s)</span>',
30
-     *                                    'Status References <span class="count">(%s)</span>' ), //the text to display
31
-     *                                    on the admin screen( or you won't see your status count ).
32
-     *                                    )
33
-     *                                    )
34
-     * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
35
-     * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is
36
-     *                                    set to true, it will be stored as an INT
37
-     */
38
-    public function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array())
39
-    {
40
-        $this->_register_new_stati($new_stati);
41
-        $this->_set_allowed_enum_values();
42
-        parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values);
43
-    }
9
+	/**
10
+	 * constructor
11
+	 *
12
+	 * @param string  $table_column       column on table
13
+	 * @param string  $nicename           nice name for column(field)
14
+	 * @param bool    $nullable           is this field nullable
15
+	 * @param string  $default_value      default status
16
+	 * @param array   $new_stati          If additional stati are to be used other than the default WP statuses then
17
+	 *                                    they can be registered via this property.  The format of the array should be
18
+	 *                                    as follows: array(
19
+	 *                                    'status_reference' => array(
20
+	 *                                    'label' => __('Status Reference Label', 'event_espresso')
21
+	 *                                    'public' => true, //'Whether posts of this status should be shown on the
22
+	 *                                    frontend of the site'
23
+	 *                                    'exclude_from_search' => false, //'Whether posts of this status should be
24
+	 *                                    excluded from wp searches'
25
+	 *                                    'show_in_admin_all_list' => true, //whether posts of this status are included
26
+	 *                                    in queries for the admin "all" view in list table views.
27
+	 *                                    'show_in_admin_status_list' => true, //Show in the list of statuses with post
28
+	 *                                    counts at the top of the admin list tables (i.e. Status Reference(2) )
29
+	 *                                    'label_count' => _n_noop( 'Status Reference <span class="count">(%s)</span>',
30
+	 *                                    'Status References <span class="count">(%s)</span>' ), //the text to display
31
+	 *                                    on the admin screen( or you won't see your status count ).
32
+	 *                                    )
33
+	 *                                    )
34
+	 * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
35
+	 * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is
36
+	 *                                    set to true, it will be stored as an INT
37
+	 */
38
+	public function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array())
39
+	{
40
+		$this->_register_new_stati($new_stati);
41
+		$this->_set_allowed_enum_values();
42
+		parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values);
43
+	}
44 44
 
45 45
 
46
-    /**
47
-     * This registers any new statuses sent via the $new_stati array on construct
48
-     *
49
-     * @access protected
50
-     * @param  array $new_stati statuses
51
-     * @return void
52
-     */
53
-    protected function _register_new_stati($new_stati)
54
-    {
46
+	/**
47
+	 * This registers any new statuses sent via the $new_stati array on construct
48
+	 *
49
+	 * @access protected
50
+	 * @param  array $new_stati statuses
51
+	 * @return void
52
+	 */
53
+	protected function _register_new_stati($new_stati)
54
+	{
55 55
 
56
-        foreach ((array) $new_stati as $status_key => $status_args) {
57
-            $args = array(
58
-                'label'                     => isset($status_args['label']) ? $status_args['label'] : $status_key,
59
-                'public'                    => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true,
60
-                'exclude_from_search'       => isset($status_args['exclude_from_search']) && is_bool($status_args['exclude_from_search']) ? $status_args['exclude_from_search'] : false,
61
-                'show_in_admin_all_list'    => isset($status_args['show_in_admin_all_list']) && is_bool($status_args['show_in_admin_all_list']) ? $status_args['show_in_admin_all_list'] : false,
62
-                'show_in_admin_status_list' => isset($status_args['show_in_admin_status_list']) && is_bool($status_args['show_in_admin_status_list']) ? $status_args['show_in_admin_status_list'] : true,
63
-                'label_count'               => isset($status_args['label_count']) ? $status_args['label_count'] : '',
64
-            );
65
-            register_post_status($status_key, $status_args);
66
-        }
67
-    }
56
+		foreach ((array) $new_stati as $status_key => $status_args) {
57
+			$args = array(
58
+				'label'                     => isset($status_args['label']) ? $status_args['label'] : $status_key,
59
+				'public'                    => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true,
60
+				'exclude_from_search'       => isset($status_args['exclude_from_search']) && is_bool($status_args['exclude_from_search']) ? $status_args['exclude_from_search'] : false,
61
+				'show_in_admin_all_list'    => isset($status_args['show_in_admin_all_list']) && is_bool($status_args['show_in_admin_all_list']) ? $status_args['show_in_admin_all_list'] : false,
62
+				'show_in_admin_status_list' => isset($status_args['show_in_admin_status_list']) && is_bool($status_args['show_in_admin_status_list']) ? $status_args['show_in_admin_status_list'] : true,
63
+				'label_count'               => isset($status_args['label_count']) ? $status_args['label_count'] : '',
64
+			);
65
+			register_post_status($status_key, $status_args);
66
+		}
67
+	}
68 68
 
69 69
 
70
-    /**
71
-     * This sets the _allowed_enum_values property using the $wp_post_stati array
72
-     *
73
-     * @access protected
74
-     * @regurn void
75
-     */
76
-    protected function _set_allowed_enum_values()
77
-    {
78
-        // first let's get the post_statuses
79
-        global $wp_post_statuses;
80
-        $this->_wp_post_stati = $wp_post_statuses;
70
+	/**
71
+	 * This sets the _allowed_enum_values property using the $wp_post_stati array
72
+	 *
73
+	 * @access protected
74
+	 * @regurn void
75
+	 */
76
+	protected function _set_allowed_enum_values()
77
+	{
78
+		// first let's get the post_statuses
79
+		global $wp_post_statuses;
80
+		$this->_wp_post_stati = $wp_post_statuses;
81 81
 
82
-        foreach ($this->_wp_post_stati as $post_status => $args_object) {
83
-            $this->_allowed_enum_values[ $post_status ] = $args_object->label;
84
-        }
85
-    }
82
+		foreach ($this->_wp_post_stati as $post_status => $args_object) {
83
+			$this->_allowed_enum_values[ $post_status ] = $args_object->label;
84
+		}
85
+	}
86 86
 
87
-    /**
88
-     * Before calling parent, first double-checks our list of acceptable post
89
-     * types is up-to-date
90
-     *
91
-     * @param string $value_inputted_for_field_on_model_object
92
-     * @return string
93
-     */
94
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
95
-    {
96
-        $this->_set_allowed_enum_values();
97
-        return parent::prepare_for_set($value_inputted_for_field_on_model_object);
98
-    }
87
+	/**
88
+	 * Before calling parent, first double-checks our list of acceptable post
89
+	 * types is up-to-date
90
+	 *
91
+	 * @param string $value_inputted_for_field_on_model_object
92
+	 * @return string
93
+	 */
94
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
95
+	{
96
+		$this->_set_allowed_enum_values();
97
+		return parent::prepare_for_set($value_inputted_for_field_on_model_object);
98
+	}
99 99
 
100 100
 
101 101
 
102
-    // helper methods for getting various $wp_post_statuses stuff.
102
+	// helper methods for getting various $wp_post_statuses stuff.
103 103
 
104
-    /**
105
-     * This just returns the status object for the given status
106
-     *
107
-     * @access public
108
-     * @see    wp_register_post_status in wp-includes/post.php for a list of properties of the status object
109
-     * @param  string $status What status object you want
110
-     * @return std_object         the status object or FALSE if it doesn't exist.
111
-     */
112
-    public function get_status_object($status)
113
-    {
114
-        return isset($this->_wp_post_stati[ $status ]) ? $this->_wp_post_stati[ $status ] : false;
115
-    }
104
+	/**
105
+	 * This just returns the status object for the given status
106
+	 *
107
+	 * @access public
108
+	 * @see    wp_register_post_status in wp-includes/post.php for a list of properties of the status object
109
+	 * @param  string $status What status object you want
110
+	 * @return std_object         the status object or FALSE if it doesn't exist.
111
+	 */
112
+	public function get_status_object($status)
113
+	{
114
+		return isset($this->_wp_post_stati[ $status ]) ? $this->_wp_post_stati[ $status ] : false;
115
+	}
116 116
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
         $this->_wp_post_stati = $wp_post_statuses;
81 81
 
82 82
         foreach ($this->_wp_post_stati as $post_status => $args_object) {
83
-            $this->_allowed_enum_values[ $post_status ] = $args_object->label;
83
+            $this->_allowed_enum_values[$post_status] = $args_object->label;
84 84
         }
85 85
     }
86 86
 
@@ -111,6 +111,6 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public function get_status_object($status)
113 113
     {
114
-        return isset($this->_wp_post_stati[ $status ]) ? $this->_wp_post_stati[ $status ] : false;
114
+        return isset($this->_wp_post_stati[$status]) ? $this->_wp_post_stati[$status] : false;
115 115
     }
116 116
 }
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Model_Query_Info_Carrier.php 3 patches
Doc Comments   +14 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,19 +44,33 @@  discard block
 block discarded – undo
44 44
    
45 45
     private $_group_by_sql;
46 46
    
47
+    /**
48
+     * @param string $limit_sql
49
+     */
47 50
     public function set_limit_sql($limit_sql)
48 51
     {
49 52
         $this->_limit_sql = $limit_sql;
50 53
     }
51 54
     
55
+    /**
56
+     * @param string $order_by_sql
57
+     */
52 58
     public function set_order_by_sql($order_by_sql)
53 59
     {
54 60
         $this->_order_by_sql = $order_by_sql;
55 61
     }
62
+
63
+    /**
64
+     * @param string $group_by_sql
65
+     */
56 66
     public function set_group_by_sql($group_by_sql)
57 67
     {
58 68
         $this->_group_by_sql = $group_by_sql;
59 69
     }
70
+
71
+    /**
72
+     * @param string $having_sql
73
+     */
60 74
     public function set_having_sql($having_sql)
61 75
     {
62 76
         $this->_having_sql = $having_sql;
@@ -81,7 +95,6 @@  discard block
 block discarded – undo
81 95
     *
82 96
     * @param type $model_included_name
83 97
     * @param type $join_sql
84
-    * @param type $data_types
85 98
     */
86 99
     public function __construct($model_included_name = array(), $join_sql = '')
87 100
     {
Please login to merge, or discard this patch.
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -14,141 +14,141 @@  discard block
 block discarded – undo
14 14
    /**
15 15
     * @var string SQL for performing joins (Eg, "INNER JOIN blah ON blah=blah INNER JOIN FOO ON foo=foo...")
16 16
     */
17
-    private $_join_sql;
17
+	private $_join_sql;
18 18
    /**
19 19
     *
20 20
     * @var array stating all the models that have been included thus far,so we don't get duplicates.
21 21
     * Keys are the model relation chains to them from the queried model
22 22
     * (eg, "Registration.Transaction.Payment"), and valuesare model names (eg "Payment")
23 23
     */
24
-    private $_models_included;
24
+	private $_models_included;
25 25
    
26 26
    /**
27 27
     * After we've acquired all the data types, we can create this sql.
28 28
     * @var string
29 29
     */
30
-    private $_where_sql;
30
+	private $_where_sql;
31 31
    /**
32 32
     * Full join sql. Eg, in a select query, that's everything after the "FROM", and before the "WHERE", so it includes
33 33
     * the declaration of the main model's tables, and then appends all the joining sql to other models
34 34
     * @var string
35 35
     */
36
-    private $_main_join_sql;
36
+	private $_main_join_sql;
37 37
    
38 38
    
39
-    private $_limit_sql;
39
+	private $_limit_sql;
40 40
    
41
-    private $_order_by_sql;
41
+	private $_order_by_sql;
42 42
    
43
-    private $_having_sql;
43
+	private $_having_sql;
44 44
    
45
-    private $_group_by_sql;
45
+	private $_group_by_sql;
46 46
    
47
-    public function set_limit_sql($limit_sql)
48
-    {
49
-        $this->_limit_sql = $limit_sql;
50
-    }
47
+	public function set_limit_sql($limit_sql)
48
+	{
49
+		$this->_limit_sql = $limit_sql;
50
+	}
51 51
     
52
-    public function set_order_by_sql($order_by_sql)
53
-    {
54
-        $this->_order_by_sql = $order_by_sql;
55
-    }
56
-    public function set_group_by_sql($group_by_sql)
57
-    {
58
-        $this->_group_by_sql = $group_by_sql;
59
-    }
60
-    public function set_having_sql($having_sql)
61
-    {
62
-        $this->_having_sql = $having_sql;
63
-    }
64
-    public function get_limit_sql()
65
-    {
66
-        return $this->_limit_sql;
67
-    }
68
-    public function get_order_by_sql()
69
-    {
70
-        return $this->_order_by_sql;
71
-    }
72
-    public function get_group_by_sql()
73
-    {
74
-        return $this->_group_by_sql;
75
-    }
76
-    public function get_having_sql()
77
-    {
78
-        return $this->_having_sql;
79
-    }
52
+	public function set_order_by_sql($order_by_sql)
53
+	{
54
+		$this->_order_by_sql = $order_by_sql;
55
+	}
56
+	public function set_group_by_sql($group_by_sql)
57
+	{
58
+		$this->_group_by_sql = $group_by_sql;
59
+	}
60
+	public function set_having_sql($having_sql)
61
+	{
62
+		$this->_having_sql = $having_sql;
63
+	}
64
+	public function get_limit_sql()
65
+	{
66
+		return $this->_limit_sql;
67
+	}
68
+	public function get_order_by_sql()
69
+	{
70
+		return $this->_order_by_sql;
71
+	}
72
+	public function get_group_by_sql()
73
+	{
74
+		return $this->_group_by_sql;
75
+	}
76
+	public function get_having_sql()
77
+	{
78
+		return $this->_having_sql;
79
+	}
80 80
    /**
81 81
     *
82 82
     * @param type $model_included_name
83 83
     * @param type $join_sql
84 84
     * @param type $data_types
85 85
     */
86
-    public function __construct($model_included_name = array(), $join_sql = '')
87
-    {
88
-        $this->_models_included = $model_included_name;
89
-        $this->_join_sql = $join_sql;
90
-    }
86
+	public function __construct($model_included_name = array(), $join_sql = '')
87
+	{
88
+		$this->_models_included = $model_included_name;
89
+		$this->_join_sql = $join_sql;
90
+	}
91 91
    
92 92
    /**
93 93
     * Merges info from the other EEM_Related_Model_Info_Carrier into this one.
94 94
     * @param EE_Model_Query_Info_Carrier $other_model_query_info_carrier
95 95
     */
96
-    public function merge($other_model_query_info_carrier)
97
-    {
98
-        if ($other_model_query_info_carrier && ! $this->_have_already_included_one_of_these_models($other_model_query_info_carrier->get_model_names_included())) {
99
-            $model_included_on_other_join_sql_and_data_types_carrier =  $other_model_query_info_carrier->get_model_names_included();
100
-            $this->_models_included = array_merge($this->_models_included, $model_included_on_other_join_sql_and_data_types_carrier);
101
-            $this->_join_sql .= $other_model_query_info_carrier->_join_sql;
102
-        }
103
-        // otherwise don't merge our data.
104
-        // yes, this means that we must immediately merge any model data into our grand list
105
-        // as soon as we get some from ONE model, or else we could reject a EEM_Related_Model_Info_Carrier
106
-        // which is carrying info from two models WHERE one is already included but the other is NOT
107
-    }
96
+	public function merge($other_model_query_info_carrier)
97
+	{
98
+		if ($other_model_query_info_carrier && ! $this->_have_already_included_one_of_these_models($other_model_query_info_carrier->get_model_names_included())) {
99
+			$model_included_on_other_join_sql_and_data_types_carrier =  $other_model_query_info_carrier->get_model_names_included();
100
+			$this->_models_included = array_merge($this->_models_included, $model_included_on_other_join_sql_and_data_types_carrier);
101
+			$this->_join_sql .= $other_model_query_info_carrier->_join_sql;
102
+		}
103
+		// otherwise don't merge our data.
104
+		// yes, this means that we must immediately merge any model data into our grand list
105
+		// as soon as we get some from ONE model, or else we could reject a EEM_Related_Model_Info_Carrier
106
+		// which is carrying info from two models WHERE one is already included but the other is NOT
107
+	}
108 108
    /**
109 109
     * Checks whether or not we have already included all the models mentione din $model_names on the query info varrier
110 110
     * @param array $model_names just like EE_MOdel_QUery_Info_Carrier::_models_included: keys are model chain paths, values are the model names only
111 111
     * @return boolean
112 112
     */
113
-    protected function _have_already_included_one_of_these_models($model_names)
114
-    {
115
-        foreach ($this->_models_included as $model_relation_path => $model_included) {
116
-            if (array_key_exists($model_relation_path, $model_names)) {
117
-                return true;
118
-            }
119
-        }
120
-        return false;
121
-    }
113
+	protected function _have_already_included_one_of_these_models($model_names)
114
+	{
115
+		foreach ($this->_models_included as $model_relation_path => $model_included) {
116
+			if (array_key_exists($model_relation_path, $model_names)) {
117
+				return true;
118
+			}
119
+		}
120
+		return false;
121
+	}
122 122
    /**
123 123
     * Array keys are model names, values are "model relation paths". See EE_Model_Query_Info_Carrier::_models_included for details
124 124
     * @return array like EE_Model_Query_Info_Carrier::_models_included
125 125
     */
126
-    public function get_model_names_included()
127
-    {
128
-        return $this->_models_included;
129
-    }
126
+	public function get_model_names_included()
127
+	{
128
+		return $this->_models_included;
129
+	}
130 130
    /**
131 131
     * sets the $where_sql for later use from client code
132 132
     * @param string $where_sql
133 133
     */
134
-    public function set_where_sql($where_sql)
135
-    {
136
-        $this->_where_sql = $where_sql;
137
-    }
138
-    public function get_where_sql()
139
-    {
140
-        return $this->_where_sql;
141
-    }
134
+	public function set_where_sql($where_sql)
135
+	{
136
+		$this->_where_sql = $where_sql;
137
+	}
138
+	public function get_where_sql()
139
+	{
140
+		return $this->_where_sql;
141
+	}
142 142
 
143 143
    /**
144 144
     * Gets the SQL for joining the main model to other models involves in the query, which was set earlier on
145 145
     * the EE_Model_Query_info_Carrier by calling set_main_model_join_sql()
146 146
     * @return string
147 147
     */
148
-    public function get_main_model_join_sql()
149
-    {
150
-        return $this->_main_join_sql;
151
-    }
148
+	public function get_main_model_join_sql()
149
+	{
150
+		return $this->_main_join_sql;
151
+	}
152 152
 
153 153
 
154 154
    /**
@@ -158,12 +158,12 @@  discard block
 block discarded – undo
158 158
     * after the FROM and before the WHERE.)
159 159
     * @param string $join_sql
160 160
     */
161
-    public function set_main_model_join_sql($join_sql)
162
-    {
163
-        $this->_main_join_sql = $join_sql;
164
-    }
165
-    public function get_full_join_sql()
166
-    {
167
-        return $this->_main_join_sql . $this->_join_sql;
168
-    }
161
+	public function set_main_model_join_sql($join_sql)
162
+	{
163
+		$this->_main_join_sql = $join_sql;
164
+	}
165
+	public function get_full_join_sql()
166
+	{
167
+		return $this->_main_join_sql . $this->_join_sql;
168
+	}
169 169
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
     public function merge($other_model_query_info_carrier)
97 97
     {
98 98
         if ($other_model_query_info_carrier && ! $this->_have_already_included_one_of_these_models($other_model_query_info_carrier->get_model_names_included())) {
99
-            $model_included_on_other_join_sql_and_data_types_carrier =  $other_model_query_info_carrier->get_model_names_included();
99
+            $model_included_on_other_join_sql_and_data_types_carrier = $other_model_query_info_carrier->get_model_names_included();
100 100
             $this->_models_included = array_merge($this->_models_included, $model_included_on_other_join_sql_and_data_types_carrier);
101 101
             $this->_join_sql .= $other_model_query_info_carrier->_join_sql;
102 102
         }
@@ -164,6 +164,6 @@  discard block
 block discarded – undo
164 164
     }
165 165
     public function get_full_join_sql()
166 166
     {
167
-        return $this->_main_join_sql . $this->_join_sql;
167
+        return $this->_main_join_sql.$this->_join_sql;
168 168
     }
169 169
 }
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Secondary_Table.php 3 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      * creates join statement FROM primary table
55 55
      * gets SQL like "LEFT JOIN table_name AS table_alias ON other_table_alias.pk = table_alias.fk
56 56
      *
57
-     * @param string $table allows us to set special conditions on the $table_name portion of the join query (i.e. doing a subquery)
57
+     * @param string $primary_table_alias_with_model_chain_prefix
58 58
      * @return string of SQL
59 59
      */
60 60
     public function get_join_sql($primary_table_alias_with_model_chain_prefix)
@@ -78,6 +78,7 @@  discard block
 block discarded – undo
78 78
      * " LEFT JOIN secondary_table_table AS Secondary ON ..." like get_join_sql, this function returns
79 79
      * " LEFT JOIN primary_table AS Primary ON ...".
80 80
      * This is useful if the secondary table is already included in the SQL, but the primary table is not yet.
81
+     * @param string $secondary_table_alias_with_model_chain_prefix
81 82
      * @return string
82 83
      */
83 84
     public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix)
Please login to merge, or discard this patch.
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -7,118 +7,118 @@
 block discarded – undo
7 7
  */
8 8
 class EE_Secondary_Table extends EE_Table_Base
9 9
 {
10
-    protected $_extra_join_conditions;
10
+	protected $_extra_join_conditions;
11 11
 
12
-    /**
13
-     *
14
-     * @global type $wpdb
15
-     * @param string $table_name with or without wpdb prefix
16
-     * @param string $pk_column name of primary key column on THIS table
17
-     * @param string $fk_column the name of the COLUMN that is a foreign key to the primary table's primary key
18
-     * @param string $extra_join_conditions string for additional SQL to add onto the join statement's ON condition
19
-     * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install,
20
-     *                  or whether each site on a multisite install has a copy of this table
21
-     */
22
-    public function __construct($table_name, $pk_column, $fk_column = null, $extra_join_conditions = null, $global = false)
23
-    {
24
-        $this->_fk_on_table = $fk_column;
25
-        $this->_extra_join_conditions = $extra_join_conditions;
26
-        parent::__construct($table_name, $pk_column, $global);
27
-    }
28
-    public function get_fk_on_table()
29
-    {
30
-        return $this->_fk_on_table;
31
-    }
32
-    public function _construct_finalize_set_table_to_join_with(EE_Table_Base $table)
33
-    {
34
-        $this->_table_to_join_with = $table;
35
-    }
36
-    /**
37
-     *
38
-     * @return string of sql like "Event.post_type = 'event'", which gets added to
39
-     * the end of the join statement with the primary table
40
-     */
41
-    public function get_extra_join_conditions()
42
-    {
43
-        return $this->_extra_join_conditions;
44
-    }
45
-    /**
46
-     *
47
-     * @return EE_Primary_Table
48
-     */
49
-    public function get_table_to_join_with()
50
-    {
51
-        return $this->_table_to_join_with;
52
-    }
53
-    /**
54
-     * creates join statement FROM primary table
55
-     * gets SQL like "LEFT JOIN table_name AS table_alias ON other_table_alias.pk = table_alias.fk
56
-     *
57
-     * @param string $table allows us to set special conditions on the $table_name portion of the join query (i.e. doing a subquery)
58
-     * @return string of SQL
59
-     */
60
-    public function get_join_sql($primary_table_alias_with_model_chain_prefix)
61
-    {
12
+	/**
13
+	 *
14
+	 * @global type $wpdb
15
+	 * @param string $table_name with or without wpdb prefix
16
+	 * @param string $pk_column name of primary key column on THIS table
17
+	 * @param string $fk_column the name of the COLUMN that is a foreign key to the primary table's primary key
18
+	 * @param string $extra_join_conditions string for additional SQL to add onto the join statement's ON condition
19
+	 * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install,
20
+	 *                  or whether each site on a multisite install has a copy of this table
21
+	 */
22
+	public function __construct($table_name, $pk_column, $fk_column = null, $extra_join_conditions = null, $global = false)
23
+	{
24
+		$this->_fk_on_table = $fk_column;
25
+		$this->_extra_join_conditions = $extra_join_conditions;
26
+		parent::__construct($table_name, $pk_column, $global);
27
+	}
28
+	public function get_fk_on_table()
29
+	{
30
+		return $this->_fk_on_table;
31
+	}
32
+	public function _construct_finalize_set_table_to_join_with(EE_Table_Base $table)
33
+	{
34
+		$this->_table_to_join_with = $table;
35
+	}
36
+	/**
37
+	 *
38
+	 * @return string of sql like "Event.post_type = 'event'", which gets added to
39
+	 * the end of the join statement with the primary table
40
+	 */
41
+	public function get_extra_join_conditions()
42
+	{
43
+		return $this->_extra_join_conditions;
44
+	}
45
+	/**
46
+	 *
47
+	 * @return EE_Primary_Table
48
+	 */
49
+	public function get_table_to_join_with()
50
+	{
51
+		return $this->_table_to_join_with;
52
+	}
53
+	/**
54
+	 * creates join statement FROM primary table
55
+	 * gets SQL like "LEFT JOIN table_name AS table_alias ON other_table_alias.pk = table_alias.fk
56
+	 *
57
+	 * @param string $table allows us to set special conditions on the $table_name portion of the join query (i.e. doing a subquery)
58
+	 * @return string of SQL
59
+	 */
60
+	public function get_join_sql($primary_table_alias_with_model_chain_prefix)
61
+	{
62 62
 
63
-        $table_name = $this->get_table_name();
64
-        $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix) . $this->get_table_alias();
65
-        $other_table_pk = $this->get_table_to_join_with()->get_pk_column();
66
-        $fk = $this->get_fk_on_table();
67
-        $join_sql = " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk ";
68
-        if ($this->get_extra_join_conditions()) {
69
-            $join_sql.="AND ".$this->get_extra_join_conditions();
70
-        }
71
-        return $join_sql;
72
-    }
63
+		$table_name = $this->get_table_name();
64
+		$secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix) . $this->get_table_alias();
65
+		$other_table_pk = $this->get_table_to_join_with()->get_pk_column();
66
+		$fk = $this->get_fk_on_table();
67
+		$join_sql = " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk ";
68
+		if ($this->get_extra_join_conditions()) {
69
+			$join_sql.="AND ".$this->get_extra_join_conditions();
70
+		}
71
+		return $join_sql;
72
+	}
73 73
 
74 74
 
75
-    /**
76
-     * Produces join SQL like get_join_sql, except instead of joining the primary table to the
77
-     * secondary table, does the inverse: joins the secondary table to the primary one. (Eg, isntead of
78
-     * " LEFT JOIN secondary_table_table AS Secondary ON ..." like get_join_sql, this function returns
79
-     * " LEFT JOIN primary_table AS Primary ON ...".
80
-     * This is useful if the secondary table is already included in the SQL, but the primary table is not yet.
81
-     * @return string
82
-     */
83
-    public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix)
84
-    {
85
-        $primary_table_name =$this->get_table_to_join_with()->get_table_name();
86
-        $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias();
87
-        $primary_table_pk = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column();
88
-        $fk = $this->get_fk_on_table();
89
-        $join_sql = " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk ";
90
-        if ($this->get_extra_join_conditions()) {
91
-            $join_sql.="AND ".$this->get_extra_join_conditions();
92
-        }
93
-        return $join_sql;
94
-    }
75
+	/**
76
+	 * Produces join SQL like get_join_sql, except instead of joining the primary table to the
77
+	 * secondary table, does the inverse: joins the secondary table to the primary one. (Eg, isntead of
78
+	 * " LEFT JOIN secondary_table_table AS Secondary ON ..." like get_join_sql, this function returns
79
+	 * " LEFT JOIN primary_table AS Primary ON ...".
80
+	 * This is useful if the secondary table is already included in the SQL, but the primary table is not yet.
81
+	 * @return string
82
+	 */
83
+	public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix)
84
+	{
85
+		$primary_table_name =$this->get_table_to_join_with()->get_table_name();
86
+		$primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias();
87
+		$primary_table_pk = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column();
88
+		$fk = $this->get_fk_on_table();
89
+		$join_sql = " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk ";
90
+		if ($this->get_extra_join_conditions()) {
91
+			$join_sql.="AND ".$this->get_extra_join_conditions();
92
+		}
93
+		return $join_sql;
94
+	}
95 95
 
96
-    /**
97
-     * This prepares the join on the other table using a select with a internal limit.
98
-     * @param  mixed (array|string) $limit limit
99
-     * @return string                       SQL to return
100
-     */
101
-    public function get_select_join_limit_join($limit)
102
-    {
103
-        // first get the select
104
-        $select = $this->get_select_join_limit($limit);
105
-        $join_sql = $this->get_join_sql($select);
106
-        return $join_sql;
107
-    }
96
+	/**
97
+	 * This prepares the join on the other table using a select with a internal limit.
98
+	 * @param  mixed (array|string) $limit limit
99
+	 * @return string                       SQL to return
100
+	 */
101
+	public function get_select_join_limit_join($limit)
102
+	{
103
+		// first get the select
104
+		$select = $this->get_select_join_limit($limit);
105
+		$join_sql = $this->get_join_sql($select);
106
+		return $join_sql;
107
+	}
108 108
 
109 109
 
110 110
 
111
-    public function get_fully_qualified_fk_column()
112
-    {
113
-        $table_alias = $this->get_table_alias();
114
-        $fk = $this->get_fk_on_table();
115
-        return $table_alias . '.' . $fk;
116
-    }
111
+	public function get_fully_qualified_fk_column()
112
+	{
113
+		$table_alias = $this->get_table_alias();
114
+		$fk = $this->get_fk_on_table();
115
+		return $table_alias . '.' . $fk;
116
+	}
117 117
 
118
-    public function get_fully_qualified_pk_on_fk_table()
119
-    {
120
-        $table_alias = $this->get_table_to_join_with()->get_table_alias();
121
-        $pk = $this->get_table_to_join_with()->get_pk_column();
122
-        return $table_alias . '.' . $pk;
123
-    }
118
+	public function get_fully_qualified_pk_on_fk_table()
119
+	{
120
+		$table_alias = $this->get_table_to_join_with()->get_table_alias();
121
+		$pk = $this->get_table_to_join_with()->get_pk_column();
122
+		return $table_alias . '.' . $pk;
123
+	}
124 124
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -61,12 +61,12 @@  discard block
 block discarded – undo
61 61
     {
62 62
 
63 63
         $table_name = $this->get_table_name();
64
-        $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix) . $this->get_table_alias();
64
+        $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix).$this->get_table_alias();
65 65
         $other_table_pk = $this->get_table_to_join_with()->get_pk_column();
66 66
         $fk = $this->get_fk_on_table();
67 67
         $join_sql = " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk ";
68 68
         if ($this->get_extra_join_conditions()) {
69
-            $join_sql.="AND ".$this->get_extra_join_conditions();
69
+            $join_sql .= "AND ".$this->get_extra_join_conditions();
70 70
         }
71 71
         return $join_sql;
72 72
     }
@@ -82,13 +82,13 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix)
84 84
     {
85
-        $primary_table_name =$this->get_table_to_join_with()->get_table_name();
86
-        $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias();
87
-        $primary_table_pk = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column();
85
+        $primary_table_name = $this->get_table_to_join_with()->get_table_name();
86
+        $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix).$this->get_table_to_join_with()->get_table_alias();
87
+        $primary_table_pk = $this->get_table_to_join_with()->get_pk_column(); // $this->get_pk_column();
88 88
         $fk = $this->get_fk_on_table();
89 89
         $join_sql = " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk ";
90 90
         if ($this->get_extra_join_conditions()) {
91
-            $join_sql.="AND ".$this->get_extra_join_conditions();
91
+            $join_sql .= "AND ".$this->get_extra_join_conditions();
92 92
         }
93 93
         return $join_sql;
94 94
     }
@@ -112,13 +112,13 @@  discard block
 block discarded – undo
112 112
     {
113 113
         $table_alias = $this->get_table_alias();
114 114
         $fk = $this->get_fk_on_table();
115
-        return $table_alias . '.' . $fk;
115
+        return $table_alias.'.'.$fk;
116 116
     }
117 117
 
118 118
     public function get_fully_qualified_pk_on_fk_table()
119 119
     {
120 120
         $table_alias = $this->get_table_to_join_with()->get_table_alias();
121 121
         $pk = $this->get_table_to_join_with()->get_pk_column();
122
-        return $table_alias . '.' . $pk;
122
+        return $table_alias.'.'.$pk;
123 123
     }
124 124
 }
Please login to merge, or discard this patch.
core/db_models/strategies/EE_CPT_Minimum_Where_Conditions.strategy.php 2 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,6 +18,10 @@  discard block
 block discarded – undo
18 18
 
19 19
     protected $_post_type;
20 20
     protected $_meta_field;
21
+
22
+    /**
23
+     * @param string $post_type
24
+     */
21 25
     public function __construct($post_type, $meta_field_to_chk = '')
22 26
     {
23 27
         $this->_post_type = $post_type;
@@ -40,7 +44,6 @@  discard block
 block discarded – undo
40 44
     }
41 45
     /**
42 46
      * Gets the where default where conditions for a custom post type model
43
-     * @param string $model_relation_path. Eg, from Event to Payment, this should be "Registration.Transaction.Payment"
44 47
      * @return array like EEM_Base::get_all's $query_params's index [0] (where conditions)
45 48
      */
46 49
     protected function _get_default_where_conditions()
Please login to merge, or discard this patch.
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 /**
4 4
  *
5 5
  * Class EE_CPT_Minimum_Where_Conditions
6
-  *
6
+ *
7 7
  * Strategy specifically for adding where conditions specific to CPT models.
8 8
  * But only sets the minimum, so any row of the right type will get used
9 9
  *
@@ -16,39 +16,39 @@  discard block
 block discarded – undo
16 16
 class EE_CPT_Minimum_Where_Conditions extends EE_Default_Where_Conditions
17 17
 {
18 18
 
19
-    protected $_post_type;
20
-    protected $_meta_field;
21
-    public function __construct($post_type, $meta_field_to_chk = '')
22
-    {
23
-        $this->_post_type = $post_type;
24
-        $this->_meta_field = $meta_field_to_chk;
25
-    }
26
-    /**
27
-     * Gets the field with the specified column. Note, this function might not work
28
-     * properly if two fields refer to columns with the same name on different tables
29
-     * @param string $column column name
30
-     * @return EE_Model_Field_Base
31
-     */
32
-    protected function _get_field_on_column($column)
33
-    {
34
-        $all_fields = $this->_model->field_settings(true);
35
-        foreach ($all_fields as $field_name => $field_obj) {
36
-            if ($column == $field_obj->get_table_column()) {
37
-                return $field_obj;
38
-            }
39
-        }
40
-    }
41
-    /**
42
-     * Gets the where default where conditions for a custom post type model
43
-     * @param string $model_relation_path. Eg, from Event to Payment, this should be "Registration.Transaction.Payment"
44
-     * @return array like EEM_Base::get_all's $query_params's index [0] (where conditions)
45
-     */
46
-    protected function _get_default_where_conditions()
47
-    {
48
-        // find post_type field
49
-        $post_type_field = $this->_get_field_on_column('post_type');
50
-        return array(
51
-            $post_type_field->get_name() => $this->_post_type
52
-        );
53
-    }
19
+	protected $_post_type;
20
+	protected $_meta_field;
21
+	public function __construct($post_type, $meta_field_to_chk = '')
22
+	{
23
+		$this->_post_type = $post_type;
24
+		$this->_meta_field = $meta_field_to_chk;
25
+	}
26
+	/**
27
+	 * Gets the field with the specified column. Note, this function might not work
28
+	 * properly if two fields refer to columns with the same name on different tables
29
+	 * @param string $column column name
30
+	 * @return EE_Model_Field_Base
31
+	 */
32
+	protected function _get_field_on_column($column)
33
+	{
34
+		$all_fields = $this->_model->field_settings(true);
35
+		foreach ($all_fields as $field_name => $field_obj) {
36
+			if ($column == $field_obj->get_table_column()) {
37
+				return $field_obj;
38
+			}
39
+		}
40
+	}
41
+	/**
42
+	 * Gets the where default where conditions for a custom post type model
43
+	 * @param string $model_relation_path. Eg, from Event to Payment, this should be "Registration.Transaction.Payment"
44
+	 * @return array like EEM_Base::get_all's $query_params's index [0] (where conditions)
45
+	 */
46
+	protected function _get_default_where_conditions()
47
+	{
48
+		// find post_type field
49
+		$post_type_field = $this->_get_field_on_column('post_type');
50
+		return array(
51
+			$post_type_field->get_name() => $this->_post_type
52
+		);
53
+	}
54 54
 }
Please login to merge, or discard this patch.
core/db_models/strategies/EE_CPT_Where_Conditions.strategy.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,6 @@
 block discarded – undo
16 16
 {
17 17
     /**
18 18
      * Gets the where default where conditions for a custom post type model
19
-     * @param string $model_relation_path. Eg, from Event to Payment, this should be "Registration.Transaction.Payment"
20 19
      * @return array like EEM_Base::get_all's $query_params's index [0] (where conditions)
21 20
      */
22 21
     protected function _get_default_where_conditions()
Please login to merge, or discard this patch.
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 /**
4 4
  *
5 5
  * Class EE_Default_Where_Conditions
6
-  *
6
+ *
7 7
  * Strategy specifically for adding where conditions specific to CPT models.
8 8
  *
9 9
  * @package         Event Espresso
@@ -14,19 +14,19 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class EE_CPT_Where_Conditions extends EE_CPT_Minimum_Where_Conditions
16 16
 {
17
-    /**
18
-     * Gets the where default where conditions for a custom post type model
19
-     * @param string $model_relation_path. Eg, from Event to Payment, this should be "Registration.Transaction.Payment"
20
-     * @return array like EEM_Base::get_all's $query_params's index [0] (where conditions)
21
-     */
22
-    protected function _get_default_where_conditions()
23
-    {
24
-        $status_field = $this->_get_field_on_column('post_status');
25
-        return array_merge(
26
-            parent::_get_default_where_conditions(),
27
-            array(
28
-                $status_field->get_name() => array('NOT IN',array('auto-draft','trash') )
29
-            )
30
-        );
31
-    }
17
+	/**
18
+	 * Gets the where default where conditions for a custom post type model
19
+	 * @param string $model_relation_path. Eg, from Event to Payment, this should be "Registration.Transaction.Payment"
20
+	 * @return array like EEM_Base::get_all's $query_params's index [0] (where conditions)
21
+	 */
22
+	protected function _get_default_where_conditions()
23
+	{
24
+		$status_field = $this->_get_field_on_column('post_status');
25
+		return array_merge(
26
+			parent::_get_default_where_conditions(),
27
+			array(
28
+				$status_field->get_name() => array('NOT IN',array('auto-draft','trash') )
29
+			)
30
+		);
31
+	}
32 32
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
         return array_merge(
26 26
             parent::_get_default_where_conditions(),
27 27
             array(
28
-                $status_field->get_name() => array('NOT IN',array('auto-draft','trash') )
28
+                $status_field->get_name() => array('NOT IN', array('auto-draft', 'trash'))
29 29
             )
30 30
         );
31 31
     }
Please login to merge, or discard this patch.