Completed
Branch FET/allow-prices-to-be-more-pr... (276f1f)
by
unknown
17:02 queued 13:56
created
core/libraries/form_sections/base/EE_Form_Section_Validatable.form.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -119,7 +119,7 @@
 block discarded – undo
119 119
         } else {
120 120
             $validation_error = new EE_Validation_Error($message_or_object, $error_code, $this, $previous_exception);
121 121
         }
122
-        $this->_validation_errors[ $this->name() ] = $validation_error;
122
+        $this->_validation_errors[$this->name()] = $validation_error;
123 123
     }
124 124
 
125 125
 
Please login to merge, or discard this patch.
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -19,151 +19,151 @@
 block discarded – undo
19 19
  */
20 20
 abstract class EE_Form_Section_Validatable extends EE_Form_Section_Base
21 21
 {
22
-    /**
23
-     * Array of validation errors in this section. Does not contain validation errors in subsections, however.
24
-     * Those are stored individually on each subsection.
25
-     *
26
-     * @var EE_Validation_Error[]
27
-     */
28
-    protected $_validation_errors = array();
29
-
30
-
31
-
32
-    /**
33
-     * Errors on this form section. Note: EE_Form_Section_Proper
34
-     * has another function for getting all errors in this form section and subsections
35
-     * called get_validation_errors_accumulated
36
-     *
37
-     * @return EE_Validation_Error[]
38
-     */
39
-    public function get_validation_errors()
40
-    {
41
-        return $this->_validation_errors;
42
-    }
43
-
44
-
45
-
46
-    /**
47
-     * returns a comma-separated list of all the validation errors in it.
48
-     * If we want this to be customizable, we may decide to create a strategy for displaying it
49
-     *
50
-     * @return string
51
-     */
52
-    public function get_validation_error_string()
53
-    {
54
-        $validation_error_messages = array();
55
-        if ($this->get_validation_errors()) {
56
-            foreach ($this->get_validation_errors() as $validation_error) {
57
-                if ($validation_error instanceof EE_Validation_Error) {
58
-                    $validation_error_messages[] = $validation_error->getMessage();
59
-                }
60
-            }
61
-        }
62
-        return implode(", ", $validation_error_messages);
63
-    }
64
-
65
-
66
-
67
-    /**
68
-     * Performs validation on this form section (and subsections). Should be called after _normalize()
69
-     *
70
-     * @return boolean of whether or not the form section is valid
71
-     */
72
-    abstract protected function _validate();
73
-
74
-
75
-
76
-    /**
77
-     * Checks if this field has any validation errors
78
-     *
79
-     * @return boolean
80
-     */
81
-    public function is_valid()
82
-    {
83
-        if (count($this->_validation_errors)) {
84
-            return false;
85
-        } else {
86
-            return true;
87
-        }
88
-    }
89
-
90
-
91
-
92
-    /**
93
-     * Sanitizes input for this form section
94
-     *
95
-     * @param array $req_data is the full request data
96
-     * @return boolean of whether a normalization error occurred
97
-     * @throws EE_Validation_Error
98
-     */
99
-    abstract protected function _normalize($req_data);
100
-
101
-
102
-    /**
103
-     * Creates a validation error from the arguments provided, and adds it to the form section's list.
104
-     * If such an EE_Validation_Error object is passed in as the first arg, simply sets this as its form section, and
105
-     * adds it to the list of validation errors of errors
106
-     *
107
-     * @param mixed     $message_or_object  internationalized string describing the validation error; or it could be a
108
-     *                                      proper EE_Validation_Error object
109
-     * @param string    $error_code         a short key which can be used to uniquely identify the error
110
-     * @param Exception $previous_exception if there was an exception that caused the error, that exception
111
-     * @return void
112
-     * @throws EE_Error
113
-     */
114
-    public function add_validation_error($message_or_object, $error_code = null, $previous_exception = null)
115
-    {
116
-        if ($message_or_object instanceof EE_Validation_Error) {
117
-            $validation_error = $message_or_object;
118
-            $validation_error->set_form_section($this);
119
-        } else {
120
-            $validation_error = new EE_Validation_Error($message_or_object, $error_code, $this, $previous_exception);
121
-        }
122
-        $this->_validation_errors[ $this->name() ] = $validation_error;
123
-    }
124
-
125
-
126
-
127
-    /**
128
-     * When generating the JS for the jquery validation rules like<br>
129
-     * <code>$( "#myform" ).validate({
130
-     * rules: {
131
-     * password: "required",
132
-     * password_again: {
133
-     * equalTo: "#password"
134
-     * }
135
-     * }
136
-     * });</code>
137
-     * gets the sections like
138
-     * <br><code>password: "required",
139
-     * password_again: {
140
-     * equalTo: "#password"
141
-     * }</code>
142
-     * except we leave it as a PHP object, and leave wp_localize_script to
143
-     * turn it into a JSON object which can be used by the js
144
-     *
145
-     * @return array
146
-     */
147
-    abstract public function get_jquery_validation_rules();
148
-
149
-
150
-
151
-    /**
152
-     * Checks if this form section's data is present in the req data specified
153
-     *
154
-     * @param array $req_data usually post data, if null that's what's used
155
-     * @return boolean
156
-     */
157
-    abstract public function form_data_present_in($req_data = null);
158
-
159
-
160
-
161
-    /**
162
-     * Removes teh sensitive data from this form section (usually done after
163
-     * utilizing the data business function, but before saving it somewhere. Eg,
164
-     * may remove a password from the form after verifying it was correct)
165
-     *
166
-     * @return void
167
-     */
168
-    abstract public function clean_sensitive_data();
22
+	/**
23
+	 * Array of validation errors in this section. Does not contain validation errors in subsections, however.
24
+	 * Those are stored individually on each subsection.
25
+	 *
26
+	 * @var EE_Validation_Error[]
27
+	 */
28
+	protected $_validation_errors = array();
29
+
30
+
31
+
32
+	/**
33
+	 * Errors on this form section. Note: EE_Form_Section_Proper
34
+	 * has another function for getting all errors in this form section and subsections
35
+	 * called get_validation_errors_accumulated
36
+	 *
37
+	 * @return EE_Validation_Error[]
38
+	 */
39
+	public function get_validation_errors()
40
+	{
41
+		return $this->_validation_errors;
42
+	}
43
+
44
+
45
+
46
+	/**
47
+	 * returns a comma-separated list of all the validation errors in it.
48
+	 * If we want this to be customizable, we may decide to create a strategy for displaying it
49
+	 *
50
+	 * @return string
51
+	 */
52
+	public function get_validation_error_string()
53
+	{
54
+		$validation_error_messages = array();
55
+		if ($this->get_validation_errors()) {
56
+			foreach ($this->get_validation_errors() as $validation_error) {
57
+				if ($validation_error instanceof EE_Validation_Error) {
58
+					$validation_error_messages[] = $validation_error->getMessage();
59
+				}
60
+			}
61
+		}
62
+		return implode(", ", $validation_error_messages);
63
+	}
64
+
65
+
66
+
67
+	/**
68
+	 * Performs validation on this form section (and subsections). Should be called after _normalize()
69
+	 *
70
+	 * @return boolean of whether or not the form section is valid
71
+	 */
72
+	abstract protected function _validate();
73
+
74
+
75
+
76
+	/**
77
+	 * Checks if this field has any validation errors
78
+	 *
79
+	 * @return boolean
80
+	 */
81
+	public function is_valid()
82
+	{
83
+		if (count($this->_validation_errors)) {
84
+			return false;
85
+		} else {
86
+			return true;
87
+		}
88
+	}
89
+
90
+
91
+
92
+	/**
93
+	 * Sanitizes input for this form section
94
+	 *
95
+	 * @param array $req_data is the full request data
96
+	 * @return boolean of whether a normalization error occurred
97
+	 * @throws EE_Validation_Error
98
+	 */
99
+	abstract protected function _normalize($req_data);
100
+
101
+
102
+	/**
103
+	 * Creates a validation error from the arguments provided, and adds it to the form section's list.
104
+	 * If such an EE_Validation_Error object is passed in as the first arg, simply sets this as its form section, and
105
+	 * adds it to the list of validation errors of errors
106
+	 *
107
+	 * @param mixed     $message_or_object  internationalized string describing the validation error; or it could be a
108
+	 *                                      proper EE_Validation_Error object
109
+	 * @param string    $error_code         a short key which can be used to uniquely identify the error
110
+	 * @param Exception $previous_exception if there was an exception that caused the error, that exception
111
+	 * @return void
112
+	 * @throws EE_Error
113
+	 */
114
+	public function add_validation_error($message_or_object, $error_code = null, $previous_exception = null)
115
+	{
116
+		if ($message_or_object instanceof EE_Validation_Error) {
117
+			$validation_error = $message_or_object;
118
+			$validation_error->set_form_section($this);
119
+		} else {
120
+			$validation_error = new EE_Validation_Error($message_or_object, $error_code, $this, $previous_exception);
121
+		}
122
+		$this->_validation_errors[ $this->name() ] = $validation_error;
123
+	}
124
+
125
+
126
+
127
+	/**
128
+	 * When generating the JS for the jquery validation rules like<br>
129
+	 * <code>$( "#myform" ).validate({
130
+	 * rules: {
131
+	 * password: "required",
132
+	 * password_again: {
133
+	 * equalTo: "#password"
134
+	 * }
135
+	 * }
136
+	 * });</code>
137
+	 * gets the sections like
138
+	 * <br><code>password: "required",
139
+	 * password_again: {
140
+	 * equalTo: "#password"
141
+	 * }</code>
142
+	 * except we leave it as a PHP object, and leave wp_localize_script to
143
+	 * turn it into a JSON object which can be used by the js
144
+	 *
145
+	 * @return array
146
+	 */
147
+	abstract public function get_jquery_validation_rules();
148
+
149
+
150
+
151
+	/**
152
+	 * Checks if this form section's data is present in the req data specified
153
+	 *
154
+	 * @param array $req_data usually post data, if null that's what's used
155
+	 * @return boolean
156
+	 */
157
+	abstract public function form_data_present_in($req_data = null);
158
+
159
+
160
+
161
+	/**
162
+	 * Removes teh sensitive data from this form section (usually done after
163
+	 * utilizing the data business function, but before saving it somewhere. Eg,
164
+	 * may remove a password from the form after verifying it was correct)
165
+	 *
166
+	 * @return void
167
+	 */
168
+	abstract public function clean_sensitive_data();
169 169
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/controllers/rpc/Checkin.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
             $force = false;
63 63
         }
64 64
         $reg = EEM_Registration::instance()->get_one_by_ID($reg_id);
