Completed
Branch BUG-10381-asset-loading (154302)
by
unknown
40:06 queued 28:16
created
form_sections/strategies/display/EE_Number_Input_Display_Strategy.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -14,56 +14,56 @@
 block discarded – undo
14 14
 class EE_Number_Input_Display_Strategy extends EE_Display_Strategy_Base
15 15
 {
16 16
 
17
-    /**
18
-     * minimum value for number field
19
-     *
20
-     * @var int|null $min
21
-     */
22
-    protected $min;
17
+	/**
18
+	 * minimum value for number field
19
+	 *
20
+	 * @var int|null $min
21
+	 */
22
+	protected $min;
23 23
 
24
-    /**
25
-     * maximum value for number field
26
-     *
27
-     * @var int|null $max
28
-     */
29
-    protected $max;
24
+	/**
25
+	 * maximum value for number field
26
+	 *
27
+	 * @var int|null $max
28
+	 */
29
+	protected $max;
30 30
 
31 31
 
32 32
 
33
-    /**
34
-     * EE_Number_Input_Display_Strategy constructor.
35
-     *
36
-     * @param int $min
37
-     * @param int $max
38
-     */
39
-    public function __construct($min = null, $max = null)
40
-    {
41
-        $this->min = $min;
42
-        $this->max = $max;
43
-    }
33
+	/**
34
+	 * EE_Number_Input_Display_Strategy constructor.
35
+	 *
36
+	 * @param int $min
37
+	 * @param int $max
38
+	 */
39
+	public function __construct($min = null, $max = null)
40
+	{
41
+		$this->min = $min;
42
+		$this->max = $max;
43
+	}
44 44
 
45 45
 
46 46
 
47
-    /**
48
-     * @return string of html to display the field
49
-     */
50
-    public function display()
51
-    {
52
-        $input = $this->_opening_tag('input');
53
-        $input .= $this->_attributes_string(
54
-            array_merge(
55
-                $this->_standard_attributes_array(),
56
-                array(
57
-                    'type' => 'number',
58
-                    'min'  => $this->min,
59
-                    'max'  => $this->max,
60
-                    'value' => $this->_input->raw_value_in_form()
61
-                )
62
-            )
63
-        );
64
-        $input .= $this->_close_tag();
65
-        return $input;
66
-    }
47
+	/**
48
+	 * @return string of html to display the field
49
+	 */
50
+	public function display()
51
+	{
52
+		$input = $this->_opening_tag('input');
53
+		$input .= $this->_attributes_string(
54
+			array_merge(
55
+				$this->_standard_attributes_array(),
56
+				array(
57
+					'type' => 'number',
58
+					'min'  => $this->min,
59
+					'max'  => $this->max,
60
+					'value' => $this->_input->raw_value_in_form()
61
+				)
62
+			)
63
+		);
64
+		$input .= $this->_close_tag();
65
+		return $input;
66
+	}
67 67
 
68 68
 }
69 69
 // End of file EE_Number_Input_Display_Strategy.php
Please login to merge, or discard this patch.
form_sections/strategies/normalization/EE_Int_Normalization.strategy.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@
 block discarded – undo
17 17
 
18 18
     /**
19 19
      * @param string $value_to_normalize
20
-     * @return int|mixed|string
20
+     * @return null|integer
21 21
      * @throws \EE_Validation_Error
22 22
      */
23 23
     public function normalize($value_to_normalize)
Please login to merge, or discard this patch.
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -15,89 +15,89 @@  discard block
 block discarded – undo
15 15
 class EE_Int_Normalization extends EE_Normalization_Strategy_Base
16 16
 {
17 17
 
18
-    /*
18
+	/*
19 19
      * regex pattern that matches for the following:
20 20
      *      * optional negative sign
21 21
      *      * one or more digits
22 22
      */
23
-    const REGEX = '/^(-?)(\d+)(?:\.0+)?$/';
23
+	const REGEX = '/^(-?)(\d+)(?:\.0+)?$/';
24 24
 
25 25
 
26
-    /**
27
-     * @param string $value_to_normalize
28
-     * @return int|mixed|string
29
-     * @throws \EE_Validation_Error
30
-     */
31
-    public function normalize($value_to_normalize)
32
-    {
33
-        if ($value_to_normalize === null) {
34
-            return null;
35
-        }
36
-        if (is_int($value_to_normalize) || is_float($value_to_normalize)) {
37
-            return (int)$value_to_normalize;
38
-        }
39
-        if (! is_string($value_to_normalize)) {
40
-            throw new EE_Validation_Error(
41
-                sprintf(
42
-                    __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'),
43
-                    print_r($value_to_normalize, true),
44
-                    gettype($value_to_normalize)
45
-                )
46
-            );
47
-        }
48
-        $value_to_normalize = filter_var(
49
-            $value_to_normalize,
50
-            FILTER_SANITIZE_NUMBER_FLOAT,
51
-            FILTER_FLAG_ALLOW_FRACTION
52
-        );
53
-        if ($value_to_normalize === '') {
54
-            return null;
55
-        }
56
-        $matches = array();
57
-        if (preg_match(EE_Int_Normalization::REGEX, $value_to_normalize, $matches)) {
58
-            if (count($matches) === 3) {
59
-                // if first match is the negative sign,
60
-                // then the number needs to be multiplied by -1 to remain negative
61
-                return $matches[1] === '-'
62
-                    ? (int)$matches[2] * -1
63
-                    : (int)$matches[2];
64
-            }
65
-        }
66
-        //find if this input has a int validation strategy
67
-        //in which case, use its message
68
-        $validation_error_message = null;
69
-        foreach ($this->_input->get_validation_strategies() as $validation_strategy) {
70
-            if ($validation_strategy instanceof EE_Int_Validation_Strategy) {
71
-                $validation_error_message = $validation_strategy->get_validation_error_message();
72
-            }
73
-        }
74
-        //this really shouldn't ever happen because fields with a int normalization strategy
75
-        //should also have a int validation strategy, but in case it doesn't use the default
76
-        if (! $validation_error_message) {
77
-            $default_validation_strategy = new EE_Int_Validation_Strategy();
78
-            $validation_error_message = $default_validation_strategy->get_validation_error_message();
79
-        }
80
-        throw new EE_Validation_Error($validation_error_message, 'numeric_only');
81
-    }
26
+	/**
27
+	 * @param string $value_to_normalize
28
+	 * @return int|mixed|string
29
+	 * @throws \EE_Validation_Error
30
+	 */
31
+	public function normalize($value_to_normalize)
32
+	{
33
+		if ($value_to_normalize === null) {
34
+			return null;
35
+		}
36
+		if (is_int($value_to_normalize) || is_float($value_to_normalize)) {
37
+			return (int)$value_to_normalize;
38
+		}
39
+		if (! is_string($value_to_normalize)) {
40
+			throw new EE_Validation_Error(
41
+				sprintf(
42
+					__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'),
43
+					print_r($value_to_normalize, true),
44
+					gettype($value_to_normalize)
45
+				)
46
+			);
47
+		}
48
+		$value_to_normalize = filter_var(
49
+			$value_to_normalize,
50
+			FILTER_SANITIZE_NUMBER_FLOAT,
51
+			FILTER_FLAG_ALLOW_FRACTION
52
+		);
53
+		if ($value_to_normalize === '') {
54
+			return null;
55
+		}
56
+		$matches = array();
57
+		if (preg_match(EE_Int_Normalization::REGEX, $value_to_normalize, $matches)) {
58
+			if (count($matches) === 3) {
59
+				// if first match is the negative sign,
60
+				// then the number needs to be multiplied by -1 to remain negative
61
+				return $matches[1] === '-'
62
+					? (int)$matches[2] * -1
63
+					: (int)$matches[2];
64
+			}
65
+		}
66
+		//find if this input has a int validation strategy
67
+		//in which case, use its message
68
+		$validation_error_message = null;
69
+		foreach ($this->_input->get_validation_strategies() as $validation_strategy) {
70
+			if ($validation_strategy instanceof EE_Int_Validation_Strategy) {
71
+				$validation_error_message = $validation_strategy->get_validation_error_message();
72
+			}
73
+		}
74
+		//this really shouldn't ever happen because fields with a int normalization strategy
75
+		//should also have a int validation strategy, but in case it doesn't use the default
76
+		if (! $validation_error_message) {
77
+			$default_validation_strategy = new EE_Int_Validation_Strategy();
78
+			$validation_error_message = $default_validation_strategy->get_validation_error_message();
79
+		}
80
+		throw new EE_Validation_Error($validation_error_message, 'numeric_only');
81
+	}
82 82
 
83 83
 
84 84
 
85
-    /**
86
-     * Converts the int into a string for use in teh html form
87
-     *
88
-     * @param int $normalized_value
89
-     * @return string
90
-     */
91
-    public function unnormalize($normalized_value)
92
-    {
93
-        if ($normalized_value === null || $normalized_value === '') {
94
-            return '';
95
-        }
96
-        if (empty($normalized_value)) {
97
-            return '0';
98
-        }
99
-        return "$normalized_value";
100
-    }
85
+	/**
86
+	 * Converts the int into a string for use in teh html form
87
+	 *
88
+	 * @param int $normalized_value
89
+	 * @return string
90
+	 */
91
+	public function unnormalize($normalized_value)
92
+	{
93
+		if ($normalized_value === null || $normalized_value === '') {
94
+			return '';
95
+		}
96
+		if (empty($normalized_value)) {
97
+			return '0';
98
+		}
99
+		return "$normalized_value";
100
+	}
101 101
 }
102 102
 
103 103
 // End of file EE_Int_Normalization.strategy.php
104 104
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 
@@ -34,9 +34,9 @@  discard block
 block discarded – undo
34 34
             return null;
35 35
         }
36 36
         if (is_int($value_to_normalize) || is_float($value_to_normalize)) {
37
-            return (int)$value_to_normalize;
37
+            return (int) $value_to_normalize;
38 38
         }
