Completed
Branch BUG/11302/correct-error-messag... (694f28)
by
unknown
29:59 queued 17:10
created
core/db_classes/EE_Price.class.php 3 patches
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
 	 *                             		    date_format and the second value is the time format
36 36
 	 * @return EE_Attendee
37 37
 	 */
38
-	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
39
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
40
-		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
38
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) {
39
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
40
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
41 41
 	}
42 42
 
43 43
 
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
 	 *                          		the website will be used.
49 49
 	 * @return EE_Attendee
50 50
 	 */
51
-	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
52
-		return new self( $props_n_values, TRUE, $timezone );
51
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null) {
52
+		return new self($props_n_values, TRUE, $timezone);
53 53
 	}
54 54
 
55 55
 
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 	 * @access        public
61 61
 	 * @param        int $PRT_ID
62 62
 	 */
63
-	public function set_type( $PRT_ID = 0 ) {
64
-		$this->set( 'PRT_ID', $PRT_ID );
63
+	public function set_type($PRT_ID = 0) {
64
+		$this->set('PRT_ID', $PRT_ID);
65 65
 	}
66 66
 
67 67
 
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
 	 * @access        public
73 73
 	 * @param        float $PRC_amount
74 74
 	 */
75
-	public function set_amount( $PRC_amount = 0.00 ) {
76
-		$this->set( 'PRC_amount', $PRC_amount );
75
+	public function set_amount($PRC_amount = 0.00) {
76
+		$this->set('PRC_amount', $PRC_amount);
77 77
 	}
78 78
 
79 79
 
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
 	 * @access        public
85 85
 	 * @param        string $PRC_name
86 86
 	 */
87
-	public function set_name( $PRC_name = '' ) {
88
-		$this->set( 'PRC_name', $PRC_name );
87
+	public function set_name($PRC_name = '') {
88
+		$this->set('PRC_name', $PRC_name);
89 89
 	}
90 90
 
91 91
 
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
 	 * @access        public
97 97
 	 * @param        string $PRC_desc
98 98
 	 */
99
-	public function set_description( $PRC_desc = '' ) {
100
-		$this->Set( 'PRC_desc', $PRC_desc );
99
+	public function set_description($PRC_desc = '') {
100
+		$this->Set('PRC_desc', $PRC_desc);
101 101
 	}
102 102
 
103 103
 
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 	* 		@access		public
109 109
 	*		@param		bool		$PRC_is_default
110 110
 	*/
111
-	public function set_is_default( $PRC_is_default = FALSE ) {
112
-		$this->set( 'PRC_is_default', $PRC_is_default );
111
+	public function set_is_default($PRC_is_default = FALSE) {
112
+		$this->set('PRC_is_default', $PRC_is_default);
113 113
 	}
114 114
 
115 115
 
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
 	* 		@access		public
121 121
 	*		@param		bool		$PRC_deleted
122 122
 	*/
123
-	public function set_deleted( $PRC_deleted = NULL ) {
124
-		$this->set( 'PRC_deleted', $PRC_deleted );
123
+	public function set_deleted($PRC_deleted = NULL) {
124
+		$this->set('PRC_deleted', $PRC_deleted);
125 125
 	}
126 126
 
127 127
 
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 	 * @return        int
133 133
 	 */
134 134
 	public function type() {
135
-		return $this->get( 'PRT_ID' );
135
+		return $this->get('PRT_ID');
136 136
 	}
137 137
 
138 138
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 	 * @return        float
144 144
 	 */
145 145
 	public function amount() {
146
-		return $this->get( 'PRC_amount' );
146
+		return $this->get('PRC_amount');
147 147
 	}
148 148
 
149 149
 
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 * @return        string
155 155
 	 */
156 156
 	public function name() {
157
-		return $this->get( 'PRC_name' );
157
+		return $this->get('PRC_name');
158 158
 	}
159 159
 
160 160
 
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 * @return        string
166 166
 	 */
167 167
 	public function desc() {
168
-		return $this->get( 'PRC_desc' );
168
+		return $this->get('PRC_desc');
169 169
 	}
170 170
 
171 171
 
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 	 * @return        int
177 177
 	 */
178 178
 	public function overrides() {
179
-		return $this->get( 'PRC_overrides' );
179
+		return $this->get('PRC_overrides');
180 180
 	}
181 181
 
182 182
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 	 * @return        int
188 188
 	 */
189 189
 	public function order() {
190
-		return $this->get( 'PRC_order' );
190
+		return $this->get('PRC_order');
191 191
 	}
192 192
 
193 193
 
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 	 * @return        bool
212 212
 	 */
213 213
 	public function is_default() {
214
-		return $this->get( 'PRC_is_default' );
214
+		return $this->get('PRC_is_default');
215 215
 	}
216 216
 
217 217
 
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 	 * @return        bool
223 223
 	 */
224 224
 	public function deleted() {
225
-		return $this->get( 'PRC_deleted' );
225
+		return $this->get('PRC_deleted');
226 226
 	}
227 227
 
228 228
 
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 	 * @return bool
232 232
 	 */
233 233
 	public function parent() {
234
-		return $this->get( 'PRC_parent' );
234
+		return $this->get('PRC_parent');
235 235
 	}
236 236
 
237 237
 
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 	 * @return EE_Price_Type
254 254
 	 */
255 255
 	public function type_obj() {
256
-		return $this->get_first_related( 'Price_Type' );
256
+		return $this->get_first_related('Price_Type');
257 257
 	}
258 258
 
259 259
 
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 	 */
276 276
 	public function is_percent() {
277 277
 		$price_type = $this->type_obj();
278
-		return $price_type->get( 'PRT_is_percent' );
278
+		return $price_type->get('PRT_is_percent');
279 279
 	}
280 280
 
281 281
 
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 	 * @return string
288 288
 	 */
289 289
 	public function pretty_price() {
290
-		return ! $this->is_percent() ? $this->get_pretty('PRC_amount') : $this->get('PRC_amount') . '%';
290
+		return ! $this->is_percent() ? $this->get_pretty('PRC_amount') : $this->get('PRC_amount').'%';
291 291
 	}
292 292
 
293 293
 
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 	 * @return mixed
297 297
 	 */
298 298
 	public function get_price_without_currency_symbol() {
299
-		return str_replace( EE_Registry::instance()->CFG->currency->sign, '', $this->get_pretty( 'PRC_amount' ) );
299
+		return str_replace(EE_Registry::instance()->CFG->currency->sign, '', $this->get_pretty('PRC_amount'));
300 300
 	}
301 301
 }
302 302
 
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@
 block discarded – undo
46 46
 	 * @param array $props_n_values  incoming values from the database
47 47
 	 * @param string $timezone  incoming timezone as set by the model.  If not set the timezone for
48 48
 	 *                          		the website will be used.
49
-	 * @return EE_Attendee
49
+	 * @return EE_Price
50 50
 	 */
51 51
 	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
52 52
 		return new self( $props_n_values, TRUE, $timezone );
Please login to merge, or discard this patch.
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -103,11 +103,11 @@  discard block
 block discarded – undo
103 103
 
104 104
 
105 105
 	/**
106
-	*		set is_default
107
-	*
108
-	* 		@access		public
109
-	*		@param		bool		$PRC_is_default
110
-	*/
106
+	 *		set is_default
107
+	 *
108
+	 * 		@access		public
109
+	 *		@param		bool		$PRC_is_default
110
+	 */
111 111
 	public function set_is_default( $PRC_is_default = FALSE ) {
112 112
 		$this->set( 'PRC_is_default', $PRC_is_default );
113 113
 	}
@@ -115,11 +115,11 @@  discard block
 block discarded – undo
115 115
 
116 116
 
117 117
 	/**
118
-	*		set deleted
119
-	*
120
-	* 		@access		public
121
-	*		@param		bool		$PRC_deleted
122
-	*/
118
+	 *		set deleted
119
+	 *
120
+	 * 		@access		public
121
+	 *		@param		bool		$PRC_deleted
122
+	 */
123 123
 	public function set_deleted( $PRC_deleted = NULL ) {
124 124
 		$this->set( 'PRC_deleted', $PRC_deleted );
125 125
 	}
Please login to merge, or discard this patch.
core/helpers/EEH_File.helper.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -325,8 +325,8 @@
 block discarded – undo
325 325
 		//eg if given "/var/something/somewhere/", we want to get "somewhere"'s
326 326
 		//parent folder, "/var/something/"
327 327
 		$ds = strlen($file_or_folder_path) > 1
328
-            ? strrpos($file_or_folder_path, DS, -2)
329
-            : strlen($file_or_folder_path);
328
+			? strrpos($file_or_folder_path, DS, -2)
329
+			: strlen($file_or_folder_path);
330 330
 		return substr($file_or_folder_path, 0, $ds + 1);
331 331
 	}
332 332
 
Please login to merge, or discard this patch.
Spacing   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -38,30 +38,30 @@  discard block
 block discarded – undo
38 38
 	 * @throws EE_Error if filesystem credentials are required
39 39
 	 * @return WP_Filesystem_Base
40 40
 	 */
41
-	private static function _get_wp_filesystem( $filepath = null) {
42
-		if( apply_filters(
41
+	private static function _get_wp_filesystem($filepath = null) {
42
+		if (apply_filters(
43 43
 				'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct',
44
-				$filepath && EEH_File::is_in_uploads_folder( $filepath ),
45
-				$filepath ) ) {
46
-			if( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct ) {
47
-				require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
44
+				$filepath && EEH_File::is_in_uploads_folder($filepath),
45
+				$filepath )) {
46
+			if ( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) {
47
+				require_once(ABSPATH.'wp-admin/includes/class-wp-filesystem-base.php');
48 48
 				$method = 'direct';
49
-				$wp_filesystem_direct_file = apply_filters( 'filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method );
49
+				$wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH.'wp-admin/includes/class-wp-filesystem-'.$method.'.php', $method);
50 50
 				//check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem()
51
-				if ( ! defined('FS_CHMOD_DIR') ) {
52
-					define('FS_CHMOD_DIR', ( fileperms( ABSPATH ) & 0777 | 0755 ) );
51
+				if ( ! defined('FS_CHMOD_DIR')) {
52
+					define('FS_CHMOD_DIR', (fileperms(ABSPATH) & 0777 | 0755));
53 53
 				}
54
-				if ( ! defined('FS_CHMOD_FILE') ) {
55
-					define('FS_CHMOD_FILE', ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ) );
54
+				if ( ! defined('FS_CHMOD_FILE')) {
55
+					define('FS_CHMOD_FILE', (fileperms(ABSPATH.'index.php') & 0777 | 0644));
56 56
 				}
57
-				require_once( $wp_filesystem_direct_file );
58
-				EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct( array() );
57
+				require_once($wp_filesystem_direct_file);
58
+				EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array());
59 59
 			}
60 60
 			return EEH_File::$_wp_filesystem_direct;
61 61
 		}
62 62
 		global $wp_filesystem;
63 63
 		// no filesystem setup ???
64
-		if ( ! $wp_filesystem instanceof WP_Filesystem_Base ) {
64
+		if ( ! $wp_filesystem instanceof WP_Filesystem_Base) {
65 65
 			// if some eager beaver's just trying to get in there too early...
66 66
 			// let them do it, because we are one of those eager beavers! :P
67 67
 			/**
@@ -74,34 +74,34 @@  discard block
 block discarded – undo
74 74
 			 * and there may be troubles if the WP files are owned by a different user
75 75
 			 * than the server user. But both of these issues should exist in 4.4 and earlier too
76 76
 			 */
77
-			if ( FALSE && ! did_action( 'wp_loaded' )) {
77
+			if (FALSE && ! did_action('wp_loaded')) {
78 78
 				$msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso');
79
-				if ( WP_DEBUG ) {
80
-					$msg .= '<br />' .  __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
79
+				if (WP_DEBUG) {
80
+					$msg .= '<br />'.__('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
81 81
 				}
82
-				throw new EE_Error( $msg );
82
+				throw new EE_Error($msg);
83 83
 			} else {
84 84
 				// should be loaded if we are past the wp_loaded hook...
85
-				if ( ! function_exists( 'WP_Filesystem' )) {
86
-					require_once( ABSPATH . 'wp-admin/includes/file.php' );
87
-					require_once( ABSPATH . 'wp-admin/includes/template.php' );
85
+				if ( ! function_exists('WP_Filesystem')) {
86
+					require_once(ABSPATH.'wp-admin/includes/file.php');
87
+					require_once(ABSPATH.'wp-admin/includes/template.php');
88 88
 				}
89 89
 				// turn on output buffering so that we can capture the credentials form
90 90
 				ob_start();
91
-				$credentials = request_filesystem_credentials( '' );
91
+				$credentials = request_filesystem_credentials('');
92 92
 				// store credentials form for the time being
93 93
 				EEH_File::$_credentials_form = ob_get_clean();
94 94
 				// basically check for direct or previously configured access
95
-				if ( ! WP_Filesystem( $credentials ) ) {
95
+				if ( ! WP_Filesystem($credentials)) {
96 96
 					// if credentials do NOT exist
97
-					if ( $credentials === FALSE ) {
98
-						add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 );
99
-						throw new EE_Error( __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'));
100
-					} elseif( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
101
-						add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 );
97
+					if ($credentials === FALSE) {
98
+						add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
99
+						throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'));
100
+					} elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
101
+						add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
102 102
 						throw new EE_Error(
103 103
 								sprintf(
104
-										__( 'WP Filesystem Error: $1%s', 'event_espresso' ),
104
+										__('WP Filesystem Error: $1%s', 'event_espresso'),
105 105
 										$wp_filesystem->errors->get_error_message() ) );
106 106
 					}
107 107
 				}
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
 	 * display_request_filesystem_credentials_form
115 115
 	 */
116 116
 	public static function display_request_filesystem_credentials_form() {
117
-		if ( ! empty( EEH_File::$_credentials_form )) {
118
-			echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>';
117
+		if ( ! empty(EEH_File::$_credentials_form)) {
118
+			echo '<div class="updated espresso-notices-attention"><p>'.EEH_File::$_credentials_form.'</p></div>';
119 119
 		}
120 120
 	}
121 121
 
@@ -133,29 +133,29 @@  discard block
 block discarded – undo
133 133
 	 * @throws EE_Error if filesystem credentials are required
134 134
 	 * @return bool
135 135
 	 */
136
-	public static function verify_filepath_and_permissions( $full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '' ) {
136
+	public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '') {
137 137
 		// load WP_Filesystem and set file permissions
138
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
139
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
140
-		if ( ! $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) )) {
141
-			$file_name = ! empty( $type_of_file ) ? $file_name . ' ' . $type_of_file : $file_name;
142
-			$file_name .= ! empty( $file_ext ) ? ' file' : ' folder';
138
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
139
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
140
+		if ( ! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
141
+			$file_name = ! empty($type_of_file) ? $file_name.' '.$type_of_file : $file_name;
142
+			$file_name .= ! empty($file_ext) ? ' file' : ' folder';
143 143
 			$msg = sprintf(
144
-				__( 'The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso' ),
144
+				__('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'),
145 145
 				$file_name,
146 146
 				'<br />'
147 147
 			);
148
-			if ( EEH_File::exists( $full_file_path )) {
149
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, $type_of_file );
148
+			if (EEH_File::exists($full_file_path)) {
149
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file);
150 150
 			} else {
151 151
 				// no file permissions means the file was not found
152 152
 				$msg .= sprintf(
153
-					__( 'Please ensure the following path is correct: "%s".', 'event_espresso' ),
153
+					__('Please ensure the following path is correct: "%s".', 'event_espresso'),
154 154
 					$full_file_path
155 155
 				);
156 156
 			}
157
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
158
-				throw new EE_Error( $msg . '||' . $msg );
157
+			if (defined('WP_DEBUG') && WP_DEBUG) {
158
+				throw new EE_Error($msg.'||'.$msg);
159 159
 			}
160 160
 			return FALSE;
161 161
 		}
@@ -173,24 +173,24 @@  discard block
 block discarded – undo
173 173
 	 * @throws EE_Error if filesystem credentials are required
174 174
 	 * @return string
175 175
 	 */
176
-	private static function _permissions_error_for_unreadable_filepath( $full_file_path = '', $type_of_file = '' ){
176
+	private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '') {
177 177
 		// load WP_Filesystem and set file permissions
178
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
178
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
179 179
 		// check file permissions
180
-		$perms = $wp_filesystem->getchmod( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) );
181
-		if ( $perms ) {
180
+		$perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
181
+		if ($perms) {
182 182
 			// file permissions exist, but way be set incorrectly
183
-			$type_of_file = ! empty( $type_of_file ) ? $type_of_file . ' ' : '';
184
-			$type_of_file .= ! empty( $type_of_file ) ? 'file' : 'folder';
183
+			$type_of_file = ! empty($type_of_file) ? $type_of_file.' ' : '';
184
+			$type_of_file .= ! empty($type_of_file) ? 'file' : 'folder';
185 185
 			return sprintf(
186
-				__( 'File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso' ),
186
+				__('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'),
187 187
 				$type_of_file,
188 188
 				$perms
189 189
 			);
190 190
 		} else {
191 191
 			// file exists but file permissions could not be read ?!?!
192 192
 			return sprintf(
193
-				__( 'Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso' ),
193
+				__('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'),
194 194
 				$full_file_path
195 195
 			);
196 196
 		}
@@ -208,35 +208,35 @@  discard block
 block discarded – undo
208 208
 	 * can't write to it
209 209
 	 * @return bool false if folder isn't writable; true if it exists and is writeable,
210 210
 	 */
211
-	public static function ensure_folder_exists_and_is_writable( $folder = '' ){
212
-		if ( empty( $folder )) {
211
+	public static function ensure_folder_exists_and_is_writable($folder = '') {
212
+		if (empty($folder)) {
213 213
 			return false;
214 214
 		}
215 215
 		// remove ending DS
216
-		$folder = EEH_File::standardise_directory_separators( rtrim( $folder, '/\\' ));
217
-		$parent_folder = EEH_File::get_parent_folder( $folder );
216
+		$folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\'));
217
+		$parent_folder = EEH_File::get_parent_folder($folder);
218 218
 		// add DS to folder
219
-		$folder = EEH_File::end_with_directory_separator( $folder );
220
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $folder );
221
-		if ( ! $wp_filesystem->is_dir( EEH_File::convert_local_filepath_to_remote_filepath( $folder ) ) ) {
219
+		$folder = EEH_File::end_with_directory_separator($folder);
220
+		$wp_filesystem = EEH_File::_get_wp_filesystem($folder);
221
+		if ( ! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
222 222
 			//ok so it doesn't exist. Does its parent? Can we write to it?
223
-			if(	! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) {
223
+			if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
224 224
 				return false;
225 225
 			}
226
-			if ( ! EEH_File::verify_is_writable( $parent_folder, 'folder' )) {
226
+			if ( ! EEH_File::verify_is_writable($parent_folder, 'folder')) {
227 227
 				return false;
228 228
 			} else {
229
-				if ( ! $wp_filesystem->mkdir( EEH_File::convert_local_filepath_to_remote_filepath(  $folder ) ) ) {
230
-					if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
231
-						$msg = sprintf( __( '"%s" could not be created.', 'event_espresso' ), $folder );
232
-						$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $folder );
233
-						throw new EE_Error( $msg );
229
+				if ( ! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
230
+					if (defined('WP_DEBUG') && WP_DEBUG) {
231
+						$msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder);
232
+						$msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder);
233
+						throw new EE_Error($msg);
234 234
 					}
235 235
 					return false;
236 236
 				}
237
-				EEH_File::add_index_file( $folder );
237
+				EEH_File::add_index_file($folder);
238 238
 			}
239
-		} elseif ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
239
+		} elseif ( ! EEH_File::verify_is_writable($folder, 'folder')) {
240 240
 			return false;
241 241
 		}
242 242
 		return true;
@@ -251,15 +251,15 @@  discard block
 block discarded – undo
251 251
 	 * @throws EE_Error if filesystem credentials are required
252 252
 	 * @return bool
253 253
 	 */
254
-	public static function verify_is_writable( $full_path = '', $file_or_folder = 'folder' ){
254
+	public static function verify_is_writable($full_path = '', $file_or_folder = 'folder') {
255 255
 		// load WP_Filesystem and set file permissions
256
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_path );
257
-		$full_path = EEH_File::standardise_directory_separators( $full_path );
258
-		if ( ! $wp_filesystem->is_writable( EEH_File::convert_local_filepath_to_remote_filepath( $full_path ) ) ) {
259
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
260
-				$msg = sprintf( __( 'The "%1$s" %2$s is not writable.', 'event_espresso' ), $full_path, $file_or_folder );
261
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_path );
262
-				throw new EE_Error( $msg );
256
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_path);
257
+		$full_path = EEH_File::standardise_directory_separators($full_path);
258
+		if ( ! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) {
259
+			if (defined('WP_DEBUG') && WP_DEBUG) {
260
+				$msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder);
261
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path);
262
+				throw new EE_Error($msg);
263 263
 			}
264 264
 			return FALSE;
265 265
 		}
@@ -276,25 +276,25 @@  discard block
 block discarded – undo
276 276
 	 * @throws EE_Error if filesystem credentials are required
277 277
 	 * @return bool
278 278
 	 */
279
-	public static function ensure_file_exists_and_is_writable( $full_file_path = '' ) {
279
+	public static function ensure_file_exists_and_is_writable($full_file_path = '') {
280 280
 		// load WP_Filesystem and set file permissions
281
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
282
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
283
-		$parent_folder = EEH_File::get_parent_folder( $full_file_path );
284
-		if ( ! EEH_File::exists( $full_file_path )) {
285
-			if( ! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) {
281
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
282
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
283
+		$parent_folder = EEH_File::get_parent_folder($full_file_path);
284
+		if ( ! EEH_File::exists($full_file_path)) {
285
+			if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
286 286
 				return false;
287 287
 			}
288
-			if ( ! $wp_filesystem->touch( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ) {
289
-				if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
290
-					$msg = sprintf( __( 'The "%s" file could not be created.', 'event_espresso' ), $full_file_path );
291
-					$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path );
292
-					throw new EE_Error( $msg );
288
+			if ( ! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
289
+				if (defined('WP_DEBUG') && WP_DEBUG) {
290
+					$msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path);
291
+					$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
292
+					throw new EE_Error($msg);
293 293
 				}
294 294
 				return false;
295 295
 			}
296 296
 		}
297
-		if ( ! EEH_File::verify_is_writable( $full_file_path, 'file' )) {
297
+		if ( ! EEH_File::verify_is_writable($full_file_path, 'file')) {
298 298
 			return false;
299 299
 		}
300 300
 		return true;
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 	 * @param string $file_or_folder_path
307 307
 	 * @return string parent folder, ENDING with a directory separator
308 308
 	 */
309
-	public static function get_parent_folder( $file_or_folder_path ) {
309
+	public static function get_parent_folder($file_or_folder_path) {
310 310
 		//find the last DS, ignoring a DS on the very end
311 311
 		//eg if given "/var/something/somewhere/", we want to get "somewhere"'s
312 312
 		//parent folder, "/var/something/"
@@ -328,12 +328,12 @@  discard block
 block discarded – undo
328 328
 	 * @throws EE_Error if filesystem credentials are required
329 329
 	 * @return string
330 330
 	 */
331
-	public static function get_file_contents( $full_file_path = '' ){
332
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
333
-		if ( EEH_File::verify_filepath_and_permissions( $full_file_path, EEH_File::get_filename_from_filepath( $full_file_path ) , EEH_File::get_file_extension( $full_file_path ))) {
331
+	public static function get_file_contents($full_file_path = '') {
332
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
333
+		if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) {
334 334
 			// load WP_Filesystem and set file permissions
335
-			$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
336
-			return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) );
335
+			$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
336
+			return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
337 337
 		}
338 338
 		return '';
339 339
 	}
@@ -348,26 +348,26 @@  discard block
 block discarded – undo
348 348
 	 * @throws EE_Error if filesystem credentials are required
349 349
 	 * @return bool
350 350
 	 */
351
-	public static function write_to_file( $full_file_path = '', $file_contents = '', $file_type = '' ){
352
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
353
-		$file_type = ! empty( $file_type ) ? rtrim( $file_type, ' ' ) . ' ' : '';
354
-		$folder = EEH_File::remove_filename_from_filepath( $full_file_path );
355
-		if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
356
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
357
-				$msg = sprintf( __( 'The %1$sfile located at "%2$s" is not writable.', 'event_espresso' ), $file_type, $full_file_path );
358
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path );
359
-				throw new EE_Error( $msg );
351
+	public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') {
352
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
353
+		$file_type = ! empty($file_type) ? rtrim($file_type, ' ').' ' : '';
354
+		$folder = EEH_File::remove_filename_from_filepath($full_file_path);
355
+		if ( ! EEH_File::verify_is_writable($folder, 'folder')) {
356
+			if (defined('WP_DEBUG') && WP_DEBUG) {
357
+				$msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path);
358
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
359
+				throw new EE_Error($msg);
360 360
 			}
361 361
 			return FALSE;
362 362
 		}
363 363
 		// load WP_Filesystem and set file permissions
364
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
364
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
365 365
 		// write the file
366
-		if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ), $file_contents )) {
367
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
368
-				$msg = sprintf( __( 'The %1$sfile located at "%2$s" could not be written to.', 'event_espresso' ), $file_type, $full_file_path );
369
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, 'f' );
370
-				throw new EE_Error( $msg );
366
+		if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) {
367
+			if (defined('WP_DEBUG') && WP_DEBUG) {
368
+				$msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path);
369
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f');
370
+				throw new EE_Error($msg);
371 371
 			}
372 372
 			return FALSE;
373 373
 		}
@@ -383,9 +383,9 @@  discard block
 block discarded – undo
383 383
 	 * @throws EE_Error if filesystem credentials are required
384 384
 	 * @return boolean
385 385
 	 */
386
-	public static function delete( $filepath, $recursive = false, $type = false ) {
386
+	public static function delete($filepath, $recursive = false, $type = false) {
387 387
 		$wp_filesystem = EEH_File::_get_wp_filesystem();
388
-		return $wp_filesystem->delete( $filepath, $recursive, $type ) ? TRUE : FALSE;
388
+		return $wp_filesystem->delete($filepath, $recursive, $type) ? TRUE : FALSE;
389 389
 	}
390 390
 
391 391
 
@@ -397,9 +397,9 @@  discard block
 block discarded – undo
397 397
 	 * @throws EE_Error if filesystem credentials are required
398 398
 	 * @return bool
399 399
 	 */
400
-	public static function exists( $full_file_path = '' ) {
401
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
402
-		return $wp_filesystem->exists( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ? TRUE : FALSE;
400
+	public static function exists($full_file_path = '') {
401
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
402
+		return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? TRUE : FALSE;
403 403
 	}
404 404
 
405 405
 
@@ -412,9 +412,9 @@  discard block
 block discarded – undo
412 412
 	 * @throws EE_Error if filesystem credentials are required
413 413
 	 * @return bool
414 414
 	 */
415
-	public static function is_readable( $full_file_path = '' ) {
416
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
417
-		if( $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath(  $full_file_path ) ) ) {
415
+	public static function is_readable($full_file_path = '') {
416
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
417
+		if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
418 418
 			return true;
419 419
 		} else {
420 420
 			return false;
@@ -430,8 +430,8 @@  discard block
 block discarded – undo
430 430
 	 * @param string $full_file_path
431 431
 	 * @return string
432 432
 	 */
433
-	public static function remove_filename_from_filepath( $full_file_path = '' ) {
434
-		return pathinfo( $full_file_path, PATHINFO_DIRNAME );
433
+	public static function remove_filename_from_filepath($full_file_path = '') {
434
+		return pathinfo($full_file_path, PATHINFO_DIRNAME);
435 435
 	}
436 436
 
437 437
 
@@ -441,8 +441,8 @@  discard block
 block discarded – undo
441 441
 	 * @param string $full_file_path
442 442
 	 * @return string
443 443
 	 */
444
-	public static function get_filename_from_filepath( $full_file_path = '' ) {
445
-		return pathinfo( $full_file_path, PATHINFO_BASENAME );
444
+	public static function get_filename_from_filepath($full_file_path = '') {
445
+		return pathinfo($full_file_path, PATHINFO_BASENAME);
446 446
 	}
447 447
 
448 448
 
@@ -452,8 +452,8 @@  discard block
 block discarded – undo
452 452
 	 * @param string $full_file_path
453 453
 	 * @return string
454 454
 	 */
455
-	public static function get_file_extension( $full_file_path = '' ) {
456
-		return pathinfo( $full_file_path, PATHINFO_EXTENSION );
455
+	public static function get_file_extension($full_file_path = '') {
456
+		return pathinfo($full_file_path, PATHINFO_EXTENSION);
457 457
 	}
458 458
 
459 459
 
@@ -464,10 +464,10 @@  discard block
 block discarded – undo
464 464
 	 * @throws EE_Error if filesystem credentials are required
465 465
 	 * @return bool
466 466
 	 */
467
-	public static function add_htaccess_deny_from_all( $folder = '' ) {
468
-		$folder = EEH_File::standardise_and_end_with_directory_separator( $folder );
469
-		if ( ! EEH_File::exists( $folder . '.htaccess' ) ) {
470
-			if ( ! EEH_File::write_to_file( $folder . '.htaccess', 'deny from all', '.htaccess' )) {
467
+	public static function add_htaccess_deny_from_all($folder = '') {
468
+		$folder = EEH_File::standardise_and_end_with_directory_separator($folder);
469
+		if ( ! EEH_File::exists($folder.'.htaccess')) {
470
+			if ( ! EEH_File::write_to_file($folder.'.htaccess', 'deny from all', '.htaccess')) {
471 471
 				return FALSE;
472 472
 			}
473 473
 		}
@@ -481,10 +481,10 @@  discard block
 block discarded – undo
481 481
 	 * @throws EE_Error if filesystem credentials are required
482 482
 	 * @return boolean
483 483
 	 */
484
-	public static function add_index_file( $folder ) {
485
-		$folder = EEH_File::standardise_and_end_with_directory_separator( $folder );
486
-		if ( ! EEH_File::exists( $folder . 'index.php' ) ) {
487
-			if ( ! EEH_File::write_to_file( $folder . 'index.php', 'You are not permitted to read from this folder', '.php' )) {
484
+	public static function add_index_file($folder) {
485
+		$folder = EEH_File::standardise_and_end_with_directory_separator($folder);
486
+		if ( ! EEH_File::exists($folder.'index.php')) {
487
+			if ( ! EEH_File::write_to_file($folder.'index.php', 'You are not permitted to read from this folder', '.php')) {
488 488
 				return false;
489 489
 			}
490 490
 		}
@@ -499,11 +499,11 @@  discard block
 block discarded – undo
499 499
 	 * @param string $file_path
500 500
 	 * @return string
501 501
 	 */
502
-	public static function get_classname_from_filepath_with_standard_filename( $file_path ){
502
+	public static function get_classname_from_filepath_with_standard_filename($file_path) {
503 503
 		//extract file from path
504
-		$filename = basename( $file_path );
504
+		$filename = basename($file_path);
505 505
 		//now remove the first period and everything after
506
-		$pos_of_first_period = strpos( $filename,'.' );
506
+		$pos_of_first_period = strpos($filename, '.');
507 507
 		return substr($filename, 0, $pos_of_first_period);
508 508
 	}
509 509
 
@@ -515,8 +515,8 @@  discard block
 block discarded – undo
515 515
 	 * @param string $file_path
516 516
 	 * @return string
517 517
 	 */
518
-	public static function standardise_directory_separators( $file_path ){
519
-		return str_replace( array( '\\', '/' ), DS, $file_path );
518
+	public static function standardise_directory_separators($file_path) {
519
+		return str_replace(array('\\', '/'), DS, $file_path);
520 520
 	}
521 521
 
522 522
 
@@ -527,8 +527,8 @@  discard block
 block discarded – undo
527 527
 	 * @param string $file_path
528 528
 	 * @return string
529 529
 	 */
530
-	public static function end_with_directory_separator( $file_path ){
531
-		return rtrim( $file_path, '/\\' ) . DS;
530
+	public static function end_with_directory_separator($file_path) {
531
+		return rtrim($file_path, '/\\').DS;
532 532
 	}
533 533
 
534 534
 
@@ -538,8 +538,8 @@  discard block
 block discarded – undo
538 538
 	 * @param $file_path
539 539
 	 * @return string
540 540
 	 */
541
-	public static function standardise_and_end_with_directory_separator( $file_path ){
542
-		return self::end_with_directory_separator( self::standardise_directory_separators( $file_path ));
541
+	public static function standardise_and_end_with_directory_separator($file_path) {
542
+		return self::end_with_directory_separator(self::standardise_directory_separators($file_path));
543 543
 	}
544 544
 
545 545
 
@@ -556,21 +556,21 @@  discard block
 block discarded – undo
556 556
 	 *		if $index_numerically == FALSE (Default) keys are what the class names SHOULD be;
557 557
 	 *		 and values are their filepaths
558 558
 	 */
559
-	public static function get_contents_of_folders( $folder_paths = array(), $index_numerically = FALSE ){
559
+	public static function get_contents_of_folders($folder_paths = array(), $index_numerically = FALSE) {
560 560
 		$class_to_folder_path = array();
561
-		foreach( $folder_paths as $folder_path ){
562
-			$folder_path = self::standardise_and_end_with_directory_separator( $folder_path );
561
+		foreach ($folder_paths as $folder_path) {
562
+			$folder_path = self::standardise_and_end_with_directory_separator($folder_path);
563 563
 			// load WP_Filesystem and set file permissions
564
-			$files_in_folder = glob( $folder_path . '*' );
564
+			$files_in_folder = glob($folder_path.'*');
565 565
 			$class_to_folder_path = array();
566
-			if ( $files_in_folder ) {
567
-				foreach( $files_in_folder as $file_path ){
566
+			if ($files_in_folder) {
567
+				foreach ($files_in_folder as $file_path) {
568 568
 					//only add files, not folders
569
-					if ( ! is_dir( $file_path )) {
570
-						if ( $index_numerically ) {
569
+					if ( ! is_dir($file_path)) {
570
+						if ($index_numerically) {
571 571
 							$class_to_folder_path[] = $file_path;
572 572
 						} else {
573
-							$classname = self::get_classname_from_filepath_with_standard_filename( $file_path );
573
+							$classname = self::get_classname_from_filepath_with_standard_filename($file_path);
574 574
 							$class_to_folder_path[$classname] = $file_path;
575 575
 						}
576 576
 					}
@@ -590,39 +590,39 @@  discard block
 block discarded – undo
590 590
 	 * @throws EE_Error if filesystem credentials are required
591 591
 	 * @return boolean success
592 592
 	 */
593
-	public static function copy( $source_file, $destination_file, $overwrite = FALSE ){
594
-		$full_source_path = EEH_File::standardise_directory_separators( $source_file );
595
-		if( ! EEH_File::exists( $full_source_path ) ){
596
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
597
-				$msg = sprintf( __( 'The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso' ), $full_source_path );
598
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path );
599
-				throw new EE_Error( $msg );
593
+	public static function copy($source_file, $destination_file, $overwrite = FALSE) {
594
+		$full_source_path = EEH_File::standardise_directory_separators($source_file);
595
+		if ( ! EEH_File::exists($full_source_path)) {
596
+			if (defined('WP_DEBUG') && WP_DEBUG) {
597
+				$msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path);
598
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path);
599
+				throw new EE_Error($msg);
600 600
 			}
601 601
 			return FALSE;
602 602
 		}
603 603
 
604
-		$full_dest_path = EEH_File::standardise_directory_separators( $destination_file );
605
-		$folder = EEH_File::remove_filename_from_filepath( $full_dest_path );
606
-		if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
607
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
608
-				$msg = sprintf( __( 'The file located at "%2$s" is not writable.', 'event_espresso' ), $full_dest_path );
609
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_dest_path );
610
-				throw new EE_Error( $msg );
604
+		$full_dest_path = EEH_File::standardise_directory_separators($destination_file);
605
+		$folder = EEH_File::remove_filename_from_filepath($full_dest_path);
606
+		if ( ! EEH_File::verify_is_writable($folder, 'folder')) {
607
+			if (defined('WP_DEBUG') && WP_DEBUG) {
608
+				$msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path);
609
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path);
610
+				throw new EE_Error($msg);
611 611
 			}
612 612
 			return FALSE;
613 613
 		}
614 614
 
615 615
 		// load WP_Filesystem and set file permissions
616
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $destination_file );
616
+		$wp_filesystem = EEH_File::_get_wp_filesystem($destination_file);
617 617
 		// write the file
618 618
 		if ( ! $wp_filesystem->copy(
619
-						EEH_File::convert_local_filepath_to_remote_filepath( $full_source_path ),
620
-						EEH_File::convert_local_filepath_to_remote_filepath( $full_dest_path ),
619
+						EEH_File::convert_local_filepath_to_remote_filepath($full_source_path),
620
+						EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path),
621 621
 						$overwrite )) {
622
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
623
-				$msg = sprintf( __( 'Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso' ), $full_source_path );
624
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path, 'f' );
625
-				throw new EE_Error( $msg );
622
+			if (defined('WP_DEBUG') && WP_DEBUG) {
623
+				$msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path);
624
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f');
625
+				throw new EE_Error($msg);
626 626
 			}
627 627
 			return FALSE;
628 628
 		}
@@ -634,9 +634,9 @@  discard block
 block discarded – undo
634 634
 	 * @param string $filepath
635 635
 	 * @return boolean
636 636
 	 */
637
-	public static function is_in_uploads_folder( $filepath ) {
637
+	public static function is_in_uploads_folder($filepath) {
638 638
 		$uploads = wp_upload_dir();
639
-		return strpos( $filepath, $uploads[ 'basedir' ] ) === 0 ? true : false;
639
+		return strpos($filepath, $uploads['basedir']) === 0 ? true : false;
640 640
 	}
641 641
 
642 642
 	/**
@@ -651,9 +651,9 @@  discard block
 block discarded – undo
651 651
 	 * @return string the remote filepath (eg the filepath the filesystem method, eg
652 652
 	 * ftp or ssh, will use to access the folder
653 653
 	 */
654
-	public static function convert_local_filepath_to_remote_filepath( $local_filepath ) {
655
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $local_filepath );
656
-		return str_replace( WP_CONTENT_DIR . DS, $wp_filesystem->wp_content_dir(), $local_filepath );
654
+	public static function convert_local_filepath_to_remote_filepath($local_filepath) {
655
+		$wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath);
656
+		return str_replace(WP_CONTENT_DIR.DS, $wp_filesystem->wp_content_dir(), $local_filepath);
657 657
 	}
658 658
 }
659 659
 // End of file EEH_File.helper.php
Please login to merge, or discard this patch.
core/db_models/fields/EE_Float_Field.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
      * @param string $table_column
13 13
      * @param string $nicename
14 14
      * @param bool   $nullable
15
-     * @param null   $default_value
15
+     * @param integer|null   $default_value
16 16
      */
17 17
     public function __construct($table_column, $nicename, $nullable, $default_value = null)
18 18
     {
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
      * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first.
28 28
      * Returns a float
29 29
      *
30
-     * @param type $value_inputted_for_field_on_model_object
30
+     * @param string $value_inputted_for_field_on_model_object
31 31
      * @return float
32 32
      */
33 33
     function prepare_for_set($value_inputted_for_field_on_model_object)
Please login to merge, or discard this patch.
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -8,64 +8,64 @@
 block discarded – undo
8 8
 class EE_Float_Field extends EE_Model_Field_Base
9 9
 {
10 10
 
11
-    /**
12
-     * @param string $table_column
13
-     * @param string $nicename
14
-     * @param bool   $nullable
15
-     * @param null   $default_value
16
-     */
17
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
18
-    {
19
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
20
-        $this->setSchemaType('number');
21
-    }
11
+	/**
12
+	 * @param string $table_column
13
+	 * @param string $nicename
14
+	 * @param bool   $nullable
15
+	 * @param null   $default_value
16
+	 */
17
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
18
+	{
19
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
20
+		$this->setSchemaType('number');
21
+	}
22 22
 
23 23
 
24
-    /**
25
-     * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc.
26
-     * However, treats commas and periods as thousand-separators ro decimal marks, as indicate by the config's currency.
27
-     * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first.
28
-     * Returns a float
29
-     *
30
-     * @param type $value_inputted_for_field_on_model_object
31
-     * @return float
32
-     */
33
-    function prepare_for_set($value_inputted_for_field_on_model_object)
34
-    {
24
+	/**
25
+	 * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc.
26
+	 * However, treats commas and periods as thousand-separators ro decimal marks, as indicate by the config's currency.
27
+	 * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first.
28
+	 * Returns a float
29
+	 *
30
+	 * @param type $value_inputted_for_field_on_model_object
31
+	 * @return float
32
+	 */
33
+	function prepare_for_set($value_inputted_for_field_on_model_object)
34
+	{
35 35
 //		echo __LINE__."$value_inputted_for_field_on_model_object<br>";
36
-        //remove whitespaces and thousands separators
37
-        if (is_string($value_inputted_for_field_on_model_object)) {
38
-            $value_inputted_for_field_on_model_object = str_replace(array(" ", EE_Config::instance()->currency->thsnds),
39
-                "", $value_inputted_for_field_on_model_object);
36
+		//remove whitespaces and thousands separators
37
+		if (is_string($value_inputted_for_field_on_model_object)) {
38
+			$value_inputted_for_field_on_model_object = str_replace(array(" ", EE_Config::instance()->currency->thsnds),
39
+				"", $value_inputted_for_field_on_model_object);
40 40
 //echo __LINE__."$value_inputted_for_field_on_model_object<br>";
41 41
 //normalize it so periods are decimal marks (we don't care where you're from: we're talking PHP now)
42
-            $value_inputted_for_field_on_model_object = str_replace(EE_Config::instance()->currency->dec_mrk, ".",
43
-                $value_inputted_for_field_on_model_object);
42
+			$value_inputted_for_field_on_model_object = str_replace(EE_Config::instance()->currency->dec_mrk, ".",
43
+				$value_inputted_for_field_on_model_object);
44 44
 //echo __LINE__."$value_inputted_for_field_on_model_object<br>";
45 45
 //double-check there's absolutely nothing left on this string besides numbers
46
-            $value_inputted_for_field_on_model_object = preg_replace("/[^0-9,.]/", "",
47
-                $value_inputted_for_field_on_model_object);
48
-        }
46
+			$value_inputted_for_field_on_model_object = preg_replace("/[^0-9,.]/", "",
47
+				$value_inputted_for_field_on_model_object);
48
+		}
49 49
 //		echo __LINE__."$value_inputted_for_field_on_model_object<br>";
50
-        return floatval($value_inputted_for_field_on_model_object);
51
-    }
50
+		return floatval($value_inputted_for_field_on_model_object);
51
+	}
52 52
 
53
-    /**
54
-     * Returns the number formatted according to local custom (set by the country of the blog).
55
-     *
56
-     * @param float $value_on_field_to_be_outputted
57
-     * @return string
58
-     */
59
-    function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
60
-    {
61
-        $EE = EE_Registry::instance();
62
-        return number_format($value_on_field_to_be_outputted, $EE->CFG->currency->dec_plc, $EE->CFG->currency->dec_mrk,
63
-            $EE->CFG->currency->thsnds);
64
-    }
53
+	/**
54
+	 * Returns the number formatted according to local custom (set by the country of the blog).
55
+	 *
56
+	 * @param float $value_on_field_to_be_outputted
57
+	 * @return string
58
+	 */
59
+	function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
60
+	{
61
+		$EE = EE_Registry::instance();
62
+		return number_format($value_on_field_to_be_outputted, $EE->CFG->currency->dec_plc, $EE->CFG->currency->dec_mrk,
63
+			$EE->CFG->currency->thsnds);
64
+	}
65 65
 
66
-    function prepare_for_set_from_db($value_found_in_db_for_model_object)
67
-    {
66
+	function prepare_for_set_from_db($value_found_in_db_for_model_object)
67
+	{
68 68
 //		echo "prepare for set from db of ";d($value_found_in_db_for_model_object);
69
-        return floatval($value_found_in_db_for_model_object);
70
-    }
69
+		return floatval($value_found_in_db_for_model_object);
70
+	}
71 71
 }
72 72
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_models/fields/EE_Money_Field.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
      * @param string $table_column
13 13
      * @param string $nicename
14 14
      * @param bool   $nullable
15
-     * @param null   $default_value
15
+     * @param integer   $default_value
16 16
      */
17 17
     public function __construct($table_column, $nicename, $nullable, $default_value = null)
18 18
     {
Please login to merge, or discard this patch.
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -8,91 +8,91 @@
 block discarded – undo
8 8
 class EE_Money_Field extends EE_Float_Field
9 9
 {
10 10
 
11
-    /**
12
-     * @param string $table_column
13
-     * @param string $nicename
14
-     * @param bool   $nullable
15
-     * @param null   $default_value
16
-     */
17
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
18
-    {
19
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
20
-        $this->setSchemaType('object');
21
-    }
11
+	/**
12
+	 * @param string $table_column
13
+	 * @param string $nicename
14
+	 * @param bool   $nullable
15
+	 * @param null   $default_value
16
+	 */
17
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
18
+	{
19
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
20
+		$this->setSchemaType('object');
21
+	}
22 22
 
23 23
 
24
-    /**
25
-     * Schemas:
26
-     *    'localized_float': "3,023.00"
27
-     *    'no_currency_code': "$3,023.00"
28
-     *    null: "$3,023.00<span>USD</span>"
29
-     *
30
-     * @param string $value_on_field_to_be_outputted
31
-     * @param string $schema
32
-     * @return string
33
-     */
34
-    function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
35
-    {
36
-        $pretty_float = parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted);
24
+	/**
25
+	 * Schemas:
26
+	 *    'localized_float': "3,023.00"
27
+	 *    'no_currency_code': "$3,023.00"
28
+	 *    null: "$3,023.00<span>USD</span>"
29
+	 *
30
+	 * @param string $value_on_field_to_be_outputted
31
+	 * @param string $schema
32
+	 * @return string
33
+	 */
34
+	function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
35
+	{
36
+		$pretty_float = parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted);
37 37
 
38
-        if ($schema == 'localized_float') {
39
-            return $pretty_float;
40
-        }
41
-        if ($schema == 'no_currency_code') {
38
+		if ($schema == 'localized_float') {
39
+			return $pretty_float;
40
+		}
41
+		if ($schema == 'no_currency_code') {
42 42
 //			echo "schema no currency!";
43
-            $display_code = false;
44
-        } else {
45
-            $display_code = true;
46
-        }
47
-        //we don't use the $pretty_float because format_currency will take care of it.
48
-        return EEH_Template::format_currency($value_on_field_to_be_outputted, false, $display_code);
49
-    }
43
+			$display_code = false;
44
+		} else {
45
+			$display_code = true;
46
+		}
47
+		//we don't use the $pretty_float because format_currency will take care of it.
48
+		return EEH_Template::format_currency($value_on_field_to_be_outputted, false, $display_code);
49
+	}
50 50
 
51
-    /**
52
-     * If provided with a string, strips out money-related formatting to turn it into a proper float.
53
-     * Rounds the float to the correct number of decimal places for this country's currency.
54
-     * Also, interprets periods and commas according to the country's currency settings.
55
-     * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first.
56
-     *
57
-     * @param string $value_inputted_for_field_on_model_object
58
-     * @return float
59
-     */
60
-    function prepare_for_set($value_inputted_for_field_on_model_object)
61
-    {
62
-        //remove any currencies etc.
51
+	/**
52
+	 * If provided with a string, strips out money-related formatting to turn it into a proper float.
53
+	 * Rounds the float to the correct number of decimal places for this country's currency.
54
+	 * Also, interprets periods and commas according to the country's currency settings.
55
+	 * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first.
56
+	 *
57
+	 * @param string $value_inputted_for_field_on_model_object
58
+	 * @return float
59
+	 */
60
+	function prepare_for_set($value_inputted_for_field_on_model_object)
61
+	{
62
+		//remove any currencies etc.
63 63
 //		if(is_string($value_inputted_for_field_on_model_object)){
64 64
 //			$value_inputted_for_field_on_model_object = preg_replace("/[^0-9,.]/", "", $value_inputted_for_field_on_model_object);
65 65
 //		}
66
-        //now it's a float-style string or number
67
-        $float_val = parent::prepare_for_set($value_inputted_for_field_on_model_object);
68
-        //round to the correctly number of decimal places for this  currency
69
-        $rounded_value = round($float_val, EE_Registry::instance()->CFG->currency->dec_plc);
70
-        return $rounded_value;
71
-    }
66
+		//now it's a float-style string or number
67
+		$float_val = parent::prepare_for_set($value_inputted_for_field_on_model_object);
68
+		//round to the correctly number of decimal places for this  currency
69
+		$rounded_value = round($float_val, EE_Registry::instance()->CFG->currency->dec_plc);
70
+		return $rounded_value;
71
+	}
72 72
 
73
-    function prepare_for_get($value_of_field_on_model_object)
74
-    {
75
-        $c = EE_Registry::instance()->CFG->currency;
76
-        return round(parent::prepare_for_get($value_of_field_on_model_object), $c->dec_plc);
77
-    }
73
+	function prepare_for_get($value_of_field_on_model_object)
74
+	{
75
+		$c = EE_Registry::instance()->CFG->currency;
76
+		return round(parent::prepare_for_get($value_of_field_on_model_object), $c->dec_plc);
77
+	}
78 78
 
79
-    public function getSchemaProperties()
80
-    {
81
-        return array(
82
-            'raw' => array(
83
-                'description' =>  sprintf(
84
-                    __('%s - the raw value as it exists in the database as a simple float.', 'event_espresso'),
85
-                    $this->get_nicename()
86
-                ),
87
-                'type' => 'number'
88
-            ),
89
-            'pretty' => array(
90
-                'description' =>  sprintf(
91
-                    __('%s - formatted for display in the set currency and decimal places.', 'event_espresso'),
92
-                    $this->get_nicename()
93
-                ),
94
-                'type' => 'string'
95
-            )
96
-        );
97
-    }
79
+	public function getSchemaProperties()
80
+	{
81
+		return array(
82
+			'raw' => array(
83
+				'description' =>  sprintf(
84
+					__('%s - the raw value as it exists in the database as a simple float.', 'event_espresso'),
85
+					$this->get_nicename()
86
+				),
87
+				'type' => 'number'
88
+			),
89
+			'pretty' => array(
90
+				'description' =>  sprintf(
91
+					__('%s - formatted for display in the set currency and decimal places.', 'event_espresso'),
92
+					$this->get_nicename()
93
+				),
94
+				'type' => 'string'
95
+			)
96
+		);
97
+	}
98 98
 }
99 99
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_classes/EE_Payment.class.php 3 patches
Spacing   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 /**
@@ -20,9 +20,9 @@  discard block
 block discarded – undo
20 20
 	 * @return EE_Payment
21 21
 	 * @throws \EE_Error
22 22
 	 */
23
-	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
24
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
25
-		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
23
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) {
24
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
25
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
26 26
 	}
27 27
 
28 28
 
@@ -34,8 +34,8 @@  discard block
 block discarded – undo
34 34
 	 * @return EE_Payment
35 35
 	 * @throws \EE_Error
36 36
 	 */
37
-	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
38
-		return new self( $props_n_values, true, $timezone );
37
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null) {
38
+		return new self($props_n_values, true, $timezone);
39 39
 	}
40 40
 
41 41
 
@@ -47,8 +47,8 @@  discard block
 block discarded – undo
47 47
 	 * @param int $TXN_ID
48 48
 	 * @throws \EE_Error
49 49
 	 */
50
-	public function set_transaction_id( $TXN_ID = 0 ) {
51
-		$this->set( 'TXN_ID', $TXN_ID );
50
+	public function set_transaction_id($TXN_ID = 0) {
51
+		$this->set('TXN_ID', $TXN_ID);
52 52
 	}
53 53
 
54 54
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 * @throws \EE_Error
61 61
 	 */
62 62
 	public function transaction() {
63
-		return $this->get_first_related( 'Transaction' );
63
+		return $this->get_first_related('Transaction');
64 64
 	}
65 65
 
66 66
 
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
 	 * @param string $STS_ID
73 73
 	 * @throws \EE_Error
74 74
 	 */
75
-	public function set_status( $STS_ID = '' ) {
76
-		$this->set( 'STS_ID', $STS_ID );
75
+	public function set_status($STS_ID = '') {
76
+		$this->set('STS_ID', $STS_ID);
77 77
 	}
78 78
 
79 79
 
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
 	 * @param int $timestamp
86 86
 	 * @throws \EE_Error
87 87
 	 */
88
-	public function set_timestamp( $timestamp = 0 ) {
89
-		$this->set( 'PAY_timestamp', $timestamp );
88
+	public function set_timestamp($timestamp = 0) {
89
+		$this->set('PAY_timestamp', $timestamp);
90 90
 	}
91 91
 
92 92
 
@@ -98,8 +98,8 @@  discard block
 block discarded – undo
98 98
 	 * @param string $PAY_source
99 99
 	 * @throws \EE_Error
100 100
 	 */
101
-	public function set_source( $PAY_source = '' ) {
102
-		$this->set( 'PAY_source', $PAY_source );
101
+	public function set_source($PAY_source = '') {
102
+		$this->set('PAY_source', $PAY_source);
103 103
 	}
104 104
 
105 105
 
@@ -111,8 +111,8 @@  discard block
 block discarded – undo
111 111
 	 * @param float $amount
112 112
 	 * @throws \EE_Error
113 113
 	 */
114
-	public function set_amount( $amount = 0.00 ) {
115
-		$this->set( 'PAY_amount', (float)$amount );
114
+	public function set_amount($amount = 0.00) {
115
+		$this->set('PAY_amount', (float) $amount);
116 116
 	}
117 117
 
118 118
 
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 	 * @param string $gateway_response
125 125
 	 * @throws \EE_Error
126 126
 	 */
127
-	public function set_gateway_response( $gateway_response = '' ) {
128
-		$this->set( 'PAY_gateway_response', $gateway_response );
127
+	public function set_gateway_response($gateway_response = '') {
128
+		$this->set('PAY_gateway_response', $gateway_response);
129 129
 	}
130 130
 
131 131
 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 			),
149 149
 			'4.6.0'
150 150
 		);
151
-		return $this->payment_method() ? $this->payment_method()->name() : __( 'Unknown', 'event_espresso' );
151
+		return $this->payment_method() ? $this->payment_method()->name() : __('Unknown', 'event_espresso');
152 152
 	}
153 153
 
154 154
 
@@ -160,8 +160,8 @@  discard block
 block discarded – undo
160 160
 	 * @param string $txn_id_chq_nmbr
161 161
 	 * @throws \EE_Error
162 162
 	 */
163
-	public function set_txn_id_chq_nmbr( $txn_id_chq_nmbr = '' ) {
164
-		$this->set( 'PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr );
163
+	public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '') {
164
+		$this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr);
165 165
 	}
166 166
 
167 167
 
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
 	 * @param string $po_number
174 174
 	 * @throws \EE_Error
175 175
 	 */
176
-	public function set_po_number( $po_number = '' ) {
177
-		$this->set( 'PAY_po_number', $po_number );
176
+	public function set_po_number($po_number = '') {
177
+		$this->set('PAY_po_number', $po_number);
178 178
 	}
179 179
 
180 180
 
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
 	 * @param string $extra_accntng
187 187
 	 * @throws \EE_Error
188 188
 	 */
189
-	public function set_extra_accntng( $extra_accntng = '' ) {
190
-		$this->set( 'PAY_extra_accntng', $extra_accntng );
189
+	public function set_extra_accntng($extra_accntng = '') {
190
+		$this->set('PAY_extra_accntng', $extra_accntng);
191 191
 	}
192 192
 
193 193
 
@@ -199,11 +199,11 @@  discard block
 block discarded – undo
199 199
 	 * @param bool $via_admin
200 200
 	 * @throws \EE_Error
201 201
 	 */
202
-	public function set_payment_made_via_admin( $via_admin = false ) {
203
-		if ( $via_admin ) {
204
-			$this->set( 'PAY_source', EEM_Payment_Method::scope_admin );
202
+	public function set_payment_made_via_admin($via_admin = false) {
203
+		if ($via_admin) {
204
+			$this->set('PAY_source', EEM_Payment_Method::scope_admin);
205 205
 		} else {
206
-			$this->set( 'PAY_source', EEM_Payment_Method::scope_cart );
206
+			$this->set('PAY_source', EEM_Payment_Method::scope_cart);
207 207
 		}
208 208
 	}
209 209
 
@@ -216,13 +216,13 @@  discard block
 block discarded – undo
216 216
 	 * @param string|array $details
217 217
 	 * @throws \EE_Error
218 218
 	 */
219
-	public function set_details( $details = '' ) {
220
-		if ( is_array( $details ) ) {
221
-			array_walk_recursive( $details, array( $this, '_strip_all_tags_within_array' ) );
219
+	public function set_details($details = '') {
220
+		if (is_array($details)) {
221
+			array_walk_recursive($details, array($this, '_strip_all_tags_within_array'));
222 222
 		} else {
223
-			$details = wp_strip_all_tags( $details );
223
+			$details = wp_strip_all_tags($details);
224 224
 		}
225
-		$this->set( 'PAY_details', $details );
225
+		$this->set('PAY_details', $details);
226 226
 	}
227 227
 
228 228
 
@@ -233,8 +233,8 @@  discard block
 block discarded – undo
233 233
 	 * @param string $redirect_url
234 234
 	 * @throws \EE_Error
235 235
 	 */
236
-	public function set_redirect_url( $redirect_url ) {
237
-		$this->set( 'PAY_redirect_url', $redirect_url );
236
+	public function set_redirect_url($redirect_url) {
237
+		$this->set('PAY_redirect_url', $redirect_url);
238 238
 	}
239 239
 
240 240
 
@@ -245,8 +245,8 @@  discard block
 block discarded – undo
245 245
 	 * @param array $redirect_args
246 246
 	 * @throws \EE_Error
247 247
 	 */
248
-	public function set_redirect_args( $redirect_args ) {
249
-		$this->set( 'PAY_redirect_args', $redirect_args );
248
+	public function set_redirect_args($redirect_args) {
249
+		$this->set('PAY_redirect_args', $redirect_args);
250 250
 	}
251 251
 
252 252
 
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 	 * @throws \EE_Error
259 259
 	 */
260 260
 	public function TXN_ID() {
261
-		return $this->get( 'TXN_ID' );
261
+		return $this->get('TXN_ID');
262 262
 	}
263 263
 
264 264
 
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 	 * @throws \EE_Error
271 271
 	 */
272 272
 	public function status() {
273
-		return $this->get( 'STS_ID' );
273
+		return $this->get('STS_ID');
274 274
 	}
275 275
 
276 276
 
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 	 * @throws \EE_Error
283 283
 	 */
284 284
 	public function STS_ID() {
285
-		return $this->get( 'STS_ID' );
285
+		return $this->get('STS_ID');
286 286
 	}
287 287
 
288 288
 
@@ -296,8 +296,8 @@  discard block
 block discarded – undo
296 296
 	 * @return string
297 297
 	 * @throws \EE_Error
298 298
 	 */
299
-	public function timestamp( $dt_frmt = '', $tm_frmt = '' ) {
300
-		return $this->get_i18n_datetime( 'PAY_timestamp', trim( $dt_frmt . ' ' . $tm_frmt) );
299
+	public function timestamp($dt_frmt = '', $tm_frmt = '') {
300
+		return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt.' '.$tm_frmt));
301 301
 	}
302 302
 
303 303
 
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 	 * @throws \EE_Error
310 310
 	 */
311 311
 	public function source() {
312
-		return $this->get( 'PAY_source' );
312
+		return $this->get('PAY_source');
313 313
 	}
314 314
 
315 315
 
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 	 * @throws \EE_Error
323 323
 	 */
324 324
 	public function amount() {
325
-		return (float)$this->get( 'PAY_amount' );
325
+		return (float) $this->get('PAY_amount');
326 326
 	}
327 327
 
328 328
 
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 	 * @throws \EE_Error
333 333
 	 */
334 334
 	public function amount_no_code() {
335
-		return $this->get_pretty( 'PAY_amount', 'no_currency_code' );
335
+		return $this->get_pretty('PAY_amount', 'no_currency_code');
336 336
 	}
337 337
 
338 338
 
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 	 * @throws \EE_Error
345 345
 	 */
346 346
 	public function gateway_response() {
347
-		return $this->get( 'PAY_gateway_response' );
347
+		return $this->get('PAY_gateway_response');
348 348
 	}
349 349
 
350 350
 
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 	 * @throws \EE_Error
357 357
 	 */
358 358
 	public function txn_id_chq_nmbr() {
359
-		return $this->get( 'PAY_txn_id_chq_nmbr' );
359
+		return $this->get('PAY_txn_id_chq_nmbr');
360 360
 	}
361 361
 
362 362
 
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 	 * @throws \EE_Error
369 369
 	 */
370 370
 	public function po_number() {
371
-		return $this->get( 'PAY_po_number' );
371
+		return $this->get('PAY_po_number');
372 372
 	}
373 373
 
374 374
 
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 	 * @throws \EE_Error
381 381
 	 */
382 382
 	public function extra_accntng() {
383
-		return $this->get( 'PAY_extra_accntng' );
383
+		return $this->get('PAY_extra_accntng');
384 384
 	}
385 385
 
386 386
 
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 	 * @throws \EE_Error
393 393
 	 */
394 394
 	public function payment_made_via_admin() {
395
-		return ( $this->get( 'PAY_source' ) === EEM_Payment_Method::scope_admin );
395
+		return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin);
396 396
 	}
397 397
 
398 398
 
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
 	 * @throws \EE_Error
405 405
 	 */
406 406
 	public function details() {
407
-		return $this->get( 'PAY_details' );
407
+		return $this->get('PAY_details');
408 408
 	}
409 409
 
410 410
 
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
 	 * @throws \EE_Error
417 417
 	 */
418 418
 	public function redirect_url() {
419
-		return $this->get( 'PAY_redirect_url' );
419
+		return $this->get('PAY_redirect_url');
420 420
 	}
421 421
 
422 422
 
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 	 * @throws \EE_Error
429 429
 	 */
430 430
 	public function redirect_args() {
431
-		return $this->get( 'PAY_redirect_args' );
431
+		return $this->get('PAY_redirect_args');
432 432
 	}
433 433
 
434 434
 
@@ -440,8 +440,8 @@  discard block
 block discarded – undo
440 440
 	 * @return void
441 441
 	 * @throws \EE_Error
442 442
 	 */
443
-	public function e_pretty_status( $show_icons = false ) {
444
-		echo $this->pretty_status( $show_icons );
443
+	public function e_pretty_status($show_icons = false) {
444
+		echo $this->pretty_status($show_icons);
445 445
 	}
446 446
 
447 447
 
@@ -453,14 +453,14 @@  discard block
 block discarded – undo
453 453
 	 * @return string
454 454
 	 * @throws \EE_Error
455 455
 	 */
456
-	public function pretty_status( $show_icons = false ) {
456
+	public function pretty_status($show_icons = false) {
457 457
 		$status = EEM_Status::instance()->localized_status(
458
-			array( $this->STS_ID() => __( 'unknown', 'event_espresso' ) ),
458
+			array($this->STS_ID() => __('unknown', 'event_espresso')),
459 459
 			false,
460 460
 			'sentence'
461 461
 		);
462 462
 		$icon = '';
463
-		switch ( $this->STS_ID() ) {
463
+		switch ($this->STS_ID()) {
464 464
 			case EEM_Payment::status_id_approved:
465 465
 				$icon = $show_icons
466 466
 					? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>'
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
 					: '';
483 483
 				break;
484 484
 		}
485
-		return $icon . $status[ $this->STS_ID() ];
485
+		return $icon.$status[$this->STS_ID()];
486 486
 	}
487 487
 
488 488
 
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
 	 * @throws \EE_Error
495 495
 	 */
496 496
 	public function is_approved() {
497
-		return $this->status_is( EEM_Payment::status_id_approved );
497
+		return $this->status_is(EEM_Payment::status_id_approved);
498 498
 	}
499 499
 
500 500
 
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
 	 * @return boolean whether the status of this payment equals the status id
509 509
 	 * @throws \EE_Error
510 510
 	 */
511
-	protected function status_is( $STS_ID ) {
511
+	protected function status_is($STS_ID) {
512 512
 		return $STS_ID === $this->STS_ID() ? true : false;
513 513
 	}
514 514
 
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 	 * @throws \EE_Error
522 522
 	 */
523 523
 	public function is_pending() {
524
-		return $this->status_is( EEM_Payment::status_id_pending );
524
+		return $this->status_is(EEM_Payment::status_id_pending);
525 525
 	}
526 526
 
527 527
 
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
 	 * @throws \EE_Error
534 534
 	 */
535 535
 	public function is_cancelled() {
536
-		return $this->status_is( EEM_Payment::status_id_cancelled );
536
+		return $this->status_is(EEM_Payment::status_id_cancelled);
537 537
 	}
538 538
 
539 539
 
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
 	 * @throws \EE_Error
546 546
 	 */
547 547
 	public function is_declined() {
548
-		return $this->status_is( EEM_Payment::status_id_declined );
548
+		return $this->status_is(EEM_Payment::status_id_declined);
549 549
 	}
550 550
 
551 551
 
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
 	 * @throws \EE_Error
558 558
 	 */
559 559
 	public function is_failed() {
560
-		return $this->status_is( EEM_Payment::status_id_failed );
560
+		return $this->status_is(EEM_Payment::status_id_failed);
561 561
 	}
562 562
 
563 563
 
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
 	 * @throws \EE_Error
582 582
 	 */
583 583
 	public function status_obj() {
584
-		return $this->get_first_related( 'Status' );
584
+		return $this->get_first_related('Status');
585 585
 	}
586 586
 
587 587
 
@@ -593,8 +593,8 @@  discard block
 block discarded – undo
593 593
 	 * @return EE_Extra_Meta
594 594
 	 * @throws \EE_Error
595 595
 	 */
596
-	public function extra_meta( $query_params = array() ) {
597
-		return $this->get_many_related( 'Extra_Meta', $query_params );
596
+	public function extra_meta($query_params = array()) {
597
+		return $this->get_many_related('Extra_Meta', $query_params);
598 598
 	}
599 599
 
600 600
 
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
 	 * @throws \EE_Error
609 609
 	 */
610 610
 	public function payment_method() {
611
-		return $this->get_first_related( 'Payment_Method' );
611
+		return $this->get_first_related('Payment_Method');
612 612
 	}
613 613
 
614 614
 
@@ -626,18 +626,18 @@  discard block
 block discarded – undo
626 626
 	 * @return string html
627 627
 	 * @throws \EE_Error
628 628
 	 */
629
-	public function redirect_form( $inside_form_html = null ) {
629
+	public function redirect_form($inside_form_html = null) {
630 630
 		$redirect_url = $this->redirect_url();
631
-		if ( ! empty( $redirect_url ) ) {
631
+		if ( ! empty($redirect_url)) {
632 632
 			// what ? no inner form content?
633
-			if ( $inside_form_html === null ) {
633
+			if ($inside_form_html === null) {
634 634
 				$inside_form_html = EEH_HTML::p(
635 635
 					sprintf(
636 636
 						__(
637 637
 							'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s',
638 638
 							'event_espresso'
639 639
 						),
640
-						EEH_HTML::br( 2 ),
640
+						EEH_HTML::br(2),
641 641
 						'<input type="submit" value="',
642 642
 						'">'
643 643
 					),
@@ -653,22 +653,22 @@  discard block
 block discarded – undo
653 653
 			);
654 654
 			//if it's a GET request, we need to remove all the GET params in the querystring
655 655
 			//and put them into the form instead
656
-			if ( $method === 'GET' ) {
657
-				$querystring = parse_url( $redirect_url, PHP_URL_QUERY );
656
+			if ($method === 'GET') {
657
+				$querystring = parse_url($redirect_url, PHP_URL_QUERY);
658 658
 				$get_params = null;
659
-				parse_str( $querystring, $get_params );
660
-				$inside_form_html .= $this->_args_as_inputs( $get_params );
661
-				$redirect_url = str_replace( '?' . $querystring, '', $redirect_url );
659
+				parse_str($querystring, $get_params);
660
+				$inside_form_html .= $this->_args_as_inputs($get_params);
661
+				$redirect_url = str_replace('?'.$querystring, '', $redirect_url);
662 662
 			}
663
-			$form = EEH_HTML::nl( 1 )
663
+			$form = EEH_HTML::nl(1)
664 664
 			        . '<form method="'
665 665
 			        . $method
666 666
 			        . '" name="gateway_form" action="'
667 667
 			        . $redirect_url
668 668
 			        . '">';
669
-			$form .= EEH_HTML::nl( 1 ) . $this->redirect_args_as_inputs();
669
+			$form .= EEH_HTML::nl(1).$this->redirect_args_as_inputs();
670 670
 			$form .= $inside_form_html;
671
-			$form .= EEH_HTML::nl( -1 ) . '</form>' . EEH_HTML::nl( -1 );
671
+			$form .= EEH_HTML::nl( -1 ).'</form>'.EEH_HTML::nl( -1 );
672 672
 			return $form;
673 673
 		} else {
674 674
 			return null;
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
 	 * @throws \EE_Error
686 686
 	 */
687 687
 	public function redirect_args_as_inputs() {
688
-		return $this->_args_as_inputs( $this->redirect_args() );
688
+		return $this->_args_as_inputs($this->redirect_args());
689 689
 	}
690 690
 
691 691
 
@@ -697,15 +697,15 @@  discard block
 block discarded – undo
697 697
 	 * @param array $args key-value pairs
698 698
 	 * @return string
699 699
 	 */
700
-	protected function _args_as_inputs( $args ) {
700
+	protected function _args_as_inputs($args) {
701 701
 		$html = '';
702
-		if ( $args !== null && is_array( $args ) ) {
703
-			foreach ( $args as $name => $value ) {
704
-				$html .= EEH_HTML::nl( 0 )
702
+		if ($args !== null && is_array($args)) {
703
+			foreach ($args as $name => $value) {
704
+				$html .= EEH_HTML::nl(0)
705 705
 				         . '<input type="hidden" name="'
706 706
 				         . $name
707 707
 				         . '" value="'
708
-				         . esc_attr( $value )
708
+				         . esc_attr($value)
709 709
 				         . '"/>';
710 710
 			}
711 711
 		}
@@ -734,14 +734,14 @@  discard block
 block discarded – undo
734 734
 	 * @access private
735 735
 	 * @param mixed $item
736 736
 	 */
737
-	private function _strip_all_tags_within_array( &$item ) {
738
-		if ( is_object( $item ) ) {
739
-			$item = (array)$item;
737
+	private function _strip_all_tags_within_array(&$item) {
738
+		if (is_object($item)) {
739
+			$item = (array) $item;
740 740
 		}
741
-		if ( is_array( $item ) ) {
742
-			array_walk_recursive( $item, array( $this, '_strip_all_tags_within_array' ) );
741
+		if (is_array($item)) {
742
+			array_walk_recursive($item, array($this, '_strip_all_tags_within_array'));
743 743
 		} else {
744
-			$item = wp_strip_all_tags( $item );
744
+			$item = wp_strip_all_tags($item);
745 745
 		}
746 746
 	}
747 747
 
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
 		$original_status = EEH_Array::is_set(
759 759
 			$this->_props_n_values_provided_in_constructor,
760 760
 			'STS_ID',
761
-			$this->get_model()->field_settings_for( 'STS_ID' )->get_default_value()
761
+			$this->get_model()->field_settings_for('STS_ID')->get_default_value()
762 762
 		);
763 763
 		$current_status = $this->status();
764 764
 		if (
@@ -784,11 +784,11 @@  discard block
 block discarded – undo
784 784
 	 * @return mixed
785 785
 	 * @throws \EE_Error
786 786
 	 */
787
-	public function get_pretty( $field_name, $extra_cache_ref = null ) {
788
-		if ( $field_name === 'PAY_gateway' ) {
789
-			return $this->payment_method() ? $this->payment_method()->name() : __( 'Unknown', 'event_espresso' );
787
+	public function get_pretty($field_name, $extra_cache_ref = null) {
788
+		if ($field_name === 'PAY_gateway') {
789
+			return $this->payment_method() ? $this->payment_method()->name() : __('Unknown', 'event_espresso');
790 790
 		}
791
-		return $this->_get_cached_property( $field_name, true, $extra_cache_ref );
791
+		return $this->_get_cached_property($field_name, true, $extra_cache_ref);
792 792
 	}
793 793
 
794 794
 
@@ -800,8 +800,8 @@  discard block
 block discarded – undo
800 800
 	 * @return EE_Registration_Payment[]
801 801
 	 * @throws \EE_Error
802 802
 	 */
803
-	public function registration_payments( $query_params = array() ) {
804
-		return $this->get_many_related( 'Registration_Payment', $query_params );
803
+	public function registration_payments($query_params = array()) {
804
+		return $this->get_many_related('Registration_Payment', $query_params);
805 805
 	}
806 806
 
807 807
 
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
     public function get_primary_attendee()
863 863
     {
864 864
         $primary_reg = $this->get_primary_registration();
865
-        if( $primary_reg instanceof EE_Registration) {
865
+        if ($primary_reg instanceof EE_Registration) {
866 866
             return $primary_reg->attendee();
867 867
         }
868 868
         return null;
Please login to merge, or discard this patch.
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -661,11 +661,11 @@  discard block
 block discarded – undo
661 661
 				$redirect_url = str_replace( '?' . $querystring, '', $redirect_url );
662 662
 			}
663 663
 			$form = EEH_HTML::nl( 1 )
664
-			        . '<form method="'
665
-			        . $method
666
-			        . '" name="gateway_form" action="'
667
-			        . $redirect_url
668
-			        . '">';
664
+					. '<form method="'
665
+					. $method
666
+					. '" name="gateway_form" action="'
667
+					. $redirect_url
668
+					. '">';
669 669
 			$form .= EEH_HTML::nl( 1 ) . $this->redirect_args_as_inputs();
670 670
 			$form .= $inside_form_html;
671 671
 			$form .= EEH_HTML::nl( -1 ) . '</form>' . EEH_HTML::nl( -1 );
@@ -702,11 +702,11 @@  discard block
 block discarded – undo
702 702
 		if ( $args !== null && is_array( $args ) ) {
703 703
 			foreach ( $args as $name => $value ) {
704 704
 				$html .= EEH_HTML::nl( 0 )
705
-				         . '<input type="hidden" name="'
706
-				         . $name
707
-				         . '" value="'
708
-				         . esc_attr( $value )
709
-				         . '"/>';
705
+						 . '<input type="hidden" name="'
706
+						 . $name
707
+						 . '" value="'
708
+						 . esc_attr( $value )
709
+						 . '"/>';
710 710
 			}
711 711
 		}
712 712
 		return $html;
@@ -806,64 +806,64 @@  discard block
 block discarded – undo
806 806
 
807 807
 
808 808
 
809
-    /**
810
-     * Gets the first event for this payment (it's possible that it could be for multiple)
811
-     *
812
-     * @return EE_Event|null
813
-     */
814
-    public function get_first_event()
815
-    {
816
-        $transaction = $this->transaction();
817
-        if ($transaction instanceof EE_Transaction) {
818
-            $primary_registrant = $transaction->primary_registration();
819
-            if ($primary_registrant instanceof EE_Registration) {
820
-                return $primary_registrant->event_obj();
821
-            }
822
-        }
823
-        return null;
824
-    }
825
-
826
-
827
-
828
-    /**
829
-     * Gets the name of the first event for which is being paid
830
-     *
831
-     * @return string
832
-     */
833
-    public function get_first_event_name()
834
-    {
835
-        $event = $this->get_first_event();
836
-        return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso');
837
-    }
838
-
839
-
840
-
841
-    /**
842
-     * Returns the payment's transaction's primary registration
843
-     * @return EE_Registration|null
844
-     */
845
-    public function get_primary_registration()
846
-    {
847
-        if ($this->transaction() instanceof EE_Transaction) {
848
-            return $this->transaction()->primary_registration();
849
-        }
850
-        return null;
851
-    }
852
-
853
-
854
-
855
-    /**
856
-     * Gets the payment's transaction's primary registration's attendee, or null
857
-     * @return EE_Attendee|null
858
-     */
859
-    public function get_primary_attendee()
860
-    {
861
-        $primary_reg = $this->get_primary_registration();
862
-        if( $primary_reg instanceof EE_Registration) {
863
-            return $primary_reg->attendee();
864
-        }
865
-        return null;
866
-    }
809
+	/**
810
+	 * Gets the first event for this payment (it's possible that it could be for multiple)
811
+	 *
812
+	 * @return EE_Event|null
813
+	 */
814
+	public function get_first_event()
815
+	{
816
+		$transaction = $this->transaction();
817
+		if ($transaction instanceof EE_Transaction) {
818
+			$primary_registrant = $transaction->primary_registration();
819
+			if ($primary_registrant instanceof EE_Registration) {
820
+				return $primary_registrant->event_obj();
821
+			}
822
+		}
823
+		return null;
824
+	}
825
+
826
+
827
+
828
+	/**
829
+	 * Gets the name of the first event for which is being paid
830
+	 *
831
+	 * @return string
832
+	 */
833
+	public function get_first_event_name()
834
+	{
835
+		$event = $this->get_first_event();
836
+		return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso');
837
+	}
838
+
839
+
840
+
841
+	/**
842
+	 * Returns the payment's transaction's primary registration
843
+	 * @return EE_Registration|null
844
+	 */
845
+	public function get_primary_registration()
846
+	{
847
+		if ($this->transaction() instanceof EE_Transaction) {
848
+			return $this->transaction()->primary_registration();
849
+		}
850
+		return null;
851
+	}
852
+
853
+
854
+
855
+	/**
856
+	 * Gets the payment's transaction's primary registration's attendee, or null
857
+	 * @return EE_Attendee|null
858
+	 */
859
+	public function get_primary_attendee()
860
+	{
861
+		$primary_reg = $this->get_primary_registration();
862
+		if( $primary_reg instanceof EE_Registration) {
863
+			return $primary_reg->attendee();
864
+		}
865
+		return null;
866
+	}
867 867
 }
868 868
 /* End of file EE_Payment.class.php */
869 869
 /* Location: /includes/classes/EE_Payment.class.php */
Please login to merge, or discard this patch.
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 	 * @param array  $props_n_values          incoming values
16 16
 	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
17 17
 	 *                                        used.)
18
-	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
18
+	 * @param string[]  $date_formats            incoming date_formats in an array where the first value is the
19 19
 	 *                                        date_format and the second value is the time format
20 20
 	 * @return EE_Payment
21 21
 	 * @throws \EE_Error
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
 	 * Gets all the extra meta info on this payment
591 591
 	 *
592 592
 	 * @param array $query_params like EEM_Base::get_all
593
-	 * @return EE_Extra_Meta
593
+	 * @return EE_Base_Class[]
594 594
 	 * @throws \EE_Error
595 595
 	 */
596 596
 	public function extra_meta( $query_params = array() ) {
@@ -840,7 +840,7 @@  discard block
 block discarded – undo
840 840
 
841 841
     /**
842 842
      * Returns the payment's transaction's primary registration
843
-     * @return EE_Registration|null
843
+     * @return EE_Base_Class|null
844 844
      */
845 845
     public function get_primary_registration()
846 846
     {
Please login to merge, or discard this patch.
core/EE_Config.core.php 3 patches
Spacing   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
     public static function instance()
151 151
     {
152 152
         // check if class object is instantiated, and instantiated properly
153
-        if (! self::$_instance instanceof EE_Config) {
153
+        if ( ! self::$_instance instanceof EE_Config) {
154 154
             self::$_instance = new self();
155 155
         }
156 156
         return self::$_instance;
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
                 $this
294 294
             );
295 295
             if (is_object($settings) && property_exists($this, $config)) {
296
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
296
+                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__'.$config, $settings);
297 297
                 //call configs populate method to ensure any defaults are set for empty values.
298 298
                 if (method_exists($settings, 'populate')) {
299 299
                     $this->{$config}->populate();
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
                         break;
562 562
                     // TEST #2 : check that settings section exists
563 563
                     case 2 :
564
-                        if (! isset($this->{$section})) {
564
+                        if ( ! isset($this->{$section})) {
565 565
                             if ($display_errors) {
566 566
                                 throw new EE_Error(
567 567
                                     sprintf(
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
                         break;
623 623
                     // TEST #6 : verify config class is accessible
624 624
                     case 6 :
625
-                        if (! class_exists($config_class)) {
625
+                        if ( ! class_exists($config_class)) {
626 626
                             if ($display_errors) {
627 627
                                 throw new EE_Error(
628 628
                                     sprintf(
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
                         break;
640 640
                     // TEST #7 : check that config has even been set
641 641
                     case 7 :
642
-                        if (! isset($this->{$section}->{$name})) {
642
+                        if ( ! isset($this->{$section}->{$name})) {
643 643
                             if ($display_errors) {
644 644
                                 throw new EE_Error(
645 645
                                     sprintf(
@@ -657,7 +657,7 @@  discard block
 block discarded – undo
657 657
                         break;
658 658
                     // TEST #8 : check that config is the requested type
659 659
                     case 8 :
660
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
660
+                        if ( ! $this->{$section}->{$name} instanceof $config_class) {
661 661
                             if ($display_errors) {
662 662
                                 throw new EE_Error(
663 663
                                     sprintf(
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
                         break;
677 677
                     // TEST #9 : verify config object
678 678
                     case 9 :
679
-                        if (! $config_obj instanceof EE_Config_Base) {
679
+                        if ( ! $config_obj instanceof EE_Config_Base) {
680 680
                             if ($display_errors) {
681 681
                                 throw new EE_Error(
682 682
                                     sprintf(
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
      */
710 710
     private function _generate_config_option_name($section = '', $name = '')
711 711
     {
712
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
712
+        return 'ee_config-'.strtolower($section.'-'.str_replace(array('EE_', 'EED_'), '', $name));
713 713
     }
714 714
 
715 715
 
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
     {
728 728
         return ! empty($config_class)
729 729
             ? $config_class
730
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
730
+            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))).'_Config';
731 731
     }
732 732
 
733 733
 
@@ -747,17 +747,17 @@  discard block
 block discarded – undo
747 747
         // ensure config class is set to something
748 748
         $config_class = $this->_set_config_class($config_class, $name);
749 749
         // run tests 1-4, 6, and 7 to verify all config params are set and valid
750
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
750
+        if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
751 751
             return null;
752 752
         }
753 753
         $config_option_name = $this->_generate_config_option_name($section, $name);
754 754
         // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
755
-        if (! isset($this->_addon_option_names[$config_option_name])) {
755
+        if ( ! isset($this->_addon_option_names[$config_option_name])) {
756 756
             $this->_addon_option_names[$config_option_name] = $config_class;
757 757
             $this->update_addon_option_names();
758 758
         }
759 759
         // verify the incoming config object but suppress errors
760
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
760
+        if ( ! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
761 761
             $config_obj = new $config_class();
762 762
         }
763 763
         if (get_option($config_option_name)) {
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
         // get class name of the incoming object
806 806
         $config_class = get_class($config_obj);
807 807
         // run tests 1-5 and 9 to verify config
808
-        if (! $this->_verify_config_params(
808
+        if ( ! $this->_verify_config_params(
809 809
             $section,
810 810
             $name,
811 811
             $config_class,
@@ -817,7 +817,7 @@  discard block
 block discarded – undo
817 817
         }
818 818
         $config_option_name = $this->_generate_config_option_name($section, $name);
819 819
         // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
820
-        if (! isset($this->_addon_option_names[$config_option_name])) {
820
+        if ( ! isset($this->_addon_option_names[$config_option_name])) {
821 821
             // save new config to db
822 822
             if ($this->set_config($section, $name, $config_class, $config_obj)) {
823 823
                 return true;
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
                             'event_espresso'
844 844
                         ),
845 845
                         $config_class,
846
-                        'EE_Config->' . $section . '->' . $name
846
+                        'EE_Config->'.$section.'->'.$name
847 847
                     ),
848 848
                     __FILE__,
849 849
                     __FUNCTION__,
@@ -870,7 +870,7 @@  discard block
 block discarded – undo
870 870
         // ensure config class is set to something
871 871
         $config_class = $this->_set_config_class($config_class, $name);
872 872
         // run tests 1-4, 6 and 7 to verify that all params have been set
873
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
873
+        if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
874 874
             return null;
875 875
         }
876 876
         // now test if the requested config object exists, but suppress errors
@@ -916,7 +916,7 @@  discard block
 block discarded – undo
916 916
         // retrieve the wp-option for this config class.
917 917
         $config_option = maybe_unserialize(get_option($config_option_name, array()));
918 918
         if (empty($config_option)) {
919
-            EE_Config::log($config_option_name . '-NOT-FOUND');
919
+            EE_Config::log($config_option_name.'-NOT-FOUND');
920 920
         }
921 921
         return $config_option;
922 922
     }
@@ -935,7 +935,7 @@  discard block
 block discarded – undo
935 935
             //copy incoming $_REQUEST and sanitize it so we can save it
936 936
             $_request = $_REQUEST;
937 937
             array_walk_recursive($_request, 'sanitize_text_field');
938
-            $config_log[(string)microtime(true)] = array(
938
+            $config_log[(string) microtime(true)] = array(
939 939
                 'config_name' => $config_option_name,
940 940
                 'request'     => $_request,
941 941
             );
@@ -951,7 +951,7 @@  discard block
 block discarded – undo
951 951
      */
952 952
     public static function trim_log()
953 953
     {
954
-        if (! EE_Config::logging_enabled()) {
954
+        if ( ! EE_Config::logging_enabled()) {
955 955
             return;
956 956
         }
957 957
         $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
@@ -976,7 +976,7 @@  discard block
 block discarded – undo
976 976
     public static function get_page_for_posts()
977 977
     {
978 978
         $page_for_posts = get_option('page_for_posts');
979
-        if (! $page_for_posts) {
979
+        if ( ! $page_for_posts) {
980 980
             return 'posts';
981 981
         }
982 982
         /** @type WPDB $wpdb */
@@ -1037,13 +1037,13 @@  discard block
 block discarded – undo
1037 1037
             )
1038 1038
         ) {
1039 1039
             // grab list of installed widgets
1040
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1040
+            $widgets_to_register = glob(EE_WIDGETS.'*', GLOB_ONLYDIR);
1041 1041
             // filter list of modules to register
1042 1042
             $widgets_to_register = apply_filters(
1043 1043
                 'FHEE__EE_Config__register_widgets__widgets_to_register',
1044 1044
                 $widgets_to_register
1045 1045
             );
1046
-            if (! empty($widgets_to_register)) {
1046
+            if ( ! empty($widgets_to_register)) {
1047 1047
                 // cycle thru widget folders
1048 1048
                 foreach ($widgets_to_register as $widget_path) {
1049 1049
                     // add to list of installed widget modules
@@ -1094,31 +1094,31 @@  discard block
 block discarded – undo
1094 1094
         // create classname from widget directory name
1095 1095
         $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1096 1096
         // add class prefix
1097
-        $widget_class = 'EEW_' . $widget;
1097
+        $widget_class = 'EEW_'.$widget;
1098 1098
         // does the widget exist ?
1099
-        if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1099
+        if ( ! is_readable($widget_path.DS.$widget_class.$widget_ext)) {
1100 1100
             $msg = sprintf(
1101 1101
                 __(
1102 1102
                     'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1103 1103
                     'event_espresso'
1104 1104
                 ),
1105 1105
                 $widget_class,
1106
-                $widget_path . DS . $widget_class . $widget_ext
1106
+                $widget_path.DS.$widget_class.$widget_ext
1107 1107
             );
1108
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1108
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1109 1109
             return;
1110 1110
         }
1111 1111
         // load the widget class file
1112
-        require_once($widget_path . DS . $widget_class . $widget_ext);
1112
+        require_once($widget_path.DS.$widget_class.$widget_ext);
1113 1113
         // verify that class exists
1114
-        if (! class_exists($widget_class)) {
1114
+        if ( ! class_exists($widget_class)) {
1115 1115
             $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1116
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1116
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1117 1117
             return;
1118 1118
         }
1119 1119
         register_widget($widget_class);
1120 1120
         // add to array of registered widgets
1121
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1121
+        EE_Registry::instance()->widgets->{$widget_class} = $widget_path.DS.$widget_class.$widget_ext;
1122 1122
     }
1123 1123
 
1124 1124
 
@@ -1132,19 +1132,19 @@  discard block
 block discarded – undo
1132 1132
     private function _register_modules()
1133 1133
     {
1134 1134
         // grab list of installed modules
1135
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1135
+        $modules_to_register = glob(EE_MODULES.'*', GLOB_ONLYDIR);
1136 1136
         // filter list of modules to register
1137 1137
         $modules_to_register = apply_filters(
1138 1138
             'FHEE__EE_Config__register_modules__modules_to_register',
1139 1139
             $modules_to_register
1140 1140
         );
1141
-        if (! empty($modules_to_register)) {
1141
+        if ( ! empty($modules_to_register)) {
1142 1142
             // loop through folders
1143 1143
             foreach ($modules_to_register as $module_path) {
1144 1144
                 /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1145 1145
                 if (
1146
-                    $module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1147
-                    && $module_path !== EE_MODULES . 'gateways'
1146
+                    $module_path !== EE_MODULES.'zzz-copy-this-module-template'
1147
+                    && $module_path !== EE_MODULES.'gateways'
1148 1148
                 ) {
1149 1149
                     // add to list of installed modules
1150 1150
                     EE_Config::register_module($module_path);
@@ -1182,25 +1182,25 @@  discard block
 block discarded – undo
1182 1182
             // remove last segment
1183 1183
             array_pop($module_path);
1184 1184
             // glue it back together
1185
-            $module_path = implode(DS, $module_path) . DS;
1185
+            $module_path = implode(DS, $module_path).DS;
1186 1186
             // take first segment from file name pieces and sanitize it
1187 1187
             $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1188 1188
             // ensure class prefix is added
1189
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1189
+            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_'.$module : $module;
1190 1190
         } else {
1191 1191
             // we need to generate the filename based off of the folder name
1192 1192
             // grab and sanitize module name
1193 1193
             $module = strtolower(basename($module_path));
1194 1194
             $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1195 1195
             // like trailingslashit()
1196
-            $module_path = rtrim($module_path, DS) . DS;
1196
+            $module_path = rtrim($module_path, DS).DS;
1197 1197
             // create classname from module directory name
1198 1198
             $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1199 1199
             // add class prefix
1200
-            $module_class = 'EED_' . $module;
1200
+            $module_class = 'EED_'.$module;
1201 1201
         }
1202 1202
         // does the module exist ?
1203
-        if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1203
+        if ( ! is_readable($module_path.DS.$module_class.$module_ext)) {
1204 1204
             $msg = sprintf(
1205 1205
                 __(
1206 1206
                     'The requested %s module file could not be found or is not readable due to file permissions.',
@@ -1208,19 +1208,19 @@  discard block
 block discarded – undo
1208 1208
                 ),
1209 1209
                 $module
1210 1210
             );
1211
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1211
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1212 1212
             return false;
1213 1213
         }
1214 1214
         // load the module class file
1215
-        require_once($module_path . $module_class . $module_ext);
1215
+        require_once($module_path.$module_class.$module_ext);
1216 1216
         // verify that class exists
1217
-        if (! class_exists($module_class)) {
1217
+        if ( ! class_exists($module_class)) {
1218 1218
             $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1219
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1219
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1220 1220
             return false;
1221 1221
         }
1222 1222
         // add to array of registered modules
1223
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1223
+        EE_Registry::instance()->modules->{$module_class} = $module_path.$module_class.$module_ext;
1224 1224
         do_action(
1225 1225
             'AHEE__EE_Config__register_module__complete',
1226 1226
             $module_class,
@@ -1273,26 +1273,26 @@  discard block
 block discarded – undo
1273 1273
     {
1274 1274
         do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1275 1275
         $module = str_replace('EED_', '', $module);
1276
-        $module_class = 'EED_' . $module;
1277
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1276
+        $module_class = 'EED_'.$module;
1277
+        if ( ! isset(EE_Registry::instance()->modules->{$module_class})) {
1278 1278
             $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1279
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1279
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1280 1280
             return false;
1281 1281
         }
1282 1282
         if (empty($route)) {
1283 1283
             $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1284
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1284
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1285 1285
             return false;
1286 1286
         }
1287
-        if (! method_exists('EED_' . $module, $method_name)) {
1287
+        if ( ! method_exists('EED_'.$module, $method_name)) {
1288 1288
             $msg = sprintf(
1289 1289
                 __('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1290 1290
                 $route
1291 1291
             );
1292
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1292
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1293 1293
             return false;
1294 1294
         }
1295
-        EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name);
1295
+        EE_Config::$_module_route_map[$key][$route] = array('EED_'.$module, $method_name);
1296 1296
         return true;
1297 1297
     }
1298 1298
 
@@ -1309,7 +1309,7 @@  discard block
 block discarded – undo
1309 1309
     public static function get_route($route = null, $key = 'ee')
1310 1310
     {
1311 1311
         do_action('AHEE__EE_Config__get_route__begin', $route);
1312
-        $route = (string)apply_filters('FHEE__EE_Config__get_route', $route);
1312
+        $route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1313 1313
         if (isset(EE_Config::$_module_route_map[$key][$route])) {
1314 1314
             return EE_Config::$_module_route_map[$key][$route];
1315 1315
         }
@@ -1345,44 +1345,44 @@  discard block
 block discarded – undo
1345 1345
     public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1346 1346
     {
1347 1347
         do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1348
-        if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1348
+        if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1349 1349
             $msg = sprintf(
1350 1350
                 __('The module route %s for this forward has not been registered.', 'event_espresso'),
1351 1351
                 $route
1352 1352
             );
1353
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1353
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1354 1354
             return false;
1355 1355
         }
1356 1356
         if (empty($forward)) {
1357 1357
             $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1358
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1358
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1359 1359
             return false;
1360 1360
         }
1361 1361
         if (is_array($forward)) {
1362
-            if (! isset($forward[1])) {
1362
+            if ( ! isset($forward[1])) {
1363 1363
                 $msg = sprintf(
1364 1364
                     __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1365 1365
                     $route
1366 1366
                 );
1367
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1367
+                EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1368 1368
                 return false;
1369 1369
             }
1370
-            if (! method_exists($forward[0], $forward[1])) {
1370
+            if ( ! method_exists($forward[0], $forward[1])) {
1371 1371
                 $msg = sprintf(
1372 1372
                     __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1373 1373
                     $forward[1],
1374 1374
                     $route
1375 1375
                 );
1376
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1376
+                EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1377 1377
                 return false;
1378 1378
             }
1379
-        } else if (! function_exists($forward)) {
1379
+        } else if ( ! function_exists($forward)) {
1380 1380
             $msg = sprintf(
1381 1381
                 __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1382 1382
                 $forward,
1383 1383
                 $route
1384 1384
             );
1385
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1385
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1386 1386
             return false;
1387 1387
         }
1388 1388
         EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward;
@@ -1432,15 +1432,15 @@  discard block
 block discarded – undo
1432 1432
     public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1433 1433
     {
1434 1434
         do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1435
-        if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1435
+        if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1436 1436
             $msg = sprintf(
1437 1437
                 __('The module route %s for this view has not been registered.', 'event_espresso'),
1438 1438
                 $route
1439 1439
             );
1440
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1440
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1441 1441
             return false;
1442 1442
         }
1443
-        if (! is_readable($view)) {
1443
+        if ( ! is_readable($view)) {
1444 1444
             $msg = sprintf(
1445 1445
                 __(
1446 1446
                     'The %s view file could not be found or is not readable due to file permissions.',
@@ -1448,7 +1448,7 @@  discard block
 block discarded – undo
1448 1448
                 ),
1449 1449
                 $view
1450 1450
             );
1451
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1451
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1452 1452
             return false;
1453 1453
         }
1454 1454
         EE_Config::$_module_view_map[$key][$route][absint($status)] = $view;
@@ -1555,7 +1555,7 @@  discard block
 block discarded – undo
1555 1555
      */
1556 1556
     public function get_pretty($property)
1557 1557
     {
1558
-        if (! property_exists($this, $property)) {
1558
+        if ( ! property_exists($this, $property)) {
1559 1559
             throw new EE_Error(
1560 1560
                 sprintf(
1561 1561
                     __(
@@ -1794,11 +1794,11 @@  discard block
 block discarded – undo
1794 1794
      */
1795 1795
     public function reg_page_url()
1796 1796
     {
1797
-        if (! $this->reg_page_url) {
1797
+        if ( ! $this->reg_page_url) {
1798 1798
             $this->reg_page_url = add_query_arg(
1799 1799
                                       array('uts' => time()),
1800 1800
                                       get_permalink($this->reg_page_id)
1801
-                                  ) . '#checkout';
1801
+                                  ).'#checkout';
1802 1802
         }
1803 1803
         return $this->reg_page_url;
1804 1804
     }
@@ -1815,7 +1815,7 @@  discard block
 block discarded – undo
1815 1815
      */
1816 1816
     public function txn_page_url($query_args = array())
1817 1817
     {
1818
-        if (! $this->txn_page_url) {
1818
+        if ( ! $this->txn_page_url) {
1819 1819
             $this->txn_page_url = get_permalink($this->txn_page_id);
1820 1820
         }
1821 1821
         if ($query_args) {
@@ -1837,7 +1837,7 @@  discard block
 block discarded – undo
1837 1837
      */
1838 1838
     public function thank_you_page_url($query_args = array())
1839 1839
     {
1840
-        if (! $this->thank_you_page_url) {
1840
+        if ( ! $this->thank_you_page_url) {
1841 1841
             $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1842 1842
         }
1843 1843
         if ($query_args) {
@@ -1857,7 +1857,7 @@  discard block
 block discarded – undo
1857 1857
      */
1858 1858
     public function cancel_page_url()
1859 1859
     {
1860
-        if (! $this->cancel_page_url) {
1860
+        if ( ! $this->cancel_page_url) {
1861 1861
             $this->cancel_page_url = get_permalink($this->cancel_page_id);
1862 1862
         }
1863 1863
         return $this->cancel_page_url;
@@ -1902,13 +1902,13 @@  discard block
 block discarded – undo
1902 1902
         $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1903 1903
         $option = 'ee_ueip_optin';
1904 1904
         //set correct table for query
1905
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1905
+        $table_name = $wpdb->get_blog_prefix($current_main_site_id).'options';
1906 1906
         //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1907 1907
         //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1908 1908
         //re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1909 1909
         //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1910 1910
         //for the purpose of caching.
1911
-        $pre = apply_filters('pre_option_' . $option, false, $option);
1911
+        $pre = apply_filters('pre_option_'.$option, false, $option);
1912 1912
         if (false !== $pre) {
1913 1913
             EE_Core_Config::$ee_ueip_option = $pre;
1914 1914
             return EE_Core_Config::$ee_ueip_option;
@@ -1918,9 +1918,9 @@  discard block
 block discarded – undo
1918 1918
         if (is_object($row)) {
1919 1919
             $value = $row->option_value;
1920 1920
         } else { //option does not exist so use default.
1921
-            return apply_filters('default_option_' . $option, false, $option);
1921
+            return apply_filters('default_option_'.$option, false, $option);
1922 1922
         }
1923
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1923
+        EE_Core_Config::$ee_ueip_option = apply_filters('option_'.$option, maybe_unserialize($value), $option);
1924 1924
         return EE_Core_Config::$ee_ueip_option;
1925 1925
     }
1926 1926
 
@@ -2197,27 +2197,27 @@  discard block
 block discarded – undo
2197 2197
             // retrieve the country settings from the db, just in case they have been customized
2198 2198
             $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2199 2199
             if ($country instanceof EE_Country) {
2200
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2201
-                $this->name = $country->currency_name_single();    // Dollar
2202
-                $this->plural = $country->currency_name_plural();    // Dollars
2203
-                $this->sign = $country->currency_sign();            // currency sign: $
2204
-                $this->sign_b4 = $country->currency_sign_before();        // currency sign before or after: $TRUE  or  FALSE$
2205
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2206
-                $this->dec_mrk = $country->currency_decimal_mark();    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2207
-                $this->thsnds = $country->currency_thousands_separator();    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2200
+                $this->code = $country->currency_code(); // currency code: USD, CAD, EUR
2201
+                $this->name = $country->currency_name_single(); // Dollar
2202
+                $this->plural = $country->currency_name_plural(); // Dollars
2203
+                $this->sign = $country->currency_sign(); // currency sign: $
2204
+                $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE  or  FALSE$
2205
+                $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00  3 = 0.000
2206
+                $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2207
+                $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2208 2208
             }
2209 2209
         }
2210 2210
         // fallback to hardcoded defaults, in case the above failed
2211 2211
         if (empty($this->code)) {
2212 2212
             // set default currency settings
2213
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2214
-            $this->name = __('Dollar', 'event_espresso');    // Dollar
2215
-            $this->plural = __('Dollars', 'event_espresso');    // Dollars
2216
-            $this->sign = '$';    // currency sign: $
2217
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2218
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2219
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2220
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2213
+            $this->code = 'USD'; // currency code: USD, CAD, EUR
2214
+            $this->name = __('Dollar', 'event_espresso'); // Dollar
2215
+            $this->plural = __('Dollars', 'event_espresso'); // Dollars
2216
+            $this->sign = '$'; // currency sign: $
2217
+            $this->sign_b4 = true; // currency sign before or after: $TRUE  or  FALSE$
2218
+            $this->dec_plc = 2; // decimal places: 2 = 0.00  3 = 0.000
2219
+            $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2220
+            $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2221 2221
         }
2222 2222
     }
2223 2223
 }
@@ -2541,7 +2541,7 @@  discard block
 block discarded – undo
2541 2541
     public function log_file_name($reset = false)
2542 2542
     {
2543 2543
         if (empty($this->log_file_name) || $reset) {
2544
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2544
+            $this->log_file_name = sanitize_key('espresso_log_'.md5(uniqid('', true))).'.txt';
2545 2545
             EE_Config::instance()->update_espresso_config(false, false);
2546 2546
         }
2547 2547
         return $this->log_file_name;
@@ -2556,7 +2556,7 @@  discard block
 block discarded – undo
2556 2556
     public function debug_file_name($reset = false)
2557 2557
     {
2558 2558
         if (empty($this->debug_file_name) || $reset) {
2559
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2559
+            $this->debug_file_name = sanitize_key('espresso_debug_'.md5(uniqid('', true))).'.txt';
2560 2560
             EE_Config::instance()->update_espresso_config(false, false);
2561 2561
         }
2562 2562
         return $this->debug_file_name;
@@ -2773,21 +2773,21 @@  discard block
 block discarded – undo
2773 2773
         $this->use_google_maps = true;
2774 2774
         $this->google_map_api_key = '';
2775 2775
         // for event details pages (reg page)
2776
-        $this->event_details_map_width = 585;            // ee_map_width_single
2777
-        $this->event_details_map_height = 362;            // ee_map_height_single
2778
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2779
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2780
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2781
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2782
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2776
+        $this->event_details_map_width = 585; // ee_map_width_single
2777
+        $this->event_details_map_height = 362; // ee_map_height_single
2778
+        $this->event_details_map_zoom = 14; // ee_map_zoom_single
2779
+        $this->event_details_display_nav = true; // ee_map_nav_display_single
2780
+        $this->event_details_nav_size = false; // ee_map_nav_size_single
2781
+        $this->event_details_control_type = 'default'; // ee_map_type_control_single
2782
+        $this->event_details_map_align = 'center'; // ee_map_align_single
2783 2783
         // for event list pages
2784
-        $this->event_list_map_width = 300;            // ee_map_width
2785
-        $this->event_list_map_height = 185;        // ee_map_height
2786
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2787
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2788
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2789
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2790
-        $this->event_list_map_align = 'center';            // ee_map_align
2784
+        $this->event_list_map_width = 300; // ee_map_width
2785
+        $this->event_list_map_height = 185; // ee_map_height
2786
+        $this->event_list_map_zoom = 12; // ee_map_zoom
2787
+        $this->event_list_display_nav = false; // ee_map_nav_display
2788
+        $this->event_list_nav_size = true; // ee_map_nav_size
2789
+        $this->event_list_control_type = 'dropdown'; // ee_map_type_control
2790
+        $this->event_list_map_align = 'center'; // ee_map_align
2791 2791
     }
2792 2792
 
2793 2793
 }
@@ -3102,7 +3102,7 @@  discard block
 block discarded – undo
3102 3102
      */
3103 3103
     public function max_input_vars_limit_check($input_count = 0)
3104 3104
     {
3105
-        if (! empty($this->php->max_input_vars)
3105
+        if ( ! empty($this->php->max_input_vars)
3106 3106
             && ($input_count >= $this->php->max_input_vars)
3107 3107
             && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9)
3108 3108
         ) {
Please login to merge, or discard this patch.
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
      * @param    string         $name
534 534
      * @param    string         $config_class
535 535
      * @param    EE_Config_Base $config_obj
536
-     * @param    array          $tests_to_run
536
+     * @param    integer[]          $tests_to_run
537 537
      * @param    bool           $display_errors
538 538
      * @return    bool    TRUE on success, FALSE on fail
539 539
      */
@@ -797,7 +797,7 @@  discard block
 block discarded – undo
797 797
      * @access    public
798 798
      * @param    string                $section
799 799
      * @param    string                $name
800
-     * @param    EE_Config_Base|string $config_obj
800
+     * @param    EE_Config_Base $config_obj
801 801
      * @param    bool                  $throw_errors
802 802
      * @return    bool
803 803
      */
@@ -1764,7 +1764,7 @@  discard block
 block discarded – undo
1764 1764
 
1765 1765
 
1766 1766
     /**
1767
-     * @return array
1767
+     * @return integer[]
1768 1768
      */
1769 1769
     public function get_critical_pages_array()
1770 1770
     {
@@ -1779,7 +1779,7 @@  discard block
 block discarded – undo
1779 1779
 
1780 1780
 
1781 1781
     /**
1782
-     * @return array
1782
+     * @return string[]
1783 1783
      */
1784 1784
     public function get_critical_pages_shortcodes_array()
1785 1785
     {
@@ -3122,7 +3122,7 @@  discard block
 block discarded – undo
3122 3122
      * according to max_input_vars
3123 3123
      *
3124 3124
      * @param int   $input_count the count of input vars.
3125
-     * @return array {
3125
+     * @return string {
3126 3126
      *                           An array that represents whether available space and if no available space the error
3127 3127
      *                           message.
3128 3128
      * @type bool   $has_space   whether more inputs can be added.
Please login to merge, or discard this patch.
Indentation   +3060 added lines, -3060 removed lines patch added patch discarded remove patch
@@ -17,2442 +17,2442 @@  discard block
 block discarded – undo
17 17
 final class EE_Config implements ResettableInterface
18 18
 {
19 19
 
20
-    const OPTION_NAME        = 'ee_config';
20
+	const OPTION_NAME        = 'ee_config';
21
+
22
+	const LOG_NAME           = 'ee_config_log';
23
+
24
+	const LOG_LENGTH         = 100;
25
+
26
+	const ADDON_OPTION_NAMES = 'ee_config_option_names';
27
+
28
+
29
+	/**
30
+	 *    instance of the EE_Config object
31
+	 *
32
+	 * @var    EE_Config $_instance
33
+	 * @access    private
34
+	 */
35
+	private static $_instance;
36
+
37
+	/**
38
+	 * @var boolean $_logging_enabled
39
+	 */
40
+	private static $_logging_enabled = false;
41
+
42
+	/**
43
+	 * @var LegacyShortcodesManager $legacy_shortcodes_manager
44
+	 */
45
+	private $legacy_shortcodes_manager;
46
+
47
+	/**
48
+	 * An StdClass whose property names are addon slugs,
49
+	 * and values are their config classes
50
+	 *
51
+	 * @var StdClass
52
+	 */
53
+	public $addons;
54
+
55
+	/**
56
+	 * @var EE_Admin_Config
57
+	 */
58
+	public $admin;
59
+
60
+	/**
61
+	 * @var EE_Core_Config
62
+	 */
63
+	public $core;
64
+
65
+	/**
66
+	 * @var EE_Currency_Config
67
+	 */
68
+	public $currency;
69
+
70
+	/**
71
+	 * @var EE_Organization_Config
72
+	 */
73
+	public $organization;
74
+
75
+	/**
76
+	 * @var EE_Registration_Config
77
+	 */
78
+	public $registration;
79
+
80
+	/**
81
+	 * @var EE_Template_Config
82
+	 */
83
+	public $template_settings;
84
+
85
+	/**
86
+	 * Holds EE environment values.
87
+	 *
88
+	 * @var EE_Environment_Config
89
+	 */
90
+	public $environment;
91
+
92
+	/**
93
+	 * settings pertaining to Google maps
94
+	 *
95
+	 * @var EE_Map_Config
96
+	 */
97
+	public $map_settings;
98
+
99
+	/**
100
+	 * settings pertaining to Taxes
101
+	 *
102
+	 * @var EE_Tax_Config
103
+	 */
104
+	public $tax_settings;
105
+
106
+
107
+	/**
108
+	 * Settings pertaining to global messages settings.
109
+	 *
110
+	 * @var EE_Messages_Config
111
+	 */
112
+	public $messages;
113
+
114
+	/**
115
+	 * @deprecated
116
+	 * @var EE_Gateway_Config
117
+	 */
118
+	public $gateway;
119
+
120
+	/**
121
+	 * @var    array $_addon_option_names
122
+	 * @access    private
123
+	 */
124
+	private $_addon_option_names = array();
125
+
126
+	/**
127
+	 * @var    array $_module_route_map
128
+	 * @access    private
129
+	 */
130
+	private static $_module_route_map = array();
131
+
132
+	/**
133
+	 * @var    array $_module_forward_map
134
+	 * @access    private
135
+	 */
136
+	private static $_module_forward_map = array();
137
+
138
+	/**
139
+	 * @var    array $_module_view_map
140
+	 * @access    private
141
+	 */
142
+	private static $_module_view_map = array();
143
+
144
+
145
+
146
+	/**
147
+	 * @singleton method used to instantiate class object
148
+	 * @access    public
149
+	 * @return EE_Config instance
150
+	 */
151
+	public static function instance()
152
+	{
153
+		// check if class object is instantiated, and instantiated properly
154
+		if (! self::$_instance instanceof EE_Config) {
155
+			self::$_instance = new self();
156
+		}
157
+		return self::$_instance;
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 * Resets the config
164
+	 *
165
+	 * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
166
+	 *                               (default) leaves the database alone, and merely resets the EE_Config object to
167
+	 *                               reflect its state in the database
168
+	 * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
169
+	 *                               $_instance as NULL. Useful in case you want to forget about the old instance on
170
+	 *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
171
+	 *                               site was put into maintenance mode)
172
+	 * @return EE_Config
173
+	 */
174
+	public static function reset($hard_reset = false, $reinstantiate = true)
175
+	{
176
+		if (self::$_instance instanceof EE_Config) {
177
+			if ($hard_reset) {
178
+				self::$_instance->legacy_shortcodes_manager = null;
179
+				self::$_instance->_addon_option_names = array();
180
+				self::$_instance->_initialize_config();
181
+				self::$_instance->update_espresso_config();
182
+			}
183
+			self::$_instance->update_addon_option_names();
184
+		}
185
+		self::$_instance = null;
186
+		//we don't need to reset the static properties imo because those should
187
+		//only change when a module is added or removed. Currently we don't
188
+		//support removing a module during a request when it previously existed
189
+		if ($reinstantiate) {
190
+			return self::instance();
191
+		} else {
192
+			return null;
193
+		}
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 *    class constructor
200
+	 *
201
+	 * @access    private
202
+	 */
203
+	private function __construct()
204
+	{
205
+		do_action('AHEE__EE_Config__construct__begin', $this);
206
+		EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
207
+		// setup empty config classes
208
+		$this->_initialize_config();
209
+		// load existing EE site settings
210
+		$this->_load_core_config();
211
+		// confirm everything loaded correctly and set filtered defaults if not
212
+		$this->_verify_config();
213
+		//  register shortcodes and modules
214
+		add_action(
215
+			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
216
+			array($this, 'register_shortcodes_and_modules'),
217
+			999
218
+		);
219
+		//  initialize shortcodes and modules
220
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
221
+		// register widgets
222
+		add_action('widgets_init', array($this, 'widgets_init'), 10);
223
+		// shutdown
224
+		add_action('shutdown', array($this, 'shutdown'), 10);
225
+		// construct__end hook
226
+		do_action('AHEE__EE_Config__construct__end', $this);
227
+		// hardcoded hack
228
+		$this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
229
+	}
230
+
231
+
232
+
233
+	/**
234
+	 * @return boolean
235
+	 */
236
+	public static function logging_enabled()
237
+	{
238
+		return self::$_logging_enabled;
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * use to get the current theme if needed from static context
245
+	 *
246
+	 * @return string current theme set.
247
+	 */
248
+	public static function get_current_theme()
249
+	{
250
+		return isset(self::$_instance->template_settings->current_espresso_theme)
251
+			? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
252
+	}
253
+
254
+
255
+
256
+	/**
257
+	 *        _initialize_config
258
+	 *
259
+	 * @access private
260
+	 * @return void
261
+	 */
262
+	private function _initialize_config()
263
+	{
264
+		EE_Config::trim_log();
265
+		//set defaults
266
+		$this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
267
+		$this->addons = new stdClass();
268
+		// set _module_route_map
269
+		EE_Config::$_module_route_map = array();
270
+		// set _module_forward_map
271
+		EE_Config::$_module_forward_map = array();
272
+		// set _module_view_map
273
+		EE_Config::$_module_view_map = array();
274
+	}
275
+
276
+
277
+
278
+	/**
279
+	 *        load core plugin configuration
280
+	 *
281
+	 * @access private
282
+	 * @return void
283
+	 */
284
+	private function _load_core_config()
285
+	{
286
+		// load_core_config__start hook
287
+		do_action('AHEE__EE_Config___load_core_config__start', $this);
288
+		$espresso_config = $this->get_espresso_config();
289
+		foreach ($espresso_config as $config => $settings) {
290
+			// load_core_config__start hook
291
+			$settings = apply_filters(
292
+				'FHEE__EE_Config___load_core_config__config_settings',
293
+				$settings,
294
+				$config,
295
+				$this
296
+			);
297
+			if (is_object($settings) && property_exists($this, $config)) {
298
+				$this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
299
+				//call configs populate method to ensure any defaults are set for empty values.
300
+				if (method_exists($settings, 'populate')) {
301
+					$this->{$config}->populate();
302
+				}
303
+				if (method_exists($settings, 'do_hooks')) {
304
+					$this->{$config}->do_hooks();
305
+				}
306
+			}
307
+		}
308
+		if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
309
+			$this->update_espresso_config();
310
+		}
311
+		// load_core_config__end hook
312
+		do_action('AHEE__EE_Config___load_core_config__end', $this);
313
+	}
314
+
315
+
316
+
317
+	/**
318
+	 *    _verify_config
319
+	 *
320
+	 * @access    protected
321
+	 * @return    void
322
+	 */
323
+	protected function _verify_config()
324
+	{
325
+		$this->core = $this->core instanceof EE_Core_Config
326
+			? $this->core
327
+			: new EE_Core_Config();
328
+		$this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
329
+		$this->organization = $this->organization instanceof EE_Organization_Config
330
+			? $this->organization
331
+			: new EE_Organization_Config();
332
+		$this->organization = apply_filters(
333
+			'FHEE__EE_Config___initialize_config__organization',
334
+			$this->organization
335
+		);
336
+		$this->currency = $this->currency instanceof EE_Currency_Config
337
+			? $this->currency
338
+			: new EE_Currency_Config();
339
+		$this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
340
+		$this->registration = $this->registration instanceof EE_Registration_Config
341
+			? $this->registration
342
+			: new EE_Registration_Config();
343
+		$this->registration = apply_filters(
344
+			'FHEE__EE_Config___initialize_config__registration',
345
+			$this->registration
346
+		);
347
+		$this->admin = $this->admin instanceof EE_Admin_Config
348
+			? $this->admin
349
+			: new EE_Admin_Config();
350
+		$this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
351
+		$this->template_settings = $this->template_settings instanceof EE_Template_Config
352
+			? $this->template_settings
353
+			: new EE_Template_Config();
354
+		$this->template_settings = apply_filters(
355
+			'FHEE__EE_Config___initialize_config__template_settings',
356
+			$this->template_settings
357
+		);
358
+		$this->map_settings = $this->map_settings instanceof EE_Map_Config
359
+			? $this->map_settings
360
+			: new EE_Map_Config();
361
+		$this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings',
362
+			$this->map_settings);
363
+		$this->environment = $this->environment instanceof EE_Environment_Config
364
+			? $this->environment
365
+			: new EE_Environment_Config();
366
+		$this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment',
367
+			$this->environment);
368
+		$this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
369
+			? $this->tax_settings
370
+			: new EE_Tax_Config();
371
+		$this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings',
372
+			$this->tax_settings);
373
+		$this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
374
+		$this->messages = $this->messages instanceof EE_Messages_Config
375
+			? $this->messages
376
+			: new EE_Messages_Config();
377
+		$this->gateway = $this->gateway instanceof EE_Gateway_Config
378
+			? $this->gateway
379
+			: new EE_Gateway_Config();
380
+		$this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
381
+		$this->legacy_shortcodes_manager = null;
382
+	}
383
+
384
+
385
+	/**
386
+	 *    get_espresso_config
387
+	 *
388
+	 * @access    public
389
+	 * @return    array of espresso config stuff
390
+	 */
391
+	public function get_espresso_config()
392
+	{
393
+		// grab espresso configuration
394
+		return apply_filters(
395
+			'FHEE__EE_Config__get_espresso_config__CFG',
396
+			get_option(EE_Config::OPTION_NAME, array())
397
+		);
398
+	}
399
+
400
+
401
+
402
+	/**
403
+	 *    double_check_config_comparison
404
+	 *
405
+	 * @access    public
406
+	 * @param string $option
407
+	 * @param        $old_value
408
+	 * @param        $value
409
+	 */
410
+	public function double_check_config_comparison($option = '', $old_value, $value)
411
+	{
412
+		// make sure we're checking the ee config
413
+		if ($option === EE_Config::OPTION_NAME) {
414
+			// run a loose comparison of the old value against the new value for type and properties,
415
+			// but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
416
+			if ($value != $old_value) {
417
+				// if they are NOT the same, then remove the hook,
418
+				// which means the subsequent update results will be based solely on the update query results
419
+				// the reason we do this is because, as stated above,
420
+				// WP update_option performs an exact instance comparison (===) on any update values passed to it
421
+				// this happens PRIOR to serialization and any subsequent update.
422
+				// If values are found to match their previous old value,
423
+				// then WP bails before performing any update.
424
+				// Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
425
+				// it just pulled from the db, with the one being passed to it (which will not match).
426
+				// HOWEVER, once the object is serialized and passed off to MySQL to update,
427
+				// MySQL MAY ALSO NOT perform the update because
428
+				// the string it sees in the db looks the same as the new one it has been passed!!!
429
+				// This results in the query returning an "affected rows" value of ZERO,
430
+				// which gets returned immediately by WP update_option and looks like an error.
431
+				remove_action('update_option', array($this, 'check_config_updated'));
432
+			}
433
+		}
434
+	}
435
+
436
+
437
+
438
+	/**
439
+	 *    update_espresso_config
440
+	 *
441
+	 * @access   public
442
+	 */
443
+	protected function _reset_espresso_addon_config()
444
+	{
445
+		$this->_addon_option_names = array();
446
+		foreach ($this->addons as $addon_name => $addon_config_obj) {
447
+			$addon_config_obj = maybe_unserialize($addon_config_obj);
448
+			if ($addon_config_obj instanceof EE_Config_Base) {
449
+				$this->update_config('addons', $addon_name, $addon_config_obj, false);
450
+			}
451
+			$this->addons->{$addon_name} = null;
452
+		}
453
+	}
454
+
455
+
456
+
457
+	/**
458
+	 *    update_espresso_config
459
+	 *
460
+	 * @access   public
461
+	 * @param   bool $add_success
462
+	 * @param   bool $add_error
463
+	 * @return   bool
464
+	 */
465
+	public function update_espresso_config($add_success = false, $add_error = true)
466
+	{
467
+		// don't allow config updates during WP heartbeats
468
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
469
+			return false;
470
+		}
471
+		// commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
472
+		//$clone = clone( self::$_instance );
473
+		//self::$_instance = NULL;
474
+		do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
475
+		$this->_reset_espresso_addon_config();
476
+		// hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
477
+		// but BEFORE the actual update occurs
478
+		add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
479
+		// don't want to persist legacy_shortcodes_manager, but don't want to lose it either
480
+		$legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
481
+		$this->legacy_shortcodes_manager = null;
482
+		// now update "ee_config"
483
+		$saved = update_option(EE_Config::OPTION_NAME, $this);
484
+		$this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
485
+		EE_Config::log(EE_Config::OPTION_NAME);
486
+		// if not saved... check if the hook we just added still exists;
487
+		// if it does, it means one of two things:
488
+		// 		that update_option bailed at the ( $value === $old_value ) conditional,
489
+		//		 or...
490
+		// 		the db update query returned 0 rows affected
491
+		// 		(probably because the data  value was the same from it's perspective)
492
+		// so the existence of the hook means that a negative result from update_option is NOT an error,
493
+		// but just means no update occurred, so don't display an error to the user.
494
+		// BUT... if update_option returns FALSE, AND the hook is missing,
495
+		// then it means that something truly went wrong
496
+		$saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
497
+		// remove our action since we don't want it in the system anymore
498
+		remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
499
+		do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
500
+		//self::$_instance = $clone;
501
+		//unset( $clone );
502
+		// if config remains the same or was updated successfully
503
+		if ($saved) {
504
+			if ($add_success) {
505
+				EE_Error::add_success(
506
+					__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
507
+					__FILE__,
508
+					__FUNCTION__,
509
+					__LINE__
510
+				);
511
+			}
512
+			return true;
513
+		} else {
514
+			if ($add_error) {
515
+				EE_Error::add_error(
516
+					__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
517
+					__FILE__,
518
+					__FUNCTION__,
519
+					__LINE__
520
+				);
521
+			}
522
+			return false;
523
+		}
524
+	}
525
+
526
+
527
+
528
+	/**
529
+	 *    _verify_config_params
530
+	 *
531
+	 * @access    private
532
+	 * @param    string         $section
533
+	 * @param    string         $name
534
+	 * @param    string         $config_class
535
+	 * @param    EE_Config_Base $config_obj
536
+	 * @param    array          $tests_to_run
537
+	 * @param    bool           $display_errors
538
+	 * @return    bool    TRUE on success, FALSE on fail
539
+	 */
540
+	private function _verify_config_params(
541
+		$section = '',
542
+		$name = '',
543
+		$config_class = '',
544
+		$config_obj = null,
545
+		$tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
546
+		$display_errors = true
547
+	) {
548
+		try {
549
+			foreach ($tests_to_run as $test) {
550
+				switch ($test) {
551
+					// TEST #1 : check that section was set
552
+					case 1 :
553
+						if (empty($section)) {
554
+							if ($display_errors) {
555
+								throw new EE_Error(
556
+									sprintf(
557
+										__(
558
+											'No configuration section has been provided while attempting to save "%s".',
559
+											'event_espresso'
560
+										),
561
+										$config_class
562
+									)
563
+								);
564
+							}
565
+							return false;
566
+						}
567
+						break;
568
+					// TEST #2 : check that settings section exists
569
+					case 2 :
570
+						if (! isset($this->{$section})) {
571
+							if ($display_errors) {
572
+								throw new EE_Error(
573
+									sprintf(
574
+										__('The "%s" configuration section does not exist.', 'event_espresso'),
575
+										$section
576
+									)
577
+								);
578
+							}
579
+							return false;
580
+						}
581
+						break;
582
+					// TEST #3 : check that section is the proper format
583
+					case 3 :
584
+						if (
585
+						! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
586
+						) {
587
+							if ($display_errors) {
588
+								throw new EE_Error(
589
+									sprintf(
590
+										__(
591
+											'The "%s" configuration settings have not been formatted correctly.',
592
+											'event_espresso'
593
+										),
594
+										$section
595
+									)
596
+								);
597
+							}
598
+							return false;
599
+						}
600
+						break;
601
+					// TEST #4 : check that config section name has been set
602
+					case 4 :
603
+						if (empty($name)) {
604
+							if ($display_errors) {
605
+								throw new EE_Error(
606
+									__(
607
+										'No name has been provided for the specific configuration section.',
608
+										'event_espresso'
609
+									)
610
+								);
611
+							}
612
+							return false;
613
+						}
614
+						break;
615
+					// TEST #5 : check that a config class name has been set
616
+					case 5 :
617
+						if (empty($config_class)) {
618
+							if ($display_errors) {
619
+								throw new EE_Error(
620
+									__(
621
+										'No class name has been provided for the specific configuration section.',
622
+										'event_espresso'
623
+									)
624
+								);
625
+							}
626
+							return false;
627
+						}
628
+						break;
629
+					// TEST #6 : verify config class is accessible
630
+					case 6 :
631
+						if (! class_exists($config_class)) {
632
+							if ($display_errors) {
633
+								throw new EE_Error(
634
+									sprintf(
635
+										__(
636
+											'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
637
+											'event_espresso'
638
+										),
639
+										$config_class
640
+									)
641
+								);
642
+							}
643
+							return false;
644
+						}
645
+						break;
646
+					// TEST #7 : check that config has even been set
647
+					case 7 :
648
+						if (! isset($this->{$section}->{$name})) {
649
+							if ($display_errors) {
650
+								throw new EE_Error(
651
+									sprintf(
652
+										__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
653
+										$section,
654
+										$name
655
+									)
656
+								);
657
+							}
658
+							return false;
659
+						} else {
660
+							// and make sure it's not serialized
661
+							$this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
662
+						}
663
+						break;
664
+					// TEST #8 : check that config is the requested type
665
+					case 8 :
666
+						if (! $this->{$section}->{$name} instanceof $config_class) {
667
+							if ($display_errors) {
668
+								throw new EE_Error(
669
+									sprintf(
670
+										__(
671
+											'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
672
+											'event_espresso'
673
+										),
674
+										$section,
675
+										$name,
676
+										$config_class
677
+									)
678
+								);
679
+							}
680
+							return false;
681
+						}
682
+						break;
683
+					// TEST #9 : verify config object
684
+					case 9 :
685
+						if (! $config_obj instanceof EE_Config_Base) {
686
+							if ($display_errors) {
687
+								throw new EE_Error(
688
+									sprintf(
689
+										__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
690
+										print_r($config_obj, true)
691
+									)
692
+								);
693
+							}
694
+							return false;
695
+						}
696
+						break;
697
+				}
698
+			}
699
+		} catch (EE_Error $e) {
700
+			$e->get_error();
701
+		}
702
+		// you have successfully run the gauntlet
703
+		return true;
704
+	}
705
+
706
+
707
+
708
+	/**
709
+	 *    _generate_config_option_name
710
+	 *
711
+	 * @access        protected
712
+	 * @param        string $section
713
+	 * @param        string $name
714
+	 * @return        string
715
+	 */
716
+	private function _generate_config_option_name($section = '', $name = '')
717
+	{
718
+		return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
719
+	}
720
+
721
+
722
+
723
+	/**
724
+	 *    _set_config_class
725
+	 * ensures that a config class is set, either from a passed config class or one generated from the config name
726
+	 *
727
+	 * @access    private
728
+	 * @param    string $config_class
729
+	 * @param    string $name
730
+	 * @return    string
731
+	 */
732
+	private function _set_config_class($config_class = '', $name = '')
733
+	{
734
+		return ! empty($config_class)
735
+			? $config_class
736
+			: str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
737
+	}
738
+
739
+
740
+
741
+	/**
742
+	 *    set_config
743
+	 *
744
+	 * @access    protected
745
+	 * @param    string         $section
746
+	 * @param    string         $name
747
+	 * @param    string         $config_class
748
+	 * @param    EE_Config_Base $config_obj
749
+	 * @return    EE_Config_Base
750
+	 */
751
+	public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
752
+	{
753
+		// ensure config class is set to something
754
+		$config_class = $this->_set_config_class($config_class, $name);
755
+		// run tests 1-4, 6, and 7 to verify all config params are set and valid
756
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
757
+			return null;
758
+		}
759
+		$config_option_name = $this->_generate_config_option_name($section, $name);
760
+		// if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
761
+		if (! isset($this->_addon_option_names[$config_option_name])) {
762
+			$this->_addon_option_names[$config_option_name] = $config_class;
763
+			$this->update_addon_option_names();
764
+		}
765
+		// verify the incoming config object but suppress errors
766
+		if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
767
+			$config_obj = new $config_class();
768
+		}
769
+		if (get_option($config_option_name)) {
770
+			EE_Config::log($config_option_name);
771
+			update_option($config_option_name, $config_obj);
772
+			$this->{$section}->{$name} = $config_obj;
773
+			return $this->{$section}->{$name};
774
+		} else {
775
+			// create a wp-option for this config
776
+			if (add_option($config_option_name, $config_obj, '', 'no')) {
777
+				$this->{$section}->{$name} = maybe_unserialize($config_obj);
778
+				return $this->{$section}->{$name};
779
+			} else {
780
+				EE_Error::add_error(
781
+					sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
782
+					__FILE__,
783
+					__FUNCTION__,
784
+					__LINE__
785
+				);
786
+				return null;
787
+			}
788
+		}
789
+	}
790
+
791
+
792
+
793
+	/**
794
+	 *    update_config
795
+	 * Important: the config object must ALREADY be set, otherwise this will produce an error.
796
+	 *
797
+	 * @access    public
798
+	 * @param    string                $section
799
+	 * @param    string                $name
800
+	 * @param    EE_Config_Base|string $config_obj
801
+	 * @param    bool                  $throw_errors
802
+	 * @return    bool
803
+	 */
804
+	public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
805
+	{
806
+		// don't allow config updates during WP heartbeats
807
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
808
+			return false;
809
+		}
810
+		$config_obj = maybe_unserialize($config_obj);
811
+		// get class name of the incoming object
812
+		$config_class = get_class($config_obj);
813
+		// run tests 1-5 and 9 to verify config
814
+		if (! $this->_verify_config_params(
815
+			$section,
816
+			$name,
817
+			$config_class,
818
+			$config_obj,
819
+			array(1, 2, 3, 4, 7, 9)
820
+		)
821
+		) {
822
+			return false;
823
+		}
824
+		$config_option_name = $this->_generate_config_option_name($section, $name);
825
+		// check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
826
+		if (! isset($this->_addon_option_names[$config_option_name])) {
827
+			// save new config to db
828
+			if ($this->set_config($section, $name, $config_class, $config_obj)) {
829
+				return true;
830
+			}
831
+		} else {
832
+			// first check if the record already exists
833
+			$existing_config = get_option($config_option_name);
834
+			$config_obj = serialize($config_obj);
835
+			// just return if db record is already up to date (NOT type safe comparison)
836
+			if ($existing_config == $config_obj) {
837
+				$this->{$section}->{$name} = $config_obj;
838
+				return true;
839
+			} else if (update_option($config_option_name, $config_obj)) {
840
+				EE_Config::log($config_option_name);
841
+				// update wp-option for this config class
842
+				$this->{$section}->{$name} = $config_obj;
843
+				return true;
844
+			} elseif ($throw_errors) {
845
+				EE_Error::add_error(
846
+					sprintf(
847
+						__(
848
+							'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
849
+							'event_espresso'
850
+						),
851
+						$config_class,
852
+						'EE_Config->' . $section . '->' . $name
853
+					),
854
+					__FILE__,
855
+					__FUNCTION__,
856
+					__LINE__
857
+				);
858
+			}
859
+		}
860
+		return false;
861
+	}
862
+
863
+
864
+
865
+	/**
866
+	 *    get_config
867
+	 *
868
+	 * @access    public
869
+	 * @param    string $section
870
+	 * @param    string $name
871
+	 * @param    string $config_class
872
+	 * @return    mixed EE_Config_Base | NULL
873
+	 */
874
+	public function get_config($section = '', $name = '', $config_class = '')
875
+	{
876
+		// ensure config class is set to something
877
+		$config_class = $this->_set_config_class($config_class, $name);
878
+		// run tests 1-4, 6 and 7 to verify that all params have been set
879
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
880
+			return null;
881
+		}
882
+		// now test if the requested config object exists, but suppress errors
883
+		if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
884
+			// config already exists, so pass it back
885
+			return $this->{$section}->{$name};
886
+		}
887
+		// load config option from db if it exists
888
+		$config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
889
+		// verify the newly retrieved config object, but suppress errors
890
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
891
+			// config is good, so set it and pass it back
892
+			$this->{$section}->{$name} = $config_obj;
893
+			return $this->{$section}->{$name};
894
+		}
895
+		// oops! $config_obj is not already set and does not exist in the db, so create a new one
896
+		$config_obj = $this->set_config($section, $name, $config_class);
897
+		// verify the newly created config object
898
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
899
+			return $this->{$section}->{$name};
900
+		} else {
901
+			EE_Error::add_error(
902
+				sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
903
+				__FILE__,
904
+				__FUNCTION__,
905
+				__LINE__
906
+			);
907
+		}
908
+		return null;
909
+	}
910
+
911
+
912
+
913
+	/**
914
+	 *    get_config_option
915
+	 *
916
+	 * @access    public
917
+	 * @param    string $config_option_name
918
+	 * @return    mixed EE_Config_Base | FALSE
919
+	 */
920
+	public function get_config_option($config_option_name = '')
921
+	{
922
+		// retrieve the wp-option for this config class.
923
+		$config_option = maybe_unserialize(get_option($config_option_name, array()));
924
+		if (empty($config_option)) {
925
+			EE_Config::log($config_option_name . '-NOT-FOUND');
926
+		}
927
+		return $config_option;
928
+	}
929
+
930
+
931
+
932
+	/**
933
+	 * log
934
+	 *
935
+	 * @param string $config_option_name
936
+	 */
937
+	public static function log($config_option_name = '')
938
+	{
939
+		if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
940
+			$config_log = get_option(EE_Config::LOG_NAME, array());
941
+			//copy incoming $_REQUEST and sanitize it so we can save it
942
+			$_request = $_REQUEST;
943
+			array_walk_recursive($_request, 'sanitize_text_field');
944
+			$config_log[(string)microtime(true)] = array(
945
+				'config_name' => $config_option_name,
946
+				'request'     => $_request,
947
+			);
948
+			update_option(EE_Config::LOG_NAME, $config_log);
949
+		}
950
+	}
951
+
952
+
953
+
954
+	/**
955
+	 * trim_log
956
+	 * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
957
+	 */
958
+	public static function trim_log()
959
+	{
960
+		if (! EE_Config::logging_enabled()) {
961
+			return;
962
+		}
963
+		$config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
964
+		$log_length = count($config_log);
965
+		if ($log_length > EE_Config::LOG_LENGTH) {
966
+			ksort($config_log);
967
+			$config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
968
+			update_option(EE_Config::LOG_NAME, $config_log);
969
+		}
970
+	}
971
+
972
+
973
+
974
+	/**
975
+	 *    get_page_for_posts
976
+	 *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
977
+	 *    wp-option "page_for_posts", or "posts" if no page is selected
978
+	 *
979
+	 * @access    public
980
+	 * @return    string
981
+	 */
982
+	public static function get_page_for_posts()
983
+	{
984
+		$page_for_posts = get_option('page_for_posts');
985
+		if (! $page_for_posts) {
986
+			return 'posts';
987
+		}
988
+		/** @type WPDB $wpdb */
989
+		global $wpdb;
990
+		$SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
991
+		return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
992
+	}
993
+
994
+
995
+
996
+	/**
997
+	 *    register_shortcodes_and_modules.
998
+	 *    At this point, it's too early to tell if we're maintenance mode or not.
999
+	 *    In fact, this is where we give modules a chance to let core know they exist
1000
+	 *    so they can help trigger maintenance mode if it's needed
1001
+	 *
1002
+	 * @access    public
1003
+	 * @return    void
1004
+	 */
1005
+	public function register_shortcodes_and_modules()
1006
+	{
1007
+		// allow modules to set hooks for the rest of the system
1008
+		EE_Registry::instance()->modules = $this->_register_modules();
1009
+	}
1010
+
1011
+
1012
+
1013
+	/**
1014
+	 *    initialize_shortcodes_and_modules
1015
+	 *    meaning they can start adding their hooks to get stuff done
1016
+	 *
1017
+	 * @access    public
1018
+	 * @return    void
1019
+	 */
1020
+	public function initialize_shortcodes_and_modules()
1021
+	{
1022
+		// allow modules to set hooks for the rest of the system
1023
+		$this->_initialize_modules();
1024
+	}
1025
+
1026
+
1027
+
1028
+	/**
1029
+	 *    widgets_init
1030
+	 *
1031
+	 * @access private
1032
+	 * @return void
1033
+	 */
1034
+	public function widgets_init()
1035
+	{
1036
+		//only init widgets on admin pages when not in complete maintenance, and
1037
+		//on frontend when not in any maintenance mode
1038
+		if (
1039
+			! EE_Maintenance_Mode::instance()->level()
1040
+			|| (
1041
+				is_admin()
1042
+				&& EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1043
+			)
1044
+		) {
1045
+			// grab list of installed widgets
1046
+			$widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1047
+			// filter list of modules to register
1048
+			$widgets_to_register = apply_filters(
1049
+				'FHEE__EE_Config__register_widgets__widgets_to_register',
1050
+				$widgets_to_register
1051
+			);
1052
+			if (! empty($widgets_to_register)) {
1053
+				// cycle thru widget folders
1054
+				foreach ($widgets_to_register as $widget_path) {
1055
+					// add to list of installed widget modules
1056
+					EE_Config::register_ee_widget($widget_path);
1057
+				}
1058
+			}
1059
+			// filter list of installed modules
1060
+			EE_Registry::instance()->widgets = apply_filters(
1061
+				'FHEE__EE_Config__register_widgets__installed_widgets',
1062
+				EE_Registry::instance()->widgets
1063
+			);
1064
+		}
1065
+	}
1066
+
1067
+
1068
+
1069
+	/**
1070
+	 *    register_ee_widget - makes core aware of this widget
1071
+	 *
1072
+	 * @access    public
1073
+	 * @param    string $widget_path - full path up to and including widget folder
1074
+	 * @return    void
1075
+	 */
1076
+	public static function register_ee_widget($widget_path = null)
1077
+	{
1078
+		do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1079
+		$widget_ext = '.widget.php';
1080
+		// make all separators match
1081
+		$widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS);
1082
+		// does the file path INCLUDE the actual file name as part of the path ?
1083
+		if (strpos($widget_path, $widget_ext) !== false) {
1084
+			// grab and shortcode file name from directory name and break apart at dots
1085
+			$file_name = explode('.', basename($widget_path));
1086
+			// take first segment from file name pieces and remove class prefix if it exists
1087
+			$widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1088
+			// sanitize shortcode directory name
1089
+			$widget = sanitize_key($widget);
1090
+			// now we need to rebuild the shortcode path
1091
+			$widget_path = explode(DS, $widget_path);
1092
+			// remove last segment
1093
+			array_pop($widget_path);
1094
+			// glue it back together
1095
+			$widget_path = implode(DS, $widget_path);
1096
+		} else {
1097
+			// grab and sanitize widget directory name
1098
+			$widget = sanitize_key(basename($widget_path));
1099
+		}
1100
+		// create classname from widget directory name
1101
+		$widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1102
+		// add class prefix
1103
+		$widget_class = 'EEW_' . $widget;
1104
+		// does the widget exist ?
1105
+		if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1106
+			$msg = sprintf(
1107
+				__(
1108
+					'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1109
+					'event_espresso'
1110
+				),
1111
+				$widget_class,
1112
+				$widget_path . DS . $widget_class . $widget_ext
1113
+			);
1114
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1115
+			return;
1116
+		}
1117
+		// load the widget class file
1118
+		require_once($widget_path . DS . $widget_class . $widget_ext);
1119
+		// verify that class exists
1120
+		if (! class_exists($widget_class)) {
1121
+			$msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1122
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1123
+			return;
1124
+		}
1125
+		register_widget($widget_class);
1126
+		// add to array of registered widgets
1127
+		EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1128
+	}
1129
+
1130
+
1131
+
1132
+	/**
1133
+	 *        _register_modules
1134
+	 *
1135
+	 * @access private
1136
+	 * @return array
1137
+	 */
1138
+	private function _register_modules()
1139
+	{
1140
+		// grab list of installed modules
1141
+		$modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1142
+		// filter list of modules to register
1143
+		$modules_to_register = apply_filters(
1144
+			'FHEE__EE_Config__register_modules__modules_to_register',
1145
+			$modules_to_register
1146
+		);
1147
+		if (! empty($modules_to_register)) {
1148
+			// loop through folders
1149
+			foreach ($modules_to_register as $module_path) {
1150
+				/**TEMPORARILY EXCLUDE gateways from modules for time being**/
1151
+				if (
1152
+					$module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1153
+					&& $module_path !== EE_MODULES . 'gateways'
1154
+				) {
1155
+					// add to list of installed modules
1156
+					EE_Config::register_module($module_path);
1157
+				}
1158
+			}
1159
+		}
1160
+		// filter list of installed modules
1161
+		return apply_filters(
1162
+			'FHEE__EE_Config___register_modules__installed_modules',
1163
+			EE_Registry::instance()->modules
1164
+		);
1165
+	}
1166
+
1167
+
1168
+
1169
+	/**
1170
+	 *    register_module - makes core aware of this module
1171
+	 *
1172
+	 * @access    public
1173
+	 * @param    string $module_path - full path up to and including module folder
1174
+	 * @return    bool
1175
+	 */
1176
+	public static function register_module($module_path = null)
1177
+	{
1178
+		do_action('AHEE__EE_Config__register_module__begin', $module_path);
1179
+		$module_ext = '.module.php';
1180
+		// make all separators match
1181
+		$module_path = str_replace(array('\\', '/'), DS, $module_path);
1182
+		// does the file path INCLUDE the actual file name as part of the path ?
1183
+		if (strpos($module_path, $module_ext) !== false) {
1184
+			// grab and shortcode file name from directory name and break apart at dots
1185
+			$module_file = explode('.', basename($module_path));
1186
+			// now we need to rebuild the shortcode path
1187
+			$module_path = explode(DS, $module_path);
1188
+			// remove last segment
1189
+			array_pop($module_path);
1190
+			// glue it back together
1191
+			$module_path = implode(DS, $module_path) . DS;
1192
+			// take first segment from file name pieces and sanitize it
1193
+			$module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1194
+			// ensure class prefix is added
1195
+			$module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1196
+		} else {
1197
+			// we need to generate the filename based off of the folder name
1198
+			// grab and sanitize module name
1199
+			$module = strtolower(basename($module_path));
1200
+			$module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1201
+			// like trailingslashit()
1202
+			$module_path = rtrim($module_path, DS) . DS;
1203
+			// create classname from module directory name
1204
+			$module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1205
+			// add class prefix
1206
+			$module_class = 'EED_' . $module;
1207
+		}
1208
+		// does the module exist ?
1209
+		if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1210
+			$msg = sprintf(
1211
+				__(
1212
+					'The requested %s module file could not be found or is not readable due to file permissions.',
1213
+					'event_espresso'
1214
+				),
1215
+				$module
1216
+			);
1217
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1218
+			return false;
1219
+		}
1220
+		// load the module class file
1221
+		require_once($module_path . $module_class . $module_ext);
1222
+		// verify that class exists
1223
+		if (! class_exists($module_class)) {
1224
+			$msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1225
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1226
+			return false;
1227
+		}
1228
+		// add to array of registered modules
1229
+		EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1230
+		do_action(
1231
+			'AHEE__EE_Config__register_module__complete',
1232
+			$module_class,
1233
+			EE_Registry::instance()->modules->{$module_class}
1234
+		);
1235
+		return true;
1236
+	}
1237
+
1238
+
1239
+
1240
+	/**
1241
+	 *    _initialize_modules
1242
+	 *    allow modules to set hooks for the rest of the system
1243
+	 *
1244
+	 * @access private
1245
+	 * @return void
1246
+	 */
1247
+	private function _initialize_modules()
1248
+	{
1249
+		// cycle thru shortcode folders
1250
+		foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1251
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1252
+			// which set hooks ?
1253
+			if (is_admin()) {
1254
+				// fire immediately
1255
+				call_user_func(array($module_class, 'set_hooks_admin'));
1256
+			} else {
1257
+				// delay until other systems are online
1258
+				add_action(
1259
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1260
+					array($module_class, 'set_hooks')
1261
+				);
1262
+			}
1263
+		}
1264
+	}
1265
+
1266
+
1267
+
1268
+	/**
1269
+	 *    register_route - adds module method routes to route_map
1270
+	 *
1271
+	 * @access    public
1272
+	 * @param    string $route       - "pretty" public alias for module method
1273
+	 * @param    string $module      - module name (classname without EED_ prefix)
1274
+	 * @param    string $method_name - the actual module method to be routed to
1275
+	 * @param    string $key         - url param key indicating a route is being called
1276
+	 * @return    bool
1277
+	 */
1278
+	public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1279
+	{
1280
+		do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1281
+		$module = str_replace('EED_', '', $module);
1282
+		$module_class = 'EED_' . $module;
1283
+		if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1284
+			$msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1285
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1286
+			return false;
1287
+		}
1288
+		if (empty($route)) {
1289
+			$msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1290
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1291
+			return false;
1292
+		}
1293
+		if (! method_exists('EED_' . $module, $method_name)) {
1294
+			$msg = sprintf(
1295
+				__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1296
+				$route
1297
+			);
1298
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1299
+			return false;
1300
+		}
1301
+		EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name);
1302
+		return true;
1303
+	}
1304
+
1305
+
1306
+
1307
+	/**
1308
+	 *    get_route - get module method route
1309
+	 *
1310
+	 * @access    public
1311
+	 * @param    string $route - "pretty" public alias for module method
1312
+	 * @param    string $key   - url param key indicating a route is being called
1313
+	 * @return    string
1314
+	 */
1315
+	public static function get_route($route = null, $key = 'ee')
1316
+	{
1317
+		do_action('AHEE__EE_Config__get_route__begin', $route);
1318
+		$route = (string)apply_filters('FHEE__EE_Config__get_route', $route);
1319
+		if (isset(EE_Config::$_module_route_map[$key][$route])) {
1320
+			return EE_Config::$_module_route_map[$key][$route];
1321
+		}
1322
+		return null;
1323
+	}
1324
+
1325
+
1326
+
1327
+	/**
1328
+	 *    get_routes - get ALL module method routes
1329
+	 *
1330
+	 * @access    public
1331
+	 * @return    array
1332
+	 */
1333
+	public static function get_routes()
1334
+	{
1335
+		return EE_Config::$_module_route_map;
1336
+	}
1337
+
1338
+
1339
+
1340
+	/**
1341
+	 *    register_forward - allows modules to forward request to another module for further processing
1342
+	 *
1343
+	 * @access    public
1344
+	 * @param    string       $route   - "pretty" public alias for module method
1345
+	 * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1346
+	 *                                 class, allows different forwards to be served based on status
1347
+	 * @param    array|string $forward - function name or array( class, method )
1348
+	 * @param    string       $key     - url param key indicating a route is being called
1349
+	 * @return    bool
1350
+	 */
1351
+	public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1352
+	{
1353
+		do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1354
+		if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1355
+			$msg = sprintf(
1356
+				__('The module route %s for this forward has not been registered.', 'event_espresso'),
1357
+				$route
1358
+			);
1359
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1360
+			return false;
1361
+		}
1362
+		if (empty($forward)) {
1363
+			$msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1364
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1365
+			return false;
1366
+		}
1367
+		if (is_array($forward)) {
1368
+			if (! isset($forward[1])) {
1369
+				$msg = sprintf(
1370
+					__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1371
+					$route
1372
+				);
1373
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1374
+				return false;
1375
+			}
1376
+			if (! method_exists($forward[0], $forward[1])) {
1377
+				$msg = sprintf(
1378
+					__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1379
+					$forward[1],
1380
+					$route
1381
+				);
1382
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1383
+				return false;
1384
+			}
1385
+		} else if (! function_exists($forward)) {
1386
+			$msg = sprintf(
1387
+				__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1388
+				$forward,
1389
+				$route
1390
+			);
1391
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1392
+			return false;
1393
+		}
1394
+		EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward;
1395
+		return true;
1396
+	}
1397
+
1398
+
1399
+
1400
+	/**
1401
+	 *    get_forward - get forwarding route
1402
+	 *
1403
+	 * @access    public
1404
+	 * @param    string  $route  - "pretty" public alias for module method
1405
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1406
+	 *                           allows different forwards to be served based on status
1407
+	 * @param    string  $key    - url param key indicating a route is being called
1408
+	 * @return    string
1409
+	 */
1410
+	public static function get_forward($route = null, $status = 0, $key = 'ee')
1411
+	{
1412
+		do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1413
+		if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) {
1414
+			return apply_filters(
1415
+				'FHEE__EE_Config__get_forward',
1416
+				EE_Config::$_module_forward_map[$key][$route][$status],
1417
+				$route,
1418
+				$status
1419
+			);
1420
+		}
1421
+		return null;
1422
+	}
1423
+
1424
+
1425
+
1426
+	/**
1427
+	 *    register_forward - allows modules to specify different view templates for different method routes and status
1428
+	 *    results
1429
+	 *
1430
+	 * @access    public
1431
+	 * @param    string  $route  - "pretty" public alias for module method
1432
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1433
+	 *                           allows different views to be served based on status
1434
+	 * @param    string  $view
1435
+	 * @param    string  $key    - url param key indicating a route is being called
1436
+	 * @return    bool
1437
+	 */
1438
+	public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1439
+	{
1440
+		do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1441
+		if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1442
+			$msg = sprintf(
1443
+				__('The module route %s for this view has not been registered.', 'event_espresso'),
1444
+				$route
1445
+			);
1446
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1447
+			return false;
1448
+		}
1449
+		if (! is_readable($view)) {
1450
+			$msg = sprintf(
1451
+				__(
1452
+					'The %s view file could not be found or is not readable due to file permissions.',
1453
+					'event_espresso'
1454
+				),
1455
+				$view
1456
+			);
1457
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1458
+			return false;
1459
+		}
1460
+		EE_Config::$_module_view_map[$key][$route][absint($status)] = $view;
1461
+		return true;
1462
+	}
1463
+
1464
+
1465
+
1466
+	/**
1467
+	 *    get_view - get view for route and status
1468
+	 *
1469
+	 * @access    public
1470
+	 * @param    string  $route  - "pretty" public alias for module method
1471
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1472
+	 *                           allows different views to be served based on status
1473
+	 * @param    string  $key    - url param key indicating a route is being called
1474
+	 * @return    string
1475
+	 */
1476
+	public static function get_view($route = null, $status = 0, $key = 'ee')
1477
+	{
1478
+		do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1479
+		if (isset(EE_Config::$_module_view_map[$key][$route][$status])) {
1480
+			return apply_filters(
1481
+				'FHEE__EE_Config__get_view',
1482
+				EE_Config::$_module_view_map[$key][$route][$status],
1483
+				$route,
1484
+				$status
1485
+			);
1486
+		}
1487
+		return null;
1488
+	}
1489
+
1490
+
1491
+
1492
+	public function update_addon_option_names()
1493
+	{
1494
+		update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1495
+	}
1496
+
1497
+
1498
+
1499
+	public function shutdown()
1500
+	{
1501
+		$this->update_addon_option_names();
1502
+	}
1503
+
1504
+
1505
+
1506
+	/**
1507
+	 * @return LegacyShortcodesManager
1508
+	 */
1509
+	public static function getLegacyShortcodesManager()
1510
+	{
1511
+
1512
+		if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1513
+			EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1514
+				EE_Registry::instance()
1515
+			);
1516
+		}
1517
+		return EE_Config::instance()->legacy_shortcodes_manager;
1518
+	}
1519
+
1520
+
1521
+
1522
+	/**
1523
+	 * register_shortcode - makes core aware of this shortcode
1524
+	 *
1525
+	 * @deprecated 4.9.26
1526
+	 * @param    string $shortcode_path - full path up to and including shortcode folder
1527
+	 * @return    bool
1528
+	 */
1529
+	public static function register_shortcode($shortcode_path = null)
1530
+	{
1531
+		EE_Error::doing_it_wrong(
1532
+			__METHOD__,
1533
+			__(
1534
+				'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1535
+				'event_espresso'
1536
+			),
1537
+			'4.9.26'
1538
+		);
1539
+		return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1540
+	}
21 1541
 
22
-    const LOG_NAME           = 'ee_config_log';
23 1542
 
24
-    const LOG_LENGTH         = 100;
25 1543
 
26
-    const ADDON_OPTION_NAMES = 'ee_config_option_names';
27
-
28
-
29
-    /**
30
-     *    instance of the EE_Config object
31
-     *
32
-     * @var    EE_Config $_instance
33
-     * @access    private
34
-     */
35
-    private static $_instance;
36
-
37
-    /**
38
-     * @var boolean $_logging_enabled
39
-     */
40
-    private static $_logging_enabled = false;
41
-
42
-    /**
43
-     * @var LegacyShortcodesManager $legacy_shortcodes_manager
44
-     */
45
-    private $legacy_shortcodes_manager;
46
-
47
-    /**
48
-     * An StdClass whose property names are addon slugs,
49
-     * and values are their config classes
50
-     *
51
-     * @var StdClass
52
-     */
53
-    public $addons;
54
-
55
-    /**
56
-     * @var EE_Admin_Config
57
-     */
58
-    public $admin;
59
-
60
-    /**
61
-     * @var EE_Core_Config
62
-     */
63
-    public $core;
64
-
65
-    /**
66
-     * @var EE_Currency_Config
67
-     */
68
-    public $currency;
69
-
70
-    /**
71
-     * @var EE_Organization_Config
72
-     */
73
-    public $organization;
74
-
75
-    /**
76
-     * @var EE_Registration_Config
77
-     */
78
-    public $registration;
79
-
80
-    /**
81
-     * @var EE_Template_Config
82
-     */
83
-    public $template_settings;
84
-
85
-    /**
86
-     * Holds EE environment values.
87
-     *
88
-     * @var EE_Environment_Config
89
-     */
90
-    public $environment;
91
-
92
-    /**
93
-     * settings pertaining to Google maps
94
-     *
95
-     * @var EE_Map_Config
96
-     */
97
-    public $map_settings;
98
-
99
-    /**
100
-     * settings pertaining to Taxes
101
-     *
102
-     * @var EE_Tax_Config
103
-     */
104
-    public $tax_settings;
105
-
106
-
107
-    /**
108
-     * Settings pertaining to global messages settings.
109
-     *
110
-     * @var EE_Messages_Config
111
-     */
112
-    public $messages;
113
-
114
-    /**
115
-     * @deprecated
116
-     * @var EE_Gateway_Config
117
-     */
118
-    public $gateway;
119
-
120
-    /**
121
-     * @var    array $_addon_option_names
122
-     * @access    private
123
-     */
124
-    private $_addon_option_names = array();
125
-
126
-    /**
127
-     * @var    array $_module_route_map
128
-     * @access    private
129
-     */
130
-    private static $_module_route_map = array();
131
-
132
-    /**
133
-     * @var    array $_module_forward_map
134
-     * @access    private
135
-     */
136
-    private static $_module_forward_map = array();
137
-
138
-    /**
139
-     * @var    array $_module_view_map
140
-     * @access    private
141
-     */
142
-    private static $_module_view_map = array();
143
-
144
-
145
-
146
-    /**
147
-     * @singleton method used to instantiate class object
148
-     * @access    public
149
-     * @return EE_Config instance
150
-     */
151
-    public static function instance()
152
-    {
153
-        // check if class object is instantiated, and instantiated properly
154
-        if (! self::$_instance instanceof EE_Config) {
155
-            self::$_instance = new self();
156
-        }
157
-        return self::$_instance;
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     * Resets the config
164
-     *
165
-     * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
166
-     *                               (default) leaves the database alone, and merely resets the EE_Config object to
167
-     *                               reflect its state in the database
168
-     * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
169
-     *                               $_instance as NULL. Useful in case you want to forget about the old instance on
170
-     *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
171
-     *                               site was put into maintenance mode)
172
-     * @return EE_Config
173
-     */
174
-    public static function reset($hard_reset = false, $reinstantiate = true)
175
-    {
176
-        if (self::$_instance instanceof EE_Config) {
177
-            if ($hard_reset) {
178
-                self::$_instance->legacy_shortcodes_manager = null;
179
-                self::$_instance->_addon_option_names = array();
180
-                self::$_instance->_initialize_config();
181
-                self::$_instance->update_espresso_config();
182
-            }
183
-            self::$_instance->update_addon_option_names();
184
-        }
185
-        self::$_instance = null;
186
-        //we don't need to reset the static properties imo because those should
187
-        //only change when a module is added or removed. Currently we don't
188
-        //support removing a module during a request when it previously existed
189
-        if ($reinstantiate) {
190
-            return self::instance();
191
-        } else {
192
-            return null;
193
-        }
194
-    }
195
-
196
-
197
-
198
-    /**
199
-     *    class constructor
200
-     *
201
-     * @access    private
202
-     */
203
-    private function __construct()
204
-    {
205
-        do_action('AHEE__EE_Config__construct__begin', $this);
206
-        EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
207
-        // setup empty config classes
208
-        $this->_initialize_config();
209
-        // load existing EE site settings
210
-        $this->_load_core_config();
211
-        // confirm everything loaded correctly and set filtered defaults if not
212
-        $this->_verify_config();
213
-        //  register shortcodes and modules
214
-        add_action(
215
-            'AHEE__EE_System__register_shortcodes_modules_and_widgets',
216
-            array($this, 'register_shortcodes_and_modules'),
217
-            999
218
-        );
219
-        //  initialize shortcodes and modules
220
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
221
-        // register widgets
222
-        add_action('widgets_init', array($this, 'widgets_init'), 10);
223
-        // shutdown
224
-        add_action('shutdown', array($this, 'shutdown'), 10);
225
-        // construct__end hook
226
-        do_action('AHEE__EE_Config__construct__end', $this);
227
-        // hardcoded hack
228
-        $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
229
-    }
230
-
231
-
232
-
233
-    /**
234
-     * @return boolean
235
-     */
236
-    public static function logging_enabled()
237
-    {
238
-        return self::$_logging_enabled;
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * use to get the current theme if needed from static context
245
-     *
246
-     * @return string current theme set.
247
-     */
248
-    public static function get_current_theme()
249
-    {
250
-        return isset(self::$_instance->template_settings->current_espresso_theme)
251
-            ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
252
-    }
253
-
254
-
255
-
256
-    /**
257
-     *        _initialize_config
258
-     *
259
-     * @access private
260
-     * @return void
261
-     */
262
-    private function _initialize_config()
263
-    {
264
-        EE_Config::trim_log();
265
-        //set defaults
266
-        $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
267
-        $this->addons = new stdClass();
268
-        // set _module_route_map
269
-        EE_Config::$_module_route_map = array();
270
-        // set _module_forward_map
271
-        EE_Config::$_module_forward_map = array();
272
-        // set _module_view_map
273
-        EE_Config::$_module_view_map = array();
274
-    }
275
-
276
-
277
-
278
-    /**
279
-     *        load core plugin configuration
280
-     *
281
-     * @access private
282
-     * @return void
283
-     */
284
-    private function _load_core_config()
285
-    {
286
-        // load_core_config__start hook
287
-        do_action('AHEE__EE_Config___load_core_config__start', $this);
288
-        $espresso_config = $this->get_espresso_config();
289
-        foreach ($espresso_config as $config => $settings) {
290
-            // load_core_config__start hook
291
-            $settings = apply_filters(
292
-                'FHEE__EE_Config___load_core_config__config_settings',
293
-                $settings,
294
-                $config,
295
-                $this
296
-            );
297
-            if (is_object($settings) && property_exists($this, $config)) {
298
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
299
-                //call configs populate method to ensure any defaults are set for empty values.
300
-                if (method_exists($settings, 'populate')) {
301
-                    $this->{$config}->populate();
302
-                }
303
-                if (method_exists($settings, 'do_hooks')) {
304
-                    $this->{$config}->do_hooks();
305
-                }
306
-            }
307
-        }
308
-        if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
309
-            $this->update_espresso_config();
310
-        }
311
-        // load_core_config__end hook
312
-        do_action('AHEE__EE_Config___load_core_config__end', $this);
313
-    }
314
-
315
-
316
-
317
-    /**
318
-     *    _verify_config
319
-     *
320
-     * @access    protected
321
-     * @return    void
322
-     */
323
-    protected function _verify_config()
324
-    {
325
-        $this->core = $this->core instanceof EE_Core_Config
326
-            ? $this->core
327
-            : new EE_Core_Config();
328
-        $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
329
-        $this->organization = $this->organization instanceof EE_Organization_Config
330
-            ? $this->organization
331
-            : new EE_Organization_Config();
332
-        $this->organization = apply_filters(
333
-            'FHEE__EE_Config___initialize_config__organization',
334
-            $this->organization
335
-        );
336
-        $this->currency = $this->currency instanceof EE_Currency_Config
337
-            ? $this->currency
338
-            : new EE_Currency_Config();
339
-        $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
340
-        $this->registration = $this->registration instanceof EE_Registration_Config
341
-            ? $this->registration
342
-            : new EE_Registration_Config();
343
-        $this->registration = apply_filters(
344
-            'FHEE__EE_Config___initialize_config__registration',
345
-            $this->registration
346
-        );
347
-        $this->admin = $this->admin instanceof EE_Admin_Config
348
-            ? $this->admin
349
-            : new EE_Admin_Config();
350
-        $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
351
-        $this->template_settings = $this->template_settings instanceof EE_Template_Config
352
-            ? $this->template_settings
353
-            : new EE_Template_Config();
354
-        $this->template_settings = apply_filters(
355
-            'FHEE__EE_Config___initialize_config__template_settings',
356
-            $this->template_settings
357
-        );
358
-        $this->map_settings = $this->map_settings instanceof EE_Map_Config
359
-            ? $this->map_settings
360
-            : new EE_Map_Config();
361
-        $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings',
362
-            $this->map_settings);
363
-        $this->environment = $this->environment instanceof EE_Environment_Config
364
-            ? $this->environment
365
-            : new EE_Environment_Config();
366
-        $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment',
367
-            $this->environment);
368
-        $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
369
-            ? $this->tax_settings
370
-            : new EE_Tax_Config();
371
-        $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings',
372
-            $this->tax_settings);
373
-        $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
374
-        $this->messages = $this->messages instanceof EE_Messages_Config
375
-            ? $this->messages
376
-            : new EE_Messages_Config();
377
-        $this->gateway = $this->gateway instanceof EE_Gateway_Config
378
-            ? $this->gateway
379
-            : new EE_Gateway_Config();
380
-        $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
381
-        $this->legacy_shortcodes_manager = null;
382
-    }
383
-
384
-
385
-    /**
386
-     *    get_espresso_config
387
-     *
388
-     * @access    public
389
-     * @return    array of espresso config stuff
390
-     */
391
-    public function get_espresso_config()
392
-    {
393
-        // grab espresso configuration
394
-        return apply_filters(
395
-            'FHEE__EE_Config__get_espresso_config__CFG',
396
-            get_option(EE_Config::OPTION_NAME, array())
397
-        );
398
-    }
399
-
400
-
401
-
402
-    /**
403
-     *    double_check_config_comparison
404
-     *
405
-     * @access    public
406
-     * @param string $option
407
-     * @param        $old_value
408
-     * @param        $value
409
-     */
410
-    public function double_check_config_comparison($option = '', $old_value, $value)
411
-    {
412
-        // make sure we're checking the ee config
413
-        if ($option === EE_Config::OPTION_NAME) {
414
-            // run a loose comparison of the old value against the new value for type and properties,
415
-            // but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
416
-            if ($value != $old_value) {
417
-                // if they are NOT the same, then remove the hook,
418
-                // which means the subsequent update results will be based solely on the update query results
419
-                // the reason we do this is because, as stated above,
420
-                // WP update_option performs an exact instance comparison (===) on any update values passed to it
421
-                // this happens PRIOR to serialization and any subsequent update.
422
-                // If values are found to match their previous old value,
423
-                // then WP bails before performing any update.
424
-                // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
425
-                // it just pulled from the db, with the one being passed to it (which will not match).
426
-                // HOWEVER, once the object is serialized and passed off to MySQL to update,
427
-                // MySQL MAY ALSO NOT perform the update because
428
-                // the string it sees in the db looks the same as the new one it has been passed!!!
429
-                // This results in the query returning an "affected rows" value of ZERO,
430
-                // which gets returned immediately by WP update_option and looks like an error.
431
-                remove_action('update_option', array($this, 'check_config_updated'));
432
-            }
433
-        }
434
-    }
435
-
436
-
437
-
438
-    /**
439
-     *    update_espresso_config
440
-     *
441
-     * @access   public
442
-     */
443
-    protected function _reset_espresso_addon_config()
444
-    {
445
-        $this->_addon_option_names = array();
446
-        foreach ($this->addons as $addon_name => $addon_config_obj) {
447
-            $addon_config_obj = maybe_unserialize($addon_config_obj);
448
-            if ($addon_config_obj instanceof EE_Config_Base) {
449
-                $this->update_config('addons', $addon_name, $addon_config_obj, false);
450
-            }
451
-            $this->addons->{$addon_name} = null;
452
-        }
453
-    }
454
-
455
-
456
-
457
-    /**
458
-     *    update_espresso_config
459
-     *
460
-     * @access   public
461
-     * @param   bool $add_success
462
-     * @param   bool $add_error
463
-     * @return   bool
464
-     */
465
-    public function update_espresso_config($add_success = false, $add_error = true)
466
-    {
467
-        // don't allow config updates during WP heartbeats
468
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
469
-            return false;
470
-        }
471
-        // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
472
-        //$clone = clone( self::$_instance );
473
-        //self::$_instance = NULL;
474
-        do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
475
-        $this->_reset_espresso_addon_config();
476
-        // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
477
-        // but BEFORE the actual update occurs
478
-        add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
479
-        // don't want to persist legacy_shortcodes_manager, but don't want to lose it either
480
-        $legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
481
-        $this->legacy_shortcodes_manager = null;
482
-        // now update "ee_config"
483
-        $saved = update_option(EE_Config::OPTION_NAME, $this);
484
-        $this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
485
-        EE_Config::log(EE_Config::OPTION_NAME);
486
-        // if not saved... check if the hook we just added still exists;
487
-        // if it does, it means one of two things:
488
-        // 		that update_option bailed at the ( $value === $old_value ) conditional,
489
-        //		 or...
490
-        // 		the db update query returned 0 rows affected
491
-        // 		(probably because the data  value was the same from it's perspective)
492
-        // so the existence of the hook means that a negative result from update_option is NOT an error,
493
-        // but just means no update occurred, so don't display an error to the user.
494
-        // BUT... if update_option returns FALSE, AND the hook is missing,
495
-        // then it means that something truly went wrong
496
-        $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
497
-        // remove our action since we don't want it in the system anymore
498
-        remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
499
-        do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
500
-        //self::$_instance = $clone;
501
-        //unset( $clone );
502
-        // if config remains the same or was updated successfully
503
-        if ($saved) {
504
-            if ($add_success) {
505
-                EE_Error::add_success(
506
-                    __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
507
-                    __FILE__,
508
-                    __FUNCTION__,
509
-                    __LINE__
510
-                );
511
-            }
512
-            return true;
513
-        } else {
514
-            if ($add_error) {
515
-                EE_Error::add_error(
516
-                    __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
517
-                    __FILE__,
518
-                    __FUNCTION__,
519
-                    __LINE__
520
-                );
521
-            }
522
-            return false;
523
-        }
524
-    }
525
-
526
-
527
-
528
-    /**
529
-     *    _verify_config_params
530
-     *
531
-     * @access    private
532
-     * @param    string         $section
533
-     * @param    string         $name
534
-     * @param    string         $config_class
535
-     * @param    EE_Config_Base $config_obj
536
-     * @param    array          $tests_to_run
537
-     * @param    bool           $display_errors
538
-     * @return    bool    TRUE on success, FALSE on fail
539
-     */
540
-    private function _verify_config_params(
541
-        $section = '',
542
-        $name = '',
543
-        $config_class = '',
544
-        $config_obj = null,
545
-        $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
546
-        $display_errors = true
547
-    ) {
548
-        try {
549
-            foreach ($tests_to_run as $test) {
550
-                switch ($test) {
551
-                    // TEST #1 : check that section was set
552
-                    case 1 :
553
-                        if (empty($section)) {
554
-                            if ($display_errors) {
555
-                                throw new EE_Error(
556
-                                    sprintf(
557
-                                        __(
558
-                                            'No configuration section has been provided while attempting to save "%s".',
559
-                                            'event_espresso'
560
-                                        ),
561
-                                        $config_class
562
-                                    )
563
-                                );
564
-                            }
565
-                            return false;
566
-                        }
567
-                        break;
568
-                    // TEST #2 : check that settings section exists
569
-                    case 2 :
570
-                        if (! isset($this->{$section})) {
571
-                            if ($display_errors) {
572
-                                throw new EE_Error(
573
-                                    sprintf(
574
-                                        __('The "%s" configuration section does not exist.', 'event_espresso'),
575
-                                        $section
576
-                                    )
577
-                                );
578
-                            }
579
-                            return false;
580
-                        }
581
-                        break;
582
-                    // TEST #3 : check that section is the proper format
583
-                    case 3 :
584
-                        if (
585
-                        ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
586
-                        ) {
587
-                            if ($display_errors) {
588
-                                throw new EE_Error(
589
-                                    sprintf(
590
-                                        __(
591
-                                            'The "%s" configuration settings have not been formatted correctly.',
592
-                                            'event_espresso'
593
-                                        ),
594
-                                        $section
595
-                                    )
596
-                                );
597
-                            }
598
-                            return false;
599
-                        }
600
-                        break;
601
-                    // TEST #4 : check that config section name has been set
602
-                    case 4 :
603
-                        if (empty($name)) {
604
-                            if ($display_errors) {
605
-                                throw new EE_Error(
606
-                                    __(
607
-                                        'No name has been provided for the specific configuration section.',
608
-                                        'event_espresso'
609
-                                    )
610
-                                );
611
-                            }
612
-                            return false;
613
-                        }
614
-                        break;
615
-                    // TEST #5 : check that a config class name has been set
616
-                    case 5 :
617
-                        if (empty($config_class)) {
618
-                            if ($display_errors) {
619
-                                throw new EE_Error(
620
-                                    __(
621
-                                        'No class name has been provided for the specific configuration section.',
622
-                                        'event_espresso'
623
-                                    )
624
-                                );
625
-                            }
626
-                            return false;
627
-                        }
628
-                        break;
629
-                    // TEST #6 : verify config class is accessible
630
-                    case 6 :
631
-                        if (! class_exists($config_class)) {
632
-                            if ($display_errors) {
633
-                                throw new EE_Error(
634
-                                    sprintf(
635
-                                        __(
636
-                                            'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
637
-                                            'event_espresso'
638
-                                        ),
639
-                                        $config_class
640
-                                    )
641
-                                );
642
-                            }
643
-                            return false;
644
-                        }
645
-                        break;
646
-                    // TEST #7 : check that config has even been set
647
-                    case 7 :
648
-                        if (! isset($this->{$section}->{$name})) {
649
-                            if ($display_errors) {
650
-                                throw new EE_Error(
651
-                                    sprintf(
652
-                                        __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
653
-                                        $section,
654
-                                        $name
655
-                                    )
656
-                                );
657
-                            }
658
-                            return false;
659
-                        } else {
660
-                            // and make sure it's not serialized
661
-                            $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
662
-                        }
663
-                        break;
664
-                    // TEST #8 : check that config is the requested type
665
-                    case 8 :
666
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
667
-                            if ($display_errors) {
668
-                                throw new EE_Error(
669
-                                    sprintf(
670
-                                        __(
671
-                                            'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
672
-                                            'event_espresso'
673
-                                        ),
674
-                                        $section,
675
-                                        $name,
676
-                                        $config_class
677
-                                    )
678
-                                );
679
-                            }
680
-                            return false;
681
-                        }
682
-                        break;
683
-                    // TEST #9 : verify config object
684
-                    case 9 :
685
-                        if (! $config_obj instanceof EE_Config_Base) {
686
-                            if ($display_errors) {
687
-                                throw new EE_Error(
688
-                                    sprintf(
689
-                                        __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
690
-                                        print_r($config_obj, true)
691
-                                    )
692
-                                );
693
-                            }
694
-                            return false;
695
-                        }
696
-                        break;
697
-                }
698
-            }
699
-        } catch (EE_Error $e) {
700
-            $e->get_error();
701
-        }
702
-        // you have successfully run the gauntlet
703
-        return true;
704
-    }
705
-
706
-
707
-
708
-    /**
709
-     *    _generate_config_option_name
710
-     *
711
-     * @access        protected
712
-     * @param        string $section
713
-     * @param        string $name
714
-     * @return        string
715
-     */
716
-    private function _generate_config_option_name($section = '', $name = '')
717
-    {
718
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
719
-    }
720
-
721
-
722
-
723
-    /**
724
-     *    _set_config_class
725
-     * ensures that a config class is set, either from a passed config class or one generated from the config name
726
-     *
727
-     * @access    private
728
-     * @param    string $config_class
729
-     * @param    string $name
730
-     * @return    string
731
-     */
732
-    private function _set_config_class($config_class = '', $name = '')
733
-    {
734
-        return ! empty($config_class)
735
-            ? $config_class
736
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
737
-    }
738
-
739
-
740
-
741
-    /**
742
-     *    set_config
743
-     *
744
-     * @access    protected
745
-     * @param    string         $section
746
-     * @param    string         $name
747
-     * @param    string         $config_class
748
-     * @param    EE_Config_Base $config_obj
749
-     * @return    EE_Config_Base
750
-     */
751
-    public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
752
-    {
753
-        // ensure config class is set to something
754
-        $config_class = $this->_set_config_class($config_class, $name);
755
-        // run tests 1-4, 6, and 7 to verify all config params are set and valid
756
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
757
-            return null;
758
-        }
759
-        $config_option_name = $this->_generate_config_option_name($section, $name);
760
-        // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
761
-        if (! isset($this->_addon_option_names[$config_option_name])) {
762
-            $this->_addon_option_names[$config_option_name] = $config_class;
763
-            $this->update_addon_option_names();
764
-        }
765
-        // verify the incoming config object but suppress errors
766
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
767
-            $config_obj = new $config_class();
768
-        }
769
-        if (get_option($config_option_name)) {
770
-            EE_Config::log($config_option_name);
771
-            update_option($config_option_name, $config_obj);
772
-            $this->{$section}->{$name} = $config_obj;
773
-            return $this->{$section}->{$name};
774
-        } else {
775
-            // create a wp-option for this config
776
-            if (add_option($config_option_name, $config_obj, '', 'no')) {
777
-                $this->{$section}->{$name} = maybe_unserialize($config_obj);
778
-                return $this->{$section}->{$name};
779
-            } else {
780
-                EE_Error::add_error(
781
-                    sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
782
-                    __FILE__,
783
-                    __FUNCTION__,
784
-                    __LINE__
785
-                );
786
-                return null;
787
-            }
788
-        }
789
-    }
790
-
791
-
792
-
793
-    /**
794
-     *    update_config
795
-     * Important: the config object must ALREADY be set, otherwise this will produce an error.
796
-     *
797
-     * @access    public
798
-     * @param    string                $section
799
-     * @param    string                $name
800
-     * @param    EE_Config_Base|string $config_obj
801
-     * @param    bool                  $throw_errors
802
-     * @return    bool
803
-     */
804
-    public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
805
-    {
806
-        // don't allow config updates during WP heartbeats
807
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
808
-            return false;
809
-        }
810
-        $config_obj = maybe_unserialize($config_obj);
811
-        // get class name of the incoming object
812
-        $config_class = get_class($config_obj);
813
-        // run tests 1-5 and 9 to verify config
814
-        if (! $this->_verify_config_params(
815
-            $section,
816
-            $name,
817
-            $config_class,
818
-            $config_obj,
819
-            array(1, 2, 3, 4, 7, 9)
820
-        )
821
-        ) {
822
-            return false;
823
-        }
824
-        $config_option_name = $this->_generate_config_option_name($section, $name);
825
-        // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
826
-        if (! isset($this->_addon_option_names[$config_option_name])) {
827
-            // save new config to db
828
-            if ($this->set_config($section, $name, $config_class, $config_obj)) {
829
-                return true;
830
-            }
831
-        } else {
832
-            // first check if the record already exists
833
-            $existing_config = get_option($config_option_name);
834
-            $config_obj = serialize($config_obj);
835
-            // just return if db record is already up to date (NOT type safe comparison)
836
-            if ($existing_config == $config_obj) {
837
-                $this->{$section}->{$name} = $config_obj;
838
-                return true;
839
-            } else if (update_option($config_option_name, $config_obj)) {
840
-                EE_Config::log($config_option_name);
841
-                // update wp-option for this config class
842
-                $this->{$section}->{$name} = $config_obj;
843
-                return true;
844
-            } elseif ($throw_errors) {
845
-                EE_Error::add_error(
846
-                    sprintf(
847
-                        __(
848
-                            'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
849
-                            'event_espresso'
850
-                        ),
851
-                        $config_class,
852
-                        'EE_Config->' . $section . '->' . $name
853
-                    ),
854
-                    __FILE__,
855
-                    __FUNCTION__,
856
-                    __LINE__
857
-                );
858
-            }
859
-        }
860
-        return false;
861
-    }
862
-
863
-
864
-
865
-    /**
866
-     *    get_config
867
-     *
868
-     * @access    public
869
-     * @param    string $section
870
-     * @param    string $name
871
-     * @param    string $config_class
872
-     * @return    mixed EE_Config_Base | NULL
873
-     */
874
-    public function get_config($section = '', $name = '', $config_class = '')
875
-    {
876
-        // ensure config class is set to something
877
-        $config_class = $this->_set_config_class($config_class, $name);
878
-        // run tests 1-4, 6 and 7 to verify that all params have been set
879
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
880
-            return null;
881
-        }
882
-        // now test if the requested config object exists, but suppress errors
883
-        if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
884
-            // config already exists, so pass it back
885
-            return $this->{$section}->{$name};
886
-        }
887
-        // load config option from db if it exists
888
-        $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
889
-        // verify the newly retrieved config object, but suppress errors
890
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
891
-            // config is good, so set it and pass it back
892
-            $this->{$section}->{$name} = $config_obj;
893
-            return $this->{$section}->{$name};
894
-        }
895
-        // oops! $config_obj is not already set and does not exist in the db, so create a new one
896
-        $config_obj = $this->set_config($section, $name, $config_class);
897
-        // verify the newly created config object
898
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
899
-            return $this->{$section}->{$name};
900
-        } else {
901
-            EE_Error::add_error(
902
-                sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
903
-                __FILE__,
904
-                __FUNCTION__,
905
-                __LINE__
906
-            );
907
-        }
908
-        return null;
909
-    }
910
-
911
-
912
-
913
-    /**
914
-     *    get_config_option
915
-     *
916
-     * @access    public
917
-     * @param    string $config_option_name
918
-     * @return    mixed EE_Config_Base | FALSE
919
-     */
920
-    public function get_config_option($config_option_name = '')
921
-    {
922
-        // retrieve the wp-option for this config class.
923
-        $config_option = maybe_unserialize(get_option($config_option_name, array()));
924
-        if (empty($config_option)) {
925
-            EE_Config::log($config_option_name . '-NOT-FOUND');
926
-        }
927
-        return $config_option;
928
-    }
929
-
930
-
931
-
932
-    /**
933
-     * log
934
-     *
935
-     * @param string $config_option_name
936
-     */
937
-    public static function log($config_option_name = '')
938
-    {
939
-        if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
940
-            $config_log = get_option(EE_Config::LOG_NAME, array());
941
-            //copy incoming $_REQUEST and sanitize it so we can save it
942
-            $_request = $_REQUEST;
943
-            array_walk_recursive($_request, 'sanitize_text_field');
944
-            $config_log[(string)microtime(true)] = array(
945
-                'config_name' => $config_option_name,
946
-                'request'     => $_request,
947
-            );
948
-            update_option(EE_Config::LOG_NAME, $config_log);
949
-        }
950
-    }
951
-
952
-
953
-
954
-    /**
955
-     * trim_log
956
-     * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
957
-     */
958
-    public static function trim_log()
959
-    {
960
-        if (! EE_Config::logging_enabled()) {
961
-            return;
962
-        }
963
-        $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
964
-        $log_length = count($config_log);
965
-        if ($log_length > EE_Config::LOG_LENGTH) {
966
-            ksort($config_log);
967
-            $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
968
-            update_option(EE_Config::LOG_NAME, $config_log);
969
-        }
970
-    }
971
-
972
-
973
-
974
-    /**
975
-     *    get_page_for_posts
976
-     *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
977
-     *    wp-option "page_for_posts", or "posts" if no page is selected
978
-     *
979
-     * @access    public
980
-     * @return    string
981
-     */
982
-    public static function get_page_for_posts()
983
-    {
984
-        $page_for_posts = get_option('page_for_posts');
985
-        if (! $page_for_posts) {
986
-            return 'posts';
987
-        }
988
-        /** @type WPDB $wpdb */
989
-        global $wpdb;
990
-        $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
991
-        return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
992
-    }
993
-
994
-
995
-
996
-    /**
997
-     *    register_shortcodes_and_modules.
998
-     *    At this point, it's too early to tell if we're maintenance mode or not.
999
-     *    In fact, this is where we give modules a chance to let core know they exist
1000
-     *    so they can help trigger maintenance mode if it's needed
1001
-     *
1002
-     * @access    public
1003
-     * @return    void
1004
-     */
1005
-    public function register_shortcodes_and_modules()
1006
-    {
1007
-        // allow modules to set hooks for the rest of the system
1008
-        EE_Registry::instance()->modules = $this->_register_modules();
1009
-    }
1010
-
1011
-
1012
-
1013
-    /**
1014
-     *    initialize_shortcodes_and_modules
1015
-     *    meaning they can start adding their hooks to get stuff done
1016
-     *
1017
-     * @access    public
1018
-     * @return    void
1019
-     */
1020
-    public function initialize_shortcodes_and_modules()
1021
-    {
1022
-        // allow modules to set hooks for the rest of the system
1023
-        $this->_initialize_modules();
1024
-    }
1025
-
1026
-
1027
-
1028
-    /**
1029
-     *    widgets_init
1030
-     *
1031
-     * @access private
1032
-     * @return void
1033
-     */
1034
-    public function widgets_init()
1035
-    {
1036
-        //only init widgets on admin pages when not in complete maintenance, and
1037
-        //on frontend when not in any maintenance mode
1038
-        if (
1039
-            ! EE_Maintenance_Mode::instance()->level()
1040
-            || (
1041
-                is_admin()
1042
-                && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1043
-            )
1044
-        ) {
1045
-            // grab list of installed widgets
1046
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1047
-            // filter list of modules to register
1048
-            $widgets_to_register = apply_filters(
1049
-                'FHEE__EE_Config__register_widgets__widgets_to_register',
1050
-                $widgets_to_register
1051
-            );
1052
-            if (! empty($widgets_to_register)) {
1053
-                // cycle thru widget folders
1054
-                foreach ($widgets_to_register as $widget_path) {
1055
-                    // add to list of installed widget modules
1056
-                    EE_Config::register_ee_widget($widget_path);
1057
-                }
1058
-            }
1059
-            // filter list of installed modules
1060
-            EE_Registry::instance()->widgets = apply_filters(
1061
-                'FHEE__EE_Config__register_widgets__installed_widgets',
1062
-                EE_Registry::instance()->widgets
1063
-            );
1064
-        }
1065
-    }
1066
-
1067
-
1068
-
1069
-    /**
1070
-     *    register_ee_widget - makes core aware of this widget
1071
-     *
1072
-     * @access    public
1073
-     * @param    string $widget_path - full path up to and including widget folder
1074
-     * @return    void
1075
-     */
1076
-    public static function register_ee_widget($widget_path = null)
1077
-    {
1078
-        do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1079
-        $widget_ext = '.widget.php';
1080
-        // make all separators match
1081
-        $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS);
1082
-        // does the file path INCLUDE the actual file name as part of the path ?
1083
-        if (strpos($widget_path, $widget_ext) !== false) {
1084
-            // grab and shortcode file name from directory name and break apart at dots
1085
-            $file_name = explode('.', basename($widget_path));
1086
-            // take first segment from file name pieces and remove class prefix if it exists
1087
-            $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1088
-            // sanitize shortcode directory name
1089
-            $widget = sanitize_key($widget);
1090
-            // now we need to rebuild the shortcode path
1091
-            $widget_path = explode(DS, $widget_path);
1092
-            // remove last segment
1093
-            array_pop($widget_path);
1094
-            // glue it back together
1095
-            $widget_path = implode(DS, $widget_path);
1096
-        } else {
1097
-            // grab and sanitize widget directory name
1098
-            $widget = sanitize_key(basename($widget_path));
1099
-        }
1100
-        // create classname from widget directory name
1101
-        $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1102
-        // add class prefix
1103
-        $widget_class = 'EEW_' . $widget;
1104
-        // does the widget exist ?
1105
-        if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1106
-            $msg = sprintf(
1107
-                __(
1108
-                    'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1109
-                    'event_espresso'
1110
-                ),
1111
-                $widget_class,
1112
-                $widget_path . DS . $widget_class . $widget_ext
1113
-            );
1114
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1115
-            return;
1116
-        }
1117
-        // load the widget class file
1118
-        require_once($widget_path . DS . $widget_class . $widget_ext);
1119
-        // verify that class exists
1120
-        if (! class_exists($widget_class)) {
1121
-            $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1122
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1123
-            return;
1124
-        }
1125
-        register_widget($widget_class);
1126
-        // add to array of registered widgets
1127
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1128
-    }
1129
-
1130
-
1131
-
1132
-    /**
1133
-     *        _register_modules
1134
-     *
1135
-     * @access private
1136
-     * @return array
1137
-     */
1138
-    private function _register_modules()
1139
-    {
1140
-        // grab list of installed modules
1141
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1142
-        // filter list of modules to register
1143
-        $modules_to_register = apply_filters(
1144
-            'FHEE__EE_Config__register_modules__modules_to_register',
1145
-            $modules_to_register
1146
-        );
1147
-        if (! empty($modules_to_register)) {
1148
-            // loop through folders
1149
-            foreach ($modules_to_register as $module_path) {
1150
-                /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1151
-                if (
1152
-                    $module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1153
-                    && $module_path !== EE_MODULES . 'gateways'
1154
-                ) {
1155
-                    // add to list of installed modules
1156
-                    EE_Config::register_module($module_path);
1157
-                }
1158
-            }
1159
-        }
1160
-        // filter list of installed modules
1161
-        return apply_filters(
1162
-            'FHEE__EE_Config___register_modules__installed_modules',
1163
-            EE_Registry::instance()->modules
1164
-        );
1165
-    }
1166
-
1167
-
1168
-
1169
-    /**
1170
-     *    register_module - makes core aware of this module
1171
-     *
1172
-     * @access    public
1173
-     * @param    string $module_path - full path up to and including module folder
1174
-     * @return    bool
1175
-     */
1176
-    public static function register_module($module_path = null)
1177
-    {
1178
-        do_action('AHEE__EE_Config__register_module__begin', $module_path);
1179
-        $module_ext = '.module.php';
1180
-        // make all separators match
1181
-        $module_path = str_replace(array('\\', '/'), DS, $module_path);
1182
-        // does the file path INCLUDE the actual file name as part of the path ?
1183
-        if (strpos($module_path, $module_ext) !== false) {
1184
-            // grab and shortcode file name from directory name and break apart at dots
1185
-            $module_file = explode('.', basename($module_path));
1186
-            // now we need to rebuild the shortcode path
1187
-            $module_path = explode(DS, $module_path);
1188
-            // remove last segment
1189
-            array_pop($module_path);
1190
-            // glue it back together
1191
-            $module_path = implode(DS, $module_path) . DS;
1192
-            // take first segment from file name pieces and sanitize it
1193
-            $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1194
-            // ensure class prefix is added
1195
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1196
-        } else {
1197
-            // we need to generate the filename based off of the folder name
1198
-            // grab and sanitize module name
1199
-            $module = strtolower(basename($module_path));
1200
-            $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1201
-            // like trailingslashit()
1202
-            $module_path = rtrim($module_path, DS) . DS;
1203
-            // create classname from module directory name
1204
-            $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1205
-            // add class prefix
1206
-            $module_class = 'EED_' . $module;
1207
-        }
1208
-        // does the module exist ?
1209
-        if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1210
-            $msg = sprintf(
1211
-                __(
1212
-                    'The requested %s module file could not be found or is not readable due to file permissions.',
1213
-                    'event_espresso'
1214
-                ),
1215
-                $module
1216
-            );
1217
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1218
-            return false;
1219
-        }
1220
-        // load the module class file
1221
-        require_once($module_path . $module_class . $module_ext);
1222
-        // verify that class exists
1223
-        if (! class_exists($module_class)) {
1224
-            $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1225
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1226
-            return false;
1227
-        }
1228
-        // add to array of registered modules
1229
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1230
-        do_action(
1231
-            'AHEE__EE_Config__register_module__complete',
1232
-            $module_class,
1233
-            EE_Registry::instance()->modules->{$module_class}
1234
-        );
1235
-        return true;
1236
-    }
1237
-
1238
-
1239
-
1240
-    /**
1241
-     *    _initialize_modules
1242
-     *    allow modules to set hooks for the rest of the system
1243
-     *
1244
-     * @access private
1245
-     * @return void
1246
-     */
1247
-    private function _initialize_modules()
1248
-    {
1249
-        // cycle thru shortcode folders
1250
-        foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1251
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1252
-            // which set hooks ?
1253
-            if (is_admin()) {
1254
-                // fire immediately
1255
-                call_user_func(array($module_class, 'set_hooks_admin'));
1256
-            } else {
1257
-                // delay until other systems are online
1258
-                add_action(
1259
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1260
-                    array($module_class, 'set_hooks')
1261
-                );
1262
-            }
1263
-        }
1264
-    }
1265
-
1266
-
1267
-
1268
-    /**
1269
-     *    register_route - adds module method routes to route_map
1270
-     *
1271
-     * @access    public
1272
-     * @param    string $route       - "pretty" public alias for module method
1273
-     * @param    string $module      - module name (classname without EED_ prefix)
1274
-     * @param    string $method_name - the actual module method to be routed to
1275
-     * @param    string $key         - url param key indicating a route is being called
1276
-     * @return    bool
1277
-     */
1278
-    public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1279
-    {
1280
-        do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1281
-        $module = str_replace('EED_', '', $module);
1282
-        $module_class = 'EED_' . $module;
1283
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1284
-            $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1285
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1286
-            return false;
1287
-        }
1288
-        if (empty($route)) {
1289
-            $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1290
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1291
-            return false;
1292
-        }
1293
-        if (! method_exists('EED_' . $module, $method_name)) {
1294
-            $msg = sprintf(
1295
-                __('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1296
-                $route
1297
-            );
1298
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1299
-            return false;
1300
-        }
1301
-        EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name);
1302
-        return true;
1303
-    }
1304
-
1305
-
1306
-
1307
-    /**
1308
-     *    get_route - get module method route
1309
-     *
1310
-     * @access    public
1311
-     * @param    string $route - "pretty" public alias for module method
1312
-     * @param    string $key   - url param key indicating a route is being called
1313
-     * @return    string
1314
-     */
1315
-    public static function get_route($route = null, $key = 'ee')
1316
-    {
1317
-        do_action('AHEE__EE_Config__get_route__begin', $route);
1318
-        $route = (string)apply_filters('FHEE__EE_Config__get_route', $route);
1319
-        if (isset(EE_Config::$_module_route_map[$key][$route])) {
1320
-            return EE_Config::$_module_route_map[$key][$route];
1321
-        }
1322
-        return null;
1323
-    }
1324
-
1325
-
1326
-
1327
-    /**
1328
-     *    get_routes - get ALL module method routes
1329
-     *
1330
-     * @access    public
1331
-     * @return    array
1332
-     */
1333
-    public static function get_routes()
1334
-    {
1335
-        return EE_Config::$_module_route_map;
1336
-    }
1337
-
1338
-
1339
-
1340
-    /**
1341
-     *    register_forward - allows modules to forward request to another module for further processing
1342
-     *
1343
-     * @access    public
1344
-     * @param    string       $route   - "pretty" public alias for module method
1345
-     * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1346
-     *                                 class, allows different forwards to be served based on status
1347
-     * @param    array|string $forward - function name or array( class, method )
1348
-     * @param    string       $key     - url param key indicating a route is being called
1349
-     * @return    bool
1350
-     */
1351
-    public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1352
-    {
1353
-        do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1354
-        if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1355
-            $msg = sprintf(
1356
-                __('The module route %s for this forward has not been registered.', 'event_espresso'),
1357
-                $route
1358
-            );
1359
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1360
-            return false;
1361
-        }
1362
-        if (empty($forward)) {
1363
-            $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1364
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1365
-            return false;
1366
-        }
1367
-        if (is_array($forward)) {
1368
-            if (! isset($forward[1])) {
1369
-                $msg = sprintf(
1370
-                    __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1371
-                    $route
1372
-                );
1373
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1374
-                return false;
1375
-            }
1376
-            if (! method_exists($forward[0], $forward[1])) {
1377
-                $msg = sprintf(
1378
-                    __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1379
-                    $forward[1],
1380
-                    $route
1381
-                );
1382
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1383
-                return false;
1384
-            }
1385
-        } else if (! function_exists($forward)) {
1386
-            $msg = sprintf(
1387
-                __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1388
-                $forward,
1389
-                $route
1390
-            );
1391
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1392
-            return false;
1393
-        }
1394
-        EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward;
1395
-        return true;
1396
-    }
1397
-
1398
-
1399
-
1400
-    /**
1401
-     *    get_forward - get forwarding route
1402
-     *
1403
-     * @access    public
1404
-     * @param    string  $route  - "pretty" public alias for module method
1405
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1406
-     *                           allows different forwards to be served based on status
1407
-     * @param    string  $key    - url param key indicating a route is being called
1408
-     * @return    string
1409
-     */
1410
-    public static function get_forward($route = null, $status = 0, $key = 'ee')
1411
-    {
1412
-        do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1413
-        if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) {
1414
-            return apply_filters(
1415
-                'FHEE__EE_Config__get_forward',
1416
-                EE_Config::$_module_forward_map[$key][$route][$status],
1417
-                $route,
1418
-                $status
1419
-            );
1420
-        }
1421
-        return null;
1422
-    }
1423
-
1424
-
1425
-
1426
-    /**
1427
-     *    register_forward - allows modules to specify different view templates for different method routes and status
1428
-     *    results
1429
-     *
1430
-     * @access    public
1431
-     * @param    string  $route  - "pretty" public alias for module method
1432
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1433
-     *                           allows different views to be served based on status
1434
-     * @param    string  $view
1435
-     * @param    string  $key    - url param key indicating a route is being called
1436
-     * @return    bool
1437
-     */
1438
-    public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1439
-    {
1440
-        do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1441
-        if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1442
-            $msg = sprintf(
1443
-                __('The module route %s for this view has not been registered.', 'event_espresso'),
1444
-                $route
1445
-            );
1446
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1447
-            return false;
1448
-        }
1449
-        if (! is_readable($view)) {
1450
-            $msg = sprintf(
1451
-                __(
1452
-                    'The %s view file could not be found or is not readable due to file permissions.',
1453
-                    'event_espresso'
1454
-                ),
1455
-                $view
1456
-            );
1457
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1458
-            return false;
1459
-        }
1460
-        EE_Config::$_module_view_map[$key][$route][absint($status)] = $view;
1461
-        return true;
1462
-    }
1463
-
1464
-
1465
-
1466
-    /**
1467
-     *    get_view - get view for route and status
1468
-     *
1469
-     * @access    public
1470
-     * @param    string  $route  - "pretty" public alias for module method
1471
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1472
-     *                           allows different views to be served based on status
1473
-     * @param    string  $key    - url param key indicating a route is being called
1474
-     * @return    string
1475
-     */
1476
-    public static function get_view($route = null, $status = 0, $key = 'ee')
1477
-    {
1478
-        do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1479
-        if (isset(EE_Config::$_module_view_map[$key][$route][$status])) {
1480
-            return apply_filters(
1481
-                'FHEE__EE_Config__get_view',
1482
-                EE_Config::$_module_view_map[$key][$route][$status],
1483
-                $route,
1484
-                $status
1485
-            );
1486
-        }
1487
-        return null;
1488
-    }
1489
-
1490
-
1491
-
1492
-    public function update_addon_option_names()
1493
-    {
1494
-        update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1495
-    }
1496
-
1497
-
1498
-
1499
-    public function shutdown()
1500
-    {
1501
-        $this->update_addon_option_names();
1502
-    }
1503
-
1504
-
1505
-
1506
-    /**
1507
-     * @return LegacyShortcodesManager
1508
-     */
1509
-    public static function getLegacyShortcodesManager()
1510
-    {
1511
-
1512
-        if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1513
-            EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1514
-                EE_Registry::instance()
1515
-            );
1516
-        }
1517
-        return EE_Config::instance()->legacy_shortcodes_manager;
1518
-    }
1519
-
1520
-
1521
-
1522
-    /**
1523
-     * register_shortcode - makes core aware of this shortcode
1524
-     *
1525
-     * @deprecated 4.9.26
1526
-     * @param    string $shortcode_path - full path up to and including shortcode folder
1527
-     * @return    bool
1528
-     */
1529
-    public static function register_shortcode($shortcode_path = null)
1530
-    {
1531
-        EE_Error::doing_it_wrong(
1532
-            __METHOD__,
1533
-            __(
1534
-                'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1535
-                'event_espresso'
1536
-            ),
1537
-            '4.9.26'
1538
-        );
1539
-        return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1540
-    }
1541
-
1542
-
1543
-
1544
-}
1545
-
1546
-
1547
-
1548
-/**
1549
- * Base class used for config classes. These classes should generally not have
1550
- * magic functions in use, except we'll allow them to magically set and get stuff...
1551
- * basically, they should just be well-defined stdClasses
1552
- */
1553
-class EE_Config_Base
1554
-{
1555
-
1556
-    /**
1557
-     * Utility function for escaping the value of a property and returning.
1558
-     *
1559
-     * @param string $property property name (checks to see if exists).
1560
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1561
-     * @throws \EE_Error
1562
-     */
1563
-    public function get_pretty($property)
1564
-    {
1565
-        if (! property_exists($this, $property)) {
1566
-            throw new EE_Error(
1567
-                sprintf(
1568
-                    __(
1569
-                        '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1570
-                        'event_espresso'
1571
-                    ),
1572
-                    get_class($this),
1573
-                    $property
1574
-                )
1575
-            );
1576
-        }
1577
-        //just handling escaping of strings for now.
1578
-        if (is_string($this->{$property})) {
1579
-            return stripslashes($this->{$property});
1580
-        }
1581
-        return $this->{$property};
1582
-    }
1583
-
1584
-
1585
-
1586
-    public function populate()
1587
-    {
1588
-        //grab defaults via a new instance of this class.
1589
-        $class_name = get_class($this);
1590
-        $defaults = new $class_name;
1591
-        //loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1592
-        //default from our $defaults object.
1593
-        foreach (get_object_vars($defaults) as $property => $value) {
1594
-            if ($this->{$property} === null) {
1595
-                $this->{$property} = $value;
1596
-            }
1597
-        }
1598
-        //cleanup
1599
-        unset($defaults);
1600
-    }
1601
-
1602
-
1603
-
1604
-    /**
1605
-     *        __isset
1606
-     *
1607
-     * @param $a
1608
-     * @return bool
1609
-     */
1610
-    public function __isset($a)
1611
-    {
1612
-        return false;
1613
-    }
1614
-
1615
-
1616
-
1617
-    /**
1618
-     *        __unset
1619
-     *
1620
-     * @param $a
1621
-     * @return bool
1622
-     */
1623
-    public function __unset($a)
1624
-    {
1625
-        return false;
1626
-    }
1627
-
1628
-
1629
-
1630
-    /**
1631
-     *        __clone
1632
-     */
1633
-    public function __clone()
1634
-    {
1635
-    }
1636
-
1637
-
1638
-
1639
-    /**
1640
-     *        __wakeup
1641
-     */
1642
-    public function __wakeup()
1643
-    {
1644
-    }
1645
-
1646
-
1647
-
1648
-    /**
1649
-     *        __destruct
1650
-     */
1651
-    public function __destruct()
1652
-    {
1653
-    }
1654
-}
1655
-
1656
-
1657
-
1658
-/**
1659
- * Class for defining what's in the EE_Config relating to registration settings
1660
- */
1661
-class EE_Core_Config extends EE_Config_Base
1662
-{
1663
-
1664
-    public $current_blog_id;
1665
-
1666
-    public $ee_ueip_optin;
1667
-
1668
-    public $ee_ueip_has_notified;
1669
-
1670
-    /**
1671
-     * Not to be confused with the 4 critical page variables (See
1672
-     * get_critical_pages_array()), this is just an array of wp posts that have EE
1673
-     * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1674
-     * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1675
-     *
1676
-     * @var array
1677
-     */
1678
-    public $post_shortcodes;
1679
-
1680
-    public $module_route_map;
1681
-
1682
-    public $module_forward_map;
1683
-
1684
-    public $module_view_map;
1685
-
1686
-    /**
1687
-     * The next 4 vars are the IDs of critical EE pages.
1688
-     *
1689
-     * @var int
1690
-     */
1691
-    public $reg_page_id;
1692
-
1693
-    public $txn_page_id;
1694
-
1695
-    public $thank_you_page_id;
1696
-
1697
-    public $cancel_page_id;
1698
-
1699
-    /**
1700
-     * The next 4 vars are the URLs of critical EE pages.
1701
-     *
1702
-     * @var int
1703
-     */
1704
-    public $reg_page_url;
1705
-
1706
-    public $txn_page_url;
1707
-
1708
-    public $thank_you_page_url;
1709
-
1710
-    public $cancel_page_url;
1711
-
1712
-    /**
1713
-     * The next vars relate to the custom slugs for EE CPT routes
1714
-     */
1715
-    public $event_cpt_slug;
1716
-
1717
-
1718
-    /**
1719
-     * This caches the _ee_ueip_option in case this config is reset in the same
1720
-     * request across blog switches in a multisite context.
1721
-     * Avoids extra queries to the db for this option.
1722
-     *
1723
-     * @var bool
1724
-     */
1725
-    public static $ee_ueip_option;
1726
-
1727
-
1728
-
1729
-    /**
1730
-     *    class constructor
1731
-     *
1732
-     * @access    public
1733
-     */
1734
-    public function __construct()
1735
-    {
1736
-        // set default organization settings
1737
-        $this->current_blog_id = get_current_blog_id();
1738
-        $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1739
-        $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1740
-        $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1741
-        $this->post_shortcodes = array();
1742
-        $this->module_route_map = array();
1743
-        $this->module_forward_map = array();
1744
-        $this->module_view_map = array();
1745
-        // critical EE page IDs
1746
-        $this->reg_page_id = 0;
1747
-        $this->txn_page_id = 0;
1748
-        $this->thank_you_page_id = 0;
1749
-        $this->cancel_page_id = 0;
1750
-        // critical EE page URLs
1751
-        $this->reg_page_url = '';
1752
-        $this->txn_page_url = '';
1753
-        $this->thank_you_page_url = '';
1754
-        $this->cancel_page_url = '';
1755
-        //cpt slugs
1756
-        $this->event_cpt_slug = __('events', 'event_espresso');
1757
-        //ueip constant check
1758
-        if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1759
-            $this->ee_ueip_optin = false;
1760
-            $this->ee_ueip_has_notified = true;
1761
-        }
1762
-    }
1763
-
1764
-
1765
-
1766
-    /**
1767
-     * @return array
1768
-     */
1769
-    public function get_critical_pages_array()
1770
-    {
1771
-        return array(
1772
-            $this->reg_page_id,
1773
-            $this->txn_page_id,
1774
-            $this->thank_you_page_id,
1775
-            $this->cancel_page_id,
1776
-        );
1777
-    }
1778
-
1779
-
1780
-
1781
-    /**
1782
-     * @return array
1783
-     */
1784
-    public function get_critical_pages_shortcodes_array()
1785
-    {
1786
-        return array(
1787
-            $this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1788
-            $this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1789
-            $this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1790
-            $this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1791
-        );
1792
-    }
1793
-
1794
-
1795
-
1796
-    /**
1797
-     *  gets/returns URL for EE reg_page
1798
-     *
1799
-     * @access    public
1800
-     * @return    string
1801
-     */
1802
-    public function reg_page_url()
1803
-    {
1804
-        if (! $this->reg_page_url) {
1805
-            $this->reg_page_url = add_query_arg(
1806
-                                      array('uts' => time()),
1807
-                                      get_permalink($this->reg_page_id)
1808
-                                  ) . '#checkout';
1809
-        }
1810
-        return $this->reg_page_url;
1811
-    }
1812
-
1813
-
1814
-
1815
-    /**
1816
-     *  gets/returns URL for EE txn_page
1817
-     *
1818
-     * @param array $query_args like what gets passed to
1819
-     *                          add_query_arg() as the first argument
1820
-     * @access    public
1821
-     * @return    string
1822
-     */
1823
-    public function txn_page_url($query_args = array())
1824
-    {
1825
-        if (! $this->txn_page_url) {
1826
-            $this->txn_page_url = get_permalink($this->txn_page_id);
1827
-        }
1828
-        if ($query_args) {
1829
-            return add_query_arg($query_args, $this->txn_page_url);
1830
-        } else {
1831
-            return $this->txn_page_url;
1832
-        }
1833
-    }
1834
-
1835
-
1836
-
1837
-    /**
1838
-     *  gets/returns URL for EE thank_you_page
1839
-     *
1840
-     * @param array $query_args like what gets passed to
1841
-     *                          add_query_arg() as the first argument
1842
-     * @access    public
1843
-     * @return    string
1844
-     */
1845
-    public function thank_you_page_url($query_args = array())
1846
-    {
1847
-        if (! $this->thank_you_page_url) {
1848
-            $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1849
-        }
1850
-        if ($query_args) {
1851
-            return add_query_arg($query_args, $this->thank_you_page_url);
1852
-        } else {
1853
-            return $this->thank_you_page_url;
1854
-        }
1855
-    }
1856
-
1857
-
1858
-
1859
-    /**
1860
-     *  gets/returns URL for EE cancel_page
1861
-     *
1862
-     * @access    public
1863
-     * @return    string
1864
-     */
1865
-    public function cancel_page_url()
1866
-    {
1867
-        if (! $this->cancel_page_url) {
1868
-            $this->cancel_page_url = get_permalink($this->cancel_page_id);
1869
-        }
1870
-        return $this->cancel_page_url;
1871
-    }
1872
-
1873
-
1874
-
1875
-    /**
1876
-     * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1877
-     *
1878
-     * @since 4.7.5
1879
-     */
1880
-    protected function _reset_urls()
1881
-    {
1882
-        $this->reg_page_url = '';
1883
-        $this->txn_page_url = '';
1884
-        $this->cancel_page_url = '';
1885
-        $this->thank_you_page_url = '';
1886
-    }
1887
-
1888
-
1889
-
1890
-    /**
1891
-     * Used to return what the optin value is set for the EE User Experience Program.
1892
-     * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1893
-     * on the main site only.
1894
-     *
1895
-     * @return mixed|void
1896
-     */
1897
-    protected function _get_main_ee_ueip_optin()
1898
-    {
1899
-        //if this is the main site then we can just bypass our direct query.
1900
-        if (is_main_site()) {
1901
-            return get_option('ee_ueip_optin', false);
1902
-        }
1903
-        //is this already cached for this request?  If so use it.
1904
-        if ( ! empty(EE_Core_Config::$ee_ueip_option)) {
1905
-            return EE_Core_Config::$ee_ueip_option;
1906
-        }
1907
-        global $wpdb;
1908
-        $current_network_main_site = is_multisite() ? get_current_site() : null;
1909
-        $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1910
-        $option = 'ee_ueip_optin';
1911
-        //set correct table for query
1912
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1913
-        //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1914
-        //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1915
-        //re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1916
-        //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1917
-        //for the purpose of caching.
1918
-        $pre = apply_filters('pre_option_' . $option, false, $option);
1919
-        if (false !== $pre) {
1920
-            EE_Core_Config::$ee_ueip_option = $pre;
1921
-            return EE_Core_Config::$ee_ueip_option;
1922
-        }
1923
-        $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1924
-            $option));
1925
-        if (is_object($row)) {
1926
-            $value = $row->option_value;
1927
-        } else { //option does not exist so use default.
1928
-            return apply_filters('default_option_' . $option, false, $option);
1929
-        }
1930
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1931
-        return EE_Core_Config::$ee_ueip_option;
1932
-    }
1933
-
1934
-
1935
-
1936
-    /**
1937
-     * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1938
-     * on the object.
1939
-     *
1940
-     * @return array
1941
-     */
1942
-    public function __sleep()
1943
-    {
1944
-        //reset all url properties
1945
-        $this->_reset_urls();
1946
-        //return what to save to db
1947
-        return array_keys(get_object_vars($this));
1948
-    }
1949
-
1950
-}
1951
-
1952
-
1953
-
1954
-/**
1955
- * Config class for storing info on the Organization
1956
- */
1957
-class EE_Organization_Config extends EE_Config_Base
1958
-{
1959
-
1960
-    /**
1961
-     * @var string $name
1962
-     * eg EE4.1
1963
-     */
1964
-    public $name;
1965
-
1966
-    /**
1967
-     * @var string $address_1
1968
-     * eg 123 Onna Road
1969
-     */
1970
-    public $address_1;
1971
-
1972
-    /**
1973
-     * @var string $address_2
1974
-     * eg PO Box 123
1975
-     */
1976
-    public $address_2;
1977
-
1978
-    /**
1979
-     * @var string $city
1980
-     * eg Inna City
1981
-     */
1982
-    public $city;
1983
-
1984
-    /**
1985
-     * @var int $STA_ID
1986
-     * eg 4
1987
-     */
1988
-    public $STA_ID;
1989
-
1990
-    /**
1991
-     * @var string $CNT_ISO
1992
-     * eg US
1993
-     */
1994
-    public $CNT_ISO;
1995
-
1996
-    /**
1997
-     * @var string $zip
1998
-     * eg 12345  or V1A 2B3
1999
-     */
2000
-    public $zip;
2001
-
2002
-    /**
2003
-     * @var string $email
2004
-     * eg [email protected]
2005
-     */
2006
-    public $email;
2007
-
2008
-
2009
-    /**
2010
-     * @var string $phone
2011
-     * eg. 111-111-1111
2012
-     */
2013
-    public $phone;
2014
-
2015
-
2016
-    /**
2017
-     * @var string $vat
2018
-     * VAT/Tax Number
2019
-     */
2020
-    public $vat;
2021
-
2022
-    /**
2023
-     * @var string $logo_url
2024
-     * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
2025
-     */
2026
-    public $logo_url;
2027
-
2028
-
2029
-    /**
2030
-     * The below are all various properties for holding links to organization social network profiles
2031
-     *
2032
-     * @var string
2033
-     */
2034
-    /**
2035
-     * facebook (facebook.com/profile.name)
2036
-     *
2037
-     * @var string
2038
-     */
2039
-    public $facebook;
2040
-
2041
-
2042
-    /**
2043
-     * twitter (twitter.com/twitter_handle)
2044
-     *
2045
-     * @var string
2046
-     */
2047
-    public $twitter;
2048
-
2049
-
2050
-    /**
2051
-     * linkedin (linkedin.com/in/profile_name)
2052
-     *
2053
-     * @var string
2054
-     */
2055
-    public $linkedin;
2056
-
2057
-
2058
-    /**
2059
-     * pinterest (www.pinterest.com/profile_name)
2060
-     *
2061
-     * @var string
2062
-     */
2063
-    public $pinterest;
2064
-
2065
-
2066
-    /**
2067
-     * google+ (google.com/+profileName)
2068
-     *
2069
-     * @var string
2070
-     */
2071
-    public $google;
2072
-
2073
-
2074
-    /**
2075
-     * instagram (instagram.com/handle)
2076
-     *
2077
-     * @var string
2078
-     */
2079
-    public $instagram;
2080
-
2081
-
2082
-
2083
-    /**
2084
-     *    class constructor
2085
-     *
2086
-     * @access    public
2087
-     */
2088
-    public function __construct()
2089
-    {
2090
-        // set default organization settings
2091
-        $this->name = get_bloginfo('name');
2092
-        $this->address_1 = '123 Onna Road';
2093
-        $this->address_2 = 'PO Box 123';
2094
-        $this->city = 'Inna City';
2095
-        $this->STA_ID = 4;
2096
-        $this->CNT_ISO = 'US';
2097
-        $this->zip = '12345';
2098
-        $this->email = get_bloginfo('admin_email');
2099
-        $this->phone = '';
2100
-        $this->vat = '123456789';
2101
-        $this->logo_url = '';
2102
-        $this->facebook = '';
2103
-        $this->twitter = '';
2104
-        $this->linkedin = '';
2105
-        $this->pinterest = '';
2106
-        $this->google = '';
2107
-        $this->instagram = '';
2108
-    }
2109
-
2110
-}
2111
-
2112
-
2113
-
2114
-/**
2115
- * Class for defining what's in the EE_Config relating to currency
2116
- */
2117
-class EE_Currency_Config extends EE_Config_Base
2118
-{
2119
-
2120
-    /**
2121
-     * @var string $code
2122
-     * eg 'US'
2123
-     */
2124
-    public $code;
2125
-
2126
-    /**
2127
-     * @var string $name
2128
-     * eg 'Dollar'
2129
-     */
2130
-    public $name;
2131
-
2132
-    /**
2133
-     * plural name
2134
-     *
2135
-     * @var string $plural
2136
-     * eg 'Dollars'
2137
-     */
2138
-    public $plural;
2139
-
2140
-    /**
2141
-     * currency sign
2142
-     *
2143
-     * @var string $sign
2144
-     * eg '$'
2145
-     */
2146
-    public $sign;
2147
-
2148
-    /**
2149
-     * Whether the currency sign should come before the number or not
2150
-     *
2151
-     * @var boolean $sign_b4
2152
-     */
2153
-    public $sign_b4;
2154
-
2155
-    /**
2156
-     * How many digits should come after the decimal place
2157
-     *
2158
-     * @var int $dec_plc
2159
-     */
2160
-    public $dec_plc;
2161
-
2162
-    /**
2163
-     * Symbol to use for decimal mark
2164
-     *
2165
-     * @var string $dec_mrk
2166
-     * eg '.'
2167
-     */
2168
-    public $dec_mrk;
2169
-
2170
-    /**
2171
-     * Symbol to use for thousands
2172
-     *
2173
-     * @var string $thsnds
2174
-     * eg ','
2175
-     */
2176
-    public $thsnds;
2177
-
2178
-
2179
-
2180
-    /**
2181
-     *    class constructor
2182
-     *
2183
-     * @access    public
2184
-     * @param string $CNT_ISO
2185
-     * @throws \EE_Error
2186
-     */
2187
-    public function __construct($CNT_ISO = '')
2188
-    {
2189
-        /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2190
-        $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2191
-        // get country code from organization settings or use default
2192
-        $ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2193
-                   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2194
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
2195
-            : '';
2196
-        // but override if requested
2197
-        $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2198
-        // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2199
-        if (
2200
-            ! empty($CNT_ISO)
2201
-            && EE_Maintenance_Mode::instance()->models_can_query()
2202
-            && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2203
-        ) {
2204
-            // retrieve the country settings from the db, just in case they have been customized
2205
-            $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2206
-            if ($country instanceof EE_Country) {
2207
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2208
-                $this->name = $country->currency_name_single();    // Dollar
2209
-                $this->plural = $country->currency_name_plural();    // Dollars
2210
-                $this->sign = $country->currency_sign();            // currency sign: $
2211
-                $this->sign_b4 = $country->currency_sign_before();        // currency sign before or after: $TRUE  or  FALSE$
2212
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2213
-                $this->dec_mrk = $country->currency_decimal_mark();    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2214
-                $this->thsnds = $country->currency_thousands_separator();    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2215
-            }
2216
-        }
2217
-        // fallback to hardcoded defaults, in case the above failed
2218
-        if (empty($this->code)) {
2219
-            // set default currency settings
2220
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2221
-            $this->name = __('Dollar', 'event_espresso');    // Dollar
2222
-            $this->plural = __('Dollars', 'event_espresso');    // Dollars
2223
-            $this->sign = '$';    // currency sign: $
2224
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2225
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2226
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2227
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2228
-        }
2229
-    }
2230
-}
2231
-
2232
-
2233
-
2234
-/**
2235
- * Class for defining what's in the EE_Config relating to registration settings
2236
- */
2237
-class EE_Registration_Config extends EE_Config_Base
2238
-{
2239
-
2240
-    /**
2241
-     * Default registration status
2242
-     *
2243
-     * @var string $default_STS_ID
2244
-     * eg 'RPP'
2245
-     */
2246
-    public $default_STS_ID;
2247
-
2248
-
2249
-    /**
2250
-     * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2251
-     * registrations)
2252
-     * @var int
2253
-     */
2254
-    public $default_maximum_number_of_tickets;
2255
-
2256
-
2257
-    /**
2258
-     * level of validation to apply to email addresses
2259
-     *
2260
-     * @var string $email_validation_level
2261
-     * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2262
-     */
2263
-    public $email_validation_level;
2264
-
2265
-    /**
2266
-     *    whether or not to show alternate payment options during the reg process if payment status is pending
2267
-     *
2268
-     * @var boolean $show_pending_payment_options
2269
-     */
2270
-    public $show_pending_payment_options;
2271
-
2272
-    /**
2273
-     * Whether to skip the registration confirmation page
2274
-     *
2275
-     * @var boolean $skip_reg_confirmation
2276
-     */
2277
-    public $skip_reg_confirmation;
2278
-
2279
-    /**
2280
-     * an array of SPCO reg steps where:
2281
-     *        the keys denotes the reg step order
2282
-     *        each element consists of an array with the following elements:
2283
-     *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2284
-     *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2285
-     *            "slug" => the URL param used to trigger the reg step
2286
-     *
2287
-     * @var array $reg_steps
2288
-     */
2289
-    public $reg_steps;
2290
-
2291
-    /**
2292
-     * Whether registration confirmation should be the last page of SPCO
2293
-     *
2294
-     * @var boolean $reg_confirmation_last
2295
-     */
2296
-    public $reg_confirmation_last;
2297
-
2298
-    /**
2299
-     * Whether or not to enable the EE Bot Trap
2300
-     *
2301
-     * @var boolean $use_bot_trap
2302
-     */
2303
-    public $use_bot_trap;
2304
-
2305
-    /**
2306
-     * Whether or not to encrypt some data sent by the EE Bot Trap
2307
-     *
2308
-     * @var boolean $use_encryption
2309
-     */
2310
-    public $use_encryption;
1544
+}
2311 1545
 
2312
-    /**
2313
-     * Whether or not to use ReCaptcha
2314
-     *
2315
-     * @var boolean $use_captcha
2316
-     */
2317
-    public $use_captcha;
2318 1546
 
2319
-    /**
2320
-     * ReCaptcha Theme
2321
-     *
2322
-     * @var string $recaptcha_theme
2323
-     *    options: 'dark    ', 'light'
2324
-     */
2325
-    public $recaptcha_theme;
2326 1547
 
2327
-    /**
2328
-     * ReCaptcha Type
2329
-     *
2330
-     * @var string $recaptcha_type
2331
-     *    options: 'audio', 'image'
2332
-     */
2333
-    public $recaptcha_type;
1548
+/**
1549
+ * Base class used for config classes. These classes should generally not have
1550
+ * magic functions in use, except we'll allow them to magically set and get stuff...
1551
+ * basically, they should just be well-defined stdClasses
1552
+ */
1553
+class EE_Config_Base
1554
+{
2334 1555
 
2335
-    /**
2336
-     * ReCaptcha language
2337
-     *
2338
-     * @var string $recaptcha_language
2339
-     * eg 'en'
2340
-     */
2341
-    public $recaptcha_language;
1556
+	/**
1557
+	 * Utility function for escaping the value of a property and returning.
1558
+	 *
1559
+	 * @param string $property property name (checks to see if exists).
1560
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1561
+	 * @throws \EE_Error
1562
+	 */
1563
+	public function get_pretty($property)
1564
+	{
1565
+		if (! property_exists($this, $property)) {
1566
+			throw new EE_Error(
1567
+				sprintf(
1568
+					__(
1569
+						'%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1570
+						'event_espresso'
1571
+					),
1572
+					get_class($this),
1573
+					$property
1574
+				)
1575
+			);
1576
+		}
1577
+		//just handling escaping of strings for now.
1578
+		if (is_string($this->{$property})) {
1579
+			return stripslashes($this->{$property});
1580
+		}
1581
+		return $this->{$property};
1582
+	}
1583
+
1584
+
1585
+
1586
+	public function populate()
1587
+	{
1588
+		//grab defaults via a new instance of this class.
1589
+		$class_name = get_class($this);
1590
+		$defaults = new $class_name;
1591
+		//loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1592
+		//default from our $defaults object.
1593
+		foreach (get_object_vars($defaults) as $property => $value) {
1594
+			if ($this->{$property} === null) {
1595
+				$this->{$property} = $value;
1596
+			}
1597
+		}
1598
+		//cleanup
1599
+		unset($defaults);
1600
+	}
1601
+
1602
+
1603
+
1604
+	/**
1605
+	 *        __isset
1606
+	 *
1607
+	 * @param $a
1608
+	 * @return bool
1609
+	 */
1610
+	public function __isset($a)
1611
+	{
1612
+		return false;
1613
+	}
1614
+
1615
+
1616
+
1617
+	/**
1618
+	 *        __unset
1619
+	 *
1620
+	 * @param $a
1621
+	 * @return bool
1622
+	 */
1623
+	public function __unset($a)
1624
+	{
1625
+		return false;
1626
+	}
1627
+
1628
+
1629
+
1630
+	/**
1631
+	 *        __clone
1632
+	 */
1633
+	public function __clone()
1634
+	{
1635
+	}
1636
+
1637
+
1638
+
1639
+	/**
1640
+	 *        __wakeup
1641
+	 */
1642
+	public function __wakeup()
1643
+	{
1644
+	}
1645
+
1646
+
1647
+
1648
+	/**
1649
+	 *        __destruct
1650
+	 */
1651
+	public function __destruct()
1652
+	{
1653
+	}
1654
+}
2342 1655
 
2343
-    /**
2344
-     * ReCaptcha public key
2345
-     *
2346
-     * @var string $recaptcha_publickey
2347
-     */
2348
-    public $recaptcha_publickey;
2349 1656
 
2350
-    /**
2351
-     * ReCaptcha private key
2352
-     *
2353
-     * @var string $recaptcha_privatekey
2354
-     */
2355
-    public $recaptcha_privatekey;
2356 1657
 
2357
-    /**
2358
-     * ReCaptcha width
2359
-     *
2360
-     * @var int $recaptcha_width
2361
-     * @deprecated
2362
-     */
2363
-    public $recaptcha_width;
1658
+/**
1659
+ * Class for defining what's in the EE_Config relating to registration settings
1660
+ */
1661
+class EE_Core_Config extends EE_Config_Base
1662
+{
2364 1663
 
2365
-    /**
2366
-     * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2367
-     *
2368
-     * @var boolean $track_invalid_checkout_access
2369
-     */
2370
-    protected $track_invalid_checkout_access = true;
1664
+	public $current_blog_id;
1665
+
1666
+	public $ee_ueip_optin;
1667
+
1668
+	public $ee_ueip_has_notified;
1669
+
1670
+	/**
1671
+	 * Not to be confused with the 4 critical page variables (See
1672
+	 * get_critical_pages_array()), this is just an array of wp posts that have EE
1673
+	 * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1674
+	 * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1675
+	 *
1676
+	 * @var array
1677
+	 */
1678
+	public $post_shortcodes;
1679
+
1680
+	public $module_route_map;
1681
+
1682
+	public $module_forward_map;
1683
+
1684
+	public $module_view_map;
1685
+
1686
+	/**
1687
+	 * The next 4 vars are the IDs of critical EE pages.
1688
+	 *
1689
+	 * @var int
1690
+	 */
1691
+	public $reg_page_id;
1692
+
1693
+	public $txn_page_id;
1694
+
1695
+	public $thank_you_page_id;
1696
+
1697
+	public $cancel_page_id;
1698
+
1699
+	/**
1700
+	 * The next 4 vars are the URLs of critical EE pages.
1701
+	 *
1702
+	 * @var int
1703
+	 */
1704
+	public $reg_page_url;
1705
+
1706
+	public $txn_page_url;
1707
+
1708
+	public $thank_you_page_url;
1709
+
1710
+	public $cancel_page_url;
1711
+
1712
+	/**
1713
+	 * The next vars relate to the custom slugs for EE CPT routes
1714
+	 */
1715
+	public $event_cpt_slug;
1716
+
1717
+
1718
+	/**
1719
+	 * This caches the _ee_ueip_option in case this config is reset in the same
1720
+	 * request across blog switches in a multisite context.
1721
+	 * Avoids extra queries to the db for this option.
1722
+	 *
1723
+	 * @var bool
1724
+	 */
1725
+	public static $ee_ueip_option;
1726
+
1727
+
1728
+
1729
+	/**
1730
+	 *    class constructor
1731
+	 *
1732
+	 * @access    public
1733
+	 */
1734
+	public function __construct()
1735
+	{
1736
+		// set default organization settings
1737
+		$this->current_blog_id = get_current_blog_id();
1738
+		$this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1739
+		$this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1740
+		$this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1741
+		$this->post_shortcodes = array();
1742
+		$this->module_route_map = array();
1743
+		$this->module_forward_map = array();
1744
+		$this->module_view_map = array();
1745
+		// critical EE page IDs
1746
+		$this->reg_page_id = 0;
1747
+		$this->txn_page_id = 0;
1748
+		$this->thank_you_page_id = 0;
1749
+		$this->cancel_page_id = 0;
1750
+		// critical EE page URLs
1751
+		$this->reg_page_url = '';
1752
+		$this->txn_page_url = '';
1753
+		$this->thank_you_page_url = '';
1754
+		$this->cancel_page_url = '';
1755
+		//cpt slugs
1756
+		$this->event_cpt_slug = __('events', 'event_espresso');
1757
+		//ueip constant check
1758
+		if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1759
+			$this->ee_ueip_optin = false;
1760
+			$this->ee_ueip_has_notified = true;
1761
+		}
1762
+	}
1763
+
1764
+
1765
+
1766
+	/**
1767
+	 * @return array
1768
+	 */
1769
+	public function get_critical_pages_array()
1770
+	{
1771
+		return array(
1772
+			$this->reg_page_id,
1773
+			$this->txn_page_id,
1774
+			$this->thank_you_page_id,
1775
+			$this->cancel_page_id,
1776
+		);
1777
+	}
1778
+
1779
+
1780
+
1781
+	/**
1782
+	 * @return array
1783
+	 */
1784
+	public function get_critical_pages_shortcodes_array()
1785
+	{
1786
+		return array(
1787
+			$this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1788
+			$this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1789
+			$this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1790
+			$this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1791
+		);
1792
+	}
1793
+
1794
+
1795
+
1796
+	/**
1797
+	 *  gets/returns URL for EE reg_page
1798
+	 *
1799
+	 * @access    public
1800
+	 * @return    string
1801
+	 */
1802
+	public function reg_page_url()
1803
+	{
1804
+		if (! $this->reg_page_url) {
1805
+			$this->reg_page_url = add_query_arg(
1806
+									  array('uts' => time()),
1807
+									  get_permalink($this->reg_page_id)
1808
+								  ) . '#checkout';
1809
+		}
1810
+		return $this->reg_page_url;
1811
+	}
1812
+
1813
+
1814
+
1815
+	/**
1816
+	 *  gets/returns URL for EE txn_page
1817
+	 *
1818
+	 * @param array $query_args like what gets passed to
1819
+	 *                          add_query_arg() as the first argument
1820
+	 * @access    public
1821
+	 * @return    string
1822
+	 */
1823
+	public function txn_page_url($query_args = array())
1824
+	{
1825
+		if (! $this->txn_page_url) {
1826
+			$this->txn_page_url = get_permalink($this->txn_page_id);
1827
+		}
1828
+		if ($query_args) {
1829
+			return add_query_arg($query_args, $this->txn_page_url);
1830
+		} else {
1831
+			return $this->txn_page_url;
1832
+		}
1833
+	}
1834
+
1835
+
1836
+
1837
+	/**
1838
+	 *  gets/returns URL for EE thank_you_page
1839
+	 *
1840
+	 * @param array $query_args like what gets passed to
1841
+	 *                          add_query_arg() as the first argument
1842
+	 * @access    public
1843
+	 * @return    string
1844
+	 */
1845
+	public function thank_you_page_url($query_args = array())
1846
+	{
1847
+		if (! $this->thank_you_page_url) {
1848
+			$this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1849
+		}
1850
+		if ($query_args) {
1851
+			return add_query_arg($query_args, $this->thank_you_page_url);
1852
+		} else {
1853
+			return $this->thank_you_page_url;
1854
+		}
1855
+	}
1856
+
1857
+
1858
+
1859
+	/**
1860
+	 *  gets/returns URL for EE cancel_page
1861
+	 *
1862
+	 * @access    public
1863
+	 * @return    string
1864
+	 */
1865
+	public function cancel_page_url()
1866
+	{
1867
+		if (! $this->cancel_page_url) {
1868
+			$this->cancel_page_url = get_permalink($this->cancel_page_id);
1869
+		}
1870
+		return $this->cancel_page_url;
1871
+	}
1872
+
1873
+
1874
+
1875
+	/**
1876
+	 * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1877
+	 *
1878
+	 * @since 4.7.5
1879
+	 */
1880
+	protected function _reset_urls()
1881
+	{
1882
+		$this->reg_page_url = '';
1883
+		$this->txn_page_url = '';
1884
+		$this->cancel_page_url = '';
1885
+		$this->thank_you_page_url = '';
1886
+	}
1887
+
1888
+
1889
+
1890
+	/**
1891
+	 * Used to return what the optin value is set for the EE User Experience Program.
1892
+	 * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1893
+	 * on the main site only.
1894
+	 *
1895
+	 * @return mixed|void
1896
+	 */
1897
+	protected function _get_main_ee_ueip_optin()
1898
+	{
1899
+		//if this is the main site then we can just bypass our direct query.
1900
+		if (is_main_site()) {
1901
+			return get_option('ee_ueip_optin', false);
1902
+		}
1903
+		//is this already cached for this request?  If so use it.
1904
+		if ( ! empty(EE_Core_Config::$ee_ueip_option)) {
1905
+			return EE_Core_Config::$ee_ueip_option;
1906
+		}
1907
+		global $wpdb;
1908
+		$current_network_main_site = is_multisite() ? get_current_site() : null;
1909
+		$current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1910
+		$option = 'ee_ueip_optin';
1911
+		//set correct table for query
1912
+		$table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1913
+		//rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1914
+		//get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1915
+		//re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1916
+		//this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1917
+		//for the purpose of caching.
1918
+		$pre = apply_filters('pre_option_' . $option, false, $option);
1919
+		if (false !== $pre) {
1920
+			EE_Core_Config::$ee_ueip_option = $pre;
1921
+			return EE_Core_Config::$ee_ueip_option;
1922
+		}
1923
+		$row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1924
+			$option));
1925
+		if (is_object($row)) {
1926
+			$value = $row->option_value;
1927
+		} else { //option does not exist so use default.
1928
+			return apply_filters('default_option_' . $option, false, $option);
1929
+		}
1930
+		EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1931
+		return EE_Core_Config::$ee_ueip_option;
1932
+	}
1933
+
1934
+
1935
+
1936
+	/**
1937
+	 * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1938
+	 * on the object.
1939
+	 *
1940
+	 * @return array
1941
+	 */
1942
+	public function __sleep()
1943
+	{
1944
+		//reset all url properties
1945
+		$this->_reset_urls();
1946
+		//return what to save to db
1947
+		return array_keys(get_object_vars($this));
1948
+	}
2371 1949
 
1950
+}
2372 1951
 
2373 1952
 
2374
-    /**
2375
-     *    class constructor
2376
-     *
2377
-     * @access    public
2378
-     */
2379
-    public function __construct()
2380
-    {
2381
-        // set default registration settings
2382
-        $this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2383
-        $this->email_validation_level = 'wp_default';
2384
-        $this->show_pending_payment_options = true;
2385
-        $this->skip_reg_confirmation = false;
2386
-        $this->reg_steps = array();
2387
-        $this->reg_confirmation_last = false;
2388
-        $this->use_bot_trap = true;
2389
-        $this->use_encryption = true;
2390
-        $this->use_captcha = false;
2391
-        $this->recaptcha_theme = 'light';
2392
-        $this->recaptcha_type = 'image';
2393
-        $this->recaptcha_language = 'en';
2394
-        $this->recaptcha_publickey = null;
2395
-        $this->recaptcha_privatekey = null;
2396
-        $this->recaptcha_width = 500;
2397
-        $this->default_maximum_number_of_tickets = 10;
2398
-    }
2399
-
2400
-
2401
-
2402
-    /**
2403
-     * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2404
-     *
2405
-     * @since 4.8.8.rc.019
2406
-     */
2407
-    public function do_hooks()
2408
-    {
2409
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2410
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2411
-    }
2412 1953
 
1954
+/**
1955
+ * Config class for storing info on the Organization
1956
+ */
1957
+class EE_Organization_Config extends EE_Config_Base
1958
+{
2413 1959
 
1960
+	/**
1961
+	 * @var string $name
1962
+	 * eg EE4.1
1963
+	 */
1964
+	public $name;
1965
+
1966
+	/**
1967
+	 * @var string $address_1
1968
+	 * eg 123 Onna Road
1969
+	 */
1970
+	public $address_1;
1971
+
1972
+	/**
1973
+	 * @var string $address_2
1974
+	 * eg PO Box 123
1975
+	 */
1976
+	public $address_2;
1977
+
1978
+	/**
1979
+	 * @var string $city
1980
+	 * eg Inna City
1981
+	 */
1982
+	public $city;
1983
+
1984
+	/**
1985
+	 * @var int $STA_ID
1986
+	 * eg 4
1987
+	 */
1988
+	public $STA_ID;
1989
+
1990
+	/**
1991
+	 * @var string $CNT_ISO
1992
+	 * eg US
1993
+	 */
1994
+	public $CNT_ISO;
1995
+
1996
+	/**
1997
+	 * @var string $zip
1998
+	 * eg 12345  or V1A 2B3
1999
+	 */
2000
+	public $zip;
2001
+
2002
+	/**
2003
+	 * @var string $email
2004
+	 * eg [email protected]
2005
+	 */
2006
+	public $email;
2007
+
2008
+
2009
+	/**
2010
+	 * @var string $phone
2011
+	 * eg. 111-111-1111
2012
+	 */
2013
+	public $phone;
2014
+
2015
+
2016
+	/**
2017
+	 * @var string $vat
2018
+	 * VAT/Tax Number
2019
+	 */
2020
+	public $vat;
2021
+
2022
+	/**
2023
+	 * @var string $logo_url
2024
+	 * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
2025
+	 */
2026
+	public $logo_url;
2027
+
2028
+
2029
+	/**
2030
+	 * The below are all various properties for holding links to organization social network profiles
2031
+	 *
2032
+	 * @var string
2033
+	 */
2034
+	/**
2035
+	 * facebook (facebook.com/profile.name)
2036
+	 *
2037
+	 * @var string
2038
+	 */
2039
+	public $facebook;
2040
+
2041
+
2042
+	/**
2043
+	 * twitter (twitter.com/twitter_handle)
2044
+	 *
2045
+	 * @var string
2046
+	 */
2047
+	public $twitter;
2048
+
2049
+
2050
+	/**
2051
+	 * linkedin (linkedin.com/in/profile_name)
2052
+	 *
2053
+	 * @var string
2054
+	 */
2055
+	public $linkedin;
2056
+
2057
+
2058
+	/**
2059
+	 * pinterest (www.pinterest.com/profile_name)
2060
+	 *
2061
+	 * @var string
2062
+	 */
2063
+	public $pinterest;
2064
+
2065
+
2066
+	/**
2067
+	 * google+ (google.com/+profileName)
2068
+	 *
2069
+	 * @var string
2070
+	 */
2071
+	public $google;
2072
+
2073
+
2074
+	/**
2075
+	 * instagram (instagram.com/handle)
2076
+	 *
2077
+	 * @var string
2078
+	 */
2079
+	public $instagram;
2080
+
2081
+
2082
+
2083
+	/**
2084
+	 *    class constructor
2085
+	 *
2086
+	 * @access    public
2087
+	 */
2088
+	public function __construct()
2089
+	{
2090
+		// set default organization settings
2091
+		$this->name = get_bloginfo('name');
2092
+		$this->address_1 = '123 Onna Road';
2093
+		$this->address_2 = 'PO Box 123';
2094
+		$this->city = 'Inna City';
2095
+		$this->STA_ID = 4;
2096
+		$this->CNT_ISO = 'US';
2097
+		$this->zip = '12345';
2098
+		$this->email = get_bloginfo('admin_email');
2099
+		$this->phone = '';
2100
+		$this->vat = '123456789';
2101
+		$this->logo_url = '';
2102
+		$this->facebook = '';
2103
+		$this->twitter = '';
2104
+		$this->linkedin = '';
2105
+		$this->pinterest = '';
2106
+		$this->google = '';
2107
+		$this->instagram = '';
2108
+	}
2414 2109
 
2415
-    /**
2416
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status
2417
-     * field matches the config setting for default_STS_ID.
2418
-     */
2419
-    public function set_default_reg_status_on_EEM_Event()
2420
-    {
2421
-        EEM_Event::set_default_reg_status($this->default_STS_ID);
2422
-    }
2110
+}
2423 2111
 
2424 2112
 
2425
-    /**
2426
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2427
-     * for Events matches the config setting for default_maximum_number_of_tickets
2428
-     */
2429
-    public function set_default_max_ticket_on_EEM_Event()
2430
-    {
2431
-        EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2432
-    }
2433 2113
 
2114
+/**
2115
+ * Class for defining what's in the EE_Config relating to currency
2116
+ */
2117
+class EE_Currency_Config extends EE_Config_Base
2118
+{
2434 2119
 
2120
+	/**
2121
+	 * @var string $code
2122
+	 * eg 'US'
2123
+	 */
2124
+	public $code;
2125
+
2126
+	/**
2127
+	 * @var string $name
2128
+	 * eg 'Dollar'
2129
+	 */
2130
+	public $name;
2131
+
2132
+	/**
2133
+	 * plural name
2134
+	 *
2135
+	 * @var string $plural
2136
+	 * eg 'Dollars'
2137
+	 */
2138
+	public $plural;
2139
+
2140
+	/**
2141
+	 * currency sign
2142
+	 *
2143
+	 * @var string $sign
2144
+	 * eg '$'
2145
+	 */
2146
+	public $sign;
2147
+
2148
+	/**
2149
+	 * Whether the currency sign should come before the number or not
2150
+	 *
2151
+	 * @var boolean $sign_b4
2152
+	 */
2153
+	public $sign_b4;
2154
+
2155
+	/**
2156
+	 * How many digits should come after the decimal place
2157
+	 *
2158
+	 * @var int $dec_plc
2159
+	 */
2160
+	public $dec_plc;
2161
+
2162
+	/**
2163
+	 * Symbol to use for decimal mark
2164
+	 *
2165
+	 * @var string $dec_mrk
2166
+	 * eg '.'
2167
+	 */
2168
+	public $dec_mrk;
2169
+
2170
+	/**
2171
+	 * Symbol to use for thousands
2172
+	 *
2173
+	 * @var string $thsnds
2174
+	 * eg ','
2175
+	 */
2176
+	public $thsnds;
2177
+
2178
+
2179
+
2180
+	/**
2181
+	 *    class constructor
2182
+	 *
2183
+	 * @access    public
2184
+	 * @param string $CNT_ISO
2185
+	 * @throws \EE_Error
2186
+	 */
2187
+	public function __construct($CNT_ISO = '')
2188
+	{
2189
+		/** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2190
+		$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2191
+		// get country code from organization settings or use default
2192
+		$ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2193
+				   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2194
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
2195
+			: '';
2196
+		// but override if requested
2197
+		$CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2198
+		// so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2199
+		if (
2200
+			! empty($CNT_ISO)
2201
+			&& EE_Maintenance_Mode::instance()->models_can_query()
2202
+			&& $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2203
+		) {
2204
+			// retrieve the country settings from the db, just in case they have been customized
2205
+			$country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2206
+			if ($country instanceof EE_Country) {
2207
+				$this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2208
+				$this->name = $country->currency_name_single();    // Dollar
2209
+				$this->plural = $country->currency_name_plural();    // Dollars
2210
+				$this->sign = $country->currency_sign();            // currency sign: $
2211
+				$this->sign_b4 = $country->currency_sign_before();        // currency sign before or after: $TRUE  or  FALSE$
2212
+				$this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2213
+				$this->dec_mrk = $country->currency_decimal_mark();    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2214
+				$this->thsnds = $country->currency_thousands_separator();    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2215
+			}
2216
+		}
2217
+		// fallback to hardcoded defaults, in case the above failed
2218
+		if (empty($this->code)) {
2219
+			// set default currency settings
2220
+			$this->code = 'USD';    // currency code: USD, CAD, EUR
2221
+			$this->name = __('Dollar', 'event_espresso');    // Dollar
2222
+			$this->plural = __('Dollars', 'event_espresso');    // Dollars
2223
+			$this->sign = '$';    // currency sign: $
2224
+			$this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2225
+			$this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2226
+			$this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2227
+			$this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2228
+		}
2229
+	}
2230
+}
2435 2231
 
2436
-    /**
2437
-     * @return boolean
2438
-     */
2439
-    public function track_invalid_checkout_access()
2440
-    {
2441
-        return $this->track_invalid_checkout_access;
2442
-    }
2443 2232
 
2444 2233
 
2234
+/**
2235
+ * Class for defining what's in the EE_Config relating to registration settings
2236
+ */
2237
+class EE_Registration_Config extends EE_Config_Base
2238
+{
2445 2239
 
2446
-    /**
2447
-     * @param boolean $track_invalid_checkout_access
2448
-     */
2449
-    public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2450
-    {
2451
-        $this->track_invalid_checkout_access = filter_var(
2452
-            $track_invalid_checkout_access,
2453
-            FILTER_VALIDATE_BOOLEAN
2454
-        );
2455
-    }
2240
+	/**
2241
+	 * Default registration status
2242
+	 *
2243
+	 * @var string $default_STS_ID
2244
+	 * eg 'RPP'
2245
+	 */
2246
+	public $default_STS_ID;
2247
+
2248
+
2249
+	/**
2250
+	 * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2251
+	 * registrations)
2252
+	 * @var int
2253
+	 */
2254
+	public $default_maximum_number_of_tickets;
2255
+
2256
+
2257
+	/**
2258
+	 * level of validation to apply to email addresses
2259
+	 *
2260
+	 * @var string $email_validation_level
2261
+	 * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2262
+	 */
2263
+	public $email_validation_level;
2264
+
2265
+	/**
2266
+	 *    whether or not to show alternate payment options during the reg process if payment status is pending
2267
+	 *
2268
+	 * @var boolean $show_pending_payment_options
2269
+	 */
2270
+	public $show_pending_payment_options;
2271
+
2272
+	/**
2273
+	 * Whether to skip the registration confirmation page
2274
+	 *
2275
+	 * @var boolean $skip_reg_confirmation
2276
+	 */
2277
+	public $skip_reg_confirmation;
2278
+
2279
+	/**
2280
+	 * an array of SPCO reg steps where:
2281
+	 *        the keys denotes the reg step order
2282
+	 *        each element consists of an array with the following elements:
2283
+	 *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2284
+	 *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2285
+	 *            "slug" => the URL param used to trigger the reg step
2286
+	 *
2287
+	 * @var array $reg_steps
2288
+	 */
2289
+	public $reg_steps;
2290
+
2291
+	/**
2292
+	 * Whether registration confirmation should be the last page of SPCO
2293
+	 *
2294
+	 * @var boolean $reg_confirmation_last
2295
+	 */
2296
+	public $reg_confirmation_last;
2297
+
2298
+	/**
2299
+	 * Whether or not to enable the EE Bot Trap
2300
+	 *
2301
+	 * @var boolean $use_bot_trap
2302
+	 */
2303
+	public $use_bot_trap;
2304
+
2305
+	/**
2306
+	 * Whether or not to encrypt some data sent by the EE Bot Trap
2307
+	 *
2308
+	 * @var boolean $use_encryption
2309
+	 */
2310
+	public $use_encryption;
2311
+
2312
+	/**
2313
+	 * Whether or not to use ReCaptcha
2314
+	 *
2315
+	 * @var boolean $use_captcha
2316
+	 */
2317
+	public $use_captcha;
2318
+
2319
+	/**
2320
+	 * ReCaptcha Theme
2321
+	 *
2322
+	 * @var string $recaptcha_theme
2323
+	 *    options: 'dark    ', 'light'
2324
+	 */
2325
+	public $recaptcha_theme;
2326
+
2327
+	/**
2328
+	 * ReCaptcha Type
2329
+	 *
2330
+	 * @var string $recaptcha_type
2331
+	 *    options: 'audio', 'image'
2332
+	 */
2333
+	public $recaptcha_type;
2334
+
2335
+	/**
2336
+	 * ReCaptcha language
2337
+	 *
2338
+	 * @var string $recaptcha_language
2339
+	 * eg 'en'
2340
+	 */
2341
+	public $recaptcha_language;
2342
+
2343
+	/**
2344
+	 * ReCaptcha public key
2345
+	 *
2346
+	 * @var string $recaptcha_publickey
2347
+	 */
2348
+	public $recaptcha_publickey;
2349
+
2350
+	/**
2351
+	 * ReCaptcha private key
2352
+	 *
2353
+	 * @var string $recaptcha_privatekey
2354
+	 */
2355
+	public $recaptcha_privatekey;
2356
+
2357
+	/**
2358
+	 * ReCaptcha width
2359
+	 *
2360
+	 * @var int $recaptcha_width
2361
+	 * @deprecated
2362
+	 */
2363
+	public $recaptcha_width;
2364
+
2365
+	/**
2366
+	 * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2367
+	 *
2368
+	 * @var boolean $track_invalid_checkout_access
2369
+	 */
2370
+	protected $track_invalid_checkout_access = true;
2371
+
2372
+
2373
+
2374
+	/**
2375
+	 *    class constructor
2376
+	 *
2377
+	 * @access    public
2378
+	 */
2379
+	public function __construct()
2380
+	{
2381
+		// set default registration settings
2382
+		$this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2383
+		$this->email_validation_level = 'wp_default';
2384
+		$this->show_pending_payment_options = true;
2385
+		$this->skip_reg_confirmation = false;
2386
+		$this->reg_steps = array();
2387
+		$this->reg_confirmation_last = false;
2388
+		$this->use_bot_trap = true;
2389
+		$this->use_encryption = true;
2390
+		$this->use_captcha = false;
2391
+		$this->recaptcha_theme = 'light';
2392
+		$this->recaptcha_type = 'image';
2393
+		$this->recaptcha_language = 'en';
2394
+		$this->recaptcha_publickey = null;
2395
+		$this->recaptcha_privatekey = null;
2396
+		$this->recaptcha_width = 500;
2397
+		$this->default_maximum_number_of_tickets = 10;
2398
+	}
2399
+
2400
+
2401
+
2402
+	/**
2403
+	 * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2404
+	 *
2405
+	 * @since 4.8.8.rc.019
2406
+	 */
2407
+	public function do_hooks()
2408
+	{
2409
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2410
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2411
+	}
2412
+
2413
+
2414
+
2415
+	/**
2416
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status
2417
+	 * field matches the config setting for default_STS_ID.
2418
+	 */
2419
+	public function set_default_reg_status_on_EEM_Event()
2420
+	{
2421
+		EEM_Event::set_default_reg_status($this->default_STS_ID);
2422
+	}
2423
+
2424
+
2425
+	/**
2426
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2427
+	 * for Events matches the config setting for default_maximum_number_of_tickets
2428
+	 */
2429
+	public function set_default_max_ticket_on_EEM_Event()
2430
+	{
2431
+		EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2432
+	}
2433
+
2434
+
2435
+
2436
+	/**
2437
+	 * @return boolean
2438
+	 */
2439
+	public function track_invalid_checkout_access()
2440
+	{
2441
+		return $this->track_invalid_checkout_access;
2442
+	}
2443
+
2444
+
2445
+
2446
+	/**
2447
+	 * @param boolean $track_invalid_checkout_access
2448
+	 */
2449
+	public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2450
+	{
2451
+		$this->track_invalid_checkout_access = filter_var(
2452
+			$track_invalid_checkout_access,
2453
+			FILTER_VALIDATE_BOOLEAN
2454
+		);
2455
+	}
2456 2456
 
2457 2457
 
2458 2458
 
@@ -2466,160 +2466,160 @@  discard block
 block discarded – undo
2466 2466
 class EE_Admin_Config extends EE_Config_Base
2467 2467
 {
2468 2468
 
2469
-    /**
2470
-     * @var boolean $use_personnel_manager
2471
-     */
2472
-    public $use_personnel_manager;
2473
-
2474
-    /**
2475
-     * @var boolean $use_dashboard_widget
2476
-     */
2477
-    public $use_dashboard_widget;
2478
-
2479
-    /**
2480
-     * @var int $events_in_dashboard
2481
-     */
2482
-    public $events_in_dashboard;
2483
-
2484
-    /**
2485
-     * @var boolean $use_event_timezones
2486
-     */
2487
-    public $use_event_timezones;
2488
-
2489
-    /**
2490
-     * @var boolean $use_full_logging
2491
-     */
2492
-    public $use_full_logging;
2493
-
2494
-    /**
2495
-     * @var string $log_file_name
2496
-     */
2497
-    public $log_file_name;
2498
-
2499
-    /**
2500
-     * @var string $debug_file_name
2501
-     */
2502
-    public $debug_file_name;
2503
-
2504
-    /**
2505
-     * @var boolean $use_remote_logging
2506
-     */
2507
-    public $use_remote_logging;
2508
-
2509
-    /**
2510
-     * @var string $remote_logging_url
2511
-     */
2512
-    public $remote_logging_url;
2513
-
2514
-    /**
2515
-     * @var boolean $show_reg_footer
2516
-     */
2517
-    public $show_reg_footer;
2518
-
2519
-    /**
2520
-     * @var string $affiliate_id
2521
-     */
2522
-    public $affiliate_id;
2523
-
2524
-    /**
2525
-     * help tours on or off (global setting)
2526
-     *
2527
-     * @var boolean
2528
-     */
2529
-    public $help_tour_activation;
2530
-
2531
-    /**
2532
-     * adds extra layer of encoding to session data to prevent serialization errors
2533
-     * but is incompatible with some server configuration errors
2534
-     * if you get "500 internal server errors" during registration, try turning this on
2535
-     * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2536
-     *
2537
-     * @var boolean $encode_session_data
2538
-     */
2539
-    private $encode_session_data = false;
2540
-
2541
-
2542
-
2543
-    /**
2544
-     *    class constructor
2545
-     *
2546
-     * @access    public
2547
-     */
2548
-    public function __construct()
2549
-    {
2550
-        // set default general admin settings
2551
-        $this->use_personnel_manager = true;
2552
-        $this->use_dashboard_widget = true;
2553
-        $this->events_in_dashboard = 30;
2554
-        $this->use_event_timezones = false;
2555
-        $this->use_full_logging = false;
2556
-        $this->use_remote_logging = false;
2557
-        $this->remote_logging_url = null;
2558
-        $this->show_reg_footer = true;
2559
-        $this->affiliate_id = 'default';
2560
-        $this->help_tour_activation = true;
2561
-        $this->encode_session_data = false;
2562
-    }
2563
-
2564
-
2565
-
2566
-    /**
2567
-     * @param bool $reset
2568
-     * @return string
2569
-     */
2570
-    public function log_file_name($reset = false)
2571
-    {
2572
-        if (empty($this->log_file_name) || $reset) {
2573
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2574
-            EE_Config::instance()->update_espresso_config(false, false);
2575
-        }
2576
-        return $this->log_file_name;
2577
-    }
2578
-
2579
-
2580
-
2581
-    /**
2582
-     * @param bool $reset
2583
-     * @return string
2584
-     */
2585
-    public function debug_file_name($reset = false)
2586
-    {
2587
-        if (empty($this->debug_file_name) || $reset) {
2588
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2589
-            EE_Config::instance()->update_espresso_config(false, false);
2590
-        }
2591
-        return $this->debug_file_name;
2592
-    }
2593
-
2594
-
2595
-
2596
-    /**
2597
-     * @return string
2598
-     */
2599
-    public function affiliate_id()
2600
-    {
2601
-        return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2602
-    }
2603
-
2604
-
2605
-
2606
-    /**
2607
-     * @return boolean
2608
-     */
2609
-    public function encode_session_data()
2610
-    {
2611
-        return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2612
-    }
2613
-
2614
-
2615
-
2616
-    /**
2617
-     * @param boolean $encode_session_data
2618
-     */
2619
-    public function set_encode_session_data($encode_session_data)
2620
-    {
2621
-        $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2622
-    }
2469
+	/**
2470
+	 * @var boolean $use_personnel_manager
2471
+	 */
2472
+	public $use_personnel_manager;
2473
+
2474
+	/**
2475
+	 * @var boolean $use_dashboard_widget
2476
+	 */
2477
+	public $use_dashboard_widget;
2478
+
2479
+	/**
2480
+	 * @var int $events_in_dashboard
2481
+	 */
2482
+	public $events_in_dashboard;
2483
+
2484
+	/**
2485
+	 * @var boolean $use_event_timezones
2486
+	 */
2487
+	public $use_event_timezones;
2488
+
2489
+	/**
2490
+	 * @var boolean $use_full_logging
2491
+	 */
2492
+	public $use_full_logging;
2493
+
2494
+	/**
2495
+	 * @var string $log_file_name
2496
+	 */
2497
+	public $log_file_name;
2498
+
2499
+	/**
2500
+	 * @var string $debug_file_name
2501
+	 */
2502
+	public $debug_file_name;
2503
+
2504
+	/**
2505
+	 * @var boolean $use_remote_logging
2506
+	 */
2507
+	public $use_remote_logging;
2508
+
2509
+	/**
2510
+	 * @var string $remote_logging_url
2511
+	 */
2512
+	public $remote_logging_url;
2513
+
2514
+	/**
2515
+	 * @var boolean $show_reg_footer
2516
+	 */
2517
+	public $show_reg_footer;
2518
+
2519
+	/**
2520
+	 * @var string $affiliate_id
2521
+	 */
2522
+	public $affiliate_id;
2523
+
2524
+	/**
2525
+	 * help tours on or off (global setting)
2526
+	 *
2527
+	 * @var boolean
2528
+	 */
2529
+	public $help_tour_activation;
2530
+
2531
+	/**
2532
+	 * adds extra layer of encoding to session data to prevent serialization errors
2533
+	 * but is incompatible with some server configuration errors
2534
+	 * if you get "500 internal server errors" during registration, try turning this on
2535
+	 * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2536
+	 *
2537
+	 * @var boolean $encode_session_data
2538
+	 */
2539
+	private $encode_session_data = false;
2540
+
2541
+
2542
+
2543
+	/**
2544
+	 *    class constructor
2545
+	 *
2546
+	 * @access    public
2547
+	 */
2548
+	public function __construct()
2549
+	{
2550
+		// set default general admin settings
2551
+		$this->use_personnel_manager = true;
2552
+		$this->use_dashboard_widget = true;
2553
+		$this->events_in_dashboard = 30;
2554
+		$this->use_event_timezones = false;
2555
+		$this->use_full_logging = false;
2556
+		$this->use_remote_logging = false;
2557
+		$this->remote_logging_url = null;
2558
+		$this->show_reg_footer = true;
2559
+		$this->affiliate_id = 'default';
2560
+		$this->help_tour_activation = true;
2561
+		$this->encode_session_data = false;
2562
+	}
2563
+
2564
+
2565
+
2566
+	/**
2567
+	 * @param bool $reset
2568
+	 * @return string
2569
+	 */
2570
+	public function log_file_name($reset = false)
2571
+	{
2572
+		if (empty($this->log_file_name) || $reset) {
2573
+			$this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2574
+			EE_Config::instance()->update_espresso_config(false, false);
2575
+		}
2576
+		return $this->log_file_name;
2577
+	}
2578
+
2579
+
2580
+
2581
+	/**
2582
+	 * @param bool $reset
2583
+	 * @return string
2584
+	 */
2585
+	public function debug_file_name($reset = false)
2586
+	{
2587
+		if (empty($this->debug_file_name) || $reset) {
2588
+			$this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2589
+			EE_Config::instance()->update_espresso_config(false, false);
2590
+		}
2591
+		return $this->debug_file_name;
2592
+	}
2593
+
2594
+
2595
+
2596
+	/**
2597
+	 * @return string
2598
+	 */
2599
+	public function affiliate_id()
2600
+	{
2601
+		return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2602
+	}
2603
+
2604
+
2605
+
2606
+	/**
2607
+	 * @return boolean
2608
+	 */
2609
+	public function encode_session_data()
2610
+	{
2611
+		return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2612
+	}
2613
+
2614
+
2615
+
2616
+	/**
2617
+	 * @param boolean $encode_session_data
2618
+	 */
2619
+	public function set_encode_session_data($encode_session_data)
2620
+	{
2621
+		$this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2622
+	}
2623 2623
 
2624 2624
 
2625 2625
 
@@ -2633,71 +2633,71 @@  discard block
 block discarded – undo
2633 2633
 class EE_Template_Config extends EE_Config_Base
2634 2634
 {
2635 2635
 
2636
-    /**
2637
-     * @var boolean $enable_default_style
2638
-     */
2639
-    public $enable_default_style;
2640
-
2641
-    /**
2642
-     * @var string $custom_style_sheet
2643
-     */
2644
-    public $custom_style_sheet;
2645
-
2646
-    /**
2647
-     * @var boolean $display_address_in_regform
2648
-     */
2649
-    public $display_address_in_regform;
2650
-
2651
-    /**
2652
-     * @var int $display_description_on_multi_reg_page
2653
-     */
2654
-    public $display_description_on_multi_reg_page;
2655
-
2656
-    /**
2657
-     * @var boolean $use_custom_templates
2658
-     */
2659
-    public $use_custom_templates;
2660
-
2661
-    /**
2662
-     * @var string $current_espresso_theme
2663
-     */
2664
-    public $current_espresso_theme;
2665
-
2666
-    /**
2667
-     * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2668
-     */
2669
-    public $EED_Ticket_Selector;
2670
-
2671
-    /**
2672
-     * @var EE_Event_Single_Config $EED_Event_Single
2673
-     */
2674
-    public $EED_Event_Single;
2675
-
2676
-    /**
2677
-     * @var EE_Events_Archive_Config $EED_Events_Archive
2678
-     */
2679
-    public $EED_Events_Archive;
2680
-
2681
-
2682
-
2683
-    /**
2684
-     *    class constructor
2685
-     *
2686
-     * @access    public
2687
-     */
2688
-    public function __construct()
2689
-    {
2690
-        // set default template settings
2691
-        $this->enable_default_style = true;
2692
-        $this->custom_style_sheet = null;
2693
-        $this->display_address_in_regform = true;
2694
-        $this->display_description_on_multi_reg_page = false;
2695
-        $this->use_custom_templates = false;
2696
-        $this->current_espresso_theme = 'Espresso_Arabica_2014';
2697
-        $this->EED_Event_Single = null;
2698
-        $this->EED_Events_Archive = null;
2699
-        $this->EED_Ticket_Selector = null;
2700
-    }
2636
+	/**
2637
+	 * @var boolean $enable_default_style
2638
+	 */
2639
+	public $enable_default_style;
2640
+
2641
+	/**
2642
+	 * @var string $custom_style_sheet
2643
+	 */
2644
+	public $custom_style_sheet;
2645
+
2646
+	/**
2647
+	 * @var boolean $display_address_in_regform
2648
+	 */
2649
+	public $display_address_in_regform;
2650
+
2651
+	/**
2652
+	 * @var int $display_description_on_multi_reg_page
2653
+	 */
2654
+	public $display_description_on_multi_reg_page;
2655
+
2656
+	/**
2657
+	 * @var boolean $use_custom_templates
2658
+	 */
2659
+	public $use_custom_templates;
2660
+
2661
+	/**
2662
+	 * @var string $current_espresso_theme
2663
+	 */
2664
+	public $current_espresso_theme;
2665
+
2666
+	/**
2667
+	 * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2668
+	 */
2669
+	public $EED_Ticket_Selector;
2670
+
2671
+	/**
2672
+	 * @var EE_Event_Single_Config $EED_Event_Single
2673
+	 */
2674
+	public $EED_Event_Single;
2675
+
2676
+	/**
2677
+	 * @var EE_Events_Archive_Config $EED_Events_Archive
2678
+	 */
2679
+	public $EED_Events_Archive;
2680
+
2681
+
2682
+
2683
+	/**
2684
+	 *    class constructor
2685
+	 *
2686
+	 * @access    public
2687
+	 */
2688
+	public function __construct()
2689
+	{
2690
+		// set default template settings
2691
+		$this->enable_default_style = true;
2692
+		$this->custom_style_sheet = null;
2693
+		$this->display_address_in_regform = true;
2694
+		$this->display_description_on_multi_reg_page = false;
2695
+		$this->use_custom_templates = false;
2696
+		$this->current_espresso_theme = 'Espresso_Arabica_2014';
2697
+		$this->EED_Event_Single = null;
2698
+		$this->EED_Events_Archive = null;
2699
+		$this->EED_Ticket_Selector = null;
2700
+	}
2701 2701
 
2702 2702
 }
2703 2703
 
@@ -2709,115 +2709,115 @@  discard block
 block discarded – undo
2709 2709
 class EE_Map_Config extends EE_Config_Base
2710 2710
 {
2711 2711
 
2712
-    /**
2713
-     * @var boolean $use_google_maps
2714
-     */
2715
-    public $use_google_maps;
2716
-
2717
-    /**
2718
-     * @var string $api_key
2719
-     */
2720
-    public $google_map_api_key;
2721
-
2722
-    /**
2723
-     * @var int $event_details_map_width
2724
-     */
2725
-    public $event_details_map_width;
2726
-
2727
-    /**
2728
-     * @var int $event_details_map_height
2729
-     */
2730
-    public $event_details_map_height;
2731
-
2732
-    /**
2733
-     * @var int $event_details_map_zoom
2734
-     */
2735
-    public $event_details_map_zoom;
2736
-
2737
-    /**
2738
-     * @var boolean $event_details_display_nav
2739
-     */
2740
-    public $event_details_display_nav;
2741
-
2742
-    /**
2743
-     * @var boolean $event_details_nav_size
2744
-     */
2745
-    public $event_details_nav_size;
2746
-
2747
-    /**
2748
-     * @var string $event_details_control_type
2749
-     */
2750
-    public $event_details_control_type;
2751
-
2752
-    /**
2753
-     * @var string $event_details_map_align
2754
-     */
2755
-    public $event_details_map_align;
2756
-
2757
-    /**
2758
-     * @var int $event_list_map_width
2759
-     */
2760
-    public $event_list_map_width;
2761
-
2762
-    /**
2763
-     * @var int $event_list_map_height
2764
-     */
2765
-    public $event_list_map_height;
2766
-
2767
-    /**
2768
-     * @var int $event_list_map_zoom
2769
-     */
2770
-    public $event_list_map_zoom;
2771
-
2772
-    /**
2773
-     * @var boolean $event_list_display_nav
2774
-     */
2775
-    public $event_list_display_nav;
2776
-
2777
-    /**
2778
-     * @var boolean $event_list_nav_size
2779
-     */
2780
-    public $event_list_nav_size;
2781
-
2782
-    /**
2783
-     * @var string $event_list_control_type
2784
-     */
2785
-    public $event_list_control_type;
2786
-
2787
-    /**
2788
-     * @var string $event_list_map_align
2789
-     */
2790
-    public $event_list_map_align;
2791
-
2792
-
2793
-
2794
-    /**
2795
-     *    class constructor
2796
-     *
2797
-     * @access    public
2798
-     */
2799
-    public function __construct()
2800
-    {
2801
-        // set default map settings
2802
-        $this->use_google_maps = true;
2803
-        $this->google_map_api_key = '';
2804
-        // for event details pages (reg page)
2805
-        $this->event_details_map_width = 585;            // ee_map_width_single
2806
-        $this->event_details_map_height = 362;            // ee_map_height_single
2807
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2808
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2809
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2810
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2811
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2812
-        // for event list pages
2813
-        $this->event_list_map_width = 300;            // ee_map_width
2814
-        $this->event_list_map_height = 185;        // ee_map_height
2815
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2816
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2817
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2818
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2819
-        $this->event_list_map_align = 'center';            // ee_map_align
2820
-    }
2712
+	/**
2713
+	 * @var boolean $use_google_maps
2714
+	 */
2715
+	public $use_google_maps;
2716
+
2717
+	/**
2718
+	 * @var string $api_key
2719
+	 */
2720
+	public $google_map_api_key;
2721
+
2722
+	/**
2723
+	 * @var int $event_details_map_width
2724
+	 */
2725
+	public $event_details_map_width;
2726
+
2727
+	/**
2728
+	 * @var int $event_details_map_height
2729
+	 */
2730
+	public $event_details_map_height;
2731
+
2732
+	/**
2733
+	 * @var int $event_details_map_zoom
2734
+	 */
2735
+	public $event_details_map_zoom;
2736
+
2737
+	/**
2738
+	 * @var boolean $event_details_display_nav
2739
+	 */
2740
+	public $event_details_display_nav;
2741
+
2742
+	/**
2743
+	 * @var boolean $event_details_nav_size
2744
+	 */
2745
+	public $event_details_nav_size;
2746
+
2747
+	/**
2748
+	 * @var string $event_details_control_type
2749
+	 */
2750
+	public $event_details_control_type;
2751
+
2752
+	/**
2753
+	 * @var string $event_details_map_align
2754
+	 */
2755
+	public $event_details_map_align;
2756
+
2757
+	/**
2758
+	 * @var int $event_list_map_width
2759
+	 */
2760
+	public $event_list_map_width;
2761
+
2762
+	/**
2763
+	 * @var int $event_list_map_height
2764
+	 */
2765
+	public $event_list_map_height;
2766
+
2767
+	/**
2768
+	 * @var int $event_list_map_zoom
2769
+	 */
2770
+	public $event_list_map_zoom;
2771
+
2772
+	/**
2773
+	 * @var boolean $event_list_display_nav
2774
+	 */
2775
+	public $event_list_display_nav;
2776
+
2777
+	/**
2778
+	 * @var boolean $event_list_nav_size
2779
+	 */
2780
+	public $event_list_nav_size;
2781
+
2782
+	/**
2783
+	 * @var string $event_list_control_type
2784
+	 */
2785
+	public $event_list_control_type;
2786
+
2787
+	/**
2788
+	 * @var string $event_list_map_align
2789
+	 */
2790
+	public $event_list_map_align;
2791
+
2792
+
2793
+
2794
+	/**
2795
+	 *    class constructor
2796
+	 *
2797
+	 * @access    public
2798
+	 */
2799
+	public function __construct()
2800
+	{
2801
+		// set default map settings
2802
+		$this->use_google_maps = true;
2803
+		$this->google_map_api_key = '';
2804
+		// for event details pages (reg page)
2805
+		$this->event_details_map_width = 585;            // ee_map_width_single
2806
+		$this->event_details_map_height = 362;            // ee_map_height_single
2807
+		$this->event_details_map_zoom = 14;            // ee_map_zoom_single
2808
+		$this->event_details_display_nav = true;            // ee_map_nav_display_single
2809
+		$this->event_details_nav_size = false;            // ee_map_nav_size_single
2810
+		$this->event_details_control_type = 'default';        // ee_map_type_control_single
2811
+		$this->event_details_map_align = 'center';            // ee_map_align_single
2812
+		// for event list pages
2813
+		$this->event_list_map_width = 300;            // ee_map_width
2814
+		$this->event_list_map_height = 185;        // ee_map_height
2815
+		$this->event_list_map_zoom = 12;            // ee_map_zoom
2816
+		$this->event_list_display_nav = false;        // ee_map_nav_display
2817
+		$this->event_list_nav_size = true;            // ee_map_nav_size
2818
+		$this->event_list_control_type = 'dropdown';        // ee_map_type_control
2819
+		$this->event_list_map_align = 'center';            // ee_map_align
2820
+	}
2821 2821
 
2822 2822
 }
2823 2823
 
@@ -2829,47 +2829,47 @@  discard block
 block discarded – undo
2829 2829
 class EE_Events_Archive_Config extends EE_Config_Base
2830 2830
 {
2831 2831
 
2832
-    public $display_status_banner;
2832
+	public $display_status_banner;
2833 2833
 
2834
-    public $display_description;
2834
+	public $display_description;
2835 2835
 
2836
-    public $display_ticket_selector;
2836
+	public $display_ticket_selector;
2837 2837
 
2838
-    public $display_datetimes;
2838
+	public $display_datetimes;
2839 2839
 
2840
-    public $display_venue;
2840
+	public $display_venue;
2841 2841
 
2842
-    public $display_expired_events;
2842
+	public $display_expired_events;
2843 2843
 
2844
-    public $use_sortable_display_order;
2844
+	public $use_sortable_display_order;
2845 2845
 
2846
-    public $display_order_tickets;
2846
+	public $display_order_tickets;
2847 2847
 
2848
-    public $display_order_datetimes;
2848
+	public $display_order_datetimes;
2849 2849
 
2850
-    public $display_order_event;
2850
+	public $display_order_event;
2851 2851
 
2852
-    public $display_order_venue;
2852
+	public $display_order_venue;
2853 2853
 
2854 2854
 
2855 2855
 
2856
-    /**
2857
-     *    class constructor
2858
-     */
2859
-    public function __construct()
2860
-    {
2861
-        $this->display_status_banner = 0;
2862
-        $this->display_description = 1;
2863
-        $this->display_ticket_selector = 0;
2864
-        $this->display_datetimes = 1;
2865
-        $this->display_venue = 0;
2866
-        $this->display_expired_events = 0;
2867
-        $this->use_sortable_display_order = false;
2868
-        $this->display_order_tickets = 100;
2869
-        $this->display_order_datetimes = 110;
2870
-        $this->display_order_event = 120;
2871
-        $this->display_order_venue = 130;
2872
-    }
2856
+	/**
2857
+	 *    class constructor
2858
+	 */
2859
+	public function __construct()
2860
+	{
2861
+		$this->display_status_banner = 0;
2862
+		$this->display_description = 1;
2863
+		$this->display_ticket_selector = 0;
2864
+		$this->display_datetimes = 1;
2865
+		$this->display_venue = 0;
2866
+		$this->display_expired_events = 0;
2867
+		$this->use_sortable_display_order = false;
2868
+		$this->display_order_tickets = 100;
2869
+		$this->display_order_datetimes = 110;
2870
+		$this->display_order_event = 120;
2871
+		$this->display_order_venue = 130;
2872
+	}
2873 2873
 }
2874 2874
 
2875 2875
 
@@ -2880,35 +2880,35 @@  discard block
 block discarded – undo
2880 2880
 class EE_Event_Single_Config extends EE_Config_Base
2881 2881
 {
2882 2882
 
2883
-    public $display_status_banner_single;
2883
+	public $display_status_banner_single;
2884 2884
 
2885
-    public $display_venue;
2885
+	public $display_venue;
2886 2886
 
2887
-    public $use_sortable_display_order;
2887
+	public $use_sortable_display_order;
2888 2888
 
2889
-    public $display_order_tickets;
2889
+	public $display_order_tickets;
2890 2890
 
2891
-    public $display_order_datetimes;
2891
+	public $display_order_datetimes;
2892 2892
 
2893
-    public $display_order_event;
2893
+	public $display_order_event;
2894 2894
 
2895
-    public $display_order_venue;
2895
+	public $display_order_venue;
2896 2896
 
2897 2897
 
2898 2898
 
2899
-    /**
2900
-     *    class constructor
2901
-     */
2902
-    public function __construct()
2903
-    {
2904
-        $this->display_status_banner_single = 0;
2905
-        $this->display_venue = 1;
2906
-        $this->use_sortable_display_order = false;
2907
-        $this->display_order_tickets = 100;
2908
-        $this->display_order_datetimes = 110;
2909
-        $this->display_order_event = 120;
2910
-        $this->display_order_venue = 130;
2911
-    }
2899
+	/**
2900
+	 *    class constructor
2901
+	 */
2902
+	public function __construct()
2903
+	{
2904
+		$this->display_status_banner_single = 0;
2905
+		$this->display_venue = 1;
2906
+		$this->use_sortable_display_order = false;
2907
+		$this->display_order_tickets = 100;
2908
+		$this->display_order_datetimes = 110;
2909
+		$this->display_order_event = 120;
2910
+		$this->display_order_venue = 130;
2911
+	}
2912 2912
 }
2913 2913
 
2914 2914
 
@@ -2919,152 +2919,152 @@  discard block
 block discarded – undo
2919 2919
 class EE_Ticket_Selector_Config extends EE_Config_Base
2920 2920
 {
2921 2921
 
2922
-    /**
2923
-     * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2924
-     */
2925
-    const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2926
-
2927
-    /**
2928
-     * constant to indicate that a datetime selector should only be shown for ticket selectors
2929
-     * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2930
-     */
2931
-    const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2932
-
2933
-    /**
2934
-     * @var boolean $show_ticket_sale_columns
2935
-     */
2936
-    public $show_ticket_sale_columns;
2937
-
2938
-    /**
2939
-     * @var boolean $show_ticket_details
2940
-     */
2941
-    public $show_ticket_details;
2942
-
2943
-    /**
2944
-     * @var boolean $show_expired_tickets
2945
-     */
2946
-    public $show_expired_tickets;
2947
-
2948
-    /**
2949
-     * whether or not to display a dropdown box populated with event datetimes
2950
-     * that toggles which tickets are displayed for a ticket selector.
2951
-     * uses one of the *_DATETIME_SELECTOR constants defined above
2952
-     *
2953
-     * @var string $show_datetime_selector
2954
-     */
2955
-    private $show_datetime_selector = 'no_datetime_selector';
2956
-
2957
-    /**
2958
-     * the number of datetimes an event has to have before conditionally displaying a datetime selector
2959
-     *
2960
-     * @var int $datetime_selector_threshold
2961
-     */
2962
-    private $datetime_selector_threshold = 3;
2963
-
2964
-
2965
-
2966
-    /**
2967
-     *    class constructor
2968
-     */
2969
-    public function __construct()
2970
-    {
2971
-        $this->show_ticket_sale_columns = true;
2972
-        $this->show_ticket_details = true;
2973
-        $this->show_expired_tickets = true;
2974
-        $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
2975
-        $this->datetime_selector_threshold = 3;
2976
-    }
2977
-
2978
-
2979
-
2980
-    /**
2981
-     * returns true if a datetime selector should be displayed
2982
-     *
2983
-     * @param array $datetimes
2984
-     * @return bool
2985
-     */
2986
-    public function showDatetimeSelector(array $datetimes)
2987
-    {
2988
-        // if the settings are NOT: don't show OR below threshold, THEN active = true
2989
-        return ! (
2990
-            $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
2991
-            || (
2992
-                $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
2993
-                && count($datetimes) < $this->getDatetimeSelectorThreshold()
2994
-            )
2995
-        );
2996
-    }
2997
-
2998
-
2999
-
3000
-    /**
3001
-     * @return string
3002
-     */
3003
-    public function getShowDatetimeSelector()
3004
-    {
3005
-        return $this->show_datetime_selector;
3006
-    }
3007
-
3008
-
3009
-
3010
-    /**
3011
-     * @param bool $keys_only
3012
-     * @return array
3013
-     */
3014
-    public function getShowDatetimeSelectorOptions($keys_only = true)
3015
-    {
3016
-        return $keys_only
3017
-            ? array(
3018
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3019
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3020
-            )
3021
-            : array(
3022
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3023
-                    'Do not show date & time filter', 'event_espresso'
3024
-                ),
3025
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3026
-                    'Maybe show date & time filter', 'event_espresso'
3027
-                ),
3028
-            );
3029
-    }
3030
-
3031
-
3032
-
3033
-    /**
3034
-     * @param string $show_datetime_selector
3035
-     */
3036
-    public function setShowDatetimeSelector($show_datetime_selector)
3037
-    {
3038
-        $this->show_datetime_selector = in_array(
3039
-            $show_datetime_selector,
3040
-            $this->getShowDatetimeSelectorOptions(),
3041
-            true
3042
-        )
3043
-            ? $show_datetime_selector
3044
-            : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3045
-    }
3046
-
3047
-
3048
-
3049
-    /**
3050
-     * @return int
3051
-     */
3052
-    public function getDatetimeSelectorThreshold()
3053
-    {
3054
-        return $this->datetime_selector_threshold;
3055
-    }
3056
-
3057
-
3058
-
3059
-
3060
-    /**
3061
-     * @param int $datetime_selector_threshold
3062
-     */
3063
-    public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3064
-    {
3065
-        $datetime_selector_threshold = absint($datetime_selector_threshold);
3066
-        $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3067
-    }
2922
+	/**
2923
+	 * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2924
+	 */
2925
+	const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2926
+
2927
+	/**
2928
+	 * constant to indicate that a datetime selector should only be shown for ticket selectors
2929
+	 * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2930
+	 */
2931
+	const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2932
+
2933
+	/**
2934
+	 * @var boolean $show_ticket_sale_columns
2935
+	 */
2936
+	public $show_ticket_sale_columns;
2937
+
2938
+	/**
2939
+	 * @var boolean $show_ticket_details
2940
+	 */
2941
+	public $show_ticket_details;
2942
+
2943
+	/**
2944
+	 * @var boolean $show_expired_tickets
2945
+	 */
2946
+	public $show_expired_tickets;
2947
+
2948
+	/**
2949
+	 * whether or not to display a dropdown box populated with event datetimes
2950
+	 * that toggles which tickets are displayed for a ticket selector.
2951
+	 * uses one of the *_DATETIME_SELECTOR constants defined above
2952
+	 *
2953
+	 * @var string $show_datetime_selector
2954
+	 */
2955
+	private $show_datetime_selector = 'no_datetime_selector';
2956
+
2957
+	/**
2958
+	 * the number of datetimes an event has to have before conditionally displaying a datetime selector
2959
+	 *
2960
+	 * @var int $datetime_selector_threshold
2961
+	 */
2962
+	private $datetime_selector_threshold = 3;
2963
+
2964
+
2965
+
2966
+	/**
2967
+	 *    class constructor
2968
+	 */
2969
+	public function __construct()
2970
+	{
2971
+		$this->show_ticket_sale_columns = true;
2972
+		$this->show_ticket_details = true;
2973
+		$this->show_expired_tickets = true;
2974
+		$this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
2975
+		$this->datetime_selector_threshold = 3;
2976
+	}
2977
+
2978
+
2979
+
2980
+	/**
2981
+	 * returns true if a datetime selector should be displayed
2982
+	 *
2983
+	 * @param array $datetimes
2984
+	 * @return bool
2985
+	 */
2986
+	public function showDatetimeSelector(array $datetimes)
2987
+	{
2988
+		// if the settings are NOT: don't show OR below threshold, THEN active = true
2989
+		return ! (
2990
+			$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
2991
+			|| (
2992
+				$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
2993
+				&& count($datetimes) < $this->getDatetimeSelectorThreshold()
2994
+			)
2995
+		);
2996
+	}
2997
+
2998
+
2999
+
3000
+	/**
3001
+	 * @return string
3002
+	 */
3003
+	public function getShowDatetimeSelector()
3004
+	{
3005
+		return $this->show_datetime_selector;
3006
+	}
3007
+
3008
+
3009
+
3010
+	/**
3011
+	 * @param bool $keys_only
3012
+	 * @return array
3013
+	 */
3014
+	public function getShowDatetimeSelectorOptions($keys_only = true)
3015
+	{
3016
+		return $keys_only
3017
+			? array(
3018
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3019
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3020
+			)
3021
+			: array(
3022
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3023
+					'Do not show date & time filter', 'event_espresso'
3024
+				),
3025
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3026
+					'Maybe show date & time filter', 'event_espresso'
3027
+				),
3028
+			);
3029
+	}
3030
+
3031
+
3032
+
3033
+	/**
3034
+	 * @param string $show_datetime_selector
3035
+	 */
3036
+	public function setShowDatetimeSelector($show_datetime_selector)
3037
+	{
3038
+		$this->show_datetime_selector = in_array(
3039
+			$show_datetime_selector,
3040
+			$this->getShowDatetimeSelectorOptions(),
3041
+			true
3042
+		)
3043
+			? $show_datetime_selector
3044
+			: \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3045
+	}
3046
+
3047
+
3048
+
3049
+	/**
3050
+	 * @return int
3051
+	 */
3052
+	public function getDatetimeSelectorThreshold()
3053
+	{
3054
+		return $this->datetime_selector_threshold;
3055
+	}
3056
+
3057
+
3058
+
3059
+
3060
+	/**
3061
+	 * @param int $datetime_selector_threshold
3062
+	 */
3063
+	public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3064
+	{
3065
+		$datetime_selector_threshold = absint($datetime_selector_threshold);
3066
+		$this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3067
+	}
3068 3068
 
3069 3069
 
3070 3070
 
@@ -3082,85 +3082,85 @@  discard block
 block discarded – undo
3082 3082
 class EE_Environment_Config extends EE_Config_Base
3083 3083
 {
3084 3084
 
3085
-    /**
3086
-     * Hold any php environment variables that we want to track.
3087
-     *
3088
-     * @var stdClass;
3089
-     */
3090
-    public $php;
3091
-
3092
-
3093
-
3094
-    /**
3095
-     *    constructor
3096
-     */
3097
-    public function __construct()
3098
-    {
3099
-        $this->php = new stdClass();
3100
-        $this->_set_php_values();
3101
-    }
3102
-
3103
-
3104
-
3105
-    /**
3106
-     * This sets the php environment variables.
3107
-     *
3108
-     * @since 4.4.0
3109
-     * @return void
3110
-     */
3111
-    protected function _set_php_values()
3112
-    {
3113
-        $this->php->max_input_vars = ini_get('max_input_vars');
3114
-        $this->php->version = phpversion();
3115
-    }
3116
-
3117
-
3118
-
3119
-    /**
3120
-     * helper method for determining whether input_count is
3121
-     * reaching the potential maximum the server can handle
3122
-     * according to max_input_vars
3123
-     *
3124
-     * @param int   $input_count the count of input vars.
3125
-     * @return array {
3126
-     *                           An array that represents whether available space and if no available space the error
3127
-     *                           message.
3128
-     * @type bool   $has_space   whether more inputs can be added.
3129
-     * @type string $msg         Any message to be displayed.
3130
-     *                           }
3131
-     */
3132
-    public function max_input_vars_limit_check($input_count = 0)
3133
-    {
3134
-        if (! empty($this->php->max_input_vars)
3135
-            && ($input_count >= $this->php->max_input_vars)
3136
-            && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9)
3137
-        ) {
3138
-            return sprintf(
3139
-                __(
3140
-                    'The maximum number of inputs on this page has been exceeded.  You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.',
3141
-                    'event_espresso'
3142
-                ),
3143
-                '<br>',
3144
-                $input_count,
3145
-                $this->php->max_input_vars
3146
-            );
3147
-        } else {
3148
-            return '';
3149
-        }
3150
-    }
3151
-
3152
-
3153
-
3154
-    /**
3155
-     * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3156
-     *
3157
-     * @since 4.4.1
3158
-     * @return void
3159
-     */
3160
-    public function recheck_values()
3161
-    {
3162
-        $this->_set_php_values();
3163
-    }
3085
+	/**
3086
+	 * Hold any php environment variables that we want to track.
3087
+	 *
3088
+	 * @var stdClass;
3089
+	 */
3090
+	public $php;
3091
+
3092
+
3093
+
3094
+	/**
3095
+	 *    constructor
3096
+	 */
3097
+	public function __construct()
3098
+	{
3099
+		$this->php = new stdClass();
3100
+		$this->_set_php_values();
3101
+	}
3102
+
3103
+
3104
+
3105
+	/**
3106
+	 * This sets the php environment variables.
3107
+	 *
3108
+	 * @since 4.4.0
3109
+	 * @return void
3110
+	 */
3111
+	protected function _set_php_values()
3112
+	{
3113
+		$this->php->max_input_vars = ini_get('max_input_vars');
3114
+		$this->php->version = phpversion();
3115
+	}
3116
+
3117
+
3118
+
3119
+	/**
3120
+	 * helper method for determining whether input_count is
3121
+	 * reaching the potential maximum the server can handle
3122
+	 * according to max_input_vars
3123
+	 *
3124
+	 * @param int   $input_count the count of input vars.
3125
+	 * @return array {
3126
+	 *                           An array that represents whether available space and if no available space the error
3127
+	 *                           message.
3128
+	 * @type bool   $has_space   whether more inputs can be added.
3129
+	 * @type string $msg         Any message to be displayed.
3130
+	 *                           }
3131
+	 */
3132
+	public function max_input_vars_limit_check($input_count = 0)
3133
+	{
3134
+		if (! empty($this->php->max_input_vars)
3135
+			&& ($input_count >= $this->php->max_input_vars)
3136
+			&& (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9)
3137
+		) {
3138
+			return sprintf(
3139
+				__(
3140
+					'The maximum number of inputs on this page has been exceeded.  You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.',
3141
+					'event_espresso'
3142
+				),
3143
+				'<br>',
3144
+				$input_count,
3145
+				$this->php->max_input_vars
3146
+			);
3147
+		} else {
3148
+			return '';
3149
+		}
3150
+	}
3151
+
3152
+
3153
+
3154
+	/**
3155
+	 * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3156
+	 *
3157
+	 * @since 4.4.1
3158
+	 * @return void
3159
+	 */
3160
+	public function recheck_values()
3161
+	{
3162
+		$this->_set_php_values();
3163
+	}
3164 3164
 
3165 3165
 
3166 3166
 
@@ -3178,22 +3178,22 @@  discard block
 block discarded – undo
3178 3178
 class EE_Tax_Config extends EE_Config_Base
3179 3179
 {
3180 3180
 
3181
-    /*
3181
+	/*
3182 3182
      * flag to indicate whether or not to display ticket prices with the taxes included
3183 3183
      *
3184 3184
      * @var boolean $prices_displayed_including_taxes
3185 3185
      */
3186
-    public $prices_displayed_including_taxes;
3186
+	public $prices_displayed_including_taxes;
3187 3187
 
3188 3188
 
3189 3189
 
3190
-    /**
3191
-     *    class constructor
3192
-     */
3193
-    public function __construct()
3194
-    {
3195
-        $this->prices_displayed_including_taxes = true;
3196
-    }
3190
+	/**
3191
+	 *    class constructor
3192
+	 */
3193
+	public function __construct()
3194
+	{
3195
+		$this->prices_displayed_including_taxes = true;
3196
+	}
3197 3197
 }
3198 3198
 
3199 3199
 
@@ -3208,17 +3208,17 @@  discard block
 block discarded – undo
3208 3208
 class EE_Messages_Config extends EE_Config_Base
3209 3209
 {
3210 3210
 
3211
-    /**
3212
-     * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3213
-     * A value of 0 represents never deleting.  Default is 0.
3214
-     *
3215
-     * @var integer
3216
-     */
3217
-    public $delete_threshold;
3218
-
3219
-    public function __construct() {
3220
-        $this->delete_threshold = 0;
3221
-    }
3211
+	/**
3212
+	 * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3213
+	 * A value of 0 represents never deleting.  Default is 0.
3214
+	 *
3215
+	 * @var integer
3216
+	 */
3217
+	public $delete_threshold;
3218
+
3219
+	public function __construct() {
3220
+		$this->delete_threshold = 0;
3221
+	}
3222 3222
 }
3223 3223
 
3224 3224
 
@@ -3230,34 +3230,34 @@  discard block
 block discarded – undo
3230 3230
 class EE_Gateway_Config extends EE_Config_Base
3231 3231
 {
3232 3232
 
3233
-    /**
3234
-     * Array with keys that are payment gateways slugs, and values are arrays
3235
-     * with any config info the gateway wants to store
3236
-     *
3237
-     * @var array
3238
-     */
3239
-    public $payment_settings;
3240
-
3241
-    /**
3242
-     * Where keys are gateway slugs, and values are booleans indicating whether or not
3243
-     * the gateway is stored in the uploads directory
3244
-     *
3245
-     * @var array
3246
-     */
3247
-    public $active_gateways;
3248
-
3249
-
3250
-
3251
-    /**
3252
-     *    class constructor
3253
-     *
3254
-     * @deprecated
3255
-     */
3256
-    public function __construct()
3257
-    {
3258
-        $this->payment_settings = array();
3259
-        $this->active_gateways = array('Invoice' => false);
3260
-    }
3233
+	/**
3234
+	 * Array with keys that are payment gateways slugs, and values are arrays
3235
+	 * with any config info the gateway wants to store
3236
+	 *
3237
+	 * @var array
3238
+	 */
3239
+	public $payment_settings;
3240
+
3241
+	/**
3242
+	 * Where keys are gateway slugs, and values are booleans indicating whether or not
3243
+	 * the gateway is stored in the uploads directory
3244
+	 *
3245
+	 * @var array
3246
+	 */
3247
+	public $active_gateways;
3248
+
3249
+
3250
+
3251
+	/**
3252
+	 *    class constructor
3253
+	 *
3254
+	 * @deprecated
3255
+	 */
3256
+	public function __construct()
3257
+	{
3258
+		$this->payment_settings = array();
3259
+		$this->active_gateways = array('Invoice' => false);
3260
+	}
3261 3261
 }
3262 3262
 
3263 3263
 // End of file EE_Config.core.php
Please login to merge, or discard this patch.
core/interfaces/EEI_Base.interface.php 1 patch
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -8,99 +8,99 @@
 block discarded – undo
8 8
 interface EEI_Base
9 9
 {
10 10
 
11
-    /**
12
-     * gets the unique ID of the model object. If it hasn't been saved yet
13
-     * to the database, this should be 0 or NULL
14
-     */
15
-    public function ID();
16
-
17
-
18
-
19
-    /**
20
-     * Returns an array where keys are field names and values are their values
21
-     *
22
-     * @return array
23
-     */
24
-    public function model_field_array();
25
-
26
-
27
-
28
-    /**
29
-     * Saves the thing to the database and returns success (or an ID)
30
-     *
31
-     * @return boolean success on insert; or int on update (ID of newly inserted thing)
32
-     */
33
-    public function save();
34
-
35
-
36
-
37
-    /**
38
-     * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value.
39
-     * A $previous_value can be specified in case there are many meta rows with the same key
40
-     *
41
-     * @param string $meta_key
42
-     * @param string $meta_value
43
-     * @param string $previous_value
44
-     * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row)
45
-     * NOTE: if the values haven't changed, returns 0
46
-     */
47
-    public function update_extra_meta($meta_key, $meta_value, $previous_value = null);
48
-
49
-
50
-
51
-    /**
52
-     * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check
53
-     * no other extra meta for this model object have the same key. Returns TRUE if the
54
-     * extra meta row was entered, false if not
55
-     *
56
-     * @param string  $meta_key
57
-     * @param string  $meta_value
58
-     * @param boolean $unique
59
-     * @return boolean
60
-     */
61
-    public function add_extra_meta($meta_key, $meta_value, $unique = false);
62
-
63
-
64
-
65
-    /**
66
-     * Deletes all the extra meta rows for this record as specified by key. If $meta_value
67
-     * is specified, only deletes extra meta records with that value.
68
-     *
69
-     * @param string $meta_key
70
-     * @param string $meta_value
71
-     * @return int number of extra meta rows deleted
72
-     */
73
-    public function delete_extra_meta($meta_key, $meta_value = null);
74
-
75
-
76
-
77
-    /**
78
-     * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise
79
-     * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation.
80
-     * You can specify $default is case you haven't found the extra meta
81
-     *
82
-     * @param string  $meta_key
83
-     * @param boolean $single
84
-     * @param mixed   $default if we don't find anything, what should we return?
85
-     * @return mixed single value if $single; array if ! $single
86
-     */
87
-    public function get_extra_meta($meta_key, $single = false, $default = NULL);
88
-
89
-
90
-
91
-    /**
92
-     * Gets a pretty view of the field's value. $extra_cache_ref can specify different formats for this.
93
-     * The $extra_cache_ref will be passed to the model field's prepare_for_pretty_echoing, so consult the field's class
94
-     * to see what options are available.
95
-     *
96
-     * @param string $field_name
97
-     * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
98
-     *                                (in cases where the same property may be used for different outputs
99
-     *                                - i.e. datetime, money etc.)
100
-     * @return mixed
101
-     * @throws \EE_Error
102
-     */
103
-    public function get_pretty($field_name, $extra_cache_ref);
11
+	/**
12
+	 * gets the unique ID of the model object. If it hasn't been saved yet
13
+	 * to the database, this should be 0 or NULL
14
+	 */
15
+	public function ID();
16
+
17
+
18
+
19
+	/**
20
+	 * Returns an array where keys are field names and values are their values
21
+	 *
22
+	 * @return array
23
+	 */
24
+	public function model_field_array();
25
+
26
+
27
+
28
+	/**
29
+	 * Saves the thing to the database and returns success (or an ID)
30
+	 *
31
+	 * @return boolean success on insert; or int on update (ID of newly inserted thing)
32
+	 */
33
+	public function save();
34
+
35
+
36
+
37
+	/**
38
+	 * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value.
39
+	 * A $previous_value can be specified in case there are many meta rows with the same key
40
+	 *
41
+	 * @param string $meta_key
42
+	 * @param string $meta_value
43
+	 * @param string $previous_value
44
+	 * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row)
45
+	 * NOTE: if the values haven't changed, returns 0
46
+	 */
47
+	public function update_extra_meta($meta_key, $meta_value, $previous_value = null);
48
+
49
+
50
+
51
+	/**
52
+	 * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check
53
+	 * no other extra meta for this model object have the same key. Returns TRUE if the
54
+	 * extra meta row was entered, false if not
55
+	 *
56
+	 * @param string  $meta_key
57
+	 * @param string  $meta_value
58
+	 * @param boolean $unique
59
+	 * @return boolean
60
+	 */
61
+	public function add_extra_meta($meta_key, $meta_value, $unique = false);
62
+
63
+
64
+
65
+	/**
66
+	 * Deletes all the extra meta rows for this record as specified by key. If $meta_value
67
+	 * is specified, only deletes extra meta records with that value.
68
+	 *
69
+	 * @param string $meta_key
70
+	 * @param string $meta_value
71
+	 * @return int number of extra meta rows deleted
72
+	 */
73
+	public function delete_extra_meta($meta_key, $meta_value = null);
74
+
75
+
76
+
77
+	/**
78
+	 * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise
79
+	 * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation.
80
+	 * You can specify $default is case you haven't found the extra meta
81
+	 *
82
+	 * @param string  $meta_key
83
+	 * @param boolean $single
84
+	 * @param mixed   $default if we don't find anything, what should we return?
85
+	 * @return mixed single value if $single; array if ! $single
86
+	 */
87
+	public function get_extra_meta($meta_key, $single = false, $default = NULL);
88
+
89
+
90
+
91
+	/**
92
+	 * Gets a pretty view of the field's value. $extra_cache_ref can specify different formats for this.
93
+	 * The $extra_cache_ref will be passed to the model field's prepare_for_pretty_echoing, so consult the field's class
94
+	 * to see what options are available.
95
+	 *
96
+	 * @param string $field_name
97
+	 * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
98
+	 *                                (in cases where the same property may be used for different outputs
99
+	 *                                - i.e. datetime, money etc.)
100
+	 * @return mixed
101
+	 * @throws \EE_Error
102
+	 */
103
+	public function get_pretty($field_name, $extra_cache_ref);
104 104
 
105 105
 
106 106
 
Please login to merge, or discard this patch.
core/db_classes/EE_Base_Class.class.php 3 patches
Doc Comments   +10 added lines, -9 removed lines patch added patch discarded remove patch
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
      *
610 610
      * @param \EE_Datetime_Field $datetime_field
611 611
      * @param bool               $pretty
612
-     * @param null $date_or_time
612
+     * @param string|null $date_or_time
613 613
      * @return void
614 614
      * @throws \EE_Error
615 615
      */
@@ -946,7 +946,7 @@  discard block
 block discarded – undo
946 946
      *
947 947
      * @param null  $field_to_order_by  What field is being used as the reference point.
948 948
      * @param array $query_params       Any additional conditions on the query.
949
-     * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
949
+     * @param string  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
950 950
      *                                  you can indicate just the columns you want returned
951 951
      * @return array|EE_Base_Class
952 952
      * @throws \EE_Error
@@ -971,7 +971,7 @@  discard block
 block discarded – undo
971 971
      *
972 972
      * @param null  $field_to_order_by  What field is being used as the reference point.
973 973
      * @param array $query_params       Any additional conditions on the query.
974
-     * @param null  $columns_to_select  If left null, then an EE_Base_Class object is returned, otherwise
974
+     * @param string  $columns_to_select  If left null, then an EE_Base_Class object is returned, otherwise
975 975
      *                                  you can indicate just the column you want returned
976 976
      * @return array|EE_Base_Class
977 977
      * @throws \EE_Error
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
      * This method simply returns the RAW unprocessed value for the given property in this class
1045 1045
      *
1046 1046
      * @param  string $field_name A valid fieldname
1047
-     * @return mixed              Whatever the raw value stored on the property is.
1047
+     * @return integer|null              Whatever the raw value stored on the property is.
1048 1048
      * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist.
1049 1049
      */
1050 1050
     public function get_raw($field_name)
@@ -1321,7 +1321,7 @@  discard block
 block discarded – undo
1321 1321
      * sets the time on a datetime property
1322 1322
      *
1323 1323
      * @access protected
1324
-     * @param string|Datetime $time      a valid time string for php datetime functions (or DateTime object)
1324
+     * @param string $time      a valid time string for php datetime functions (or DateTime object)
1325 1325
      * @param string          $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field)
1326 1326
      * @throws \EE_Error
1327 1327
      */
@@ -1336,7 +1336,7 @@  discard block
 block discarded – undo
1336 1336
      * sets the date on a datetime property
1337 1337
      *
1338 1338
      * @access protected
1339
-     * @param string|DateTime $date      a valid date string for php datetime functions ( or DateTime object)
1339
+     * @param string $date      a valid date string for php datetime functions ( or DateTime object)
1340 1340
      * @param string          $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field)
1341 1341
      * @throws \EE_Error
1342 1342
      */
@@ -1399,6 +1399,7 @@  discard block
 block discarded – undo
1399 1399
      * @param mixed (array|string) $args       This is the arguments that will be passed to the callback.
1400 1400
      * @param string               $prepend    You can include something to prepend on the timestamp
1401 1401
      * @param string               $append     You can include something to append on the timestamp
1402
+     * @param string $args
1402 1403
      * @throws EE_Error
1403 1404
      * @return string timestamp
1404 1405
      */
@@ -1790,7 +1791,7 @@  discard block
 block discarded – undo
1790 1791
      *
1791 1792
      * @param  array  $props_n_values   incoming array of properties and their values
1792 1793
      * @param  string $classname        the classname of the child class
1793
-     * @param null    $timezone
1794
+     * @param string|null    $timezone
1794 1795
      * @param array   $date_formats     incoming date_formats in an array where the first value is the
1795 1796
      *                                  date_format and the second value is the time format
1796 1797
      * @return mixed (EE_Base_Class|bool)
@@ -1868,7 +1869,7 @@  discard block
 block discarded – undo
1868 1869
      * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee)
1869 1870
      *
1870 1871
      * @param string $model_classname
1871
-     * @param null   $timezone
1872
+     * @param string|null   $timezone
1872 1873
      * @return EEM_Base
1873 1874
      */
1874 1875
     protected static function _get_model_instance_with_name($model_classname, $timezone = null)
@@ -2367,7 +2368,7 @@  discard block
 block discarded – undo
2367 2368
      *
2368 2369
      * @param string $meta_key
2369 2370
      * @param mixed  $meta_value
2370
-     * @param mixed  $previous_value
2371
+     * @param boolean  $previous_value
2371 2372
      * @return bool|int # of records updated (or BOOLEAN if we actually ended up inserting the extra meta row)
2372 2373
      * @throws \EE_Error
2373 2374
      * NOTE: if the values haven't changed, returns 0
Please login to merge, or discard this patch.
Indentation   +2723 added lines, -2723 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 do_action('AHEE_log', __FILE__, ' FILE LOADED', '');
5 5
 
@@ -25,2728 +25,2728 @@  discard block
 block discarded – undo
25 25
 abstract class EE_Base_Class
26 26
 {
27 27
 
28
-    /**
29
-     * This is an array of the original properties and values provided during construction
30
-     * of this model object. (keys are model field names, values are their values).
31
-     * This list is important to remember so that when we are merging data from the db, we know
32
-     * which values to override and which to not override.
33
-     *
34
-     * @var array
35
-     */
36
-    protected $_props_n_values_provided_in_constructor;
37
-
38
-    /**
39
-     * Timezone
40
-     * This gets set by the "set_timezone()" method so that we know what timezone incoming strings|timestamps are in.
41
-     * This can also be used before a get to set what timezone you want strings coming out of the object to be in.  NOT
42
-     * all EE_Base_Class child classes use this property but any that use a EE_Datetime_Field data type will have
43
-     * access to it.
44
-     *
45
-     * @var string
46
-     */
47
-    protected $_timezone;
48
-
49
-
50
-
51
-    /**
52
-     * date format
53
-     * pattern or format for displaying dates
54
-     *
55
-     * @var string $_dt_frmt
56
-     */
57
-    protected $_dt_frmt;
58
-
59
-
60
-
61
-    /**
62
-     * time format
63
-     * pattern or format for displaying time
64
-     *
65
-     * @var string $_tm_frmt
66
-     */
67
-    protected $_tm_frmt;
68
-
69
-
70
-
71
-    /**
72
-     * This property is for holding a cached array of object properties indexed by property name as the key.
73
-     * The purpose of this is for setting a cache on properties that may have calculated values after a
74
-     * prepare_for_get.  That way the cache can be checked first and the calculated property returned instead of having
75
-     * to recalculate. Used by _set_cached_property() and _get_cached_property() methods.
76
-     *
77
-     * @var array
78
-     */
79
-    protected $_cached_properties = array();
80
-
81
-    /**
82
-     * An array containing keys of the related model, and values are either an array of related mode objects or a
83
-     * single
84
-     * related model object. see the model's _model_relations. The keys should match those specified. And if the
85
-     * relation is of type EE_Belongs_To (or one of its children), then there should only be ONE related model object,
86
-     * all others have an array)
87
-     *
88
-     * @var array
89
-     */
90
-    protected $_model_relations = array();
91
-
92
-    /**
93
-     * Array where keys are field names (see the model's _fields property) and values are their values. To see what
94
-     * their types should be, look at what that field object returns on its prepare_for_get and prepare_for_set methods)
95
-     *
96
-     * @var array
97
-     */
98
-    protected $_fields = array();
99
-
100
-    /**
101
-     * @var boolean indicating whether or not this model object is intended to ever be saved
102
-     * For example, we might create model objects intended to only be used for the duration
103
-     * of this request and to be thrown away, and if they were accidentally saved
104
-     * it would be a bug.
105
-     */
106
-    protected $_allow_persist = true;
107
-
108
-    /**
109
-     * @var boolean indicating whether or not this model object's properties have changed since construction
110
-     */
111
-    protected $_has_changes = false;
112
-
113
-    /**
114
-     * @var EEM_Base
115
-     */
116
-    protected $_model;
117
-
118
-
119
-
120
-    /**
121
-     * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children
122
-     * play nice
123
-     *
124
-     * @param array   $fieldValues                             where each key is a field (ie, array key in the 2nd
125
-     *                                                         layer of the model's _fields array, (eg, EVT_ID,
126
-     *                                                         TXN_amount, QST_name, etc) and values are their values
127
-     * @param boolean $bydb                                    a flag for setting if the class is instantiated by the
128
-     *                                                         corresponding db model or not.
129
-     * @param string  $timezone                                indicate what timezone you want any datetime fields to
130
-     *                                                         be in when instantiating a EE_Base_Class object.
131
-     * @param array   $date_formats                            An array of date formats to set on construct where first
132
-     *                                                         value is the date_format and second value is the time
133
-     *                                                         format.
134
-     * @throws EE_Error
135
-     */
136
-    protected function __construct($fieldValues = array(), $bydb = false, $timezone = '', $date_formats = array())
137
-    {
138
-        $className = get_class($this);
139
-        do_action("AHEE__{$className}__construct", $this, $fieldValues);
140
-        $model = $this->get_model();
141
-        $model_fields = $model->field_settings(false);
142
-        // ensure $fieldValues is an array
143
-        $fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues);
144
-        // EEH_Debug_Tools::printr( $fieldValues, '$fieldValues  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
145
-        // verify client code has not passed any invalid field names
146
-        foreach ($fieldValues as $field_name => $field_value) {
147
-            if ( ! isset($model_fields[$field_name])) {
148
-                throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s",
149
-                    "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields))));
150
-            }
151
-        }
152
-        // EEH_Debug_Tools::printr( $model_fields, '$model_fields  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
153
-        $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone);
154
-        if ( ! empty($date_formats) && is_array($date_formats)) {
155
-            list($this->_dt_frmt, $this->_tm_frmt) = $date_formats;
156
-        } else {
157
-            //set default formats for date and time
158
-            $this->_dt_frmt = (string)get_option('date_format', 'Y-m-d');
159
-            $this->_tm_frmt = (string)get_option('time_format', 'g:i a');
160
-        }
161
-        //if db model is instantiating
162
-        if ($bydb) {
163
-            //client code has indicated these field values are from the database
164
-            foreach ($model_fields as $fieldName => $field) {
165
-                $this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null);
166
-            }
167
-        } else {
168
-            //we're constructing a brand
169
-            //new instance of the model object. Generally, this means we'll need to do more field validation
170
-            foreach ($model_fields as $fieldName => $field) {
171
-                $this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true);
172
-            }
173
-        }
174
-        //remember what values were passed to this constructor
175
-        $this->_props_n_values_provided_in_constructor = $fieldValues;
176
-        //remember in entity mapper
177
-        if ( ! $bydb && $model->has_primary_key_field() && $this->ID()) {
178
-            $model->add_to_entity_map($this);
179
-        }
180
-        //setup all the relations
181
-        foreach ($model->relation_settings() as $relation_name => $relation_obj) {
182
-            if ($relation_obj instanceof EE_Belongs_To_Relation) {
183
-                $this->_model_relations[$relation_name] = null;
184
-            } else {
185
-                $this->_model_relations[$relation_name] = array();
186
-            }
187
-        }
188
-        /**
189
-         * Action done at the end of each model object construction
190
-         *
191
-         * @param EE_Base_Class $this the model object just created
192
-         */
193
-        do_action('AHEE__EE_Base_Class__construct__finished', $this);
194
-    }
195
-
196
-
197
-
198
-    /**
199
-     * Gets whether or not this model object is allowed to persist/be saved to the database.
200
-     *
201
-     * @return boolean
202
-     */
203
-    public function allow_persist()
204
-    {
205
-        return $this->_allow_persist;
206
-    }
207
-
208
-
209
-
210
-    /**
211
-     * Sets whether or not this model object should be allowed to be saved to the DB.
212
-     * Normally once this is set to FALSE you wouldn't set it back to TRUE, unless
213
-     * you got new information that somehow made you change your mind.
214
-     *
215
-     * @param boolean $allow_persist
216
-     * @return boolean
217
-     */
218
-    public function set_allow_persist($allow_persist)
219
-    {
220
-        return $this->_allow_persist = $allow_persist;
221
-    }
222
-
223
-
224
-
225
-    /**
226
-     * Gets the field's original value when this object was constructed during this request.
227
-     * This can be helpful when determining if a model object has changed or not
228
-     *
229
-     * @param string $field_name
230
-     * @return mixed|null
231
-     * @throws \EE_Error
232
-     */
233
-    public function get_original($field_name)
234
-    {
235
-        if (isset($this->_props_n_values_provided_in_constructor[$field_name])
236
-            && $field_settings = $this->get_model()->field_settings_for($field_name)
237
-        ) {
238
-            return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]);
239
-        } else {
240
-            return null;
241
-        }
242
-    }
243
-
244
-
245
-
246
-    /**
247
-     * @param EE_Base_Class $obj
248
-     * @return string
249
-     */
250
-    public function get_class($obj)
251
-    {
252
-        return get_class($obj);
253
-    }
254
-
255
-
256
-
257
-    /**
258
-     * Overrides parent because parent expects old models.
259
-     * This also doesn't do any validation, and won't work for serialized arrays
260
-     *
261
-     * @param    string $field_name
262
-     * @param    mixed  $field_value
263
-     * @param bool      $use_default
264
-     * @throws \EE_Error
265
-     */
266
-    public function set($field_name, $field_value, $use_default = false)
267
-    {
268
-        // if not using default and nothing has changed, and object has already been setup (has ID),
269
-        // then don't do anything
270
-        if (
271
-            ! $use_default
272
-            && $this->_fields[$field_name] === $field_value
273
-            && $this->ID()
274
-        ) {
275
-            return;
276
-        }
277
-        $model = $this->get_model();
278
-        $this->_has_changes = true;
279
-        $field_obj = $model->field_settings_for($field_name);
280
-        if ($field_obj instanceof EE_Model_Field_Base) {
281
-            //			if ( method_exists( $field_obj, 'set_timezone' )) {
282
-            if ($field_obj instanceof EE_Datetime_Field) {
283
-                $field_obj->set_timezone($this->_timezone);
284
-                $field_obj->set_date_format($this->_dt_frmt);
285
-                $field_obj->set_time_format($this->_tm_frmt);
286
-            }
287
-            $holder_of_value = $field_obj->prepare_for_set($field_value);
288
-            //should the value be null?
289
-            if (($field_value === null || $holder_of_value === null || $holder_of_value === '') && $use_default) {
290
-                $this->_fields[$field_name] = $field_obj->get_default_value();
291
-                /**
292
-                 * To save having to refactor all the models, if a default value is used for a
293
-                 * EE_Datetime_Field, and that value is not null nor is it a DateTime
294
-                 * object.  Then let's do a set again to ensure that it becomes a DateTime
295
-                 * object.
296
-                 *
297
-                 * @since 4.6.10+
298
-                 */
299
-                if (
300
-                    $field_obj instanceof EE_Datetime_Field
301
-                    && $this->_fields[$field_name] !== null
302
-                    && ! $this->_fields[$field_name] instanceof DateTime
303
-                ) {
304
-                    empty($this->_fields[$field_name])
305
-                        ? $this->set($field_name, time())
306
-                        : $this->set($field_name, $this->_fields[$field_name]);
307
-                }
308
-            } else {
309
-                $this->_fields[$field_name] = $holder_of_value;
310
-            }
311
-            //if we're not in the constructor...
312
-            //now check if what we set was a primary key
313
-            if (
314
-                //note: props_n_values_provided_in_constructor is only set at the END of the constructor
315
-                $this->_props_n_values_provided_in_constructor
316
-                && $field_value
317
-                && $field_name === $model->primary_key_name()
318
-            ) {
319
-                //if so, we want all this object's fields to be filled either with
320
-                //what we've explicitly set on this model
321
-                //or what we have in the db
322
-                // echo "setting primary key!";
323
-                $fields_on_model = self::_get_model(get_class($this))->field_settings();
324
-                $obj_in_db = self::_get_model(get_class($this))->get_one_by_ID($field_value);
325
-                foreach ($fields_on_model as $field_obj) {
326
-                    if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor)
327
-                         && $field_obj->get_name() !== $field_name
328
-                    ) {
329
-                        $this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name()));
330
-                    }
331
-                }
332
-                //oh this model object has an ID? well make sure its in the entity mapper
333
-                $model->add_to_entity_map($this);
334
-            }
335
-            //let's unset any cache for this field_name from the $_cached_properties property.
336
-            $this->_clear_cached_property($field_name);
337
-        } else {
338
-            throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s",
339
-                "event_espresso"), $field_name));
340
-        }
341
-    }
342
-
343
-
344
-
345
-    /**
346
-     * This sets the field value on the db column if it exists for the given $column_name or
347
-     * saves it to EE_Extra_Meta if the given $column_name does not match a db column.
348
-     *
349
-     * @see EE_message::get_column_value for related documentation on the necessity of this method.
350
-     * @param string $field_name  Must be the exact column name.
351
-     * @param mixed  $field_value The value to set.
352
-     * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs.
353
-     * @throws \EE_Error
354
-     */
355
-    public function set_field_or_extra_meta($field_name, $field_value)
356
-    {
357
-        if ($this->get_model()->has_field($field_name)) {
358
-            $this->set($field_name, $field_value);
359
-            return true;
360
-        } else {
361
-            //ensure this object is saved first so that extra meta can be properly related.
362
-            $this->save();
363
-            return $this->update_extra_meta($field_name, $field_value);
364
-        }
365
-    }
366
-
367
-
368
-
369
-    /**
370
-     * This retrieves the value of the db column set on this class or if that's not present
371
-     * it will attempt to retrieve from extra_meta if found.
372
-     * Example Usage:
373
-     * Via EE_Message child class:
374
-     * Due to the dynamic nature of the EE_messages system, EE_messengers will always have a "to",
375
-     * "from", "subject", and "content" field (as represented in the EE_Message schema), however they may
376
-     * also have additional main fields specific to the messenger.  The system accommodates those extra
377
-     * fields through the EE_Extra_Meta table.  This method allows for EE_messengers to retrieve the
378
-     * value for those extra fields dynamically via the EE_message object.
379
-     *
380
-     * @param  string $field_name expecting the fully qualified field name.
381
-     * @return mixed|null  value for the field if found.  null if not found.
382
-     * @throws \EE_Error
383
-     */
384
-    public function get_field_or_extra_meta($field_name)
385
-    {
386
-        if ($this->get_model()->has_field($field_name)) {
387
-            $column_value = $this->get($field_name);
388
-        } else {
389
-            //This isn't a column in the main table, let's see if it is in the extra meta.
390
-            $column_value = $this->get_extra_meta($field_name, true, null);
391
-        }
392
-        return $column_value;
393
-    }
394
-
395
-
396
-
397
-    /**
398
-     * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
399
-     * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
400
-     * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). This is
401
-     * available to all child classes that may be using the EE_Datetime_Field for a field data type.
402
-     *
403
-     * @access public
404
-     * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php
405
-     * @return void
406
-     * @throws \EE_Error
407
-     */
408
-    public function set_timezone($timezone = '')
409
-    {
410
-        $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone);
411
-        //make sure we clear all cached properties because they won't be relevant now
412
-        $this->_clear_cached_properties();
413
-        //make sure we update field settings and the date for all EE_Datetime_Fields
414
-        $model_fields = $this->get_model()->field_settings(false);
415
-        foreach ($model_fields as $field_name => $field_obj) {
416
-            if ($field_obj instanceof EE_Datetime_Field) {
417
-                $field_obj->set_timezone($this->_timezone);
418
-                if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) {
419
-                    $this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone));
420
-                }
421
-            }
422
-        }
423
-    }
424
-
425
-
426
-
427
-    /**
428
-     * This just returns whatever is set for the current timezone.
429
-     *
430
-     * @access public
431
-     * @return string timezone string
432
-     */
433
-    public function get_timezone()
434
-    {
435
-        return $this->_timezone;
436
-    }
437
-
438
-
439
-
440
-    /**
441
-     * This sets the internal date format to what is sent in to be used as the new default for the class
442
-     * internally instead of wp set date format options
443
-     *
444
-     * @since 4.6
445
-     * @param string $format should be a format recognizable by PHP date() functions.
446
-     */
447
-    public function set_date_format($format)
448
-    {
449
-        $this->_dt_frmt = $format;
450
-        //clear cached_properties because they won't be relevant now.
451
-        $this->_clear_cached_properties();
452
-    }
453
-
454
-
455
-
456
-    /**
457
-     * This sets the internal time format string to what is sent in to be used as the new default for the
458
-     * class internally instead of wp set time format options.
459
-     *
460
-     * @since 4.6
461
-     * @param string $format should be a format recognizable by PHP date() functions.
462
-     */
463
-    public function set_time_format($format)
464
-    {
465
-        $this->_tm_frmt = $format;
466
-        //clear cached_properties because they won't be relevant now.
467
-        $this->_clear_cached_properties();
468
-    }
469
-
470
-
471
-
472
-    /**
473
-     * This returns the current internal set format for the date and time formats.
474
-     *
475
-     * @param bool $full           if true (default), then return the full format.  Otherwise will return an array
476
-     *                             where the first value is the date format and the second value is the time format.
477
-     * @return mixed string|array
478
-     */
479
-    public function get_format($full = true)
480
-    {
481
-        return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt);
482
-    }
483
-
484
-
485
-
486
-    /**
487
-     * cache
488
-     * stores the passed model object on the current model object.
489
-     * In certain circumstances, we can use this cached model object instead of querying for another one entirely.
490
-     *
491
-     * @param string        $relationName    one of the keys in the _model_relations array on the model. Eg
492
-     *                                       'Registration' associated with this model object
493
-     * @param EE_Base_Class $object_to_cache that has a relation to this model object. (Eg, if this is a Transaction,
494
-     *                                       that could be a payment or a registration)
495
-     * @param null          $cache_id        a string or number that will be used as the key for any Belongs_To_Many
496
-     *                                       items which will be stored in an array on this object
497
-     * @throws EE_Error
498
-     * @return mixed    index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one
499
-     *                  related thing, no array)
500
-     */
501
-    public function cache($relationName = '', $object_to_cache = null, $cache_id = null)
502
-    {
503
-        // its entirely possible that there IS no related object yet in which case there is nothing to cache.
504
-        if ( ! $object_to_cache instanceof EE_Base_Class) {
505
-            return false;
506
-        }
507
-        // also get "how" the object is related, or throw an error
508
-        if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) {
509
-            throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'),
510
-                $relationName, get_class($this)));
511
-        }
512
-        // how many things are related ?
513
-        if ($relationship_to_model instanceof EE_Belongs_To_Relation) {
514
-            // if it's a "belongs to" relationship, then there's only one related model object  eg, if this is a registration, there's only 1 attendee for it
515
-            // so for these model objects just set it to be cached
516
-            $this->_model_relations[$relationName] = $object_to_cache;
517
-            $return = true;
518
-        } else {
519
-            // otherwise, this is the "many" side of a one to many relationship, so we'll add the object to the array of related objects for that type.
520
-            // eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array
521
-            if ( ! is_array($this->_model_relations[$relationName])) {
522
-                // if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array
523
-                $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class
524
-                    ? array($this->_model_relations[$relationName]) : array();
525
-            }
526
-            // first check for a cache_id which is normally empty
527
-            if ( ! empty($cache_id)) {
528
-                // if the cache_id exists, then it means we are purposely trying to cache this with a known key that can then be used to retrieve the object later on
529
-                $this->_model_relations[$relationName][$cache_id] = $object_to_cache;
530
-                $return = $cache_id;
531
-            } elseif ($object_to_cache->ID()) {
532
-                // OR the cached object originally came from the db, so let's just use it's PK for an ID
533
-                $this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache;
534
-                $return = $object_to_cache->ID();
535
-            } else {
536
-                // OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID
537
-                $this->_model_relations[$relationName][] = $object_to_cache;
538
-                // move the internal pointer to the end of the array
539
-                end($this->_model_relations[$relationName]);
540
-                // and grab the key so that we can return it
541
-                $return = key($this->_model_relations[$relationName]);
542
-            }
543
-        }
544
-        return $return;
545
-    }
546
-
547
-
548
-
549
-    /**
550
-     * For adding an item to the cached_properties property.
551
-     *
552
-     * @access protected
553
-     * @param string      $fieldname the property item the corresponding value is for.
554
-     * @param mixed       $value     The value we are caching.
555
-     * @param string|null $cache_type
556
-     * @return void
557
-     * @throws \EE_Error
558
-     */
559
-    protected function _set_cached_property($fieldname, $value, $cache_type = null)
560
-    {
561
-        //first make sure this property exists
562
-        $this->get_model()->field_settings_for($fieldname);
563
-        $cache_type = empty($cache_type) ? 'standard' : $cache_type;
564
-        $this->_cached_properties[$fieldname][$cache_type] = $value;
565
-    }
566
-
567
-
568
-
569
-    /**
570
-     * This returns the value cached property if it exists OR the actual property value if the cache doesn't exist.
571
-     * This also SETS the cache if we return the actual property!
572
-     *
573
-     * @param string $fieldname        the name of the property we're trying to retrieve
574
-     * @param bool   $pretty
575
-     * @param string $extra_cache_ref  This allows the user to specify an extra cache ref for the given property
576
-     *                                 (in cases where the same property may be used for different outputs
577
-     *                                 - i.e. datetime, money etc.)
578
-     *                                 It can also accept certain pre-defined "schema" strings
579
-     *                                 to define how to output the property.
580
-     *                                 see the field's prepare_for_pretty_echoing for what strings can be used
581
-     * @return mixed                   whatever the value for the property is we're retrieving
582
-     * @throws \EE_Error
583
-     */
584
-    protected function _get_cached_property($fieldname, $pretty = false, $extra_cache_ref = null)
585
-    {
586
-        //verify the field exists
587
-        $model = $this->get_model();
588
-        $model->field_settings_for($fieldname);
589
-        $cache_type = $pretty ? 'pretty' : 'standard';
590
-        $cache_type .= ! empty($extra_cache_ref) ? '_' . $extra_cache_ref : '';
591
-        if (isset($this->_cached_properties[$fieldname][$cache_type])) {
592
-            return $this->_cached_properties[$fieldname][$cache_type];
593
-        }
594
-        $value = $this->_get_fresh_property($fieldname, $pretty, $extra_cache_ref);
595
-        $this->_set_cached_property($fieldname, $value, $cache_type);
596
-        return $value;
597
-    }
598
-
599
-
600
-
601
-    /**
602
-     * If the cache didn't fetch the needed item, this fetches it.
603
-     * @param string $fieldname
604
-     * @param bool $pretty
605
-     * @param string $extra_cache_ref
606
-     * @return mixed
607
-     */
608
-    protected function _get_fresh_property($fieldname, $pretty = false, $extra_cache_ref = null)
609
-    {
610
-        $field_obj = $this->get_model()->field_settings_for($fieldname);
611
-        // If this is an EE_Datetime_Field we need to make sure timezone, formats, and output are correct
612
-        if ($field_obj instanceof EE_Datetime_Field) {
613
-            $this->_prepare_datetime_field($field_obj, $pretty, $extra_cache_ref);
614
-        }
615
-        if ( ! isset($this->_fields[$fieldname])) {
616
-            $this->_fields[$fieldname] = null;
617
-        }
618
-        $value = $pretty
619
-            ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref)
620
-            : $field_obj->prepare_for_get($this->_fields[$fieldname]);
621
-        return $value;
622
-    }
623
-
624
-
625
-
626
-    /**
627
-     * set timezone, formats, and output for EE_Datetime_Field objects
628
-     *
629
-     * @param \EE_Datetime_Field $datetime_field
630
-     * @param bool               $pretty
631
-     * @param null $date_or_time
632
-     * @return void
633
-     * @throws \EE_Error
634
-     */
635
-    protected function _prepare_datetime_field(
636
-        EE_Datetime_Field $datetime_field,
637
-        $pretty = false,
638
-        $date_or_time = null
639
-    ) {
640
-        $datetime_field->set_timezone($this->_timezone);
641
-        $datetime_field->set_date_format($this->_dt_frmt, $pretty);
642
-        $datetime_field->set_time_format($this->_tm_frmt, $pretty);
643
-        //set the output returned
644
-        switch ($date_or_time) {
645
-            case 'D' :
646
-                $datetime_field->set_date_time_output('date');
647
-                break;
648
-            case 'T' :
649
-                $datetime_field->set_date_time_output('time');
650
-                break;
651
-            default :
652
-                $datetime_field->set_date_time_output();
653
-        }
654
-    }
655
-
656
-
657
-
658
-    /**
659
-     * This just takes care of clearing out the cached_properties
660
-     *
661
-     * @return void
662
-     */
663
-    protected function _clear_cached_properties()
664
-    {
665
-        $this->_cached_properties = array();
666
-    }
667
-
668
-
669
-
670
-    /**
671
-     * This just clears out ONE property if it exists in the cache
672
-     *
673
-     * @param  string $property_name the property to remove if it exists (from the _cached_properties array)
674
-     * @return void
675
-     */
676
-    protected function _clear_cached_property($property_name)
677
-    {
678
-        if (isset($this->_cached_properties[$property_name])) {
679
-            unset($this->_cached_properties[$property_name]);
680
-        }
681
-    }
682
-
683
-
684
-
685
-    /**
686
-     * Ensures that this related thing is a model object.
687
-     *
688
-     * @param mixed  $object_or_id EE_base_Class/int/string either a related model object, or its ID
689
-     * @param string $model_name   name of the related thing, eg 'Attendee',
690
-     * @return EE_Base_Class
691
-     * @throws \EE_Error
692
-     */
693
-    protected function ensure_related_thing_is_model_obj($object_or_id, $model_name)
694
-    {
695
-        $other_model_instance = self::_get_model_instance_with_name(
696
-            self::_get_model_classname($model_name),
697
-            $this->_timezone
698
-        );
699
-        return $other_model_instance->ensure_is_obj($object_or_id);
700
-    }
701
-
702
-
703
-
704
-    /**
705
-     * Forgets the cached model of the given relation Name. So the next time we request it,
706
-     * we will fetch it again from the database. (Handy if you know it's changed somehow).
707
-     * If a specific object is supplied, and the relationship to it is either a HasMany or HABTM,
708
-     * then only remove that one object from our cached array. Otherwise, clear the entire list
709
-     *
710
-     * @param string $relationName                         one of the keys in the _model_relations array on the model.
711
-     *                                                     Eg 'Registration'
712
-     * @param mixed  $object_to_remove_or_index_into_array or an index into the array of cached things, or NULL
713
-     *                                                     if you intend to use $clear_all = TRUE, or the relation only
714
-     *                                                     has 1 object anyways (ie, it's a BelongsToRelation)
715
-     * @param bool   $clear_all                            This flags clearing the entire cache relation property if
716
-     *                                                     this is HasMany or HABTM.
717
-     * @throws EE_Error
718
-     * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a
719
-     *                       relation from all
720
-     */
721
-    public function clear_cache($relationName, $object_to_remove_or_index_into_array = null, $clear_all = false)
722
-    {
723
-        $relationship_to_model = $this->get_model()->related_settings_for($relationName);
724
-        $index_in_cache = '';
725
-        if ( ! $relationship_to_model) {
726
-            throw new EE_Error(
727
-                sprintf(
728
-                    __("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'),
729
-                    $relationName,
730
-                    get_class($this)
731
-                )
732
-            );
733
-        }
734
-        if ($clear_all) {
735
-            $obj_removed = true;
736
-            $this->_model_relations[$relationName] = null;
737
-        } elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) {
738
-            $obj_removed = $this->_model_relations[$relationName];
739
-            $this->_model_relations[$relationName] = null;
740
-        } else {
741
-            if ($object_to_remove_or_index_into_array instanceof EE_Base_Class
742
-                && $object_to_remove_or_index_into_array->ID()
743
-            ) {
744
-                $index_in_cache = $object_to_remove_or_index_into_array->ID();
745
-                if (is_array($this->_model_relations[$relationName])
746
-                    && ! isset($this->_model_relations[$relationName][$index_in_cache])
747
-                ) {
748
-                    $index_found_at = null;
749
-                    //find this object in the array even though it has a different key
750
-                    foreach ($this->_model_relations[$relationName] as $index => $obj) {
751
-                        if (
752
-                            $obj instanceof EE_Base_Class
753
-                            && (
754
-                                $obj == $object_to_remove_or_index_into_array
755
-                                || $obj->ID() === $object_to_remove_or_index_into_array->ID()
756
-                            )
757
-                        ) {
758
-                            $index_found_at = $index;
759
-                            break;
760
-                        }
761
-                    }
762
-                    if ($index_found_at) {
763
-                        $index_in_cache = $index_found_at;
764
-                    } else {
765
-                        //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache
766
-                        //if it wasn't in it to begin with. So we're done
767
-                        return $object_to_remove_or_index_into_array;
768
-                    }
769
-                }
770
-            } elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) {
771
-                //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it!
772
-                foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) {
773
-                    if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) {
774
-                        $index_in_cache = $index;
775
-                    }
776
-                }
777
-            } else {
778
-                $index_in_cache = $object_to_remove_or_index_into_array;
779
-            }
780
-            //supposedly we've found it. But it could just be that the client code
781
-            //provided a bad index/object
782
-            if (
783
-            isset(
784
-                $this->_model_relations[$relationName],
785
-                $this->_model_relations[$relationName][$index_in_cache]
786
-            )
787
-            ) {
788
-                $obj_removed = $this->_model_relations[$relationName][$index_in_cache];
789
-                unset($this->_model_relations[$relationName][$index_in_cache]);
790
-            } else {
791
-                //that thing was never cached anyways.
792
-                $obj_removed = null;
793
-            }
794
-        }
795
-        return $obj_removed;
796
-    }
797
-
798
-
799
-
800
-    /**
801
-     * update_cache_after_object_save
802
-     * Allows a cached item to have it's cache ID (within the array of cached items) reset using the new ID it has
803
-     * obtained after being saved to the db
804
-     *
805
-     * @param string         $relationName       - the type of object that is cached
806
-     * @param \EE_Base_Class $newly_saved_object - the newly saved object to be re-cached
807
-     * @param string         $current_cache_id   - the ID that was used when originally caching the object
808
-     * @return boolean TRUE on success, FALSE on fail
809
-     * @throws \EE_Error
810
-     */
811
-    public function update_cache_after_object_save(
812
-        $relationName,
813
-        EE_Base_Class $newly_saved_object,
814
-        $current_cache_id = ''
815
-    ) {
816
-        // verify that incoming object is of the correct type
817
-        $obj_class = 'EE_' . $relationName;
818
-        if ($newly_saved_object instanceof $obj_class) {
819
-            /* @type EE_Base_Class $newly_saved_object */
820
-            // now get the type of relation
821
-            $relationship_to_model = $this->get_model()->related_settings_for($relationName);
822
-            // if this is a 1:1 relationship
823
-            if ($relationship_to_model instanceof EE_Belongs_To_Relation) {
824
-                // then just replace the cached object with the newly saved object
825
-                $this->_model_relations[$relationName] = $newly_saved_object;
826
-                return true;
827
-                // or if it's some kind of sordid feral polyamorous relationship...
828
-            } elseif (is_array($this->_model_relations[$relationName])
829
-                      && isset($this->_model_relations[$relationName][$current_cache_id])
830
-            ) {
831
-                // then remove the current cached item
832
-                unset($this->_model_relations[$relationName][$current_cache_id]);
833
-                // and cache the newly saved object using it's new ID
834
-                $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object;
835
-                return true;
836
-            }
837
-        }
838
-        return false;
839
-    }
840
-
841
-
842
-
843
-    /**
844
-     * Fetches a single EE_Base_Class on that relation. (If the relation is of type
845
-     * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects)
846
-     *
847
-     * @param string $relationName
848
-     * @return EE_Base_Class
849
-     */
850
-    public function get_one_from_cache($relationName)
851
-    {
852
-        $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName]
853
-            : null;
854
-        if (is_array($cached_array_or_object)) {
855
-            return array_shift($cached_array_or_object);
856
-        } else {
857
-            return $cached_array_or_object;
858
-        }
859
-    }
860
-
861
-
862
-
863
-    /**
864
-     * Fetches a single EE_Base_Class on that relation. (If the relation is of type
865
-     * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects)
866
-     *
867
-     * @param string $relationName
868
-     * @throws \EE_Error
869
-     * @return EE_Base_Class[] NOT necessarily indexed by primary keys
870
-     */
871
-    public function get_all_from_cache($relationName)
872
-    {
873
-        $objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array();
874
-        // if the result is not an array, but exists, make it an array
875
-        $objects = is_array($objects) ? $objects : array($objects);
876
-        //bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143
877
-        //basically, if this model object was stored in the session, and these cached model objects
878
-        //already have IDs, let's make sure they're in their model's entity mapper
879
-        //otherwise we will have duplicates next time we call
880
-        // EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() );
881
-        $model = EE_Registry::instance()->load_model($relationName);
882
-        foreach ($objects as $model_object) {
883
-            if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) {
884
-                //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved
885
-                if ($model_object->ID()) {
886
-                    $model->add_to_entity_map($model_object);
887
-                }
888
-            } else {
889
-                throw new EE_Error(
890
-                    sprintf(
891
-                        __(
892
-                            'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object',
893
-                            'event_espresso'
894
-                        ),
895
-                        $relationName,
896
-                        gettype($model_object)
897
-                    )
898
-                );
899
-            }
900
-        }
901
-        return $objects;
902
-    }
903
-
904
-
905
-
906
-    /**
907
-     * Returns the next x number of EE_Base_Class objects in sequence from this object as found in the database
908
-     * matching the given query conditions.
909
-     *
910
-     * @param null  $field_to_order_by  What field is being used as the reference point.
911
-     * @param int   $limit              How many objects to return.
912
-     * @param array $query_params       Any additional conditions on the query.
913
-     * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
914
-     *                                  you can indicate just the columns you want returned
915
-     * @return array|EE_Base_Class[]
916
-     * @throws \EE_Error
917
-     */
918
-    public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null)
919
-    {
920
-        $model = $this->get_model();
921
-        $field = empty($field_to_order_by) && $model->has_primary_key_field()
922
-            ? $model->get_primary_key_field()->get_name()
923
-            : $field_to_order_by;
924
-        $current_value = ! empty($field) ? $this->get($field) : null;
925
-        if (empty($field) || empty($current_value)) {
926
-            return array();
927
-        }
928
-        return $model->next_x($current_value, $field, $limit, $query_params, $columns_to_select);
929
-    }
930
-
931
-
932
-
933
-    /**
934
-     * Returns the previous x number of EE_Base_Class objects in sequence from this object as found in the database
935
-     * matching the given query conditions.
936
-     *
937
-     * @param null  $field_to_order_by  What field is being used as the reference point.
938
-     * @param int   $limit              How many objects to return.
939
-     * @param array $query_params       Any additional conditions on the query.
940
-     * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
941
-     *                                  you can indicate just the columns you want returned
942
-     * @return array|EE_Base_Class[]
943
-     * @throws \EE_Error
944
-     */
945
-    public function previous_x(
946
-        $field_to_order_by = null,
947
-        $limit = 1,
948
-        $query_params = array(),
949
-        $columns_to_select = null
950
-    ) {
951
-        $model = $this->get_model();
952
-        $field = empty($field_to_order_by) && $model->has_primary_key_field()
953
-            ? $model->get_primary_key_field()->get_name()
954
-            : $field_to_order_by;
955
-        $current_value = ! empty($field) ? $this->get($field) : null;
956
-        if (empty($field) || empty($current_value)) {
957
-            return array();
958
-        }
959
-        return $model->previous_x($current_value, $field, $limit, $query_params, $columns_to_select);
960
-    }
961
-
962
-
963
-
964
-    /**
965
-     * Returns the next EE_Base_Class object in sequence from this object as found in the database
966
-     * matching the given query conditions.
967
-     *
968
-     * @param null  $field_to_order_by  What field is being used as the reference point.
969
-     * @param array $query_params       Any additional conditions on the query.
970
-     * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
971
-     *                                  you can indicate just the columns you want returned
972
-     * @return array|EE_Base_Class
973
-     * @throws \EE_Error
974
-     */
975
-    public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null)
976
-    {
977
-        $model = $this->get_model();
978
-        $field = empty($field_to_order_by) && $model->has_primary_key_field()
979
-            ? $model->get_primary_key_field()->get_name()
980
-            : $field_to_order_by;
981
-        $current_value = ! empty($field) ? $this->get($field) : null;
982
-        if (empty($field) || empty($current_value)) {
983
-            return array();
984
-        }
985
-        return $model->next($current_value, $field, $query_params, $columns_to_select);
986
-    }
987
-
988
-
989
-
990
-    /**
991
-     * Returns the previous EE_Base_Class object in sequence from this object as found in the database
992
-     * matching the given query conditions.
993
-     *
994
-     * @param null  $field_to_order_by  What field is being used as the reference point.
995
-     * @param array $query_params       Any additional conditions on the query.
996
-     * @param null  $columns_to_select  If left null, then an EE_Base_Class object is returned, otherwise
997
-     *                                  you can indicate just the column you want returned
998
-     * @return array|EE_Base_Class
999
-     * @throws \EE_Error
1000
-     */
1001
-    public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null)
1002
-    {
1003
-        $model = $this->get_model();
1004
-        $field = empty($field_to_order_by) && $model->has_primary_key_field()
1005
-            ? $model->get_primary_key_field()->get_name()
1006
-            : $field_to_order_by;
1007
-        $current_value = ! empty($field) ? $this->get($field) : null;
1008
-        if (empty($field) || empty($current_value)) {
1009
-            return array();
1010
-        }
1011
-        return $model->previous($current_value, $field, $query_params, $columns_to_select);
1012
-    }
1013
-
1014
-
1015
-
1016
-    /**
1017
-     * Overrides parent because parent expects old models.
1018
-     * This also doesn't do any validation, and won't work for serialized arrays
1019
-     *
1020
-     * @param string $field_name
1021
-     * @param mixed  $field_value_from_db
1022
-     * @throws \EE_Error
1023
-     */
1024
-    public function set_from_db($field_name, $field_value_from_db)
1025
-    {
1026
-        $field_obj = $this->get_model()->field_settings_for($field_name);
1027
-        if ($field_obj instanceof EE_Model_Field_Base) {
1028
-            //you would think the DB has no NULLs for non-null label fields right? wrong!
1029
-            //eg, a CPT model object could have an entry in the posts table, but no
1030
-            //entry in the meta table. Meaning that all its columns in the meta table
1031
-            //are null! yikes! so when we find one like that, use defaults for its meta columns
1032
-            if ($field_value_from_db === null) {
1033
-                if ($field_obj->is_nullable()) {
1034
-                    //if the field allows nulls, then let it be null
1035
-                    $field_value = null;
1036
-                } else {
1037
-                    $field_value = $field_obj->get_default_value();
1038
-                }
1039
-            } else {
1040
-                $field_value = $field_obj->prepare_for_set_from_db($field_value_from_db);
1041
-            }
1042
-            $this->_fields[$field_name] = $field_value;
1043
-            $this->_clear_cached_property($field_name);
1044
-        }
1045
-    }
1046
-
1047
-
1048
-
1049
-    /**
1050
-     * verifies that the specified field is of the correct type
1051
-     *
1052
-     * @param string $field_name
1053
-     * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1054
-     *                                (in cases where the same property may be used for different outputs
1055
-     *                                - i.e. datetime, money etc.)
1056
-     * @return mixed
1057
-     * @throws \EE_Error
1058
-     */
1059
-    public function get($field_name, $extra_cache_ref = null)
1060
-    {
1061
-        return $this->_get_cached_property($field_name, false, $extra_cache_ref);
1062
-    }
1063
-
1064
-
1065
-
1066
-    /**
1067
-     * This method simply returns the RAW unprocessed value for the given property in this class
1068
-     *
1069
-     * @param  string $field_name A valid fieldname
1070
-     * @return mixed              Whatever the raw value stored on the property is.
1071
-     * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist.
1072
-     */
1073
-    public function get_raw($field_name)
1074
-    {
1075
-        $field_settings = $this->get_model()->field_settings_for($field_name);
1076
-        return $field_settings instanceof EE_Datetime_Field && $this->_fields[$field_name] instanceof DateTime
1077
-            ? $this->_fields[$field_name]->format('U')
1078
-            : $this->_fields[$field_name];
1079
-    }
1080
-
1081
-
1082
-
1083
-    /**
1084
-     * This is used to return the internal DateTime object used for a field that is a
1085
-     * EE_Datetime_Field.
1086
-     *
1087
-     * @param string $field_name               The field name retrieving the DateTime object.
1088
-     * @return mixed null | false | DateTime  If the requested field is NOT a EE_Datetime_Field then
1089
-     * @throws \EE_Error
1090
-     *                                         an error is set and false returned.  If the field IS an
1091
-     *                                         EE_Datetime_Field and but the field value is null, then
1092
-     *                                         just null is returned (because that indicates that likely
1093
-     *                                         this field is nullable).
1094
-     */
1095
-    public function get_DateTime_object($field_name)
1096
-    {
1097
-        $field_settings = $this->get_model()->field_settings_for($field_name);
1098
-        if ( ! $field_settings instanceof EE_Datetime_Field) {
1099
-            EE_Error::add_error(
1100
-                sprintf(
1101
-                    __(
1102
-                        'The field %s is not an EE_Datetime_Field field.  There is no DateTime object stored on this field type.',
1103
-                        'event_espresso'
1104
-                    ),
1105
-                    $field_name
1106
-                ),
1107
-                __FILE__,
1108
-                __FUNCTION__,
1109
-                __LINE__
1110
-            );
1111
-            return false;
1112
-        }
1113
-        return $this->_fields[$field_name];
1114
-    }
1115
-
1116
-
1117
-
1118
-    /**
1119
-     * To be used in template to immediately echo out the value, and format it for output.
1120
-     * Eg, should call stripslashes and whatnot before echoing
1121
-     *
1122
-     * @param string $field_name      the name of the field as it appears in the DB
1123
-     * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1124
-     *                                (in cases where the same property may be used for different outputs
1125
-     *                                - i.e. datetime, money etc.)
1126
-     * @return void
1127
-     * @throws \EE_Error
1128
-     */
1129
-    public function e($field_name, $extra_cache_ref = null)
1130
-    {
1131
-        echo $this->get_pretty($field_name, $extra_cache_ref);
1132
-    }
1133
-
1134
-
1135
-
1136
-    /**
1137
-     * Exactly like e(), echoes out the field, but sets its schema to 'form_input', so that it
1138
-     * can be easily used as the value of form input.
1139
-     *
1140
-     * @param string $field_name
1141
-     * @return void
1142
-     * @throws \EE_Error
1143
-     */
1144
-    public function f($field_name)
1145
-    {
1146
-        $this->e($field_name, 'form_input');
1147
-    }
1148
-
1149
-    /**
1150
-     * Same as `f()` but just returns the value instead of echoing it
1151
-     * @param string $field_name
1152
-     * @return string
1153
-     */
1154
-    public function get_f($field_name)
1155
-    {
1156
-        return (string)$this->get_pretty($field_name,'form_input');
1157
-    }
1158
-
1159
-
1160
-
1161
-    /**
1162
-     * Gets a pretty view of the field's value. $extra_cache_ref can specify different formats for this.
1163
-     * The $extra_cache_ref will be passed to the model field's prepare_for_pretty_echoing, so consult the field's class
1164
-     * to see what options are available.
1165
-     * @param string $field_name
1166
-     * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1167
-     *                                (in cases where the same property may be used for different outputs
1168
-     *                                - i.e. datetime, money etc.)
1169
-     * @return mixed
1170
-     * @throws \EE_Error
1171
-     */
1172
-    public function get_pretty($field_name, $extra_cache_ref = null)
1173
-    {
1174
-        return $this->_get_cached_property($field_name, true, $extra_cache_ref);
1175
-    }
1176
-
1177
-
1178
-
1179
-    /**
1180
-     * This simply returns the datetime for the given field name
1181
-     * Note: this protected function is called by the wrapper get_date or get_time or get_datetime functions
1182
-     * (and the equivalent e_date, e_time, e_datetime).
1183
-     *
1184
-     * @access   protected
1185
-     * @param string   $field_name   Field on the instantiated EE_Base_Class child object
1186
-     * @param string   $dt_frmt      valid datetime format used for date
1187
-     *                               (if '' then we just use the default on the field,
1188
-     *                               if NULL we use the last-used format)
1189
-     * @param string   $tm_frmt      Same as above except this is for time format
1190
-     * @param string   $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time.
1191
-     * @param  boolean $echo         Whether the dtt is echoing using pretty echoing or just returned using vanilla get
1192
-     * @return string|bool|EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown
1193
-     *                               if field is not a valid dtt field, or void if echoing
1194
-     * @throws \EE_Error
1195
-     */
1196
-    protected function _get_datetime($field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false)
1197
-    {
1198
-        // clear cached property
1199
-        $this->_clear_cached_property($field_name);
1200
-        //reset format properties because they are used in get()
1201
-        $this->_dt_frmt = $dt_frmt !== '' ? $dt_frmt : $this->_dt_frmt;
1202
-        $this->_tm_frmt = $tm_frmt !== '' ? $tm_frmt : $this->_tm_frmt;
1203
-        if ($echo) {
1204
-            $this->e($field_name, $date_or_time);
1205
-            return '';
1206
-        }
1207
-        return $this->get($field_name, $date_or_time);
1208
-    }
1209
-
1210
-
1211
-
1212
-    /**
1213
-     * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the date
1214
-     * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the
1215
-     * other echoes the pretty value for dtt)
1216
-     *
1217
-     * @param  string $field_name name of model object datetime field holding the value
1218
-     * @param  string $format     format for the date returned (if NULL we use default in dt_frmt property)
1219
-     * @return string            datetime value formatted
1220
-     * @throws \EE_Error
1221
-     */
1222
-    public function get_date($field_name, $format = '')
1223
-    {
1224
-        return $this->_get_datetime($field_name, $format, null, 'D');
1225
-    }
1226
-
1227
-
1228
-
1229
-    /**
1230
-     * @param      $field_name
1231
-     * @param string $format
1232
-     * @throws \EE_Error
1233
-     */
1234
-    public function e_date($field_name, $format = '')
1235
-    {
1236
-        $this->_get_datetime($field_name, $format, null, 'D', true);
1237
-    }
1238
-
1239
-
1240
-
1241
-    /**
1242
-     * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the time
1243
-     * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the
1244
-     * other echoes the pretty value for dtt)
1245
-     *
1246
-     * @param  string $field_name name of model object datetime field holding the value
1247
-     * @param  string $format     format for the time returned ( if NULL we use default in tm_frmt property)
1248
-     * @return string             datetime value formatted
1249
-     * @throws \EE_Error
1250
-     */
1251
-    public function get_time($field_name, $format = '')
1252
-    {
1253
-        return $this->_get_datetime($field_name, null, $format, 'T');
1254
-    }
1255
-
1256
-
1257
-
1258
-    /**
1259
-     * @param      $field_name
1260
-     * @param string $format
1261
-     * @throws \EE_Error
1262
-     */
1263
-    public function e_time($field_name, $format = '')
1264
-    {
1265
-        $this->_get_datetime($field_name, null, $format, 'T', true);
1266
-    }
1267
-
1268
-
1269
-
1270
-    /**
1271
-     * below are wrapper functions for the various datetime outputs that can be obtained for returning the date AND
1272
-     * time portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the
1273
-     * other echoes the pretty value for dtt)
1274
-     *
1275
-     * @param  string $field_name name of model object datetime field holding the value
1276
-     * @param  string $dt_frmt    format for the date returned (if NULL we use default in dt_frmt property)
1277
-     * @param  string $tm_frmt    format for the time returned (if NULL we use default in tm_frmt property)
1278
-     * @return string             datetime value formatted
1279
-     * @throws \EE_Error
1280
-     */
1281
-    public function get_datetime($field_name, $dt_frmt = '', $tm_frmt = '')
1282
-    {
1283
-        return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt);
1284
-    }
1285
-
1286
-
1287
-
1288
-    /**
1289
-     * @param string $field_name
1290
-     * @param string $dt_frmt
1291
-     * @param string $tm_frmt
1292
-     * @throws \EE_Error
1293
-     */
1294
-    public function e_datetime($field_name, $dt_frmt = '', $tm_frmt = '')
1295
-    {
1296
-        $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, null, true);
1297
-    }
1298
-
1299
-
1300
-
1301
-    /**
1302
-     * Get the i8ln value for a date using the WordPress @see date_i18n function.
1303
-     *
1304
-     * @param string $field_name The EE_Datetime_Field reference for the date being retrieved.
1305
-     * @param string $format     PHP valid date/time string format.  If none is provided then the internal set format
1306
-     *                           on the object will be used.
1307
-     * @return string Date and time string in set locale or false if no field exists for the given
1308
-     * @throws \EE_Error
1309
-     *                           field name.
1310
-     */
1311
-    public function get_i18n_datetime($field_name, $format = '')
1312
-    {
1313
-        $format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format;
1314
-        return date_i18n(
1315
-            $format,
1316
-            EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone)
1317
-        );
1318
-    }
1319
-
1320
-
1321
-
1322
-    /**
1323
-     * This method validates whether the given field name is a valid field on the model object as well as it is of a
1324
-     * type EE_Datetime_Field.  On success there will be returned the field settings.  On fail an EE_Error exception is
1325
-     * thrown.
1326
-     *
1327
-     * @param  string $field_name The field name being checked
1328
-     * @throws EE_Error
1329
-     * @return EE_Datetime_Field
1330
-     */
1331
-    protected function _get_dtt_field_settings($field_name)
1332
-    {
1333
-        $field = $this->get_model()->field_settings_for($field_name);
1334
-        //check if field is dtt
1335
-        if ($field instanceof EE_Datetime_Field) {
1336
-            return $field;
1337
-        } else {
1338
-            throw new EE_Error(sprintf(__('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field.  Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor',
1339
-                'event_espresso'), $field_name, self::_get_model_classname(get_class($this))));
1340
-        }
1341
-    }
1342
-
1343
-
1344
-
1345
-
1346
-    /**
1347
-     * NOTE ABOUT BELOW:
1348
-     * These convenience date and time setters are for setting date and time independently.  In other words you might
1349
-     * want to change the time on a datetime_field but leave the date the same (or vice versa). IF on the other hand
1350
-     * you want to set both date and time at the same time, you can just use the models default set($fieldname,$value)
1351
-     * method and make sure you send the entire datetime value for setting.
1352
-     */
1353
-    /**
1354
-     * sets the time on a datetime property
1355
-     *
1356
-     * @access protected
1357
-     * @param string|Datetime $time      a valid time string for php datetime functions (or DateTime object)
1358
-     * @param string          $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field)
1359
-     * @throws \EE_Error
1360
-     */
1361
-    protected function _set_time_for($time, $fieldname)
1362
-    {
1363
-        $this->_set_date_time('T', $time, $fieldname);
1364
-    }
1365
-
1366
-
1367
-
1368
-    /**
1369
-     * sets the date on a datetime property
1370
-     *
1371
-     * @access protected
1372
-     * @param string|DateTime $date      a valid date string for php datetime functions ( or DateTime object)
1373
-     * @param string          $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field)
1374
-     * @throws \EE_Error
1375
-     */
1376
-    protected function _set_date_for($date, $fieldname)
1377
-    {
1378
-        $this->_set_date_time('D', $date, $fieldname);
1379
-    }
1380
-
1381
-
1382
-
1383
-    /**
1384
-     * This takes care of setting a date or time independently on a given model object property. This method also
1385
-     * verifies that the given fieldname matches a model object property and is for a EE_Datetime_Field field
1386
-     *
1387
-     * @access protected
1388
-     * @param string          $what           "T" for time, 'B' for both, 'D' for Date.
1389
-     * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object)
1390
-     * @param string          $fieldname      the name of the field the date OR time is being set on (must match a
1391
-     *                                        EE_Datetime_Field property)
1392
-     * @throws \EE_Error
1393
-     */
1394
-    protected function _set_date_time($what = 'T', $datetime_value, $fieldname)
1395
-    {
1396
-        $field = $this->_get_dtt_field_settings($fieldname);
1397
-        $field->set_timezone($this->_timezone);
1398
-        $field->set_date_format($this->_dt_frmt);
1399
-        $field->set_time_format($this->_tm_frmt);
1400
-        switch ($what) {
1401
-            case 'T' :
1402
-                $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time(
1403
-                    $datetime_value,
1404
-                    $this->_fields[$fieldname]
1405
-                );
1406
-                break;
1407
-            case 'D' :
1408
-                $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date(
1409
-                    $datetime_value,
1410
-                    $this->_fields[$fieldname]
1411
-                );
1412
-                break;
1413
-            case 'B' :
1414
-                $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value);
1415
-                break;
1416
-        }
1417
-        $this->_clear_cached_property($fieldname);
1418
-    }
1419
-
1420
-
1421
-
1422
-    /**
1423
-     * This will return a timestamp for the website timezone but ONLY when the current website timezone is different
1424
-     * than the timezone set for the website. NOTE, this currently only works well with methods that return values.  If
1425
-     * you use it with methods that echo values the $_timestamp property may not get reset to its original value and
1426
-     * that could lead to some unexpected results!
1427
-     *
1428
-     * @access public
1429
-     * @param string               $field_name This is the name of the field on the object that contains the date/time
1430
-     *                                         value being returned.
1431
-     * @param string               $callback   must match a valid method in this class (defaults to get_datetime)
1432
-     * @param mixed (array|string) $args       This is the arguments that will be passed to the callback.
1433
-     * @param string               $prepend    You can include something to prepend on the timestamp
1434
-     * @param string               $append     You can include something to append on the timestamp
1435
-     * @throws EE_Error
1436
-     * @return string timestamp
1437
-     */
1438
-    public function display_in_my_timezone(
1439
-        $field_name,
1440
-        $callback = 'get_datetime',
1441
-        $args = null,
1442
-        $prepend = '',
1443
-        $append = ''
1444
-    ) {
1445
-        $timezone = EEH_DTT_Helper::get_timezone();
1446
-        if ($timezone === $this->_timezone) {
1447
-            return '';
1448
-        }
1449
-        $original_timezone = $this->_timezone;
1450
-        $this->set_timezone($timezone);
1451
-        $fn = (array)$field_name;
1452
-        $args = array_merge($fn, (array)$args);
1453
-        if ( ! method_exists($this, $callback)) {
1454
-            throw new EE_Error(
1455
-                sprintf(
1456
-                    __(
1457
-                        'The method named "%s" given as the callback param in "display_in_my_timezone" does not exist.  Please check your spelling',
1458
-                        'event_espresso'
1459
-                    ),
1460
-                    $callback
1461
-                )
1462
-            );
1463
-        }
1464
-        $args = (array)$args;
1465
-        $return = $prepend . call_user_func_array(array($this, $callback), $args) . $append;
1466
-        $this->set_timezone($original_timezone);
1467
-        return $return;
1468
-    }
1469
-
1470
-
1471
-
1472
-    /**
1473
-     * Deletes this model object.
1474
-     * This calls the `EE_Base_Class::_delete` method.  Child classes wishing to change default behaviour should
1475
-     * override
1476
-     * `EE_Base_Class::_delete` NOT this class.
1477
-     *
1478
-     * @return boolean | int
1479
-     * @throws \EE_Error
1480
-     */
1481
-    public function delete()
1482
-    {
1483
-        /**
1484
-         * Called just before the `EE_Base_Class::_delete` method call.
1485
-         * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
1486
-         * should be aware that `_delete` may not always result in a permanent delete.  For example, `EE_Soft_Delete_Base_Class::_delete`
1487
-         * soft deletes (trash) the object and does not permanently delete it.
1488
-         *
1489
-         * @param EE_Base_Class $model_object about to be 'deleted'
1490
-         */
1491
-        do_action('AHEE__EE_Base_Class__delete__before', $this);
1492
-        $result = $this->_delete();
1493
-        /**
1494
-         * Called just after the `EE_Base_Class::_delete` method call.
1495
-         * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
1496
-         * should be aware that `_delete` may not always result in a permanent delete.  For example `EE_Soft_Base_Class::_delete`
1497
-         * soft deletes (trash) the object and does not permanently delete it.
1498
-         *
1499
-         * @param EE_Base_Class $model_object that was just 'deleted'
1500
-         * @param boolean       $result
1501
-         */
1502
-        do_action('AHEE__EE_Base_Class__delete__end', $this, $result);
1503
-        return $result;
1504
-    }
1505
-
1506
-
1507
-
1508
-    /**
1509
-     * Calls the specific delete method for the instantiated class.
1510
-     * This method is called by the public `EE_Base_Class::delete` method.  Any child classes desiring to override
1511
-     * default functionality for "delete" (which is to call `permanently_delete`) should override this method NOT
1512
-     * `EE_Base_Class::delete`
1513
-     *
1514
-     * @return bool|int
1515
-     * @throws \EE_Error
1516
-     */
1517
-    protected function _delete()
1518
-    {
1519
-        return $this->delete_permanently();
1520
-    }
1521
-
1522
-
1523
-
1524
-    /**
1525
-     * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an
1526
-     * error)
1527
-     *
1528
-     * @return bool | int
1529
-     * @throws \EE_Error
1530
-     */
1531
-    public function delete_permanently()
1532
-    {
1533
-        /**
1534
-         * Called just before HARD deleting a model object
1535
-         *
1536
-         * @param EE_Base_Class $model_object about to be 'deleted'
1537
-         */
1538
-        do_action('AHEE__EE_Base_Class__delete_permanently__before', $this);
1539
-        $model = $this->get_model();
1540
-        $result = $model->delete_permanently_by_ID($this->ID());
1541
-        $this->refresh_cache_of_related_objects();
1542
-        /**
1543
-         * Called just after HARD deleting a model object
1544
-         *
1545
-         * @param EE_Base_Class $model_object that was just 'deleted'
1546
-         * @param boolean       $result
1547
-         */
1548
-        do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result);
1549
-        return $result;
1550
-    }
1551
-
1552
-
1553
-
1554
-    /**
1555
-     * When this model object is deleted, it may still be cached on related model objects. This clears the cache of
1556
-     * related model objects
1557
-     *
1558
-     * @throws \EE_Error
1559
-     */
1560
-    public function refresh_cache_of_related_objects()
1561
-    {
1562
-        $model = $this->get_model();
1563
-        foreach ($model->relation_settings() as $relation_name => $relation_obj) {
1564
-            if ( ! empty($this->_model_relations[$relation_name])) {
1565
-                $related_objects = $this->_model_relations[$relation_name];
1566
-                if ($relation_obj instanceof EE_Belongs_To_Relation) {
1567
-                    //this relation only stores a single model object, not an array
1568
-                    //but let's make it consistent
1569
-                    $related_objects = array($related_objects);
1570
-                }
1571
-                foreach ($related_objects as $related_object) {
1572
-                    //only refresh their cache if they're in memory
1573
-                    if ($related_object instanceof EE_Base_Class) {
1574
-                        $related_object->clear_cache($model->get_this_model_name(), $this);
1575
-                    }
1576
-                }
1577
-            }
1578
-        }
1579
-    }
1580
-
1581
-
1582
-
1583
-    /**
1584
-     *        Saves this object to the database. An array may be supplied to set some values on this
1585
-     * object just before saving.
1586
-     *
1587
-     * @access public
1588
-     * @param array $set_cols_n_values keys are field names, values are their new values,
1589
-     *                                 if provided during the save() method (often client code will change the fields'
1590
-     *                                 values before calling save)
1591
-     * @throws \EE_Error
1592
-     * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object
1593
-     *                                 isn't allowed to persist (as determined by EE_Base_Class::allow_persist())
1594
-     */
1595
-    public function save($set_cols_n_values = array())
1596
-    {
1597
-        $model = $this->get_model();
1598
-        /**
1599
-         * Filters the fields we're about to save on the model object
1600
-         *
1601
-         * @param array         $set_cols_n_values
1602
-         * @param EE_Base_Class $model_object
1603
-         */
1604
-        $set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values,
1605
-            $this);
1606
-        //set attributes as provided in $set_cols_n_values
1607
-        foreach ($set_cols_n_values as $column => $value) {
1608
-            $this->set($column, $value);
1609
-        }
1610
-        // no changes ? then don't do anything
1611
-        if (! $this->_has_changes && $this->ID() && $model->get_primary_key_field()->is_auto_increment()) {
1612
-            return 0;
1613
-        }
1614
-        /**
1615
-         * Saving a model object.
1616
-         * Before we perform a save, this action is fired.
1617
-         *
1618
-         * @param EE_Base_Class $model_object the model object about to be saved.
1619
-         */
1620
-        do_action('AHEE__EE_Base_Class__save__begin', $this);
1621
-        if ( ! $this->allow_persist()) {
1622
-            return 0;
1623
-        }
1624
-        //now get current attribute values
1625
-        $save_cols_n_values = $this->_fields;
1626
-        //if the object already has an ID, update it. Otherwise, insert it
1627
-        //also: change the assumption about values passed to the model NOT being prepare dby the model object. They have been
1628
-        $old_assumption_concerning_value_preparation = $model
1629
-                                                            ->get_assumption_concerning_values_already_prepared_by_model_object();
1630
-        $model->assume_values_already_prepared_by_model_object(true);
1631
-        //does this model have an autoincrement PK?
1632
-        if ($model->has_primary_key_field()) {
1633
-            if ($model->get_primary_key_field()->is_auto_increment()) {
1634
-                //ok check if it's set, if so: update; if not, insert
1635
-                if ( ! empty($save_cols_n_values[$model->primary_key_name()])) {
1636
-                    $results = $model->update_by_ID($save_cols_n_values, $this->ID());
1637
-                } else {
1638
-                    unset($save_cols_n_values[$model->primary_key_name()]);
1639
-                    $results = $model->insert($save_cols_n_values);
1640
-                    if ($results) {
1641
-                        //if successful, set the primary key
1642
-                        //but don't use the normal SET method, because it will check if
1643
-                        //an item with the same ID exists in the mapper & db, then
1644
-                        //will find it in the db (because we just added it) and THAT object
1645
-                        //will get added to the mapper before we can add this one!
1646
-                        //but if we just avoid using the SET method, all that headache can be avoided
1647
-                        $pk_field_name = $model->primary_key_name();
1648
-                        $this->_fields[$pk_field_name] = $results;
1649
-                        $this->_clear_cached_property($pk_field_name);
1650
-                        $model->add_to_entity_map($this);
1651
-                        $this->_update_cached_related_model_objs_fks();
1652
-                    }
1653
-                }
1654
-            } else {//PK is NOT auto-increment
1655
-                //so check if one like it already exists in the db
1656
-                if ($model->exists_by_ID($this->ID())) {
1657
-                    if (WP_DEBUG && ! $this->in_entity_map()) {
1658
-                        throw new EE_Error(
1659
-                            sprintf(
1660
-                                __('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s',
1661
-                                    'event_espresso'),
1662
-                                get_class($this),
1663
-                                get_class($model) . '::instance()->add_to_entity_map()',
1664
-                                get_class($model) . '::instance()->get_one_by_ID()',
1665
-                                '<br />'
1666
-                            )
1667
-                        );
1668
-                    }
1669
-                    $results = $model->update_by_ID($save_cols_n_values, $this->ID());
1670
-                } else {
1671
-                    $results = $model->insert($save_cols_n_values);
1672
-                    $this->_update_cached_related_model_objs_fks();
1673
-                }
1674
-            }
1675
-        } else {//there is NO primary key
1676
-            $already_in_db = false;
1677
-            foreach ($model->unique_indexes() as $index) {
1678
-                $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields());
1679
-                if ($model->exists(array($uniqueness_where_params))) {
1680
-                    $already_in_db = true;
1681
-                }
1682
-            }
1683
-            if ($already_in_db) {
1684
-                $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values,
1685
-                    $model->get_combined_primary_key_fields());
1686
-                $results = $model->update($save_cols_n_values, $combined_pk_fields_n_values);
1687
-            } else {
1688
-                $results = $model->insert($save_cols_n_values);
1689
-            }
1690
-        }
1691
-        //restore the old assumption about values being prepared by the model object
1692
-        $model
1693
-             ->assume_values_already_prepared_by_model_object($old_assumption_concerning_value_preparation);
1694
-        /**
1695
-         * After saving the model object this action is called
1696
-         *
1697
-         * @param EE_Base_Class $model_object which was just saved
1698
-         * @param boolean|int   $results      if it were updated, TRUE or FALSE; if it were newly inserted
1699
-         *                                    the new ID (or 0 if an error occurred and it wasn't updated)
1700
-         */
1701
-        do_action('AHEE__EE_Base_Class__save__end', $this, $results);
1702
-        $this->_has_changes = false;
1703
-        return $results;
1704
-    }
1705
-
1706
-
1707
-
1708
-    /**
1709
-     * Updates the foreign key on related models objects pointing to this to have this model object's ID
1710
-     * as their foreign key.  If the cached related model objects already exist in the db, saves them (so that the DB
1711
-     * is consistent) Especially useful in case we JUST added this model object ot the database and we want to let its
1712
-     * cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't
1713
-     * saved it to the db. We also create a registration and don't save it to the DB, but we DO cache it on the
1714
-     * transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether
1715
-     * or not they exist in the DB (if they do, their DB records will be automatically updated)
1716
-     *
1717
-     * @return void
1718
-     * @throws \EE_Error
1719
-     */
1720
-    protected function _update_cached_related_model_objs_fks()
1721
-    {
1722
-        $model = $this->get_model();
1723
-        foreach ($model->relation_settings() as $relation_name => $relation_obj) {
1724
-            if ($relation_obj instanceof EE_Has_Many_Relation) {
1725
-                foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) {
1726
-                    $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to(
1727
-                        $model->get_this_model_name()
1728
-                    );
1729
-                    $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID());
1730
-                    if ($related_model_obj_in_cache->ID()) {
1731
-                        $related_model_obj_in_cache->save();
1732
-                    }
1733
-                }
1734
-            }
1735
-        }
1736
-    }
1737
-
1738
-
1739
-
1740
-    /**
1741
-     * Saves this model object and its NEW cached relations to the database.
1742
-     * (Meaning, for now, IT DOES NOT WORK if the cached items already exist in the DB.
1743
-     * In order for that to work, we would need to mark model objects as dirty/clean...
1744
-     * because otherwise, there's a potential for infinite looping of saving
1745
-     * Saves the cached related model objects, and ensures the relation between them
1746
-     * and this object and properly setup
1747
-     *
1748
-     * @return int ID of new model object on save; 0 on failure+
1749
-     * @throws \EE_Error
1750
-     */
1751
-    public function save_new_cached_related_model_objs()
1752
-    {
1753
-        //make sure this has been saved
1754
-        if ( ! $this->ID()) {
1755
-            $id = $this->save();
1756
-        } else {
1757
-            $id = $this->ID();
1758
-        }
1759
-        //now save all the NEW cached model objects  (ie they don't exist in the DB)
1760
-        foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) {
1761
-            if ($this->_model_relations[$relationName]) {
1762
-                //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation)
1763
-                //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)?
1764
-                if ($relationObj instanceof EE_Belongs_To_Relation) {
1765
-                    //add a relation to that relation type (which saves the appropriate thing in the process)
1766
-                    //but ONLY if it DOES NOT exist in the DB
1767
-                    /* @var $related_model_obj EE_Base_Class */
1768
-                    $related_model_obj = $this->_model_relations[$relationName];
1769
-                    //					if( ! $related_model_obj->ID()){
1770
-                    $this->_add_relation_to($related_model_obj, $relationName);
1771
-                    $related_model_obj->save_new_cached_related_model_objs();
1772
-                    //					}
1773
-                } else {
1774
-                    foreach ($this->_model_relations[$relationName] as $related_model_obj) {
1775
-                        //add a relation to that relation type (which saves the appropriate thing in the process)
1776
-                        //but ONLY if it DOES NOT exist in the DB
1777
-                        //						if( ! $related_model_obj->ID()){
1778
-                        $this->_add_relation_to($related_model_obj, $relationName);
1779
-                        $related_model_obj->save_new_cached_related_model_objs();
1780
-                        //						}
1781
-                    }
1782
-                }
1783
-            }
1784
-        }
1785
-        return $id;
1786
-    }
1787
-
1788
-
1789
-
1790
-    /**
1791
-     * for getting a model while instantiated.
1792
-     *
1793
-     * @return \EEM_Base | \EEM_CPT_Base
1794
-     */
1795
-    public function get_model()
1796
-    {
1797
-        if( ! $this->_model){
1798
-            $modelName = self::_get_model_classname(get_class($this));
1799
-            $this->_model = self::_get_model_instance_with_name($modelName, $this->_timezone);
1800
-        } else {
1801
-            $this->_model->set_timezone($this->_timezone);
1802
-        }
1803
-
1804
-        return $this->_model;
1805
-    }
1806
-
1807
-
1808
-
1809
-    /**
1810
-     * @param $props_n_values
1811
-     * @param $classname
1812
-     * @return mixed bool|EE_Base_Class|EEM_CPT_Base
1813
-     * @throws \EE_Error
1814
-     */
1815
-    protected static function _get_object_from_entity_mapper($props_n_values, $classname)
1816
-    {
1817
-        //TODO: will not work for Term_Relationships because they have no PK!
1818
-        $primary_id_ref = self::_get_primary_key_name($classname);
1819
-        if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) {
1820
-            $id = $props_n_values[$primary_id_ref];
1821
-            return self::_get_model($classname)->get_from_entity_map($id);
1822
-        }
1823
-        return false;
1824
-    }
1825
-
1826
-
1827
-
1828
-    /**
1829
-     * This is called by child static "new_instance" method and we'll check to see if there is an existing db entry for
1830
-     * the primary key (if present in incoming values). If there is a key in the incoming array that matches the
1831
-     * primary key for the model AND it is not null, then we check the db. If there's a an object we return it.  If not
1832
-     * we return false.
1833
-     *
1834
-     * @param  array  $props_n_values   incoming array of properties and their values
1835
-     * @param  string $classname        the classname of the child class
1836
-     * @param null    $timezone
1837
-     * @param array   $date_formats     incoming date_formats in an array where the first value is the
1838
-     *                                  date_format and the second value is the time format
1839
-     * @return mixed (EE_Base_Class|bool)
1840
-     * @throws \EE_Error
1841
-     */
1842
-    protected static function _check_for_object($props_n_values, $classname, $timezone = null, $date_formats = array())
1843
-    {
1844
-        $existing = null;
1845
-        $model = self::_get_model($classname, $timezone);
1846
-        if ($model->has_primary_key_field()) {
1847
-            $primary_id_ref = self::_get_primary_key_name($classname);
1848
-            if (array_key_exists($primary_id_ref, $props_n_values)
1849
-                && ! empty($props_n_values[$primary_id_ref])
1850
-            ) {
1851
-                $existing = $model->get_one_by_ID(
1852
-                    $props_n_values[$primary_id_ref]
1853
-                );
1854
-            }
1855
-        } elseif ($model->has_all_combined_primary_key_fields($props_n_values)) {
1856
-            //no primary key on this model, but there's still a matching item in the DB
1857
-            $existing = self::_get_model($classname, $timezone)->get_one_by_ID(
1858
-                self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values)
1859
-            );
1860
-        }
1861
-        if ($existing) {
1862
-            //set date formats if present before setting values
1863
-            if ( ! empty($date_formats) && is_array($date_formats)) {
1864
-                $existing->set_date_format($date_formats[0]);
1865
-                $existing->set_time_format($date_formats[1]);
1866
-            } else {
1867
-                //set default formats for date and time
1868
-                $existing->set_date_format(get_option('date_format'));
1869
-                $existing->set_time_format(get_option('time_format'));
1870
-            }
1871
-            foreach ($props_n_values as $property => $field_value) {
1872
-                $existing->set($property, $field_value);
1873
-            }
1874
-            return $existing;
1875
-        } else {
1876
-            return false;
1877
-        }
1878
-    }
1879
-
1880
-
1881
-
1882
-    /**
1883
-     * Gets the EEM_*_Model for this class
1884
-     *
1885
-     * @access public now, as this is more convenient
1886
-     * @param      $classname
1887
-     * @param null $timezone
1888
-     * @throws EE_Error
1889
-     * @return EEM_Base
1890
-     */
1891
-    protected static function _get_model($classname, $timezone = null)
1892
-    {
1893
-        //find model for this class
1894
-        if ( ! $classname) {
1895
-            throw new EE_Error(
1896
-                sprintf(
1897
-                    __(
1898
-                        "What were you thinking calling _get_model(%s)?? You need to specify the class name",
1899
-                        "event_espresso"
1900
-                    ),
1901
-                    $classname
1902
-                )
1903
-            );
1904
-        }
1905
-        $modelName = self::_get_model_classname($classname);
1906
-        return self::_get_model_instance_with_name($modelName, $timezone);
1907
-    }
1908
-
1909
-
1910
-
1911
-    /**
1912
-     * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee)
1913
-     *
1914
-     * @param string $model_classname
1915
-     * @param null   $timezone
1916
-     * @return EEM_Base
1917
-     */
1918
-    protected static function _get_model_instance_with_name($model_classname, $timezone = null)
1919
-    {
1920
-        $model_classname = str_replace('EEM_', '', $model_classname);
1921
-        $model = EE_Registry::instance()->load_model($model_classname);
1922
-        $model->set_timezone($timezone);
1923
-        return $model;
1924
-    }
1925
-
1926
-
1927
-
1928
-    /**
1929
-     * If a model name is provided (eg Registration), gets the model classname for that model.
1930
-     * Also works if a model class's classname is provided (eg EE_Registration).
1931
-     *
1932
-     * @param null $model_name
1933
-     * @return string like EEM_Attendee
1934
-     */
1935
-    private static function _get_model_classname($model_name = null)
1936
-    {
1937
-        if (strpos($model_name, "EE_") === 0) {
1938
-            $model_classname = str_replace("EE_", "EEM_", $model_name);
1939
-        } else {
1940
-            $model_classname = "EEM_" . $model_name;
1941
-        }
1942
-        return $model_classname;
1943
-    }
1944
-
1945
-
1946
-
1947
-    /**
1948
-     * returns the name of the primary key attribute
1949
-     *
1950
-     * @param null $classname
1951
-     * @throws EE_Error
1952
-     * @return string
1953
-     */
1954
-    protected static function _get_primary_key_name($classname = null)
1955
-    {
1956
-        if ( ! $classname) {
1957
-            throw new EE_Error(
1958
-                sprintf(
1959
-                    __("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"),
1960
-                    $classname
1961
-                )
1962
-            );
1963
-        }
1964
-        return self::_get_model($classname)->get_primary_key_field()->get_name();
1965
-    }
1966
-
1967
-
1968
-
1969
-    /**
1970
-     * Gets the value of the primary key.
1971
-     * If the object hasn't yet been saved, it should be whatever the model field's default was
1972
-     * (eg, if this were the EE_Event class, look at the primary key field on EEM_Event and see what its default value
1973
-     * is. Usually defaults for integer primary keys are 0; string primary keys are usually NULL).
1974
-     *
1975
-     * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string
1976
-     * @throws \EE_Error
1977
-     */
1978
-    public function ID()
1979
-    {
1980
-        $model = $this->get_model();
1981
-        //now that we know the name of the variable, use a variable variable to get its value and return its
1982
-        if ($model->has_primary_key_field()) {
1983
-            return $this->_fields[$model->primary_key_name()];
1984
-        } else {
1985
-            return $model->get_index_primary_key_string($this->_fields);
1986
-        }
1987
-    }
1988
-
1989
-
1990
-
1991
-    /**
1992
-     * Adds a relationship to the specified EE_Base_Class object, given the relationship's name. Eg, if the current
1993
-     * model is related to a group of events, the $relationName should be 'Event', and should be a key in the EE
1994
-     * Model's $_model_relations array. If this model object doesn't exist in the DB, just caches the related thing
1995
-     *
1996
-     * @param mixed  $otherObjectModelObjectOrID       EE_Base_Class or the ID of the other object
1997
-     * @param string $relationName                     eg 'Events','Question',etc.
1998
-     *                                                 an attendee to a group, you also want to specify which role they
1999
-     *                                                 will have in that group. So you would use this parameter to
2000
-     *                                                 specify array('role-column-name'=>'role-id')
2001
-     * @param array  $extra_join_model_fields_n_values You can optionally include an array of key=>value pairs that
2002
-     *                                                 allow you to further constrict the relation to being added.
2003
-     *                                                 However, keep in mind that the columns (keys) given must match a
2004
-     *                                                 column on the JOIN table and currently only the HABTM models
2005
-     *                                                 accept these additional conditions.  Also remember that if an
2006
-     *                                                 exact match isn't found for these extra cols/val pairs, then a
2007
-     *                                                 NEW row is created in the join table.
2008
-     * @param null   $cache_id
2009
-     * @throws EE_Error
2010
-     * @return EE_Base_Class the object the relation was added to
2011
-     */
2012
-    public function _add_relation_to(
2013
-        $otherObjectModelObjectOrID,
2014
-        $relationName,
2015
-        $extra_join_model_fields_n_values = array(),
2016
-        $cache_id = null
2017
-    ) {
2018
-        $model = $this->get_model();
2019
-        //if this thing exists in the DB, save the relation to the DB
2020
-        if ($this->ID()) {
2021
-            $otherObject = $model
2022
-                                ->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName,
2023
-                                    $extra_join_model_fields_n_values);
2024
-            //clear cache so future get_many_related and get_first_related() return new results.
2025
-            $this->clear_cache($relationName, $otherObject, true);
2026
-            if ($otherObject instanceof EE_Base_Class) {
2027
-                $otherObject->clear_cache($model->get_this_model_name(), $this);
2028
-            }
2029
-        } else {
2030
-            //this thing doesn't exist in the DB,  so just cache it
2031
-            if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) {
2032
-                throw new EE_Error(sprintf(
2033
-                    __('Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s',
2034
-                        'event_espresso'),
2035
-                    $otherObjectModelObjectOrID,
2036
-                    get_class($this)
2037
-                ));
2038
-            } else {
2039
-                $otherObject = $otherObjectModelObjectOrID;
2040
-            }
2041
-            $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id);
2042
-        }
2043
-        if ($otherObject instanceof EE_Base_Class) {
2044
-            //fix the reciprocal relation too
2045
-            if ($otherObject->ID()) {
2046
-                //its saved so assumed relations exist in the DB, so we can just
2047
-                //clear the cache so future queries use the updated info in the DB
2048
-                $otherObject->clear_cache($model->get_this_model_name(), null, true);
2049
-            } else {
2050
-                //it's not saved, so it caches relations like this
2051
-                $otherObject->cache($model->get_this_model_name(), $this);
2052
-            }
2053
-        }
2054
-        return $otherObject;
2055
-    }
2056
-
2057
-
2058
-
2059
-    /**
2060
-     * Removes a relationship to the specified EE_Base_Class object, given the relationships' name. Eg, if the current
2061
-     * model is related to a group of events, the $relationName should be 'Events', and should be a key in the EE
2062
-     * Model's $_model_relations array. If this model object doesn't exist in the DB, just removes the related thing
2063
-     * from the cache
2064
-     *
2065
-     * @param mixed  $otherObjectModelObjectOrID
2066
-     *                EE_Base_Class or the ID of the other object, OR an array key into the cache if this isn't saved
2067
-     *                to the DB yet
2068
-     * @param string $relationName
2069
-     * @param array  $where_query
2070
-     *                You can optionally include an array of key=>value pairs that allow you to further constrict the
2071
-     *                relation to being added. However, keep in mind that the columns (keys) given must match a column
2072
-     *                on the JOIN table and currently only the HABTM models accept these additional conditions. Also
2073
-     *                remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is
2074
-     *                created in the join table.
2075
-     * @return EE_Base_Class the relation was removed from
2076
-     * @throws \EE_Error
2077
-     */
2078
-    public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array())
2079
-    {
2080
-        if ($this->ID()) {
2081
-            //if this exists in the DB, save the relation change to the DB too
2082
-            $otherObject = $this->get_model()
2083
-                                ->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName,
2084
-                                    $where_query);
2085
-            $this->clear_cache($relationName, $otherObject);
2086
-        } else {
2087
-            //this doesn't exist in the DB, just remove it from the cache
2088
-            $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID);
2089
-        }
2090
-        if ($otherObject instanceof EE_Base_Class) {
2091
-            $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
2092
-        }
2093
-        return $otherObject;
2094
-    }
2095
-
2096
-
2097
-
2098
-    /**
2099
-     * Removes ALL the related things for the $relationName.
2100
-     *
2101
-     * @param string $relationName
2102
-     * @param array  $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions)
2103
-     * @return EE_Base_Class
2104
-     * @throws \EE_Error
2105
-     */
2106
-    public function _remove_relations($relationName, $where_query_params = array())
2107
-    {
2108
-        if ($this->ID()) {
2109
-            //if this exists in the DB, save the relation change to the DB too
2110
-            $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params);
2111
-            $this->clear_cache($relationName, null, true);
2112
-        } else {
2113
-            //this doesn't exist in the DB, just remove it from the cache
2114
-            $otherObjects = $this->clear_cache($relationName, null, true);
2115
-        }
2116
-        if (is_array($otherObjects)) {
2117
-            foreach ($otherObjects as $otherObject) {
2118
-                $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
2119
-            }
2120
-        }
2121
-        return $otherObjects;
2122
-    }
2123
-
2124
-
2125
-
2126
-    /**
2127
-     * Gets all the related model objects of the specified type. Eg, if the current class if
2128
-     * EE_Event, you could call $this->get_many_related('Registration') to get an array of all the
2129
-     * EE_Registration objects which related to this event. Note: by default, we remove the "default query params"
2130
-     * because we want to get even deleted items etc.
2131
-     *
2132
-     * @param string $relationName key in the model's _model_relations array
2133
-     * @param array  $query_params like EEM_Base::get_all
2134
-     * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys
2135
-     * @throws \EE_Error
2136
-     *                             or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if
2137
-     *                             you want IDs
2138
-     */
2139
-    public function get_many_related($relationName, $query_params = array())
2140
-    {
2141
-        if ($this->ID()) {
2142
-            //this exists in the DB, so get the related things from either the cache or the DB
2143
-            //if there are query parameters, forget about caching the related model objects.
2144
-            if ($query_params) {
2145
-                $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
2146
-            } else {
2147
-                //did we already cache the result of this query?
2148
-                $cached_results = $this->get_all_from_cache($relationName);
2149
-                if ( ! $cached_results) {
2150
-                    $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
2151
-                    //if no query parameters were passed, then we got all the related model objects
2152
-                    //for that relation. We can cache them then.
2153
-                    foreach ($related_model_objects as $related_model_object) {
2154
-                        $this->cache($relationName, $related_model_object);
2155
-                    }
2156
-                } else {
2157
-                    $related_model_objects = $cached_results;
2158
-                }
2159
-            }
2160
-        } else {
2161
-            //this doesn't exist in the DB, so just get the related things from the cache
2162
-            $related_model_objects = $this->get_all_from_cache($relationName);
2163
-        }
2164
-        return $related_model_objects;
2165
-    }
2166
-
2167
-
2168
-
2169
-    /**
2170
-     * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default,
2171
-     * unless otherwise specified in the $query_params
2172
-     *
2173
-     * @param string $relation_name  model_name like 'Event', or 'Registration'
2174
-     * @param array  $query_params   like EEM_Base::get_all's
2175
-     * @param string $field_to_count name of field to count by. By default, uses primary key
2176
-     * @param bool   $distinct       if we want to only count the distinct values for the column then you can trigger
2177
-     *                               that by the setting $distinct to TRUE;
2178
-     * @return int
2179
-     */
2180
-    public function count_related($relation_name, $query_params = array(), $field_to_count = null, $distinct = false)
2181
-    {
2182
-        return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct);
2183
-    }
2184
-
2185
-
2186
-
2187
-    /**
2188
-     * Instead of getting the related model objects, simply sums up the values of the specified field.
2189
-     * Note: ignores default_where_conditions by default, unless otherwise specified in the $query_params
2190
-     *
2191
-     * @param string $relation_name model_name like 'Event', or 'Registration'
2192
-     * @param array  $query_params  like EEM_Base::get_all's
2193
-     * @param string $field_to_sum  name of field to count by.
2194
-     *                              By default, uses primary key (which doesn't make much sense, so you should probably
2195
-     *                              change it)
2196
-     * @return int
2197
-     */
2198
-    public function sum_related($relation_name, $query_params = array(), $field_to_sum = null)
2199
-    {
2200
-        return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum);
2201
-    }
2202
-
2203
-
2204
-
2205
-    /**
2206
-     * Gets the first (ie, one) related model object of the specified type.
2207
-     *
2208
-     * @param string $relationName key in the model's _model_relations array
2209
-     * @param array  $query_params like EEM_Base::get_all
2210
-     * @return EE_Base_Class (not an array, a single object)
2211
-     * @throws \EE_Error
2212
-     */
2213
-    public function get_first_related($relationName, $query_params = array())
2214
-    {
2215
-        $model = $this->get_model();
2216
-        if ($this->ID()) {//this exists in the DB, get from the cache OR the DB
2217
-            //if they've provided some query parameters, don't bother trying to cache the result
2218
-            //also make sure we're not caching the result of get_first_related
2219
-            //on a relation which should have an array of objects (because the cache might have an array of objects)
2220
-            if ($query_params
2221
-                || ! $model->related_settings_for($relationName)
2222
-                     instanceof
2223
-                     EE_Belongs_To_Relation
2224
-            ) {
2225
-                $related_model_object = $model->get_first_related($this, $relationName, $query_params);
2226
-            } else {
2227
-                //first, check if we've already cached the result of this query
2228
-                $cached_result = $this->get_one_from_cache($relationName);
2229
-                if ( ! $cached_result) {
2230
-                    $related_model_object = $model->get_first_related($this, $relationName, $query_params);
2231
-                    $this->cache($relationName, $related_model_object);
2232
-                } else {
2233
-                    $related_model_object = $cached_result;
2234
-                }
2235
-            }
2236
-        } else {
2237
-            $related_model_object = null;
2238
-            //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might
2239
-            if ($model->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) {
2240
-                $related_model_object = $model->get_first_related($this, $relationName, $query_params);
2241
-            }
2242
-            //this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object
2243
-            if ( ! $related_model_object) {
2244
-                $related_model_object = $this->get_one_from_cache($relationName);
2245
-            }
2246
-        }
2247
-        return $related_model_object;
2248
-    }
2249
-
2250
-
2251
-
2252
-    /**
2253
-     * Does a delete on all related objects of type $relationName and removes
2254
-     * the current model object's relation to them. If they can't be deleted (because
2255
-     * of blocking related model objects) does nothing. If the related model objects are
2256
-     * soft-deletable, they will be soft-deleted regardless of related blocking model objects.
2257
-     * If this model object doesn't exist yet in the DB, just removes its related things
2258
-     *
2259
-     * @param string $relationName
2260
-     * @param array  $query_params like EEM_Base::get_all's
2261
-     * @return int how many deleted
2262
-     * @throws \EE_Error
2263
-     */
2264
-    public function delete_related($relationName, $query_params = array())
2265
-    {
2266
-        if ($this->ID()) {
2267
-            $count = $this->get_model()->delete_related($this, $relationName, $query_params);
2268
-        } else {
2269
-            $count = count($this->get_all_from_cache($relationName));
2270
-            $this->clear_cache($relationName, null, true);
2271
-        }
2272
-        return $count;
2273
-    }
2274
-
2275
-
2276
-
2277
-    /**
2278
-     * Does a hard delete (ie, removes the DB row) on all related objects of type $relationName and removes
2279
-     * the current model object's relation to them. If they can't be deleted (because
2280
-     * of blocking related model objects) just does a soft delete on it instead, if possible.
2281
-     * If the related thing isn't a soft-deletable model object, this function is identical
2282
-     * to delete_related(). If this model object doesn't exist in the DB, just remove its related things
2283
-     *
2284
-     * @param string $relationName
2285
-     * @param array  $query_params like EEM_Base::get_all's
2286
-     * @return int how many deleted (including those soft deleted)
2287
-     * @throws \EE_Error
2288
-     */
2289
-    public function delete_related_permanently($relationName, $query_params = array())
2290
-    {
2291
-        if ($this->ID()) {
2292
-            $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params);
2293
-        } else {
2294
-            $count = count($this->get_all_from_cache($relationName));
2295
-        }
2296
-        $this->clear_cache($relationName, null, true);
2297
-        return $count;
2298
-    }
2299
-
2300
-
2301
-
2302
-    /**
2303
-     * is_set
2304
-     * Just a simple utility function children can use for checking if property exists
2305
-     *
2306
-     * @access  public
2307
-     * @param  string $field_name property to check
2308
-     * @return bool                              TRUE if existing,FALSE if not.
2309
-     */
2310
-    public function is_set($field_name)
2311
-    {
2312
-        return isset($this->_fields[$field_name]);
2313
-    }
2314
-
2315
-
2316
-
2317
-    /**
2318
-     * Just a simple utility function children can use for checking if property (or properties) exists and throwing an
2319
-     * EE_Error exception if they don't
2320
-     *
2321
-     * @param  mixed (string|array) $properties properties to check
2322
-     * @throws EE_Error
2323
-     * @return bool                              TRUE if existing, throw EE_Error if not.
2324
-     */
2325
-    protected function _property_exists($properties)
2326
-    {
2327
-        foreach ((array)$properties as $property_name) {
2328
-            //first make sure this property exists
2329
-            if ( ! $this->_fields[$property_name]) {
2330
-                throw new EE_Error(
2331
-                    sprintf(
2332
-                        __(
2333
-                            'Trying to retrieve a non-existent property (%s).  Double check the spelling please',
2334
-                            'event_espresso'
2335
-                        ),
2336
-                        $property_name
2337
-                    )
2338
-                );
2339
-            }
2340
-        }
2341
-        return true;
2342
-    }
2343
-
2344
-
2345
-
2346
-    /**
2347
-     * This simply returns an array of model fields for this object
2348
-     *
2349
-     * @return array
2350
-     * @throws \EE_Error
2351
-     */
2352
-    public function model_field_array()
2353
-    {
2354
-        $fields = $this->get_model()->field_settings(false);
2355
-        $properties = array();
2356
-        //remove prepended underscore
2357
-        foreach ($fields as $field_name => $settings) {
2358
-            $properties[$field_name] = $this->get($field_name);
2359
-        }
2360
-        return $properties;
2361
-    }
2362
-
2363
-
2364
-
2365
-    /**
2366
-     * Very handy general function to allow for plugins to extend any child of EE_Base_Class.
2367
-     * If a method is called on a child of EE_Base_Class that doesn't exist, this function is called
2368
-     * (http://www.garfieldtech.com/blog/php-magic-call) and passed the method's name and arguments. Instead of
2369
-     * requiring a plugin to extend the EE_Base_Class (which works fine is there's only 1 plugin, but when will that
2370
-     * happen?) they can add a hook onto 'filters_hook_espresso__{className}__{methodName}' (eg,
2371
-     * filters_hook_espresso__EE_Answer__my_great_function) and accepts 2 arguments: the object on which the function
2372
-     * was called, and an array of the original arguments passed to the function. Whatever their callback function
2373
-     * returns will be returned by this function. Example: in functions.php (or in a plugin):
2374
-     * add_filter('FHEE__EE_Answer__my_callback','my_callback',10,3); function
2375
-     * my_callback($previousReturnValue,EE_Base_Class $object,$argsArray){
2376
-     * $returnString= "you called my_callback! and passed args:".implode(",",$argsArray);
2377
-     *        return $previousReturnValue.$returnString;
2378
-     * }
2379
-     * require('EE_Answer.class.php');
2380
-     * $answer= EE_Answer::new_instance(array('REG_ID' => 2,'QST_ID' => 3,'ANS_value' => The answer is 42'));
2381
-     * echo $answer->my_callback('monkeys',100);
2382
-     * //will output "you called my_callback! and passed args:monkeys,100"
2383
-     *
2384
-     * @param string $methodName name of method which was called on a child of EE_Base_Class, but which
2385
-     * @param array  $args       array of original arguments passed to the function
2386
-     * @throws EE_Error
2387
-     * @return mixed whatever the plugin which calls add_filter decides
2388
-     */
2389
-    public function __call($methodName, $args)
2390
-    {
2391
-        $className = get_class($this);
2392
-        $tagName = "FHEE__{$className}__{$methodName}";
2393
-        if ( ! has_filter($tagName)) {
2394
-            throw new EE_Error(
2395
-                sprintf(
2396
-                    __(
2397
-                        "Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}",
2398
-                        "event_espresso"
2399
-                    ),
2400
-                    $methodName,
2401
-                    $className,
2402
-                    $tagName
2403
-                )
2404
-            );
2405
-        }
2406
-        return apply_filters($tagName, null, $this, $args);
2407
-    }
2408
-
2409
-
2410
-
2411
-    /**
2412
-     * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value.
2413
-     * A $previous_value can be specified in case there are many meta rows with the same key
2414
-     *
2415
-     * @param string $meta_key
2416
-     * @param mixed  $meta_value
2417
-     * @param mixed  $previous_value
2418
-     * @return bool|int # of records updated (or BOOLEAN if we actually ended up inserting the extra meta row)
2419
-     * @throws \EE_Error
2420
-     * NOTE: if the values haven't changed, returns 0
2421
-     */
2422
-    public function update_extra_meta($meta_key, $meta_value, $previous_value = null)
2423
-    {
2424
-        $query_params = array(
2425
-            array(
2426
-                'EXM_key'  => $meta_key,
2427
-                'OBJ_ID'   => $this->ID(),
2428
-                'EXM_type' => $this->get_model()->get_this_model_name(),
2429
-            ),
2430
-        );
2431
-        if ($previous_value !== null) {
2432
-            $query_params[0]['EXM_value'] = $meta_value;
2433
-        }
2434
-        $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params);
2435
-        if ( ! $existing_rows_like_that) {
2436
-            return $this->add_extra_meta($meta_key, $meta_value);
2437
-        }
2438
-        foreach ($existing_rows_like_that as $existing_row) {
2439
-            $existing_row->save(array('EXM_value' => $meta_value));
2440
-        }
2441
-        return count($existing_rows_like_that);
2442
-    }
2443
-
2444
-
2445
-
2446
-    /**
2447
-     * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check
2448
-     * no other extra meta for this model object have the same key. Returns TRUE if the
2449
-     * extra meta row was entered, false if not
2450
-     *
2451
-     * @param string  $meta_key
2452
-     * @param mixed   $meta_value
2453
-     * @param boolean $unique
2454
-     * @return boolean
2455
-     * @throws \EE_Error
2456
-     */
2457
-    public function add_extra_meta($meta_key, $meta_value, $unique = false)
2458
-    {
2459
-        if ($unique) {
2460
-            $existing_extra_meta = EEM_Extra_Meta::instance()->get_one(
2461
-                array(
2462
-                    array(
2463
-                        'EXM_key'  => $meta_key,
2464
-                        'OBJ_ID'   => $this->ID(),
2465
-                        'EXM_type' => $this->get_model()->get_this_model_name(),
2466
-                    ),
2467
-                )
2468
-            );
2469
-            if ($existing_extra_meta) {
2470
-                return false;
2471
-            }
2472
-        }
2473
-        $new_extra_meta = EE_Extra_Meta::new_instance(
2474
-            array(
2475
-                'EXM_key'   => $meta_key,
2476
-                'EXM_value' => $meta_value,
2477
-                'OBJ_ID'    => $this->ID(),
2478
-                'EXM_type'  => $this->get_model()->get_this_model_name(),
2479
-            )
2480
-        );
2481
-        $new_extra_meta->save();
2482
-        return true;
2483
-    }
2484
-
2485
-
2486
-
2487
-    /**
2488
-     * Deletes all the extra meta rows for this record as specified by key. If $meta_value
2489
-     * is specified, only deletes extra meta records with that value.
2490
-     *
2491
-     * @param string $meta_key
2492
-     * @param mixed  $meta_value
2493
-     * @return int number of extra meta rows deleted
2494
-     * @throws \EE_Error
2495
-     */
2496
-    public function delete_extra_meta($meta_key, $meta_value = null)
2497
-    {
2498
-        $query_params = array(
2499
-            array(
2500
-                'EXM_key'  => $meta_key,
2501
-                'OBJ_ID'   => $this->ID(),
2502
-                'EXM_type' => $this->get_model()->get_this_model_name(),
2503
-            ),
2504
-        );
2505
-        if ($meta_value !== null) {
2506
-            $query_params[0]['EXM_value'] = $meta_value;
2507
-        }
2508
-        return EEM_Extra_Meta::instance()->delete($query_params);
2509
-    }
2510
-
2511
-
2512
-
2513
-    /**
2514
-     * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise
2515
-     * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation.
2516
-     * You can specify $default is case you haven't found the extra meta
2517
-     *
2518
-     * @param string  $meta_key
2519
-     * @param boolean $single
2520
-     * @param mixed   $default if we don't find anything, what should we return?
2521
-     * @return mixed single value if $single; array if ! $single
2522
-     * @throws \EE_Error
2523
-     */
2524
-    public function get_extra_meta($meta_key, $single = false, $default = null)
2525
-    {
2526
-        if ($single) {
2527
-            $result = $this->get_first_related('Extra_Meta', array(array('EXM_key' => $meta_key)));
2528
-            if ($result instanceof EE_Extra_Meta) {
2529
-                return $result->value();
2530
-            }
2531
-        } else {
2532
-            $results = $this->get_many_related('Extra_Meta', array(array('EXM_key' => $meta_key)));
2533
-            if ($results) {
2534
-                $values = array();
2535
-                foreach ($results as $result) {
2536
-                    if ($result instanceof EE_Extra_Meta) {
2537
-                        $values[$result->ID()] = $result->value();
2538
-                    }
2539
-                }
2540
-                return $values;
2541
-            }
2542
-        }
2543
-        //if nothing discovered yet return default.
2544
-        return apply_filters(
2545
-            'FHEE__EE_Base_Class__get_extra_meta__default_value',
2546
-            $default,
2547
-            $meta_key,
2548
-            $single,
2549
-            $this
2550
-            );
2551
-    }
2552
-
2553
-
2554
-
2555
-    /**
2556
-     * Returns a simple array of all the extra meta associated with this model object.
2557
-     * If $one_of_each_key is true (Default), it will be an array of simple key-value pairs, keys being the
2558
-     * extra meta's key, and teh value being its value. However, if there are duplicate extra meta rows with
2559
-     * the same key, only one will be used. (eg array('foo'=>'bar','monkey'=>123))
2560
-     * If $one_of_each_key is false, it will return an array with the top-level keys being
2561
-     * the extra meta keys, but their values are also arrays, which have the extra-meta's ID as their sub-key, and
2562
-     * finally the extra meta's value as each sub-value. (eg
2563
-     * array('foo'=>array(1=>'bar',2=>'bill'),'monkey'=>array(3=>123)))
2564
-     *
2565
-     * @param boolean $one_of_each_key
2566
-     * @return array
2567
-     * @throws \EE_Error
2568
-     */
2569
-    public function all_extra_meta_array($one_of_each_key = true)
2570
-    {
2571
-        $return_array = array();
2572
-        if ($one_of_each_key) {
2573
-            $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by' => 'EXM_key'));
2574
-            foreach ($extra_meta_objs as $extra_meta_obj) {
2575
-                if ($extra_meta_obj instanceof EE_Extra_Meta) {
2576
-                    $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value();
2577
-                }
2578
-            }
2579
-        } else {
2580
-            $extra_meta_objs = $this->get_many_related('Extra_Meta');
2581
-            foreach ($extra_meta_objs as $extra_meta_obj) {
2582
-                if ($extra_meta_obj instanceof EE_Extra_Meta) {
2583
-                    if ( ! isset($return_array[$extra_meta_obj->key()])) {
2584
-                        $return_array[$extra_meta_obj->key()] = array();
2585
-                    }
2586
-                    $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value();
2587
-                }
2588
-            }
2589
-        }
2590
-        return $return_array;
2591
-    }
2592
-
2593
-
2594
-
2595
-    /**
2596
-     * Gets a pretty nice displayable nice for this model object. Often overridden
2597
-     *
2598
-     * @return string
2599
-     * @throws \EE_Error
2600
-     */
2601
-    public function name()
2602
-    {
2603
-        //find a field that's not a text field
2604
-        $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base');
2605
-        if ($field_we_can_use) {
2606
-            return $this->get($field_we_can_use->get_name());
2607
-        } else {
2608
-            $first_few_properties = $this->model_field_array();
2609
-            $first_few_properties = array_slice($first_few_properties, 0, 3);
2610
-            $name_parts = array();
2611
-            foreach ($first_few_properties as $name => $value) {
2612
-                $name_parts[] = "$name:$value";
2613
-            }
2614
-            return implode(",", $name_parts);
2615
-        }
2616
-    }
2617
-
2618
-
2619
-
2620
-    /**
2621
-     * in_entity_map
2622
-     * Checks if this model object has been proven to already be in the entity map
2623
-     *
2624
-     * @return boolean
2625
-     * @throws \EE_Error
2626
-     */
2627
-    public function in_entity_map()
2628
-    {
2629
-        if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) {
2630
-            //well, if we looked, did we find it in the entity map?
2631
-            return true;
2632
-        } else {
2633
-            return false;
2634
-        }
2635
-    }
2636
-
2637
-
2638
-
2639
-    /**
2640
-     * refresh_from_db
2641
-     * Makes sure the fields and values on this model object are in-sync with what's in the database.
2642
-     *
2643
-     * @throws EE_Error if this model object isn't in the entity mapper (because then you should
2644
-     * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE
2645
-     */
2646
-    public function refresh_from_db()
2647
-    {
2648
-        if ($this->ID() && $this->in_entity_map()) {
2649
-            $this->get_model()->refresh_entity_map_from_db($this->ID());
2650
-        } else {
2651
-            //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database)
2652
-            //if it has an ID but it's not in the map, and you're asking me to refresh it
2653
-            //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's
2654
-            //absolutely nothing in it for this ID
2655
-            if (WP_DEBUG) {
2656
-                throw new EE_Error(
2657
-                    sprintf(
2658
-                        __('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.',
2659
-                            'event_espresso'),
2660
-                        $this->ID(),
2661
-                        get_class($this->get_model()) . '::instance()->add_to_entity_map()',
2662
-                        get_class($this->get_model()) . '::instance()->refresh_entity_map()'
2663
-                    )
2664
-                );
2665
-            }
2666
-        }
2667
-    }
2668
-
2669
-
2670
-
2671
-    /**
2672
-     * Because some other plugins, like Advanced Cron Manager, expect all objects to have this method
2673
-     * (probably a bad assumption they have made, oh well)
2674
-     *
2675
-     * @return string
2676
-     */
2677
-    public function __toString()
2678
-    {
2679
-        try {
2680
-            return sprintf('%s (%s)', $this->name(), $this->ID());
2681
-        } catch (Exception $e) {
2682
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
2683
-            return '';
2684
-        }
2685
-    }
2686
-
2687
-
2688
-
2689
-    /**
2690
-     * Clear related model objects if they're already in the DB, because otherwise when we
2691
-     * UN-serialize this model object we'll need to be careful to add them to the entity map.
2692
-     * This means if we have made changes to those related model objects, and want to unserialize
2693
-     * the this model object on a subsequent request, changes to those related model objects will be lost.
2694
-     * Instead, those related model objects should be directly serialized and stored.
2695
-     * Eg, the following won't work:
2696
-     * $reg = EEM_Registration::instance()->get_one_by_ID( 123 );
2697
-     * $att = $reg->attendee();
2698
-     * $att->set( 'ATT_fname', 'Dirk' );
2699
-     * update_option( 'my_option', serialize( $reg ) );
2700
-     * //END REQUEST
2701
-     * //START NEXT REQUEST
2702
-     * $reg = get_option( 'my_option' );
2703
-     * $reg->attendee()->save();
2704
-     * And would need to be replace with:
2705
-     * $reg = EEM_Registration::instance()->get_one_by_ID( 123 );
2706
-     * $att = $reg->attendee();
2707
-     * $att->set( 'ATT_fname', 'Dirk' );
2708
-     * update_option( 'my_option', serialize( $reg ) );
2709
-     * //END REQUEST
2710
-     * //START NEXT REQUEST
2711
-     * $att = get_option( 'my_option' );
2712
-     * $att->save();
2713
-     *
2714
-     * @return array
2715
-     * @throws \EE_Error
2716
-     */
2717
-    public function __sleep()
2718
-    {
2719
-        $model = $this->get_model();
2720
-        foreach ($model->relation_settings() as $relation_name => $relation_obj) {
2721
-            if ($relation_obj instanceof EE_Belongs_To_Relation) {
2722
-                $classname = 'EE_' . $model->get_this_model_name();
2723
-                if (
2724
-                    $this->get_one_from_cache($relation_name) instanceof $classname
2725
-                    && $this->get_one_from_cache($relation_name)->ID()
2726
-                ) {
2727
-                    $this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID());
2728
-                }
2729
-            }
2730
-        }
2731
-        $this->_props_n_values_provided_in_constructor = array();
2732
-        $properties_to_serialize = get_object_vars($this);
2733
-        //don't serialize the model. It's big and that risks recursion
2734
-        unset($properties_to_serialize['_model']);
2735
-        return array_keys($properties_to_serialize);
2736
-    }
2737
-
2738
-
2739
-
2740
-    /**
2741
-     * restore _props_n_values_provided_in_constructor
2742
-     * PLZ NOTE: this will reset the array to whatever fields values were present prior to serialization,
2743
-     * and therefore should NOT be used to determine if state change has occurred since initial construction.
2744
-     * At best, you would only be able to detect if state change has occurred during THIS request.
2745
-     */
2746
-    public function __wakeup()
2747
-    {
2748
-        $this->_props_n_values_provided_in_constructor = $this->_fields;
2749
-    }
28
+	/**
29
+	 * This is an array of the original properties and values provided during construction
30
+	 * of this model object. (keys are model field names, values are their values).
31
+	 * This list is important to remember so that when we are merging data from the db, we know
32
+	 * which values to override and which to not override.
33
+	 *
34
+	 * @var array
35
+	 */
36
+	protected $_props_n_values_provided_in_constructor;
37
+
38
+	/**
39
+	 * Timezone
40
+	 * This gets set by the "set_timezone()" method so that we know what timezone incoming strings|timestamps are in.
41
+	 * This can also be used before a get to set what timezone you want strings coming out of the object to be in.  NOT
42
+	 * all EE_Base_Class child classes use this property but any that use a EE_Datetime_Field data type will have
43
+	 * access to it.
44
+	 *
45
+	 * @var string
46
+	 */
47
+	protected $_timezone;
48
+
49
+
50
+
51
+	/**
52
+	 * date format
53
+	 * pattern or format for displaying dates
54
+	 *
55
+	 * @var string $_dt_frmt
56
+	 */
57
+	protected $_dt_frmt;
58
+
59
+
60
+
61
+	/**
62
+	 * time format
63
+	 * pattern or format for displaying time
64
+	 *
65
+	 * @var string $_tm_frmt
66
+	 */
67
+	protected $_tm_frmt;
68
+
69
+
70
+
71
+	/**
72
+	 * This property is for holding a cached array of object properties indexed by property name as the key.
73
+	 * The purpose of this is for setting a cache on properties that may have calculated values after a
74
+	 * prepare_for_get.  That way the cache can be checked first and the calculated property returned instead of having
75
+	 * to recalculate. Used by _set_cached_property() and _get_cached_property() methods.
76
+	 *
77
+	 * @var array
78
+	 */
79
+	protected $_cached_properties = array();
80
+
81
+	/**
82
+	 * An array containing keys of the related model, and values are either an array of related mode objects or a
83
+	 * single
84
+	 * related model object. see the model's _model_relations. The keys should match those specified. And if the
85
+	 * relation is of type EE_Belongs_To (or one of its children), then there should only be ONE related model object,
86
+	 * all others have an array)
87
+	 *
88
+	 * @var array
89
+	 */
90
+	protected $_model_relations = array();
91
+
92
+	/**
93
+	 * Array where keys are field names (see the model's _fields property) and values are their values. To see what
94
+	 * their types should be, look at what that field object returns on its prepare_for_get and prepare_for_set methods)
95
+	 *
96
+	 * @var array
97
+	 */
98
+	protected $_fields = array();
99
+
100
+	/**
101
+	 * @var boolean indicating whether or not this model object is intended to ever be saved
102
+	 * For example, we might create model objects intended to only be used for the duration
103
+	 * of this request and to be thrown away, and if they were accidentally saved
104
+	 * it would be a bug.
105
+	 */
106
+	protected $_allow_persist = true;
107
+
108
+	/**
109
+	 * @var boolean indicating whether or not this model object's properties have changed since construction
110
+	 */
111
+	protected $_has_changes = false;
112
+
113
+	/**
114
+	 * @var EEM_Base
115
+	 */
116
+	protected $_model;
117
+
118
+
119
+
120
+	/**
121
+	 * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children
122
+	 * play nice
123
+	 *
124
+	 * @param array   $fieldValues                             where each key is a field (ie, array key in the 2nd
125
+	 *                                                         layer of the model's _fields array, (eg, EVT_ID,
126
+	 *                                                         TXN_amount, QST_name, etc) and values are their values
127
+	 * @param boolean $bydb                                    a flag for setting if the class is instantiated by the
128
+	 *                                                         corresponding db model or not.
129
+	 * @param string  $timezone                                indicate what timezone you want any datetime fields to
130
+	 *                                                         be in when instantiating a EE_Base_Class object.
131
+	 * @param array   $date_formats                            An array of date formats to set on construct where first
132
+	 *                                                         value is the date_format and second value is the time
133
+	 *                                                         format.
134
+	 * @throws EE_Error
135
+	 */
136
+	protected function __construct($fieldValues = array(), $bydb = false, $timezone = '', $date_formats = array())
137
+	{
138
+		$className = get_class($this);
139
+		do_action("AHEE__{$className}__construct", $this, $fieldValues);
140
+		$model = $this->get_model();
141
+		$model_fields = $model->field_settings(false);
142
+		// ensure $fieldValues is an array
143
+		$fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues);
144
+		// EEH_Debug_Tools::printr( $fieldValues, '$fieldValues  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
145
+		// verify client code has not passed any invalid field names
146
+		foreach ($fieldValues as $field_name => $field_value) {
147
+			if ( ! isset($model_fields[$field_name])) {
148
+				throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s",
149
+					"event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields))));
150
+			}
151
+		}
152
+		// EEH_Debug_Tools::printr( $model_fields, '$model_fields  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
153
+		$this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone);
154
+		if ( ! empty($date_formats) && is_array($date_formats)) {
155
+			list($this->_dt_frmt, $this->_tm_frmt) = $date_formats;
156
+		} else {
157
+			//set default formats for date and time
158
+			$this->_dt_frmt = (string)get_option('date_format', 'Y-m-d');
159
+			$this->_tm_frmt = (string)get_option('time_format', 'g:i a');
160
+		}
161
+		//if db model is instantiating
162
+		if ($bydb) {
163
+			//client code has indicated these field values are from the database
164
+			foreach ($model_fields as $fieldName => $field) {
165
+				$this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null);
166
+			}
167
+		} else {
168
+			//we're constructing a brand
169
+			//new instance of the model object. Generally, this means we'll need to do more field validation
170
+			foreach ($model_fields as $fieldName => $field) {
171
+				$this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true);
172
+			}
173
+		}
174
+		//remember what values were passed to this constructor
175
+		$this->_props_n_values_provided_in_constructor = $fieldValues;
176
+		//remember in entity mapper
177
+		if ( ! $bydb && $model->has_primary_key_field() && $this->ID()) {
178
+			$model->add_to_entity_map($this);
179
+		}
180
+		//setup all the relations
181
+		foreach ($model->relation_settings() as $relation_name => $relation_obj) {
182
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
183
+				$this->_model_relations[$relation_name] = null;
184
+			} else {
185
+				$this->_model_relations[$relation_name] = array();
186
+			}
187
+		}
188
+		/**
189
+		 * Action done at the end of each model object construction
190
+		 *
191
+		 * @param EE_Base_Class $this the model object just created
192
+		 */
193
+		do_action('AHEE__EE_Base_Class__construct__finished', $this);
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 * Gets whether or not this model object is allowed to persist/be saved to the database.
200
+	 *
201
+	 * @return boolean
202
+	 */
203
+	public function allow_persist()
204
+	{
205
+		return $this->_allow_persist;
206
+	}
207
+
208
+
209
+
210
+	/**
211
+	 * Sets whether or not this model object should be allowed to be saved to the DB.
212
+	 * Normally once this is set to FALSE you wouldn't set it back to TRUE, unless
213
+	 * you got new information that somehow made you change your mind.
214
+	 *
215
+	 * @param boolean $allow_persist
216
+	 * @return boolean
217
+	 */
218
+	public function set_allow_persist($allow_persist)
219
+	{
220
+		return $this->_allow_persist = $allow_persist;
221
+	}
222
+
223
+
224
+
225
+	/**
226
+	 * Gets the field's original value when this object was constructed during this request.
227
+	 * This can be helpful when determining if a model object has changed or not
228
+	 *
229
+	 * @param string $field_name
230
+	 * @return mixed|null
231
+	 * @throws \EE_Error
232
+	 */
233
+	public function get_original($field_name)
234
+	{
235
+		if (isset($this->_props_n_values_provided_in_constructor[$field_name])
236
+			&& $field_settings = $this->get_model()->field_settings_for($field_name)
237
+		) {
238
+			return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]);
239
+		} else {
240
+			return null;
241
+		}
242
+	}
243
+
244
+
245
+
246
+	/**
247
+	 * @param EE_Base_Class $obj
248
+	 * @return string
249
+	 */
250
+	public function get_class($obj)
251
+	{
252
+		return get_class($obj);
253
+	}
254
+
255
+
256
+
257
+	/**
258
+	 * Overrides parent because parent expects old models.
259
+	 * This also doesn't do any validation, and won't work for serialized arrays
260
+	 *
261
+	 * @param    string $field_name
262
+	 * @param    mixed  $field_value
263
+	 * @param bool      $use_default
264
+	 * @throws \EE_Error
265
+	 */
266
+	public function set($field_name, $field_value, $use_default = false)
267
+	{
268
+		// if not using default and nothing has changed, and object has already been setup (has ID),
269
+		// then don't do anything
270
+		if (
271
+			! $use_default
272
+			&& $this->_fields[$field_name] === $field_value
273
+			&& $this->ID()
274
+		) {
275
+			return;
276
+		}
277
+		$model = $this->get_model();
278
+		$this->_has_changes = true;
279
+		$field_obj = $model->field_settings_for($field_name);
280
+		if ($field_obj instanceof EE_Model_Field_Base) {
281
+			//			if ( method_exists( $field_obj, 'set_timezone' )) {
282
+			if ($field_obj instanceof EE_Datetime_Field) {
283
+				$field_obj->set_timezone($this->_timezone);
284
+				$field_obj->set_date_format($this->_dt_frmt);
285
+				$field_obj->set_time_format($this->_tm_frmt);
286
+			}
287
+			$holder_of_value = $field_obj->prepare_for_set($field_value);
288
+			//should the value be null?
289
+			if (($field_value === null || $holder_of_value === null || $holder_of_value === '') && $use_default) {
290
+				$this->_fields[$field_name] = $field_obj->get_default_value();
291
+				/**
292
+				 * To save having to refactor all the models, if a default value is used for a
293
+				 * EE_Datetime_Field, and that value is not null nor is it a DateTime
294
+				 * object.  Then let's do a set again to ensure that it becomes a DateTime
295
+				 * object.
296
+				 *
297
+				 * @since 4.6.10+
298
+				 */
299
+				if (
300
+					$field_obj instanceof EE_Datetime_Field
301
+					&& $this->_fields[$field_name] !== null
302
+					&& ! $this->_fields[$field_name] instanceof DateTime
303
+				) {
304
+					empty($this->_fields[$field_name])
305
+						? $this->set($field_name, time())
306
+						: $this->set($field_name, $this->_fields[$field_name]);
307
+				}
308
+			} else {
309
+				$this->_fields[$field_name] = $holder_of_value;
310
+			}
311
+			//if we're not in the constructor...
312
+			//now check if what we set was a primary key
313
+			if (
314
+				//note: props_n_values_provided_in_constructor is only set at the END of the constructor
315
+				$this->_props_n_values_provided_in_constructor
316
+				&& $field_value
317
+				&& $field_name === $model->primary_key_name()
318
+			) {
319
+				//if so, we want all this object's fields to be filled either with
320
+				//what we've explicitly set on this model
321
+				//or what we have in the db
322
+				// echo "setting primary key!";
323
+				$fields_on_model = self::_get_model(get_class($this))->field_settings();
324
+				$obj_in_db = self::_get_model(get_class($this))->get_one_by_ID($field_value);
325
+				foreach ($fields_on_model as $field_obj) {
326
+					if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor)
327
+						 && $field_obj->get_name() !== $field_name
328
+					) {
329
+						$this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name()));
330
+					}
331
+				}
332
+				//oh this model object has an ID? well make sure its in the entity mapper
333
+				$model->add_to_entity_map($this);
334
+			}
335
+			//let's unset any cache for this field_name from the $_cached_properties property.
336
+			$this->_clear_cached_property($field_name);
337
+		} else {
338
+			throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s",
339
+				"event_espresso"), $field_name));
340
+		}
341
+	}
342
+
343
+
344
+
345
+	/**
346
+	 * This sets the field value on the db column if it exists for the given $column_name or
347
+	 * saves it to EE_Extra_Meta if the given $column_name does not match a db column.
348
+	 *
349
+	 * @see EE_message::get_column_value for related documentation on the necessity of this method.
350
+	 * @param string $field_name  Must be the exact column name.
351
+	 * @param mixed  $field_value The value to set.
352
+	 * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs.
353
+	 * @throws \EE_Error
354
+	 */
355
+	public function set_field_or_extra_meta($field_name, $field_value)
356
+	{
357
+		if ($this->get_model()->has_field($field_name)) {
358
+			$this->set($field_name, $field_value);
359
+			return true;
360
+		} else {
361
+			//ensure this object is saved first so that extra meta can be properly related.
362
+			$this->save();
363
+			return $this->update_extra_meta($field_name, $field_value);
364
+		}
365
+	}
366
+
367
+
368
+
369
+	/**
370
+	 * This retrieves the value of the db column set on this class or if that's not present
371
+	 * it will attempt to retrieve from extra_meta if found.
372
+	 * Example Usage:
373
+	 * Via EE_Message child class:
374
+	 * Due to the dynamic nature of the EE_messages system, EE_messengers will always have a "to",
375
+	 * "from", "subject", and "content" field (as represented in the EE_Message schema), however they may
376
+	 * also have additional main fields specific to the messenger.  The system accommodates those extra
377
+	 * fields through the EE_Extra_Meta table.  This method allows for EE_messengers to retrieve the
378
+	 * value for those extra fields dynamically via the EE_message object.
379
+	 *
380
+	 * @param  string $field_name expecting the fully qualified field name.
381
+	 * @return mixed|null  value for the field if found.  null if not found.
382
+	 * @throws \EE_Error
383
+	 */
384
+	public function get_field_or_extra_meta($field_name)
385
+	{
386
+		if ($this->get_model()->has_field($field_name)) {
387
+			$column_value = $this->get($field_name);
388
+		} else {
389
+			//This isn't a column in the main table, let's see if it is in the extra meta.
390
+			$column_value = $this->get_extra_meta($field_name, true, null);
391
+		}
392
+		return $column_value;
393
+	}
394
+
395
+
396
+
397
+	/**
398
+	 * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
399
+	 * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
400
+	 * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). This is
401
+	 * available to all child classes that may be using the EE_Datetime_Field for a field data type.
402
+	 *
403
+	 * @access public
404
+	 * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php
405
+	 * @return void
406
+	 * @throws \EE_Error
407
+	 */
408
+	public function set_timezone($timezone = '')
409
+	{
410
+		$this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone);
411
+		//make sure we clear all cached properties because they won't be relevant now
412
+		$this->_clear_cached_properties();
413
+		//make sure we update field settings and the date for all EE_Datetime_Fields
414
+		$model_fields = $this->get_model()->field_settings(false);
415
+		foreach ($model_fields as $field_name => $field_obj) {
416
+			if ($field_obj instanceof EE_Datetime_Field) {
417
+				$field_obj->set_timezone($this->_timezone);
418
+				if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) {
419
+					$this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone));
420
+				}
421
+			}
422
+		}
423
+	}
424
+
425
+
426
+
427
+	/**
428
+	 * This just returns whatever is set for the current timezone.
429
+	 *
430
+	 * @access public
431
+	 * @return string timezone string
432
+	 */
433
+	public function get_timezone()
434
+	{
435
+		return $this->_timezone;
436
+	}
437
+
438
+
439
+
440
+	/**
441
+	 * This sets the internal date format to what is sent in to be used as the new default for the class
442
+	 * internally instead of wp set date format options
443
+	 *
444
+	 * @since 4.6
445
+	 * @param string $format should be a format recognizable by PHP date() functions.
446
+	 */
447
+	public function set_date_format($format)
448
+	{
449
+		$this->_dt_frmt = $format;
450
+		//clear cached_properties because they won't be relevant now.
451
+		$this->_clear_cached_properties();
452
+	}
453
+
454
+
455
+
456
+	/**
457
+	 * This sets the internal time format string to what is sent in to be used as the new default for the
458
+	 * class internally instead of wp set time format options.
459
+	 *
460
+	 * @since 4.6
461
+	 * @param string $format should be a format recognizable by PHP date() functions.
462
+	 */
463
+	public function set_time_format($format)
464
+	{
465
+		$this->_tm_frmt = $format;
466
+		//clear cached_properties because they won't be relevant now.
467
+		$this->_clear_cached_properties();
468
+	}
469
+
470
+
471
+
472
+	/**
473
+	 * This returns the current internal set format for the date and time formats.
474
+	 *
475
+	 * @param bool $full           if true (default), then return the full format.  Otherwise will return an array
476
+	 *                             where the first value is the date format and the second value is the time format.
477
+	 * @return mixed string|array
478
+	 */
479
+	public function get_format($full = true)
480
+	{
481
+		return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt);
482
+	}
483
+
484
+
485
+
486
+	/**
487
+	 * cache
488
+	 * stores the passed model object on the current model object.
489
+	 * In certain circumstances, we can use this cached model object instead of querying for another one entirely.
490
+	 *
491
+	 * @param string        $relationName    one of the keys in the _model_relations array on the model. Eg
492
+	 *                                       'Registration' associated with this model object
493
+	 * @param EE_Base_Class $object_to_cache that has a relation to this model object. (Eg, if this is a Transaction,
494
+	 *                                       that could be a payment or a registration)
495
+	 * @param null          $cache_id        a string or number that will be used as the key for any Belongs_To_Many
496
+	 *                                       items which will be stored in an array on this object
497
+	 * @throws EE_Error
498
+	 * @return mixed    index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one
499
+	 *                  related thing, no array)
500
+	 */
501
+	public function cache($relationName = '', $object_to_cache = null, $cache_id = null)
502
+	{
503
+		// its entirely possible that there IS no related object yet in which case there is nothing to cache.
504
+		if ( ! $object_to_cache instanceof EE_Base_Class) {
505
+			return false;
506
+		}
507
+		// also get "how" the object is related, or throw an error
508
+		if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) {
509
+			throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'),
510
+				$relationName, get_class($this)));
511
+		}
512
+		// how many things are related ?
513
+		if ($relationship_to_model instanceof EE_Belongs_To_Relation) {
514
+			// if it's a "belongs to" relationship, then there's only one related model object  eg, if this is a registration, there's only 1 attendee for it
515
+			// so for these model objects just set it to be cached
516
+			$this->_model_relations[$relationName] = $object_to_cache;
517
+			$return = true;
518
+		} else {
519
+			// otherwise, this is the "many" side of a one to many relationship, so we'll add the object to the array of related objects for that type.
520
+			// eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array
521
+			if ( ! is_array($this->_model_relations[$relationName])) {
522
+				// if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array
523
+				$this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class
524
+					? array($this->_model_relations[$relationName]) : array();
525
+			}
526
+			// first check for a cache_id which is normally empty
527
+			if ( ! empty($cache_id)) {
528
+				// if the cache_id exists, then it means we are purposely trying to cache this with a known key that can then be used to retrieve the object later on
529
+				$this->_model_relations[$relationName][$cache_id] = $object_to_cache;
530
+				$return = $cache_id;
531
+			} elseif ($object_to_cache->ID()) {
532
+				// OR the cached object originally came from the db, so let's just use it's PK for an ID
533
+				$this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache;
534
+				$return = $object_to_cache->ID();
535
+			} else {
536
+				// OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID
537
+				$this->_model_relations[$relationName][] = $object_to_cache;
538
+				// move the internal pointer to the end of the array
539
+				end($this->_model_relations[$relationName]);
540
+				// and grab the key so that we can return it
541
+				$return = key($this->_model_relations[$relationName]);
542
+			}
543
+		}
544
+		return $return;
545
+	}
546
+
547
+
548
+
549
+	/**
550
+	 * For adding an item to the cached_properties property.
551
+	 *
552
+	 * @access protected
553
+	 * @param string      $fieldname the property item the corresponding value is for.
554
+	 * @param mixed       $value     The value we are caching.
555
+	 * @param string|null $cache_type
556
+	 * @return void
557
+	 * @throws \EE_Error
558
+	 */
559
+	protected function _set_cached_property($fieldname, $value, $cache_type = null)
560
+	{
561
+		//first make sure this property exists
562
+		$this->get_model()->field_settings_for($fieldname);
563
+		$cache_type = empty($cache_type) ? 'standard' : $cache_type;
564
+		$this->_cached_properties[$fieldname][$cache_type] = $value;
565
+	}
566
+
567
+
568
+
569
+	/**
570
+	 * This returns the value cached property if it exists OR the actual property value if the cache doesn't exist.
571
+	 * This also SETS the cache if we return the actual property!
572
+	 *
573
+	 * @param string $fieldname        the name of the property we're trying to retrieve
574
+	 * @param bool   $pretty
575
+	 * @param string $extra_cache_ref  This allows the user to specify an extra cache ref for the given property
576
+	 *                                 (in cases where the same property may be used for different outputs
577
+	 *                                 - i.e. datetime, money etc.)
578
+	 *                                 It can also accept certain pre-defined "schema" strings
579
+	 *                                 to define how to output the property.
580
+	 *                                 see the field's prepare_for_pretty_echoing for what strings can be used
581
+	 * @return mixed                   whatever the value for the property is we're retrieving
582
+	 * @throws \EE_Error
583
+	 */
584
+	protected function _get_cached_property($fieldname, $pretty = false, $extra_cache_ref = null)
585
+	{
586
+		//verify the field exists
587
+		$model = $this->get_model();
588
+		$model->field_settings_for($fieldname);
589
+		$cache_type = $pretty ? 'pretty' : 'standard';
590
+		$cache_type .= ! empty($extra_cache_ref) ? '_' . $extra_cache_ref : '';
591
+		if (isset($this->_cached_properties[$fieldname][$cache_type])) {
592
+			return $this->_cached_properties[$fieldname][$cache_type];
593
+		}
594
+		$value = $this->_get_fresh_property($fieldname, $pretty, $extra_cache_ref);
595
+		$this->_set_cached_property($fieldname, $value, $cache_type);
596
+		return $value;
597
+	}
598
+
599
+
600
+
601
+	/**
602
+	 * If the cache didn't fetch the needed item, this fetches it.
603
+	 * @param string $fieldname
604
+	 * @param bool $pretty
605
+	 * @param string $extra_cache_ref
606
+	 * @return mixed
607
+	 */
608
+	protected function _get_fresh_property($fieldname, $pretty = false, $extra_cache_ref = null)
609
+	{
610
+		$field_obj = $this->get_model()->field_settings_for($fieldname);
611
+		// If this is an EE_Datetime_Field we need to make sure timezone, formats, and output are correct
612
+		if ($field_obj instanceof EE_Datetime_Field) {
613
+			$this->_prepare_datetime_field($field_obj, $pretty, $extra_cache_ref);
614
+		}
615
+		if ( ! isset($this->_fields[$fieldname])) {
616
+			$this->_fields[$fieldname] = null;
617
+		}
618
+		$value = $pretty
619
+			? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref)
620
+			: $field_obj->prepare_for_get($this->_fields[$fieldname]);
621
+		return $value;
622
+	}
623
+
624
+
625
+
626
+	/**
627
+	 * set timezone, formats, and output for EE_Datetime_Field objects
628
+	 *
629
+	 * @param \EE_Datetime_Field $datetime_field
630
+	 * @param bool               $pretty
631
+	 * @param null $date_or_time
632
+	 * @return void
633
+	 * @throws \EE_Error
634
+	 */
635
+	protected function _prepare_datetime_field(
636
+		EE_Datetime_Field $datetime_field,
637
+		$pretty = false,
638
+		$date_or_time = null
639
+	) {
640
+		$datetime_field->set_timezone($this->_timezone);
641
+		$datetime_field->set_date_format($this->_dt_frmt, $pretty);
642
+		$datetime_field->set_time_format($this->_tm_frmt, $pretty);
643
+		//set the output returned
644
+		switch ($date_or_time) {
645
+			case 'D' :
646
+				$datetime_field->set_date_time_output('date');
647
+				break;
648
+			case 'T' :
649
+				$datetime_field->set_date_time_output('time');
650
+				break;
651
+			default :
652
+				$datetime_field->set_date_time_output();
653
+		}
654
+	}
655
+
656
+
657
+
658
+	/**
659
+	 * This just takes care of clearing out the cached_properties
660
+	 *
661
+	 * @return void
662
+	 */
663
+	protected function _clear_cached_properties()
664
+	{
665
+		$this->_cached_properties = array();
666
+	}
667
+
668
+
669
+
670
+	/**
671
+	 * This just clears out ONE property if it exists in the cache
672
+	 *
673
+	 * @param  string $property_name the property to remove if it exists (from the _cached_properties array)
674
+	 * @return void
675
+	 */
676
+	protected function _clear_cached_property($property_name)
677
+	{
678
+		if (isset($this->_cached_properties[$property_name])) {
679
+			unset($this->_cached_properties[$property_name]);
680
+		}
681
+	}
682
+
683
+
684
+
685
+	/**
686
+	 * Ensures that this related thing is a model object.
687
+	 *
688
+	 * @param mixed  $object_or_id EE_base_Class/int/string either a related model object, or its ID
689
+	 * @param string $model_name   name of the related thing, eg 'Attendee',
690
+	 * @return EE_Base_Class
691
+	 * @throws \EE_Error
692
+	 */
693
+	protected function ensure_related_thing_is_model_obj($object_or_id, $model_name)
694
+	{
695
+		$other_model_instance = self::_get_model_instance_with_name(
696
+			self::_get_model_classname($model_name),
697
+			$this->_timezone
698
+		);
699
+		return $other_model_instance->ensure_is_obj($object_or_id);
700
+	}
701
+
702
+
703
+
704
+	/**
705
+	 * Forgets the cached model of the given relation Name. So the next time we request it,
706
+	 * we will fetch it again from the database. (Handy if you know it's changed somehow).
707
+	 * If a specific object is supplied, and the relationship to it is either a HasMany or HABTM,
708
+	 * then only remove that one object from our cached array. Otherwise, clear the entire list
709
+	 *
710
+	 * @param string $relationName                         one of the keys in the _model_relations array on the model.
711
+	 *                                                     Eg 'Registration'
712
+	 * @param mixed  $object_to_remove_or_index_into_array or an index into the array of cached things, or NULL
713
+	 *                                                     if you intend to use $clear_all = TRUE, or the relation only
714
+	 *                                                     has 1 object anyways (ie, it's a BelongsToRelation)
715
+	 * @param bool   $clear_all                            This flags clearing the entire cache relation property if
716
+	 *                                                     this is HasMany or HABTM.
717
+	 * @throws EE_Error
718
+	 * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a
719
+	 *                       relation from all
720
+	 */
721
+	public function clear_cache($relationName, $object_to_remove_or_index_into_array = null, $clear_all = false)
722
+	{
723
+		$relationship_to_model = $this->get_model()->related_settings_for($relationName);
724
+		$index_in_cache = '';
725
+		if ( ! $relationship_to_model) {
726
+			throw new EE_Error(
727
+				sprintf(
728
+					__("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'),
729
+					$relationName,
730
+					get_class($this)
731
+				)
732
+			);
733
+		}
734
+		if ($clear_all) {
735
+			$obj_removed = true;
736
+			$this->_model_relations[$relationName] = null;
737
+		} elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) {
738
+			$obj_removed = $this->_model_relations[$relationName];
739
+			$this->_model_relations[$relationName] = null;
740
+		} else {
741
+			if ($object_to_remove_or_index_into_array instanceof EE_Base_Class
742
+				&& $object_to_remove_or_index_into_array->ID()
743
+			) {
744
+				$index_in_cache = $object_to_remove_or_index_into_array->ID();
745
+				if (is_array($this->_model_relations[$relationName])
746
+					&& ! isset($this->_model_relations[$relationName][$index_in_cache])
747
+				) {
748
+					$index_found_at = null;
749
+					//find this object in the array even though it has a different key
750
+					foreach ($this->_model_relations[$relationName] as $index => $obj) {
751
+						if (
752
+							$obj instanceof EE_Base_Class
753
+							&& (
754
+								$obj == $object_to_remove_or_index_into_array
755
+								|| $obj->ID() === $object_to_remove_or_index_into_array->ID()
756
+							)
757
+						) {
758
+							$index_found_at = $index;
759
+							break;
760
+						}
761
+					}
762
+					if ($index_found_at) {
763
+						$index_in_cache = $index_found_at;
764
+					} else {
765
+						//it wasn't found. huh. well obviously it doesn't need to be removed from teh cache
766
+						//if it wasn't in it to begin with. So we're done
767
+						return $object_to_remove_or_index_into_array;
768
+					}
769
+				}
770
+			} elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) {
771
+				//so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it!
772
+				foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) {
773
+					if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) {
774
+						$index_in_cache = $index;
775
+					}
776
+				}
777
+			} else {
778
+				$index_in_cache = $object_to_remove_or_index_into_array;
779
+			}
780
+			//supposedly we've found it. But it could just be that the client code
781
+			//provided a bad index/object
782
+			if (
783
+			isset(
784
+				$this->_model_relations[$relationName],
785
+				$this->_model_relations[$relationName][$index_in_cache]
786
+			)
787
+			) {
788
+				$obj_removed = $this->_model_relations[$relationName][$index_in_cache];
789
+				unset($this->_model_relations[$relationName][$index_in_cache]);
790
+			} else {
791
+				//that thing was never cached anyways.
792
+				$obj_removed = null;
793
+			}
794
+		}
795
+		return $obj_removed;
796
+	}
797
+
798
+
799
+
800
+	/**
801
+	 * update_cache_after_object_save
802
+	 * Allows a cached item to have it's cache ID (within the array of cached items) reset using the new ID it has
803
+	 * obtained after being saved to the db
804
+	 *
805
+	 * @param string         $relationName       - the type of object that is cached
806
+	 * @param \EE_Base_Class $newly_saved_object - the newly saved object to be re-cached
807
+	 * @param string         $current_cache_id   - the ID that was used when originally caching the object
808
+	 * @return boolean TRUE on success, FALSE on fail
809
+	 * @throws \EE_Error
810
+	 */
811
+	public function update_cache_after_object_save(
812
+		$relationName,
813
+		EE_Base_Class $newly_saved_object,
814
+		$current_cache_id = ''
815
+	) {
816
+		// verify that incoming object is of the correct type
817
+		$obj_class = 'EE_' . $relationName;
818
+		if ($newly_saved_object instanceof $obj_class) {
819
+			/* @type EE_Base_Class $newly_saved_object */
820
+			// now get the type of relation
821
+			$relationship_to_model = $this->get_model()->related_settings_for($relationName);
822
+			// if this is a 1:1 relationship
823
+			if ($relationship_to_model instanceof EE_Belongs_To_Relation) {
824
+				// then just replace the cached object with the newly saved object
825
+				$this->_model_relations[$relationName] = $newly_saved_object;
826
+				return true;
827
+				// or if it's some kind of sordid feral polyamorous relationship...
828
+			} elseif (is_array($this->_model_relations[$relationName])
829
+					  && isset($this->_model_relations[$relationName][$current_cache_id])
830
+			) {
831
+				// then remove the current cached item
832
+				unset($this->_model_relations[$relationName][$current_cache_id]);
833
+				// and cache the newly saved object using it's new ID
834
+				$this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object;
835
+				return true;
836
+			}
837
+		}
838
+		return false;
839
+	}
840
+
841
+
842
+
843
+	/**
844
+	 * Fetches a single EE_Base_Class on that relation. (If the relation is of type
845
+	 * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects)
846
+	 *
847
+	 * @param string $relationName
848
+	 * @return EE_Base_Class
849
+	 */
850
+	public function get_one_from_cache($relationName)
851
+	{
852
+		$cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName]
853
+			: null;
854
+		if (is_array($cached_array_or_object)) {
855
+			return array_shift($cached_array_or_object);
856
+		} else {
857
+			return $cached_array_or_object;
858
+		}
859
+	}
860
+
861
+
862
+
863
+	/**
864
+	 * Fetches a single EE_Base_Class on that relation. (If the relation is of type
865
+	 * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects)
866
+	 *
867
+	 * @param string $relationName
868
+	 * @throws \EE_Error
869
+	 * @return EE_Base_Class[] NOT necessarily indexed by primary keys
870
+	 */
871
+	public function get_all_from_cache($relationName)
872
+	{
873
+		$objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array();
874
+		// if the result is not an array, but exists, make it an array
875
+		$objects = is_array($objects) ? $objects : array($objects);
876
+		//bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143
877
+		//basically, if this model object was stored in the session, and these cached model objects
878
+		//already have IDs, let's make sure they're in their model's entity mapper
879
+		//otherwise we will have duplicates next time we call
880
+		// EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() );
881
+		$model = EE_Registry::instance()->load_model($relationName);
882
+		foreach ($objects as $model_object) {
883
+			if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) {
884
+				//ensure its in the map if it has an ID; otherwise it will be added to the map when its saved
885
+				if ($model_object->ID()) {
886
+					$model->add_to_entity_map($model_object);
887
+				}
888
+			} else {
889
+				throw new EE_Error(
890
+					sprintf(
891
+						__(
892
+							'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object',
893
+							'event_espresso'
894
+						),
895
+						$relationName,
896
+						gettype($model_object)
897
+					)
898
+				);
899
+			}
900
+		}
901
+		return $objects;
902
+	}
903
+
904
+
905
+
906
+	/**
907
+	 * Returns the next x number of EE_Base_Class objects in sequence from this object as found in the database
908
+	 * matching the given query conditions.
909
+	 *
910
+	 * @param null  $field_to_order_by  What field is being used as the reference point.
911
+	 * @param int   $limit              How many objects to return.
912
+	 * @param array $query_params       Any additional conditions on the query.
913
+	 * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
914
+	 *                                  you can indicate just the columns you want returned
915
+	 * @return array|EE_Base_Class[]
916
+	 * @throws \EE_Error
917
+	 */
918
+	public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null)
919
+	{
920
+		$model = $this->get_model();
921
+		$field = empty($field_to_order_by) && $model->has_primary_key_field()
922
+			? $model->get_primary_key_field()->get_name()
923
+			: $field_to_order_by;
924
+		$current_value = ! empty($field) ? $this->get($field) : null;
925
+		if (empty($field) || empty($current_value)) {
926
+			return array();
927
+		}
928
+		return $model->next_x($current_value, $field, $limit, $query_params, $columns_to_select);
929
+	}
930
+
931
+
932
+
933
+	/**
934
+	 * Returns the previous x number of EE_Base_Class objects in sequence from this object as found in the database
935
+	 * matching the given query conditions.
936
+	 *
937
+	 * @param null  $field_to_order_by  What field is being used as the reference point.
938
+	 * @param int   $limit              How many objects to return.
939
+	 * @param array $query_params       Any additional conditions on the query.
940
+	 * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
941
+	 *                                  you can indicate just the columns you want returned
942
+	 * @return array|EE_Base_Class[]
943
+	 * @throws \EE_Error
944
+	 */
945
+	public function previous_x(
946
+		$field_to_order_by = null,
947
+		$limit = 1,
948
+		$query_params = array(),
949
+		$columns_to_select = null
950
+	) {
951
+		$model = $this->get_model();
952
+		$field = empty($field_to_order_by) && $model->has_primary_key_field()
953
+			? $model->get_primary_key_field()->get_name()
954
+			: $field_to_order_by;
955
+		$current_value = ! empty($field) ? $this->get($field) : null;
956
+		if (empty($field) || empty($current_value)) {
957
+			return array();
958
+		}
959
+		return $model->previous_x($current_value, $field, $limit, $query_params, $columns_to_select);
960
+	}
961
+
962
+
963
+
964
+	/**
965
+	 * Returns the next EE_Base_Class object in sequence from this object as found in the database
966
+	 * matching the given query conditions.
967
+	 *
968
+	 * @param null  $field_to_order_by  What field is being used as the reference point.
969
+	 * @param array $query_params       Any additional conditions on the query.
970
+	 * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
971
+	 *                                  you can indicate just the columns you want returned
972
+	 * @return array|EE_Base_Class
973
+	 * @throws \EE_Error
974
+	 */
975
+	public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null)
976
+	{
977
+		$model = $this->get_model();
978
+		$field = empty($field_to_order_by) && $model->has_primary_key_field()
979
+			? $model->get_primary_key_field()->get_name()
980
+			: $field_to_order_by;
981
+		$current_value = ! empty($field) ? $this->get($field) : null;
982
+		if (empty($field) || empty($current_value)) {
983
+			return array();
984
+		}
985
+		return $model->next($current_value, $field, $query_params, $columns_to_select);
986
+	}
987
+
988
+
989
+
990
+	/**
991
+	 * Returns the previous EE_Base_Class object in sequence from this object as found in the database
992
+	 * matching the given query conditions.
993
+	 *
994
+	 * @param null  $field_to_order_by  What field is being used as the reference point.
995
+	 * @param array $query_params       Any additional conditions on the query.
996
+	 * @param null  $columns_to_select  If left null, then an EE_Base_Class object is returned, otherwise
997
+	 *                                  you can indicate just the column you want returned
998
+	 * @return array|EE_Base_Class
999
+	 * @throws \EE_Error
1000
+	 */
1001
+	public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null)
1002
+	{
1003
+		$model = $this->get_model();
1004
+		$field = empty($field_to_order_by) && $model->has_primary_key_field()
1005
+			? $model->get_primary_key_field()->get_name()
1006
+			: $field_to_order_by;
1007
+		$current_value = ! empty($field) ? $this->get($field) : null;
1008
+		if (empty($field) || empty($current_value)) {
1009
+			return array();
1010
+		}
1011
+		return $model->previous($current_value, $field, $query_params, $columns_to_select);
1012
+	}
1013
+
1014
+
1015
+
1016
+	/**
1017
+	 * Overrides parent because parent expects old models.
1018
+	 * This also doesn't do any validation, and won't work for serialized arrays
1019
+	 *
1020
+	 * @param string $field_name
1021
+	 * @param mixed  $field_value_from_db
1022
+	 * @throws \EE_Error
1023
+	 */
1024
+	public function set_from_db($field_name, $field_value_from_db)
1025
+	{
1026
+		$field_obj = $this->get_model()->field_settings_for($field_name);
1027
+		if ($field_obj instanceof EE_Model_Field_Base) {
1028
+			//you would think the DB has no NULLs for non-null label fields right? wrong!
1029
+			//eg, a CPT model object could have an entry in the posts table, but no
1030
+			//entry in the meta table. Meaning that all its columns in the meta table
1031
+			//are null! yikes! so when we find one like that, use defaults for its meta columns
1032
+			if ($field_value_from_db === null) {
1033
+				if ($field_obj->is_nullable()) {
1034
+					//if the field allows nulls, then let it be null
1035
+					$field_value = null;
1036
+				} else {
1037
+					$field_value = $field_obj->get_default_value();
1038
+				}
1039
+			} else {
1040
+				$field_value = $field_obj->prepare_for_set_from_db($field_value_from_db);
1041
+			}
1042
+			$this->_fields[$field_name] = $field_value;
1043
+			$this->_clear_cached_property($field_name);
1044
+		}
1045
+	}
1046
+
1047
+
1048
+
1049
+	/**
1050
+	 * verifies that the specified field is of the correct type
1051
+	 *
1052
+	 * @param string $field_name
1053
+	 * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1054
+	 *                                (in cases where the same property may be used for different outputs
1055
+	 *                                - i.e. datetime, money etc.)
1056
+	 * @return mixed
1057
+	 * @throws \EE_Error
1058
+	 */
1059
+	public function get($field_name, $extra_cache_ref = null)
1060
+	{
1061
+		return $this->_get_cached_property($field_name, false, $extra_cache_ref);
1062
+	}
1063
+
1064
+
1065
+
1066
+	/**
1067
+	 * This method simply returns the RAW unprocessed value for the given property in this class
1068
+	 *
1069
+	 * @param  string $field_name A valid fieldname
1070
+	 * @return mixed              Whatever the raw value stored on the property is.
1071
+	 * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist.
1072
+	 */
1073
+	public function get_raw($field_name)
1074
+	{
1075
+		$field_settings = $this->get_model()->field_settings_for($field_name);
1076
+		return $field_settings instanceof EE_Datetime_Field && $this->_fields[$field_name] instanceof DateTime
1077
+			? $this->_fields[$field_name]->format('U')
1078
+			: $this->_fields[$field_name];
1079
+	}
1080
+
1081
+
1082
+
1083
+	/**
1084
+	 * This is used to return the internal DateTime object used for a field that is a
1085
+	 * EE_Datetime_Field.
1086
+	 *
1087
+	 * @param string $field_name               The field name retrieving the DateTime object.
1088
+	 * @return mixed null | false | DateTime  If the requested field is NOT a EE_Datetime_Field then
1089
+	 * @throws \EE_Error
1090
+	 *                                         an error is set and false returned.  If the field IS an
1091
+	 *                                         EE_Datetime_Field and but the field value is null, then
1092
+	 *                                         just null is returned (because that indicates that likely
1093
+	 *                                         this field is nullable).
1094
+	 */
1095
+	public function get_DateTime_object($field_name)
1096
+	{
1097
+		$field_settings = $this->get_model()->field_settings_for($field_name);
1098
+		if ( ! $field_settings instanceof EE_Datetime_Field) {
1099
+			EE_Error::add_error(
1100
+				sprintf(
1101
+					__(
1102
+						'The field %s is not an EE_Datetime_Field field.  There is no DateTime object stored on this field type.',
1103
+						'event_espresso'
1104
+					),
1105
+					$field_name
1106
+				),
1107
+				__FILE__,
1108
+				__FUNCTION__,
1109
+				__LINE__
1110
+			);
1111
+			return false;
1112
+		}
1113
+		return $this->_fields[$field_name];
1114
+	}
1115
+
1116
+
1117
+
1118
+	/**
1119
+	 * To be used in template to immediately echo out the value, and format it for output.
1120
+	 * Eg, should call stripslashes and whatnot before echoing
1121
+	 *
1122
+	 * @param string $field_name      the name of the field as it appears in the DB
1123
+	 * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1124
+	 *                                (in cases where the same property may be used for different outputs
1125
+	 *                                - i.e. datetime, money etc.)
1126
+	 * @return void
1127
+	 * @throws \EE_Error
1128
+	 */
1129
+	public function e($field_name, $extra_cache_ref = null)
1130
+	{
1131
+		echo $this->get_pretty($field_name, $extra_cache_ref);
1132
+	}
1133
+
1134
+
1135
+
1136
+	/**
1137
+	 * Exactly like e(), echoes out the field, but sets its schema to 'form_input', so that it
1138
+	 * can be easily used as the value of form input.
1139
+	 *
1140
+	 * @param string $field_name
1141
+	 * @return void
1142
+	 * @throws \EE_Error
1143
+	 */
1144
+	public function f($field_name)
1145
+	{
1146
+		$this->e($field_name, 'form_input');
1147
+	}
1148
+
1149
+	/**
1150
+	 * Same as `f()` but just returns the value instead of echoing it
1151
+	 * @param string $field_name
1152
+	 * @return string
1153
+	 */
1154
+	public function get_f($field_name)
1155
+	{
1156
+		return (string)$this->get_pretty($field_name,'form_input');
1157
+	}
1158
+
1159
+
1160
+
1161
+	/**
1162
+	 * Gets a pretty view of the field's value. $extra_cache_ref can specify different formats for this.
1163
+	 * The $extra_cache_ref will be passed to the model field's prepare_for_pretty_echoing, so consult the field's class
1164
+	 * to see what options are available.
1165
+	 * @param string $field_name
1166
+	 * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1167
+	 *                                (in cases where the same property may be used for different outputs
1168
+	 *                                - i.e. datetime, money etc.)
1169
+	 * @return mixed
1170
+	 * @throws \EE_Error
1171
+	 */
1172
+	public function get_pretty($field_name, $extra_cache_ref = null)
1173
+	{
1174
+		return $this->_get_cached_property($field_name, true, $extra_cache_ref);
1175
+	}
1176
+
1177
+
1178
+
1179
+	/**
1180
+	 * This simply returns the datetime for the given field name
1181
+	 * Note: this protected function is called by the wrapper get_date or get_time or get_datetime functions
1182
+	 * (and the equivalent e_date, e_time, e_datetime).
1183
+	 *
1184
+	 * @access   protected
1185
+	 * @param string   $field_name   Field on the instantiated EE_Base_Class child object
1186
+	 * @param string   $dt_frmt      valid datetime format used for date
1187
+	 *                               (if '' then we just use the default on the field,
1188
+	 *                               if NULL we use the last-used format)
1189
+	 * @param string   $tm_frmt      Same as above except this is for time format
1190
+	 * @param string   $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time.
1191
+	 * @param  boolean $echo         Whether the dtt is echoing using pretty echoing or just returned using vanilla get
1192
+	 * @return string|bool|EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown
1193
+	 *                               if field is not a valid dtt field, or void if echoing
1194
+	 * @throws \EE_Error
1195
+	 */
1196
+	protected function _get_datetime($field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false)
1197
+	{
1198
+		// clear cached property
1199
+		$this->_clear_cached_property($field_name);
1200
+		//reset format properties because they are used in get()
1201
+		$this->_dt_frmt = $dt_frmt !== '' ? $dt_frmt : $this->_dt_frmt;
1202
+		$this->_tm_frmt = $tm_frmt !== '' ? $tm_frmt : $this->_tm_frmt;
1203
+		if ($echo) {
1204
+			$this->e($field_name, $date_or_time);
1205
+			return '';
1206
+		}
1207
+		return $this->get($field_name, $date_or_time);
1208
+	}
1209
+
1210
+
1211
+
1212
+	/**
1213
+	 * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the date
1214
+	 * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the
1215
+	 * other echoes the pretty value for dtt)
1216
+	 *
1217
+	 * @param  string $field_name name of model object datetime field holding the value
1218
+	 * @param  string $format     format for the date returned (if NULL we use default in dt_frmt property)
1219
+	 * @return string            datetime value formatted
1220
+	 * @throws \EE_Error
1221
+	 */
1222
+	public function get_date($field_name, $format = '')
1223
+	{
1224
+		return $this->_get_datetime($field_name, $format, null, 'D');
1225
+	}
1226
+
1227
+
1228
+
1229
+	/**
1230
+	 * @param      $field_name
1231
+	 * @param string $format
1232
+	 * @throws \EE_Error
1233
+	 */
1234
+	public function e_date($field_name, $format = '')
1235
+	{
1236
+		$this->_get_datetime($field_name, $format, null, 'D', true);
1237
+	}
1238
+
1239
+
1240
+
1241
+	/**
1242
+	 * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the time
1243
+	 * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the
1244
+	 * other echoes the pretty value for dtt)
1245
+	 *
1246
+	 * @param  string $field_name name of model object datetime field holding the value
1247
+	 * @param  string $format     format for the time returned ( if NULL we use default in tm_frmt property)
1248
+	 * @return string             datetime value formatted
1249
+	 * @throws \EE_Error
1250
+	 */
1251
+	public function get_time($field_name, $format = '')
1252
+	{
1253
+		return $this->_get_datetime($field_name, null, $format, 'T');
1254
+	}
1255
+
1256
+
1257
+
1258
+	/**
1259
+	 * @param      $field_name
1260
+	 * @param string $format
1261
+	 * @throws \EE_Error
1262
+	 */
1263
+	public function e_time($field_name, $format = '')
1264
+	{
1265
+		$this->_get_datetime($field_name, null, $format, 'T', true);
1266
+	}
1267
+
1268
+
1269
+
1270
+	/**
1271
+	 * below are wrapper functions for the various datetime outputs that can be obtained for returning the date AND
1272
+	 * time portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the
1273
+	 * other echoes the pretty value for dtt)
1274
+	 *
1275
+	 * @param  string $field_name name of model object datetime field holding the value
1276
+	 * @param  string $dt_frmt    format for the date returned (if NULL we use default in dt_frmt property)
1277
+	 * @param  string $tm_frmt    format for the time returned (if NULL we use default in tm_frmt property)
1278
+	 * @return string             datetime value formatted
1279
+	 * @throws \EE_Error
1280
+	 */
1281
+	public function get_datetime($field_name, $dt_frmt = '', $tm_frmt = '')
1282
+	{
1283
+		return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt);
1284
+	}
1285
+
1286
+
1287
+
1288
+	/**
1289
+	 * @param string $field_name
1290
+	 * @param string $dt_frmt
1291
+	 * @param string $tm_frmt
1292
+	 * @throws \EE_Error
1293
+	 */
1294
+	public function e_datetime($field_name, $dt_frmt = '', $tm_frmt = '')
1295
+	{
1296
+		$this->_get_datetime($field_name, $dt_frmt, $tm_frmt, null, true);
1297
+	}
1298
+
1299
+
1300
+
1301
+	/**
1302
+	 * Get the i8ln value for a date using the WordPress @see date_i18n function.
1303
+	 *
1304
+	 * @param string $field_name The EE_Datetime_Field reference for the date being retrieved.
1305
+	 * @param string $format     PHP valid date/time string format.  If none is provided then the internal set format
1306
+	 *                           on the object will be used.
1307
+	 * @return string Date and time string in set locale or false if no field exists for the given
1308
+	 * @throws \EE_Error
1309
+	 *                           field name.
1310
+	 */
1311
+	public function get_i18n_datetime($field_name, $format = '')
1312
+	{
1313
+		$format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format;
1314
+		return date_i18n(
1315
+			$format,
1316
+			EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone)
1317
+		);
1318
+	}
1319
+
1320
+
1321
+
1322
+	/**
1323
+	 * This method validates whether the given field name is a valid field on the model object as well as it is of a
1324
+	 * type EE_Datetime_Field.  On success there will be returned the field settings.  On fail an EE_Error exception is
1325
+	 * thrown.
1326
+	 *
1327
+	 * @param  string $field_name The field name being checked
1328
+	 * @throws EE_Error
1329
+	 * @return EE_Datetime_Field
1330
+	 */
1331
+	protected function _get_dtt_field_settings($field_name)
1332
+	{
1333
+		$field = $this->get_model()->field_settings_for($field_name);
1334
+		//check if field is dtt
1335
+		if ($field instanceof EE_Datetime_Field) {
1336
+			return $field;
1337
+		} else {
1338
+			throw new EE_Error(sprintf(__('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field.  Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor',
1339
+				'event_espresso'), $field_name, self::_get_model_classname(get_class($this))));
1340
+		}
1341
+	}
1342
+
1343
+
1344
+
1345
+
1346
+	/**
1347
+	 * NOTE ABOUT BELOW:
1348
+	 * These convenience date and time setters are for setting date and time independently.  In other words you might
1349
+	 * want to change the time on a datetime_field but leave the date the same (or vice versa). IF on the other hand
1350
+	 * you want to set both date and time at the same time, you can just use the models default set($fieldname,$value)
1351
+	 * method and make sure you send the entire datetime value for setting.
1352
+	 */
1353
+	/**
1354
+	 * sets the time on a datetime property
1355
+	 *
1356
+	 * @access protected
1357
+	 * @param string|Datetime $time      a valid time string for php datetime functions (or DateTime object)
1358
+	 * @param string          $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field)
1359
+	 * @throws \EE_Error
1360
+	 */
1361
+	protected function _set_time_for($time, $fieldname)
1362
+	{
1363
+		$this->_set_date_time('T', $time, $fieldname);
1364
+	}
1365
+
1366
+
1367
+
1368
+	/**
1369
+	 * sets the date on a datetime property
1370
+	 *
1371
+	 * @access protected
1372
+	 * @param string|DateTime $date      a valid date string for php datetime functions ( or DateTime object)
1373
+	 * @param string          $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field)
1374
+	 * @throws \EE_Error
1375
+	 */
1376
+	protected function _set_date_for($date, $fieldname)
1377
+	{
1378
+		$this->_set_date_time('D', $date, $fieldname);
1379
+	}
1380
+
1381
+
1382
+
1383
+	/**
1384
+	 * This takes care of setting a date or time independently on a given model object property. This method also
1385
+	 * verifies that the given fieldname matches a model object property and is for a EE_Datetime_Field field
1386
+	 *
1387
+	 * @access protected
1388
+	 * @param string          $what           "T" for time, 'B' for both, 'D' for Date.
1389
+	 * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object)
1390
+	 * @param string          $fieldname      the name of the field the date OR time is being set on (must match a
1391
+	 *                                        EE_Datetime_Field property)
1392
+	 * @throws \EE_Error
1393
+	 */
1394
+	protected function _set_date_time($what = 'T', $datetime_value, $fieldname)
1395
+	{
1396
+		$field = $this->_get_dtt_field_settings($fieldname);
1397
+		$field->set_timezone($this->_timezone);
1398
+		$field->set_date_format($this->_dt_frmt);
1399
+		$field->set_time_format($this->_tm_frmt);
1400
+		switch ($what) {
1401
+			case 'T' :
1402
+				$this->_fields[$fieldname] = $field->prepare_for_set_with_new_time(
1403
+					$datetime_value,
1404
+					$this->_fields[$fieldname]
1405
+				);
1406
+				break;
1407
+			case 'D' :
1408
+				$this->_fields[$fieldname] = $field->prepare_for_set_with_new_date(
1409
+					$datetime_value,
1410
+					$this->_fields[$fieldname]
1411
+				);
1412
+				break;
1413
+			case 'B' :
1414
+				$this->_fields[$fieldname] = $field->prepare_for_set($datetime_value);
1415
+				break;
1416
+		}
1417
+		$this->_clear_cached_property($fieldname);
1418
+	}
1419
+
1420
+
1421
+
1422
+	/**
1423
+	 * This will return a timestamp for the website timezone but ONLY when the current website timezone is different
1424
+	 * than the timezone set for the website. NOTE, this currently only works well with methods that return values.  If
1425
+	 * you use it with methods that echo values the $_timestamp property may not get reset to its original value and
1426
+	 * that could lead to some unexpected results!
1427
+	 *
1428
+	 * @access public
1429
+	 * @param string               $field_name This is the name of the field on the object that contains the date/time
1430
+	 *                                         value being returned.
1431
+	 * @param string               $callback   must match a valid method in this class (defaults to get_datetime)
1432
+	 * @param mixed (array|string) $args       This is the arguments that will be passed to the callback.
1433
+	 * @param string               $prepend    You can include something to prepend on the timestamp
1434
+	 * @param string               $append     You can include something to append on the timestamp
1435
+	 * @throws EE_Error
1436
+	 * @return string timestamp
1437
+	 */
1438
+	public function display_in_my_timezone(
1439
+		$field_name,
1440
+		$callback = 'get_datetime',
1441
+		$args = null,
1442
+		$prepend = '',
1443
+		$append = ''
1444
+	) {
1445
+		$timezone = EEH_DTT_Helper::get_timezone();
1446
+		if ($timezone === $this->_timezone) {
1447
+			return '';
1448
+		}
1449
+		$original_timezone = $this->_timezone;
1450
+		$this->set_timezone($timezone);
1451
+		$fn = (array)$field_name;
1452
+		$args = array_merge($fn, (array)$args);
1453
+		if ( ! method_exists($this, $callback)) {
1454
+			throw new EE_Error(
1455
+				sprintf(
1456
+					__(
1457
+						'The method named "%s" given as the callback param in "display_in_my_timezone" does not exist.  Please check your spelling',
1458
+						'event_espresso'
1459
+					),
1460
+					$callback
1461
+				)
1462
+			);
1463
+		}
1464
+		$args = (array)$args;
1465
+		$return = $prepend . call_user_func_array(array($this, $callback), $args) . $append;
1466
+		$this->set_timezone($original_timezone);
1467
+		return $return;
1468
+	}
1469
+
1470
+
1471
+
1472
+	/**
1473
+	 * Deletes this model object.
1474
+	 * This calls the `EE_Base_Class::_delete` method.  Child classes wishing to change default behaviour should
1475
+	 * override
1476
+	 * `EE_Base_Class::_delete` NOT this class.
1477
+	 *
1478
+	 * @return boolean | int
1479
+	 * @throws \EE_Error
1480
+	 */
1481
+	public function delete()
1482
+	{
1483
+		/**
1484
+		 * Called just before the `EE_Base_Class::_delete` method call.
1485
+		 * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
1486
+		 * should be aware that `_delete` may not always result in a permanent delete.  For example, `EE_Soft_Delete_Base_Class::_delete`
1487
+		 * soft deletes (trash) the object and does not permanently delete it.
1488
+		 *
1489
+		 * @param EE_Base_Class $model_object about to be 'deleted'
1490
+		 */
1491
+		do_action('AHEE__EE_Base_Class__delete__before', $this);
1492
+		$result = $this->_delete();
1493
+		/**
1494
+		 * Called just after the `EE_Base_Class::_delete` method call.
1495
+		 * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
1496
+		 * should be aware that `_delete` may not always result in a permanent delete.  For example `EE_Soft_Base_Class::_delete`
1497
+		 * soft deletes (trash) the object and does not permanently delete it.
1498
+		 *
1499
+		 * @param EE_Base_Class $model_object that was just 'deleted'
1500
+		 * @param boolean       $result
1501
+		 */
1502
+		do_action('AHEE__EE_Base_Class__delete__end', $this, $result);
1503
+		return $result;
1504
+	}
1505
+
1506
+
1507
+
1508
+	/**
1509
+	 * Calls the specific delete method for the instantiated class.
1510
+	 * This method is called by the public `EE_Base_Class::delete` method.  Any child classes desiring to override
1511
+	 * default functionality for "delete" (which is to call `permanently_delete`) should override this method NOT
1512
+	 * `EE_Base_Class::delete`
1513
+	 *
1514
+	 * @return bool|int
1515
+	 * @throws \EE_Error
1516
+	 */
1517
+	protected function _delete()
1518
+	{
1519
+		return $this->delete_permanently();
1520
+	}
1521
+
1522
+
1523
+
1524
+	/**
1525
+	 * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an
1526
+	 * error)
1527
+	 *
1528
+	 * @return bool | int
1529
+	 * @throws \EE_Error
1530
+	 */
1531
+	public function delete_permanently()
1532
+	{
1533
+		/**
1534
+		 * Called just before HARD deleting a model object
1535
+		 *
1536
+		 * @param EE_Base_Class $model_object about to be 'deleted'
1537
+		 */
1538
+		do_action('AHEE__EE_Base_Class__delete_permanently__before', $this);
1539
+		$model = $this->get_model();
1540
+		$result = $model->delete_permanently_by_ID($this->ID());
1541
+		$this->refresh_cache_of_related_objects();
1542
+		/**
1543
+		 * Called just after HARD deleting a model object
1544
+		 *
1545
+		 * @param EE_Base_Class $model_object that was just 'deleted'
1546
+		 * @param boolean       $result
1547
+		 */
1548
+		do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result);
1549
+		return $result;
1550
+	}
1551
+
1552
+
1553
+
1554
+	/**
1555
+	 * When this model object is deleted, it may still be cached on related model objects. This clears the cache of
1556
+	 * related model objects
1557
+	 *
1558
+	 * @throws \EE_Error
1559
+	 */
1560
+	public function refresh_cache_of_related_objects()
1561
+	{
1562
+		$model = $this->get_model();
1563
+		foreach ($model->relation_settings() as $relation_name => $relation_obj) {
1564
+			if ( ! empty($this->_model_relations[$relation_name])) {
1565
+				$related_objects = $this->_model_relations[$relation_name];
1566
+				if ($relation_obj instanceof EE_Belongs_To_Relation) {
1567
+					//this relation only stores a single model object, not an array
1568
+					//but let's make it consistent
1569
+					$related_objects = array($related_objects);
1570
+				}
1571
+				foreach ($related_objects as $related_object) {
1572
+					//only refresh their cache if they're in memory
1573
+					if ($related_object instanceof EE_Base_Class) {
1574
+						$related_object->clear_cache($model->get_this_model_name(), $this);
1575
+					}
1576
+				}
1577
+			}
1578
+		}
1579
+	}
1580
+
1581
+
1582
+
1583
+	/**
1584
+	 *        Saves this object to the database. An array may be supplied to set some values on this
1585
+	 * object just before saving.
1586
+	 *
1587
+	 * @access public
1588
+	 * @param array $set_cols_n_values keys are field names, values are their new values,
1589
+	 *                                 if provided during the save() method (often client code will change the fields'
1590
+	 *                                 values before calling save)
1591
+	 * @throws \EE_Error
1592
+	 * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object
1593
+	 *                                 isn't allowed to persist (as determined by EE_Base_Class::allow_persist())
1594
+	 */
1595
+	public function save($set_cols_n_values = array())
1596
+	{
1597
+		$model = $this->get_model();
1598
+		/**
1599
+		 * Filters the fields we're about to save on the model object
1600
+		 *
1601
+		 * @param array         $set_cols_n_values
1602
+		 * @param EE_Base_Class $model_object
1603
+		 */
1604
+		$set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values,
1605
+			$this);
1606
+		//set attributes as provided in $set_cols_n_values
1607
+		foreach ($set_cols_n_values as $column => $value) {
1608
+			$this->set($column, $value);
1609
+		}
1610
+		// no changes ? then don't do anything
1611
+		if (! $this->_has_changes && $this->ID() && $model->get_primary_key_field()->is_auto_increment()) {
1612
+			return 0;
1613
+		}
1614
+		/**
1615
+		 * Saving a model object.
1616
+		 * Before we perform a save, this action is fired.
1617
+		 *
1618
+		 * @param EE_Base_Class $model_object the model object about to be saved.
1619
+		 */
1620
+		do_action('AHEE__EE_Base_Class__save__begin', $this);
1621
+		if ( ! $this->allow_persist()) {
1622
+			return 0;
1623
+		}
1624
+		//now get current attribute values
1625
+		$save_cols_n_values = $this->_fields;
1626
+		//if the object already has an ID, update it. Otherwise, insert it
1627
+		//also: change the assumption about values passed to the model NOT being prepare dby the model object. They have been
1628
+		$old_assumption_concerning_value_preparation = $model
1629
+															->get_assumption_concerning_values_already_prepared_by_model_object();
1630
+		$model->assume_values_already_prepared_by_model_object(true);
1631
+		//does this model have an autoincrement PK?
1632
+		if ($model->has_primary_key_field()) {
1633
+			if ($model->get_primary_key_field()->is_auto_increment()) {
1634
+				//ok check if it's set, if so: update; if not, insert
1635
+				if ( ! empty($save_cols_n_values[$model->primary_key_name()])) {
1636
+					$results = $model->update_by_ID($save_cols_n_values, $this->ID());
1637
+				} else {
1638
+					unset($save_cols_n_values[$model->primary_key_name()]);
1639
+					$results = $model->insert($save_cols_n_values);
1640
+					if ($results) {
1641
+						//if successful, set the primary key
1642
+						//but don't use the normal SET method, because it will check if
1643
+						//an item with the same ID exists in the mapper & db, then
1644
+						//will find it in the db (because we just added it) and THAT object
1645
+						//will get added to the mapper before we can add this one!
1646
+						//but if we just avoid using the SET method, all that headache can be avoided
1647
+						$pk_field_name = $model->primary_key_name();
1648
+						$this->_fields[$pk_field_name] = $results;
1649
+						$this->_clear_cached_property($pk_field_name);
1650
+						$model->add_to_entity_map($this);
1651
+						$this->_update_cached_related_model_objs_fks();
1652
+					}
1653
+				}
1654
+			} else {//PK is NOT auto-increment
1655
+				//so check if one like it already exists in the db
1656
+				if ($model->exists_by_ID($this->ID())) {
1657
+					if (WP_DEBUG && ! $this->in_entity_map()) {
1658
+						throw new EE_Error(
1659
+							sprintf(
1660
+								__('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s',
1661
+									'event_espresso'),
1662
+								get_class($this),
1663
+								get_class($model) . '::instance()->add_to_entity_map()',
1664
+								get_class($model) . '::instance()->get_one_by_ID()',
1665
+								'<br />'
1666
+							)
1667
+						);
1668
+					}
1669
+					$results = $model->update_by_ID($save_cols_n_values, $this->ID());
1670
+				} else {
1671
+					$results = $model->insert($save_cols_n_values);
1672
+					$this->_update_cached_related_model_objs_fks();
1673
+				}
1674
+			}
1675
+		} else {//there is NO primary key
1676
+			$already_in_db = false;
1677
+			foreach ($model->unique_indexes() as $index) {
1678
+				$uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields());
1679
+				if ($model->exists(array($uniqueness_where_params))) {
1680
+					$already_in_db = true;
1681
+				}
1682
+			}
1683
+			if ($already_in_db) {
1684
+				$combined_pk_fields_n_values = array_intersect_key($save_cols_n_values,
1685
+					$model->get_combined_primary_key_fields());
1686
+				$results = $model->update($save_cols_n_values, $combined_pk_fields_n_values);
1687
+			} else {
1688
+				$results = $model->insert($save_cols_n_values);
1689
+			}
1690
+		}
1691
+		//restore the old assumption about values being prepared by the model object
1692
+		$model
1693
+			 ->assume_values_already_prepared_by_model_object($old_assumption_concerning_value_preparation);
1694
+		/**
1695
+		 * After saving the model object this action is called
1696
+		 *
1697
+		 * @param EE_Base_Class $model_object which was just saved
1698
+		 * @param boolean|int   $results      if it were updated, TRUE or FALSE; if it were newly inserted
1699
+		 *                                    the new ID (or 0 if an error occurred and it wasn't updated)
1700
+		 */
1701
+		do_action('AHEE__EE_Base_Class__save__end', $this, $results);
1702
+		$this->_has_changes = false;
1703
+		return $results;
1704
+	}
1705
+
1706
+
1707
+
1708
+	/**
1709
+	 * Updates the foreign key on related models objects pointing to this to have this model object's ID
1710
+	 * as their foreign key.  If the cached related model objects already exist in the db, saves them (so that the DB
1711
+	 * is consistent) Especially useful in case we JUST added this model object ot the database and we want to let its
1712
+	 * cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't
1713
+	 * saved it to the db. We also create a registration and don't save it to the DB, but we DO cache it on the
1714
+	 * transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether
1715
+	 * or not they exist in the DB (if they do, their DB records will be automatically updated)
1716
+	 *
1717
+	 * @return void
1718
+	 * @throws \EE_Error
1719
+	 */
1720
+	protected function _update_cached_related_model_objs_fks()
1721
+	{
1722
+		$model = $this->get_model();
1723
+		foreach ($model->relation_settings() as $relation_name => $relation_obj) {
1724
+			if ($relation_obj instanceof EE_Has_Many_Relation) {
1725
+				foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) {
1726
+					$fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to(
1727
+						$model->get_this_model_name()
1728
+					);
1729
+					$related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID());
1730
+					if ($related_model_obj_in_cache->ID()) {
1731
+						$related_model_obj_in_cache->save();
1732
+					}
1733
+				}
1734
+			}
1735
+		}
1736
+	}
1737
+
1738
+
1739
+
1740
+	/**
1741
+	 * Saves this model object and its NEW cached relations to the database.
1742
+	 * (Meaning, for now, IT DOES NOT WORK if the cached items already exist in the DB.
1743
+	 * In order for that to work, we would need to mark model objects as dirty/clean...
1744
+	 * because otherwise, there's a potential for infinite looping of saving
1745
+	 * Saves the cached related model objects, and ensures the relation between them
1746
+	 * and this object and properly setup
1747
+	 *
1748
+	 * @return int ID of new model object on save; 0 on failure+
1749
+	 * @throws \EE_Error
1750
+	 */
1751
+	public function save_new_cached_related_model_objs()
1752
+	{
1753
+		//make sure this has been saved
1754
+		if ( ! $this->ID()) {
1755
+			$id = $this->save();
1756
+		} else {
1757
+			$id = $this->ID();
1758
+		}
1759
+		//now save all the NEW cached model objects  (ie they don't exist in the DB)
1760
+		foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) {
1761
+			if ($this->_model_relations[$relationName]) {
1762
+				//is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation)
1763
+				//or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)?
1764
+				if ($relationObj instanceof EE_Belongs_To_Relation) {
1765
+					//add a relation to that relation type (which saves the appropriate thing in the process)
1766
+					//but ONLY if it DOES NOT exist in the DB
1767
+					/* @var $related_model_obj EE_Base_Class */
1768
+					$related_model_obj = $this->_model_relations[$relationName];
1769
+					//					if( ! $related_model_obj->ID()){
1770
+					$this->_add_relation_to($related_model_obj, $relationName);
1771
+					$related_model_obj->save_new_cached_related_model_objs();
1772
+					//					}
1773
+				} else {
1774
+					foreach ($this->_model_relations[$relationName] as $related_model_obj) {
1775
+						//add a relation to that relation type (which saves the appropriate thing in the process)
1776
+						//but ONLY if it DOES NOT exist in the DB
1777
+						//						if( ! $related_model_obj->ID()){
1778
+						$this->_add_relation_to($related_model_obj, $relationName);
1779
+						$related_model_obj->save_new_cached_related_model_objs();
1780
+						//						}
1781
+					}
1782
+				}
1783
+			}
1784
+		}
1785
+		return $id;
1786
+	}
1787
+
1788
+
1789
+
1790
+	/**
1791
+	 * for getting a model while instantiated.
1792
+	 *
1793
+	 * @return \EEM_Base | \EEM_CPT_Base
1794
+	 */
1795
+	public function get_model()
1796
+	{
1797
+		if( ! $this->_model){
1798
+			$modelName = self::_get_model_classname(get_class($this));
1799
+			$this->_model = self::_get_model_instance_with_name($modelName, $this->_timezone);
1800
+		} else {
1801
+			$this->_model->set_timezone($this->_timezone);
1802
+		}
1803
+
1804
+		return $this->_model;
1805
+	}
1806
+
1807
+
1808
+
1809
+	/**
1810
+	 * @param $props_n_values
1811
+	 * @param $classname
1812
+	 * @return mixed bool|EE_Base_Class|EEM_CPT_Base
1813
+	 * @throws \EE_Error
1814
+	 */
1815
+	protected static function _get_object_from_entity_mapper($props_n_values, $classname)
1816
+	{
1817
+		//TODO: will not work for Term_Relationships because they have no PK!
1818
+		$primary_id_ref = self::_get_primary_key_name($classname);
1819
+		if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) {
1820
+			$id = $props_n_values[$primary_id_ref];
1821
+			return self::_get_model($classname)->get_from_entity_map($id);
1822
+		}
1823
+		return false;
1824
+	}
1825
+
1826
+
1827
+
1828
+	/**
1829
+	 * This is called by child static "new_instance" method and we'll check to see if there is an existing db entry for
1830
+	 * the primary key (if present in incoming values). If there is a key in the incoming array that matches the
1831
+	 * primary key for the model AND it is not null, then we check the db. If there's a an object we return it.  If not
1832
+	 * we return false.
1833
+	 *
1834
+	 * @param  array  $props_n_values   incoming array of properties and their values
1835
+	 * @param  string $classname        the classname of the child class
1836
+	 * @param null    $timezone
1837
+	 * @param array   $date_formats     incoming date_formats in an array where the first value is the
1838
+	 *                                  date_format and the second value is the time format
1839
+	 * @return mixed (EE_Base_Class|bool)
1840
+	 * @throws \EE_Error
1841
+	 */
1842
+	protected static function _check_for_object($props_n_values, $classname, $timezone = null, $date_formats = array())
1843
+	{
1844
+		$existing = null;
1845
+		$model = self::_get_model($classname, $timezone);
1846
+		if ($model->has_primary_key_field()) {
1847
+			$primary_id_ref = self::_get_primary_key_name($classname);
1848
+			if (array_key_exists($primary_id_ref, $props_n_values)
1849
+				&& ! empty($props_n_values[$primary_id_ref])
1850
+			) {
1851
+				$existing = $model->get_one_by_ID(
1852
+					$props_n_values[$primary_id_ref]
1853
+				);
1854
+			}
1855
+		} elseif ($model->has_all_combined_primary_key_fields($props_n_values)) {
1856
+			//no primary key on this model, but there's still a matching item in the DB
1857
+			$existing = self::_get_model($classname, $timezone)->get_one_by_ID(
1858
+				self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values)
1859
+			);
1860
+		}
1861
+		if ($existing) {
1862
+			//set date formats if present before setting values
1863
+			if ( ! empty($date_formats) && is_array($date_formats)) {
1864
+				$existing->set_date_format($date_formats[0]);
1865
+				$existing->set_time_format($date_formats[1]);
1866
+			} else {
1867
+				//set default formats for date and time
1868
+				$existing->set_date_format(get_option('date_format'));
1869
+				$existing->set_time_format(get_option('time_format'));
1870
+			}
1871
+			foreach ($props_n_values as $property => $field_value) {
1872
+				$existing->set($property, $field_value);
1873
+			}
1874
+			return $existing;
1875
+		} else {
1876
+			return false;
1877
+		}
1878
+	}
1879
+
1880
+
1881
+
1882
+	/**
1883
+	 * Gets the EEM_*_Model for this class
1884
+	 *
1885
+	 * @access public now, as this is more convenient
1886
+	 * @param      $classname
1887
+	 * @param null $timezone
1888
+	 * @throws EE_Error
1889
+	 * @return EEM_Base
1890
+	 */
1891
+	protected static function _get_model($classname, $timezone = null)
1892
+	{
1893
+		//find model for this class
1894
+		if ( ! $classname) {
1895
+			throw new EE_Error(
1896
+				sprintf(
1897
+					__(
1898
+						"What were you thinking calling _get_model(%s)?? You need to specify the class name",
1899
+						"event_espresso"
1900
+					),
1901
+					$classname
1902
+				)
1903
+			);
1904
+		}
1905
+		$modelName = self::_get_model_classname($classname);
1906
+		return self::_get_model_instance_with_name($modelName, $timezone);
1907
+	}
1908
+
1909
+
1910
+
1911
+	/**
1912
+	 * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee)
1913
+	 *
1914
+	 * @param string $model_classname
1915
+	 * @param null   $timezone
1916
+	 * @return EEM_Base
1917
+	 */
1918
+	protected static function _get_model_instance_with_name($model_classname, $timezone = null)
1919
+	{
1920
+		$model_classname = str_replace('EEM_', '', $model_classname);
1921
+		$model = EE_Registry::instance()->load_model($model_classname);
1922
+		$model->set_timezone($timezone);
1923
+		return $model;
1924
+	}
1925
+
1926
+
1927
+
1928
+	/**
1929
+	 * If a model name is provided (eg Registration), gets the model classname for that model.
1930
+	 * Also works if a model class's classname is provided (eg EE_Registration).
1931
+	 *
1932
+	 * @param null $model_name
1933
+	 * @return string like EEM_Attendee
1934
+	 */
1935
+	private static function _get_model_classname($model_name = null)
1936
+	{
1937
+		if (strpos($model_name, "EE_") === 0) {
1938
+			$model_classname = str_replace("EE_", "EEM_", $model_name);
1939
+		} else {
1940
+			$model_classname = "EEM_" . $model_name;
1941
+		}
1942
+		return $model_classname;
1943
+	}
1944
+
1945
+
1946
+
1947
+	/**
1948
+	 * returns the name of the primary key attribute
1949
+	 *
1950
+	 * @param null $classname
1951
+	 * @throws EE_Error
1952
+	 * @return string
1953
+	 */
1954
+	protected static function _get_primary_key_name($classname = null)
1955
+	{
1956
+		if ( ! $classname) {
1957
+			throw new EE_Error(
1958
+				sprintf(
1959
+					__("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"),
1960
+					$classname
1961
+				)
1962
+			);
1963
+		}
1964
+		return self::_get_model($classname)->get_primary_key_field()->get_name();
1965
+	}
1966
+
1967
+
1968
+
1969
+	/**
1970
+	 * Gets the value of the primary key.
1971
+	 * If the object hasn't yet been saved, it should be whatever the model field's default was
1972
+	 * (eg, if this were the EE_Event class, look at the primary key field on EEM_Event and see what its default value
1973
+	 * is. Usually defaults for integer primary keys are 0; string primary keys are usually NULL).
1974
+	 *
1975
+	 * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string
1976
+	 * @throws \EE_Error
1977
+	 */
1978
+	public function ID()
1979
+	{
1980
+		$model = $this->get_model();
1981
+		//now that we know the name of the variable, use a variable variable to get its value and return its
1982
+		if ($model->has_primary_key_field()) {
1983
+			return $this->_fields[$model->primary_key_name()];
1984
+		} else {
1985
+			return $model->get_index_primary_key_string($this->_fields);
1986
+		}
1987
+	}
1988
+
1989
+
1990
+
1991
+	/**
1992
+	 * Adds a relationship to the specified EE_Base_Class object, given the relationship's name. Eg, if the current
1993
+	 * model is related to a group of events, the $relationName should be 'Event', and should be a key in the EE
1994
+	 * Model's $_model_relations array. If this model object doesn't exist in the DB, just caches the related thing
1995
+	 *
1996
+	 * @param mixed  $otherObjectModelObjectOrID       EE_Base_Class or the ID of the other object
1997
+	 * @param string $relationName                     eg 'Events','Question',etc.
1998
+	 *                                                 an attendee to a group, you also want to specify which role they
1999
+	 *                                                 will have in that group. So you would use this parameter to
2000
+	 *                                                 specify array('role-column-name'=>'role-id')
2001
+	 * @param array  $extra_join_model_fields_n_values You can optionally include an array of key=>value pairs that
2002
+	 *                                                 allow you to further constrict the relation to being added.
2003
+	 *                                                 However, keep in mind that the columns (keys) given must match a
2004
+	 *                                                 column on the JOIN table and currently only the HABTM models
2005
+	 *                                                 accept these additional conditions.  Also remember that if an
2006
+	 *                                                 exact match isn't found for these extra cols/val pairs, then a
2007
+	 *                                                 NEW row is created in the join table.
2008
+	 * @param null   $cache_id
2009
+	 * @throws EE_Error
2010
+	 * @return EE_Base_Class the object the relation was added to
2011
+	 */
2012
+	public function _add_relation_to(
2013
+		$otherObjectModelObjectOrID,
2014
+		$relationName,
2015
+		$extra_join_model_fields_n_values = array(),
2016
+		$cache_id = null
2017
+	) {
2018
+		$model = $this->get_model();
2019
+		//if this thing exists in the DB, save the relation to the DB
2020
+		if ($this->ID()) {
2021
+			$otherObject = $model
2022
+								->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName,
2023
+									$extra_join_model_fields_n_values);
2024
+			//clear cache so future get_many_related and get_first_related() return new results.
2025
+			$this->clear_cache($relationName, $otherObject, true);
2026
+			if ($otherObject instanceof EE_Base_Class) {
2027
+				$otherObject->clear_cache($model->get_this_model_name(), $this);
2028
+			}
2029
+		} else {
2030
+			//this thing doesn't exist in the DB,  so just cache it
2031
+			if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) {
2032
+				throw new EE_Error(sprintf(
2033
+					__('Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s',
2034
+						'event_espresso'),
2035
+					$otherObjectModelObjectOrID,
2036
+					get_class($this)
2037
+				));
2038
+			} else {
2039
+				$otherObject = $otherObjectModelObjectOrID;
2040
+			}
2041
+			$this->cache($relationName, $otherObjectModelObjectOrID, $cache_id);
2042
+		}
2043
+		if ($otherObject instanceof EE_Base_Class) {
2044
+			//fix the reciprocal relation too
2045
+			if ($otherObject->ID()) {
2046
+				//its saved so assumed relations exist in the DB, so we can just
2047
+				//clear the cache so future queries use the updated info in the DB
2048
+				$otherObject->clear_cache($model->get_this_model_name(), null, true);
2049
+			} else {
2050
+				//it's not saved, so it caches relations like this
2051
+				$otherObject->cache($model->get_this_model_name(), $this);
2052
+			}
2053
+		}
2054
+		return $otherObject;
2055
+	}
2056
+
2057
+
2058
+
2059
+	/**
2060
+	 * Removes a relationship to the specified EE_Base_Class object, given the relationships' name. Eg, if the current
2061
+	 * model is related to a group of events, the $relationName should be 'Events', and should be a key in the EE
2062
+	 * Model's $_model_relations array. If this model object doesn't exist in the DB, just removes the related thing
2063
+	 * from the cache
2064
+	 *
2065
+	 * @param mixed  $otherObjectModelObjectOrID
2066
+	 *                EE_Base_Class or the ID of the other object, OR an array key into the cache if this isn't saved
2067
+	 *                to the DB yet
2068
+	 * @param string $relationName
2069
+	 * @param array  $where_query
2070
+	 *                You can optionally include an array of key=>value pairs that allow you to further constrict the
2071
+	 *                relation to being added. However, keep in mind that the columns (keys) given must match a column
2072
+	 *                on the JOIN table and currently only the HABTM models accept these additional conditions. Also
2073
+	 *                remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is
2074
+	 *                created in the join table.
2075
+	 * @return EE_Base_Class the relation was removed from
2076
+	 * @throws \EE_Error
2077
+	 */
2078
+	public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array())
2079
+	{
2080
+		if ($this->ID()) {
2081
+			//if this exists in the DB, save the relation change to the DB too
2082
+			$otherObject = $this->get_model()
2083
+								->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName,
2084
+									$where_query);
2085
+			$this->clear_cache($relationName, $otherObject);
2086
+		} else {
2087
+			//this doesn't exist in the DB, just remove it from the cache
2088
+			$otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID);
2089
+		}
2090
+		if ($otherObject instanceof EE_Base_Class) {
2091
+			$otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
2092
+		}
2093
+		return $otherObject;
2094
+	}
2095
+
2096
+
2097
+
2098
+	/**
2099
+	 * Removes ALL the related things for the $relationName.
2100
+	 *
2101
+	 * @param string $relationName
2102
+	 * @param array  $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions)
2103
+	 * @return EE_Base_Class
2104
+	 * @throws \EE_Error
2105
+	 */
2106
+	public function _remove_relations($relationName, $where_query_params = array())
2107
+	{
2108
+		if ($this->ID()) {
2109
+			//if this exists in the DB, save the relation change to the DB too
2110
+			$otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params);
2111
+			$this->clear_cache($relationName, null, true);
2112
+		} else {
2113
+			//this doesn't exist in the DB, just remove it from the cache
2114
+			$otherObjects = $this->clear_cache($relationName, null, true);
2115
+		}
2116
+		if (is_array($otherObjects)) {
2117
+			foreach ($otherObjects as $otherObject) {
2118
+				$otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
2119
+			}
2120
+		}
2121
+		return $otherObjects;
2122
+	}
2123
+
2124
+
2125
+
2126
+	/**
2127
+	 * Gets all the related model objects of the specified type. Eg, if the current class if
2128
+	 * EE_Event, you could call $this->get_many_related('Registration') to get an array of all the
2129
+	 * EE_Registration objects which related to this event. Note: by default, we remove the "default query params"
2130
+	 * because we want to get even deleted items etc.
2131
+	 *
2132
+	 * @param string $relationName key in the model's _model_relations array
2133
+	 * @param array  $query_params like EEM_Base::get_all
2134
+	 * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys
2135
+	 * @throws \EE_Error
2136
+	 *                             or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if
2137
+	 *                             you want IDs
2138
+	 */
2139
+	public function get_many_related($relationName, $query_params = array())
2140
+	{
2141
+		if ($this->ID()) {
2142
+			//this exists in the DB, so get the related things from either the cache or the DB
2143
+			//if there are query parameters, forget about caching the related model objects.
2144
+			if ($query_params) {
2145
+				$related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
2146
+			} else {
2147
+				//did we already cache the result of this query?
2148
+				$cached_results = $this->get_all_from_cache($relationName);
2149
+				if ( ! $cached_results) {
2150
+					$related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
2151
+					//if no query parameters were passed, then we got all the related model objects
2152
+					//for that relation. We can cache them then.
2153
+					foreach ($related_model_objects as $related_model_object) {
2154
+						$this->cache($relationName, $related_model_object);
2155
+					}
2156
+				} else {
2157
+					$related_model_objects = $cached_results;
2158
+				}
2159
+			}
2160
+		} else {
2161
+			//this doesn't exist in the DB, so just get the related things from the cache
2162
+			$related_model_objects = $this->get_all_from_cache($relationName);
2163
+		}
2164
+		return $related_model_objects;
2165
+	}
2166
+
2167
+
2168
+
2169
+	/**
2170
+	 * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default,
2171
+	 * unless otherwise specified in the $query_params
2172
+	 *
2173
+	 * @param string $relation_name  model_name like 'Event', or 'Registration'
2174
+	 * @param array  $query_params   like EEM_Base::get_all's
2175
+	 * @param string $field_to_count name of field to count by. By default, uses primary key
2176
+	 * @param bool   $distinct       if we want to only count the distinct values for the column then you can trigger
2177
+	 *                               that by the setting $distinct to TRUE;
2178
+	 * @return int
2179
+	 */
2180
+	public function count_related($relation_name, $query_params = array(), $field_to_count = null, $distinct = false)
2181
+	{
2182
+		return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct);
2183
+	}
2184
+
2185
+
2186
+
2187
+	/**
2188
+	 * Instead of getting the related model objects, simply sums up the values of the specified field.
2189
+	 * Note: ignores default_where_conditions by default, unless otherwise specified in the $query_params
2190
+	 *
2191
+	 * @param string $relation_name model_name like 'Event', or 'Registration'
2192
+	 * @param array  $query_params  like EEM_Base::get_all's
2193
+	 * @param string $field_to_sum  name of field to count by.
2194
+	 *                              By default, uses primary key (which doesn't make much sense, so you should probably
2195
+	 *                              change it)
2196
+	 * @return int
2197
+	 */
2198
+	public function sum_related($relation_name, $query_params = array(), $field_to_sum = null)
2199
+	{
2200
+		return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum);
2201
+	}
2202
+
2203
+
2204
+
2205
+	/**
2206
+	 * Gets the first (ie, one) related model object of the specified type.
2207
+	 *
2208
+	 * @param string $relationName key in the model's _model_relations array
2209
+	 * @param array  $query_params like EEM_Base::get_all
2210
+	 * @return EE_Base_Class (not an array, a single object)
2211
+	 * @throws \EE_Error
2212
+	 */
2213
+	public function get_first_related($relationName, $query_params = array())
2214
+	{
2215
+		$model = $this->get_model();
2216
+		if ($this->ID()) {//this exists in the DB, get from the cache OR the DB
2217
+			//if they've provided some query parameters, don't bother trying to cache the result
2218
+			//also make sure we're not caching the result of get_first_related
2219
+			//on a relation which should have an array of objects (because the cache might have an array of objects)
2220
+			if ($query_params
2221
+				|| ! $model->related_settings_for($relationName)
2222
+					 instanceof
2223
+					 EE_Belongs_To_Relation
2224
+			) {
2225
+				$related_model_object = $model->get_first_related($this, $relationName, $query_params);
2226
+			} else {
2227
+				//first, check if we've already cached the result of this query
2228
+				$cached_result = $this->get_one_from_cache($relationName);
2229
+				if ( ! $cached_result) {
2230
+					$related_model_object = $model->get_first_related($this, $relationName, $query_params);
2231
+					$this->cache($relationName, $related_model_object);
2232
+				} else {
2233
+					$related_model_object = $cached_result;
2234
+				}
2235
+			}
2236
+		} else {
2237
+			$related_model_object = null;
2238
+			//this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might
2239
+			if ($model->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) {
2240
+				$related_model_object = $model->get_first_related($this, $relationName, $query_params);
2241
+			}
2242
+			//this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object
2243
+			if ( ! $related_model_object) {
2244
+				$related_model_object = $this->get_one_from_cache($relationName);
2245
+			}
2246
+		}
2247
+		return $related_model_object;
2248
+	}
2249
+
2250
+
2251
+
2252
+	/**
2253
+	 * Does a delete on all related objects of type $relationName and removes
2254
+	 * the current model object's relation to them. If they can't be deleted (because
2255
+	 * of blocking related model objects) does nothing. If the related model objects are
2256
+	 * soft-deletable, they will be soft-deleted regardless of related blocking model objects.
2257
+	 * If this model object doesn't exist yet in the DB, just removes its related things
2258
+	 *
2259
+	 * @param string $relationName
2260
+	 * @param array  $query_params like EEM_Base::get_all's
2261
+	 * @return int how many deleted
2262
+	 * @throws \EE_Error
2263
+	 */
2264
+	public function delete_related($relationName, $query_params = array())
2265
+	{
2266
+		if ($this->ID()) {
2267
+			$count = $this->get_model()->delete_related($this, $relationName, $query_params);
2268
+		} else {
2269
+			$count = count($this->get_all_from_cache($relationName));
2270
+			$this->clear_cache($relationName, null, true);
2271
+		}
2272
+		return $count;
2273
+	}
2274
+
2275
+
2276
+
2277
+	/**
2278
+	 * Does a hard delete (ie, removes the DB row) on all related objects of type $relationName and removes
2279
+	 * the current model object's relation to them. If they can't be deleted (because
2280
+	 * of blocking related model objects) just does a soft delete on it instead, if possible.
2281
+	 * If the related thing isn't a soft-deletable model object, this function is identical
2282
+	 * to delete_related(). If this model object doesn't exist in the DB, just remove its related things
2283
+	 *
2284
+	 * @param string $relationName
2285
+	 * @param array  $query_params like EEM_Base::get_all's
2286
+	 * @return int how many deleted (including those soft deleted)
2287
+	 * @throws \EE_Error
2288
+	 */
2289
+	public function delete_related_permanently($relationName, $query_params = array())
2290
+	{
2291
+		if ($this->ID()) {
2292
+			$count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params);
2293
+		} else {
2294
+			$count = count($this->get_all_from_cache($relationName));
2295
+		}
2296
+		$this->clear_cache($relationName, null, true);
2297
+		return $count;
2298
+	}
2299
+
2300
+
2301
+
2302
+	/**
2303
+	 * is_set
2304
+	 * Just a simple utility function children can use for checking if property exists
2305
+	 *
2306
+	 * @access  public
2307
+	 * @param  string $field_name property to check
2308
+	 * @return bool                              TRUE if existing,FALSE if not.
2309
+	 */
2310
+	public function is_set($field_name)
2311
+	{
2312
+		return isset($this->_fields[$field_name]);
2313
+	}
2314
+
2315
+
2316
+
2317
+	/**
2318
+	 * Just a simple utility function children can use for checking if property (or properties) exists and throwing an
2319
+	 * EE_Error exception if they don't
2320
+	 *
2321
+	 * @param  mixed (string|array) $properties properties to check
2322
+	 * @throws EE_Error
2323
+	 * @return bool                              TRUE if existing, throw EE_Error if not.
2324
+	 */
2325
+	protected function _property_exists($properties)
2326
+	{
2327
+		foreach ((array)$properties as $property_name) {
2328
+			//first make sure this property exists
2329
+			if ( ! $this->_fields[$property_name]) {
2330
+				throw new EE_Error(
2331
+					sprintf(
2332
+						__(
2333
+							'Trying to retrieve a non-existent property (%s).  Double check the spelling please',
2334
+							'event_espresso'
2335
+						),
2336
+						$property_name
2337
+					)
2338
+				);
2339
+			}
2340
+		}
2341
+		return true;
2342
+	}
2343
+
2344
+
2345
+
2346
+	/**
2347
+	 * This simply returns an array of model fields for this object
2348
+	 *
2349
+	 * @return array
2350
+	 * @throws \EE_Error
2351
+	 */
2352
+	public function model_field_array()
2353
+	{
2354
+		$fields = $this->get_model()->field_settings(false);
2355
+		$properties = array();
2356
+		//remove prepended underscore
2357
+		foreach ($fields as $field_name => $settings) {
2358
+			$properties[$field_name] = $this->get($field_name);
2359
+		}
2360
+		return $properties;
2361
+	}
2362
+
2363
+
2364
+
2365
+	/**
2366
+	 * Very handy general function to allow for plugins to extend any child of EE_Base_Class.
2367
+	 * If a method is called on a child of EE_Base_Class that doesn't exist, this function is called
2368
+	 * (http://www.garfieldtech.com/blog/php-magic-call) and passed the method's name and arguments. Instead of
2369
+	 * requiring a plugin to extend the EE_Base_Class (which works fine is there's only 1 plugin, but when will that
2370
+	 * happen?) they can add a hook onto 'filters_hook_espresso__{className}__{methodName}' (eg,
2371
+	 * filters_hook_espresso__EE_Answer__my_great_function) and accepts 2 arguments: the object on which the function
2372
+	 * was called, and an array of the original arguments passed to the function. Whatever their callback function
2373
+	 * returns will be returned by this function. Example: in functions.php (or in a plugin):
2374
+	 * add_filter('FHEE__EE_Answer__my_callback','my_callback',10,3); function
2375
+	 * my_callback($previousReturnValue,EE_Base_Class $object,$argsArray){
2376
+	 * $returnString= "you called my_callback! and passed args:".implode(",",$argsArray);
2377
+	 *        return $previousReturnValue.$returnString;
2378
+	 * }
2379
+	 * require('EE_Answer.class.php');
2380
+	 * $answer= EE_Answer::new_instance(array('REG_ID' => 2,'QST_ID' => 3,'ANS_value' => The answer is 42'));
2381
+	 * echo $answer->my_callback('monkeys',100);
2382
+	 * //will output "you called my_callback! and passed args:monkeys,100"
2383
+	 *
2384
+	 * @param string $methodName name of method which was called on a child of EE_Base_Class, but which
2385
+	 * @param array  $args       array of original arguments passed to the function
2386
+	 * @throws EE_Error
2387
+	 * @return mixed whatever the plugin which calls add_filter decides
2388
+	 */
2389
+	public function __call($methodName, $args)
2390
+	{
2391
+		$className = get_class($this);
2392
+		$tagName = "FHEE__{$className}__{$methodName}";
2393
+		if ( ! has_filter($tagName)) {
2394
+			throw new EE_Error(
2395
+				sprintf(
2396
+					__(
2397
+						"Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}",
2398
+						"event_espresso"
2399
+					),
2400
+					$methodName,
2401
+					$className,
2402
+					$tagName
2403
+				)
2404
+			);
2405
+		}
2406
+		return apply_filters($tagName, null, $this, $args);
2407
+	}
2408
+
2409
+
2410
+
2411
+	/**
2412
+	 * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value.
2413
+	 * A $previous_value can be specified in case there are many meta rows with the same key
2414
+	 *
2415
+	 * @param string $meta_key
2416
+	 * @param mixed  $meta_value
2417
+	 * @param mixed  $previous_value
2418
+	 * @return bool|int # of records updated (or BOOLEAN if we actually ended up inserting the extra meta row)
2419
+	 * @throws \EE_Error
2420
+	 * NOTE: if the values haven't changed, returns 0
2421
+	 */
2422
+	public function update_extra_meta($meta_key, $meta_value, $previous_value = null)
2423
+	{
2424
+		$query_params = array(
2425
+			array(
2426
+				'EXM_key'  => $meta_key,
2427
+				'OBJ_ID'   => $this->ID(),
2428
+				'EXM_type' => $this->get_model()->get_this_model_name(),
2429
+			),
2430
+		);
2431
+		if ($previous_value !== null) {
2432
+			$query_params[0]['EXM_value'] = $meta_value;
2433
+		}
2434
+		$existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params);
2435
+		if ( ! $existing_rows_like_that) {
2436
+			return $this->add_extra_meta($meta_key, $meta_value);
2437
+		}
2438
+		foreach ($existing_rows_like_that as $existing_row) {
2439
+			$existing_row->save(array('EXM_value' => $meta_value));
2440
+		}
2441
+		return count($existing_rows_like_that);
2442
+	}
2443
+
2444
+
2445
+
2446
+	/**
2447
+	 * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check
2448
+	 * no other extra meta for this model object have the same key. Returns TRUE if the
2449
+	 * extra meta row was entered, false if not
2450
+	 *
2451
+	 * @param string  $meta_key
2452
+	 * @param mixed   $meta_value
2453
+	 * @param boolean $unique
2454
+	 * @return boolean
2455
+	 * @throws \EE_Error
2456
+	 */
2457
+	public function add_extra_meta($meta_key, $meta_value, $unique = false)
2458
+	{
2459
+		if ($unique) {
2460
+			$existing_extra_meta = EEM_Extra_Meta::instance()->get_one(
2461
+				array(
2462
+					array(
2463
+						'EXM_key'  => $meta_key,
2464
+						'OBJ_ID'   => $this->ID(),
2465
+						'EXM_type' => $this->get_model()->get_this_model_name(),
2466
+					),
2467
+				)
2468
+			);
2469
+			if ($existing_extra_meta) {
2470
+				return false;
2471
+			}
2472
+		}
2473
+		$new_extra_meta = EE_Extra_Meta::new_instance(
2474
+			array(
2475
+				'EXM_key'   => $meta_key,
2476
+				'EXM_value' => $meta_value,
2477
+				'OBJ_ID'    => $this->ID(),
2478
+				'EXM_type'  => $this->get_model()->get_this_model_name(),
2479
+			)
2480
+		);
2481
+		$new_extra_meta->save();
2482
+		return true;
2483
+	}
2484
+
2485
+
2486
+
2487
+	/**
2488
+	 * Deletes all the extra meta rows for this record as specified by key. If $meta_value
2489
+	 * is specified, only deletes extra meta records with that value.
2490
+	 *
2491
+	 * @param string $meta_key
2492
+	 * @param mixed  $meta_value
2493
+	 * @return int number of extra meta rows deleted
2494
+	 * @throws \EE_Error
2495
+	 */
2496
+	public function delete_extra_meta($meta_key, $meta_value = null)
2497
+	{
2498
+		$query_params = array(
2499
+			array(
2500
+				'EXM_key'  => $meta_key,
2501
+				'OBJ_ID'   => $this->ID(),
2502
+				'EXM_type' => $this->get_model()->get_this_model_name(),
2503
+			),
2504
+		);
2505
+		if ($meta_value !== null) {
2506
+			$query_params[0]['EXM_value'] = $meta_value;
2507
+		}
2508
+		return EEM_Extra_Meta::instance()->delete($query_params);
2509
+	}
2510
+
2511
+
2512
+
2513
+	/**
2514
+	 * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise
2515
+	 * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation.
2516
+	 * You can specify $default is case you haven't found the extra meta
2517
+	 *
2518
+	 * @param string  $meta_key
2519
+	 * @param boolean $single
2520
+	 * @param mixed   $default if we don't find anything, what should we return?
2521
+	 * @return mixed single value if $single; array if ! $single
2522
+	 * @throws \EE_Error
2523
+	 */
2524
+	public function get_extra_meta($meta_key, $single = false, $default = null)
2525
+	{
2526
+		if ($single) {
2527
+			$result = $this->get_first_related('Extra_Meta', array(array('EXM_key' => $meta_key)));
2528
+			if ($result instanceof EE_Extra_Meta) {
2529
+				return $result->value();
2530
+			}
2531
+		} else {
2532
+			$results = $this->get_many_related('Extra_Meta', array(array('EXM_key' => $meta_key)));
2533
+			if ($results) {
2534
+				$values = array();
2535
+				foreach ($results as $result) {
2536
+					if ($result instanceof EE_Extra_Meta) {
2537
+						$values[$result->ID()] = $result->value();
2538
+					}
2539
+				}
2540
+				return $values;
2541
+			}
2542
+		}
2543
+		//if nothing discovered yet return default.
2544
+		return apply_filters(
2545
+			'FHEE__EE_Base_Class__get_extra_meta__default_value',
2546
+			$default,
2547
+			$meta_key,
2548
+			$single,
2549
+			$this
2550
+			);
2551
+	}
2552
+
2553
+
2554
+
2555
+	/**
2556
+	 * Returns a simple array of all the extra meta associated with this model object.
2557
+	 * If $one_of_each_key is true (Default), it will be an array of simple key-value pairs, keys being the
2558
+	 * extra meta's key, and teh value being its value. However, if there are duplicate extra meta rows with
2559
+	 * the same key, only one will be used. (eg array('foo'=>'bar','monkey'=>123))
2560
+	 * If $one_of_each_key is false, it will return an array with the top-level keys being
2561
+	 * the extra meta keys, but their values are also arrays, which have the extra-meta's ID as their sub-key, and
2562
+	 * finally the extra meta's value as each sub-value. (eg
2563
+	 * array('foo'=>array(1=>'bar',2=>'bill'),'monkey'=>array(3=>123)))
2564
+	 *
2565
+	 * @param boolean $one_of_each_key
2566
+	 * @return array
2567
+	 * @throws \EE_Error
2568
+	 */
2569
+	public function all_extra_meta_array($one_of_each_key = true)
2570
+	{
2571
+		$return_array = array();
2572
+		if ($one_of_each_key) {
2573
+			$extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by' => 'EXM_key'));
2574
+			foreach ($extra_meta_objs as $extra_meta_obj) {
2575
+				if ($extra_meta_obj instanceof EE_Extra_Meta) {
2576
+					$return_array[$extra_meta_obj->key()] = $extra_meta_obj->value();
2577
+				}
2578
+			}
2579
+		} else {
2580
+			$extra_meta_objs = $this->get_many_related('Extra_Meta');
2581
+			foreach ($extra_meta_objs as $extra_meta_obj) {
2582
+				if ($extra_meta_obj instanceof EE_Extra_Meta) {
2583
+					if ( ! isset($return_array[$extra_meta_obj->key()])) {
2584
+						$return_array[$extra_meta_obj->key()] = array();
2585
+					}
2586
+					$return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value();
2587
+				}
2588
+			}
2589
+		}
2590
+		return $return_array;
2591
+	}
2592
+
2593
+
2594
+
2595
+	/**
2596
+	 * Gets a pretty nice displayable nice for this model object. Often overridden
2597
+	 *
2598
+	 * @return string
2599
+	 * @throws \EE_Error
2600
+	 */
2601
+	public function name()
2602
+	{
2603
+		//find a field that's not a text field
2604
+		$field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base');
2605
+		if ($field_we_can_use) {
2606
+			return $this->get($field_we_can_use->get_name());
2607
+		} else {
2608
+			$first_few_properties = $this->model_field_array();
2609
+			$first_few_properties = array_slice($first_few_properties, 0, 3);
2610
+			$name_parts = array();
2611
+			foreach ($first_few_properties as $name => $value) {
2612
+				$name_parts[] = "$name:$value";
2613
+			}
2614
+			return implode(",", $name_parts);
2615
+		}
2616
+	}
2617
+
2618
+
2619
+
2620
+	/**
2621
+	 * in_entity_map
2622
+	 * Checks if this model object has been proven to already be in the entity map
2623
+	 *
2624
+	 * @return boolean
2625
+	 * @throws \EE_Error
2626
+	 */
2627
+	public function in_entity_map()
2628
+	{
2629
+		if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) {
2630
+			//well, if we looked, did we find it in the entity map?
2631
+			return true;
2632
+		} else {
2633
+			return false;
2634
+		}
2635
+	}
2636
+
2637
+
2638
+
2639
+	/**
2640
+	 * refresh_from_db
2641
+	 * Makes sure the fields and values on this model object are in-sync with what's in the database.
2642
+	 *
2643
+	 * @throws EE_Error if this model object isn't in the entity mapper (because then you should
2644
+	 * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE
2645
+	 */
2646
+	public function refresh_from_db()
2647
+	{
2648
+		if ($this->ID() && $this->in_entity_map()) {
2649
+			$this->get_model()->refresh_entity_map_from_db($this->ID());
2650
+		} else {
2651
+			//if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database)
2652
+			//if it has an ID but it's not in the map, and you're asking me to refresh it
2653
+			//that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's
2654
+			//absolutely nothing in it for this ID
2655
+			if (WP_DEBUG) {
2656
+				throw new EE_Error(
2657
+					sprintf(
2658
+						__('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.',
2659
+							'event_espresso'),
2660
+						$this->ID(),
2661
+						get_class($this->get_model()) . '::instance()->add_to_entity_map()',
2662
+						get_class($this->get_model()) . '::instance()->refresh_entity_map()'
2663
+					)
2664
+				);
2665
+			}
2666
+		}
2667
+	}
2668
+
2669
+
2670
+
2671
+	/**
2672
+	 * Because some other plugins, like Advanced Cron Manager, expect all objects to have this method
2673
+	 * (probably a bad assumption they have made, oh well)
2674
+	 *
2675
+	 * @return string
2676
+	 */
2677
+	public function __toString()
2678
+	{
2679
+		try {
2680
+			return sprintf('%s (%s)', $this->name(), $this->ID());
2681
+		} catch (Exception $e) {
2682
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
2683
+			return '';
2684
+		}
2685
+	}
2686
+
2687
+
2688
+
2689
+	/**
2690
+	 * Clear related model objects if they're already in the DB, because otherwise when we
2691
+	 * UN-serialize this model object we'll need to be careful to add them to the entity map.
2692
+	 * This means if we have made changes to those related model objects, and want to unserialize
2693
+	 * the this model object on a subsequent request, changes to those related model objects will be lost.
2694
+	 * Instead, those related model objects should be directly serialized and stored.
2695
+	 * Eg, the following won't work:
2696
+	 * $reg = EEM_Registration::instance()->get_one_by_ID( 123 );
2697
+	 * $att = $reg->attendee();
2698
+	 * $att->set( 'ATT_fname', 'Dirk' );
2699
+	 * update_option( 'my_option', serialize( $reg ) );
2700
+	 * //END REQUEST
2701
+	 * //START NEXT REQUEST
2702
+	 * $reg = get_option( 'my_option' );
2703
+	 * $reg->attendee()->save();
2704
+	 * And would need to be replace with:
2705
+	 * $reg = EEM_Registration::instance()->get_one_by_ID( 123 );
2706
+	 * $att = $reg->attendee();
2707
+	 * $att->set( 'ATT_fname', 'Dirk' );
2708
+	 * update_option( 'my_option', serialize( $reg ) );
2709
+	 * //END REQUEST
2710
+	 * //START NEXT REQUEST
2711
+	 * $att = get_option( 'my_option' );
2712
+	 * $att->save();
2713
+	 *
2714
+	 * @return array
2715
+	 * @throws \EE_Error
2716
+	 */
2717
+	public function __sleep()
2718
+	{
2719
+		$model = $this->get_model();
2720
+		foreach ($model->relation_settings() as $relation_name => $relation_obj) {
2721
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
2722
+				$classname = 'EE_' . $model->get_this_model_name();
2723
+				if (
2724
+					$this->get_one_from_cache($relation_name) instanceof $classname
2725
+					&& $this->get_one_from_cache($relation_name)->ID()
2726
+				) {
2727
+					$this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID());
2728
+				}
2729
+			}
2730
+		}
2731
+		$this->_props_n_values_provided_in_constructor = array();
2732
+		$properties_to_serialize = get_object_vars($this);
2733
+		//don't serialize the model. It's big and that risks recursion
2734
+		unset($properties_to_serialize['_model']);
2735
+		return array_keys($properties_to_serialize);
2736
+	}
2737
+
2738
+
2739
+
2740
+	/**
2741
+	 * restore _props_n_values_provided_in_constructor
2742
+	 * PLZ NOTE: this will reset the array to whatever fields values were present prior to serialization,
2743
+	 * and therefore should NOT be used to determine if state change has occurred since initial construction.
2744
+	 * At best, you would only be able to detect if state change has occurred during THIS request.
2745
+	 */
2746
+	public function __wakeup()
2747
+	{
2748
+		$this->_props_n_values_provided_in_constructor = $this->_fields;
2749
+	}
2750 2750
 
2751 2751
 
2752 2752
 
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -155,8 +155,8 @@  discard block
 block discarded – undo
155 155
             list($this->_dt_frmt, $this->_tm_frmt) = $date_formats;
156 156
         } else {
157 157
             //set default formats for date and time
158
-            $this->_dt_frmt = (string)get_option('date_format', 'Y-m-d');
159
-            $this->_tm_frmt = (string)get_option('time_format', 'g:i a');
158
+            $this->_dt_frmt = (string) get_option('date_format', 'Y-m-d');
159
+            $this->_tm_frmt = (string) get_option('time_format', 'g:i a');
160 160
         }
161 161
         //if db model is instantiating
162 162
         if ($bydb) {
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
      */
479 479
     public function get_format($full = true)
480 480
     {
481
-        return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt);
481
+        return $full ? $this->_dt_frmt.' '.$this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt);
482 482
     }
483 483
 
484 484
 
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
         $model = $this->get_model();
588 588
         $model->field_settings_for($fieldname);
589 589
         $cache_type = $pretty ? 'pretty' : 'standard';
590
-        $cache_type .= ! empty($extra_cache_ref) ? '_' . $extra_cache_ref : '';
590
+        $cache_type .= ! empty($extra_cache_ref) ? '_'.$extra_cache_ref : '';
591 591
         if (isset($this->_cached_properties[$fieldname][$cache_type])) {
592 592
             return $this->_cached_properties[$fieldname][$cache_type];
593 593
         }
@@ -814,7 +814,7 @@  discard block
 block discarded – undo
814 814
         $current_cache_id = ''
815 815
     ) {
816 816
         // verify that incoming object is of the correct type
817
-        $obj_class = 'EE_' . $relationName;
817
+        $obj_class = 'EE_'.$relationName;
818 818
         if ($newly_saved_object instanceof $obj_class) {
819 819
             /* @type EE_Base_Class $newly_saved_object */
820 820
             // now get the type of relation
@@ -1153,7 +1153,7 @@  discard block
 block discarded – undo
1153 1153
      */
1154 1154
     public function get_f($field_name)
1155 1155
     {
1156
-        return (string)$this->get_pretty($field_name,'form_input');
1156
+        return (string) $this->get_pretty($field_name, 'form_input');
1157 1157
     }
1158 1158
 
1159 1159
 
@@ -1310,7 +1310,7 @@  discard block
 block discarded – undo
1310 1310
      */
1311 1311
     public function get_i18n_datetime($field_name, $format = '')
1312 1312
     {
1313
-        $format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format;
1313
+        $format = empty($format) ? $this->_dt_frmt.' '.$this->_tm_frmt : $format;
1314 1314
         return date_i18n(
1315 1315
             $format,
1316 1316
             EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone)
@@ -1448,8 +1448,8 @@  discard block
 block discarded – undo
1448 1448
         }
1449 1449
         $original_timezone = $this->_timezone;
1450 1450
         $this->set_timezone($timezone);
1451
-        $fn = (array)$field_name;
1452
-        $args = array_merge($fn, (array)$args);
1451
+        $fn = (array) $field_name;
1452
+        $args = array_merge($fn, (array) $args);
1453 1453
         if ( ! method_exists($this, $callback)) {
1454 1454
             throw new EE_Error(
1455 1455
                 sprintf(
@@ -1461,8 +1461,8 @@  discard block
 block discarded – undo
1461 1461
                 )
1462 1462
             );
1463 1463
         }
1464
-        $args = (array)$args;
1465
-        $return = $prepend . call_user_func_array(array($this, $callback), $args) . $append;
1464
+        $args = (array) $args;
1465
+        $return = $prepend.call_user_func_array(array($this, $callback), $args).$append;
1466 1466
         $this->set_timezone($original_timezone);
1467 1467
         return $return;
1468 1468
     }
@@ -1601,14 +1601,14 @@  discard block
 block discarded – undo
1601 1601
          * @param array         $set_cols_n_values
1602 1602
          * @param EE_Base_Class $model_object
1603 1603
          */
1604
-        $set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values,
1604
+        $set_cols_n_values = (array) apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values,
1605 1605
             $this);
1606 1606
         //set attributes as provided in $set_cols_n_values
1607 1607
         foreach ($set_cols_n_values as $column => $value) {
1608 1608
             $this->set($column, $value);
1609 1609
         }
1610 1610
         // no changes ? then don't do anything
1611
-        if (! $this->_has_changes && $this->ID() && $model->get_primary_key_field()->is_auto_increment()) {
1611
+        if ( ! $this->_has_changes && $this->ID() && $model->get_primary_key_field()->is_auto_increment()) {
1612 1612
             return 0;
1613 1613
         }
1614 1614
         /**
@@ -1660,8 +1660,8 @@  discard block
 block discarded – undo
1660 1660
                                 __('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s',
1661 1661
                                     'event_espresso'),
1662 1662
                                 get_class($this),
1663
-                                get_class($model) . '::instance()->add_to_entity_map()',
1664
-                                get_class($model) . '::instance()->get_one_by_ID()',
1663
+                                get_class($model).'::instance()->add_to_entity_map()',
1664
+                                get_class($model).'::instance()->get_one_by_ID()',
1665 1665
                                 '<br />'
1666 1666
                             )
1667 1667
                         );
@@ -1794,7 +1794,7 @@  discard block
 block discarded – undo
1794 1794
      */
1795 1795
     public function get_model()
1796 1796
     {
1797
-        if( ! $this->_model){
1797
+        if ( ! $this->_model) {
1798 1798
             $modelName = self::_get_model_classname(get_class($this));
1799 1799
             $this->_model = self::_get_model_instance_with_name($modelName, $this->_timezone);
1800 1800
         } else {
@@ -1937,7 +1937,7 @@  discard block
 block discarded – undo
1937 1937
         if (strpos($model_name, "EE_") === 0) {
1938 1938
             $model_classname = str_replace("EE_", "EEM_", $model_name);
1939 1939
         } else {
1940
-            $model_classname = "EEM_" . $model_name;
1940
+            $model_classname = "EEM_".$model_name;
1941 1941
         }
1942 1942
         return $model_classname;
1943 1943
     }
@@ -2324,7 +2324,7 @@  discard block
 block discarded – undo
2324 2324
      */
2325 2325
     protected function _property_exists($properties)
2326 2326
     {
2327
-        foreach ((array)$properties as $property_name) {
2327
+        foreach ((array) $properties as $property_name) {
2328 2328
             //first make sure this property exists
2329 2329
             if ( ! $this->_fields[$property_name]) {
2330 2330
                 throw new EE_Error(
@@ -2658,8 +2658,8 @@  discard block
 block discarded – undo
2658 2658
                         __('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.',
2659 2659
                             'event_espresso'),
2660 2660
                         $this->ID(),
2661
-                        get_class($this->get_model()) . '::instance()->add_to_entity_map()',
2662
-                        get_class($this->get_model()) . '::instance()->refresh_entity_map()'
2661
+                        get_class($this->get_model()).'::instance()->add_to_entity_map()',
2662
+                        get_class($this->get_model()).'::instance()->refresh_entity_map()'
2663 2663
                     )
2664 2664
                 );
2665 2665
             }
@@ -2719,7 +2719,7 @@  discard block
 block discarded – undo
2719 2719
         $model = $this->get_model();
2720 2720
         foreach ($model->relation_settings() as $relation_name => $relation_obj) {
2721 2721
             if ($relation_obj instanceof EE_Belongs_To_Relation) {
2722
-                $classname = 'EE_' . $model->get_this_model_name();
2722
+                $classname = 'EE_'.$model->get_this_model_name();
2723 2723
                 if (
2724 2724
                     $this->get_one_from_cache($relation_name) instanceof $classname
2725 2725
                     && $this->get_one_from_cache($relation_name)->ID()
Please login to merge, or discard this patch.
core/libraries/messages/data_class/EE_Messages_incoming_data.core.php 2 patches
Indentation   +515 added lines, -515 removed lines patch added patch discarded remove patch
@@ -20,521 +20,521 @@
 block discarded – undo
20 20
 {
21 21
 
22 22
 
23
-    /**
24
-     * user id for logged in user when data collected
25
-     *
26
-     * @var string $user_id
27
-     */
28
-    public $user_id;
29
-
30
-    /**
31
-     * IP Address of browser used
32
-     *
33
-     * @var string $ip_address
34
-     */
35
-    public $ip_address;
36
-
37
-    /**
38
-     * browser
39
-     *
40
-     * @var string $user_agent
41
-     */
42
-    public $user_agent;
43
-
44
-    /**
45
-     * Unix timestamp
46
-     *
47
-     * @var string $init_access
48
-     */
49
-    public $init_access;
50
-
51
-    /**
52
-     * Unix timestamp
53
-     *
54
-     * @var string $last_access
55
-     */
56
-    public $last_access;
57
-
58
-    /**
59
-     * The registrations details from the cart
60
-     *
61
-     * @var array $reg_info
62
-     */
63
-    public $reg_info;
64
-
65
-    /**
66
-     * Some data handlers can set what reg status all the registrations are filtered by.
67
-     * The status should match a EEM_Registration status constant.
68
-     *
69
-     * @var string $filtered_reg_status
70
-     */
71
-    public $filtered_reg_status;
72
-
73
-    /**
74
-     * will hold an array of events assembled from $reg_info
75
-     *
76
-     * @var EE_Event[] $events
77
-     */
78
-    public $events;
79
-
80
-    /**
81
-     * holds an array of datetimes assembled from the incoming data.
82
-     *
83
-     * @var EE_Datetime[] $datetimes
84
-     */
85
-    public $datetimes;
86
-
87
-    /**
88
-     * holds an array of tickets assembled from the incoming data.
89
-     *
90
-     * @var EE_Ticket[] $tickets
91
-     */
92
-    public $tickets;
93
-
94
-    /**
95
-     * holds an array with a key of parent line item and values are an array of children of that line item.
96
-     *
97
-     * @since 4.5.0
98
-     * @var EE_Line_Item[] $line_items_with_children
99
-     */
100
-    public $line_items_with_children;
101
-
102
-    /**
103
-     * will hold an array of attendees assembled from the $reg_info
104
-     *
105
-     * @var EE_Attendee[] $attendees
106
-     */
107
-    public $attendees;
108
-
109
-    /**
110
-     * will hold an array of cached registration objects and info assembled from reg_info
111
-     *
112
-     * @var array $registrations
113
-     */
114
-    public $registrations;
115
-
116
-    /**
117
-     * will hold an array of answers assembled from the $reg_info
118
-     *
119
-     * @var EE_Answer[] $answers
120
-     */
121
-    public $answers;
122
-
123
-    /**
124
-     * will hold an array of questions assembled from the $reg_info (indexed by Answer ID);
125
-     *
126
-     * @var EE_Question[] $questions
127
-     */
128
-    public $questions;
129
-
130
-    /**
131
-     * Will hold billing data assembled from $billing_info (if present)
132
-     *
133
-     * @var mixed (array|null) $billing
134
-     */
135
-    public $billing;
136
-
137
-    /**
138
-     * The total amount of tax for the transaction
139
-     *
140
-     * @var float $taxes
141
-     */
142
-    public $taxes;
143
-
144
-    /**
145
-     * Holds the line items related to taxes
146
-     *
147
-     * @since 4.5.0
148
-     * @var EE_Line_Item[] $tax_line_items
149
-     */
150
-    public $tax_line_items;
151
-
152
-    /**
153
-     * Hold the line items which aren't taxes and don't relate
154
-     * to tickets. So: promotions and miscellaneous charges
155
-     *
156
-     * @since 4.5
157
-     * @var EE_Line_Item[] $additional_line_items
158
-     */
159
-    public $additional_line_items;
160
-
161
-    /**
162
-     * Holds the grand total EE_Line_Item
163
-     *
164
-     * @var EE_Line_Item $grand_total_line_item
165
-     */
166
-    public $grand_total_line_item;
167
-
168
-    /**
169
-     * holds the grand total price object
170
-     * currently not used.
171
-     *
172
-     * @var null $grand_total_price_object
173
-     */
174
-    public $grand_total_price_object;
175
-
176
-    /**
177
-     * total number of tickets
178
-     *
179
-     * @var int $total_ticket_count
180
-     */
181
-    public $total_ticket_count;
182
-
183
-    /**
184
-     * Will hold the final transaction object (EE_Transaction)
185
-     *
186
-     * @var EE_Transaction $txn
187
-     */
188
-    public $txn;
189
-
190
-    /**
191
-     * Holds the payments related to a transaction
192
-     *
193
-     * @since 4.5.0
194
-     * @var EE_Payment[] $payments
195
-     */
196
-    public $payments;
197
-
198
-    /**
199
-     * Holds the first related payment related for a transaction
200
-     *
201
-     * @since 4.5.0
202
-     * @var EE_Payment $payment
203
-     */
204
-    public $payment;
205
-
206
-    /**
207
-     * Will hold the label for the txn status
208
-     *
209
-     * @var string $txn_status
210
-     */
211
-    public $txn_status;
212
-
213
-    /**
214
-     * Will hold the final registration object (EE_Registration)
215
-     *
216
-     * @var EE_Registration[] $reg_objs
217
-     */
218
-    public $reg_objs;
219
-
220
-    /**
221
-     * Will hold an array of primary attendee data (if present)
222
-     *
223
-     * @var array $primary_attendee_data
224
-     */
225
-    public $primary_attendee_data;
226
-
227
-    /**
228
-     * This is just an internal object used for passing around the incoming data.
229
-     *
230
-     * @var mixed $_data
231
-     */
232
-    protected $_data;
233
-
234
-    /**
235
-     * This is just an internal object used for passing around the incoming data.
236
-     *
237
-     * @var mixed $incoming_data
238
-     */
239
-    public $incoming_data;
240
-
241
-    /**
242
-     * hold objects that might be created
243
-     *
244
-     * @type EE_Registration $reg_obj
245
-     */
246
-    public $reg_obj;
247
-
248
-
249
-    /**
250
-     * constructor
251
-     *
252
-     * @param mixed $data incoming data object|array.  Suggested that child classes use type hinting for expected
253
-     *                    data object.  But here parent will be generic because we don't know what's coming in.
254
-     */
255
-    public function __construct($data)
256
-    {
257
-        $this->_data = $data;
258
-        $this->_setup_data();
259
-    }
260
-
261
-
262
-    /**
263
-     * Every child class has to setup the data object !
264
-     *
265
-     * @return void
266
-     */
267
-    abstract protected function _setup_data();
268
-
269
-
270
-    /**
271
-     * Returns database safe representation of the data later used to when instantiating this object.
272
-     *
273
-     * @param mixed $data The incoming data to be prepped.
274
-     * @return mixed   The prepped data for db
275
-     */
276
-    public static function convert_data_for_persistent_storage($data)
277
-    {
278
-        return $data;
279
-    }
280
-
281
-
282
-    /**
283
-     * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
284
-     * can be sent into this method and converted back into the format used for instantiating with this data handler.
285
-     *
286
-     * @param $data
287
-     * @return mixed
288
-     */
289
-    public static function convert_data_from_persistent_storage($data)
290
-    {
291
-        return $data;
292
-    }
293
-
294
-
295
-    /**
296
-     * only purpose is to return the data
297
-     *
298
-     * @access public
299
-     * @return mixed the formatted data object!
300
-     */
301
-    public function data()
302
-    {
303
-        return $this->_data;
304
-    }
305
-
306
-
307
-    /**
308
-     * This helper method can be used by any incoming data handlers to setup the data correctly.  All that is required
309
-     * is that $this->reg_objs be set.
310
-     *
311
-     * @throws EE_Error
312
-     * @throws InvalidDataTypeException
313
-     * @throws InvalidInterfaceException
314
-     * @throws InvalidArgumentException
315
-     * @throws EntityNotFoundException
316
-     */
317
-    protected function _assemble_data()
318
-    {
319
-        //verify that reg_objs is set
320
-        if (! is_array($this->reg_objs)
321
-            && ! reset($this->reg_objs) instanceof EE_Registration
322
-        ) {
323
-            throw new EE_Error(
324
-                esc_html__(
325
-                    'In order to assemble the data correctly, the "reg_objs" property must be an array of EE_Registration objects',
326
-                    'event_espresso'
327
-                )
328
-            );
329
-        }
330
-
331
-        //get all attendee and events associated with the registrations in this transaction
332
-        $events             = $event_setup = $evtcache = $tickets = $datetimes = array();
333
-        $answers            = $questions = $attendees = $line_items = $registrations = array();
334
-        $total_ticket_count = 0;
335
-
336
-        if (! empty($this->reg_objs)) {
337
-            $event_attendee_count = array();
338
-            /** @var EE_Registration $reg */
339
-            foreach ($this->reg_objs as $reg) {
340
-                if ($this->_skip_registration_for_processing($reg)
341
-                ) {
342
-                    continue;
343
-                }
344
-
345
-                $evt_id = $reg->event_ID();
346
-                /** @type EE_Ticket $ticket */
347
-                $ticket          = $reg->get_first_related('Ticket');
348
-                $attendee = $reg->attendee();
349
-                $event = $reg->event();
350
-                //if none of the following entities are available, then we can't setup other data reliably,
351
-                // so let's just skip.
352
-                if (! $ticket instanceof EE_Ticket
353
-                    || ! $attendee instanceof EE_Attendee
354
-                    || ! $event instanceof EE_Event
355
-                ) {
356
-                    continue;
357
-                }
358
-                $relateddatetime = $ticket->datetimes();
359
-                $total_ticket_count++;
360
-                $tickets[$ticket->ID()]['ticket']                        = $ticket;
361
-                $tickets[$ticket->ID()]['count']                         = is_array($tickets[$ticket->ID()])
362
-                                                                           && isset($tickets[$ticket->ID()]['count'])
363
-                    ? $tickets[$ticket->ID()]['count'] + 1
364
-                    : 1;
365
-                $tickets[$ticket->ID()]['att_objs'][$attendee->ID()] = $attendee;
366
-                $tickets[$ticket->ID()]['dtt_objs']                      = $relateddatetime;
367
-                $tickets[$ticket->ID()]['reg_objs'][$reg->ID()]          = $reg;
368
-                $tickets[$ticket->ID()]['EE_Event']                      = $event;
369
-                $evtcache[$evt_id]                                       = $event;
370
-                $eventsetup[$evt_id]['reg_objs'][$reg->ID()]             = $reg;
371
-                $eventsetup[$evt_id]['tkt_objs'][$ticket->ID()]          = $ticket;
372
-                $eventsetup[$evt_id]['att_objs'][$attendee->ID()]    = $attendee;
373
-                $event_attendee_count[$evt_id]                           = isset($event_attendee_count[$evt_id])
374
-                    ? $event_attendee_count[$evt_id] + 1
375
-                    : 0;
376
-                $attendees[$reg->attendee_ID()]['line_ref'][]            = $evt_id;
377
-                $attendees[$reg->attendee_ID()]['att_obj']               = $attendee;
378
-                $attendees[$reg->attendee_ID()]['reg_objs'][$reg->ID()]  = $reg;
379
-                //$attendees[ $reg->attendee_ID() ]['registration_id'] = $reg->ID();
380
-                $attendees[$reg->attendee_ID()]['attendee_email']          = $attendee->email();
381
-                $attendees[$reg->attendee_ID()]['tkt_objs'][$ticket->ID()] = $ticket;
382
-                $attendees[$reg->attendee_ID()]['evt_objs'][$evt_id]       = $event;
383
-
384
-                //registrations
385
-                $registrations[$reg->ID()]['tkt_obj'] = $ticket;
386
-                $registrations[$reg->ID()]['evt_obj'] = $event;
387
-                $registrations[$reg->ID()]['reg_obj'] = $reg;
388
-                $registrations[$reg->ID()]['att_obj'] = $attendee;
389
-
390
-                //set up answer objects
391
-                $rel_ans = $reg->get_many_related('Answer');
392
-                foreach ($rel_ans as $ansid => $answer) {
393
-                    if (! isset($questions[$ansid])) {
394
-                        $questions[$ansid] = $answer->get_first_related('Question');
395
-                    }
396
-                    $answers[$ansid]                               = $answer;
397
-                    $registrations[$reg->ID()]['ans_objs'][$ansid] = $answer;
398
-                }
399
-                /**
400
-                 * @var int $dtt_id
401
-                 * @var EE_Datetime $datetime
402
-                 */
403
-                foreach ($relateddatetime as $dtt_id => $datetime) {
404
-                    $eventsetup[$evt_id]['dtt_objs'][$dtt_id]       = $datetime;
405
-                    $registrations[$reg->ID()]['dtt_objs'][$dtt_id] = $datetime;
406
-
407
-                    if (isset($datetimes[$dtt_id])) {
408
-                        continue; //already have this info in the datetimes array.
409
-                    }
410
-
411
-                    $datetimes[$dtt_id]['tkt_objs'][]           = $ticket;
412
-                    $datetimes[$dtt_id]['datetime']             = $datetime;
413
-                    $datetimes[$dtt_id]['evt_objs'][$evt_id]    = $event;
414
-                    $datetimes[$dtt_id]['reg_objs'][$reg->ID()] = $reg;
415
-                }
416
-            }
417
-
418
-            //let's loop through the unique event=>reg items and setup data on them
419
-
420
-            if (! empty($eventsetup)) {
421
-                foreach ($eventsetup as $evt_id => $items) {
422
-                    $ticket_line_items_for_event = array();
423
-                    if ($this->txn instanceof EE_Transaction) {
424
-                        $ticket_line_items_for_event = EEM_Line_Item::instance()->get_all(
425
-                            array(
426
-                                array(
427
-                                    'Ticket.Datetime.EVT_ID' => $evt_id,
428
-                                    'TXN_ID'                 => $this->txn->ID(),
429
-                                ),
430
-                                'default_where_conditions' => 'none',
431
-                            )
432
-                        );
433
-                    }
434
-                    $events[$evt_id] = array(
435
-                        'ID'              => $evt_id,
436
-                        'event'           => $evtcache[$evt_id],
437
-                        'name'            => $evtcache[$evt_id] instanceof EE_Event ? $evtcache[$evt_id]->name() : '',
438
-                        'total_attendees' => $event_attendee_count[$evt_id],
439
-                        'reg_objs'        => $items['reg_objs'],
440
-                        'tkt_objs'        => $items['tkt_objs'],
441
-                        'att_objs'        => $items['att_objs'],
442
-                        'dtt_objs'        => isset($items['dtt_objs']) ? $items['dtt_objs'] : array(),
443
-                        'line_items'      => $ticket_line_items_for_event,
444
-                    );
445
-
446
-                    //make sure the tickets have the line items setup for them.
447
-                    foreach ($ticket_line_items_for_event as $line_id => $line_item) {
448
-                        if ($line_item instanceof EE_Line_Item) {
449
-                            $tickets[$line_item->ticket()->ID()]['line_item']      = $line_item;
450
-                            $tickets[$line_item->ticket()->ID()]['sub_line_items'] = $line_item->children();
451
-                            $line_items[$line_item->ID()]['children']              = $line_item->children();
452
-                            $line_items[$line_item->ID()]['EE_Ticket']             = $line_item->ticket();
453
-                        }
454
-                    }
455
-                }
456
-            }
457
-
458
-            $this->grand_total_line_item = $this->txn instanceof EE_Transaction
459
-                ? $this->txn->total_line_item()
460
-                : null;
461
-        }
462
-
463
-        //lets set the attendees and events properties
464
-        $this->attendees                = $attendees;
465
-        $this->events                   = $events;
466
-        $this->tickets                  = $tickets;
467
-        $this->line_items_with_children = $line_items;
468
-        $this->datetimes                = $datetimes;
469
-        $this->questions                = $questions;
470
-        $this->answers                  = $answers;
471
-        $this->total_ticket_count       = $total_ticket_count;
472
-        $this->registrations            = $registrations;
473
-
474
-        if ($this->txn instanceof EE_Transaction) {
475
-            $this->tax_line_items        = $this->txn->tax_items();
476
-            $this->additional_line_items = $this->txn->non_ticket_line_items();
477
-            $this->payments              = $this->txn->payments();
478
-
479
-            //setup primary registration if we have a single transaction object to work with
480
-
481
-            //let's get just the primary_attendee_data!  First we get the primary registration object.
482
-            $primary_reg = $this->txn->primary_registration();
483
-            // verify
484
-            if ($primary_reg instanceof EE_Registration) {
485
-                // get attendee object
486
-                if ($primary_reg->attendee() instanceof EE_Attendee) {
487
-                    //now we can setup the primary_attendee_data array
488
-                    $this->primary_attendee_data = array(
489
-                        'registration_id' => $primary_reg->ID(),
490
-                        'att_obj'         => $primary_reg->attendee(),
491
-                        'reg_obj'         => $primary_reg,
492
-                        'primary_att_obj' => $primary_reg->attendee(),
493
-                        'primary_reg_obj' => $primary_reg,
494
-                    );
495
-
496
-                } else {
497
-                    EE_Error::add_error(
498
-                        esc_html__(
499
-                            'Incoming data does not have a valid Attendee object for the primary registrant.',
500
-                            'event_espresso'
501
-                        ),
502
-                        __FILE__,
503
-                        __FUNCTION__,
504
-                        __LINE__
505
-                    );
506
-                }
507
-            } else {
508
-                EE_Error::add_error(
509
-                    esc_html__(
510
-                        'Incoming data does not have a valid Registration object for the primary registrant.',
511
-                        'event_espresso'
512
-                    ),
513
-                    __FILE__,
514
-                    __FUNCTION__,
515
-                    __LINE__
516
-                );
517
-            }
518
-        }
519
-    }
520
-
521
-    /**
522
-     * This simply considers whether the given registration should be processed or not based on comparison with the
523
-     * filtered_reg_status property.
524
-     *
525
-     * @param EE_Registration $registration
526
-     * @return bool  returning true means we DO want to skip processing.  returning false means we DON'T want to skip
527
-     *               processing
528
-     */
529
-    protected function _skip_registration_for_processing(EE_Registration $registration)
530
-    {
531
-        if (empty($this->filtered_reg_status)) {
532
-            return false;
533
-        }
534
-
535
-        //if we made it here then we just compare the filtered_reg_status with the registration status and return that
536
-        return $this->filtered_reg_status !== $registration->status_ID();
537
-    }
23
+	/**
24
+	 * user id for logged in user when data collected
25
+	 *
26
+	 * @var string $user_id
27
+	 */
28
+	public $user_id;
29
+
30
+	/**
31
+	 * IP Address of browser used
32
+	 *
33
+	 * @var string $ip_address
34
+	 */
35
+	public $ip_address;
36
+
37
+	/**
38
+	 * browser
39
+	 *
40
+	 * @var string $user_agent
41
+	 */
42
+	public $user_agent;
43
+
44
+	/**
45
+	 * Unix timestamp
46
+	 *
47
+	 * @var string $init_access
48
+	 */
49
+	public $init_access;
50
+
51
+	/**
52
+	 * Unix timestamp
53
+	 *
54
+	 * @var string $last_access
55
+	 */
56
+	public $last_access;
57
+
58
+	/**
59
+	 * The registrations details from the cart
60
+	 *
61
+	 * @var array $reg_info
62
+	 */
63
+	public $reg_info;
64
+
65
+	/**
66
+	 * Some data handlers can set what reg status all the registrations are filtered by.
67
+	 * The status should match a EEM_Registration status constant.
68
+	 *
69
+	 * @var string $filtered_reg_status
70
+	 */
71
+	public $filtered_reg_status;
72
+
73
+	/**
74
+	 * will hold an array of events assembled from $reg_info
75
+	 *
76
+	 * @var EE_Event[] $events
77
+	 */
78
+	public $events;
79
+
80
+	/**
81
+	 * holds an array of datetimes assembled from the incoming data.
82
+	 *
83
+	 * @var EE_Datetime[] $datetimes
84
+	 */
85
+	public $datetimes;
86
+
87
+	/**
88
+	 * holds an array of tickets assembled from the incoming data.
89
+	 *
90
+	 * @var EE_Ticket[] $tickets
91
+	 */
92
+	public $tickets;
93
+
94
+	/**
95
+	 * holds an array with a key of parent line item and values are an array of children of that line item.
96
+	 *
97
+	 * @since 4.5.0
98
+	 * @var EE_Line_Item[] $line_items_with_children
99
+	 */
100
+	public $line_items_with_children;
101
+
102
+	/**
103
+	 * will hold an array of attendees assembled from the $reg_info
104
+	 *
105
+	 * @var EE_Attendee[] $attendees
106
+	 */
107
+	public $attendees;
108
+
109
+	/**
110
+	 * will hold an array of cached registration objects and info assembled from reg_info
111
+	 *
112
+	 * @var array $registrations
113
+	 */
114
+	public $registrations;
115
+
116
+	/**
117
+	 * will hold an array of answers assembled from the $reg_info
118
+	 *
119
+	 * @var EE_Answer[] $answers
120
+	 */
121
+	public $answers;
122
+
123
+	/**
124
+	 * will hold an array of questions assembled from the $reg_info (indexed by Answer ID);
125
+	 *
126
+	 * @var EE_Question[] $questions
127
+	 */
128
+	public $questions;
129
+
130
+	/**
131
+	 * Will hold billing data assembled from $billing_info (if present)
132
+	 *
133
+	 * @var mixed (array|null) $billing
134
+	 */
135
+	public $billing;
136
+
137
+	/**
138
+	 * The total amount of tax for the transaction
139
+	 *
140
+	 * @var float $taxes
141
+	 */
142
+	public $taxes;
143
+
144
+	/**
145
+	 * Holds the line items related to taxes
146
+	 *
147
+	 * @since 4.5.0
148
+	 * @var EE_Line_Item[] $tax_line_items
149
+	 */
150
+	public $tax_line_items;
151
+
152
+	/**
153
+	 * Hold the line items which aren't taxes and don't relate
154
+	 * to tickets. So: promotions and miscellaneous charges
155
+	 *
156
+	 * @since 4.5
157
+	 * @var EE_Line_Item[] $additional_line_items
158
+	 */
159
+	public $additional_line_items;
160
+
161
+	/**
162
+	 * Holds the grand total EE_Line_Item
163
+	 *
164
+	 * @var EE_Line_Item $grand_total_line_item
165
+	 */
166
+	public $grand_total_line_item;
167
+
168
+	/**
169
+	 * holds the grand total price object
170
+	 * currently not used.
171
+	 *
172
+	 * @var null $grand_total_price_object
173
+	 */
174
+	public $grand_total_price_object;
175
+
176
+	/**
177
+	 * total number of tickets
178
+	 *
179
+	 * @var int $total_ticket_count
180
+	 */
181
+	public $total_ticket_count;
182
+
183
+	/**
184
+	 * Will hold the final transaction object (EE_Transaction)
185
+	 *
186
+	 * @var EE_Transaction $txn
187
+	 */
188
+	public $txn;
189
+
190
+	/**
191
+	 * Holds the payments related to a transaction
192
+	 *
193
+	 * @since 4.5.0
194
+	 * @var EE_Payment[] $payments
195
+	 */
196
+	public $payments;
197
+
198
+	/**
199
+	 * Holds the first related payment related for a transaction
200
+	 *
201
+	 * @since 4.5.0
202
+	 * @var EE_Payment $payment
203
+	 */
204
+	public $payment;
205
+
206
+	/**
207
+	 * Will hold the label for the txn status
208
+	 *
209
+	 * @var string $txn_status
210
+	 */
211
+	public $txn_status;
212
+
213
+	/**
214
+	 * Will hold the final registration object (EE_Registration)
215
+	 *
216
+	 * @var EE_Registration[] $reg_objs
217
+	 */
218
+	public $reg_objs;
219
+
220
+	/**
221
+	 * Will hold an array of primary attendee data (if present)
222
+	 *
223
+	 * @var array $primary_attendee_data
224
+	 */
225
+	public $primary_attendee_data;
226
+
227
+	/**
228
+	 * This is just an internal object used for passing around the incoming data.
229
+	 *
230
+	 * @var mixed $_data
231
+	 */
232
+	protected $_data;
233
+
234
+	/**
235
+	 * This is just an internal object used for passing around the incoming data.
236
+	 *
237
+	 * @var mixed $incoming_data
238
+	 */
239
+	public $incoming_data;
240
+
241
+	/**
242
+	 * hold objects that might be created
243
+	 *
244
+	 * @type EE_Registration $reg_obj
245
+	 */
246
+	public $reg_obj;
247
+
248
+
249
+	/**
250
+	 * constructor
251
+	 *
252
+	 * @param mixed $data incoming data object|array.  Suggested that child classes use type hinting for expected
253
+	 *                    data object.  But here parent will be generic because we don't know what's coming in.
254
+	 */
255
+	public function __construct($data)
256
+	{
257
+		$this->_data = $data;
258
+		$this->_setup_data();
259
+	}
260
+
261
+
262
+	/**
263
+	 * Every child class has to setup the data object !
264
+	 *
265
+	 * @return void
266
+	 */
267
+	abstract protected function _setup_data();
268
+
269
+
270
+	/**
271
+	 * Returns database safe representation of the data later used to when instantiating this object.
272
+	 *
273
+	 * @param mixed $data The incoming data to be prepped.
274
+	 * @return mixed   The prepped data for db
275
+	 */
276
+	public static function convert_data_for_persistent_storage($data)
277
+	{
278
+		return $data;
279
+	}
280
+
281
+
282
+	/**
283
+	 * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
284
+	 * can be sent into this method and converted back into the format used for instantiating with this data handler.
285
+	 *
286
+	 * @param $data
287
+	 * @return mixed
288
+	 */
289
+	public static function convert_data_from_persistent_storage($data)
290
+	{
291
+		return $data;
292
+	}
293
+
294
+
295
+	/**
296
+	 * only purpose is to return the data
297
+	 *
298
+	 * @access public
299
+	 * @return mixed the formatted data object!
300
+	 */
301
+	public function data()
302
+	{
303
+		return $this->_data;
304
+	}
305
+
306
+
307
+	/**
308
+	 * This helper method can be used by any incoming data handlers to setup the data correctly.  All that is required
309
+	 * is that $this->reg_objs be set.
310
+	 *
311
+	 * @throws EE_Error
312
+	 * @throws InvalidDataTypeException
313
+	 * @throws InvalidInterfaceException
314
+	 * @throws InvalidArgumentException
315
+	 * @throws EntityNotFoundException
316
+	 */
317
+	protected function _assemble_data()
318
+	{
319
+		//verify that reg_objs is set
320
+		if (! is_array($this->reg_objs)
321
+			&& ! reset($this->reg_objs) instanceof EE_Registration
322
+		) {
323
+			throw new EE_Error(
324
+				esc_html__(
325
+					'In order to assemble the data correctly, the "reg_objs" property must be an array of EE_Registration objects',
326
+					'event_espresso'
327
+				)
328
+			);
329
+		}
330
+
331
+		//get all attendee and events associated with the registrations in this transaction
332
+		$events             = $event_setup = $evtcache = $tickets = $datetimes = array();
333
+		$answers            = $questions = $attendees = $line_items = $registrations = array();
334
+		$total_ticket_count = 0;
335
+
336
+		if (! empty($this->reg_objs)) {
337
+			$event_attendee_count = array();
338
+			/** @var EE_Registration $reg */
339
+			foreach ($this->reg_objs as $reg) {
340
+				if ($this->_skip_registration_for_processing($reg)
341
+				) {
342
+					continue;
343
+				}
344
+
345
+				$evt_id = $reg->event_ID();
346
+				/** @type EE_Ticket $ticket */
347
+				$ticket          = $reg->get_first_related('Ticket');
348
+				$attendee = $reg->attendee();
349
+				$event = $reg->event();
350
+				//if none of the following entities are available, then we can't setup other data reliably,
351
+				// so let's just skip.
352
+				if (! $ticket instanceof EE_Ticket
353
+					|| ! $attendee instanceof EE_Attendee
354
+					|| ! $event instanceof EE_Event
355
+				) {
356
+					continue;
357
+				}
358
+				$relateddatetime = $ticket->datetimes();
359
+				$total_ticket_count++;
360
+				$tickets[$ticket->ID()]['ticket']                        = $ticket;
361
+				$tickets[$ticket->ID()]['count']                         = is_array($tickets[$ticket->ID()])
362
+																		   && isset($tickets[$ticket->ID()]['count'])
363
+					? $tickets[$ticket->ID()]['count'] + 1
364
+					: 1;
365
+				$tickets[$ticket->ID()]['att_objs'][$attendee->ID()] = $attendee;
366
+				$tickets[$ticket->ID()]['dtt_objs']                      = $relateddatetime;
367
+				$tickets[$ticket->ID()]['reg_objs'][$reg->ID()]          = $reg;
368
+				$tickets[$ticket->ID()]['EE_Event']                      = $event;
369
+				$evtcache[$evt_id]                                       = $event;
370
+				$eventsetup[$evt_id]['reg_objs'][$reg->ID()]             = $reg;
371
+				$eventsetup[$evt_id]['tkt_objs'][$ticket->ID()]          = $ticket;
372
+				$eventsetup[$evt_id]['att_objs'][$attendee->ID()]    = $attendee;
373
+				$event_attendee_count[$evt_id]                           = isset($event_attendee_count[$evt_id])
374
+					? $event_attendee_count[$evt_id] + 1
375
+					: 0;
376
+				$attendees[$reg->attendee_ID()]['line_ref'][]            = $evt_id;
377
+				$attendees[$reg->attendee_ID()]['att_obj']               = $attendee;
378
+				$attendees[$reg->attendee_ID()]['reg_objs'][$reg->ID()]  = $reg;
379
+				//$attendees[ $reg->attendee_ID() ]['registration_id'] = $reg->ID();
380
+				$attendees[$reg->attendee_ID()]['attendee_email']          = $attendee->email();
381
+				$attendees[$reg->attendee_ID()]['tkt_objs'][$ticket->ID()] = $ticket;
382
+				$attendees[$reg->attendee_ID()]['evt_objs'][$evt_id]       = $event;
383
+
384
+				//registrations
385
+				$registrations[$reg->ID()]['tkt_obj'] = $ticket;
386
+				$registrations[$reg->ID()]['evt_obj'] = $event;
387
+				$registrations[$reg->ID()]['reg_obj'] = $reg;
388
+				$registrations[$reg->ID()]['att_obj'] = $attendee;
389
+
390
+				//set up answer objects
391
+				$rel_ans = $reg->get_many_related('Answer');
392
+				foreach ($rel_ans as $ansid => $answer) {
393
+					if (! isset($questions[$ansid])) {
394
+						$questions[$ansid] = $answer->get_first_related('Question');
395
+					}
396
+					$answers[$ansid]                               = $answer;
397
+					$registrations[$reg->ID()]['ans_objs'][$ansid] = $answer;
398
+				}
399
+				/**
400
+				 * @var int $dtt_id
401
+				 * @var EE_Datetime $datetime
402
+				 */
403
+				foreach ($relateddatetime as $dtt_id => $datetime) {
404
+					$eventsetup[$evt_id]['dtt_objs'][$dtt_id]       = $datetime;
405
+					$registrations[$reg->ID()]['dtt_objs'][$dtt_id] = $datetime;
406
+
407
+					if (isset($datetimes[$dtt_id])) {
408
+						continue; //already have this info in the datetimes array.
409
+					}
410
+
411
+					$datetimes[$dtt_id]['tkt_objs'][]           = $ticket;
412
+					$datetimes[$dtt_id]['datetime']             = $datetime;
413
+					$datetimes[$dtt_id]['evt_objs'][$evt_id]    = $event;
414
+					$datetimes[$dtt_id]['reg_objs'][$reg->ID()] = $reg;
415
+				}
416
+			}
417
+
418
+			//let's loop through the unique event=>reg items and setup data on them
419
+
420
+			if (! empty($eventsetup)) {
421
+				foreach ($eventsetup as $evt_id => $items) {
422
+					$ticket_line_items_for_event = array();
423
+					if ($this->txn instanceof EE_Transaction) {
424
+						$ticket_line_items_for_event = EEM_Line_Item::instance()->get_all(
425
+							array(
426
+								array(
427
+									'Ticket.Datetime.EVT_ID' => $evt_id,
428
+									'TXN_ID'                 => $this->txn->ID(),
429
+								),
430
+								'default_where_conditions' => 'none',
431
+							)
432
+						);
433
+					}
434
+					$events[$evt_id] = array(
435
+						'ID'              => $evt_id,
436
+						'event'           => $evtcache[$evt_id],
437
+						'name'            => $evtcache[$evt_id] instanceof EE_Event ? $evtcache[$evt_id]->name() : '',
438
+						'total_attendees' => $event_attendee_count[$evt_id],
439
+						'reg_objs'        => $items['reg_objs'],
440
+						'tkt_objs'        => $items['tkt_objs'],
441
+						'att_objs'        => $items['att_objs'],
442
+						'dtt_objs'        => isset($items['dtt_objs']) ? $items['dtt_objs'] : array(),
443
+						'line_items'      => $ticket_line_items_for_event,
444
+					);
445
+
446
+					//make sure the tickets have the line items setup for them.
447
+					foreach ($ticket_line_items_for_event as $line_id => $line_item) {
448
+						if ($line_item instanceof EE_Line_Item) {
449
+							$tickets[$line_item->ticket()->ID()]['line_item']      = $line_item;
450
+							$tickets[$line_item->ticket()->ID()]['sub_line_items'] = $line_item->children();
451
+							$line_items[$line_item->ID()]['children']              = $line_item->children();
452
+							$line_items[$line_item->ID()]['EE_Ticket']             = $line_item->ticket();
453
+						}
454
+					}
455
+				}
456
+			}
457
+
458
+			$this->grand_total_line_item = $this->txn instanceof EE_Transaction
459
+				? $this->txn->total_line_item()
460
+				: null;
461
+		}
462
+
463
+		//lets set the attendees and events properties
464
+		$this->attendees                = $attendees;
465
+		$this->events                   = $events;
466
+		$this->tickets                  = $tickets;
467
+		$this->line_items_with_children = $line_items;
468
+		$this->datetimes                = $datetimes;
469
+		$this->questions                = $questions;
470
+		$this->answers                  = $answers;
471
+		$this->total_ticket_count       = $total_ticket_count;
472
+		$this->registrations            = $registrations;
473
+
474
+		if ($this->txn instanceof EE_Transaction) {
475
+			$this->tax_line_items        = $this->txn->tax_items();
476
+			$this->additional_line_items = $this->txn->non_ticket_line_items();
477
+			$this->payments              = $this->txn->payments();
478
+
479
+			//setup primary registration if we have a single transaction object to work with
480
+
481
+			//let's get just the primary_attendee_data!  First we get the primary registration object.
482
+			$primary_reg = $this->txn->primary_registration();
483
+			// verify
484
+			if ($primary_reg instanceof EE_Registration) {
485
+				// get attendee object
486
+				if ($primary_reg->attendee() instanceof EE_Attendee) {
487
+					//now we can setup the primary_attendee_data array
488
+					$this->primary_attendee_data = array(
489
+						'registration_id' => $primary_reg->ID(),
490
+						'att_obj'         => $primary_reg->attendee(),
491
+						'reg_obj'         => $primary_reg,
492
+						'primary_att_obj' => $primary_reg->attendee(),
493
+						'primary_reg_obj' => $primary_reg,
494
+					);
495
+
496
+				} else {
497
+					EE_Error::add_error(
498
+						esc_html__(
499
+							'Incoming data does not have a valid Attendee object for the primary registrant.',
500
+							'event_espresso'
501
+						),
502
+						__FILE__,
503
+						__FUNCTION__,
504
+						__LINE__
505
+					);
506
+				}
507
+			} else {
508
+				EE_Error::add_error(
509
+					esc_html__(
510
+						'Incoming data does not have a valid Registration object for the primary registrant.',
511
+						'event_espresso'
512
+					),
513
+					__FILE__,
514
+					__FUNCTION__,
515
+					__LINE__
516
+				);
517
+			}
518
+		}
519
+	}
520
+
521
+	/**
522
+	 * This simply considers whether the given registration should be processed or not based on comparison with the
523
+	 * filtered_reg_status property.
524
+	 *
525
+	 * @param EE_Registration $registration
526
+	 * @return bool  returning true means we DO want to skip processing.  returning false means we DON'T want to skip
527
+	 *               processing
528
+	 */
529
+	protected function _skip_registration_for_processing(EE_Registration $registration)
530
+	{
531
+		if (empty($this->filtered_reg_status)) {
532
+			return false;
533
+		}
534
+
535
+		//if we made it here then we just compare the filtered_reg_status with the registration status and return that
536
+		return $this->filtered_reg_status !== $registration->status_ID();
537
+	}
538 538
 
539 539
 
540 540
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
     protected function _assemble_data()
318 318
     {
319 319
         //verify that reg_objs is set
320
-        if (! is_array($this->reg_objs)
320
+        if ( ! is_array($this->reg_objs)
321 321
             && ! reset($this->reg_objs) instanceof EE_Registration
322 322
         ) {
323 323
             throw new EE_Error(
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
         $answers            = $questions = $attendees = $line_items = $registrations = array();
334 334
         $total_ticket_count = 0;
335 335
 
336
-        if (! empty($this->reg_objs)) {
336
+        if ( ! empty($this->reg_objs)) {
337 337
             $event_attendee_count = array();
338 338
             /** @var EE_Registration $reg */
339 339
             foreach ($this->reg_objs as $reg) {
@@ -344,12 +344,12 @@  discard block
 block discarded – undo
344 344
 
345 345
                 $evt_id = $reg->event_ID();
346 346
                 /** @type EE_Ticket $ticket */
347
-                $ticket          = $reg->get_first_related('Ticket');
347
+                $ticket = $reg->get_first_related('Ticket');
348 348
                 $attendee = $reg->attendee();
349 349
                 $event = $reg->event();
350 350
                 //if none of the following entities are available, then we can't setup other data reliably,
351 351
                 // so let's just skip.
352
-                if (! $ticket instanceof EE_Ticket
352
+                if ( ! $ticket instanceof EE_Ticket
353 353
                     || ! $attendee instanceof EE_Attendee
354 354
                     || ! $event instanceof EE_Event
355 355
                 ) {
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
                 $evtcache[$evt_id]                                       = $event;
370 370
                 $eventsetup[$evt_id]['reg_objs'][$reg->ID()]             = $reg;
371 371
                 $eventsetup[$evt_id]['tkt_objs'][$ticket->ID()]          = $ticket;
372
-                $eventsetup[$evt_id]['att_objs'][$attendee->ID()]    = $attendee;
372
+                $eventsetup[$evt_id]['att_objs'][$attendee->ID()] = $attendee;
373 373
                 $event_attendee_count[$evt_id]                           = isset($event_attendee_count[$evt_id])
374 374
                     ? $event_attendee_count[$evt_id] + 1
375 375
                     : 0;
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
                 //set up answer objects
391 391
                 $rel_ans = $reg->get_many_related('Answer');
392 392
                 foreach ($rel_ans as $ansid => $answer) {
393
-                    if (! isset($questions[$ansid])) {
393
+                    if ( ! isset($questions[$ansid])) {
394 394
                         $questions[$ansid] = $answer->get_first_related('Question');
395 395
                     }
396 396
                     $answers[$ansid]                               = $answer;
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
 
418 418
             //let's loop through the unique event=>reg items and setup data on them
419 419
 
420
-            if (! empty($eventsetup)) {
420
+            if ( ! empty($eventsetup)) {
421 421
                 foreach ($eventsetup as $evt_id => $items) {
422 422
                     $ticket_line_items_for_event = array();
423 423
                     if ($this->txn instanceof EE_Transaction) {
Please login to merge, or discard this patch.