65
-        if (! $reg instanceof EE_Registration) {
65
+        if ( ! $reg instanceof EE_Registration) {
66 66
             return $this->sendResponse(
67 67
                 new WP_Error(
68 68
                     'rest_registration_toggle_checkin_invalid_id',
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
                 )
78 78
             );
79 79
         }
80
-        if (! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) {
80
+        if ( ! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) {
81 81
             return $this->sendResponse(
82 82
                 new WP_Error(
83 83
                     'rest_user_cannot_toggle_checkin',
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
         $success = $reg->toggle_checkin_status($dtt_id, ! $force);
93 93
         if ($success === false) {
94 94
             // check if we know they can't check in because they're not approved and we aren't forcing
95
-            if (! $reg->is_approved() && ! $force) {
95
+            if ( ! $reg->is_approved() && ! $force) {
96 96
                 // rely on EE_Error::add_error messages to have been added to give more data about why it failed
97 97
                 return $this->sendResponse(
98 98
                     new WP_Error(
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
                 ],
125 125
             ]
126 126
         );
127
-        if (! $checkin instanceof EE_Checkin) {
127
+        if ( ! $checkin instanceof EE_Checkin) {
128 128
             return $this->sendResponse(
129 129
                 new WP_Error(
130 130
                     'rest_toggle_checkin_error',
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
         }
144 144
         $get_request = new WP_REST_Request(
145 145
             'GET',
146
-            '/' . EED_Core_Rest_Api::ee_api_namespace . 'v' . $version . '/checkins/' . $checkin->ID()
146
+            '/'.EED_Core_Rest_Api::ee_api_namespace.'v'.$version.'/checkins/'.$checkin->ID()
147 147
         );
148 148
         $get_request->set_url_params(['id' => $checkin->ID()]);
149 149
         return Read::handleRequestGetOne($get_request, $version, 'Checkin');
Please login to merge, or discard this patch.
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -27,124 +27,124 @@
 block discarded – undo
27 27
  */
28 28
 class Checkin extends Base
29 29
 {
30
-    /**
31
-     * @param WP_REST_Request $request
32
-     * @param string          $version
33
-     * @return WP_Error|WP_REST_Response
34
-     * @throws EE_Error
35
-     * @throws ReflectionException
36
-     */
37
-    public static function handleRequestToggleCheckin(WP_REST_Request $request, $version)
38
-    {
39
-        $controller = new Checkin();
40
-        return $controller->createCheckinCheckoutObject($request, $version);
41
-    }
30
+	/**
31
+	 * @param WP_REST_Request $request
32
+	 * @param string          $version
33
+	 * @return WP_Error|WP_REST_Response
34
+	 * @throws EE_Error
35
+	 * @throws ReflectionException
36
+	 */
37
+	public static function handleRequestToggleCheckin(WP_REST_Request $request, $version)
38
+	{
39
+		$controller = new Checkin();
40
+		return $controller->createCheckinCheckoutObject($request, $version);
41
+	}
42 42
 
43 43
 
44
-    /**
45
-     * Toggles whether the user is checked in or not.
46
-     *
47
-     * @param WP_REST_Request $request
48
-     * @param string          $version
49
-     * @return WP_Error|WP_REST_Response
50
-     * @throws EE_Error
51
-     * @throws ReflectionException
52
-     */
53
-    protected function createCheckinCheckoutObject(WP_REST_Request $request, $version)
54
-    {
55
-        $reg_id = $request->get_param('REG_ID');
56
-        $dtt_id = $request->get_param('DTT_ID');
57
-        $force  = $request->get_param('force');
58
-        if ($force == 'true') {
59
-            $force = true;
60
-        } else {
61
-            $force = false;
62
-        }
63
-        $reg = EEM_Registration::instance()->get_one_by_ID($reg_id);
64
-        if (! $reg instanceof EE_Registration) {
65
-            return $this->sendResponse(
66
-                new WP_Error(
67
-                    'rest_registration_toggle_checkin_invalid_id',
68
-                    sprintf(
69
-                        esc_html__(
70
-                            'You cannot checkin registration with ID %1$s because it doesn\'t exist.',
71
-                            'event_espresso'
72
-                        ),
73
-                        $reg_id
74
-                    ),
75
-                    ['status' => 422]
76
-                )
77
-            );
78
-        }
79
-        if (! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) {
80
-            return $this->sendResponse(
81
-                new WP_Error(
82
-                    'rest_user_cannot_toggle_checkin',
83
-                    sprintf(
84
-                        esc_html__('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'),
85
-                        $reg_id
86
-                    ),
87
-                    ['status' => 403]
88
-                )
89
-            );
90
-        }
91
-        $success = $reg->toggle_checkin_status($dtt_id, ! $force);
92
-        if ($success === false) {
93
-            // check if we know they can't check in because they're not approved and we aren't forcing
94
-            if (! $reg->is_approved() && ! $force) {
95
-                // rely on EE_Error::add_error messages to have been added to give more data about why it failed
96
-                return $this->sendResponse(
97
-                    new WP_Error(
98
-                        'rest_toggle_checkin_failed',
99
-                        esc_html__(
100
-                        // @codingStandardsIgnoreStart
101
-                            'Registration check-in failed because the registration is not approved. You may attempt to force checking in though.',
102
-                            // @codingStandardsIgnoreEnd
103
-                            'event_espresso'
104
-                        )
105
-                    )
106
-                );
107
-            }
108
-            return $this->sendResponse(
109
-                new WP_Error(
110
-                    'rest_toggle_checkin_failed_not_forceable',
111
-                    esc_html__('Registration checkin failed. Please see additional error data.', 'event_espresso')
112
-                )
113
-            );
114
-        }
115
-        $checkin = EEM_Checkin::instance()->get_one(
116
-            [
117
-                [
118
-                    'REG_ID' => $reg_id,
119
-                    'DTT_ID' => $dtt_id,
120
-                ],
121
-                'order_by' => [
122
-                    'CHK_timestamp' => 'DESC',
123
-                ],
124
-            ]
125
-        );
126
-        if (! $checkin instanceof EE_Checkin) {
127
-            return $this->sendResponse(
128
-                new WP_Error(
129
-                    'rest_toggle_checkin_error',
130
-                    sprintf(
131
-                        esc_html__(
132
-                        // @codingStandardsIgnoreStart
133
-                            'Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.',
134
-                            // @codingStandardsIgnoreEnd
135
-                            'event_espresso'
136
-                        ),
137
-                        $reg_id,
138
-                        $dtt_id
139
-                    )
140
-                )
141
-            );
142
-        }
143
-        $get_request = new WP_REST_Request(
144
-            'GET',
145
-            '/' . EED_Core_Rest_Api::ee_api_namespace . 'v' . $version . '/checkins/' . $checkin->ID()
146
-        );
147
-        $get_request->set_url_params(['id' => $checkin->ID()]);
148
-        return Read::handleRequestGetOne($get_request, $version, 'Checkin');
149
-    }
44
+	/**
45
+	 * Toggles whether the user is checked in or not.
46
+	 *
47
+	 * @param WP_REST_Request $request
48
+	 * @param string          $version
49
+	 * @return WP_Error|WP_REST_Response
50
+	 * @throws EE_Error
51
+	 * @throws ReflectionException
52
+	 */
53
+	protected function createCheckinCheckoutObject(WP_REST_Request $request, $version)
54
+	{
55
+		$reg_id = $request->get_param('REG_ID');
56
+		$dtt_id = $request->get_param('DTT_ID');
57
+		$force  = $request->get_param('force');
58
+		if ($force == 'true') {
59
+			$force = true;
60
+		} else {
61
+			$force = false;
62
+		}
63
+		$reg = EEM_Registration::instance()->get_one_by_ID($reg_id);
64
+		if (! $reg instanceof EE_Registration) {
65
+			return $this->sendResponse(
66
+				new WP_Error(
67
+					'rest_registration_toggle_checkin_invalid_id',
68
+					sprintf(
69
+						esc_html__(
70
+							'You cannot checkin registration with ID %1$s because it doesn\'t exist.',
71
+							'event_espresso'
72
+						),
73
+						$reg_id
74
+					),
75
+					['status' => 422]
76
+				)
77
+			);
78
+		}
79
+		if (! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) {
80
+			return $this->sendResponse(
81
+				new WP_Error(
82
+					'rest_user_cannot_toggle_checkin',
83
+					sprintf(
84
+						esc_html__('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'),
85
+						$reg_id
86
+					),
87
+					['status' => 403]
88
+				)
89
+			);
90
+		}
91
+		$success = $reg->toggle_checkin_status($dtt_id, ! $force);
92
+		if ($success === false) {
93
+			// check if we know they can't check in because they're not approved and we aren't forcing
94
+			if (! $reg->is_approved() && ! $force) {
95
+				// rely on EE_Error::add_error messages to have been added to give more data about why it failed
96
+				return $this->sendResponse(
97
+					new WP_Error(
98
+						'rest_toggle_checkin_failed',
99
+						esc_html__(
100
+						// @codingStandardsIgnoreStart
101
+							'Registration check-in failed because the registration is not approved. You may attempt to force checking in though.',
102
+							// @codingStandardsIgnoreEnd
103
+							'event_espresso'
104
+						)
105
+					)
106
+				);
107
+			}
108
+			return $this->sendResponse(
109
+				new WP_Error(
110
+					'rest_toggle_checkin_failed_not_forceable',
111
+					esc_html__('Registration checkin failed. Please see additional error data.', 'event_espresso')
112
+				)
113
+			);
114
+		}
115
+		$checkin = EEM_Checkin::instance()->get_one(
116
+			[
117
+				[
118
+					'REG_ID' => $reg_id,
119
+					'DTT_ID' => $dtt_id,
120
+				],
121
+				'order_by' => [
122
+					'CHK_timestamp' => 'DESC',
123
+				],
124
+			]
125
+		);
126
+		if (! $checkin instanceof EE_Checkin) {
127
+			return $this->sendResponse(
128
+				new WP_Error(
129
+					'rest_toggle_checkin_error',
130
+					sprintf(
131
+						esc_html__(
132
+						// @codingStandardsIgnoreStart
133
+							'Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.',
134
+							// @codingStandardsIgnoreEnd
135
+							'event_espresso'
136
+						),
137
+						$reg_id,
138
+						$dtt_id
139
+					)
140
+				)
141
+			);
142
+		}
143
+		$get_request = new WP_REST_Request(
144
+			'GET',
145
+			'/' . EED_Core_Rest_Api::ee_api_namespace . 'v' . $version . '/checkins/' . $checkin->ID()
146
+		);
147
+		$get_request->set_url_params(['id' => $checkin->ID()]);
148
+		return Read::handleRequestGetOne($get_request, $version, 'Checkin');
149
+	}
150 150
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Event.model.php 2 patches
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
             'WP_User'                => new EE_Belongs_To_Relation(),
279 279
         );
280 280
         // this model is generally available for reading
281
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
281
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
282 282
         $this->model_chain_to_password = '';
283 283
         parent::__construct($timezone);
284 284
     }
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
      */
372 372
     public function get_all_event_question_groups($EVT_ID = 0)
373 373
     {
374
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
374
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
375 375
             EE_Error::add_error(
376 376
                 esc_html__(
377 377
                     'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
      */
406 406
     public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
407 407
     {
408
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
408
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
409 409
             EE_Error::add_error(
410 410
                 esc_html__(
411 411
                     // @codingStandardsIgnoreStart
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
      */
449 449
     public function get_question_groups_for_event($EVT_ID, EE_Registration $registration)
450 450
     {
451
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
451
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
452 452
             EE_Error::add_error(
453 453
                 esc_html__(
454 454
                     'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
@@ -867,11 +867,11 @@  discard block
 block discarded – undo
867 867
         $questions = array();
868 868
         // get all question groups for event
869 869
         $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
870
-        if (! empty($qgs)) {
870
+        if ( ! empty($qgs)) {
871 871
             foreach ($qgs as $qg) {
872 872
                 $qsts = $qg->questions();
873
-                $questions[ $qg->ID() ] = $qg->model_field_array();
874
-                $questions[ $qg->ID() ]['QSG_questions'] = array();
873
+                $questions[$qg->ID()] = $qg->model_field_array();
874
+                $questions[$qg->ID()]['QSG_questions'] = array();
875 875
                 foreach ($qsts as $qst) {
876 876
                     if ($qst->is_system_question()) {
877 877
                         continue;
@@ -885,26 +885,26 @@  discard block
 block discarded – undo
885 885
                     $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
886 886
                     $qst_name = $qstn_id = $qst->ID();
887 887
                     $ans_id = $answer->ID();
888
-                    $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
888
+                    $qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']';
889 889
                     $input_name = '';
890 890
                     $input_id = sanitize_key($qst->display_text());
891 891
                     $input_class = '';
892
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array();
893
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn'
892
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array();
893
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'
894 894
                                                                                            . $input_name
895 895
                                                                                            . $qst_name;
896
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id;
897
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
898
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array();
899
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst;
900
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer;
896
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id;
897
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class;
898
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array();
899
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst;
900
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer;
901 901
                     // leave responses as-is, don't convert stuff into html entities please!
902
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
902
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false;
903 903
                     if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
904 904
                         $QSOs = $qst->options(true, $answer->value());
905 905
                         if (is_array($QSOs)) {
906 906
                             foreach ($QSOs as $QSO_ID => $QSO) {
907
-                                $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array();
907
+                                $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array();
908 908
                             }
909 909
                         }
910 910
                     }
Please login to merge, or discard this patch.
Indentation   +951 added lines, -951 removed lines patch added patch discarded remove patch
@@ -14,955 +14,955 @@
 block discarded – undo
14 14
  */
15 15
 class EEM_Event extends EEM_CPT_Base
16 16
 {
17
-    /**
18
-     * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
19
-     * event
20
-     */
21
-    const sold_out = 'sold_out';
22
-
23
-    /**
24
-     * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
25
-     * date)
26
-     */
27
-    const postponed = 'postponed';
28
-
29
-    /**
30
-     * constant used by status(), indicating that the event will no longer occur
31
-     */
32
-    const cancelled = 'cancelled';
33
-
34
-
35
-    /**
36
-     * @var string
37
-     */
38
-    protected static $_default_reg_status;
39
-
40
-
41
-    /**
42
-     * This is the default for the additional limit field.
43
-     * @var int
44
-     */
45
-    protected static $_default_additional_limit = 10;
46
-
47
-
48
-    /**
49
-     * private instance of the Event object
50
-     *
51
-     * @var EEM_Event
52
-     */
53
-    protected static $_instance;
54
-
55
-
56
-
57
-
58
-    /**
59
-     * Adds a relationship to Term_Taxonomy for each CPT_Base
60
-     *
61
-     * @param string $timezone
62
-     * @throws \EE_Error
63
-     */
64
-    protected function __construct($timezone = null)
65
-    {
66
-        EE_Registry::instance()->load_model('Registration');
67
-        $this->singular_item = esc_html__('Event', 'event_espresso');
68
-        $this->plural_item = esc_html__('Events', 'event_espresso');
69
-        // to remove Cancelled events from the frontend, copy the following filter to your functions.php file
70
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
71
-        // to remove Postponed events from the frontend, copy the following filter to your functions.php file
72
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
73
-        // to remove Sold Out events from the frontend, copy the following filter to your functions.php file
74
-        //  add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
75
-        $this->_custom_stati = apply_filters(
76
-            'AFEE__EEM_Event__construct___custom_stati',
77
-            array(
78
-                EEM_Event::cancelled => array(
79
-                    'label'  => esc_html__('Cancelled', 'event_espresso'),
80
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
81
-                ),
82
-                EEM_Event::postponed => array(
83
-                    'label'  => esc_html__('Postponed', 'event_espresso'),
84
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
85
-                ),
86
-                EEM_Event::sold_out  => array(
87
-                    'label'  => esc_html__('Sold Out', 'event_espresso'),
88
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
89
-                ),
90
-            )
91
-        );
92
-        self::$_default_reg_status = EE_Registry::instance()->CFG->registration->default_STS_ID
93
-            ?: EEM_Registration::status_id_pending_payment;
94
-        $this->_tables = array(
95
-            'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
96
-            'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
97
-        );
98
-        $this->_fields = array(
99
-            'Event_CPT'  => array(
100
-                'EVT_ID'         => new EE_Primary_Key_Int_Field(
101
-                    'ID',
102
-                    esc_html__('Post ID for Event', 'event_espresso')
103
-                ),
104
-                'EVT_name'       => new EE_Plain_Text_Field(
105
-                    'post_title',
106
-                    esc_html__('Event Name', 'event_espresso'),
107
-                    false,
108
-                    ''
109
-                ),
110
-                'EVT_desc'       => new EE_Post_Content_Field(
111
-                    'post_content',
112
-                    esc_html__('Event Description', 'event_espresso'),
113
-                    false,
114
-                    ''
115
-                ),
116
-                'EVT_slug'       => new EE_Slug_Field(
117
-                    'post_name',
118
-                    esc_html__('Event Slug', 'event_espresso'),
119
-                    false,
120
-                    ''
121
-                ),
122
-                'EVT_created'    => new EE_Datetime_Field(
123
-                    'post_date',
124
-                    esc_html__('Date/Time Event Created', 'event_espresso'),
125
-                    false,
126
-                    EE_Datetime_Field::now
127
-                ),
128
-                'EVT_short_desc' => new EE_Simple_HTML_Field(
129
-                    'post_excerpt',
130
-                    esc_html__('Event Short Description', 'event_espresso'),
131
-                    false,
132
-                    ''
133
-                ),
134
-                'EVT_modified'   => new EE_Datetime_Field(
135
-                    'post_modified',
136
-                    esc_html__('Date/Time Event Modified', 'event_espresso'),
137
-                    false,
138
-                    EE_Datetime_Field::now
139
-                ),
140
-                'EVT_wp_user'    => new EE_WP_User_Field(
141
-                    'post_author',
142
-                    esc_html__('Event Creator ID', 'event_espresso'),
143
-                    false
144
-                ),
145
-                'parent'         => new EE_Integer_Field(
146
-                    'post_parent',
147
-                    esc_html__('Event Parent ID', 'event_espresso'),
148
-                    false,
149
-                    0
150
-                ),
151
-                'EVT_order'      => new EE_Integer_Field(
152
-                    'menu_order',
153
-                    esc_html__('Event Menu Order', 'event_espresso'),
154
-                    false,
155
-                    1
156
-                ),
157
-                'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
158
-                // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
159
-                'status'         => new EE_WP_Post_Status_Field(
160
-                    'post_status',
161
-                    esc_html__('Event Status', 'event_espresso'),
162
-                    false,
163
-                    'draft',
164
-                    $this->_custom_stati
165
-                ),
166
-                'password' => new EE_Password_Field(
167
-                    'post_password',
168
-                    esc_html__('Password', 'event_espresso'),
169
-                    false,
170
-                    '',
171
-                    array(
172
-                        'EVT_desc',
173
-                        'EVT_short_desc',
174
-                        'EVT_display_desc',
175
-                        'EVT_display_ticket_selector',
176
-                        'EVT_visible_on',
177
-                        'EVT_additional_limit',
178
-                        'EVT_default_registration_status',
179
-                        'EVT_member_only',
180
-                        'EVT_phone',
181
-                        'EVT_allow_overflow',
182
-                        'EVT_timezone_string',
183
-                        'EVT_external_URL',
184
-                        'EVT_donations'
185
-                    )
186
-                )
187
-            ),
188
-            'Event_Meta' => array(
189
-                'EVTM_ID'                         => new EE_DB_Only_Float_Field(
190
-                    'EVTM_ID',
191
-                    esc_html__('Event Meta Row ID', 'event_espresso'),
192
-                    false
193
-                ),
194
-                'EVT_ID_fk'                       => new EE_DB_Only_Int_Field(
195
-                    'EVT_ID',
196
-                    esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'),
197
-                    false
198
-                ),
199
-                'EVT_display_desc'                => new EE_Boolean_Field(
200
-                    'EVT_display_desc',
201
-                    esc_html__('Display Description Flag', 'event_espresso'),
202
-                    false,
203
-                    true
204
-                ),
205
-                'EVT_display_ticket_selector'     => new EE_Boolean_Field(
206
-                    'EVT_display_ticket_selector',
207
-                    esc_html__('Display Ticket Selector Flag', 'event_espresso'),
208
-                    false,
209
-                    true
210
-                ),
211
-                'EVT_visible_on'                  => new EE_Datetime_Field(
212
-                    'EVT_visible_on',
213
-                    esc_html__('Event Visible Date', 'event_espresso'),
214
-                    true,
215
-                    EE_Datetime_Field::now
216
-                ),
217
-                'EVT_additional_limit'            => new EE_Integer_Field(
218
-                    'EVT_additional_limit',
219
-                    esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
220
-                    true,
221
-                    self::$_default_additional_limit
222
-                ),
223
-                'EVT_default_registration_status' => new EE_Enum_Text_Field(
224
-                    'EVT_default_registration_status',
225
-                    esc_html__('Default Registration Status on this Event', 'event_espresso'),
226
-                    false,
227
-                    EEM_Event::$_default_reg_status,
228
-                    EEM_Registration::reg_status_array()
229
-                ),
230
-                'EVT_member_only'                 => new EE_Boolean_Field(
231
-                    'EVT_member_only',
232
-                    esc_html__('Member-Only Event Flag', 'event_espresso'),
233
-                    false,
234
-                    false
235
-                ),
236
-                'EVT_phone'                       => new EE_Plain_Text_Field(
237
-                    'EVT_phone',
238
-                    esc_html__('Event Phone Number', 'event_espresso'),
239
-                    false,
240
-                    ''
241
-                ),
242
-                'EVT_allow_overflow'              => new EE_Boolean_Field(
243
-                    'EVT_allow_overflow',
244
-                    esc_html__('Allow Overflow on Event', 'event_espresso'),
245
-                    false,
246
-                    false
247
-                ),
248
-                'EVT_timezone_string'             => new EE_Plain_Text_Field(
249
-                    'EVT_timezone_string',
250
-                    esc_html__('Timezone (name) for Event times', 'event_espresso'),
251
-                    false,
252
-                    ''
253
-                ),
254
-                'EVT_external_URL'                => new EE_Plain_Text_Field(
255
-                    'EVT_external_URL',
256
-                    esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'),
257
-                    true
258
-                ),
259
-                'EVT_donations'                   => new EE_Boolean_Field(
260
-                    'EVT_donations',
261
-                    esc_html__('Accept Donations?', 'event_espresso'),
262
-                    false,
263
-                    false
264
-                ),
265
-            ),
266
-        );
267
-        $this->_model_relations = array(
268
-            'Registration'           => new EE_Has_Many_Relation(),
269
-            'Datetime'               => new EE_Has_Many_Relation(),
270
-            'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
271
-            'Event_Question_Group'   => new EE_Has_Many_Relation(),
272
-            'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
273
-            'Term_Relationship'      => new EE_Has_Many_Relation(),
274
-            'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
275
-            'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
276
-            'Attendee'               => new EE_HABTM_Relation('Registration'),
277
-            'WP_User'                => new EE_Belongs_To_Relation(),
278
-        );
279
-        // this model is generally available for reading
280
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
281
-        $this->model_chain_to_password = '';
282
-        parent::__construct($timezone);
283
-    }
284
-
285
-
286
-
287
-    /**
288
-     * @param string $default_reg_status
289
-     */
290
-    public static function set_default_reg_status($default_reg_status)
291
-    {
292
-        self::$_default_reg_status = $default_reg_status;
293
-        // if EEM_Event has already been instantiated,
294
-        // then we need to reset the `EVT_default_reg_status` field to use the new default.
295
-        if (self::$_instance instanceof EEM_Event) {
296
-            $default_reg_status = new EE_Enum_Text_Field(
297
-                'EVT_default_registration_status',
298
-                esc_html__('Default Registration Status on this Event', 'event_espresso'),
299
-                false,
300
-                $default_reg_status,
301
-                EEM_Registration::reg_status_array()
302
-            );
303
-            $default_reg_status->_construct_finalize(
304
-                'Event_Meta',
305
-                'EVT_default_registration_status',
306
-                'EEM_Event'
307
-            );
308
-            self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
309
-        }
310
-    }
311
-
312
-
313
-    /**
314
-     * Used to override the default for the additional limit field.
315
-     * @param $additional_limit
316
-     */
317
-    public static function set_default_additional_limit($additional_limit)
318
-    {
319
-        self::$_default_additional_limit = (int) $additional_limit;
320
-        if (self::$_instance instanceof EEM_Event) {
321
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
322
-                'EVT_additional_limit',
323
-                esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
324
-                true,
325
-                self::$_default_additional_limit
326
-            );
327
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
328
-                'Event_Meta',
329
-                'EVT_additional_limit',
330
-                'EEM_Event'
331
-            );
332
-        }
333
-    }
334
-
335
-
336
-    /**
337
-     * Return what is currently set as the default additional limit for the event.
338
-     * @return int
339
-     */
340
-    public static function get_default_additional_limit()
341
-    {
342
-        return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
343
-    }
344
-
345
-
346
-    /**
347
-     * get_question_groups
348
-     *
349
-     * @return array
350
-     * @throws \EE_Error
351
-     */
352
-    public function get_all_question_groups()
353
-    {
354
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
355
-            array(
356
-                array('QSG_deleted' => false),
357
-                'order_by' => array('QSG_order' => 'ASC'),
358
-            )
359
-        );
360
-    }
361
-
362
-
363
-
364
-    /**
365
-     * get_question_groups
366
-     *
367
-     * @param int $EVT_ID
368
-     * @return array|bool
369
-     * @throws \EE_Error
370
-     */
371
-    public function get_all_event_question_groups($EVT_ID = 0)
372
-    {
373
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
374
-            EE_Error::add_error(
375
-                esc_html__(
376
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
377
-                    'event_espresso'
378
-                ),
379
-                __FILE__,
380
-                __FUNCTION__,
381
-                __LINE__
382
-            );
383
-            return false;
384
-        }
385
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
386
-            array(
387
-                array('EVT_ID' => $EVT_ID),
388
-            )
389
-        );
390
-    }
391
-
392
-
393
-    /**
394
-     * get_question_groups
395
-     *
396
-     * @param int $EVT_ID
397
-     * @param boolean $for_primary_attendee
398
-     * @return array|bool
399
-     * @throws EE_Error
400
-     * @throws InvalidArgumentException
401
-     * @throws ReflectionException
402
-     * @throws InvalidDataTypeException
403
-     * @throws InvalidInterfaceException
404
-     */
405
-    public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
406
-    {
407
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
408
-            EE_Error::add_error(
409
-                esc_html__(
410
-                    // @codingStandardsIgnoreStart
411
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
412
-                    // @codingStandardsIgnoreEnd
413
-                    'event_espresso'
414
-                ),
415
-                __FILE__,
416
-                __FUNCTION__,
417
-                __LINE__
418
-            );
419
-            return false;
420
-        }
421
-        $query_params = [
422
-            [
423
-                'EVT_ID' => $EVT_ID,
424
-                EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true
425
-            ]
426
-        ];
427
-        if ($for_primary_attendee) {
428
-            $query_params[0]['EQG_primary'] = true;
429
-        } else {
430
-            $query_params[0]['EQG_additional'] = true;
431
-        }
432
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params);
433
-    }
434
-
435
-
436
-    /**
437
-     * get_question_groups
438
-     *
439
-     * @param int $EVT_ID
440
-     * @param EE_Registration $registration
441
-     * @return array
442
-     * @throws EE_Error
443
-     * @throws InvalidArgumentException
444
-     * @throws InvalidDataTypeException
445
-     * @throws InvalidInterfaceException
446
-     * @throws ReflectionException
447
-     */
448
-    public function get_question_groups_for_event($EVT_ID, EE_Registration $registration)
449
-    {
450
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
451
-            EE_Error::add_error(
452
-                esc_html__(
453
-                    'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
454
-                    'event_espresso'
455
-                ),
456
-                __FILE__,
457
-                __FUNCTION__,
458
-                __LINE__
459
-            );
460
-            return [];
461
-        }
462
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
463
-            [
464
-                [
465
-                    'Event_Question_Group.EVT_ID'      => $EVT_ID,
466
-                    'Event_Question_Group.'
467
-                        . EEM_Event_Question_Group::instance()->fieldNameForContext(
468
-                            $registration->is_primary_registrant()
469
-                        ) => true
470
-                ],
471
-                'order_by' => ['QSG_order' => 'ASC'],
472
-            ]
473
-        );
474
-    }
475
-
476
-
477
-
478
-    /**
479
-     * get_question_target_db_column
480
-     *
481
-     * @param string $QSG_IDs csv list of $QSG IDs
482
-     * @return array|bool
483
-     * @throws \EE_Error
484
-     */
485
-    public function get_questions_in_groups($QSG_IDs = '')
486
-    {
487
-        if (empty($QSG_IDs)) {
488
-            EE_Error::add_error(
489
-                esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
490
-                __FILE__,
491
-                __FUNCTION__,
492
-                __LINE__
493
-            );
494
-            return false;
495
-        }
496
-        return EE_Registry::instance()->load_model('Question')->get_all(
497
-            array(
498
-                array(
499
-                    'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
500
-                    'QST_deleted'           => false,
501
-                    'QST_admin_only'        => is_admin(),
502
-                ),
503
-                'order_by' => 'QST_order',
504
-            )
505
-        );
506
-    }
507
-
508
-
509
-
510
-    /**
511
-     * get_options_for_question
512
-     *
513
-     * @param string $QST_IDs csv list of $QST IDs
514
-     * @return array|bool
515
-     * @throws \EE_Error
516
-     */
517
-    public function get_options_for_question($QST_IDs)
518
-    {
519
-        if (empty($QST_IDs)) {
520
-            EE_Error::add_error(
521
-                esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
522
-                __FILE__,
523
-                __FUNCTION__,
524
-                __LINE__
525
-            );
526
-            return false;
527
-        }
528
-        return EE_Registry::instance()->load_model('Question_Option')->get_all(
529
-            array(
530
-                array(
531
-                    'Question.QST_ID' => array('IN', $QST_IDs),
532
-                    'QSO_deleted'     => false,
533
-                ),
534
-                'order_by' => 'QSO_ID',
535
-            )
536
-        );
537
-    }
538
-
539
-
540
-
541
-
542
-
543
-
544
-
545
-    /**
546
-     * Gets all events that are published
547
-     * and have event start time earlier than now and an event end time later than now
548
-     *
549
-     * @param  array $query_params An array of query params to further filter on
550
-     *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
551
-     * @param bool   $count        whether to return the count or not (default FALSE)
552
-     * @return EE_Event[]|int
553
-     * @throws \EE_Error
554
-     */
555
-    public function get_active_events($query_params, $count = false)
556
-    {
557
-        if (array_key_exists(0, $query_params)) {
558
-            $where_params = $query_params[0];
559
-            unset($query_params[0]);
560
-        } else {
561
-            $where_params = array();
562
-        }
563
-        // if we have count make sure we don't include group by
564
-        if ($count && isset($query_params['group_by'])) {
565
-            unset($query_params['group_by']);
566
-        }
567
-        // let's add specific query_params for active_events
568
-        // keep in mind this will override any sent status in the query AND any date queries.
569
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
570
-        // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
571
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
572
-            $where_params['Datetime.DTT_EVT_start******'] = array(
573
-                '<',
574
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
575
-            );
576
-        } else {
577
-            $where_params['Datetime.DTT_EVT_start'] = array(
578
-                '<',
579
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
580
-            );
581
-        }
582
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
583
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
584
-                '>',
585
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
586
-            );
587
-        } else {
588
-            $where_params['Datetime.DTT_EVT_end'] = array(
589
-                '>',
590
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
591
-            );
592
-        }
593
-        $query_params[0] = $where_params;
594
-        // don't use $query_params with count()
595
-        // because we don't want to include additional query clauses like "GROUP BY"
596
-        return $count
597
-            ? $this->count(array($where_params), 'EVT_ID', true)
598
-            : $this->get_all($query_params);
599
-    }
600
-
601
-
602
-
603
-    /**
604
-     * get all events that are published and have an event start time later than now
605
-     *
606
-     * @param  array $query_params An array of query params to further filter on
607
-     *                             (Note that status and DTT_EVT_start will be overridden)
608
-     * @param bool   $count        whether to return the count or not (default FALSE)
609
-     * @return EE_Event[]|int
610
-     * @throws \EE_Error
611
-     */
612
-    public function get_upcoming_events($query_params, $count = false)
613
-    {
614
-        if (array_key_exists(0, $query_params)) {
615
-            $where_params = $query_params[0];
616
-            unset($query_params[0]);
617
-        } else {
618
-            $where_params = array();
619
-        }
620
-        // if we have count make sure we don't include group by
621
-        if ($count && isset($query_params['group_by'])) {
622
-            unset($query_params['group_by']);
623
-        }
624
-        // let's add specific query_params for active_events
625
-        // keep in mind this will override any sent status in the query AND any date queries.
626
-        // we need to pull events with a status of publish and sold_out
627
-        $event_status = array('publish', EEM_Event::sold_out);
628
-        // check if the user can read private events and if so add the 'private status to the were params'
629
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) {
630
-            $event_status[] = 'private';
631
-        }
632
-        $where_params['status'] = array('IN', $event_status);
633
-        // if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
634
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
635
-            $where_params['Datetime.DTT_EVT_start*****'] = array(
636
-                '>',
637
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
638
-            );
639
-        } else {
640
-            $where_params['Datetime.DTT_EVT_start'] = array(
641
-                '>',
642
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
643
-            );
644
-        }
645
-        $query_params[0] = $where_params;
646
-        // don't use $query_params with count()
647
-        // because we don't want to include additional query clauses like "GROUP BY"
648
-        return $count
649
-            ? $this->count(array($where_params), 'EVT_ID', true)
650
-            : $this->get_all($query_params);
651
-    }
652
-
653
-
654
-
655
-    /**
656
-     * Gets all events that are published
657
-     * and have an event end time later than now
658
-     *
659
-     * @param  array $query_params An array of query params to further filter on
660
-     *                             (note that status and DTT_EVT_end will be overridden)
661
-     * @param bool   $count        whether to return the count or not (default FALSE)
662
-     * @return EE_Event[]|int
663
-     * @throws \EE_Error
664
-     */
665
-    public function get_active_and_upcoming_events($query_params, $count = false)
666
-    {
667
-        if (array_key_exists(0, $query_params)) {
668
-            $where_params = $query_params[0];
669
-            unset($query_params[0]);
670
-        } else {
671
-            $where_params = array();
672
-        }
673
-        // if we have count make sure we don't include group by
674
-        if ($count && isset($query_params['group_by'])) {
675
-            unset($query_params['group_by']);
676
-        }
677
-        // let's add specific query_params for active_events
678
-        // keep in mind this will override any sent status in the query AND any date queries.
679
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
680
-        // add where params for DTT_EVT_end
681
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
682
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
683
-                '>',
684
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
685
-            );
686
-        } else {
687
-            $where_params['Datetime.DTT_EVT_end'] = array(
688
-                '>',
689
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
690
-            );
691
-        }
692
-        $query_params[0] = $where_params;
693
-        // don't use $query_params with count()
694
-        // because we don't want to include additional query clauses like "GROUP BY"
695
-        return $count
696
-            ? $this->count(array($where_params), 'EVT_ID', true)
697
-            : $this->get_all($query_params);
698
-    }
699
-
700
-
701
-
702
-    /**
703
-     * This only returns events that are expired.
704
-     * They may still be published but all their datetimes have expired.
705
-     *
706
-     * @param  array $query_params An array of query params to further filter on
707
-     *                             (note that status and DTT_EVT_end will be overridden)
708
-     * @param bool   $count        whether to return the count or not (default FALSE)
709
-     * @return EE_Event[]|int
710
-     * @throws \EE_Error
711
-     */
712
-    public function get_expired_events($query_params, $count = false)
713
-    {
714
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
715
-        // if we have count make sure we don't include group by
716
-        if ($count && isset($query_params['group_by'])) {
717
-            unset($query_params['group_by']);
718
-        }
719
-        // let's add specific query_params for active_events
720
-        // keep in mind this will override any sent status in the query AND any date queries.
721
-        if (isset($where_params['status'])) {
722
-            unset($where_params['status']);
723
-        }
724
-        $exclude_query = $query_params;
725
-        if (isset($exclude_query[0])) {
726
-            unset($exclude_query[0]);
727
-        }
728
-        $exclude_query[0] = array(
729
-            'Datetime.DTT_EVT_end' => array(
730
-                '>',
731
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
732
-            ),
733
-        );
734
-        // first get all events that have datetimes where its not expired.
735
-        $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
736
-        $event_ids = array_keys($event_ids);
737
-        // if we have any additional query_params, let's add them to the 'AND' condition
738
-        $and_condition = array(
739
-            'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
740
-            'EVT_ID'               => array('NOT IN', $event_ids),
741
-        );
742
-        if (isset($where_params['OR'])) {
743
-            $and_condition['OR'] = $where_params['OR'];
744
-            unset($where_params['OR']);
745
-        }
746
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
747
-            $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
748
-            unset($where_params['Datetime.DTT_EVT_end']);
749
-        }
750
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
751
-            $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
752
-            unset($where_params['Datetime.DTT_EVT_start']);
753
-        }
754
-        // merge remaining $where params with the and conditions.
755
-        $where_params['AND'] = array_merge($and_condition, $where_params);
756
-        $query_params[0] = $where_params;
757
-        // don't use $query_params with count()
758
-        // because we don't want to include additional query clauses like "GROUP BY"
759
-        return $count
760
-            ? $this->count(array($where_params), 'EVT_ID', true)
761
-            : $this->get_all($query_params);
762
-    }
763
-
764
-
765
-
766
-    /**
767
-     * This basically just returns the events that do not have the publish status.
768
-     *
769
-     * @param  array   $query_params An array of query params to further filter on
770
-     *                               (note that status will be overwritten)
771
-     * @param  boolean $count        whether to return the count or not (default FALSE)
772
-     * @return EE_Event[]|int
773
-     * @throws \EE_Error
774
-     */
775
-    public function get_inactive_events($query_params, $count = false)
776
-    {
777
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
778
-        // let's add in specific query_params for inactive events.
779
-        if (isset($where_params['status'])) {
780
-            unset($where_params['status']);
781
-        }
782
-        // if we have count make sure we don't include group by
783
-        if ($count && isset($query_params['group_by'])) {
784
-            unset($query_params['group_by']);
785
-        }
786
-        // if we have any additional query_params, let's add them to the 'AND' condition
787
-        $where_params['AND']['status'] = array('!=', 'publish');
788
-        if (isset($where_params['OR'])) {
789
-            $where_params['AND']['OR'] = $where_params['OR'];
790
-            unset($where_params['OR']);
791
-        }
792
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
793
-            $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
794
-            unset($where_params['Datetime.DTT_EVT_end']);
795
-        }
796
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
797
-            $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
798
-            unset($where_params['Datetime.DTT_EVT_start']);
799
-        }
800
-        $query_params[0] = $where_params;
801
-        // don't use $query_params with count()
802
-        // because we don't want to include additional query clauses like "GROUP BY"
803
-        return $count
804
-            ? $this->count(array($where_params), 'EVT_ID', true)
805
-            : $this->get_all($query_params);
806
-    }
807
-
808
-
809
-
810
-    /**
811
-     * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
812
-     * because we don't want to override any existing global default prices but instead insert NEW prices that get
813
-     * attached to the event. See parent for param descriptions
814
-     *
815
-     * @param        $id_or_obj
816
-     * @param        $other_model_id_or_obj
817
-     * @param string $relationName
818
-     * @param array  $where_query
819
-     * @return EE_Base_Class
820
-     * @throws EE_Error
821
-     */
822
-    public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
823
-    {
824
-        if ($relationName === 'Price') {
825
-            // let's get the PRC object for the given ID to make sure that we aren't dealing with a default
826
-            $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
827
-            // if EVT_ID = 0, then this is a default
828
-            if ((int) $prc_chk->get('EVT_ID') === 0) {
829
-                // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
830
-                $prc_chk->set('PRC_ID', 0);
831
-            }
832
-            // run parent
833
-            return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
834
-        }
835
-        // otherwise carry on as normal
836
-        return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
837
-    }
838
-
839
-
840
-
841
-    /******************** DEPRECATED METHODS ********************/
842
-
843
-
844
-
845
-    /**
846
-     * _get_question_target_db_column
847
-     *
848
-     * @deprecated as of 4.8.32.rc.001. Instead consider using
849
-     *             EE_Registration_Custom_Questions_Form located in
850
-     *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
851
-     * @access     public
852
-     * @param    EE_Registration $registration (so existing answers for registration are included)
853
-     * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
854
-     *                                         registration).
855
-     * @throws EE_Error
856
-     * @return    array
857
-     */
858
-    public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
859
-    {
860
-        if (empty($EVT_ID)) {
861
-            throw new EE_Error(esc_html__(
862
-                'An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
863
-                'event_espresso'
864
-            ));
865
-        }
866
-        $questions = array();
867
-        // get all question groups for event
868
-        $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
869
-        if (! empty($qgs)) {
870
-            foreach ($qgs as $qg) {
871
-                $qsts = $qg->questions();
872
-                $questions[ $qg->ID() ] = $qg->model_field_array();
873
-                $questions[ $qg->ID() ]['QSG_questions'] = array();
874
-                foreach ($qsts as $qst) {
875
-                    if ($qst->is_system_question()) {
876
-                        continue;
877
-                    }
878
-                    $answer = EEM_Answer::instance()->get_one(array(
879
-                        array(
880
-                            'QST_ID' => $qst->ID(),
881
-                            'REG_ID' => $registration->ID(),
882
-                        ),
883
-                    ));
884
-                    $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
885
-                    $qst_name = $qstn_id = $qst->ID();
886
-                    $ans_id = $answer->ID();
887
-                    $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
888
-                    $input_name = '';
889
-                    $input_id = sanitize_key($qst->display_text());
890
-                    $input_class = '';
891
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array();
892
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn'
893
-                                                                                           . $input_name
894
-                                                                                           . $qst_name;
895
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id;
896
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
897
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array();
898
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst;
899
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer;
900
-                    // leave responses as-is, don't convert stuff into html entities please!
901
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
902
-                    if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
903
-                        $QSOs = $qst->options(true, $answer->value());
904
-                        if (is_array($QSOs)) {
905
-                            foreach ($QSOs as $QSO_ID => $QSO) {
906
-                                $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array();
907
-                            }
908
-                        }
909
-                    }
910
-                }
911
-            }
912
-        }
913
-        return $questions;
914
-    }
915
-
916
-
917
-    /**
918
-     * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value
919
-     *                             or an stdClass where each property is the name of a column,
920
-     * @return EE_Base_Class
921
-     * @throws \EE_Error
922
-     */
923
-    public function instantiate_class_from_array_or_object($cols_n_values)
924
-    {
925
-        $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values);
926
-        if ($classInstance instanceof EE_Event) {
927
-            // events have their timezone defined in the DB, so use it immediately
928
-            $this->set_timezone($classInstance->get_timezone());
929
-        }
930
-        return $classInstance;
931
-    }
932
-
933
-
934
-    /**
935
-     * Deletes the model objects that meet the query params. Note: this method is overridden
936
-     * in EEM_Soft_Delete_Base so that soft-deleted model objects are instead only flagged
937
-     * as archived, not actually deleted
938
-     *
939
-     * @param array   $query_params   @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
940
-     * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
941
-     *                                that blocks it (ie, there' sno other data that depends on this data); if false,
942
-     *                                deletes regardless of other objects which may depend on it. Its generally
943
-     *                                advisable to always leave this as TRUE, otherwise you could easily corrupt your
944
-     *                                DB
945
-     * @return int                    number of rows deleted
946
-     * @throws EE_Error
947
-     */
948
-    public function delete_permanently($query_params, $allow_blocking = true)
949
-    {
950
-        $deleted = parent::delete_permanently($query_params, $allow_blocking);
951
-        if ($deleted) {
952
-            // get list of events with no prices
953
-            $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', []);
954
-            $where = isset($query_params[0]) ? $query_params[0] : [];
955
-            $where_event = isset($where['EVT_ID']) ? $where['EVT_ID'] : ['', ''];
956
-            $where_event_ids = isset($where_event[1]) ? $where_event[1] : '';
957
-            $event_ids = is_string($where_event_ids)
958
-                ? explode(',', $where_event_ids)
959
-                : (array) $where_event_ids;
960
-            array_walk($event_ids, 'trim');
961
-            $event_ids = array_filter($event_ids);
962
-            // remove events from list of events with no prices
963
-            $espresso_no_ticket_prices = array_diff($espresso_no_ticket_prices, $event_ids);
964
-            update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
965
-        }
966
-        return $deleted;
967
-    }
17
+	/**
18
+	 * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
19
+	 * event
20
+	 */
21
+	const sold_out = 'sold_out';
22
+
23
+	/**
24
+	 * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
25
+	 * date)
26
+	 */
27
+	const postponed = 'postponed';
28
+
29
+	/**
30
+	 * constant used by status(), indicating that the event will no longer occur
31
+	 */
32
+	const cancelled = 'cancelled';
33
+
34
+
35
+	/**
36
+	 * @var string
37
+	 */
38
+	protected static $_default_reg_status;
39
+
40
+
41
+	/**
42
+	 * This is the default for the additional limit field.
43
+	 * @var int
44
+	 */
45
+	protected static $_default_additional_limit = 10;
46
+
47
+
48
+	/**
49
+	 * private instance of the Event object
50
+	 *
51
+	 * @var EEM_Event
52
+	 */
53
+	protected static $_instance;
54
+
55
+
56
+
57
+
58
+	/**
59
+	 * Adds a relationship to Term_Taxonomy for each CPT_Base
60
+	 *
61
+	 * @param string $timezone
62
+	 * @throws \EE_Error
63
+	 */
64
+	protected function __construct($timezone = null)
65
+	{
66
+		EE_Registry::instance()->load_model('Registration');
67
+		$this->singular_item = esc_html__('Event', 'event_espresso');
68
+		$this->plural_item = esc_html__('Events', 'event_espresso');
69
+		// to remove Cancelled events from the frontend, copy the following filter to your functions.php file
70
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
71
+		// to remove Postponed events from the frontend, copy the following filter to your functions.php file
72
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
73
+		// to remove Sold Out events from the frontend, copy the following filter to your functions.php file
74
+		//  add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
75
+		$this->_custom_stati = apply_filters(
76
+			'AFEE__EEM_Event__construct___custom_stati',
77
+			array(
78
+				EEM_Event::cancelled => array(
79
+					'label'  => esc_html__('Cancelled', 'event_espresso'),
80
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
81
+				),
82
+				EEM_Event::postponed => array(
83
+					'label'  => esc_html__('Postponed', 'event_espresso'),
84
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
85
+				),
86
+				EEM_Event::sold_out  => array(
87
+					'label'  => esc_html__('Sold Out', 'event_espresso'),
88
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
89
+				),
90
+			)
91
+		);
92
+		self::$_default_reg_status = EE_Registry::instance()->CFG->registration->default_STS_ID
93
+			?: EEM_Registration::status_id_pending_payment;
94
+		$this->_tables = array(
95
+			'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
96
+			'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
97
+		);
98
+		$this->_fields = array(
99
+			'Event_CPT'  => array(
100
+				'EVT_ID'         => new EE_Primary_Key_Int_Field(
101
+					'ID',
102
+					esc_html__('Post ID for Event', 'event_espresso')
103
+				),
104
+				'EVT_name'       => new EE_Plain_Text_Field(
105
+					'post_title',
106
+					esc_html__('Event Name', 'event_espresso'),
107
+					false,
108
+					''
109
+				),
110
+				'EVT_desc'       => new EE_Post_Content_Field(
111
+					'post_content',
112
+					esc_html__('Event Description', 'event_espresso'),
113
+					false,
114
+					''
115
+				),
116
+				'EVT_slug'       => new EE_Slug_Field(
117
+					'post_name',
118
+					esc_html__('Event Slug', 'event_espresso'),
119
+					false,
120
+					''
121
+				),
122
+				'EVT_created'    => new EE_Datetime_Field(
123
+					'post_date',
124
+					esc_html__('Date/Time Event Created', 'event_espresso'),
125
+					false,
126
+					EE_Datetime_Field::now
127
+				),
128
+				'EVT_short_desc' => new EE_Simple_HTML_Field(
129
+					'post_excerpt',
130
+					esc_html__('Event Short Description', 'event_espresso'),
131
+					false,
132
+					''
133
+				),
134
+				'EVT_modified'   => new EE_Datetime_Field(
135
+					'post_modified',
136
+					esc_html__('Date/Time Event Modified', 'event_espresso'),
137
+					false,
138
+					EE_Datetime_Field::now
139
+				),
140
+				'EVT_wp_user'    => new EE_WP_User_Field(
141
+					'post_author',
142
+					esc_html__('Event Creator ID', 'event_espresso'),
143
+					false
144
+				),
145
+				'parent'         => new EE_Integer_Field(
146
+					'post_parent',
147
+					esc_html__('Event Parent ID', 'event_espresso'),
148
+					false,
149
+					0
150
+				),
151
+				'EVT_order'      => new EE_Integer_Field(
152
+					'menu_order',
153
+					esc_html__('Event Menu Order', 'event_espresso'),
154
+					false,
155
+					1
156
+				),
157
+				'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
158
+				// EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
159
+				'status'         => new EE_WP_Post_Status_Field(
160
+					'post_status',
161
+					esc_html__('Event Status', 'event_espresso'),
162
+					false,
163
+					'draft',
164
+					$this->_custom_stati
165
+				),
166
+				'password' => new EE_Password_Field(
167
+					'post_password',
168
+					esc_html__('Password', 'event_espresso'),
169
+					false,
170
+					'',
171
+					array(
172
+						'EVT_desc',
173
+						'EVT_short_desc',
174
+						'EVT_display_desc',
175
+						'EVT_display_ticket_selector',
176
+						'EVT_visible_on',
177
+						'EVT_additional_limit',
178
+						'EVT_default_registration_status',
179
+						'EVT_member_only',
180
+						'EVT_phone',
181
+						'EVT_allow_overflow',
182
+						'EVT_timezone_string',
183
+						'EVT_external_URL',
184
+						'EVT_donations'
185
+					)
186
+				)
187
+			),
188
+			'Event_Meta' => array(
189
+				'EVTM_ID'                         => new EE_DB_Only_Float_Field(
190
+					'EVTM_ID',
191
+					esc_html__('Event Meta Row ID', 'event_espresso'),
192
+					false
193
+				),
194
+				'EVT_ID_fk'                       => new EE_DB_Only_Int_Field(
195
+					'EVT_ID',
196
+					esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'),
197
+					false
198
+				),
199
+				'EVT_display_desc'                => new EE_Boolean_Field(
200
+					'EVT_display_desc',
201
+					esc_html__('Display Description Flag', 'event_espresso'),
202
+					false,
203
+					true
204
+				),
205
+				'EVT_display_ticket_selector'     => new EE_Boolean_Field(
206
+					'EVT_display_ticket_selector',
207
+					esc_html__('Display Ticket Selector Flag', 'event_espresso'),
208
+					false,
209
+					true
210
+				),
211
+				'EVT_visible_on'                  => new EE_Datetime_Field(
212
+					'EVT_visible_on',
213
+					esc_html__('Event Visible Date', 'event_espresso'),
214
+					true,
215
+					EE_Datetime_Field::now
216
+				),
217
+				'EVT_additional_limit'            => new EE_Integer_Field(
218
+					'EVT_additional_limit',
219
+					esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
220
+					true,
221
+					self::$_default_additional_limit
222
+				),
223
+				'EVT_default_registration_status' => new EE_Enum_Text_Field(
224
+					'EVT_default_registration_status',
225
+					esc_html__('Default Registration Status on this Event', 'event_espresso'),
226
+					false,
227
+					EEM_Event::$_default_reg_status,
228
+					EEM_Registration::reg_status_array()
229
+				),
230
+				'EVT_member_only'                 => new EE_Boolean_Field(
231
+					'EVT_member_only',
232
+					esc_html__('Member-Only Event Flag', 'event_espresso'),
233
+					false,
234
+					false
235
+				),
236
+				'EVT_phone'                       => new EE_Plain_Text_Field(
237
+					'EVT_phone',
238
+					esc_html__('Event Phone Number', 'event_espresso'),
239
+					false,
240
+					''
241
+				),
242
+				'EVT_allow_overflow'              => new EE_Boolean_Field(
243
+					'EVT_allow_overflow',
244
+					esc_html__('Allow Overflow on Event', 'event_espresso'),
245
+					false,
246
+					false
247
+				),
248
+				'EVT_timezone_string'             => new EE_Plain_Text_Field(
249
+					'EVT_timezone_string',
250
+					esc_html__('Timezone (name) for Event times', 'event_espresso'),
251
+					false,
252
+					''
253
+				),
254
+				'EVT_external_URL'                => new EE_Plain_Text_Field(
255
+					'EVT_external_URL',
256
+					esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'),
257
+					true
258
+				),
259
+				'EVT_donations'                   => new EE_Boolean_Field(
260
+					'EVT_donations',
261
+					esc_html__('Accept Donations?', 'event_espresso'),
262
+					false,
263
+					false
264
+				),
265
+			),
266
+		);
267
+		$this->_model_relations = array(
268
+			'Registration'           => new EE_Has_Many_Relation(),
269
+			'Datetime'               => new EE_Has_Many_Relation(),
270
+			'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
271
+			'Event_Question_Group'   => new EE_Has_Many_Relation(),
272
+			'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
273
+			'Term_Relationship'      => new EE_Has_Many_Relation(),
274
+			'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
275
+			'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
276
+			'Attendee'               => new EE_HABTM_Relation('Registration'),
277
+			'WP_User'                => new EE_Belongs_To_Relation(),
278
+		);
279
+		// this model is generally available for reading
280
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
281
+		$this->model_chain_to_password = '';
282
+		parent::__construct($timezone);
283
+	}
284
+
285
+
286
+
287
+	/**
288
+	 * @param string $default_reg_status
289
+	 */
290
+	public static function set_default_reg_status($default_reg_status)
291
+	{
292
+		self::$_default_reg_status = $default_reg_status;
293
+		// if EEM_Event has already been instantiated,
294
+		// then we need to reset the `EVT_default_reg_status` field to use the new default.
295
+		if (self::$_instance instanceof EEM_Event) {
296
+			$default_reg_status = new EE_Enum_Text_Field(
297
+				'EVT_default_registration_status',
298
+				esc_html__('Default Registration Status on this Event', 'event_espresso'),
299
+				false,
300
+				$default_reg_status,
301
+				EEM_Registration::reg_status_array()
302
+			);
303
+			$default_reg_status->_construct_finalize(
304
+				'Event_Meta',
305
+				'EVT_default_registration_status',
306
+				'EEM_Event'
307
+			);
308
+			self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
309
+		}
310
+	}
311
+
312
+
313
+	/**
314
+	 * Used to override the default for the additional limit field.
315
+	 * @param $additional_limit
316
+	 */
317
+	public static function set_default_additional_limit($additional_limit)
318
+	{
319
+		self::$_default_additional_limit = (int) $additional_limit;
320
+		if (self::$_instance instanceof EEM_Event) {
321
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
322
+				'EVT_additional_limit',
323
+				esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
324
+				true,
325
+				self::$_default_additional_limit
326
+			);
327
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
328
+				'Event_Meta',
329
+				'EVT_additional_limit',
330
+				'EEM_Event'
331
+			);
332
+		}
333
+	}
334
+
335
+
336
+	/**
337
+	 * Return what is currently set as the default additional limit for the event.
338
+	 * @return int
339
+	 */
340
+	public static function get_default_additional_limit()
341
+	{
342
+		return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
343
+	}
344
+
345
+
346
+	/**
347
+	 * get_question_groups
348
+	 *
349
+	 * @return array
350
+	 * @throws \EE_Error
351
+	 */
352
+	public function get_all_question_groups()
353
+	{
354
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
355
+			array(
356
+				array('QSG_deleted' => false),
357
+				'order_by' => array('QSG_order' => 'ASC'),
358
+			)
359
+		);
360
+	}
361
+
362
+
363
+
364
+	/**
365
+	 * get_question_groups
366
+	 *
367
+	 * @param int $EVT_ID
368
+	 * @return array|bool
369
+	 * @throws \EE_Error
370
+	 */
371
+	public function get_all_event_question_groups($EVT_ID = 0)
372
+	{
373
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
374
+			EE_Error::add_error(
375
+				esc_html__(
376
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
377
+					'event_espresso'
378
+				),
379
+				__FILE__,
380
+				__FUNCTION__,
381
+				__LINE__
382
+			);
383
+			return false;
384
+		}
385
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
386
+			array(
387
+				array('EVT_ID' => $EVT_ID),
388
+			)
389
+		);
390
+	}
391
+
392
+
393
+	/**
394
+	 * get_question_groups
395
+	 *
396
+	 * @param int $EVT_ID
397
+	 * @param boolean $for_primary_attendee
398
+	 * @return array|bool
399
+	 * @throws EE_Error
400
+	 * @throws InvalidArgumentException
401
+	 * @throws ReflectionException
402
+	 * @throws InvalidDataTypeException
403
+	 * @throws InvalidInterfaceException
404
+	 */
405
+	public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
406
+	{
407
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
408
+			EE_Error::add_error(
409
+				esc_html__(
410
+					// @codingStandardsIgnoreStart
411
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
412
+					// @codingStandardsIgnoreEnd
413
+					'event_espresso'
414
+				),
415
+				__FILE__,
416
+				__FUNCTION__,
417
+				__LINE__
418
+			);
419
+			return false;
420
+		}
421
+		$query_params = [
422
+			[
423
+				'EVT_ID' => $EVT_ID,
424
+				EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true
425
+			]
426
+		];
427
+		if ($for_primary_attendee) {
428
+			$query_params[0]['EQG_primary'] = true;
429
+		} else {
430
+			$query_params[0]['EQG_additional'] = true;
431
+		}
432
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params);
433
+	}
434
+
435
+
436
+	/**
437
+	 * get_question_groups
438
+	 *
439
+	 * @param int $EVT_ID
440
+	 * @param EE_Registration $registration
441
+	 * @return array
442
+	 * @throws EE_Error
443
+	 * @throws InvalidArgumentException
444
+	 * @throws InvalidDataTypeException
445
+	 * @throws InvalidInterfaceException
446
+	 * @throws ReflectionException
447
+	 */
448
+	public function get_question_groups_for_event($EVT_ID, EE_Registration $registration)
449
+	{
450
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
451
+			EE_Error::add_error(
452
+				esc_html__(
453
+					'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
454
+					'event_espresso'
455
+				),
456
+				__FILE__,
457
+				__FUNCTION__,
458
+				__LINE__
459
+			);
460
+			return [];
461
+		}
462
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
463
+			[
464
+				[
465
+					'Event_Question_Group.EVT_ID'      => $EVT_ID,
466
+					'Event_Question_Group.'
467
+						. EEM_Event_Question_Group::instance()->fieldNameForContext(
468
+							$registration->is_primary_registrant()
469
+						) => true
470
+				],
471
+				'order_by' => ['QSG_order' => 'ASC'],
472
+			]
473
+		);
474
+	}
475
+
476
+
477
+
478
+	/**
479
+	 * get_question_target_db_column
480
+	 *
481
+	 * @param string $QSG_IDs csv list of $QSG IDs
482
+	 * @return array|bool
483
+	 * @throws \EE_Error
484
+	 */
485
+	public function get_questions_in_groups($QSG_IDs = '')
486
+	{
487
+		if (empty($QSG_IDs)) {
488
+			EE_Error::add_error(
489
+				esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
490
+				__FILE__,
491
+				__FUNCTION__,
492
+				__LINE__
493
+			);
494
+			return false;
495
+		}
496
+		return EE_Registry::instance()->load_model('Question')->get_all(
497
+			array(
498
+				array(
499
+					'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
500
+					'QST_deleted'           => false,
501
+					'QST_admin_only'        => is_admin(),
502
+				),
503
+				'order_by' => 'QST_order',
504
+			)
505
+		);
506
+	}
507
+
508
+
509
+
510
+	/**
511
+	 * get_options_for_question
512
+	 *
513
+	 * @param string $QST_IDs csv list of $QST IDs
514
+	 * @return array|bool
515
+	 * @throws \EE_Error
516
+	 */
517
+	public function get_options_for_question($QST_IDs)
518
+	{
519
+		if (empty($QST_IDs)) {
520
+			EE_Error::add_error(
521
+				esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
522
+				__FILE__,
523
+				__FUNCTION__,
524
+				__LINE__
525
+			);
526
+			return false;
527
+		}
528
+		return EE_Registry::instance()->load_model('Question_Option')->get_all(
529
+			array(
530
+				array(
531
+					'Question.QST_ID' => array('IN', $QST_IDs),
532
+					'QSO_deleted'     => false,
533
+				),
534
+				'order_by' => 'QSO_ID',
535
+			)
536
+		);
537
+	}
538
+
539
+
540
+
541
+
542
+
543
+
544
+
545
+	/**
546
+	 * Gets all events that are published
547
+	 * and have event start time earlier than now and an event end time later than now
548
+	 *
549
+	 * @param  array $query_params An array of query params to further filter on
550
+	 *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
551
+	 * @param bool   $count        whether to return the count or not (default FALSE)
552
+	 * @return EE_Event[]|int
553
+	 * @throws \EE_Error
554
+	 */
555
+	public function get_active_events($query_params, $count = false)
556
+	{
557
+		if (array_key_exists(0, $query_params)) {
558
+			$where_params = $query_params[0];
559
+			unset($query_params[0]);
560
+		} else {
561
+			$where_params = array();
562
+		}
563
+		// if we have count make sure we don't include group by
564
+		if ($count && isset($query_params['group_by'])) {
565
+			unset($query_params['group_by']);
566
+		}
567
+		// let's add specific query_params for active_events
568
+		// keep in mind this will override any sent status in the query AND any date queries.
569
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
570
+		// if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
571
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
572
+			$where_params['Datetime.DTT_EVT_start******'] = array(
573
+				'<',
574
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
575
+			);
576
+		} else {
577
+			$where_params['Datetime.DTT_EVT_start'] = array(
578
+				'<',
579
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
580
+			);
581
+		}
582
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
583
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
584
+				'>',
585
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
586
+			);
587
+		} else {
588
+			$where_params['Datetime.DTT_EVT_end'] = array(
589
+				'>',
590
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
591
+			);
592
+		}
593
+		$query_params[0] = $where_params;
594
+		// don't use $query_params with count()
595
+		// because we don't want to include additional query clauses like "GROUP BY"
596
+		return $count
597
+			? $this->count(array($where_params), 'EVT_ID', true)
598
+			: $this->get_all($query_params);
599
+	}
600
+
601
+
602
+
603
+	/**
604
+	 * get all events that are published and have an event start time later than now
605
+	 *
606
+	 * @param  array $query_params An array of query params to further filter on
607
+	 *                             (Note that status and DTT_EVT_start will be overridden)
608
+	 * @param bool   $count        whether to return the count or not (default FALSE)
609
+	 * @return EE_Event[]|int
610
+	 * @throws \EE_Error
611
+	 */
612
+	public function get_upcoming_events($query_params, $count = false)
613
+	{
614
+		if (array_key_exists(0, $query_params)) {
615
+			$where_params = $query_params[0];
616
+			unset($query_params[0]);
617
+		} else {
618
+			$where_params = array();
619
+		}
620
+		// if we have count make sure we don't include group by
621
+		if ($count && isset($query_params['group_by'])) {
622
+			unset($query_params['group_by']);
623
+		}
624
+		// let's add specific query_params for active_events
625
+		// keep in mind this will override any sent status in the query AND any date queries.
626
+		// we need to pull events with a status of publish and sold_out
627
+		$event_status = array('publish', EEM_Event::sold_out);
628
+		// check if the user can read private events and if so add the 'private status to the were params'
629
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) {
630
+			$event_status[] = 'private';
631
+		}
632
+		$where_params['status'] = array('IN', $event_status);
633
+		// if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
634
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
635
+			$where_params['Datetime.DTT_EVT_start*****'] = array(
636
+				'>',
637
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
638
+			);
639
+		} else {
640
+			$where_params['Datetime.DTT_EVT_start'] = array(
641
+				'>',
642
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
643
+			);
644
+		}
645
+		$query_params[0] = $where_params;
646
+		// don't use $query_params with count()
647
+		// because we don't want to include additional query clauses like "GROUP BY"
648
+		return $count
649
+			? $this->count(array($where_params), 'EVT_ID', true)
650
+			: $this->get_all($query_params);
651
+	}
652
+
653
+
654
+
655
+	/**
656
+	 * Gets all events that are published
657
+	 * and have an event end time later than now
658
+	 *
659
+	 * @param  array $query_params An array of query params to further filter on
660
+	 *                             (note that status and DTT_EVT_end will be overridden)
661
+	 * @param bool   $count        whether to return the count or not (default FALSE)
662
+	 * @return EE_Event[]|int
663
+	 * @throws \EE_Error
664
+	 */
665
+	public function get_active_and_upcoming_events($query_params, $count = false)
666
+	{
667
+		if (array_key_exists(0, $query_params)) {
668
+			$where_params = $query_params[0];
669
+			unset($query_params[0]);
670
+		} else {
671
+			$where_params = array();
672
+		}
673
+		// if we have count make sure we don't include group by
674
+		if ($count && isset($query_params['group_by'])) {
675
+			unset($query_params['group_by']);
676
+		}
677
+		// let's add specific query_params for active_events
678
+		// keep in mind this will override any sent status in the query AND any date queries.
679
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
680
+		// add where params for DTT_EVT_end
681
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
682
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
683
+				'>',
684
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
685
+			);
686
+		} else {
687
+			$where_params['Datetime.DTT_EVT_end'] = array(
688
+				'>',
689
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
690
+			);
691
+		}
692
+		$query_params[0] = $where_params;
693
+		// don't use $query_params with count()
694
+		// because we don't want to include additional query clauses like "GROUP BY"
695
+		return $count
696
+			? $this->count(array($where_params), 'EVT_ID', true)
697
+			: $this->get_all($query_params);
698
+	}
699
+
700
+
701
+
702
+	/**
703
+	 * This only returns events that are expired.
704
+	 * They may still be published but all their datetimes have expired.
705
+	 *
706
+	 * @param  array $query_params An array of query params to further filter on
707
+	 *                             (note that status and DTT_EVT_end will be overridden)
708
+	 * @param bool   $count        whether to return the count or not (default FALSE)
709
+	 * @return EE_Event[]|int
710
+	 * @throws \EE_Error
711
+	 */
712
+	public function get_expired_events($query_params, $count = false)
713
+	{
714
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
715
+		// if we have count make sure we don't include group by
716
+		if ($count && isset($query_params['group_by'])) {
717
+			unset($query_params['group_by']);
718
+		}
719
+		// let's add specific query_params for active_events
720
+		// keep in mind this will override any sent status in the query AND any date queries.
721
+		if (isset($where_params['status'])) {
722
+			unset($where_params['status']);
723
+		}
724
+		$exclude_query = $query_params;
725
+		if (isset($exclude_query[0])) {
726
+			unset($exclude_query[0]);
727
+		}
728
+		$exclude_query[0] = array(
729
+			'Datetime.DTT_EVT_end' => array(
730
+				'>',
731
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
732
+			),
733
+		);
734
+		// first get all events that have datetimes where its not expired.
735
+		$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
736
+		$event_ids = array_keys($event_ids);
737
+		// if we have any additional query_params, let's add them to the 'AND' condition
738
+		$and_condition = array(
739
+			'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
740
+			'EVT_ID'               => array('NOT IN', $event_ids),
741
+		);
742
+		if (isset($where_params['OR'])) {
743
+			$and_condition['OR'] = $where_params['OR'];
744
+			unset($where_params['OR']);
745
+		}
746
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
747
+			$and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
748
+			unset($where_params['Datetime.DTT_EVT_end']);
749
+		}
750
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
751
+			$and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
752
+			unset($where_params['Datetime.DTT_EVT_start']);
753
+		}
754
+		// merge remaining $where params with the and conditions.
755
+		$where_params['AND'] = array_merge($and_condition, $where_params);
756
+		$query_params[0] = $where_params;
757
+		// don't use $query_params with count()
758
+		// because we don't want to include additional query clauses like "GROUP BY"
759
+		return $count
760
+			? $this->count(array($where_params), 'EVT_ID', true)
761
+			: $this->get_all($query_params);
762
+	}
763
+
764
+
765
+
766
+	/**
767
+	 * This basically just returns the events that do not have the publish status.
768
+	 *
769
+	 * @param  array   $query_params An array of query params to further filter on
770
+	 *                               (note that status will be overwritten)
771
+	 * @param  boolean $count        whether to return the count or not (default FALSE)
772
+	 * @return EE_Event[]|int
773
+	 * @throws \EE_Error
774
+	 */
775
+	public function get_inactive_events($query_params, $count = false)
776
+	{
777
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
778
+		// let's add in specific query_params for inactive events.
779
+		if (isset($where_params['status'])) {
780
+			unset($where_params['status']);
781
+		}
782
+		// if we have count make sure we don't include group by
783
+		if ($count && isset($query_params['group_by'])) {
784
+			unset($query_params['group_by']);
785
+		}
786
+		// if we have any additional query_params, let's add them to the 'AND' condition
787
+		$where_params['AND']['status'] = array('!=', 'publish');
788
+		if (isset($where_params['OR'])) {
789
+			$where_params['AND']['OR'] = $where_params['OR'];
790
+			unset($where_params['OR']);
791
+		}
792
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
793
+			$where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
794
+			unset($where_params['Datetime.DTT_EVT_end']);
795
+		}
796
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
797
+			$where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
798
+			unset($where_params['Datetime.DTT_EVT_start']);
799
+		}
800
+		$query_params[0] = $where_params;
801
+		// don't use $query_params with count()
802
+		// because we don't want to include additional query clauses like "GROUP BY"
803
+		return $count
804
+			? $this->count(array($where_params), 'EVT_ID', true)
805
+			: $this->get_all($query_params);
806
+	}
807
+
808
+
809
+
810
+	/**
811
+	 * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
812
+	 * because we don't want to override any existing global default prices but instead insert NEW prices that get
813
+	 * attached to the event. See parent for param descriptions
814
+	 *
815
+	 * @param        $id_or_obj
816
+	 * @param        $other_model_id_or_obj
817
+	 * @param string $relationName
818
+	 * @param array  $where_query
819
+	 * @return EE_Base_Class
820
+	 * @throws EE_Error
821
+	 */
822
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
823
+	{
824
+		if ($relationName === 'Price') {
825
+			// let's get the PRC object for the given ID to make sure that we aren't dealing with a default
826
+			$prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
827
+			// if EVT_ID = 0, then this is a default
828
+			if ((int) $prc_chk->get('EVT_ID') === 0) {
829
+				// let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
830
+				$prc_chk->set('PRC_ID', 0);
831
+			}
832
+			// run parent
833
+			return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
834
+		}
835
+		// otherwise carry on as normal
836
+		return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
837
+	}
838
+
839
+
840
+
841
+	/******************** DEPRECATED METHODS ********************/
842
+
843
+
844
+
845
+	/**
846
+	 * _get_question_target_db_column
847
+	 *
848
+	 * @deprecated as of 4.8.32.rc.001. Instead consider using
849
+	 *             EE_Registration_Custom_Questions_Form located in
850
+	 *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
851
+	 * @access     public
852
+	 * @param    EE_Registration $registration (so existing answers for registration are included)
853
+	 * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
854
+	 *                                         registration).
855
+	 * @throws EE_Error
856
+	 * @return    array
857
+	 */
858
+	public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
859
+	{
860
+		if (empty($EVT_ID)) {
861
+			throw new EE_Error(esc_html__(
862
+				'An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
863
+				'event_espresso'
864
+			));
865
+		}
866
+		$questions = array();
867
+		// get all question groups for event
868
+		$qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
869
+		if (! empty($qgs)) {
870
+			foreach ($qgs as $qg) {
871
+				$qsts = $qg->questions();
872
+				$questions[ $qg->ID() ] = $qg->model_field_array();
873
+				$questions[ $qg->ID() ]['QSG_questions'] = array();
874
+				foreach ($qsts as $qst) {
875
+					if ($qst->is_system_question()) {
876
+						continue;
877
+					}
878
+					$answer = EEM_Answer::instance()->get_one(array(
879
+						array(
880
+							'QST_ID' => $qst->ID(),
881
+							'REG_ID' => $registration->ID(),
882
+						),
883
+					));
884
+					$answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
885
+					$qst_name = $qstn_id = $qst->ID();
886
+					$ans_id = $answer->ID();
887
+					$qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
888
+					$input_name = '';
889
+					$input_id = sanitize_key($qst->display_text());
890
+					$input_class = '';
891
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array();
892
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn'
893
+																						   . $input_name
894
+																						   . $qst_name;
895
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id;
896
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
897
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array();
898
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst;
899
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer;
900
+					// leave responses as-is, don't convert stuff into html entities please!
901
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
902
+					if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
903
+						$QSOs = $qst->options(true, $answer->value());
904
+						if (is_array($QSOs)) {
905
+							foreach ($QSOs as $QSO_ID => $QSO) {
906
+								$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array();
907
+							}
908
+						}
909
+					}
910
+				}
911
+			}
912
+		}
913
+		return $questions;
914
+	}
915
+
916
+
917
+	/**
918
+	 * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value
919
+	 *                             or an stdClass where each property is the name of a column,
920
+	 * @return EE_Base_Class
921
+	 * @throws \EE_Error
922
+	 */
923
+	public function instantiate_class_from_array_or_object($cols_n_values)
924
+	{
925
+		$classInstance = parent::instantiate_class_from_array_or_object($cols_n_values);
926
+		if ($classInstance instanceof EE_Event) {
927
+			// events have their timezone defined in the DB, so use it immediately
928
+			$this->set_timezone($classInstance->get_timezone());
929
+		}
930
+		return $classInstance;
931
+	}
932
+
933
+
934
+	/**
935
+	 * Deletes the model objects that meet the query params. Note: this method is overridden
936
+	 * in EEM_Soft_Delete_Base so that soft-deleted model objects are instead only flagged
937
+	 * as archived, not actually deleted
938
+	 *
939
+	 * @param array   $query_params   @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
940
+	 * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
941
+	 *                                that blocks it (ie, there' sno other data that depends on this data); if false,
942
+	 *                                deletes regardless of other objects which may depend on it. Its generally
943
+	 *                                advisable to always leave this as TRUE, otherwise you could easily corrupt your
944
+	 *                                DB
945
+	 * @return int                    number of rows deleted
946
+	 * @throws EE_Error
947
+	 */
948
+	public function delete_permanently($query_params, $allow_blocking = true)
949
+	{
950
+		$deleted = parent::delete_permanently($query_params, $allow_blocking);
951
+		if ($deleted) {
952
+			// get list of events with no prices
953
+			$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', []);
954
+			$where = isset($query_params[0]) ? $query_params[0] : [];
955
+			$where_event = isset($where['EVT_ID']) ? $where['EVT_ID'] : ['', ''];
956
+			$where_event_ids = isset($where_event[1]) ? $where_event[1] : '';
957
+			$event_ids = is_string($where_event_ids)
958
+				? explode(',', $where_event_ids)
959
+				: (array) $where_event_ids;
960
+			array_walk($event_ids, 'trim');
961
+			$event_ids = array_filter($event_ids);
962
+			// remove events from list of events with no prices
963
+			$espresso_no_ticket_prices = array_diff($espresso_no_ticket_prices, $event_ids);
964
+			update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
965
+		}
966
+		return $deleted;
967
+	}
968 968
 }