39
-        if (! is_string($value_to_normalize)) {
39
+        if ( ! is_string($value_to_normalize)) {
40 40
             throw new EE_Validation_Error(
41 41
                 sprintf(
42 42
                     __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'),
@@ -59,8 +59,8 @@  discard block
 block discarded – undo
59 59
                 // if first match is the negative sign,
60 60
                 // then the number needs to be multiplied by -1 to remain negative
61 61
                 return $matches[1] === '-'
62
-                    ? (int)$matches[2] * -1
63
-                    : (int)$matches[2];
62
+                    ? (int) $matches[2] * -1
63
+                    : (int) $matches[2];
64 64
             }
65 65
         }
66 66
         //find if this input has a int validation strategy
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
         }
74 74
         //this really shouldn't ever happen because fields with a int normalization strategy
75 75
         //should also have a int validation strategy, but in case it doesn't use the default
76
-        if (! $validation_error_message) {
76
+        if ( ! $validation_error_message) {
77 77
             $default_validation_strategy = new EE_Int_Validation_Strategy();
78 78
             $validation_error_message = $default_validation_strategy->get_validation_error_message();
79 79
         }
Please login to merge, or discard this patch.
form_sections/strategies/validation/EE_Int_Validation_Strategy.strategy.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -33,14 +33,14 @@
 block discarded – undo
33 33
 	 * @return array
34 34
 	 */
35 35
 	function get_jquery_validation_rule_array(){
36
-        return array(
37
-            'number'=>true,
38
-            'step' => 1,
39
-            'messages' => array(
40
-                'number' => $this->get_validation_error_message(),
41
-                'step' => $this->get_validation_error_message()
42
-            )
43
-        );
36
+		return array(
37
+			'number'=>true,
38
+			'step' => 1,
39
+			'messages' => array(
40
+				'number' => $this->get_validation_error_message(),
41
+				'step' => $this->get_validation_error_message()
42
+			)
43
+		);
44 44
 	}
45 45
 }
46 46
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -6,16 +6,16 @@  discard block
 block discarded – undo
6 6
  * @subpackage	Expression package is undefined on line 19, column 19 in Templates/Scripting/PHPClass.php.
7 7
  * @author				Mike Nelson
8 8
  */
9
-class EE_Int_Validation_Strategy extends EE_Validation_Strategy_Base{
9
+class EE_Int_Validation_Strategy extends EE_Validation_Strategy_Base {
10 10
 
11 11
 	/**
12 12
 	 * @param null $validation_error_message
13 13
 	 */
14
-	public function __construct( $validation_error_message = NULL ) {
15
-		if( ! $validation_error_message ){
14
+	public function __construct($validation_error_message = NULL) {
15
+		if ( ! $validation_error_message) {
16 16
 			$validation_error_message = __("Only digits are allowed.", "event_espresso");
17 17
 		}
18
-		parent::__construct( $validation_error_message );
18
+		parent::__construct($validation_error_message);
19 19
 	}
20 20
 
21 21
 
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	/**
33 33
 	 * @return array
34 34
 	 */
35
-	function get_jquery_validation_rule_array(){
35
+	function get_jquery_validation_rule_array() {
36 36
         return array(
37 37
             'number'=>true,
38 38
             'step' => 1,
Please login to merge, or discard this patch.
core/helpers/EEH_Money.helper.php 2 patches
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -8,62 +8,62 @@  discard block
 block discarded – undo
8 8
  */
9 9
 if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
10 10
  /**
11
- *
12
- * Money helper class.
13
- * This class has helper methods that help with money related conversions and calculations.
14
- *
15
- * @since %VER%
16
- *
17
- * @package		Event Espresso
18
- * @subpackage	helpers
19
- * @author		Darren Ethier
20
- *
21
- * ------------------------------------------------------------------------
22
- */
11
+  *
12
+  * Money helper class.
13
+  * This class has helper methods that help with money related conversions and calculations.
14
+  *
15
+  * @since %VER%
16
+  *
17
+  * @package		Event Espresso
18
+  * @subpackage	helpers
19
+  * @author		Darren Ethier
20
+  *
21
+  * ------------------------------------------------------------------------
22
+  */
23 23
 class EEH_Money extends EEH_Base  {
24 24
 
25 25
 
26
-    /**
27
-     * This removes all localized money formatting from the incoming value
28
-     *
29
-     * @param int|float|string $money_value
30
-     * @param string           $CNT_ISO
31
-     * @return float
32
-     * @throws EE_Error
33
-     */
26
+	/**
27
+	 * This removes all localized money formatting from the incoming value
28
+	 *
29
+	 * @param int|float|string $money_value
30
+	 * @param string           $CNT_ISO
31
+	 * @return float
32
+	 * @throws EE_Error
33
+	 */
34 34
 	public static function strip_localized_money_formatting($money_value, $CNT_ISO = '') {
35
-        $currency_config = EEH_Money::get_currency_config($CNT_ISO);
36
-        $money_value = str_replace(
37
-		    array(
38
-                $currency_config->thsnds,
39
-                $currency_config->dec_mrk,
40
-            ),
41
-            array(
42
-                '', // remove thousands separator
43
-                '.', // convert decimal mark to what PHP expects
44
-            ),
45
-            $money_value
46
-        );
47
-        $money_value = filter_var(
48
-            $money_value,
49
-            FILTER_SANITIZE_NUMBER_FLOAT,
50
-            FILTER_FLAG_ALLOW_FRACTION
51
-        );
52
-        return $money_value;
53
-    }
54
-
55
-
56
-
57
-    /**
58
-     * This converts an incoming localized money value into a standard float item (to three decimal places)
59
-     *
60
-     * @param int|string $money_value
61
-     * @return float
62
-     * @throws EE_Error
63
-     */
35
+		$currency_config = EEH_Money::get_currency_config($CNT_ISO);
36
+		$money_value = str_replace(
37
+			array(
38
+				$currency_config->thsnds,
39
+				$currency_config->dec_mrk,
40
+			),
41
+			array(
42
+				'', // remove thousands separator
43
+				'.', // convert decimal mark to what PHP expects
44
+			),
45
+			$money_value
46
+		);
47
+		$money_value = filter_var(
48
+			$money_value,
49
+			FILTER_SANITIZE_NUMBER_FLOAT,
50
+			FILTER_FLAG_ALLOW_FRACTION
51
+		);
52
+		return $money_value;
53
+	}
54
+
55
+
56
+
57
+	/**
58
+	 * This converts an incoming localized money value into a standard float item (to three decimal places)
59
+	 *
60
+	 * @param int|string $money_value
61
+	 * @return float
62
+	 * @throws EE_Error
63
+	 */
64 64
 	public static function convert_to_float_from_localized_money($money_value ) {
65 65
 		//float it! and round to three decimal places
66
-        return round ( (float) EEH_Money::strip_localized_money_formatting($money_value), 3 );
66
+		return round ( (float) EEH_Money::strip_localized_money_formatting($money_value), 3 );
67 67
 	}
68 68
 
69 69
 
@@ -151,19 +151,19 @@  discard block
 block discarded – undo
151 151
 
152 152
 
153 153
 
154
-    /**
155
-     * This returns a localized format string suitable for jQplot.
156
-     *
157
-     * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
158
-     *                         Otherwise will use currency settings for current active country on site.
159
-     * @return string
160
-     * @throws EE_Error
161
-     */
154
+	/**
155
+	 * This returns a localized format string suitable for jQplot.
156
+	 *
157
+	 * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
158
+	 *                         Otherwise will use currency settings for current active country on site.
159
+	 * @return string
160
+	 * @throws EE_Error
161
+	 */
162 162
 	public static function get_format_for_jqplot( $CNT_ISO = '') {
163 163
 		//default format
164 164
 		$format = 'f';
165 165
 		$currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO);
166
-        //first get the decimal place and number of places
166
+		//first get the decimal place and number of places
167 167
 		$format = "%'." . $currency_config->dec_plc . $format;
168 168
 		//currency symbol on right side.
169 169
 		$format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign;
@@ -172,16 +172,16 @@  discard block
 block discarded – undo
172 172
 
173 173
 
174 174
 
175
-    /**
176
-     * This returns a localized format string suitable for usage with the Google Charts API format param.
177
-     *
178
-     * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
179
-     *                         Otherwise will use currency settings for current active country on site.
180
-     *                         Note: GoogleCharts uses ICU pattern set
181
-     *                         (@see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details)
182
-     * @return string
183
-     * @throws EE_Error
184
-     */
175
+	/**
176
+	 * This returns a localized format string suitable for usage with the Google Charts API format param.
177
+	 *
178
+	 * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
179
+	 *                         Otherwise will use currency settings for current active country on site.
180
+	 *                         Note: GoogleCharts uses ICU pattern set
181
+	 *                         (@see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details)
182
+	 * @return string
183
+	 * @throws EE_Error
184
+	 */
185 185
 	public static function get_format_for_google_charts( $CNT_ISO = '' ) {
186 186
 		$currency_config = EEH_Money::get_currency_config($CNT_ISO);
187 187
 		$decimal_places_placeholder = str_pad( '', $currency_config->dec_plc, '0' );
@@ -208,24 +208,24 @@  discard block
 block discarded – undo
208 208
 
209 209
 
210 210
 
211
-    /**
212
-     * @param string $CNT_ISO
213
-     * @return EE_Currency_Config|null
214
-     * @throws EE_Error
215
-     */
216
-    public static function get_currency_config($CNT_ISO = '')
217
-    {
218
-        //if CNT_ISO passed lets try to get currency settings for it.
219
-        $currency_config = $CNT_ISO !== ''
220
-            ? new EE_Currency_Config($CNT_ISO)
221
-            : null;
222
-        //default currency settings for site if not set
223
-        if (! $currency_config instanceof EE_Currency_Config) {
224
-            $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
225
-                ? EE_Registry::instance()->CFG->currency
226
-                : new EE_Currency_Config();
227
-        }
228
-        return $currency_config;
229
-    }
211
+	/**
212
+	 * @param string $CNT_ISO
213
+	 * @return EE_Currency_Config|null
214
+	 * @throws EE_Error
215
+	 */
216
+	public static function get_currency_config($CNT_ISO = '')
217
+	{
218
+		//if CNT_ISO passed lets try to get currency settings for it.
219
+		$currency_config = $CNT_ISO !== ''
220
+			? new EE_Currency_Config($CNT_ISO)
221
+			: null;
222
+		//default currency settings for site if not set
223
+		if (! $currency_config instanceof EE_Currency_Config) {
224
+			$currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
225
+				? EE_Registry::instance()->CFG->currency
226
+				: new EE_Currency_Config();
227
+		}
228
+		return $currency_config;
229
+	}
230 230
 
231 231
 } //end class EEH_Money
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  *
21 21
  * ------------------------------------------------------------------------
22 22
  */
23
-class EEH_Money extends EEH_Base  {
23
+class EEH_Money extends EEH_Base {
24 24
 
25 25
 
26 26
     /**
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
      * @return float
62 62
      * @throws EE_Error
63 63
      */
64
-	public static function convert_to_float_from_localized_money($money_value ) {
64
+	public static function convert_to_float_from_localized_money($money_value) {
65 65
 		//float it! and round to three decimal places
66
-        return round ( (float) EEH_Money::strip_localized_money_formatting($money_value), 3 );
66
+        return round((float) EEH_Money::strip_localized_money_formatting($money_value), 3);
67 67
 	}
68 68
 
69 69
 
@@ -82,12 +82,12 @@  discard block
 block discarded – undo
82 82
 	 * @throws EE_Error
83 83
 	 */
84 84
 
85
-	public static function compare_floats( $float1, $float2, $operator='=' ) {
85
+	public static function compare_floats($float1, $float2, $operator = '=') {
86 86
 		// Check numbers to 5 digits of precision
87 87
 		$epsilon = 0.00001;
88 88
 
89
-		$float1 = (float)$float1;
90
-		$float2 = (float)$float2;
89
+		$float1 = (float) $float1;
90
+		$float2 = (float) $float2;
91 91
 
92 92
 		switch ($operator) {
93 93
 			// equal
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 				}
144 144
 				break;
145 145
 			default:
146
-				throw new EE_Error(__( "Unknown operator '" . $operator . "' in EEH_Money::compare_floats()", 'event_espresso' ) );
146
+				throw new EE_Error(__("Unknown operator '".$operator."' in EEH_Money::compare_floats()", 'event_espresso'));
147 147
 		}
148 148
 
149 149
 		return false;
@@ -159,14 +159,14 @@  discard block
 block discarded – undo
159 159
      * @return string
160 160
      * @throws EE_Error
161 161
      */
162
-	public static function get_format_for_jqplot( $CNT_ISO = '') {
162
+	public static function get_format_for_jqplot($CNT_ISO = '') {
163 163
 		//default format
164 164
 		$format = 'f';
165 165
 		$currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO);
166 166
         //first get the decimal place and number of places
167
-		$format = "%'." . $currency_config->dec_plc . $format;
167
+		$format = "%'.".$currency_config->dec_plc.$format;
168 168
 		//currency symbol on right side.
169
-		$format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign;
169
+		$format = $currency_config->sign_b4 ? $currency_config->sign.$format : $format.$currency_config->sign;
170 170
 		return $format;
171 171
 	}
172 172
 
@@ -182,20 +182,20 @@  discard block
 block discarded – undo
182 182
      * @return string
183 183
      * @throws EE_Error
184 184
      */
185
-	public static function get_format_for_google_charts( $CNT_ISO = '' ) {
185
+	public static function get_format_for_google_charts($CNT_ISO = '') {
186 186
 		$currency_config = EEH_Money::get_currency_config($CNT_ISO);
187
-		$decimal_places_placeholder = str_pad( '', $currency_config->dec_plc, '0' );
187
+		$decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0');
188 188
 		//first get the decimal place and number of places
189
-		$format = '#,##0.' . $decimal_places_placeholder;
189
+		$format = '#,##0.'.$decimal_places_placeholder;
190 190
 
191 191
 		//currency symbol on right side.
192
-		$format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign;
192
+		$format = $currency_config->sign_b4 ? $currency_config->sign.$format : $format.$currency_config->sign;
193 193
 		$formatterObject = array(
194 194
 			'decimalSymbol' => $currency_config->dec_mrk,
195 195
 			'groupingSymbol' => $currency_config->thsnds,
196 196
 			'fractionDigits' => $currency_config->dec_plc,
197 197
 		);
198
-		if ( $currency_config->sign_b4 ) {
198
+		if ($currency_config->sign_b4) {
199 199
 			$formatterObject['prefix'] = $currency_config->sign;
200 200
 		} else {
201 201
 			$formatterObject['suffix'] = $currency_config->sign;
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
             ? new EE_Currency_Config($CNT_ISO)
221 221
             : null;
222 222
         //default currency settings for site if not set
223
-        if (! $currency_config instanceof EE_Currency_Config) {
223
+        if ( ! $currency_config instanceof EE_Currency_Config) {
224 224
             $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
225 225
                 ? EE_Registry::instance()->CFG->currency
226 226
                 : new EE_Currency_Config();
Please login to merge, or discard this patch.
form_sections/strategies/normalization/EE_Float_Normalization.strategy.php 2 patches
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -15,85 +15,85 @@  discard block
 block discarded – undo
15 15
 class EE_Float_Normalization extends EE_Normalization_Strategy_Base
16 16
 {
17 17
 
18
-    /*
18
+	/*
19 19
      * regex pattern that matches for the following:
20 20
      *      * optional negative sign
21 21
      *      * one or more digits or decimals
22 22
      */
23
-    const REGEX = '/^(-?)([\d.]+)$/';
23
+	const REGEX = '/^(-?)([\d.]+)$/';
24 24
 
25 25
 
26
-    /**
27
-     * @param string $value_to_normalize
28
-     * @return float
29
-     * @throws \EE_Validation_Error
30
-     */
31
-    public function normalize($value_to_normalize)
32
-    {
33
-        if ($value_to_normalize === null) {
34
-            return null;
35
-        }
36
-        if (is_float($value_to_normalize) || is_int($value_to_normalize)) {
37
-            return (float)$value_to_normalize;
38
-        }
39
-        if (! is_string($value_to_normalize)) {
40
-            throw new EE_Validation_Error(
41
-                sprintf(
42
-                    __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'),
43
-                    print_r($value_to_normalize, true),
44
-                    gettype($value_to_normalize)
45
-                )
46
-            );
47
-        }
48
-        $normalized_value = filter_var(
49
-            $value_to_normalize,
50
-            FILTER_SANITIZE_NUMBER_FLOAT,
51
-            FILTER_FLAG_ALLOW_FRACTION
52
-        );
53
-        if($normalized_value === ''){
54
-            return null;
55
-        }
56
-        if (preg_match(EE_Float_Normalization::REGEX, $normalized_value, $matches)) {
57
-            if (count($matches) === 3) {
58
-                // if first match is the negative sign,
59
-                // then the number needs to be multiplied by -1 to remain negative
60
-                return $matches[1] === '-'
61
-                    ? (float)$matches[2] * -1
62
-                    : (float)$matches[2];
63
-            }
64
-        }
65
-        //find if this input has a float validation strategy
66
-        //in which case, use its message
67
-        $validation_error_message = null;
68
-        foreach ($this->_input->get_validation_strategies() as $validation_strategy) {
69
-            if ($validation_strategy instanceof EE_Float_Validation_Strategy) {
70
-                $validation_error_message = $validation_strategy->get_validation_error_message();
71
-            }
72
-        }
73
-        //this really shouldn't ever happen because fields with a float normalization strategy
74
-        //should also have a float validation strategy, but in case it doesn't use the default
75
-        if (! $validation_error_message) {
76
-            $default_validation_strategy = new EE_Float_Validation_Strategy();
77
-            $validation_error_message = $default_validation_strategy->get_validation_error_message();
78
-        }
79
-        throw new EE_Validation_Error($validation_error_message, 'float_only');
80
-    }
26
+	/**
27
+	 * @param string $value_to_normalize
28
+	 * @return float
29
+	 * @throws \EE_Validation_Error
30
+	 */
31
+	public function normalize($value_to_normalize)
32
+	{
33
+		if ($value_to_normalize === null) {
34
+			return null;
35
+		}
36
+		if (is_float($value_to_normalize) || is_int($value_to_normalize)) {
37
+			return (float)$value_to_normalize;
38
+		}
39
+		if (! is_string($value_to_normalize)) {
40
+			throw new EE_Validation_Error(
41
+				sprintf(
42
+					__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'),
43
+					print_r($value_to_normalize, true),
44
+					gettype($value_to_normalize)
45
+				)
46
+			);
47
+		}
48
+		$normalized_value = filter_var(
49
+			$value_to_normalize,
50
+			FILTER_SANITIZE_NUMBER_FLOAT,
51
+			FILTER_FLAG_ALLOW_FRACTION
52
+		);
53
+		if($normalized_value === ''){
54
+			return null;
55
+		}
56
+		if (preg_match(EE_Float_Normalization::REGEX, $normalized_value, $matches)) {
57
+			if (count($matches) === 3) {
58
+				// if first match is the negative sign,
59
+				// then the number needs to be multiplied by -1 to remain negative
60
+				return $matches[1] === '-'
61
+					? (float)$matches[2] * -1
62
+					: (float)$matches[2];
63
+			}
64
+		}
65
+		//find if this input has a float validation strategy
66
+		//in which case, use its message
67
+		$validation_error_message = null;
68
+		foreach ($this->_input->get_validation_strategies() as $validation_strategy) {
69
+			if ($validation_strategy instanceof EE_Float_Validation_Strategy) {
70
+				$validation_error_message = $validation_strategy->get_validation_error_message();
71
+			}
72
+		}
73
+		//this really shouldn't ever happen because fields with a float normalization strategy
74
+		//should also have a float validation strategy, but in case it doesn't use the default
75
+		if (! $validation_error_message) {
76
+			$default_validation_strategy = new EE_Float_Validation_Strategy();
77
+			$validation_error_message = $default_validation_strategy->get_validation_error_message();
78
+		}
79
+		throw new EE_Validation_Error($validation_error_message, 'float_only');
80
+	}
81 81
 
82 82
 
83 83
 
84
-    /**
85
-     * Converts a float into a string
86
-     *
87
-     * @param float $normalized_value
88
-     * @return string
89
-     */
90
-    public function unnormalize($normalized_value)
91
-    {
92
-        if (empty($normalized_value)) {
93
-            return '0.00';
94
-        }
95
-        return "{$normalized_value}";
96
-    }
84
+	/**
85
+	 * Converts a float into a string
86
+	 *
87
+	 * @param float $normalized_value
88
+	 * @return string
89
+	 */
90
+	public function unnormalize($normalized_value)
91
+	{
92
+		if (empty($normalized_value)) {
93
+			return '0.00';
94
+		}
95
+		return "{$normalized_value}";
96
+	}
97 97
 }
98 98
 
99 99
 // End of file EE_Float_Normalization.strategy.php
100 100
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 
@@ -34,9 +34,9 @@  discard block
 block discarded – undo
34 34
             return null;
35 35
         }
36 36
         if (is_float($value_to_normalize) || is_int($value_to_normalize)) {
37
-            return (float)$value_to_normalize;
37
+            return (float) $value_to_normalize;
38 38
         }
39
-        if (! is_string($value_to_normalize)) {
39
+        if ( ! is_string($value_to_normalize)) {
40 40
             throw new EE_Validation_Error(
41 41
                 sprintf(
42 42
                     __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'),
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
             FILTER_SANITIZE_NUMBER_FLOAT,
51 51
             FILTER_FLAG_ALLOW_FRACTION
52 52
         );
53
-        if($normalized_value === ''){
53
+        if ($normalized_value === '') {
54 54
             return null;
55 55
         }
56 56
         if (preg_match(EE_Float_Normalization::REGEX, $normalized_value, $matches)) {
@@ -58,8 +58,8 @@  discard block
 block discarded – undo
58 58
                 // if first match is the negative sign,
59 59
                 // then the number needs to be multiplied by -1 to remain negative
60 60
                 return $matches[1] === '-'
61
-                    ? (float)$matches[2] * -1
62
-                    : (float)$matches[2];
61
+                    ? (float) $matches[2] * -1
62
+                    : (float) $matches[2];
63 63
             }
64 64
         }
65 65
         //find if this input has a float validation strategy
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
         }
73 73
         //this really shouldn't ever happen because fields with a float normalization strategy
74 74
         //should also have a float validation strategy, but in case it doesn't use the default
75
-        if (! $validation_error_message) {
75
+        if ( ! $validation_error_message) {
76 76
             $default_validation_strategy = new EE_Float_Validation_Strategy();
77 77
             $validation_error_message = $default_validation_strategy->get_validation_error_message();
78 78
         }
Please login to merge, or discard this patch.
core/db_models/EEM_Event.model.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -217,7 +217,7 @@
 block discarded – undo
217 217
 
218 218
     /**
219 219
      * Used to override the default for the additional limit field.
220
-     * @param $additional_limit
220
+     * @param integer $additional_limit
221 221
      */
222 222
     public static function set_default_additional_limit($additional_limit)
223 223
     {
Please login to merge, or discard this patch.
Indentation   +788 added lines, -788 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 require_once(EE_MODELS . 'EEM_CPT_Base.model.php');
5 5
 
@@ -16,793 +16,793 @@  discard block
 block discarded – undo
16 16
 class EEM_Event extends EEM_CPT_Base
17 17
 {
18 18
 
19
-    /**
20
-     * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
21
-     * event
22
-     */
23
-    const sold_out = 'sold_out';
24
-
25
-    /**
26
-     * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
27
-     * date)
28
-     */
29
-    const postponed = 'postponed';
30
-
31
-    /**
32
-     * constant used by status(), indicating that the event will no longer occur
33
-     */
34
-    const cancelled = 'cancelled';
35
-
36
-
37
-    /**
38
-     * @var string
39
-     */
40
-    protected static $_default_reg_status;
41
-
42
-
43
-    /**
44
-     * This is the default for the additional limit field.
45
-     * @var int
46
-     */
47
-    protected static $_default_additional_limit = 10;
48
-
49
-
50
-    /**
51
-     * private instance of the Event object
52
-     *
53
-     * @var EEM_Event
54
-     */
55
-    protected static $_instance;
56
-
57
-
58
-
59
-    /**
60
-     *  This function is a singleton method used to instantiate the EEM_Event object
61
-     *
62
-     * @param string $timezone
63
-     * @return EEM_Event
64
-     * @throws \EE_Error
65
-     */
66
-    public static function instance($timezone = null)
67
-    {
68
-        // check if instance of EEM_Event already exists
69
-        if (! self::$_instance instanceof EEM_Event) {
70
-            // instantiate Espresso_model
71
-            self::$_instance = new self($timezone);
72
-        }
73
-        //we might have a timezone set, let set_timezone decide what to do with it
74
-        self::$_instance->set_timezone($timezone);
75
-        // EEM_Event object
76
-        return self::$_instance;
77
-    }
78
-
79
-
80
-
81
-    /**
82
-     * Adds a relationship to Term_Taxonomy for each CPT_Base
83
-     *
84
-     * @param string $timezone
85
-     * @throws \EE_Error
86
-     */
87
-    protected function __construct($timezone = null)
88
-    {
89
-        EE_Registry::instance()->load_model('Registration');
90
-        $this->singular_item = esc_html__('Event', 'event_espresso');
91
-        $this->plural_item = esc_html__('Events', 'event_espresso');
92
-        // to remove Cancelled events from the frontend, copy the following filter to your functions.php file
93
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
94
-        // to remove Postponed events from the frontend, copy the following filter to your functions.php file
95
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
96
-        // to remove Sold Out events from the frontend, copy the following filter to your functions.php file
97
-        //	add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
98
-        $this->_custom_stati = apply_filters(
99
-            'AFEE__EEM_Event__construct___custom_stati',
100
-            array(
101
-                EEM_Event::cancelled => array(
102
-                    'label'  => esc_html__('Cancelled', 'event_espresso'),
103
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
104
-                ),
105
-                EEM_Event::postponed => array(
106
-                    'label'  => esc_html__('Postponed', 'event_espresso'),
107
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
108
-                ),
109
-                EEM_Event::sold_out  => array(
110
-                    'label'  => esc_html__('Sold Out', 'event_espresso'),
111
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
112
-                ),
113
-            )
114
-        );
115
-        self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment
116
-            : self::$_default_reg_status;
117
-        $this->_tables = array(
118
-            'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
119
-            'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
120
-        );
121
-        $this->_fields = array(
122
-            'Event_CPT'  => array(
123
-                'EVT_ID'         => new EE_Primary_Key_Int_Field('ID',
124
-                    esc_html__('Post ID for Event', 'event_espresso')),
125
-                'EVT_name'       => new EE_Plain_Text_Field('post_title', esc_html__('Event Name', 'event_espresso'),
126
-                    false,
127
-                    ''),
128
-                'EVT_desc'       => new EE_Post_Content_Field('post_content',
129
-                    esc_html__('Event Description', 'event_espresso'),
130
-                    false, ''),
131
-                'EVT_slug'       => new EE_Slug_Field('post_name', esc_html__('Event Slug', 'event_espresso'), false,
132
-                    ''),
133
-                'EVT_created'    => new EE_Datetime_Field('post_date',
134
-                    esc_html__('Date/Time Event Created', 'event_espresso'),
135
-                    false, EE_Datetime_Field::now),
136
-                'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt',
137
-                    esc_html__('Event Short Description', 'event_espresso'), false, ''),
138
-                'EVT_modified'   => new EE_Datetime_Field('post_modified',
139
-                    esc_html__('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now),
140
-                'EVT_wp_user'    => new EE_WP_User_Field('post_author',
141
-                    esc_html__('Event Creator ID', 'event_espresso'),
142
-                    false),
143
-                'parent'         => new EE_Integer_Field('post_parent', esc_html__('Event Parent ID', 'event_espresso'),
144
-                    false,
145
-                    0),
146
-                'EVT_order'      => new EE_Integer_Field('menu_order', esc_html__('Event Menu Order', 'event_espresso'),
147
-                    false,
148
-                    1),
149
-                'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
150
-                // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
151
-                'status'         => new EE_WP_Post_Status_Field('post_status',
152
-                    esc_html__('Event Status', 'event_espresso'),
153
-                    false, 'draft', $this->_custom_stati),
154
-            ),
155
-            'Event_Meta' => array(
156
-                'EVTM_ID'                         => new EE_DB_Only_Float_Field('EVTM_ID',
157
-                    esc_html__('Event Meta Row ID', 'event_espresso'), false),
158
-                'EVT_ID_fk'                       => new EE_DB_Only_Int_Field('EVT_ID',
159
-                    esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), false),
160
-                'EVT_display_desc'                => new EE_Boolean_Field('EVT_display_desc',
161
-                    esc_html__('Display Description Flag', 'event_espresso'), false, 1),
162
-                'EVT_display_ticket_selector'     => new EE_Boolean_Field('EVT_display_ticket_selector',
163
-                    esc_html__('Display Ticket Selector Flag', 'event_espresso'), false, 1),
164
-                'EVT_visible_on'                  => new EE_Datetime_Field('EVT_visible_on',
165
-                    esc_html__('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now),
166
-                'EVT_additional_limit'            => new EE_Integer_Field(
167
-                    'EVT_additional_limit',
168
-                    esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
169
-                    true,
170
-                    self::$_default_additional_limit
171
-                ),
172
-                'EVT_default_registration_status' => new EE_Enum_Text_Field(
173
-                    'EVT_default_registration_status',
174
-                    esc_html__('Default Registration Status on this Event', 'event_espresso'), false,
175
-                    EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array()
176
-                ),
177
-                'EVT_member_only'                 => new EE_Boolean_Field('EVT_member_only',
178
-                    esc_html__('Member-Only Event Flag', 'event_espresso'), false, false),
179
-                'EVT_phone'                       => new EE_Plain_Text_Field('EVT_phone',
180
-                    esc_html__('Event Phone Number', 'event_espresso'), false),
181
-                'EVT_allow_overflow'              => new EE_Boolean_Field('EVT_allow_overflow',
182
-                    esc_html__('Allow Overflow on Event', 'event_espresso'), false, false),
183
-                'EVT_timezone_string'             => new EE_Plain_Text_Field('EVT_timezone_string',
184
-                    esc_html__('Timezone (name) for Event times', 'event_espresso'), false),
185
-                'EVT_external_URL'                => new EE_Plain_Text_Field('EVT_external_URL',
186
-                    esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true),
187
-                'EVT_donations'                   => new EE_Boolean_Field('EVT_donations',
188
-                    esc_html__('Accept Donations?', 'event_espresso'), false, false),
189
-            ),
190
-        );
191
-        $this->_model_relations = array(
192
-            'Registration'           => new EE_Has_Many_Relation(),
193
-            'Datetime'               => new EE_Has_Many_Relation(),
194
-            'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
195
-            'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
196
-            'Term_Relationship'      => new EE_Has_Many_Relation(),
197
-            'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
198
-            'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
199
-            'Attendee'               => new EE_HABTM_Relation('Registration'),
200
-            'WP_User'                => new EE_Belongs_To_Relation(),
201
-        );
202
-        //this model is generally available for reading
203
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
204
-        parent::__construct($timezone);
205
-    }
206
-
207
-
208
-
209
-    /**
210
-     * @param string $default_reg_status
211
-     */
212
-    public static function set_default_reg_status($default_reg_status)
213
-    {
214
-        self::$_default_reg_status = $default_reg_status;
215
-        // if EEM_Event has already been instantiated,
216
-        // then we need to reset the `EVT_default_reg_status` field to use the new default.
217
-        if (self::$_instance instanceof EEM_Event) {
218
-            $default_reg_status = new EE_Enum_Text_Field(
219
-                'EVT_default_registration_status',
220
-                esc_html__('Default Registration Status on this Event', 'event_espresso'),
221
-                false,
222
-                $default_reg_status,
223
-                EEM_Registration::reg_status_array()
224
-            );
225
-            $default_reg_status->_construct_finalize(
226
-                'Event_Meta',
227
-                'EVT_default_registration_status',
228
-                'EEM_Event'
229
-            );
230
-            self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
231
-        }
232
-    }
233
-
234
-
235
-    /**
236
-     * Used to override the default for the additional limit field.
237
-     * @param $additional_limit
238
-     */
239
-    public static function set_default_additional_limit($additional_limit)
240
-    {
241
-        self::$_default_additional_limit = (int) $additional_limit;
242
-        if (self::$_instance instanceof EEM_Event) {
243
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
244
-                'EVT_additional_limit',
245
-                __('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
246
-                true,
247
-                self::$_default_additional_limit
248
-            );
249
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
250
-                'Event_Meta',
251
-                'EVT_additional_limit',
252
-                'EEM_Event'
253
-            );
254
-        }
255
-    }
256
-
257
-
258
-    /**
259
-     * Return what is currently set as the default additional limit for the event.
260
-     * @return int
261
-     */
262
-    public static function get_default_additional_limit()
263
-    {
264
-        return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
265
-    }
266
-
267
-
268
-    /**
269
-     * get_question_groups
270
-     *
271
-     * @return array
272
-     * @throws \EE_Error
273
-     */
274
-    public function get_all_question_groups()
275
-    {
276
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
277
-            array(
278
-                array('QSG_deleted' => false),
279
-                'order_by' => array('QSG_order' => 'ASC'),
280
-            )
281
-        );
282
-    }
283
-
284
-
285
-
286
-    /**
287
-     * get_question_groups
288
-     *
289
-     * @param int $EVT_ID
290
-     * @return array|bool
291
-     * @throws \EE_Error
292
-     */
293
-    public function get_all_event_question_groups($EVT_ID = 0)
294
-    {
295
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
296
-            EE_Error::add_error(
297
-                esc_html__(
298
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
299
-                    'event_espresso'
300
-                ),
301
-                __FILE__, __FUNCTION__, __LINE__
302
-            );
303
-            return false;
304
-        }
305
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
306
-            array(
307
-                array('EVT_ID' => $EVT_ID),
308
-            )
309
-        );
310
-    }
311
-
312
-
313
-
314
-    /**
315
-     * get_question_groups
316
-     *
317
-     * @param int     $EVT_ID
318
-     * @param boolean $for_primary_attendee
319
-     * @return array|bool
320
-     * @throws \EE_Error
321
-     */
322
-    public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
323
-    {
324
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
325
-            EE_Error::add_error(
326
-                esc_html__(
327
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
328
-                    'event_espresso'
329
-                ),
330
-                __FILE__, __FUNCTION__, __LINE__
331
-            );
332
-            return false;
333
-        }
334
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
335
-            array(
336
-                array(
337
-                    'EVT_ID'      => $EVT_ID,
338
-                    'EQG_primary' => $for_primary_attendee,
339
-                ),
340
-            )
341
-        );
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     * get_question_groups
348
-     *
349
-     * @param int             $EVT_ID
350
-     * @param EE_Registration $registration
351
-     * @return array|bool
352
-     * @throws \EE_Error
353
-     */
354
-    public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
355
-    {
356
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
357
-            EE_Error::add_error(
358
-                esc_html__(
359
-                    'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
360
-                    'event_espresso'
361
-                ),
362
-                __FILE__, __FUNCTION__, __LINE__
363
-            );
364
-            return false;
365
-        }
366
-        $where_params = array(
367
-            'Event_Question_Group.EVT_ID'      => $EVT_ID,
368
-            'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false,
369
-            'QSG_deleted'                      => false,
370
-        );
371
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
372
-            array(
373
-                $where_params,
374
-                'order_by' => array('QSG_order' => 'ASC'),
375
-            )
376
-        );
377
-    }
378
-
379
-
380
-
381
-    /**
382
-     * get_question_target_db_column
383
-     *
384
-     * @param string $QSG_IDs csv list of $QSG IDs
385
-     * @return array|bool
386
-     * @throws \EE_Error
387
-     */
388
-    public function get_questions_in_groups($QSG_IDs = '')
389
-    {
390
-        if (empty($QSG_IDs)) {
391
-            EE_Error::add_error(
392
-                esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
393
-                __FILE__, __FUNCTION__, __LINE__
394
-            );
395
-            return false;
396
-        }
397
-        return EE_Registry::instance()->load_model('Question')->get_all(
398
-            array(
399
-                array(
400
-                    'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
401
-                    'QST_deleted'           => false,
402
-                    'QST_admin_only'        => is_admin(),
403
-                ),
404
-                'order_by' => 'QST_order',
405
-            )
406
-        );
407
-    }
408
-
409
-
410
-
411
-    /**
412
-     * get_options_for_question
413
-     *
414
-     * @param string $QST_IDs csv list of $QST IDs
415
-     * @return array|bool
416
-     * @throws \EE_Error
417
-     */
418
-    public function get_options_for_question($QST_IDs)
419
-    {
420
-        if (empty($QST_IDs)) {
421
-            EE_Error::add_error(
422
-                esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
423
-                __FILE__, __FUNCTION__, __LINE__
424
-            );
425
-            return false;
426
-        }
427
-        return EE_Registry::instance()->load_model('Question_Option')->get_all(
428
-            array(
429
-                array(
430
-                    'Question.QST_ID' => array('IN', $QST_IDs),
431
-                    'QSO_deleted'     => false,
432
-                ),
433
-                'order_by' => 'QSO_ID',
434
-            )
435
-        );
436
-    }
437
-
438
-
439
-
440
-
441
-
442
-
443
-
444
-    /**
445
-     * Gets all events that are published
446
-     * and have event start time earlier than now and an event end time later than now
447
-     *
448
-     * @param  array $query_params An array of query params to further filter on
449
-     *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
450
-     * @param bool   $count        whether to return the count or not (default FALSE)
451
-     * @return EE_Event[]|int
452
-     * @throws \EE_Error
453
-     */
454
-    public function get_active_events($query_params, $count = false)
455
-    {
456
-        if (array_key_exists(0, $query_params)) {
457
-            $where_params = $query_params[0];
458
-            unset($query_params[0]);
459
-        } else {
460
-            $where_params = array();
461
-        }
462
-        // if we have count make sure we don't include group by
463
-        if ($count && isset($query_params['group_by'])) {
464
-            unset($query_params['group_by']);
465
-        }
466
-        // let's add specific query_params for active_events
467
-        // keep in mind this will override any sent status in the query AND any date queries.
468
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
469
-        //if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
470
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
471
-            $where_params['Datetime.DTT_EVT_start******'] = array(
472
-                '<',
473
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
474
-            );
475
-        } else {
476
-            $where_params['Datetime.DTT_EVT_start'] = array(
477
-                '<',
478
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
479
-            );
480
-        }
481
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
482
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
483
-                '>',
484
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
485
-            );
486
-        } else {
487
-            $where_params['Datetime.DTT_EVT_end'] = array(
488
-                '>',
489
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
490
-            );
491
-        }
492
-        $query_params[0] = $where_params;
493
-        // don't use $query_params with count()
494
-        // because we don't want to include additional query clauses like "GROUP BY"
495
-        return $count
496
-            ? $this->count(array($where_params), 'EVT_ID', true)
497
-            : $this->get_all($query_params);
498
-    }
499
-
500
-
501
-
502
-    /**
503
-     * get all events that are published and have an event start time later than now
504
-     *
505
-     * @param  array $query_params An array of query params to further filter on
506
-     *                             (Note that status and DTT_EVT_start will be overridden)
507
-     * @param bool   $count        whether to return the count or not (default FALSE)
508
-     * @return EE_Event[]|int
509
-     * @throws \EE_Error
510
-     */
511
-    public function get_upcoming_events($query_params, $count = false)
512
-    {
513
-        if (array_key_exists(0, $query_params)) {
514
-            $where_params = $query_params[0];
515
-            unset($query_params[0]);
516
-        } else {
517
-            $where_params = array();
518
-        }
519
-        // if we have count make sure we don't include group by
520
-        if ($count && isset($query_params['group_by'])) {
521
-            unset($query_params['group_by']);
522
-        }
523
-        // let's add specific query_params for active_events
524
-        // keep in mind this will override any sent status in the query AND any date queries.
525
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
526
-        // if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
527
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
528
-            $where_params['Datetime.DTT_EVT_start*****'] = array(
529
-                '>',
530
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
531
-            );
532
-        } else {
533
-            $where_params['Datetime.DTT_EVT_start'] = array(
534
-                '>',
535
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
536
-            );
537
-        }
538
-        $query_params[0] = $where_params;
539
-        // don't use $query_params with count()
540
-        // because we don't want to include additional query clauses like "GROUP BY"
541
-        return $count
542
-            ? $this->count(array($where_params), 'EVT_ID', true)
543
-            : $this->get_all($query_params);
544
-    }
545
-
546
-
547
-
548
-    /**
549
-     * Gets all events that are published
550
-     * and have an event end time later than now
551
-     *
552
-     * @param  array $query_params An array of query params to further filter on
553
-     *                             (note that status and DTT_EVT_end will be overridden)
554
-     * @param bool   $count        whether to return the count or not (default FALSE)
555
-     * @return EE_Event[]|int
556
-     * @throws \EE_Error
557
-     */
558
-    public function get_active_and_upcoming_events($query_params, $count = false)
559
-    {
560
-        if (array_key_exists(0, $query_params)) {
561
-            $where_params = $query_params[0];
562
-            unset($query_params[0]);
563
-        } else {
564
-            $where_params = array();
565
-        }
566
-        // if we have count make sure we don't include group by
567
-        if ($count && isset($query_params['group_by'])) {
568
-            unset($query_params['group_by']);
569
-        }
570
-        // let's add specific query_params for active_events
571
-        // keep in mind this will override any sent status in the query AND any date queries.
572
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
573
-        // add where params for DTT_EVT_end
574
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
575
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
576
-                '>',
577
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
578
-            );
579
-        } else {
580
-            $where_params['Datetime.DTT_EVT_end'] = array(
581
-                '>',
582
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
583
-            );
584
-        }
585
-        $query_params[0] = $where_params;
586
-        // don't use $query_params with count()
587
-        // because we don't want to include additional query clauses like "GROUP BY"
588
-        return $count
589
-            ? $this->count(array($where_params), 'EVT_ID', true)
590
-            : $this->get_all($query_params);
591
-    }
592
-
593
-
594
-
595
-    /**
596
-     * This only returns events that are expired.
597
-     * They may still be published but all their datetimes have expired.
598
-     *
599
-     * @param  array $query_params An array of query params to further filter on
600
-     *                             (note that status and DTT_EVT_end will be overridden)
601
-     * @param bool   $count        whether to return the count or not (default FALSE)
602
-     * @return EE_Event[]|int
603
-     * @throws \EE_Error
604
-     */
605
-    public function get_expired_events($query_params, $count = false)
606
-    {
607
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
608
-        // if we have count make sure we don't include group by
609
-        if ($count && isset($query_params['group_by'])) {
610
-            unset($query_params['group_by']);
611
-        }
612
-        // let's add specific query_params for active_events
613
-        // keep in mind this will override any sent status in the query AND any date queries.
614
-        if (isset($where_params['status'])) {
615
-            unset($where_params['status']);
616
-        }
617
-        $exclude_query = $query_params;
618
-        if (isset($exclude_query[0])) {
619
-            unset($exclude_query[0]);
620
-        }
621
-        $exclude_query[0] = array(
622
-            'Datetime.DTT_EVT_end' => array(
623
-                '>',
624
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
625
-            ),
626
-        );
627
-        // first get all events that have datetimes where its not expired.
628
-        $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
629
-        $event_ids = array_keys($event_ids);
630
-        // if we have any additional query_params, let's add them to the 'AND' condition
631
-        $and_condition = array(
632
-            'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
633
-            'EVT_ID'               => array('NOT IN', $event_ids),
634
-        );
635
-        if (isset($where_params['OR'])) {
636
-            $and_condition['OR'] = $where_params['OR'];
637
-            unset($where_params['OR']);
638
-        }
639
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
640
-            $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
641
-            unset($where_params['Datetime.DTT_EVT_end']);
642
-        }
643
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
644
-            $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
645
-            unset($where_params['Datetime.DTT_EVT_start']);
646
-        }
647
-        // merge remaining $where params with the and conditions.
648
-        $where_params['AND'] = array_merge($and_condition, $where_params);
649
-        $query_params[0] = $where_params;
650
-        // don't use $query_params with count()
651
-        // because we don't want to include additional query clauses like "GROUP BY"
652
-        return $count
653
-            ? $this->count(array($where_params), 'EVT_ID', true)
654
-            : $this->get_all($query_params);
655
-    }
656
-
657
-
658
-
659
-    /**
660
-     * This basically just returns the events that do not have the publish status.
661
-     *
662
-     * @param  array   $query_params An array of query params to further filter on
663
-     *                               (note that status will be overwritten)
664
-     * @param  boolean $count        whether to return the count or not (default FALSE)
665
-     * @return EE_Event[]|int
666
-     * @throws \EE_Error
667
-     */
668
-    public function get_inactive_events($query_params, $count = false)
669
-    {
670
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
671
-        // let's add in specific query_params for inactive events.
672
-        if (isset($where_params['status'])) {
673
-            unset($where_params['status']);
674
-        }
675
-        // if we have count make sure we don't include group by
676
-        if ($count && isset($query_params['group_by'])) {
677
-            unset($query_params['group_by']);
678
-        }
679
-        // if we have any additional query_params, let's add them to the 'AND' condition
680
-        $where_params['AND']['status'] = array('!=', 'publish');
681
-        if (isset($where_params['OR'])) {
682
-            $where_params['AND']['OR'] = $where_params['OR'];
683
-            unset($where_params['OR']);
684
-        }
685
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
686
-            $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
687
-            unset($where_params['Datetime.DTT_EVT_end']);
688
-        }
689
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
690
-            $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
691
-            unset($where_params['Datetime.DTT_EVT_start']);
692
-        }
693
-        $query_params[0] = $where_params;
694
-        // don't use $query_params with count()
695
-        // because we don't want to include additional query clauses like "GROUP BY"
696
-        return $count
697
-            ? $this->count(array($where_params), 'EVT_ID', true)
698
-            : $this->get_all($query_params);
699
-    }
700
-
701
-
702
-
703
-    /**
704
-     * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
705
-     * because we don't want to override any existing global default prices but instead insert NEW prices that get
706
-     * attached to the event. See parent for param descriptions
707
-     *
708
-     * @param        $id_or_obj
709
-     * @param        $other_model_id_or_obj
710
-     * @param string $relationName
711
-     * @param array  $where_query
712
-     * @return EE_Base_Class
713
-     * @throws EE_Error
714
-     */
715
-    public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
716
-    {
717
-        if ($relationName === 'Price') {
718
-            //let's get the PRC object for the given ID to make sure that we aren't dealing with a default
719
-            $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
720
-            //if EVT_ID = 0, then this is a default
721
-            if ((int) $prc_chk->get('EVT_ID') === 0) {
722
-                //let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
723
-                $prc_chk->set('PRC_ID', 0);
724
-            }
725
-            //run parent
726
-            return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
727
-        }
728
-        //otherwise carry on as normal
729
-        return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
730
-    }
731
-
732
-
733
-
734
-    /******************** DEPRECATED METHODS ********************/
735
-
736
-
737
-
738
-    /**
739
-     * _get_question_target_db_column
740
-     *
741
-     * @deprecated as of 4.8.32.rc.001. Instead consider using
742
-     *             EE_Registration_Custom_Questions_Form located in
743
-     *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
744
-     * @access     public
745
-     * @param    EE_Registration $registration (so existing answers for registration are included)
746
-     * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
747
-     *                                         registration).
748
-     * @throws EE_Error
749
-     * @return    array
750
-     */
751
-    public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
752
-    {
753
-        if (empty($EVT_ID)) {
754
-            throw new EE_Error(__('An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
755
-                'event_espresso'));
756
-        }
757
-        $questions = array();
758
-        // get all question groups for event
759
-        $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
760
-        if (! empty($qgs)) {
761
-            foreach ($qgs as $qg) {
762
-                $qsts = $qg->questions();
763
-                $questions[$qg->ID()] = $qg->model_field_array();
764
-                $questions[$qg->ID()]['QSG_questions'] = array();
765
-                foreach ($qsts as $qst) {
766
-                    if ($qst->is_system_question()) {
767
-                        continue;
768
-                    }
769
-                    $answer = EEM_Answer::instance()->get_one(array(
770
-                        array(
771
-                            'QST_ID' => $qst->ID(),
772
-                            'REG_ID' => $registration->ID(),
773
-                        ),
774
-                    ));
775
-                    $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
776
-                    $qst_name = $qstn_id = $qst->ID();
777
-                    $ans_id = $answer->ID();
778
-                    $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
779
-                    $input_name = '';
780
-                    $input_id = sanitize_key($qst->display_text());
781
-                    $input_class = '';
782
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array();
783
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'
784
-                                                                                           . $input_name
785
-                                                                                           . $qst_name;
786
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id;
787
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class;
788
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array();
789
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst;
790
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer;
791
-                    //leave responses as-is, don't convert stuff into html entities please!
792
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false;
793
-                    if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
794
-                        $QSOs = $qst->options(true, $answer->value());
795
-                        if (is_array($QSOs)) {
796
-                            foreach ($QSOs as $QSO_ID => $QSO) {
797
-                                $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array();
798
-                            }
799
-                        }
800
-                    }
801
-                }
802
-            }
803
-        }
804
-        return $questions;
805
-    }
19
+	/**
20
+	 * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
21
+	 * event
22
+	 */
23
+	const sold_out = 'sold_out';
24
+
25
+	/**
26
+	 * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
27
+	 * date)
28
+	 */
29
+	const postponed = 'postponed';
30
+
31
+	/**
32
+	 * constant used by status(), indicating that the event will no longer occur
33
+	 */
34
+	const cancelled = 'cancelled';
35
+
36
+
37
+	/**
38
+	 * @var string
39
+	 */
40
+	protected static $_default_reg_status;
41
+
42
+
43
+	/**
44
+	 * This is the default for the additional limit field.
45
+	 * @var int
46
+	 */
47
+	protected static $_default_additional_limit = 10;
48
+
49
+
50
+	/**
51
+	 * private instance of the Event object
52
+	 *
53
+	 * @var EEM_Event
54
+	 */
55
+	protected static $_instance;
56
+
57
+
58
+
59
+	/**
60
+	 *  This function is a singleton method used to instantiate the EEM_Event object
61
+	 *
62
+	 * @param string $timezone
63
+	 * @return EEM_Event
64
+	 * @throws \EE_Error
65
+	 */
66
+	public static function instance($timezone = null)
67
+	{
68
+		// check if instance of EEM_Event already exists
69
+		if (! self::$_instance instanceof EEM_Event) {
70
+			// instantiate Espresso_model
71
+			self::$_instance = new self($timezone);
72
+		}
73
+		//we might have a timezone set, let set_timezone decide what to do with it
74
+		self::$_instance->set_timezone($timezone);
75
+		// EEM_Event object
76
+		return self::$_instance;
77
+	}
78
+
79
+
80
+
81
+	/**
82
+	 * Adds a relationship to Term_Taxonomy for each CPT_Base
83
+	 *
84
+	 * @param string $timezone
85
+	 * @throws \EE_Error
86
+	 */
87
+	protected function __construct($timezone = null)
88
+	{
89
+		EE_Registry::instance()->load_model('Registration');
90
+		$this->singular_item = esc_html__('Event', 'event_espresso');
91
+		$this->plural_item = esc_html__('Events', 'event_espresso');
92
+		// to remove Cancelled events from the frontend, copy the following filter to your functions.php file
93
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
94
+		// to remove Postponed events from the frontend, copy the following filter to your functions.php file
95
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
96
+		// to remove Sold Out events from the frontend, copy the following filter to your functions.php file
97
+		//	add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
98
+		$this->_custom_stati = apply_filters(
99
+			'AFEE__EEM_Event__construct___custom_stati',
100
+			array(
101
+				EEM_Event::cancelled => array(
102
+					'label'  => esc_html__('Cancelled', 'event_espresso'),
103
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
104
+				),
105
+				EEM_Event::postponed => array(
106
+					'label'  => esc_html__('Postponed', 'event_espresso'),
107
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
108
+				),
109
+				EEM_Event::sold_out  => array(
110
+					'label'  => esc_html__('Sold Out', 'event_espresso'),
111
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
112
+				),
113
+			)
114
+		);
115
+		self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment
116
+			: self::$_default_reg_status;
117
+		$this->_tables = array(
118
+			'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
119
+			'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
120
+		);
121
+		$this->_fields = array(
122
+			'Event_CPT'  => array(
123
+				'EVT_ID'         => new EE_Primary_Key_Int_Field('ID',
124
+					esc_html__('Post ID for Event', 'event_espresso')),
125
+				'EVT_name'       => new EE_Plain_Text_Field('post_title', esc_html__('Event Name', 'event_espresso'),
126
+					false,
127
+					''),
128
+				'EVT_desc'       => new EE_Post_Content_Field('post_content',
129
+					esc_html__('Event Description', 'event_espresso'),
130
+					false, ''),
131
+				'EVT_slug'       => new EE_Slug_Field('post_name', esc_html__('Event Slug', 'event_espresso'), false,
132
+					''),
133
+				'EVT_created'    => new EE_Datetime_Field('post_date',
134
+					esc_html__('Date/Time Event Created', 'event_espresso'),
135
+					false, EE_Datetime_Field::now),
136
+				'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt',
137
+					esc_html__('Event Short Description', 'event_espresso'), false, ''),
138
+				'EVT_modified'   => new EE_Datetime_Field('post_modified',
139
+					esc_html__('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now),
140
+				'EVT_wp_user'    => new EE_WP_User_Field('post_author',
141
+					esc_html__('Event Creator ID', 'event_espresso'),
142
+					false),
143
+				'parent'         => new EE_Integer_Field('post_parent', esc_html__('Event Parent ID', 'event_espresso'),
144
+					false,
145
+					0),
146
+				'EVT_order'      => new EE_Integer_Field('menu_order', esc_html__('Event Menu Order', 'event_espresso'),
147
+					false,
148
+					1),
149
+				'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
150
+				// EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
151
+				'status'         => new EE_WP_Post_Status_Field('post_status',
152
+					esc_html__('Event Status', 'event_espresso'),
153
+					false, 'draft', $this->_custom_stati),
154
+			),
155
+			'Event_Meta' => array(
156
+				'EVTM_ID'                         => new EE_DB_Only_Float_Field('EVTM_ID',
157
+					esc_html__('Event Meta Row ID', 'event_espresso'), false),
158
+				'EVT_ID_fk'                       => new EE_DB_Only_Int_Field('EVT_ID',
159
+					esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), false),
160
+				'EVT_display_desc'                => new EE_Boolean_Field('EVT_display_desc',
161
+					esc_html__('Display Description Flag', 'event_espresso'), false, 1),
162
+				'EVT_display_ticket_selector'     => new EE_Boolean_Field('EVT_display_ticket_selector',
163
+					esc_html__('Display Ticket Selector Flag', 'event_espresso'), false, 1),
164
+				'EVT_visible_on'                  => new EE_Datetime_Field('EVT_visible_on',
165
+					esc_html__('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now),
166
+				'EVT_additional_limit'            => new EE_Integer_Field(
167
+					'EVT_additional_limit',
168
+					esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
169
+					true,
170
+					self::$_default_additional_limit
171
+				),
172
+				'EVT_default_registration_status' => new EE_Enum_Text_Field(
173
+					'EVT_default_registration_status',
174
+					esc_html__('Default Registration Status on this Event', 'event_espresso'), false,
175
+					EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array()
176
+				),
177
+				'EVT_member_only'                 => new EE_Boolean_Field('EVT_member_only',
178
+					esc_html__('Member-Only Event Flag', 'event_espresso'), false, false),
179
+				'EVT_phone'                       => new EE_Plain_Text_Field('EVT_phone',
180
+					esc_html__('Event Phone Number', 'event_espresso'), false),
181
+				'EVT_allow_overflow'              => new EE_Boolean_Field('EVT_allow_overflow',
182
+					esc_html__('Allow Overflow on Event', 'event_espresso'), false, false),
183
+				'EVT_timezone_string'             => new EE_Plain_Text_Field('EVT_timezone_string',
184
+					esc_html__('Timezone (name) for Event times', 'event_espresso'), false),
185
+				'EVT_external_URL'                => new EE_Plain_Text_Field('EVT_external_URL',
186
+					esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true),
187
+				'EVT_donations'                   => new EE_Boolean_Field('EVT_donations',
188
+					esc_html__('Accept Donations?', 'event_espresso'), false, false),
189
+			),
190
+		);
191
+		$this->_model_relations = array(
192
+			'Registration'           => new EE_Has_Many_Relation(),
193
+			'Datetime'               => new EE_Has_Many_Relation(),
194
+			'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
195
+			'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
196
+			'Term_Relationship'      => new EE_Has_Many_Relation(),
197
+			'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
198
+			'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
199
+			'Attendee'               => new EE_HABTM_Relation('Registration'),
200
+			'WP_User'                => new EE_Belongs_To_Relation(),
201
+		);
202
+		//this model is generally available for reading
203
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
204
+		parent::__construct($timezone);
205
+	}
206
+
207
+
208
+
209
+	/**
210
+	 * @param string $default_reg_status
211
+	 */
212
+	public static function set_default_reg_status($default_reg_status)
213
+	{
214
+		self::$_default_reg_status = $default_reg_status;
215
+		// if EEM_Event has already been instantiated,
216
+		// then we need to reset the `EVT_default_reg_status` field to use the new default.
217
+		if (self::$_instance instanceof EEM_Event) {
218
+			$default_reg_status = new EE_Enum_Text_Field(
219
+				'EVT_default_registration_status',
220
+				esc_html__('Default Registration Status on this Event', 'event_espresso'),
221
+				false,
222
+				$default_reg_status,
223
+				EEM_Registration::reg_status_array()
224
+			);
225
+			$default_reg_status->_construct_finalize(
226
+				'Event_Meta',
227
+				'EVT_default_registration_status',
228
+				'EEM_Event'
229
+			);
230
+			self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
231
+		}
232
+	}
233
+
234
+
235
+	/**
236
+	 * Used to override the default for the additional limit field.
237
+	 * @param $additional_limit
238
+	 */
239
+	public static function set_default_additional_limit($additional_limit)
240
+	{
241
+		self::$_default_additional_limit = (int) $additional_limit;
242
+		if (self::$_instance instanceof EEM_Event) {
243
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
244
+				'EVT_additional_limit',
245
+				__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
246
+				true,
247
+				self::$_default_additional_limit
248
+			);
249
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
250
+				'Event_Meta',
251
+				'EVT_additional_limit',
252
+				'EEM_Event'
253
+			);
254
+		}
255
+	}
256
+
257
+
258
+	/**
259
+	 * Return what is currently set as the default additional limit for the event.
260
+	 * @return int
261
+	 */
262
+	public static function get_default_additional_limit()
263
+	{
264
+		return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
265
+	}
266
+
267
+
268
+	/**
269
+	 * get_question_groups
270
+	 *
271
+	 * @return array
272
+	 * @throws \EE_Error
273
+	 */
274
+	public function get_all_question_groups()
275
+	{
276
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
277
+			array(
278
+				array('QSG_deleted' => false),
279
+				'order_by' => array('QSG_order' => 'ASC'),
280
+			)
281
+		);
282
+	}
283
+
284
+
285
+
286
+	/**
287
+	 * get_question_groups
288
+	 *
289
+	 * @param int $EVT_ID
290
+	 * @return array|bool
291
+	 * @throws \EE_Error
292
+	 */
293
+	public function get_all_event_question_groups($EVT_ID = 0)
294
+	{
295
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
296
+			EE_Error::add_error(
297
+				esc_html__(
298
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
299
+					'event_espresso'
300
+				),
301
+				__FILE__, __FUNCTION__, __LINE__
302
+			);
303
+			return false;
304
+		}
305
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
306
+			array(
307
+				array('EVT_ID' => $EVT_ID),
308
+			)
309
+		);
310
+	}
311
+
312
+
313
+
314
+	/**
315
+	 * get_question_groups
316
+	 *
317
+	 * @param int     $EVT_ID
318
+	 * @param boolean $for_primary_attendee
319
+	 * @return array|bool
320
+	 * @throws \EE_Error
321
+	 */
322
+	public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
323
+	{
324
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
325
+			EE_Error::add_error(
326
+				esc_html__(
327
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
328
+					'event_espresso'
329
+				),
330
+				__FILE__, __FUNCTION__, __LINE__
331
+			);
332
+			return false;
333
+		}
334
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
335
+			array(
336
+				array(
337
+					'EVT_ID'      => $EVT_ID,
338
+					'EQG_primary' => $for_primary_attendee,
339
+				),
340
+			)
341
+		);
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 * get_question_groups
348
+	 *
349
+	 * @param int             $EVT_ID
350
+	 * @param EE_Registration $registration
351
+	 * @return array|bool
352
+	 * @throws \EE_Error
353
+	 */
354
+	public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
355
+	{
356
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
357
+			EE_Error::add_error(
358
+				esc_html__(
359
+					'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
360
+					'event_espresso'
361
+				),
362
+				__FILE__, __FUNCTION__, __LINE__
363
+			);
364
+			return false;
365
+		}
366
+		$where_params = array(
367
+			'Event_Question_Group.EVT_ID'      => $EVT_ID,
368
+			'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false,
369
+			'QSG_deleted'                      => false,
370
+		);
371
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
372
+			array(
373
+				$where_params,
374
+				'order_by' => array('QSG_order' => 'ASC'),
375
+			)
376
+		);
377
+	}
378
+
379
+
380
+
381
+	/**
382
+	 * get_question_target_db_column
383
+	 *
384
+	 * @param string $QSG_IDs csv list of $QSG IDs
385
+	 * @return array|bool
386
+	 * @throws \EE_Error
387
+	 */
388
+	public function get_questions_in_groups($QSG_IDs = '')
389
+	{
390
+		if (empty($QSG_IDs)) {
391
+			EE_Error::add_error(
392
+				esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
393
+				__FILE__, __FUNCTION__, __LINE__
394
+			);
395
+			return false;
396
+		}
397
+		return EE_Registry::instance()->load_model('Question')->get_all(
398
+			array(
399
+				array(
400
+					'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
401
+					'QST_deleted'           => false,
402
+					'QST_admin_only'        => is_admin(),
403
+				),
404
+				'order_by' => 'QST_order',
405
+			)
406
+		);
407
+	}
408
+
409
+
410
+
411
+	/**
412
+	 * get_options_for_question
413
+	 *
414
+	 * @param string $QST_IDs csv list of $QST IDs
415
+	 * @return array|bool
416
+	 * @throws \EE_Error
417
+	 */
418
+	public function get_options_for_question($QST_IDs)
419
+	{
420
+		if (empty($QST_IDs)) {
421
+			EE_Error::add_error(
422
+				esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
423
+				__FILE__, __FUNCTION__, __LINE__
424
+			);
425
+			return false;
426
+		}
427
+		return EE_Registry::instance()->load_model('Question_Option')->get_all(
428
+			array(
429
+				array(
430
+					'Question.QST_ID' => array('IN', $QST_IDs),
431
+					'QSO_deleted'     => false,
432
+				),
433
+				'order_by' => 'QSO_ID',
434
+			)
435
+		);
436
+	}
437
+
438
+
439
+
440
+
441
+
442
+
443
+
444
+	/**
445
+	 * Gets all events that are published
446
+	 * and have event start time earlier than now and an event end time later than now
447
+	 *
448
+	 * @param  array $query_params An array of query params to further filter on
449
+	 *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
450
+	 * @param bool   $count        whether to return the count or not (default FALSE)
451
+	 * @return EE_Event[]|int
452
+	 * @throws \EE_Error
453
+	 */
454
+	public function get_active_events($query_params, $count = false)
455
+	{
456
+		if (array_key_exists(0, $query_params)) {
457
+			$where_params = $query_params[0];
458
+			unset($query_params[0]);
459
+		} else {
460
+			$where_params = array();
461
+		}
462
+		// if we have count make sure we don't include group by
463
+		if ($count && isset($query_params['group_by'])) {
464
+			unset($query_params['group_by']);
465
+		}
466
+		// let's add specific query_params for active_events
467
+		// keep in mind this will override any sent status in the query AND any date queries.
468
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
469
+		//if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
470
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
471
+			$where_params['Datetime.DTT_EVT_start******'] = array(
472
+				'<',
473
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
474
+			);
475
+		} else {
476
+			$where_params['Datetime.DTT_EVT_start'] = array(
477
+				'<',
478
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
479
+			);
480
+		}
481
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
482
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
483
+				'>',
484
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
485
+			);
486
+		} else {
487
+			$where_params['Datetime.DTT_EVT_end'] = array(
488
+				'>',
489
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
490
+			);
491
+		}
492
+		$query_params[0] = $where_params;
493
+		// don't use $query_params with count()
494
+		// because we don't want to include additional query clauses like "GROUP BY"
495
+		return $count
496
+			? $this->count(array($where_params), 'EVT_ID', true)
497
+			: $this->get_all($query_params);
498
+	}
499
+
500
+
501
+
502
+	/**
503
+	 * get all events that are published and have an event start time later than now
504
+	 *
505
+	 * @param  array $query_params An array of query params to further filter on
506
+	 *                             (Note that status and DTT_EVT_start will be overridden)
507
+	 * @param bool   $count        whether to return the count or not (default FALSE)
508
+	 * @return EE_Event[]|int
509
+	 * @throws \EE_Error
510
+	 */
511
+	public function get_upcoming_events($query_params, $count = false)
512
+	{
513
+		if (array_key_exists(0, $query_params)) {
514
+			$where_params = $query_params[0];
515
+			unset($query_params[0]);
516
+		} else {
517
+			$where_params = array();
518
+		}
519
+		// if we have count make sure we don't include group by
520
+		if ($count && isset($query_params['group_by'])) {
521
+			unset($query_params['group_by']);
522
+		}
523
+		// let's add specific query_params for active_events
524
+		// keep in mind this will override any sent status in the query AND any date queries.
525
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
526
+		// if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
527
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
528
+			$where_params['Datetime.DTT_EVT_start*****'] = array(
529
+				'>',
530
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
531
+			);
532
+		} else {
533
+			$where_params['Datetime.DTT_EVT_start'] = array(
534
+				'>',
535
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
536
+			);
537
+		}
538
+		$query_params[0] = $where_params;
539
+		// don't use $query_params with count()
540
+		// because we don't want to include additional query clauses like "GROUP BY"
541
+		return $count
542
+			? $this->count(array($where_params), 'EVT_ID', true)
543
+			: $this->get_all($query_params);
544
+	}
545
+
546
+
547
+
548
+	/**
549
+	 * Gets all events that are published
550
+	 * and have an event end time later than now
551
+	 *
552
+	 * @param  array $query_params An array of query params to further filter on
553
+	 *                             (note that status and DTT_EVT_end will be overridden)
554
+	 * @param bool   $count        whether to return the count or not (default FALSE)
555
+	 * @return EE_Event[]|int
556
+	 * @throws \EE_Error
557
+	 */
558
+	public function get_active_and_upcoming_events($query_params, $count = false)
559
+	{
560
+		if (array_key_exists(0, $query_params)) {
561
+			$where_params = $query_params[0];
562
+			unset($query_params[0]);
563
+		} else {
564
+			$where_params = array();
565
+		}
566
+		// if we have count make sure we don't include group by
567
+		if ($count && isset($query_params['group_by'])) {
568
+			unset($query_params['group_by']);
569
+		}
570
+		// let's add specific query_params for active_events
571
+		// keep in mind this will override any sent status in the query AND any date queries.
572
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
573
+		// add where params for DTT_EVT_end
574
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
575
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
576
+				'>',
577
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
578
+			);
579
+		} else {
580
+			$where_params['Datetime.DTT_EVT_end'] = array(
581
+				'>',
582
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
583
+			);
584
+		}
585
+		$query_params[0] = $where_params;
586
+		// don't use $query_params with count()
587
+		// because we don't want to include additional query clauses like "GROUP BY"
588
+		return $count
589
+			? $this->count(array($where_params), 'EVT_ID', true)
590
+			: $this->get_all($query_params);
591
+	}
592
+
593
+
594
+
595
+	/**
596
+	 * This only returns events that are expired.
597
+	 * They may still be published but all their datetimes have expired.
598
+	 *
599
+	 * @param  array $query_params An array of query params to further filter on
600
+	 *                             (note that status and DTT_EVT_end will be overridden)
601
+	 * @param bool   $count        whether to return the count or not (default FALSE)
602
+	 * @return EE_Event[]|int
603
+	 * @throws \EE_Error
604
+	 */
605
+	public function get_expired_events($query_params, $count = false)
606
+	{
607
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
608
+		// if we have count make sure we don't include group by
609
+		if ($count && isset($query_params['group_by'])) {
610
+			unset($query_params['group_by']);
611
+		}
612
+		// let's add specific query_params for active_events
613
+		// keep in mind this will override any sent status in the query AND any date queries.
614
+		if (isset($where_params['status'])) {
615
+			unset($where_params['status']);
616
+		}
617
+		$exclude_query = $query_params;
618
+		if (isset($exclude_query[0])) {
619
+			unset($exclude_query[0]);
620
+		}
621
+		$exclude_query[0] = array(
622
+			'Datetime.DTT_EVT_end' => array(
623
+				'>',
624
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
625
+			),
626
+		);
627
+		// first get all events that have datetimes where its not expired.
628
+		$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
629
+		$event_ids = array_keys($event_ids);
630
+		// if we have any additional query_params, let's add them to the 'AND' condition
631
+		$and_condition = array(
632
+			'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
633
+			'EVT_ID'               => array('NOT IN', $event_ids),
634
+		);
635
+		if (isset($where_params['OR'])) {
636
+			$and_condition['OR'] = $where_params['OR'];
637
+			unset($where_params['OR']);
638
+		}
639
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
640
+			$and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
641
+			unset($where_params['Datetime.DTT_EVT_end']);
642
+		}
643
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
644
+			$and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
645
+			unset($where_params['Datetime.DTT_EVT_start']);
646
+		}
647
+		// merge remaining $where params with the and conditions.
648
+		$where_params['AND'] = array_merge($and_condition, $where_params);
649
+		$query_params[0] = $where_params;
650
+		// don't use $query_params with count()
651
+		// because we don't want to include additional query clauses like "GROUP BY"
652
+		return $count
653
+			? $this->count(array($where_params), 'EVT_ID', true)
654
+			: $this->get_all($query_params);
655
+	}
656
+
657
+
658
+
659
+	/**
660
+	 * This basically just returns the events that do not have the publish status.
661
+	 *
662
+	 * @param  array   $query_params An array of query params to further filter on
663
+	 *                               (note that status will be overwritten)
664
+	 * @param  boolean $count        whether to return the count or not (default FALSE)
665
+	 * @return EE_Event[]|int
666
+	 * @throws \EE_Error
667
+	 */
668
+	public function get_inactive_events($query_params, $count = false)
669
+	{
670
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
671
+		// let's add in specific query_params for inactive events.
672
+		if (isset($where_params['status'])) {
673
+			unset($where_params['status']);
674
+		}
675
+		// if we have count make sure we don't include group by
676
+		if ($count && isset($query_params['group_by'])) {
677
+			unset($query_params['group_by']);
678
+		}
679
+		// if we have any additional query_params, let's add them to the 'AND' condition
680
+		$where_params['AND']['status'] = array('!=', 'publish');
681
+		if (isset($where_params['OR'])) {
682
+			$where_params['AND']['OR'] = $where_params['OR'];
683
+			unset($where_params['OR']);
684
+		}
685
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
686
+			$where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
687
+			unset($where_params['Datetime.DTT_EVT_end']);
688
+		}
689
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
690
+			$where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
691
+			unset($where_params['Datetime.DTT_EVT_start']);
692
+		}
693
+		$query_params[0] = $where_params;
694
+		// don't use $query_params with count()
695
+		// because we don't want to include additional query clauses like "GROUP BY"
696
+		return $count
697
+			? $this->count(array($where_params), 'EVT_ID', true)
698
+			: $this->get_all($query_params);
699
+	}
700
+
701
+
702
+
703
+	/**
704
+	 * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
705
+	 * because we don't want to override any existing global default prices but instead insert NEW prices that get
706
+	 * attached to the event. See parent for param descriptions
707
+	 *
708
+	 * @param        $id_or_obj
709
+	 * @param        $other_model_id_or_obj
710
+	 * @param string $relationName
711
+	 * @param array  $where_query
712
+	 * @return EE_Base_Class
713
+	 * @throws EE_Error
714
+	 */
715
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
716
+	{
717
+		if ($relationName === 'Price') {
718
+			//let's get the PRC object for the given ID to make sure that we aren't dealing with a default
719
+			$prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
720
+			//if EVT_ID = 0, then this is a default
721
+			if ((int) $prc_chk->get('EVT_ID') === 0) {
722
+				//let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
723
+				$prc_chk->set('PRC_ID', 0);
724
+			}
725
+			//run parent
726
+			return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
727
+		}
728
+		//otherwise carry on as normal
729
+		return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
730
+	}
731
+
732
+
733
+
734
+	/******************** DEPRECATED METHODS ********************/
735
+
736
+
737
+
738
+	/**
739
+	 * _get_question_target_db_column
740
+	 *
741
+	 * @deprecated as of 4.8.32.rc.001. Instead consider using
742
+	 *             EE_Registration_Custom_Questions_Form located in
743
+	 *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
744
+	 * @access     public
745
+	 * @param    EE_Registration $registration (so existing answers for registration are included)
746
+	 * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
747
+	 *                                         registration).
748
+	 * @throws EE_Error
749
+	 * @return    array
750
+	 */
751
+	public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
752
+	{
753
+		if (empty($EVT_ID)) {
754
+			throw new EE_Error(__('An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
755
+				'event_espresso'));
756
+		}
757
+		$questions = array();
758
+		// get all question groups for event
759
+		$qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
760
+		if (! empty($qgs)) {
761
+			foreach ($qgs as $qg) {
762
+				$qsts = $qg->questions();
763
+				$questions[$qg->ID()] = $qg->model_field_array();
764
+				$questions[$qg->ID()]['QSG_questions'] = array();
765
+				foreach ($qsts as $qst) {
766
+					if ($qst->is_system_question()) {
767
+						continue;
768
+					}
769
+					$answer = EEM_Answer::instance()->get_one(array(
770
+						array(
771
+							'QST_ID' => $qst->ID(),
772
+							'REG_ID' => $registration->ID(),
773
+						),
774
+					));
775
+					$answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
776
+					$qst_name = $qstn_id = $qst->ID();
777
+					$ans_id = $answer->ID();
778
+					$qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
779
+					$input_name = '';
780
+					$input_id = sanitize_key($qst->display_text());
781
+					$input_class = '';
782
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array();
783
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'
784
+																						   . $input_name
785
+																						   . $qst_name;
786
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id;
787
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class;
788
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array();
789
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst;
790
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer;
791
+					//leave responses as-is, don't convert stuff into html entities please!
792
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false;
793
+					if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
794
+						$QSOs = $qst->options(true, $answer->value());
795
+						if (is_array($QSOs)) {
796
+							foreach ($QSOs as $QSO_ID => $QSO) {
797
+								$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array();
798
+							}
799
+						}
800
+					}
801
+				}
802
+			}
803
+		}
804
+		return $questions;
805
+	}
806 806
 
