@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 3 | - exit('No direct script access allowed'); |
|
| 3 | + exit('No direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * private constructor to prevent direct creation |
| 31 | - * |
|
| 31 | + * |
|
| 32 | 32 | */ |
| 33 | 33 | private function __construct() { |
| 34 | 34 | define( 'ESPRESSO_ENCRYPT', true ); |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | /** |
| 126 | 126 | * encodes string with PHP's base64 encoding |
| 127 | - * |
|
| 127 | + * |
|
| 128 | 128 | * @source http://php.net/manual/en/function.base64-encode.php |
| 129 | 129 | * @param string $text_string |
| 130 | 130 | * @internal param $string - the text to be encoded |
@@ -136,14 +136,14 @@ discard block |
||
| 136 | 136 | return $text_string; |
| 137 | 137 | } |
| 138 | 138 | // encode |
| 139 | - return base64_encode ( $text_string ); |
|
| 139 | + return base64_encode ( $text_string ); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | |
| 143 | 143 | |
| 144 | 144 | /** |
| 145 | 145 | * decodes string that has been encoded with PHP's base64 encoding |
| 146 | - * |
|
| 146 | + * |
|
| 147 | 147 | * @source http://php.net/manual/en/function.base64-encode.php |
| 148 | 148 | * @param string $encoded_string |
| 149 | 149 | * @internal param $string - the text to be decoded |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | return $encoded_string; |
| 156 | 156 | } |
| 157 | 157 | // decode |
| 158 | - return base64_decode ( $encoded_string ); |
|
| 158 | + return base64_decode ( $encoded_string ); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | // encode |
| 177 | 177 | $encoded_string = base64_encode ( $text_string ); |
| 178 | 178 | // remove chars to make encoding more URL friendly |
| 179 | - return strtr ( $encoded_string, '+/=', '-_,' ); |
|
| 179 | + return strtr ( $encoded_string, '+/=', '-_,' ); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | // replace previously removed characters |
| 198 | 198 | $encoded_string = strtr ( $encoded_string, '-_,', '+/=' ); |
| 199 | 199 | // decode |
| 200 | - return base64_decode ( $encoded_string ); |
|
| 200 | + return base64_decode ( $encoded_string ); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | |
@@ -211,8 +211,8 @@ discard block |
||
| 211 | 211 | */ |
| 212 | 212 | private function m_encrypt ( $text_string = '' ) { |
| 213 | 213 | // you give me nothing??? GET OUT ! |
| 214 | - if (empty($text_string)) { |
|
| 215 | - return $text_string; |
|
| 214 | + if (empty($text_string)) { |
|
| 215 | + return $text_string; |
|
| 216 | 216 | } |
| 217 | 217 | // get the initialization vector size |
| 218 | 218 | $iv_size = mcrypt_get_iv_size ( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB ); |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | $iv = mcrypt_create_iv ( $iv_size, MCRYPT_RAND ); |
| 221 | 221 | // encrypt it |
| 222 | 222 | $encrypted_text = mcrypt_encrypt ( MCRYPT_RIJNDAEL_256, $this->get_encryption_key(), $text_string, MCRYPT_MODE_ECB, $iv ); |
| 223 | - // trim and maybe encode |
|
| 223 | + // trim and maybe encode |
|
| 224 | 224 | return function_exists('base64_encode') ? trim(base64_encode($encrypted_text)) : trim($encrypted_text); |
| 225 | 225 | } |
| 226 | 226 | |
@@ -235,12 +235,12 @@ discard block |
||
| 235 | 235 | */ |
| 236 | 236 | private function m_decrypt ( $encrypted_text = '' ) { |
| 237 | 237 | // you give me nothing??? GET OUT ! |
| 238 | - if (empty($encrypted_text)) { |
|
| 239 | - return $encrypted_text; |
|
| 238 | + if (empty($encrypted_text)) { |
|
| 239 | + return $encrypted_text; |
|
| 240 | 240 | } |
| 241 | 241 | // decode |
| 242 | - $encrypted_text = $this->valid_base_64($encrypted_text) ? base64_decode($encrypted_text) : $encrypted_text; |
|
| 243 | - // get the initialization vector size |
|
| 242 | + $encrypted_text = $this->valid_base_64($encrypted_text) ? base64_decode($encrypted_text) : $encrypted_text; |
|
| 243 | + // get the initialization vector size |
|
| 244 | 244 | $iv_size = mcrypt_get_iv_size ( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB ); |
| 245 | 245 | $iv = mcrypt_create_iv ( $iv_size, MCRYPT_RAND ); |
| 246 | 246 | // decrypt it |
@@ -261,8 +261,8 @@ discard block |
||
| 261 | 261 | */ |
| 262 | 262 | private function acme_encrypt ( $text_string = '' ) { |
| 263 | 263 | // you give me nothing??? GET OUT ! |
| 264 | - if (empty($text_string)) { |
|
| 265 | - return $text_string; |
|
| 264 | + if (empty($text_string)) { |
|
| 265 | + return $text_string; |
|
| 266 | 266 | } |
| 267 | 267 | $key_bits = str_split ( str_pad ( '', strlen( $text_string ), $this->get_encryption_key(), STR_PAD_RIGHT )); |
| 268 | 268 | $string_bits = str_split( $text_string ); |
@@ -270,15 +270,15 @@ discard block |
||
| 270 | 270 | $temp = ord( $v ) + ord ( $key_bits[$k] ); |
| 271 | 271 | $string_bits[$k] = chr ( $temp > 255 ? ( $temp - 256 ) : $temp ); |
| 272 | 272 | } |
| 273 | - return function_exists('base64_encode') ? base64_encode( implode( '', $string_bits ) ) : implode('', $string_bits); |
|
| 273 | + return function_exists('base64_encode') ? base64_encode( implode( '', $string_bits ) ) : implode('', $string_bits); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | |
| 277 | 277 | |
| 278 | 278 | /** |
| 279 | - * decrypts data for acme servers that didn't bother to install PHP mcrypt |
|
| 280 | - * |
|
| 281 | - * @source : http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
| 279 | + * decrypts data for acme servers that didn't bother to install PHP mcrypt |
|
| 280 | + * |
|
| 281 | + * @source : http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
| 282 | 282 | * @param string $encrypted_text the text to be decrypted |
| 283 | 283 | * @return string |
| 284 | 284 | */ |
@@ -287,46 +287,46 @@ discard block |
||
| 287 | 287 | if ( empty($encrypted_text)) { |
| 288 | 288 | return $encrypted_text; |
| 289 | 289 | } |
| 290 | - // decode the data ? |
|
| 291 | - $encrypted_text = $this->valid_base_64($encrypted_text) ? base64_decode($encrypted_text) : $encrypted_text; |
|
| 290 | + // decode the data ? |
|
| 291 | + $encrypted_text = $this->valid_base_64($encrypted_text) ? base64_decode($encrypted_text) : $encrypted_text; |
|
| 292 | 292 | $key_bits = str_split ( str_pad ( '', strlen ( $encrypted_text ), $this->get_encryption_key(), STR_PAD_RIGHT )); |
| 293 | 293 | $string_bits = str_split ( $encrypted_text ); |
| 294 | 294 | foreach ( $string_bits as $k => $v ) { |
| 295 | 295 | $temp = ord ( $v ) - ord ( $key_bits[$k] ); |
| 296 | 296 | $string_bits[$k] = chr ( $temp < 0 ? ( $temp + 256 ) : $temp ); |
| 297 | 297 | } |
| 298 | - return implode( '', $string_bits ); |
|
| 298 | + return implode( '', $string_bits ); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | |
| 302 | 302 | |
| 303 | - /** |
|
| 304 | - * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906 |
|
| 305 | - * @param $string |
|
| 306 | - * @return bool |
|
| 307 | - */ |
|
| 308 | - private function valid_base_64($string) |
|
| 309 | - { |
|
| 310 | - // ensure data is a string |
|
| 311 | - if ( ! is_string($string) || ! function_exists('base64_decode')) { |
|
| 312 | - return false; |
|
| 313 | - } |
|
| 314 | - $decoded = base64_decode($string, true); |
|
| 315 | - // Check if there is no invalid character in string |
|
| 316 | - if ( ! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
| 317 | - return false; |
|
| 318 | - } |
|
| 319 | - // Decode the string in strict mode and send the response |
|
| 320 | - if ( ! base64_decode($string, true)) { |
|
| 321 | - return false; |
|
| 322 | - } |
|
| 323 | - // Encode and compare it to original one |
|
| 324 | - return base64_encode($decoded) === $string; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - |
|
| 328 | - |
|
| 329 | - /** |
|
| 303 | + /** |
|
| 304 | + * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906 |
|
| 305 | + * @param $string |
|
| 306 | + * @return bool |
|
| 307 | + */ |
|
| 308 | + private function valid_base_64($string) |
|
| 309 | + { |
|
| 310 | + // ensure data is a string |
|
| 311 | + if ( ! is_string($string) || ! function_exists('base64_decode')) { |
|
| 312 | + return false; |
|
| 313 | + } |
|
| 314 | + $decoded = base64_decode($string, true); |
|
| 315 | + // Check if there is no invalid character in string |
|
| 316 | + if ( ! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
| 317 | + return false; |
|
| 318 | + } |
|
| 319 | + // Decode the string in strict mode and send the response |
|
| 320 | + if ( ! base64_decode($string, true)) { |
|
| 321 | + return false; |
|
| 322 | + } |
|
| 323 | + // Encode and compare it to original one |
|
| 324 | + return base64_encode($decoded) === $string; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | 330 | * generate random string |
| 331 | 331 | * @source : http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php |
| 332 | 332 | * @access public |
@@ -31,8 +31,8 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | */ |
| 33 | 33 | private function __construct() { |
| 34 | - define( 'ESPRESSO_ENCRYPT', true ); |
|
| 35 | - if ( ! function_exists( 'mcrypt_encrypt' ) ) { |
|
| 34 | + define('ESPRESSO_ENCRYPT', true); |
|
| 35 | + if ( ! function_exists('mcrypt_encrypt')) { |
|
| 36 | 36 | $this->_use_mcrypt = false; |
| 37 | 37 | } |
| 38 | 38 | } |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | * @access public |
| 45 | 45 | * @return \EE_Encryption |
| 46 | 46 | */ |
| 47 | - public static function instance ( ) { |
|
| 47 | + public static function instance( ) { |
|
| 48 | 48 | // check if class object is instantiated |
| 49 | - if ( ! self::$_instance instanceof EE_Encryption ) { |
|
| 49 | + if ( ! self::$_instance instanceof EE_Encryption) { |
|
| 50 | 50 | self::$_instance = new self(); |
| 51 | 51 | } |
| 52 | 52 | return self::$_instance; |
@@ -61,15 +61,15 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | public function get_encryption_key() { |
| 63 | 63 | // if encryption key has not been set |
| 64 | - if ( empty( $this->_encryption_key )) { |
|
| 64 | + if (empty($this->_encryption_key)) { |
|
| 65 | 65 | // retrieve encryption_key from db |
| 66 | - $this->_encryption_key = get_option( 'ee_encryption_key', '' ); |
|
| 66 | + $this->_encryption_key = get_option('ee_encryption_key', ''); |
|
| 67 | 67 | // WHAT?? No encryption_key in the db ?? |
| 68 | - if ( $this->_encryption_key === '' ) { |
|
| 68 | + if ($this->_encryption_key === '') { |
|
| 69 | 69 | // let's make one. And md5 it to make it just the right size for a key |
| 70 | - $new_key = md5($this->generate_random_string()); |
|
| 70 | + $new_key = md5($this->generate_random_string()); |
|
| 71 | 71 | // now save it to the db for later |
| 72 | - add_option( 'ee_encryption_key', $new_key ); |
|
| 72 | + add_option('ee_encryption_key', $new_key); |
|
| 73 | 73 | // here's the key - FINALLY ! |
| 74 | 74 | $this->_encryption_key = $new_key; |
| 75 | 75 | } |
@@ -85,15 +85,15 @@ discard block |
||
| 85 | 85 | * @param string $text_string - the text to be encrypted |
| 86 | 86 | * @return string |
| 87 | 87 | */ |
| 88 | - public function encrypt ( $text_string = '' ) { |
|
| 88 | + public function encrypt($text_string = '') { |
|
| 89 | 89 | // you give me nothing??? GET OUT ! |
| 90 | - if ( empty( $text_string )) { |
|
| 90 | + if (empty($text_string)) { |
|
| 91 | 91 | return $text_string; |
| 92 | 92 | } |
| 93 | - if ( $this->_use_mcrypt ) { |
|
| 94 | - $encrypted_text = $this->m_encrypt( $text_string ); |
|
| 93 | + if ($this->_use_mcrypt) { |
|
| 94 | + $encrypted_text = $this->m_encrypt($text_string); |
|
| 95 | 95 | } else { |
| 96 | - $encrypted_text = $this->acme_encrypt( $text_string ); |
|
| 96 | + $encrypted_text = $this->acme_encrypt($text_string); |
|
| 97 | 97 | } |
| 98 | 98 | return $encrypted_text; |
| 99 | 99 | } |
@@ -106,16 +106,16 @@ discard block |
||
| 106 | 106 | * @param string $encrypted_text - the text to be decrypted |
| 107 | 107 | * @return string |
| 108 | 108 | */ |
| 109 | - public function decrypt ( $encrypted_text = '' ) { |
|
| 109 | + public function decrypt($encrypted_text = '') { |
|
| 110 | 110 | // you give me nothing??? GET OUT ! |
| 111 | - if ( empty( $encrypted_text )) { |
|
| 111 | + if (empty($encrypted_text)) { |
|
| 112 | 112 | return $encrypted_text; |
| 113 | 113 | } |
| 114 | 114 | // if PHP's mcrypt functions are installed then we'll use them |
| 115 | - if ( $this->_use_mcrypt ) { |
|
| 116 | - $decrypted_text = $this->m_decrypt( $encrypted_text ); |
|
| 115 | + if ($this->_use_mcrypt) { |
|
| 116 | + $decrypted_text = $this->m_decrypt($encrypted_text); |
|
| 117 | 117 | } else { |
| 118 | - $decrypted_text = $this->acme_decrypt( $encrypted_text ); |
|
| 118 | + $decrypted_text = $this->acme_decrypt($encrypted_text); |
|
| 119 | 119 | } |
| 120 | 120 | return $decrypted_text; |
| 121 | 121 | } |
@@ -130,13 +130,13 @@ discard block |
||
| 130 | 130 | * @internal param $string - the text to be encoded |
| 131 | 131 | * @return string |
| 132 | 132 | */ |
| 133 | - public function base64_string_encode ( $text_string = '' ) { |
|
| 133 | + public function base64_string_encode($text_string = '') { |
|
| 134 | 134 | // you give me nothing??? GET OUT ! |
| 135 | - if (empty($text_string) || ! function_exists('base64_encode')) { |
|
| 135 | + if (empty($text_string) || ! function_exists('base64_encode')) { |
|
| 136 | 136 | return $text_string; |
| 137 | 137 | } |
| 138 | 138 | // encode |
| 139 | - return base64_encode ( $text_string ); |
|
| 139 | + return base64_encode($text_string); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | |
@@ -149,13 +149,13 @@ discard block |
||
| 149 | 149 | * @internal param $string - the text to be decoded |
| 150 | 150 | * @return string |
| 151 | 151 | */ |
| 152 | - public function base64_string_decode ( $encoded_string = '' ) { |
|
| 152 | + public function base64_string_decode($encoded_string = '') { |
|
| 153 | 153 | // you give me nothing??? GET OUT ! |
| 154 | - if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
| 154 | + if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
| 155 | 155 | return $encoded_string; |
| 156 | 156 | } |
| 157 | 157 | // decode |
| 158 | - return base64_decode ( $encoded_string ); |
|
| 158 | + return base64_decode($encoded_string); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | |
@@ -168,15 +168,15 @@ discard block |
||
| 168 | 168 | * @internal param $string - the text to be encoded |
| 169 | 169 | * @return string |
| 170 | 170 | */ |
| 171 | - public function base64_url_encode ( $text_string = '' ) { |
|
| 171 | + public function base64_url_encode($text_string = '') { |
|
| 172 | 172 | // you give me nothing??? GET OUT ! |
| 173 | - if (empty($text_string) || ! function_exists('base64_encode')) { |
|
| 173 | + if (empty($text_string) || ! function_exists('base64_encode')) { |
|
| 174 | 174 | return $text_string; |
| 175 | 175 | } |
| 176 | 176 | // encode |
| 177 | - $encoded_string = base64_encode ( $text_string ); |
|
| 177 | + $encoded_string = base64_encode($text_string); |
|
| 178 | 178 | // remove chars to make encoding more URL friendly |
| 179 | - return strtr ( $encoded_string, '+/=', '-_,' ); |
|
| 179 | + return strtr($encoded_string, '+/=', '-_,'); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | |
@@ -189,15 +189,15 @@ discard block |
||
| 189 | 189 | * @internal param $string - the text to be decoded |
| 190 | 190 | * @return string |
| 191 | 191 | */ |
| 192 | - public function base64_url_decode ( $encoded_string = '' ) { |
|
| 192 | + public function base64_url_decode($encoded_string = '') { |
|
| 193 | 193 | // you give me nothing??? GET OUT ! |
| 194 | - if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
| 194 | + if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
| 195 | 195 | return $encoded_string; |
| 196 | 196 | } |
| 197 | 197 | // replace previously removed characters |
| 198 | - $encoded_string = strtr ( $encoded_string, '-_,', '+/=' ); |
|
| 198 | + $encoded_string = strtr($encoded_string, '-_,', '+/='); |
|
| 199 | 199 | // decode |
| 200 | - return base64_decode ( $encoded_string ); |
|
| 200 | + return base64_decode($encoded_string); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | |
@@ -209,17 +209,17 @@ discard block |
||
| 209 | 209 | * @internal param $string - the text to be encrypted |
| 210 | 210 | * @return string |
| 211 | 211 | */ |
| 212 | - private function m_encrypt ( $text_string = '' ) { |
|
| 212 | + private function m_encrypt($text_string = '') { |
|
| 213 | 213 | // you give me nothing??? GET OUT ! |
| 214 | 214 | if (empty($text_string)) { |
| 215 | 215 | return $text_string; |
| 216 | 216 | } |
| 217 | 217 | // get the initialization vector size |
| 218 | - $iv_size = mcrypt_get_iv_size ( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB ); |
|
| 218 | + $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
| 219 | 219 | // initialization vector |
| 220 | - $iv = mcrypt_create_iv ( $iv_size, MCRYPT_RAND ); |
|
| 220 | + $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
| 221 | 221 | // encrypt it |
| 222 | - $encrypted_text = mcrypt_encrypt ( MCRYPT_RIJNDAEL_256, $this->get_encryption_key(), $text_string, MCRYPT_MODE_ECB, $iv ); |
|
| 222 | + $encrypted_text = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->get_encryption_key(), $text_string, MCRYPT_MODE_ECB, $iv); |
|
| 223 | 223 | // trim and maybe encode |
| 224 | 224 | return function_exists('base64_encode') ? trim(base64_encode($encrypted_text)) : trim($encrypted_text); |
| 225 | 225 | } |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | * @internal param $string - the text to be decrypted |
| 234 | 234 | * @return string |
| 235 | 235 | */ |
| 236 | - private function m_decrypt ( $encrypted_text = '' ) { |
|
| 236 | + private function m_decrypt($encrypted_text = '') { |
|
| 237 | 237 | // you give me nothing??? GET OUT ! |
| 238 | 238 | if (empty($encrypted_text)) { |
| 239 | 239 | return $encrypted_text; |
@@ -241,11 +241,11 @@ discard block |
||
| 241 | 241 | // decode |
| 242 | 242 | $encrypted_text = $this->valid_base_64($encrypted_text) ? base64_decode($encrypted_text) : $encrypted_text; |
| 243 | 243 | // get the initialization vector size |
| 244 | - $iv_size = mcrypt_get_iv_size ( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB ); |
|
| 245 | - $iv = mcrypt_create_iv ( $iv_size, MCRYPT_RAND ); |
|
| 244 | + $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
| 245 | + $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
| 246 | 246 | // decrypt it |
| 247 | - $decrypted_text = mcrypt_decrypt ( MCRYPT_RIJNDAEL_256, $this->get_encryption_key(), $encrypted_text, MCRYPT_MODE_ECB, $iv ); |
|
| 248 | - $decrypted_text = trim ( $decrypted_text ); |
|
| 247 | + $decrypted_text = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->get_encryption_key(), $encrypted_text, MCRYPT_MODE_ECB, $iv); |
|
| 248 | + $decrypted_text = trim($decrypted_text); |
|
| 249 | 249 | return $decrypted_text; |
| 250 | 250 | } |
| 251 | 251 | |
@@ -259,18 +259,18 @@ discard block |
||
| 259 | 259 | * @internal param $string - the text to be decrypted |
| 260 | 260 | * @return string |
| 261 | 261 | */ |
| 262 | - private function acme_encrypt ( $text_string = '' ) { |
|
| 262 | + private function acme_encrypt($text_string = '') { |
|
| 263 | 263 | // you give me nothing??? GET OUT ! |
| 264 | 264 | if (empty($text_string)) { |
| 265 | 265 | return $text_string; |
| 266 | 266 | } |
| 267 | - $key_bits = str_split ( str_pad ( '', strlen( $text_string ), $this->get_encryption_key(), STR_PAD_RIGHT )); |
|
| 268 | - $string_bits = str_split( $text_string ); |
|
| 269 | - foreach ( $string_bits as $k =>$v ) { |
|
| 270 | - $temp = ord( $v ) + ord ( $key_bits[$k] ); |
|
| 271 | - $string_bits[$k] = chr ( $temp > 255 ? ( $temp - 256 ) : $temp ); |
|
| 267 | + $key_bits = str_split(str_pad('', strlen($text_string), $this->get_encryption_key(), STR_PAD_RIGHT)); |
|
| 268 | + $string_bits = str_split($text_string); |
|
| 269 | + foreach ($string_bits as $k =>$v) { |
|
| 270 | + $temp = ord($v) + ord($key_bits[$k]); |
|
| 271 | + $string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp); |
|
| 272 | 272 | } |
| 273 | - return function_exists('base64_encode') ? base64_encode( implode( '', $string_bits ) ) : implode('', $string_bits); |
|
| 273 | + return function_exists('base64_encode') ? base64_encode(implode('', $string_bits)) : implode('', $string_bits); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | |
@@ -282,20 +282,20 @@ discard block |
||
| 282 | 282 | * @param string $encrypted_text the text to be decrypted |
| 283 | 283 | * @return string |
| 284 | 284 | */ |
| 285 | - private function acme_decrypt ( $encrypted_text = '' ) { |
|
| 285 | + private function acme_decrypt($encrypted_text = '') { |
|
| 286 | 286 | // you give me nothing??? GET OUT ! |
| 287 | - if ( empty($encrypted_text)) { |
|
| 287 | + if (empty($encrypted_text)) { |
|
| 288 | 288 | return $encrypted_text; |
| 289 | 289 | } |
| 290 | 290 | // decode the data ? |
| 291 | 291 | $encrypted_text = $this->valid_base_64($encrypted_text) ? base64_decode($encrypted_text) : $encrypted_text; |
| 292 | - $key_bits = str_split ( str_pad ( '', strlen ( $encrypted_text ), $this->get_encryption_key(), STR_PAD_RIGHT )); |
|
| 293 | - $string_bits = str_split ( $encrypted_text ); |
|
| 294 | - foreach ( $string_bits as $k => $v ) { |
|
| 295 | - $temp = ord ( $v ) - ord ( $key_bits[$k] ); |
|
| 296 | - $string_bits[$k] = chr ( $temp < 0 ? ( $temp + 256 ) : $temp ); |
|
| 292 | + $key_bits = str_split(str_pad('', strlen($encrypted_text), $this->get_encryption_key(), STR_PAD_RIGHT)); |
|
| 293 | + $string_bits = str_split($encrypted_text); |
|
| 294 | + foreach ($string_bits as $k => $v) { |
|
| 295 | + $temp = ord($v) - ord($key_bits[$k]); |
|
| 296 | + $string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp); |
|
| 297 | 297 | } |
| 298 | - return implode( '', $string_bits ); |
|
| 298 | + return implode('', $string_bits); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | |
@@ -334,13 +334,13 @@ discard block |
||
| 334 | 334 | * @internal param $string - number of characters for random string |
| 335 | 335 | * @return string |
| 336 | 336 | */ |
| 337 | - public function generate_random_string ( $length = 40 ) { |
|
| 338 | - $iterations = ceil ( $length / 40 ); |
|
| 337 | + public function generate_random_string($length = 40) { |
|
| 338 | + $iterations = ceil($length / 40); |
|
| 339 | 339 | $random_string = ''; |
| 340 | - for ($i = 0; $i < $iterations; $i ++) { |
|
| 341 | - $random_string .= sha1( microtime(TRUE) . mt_rand( 10000, 90000 )); |
|
| 340 | + for ($i = 0; $i < $iterations; $i++) { |
|
| 341 | + $random_string .= sha1(microtime(TRUE).mt_rand(10000, 90000)); |
|
| 342 | 342 | } |
| 343 | - $random_string = substr( $random_string, 0, $length ); |
|
| 343 | + $random_string = substr($random_string, 0, $length); |
|
| 344 | 344 | return $random_string; |
| 345 | 345 | } |
| 346 | 346 | |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @param EE_Event $evtobj The Event object we're attaching data to |
| 203 | 203 | * @param array $data The request data from the form |
| 204 | 204 | * |
| 205 | - * @return bool success or fail |
|
| 205 | + * @return boolean|null success or fail |
|
| 206 | 206 | */ |
| 207 | 207 | public function dtt_and_tickets_caf_update($evtobj, $data) |
| 208 | 208 | { |
@@ -980,6 +980,9 @@ discard block |
||
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | |
| 983 | + /** |
|
| 984 | + * @param integer $dttrow |
|
| 985 | + */ |
|
| 983 | 986 | protected function _get_datetime_row( |
| 984 | 987 | $dttrow, |
| 985 | 988 | EE_Datetime $dtt, |
@@ -1012,6 +1015,7 @@ discard block |
||
| 1012 | 1015 | * object. |
| 1013 | 1016 | * @param bool $default Whether a default row is being generated or not. |
| 1014 | 1017 | * @param EE_Datetime[] $all_dtts This is the array of all datetimes used in the editor. |
| 1018 | + * @param EE_Datetime|null $dtt |
|
| 1015 | 1019 | * |
| 1016 | 1020 | * @return string Generated edit row. |
| 1017 | 1021 | */ |
@@ -1056,6 +1060,10 @@ discard block |
||
| 1056 | 1060 | } |
| 1057 | 1061 | |
| 1058 | 1062 | |
| 1063 | + /** |
|
| 1064 | + * @param EE_Datetime|null $dtt |
|
| 1065 | + * @param boolean $default |
|
| 1066 | + */ |
|
| 1059 | 1067 | protected function _get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets, $all_tickets, $default) |
| 1060 | 1068 | { |
| 1061 | 1069 | |
@@ -1305,6 +1313,9 @@ discard block |
||
| 1305 | 1313 | } |
| 1306 | 1314 | |
| 1307 | 1315 | |
| 1316 | + /** |
|
| 1317 | + * @param integer $tktrow |
|
| 1318 | + */ |
|
| 1308 | 1319 | protected function _get_tax_rows($tktrow, $ticket) |
| 1309 | 1320 | { |
| 1310 | 1321 | $tax_rows = ''; |
@@ -1340,6 +1351,9 @@ discard block |
||
| 1340 | 1351 | } |
| 1341 | 1352 | |
| 1342 | 1353 | |
| 1354 | + /** |
|
| 1355 | + * @param boolean $default |
|
| 1356 | + */ |
|
| 1343 | 1357 | protected function _get_ticket_price_row( |
| 1344 | 1358 | $tktrow, |
| 1345 | 1359 | $prcrow, |
@@ -1475,6 +1489,9 @@ discard block |
||
| 1475 | 1489 | } |
| 1476 | 1490 | |
| 1477 | 1491 | |
| 1492 | + /** |
|
| 1493 | + * @param boolean $default |
|
| 1494 | + */ |
|
| 1478 | 1495 | protected function _get_ticket_datetime_list_item($dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default) |
| 1479 | 1496 | { |
| 1480 | 1497 | $dttid = ! empty($dtt) ? $dtt->ID() : 0; |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 3 | - exit('NO direct script access allowed'); |
|
| 3 | + exit('NO direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -31,1535 +31,1535 @@ discard block |
||
| 31 | 31 | class espresso_events_Pricing_Hooks extends EE_Admin_Hooks |
| 32 | 32 | { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * This property is just used to hold the status of whether an event is currently being |
|
| 36 | - * created (true) or edited (false) |
|
| 37 | - * @access protected |
|
| 38 | - * @var bool |
|
| 39 | - */ |
|
| 40 | - protected $_is_creating_event; |
|
| 34 | + /** |
|
| 35 | + * This property is just used to hold the status of whether an event is currently being |
|
| 36 | + * created (true) or edited (false) |
|
| 37 | + * @access protected |
|
| 38 | + * @var bool |
|
| 39 | + */ |
|
| 40 | + protected $_is_creating_event; |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Used to contain the format strings for date and time that will be used for php date and |
|
| 45 | - * time. |
|
| 46 | - * |
|
| 47 | - * Is set in the _set_hooks_properties() method. |
|
| 48 | - * |
|
| 49 | - * @var array |
|
| 50 | - */ |
|
| 51 | - protected $_date_format_strings; |
|
| 43 | + /** |
|
| 44 | + * Used to contain the format strings for date and time that will be used for php date and |
|
| 45 | + * time. |
|
| 46 | + * |
|
| 47 | + * Is set in the _set_hooks_properties() method. |
|
| 48 | + * |
|
| 49 | + * @var array |
|
| 50 | + */ |
|
| 51 | + protected $_date_format_strings; |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - protected function _set_hooks_properties() |
|
| 55 | - { |
|
| 56 | - $this->_name = 'pricing'; |
|
| 57 | - |
|
| 58 | - //capability check |
|
| 59 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_default_prices', |
|
| 60 | - 'advanced_ticket_datetime_metabox') |
|
| 61 | - ) { |
|
| 62 | - return; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - //if we were going to add our own metaboxes we'd use the below. |
|
| 67 | - $this->_metaboxes = array( |
|
| 68 | - 0 => array( |
|
| 69 | - 'page_route' => array('edit', 'create_new'), |
|
| 70 | - 'func' => 'pricing_metabox', |
|
| 71 | - 'label' => __('Event Tickets & Datetimes', 'event_espresso'), |
|
| 72 | - 'priority' => 'high', |
|
| 73 | - 'context' => 'normal' |
|
| 74 | - ), |
|
| 75 | - |
|
| 76 | - );/**/ |
|
| 77 | - |
|
| 78 | - $this->_remove_metaboxes = array( |
|
| 79 | - 0 => array( |
|
| 80 | - 'page_route' => array('edit', 'create_new'), |
|
| 81 | - 'id' => 'espresso_event_editor_tickets', |
|
| 82 | - 'context' => 'normal' |
|
| 83 | - ) |
|
| 84 | - ); |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
| 88 | - * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
| 89 | - * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
| 90 | - * |
|
| 91 | - * @since 4.6.7 |
|
| 92 | - * |
|
| 93 | - * @var array Expected an array returned with 'date' and 'time' keys. |
|
| 94 | - */ |
|
| 95 | - $this->_date_format_strings = apply_filters('FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
| 96 | - array( |
|
| 97 | - 'date' => 'Y-m-d', |
|
| 98 | - 'time' => 'h:i a' |
|
| 99 | - )); |
|
| 100 | - |
|
| 101 | - //validate |
|
| 102 | - $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) ? $this->_date_format_strings['date'] : null; |
|
| 103 | - $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) ? $this->_date_format_strings['time'] : null; |
|
| 104 | - |
|
| 105 | - //validate format strings |
|
| 106 | - $format_validation = EEH_DTT_Helper::validate_format_string($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']); |
|
| 107 | - if (is_array($format_validation)) { |
|
| 108 | - $msg = '<p>' . sprintf(__('The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
| 109 | - 'event_espresso'), |
|
| 110 | - $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']) . '</p><ul>'; |
|
| 111 | - foreach ($format_validation as $error) { |
|
| 112 | - $msg .= '<li>' . $error . '</li>'; |
|
| 113 | - } |
|
| 114 | - $msg .= '</ul></p><p>' . sprintf(__('%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
| 115 | - 'event_espresso'), '<span style="color:#D54E21;">', '</span>') . '</p>'; |
|
| 116 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 117 | - $this->_date_format_strings = array( |
|
| 118 | - 'date' => 'Y-m-d', |
|
| 119 | - 'time' => 'h:i a' |
|
| 120 | - ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - $this->_scripts_styles = array( |
|
| 125 | - 'registers' => array( |
|
| 126 | - 'ee-tickets-datetimes-css' => array( |
|
| 127 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
| 128 | - 'type' => 'css' |
|
| 129 | - ), |
|
| 130 | - 'ee-dtt-ticket-metabox' => array( |
|
| 131 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
| 132 | - 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore') |
|
| 133 | - ) |
|
| 134 | - ), |
|
| 135 | - 'deregisters' => array( |
|
| 136 | - 'event-editor-css' => array('type' => 'css'), |
|
| 137 | - 'event-datetime-metabox' => array('type' => 'js') |
|
| 138 | - ), |
|
| 139 | - 'enqueues' => array( |
|
| 140 | - 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
| 141 | - 'ee-dtt-ticket-metabox' => array('edit', 'create_new') |
|
| 142 | - ), |
|
| 143 | - 'localize' => array( |
|
| 144 | - 'ee-dtt-ticket-metabox' => array( |
|
| 145 | - 'DTT_TRASH_BLOCK' => array( |
|
| 146 | - 'main_warning' => __('The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
| 147 | - 'event_espresso'), |
|
| 148 | - 'after_warning' => __('In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
| 149 | - 'event_espresso'), |
|
| 150 | - 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' . __('Cancel', |
|
| 151 | - 'event_espresso') . '</button>', |
|
| 152 | - 'single_warning_from_tkt' => __('The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
| 153 | - 'event_espresso'), |
|
| 154 | - 'single_warning_from_dtt' => __('The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
| 155 | - 'event_espresso'), |
|
| 156 | - 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' . __('Dismiss', |
|
| 157 | - 'event_espresso') . '</button>' |
|
| 158 | - ), |
|
| 159 | - 'DTT_ERROR_MSG' => array( |
|
| 160 | - 'no_ticket_name' => __('General Admission', 'event_espresso'), |
|
| 161 | - 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' . __('Dismiss', |
|
| 162 | - 'event_espresso') . '</button></div>' |
|
| 163 | - ), |
|
| 164 | - 'DTT_OVERSELL_WARNING' => array( |
|
| 165 | - 'datetime_ticket' => __('You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
| 166 | - 'event_espresso'), |
|
| 167 | - 'ticket_datetime' => __('You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
| 168 | - 'event_espresso') |
|
| 169 | - ), |
|
| 170 | - 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats($this->_date_format_strings['date'], |
|
| 171 | - $this->_date_format_strings['time']), |
|
| 172 | - 'DTT_START_OF_WEEK' => array('dayValue' => (int)get_option('start_of_week')) |
|
| 173 | - ) |
|
| 174 | - ) |
|
| 175 | - ); |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - add_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
| 179 | - array($this, 'autosave_handling'), 10); |
|
| 180 | - add_filter('FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 181 | - array($this, 'caf_updates'), 10); |
|
| 182 | - } |
|
| 54 | + protected function _set_hooks_properties() |
|
| 55 | + { |
|
| 56 | + $this->_name = 'pricing'; |
|
| 57 | + |
|
| 58 | + //capability check |
|
| 59 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_default_prices', |
|
| 60 | + 'advanced_ticket_datetime_metabox') |
|
| 61 | + ) { |
|
| 62 | + return; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + //if we were going to add our own metaboxes we'd use the below. |
|
| 67 | + $this->_metaboxes = array( |
|
| 68 | + 0 => array( |
|
| 69 | + 'page_route' => array('edit', 'create_new'), |
|
| 70 | + 'func' => 'pricing_metabox', |
|
| 71 | + 'label' => __('Event Tickets & Datetimes', 'event_espresso'), |
|
| 72 | + 'priority' => 'high', |
|
| 73 | + 'context' => 'normal' |
|
| 74 | + ), |
|
| 75 | + |
|
| 76 | + );/**/ |
|
| 77 | + |
|
| 78 | + $this->_remove_metaboxes = array( |
|
| 79 | + 0 => array( |
|
| 80 | + 'page_route' => array('edit', 'create_new'), |
|
| 81 | + 'id' => 'espresso_event_editor_tickets', |
|
| 82 | + 'context' => 'normal' |
|
| 83 | + ) |
|
| 84 | + ); |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
| 88 | + * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
| 89 | + * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
| 90 | + * |
|
| 91 | + * @since 4.6.7 |
|
| 92 | + * |
|
| 93 | + * @var array Expected an array returned with 'date' and 'time' keys. |
|
| 94 | + */ |
|
| 95 | + $this->_date_format_strings = apply_filters('FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
| 96 | + array( |
|
| 97 | + 'date' => 'Y-m-d', |
|
| 98 | + 'time' => 'h:i a' |
|
| 99 | + )); |
|
| 100 | + |
|
| 101 | + //validate |
|
| 102 | + $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) ? $this->_date_format_strings['date'] : null; |
|
| 103 | + $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) ? $this->_date_format_strings['time'] : null; |
|
| 104 | + |
|
| 105 | + //validate format strings |
|
| 106 | + $format_validation = EEH_DTT_Helper::validate_format_string($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']); |
|
| 107 | + if (is_array($format_validation)) { |
|
| 108 | + $msg = '<p>' . sprintf(__('The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
| 109 | + 'event_espresso'), |
|
| 110 | + $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']) . '</p><ul>'; |
|
| 111 | + foreach ($format_validation as $error) { |
|
| 112 | + $msg .= '<li>' . $error . '</li>'; |
|
| 113 | + } |
|
| 114 | + $msg .= '</ul></p><p>' . sprintf(__('%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
| 115 | + 'event_espresso'), '<span style="color:#D54E21;">', '</span>') . '</p>'; |
|
| 116 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 117 | + $this->_date_format_strings = array( |
|
| 118 | + 'date' => 'Y-m-d', |
|
| 119 | + 'time' => 'h:i a' |
|
| 120 | + ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + $this->_scripts_styles = array( |
|
| 125 | + 'registers' => array( |
|
| 126 | + 'ee-tickets-datetimes-css' => array( |
|
| 127 | + 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
| 128 | + 'type' => 'css' |
|
| 129 | + ), |
|
| 130 | + 'ee-dtt-ticket-metabox' => array( |
|
| 131 | + 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
| 132 | + 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore') |
|
| 133 | + ) |
|
| 134 | + ), |
|
| 135 | + 'deregisters' => array( |
|
| 136 | + 'event-editor-css' => array('type' => 'css'), |
|
| 137 | + 'event-datetime-metabox' => array('type' => 'js') |
|
| 138 | + ), |
|
| 139 | + 'enqueues' => array( |
|
| 140 | + 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
| 141 | + 'ee-dtt-ticket-metabox' => array('edit', 'create_new') |
|
| 142 | + ), |
|
| 143 | + 'localize' => array( |
|
| 144 | + 'ee-dtt-ticket-metabox' => array( |
|
| 145 | + 'DTT_TRASH_BLOCK' => array( |
|
| 146 | + 'main_warning' => __('The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
| 147 | + 'event_espresso'), |
|
| 148 | + 'after_warning' => __('In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
| 149 | + 'event_espresso'), |
|
| 150 | + 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' . __('Cancel', |
|
| 151 | + 'event_espresso') . '</button>', |
|
| 152 | + 'single_warning_from_tkt' => __('The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
| 153 | + 'event_espresso'), |
|
| 154 | + 'single_warning_from_dtt' => __('The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
| 155 | + 'event_espresso'), |
|
| 156 | + 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' . __('Dismiss', |
|
| 157 | + 'event_espresso') . '</button>' |
|
| 158 | + ), |
|
| 159 | + 'DTT_ERROR_MSG' => array( |
|
| 160 | + 'no_ticket_name' => __('General Admission', 'event_espresso'), |
|
| 161 | + 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' . __('Dismiss', |
|
| 162 | + 'event_espresso') . '</button></div>' |
|
| 163 | + ), |
|
| 164 | + 'DTT_OVERSELL_WARNING' => array( |
|
| 165 | + 'datetime_ticket' => __('You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
| 166 | + 'event_espresso'), |
|
| 167 | + 'ticket_datetime' => __('You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
| 168 | + 'event_espresso') |
|
| 169 | + ), |
|
| 170 | + 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats($this->_date_format_strings['date'], |
|
| 171 | + $this->_date_format_strings['time']), |
|
| 172 | + 'DTT_START_OF_WEEK' => array('dayValue' => (int)get_option('start_of_week')) |
|
| 173 | + ) |
|
| 174 | + ) |
|
| 175 | + ); |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + add_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
| 179 | + array($this, 'autosave_handling'), 10); |
|
| 180 | + add_filter('FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 181 | + array($this, 'caf_updates'), 10); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | 184 | |
| 185 | - public function caf_updates($update_callbacks) |
|
| 186 | - { |
|
| 187 | - foreach ($update_callbacks as $key => $callback) { |
|
| 188 | - if ($callback[1] == '_default_tickets_update') { |
|
| 189 | - unset($update_callbacks[$key]); |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - $update_callbacks[] = array($this, 'dtt_and_tickets_caf_update'); |
|
| 194 | - |
|
| 195 | - return $update_callbacks; |
|
| 196 | - } |
|
| 185 | + public function caf_updates($update_callbacks) |
|
| 186 | + { |
|
| 187 | + foreach ($update_callbacks as $key => $callback) { |
|
| 188 | + if ($callback[1] == '_default_tickets_update') { |
|
| 189 | + unset($update_callbacks[$key]); |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + $update_callbacks[] = array($this, 'dtt_and_tickets_caf_update'); |
|
| 194 | + |
|
| 195 | + return $update_callbacks; |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | 198 | |
| 199 | - /** |
|
| 200 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 201 | - * |
|
| 202 | - * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 203 | - * @param array $data The request data from the form |
|
| 204 | - * |
|
| 205 | - * @return bool success or fail |
|
| 206 | - */ |
|
| 207 | - public function dtt_and_tickets_caf_update($evtobj, $data) |
|
| 208 | - { |
|
| 209 | - //first we need to start with datetimes cause they are the "root" items attached to events. |
|
| 210 | - $saved_dtts = $this->_update_dtts($evtobj, $data); |
|
| 211 | - //next tackle the tickets (and prices?) |
|
| 212 | - $this->_update_tkts($evtobj, $saved_dtts, $data); |
|
| 213 | - } |
|
| 199 | + /** |
|
| 200 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 201 | + * |
|
| 202 | + * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 203 | + * @param array $data The request data from the form |
|
| 204 | + * |
|
| 205 | + * @return bool success or fail |
|
| 206 | + */ |
|
| 207 | + public function dtt_and_tickets_caf_update($evtobj, $data) |
|
| 208 | + { |
|
| 209 | + //first we need to start with datetimes cause they are the "root" items attached to events. |
|
| 210 | + $saved_dtts = $this->_update_dtts($evtobj, $data); |
|
| 211 | + //next tackle the tickets (and prices?) |
|
| 212 | + $this->_update_tkts($evtobj, $saved_dtts, $data); |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | 215 | |
| 216 | - /** |
|
| 217 | - * update event_datetimes |
|
| 218 | - * |
|
| 219 | - * @param EE_Event $evt_obj Event being updated |
|
| 220 | - * @param array $data the request data from the form |
|
| 221 | - * |
|
| 222 | - * @return EE_Datetime[] |
|
| 223 | - */ |
|
| 224 | - protected function _update_dtts($evt_obj, $data) |
|
| 225 | - { |
|
| 226 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 227 | - $saved_dtt_ids = array(); |
|
| 228 | - $saved_dtt_objs = array(); |
|
| 229 | - |
|
| 230 | - foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 231 | - //trim all values to ensure any excess whitespace is removed. |
|
| 232 | - $dtt = array_map( |
|
| 233 | - function ($datetime_data) { |
|
| 234 | - return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
| 235 | - }, |
|
| 236 | - $dtt |
|
| 237 | - ); |
|
| 238 | - $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] : $dtt['DTT_EVT_start']; |
|
| 239 | - $datetime_values = array( |
|
| 240 | - 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 241 | - 'DTT_name' => ! empty($dtt['DTT_name']) ? $dtt['DTT_name'] : '', |
|
| 242 | - 'DTT_description' => ! empty($dtt['DTT_description']) ? $dtt['DTT_description'] : '', |
|
| 243 | - 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 244 | - 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 245 | - 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 246 | - 'DTT_order' => ! isset($dtt['DTT_order']) ? $row : $dtt['DTT_order'], |
|
| 247 | - ); |
|
| 216 | + /** |
|
| 217 | + * update event_datetimes |
|
| 218 | + * |
|
| 219 | + * @param EE_Event $evt_obj Event being updated |
|
| 220 | + * @param array $data the request data from the form |
|
| 221 | + * |
|
| 222 | + * @return EE_Datetime[] |
|
| 223 | + */ |
|
| 224 | + protected function _update_dtts($evt_obj, $data) |
|
| 225 | + { |
|
| 226 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 227 | + $saved_dtt_ids = array(); |
|
| 228 | + $saved_dtt_objs = array(); |
|
| 229 | + |
|
| 230 | + foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 231 | + //trim all values to ensure any excess whitespace is removed. |
|
| 232 | + $dtt = array_map( |
|
| 233 | + function ($datetime_data) { |
|
| 234 | + return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
| 235 | + }, |
|
| 236 | + $dtt |
|
| 237 | + ); |
|
| 238 | + $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] : $dtt['DTT_EVT_start']; |
|
| 239 | + $datetime_values = array( |
|
| 240 | + 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 241 | + 'DTT_name' => ! empty($dtt['DTT_name']) ? $dtt['DTT_name'] : '', |
|
| 242 | + 'DTT_description' => ! empty($dtt['DTT_description']) ? $dtt['DTT_description'] : '', |
|
| 243 | + 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 244 | + 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 245 | + 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 246 | + 'DTT_order' => ! isset($dtt['DTT_order']) ? $row : $dtt['DTT_order'], |
|
| 247 | + ); |
|
| 248 | 248 | |
| 249 | - //if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
| 249 | + //if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
| 250 | 250 | |
| 251 | - if ( ! empty($dtt['DTT_ID'])) { |
|
| 252 | - $DTM = EE_Registry::instance()->load_model('Datetime', array($timezone))->get_one_by_ID($dtt['DTT_ID']); |
|
| 251 | + if ( ! empty($dtt['DTT_ID'])) { |
|
| 252 | + $DTM = EE_Registry::instance()->load_model('Datetime', array($timezone))->get_one_by_ID($dtt['DTT_ID']); |
|
| 253 | 253 | |
| 254 | - //set date and time format according to what is set in this class. |
|
| 255 | - $DTM->set_date_format($this->_date_format_strings['date']); |
|
| 256 | - $DTM->set_time_format($this->_date_format_strings['time']); |
|
| 254 | + //set date and time format according to what is set in this class. |
|
| 255 | + $DTM->set_date_format($this->_date_format_strings['date']); |
|
| 256 | + $DTM->set_time_format($this->_date_format_strings['time']); |
|
| 257 | 257 | |
| 258 | - foreach ($datetime_values as $field => $value) { |
|
| 259 | - $DTM->set($field, $value); |
|
| 260 | - } |
|
| 258 | + foreach ($datetime_values as $field => $value) { |
|
| 259 | + $DTM->set($field, $value); |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. |
|
| 263 | - // We need to do this so we dont' TRASH the parent DTT.(save the ID for both key and value to avoid duplications) |
|
| 264 | - $saved_dtt_ids[$DTM->ID()] = $DTM->ID(); |
|
| 262 | + // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. |
|
| 263 | + // We need to do this so we dont' TRASH the parent DTT.(save the ID for both key and value to avoid duplications) |
|
| 264 | + $saved_dtt_ids[$DTM->ID()] = $DTM->ID(); |
|
| 265 | 265 | |
| 266 | - } else { |
|
| 267 | - $DTM = EE_Registry::instance()->load_class( |
|
| 268 | - 'Datetime', |
|
| 269 | - array( |
|
| 270 | - $datetime_values, |
|
| 271 | - $timezone, |
|
| 272 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
| 273 | - ), |
|
| 274 | - false, |
|
| 275 | - false |
|
| 276 | - ); |
|
| 266 | + } else { |
|
| 267 | + $DTM = EE_Registry::instance()->load_class( |
|
| 268 | + 'Datetime', |
|
| 269 | + array( |
|
| 270 | + $datetime_values, |
|
| 271 | + $timezone, |
|
| 272 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
| 273 | + ), |
|
| 274 | + false, |
|
| 275 | + false |
|
| 276 | + ); |
|
| 277 | 277 | |
| 278 | - foreach ($datetime_values as $field => $value) { |
|
| 279 | - $DTM->set($field, $value); |
|
| 280 | - } |
|
| 281 | - } |
|
| 278 | + foreach ($datetime_values as $field => $value) { |
|
| 279 | + $DTM->set($field, $value); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | 283 | |
| 284 | - $DTM->save(); |
|
| 285 | - $DTM = $evt_obj->_add_relation_to($DTM, 'Datetime'); |
|
| 286 | - $evt_obj->save(); |
|
| 284 | + $DTM->save(); |
|
| 285 | + $DTM = $evt_obj->_add_relation_to($DTM, 'Datetime'); |
|
| 286 | + $evt_obj->save(); |
|
| 287 | 287 | |
| 288 | - //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 289 | - if ($DTM->get_raw('DTT_EVT_start') > $DTM->get_raw('DTT_EVT_end')) { |
|
| 290 | - $DTM->set('DTT_EVT_end', $DTM->get('DTT_EVT_start')); |
|
| 291 | - $DTM = EEH_DTT_Helper::date_time_add($DTM, 'DTT_EVT_end', 'days'); |
|
| 292 | - $DTM->save(); |
|
| 293 | - } |
|
| 288 | + //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 289 | + if ($DTM->get_raw('DTT_EVT_start') > $DTM->get_raw('DTT_EVT_end')) { |
|
| 290 | + $DTM->set('DTT_EVT_end', $DTM->get('DTT_EVT_start')); |
|
| 291 | + $DTM = EEH_DTT_Helper::date_time_add($DTM, 'DTT_EVT_end', 'days'); |
|
| 292 | + $DTM->save(); |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | - // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
| 296 | - // because it is possible there was a new one created for the autosave. |
|
| 297 | - // (save the ID for both key and value to avoid duplications) |
|
| 298 | - $saved_dtt_ids[$DTM->ID()] = $DTM->ID(); |
|
| 299 | - $saved_dtt_objs[$row] = $DTM; |
|
| 295 | + // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
| 296 | + // because it is possible there was a new one created for the autosave. |
|
| 297 | + // (save the ID for both key and value to avoid duplications) |
|
| 298 | + $saved_dtt_ids[$DTM->ID()] = $DTM->ID(); |
|
| 299 | + $saved_dtt_objs[$row] = $DTM; |
|
| 300 | 300 | |
| 301 | - //todo if ANY of these updates fail then we want the appropriate global error message. |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - //now we need to REMOVE any dtts that got deleted. Keep in mind that this process will only kick in for DTT's that don't have any DTT_sold on them. So its safe to permanently delete at this point. |
|
| 305 | - $old_datetimes = explode(',', $data['datetime_IDs']); |
|
| 306 | - $old_datetimes = $old_datetimes[0] == '' ? array() : $old_datetimes; |
|
| 307 | - |
|
| 308 | - if (is_array($old_datetimes)) { |
|
| 309 | - $dtts_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
| 310 | - foreach ($dtts_to_delete as $id) { |
|
| 311 | - $id = absint($id); |
|
| 312 | - if (empty($id)) { |
|
| 313 | - continue; |
|
| 314 | - } |
|
| 301 | + //todo if ANY of these updates fail then we want the appropriate global error message. |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + //now we need to REMOVE any dtts that got deleted. Keep in mind that this process will only kick in for DTT's that don't have any DTT_sold on them. So its safe to permanently delete at this point. |
|
| 305 | + $old_datetimes = explode(',', $data['datetime_IDs']); |
|
| 306 | + $old_datetimes = $old_datetimes[0] == '' ? array() : $old_datetimes; |
|
| 307 | + |
|
| 308 | + if (is_array($old_datetimes)) { |
|
| 309 | + $dtts_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
| 310 | + foreach ($dtts_to_delete as $id) { |
|
| 311 | + $id = absint($id); |
|
| 312 | + if (empty($id)) { |
|
| 313 | + continue; |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | - $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
| 316 | + $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
| 317 | 317 | |
| 318 | - //remove tkt relationships. |
|
| 319 | - $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
| 320 | - foreach ($related_tickets as $tkt) { |
|
| 321 | - $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
| 322 | - } |
|
| 318 | + //remove tkt relationships. |
|
| 319 | + $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
| 320 | + foreach ($related_tickets as $tkt) { |
|
| 321 | + $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | - $evt_obj->_remove_relation_to($id, 'Datetime'); |
|
| 325 | - $dtt_to_remove->refresh_cache_of_related_objects(); |
|
| 324 | + $evt_obj->_remove_relation_to($id, 'Datetime'); |
|
| 325 | + $dtt_to_remove->refresh_cache_of_related_objects(); |
|
| 326 | 326 | |
| 327 | - } |
|
| 328 | - } |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | 329 | |
| 330 | - return $saved_dtt_objs; |
|
| 331 | - } |
|
| 330 | + return $saved_dtt_objs; |
|
| 331 | + } |
|
| 332 | 332 | |
| 333 | 333 | |
| 334 | - /** |
|
| 335 | - * update tickets |
|
| 336 | - * |
|
| 337 | - * @param EE_Event $evtobj Event object being updated |
|
| 338 | - * @param EE_Datetime[] $saved_dtts an array of datetime ids being updated |
|
| 339 | - * @param array $data incoming request data |
|
| 340 | - * |
|
| 341 | - * @return EE_Ticket[] |
|
| 342 | - */ |
|
| 343 | - protected function _update_tkts($evtobj, $saved_dtts, $data) |
|
| 344 | - { |
|
| 345 | - |
|
| 346 | - $new_tkt = null; |
|
| 347 | - $new_default = null; |
|
| 348 | - //stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
| 349 | - $data = stripslashes_deep($data); |
|
| 350 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 351 | - $saved_tickets = $dtts_on_existing = array(); |
|
| 352 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 353 | - |
|
| 354 | - //load money helper |
|
| 355 | - |
|
| 356 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 334 | + /** |
|
| 335 | + * update tickets |
|
| 336 | + * |
|
| 337 | + * @param EE_Event $evtobj Event object being updated |
|
| 338 | + * @param EE_Datetime[] $saved_dtts an array of datetime ids being updated |
|
| 339 | + * @param array $data incoming request data |
|
| 340 | + * |
|
| 341 | + * @return EE_Ticket[] |
|
| 342 | + */ |
|
| 343 | + protected function _update_tkts($evtobj, $saved_dtts, $data) |
|
| 344 | + { |
|
| 345 | + |
|
| 346 | + $new_tkt = null; |
|
| 347 | + $new_default = null; |
|
| 348 | + //stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
| 349 | + $data = stripslashes_deep($data); |
|
| 350 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 351 | + $saved_tickets = $dtts_on_existing = array(); |
|
| 352 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 353 | + |
|
| 354 | + //load money helper |
|
| 355 | + |
|
| 356 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 357 | 357 | |
| 358 | - $update_prices = $create_new_TKT = false; |
|
| 358 | + $update_prices = $create_new_TKT = false; |
|
| 359 | 359 | |
| 360 | - //figure out what dtts were added to the ticket and what dtts were removed from the ticket in the session. |
|
| 360 | + //figure out what dtts were added to the ticket and what dtts were removed from the ticket in the session. |
|
| 361 | 361 | |
| 362 | - $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]); |
|
| 363 | - $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]); |
|
| 364 | - $dtts_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
| 365 | - $dtts_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
| 362 | + $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]); |
|
| 363 | + $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]); |
|
| 364 | + $dtts_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
| 365 | + $dtts_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
| 366 | 366 | |
| 367 | - // trim inputs to ensure any excess whitespace is removed. |
|
| 368 | - $tkt = array_map( |
|
| 369 | - function ($ticket_data) { |
|
| 370 | - return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
| 371 | - }, |
|
| 372 | - $tkt |
|
| 373 | - ); |
|
| 367 | + // trim inputs to ensure any excess whitespace is removed. |
|
| 368 | + $tkt = array_map( |
|
| 369 | + function ($ticket_data) { |
|
| 370 | + return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
| 371 | + }, |
|
| 372 | + $tkt |
|
| 373 | + ); |
|
| 374 | 374 | |
| 375 | - //note we are doing conversions to floats here instead of allowing EE_Money_Field to handle because we're doing calcs prior to using the models. |
|
| 376 | - //note incoming ['TKT_price'] value is already in standard notation (via js). |
|
| 377 | - $ticket_price = isset($tkt['TKT_price']) ? round((float)$tkt['TKT_price'], 3) : 0; |
|
| 375 | + //note we are doing conversions to floats here instead of allowing EE_Money_Field to handle because we're doing calcs prior to using the models. |
|
| 376 | + //note incoming ['TKT_price'] value is already in standard notation (via js). |
|
| 377 | + $ticket_price = isset($tkt['TKT_price']) ? round((float)$tkt['TKT_price'], 3) : 0; |
|
| 378 | 378 | |
| 379 | - //note incoming base price needs converted from localized value. |
|
| 380 | - $base_price = isset($tkt['TKT_base_price']) ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) : 0; |
|
| 381 | - //if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
| 382 | - $ticket_price = $ticket_price === 0 && $base_price !== 0 ? $base_price : $ticket_price; |
|
| 383 | - $base_price_id = isset($tkt['TKT_base_price_ID']) ? $tkt['TKT_base_price_ID'] : 0; |
|
| 379 | + //note incoming base price needs converted from localized value. |
|
| 380 | + $base_price = isset($tkt['TKT_base_price']) ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) : 0; |
|
| 381 | + //if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
| 382 | + $ticket_price = $ticket_price === 0 && $base_price !== 0 ? $base_price : $ticket_price; |
|
| 383 | + $base_price_id = isset($tkt['TKT_base_price_ID']) ? $tkt['TKT_base_price_ID'] : 0; |
|
| 384 | 384 | |
| 385 | - $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) ? $data['edit_prices'][$row] : array(); |
|
| 385 | + $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) ? $data['edit_prices'][$row] : array(); |
|
| 386 | 386 | |
| 387 | - $now = null; |
|
| 388 | - if (empty($tkt['TKT_start_date'])) { |
|
| 389 | - //lets' use now in the set timezone. |
|
| 390 | - $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
| 391 | - $tkt['TKT_start_date'] = $now->format($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']); |
|
| 392 | - } |
|
| 387 | + $now = null; |
|
| 388 | + if (empty($tkt['TKT_start_date'])) { |
|
| 389 | + //lets' use now in the set timezone. |
|
| 390 | + $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
| 391 | + $tkt['TKT_start_date'] = $now->format($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']); |
|
| 392 | + } |
|
| 393 | 393 | |
| 394 | - if (empty($tkt['TKT_end_date'])) { |
|
| 395 | - /** |
|
| 396 | - * set the TKT_end_date to the first datetime attached to the ticket. |
|
| 397 | - */ |
|
| 398 | - $first_dtt = $saved_dtts[reset($tkt_dtt_rows)]; |
|
| 399 | - $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_format_strings['date'] . ' ' . $this->_date_format_string['time']); |
|
| 400 | - } |
|
| 394 | + if (empty($tkt['TKT_end_date'])) { |
|
| 395 | + /** |
|
| 396 | + * set the TKT_end_date to the first datetime attached to the ticket. |
|
| 397 | + */ |
|
| 398 | + $first_dtt = $saved_dtts[reset($tkt_dtt_rows)]; |
|
| 399 | + $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_format_strings['date'] . ' ' . $this->_date_format_string['time']); |
|
| 400 | + } |
|
| 401 | 401 | |
| 402 | - $TKT_values = array( |
|
| 403 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 404 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 405 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 406 | - 'TKT_description' => ! empty($tkt['TKT_description']) && $tkt['TKT_description'] != __('You can modify this description', |
|
| 407 | - 'event_espresso') ? $tkt['TKT_description'] : '', |
|
| 408 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 409 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 410 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 411 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 412 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 413 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 414 | - 'TKT_row' => $row, |
|
| 415 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
| 416 | - 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
| 417 | - 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
| 418 | - 'TKT_price' => $ticket_price |
|
| 419 | - ); |
|
| 402 | + $TKT_values = array( |
|
| 403 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 404 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 405 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 406 | + 'TKT_description' => ! empty($tkt['TKT_description']) && $tkt['TKT_description'] != __('You can modify this description', |
|
| 407 | + 'event_espresso') ? $tkt['TKT_description'] : '', |
|
| 408 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 409 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 410 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 411 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 412 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 413 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 414 | + 'TKT_row' => $row, |
|
| 415 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
| 416 | + 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
| 417 | + 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
| 418 | + 'TKT_price' => $ticket_price |
|
| 419 | + ); |
|
| 420 | 420 | |
| 421 | 421 | |
| 422 | - //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
| 423 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 424 | - $TKT_values['TKT_ID'] = 0; |
|
| 425 | - $TKT_values['TKT_is_default'] = 0; |
|
| 426 | - $update_prices = true; |
|
| 427 | - } |
|
| 422 | + //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
| 423 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 424 | + $TKT_values['TKT_ID'] = 0; |
|
| 425 | + $TKT_values['TKT_is_default'] = 0; |
|
| 426 | + $update_prices = true; |
|
| 427 | + } |
|
| 428 | 428 | |
| 429 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 430 | - // we actually do our saves ahead of doing any add_relations to |
|
| 431 | - // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
| 432 | - // but DID have it's items modified. |
|
| 433 | - // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
| 434 | - // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 435 | - if (absint($TKT_values['TKT_ID'])) { |
|
| 436 | - $TKT = EE_Registry::instance()->load_model('Ticket', array($timezone))->get_one_by_ID($tkt['TKT_ID']); |
|
| 437 | - if ($TKT instanceof EE_Ticket) { |
|
| 429 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 430 | + // we actually do our saves ahead of doing any add_relations to |
|
| 431 | + // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
| 432 | + // but DID have it's items modified. |
|
| 433 | + // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
| 434 | + // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 435 | + if (absint($TKT_values['TKT_ID'])) { |
|
| 436 | + $TKT = EE_Registry::instance()->load_model('Ticket', array($timezone))->get_one_by_ID($tkt['TKT_ID']); |
|
| 437 | + if ($TKT instanceof EE_Ticket) { |
|
| 438 | 438 | |
| 439 | - $TKT = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed); |
|
| 440 | - // are there any registrations using this ticket ? |
|
| 441 | - $tickets_sold = $TKT->count_related( |
|
| 442 | - 'Registration', |
|
| 443 | - array( |
|
| 444 | - array( |
|
| 445 | - 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)) |
|
| 446 | - ) |
|
| 447 | - ) |
|
| 448 | - ); |
|
| 449 | - //set ticket formats |
|
| 450 | - $TKT->set_date_format($this->_date_format_strings['date']); |
|
| 451 | - $TKT->set_time_format($this->_date_format_strings['time']); |
|
| 439 | + $TKT = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed); |
|
| 440 | + // are there any registrations using this ticket ? |
|
| 441 | + $tickets_sold = $TKT->count_related( |
|
| 442 | + 'Registration', |
|
| 443 | + array( |
|
| 444 | + array( |
|
| 445 | + 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)) |
|
| 446 | + ) |
|
| 447 | + ) |
|
| 448 | + ); |
|
| 449 | + //set ticket formats |
|
| 450 | + $TKT->set_date_format($this->_date_format_strings['date']); |
|
| 451 | + $TKT->set_time_format($this->_date_format_strings['time']); |
|
| 452 | 452 | |
| 453 | - // let's just check the total price for the existing ticket |
|
| 454 | - // and determine if it matches the new total price. |
|
| 455 | - // if they are different then we create a new ticket (if tkts sold) |
|
| 456 | - // if they aren't different then we go ahead and modify existing ticket. |
|
| 457 | - $create_new_TKT = $tickets_sold > 0 && $ticket_price != $TKT->price() && ! $TKT->deleted() |
|
| 458 | - ? true : false; |
|
| 453 | + // let's just check the total price for the existing ticket |
|
| 454 | + // and determine if it matches the new total price. |
|
| 455 | + // if they are different then we create a new ticket (if tkts sold) |
|
| 456 | + // if they aren't different then we go ahead and modify existing ticket. |
|
| 457 | + $create_new_TKT = $tickets_sold > 0 && $ticket_price != $TKT->price() && ! $TKT->deleted() |
|
| 458 | + ? true : false; |
|
| 459 | 459 | |
| 460 | - //set new values |
|
| 461 | - foreach ($TKT_values as $field => $value) { |
|
| 462 | - if ($field === 'TKT_qty') { |
|
| 463 | - $TKT->set_qty($value); |
|
| 464 | - } else { |
|
| 465 | - $TKT->set($field, $value); |
|
| 466 | - } |
|
| 467 | - } |
|
| 460 | + //set new values |
|
| 461 | + foreach ($TKT_values as $field => $value) { |
|
| 462 | + if ($field === 'TKT_qty') { |
|
| 463 | + $TKT->set_qty($value); |
|
| 464 | + } else { |
|
| 465 | + $TKT->set($field, $value); |
|
| 466 | + } |
|
| 467 | + } |
|
| 468 | 468 | |
| 469 | - //if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
| 470 | - if ($create_new_TKT) { |
|
| 471 | - $new_tkt = $this->_duplicate_ticket($TKT, $price_rows, $ticket_price, $base_price, |
|
| 472 | - $base_price_id); |
|
| 473 | - } |
|
| 474 | - } |
|
| 469 | + //if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
| 470 | + if ($create_new_TKT) { |
|
| 471 | + $new_tkt = $this->_duplicate_ticket($TKT, $price_rows, $ticket_price, $base_price, |
|
| 472 | + $base_price_id); |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | 475 | |
| 476 | - } else { |
|
| 477 | - // no TKT_id so a new TKT |
|
| 478 | - $TKT = EE_Ticket::new_instance( |
|
| 479 | - $TKT_values, |
|
| 480 | - $timezone, |
|
| 481 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
| 482 | - ); |
|
| 483 | - if ($TKT instanceof EE_Ticket) { |
|
| 484 | - // make sure ticket has an ID of setting relations won't work |
|
| 485 | - $TKT->save(); |
|
| 486 | - $TKT = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed); |
|
| 487 | - $update_prices = true; |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - //make sure any current values have been saved. |
|
| 491 | - //$TKT->save(); |
|
| 476 | + } else { |
|
| 477 | + // no TKT_id so a new TKT |
|
| 478 | + $TKT = EE_Ticket::new_instance( |
|
| 479 | + $TKT_values, |
|
| 480 | + $timezone, |
|
| 481 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
| 482 | + ); |
|
| 483 | + if ($TKT instanceof EE_Ticket) { |
|
| 484 | + // make sure ticket has an ID of setting relations won't work |
|
| 485 | + $TKT->save(); |
|
| 486 | + $TKT = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed); |
|
| 487 | + $update_prices = true; |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + //make sure any current values have been saved. |
|
| 491 | + //$TKT->save(); |
|
| 492 | 492 | |
| 493 | - //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 494 | - if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 495 | - $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 496 | - $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 497 | - } |
|
| 493 | + //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 494 | + if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 495 | + $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 496 | + $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 497 | + } |
|
| 498 | 498 | |
| 499 | - //let's make sure the base price is handled |
|
| 500 | - $TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $TKT, $update_prices, $base_price, |
|
| 501 | - $base_price_id) : $TKT; |
|
| 499 | + //let's make sure the base price is handled |
|
| 500 | + $TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $TKT, $update_prices, $base_price, |
|
| 501 | + $base_price_id) : $TKT; |
|
| 502 | 502 | |
| 503 | - //add/update price_modifiers |
|
| 504 | - $TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $TKT, $update_prices) : $TKT; |
|
| 503 | + //add/update price_modifiers |
|
| 504 | + $TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $TKT, $update_prices) : $TKT; |
|
| 505 | 505 | |
| 506 | - //need to make sue that the TKT_price is accurate after saving the prices. |
|
| 507 | - $TKT->ensure_TKT_Price_correct(); |
|
| 506 | + //need to make sue that the TKT_price is accurate after saving the prices. |
|
| 507 | + $TKT->ensure_TKT_Price_correct(); |
|
| 508 | 508 | |
| 509 | - //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
| 510 | - if ( ! defined('DOING_AUTOSAVE')) { |
|
| 511 | - if ( ! empty($tkt['TKT_is_default_selector'])) { |
|
| 512 | - $update_prices = true; |
|
| 513 | - $new_default = clone $TKT; |
|
| 514 | - $new_default->set('TKT_ID', 0); |
|
| 515 | - $new_default->set('TKT_is_default', 1); |
|
| 516 | - $new_default->set('TKT_row', 1); |
|
| 517 | - $new_default->set('TKT_price', $ticket_price); |
|
| 518 | - //remove any dtt relations cause we DON'T want dtt relations attached (note this is just removing the cached relations in the object) |
|
| 519 | - $new_default->_remove_relations('Datetime'); |
|
| 520 | - //todo we need to add the current attached prices as new prices to the new default ticket. |
|
| 521 | - $new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices); |
|
| 522 | - //don't forget the base price! |
|
| 523 | - $new_default = $this->_add_prices_to_ticket(array(), $new_default, $update_prices, $base_price, |
|
| 524 | - $base_price_id); |
|
| 525 | - $new_default->save(); |
|
| 526 | - do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', $new_default, |
|
| 527 | - $row, $TKT, $data); |
|
| 528 | - } |
|
| 529 | - } |
|
| 509 | + //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
| 510 | + if ( ! defined('DOING_AUTOSAVE')) { |
|
| 511 | + if ( ! empty($tkt['TKT_is_default_selector'])) { |
|
| 512 | + $update_prices = true; |
|
| 513 | + $new_default = clone $TKT; |
|
| 514 | + $new_default->set('TKT_ID', 0); |
|
| 515 | + $new_default->set('TKT_is_default', 1); |
|
| 516 | + $new_default->set('TKT_row', 1); |
|
| 517 | + $new_default->set('TKT_price', $ticket_price); |
|
| 518 | + //remove any dtt relations cause we DON'T want dtt relations attached (note this is just removing the cached relations in the object) |
|
| 519 | + $new_default->_remove_relations('Datetime'); |
|
| 520 | + //todo we need to add the current attached prices as new prices to the new default ticket. |
|
| 521 | + $new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices); |
|
| 522 | + //don't forget the base price! |
|
| 523 | + $new_default = $this->_add_prices_to_ticket(array(), $new_default, $update_prices, $base_price, |
|
| 524 | + $base_price_id); |
|
| 525 | + $new_default->save(); |
|
| 526 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', $new_default, |
|
| 527 | + $row, $TKT, $data); |
|
| 528 | + } |
|
| 529 | + } |
|
| 530 | 530 | |
| 531 | 531 | |
| 532 | - //DO ALL dtt relationships for both current tickets and any archived tickets for the given dtt that are related to the current ticket. TODO... not sure exactly how we're going to do this considering we don't know what current ticket the archived tickets are related to (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
| 532 | + //DO ALL dtt relationships for both current tickets and any archived tickets for the given dtt that are related to the current ticket. TODO... not sure exactly how we're going to do this considering we don't know what current ticket the archived tickets are related to (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
| 533 | 533 | |
| 534 | 534 | |
| 535 | - //let's assign any tickets that have been setup to the saved_tickets tracker |
|
| 536 | - //save existing TKT |
|
| 537 | - $TKT->save(); |
|
| 538 | - if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
| 539 | - //save new TKT |
|
| 540 | - $new_tkt->save(); |
|
| 541 | - //add new ticket to array |
|
| 542 | - $saved_tickets[$new_tkt->ID()] = $new_tkt; |
|
| 535 | + //let's assign any tickets that have been setup to the saved_tickets tracker |
|
| 536 | + //save existing TKT |
|
| 537 | + $TKT->save(); |
|
| 538 | + if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
| 539 | + //save new TKT |
|
| 540 | + $new_tkt->save(); |
|
| 541 | + //add new ticket to array |
|
| 542 | + $saved_tickets[$new_tkt->ID()] = $new_tkt; |
|
| 543 | 543 | |
| 544 | - do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', $new_tkt, $row, $tkt, $data); |
|
| 544 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', $new_tkt, $row, $tkt, $data); |
|
| 545 | 545 | |
| 546 | - } else { |
|
| 547 | - //add tkt to saved tkts |
|
| 548 | - $saved_tickets[$TKT->ID()] = $TKT; |
|
| 546 | + } else { |
|
| 547 | + //add tkt to saved tkts |
|
| 548 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
| 549 | 549 | |
| 550 | - do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', $TKT, $row, $tkt, $data); |
|
| 551 | - } |
|
| 550 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', $TKT, $row, $tkt, $data); |
|
| 551 | + } |
|
| 552 | 552 | |
| 553 | - } |
|
| 554 | - |
|
| 555 | - // now we need to handle tickets actually "deleted permanently". |
|
| 556 | - // There are cases where we'd want this to happen |
|
| 557 | - // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
| 558 | - // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
| 559 | - // No sense in keeping all the related data in the db! |
|
| 560 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
| 561 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 562 | - |
|
| 563 | - foreach ($tickets_removed as $id) { |
|
| 564 | - $id = absint($id); |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + // now we need to handle tickets actually "deleted permanently". |
|
| 556 | + // There are cases where we'd want this to happen |
|
| 557 | + // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
| 558 | + // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
| 559 | + // No sense in keeping all the related data in the db! |
|
| 560 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
| 561 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 562 | + |
|
| 563 | + foreach ($tickets_removed as $id) { |
|
| 564 | + $id = absint($id); |
|
| 565 | 565 | |
| 566 | - //get the ticket for this id |
|
| 567 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 566 | + //get the ticket for this id |
|
| 567 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 568 | 568 | |
| 569 | - //if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
| 570 | - if ($tkt_to_remove->get('TKT_is_default')) { |
|
| 571 | - continue; |
|
| 572 | - } |
|
| 569 | + //if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
| 570 | + if ($tkt_to_remove->get('TKT_is_default')) { |
|
| 571 | + continue; |
|
| 572 | + } |
|
| 573 | 573 | |
| 574 | - // if this tkt has any registrations attached so then we just ARCHIVE |
|
| 575 | - // because we don't actually permanently delete these tickets. |
|
| 576 | - if ($tkt_to_remove->count_related('Registration') > 0) { |
|
| 577 | - $tkt_to_remove->delete(); |
|
| 578 | - continue; |
|
| 579 | - } |
|
| 574 | + // if this tkt has any registrations attached so then we just ARCHIVE |
|
| 575 | + // because we don't actually permanently delete these tickets. |
|
| 576 | + if ($tkt_to_remove->count_related('Registration') > 0) { |
|
| 577 | + $tkt_to_remove->delete(); |
|
| 578 | + continue; |
|
| 579 | + } |
|
| 580 | 580 | |
| 581 | - // need to get all the related datetimes on this ticket and remove from every single one of them |
|
| 582 | - // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 583 | - $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 581 | + // need to get all the related datetimes on this ticket and remove from every single one of them |
|
| 582 | + // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 583 | + $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 584 | 584 | |
| 585 | - foreach ($dtts as $dtt) { |
|
| 586 | - $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 587 | - } |
|
| 585 | + foreach ($dtts as $dtt) { |
|
| 586 | + $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 587 | + } |
|
| 588 | 588 | |
| 589 | - // need to do the same for prices (except these prices can also be deleted because again, |
|
| 590 | - // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 591 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
| 589 | + // need to do the same for prices (except these prices can also be deleted because again, |
|
| 590 | + // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 591 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
| 592 | 592 | |
| 593 | - do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
| 593 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
| 594 | 594 | |
| 595 | - // finally let's delete this ticket |
|
| 596 | - // (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 597 | - $tkt_to_remove->delete_permanently(); |
|
| 598 | - } |
|
| 595 | + // finally let's delete this ticket |
|
| 596 | + // (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 597 | + $tkt_to_remove->delete_permanently(); |
|
| 598 | + } |
|
| 599 | 599 | |
| 600 | - return $saved_tickets; |
|
| 601 | - } |
|
| 600 | + return $saved_tickets; |
|
| 601 | + } |
|
| 602 | 602 | |
| 603 | 603 | |
| 604 | - /** |
|
| 605 | - * |
|
| 606 | - * @access protected |
|
| 607 | - * |
|
| 608 | - * @param \EE_Ticket $ticket |
|
| 609 | - * @param \EE_Datetime[] $saved_datetimes |
|
| 610 | - * @param \EE_Datetime[] $added_datetimes |
|
| 611 | - * @param \EE_Datetime[] $removed_datetimes |
|
| 612 | - * |
|
| 613 | - * @return \EE_Ticket |
|
| 614 | - * @throws \EE_Error |
|
| 615 | - */ |
|
| 616 | - protected function _update_ticket_datetimes( |
|
| 617 | - EE_Ticket $ticket, |
|
| 618 | - $saved_datetimes = array(), |
|
| 619 | - $added_datetimes = array(), |
|
| 620 | - $removed_datetimes = array() |
|
| 621 | - ) { |
|
| 622 | - |
|
| 623 | - // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
| 624 | - // and removing the ticket from datetimes it got removed from. |
|
| 625 | - |
|
| 626 | - // first let's add datetimes |
|
| 627 | - if ( ! empty($added_datetimes) && is_array($added_datetimes)) { |
|
| 628 | - foreach ($added_datetimes as $row_id) { |
|
| 629 | - $row_id = (int)$row_id; |
|
| 630 | - if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
| 631 | - $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
| 632 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 633 | - // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
| 634 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 635 | - $saved_datetimes[$row_id]->increase_sold($ticket->sold()); |
|
| 636 | - $saved_datetimes[$row_id]->save(); |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - // then remove datetimes |
|
| 642 | - if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
| 643 | - foreach ($removed_datetimes as $row_id) { |
|
| 644 | - $row_id = (int)$row_id; |
|
| 645 | - // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
| 646 | - // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
| 647 | - if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
| 648 | - $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
| 649 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 650 | - // If so, then we need to remove it's sold from the DTT_sold. |
|
| 651 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 652 | - $saved_datetimes[$row_id]->decrease_sold($ticket->sold()); |
|
| 653 | - $saved_datetimes[$row_id]->save(); |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - } |
|
| 657 | - } |
|
| 658 | - // cap ticket qty by datetime reg limits |
|
| 659 | - $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
| 660 | - |
|
| 661 | - return $ticket; |
|
| 662 | - } |
|
| 604 | + /** |
|
| 605 | + * |
|
| 606 | + * @access protected |
|
| 607 | + * |
|
| 608 | + * @param \EE_Ticket $ticket |
|
| 609 | + * @param \EE_Datetime[] $saved_datetimes |
|
| 610 | + * @param \EE_Datetime[] $added_datetimes |
|
| 611 | + * @param \EE_Datetime[] $removed_datetimes |
|
| 612 | + * |
|
| 613 | + * @return \EE_Ticket |
|
| 614 | + * @throws \EE_Error |
|
| 615 | + */ |
|
| 616 | + protected function _update_ticket_datetimes( |
|
| 617 | + EE_Ticket $ticket, |
|
| 618 | + $saved_datetimes = array(), |
|
| 619 | + $added_datetimes = array(), |
|
| 620 | + $removed_datetimes = array() |
|
| 621 | + ) { |
|
| 622 | + |
|
| 623 | + // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
| 624 | + // and removing the ticket from datetimes it got removed from. |
|
| 625 | + |
|
| 626 | + // first let's add datetimes |
|
| 627 | + if ( ! empty($added_datetimes) && is_array($added_datetimes)) { |
|
| 628 | + foreach ($added_datetimes as $row_id) { |
|
| 629 | + $row_id = (int)$row_id; |
|
| 630 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
| 631 | + $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
| 632 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 633 | + // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
| 634 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 635 | + $saved_datetimes[$row_id]->increase_sold($ticket->sold()); |
|
| 636 | + $saved_datetimes[$row_id]->save(); |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + // then remove datetimes |
|
| 642 | + if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
| 643 | + foreach ($removed_datetimes as $row_id) { |
|
| 644 | + $row_id = (int)$row_id; |
|
| 645 | + // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
| 646 | + // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
| 647 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
| 648 | + $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
| 649 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 650 | + // If so, then we need to remove it's sold from the DTT_sold. |
|
| 651 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 652 | + $saved_datetimes[$row_id]->decrease_sold($ticket->sold()); |
|
| 653 | + $saved_datetimes[$row_id]->save(); |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | + } |
|
| 657 | + } |
|
| 658 | + // cap ticket qty by datetime reg limits |
|
| 659 | + $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
| 660 | + |
|
| 661 | + return $ticket; |
|
| 662 | + } |
|
| 663 | 663 | |
| 664 | 664 | |
| 665 | - /** |
|
| 666 | - * |
|
| 667 | - * @access protected |
|
| 668 | - * |
|
| 669 | - * @param \EE_Ticket $ticket |
|
| 670 | - * @param array $price_rows |
|
| 671 | - * @param int $ticket_price |
|
| 672 | - * @param int $base_price |
|
| 673 | - * @param int $base_price_id |
|
| 674 | - * |
|
| 675 | - * @return \EE_Ticket |
|
| 676 | - * @throws \EE_Error |
|
| 677 | - */ |
|
| 678 | - protected function _duplicate_ticket( |
|
| 679 | - EE_Ticket $ticket, |
|
| 680 | - $price_rows = array(), |
|
| 681 | - $ticket_price = 0, |
|
| 682 | - $base_price = 0, |
|
| 683 | - $base_price_id = 0 |
|
| 684 | - ) { |
|
| 685 | - |
|
| 686 | - // create new ticket that's a copy of the existing |
|
| 687 | - // except a new id of course (and not archived) |
|
| 688 | - // AND has the new TKT_price associated with it. |
|
| 689 | - $new_ticket = clone($ticket); |
|
| 690 | - $new_ticket->set('TKT_ID', 0); |
|
| 691 | - $new_ticket->set('TKT_deleted', 0); |
|
| 692 | - $new_ticket->set('TKT_price', $ticket_price); |
|
| 693 | - $new_ticket->set('TKT_sold', 0); |
|
| 694 | - // let's get a new ID for this ticket |
|
| 695 | - $new_ticket->save(); |
|
| 696 | - // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
| 697 | - $datetimes_on_existing = $ticket->get_many_related('Datetime'); |
|
| 698 | - $new_ticket = $this->_update_ticket_datetimes( |
|
| 699 | - $new_ticket, |
|
| 700 | - $datetimes_on_existing, |
|
| 701 | - array_keys($datetimes_on_existing) |
|
| 702 | - ); |
|
| 703 | - |
|
| 704 | - // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
| 705 | - // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
| 706 | - // available. |
|
| 707 | - if ($ticket->sold() > 0) { |
|
| 708 | - $new_qty = $ticket->qty() - $ticket->sold(); |
|
| 709 | - $new_ticket->set_qty($new_qty); |
|
| 710 | - } |
|
| 711 | - //now we update the prices just for this ticket |
|
| 712 | - $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
| 713 | - //and we update the base price |
|
| 714 | - $new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id); |
|
| 715 | - |
|
| 716 | - return $new_ticket; |
|
| 717 | - } |
|
| 665 | + /** |
|
| 666 | + * |
|
| 667 | + * @access protected |
|
| 668 | + * |
|
| 669 | + * @param \EE_Ticket $ticket |
|
| 670 | + * @param array $price_rows |
|
| 671 | + * @param int $ticket_price |
|
| 672 | + * @param int $base_price |
|
| 673 | + * @param int $base_price_id |
|
| 674 | + * |
|
| 675 | + * @return \EE_Ticket |
|
| 676 | + * @throws \EE_Error |
|
| 677 | + */ |
|
| 678 | + protected function _duplicate_ticket( |
|
| 679 | + EE_Ticket $ticket, |
|
| 680 | + $price_rows = array(), |
|
| 681 | + $ticket_price = 0, |
|
| 682 | + $base_price = 0, |
|
| 683 | + $base_price_id = 0 |
|
| 684 | + ) { |
|
| 685 | + |
|
| 686 | + // create new ticket that's a copy of the existing |
|
| 687 | + // except a new id of course (and not archived) |
|
| 688 | + // AND has the new TKT_price associated with it. |
|
| 689 | + $new_ticket = clone($ticket); |
|
| 690 | + $new_ticket->set('TKT_ID', 0); |
|
| 691 | + $new_ticket->set('TKT_deleted', 0); |
|
| 692 | + $new_ticket->set('TKT_price', $ticket_price); |
|
| 693 | + $new_ticket->set('TKT_sold', 0); |
|
| 694 | + // let's get a new ID for this ticket |
|
| 695 | + $new_ticket->save(); |
|
| 696 | + // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
| 697 | + $datetimes_on_existing = $ticket->get_many_related('Datetime'); |
|
| 698 | + $new_ticket = $this->_update_ticket_datetimes( |
|
| 699 | + $new_ticket, |
|
| 700 | + $datetimes_on_existing, |
|
| 701 | + array_keys($datetimes_on_existing) |
|
| 702 | + ); |
|
| 703 | + |
|
| 704 | + // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
| 705 | + // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
| 706 | + // available. |
|
| 707 | + if ($ticket->sold() > 0) { |
|
| 708 | + $new_qty = $ticket->qty() - $ticket->sold(); |
|
| 709 | + $new_ticket->set_qty($new_qty); |
|
| 710 | + } |
|
| 711 | + //now we update the prices just for this ticket |
|
| 712 | + $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
| 713 | + //and we update the base price |
|
| 714 | + $new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id); |
|
| 715 | + |
|
| 716 | + return $new_ticket; |
|
| 717 | + } |
|
| 718 | 718 | |
| 719 | 719 | |
| 720 | - /** |
|
| 721 | - * This attaches a list of given prices to a ticket. |
|
| 722 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 723 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 724 | - * price info and prices are automatically "archived" via the ticket. |
|
| 725 | - * |
|
| 726 | - * @access private |
|
| 727 | - * |
|
| 728 | - * @param array $prices Array of prices from the form. |
|
| 729 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 730 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 731 | - * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
| 732 | - * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
| 733 | - * |
|
| 734 | - * @return EE_Ticket |
|
| 735 | - */ |
|
| 736 | - protected function _add_prices_to_ticket( |
|
| 737 | - $prices = array(), |
|
| 738 | - EE_Ticket $ticket, |
|
| 739 | - $new_prices = false, |
|
| 740 | - $base_price = false, |
|
| 741 | - $base_price_id = false |
|
| 742 | - ) { |
|
| 743 | - |
|
| 744 | - //let's just get any current prices that may exist on the given ticket so we can remove any prices that got trashed in this session. |
|
| 745 | - $current_prices_on_ticket = $base_price !== false ? $ticket->base_price(true) : $ticket->price_modifiers(); |
|
| 746 | - |
|
| 747 | - $updated_prices = array(); |
|
| 748 | - |
|
| 749 | - // if $base_price ! FALSE then updating a base price. |
|
| 750 | - if ($base_price !== false) { |
|
| 751 | - $prices[1] = array( |
|
| 752 | - 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
| 753 | - 'PRT_ID' => 1, |
|
| 754 | - 'PRC_amount' => $base_price, |
|
| 755 | - 'PRC_name' => $ticket->get('TKT_name'), |
|
| 756 | - 'PRC_desc' => $ticket->get('TKT_description') |
|
| 757 | - ); |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - //possibly need to save tkt |
|
| 761 | - if ( ! $ticket->ID()) { |
|
| 762 | - $ticket->save(); |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - foreach ($prices as $row => $prc) { |
|
| 766 | - $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
| 767 | - if (empty($prt_id)) { |
|
| 768 | - continue; |
|
| 769 | - } //prices MUST have a price type id. |
|
| 770 | - $PRC_values = array( |
|
| 771 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 772 | - 'PRT_ID' => $prt_id, |
|
| 773 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 774 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 775 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 776 | - 'PRC_is_default' => false, |
|
| 777 | - //make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
| 778 | - 'PRC_order' => $row |
|
| 779 | - ); |
|
| 780 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 781 | - $PRC_values['PRC_ID'] = 0; |
|
| 782 | - $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
| 783 | - } else { |
|
| 784 | - $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 785 | - //update this price with new values |
|
| 786 | - foreach ($PRC_values as $field => $newprc) { |
|
| 787 | - $PRC->set($field, $newprc); |
|
| 788 | - } |
|
| 789 | - } |
|
| 790 | - $PRC->save(); |
|
| 791 | - $prcid = $PRC->ID(); |
|
| 792 | - $updated_prices[$prcid] = $PRC; |
|
| 793 | - $ticket->_add_relation_to($PRC, 'Price'); |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - //now let's remove any prices that got removed from the ticket |
|
| 797 | - if ( ! empty ($current_prices_on_ticket)) { |
|
| 798 | - $current = array_keys($current_prices_on_ticket); |
|
| 799 | - $updated = array_keys($updated_prices); |
|
| 800 | - $prices_to_remove = array_diff($current, $updated); |
|
| 801 | - if ( ! empty($prices_to_remove)) { |
|
| 802 | - foreach ($prices_to_remove as $prc_id) { |
|
| 803 | - $p = $current_prices_on_ticket[$prc_id]; |
|
| 804 | - $ticket->_remove_relation_to($p, 'Price'); |
|
| 720 | + /** |
|
| 721 | + * This attaches a list of given prices to a ticket. |
|
| 722 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 723 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 724 | + * price info and prices are automatically "archived" via the ticket. |
|
| 725 | + * |
|
| 726 | + * @access private |
|
| 727 | + * |
|
| 728 | + * @param array $prices Array of prices from the form. |
|
| 729 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 730 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 731 | + * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
| 732 | + * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
| 733 | + * |
|
| 734 | + * @return EE_Ticket |
|
| 735 | + */ |
|
| 736 | + protected function _add_prices_to_ticket( |
|
| 737 | + $prices = array(), |
|
| 738 | + EE_Ticket $ticket, |
|
| 739 | + $new_prices = false, |
|
| 740 | + $base_price = false, |
|
| 741 | + $base_price_id = false |
|
| 742 | + ) { |
|
| 743 | + |
|
| 744 | + //let's just get any current prices that may exist on the given ticket so we can remove any prices that got trashed in this session. |
|
| 745 | + $current_prices_on_ticket = $base_price !== false ? $ticket->base_price(true) : $ticket->price_modifiers(); |
|
| 746 | + |
|
| 747 | + $updated_prices = array(); |
|
| 748 | + |
|
| 749 | + // if $base_price ! FALSE then updating a base price. |
|
| 750 | + if ($base_price !== false) { |
|
| 751 | + $prices[1] = array( |
|
| 752 | + 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
| 753 | + 'PRT_ID' => 1, |
|
| 754 | + 'PRC_amount' => $base_price, |
|
| 755 | + 'PRC_name' => $ticket->get('TKT_name'), |
|
| 756 | + 'PRC_desc' => $ticket->get('TKT_description') |
|
| 757 | + ); |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + //possibly need to save tkt |
|
| 761 | + if ( ! $ticket->ID()) { |
|
| 762 | + $ticket->save(); |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + foreach ($prices as $row => $prc) { |
|
| 766 | + $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
| 767 | + if (empty($prt_id)) { |
|
| 768 | + continue; |
|
| 769 | + } //prices MUST have a price type id. |
|
| 770 | + $PRC_values = array( |
|
| 771 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 772 | + 'PRT_ID' => $prt_id, |
|
| 773 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 774 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 775 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 776 | + 'PRC_is_default' => false, |
|
| 777 | + //make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
| 778 | + 'PRC_order' => $row |
|
| 779 | + ); |
|
| 780 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 781 | + $PRC_values['PRC_ID'] = 0; |
|
| 782 | + $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
| 783 | + } else { |
|
| 784 | + $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 785 | + //update this price with new values |
|
| 786 | + foreach ($PRC_values as $field => $newprc) { |
|
| 787 | + $PRC->set($field, $newprc); |
|
| 788 | + } |
|
| 789 | + } |
|
| 790 | + $PRC->save(); |
|
| 791 | + $prcid = $PRC->ID(); |
|
| 792 | + $updated_prices[$prcid] = $PRC; |
|
| 793 | + $ticket->_add_relation_to($PRC, 'Price'); |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + //now let's remove any prices that got removed from the ticket |
|
| 797 | + if ( ! empty ($current_prices_on_ticket)) { |
|
| 798 | + $current = array_keys($current_prices_on_ticket); |
|
| 799 | + $updated = array_keys($updated_prices); |
|
| 800 | + $prices_to_remove = array_diff($current, $updated); |
|
| 801 | + if ( ! empty($prices_to_remove)) { |
|
| 802 | + foreach ($prices_to_remove as $prc_id) { |
|
| 803 | + $p = $current_prices_on_ticket[$prc_id]; |
|
| 804 | + $ticket->_remove_relation_to($p, 'Price'); |
|
| 805 | 805 | |
| 806 | - //delete permanently the price |
|
| 807 | - $p->delete_permanently(); |
|
| 808 | - } |
|
| 809 | - } |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - return $ticket; |
|
| 813 | - } |
|
| 806 | + //delete permanently the price |
|
| 807 | + $p->delete_permanently(); |
|
| 808 | + } |
|
| 809 | + } |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + return $ticket; |
|
| 813 | + } |
|
| 814 | 814 | |
| 815 | 815 | |
| 816 | - public function autosave_handling($event_admin_obj) |
|
| 817 | - { |
|
| 818 | - return $event_admin_obj; //doing nothing for the moment. |
|
| 819 | - //todo when I get to this remember that I need to set the template args on the $event_admin_obj (use the set_template_args() method) |
|
| 820 | - |
|
| 821 | - /** |
|
| 822 | - * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
| 823 | - * |
|
| 824 | - * 1. TKT_is_default_selector (visible) |
|
| 825 | - * 2. TKT_is_default (hidden) |
|
| 826 | - * |
|
| 827 | - * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want this ticket to be saved as a default. |
|
| 828 | - * |
|
| 829 | - * The tricky part is, on an initial display on create or edit (or after manually updating), the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true if this is a create. However, after an autosave, users will want some sort of indicator that the TKT HAS been saved as a default.. in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
| 830 | - * On Autosave: |
|
| 831 | - * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, then set the TKT_is_default to false. |
|
| 832 | - * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
| 833 | - * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
| 834 | - */ |
|
| 835 | - } |
|
| 816 | + public function autosave_handling($event_admin_obj) |
|
| 817 | + { |
|
| 818 | + return $event_admin_obj; //doing nothing for the moment. |
|
| 819 | + //todo when I get to this remember that I need to set the template args on the $event_admin_obj (use the set_template_args() method) |
|
| 820 | + |
|
| 821 | + /** |
|
| 822 | + * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
| 823 | + * |
|
| 824 | + * 1. TKT_is_default_selector (visible) |
|
| 825 | + * 2. TKT_is_default (hidden) |
|
| 826 | + * |
|
| 827 | + * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want this ticket to be saved as a default. |
|
| 828 | + * |
|
| 829 | + * The tricky part is, on an initial display on create or edit (or after manually updating), the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true if this is a create. However, after an autosave, users will want some sort of indicator that the TKT HAS been saved as a default.. in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
| 830 | + * On Autosave: |
|
| 831 | + * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, then set the TKT_is_default to false. |
|
| 832 | + * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
| 833 | + * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
| 834 | + */ |
|
| 835 | + } |
|
| 836 | 836 | |
| 837 | 837 | |
| 838 | - public function pricing_metabox() |
|
| 839 | - { |
|
| 840 | - $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
| 841 | - |
|
| 842 | - $evtobj = $this->_adminpage_obj->get_cpt_model_obj(); |
|
| 843 | - |
|
| 844 | - //set is_creating_event property. |
|
| 845 | - $evtID = $evtobj->ID(); |
|
| 846 | - $this->_is_creating_event = absint($evtID) != 0 ? false : true; |
|
| 847 | - |
|
| 848 | - //default main template args |
|
| 849 | - $main_template_args = array( |
|
| 850 | - 'event_datetime_help_link' => EEH_Template::get_help_tab_link('event_editor_event_datetimes_help_tab', |
|
| 851 | - $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false), |
|
| 852 | - //todo need to add a filter to the template for the help text in the Events_Admin_Page core file so we can add further help |
|
| 853 | - 'existing_datetime_ids' => '', |
|
| 854 | - 'total_dtt_rows' => 1, |
|
| 855 | - 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link('add_new_dtt_info', |
|
| 856 | - $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false), |
|
| 857 | - //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 858 | - 'datetime_rows' => '', |
|
| 859 | - 'show_tickets_container' => '', |
|
| 860 | - //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
| 861 | - 'ticket_rows' => '', |
|
| 862 | - 'existing_ticket_ids' => '', |
|
| 863 | - 'total_ticket_rows' => 1, |
|
| 864 | - 'ticket_js_structure' => '', |
|
| 865 | - 'ee_collapsible_status' => ' ee-collapsible-open' |
|
| 866 | - //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
| 867 | - ); |
|
| 868 | - |
|
| 869 | - $timezone = $evtobj instanceof EE_Event ? $evtobj->timezone_string() : null; |
|
| 870 | - |
|
| 871 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 872 | - |
|
| 873 | - /** |
|
| 874 | - * 1. Start with retrieving Datetimes |
|
| 875 | - * 2. For each datetime get related tickets |
|
| 876 | - * 3. For each ticket get related prices |
|
| 877 | - */ |
|
| 878 | - |
|
| 879 | - $DTM = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
| 880 | - $times = $DTM->get_all_event_dates($evtID); |
|
| 881 | - |
|
| 882 | - |
|
| 883 | - $main_template_args['total_dtt_rows'] = count($times); |
|
| 884 | - |
|
| 885 | - /** @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 for why we are counting $dttrow and then setting that on the Datetime object */ |
|
| 886 | - $dttrow = 1; |
|
| 887 | - foreach ($times as $time) { |
|
| 888 | - $dttid = $time->get('DTT_ID'); |
|
| 889 | - $time->set('DTT_order', $dttrow); |
|
| 890 | - $existing_datetime_ids[] = $dttid; |
|
| 838 | + public function pricing_metabox() |
|
| 839 | + { |
|
| 840 | + $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
| 841 | + |
|
| 842 | + $evtobj = $this->_adminpage_obj->get_cpt_model_obj(); |
|
| 843 | + |
|
| 844 | + //set is_creating_event property. |
|
| 845 | + $evtID = $evtobj->ID(); |
|
| 846 | + $this->_is_creating_event = absint($evtID) != 0 ? false : true; |
|
| 847 | + |
|
| 848 | + //default main template args |
|
| 849 | + $main_template_args = array( |
|
| 850 | + 'event_datetime_help_link' => EEH_Template::get_help_tab_link('event_editor_event_datetimes_help_tab', |
|
| 851 | + $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false), |
|
| 852 | + //todo need to add a filter to the template for the help text in the Events_Admin_Page core file so we can add further help |
|
| 853 | + 'existing_datetime_ids' => '', |
|
| 854 | + 'total_dtt_rows' => 1, |
|
| 855 | + 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link('add_new_dtt_info', |
|
| 856 | + $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false), |
|
| 857 | + //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 858 | + 'datetime_rows' => '', |
|
| 859 | + 'show_tickets_container' => '', |
|
| 860 | + //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
| 861 | + 'ticket_rows' => '', |
|
| 862 | + 'existing_ticket_ids' => '', |
|
| 863 | + 'total_ticket_rows' => 1, |
|
| 864 | + 'ticket_js_structure' => '', |
|
| 865 | + 'ee_collapsible_status' => ' ee-collapsible-open' |
|
| 866 | + //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
| 867 | + ); |
|
| 868 | + |
|
| 869 | + $timezone = $evtobj instanceof EE_Event ? $evtobj->timezone_string() : null; |
|
| 870 | + |
|
| 871 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 872 | + |
|
| 873 | + /** |
|
| 874 | + * 1. Start with retrieving Datetimes |
|
| 875 | + * 2. For each datetime get related tickets |
|
| 876 | + * 3. For each ticket get related prices |
|
| 877 | + */ |
|
| 878 | + |
|
| 879 | + $DTM = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
| 880 | + $times = $DTM->get_all_event_dates($evtID); |
|
| 881 | + |
|
| 882 | + |
|
| 883 | + $main_template_args['total_dtt_rows'] = count($times); |
|
| 884 | + |
|
| 885 | + /** @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 for why we are counting $dttrow and then setting that on the Datetime object */ |
|
| 886 | + $dttrow = 1; |
|
| 887 | + foreach ($times as $time) { |
|
| 888 | + $dttid = $time->get('DTT_ID'); |
|
| 889 | + $time->set('DTT_order', $dttrow); |
|
| 890 | + $existing_datetime_ids[] = $dttid; |
|
| 891 | 891 | |
| 892 | - //tickets attached |
|
| 893 | - $related_tickets = $time->ID() > 0 ? $time->get_many_related('Ticket', array( |
|
| 894 | - array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
| 895 | - 'default_where_conditions' => 'none', |
|
| 896 | - 'order_by' => array('TKT_order' => 'ASC') |
|
| 897 | - )) : array(); |
|
| 892 | + //tickets attached |
|
| 893 | + $related_tickets = $time->ID() > 0 ? $time->get_many_related('Ticket', array( |
|
| 894 | + array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
| 895 | + 'default_where_conditions' => 'none', |
|
| 896 | + 'order_by' => array('TKT_order' => 'ASC') |
|
| 897 | + )) : array(); |
|
| 898 | 898 | |
| 899 | - //if there are no related tickets this is likely a new event OR autodraft |
|
| 900 | - // event so we need to generate the default tickets because dtts |
|
| 901 | - // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
| 902 | - // datetime on the event. |
|
| 903 | - if (empty ($related_tickets) && count($times) < 2) { |
|
| 904 | - $related_tickets = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
| 899 | + //if there are no related tickets this is likely a new event OR autodraft |
|
| 900 | + // event so we need to generate the default tickets because dtts |
|
| 901 | + // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
| 902 | + // datetime on the event. |
|
| 903 | + if (empty ($related_tickets) && count($times) < 2) { |
|
| 904 | + $related_tickets = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
| 905 | 905 | |
| 906 | - //this should be ordered by TKT_ID, so let's grab the first default ticket (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
| 907 | - $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
| 906 | + //this should be ordered by TKT_ID, so let's grab the first default ticket (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
| 907 | + $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
| 908 | 908 | |
| 909 | - $main_default_ticket = reset($related_tickets); |
|
| 910 | - if ($main_default_ticket instanceof EE_Ticket) { |
|
| 911 | - foreach ($default_prices as $default_price) { |
|
| 912 | - if ($default_price->is_base_price()) { |
|
| 913 | - continue; |
|
| 914 | - } |
|
| 915 | - $main_default_ticket->cache('Price', $default_price); |
|
| 916 | - } |
|
| 917 | - } |
|
| 918 | - } |
|
| 909 | + $main_default_ticket = reset($related_tickets); |
|
| 910 | + if ($main_default_ticket instanceof EE_Ticket) { |
|
| 911 | + foreach ($default_prices as $default_price) { |
|
| 912 | + if ($default_price->is_base_price()) { |
|
| 913 | + continue; |
|
| 914 | + } |
|
| 915 | + $main_default_ticket->cache('Price', $default_price); |
|
| 916 | + } |
|
| 917 | + } |
|
| 918 | + } |
|
| 919 | 919 | |
| 920 | 920 | |
| 921 | - //we can't actually setup rows in this loop yet cause we don't know all the unique tickets for this event yet (tickets are linked through all datetimes). So we're going to temporarily cache some of that information. |
|
| 921 | + //we can't actually setup rows in this loop yet cause we don't know all the unique tickets for this event yet (tickets are linked through all datetimes). So we're going to temporarily cache some of that information. |
|
| 922 | 922 | |
| 923 | - //loop through and setup the ticket rows and make sure the order is set. |
|
| 924 | - foreach ($related_tickets as $ticket) { |
|
| 925 | - $tktid = $ticket->get('TKT_ID'); |
|
| 926 | - $tktrow = $ticket->get('TKT_row'); |
|
| 927 | - //we only want unique tickets in our final display!! |
|
| 928 | - if ( ! in_array($tktid, $existing_ticket_ids)) { |
|
| 929 | - $existing_ticket_ids[] = $tktid; |
|
| 930 | - $all_tickets[] = $ticket; |
|
| 931 | - } |
|
| 923 | + //loop through and setup the ticket rows and make sure the order is set. |
|
| 924 | + foreach ($related_tickets as $ticket) { |
|
| 925 | + $tktid = $ticket->get('TKT_ID'); |
|
| 926 | + $tktrow = $ticket->get('TKT_row'); |
|
| 927 | + //we only want unique tickets in our final display!! |
|
| 928 | + if ( ! in_array($tktid, $existing_ticket_ids)) { |
|
| 929 | + $existing_ticket_ids[] = $tktid; |
|
| 930 | + $all_tickets[] = $ticket; |
|
| 931 | + } |
|
| 932 | 932 | |
| 933 | - //temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
| 934 | - $datetime_tickets[$dttid][] = $tktrow; |
|
| 933 | + //temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
| 934 | + $datetime_tickets[$dttid][] = $tktrow; |
|
| 935 | 935 | |
| 936 | - //temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
| 937 | - if ( ! isset($ticket_datetimes[$tktid]) || ! in_array($dttrow, $ticket_datetimes[$tktid])) { |
|
| 938 | - $ticket_datetimes[$tktid][] = $dttrow; |
|
| 939 | - } |
|
| 940 | - } |
|
| 941 | - $dttrow++; |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
| 945 | - $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 946 | - $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 947 | - |
|
| 948 | - //sort $all_tickets by order |
|
| 949 | - usort($all_tickets, function ($a, $b) { |
|
| 950 | - $a_order = (int)$a->get('TKT_order'); |
|
| 951 | - $b_order = (int)$b->get('TKT_order'); |
|
| 952 | - if ($a_order == $b_order) { |
|
| 953 | - return 0; |
|
| 954 | - } |
|
| 936 | + //temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
| 937 | + if ( ! isset($ticket_datetimes[$tktid]) || ! in_array($dttrow, $ticket_datetimes[$tktid])) { |
|
| 938 | + $ticket_datetimes[$tktid][] = $dttrow; |
|
| 939 | + } |
|
| 940 | + } |
|
| 941 | + $dttrow++; |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
| 945 | + $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 946 | + $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 947 | + |
|
| 948 | + //sort $all_tickets by order |
|
| 949 | + usort($all_tickets, function ($a, $b) { |
|
| 950 | + $a_order = (int)$a->get('TKT_order'); |
|
| 951 | + $b_order = (int)$b->get('TKT_order'); |
|
| 952 | + if ($a_order == $b_order) { |
|
| 953 | + return 0; |
|
| 954 | + } |
|
| 955 | 955 | |
| 956 | - return ($a_order < $b_order) ? -1 : 1; |
|
| 957 | - }); |
|
| 958 | - |
|
| 959 | - //k NOW we have all the data we need for setting up the dtt rows and ticket rows so we start our dtt loop again. |
|
| 960 | - $dttrow = 1; |
|
| 961 | - foreach ($times as $time) { |
|
| 962 | - $main_template_args['datetime_rows'] .= $this->_get_datetime_row($dttrow, $time, $datetime_tickets, |
|
| 963 | - $all_tickets, false, $times); |
|
| 964 | - $dttrow++; |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - //then loop through all tickets for the ticket rows. |
|
| 968 | - $tktrow = 1; |
|
| 969 | - foreach ($all_tickets as $ticket) { |
|
| 970 | - $main_template_args['ticket_rows'] .= $this->_get_ticket_row($tktrow, $ticket, $ticket_datetimes, $times, |
|
| 971 | - false, $all_tickets); |
|
| 972 | - $tktrow++; |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($times, $all_tickets); |
|
| 976 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'; |
|
| 977 | - EEH_Template::display_template($template, $main_template_args); |
|
| 978 | - |
|
| 979 | - return; |
|
| 980 | - } |
|
| 956 | + return ($a_order < $b_order) ? -1 : 1; |
|
| 957 | + }); |
|
| 958 | + |
|
| 959 | + //k NOW we have all the data we need for setting up the dtt rows and ticket rows so we start our dtt loop again. |
|
| 960 | + $dttrow = 1; |
|
| 961 | + foreach ($times as $time) { |
|
| 962 | + $main_template_args['datetime_rows'] .= $this->_get_datetime_row($dttrow, $time, $datetime_tickets, |
|
| 963 | + $all_tickets, false, $times); |
|
| 964 | + $dttrow++; |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + //then loop through all tickets for the ticket rows. |
|
| 968 | + $tktrow = 1; |
|
| 969 | + foreach ($all_tickets as $ticket) { |
|
| 970 | + $main_template_args['ticket_rows'] .= $this->_get_ticket_row($tktrow, $ticket, $ticket_datetimes, $times, |
|
| 971 | + false, $all_tickets); |
|
| 972 | + $tktrow++; |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($times, $all_tickets); |
|
| 976 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'; |
|
| 977 | + EEH_Template::display_template($template, $main_template_args); |
|
| 978 | + |
|
| 979 | + return; |
|
| 980 | + } |
|
| 981 | 981 | |
| 982 | 982 | |
| 983 | - protected function _get_datetime_row( |
|
| 984 | - $dttrow, |
|
| 985 | - EE_Datetime $dtt, |
|
| 986 | - $datetime_tickets, |
|
| 987 | - $all_tickets, |
|
| 988 | - $default = false, |
|
| 989 | - $all_dtts = array() |
|
| 990 | - ) { |
|
| 991 | - |
|
| 992 | - $dtt_display_template_args = array( |
|
| 993 | - 'dtt_edit_row' => $this->_get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts), |
|
| 994 | - 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets, |
|
| 995 | - $all_tickets, $default), |
|
| 996 | - 'dtt_row' => $default ? 'DTTNUM' : $dttrow |
|
| 997 | - ); |
|
| 998 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php'; |
|
| 999 | - |
|
| 1000 | - return EEH_Template::display_template($template, $dtt_display_template_args, true); |
|
| 1001 | - } |
|
| 983 | + protected function _get_datetime_row( |
|
| 984 | + $dttrow, |
|
| 985 | + EE_Datetime $dtt, |
|
| 986 | + $datetime_tickets, |
|
| 987 | + $all_tickets, |
|
| 988 | + $default = false, |
|
| 989 | + $all_dtts = array() |
|
| 990 | + ) { |
|
| 991 | + |
|
| 992 | + $dtt_display_template_args = array( |
|
| 993 | + 'dtt_edit_row' => $this->_get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts), |
|
| 994 | + 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets, |
|
| 995 | + $all_tickets, $default), |
|
| 996 | + 'dtt_row' => $default ? 'DTTNUM' : $dttrow |
|
| 997 | + ); |
|
| 998 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php'; |
|
| 999 | + |
|
| 1000 | + return EEH_Template::display_template($template, $dtt_display_template_args, true); |
|
| 1001 | + } |
|
| 1002 | 1002 | |
| 1003 | 1003 | |
| 1004 | - /** |
|
| 1005 | - * This method is used to generate a dtt fields edit row. |
|
| 1006 | - * The same row is used to generate a row with valid DTT objects and the default row that is used as the |
|
| 1007 | - * skeleton by the js. |
|
| 1008 | - * |
|
| 1009 | - * @param int $dttrow The row number for the row being generated. |
|
| 1010 | - * @param mixed EE_Datetime|null $dtt If not default row being |
|
| 1011 | - * generated, this must be a EE_Datetime |
|
| 1012 | - * object. |
|
| 1013 | - * @param bool $default Whether a default row is being generated or not. |
|
| 1014 | - * @param EE_Datetime[] $all_dtts This is the array of all datetimes used in the editor. |
|
| 1015 | - * |
|
| 1016 | - * @return string Generated edit row. |
|
| 1017 | - */ |
|
| 1018 | - protected function _get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts) |
|
| 1019 | - { |
|
| 1020 | - |
|
| 1021 | - // if the incoming $dtt object is NOT an instance of EE_Datetime then force default to true. |
|
| 1022 | - $default = ! $dtt instanceof EE_Datetime ? true : false; |
|
| 1023 | - |
|
| 1024 | - $template_args = array( |
|
| 1025 | - 'dtt_row' => $default ? 'DTTNUM' : $dttrow, |
|
| 1026 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1027 | - 'edit_dtt_expanded' => '', |
|
| 1028 | - //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? '' : ' ee-edit-editing', |
|
| 1029 | - 'DTT_ID' => $default ? '' : $dtt->ID(), |
|
| 1030 | - 'DTT_name' => $default ? '' : $dtt->name(), |
|
| 1031 | - 'DTT_description' => $default ? '' : $dtt->description(), |
|
| 1032 | - 'DTT_EVT_start' => $default ? '' : $dtt->start_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']), |
|
| 1033 | - 'DTT_EVT_end' => $default ? '' : $dtt->end_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']), |
|
| 1034 | - 'DTT_reg_limit' => $default ? '' : $dtt->get_pretty('DTT_reg_limit', 'input'), |
|
| 1035 | - 'DTT_order' => $default ? 'DTTNUM' : $dttrow, |
|
| 1036 | - 'dtt_sold' => $default ? '0' : $dtt->get('DTT_sold'), |
|
| 1037 | - 'clone_icon' => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? '' : 'clone-icon ee-icon ee-icon-clone clickable', |
|
| 1038 | - 'trash_icon' => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? 'ee-lock-icon' : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1039 | - 'reg_list_url' => $default || ! $dtt->event() instanceof \EE_Event |
|
| 1040 | - ? '' |
|
| 1041 | - : EE_Admin_Page::add_query_args_and_nonce( |
|
| 1042 | - array('event_id' => $dtt->event()->ID(), 'datetime_id' => $dtt->ID()), |
|
| 1043 | - REG_ADMIN_URL |
|
| 1044 | - ) |
|
| 1045 | - ); |
|
| 1046 | - |
|
| 1047 | - $template_args['show_trash'] = count($all_dtts) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' ? ' style="display:none"' : ''; |
|
| 1048 | - |
|
| 1049 | - //allow filtering of template args at this point. |
|
| 1050 | - $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
| 1051 | - $template_args, $dttrow, $dtt, $default, $all_dtts, $this->_is_creating_event); |
|
| 1052 | - |
|
| 1053 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php'; |
|
| 1054 | - |
|
| 1055 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1056 | - } |
|
| 1004 | + /** |
|
| 1005 | + * This method is used to generate a dtt fields edit row. |
|
| 1006 | + * The same row is used to generate a row with valid DTT objects and the default row that is used as the |
|
| 1007 | + * skeleton by the js. |
|
| 1008 | + * |
|
| 1009 | + * @param int $dttrow The row number for the row being generated. |
|
| 1010 | + * @param mixed EE_Datetime|null $dtt If not default row being |
|
| 1011 | + * generated, this must be a EE_Datetime |
|
| 1012 | + * object. |
|
| 1013 | + * @param bool $default Whether a default row is being generated or not. |
|
| 1014 | + * @param EE_Datetime[] $all_dtts This is the array of all datetimes used in the editor. |
|
| 1015 | + * |
|
| 1016 | + * @return string Generated edit row. |
|
| 1017 | + */ |
|
| 1018 | + protected function _get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts) |
|
| 1019 | + { |
|
| 1020 | + |
|
| 1021 | + // if the incoming $dtt object is NOT an instance of EE_Datetime then force default to true. |
|
| 1022 | + $default = ! $dtt instanceof EE_Datetime ? true : false; |
|
| 1023 | + |
|
| 1024 | + $template_args = array( |
|
| 1025 | + 'dtt_row' => $default ? 'DTTNUM' : $dttrow, |
|
| 1026 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1027 | + 'edit_dtt_expanded' => '', |
|
| 1028 | + //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? '' : ' ee-edit-editing', |
|
| 1029 | + 'DTT_ID' => $default ? '' : $dtt->ID(), |
|
| 1030 | + 'DTT_name' => $default ? '' : $dtt->name(), |
|
| 1031 | + 'DTT_description' => $default ? '' : $dtt->description(), |
|
| 1032 | + 'DTT_EVT_start' => $default ? '' : $dtt->start_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']), |
|
| 1033 | + 'DTT_EVT_end' => $default ? '' : $dtt->end_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']), |
|
| 1034 | + 'DTT_reg_limit' => $default ? '' : $dtt->get_pretty('DTT_reg_limit', 'input'), |
|
| 1035 | + 'DTT_order' => $default ? 'DTTNUM' : $dttrow, |
|
| 1036 | + 'dtt_sold' => $default ? '0' : $dtt->get('DTT_sold'), |
|
| 1037 | + 'clone_icon' => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? '' : 'clone-icon ee-icon ee-icon-clone clickable', |
|
| 1038 | + 'trash_icon' => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? 'ee-lock-icon' : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1039 | + 'reg_list_url' => $default || ! $dtt->event() instanceof \EE_Event |
|
| 1040 | + ? '' |
|
| 1041 | + : EE_Admin_Page::add_query_args_and_nonce( |
|
| 1042 | + array('event_id' => $dtt->event()->ID(), 'datetime_id' => $dtt->ID()), |
|
| 1043 | + REG_ADMIN_URL |
|
| 1044 | + ) |
|
| 1045 | + ); |
|
| 1046 | + |
|
| 1047 | + $template_args['show_trash'] = count($all_dtts) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' ? ' style="display:none"' : ''; |
|
| 1048 | + |
|
| 1049 | + //allow filtering of template args at this point. |
|
| 1050 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
| 1051 | + $template_args, $dttrow, $dtt, $default, $all_dtts, $this->_is_creating_event); |
|
| 1052 | + |
|
| 1053 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php'; |
|
| 1054 | + |
|
| 1055 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1056 | + } |
|
| 1057 | 1057 | |
| 1058 | 1058 | |
| 1059 | - protected function _get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets, $all_tickets, $default) |
|
| 1060 | - { |
|
| 1061 | - |
|
| 1062 | - $template_args = array( |
|
| 1063 | - 'dtt_row' => $default ? 'DTTNUM' : $dttrow, |
|
| 1064 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1065 | - 'DTT_description' => $default ? '' : $dtt->description(), |
|
| 1066 | - 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1067 | - 'show_tickets_row' => ' style="display:none;"', |
|
| 1068 | - //$default || $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' style="display:none;"' : '', |
|
| 1069 | - 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link('add_new_ticket_via_datetime', |
|
| 1070 | - $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false), |
|
| 1071 | - //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 1072 | - 'DTT_ID' => $default ? '' : $dtt->ID() |
|
| 1073 | - ); |
|
| 1074 | - |
|
| 1075 | - //need to setup the list items (but only if this isnt' a default skeleton setup) |
|
| 1076 | - if ( ! $default) { |
|
| 1077 | - $tktrow = 1; |
|
| 1078 | - foreach ($all_tickets as $ticket) { |
|
| 1079 | - $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item($dttrow, $tktrow, |
|
| 1080 | - $dtt, $ticket, $datetime_tickets, $default); |
|
| 1081 | - $tktrow++; |
|
| 1082 | - } |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - //filter template args at this point |
|
| 1086 | - $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
| 1087 | - $template_args, $dttrow, $dtt, $datetime_tickets, $all_tickets, $default, $this->_is_creating_event); |
|
| 1088 | - |
|
| 1089 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php'; |
|
| 1090 | - |
|
| 1091 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1092 | - } |
|
| 1059 | + protected function _get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets, $all_tickets, $default) |
|
| 1060 | + { |
|
| 1061 | + |
|
| 1062 | + $template_args = array( |
|
| 1063 | + 'dtt_row' => $default ? 'DTTNUM' : $dttrow, |
|
| 1064 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1065 | + 'DTT_description' => $default ? '' : $dtt->description(), |
|
| 1066 | + 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1067 | + 'show_tickets_row' => ' style="display:none;"', |
|
| 1068 | + //$default || $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' style="display:none;"' : '', |
|
| 1069 | + 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link('add_new_ticket_via_datetime', |
|
| 1070 | + $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false), |
|
| 1071 | + //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 1072 | + 'DTT_ID' => $default ? '' : $dtt->ID() |
|
| 1073 | + ); |
|
| 1074 | + |
|
| 1075 | + //need to setup the list items (but only if this isnt' a default skeleton setup) |
|
| 1076 | + if ( ! $default) { |
|
| 1077 | + $tktrow = 1; |
|
| 1078 | + foreach ($all_tickets as $ticket) { |
|
| 1079 | + $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item($dttrow, $tktrow, |
|
| 1080 | + $dtt, $ticket, $datetime_tickets, $default); |
|
| 1081 | + $tktrow++; |
|
| 1082 | + } |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + //filter template args at this point |
|
| 1086 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
| 1087 | + $template_args, $dttrow, $dtt, $datetime_tickets, $all_tickets, $default, $this->_is_creating_event); |
|
| 1088 | + |
|
| 1089 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php'; |
|
| 1090 | + |
|
| 1091 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1092 | + } |
|
| 1093 | 1093 | |
| 1094 | 1094 | |
| 1095 | - protected function _get_datetime_tickets_list_item($dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default) |
|
| 1096 | - { |
|
| 1097 | - $tktid = ! empty($ticket) ? $ticket->ID() : 0; |
|
| 1098 | - $dtt_tkts = $dtt instanceof EE_Datetime && isset($datetime_tickets[$dtt->ID()]) ? $datetime_tickets[$dtt->ID()] : array(); |
|
| 1099 | - |
|
| 1100 | - $displayrow = ! empty($ticket) ? $ticket->get('TKT_row') : 0; |
|
| 1101 | - $template_args = array( |
|
| 1102 | - 'dtt_row' => $default ? 'DTTNUM' : $dttrow, |
|
| 1103 | - 'tkt_row' => $default && empty($ticket) ? 'TICKETNUM' : $tktrow, |
|
| 1104 | - 'datetime_ticket_checked' => in_array($displayrow, $dtt_tkts) ? ' checked="checked"' : '', |
|
| 1105 | - 'ticket_selected' => in_array($displayrow, $dtt_tkts) ? ' ticket-selected' : '', |
|
| 1106 | - 'TKT_name' => $default && empty($ticket) ? 'TKTNAME' : $ticket->get('TKT_name'), |
|
| 1107 | - 'tkt_status_class' => ($default && empty($ticket)) || $this->_is_creating_event ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status(), |
|
| 1108 | - ); |
|
| 1109 | - |
|
| 1110 | - //filter template args |
|
| 1111 | - $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
| 1112 | - $template_args, $dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default, $this->_is_creating_event); |
|
| 1113 | - |
|
| 1114 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php'; |
|
| 1115 | - |
|
| 1116 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1117 | - } |
|
| 1095 | + protected function _get_datetime_tickets_list_item($dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default) |
|
| 1096 | + { |
|
| 1097 | + $tktid = ! empty($ticket) ? $ticket->ID() : 0; |
|
| 1098 | + $dtt_tkts = $dtt instanceof EE_Datetime && isset($datetime_tickets[$dtt->ID()]) ? $datetime_tickets[$dtt->ID()] : array(); |
|
| 1099 | + |
|
| 1100 | + $displayrow = ! empty($ticket) ? $ticket->get('TKT_row') : 0; |
|
| 1101 | + $template_args = array( |
|
| 1102 | + 'dtt_row' => $default ? 'DTTNUM' : $dttrow, |
|
| 1103 | + 'tkt_row' => $default && empty($ticket) ? 'TICKETNUM' : $tktrow, |
|
| 1104 | + 'datetime_ticket_checked' => in_array($displayrow, $dtt_tkts) ? ' checked="checked"' : '', |
|
| 1105 | + 'ticket_selected' => in_array($displayrow, $dtt_tkts) ? ' ticket-selected' : '', |
|
| 1106 | + 'TKT_name' => $default && empty($ticket) ? 'TKTNAME' : $ticket->get('TKT_name'), |
|
| 1107 | + 'tkt_status_class' => ($default && empty($ticket)) || $this->_is_creating_event ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status(), |
|
| 1108 | + ); |
|
| 1109 | + |
|
| 1110 | + //filter template args |
|
| 1111 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
| 1112 | + $template_args, $dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default, $this->_is_creating_event); |
|
| 1113 | + |
|
| 1114 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php'; |
|
| 1115 | + |
|
| 1116 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1117 | + } |
|
| 1118 | 1118 | |
| 1119 | 1119 | |
| 1120 | - /** |
|
| 1121 | - * This generates the ticket row for tickets. |
|
| 1122 | - * This same method is used to generate both the actual rows and the js skeleton row (when default == |
|
| 1123 | - * true) |
|
| 1124 | - * |
|
| 1125 | - * @param int $tktrow Represents the row number being generated. |
|
| 1126 | - * @param mixed null|EE_Ticket $ticket If default then this will |
|
| 1127 | - * be null. |
|
| 1128 | - * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by |
|
| 1129 | - * each ticket or empty for default |
|
| 1130 | - * @param EE_Datetime[] $all_dtts All Datetimes on the event or empty for default. |
|
| 1131 | - * @param bool $default Whether default row being generated or not. |
|
| 1132 | - * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event (or |
|
| 1133 | - * empty in the case of defaults) |
|
| 1134 | - * |
|
| 1135 | - * @return [type] [description] |
|
| 1136 | - */ |
|
| 1137 | - protected function _get_ticket_row( |
|
| 1138 | - $tktrow, |
|
| 1139 | - $ticket, |
|
| 1140 | - $ticket_datetimes, |
|
| 1141 | - $all_dtts, |
|
| 1142 | - $default = false, |
|
| 1143 | - $all_tickets = array() |
|
| 1144 | - ) { |
|
| 1145 | - |
|
| 1146 | - //if $ticket is not an instance of EE_Ticket then force default to true. |
|
| 1147 | - $default = ! $ticket instanceof EE_Ticket ? true : false; |
|
| 1148 | - |
|
| 1149 | - $prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price', |
|
| 1150 | - array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array(); |
|
| 1151 | - |
|
| 1152 | - //if there is only one price (which would be the base price) or NO prices and this ticket is a default ticket, let's just make sure there are no cached default prices on |
|
| 1153 | - //the object. This is done by not including any query_params. |
|
| 1154 | - if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
| 1155 | - $prices = $ticket->get_many_related('Price'); |
|
| 1156 | - } |
|
| 1157 | - |
|
| 1158 | - // check if we're dealing with a default ticket in which case we don't want any starting_ticket_datetime_row values set (otherwise there won't be any new relationships created for tickets based off of the default ticket). This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
| 1159 | - $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->get('TKT_is_default')) ? true : false; |
|
| 1160 | - |
|
| 1161 | - $tkt_dtts = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array(); |
|
| 1162 | - |
|
| 1163 | - $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1164 | - $base_price = $default ? null : $ticket->base_price(); |
|
| 1165 | - $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
| 1166 | - |
|
| 1167 | - //breaking out complicated condition for ticket_status |
|
| 1168 | - if ($default) { |
|
| 1169 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1170 | - } else { |
|
| 1171 | - $ticket_status_class = $ticket->is_default() ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status(); |
|
| 1172 | - } |
|
| 1173 | - |
|
| 1174 | - //breaking out complicated condition for TKT_taxable |
|
| 1175 | - if ($default) { |
|
| 1176 | - $TKT_taxable = ''; |
|
| 1177 | - } else { |
|
| 1178 | - $TKT_taxable = $ticket->get('TKT_taxable') ? ' checked="checked"' : ''; |
|
| 1179 | - } |
|
| 1180 | - |
|
| 1181 | - |
|
| 1182 | - $template_args = array( |
|
| 1183 | - 'tkt_row' => $default ? 'TICKETNUM' : $tktrow, |
|
| 1184 | - 'TKT_order' => $default ? 'TICKETNUM' : $tktrow, |
|
| 1185 | - //on initial page load this will always be the correct order. |
|
| 1186 | - 'tkt_status_class' => $ticket_status_class, |
|
| 1187 | - 'display_edit_tkt_row' => ' style="display:none;"', |
|
| 1188 | - 'edit_tkt_expanded' => '', |
|
| 1189 | - 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1190 | - 'TKT_name' => $default ? '' : $ticket->get('TKT_name'), |
|
| 1191 | - 'TKT_start_date' => $default ? '' : $ticket->get_date('TKT_start_date', |
|
| 1192 | - $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']), |
|
| 1193 | - 'TKT_end_date' => $default ? '' : $ticket->get_date('TKT_end_date', |
|
| 1194 | - $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']), |
|
| 1195 | - 'TKT_status' => $default ? EEH_Template::pretty_status(EE_Ticket::onsale, false, |
|
| 1196 | - 'sentence') : $ticket->is_default() ? EEH_Template::pretty_status(EE_Ticket::onsale, false, |
|
| 1197 | - 'sentence') : $ticket->ticket_status(true), |
|
| 1198 | - 'TKT_price' => $default ? '' : EEH_Template::format_currency($ticket->get_ticket_total_with_taxes(), |
|
| 1199 | - false, false), |
|
| 1200 | - 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
| 1201 | - 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
| 1202 | - 'TKT_qty' => $default ? '' : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
| 1203 | - 'TKT_qty_for_input' => $default ? '' : $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1204 | - 'TKT_uses' => $default ? '' : $ticket->get_pretty('TKT_uses', 'input'), |
|
| 1205 | - 'TKT_min' => $default ? '' : ($ticket->get('TKT_min') === -1 || $ticket->get('TKT_min') === 0 ? '' : $ticket->get('TKT_min')), |
|
| 1206 | - 'TKT_max' => $default ? '' : $ticket->get_pretty('TKT_max', 'input'), |
|
| 1207 | - 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
| 1208 | - 'TKT_registrations' => $default ? 0 : $ticket->count_registrations(array( |
|
| 1209 | - array( |
|
| 1210 | - 'STS_ID' => array( |
|
| 1211 | - '!=', |
|
| 1212 | - EEM_Registration::status_id_incomplete |
|
| 1213 | - ) |
|
| 1214 | - ) |
|
| 1215 | - )), |
|
| 1216 | - 'TKT_ID' => $default ? 0 : $ticket->get('TKT_ID'), |
|
| 1217 | - 'TKT_description' => $default ? '' : $ticket->get('TKT_description'), |
|
| 1218 | - 'TKT_is_default' => $default ? 0 : $ticket->get('TKT_is_default'), |
|
| 1219 | - 'TKT_required' => $default ? 0 : $ticket->required(), |
|
| 1220 | - 'TKT_is_default_selector' => '', |
|
| 1221 | - 'ticket_price_rows' => '', |
|
| 1222 | - 'TKT_base_price' => $default || ! $base_price instanceof EE_Price ? '' : $base_price->get_pretty('PRC_amount', |
|
| 1223 | - 'localized_float'), |
|
| 1224 | - 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
| 1225 | - 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) ? '' : ' style="display:none;"', |
|
| 1226 | - 'show_price_mod_button' => count($prices) > 1 || ($default && $count_price_mods > 0) || ( ! $default && $ticket->get('TKT_deleted')) ? ' style="display:none;"' : '', |
|
| 1227 | - 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
| 1228 | - 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1229 | - 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_dtts), |
|
| 1230 | - 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_dtts), |
|
| 1231 | - 'existing_ticket_price_ids' => $default, |
|
| 1232 | - '', |
|
| 1233 | - implode(',', array_keys($prices)), |
|
| 1234 | - 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
| 1235 | - 'TKT_taxable' => $TKT_taxable, |
|
| 1236 | - 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->get('TKT_taxable') ? '' : ' style="display:none"', |
|
| 1237 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1238 | - 'TKT_subtotal_amount_display' => EEH_Template::format_currency($ticket_subtotal, false, false), |
|
| 1239 | - 'TKT_subtotal_amount' => $ticket_subtotal, |
|
| 1240 | - 'tax_rows' => $this->_get_tax_rows($tktrow, $ticket), |
|
| 1241 | - 'disabled' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? true : false, |
|
| 1242 | - 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? ' ticket-archived' : '', |
|
| 1243 | - 'trash_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? 'ee-lock-icon ' : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1244 | - 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? '' : 'clone-icon ee-icon ee-icon-clone clickable' |
|
| 1245 | - ); |
|
| 1246 | - |
|
| 1247 | - $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] != 'ee-lock-icon' ? ' style="display:none"' : ''; |
|
| 1248 | - |
|
| 1249 | - //handle rows that should NOT be empty |
|
| 1250 | - if (empty($template_args['TKT_start_date'])) { |
|
| 1251 | - //if empty then the start date will be now. |
|
| 1252 | - $template_args['TKT_start_date'] = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'], |
|
| 1253 | - current_time('timestamp')); |
|
| 1254 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - if (empty($template_args['TKT_end_date'])) { |
|
| 1120 | + /** |
|
| 1121 | + * This generates the ticket row for tickets. |
|
| 1122 | + * This same method is used to generate both the actual rows and the js skeleton row (when default == |
|
| 1123 | + * true) |
|
| 1124 | + * |
|
| 1125 | + * @param int $tktrow Represents the row number being generated. |
|
| 1126 | + * @param mixed null|EE_Ticket $ticket If default then this will |
|
| 1127 | + * be null. |
|
| 1128 | + * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by |
|
| 1129 | + * each ticket or empty for default |
|
| 1130 | + * @param EE_Datetime[] $all_dtts All Datetimes on the event or empty for default. |
|
| 1131 | + * @param bool $default Whether default row being generated or not. |
|
| 1132 | + * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event (or |
|
| 1133 | + * empty in the case of defaults) |
|
| 1134 | + * |
|
| 1135 | + * @return [type] [description] |
|
| 1136 | + */ |
|
| 1137 | + protected function _get_ticket_row( |
|
| 1138 | + $tktrow, |
|
| 1139 | + $ticket, |
|
| 1140 | + $ticket_datetimes, |
|
| 1141 | + $all_dtts, |
|
| 1142 | + $default = false, |
|
| 1143 | + $all_tickets = array() |
|
| 1144 | + ) { |
|
| 1145 | + |
|
| 1146 | + //if $ticket is not an instance of EE_Ticket then force default to true. |
|
| 1147 | + $default = ! $ticket instanceof EE_Ticket ? true : false; |
|
| 1148 | + |
|
| 1149 | + $prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price', |
|
| 1150 | + array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array(); |
|
| 1151 | + |
|
| 1152 | + //if there is only one price (which would be the base price) or NO prices and this ticket is a default ticket, let's just make sure there are no cached default prices on |
|
| 1153 | + //the object. This is done by not including any query_params. |
|
| 1154 | + if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
| 1155 | + $prices = $ticket->get_many_related('Price'); |
|
| 1156 | + } |
|
| 1157 | + |
|
| 1158 | + // check if we're dealing with a default ticket in which case we don't want any starting_ticket_datetime_row values set (otherwise there won't be any new relationships created for tickets based off of the default ticket). This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
| 1159 | + $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->get('TKT_is_default')) ? true : false; |
|
| 1160 | + |
|
| 1161 | + $tkt_dtts = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array(); |
|
| 1162 | + |
|
| 1163 | + $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1164 | + $base_price = $default ? null : $ticket->base_price(); |
|
| 1165 | + $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
| 1166 | + |
|
| 1167 | + //breaking out complicated condition for ticket_status |
|
| 1168 | + if ($default) { |
|
| 1169 | + $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1170 | + } else { |
|
| 1171 | + $ticket_status_class = $ticket->is_default() ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status(); |
|
| 1172 | + } |
|
| 1173 | + |
|
| 1174 | + //breaking out complicated condition for TKT_taxable |
|
| 1175 | + if ($default) { |
|
| 1176 | + $TKT_taxable = ''; |
|
| 1177 | + } else { |
|
| 1178 | + $TKT_taxable = $ticket->get('TKT_taxable') ? ' checked="checked"' : ''; |
|
| 1179 | + } |
|
| 1180 | + |
|
| 1181 | + |
|
| 1182 | + $template_args = array( |
|
| 1183 | + 'tkt_row' => $default ? 'TICKETNUM' : $tktrow, |
|
| 1184 | + 'TKT_order' => $default ? 'TICKETNUM' : $tktrow, |
|
| 1185 | + //on initial page load this will always be the correct order. |
|
| 1186 | + 'tkt_status_class' => $ticket_status_class, |
|
| 1187 | + 'display_edit_tkt_row' => ' style="display:none;"', |
|
| 1188 | + 'edit_tkt_expanded' => '', |
|
| 1189 | + 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1190 | + 'TKT_name' => $default ? '' : $ticket->get('TKT_name'), |
|
| 1191 | + 'TKT_start_date' => $default ? '' : $ticket->get_date('TKT_start_date', |
|
| 1192 | + $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']), |
|
| 1193 | + 'TKT_end_date' => $default ? '' : $ticket->get_date('TKT_end_date', |
|
| 1194 | + $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']), |
|
| 1195 | + 'TKT_status' => $default ? EEH_Template::pretty_status(EE_Ticket::onsale, false, |
|
| 1196 | + 'sentence') : $ticket->is_default() ? EEH_Template::pretty_status(EE_Ticket::onsale, false, |
|
| 1197 | + 'sentence') : $ticket->ticket_status(true), |
|
| 1198 | + 'TKT_price' => $default ? '' : EEH_Template::format_currency($ticket->get_ticket_total_with_taxes(), |
|
| 1199 | + false, false), |
|
| 1200 | + 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
| 1201 | + 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
| 1202 | + 'TKT_qty' => $default ? '' : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
| 1203 | + 'TKT_qty_for_input' => $default ? '' : $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1204 | + 'TKT_uses' => $default ? '' : $ticket->get_pretty('TKT_uses', 'input'), |
|
| 1205 | + 'TKT_min' => $default ? '' : ($ticket->get('TKT_min') === -1 || $ticket->get('TKT_min') === 0 ? '' : $ticket->get('TKT_min')), |
|
| 1206 | + 'TKT_max' => $default ? '' : $ticket->get_pretty('TKT_max', 'input'), |
|
| 1207 | + 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
| 1208 | + 'TKT_registrations' => $default ? 0 : $ticket->count_registrations(array( |
|
| 1209 | + array( |
|
| 1210 | + 'STS_ID' => array( |
|
| 1211 | + '!=', |
|
| 1212 | + EEM_Registration::status_id_incomplete |
|
| 1213 | + ) |
|
| 1214 | + ) |
|
| 1215 | + )), |
|
| 1216 | + 'TKT_ID' => $default ? 0 : $ticket->get('TKT_ID'), |
|
| 1217 | + 'TKT_description' => $default ? '' : $ticket->get('TKT_description'), |
|
| 1218 | + 'TKT_is_default' => $default ? 0 : $ticket->get('TKT_is_default'), |
|
| 1219 | + 'TKT_required' => $default ? 0 : $ticket->required(), |
|
| 1220 | + 'TKT_is_default_selector' => '', |
|
| 1221 | + 'ticket_price_rows' => '', |
|
| 1222 | + 'TKT_base_price' => $default || ! $base_price instanceof EE_Price ? '' : $base_price->get_pretty('PRC_amount', |
|
| 1223 | + 'localized_float'), |
|
| 1224 | + 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
| 1225 | + 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) ? '' : ' style="display:none;"', |
|
| 1226 | + 'show_price_mod_button' => count($prices) > 1 || ($default && $count_price_mods > 0) || ( ! $default && $ticket->get('TKT_deleted')) ? ' style="display:none;"' : '', |
|
| 1227 | + 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
| 1228 | + 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1229 | + 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_dtts), |
|
| 1230 | + 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_dtts), |
|
| 1231 | + 'existing_ticket_price_ids' => $default, |
|
| 1232 | + '', |
|
| 1233 | + implode(',', array_keys($prices)), |
|
| 1234 | + 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
| 1235 | + 'TKT_taxable' => $TKT_taxable, |
|
| 1236 | + 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->get('TKT_taxable') ? '' : ' style="display:none"', |
|
| 1237 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1238 | + 'TKT_subtotal_amount_display' => EEH_Template::format_currency($ticket_subtotal, false, false), |
|
| 1239 | + 'TKT_subtotal_amount' => $ticket_subtotal, |
|
| 1240 | + 'tax_rows' => $this->_get_tax_rows($tktrow, $ticket), |
|
| 1241 | + 'disabled' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? true : false, |
|
| 1242 | + 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? ' ticket-archived' : '', |
|
| 1243 | + 'trash_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? 'ee-lock-icon ' : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1244 | + 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? '' : 'clone-icon ee-icon ee-icon-clone clickable' |
|
| 1245 | + ); |
|
| 1246 | + |
|
| 1247 | + $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] != 'ee-lock-icon' ? ' style="display:none"' : ''; |
|
| 1248 | + |
|
| 1249 | + //handle rows that should NOT be empty |
|
| 1250 | + if (empty($template_args['TKT_start_date'])) { |
|
| 1251 | + //if empty then the start date will be now. |
|
| 1252 | + $template_args['TKT_start_date'] = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'], |
|
| 1253 | + current_time('timestamp')); |
|
| 1254 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + if (empty($template_args['TKT_end_date'])) { |
|
| 1258 | 1258 | |
| 1259 | - //get the earliest datetime (if present); |
|
| 1260 | - $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related('Datetime', |
|
| 1261 | - array('order_by' => array('DTT_EVT_start' => 'ASC'))) : null; |
|
| 1259 | + //get the earliest datetime (if present); |
|
| 1260 | + $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related('Datetime', |
|
| 1261 | + array('order_by' => array('DTT_EVT_start' => 'ASC'))) : null; |
|
| 1262 | 1262 | |
| 1263 | - if ( ! empty($earliest_dtt)) { |
|
| 1264 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', |
|
| 1265 | - $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']); |
|
| 1266 | - } else { |
|
| 1267 | - //default so let's just use what's been set for the default date-time which is 30 days from now. |
|
| 1268 | - $template_args['TKT_end_date'] = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'], |
|
| 1269 | - mktime(24, 0, 0, date("m"), date("d") + 29, date("Y"))); |
|
| 1270 | - } |
|
| 1271 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1272 | - } |
|
| 1273 | - |
|
| 1274 | - //generate ticket_datetime items |
|
| 1275 | - if ( ! $default) { |
|
| 1276 | - $dttrow = 1; |
|
| 1277 | - foreach ($all_dtts as $dtt) { |
|
| 1278 | - $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow, $tktrow, $dtt, |
|
| 1279 | - $ticket, $ticket_datetimes, $default); |
|
| 1280 | - $dttrow++; |
|
| 1281 | - } |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - $prcrow = 1; |
|
| 1285 | - foreach ($prices as $price) { |
|
| 1286 | - if ($price->is_base_price()) { |
|
| 1287 | - $prcrow++; |
|
| 1288 | - continue; |
|
| 1289 | - } |
|
| 1290 | - $show_trash = (count($prices) > 1 && $prcrow === 1) || count($prices) === 1 ? false : true; |
|
| 1291 | - $show_create = count($prices) > 1 && count($prices) !== $prcrow ? false : true; |
|
| 1292 | - $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row($tktrow, $prcrow, $price, $default, |
|
| 1293 | - $ticket, $show_trash, $show_create); |
|
| 1294 | - $prcrow++; |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - //filter $template_args |
|
| 1298 | - $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
| 1299 | - $template_args, $tktrow, $ticket, $ticket_datetimes, $all_dtts, $default, $all_tickets, |
|
| 1300 | - $this->_is_creating_event); |
|
| 1301 | - |
|
| 1302 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php'; |
|
| 1303 | - |
|
| 1304 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1305 | - } |
|
| 1263 | + if ( ! empty($earliest_dtt)) { |
|
| 1264 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', |
|
| 1265 | + $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']); |
|
| 1266 | + } else { |
|
| 1267 | + //default so let's just use what's been set for the default date-time which is 30 days from now. |
|
| 1268 | + $template_args['TKT_end_date'] = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'], |
|
| 1269 | + mktime(24, 0, 0, date("m"), date("d") + 29, date("Y"))); |
|
| 1270 | + } |
|
| 1271 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1272 | + } |
|
| 1273 | + |
|
| 1274 | + //generate ticket_datetime items |
|
| 1275 | + if ( ! $default) { |
|
| 1276 | + $dttrow = 1; |
|
| 1277 | + foreach ($all_dtts as $dtt) { |
|
| 1278 | + $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow, $tktrow, $dtt, |
|
| 1279 | + $ticket, $ticket_datetimes, $default); |
|
| 1280 | + $dttrow++; |
|
| 1281 | + } |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + $prcrow = 1; |
|
| 1285 | + foreach ($prices as $price) { |
|
| 1286 | + if ($price->is_base_price()) { |
|
| 1287 | + $prcrow++; |
|
| 1288 | + continue; |
|
| 1289 | + } |
|
| 1290 | + $show_trash = (count($prices) > 1 && $prcrow === 1) || count($prices) === 1 ? false : true; |
|
| 1291 | + $show_create = count($prices) > 1 && count($prices) !== $prcrow ? false : true; |
|
| 1292 | + $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row($tktrow, $prcrow, $price, $default, |
|
| 1293 | + $ticket, $show_trash, $show_create); |
|
| 1294 | + $prcrow++; |
|
| 1295 | + } |
|
| 1296 | + |
|
| 1297 | + //filter $template_args |
|
| 1298 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
| 1299 | + $template_args, $tktrow, $ticket, $ticket_datetimes, $all_dtts, $default, $all_tickets, |
|
| 1300 | + $this->_is_creating_event); |
|
| 1301 | + |
|
| 1302 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php'; |
|
| 1303 | + |
|
| 1304 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1305 | + } |
|
| 1306 | 1306 | |
| 1307 | 1307 | |
| 1308 | - protected function _get_tax_rows($tktrow, $ticket) |
|
| 1309 | - { |
|
| 1310 | - $tax_rows = ''; |
|
| 1311 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php'; |
|
| 1312 | - $template_args = array(); |
|
| 1313 | - $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
| 1314 | - foreach ($taxes as $tax) { |
|
| 1315 | - $tax_added = $this->_get_tax_added($tax, $ticket); |
|
| 1316 | - $template_args = array( |
|
| 1317 | - 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') ? '' : ' style="display:none;"', |
|
| 1318 | - 'tax_id' => $tax->ID(), |
|
| 1319 | - 'tkt_row' => $tktrow, |
|
| 1320 | - 'tax_label' => $tax->get('PRC_name'), |
|
| 1321 | - 'tax_added' => $tax_added, |
|
| 1322 | - 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
| 1323 | - 'tax_amount' => $tax->get('PRC_amount') |
|
| 1324 | - ); |
|
| 1325 | - $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
| 1326 | - $template_args, $tktrow, $ticket, $this->_is_creating_event); |
|
| 1327 | - $tax_rows .= EEH_Template::display_template($template, $template_args, true); |
|
| 1328 | - } |
|
| 1329 | - |
|
| 1330 | - |
|
| 1331 | - return $tax_rows; |
|
| 1332 | - } |
|
| 1308 | + protected function _get_tax_rows($tktrow, $ticket) |
|
| 1309 | + { |
|
| 1310 | + $tax_rows = ''; |
|
| 1311 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php'; |
|
| 1312 | + $template_args = array(); |
|
| 1313 | + $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
| 1314 | + foreach ($taxes as $tax) { |
|
| 1315 | + $tax_added = $this->_get_tax_added($tax, $ticket); |
|
| 1316 | + $template_args = array( |
|
| 1317 | + 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') ? '' : ' style="display:none;"', |
|
| 1318 | + 'tax_id' => $tax->ID(), |
|
| 1319 | + 'tkt_row' => $tktrow, |
|
| 1320 | + 'tax_label' => $tax->get('PRC_name'), |
|
| 1321 | + 'tax_added' => $tax_added, |
|
| 1322 | + 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
| 1323 | + 'tax_amount' => $tax->get('PRC_amount') |
|
| 1324 | + ); |
|
| 1325 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
| 1326 | + $template_args, $tktrow, $ticket, $this->_is_creating_event); |
|
| 1327 | + $tax_rows .= EEH_Template::display_template($template, $template_args, true); |
|
| 1328 | + } |
|
| 1329 | + |
|
| 1330 | + |
|
| 1331 | + return $tax_rows; |
|
| 1332 | + } |
|
| 1333 | 1333 | |
| 1334 | 1334 | |
| 1335 | - protected function _get_tax_added(EE_Price $tax, $ticket) |
|
| 1336 | - { |
|
| 1337 | - $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1335 | + protected function _get_tax_added(EE_Price $tax, $ticket) |
|
| 1336 | + { |
|
| 1337 | + $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1338 | 1338 | |
| 1339 | - return $subtotal * $tax->get('PRC_amount') / 100; |
|
| 1340 | - } |
|
| 1339 | + return $subtotal * $tax->get('PRC_amount') / 100; |
|
| 1340 | + } |
|
| 1341 | 1341 | |
| 1342 | 1342 | |
| 1343 | - protected function _get_ticket_price_row( |
|
| 1344 | - $tktrow, |
|
| 1345 | - $prcrow, |
|
| 1346 | - $price, |
|
| 1347 | - $default, |
|
| 1348 | - $ticket, |
|
| 1349 | - $show_trash = true, |
|
| 1350 | - $show_create = true |
|
| 1351 | - ) { |
|
| 1352 | - $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false; |
|
| 1353 | - $template_args = array( |
|
| 1354 | - 'tkt_row' => $default && empty($ticket) ? 'TICKETNUM' : $tktrow, |
|
| 1355 | - 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $prcrow, |
|
| 1356 | - 'edit_prices_name' => $default && empty($price) ? 'PRICENAMEATTR' : 'edit_prices', |
|
| 1357 | - 'price_type_selector' => $default && empty($price) ? $this->_get_base_price_template($tktrow, $prcrow, |
|
| 1358 | - $price, $default) : $this->_get_price_type_selector($tktrow, $prcrow, $price, $default, $send_disabled), |
|
| 1359 | - 'PRC_ID' => $default && empty($price) ? 0 : $price->ID(), |
|
| 1360 | - 'PRC_is_default' => $default && empty($price) ? 0 : $price->get('PRC_is_default'), |
|
| 1361 | - 'PRC_name' => $default && empty($price) ? '' : $price->get('PRC_name'), |
|
| 1362 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1363 | - 'show_plus_or_minus' => $default && empty($price) ? '' : ' style="display:none;"', |
|
| 1364 | - 'show_plus' => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() || $price->is_base_price() ? ' style="display:none;"' : ''), |
|
| 1365 | - 'show_minus' => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() ? '' : ' style="display:none;"'), |
|
| 1366 | - 'show_currency_symbol' => $default && empty($price) ? ' style="display:none"' : ($price->is_percent() ? ' style="display:none"' : ''), |
|
| 1367 | - 'PRC_amount' => $default && empty($price) ? 0 : $price->get_pretty('PRC_amount', |
|
| 1368 | - 'localized_float'), |
|
| 1369 | - 'show_percentage' => $default && empty($price) ? ' style="display:none;"' : ($price->is_percent() ? '' : ' style="display:none;"'), |
|
| 1370 | - 'show_trash_icon' => $show_trash ? '' : ' style="display:none;"', |
|
| 1371 | - 'show_create_button' => $show_create ? '' : ' style="display:none;"', |
|
| 1372 | - 'PRC_desc' => $default && empty($price) ? '' : $price->get('PRC_desc'), |
|
| 1373 | - 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false |
|
| 1374 | - ); |
|
| 1375 | - |
|
| 1376 | - $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
| 1377 | - $template_args, $tktrow, $prcrow, $price, $default, $ticket, $show_trash, $show_create, |
|
| 1378 | - $this->_is_creating_event); |
|
| 1379 | - |
|
| 1380 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php'; |
|
| 1381 | - |
|
| 1382 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1383 | - } |
|
| 1343 | + protected function _get_ticket_price_row( |
|
| 1344 | + $tktrow, |
|
| 1345 | + $prcrow, |
|
| 1346 | + $price, |
|
| 1347 | + $default, |
|
| 1348 | + $ticket, |
|
| 1349 | + $show_trash = true, |
|
| 1350 | + $show_create = true |
|
| 1351 | + ) { |
|
| 1352 | + $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false; |
|
| 1353 | + $template_args = array( |
|
| 1354 | + 'tkt_row' => $default && empty($ticket) ? 'TICKETNUM' : $tktrow, |
|
| 1355 | + 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $prcrow, |
|
| 1356 | + 'edit_prices_name' => $default && empty($price) ? 'PRICENAMEATTR' : 'edit_prices', |
|
| 1357 | + 'price_type_selector' => $default && empty($price) ? $this->_get_base_price_template($tktrow, $prcrow, |
|
| 1358 | + $price, $default) : $this->_get_price_type_selector($tktrow, $prcrow, $price, $default, $send_disabled), |
|
| 1359 | + 'PRC_ID' => $default && empty($price) ? 0 : $price->ID(), |
|
| 1360 | + 'PRC_is_default' => $default && empty($price) ? 0 : $price->get('PRC_is_default'), |
|
| 1361 | + 'PRC_name' => $default && empty($price) ? '' : $price->get('PRC_name'), |
|
| 1362 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1363 | + 'show_plus_or_minus' => $default && empty($price) ? '' : ' style="display:none;"', |
|
| 1364 | + 'show_plus' => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() || $price->is_base_price() ? ' style="display:none;"' : ''), |
|
| 1365 | + 'show_minus' => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() ? '' : ' style="display:none;"'), |
|
| 1366 | + 'show_currency_symbol' => $default && empty($price) ? ' style="display:none"' : ($price->is_percent() ? ' style="display:none"' : ''), |
|
| 1367 | + 'PRC_amount' => $default && empty($price) ? 0 : $price->get_pretty('PRC_amount', |
|
| 1368 | + 'localized_float'), |
|
| 1369 | + 'show_percentage' => $default && empty($price) ? ' style="display:none;"' : ($price->is_percent() ? '' : ' style="display:none;"'), |
|
| 1370 | + 'show_trash_icon' => $show_trash ? '' : ' style="display:none;"', |
|
| 1371 | + 'show_create_button' => $show_create ? '' : ' style="display:none;"', |
|
| 1372 | + 'PRC_desc' => $default && empty($price) ? '' : $price->get('PRC_desc'), |
|
| 1373 | + 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false |
|
| 1374 | + ); |
|
| 1375 | + |
|
| 1376 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
| 1377 | + $template_args, $tktrow, $prcrow, $price, $default, $ticket, $show_trash, $show_create, |
|
| 1378 | + $this->_is_creating_event); |
|
| 1379 | + |
|
| 1380 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php'; |
|
| 1381 | + |
|
| 1382 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1383 | + } |
|
| 1384 | 1384 | |
| 1385 | 1385 | |
| 1386 | - protected function _get_price_type_selector($tktrow, $prcrow, $price, $default, $disabled = false) |
|
| 1387 | - { |
|
| 1388 | - if ($price->is_base_price()) { |
|
| 1389 | - return $this->_get_base_price_template($tktrow, $prcrow, $price, $default); |
|
| 1390 | - } else { |
|
| 1391 | - return $this->_get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled); |
|
| 1392 | - } |
|
| 1393 | - |
|
| 1394 | - } |
|
| 1386 | + protected function _get_price_type_selector($tktrow, $prcrow, $price, $default, $disabled = false) |
|
| 1387 | + { |
|
| 1388 | + if ($price->is_base_price()) { |
|
| 1389 | + return $this->_get_base_price_template($tktrow, $prcrow, $price, $default); |
|
| 1390 | + } else { |
|
| 1391 | + return $this->_get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled); |
|
| 1392 | + } |
|
| 1393 | + |
|
| 1394 | + } |
|
| 1395 | 1395 | |
| 1396 | 1396 | |
| 1397 | - protected function _get_base_price_template($tktrow, $prcrow, $price, $default) |
|
| 1398 | - { |
|
| 1399 | - $template_args = array( |
|
| 1400 | - 'tkt_row' => $default ? 'TICKETNUM' : $tktrow, |
|
| 1401 | - 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $prcrow, |
|
| 1402 | - 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
| 1403 | - 'PRT_name' => __('Price', 'event_espresso'), |
|
| 1404 | - 'price_selected_operator' => '+', |
|
| 1405 | - 'price_selected_is_percent' => 0 |
|
| 1406 | - ); |
|
| 1407 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php'; |
|
| 1408 | - |
|
| 1409 | - $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
| 1410 | - $template_args, $tktrow, $prcrow, $price, $default, $this->_is_creating_event); |
|
| 1411 | - |
|
| 1412 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1413 | - } |
|
| 1397 | + protected function _get_base_price_template($tktrow, $prcrow, $price, $default) |
|
| 1398 | + { |
|
| 1399 | + $template_args = array( |
|
| 1400 | + 'tkt_row' => $default ? 'TICKETNUM' : $tktrow, |
|
| 1401 | + 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $prcrow, |
|
| 1402 | + 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
| 1403 | + 'PRT_name' => __('Price', 'event_espresso'), |
|
| 1404 | + 'price_selected_operator' => '+', |
|
| 1405 | + 'price_selected_is_percent' => 0 |
|
| 1406 | + ); |
|
| 1407 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php'; |
|
| 1408 | + |
|
| 1409 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
| 1410 | + $template_args, $tktrow, $prcrow, $price, $default, $this->_is_creating_event); |
|
| 1411 | + |
|
| 1412 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1413 | + } |
|
| 1414 | 1414 | |
| 1415 | 1415 | |
| 1416 | - protected function _get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled = false) |
|
| 1417 | - { |
|
| 1418 | - $select_name = $default && empty($price) ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' : 'edit_prices[' . $tktrow . '][' . $prcrow . '][PRT_ID]'; |
|
| 1419 | - $price_types = EE_Registry::instance()->load_model('Price_Type')->get_all(array( |
|
| 1420 | - array( |
|
| 1421 | - 'OR' => array( |
|
| 1422 | - 'PBT_ID' => '2', |
|
| 1423 | - 'PBT_ID*' => '3' |
|
| 1424 | - ) |
|
| 1425 | - ) |
|
| 1426 | - )); |
|
| 1427 | - $price_option_span_template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php'; |
|
| 1428 | - $all_price_types = $default && empty($price) ? array( |
|
| 1429 | - array( |
|
| 1430 | - 'id' => 0, |
|
| 1431 | - 'text' => __('Select Modifier', 'event_espresso') |
|
| 1432 | - ) |
|
| 1433 | - ) : array(); |
|
| 1434 | - $selected_price_type_id = $default && empty($price) ? 0 : $price->type(); |
|
| 1435 | - $price_option_spans = ''; |
|
| 1436 | - //setup pricetypes for selector |
|
| 1437 | - foreach ($price_types as $price_type) { |
|
| 1438 | - $all_price_types[] = array( |
|
| 1439 | - 'id' => $price_type->ID(), |
|
| 1440 | - 'text' => $price_type->get('PRT_name'), |
|
| 1441 | - ); |
|
| 1416 | + protected function _get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled = false) |
|
| 1417 | + { |
|
| 1418 | + $select_name = $default && empty($price) ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' : 'edit_prices[' . $tktrow . '][' . $prcrow . '][PRT_ID]'; |
|
| 1419 | + $price_types = EE_Registry::instance()->load_model('Price_Type')->get_all(array( |
|
| 1420 | + array( |
|
| 1421 | + 'OR' => array( |
|
| 1422 | + 'PBT_ID' => '2', |
|
| 1423 | + 'PBT_ID*' => '3' |
|
| 1424 | + ) |
|
| 1425 | + ) |
|
| 1426 | + )); |
|
| 1427 | + $price_option_span_template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php'; |
|
| 1428 | + $all_price_types = $default && empty($price) ? array( |
|
| 1429 | + array( |
|
| 1430 | + 'id' => 0, |
|
| 1431 | + 'text' => __('Select Modifier', 'event_espresso') |
|
| 1432 | + ) |
|
| 1433 | + ) : array(); |
|
| 1434 | + $selected_price_type_id = $default && empty($price) ? 0 : $price->type(); |
|
| 1435 | + $price_option_spans = ''; |
|
| 1436 | + //setup pricetypes for selector |
|
| 1437 | + foreach ($price_types as $price_type) { |
|
| 1438 | + $all_price_types[] = array( |
|
| 1439 | + 'id' => $price_type->ID(), |
|
| 1440 | + 'text' => $price_type->get('PRT_name'), |
|
| 1441 | + ); |
|
| 1442 | 1442 | |
| 1443 | - //while we're in the loop let's setup the option spans used by js |
|
| 1444 | - $spanargs = array( |
|
| 1445 | - 'PRT_ID' => $price_type->ID(), |
|
| 1446 | - 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
| 1447 | - 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0 |
|
| 1448 | - ); |
|
| 1449 | - $price_option_spans .= EEH_Template::display_template($price_option_span_template, $spanargs, true); |
|
| 1450 | - } |
|
| 1451 | - |
|
| 1452 | - $select_params = $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"'; |
|
| 1453 | - $main_name = $select_name; |
|
| 1454 | - $select_name = $disabled ? 'archive_price[' . $tktrow . '][' . $prcrow . '][PRT_ID]' : $main_name; |
|
| 1455 | - |
|
| 1456 | - $template_args = array( |
|
| 1457 | - 'tkt_row' => $default ? 'TICKETNUM' : $tktrow, |
|
| 1458 | - 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $prcrow, |
|
| 1459 | - 'price_modifier_selector' => EEH_Form_Fields::select_input($select_name, $all_price_types, |
|
| 1460 | - $selected_price_type_id, $select_params, 'edit-price-PRT_ID'), |
|
| 1461 | - 'main_name' => $main_name, |
|
| 1462 | - 'selected_price_type_id' => $selected_price_type_id, |
|
| 1463 | - 'price_option_spans' => $price_option_spans, |
|
| 1464 | - 'price_selected_operator' => $default && empty($price) ? '' : ($price->is_discount() ? '-' : '+'), |
|
| 1465 | - 'price_selected_is_percent' => $default && empty($price) ? '' : ($price->is_percent() ? 1 : 0), |
|
| 1466 | - 'disabled' => $disabled |
|
| 1467 | - ); |
|
| 1468 | - |
|
| 1469 | - $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
| 1470 | - $template_args, $tktrow, $prcrow, $price, $default, $disabled, $this->_is_creating_event); |
|
| 1471 | - |
|
| 1472 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php'; |
|
| 1473 | - |
|
| 1474 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1475 | - } |
|
| 1443 | + //while we're in the loop let's setup the option spans used by js |
|
| 1444 | + $spanargs = array( |
|
| 1445 | + 'PRT_ID' => $price_type->ID(), |
|
| 1446 | + 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
| 1447 | + 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0 |
|
| 1448 | + ); |
|
| 1449 | + $price_option_spans .= EEH_Template::display_template($price_option_span_template, $spanargs, true); |
|
| 1450 | + } |
|
| 1451 | + |
|
| 1452 | + $select_params = $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"'; |
|
| 1453 | + $main_name = $select_name; |
|
| 1454 | + $select_name = $disabled ? 'archive_price[' . $tktrow . '][' . $prcrow . '][PRT_ID]' : $main_name; |
|
| 1455 | + |
|
| 1456 | + $template_args = array( |
|
| 1457 | + 'tkt_row' => $default ? 'TICKETNUM' : $tktrow, |
|
| 1458 | + 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $prcrow, |
|
| 1459 | + 'price_modifier_selector' => EEH_Form_Fields::select_input($select_name, $all_price_types, |
|
| 1460 | + $selected_price_type_id, $select_params, 'edit-price-PRT_ID'), |
|
| 1461 | + 'main_name' => $main_name, |
|
| 1462 | + 'selected_price_type_id' => $selected_price_type_id, |
|
| 1463 | + 'price_option_spans' => $price_option_spans, |
|
| 1464 | + 'price_selected_operator' => $default && empty($price) ? '' : ($price->is_discount() ? '-' : '+'), |
|
| 1465 | + 'price_selected_is_percent' => $default && empty($price) ? '' : ($price->is_percent() ? 1 : 0), |
|
| 1466 | + 'disabled' => $disabled |
|
| 1467 | + ); |
|
| 1468 | + |
|
| 1469 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
| 1470 | + $template_args, $tktrow, $prcrow, $price, $default, $disabled, $this->_is_creating_event); |
|
| 1471 | + |
|
| 1472 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php'; |
|
| 1473 | + |
|
| 1474 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1475 | + } |
|
| 1476 | 1476 | |
| 1477 | 1477 | |
| 1478 | - protected function _get_ticket_datetime_list_item($dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default) |
|
| 1479 | - { |
|
| 1480 | - $dttid = ! empty($dtt) ? $dtt->ID() : 0; |
|
| 1481 | - $displayrow = ! empty($dtt) ? $dtt->get('DTT_order') : 0; |
|
| 1482 | - $tkt_dtts = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array(); |
|
| 1483 | - $template_args = array( |
|
| 1484 | - 'dtt_row' => $default && empty($dtt) ? 'DTTNUM' : $dttrow, |
|
| 1485 | - 'tkt_row' => $default ? 'TICKETNUM' : $tktrow, |
|
| 1486 | - 'ticket_datetime_selected' => in_array($displayrow, $tkt_dtts) ? ' ticket-selected' : '', |
|
| 1487 | - 'ticket_datetime_checked' => in_array($displayrow, $tkt_dtts) ? ' checked="checked"' : '', |
|
| 1488 | - 'DTT_name' => $default && empty($dtt) ? 'DTTNAME' : $dtt->get_dtt_display_name(true), |
|
| 1489 | - 'tkt_status_class' => '', |
|
| 1490 | - ); |
|
| 1491 | - |
|
| 1492 | - $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
| 1493 | - $template_args, $dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default, $this->_is_creating_event); |
|
| 1494 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php'; |
|
| 1495 | - |
|
| 1496 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1497 | - } |
|
| 1478 | + protected function _get_ticket_datetime_list_item($dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default) |
|
| 1479 | + { |
|
| 1480 | + $dttid = ! empty($dtt) ? $dtt->ID() : 0; |
|
| 1481 | + $displayrow = ! empty($dtt) ? $dtt->get('DTT_order') : 0; |
|
| 1482 | + $tkt_dtts = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array(); |
|
| 1483 | + $template_args = array( |
|
| 1484 | + 'dtt_row' => $default && empty($dtt) ? 'DTTNUM' : $dttrow, |
|
| 1485 | + 'tkt_row' => $default ? 'TICKETNUM' : $tktrow, |
|
| 1486 | + 'ticket_datetime_selected' => in_array($displayrow, $tkt_dtts) ? ' ticket-selected' : '', |
|
| 1487 | + 'ticket_datetime_checked' => in_array($displayrow, $tkt_dtts) ? ' checked="checked"' : '', |
|
| 1488 | + 'DTT_name' => $default && empty($dtt) ? 'DTTNAME' : $dtt->get_dtt_display_name(true), |
|
| 1489 | + 'tkt_status_class' => '', |
|
| 1490 | + ); |
|
| 1491 | + |
|
| 1492 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
| 1493 | + $template_args, $dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default, $this->_is_creating_event); |
|
| 1494 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php'; |
|
| 1495 | + |
|
| 1496 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1497 | + } |
|
| 1498 | 1498 | |
| 1499 | 1499 | |
| 1500 | - protected function _get_ticket_js_structure($all_dtts, $all_tickets) |
|
| 1501 | - { |
|
| 1502 | - $template_args = array( |
|
| 1503 | - 'default_datetime_edit_row' => $this->_get_dtt_edit_row('DTTNUM', null, true, $all_dtts), |
|
| 1504 | - 'default_ticket_row' => $this->_get_ticket_row('TICKETNUM', null, array(), array(), |
|
| 1505 | - true), |
|
| 1506 | - 'default_price_row' => $this->_get_ticket_price_row('TICKETNUM', 'PRICENUM', null, |
|
| 1507 | - true, null), |
|
| 1508 | - 'default_price_rows' => '', |
|
| 1509 | - 'default_base_price_amount' => 0, |
|
| 1510 | - 'default_base_price_name' => '', |
|
| 1511 | - 'default_base_price_description' => '', |
|
| 1512 | - 'default_price_modifier_selector_row' => $this->_get_price_modifier_template('TICKETNUM', 'PRICENUM', |
|
| 1513 | - null, true), |
|
| 1514 | - 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row('DTTNUM', null, array(), |
|
| 1515 | - array(), true), |
|
| 1516 | - 'existing_available_datetime_tickets_list' => '', |
|
| 1517 | - 'existing_available_ticket_datetimes_list' => '', |
|
| 1518 | - 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item('DTTNUM', 'TICKETNUM', |
|
| 1519 | - null, null, array(), true), |
|
| 1520 | - 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item('DTTNUM', 'TICKETNUM', |
|
| 1521 | - null, null, array(), true) |
|
| 1522 | - ); |
|
| 1523 | - |
|
| 1524 | - $tktrow = 1; |
|
| 1525 | - foreach ($all_tickets as $ticket) { |
|
| 1526 | - $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item('DTTNUM', |
|
| 1527 | - $tktrow, null, $ticket, array(), true); |
|
| 1528 | - $tktrow++; |
|
| 1529 | - } |
|
| 1530 | - |
|
| 1531 | - |
|
| 1532 | - $dttrow = 1; |
|
| 1533 | - foreach ($all_dtts as $dtt) { |
|
| 1534 | - $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow, |
|
| 1535 | - 'TICKETNUM', $dtt, null, array(), true); |
|
| 1536 | - $dttrow++; |
|
| 1537 | - } |
|
| 1538 | - |
|
| 1539 | - $default_prices = EE_Registry::instance()->load_model('Price')->get_all_default_prices(); |
|
| 1540 | - $prcrow = 1; |
|
| 1541 | - foreach ($default_prices as $price) { |
|
| 1542 | - if ($price->is_base_price()) { |
|
| 1543 | - $template_args['default_base_price_amount'] = $price->get_pretty('PRC_amount', 'localized_float'); |
|
| 1544 | - $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
| 1545 | - $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
| 1546 | - $prcrow++; |
|
| 1547 | - continue; |
|
| 1548 | - } |
|
| 1549 | - $show_trash = (count($default_prices) > 1 && $prcrow === 1) || count($default_prices) === 1 ? false : true; |
|
| 1550 | - $show_create = count($default_prices) > 1 && count($default_prices) !== $prcrow ? false : true; |
|
| 1551 | - $template_args['default_price_rows'] .= $this->_get_ticket_price_row('TICKETNUM', $prcrow, $price, true, |
|
| 1552 | - null, $show_trash, $show_create); |
|
| 1553 | - $prcrow++; |
|
| 1554 | - } |
|
| 1555 | - |
|
| 1556 | - $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
| 1557 | - $template_args, $all_dtts, $all_tickets, $this->_is_creating_event); |
|
| 1558 | - |
|
| 1559 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php'; |
|
| 1560 | - |
|
| 1561 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1562 | - } |
|
| 1500 | + protected function _get_ticket_js_structure($all_dtts, $all_tickets) |
|
| 1501 | + { |
|
| 1502 | + $template_args = array( |
|
| 1503 | + 'default_datetime_edit_row' => $this->_get_dtt_edit_row('DTTNUM', null, true, $all_dtts), |
|
| 1504 | + 'default_ticket_row' => $this->_get_ticket_row('TICKETNUM', null, array(), array(), |
|
| 1505 | + true), |
|
| 1506 | + 'default_price_row' => $this->_get_ticket_price_row('TICKETNUM', 'PRICENUM', null, |
|
| 1507 | + true, null), |
|
| 1508 | + 'default_price_rows' => '', |
|
| 1509 | + 'default_base_price_amount' => 0, |
|
| 1510 | + 'default_base_price_name' => '', |
|
| 1511 | + 'default_base_price_description' => '', |
|
| 1512 | + 'default_price_modifier_selector_row' => $this->_get_price_modifier_template('TICKETNUM', 'PRICENUM', |
|
| 1513 | + null, true), |
|
| 1514 | + 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row('DTTNUM', null, array(), |
|
| 1515 | + array(), true), |
|
| 1516 | + 'existing_available_datetime_tickets_list' => '', |
|
| 1517 | + 'existing_available_ticket_datetimes_list' => '', |
|
| 1518 | + 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item('DTTNUM', 'TICKETNUM', |
|
| 1519 | + null, null, array(), true), |
|
| 1520 | + 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item('DTTNUM', 'TICKETNUM', |
|
| 1521 | + null, null, array(), true) |
|
| 1522 | + ); |
|
| 1523 | + |
|
| 1524 | + $tktrow = 1; |
|
| 1525 | + foreach ($all_tickets as $ticket) { |
|
| 1526 | + $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item('DTTNUM', |
|
| 1527 | + $tktrow, null, $ticket, array(), true); |
|
| 1528 | + $tktrow++; |
|
| 1529 | + } |
|
| 1530 | + |
|
| 1531 | + |
|
| 1532 | + $dttrow = 1; |
|
| 1533 | + foreach ($all_dtts as $dtt) { |
|
| 1534 | + $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow, |
|
| 1535 | + 'TICKETNUM', $dtt, null, array(), true); |
|
| 1536 | + $dttrow++; |
|
| 1537 | + } |
|
| 1538 | + |
|
| 1539 | + $default_prices = EE_Registry::instance()->load_model('Price')->get_all_default_prices(); |
|
| 1540 | + $prcrow = 1; |
|
| 1541 | + foreach ($default_prices as $price) { |
|
| 1542 | + if ($price->is_base_price()) { |
|
| 1543 | + $template_args['default_base_price_amount'] = $price->get_pretty('PRC_amount', 'localized_float'); |
|
| 1544 | + $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
| 1545 | + $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
| 1546 | + $prcrow++; |
|
| 1547 | + continue; |
|
| 1548 | + } |
|
| 1549 | + $show_trash = (count($default_prices) > 1 && $prcrow === 1) || count($default_prices) === 1 ? false : true; |
|
| 1550 | + $show_create = count($default_prices) > 1 && count($default_prices) !== $prcrow ? false : true; |
|
| 1551 | + $template_args['default_price_rows'] .= $this->_get_ticket_price_row('TICKETNUM', $prcrow, $price, true, |
|
| 1552 | + null, $show_trash, $show_create); |
|
| 1553 | + $prcrow++; |
|
| 1554 | + } |
|
| 1555 | + |
|
| 1556 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
| 1557 | + $template_args, $all_dtts, $all_tickets, $this->_is_creating_event); |
|
| 1558 | + |
|
| 1559 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php'; |
|
| 1560 | + |
|
| 1561 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1562 | + } |
|
| 1563 | 1563 | |
| 1564 | 1564 | |
| 1565 | 1565 | } //end class espresso_events_Pricing_Hooks |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | 'context' => 'normal' |
| 74 | 74 | ), |
| 75 | 75 | |
| 76 | - );/**/ |
|
| 76 | + ); /**/ |
|
| 77 | 77 | |
| 78 | 78 | $this->_remove_metaboxes = array( |
| 79 | 79 | 0 => array( |
@@ -103,16 +103,16 @@ discard block |
||
| 103 | 103 | $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) ? $this->_date_format_strings['time'] : null; |
| 104 | 104 | |
| 105 | 105 | //validate format strings |
| 106 | - $format_validation = EEH_DTT_Helper::validate_format_string($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']); |
|
| 106 | + $format_validation = EEH_DTT_Helper::validate_format_string($this->_date_format_strings['date'].' '.$this->_date_format_strings['time']); |
|
| 107 | 107 | if (is_array($format_validation)) { |
| 108 | - $msg = '<p>' . sprintf(__('The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
| 108 | + $msg = '<p>'.sprintf(__('The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
| 109 | 109 | 'event_espresso'), |
| 110 | - $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']) . '</p><ul>'; |
|
| 110 | + $this->_date_format_strings['date'].' '.$this->_date_format_strings['time']).'</p><ul>'; |
|
| 111 | 111 | foreach ($format_validation as $error) { |
| 112 | - $msg .= '<li>' . $error . '</li>'; |
|
| 112 | + $msg .= '<li>'.$error.'</li>'; |
|
| 113 | 113 | } |
| 114 | - $msg .= '</ul></p><p>' . sprintf(__('%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
| 115 | - 'event_espresso'), '<span style="color:#D54E21;">', '</span>') . '</p>'; |
|
| 114 | + $msg .= '</ul></p><p>'.sprintf(__('%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
| 115 | + 'event_espresso'), '<span style="color:#D54E21;">', '</span>').'</p>'; |
|
| 116 | 116 | EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
| 117 | 117 | $this->_date_format_strings = array( |
| 118 | 118 | 'date' => 'Y-m-d', |
@@ -124,11 +124,11 @@ discard block |
||
| 124 | 124 | $this->_scripts_styles = array( |
| 125 | 125 | 'registers' => array( |
| 126 | 126 | 'ee-tickets-datetimes-css' => array( |
| 127 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
| 127 | + 'url' => PRICING_ASSETS_URL.'event-tickets-datetimes.css', |
|
| 128 | 128 | 'type' => 'css' |
| 129 | 129 | ), |
| 130 | 130 | 'ee-dtt-ticket-metabox' => array( |
| 131 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
| 131 | + 'url' => PRICING_ASSETS_URL.'ee-datetime-ticket-metabox.js', |
|
| 132 | 132 | 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore') |
| 133 | 133 | ) |
| 134 | 134 | ), |
@@ -147,19 +147,19 @@ discard block |
||
| 147 | 147 | 'event_espresso'), |
| 148 | 148 | 'after_warning' => __('In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
| 149 | 149 | 'event_espresso'), |
| 150 | - 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' . __('Cancel', |
|
| 151 | - 'event_espresso') . '</button>', |
|
| 150 | + 'cancel_button' => '<button class="button-secondary ee-modal-cancel">'.__('Cancel', |
|
| 151 | + 'event_espresso').'</button>', |
|
| 152 | 152 | 'single_warning_from_tkt' => __('The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
| 153 | 153 | 'event_espresso'), |
| 154 | 154 | 'single_warning_from_dtt' => __('The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
| 155 | 155 | 'event_espresso'), |
| 156 | - 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' . __('Dismiss', |
|
| 157 | - 'event_espresso') . '</button>' |
|
| 156 | + 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">'.__('Dismiss', |
|
| 157 | + 'event_espresso').'</button>' |
|
| 158 | 158 | ), |
| 159 | 159 | 'DTT_ERROR_MSG' => array( |
| 160 | 160 | 'no_ticket_name' => __('General Admission', 'event_espresso'), |
| 161 | - 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' . __('Dismiss', |
|
| 162 | - 'event_espresso') . '</button></div>' |
|
| 161 | + 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">'.__('Dismiss', |
|
| 162 | + 'event_espresso').'</button></div>' |
|
| 163 | 163 | ), |
| 164 | 164 | 'DTT_OVERSELL_WARNING' => array( |
| 165 | 165 | 'datetime_ticket' => __('You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | ), |
| 170 | 170 | 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats($this->_date_format_strings['date'], |
| 171 | 171 | $this->_date_format_strings['time']), |
| 172 | - 'DTT_START_OF_WEEK' => array('dayValue' => (int)get_option('start_of_week')) |
|
| 172 | + 'DTT_START_OF_WEEK' => array('dayValue' => (int) get_option('start_of_week')) |
|
| 173 | 173 | ) |
| 174 | 174 | ) |
| 175 | 175 | ); |
@@ -229,8 +229,8 @@ discard block |
||
| 229 | 229 | |
| 230 | 230 | foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
| 231 | 231 | //trim all values to ensure any excess whitespace is removed. |
| 232 | - $dtt = array_map( |
|
| 233 | - function ($datetime_data) { |
|
| 232 | + $dtt = array_map( |
|
| 233 | + function($datetime_data) { |
|
| 234 | 234 | return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
| 235 | 235 | }, |
| 236 | 236 | $dtt |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | |
| 367 | 367 | // trim inputs to ensure any excess whitespace is removed. |
| 368 | 368 | $tkt = array_map( |
| 369 | - function ($ticket_data) { |
|
| 369 | + function($ticket_data) { |
|
| 370 | 370 | return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
| 371 | 371 | }, |
| 372 | 372 | $tkt |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | |
| 375 | 375 | //note we are doing conversions to floats here instead of allowing EE_Money_Field to handle because we're doing calcs prior to using the models. |
| 376 | 376 | //note incoming ['TKT_price'] value is already in standard notation (via js). |
| 377 | - $ticket_price = isset($tkt['TKT_price']) ? round((float)$tkt['TKT_price'], 3) : 0; |
|
| 377 | + $ticket_price = isset($tkt['TKT_price']) ? round((float) $tkt['TKT_price'], 3) : 0; |
|
| 378 | 378 | |
| 379 | 379 | //note incoming base price needs converted from localized value. |
| 380 | 380 | $base_price = isset($tkt['TKT_base_price']) ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) : 0; |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | if (empty($tkt['TKT_start_date'])) { |
| 389 | 389 | //lets' use now in the set timezone. |
| 390 | 390 | $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
| 391 | - $tkt['TKT_start_date'] = $now->format($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']); |
|
| 391 | + $tkt['TKT_start_date'] = $now->format($this->_date_format_strings['date'].' '.$this->_date_format_strings['time']); |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | if (empty($tkt['TKT_end_date'])) { |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | * set the TKT_end_date to the first datetime attached to the ticket. |
| 397 | 397 | */ |
| 398 | 398 | $first_dtt = $saved_dtts[reset($tkt_dtt_rows)]; |
| 399 | - $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_format_strings['date'] . ' ' . $this->_date_format_string['time']); |
|
| 399 | + $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_format_strings['date'].' '.$this->_date_format_string['time']); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | $TKT_values = array( |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | // first let's add datetimes |
| 627 | 627 | if ( ! empty($added_datetimes) && is_array($added_datetimes)) { |
| 628 | 628 | foreach ($added_datetimes as $row_id) { |
| 629 | - $row_id = (int)$row_id; |
|
| 629 | + $row_id = (int) $row_id; |
|
| 630 | 630 | if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
| 631 | 631 | $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
| 632 | 632 | // Is this an existing ticket (has an ID) and does it have any sold? |
@@ -641,7 +641,7 @@ discard block |
||
| 641 | 641 | // then remove datetimes |
| 642 | 642 | if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) { |
| 643 | 643 | foreach ($removed_datetimes as $row_id) { |
| 644 | - $row_id = (int)$row_id; |
|
| 644 | + $row_id = (int) $row_id; |
|
| 645 | 645 | // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
| 646 | 646 | // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
| 647 | 647 | if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
@@ -946,9 +946,9 @@ discard block |
||
| 946 | 946 | $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
| 947 | 947 | |
| 948 | 948 | //sort $all_tickets by order |
| 949 | - usort($all_tickets, function ($a, $b) { |
|
| 950 | - $a_order = (int)$a->get('TKT_order'); |
|
| 951 | - $b_order = (int)$b->get('TKT_order'); |
|
| 949 | + usort($all_tickets, function($a, $b) { |
|
| 950 | + $a_order = (int) $a->get('TKT_order'); |
|
| 951 | + $b_order = (int) $b->get('TKT_order'); |
|
| 952 | 952 | if ($a_order == $b_order) { |
| 953 | 953 | return 0; |
| 954 | 954 | } |
@@ -973,7 +973,7 @@ discard block |
||
| 973 | 973 | } |
| 974 | 974 | |
| 975 | 975 | $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($times, $all_tickets); |
| 976 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'; |
|
| 976 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'; |
|
| 977 | 977 | EEH_Template::display_template($template, $main_template_args); |
| 978 | 978 | |
| 979 | 979 | return; |
@@ -995,7 +995,7 @@ discard block |
||
| 995 | 995 | $all_tickets, $default), |
| 996 | 996 | 'dtt_row' => $default ? 'DTTNUM' : $dttrow |
| 997 | 997 | ); |
| 998 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php'; |
|
| 998 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_row_wrapper.template.php'; |
|
| 999 | 999 | |
| 1000 | 1000 | return EEH_Template::display_template($template, $dtt_display_template_args, true); |
| 1001 | 1001 | } |
@@ -1029,8 +1029,8 @@ discard block |
||
| 1029 | 1029 | 'DTT_ID' => $default ? '' : $dtt->ID(), |
| 1030 | 1030 | 'DTT_name' => $default ? '' : $dtt->name(), |
| 1031 | 1031 | 'DTT_description' => $default ? '' : $dtt->description(), |
| 1032 | - 'DTT_EVT_start' => $default ? '' : $dtt->start_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']), |
|
| 1033 | - 'DTT_EVT_end' => $default ? '' : $dtt->end_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']), |
|
| 1032 | + 'DTT_EVT_start' => $default ? '' : $dtt->start_date($this->_date_format_strings['date'].' '.$this->_date_format_strings['time']), |
|
| 1033 | + 'DTT_EVT_end' => $default ? '' : $dtt->end_date($this->_date_format_strings['date'].' '.$this->_date_format_strings['time']), |
|
| 1034 | 1034 | 'DTT_reg_limit' => $default ? '' : $dtt->get_pretty('DTT_reg_limit', 'input'), |
| 1035 | 1035 | 'DTT_order' => $default ? 'DTTNUM' : $dttrow, |
| 1036 | 1036 | 'dtt_sold' => $default ? '0' : $dtt->get('DTT_sold'), |
@@ -1050,7 +1050,7 @@ discard block |
||
| 1050 | 1050 | $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
| 1051 | 1051 | $template_args, $dttrow, $dtt, $default, $all_dtts, $this->_is_creating_event); |
| 1052 | 1052 | |
| 1053 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php'; |
|
| 1053 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_edit_row.template.php'; |
|
| 1054 | 1054 | |
| 1055 | 1055 | return EEH_Template::display_template($template, $template_args, true); |
| 1056 | 1056 | } |
@@ -1086,7 +1086,7 @@ discard block |
||
| 1086 | 1086 | $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
| 1087 | 1087 | $template_args, $dttrow, $dtt, $datetime_tickets, $all_tickets, $default, $this->_is_creating_event); |
| 1088 | 1088 | |
| 1089 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php'; |
|
| 1089 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_attached_tickets_row.template.php'; |
|
| 1090 | 1090 | |
| 1091 | 1091 | return EEH_Template::display_template($template, $template_args, true); |
| 1092 | 1092 | } |
@@ -1104,14 +1104,14 @@ discard block |
||
| 1104 | 1104 | 'datetime_ticket_checked' => in_array($displayrow, $dtt_tkts) ? ' checked="checked"' : '', |
| 1105 | 1105 | 'ticket_selected' => in_array($displayrow, $dtt_tkts) ? ' ticket-selected' : '', |
| 1106 | 1106 | 'TKT_name' => $default && empty($ticket) ? 'TKTNAME' : $ticket->get('TKT_name'), |
| 1107 | - 'tkt_status_class' => ($default && empty($ticket)) || $this->_is_creating_event ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status(), |
|
| 1107 | + 'tkt_status_class' => ($default && empty($ticket)) || $this->_is_creating_event ? ' tkt-status-'.EE_Ticket::onsale : ' tkt-status-'.$ticket->ticket_status(), |
|
| 1108 | 1108 | ); |
| 1109 | 1109 | |
| 1110 | 1110 | //filter template args |
| 1111 | 1111 | $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
| 1112 | 1112 | $template_args, $dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default, $this->_is_creating_event); |
| 1113 | 1113 | |
| 1114 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php'; |
|
| 1114 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_dtt_tickets_list.template.php'; |
|
| 1115 | 1115 | |
| 1116 | 1116 | return EEH_Template::display_template($template, $template_args, true); |
| 1117 | 1117 | } |
@@ -1166,9 +1166,9 @@ discard block |
||
| 1166 | 1166 | |
| 1167 | 1167 | //breaking out complicated condition for ticket_status |
| 1168 | 1168 | if ($default) { |
| 1169 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1169 | + $ticket_status_class = ' tkt-status-'.EE_Ticket::onsale; |
|
| 1170 | 1170 | } else { |
| 1171 | - $ticket_status_class = $ticket->is_default() ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status(); |
|
| 1171 | + $ticket_status_class = $ticket->is_default() ? ' tkt-status-'.EE_Ticket::onsale : ' tkt-status-'.$ticket->ticket_status(); |
|
| 1172 | 1172 | } |
| 1173 | 1173 | |
| 1174 | 1174 | //breaking out complicated condition for TKT_taxable |
@@ -1189,9 +1189,9 @@ discard block |
||
| 1189 | 1189 | 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
| 1190 | 1190 | 'TKT_name' => $default ? '' : $ticket->get('TKT_name'), |
| 1191 | 1191 | 'TKT_start_date' => $default ? '' : $ticket->get_date('TKT_start_date', |
| 1192 | - $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']), |
|
| 1192 | + $this->_date_format_strings['date'].' '.$this->_date_format_strings['time']), |
|
| 1193 | 1193 | 'TKT_end_date' => $default ? '' : $ticket->get_date('TKT_end_date', |
| 1194 | - $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']), |
|
| 1194 | + $this->_date_format_strings['date'].' '.$this->_date_format_strings['time']), |
|
| 1195 | 1195 | 'TKT_status' => $default ? EEH_Template::pretty_status(EE_Ticket::onsale, false, |
| 1196 | 1196 | 'sentence') : $ticket->is_default() ? EEH_Template::pretty_status(EE_Ticket::onsale, false, |
| 1197 | 1197 | 'sentence') : $ticket->ticket_status(true), |
@@ -1249,9 +1249,9 @@ discard block |
||
| 1249 | 1249 | //handle rows that should NOT be empty |
| 1250 | 1250 | if (empty($template_args['TKT_start_date'])) { |
| 1251 | 1251 | //if empty then the start date will be now. |
| 1252 | - $template_args['TKT_start_date'] = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'], |
|
| 1252 | + $template_args['TKT_start_date'] = date($this->_date_format_strings['date'].' '.$this->_date_format_strings['time'], |
|
| 1253 | 1253 | current_time('timestamp')); |
| 1254 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1254 | + $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale; |
|
| 1255 | 1255 | } |
| 1256 | 1256 | |
| 1257 | 1257 | if (empty($template_args['TKT_end_date'])) { |
@@ -1262,13 +1262,13 @@ discard block |
||
| 1262 | 1262 | |
| 1263 | 1263 | if ( ! empty($earliest_dtt)) { |
| 1264 | 1264 | $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', |
| 1265 | - $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']); |
|
| 1265 | + $this->_date_format_strings['date'].' '.$this->_date_format_strings['time']); |
|
| 1266 | 1266 | } else { |
| 1267 | 1267 | //default so let's just use what's been set for the default date-time which is 30 days from now. |
| 1268 | - $template_args['TKT_end_date'] = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'], |
|
| 1268 | + $template_args['TKT_end_date'] = date($this->_date_format_strings['date'].' '.$this->_date_format_strings['time'], |
|
| 1269 | 1269 | mktime(24, 0, 0, date("m"), date("d") + 29, date("Y"))); |
| 1270 | 1270 | } |
| 1271 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1271 | + $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale; |
|
| 1272 | 1272 | } |
| 1273 | 1273 | |
| 1274 | 1274 | //generate ticket_datetime items |
@@ -1299,7 +1299,7 @@ discard block |
||
| 1299 | 1299 | $template_args, $tktrow, $ticket, $ticket_datetimes, $all_dtts, $default, $all_tickets, |
| 1300 | 1300 | $this->_is_creating_event); |
| 1301 | 1301 | |
| 1302 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php'; |
|
| 1302 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_row.template.php'; |
|
| 1303 | 1303 | |
| 1304 | 1304 | return EEH_Template::display_template($template, $template_args, true); |
| 1305 | 1305 | } |
@@ -1308,7 +1308,7 @@ discard block |
||
| 1308 | 1308 | protected function _get_tax_rows($tktrow, $ticket) |
| 1309 | 1309 | { |
| 1310 | 1310 | $tax_rows = ''; |
| 1311 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php'; |
|
| 1311 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_tax_row.template.php'; |
|
| 1312 | 1312 | $template_args = array(); |
| 1313 | 1313 | $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
| 1314 | 1314 | foreach ($taxes as $tax) { |
@@ -1377,7 +1377,7 @@ discard block |
||
| 1377 | 1377 | $template_args, $tktrow, $prcrow, $price, $default, $ticket, $show_trash, $show_create, |
| 1378 | 1378 | $this->_is_creating_event); |
| 1379 | 1379 | |
| 1380 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php'; |
|
| 1380 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_price_row.template.php'; |
|
| 1381 | 1381 | |
| 1382 | 1382 | return EEH_Template::display_template($template, $template_args, true); |
| 1383 | 1383 | } |
@@ -1404,7 +1404,7 @@ discard block |
||
| 1404 | 1404 | 'price_selected_operator' => '+', |
| 1405 | 1405 | 'price_selected_is_percent' => 0 |
| 1406 | 1406 | ); |
| 1407 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php'; |
|
| 1407 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_type_base.template.php'; |
|
| 1408 | 1408 | |
| 1409 | 1409 | $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
| 1410 | 1410 | $template_args, $tktrow, $prcrow, $price, $default, $this->_is_creating_event); |
@@ -1415,7 +1415,7 @@ discard block |
||
| 1415 | 1415 | |
| 1416 | 1416 | protected function _get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled = false) |
| 1417 | 1417 | { |
| 1418 | - $select_name = $default && empty($price) ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' : 'edit_prices[' . $tktrow . '][' . $prcrow . '][PRT_ID]'; |
|
| 1418 | + $select_name = $default && empty($price) ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' : 'edit_prices['.$tktrow.']['.$prcrow.'][PRT_ID]'; |
|
| 1419 | 1419 | $price_types = EE_Registry::instance()->load_model('Price_Type')->get_all(array( |
| 1420 | 1420 | array( |
| 1421 | 1421 | 'OR' => array( |
@@ -1424,7 +1424,7 @@ discard block |
||
| 1424 | 1424 | ) |
| 1425 | 1425 | ) |
| 1426 | 1426 | )); |
| 1427 | - $price_option_span_template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php'; |
|
| 1427 | + $price_option_span_template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_option_span.template.php'; |
|
| 1428 | 1428 | $all_price_types = $default && empty($price) ? array( |
| 1429 | 1429 | array( |
| 1430 | 1430 | 'id' => 0, |
@@ -1451,7 +1451,7 @@ discard block |
||
| 1451 | 1451 | |
| 1452 | 1452 | $select_params = $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"'; |
| 1453 | 1453 | $main_name = $select_name; |
| 1454 | - $select_name = $disabled ? 'archive_price[' . $tktrow . '][' . $prcrow . '][PRT_ID]' : $main_name; |
|
| 1454 | + $select_name = $disabled ? 'archive_price['.$tktrow.']['.$prcrow.'][PRT_ID]' : $main_name; |
|
| 1455 | 1455 | |
| 1456 | 1456 | $template_args = array( |
| 1457 | 1457 | 'tkt_row' => $default ? 'TICKETNUM' : $tktrow, |
@@ -1469,7 +1469,7 @@ discard block |
||
| 1469 | 1469 | $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
| 1470 | 1470 | $template_args, $tktrow, $prcrow, $price, $default, $disabled, $this->_is_creating_event); |
| 1471 | 1471 | |
| 1472 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php'; |
|
| 1472 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_modifier_selector.template.php'; |
|
| 1473 | 1473 | |
| 1474 | 1474 | return EEH_Template::display_template($template, $template_args, true); |
| 1475 | 1475 | } |
@@ -1491,7 +1491,7 @@ discard block |
||
| 1491 | 1491 | |
| 1492 | 1492 | $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
| 1493 | 1493 | $template_args, $dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default, $this->_is_creating_event); |
| 1494 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php'; |
|
| 1494 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_datetimes_list_item.template.php'; |
|
| 1495 | 1495 | |
| 1496 | 1496 | return EEH_Template::display_template($template, $template_args, true); |
| 1497 | 1497 | } |
@@ -1556,7 +1556,7 @@ discard block |
||
| 1556 | 1556 | $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
| 1557 | 1557 | $template_args, $all_dtts, $all_tickets, $this->_is_creating_event); |
| 1558 | 1558 | |
| 1559 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php'; |
|
| 1559 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_js_structure.template.php'; |
|
| 1560 | 1560 | |
| 1561 | 1561 | return EEH_Template::display_template($template, $template_args, true); |
| 1562 | 1562 | } |
@@ -590,7 +590,7 @@ discard block |
||
| 590 | 590 | * allowed) |
| 591 | 591 | * |
| 592 | 592 | * @param string $datetime_string mysql timestamp in UTC |
| 593 | - * @return mixed null | DateTime |
|
| 593 | + * @return null|DbSafeDateTime null | DateTime |
|
| 594 | 594 | * @throws \EE_Error |
| 595 | 595 | */ |
| 596 | 596 | public function prepare_for_set_from_db($datetime_string) |
@@ -731,7 +731,7 @@ discard block |
||
| 731 | 731 | * @param \DateTimeZone $DateTimeZone |
| 732 | 732 | * @param int $time |
| 733 | 733 | * |
| 734 | - * @return mixed |
|
| 734 | + * @return string |
|
| 735 | 735 | */ |
| 736 | 736 | public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
| 737 | 737 | { |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\domain\entities\DbSafeDateTime; |
| 2 | 2 | |
| 3 | 3 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 4 | - exit('No direct script access allowed'); |
|
| 4 | + exit('No direct script access allowed'); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -17,102 +17,102 @@ discard block |
||
| 17 | 17 | class EE_Datetime_Field extends EE_Model_Field_Base |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * The pattern we're looking for is if only the characters 0-9 are found and there are only |
|
| 22 | - * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 ) |
|
| 23 | - * @type string unix_timestamp_regex |
|
| 24 | - */ |
|
| 25 | - const unix_timestamp_regex = '/[0-9]{10,}/'; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @type string mysql_timestamp_format |
|
| 29 | - */ |
|
| 30 | - const mysql_timestamp_format = 'Y-m-d H:i:s'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @type string mysql_date_format |
|
| 34 | - */ |
|
| 35 | - const mysql_date_format = 'Y-m-d'; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @type string mysql_time_format |
|
| 39 | - */ |
|
| 40 | - const mysql_time_format = 'H:i:s'; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Const for using in the default value. If the field's default is set to this, |
|
| 44 | - * then we will return the time of calling `get_default_value()`, not |
|
| 45 | - * just the current time at construction |
|
| 46 | - */ |
|
| 47 | - const now = 'now'; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * The following properties hold the default formats for date and time. |
|
| 51 | - * Defaults are set via the constructor and can be overridden on class instantiation. |
|
| 52 | - * However they can also be overridden later by the set_format() method |
|
| 53 | - * (and corresponding set_date_format, set_time_format methods); |
|
| 54 | - */ |
|
| 55 | - /** |
|
| 56 | - * @type string $_date_format |
|
| 57 | - */ |
|
| 58 | - protected $_date_format = ''; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @type string $_time_format |
|
| 62 | - */ |
|
| 63 | - protected $_time_format = ''; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @type string $_pretty_date_format |
|
| 67 | - */ |
|
| 68 | - protected $_pretty_date_format = ''; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @type string $_pretty_time_format |
|
| 72 | - */ |
|
| 73 | - protected $_pretty_time_format = ''; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @type DateTimeZone $_DateTimeZone |
|
| 77 | - */ |
|
| 78 | - protected $_DateTimeZone; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @type DateTimeZone $_UTC_DateTimeZone |
|
| 82 | - */ |
|
| 83 | - protected $_UTC_DateTimeZone; |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @type DateTimeZone $_blog_DateTimeZone |
|
| 87 | - */ |
|
| 88 | - protected $_blog_DateTimeZone; |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * This property holds how we want the output returned when getting a datetime string. It is set for the |
|
| 93 | - * set_date_time_output() method. By default this is empty. When empty, we are assuming that we want both date |
|
| 94 | - * and time returned via getters. |
|
| 95 | - * @var mixed (null|string) |
|
| 96 | - */ |
|
| 97 | - protected $_date_time_output; |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * timezone string |
|
| 102 | - * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone |
|
| 103 | - * incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings |
|
| 104 | - * coming out of the object to be in. Default timezone is the current WP timezone option setting |
|
| 105 | - * @var string |
|
| 106 | - */ |
|
| 107 | - protected $_timezone_string; |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related |
|
| 112 | - * offsets for comparison purposes). |
|
| 113 | - * @var int |
|
| 114 | - */ |
|
| 115 | - protected $_blog_offset; |
|
| 20 | + /** |
|
| 21 | + * The pattern we're looking for is if only the characters 0-9 are found and there are only |
|
| 22 | + * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 ) |
|
| 23 | + * @type string unix_timestamp_regex |
|
| 24 | + */ |
|
| 25 | + const unix_timestamp_regex = '/[0-9]{10,}/'; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @type string mysql_timestamp_format |
|
| 29 | + */ |
|
| 30 | + const mysql_timestamp_format = 'Y-m-d H:i:s'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @type string mysql_date_format |
|
| 34 | + */ |
|
| 35 | + const mysql_date_format = 'Y-m-d'; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @type string mysql_time_format |
|
| 39 | + */ |
|
| 40 | + const mysql_time_format = 'H:i:s'; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Const for using in the default value. If the field's default is set to this, |
|
| 44 | + * then we will return the time of calling `get_default_value()`, not |
|
| 45 | + * just the current time at construction |
|
| 46 | + */ |
|
| 47 | + const now = 'now'; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * The following properties hold the default formats for date and time. |
|
| 51 | + * Defaults are set via the constructor and can be overridden on class instantiation. |
|
| 52 | + * However they can also be overridden later by the set_format() method |
|
| 53 | + * (and corresponding set_date_format, set_time_format methods); |
|
| 54 | + */ |
|
| 55 | + /** |
|
| 56 | + * @type string $_date_format |
|
| 57 | + */ |
|
| 58 | + protected $_date_format = ''; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @type string $_time_format |
|
| 62 | + */ |
|
| 63 | + protected $_time_format = ''; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @type string $_pretty_date_format |
|
| 67 | + */ |
|
| 68 | + protected $_pretty_date_format = ''; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @type string $_pretty_time_format |
|
| 72 | + */ |
|
| 73 | + protected $_pretty_time_format = ''; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @type DateTimeZone $_DateTimeZone |
|
| 77 | + */ |
|
| 78 | + protected $_DateTimeZone; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @type DateTimeZone $_UTC_DateTimeZone |
|
| 82 | + */ |
|
| 83 | + protected $_UTC_DateTimeZone; |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @type DateTimeZone $_blog_DateTimeZone |
|
| 87 | + */ |
|
| 88 | + protected $_blog_DateTimeZone; |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * This property holds how we want the output returned when getting a datetime string. It is set for the |
|
| 93 | + * set_date_time_output() method. By default this is empty. When empty, we are assuming that we want both date |
|
| 94 | + * and time returned via getters. |
|
| 95 | + * @var mixed (null|string) |
|
| 96 | + */ |
|
| 97 | + protected $_date_time_output; |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * timezone string |
|
| 102 | + * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone |
|
| 103 | + * incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings |
|
| 104 | + * coming out of the object to be in. Default timezone is the current WP timezone option setting |
|
| 105 | + * @var string |
|
| 106 | + */ |
|
| 107 | + protected $_timezone_string; |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related |
|
| 112 | + * offsets for comparison purposes). |
|
| 113 | + * @var int |
|
| 114 | + */ |
|
| 115 | + protected $_blog_offset; |
|
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | |
@@ -128,36 +128,36 @@ discard block |
||
| 128 | 128 | * @param string $pretty_time_format |
| 129 | 129 | * @throws \EE_Error |
| 130 | 130 | */ |
| 131 | - public function __construct( |
|
| 132 | - $table_column, |
|
| 133 | - $nice_name, |
|
| 134 | - $nullable, |
|
| 135 | - $default_value, |
|
| 136 | - $timezone_string = '', |
|
| 137 | - $date_format = '', |
|
| 138 | - $time_format = '', |
|
| 139 | - $pretty_date_format = '', |
|
| 140 | - $pretty_time_format = '' |
|
| 141 | - ) { |
|
| 131 | + public function __construct( |
|
| 132 | + $table_column, |
|
| 133 | + $nice_name, |
|
| 134 | + $nullable, |
|
| 135 | + $default_value, |
|
| 136 | + $timezone_string = '', |
|
| 137 | + $date_format = '', |
|
| 138 | + $time_format = '', |
|
| 139 | + $pretty_date_format = '', |
|
| 140 | + $pretty_time_format = '' |
|
| 141 | + ) { |
|
| 142 | 142 | |
| 143 | - $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
| 144 | - $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
| 145 | - $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
| 146 | - $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
| 143 | + $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
| 144 | + $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
| 145 | + $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
| 146 | + $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
| 147 | 147 | |
| 148 | - parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
| 149 | - $this->set_timezone($timezone_string); |
|
| 148 | + parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
| 149 | + $this->set_timezone($timezone_string); |
|
| 150 | 150 | |
| 151 | - } |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | 153 | |
| 154 | - /** |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 157 | - public function get_wpdb_data_type() |
|
| 158 | - { |
|
| 159 | - return '%s'; |
|
| 160 | - } |
|
| 154 | + /** |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | + public function get_wpdb_data_type() |
|
| 158 | + { |
|
| 159 | + return '%s'; |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | 162 | |
| 163 | 163 | |
@@ -165,12 +165,12 @@ discard block |
||
| 165 | 165 | * @return DateTimeZone |
| 166 | 166 | * @throws \EE_Error |
| 167 | 167 | */ |
| 168 | - public function get_UTC_DateTimeZone() |
|
| 169 | - { |
|
| 170 | - return $this->_UTC_DateTimeZone instanceof DateTimeZone |
|
| 171 | - ? $this->_UTC_DateTimeZone |
|
| 172 | - : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
| 173 | - } |
|
| 168 | + public function get_UTC_DateTimeZone() |
|
| 169 | + { |
|
| 170 | + return $this->_UTC_DateTimeZone instanceof DateTimeZone |
|
| 171 | + ? $this->_UTC_DateTimeZone |
|
| 172 | + : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | 175 | |
| 176 | 176 | |
@@ -178,69 +178,69 @@ discard block |
||
| 178 | 178 | * @return DateTimeZone |
| 179 | 179 | * @throws \EE_Error |
| 180 | 180 | */ |
| 181 | - public function get_blog_DateTimeZone() |
|
| 182 | - { |
|
| 183 | - return $this->_blog_DateTimeZone instanceof DateTimeZone |
|
| 184 | - ? $this->_blog_DateTimeZone |
|
| 185 | - : $this->_create_timezone_object_from_timezone_string(''); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * this prepares any incoming date data and make sure its converted to a utc unix timestamp |
|
| 191 | - * |
|
| 192 | - * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix |
|
| 193 | - * timestamp |
|
| 194 | - * |
|
| 195 | - * @return DateTime |
|
| 196 | - */ |
|
| 197 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 198 | - { |
|
| 199 | - return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * This returns the format string to be used by getters depending on what the $_date_time_output property is set at. |
|
| 205 | - * |
|
| 206 | - * getters need to know whether we're just returning the date or the time or both. By default we return both. |
|
| 207 | - * |
|
| 208 | - * @param bool $pretty If we're returning the pretty formats or standard format string. |
|
| 209 | - * @return string The final assembled format string. |
|
| 210 | - */ |
|
| 211 | - protected function _get_date_time_output($pretty = false) |
|
| 212 | - { |
|
| 213 | - |
|
| 214 | - switch ($this->_date_time_output) { |
|
| 215 | - case 'time' : |
|
| 216 | - return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
| 217 | - break; |
|
| 218 | - |
|
| 219 | - case 'date' : |
|
| 220 | - return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
| 221 | - break; |
|
| 222 | - |
|
| 223 | - default : |
|
| 224 | - return $pretty |
|
| 225 | - ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
| 226 | - : $this->_date_format . ' ' . $this->_time_format; |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * This just sets the $_date_time_output property so we can flag how date and times are formatted before being |
|
| 233 | - * returned (using the format properties) |
|
| 234 | - * |
|
| 235 | - * @param string $what acceptable values are 'time' or 'date'. |
|
| 236 | - * Any other value will be set but will always result |
|
| 237 | - * in both 'date' and 'time' being returned. |
|
| 238 | - * @return void |
|
| 239 | - */ |
|
| 240 | - public function set_date_time_output($what = null) |
|
| 241 | - { |
|
| 242 | - $this->_date_time_output = $what; |
|
| 243 | - } |
|
| 181 | + public function get_blog_DateTimeZone() |
|
| 182 | + { |
|
| 183 | + return $this->_blog_DateTimeZone instanceof DateTimeZone |
|
| 184 | + ? $this->_blog_DateTimeZone |
|
| 185 | + : $this->_create_timezone_object_from_timezone_string(''); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * this prepares any incoming date data and make sure its converted to a utc unix timestamp |
|
| 191 | + * |
|
| 192 | + * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix |
|
| 193 | + * timestamp |
|
| 194 | + * |
|
| 195 | + * @return DateTime |
|
| 196 | + */ |
|
| 197 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 198 | + { |
|
| 199 | + return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * This returns the format string to be used by getters depending on what the $_date_time_output property is set at. |
|
| 205 | + * |
|
| 206 | + * getters need to know whether we're just returning the date or the time or both. By default we return both. |
|
| 207 | + * |
|
| 208 | + * @param bool $pretty If we're returning the pretty formats or standard format string. |
|
| 209 | + * @return string The final assembled format string. |
|
| 210 | + */ |
|
| 211 | + protected function _get_date_time_output($pretty = false) |
|
| 212 | + { |
|
| 213 | + |
|
| 214 | + switch ($this->_date_time_output) { |
|
| 215 | + case 'time' : |
|
| 216 | + return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
| 217 | + break; |
|
| 218 | + |
|
| 219 | + case 'date' : |
|
| 220 | + return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
| 221 | + break; |
|
| 222 | + |
|
| 223 | + default : |
|
| 224 | + return $pretty |
|
| 225 | + ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
| 226 | + : $this->_date_format . ' ' . $this->_time_format; |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * This just sets the $_date_time_output property so we can flag how date and times are formatted before being |
|
| 233 | + * returned (using the format properties) |
|
| 234 | + * |
|
| 235 | + * @param string $what acceptable values are 'time' or 'date'. |
|
| 236 | + * Any other value will be set but will always result |
|
| 237 | + * in both 'date' and 'time' being returned. |
|
| 238 | + * @return void |
|
| 239 | + */ |
|
| 240 | + public function set_date_time_output($what = null) |
|
| 241 | + { |
|
| 242 | + $this->_date_time_output = $what; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | 245 | |
| 246 | 246 | |
@@ -255,17 +255,17 @@ discard block |
||
| 255 | 255 | * @return void |
| 256 | 256 | * @throws \EE_Error |
| 257 | 257 | */ |
| 258 | - public function set_timezone($timezone_string) |
|
| 259 | - { |
|
| 260 | - if (empty($timezone_string) && $this->_timezone_string !== null) { |
|
| 261 | - // leave the timezone AS-IS if we already have one and |
|
| 262 | - // the function arg didn't provide one |
|
| 263 | - return; |
|
| 264 | - } |
|
| 265 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
| 266 | - $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
| 267 | - $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
| 268 | - } |
|
| 258 | + public function set_timezone($timezone_string) |
|
| 259 | + { |
|
| 260 | + if (empty($timezone_string) && $this->_timezone_string !== null) { |
|
| 261 | + // leave the timezone AS-IS if we already have one and |
|
| 262 | + // the function arg didn't provide one |
|
| 263 | + return; |
|
| 264 | + } |
|
| 265 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
| 266 | + $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
| 267 | + $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | 270 | |
| 271 | 271 | |
@@ -277,178 +277,178 @@ discard block |
||
| 277 | 277 | * @return \DateTimeZone |
| 278 | 278 | * @throws \EE_Error |
| 279 | 279 | */ |
| 280 | - protected function _create_timezone_object_from_timezone_string($timezone_string = '') |
|
| 281 | - { |
|
| 282 | - return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * This just returns whatever is set for the current timezone. |
|
| 288 | - * |
|
| 289 | - * @access public |
|
| 290 | - * @return string timezone string |
|
| 291 | - */ |
|
| 292 | - public function get_timezone() |
|
| 293 | - { |
|
| 294 | - return $this->_timezone_string; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * set the $_date_format property |
|
| 300 | - * |
|
| 301 | - * @access public |
|
| 302 | - * |
|
| 303 | - * @param string $format a new date format (corresponding to formats accepted by PHP date() function) |
|
| 304 | - * @param bool $pretty Whether to set pretty format or not. |
|
| 305 | - * |
|
| 306 | - * @return void |
|
| 307 | - */ |
|
| 308 | - public function set_date_format($format, $pretty = false) |
|
| 309 | - { |
|
| 310 | - if ($pretty) { |
|
| 311 | - $this->_pretty_date_format = $format; |
|
| 312 | - } else { |
|
| 313 | - $this->_date_format = $format; |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * return the $_date_format property value. |
|
| 320 | - * |
|
| 321 | - * @param bool $pretty Whether to get pretty format or not. |
|
| 322 | - * |
|
| 323 | - * @return string |
|
| 324 | - */ |
|
| 325 | - public function get_date_format($pretty = false) |
|
| 326 | - { |
|
| 327 | - return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * set the $_time_format property |
|
| 333 | - * |
|
| 334 | - * @access public |
|
| 335 | - * |
|
| 336 | - * @param string $format a new time format (corresponding to formats accepted by PHP date() function) |
|
| 337 | - * @param bool $pretty Whether to set pretty format or not. |
|
| 338 | - * |
|
| 339 | - * @return void |
|
| 340 | - */ |
|
| 341 | - public function set_time_format($format, $pretty = false) |
|
| 342 | - { |
|
| 343 | - if ($pretty) { |
|
| 344 | - $this->_pretty_time_format = $format; |
|
| 345 | - } else { |
|
| 346 | - $this->_time_format = $format; |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * return the $_time_format property value. |
|
| 353 | - * |
|
| 354 | - * @param bool $pretty Whether to get pretty format or not. |
|
| 355 | - * |
|
| 356 | - * @return string |
|
| 357 | - */ |
|
| 358 | - public function get_time_format($pretty = false) |
|
| 359 | - { |
|
| 360 | - return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * set the $_pretty_date_format property |
|
| 366 | - * |
|
| 367 | - * @access public |
|
| 368 | - * |
|
| 369 | - * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
|
| 370 | - * |
|
| 371 | - * @return void |
|
| 372 | - */ |
|
| 373 | - public function set_pretty_date_format($format) |
|
| 374 | - { |
|
| 375 | - $this->_pretty_date_format = $format; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * set the $_pretty_time_format property |
|
| 381 | - * |
|
| 382 | - * @access public |
|
| 383 | - * |
|
| 384 | - * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
|
| 385 | - * |
|
| 386 | - * @return void |
|
| 387 | - */ |
|
| 388 | - public function set_pretty_time_format($format) |
|
| 389 | - { |
|
| 390 | - $this->_pretty_time_format = $format; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * Only sets the time portion of the datetime. |
|
| 396 | - * |
|
| 397 | - * @param string|DateTime $time_to_set_string like 8am OR a DateTime object. |
|
| 398 | - * @param DateTime $current current DateTime object for the datetime field |
|
| 399 | - * |
|
| 400 | - * @return DateTime |
|
| 401 | - */ |
|
| 402 | - public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) |
|
| 403 | - { |
|
| 404 | - // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
| 405 | - // Otherwise parse the string. |
|
| 406 | - if ($time_to_set_string instanceof DateTime) { |
|
| 407 | - $parsed = array( |
|
| 408 | - 'hour' => $time_to_set_string->format('H'), |
|
| 409 | - 'minute' => $time_to_set_string->format('i'), |
|
| 410 | - 'second' => $time_to_set_string->format('s') |
|
| 411 | - ); |
|
| 412 | - } else { |
|
| 413 | - //parse incoming string |
|
| 414 | - $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - //make sure $current is in the correct timezone. |
|
| 418 | - $current->setTimezone($this->_DateTimeZone); |
|
| 419 | - |
|
| 420 | - return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Only sets the date portion of the datetime. |
|
| 426 | - * |
|
| 427 | - * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object. |
|
| 428 | - * @param DateTime $current current DateTime object for the datetime field |
|
| 429 | - * |
|
| 430 | - * @return DateTime |
|
| 431 | - */ |
|
| 432 | - public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) |
|
| 433 | - { |
|
| 434 | - // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
| 435 | - // Otherwise parse the string. |
|
| 436 | - if ($date_to_set_string instanceof DateTime) { |
|
| 437 | - $parsed = array( |
|
| 438 | - 'year' => $date_to_set_string->format('Y'), |
|
| 439 | - 'month' => $date_to_set_string->format('m'), |
|
| 440 | - 'day' => $date_to_set_string->format('d') |
|
| 441 | - ); |
|
| 442 | - } else { |
|
| 443 | - //parse incoming string |
|
| 444 | - $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - //make sure $current is in the correct timezone |
|
| 448 | - $current->setTimezone($this->_DateTimeZone); |
|
| 449 | - |
|
| 450 | - return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
| 451 | - } |
|
| 280 | + protected function _create_timezone_object_from_timezone_string($timezone_string = '') |
|
| 281 | + { |
|
| 282 | + return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * This just returns whatever is set for the current timezone. |
|
| 288 | + * |
|
| 289 | + * @access public |
|
| 290 | + * @return string timezone string |
|
| 291 | + */ |
|
| 292 | + public function get_timezone() |
|
| 293 | + { |
|
| 294 | + return $this->_timezone_string; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * set the $_date_format property |
|
| 300 | + * |
|
| 301 | + * @access public |
|
| 302 | + * |
|
| 303 | + * @param string $format a new date format (corresponding to formats accepted by PHP date() function) |
|
| 304 | + * @param bool $pretty Whether to set pretty format or not. |
|
| 305 | + * |
|
| 306 | + * @return void |
|
| 307 | + */ |
|
| 308 | + public function set_date_format($format, $pretty = false) |
|
| 309 | + { |
|
| 310 | + if ($pretty) { |
|
| 311 | + $this->_pretty_date_format = $format; |
|
| 312 | + } else { |
|
| 313 | + $this->_date_format = $format; |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * return the $_date_format property value. |
|
| 320 | + * |
|
| 321 | + * @param bool $pretty Whether to get pretty format or not. |
|
| 322 | + * |
|
| 323 | + * @return string |
|
| 324 | + */ |
|
| 325 | + public function get_date_format($pretty = false) |
|
| 326 | + { |
|
| 327 | + return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * set the $_time_format property |
|
| 333 | + * |
|
| 334 | + * @access public |
|
| 335 | + * |
|
| 336 | + * @param string $format a new time format (corresponding to formats accepted by PHP date() function) |
|
| 337 | + * @param bool $pretty Whether to set pretty format or not. |
|
| 338 | + * |
|
| 339 | + * @return void |
|
| 340 | + */ |
|
| 341 | + public function set_time_format($format, $pretty = false) |
|
| 342 | + { |
|
| 343 | + if ($pretty) { |
|
| 344 | + $this->_pretty_time_format = $format; |
|
| 345 | + } else { |
|
| 346 | + $this->_time_format = $format; |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * return the $_time_format property value. |
|
| 353 | + * |
|
| 354 | + * @param bool $pretty Whether to get pretty format or not. |
|
| 355 | + * |
|
| 356 | + * @return string |
|
| 357 | + */ |
|
| 358 | + public function get_time_format($pretty = false) |
|
| 359 | + { |
|
| 360 | + return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * set the $_pretty_date_format property |
|
| 366 | + * |
|
| 367 | + * @access public |
|
| 368 | + * |
|
| 369 | + * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
|
| 370 | + * |
|
| 371 | + * @return void |
|
| 372 | + */ |
|
| 373 | + public function set_pretty_date_format($format) |
|
| 374 | + { |
|
| 375 | + $this->_pretty_date_format = $format; |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * set the $_pretty_time_format property |
|
| 381 | + * |
|
| 382 | + * @access public |
|
| 383 | + * |
|
| 384 | + * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
|
| 385 | + * |
|
| 386 | + * @return void |
|
| 387 | + */ |
|
| 388 | + public function set_pretty_time_format($format) |
|
| 389 | + { |
|
| 390 | + $this->_pretty_time_format = $format; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * Only sets the time portion of the datetime. |
|
| 396 | + * |
|
| 397 | + * @param string|DateTime $time_to_set_string like 8am OR a DateTime object. |
|
| 398 | + * @param DateTime $current current DateTime object for the datetime field |
|
| 399 | + * |
|
| 400 | + * @return DateTime |
|
| 401 | + */ |
|
| 402 | + public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) |
|
| 403 | + { |
|
| 404 | + // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
| 405 | + // Otherwise parse the string. |
|
| 406 | + if ($time_to_set_string instanceof DateTime) { |
|
| 407 | + $parsed = array( |
|
| 408 | + 'hour' => $time_to_set_string->format('H'), |
|
| 409 | + 'minute' => $time_to_set_string->format('i'), |
|
| 410 | + 'second' => $time_to_set_string->format('s') |
|
| 411 | + ); |
|
| 412 | + } else { |
|
| 413 | + //parse incoming string |
|
| 414 | + $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + //make sure $current is in the correct timezone. |
|
| 418 | + $current->setTimezone($this->_DateTimeZone); |
|
| 419 | + |
|
| 420 | + return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Only sets the date portion of the datetime. |
|
| 426 | + * |
|
| 427 | + * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object. |
|
| 428 | + * @param DateTime $current current DateTime object for the datetime field |
|
| 429 | + * |
|
| 430 | + * @return DateTime |
|
| 431 | + */ |
|
| 432 | + public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) |
|
| 433 | + { |
|
| 434 | + // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
| 435 | + // Otherwise parse the string. |
|
| 436 | + if ($date_to_set_string instanceof DateTime) { |
|
| 437 | + $parsed = array( |
|
| 438 | + 'year' => $date_to_set_string->format('Y'), |
|
| 439 | + 'month' => $date_to_set_string->format('m'), |
|
| 440 | + 'day' => $date_to_set_string->format('d') |
|
| 441 | + ); |
|
| 442 | + } else { |
|
| 443 | + //parse incoming string |
|
| 444 | + $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + //make sure $current is in the correct timezone |
|
| 448 | + $current->setTimezone($this->_DateTimeZone); |
|
| 449 | + |
|
| 450 | + return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
| 451 | + } |
|
| 452 | 452 | |
| 453 | 453 | |
| 454 | 454 | |
@@ -460,10 +460,10 @@ discard block |
||
| 460 | 460 | * @return string formatted date time for given timezone |
| 461 | 461 | * @throws \EE_Error |
| 462 | 462 | */ |
| 463 | - public function prepare_for_get($DateTime) |
|
| 464 | - { |
|
| 465 | - return $this->_prepare_for_display($DateTime); |
|
| 466 | - } |
|
| 463 | + public function prepare_for_get($DateTime) |
|
| 464 | + { |
|
| 465 | + return $this->_prepare_for_display($DateTime); |
|
| 466 | + } |
|
| 467 | 467 | |
| 468 | 468 | |
| 469 | 469 | |
@@ -478,110 +478,110 @@ discard block |
||
| 478 | 478 | * @return string |
| 479 | 479 | * @throws \EE_Error |
| 480 | 480 | */ |
| 481 | - public function prepare_for_pretty_echoing($DateTime, $schema = null) |
|
| 482 | - { |
|
| 483 | - return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
| 489 | - * timezone). |
|
| 490 | - * |
|
| 491 | - * @param DateTime $DateTime |
|
| 492 | - * @param bool|string $schema |
|
| 493 | - * @return string |
|
| 494 | - * @throws \EE_Error |
|
| 495 | - */ |
|
| 496 | - protected function _prepare_for_display($DateTime, $schema = false) |
|
| 497 | - { |
|
| 498 | - if ( ! $DateTime instanceof DateTime) { |
|
| 499 | - if ($this->_nullable) { |
|
| 500 | - return ''; |
|
| 501 | - } else { |
|
| 502 | - if (WP_DEBUG) { |
|
| 503 | - throw new EE_Error( |
|
| 504 | - sprintf( |
|
| 505 | - __( |
|
| 506 | - 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', |
|
| 507 | - 'event_espresso' |
|
| 508 | - ), |
|
| 509 | - $this->_nicename |
|
| 510 | - ) |
|
| 511 | - ); |
|
| 512 | - } else { |
|
| 513 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now); |
|
| 514 | - EE_Error::add_error( |
|
| 515 | - sprintf( |
|
| 516 | - __( |
|
| 517 | - 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', |
|
| 518 | - 'event_espresso' |
|
| 519 | - ), |
|
| 520 | - $this->_nicename |
|
| 521 | - ) |
|
| 522 | - ); |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - } |
|
| 526 | - $format_string = $this->_get_date_time_output($schema); |
|
| 527 | - //make sure datetime_value is in the correct timezone (in case that's been updated). |
|
| 528 | - $DateTime->setTimezone($this->_DateTimeZone); |
|
| 529 | - if ($schema) { |
|
| 530 | - if ($this->_display_timezone()) { |
|
| 531 | - //must be explicit because schema could equal true. |
|
| 532 | - if ($schema === 'no_html') { |
|
| 533 | - $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
| 534 | - } else { |
|
| 535 | - $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
| 536 | - } |
|
| 537 | - } else { |
|
| 538 | - $timezone_string = ''; |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - return $DateTime->format($format_string) . $timezone_string; |
|
| 542 | - } else { |
|
| 543 | - return $DateTime->format($format_string); |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
| 550 | - * timezone). |
|
| 551 | - * |
|
| 552 | - * @param mixed $datetime_value u |
|
| 553 | - * |
|
| 554 | - * @return string mysql timestamp in UTC |
|
| 555 | - * @throws \EE_Error |
|
| 556 | - */ |
|
| 557 | - public function prepare_for_use_in_db($datetime_value) |
|
| 558 | - { |
|
| 559 | - //we allow an empty value or DateTime object, but nothing else. |
|
| 560 | - if ( ! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
| 561 | - throw new EE_Error( |
|
| 562 | - __( |
|
| 563 | - 'The incoming value being prepared for setting in the database must either be empty or a php DateTime object', |
|
| 564 | - 'event_espresso' |
|
| 565 | - ) |
|
| 566 | - ); |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - if ($datetime_value instanceof DateTime) { |
|
| 570 | - if ( ! $datetime_value instanceof DbSafeDateTime) { |
|
| 571 | - $datetime_value = new DbSafeDateTime( |
|
| 572 | - $datetime_value->format(EE_Datetime_Field::mysql_timestamp_format), |
|
| 573 | - new \DateTimeZone($datetime_value->format('e')) |
|
| 574 | - ); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format( |
|
| 578 | - EE_Datetime_Field::mysql_timestamp_format |
|
| 579 | - ); |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
|
| 583 | - return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
| 584 | - } |
|
| 481 | + public function prepare_for_pretty_echoing($DateTime, $schema = null) |
|
| 482 | + { |
|
| 483 | + return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
| 489 | + * timezone). |
|
| 490 | + * |
|
| 491 | + * @param DateTime $DateTime |
|
| 492 | + * @param bool|string $schema |
|
| 493 | + * @return string |
|
| 494 | + * @throws \EE_Error |
|
| 495 | + */ |
|
| 496 | + protected function _prepare_for_display($DateTime, $schema = false) |
|
| 497 | + { |
|
| 498 | + if ( ! $DateTime instanceof DateTime) { |
|
| 499 | + if ($this->_nullable) { |
|
| 500 | + return ''; |
|
| 501 | + } else { |
|
| 502 | + if (WP_DEBUG) { |
|
| 503 | + throw new EE_Error( |
|
| 504 | + sprintf( |
|
| 505 | + __( |
|
| 506 | + 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', |
|
| 507 | + 'event_espresso' |
|
| 508 | + ), |
|
| 509 | + $this->_nicename |
|
| 510 | + ) |
|
| 511 | + ); |
|
| 512 | + } else { |
|
| 513 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now); |
|
| 514 | + EE_Error::add_error( |
|
| 515 | + sprintf( |
|
| 516 | + __( |
|
| 517 | + 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', |
|
| 518 | + 'event_espresso' |
|
| 519 | + ), |
|
| 520 | + $this->_nicename |
|
| 521 | + ) |
|
| 522 | + ); |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | + $format_string = $this->_get_date_time_output($schema); |
|
| 527 | + //make sure datetime_value is in the correct timezone (in case that's been updated). |
|
| 528 | + $DateTime->setTimezone($this->_DateTimeZone); |
|
| 529 | + if ($schema) { |
|
| 530 | + if ($this->_display_timezone()) { |
|
| 531 | + //must be explicit because schema could equal true. |
|
| 532 | + if ($schema === 'no_html') { |
|
| 533 | + $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
| 534 | + } else { |
|
| 535 | + $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
| 536 | + } |
|
| 537 | + } else { |
|
| 538 | + $timezone_string = ''; |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + return $DateTime->format($format_string) . $timezone_string; |
|
| 542 | + } else { |
|
| 543 | + return $DateTime->format($format_string); |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
| 550 | + * timezone). |
|
| 551 | + * |
|
| 552 | + * @param mixed $datetime_value u |
|
| 553 | + * |
|
| 554 | + * @return string mysql timestamp in UTC |
|
| 555 | + * @throws \EE_Error |
|
| 556 | + */ |
|
| 557 | + public function prepare_for_use_in_db($datetime_value) |
|
| 558 | + { |
|
| 559 | + //we allow an empty value or DateTime object, but nothing else. |
|
| 560 | + if ( ! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
| 561 | + throw new EE_Error( |
|
| 562 | + __( |
|
| 563 | + 'The incoming value being prepared for setting in the database must either be empty or a php DateTime object', |
|
| 564 | + 'event_espresso' |
|
| 565 | + ) |
|
| 566 | + ); |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + if ($datetime_value instanceof DateTime) { |
|
| 570 | + if ( ! $datetime_value instanceof DbSafeDateTime) { |
|
| 571 | + $datetime_value = new DbSafeDateTime( |
|
| 572 | + $datetime_value->format(EE_Datetime_Field::mysql_timestamp_format), |
|
| 573 | + new \DateTimeZone($datetime_value->format('e')) |
|
| 574 | + ); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format( |
|
| 578 | + EE_Datetime_Field::mysql_timestamp_format |
|
| 579 | + ); |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
|
| 583 | + return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
| 584 | + } |
|
| 585 | 585 | |
| 586 | 586 | |
| 587 | 587 | |
@@ -593,38 +593,38 @@ discard block |
||
| 593 | 593 | * @return mixed null | DateTime |
| 594 | 594 | * @throws \EE_Error |
| 595 | 595 | */ |
| 596 | - public function prepare_for_set_from_db($datetime_string) |
|
| 597 | - { |
|
| 598 | - //if $datetime_value is empty, and ! $this->_nullable, just use time() |
|
| 599 | - if (empty($datetime_string) && $this->_nullable) { |
|
| 600 | - return null; |
|
| 601 | - } |
|
| 602 | - // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
|
| 603 | - if (empty($datetime_string)) { |
|
| 604 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
| 605 | - } else { |
|
| 606 | - $DateTime = DateTime::createFromFormat( |
|
| 607 | - EE_Datetime_Field::mysql_timestamp_format, |
|
| 608 | - $datetime_string, |
|
| 609 | - $this->get_UTC_DateTimeZone() |
|
| 610 | - ); |
|
| 611 | - if ($DateTime instanceof \DateTime) { |
|
| 612 | - $DateTime = new DbSafeDateTime( |
|
| 613 | - $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 614 | - $this->get_UTC_DateTimeZone() |
|
| 615 | - ); |
|
| 616 | - } |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - if ( ! $DateTime instanceof DbSafeDateTime) { |
|
| 620 | - // if still no datetime object, then let's just use now |
|
| 621 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
| 622 | - } |
|
| 623 | - // THEN apply the field's set DateTimeZone |
|
| 624 | - $DateTime->setTimezone($this->_DateTimeZone); |
|
| 625 | - |
|
| 626 | - return $DateTime; |
|
| 627 | - } |
|
| 596 | + public function prepare_for_set_from_db($datetime_string) |
|
| 597 | + { |
|
| 598 | + //if $datetime_value is empty, and ! $this->_nullable, just use time() |
|
| 599 | + if (empty($datetime_string) && $this->_nullable) { |
|
| 600 | + return null; |
|
| 601 | + } |
|
| 602 | + // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
|
| 603 | + if (empty($datetime_string)) { |
|
| 604 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
| 605 | + } else { |
|
| 606 | + $DateTime = DateTime::createFromFormat( |
|
| 607 | + EE_Datetime_Field::mysql_timestamp_format, |
|
| 608 | + $datetime_string, |
|
| 609 | + $this->get_UTC_DateTimeZone() |
|
| 610 | + ); |
|
| 611 | + if ($DateTime instanceof \DateTime) { |
|
| 612 | + $DateTime = new DbSafeDateTime( |
|
| 613 | + $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 614 | + $this->get_UTC_DateTimeZone() |
|
| 615 | + ); |
|
| 616 | + } |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + if ( ! $DateTime instanceof DbSafeDateTime) { |
|
| 620 | + // if still no datetime object, then let's just use now |
|
| 621 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
| 622 | + } |
|
| 623 | + // THEN apply the field's set DateTimeZone |
|
| 624 | + $DateTime->setTimezone($this->_DateTimeZone); |
|
| 625 | + |
|
| 626 | + return $DateTime; |
|
| 627 | + } |
|
| 628 | 628 | |
| 629 | 629 | |
| 630 | 630 | |
@@ -636,110 +636,110 @@ discard block |
||
| 636 | 636 | * @return bool true for yes false for no |
| 637 | 637 | * @throws \EE_Error |
| 638 | 638 | */ |
| 639 | - protected function _display_timezone() |
|
| 640 | - { |
|
| 641 | - |
|
| 642 | - // first let's do a comparison of timezone strings. |
|
| 643 | - // If they match then we can get out without any further calculations |
|
| 644 | - $blog_string = get_option('timezone_string'); |
|
| 645 | - if ($blog_string === $this->_timezone_string) { |
|
| 646 | - return false; |
|
| 647 | - } |
|
| 648 | - // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
|
| 649 | - $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
| 650 | - $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
| 651 | - // now compare |
|
| 652 | - return $blog_offset !== $this_offset; |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - |
|
| 656 | - /** |
|
| 657 | - * This method returns a php DateTime object for setting on the EE_Base_Class model. |
|
| 658 | - * EE passes around DateTime objects because they are MUCH easier to manipulate and deal |
|
| 659 | - * with. |
|
| 660 | - * |
|
| 661 | - * @param int|string|DateTime $date_string This should be the incoming date string. It's assumed to be |
|
| 662 | - * in the format that is set on the date_field (or DateTime |
|
| 663 | - * object)! |
|
| 664 | - * |
|
| 665 | - * @return DateTime |
|
| 666 | - */ |
|
| 667 | - protected function _get_date_object($date_string) |
|
| 668 | - { |
|
| 669 | - //first if this is an empty date_string and nullable is allowed, just return null. |
|
| 670 | - if ($this->_nullable && empty($date_string)) { |
|
| 671 | - return null; |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - // if incoming date |
|
| 675 | - if ($date_string instanceof DateTime) { |
|
| 676 | - $date_string->setTimezone($this->_DateTimeZone); |
|
| 677 | - |
|
| 678 | - return $date_string; |
|
| 679 | - } |
|
| 680 | - // if empty date_string and made it here. |
|
| 681 | - // Return a datetime object for now in the given timezone. |
|
| 682 | - if (empty($date_string)) { |
|
| 683 | - return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 684 | - } |
|
| 685 | - // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
|
| 686 | - if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
| 687 | - try { |
|
| 688 | - // This is operating under the assumption that the incoming Unix timestamp |
|
| 689 | - // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp'); |
|
| 690 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 691 | - $DateTime->setTimestamp($date_string); |
|
| 692 | - |
|
| 693 | - return $DateTime; |
|
| 694 | - } catch (Exception $e) { |
|
| 695 | - // should be rare, but if things got fooled then let's just continue |
|
| 696 | - } |
|
| 697 | - } |
|
| 698 | - //not a unix timestamp. So we will use the set format on this object and set timezone to |
|
| 699 | - //create the DateTime object. |
|
| 700 | - $format = $this->_date_format . ' ' . $this->_time_format; |
|
| 701 | - try { |
|
| 702 | - $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
| 703 | - if ($DateTime instanceof DateTime) { |
|
| 704 | - $DateTime = new DbSafeDateTime( |
|
| 705 | - $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 706 | - $this->_DateTimeZone |
|
| 707 | - ); |
|
| 708 | - } |
|
| 709 | - if ( ! $DateTime instanceof DbSafeDateTime) { |
|
| 710 | - throw new EE_Error( |
|
| 711 | - sprintf( |
|
| 712 | - __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
| 713 | - $date_string, |
|
| 714 | - $format |
|
| 715 | - ) |
|
| 716 | - ); |
|
| 717 | - } |
|
| 718 | - } catch (Exception $e) { |
|
| 719 | - // if we made it here then likely then something went really wrong. |
|
| 720 | - // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
|
| 721 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - return $DateTime; |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - |
|
| 728 | - /** |
|
| 729 | - * get_timezone_offset |
|
| 730 | - * |
|
| 731 | - * @param \DateTimeZone $DateTimeZone |
|
| 732 | - * @param int $time |
|
| 733 | - * |
|
| 734 | - * @return mixed |
|
| 735 | - */ |
|
| 736 | - public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
|
| 737 | - { |
|
| 738 | - $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
| 739 | - $transitions = $DateTimeZone->getTransitions($time); |
|
| 740 | - |
|
| 741 | - return $transitions[0]['offset']; |
|
| 742 | - } |
|
| 639 | + protected function _display_timezone() |
|
| 640 | + { |
|
| 641 | + |
|
| 642 | + // first let's do a comparison of timezone strings. |
|
| 643 | + // If they match then we can get out without any further calculations |
|
| 644 | + $blog_string = get_option('timezone_string'); |
|
| 645 | + if ($blog_string === $this->_timezone_string) { |
|
| 646 | + return false; |
|
| 647 | + } |
|
| 648 | + // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
|
| 649 | + $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
| 650 | + $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
| 651 | + // now compare |
|
| 652 | + return $blog_offset !== $this_offset; |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + |
|
| 656 | + /** |
|
| 657 | + * This method returns a php DateTime object for setting on the EE_Base_Class model. |
|
| 658 | + * EE passes around DateTime objects because they are MUCH easier to manipulate and deal |
|
| 659 | + * with. |
|
| 660 | + * |
|
| 661 | + * @param int|string|DateTime $date_string This should be the incoming date string. It's assumed to be |
|
| 662 | + * in the format that is set on the date_field (or DateTime |
|
| 663 | + * object)! |
|
| 664 | + * |
|
| 665 | + * @return DateTime |
|
| 666 | + */ |
|
| 667 | + protected function _get_date_object($date_string) |
|
| 668 | + { |
|
| 669 | + //first if this is an empty date_string and nullable is allowed, just return null. |
|
| 670 | + if ($this->_nullable && empty($date_string)) { |
|
| 671 | + return null; |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + // if incoming date |
|
| 675 | + if ($date_string instanceof DateTime) { |
|
| 676 | + $date_string->setTimezone($this->_DateTimeZone); |
|
| 677 | + |
|
| 678 | + return $date_string; |
|
| 679 | + } |
|
| 680 | + // if empty date_string and made it here. |
|
| 681 | + // Return a datetime object for now in the given timezone. |
|
| 682 | + if (empty($date_string)) { |
|
| 683 | + return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 684 | + } |
|
| 685 | + // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
|
| 686 | + if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
| 687 | + try { |
|
| 688 | + // This is operating under the assumption that the incoming Unix timestamp |
|
| 689 | + // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp'); |
|
| 690 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 691 | + $DateTime->setTimestamp($date_string); |
|
| 692 | + |
|
| 693 | + return $DateTime; |
|
| 694 | + } catch (Exception $e) { |
|
| 695 | + // should be rare, but if things got fooled then let's just continue |
|
| 696 | + } |
|
| 697 | + } |
|
| 698 | + //not a unix timestamp. So we will use the set format on this object and set timezone to |
|
| 699 | + //create the DateTime object. |
|
| 700 | + $format = $this->_date_format . ' ' . $this->_time_format; |
|
| 701 | + try { |
|
| 702 | + $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
| 703 | + if ($DateTime instanceof DateTime) { |
|
| 704 | + $DateTime = new DbSafeDateTime( |
|
| 705 | + $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 706 | + $this->_DateTimeZone |
|
| 707 | + ); |
|
| 708 | + } |
|
| 709 | + if ( ! $DateTime instanceof DbSafeDateTime) { |
|
| 710 | + throw new EE_Error( |
|
| 711 | + sprintf( |
|
| 712 | + __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
| 713 | + $date_string, |
|
| 714 | + $format |
|
| 715 | + ) |
|
| 716 | + ); |
|
| 717 | + } |
|
| 718 | + } catch (Exception $e) { |
|
| 719 | + // if we made it here then likely then something went really wrong. |
|
| 720 | + // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
|
| 721 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + return $DateTime; |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + |
|
| 728 | + /** |
|
| 729 | + * get_timezone_offset |
|
| 730 | + * |
|
| 731 | + * @param \DateTimeZone $DateTimeZone |
|
| 732 | + * @param int $time |
|
| 733 | + * |
|
| 734 | + * @return mixed |
|
| 735 | + */ |
|
| 736 | + public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
|
| 737 | + { |
|
| 738 | + $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
| 739 | + $transitions = $DateTimeZone->getTransitions($time); |
|
| 740 | + |
|
| 741 | + return $transitions[0]['offset']; |
|
| 742 | + } |
|
| 743 | 743 | |
| 744 | 744 | |
| 745 | 745 | |
@@ -750,27 +750,27 @@ discard block |
||
| 750 | 750 | * @return string abbreviation |
| 751 | 751 | * @throws \EE_Error |
| 752 | 752 | */ |
| 753 | - public function get_timezone_abbrev($timezone_string) |
|
| 754 | - { |
|
| 755 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
| 756 | - $dateTime = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string)); |
|
| 757 | - |
|
| 758 | - return $dateTime->format('T'); |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - /** |
|
| 762 | - * Overrides the parent to allow for having a dynamic "now" value |
|
| 763 | - * |
|
| 764 | - * @return mixed |
|
| 765 | - */ |
|
| 766 | - public function get_default_value() |
|
| 767 | - { |
|
| 768 | - if ($this->_default_value === EE_Datetime_Field::now) { |
|
| 769 | - return time(); |
|
| 770 | - } else { |
|
| 771 | - return parent::get_default_value(); |
|
| 772 | - } |
|
| 773 | - } |
|
| 753 | + public function get_timezone_abbrev($timezone_string) |
|
| 754 | + { |
|
| 755 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
| 756 | + $dateTime = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string)); |
|
| 757 | + |
|
| 758 | + return $dateTime->format('T'); |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + /** |
|
| 762 | + * Overrides the parent to allow for having a dynamic "now" value |
|
| 763 | + * |
|
| 764 | + * @return mixed |
|
| 765 | + */ |
|
| 766 | + public function get_default_value() |
|
| 767 | + { |
|
| 768 | + if ($this->_default_value === EE_Datetime_Field::now) { |
|
| 769 | + return time(); |
|
| 770 | + } else { |
|
| 771 | + return parent::get_default_value(); |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | 774 | |
| 775 | 775 | |
| 776 | 776 | } |
@@ -222,8 +222,8 @@ discard block |
||
| 222 | 222 | |
| 223 | 223 | default : |
| 224 | 224 | return $pretty |
| 225 | - ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
| 226 | - : $this->_date_format . ' ' . $this->_time_format; |
|
| 225 | + ? $this->_pretty_date_format.' '.$this->_pretty_time_format |
|
| 226 | + : $this->_date_format.' '.$this->_time_format; |
|
| 227 | 227 | } |
| 228 | 228 | } |
| 229 | 229 | |
@@ -530,15 +530,15 @@ discard block |
||
| 530 | 530 | if ($this->_display_timezone()) { |
| 531 | 531 | //must be explicit because schema could equal true. |
| 532 | 532 | if ($schema === 'no_html') { |
| 533 | - $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
| 533 | + $timezone_string = ' ('.$DateTime->format('T').')'; |
|
| 534 | 534 | } else { |
| 535 | - $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
| 535 | + $timezone_string = ' <span class="ee_dtt_timezone_string">('.$DateTime->format('T').')</span>'; |
|
| 536 | 536 | } |
| 537 | 537 | } else { |
| 538 | 538 | $timezone_string = ''; |
| 539 | 539 | } |
| 540 | 540 | |
| 541 | - return $DateTime->format($format_string) . $timezone_string; |
|
| 541 | + return $DateTime->format($format_string).$timezone_string; |
|
| 542 | 542 | } else { |
| 543 | 543 | return $DateTime->format($format_string); |
| 544 | 544 | } |
@@ -697,7 +697,7 @@ discard block |
||
| 697 | 697 | } |
| 698 | 698 | //not a unix timestamp. So we will use the set format on this object and set timezone to |
| 699 | 699 | //create the DateTime object. |
| 700 | - $format = $this->_date_format . ' ' . $this->_time_format; |
|
| 700 | + $format = $this->_date_format.' '.$this->_time_format; |
|
| 701 | 701 | try { |
| 702 | 702 | $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
| 703 | 703 | if ($DateTime instanceof DateTime) { |
@@ -1,16 +1,16 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
| 2 | 2 | /** |
| 3 | - * |
|
| 4 | - * Class EE_Checkout |
|
| 5 | - * |
|
| 6 | - * Description |
|
| 7 | - * |
|
| 8 | - * @package Event Espresso |
|
| 9 | - * @subpackage core |
|
| 10 | - * @author Brent Christensen |
|
| 11 | - * @since 4.5.0 |
|
| 12 | - * |
|
| 13 | - */ |
|
| 3 | + * |
|
| 4 | + * Class EE_Checkout |
|
| 5 | + * |
|
| 6 | + * Description |
|
| 7 | + * |
|
| 8 | + * @package Event Espresso |
|
| 9 | + * @subpackage core |
|
| 10 | + * @author Brent Christensen |
|
| 11 | + * @since 4.5.0 |
|
| 12 | + * |
|
| 13 | + */ |
|
| 14 | 14 | class EE_Checkout { |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -804,10 +804,10 @@ discard block |
||
| 804 | 804 | */ |
| 805 | 805 | public function visit_allows_processing_of_this_registration( EE_Registration $registration ) { |
| 806 | 806 | return ! $this->revisit |
| 807 | - || $this->primary_revisit |
|
| 808 | - || ( |
|
| 809 | - $this->revisit && $this->reg_url_link === $registration->reg_url_link() |
|
| 810 | - ) |
|
| 807 | + || $this->primary_revisit |
|
| 808 | + || ( |
|
| 809 | + $this->revisit && $this->reg_url_link === $registration->reg_url_link() |
|
| 810 | + ) |
|
| 811 | 811 | ? true |
| 812 | 812 | : false; |
| 813 | 813 | } |
@@ -1199,16 +1199,16 @@ discard block |
||
| 1199 | 1199 | * @return array |
| 1200 | 1200 | * @throws \EE_Error |
| 1201 | 1201 | */ |
| 1202 | - public function __sleep() |
|
| 1203 | - { |
|
| 1204 | - if ( $this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID() ) { |
|
| 1205 | - $this->primary_attendee_obj = $this->primary_attendee_obj->ID(); |
|
| 1206 | - } // remove the reg form and the checkout |
|
| 1207 | - if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) { |
|
| 1208 | - $this->transaction = $this->transaction->ID(); |
|
| 1209 | - } // remove the reg form and the checkout |
|
| 1210 | - return array_diff( array_keys( get_object_vars( $this ) ), array( 'billing_form', 'registration_form' ) ); |
|
| 1211 | - } |
|
| 1202 | + public function __sleep() |
|
| 1203 | + { |
|
| 1204 | + if ( $this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID() ) { |
|
| 1205 | + $this->primary_attendee_obj = $this->primary_attendee_obj->ID(); |
|
| 1206 | + } // remove the reg form and the checkout |
|
| 1207 | + if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) { |
|
| 1208 | + $this->transaction = $this->transaction->ID(); |
|
| 1209 | + } // remove the reg form and the checkout |
|
| 1210 | + return array_diff( array_keys( get_object_vars( $this ) ), array( 'billing_form', 'registration_form' ) ); |
|
| 1211 | + } |
|
| 1212 | 1212 | |
| 1213 | 1213 | |
| 1214 | 1214 | /** |
@@ -247,9 +247,9 @@ discard block |
||
| 247 | 247 | $this->reg_page_base_url = EE_Registry::instance()->CFG->core->reg_page_url(); |
| 248 | 248 | $this->thank_you_page_url = EE_Registry::instance()->CFG->core->thank_you_page_url(); |
| 249 | 249 | $this->cancel_page_url = EE_Registry::instance()->CFG->core->cancel_page_url(); |
| 250 | - $this->continue_reg = apply_filters( 'FHEE__EE_Checkout___construct___continue_reg', TRUE ); |
|
| 250 | + $this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', TRUE); |
|
| 251 | 251 | $this->admin_request = is_admin() && ! EE_Registry::instance()->REQ->ajax; |
| 252 | - $this->reg_cache_where_params = array( 'order_by' => array( 'REG_count' => 'ASC' )); |
|
| 252 | + $this->reg_cache_where_params = array('order_by' => array('REG_count' => 'ASC')); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | |
@@ -260,8 +260,8 @@ discard block |
||
| 260 | 260 | * @return boolean |
| 261 | 261 | */ |
| 262 | 262 | public function any_reg_status_updated() { |
| 263 | - foreach ( $this->reg_status_updated as $reg_status ) { |
|
| 264 | - if ( $reg_status ) { |
|
| 263 | + foreach ($this->reg_status_updated as $reg_status) { |
|
| 264 | + if ($reg_status) { |
|
| 265 | 265 | return true; |
| 266 | 266 | } |
| 267 | 267 | } |
@@ -274,8 +274,8 @@ discard block |
||
| 274 | 274 | * @param $REG_ID |
| 275 | 275 | * @return boolean |
| 276 | 276 | */ |
| 277 | - public function reg_status_updated( $REG_ID ) { |
|
| 278 | - return isset( $this->reg_status_updated[ $REG_ID ] ) ? $this->reg_status_updated[ $REG_ID ] : false; |
|
| 277 | + public function reg_status_updated($REG_ID) { |
|
| 278 | + return isset($this->reg_status_updated[$REG_ID]) ? $this->reg_status_updated[$REG_ID] : false; |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | |
@@ -284,8 +284,8 @@ discard block |
||
| 284 | 284 | * @param $REG_ID |
| 285 | 285 | * @param $reg_status |
| 286 | 286 | */ |
| 287 | - public function set_reg_status_updated( $REG_ID, $reg_status ) { |
|
| 288 | - $this->reg_status_updated[ $REG_ID ] = filter_var( $reg_status, FILTER_VALIDATE_BOOLEAN ); |
|
| 287 | + public function set_reg_status_updated($REG_ID, $reg_status) { |
|
| 288 | + $this->reg_status_updated[$REG_ID] = filter_var($reg_status, FILTER_VALIDATE_BOOLEAN); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | * can ONLY be set by the Finalize_Registration reg step |
| 307 | 307 | */ |
| 308 | 308 | public function set_exit_spco() { |
| 309 | - if ( $this->current_step instanceof EE_SPCO_Reg_Step_Finalize_Registration ) { |
|
| 309 | + if ($this->current_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
| 310 | 310 | $this->exit_spco = true; |
| 311 | 311 | } |
| 312 | 312 | } |
@@ -323,12 +323,12 @@ discard block |
||
| 323 | 323 | */ |
| 324 | 324 | public function reset_for_current_request() { |
| 325 | 325 | $this->process_form_submission = FALSE; |
| 326 | - $this->continue_reg = apply_filters( 'FHEE__EE_Checkout___construct___continue_reg', true ); |
|
| 326 | + $this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', true); |
|
| 327 | 327 | $this->admin_request = is_admin() && ! EE_Registry::instance()->REQ->front_ajax; |
| 328 | 328 | $this->continue_reg = true; |
| 329 | 329 | $this->redirect = false; |
| 330 | 330 | // don't reset the cached redirect form if we're about to be asked to display it !!! |
| 331 | - if ( EE_Registry::instance()->REQ->get( 'action', 'display_spco_reg_step' ) !== 'redirect_form' ) { |
|
| 331 | + if (EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step') !== 'redirect_form') { |
|
| 332 | 332 | $this->redirect_form = ''; |
| 333 | 333 | } |
| 334 | 334 | $this->redirect_url = ''; |
@@ -345,8 +345,8 @@ discard block |
||
| 345 | 345 | * @param EE_SPCO_Reg_Step $reg_step_obj |
| 346 | 346 | * @return void |
| 347 | 347 | */ |
| 348 | - public function add_reg_step( EE_SPCO_Reg_Step $reg_step_obj ) { |
|
| 349 | - $this->reg_steps[ $reg_step_obj->slug() ] = $reg_step_obj; |
|
| 348 | + public function add_reg_step(EE_SPCO_Reg_Step $reg_step_obj) { |
|
| 349 | + $this->reg_steps[$reg_step_obj->slug()] = $reg_step_obj; |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | |
@@ -362,22 +362,22 @@ discard block |
||
| 362 | 362 | * @return void |
| 363 | 363 | * @throws \EE_Error |
| 364 | 364 | */ |
| 365 | - public function skip_reg_step( $reg_step_slug = '' ) { |
|
| 366 | - $step_to_skip = $this->find_reg_step( $reg_step_slug ); |
|
| 367 | - if ( $step_to_skip instanceof EE_SPCO_Reg_Step && $step_to_skip->is_current_step() ) { |
|
| 368 | - $step_to_skip->set_is_current_step( false ); |
|
| 365 | + public function skip_reg_step($reg_step_slug = '') { |
|
| 366 | + $step_to_skip = $this->find_reg_step($reg_step_slug); |
|
| 367 | + if ($step_to_skip instanceof EE_SPCO_Reg_Step && $step_to_skip->is_current_step()) { |
|
| 368 | + $step_to_skip->set_is_current_step(false); |
|
| 369 | 369 | $step_to_skip->set_completed(); |
| 370 | 370 | // advance to the next step |
| 371 | - $this->set_current_step( $this->next_step->slug() ); |
|
| 371 | + $this->set_current_step($this->next_step->slug()); |
|
| 372 | 372 | // also reset the step param in the request in case any other code references that directly |
| 373 | - EE_Registry::instance()->REQ->set( 'step', $this->current_step->slug() ); |
|
| 373 | + EE_Registry::instance()->REQ->set('step', $this->current_step->slug()); |
|
| 374 | 374 | // since we are skipping a step and setting the current step to be what was previously the next step, |
| 375 | 375 | // we need to check that the next step is now correct, and not still set to the current step. |
| 376 | - if ( $this->current_step->slug() === $this->next_step->slug() ) { |
|
| 376 | + if ($this->current_step->slug() === $this->next_step->slug()) { |
|
| 377 | 377 | // correctly setup the next step |
| 378 | 378 | $this->set_next_step(); |
| 379 | 379 | } |
| 380 | - $this->set_reg_step_initiated( $this->current_step ); |
|
| 380 | + $this->set_reg_step_initiated($this->current_step); |
|
| 381 | 381 | } |
| 382 | 382 | } |
| 383 | 383 | |
@@ -391,14 +391,14 @@ discard block |
||
| 391 | 391 | * @param bool $reset whether to reset reg steps after removal |
| 392 | 392 | * @throws EE_Error |
| 393 | 393 | */ |
| 394 | - public function remove_reg_step( $reg_step_slug = '', $reset = true ) { |
|
| 395 | - unset( $this->reg_steps[ $reg_step_slug ] ); |
|
| 396 | - if ( $this->transaction instanceof EE_Transaction ) { |
|
| 394 | + public function remove_reg_step($reg_step_slug = '', $reset = true) { |
|
| 395 | + unset($this->reg_steps[$reg_step_slug]); |
|
| 396 | + if ($this->transaction instanceof EE_Transaction) { |
|
| 397 | 397 | // now remove reg step from TXN and save |
| 398 | - $this->transaction->remove_reg_step( $reg_step_slug ); |
|
| 398 | + $this->transaction->remove_reg_step($reg_step_slug); |
|
| 399 | 399 | $this->transaction->save(); |
| 400 | 400 | } |
| 401 | - if ( $reset ) { |
|
| 401 | + if ($reset) { |
|
| 402 | 402 | $this->reset_reg_steps(); |
| 403 | 403 | } |
| 404 | 404 | } |
@@ -413,9 +413,9 @@ discard block |
||
| 413 | 413 | * @param int $order |
| 414 | 414 | * @return void |
| 415 | 415 | */ |
| 416 | - public function set_reg_step_order( $reg_step_slug = '', $order = 100 ) { |
|
| 417 | - if ( isset( $this->reg_steps[ $reg_step_slug ] )) { |
|
| 418 | - $this->reg_steps[ $reg_step_slug ]->set_order( $order ); |
|
| 416 | + public function set_reg_step_order($reg_step_slug = '', $order = 100) { |
|
| 417 | + if (isset($this->reg_steps[$reg_step_slug])) { |
|
| 418 | + $this->reg_steps[$reg_step_slug]->set_order($order); |
|
| 419 | 419 | } |
| 420 | 420 | } |
| 421 | 421 | |
@@ -428,25 +428,25 @@ discard block |
||
| 428 | 428 | * @param string $current_step |
| 429 | 429 | * @return void |
| 430 | 430 | */ |
| 431 | - public function set_current_step( $current_step ) { |
|
| 431 | + public function set_current_step($current_step) { |
|
| 432 | 432 | // grab what step we're on |
| 433 | - $this->current_step = isset( $this->reg_steps[ $current_step ] ) ? $this->reg_steps[ $current_step ] : reset( $this->reg_steps ); |
|
| 433 | + $this->current_step = isset($this->reg_steps[$current_step]) ? $this->reg_steps[$current_step] : reset($this->reg_steps); |
|
| 434 | 434 | // verify instance |
| 435 | - if ( $this->current_step instanceof EE_SPCO_Reg_Step ) { |
|
| 435 | + if ($this->current_step instanceof EE_SPCO_Reg_Step) { |
|
| 436 | 436 | // we don't want to repeat completed steps if this is the first time through SPCO |
| 437 | - if ( $this->continue_reg && ! $this->revisit && $this->current_step->completed() ) { |
|
| 437 | + if ($this->continue_reg && ! $this->revisit && $this->current_step->completed()) { |
|
| 438 | 438 | // so advance to the next step |
| 439 | 439 | $this->set_next_step(); |
| 440 | - if ( $this->next_step instanceof EE_SPCO_Reg_Step ) { |
|
| 440 | + if ($this->next_step instanceof EE_SPCO_Reg_Step) { |
|
| 441 | 441 | // and attempt to set it as the current step |
| 442 | - $this->set_current_step( $this->next_step->slug() ); |
|
| 442 | + $this->set_current_step($this->next_step->slug()); |
|
| 443 | 443 | } |
| 444 | 444 | return; |
| 445 | 445 | } |
| 446 | - $this->current_step->set_is_current_step( TRUE ); |
|
| 446 | + $this->current_step->set_is_current_step(TRUE); |
|
| 447 | 447 | } else { |
| 448 | 448 | EE_Error::add_error( |
| 449 | - __( 'The current step could not be set.', 'event_espresso' ), |
|
| 449 | + __('The current step could not be set.', 'event_espresso'), |
|
| 450 | 450 | __FILE__, __FUNCTION__, __LINE__ |
| 451 | 451 | ); |
| 452 | 452 | } |
@@ -463,20 +463,20 @@ discard block |
||
| 463 | 463 | */ |
| 464 | 464 | public function set_next_step() { |
| 465 | 465 | // set pointer to start of array |
| 466 | - reset( $this->reg_steps ); |
|
| 466 | + reset($this->reg_steps); |
|
| 467 | 467 | // if there is more than one step |
| 468 | - if ( count( $this->reg_steps ) > 1 ) { |
|
| 468 | + if (count($this->reg_steps) > 1) { |
|
| 469 | 469 | // advance to the current step and set pointer |
| 470 | - while ( key( $this->reg_steps ) !== $this->current_step->slug() && key( $this->reg_steps ) !== '' ) { |
|
| 471 | - next( $this->reg_steps ); |
|
| 470 | + while (key($this->reg_steps) !== $this->current_step->slug() && key($this->reg_steps) !== '') { |
|
| 471 | + next($this->reg_steps); |
|
| 472 | 472 | } |
| 473 | 473 | } |
| 474 | 474 | // advance one more spot ( if it exists ) |
| 475 | - $this->next_step = next( $this->reg_steps ); |
|
| 475 | + $this->next_step = next($this->reg_steps); |
|
| 476 | 476 | // verify instance |
| 477 | - $this->next_step = $this->next_step instanceof EE_SPCO_Reg_Step ? $this->next_step : NULL; |
|
| 477 | + $this->next_step = $this->next_step instanceof EE_SPCO_Reg_Step ? $this->next_step : NULL; |
|
| 478 | 478 | // then back to current step to reset |
| 479 | - prev( $this->reg_steps ); |
|
| 479 | + prev($this->reg_steps); |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | |
@@ -490,8 +490,8 @@ discard block |
||
| 490 | 490 | * @return EE_SPCO_Reg_Step | null |
| 491 | 491 | */ |
| 492 | 492 | public function get_next_reg_step() { |
| 493 | - $next = next( $this->reg_steps ); |
|
| 494 | - prev( $this->reg_steps ); |
|
| 493 | + $next = next($this->reg_steps); |
|
| 494 | + prev($this->reg_steps); |
|
| 495 | 495 | return $next instanceof EE_SPCO_Reg_Step ? $next : null; |
| 496 | 496 | } |
| 497 | 497 | |
@@ -506,8 +506,8 @@ discard block |
||
| 506 | 506 | * @return EE_SPCO_Reg_Step | null |
| 507 | 507 | */ |
| 508 | 508 | public function get_prev_reg_step() { |
| 509 | - $prev = prev( $this->reg_steps ); |
|
| 510 | - next( $this->reg_steps ); |
|
| 509 | + $prev = prev($this->reg_steps); |
|
| 510 | + next($this->reg_steps); |
|
| 511 | 511 | return $prev instanceof EE_SPCO_Reg_Step ? $prev : null; |
| 512 | 512 | } |
| 513 | 513 | |
@@ -520,8 +520,8 @@ discard block |
||
| 520 | 520 | * @return void |
| 521 | 521 | */ |
| 522 | 522 | public function sort_reg_steps() { |
| 523 | - $reg_step_sorting_callback = apply_filters( 'FHEE__EE_Checkout__sort_reg_steps__reg_step_sorting_callback', 'reg_step_sorting_callback' ); |
|
| 524 | - uasort( $this->reg_steps, array( $this, $reg_step_sorting_callback )); |
|
| 523 | + $reg_step_sorting_callback = apply_filters('FHEE__EE_Checkout__sort_reg_steps__reg_step_sorting_callback', 'reg_step_sorting_callback'); |
|
| 524 | + uasort($this->reg_steps, array($this, $reg_step_sorting_callback)); |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | |
@@ -534,19 +534,19 @@ discard block |
||
| 534 | 534 | * @param string $reg_step_slug |
| 535 | 535 | * @return EE_SPCO_Reg_Step|null |
| 536 | 536 | */ |
| 537 | - public function find_reg_step( $reg_step_slug = '' ) { |
|
| 538 | - if ( ! empty( $reg_step_slug ) ) { |
|
| 537 | + public function find_reg_step($reg_step_slug = '') { |
|
| 538 | + if ( ! empty($reg_step_slug)) { |
|
| 539 | 539 | // copy reg step array |
| 540 | 540 | $reg_steps = $this->reg_steps; |
| 541 | 541 | // set pointer to start of array |
| 542 | - reset( $reg_steps ); |
|
| 542 | + reset($reg_steps); |
|
| 543 | 543 | // if there is more than one step |
| 544 | - if ( count( $reg_steps ) > 1 ) { |
|
| 544 | + if (count($reg_steps) > 1) { |
|
| 545 | 545 | // advance to the current step and set pointer |
| 546 | - while ( key( $reg_steps ) !== $reg_step_slug && key( $reg_steps ) !== '' ) { |
|
| 547 | - next( $reg_steps ); |
|
| 546 | + while (key($reg_steps) !== $reg_step_slug && key($reg_steps) !== '') { |
|
| 547 | + next($reg_steps); |
|
| 548 | 548 | } |
| 549 | - return current( $reg_steps ); |
|
| 549 | + return current($reg_steps); |
|
| 550 | 550 | } |
| 551 | 551 | } |
| 552 | 552 | return null; |
@@ -562,17 +562,17 @@ discard block |
||
| 562 | 562 | * @param EE_SPCO_Reg_Step $reg_step_B |
| 563 | 563 | * @return int |
| 564 | 564 | */ |
| 565 | - public function reg_step_sorting_callback( EE_SPCO_Reg_Step $reg_step_A, EE_SPCO_Reg_Step $reg_step_B ) { |
|
| 565 | + public function reg_step_sorting_callback(EE_SPCO_Reg_Step $reg_step_A, EE_SPCO_Reg_Step $reg_step_B) { |
|
| 566 | 566 | // send finalize_registration step to the end of the array |
| 567 | - if ( $reg_step_A->slug() === 'finalize_registration' ) { |
|
| 567 | + if ($reg_step_A->slug() === 'finalize_registration') { |
|
| 568 | 568 | return 1; |
| 569 | - } else if ( $reg_step_B->slug() === 'finalize_registration' ) { |
|
| 569 | + } else if ($reg_step_B->slug() === 'finalize_registration') { |
|
| 570 | 570 | return -1; |
| 571 | 571 | } |
| 572 | - if ( $reg_step_A->order() === $reg_step_B->order() ) { |
|
| 572 | + if ($reg_step_A->order() === $reg_step_B->order()) { |
|
| 573 | 573 | return 0; |
| 574 | 574 | } |
| 575 | - return ( $reg_step_A->order() > $reg_step_B->order() ) ? 1 : -1; |
|
| 575 | + return ($reg_step_A->order() > $reg_step_B->order()) ? 1 : -1; |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | * @param EE_SPCO_Reg_Step $reg_step |
| 585 | 585 | * @throws \EE_Error |
| 586 | 586 | */ |
| 587 | - public function set_reg_step_initiated( EE_SPCO_Reg_Step $reg_step ) { |
|
| 587 | + public function set_reg_step_initiated(EE_SPCO_Reg_Step $reg_step) { |
|
| 588 | 588 | // call set_reg_step_initiated ??? |
| 589 | 589 | if ( |
| 590 | 590 | // first time visiting SPCO ? |
@@ -597,11 +597,11 @@ discard block |
||
| 597 | 597 | ) |
| 598 | 598 | ) { |
| 599 | 599 | // set the start time for this reg step |
| 600 | - if ( ! $this->transaction->set_reg_step_initiated( $reg_step->slug() ) ) { |
|
| 601 | - if ( WP_DEBUG ) { |
|
| 600 | + if ( ! $this->transaction->set_reg_step_initiated($reg_step->slug())) { |
|
| 601 | + if (WP_DEBUG) { |
|
| 602 | 602 | EE_Error::add_error( |
| 603 | 603 | sprintf( |
| 604 | - __( 'The "%1$s" registration step was not initialized properly.', 'event_espresso' ), |
|
| 604 | + __('The "%1$s" registration step was not initialized properly.', 'event_espresso'), |
|
| 605 | 605 | $reg_step->name() |
| 606 | 606 | ), |
| 607 | 607 | __FILE__, __FUNCTION__, __LINE__ |
@@ -620,10 +620,10 @@ discard block |
||
| 620 | 620 | * @return void |
| 621 | 621 | */ |
| 622 | 622 | public function set_reg_step_JSON_info() { |
| 623 | - EE_Registry::$i18n_js_strings[ 'reg_steps' ] = array(); |
|
| 623 | + EE_Registry::$i18n_js_strings['reg_steps'] = array(); |
|
| 624 | 624 | // pass basic reg step data to JS |
| 625 | - foreach ( $this->reg_steps as $reg_step ) { |
|
| 626 | - EE_Registry::$i18n_js_strings[ 'reg_steps' ][] = $reg_step->slug(); |
|
| 625 | + foreach ($this->reg_steps as $reg_step) { |
|
| 626 | + EE_Registry::$i18n_js_strings['reg_steps'][] = $reg_step->slug(); |
|
| 627 | 627 | } |
| 628 | 628 | // reset reg step html |
| 629 | 629 | // $this->json_response->set_reg_step_html( '' ); |
@@ -639,7 +639,7 @@ discard block |
||
| 639 | 639 | */ |
| 640 | 640 | public function reset_reg_steps() { |
| 641 | 641 | $this->sort_reg_steps(); |
| 642 | - $this->set_current_step( EE_Registry::instance()->REQ->get( 'step' )); |
|
| 642 | + $this->set_current_step(EE_Registry::instance()->REQ->get('step')); |
|
| 643 | 643 | $this->set_next_step(); |
| 644 | 644 | // the text that appears on the reg step form submit button |
| 645 | 645 | $this->current_step->set_submit_button_text(); |
@@ -656,9 +656,9 @@ discard block |
||
| 656 | 656 | */ |
| 657 | 657 | public function get_registration_time_limit() { |
| 658 | 658 | |
| 659 | - $registration_time_limit = (float)( EE_Registry::instance() ->SSN->expiration() - time() ); |
|
| 659 | + $registration_time_limit = (float) (EE_Registry::instance() ->SSN->expiration() - time()); |
|
| 660 | 660 | $time_limit_format = $registration_time_limit > 60 * MINUTE_IN_SECONDS ? 'H:i:s' : 'i:s'; |
| 661 | - $registration_time_limit = date( $time_limit_format, $registration_time_limit ); |
|
| 661 | + $registration_time_limit = date($time_limit_format, $registration_time_limit); |
|
| 662 | 662 | return apply_filters( |
| 663 | 663 | 'FHEE__EE_Checkout__get_registration_time_limit__registration_time_limit', |
| 664 | 664 | $registration_time_limit |
@@ -678,7 +678,7 @@ discard block |
||
| 678 | 678 | // overpaid TXN |
| 679 | 679 | // free TXN ( total = 0.00 ) |
| 680 | 680 | // then payment required is TRUE |
| 681 | - return ! ( $this->admin_request || $this->transaction->is_completed() || $this->transaction->is_overpaid() || $this->transaction->is_free() ) ? TRUE : FALSE; |
|
| 681 | + return ! ($this->admin_request || $this->transaction->is_completed() || $this->transaction->is_overpaid() || $this->transaction->is_free()) ? TRUE : FALSE; |
|
| 682 | 682 | } |
| 683 | 683 | |
| 684 | 684 | |
@@ -690,12 +690,12 @@ discard block |
||
| 690 | 690 | * @param EE_Transaction $transaction |
| 691 | 691 | * @return EE_Cart |
| 692 | 692 | */ |
| 693 | - public function get_cart_for_transaction( $transaction ) { |
|
| 694 | - $session = EE_Registry::instance()->load_core( 'Session' ); |
|
| 695 | - $cart = $transaction instanceof EE_Transaction ? EE_Cart::get_cart_from_txn( $transaction, $session ) : null; |
|
| 693 | + public function get_cart_for_transaction($transaction) { |
|
| 694 | + $session = EE_Registry::instance()->load_core('Session'); |
|
| 695 | + $cart = $transaction instanceof EE_Transaction ? EE_Cart::get_cart_from_txn($transaction, $session) : null; |
|
| 696 | 696 | // verify cart |
| 697 | - if ( ! $cart instanceof EE_Cart ) { |
|
| 698 | - $cart = EE_Registry::instance()->load_core( 'Cart' ); |
|
| 697 | + if ( ! $cart instanceof EE_Cart) { |
|
| 698 | + $cart = EE_Registry::instance()->load_core('Cart'); |
|
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | return $cart; |
@@ -711,8 +711,8 @@ discard block |
||
| 711 | 711 | */ |
| 712 | 712 | public function initialize_txn_reg_steps_array() { |
| 713 | 713 | $txn_reg_steps_array = array(); |
| 714 | - foreach ( $this->reg_steps as $reg_step ) { |
|
| 715 | - $txn_reg_steps_array[ $reg_step->slug() ] = FALSE; |
|
| 714 | + foreach ($this->reg_steps as $reg_step) { |
|
| 715 | + $txn_reg_steps_array[$reg_step->slug()] = FALSE; |
|
| 716 | 716 | } |
| 717 | 717 | return $txn_reg_steps_array; |
| 718 | 718 | } |
@@ -728,14 +728,14 @@ discard block |
||
| 728 | 728 | */ |
| 729 | 729 | public function update_txn_reg_steps_array() { |
| 730 | 730 | $updated = false; |
| 731 | - foreach ( $this->reg_steps as $reg_step ) { |
|
| 732 | - if ( $reg_step->completed() ) { |
|
| 733 | - $updated = $this->transaction->set_reg_step_completed( $reg_step->slug() ) |
|
| 731 | + foreach ($this->reg_steps as $reg_step) { |
|
| 732 | + if ($reg_step->completed()) { |
|
| 733 | + $updated = $this->transaction->set_reg_step_completed($reg_step->slug()) |
|
| 734 | 734 | ? true |
| 735 | 735 | : $updated; |
| 736 | 736 | } |
| 737 | 737 | } |
| 738 | - if ( $updated ) { |
|
| 738 | + if ($updated) { |
|
| 739 | 739 | $this->transaction->save(); |
| 740 | 740 | } |
| 741 | 741 | return $updated; |
@@ -751,14 +751,14 @@ discard block |
||
| 751 | 751 | * @throws \EE_Error |
| 752 | 752 | */ |
| 753 | 753 | public function stash_transaction_and_checkout() { |
| 754 | - if ( ! $this->revisit ) { |
|
| 754 | + if ( ! $this->revisit) { |
|
| 755 | 755 | $this->update_txn_reg_steps_array(); |
| 756 | 756 | } |
| 757 | 757 | $this->track_transaction_and_registration_status_updates(); |
| 758 | 758 | // save all data to the db, but suppress errors |
| 759 | 759 | //$this->save_all_data( FALSE ); |
| 760 | 760 | // cache the checkout in the session |
| 761 | - EE_Registry::instance()->SSN->set_checkout( $this ); |
|
| 761 | + EE_Registry::instance()->SSN->set_checkout($this); |
|
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | |
@@ -773,15 +773,15 @@ discard block |
||
| 773 | 773 | */ |
| 774 | 774 | public function track_transaction_and_registration_status_updates() { |
| 775 | 775 | // verify the transaction |
| 776 | - if ( $this->transaction instanceof EE_Transaction ) { |
|
| 776 | + if ($this->transaction instanceof EE_Transaction) { |
|
| 777 | 777 | // has there been a TXN status change during this checkout? |
| 778 | 778 | $this->txn_status_updated = $this->transaction->txn_status_updated(); |
| 779 | 779 | /** @type EE_Registration_Processor $registration_processor */ |
| 780 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
| 780 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 781 | 781 | // grab the saved registrations from the transaction |
| 782 | - foreach ( $this->transaction->registrations( $this->reg_cache_where_params ) as $registration ) { |
|
| 783 | - if ( $registration_processor->reg_status_updated( $registration->ID() ) ) { |
|
| 784 | - $this->set_reg_status_updated( $registration->ID(), true ); |
|
| 782 | + foreach ($this->transaction->registrations($this->reg_cache_where_params) as $registration) { |
|
| 783 | + if ($registration_processor->reg_status_updated($registration->ID())) { |
|
| 784 | + $this->set_reg_status_updated($registration->ID(), true); |
|
| 785 | 785 | } |
| 786 | 786 | } |
| 787 | 787 | } |
@@ -802,7 +802,7 @@ discard block |
||
| 802 | 802 | * @return bool |
| 803 | 803 | * @throws \EE_Error |
| 804 | 804 | */ |
| 805 | - public function visit_allows_processing_of_this_registration( EE_Registration $registration ) { |
|
| 805 | + public function visit_allows_processing_of_this_registration(EE_Registration $registration) { |
|
| 806 | 806 | return ! $this->revisit |
| 807 | 807 | || $this->primary_revisit |
| 808 | 808 | || ( |
@@ -835,18 +835,18 @@ discard block |
||
| 835 | 835 | * @return bool |
| 836 | 836 | * @throws \EE_Error |
| 837 | 837 | */ |
| 838 | - public function save_all_data( $show_errors = TRUE ) { |
|
| 838 | + public function save_all_data($show_errors = TRUE) { |
|
| 839 | 839 | // verify the transaction |
| 840 | - if ( $this->transaction instanceof EE_Transaction ) { |
|
| 840 | + if ($this->transaction instanceof EE_Transaction) { |
|
| 841 | 841 | // save to ensure that TXN has ID |
| 842 | 842 | $this->transaction->save(); |
| 843 | 843 | // grab the saved registrations from the transaction |
| 844 | - foreach ( $this->transaction->registrations( $this->reg_cache_where_params ) as $registration ) { |
|
| 845 | - $this->_save_registration( $registration, $show_errors ); |
|
| 844 | + foreach ($this->transaction->registrations($this->reg_cache_where_params) as $registration) { |
|
| 845 | + $this->_save_registration($registration, $show_errors); |
|
| 846 | 846 | } |
| 847 | 847 | } else { |
| 848 | - if ( $show_errors ) { |
|
| 849 | - EE_Error::add_error( __( 'A valid Transaction was not found when attempting to save your registration information.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
|
| 848 | + if ($show_errors) { |
|
| 849 | + EE_Error::add_error(__('A valid Transaction was not found when attempting to save your registration information.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 850 | 850 | } |
| 851 | 851 | return FALSE; |
| 852 | 852 | } |
@@ -863,32 +863,32 @@ discard block |
||
| 863 | 863 | * @return void |
| 864 | 864 | * @throws \EE_Error |
| 865 | 865 | */ |
| 866 | - private function _save_registration( $registration, $show_errors = TRUE ) { |
|
| 866 | + private function _save_registration($registration, $show_errors = TRUE) { |
|
| 867 | 867 | // verify object |
| 868 | - if ( $registration instanceof EE_Registration ) { |
|
| 868 | + if ($registration instanceof EE_Registration) { |
|
| 869 | 869 | // should this registration be processed during this visit ? |
| 870 | - if ( $this->visit_allows_processing_of_this_registration( $registration ) ) { |
|
| 870 | + if ($this->visit_allows_processing_of_this_registration($registration)) { |
|
| 871 | 871 | //set TXN ID |
| 872 | - if ( ! $registration->transaction_ID() ) { |
|
| 873 | - $registration->set_transaction_id( $this->transaction->ID() ); |
|
| 872 | + if ( ! $registration->transaction_ID()) { |
|
| 873 | + $registration->set_transaction_id($this->transaction->ID()); |
|
| 874 | 874 | } |
| 875 | 875 | // verify and save the attendee |
| 876 | - $this->_save_registration_attendee( $registration, $show_errors ); |
|
| 876 | + $this->_save_registration_attendee($registration, $show_errors); |
|
| 877 | 877 | // save answers to reg form questions |
| 878 | - $this->_save_registration_answers( $registration, $show_errors ); |
|
| 878 | + $this->_save_registration_answers($registration, $show_errors); |
|
| 879 | 879 | // save changes |
| 880 | 880 | $registration->save(); |
| 881 | 881 | // update txn cache |
| 882 | - if ( ! $this->transaction->update_cache_after_object_save( 'Registration', $registration )) { |
|
| 883 | - if ( $show_errors ) { |
|
| 884 | - EE_Error::add_error( __( 'The newly saved Registration object could not be cached on the Transaction.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
|
| 882 | + if ( ! $this->transaction->update_cache_after_object_save('Registration', $registration)) { |
|
| 883 | + if ($show_errors) { |
|
| 884 | + EE_Error::add_error(__('The newly saved Registration object could not be cached on the Transaction.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 885 | 885 | } |
| 886 | 886 | } |
| 887 | 887 | } |
| 888 | 888 | } else { |
| 889 | - if ( $show_errors ) { |
|
| 889 | + if ($show_errors) { |
|
| 890 | 890 | EE_Error::add_error( |
| 891 | - __( 'An invalid Registration object was discovered when attempting to save your registration information.', 'event_espresso' ), |
|
| 891 | + __('An invalid Registration object was discovered when attempting to save your registration information.', 'event_espresso'), |
|
| 892 | 892 | __FILE__, __FUNCTION__, __LINE__ |
| 893 | 893 | ); |
| 894 | 894 | } |
@@ -905,25 +905,25 @@ discard block |
||
| 905 | 905 | * @return void |
| 906 | 906 | * @throws \EE_Error |
| 907 | 907 | */ |
| 908 | - private function _save_registration_attendee( $registration, $show_errors = TRUE ) { |
|
| 909 | - if ( $registration->attendee() instanceof EE_Attendee ) { |
|
| 908 | + private function _save_registration_attendee($registration, $show_errors = TRUE) { |
|
| 909 | + if ($registration->attendee() instanceof EE_Attendee) { |
|
| 910 | 910 | // save so that ATT has ID |
| 911 | 911 | $registration->attendee()->save(); |
| 912 | - if ( ! $registration->update_cache_after_object_save( 'Attendee', $registration->attendee() ) ) { |
|
| 913 | - if ( $show_errors ) { |
|
| 912 | + if ( ! $registration->update_cache_after_object_save('Attendee', $registration->attendee())) { |
|
| 913 | + if ($show_errors) { |
|
| 914 | 914 | EE_Error::add_error( |
| 915 | - __( 'The newly saved Attendee object could not be cached on the registration.', 'event_espresso' ), |
|
| 915 | + __('The newly saved Attendee object could not be cached on the registration.', 'event_espresso'), |
|
| 916 | 916 | __FILE__, __FUNCTION__, __LINE__ |
| 917 | 917 | ); |
| 918 | 918 | } |
| 919 | 919 | } |
| 920 | 920 | } else { |
| 921 | - if ( $show_errors ) { |
|
| 921 | + if ($show_errors) { |
|
| 922 | 922 | EE_Error::add_error( |
| 923 | 923 | sprintf( |
| 924 | 924 | '%1$s||%1$s $attendee = %2$s', |
| 925 | - __( 'Either no Attendee information was found, or an invalid Attendee object was discovered when attempting to save your registration information.', 'event_espresso' ), |
|
| 926 | - var_export( $registration->attendee(), true ) |
|
| 925 | + __('Either no Attendee information was found, or an invalid Attendee object was discovered when attempting to save your registration information.', 'event_espresso'), |
|
| 926 | + var_export($registration->attendee(), true) |
|
| 927 | 927 | ), |
| 928 | 928 | __FILE__, __FUNCTION__, __LINE__ |
| 929 | 929 | ); |
@@ -941,25 +941,25 @@ discard block |
||
| 941 | 941 | * @return void |
| 942 | 942 | * @throws \EE_Error |
| 943 | 943 | */ |
| 944 | - private function _save_registration_answers( $registration, $show_errors = TRUE ) { |
|
| 944 | + private function _save_registration_answers($registration, $show_errors = TRUE) { |
|
| 945 | 945 | // now save the answers |
| 946 | - foreach ( $registration->answers() as $cache_key => $answer ) { |
|
| 946 | + foreach ($registration->answers() as $cache_key => $answer) { |
|
| 947 | 947 | // verify object |
| 948 | - if ( $answer instanceof EE_Answer ) { |
|
| 949 | - $answer->set_registration( $registration->ID() ); |
|
| 948 | + if ($answer instanceof EE_Answer) { |
|
| 949 | + $answer->set_registration($registration->ID()); |
|
| 950 | 950 | $answer->save(); |
| 951 | - if ( ! $registration->update_cache_after_object_save( 'Answer', $answer, $cache_key )) { |
|
| 952 | - if ( $show_errors ) { |
|
| 951 | + if ( ! $registration->update_cache_after_object_save('Answer', $answer, $cache_key)) { |
|
| 952 | + if ($show_errors) { |
|
| 953 | 953 | EE_Error::add_error( |
| 954 | - __( 'The newly saved Answer object could not be cached on the registration.', 'event_espresso' ), |
|
| 954 | + __('The newly saved Answer object could not be cached on the registration.', 'event_espresso'), |
|
| 955 | 955 | __FILE__, __FUNCTION__, __LINE__ |
| 956 | 956 | ); |
| 957 | 957 | } |
| 958 | 958 | } |
| 959 | 959 | } else { |
| 960 | - if ( $show_errors ) { |
|
| 960 | + if ($show_errors) { |
|
| 961 | 961 | EE_Error::add_error( |
| 962 | - __( 'An invalid Answer object was discovered when attempting to save your registration information.', 'event_espresso' ), |
|
| 962 | + __('An invalid Answer object was discovered when attempting to save your registration information.', 'event_espresso'), |
|
| 963 | 963 | __FILE__, __FUNCTION__, __LINE__ |
| 964 | 964 | ); |
| 965 | 965 | } |
@@ -978,7 +978,7 @@ discard block |
||
| 978 | 978 | * @return bool |
| 979 | 979 | * @throws \EE_Error |
| 980 | 980 | */ |
| 981 | - public function refresh_all_entities( $from_db = false ) { |
|
| 981 | + public function refresh_all_entities($from_db = false) { |
|
| 982 | 982 | $from_db = $this->current_step->is_final_step() || $this->action === 'process_gateway_response' |
| 983 | 983 | ? true |
| 984 | 984 | : $from_db; |
@@ -1002,11 +1002,11 @@ discard block |
||
| 1002 | 1002 | */ |
| 1003 | 1003 | protected function refresh_from_db() { |
| 1004 | 1004 | // verify the transaction |
| 1005 | - if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) { |
|
| 1005 | + if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) { |
|
| 1006 | 1006 | // pull fresh TXN data from the db |
| 1007 | - $this->transaction = $this->transaction->get_model()->refresh_entity_map_from_db( $this->transaction->ID() ); |
|
| 1007 | + $this->transaction = $this->transaction->get_model()->refresh_entity_map_from_db($this->transaction->ID()); |
|
| 1008 | 1008 | // update EE_Checkout's cached primary_attendee object |
| 1009 | - $this->primary_attendee_obj = $this->_refresh_primary_attendee_obj_from_db( $this->transaction ); |
|
| 1009 | + $this->primary_attendee_obj = $this->_refresh_primary_attendee_obj_from_db($this->transaction); |
|
| 1010 | 1010 | // update EE_Checkout's cached payment object |
| 1011 | 1011 | $payment = $this->transaction->last_payment(); |
| 1012 | 1012 | $this->payment = $payment instanceof EE_Payment ? $payment : $this->payment; |
@@ -1014,9 +1014,9 @@ discard block |
||
| 1014 | 1014 | $payment_method = $this->payment instanceof EE_Payment ? $this->payment->payment_method() : null; |
| 1015 | 1015 | $this->payment_method = $payment_method instanceof EE_Payment_Method ? $payment_method : $this->payment_method; |
| 1016 | 1016 | //now refresh the cart, based on the TXN |
| 1017 | - $this->cart = $this->get_cart_for_transaction( $this->transaction ); |
|
| 1017 | + $this->cart = $this->get_cart_for_transaction($this->transaction); |
|
| 1018 | 1018 | } else { |
| 1019 | - EE_Error::add_error( __( 'A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
|
| 1019 | + EE_Error::add_error(__('A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1020 | 1020 | return FALSE; |
| 1021 | 1021 | } |
| 1022 | 1022 | return TRUE; |
@@ -1031,21 +1031,21 @@ discard block |
||
| 1031 | 1031 | * @return EE_Attendee | null |
| 1032 | 1032 | * @throws \EE_Error |
| 1033 | 1033 | */ |
| 1034 | - protected function _refresh_primary_attendee_obj_from_db( EE_Transaction $transaction ) { |
|
| 1034 | + protected function _refresh_primary_attendee_obj_from_db(EE_Transaction $transaction) { |
|
| 1035 | 1035 | |
| 1036 | 1036 | $primary_attendee_obj = null; |
| 1037 | 1037 | // grab the saved registrations from the transaction |
| 1038 | - foreach ( $transaction->registrations( $this->reg_cache_where_params, true ) as $registration ) { |
|
| 1038 | + foreach ($transaction->registrations($this->reg_cache_where_params, true) as $registration) { |
|
| 1039 | 1039 | // verify object |
| 1040 | - if ( $registration instanceof EE_Registration ) { |
|
| 1040 | + if ($registration instanceof EE_Registration) { |
|
| 1041 | 1041 | $attendee = $registration->attendee(); |
| 1042 | 1042 | // verify object && maybe cache primary_attendee_obj ? |
| 1043 | - if ( $attendee instanceof EE_Attendee&& $registration->is_primary_registrant() ) { |
|
| 1043 | + if ($attendee instanceof EE_Attendee && $registration->is_primary_registrant()) { |
|
| 1044 | 1044 | $primary_attendee_obj = $attendee; |
| 1045 | 1045 | } |
| 1046 | 1046 | } else { |
| 1047 | 1047 | EE_Error::add_error( |
| 1048 | - __( 'An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso' ), |
|
| 1048 | + __('An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso'), |
|
| 1049 | 1049 | __FILE__, __FUNCTION__, __LINE__ |
| 1050 | 1050 | ); |
| 1051 | 1051 | } |
@@ -1066,43 +1066,43 @@ discard block |
||
| 1066 | 1066 | */ |
| 1067 | 1067 | protected function refresh_entity_map() { |
| 1068 | 1068 | // verify the transaction |
| 1069 | - if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) { |
|
| 1069 | + if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) { |
|
| 1070 | 1070 | // never cache payment info |
| 1071 | - $this->transaction->clear_cache( 'Payment' ); |
|
| 1071 | + $this->transaction->clear_cache('Payment'); |
|
| 1072 | 1072 | // is the Payment Options Reg Step completed ? |
| 1073 | - if ( $this->transaction->reg_step_completed( 'payment_options' ) ) { |
|
| 1073 | + if ($this->transaction->reg_step_completed('payment_options')) { |
|
| 1074 | 1074 | // then check for payments and update TXN accordingly |
| 1075 | 1075 | /** @type EE_Transaction_Payments $transaction_payments */ |
| 1076 | - $transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' ); |
|
| 1077 | - $transaction_payments->calculate_total_payments_and_update_status( $this->transaction ); |
|
| 1076 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1077 | + $transaction_payments->calculate_total_payments_and_update_status($this->transaction); |
|
| 1078 | 1078 | } |
| 1079 | 1079 | // grab the saved registrations from the transaction |
| 1080 | 1080 | foreach ( |
| 1081 | - $this->transaction->registrations( $this->reg_cache_where_params ) as $reg_cache_ID => $registration |
|
| 1081 | + $this->transaction->registrations($this->reg_cache_where_params) as $reg_cache_ID => $registration |
|
| 1082 | 1082 | ) { |
| 1083 | - $this->_refresh_registration( $reg_cache_ID, $registration ); |
|
| 1083 | + $this->_refresh_registration($reg_cache_ID, $registration); |
|
| 1084 | 1084 | } |
| 1085 | 1085 | // make sure our cached TXN is added to the model entity mapper |
| 1086 | - $this->transaction = $this->transaction->get_model()->refresh_entity_map_with( $this->transaction->ID(), $this->transaction ); |
|
| 1086 | + $this->transaction = $this->transaction->get_model()->refresh_entity_map_with($this->transaction->ID(), $this->transaction); |
|
| 1087 | 1087 | |
| 1088 | 1088 | } else { |
| 1089 | - EE_Error::add_error( __( 'A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
|
| 1089 | + EE_Error::add_error(__('A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1090 | 1090 | return FALSE; |
| 1091 | 1091 | } |
| 1092 | 1092 | // verify and update the cart because inaccurate totals are not so much fun |
| 1093 | - if ( $this->cart instanceof EE_Cart ) { |
|
| 1093 | + if ($this->cart instanceof EE_Cart) { |
|
| 1094 | 1094 | $grand_total = $this->cart->get_grand_total(); |
| 1095 | - if ( $grand_total instanceof EE_Line_Item && $grand_total->ID() ) { |
|
| 1095 | + if ($grand_total instanceof EE_Line_Item && $grand_total->ID()) { |
|
| 1096 | 1096 | $grand_total->recalculate_total_including_taxes(); |
| 1097 | 1097 | $grand_total = $grand_total->get_model()->refresh_entity_map_with( |
| 1098 | 1098 | $this->cart->get_grand_total()->ID(), |
| 1099 | 1099 | $this->cart->get_grand_total() |
| 1100 | 1100 | ); |
| 1101 | 1101 | } |
| 1102 | - if ( $grand_total instanceof EE_Line_Item ) { |
|
| 1103 | - $this->cart = EE_Cart::instance( $grand_total ); |
|
| 1102 | + if ($grand_total instanceof EE_Line_Item) { |
|
| 1103 | + $this->cart = EE_Cart::instance($grand_total); |
|
| 1104 | 1104 | } else { |
| 1105 | - EE_Error::add_error( __( 'A valid Cart was not found when attempting to update the model entity mapper.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1105 | + EE_Error::add_error(__('A valid Cart was not found when attempting to update the model entity mapper.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1106 | 1106 | return false; |
| 1107 | 1107 | } |
| 1108 | 1108 | } |
@@ -1119,19 +1119,19 @@ discard block |
||
| 1119 | 1119 | * @return void |
| 1120 | 1120 | * @throws \EE_Error |
| 1121 | 1121 | */ |
| 1122 | - protected function _refresh_registration( $reg_cache_ID, $registration ) { |
|
| 1122 | + protected function _refresh_registration($reg_cache_ID, $registration) { |
|
| 1123 | 1123 | |
| 1124 | 1124 | // verify object |
| 1125 | - if ( $registration instanceof EE_Registration ) { |
|
| 1125 | + if ($registration instanceof EE_Registration) { |
|
| 1126 | 1126 | // update the entity mapper attendee |
| 1127 | - $this->_refresh_registration_attendee( $registration ); |
|
| 1127 | + $this->_refresh_registration_attendee($registration); |
|
| 1128 | 1128 | // update the entity mapper answers for reg form questions |
| 1129 | - $this->_refresh_registration_answers( $registration ); |
|
| 1129 | + $this->_refresh_registration_answers($registration); |
|
| 1130 | 1130 | // make sure the cached registration is added to the model entity mapper |
| 1131 | - $registration->get_model()->refresh_entity_map_with( $reg_cache_ID, $registration ); |
|
| 1131 | + $registration->get_model()->refresh_entity_map_with($reg_cache_ID, $registration); |
|
| 1132 | 1132 | } else { |
| 1133 | 1133 | EE_Error::add_error( |
| 1134 | - __( 'An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso' ), |
|
| 1134 | + __('An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso'), |
|
| 1135 | 1135 | __FILE__, __FUNCTION__, __LINE__ |
| 1136 | 1136 | ); |
| 1137 | 1137 | } |
@@ -1146,15 +1146,15 @@ discard block |
||
| 1146 | 1146 | * @return void |
| 1147 | 1147 | * @throws \EE_Error |
| 1148 | 1148 | */ |
| 1149 | - protected function _refresh_registration_attendee( $registration ) { |
|
| 1149 | + protected function _refresh_registration_attendee($registration) { |
|
| 1150 | 1150 | |
| 1151 | 1151 | $attendee = $registration->attendee(); |
| 1152 | 1152 | // verify object |
| 1153 | - if ( $attendee instanceof EE_Attendee && $attendee->ID() ) { |
|
| 1153 | + if ($attendee instanceof EE_Attendee && $attendee->ID()) { |
|
| 1154 | 1154 | // make sure the cached attendee is added to the model entity mapper |
| 1155 | - $registration->attendee()->get_model()->refresh_entity_map_with( $attendee->ID(), $attendee ); |
|
| 1155 | + $registration->attendee()->get_model()->refresh_entity_map_with($attendee->ID(), $attendee); |
|
| 1156 | 1156 | // maybe cache primary_attendee_obj ? |
| 1157 | - if ( $registration->is_primary_registrant() ) { |
|
| 1157 | + if ($registration->is_primary_registrant()) { |
|
| 1158 | 1158 | $this->primary_attendee_obj = $attendee; |
| 1159 | 1159 | } |
| 1160 | 1160 | } |
@@ -1169,19 +1169,19 @@ discard block |
||
| 1169 | 1169 | * @return void |
| 1170 | 1170 | * @throws \EE_Error |
| 1171 | 1171 | */ |
| 1172 | - protected function _refresh_registration_answers( $registration ) { |
|
| 1172 | + protected function _refresh_registration_answers($registration) { |
|
| 1173 | 1173 | |
| 1174 | 1174 | // now update the answers |
| 1175 | - foreach ( $registration->answers() as $cache_key => $answer ) { |
|
| 1175 | + foreach ($registration->answers() as $cache_key => $answer) { |
|
| 1176 | 1176 | // verify object |
| 1177 | - if ( $answer instanceof EE_Answer ) { |
|
| 1178 | - if ( $answer->ID() ) { |
|
| 1177 | + if ($answer instanceof EE_Answer) { |
|
| 1178 | + if ($answer->ID()) { |
|
| 1179 | 1179 | // make sure the cached answer is added to the model entity mapper |
| 1180 | - $answer->get_model()->refresh_entity_map_with( $answer->ID(), $answer ); |
|
| 1180 | + $answer->get_model()->refresh_entity_map_with($answer->ID(), $answer); |
|
| 1181 | 1181 | } |
| 1182 | 1182 | } else { |
| 1183 | 1183 | EE_Error::add_error( |
| 1184 | - __( 'An invalid Answer object was discovered when attempting to update the model entity mapper.', 'event_espresso' ), |
|
| 1184 | + __('An invalid Answer object was discovered when attempting to update the model entity mapper.', 'event_espresso'), |
|
| 1185 | 1185 | __FILE__, __FUNCTION__, __LINE__ |
| 1186 | 1186 | ); |
| 1187 | 1187 | } |
@@ -1201,13 +1201,13 @@ discard block |
||
| 1201 | 1201 | */ |
| 1202 | 1202 | public function __sleep() |
| 1203 | 1203 | { |
| 1204 | - if ( $this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID() ) { |
|
| 1204 | + if ($this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID()) { |
|
| 1205 | 1205 | $this->primary_attendee_obj = $this->primary_attendee_obj->ID(); |
| 1206 | 1206 | } // remove the reg form and the checkout |
| 1207 | - if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) { |
|
| 1207 | + if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) { |
|
| 1208 | 1208 | $this->transaction = $this->transaction->ID(); |
| 1209 | 1209 | } // remove the reg form and the checkout |
| 1210 | - return array_diff( array_keys( get_object_vars( $this ) ), array( 'billing_form', 'registration_form' ) ); |
|
| 1210 | + return array_diff(array_keys(get_object_vars($this)), array('billing_form', 'registration_form')); |
|
| 1211 | 1211 | } |
| 1212 | 1212 | |
| 1213 | 1213 | |
@@ -1217,15 +1217,15 @@ discard block |
||
| 1217 | 1217 | * this will reinstate the EE_Checkout object on each EE_SPCO_Reg_Step object |
| 1218 | 1218 | */ |
| 1219 | 1219 | public function __wakeup() { |
| 1220 | - if ( ! $this->primary_attendee_obj instanceof EE_Attendee && absint( $this->primary_attendee_obj ) !== 0 ) { |
|
| 1220 | + if ( ! $this->primary_attendee_obj instanceof EE_Attendee && absint($this->primary_attendee_obj) !== 0) { |
|
| 1221 | 1221 | // $this->primary_attendee_obj is actually just an ID, so use it to get the object from the db |
| 1222 | - $this->primary_attendee_obj = EEM_Attendee::instance()->get_one_by_ID( $this->primary_attendee_obj ); |
|
| 1222 | + $this->primary_attendee_obj = EEM_Attendee::instance()->get_one_by_ID($this->primary_attendee_obj); |
|
| 1223 | 1223 | } |
| 1224 | - if ( ! $this->transaction instanceof EE_Transaction && absint( $this->transaction ) !== 0 ) { |
|
| 1224 | + if ( ! $this->transaction instanceof EE_Transaction && absint($this->transaction) !== 0) { |
|
| 1225 | 1225 | // $this->transaction is actually just an ID, so use it to get the object from the db |
| 1226 | - $this->transaction = EEM_Transaction::instance()->get_one_by_ID( $this->transaction ); |
|
| 1226 | + $this->transaction = EEM_Transaction::instance()->get_one_by_ID($this->transaction); |
|
| 1227 | 1227 | } |
| 1228 | - foreach ( $this->reg_steps as $reg_step ) { |
|
| 1228 | + foreach ($this->reg_steps as $reg_step) { |
|
| 1229 | 1229 | $reg_step->checkout = $this; |
| 1230 | 1230 | } |
| 1231 | 1231 | } |
@@ -1242,12 +1242,12 @@ discard block |
||
| 1242 | 1242 | * @param bool $display_request |
| 1243 | 1243 | * @throws \EE_Error |
| 1244 | 1244 | */ |
| 1245 | - public function log( $class = '', $func = '', $line = '', $info = array(), $display_request = false ) { |
|
| 1245 | + public function log($class = '', $func = '', $line = '', $info = array(), $display_request = false) { |
|
| 1246 | 1246 | $disabled = true; |
| 1247 | - if ( WP_DEBUG && ! $disabled ) { |
|
| 1248 | - $debug_data = get_option( 'EE_DEBUG_SPCO_' . EE_Session::instance()->id(), array() ); |
|
| 1247 | + if (WP_DEBUG && ! $disabled) { |
|
| 1248 | + $debug_data = get_option('EE_DEBUG_SPCO_'.EE_Session::instance()->id(), array()); |
|
| 1249 | 1249 | $default_data = array( |
| 1250 | - $class => $func . '() : ' . $line, |
|
| 1250 | + $class => $func.'() : '.$line, |
|
| 1251 | 1251 | 'request->step' => $this->step, |
| 1252 | 1252 | 'request->action' => $this->action, |
| 1253 | 1253 | 'current_step->slug' => $this->current_step instanceof EE_SPCO_Reg_Step ? |
@@ -1259,24 +1259,24 @@ discard block |
||
| 1259 | 1259 | 'reg_url_link' => $this->reg_url_link, |
| 1260 | 1260 | 'REQ' => $display_request ? $_REQUEST : '', |
| 1261 | 1261 | ); |
| 1262 | - if ( $this->transaction instanceof EE_Transaction ) { |
|
| 1263 | - $default_data[ 'TXN_status' ] = $this->transaction->status_ID(); |
|
| 1264 | - $default_data[ 'TXN_reg_steps' ] = $this->transaction->reg_steps(); |
|
| 1265 | - foreach ( $this->transaction->registrations( $this->reg_cache_where_params ) as $REG_ID => $registration ) { |
|
| 1266 | - $default_data[ 'registrations' ][ $REG_ID ] = $registration->status_ID(); |
|
| 1262 | + if ($this->transaction instanceof EE_Transaction) { |
|
| 1263 | + $default_data['TXN_status'] = $this->transaction->status_ID(); |
|
| 1264 | + $default_data['TXN_reg_steps'] = $this->transaction->reg_steps(); |
|
| 1265 | + foreach ($this->transaction->registrations($this->reg_cache_where_params) as $REG_ID => $registration) { |
|
| 1266 | + $default_data['registrations'][$REG_ID] = $registration->status_ID(); |
|
| 1267 | 1267 | } |
| 1268 | - if ( $this->transaction->ID() ) { |
|
| 1269 | - $TXN_ID = 'EE_Transaction: ' . $this->transaction->ID(); |
|
| 1268 | + if ($this->transaction->ID()) { |
|
| 1269 | + $TXN_ID = 'EE_Transaction: '.$this->transaction->ID(); |
|
| 1270 | 1270 | // don't serialize objects |
| 1271 | - $info = $this->_strip_objects( $info ); |
|
| 1272 | - if ( ! isset( $debug_data[ $TXN_ID ] ) ) { |
|
| 1273 | - $debug_data[ $TXN_ID ] = array(); |
|
| 1271 | + $info = $this->_strip_objects($info); |
|
| 1272 | + if ( ! isset($debug_data[$TXN_ID])) { |
|
| 1273 | + $debug_data[$TXN_ID] = array(); |
|
| 1274 | 1274 | } |
| 1275 | - $debug_data[ $TXN_ID ][ microtime() ] = array_merge( |
|
| 1275 | + $debug_data[$TXN_ID][microtime()] = array_merge( |
|
| 1276 | 1276 | $default_data, |
| 1277 | 1277 | $info |
| 1278 | 1278 | ); |
| 1279 | - update_option( 'EE_DEBUG_SPCO_' . EE_Session::instance()->id(), $debug_data ); |
|
| 1279 | + update_option('EE_DEBUG_SPCO_'.EE_Session::instance()->id(), $debug_data); |
|
| 1280 | 1280 | } |
| 1281 | 1281 | } |
| 1282 | 1282 | } |
@@ -1289,23 +1289,23 @@ discard block |
||
| 1289 | 1289 | * @param array $info |
| 1290 | 1290 | * @return array |
| 1291 | 1291 | */ |
| 1292 | - public function _strip_objects( $info = array() ) { |
|
| 1293 | - foreach ( (array)$info as $key => $value ) { |
|
| 1294 | - if ( is_array( $value )) { |
|
| 1295 | - $info[ $key ] = $this->_strip_objects( $value ); |
|
| 1296 | - } else if ( is_object( $value ) ) { |
|
| 1297 | - $object_class = get_class( $value ); |
|
| 1298 | - $info[ $object_class ] = array(); |
|
| 1299 | - $info[ $object_class ][ 'ID' ] = method_exists( $value, 'ID' ) ? $value->ID() : 0; |
|
| 1300 | - if ( method_exists( $value, 'status' ) ) { |
|
| 1301 | - $info[ $object_class ][ 'status' ] = $value->status(); |
|
| 1302 | - } else if ( method_exists( $value, 'status_ID' ) ) { |
|
| 1303 | - $info[ $object_class ][ 'status' ] = $value->status_ID(); |
|
| 1292 | + public function _strip_objects($info = array()) { |
|
| 1293 | + foreach ((array) $info as $key => $value) { |
|
| 1294 | + if (is_array($value)) { |
|
| 1295 | + $info[$key] = $this->_strip_objects($value); |
|
| 1296 | + } else if (is_object($value)) { |
|
| 1297 | + $object_class = get_class($value); |
|
| 1298 | + $info[$object_class] = array(); |
|
| 1299 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : 0; |
|
| 1300 | + if (method_exists($value, 'status')) { |
|
| 1301 | + $info[$object_class]['status'] = $value->status(); |
|
| 1302 | + } else if (method_exists($value, 'status_ID')) { |
|
| 1303 | + $info[$object_class]['status'] = $value->status_ID(); |
|
| 1304 | 1304 | } |
| 1305 | - unset( $info[ $key ] ); |
|
| 1305 | + unset($info[$key]); |
|
| 1306 | 1306 | } |
| 1307 | 1307 | } |
| 1308 | - return (array)$info; |
|
| 1308 | + return (array) $info; |
|
| 1309 | 1309 | } |
| 1310 | 1310 | |
| 1311 | 1311 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');} |
|
| 2 | -do_action( 'AHEE_log', __FILE__, ' FILE LOADED', '' ); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); } |
|
| 2 | +do_action('AHEE_log', __FILE__, ' FILE LOADED', ''); |
|
| 3 | 3 | /** |
| 4 | 4 | * |
| 5 | 5 | * Event Espresso |
@@ -110,58 +110,58 @@ discard block |
||
| 110 | 110 | * format. |
| 111 | 111 | * @throws EE_Error |
| 112 | 112 | */ |
| 113 | - protected function __construct( $fieldValues = array(), $bydb = FALSE, $timezone = '', $date_formats = array() ){ |
|
| 113 | + protected function __construct($fieldValues = array(), $bydb = FALSE, $timezone = '', $date_formats = array()) { |
|
| 114 | 114 | |
| 115 | - $className=get_class($this); |
|
| 115 | + $className = get_class($this); |
|
| 116 | 116 | |
| 117 | - do_action("AHEE__{$className}__construct",$this,$fieldValues); |
|
| 118 | - $model=$this->get_model(); |
|
| 119 | - $model_fields = $model->field_settings( FALSE ); |
|
| 117 | + do_action("AHEE__{$className}__construct", $this, $fieldValues); |
|
| 118 | + $model = $this->get_model(); |
|
| 119 | + $model_fields = $model->field_settings(FALSE); |
|
| 120 | 120 | // ensure $fieldValues is an array |
| 121 | - $fieldValues = is_array( $fieldValues ) ? $fieldValues : array( $fieldValues ); |
|
| 121 | + $fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues); |
|
| 122 | 122 | // EEH_Debug_Tools::printr( $fieldValues, '$fieldValues <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
| 123 | 123 | // verify client code has not passed any invalid field names |
| 124 | - foreach($fieldValues as $field_name=> $field_value){ |
|
| 125 | - if( ! isset( $model_fields[ $field_name] ) ){ |
|
| 126 | - throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", "event_espresso"),$field_name,get_class($this),implode(", ",array_keys($model_fields)))); |
|
| 124 | + foreach ($fieldValues as $field_name=> $field_value) { |
|
| 125 | + if ( ! isset($model_fields[$field_name])) { |
|
| 126 | + throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields)))); |
|
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | // EEH_Debug_Tools::printr( $model_fields, '$model_fields <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
| 130 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string( $timezone ); |
|
| 130 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
| 131 | 131 | |
| 132 | - if ( ! empty( $date_formats ) && is_array( $date_formats ) ) { |
|
| 133 | - list( $this->_dt_frmt, $this->_tm_frmt ) = $date_formats; |
|
| 132 | + if ( ! empty($date_formats) && is_array($date_formats)) { |
|
| 133 | + list($this->_dt_frmt, $this->_tm_frmt) = $date_formats; |
|
| 134 | 134 | } else { |
| 135 | 135 | //set default formats for date and time |
| 136 | - $this->_dt_frmt = (string) get_option( 'date_format', 'Y-m-d' ); |
|
| 137 | - $this->_tm_frmt = (string) get_option( 'time_format', 'g:i a' ); |
|
| 136 | + $this->_dt_frmt = (string) get_option('date_format', 'Y-m-d'); |
|
| 137 | + $this->_tm_frmt = (string) get_option('time_format', 'g:i a'); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | //if db model is instantiating |
| 141 | - if ( $bydb ){ |
|
| 141 | + if ($bydb) { |
|
| 142 | 142 | //client code has indicated these field values are from the database |
| 143 | - foreach( $model_fields as $fieldName => $field ){ |
|
| 144 | - $this->set_from_db( $fieldName, isset( $fieldValues[ $fieldName] ) ? $fieldValues[ $fieldName ] : null ); |
|
| 143 | + foreach ($model_fields as $fieldName => $field) { |
|
| 144 | + $this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null); |
|
| 145 | 145 | } |
| 146 | 146 | } else { |
| 147 | 147 | //we're constructing a brand |
| 148 | 148 | //new instance of the model object. Generally, this means we'll need to do more field validation |
| 149 | - foreach( $model_fields as $fieldName => $field ){ |
|
| 150 | - $this->set( $fieldName, isset( $fieldValues[ $fieldName ] ) ? $fieldValues[ $fieldName ] : null, true ); |
|
| 149 | + foreach ($model_fields as $fieldName => $field) { |
|
| 150 | + $this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true); |
|
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | //remember what values were passed to this constructor |
| 155 | 155 | $this->_props_n_values_provided_in_constructor = $fieldValues; |
| 156 | 156 | //remember in entity mapper |
| 157 | - if( ! $bydb && $model->has_primary_key_field() && $this->ID() ){ |
|
| 157 | + if ( ! $bydb && $model->has_primary_key_field() && $this->ID()) { |
|
| 158 | 158 | $model->add_to_entity_map($this); |
| 159 | 159 | } |
| 160 | 160 | //setup all the relations |
| 161 | - foreach($this->get_model()->relation_settings() as $relation_name=>$relation_obj){ |
|
| 162 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
| 161 | + foreach ($this->get_model()->relation_settings() as $relation_name=>$relation_obj) { |
|
| 162 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 163 | 163 | $this->_model_relations[$relation_name] = NULL; |
| 164 | - }else{ |
|
| 164 | + } else { |
|
| 165 | 165 | $this->_model_relations[$relation_name] = array(); |
| 166 | 166 | } |
| 167 | 167 | } |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | * Action done at the end of each model object construction |
| 170 | 170 | * @param EE_Base_Class $this the model object just created |
| 171 | 171 | */ |
| 172 | - do_action( 'AHEE__EE_Base_Class__construct__finished', $this ); |
|
| 172 | + do_action('AHEE__EE_Base_Class__construct__finished', $this); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | * @param boolean $allow_persist |
| 190 | 190 | * @return boolean |
| 191 | 191 | */ |
| 192 | - public function set_allow_persist( $allow_persist ) { |
|
| 192 | + public function set_allow_persist($allow_persist) { |
|
| 193 | 193 | return $this->_allow_persist = $allow_persist; |
| 194 | 194 | } |
| 195 | 195 | |
@@ -203,11 +203,11 @@ discard block |
||
| 203 | 203 | * @return mixed|null |
| 204 | 204 | * @throws \EE_Error |
| 205 | 205 | */ |
| 206 | - public function get_original( $field_name ){ |
|
| 207 | - if( isset( $this->_props_n_values_provided_in_constructor[ $field_name ] ) && |
|
| 208 | - $field_settings = $this->get_model()->field_settings_for( $field_name )){ |
|
| 209 | - return $field_settings->prepare_for_get( $this->_props_n_values_provided_in_constructor[ $field_name ] ); |
|
| 210 | - }else{ |
|
| 206 | + public function get_original($field_name) { |
|
| 207 | + if (isset($this->_props_n_values_provided_in_constructor[$field_name]) && |
|
| 208 | + $field_settings = $this->get_model()->field_settings_for($field_name)) { |
|
| 209 | + return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]); |
|
| 210 | + } else { |
|
| 211 | 211 | return NULL; |
| 212 | 212 | } |
| 213 | 213 | } |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * @param EE_Base_Class $obj |
| 218 | 218 | * @return string |
| 219 | 219 | */ |
| 220 | - public function get_class($obj){ |
|
| 220 | + public function get_class($obj) { |
|
| 221 | 221 | return get_class($obj); |
| 222 | 222 | } |
| 223 | 223 | |
@@ -232,19 +232,19 @@ discard block |
||
| 232 | 232 | * @param bool $use_default |
| 233 | 233 | * @throws \EE_Error |
| 234 | 234 | */ |
| 235 | - public function set( $field_name, $field_value, $use_default = FALSE ){ |
|
| 236 | - $field_obj = $this->get_model()->field_settings_for( $field_name ); |
|
| 237 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
| 235 | + public function set($field_name, $field_value, $use_default = FALSE) { |
|
| 236 | + $field_obj = $this->get_model()->field_settings_for($field_name); |
|
| 237 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 238 | 238 | // if ( method_exists( $field_obj, 'set_timezone' )) { |
| 239 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
| 240 | - $field_obj->set_timezone( $this->_timezone ); |
|
| 241 | - $field_obj->set_date_format( $this->_dt_frmt ); |
|
| 242 | - $field_obj->set_time_format( $this->_tm_frmt ); |
|
| 239 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 240 | + $field_obj->set_timezone($this->_timezone); |
|
| 241 | + $field_obj->set_date_format($this->_dt_frmt); |
|
| 242 | + $field_obj->set_time_format($this->_tm_frmt); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | $holder_of_value = $field_obj->prepare_for_set($field_value); |
| 246 | 246 | //should the value be null? |
| 247 | - if( ($field_value === NULL || $holder_of_value === NULL || $holder_of_value ==='') && $use_default){ |
|
| 247 | + if (($field_value === NULL || $holder_of_value === NULL || $holder_of_value === '') && $use_default) { |
|
| 248 | 248 | $this->_fields[$field_name] = $field_obj->get_default_value(); |
| 249 | 249 | |
| 250 | 250 | /** |
@@ -256,26 +256,26 @@ discard block |
||
| 256 | 256 | */ |
| 257 | 257 | if ( |
| 258 | 258 | $field_obj instanceof EE_Datetime_Field |
| 259 | - && $this->_fields[ $field_name ] !== null |
|
| 259 | + && $this->_fields[$field_name] !== null |
|
| 260 | 260 | && ! $this->_fields[$field_name] instanceof DateTime |
| 261 | 261 | ) { |
| 262 | - empty( $this->_fields[$field_name] ) |
|
| 263 | - ? $this->set( $field_name, time() ) |
|
| 264 | - : $this->set( $field_name, $this->_fields[$field_name] ); |
|
| 262 | + empty($this->_fields[$field_name]) |
|
| 263 | + ? $this->set($field_name, time()) |
|
| 264 | + : $this->set($field_name, $this->_fields[$field_name]); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - }else{ |
|
| 267 | + } else { |
|
| 268 | 268 | $this->_fields[$field_name] = $holder_of_value; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | //if we're not in the constructor... |
| 272 | 272 | //now check if what we set was a primary key |
| 273 | - if( |
|
| 273 | + if ( |
|
| 274 | 274 | //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
| 275 | 275 | $this->_props_n_values_provided_in_constructor |
| 276 | 276 | && $field_value |
| 277 | - && $field_name === self::_get_primary_key_name( get_class( $this ) ) |
|
| 278 | - ){ |
|
| 277 | + && $field_name === self::_get_primary_key_name(get_class($this)) |
|
| 278 | + ) { |
|
| 279 | 279 | //if so, we want all this object's fields to be filled either with |
| 280 | 280 | //what we've explicitly set on this model |
| 281 | 281 | //or what we have in the db |
@@ -283,20 +283,20 @@ discard block |
||
| 283 | 283 | $fields_on_model = self::_get_model(get_class($this))->field_settings(); |
| 284 | 284 | |
| 285 | 285 | $obj_in_db = self::_get_model(get_class($this))->get_one_by_ID($field_value); |
| 286 | - foreach($fields_on_model as $field_obj){ |
|
| 287 | - if( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
| 288 | - && $field_obj->get_name() !== $field_name ){ |
|
| 286 | + foreach ($fields_on_model as $field_obj) { |
|
| 287 | + if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
| 288 | + && $field_obj->get_name() !== $field_name) { |
|
| 289 | 289 | |
| 290 | - $this->set($field_obj->get_name(),$obj_in_db->get($field_obj->get_name())); |
|
| 290 | + $this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name())); |
|
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | //oh this model object has an ID? well make sure its in the entity mapper |
| 294 | 294 | $this->get_model()->add_to_entity_map($this); |
| 295 | 295 | } |
| 296 | 296 | //let's unset any cache for this field_name from the $_cached_properties property. |
| 297 | - $this->_clear_cached_property( $field_name ); |
|
| 298 | - }else{ |
|
| 299 | - throw new EE_Error( sprintf( __( "A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso" ), $field_name ) ); |
|
| 297 | + $this->_clear_cached_property($field_name); |
|
| 298 | + } else { |
|
| 299 | + throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso"), $field_name)); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | } |
@@ -313,14 +313,14 @@ discard block |
||
| 313 | 313 | * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs. |
| 314 | 314 | * @throws \EE_Error |
| 315 | 315 | */ |
| 316 | - public function set_field_or_extra_meta( $field_name, $field_value ) { |
|
| 317 | - if ( $this->get_model()->has_field( $field_name ) ) { |
|
| 318 | - $this->set( $field_name, $field_value ); |
|
| 316 | + public function set_field_or_extra_meta($field_name, $field_value) { |
|
| 317 | + if ($this->get_model()->has_field($field_name)) { |
|
| 318 | + $this->set($field_name, $field_value); |
|
| 319 | 319 | return true; |
| 320 | 320 | } else { |
| 321 | 321 | //ensure this object is saved first so that extra meta can be properly related. |
| 322 | 322 | $this->save(); |
| 323 | - return $this->update_extra_meta( $field_name, $field_value ); |
|
| 323 | + return $this->update_extra_meta($field_name, $field_value); |
|
| 324 | 324 | } |
| 325 | 325 | } |
| 326 | 326 | |
@@ -341,12 +341,12 @@ discard block |
||
| 341 | 341 | * @return mixed|null value for the field if found. null if not found. |
| 342 | 342 | * @throws \EE_Error |
| 343 | 343 | */ |
| 344 | - public function get_field_or_extra_meta( $field_name ) { |
|
| 345 | - if ( $this->get_model()->has_field( $field_name ) ) { |
|
| 346 | - $column_value = $this->get( $field_name ); |
|
| 344 | + public function get_field_or_extra_meta($field_name) { |
|
| 345 | + if ($this->get_model()->has_field($field_name)) { |
|
| 346 | + $column_value = $this->get($field_name); |
|
| 347 | 347 | } else { |
| 348 | 348 | //This isn't a column in the main table, let's see if it is in the extra meta. |
| 349 | - $column_value = $this->get_extra_meta( $field_name, true, null ); |
|
| 349 | + $column_value = $this->get_extra_meta($field_name, true, null); |
|
| 350 | 350 | } |
| 351 | 351 | return $column_value; |
| 352 | 352 | } |
@@ -362,18 +362,18 @@ discard block |
||
| 362 | 362 | * @return void |
| 363 | 363 | * @throws \EE_Error |
| 364 | 364 | */ |
| 365 | - public function set_timezone( $timezone = '' ) { |
|
| 366 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string( $timezone ); |
|
| 365 | + public function set_timezone($timezone = '') { |
|
| 366 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
| 367 | 367 | //make sure we clear all cached properties because they won't be relevant now |
| 368 | 368 | $this->_clear_cached_properties(); |
| 369 | 369 | |
| 370 | 370 | //make sure we update field settings and the date for all EE_Datetime_Fields |
| 371 | - $model_fields = $this->get_model()->field_settings( false ); |
|
| 372 | - foreach ( $model_fields as $field_name => $field_obj ) { |
|
| 373 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
| 374 | - $field_obj->set_timezone( $this->_timezone ); |
|
| 375 | - if ( isset( $this->_fields[$field_name] ) && $this->_fields[$field_name] instanceof DateTime ) { |
|
| 376 | - $this->_fields[$field_name]->setTimezone( new DateTimeZone( $this->_timezone ) ); |
|
| 371 | + $model_fields = $this->get_model()->field_settings(false); |
|
| 372 | + foreach ($model_fields as $field_name => $field_obj) { |
|
| 373 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 374 | + $field_obj->set_timezone($this->_timezone); |
|
| 375 | + if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) { |
|
| 376 | + $this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone)); |
|
| 377 | 377 | } |
| 378 | 378 | } |
| 379 | 379 | } |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | * |
| 403 | 403 | * @param string $format should be a format recognizable by PHP date() functions. |
| 404 | 404 | */ |
| 405 | - public function set_date_format( $format ) { |
|
| 405 | + public function set_date_format($format) { |
|
| 406 | 406 | $this->_dt_frmt = $format; |
| 407 | 407 | //clear cached_properties because they won't be relevant now. |
| 408 | 408 | $this->_clear_cached_properties(); |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | * @since 4.6 |
| 419 | 419 | * @param string $format should be a format recognizable by PHP date() functions. |
| 420 | 420 | */ |
| 421 | - public function set_time_format( $format ) { |
|
| 421 | + public function set_time_format($format) { |
|
| 422 | 422 | $this->_tm_frmt = $format; |
| 423 | 423 | //clear cached_properties because they won't be relevant now. |
| 424 | 424 | $this->_clear_cached_properties(); |
@@ -435,8 +435,8 @@ discard block |
||
| 435 | 435 | * |
| 436 | 436 | * @return mixed string|array |
| 437 | 437 | */ |
| 438 | - public function get_format( $full = true ) { |
|
| 439 | - return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array( $this->_dt_frmt, $this->_tm_frmt ); |
|
| 438 | + public function get_format($full = true) { |
|
| 439 | + return $full ? $this->_dt_frmt.' '.$this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt); |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | |
@@ -454,17 +454,17 @@ discard block |
||
| 454 | 454 | * @throws EE_Error |
| 455 | 455 | * @return mixed index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one related thing, no array) |
| 456 | 456 | */ |
| 457 | - public function cache( $relationName = '', $object_to_cache = NULL, $cache_id = NULL ){ |
|
| 457 | + public function cache($relationName = '', $object_to_cache = NULL, $cache_id = NULL) { |
|
| 458 | 458 | // its entirely possible that there IS no related object yet in which case there is nothing to cache. |
| 459 | - if ( ! $object_to_cache instanceof EE_Base_Class ) { |
|
| 459 | + if ( ! $object_to_cache instanceof EE_Base_Class) { |
|
| 460 | 460 | return FALSE; |
| 461 | 461 | } |
| 462 | 462 | // also get "how" the object is related, or throw an error |
| 463 | - if( ! $relationship_to_model = $this->get_model()->related_settings_for( $relationName )) { |
|
| 464 | - throw new EE_Error( sprintf( __( 'There is no relationship to %s on a %s. Cannot cache it', 'event_espresso' ), $relationName, get_class( $this ))); |
|
| 463 | + if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) { |
|
| 464 | + throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'), $relationName, get_class($this))); |
|
| 465 | 465 | } |
| 466 | 466 | // how many things are related ? |
| 467 | - if( $relationship_to_model instanceof EE_Belongs_To_Relation ){ |
|
| 467 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 468 | 468 | // 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 |
| 469 | 469 | // so for these model objects just set it to be cached |
| 470 | 470 | $this->_model_relations[$relationName] = $object_to_cache; |
@@ -472,26 +472,26 @@ discard block |
||
| 472 | 472 | } else { |
| 473 | 473 | // 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. |
| 474 | 474 | // eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array |
| 475 | - if( ! is_array( $this->_model_relations[$relationName] )) { |
|
| 475 | + if ( ! is_array($this->_model_relations[$relationName])) { |
|
| 476 | 476 | // if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array |
| 477 | - $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array( $this->_model_relations[$relationName] ) : array(); |
|
| 477 | + $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array($this->_model_relations[$relationName]) : array(); |
|
| 478 | 478 | } |
| 479 | 479 | // first check for a cache_id which is normally empty |
| 480 | - if ( ! empty( $cache_id )) { |
|
| 480 | + if ( ! empty($cache_id)) { |
|
| 481 | 481 | // 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 |
| 482 | - $this->_model_relations[$relationName][ $cache_id ] = $object_to_cache; |
|
| 482 | + $this->_model_relations[$relationName][$cache_id] = $object_to_cache; |
|
| 483 | 483 | $return = $cache_id; |
| 484 | - } elseif ( $object_to_cache->ID() ) { |
|
| 484 | + } elseif ($object_to_cache->ID()) { |
|
| 485 | 485 | // OR the cached object originally came from the db, so let's just use it's PK for an ID |
| 486 | - $this->_model_relations[$relationName][ $object_to_cache->ID() ] = $object_to_cache; |
|
| 486 | + $this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache; |
|
| 487 | 487 | $return = $object_to_cache->ID(); |
| 488 | 488 | } else { |
| 489 | 489 | // OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID |
| 490 | 490 | $this->_model_relations[$relationName][] = $object_to_cache; |
| 491 | 491 | // move the internal pointer to the end of the array |
| 492 | - end( $this->_model_relations[$relationName] ); |
|
| 492 | + end($this->_model_relations[$relationName]); |
|
| 493 | 493 | // and grab the key so that we can return it |
| 494 | - $return = key( $this->_model_relations[$relationName] ); |
|
| 494 | + $return = key($this->_model_relations[$relationName]); |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | } |
@@ -510,11 +510,11 @@ discard block |
||
| 510 | 510 | * @return void |
| 511 | 511 | * @throws \EE_Error |
| 512 | 512 | */ |
| 513 | - protected function _set_cached_property( $fieldname, $value, $cache_type = NULL ) { |
|
| 513 | + protected function _set_cached_property($fieldname, $value, $cache_type = NULL) { |
|
| 514 | 514 | //first make sure this property exists |
| 515 | 515 | $this->get_model()->field_settings_for($fieldname); |
| 516 | 516 | |
| 517 | - $cache_type = empty( $cache_type ) ? 'standard' : $cache_type; |
|
| 517 | + $cache_type = empty($cache_type) ? 'standard' : $cache_type; |
|
| 518 | 518 | $this->_cached_properties[$fieldname][$cache_type] = $value; |
| 519 | 519 | } |
| 520 | 520 | |
@@ -535,36 +535,36 @@ discard block |
||
| 535 | 535 | * @return mixed whatever the value for the property is we're retrieving |
| 536 | 536 | * @throws \EE_Error |
| 537 | 537 | */ |
| 538 | - protected function _get_cached_property( $fieldname, $pretty = FALSE, $extra_cache_ref = NULL ) { |
|
| 538 | + protected function _get_cached_property($fieldname, $pretty = FALSE, $extra_cache_ref = NULL) { |
|
| 539 | 539 | //verify the field exists |
| 540 | 540 | $this->get_model()->field_settings_for($fieldname); |
| 541 | 541 | |
| 542 | 542 | $cache_type = $pretty ? 'pretty' : 'standard'; |
| 543 | - $cache_type .= !empty( $extra_cache_ref ) ? '_' . $extra_cache_ref : ''; |
|
| 543 | + $cache_type .= ! empty($extra_cache_ref) ? '_'.$extra_cache_ref : ''; |
|
| 544 | 544 | |
| 545 | - if ( isset( $this->_cached_properties[$fieldname][$cache_type] ) ) { |
|
| 545 | + if (isset($this->_cached_properties[$fieldname][$cache_type])) { |
|
| 546 | 546 | return $this->_cached_properties[$fieldname][$cache_type]; |
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | $field_obj = $this->get_model()->field_settings_for($fieldname); |
| 550 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
| 550 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 551 | 551 | /** |
| 552 | 552 | * maybe this is EE_Datetime_Field. If so we need to make sure timezone and |
| 553 | 553 | * formats are correct. |
| 554 | 554 | */ |
| 555 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
| 556 | - $field_obj->set_timezone( $this->_timezone ); |
|
| 557 | - $field_obj->set_date_format( $this->_dt_frmt, $pretty ); |
|
| 558 | - $field_obj->set_time_format( $this->_tm_frmt, $pretty ); |
|
| 555 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 556 | + $field_obj->set_timezone($this->_timezone); |
|
| 557 | + $field_obj->set_date_format($this->_dt_frmt, $pretty); |
|
| 558 | + $field_obj->set_time_format($this->_tm_frmt, $pretty); |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | - if( ! isset($this->_fields[$fieldname])){ |
|
| 561 | + if ( ! isset($this->_fields[$fieldname])) { |
|
| 562 | 562 | $this->_fields[$fieldname] = NULL; |
| 563 | 563 | } |
| 564 | 564 | $value = $pretty |
| 565 | 565 | ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) |
| 566 | - : $field_obj->prepare_for_get($this->_fields[$fieldname] ); |
|
| 567 | - $this->_set_cached_property( $fieldname, $value, $cache_type ); |
|
| 566 | + : $field_obj->prepare_for_get($this->_fields[$fieldname]); |
|
| 567 | + $this->_set_cached_property($fieldname, $value, $cache_type); |
|
| 568 | 568 | return $value; |
| 569 | 569 | } |
| 570 | 570 | return null; |
@@ -590,9 +590,9 @@ discard block |
||
| 590 | 590 | * @param string $property_name the property to remove if it exists (from the _cached_properties array) |
| 591 | 591 | * @return void |
| 592 | 592 | */ |
| 593 | - protected function _clear_cached_property( $property_name ) { |
|
| 594 | - if ( isset( $this->_cached_properties[ $property_name ] ) ) { |
|
| 595 | - unset( $this->_cached_properties[ $property_name ] ); |
|
| 593 | + protected function _clear_cached_property($property_name) { |
|
| 594 | + if (isset($this->_cached_properties[$property_name])) { |
|
| 595 | + unset($this->_cached_properties[$property_name]); |
|
| 596 | 596 | } |
| 597 | 597 | } |
| 598 | 598 | |
@@ -606,12 +606,12 @@ discard block |
||
| 606 | 606 | * @return EE_Base_Class |
| 607 | 607 | * @throws \EE_Error |
| 608 | 608 | */ |
| 609 | - protected function ensure_related_thing_is_model_obj($object_or_id,$model_name){ |
|
| 609 | + protected function ensure_related_thing_is_model_obj($object_or_id, $model_name) { |
|
| 610 | 610 | $other_model_instance = self::_get_model_instance_with_name( |
| 611 | - self::_get_model_classname( $model_name ), |
|
| 611 | + self::_get_model_classname($model_name), |
|
| 612 | 612 | $this->_timezone |
| 613 | 613 | ); |
| 614 | - return $other_model_instance->ensure_is_obj( $object_or_id ); |
|
| 614 | + return $other_model_instance->ensure_is_obj($object_or_id); |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | |
@@ -628,32 +628,32 @@ discard block |
||
| 628 | 628 | * @throws EE_Error |
| 629 | 629 | * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a relation from all |
| 630 | 630 | */ |
| 631 | - public function clear_cache($relationName, $object_to_remove_or_index_into_array = NULL, $clear_all = FALSE){ |
|
| 631 | + public function clear_cache($relationName, $object_to_remove_or_index_into_array = NULL, $clear_all = FALSE) { |
|
| 632 | 632 | $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
| 633 | 633 | $index_in_cache = ''; |
| 634 | - if( ! $relationship_to_model){ |
|
| 634 | + if ( ! $relationship_to_model) { |
|
| 635 | 635 | throw new EE_Error( |
| 636 | 636 | sprintf( |
| 637 | - __( "There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso' ), |
|
| 637 | + __("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'), |
|
| 638 | 638 | $relationName, |
| 639 | - get_class( $this ) |
|
| 639 | + get_class($this) |
|
| 640 | 640 | ) |
| 641 | 641 | ); |
| 642 | 642 | } |
| 643 | - if($clear_all){ |
|
| 643 | + if ($clear_all) { |
|
| 644 | 644 | $obj_removed = true; |
| 645 | 645 | $this->_model_relations[$relationName] = null; |
| 646 | - }elseif($relationship_to_model instanceof EE_Belongs_To_Relation){ |
|
| 646 | + }elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 647 | 647 | $obj_removed = $this->_model_relations[$relationName]; |
| 648 | 648 | $this->_model_relations[$relationName] = null; |
| 649 | - }else{ |
|
| 650 | - if($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()){ |
|
| 649 | + } else { |
|
| 650 | + if ($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()) { |
|
| 651 | 651 | $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
| 652 | - if( is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])){ |
|
| 652 | + if (is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])) { |
|
| 653 | 653 | $index_found_at = NULL; |
| 654 | 654 | //find this object in the array even though it has a different key |
| 655 | - foreach($this->_model_relations[$relationName] as $index=>$obj){ |
|
| 656 | - if( |
|
| 655 | + foreach ($this->_model_relations[$relationName] as $index=>$obj) { |
|
| 656 | + if ( |
|
| 657 | 657 | $obj instanceof EE_Base_Class |
| 658 | 658 | && ( |
| 659 | 659 | $obj == $object_to_remove_or_index_into_array |
@@ -664,34 +664,34 @@ discard block |
||
| 664 | 664 | break; |
| 665 | 665 | } |
| 666 | 666 | } |
| 667 | - if($index_found_at){ |
|
| 667 | + if ($index_found_at) { |
|
| 668 | 668 | $index_in_cache = $index_found_at; |
| 669 | - }else{ |
|
| 669 | + } else { |
|
| 670 | 670 | //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
| 671 | 671 | //if it wasn't in it to begin with. So we're done |
| 672 | 672 | return $object_to_remove_or_index_into_array; |
| 673 | 673 | } |
| 674 | 674 | } |
| 675 | - }elseif($object_to_remove_or_index_into_array instanceof EE_Base_Class){ |
|
| 675 | + }elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) { |
|
| 676 | 676 | //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
| 677 | - foreach($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want){ |
|
| 678 | - if($potentially_obj_we_want == $object_to_remove_or_index_into_array){ |
|
| 677 | + foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) { |
|
| 678 | + if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) { |
|
| 679 | 679 | $index_in_cache = $index; |
| 680 | 680 | } |
| 681 | 681 | } |
| 682 | - }else{ |
|
| 682 | + } else { |
|
| 683 | 683 | $index_in_cache = $object_to_remove_or_index_into_array; |
| 684 | 684 | } |
| 685 | 685 | //supposedly we've found it. But it could just be that the client code |
| 686 | 686 | //provided a bad index/object |
| 687 | 687 | if ( |
| 688 | 688 | isset( |
| 689 | - $this->_model_relations[ $relationName ], |
|
| 690 | - $this->_model_relations[ $relationName ][ $index_in_cache ] |
|
| 689 | + $this->_model_relations[$relationName], |
|
| 690 | + $this->_model_relations[$relationName][$index_in_cache] |
|
| 691 | 691 | ) |
| 692 | 692 | ) { |
| 693 | - $obj_removed = $this->_model_relations[ $relationName ][ $index_in_cache ]; |
|
| 694 | - unset( $this->_model_relations[ $relationName ][ $index_in_cache ] ); |
|
| 693 | + $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
|
| 694 | + unset($this->_model_relations[$relationName][$index_in_cache]); |
|
| 695 | 695 | } else { |
| 696 | 696 | //that thing was never cached anyways. |
| 697 | 697 | $obj_removed = null; |
@@ -712,24 +712,24 @@ discard block |
||
| 712 | 712 | * @return boolean TRUE on success, FALSE on fail |
| 713 | 713 | * @throws \EE_Error |
| 714 | 714 | */ |
| 715 | - public function update_cache_after_object_save( $relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') { |
|
| 715 | + public function update_cache_after_object_save($relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') { |
|
| 716 | 716 | // verify that incoming object is of the correct type |
| 717 | - $obj_class = 'EE_' . $relationName; |
|
| 718 | - if ( $newly_saved_object instanceof $obj_class ) { |
|
| 717 | + $obj_class = 'EE_'.$relationName; |
|
| 718 | + if ($newly_saved_object instanceof $obj_class) { |
|
| 719 | 719 | /* @type EE_Base_Class $newly_saved_object*/ |
| 720 | 720 | // now get the type of relation |
| 721 | - $relationship_to_model = $this->get_model()->related_settings_for( $relationName ); |
|
| 721 | + $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
| 722 | 722 | // if this is a 1:1 relationship |
| 723 | - if( $relationship_to_model instanceof EE_Belongs_To_Relation ) { |
|
| 723 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 724 | 724 | // then just replace the cached object with the newly saved object |
| 725 | 725 | $this->_model_relations[$relationName] = $newly_saved_object; |
| 726 | 726 | return TRUE; |
| 727 | 727 | // or if it's some kind of sordid feral polyamorous relationship... |
| 728 | - } elseif ( is_array( $this->_model_relations[$relationName] ) && isset( $this->_model_relations[$relationName][ $current_cache_id ] )) { |
|
| 728 | + } elseif (is_array($this->_model_relations[$relationName]) && isset($this->_model_relations[$relationName][$current_cache_id])) { |
|
| 729 | 729 | // then remove the current cached item |
| 730 | - unset( $this->_model_relations[$relationName][ $current_cache_id ] ); |
|
| 730 | + unset($this->_model_relations[$relationName][$current_cache_id]); |
|
| 731 | 731 | // and cache the newly saved object using it's new ID |
| 732 | - $this->_model_relations[$relationName][ $newly_saved_object->ID() ] = $newly_saved_object; |
|
| 732 | + $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object; |
|
| 733 | 733 | return TRUE; |
| 734 | 734 | } |
| 735 | 735 | } |
@@ -745,11 +745,11 @@ discard block |
||
| 745 | 745 | * @param string $relationName |
| 746 | 746 | * @return EE_Base_Class |
| 747 | 747 | */ |
| 748 | - public function get_one_from_cache($relationName){ |
|
| 749 | - $cached_array_or_object = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : null; |
|
| 750 | - if(is_array($cached_array_or_object)){ |
|
| 748 | + public function get_one_from_cache($relationName) { |
|
| 749 | + $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : null; |
|
| 750 | + if (is_array($cached_array_or_object)) { |
|
| 751 | 751 | return array_shift($cached_array_or_object); |
| 752 | - }else{ |
|
| 752 | + } else { |
|
| 753 | 753 | return $cached_array_or_object; |
| 754 | 754 | } |
| 755 | 755 | } |
@@ -764,23 +764,23 @@ discard block |
||
| 764 | 764 | * @throws \EE_Error |
| 765 | 765 | * @return EE_Base_Class[] NOT necessarily indexed by primary keys |
| 766 | 766 | */ |
| 767 | - public function get_all_from_cache($relationName){ |
|
| 768 | - $objects = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : array(); |
|
| 767 | + public function get_all_from_cache($relationName) { |
|
| 768 | + $objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array(); |
|
| 769 | 769 | // if the result is not an array, but exists, make it an array |
| 770 | - $objects = is_array( $objects ) ? $objects : array( $objects ); |
|
| 770 | + $objects = is_array($objects) ? $objects : array($objects); |
|
| 771 | 771 | //bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143 |
| 772 | 772 | //basically, if this model object was stored in the session, and these cached model objects |
| 773 | 773 | //already have IDs, let's make sure they're in their model's entity mapper |
| 774 | 774 | //otherwise we will have duplicates next time we call |
| 775 | 775 | // EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() ); |
| 776 | - $model = EE_Registry::instance()->load_model( $relationName ); |
|
| 777 | - foreach( $objects as $model_object ){ |
|
| 778 | - if( $model instanceof EEM_Base && $model_object instanceof EE_Base_Class ){ |
|
| 776 | + $model = EE_Registry::instance()->load_model($relationName); |
|
| 777 | + foreach ($objects as $model_object) { |
|
| 778 | + if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) { |
|
| 779 | 779 | //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved |
| 780 | - if( $model_object->ID() ){ |
|
| 781 | - $model->add_to_entity_map( $model_object ); |
|
| 780 | + if ($model_object->ID()) { |
|
| 781 | + $model->add_to_entity_map($model_object); |
|
| 782 | 782 | } |
| 783 | - }else{ |
|
| 783 | + } else { |
|
| 784 | 784 | throw new EE_Error( |
| 785 | 785 | sprintf( |
| 786 | 786 | __( |
@@ -788,7 +788,7 @@ discard block |
||
| 788 | 788 | 'event_espresso' |
| 789 | 789 | ), |
| 790 | 790 | $relationName, |
| 791 | - gettype( $model_object ) |
|
| 791 | + gettype($model_object) |
|
| 792 | 792 | ) |
| 793 | 793 | ); |
| 794 | 794 | } |
@@ -810,15 +810,15 @@ discard block |
||
| 810 | 810 | * @return array|EE_Base_Class[] |
| 811 | 811 | * @throws \EE_Error |
| 812 | 812 | */ |
| 813 | - public function next_x( $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
| 814 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() |
|
| 813 | + public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
| 814 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 815 | 815 | ? $this->get_model()->get_primary_key_field()->get_name() |
| 816 | 816 | : $field_to_order_by; |
| 817 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
| 818 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
| 817 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 818 | + if (empty($field) || empty($current_value)) { |
|
| 819 | 819 | return array(); |
| 820 | 820 | } |
| 821 | - return $this->get_model()->next_x( $current_value, $field, $limit, $query_params, $columns_to_select ); |
|
| 821 | + return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | |
@@ -835,15 +835,15 @@ discard block |
||
| 835 | 835 | * @return array|EE_Base_Class[] |
| 836 | 836 | * @throws \EE_Error |
| 837 | 837 | */ |
| 838 | - public function previous_x( $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
| 839 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() |
|
| 838 | + public function previous_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
| 839 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 840 | 840 | ? $this->get_model()->get_primary_key_field()->get_name() |
| 841 | 841 | : $field_to_order_by; |
| 842 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
| 843 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
| 842 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 843 | + if (empty($field) || empty($current_value)) { |
|
| 844 | 844 | return array(); |
| 845 | 845 | } |
| 846 | - return $this->get_model()->previous_x( $current_value, $field, $limit, $query_params, $columns_to_select ); |
|
| 846 | + return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
| 847 | 847 | } |
| 848 | 848 | |
| 849 | 849 | |
@@ -859,15 +859,15 @@ discard block |
||
| 859 | 859 | * @return array|EE_Base_Class |
| 860 | 860 | * @throws \EE_Error |
| 861 | 861 | */ |
| 862 | - public function next( $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
| 863 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() |
|
| 862 | + public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
| 863 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 864 | 864 | ? $this->get_model()->get_primary_key_field()->get_name() |
| 865 | 865 | : $field_to_order_by; |
| 866 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
| 867 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
| 866 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 867 | + if (empty($field) || empty($current_value)) { |
|
| 868 | 868 | return array(); |
| 869 | 869 | } |
| 870 | - return $this->get_model()->next( $current_value, $field, $query_params, $columns_to_select ); |
|
| 870 | + return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select); |
|
| 871 | 871 | } |
| 872 | 872 | |
| 873 | 873 | |
@@ -883,15 +883,15 @@ discard block |
||
| 883 | 883 | * @return array|EE_Base_Class |
| 884 | 884 | * @throws \EE_Error |
| 885 | 885 | */ |
| 886 | - public function previous( $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
| 887 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() |
|
| 886 | + public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
| 887 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 888 | 888 | ? $this->get_model()->get_primary_key_field()->get_name() |
| 889 | 889 | : $field_to_order_by; |
| 890 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
| 891 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
| 890 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 891 | + if (empty($field) || empty($current_value)) { |
|
| 892 | 892 | return array(); |
| 893 | 893 | } |
| 894 | - return $this->get_model()->previous( $current_value, $field, $query_params, $columns_to_select ); |
|
| 894 | + return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select); |
|
| 895 | 895 | } |
| 896 | 896 | |
| 897 | 897 | |
@@ -904,25 +904,25 @@ discard block |
||
| 904 | 904 | * @param mixed $field_value_from_db |
| 905 | 905 | * @throws \EE_Error |
| 906 | 906 | */ |
| 907 | - public function set_from_db($field_name,$field_value_from_db){ |
|
| 907 | + public function set_from_db($field_name, $field_value_from_db) { |
|
| 908 | 908 | $field_obj = $this->get_model()->field_settings_for($field_name); |
| 909 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
| 909 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 910 | 910 | //you would think the DB has no NULLs for non-null label fields right? wrong! |
| 911 | 911 | //eg, a CPT model object could have an entry in the posts table, but no |
| 912 | 912 | //entry in the meta table. Meaning that all its columns in the meta table |
| 913 | 913 | //are null! yikes! so when we find one like that, use defaults for its meta columns |
| 914 | - if($field_value_from_db === NULL ){ |
|
| 915 | - if( $field_obj->is_nullable()){ |
|
| 914 | + if ($field_value_from_db === NULL) { |
|
| 915 | + if ($field_obj->is_nullable()) { |
|
| 916 | 916 | //if the field allows nulls, then let it be null |
| 917 | 917 | $field_value = NULL; |
| 918 | - }else{ |
|
| 918 | + } else { |
|
| 919 | 919 | $field_value = $field_obj->get_default_value(); |
| 920 | 920 | } |
| 921 | - }else{ |
|
| 922 | - $field_value = $field_obj->prepare_for_set_from_db( $field_value_from_db ); |
|
| 921 | + } else { |
|
| 922 | + $field_value = $field_obj->prepare_for_set_from_db($field_value_from_db); |
|
| 923 | 923 | } |
| 924 | 924 | $this->_fields[$field_name] = $field_value; |
| 925 | - $this->_clear_cached_property( $field_name ); |
|
| 925 | + $this->_clear_cached_property($field_name); |
|
| 926 | 926 | } |
| 927 | 927 | } |
| 928 | 928 | |
@@ -938,8 +938,8 @@ discard block |
||
| 938 | 938 | * @return mixed |
| 939 | 939 | * @throws \EE_Error |
| 940 | 940 | */ |
| 941 | - public function get($field_name, $extra_cache_ref = NULL ){ |
|
| 942 | - return $this->_get_cached_property( $field_name, FALSE, $extra_cache_ref ); |
|
| 941 | + public function get($field_name, $extra_cache_ref = NULL) { |
|
| 942 | + return $this->_get_cached_property($field_name, FALSE, $extra_cache_ref); |
|
| 943 | 943 | } |
| 944 | 944 | |
| 945 | 945 | |
@@ -972,10 +972,10 @@ discard block |
||
| 972 | 972 | * just null is returned (because that indicates that likely |
| 973 | 973 | * this field is nullable). |
| 974 | 974 | */ |
| 975 | - public function get_DateTime_object( $field_name ) { |
|
| 976 | - $field_settings = $this->get_model()->field_settings_for( $field_name ); |
|
| 975 | + public function get_DateTime_object($field_name) { |
|
| 976 | + $field_settings = $this->get_model()->field_settings_for($field_name); |
|
| 977 | 977 | |
| 978 | - if ( ! $field_settings instanceof EE_Datetime_Field ) { |
|
| 978 | + if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
| 979 | 979 | EE_Error::add_error( |
| 980 | 980 | sprintf( |
| 981 | 981 | __( |
@@ -1007,7 +1007,7 @@ discard block |
||
| 1007 | 1007 | * @return void |
| 1008 | 1008 | * @throws \EE_Error |
| 1009 | 1009 | */ |
| 1010 | - public function e($field_name, $extra_cache_ref = NULL){ |
|
| 1010 | + public function e($field_name, $extra_cache_ref = NULL) { |
|
| 1011 | 1011 | echo $this->get_pretty($field_name, $extra_cache_ref); |
| 1012 | 1012 | } |
| 1013 | 1013 | |
@@ -1021,8 +1021,8 @@ discard block |
||
| 1021 | 1021 | * @return void |
| 1022 | 1022 | * @throws \EE_Error |
| 1023 | 1023 | */ |
| 1024 | - public function f($field_name){ |
|
| 1025 | - $this->e($field_name,'form_input'); |
|
| 1024 | + public function f($field_name) { |
|
| 1025 | + $this->e($field_name, 'form_input'); |
|
| 1026 | 1026 | } |
| 1027 | 1027 | |
| 1028 | 1028 | |
@@ -1035,8 +1035,8 @@ discard block |
||
| 1035 | 1035 | * @return mixed |
| 1036 | 1036 | * @throws \EE_Error |
| 1037 | 1037 | */ |
| 1038 | - public function get_pretty($field_name, $extra_cache_ref = NULL){ |
|
| 1039 | - return $this->_get_cached_property( $field_name, TRUE, $extra_cache_ref ); |
|
| 1038 | + public function get_pretty($field_name, $extra_cache_ref = NULL) { |
|
| 1039 | + return $this->_get_cached_property($field_name, TRUE, $extra_cache_ref); |
|
| 1040 | 1040 | } |
| 1041 | 1041 | |
| 1042 | 1042 | |
@@ -1058,36 +1058,36 @@ discard block |
||
| 1058 | 1058 | * if field is not a valid dtt field, or void if echoing |
| 1059 | 1059 | * @throws \EE_Error |
| 1060 | 1060 | */ |
| 1061 | - protected function _get_datetime( $field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false ) { |
|
| 1061 | + protected function _get_datetime($field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false) { |
|
| 1062 | 1062 | |
| 1063 | - $in_dt_frmt = empty($dt_frmt) ? $this->_dt_frmt : $dt_frmt; |
|
| 1063 | + $in_dt_frmt = empty($dt_frmt) ? $this->_dt_frmt : $dt_frmt; |
|
| 1064 | 1064 | $in_tm_frmt = empty($tm_frmt) ? $this->_tm_frmt : $tm_frmt; |
| 1065 | 1065 | |
| 1066 | 1066 | //validate field for datetime and returns field settings if valid. |
| 1067 | - $field = $this->_get_dtt_field_settings( $field_name ); |
|
| 1067 | + $field = $this->_get_dtt_field_settings($field_name); |
|
| 1068 | 1068 | |
| 1069 | 1069 | //clear cached property if either formats are not null. |
| 1070 | - if( $dt_frmt !== null || $tm_frmt !== null ) { |
|
| 1071 | - $this->_clear_cached_property( $field_name ); |
|
| 1070 | + if ($dt_frmt !== null || $tm_frmt !== null) { |
|
| 1071 | + $this->_clear_cached_property($field_name); |
|
| 1072 | 1072 | //reset format properties because they are used in get() |
| 1073 | 1073 | $this->_dt_frmt = $in_dt_frmt; |
| 1074 | 1074 | $this->_tm_frmt = $in_tm_frmt; |
| 1075 | 1075 | } |
| 1076 | - if ( $echo ) { |
|
| 1077 | - $field->set_pretty_date_format( $in_dt_frmt ); |
|
| 1076 | + if ($echo) { |
|
| 1077 | + $field->set_pretty_date_format($in_dt_frmt); |
|
| 1078 | 1078 | } else { |
| 1079 | - $field->set_date_format( $in_dt_frmt ); |
|
| 1079 | + $field->set_date_format($in_dt_frmt); |
|
| 1080 | 1080 | } |
| 1081 | - if ( $echo ) { |
|
| 1082 | - $field->set_pretty_time_format( $in_tm_frmt ); |
|
| 1081 | + if ($echo) { |
|
| 1082 | + $field->set_pretty_time_format($in_tm_frmt); |
|
| 1083 | 1083 | } else { |
| 1084 | - $field->set_time_format( $in_tm_frmt ); |
|
| 1084 | + $field->set_time_format($in_tm_frmt); |
|
| 1085 | 1085 | } |
| 1086 | 1086 | //set timezone in field object |
| 1087 | - $field->set_timezone( $this->_timezone ); |
|
| 1087 | + $field->set_timezone($this->_timezone); |
|
| 1088 | 1088 | |
| 1089 | 1089 | //set the output returned |
| 1090 | - switch ( $date_or_time ) { |
|
| 1090 | + switch ($date_or_time) { |
|
| 1091 | 1091 | |
| 1092 | 1092 | case 'D' : |
| 1093 | 1093 | $field->set_date_time_output('date'); |
@@ -1102,11 +1102,11 @@ discard block |
||
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | 1104 | |
| 1105 | - if ( $echo ) { |
|
| 1106 | - $this->e( $field_name, $date_or_time ); |
|
| 1105 | + if ($echo) { |
|
| 1106 | + $this->e($field_name, $date_or_time); |
|
| 1107 | 1107 | return ''; |
| 1108 | 1108 | } |
| 1109 | - return $this->get( $field_name, $date_or_time ); |
|
| 1109 | + return $this->get($field_name, $date_or_time); |
|
| 1110 | 1110 | } |
| 1111 | 1111 | |
| 1112 | 1112 | |
@@ -1119,8 +1119,8 @@ discard block |
||
| 1119 | 1119 | * @return string datetime value formatted |
| 1120 | 1120 | * @throws \EE_Error |
| 1121 | 1121 | */ |
| 1122 | - public function get_date( $field_name, $format = NULL ) { |
|
| 1123 | - return $this->_get_datetime( $field_name, $format, NULL, 'D' ); |
|
| 1122 | + public function get_date($field_name, $format = NULL) { |
|
| 1123 | + return $this->_get_datetime($field_name, $format, NULL, 'D'); |
|
| 1124 | 1124 | } |
| 1125 | 1125 | |
| 1126 | 1126 | |
@@ -1130,8 +1130,8 @@ discard block |
||
| 1130 | 1130 | * @param null $format |
| 1131 | 1131 | * @throws \EE_Error |
| 1132 | 1132 | */ |
| 1133 | - public function e_date( $field_name, $format = NULL ) { |
|
| 1134 | - $this->_get_datetime( $field_name, $format, NULL, 'D', TRUE ); |
|
| 1133 | + public function e_date($field_name, $format = NULL) { |
|
| 1134 | + $this->_get_datetime($field_name, $format, NULL, 'D', TRUE); |
|
| 1135 | 1135 | } |
| 1136 | 1136 | |
| 1137 | 1137 | |
@@ -1144,8 +1144,8 @@ discard block |
||
| 1144 | 1144 | * @return string datetime value formatted |
| 1145 | 1145 | * @throws \EE_Error |
| 1146 | 1146 | */ |
| 1147 | - public function get_time( $field_name, $format = NULL ) { |
|
| 1148 | - return $this->_get_datetime( $field_name, NULL, $format, 'T' ); |
|
| 1147 | + public function get_time($field_name, $format = NULL) { |
|
| 1148 | + return $this->_get_datetime($field_name, NULL, $format, 'T'); |
|
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | 1151 | |
@@ -1155,8 +1155,8 @@ discard block |
||
| 1155 | 1155 | * @param null $format |
| 1156 | 1156 | * @throws \EE_Error |
| 1157 | 1157 | */ |
| 1158 | - public function e_time( $field_name, $format = NULL ) { |
|
| 1159 | - $this->_get_datetime( $field_name, NULL, $format, 'T', TRUE ); |
|
| 1158 | + public function e_time($field_name, $format = NULL) { |
|
| 1159 | + $this->_get_datetime($field_name, NULL, $format, 'T', TRUE); |
|
| 1160 | 1160 | } |
| 1161 | 1161 | |
| 1162 | 1162 | |
@@ -1170,8 +1170,8 @@ discard block |
||
| 1170 | 1170 | * @return string datetime value formatted |
| 1171 | 1171 | * @throws \EE_Error |
| 1172 | 1172 | */ |
| 1173 | - public function get_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL ) { |
|
| 1174 | - return $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt ); |
|
| 1173 | + public function get_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL) { |
|
| 1174 | + return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt); |
|
| 1175 | 1175 | } |
| 1176 | 1176 | |
| 1177 | 1177 | |
@@ -1182,8 +1182,8 @@ discard block |
||
| 1182 | 1182 | * @param null $tm_frmt |
| 1183 | 1183 | * @throws \EE_Error |
| 1184 | 1184 | */ |
| 1185 | - public function e_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL ) { |
|
| 1186 | - $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt, NULL, TRUE); |
|
| 1185 | + public function e_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL) { |
|
| 1186 | + $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, NULL, TRUE); |
|
| 1187 | 1187 | } |
| 1188 | 1188 | |
| 1189 | 1189 | |
@@ -1197,11 +1197,11 @@ discard block |
||
| 1197 | 1197 | * @throws \EE_Error |
| 1198 | 1198 | * field name. |
| 1199 | 1199 | */ |
| 1200 | - public function get_i18n_datetime( $field_name, $format = NULL ) { |
|
| 1201 | - $format = empty( $format ) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format; |
|
| 1200 | + public function get_i18n_datetime($field_name, $format = NULL) { |
|
| 1201 | + $format = empty($format) ? $this->_dt_frmt.' '.$this->_tm_frmt : $format; |
|
| 1202 | 1202 | return date_i18n( |
| 1203 | 1203 | $format, |
| 1204 | - EEH_DTT_Helper::get_timestamp_with_offset( $this->get_raw( $field_name ), $this->_timezone ) |
|
| 1204 | + EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone) |
|
| 1205 | 1205 | ); |
| 1206 | 1206 | } |
| 1207 | 1207 | |
@@ -1214,14 +1214,14 @@ discard block |
||
| 1214 | 1214 | * @throws EE_Error |
| 1215 | 1215 | * @return EE_Datetime_Field |
| 1216 | 1216 | */ |
| 1217 | - protected function _get_dtt_field_settings( $field_name ) { |
|
| 1217 | + protected function _get_dtt_field_settings($field_name) { |
|
| 1218 | 1218 | $field = $this->get_model()->field_settings_for($field_name); |
| 1219 | 1219 | |
| 1220 | 1220 | //check if field is dtt |
| 1221 | - if ( $field instanceof EE_Datetime_Field ) { |
|
| 1221 | + if ($field instanceof EE_Datetime_Field) { |
|
| 1222 | 1222 | return $field; |
| 1223 | 1223 | } else { |
| 1224 | - 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', 'event_espresso'), $field_name, self::_get_model_classname( get_class($this) ) ) ); |
|
| 1224 | + 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', 'event_espresso'), $field_name, self::_get_model_classname(get_class($this)))); |
|
| 1225 | 1225 | } |
| 1226 | 1226 | } |
| 1227 | 1227 | |
@@ -1242,8 +1242,8 @@ discard block |
||
| 1242 | 1242 | * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
| 1243 | 1243 | * @throws \EE_Error |
| 1244 | 1244 | */ |
| 1245 | - protected function _set_time_for( $time, $fieldname ) { |
|
| 1246 | - $this->_set_date_time( 'T', $time, $fieldname ); |
|
| 1245 | + protected function _set_time_for($time, $fieldname) { |
|
| 1246 | + $this->_set_date_time('T', $time, $fieldname); |
|
| 1247 | 1247 | } |
| 1248 | 1248 | |
| 1249 | 1249 | |
@@ -1256,8 +1256,8 @@ discard block |
||
| 1256 | 1256 | * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
| 1257 | 1257 | * @throws \EE_Error |
| 1258 | 1258 | */ |
| 1259 | - protected function _set_date_for( $date, $fieldname ) { |
|
| 1260 | - $this->_set_date_time( 'D', $date, $fieldname ); |
|
| 1259 | + protected function _set_date_for($date, $fieldname) { |
|
| 1260 | + $this->_set_date_time('D', $date, $fieldname); |
|
| 1261 | 1261 | } |
| 1262 | 1262 | |
| 1263 | 1263 | |
@@ -1271,26 +1271,26 @@ discard block |
||
| 1271 | 1271 | * @param string $fieldname the name of the field the date OR time is being set on (must match a EE_Datetime_Field property) |
| 1272 | 1272 | * @throws \EE_Error |
| 1273 | 1273 | */ |
| 1274 | - protected function _set_date_time( $what = 'T', $datetime_value, $fieldname ) { |
|
| 1275 | - $field = $this->_get_dtt_field_settings( $fieldname ); |
|
| 1276 | - $field->set_timezone( $this->_timezone ); |
|
| 1277 | - $field->set_date_format( $this->_dt_frmt ); |
|
| 1278 | - $field->set_time_format( $this->_tm_frmt ); |
|
| 1279 | - switch ( $what ) { |
|
| 1274 | + protected function _set_date_time($what = 'T', $datetime_value, $fieldname) { |
|
| 1275 | + $field = $this->_get_dtt_field_settings($fieldname); |
|
| 1276 | + $field->set_timezone($this->_timezone); |
|
| 1277 | + $field->set_date_format($this->_dt_frmt); |
|
| 1278 | + $field->set_time_format($this->_tm_frmt); |
|
| 1279 | + switch ($what) { |
|
| 1280 | 1280 | case 'T' : |
| 1281 | - $this->_fields[ $fieldname ] = $field->prepare_for_set_with_new_time( |
|
| 1281 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time( |
|
| 1282 | 1282 | $datetime_value, |
| 1283 | - $this->_fields[ $fieldname ] |
|
| 1283 | + $this->_fields[$fieldname] |
|
| 1284 | 1284 | ); |
| 1285 | 1285 | break; |
| 1286 | 1286 | case 'D' : |
| 1287 | - $this->_fields[ $fieldname ] = $field->prepare_for_set_with_new_date( |
|
| 1287 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date( |
|
| 1288 | 1288 | $datetime_value, |
| 1289 | - $this->_fields[ $fieldname ] |
|
| 1289 | + $this->_fields[$fieldname] |
|
| 1290 | 1290 | ); |
| 1291 | 1291 | break; |
| 1292 | 1292 | case 'B' : |
| 1293 | - $this->_fields[ $fieldname ] = $field->prepare_for_set( $datetime_value ); |
|
| 1293 | + $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value); |
|
| 1294 | 1294 | break; |
| 1295 | 1295 | } |
| 1296 | 1296 | $this->_clear_cached_property($fieldname); |
@@ -1312,17 +1312,17 @@ discard block |
||
| 1312 | 1312 | * @throws EE_Error |
| 1313 | 1313 | * @return string timestamp |
| 1314 | 1314 | */ |
| 1315 | - public function display_in_my_timezone( $field_name, $callback = 'get_datetime', $args = NULL, $prepend = '', $append = '' ) { |
|
| 1315 | + public function display_in_my_timezone($field_name, $callback = 'get_datetime', $args = NULL, $prepend = '', $append = '') { |
|
| 1316 | 1316 | $timezone = EEH_DTT_Helper::get_timezone(); |
| 1317 | - if ( $timezone === $this->_timezone ) { |
|
| 1317 | + if ($timezone === $this->_timezone) { |
|
| 1318 | 1318 | return ''; |
| 1319 | 1319 | } |
| 1320 | 1320 | $original_timezone = $this->_timezone; |
| 1321 | - $this->set_timezone( $timezone ); |
|
| 1321 | + $this->set_timezone($timezone); |
|
| 1322 | 1322 | |
| 1323 | 1323 | $fn = (array) $field_name; |
| 1324 | - $args = array_merge( $fn, (array) $args ); |
|
| 1325 | - if ( ! method_exists( $this, $callback ) ) { |
|
| 1324 | + $args = array_merge($fn, (array) $args); |
|
| 1325 | + if ( ! method_exists($this, $callback)) { |
|
| 1326 | 1326 | throw new EE_Error( |
| 1327 | 1327 | sprintf( |
| 1328 | 1328 | __( |
@@ -1334,9 +1334,9 @@ discard block |
||
| 1334 | 1334 | ); |
| 1335 | 1335 | } |
| 1336 | 1336 | $args = (array) $args; |
| 1337 | - $return = $prepend . call_user_func_array( array( $this, $callback ), $args ) . $append; |
|
| 1337 | + $return = $prepend.call_user_func_array(array($this, $callback), $args).$append; |
|
| 1338 | 1338 | |
| 1339 | - $this->set_timezone( $original_timezone ); |
|
| 1339 | + $this->set_timezone($original_timezone); |
|
| 1340 | 1340 | return $return; |
| 1341 | 1341 | } |
| 1342 | 1342 | |
@@ -1350,7 +1350,7 @@ discard block |
||
| 1350 | 1350 | * @return boolean | int |
| 1351 | 1351 | * @throws \EE_Error |
| 1352 | 1352 | */ |
| 1353 | - public function delete(){ |
|
| 1353 | + public function delete() { |
|
| 1354 | 1354 | /** |
| 1355 | 1355 | * Called just before the `EE_Base_Class::_delete` method call. |
| 1356 | 1356 | * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions |
@@ -1359,7 +1359,7 @@ discard block |
||
| 1359 | 1359 | * |
| 1360 | 1360 | * @param EE_Base_Class $model_object about to be 'deleted' |
| 1361 | 1361 | */ |
| 1362 | - do_action( 'AHEE__EE_Base_Class__delete__before', $this ); |
|
| 1362 | + do_action('AHEE__EE_Base_Class__delete__before', $this); |
|
| 1363 | 1363 | $result = $this->_delete(); |
| 1364 | 1364 | /** |
| 1365 | 1365 | * Called just after the `EE_Base_Class::_delete` method call. |
@@ -1369,7 +1369,7 @@ discard block |
||
| 1369 | 1369 | * @param EE_Base_Class $model_object that was just 'deleted' |
| 1370 | 1370 | * @param boolean $result |
| 1371 | 1371 | */ |
| 1372 | - do_action( 'AHEE__EE_Base_Class__delete__end', $this, $result ); |
|
| 1372 | + do_action('AHEE__EE_Base_Class__delete__end', $this, $result); |
|
| 1373 | 1373 | return $result; |
| 1374 | 1374 | } |
| 1375 | 1375 | |
@@ -1395,22 +1395,22 @@ discard block |
||
| 1395 | 1395 | * @return bool | int |
| 1396 | 1396 | * @throws \EE_Error |
| 1397 | 1397 | */ |
| 1398 | - public function delete_permanently(){ |
|
| 1398 | + public function delete_permanently() { |
|
| 1399 | 1399 | /** |
| 1400 | 1400 | * Called just before HARD deleting a model object |
| 1401 | 1401 | * |
| 1402 | 1402 | * @param EE_Base_Class $model_object about to be 'deleted' |
| 1403 | 1403 | */ |
| 1404 | - do_action( 'AHEE__EE_Base_Class__delete_permanently__before', $this ); |
|
| 1405 | - $model=$this->get_model(); |
|
| 1406 | - $result=$model->delete_permanently_by_ID($this->ID()); |
|
| 1404 | + do_action('AHEE__EE_Base_Class__delete_permanently__before', $this); |
|
| 1405 | + $model = $this->get_model(); |
|
| 1406 | + $result = $model->delete_permanently_by_ID($this->ID()); |
|
| 1407 | 1407 | $this->refresh_cache_of_related_objects(); |
| 1408 | 1408 | /** |
| 1409 | 1409 | * Called just after HARD deleting a model object |
| 1410 | 1410 | * @param EE_Base_Class $model_object that was just 'deleted' |
| 1411 | 1411 | * @param boolean $result |
| 1412 | 1412 | */ |
| 1413 | - do_action( 'AHEE__EE_Base_Class__delete_permanently__end', $this, $result ); |
|
| 1413 | + do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result); |
|
| 1414 | 1414 | return $result; |
| 1415 | 1415 | } |
| 1416 | 1416 | |
@@ -1423,18 +1423,18 @@ discard block |
||
| 1423 | 1423 | * @throws \EE_Error |
| 1424 | 1424 | */ |
| 1425 | 1425 | public function refresh_cache_of_related_objects() { |
| 1426 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
| 1427 | - if( ! empty( $this->_model_relations[ $relation_name ] ) ) { |
|
| 1428 | - $related_objects = $this->_model_relations[ $relation_name ]; |
|
| 1429 | - if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
| 1426 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 1427 | + if ( ! empty($this->_model_relations[$relation_name])) { |
|
| 1428 | + $related_objects = $this->_model_relations[$relation_name]; |
|
| 1429 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 1430 | 1430 | //this relation only stores a single model object, not an array |
| 1431 | 1431 | //but let's make it consistent |
| 1432 | - $related_objects = array( $related_objects ); |
|
| 1432 | + $related_objects = array($related_objects); |
|
| 1433 | 1433 | } |
| 1434 | - foreach( $related_objects as $related_object ) { |
|
| 1434 | + foreach ($related_objects as $related_object) { |
|
| 1435 | 1435 | //only refresh their cache if they're in memory |
| 1436 | - if( $related_object instanceof EE_Base_Class ) { |
|
| 1437 | - $related_object->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1436 | + if ($related_object instanceof EE_Base_Class) { |
|
| 1437 | + $related_object->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 1438 | 1438 | } |
| 1439 | 1439 | } |
| 1440 | 1440 | } |
@@ -1454,17 +1454,17 @@ discard block |
||
| 1454 | 1454 | * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object |
| 1455 | 1455 | * isn't allowed to persist (as determined by EE_Base_Class::allow_persist()) |
| 1456 | 1456 | */ |
| 1457 | - public function save($set_cols_n_values=array()) { |
|
| 1457 | + public function save($set_cols_n_values = array()) { |
|
| 1458 | 1458 | /** |
| 1459 | 1459 | * Filters the fields we're about to save on the model object |
| 1460 | 1460 | * |
| 1461 | 1461 | * @param array $set_cols_n_values |
| 1462 | 1462 | * @param EE_Base_Class $model_object |
| 1463 | 1463 | */ |
| 1464 | - $set_cols_n_values = (array)apply_filters( 'FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this ); |
|
| 1464 | + $set_cols_n_values = (array) apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this); |
|
| 1465 | 1465 | //set attributes as provided in $set_cols_n_values |
| 1466 | - foreach($set_cols_n_values as $column=>$value){ |
|
| 1467 | - $this->set($column,$value); |
|
| 1466 | + foreach ($set_cols_n_values as $column=>$value) { |
|
| 1467 | + $this->set($column, $value); |
|
| 1468 | 1468 | } |
| 1469 | 1469 | /** |
| 1470 | 1470 | * Saving a model object. |
@@ -1472,8 +1472,8 @@ discard block |
||
| 1472 | 1472 | * Before we perform a save, this action is fired. |
| 1473 | 1473 | * @param EE_Base_Class $model_object the model object about to be saved. |
| 1474 | 1474 | */ |
| 1475 | - do_action( 'AHEE__EE_Base_Class__save__begin', $this ); |
|
| 1476 | - if( ! $this->allow_persist() ) { |
|
| 1475 | + do_action('AHEE__EE_Base_Class__save__begin', $this); |
|
| 1476 | + if ( ! $this->allow_persist()) { |
|
| 1477 | 1477 | return 0; |
| 1478 | 1478 | } |
| 1479 | 1479 | //now get current attribute values |
@@ -1483,61 +1483,61 @@ discard block |
||
| 1483 | 1483 | $old_assumption_concerning_value_preparation = $this->get_model()->get_assumption_concerning_values_already_prepared_by_model_object(); |
| 1484 | 1484 | $this->get_model()->assume_values_already_prepared_by_model_object(true); |
| 1485 | 1485 | //does this model have an autoincrement PK? |
| 1486 | - if($this->get_model()->has_primary_key_field()){ |
|
| 1487 | - if($this->get_model()->get_primary_key_field()->is_auto_increment()){ |
|
| 1486 | + if ($this->get_model()->has_primary_key_field()) { |
|
| 1487 | + if ($this->get_model()->get_primary_key_field()->is_auto_increment()) { |
|
| 1488 | 1488 | //ok check if it's set, if so: update; if not, insert |
| 1489 | - if ( ! empty( $save_cols_n_values[self::_get_primary_key_name( get_class($this) )] ) ){ |
|
| 1490 | - $results = $this->get_model()->update_by_ID ( $save_cols_n_values, $this->ID() ); |
|
| 1489 | + if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) { |
|
| 1490 | + $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
|
| 1491 | 1491 | } else { |
| 1492 | - unset($save_cols_n_values[self::_get_primary_key_name( get_class( $this) )]); |
|
| 1493 | - $results = $this->get_model()->insert( $save_cols_n_values ); |
|
| 1494 | - if($results){ |
|
| 1492 | + unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]); |
|
| 1493 | + $results = $this->get_model()->insert($save_cols_n_values); |
|
| 1494 | + if ($results) { |
|
| 1495 | 1495 | //if successful, set the primary key |
| 1496 | 1496 | //but don't use the normal SET method, because it will check if |
| 1497 | 1497 | //an item with the same ID exists in the mapper & db, then |
| 1498 | 1498 | //will find it in the db (because we just added it) and THAT object |
| 1499 | 1499 | //will get added to the mapper before we can add this one! |
| 1500 | 1500 | //but if we just avoid using the SET method, all that headache can be avoided |
| 1501 | - $pk_field_name =self::_get_primary_key_name( get_class($this)); |
|
| 1501 | + $pk_field_name = self::_get_primary_key_name(get_class($this)); |
|
| 1502 | 1502 | $this->_fields[$pk_field_name] = $results; |
| 1503 | 1503 | $this->_clear_cached_property($pk_field_name); |
| 1504 | - $this->get_model()->add_to_entity_map( $this ); |
|
| 1504 | + $this->get_model()->add_to_entity_map($this); |
|
| 1505 | 1505 | $this->_update_cached_related_model_objs_fks(); |
| 1506 | 1506 | } |
| 1507 | 1507 | } |
| 1508 | - }else{//PK is NOT auto-increment |
|
| 1508 | + } else {//PK is NOT auto-increment |
|
| 1509 | 1509 | //so check if one like it already exists in the db |
| 1510 | - if( $this->get_model()->exists_by_ID( $this->ID() ) ){ |
|
| 1511 | - if( WP_DEBUG && ! $this->in_entity_map() ){ |
|
| 1510 | + if ($this->get_model()->exists_by_ID($this->ID())) { |
|
| 1511 | + if (WP_DEBUG && ! $this->in_entity_map()) { |
|
| 1512 | 1512 | throw new EE_Error( |
| 1513 | 1513 | sprintf( |
| 1514 | - __( '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', 'event_espresso' ), |
|
| 1514 | + __('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', 'event_espresso'), |
|
| 1515 | 1515 | get_class($this), |
| 1516 | - get_class( $this->get_model() ) . '::instance()->add_to_entity_map()', |
|
| 1517 | - get_class( $this->get_model() ) . '::instance()->get_one_by_ID()', |
|
| 1516 | + get_class($this->get_model()).'::instance()->add_to_entity_map()', |
|
| 1517 | + get_class($this->get_model()).'::instance()->get_one_by_ID()', |
|
| 1518 | 1518 | '<br />' |
| 1519 | 1519 | ) |
| 1520 | 1520 | ); |
| 1521 | 1521 | } |
| 1522 | 1522 | $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
| 1523 | - }else{ |
|
| 1523 | + } else { |
|
| 1524 | 1524 | $results = $this->get_model()->insert($save_cols_n_values); |
| 1525 | 1525 | $this->_update_cached_related_model_objs_fks(); |
| 1526 | 1526 | } |
| 1527 | 1527 | } |
| 1528 | - }else{//there is NO primary key |
|
| 1528 | + } else {//there is NO primary key |
|
| 1529 | 1529 | $already_in_db = false; |
| 1530 | - foreach($this->get_model()->unique_indexes() as $index){ |
|
| 1530 | + foreach ($this->get_model()->unique_indexes() as $index) { |
|
| 1531 | 1531 | $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
| 1532 | - if($this->get_model()->exists(array($uniqueness_where_params))){ |
|
| 1532 | + if ($this->get_model()->exists(array($uniqueness_where_params))) { |
|
| 1533 | 1533 | $already_in_db = true; |
| 1534 | 1534 | } |
| 1535 | 1535 | } |
| 1536 | - if( $already_in_db ){ |
|
| 1537 | - $combined_pk_fields_n_values = array_intersect_key( $save_cols_n_values, $this->get_model()->get_combined_primary_key_fields() ); |
|
| 1538 | - $results = $this->get_model()->update( $save_cols_n_values,$combined_pk_fields_n_values ); |
|
| 1539 | - }else{ |
|
| 1540 | - $results = $this->get_model()->insert( $save_cols_n_values ); |
|
| 1536 | + if ($already_in_db) { |
|
| 1537 | + $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, $this->get_model()->get_combined_primary_key_fields()); |
|
| 1538 | + $results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values); |
|
| 1539 | + } else { |
|
| 1540 | + $results = $this->get_model()->insert($save_cols_n_values); |
|
| 1541 | 1541 | } |
| 1542 | 1542 | } |
| 1543 | 1543 | //restore the old assumption about values being prepared by the model object |
@@ -1550,7 +1550,7 @@ discard block |
||
| 1550 | 1550 | * @param boolean|int $results if it were updated, TRUE or FALSE; if it were newly inserted |
| 1551 | 1551 | * the new ID (or 0 if an error occurred and it wasn't updated) |
| 1552 | 1552 | */ |
| 1553 | - do_action( 'AHEE__EE_Base_Class__save__end', $this, $results ); |
|
| 1553 | + do_action('AHEE__EE_Base_Class__save__end', $this, $results); |
|
| 1554 | 1554 | return $results; |
| 1555 | 1555 | } |
| 1556 | 1556 | |
@@ -1565,15 +1565,15 @@ discard block |
||
| 1565 | 1565 | * @return void |
| 1566 | 1566 | * @throws \EE_Error |
| 1567 | 1567 | */ |
| 1568 | - protected function _update_cached_related_model_objs_fks(){ |
|
| 1569 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ){ |
|
| 1570 | - if( $relation_obj instanceof EE_Has_Many_Relation ){ |
|
| 1571 | - foreach( $this->get_all_from_cache( $relation_name ) as $related_model_obj_in_cache) { |
|
| 1568 | + protected function _update_cached_related_model_objs_fks() { |
|
| 1569 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 1570 | + if ($relation_obj instanceof EE_Has_Many_Relation) { |
|
| 1571 | + foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) { |
|
| 1572 | 1572 | $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to( |
| 1573 | 1573 | $this->get_model()->get_this_model_name() |
| 1574 | 1574 | ); |
| 1575 | - $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID() ); |
|
| 1576 | - if( $related_model_obj_in_cache->ID() ){ |
|
| 1575 | + $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID()); |
|
| 1576 | + if ($related_model_obj_in_cache->ID()) { |
|
| 1577 | 1577 | $related_model_obj_in_cache->save(); |
| 1578 | 1578 | } |
| 1579 | 1579 | } |
@@ -1594,21 +1594,21 @@ discard block |
||
| 1594 | 1594 | * @return int ID of new model object on save; 0 on failure+ |
| 1595 | 1595 | * @throws \EE_Error |
| 1596 | 1596 | */ |
| 1597 | - public function save_new_cached_related_model_objs(){ |
|
| 1597 | + public function save_new_cached_related_model_objs() { |
|
| 1598 | 1598 | //make sure this has been saved |
| 1599 | - if( ! $this->ID()){ |
|
| 1599 | + if ( ! $this->ID()) { |
|
| 1600 | 1600 | $id = $this->save(); |
| 1601 | - }else{ |
|
| 1601 | + } else { |
|
| 1602 | 1602 | $id = $this->ID(); |
| 1603 | 1603 | } |
| 1604 | 1604 | //now save all the NEW cached model objects (ie they don't exist in the DB) |
| 1605 | - foreach($this->get_model()->relation_settings() as $relationName => $relationObj){ |
|
| 1605 | + foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) { |
|
| 1606 | 1606 | |
| 1607 | 1607 | |
| 1608 | - if($this->_model_relations[$relationName]){ |
|
| 1608 | + if ($this->_model_relations[$relationName]) { |
|
| 1609 | 1609 | //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation) |
| 1610 | 1610 | //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)? |
| 1611 | - if($relationObj instanceof EE_Belongs_To_Relation){ |
|
| 1611 | + if ($relationObj instanceof EE_Belongs_To_Relation) { |
|
| 1612 | 1612 | //add a relation to that relation type (which saves the appropriate thing in the process) |
| 1613 | 1613 | //but ONLY if it DOES NOT exist in the DB |
| 1614 | 1614 | /* @var $related_model_obj EE_Base_Class */ |
@@ -1617,8 +1617,8 @@ discard block |
||
| 1617 | 1617 | $this->_add_relation_to($related_model_obj, $relationName); |
| 1618 | 1618 | $related_model_obj->save_new_cached_related_model_objs(); |
| 1619 | 1619 | // } |
| 1620 | - }else{ |
|
| 1621 | - foreach($this->_model_relations[$relationName] as $related_model_obj){ |
|
| 1620 | + } else { |
|
| 1621 | + foreach ($this->_model_relations[$relationName] as $related_model_obj) { |
|
| 1622 | 1622 | //add a relation to that relation type (which saves the appropriate thing in the process) |
| 1623 | 1623 | //but ONLY if it DOES NOT exist in the DB |
| 1624 | 1624 | // if( ! $related_model_obj->ID()){ |
@@ -1639,8 +1639,8 @@ discard block |
||
| 1639 | 1639 | * @return \EEM_Base | \EEM_CPT_Base |
| 1640 | 1640 | */ |
| 1641 | 1641 | public function get_model() { |
| 1642 | - $modelName = self::_get_model_classname( get_class($this) ); |
|
| 1643 | - return self::_get_model_instance_with_name($modelName, $this->_timezone ); |
|
| 1642 | + $modelName = self::_get_model_classname(get_class($this)); |
|
| 1643 | + return self::_get_model_instance_with_name($modelName, $this->_timezone); |
|
| 1644 | 1644 | } |
| 1645 | 1645 | |
| 1646 | 1646 | |
@@ -1651,10 +1651,10 @@ discard block |
||
| 1651 | 1651 | * @return mixed bool|EE_Base_Class|EEM_CPT_Base |
| 1652 | 1652 | * @throws \EE_Error |
| 1653 | 1653 | */ |
| 1654 | - protected static function _get_object_from_entity_mapper($props_n_values, $classname){ |
|
| 1654 | + protected static function _get_object_from_entity_mapper($props_n_values, $classname) { |
|
| 1655 | 1655 | //TODO: will not work for Term_Relationships because they have no PK! |
| 1656 | - $primary_id_ref = self::_get_primary_key_name( $classname ); |
|
| 1657 | - if ( array_key_exists( $primary_id_ref, $props_n_values ) && !empty( $props_n_values[$primary_id_ref] ) ) { |
|
| 1656 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
| 1657 | + if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
| 1658 | 1658 | $id = $props_n_values[$primary_id_ref]; |
| 1659 | 1659 | return self::_get_model($classname)->get_from_entity_map($id); |
| 1660 | 1660 | } |
@@ -1675,37 +1675,37 @@ discard block |
||
| 1675 | 1675 | * @return mixed (EE_Base_Class|bool) |
| 1676 | 1676 | * @throws \EE_Error |
| 1677 | 1677 | */ |
| 1678 | - protected static function _check_for_object( $props_n_values, $classname, $timezone = NULL, $date_formats = array() ) { |
|
| 1678 | + protected static function _check_for_object($props_n_values, $classname, $timezone = NULL, $date_formats = array()) { |
|
| 1679 | 1679 | $existing = null; |
| 1680 | - if ( self::_get_model( $classname )->has_primary_key_field() ) { |
|
| 1681 | - $primary_id_ref = self::_get_primary_key_name( $classname ); |
|
| 1682 | - if ( array_key_exists( $primary_id_ref, $props_n_values ) |
|
| 1683 | - && ! empty( $props_n_values[ $primary_id_ref ] ) |
|
| 1680 | + if (self::_get_model($classname)->has_primary_key_field()) { |
|
| 1681 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
| 1682 | + if (array_key_exists($primary_id_ref, $props_n_values) |
|
| 1683 | + && ! empty($props_n_values[$primary_id_ref]) |
|
| 1684 | 1684 | ) { |
| 1685 | - $existing = self::_get_model( $classname, $timezone )->get_one_by_ID( |
|
| 1686 | - $props_n_values[ $primary_id_ref ] |
|
| 1685 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID( |
|
| 1686 | + $props_n_values[$primary_id_ref] |
|
| 1687 | 1687 | ); |
| 1688 | 1688 | } |
| 1689 | - } elseif ( self::_get_model( $classname, $timezone )->has_all_combined_primary_key_fields( $props_n_values ) ) { |
|
| 1689 | + } elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) { |
|
| 1690 | 1690 | //no primary key on this model, but there's still a matching item in the DB |
| 1691 | - $existing = self::_get_model( $classname, $timezone )->get_one_by_ID( |
|
| 1692 | - self::_get_model( $classname, $timezone )->get_index_primary_key_string( $props_n_values ) |
|
| 1691 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID( |
|
| 1692 | + self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values) |
|
| 1693 | 1693 | ); |
| 1694 | 1694 | } |
| 1695 | - if ( $existing ) { |
|
| 1695 | + if ($existing) { |
|
| 1696 | 1696 | |
| 1697 | 1697 | //set date formats if present before setting values |
| 1698 | - if ( ! empty( $date_formats ) && is_array( $date_formats ) ) { |
|
| 1699 | - $existing->set_date_format( $date_formats[0] ); |
|
| 1700 | - $existing->set_time_format( $date_formats[1] ); |
|
| 1698 | + if ( ! empty($date_formats) && is_array($date_formats)) { |
|
| 1699 | + $existing->set_date_format($date_formats[0]); |
|
| 1700 | + $existing->set_time_format($date_formats[1]); |
|
| 1701 | 1701 | } else { |
| 1702 | 1702 | //set default formats for date and time |
| 1703 | - $existing->set_date_format( get_option( 'date_format' ) ); |
|
| 1704 | - $existing->set_time_format( get_option( 'time_format' ) ); |
|
| 1703 | + $existing->set_date_format(get_option('date_format')); |
|
| 1704 | + $existing->set_time_format(get_option('time_format')); |
|
| 1705 | 1705 | } |
| 1706 | 1706 | |
| 1707 | - foreach ( $props_n_values as $property => $field_value ) { |
|
| 1708 | - $existing->set( $property, $field_value ); |
|
| 1707 | + foreach ($props_n_values as $property => $field_value) { |
|
| 1708 | + $existing->set($property, $field_value); |
|
| 1709 | 1709 | } |
| 1710 | 1710 | return $existing; |
| 1711 | 1711 | } else { |
@@ -1723,9 +1723,9 @@ discard block |
||
| 1723 | 1723 | * @throws EE_Error |
| 1724 | 1724 | * @return EEM_Base |
| 1725 | 1725 | */ |
| 1726 | - protected static function _get_model( $classname, $timezone = NULL ){ |
|
| 1726 | + protected static function _get_model($classname, $timezone = NULL) { |
|
| 1727 | 1727 | //find model for this class |
| 1728 | - if( ! $classname ){ |
|
| 1728 | + if ( ! $classname) { |
|
| 1729 | 1729 | throw new EE_Error( |
| 1730 | 1730 | sprintf( |
| 1731 | 1731 | __( |
@@ -1736,8 +1736,8 @@ discard block |
||
| 1736 | 1736 | ) |
| 1737 | 1737 | ); |
| 1738 | 1738 | } |
| 1739 | - $modelName=self::_get_model_classname($classname); |
|
| 1740 | - return self::_get_model_instance_with_name($modelName, $timezone ); |
|
| 1739 | + $modelName = self::_get_model_classname($classname); |
|
| 1740 | + return self::_get_model_instance_with_name($modelName, $timezone); |
|
| 1741 | 1741 | } |
| 1742 | 1742 | |
| 1743 | 1743 | |
@@ -1748,10 +1748,10 @@ discard block |
||
| 1748 | 1748 | * @param null $timezone |
| 1749 | 1749 | * @return EEM_Base |
| 1750 | 1750 | */ |
| 1751 | - protected static function _get_model_instance_with_name($model_classname, $timezone = NULL){ |
|
| 1752 | - $model_classname = str_replace( 'EEM_', '', $model_classname ); |
|
| 1753 | - $model = EE_Registry::instance()->load_model( $model_classname ); |
|
| 1754 | - $model->set_timezone( $timezone ); |
|
| 1751 | + protected static function _get_model_instance_with_name($model_classname, $timezone = NULL) { |
|
| 1752 | + $model_classname = str_replace('EEM_', '', $model_classname); |
|
| 1753 | + $model = EE_Registry::instance()->load_model($model_classname); |
|
| 1754 | + $model->set_timezone($timezone); |
|
| 1755 | 1755 | return $model; |
| 1756 | 1756 | } |
| 1757 | 1757 | |
@@ -1763,10 +1763,10 @@ discard block |
||
| 1763 | 1763 | * @param null $model_name |
| 1764 | 1764 | * @return string like EEM_Attendee |
| 1765 | 1765 | */ |
| 1766 | - private static function _get_model_classname( $model_name = null){ |
|
| 1767 | - if(strpos($model_name,"EE_")===0){ |
|
| 1768 | - $model_classname=str_replace("EE_","EEM_",$model_name); |
|
| 1769 | - }else{ |
|
| 1766 | + private static function _get_model_classname($model_name = null) { |
|
| 1767 | + if (strpos($model_name, "EE_") === 0) { |
|
| 1768 | + $model_classname = str_replace("EE_", "EEM_", $model_name); |
|
| 1769 | + } else { |
|
| 1770 | 1770 | $model_classname = "EEM_".$model_name; |
| 1771 | 1771 | } |
| 1772 | 1772 | return $model_classname; |
@@ -1780,16 +1780,16 @@ discard block |
||
| 1780 | 1780 | * @throws EE_Error |
| 1781 | 1781 | * @return string |
| 1782 | 1782 | */ |
| 1783 | - protected static function _get_primary_key_name( $classname = NULL ){ |
|
| 1784 | - if( ! $classname){ |
|
| 1783 | + protected static function _get_primary_key_name($classname = NULL) { |
|
| 1784 | + if ( ! $classname) { |
|
| 1785 | 1785 | throw new EE_Error( |
| 1786 | 1786 | sprintf( |
| 1787 | - __( "What were you thinking calling _get_primary_key_name(%s)", "event_espresso" ), |
|
| 1787 | + __("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"), |
|
| 1788 | 1788 | $classname |
| 1789 | 1789 | ) |
| 1790 | 1790 | ); |
| 1791 | 1791 | } |
| 1792 | - return self::_get_model( $classname )->get_primary_key_field()->get_name(); |
|
| 1792 | + return self::_get_model($classname)->get_primary_key_field()->get_name(); |
|
| 1793 | 1793 | } |
| 1794 | 1794 | |
| 1795 | 1795 | |
@@ -1803,12 +1803,12 @@ discard block |
||
| 1803 | 1803 | * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string |
| 1804 | 1804 | * @throws \EE_Error |
| 1805 | 1805 | */ |
| 1806 | - public function ID(){ |
|
| 1806 | + public function ID() { |
|
| 1807 | 1807 | //now that we know the name of the variable, use a variable variable to get its value and return its |
| 1808 | - if( $this->get_model()->has_primary_key_field() ) { |
|
| 1809 | - return $this->_fields[ self::_get_primary_key_name( get_class($this) ) ]; |
|
| 1810 | - }else{ |
|
| 1811 | - return $this->get_model()->get_index_primary_key_string( $this->_fields ); |
|
| 1808 | + if ($this->get_model()->has_primary_key_field()) { |
|
| 1809 | + return $this->_fields[self::_get_primary_key_name(get_class($this))]; |
|
| 1810 | + } else { |
|
| 1811 | + return $this->get_model()->get_index_primary_key_string($this->_fields); |
|
| 1812 | 1812 | } |
| 1813 | 1813 | } |
| 1814 | 1814 | |
@@ -1826,38 +1826,38 @@ discard block |
||
| 1826 | 1826 | * @throws EE_Error |
| 1827 | 1827 | * @return EE_Base_Class the object the relation was added to |
| 1828 | 1828 | */ |
| 1829 | - public function _add_relation_to( $otherObjectModelObjectOrID,$relationName, $extra_join_model_fields_n_values = array(), $cache_id = NULL ){ |
|
| 1829 | + public function _add_relation_to($otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values = array(), $cache_id = NULL) { |
|
| 1830 | 1830 | //if this thing exists in the DB, save the relation to the DB |
| 1831 | - if( $this->ID() ){ |
|
| 1832 | - $otherObject = $this->get_model()->add_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values ); |
|
| 1831 | + if ($this->ID()) { |
|
| 1832 | + $otherObject = $this->get_model()->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values); |
|
| 1833 | 1833 | //clear cache so future get_many_related and get_first_related() return new results. |
| 1834 | - $this->clear_cache( $relationName, $otherObject, TRUE ); |
|
| 1835 | - if( $otherObject instanceof EE_Base_Class ) { |
|
| 1836 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1834 | + $this->clear_cache($relationName, $otherObject, TRUE); |
|
| 1835 | + if ($otherObject instanceof EE_Base_Class) { |
|
| 1836 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 1837 | 1837 | } |
| 1838 | 1838 | } else { |
| 1839 | 1839 | //this thing doesn't exist in the DB, so just cache it |
| 1840 | - if( ! $otherObjectModelObjectOrID instanceof EE_Base_Class){ |
|
| 1841 | - throw new EE_Error( sprintf( |
|
| 1842 | - __( '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', 'event_espresso' ), |
|
| 1840 | + if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) { |
|
| 1841 | + throw new EE_Error(sprintf( |
|
| 1842 | + __('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', 'event_espresso'), |
|
| 1843 | 1843 | $otherObjectModelObjectOrID, |
| 1844 | - get_class( $this ) |
|
| 1844 | + get_class($this) |
|
| 1845 | 1845 | )); |
| 1846 | 1846 | } else { |
| 1847 | 1847 | $otherObject = $otherObjectModelObjectOrID; |
| 1848 | 1848 | } |
| 1849 | - $this->cache( $relationName, $otherObjectModelObjectOrID, $cache_id ); |
|
| 1849 | + $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id); |
|
| 1850 | 1850 | } |
| 1851 | - if( $otherObject instanceof EE_Base_Class ) { |
|
| 1851 | + if ($otherObject instanceof EE_Base_Class) { |
|
| 1852 | 1852 | //fix the reciprocal relation too |
| 1853 | - if( $otherObject->ID() ) { |
|
| 1853 | + if ($otherObject->ID()) { |
|
| 1854 | 1854 | //its saved so assumed relations exist in the DB, so we can just |
| 1855 | 1855 | //clear the cache so future queries use the updated info in the DB |
| 1856 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), null, true ); |
|
| 1856 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true); |
|
| 1857 | 1857 | } else { |
| 1858 | 1858 | |
| 1859 | 1859 | //it's not saved, so it caches relations like this |
| 1860 | - $otherObject->cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1860 | + $otherObject->cache($this->get_model()->get_this_model_name(), $this); |
|
| 1861 | 1861 | } |
| 1862 | 1862 | } |
| 1863 | 1863 | return $otherObject; |
@@ -1881,17 +1881,17 @@ discard block |
||
| 1881 | 1881 | * @return EE_Base_Class the relation was removed from |
| 1882 | 1882 | * @throws \EE_Error |
| 1883 | 1883 | */ |
| 1884 | - public function _remove_relation_to($otherObjectModelObjectOrID,$relationName, $where_query = array() ){ |
|
| 1885 | - if ( $this->ID() ) { |
|
| 1884 | + public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array()) { |
|
| 1885 | + if ($this->ID()) { |
|
| 1886 | 1886 | //if this exists in the DB, save the relation change to the DB too |
| 1887 | - $otherObject = $this->get_model()->remove_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $where_query ); |
|
| 1888 | - $this->clear_cache( $relationName, $otherObject ); |
|
| 1887 | + $otherObject = $this->get_model()->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $where_query); |
|
| 1888 | + $this->clear_cache($relationName, $otherObject); |
|
| 1889 | 1889 | } else { |
| 1890 | 1890 | //this doesn't exist in the DB, just remove it from the cache |
| 1891 | - $otherObject = $this->clear_cache( $relationName, $otherObjectModelObjectOrID ); |
|
| 1891 | + $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID); |
|
| 1892 | 1892 | } |
| 1893 | - if( $otherObject instanceof EE_Base_Class ) { |
|
| 1894 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1893 | + if ($otherObject instanceof EE_Base_Class) { |
|
| 1894 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 1895 | 1895 | } |
| 1896 | 1896 | return $otherObject; |
| 1897 | 1897 | } |
@@ -1906,18 +1906,18 @@ discard block |
||
| 1906 | 1906 | * @return EE_Base_Class |
| 1907 | 1907 | * @throws \EE_Error |
| 1908 | 1908 | */ |
| 1909 | - public function _remove_relations($relationName,$where_query_params = array()){ |
|
| 1910 | - if ( $this->ID() ) { |
|
| 1909 | + public function _remove_relations($relationName, $where_query_params = array()) { |
|
| 1910 | + if ($this->ID()) { |
|
| 1911 | 1911 | //if this exists in the DB, save the relation change to the DB too |
| 1912 | - $otherObjects = $this->get_model()->remove_relations( $this, $relationName, $where_query_params ); |
|
| 1913 | - $this->clear_cache( $relationName, null, true ); |
|
| 1912 | + $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params); |
|
| 1913 | + $this->clear_cache($relationName, null, true); |
|
| 1914 | 1914 | } else { |
| 1915 | 1915 | //this doesn't exist in the DB, just remove it from the cache |
| 1916 | - $otherObjects = $this->clear_cache( $relationName, null, true ); |
|
| 1916 | + $otherObjects = $this->clear_cache($relationName, null, true); |
|
| 1917 | 1917 | } |
| 1918 | - if( is_array( $otherObjects ) ) { |
|
| 1919 | - foreach ( $otherObjects as $otherObject ) { |
|
| 1920 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1918 | + if (is_array($otherObjects)) { |
|
| 1919 | + foreach ($otherObjects as $otherObject) { |
|
| 1920 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 1921 | 1921 | } |
| 1922 | 1922 | } |
| 1923 | 1923 | return $otherObjects; |
@@ -1937,27 +1937,27 @@ discard block |
||
| 1937 | 1937 | * @throws \EE_Error |
| 1938 | 1938 | * or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if you want IDs |
| 1939 | 1939 | */ |
| 1940 | - public function get_many_related($relationName,$query_params = array()){ |
|
| 1941 | - if($this->ID()){ |
|
| 1940 | + public function get_many_related($relationName, $query_params = array()) { |
|
| 1941 | + if ($this->ID()) { |
|
| 1942 | 1942 | //this exists in the DB, so get the related things from either the cache or the DB |
| 1943 | 1943 | //if there are query parameters, forget about caching the related model objects. |
| 1944 | - if( $query_params ){ |
|
| 1944 | + if ($query_params) { |
|
| 1945 | 1945 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
| 1946 | - }else{ |
|
| 1946 | + } else { |
|
| 1947 | 1947 | //did we already cache the result of this query? |
| 1948 | 1948 | $cached_results = $this->get_all_from_cache($relationName); |
| 1949 | - if ( ! $cached_results ){ |
|
| 1949 | + if ( ! $cached_results) { |
|
| 1950 | 1950 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
| 1951 | 1951 | //if no query parameters were passed, then we got all the related model objects |
| 1952 | 1952 | //for that relation. We can cache them then. |
| 1953 | - foreach($related_model_objects as $related_model_object){ |
|
| 1953 | + foreach ($related_model_objects as $related_model_object) { |
|
| 1954 | 1954 | $this->cache($relationName, $related_model_object); |
| 1955 | 1955 | } |
| 1956 | - }else{ |
|
| 1956 | + } else { |
|
| 1957 | 1957 | $related_model_objects = $cached_results; |
| 1958 | 1958 | } |
| 1959 | 1959 | } |
| 1960 | - }else{ |
|
| 1960 | + } else { |
|
| 1961 | 1961 | //this doesn't exist in the DB, so just get the related things from the cache |
| 1962 | 1962 | $related_model_objects = $this->get_all_from_cache($relationName); |
| 1963 | 1963 | } |
@@ -1975,8 +1975,8 @@ discard block |
||
| 1975 | 1975 | * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
| 1976 | 1976 | * @return int |
| 1977 | 1977 | */ |
| 1978 | - public function count_related($relation_name, $query_params =array(),$field_to_count = NULL, $distinct = FALSE){ |
|
| 1979 | - return $this->get_model()->count_related($this,$relation_name,$query_params,$field_to_count,$distinct); |
|
| 1978 | + public function count_related($relation_name, $query_params = array(), $field_to_count = NULL, $distinct = FALSE) { |
|
| 1979 | + return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct); |
|
| 1980 | 1980 | } |
| 1981 | 1981 | |
| 1982 | 1982 | |
@@ -1990,7 +1990,7 @@ discard block |
||
| 1990 | 1990 | * By default, uses primary key (which doesn't make much sense, so you should probably change it) |
| 1991 | 1991 | * @return int |
| 1992 | 1992 | */ |
| 1993 | - public function sum_related($relation_name, $query_params = array(), $field_to_sum = null){ |
|
| 1993 | + public function sum_related($relation_name, $query_params = array(), $field_to_sum = null) { |
|
| 1994 | 1994 | return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum); |
| 1995 | 1995 | } |
| 1996 | 1996 | |
@@ -2004,33 +2004,33 @@ discard block |
||
| 2004 | 2004 | * @return EE_Base_Class (not an array, a single object) |
| 2005 | 2005 | * @throws \EE_Error |
| 2006 | 2006 | */ |
| 2007 | - public function get_first_related($relationName,$query_params = array()){ |
|
| 2008 | - if($this->ID()){//this exists in the DB, get from the cache OR the DB |
|
| 2007 | + public function get_first_related($relationName, $query_params = array()) { |
|
| 2008 | + if ($this->ID()) {//this exists in the DB, get from the cache OR the DB |
|
| 2009 | 2009 | |
| 2010 | 2010 | //if they've provided some query parameters, don't bother trying to cache the result |
| 2011 | 2011 | //also make sure we're not caching the result of get_first_related |
| 2012 | 2012 | //on a relation which should have an array of objects (because the cache might have an array of objects) |
| 2013 | - if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
|
| 2014 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 2015 | - }else{ |
|
| 2013 | + if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
| 2014 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 2015 | + } else { |
|
| 2016 | 2016 | //first, check if we've already cached the result of this query |
| 2017 | 2017 | $cached_result = $this->get_one_from_cache($relationName); |
| 2018 | - if ( ! $cached_result ){ |
|
| 2018 | + if ( ! $cached_result) { |
|
| 2019 | 2019 | |
| 2020 | 2020 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
| 2021 | - $this->cache($relationName,$related_model_object); |
|
| 2022 | - }else{ |
|
| 2021 | + $this->cache($relationName, $related_model_object); |
|
| 2022 | + } else { |
|
| 2023 | 2023 | $related_model_object = $cached_result; |
| 2024 | 2024 | } |
| 2025 | 2025 | } |
| 2026 | - }else{ |
|
| 2026 | + } else { |
|
| 2027 | 2027 | $related_model_object = null; |
| 2028 | 2028 | //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
| 2029 | - if( $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
|
| 2030 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 2029 | + if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
| 2030 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 2031 | 2031 | } |
| 2032 | 2032 | //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 |
| 2033 | - if( ! $related_model_object){ |
|
| 2033 | + if ( ! $related_model_object) { |
|
| 2034 | 2034 | $related_model_object = $this->get_one_from_cache($relationName); |
| 2035 | 2035 | } |
| 2036 | 2036 | |
@@ -2052,12 +2052,12 @@ discard block |
||
| 2052 | 2052 | * @return int how many deleted |
| 2053 | 2053 | * @throws \EE_Error |
| 2054 | 2054 | */ |
| 2055 | - public function delete_related($relationName,$query_params = array()){ |
|
| 2056 | - if($this->ID()){ |
|
| 2057 | - $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
| 2058 | - }else{ |
|
| 2055 | + public function delete_related($relationName, $query_params = array()) { |
|
| 2056 | + if ($this->ID()) { |
|
| 2057 | + $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
| 2058 | + } else { |
|
| 2059 | 2059 | $count = count($this->get_all_from_cache($relationName)); |
| 2060 | - $this->clear_cache($relationName,NULL,TRUE); |
|
| 2060 | + $this->clear_cache($relationName, NULL, TRUE); |
|
| 2061 | 2061 | } |
| 2062 | 2062 | return $count; |
| 2063 | 2063 | } |
@@ -2076,13 +2076,13 @@ discard block |
||
| 2076 | 2076 | * @return int how many deleted (including those soft deleted) |
| 2077 | 2077 | * @throws \EE_Error |
| 2078 | 2078 | */ |
| 2079 | - public function delete_related_permanently($relationName,$query_params = array()){ |
|
| 2080 | - if($this->ID()){ |
|
| 2081 | - $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
| 2082 | - }else{ |
|
| 2079 | + public function delete_related_permanently($relationName, $query_params = array()) { |
|
| 2080 | + if ($this->ID()) { |
|
| 2081 | + $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
| 2082 | + } else { |
|
| 2083 | 2083 | $count = count($this->get_all_from_cache($relationName)); |
| 2084 | 2084 | } |
| 2085 | - $this->clear_cache($relationName,NULL,TRUE); |
|
| 2085 | + $this->clear_cache($relationName, NULL, TRUE); |
|
| 2086 | 2086 | return $count; |
| 2087 | 2087 | } |
| 2088 | 2088 | |
@@ -2098,7 +2098,7 @@ discard block |
||
| 2098 | 2098 | * @param string $field_name property to check |
| 2099 | 2099 | * @return bool TRUE if existing,FALSE if not. |
| 2100 | 2100 | */ |
| 2101 | - public function is_set( $field_name ) { |
|
| 2101 | + public function is_set($field_name) { |
|
| 2102 | 2102 | return isset($this->_fields[$field_name]); |
| 2103 | 2103 | } |
| 2104 | 2104 | |
@@ -2110,11 +2110,11 @@ discard block |
||
| 2110 | 2110 | * @throws EE_Error |
| 2111 | 2111 | * @return bool TRUE if existing, throw EE_Error if not. |
| 2112 | 2112 | */ |
| 2113 | - protected function _property_exists( $properties ) { |
|
| 2113 | + protected function _property_exists($properties) { |
|
| 2114 | 2114 | |
| 2115 | - foreach ( (array) $properties as $property_name ) { |
|
| 2115 | + foreach ((array) $properties as $property_name) { |
|
| 2116 | 2116 | //first make sure this property exists |
| 2117 | - if ( ! $this->_fields[ $property_name ] ) { |
|
| 2117 | + if ( ! $this->_fields[$property_name]) { |
|
| 2118 | 2118 | throw new EE_Error( |
| 2119 | 2119 | sprintf( |
| 2120 | 2120 | __( |
@@ -2142,7 +2142,7 @@ discard block |
||
| 2142 | 2142 | $fields = $this->get_model()->field_settings(FALSE); |
| 2143 | 2143 | $properties = array(); |
| 2144 | 2144 | //remove prepended underscore |
| 2145 | - foreach ( $fields as $field_name => $settings ) { |
|
| 2145 | + foreach ($fields as $field_name => $settings) { |
|
| 2146 | 2146 | $properties[$field_name] = $this->get($field_name); |
| 2147 | 2147 | } |
| 2148 | 2148 | return $properties; |
@@ -2172,10 +2172,10 @@ discard block |
||
| 2172 | 2172 | * @throws EE_Error |
| 2173 | 2173 | * @return mixed whatever the plugin which calls add_filter decides |
| 2174 | 2174 | */ |
| 2175 | - public function __call($methodName,$args){ |
|
| 2176 | - $className=get_class($this); |
|
| 2177 | - $tagName="FHEE__{$className}__{$methodName}"; |
|
| 2178 | - if ( ! has_filter( $tagName ) ) { |
|
| 2175 | + public function __call($methodName, $args) { |
|
| 2176 | + $className = get_class($this); |
|
| 2177 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
| 2178 | + if ( ! has_filter($tagName)) { |
|
| 2179 | 2179 | throw new EE_Error( |
| 2180 | 2180 | sprintf( |
| 2181 | 2181 | __( |
@@ -2188,7 +2188,7 @@ discard block |
||
| 2188 | 2188 | ) |
| 2189 | 2189 | ); |
| 2190 | 2190 | } |
| 2191 | - return apply_filters($tagName,null,$this,$args); |
|
| 2191 | + return apply_filters($tagName, null, $this, $args); |
|
| 2192 | 2192 | } |
| 2193 | 2193 | |
| 2194 | 2194 | |
@@ -2204,7 +2204,7 @@ discard block |
||
| 2204 | 2204 | * @throws \EE_Error |
| 2205 | 2205 | * NOTE: if the values haven't changed, returns 0 |
| 2206 | 2206 | */ |
| 2207 | - public function update_extra_meta($meta_key,$meta_value,$previous_value = NULL){ |
|
| 2207 | + public function update_extra_meta($meta_key, $meta_value, $previous_value = NULL) { |
|
| 2208 | 2208 | $query_params = array( |
| 2209 | 2209 | array( |
| 2210 | 2210 | 'EXM_key' => $meta_key, |
@@ -2212,17 +2212,17 @@ discard block |
||
| 2212 | 2212 | 'EXM_type' => $this->get_model()->get_this_model_name() |
| 2213 | 2213 | ) |
| 2214 | 2214 | ); |
| 2215 | - if ( $previous_value !== null ) { |
|
| 2215 | + if ($previous_value !== null) { |
|
| 2216 | 2216 | $query_params[0]['EXM_value'] = $meta_value; |
| 2217 | 2217 | } |
| 2218 | - $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all( $query_params ); |
|
| 2219 | - if ( ! $existing_rows_like_that ) { |
|
| 2220 | - return $this->add_extra_meta( $meta_key, $meta_value ); |
|
| 2218 | + $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
|
| 2219 | + if ( ! $existing_rows_like_that) { |
|
| 2220 | + return $this->add_extra_meta($meta_key, $meta_value); |
|
| 2221 | 2221 | } else { |
| 2222 | - foreach ( $existing_rows_like_that as $existing_row ) { |
|
| 2223 | - $existing_row->save( array( 'EXM_value' => $meta_value ) ); |
|
| 2222 | + foreach ($existing_rows_like_that as $existing_row) { |
|
| 2223 | + $existing_row->save(array('EXM_value' => $meta_value)); |
|
| 2224 | 2224 | } |
| 2225 | - return count( $existing_rows_like_that ); |
|
| 2225 | + return count($existing_rows_like_that); |
|
| 2226 | 2226 | } |
| 2227 | 2227 | } |
| 2228 | 2228 | |
@@ -2239,8 +2239,8 @@ discard block |
||
| 2239 | 2239 | * @return boolean |
| 2240 | 2240 | * @throws \EE_Error |
| 2241 | 2241 | */ |
| 2242 | - public function add_extra_meta($meta_key,$meta_value,$unique = false){ |
|
| 2243 | - if ( $unique ) { |
|
| 2242 | + public function add_extra_meta($meta_key, $meta_value, $unique = false) { |
|
| 2243 | + if ($unique) { |
|
| 2244 | 2244 | $existing_extra_meta = EEM_Extra_Meta::instance()->get_one( |
| 2245 | 2245 | array( |
| 2246 | 2246 | array( |
@@ -2250,7 +2250,7 @@ discard block |
||
| 2250 | 2250 | ) |
| 2251 | 2251 | ) |
| 2252 | 2252 | ); |
| 2253 | - if ( $existing_extra_meta ) { |
|
| 2253 | + if ($existing_extra_meta) { |
|
| 2254 | 2254 | return false; |
| 2255 | 2255 | } |
| 2256 | 2256 | } |
@@ -2277,7 +2277,7 @@ discard block |
||
| 2277 | 2277 | * @return int number of extra meta rows deleted |
| 2278 | 2278 | * @throws \EE_Error |
| 2279 | 2279 | */ |
| 2280 | - public function delete_extra_meta($meta_key,$meta_value = NULL){ |
|
| 2280 | + public function delete_extra_meta($meta_key, $meta_value = NULL) { |
|
| 2281 | 2281 | $query_params = array( |
| 2282 | 2282 | array( |
| 2283 | 2283 | 'EXM_key' => $meta_key, |
@@ -2285,10 +2285,10 @@ discard block |
||
| 2285 | 2285 | 'EXM_type' => $this->get_model()->get_this_model_name() |
| 2286 | 2286 | ) |
| 2287 | 2287 | ); |
| 2288 | - if ( $meta_value !== null ) { |
|
| 2288 | + if ($meta_value !== null) { |
|
| 2289 | 2289 | $query_params[0]['EXM_value'] = $meta_value; |
| 2290 | 2290 | } |
| 2291 | - return EEM_Extra_Meta::instance()->delete( $query_params ); |
|
| 2291 | + return EEM_Extra_Meta::instance()->delete($query_params); |
|
| 2292 | 2292 | } |
| 2293 | 2293 | |
| 2294 | 2294 | |
@@ -2304,25 +2304,25 @@ discard block |
||
| 2304 | 2304 | * @return mixed single value if $single; array if ! $single |
| 2305 | 2305 | * @throws \EE_Error |
| 2306 | 2306 | */ |
| 2307 | - public function get_extra_meta($meta_key,$single = FALSE,$default = NULL){ |
|
| 2308 | - if($single){ |
|
| 2309 | - $result = $this->get_first_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
|
| 2310 | - if ( $result instanceof EE_Extra_Meta ){ |
|
| 2307 | + public function get_extra_meta($meta_key, $single = FALSE, $default = NULL) { |
|
| 2308 | + if ($single) { |
|
| 2309 | + $result = $this->get_first_related('Extra_Meta', array(array('EXM_key'=>$meta_key))); |
|
| 2310 | + if ($result instanceof EE_Extra_Meta) { |
|
| 2311 | 2311 | return $result->value(); |
| 2312 | - }else{ |
|
| 2312 | + } else { |
|
| 2313 | 2313 | return $default; |
| 2314 | 2314 | } |
| 2315 | - }else{ |
|
| 2316 | - $results = $this->get_many_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
|
| 2317 | - if($results){ |
|
| 2315 | + } else { |
|
| 2316 | + $results = $this->get_many_related('Extra_Meta', array(array('EXM_key'=>$meta_key))); |
|
| 2317 | + if ($results) { |
|
| 2318 | 2318 | $values = array(); |
| 2319 | - foreach($results as $result){ |
|
| 2320 | - if ( $result instanceof EE_Extra_Meta ){ |
|
| 2319 | + foreach ($results as $result) { |
|
| 2320 | + if ($result instanceof EE_Extra_Meta) { |
|
| 2321 | 2321 | $values[$result->ID()] = $result->value(); |
| 2322 | 2322 | } |
| 2323 | 2323 | } |
| 2324 | 2324 | return $values; |
| 2325 | - }else{ |
|
| 2325 | + } else { |
|
| 2326 | 2326 | return $default; |
| 2327 | 2327 | } |
| 2328 | 2328 | } |
@@ -2344,20 +2344,20 @@ discard block |
||
| 2344 | 2344 | * @return array |
| 2345 | 2345 | * @throws \EE_Error |
| 2346 | 2346 | */ |
| 2347 | - public function all_extra_meta_array($one_of_each_key = true){ |
|
| 2347 | + public function all_extra_meta_array($one_of_each_key = true) { |
|
| 2348 | 2348 | $return_array = array(); |
| 2349 | - if($one_of_each_key){ |
|
| 2349 | + if ($one_of_each_key) { |
|
| 2350 | 2350 | $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by'=>'EXM_key')); |
| 2351 | - foreach($extra_meta_objs as $extra_meta_obj){ |
|
| 2352 | - if ( $extra_meta_obj instanceof EE_Extra_Meta ) { |
|
| 2351 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
| 2352 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
| 2353 | 2353 | $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
| 2354 | 2354 | } |
| 2355 | 2355 | } |
| 2356 | - }else{ |
|
| 2356 | + } else { |
|
| 2357 | 2357 | $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
| 2358 | - foreach($extra_meta_objs as $extra_meta_obj){ |
|
| 2359 | - if ( $extra_meta_obj instanceof EE_Extra_Meta ) { |
|
| 2360 | - if( ! isset($return_array[$extra_meta_obj->key()])){ |
|
| 2358 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
| 2359 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
| 2360 | + if ( ! isset($return_array[$extra_meta_obj->key()])) { |
|
| 2361 | 2361 | $return_array[$extra_meta_obj->key()] = array(); |
| 2362 | 2362 | } |
| 2363 | 2363 | $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value(); |
@@ -2375,19 +2375,19 @@ discard block |
||
| 2375 | 2375 | * @return string |
| 2376 | 2376 | * @throws \EE_Error |
| 2377 | 2377 | */ |
| 2378 | - public function name(){ |
|
| 2378 | + public function name() { |
|
| 2379 | 2379 | //find a field that's not a text field |
| 2380 | 2380 | $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
| 2381 | - if($field_we_can_use){ |
|
| 2381 | + if ($field_we_can_use) { |
|
| 2382 | 2382 | return $this->get($field_we_can_use->get_name()); |
| 2383 | - }else{ |
|
| 2383 | + } else { |
|
| 2384 | 2384 | $first_few_properties = $this->model_field_array(); |
| 2385 | - $first_few_properties = array_slice($first_few_properties,0,3); |
|
| 2385 | + $first_few_properties = array_slice($first_few_properties, 0, 3); |
|
| 2386 | 2386 | $name_parts = array(); |
| 2387 | - foreach( $first_few_properties as $name=> $value ){ |
|
| 2387 | + foreach ($first_few_properties as $name=> $value) { |
|
| 2388 | 2388 | $name_parts[] = "$name:$value"; |
| 2389 | 2389 | } |
| 2390 | - return implode(",",$name_parts); |
|
| 2390 | + return implode(",", $name_parts); |
|
| 2391 | 2391 | } |
| 2392 | 2392 | } |
| 2393 | 2393 | |
@@ -2400,11 +2400,11 @@ discard block |
||
| 2400 | 2400 | * @return boolean |
| 2401 | 2401 | * @throws \EE_Error |
| 2402 | 2402 | */ |
| 2403 | - public function in_entity_map(){ |
|
| 2404 | - if( $this->ID() && $this->get_model()->get_from_entity_map( $this->ID() ) === $this ) { |
|
| 2403 | + public function in_entity_map() { |
|
| 2404 | + if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) { |
|
| 2405 | 2405 | //well, if we looked, did we find it in the entity map? |
| 2406 | 2406 | return TRUE; |
| 2407 | - }else{ |
|
| 2407 | + } else { |
|
| 2408 | 2408 | return FALSE; |
| 2409 | 2409 | } |
| 2410 | 2410 | } |
@@ -2415,21 +2415,21 @@ discard block |
||
| 2415 | 2415 | * @throws EE_Error if this model object isn't in the entity mapper (because then you should |
| 2416 | 2416 | * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE |
| 2417 | 2417 | */ |
| 2418 | - public function refresh_from_db(){ |
|
| 2419 | - if( $this->ID() && $this->in_entity_map() ){ |
|
| 2420 | - $this->get_model()->refresh_entity_map_from_db( $this->ID() ); |
|
| 2421 | - }else{ |
|
| 2418 | + public function refresh_from_db() { |
|
| 2419 | + if ($this->ID() && $this->in_entity_map()) { |
|
| 2420 | + $this->get_model()->refresh_entity_map_from_db($this->ID()); |
|
| 2421 | + } else { |
|
| 2422 | 2422 | //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
| 2423 | 2423 | //if it has an ID but it's not in the map, and you're asking me to refresh it |
| 2424 | 2424 | //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |
| 2425 | 2425 | //absolutely nothing in it for this ID |
| 2426 | - if( WP_DEBUG ) { |
|
| 2426 | + if (WP_DEBUG) { |
|
| 2427 | 2427 | throw new EE_Error( |
| 2428 | 2428 | sprintf( |
| 2429 | - __( '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.', 'event_espresso' ), |
|
| 2429 | + __('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.', 'event_espresso'), |
|
| 2430 | 2430 | $this->ID(), |
| 2431 | - get_class( $this->get_model() ) . '::instance()->add_to_entity_map()', |
|
| 2432 | - get_class( $this->get_model() ) . '::instance()->refresh_entity_map()' |
|
| 2431 | + get_class($this->get_model()).'::instance()->add_to_entity_map()', |
|
| 2432 | + get_class($this->get_model()).'::instance()->refresh_entity_map()' |
|
| 2433 | 2433 | ) |
| 2434 | 2434 | ); |
| 2435 | 2435 | } |
@@ -2443,11 +2443,11 @@ discard block |
||
| 2443 | 2443 | * (probably a bad assumption they have made, oh well) |
| 2444 | 2444 | * @return string |
| 2445 | 2445 | */ |
| 2446 | - public function __toString(){ |
|
| 2446 | + public function __toString() { |
|
| 2447 | 2447 | try { |
| 2448 | - return sprintf( '%s (%s)', $this->name(), $this->ID() ); |
|
| 2449 | - } catch ( Exception $e ) { |
|
| 2450 | - EE_Error::add_error( $e->getMessage(), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 2448 | + return sprintf('%s (%s)', $this->name(), $this->ID()); |
|
| 2449 | + } catch (Exception $e) { |
|
| 2450 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2451 | 2451 | return ''; |
| 2452 | 2452 | } |
| 2453 | 2453 | } |
@@ -2483,19 +2483,19 @@ discard block |
||
| 2483 | 2483 | * @throws \EE_Error |
| 2484 | 2484 | */ |
| 2485 | 2485 | public function __sleep() { |
| 2486 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
| 2487 | - if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
| 2488 | - $classname = 'EE_' . $this->get_model()->get_this_model_name(); |
|
| 2489 | - if( |
|
| 2490 | - $this->get_one_from_cache( $relation_name ) instanceof $classname |
|
| 2491 | - && $this->get_one_from_cache( $relation_name )->ID() |
|
| 2486 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 2487 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 2488 | + $classname = 'EE_'.$this->get_model()->get_this_model_name(); |
|
| 2489 | + if ( |
|
| 2490 | + $this->get_one_from_cache($relation_name) instanceof $classname |
|
| 2491 | + && $this->get_one_from_cache($relation_name)->ID() |
|
| 2492 | 2492 | ) { |
| 2493 | - $this->clear_cache( $relation_name, $this->get_one_from_cache( $relation_name )->ID() ); |
|
| 2493 | + $this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID()); |
|
| 2494 | 2494 | } |
| 2495 | 2495 | } |
| 2496 | 2496 | } |
| 2497 | 2497 | $this->_props_n_values_provided_in_constructor = array(); |
| 2498 | - return array_keys( get_object_vars( $this ) ); |
|
| 2498 | + return array_keys(get_object_vars($this)); |
|
| 2499 | 2499 | } |
| 2500 | 2500 | |
| 2501 | 2501 | |
@@ -76,11 +76,11 @@ discard block |
||
| 76 | 76 | protected $_cached_properties = array(); |
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | - * An array containing keys of the related model, and values are either an array of related mode objects or a single |
|
| 80 | - * related model object. see the model's _model_relations. The keys should match those specified. And if the relation |
|
| 81 | - * is of type EE_Belongs_To (or one of its children), then there should only be ONE related model object, all others have an array) |
|
| 82 | - * @var array |
|
| 83 | - */ |
|
| 79 | + * An array containing keys of the related model, and values are either an array of related mode objects or a single |
|
| 80 | + * related model object. see the model's _model_relations. The keys should match those specified. And if the relation |
|
| 81 | + * is of type EE_Belongs_To (or one of its children), then there should only be ONE related model object, all others have an array) |
|
| 82 | + * @var array |
|
| 83 | + */ |
|
| 84 | 84 | protected $_model_relations = array(); |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -1424,24 +1424,24 @@ discard block |
||
| 1424 | 1424 | * |
| 1425 | 1425 | * @throws \EE_Error |
| 1426 | 1426 | */ |
| 1427 | - public function refresh_cache_of_related_objects() { |
|
| 1428 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
| 1429 | - if( ! empty( $this->_model_relations[ $relation_name ] ) ) { |
|
| 1430 | - $related_objects = $this->_model_relations[ $relation_name ]; |
|
| 1431 | - if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
| 1432 | - //this relation only stores a single model object, not an array |
|
| 1433 | - //but let's make it consistent |
|
| 1434 | - $related_objects = array( $related_objects ); |
|
| 1435 | - } |
|
| 1436 | - foreach( $related_objects as $related_object ) { |
|
| 1437 | - //only refresh their cache if they're in memory |
|
| 1438 | - if( $related_object instanceof EE_Base_Class ) { |
|
| 1427 | + public function refresh_cache_of_related_objects() { |
|
| 1428 | + foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
| 1429 | + if( ! empty( $this->_model_relations[ $relation_name ] ) ) { |
|
| 1430 | + $related_objects = $this->_model_relations[ $relation_name ]; |
|
| 1431 | + if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
| 1432 | + //this relation only stores a single model object, not an array |
|
| 1433 | + //but let's make it consistent |
|
| 1434 | + $related_objects = array( $related_objects ); |
|
| 1435 | + } |
|
| 1436 | + foreach( $related_objects as $related_object ) { |
|
| 1437 | + //only refresh their cache if they're in memory |
|
| 1438 | + if( $related_object instanceof EE_Base_Class ) { |
|
| 1439 | 1439 | $related_object->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
| 1440 | - } |
|
| 1441 | - } |
|
| 1442 | - } |
|
| 1443 | - } |
|
| 1444 | - } |
|
| 1440 | + } |
|
| 1441 | + } |
|
| 1442 | + } |
|
| 1443 | + } |
|
| 1444 | + } |
|
| 1445 | 1445 | |
| 1446 | 1446 | |
| 1447 | 1447 | |
@@ -1682,7 +1682,7 @@ discard block |
||
| 1682 | 1682 | if ( self::_get_model( $classname )->has_primary_key_field() ) { |
| 1683 | 1683 | $primary_id_ref = self::_get_primary_key_name( $classname ); |
| 1684 | 1684 | if ( array_key_exists( $primary_id_ref, $props_n_values ) |
| 1685 | - && ! empty( $props_n_values[ $primary_id_ref ] ) |
|
| 1685 | + && ! empty( $props_n_values[ $primary_id_ref ] ) |
|
| 1686 | 1686 | ) { |
| 1687 | 1687 | $existing = self::_get_model( $classname, $timezone )->get_one_by_ID( |
| 1688 | 1688 | $props_n_values[ $primary_id_ref ] |
@@ -1834,9 +1834,9 @@ discard block |
||
| 1834 | 1834 | $otherObject = $this->get_model()->add_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values ); |
| 1835 | 1835 | //clear cache so future get_many_related and get_first_related() return new results. |
| 1836 | 1836 | $this->clear_cache( $relationName, $otherObject, TRUE ); |
| 1837 | - if( $otherObject instanceof EE_Base_Class ) { |
|
| 1838 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1839 | - } |
|
| 1837 | + if( $otherObject instanceof EE_Base_Class ) { |
|
| 1838 | + $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1839 | + } |
|
| 1840 | 1840 | } else { |
| 1841 | 1841 | //this thing doesn't exist in the DB, so just cache it |
| 1842 | 1842 | if( ! $otherObjectModelObjectOrID instanceof EE_Base_Class){ |
@@ -1850,18 +1850,18 @@ discard block |
||
| 1850 | 1850 | } |
| 1851 | 1851 | $this->cache( $relationName, $otherObjectModelObjectOrID, $cache_id ); |
| 1852 | 1852 | } |
| 1853 | - if( $otherObject instanceof EE_Base_Class ) { |
|
| 1854 | - //fix the reciprocal relation too |
|
| 1855 | - if( $otherObject->ID() ) { |
|
| 1856 | - //its saved so assumed relations exist in the DB, so we can just |
|
| 1857 | - //clear the cache so future queries use the updated info in the DB |
|
| 1858 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), null, true ); |
|
| 1859 | - } else { |
|
| 1860 | - |
|
| 1861 | - //it's not saved, so it caches relations like this |
|
| 1862 | - $otherObject->cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1863 | - } |
|
| 1864 | - } |
|
| 1853 | + if( $otherObject instanceof EE_Base_Class ) { |
|
| 1854 | + //fix the reciprocal relation too |
|
| 1855 | + if( $otherObject->ID() ) { |
|
| 1856 | + //its saved so assumed relations exist in the DB, so we can just |
|
| 1857 | + //clear the cache so future queries use the updated info in the DB |
|
| 1858 | + $otherObject->clear_cache( $this->get_model()->get_this_model_name(), null, true ); |
|
| 1859 | + } else { |
|
| 1860 | + |
|
| 1861 | + //it's not saved, so it caches relations like this |
|
| 1862 | + $otherObject->cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1863 | + } |
|
| 1864 | + } |
|
| 1865 | 1865 | return $otherObject; |
| 1866 | 1866 | } |
| 1867 | 1867 | |
@@ -1892,9 +1892,9 @@ discard block |
||
| 1892 | 1892 | //this doesn't exist in the DB, just remove it from the cache |
| 1893 | 1893 | $otherObject = $this->clear_cache( $relationName, $otherObjectModelObjectOrID ); |
| 1894 | 1894 | } |
| 1895 | - if( $otherObject instanceof EE_Base_Class ) { |
|
| 1896 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1897 | - } |
|
| 1895 | + if( $otherObject instanceof EE_Base_Class ) { |
|
| 1896 | + $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1897 | + } |
|
| 1898 | 1898 | return $otherObject; |
| 1899 | 1899 | } |
| 1900 | 1900 | |
@@ -1917,11 +1917,11 @@ discard block |
||
| 1917 | 1917 | //this doesn't exist in the DB, just remove it from the cache |
| 1918 | 1918 | $otherObjects = $this->clear_cache( $relationName, null, true ); |
| 1919 | 1919 | } |
| 1920 | - if( is_array( $otherObjects ) ) { |
|
| 1921 | - foreach ( $otherObjects as $otherObject ) { |
|
| 1922 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1923 | - } |
|
| 1924 | - } |
|
| 1920 | + if( is_array( $otherObjects ) ) { |
|
| 1921 | + foreach ( $otherObjects as $otherObject ) { |
|
| 1922 | + $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1923 | + } |
|
| 1924 | + } |
|
| 1925 | 1925 | return $otherObjects; |
| 1926 | 1926 | } |
| 1927 | 1927 | |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace EventEspresso\core\domain\entities; |
| 3 | 3 | |
| 4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 5 | - exit( 'No direct script access allowed' ); |
|
| 4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 5 | + exit('No direct script access allowed'); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
@@ -34,23 +34,23 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | |
| 36 | 36 | public function __toString() { |
| 37 | - return $this->format( DbSafeDateTime::db_safe_timestamp_format ); |
|
| 37 | + return $this->format(DbSafeDateTime::db_safe_timestamp_format); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 | |
| 42 | 42 | public function __sleep() { |
| 43 | - $this->_datetime_string = $this->format( DbSafeDateTime::db_safe_timestamp_format ); |
|
| 44 | - return array( '_datetime_string' ); |
|
| 43 | + $this->_datetime_string = $this->format(DbSafeDateTime::db_safe_timestamp_format); |
|
| 44 | + return array('_datetime_string'); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | |
| 48 | 48 | |
| 49 | 49 | public function __wakeup() { |
| 50 | - $date = \DateTime::createFromFormat( DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string ); |
|
| 50 | + $date = \DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string); |
|
| 51 | 51 | $this->__construct( |
| 52 | - $date->format( \EE_Datetime_Field::mysql_timestamp_format), |
|
| 53 | - new \DateTimeZone( $date->format( 'e' ) ) |
|
| 52 | + $date->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 53 | + new \DateTimeZone($date->format('e')) |
|
| 54 | 54 | ); |
| 55 | 55 | } |
| 56 | 56 | |
@@ -163,18 +163,18 @@ discard block |
||
| 163 | 163 | $this->{$var_name} = $session_setting; |
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | - // are we using encryption? |
|
| 167 | - $this->_use_encryption = $encryption instanceof EE_Encryption && EE_Registry::instance()->CFG->admin->encode_session_data(); |
|
| 168 | - // \EEH_Debug_Tools::printr($this->_use_encryption, '$this->_use_encryption', __FILE__, __LINE__); |
|
| 169 | - // encrypt data via: $this->encryption->encrypt(); |
|
| 170 | - $this->encryption = $encryption; |
|
| 166 | + // are we using encryption? |
|
| 167 | + $this->_use_encryption = $encryption instanceof EE_Encryption && EE_Registry::instance()->CFG->admin->encode_session_data(); |
|
| 168 | + // \EEH_Debug_Tools::printr($this->_use_encryption, '$this->_use_encryption', __FILE__, __LINE__); |
|
| 169 | + // encrypt data via: $this->encryption->encrypt(); |
|
| 170 | + $this->encryption = $encryption; |
|
| 171 | 171 | // filter hook allows outside functions/classes/plugins to change default empty cart |
| 172 | 172 | $extra_default_session_vars = apply_filters( 'FHEE__EE_Session__construct__extra_default_session_vars', array() ); |
| 173 | 173 | array_merge( $this->_default_session_vars, $extra_default_session_vars ); |
| 174 | 174 | // apply default session vars |
| 175 | 175 | $this->_set_defaults(); |
| 176 | - add_action('AHEE__EE_System__initialize', array($this, 'open_session')); |
|
| 177 | - // check request for 'clear_session' param |
|
| 176 | + add_action('AHEE__EE_System__initialize', array($this, 'open_session')); |
|
| 177 | + // check request for 'clear_session' param |
|
| 178 | 178 | add_action( 'AHEE__EE_Request_Handler__construct__complete', array( $this, 'wp_loaded' )); |
| 179 | 179 | // once everything is all said and done, |
| 180 | 180 | add_action( 'shutdown', array( $this, 'update' ), 100 ); |
@@ -184,18 +184,18 @@ discard block |
||
| 184 | 184 | |
| 185 | 185 | |
| 186 | 186 | |
| 187 | - /** |
|
| 188 | - * @return void |
|
| 189 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 190 | - * @throws \EE_Error |
|
| 191 | - */ |
|
| 187 | + /** |
|
| 188 | + * @return void |
|
| 189 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 190 | + * @throws \EE_Error |
|
| 191 | + */ |
|
| 192 | 192 | public function open_session() { |
| 193 | - // check for existing session and retrieve it from db |
|
| 194 | - if ( ! $this->_espresso_session()) { |
|
| 195 | - // or just start a new one |
|
| 196 | - $this->_create_espresso_session(); |
|
| 197 | - } |
|
| 198 | - } |
|
| 193 | + // check for existing session and retrieve it from db |
|
| 194 | + if ( ! $this->_espresso_session()) { |
|
| 195 | + // or just start a new one |
|
| 196 | + $this->_create_espresso_session(); |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -408,16 +408,16 @@ discard block |
||
| 408 | 408 | // set the "user agent" |
| 409 | 409 | $this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr( $_SERVER['HTTP_USER_AGENT'] ) : FALSE; |
| 410 | 410 | // now let's retrieve what's in the db |
| 411 | - $session_data = $this->_retrieve_session_data(); |
|
| 412 | - if (! empty($session_data)) { |
|
| 413 | - // get the current time in UTC |
|
| 411 | + $session_data = $this->_retrieve_session_data(); |
|
| 412 | + if (! empty($session_data)) { |
|
| 413 | + // get the current time in UTC |
|
| 414 | 414 | $this->_time = isset( $this->_time ) ? $this->_time : time(); |
| 415 | 415 | // and reset the session expiration |
| 416 | 416 | $this->_expiration = isset( $session_data['expiration'] ) |
| 417 | 417 | ? $session_data['expiration'] |
| 418 | 418 | : $this->_time + $this->_lifespan; |
| 419 | 419 | } else { |
| 420 | - // set initial site access time and the session expiration |
|
| 420 | + // set initial site access time and the session expiration |
|
| 421 | 421 | $this->_set_init_access_and_expiration(); |
| 422 | 422 | // set referer |
| 423 | 423 | $this->_session_data[ 'pages_visited' ][ $this->_session_data['init_access'] ] = isset( $_SERVER['HTTP_REFERER'] ) |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | // no previous session = go back and create one (on top of the data above) |
| 427 | 427 | return FALSE; |
| 428 | 428 | } |
| 429 | - // now the user agent |
|
| 429 | + // now the user agent |
|
| 430 | 430 | if ( $session_data['user_agent'] !== $this->_user_agent ) { |
| 431 | 431 | return FALSE; |
| 432 | 432 | } |
@@ -444,95 +444,95 @@ discard block |
||
| 444 | 444 | |
| 445 | 445 | |
| 446 | 446 | |
| 447 | - /** |
|
| 448 | - * _get_session_data |
|
| 449 | - * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup databases |
|
| 450 | - * |
|
| 451 | - * @return array |
|
| 452 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 453 | - */ |
|
| 454 | - protected function _retrieve_session_data() |
|
| 455 | - { |
|
| 456 | - $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
| 457 | - try { |
|
| 458 | - // we're using WP's Transient API to store session data using the PHP session ID as the option name |
|
| 459 | - $session_data = get_transient($ssn_key); |
|
| 460 | - if ($session_data === false) { |
|
| 461 | - return array(); |
|
| 462 | - } |
|
| 463 | - if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
| 464 | - $hash_check = get_transient(EE_Session::hash_check_prefix . $this->_sid); |
|
| 465 | - if ($hash_check && $hash_check !== md5($session_data)) { |
|
| 466 | - EE_Error::add_error( |
|
| 467 | - sprintf( |
|
| 468 | - __('The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', 'event_espresso'), |
|
| 469 | - EE_Session::session_id_prefix . $this->_sid |
|
| 470 | - ), |
|
| 471 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 472 | - ); |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - } catch (Exception $e) { |
|
| 476 | - // let's just eat that error for now and attempt to correct any corrupted data |
|
| 477 | - global $wpdb; |
|
| 478 | - $row = $wpdb->get_row( |
|
| 479 | - $wpdb->prepare( |
|
| 480 | - "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
|
| 481 | - '_transient_' . $ssn_key |
|
| 482 | - ) |
|
| 483 | - ); |
|
| 484 | - $session_data = is_object($row) ? $row->option_value : null; |
|
| 485 | - if ($session_data) { |
|
| 486 | - $session_data = preg_replace_callback( |
|
| 487 | - '!s:(d+):"(.*?)";!', |
|
| 488 | - function ($match) { |
|
| 489 | - return $match[1] === strlen($match[2]) |
|
| 490 | - ? $match[0] |
|
| 491 | - : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
| 492 | - }, |
|
| 493 | - $session_data |
|
| 494 | - ); |
|
| 495 | - } |
|
| 496 | - $session_data = maybe_unserialize($session_data); |
|
| 497 | - } |
|
| 498 | - // in case the data is encoded... try to decode it |
|
| 499 | - $session_data = $this->encryption instanceof EE_Encryption |
|
| 500 | - ? $this->encryption->base64_string_decode($session_data) |
|
| 501 | - : $session_data; |
|
| 502 | - |
|
| 503 | - if ( ! is_array($session_data)) { |
|
| 504 | - try { |
|
| 505 | - $session_data = maybe_unserialize($session_data); |
|
| 506 | - } catch (Exception $e) { |
|
| 507 | - $msg = esc_html__( |
|
| 508 | - 'An error occurred while attempting to unserialize the session data.', |
|
| 509 | - 'event_espresso' |
|
| 510 | - ); |
|
| 511 | - $msg .= WP_DEBUG |
|
| 512 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
| 513 | - : ''; |
|
| 514 | - throw new InvalidSessionDataException($msg, 0, $e); |
|
| 515 | - } |
|
| 516 | - } |
|
| 517 | - // just a check to make sure the session array is indeed an array |
|
| 518 | - if ( ! is_array($session_data)) { |
|
| 519 | - // no?!?! then something is wrong |
|
| 520 | - $msg = esc_html__( |
|
| 521 | - 'The session data is missing, invalid, or corrupted.', |
|
| 522 | - 'event_espresso' |
|
| 523 | - ); |
|
| 524 | - $msg .= WP_DEBUG |
|
| 525 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
| 526 | - : ''; |
|
| 527 | - throw new InvalidSessionDataException($msg); |
|
| 528 | - } |
|
| 529 | - if ( isset( $this->_session_data['transaction'] ) && absint( $this->_session_data['transaction'] ) !== 0 ) { |
|
| 530 | - $this->_session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID( |
|
| 531 | - $this->_session_data['transaction'] |
|
| 532 | - ); |
|
| 533 | - } |
|
| 534 | - return $session_data; |
|
| 535 | - } |
|
| 447 | + /** |
|
| 448 | + * _get_session_data |
|
| 449 | + * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup databases |
|
| 450 | + * |
|
| 451 | + * @return array |
|
| 452 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 453 | + */ |
|
| 454 | + protected function _retrieve_session_data() |
|
| 455 | + { |
|
| 456 | + $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
| 457 | + try { |
|
| 458 | + // we're using WP's Transient API to store session data using the PHP session ID as the option name |
|
| 459 | + $session_data = get_transient($ssn_key); |
|
| 460 | + if ($session_data === false) { |
|
| 461 | + return array(); |
|
| 462 | + } |
|
| 463 | + if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
| 464 | + $hash_check = get_transient(EE_Session::hash_check_prefix . $this->_sid); |
|
| 465 | + if ($hash_check && $hash_check !== md5($session_data)) { |
|
| 466 | + EE_Error::add_error( |
|
| 467 | + sprintf( |
|
| 468 | + __('The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', 'event_espresso'), |
|
| 469 | + EE_Session::session_id_prefix . $this->_sid |
|
| 470 | + ), |
|
| 471 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 472 | + ); |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + } catch (Exception $e) { |
|
| 476 | + // let's just eat that error for now and attempt to correct any corrupted data |
|
| 477 | + global $wpdb; |
|
| 478 | + $row = $wpdb->get_row( |
|
| 479 | + $wpdb->prepare( |
|
| 480 | + "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
|
| 481 | + '_transient_' . $ssn_key |
|
| 482 | + ) |
|
| 483 | + ); |
|
| 484 | + $session_data = is_object($row) ? $row->option_value : null; |
|
| 485 | + if ($session_data) { |
|
| 486 | + $session_data = preg_replace_callback( |
|
| 487 | + '!s:(d+):"(.*?)";!', |
|
| 488 | + function ($match) { |
|
| 489 | + return $match[1] === strlen($match[2]) |
|
| 490 | + ? $match[0] |
|
| 491 | + : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
| 492 | + }, |
|
| 493 | + $session_data |
|
| 494 | + ); |
|
| 495 | + } |
|
| 496 | + $session_data = maybe_unserialize($session_data); |
|
| 497 | + } |
|
| 498 | + // in case the data is encoded... try to decode it |
|
| 499 | + $session_data = $this->encryption instanceof EE_Encryption |
|
| 500 | + ? $this->encryption->base64_string_decode($session_data) |
|
| 501 | + : $session_data; |
|
| 502 | + |
|
| 503 | + if ( ! is_array($session_data)) { |
|
| 504 | + try { |
|
| 505 | + $session_data = maybe_unserialize($session_data); |
|
| 506 | + } catch (Exception $e) { |
|
| 507 | + $msg = esc_html__( |
|
| 508 | + 'An error occurred while attempting to unserialize the session data.', |
|
| 509 | + 'event_espresso' |
|
| 510 | + ); |
|
| 511 | + $msg .= WP_DEBUG |
|
| 512 | + ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
| 513 | + : ''; |
|
| 514 | + throw new InvalidSessionDataException($msg, 0, $e); |
|
| 515 | + } |
|
| 516 | + } |
|
| 517 | + // just a check to make sure the session array is indeed an array |
|
| 518 | + if ( ! is_array($session_data)) { |
|
| 519 | + // no?!?! then something is wrong |
|
| 520 | + $msg = esc_html__( |
|
| 521 | + 'The session data is missing, invalid, or corrupted.', |
|
| 522 | + 'event_espresso' |
|
| 523 | + ); |
|
| 524 | + $msg .= WP_DEBUG |
|
| 525 | + ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
| 526 | + : ''; |
|
| 527 | + throw new InvalidSessionDataException($msg); |
|
| 528 | + } |
|
| 529 | + if ( isset( $this->_session_data['transaction'] ) && absint( $this->_session_data['transaction'] ) !== 0 ) { |
|
| 530 | + $this->_session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID( |
|
| 531 | + $this->_session_data['transaction'] |
|
| 532 | + ); |
|
| 533 | + } |
|
| 534 | + return $session_data; |
|
| 535 | + } |
|
| 536 | 536 | |
| 537 | 537 | |
| 538 | 538 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\exceptions\InvalidSessionDataException; |
| 2 | 2 | |
| 3 | -if (!defined( 'EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');} |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); } |
|
| 4 | 4 | /** |
| 5 | 5 | * |
| 6 | 6 | * EE_Session class |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * array for defining default session vars |
| 92 | 92 | * @var array |
| 93 | 93 | */ |
| 94 | - private $_default_session_vars = array ( |
|
| 94 | + private $_default_session_vars = array( |
|
| 95 | 95 | 'id' => NULL, |
| 96 | 96 | 'user_id' => NULL, |
| 97 | 97 | 'ip_address' => NULL, |
@@ -111,12 +111,12 @@ discard block |
||
| 111 | 111 | * @throws InvalidSessionDataException |
| 112 | 112 | * @throws \EE_Error |
| 113 | 113 | */ |
| 114 | - public static function instance( EE_Encryption $encryption = null ) { |
|
| 114 | + public static function instance(EE_Encryption $encryption = null) { |
|
| 115 | 115 | // check if class object is instantiated |
| 116 | 116 | // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
| 117 | 117 | // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
| 118 | - if ( ! self::$_instance instanceof EE_Session && apply_filters( 'FHEE_load_EE_Session', true ) ) { |
|
| 119 | - self::$_instance = new self( $encryption ); |
|
| 118 | + if ( ! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
| 119 | + self::$_instance = new self($encryption); |
|
| 120 | 120 | } |
| 121 | 121 | return self::$_instance; |
| 122 | 122 | } |
@@ -132,15 +132,15 @@ discard block |
||
| 132 | 132 | * @throws \EE_Error |
| 133 | 133 | * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
| 134 | 134 | */ |
| 135 | - protected function __construct( EE_Encryption $encryption = null ) { |
|
| 135 | + protected function __construct(EE_Encryption $encryption = null) { |
|
| 136 | 136 | |
| 137 | 137 | // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
| 138 | - if ( ! apply_filters( 'FHEE_load_EE_Session', TRUE ) ) { |
|
| 138 | + if ( ! apply_filters('FHEE_load_EE_Session', TRUE)) { |
|
| 139 | 139 | return; |
| 140 | 140 | } |
| 141 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 142 | - if ( ! defined( 'ESPRESSO_SESSION' ) ) { |
|
| 143 | - define( 'ESPRESSO_SESSION', true ); |
|
| 141 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 142 | + if ( ! defined('ESPRESSO_SESSION')) { |
|
| 143 | + define('ESPRESSO_SESSION', true); |
|
| 144 | 144 | } |
| 145 | 145 | // default session lifespan in seconds |
| 146 | 146 | $this->_lifespan = apply_filters( |
@@ -154,12 +154,12 @@ discard block |
||
| 154 | 154 | * } |
| 155 | 155 | */ |
| 156 | 156 | // retrieve session options from db |
| 157 | - $session_settings = (array) get_option( 'ee_session_settings', array() ); |
|
| 158 | - if ( ! empty( $session_settings )) { |
|
| 157 | + $session_settings = (array) get_option('ee_session_settings', array()); |
|
| 158 | + if ( ! empty($session_settings)) { |
|
| 159 | 159 | // cycle though existing session options |
| 160 | - foreach ( $session_settings as $var_name => $session_setting ) { |
|
| 160 | + foreach ($session_settings as $var_name => $session_setting) { |
|
| 161 | 161 | // set values for class properties |
| 162 | - $var_name = '_' . $var_name; |
|
| 162 | + $var_name = '_'.$var_name; |
|
| 163 | 163 | $this->{$var_name} = $session_setting; |
| 164 | 164 | } |
| 165 | 165 | } |
@@ -169,17 +169,17 @@ discard block |
||
| 169 | 169 | // encrypt data via: $this->encryption->encrypt(); |
| 170 | 170 | $this->encryption = $encryption; |
| 171 | 171 | // filter hook allows outside functions/classes/plugins to change default empty cart |
| 172 | - $extra_default_session_vars = apply_filters( 'FHEE__EE_Session__construct__extra_default_session_vars', array() ); |
|
| 173 | - array_merge( $this->_default_session_vars, $extra_default_session_vars ); |
|
| 172 | + $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array()); |
|
| 173 | + array_merge($this->_default_session_vars, $extra_default_session_vars); |
|
| 174 | 174 | // apply default session vars |
| 175 | 175 | $this->_set_defaults(); |
| 176 | 176 | add_action('AHEE__EE_System__initialize', array($this, 'open_session')); |
| 177 | 177 | // check request for 'clear_session' param |
| 178 | - add_action( 'AHEE__EE_Request_Handler__construct__complete', array( $this, 'wp_loaded' )); |
|
| 178 | + add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded')); |
|
| 179 | 179 | // once everything is all said and done, |
| 180 | - add_action( 'shutdown', array( $this, 'update' ), 100 ); |
|
| 181 | - add_action( 'shutdown', array( $this, 'garbage_collection' ), 999 ); |
|
| 182 | - add_filter( 'wp_redirect', array( $this, 'update_on_redirect' ), 100, 1 ); |
|
| 180 | + add_action('shutdown', array($this, 'update'), 100); |
|
| 181 | + add_action('shutdown', array($this, 'garbage_collection'), 999); |
|
| 182 | + add_filter('wp_redirect', array($this, 'update_on_redirect'), 100, 1); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | |
@@ -224,11 +224,11 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | private function _set_defaults() { |
| 226 | 226 | // set some defaults |
| 227 | - foreach ( $this->_default_session_vars as $key => $default_var ) { |
|
| 228 | - if ( is_array( $default_var )) { |
|
| 229 | - $this->_session_data[ $key ] = array(); |
|
| 227 | + foreach ($this->_default_session_vars as $key => $default_var) { |
|
| 228 | + if (is_array($default_var)) { |
|
| 229 | + $this->_session_data[$key] = array(); |
|
| 230 | 230 | } else { |
| 231 | - $this->_session_data[ $key ] = ''; |
|
| 231 | + $this->_session_data[$key] = ''; |
|
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | 234 | } |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * @param \EE_Cart $cart |
| 251 | 251 | * @return bool |
| 252 | 252 | */ |
| 253 | - public function set_cart( EE_Cart $cart ) { |
|
| 253 | + public function set_cart(EE_Cart $cart) { |
|
| 254 | 254 | $this->_session_data['cart'] = $cart; |
| 255 | 255 | return TRUE; |
| 256 | 256 | } |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * @return \EE_Cart |
| 271 | 271 | */ |
| 272 | 272 | public function cart() { |
| 273 | - return isset( $this->_session_data['cart'] ) ? $this->_session_data['cart'] : NULL; |
|
| 273 | + return isset($this->_session_data['cart']) ? $this->_session_data['cart'] : NULL; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | * @param \EE_Checkout $checkout |
| 280 | 280 | * @return bool |
| 281 | 281 | */ |
| 282 | - public function set_checkout( EE_Checkout $checkout ) { |
|
| 282 | + public function set_checkout(EE_Checkout $checkout) { |
|
| 283 | 283 | $this->_session_data['checkout'] = $checkout; |
| 284 | 284 | return TRUE; |
| 285 | 285 | } |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @return \EE_Checkout |
| 300 | 300 | */ |
| 301 | 301 | public function checkout() { |
| 302 | - return isset( $this->_session_data['checkout'] ) ? $this->_session_data['checkout'] : NULL; |
|
| 302 | + return isset($this->_session_data['checkout']) ? $this->_session_data['checkout'] : NULL; |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | |
@@ -309,9 +309,9 @@ discard block |
||
| 309 | 309 | * @return bool |
| 310 | 310 | * @throws \EE_Error |
| 311 | 311 | */ |
| 312 | - public function set_transaction( EE_Transaction $transaction ) { |
|
| 312 | + public function set_transaction(EE_Transaction $transaction) { |
|
| 313 | 313 | // first remove the session from the transaction before we save the transaction in the session |
| 314 | - $transaction->set_txn_session_data( NULL ); |
|
| 314 | + $transaction->set_txn_session_data(NULL); |
|
| 315 | 315 | $this->_session_data['transaction'] = $transaction; |
| 316 | 316 | return TRUE; |
| 317 | 317 | } |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | * @return \EE_Transaction |
| 332 | 332 | */ |
| 333 | 333 | public function transaction() { |
| 334 | - return isset( $this->_session_data['transaction'] ) ? $this->_session_data['transaction'] : NULL; |
|
| 334 | + return isset($this->_session_data['transaction']) ? $this->_session_data['transaction'] : NULL; |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | |
@@ -343,15 +343,15 @@ discard block |
||
| 343 | 343 | * @param bool $reset_cache |
| 344 | 344 | * @return array |
| 345 | 345 | */ |
| 346 | - public function get_session_data( $key = NULL, $reset_cache = FALSE ) { |
|
| 347 | - if ( $reset_cache ) { |
|
| 346 | + public function get_session_data($key = NULL, $reset_cache = FALSE) { |
|
| 347 | + if ($reset_cache) { |
|
| 348 | 348 | $this->reset_cart(); |
| 349 | 349 | $this->reset_checkout(); |
| 350 | 350 | $this->reset_transaction(); |
| 351 | 351 | } |
| 352 | - if ( ! empty( $key )) { |
|
| 353 | - return isset( $this->_session_data[ $key ] ) ? $this->_session_data[ $key ] : NULL; |
|
| 354 | - } else { |
|
| 352 | + if ( ! empty($key)) { |
|
| 353 | + return isset($this->_session_data[$key]) ? $this->_session_data[$key] : NULL; |
|
| 354 | + } else { |
|
| 355 | 355 | return $this->_session_data; |
| 356 | 356 | } |
| 357 | 357 | } |
@@ -364,20 +364,20 @@ discard block |
||
| 364 | 364 | * @param array $data |
| 365 | 365 | * @return TRUE on success, FALSE on fail |
| 366 | 366 | */ |
| 367 | - public function set_session_data( $data ) { |
|
| 367 | + public function set_session_data($data) { |
|
| 368 | 368 | |
| 369 | 369 | // nothing ??? bad data ??? go home! |
| 370 | - if ( empty( $data ) || ! is_array( $data )) { |
|
| 371 | - EE_Error::add_error( __( 'No session data or invalid session data was provided.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 370 | + if (empty($data) || ! is_array($data)) { |
|
| 371 | + EE_Error::add_error(__('No session data or invalid session data was provided.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 372 | 372 | return FALSE; |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - foreach ( $data as $key =>$value ) { |
|
| 376 | - if ( isset( $this->_default_session_vars[ $key ] )) { |
|
| 377 | - EE_Error::add_error( sprintf( __( 'Sorry! %s is a default session datum and can not be reset.', 'event_espresso' ), $key ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 375 | + foreach ($data as $key =>$value) { |
|
| 376 | + if (isset($this->_default_session_vars[$key])) { |
|
| 377 | + EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', 'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__); |
|
| 378 | 378 | return FALSE; |
| 379 | 379 | } else { |
| 380 | - $this->_session_data[ $key ] = $value; |
|
| 380 | + $this->_session_data[$key] = $value; |
|
| 381 | 381 | } |
| 382 | 382 | } |
| 383 | 383 | |
@@ -395,9 +395,9 @@ discard block |
||
| 395 | 395 | * @throws \EE_Error |
| 396 | 396 | */ |
| 397 | 397 | private function _espresso_session() { |
| 398 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 398 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 399 | 399 | // check that session has started |
| 400 | - if ( session_id() === '' ) { |
|
| 400 | + if (session_id() === '') { |
|
| 401 | 401 | //starts a new session if one doesn't already exist, or re-initiates an existing one |
| 402 | 402 | session_start(); |
| 403 | 403 | } |
@@ -406,38 +406,38 @@ discard block |
||
| 406 | 406 | // and the visitors IP |
| 407 | 407 | $this->_ip_address = $this->_visitor_ip(); |
| 408 | 408 | // set the "user agent" |
| 409 | - $this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr( $_SERVER['HTTP_USER_AGENT'] ) : FALSE; |
|
| 409 | + $this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr($_SERVER['HTTP_USER_AGENT']) : FALSE; |
|
| 410 | 410 | // now let's retrieve what's in the db |
| 411 | 411 | $session_data = $this->_retrieve_session_data(); |
| 412 | - if (! empty($session_data)) { |
|
| 412 | + if ( ! empty($session_data)) { |
|
| 413 | 413 | // get the current time in UTC |
| 414 | - $this->_time = isset( $this->_time ) ? $this->_time : time(); |
|
| 414 | + $this->_time = isset($this->_time) ? $this->_time : time(); |
|
| 415 | 415 | // and reset the session expiration |
| 416 | - $this->_expiration = isset( $session_data['expiration'] ) |
|
| 416 | + $this->_expiration = isset($session_data['expiration']) |
|
| 417 | 417 | ? $session_data['expiration'] |
| 418 | 418 | : $this->_time + $this->_lifespan; |
| 419 | 419 | } else { |
| 420 | 420 | // set initial site access time and the session expiration |
| 421 | 421 | $this->_set_init_access_and_expiration(); |
| 422 | 422 | // set referer |
| 423 | - $this->_session_data[ 'pages_visited' ][ $this->_session_data['init_access'] ] = isset( $_SERVER['HTTP_REFERER'] ) |
|
| 424 | - ? esc_attr( $_SERVER['HTTP_REFERER'] ) |
|
| 423 | + $this->_session_data['pages_visited'][$this->_session_data['init_access']] = isset($_SERVER['HTTP_REFERER']) |
|
| 424 | + ? esc_attr($_SERVER['HTTP_REFERER']) |
|
| 425 | 425 | : ''; |
| 426 | 426 | // no previous session = go back and create one (on top of the data above) |
| 427 | 427 | return FALSE; |
| 428 | 428 | } |
| 429 | 429 | // now the user agent |
| 430 | - if ( $session_data['user_agent'] !== $this->_user_agent ) { |
|
| 430 | + if ($session_data['user_agent'] !== $this->_user_agent) { |
|
| 431 | 431 | return FALSE; |
| 432 | 432 | } |
| 433 | 433 | // wait a minute... how old are you? |
| 434 | - if ( $this->_time > $this->_expiration ) { |
|
| 434 | + if ($this->_time > $this->_expiration) { |
|
| 435 | 435 | // yer too old fer me! |
| 436 | 436 | // wipe out everything that isn't a default session datum |
| 437 | - $this->clear_session( __CLASS__, __FUNCTION__ ); |
|
| 437 | + $this->clear_session(__CLASS__, __FUNCTION__); |
|
| 438 | 438 | } |
| 439 | 439 | // make event espresso session data available to plugin |
| 440 | - $this->_session_data = array_merge( $this->_session_data, $session_data ); |
|
| 440 | + $this->_session_data = array_merge($this->_session_data, $session_data); |
|
| 441 | 441 | return TRUE; |
| 442 | 442 | |
| 443 | 443 | } |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | */ |
| 454 | 454 | protected function _retrieve_session_data() |
| 455 | 455 | { |
| 456 | - $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
| 456 | + $ssn_key = EE_Session::session_id_prefix.$this->_sid; |
|
| 457 | 457 | try { |
| 458 | 458 | // we're using WP's Transient API to store session data using the PHP session ID as the option name |
| 459 | 459 | $session_data = get_transient($ssn_key); |
@@ -461,12 +461,12 @@ discard block |
||
| 461 | 461 | return array(); |
| 462 | 462 | } |
| 463 | 463 | if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
| 464 | - $hash_check = get_transient(EE_Session::hash_check_prefix . $this->_sid); |
|
| 464 | + $hash_check = get_transient(EE_Session::hash_check_prefix.$this->_sid); |
|
| 465 | 465 | if ($hash_check && $hash_check !== md5($session_data)) { |
| 466 | 466 | EE_Error::add_error( |
| 467 | 467 | sprintf( |
| 468 | 468 | __('The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', 'event_espresso'), |
| 469 | - EE_Session::session_id_prefix . $this->_sid |
|
| 469 | + EE_Session::session_id_prefix.$this->_sid |
|
| 470 | 470 | ), |
| 471 | 471 | __FILE__, __FUNCTION__, __LINE__ |
| 472 | 472 | ); |
@@ -478,17 +478,17 @@ discard block |
||
| 478 | 478 | $row = $wpdb->get_row( |
| 479 | 479 | $wpdb->prepare( |
| 480 | 480 | "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
| 481 | - '_transient_' . $ssn_key |
|
| 481 | + '_transient_'.$ssn_key |
|
| 482 | 482 | ) |
| 483 | 483 | ); |
| 484 | 484 | $session_data = is_object($row) ? $row->option_value : null; |
| 485 | 485 | if ($session_data) { |
| 486 | 486 | $session_data = preg_replace_callback( |
| 487 | 487 | '!s:(d+):"(.*?)";!', |
| 488 | - function ($match) { |
|
| 488 | + function($match) { |
|
| 489 | 489 | return $match[1] === strlen($match[2]) |
| 490 | 490 | ? $match[0] |
| 491 | - : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
| 491 | + : 's:'.strlen($match[2]).':"'.$match[2].'";'; |
|
| 492 | 492 | }, |
| 493 | 493 | $session_data |
| 494 | 494 | ); |
@@ -509,7 +509,7 @@ discard block |
||
| 509 | 509 | 'event_espresso' |
| 510 | 510 | ); |
| 511 | 511 | $msg .= WP_DEBUG |
| 512 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
| 512 | + ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data) |
|
| 513 | 513 | : ''; |
| 514 | 514 | throw new InvalidSessionDataException($msg, 0, $e); |
| 515 | 515 | } |
@@ -522,11 +522,11 @@ discard block |
||
| 522 | 522 | 'event_espresso' |
| 523 | 523 | ); |
| 524 | 524 | $msg .= WP_DEBUG |
| 525 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
| 525 | + ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data) |
|
| 526 | 526 | : ''; |
| 527 | 527 | throw new InvalidSessionDataException($msg); |
| 528 | 528 | } |
| 529 | - if ( isset( $this->_session_data['transaction'] ) && absint( $this->_session_data['transaction'] ) !== 0 ) { |
|
| 529 | + if (isset($this->_session_data['transaction']) && absint($this->_session_data['transaction']) !== 0) { |
|
| 530 | 530 | $this->_session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID( |
| 531 | 531 | $this->_session_data['transaction'] |
| 532 | 532 | ); |
@@ -547,12 +547,12 @@ discard block |
||
| 547 | 547 | */ |
| 548 | 548 | protected function _generate_session_id() { |
| 549 | 549 | // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length |
| 550 | - if ( isset( $_REQUEST[ 'EESID' ] ) ) { |
|
| 551 | - $session_id = sanitize_text_field( $_REQUEST[ 'EESID' ] ); |
|
| 550 | + if (isset($_REQUEST['EESID'])) { |
|
| 551 | + $session_id = sanitize_text_field($_REQUEST['EESID']); |
|
| 552 | 552 | } else { |
| 553 | - $session_id = md5( session_id() . get_current_blog_id() . $this->_get_sid_salt() ); |
|
| 553 | + $session_id = md5(session_id().get_current_blog_id().$this->_get_sid_salt()); |
|
| 554 | 554 | } |
| 555 | - return apply_filters( 'FHEE__EE_Session___generate_session_id__session_id', $session_id ); |
|
| 555 | + return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
|
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | |
@@ -564,20 +564,20 @@ discard block |
||
| 564 | 564 | */ |
| 565 | 565 | protected function _get_sid_salt() { |
| 566 | 566 | // was session id salt already saved to db ? |
| 567 | - if ( empty( $this->_sid_salt ) ) { |
|
| 567 | + if (empty($this->_sid_salt)) { |
|
| 568 | 568 | // no? then maybe use WP defined constant |
| 569 | - if ( defined( 'AUTH_SALT' ) ) { |
|
| 569 | + if (defined('AUTH_SALT')) { |
|
| 570 | 570 | $this->_sid_salt = AUTH_SALT; |
| 571 | 571 | } |
| 572 | 572 | // if salt doesn't exist or is too short |
| 573 | - if ( empty( $this->_sid_salt ) || strlen( $this->_sid_salt ) < 32 ) { |
|
| 573 | + if (empty($this->_sid_salt) || strlen($this->_sid_salt) < 32) { |
|
| 574 | 574 | // create a new one |
| 575 | - $this->_sid_salt = wp_generate_password( 64 ); |
|
| 575 | + $this->_sid_salt = wp_generate_password(64); |
|
| 576 | 576 | } |
| 577 | 577 | // and save it as a permanent session setting |
| 578 | - $session_settings = get_option( 'ee_session_settings' ); |
|
| 579 | - $session_settings[ 'sid_salt' ] = $this->_sid_salt; |
|
| 580 | - update_option( 'ee_session_settings', $session_settings ); |
|
| 578 | + $session_settings = get_option('ee_session_settings'); |
|
| 579 | + $session_settings['sid_salt'] = $this->_sid_salt; |
|
| 580 | + update_option('ee_session_settings', $session_settings); |
|
| 581 | 581 | } |
| 582 | 582 | return $this->_sid_salt; |
| 583 | 583 | } |
@@ -605,19 +605,19 @@ discard block |
||
| 605 | 605 | * @param bool $new_session |
| 606 | 606 | * @return TRUE on success, FALSE on fail |
| 607 | 607 | */ |
| 608 | - public function update( $new_session = FALSE ) { |
|
| 609 | - $this->_session_data = isset( $this->_session_data ) |
|
| 610 | - && is_array( $this->_session_data ) |
|
| 611 | - && isset( $this->_session_data['id']) |
|
| 608 | + public function update($new_session = FALSE) { |
|
| 609 | + $this->_session_data = isset($this->_session_data) |
|
| 610 | + && is_array($this->_session_data) |
|
| 611 | + && isset($this->_session_data['id']) |
|
| 612 | 612 | ? $this->_session_data |
| 613 | 613 | : array(); |
| 614 | - if ( empty( $this->_session_data )) { |
|
| 614 | + if (empty($this->_session_data)) { |
|
| 615 | 615 | $this->_set_defaults(); |
| 616 | 616 | } |
| 617 | 617 | $session_data = array(); |
| 618 | - foreach ( $this->_session_data as $key => $value ) { |
|
| 618 | + foreach ($this->_session_data as $key => $value) { |
|
| 619 | 619 | |
| 620 | - switch( $key ) { |
|
| 620 | + switch ($key) { |
|
| 621 | 621 | |
| 622 | 622 | case 'id' : |
| 623 | 623 | // session ID |
@@ -635,7 +635,7 @@ discard block |
||
| 635 | 635 | break; |
| 636 | 636 | |
| 637 | 637 | case 'init_access' : |
| 638 | - $session_data['init_access'] = absint( $value ); |
|
| 638 | + $session_data['init_access'] = absint($value); |
|
| 639 | 639 | break; |
| 640 | 640 | |
| 641 | 641 | case 'last_access' : |
@@ -645,7 +645,7 @@ discard block |
||
| 645 | 645 | |
| 646 | 646 | case 'expiration' : |
| 647 | 647 | // when the session expires |
| 648 | - $session_data['expiration'] = ! empty( $this->_expiration ) |
|
| 648 | + $session_data['expiration'] = ! empty($this->_expiration) |
|
| 649 | 649 | ? $this->_expiration |
| 650 | 650 | : $session_data['init_access'] + $this->_lifespan; |
| 651 | 651 | break; |
@@ -657,11 +657,11 @@ discard block |
||
| 657 | 657 | |
| 658 | 658 | case 'pages_visited' : |
| 659 | 659 | $page_visit = $this->_get_page_visit(); |
| 660 | - if ( $page_visit ) { |
|
| 660 | + if ($page_visit) { |
|
| 661 | 661 | // set pages visited where the first will be the http referrer |
| 662 | - $this->_session_data[ 'pages_visited' ][ $this->_time ] = $page_visit; |
|
| 662 | + $this->_session_data['pages_visited'][$this->_time] = $page_visit; |
|
| 663 | 663 | // we'll only save the last 10 page visits. |
| 664 | - $session_data[ 'pages_visited' ] = array_slice( $this->_session_data['pages_visited'], -10 ); |
|
| 664 | + $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
|
| 665 | 665 | } |
| 666 | 666 | break; |
| 667 | 667 | |
@@ -675,9 +675,9 @@ discard block |
||
| 675 | 675 | |
| 676 | 676 | $this->_session_data = $session_data; |
| 677 | 677 | // creating a new session does not require saving to the db just yet |
| 678 | - if ( ! $new_session ) { |
|
| 678 | + if ( ! $new_session) { |
|
| 679 | 679 | // ready? let's save |
| 680 | - if ( $this->_save_session_to_db() ) { |
|
| 680 | + if ($this->_save_session_to_db()) { |
|
| 681 | 681 | return TRUE; |
| 682 | 682 | } else { |
| 683 | 683 | return FALSE; |
@@ -699,7 +699,7 @@ discard block |
||
| 699 | 699 | * @param string $location |
| 700 | 700 | * @return mixed |
| 701 | 701 | */ |
| 702 | - public function update_on_redirect( $location ) { |
|
| 702 | + public function update_on_redirect($location) { |
|
| 703 | 703 | $this->update(); |
| 704 | 704 | return $location; |
| 705 | 705 | } |
@@ -711,9 +711,9 @@ discard block |
||
| 711 | 711 | * @return bool |
| 712 | 712 | */ |
| 713 | 713 | private function _create_espresso_session( ) { |
| 714 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__, '' ); |
|
| 714 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, ''); |
|
| 715 | 715 | // use the update function for now with $new_session arg set to TRUE |
| 716 | - return $this->update( TRUE ) ? TRUE : FALSE; |
|
| 716 | + return $this->update(TRUE) ? TRUE : FALSE; |
|
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | |
@@ -739,15 +739,15 @@ discard block |
||
| 739 | 739 | // OR an admin request that is NOT AJAX |
| 740 | 740 | || ( |
| 741 | 741 | is_admin() |
| 742 | - && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
|
| 742 | + && ! (defined('DOING_AJAX') && DOING_AJAX) |
|
| 743 | 743 | ) |
| 744 | 744 | ) |
| 745 | 745 | ) { |
| 746 | 746 | return false; |
| 747 | 747 | } |
| 748 | 748 | $transaction = $this->_session_data['transaction']; |
| 749 | - if ( $transaction instanceof EE_Transaction ) { |
|
| 750 | - if ( ! $transaction->ID() ) { |
|
| 749 | + if ($transaction instanceof EE_Transaction) { |
|
| 750 | + if ( ! $transaction->ID()) { |
|
| 751 | 751 | $transaction->save(); |
| 752 | 752 | } |
| 753 | 753 | $this->_session_data['transaction'] = $transaction->ID(); |
@@ -755,13 +755,13 @@ discard block |
||
| 755 | 755 | // then serialize all of our session data |
| 756 | 756 | $session_data = serialize($this->_session_data); |
| 757 | 757 | // do we need to also encode it to avoid corrupted data when saved to the db? |
| 758 | - $session_data = $this->_use_encryption ? $this->encryption->base64_string_encode( $session_data ) : $session_data; |
|
| 758 | + $session_data = $this->_use_encryption ? $this->encryption->base64_string_encode($session_data) : $session_data; |
|
| 759 | 759 | // maybe save hash check |
| 760 | - if ( apply_filters( 'FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG ) ) { |
|
| 761 | - set_transient( EE_Session::hash_check_prefix . $this->_sid, md5( $session_data ), $this->_lifespan ); |
|
| 760 | + if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
| 761 | + set_transient(EE_Session::hash_check_prefix.$this->_sid, md5($session_data), $this->_lifespan); |
|
| 762 | 762 | } |
| 763 | 763 | // we're using the Transient API for storing session data, cuz it's so damn simple -> set_transient( transient ID, data, expiry ) |
| 764 | - return set_transient( EE_Session::session_id_prefix . $this->_sid, $session_data, $this->_lifespan ); |
|
| 764 | + return set_transient(EE_Session::session_id_prefix.$this->_sid, $session_data, $this->_lifespan); |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | |
@@ -787,10 +787,10 @@ discard block |
||
| 787 | 787 | 'HTTP_FORWARDED', |
| 788 | 788 | 'REMOTE_ADDR' |
| 789 | 789 | ); |
| 790 | - foreach ( $server_keys as $key ){ |
|
| 791 | - if ( isset( $_SERVER[ $key ] )) { |
|
| 792 | - foreach ( array_map( 'trim', explode( ',', $_SERVER[ $key ] )) as $ip ) { |
|
| 793 | - if ( $ip === '127.0.0.1' || filter_var( $ip, FILTER_VALIDATE_IP ) !== FALSE ) { |
|
| 790 | + foreach ($server_keys as $key) { |
|
| 791 | + if (isset($_SERVER[$key])) { |
|
| 792 | + foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) { |
|
| 793 | + if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== FALSE) { |
|
| 794 | 794 | $visitor_ip = $ip; |
| 795 | 795 | } |
| 796 | 796 | } |
@@ -809,32 +809,32 @@ discard block |
||
| 809 | 809 | * @return string |
| 810 | 810 | */ |
| 811 | 811 | public function _get_page_visit() { |
| 812 | - $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
| 812 | + $page_visit = home_url('/').'wp-admin/admin-ajax.php'; |
|
| 813 | 813 | // check for request url |
| 814 | - if ( isset( $_SERVER['REQUEST_URI'] )) { |
|
| 814 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 815 | 815 | $http_host = ''; |
| 816 | 816 | $page_id = '?'; |
| 817 | 817 | $e_reg = ''; |
| 818 | - $request_uri = esc_url( $_SERVER['REQUEST_URI'] ); |
|
| 819 | - $ru_bits = explode( '?', $request_uri ); |
|
| 818 | + $request_uri = esc_url($_SERVER['REQUEST_URI']); |
|
| 819 | + $ru_bits = explode('?', $request_uri); |
|
| 820 | 820 | $request_uri = $ru_bits[0]; |
| 821 | 821 | // check for and grab host as well |
| 822 | - if ( isset( $_SERVER['HTTP_HOST'] )) { |
|
| 823 | - $http_host = esc_url( $_SERVER['HTTP_HOST'] ); |
|
| 822 | + if (isset($_SERVER['HTTP_HOST'])) { |
|
| 823 | + $http_host = esc_url($_SERVER['HTTP_HOST']); |
|
| 824 | 824 | } |
| 825 | 825 | // check for page_id in SERVER REQUEST |
| 826 | - if ( isset( $_REQUEST['page_id'] )) { |
|
| 826 | + if (isset($_REQUEST['page_id'])) { |
|
| 827 | 827 | // rebuild $e_reg without any of the extra parameters |
| 828 | - $page_id = '?page_id=' . esc_attr( $_REQUEST['page_id'] ) . '&'; |
|
| 828 | + $page_id = '?page_id='.esc_attr($_REQUEST['page_id']).'&'; |
|
| 829 | 829 | } |
| 830 | 830 | // check for $e_reg in SERVER REQUEST |
| 831 | - if ( isset( $_REQUEST['ee'] )) { |
|
| 831 | + if (isset($_REQUEST['ee'])) { |
|
| 832 | 832 | // rebuild $e_reg without any of the extra parameters |
| 833 | - $e_reg = 'ee=' . esc_attr( $_REQUEST['ee'] ); |
|
| 833 | + $e_reg = 'ee='.esc_attr($_REQUEST['ee']); |
|
| 834 | 834 | } |
| 835 | - $page_visit = rtrim( $http_host . $request_uri . $page_id . $e_reg, '?' ); |
|
| 835 | + $page_visit = rtrim($http_host.$request_uri.$page_id.$e_reg, '?'); |
|
| 836 | 836 | } |
| 837 | - return $page_visit !== home_url( '/wp-admin/admin-ajax.php' ) ? $page_visit : ''; |
|
| 837 | + return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
|
| 838 | 838 | |
| 839 | 839 | } |
| 840 | 840 | |
@@ -863,14 +863,14 @@ discard block |
||
| 863 | 863 | * @param string $function |
| 864 | 864 | * @return void |
| 865 | 865 | */ |
| 866 | - public function clear_session( $class = '', $function = '' ) { |
|
| 866 | + public function clear_session($class = '', $function = '') { |
|
| 867 | 867 | //echo '<h3 style="color:#999;line-height:.9em;"><span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/><span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span> <b style="font-size:10px;"> ' . __LINE__ . ' </b></h3>'; |
| 868 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()' ); |
|
| 868 | + do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : '.$class.'::'.$function.'()'); |
|
| 869 | 869 | $this->reset_cart(); |
| 870 | 870 | $this->reset_checkout(); |
| 871 | 871 | $this->reset_transaction(); |
| 872 | 872 | // wipe out everything that isn't a default session datum |
| 873 | - $this->reset_data( array_keys( $this->_session_data )); |
|
| 873 | + $this->reset_data(array_keys($this->_session_data)); |
|
| 874 | 874 | // reset initial site access time and the session expiration |
| 875 | 875 | $this->_set_init_access_and_expiration(); |
| 876 | 876 | $this->_save_session_to_db(); |
@@ -885,42 +885,42 @@ discard block |
||
| 885 | 885 | * @param bool $show_all_notices |
| 886 | 886 | * @return TRUE on success, FALSE on fail |
| 887 | 887 | */ |
| 888 | - public function reset_data( $data_to_reset = array(), $show_all_notices = FALSE ) { |
|
| 888 | + public function reset_data($data_to_reset = array(), $show_all_notices = FALSE) { |
|
| 889 | 889 | // if $data_to_reset is not in an array, then put it in one |
| 890 | - if ( ! is_array( $data_to_reset ) ) { |
|
| 891 | - $data_to_reset = array ( $data_to_reset ); |
|
| 890 | + if ( ! is_array($data_to_reset)) { |
|
| 891 | + $data_to_reset = array($data_to_reset); |
|
| 892 | 892 | } |
| 893 | 893 | // nothing ??? go home! |
| 894 | - if ( empty( $data_to_reset )) { |
|
| 895 | - EE_Error::add_error( __( 'No session data could be reset, because no session var name was provided.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 894 | + if (empty($data_to_reset)) { |
|
| 895 | + EE_Error::add_error(__('No session data could be reset, because no session var name was provided.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 896 | 896 | return FALSE; |
| 897 | 897 | } |
| 898 | 898 | $return_value = TRUE; |
| 899 | 899 | // since $data_to_reset is an array, cycle through the values |
| 900 | - foreach ( $data_to_reset as $reset ) { |
|
| 900 | + foreach ($data_to_reset as $reset) { |
|
| 901 | 901 | |
| 902 | 902 | // first check to make sure it is a valid session var |
| 903 | - if ( isset( $this->_session_data[ $reset ] )) { |
|
| 903 | + if (isset($this->_session_data[$reset])) { |
|
| 904 | 904 | // then check to make sure it is not a default var |
| 905 | - if ( ! array_key_exists( $reset, $this->_default_session_vars )) { |
|
| 905 | + if ( ! array_key_exists($reset, $this->_default_session_vars)) { |
|
| 906 | 906 | // remove session var |
| 907 | - unset( $this->_session_data[ $reset ] ); |
|
| 908 | - if ( $show_all_notices ) { |
|
| 909 | - EE_Error::add_success( sprintf( __( 'The session variable %s was removed.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 907 | + unset($this->_session_data[$reset]); |
|
| 908 | + if ($show_all_notices) { |
|
| 909 | + EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 910 | 910 | } |
| 911 | - $return_value = !isset($return_value) ? TRUE : $return_value; |
|
| 911 | + $return_value = ! isset($return_value) ? TRUE : $return_value; |
|
| 912 | 912 | |
| 913 | 913 | } else { |
| 914 | 914 | // yeeeeeeeeerrrrrrrrrrr OUT !!!! |
| 915 | - if ( $show_all_notices ) { |
|
| 916 | - EE_Error::add_error( sprintf( __( 'Sorry! %s is a default session datum and can not be reset.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 915 | + if ($show_all_notices) { |
|
| 916 | + EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 917 | 917 | } |
| 918 | 918 | $return_value = FALSE; |
| 919 | 919 | } |
| 920 | 920 | |
| 921 | - } else if ( $show_all_notices ) { |
|
| 921 | + } else if ($show_all_notices) { |
|
| 922 | 922 | // oops! that session var does not exist! |
| 923 | - EE_Error::add_error( sprintf( __( 'The session item provided, %s, is invalid or does not exist.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 923 | + EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 924 | 924 | $return_value = FALSE; |
| 925 | 925 | } |
| 926 | 926 | |
@@ -940,8 +940,8 @@ discard block |
||
| 940 | 940 | * @access public |
| 941 | 941 | */ |
| 942 | 942 | public function wp_loaded() { |
| 943 | - if ( isset( EE_Registry::instance()->REQ ) && EE_Registry::instance()->REQ->is_set( 'clear_session' )) { |
|
| 944 | - $this->clear_session( __CLASS__, __FUNCTION__ ); |
|
| 943 | + if (isset(EE_Registry::instance()->REQ) && EE_Registry::instance()->REQ->is_set('clear_session')) { |
|
| 944 | + $this->clear_session(__CLASS__, __FUNCTION__); |
|
| 945 | 945 | } |
| 946 | 946 | } |
| 947 | 947 | |
@@ -966,24 +966,24 @@ discard block |
||
| 966 | 966 | */ |
| 967 | 967 | public function garbage_collection() { |
| 968 | 968 | // only perform during regular requests |
| 969 | - if ( ! defined( 'DOING_AJAX') || ! DOING_AJAX ) { |
|
| 969 | + if ( ! defined('DOING_AJAX') || ! DOING_AJAX) { |
|
| 970 | 970 | /** @type WPDB $wpdb */ |
| 971 | 971 | global $wpdb; |
| 972 | 972 | // since transient expiration timestamps are set in the future, we can compare against NOW |
| 973 | 973 | $expiration = time(); |
| 974 | - $too_far_in_the_the_future = $expiration + ( $this->_lifespan * 2 ); |
|
| 974 | + $too_far_in_the_the_future = $expiration + ($this->_lifespan * 2); |
|
| 975 | 975 | // filter the query limit. Set to 0 to turn off garbage collection |
| 976 | - $expired_session_transient_delete_query_limit = absint( apply_filters( 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', 50 )); |
|
| 976 | + $expired_session_transient_delete_query_limit = absint(apply_filters('FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', 50)); |
|
| 977 | 977 | // non-zero LIMIT means take out the trash |
| 978 | - if ( $expired_session_transient_delete_query_limit ) { |
|
| 978 | + if ($expired_session_transient_delete_query_limit) { |
|
| 979 | 979 | //array of transient keys that require garbage collection |
| 980 | 980 | $session_keys = array( |
| 981 | 981 | EE_Session::session_id_prefix, |
| 982 | 982 | EE_Session::hash_check_prefix, |
| 983 | 983 | ); |
| 984 | - foreach ( $session_keys as $session_key ) { |
|
| 985 | - $session_key = str_replace( '_', '\_', $session_key ); |
|
| 986 | - $session_key = '\_transient\_timeout\_' . $session_key . '%'; |
|
| 984 | + foreach ($session_keys as $session_key) { |
|
| 985 | + $session_key = str_replace('_', '\_', $session_key); |
|
| 986 | + $session_key = '\_transient\_timeout\_'.$session_key.'%'; |
|
| 987 | 987 | $SQL = " |
| 988 | 988 | SELECT option_name |
| 989 | 989 | FROM {$wpdb->options} |
@@ -993,25 +993,25 @@ discard block |
||
| 993 | 993 | OR option_value > {$too_far_in_the_the_future} ) |
| 994 | 994 | LIMIT {$expired_session_transient_delete_query_limit} |
| 995 | 995 | "; |
| 996 | - $expired_sessions = $wpdb->get_col( $SQL ); |
|
| 996 | + $expired_sessions = $wpdb->get_col($SQL); |
|
| 997 | 997 | // valid results? |
| 998 | - if ( ! $expired_sessions instanceof WP_Error && ! empty( $expired_sessions ) ) { |
|
| 998 | + if ( ! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
| 999 | 999 | // format array of results into something usable within the actual DELETE query's IN clause |
| 1000 | 1000 | $expired = array(); |
| 1001 | - foreach ( $expired_sessions as $expired_session ) { |
|
| 1002 | - $expired[ ] = "'" . $expired_session . "'"; |
|
| 1003 | - $expired[ ] = "'" . str_replace( 'timeout_', '', $expired_session ) . "'"; |
|
| 1001 | + foreach ($expired_sessions as $expired_session) { |
|
| 1002 | + $expired[] = "'".$expired_session."'"; |
|
| 1003 | + $expired[] = "'".str_replace('timeout_', '', $expired_session)."'"; |
|
| 1004 | 1004 | } |
| 1005 | - $expired = implode( ', ', $expired ); |
|
| 1005 | + $expired = implode(', ', $expired); |
|
| 1006 | 1006 | $SQL = " |
| 1007 | 1007 | DELETE FROM {$wpdb->options} |
| 1008 | 1008 | WHERE option_name |
| 1009 | 1009 | IN ( $expired ); |
| 1010 | 1010 | "; |
| 1011 | - $results = $wpdb->query( $SQL ); |
|
| 1011 | + $results = $wpdb->query($SQL); |
|
| 1012 | 1012 | // if something went wrong, then notify the admin |
| 1013 | - if ( $results instanceof WP_Error && is_admin() ) { |
|
| 1014 | - EE_Error::add_error( $results->get_error_message(), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1013 | + if ($results instanceof WP_Error && is_admin()) { |
|
| 1014 | + EE_Error::add_error($results->get_error_message(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1015 | 1015 | } |
| 1016 | 1016 | } |
| 1017 | 1017 | } |
@@ -1032,34 +1032,34 @@ discard block |
||
| 1032 | 1032 | * @param $data1 |
| 1033 | 1033 | * @return string |
| 1034 | 1034 | */ |
| 1035 | - private function find_serialize_error( $data1 ) { |
|
| 1035 | + private function find_serialize_error($data1) { |
|
| 1036 | 1036 | $error = "<pre>"; |
| 1037 | 1037 | $data2 = preg_replace_callback( |
| 1038 | 1038 | '!s:(\d+):"(.*?)";!', |
| 1039 | - function ( $match ) { |
|
| 1040 | - return ( $match[1] === strlen( $match[2] ) ) |
|
| 1039 | + function($match) { |
|
| 1040 | + return ($match[1] === strlen($match[2])) |
|
| 1041 | 1041 | ? $match[0] |
| 1042 | 1042 | : 's:' |
| 1043 | - . strlen( $match[2] ) |
|
| 1043 | + . strlen($match[2]) |
|
| 1044 | 1044 | . ':"' |
| 1045 | 1045 | . $match[2] |
| 1046 | 1046 | . '";'; |
| 1047 | 1047 | }, |
| 1048 | 1048 | $data1 |
| 1049 | 1049 | ); |
| 1050 | - $max = ( strlen( $data1 ) > strlen( $data2 ) ) ? strlen( $data1 ) : strlen( $data2 ); |
|
| 1051 | - $error .= $data1 . PHP_EOL; |
|
| 1052 | - $error .= $data2 . PHP_EOL; |
|
| 1053 | - for ( $i = 0; $i < $max; $i++ ) { |
|
| 1054 | - if ( @$data1[ $i ] !== @$data2[ $i ] ) { |
|
| 1055 | - $error .= "Difference " . @$data1[ $i ] . " != " . @$data2[ $i ] . PHP_EOL; |
|
| 1056 | - $error .= "\t-> ORD number " . ord( @$data1[ $i ] ) . " != " . ord( @$data2[ $i ] ) . PHP_EOL; |
|
| 1057 | - $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
| 1058 | - $start = ( $i - 20 ); |
|
| 1059 | - $start = ( $start < 0 ) ? 0 : $start; |
|
| 1050 | + $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
| 1051 | + $error .= $data1.PHP_EOL; |
|
| 1052 | + $error .= $data2.PHP_EOL; |
|
| 1053 | + for ($i = 0; $i < $max; $i++) { |
|
| 1054 | + if (@$data1[$i] !== @$data2[$i]) { |
|
| 1055 | + $error .= "Difference ".@$data1[$i]." != ".@$data2[$i].PHP_EOL; |
|
| 1056 | + $error .= "\t-> ORD number ".ord(@$data1[$i])." != ".ord(@$data2[$i]).PHP_EOL; |
|
| 1057 | + $error .= "\t-> Line Number = $i".PHP_EOL; |
|
| 1058 | + $start = ($i - 20); |
|
| 1059 | + $start = ($start < 0) ? 0 : $start; |
|
| 1060 | 1060 | $length = 40; |
| 1061 | 1061 | $point = $max - $i; |
| 1062 | - if ( $point < 20 ) { |
|
| 1062 | + if ($point < 20) { |
|
| 1063 | 1063 | $rlength = 1; |
| 1064 | 1064 | $rpoint = -$point; |
| 1065 | 1065 | } else { |
@@ -1068,16 +1068,16 @@ discard block |
||
| 1068 | 1068 | } |
| 1069 | 1069 | $error .= "\t-> Section Data1 = "; |
| 1070 | 1070 | $error .= substr_replace( |
| 1071 | - substr( $data1, $start, $length ), |
|
| 1072 | - "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
| 1071 | + substr($data1, $start, $length), |
|
| 1072 | + "<b style=\"color:green\">{$data1[$i]}</b>", |
|
| 1073 | 1073 | $rpoint, |
| 1074 | 1074 | $rlength |
| 1075 | 1075 | ); |
| 1076 | 1076 | $error .= PHP_EOL; |
| 1077 | 1077 | $error .= "\t-> Section Data2 = "; |
| 1078 | 1078 | $error .= substr_replace( |
| 1079 | - substr( $data2, $start, $length ), |
|
| 1080 | - "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
| 1079 | + substr($data2, $start, $length), |
|
| 1080 | + "<b style=\"color:red\">{$data2[$i]}</b>", |
|
| 1081 | 1081 | $rpoint, |
| 1082 | 1082 | $rlength |
| 1083 | 1083 | ); |
@@ -781,7 +781,7 @@ discard block |
||
| 781 | 781 | * _get_transaction_and_cart_for_previous_visit |
| 782 | 782 | * |
| 783 | 783 | * @access private |
| 784 | - * @return mixed EE_Transaction|NULL |
|
| 784 | + * @return EE_Transaction|null EE_Transaction|NULL |
|
| 785 | 785 | */ |
| 786 | 786 | private function _get_transaction_and_cart_for_previous_visit() |
| 787 | 787 | { |
@@ -863,7 +863,7 @@ discard block |
||
| 863 | 863 | * generates a new EE_Transaction object and adds it to the $_transaction property. |
| 864 | 864 | * |
| 865 | 865 | * @access private |
| 866 | - * @return mixed EE_Transaction|NULL |
|
| 866 | + * @return EE_Transaction|null EE_Transaction|NULL |
|
| 867 | 867 | */ |
| 868 | 868 | private function _initialize_transaction() |
| 869 | 869 | { |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | use EventEspresso\core\exceptions\InvalidEntityException; |
| 3 | 3 | |
| 4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 5 | - exit('No direct script access allowed'); |
|
| 5 | + exit('No direct script access allowed'); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
@@ -17,1605 +17,1605 @@ discard block |
||
| 17 | 17 | class EED_Single_Page_Checkout extends EED_Module |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * $_initialized - has the SPCO controller already been initialized ? |
|
| 22 | - * |
|
| 23 | - * @access private |
|
| 24 | - * @var bool $_initialized |
|
| 25 | - */ |
|
| 26 | - private static $_initialized = false; |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
| 31 | - * |
|
| 32 | - * @access private |
|
| 33 | - * @var bool $_valid_checkout |
|
| 34 | - */ |
|
| 35 | - private static $_checkout_verified = true; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * $_reg_steps_array - holds initial array of reg steps |
|
| 39 | - * |
|
| 40 | - * @access private |
|
| 41 | - * @var array $_reg_steps_array |
|
| 42 | - */ |
|
| 43 | - private static $_reg_steps_array = array(); |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
| 47 | - * |
|
| 48 | - * @access public |
|
| 49 | - * @var EE_Checkout $checkout |
|
| 50 | - */ |
|
| 51 | - public $checkout; |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @return EED_Single_Page_Checkout |
|
| 57 | - */ |
|
| 58 | - public static function instance() |
|
| 59 | - { |
|
| 60 | - add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
| 61 | - return parent::get_instance(__CLASS__); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @return EE_CART |
|
| 68 | - */ |
|
| 69 | - public function cart() |
|
| 70 | - { |
|
| 71 | - return $this->checkout->cart; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @return EE_Transaction |
|
| 78 | - */ |
|
| 79 | - public function transaction() |
|
| 80 | - { |
|
| 81 | - return $this->checkout->transaction; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 88 | - * |
|
| 89 | - * @access public |
|
| 90 | - * @return void |
|
| 91 | - * @throws \EE_Error |
|
| 92 | - */ |
|
| 93 | - public static function set_hooks() |
|
| 94 | - { |
|
| 95 | - EED_Single_Page_Checkout::set_definitions(); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 102 | - * |
|
| 103 | - * @access public |
|
| 104 | - * @return void |
|
| 105 | - * @throws \EE_Error |
|
| 106 | - */ |
|
| 107 | - public static function set_hooks_admin() |
|
| 108 | - { |
|
| 109 | - EED_Single_Page_Checkout::set_definitions(); |
|
| 110 | - if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 111 | - // hook into the top of pre_get_posts to set the reg step routing, which gives other modules or plugins a chance to modify the reg steps, but just before the routes get called |
|
| 112 | - add_action('pre_get_posts', array('EED_Single_Page_Checkout', 'load_reg_steps'), 1); |
|
| 113 | - return; |
|
| 114 | - } |
|
| 115 | - // going to start an output buffer in case anything gets accidentally output that might disrupt our JSON response |
|
| 116 | - ob_start(); |
|
| 117 | - EED_Single_Page_Checkout::load_request_handler(); |
|
| 118 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
| 119 | - // set ajax hooks |
|
| 120 | - add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
| 121 | - add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
| 122 | - add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
| 123 | - add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
| 124 | - add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
| 125 | - add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * process ajax request |
|
| 132 | - * |
|
| 133 | - * @param string $ajax_action |
|
| 134 | - * @throws \EE_Error |
|
| 135 | - */ |
|
| 136 | - public static function process_ajax_request($ajax_action) |
|
| 137 | - { |
|
| 138 | - EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
| 139 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * ajax display registration step |
|
| 146 | - * |
|
| 147 | - * @throws \EE_Error |
|
| 148 | - */ |
|
| 149 | - public static function display_reg_step() |
|
| 150 | - { |
|
| 151 | - EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * ajax process registration step |
|
| 158 | - * |
|
| 159 | - * @throws \EE_Error |
|
| 160 | - */ |
|
| 161 | - public static function process_reg_step() |
|
| 162 | - { |
|
| 163 | - EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * ajax process registration step |
|
| 170 | - * |
|
| 171 | - * @throws \EE_Error |
|
| 172 | - */ |
|
| 173 | - public static function update_reg_step() |
|
| 174 | - { |
|
| 175 | - EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * update_checkout |
|
| 182 | - * |
|
| 183 | - * @access public |
|
| 184 | - * @return void |
|
| 185 | - * @throws \EE_Error |
|
| 186 | - */ |
|
| 187 | - public static function update_checkout() |
|
| 188 | - { |
|
| 189 | - EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * load_request_handler |
|
| 196 | - * |
|
| 197 | - * @access public |
|
| 198 | - * @return void |
|
| 199 | - */ |
|
| 200 | - public static function load_request_handler() |
|
| 201 | - { |
|
| 202 | - // load core Request_Handler class |
|
| 203 | - if ( ! isset(EE_Registry::instance()->REQ)) { |
|
| 204 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * set_definitions |
|
| 212 | - * |
|
| 213 | - * @access public |
|
| 214 | - * @return void |
|
| 215 | - * @throws \EE_Error |
|
| 216 | - */ |
|
| 217 | - public static function set_definitions() |
|
| 218 | - { |
|
| 219 | - define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS); |
|
| 220 | - define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
| 221 | - define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
| 222 | - define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
| 223 | - define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
| 224 | - define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
| 225 | - define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
| 226 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * load_reg_steps |
|
| 233 | - * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
| 234 | - * |
|
| 235 | - * @access private |
|
| 236 | - * @throws EE_Error |
|
| 237 | - * @return void |
|
| 238 | - */ |
|
| 239 | - public static function load_reg_steps() |
|
| 240 | - { |
|
| 241 | - static $reg_steps_loaded = false; |
|
| 242 | - if ($reg_steps_loaded) { |
|
| 243 | - return; |
|
| 244 | - } |
|
| 245 | - // filter list of reg_steps |
|
| 246 | - $reg_steps_to_load = (array)apply_filters( |
|
| 247 | - 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
| 248 | - EED_Single_Page_Checkout::get_reg_steps() |
|
| 249 | - ); |
|
| 250 | - // sort by key (order) |
|
| 251 | - ksort($reg_steps_to_load); |
|
| 252 | - // loop through folders |
|
| 253 | - foreach ($reg_steps_to_load as $order => $reg_step) { |
|
| 254 | - // we need a |
|
| 255 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
| 256 | - // copy over to the reg_steps_array |
|
| 257 | - EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step; |
|
| 258 | - // register custom key route for each reg step |
|
| 259 | - // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
| 260 | - EE_Config::register_route($reg_step['slug'], 'EED_Single_Page_Checkout', 'run', 'step'); |
|
| 261 | - // add AJAX or other hooks |
|
| 262 | - if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
| 263 | - // setup autoloaders if necessary |
|
| 264 | - if ( ! class_exists($reg_step['class_name'])) { |
|
| 265 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($reg_step['file_path'], true); |
|
| 266 | - } |
|
| 267 | - if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
| 268 | - call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - $reg_steps_loaded = true; |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * get_reg_steps |
|
| 280 | - * |
|
| 281 | - * @access public |
|
| 282 | - * @return array |
|
| 283 | - */ |
|
| 284 | - public static function get_reg_steps() |
|
| 285 | - { |
|
| 286 | - $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
| 287 | - if (empty($reg_steps)) { |
|
| 288 | - $reg_steps = array( |
|
| 289 | - 10 => array( |
|
| 290 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
| 291 | - 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
| 292 | - 'slug' => 'attendee_information', |
|
| 293 | - 'has_hooks' => false, |
|
| 294 | - ), |
|
| 295 | - 20 => array( |
|
| 296 | - 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
| 297 | - 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
|
| 298 | - 'slug' => 'registration_confirmation', |
|
| 299 | - 'has_hooks' => false, |
|
| 300 | - ), |
|
| 301 | - 30 => array( |
|
| 302 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
| 303 | - 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
| 304 | - 'slug' => 'payment_options', |
|
| 305 | - 'has_hooks' => true, |
|
| 306 | - ), |
|
| 307 | - 999 => array( |
|
| 308 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
| 309 | - 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
| 310 | - 'slug' => 'finalize_registration', |
|
| 311 | - 'has_hooks' => false, |
|
| 312 | - ), |
|
| 313 | - ); |
|
| 314 | - } |
|
| 315 | - return $reg_steps; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * registration_checkout_for_admin |
|
| 322 | - * |
|
| 323 | - * @access public |
|
| 324 | - * @return string |
|
| 325 | - * @throws \EE_Error |
|
| 326 | - */ |
|
| 327 | - public static function registration_checkout_for_admin() |
|
| 328 | - { |
|
| 329 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
| 330 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
| 331 | - EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
| 332 | - EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
| 333 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 334 | - EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
| 335 | - return EE_Registry::instance()->REQ->get_output(); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * process_registration_from_admin |
|
| 342 | - * |
|
| 343 | - * @access public |
|
| 344 | - * @return \EE_Transaction |
|
| 345 | - * @throws \EE_Error |
|
| 346 | - */ |
|
| 347 | - public static function process_registration_from_admin() |
|
| 348 | - { |
|
| 349 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
| 350 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
| 351 | - EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
| 352 | - EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
| 353 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 354 | - if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
| 355 | - $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
| 356 | - if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
| 357 | - EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
| 358 | - if ($final_reg_step->process_reg_step()) { |
|
| 359 | - $final_reg_step->set_completed(); |
|
| 360 | - EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
| 361 | - return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
| 362 | - } |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - return null; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * run |
|
| 372 | - * |
|
| 373 | - * @access public |
|
| 374 | - * @param WP_Query $WP_Query |
|
| 375 | - * @return void |
|
| 376 | - * @throws \EE_Error |
|
| 377 | - */ |
|
| 378 | - public function run($WP_Query) |
|
| 379 | - { |
|
| 380 | - if ( |
|
| 381 | - $WP_Query instanceof WP_Query |
|
| 382 | - && $WP_Query->is_main_query() |
|
| 383 | - && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
| 384 | - && $this->_is_reg_checkout() |
|
| 385 | - ) { |
|
| 386 | - $this->_initialize(); |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * determines whether current url matches reg page url |
|
| 394 | - * |
|
| 395 | - * @return bool |
|
| 396 | - */ |
|
| 397 | - protected function _is_reg_checkout() |
|
| 398 | - { |
|
| 399 | - // get current permalink for reg page without any extra query args |
|
| 400 | - $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
| 401 | - // get request URI for current request, but without the scheme or host |
|
| 402 | - $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
| 403 | - $current_request_uri = html_entity_decode($current_request_uri); |
|
| 404 | - // get array of query args from the current request URI |
|
| 405 | - $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
| 406 | - // grab page id if it is set |
|
| 407 | - $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
| 408 | - // and remove the page id from the query args (we will re-add it later) |
|
| 409 | - unset($query_args['page_id']); |
|
| 410 | - // now strip all query args from current request URI |
|
| 411 | - $current_request_uri = remove_query_arg(array_flip($query_args), $current_request_uri); |
|
| 412 | - // and re-add the page id if it was set |
|
| 413 | - if ($page_id) { |
|
| 414 | - $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
| 415 | - } |
|
| 416 | - // remove slashes and ? |
|
| 417 | - $current_request_uri = trim($current_request_uri, '?/'); |
|
| 418 | - // is current request URI part of the known full reg page URL ? |
|
| 419 | - return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * run |
|
| 426 | - * |
|
| 427 | - * @access public |
|
| 428 | - * @param WP_Query $WP_Query |
|
| 429 | - * @return void |
|
| 430 | - * @throws \EE_Error |
|
| 431 | - */ |
|
| 432 | - public static function init($WP_Query) |
|
| 433 | - { |
|
| 434 | - EED_Single_Page_Checkout::instance()->run($WP_Query); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * _initialize - initial module setup |
|
| 441 | - * |
|
| 442 | - * @access private |
|
| 443 | - * @throws EE_Error |
|
| 444 | - * @return void |
|
| 445 | - */ |
|
| 446 | - private function _initialize() |
|
| 447 | - { |
|
| 448 | - // ensure SPCO doesn't run twice |
|
| 449 | - if (EED_Single_Page_Checkout::$_initialized) { |
|
| 450 | - return; |
|
| 451 | - } |
|
| 452 | - try { |
|
| 453 | - // setup the EE_Checkout object |
|
| 454 | - $this->checkout = $this->_initialize_checkout(); |
|
| 455 | - // filter checkout |
|
| 456 | - $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
| 457 | - // get the $_GET |
|
| 458 | - $this->_get_request_vars(); |
|
| 459 | - if ($this->_block_bots()) { |
|
| 460 | - return; |
|
| 461 | - } |
|
| 462 | - // filter continue_reg |
|
| 463 | - $this->checkout->continue_reg = apply_filters('FHEE__EED_Single_Page_Checkout__init___continue_reg', true, $this->checkout); |
|
| 464 | - // load the reg steps array |
|
| 465 | - if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
| 466 | - EED_Single_Page_Checkout::$_initialized = true; |
|
| 467 | - return; |
|
| 468 | - } |
|
| 469 | - // set the current step |
|
| 470 | - $this->checkout->set_current_step($this->checkout->step); |
|
| 471 | - // and the next step |
|
| 472 | - $this->checkout->set_next_step(); |
|
| 473 | - // was there already a valid transaction in the checkout from the session ? |
|
| 474 | - if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 475 | - // get transaction from db or session |
|
| 476 | - $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
| 477 | - ? $this->_get_transaction_and_cart_for_previous_visit() |
|
| 478 | - : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
| 479 | - if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 480 | - // add some style and make it dance |
|
| 481 | - $this->checkout->transaction = EE_Transaction::new_instance(); |
|
| 482 | - $this->add_styles_and_scripts(); |
|
| 483 | - EED_Single_Page_Checkout::$_initialized = true; |
|
| 484 | - return; |
|
| 485 | - } |
|
| 486 | - // and the registrations for the transaction |
|
| 487 | - $this->_get_registrations($this->checkout->transaction); |
|
| 488 | - } |
|
| 489 | - // verify that everything has been setup correctly |
|
| 490 | - if ( ! $this->_final_verifications()) { |
|
| 491 | - EED_Single_Page_Checkout::$_initialized = true; |
|
| 492 | - return; |
|
| 493 | - } |
|
| 494 | - // lock the transaction |
|
| 495 | - $this->checkout->transaction->lock(); |
|
| 496 | - // make sure all of our cached objects are added to their respective model entity mappers |
|
| 497 | - $this->checkout->refresh_all_entities(); |
|
| 498 | - // set amount owing |
|
| 499 | - $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
| 500 | - // initialize each reg step, which gives them the chance to potentially alter the process |
|
| 501 | - $this->_initialize_reg_steps(); |
|
| 502 | - // DEBUG LOG |
|
| 503 | - //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
| 504 | - // get reg form |
|
| 505 | - $this->_check_form_submission(); |
|
| 506 | - // checkout the action!!! |
|
| 507 | - $this->_process_form_action(); |
|
| 508 | - // add some style and make it dance |
|
| 509 | - $this->add_styles_and_scripts(); |
|
| 510 | - // kk... SPCO has successfully run |
|
| 511 | - EED_Single_Page_Checkout::$_initialized = true; |
|
| 512 | - // set no cache headers and constants |
|
| 513 | - EE_System::do_not_cache(); |
|
| 514 | - // add anchor |
|
| 515 | - add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
| 516 | - } catch (Exception $e) { |
|
| 517 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 518 | - } |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * _initialize_checkout |
|
| 525 | - * loads and instantiates EE_Checkout |
|
| 526 | - * |
|
| 527 | - * @access private |
|
| 528 | - * @throws EE_Error |
|
| 529 | - * @return EE_Checkout |
|
| 530 | - */ |
|
| 531 | - private function _initialize_checkout() |
|
| 532 | - { |
|
| 533 | - // look in session for existing checkout |
|
| 534 | - $checkout = EE_Registry::instance()->SSN->checkout(); |
|
| 535 | - // verify |
|
| 536 | - if ( ! $checkout instanceof EE_Checkout) { |
|
| 537 | - // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
| 538 | - $checkout = EE_Registry::instance()->load_file(SPCO_INC_PATH, 'EE_Checkout', 'class', array(), false); |
|
| 539 | - } else { |
|
| 540 | - if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
| 541 | - $this->unlock_transaction(); |
|
| 542 | - wp_safe_redirect($checkout->redirect_url); |
|
| 543 | - exit(); |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
| 547 | - // verify again |
|
| 548 | - if ( ! $checkout instanceof EE_Checkout) { |
|
| 549 | - throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
| 550 | - } |
|
| 551 | - // reset anything that needs a clean slate for each request |
|
| 552 | - $checkout->reset_for_current_request(); |
|
| 553 | - return $checkout; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * _get_request_vars |
|
| 560 | - * |
|
| 561 | - * @access private |
|
| 562 | - * @return void |
|
| 563 | - * @throws \EE_Error |
|
| 564 | - */ |
|
| 565 | - private function _get_request_vars() |
|
| 566 | - { |
|
| 567 | - // load classes |
|
| 568 | - EED_Single_Page_Checkout::load_request_handler(); |
|
| 569 | - //make sure this request is marked as belonging to EE |
|
| 570 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 571 | - // which step is being requested ? |
|
| 572 | - $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
| 573 | - // which step is being edited ? |
|
| 574 | - $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
| 575 | - // and what we're doing on the current step |
|
| 576 | - $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
| 577 | - // timestamp |
|
| 578 | - $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
| 579 | - // returning to edit ? |
|
| 580 | - $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
| 581 | - // or some other kind of revisit ? |
|
| 582 | - $this->checkout->revisit = EE_Registry::instance()->REQ->get('revisit', false); |
|
| 583 | - // and whether or not to generate a reg form for this request |
|
| 584 | - $this->checkout->generate_reg_form = EE_Registry::instance()->REQ->get('generate_reg_form', true); // TRUE FALSE |
|
| 585 | - // and whether or not to process a reg form submission for this request |
|
| 586 | - $this->checkout->process_form_submission = EE_Registry::instance()->REQ->get('process_form_submission', false); // TRUE FALSE |
|
| 587 | - $this->checkout->process_form_submission = $this->checkout->action !== 'display_spco_reg_step' |
|
| 588 | - ? $this->checkout->process_form_submission |
|
| 589 | - : false; // TRUE FALSE |
|
| 590 | - // $this->_display_request_vars(); |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * _display_request_vars |
|
| 597 | - * |
|
| 598 | - * @access protected |
|
| 599 | - * @return void |
|
| 600 | - */ |
|
| 601 | - protected function _display_request_vars() |
|
| 602 | - { |
|
| 603 | - if ( ! WP_DEBUG) { |
|
| 604 | - return; |
|
| 605 | - } |
|
| 606 | - EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
| 607 | - EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
| 608 | - EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
| 609 | - EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
| 610 | - EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
| 611 | - EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
| 612 | - EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); |
|
| 613 | - EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * _block_bots |
|
| 620 | - * checks that the incoming request has either of the following set: |
|
| 621 | - * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
| 622 | - * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
| 623 | - * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
| 624 | - * then where you coming from man? |
|
| 625 | - * |
|
| 626 | - * @return boolean |
|
| 627 | - */ |
|
| 628 | - private function _block_bots() |
|
| 629 | - { |
|
| 630 | - $invalid_checkout_access = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
| 631 | - if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
| 632 | - return true; |
|
| 633 | - } |
|
| 634 | - return false; |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - /** |
|
| 640 | - * _get_first_step |
|
| 641 | - * gets slug for first step in $_reg_steps_array |
|
| 642 | - * |
|
| 643 | - * @access private |
|
| 644 | - * @throws EE_Error |
|
| 645 | - * @return array |
|
| 646 | - */ |
|
| 647 | - private function _get_first_step() |
|
| 648 | - { |
|
| 649 | - $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
| 650 | - return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - |
|
| 654 | - |
|
| 655 | - /** |
|
| 656 | - * _load_and_instantiate_reg_steps |
|
| 657 | - * instantiates each reg step based on the loaded reg_steps array |
|
| 658 | - * |
|
| 659 | - * @access private |
|
| 660 | - * @throws EE_Error |
|
| 661 | - * @return bool |
|
| 662 | - */ |
|
| 663 | - private function _load_and_instantiate_reg_steps() |
|
| 664 | - { |
|
| 665 | - // have reg_steps already been instantiated ? |
|
| 666 | - if ( |
|
| 667 | - empty($this->checkout->reg_steps) || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
| 668 | - ) { |
|
| 669 | - // if not, then loop through raw reg steps array |
|
| 670 | - foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
| 671 | - if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
| 672 | - return false; |
|
| 673 | - } |
|
| 674 | - } |
|
| 675 | - EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true; |
|
| 676 | - EE_Registry::instance()->CFG->registration->reg_confirmation_last = true; |
|
| 677 | - // skip the registration_confirmation page ? |
|
| 678 | - if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
| 679 | - // just remove it from the reg steps array |
|
| 680 | - $this->checkout->remove_reg_step('registration_confirmation', false); |
|
| 681 | - } else if ( |
|
| 682 | - isset($this->checkout->reg_steps['registration_confirmation']) |
|
| 683 | - && EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
| 684 | - ) { |
|
| 685 | - // set the order to something big like 100 |
|
| 686 | - $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
| 687 | - } |
|
| 688 | - // filter the array for good luck |
|
| 689 | - $this->checkout->reg_steps = apply_filters( |
|
| 690 | - 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
| 691 | - $this->checkout->reg_steps |
|
| 692 | - ); |
|
| 693 | - // finally re-sort based on the reg step class order properties |
|
| 694 | - $this->checkout->sort_reg_steps(); |
|
| 695 | - } else { |
|
| 696 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
| 697 | - // set all current step stati to FALSE |
|
| 698 | - $reg_step->set_is_current_step(false); |
|
| 699 | - } |
|
| 700 | - } |
|
| 701 | - if (empty($this->checkout->reg_steps)) { |
|
| 702 | - EE_Error::add_error(__('No Reg Steps were loaded..', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 703 | - return false; |
|
| 704 | - } |
|
| 705 | - // make reg step details available to JS |
|
| 706 | - $this->checkout->set_reg_step_JSON_info(); |
|
| 707 | - return true; |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - |
|
| 711 | - |
|
| 712 | - /** |
|
| 713 | - * _load_and_instantiate_reg_step |
|
| 714 | - * |
|
| 715 | - * @access private |
|
| 716 | - * @param array $reg_step |
|
| 717 | - * @param int $order |
|
| 718 | - * @return bool |
|
| 719 | - */ |
|
| 720 | - private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
| 721 | - { |
|
| 722 | - // we need a file_path, class_name, and slug to add a reg step |
|
| 723 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
| 724 | - // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
| 725 | - if ( |
|
| 726 | - $this->checkout->reg_url_link |
|
| 727 | - && $this->checkout->step !== $reg_step['slug'] |
|
| 728 | - && $reg_step['slug'] !== 'finalize_registration' |
|
| 729 | - ) { |
|
| 730 | - return true; |
|
| 731 | - } |
|
| 732 | - // instantiate step class using file path and class name |
|
| 733 | - $reg_step_obj = EE_Registry::instance()->load_file( |
|
| 734 | - $reg_step['file_path'], |
|
| 735 | - $reg_step['class_name'], |
|
| 736 | - 'class', |
|
| 737 | - $this->checkout, |
|
| 738 | - false |
|
| 739 | - ); |
|
| 740 | - // did we gets the goods ? |
|
| 741 | - if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
| 742 | - // set reg step order based on config |
|
| 743 | - $reg_step_obj->set_order($order); |
|
| 744 | - // add instantiated reg step object to the master reg steps array |
|
| 745 | - $this->checkout->add_reg_step($reg_step_obj); |
|
| 746 | - } else { |
|
| 747 | - EE_Error::add_error( |
|
| 748 | - __('The current step could not be set.', 'event_espresso'), |
|
| 749 | - __FILE__, |
|
| 750 | - __FUNCTION__, |
|
| 751 | - __LINE__ |
|
| 752 | - ); |
|
| 753 | - return false; |
|
| 754 | - } |
|
| 755 | - } else { |
|
| 756 | - if (WP_DEBUG) { |
|
| 757 | - EE_Error::add_error( |
|
| 758 | - sprintf( |
|
| 759 | - __('A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', 'event_espresso'), |
|
| 760 | - isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
| 761 | - isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
| 762 | - isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
| 763 | - '<ul>', |
|
| 764 | - '<li>', |
|
| 765 | - '</li>', |
|
| 766 | - '</ul>' |
|
| 767 | - ), |
|
| 768 | - __FILE__, |
|
| 769 | - __FUNCTION__, |
|
| 770 | - __LINE__ |
|
| 771 | - ); |
|
| 772 | - } |
|
| 773 | - return false; |
|
| 774 | - } |
|
| 775 | - return true; |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - |
|
| 779 | - |
|
| 780 | - /** |
|
| 781 | - * _get_transaction_and_cart_for_previous_visit |
|
| 782 | - * |
|
| 783 | - * @access private |
|
| 784 | - * @return mixed EE_Transaction|NULL |
|
| 785 | - */ |
|
| 786 | - private function _get_transaction_and_cart_for_previous_visit() |
|
| 787 | - { |
|
| 788 | - /** @var $TXN_model EEM_Transaction */ |
|
| 789 | - $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
| 790 | - // because the reg_url_link is present in the request, this is a return visit to SPCO, so we'll get the transaction data from the db |
|
| 791 | - $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
| 792 | - // verify transaction |
|
| 793 | - if ($transaction instanceof EE_Transaction) { |
|
| 794 | - // and get the cart that was used for that transaction |
|
| 795 | - $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
| 796 | - return $transaction; |
|
| 797 | - } else { |
|
| 798 | - EE_Error::add_error(__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 799 | - return null; |
|
| 800 | - } |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - |
|
| 804 | - |
|
| 805 | - /** |
|
| 806 | - * _get_cart_for_transaction |
|
| 807 | - * |
|
| 808 | - * @access private |
|
| 809 | - * @param EE_Transaction $transaction |
|
| 810 | - * @return EE_Cart |
|
| 811 | - */ |
|
| 812 | - private function _get_cart_for_transaction($transaction) |
|
| 813 | - { |
|
| 814 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - |
|
| 818 | - |
|
| 819 | - /** |
|
| 820 | - * get_cart_for_transaction |
|
| 821 | - * |
|
| 822 | - * @access public |
|
| 823 | - * @param EE_Transaction $transaction |
|
| 824 | - * @return EE_Cart |
|
| 825 | - */ |
|
| 826 | - public function get_cart_for_transaction(EE_Transaction $transaction) |
|
| 827 | - { |
|
| 828 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
| 829 | - } |
|
| 830 | - |
|
| 831 | - |
|
| 832 | - |
|
| 833 | - /** |
|
| 834 | - * _get_transaction_and_cart_for_current_session |
|
| 835 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
| 836 | - * |
|
| 837 | - * @access private |
|
| 838 | - * @return EE_Transaction |
|
| 839 | - * @throws \EE_Error |
|
| 840 | - */ |
|
| 841 | - private function _get_cart_for_current_session_and_setup_new_transaction() |
|
| 842 | - { |
|
| 843 | - // if there's no transaction, then this is the FIRST visit to SPCO |
|
| 844 | - // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
| 845 | - $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
| 846 | - // and then create a new transaction |
|
| 847 | - $transaction = $this->_initialize_transaction(); |
|
| 848 | - // verify transaction |
|
| 849 | - if ($transaction instanceof EE_Transaction) { |
|
| 850 | - // save it so that we have an ID for other objects to use |
|
| 851 | - $transaction->save(); |
|
| 852 | - // and save TXN data to the cart |
|
| 853 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
| 854 | - } else { |
|
| 855 | - EE_Error::add_error(__('A Valid Transaction could not be initialized.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 856 | - } |
|
| 857 | - return $transaction; |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - |
|
| 861 | - |
|
| 862 | - /** |
|
| 863 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
| 864 | - * |
|
| 865 | - * @access private |
|
| 866 | - * @return mixed EE_Transaction|NULL |
|
| 867 | - */ |
|
| 868 | - private function _initialize_transaction() |
|
| 869 | - { |
|
| 870 | - try { |
|
| 871 | - // ensure cart totals have been calculated |
|
| 872 | - $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
| 873 | - // grab the cart grand total |
|
| 874 | - $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
| 875 | - // create new TXN |
|
| 876 | - return EE_Transaction::new_instance( |
|
| 877 | - array( |
|
| 878 | - 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
| 879 | - 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
| 880 | - 'TXN_paid' => 0, |
|
| 881 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
| 882 | - ) |
|
| 883 | - ); |
|
| 884 | - } catch (Exception $e) { |
|
| 885 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 886 | - } |
|
| 887 | - return null; |
|
| 888 | - } |
|
| 889 | - |
|
| 890 | - |
|
| 891 | - |
|
| 892 | - /** |
|
| 893 | - * _get_registrations |
|
| 894 | - * |
|
| 895 | - * @access private |
|
| 896 | - * @param EE_Transaction $transaction |
|
| 897 | - * @return void |
|
| 898 | - * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
| 899 | - * @throws \EE_Error |
|
| 900 | - */ |
|
| 901 | - private function _get_registrations(EE_Transaction $transaction) |
|
| 902 | - { |
|
| 903 | - // first step: grab the registrants { : o |
|
| 904 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true); |
|
| 905 | - // verify registrations have been set |
|
| 906 | - if (empty($registrations)) { |
|
| 907 | - // if no cached registrations, then check the db |
|
| 908 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
| 909 | - // still nothing ? well as long as this isn't a revisit |
|
| 910 | - if (empty($registrations) && ! $this->checkout->revisit) { |
|
| 911 | - // generate new registrations from scratch |
|
| 912 | - $registrations = $this->_initialize_registrations($transaction); |
|
| 913 | - } |
|
| 914 | - } |
|
| 915 | - // sort by their original registration order |
|
| 916 | - usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
| 917 | - // then loop thru the array |
|
| 918 | - foreach ($registrations as $registration) { |
|
| 919 | - // verify each registration |
|
| 920 | - if ($registration instanceof EE_Registration) { |
|
| 921 | - // we display all attendee info for the primary registrant |
|
| 922 | - if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
| 923 | - && $registration->is_primary_registrant() |
|
| 924 | - ) { |
|
| 925 | - $this->checkout->primary_revisit = true; |
|
| 926 | - break; |
|
| 927 | - } else if ($this->checkout->revisit |
|
| 928 | - && $this->checkout->reg_url_link !== $registration->reg_url_link() |
|
| 929 | - ) { |
|
| 930 | - // but hide info if it doesn't belong to you |
|
| 931 | - $transaction->clear_cache('Registration', $registration->ID()); |
|
| 932 | - } |
|
| 933 | - $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
| 934 | - } |
|
| 935 | - } |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - |
|
| 939 | - |
|
| 940 | - /** |
|
| 941 | - * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
| 942 | - * |
|
| 943 | - * @access private |
|
| 944 | - * @param EE_Transaction $transaction |
|
| 945 | - * @return array |
|
| 946 | - * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
| 947 | - * @throws \EE_Error |
|
| 948 | - */ |
|
| 949 | - private function _initialize_registrations(EE_Transaction $transaction) |
|
| 950 | - { |
|
| 951 | - $att_nmbr = 0; |
|
| 952 | - $registrations = array(); |
|
| 953 | - if ($transaction instanceof EE_Transaction) { |
|
| 954 | - /** @type EE_Registration_Processor $registration_processor */ |
|
| 955 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 956 | - $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
| 957 | - // now let's add the cart items to the $transaction |
|
| 958 | - foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
| 959 | - //do the following for each ticket of this type they selected |
|
| 960 | - for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
| 961 | - $att_nmbr++; |
|
| 962 | - /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
| 963 | - $CreateRegistrationCommand = EE_Registry::instance() |
|
| 964 | - ->create( |
|
| 965 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 966 | - array( |
|
| 967 | - $transaction, |
|
| 968 | - $line_item, |
|
| 969 | - $att_nmbr, |
|
| 970 | - $this->checkout->total_ticket_count, |
|
| 971 | - ) |
|
| 972 | - ); |
|
| 973 | - // override capabilities for frontend registrations |
|
| 974 | - if ( ! is_admin()) { |
|
| 975 | - $CreateRegistrationCommand->setCapCheck( |
|
| 976 | - new PublicCapabilities('', 'create_new_registration') |
|
| 977 | - ); |
|
| 978 | - } |
|
| 979 | - $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
| 980 | - if ( ! $registration instanceof EE_Registration) { |
|
| 981 | - throw new InvalidEntityException($registration, 'EE_Registration'); |
|
| 982 | - } |
|
| 983 | - $registrations[ $registration->ID() ] = $registration; |
|
| 984 | - } |
|
| 985 | - } |
|
| 986 | - $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
| 987 | - } |
|
| 988 | - return $registrations; |
|
| 989 | - } |
|
| 990 | - |
|
| 991 | - |
|
| 992 | - |
|
| 993 | - /** |
|
| 994 | - * sorts registrations by REG_count |
|
| 995 | - * |
|
| 996 | - * @access public |
|
| 997 | - * @param EE_Registration $reg_A |
|
| 998 | - * @param EE_Registration $reg_B |
|
| 999 | - * @return int |
|
| 1000 | - */ |
|
| 1001 | - public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
| 1002 | - { |
|
| 1003 | - // this shouldn't ever happen within the same TXN, but oh well |
|
| 1004 | - if ($reg_A->count() === $reg_B->count()) { |
|
| 1005 | - return 0; |
|
| 1006 | - } |
|
| 1007 | - return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - |
|
| 1011 | - |
|
| 1012 | - /** |
|
| 1013 | - * _final_verifications |
|
| 1014 | - * just makes sure that everything is set up correctly before proceeding |
|
| 1015 | - * |
|
| 1016 | - * @access private |
|
| 1017 | - * @return bool |
|
| 1018 | - * @throws \EE_Error |
|
| 1019 | - */ |
|
| 1020 | - private function _final_verifications() |
|
| 1021 | - { |
|
| 1022 | - // filter checkout |
|
| 1023 | - $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout); |
|
| 1024 | - //verify that current step is still set correctly |
|
| 1025 | - if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
| 1026 | - EE_Error::add_error( |
|
| 1027 | - __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
| 1028 | - __FILE__, |
|
| 1029 | - __FUNCTION__, |
|
| 1030 | - __LINE__ |
|
| 1031 | - ); |
|
| 1032 | - return false; |
|
| 1033 | - } |
|
| 1034 | - // if returning to SPCO, then verify that primary registrant is set |
|
| 1035 | - if ( ! empty($this->checkout->reg_url_link)) { |
|
| 1036 | - $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
| 1037 | - if ( ! $valid_registrant instanceof EE_Registration) { |
|
| 1038 | - EE_Error::add_error( |
|
| 1039 | - __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
| 1040 | - __FILE__, |
|
| 1041 | - __FUNCTION__, |
|
| 1042 | - __LINE__ |
|
| 1043 | - ); |
|
| 1044 | - return false; |
|
| 1045 | - } |
|
| 1046 | - $valid_registrant = null; |
|
| 1047 | - foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) { |
|
| 1048 | - if ( |
|
| 1049 | - $registration instanceof EE_Registration |
|
| 1050 | - && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
| 1051 | - ) { |
|
| 1052 | - $valid_registrant = $registration; |
|
| 1053 | - } |
|
| 1054 | - } |
|
| 1055 | - if ( ! $valid_registrant instanceof EE_Registration) { |
|
| 1056 | - // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
| 1057 | - if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
| 1058 | - // clear the session, mark the checkout as unverified, and try again |
|
| 1059 | - EE_Registry::instance()->SSN->clear_session(); |
|
| 1060 | - EED_Single_Page_Checkout::$_initialized = false; |
|
| 1061 | - EED_Single_Page_Checkout::$_checkout_verified = false; |
|
| 1062 | - $this->_initialize(); |
|
| 1063 | - EE_Error::reset_notices(); |
|
| 1064 | - return false; |
|
| 1065 | - } |
|
| 1066 | - EE_Error::add_error( |
|
| 1067 | - __('We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
| 1068 | - __FILE__, |
|
| 1069 | - __FUNCTION__, |
|
| 1070 | - __LINE__ |
|
| 1071 | - ); |
|
| 1072 | - return false; |
|
| 1073 | - } |
|
| 1074 | - } |
|
| 1075 | - // now that things have been kinda sufficiently verified, |
|
| 1076 | - // let's add the checkout to the session so that's available other systems |
|
| 1077 | - EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
| 1078 | - return true; |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - |
|
| 1082 | - |
|
| 1083 | - /** |
|
| 1084 | - * _initialize_reg_steps |
|
| 1085 | - * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
| 1086 | - * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
| 1087 | - * |
|
| 1088 | - * @access private |
|
| 1089 | - * @param bool $reinitializing |
|
| 1090 | - * @throws \EE_Error |
|
| 1091 | - */ |
|
| 1092 | - private function _initialize_reg_steps($reinitializing = false) |
|
| 1093 | - { |
|
| 1094 | - $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
| 1095 | - // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
| 1096 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
| 1097 | - if ( ! $reg_step->initialize_reg_step()) { |
|
| 1098 | - // if not initialized then maybe this step is being removed... |
|
| 1099 | - if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
| 1100 | - // if it was the current step, then we need to start over here |
|
| 1101 | - $this->_initialize_reg_steps(true); |
|
| 1102 | - return; |
|
| 1103 | - } |
|
| 1104 | - continue; |
|
| 1105 | - } |
|
| 1106 | - // add css and JS for current step |
|
| 1107 | - $reg_step->enqueue_styles_and_scripts(); |
|
| 1108 | - // i18n |
|
| 1109 | - $reg_step->translate_js_strings(); |
|
| 1110 | - if ($reg_step->is_current_step()) { |
|
| 1111 | - // the text that appears on the reg step form submit button |
|
| 1112 | - $reg_step->set_submit_button_text(); |
|
| 1113 | - } |
|
| 1114 | - } |
|
| 1115 | - // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
| 1116 | - do_action("AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step); |
|
| 1117 | - } |
|
| 1118 | - |
|
| 1119 | - |
|
| 1120 | - |
|
| 1121 | - /** |
|
| 1122 | - * _check_form_submission |
|
| 1123 | - * |
|
| 1124 | - * @access private |
|
| 1125 | - * @return void |
|
| 1126 | - */ |
|
| 1127 | - private function _check_form_submission() |
|
| 1128 | - { |
|
| 1129 | - //does this request require the reg form to be generated ? |
|
| 1130 | - if ($this->checkout->generate_reg_form) { |
|
| 1131 | - // ever heard that song by Blue Rodeo ? |
|
| 1132 | - try { |
|
| 1133 | - $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
| 1134 | - // if not displaying a form, then check for form submission |
|
| 1135 | - if ($this->checkout->process_form_submission && $this->checkout->current_step->reg_form->was_submitted()) { |
|
| 1136 | - // clear out any old data in case this step is being run again |
|
| 1137 | - $this->checkout->current_step->set_valid_data(array()); |
|
| 1138 | - // capture submitted form data |
|
| 1139 | - $this->checkout->current_step->reg_form->receive_form_submission( |
|
| 1140 | - apply_filters('FHEE__Single_Page_Checkout___check_form_submission__request_params', EE_Registry::instance()->REQ->params(), $this->checkout) |
|
| 1141 | - ); |
|
| 1142 | - // validate submitted form data |
|
| 1143 | - if ( ! $this->checkout->continue_reg && ! $this->checkout->current_step->reg_form->is_valid()) { |
|
| 1144 | - // thou shall not pass !!! |
|
| 1145 | - $this->checkout->continue_reg = false; |
|
| 1146 | - // any form validation errors? |
|
| 1147 | - if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
| 1148 | - $submission_error_messages = array(); |
|
| 1149 | - // bad, bad, bad registrant |
|
| 1150 | - foreach ($this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1151 | - if ($validation_error instanceof EE_Validation_Error) { |
|
| 1152 | - $submission_error_messages[] = sprintf( |
|
| 1153 | - __('%s : %s', 'event_espresso'), |
|
| 1154 | - $validation_error->get_form_section()->html_label_text(), |
|
| 1155 | - $validation_error->getMessage() |
|
| 1156 | - ); |
|
| 1157 | - } |
|
| 1158 | - } |
|
| 1159 | - EE_Error::add_error(implode('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); |
|
| 1160 | - } |
|
| 1161 | - // well not really... what will happen is we'll just get redirected back to redo the current step |
|
| 1162 | - $this->go_to_next_step(); |
|
| 1163 | - return; |
|
| 1164 | - } |
|
| 1165 | - } |
|
| 1166 | - } catch (EE_Error $e) { |
|
| 1167 | - $e->get_error(); |
|
| 1168 | - } |
|
| 1169 | - } |
|
| 1170 | - } |
|
| 1171 | - |
|
| 1172 | - |
|
| 1173 | - |
|
| 1174 | - /** |
|
| 1175 | - * _process_action |
|
| 1176 | - * |
|
| 1177 | - * @access private |
|
| 1178 | - * @return void |
|
| 1179 | - * @throws \EE_Error |
|
| 1180 | - */ |
|
| 1181 | - private function _process_form_action() |
|
| 1182 | - { |
|
| 1183 | - // what cha wanna do? |
|
| 1184 | - switch ($this->checkout->action) { |
|
| 1185 | - // AJAX next step reg form |
|
| 1186 | - case 'display_spco_reg_step' : |
|
| 1187 | - $this->checkout->redirect = false; |
|
| 1188 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 1189 | - $this->checkout->json_response->set_reg_step_html($this->checkout->current_step->display_reg_form()); |
|
| 1190 | - } |
|
| 1191 | - break; |
|
| 1192 | - default : |
|
| 1193 | - // meh... do one of those other steps first |
|
| 1194 | - if ( ! empty($this->checkout->action) && is_callable(array($this->checkout->current_step, $this->checkout->action))) { |
|
| 1195 | - // dynamically creates hook point like: AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
| 1196 | - do_action("AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step); |
|
| 1197 | - // call action on current step |
|
| 1198 | - if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
| 1199 | - // good registrant, you get to proceed |
|
| 1200 | - if ( |
|
| 1201 | - $this->checkout->current_step->success_message() !== '' |
|
| 1202 | - && apply_filters( |
|
| 1203 | - 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
| 1204 | - false |
|
| 1205 | - ) |
|
| 1206 | - ) { |
|
| 1207 | - EE_Error::add_success( |
|
| 1208 | - $this->checkout->current_step->success_message() |
|
| 1209 | - . '<br />' . $this->checkout->next_step->_instructions() |
|
| 1210 | - ); |
|
| 1211 | - } |
|
| 1212 | - // pack it up, pack it in... |
|
| 1213 | - $this->_setup_redirect(); |
|
| 1214 | - } |
|
| 1215 | - // dynamically creates hook point like: AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
| 1216 | - do_action("AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step); |
|
| 1217 | - } else { |
|
| 1218 | - EE_Error::add_error( |
|
| 1219 | - sprintf( |
|
| 1220 | - __('The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso'), |
|
| 1221 | - $this->checkout->action, |
|
| 1222 | - $this->checkout->current_step->name() |
|
| 1223 | - ), |
|
| 1224 | - __FILE__, |
|
| 1225 | - __FUNCTION__, |
|
| 1226 | - __LINE__ |
|
| 1227 | - ); |
|
| 1228 | - } |
|
| 1229 | - // end default |
|
| 1230 | - } |
|
| 1231 | - // store our progress so far |
|
| 1232 | - $this->checkout->stash_transaction_and_checkout(); |
|
| 1233 | - // advance to the next step! If you pass GO, collect $200 |
|
| 1234 | - $this->go_to_next_step(); |
|
| 1235 | - } |
|
| 1236 | - |
|
| 1237 | - |
|
| 1238 | - |
|
| 1239 | - /** |
|
| 1240 | - * add_styles_and_scripts |
|
| 1241 | - * |
|
| 1242 | - * @access public |
|
| 1243 | - * @return void |
|
| 1244 | - */ |
|
| 1245 | - public function add_styles_and_scripts() |
|
| 1246 | - { |
|
| 1247 | - // i18n |
|
| 1248 | - $this->translate_js_strings(); |
|
| 1249 | - if ($this->checkout->admin_request) { |
|
| 1250 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
| 1251 | - } else { |
|
| 1252 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
| 1253 | - } |
|
| 1254 | - } |
|
| 1255 | - |
|
| 1256 | - |
|
| 1257 | - |
|
| 1258 | - /** |
|
| 1259 | - * translate_js_strings |
|
| 1260 | - * |
|
| 1261 | - * @access public |
|
| 1262 | - * @return void |
|
| 1263 | - */ |
|
| 1264 | - public function translate_js_strings() |
|
| 1265 | - { |
|
| 1266 | - EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
| 1267 | - EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
| 1268 | - EE_Registry::$i18n_js_strings['server_error'] = __('An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
|
| 1269 | - EE_Registry::$i18n_js_strings['invalid_json_response'] = __('An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
|
| 1270 | - EE_Registry::$i18n_js_strings['validation_error'] = __('There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', 'event_espresso'); |
|
| 1271 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = __('There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', 'event_espresso'); |
|
| 1272 | - EE_Registry::$i18n_js_strings['reg_step_error'] = __('This registration step could not be completed. Please refresh the page and try again.', 'event_espresso'); |
|
| 1273 | - EE_Registry::$i18n_js_strings['invalid_coupon'] = __('We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', 'event_espresso'); |
|
| 1274 | - EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
| 1275 | - __('Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', 'event_espresso'), |
|
| 1276 | - '<br/>', |
|
| 1277 | - '<br/>' |
|
| 1278 | - ); |
|
| 1279 | - EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
| 1280 | - EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
| 1281 | - EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
| 1282 | - EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
| 1283 | - EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
| 1284 | - EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
| 1285 | - EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
| 1286 | - EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
| 1287 | - EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
| 1288 | - EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
| 1289 | - EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
| 1290 | - EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
| 1291 | - EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
| 1292 | - EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
| 1293 | - EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
| 1294 | - EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
| 1295 | - EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
| 1296 | - EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
| 1297 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
| 1298 | - __( |
|
| 1299 | - '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
| 1300 | - 'event_espresso' |
|
| 1301 | - ), |
|
| 1302 | - '<h4 class="important-notice">', |
|
| 1303 | - '</h4>', |
|
| 1304 | - '<br />', |
|
| 1305 | - '<p>', |
|
| 1306 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
| 1307 | - '">', |
|
| 1308 | - '</a>', |
|
| 1309 | - '</p>' |
|
| 1310 | - ); |
|
| 1311 | - EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters('FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true); |
|
| 1312 | - } |
|
| 1313 | - |
|
| 1314 | - |
|
| 1315 | - |
|
| 1316 | - /** |
|
| 1317 | - * enqueue_styles_and_scripts |
|
| 1318 | - * |
|
| 1319 | - * @access public |
|
| 1320 | - * @return void |
|
| 1321 | - * @throws \EE_Error |
|
| 1322 | - */ |
|
| 1323 | - public function enqueue_styles_and_scripts() |
|
| 1324 | - { |
|
| 1325 | - // load css |
|
| 1326 | - wp_register_style('single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1327 | - wp_enqueue_style('single_page_checkout'); |
|
| 1328 | - // load JS |
|
| 1329 | - wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', array('jquery'), '1.0.1', true); |
|
| 1330 | - wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', array('jquery_plugin'), '2.0.2', true); |
|
| 1331 | - wp_register_script('single_page_checkout', SPCO_JS_URL . 'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, true); |
|
| 1332 | - $this->checkout->registration_form->enqueue_js(); |
|
| 1333 | - $this->checkout->current_step->reg_form->enqueue_js(); |
|
| 1334 | - wp_enqueue_script('single_page_checkout'); |
|
| 1335 | - /** |
|
| 1336 | - * global action hook for enqueueing styles and scripts with |
|
| 1337 | - * spco calls. |
|
| 1338 | - */ |
|
| 1339 | - do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
| 1340 | - /** |
|
| 1341 | - * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
| 1342 | - * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
| 1343 | - */ |
|
| 1344 | - do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this); |
|
| 1345 | - } |
|
| 1346 | - |
|
| 1347 | - |
|
| 1348 | - |
|
| 1349 | - /** |
|
| 1350 | - * display the Registration Single Page Checkout Form |
|
| 1351 | - * |
|
| 1352 | - * @access private |
|
| 1353 | - * @return void |
|
| 1354 | - * @throws \EE_Error |
|
| 1355 | - */ |
|
| 1356 | - private function _display_spco_reg_form() |
|
| 1357 | - { |
|
| 1358 | - // if registering via the admin, just display the reg form for the current step |
|
| 1359 | - if ($this->checkout->admin_request) { |
|
| 1360 | - EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
| 1361 | - } else { |
|
| 1362 | - // add powered by EE msg |
|
| 1363 | - add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
| 1364 | - $empty_cart = count($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)) < 1 ? true : false; |
|
| 1365 | - $cookies_not_set_msg = ''; |
|
| 1366 | - if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) { |
|
| 1367 | - $cookies_not_set_msg = apply_filters( |
|
| 1368 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
| 1369 | - sprintf( |
|
| 1370 | - __( |
|
| 1371 | - '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', |
|
| 1372 | - 'event_espresso' |
|
| 1373 | - ), |
|
| 1374 | - '<div class="ee-attention">', |
|
| 1375 | - '</div>', |
|
| 1376 | - '<h6 class="important-notice">', |
|
| 1377 | - '</h6>', |
|
| 1378 | - '<p>', |
|
| 1379 | - '</p>', |
|
| 1380 | - '<br />', |
|
| 1381 | - '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', |
|
| 1382 | - '</a>' |
|
| 1383 | - ) |
|
| 1384 | - ); |
|
| 1385 | - } |
|
| 1386 | - $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
| 1387 | - array( |
|
| 1388 | - 'name' => 'single-page-checkout', |
|
| 1389 | - 'html_id' => 'ee-single-page-checkout-dv', |
|
| 1390 | - 'layout_strategy' => |
|
| 1391 | - new EE_Template_Layout( |
|
| 1392 | - array( |
|
| 1393 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
| 1394 | - 'template_args' => array( |
|
| 1395 | - 'empty_cart' => $empty_cart, |
|
| 1396 | - 'revisit' => $this->checkout->revisit, |
|
| 1397 | - 'reg_steps' => $this->checkout->reg_steps, |
|
| 1398 | - 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step ? $this->checkout->next_step->slug() : '', |
|
| 1399 | - 'empty_msg' => apply_filters( |
|
| 1400 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
| 1401 | - sprintf( |
|
| 1402 | - __('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', 'event_espresso'), |
|
| 1403 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
| 1404 | - '">', |
|
| 1405 | - '</a>' |
|
| 1406 | - ) |
|
| 1407 | - ), |
|
| 1408 | - 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
| 1409 | - 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
| 1410 | - 'session_expiration' => |
|
| 1411 | - date('M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)), |
|
| 1412 | - ), |
|
| 1413 | - ) |
|
| 1414 | - ), |
|
| 1415 | - ) |
|
| 1416 | - ); |
|
| 1417 | - // load template and add to output sent that gets filtered into the_content() |
|
| 1418 | - EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
| 1419 | - } |
|
| 1420 | - } |
|
| 1421 | - |
|
| 1422 | - |
|
| 1423 | - |
|
| 1424 | - /** |
|
| 1425 | - * add_extra_finalize_registration_inputs |
|
| 1426 | - * |
|
| 1427 | - * @access public |
|
| 1428 | - * @param $next_step |
|
| 1429 | - * @internal param string $label |
|
| 1430 | - * @return void |
|
| 1431 | - */ |
|
| 1432 | - public function add_extra_finalize_registration_inputs($next_step) |
|
| 1433 | - { |
|
| 1434 | - if ($next_step === 'finalize_registration') { |
|
| 1435 | - echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
| 1436 | - } |
|
| 1437 | - } |
|
| 1438 | - |
|
| 1439 | - |
|
| 1440 | - |
|
| 1441 | - /** |
|
| 1442 | - * display_registration_footer |
|
| 1443 | - * |
|
| 1444 | - * @access public |
|
| 1445 | - * @return string |
|
| 1446 | - */ |
|
| 1447 | - public static function display_registration_footer() |
|
| 1448 | - { |
|
| 1449 | - if ( |
|
| 1450 | - apply_filters( |
|
| 1451 | - 'FHEE__EE_Front__Controller__show_reg_footer', |
|
| 1452 | - EE_Registry::instance()->CFG->admin->show_reg_footer |
|
| 1453 | - ) |
|
| 1454 | - ) { |
|
| 1455 | - add_filter( |
|
| 1456 | - 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
| 1457 | - function ($url) { |
|
| 1458 | - return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
| 1459 | - } |
|
| 1460 | - ); |
|
| 1461 | - echo apply_filters( |
|
| 1462 | - 'FHEE__EE_Front_Controller__display_registration_footer', |
|
| 1463 | - \EEH_Template::powered_by_event_espresso( |
|
| 1464 | - '', |
|
| 1465 | - 'espresso-registration-footer-dv', |
|
| 1466 | - array('utm_content' => 'registration_checkout') |
|
| 1467 | - ) |
|
| 1468 | - ); |
|
| 1469 | - } |
|
| 1470 | - return ''; |
|
| 1471 | - } |
|
| 1472 | - |
|
| 1473 | - |
|
| 1474 | - |
|
| 1475 | - /** |
|
| 1476 | - * unlock_transaction |
|
| 1477 | - * |
|
| 1478 | - * @access public |
|
| 1479 | - * @return void |
|
| 1480 | - * @throws \EE_Error |
|
| 1481 | - */ |
|
| 1482 | - public function unlock_transaction() |
|
| 1483 | - { |
|
| 1484 | - if ($this->checkout->transaction instanceof EE_Transaction) { |
|
| 1485 | - $this->checkout->transaction->unlock(); |
|
| 1486 | - } |
|
| 1487 | - } |
|
| 1488 | - |
|
| 1489 | - |
|
| 1490 | - |
|
| 1491 | - /** |
|
| 1492 | - * _setup_redirect |
|
| 1493 | - * |
|
| 1494 | - * @access private |
|
| 1495 | - * @return void |
|
| 1496 | - */ |
|
| 1497 | - private function _setup_redirect() |
|
| 1498 | - { |
|
| 1499 | - if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
| 1500 | - $this->checkout->redirect = true; |
|
| 1501 | - if (empty($this->checkout->redirect_url)) { |
|
| 1502 | - $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
| 1503 | - } |
|
| 1504 | - $this->checkout->redirect_url = apply_filters( |
|
| 1505 | - 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
| 1506 | - $this->checkout->redirect_url, |
|
| 1507 | - $this->checkout |
|
| 1508 | - ); |
|
| 1509 | - } |
|
| 1510 | - } |
|
| 1511 | - |
|
| 1512 | - |
|
| 1513 | - |
|
| 1514 | - /** |
|
| 1515 | - * handle ajax message responses and redirects |
|
| 1516 | - * |
|
| 1517 | - * @access public |
|
| 1518 | - * @return void |
|
| 1519 | - * @throws \EE_Error |
|
| 1520 | - */ |
|
| 1521 | - public function go_to_next_step() |
|
| 1522 | - { |
|
| 1523 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 1524 | - // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
| 1525 | - $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
| 1526 | - } |
|
| 1527 | - $this->unlock_transaction(); |
|
| 1528 | - // just return for these conditions |
|
| 1529 | - if ( |
|
| 1530 | - $this->checkout->admin_request |
|
| 1531 | - || $this->checkout->action === 'redirect_form' |
|
| 1532 | - || $this->checkout->action === 'update_checkout' |
|
| 1533 | - ) { |
|
| 1534 | - return; |
|
| 1535 | - } |
|
| 1536 | - // AJAX response |
|
| 1537 | - $this->_handle_json_response(); |
|
| 1538 | - // redirect to next step or the Thank You page |
|
| 1539 | - $this->_handle_html_redirects(); |
|
| 1540 | - // hmmm... must be something wrong, so let's just display the form again ! |
|
| 1541 | - $this->_display_spco_reg_form(); |
|
| 1542 | - } |
|
| 1543 | - |
|
| 1544 | - |
|
| 1545 | - |
|
| 1546 | - /** |
|
| 1547 | - * _handle_json_response |
|
| 1548 | - * |
|
| 1549 | - * @access protected |
|
| 1550 | - * @return void |
|
| 1551 | - */ |
|
| 1552 | - protected function _handle_json_response() |
|
| 1553 | - { |
|
| 1554 | - // if this is an ajax request |
|
| 1555 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 1556 | - // DEBUG LOG |
|
| 1557 | - //$this->checkout->log( |
|
| 1558 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
| 1559 | - // array( |
|
| 1560 | - // 'json_response_redirect_url' => $this->checkout->json_response->redirect_url(), |
|
| 1561 | - // 'redirect' => $this->checkout->redirect, |
|
| 1562 | - // 'continue_reg' => $this->checkout->continue_reg, |
|
| 1563 | - // ) |
|
| 1564 | - //); |
|
| 1565 | - $this->checkout->json_response->set_registration_time_limit( |
|
| 1566 | - $this->checkout->get_registration_time_limit() |
|
| 1567 | - ); |
|
| 1568 | - $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
| 1569 | - // just send the ajax ( |
|
| 1570 | - $json_response = apply_filters( |
|
| 1571 | - 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
| 1572 | - $this->checkout->json_response |
|
| 1573 | - ); |
|
| 1574 | - echo $json_response; |
|
| 1575 | - exit(); |
|
| 1576 | - } |
|
| 1577 | - } |
|
| 1578 | - |
|
| 1579 | - |
|
| 1580 | - |
|
| 1581 | - /** |
|
| 1582 | - * _handle_redirects |
|
| 1583 | - * |
|
| 1584 | - * @access protected |
|
| 1585 | - * @return void |
|
| 1586 | - */ |
|
| 1587 | - protected function _handle_html_redirects() |
|
| 1588 | - { |
|
| 1589 | - // going somewhere ? |
|
| 1590 | - if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
| 1591 | - // store notices in a transient |
|
| 1592 | - EE_Error::get_notices(false, true, true); |
|
| 1593 | - // DEBUG LOG |
|
| 1594 | - //$this->checkout->log( |
|
| 1595 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
| 1596 | - // array( |
|
| 1597 | - // 'headers_sent' => headers_sent(), |
|
| 1598 | - // 'redirect_url' => $this->checkout->redirect_url, |
|
| 1599 | - // 'headers_list' => headers_list(), |
|
| 1600 | - // ) |
|
| 1601 | - //); |
|
| 1602 | - wp_safe_redirect($this->checkout->redirect_url); |
|
| 1603 | - exit(); |
|
| 1604 | - } |
|
| 1605 | - } |
|
| 1606 | - |
|
| 1607 | - |
|
| 1608 | - |
|
| 1609 | - /** |
|
| 1610 | - * set_checkout_anchor |
|
| 1611 | - * |
|
| 1612 | - * @access public |
|
| 1613 | - * @return void |
|
| 1614 | - */ |
|
| 1615 | - public function set_checkout_anchor() |
|
| 1616 | - { |
|
| 1617 | - echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
| 1618 | - } |
|
| 20 | + /** |
|
| 21 | + * $_initialized - has the SPCO controller already been initialized ? |
|
| 22 | + * |
|
| 23 | + * @access private |
|
| 24 | + * @var bool $_initialized |
|
| 25 | + */ |
|
| 26 | + private static $_initialized = false; |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
| 31 | + * |
|
| 32 | + * @access private |
|
| 33 | + * @var bool $_valid_checkout |
|
| 34 | + */ |
|
| 35 | + private static $_checkout_verified = true; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * $_reg_steps_array - holds initial array of reg steps |
|
| 39 | + * |
|
| 40 | + * @access private |
|
| 41 | + * @var array $_reg_steps_array |
|
| 42 | + */ |
|
| 43 | + private static $_reg_steps_array = array(); |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
| 47 | + * |
|
| 48 | + * @access public |
|
| 49 | + * @var EE_Checkout $checkout |
|
| 50 | + */ |
|
| 51 | + public $checkout; |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @return EED_Single_Page_Checkout |
|
| 57 | + */ |
|
| 58 | + public static function instance() |
|
| 59 | + { |
|
| 60 | + add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
| 61 | + return parent::get_instance(__CLASS__); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @return EE_CART |
|
| 68 | + */ |
|
| 69 | + public function cart() |
|
| 70 | + { |
|
| 71 | + return $this->checkout->cart; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @return EE_Transaction |
|
| 78 | + */ |
|
| 79 | + public function transaction() |
|
| 80 | + { |
|
| 81 | + return $this->checkout->transaction; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 88 | + * |
|
| 89 | + * @access public |
|
| 90 | + * @return void |
|
| 91 | + * @throws \EE_Error |
|
| 92 | + */ |
|
| 93 | + public static function set_hooks() |
|
| 94 | + { |
|
| 95 | + EED_Single_Page_Checkout::set_definitions(); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 102 | + * |
|
| 103 | + * @access public |
|
| 104 | + * @return void |
|
| 105 | + * @throws \EE_Error |
|
| 106 | + */ |
|
| 107 | + public static function set_hooks_admin() |
|
| 108 | + { |
|
| 109 | + EED_Single_Page_Checkout::set_definitions(); |
|
| 110 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 111 | + // hook into the top of pre_get_posts to set the reg step routing, which gives other modules or plugins a chance to modify the reg steps, but just before the routes get called |
|
| 112 | + add_action('pre_get_posts', array('EED_Single_Page_Checkout', 'load_reg_steps'), 1); |
|
| 113 | + return; |
|
| 114 | + } |
|
| 115 | + // going to start an output buffer in case anything gets accidentally output that might disrupt our JSON response |
|
| 116 | + ob_start(); |
|
| 117 | + EED_Single_Page_Checkout::load_request_handler(); |
|
| 118 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
| 119 | + // set ajax hooks |
|
| 120 | + add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
| 121 | + add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
| 122 | + add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
| 123 | + add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
| 124 | + add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
| 125 | + add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * process ajax request |
|
| 132 | + * |
|
| 133 | + * @param string $ajax_action |
|
| 134 | + * @throws \EE_Error |
|
| 135 | + */ |
|
| 136 | + public static function process_ajax_request($ajax_action) |
|
| 137 | + { |
|
| 138 | + EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
| 139 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * ajax display registration step |
|
| 146 | + * |
|
| 147 | + * @throws \EE_Error |
|
| 148 | + */ |
|
| 149 | + public static function display_reg_step() |
|
| 150 | + { |
|
| 151 | + EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * ajax process registration step |
|
| 158 | + * |
|
| 159 | + * @throws \EE_Error |
|
| 160 | + */ |
|
| 161 | + public static function process_reg_step() |
|
| 162 | + { |
|
| 163 | + EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * ajax process registration step |
|
| 170 | + * |
|
| 171 | + * @throws \EE_Error |
|
| 172 | + */ |
|
| 173 | + public static function update_reg_step() |
|
| 174 | + { |
|
| 175 | + EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * update_checkout |
|
| 182 | + * |
|
| 183 | + * @access public |
|
| 184 | + * @return void |
|
| 185 | + * @throws \EE_Error |
|
| 186 | + */ |
|
| 187 | + public static function update_checkout() |
|
| 188 | + { |
|
| 189 | + EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * load_request_handler |
|
| 196 | + * |
|
| 197 | + * @access public |
|
| 198 | + * @return void |
|
| 199 | + */ |
|
| 200 | + public static function load_request_handler() |
|
| 201 | + { |
|
| 202 | + // load core Request_Handler class |
|
| 203 | + if ( ! isset(EE_Registry::instance()->REQ)) { |
|
| 204 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * set_definitions |
|
| 212 | + * |
|
| 213 | + * @access public |
|
| 214 | + * @return void |
|
| 215 | + * @throws \EE_Error |
|
| 216 | + */ |
|
| 217 | + public static function set_definitions() |
|
| 218 | + { |
|
| 219 | + define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS); |
|
| 220 | + define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
| 221 | + define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
| 222 | + define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
| 223 | + define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
| 224 | + define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
| 225 | + define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
| 226 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * load_reg_steps |
|
| 233 | + * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
| 234 | + * |
|
| 235 | + * @access private |
|
| 236 | + * @throws EE_Error |
|
| 237 | + * @return void |
|
| 238 | + */ |
|
| 239 | + public static function load_reg_steps() |
|
| 240 | + { |
|
| 241 | + static $reg_steps_loaded = false; |
|
| 242 | + if ($reg_steps_loaded) { |
|
| 243 | + return; |
|
| 244 | + } |
|
| 245 | + // filter list of reg_steps |
|
| 246 | + $reg_steps_to_load = (array)apply_filters( |
|
| 247 | + 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
| 248 | + EED_Single_Page_Checkout::get_reg_steps() |
|
| 249 | + ); |
|
| 250 | + // sort by key (order) |
|
| 251 | + ksort($reg_steps_to_load); |
|
| 252 | + // loop through folders |
|
| 253 | + foreach ($reg_steps_to_load as $order => $reg_step) { |
|
| 254 | + // we need a |
|
| 255 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
| 256 | + // copy over to the reg_steps_array |
|
| 257 | + EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step; |
|
| 258 | + // register custom key route for each reg step |
|
| 259 | + // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
| 260 | + EE_Config::register_route($reg_step['slug'], 'EED_Single_Page_Checkout', 'run', 'step'); |
|
| 261 | + // add AJAX or other hooks |
|
| 262 | + if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
| 263 | + // setup autoloaders if necessary |
|
| 264 | + if ( ! class_exists($reg_step['class_name'])) { |
|
| 265 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($reg_step['file_path'], true); |
|
| 266 | + } |
|
| 267 | + if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
| 268 | + call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + $reg_steps_loaded = true; |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * get_reg_steps |
|
| 280 | + * |
|
| 281 | + * @access public |
|
| 282 | + * @return array |
|
| 283 | + */ |
|
| 284 | + public static function get_reg_steps() |
|
| 285 | + { |
|
| 286 | + $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
| 287 | + if (empty($reg_steps)) { |
|
| 288 | + $reg_steps = array( |
|
| 289 | + 10 => array( |
|
| 290 | + 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
| 291 | + 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
| 292 | + 'slug' => 'attendee_information', |
|
| 293 | + 'has_hooks' => false, |
|
| 294 | + ), |
|
| 295 | + 20 => array( |
|
| 296 | + 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
| 297 | + 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
|
| 298 | + 'slug' => 'registration_confirmation', |
|
| 299 | + 'has_hooks' => false, |
|
| 300 | + ), |
|
| 301 | + 30 => array( |
|
| 302 | + 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
| 303 | + 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
| 304 | + 'slug' => 'payment_options', |
|
| 305 | + 'has_hooks' => true, |
|
| 306 | + ), |
|
| 307 | + 999 => array( |
|
| 308 | + 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
| 309 | + 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
| 310 | + 'slug' => 'finalize_registration', |
|
| 311 | + 'has_hooks' => false, |
|
| 312 | + ), |
|
| 313 | + ); |
|
| 314 | + } |
|
| 315 | + return $reg_steps; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * registration_checkout_for_admin |
|
| 322 | + * |
|
| 323 | + * @access public |
|
| 324 | + * @return string |
|
| 325 | + * @throws \EE_Error |
|
| 326 | + */ |
|
| 327 | + public static function registration_checkout_for_admin() |
|
| 328 | + { |
|
| 329 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
| 330 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
| 331 | + EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
| 332 | + EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
| 333 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 334 | + EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
| 335 | + return EE_Registry::instance()->REQ->get_output(); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * process_registration_from_admin |
|
| 342 | + * |
|
| 343 | + * @access public |
|
| 344 | + * @return \EE_Transaction |
|
| 345 | + * @throws \EE_Error |
|
| 346 | + */ |
|
| 347 | + public static function process_registration_from_admin() |
|
| 348 | + { |
|
| 349 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
| 350 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
| 351 | + EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
| 352 | + EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
| 353 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 354 | + if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
| 355 | + $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
| 356 | + if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
| 357 | + EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
| 358 | + if ($final_reg_step->process_reg_step()) { |
|
| 359 | + $final_reg_step->set_completed(); |
|
| 360 | + EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
| 361 | + return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
| 362 | + } |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + return null; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * run |
|
| 372 | + * |
|
| 373 | + * @access public |
|
| 374 | + * @param WP_Query $WP_Query |
|
| 375 | + * @return void |
|
| 376 | + * @throws \EE_Error |
|
| 377 | + */ |
|
| 378 | + public function run($WP_Query) |
|
| 379 | + { |
|
| 380 | + if ( |
|
| 381 | + $WP_Query instanceof WP_Query |
|
| 382 | + && $WP_Query->is_main_query() |
|
| 383 | + && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
| 384 | + && $this->_is_reg_checkout() |
|
| 385 | + ) { |
|
| 386 | + $this->_initialize(); |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * determines whether current url matches reg page url |
|
| 394 | + * |
|
| 395 | + * @return bool |
|
| 396 | + */ |
|
| 397 | + protected function _is_reg_checkout() |
|
| 398 | + { |
|
| 399 | + // get current permalink for reg page without any extra query args |
|
| 400 | + $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
| 401 | + // get request URI for current request, but without the scheme or host |
|
| 402 | + $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
| 403 | + $current_request_uri = html_entity_decode($current_request_uri); |
|
| 404 | + // get array of query args from the current request URI |
|
| 405 | + $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
| 406 | + // grab page id if it is set |
|
| 407 | + $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
| 408 | + // and remove the page id from the query args (we will re-add it later) |
|
| 409 | + unset($query_args['page_id']); |
|
| 410 | + // now strip all query args from current request URI |
|
| 411 | + $current_request_uri = remove_query_arg(array_flip($query_args), $current_request_uri); |
|
| 412 | + // and re-add the page id if it was set |
|
| 413 | + if ($page_id) { |
|
| 414 | + $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
| 415 | + } |
|
| 416 | + // remove slashes and ? |
|
| 417 | + $current_request_uri = trim($current_request_uri, '?/'); |
|
| 418 | + // is current request URI part of the known full reg page URL ? |
|
| 419 | + return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * run |
|
| 426 | + * |
|
| 427 | + * @access public |
|
| 428 | + * @param WP_Query $WP_Query |
|
| 429 | + * @return void |
|
| 430 | + * @throws \EE_Error |
|
| 431 | + */ |
|
| 432 | + public static function init($WP_Query) |
|
| 433 | + { |
|
| 434 | + EED_Single_Page_Checkout::instance()->run($WP_Query); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * _initialize - initial module setup |
|
| 441 | + * |
|
| 442 | + * @access private |
|
| 443 | + * @throws EE_Error |
|
| 444 | + * @return void |
|
| 445 | + */ |
|
| 446 | + private function _initialize() |
|
| 447 | + { |
|
| 448 | + // ensure SPCO doesn't run twice |
|
| 449 | + if (EED_Single_Page_Checkout::$_initialized) { |
|
| 450 | + return; |
|
| 451 | + } |
|
| 452 | + try { |
|
| 453 | + // setup the EE_Checkout object |
|
| 454 | + $this->checkout = $this->_initialize_checkout(); |
|
| 455 | + // filter checkout |
|
| 456 | + $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
| 457 | + // get the $_GET |
|
| 458 | + $this->_get_request_vars(); |
|
| 459 | + if ($this->_block_bots()) { |
|
| 460 | + return; |
|
| 461 | + } |
|
| 462 | + // filter continue_reg |
|
| 463 | + $this->checkout->continue_reg = apply_filters('FHEE__EED_Single_Page_Checkout__init___continue_reg', true, $this->checkout); |
|
| 464 | + // load the reg steps array |
|
| 465 | + if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
| 466 | + EED_Single_Page_Checkout::$_initialized = true; |
|
| 467 | + return; |
|
| 468 | + } |
|
| 469 | + // set the current step |
|
| 470 | + $this->checkout->set_current_step($this->checkout->step); |
|
| 471 | + // and the next step |
|
| 472 | + $this->checkout->set_next_step(); |
|
| 473 | + // was there already a valid transaction in the checkout from the session ? |
|
| 474 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 475 | + // get transaction from db or session |
|
| 476 | + $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
| 477 | + ? $this->_get_transaction_and_cart_for_previous_visit() |
|
| 478 | + : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
| 479 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 480 | + // add some style and make it dance |
|
| 481 | + $this->checkout->transaction = EE_Transaction::new_instance(); |
|
| 482 | + $this->add_styles_and_scripts(); |
|
| 483 | + EED_Single_Page_Checkout::$_initialized = true; |
|
| 484 | + return; |
|
| 485 | + } |
|
| 486 | + // and the registrations for the transaction |
|
| 487 | + $this->_get_registrations($this->checkout->transaction); |
|
| 488 | + } |
|
| 489 | + // verify that everything has been setup correctly |
|
| 490 | + if ( ! $this->_final_verifications()) { |
|
| 491 | + EED_Single_Page_Checkout::$_initialized = true; |
|
| 492 | + return; |
|
| 493 | + } |
|
| 494 | + // lock the transaction |
|
| 495 | + $this->checkout->transaction->lock(); |
|
| 496 | + // make sure all of our cached objects are added to their respective model entity mappers |
|
| 497 | + $this->checkout->refresh_all_entities(); |
|
| 498 | + // set amount owing |
|
| 499 | + $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
| 500 | + // initialize each reg step, which gives them the chance to potentially alter the process |
|
| 501 | + $this->_initialize_reg_steps(); |
|
| 502 | + // DEBUG LOG |
|
| 503 | + //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
| 504 | + // get reg form |
|
| 505 | + $this->_check_form_submission(); |
|
| 506 | + // checkout the action!!! |
|
| 507 | + $this->_process_form_action(); |
|
| 508 | + // add some style and make it dance |
|
| 509 | + $this->add_styles_and_scripts(); |
|
| 510 | + // kk... SPCO has successfully run |
|
| 511 | + EED_Single_Page_Checkout::$_initialized = true; |
|
| 512 | + // set no cache headers and constants |
|
| 513 | + EE_System::do_not_cache(); |
|
| 514 | + // add anchor |
|
| 515 | + add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
| 516 | + } catch (Exception $e) { |
|
| 517 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 518 | + } |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * _initialize_checkout |
|
| 525 | + * loads and instantiates EE_Checkout |
|
| 526 | + * |
|
| 527 | + * @access private |
|
| 528 | + * @throws EE_Error |
|
| 529 | + * @return EE_Checkout |
|
| 530 | + */ |
|
| 531 | + private function _initialize_checkout() |
|
| 532 | + { |
|
| 533 | + // look in session for existing checkout |
|
| 534 | + $checkout = EE_Registry::instance()->SSN->checkout(); |
|
| 535 | + // verify |
|
| 536 | + if ( ! $checkout instanceof EE_Checkout) { |
|
| 537 | + // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
| 538 | + $checkout = EE_Registry::instance()->load_file(SPCO_INC_PATH, 'EE_Checkout', 'class', array(), false); |
|
| 539 | + } else { |
|
| 540 | + if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
| 541 | + $this->unlock_transaction(); |
|
| 542 | + wp_safe_redirect($checkout->redirect_url); |
|
| 543 | + exit(); |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
| 547 | + // verify again |
|
| 548 | + if ( ! $checkout instanceof EE_Checkout) { |
|
| 549 | + throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
| 550 | + } |
|
| 551 | + // reset anything that needs a clean slate for each request |
|
| 552 | + $checkout->reset_for_current_request(); |
|
| 553 | + return $checkout; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * _get_request_vars |
|
| 560 | + * |
|
| 561 | + * @access private |
|
| 562 | + * @return void |
|
| 563 | + * @throws \EE_Error |
|
| 564 | + */ |
|
| 565 | + private function _get_request_vars() |
|
| 566 | + { |
|
| 567 | + // load classes |
|
| 568 | + EED_Single_Page_Checkout::load_request_handler(); |
|
| 569 | + //make sure this request is marked as belonging to EE |
|
| 570 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 571 | + // which step is being requested ? |
|
| 572 | + $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
| 573 | + // which step is being edited ? |
|
| 574 | + $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
| 575 | + // and what we're doing on the current step |
|
| 576 | + $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
| 577 | + // timestamp |
|
| 578 | + $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
| 579 | + // returning to edit ? |
|
| 580 | + $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
| 581 | + // or some other kind of revisit ? |
|
| 582 | + $this->checkout->revisit = EE_Registry::instance()->REQ->get('revisit', false); |
|
| 583 | + // and whether or not to generate a reg form for this request |
|
| 584 | + $this->checkout->generate_reg_form = EE_Registry::instance()->REQ->get('generate_reg_form', true); // TRUE FALSE |
|
| 585 | + // and whether or not to process a reg form submission for this request |
|
| 586 | + $this->checkout->process_form_submission = EE_Registry::instance()->REQ->get('process_form_submission', false); // TRUE FALSE |
|
| 587 | + $this->checkout->process_form_submission = $this->checkout->action !== 'display_spco_reg_step' |
|
| 588 | + ? $this->checkout->process_form_submission |
|
| 589 | + : false; // TRUE FALSE |
|
| 590 | + // $this->_display_request_vars(); |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * _display_request_vars |
|
| 597 | + * |
|
| 598 | + * @access protected |
|
| 599 | + * @return void |
|
| 600 | + */ |
|
| 601 | + protected function _display_request_vars() |
|
| 602 | + { |
|
| 603 | + if ( ! WP_DEBUG) { |
|
| 604 | + return; |
|
| 605 | + } |
|
| 606 | + EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
| 607 | + EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
| 608 | + EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
| 609 | + EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
| 610 | + EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
| 611 | + EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
| 612 | + EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); |
|
| 613 | + EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * _block_bots |
|
| 620 | + * checks that the incoming request has either of the following set: |
|
| 621 | + * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
| 622 | + * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
| 623 | + * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
| 624 | + * then where you coming from man? |
|
| 625 | + * |
|
| 626 | + * @return boolean |
|
| 627 | + */ |
|
| 628 | + private function _block_bots() |
|
| 629 | + { |
|
| 630 | + $invalid_checkout_access = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
| 631 | + if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
| 632 | + return true; |
|
| 633 | + } |
|
| 634 | + return false; |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + /** |
|
| 640 | + * _get_first_step |
|
| 641 | + * gets slug for first step in $_reg_steps_array |
|
| 642 | + * |
|
| 643 | + * @access private |
|
| 644 | + * @throws EE_Error |
|
| 645 | + * @return array |
|
| 646 | + */ |
|
| 647 | + private function _get_first_step() |
|
| 648 | + { |
|
| 649 | + $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
| 650 | + return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + |
|
| 654 | + |
|
| 655 | + /** |
|
| 656 | + * _load_and_instantiate_reg_steps |
|
| 657 | + * instantiates each reg step based on the loaded reg_steps array |
|
| 658 | + * |
|
| 659 | + * @access private |
|
| 660 | + * @throws EE_Error |
|
| 661 | + * @return bool |
|
| 662 | + */ |
|
| 663 | + private function _load_and_instantiate_reg_steps() |
|
| 664 | + { |
|
| 665 | + // have reg_steps already been instantiated ? |
|
| 666 | + if ( |
|
| 667 | + empty($this->checkout->reg_steps) || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
| 668 | + ) { |
|
| 669 | + // if not, then loop through raw reg steps array |
|
| 670 | + foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
| 671 | + if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
| 672 | + return false; |
|
| 673 | + } |
|
| 674 | + } |
|
| 675 | + EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true; |
|
| 676 | + EE_Registry::instance()->CFG->registration->reg_confirmation_last = true; |
|
| 677 | + // skip the registration_confirmation page ? |
|
| 678 | + if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
| 679 | + // just remove it from the reg steps array |
|
| 680 | + $this->checkout->remove_reg_step('registration_confirmation', false); |
|
| 681 | + } else if ( |
|
| 682 | + isset($this->checkout->reg_steps['registration_confirmation']) |
|
| 683 | + && EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
| 684 | + ) { |
|
| 685 | + // set the order to something big like 100 |
|
| 686 | + $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
| 687 | + } |
|
| 688 | + // filter the array for good luck |
|
| 689 | + $this->checkout->reg_steps = apply_filters( |
|
| 690 | + 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
| 691 | + $this->checkout->reg_steps |
|
| 692 | + ); |
|
| 693 | + // finally re-sort based on the reg step class order properties |
|
| 694 | + $this->checkout->sort_reg_steps(); |
|
| 695 | + } else { |
|
| 696 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
| 697 | + // set all current step stati to FALSE |
|
| 698 | + $reg_step->set_is_current_step(false); |
|
| 699 | + } |
|
| 700 | + } |
|
| 701 | + if (empty($this->checkout->reg_steps)) { |
|
| 702 | + EE_Error::add_error(__('No Reg Steps were loaded..', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 703 | + return false; |
|
| 704 | + } |
|
| 705 | + // make reg step details available to JS |
|
| 706 | + $this->checkout->set_reg_step_JSON_info(); |
|
| 707 | + return true; |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + |
|
| 711 | + |
|
| 712 | + /** |
|
| 713 | + * _load_and_instantiate_reg_step |
|
| 714 | + * |
|
| 715 | + * @access private |
|
| 716 | + * @param array $reg_step |
|
| 717 | + * @param int $order |
|
| 718 | + * @return bool |
|
| 719 | + */ |
|
| 720 | + private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
| 721 | + { |
|
| 722 | + // we need a file_path, class_name, and slug to add a reg step |
|
| 723 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
| 724 | + // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
| 725 | + if ( |
|
| 726 | + $this->checkout->reg_url_link |
|
| 727 | + && $this->checkout->step !== $reg_step['slug'] |
|
| 728 | + && $reg_step['slug'] !== 'finalize_registration' |
|
| 729 | + ) { |
|
| 730 | + return true; |
|
| 731 | + } |
|
| 732 | + // instantiate step class using file path and class name |
|
| 733 | + $reg_step_obj = EE_Registry::instance()->load_file( |
|
| 734 | + $reg_step['file_path'], |
|
| 735 | + $reg_step['class_name'], |
|
| 736 | + 'class', |
|
| 737 | + $this->checkout, |
|
| 738 | + false |
|
| 739 | + ); |
|
| 740 | + // did we gets the goods ? |
|
| 741 | + if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
| 742 | + // set reg step order based on config |
|
| 743 | + $reg_step_obj->set_order($order); |
|
| 744 | + // add instantiated reg step object to the master reg steps array |
|
| 745 | + $this->checkout->add_reg_step($reg_step_obj); |
|
| 746 | + } else { |
|
| 747 | + EE_Error::add_error( |
|
| 748 | + __('The current step could not be set.', 'event_espresso'), |
|
| 749 | + __FILE__, |
|
| 750 | + __FUNCTION__, |
|
| 751 | + __LINE__ |
|
| 752 | + ); |
|
| 753 | + return false; |
|
| 754 | + } |
|
| 755 | + } else { |
|
| 756 | + if (WP_DEBUG) { |
|
| 757 | + EE_Error::add_error( |
|
| 758 | + sprintf( |
|
| 759 | + __('A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', 'event_espresso'), |
|
| 760 | + isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
| 761 | + isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
| 762 | + isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
| 763 | + '<ul>', |
|
| 764 | + '<li>', |
|
| 765 | + '</li>', |
|
| 766 | + '</ul>' |
|
| 767 | + ), |
|
| 768 | + __FILE__, |
|
| 769 | + __FUNCTION__, |
|
| 770 | + __LINE__ |
|
| 771 | + ); |
|
| 772 | + } |
|
| 773 | + return false; |
|
| 774 | + } |
|
| 775 | + return true; |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + |
|
| 779 | + |
|
| 780 | + /** |
|
| 781 | + * _get_transaction_and_cart_for_previous_visit |
|
| 782 | + * |
|
| 783 | + * @access private |
|
| 784 | + * @return mixed EE_Transaction|NULL |
|
| 785 | + */ |
|
| 786 | + private function _get_transaction_and_cart_for_previous_visit() |
|
| 787 | + { |
|
| 788 | + /** @var $TXN_model EEM_Transaction */ |
|
| 789 | + $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
| 790 | + // because the reg_url_link is present in the request, this is a return visit to SPCO, so we'll get the transaction data from the db |
|
| 791 | + $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
| 792 | + // verify transaction |
|
| 793 | + if ($transaction instanceof EE_Transaction) { |
|
| 794 | + // and get the cart that was used for that transaction |
|
| 795 | + $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
| 796 | + return $transaction; |
|
| 797 | + } else { |
|
| 798 | + EE_Error::add_error(__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 799 | + return null; |
|
| 800 | + } |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + |
|
| 804 | + |
|
| 805 | + /** |
|
| 806 | + * _get_cart_for_transaction |
|
| 807 | + * |
|
| 808 | + * @access private |
|
| 809 | + * @param EE_Transaction $transaction |
|
| 810 | + * @return EE_Cart |
|
| 811 | + */ |
|
| 812 | + private function _get_cart_for_transaction($transaction) |
|
| 813 | + { |
|
| 814 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + |
|
| 818 | + |
|
| 819 | + /** |
|
| 820 | + * get_cart_for_transaction |
|
| 821 | + * |
|
| 822 | + * @access public |
|
| 823 | + * @param EE_Transaction $transaction |
|
| 824 | + * @return EE_Cart |
|
| 825 | + */ |
|
| 826 | + public function get_cart_for_transaction(EE_Transaction $transaction) |
|
| 827 | + { |
|
| 828 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
| 829 | + } |
|
| 830 | + |
|
| 831 | + |
|
| 832 | + |
|
| 833 | + /** |
|
| 834 | + * _get_transaction_and_cart_for_current_session |
|
| 835 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
| 836 | + * |
|
| 837 | + * @access private |
|
| 838 | + * @return EE_Transaction |
|
| 839 | + * @throws \EE_Error |
|
| 840 | + */ |
|
| 841 | + private function _get_cart_for_current_session_and_setup_new_transaction() |
|
| 842 | + { |
|
| 843 | + // if there's no transaction, then this is the FIRST visit to SPCO |
|
| 844 | + // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
| 845 | + $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
| 846 | + // and then create a new transaction |
|
| 847 | + $transaction = $this->_initialize_transaction(); |
|
| 848 | + // verify transaction |
|
| 849 | + if ($transaction instanceof EE_Transaction) { |
|
| 850 | + // save it so that we have an ID for other objects to use |
|
| 851 | + $transaction->save(); |
|
| 852 | + // and save TXN data to the cart |
|
| 853 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
| 854 | + } else { |
|
| 855 | + EE_Error::add_error(__('A Valid Transaction could not be initialized.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 856 | + } |
|
| 857 | + return $transaction; |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + |
|
| 861 | + |
|
| 862 | + /** |
|
| 863 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
| 864 | + * |
|
| 865 | + * @access private |
|
| 866 | + * @return mixed EE_Transaction|NULL |
|
| 867 | + */ |
|
| 868 | + private function _initialize_transaction() |
|
| 869 | + { |
|
| 870 | + try { |
|
| 871 | + // ensure cart totals have been calculated |
|
| 872 | + $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
| 873 | + // grab the cart grand total |
|
| 874 | + $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
| 875 | + // create new TXN |
|
| 876 | + return EE_Transaction::new_instance( |
|
| 877 | + array( |
|
| 878 | + 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
| 879 | + 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
| 880 | + 'TXN_paid' => 0, |
|
| 881 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
| 882 | + ) |
|
| 883 | + ); |
|
| 884 | + } catch (Exception $e) { |
|
| 885 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 886 | + } |
|
| 887 | + return null; |
|
| 888 | + } |
|
| 889 | + |
|
| 890 | + |
|
| 891 | + |
|
| 892 | + /** |
|
| 893 | + * _get_registrations |
|
| 894 | + * |
|
| 895 | + * @access private |
|
| 896 | + * @param EE_Transaction $transaction |
|
| 897 | + * @return void |
|
| 898 | + * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
| 899 | + * @throws \EE_Error |
|
| 900 | + */ |
|
| 901 | + private function _get_registrations(EE_Transaction $transaction) |
|
| 902 | + { |
|
| 903 | + // first step: grab the registrants { : o |
|
| 904 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true); |
|
| 905 | + // verify registrations have been set |
|
| 906 | + if (empty($registrations)) { |
|
| 907 | + // if no cached registrations, then check the db |
|
| 908 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
| 909 | + // still nothing ? well as long as this isn't a revisit |
|
| 910 | + if (empty($registrations) && ! $this->checkout->revisit) { |
|
| 911 | + // generate new registrations from scratch |
|
| 912 | + $registrations = $this->_initialize_registrations($transaction); |
|
| 913 | + } |
|
| 914 | + } |
|
| 915 | + // sort by their original registration order |
|
| 916 | + usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
| 917 | + // then loop thru the array |
|
| 918 | + foreach ($registrations as $registration) { |
|
| 919 | + // verify each registration |
|
| 920 | + if ($registration instanceof EE_Registration) { |
|
| 921 | + // we display all attendee info for the primary registrant |
|
| 922 | + if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
| 923 | + && $registration->is_primary_registrant() |
|
| 924 | + ) { |
|
| 925 | + $this->checkout->primary_revisit = true; |
|
| 926 | + break; |
|
| 927 | + } else if ($this->checkout->revisit |
|
| 928 | + && $this->checkout->reg_url_link !== $registration->reg_url_link() |
|
| 929 | + ) { |
|
| 930 | + // but hide info if it doesn't belong to you |
|
| 931 | + $transaction->clear_cache('Registration', $registration->ID()); |
|
| 932 | + } |
|
| 933 | + $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
| 934 | + } |
|
| 935 | + } |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + |
|
| 939 | + |
|
| 940 | + /** |
|
| 941 | + * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
| 942 | + * |
|
| 943 | + * @access private |
|
| 944 | + * @param EE_Transaction $transaction |
|
| 945 | + * @return array |
|
| 946 | + * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
| 947 | + * @throws \EE_Error |
|
| 948 | + */ |
|
| 949 | + private function _initialize_registrations(EE_Transaction $transaction) |
|
| 950 | + { |
|
| 951 | + $att_nmbr = 0; |
|
| 952 | + $registrations = array(); |
|
| 953 | + if ($transaction instanceof EE_Transaction) { |
|
| 954 | + /** @type EE_Registration_Processor $registration_processor */ |
|
| 955 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 956 | + $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
| 957 | + // now let's add the cart items to the $transaction |
|
| 958 | + foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
| 959 | + //do the following for each ticket of this type they selected |
|
| 960 | + for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
| 961 | + $att_nmbr++; |
|
| 962 | + /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
| 963 | + $CreateRegistrationCommand = EE_Registry::instance() |
|
| 964 | + ->create( |
|
| 965 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 966 | + array( |
|
| 967 | + $transaction, |
|
| 968 | + $line_item, |
|
| 969 | + $att_nmbr, |
|
| 970 | + $this->checkout->total_ticket_count, |
|
| 971 | + ) |
|
| 972 | + ); |
|
| 973 | + // override capabilities for frontend registrations |
|
| 974 | + if ( ! is_admin()) { |
|
| 975 | + $CreateRegistrationCommand->setCapCheck( |
|
| 976 | + new PublicCapabilities('', 'create_new_registration') |
|
| 977 | + ); |
|
| 978 | + } |
|
| 979 | + $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
| 980 | + if ( ! $registration instanceof EE_Registration) { |
|
| 981 | + throw new InvalidEntityException($registration, 'EE_Registration'); |
|
| 982 | + } |
|
| 983 | + $registrations[ $registration->ID() ] = $registration; |
|
| 984 | + } |
|
| 985 | + } |
|
| 986 | + $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
| 987 | + } |
|
| 988 | + return $registrations; |
|
| 989 | + } |
|
| 990 | + |
|
| 991 | + |
|
| 992 | + |
|
| 993 | + /** |
|
| 994 | + * sorts registrations by REG_count |
|
| 995 | + * |
|
| 996 | + * @access public |
|
| 997 | + * @param EE_Registration $reg_A |
|
| 998 | + * @param EE_Registration $reg_B |
|
| 999 | + * @return int |
|
| 1000 | + */ |
|
| 1001 | + public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
| 1002 | + { |
|
| 1003 | + // this shouldn't ever happen within the same TXN, but oh well |
|
| 1004 | + if ($reg_A->count() === $reg_B->count()) { |
|
| 1005 | + return 0; |
|
| 1006 | + } |
|
| 1007 | + return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + |
|
| 1011 | + |
|
| 1012 | + /** |
|
| 1013 | + * _final_verifications |
|
| 1014 | + * just makes sure that everything is set up correctly before proceeding |
|
| 1015 | + * |
|
| 1016 | + * @access private |
|
| 1017 | + * @return bool |
|
| 1018 | + * @throws \EE_Error |
|
| 1019 | + */ |
|
| 1020 | + private function _final_verifications() |
|
| 1021 | + { |
|
| 1022 | + // filter checkout |
|
| 1023 | + $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout); |
|
| 1024 | + //verify that current step is still set correctly |
|
| 1025 | + if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
| 1026 | + EE_Error::add_error( |
|
| 1027 | + __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
| 1028 | + __FILE__, |
|
| 1029 | + __FUNCTION__, |
|
| 1030 | + __LINE__ |
|
| 1031 | + ); |
|
| 1032 | + return false; |
|
| 1033 | + } |
|
| 1034 | + // if returning to SPCO, then verify that primary registrant is set |
|
| 1035 | + if ( ! empty($this->checkout->reg_url_link)) { |
|
| 1036 | + $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
| 1037 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
| 1038 | + EE_Error::add_error( |
|
| 1039 | + __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
| 1040 | + __FILE__, |
|
| 1041 | + __FUNCTION__, |
|
| 1042 | + __LINE__ |
|
| 1043 | + ); |
|
| 1044 | + return false; |
|
| 1045 | + } |
|
| 1046 | + $valid_registrant = null; |
|
| 1047 | + foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) { |
|
| 1048 | + if ( |
|
| 1049 | + $registration instanceof EE_Registration |
|
| 1050 | + && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
| 1051 | + ) { |
|
| 1052 | + $valid_registrant = $registration; |
|
| 1053 | + } |
|
| 1054 | + } |
|
| 1055 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
| 1056 | + // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
| 1057 | + if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
| 1058 | + // clear the session, mark the checkout as unverified, and try again |
|
| 1059 | + EE_Registry::instance()->SSN->clear_session(); |
|
| 1060 | + EED_Single_Page_Checkout::$_initialized = false; |
|
| 1061 | + EED_Single_Page_Checkout::$_checkout_verified = false; |
|
| 1062 | + $this->_initialize(); |
|
| 1063 | + EE_Error::reset_notices(); |
|
| 1064 | + return false; |
|
| 1065 | + } |
|
| 1066 | + EE_Error::add_error( |
|
| 1067 | + __('We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
| 1068 | + __FILE__, |
|
| 1069 | + __FUNCTION__, |
|
| 1070 | + __LINE__ |
|
| 1071 | + ); |
|
| 1072 | + return false; |
|
| 1073 | + } |
|
| 1074 | + } |
|
| 1075 | + // now that things have been kinda sufficiently verified, |
|
| 1076 | + // let's add the checkout to the session so that's available other systems |
|
| 1077 | + EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
| 1078 | + return true; |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + |
|
| 1082 | + |
|
| 1083 | + /** |
|
| 1084 | + * _initialize_reg_steps |
|
| 1085 | + * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
| 1086 | + * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
| 1087 | + * |
|
| 1088 | + * @access private |
|
| 1089 | + * @param bool $reinitializing |
|
| 1090 | + * @throws \EE_Error |
|
| 1091 | + */ |
|
| 1092 | + private function _initialize_reg_steps($reinitializing = false) |
|
| 1093 | + { |
|
| 1094 | + $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
| 1095 | + // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
| 1096 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
| 1097 | + if ( ! $reg_step->initialize_reg_step()) { |
|
| 1098 | + // if not initialized then maybe this step is being removed... |
|
| 1099 | + if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
| 1100 | + // if it was the current step, then we need to start over here |
|
| 1101 | + $this->_initialize_reg_steps(true); |
|
| 1102 | + return; |
|
| 1103 | + } |
|
| 1104 | + continue; |
|
| 1105 | + } |
|
| 1106 | + // add css and JS for current step |
|
| 1107 | + $reg_step->enqueue_styles_and_scripts(); |
|
| 1108 | + // i18n |
|
| 1109 | + $reg_step->translate_js_strings(); |
|
| 1110 | + if ($reg_step->is_current_step()) { |
|
| 1111 | + // the text that appears on the reg step form submit button |
|
| 1112 | + $reg_step->set_submit_button_text(); |
|
| 1113 | + } |
|
| 1114 | + } |
|
| 1115 | + // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
| 1116 | + do_action("AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step); |
|
| 1117 | + } |
|
| 1118 | + |
|
| 1119 | + |
|
| 1120 | + |
|
| 1121 | + /** |
|
| 1122 | + * _check_form_submission |
|
| 1123 | + * |
|
| 1124 | + * @access private |
|
| 1125 | + * @return void |
|
| 1126 | + */ |
|
| 1127 | + private function _check_form_submission() |
|
| 1128 | + { |
|
| 1129 | + //does this request require the reg form to be generated ? |
|
| 1130 | + if ($this->checkout->generate_reg_form) { |
|
| 1131 | + // ever heard that song by Blue Rodeo ? |
|
| 1132 | + try { |
|
| 1133 | + $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
| 1134 | + // if not displaying a form, then check for form submission |
|
| 1135 | + if ($this->checkout->process_form_submission && $this->checkout->current_step->reg_form->was_submitted()) { |
|
| 1136 | + // clear out any old data in case this step is being run again |
|
| 1137 | + $this->checkout->current_step->set_valid_data(array()); |
|
| 1138 | + // capture submitted form data |
|
| 1139 | + $this->checkout->current_step->reg_form->receive_form_submission( |
|
| 1140 | + apply_filters('FHEE__Single_Page_Checkout___check_form_submission__request_params', EE_Registry::instance()->REQ->params(), $this->checkout) |
|
| 1141 | + ); |
|
| 1142 | + // validate submitted form data |
|
| 1143 | + if ( ! $this->checkout->continue_reg && ! $this->checkout->current_step->reg_form->is_valid()) { |
|
| 1144 | + // thou shall not pass !!! |
|
| 1145 | + $this->checkout->continue_reg = false; |
|
| 1146 | + // any form validation errors? |
|
| 1147 | + if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
| 1148 | + $submission_error_messages = array(); |
|
| 1149 | + // bad, bad, bad registrant |
|
| 1150 | + foreach ($this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1151 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 1152 | + $submission_error_messages[] = sprintf( |
|
| 1153 | + __('%s : %s', 'event_espresso'), |
|
| 1154 | + $validation_error->get_form_section()->html_label_text(), |
|
| 1155 | + $validation_error->getMessage() |
|
| 1156 | + ); |
|
| 1157 | + } |
|
| 1158 | + } |
|
| 1159 | + EE_Error::add_error(implode('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); |
|
| 1160 | + } |
|
| 1161 | + // well not really... what will happen is we'll just get redirected back to redo the current step |
|
| 1162 | + $this->go_to_next_step(); |
|
| 1163 | + return; |
|
| 1164 | + } |
|
| 1165 | + } |
|
| 1166 | + } catch (EE_Error $e) { |
|
| 1167 | + $e->get_error(); |
|
| 1168 | + } |
|
| 1169 | + } |
|
| 1170 | + } |
|
| 1171 | + |
|
| 1172 | + |
|
| 1173 | + |
|
| 1174 | + /** |
|
| 1175 | + * _process_action |
|
| 1176 | + * |
|
| 1177 | + * @access private |
|
| 1178 | + * @return void |
|
| 1179 | + * @throws \EE_Error |
|
| 1180 | + */ |
|
| 1181 | + private function _process_form_action() |
|
| 1182 | + { |
|
| 1183 | + // what cha wanna do? |
|
| 1184 | + switch ($this->checkout->action) { |
|
| 1185 | + // AJAX next step reg form |
|
| 1186 | + case 'display_spco_reg_step' : |
|
| 1187 | + $this->checkout->redirect = false; |
|
| 1188 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 1189 | + $this->checkout->json_response->set_reg_step_html($this->checkout->current_step->display_reg_form()); |
|
| 1190 | + } |
|
| 1191 | + break; |
|
| 1192 | + default : |
|
| 1193 | + // meh... do one of those other steps first |
|
| 1194 | + if ( ! empty($this->checkout->action) && is_callable(array($this->checkout->current_step, $this->checkout->action))) { |
|
| 1195 | + // dynamically creates hook point like: AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
| 1196 | + do_action("AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step); |
|
| 1197 | + // call action on current step |
|
| 1198 | + if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
| 1199 | + // good registrant, you get to proceed |
|
| 1200 | + if ( |
|
| 1201 | + $this->checkout->current_step->success_message() !== '' |
|
| 1202 | + && apply_filters( |
|
| 1203 | + 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
| 1204 | + false |
|
| 1205 | + ) |
|
| 1206 | + ) { |
|
| 1207 | + EE_Error::add_success( |
|
| 1208 | + $this->checkout->current_step->success_message() |
|
| 1209 | + . '<br />' . $this->checkout->next_step->_instructions() |
|
| 1210 | + ); |
|
| 1211 | + } |
|
| 1212 | + // pack it up, pack it in... |
|
| 1213 | + $this->_setup_redirect(); |
|
| 1214 | + } |
|
| 1215 | + // dynamically creates hook point like: AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
| 1216 | + do_action("AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step); |
|
| 1217 | + } else { |
|
| 1218 | + EE_Error::add_error( |
|
| 1219 | + sprintf( |
|
| 1220 | + __('The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso'), |
|
| 1221 | + $this->checkout->action, |
|
| 1222 | + $this->checkout->current_step->name() |
|
| 1223 | + ), |
|
| 1224 | + __FILE__, |
|
| 1225 | + __FUNCTION__, |
|
| 1226 | + __LINE__ |
|
| 1227 | + ); |
|
| 1228 | + } |
|
| 1229 | + // end default |
|
| 1230 | + } |
|
| 1231 | + // store our progress so far |
|
| 1232 | + $this->checkout->stash_transaction_and_checkout(); |
|
| 1233 | + // advance to the next step! If you pass GO, collect $200 |
|
| 1234 | + $this->go_to_next_step(); |
|
| 1235 | + } |
|
| 1236 | + |
|
| 1237 | + |
|
| 1238 | + |
|
| 1239 | + /** |
|
| 1240 | + * add_styles_and_scripts |
|
| 1241 | + * |
|
| 1242 | + * @access public |
|
| 1243 | + * @return void |
|
| 1244 | + */ |
|
| 1245 | + public function add_styles_and_scripts() |
|
| 1246 | + { |
|
| 1247 | + // i18n |
|
| 1248 | + $this->translate_js_strings(); |
|
| 1249 | + if ($this->checkout->admin_request) { |
|
| 1250 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
| 1251 | + } else { |
|
| 1252 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
| 1253 | + } |
|
| 1254 | + } |
|
| 1255 | + |
|
| 1256 | + |
|
| 1257 | + |
|
| 1258 | + /** |
|
| 1259 | + * translate_js_strings |
|
| 1260 | + * |
|
| 1261 | + * @access public |
|
| 1262 | + * @return void |
|
| 1263 | + */ |
|
| 1264 | + public function translate_js_strings() |
|
| 1265 | + { |
|
| 1266 | + EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
| 1267 | + EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
| 1268 | + EE_Registry::$i18n_js_strings['server_error'] = __('An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
|
| 1269 | + EE_Registry::$i18n_js_strings['invalid_json_response'] = __('An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
|
| 1270 | + EE_Registry::$i18n_js_strings['validation_error'] = __('There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', 'event_espresso'); |
|
| 1271 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = __('There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', 'event_espresso'); |
|
| 1272 | + EE_Registry::$i18n_js_strings['reg_step_error'] = __('This registration step could not be completed. Please refresh the page and try again.', 'event_espresso'); |
|
| 1273 | + EE_Registry::$i18n_js_strings['invalid_coupon'] = __('We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', 'event_espresso'); |
|
| 1274 | + EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
| 1275 | + __('Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', 'event_espresso'), |
|
| 1276 | + '<br/>', |
|
| 1277 | + '<br/>' |
|
| 1278 | + ); |
|
| 1279 | + EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
| 1280 | + EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
| 1281 | + EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
| 1282 | + EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
| 1283 | + EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
| 1284 | + EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
| 1285 | + EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
| 1286 | + EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
| 1287 | + EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
| 1288 | + EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
| 1289 | + EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
| 1290 | + EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
| 1291 | + EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
| 1292 | + EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
| 1293 | + EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
| 1294 | + EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
| 1295 | + EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
| 1296 | + EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
| 1297 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
| 1298 | + __( |
|
| 1299 | + '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
| 1300 | + 'event_espresso' |
|
| 1301 | + ), |
|
| 1302 | + '<h4 class="important-notice">', |
|
| 1303 | + '</h4>', |
|
| 1304 | + '<br />', |
|
| 1305 | + '<p>', |
|
| 1306 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
| 1307 | + '">', |
|
| 1308 | + '</a>', |
|
| 1309 | + '</p>' |
|
| 1310 | + ); |
|
| 1311 | + EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters('FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true); |
|
| 1312 | + } |
|
| 1313 | + |
|
| 1314 | + |
|
| 1315 | + |
|
| 1316 | + /** |
|
| 1317 | + * enqueue_styles_and_scripts |
|
| 1318 | + * |
|
| 1319 | + * @access public |
|
| 1320 | + * @return void |
|
| 1321 | + * @throws \EE_Error |
|
| 1322 | + */ |
|
| 1323 | + public function enqueue_styles_and_scripts() |
|
| 1324 | + { |
|
| 1325 | + // load css |
|
| 1326 | + wp_register_style('single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1327 | + wp_enqueue_style('single_page_checkout'); |
|
| 1328 | + // load JS |
|
| 1329 | + wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', array('jquery'), '1.0.1', true); |
|
| 1330 | + wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', array('jquery_plugin'), '2.0.2', true); |
|
| 1331 | + wp_register_script('single_page_checkout', SPCO_JS_URL . 'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, true); |
|
| 1332 | + $this->checkout->registration_form->enqueue_js(); |
|
| 1333 | + $this->checkout->current_step->reg_form->enqueue_js(); |
|
| 1334 | + wp_enqueue_script('single_page_checkout'); |
|
| 1335 | + /** |
|
| 1336 | + * global action hook for enqueueing styles and scripts with |
|
| 1337 | + * spco calls. |
|
| 1338 | + */ |
|
| 1339 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
| 1340 | + /** |
|
| 1341 | + * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
| 1342 | + * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
| 1343 | + */ |
|
| 1344 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this); |
|
| 1345 | + } |
|
| 1346 | + |
|
| 1347 | + |
|
| 1348 | + |
|
| 1349 | + /** |
|
| 1350 | + * display the Registration Single Page Checkout Form |
|
| 1351 | + * |
|
| 1352 | + * @access private |
|
| 1353 | + * @return void |
|
| 1354 | + * @throws \EE_Error |
|
| 1355 | + */ |
|
| 1356 | + private function _display_spco_reg_form() |
|
| 1357 | + { |
|
| 1358 | + // if registering via the admin, just display the reg form for the current step |
|
| 1359 | + if ($this->checkout->admin_request) { |
|
| 1360 | + EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
| 1361 | + } else { |
|
| 1362 | + // add powered by EE msg |
|
| 1363 | + add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
| 1364 | + $empty_cart = count($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)) < 1 ? true : false; |
|
| 1365 | + $cookies_not_set_msg = ''; |
|
| 1366 | + if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) { |
|
| 1367 | + $cookies_not_set_msg = apply_filters( |
|
| 1368 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
| 1369 | + sprintf( |
|
| 1370 | + __( |
|
| 1371 | + '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', |
|
| 1372 | + 'event_espresso' |
|
| 1373 | + ), |
|
| 1374 | + '<div class="ee-attention">', |
|
| 1375 | + '</div>', |
|
| 1376 | + '<h6 class="important-notice">', |
|
| 1377 | + '</h6>', |
|
| 1378 | + '<p>', |
|
| 1379 | + '</p>', |
|
| 1380 | + '<br />', |
|
| 1381 | + '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', |
|
| 1382 | + '</a>' |
|
| 1383 | + ) |
|
| 1384 | + ); |
|
| 1385 | + } |
|
| 1386 | + $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
| 1387 | + array( |
|
| 1388 | + 'name' => 'single-page-checkout', |
|
| 1389 | + 'html_id' => 'ee-single-page-checkout-dv', |
|
| 1390 | + 'layout_strategy' => |
|
| 1391 | + new EE_Template_Layout( |
|
| 1392 | + array( |
|
| 1393 | + 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
| 1394 | + 'template_args' => array( |
|
| 1395 | + 'empty_cart' => $empty_cart, |
|
| 1396 | + 'revisit' => $this->checkout->revisit, |
|
| 1397 | + 'reg_steps' => $this->checkout->reg_steps, |
|
| 1398 | + 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step ? $this->checkout->next_step->slug() : '', |
|
| 1399 | + 'empty_msg' => apply_filters( |
|
| 1400 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
| 1401 | + sprintf( |
|
| 1402 | + __('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', 'event_espresso'), |
|
| 1403 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
| 1404 | + '">', |
|
| 1405 | + '</a>' |
|
| 1406 | + ) |
|
| 1407 | + ), |
|
| 1408 | + 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
| 1409 | + 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
| 1410 | + 'session_expiration' => |
|
| 1411 | + date('M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)), |
|
| 1412 | + ), |
|
| 1413 | + ) |
|
| 1414 | + ), |
|
| 1415 | + ) |
|
| 1416 | + ); |
|
| 1417 | + // load template and add to output sent that gets filtered into the_content() |
|
| 1418 | + EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
| 1419 | + } |
|
| 1420 | + } |
|
| 1421 | + |
|
| 1422 | + |
|
| 1423 | + |
|
| 1424 | + /** |
|
| 1425 | + * add_extra_finalize_registration_inputs |
|
| 1426 | + * |
|
| 1427 | + * @access public |
|
| 1428 | + * @param $next_step |
|
| 1429 | + * @internal param string $label |
|
| 1430 | + * @return void |
|
| 1431 | + */ |
|
| 1432 | + public function add_extra_finalize_registration_inputs($next_step) |
|
| 1433 | + { |
|
| 1434 | + if ($next_step === 'finalize_registration') { |
|
| 1435 | + echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
| 1436 | + } |
|
| 1437 | + } |
|
| 1438 | + |
|
| 1439 | + |
|
| 1440 | + |
|
| 1441 | + /** |
|
| 1442 | + * display_registration_footer |
|
| 1443 | + * |
|
| 1444 | + * @access public |
|
| 1445 | + * @return string |
|
| 1446 | + */ |
|
| 1447 | + public static function display_registration_footer() |
|
| 1448 | + { |
|
| 1449 | + if ( |
|
| 1450 | + apply_filters( |
|
| 1451 | + 'FHEE__EE_Front__Controller__show_reg_footer', |
|
| 1452 | + EE_Registry::instance()->CFG->admin->show_reg_footer |
|
| 1453 | + ) |
|
| 1454 | + ) { |
|
| 1455 | + add_filter( |
|
| 1456 | + 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
| 1457 | + function ($url) { |
|
| 1458 | + return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
| 1459 | + } |
|
| 1460 | + ); |
|
| 1461 | + echo apply_filters( |
|
| 1462 | + 'FHEE__EE_Front_Controller__display_registration_footer', |
|
| 1463 | + \EEH_Template::powered_by_event_espresso( |
|
| 1464 | + '', |
|
| 1465 | + 'espresso-registration-footer-dv', |
|
| 1466 | + array('utm_content' => 'registration_checkout') |
|
| 1467 | + ) |
|
| 1468 | + ); |
|
| 1469 | + } |
|
| 1470 | + return ''; |
|
| 1471 | + } |
|
| 1472 | + |
|
| 1473 | + |
|
| 1474 | + |
|
| 1475 | + /** |
|
| 1476 | + * unlock_transaction |
|
| 1477 | + * |
|
| 1478 | + * @access public |
|
| 1479 | + * @return void |
|
| 1480 | + * @throws \EE_Error |
|
| 1481 | + */ |
|
| 1482 | + public function unlock_transaction() |
|
| 1483 | + { |
|
| 1484 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
| 1485 | + $this->checkout->transaction->unlock(); |
|
| 1486 | + } |
|
| 1487 | + } |
|
| 1488 | + |
|
| 1489 | + |
|
| 1490 | + |
|
| 1491 | + /** |
|
| 1492 | + * _setup_redirect |
|
| 1493 | + * |
|
| 1494 | + * @access private |
|
| 1495 | + * @return void |
|
| 1496 | + */ |
|
| 1497 | + private function _setup_redirect() |
|
| 1498 | + { |
|
| 1499 | + if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
| 1500 | + $this->checkout->redirect = true; |
|
| 1501 | + if (empty($this->checkout->redirect_url)) { |
|
| 1502 | + $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
| 1503 | + } |
|
| 1504 | + $this->checkout->redirect_url = apply_filters( |
|
| 1505 | + 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
| 1506 | + $this->checkout->redirect_url, |
|
| 1507 | + $this->checkout |
|
| 1508 | + ); |
|
| 1509 | + } |
|
| 1510 | + } |
|
| 1511 | + |
|
| 1512 | + |
|
| 1513 | + |
|
| 1514 | + /** |
|
| 1515 | + * handle ajax message responses and redirects |
|
| 1516 | + * |
|
| 1517 | + * @access public |
|
| 1518 | + * @return void |
|
| 1519 | + * @throws \EE_Error |
|
| 1520 | + */ |
|
| 1521 | + public function go_to_next_step() |
|
| 1522 | + { |
|
| 1523 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 1524 | + // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
| 1525 | + $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
| 1526 | + } |
|
| 1527 | + $this->unlock_transaction(); |
|
| 1528 | + // just return for these conditions |
|
| 1529 | + if ( |
|
| 1530 | + $this->checkout->admin_request |
|
| 1531 | + || $this->checkout->action === 'redirect_form' |
|
| 1532 | + || $this->checkout->action === 'update_checkout' |
|
| 1533 | + ) { |
|
| 1534 | + return; |
|
| 1535 | + } |
|
| 1536 | + // AJAX response |
|
| 1537 | + $this->_handle_json_response(); |
|
| 1538 | + // redirect to next step or the Thank You page |
|
| 1539 | + $this->_handle_html_redirects(); |
|
| 1540 | + // hmmm... must be something wrong, so let's just display the form again ! |
|
| 1541 | + $this->_display_spco_reg_form(); |
|
| 1542 | + } |
|
| 1543 | + |
|
| 1544 | + |
|
| 1545 | + |
|
| 1546 | + /** |
|
| 1547 | + * _handle_json_response |
|
| 1548 | + * |
|
| 1549 | + * @access protected |
|
| 1550 | + * @return void |
|
| 1551 | + */ |
|
| 1552 | + protected function _handle_json_response() |
|
| 1553 | + { |
|
| 1554 | + // if this is an ajax request |
|
| 1555 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 1556 | + // DEBUG LOG |
|
| 1557 | + //$this->checkout->log( |
|
| 1558 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
| 1559 | + // array( |
|
| 1560 | + // 'json_response_redirect_url' => $this->checkout->json_response->redirect_url(), |
|
| 1561 | + // 'redirect' => $this->checkout->redirect, |
|
| 1562 | + // 'continue_reg' => $this->checkout->continue_reg, |
|
| 1563 | + // ) |
|
| 1564 | + //); |
|
| 1565 | + $this->checkout->json_response->set_registration_time_limit( |
|
| 1566 | + $this->checkout->get_registration_time_limit() |
|
| 1567 | + ); |
|
| 1568 | + $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
| 1569 | + // just send the ajax ( |
|
| 1570 | + $json_response = apply_filters( |
|
| 1571 | + 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
| 1572 | + $this->checkout->json_response |
|
| 1573 | + ); |
|
| 1574 | + echo $json_response; |
|
| 1575 | + exit(); |
|
| 1576 | + } |
|
| 1577 | + } |
|
| 1578 | + |
|
| 1579 | + |
|
| 1580 | + |
|
| 1581 | + /** |
|
| 1582 | + * _handle_redirects |
|
| 1583 | + * |
|
| 1584 | + * @access protected |
|
| 1585 | + * @return void |
|
| 1586 | + */ |
|
| 1587 | + protected function _handle_html_redirects() |
|
| 1588 | + { |
|
| 1589 | + // going somewhere ? |
|
| 1590 | + if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
| 1591 | + // store notices in a transient |
|
| 1592 | + EE_Error::get_notices(false, true, true); |
|
| 1593 | + // DEBUG LOG |
|
| 1594 | + //$this->checkout->log( |
|
| 1595 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
| 1596 | + // array( |
|
| 1597 | + // 'headers_sent' => headers_sent(), |
|
| 1598 | + // 'redirect_url' => $this->checkout->redirect_url, |
|
| 1599 | + // 'headers_list' => headers_list(), |
|
| 1600 | + // ) |
|
| 1601 | + //); |
|
| 1602 | + wp_safe_redirect($this->checkout->redirect_url); |
|
| 1603 | + exit(); |
|
| 1604 | + } |
|
| 1605 | + } |
|
| 1606 | + |
|
| 1607 | + |
|
| 1608 | + |
|
| 1609 | + /** |
|
| 1610 | + * set_checkout_anchor |
|
| 1611 | + * |
|
| 1612 | + * @access public |
|
| 1613 | + * @return void |
|
| 1614 | + */ |
|
| 1615 | + public function set_checkout_anchor() |
|
| 1616 | + { |
|
| 1617 | + echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
| 1618 | + } |
|
| 1619 | 1619 | |
| 1620 | 1620 | |
| 1621 | 1621 | |
@@ -216,13 +216,13 @@ discard block |
||
| 216 | 216 | */ |
| 217 | 217 | public static function set_definitions() |
| 218 | 218 | { |
| 219 | - define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS); |
|
| 220 | - define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
| 221 | - define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
| 222 | - define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
| 223 | - define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
| 224 | - define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
| 225 | - define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
| 219 | + define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS); |
|
| 220 | + define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css'.DS); |
|
| 221 | + define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img'.DS); |
|
| 222 | + define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js'.DS); |
|
| 223 | + define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc'.DS); |
|
| 224 | + define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps'.DS); |
|
| 225 | + define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates'.DS); |
|
| 226 | 226 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
| 227 | 227 | } |
| 228 | 228 | |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | return; |
| 244 | 244 | } |
| 245 | 245 | // filter list of reg_steps |
| 246 | - $reg_steps_to_load = (array)apply_filters( |
|
| 246 | + $reg_steps_to_load = (array) apply_filters( |
|
| 247 | 247 | 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
| 248 | 248 | EED_Single_Page_Checkout::get_reg_steps() |
| 249 | 249 | ); |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | // we need a |
| 255 | 255 | if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
| 256 | 256 | // copy over to the reg_steps_array |
| 257 | - EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step; |
|
| 257 | + EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
| 258 | 258 | // register custom key route for each reg step |
| 259 | 259 | // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
| 260 | 260 | EE_Config::register_route($reg_step['slug'], 'EED_Single_Page_Checkout', 'run', 'step'); |
@@ -287,25 +287,25 @@ discard block |
||
| 287 | 287 | if (empty($reg_steps)) { |
| 288 | 288 | $reg_steps = array( |
| 289 | 289 | 10 => array( |
| 290 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
| 290 | + 'file_path' => SPCO_REG_STEPS_PATH.'attendee_information', |
|
| 291 | 291 | 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
| 292 | 292 | 'slug' => 'attendee_information', |
| 293 | 293 | 'has_hooks' => false, |
| 294 | 294 | ), |
| 295 | 295 | 20 => array( |
| 296 | - 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
| 296 | + 'file_path' => SPCO_REG_STEPS_PATH.'registration_confirmation', |
|
| 297 | 297 | 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
| 298 | 298 | 'slug' => 'registration_confirmation', |
| 299 | 299 | 'has_hooks' => false, |
| 300 | 300 | ), |
| 301 | 301 | 30 => array( |
| 302 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
| 302 | + 'file_path' => SPCO_REG_STEPS_PATH.'payment_options', |
|
| 303 | 303 | 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
| 304 | 304 | 'slug' => 'payment_options', |
| 305 | 305 | 'has_hooks' => true, |
| 306 | 306 | ), |
| 307 | 307 | 999 => array( |
| 308 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
| 308 | + 'file_path' => SPCO_REG_STEPS_PATH.'finalize_registration', |
|
| 309 | 309 | 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
| 310 | 310 | 'slug' => 'finalize_registration', |
| 311 | 311 | 'has_hooks' => false, |
@@ -581,12 +581,12 @@ discard block |
||
| 581 | 581 | // or some other kind of revisit ? |
| 582 | 582 | $this->checkout->revisit = EE_Registry::instance()->REQ->get('revisit', false); |
| 583 | 583 | // and whether or not to generate a reg form for this request |
| 584 | - $this->checkout->generate_reg_form = EE_Registry::instance()->REQ->get('generate_reg_form', true); // TRUE FALSE |
|
| 584 | + $this->checkout->generate_reg_form = EE_Registry::instance()->REQ->get('generate_reg_form', true); // TRUE FALSE |
|
| 585 | 585 | // and whether or not to process a reg form submission for this request |
| 586 | - $this->checkout->process_form_submission = EE_Registry::instance()->REQ->get('process_form_submission', false); // TRUE FALSE |
|
| 586 | + $this->checkout->process_form_submission = EE_Registry::instance()->REQ->get('process_form_submission', false); // TRUE FALSE |
|
| 587 | 587 | $this->checkout->process_form_submission = $this->checkout->action !== 'display_spco_reg_step' |
| 588 | 588 | ? $this->checkout->process_form_submission |
| 589 | - : false; // TRUE FALSE |
|
| 589 | + : false; // TRUE FALSE |
|
| 590 | 590 | // $this->_display_request_vars(); |
| 591 | 591 | } |
| 592 | 592 | |
@@ -980,7 +980,7 @@ discard block |
||
| 980 | 980 | if ( ! $registration instanceof EE_Registration) { |
| 981 | 981 | throw new InvalidEntityException($registration, 'EE_Registration'); |
| 982 | 982 | } |
| 983 | - $registrations[ $registration->ID() ] = $registration; |
|
| 983 | + $registrations[$registration->ID()] = $registration; |
|
| 984 | 984 | } |
| 985 | 985 | } |
| 986 | 986 | $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
@@ -1206,7 +1206,7 @@ discard block |
||
| 1206 | 1206 | ) { |
| 1207 | 1207 | EE_Error::add_success( |
| 1208 | 1208 | $this->checkout->current_step->success_message() |
| 1209 | - . '<br />' . $this->checkout->next_step->_instructions() |
|
| 1209 | + . '<br />'.$this->checkout->next_step->_instructions() |
|
| 1210 | 1210 | ); |
| 1211 | 1211 | } |
| 1212 | 1212 | // pack it up, pack it in... |
@@ -1303,7 +1303,7 @@ discard block |
||
| 1303 | 1303 | '</h4>', |
| 1304 | 1304 | '<br />', |
| 1305 | 1305 | '<p>', |
| 1306 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
| 1306 | + '<a href="'.get_post_type_archive_link('espresso_events').'" title="', |
|
| 1307 | 1307 | '">', |
| 1308 | 1308 | '</a>', |
| 1309 | 1309 | '</p>' |
@@ -1323,12 +1323,12 @@ discard block |
||
| 1323 | 1323 | public function enqueue_styles_and_scripts() |
| 1324 | 1324 | { |
| 1325 | 1325 | // load css |
| 1326 | - wp_register_style('single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1326 | + wp_register_style('single_page_checkout', SPCO_CSS_URL.'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1327 | 1327 | wp_enqueue_style('single_page_checkout'); |
| 1328 | 1328 | // load JS |
| 1329 | - wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', array('jquery'), '1.0.1', true); |
|
| 1330 | - wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', array('jquery_plugin'), '2.0.2', true); |
|
| 1331 | - wp_register_script('single_page_checkout', SPCO_JS_URL . 'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, true); |
|
| 1329 | + wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL.'jquery .plugin.min.js', array('jquery'), '1.0.1', true); |
|
| 1330 | + wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL.'jquery .countdown.min.js', array('jquery_plugin'), '2.0.2', true); |
|
| 1331 | + wp_register_script('single_page_checkout', SPCO_JS_URL.'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, true); |
|
| 1332 | 1332 | $this->checkout->registration_form->enqueue_js(); |
| 1333 | 1333 | $this->checkout->current_step->reg_form->enqueue_js(); |
| 1334 | 1334 | wp_enqueue_script('single_page_checkout'); |
@@ -1341,7 +1341,7 @@ discard block |
||
| 1341 | 1341 | * dynamic action hook for enqueueing styles and scripts with spco calls. |
| 1342 | 1342 | * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
| 1343 | 1343 | */ |
| 1344 | - do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this); |
|
| 1344 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(), $this); |
|
| 1345 | 1345 | } |
| 1346 | 1346 | |
| 1347 | 1347 | |
@@ -1390,7 +1390,7 @@ discard block |
||
| 1390 | 1390 | 'layout_strategy' => |
| 1391 | 1391 | new EE_Template_Layout( |
| 1392 | 1392 | array( |
| 1393 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
| 1393 | + 'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php', |
|
| 1394 | 1394 | 'template_args' => array( |
| 1395 | 1395 | 'empty_cart' => $empty_cart, |
| 1396 | 1396 | 'revisit' => $this->checkout->revisit, |
@@ -1400,7 +1400,7 @@ discard block |
||
| 1400 | 1400 | 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
| 1401 | 1401 | sprintf( |
| 1402 | 1402 | __('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', 'event_espresso'), |
| 1403 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
| 1403 | + '<a href="'.get_post_type_archive_link('espresso_events').'" title="', |
|
| 1404 | 1404 | '">', |
| 1405 | 1405 | '</a>' |
| 1406 | 1406 | ) |
@@ -1454,7 +1454,7 @@ discard block |
||
| 1454 | 1454 | ) { |
| 1455 | 1455 | add_filter( |
| 1456 | 1456 | 'FHEE__EEH_Template__powered_by_event_espresso__url', |
| 1457 | - function ($url) { |
|
| 1457 | + function($url) { |
|
| 1458 | 1458 | return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
| 1459 | 1459 | } |
| 1460 | 1460 | ); |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 3 | - exit('NO direct script access allowed'); |
|
| 3 | + exit('NO direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | |
@@ -17,1220 +17,1220 @@ discard block |
||
| 17 | 17 | { |
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * This is used to hold the reports template data which is setup early in the request. |
|
| 22 | - * |
|
| 23 | - * @type array |
|
| 24 | - */ |
|
| 25 | - protected $_reports_template_data = array(); |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Extend_Registrations_Admin_Page constructor. |
|
| 31 | - * |
|
| 32 | - * @param bool $routing |
|
| 33 | - */ |
|
| 34 | - public function __construct($routing = true) |
|
| 35 | - { |
|
| 36 | - parent::__construct($routing); |
|
| 37 | - if ( ! defined('REG_CAF_TEMPLATE_PATH')) { |
|
| 38 | - define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
| 39 | - define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
| 40 | - define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - protected function _extend_page_config() |
|
| 47 | - { |
|
| 48 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
| 49 | - $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
| 50 | - ? $this->_req_data['_REG_ID'] |
|
| 51 | - : 0; |
|
| 52 | - // $att_id = ! empty( $this->_req_data['ATT_ID'] ) ? ! is_array( $this->_req_data['ATT_ID'] ) : 0; |
|
| 53 | - // $att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] ) |
|
| 54 | - // ? $this->_req_data['post'] : $att_id; |
|
| 55 | - $new_page_routes = array( |
|
| 56 | - 'reports' => array( |
|
| 57 | - 'func' => '_registration_reports', |
|
| 58 | - 'capability' => 'ee_read_registrations', |
|
| 59 | - ), |
|
| 60 | - 'registration_checkins' => array( |
|
| 61 | - 'func' => '_registration_checkin_list_table', |
|
| 62 | - 'capability' => 'ee_read_checkins', |
|
| 63 | - ), |
|
| 64 | - 'newsletter_selected_send' => array( |
|
| 65 | - 'func' => '_newsletter_selected_send', |
|
| 66 | - 'noheader' => true, |
|
| 67 | - 'capability' => 'ee_send_message', |
|
| 68 | - ), |
|
| 69 | - 'delete_checkin_rows' => array( |
|
| 70 | - 'func' => '_delete_checkin_rows', |
|
| 71 | - 'noheader' => true, |
|
| 72 | - 'capability' => 'ee_delete_checkins', |
|
| 73 | - ), |
|
| 74 | - 'delete_checkin_row' => array( |
|
| 75 | - 'func' => '_delete_checkin_row', |
|
| 76 | - 'noheader' => true, |
|
| 77 | - 'capability' => 'ee_delete_checkin', |
|
| 78 | - 'obj_id' => $reg_id, |
|
| 79 | - ), |
|
| 80 | - 'toggle_checkin_status' => array( |
|
| 81 | - 'func' => '_toggle_checkin_status', |
|
| 82 | - 'noheader' => true, |
|
| 83 | - 'capability' => 'ee_edit_checkin', |
|
| 84 | - 'obj_id' => $reg_id, |
|
| 85 | - ), |
|
| 86 | - 'event_registrations' => array( |
|
| 87 | - 'func' => '_event_registrations_list_table', |
|
| 88 | - 'capability' => 'ee_read_checkins', |
|
| 89 | - ), |
|
| 90 | - ); |
|
| 91 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 92 | - $new_page_config = array( |
|
| 93 | - 'reports' => array( |
|
| 94 | - 'nav' => array( |
|
| 95 | - 'label' => __('Reports', 'event_espresso'), |
|
| 96 | - 'order' => 30, |
|
| 97 | - ), |
|
| 98 | - 'help_tabs' => array( |
|
| 99 | - 'registrations_reports_help_tab' => array( |
|
| 100 | - 'title' => __('Registration Reports', 'event_espresso'), |
|
| 101 | - 'filename' => 'registrations_reports', |
|
| 102 | - ), |
|
| 103 | - ), |
|
| 104 | - /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/ |
|
| 105 | - 'require_nonce' => false, |
|
| 106 | - ), |
|
| 107 | - 'event_registrations' => array( |
|
| 108 | - 'nav' => array( |
|
| 109 | - 'label' => __('Event Check-In', 'event_espresso'), |
|
| 110 | - 'order' => 10, |
|
| 111 | - 'persistent' => true, |
|
| 112 | - ), |
|
| 113 | - 'help_tabs' => array( |
|
| 114 | - 'registrations_event_checkin_help_tab' => array( |
|
| 115 | - 'title' => __('Registrations Event Check-In', 'event_espresso'), |
|
| 116 | - 'filename' => 'registrations_event_checkin', |
|
| 117 | - ), |
|
| 118 | - 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
| 119 | - 'title' => __('Event Check-In Table Column Headings', 'event_espresso'), |
|
| 120 | - 'filename' => 'registrations_event_checkin_table_column_headings', |
|
| 121 | - ), |
|
| 122 | - 'registrations_event_checkin_filters_help_tab' => array( |
|
| 123 | - 'title' => __('Event Check-In Filters', 'event_espresso'), |
|
| 124 | - 'filename' => 'registrations_event_checkin_filters', |
|
| 125 | - ), |
|
| 126 | - 'registrations_event_checkin_views_help_tab' => array( |
|
| 127 | - 'title' => __('Event Check-In Views', 'event_espresso'), |
|
| 128 | - 'filename' => 'registrations_event_checkin_views', |
|
| 129 | - ), |
|
| 130 | - 'registrations_event_checkin_other_help_tab' => array( |
|
| 131 | - 'title' => __('Event Check-In Other', 'event_espresso'), |
|
| 132 | - 'filename' => 'registrations_event_checkin_other', |
|
| 133 | - ), |
|
| 134 | - ), |
|
| 135 | - 'help_tour' => array('Event_Checkin_Help_Tour'), |
|
| 136 | - 'qtips' => array('Registration_List_Table_Tips'), |
|
| 137 | - 'list_table' => 'EE_Event_Registrations_List_Table', |
|
| 138 | - 'metaboxes' => array(), |
|
| 139 | - 'require_nonce' => false, |
|
| 140 | - ), |
|
| 141 | - 'registration_checkins' => array( |
|
| 142 | - 'nav' => array( |
|
| 143 | - 'label' => __('Check-In Records', 'event_espresso'), |
|
| 144 | - 'order' => 15, |
|
| 145 | - 'persistent' => false, |
|
| 146 | - ), |
|
| 147 | - 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
| 148 | - //'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ), |
|
| 149 | - 'metaboxes' => array(), |
|
| 150 | - 'require_nonce' => false, |
|
| 151 | - ), |
|
| 152 | - ); |
|
| 153 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 154 | - $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
| 155 | - $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - protected function _ajax_hooks() |
|
| 161 | - { |
|
| 162 | - parent::_ajax_hooks(); |
|
| 163 | - add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - public function load_scripts_styles() |
|
| 169 | - { |
|
| 170 | - parent::load_scripts_styles(); |
|
| 171 | - //if newsletter message type is active then let's add filter and load js for it. |
|
| 172 | - if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
| 173 | - //enqueue newsletter js |
|
| 174 | - wp_enqueue_script( |
|
| 175 | - 'ee-newsletter-trigger', |
|
| 176 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
| 177 | - array('ee-dialog'), |
|
| 178 | - EVENT_ESPRESSO_VERSION, |
|
| 179 | - true |
|
| 180 | - ); |
|
| 181 | - wp_enqueue_style( |
|
| 182 | - 'ee-newsletter-trigger-css', |
|
| 183 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
| 184 | - array(), |
|
| 185 | - EVENT_ESPRESSO_VERSION |
|
| 186 | - ); |
|
| 187 | - //hook in buttons for newsletter message type trigger. |
|
| 188 | - add_action( |
|
| 189 | - 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
| 190 | - array($this, 'add_newsletter_action_buttons'), |
|
| 191 | - 10 |
|
| 192 | - ); |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - public function load_scripts_styles_reports() |
|
| 199 | - { |
|
| 200 | - wp_register_script( |
|
| 201 | - 'ee-reg-reports-js', |
|
| 202 | - REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
| 203 | - array('google-charts'), |
|
| 204 | - EVENT_ESPRESSO_VERSION, |
|
| 205 | - true |
|
| 206 | - ); |
|
| 207 | - wp_enqueue_script('ee-reg-reports-js'); |
|
| 208 | - $this->_registration_reports_js_setup(); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - |
|
| 213 | - protected function _add_screen_options_event_registrations() |
|
| 214 | - { |
|
| 215 | - $this->_per_page_screen_option(); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - |
|
| 220 | - protected function _add_screen_options_registration_checkins() |
|
| 221 | - { |
|
| 222 | - $page_title = $this->_admin_page_title; |
|
| 223 | - $this->_admin_page_title = __('Check-In Records', 'event_espresso'); |
|
| 224 | - $this->_per_page_screen_option(); |
|
| 225 | - $this->_admin_page_title = $page_title; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - protected function _set_list_table_views_event_registrations() |
|
| 231 | - { |
|
| 232 | - $this->_views = array( |
|
| 233 | - 'all' => array( |
|
| 234 | - 'slug' => 'all', |
|
| 235 | - 'label' => __('All', 'event_espresso'), |
|
| 236 | - 'count' => 0, |
|
| 237 | - 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
| 238 | - ? array() |
|
| 239 | - : array( |
|
| 240 | - 'toggle_checkin_status' => __('Toggle Check-In', 'event_espresso'), |
|
| 241 | - //'trash_registrations' => __('Trash Registrations', 'event_espresso') |
|
| 242 | - ), |
|
| 243 | - ), |
|
| 244 | - ); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - protected function _set_list_table_views_registration_checkins() |
|
| 250 | - { |
|
| 251 | - $this->_views = array( |
|
| 252 | - 'all' => array( |
|
| 253 | - 'slug' => 'all', |
|
| 254 | - 'label' => __('All', 'event_espresso'), |
|
| 255 | - 'count' => 0, |
|
| 256 | - 'bulk_action' => array('delete_checkin_rows' => __('Delete Check-In Rows', 'event_espresso')), |
|
| 257 | - ), |
|
| 258 | - ); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * callback for ajax action. |
|
| 265 | - * |
|
| 266 | - * @since 4.3.0 |
|
| 267 | - * @return void (JSON) |
|
| 268 | - * @throws \EE_Error |
|
| 269 | - */ |
|
| 270 | - public function get_newsletter_form_content() |
|
| 271 | - { |
|
| 272 | - //do a nonce check cause we're not coming in from an normal route here. |
|
| 273 | - $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
| 274 | - $this->_req_data['get_newsletter_form_content_nonce'] |
|
| 275 | - ) : ''; |
|
| 276 | - $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
| 277 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 278 | - //let's get the mtp for the incoming MTP_ ID |
|
| 279 | - if ( ! isset($this->_req_data['GRP_ID'])) { |
|
| 280 | - EE_Error::add_error( |
|
| 281 | - __( |
|
| 282 | - 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
| 283 | - 'event_espresso' |
|
| 284 | - ), |
|
| 285 | - __FILE__, |
|
| 286 | - __FUNCTION__, |
|
| 287 | - __LINE__ |
|
| 288 | - ); |
|
| 289 | - $this->_template_args['success'] = false; |
|
| 290 | - $this->_template_args['error'] = true; |
|
| 291 | - $this->_return_json(); |
|
| 292 | - } |
|
| 293 | - $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
| 294 | - if ( ! $MTPG instanceof EE_Message_Template_Group) { |
|
| 295 | - EE_Error::add_error( |
|
| 296 | - sprintf( |
|
| 297 | - __( |
|
| 298 | - 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
| 299 | - 'event_espresso' |
|
| 300 | - ), |
|
| 301 | - $this->_req_data['GRP_ID'] |
|
| 302 | - ), |
|
| 303 | - __FILE__, |
|
| 304 | - __FUNCTION__, |
|
| 305 | - __LINE__ |
|
| 306 | - ); |
|
| 307 | - $this->_template_args['success'] = false; |
|
| 308 | - $this->_template_args['error'] = true; |
|
| 309 | - $this->_return_json(); |
|
| 310 | - } |
|
| 311 | - $MTPs = $MTPG->context_templates(); |
|
| 312 | - $MTPs = $MTPs['attendee']; |
|
| 313 | - $template_fields = array(); |
|
| 314 | - /** @var EE_Message_Template $MTP */ |
|
| 315 | - foreach ($MTPs as $MTP) { |
|
| 316 | - $field = $MTP->get('MTP_template_field'); |
|
| 317 | - if ($field === 'content') { |
|
| 318 | - $content = $MTP->get('MTP_content'); |
|
| 319 | - if ( ! empty($content['newsletter_content'])) { |
|
| 320 | - $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
| 321 | - } |
|
| 322 | - continue; |
|
| 323 | - } |
|
| 324 | - $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content'); |
|
| 325 | - } |
|
| 326 | - $this->_template_args['success'] = true; |
|
| 327 | - $this->_template_args['error'] = false; |
|
| 328 | - $this->_template_args['data'] = array( |
|
| 329 | - 'batch_message_from' => isset($template_fields['from']) |
|
| 330 | - ? $template_fields['from'] |
|
| 331 | - : '', |
|
| 332 | - 'batch_message_subject' => isset($template_fields['subject']) |
|
| 333 | - ? $template_fields['subject'] |
|
| 334 | - : '', |
|
| 335 | - 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
| 336 | - ? $template_fields['newsletter_content'] |
|
| 337 | - : '', |
|
| 338 | - ); |
|
| 339 | - $this->_return_json(); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
| 346 | - * |
|
| 347 | - * @since 4.3.0 |
|
| 348 | - * @param EE_Admin_List_Table $list_table |
|
| 349 | - * @return void |
|
| 350 | - */ |
|
| 351 | - public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
| 352 | - { |
|
| 353 | - if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
| 354 | - 'ee_send_message', |
|
| 355 | - 'espresso_registrations_newsletter_selected_send' |
|
| 356 | - ) |
|
| 357 | - ) { |
|
| 358 | - return; |
|
| 359 | - } |
|
| 360 | - $routes_to_add_to = array( |
|
| 361 | - 'contact_list', |
|
| 362 | - 'event_registrations', |
|
| 363 | - 'default', |
|
| 364 | - ); |
|
| 365 | - if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
| 366 | - if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
| 367 | - || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
| 368 | - ) { |
|
| 369 | - echo ''; |
|
| 370 | - } else { |
|
| 371 | - $button_text = sprintf( |
|
| 372 | - __('Send Batch Message (%s selected)', 'event_espresso'), |
|
| 373 | - '<span class="send-selected-newsletter-count">0</span>' |
|
| 374 | - ); |
|
| 375 | - echo '<button id="selected-batch-send-trigger" class="button secondary-button"><span class="dashicons dashicons-email "></span>' |
|
| 376 | - . $button_text |
|
| 377 | - . '</button>'; |
|
| 378 | - add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - public function newsletter_send_form_skeleton() |
|
| 386 | - { |
|
| 387 | - $list_table = $this->_list_table_object; |
|
| 388 | - $codes = array(); |
|
| 389 | - //need to templates for the newsletter message type for the template selector. |
|
| 390 | - $values[] = array('text' => __('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
| 391 | - $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
| 392 | - array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
| 393 | - ); |
|
| 394 | - foreach ($mtps as $mtp) { |
|
| 395 | - $name = $mtp->name(); |
|
| 396 | - $values[] = array( |
|
| 397 | - 'text' => empty($name) ? __('Global', 'event_espresso') : $name, |
|
| 398 | - 'id' => $mtp->ID(), |
|
| 399 | - ); |
|
| 400 | - } |
|
| 401 | - //need to get a list of shortcodes that are available for the newsletter message type. |
|
| 402 | - $shortcodes = EEH_MSG_Template::get_shortcodes('newsletter', 'email', array(), 'attendee', false); |
|
| 403 | - foreach ($shortcodes as $field => $shortcode_array) { |
|
| 404 | - $codes[$field] = implode(', ', array_keys($shortcode_array)); |
|
| 405 | - } |
|
| 406 | - $shortcodes = $codes; |
|
| 407 | - $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
| 408 | - $form_template_args = array( |
|
| 409 | - 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
| 410 | - 'form_route' => 'newsletter_selected_send', |
|
| 411 | - 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
| 412 | - 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
| 413 | - 'redirect_back_to' => $this->_req_action, |
|
| 414 | - 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
| 415 | - 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
| 416 | - 'shortcodes' => $shortcodes, |
|
| 417 | - 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
| 418 | - ); |
|
| 419 | - EEH_Template::display_template($form_template, $form_template_args); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Handles sending selected registrations/contacts a newsletter. |
|
| 426 | - * |
|
| 427 | - * @since 4.3.0 |
|
| 428 | - * @return void |
|
| 429 | - * @throws \EE_Error |
|
| 430 | - */ |
|
| 431 | - protected function _newsletter_selected_send() |
|
| 432 | - { |
|
| 433 | - $success = true; |
|
| 434 | - //first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
| 435 | - if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
| 436 | - EE_Error::add_error( |
|
| 437 | - __( |
|
| 438 | - 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
| 439 | - 'event_espresso' |
|
| 440 | - ), |
|
| 441 | - __FILE__, |
|
| 442 | - __FUNCTION__, |
|
| 443 | - __LINE__ |
|
| 444 | - ); |
|
| 445 | - $success = false; |
|
| 446 | - } |
|
| 447 | - if ($success) { |
|
| 448 | - //update Message template in case there are any changes |
|
| 449 | - $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 450 | - $this->_req_data['newsletter_mtp_selected'] |
|
| 451 | - ); |
|
| 452 | - $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
| 453 | - ? $Message_Template_Group->context_templates() |
|
| 454 | - : array(); |
|
| 455 | - if (empty($Message_Templates)) { |
|
| 456 | - EE_Error::add_error( |
|
| 457 | - __( |
|
| 458 | - 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
| 459 | - 'event_espresso' |
|
| 460 | - ), |
|
| 461 | - __FILE__, |
|
| 462 | - __FUNCTION__, |
|
| 463 | - __LINE__ |
|
| 464 | - ); |
|
| 465 | - } |
|
| 466 | - //let's just update the specific fields |
|
| 467 | - foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
| 468 | - if ($Message_Template instanceof EE_Message_Template) { |
|
| 469 | - $field = $Message_Template->get('MTP_template_field'); |
|
| 470 | - $content = $Message_Template->get('MTP_content'); |
|
| 471 | - $new_content = $content; |
|
| 472 | - switch ($field) { |
|
| 473 | - case 'from' : |
|
| 474 | - $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
| 475 | - ? $this->_req_data['batch_message']['from'] |
|
| 476 | - : $content; |
|
| 477 | - break; |
|
| 478 | - case 'subject' : |
|
| 479 | - $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
| 480 | - ? $this->_req_data['batch_message']['subject'] |
|
| 481 | - : $content; |
|
| 482 | - break; |
|
| 483 | - case 'content' : |
|
| 484 | - $new_content = $content; |
|
| 485 | - $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
| 486 | - ? $this->_req_data['batch_message']['content'] |
|
| 487 | - : $content['newsletter_content']; |
|
| 488 | - break; |
|
| 489 | - default : |
|
| 490 | - //continue the foreach loop, we don't want to set $new_content nor save. |
|
| 491 | - continue 2; |
|
| 492 | - } |
|
| 493 | - $Message_Template->set('MTP_content', $new_content); |
|
| 494 | - $Message_Template->save(); |
|
| 495 | - } |
|
| 496 | - } |
|
| 497 | - //great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
| 498 | - $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
| 499 | - ? $this->_req_data['batch_message']['id_type'] |
|
| 500 | - : 'registration'; |
|
| 501 | - //id_type will affect how we assemble the ids. |
|
| 502 | - $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
| 503 | - ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
| 504 | - : array(); |
|
| 505 | - $registrations_used_for_contact_data = array(); |
|
| 506 | - //using switch because eventually we'll have other contexts that will be used for generating messages. |
|
| 507 | - switch ($id_type) { |
|
| 508 | - case 'registration' : |
|
| 509 | - $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
| 510 | - array( |
|
| 511 | - array( |
|
| 512 | - 'REG_ID' => array('IN', $ids), |
|
| 513 | - ), |
|
| 514 | - ) |
|
| 515 | - ); |
|
| 516 | - break; |
|
| 517 | - case 'contact' : |
|
| 518 | - $registrations_used_for_contact_data = EEM_Registration::instance() |
|
| 519 | - ->get_latest_registration_for_each_of_given_contacts($ids); |
|
| 520 | - break; |
|
| 521 | - } |
|
| 522 | - do_action( |
|
| 523 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 524 | - $registrations_used_for_contact_data, |
|
| 525 | - $Message_Template_Group->ID() |
|
| 526 | - ); |
|
| 527 | - //kept for backward compat, internally we no longer use this action. |
|
| 528 | - //@deprecated 4.8.36.rc.002 |
|
| 529 | - $contacts = $id_type === 'registration' |
|
| 530 | - ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
| 531 | - : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
| 532 | - do_action( |
|
| 533 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
| 534 | - $contacts, |
|
| 535 | - $Message_Template_Group->ID() |
|
| 536 | - ); |
|
| 537 | - } |
|
| 538 | - $query_args = array( |
|
| 539 | - 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
| 540 | - ? $this->_req_data['redirect_back_to'] |
|
| 541 | - : 'default', |
|
| 542 | - ); |
|
| 543 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
| 550 | - * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
| 551 | - */ |
|
| 552 | - protected function _registration_reports_js_setup() |
|
| 553 | - { |
|
| 554 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
| 555 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * generates Business Reports regarding Registrations |
|
| 562 | - * |
|
| 563 | - * @access protected |
|
| 564 | - * @return void |
|
| 565 | - */ |
|
| 566 | - protected function _registration_reports() |
|
| 567 | - { |
|
| 568 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
| 569 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 570 | - $template_path, |
|
| 571 | - $this->_reports_template_data, |
|
| 572 | - true |
|
| 573 | - ); |
|
| 574 | - // the final template wrapper |
|
| 575 | - $this->display_admin_page_with_no_sidebar(); |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * Generates Business Report showing total registrations per day. |
|
| 582 | - * |
|
| 583 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
| 584 | - * @return string |
|
| 585 | - */ |
|
| 586 | - private function _registrations_per_day_report($period = '-1 month') |
|
| 587 | - { |
|
| 588 | - $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
| 589 | - $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
| 590 | - $results = (array)$results; |
|
| 591 | - $regs = array(); |
|
| 592 | - $subtitle = ''; |
|
| 593 | - if ($results) { |
|
| 594 | - $column_titles = array(); |
|
| 595 | - $tracker = 0; |
|
| 596 | - foreach ($results as $result) { |
|
| 597 | - $report_column_values = array(); |
|
| 598 | - foreach ($result as $property_name => $property_value) { |
|
| 599 | - $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
| 600 | - : (int)$property_value; |
|
| 601 | - $report_column_values[] = $property_value; |
|
| 602 | - if ($tracker === 0) { |
|
| 603 | - if ($property_name === 'Registration_REG_date') { |
|
| 604 | - $column_titles[] = __('Date (only days with registrations are shown)', 'event_espresso'); |
|
| 605 | - } else { |
|
| 606 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
| 607 | - } |
|
| 608 | - } |
|
| 609 | - } |
|
| 610 | - $tracker++; |
|
| 611 | - $regs[] = $report_column_values; |
|
| 612 | - } |
|
| 613 | - //make sure the column_titles is pushed to the beginning of the array |
|
| 614 | - array_unshift($regs, $column_titles); |
|
| 615 | - //setup the date range. |
|
| 616 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
| 617 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 618 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
| 619 | - $subtitle = sprintf( |
|
| 620 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
| 621 | - $beginning_date->format('Y-m-d'), |
|
| 622 | - $ending_date->format('Y-m-d') |
|
| 623 | - ); |
|
| 624 | - } |
|
| 625 | - $report_title = __('Total Registrations per Day', 'event_espresso'); |
|
| 626 | - $report_params = array( |
|
| 627 | - 'title' => $report_title, |
|
| 628 | - 'subtitle' => $subtitle, |
|
| 629 | - 'id' => $report_ID, |
|
| 630 | - 'regs' => $regs, |
|
| 631 | - 'noResults' => empty($regs), |
|
| 632 | - 'noRegsMsg' => sprintf( |
|
| 633 | - __( |
|
| 634 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
| 635 | - 'event_espresso' |
|
| 636 | - ), |
|
| 637 | - '<h2>' . $report_title . '</h2><p>', |
|
| 638 | - '</p>' |
|
| 639 | - ), |
|
| 640 | - ); |
|
| 641 | - wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
| 642 | - return $report_ID; |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - |
|
| 646 | - |
|
| 647 | - /** |
|
| 648 | - * Generates Business Report showing total registrations per event. |
|
| 649 | - * |
|
| 650 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
| 651 | - * @return string |
|
| 652 | - */ |
|
| 653 | - private function _registrations_per_event_report($period = '-1 month') |
|
| 654 | - { |
|
| 655 | - $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
| 656 | - $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
| 657 | - $results = (array)$results; |
|
| 658 | - $regs = array(); |
|
| 659 | - $subtitle = ''; |
|
| 660 | - if ($results) { |
|
| 661 | - $column_titles = array(); |
|
| 662 | - $tracker = 0; |
|
| 663 | - foreach ($results as $result) { |
|
| 664 | - $report_column_values = array(); |
|
| 665 | - foreach ($result as $property_name => $property_value) { |
|
| 666 | - $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
| 667 | - $property_value, |
|
| 668 | - 4, |
|
| 669 | - '...' |
|
| 670 | - ) : (int)$property_value; |
|
| 671 | - $report_column_values[] = $property_value; |
|
| 672 | - if ($tracker === 0) { |
|
| 673 | - if ($property_name === 'Registration_Event') { |
|
| 674 | - $column_titles[] = __('Event', 'event_espresso'); |
|
| 675 | - } else { |
|
| 676 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
| 677 | - } |
|
| 678 | - } |
|
| 679 | - } |
|
| 680 | - $tracker++; |
|
| 681 | - $regs[] = $report_column_values; |
|
| 682 | - } |
|
| 683 | - //make sure the column_titles is pushed to the beginning of the array |
|
| 684 | - array_unshift($regs, $column_titles); |
|
| 685 | - //setup the date range. |
|
| 686 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
| 687 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 688 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
| 689 | - $subtitle = sprintf( |
|
| 690 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
| 691 | - $beginning_date->format('Y-m-d'), |
|
| 692 | - $ending_date->format('Y-m-d') |
|
| 693 | - ); |
|
| 694 | - } |
|
| 695 | - $report_title = __('Total Registrations per Event', 'event_espresso'); |
|
| 696 | - $report_params = array( |
|
| 697 | - 'title' => $report_title, |
|
| 698 | - 'subtitle' => $subtitle, |
|
| 699 | - 'id' => $report_ID, |
|
| 700 | - 'regs' => $regs, |
|
| 701 | - 'noResults' => empty($regs), |
|
| 702 | - 'noRegsMsg' => sprintf( |
|
| 703 | - __( |
|
| 704 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
| 705 | - 'event_espresso' |
|
| 706 | - ), |
|
| 707 | - '<h2>' . $report_title . '</h2><p>', |
|
| 708 | - '</p>' |
|
| 709 | - ), |
|
| 710 | - ); |
|
| 711 | - wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
| 712 | - return $report_ID; |
|
| 713 | - } |
|
| 714 | - |
|
| 715 | - |
|
| 716 | - |
|
| 717 | - /** |
|
| 718 | - * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
| 719 | - * |
|
| 720 | - * @access protected |
|
| 721 | - * @return void |
|
| 722 | - * @throws \EE_Error |
|
| 723 | - */ |
|
| 724 | - protected function _registration_checkin_list_table() |
|
| 725 | - { |
|
| 726 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 727 | - $reg_id = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : null; |
|
| 728 | - /** @var EE_Registration $reg */ |
|
| 729 | - $reg = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
| 730 | - $this->_admin_page_title .= $this->get_action_link_or_button( |
|
| 731 | - 'new_registration', |
|
| 732 | - 'add-registrant', |
|
| 733 | - array('event_id' => $reg->event_ID()), |
|
| 734 | - 'add-new-h2' |
|
| 735 | - ); |
|
| 736 | - $legend_items = array( |
|
| 737 | - 'checkin' => array( |
|
| 738 | - 'class' => 'ee-icon ee-icon-check-in', |
|
| 739 | - 'desc' => __('This indicates the attendee has been checked in', 'event_espresso'), |
|
| 740 | - ), |
|
| 741 | - 'checkout' => array( |
|
| 742 | - 'class' => 'ee-icon ee-icon-check-out', |
|
| 743 | - 'desc' => __('This indicates the attendee has been checked out', 'event_espresso'), |
|
| 744 | - ), |
|
| 745 | - ); |
|
| 746 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
| 747 | - $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 748 | - $go_back_url = ! empty($reg_id) ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 749 | - array( |
|
| 750 | - 'action' => 'event_registrations', |
|
| 751 | - 'event_id' => EEM_Registration::instance()->get_one_by_ID($reg_id)->get_first_related('Event')->ID(), |
|
| 752 | - 'DTT_ID' => $dtt_id, |
|
| 753 | - ), |
|
| 754 | - $this->_admin_base_url |
|
| 755 | - ) : ''; |
|
| 756 | - $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
| 757 | - ? '<h2>' . sprintf( |
|
| 758 | - __("%s's check in records for %s at the event, %s", 'event_espresso'), |
|
| 759 | - '<span id="checkin-attendee-name">' |
|
| 760 | - . EEM_Registration::instance() |
|
| 761 | - ->get_one_by_ID($reg_id) |
|
| 762 | - ->get_first_related('Attendee') |
|
| 763 | - ->full_name() . '</span>', |
|
| 764 | - '<span id="checkin-dtt"><a href="' . $go_back_url . '">' |
|
| 765 | - . EEM_Datetime::instance() |
|
| 766 | - ->get_one_by_ID($dtt_id) |
|
| 767 | - ->start_date_and_time() . ' - ' |
|
| 768 | - . EEM_Datetime::instance() |
|
| 769 | - ->get_one_by_ID($dtt_id) |
|
| 770 | - ->end_date_and_time() . '</a></span>', |
|
| 771 | - '<span id="checkin-event-name">' |
|
| 772 | - . EEM_Datetime::instance() |
|
| 773 | - ->get_one_by_ID($dtt_id) |
|
| 774 | - ->get_first_related('Event') |
|
| 775 | - ->get('EVT_name') . '</span>' |
|
| 776 | - ) . '</h2>' |
|
| 777 | - : ''; |
|
| 778 | - $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
| 779 | - ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : ''; |
|
| 780 | - $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
| 781 | - ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
| 782 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - |
|
| 786 | - |
|
| 787 | - /** |
|
| 788 | - * toggle the Check-in status for the given registration (coming from ajax) |
|
| 789 | - * |
|
| 790 | - * @return void (JSON) |
|
| 791 | - */ |
|
| 792 | - public function toggle_checkin_status() |
|
| 793 | - { |
|
| 794 | - //first make sure we have the necessary data |
|
| 795 | - if ( ! isset($this->_req_data['_regid'])) { |
|
| 796 | - EE_Error::add_error( |
|
| 797 | - __( |
|
| 798 | - 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
| 799 | - 'event_espresso' |
|
| 800 | - ), |
|
| 801 | - __FILE__, |
|
| 802 | - __FUNCTION__, |
|
| 803 | - __LINE__ |
|
| 804 | - ); |
|
| 805 | - $this->_template_args['success'] = false; |
|
| 806 | - $this->_template_args['error'] = true; |
|
| 807 | - $this->_return_json(); |
|
| 808 | - }; |
|
| 809 | - //do a nonce check cause we're not coming in from an normal route here. |
|
| 810 | - $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
| 811 | - : ''; |
|
| 812 | - $nonce_ref = 'checkin_nonce'; |
|
| 813 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 814 | - //beautiful! Made it this far so let's get the status. |
|
| 815 | - $new_status = $this->_toggle_checkin_status(); |
|
| 816 | - //setup new class to return via ajax |
|
| 817 | - $this->_template_args['admin_page_content'] = 'clickable trigger-checkin checkin-icons checkedin-status-' |
|
| 818 | - . $new_status; |
|
| 819 | - $this->_template_args['success'] = true; |
|
| 820 | - $this->_return_json(); |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - |
|
| 824 | - |
|
| 825 | - /** |
|
| 826 | - * handles toggling the checkin status for the registration, |
|
| 827 | - * |
|
| 828 | - * @access protected |
|
| 829 | - * @return int|void |
|
| 830 | - */ |
|
| 831 | - protected function _toggle_checkin_status() |
|
| 832 | - { |
|
| 833 | - //first let's get the query args out of the way for the redirect |
|
| 834 | - $query_args = array( |
|
| 835 | - 'action' => 'event_registrations', |
|
| 836 | - 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
| 837 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
| 838 | - ); |
|
| 839 | - $new_status = false; |
|
| 840 | - // bulk action check in toggle |
|
| 841 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 842 | - // cycle thru checkboxes |
|
| 843 | - while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 844 | - $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 845 | - $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
| 846 | - } |
|
| 847 | - } elseif (isset($this->_req_data['_regid'])) { |
|
| 848 | - //coming from ajax request |
|
| 849 | - $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
| 850 | - $query_args['DTT_ID'] = $DTT_ID; |
|
| 851 | - $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
| 852 | - } else { |
|
| 853 | - EE_Error::add_error( |
|
| 854 | - __('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
| 855 | - __FILE__, |
|
| 856 | - __FUNCTION__, |
|
| 857 | - __LINE__ |
|
| 858 | - ); |
|
| 859 | - } |
|
| 860 | - if (defined('DOING_AJAX')) { |
|
| 861 | - return $new_status; |
|
| 862 | - } |
|
| 863 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - |
|
| 867 | - |
|
| 868 | - /** |
|
| 869 | - * This is toggles a single Check-in for the given registration and datetime. |
|
| 870 | - * |
|
| 871 | - * @param int $REG_ID The registration we're toggling |
|
| 872 | - * @param int $DTT_ID The datetime we're toggling |
|
| 873 | - * @return int The new status toggled to. |
|
| 874 | - * @throws \EE_Error |
|
| 875 | - */ |
|
| 876 | - private function _toggle_checkin($REG_ID, $DTT_ID) |
|
| 877 | - { |
|
| 878 | - /** @var EE_Registration $REG */ |
|
| 879 | - $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 880 | - $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
| 881 | - if ($new_status !== false) { |
|
| 882 | - EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
| 883 | - } else { |
|
| 884 | - EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
| 885 | - $new_status = false; |
|
| 886 | - } |
|
| 887 | - return $new_status; |
|
| 888 | - } |
|
| 889 | - |
|
| 890 | - |
|
| 891 | - |
|
| 892 | - /** |
|
| 893 | - * Takes care of deleting multiple EE_Checkin table rows |
|
| 894 | - * |
|
| 895 | - * @access protected |
|
| 896 | - * @return void |
|
| 897 | - * @throws \EE_Error |
|
| 898 | - */ |
|
| 899 | - protected function _delete_checkin_rows() |
|
| 900 | - { |
|
| 901 | - $query_args = array( |
|
| 902 | - 'action' => 'registration_checkins', |
|
| 903 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
| 904 | - '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0, |
|
| 905 | - ); |
|
| 906 | - $errors = 0; |
|
| 907 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 908 | - while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 909 | - if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
| 910 | - $errors++; |
|
| 911 | - } |
|
| 912 | - } |
|
| 913 | - } else { |
|
| 914 | - EE_Error::add_error( |
|
| 915 | - __( |
|
| 916 | - 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
| 917 | - 'event_espresso' |
|
| 918 | - ), |
|
| 919 | - __FILE__, |
|
| 920 | - __FUNCTION__, |
|
| 921 | - __LINE__ |
|
| 922 | - ); |
|
| 923 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 924 | - } |
|
| 925 | - if ($errors > 0) { |
|
| 926 | - EE_Error::add_error( |
|
| 927 | - sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
| 928 | - __FILE__, |
|
| 929 | - __FUNCTION__, |
|
| 930 | - __LINE__ |
|
| 931 | - ); |
|
| 932 | - } else { |
|
| 933 | - EE_Error::add_success(__('Records were successfully deleted', 'event_espresso')); |
|
| 934 | - } |
|
| 935 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - |
|
| 939 | - |
|
| 940 | - /** |
|
| 941 | - * Deletes a single EE_Checkin row |
|
| 942 | - * |
|
| 943 | - * @return void |
|
| 944 | - * @throws \EE_Error |
|
| 945 | - */ |
|
| 946 | - protected function _delete_checkin_row() |
|
| 947 | - { |
|
| 948 | - $query_args = array( |
|
| 949 | - 'action' => 'registration_checkins', |
|
| 950 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
| 951 | - '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0, |
|
| 952 | - ); |
|
| 953 | - if ( ! empty($this->_req_data['CHK_ID'])) { |
|
| 954 | - if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
| 955 | - EE_Error::add_error( |
|
| 956 | - __('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
| 957 | - __FILE__, |
|
| 958 | - __FUNCTION__, |
|
| 959 | - __LINE__ |
|
| 960 | - ); |
|
| 961 | - } else { |
|
| 962 | - EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso')); |
|
| 963 | - } |
|
| 964 | - } else { |
|
| 965 | - EE_Error::add_error( |
|
| 966 | - __( |
|
| 967 | - 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
| 968 | - 'event_espresso' |
|
| 969 | - ), |
|
| 970 | - __FILE__, |
|
| 971 | - __FUNCTION__, |
|
| 972 | - __LINE__ |
|
| 973 | - ); |
|
| 974 | - } |
|
| 975 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 976 | - } |
|
| 977 | - |
|
| 978 | - |
|
| 979 | - |
|
| 980 | - /** |
|
| 981 | - * generates HTML for the Event Registrations List Table |
|
| 982 | - * |
|
| 983 | - * @access protected |
|
| 984 | - * @return void |
|
| 985 | - * @throws \EE_Error |
|
| 986 | - */ |
|
| 987 | - protected function _event_registrations_list_table() |
|
| 988 | - { |
|
| 989 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 990 | - $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
| 991 | - ? $this->get_action_link_or_button( |
|
| 992 | - 'new_registration', |
|
| 993 | - 'add-registrant', |
|
| 994 | - array('event_id' => $this->_req_data['event_id']), |
|
| 995 | - 'add-new-h2', |
|
| 996 | - '', |
|
| 997 | - false |
|
| 998 | - ) |
|
| 999 | - : ''; |
|
| 1000 | - $legend_items = array( |
|
| 1001 | - 'star-icon' => array( |
|
| 1002 | - 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
| 1003 | - 'desc' => __('This Registrant is the Primary Registrant', 'event_espresso'), |
|
| 1004 | - ), |
|
| 1005 | - 'checkin' => array( |
|
| 1006 | - 'class' => 'ee-icon ee-icon-check-in', |
|
| 1007 | - 'desc' => __('This Registrant has been Checked In', 'event_espresso'), |
|
| 1008 | - ), |
|
| 1009 | - 'checkout' => array( |
|
| 1010 | - 'class' => 'ee-icon ee-icon-check-out', |
|
| 1011 | - 'desc' => __('This Registrant has been Checked Out', 'event_espresso'), |
|
| 1012 | - ), |
|
| 1013 | - 'nocheckinrecord' => array( |
|
| 1014 | - 'class' => 'dashicons dashicons-no', |
|
| 1015 | - 'desc' => __('No Check-in Record has been Created for this Registrant', 'event_espresso'), |
|
| 1016 | - ), |
|
| 1017 | - 'view_details' => array( |
|
| 1018 | - 'class' => 'dashicons dashicons-search', |
|
| 1019 | - 'desc' => __('View All Check-in Records for this Registrant', 'event_espresso'), |
|
| 1020 | - ), |
|
| 1021 | - 'approved_status' => array( |
|
| 1022 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 1023 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
| 1024 | - ), |
|
| 1025 | - 'cancelled_status' => array( |
|
| 1026 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 1027 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
| 1028 | - ), |
|
| 1029 | - 'declined_status' => array( |
|
| 1030 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 1031 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
| 1032 | - ), |
|
| 1033 | - 'not_approved' => array( |
|
| 1034 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 1035 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
| 1036 | - ), |
|
| 1037 | - 'pending_status' => array( |
|
| 1038 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 1039 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
| 1040 | - ), |
|
| 1041 | - 'wait_list' => array( |
|
| 1042 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 1043 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
| 1044 | - ), |
|
| 1045 | - ); |
|
| 1046 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
| 1047 | - $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
| 1048 | - $this->_template_args['before_list_table'] = ! empty($event_id) |
|
| 1049 | - ? '<h2>' . sprintf( |
|
| 1050 | - __('Viewing Registrations for Event: %s', 'event_espresso'), |
|
| 1051 | - EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
| 1052 | - ) . '</h2>' |
|
| 1053 | - : ''; |
|
| 1054 | - //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event. |
|
| 1055 | - /** @var EE_Event $event */ |
|
| 1056 | - $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
| 1057 | - $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
| 1058 | - $datetime = null; |
|
| 1059 | - if ($event instanceof EE_Event) { |
|
| 1060 | - $datetimes_on_event = $event->datetimes(); |
|
| 1061 | - if (count($datetimes_on_event) === 1) { |
|
| 1062 | - $datetime = reset($datetimes_on_event); |
|
| 1063 | - } |
|
| 1064 | - } |
|
| 1065 | - $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
| 1066 | - if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
| 1067 | - $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
| 1068 | - $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
| 1069 | - $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
| 1070 | - $this->_template_args['before_list_table'] .= $datetime->name(); |
|
| 1071 | - $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
| 1072 | - $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
| 1073 | - } |
|
| 1074 | - //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column |
|
| 1075 | - //represents |
|
| 1076 | - if ( ! $datetime instanceof EE_Datetime) { |
|
| 1077 | - $this->_template_args['before_list_table'] .= '<br><p class="description">' |
|
| 1078 | - . __('In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
| 1079 | - 'event_espresso') |
|
| 1080 | - . '</p>'; |
|
| 1081 | - } |
|
| 1082 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - |
|
| 1086 | - |
|
| 1087 | - /** |
|
| 1088 | - * get_attendees |
|
| 1089 | - * |
|
| 1090 | - * @param int $per_page |
|
| 1091 | - * @param bool $count whether to return count or data. |
|
| 1092 | - * @param bool $trash |
|
| 1093 | - * @param string $orderby |
|
| 1094 | - * @return array |
|
| 1095 | - * @throws \EE_Error |
|
| 1096 | - * @access public |
|
| 1097 | - */ |
|
| 1098 | - public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = '') |
|
| 1099 | - { |
|
| 1100 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1101 | - require_once(EE_MODELS . 'EEM_Attendee.model.php'); |
|
| 1102 | - //$ATT_MDL = EEM_Attendee::instance(); |
|
| 1103 | - $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
| 1104 | - $CAT_ID = isset($this->_req_data['category_id']) ? absint($this->_req_data['category_id']) : false; |
|
| 1105 | - $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 1106 | - $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
| 1107 | - switch ($this->_req_data['orderby']) { |
|
| 1108 | - case '_REG_date': |
|
| 1109 | - $orderby = 'REG_date'; |
|
| 1110 | - break; |
|
| 1111 | - default : |
|
| 1112 | - $orderby = 'Attendee.ATT_lname'; |
|
| 20 | + /** |
|
| 21 | + * This is used to hold the reports template data which is setup early in the request. |
|
| 22 | + * |
|
| 23 | + * @type array |
|
| 24 | + */ |
|
| 25 | + protected $_reports_template_data = array(); |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Extend_Registrations_Admin_Page constructor. |
|
| 31 | + * |
|
| 32 | + * @param bool $routing |
|
| 33 | + */ |
|
| 34 | + public function __construct($routing = true) |
|
| 35 | + { |
|
| 36 | + parent::__construct($routing); |
|
| 37 | + if ( ! defined('REG_CAF_TEMPLATE_PATH')) { |
|
| 38 | + define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
| 39 | + define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
| 40 | + define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + protected function _extend_page_config() |
|
| 47 | + { |
|
| 48 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
| 49 | + $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
| 50 | + ? $this->_req_data['_REG_ID'] |
|
| 51 | + : 0; |
|
| 52 | + // $att_id = ! empty( $this->_req_data['ATT_ID'] ) ? ! is_array( $this->_req_data['ATT_ID'] ) : 0; |
|
| 53 | + // $att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] ) |
|
| 54 | + // ? $this->_req_data['post'] : $att_id; |
|
| 55 | + $new_page_routes = array( |
|
| 56 | + 'reports' => array( |
|
| 57 | + 'func' => '_registration_reports', |
|
| 58 | + 'capability' => 'ee_read_registrations', |
|
| 59 | + ), |
|
| 60 | + 'registration_checkins' => array( |
|
| 61 | + 'func' => '_registration_checkin_list_table', |
|
| 62 | + 'capability' => 'ee_read_checkins', |
|
| 63 | + ), |
|
| 64 | + 'newsletter_selected_send' => array( |
|
| 65 | + 'func' => '_newsletter_selected_send', |
|
| 66 | + 'noheader' => true, |
|
| 67 | + 'capability' => 'ee_send_message', |
|
| 68 | + ), |
|
| 69 | + 'delete_checkin_rows' => array( |
|
| 70 | + 'func' => '_delete_checkin_rows', |
|
| 71 | + 'noheader' => true, |
|
| 72 | + 'capability' => 'ee_delete_checkins', |
|
| 73 | + ), |
|
| 74 | + 'delete_checkin_row' => array( |
|
| 75 | + 'func' => '_delete_checkin_row', |
|
| 76 | + 'noheader' => true, |
|
| 77 | + 'capability' => 'ee_delete_checkin', |
|
| 78 | + 'obj_id' => $reg_id, |
|
| 79 | + ), |
|
| 80 | + 'toggle_checkin_status' => array( |
|
| 81 | + 'func' => '_toggle_checkin_status', |
|
| 82 | + 'noheader' => true, |
|
| 83 | + 'capability' => 'ee_edit_checkin', |
|
| 84 | + 'obj_id' => $reg_id, |
|
| 85 | + ), |
|
| 86 | + 'event_registrations' => array( |
|
| 87 | + 'func' => '_event_registrations_list_table', |
|
| 88 | + 'capability' => 'ee_read_checkins', |
|
| 89 | + ), |
|
| 90 | + ); |
|
| 91 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 92 | + $new_page_config = array( |
|
| 93 | + 'reports' => array( |
|
| 94 | + 'nav' => array( |
|
| 95 | + 'label' => __('Reports', 'event_espresso'), |
|
| 96 | + 'order' => 30, |
|
| 97 | + ), |
|
| 98 | + 'help_tabs' => array( |
|
| 99 | + 'registrations_reports_help_tab' => array( |
|
| 100 | + 'title' => __('Registration Reports', 'event_espresso'), |
|
| 101 | + 'filename' => 'registrations_reports', |
|
| 102 | + ), |
|
| 103 | + ), |
|
| 104 | + /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/ |
|
| 105 | + 'require_nonce' => false, |
|
| 106 | + ), |
|
| 107 | + 'event_registrations' => array( |
|
| 108 | + 'nav' => array( |
|
| 109 | + 'label' => __('Event Check-In', 'event_espresso'), |
|
| 110 | + 'order' => 10, |
|
| 111 | + 'persistent' => true, |
|
| 112 | + ), |
|
| 113 | + 'help_tabs' => array( |
|
| 114 | + 'registrations_event_checkin_help_tab' => array( |
|
| 115 | + 'title' => __('Registrations Event Check-In', 'event_espresso'), |
|
| 116 | + 'filename' => 'registrations_event_checkin', |
|
| 117 | + ), |
|
| 118 | + 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
| 119 | + 'title' => __('Event Check-In Table Column Headings', 'event_espresso'), |
|
| 120 | + 'filename' => 'registrations_event_checkin_table_column_headings', |
|
| 121 | + ), |
|
| 122 | + 'registrations_event_checkin_filters_help_tab' => array( |
|
| 123 | + 'title' => __('Event Check-In Filters', 'event_espresso'), |
|
| 124 | + 'filename' => 'registrations_event_checkin_filters', |
|
| 125 | + ), |
|
| 126 | + 'registrations_event_checkin_views_help_tab' => array( |
|
| 127 | + 'title' => __('Event Check-In Views', 'event_espresso'), |
|
| 128 | + 'filename' => 'registrations_event_checkin_views', |
|
| 129 | + ), |
|
| 130 | + 'registrations_event_checkin_other_help_tab' => array( |
|
| 131 | + 'title' => __('Event Check-In Other', 'event_espresso'), |
|
| 132 | + 'filename' => 'registrations_event_checkin_other', |
|
| 133 | + ), |
|
| 134 | + ), |
|
| 135 | + 'help_tour' => array('Event_Checkin_Help_Tour'), |
|
| 136 | + 'qtips' => array('Registration_List_Table_Tips'), |
|
| 137 | + 'list_table' => 'EE_Event_Registrations_List_Table', |
|
| 138 | + 'metaboxes' => array(), |
|
| 139 | + 'require_nonce' => false, |
|
| 140 | + ), |
|
| 141 | + 'registration_checkins' => array( |
|
| 142 | + 'nav' => array( |
|
| 143 | + 'label' => __('Check-In Records', 'event_espresso'), |
|
| 144 | + 'order' => 15, |
|
| 145 | + 'persistent' => false, |
|
| 146 | + ), |
|
| 147 | + 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
| 148 | + //'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ), |
|
| 149 | + 'metaboxes' => array(), |
|
| 150 | + 'require_nonce' => false, |
|
| 151 | + ), |
|
| 152 | + ); |
|
| 153 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 154 | + $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
| 155 | + $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + protected function _ajax_hooks() |
|
| 161 | + { |
|
| 162 | + parent::_ajax_hooks(); |
|
| 163 | + add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + public function load_scripts_styles() |
|
| 169 | + { |
|
| 170 | + parent::load_scripts_styles(); |
|
| 171 | + //if newsletter message type is active then let's add filter and load js for it. |
|
| 172 | + if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
| 173 | + //enqueue newsletter js |
|
| 174 | + wp_enqueue_script( |
|
| 175 | + 'ee-newsletter-trigger', |
|
| 176 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
| 177 | + array('ee-dialog'), |
|
| 178 | + EVENT_ESPRESSO_VERSION, |
|
| 179 | + true |
|
| 180 | + ); |
|
| 181 | + wp_enqueue_style( |
|
| 182 | + 'ee-newsletter-trigger-css', |
|
| 183 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
| 184 | + array(), |
|
| 185 | + EVENT_ESPRESSO_VERSION |
|
| 186 | + ); |
|
| 187 | + //hook in buttons for newsletter message type trigger. |
|
| 188 | + add_action( |
|
| 189 | + 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
| 190 | + array($this, 'add_newsletter_action_buttons'), |
|
| 191 | + 10 |
|
| 192 | + ); |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + public function load_scripts_styles_reports() |
|
| 199 | + { |
|
| 200 | + wp_register_script( |
|
| 201 | + 'ee-reg-reports-js', |
|
| 202 | + REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
| 203 | + array('google-charts'), |
|
| 204 | + EVENT_ESPRESSO_VERSION, |
|
| 205 | + true |
|
| 206 | + ); |
|
| 207 | + wp_enqueue_script('ee-reg-reports-js'); |
|
| 208 | + $this->_registration_reports_js_setup(); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + |
|
| 213 | + protected function _add_screen_options_event_registrations() |
|
| 214 | + { |
|
| 215 | + $this->_per_page_screen_option(); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + |
|
| 220 | + protected function _add_screen_options_registration_checkins() |
|
| 221 | + { |
|
| 222 | + $page_title = $this->_admin_page_title; |
|
| 223 | + $this->_admin_page_title = __('Check-In Records', 'event_espresso'); |
|
| 224 | + $this->_per_page_screen_option(); |
|
| 225 | + $this->_admin_page_title = $page_title; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + protected function _set_list_table_views_event_registrations() |
|
| 231 | + { |
|
| 232 | + $this->_views = array( |
|
| 233 | + 'all' => array( |
|
| 234 | + 'slug' => 'all', |
|
| 235 | + 'label' => __('All', 'event_espresso'), |
|
| 236 | + 'count' => 0, |
|
| 237 | + 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
| 238 | + ? array() |
|
| 239 | + : array( |
|
| 240 | + 'toggle_checkin_status' => __('Toggle Check-In', 'event_espresso'), |
|
| 241 | + //'trash_registrations' => __('Trash Registrations', 'event_espresso') |
|
| 242 | + ), |
|
| 243 | + ), |
|
| 244 | + ); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + protected function _set_list_table_views_registration_checkins() |
|
| 250 | + { |
|
| 251 | + $this->_views = array( |
|
| 252 | + 'all' => array( |
|
| 253 | + 'slug' => 'all', |
|
| 254 | + 'label' => __('All', 'event_espresso'), |
|
| 255 | + 'count' => 0, |
|
| 256 | + 'bulk_action' => array('delete_checkin_rows' => __('Delete Check-In Rows', 'event_espresso')), |
|
| 257 | + ), |
|
| 258 | + ); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * callback for ajax action. |
|
| 265 | + * |
|
| 266 | + * @since 4.3.0 |
|
| 267 | + * @return void (JSON) |
|
| 268 | + * @throws \EE_Error |
|
| 269 | + */ |
|
| 270 | + public function get_newsletter_form_content() |
|
| 271 | + { |
|
| 272 | + //do a nonce check cause we're not coming in from an normal route here. |
|
| 273 | + $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
| 274 | + $this->_req_data['get_newsletter_form_content_nonce'] |
|
| 275 | + ) : ''; |
|
| 276 | + $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
| 277 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 278 | + //let's get the mtp for the incoming MTP_ ID |
|
| 279 | + if ( ! isset($this->_req_data['GRP_ID'])) { |
|
| 280 | + EE_Error::add_error( |
|
| 281 | + __( |
|
| 282 | + 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
| 283 | + 'event_espresso' |
|
| 284 | + ), |
|
| 285 | + __FILE__, |
|
| 286 | + __FUNCTION__, |
|
| 287 | + __LINE__ |
|
| 288 | + ); |
|
| 289 | + $this->_template_args['success'] = false; |
|
| 290 | + $this->_template_args['error'] = true; |
|
| 291 | + $this->_return_json(); |
|
| 292 | + } |
|
| 293 | + $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
| 294 | + if ( ! $MTPG instanceof EE_Message_Template_Group) { |
|
| 295 | + EE_Error::add_error( |
|
| 296 | + sprintf( |
|
| 297 | + __( |
|
| 298 | + 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
| 299 | + 'event_espresso' |
|
| 300 | + ), |
|
| 301 | + $this->_req_data['GRP_ID'] |
|
| 302 | + ), |
|
| 303 | + __FILE__, |
|
| 304 | + __FUNCTION__, |
|
| 305 | + __LINE__ |
|
| 306 | + ); |
|
| 307 | + $this->_template_args['success'] = false; |
|
| 308 | + $this->_template_args['error'] = true; |
|
| 309 | + $this->_return_json(); |
|
| 310 | + } |
|
| 311 | + $MTPs = $MTPG->context_templates(); |
|
| 312 | + $MTPs = $MTPs['attendee']; |
|
| 313 | + $template_fields = array(); |
|
| 314 | + /** @var EE_Message_Template $MTP */ |
|
| 315 | + foreach ($MTPs as $MTP) { |
|
| 316 | + $field = $MTP->get('MTP_template_field'); |
|
| 317 | + if ($field === 'content') { |
|
| 318 | + $content = $MTP->get('MTP_content'); |
|
| 319 | + if ( ! empty($content['newsletter_content'])) { |
|
| 320 | + $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
| 321 | + } |
|
| 322 | + continue; |
|
| 323 | + } |
|
| 324 | + $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content'); |
|
| 325 | + } |
|
| 326 | + $this->_template_args['success'] = true; |
|
| 327 | + $this->_template_args['error'] = false; |
|
| 328 | + $this->_template_args['data'] = array( |
|
| 329 | + 'batch_message_from' => isset($template_fields['from']) |
|
| 330 | + ? $template_fields['from'] |
|
| 331 | + : '', |
|
| 332 | + 'batch_message_subject' => isset($template_fields['subject']) |
|
| 333 | + ? $template_fields['subject'] |
|
| 334 | + : '', |
|
| 335 | + 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
| 336 | + ? $template_fields['newsletter_content'] |
|
| 337 | + : '', |
|
| 338 | + ); |
|
| 339 | + $this->_return_json(); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
| 346 | + * |
|
| 347 | + * @since 4.3.0 |
|
| 348 | + * @param EE_Admin_List_Table $list_table |
|
| 349 | + * @return void |
|
| 350 | + */ |
|
| 351 | + public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
| 352 | + { |
|
| 353 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
| 354 | + 'ee_send_message', |
|
| 355 | + 'espresso_registrations_newsletter_selected_send' |
|
| 356 | + ) |
|
| 357 | + ) { |
|
| 358 | + return; |
|
| 359 | + } |
|
| 360 | + $routes_to_add_to = array( |
|
| 361 | + 'contact_list', |
|
| 362 | + 'event_registrations', |
|
| 363 | + 'default', |
|
| 364 | + ); |
|
| 365 | + if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
| 366 | + if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
| 367 | + || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
| 368 | + ) { |
|
| 369 | + echo ''; |
|
| 370 | + } else { |
|
| 371 | + $button_text = sprintf( |
|
| 372 | + __('Send Batch Message (%s selected)', 'event_espresso'), |
|
| 373 | + '<span class="send-selected-newsletter-count">0</span>' |
|
| 374 | + ); |
|
| 375 | + echo '<button id="selected-batch-send-trigger" class="button secondary-button"><span class="dashicons dashicons-email "></span>' |
|
| 376 | + . $button_text |
|
| 377 | + . '</button>'; |
|
| 378 | + add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + public function newsletter_send_form_skeleton() |
|
| 386 | + { |
|
| 387 | + $list_table = $this->_list_table_object; |
|
| 388 | + $codes = array(); |
|
| 389 | + //need to templates for the newsletter message type for the template selector. |
|
| 390 | + $values[] = array('text' => __('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
| 391 | + $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
| 392 | + array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
| 393 | + ); |
|
| 394 | + foreach ($mtps as $mtp) { |
|
| 395 | + $name = $mtp->name(); |
|
| 396 | + $values[] = array( |
|
| 397 | + 'text' => empty($name) ? __('Global', 'event_espresso') : $name, |
|
| 398 | + 'id' => $mtp->ID(), |
|
| 399 | + ); |
|
| 400 | + } |
|
| 401 | + //need to get a list of shortcodes that are available for the newsletter message type. |
|
| 402 | + $shortcodes = EEH_MSG_Template::get_shortcodes('newsletter', 'email', array(), 'attendee', false); |
|
| 403 | + foreach ($shortcodes as $field => $shortcode_array) { |
|
| 404 | + $codes[$field] = implode(', ', array_keys($shortcode_array)); |
|
| 405 | + } |
|
| 406 | + $shortcodes = $codes; |
|
| 407 | + $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
| 408 | + $form_template_args = array( |
|
| 409 | + 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
| 410 | + 'form_route' => 'newsletter_selected_send', |
|
| 411 | + 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
| 412 | + 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
| 413 | + 'redirect_back_to' => $this->_req_action, |
|
| 414 | + 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
| 415 | + 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
| 416 | + 'shortcodes' => $shortcodes, |
|
| 417 | + 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
| 418 | + ); |
|
| 419 | + EEH_Template::display_template($form_template, $form_template_args); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Handles sending selected registrations/contacts a newsletter. |
|
| 426 | + * |
|
| 427 | + * @since 4.3.0 |
|
| 428 | + * @return void |
|
| 429 | + * @throws \EE_Error |
|
| 430 | + */ |
|
| 431 | + protected function _newsletter_selected_send() |
|
| 432 | + { |
|
| 433 | + $success = true; |
|
| 434 | + //first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
| 435 | + if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
| 436 | + EE_Error::add_error( |
|
| 437 | + __( |
|
| 438 | + 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
| 439 | + 'event_espresso' |
|
| 440 | + ), |
|
| 441 | + __FILE__, |
|
| 442 | + __FUNCTION__, |
|
| 443 | + __LINE__ |
|
| 444 | + ); |
|
| 445 | + $success = false; |
|
| 446 | + } |
|
| 447 | + if ($success) { |
|
| 448 | + //update Message template in case there are any changes |
|
| 449 | + $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 450 | + $this->_req_data['newsletter_mtp_selected'] |
|
| 451 | + ); |
|
| 452 | + $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
| 453 | + ? $Message_Template_Group->context_templates() |
|
| 454 | + : array(); |
|
| 455 | + if (empty($Message_Templates)) { |
|
| 456 | + EE_Error::add_error( |
|
| 457 | + __( |
|
| 458 | + 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
| 459 | + 'event_espresso' |
|
| 460 | + ), |
|
| 461 | + __FILE__, |
|
| 462 | + __FUNCTION__, |
|
| 463 | + __LINE__ |
|
| 464 | + ); |
|
| 465 | + } |
|
| 466 | + //let's just update the specific fields |
|
| 467 | + foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
| 468 | + if ($Message_Template instanceof EE_Message_Template) { |
|
| 469 | + $field = $Message_Template->get('MTP_template_field'); |
|
| 470 | + $content = $Message_Template->get('MTP_content'); |
|
| 471 | + $new_content = $content; |
|
| 472 | + switch ($field) { |
|
| 473 | + case 'from' : |
|
| 474 | + $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
| 475 | + ? $this->_req_data['batch_message']['from'] |
|
| 476 | + : $content; |
|
| 477 | + break; |
|
| 478 | + case 'subject' : |
|
| 479 | + $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
| 480 | + ? $this->_req_data['batch_message']['subject'] |
|
| 481 | + : $content; |
|
| 482 | + break; |
|
| 483 | + case 'content' : |
|
| 484 | + $new_content = $content; |
|
| 485 | + $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
| 486 | + ? $this->_req_data['batch_message']['content'] |
|
| 487 | + : $content['newsletter_content']; |
|
| 488 | + break; |
|
| 489 | + default : |
|
| 490 | + //continue the foreach loop, we don't want to set $new_content nor save. |
|
| 491 | + continue 2; |
|
| 492 | + } |
|
| 493 | + $Message_Template->set('MTP_content', $new_content); |
|
| 494 | + $Message_Template->save(); |
|
| 495 | + } |
|
| 496 | + } |
|
| 497 | + //great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
| 498 | + $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
| 499 | + ? $this->_req_data['batch_message']['id_type'] |
|
| 500 | + : 'registration'; |
|
| 501 | + //id_type will affect how we assemble the ids. |
|
| 502 | + $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
| 503 | + ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
| 504 | + : array(); |
|
| 505 | + $registrations_used_for_contact_data = array(); |
|
| 506 | + //using switch because eventually we'll have other contexts that will be used for generating messages. |
|
| 507 | + switch ($id_type) { |
|
| 508 | + case 'registration' : |
|
| 509 | + $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
| 510 | + array( |
|
| 511 | + array( |
|
| 512 | + 'REG_ID' => array('IN', $ids), |
|
| 513 | + ), |
|
| 514 | + ) |
|
| 515 | + ); |
|
| 516 | + break; |
|
| 517 | + case 'contact' : |
|
| 518 | + $registrations_used_for_contact_data = EEM_Registration::instance() |
|
| 519 | + ->get_latest_registration_for_each_of_given_contacts($ids); |
|
| 520 | + break; |
|
| 521 | + } |
|
| 522 | + do_action( |
|
| 523 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 524 | + $registrations_used_for_contact_data, |
|
| 525 | + $Message_Template_Group->ID() |
|
| 526 | + ); |
|
| 527 | + //kept for backward compat, internally we no longer use this action. |
|
| 528 | + //@deprecated 4.8.36.rc.002 |
|
| 529 | + $contacts = $id_type === 'registration' |
|
| 530 | + ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
| 531 | + : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
| 532 | + do_action( |
|
| 533 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
| 534 | + $contacts, |
|
| 535 | + $Message_Template_Group->ID() |
|
| 536 | + ); |
|
| 537 | + } |
|
| 538 | + $query_args = array( |
|
| 539 | + 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
| 540 | + ? $this->_req_data['redirect_back_to'] |
|
| 541 | + : 'default', |
|
| 542 | + ); |
|
| 543 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
| 550 | + * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
| 551 | + */ |
|
| 552 | + protected function _registration_reports_js_setup() |
|
| 553 | + { |
|
| 554 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
| 555 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * generates Business Reports regarding Registrations |
|
| 562 | + * |
|
| 563 | + * @access protected |
|
| 564 | + * @return void |
|
| 565 | + */ |
|
| 566 | + protected function _registration_reports() |
|
| 567 | + { |
|
| 568 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
| 569 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 570 | + $template_path, |
|
| 571 | + $this->_reports_template_data, |
|
| 572 | + true |
|
| 573 | + ); |
|
| 574 | + // the final template wrapper |
|
| 575 | + $this->display_admin_page_with_no_sidebar(); |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * Generates Business Report showing total registrations per day. |
|
| 582 | + * |
|
| 583 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
| 584 | + * @return string |
|
| 585 | + */ |
|
| 586 | + private function _registrations_per_day_report($period = '-1 month') |
|
| 587 | + { |
|
| 588 | + $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
| 589 | + $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
| 590 | + $results = (array)$results; |
|
| 591 | + $regs = array(); |
|
| 592 | + $subtitle = ''; |
|
| 593 | + if ($results) { |
|
| 594 | + $column_titles = array(); |
|
| 595 | + $tracker = 0; |
|
| 596 | + foreach ($results as $result) { |
|
| 597 | + $report_column_values = array(); |
|
| 598 | + foreach ($result as $property_name => $property_value) { |
|
| 599 | + $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
| 600 | + : (int)$property_value; |
|
| 601 | + $report_column_values[] = $property_value; |
|
| 602 | + if ($tracker === 0) { |
|
| 603 | + if ($property_name === 'Registration_REG_date') { |
|
| 604 | + $column_titles[] = __('Date (only days with registrations are shown)', 'event_espresso'); |
|
| 605 | + } else { |
|
| 606 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
| 607 | + } |
|
| 608 | + } |
|
| 609 | + } |
|
| 610 | + $tracker++; |
|
| 611 | + $regs[] = $report_column_values; |
|
| 612 | + } |
|
| 613 | + //make sure the column_titles is pushed to the beginning of the array |
|
| 614 | + array_unshift($regs, $column_titles); |
|
| 615 | + //setup the date range. |
|
| 616 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
| 617 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 618 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
| 619 | + $subtitle = sprintf( |
|
| 620 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
| 621 | + $beginning_date->format('Y-m-d'), |
|
| 622 | + $ending_date->format('Y-m-d') |
|
| 623 | + ); |
|
| 624 | + } |
|
| 625 | + $report_title = __('Total Registrations per Day', 'event_espresso'); |
|
| 626 | + $report_params = array( |
|
| 627 | + 'title' => $report_title, |
|
| 628 | + 'subtitle' => $subtitle, |
|
| 629 | + 'id' => $report_ID, |
|
| 630 | + 'regs' => $regs, |
|
| 631 | + 'noResults' => empty($regs), |
|
| 632 | + 'noRegsMsg' => sprintf( |
|
| 633 | + __( |
|
| 634 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
| 635 | + 'event_espresso' |
|
| 636 | + ), |
|
| 637 | + '<h2>' . $report_title . '</h2><p>', |
|
| 638 | + '</p>' |
|
| 639 | + ), |
|
| 640 | + ); |
|
| 641 | + wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
| 642 | + return $report_ID; |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + |
|
| 646 | + |
|
| 647 | + /** |
|
| 648 | + * Generates Business Report showing total registrations per event. |
|
| 649 | + * |
|
| 650 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
| 651 | + * @return string |
|
| 652 | + */ |
|
| 653 | + private function _registrations_per_event_report($period = '-1 month') |
|
| 654 | + { |
|
| 655 | + $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
| 656 | + $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
| 657 | + $results = (array)$results; |
|
| 658 | + $regs = array(); |
|
| 659 | + $subtitle = ''; |
|
| 660 | + if ($results) { |
|
| 661 | + $column_titles = array(); |
|
| 662 | + $tracker = 0; |
|
| 663 | + foreach ($results as $result) { |
|
| 664 | + $report_column_values = array(); |
|
| 665 | + foreach ($result as $property_name => $property_value) { |
|
| 666 | + $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
| 667 | + $property_value, |
|
| 668 | + 4, |
|
| 669 | + '...' |
|
| 670 | + ) : (int)$property_value; |
|
| 671 | + $report_column_values[] = $property_value; |
|
| 672 | + if ($tracker === 0) { |
|
| 673 | + if ($property_name === 'Registration_Event') { |
|
| 674 | + $column_titles[] = __('Event', 'event_espresso'); |
|
| 675 | + } else { |
|
| 676 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
| 677 | + } |
|
| 678 | + } |
|
| 679 | + } |
|
| 680 | + $tracker++; |
|
| 681 | + $regs[] = $report_column_values; |
|
| 682 | + } |
|
| 683 | + //make sure the column_titles is pushed to the beginning of the array |
|
| 684 | + array_unshift($regs, $column_titles); |
|
| 685 | + //setup the date range. |
|
| 686 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
| 687 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 688 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
| 689 | + $subtitle = sprintf( |
|
| 690 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
| 691 | + $beginning_date->format('Y-m-d'), |
|
| 692 | + $ending_date->format('Y-m-d') |
|
| 693 | + ); |
|
| 694 | + } |
|
| 695 | + $report_title = __('Total Registrations per Event', 'event_espresso'); |
|
| 696 | + $report_params = array( |
|
| 697 | + 'title' => $report_title, |
|
| 698 | + 'subtitle' => $subtitle, |
|
| 699 | + 'id' => $report_ID, |
|
| 700 | + 'regs' => $regs, |
|
| 701 | + 'noResults' => empty($regs), |
|
| 702 | + 'noRegsMsg' => sprintf( |
|
| 703 | + __( |
|
| 704 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
| 705 | + 'event_espresso' |
|
| 706 | + ), |
|
| 707 | + '<h2>' . $report_title . '</h2><p>', |
|
| 708 | + '</p>' |
|
| 709 | + ), |
|
| 710 | + ); |
|
| 711 | + wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
| 712 | + return $report_ID; |
|
| 713 | + } |
|
| 714 | + |
|
| 715 | + |
|
| 716 | + |
|
| 717 | + /** |
|
| 718 | + * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
| 719 | + * |
|
| 720 | + * @access protected |
|
| 721 | + * @return void |
|
| 722 | + * @throws \EE_Error |
|
| 723 | + */ |
|
| 724 | + protected function _registration_checkin_list_table() |
|
| 725 | + { |
|
| 726 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 727 | + $reg_id = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : null; |
|
| 728 | + /** @var EE_Registration $reg */ |
|
| 729 | + $reg = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
| 730 | + $this->_admin_page_title .= $this->get_action_link_or_button( |
|
| 731 | + 'new_registration', |
|
| 732 | + 'add-registrant', |
|
| 733 | + array('event_id' => $reg->event_ID()), |
|
| 734 | + 'add-new-h2' |
|
| 735 | + ); |
|
| 736 | + $legend_items = array( |
|
| 737 | + 'checkin' => array( |
|
| 738 | + 'class' => 'ee-icon ee-icon-check-in', |
|
| 739 | + 'desc' => __('This indicates the attendee has been checked in', 'event_espresso'), |
|
| 740 | + ), |
|
| 741 | + 'checkout' => array( |
|
| 742 | + 'class' => 'ee-icon ee-icon-check-out', |
|
| 743 | + 'desc' => __('This indicates the attendee has been checked out', 'event_espresso'), |
|
| 744 | + ), |
|
| 745 | + ); |
|
| 746 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
| 747 | + $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 748 | + $go_back_url = ! empty($reg_id) ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 749 | + array( |
|
| 750 | + 'action' => 'event_registrations', |
|
| 751 | + 'event_id' => EEM_Registration::instance()->get_one_by_ID($reg_id)->get_first_related('Event')->ID(), |
|
| 752 | + 'DTT_ID' => $dtt_id, |
|
| 753 | + ), |
|
| 754 | + $this->_admin_base_url |
|
| 755 | + ) : ''; |
|
| 756 | + $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
| 757 | + ? '<h2>' . sprintf( |
|
| 758 | + __("%s's check in records for %s at the event, %s", 'event_espresso'), |
|
| 759 | + '<span id="checkin-attendee-name">' |
|
| 760 | + . EEM_Registration::instance() |
|
| 761 | + ->get_one_by_ID($reg_id) |
|
| 762 | + ->get_first_related('Attendee') |
|
| 763 | + ->full_name() . '</span>', |
|
| 764 | + '<span id="checkin-dtt"><a href="' . $go_back_url . '">' |
|
| 765 | + . EEM_Datetime::instance() |
|
| 766 | + ->get_one_by_ID($dtt_id) |
|
| 767 | + ->start_date_and_time() . ' - ' |
|
| 768 | + . EEM_Datetime::instance() |
|
| 769 | + ->get_one_by_ID($dtt_id) |
|
| 770 | + ->end_date_and_time() . '</a></span>', |
|
| 771 | + '<span id="checkin-event-name">' |
|
| 772 | + . EEM_Datetime::instance() |
|
| 773 | + ->get_one_by_ID($dtt_id) |
|
| 774 | + ->get_first_related('Event') |
|
| 775 | + ->get('EVT_name') . '</span>' |
|
| 776 | + ) . '</h2>' |
|
| 777 | + : ''; |
|
| 778 | + $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
| 779 | + ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : ''; |
|
| 780 | + $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
| 781 | + ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
| 782 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + |
|
| 786 | + |
|
| 787 | + /** |
|
| 788 | + * toggle the Check-in status for the given registration (coming from ajax) |
|
| 789 | + * |
|
| 790 | + * @return void (JSON) |
|
| 791 | + */ |
|
| 792 | + public function toggle_checkin_status() |
|
| 793 | + { |
|
| 794 | + //first make sure we have the necessary data |
|
| 795 | + if ( ! isset($this->_req_data['_regid'])) { |
|
| 796 | + EE_Error::add_error( |
|
| 797 | + __( |
|
| 798 | + 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
| 799 | + 'event_espresso' |
|
| 800 | + ), |
|
| 801 | + __FILE__, |
|
| 802 | + __FUNCTION__, |
|
| 803 | + __LINE__ |
|
| 804 | + ); |
|
| 805 | + $this->_template_args['success'] = false; |
|
| 806 | + $this->_template_args['error'] = true; |
|
| 807 | + $this->_return_json(); |
|
| 808 | + }; |
|
| 809 | + //do a nonce check cause we're not coming in from an normal route here. |
|
| 810 | + $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
| 811 | + : ''; |
|
| 812 | + $nonce_ref = 'checkin_nonce'; |
|
| 813 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 814 | + //beautiful! Made it this far so let's get the status. |
|
| 815 | + $new_status = $this->_toggle_checkin_status(); |
|
| 816 | + //setup new class to return via ajax |
|
| 817 | + $this->_template_args['admin_page_content'] = 'clickable trigger-checkin checkin-icons checkedin-status-' |
|
| 818 | + . $new_status; |
|
| 819 | + $this->_template_args['success'] = true; |
|
| 820 | + $this->_return_json(); |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + |
|
| 824 | + |
|
| 825 | + /** |
|
| 826 | + * handles toggling the checkin status for the registration, |
|
| 827 | + * |
|
| 828 | + * @access protected |
|
| 829 | + * @return int|void |
|
| 830 | + */ |
|
| 831 | + protected function _toggle_checkin_status() |
|
| 832 | + { |
|
| 833 | + //first let's get the query args out of the way for the redirect |
|
| 834 | + $query_args = array( |
|
| 835 | + 'action' => 'event_registrations', |
|
| 836 | + 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
| 837 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
| 838 | + ); |
|
| 839 | + $new_status = false; |
|
| 840 | + // bulk action check in toggle |
|
| 841 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 842 | + // cycle thru checkboxes |
|
| 843 | + while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 844 | + $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 845 | + $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
| 846 | + } |
|
| 847 | + } elseif (isset($this->_req_data['_regid'])) { |
|
| 848 | + //coming from ajax request |
|
| 849 | + $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
| 850 | + $query_args['DTT_ID'] = $DTT_ID; |
|
| 851 | + $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
| 852 | + } else { |
|
| 853 | + EE_Error::add_error( |
|
| 854 | + __('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
| 855 | + __FILE__, |
|
| 856 | + __FUNCTION__, |
|
| 857 | + __LINE__ |
|
| 858 | + ); |
|
| 859 | + } |
|
| 860 | + if (defined('DOING_AJAX')) { |
|
| 861 | + return $new_status; |
|
| 862 | + } |
|
| 863 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + |
|
| 867 | + |
|
| 868 | + /** |
|
| 869 | + * This is toggles a single Check-in for the given registration and datetime. |
|
| 870 | + * |
|
| 871 | + * @param int $REG_ID The registration we're toggling |
|
| 872 | + * @param int $DTT_ID The datetime we're toggling |
|
| 873 | + * @return int The new status toggled to. |
|
| 874 | + * @throws \EE_Error |
|
| 875 | + */ |
|
| 876 | + private function _toggle_checkin($REG_ID, $DTT_ID) |
|
| 877 | + { |
|
| 878 | + /** @var EE_Registration $REG */ |
|
| 879 | + $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 880 | + $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
| 881 | + if ($new_status !== false) { |
|
| 882 | + EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
| 883 | + } else { |
|
| 884 | + EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
| 885 | + $new_status = false; |
|
| 886 | + } |
|
| 887 | + return $new_status; |
|
| 888 | + } |
|
| 889 | + |
|
| 890 | + |
|
| 891 | + |
|
| 892 | + /** |
|
| 893 | + * Takes care of deleting multiple EE_Checkin table rows |
|
| 894 | + * |
|
| 895 | + * @access protected |
|
| 896 | + * @return void |
|
| 897 | + * @throws \EE_Error |
|
| 898 | + */ |
|
| 899 | + protected function _delete_checkin_rows() |
|
| 900 | + { |
|
| 901 | + $query_args = array( |
|
| 902 | + 'action' => 'registration_checkins', |
|
| 903 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
| 904 | + '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0, |
|
| 905 | + ); |
|
| 906 | + $errors = 0; |
|
| 907 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 908 | + while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 909 | + if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
| 910 | + $errors++; |
|
| 911 | + } |
|
| 912 | + } |
|
| 913 | + } else { |
|
| 914 | + EE_Error::add_error( |
|
| 915 | + __( |
|
| 916 | + 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
| 917 | + 'event_espresso' |
|
| 918 | + ), |
|
| 919 | + __FILE__, |
|
| 920 | + __FUNCTION__, |
|
| 921 | + __LINE__ |
|
| 922 | + ); |
|
| 923 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 924 | + } |
|
| 925 | + if ($errors > 0) { |
|
| 926 | + EE_Error::add_error( |
|
| 927 | + sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
| 928 | + __FILE__, |
|
| 929 | + __FUNCTION__, |
|
| 930 | + __LINE__ |
|
| 931 | + ); |
|
| 932 | + } else { |
|
| 933 | + EE_Error::add_success(__('Records were successfully deleted', 'event_espresso')); |
|
| 934 | + } |
|
| 935 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + |
|
| 939 | + |
|
| 940 | + /** |
|
| 941 | + * Deletes a single EE_Checkin row |
|
| 942 | + * |
|
| 943 | + * @return void |
|
| 944 | + * @throws \EE_Error |
|
| 945 | + */ |
|
| 946 | + protected function _delete_checkin_row() |
|
| 947 | + { |
|
| 948 | + $query_args = array( |
|
| 949 | + 'action' => 'registration_checkins', |
|
| 950 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
| 951 | + '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0, |
|
| 952 | + ); |
|
| 953 | + if ( ! empty($this->_req_data['CHK_ID'])) { |
|
| 954 | + if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
| 955 | + EE_Error::add_error( |
|
| 956 | + __('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
| 957 | + __FILE__, |
|
| 958 | + __FUNCTION__, |
|
| 959 | + __LINE__ |
|
| 960 | + ); |
|
| 961 | + } else { |
|
| 962 | + EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso')); |
|
| 963 | + } |
|
| 964 | + } else { |
|
| 965 | + EE_Error::add_error( |
|
| 966 | + __( |
|
| 967 | + 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
| 968 | + 'event_espresso' |
|
| 969 | + ), |
|
| 970 | + __FILE__, |
|
| 971 | + __FUNCTION__, |
|
| 972 | + __LINE__ |
|
| 973 | + ); |
|
| 974 | + } |
|
| 975 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + |
|
| 979 | + |
|
| 980 | + /** |
|
| 981 | + * generates HTML for the Event Registrations List Table |
|
| 982 | + * |
|
| 983 | + * @access protected |
|
| 984 | + * @return void |
|
| 985 | + * @throws \EE_Error |
|
| 986 | + */ |
|
| 987 | + protected function _event_registrations_list_table() |
|
| 988 | + { |
|
| 989 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 990 | + $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
| 991 | + ? $this->get_action_link_or_button( |
|
| 992 | + 'new_registration', |
|
| 993 | + 'add-registrant', |
|
| 994 | + array('event_id' => $this->_req_data['event_id']), |
|
| 995 | + 'add-new-h2', |
|
| 996 | + '', |
|
| 997 | + false |
|
| 998 | + ) |
|
| 999 | + : ''; |
|
| 1000 | + $legend_items = array( |
|
| 1001 | + 'star-icon' => array( |
|
| 1002 | + 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
| 1003 | + 'desc' => __('This Registrant is the Primary Registrant', 'event_espresso'), |
|
| 1004 | + ), |
|
| 1005 | + 'checkin' => array( |
|
| 1006 | + 'class' => 'ee-icon ee-icon-check-in', |
|
| 1007 | + 'desc' => __('This Registrant has been Checked In', 'event_espresso'), |
|
| 1008 | + ), |
|
| 1009 | + 'checkout' => array( |
|
| 1010 | + 'class' => 'ee-icon ee-icon-check-out', |
|
| 1011 | + 'desc' => __('This Registrant has been Checked Out', 'event_espresso'), |
|
| 1012 | + ), |
|
| 1013 | + 'nocheckinrecord' => array( |
|
| 1014 | + 'class' => 'dashicons dashicons-no', |
|
| 1015 | + 'desc' => __('No Check-in Record has been Created for this Registrant', 'event_espresso'), |
|
| 1016 | + ), |
|
| 1017 | + 'view_details' => array( |
|
| 1018 | + 'class' => 'dashicons dashicons-search', |
|
| 1019 | + 'desc' => __('View All Check-in Records for this Registrant', 'event_espresso'), |
|
| 1020 | + ), |
|
| 1021 | + 'approved_status' => array( |
|
| 1022 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 1023 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
| 1024 | + ), |
|
| 1025 | + 'cancelled_status' => array( |
|
| 1026 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 1027 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
| 1028 | + ), |
|
| 1029 | + 'declined_status' => array( |
|
| 1030 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 1031 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
| 1032 | + ), |
|
| 1033 | + 'not_approved' => array( |
|
| 1034 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 1035 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
| 1036 | + ), |
|
| 1037 | + 'pending_status' => array( |
|
| 1038 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 1039 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
| 1040 | + ), |
|
| 1041 | + 'wait_list' => array( |
|
| 1042 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 1043 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
| 1044 | + ), |
|
| 1045 | + ); |
|
| 1046 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
| 1047 | + $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
| 1048 | + $this->_template_args['before_list_table'] = ! empty($event_id) |
|
| 1049 | + ? '<h2>' . sprintf( |
|
| 1050 | + __('Viewing Registrations for Event: %s', 'event_espresso'), |
|
| 1051 | + EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
| 1052 | + ) . '</h2>' |
|
| 1053 | + : ''; |
|
| 1054 | + //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event. |
|
| 1055 | + /** @var EE_Event $event */ |
|
| 1056 | + $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
| 1057 | + $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
| 1058 | + $datetime = null; |
|
| 1059 | + if ($event instanceof EE_Event) { |
|
| 1060 | + $datetimes_on_event = $event->datetimes(); |
|
| 1061 | + if (count($datetimes_on_event) === 1) { |
|
| 1062 | + $datetime = reset($datetimes_on_event); |
|
| 1063 | + } |
|
| 1064 | + } |
|
| 1065 | + $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
| 1066 | + if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
| 1067 | + $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
| 1068 | + $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
| 1069 | + $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
| 1070 | + $this->_template_args['before_list_table'] .= $datetime->name(); |
|
| 1071 | + $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
| 1072 | + $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
| 1073 | + } |
|
| 1074 | + //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column |
|
| 1075 | + //represents |
|
| 1076 | + if ( ! $datetime instanceof EE_Datetime) { |
|
| 1077 | + $this->_template_args['before_list_table'] .= '<br><p class="description">' |
|
| 1078 | + . __('In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
| 1079 | + 'event_espresso') |
|
| 1080 | + . '</p>'; |
|
| 1081 | + } |
|
| 1082 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + |
|
| 1086 | + |
|
| 1087 | + /** |
|
| 1088 | + * get_attendees |
|
| 1089 | + * |
|
| 1090 | + * @param int $per_page |
|
| 1091 | + * @param bool $count whether to return count or data. |
|
| 1092 | + * @param bool $trash |
|
| 1093 | + * @param string $orderby |
|
| 1094 | + * @return array |
|
| 1095 | + * @throws \EE_Error |
|
| 1096 | + * @access public |
|
| 1097 | + */ |
|
| 1098 | + public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = '') |
|
| 1099 | + { |
|
| 1100 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1101 | + require_once(EE_MODELS . 'EEM_Attendee.model.php'); |
|
| 1102 | + //$ATT_MDL = EEM_Attendee::instance(); |
|
| 1103 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
| 1104 | + $CAT_ID = isset($this->_req_data['category_id']) ? absint($this->_req_data['category_id']) : false; |
|
| 1105 | + $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 1106 | + $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
| 1107 | + switch ($this->_req_data['orderby']) { |
|
| 1108 | + case '_REG_date': |
|
| 1109 | + $orderby = 'REG_date'; |
|
| 1110 | + break; |
|
| 1111 | + default : |
|
| 1112 | + $orderby = 'Attendee.ATT_lname'; |
|
| 1113 | 1113 | // $orderby = 'reg.REG_final_price'; |
| 1114 | - } |
|
| 1115 | - $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
| 1116 | - ? $this->_req_data['order'] : 'ASC'; |
|
| 1117 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1118 | - ? $this->_req_data['paged'] : 1; |
|
| 1119 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1120 | - ? $this->_req_data['perpage'] : $per_page; |
|
| 1121 | - $offset = ($current_page - 1) * $per_page; |
|
| 1122 | - $limit = $count ? null : array($offset, $per_page); |
|
| 1123 | - $query_params = array( |
|
| 1124 | - array( |
|
| 1125 | - 'Event.status' => array( |
|
| 1126 | - 'IN', |
|
| 1127 | - array_keys(EEM_Event::instance()->get_status_array()), |
|
| 1128 | - ), |
|
| 1129 | - ), |
|
| 1130 | - ); |
|
| 1131 | - if ($EVT_ID) { |
|
| 1132 | - $query_params[0]['EVT_ID'] = $EVT_ID; |
|
| 1133 | - } |
|
| 1134 | - if ($CAT_ID) { |
|
| 1135 | - throw new EE_Error( |
|
| 1136 | - "You specified a Category Id for this query. Thats odd because we are now using terms and taxonomies. So did you mean the term taxonomy id o rthe term id?" |
|
| 1137 | - ); |
|
| 1138 | - } |
|
| 1139 | - //if DTT is included we do multiple datetimes. |
|
| 1140 | - if ($DTT_ID) { |
|
| 1141 | - $query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID; |
|
| 1142 | - } |
|
| 1143 | - //make sure we only have default where on the current regs |
|
| 1144 | - $query_params['default_where_conditions'] = 'this_model_only'; |
|
| 1145 | - $status_ids_array = apply_filters( |
|
| 1146 | - 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
| 1147 | - array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
| 1148 | - ); |
|
| 1149 | - $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
| 1150 | - if ($trash) { |
|
| 1151 | - $query_params[0]['Attendee.status'] = EEM_CPT_Base::post_status_trashed; |
|
| 1152 | - } |
|
| 1153 | - if (isset($this->_req_data['s'])) { |
|
| 1154 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 1155 | - $query_params[0]['OR'] = array( |
|
| 1156 | - 'Event.EVT_name' => array('LIKE', $sstr), |
|
| 1157 | - 'Event.EVT_desc' => array('LIKE', $sstr), |
|
| 1158 | - 'Event.EVT_short_desc' => array('LIKE', $sstr), |
|
| 1159 | - 'Attendee.ATT_fname' => array('LIKE', $sstr), |
|
| 1160 | - 'Attendee.ATT_lname' => array('LIKE', $sstr), |
|
| 1161 | - 'Attendee.ATT_short_bio' => array('LIKE', $sstr), |
|
| 1162 | - 'Attendee.ATT_email' => array('LIKE', $sstr), |
|
| 1163 | - 'Attendee.ATT_address' => array('LIKE', $sstr), |
|
| 1164 | - 'Attendee.ATT_address2' => array('LIKE', $sstr), |
|
| 1165 | - 'Attendee.ATT_city' => array('LIKE', $sstr), |
|
| 1166 | - 'REG_final_price' => array('LIKE', $sstr), |
|
| 1167 | - 'REG_code' => array('LIKE', $sstr), |
|
| 1168 | - 'REG_count' => array('LIKE', $sstr), |
|
| 1169 | - 'REG_group_size' => array('LIKE', $sstr), |
|
| 1170 | - 'Ticket.TKT_name' => array('LIKE', $sstr), |
|
| 1171 | - 'Ticket.TKT_description' => array('LIKE', $sstr), |
|
| 1172 | - ); |
|
| 1173 | - } |
|
| 1174 | - $query_params['order_by'][$orderby] = $sort; |
|
| 1175 | - $query_params['limit'] = $limit; |
|
| 1176 | - $query_params['force_join'] = array('Attendee');//force join to attendee model so that it gets cached, because we're going to need the attendee for each registration |
|
| 1177 | - if ($count) { |
|
| 1178 | - $registrations = EEM_Registration::instance()->count( |
|
| 1179 | - array($query_params[0], 'default_where_conditions' => 'this_model_only') |
|
| 1180 | - ); |
|
| 1181 | - } else { |
|
| 1182 | - $registrations = EEM_Registration::instance()->get_all($query_params); |
|
| 1183 | - // $registrations = EEM_Registration::instance(); |
|
| 1184 | - // $all_attendees = EEM_Attendee::instance()->get_event_attendees( $EVT_ID, $CAT_ID, $reg_status, $trash, $orderby, $sort, $limit, $output ); |
|
| 1185 | - if (isset($registrations[0]) && $registrations[0] instanceof EE_Registration) { |
|
| 1186 | - //EEH_Debug_Tools::printr( $all_attendees[0], '$all_attendees[0] <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 1187 | - // name |
|
| 1188 | - /** @var EE_Registration $first_registration */ |
|
| 1189 | - $first_registration = $registrations[0]; |
|
| 1190 | - $event_obj = $first_registration->event_obj(); |
|
| 1191 | - if ($event_obj) { |
|
| 1192 | - $event_name = $first_registration->event_obj()->name(); |
|
| 1193 | - $event_date = 'TODO: we need to get date from earliest price date or should this be the actual event date?';//$first_registration->date_obj()->reg_start_date_and_time('l F j, Y,', ' g:i:s a');// isset( $registrations[0]->DTT_EVT_start ) ? date( 'l F j, Y, g:i:s a', $registrations[0]->DTT_EVT_start ) : ''; |
|
| 1194 | - // edit event link |
|
| 1195 | - if ($event_name !== '') { |
|
| 1196 | - $edit_event_url = self::add_query_args_and_nonce( |
|
| 1197 | - array('action' => 'edit_event', 'EVT_ID' => $EVT_ID), |
|
| 1198 | - EVENTS_ADMIN_URL |
|
| 1199 | - ); |
|
| 1200 | - $edit_event_lnk = '<a href="' . $edit_event_url . '" title="' . esc_attr__( |
|
| 1201 | - 'Edit ', |
|
| 1202 | - 'event_espresso' |
|
| 1203 | - ) . $event_name . '">' . __('Edit Event', 'event_espresso') . '</a>'; |
|
| 1204 | - $event_name .= ' <span class="admin-page-header-edit-lnk not-bold">' |
|
| 1205 | - . $edit_event_lnk |
|
| 1206 | - . '</span>'; |
|
| 1207 | - } |
|
| 1208 | - $back_2_reg_url = self::add_query_args_and_nonce(array('action' => 'default'), REG_ADMIN_URL); |
|
| 1209 | - $back_2_reg_lnk = '<a href="' . $back_2_reg_url . '" title="' . esc_attr__( |
|
| 1210 | - 'click to return to viewing all registrations ', |
|
| 1211 | - 'event_espresso' |
|
| 1212 | - ) . '">« ' . __('Back to All Registrations', 'event_espresso') . '</a>'; |
|
| 1213 | - $this->_template_args['before_admin_page_content'] = ' |
|
| 1114 | + } |
|
| 1115 | + $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
| 1116 | + ? $this->_req_data['order'] : 'ASC'; |
|
| 1117 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1118 | + ? $this->_req_data['paged'] : 1; |
|
| 1119 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1120 | + ? $this->_req_data['perpage'] : $per_page; |
|
| 1121 | + $offset = ($current_page - 1) * $per_page; |
|
| 1122 | + $limit = $count ? null : array($offset, $per_page); |
|
| 1123 | + $query_params = array( |
|
| 1124 | + array( |
|
| 1125 | + 'Event.status' => array( |
|
| 1126 | + 'IN', |
|
| 1127 | + array_keys(EEM_Event::instance()->get_status_array()), |
|
| 1128 | + ), |
|
| 1129 | + ), |
|
| 1130 | + ); |
|
| 1131 | + if ($EVT_ID) { |
|
| 1132 | + $query_params[0]['EVT_ID'] = $EVT_ID; |
|
| 1133 | + } |
|
| 1134 | + if ($CAT_ID) { |
|
| 1135 | + throw new EE_Error( |
|
| 1136 | + "You specified a Category Id for this query. Thats odd because we are now using terms and taxonomies. So did you mean the term taxonomy id o rthe term id?" |
|
| 1137 | + ); |
|
| 1138 | + } |
|
| 1139 | + //if DTT is included we do multiple datetimes. |
|
| 1140 | + if ($DTT_ID) { |
|
| 1141 | + $query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID; |
|
| 1142 | + } |
|
| 1143 | + //make sure we only have default where on the current regs |
|
| 1144 | + $query_params['default_where_conditions'] = 'this_model_only'; |
|
| 1145 | + $status_ids_array = apply_filters( |
|
| 1146 | + 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
| 1147 | + array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
| 1148 | + ); |
|
| 1149 | + $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
| 1150 | + if ($trash) { |
|
| 1151 | + $query_params[0]['Attendee.status'] = EEM_CPT_Base::post_status_trashed; |
|
| 1152 | + } |
|
| 1153 | + if (isset($this->_req_data['s'])) { |
|
| 1154 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 1155 | + $query_params[0]['OR'] = array( |
|
| 1156 | + 'Event.EVT_name' => array('LIKE', $sstr), |
|
| 1157 | + 'Event.EVT_desc' => array('LIKE', $sstr), |
|
| 1158 | + 'Event.EVT_short_desc' => array('LIKE', $sstr), |
|
| 1159 | + 'Attendee.ATT_fname' => array('LIKE', $sstr), |
|
| 1160 | + 'Attendee.ATT_lname' => array('LIKE', $sstr), |
|
| 1161 | + 'Attendee.ATT_short_bio' => array('LIKE', $sstr), |
|
| 1162 | + 'Attendee.ATT_email' => array('LIKE', $sstr), |
|
| 1163 | + 'Attendee.ATT_address' => array('LIKE', $sstr), |
|
| 1164 | + 'Attendee.ATT_address2' => array('LIKE', $sstr), |
|
| 1165 | + 'Attendee.ATT_city' => array('LIKE', $sstr), |
|
| 1166 | + 'REG_final_price' => array('LIKE', $sstr), |
|
| 1167 | + 'REG_code' => array('LIKE', $sstr), |
|
| 1168 | + 'REG_count' => array('LIKE', $sstr), |
|
| 1169 | + 'REG_group_size' => array('LIKE', $sstr), |
|
| 1170 | + 'Ticket.TKT_name' => array('LIKE', $sstr), |
|
| 1171 | + 'Ticket.TKT_description' => array('LIKE', $sstr), |
|
| 1172 | + ); |
|
| 1173 | + } |
|
| 1174 | + $query_params['order_by'][$orderby] = $sort; |
|
| 1175 | + $query_params['limit'] = $limit; |
|
| 1176 | + $query_params['force_join'] = array('Attendee');//force join to attendee model so that it gets cached, because we're going to need the attendee for each registration |
|
| 1177 | + if ($count) { |
|
| 1178 | + $registrations = EEM_Registration::instance()->count( |
|
| 1179 | + array($query_params[0], 'default_where_conditions' => 'this_model_only') |
|
| 1180 | + ); |
|
| 1181 | + } else { |
|
| 1182 | + $registrations = EEM_Registration::instance()->get_all($query_params); |
|
| 1183 | + // $registrations = EEM_Registration::instance(); |
|
| 1184 | + // $all_attendees = EEM_Attendee::instance()->get_event_attendees( $EVT_ID, $CAT_ID, $reg_status, $trash, $orderby, $sort, $limit, $output ); |
|
| 1185 | + if (isset($registrations[0]) && $registrations[0] instanceof EE_Registration) { |
|
| 1186 | + //EEH_Debug_Tools::printr( $all_attendees[0], '$all_attendees[0] <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 1187 | + // name |
|
| 1188 | + /** @var EE_Registration $first_registration */ |
|
| 1189 | + $first_registration = $registrations[0]; |
|
| 1190 | + $event_obj = $first_registration->event_obj(); |
|
| 1191 | + if ($event_obj) { |
|
| 1192 | + $event_name = $first_registration->event_obj()->name(); |
|
| 1193 | + $event_date = 'TODO: we need to get date from earliest price date or should this be the actual event date?';//$first_registration->date_obj()->reg_start_date_and_time('l F j, Y,', ' g:i:s a');// isset( $registrations[0]->DTT_EVT_start ) ? date( 'l F j, Y, g:i:s a', $registrations[0]->DTT_EVT_start ) : ''; |
|
| 1194 | + // edit event link |
|
| 1195 | + if ($event_name !== '') { |
|
| 1196 | + $edit_event_url = self::add_query_args_and_nonce( |
|
| 1197 | + array('action' => 'edit_event', 'EVT_ID' => $EVT_ID), |
|
| 1198 | + EVENTS_ADMIN_URL |
|
| 1199 | + ); |
|
| 1200 | + $edit_event_lnk = '<a href="' . $edit_event_url . '" title="' . esc_attr__( |
|
| 1201 | + 'Edit ', |
|
| 1202 | + 'event_espresso' |
|
| 1203 | + ) . $event_name . '">' . __('Edit Event', 'event_espresso') . '</a>'; |
|
| 1204 | + $event_name .= ' <span class="admin-page-header-edit-lnk not-bold">' |
|
| 1205 | + . $edit_event_lnk |
|
| 1206 | + . '</span>'; |
|
| 1207 | + } |
|
| 1208 | + $back_2_reg_url = self::add_query_args_and_nonce(array('action' => 'default'), REG_ADMIN_URL); |
|
| 1209 | + $back_2_reg_lnk = '<a href="' . $back_2_reg_url . '" title="' . esc_attr__( |
|
| 1210 | + 'click to return to viewing all registrations ', |
|
| 1211 | + 'event_espresso' |
|
| 1212 | + ) . '">« ' . __('Back to All Registrations', 'event_espresso') . '</a>'; |
|
| 1213 | + $this->_template_args['before_admin_page_content'] = ' |
|
| 1214 | 1214 | <div id="admin-page-header"> |
| 1215 | 1215 | <h1><span class="small-text not-bold">' |
| 1216 | - . __('Event: ', 'event_espresso') |
|
| 1217 | - . '</span>' |
|
| 1218 | - . $event_name |
|
| 1219 | - . '</h1> |
|
| 1216 | + . __('Event: ', 'event_espresso') |
|
| 1217 | + . '</span>' |
|
| 1218 | + . $event_name |
|
| 1219 | + . '</h1> |
|
| 1220 | 1220 | <h3><span class="small-text not-bold">' |
| 1221 | - . __('Date: ', 'event_espresso') |
|
| 1222 | - . '</span>' |
|
| 1223 | - . $event_date |
|
| 1224 | - . '</h3> |
|
| 1221 | + . __('Date: ', 'event_espresso') |
|
| 1222 | + . '</span>' |
|
| 1223 | + . $event_date |
|
| 1224 | + . '</h3> |
|
| 1225 | 1225 | <span class="admin-page-header-go-back-lnk not-bold">' |
| 1226 | - . $back_2_reg_lnk |
|
| 1227 | - . '</span> |
|
| 1226 | + . $back_2_reg_lnk |
|
| 1227 | + . '</span> |
|
| 1228 | 1228 | </div> |
| 1229 | 1229 | '; |
| 1230 | - } |
|
| 1231 | - } |
|
| 1232 | - } |
|
| 1233 | - return $registrations; |
|
| 1234 | - } |
|
| 1230 | + } |
|
| 1231 | + } |
|
| 1232 | + } |
|
| 1233 | + return $registrations; |
|
| 1234 | + } |
|
| 1235 | 1235 | |
| 1236 | 1236 | } //end class Registrations Admin Page |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | { |
| 36 | 36 | parent::__construct($routing); |
| 37 | 37 | if ( ! defined('REG_CAF_TEMPLATE_PATH')) { |
| 38 | - define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
| 39 | - define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
| 40 | - define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
| 38 | + define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'registrations/templates/'); |
|
| 39 | + define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'registrations/assets/'); |
|
| 40 | + define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registrations/assets/'); |
|
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | protected function _extend_page_config() |
| 47 | 47 | { |
| 48 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
| 48 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'registrations'; |
|
| 49 | 49 | $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
| 50 | 50 | ? $this->_req_data['_REG_ID'] |
| 51 | 51 | : 0; |
@@ -173,14 +173,14 @@ discard block |
||
| 173 | 173 | //enqueue newsletter js |
| 174 | 174 | wp_enqueue_script( |
| 175 | 175 | 'ee-newsletter-trigger', |
| 176 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
| 176 | + REG_CAF_ASSETS_URL.'ee-newsletter-trigger.js', |
|
| 177 | 177 | array('ee-dialog'), |
| 178 | 178 | EVENT_ESPRESSO_VERSION, |
| 179 | 179 | true |
| 180 | 180 | ); |
| 181 | 181 | wp_enqueue_style( |
| 182 | 182 | 'ee-newsletter-trigger-css', |
| 183 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
| 183 | + REG_CAF_ASSETS_URL.'ee-newsletter-trigger.css', |
|
| 184 | 184 | array(), |
| 185 | 185 | EVENT_ESPRESSO_VERSION |
| 186 | 186 | ); |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | { |
| 200 | 200 | wp_register_script( |
| 201 | 201 | 'ee-reg-reports-js', |
| 202 | - REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
| 202 | + REG_CAF_ASSETS_URL.'ee-registration-admin-reports.js', |
|
| 203 | 203 | array('google-charts'), |
| 204 | 204 | EVENT_ESPRESSO_VERSION, |
| 205 | 205 | true |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | $codes[$field] = implode(', ', array_keys($shortcode_array)); |
| 405 | 405 | } |
| 406 | 406 | $shortcodes = $codes; |
| 407 | - $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
| 407 | + $form_template = REG_CAF_TEMPLATE_PATH.'newsletter-send-form.template.php'; |
|
| 408 | 408 | $form_template_args = array( |
| 409 | 409 | 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
| 410 | 410 | 'form_route' => 'newsletter_selected_send', |
@@ -565,7 +565,7 @@ discard block |
||
| 565 | 565 | */ |
| 566 | 566 | protected function _registration_reports() |
| 567 | 567 | { |
| 568 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
| 568 | + $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php'; |
|
| 569 | 569 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 570 | 570 | $template_path, |
| 571 | 571 | $this->_reports_template_data, |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | { |
| 588 | 588 | $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
| 589 | 589 | $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
| 590 | - $results = (array)$results; |
|
| 590 | + $results = (array) $results; |
|
| 591 | 591 | $regs = array(); |
| 592 | 592 | $subtitle = ''; |
| 593 | 593 | if ($results) { |
@@ -597,7 +597,7 @@ discard block |
||
| 597 | 597 | $report_column_values = array(); |
| 598 | 598 | foreach ($result as $property_name => $property_value) { |
| 599 | 599 | $property_value = $property_name === 'Registration_REG_date' ? $property_value |
| 600 | - : (int)$property_value; |
|
| 600 | + : (int) $property_value; |
|
| 601 | 601 | $report_column_values[] = $property_value; |
| 602 | 602 | if ($tracker === 0) { |
| 603 | 603 | if ($property_name === 'Registration_REG_date') { |
@@ -614,7 +614,7 @@ discard block |
||
| 614 | 614 | array_unshift($regs, $column_titles); |
| 615 | 615 | //setup the date range. |
| 616 | 616 | $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
| 617 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 617 | + $beginning_date = new DateTime("now ".$period, $DateTimeZone); |
|
| 618 | 618 | $ending_date = new DateTime("now", $DateTimeZone); |
| 619 | 619 | $subtitle = sprintf( |
| 620 | 620 | _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
@@ -634,7 +634,7 @@ discard block |
||
| 634 | 634 | '%sThere are currently no registration records in the last month for this report.%s', |
| 635 | 635 | 'event_espresso' |
| 636 | 636 | ), |
| 637 | - '<h2>' . $report_title . '</h2><p>', |
|
| 637 | + '<h2>'.$report_title.'</h2><p>', |
|
| 638 | 638 | '</p>' |
| 639 | 639 | ), |
| 640 | 640 | ); |
@@ -654,7 +654,7 @@ discard block |
||
| 654 | 654 | { |
| 655 | 655 | $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
| 656 | 656 | $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
| 657 | - $results = (array)$results; |
|
| 657 | + $results = (array) $results; |
|
| 658 | 658 | $regs = array(); |
| 659 | 659 | $subtitle = ''; |
| 660 | 660 | if ($results) { |
@@ -667,7 +667,7 @@ discard block |
||
| 667 | 667 | $property_value, |
| 668 | 668 | 4, |
| 669 | 669 | '...' |
| 670 | - ) : (int)$property_value; |
|
| 670 | + ) : (int) $property_value; |
|
| 671 | 671 | $report_column_values[] = $property_value; |
| 672 | 672 | if ($tracker === 0) { |
| 673 | 673 | if ($property_name === 'Registration_Event') { |
@@ -684,7 +684,7 @@ discard block |
||
| 684 | 684 | array_unshift($regs, $column_titles); |
| 685 | 685 | //setup the date range. |
| 686 | 686 | $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
| 687 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 687 | + $beginning_date = new DateTime("now ".$period, $DateTimeZone); |
|
| 688 | 688 | $ending_date = new DateTime("now", $DateTimeZone); |
| 689 | 689 | $subtitle = sprintf( |
| 690 | 690 | _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
@@ -704,7 +704,7 @@ discard block |
||
| 704 | 704 | '%sThere are currently no registration records in the last month for this report.%s', |
| 705 | 705 | 'event_espresso' |
| 706 | 706 | ), |
| 707 | - '<h2>' . $report_title . '</h2><p>', |
|
| 707 | + '<h2>'.$report_title.'</h2><p>', |
|
| 708 | 708 | '</p>' |
| 709 | 709 | ), |
| 710 | 710 | ); |
@@ -754,31 +754,31 @@ discard block |
||
| 754 | 754 | $this->_admin_base_url |
| 755 | 755 | ) : ''; |
| 756 | 756 | $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
| 757 | - ? '<h2>' . sprintf( |
|
| 757 | + ? '<h2>'.sprintf( |
|
| 758 | 758 | __("%s's check in records for %s at the event, %s", 'event_espresso'), |
| 759 | 759 | '<span id="checkin-attendee-name">' |
| 760 | 760 | . EEM_Registration::instance() |
| 761 | 761 | ->get_one_by_ID($reg_id) |
| 762 | 762 | ->get_first_related('Attendee') |
| 763 | - ->full_name() . '</span>', |
|
| 764 | - '<span id="checkin-dtt"><a href="' . $go_back_url . '">' |
|
| 763 | + ->full_name().'</span>', |
|
| 764 | + '<span id="checkin-dtt"><a href="'.$go_back_url.'">' |
|
| 765 | 765 | . EEM_Datetime::instance() |
| 766 | 766 | ->get_one_by_ID($dtt_id) |
| 767 | - ->start_date_and_time() . ' - ' |
|
| 767 | + ->start_date_and_time().' - ' |
|
| 768 | 768 | . EEM_Datetime::instance() |
| 769 | 769 | ->get_one_by_ID($dtt_id) |
| 770 | - ->end_date_and_time() . '</a></span>', |
|
| 770 | + ->end_date_and_time().'</a></span>', |
|
| 771 | 771 | '<span id="checkin-event-name">' |
| 772 | 772 | . EEM_Datetime::instance() |
| 773 | 773 | ->get_one_by_ID($dtt_id) |
| 774 | 774 | ->get_first_related('Event') |
| 775 | - ->get('EVT_name') . '</span>' |
|
| 776 | - ) . '</h2>' |
|
| 775 | + ->get('EVT_name').'</span>' |
|
| 776 | + ).'</h2>' |
|
| 777 | 777 | : ''; |
| 778 | 778 | $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
| 779 | - ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : ''; |
|
| 779 | + ? '<input type="hidden" name="_REGID" value="'.$reg_id.'">' : ''; |
|
| 780 | 780 | $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
| 781 | - ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
| 781 | + ? '<input type="hidden" name="DTT_ID" value="'.$dtt_id.'">' : ''; |
|
| 782 | 782 | $this->display_admin_list_table_page_with_no_sidebar(); |
| 783 | 783 | } |
| 784 | 784 | |
@@ -1019,37 +1019,37 @@ discard block |
||
| 1019 | 1019 | 'desc' => __('View All Check-in Records for this Registrant', 'event_espresso'), |
| 1020 | 1020 | ), |
| 1021 | 1021 | 'approved_status' => array( |
| 1022 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 1022 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved, |
|
| 1023 | 1023 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
| 1024 | 1024 | ), |
| 1025 | 1025 | 'cancelled_status' => array( |
| 1026 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 1026 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled, |
|
| 1027 | 1027 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
| 1028 | 1028 | ), |
| 1029 | 1029 | 'declined_status' => array( |
| 1030 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 1030 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined, |
|
| 1031 | 1031 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
| 1032 | 1032 | ), |
| 1033 | 1033 | 'not_approved' => array( |
| 1034 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 1034 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved, |
|
| 1035 | 1035 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
| 1036 | 1036 | ), |
| 1037 | 1037 | 'pending_status' => array( |
| 1038 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 1038 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment, |
|
| 1039 | 1039 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
| 1040 | 1040 | ), |
| 1041 | 1041 | 'wait_list' => array( |
| 1042 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 1042 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list, |
|
| 1043 | 1043 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
| 1044 | 1044 | ), |
| 1045 | 1045 | ); |
| 1046 | 1046 | $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
| 1047 | 1047 | $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
| 1048 | 1048 | $this->_template_args['before_list_table'] = ! empty($event_id) |
| 1049 | - ? '<h2>' . sprintf( |
|
| 1049 | + ? '<h2>'.sprintf( |
|
| 1050 | 1050 | __('Viewing Registrations for Event: %s', 'event_espresso'), |
| 1051 | 1051 | EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
| 1052 | - ) . '</h2>' |
|
| 1052 | + ).'</h2>' |
|
| 1053 | 1053 | : ''; |
| 1054 | 1054 | //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event. |
| 1055 | 1055 | /** @var EE_Event $event */ |
@@ -1068,7 +1068,7 @@ discard block |
||
| 1068 | 1068 | $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
| 1069 | 1069 | $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
| 1070 | 1070 | $this->_template_args['before_list_table'] .= $datetime->name(); |
| 1071 | - $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
| 1071 | + $this->_template_args['before_list_table'] .= ' ( '.$datetime->date_and_time_range().' )'; |
|
| 1072 | 1072 | $this->_template_args['before_list_table'] .= '</span></h2>'; |
| 1073 | 1073 | } |
| 1074 | 1074 | //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column |
@@ -1098,7 +1098,7 @@ discard block |
||
| 1098 | 1098 | public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = '') |
| 1099 | 1099 | { |
| 1100 | 1100 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 1101 | - require_once(EE_MODELS . 'EEM_Attendee.model.php'); |
|
| 1101 | + require_once(EE_MODELS.'EEM_Attendee.model.php'); |
|
| 1102 | 1102 | //$ATT_MDL = EEM_Attendee::instance(); |
| 1103 | 1103 | $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
| 1104 | 1104 | $CAT_ID = isset($this->_req_data['category_id']) ? absint($this->_req_data['category_id']) : false; |
@@ -1151,7 +1151,7 @@ discard block |
||
| 1151 | 1151 | $query_params[0]['Attendee.status'] = EEM_CPT_Base::post_status_trashed; |
| 1152 | 1152 | } |
| 1153 | 1153 | if (isset($this->_req_data['s'])) { |
| 1154 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 1154 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
| 1155 | 1155 | $query_params[0]['OR'] = array( |
| 1156 | 1156 | 'Event.EVT_name' => array('LIKE', $sstr), |
| 1157 | 1157 | 'Event.EVT_desc' => array('LIKE', $sstr), |
@@ -1173,7 +1173,7 @@ discard block |
||
| 1173 | 1173 | } |
| 1174 | 1174 | $query_params['order_by'][$orderby] = $sort; |
| 1175 | 1175 | $query_params['limit'] = $limit; |
| 1176 | - $query_params['force_join'] = array('Attendee');//force join to attendee model so that it gets cached, because we're going to need the attendee for each registration |
|
| 1176 | + $query_params['force_join'] = array('Attendee'); //force join to attendee model so that it gets cached, because we're going to need the attendee for each registration |
|
| 1177 | 1177 | if ($count) { |
| 1178 | 1178 | $registrations = EEM_Registration::instance()->count( |
| 1179 | 1179 | array($query_params[0], 'default_where_conditions' => 'this_model_only') |
@@ -1190,26 +1190,26 @@ discard block |
||
| 1190 | 1190 | $event_obj = $first_registration->event_obj(); |
| 1191 | 1191 | if ($event_obj) { |
| 1192 | 1192 | $event_name = $first_registration->event_obj()->name(); |
| 1193 | - $event_date = 'TODO: we need to get date from earliest price date or should this be the actual event date?';//$first_registration->date_obj()->reg_start_date_and_time('l F j, Y,', ' g:i:s a');// isset( $registrations[0]->DTT_EVT_start ) ? date( 'l F j, Y, g:i:s a', $registrations[0]->DTT_EVT_start ) : ''; |
|
| 1193 | + $event_date = 'TODO: we need to get date from earliest price date or should this be the actual event date?'; //$first_registration->date_obj()->reg_start_date_and_time('l F j, Y,', ' g:i:s a');// isset( $registrations[0]->DTT_EVT_start ) ? date( 'l F j, Y, g:i:s a', $registrations[0]->DTT_EVT_start ) : ''; |
|
| 1194 | 1194 | // edit event link |
| 1195 | 1195 | if ($event_name !== '') { |
| 1196 | 1196 | $edit_event_url = self::add_query_args_and_nonce( |
| 1197 | 1197 | array('action' => 'edit_event', 'EVT_ID' => $EVT_ID), |
| 1198 | 1198 | EVENTS_ADMIN_URL |
| 1199 | 1199 | ); |
| 1200 | - $edit_event_lnk = '<a href="' . $edit_event_url . '" title="' . esc_attr__( |
|
| 1200 | + $edit_event_lnk = '<a href="'.$edit_event_url.'" title="'.esc_attr__( |
|
| 1201 | 1201 | 'Edit ', |
| 1202 | 1202 | 'event_espresso' |
| 1203 | - ) . $event_name . '">' . __('Edit Event', 'event_espresso') . '</a>'; |
|
| 1203 | + ).$event_name.'">'.__('Edit Event', 'event_espresso').'</a>'; |
|
| 1204 | 1204 | $event_name .= ' <span class="admin-page-header-edit-lnk not-bold">' |
| 1205 | 1205 | . $edit_event_lnk |
| 1206 | 1206 | . '</span>'; |
| 1207 | 1207 | } |
| 1208 | 1208 | $back_2_reg_url = self::add_query_args_and_nonce(array('action' => 'default'), REG_ADMIN_URL); |
| 1209 | - $back_2_reg_lnk = '<a href="' . $back_2_reg_url . '" title="' . esc_attr__( |
|
| 1209 | + $back_2_reg_lnk = '<a href="'.$back_2_reg_url.'" title="'.esc_attr__( |
|
| 1210 | 1210 | 'click to return to viewing all registrations ', |
| 1211 | 1211 | 'event_espresso' |
| 1212 | - ) . '">« ' . __('Back to All Registrations', 'event_espresso') . '</a>'; |
|
| 1212 | + ).'">« '.__('Back to All Registrations', 'event_espresso').'</a>'; |
|
| 1213 | 1213 | $this->_template_args['before_admin_page_content'] = ' |
| 1214 | 1214 | <div id="admin-page-header"> |
| 1215 | 1215 | <h1><span class="small-text not-bold">' |