Please login to merge, or discard this patch.
core/domain/services/admin/events/data/ConfirmDeletion.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -30,86 +30,86 @@
 block discarded – undo
30 30
  */
31 31
 class ConfirmDeletion
32 32
 {
33
-    /**
34
-     * @var NodeGroupDao
35
-     */
36
-    private $dao;
33
+	/**
34
+	 * @var NodeGroupDao
35
+	 */
36
+	private $dao;
37 37
 
38
-    /**
39
-     * ConfirmDeletion constructor.
40
-     * @param NodeGroupDao $dao
41
-     */
42
-    public function __construct(
43
-        NodeGroupDao $dao
44
-    ) {
38
+	/**
39
+	 * ConfirmDeletion constructor.
40
+	 * @param NodeGroupDao $dao
41
+	 */
42
+	public function __construct(
43
+		NodeGroupDao $dao
44
+	) {
45 45
 
46
-        $this->dao = $dao;
47
-    }
46
+		$this->dao = $dao;
47
+	}
48 48
 
49
-    /**
50
-     * Redirects to the batch job for deleting events if the form submission is valid, otherwise back to the deletion
51
-     * preview page.
52
-     * @since 4.10.12.p
53
-     * @param $request_data
54
-     * @param $admin_base_url
55
-     * @throws EE_Error
56
-     * @throws InvalidArgumentException
57
-     * @throws InvalidDataTypeException
58
-     * @throws InvalidInterfaceException
59
-     * @throws ReflectionException
60
-     * @throws UnexpectedEntityException
61
-     */
62
-    public function handle($request_data, $admin_base_url)
63
-    {
64
-        $deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : '';
65
-        $models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code);
66
-        $form = new ConfirmEventDeletionForm($models_and_ids_to_delete['Event']);
67
-        // Initialize the form from the request, and check if its valid.
68
-        $form->receive_form_submission($request_data);
69
-        if ($form->is_valid()) {
70
-            // Redirect the user to the deletion batch job.
71
-            EEH_URL::safeRedirectAndExit(
72
-                EE_Admin_Page::add_query_args_and_nonce(
73
-                    array(
74
-                        'page' => 'espresso_batch',
75
-                        'batch' => EED_Batch::batch_job,
76
-                        'deletion_job_code' => $deletion_job_code,
77
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion'),
78
-                        'return_url' => urlencode(
79
-                            add_query_arg(
80
-                                [
81
-                                    'status' => 'trash'
82
-                                ],
83
-                                EVENTS_ADMIN_URL
84
-                            )
85
-                        )
86
-                    ),
87
-                    admin_url()
88
-                )
89
-            );
90
-        }
91
-        // Dont' use $form->submission_error_message() because it adds the form input's label in front
92
-        // of each validation error which ends up looking quite confusing.
93
-        $validation_errors = $form->get_validation_errors_accumulated();
94
-        foreach ($validation_errors as $validation_error) {
95
-            EE_Error::add_error(
96
-                $validation_error->getMessage(),
97
-                __FILE__,
98
-                __FUNCTION__,
99
-                __LINE__
100
-            );
101
-        }
49
+	/**
50
+	 * Redirects to the batch job for deleting events if the form submission is valid, otherwise back to the deletion
51
+	 * preview page.
52
+	 * @since 4.10.12.p
53
+	 * @param $request_data
54
+	 * @param $admin_base_url
55
+	 * @throws EE_Error
56
+	 * @throws InvalidArgumentException
57
+	 * @throws InvalidDataTypeException
58
+	 * @throws InvalidInterfaceException
59
+	 * @throws ReflectionException
60
+	 * @throws UnexpectedEntityException
61
+	 */
62
+	public function handle($request_data, $admin_base_url)
63
+	{
64
+		$deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : '';
65
+		$models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code);
66
+		$form = new ConfirmEventDeletionForm($models_and_ids_to_delete['Event']);
67
+		// Initialize the form from the request, and check if its valid.
68
+		$form->receive_form_submission($request_data);
69
+		if ($form->is_valid()) {
70
+			// Redirect the user to the deletion batch job.
71
+			EEH_URL::safeRedirectAndExit(
72
+				EE_Admin_Page::add_query_args_and_nonce(
73
+					array(
74
+						'page' => 'espresso_batch',
75
+						'batch' => EED_Batch::batch_job,
76
+						'deletion_job_code' => $deletion_job_code,
77
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion'),
78
+						'return_url' => urlencode(
79
+							add_query_arg(
80
+								[
81
+									'status' => 'trash'
82
+								],
83
+								EVENTS_ADMIN_URL
84
+							)
85
+						)
86
+					),
87
+					admin_url()
88
+				)
89
+			);
90
+		}
91
+		// Dont' use $form->submission_error_message() because it adds the form input's label in front
92
+		// of each validation error which ends up looking quite confusing.
93
+		$validation_errors = $form->get_validation_errors_accumulated();
94
+		foreach ($validation_errors as $validation_error) {
95
+			EE_Error::add_error(
96
+				$validation_error->getMessage(),
97
+				__FILE__,
98
+				__FUNCTION__,
99
+				__LINE__
100
+			);
101
+		}
102 102
 
103
-        EEH_URL::safeRedirectAndExit(
104
-            EE_Admin_Page::add_query_args_and_nonce(
105
-                [
106
-                    'action' => 'preview_deletion',
107
-                    'deletion_job_code' => $deletion_job_code
108
-                ],
109
-                $admin_base_url
110
-            )
111
-        );
112
-    }
103
+		EEH_URL::safeRedirectAndExit(
104
+			EE_Admin_Page::add_query_args_and_nonce(
105
+				[
106
+					'action' => 'preview_deletion',
107
+					'deletion_job_code' => $deletion_job_code
108
+				],
109
+				$admin_base_url
110
+			)
111
+		);
112
+	}
113 113
 }