807 807
 
808 808
 }
Please login to merge, or discard this patch.
core/services/loaders/CoreLoader.php 3 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
      */
39 39
     public function __construct($generator)
40 40
     {
41
-        if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
41
+        if ( ! ($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
42 42
             throw new InvalidArgumentException(
43 43
                 esc_html__(
44 44
                     'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.',
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
     /**
34 34
      * CoreLoader constructor.
35 35
      *
36
-     * @param EE_Registry|CoffeeShop $generator
36
+     * @param EE_Registry $generator
37 37
      * @throws InvalidArgumentException
38 38
      */
39 39
     public function __construct($generator)
Please login to merge, or discard this patch.
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -23,58 +23,58 @@
 block discarded – undo
23 23
 class CoreLoader implements LoaderInterface
24 24
 {
25 25
 
26
-    /**
27
-     * @var EE_Registry|CoffeeShop $generator
28
-     */
29
-    private $generator;
30
-
31
-
32
-
33
-    /**
34
-     * CoreLoader constructor.
35
-     *
36
-     * @param EE_Registry|CoffeeShop $generator
37
-     * @throws InvalidArgumentException
38
-     */
39
-    public function __construct($generator)
40
-    {
41
-        if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
42
-            throw new InvalidArgumentException(
43
-                esc_html__(
44
-                    'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.',
45
-                    'event_espresso'
46
-                )
47
-            );
48
-        }
49
-        $this->generator = $generator;
50
-    }
51
-
52
-
53
-
54
-    /**
55
-     * @param string $fqcn
56
-     * @param array  $arguments
57
-     * @return mixed
58
-     * @throws ServiceNotFoundException
59
-     */
60
-    public function load($fqcn, $arguments = array())
61
-    {
62
-        return $this->generator instanceof EE_Registry
63
-            ? $this->generator->create($fqcn, $arguments)
64
-            : $this->generator->brew($fqcn, $arguments);
65
-    }
66
-
67
-
68
-
69
-    /**
70
-     * calls reset() on generator if method exists
71
-     */
72
-    public function reset()
73
-    {
74
-        if (method_exists($this->generator, 'reset')) {
75
-            $this->generator->reset();
76
-        }
77
-    }
26
+	/**
27
+	 * @var EE_Registry|CoffeeShop $generator
28
+	 */
29
+	private $generator;
30
+
31
+
32
+
33
+	/**
34
+	 * CoreLoader constructor.
35
+	 *
36
+	 * @param EE_Registry|CoffeeShop $generator
37
+	 * @throws InvalidArgumentException
38
+	 */
39
+	public function __construct($generator)
40
+	{
41
+		if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
42
+			throw new InvalidArgumentException(
43
+				esc_html__(
44
+					'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.',
45
+					'event_espresso'
46
+				)
47
+			);
48
+		}
49
+		$this->generator = $generator;
50
+	}
51
+
52
+
53
+
54
+	/**
55
+	 * @param string $fqcn
56
+	 * @param array  $arguments
57
+	 * @return mixed
58
+	 * @throws ServiceNotFoundException
59
+	 */
60
+	public function load($fqcn, $arguments = array())
61
+	{
62
+		return $this->generator instanceof EE_Registry
63
+			? $this->generator->create($fqcn, $arguments)
64
+			: $this->generator->brew($fqcn, $arguments);
65
+	}
66
+
67
+
68
+
69
+	/**
70
+	 * calls reset() on generator if method exists
71
+	 */
72
+	public function reset()
73
+	{
74
+		if (method_exists($this->generator, 'reset')) {
75
+			$this->generator->reset();
76
+		}
77
+	}
78 78
 
79 79
 }
80 80
 // End of file CoreLoader.php
Please login to merge, or discard this patch.
core/services/loaders/LoaderDecorator.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -19,22 +19,22 @@
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    /**
23
-     * @var LoaderInterface $loader
24
-     */
25
-    protected $loader;
26
-
27
-
28
-
29
-    /**
30
-     * LoaderDecorator constructor.
31
-     *
32
-     * @param LoaderInterface $loader
33
-     */
34
-    public function __construct(LoaderInterface $loader)
35
-    {
36
-        $this->loader = $loader;
37
-    }
22
+	/**
23
+	 * @var LoaderInterface $loader
24
+	 */
25
+	protected $loader;
26
+
27
+
28
+
29
+	/**
30
+	 * LoaderDecorator constructor.
31
+	 *
32
+	 * @param LoaderInterface $loader
33
+	 */
34
+	public function __construct(LoaderInterface $loader)
35
+	{
36
+		$this->loader = $loader;
37
+	}
38 38
 
39 39
 
40 40
 
Please login to merge, or discard this patch.
core/services/collections/CollectionInterface.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\services\collections;
3 3
 
4
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
-	exit( 'No direct script access allowed' );
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	 * @param  mixed $identifier
28 28
 	 * @return bool
29 29
 	 */
30
-	public function add( $object, $identifier = null );
30
+	public function add($object, $identifier = null);
31 31
 
32 32
 	/**
33 33
 	 * setIdentifier
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	 * @param  mixed $identifier
40 40
 	 * @return bool
41 41
 	 */
42
-	public function setIdentifier( $object, $identifier = null );
42
+	public function setIdentifier($object, $identifier = null);
43 43
 
44 44
 	/**
45 45
 	 * get
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 * @param mixed $identifier
51 51
 	 * @return mixed
52 52
 	 */
53
-	public function get( $identifier );
53
+	public function get($identifier);
54 54
 
55 55
 	/**
56 56
 	 * has
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 * @param  mixed $identifier
63 63
 	 * @return bool
64 64
 	 */
65
-	public function has( $identifier );
65
+	public function has($identifier);
66 66
 
67 67
 	/**
68 68
 	 * hasObject
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	 * @param $object
73 73
 	 * @return bool
74 74
 	 */
75
-	public function hasObject( $object );
75
+	public function hasObject($object);
76 76
 
77 77
 	/**
78 78
 	 * remove
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	 * @param $object
83 83
 	 * @return bool
84 84
 	 */
85
-	public function remove( $object );
85
+	public function remove($object);
86 86
 
87 87
 	/**
88 88
 	 * setCurrent
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	 * @param mixed $identifier
93 93
 	 * @return boolean
94 94
 	 */
95
-	public function setCurrent( $identifier ) ;
95
+	public function setCurrent($identifier);
96 96
 
97 97
 	/**
98 98
 	 * setCurrentUsingObject
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	 * @param $object
103 103
 	 * @return boolean
104 104
 	 */
105
-	public function setCurrentUsingObject( $object );
105
+	public function setCurrentUsingObject($object);
106 106
 
107 107
 	/**
108 108
 	 * Returns the object occupying the index before the current object,
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	 * @param $object
120 120
 	 * @return boolean|int|string
121 121
 	 */
122
-	public function indexOf( $object );
122
+	public function indexOf($object);
123 123
 
124 124
 
125 125
 	/**
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 	 * @param $index
130 130
 	 * @return mixed
131 131
 	 */
132
-	public function objectAtIndex( $index );
132
+	public function objectAtIndex($index);
133 133
 
134 134
 	/**
135 135
 	 * Returns the sequence of objects as specified by the offset and length
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 	 * @param int $length
140 140
 	 * @return array
141 141
 	 */
142
-	public function slice( $offset, $length );
142
+	public function slice($offset, $length);
143 143
 
144 144
 	/**
145 145
 	 * Inserts an object (or an array of objects) at a certain point
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 	 * @param mixed   $objects A single object or an array of objects
149 149
 	 * @param integer $index
150 150
 	 */
151
-	public function insertAt( $objects, $index );
151
+	public function insertAt($objects, $index);
152 152
 
153 153
 	/**
154 154
 	 * Removes the object at the given index
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 	 * @see http://stackoverflow.com/a/8736013
157 157
 	 * @param integer $index
158 158
 	 */
159
-	public function removeAt( $index ) ;
159
+	public function removeAt($index);
160 160
 
161 161
 
162 162
 
Please login to merge, or discard this patch.
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -113,12 +113,12 @@  discard block
 block discarded – undo
113 113
 	public function previous();
114 114
 
115 115
 		/**
116
-	 * Returns the index of a given object, or false if not found
117
-	 *
118
-	 * @see http://stackoverflow.com/a/8736013
119
-	 * @param $object
120
-	 * @return boolean|int|string
121
-	 */
116
+		 * Returns the index of a given object, or false if not found
117
+		 *
118
+		 * @see http://stackoverflow.com/a/8736013
119
+		 * @param $object
120
+		 * @return boolean|int|string
121
+		 */
122 122
 	public function indexOf( $object );
123 123
 
124 124
 
@@ -160,10 +160,10 @@  discard block
 block discarded – undo
160 160
 
161 161
 
162 162
 
163
-    /**
164
-     * detaches ALL objects from the Collection
165
-     */
166
-    public function detachAll();
163
+	/**
164
+	 * detaches ALL objects from the Collection
165
+	 */
166
+	public function detachAll();
167 167
 
168 168
 }
169 169
 // End of file CollectionInterface.php
Please login to merge, or discard this patch.