114 114
 // End of file ConfirmDeletion.php
115 115
 // Location: EventEspresso\core\domain\services\admin\events\data/ConfirmDeletion.php
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Table_Base.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
      */
94 94
     public function get_table_name()
95 95
     {
96
-        return $this->get_table_prefix() . $this->_table_name;
96
+        return $this->get_table_prefix().$this->_table_name;
97 97
     }
98 98
 
99 99
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
      */
106 106
     public function get_table_alias()
107 107
     {
108
-        if (! $this->_table_alias) {
108
+        if ( ! $this->_table_alias) {
109 109
             throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
110 110
         }
111 111
         return $this->_table_alias;
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
      */
129 129
     public function get_fully_qualified_pk_column()
130 130
     {
131
-        return $this->get_table_alias() . "." . $this->get_pk_column();
131
+        return $this->get_table_alias().".".$this->get_pk_column();
132 132
     }
133 133
 
134 134
 
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
      */
140 140
     public function get_select_join_limit($limit)
141 141
     {
142
-        $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit;
143
-        return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
142
+        $limit = is_array($limit) ? 'LIMIT '.implode(',', array_map('intval', $limit)) : 'LIMIT '.(int) $limit;
143
+        return SP.'(SELECT * FROM '.$this->_table_name.SP.$limit.') AS '.$this->_table_alias;
144 144
     }
145 145
 
146 146
 
Please login to merge, or discard this patch.
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -6,151 +6,151 @@
 block discarded – undo
6 6
  */
7 7
 abstract class EE_Table_Base
8 8
 {
9
-    /**
10
-     * This holds the table_name without the table prefix.
11
-     *
12
-     * @var string
13
-     */
14
-    public $_table_name;
15
-
16
-
17
-    /**
18
-     * This holds what is used as the alias for the table in queries.
19
-     *
20
-     * @var string
21
-     */
22
-    public $_table_alias;
23
-
24
-
25
-    /**
26
-     * Table's private key column
27
-     *
28
-     * @var string
29
-     */
30
-    protected $_pk_column;
31
-
32
-
33
-    /**
34
-     * Whether this table is a global table (in multisite) or specific to site.
35
-     *
36
-     * @var bool
37
-     */
38
-    protected $_global;
39
-
40
-
41
-    /**
42
-     * @param string  $table_name with or without wpdb prefix
43
-     * @param string  $pk_column
44
-     * @param boolean $global     whether the table is "global" as in there is only 1 table on an entire multisite
45
-     *                            install, or whether each site on a multisite install has a copy of this table
46
-     * @global wpdb   $wpdb
47
-     */
48
-    public function __construct($table_name, $pk_column, $global = false)
49
-    {
50
-        $this->_global = $global;
51
-        $prefix        = $this->get_table_prefix();
52
-        // if they added the prefix, let's remove it because we delay adding the prefix until right when its needed.
53
-        if (strpos($table_name, $prefix) === 0) {
54
-            $table_name = substr_replace($table_name, '', 0, strlen($prefix));
55
-        }
56
-        $this->_table_name = $table_name;
57
-        $this->_pk_column  = $pk_column;
58
-    }
59
-
60
-
61
-    /**
62
-     * This returns the table prefix for the current model state.
63
-     *
64
-     * @return string
65
-     * @global wpdb $wpdb
66
-     */
67
-    public function get_table_prefix()
68
-    {
69
-        global $wpdb;
70
-        if ($this->_global) {
71
-            return $wpdb->base_prefix;
72
-        }
73
-        return $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id());
74
-    }
75
-
76
-
77
-    /**
78
-     * Used to set the table_alias property
79
-     *
80
-     * @param string $table_alias
81
-     */
82
-    public function _construct_finalize_with_alias($table_alias)
83
-    {
84
-        $this->_table_alias = $table_alias;
85
-    }
86
-
87
-
88
-    /**
89
-     * Returns the fully qualified table name for the database (includes the table prefix current for the blog).
90
-     *
91
-     * @return string
92
-     */
93
-    public function get_table_name()
94
-    {
95
-        return $this->get_table_prefix() . $this->_table_name;
96
-    }
97
-
98
-
99
-    /**
100
-     * Provides what is currently set as the alias for the table to be used in queries.
101
-     *
102
-     * @return string
103
-     * @throws EE_Error
104
-     */
105
-    public function get_table_alias()
106
-    {
107
-        if (! $this->_table_alias) {
108
-            throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
109
-        }
110
-        return $this->_table_alias;
111
-    }
112
-
113
-
114
-    /**
115
-     * @return string name of column of PK
116
-     */
117
-    public function get_pk_column()
118
-    {
119
-        return $this->_pk_column;
120
-    }
121
-
122
-
123
-    /**
124
-     * returns a string with the table alias, a period, and the private key's column.
125
-     *
126
-     * @return string
127
-     */
128
-    public function get_fully_qualified_pk_column()
129
-    {
130
-        return $this->get_table_alias() . "." . $this->get_pk_column();
131
-    }
132
-
133
-
134
-    /**
135
-     * returns the special sql for a inner select with a limit.
136
-     *
137
-     * @return string    SQL select
138
-     */
139
-    public function get_select_join_limit($limit)
140
-    {
141
-        $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit;
142
-        return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
143
-    }
144
-
145
-
146
-    /**
147
-     * Returns whether or not htis is a global table (ie, on multisite there's
148
-     * only one of these tables, on the main blog)
149
-     *
150
-     * @return boolean
151
-     */
152
-    public function is_global()
153
-    {
154
-        return $this->_global;
155
-    }
9
+	/**
10
+	 * This holds the table_name without the table prefix.
11
+	 *
12
+	 * @var string
13
+	 */
14
+	public $_table_name;
15
+
16
+
17
+	/**
18
+	 * This holds what is used as the alias for the table in queries.
19
+	 *
20
+	 * @var string
21
+	 */
22
+	public $_table_alias;
23
+
24
+
25
+	/**
26
+	 * Table's private key column
27
+	 *
28
+	 * @var string
29
+	 */
30
+	protected $_pk_column;
31
+
32
+
33
+	/**
34
+	 * Whether this table is a global table (in multisite) or specific to site.
35
+	 *
36
+	 * @var bool
37
+	 */
38
+	protected $_global;
39
+
40
+
41
+	/**
42
+	 * @param string  $table_name with or without wpdb prefix
43
+	 * @param string  $pk_column
44
+	 * @param boolean $global     whether the table is "global" as in there is only 1 table on an entire multisite
45
+	 *                            install, or whether each site on a multisite install has a copy of this table
46
+	 * @global wpdb   $wpdb
47
+	 */
48
+	public function __construct($table_name, $pk_column, $global = false)
49
+	{
50
+		$this->_global = $global;
51
+		$prefix        = $this->get_table_prefix();
52
+		// if they added the prefix, let's remove it because we delay adding the prefix until right when its needed.
53
+		if (strpos($table_name, $prefix) === 0) {
54
+			$table_name = substr_replace($table_name, '', 0, strlen($prefix));
55
+		}
56
+		$this->_table_name = $table_name;
57
+		$this->_pk_column  = $pk_column;
58
+	}
59
+
60
+
61
+	/**
62
+	 * This returns the table prefix for the current model state.
63
+	 *
64
+	 * @return string
65
+	 * @global wpdb $wpdb
66
+	 */
67
+	public function get_table_prefix()
68
+	{
69
+		global $wpdb;
70
+		if ($this->_global) {
71
+			return $wpdb->base_prefix;
72
+		}
73
+		return $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id());
74
+	}
75
+
76
+
77
+	/**
78
+	 * Used to set the table_alias property
79
+	 *
80
+	 * @param string $table_alias
81
+	 */
82
+	public function _construct_finalize_with_alias($table_alias)
83
+	{
84
+		$this->_table_alias = $table_alias;
85
+	}
86
+
87
+
88
+	/**
89
+	 * Returns the fully qualified table name for the database (includes the table prefix current for the blog).
90
+	 *
91
+	 * @return string
92
+	 */
93
+	public function get_table_name()
94
+	{
95
+		return $this->get_table_prefix() . $this->_table_name;
96
+	}
97
+
98
+
99
+	/**
100
+	 * Provides what is currently set as the alias for the table to be used in queries.
101
+	 *
102
+	 * @return string
103
+	 * @throws EE_Error
104
+	 */
105
+	public function get_table_alias()
106
+	{
107
+		if (! $this->_table_alias) {
108
+			throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
109
+		}
110
+		return $this->_table_alias;
111
+	}
112
+
113
+
114
+	/**
115
+	 * @return string name of column of PK
116
+	 */
117
+	public function get_pk_column()
118
+	{
119
+		return $this->_pk_column;
120
+	}
121
+
122
+
123
+	/**
124
+	 * returns a string with the table alias, a period, and the private key's column.
125
+	 *
126
+	 * @return string
127
+	 */
128
+	public function get_fully_qualified_pk_column()
129
+	{
130
+		return $this->get_table_alias() . "." . $this->get_pk_column();
131
+	}
132
+
133
+
134
+	/**
135
+	 * returns the special sql for a inner select with a limit.
136
+	 *
137
+	 * @return string    SQL select
138
+	 */
139
+	public function get_select_join_limit($limit)
140
+	{
141
+		$limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit;
142
+		return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
143
+	}
144
+
145
+
146
+	/**
147
+	 * Returns whether or not htis is a global table (ie, on multisite there's
148
+	 * only one of these tables, on the main blog)
149
+	 *
150
+	 * @return boolean
151
+	 */
152
+	public function is_global()
153
+	{
154
+		return $this->_global;
155
+	}
156 156
 }
Please login to merge, or discard this patch.
core/domain/DomainFactory.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      */
40 40
     public static function getShared(FullyQualifiedName $domain_fqcn, array $arguments)
41 41
     {
42
-        if (! isset($arguments[0], $arguments[1])) {
42
+        if ( ! isset($arguments[0], $arguments[1])) {
43 43
             throw new InvalidArgumentException(
44 44
                 esc_html__(
45 45
                     'You need to pass at least two arguments, representing the addon plugin file and version, in order to generate a Domain class',
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
         }
50 50
         /** @var DomainInterface $domain */
51 51
         $domain = LoaderFactory::getLoader()->getShared($domain_fqcn, $arguments);
52
-        if (! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) {
52
+        if ( ! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) {
53 53
             throw new DomainException(
54 54
                 sprintf(
55 55
                     esc_html__(
Please login to merge, or discard this patch.
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -22,62 +22,62 @@
 block discarded – undo
22 22
  */
23 23
 class DomainFactory
24 24
 {
25
-    /**
26
-     * @param FullyQualifiedName $domain_fqcn   [required] Fully Qualified Class Name for the Domain class
27
-     * @param array $arguments                  [required] array of arguments to be passed to the Domain class
28
-     *                                          constructor. Must at least include the following two value objects:
29
-     *                                          array(
30
-     *                                              EventEspresso\core\domain\values\FilePath $plugin_file
31
-     *                                              EventEspresso\core\domain\values\Version $version
32
-     *                                          )
33
-     * @return DomainInterface
34
-     * @throws DomainException
35
-     * @throws InvalidArgumentException
36
-     * @throws InvalidDataTypeException
37
-     * @throws InvalidInterfaceException
38
-     */
39
-    public static function getShared(FullyQualifiedName $domain_fqcn, array $arguments)
40
-    {
41
-        if (! isset($arguments[0], $arguments[1])) {
42
-            throw new InvalidArgumentException(
43
-                esc_html__(
44
-                    'You need to pass at least two arguments, representing the addon plugin file and version, in order to generate a Domain class',
45
-                    'event_espresso'
46
-                )
47
-            );
48
-        }
49
-        /** @var DomainInterface $domain */
50
-        $domain = LoaderFactory::getLoader()->getShared($domain_fqcn, $arguments);
51
-        if (! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) {
52
-            throw new DomainException(
53
-                sprintf(
54
-                    esc_html__(
55
-                        'The requested Domain class "%1$s" could not be loaded.',
56
-                        'event_espresso'
57
-                    ),
58
-                    $domain_fqcn
59
-                )
60
-            );
61
-        }
62
-        return $domain;
63
-    }
25
+	/**
26
+	 * @param FullyQualifiedName $domain_fqcn   [required] Fully Qualified Class Name for the Domain class
27
+	 * @param array $arguments                  [required] array of arguments to be passed to the Domain class
28
+	 *                                          constructor. Must at least include the following two value objects:
29
+	 *                                          array(
30
+	 *                                              EventEspresso\core\domain\values\FilePath $plugin_file
31
+	 *                                              EventEspresso\core\domain\values\Version $version
32
+	 *                                          )
33
+	 * @return DomainInterface
34
+	 * @throws DomainException
35
+	 * @throws InvalidArgumentException
36
+	 * @throws InvalidDataTypeException
37
+	 * @throws InvalidInterfaceException
38
+	 */
39
+	public static function getShared(FullyQualifiedName $domain_fqcn, array $arguments)
40
+	{
41
+		if (! isset($arguments[0], $arguments[1])) {
42
+			throw new InvalidArgumentException(
43
+				esc_html__(
44
+					'You need to pass at least two arguments, representing the addon plugin file and version, in order to generate a Domain class',
45
+					'event_espresso'
46
+				)
47
+			);
48
+		}
49
+		/** @var DomainInterface $domain */
50
+		$domain = LoaderFactory::getLoader()->getShared($domain_fqcn, $arguments);
51
+		if (! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) {
52
+			throw new DomainException(
53
+				sprintf(
54
+					esc_html__(
55
+						'The requested Domain class "%1$s" could not be loaded.',
56
+						'event_espresso'
57
+					),
58
+					$domain_fqcn
59
+				)
60
+			);
61
+		}
62
+		return $domain;
63
+	}
64 64
 
65 65
 
66
-    /**
67
-     * @return Domain
68
-     * @throws DomainException
69
-     * @throws InvalidArgumentException
70
-     * @throws InvalidDataTypeException
71
-     * @throws InvalidFilePathException
72
-     * @throws InvalidInterfaceException
73
-     */
74
-    public static function getEventEspressoCoreDomain()
75
-    {
76
-        $domain = new Domain(
77
-            new FilePath(EVENT_ESPRESSO_MAIN_FILE),
78
-            Version::fromString(espresso_version())
79
-        );
80
-        LoaderFactory::getLoader()->share('EventEspresso\core\domain\Domain', $domain);
81
-        return $domain;
82
-    }
66
+	/**
67
+	 * @return Domain
68
+	 * @throws DomainException
69
+	 * @throws InvalidArgumentException
70
+	 * @throws InvalidDataTypeException
71
+	 * @throws InvalidFilePathException
72
+	 * @throws InvalidInterfaceException
73
+	 */
74
+	public static function getEventEspressoCoreDomain()
75
+	{
76
+		$domain = new Domain(
77
+			new FilePath(EVENT_ESPRESSO_MAIN_FILE),
78
+			Version::fromString(espresso_version())
79
+		);
80
+		LoaderFactory::getLoader()->share('EventEspresso\core\domain\Domain', $domain);
81
+		return $domain;
82
+	}
83 83
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Personal_Data_Exporter.lib.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
      */
29 29
     public static function register($identifier = '', array $setup_args = [])
30 30
     {
31
-        self::$exporters[ $identifier ] = $setup_args;
31
+        self::$exporters[$identifier] = $setup_args;
32 32
         // add to list of modules to be registered
33 33
         add_filter(
34 34
             'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters',
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public static function deregister($identifier = '')
44 44
     {
45
-        unset(self::$exporters[ $identifier ]);
45
+        unset(self::$exporters[$identifier]);
46 46
     }
47 47
 
48 48
 
Please login to merge, or discard this patch.
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -12,55 +12,55 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Register_Personal_Data_Exporter implements EEI_Plugin_API
14 14
 {
15
-    /**
16
-     * FQCN for all privacy policy generators
17
-     *
18
-     * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs
19
-     */
20
-    protected static $exporters = [];
15
+	/**
16
+	 * FQCN for all privacy policy generators
17
+	 *
18
+	 * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs
19
+	 */
20
+	protected static $exporters = [];
21 21
 
22 22
 
23
-    /**
24
-     * @param string $identifier
25
-     * @param array  $setup_args can be the fully qualified namespaces each containing only privacy policies,
26
-     *                           OR fully qualified class names of privacy policies
27
-     */
28
-    public static function register($identifier = '', array $setup_args = [])
29
-    {
30
-        self::$exporters[ $identifier ] = $setup_args;
31
-        // add to list of modules to be registered
32
-        add_filter(
33
-            'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters',
34
-            ['EE_Register_Personal_Data_Exporter', 'addExporters']
35
-        );
36
-    }
23
+	/**
24
+	 * @param string $identifier
25
+	 * @param array  $setup_args can be the fully qualified namespaces each containing only privacy policies,
26
+	 *                           OR fully qualified class names of privacy policies
27
+	 */
28
+	public static function register($identifier = '', array $setup_args = [])
29
+	{
30
+		self::$exporters[ $identifier ] = $setup_args;
31
+		// add to list of modules to be registered
32
+		add_filter(
33
+			'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters',
34
+			['EE_Register_Personal_Data_Exporter', 'addExporters']
35
+		);
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * @param string $identifier
41
-     */
42
-    public static function deregister($identifier = '')
43
-    {
44
-        unset(self::$exporters[ $identifier ]);
45
-    }
39
+	/**
40
+	 * @param string $identifier
41
+	 */
42
+	public static function deregister($identifier = '')
43
+	{
44
+		unset(self::$exporters[ $identifier ]);
45
+	}
46 46
 
47 47
 
48
-    /**
49
-     * Adds our personal data exporters registered by add-ons
50
-     *
51
-     * @param string[] $exporters
52
-     * @return string[]
53
-     */
54
-    public static function addExporters(array $exporters)
55
-    {
56
-        foreach (self::$exporters as $exporters_per_addon) {
57
-            $exporters = array_merge(
58
-                $exporters,
59
-                $exporters_per_addon
60
-            );
61
-        }
62
-        return $exporters;
63
-    }
48
+	/**
49
+	 * Adds our personal data exporters registered by add-ons
50
+	 *
51
+	 * @param string[] $exporters
52
+	 * @return string[]
53
+	 */
54
+	public static function addExporters(array $exporters)
55
+	{
56
+		foreach (self::$exporters as $exporters_per_addon) {
57
+			$exporters = array_merge(
58
+				$exporters,
59
+				$exporters_per_addon
60
+			);
61
+		}
62
+		return $exporters;
63
+	}
64 64
 }
65 65
 // End of file EE_Register_Personal_Data_Exporter.lib.php
66 66
 // Location: ${NAMESPACE}/EE_Register_Personal_Data_Exporter.lib.php
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Personal_Data_Eraser.lib.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
      */
29 29
     public static function register($identifier = '', array $setup_args = [])
30 30
     {
31
-        self::$erasers[ $identifier ] = $setup_args;
31
+        self::$erasers[$identifier] = $setup_args;
32 32
         // add to list of modules to be registered
33 33
         add_filter(
34 34
             'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers',
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public static function deregister($identifier = '')
44 44
     {
45
-        unset(self::$erasers[ $identifier ]);
45
+        unset(self::$erasers[$identifier]);
46 46
     }
47 47
 
48 48
 
Please login to merge, or discard this patch.
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -12,55 +12,55 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Register_Personal_Data_Eraser implements EEI_Plugin_API
14 14
 {
15
-    /**
16
-     * FQCN for all privacy policy generators
17
-     *
18
-     * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs
19
-     */
20
-    protected static $erasers = [];
15
+	/**
16
+	 * FQCN for all privacy policy generators
17
+	 *
18
+	 * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs
19
+	 */
20
+	protected static $erasers = [];
21 21
 
22 22
 
23
-    /**
24
-     * @param string $identifier
25
-     * @param array  $setup_args can be the fully qualified namespaces each containing only privacy policies,
26
-     *                           OR fully qualified class names of privacy policies
27
-     */
28
-    public static function register($identifier = '', array $setup_args = [])
29
-    {
30
-        self::$erasers[ $identifier ] = $setup_args;
31
-        // add to list of modules to be registered
32
-        add_filter(
33
-            'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers',
34
-            ['EE_Register_Personal_Data_Eraser', 'addErasers']
35
-        );
36
-    }
23
+	/**
24
+	 * @param string $identifier
25
+	 * @param array  $setup_args can be the fully qualified namespaces each containing only privacy policies,
26
+	 *                           OR fully qualified class names of privacy policies
27
+	 */
28
+	public static function register($identifier = '', array $setup_args = [])
29
+	{
30
+		self::$erasers[ $identifier ] = $setup_args;
31
+		// add to list of modules to be registered
32
+		add_filter(
33
+			'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers',
34
+			['EE_Register_Personal_Data_Eraser', 'addErasers']
35
+		);
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * @param string $identifier
41
-     */
42
-    public static function deregister($identifier = '')
43
-    {
44
-        unset(self::$erasers[ $identifier ]);
45
-    }
39
+	/**
40
+	 * @param string $identifier
41
+	 */
42
+	public static function deregister($identifier = '')
43
+	{
44
+		unset(self::$erasers[ $identifier ]);
45
+	}
46 46
 
47 47
 
48
-    /**
49
-     * Adds our personal data erasers registered by add-ons
50
-     *
51
-     * @param string[] $erasers
52
-     * @return string[]
53
-     */
54
-    public static function addErasers(array $erasers)
55
-    {
56
-        foreach (self::$erasers as $erasers_per_addon) {
57
-            $erasers = array_merge(
58
-                $erasers,
59
-                $erasers_per_addon
60
-            );
61
-        }
62
-        return $erasers;
63
-    }
48
+	/**
49
+	 * Adds our personal data erasers registered by add-ons
50
+	 *
51
+	 * @param string[] $erasers
52
+	 * @return string[]
53
+	 */
54
+	public static function addErasers(array $erasers)
55
+	{
56
+		foreach (self::$erasers as $erasers_per_addon) {
57
+			$erasers = array_merge(
58
+				$erasers,
59
+				$erasers_per_addon
60
+			);
61
+		}
62
+		return $erasers;
63
+	}
64 64
 }
65 65
 // End of file EE_Register_Personal_Data_Eraser.lib.php
66 66
 // Location: ${NAMESPACE}/EE_Register_Personal_Data_Eraser.lib.php
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Privacy_Policy.lib.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
      */
29 29
     public static function register($identifier = '', array $setup_args = [])
30 30
     {
31
-        self::$privacy_policies[ $identifier ] = $setup_args;
31
+        self::$privacy_policies[$identifier] = $setup_args;
32 32
         // add to list of modules to be registered
33 33
         add_filter(
34 34
             'FHEE__EventEspresso_core_services_privacy_policy_PrivacyPolicyManager__privacy_policies',
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public static function deregister($identifier = '')
44 44
     {
45
-        unset(self::$privacy_policies[ $identifier ]);
45
+        unset(self::$privacy_policies[$identifier]);
46 46
     }
47 47
 
48 48
 
Please login to merge, or discard this patch.
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -12,55 +12,55 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Register_Privacy_Policy implements EEI_Plugin_API
14 14
 {
15
-    /**
16
-     * FQCN for all privacy policy generators
17
-     *
18
-     * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs
19
-     */
20
-    protected static $privacy_policies = array();
15
+	/**
16
+	 * FQCN for all privacy policy generators
17
+	 *
18
+	 * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs
19
+	 */
20
+	protected static $privacy_policies = array();
21 21
 
22 22
 
23
-    /**
24
-     * @param string $identifier
25
-     * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies,
26
-     *              OR fully qualified class names of privacy policies
27
-     */
28
-    public static function register($identifier = '', array $setup_args = [])
29
-    {
30
-        self::$privacy_policies[ $identifier ] = $setup_args;
31
-        // add to list of modules to be registered
32
-        add_filter(
33
-            'FHEE__EventEspresso_core_services_privacy_policy_PrivacyPolicyManager__privacy_policies',
34
-            array('EE_Register_Privacy_Policy', 'addPrivacyPolicies')
35
-        );
36
-    }
23
+	/**
24
+	 * @param string $identifier
25
+	 * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies,
26
+	 *              OR fully qualified class names of privacy policies
27
+	 */
28
+	public static function register($identifier = '', array $setup_args = [])
29
+	{
30
+		self::$privacy_policies[ $identifier ] = $setup_args;
31
+		// add to list of modules to be registered
32
+		add_filter(
33
+			'FHEE__EventEspresso_core_services_privacy_policy_PrivacyPolicyManager__privacy_policies',
34
+			array('EE_Register_Privacy_Policy', 'addPrivacyPolicies')
35
+		);
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * @param string $identifier
41
-     */
42
-    public static function deregister($identifier = '')
43
-    {
44
-        unset(self::$privacy_policies[ $identifier ]);
45
-    }
39
+	/**
40
+	 * @param string $identifier
41
+	 */
42
+	public static function deregister($identifier = '')
43
+	{
44
+		unset(self::$privacy_policies[ $identifier ]);
45
+	}
46 46
 
47 47
 
48
-    /**
49
-     * Adds our privacy policy generators registered by add-ons
50
-     *
51
-     * @param string[] $privacy_policies
52
-     * @return string[]
53
-     */
54
-    public static function addPrivacyPolicies(array $privacy_policies)
55
-    {
56
-        foreach (self::$privacy_policies as $privacy_policies_per_addon) {
57
-            $privacy_policies = array_merge(
58
-                $privacy_policies,
59
-                $privacy_policies_per_addon
60
-            );
61
-        }
62
-        return $privacy_policies;
63
-    }
48
+	/**
49
+	 * Adds our privacy policy generators registered by add-ons
50
+	 *
51
+	 * @param string[] $privacy_policies
52
+	 * @return string[]
53
+	 */
54
+	public static function addPrivacyPolicies(array $privacy_policies)
55
+	{
56
+		foreach (self::$privacy_policies as $privacy_policies_per_addon) {
57
+			$privacy_policies = array_merge(
58
+				$privacy_policies,
59
+				$privacy_policies_per_addon
60
+			);
61
+		}
62
+		return $privacy_policies;
63
+	}
64 64
 }
65 65
 // End of file EE_Register_Privacy_Policy.lib.php
66 66
 // Location: ${NAMESPACE}/EE_Register_Privacy_Policy.lib.php
Please login to merge, or discard this patch.