@@ -13,1349 +13,1349 @@ |
||
| 13 | 13 | class EE_Form_Section_Proper extends EE_Form_Section_Validatable |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * Subsections |
|
| 20 | - * |
|
| 21 | - * @var EE_Form_Section_Validatable[] |
|
| 22 | - */ |
|
| 23 | - protected $_subsections = array(); |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Strategy for laying out the form |
|
| 27 | - * |
|
| 28 | - * @var EE_Form_Section_Layout_Base |
|
| 29 | - */ |
|
| 30 | - protected $_layout_strategy; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Whether or not this form has received and validated a form submission yet |
|
| 34 | - * |
|
| 35 | - * @var boolean |
|
| 36 | - */ |
|
| 37 | - protected $_received_submission = false; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * message displayed to users upon successful form submission |
|
| 41 | - * |
|
| 42 | - * @var string |
|
| 43 | - */ |
|
| 44 | - protected $_form_submission_success_message = ''; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * message displayed to users upon unsuccessful form submission |
|
| 48 | - * |
|
| 49 | - * @var string |
|
| 50 | - */ |
|
| 51 | - protected $_form_submission_error_message = ''; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Stores all the data that will localized for form validation |
|
| 55 | - * |
|
| 56 | - * @var array |
|
| 57 | - */ |
|
| 58 | - static protected $_js_localization = array(); |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * whether or not the form's localized validation JS vars have been set |
|
| 62 | - * |
|
| 63 | - * @type boolean |
|
| 64 | - */ |
|
| 65 | - static protected $_scripts_localized = false; |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * when constructing a proper form section, calls _construct_finalize on children |
|
| 71 | - * so that they know who their parent is, and what name they've been given. |
|
| 72 | - * |
|
| 73 | - * @param array $options_array { |
|
| 74 | - * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
| 75 | - * @type $include string[] numerically-indexed where values are section names to be included, |
|
| 76 | - * and in that order. This is handy if you want |
|
| 77 | - * the subsections to be ordered differently than the default, and if you override |
|
| 78 | - * which fields are shown |
|
| 79 | - * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
| 80 | - * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
| 81 | - * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
| 82 | - * items from that list of inclusions) |
|
| 83 | - * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
| 84 | - * } @see EE_Form_Section_Validatable::__construct() |
|
| 85 | - * @throws \EE_Error |
|
| 86 | - */ |
|
| 87 | - public function __construct($options_array = array()) |
|
| 88 | - { |
|
| 89 | - $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
| 90 | - $this); |
|
| 91 | - //call parent first, as it may be setting the name |
|
| 92 | - parent::__construct($options_array); |
|
| 93 | - //if they've included subsections in the constructor, add them now |
|
| 94 | - if (isset($options_array['include'])) { |
|
| 95 | - //we are going to make sure we ONLY have those subsections to include |
|
| 96 | - //AND we are going to make sure they're in that specified order |
|
| 97 | - $reordered_subsections = array(); |
|
| 98 | - foreach ($options_array['include'] as $input_name) { |
|
| 99 | - if (isset($this->_subsections[$input_name])) { |
|
| 100 | - $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - $this->_subsections = $reordered_subsections; |
|
| 104 | - } |
|
| 105 | - if (isset($options_array['exclude'])) { |
|
| 106 | - $exclude = $options_array['exclude']; |
|
| 107 | - $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
| 108 | - } |
|
| 109 | - if (isset($options_array['layout_strategy'])) { |
|
| 110 | - $this->_layout_strategy = $options_array['layout_strategy']; |
|
| 111 | - } |
|
| 112 | - if ( ! $this->_layout_strategy) { |
|
| 113 | - $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
| 114 | - } |
|
| 115 | - $this->_layout_strategy->_construct_finalize($this); |
|
| 116 | - //ok so we are definitely going to want the forms JS, |
|
| 117 | - //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
| 118 | - if (did_action('wp_enqueue_scripts') |
|
| 119 | - || did_action('admin_enqueue_scripts') |
|
| 120 | - ) { |
|
| 121 | - //ok so they've constructed this object after when they should have. |
|
| 122 | - //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
| 123 | - \EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
| 124 | - } else { |
|
| 125 | - add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 126 | - add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 127 | - } |
|
| 128 | - add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
| 129 | - if (isset($options_array['name'])) { |
|
| 130 | - $this->_construct_finalize(null, $options_array['name']); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Finishes construction given the parent form section and this form section's name |
|
| 138 | - * |
|
| 139 | - * @param EE_Form_Section_Proper $parent_form_section |
|
| 140 | - * @param string $name |
|
| 141 | - * @throws \EE_Error |
|
| 142 | - */ |
|
| 143 | - public function _construct_finalize($parent_form_section, $name) |
|
| 144 | - { |
|
| 145 | - parent::_construct_finalize($parent_form_section, $name); |
|
| 146 | - $this->_set_default_name_if_empty(); |
|
| 147 | - $this->_set_default_html_id_if_empty(); |
|
| 148 | - foreach ($this->_subsections as $subsection_name => $subsection) { |
|
| 149 | - if ($subsection instanceof EE_Form_Section_Base) { |
|
| 150 | - $subsection->_construct_finalize($this, $subsection_name); |
|
| 151 | - } else { |
|
| 152 | - throw new EE_Error( |
|
| 153 | - sprintf( |
|
| 154 | - __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
| 155 | - 'event_espresso'), |
|
| 156 | - $subsection_name, |
|
| 157 | - get_class($this), |
|
| 158 | - $subsection ? get_class($subsection) : __('NULL', 'event_espresso') |
|
| 159 | - ) |
|
| 160 | - ); |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Gets the layout strategy for this form section |
|
| 170 | - * |
|
| 171 | - * @return EE_Form_Section_Layout_Base |
|
| 172 | - */ |
|
| 173 | - public function get_layout_strategy() |
|
| 174 | - { |
|
| 175 | - return $this->_layout_strategy; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Gets the HTML for a single input for this form section according |
|
| 182 | - * to the layout strategy |
|
| 183 | - * |
|
| 184 | - * @param EE_Form_Input_Base $input |
|
| 185 | - * @return string |
|
| 186 | - */ |
|
| 187 | - public function get_html_for_input($input) |
|
| 188 | - { |
|
| 189 | - return $this->_layout_strategy->layout_input($input); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * was_submitted - checks if form inputs are present in request data |
|
| 196 | - * Basically an alias for form_data_present_in() (which is used by both |
|
| 197 | - * proper form sections and form inputs) |
|
| 198 | - * |
|
| 199 | - * @param null $form_data |
|
| 200 | - * @return boolean |
|
| 201 | - */ |
|
| 202 | - public function was_submitted($form_data = null) |
|
| 203 | - { |
|
| 204 | - return $this->form_data_present_in($form_data); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * After the form section is initially created, call this to sanitize the data in the submission |
|
| 211 | - * which relates to this form section, validate it, and set it as properties on the form. |
|
| 212 | - * |
|
| 213 | - * @param array|null $req_data should usually be $_POST (the default). |
|
| 214 | - * However, you CAN supply a different array. |
|
| 215 | - * Consider using set_defaults() instead however. |
|
| 216 | - * (If you rendered the form in the page using echo $form_x->get_html() |
|
| 217 | - * the inputs will have the correct name in the request data for this function |
|
| 218 | - * to find them and populate the form with them. |
|
| 219 | - * If you have a flat form (with only input subsections), |
|
| 220 | - * you can supply a flat array where keys |
|
| 221 | - * are the form input names and values are their values) |
|
| 222 | - * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
| 223 | - * of course, to validate that data, and set errors on the invalid values. |
|
| 224 | - * But if the data has already been validated |
|
| 225 | - * (eg you validated the data then stored it in the DB) |
|
| 226 | - * you may want to skip this step. |
|
| 227 | - */ |
|
| 228 | - public function receive_form_submission($req_data = null, $validate = true) |
|
| 229 | - { |
|
| 230 | - $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this, |
|
| 231 | - $validate); |
|
| 232 | - if ($req_data === null) { |
|
| 233 | - $req_data = array_merge($_GET, $_POST); |
|
| 234 | - } |
|
| 235 | - $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data, |
|
| 236 | - $this); |
|
| 237 | - $this->_normalize($req_data); |
|
| 238 | - if ($validate) { |
|
| 239 | - $this->_validate(); |
|
| 240 | - //if it's invalid, we're going to want to re-display so remember what they submitted |
|
| 241 | - if ( ! $this->is_valid()) { |
|
| 242 | - $this->store_submitted_form_data_in_session(); |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * caches the originally submitted input values in the session |
|
| 252 | - * so that they can be used to repopulate the form if it failed validation |
|
| 253 | - * |
|
| 254 | - * @return boolean whether or not the data was successfully stored in the session |
|
| 255 | - */ |
|
| 256 | - protected function store_submitted_form_data_in_session() |
|
| 257 | - { |
|
| 258 | - return EE_Registry::instance()->SSN->set_session_data( |
|
| 259 | - array( |
|
| 260 | - \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
| 261 | - ) |
|
| 262 | - ); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * retrieves the originally submitted input values in the session |
|
| 269 | - * so that they can be used to repopulate the form if it failed validation |
|
| 270 | - * |
|
| 271 | - * @return array |
|
| 272 | - */ |
|
| 273 | - protected function get_submitted_form_data_from_session() |
|
| 274 | - { |
|
| 275 | - $session = EE_Registry::instance()->SSN; |
|
| 276 | - if ($session instanceof EE_Session) { |
|
| 277 | - return $session->get_session_data( |
|
| 278 | - \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
| 279 | - ); |
|
| 280 | - } else { |
|
| 281 | - return array(); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * flushed the originally submitted input values from the session |
|
| 289 | - * |
|
| 290 | - * @return boolean whether or not the data was successfully removed from the session |
|
| 291 | - */ |
|
| 292 | - protected function flush_submitted_form_data_from_session() |
|
| 293 | - { |
|
| 294 | - return EE_Registry::instance()->SSN->reset_data( |
|
| 295 | - array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
| 296 | - ); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Populates this form and its subsections with data from the session. |
|
| 303 | - * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
| 304 | - * validation errors when displaying too) |
|
| 305 | - * Returns true if the form was populated from the session, false otherwise |
|
| 306 | - * |
|
| 307 | - * @return boolean |
|
| 308 | - */ |
|
| 309 | - public function populate_from_session() |
|
| 310 | - { |
|
| 311 | - $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
| 312 | - if (empty($form_data_in_session)) { |
|
| 313 | - return false; |
|
| 314 | - } |
|
| 315 | - $this->receive_form_submission($form_data_in_session); |
|
| 316 | - $this->flush_submitted_form_data_from_session(); |
|
| 317 | - if ($this->form_data_present_in($form_data_in_session)) { |
|
| 318 | - return true; |
|
| 319 | - } else { |
|
| 320 | - return false; |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Populates the default data for the form, given an array where keys are |
|
| 328 | - * the input names, and values are their values (preferably normalized to be their |
|
| 329 | - * proper PHP types, not all strings... although that should be ok too). |
|
| 330 | - * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
| 331 | - * the value being an array formatted in teh same way |
|
| 332 | - * |
|
| 333 | - * @param array $default_data |
|
| 334 | - */ |
|
| 335 | - public function populate_defaults($default_data) |
|
| 336 | - { |
|
| 337 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 338 | - if (isset($default_data[$subsection_name])) { |
|
| 339 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 340 | - $subsection->set_default($default_data[$subsection_name]); |
|
| 341 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 342 | - $subsection->populate_defaults($default_data[$subsection_name]); |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * returns true if subsection exists |
|
| 352 | - * |
|
| 353 | - * @param string $name |
|
| 354 | - * @return boolean |
|
| 355 | - */ |
|
| 356 | - public function subsection_exists($name) |
|
| 357 | - { |
|
| 358 | - return isset($this->_subsections[$name]) ? true : false; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Gets the subsection specified by its name |
|
| 365 | - * |
|
| 366 | - * @param string $name |
|
| 367 | - * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
| 368 | - * so that the inputs will be properly configured. |
|
| 369 | - * However, some client code may be ok |
|
| 370 | - * with construction finalize being called later |
|
| 371 | - * (realizing that the subsections' html names |
|
| 372 | - * might not be set yet, etc.) |
|
| 373 | - * @return EE_Form_Section_Base |
|
| 374 | - * @throws \EE_Error |
|
| 375 | - */ |
|
| 376 | - public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
| 377 | - { |
|
| 378 | - if ($require_construction_to_be_finalized) { |
|
| 379 | - $this->ensure_construct_finalized_called(); |
|
| 380 | - } |
|
| 381 | - return $this->subsection_exists($name) ? $this->_subsections[$name] : null; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * Gets all the validatable subsections of this form section |
|
| 388 | - * |
|
| 389 | - * @return EE_Form_Section_Validatable[] |
|
| 390 | - */ |
|
| 391 | - public function get_validatable_subsections() |
|
| 392 | - { |
|
| 393 | - $validatable_subsections = array(); |
|
| 394 | - foreach ($this->subsections() as $name => $obj) { |
|
| 395 | - if ($obj instanceof EE_Form_Section_Validatable) { |
|
| 396 | - $validatable_subsections[$name] = $obj; |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - return $validatable_subsections; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
| 406 | - * throw an EE_Error. |
|
| 407 | - * |
|
| 408 | - * @param string $name |
|
| 409 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 410 | - * leave this as TRUE so that the inputs will be properly |
|
| 411 | - * configured. However, some client code may be ok with |
|
| 412 | - * construction finalize being called later |
|
| 413 | - * (realizing that the subsections' html names might not be |
|
| 414 | - * set yet, etc.) |
|
| 415 | - * @return EE_Form_Input_Base |
|
| 416 | - * @throws EE_Error |
|
| 417 | - */ |
|
| 418 | - public function get_input($name, $require_construction_to_be_finalized = true) |
|
| 419 | - { |
|
| 420 | - $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
| 421 | - if ( ! $subsection instanceof EE_Form_Input_Base) { |
|
| 422 | - throw new EE_Error( |
|
| 423 | - sprintf( |
|
| 424 | - __( |
|
| 425 | - "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
| 426 | - 'event_espresso' |
|
| 427 | - ), |
|
| 428 | - $name, |
|
| 429 | - get_class($this), |
|
| 430 | - $subsection ? get_class($subsection) : __("NULL", 'event_espresso') |
|
| 431 | - ) |
|
| 432 | - ); |
|
| 433 | - } |
|
| 434 | - return $subsection; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * Like get_input(), gets the proper subsection of the form given the name, |
|
| 441 | - * otherwise throws an EE_Error |
|
| 442 | - * |
|
| 443 | - * @param string $name |
|
| 444 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 445 | - * leave this as TRUE so that the inputs will be properly |
|
| 446 | - * configured. However, some client code may be ok with |
|
| 447 | - * construction finalize being called later |
|
| 448 | - * (realizing that the subsections' html names might not be |
|
| 449 | - * set yet, etc.) |
|
| 450 | - * @return EE_Form_Section_Proper |
|
| 451 | - * @throws EE_Error |
|
| 452 | - */ |
|
| 453 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
| 454 | - { |
|
| 455 | - $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
| 456 | - if ( ! $subsection instanceof EE_Form_Section_Proper) { |
|
| 457 | - throw new EE_Error( |
|
| 458 | - sprintf( |
|
| 459 | - __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), |
|
| 460 | - $name, |
|
| 461 | - get_class($this) |
|
| 462 | - ) |
|
| 463 | - ); |
|
| 464 | - } |
|
| 465 | - return $subsection; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * Gets the value of the specified input. Should be called after receive_form_submission() |
|
| 472 | - * or populate_defaults() on the form, where the normalized value on the input is set. |
|
| 473 | - * |
|
| 474 | - * @param string $name |
|
| 475 | - * @return mixed depending on the input's type and its normalization strategy |
|
| 476 | - * @throws \EE_Error |
|
| 477 | - */ |
|
| 478 | - public function get_input_value($name) |
|
| 479 | - { |
|
| 480 | - $input = $this->get_input($name); |
|
| 481 | - return $input->normalized_value(); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * Checks if this form section itself is valid, and then checks its subsections |
|
| 488 | - * |
|
| 489 | - * @throws EE_Error |
|
| 490 | - * @return boolean |
|
| 491 | - */ |
|
| 492 | - public function is_valid() |
|
| 493 | - { |
|
| 494 | - if ( ! $this->has_received_submission()) { |
|
| 495 | - throw new EE_Error( |
|
| 496 | - sprintf( |
|
| 497 | - __( |
|
| 498 | - "You cannot check if a form is valid before receiving the form submission using receive_form_submission", |
|
| 499 | - "event_espresso" |
|
| 500 | - ) |
|
| 501 | - ) |
|
| 502 | - ); |
|
| 503 | - } |
|
| 504 | - if ( ! parent::is_valid()) { |
|
| 505 | - return false; |
|
| 506 | - } |
|
| 507 | - // ok so no general errors to this entire form section. |
|
| 508 | - // so let's check the subsections, but only set errors if that hasn't been done yet |
|
| 509 | - $set_submission_errors = $this->submission_error_message() === '' ? true : false; |
|
| 510 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 511 | - if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
| 512 | - if ($set_submission_errors) { |
|
| 513 | - $this->set_submission_error_message($subsection->get_validation_error_string()); |
|
| 514 | - } |
|
| 515 | - return false; |
|
| 516 | - } |
|
| 517 | - } |
|
| 518 | - return true; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * gets teh default name of this form section if none is specified |
|
| 525 | - * |
|
| 526 | - * @return string |
|
| 527 | - */ |
|
| 528 | - protected function _set_default_name_if_empty() |
|
| 529 | - { |
|
| 530 | - if ( ! $this->_name) { |
|
| 531 | - $classname = get_class($this); |
|
| 532 | - $default_name = str_replace("EE_", "", $classname); |
|
| 533 | - $this->_name = $default_name; |
|
| 534 | - } |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * Returns the JS for validating the form (and subsections) inside script tags. |
|
| 541 | - * Also returns the HTML for the form, except for the form opening and closing tags |
|
| 542 | - * (as the form section doesn't know where you necessarily want to send the information to), |
|
| 543 | - * and except for a submit button. |
|
| 544 | - * |
|
| 545 | - * @deprecated since 4.9.0. You should instead call enqueue_js during the "wp_enqueue_scripts" |
|
| 546 | - * and get_html when you are about to display the form. |
|
| 547 | - * @throws \EE_Error |
|
| 548 | - */ |
|
| 549 | - public function get_html_and_js() |
|
| 550 | - { |
|
| 551 | - //no doing_it_wrong yet because we ourselves are still doing it wrong... |
|
| 552 | - //and theoretically this CAN be used properly, provided its used during "wp_enqueue_scripts" |
|
| 553 | - $this->enqueue_js(); |
|
| 554 | - return $this->get_html(); |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
| 561 | - * |
|
| 562 | - * @param bool $display_previously_submitted_data |
|
| 563 | - * @return string |
|
| 564 | - */ |
|
| 565 | - public function get_html($display_previously_submitted_data = true) |
|
| 566 | - { |
|
| 567 | - $this->ensure_construct_finalized_called(); |
|
| 568 | - if ($display_previously_submitted_data) { |
|
| 569 | - $this->populate_from_session(); |
|
| 570 | - } |
|
| 571 | - return $this->_layout_strategy->layout_form(); |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - |
|
| 575 | - |
|
| 576 | - /** |
|
| 577 | - * enqueues JS for the form |
|
| 578 | - * |
|
| 579 | - * @return string |
|
| 580 | - * @throws \EE_Error |
|
| 581 | - */ |
|
| 582 | - public function enqueue_js() |
|
| 583 | - { |
|
| 584 | - $this->_enqueue_and_localize_form_js(); |
|
| 585 | - foreach ($this->subsections() as $subsection) { |
|
| 586 | - $subsection->enqueue_js(); |
|
| 587 | - } |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
| 594 | - * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
| 595 | - * the wp_enqueue_scripts hook. |
|
| 596 | - * However, registering the form js and localizing it can happen when we |
|
| 597 | - * actually output the form (which is preferred, seeing how teh form's fields |
|
| 598 | - * could change until it's actually outputted) |
|
| 599 | - * |
|
| 600 | - * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
| 601 | - * to be triggered automatically or not |
|
| 602 | - * @return void |
|
| 603 | - */ |
|
| 604 | - public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
| 605 | - { |
|
| 606 | - add_filter('FHEE_load_jquery_validate', '__return_true'); |
|
| 607 | - wp_register_script( |
|
| 608 | - 'ee_form_section_validation', |
|
| 609 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
| 610 | - array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
| 611 | - EVENT_ESPRESSO_VERSION, |
|
| 612 | - true |
|
| 613 | - ); |
|
| 614 | - wp_localize_script( |
|
| 615 | - 'ee_form_section_validation', |
|
| 616 | - 'ee_form_section_validation_init', |
|
| 617 | - array('init' => $init_form_validation_automatically ? true : false) |
|
| 618 | - ); |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - |
|
| 622 | - |
|
| 623 | - /** |
|
| 624 | - * gets the variables used by form_section_validation.js. |
|
| 625 | - * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
| 626 | - * but before the wordpress hook wp_loaded |
|
| 627 | - * |
|
| 628 | - * @throws \EE_Error |
|
| 629 | - */ |
|
| 630 | - public function _enqueue_and_localize_form_js() |
|
| 631 | - { |
|
| 632 | - $this->ensure_construct_finalized_called(); |
|
| 633 | - //actually, we don't want to localize just yet. There may be other forms on the page. |
|
| 634 | - //so we need to add our form section data to a static variable accessible by all form sections |
|
| 635 | - //and localize it just before the footer |
|
| 636 | - $this->localize_validation_rules(); |
|
| 637 | - add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
| 638 | - add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - |
|
| 642 | - |
|
| 643 | - /** |
|
| 644 | - * add our form section data to a static variable accessible by all form sections |
|
| 645 | - * |
|
| 646 | - * @param bool $return_for_subsection |
|
| 647 | - * @return void |
|
| 648 | - * @throws \EE_Error |
|
| 649 | - */ |
|
| 650 | - public function localize_validation_rules($return_for_subsection = false) |
|
| 651 | - { |
|
| 652 | - // we only want to localize vars ONCE for the entire form, |
|
| 653 | - // so if the form section doesn't have a parent, then it must be the top dog |
|
| 654 | - if ($return_for_subsection || ! $this->parent_section()) { |
|
| 655 | - EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
| 656 | - 'form_section_id' => $this->html_id(true), |
|
| 657 | - 'validation_rules' => $this->get_jquery_validation_rules(), |
|
| 658 | - 'other_data' => $this->get_other_js_data(), |
|
| 659 | - 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
| 660 | - ); |
|
| 661 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 662 | - } |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * Gets an array of extra data that will be useful for client-side javascript. |
|
| 669 | - * This is primarily data added by inputs and forms in addition to any |
|
| 670 | - * scripts they might enqueue |
|
| 671 | - * |
|
| 672 | - * @param array $form_other_js_data |
|
| 673 | - * @return array |
|
| 674 | - */ |
|
| 675 | - public function get_other_js_data($form_other_js_data = array()) |
|
| 676 | - { |
|
| 677 | - foreach ($this->subsections() as $subsection) { |
|
| 678 | - $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
| 679 | - } |
|
| 680 | - return $form_other_js_data; |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * Gets a flat array of inputs for this form section and its subsections. |
|
| 687 | - * Keys are their form names, and values are the inputs themselves |
|
| 688 | - * |
|
| 689 | - * @return EE_Form_Input_Base |
|
| 690 | - */ |
|
| 691 | - public function inputs_in_subsections() |
|
| 692 | - { |
|
| 693 | - $inputs = array(); |
|
| 694 | - foreach ($this->subsections() as $subsection) { |
|
| 695 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 696 | - $inputs[$subsection->html_name()] = $subsection; |
|
| 697 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 698 | - $inputs += $subsection->inputs_in_subsections(); |
|
| 699 | - } |
|
| 700 | - } |
|
| 701 | - return $inputs; |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - |
|
| 705 | - |
|
| 706 | - /** |
|
| 707 | - * Gets a flat array of all the validation errors. |
|
| 708 | - * Keys are html names (because those should be unique) |
|
| 709 | - * and values are a string of all their validation errors |
|
| 710 | - * |
|
| 711 | - * @return string[] |
|
| 712 | - */ |
|
| 713 | - public function subsection_validation_errors_by_html_name() |
|
| 714 | - { |
|
| 715 | - $inputs = $this->inputs(); |
|
| 716 | - $errors = array(); |
|
| 717 | - foreach ($inputs as $form_input) { |
|
| 718 | - if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
| 719 | - $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
| 720 | - } |
|
| 721 | - } |
|
| 722 | - return $errors; |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - |
|
| 726 | - |
|
| 727 | - /** |
|
| 728 | - * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
| 729 | - * Should be setup by each form during the _enqueues_and_localize_form_js |
|
| 730 | - */ |
|
| 731 | - public static function localize_script_for_all_forms() |
|
| 732 | - { |
|
| 733 | - //allow inputs and stuff to hook in their JS and stuff here |
|
| 734 | - do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
| 735 | - EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
| 736 | - $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
| 737 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 738 | - : 'wp_default'; |
|
| 739 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 740 | - wp_enqueue_script('ee_form_section_validation'); |
|
| 741 | - wp_localize_script( |
|
| 742 | - 'ee_form_section_validation', |
|
| 743 | - 'ee_form_section_vars', |
|
| 744 | - EE_Form_Section_Proper::$_js_localization |
|
| 745 | - ); |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * ensure_scripts_localized |
|
| 752 | - */ |
|
| 753 | - public function ensure_scripts_localized() |
|
| 754 | - { |
|
| 755 | - if ( ! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 756 | - $this->_enqueue_and_localize_form_js(); |
|
| 757 | - } |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - |
|
| 761 | - |
|
| 762 | - /** |
|
| 763 | - * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
| 764 | - * is that the key here should be the same as the custom validation rule put in the JS file |
|
| 765 | - * |
|
| 766 | - * @return array keys are custom validation rules, and values are internationalized strings |
|
| 767 | - */ |
|
| 768 | - private static function _get_localized_error_messages() |
|
| 769 | - { |
|
| 770 | - return array( |
|
| 771 | - 'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"), |
|
| 772 | - 'regex' => __('Please check your input', 'event_espresso'), |
|
| 773 | - ); |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - |
|
| 777 | - |
|
| 778 | - /** |
|
| 779 | - * @return array |
|
| 780 | - */ |
|
| 781 | - public static function js_localization() |
|
| 782 | - { |
|
| 783 | - return self::$_js_localization; |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - |
|
| 787 | - |
|
| 788 | - /** |
|
| 789 | - * @return array |
|
| 790 | - */ |
|
| 791 | - public static function reset_js_localization() |
|
| 792 | - { |
|
| 793 | - self::$_js_localization = array(); |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - |
|
| 797 | - |
|
| 798 | - /** |
|
| 799 | - * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
| 800 | - * See parent function for more... |
|
| 801 | - * |
|
| 802 | - * @return array |
|
| 803 | - */ |
|
| 804 | - public function get_jquery_validation_rules() |
|
| 805 | - { |
|
| 806 | - $jquery_validation_rules = array(); |
|
| 807 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 808 | - $jquery_validation_rules = array_merge( |
|
| 809 | - $jquery_validation_rules, |
|
| 810 | - $subsection->get_jquery_validation_rules() |
|
| 811 | - ); |
|
| 812 | - } |
|
| 813 | - return $jquery_validation_rules; |
|
| 814 | - } |
|
| 815 | - |
|
| 816 | - |
|
| 817 | - |
|
| 818 | - /** |
|
| 819 | - * Sanitizes all the data and sets the sanitized value of each field |
|
| 820 | - * |
|
| 821 | - * @param array $req_data like $_POST |
|
| 822 | - * @return void |
|
| 823 | - */ |
|
| 824 | - protected function _normalize($req_data) |
|
| 825 | - { |
|
| 826 | - $this->_received_submission = true; |
|
| 827 | - $this->_validation_errors = array(); |
|
| 828 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 829 | - try { |
|
| 830 | - $subsection->_normalize($req_data); |
|
| 831 | - } catch (EE_Validation_Error $e) { |
|
| 832 | - $subsection->add_validation_error($e); |
|
| 833 | - } |
|
| 834 | - } |
|
| 835 | - } |
|
| 836 | - |
|
| 837 | - |
|
| 838 | - |
|
| 839 | - /** |
|
| 840 | - * Performs validation on this form section and its subsections. |
|
| 841 | - * For each subsection, |
|
| 842 | - * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
| 843 | - * and passes it the subsection, then calls _validate on that subsection. |
|
| 844 | - * If you need to perform validation on the form as a whole (considering multiple) |
|
| 845 | - * you would be best to override this _validate method, |
|
| 846 | - * calling parent::_validate() first. |
|
| 847 | - */ |
|
| 848 | - protected function _validate() |
|
| 849 | - { |
|
| 850 | - foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
| 851 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 852 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 853 | - } |
|
| 854 | - $subsection->_validate(); |
|
| 855 | - } |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - |
|
| 859 | - |
|
| 860 | - /** |
|
| 861 | - * Gets all the validated inputs for the form section |
|
| 862 | - * |
|
| 863 | - * @return array |
|
| 864 | - */ |
|
| 865 | - public function valid_data() |
|
| 866 | - { |
|
| 867 | - $inputs = array(); |
|
| 868 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 869 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 870 | - $inputs[$subsection_name] = $subsection->valid_data(); |
|
| 871 | - } else if ($subsection instanceof EE_Form_Input_Base) { |
|
| 872 | - $inputs[$subsection_name] = $subsection->normalized_value(); |
|
| 873 | - } |
|
| 874 | - } |
|
| 875 | - return $inputs; |
|
| 876 | - } |
|
| 877 | - |
|
| 878 | - |
|
| 879 | - |
|
| 880 | - /** |
|
| 881 | - * Gets all the inputs on this form section |
|
| 882 | - * |
|
| 883 | - * @return EE_Form_Input_Base[] |
|
| 884 | - */ |
|
| 885 | - public function inputs() |
|
| 886 | - { |
|
| 887 | - $inputs = array(); |
|
| 888 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 889 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 890 | - $inputs[$subsection_name] = $subsection; |
|
| 891 | - } |
|
| 892 | - } |
|
| 893 | - return $inputs; |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - |
|
| 897 | - |
|
| 898 | - /** |
|
| 899 | - * Gets all the subsections which are a proper form |
|
| 900 | - * |
|
| 901 | - * @return EE_Form_Section_Proper[] |
|
| 902 | - */ |
|
| 903 | - public function subforms() |
|
| 904 | - { |
|
| 905 | - $form_sections = array(); |
|
| 906 | - foreach ($this->subsections() as $name => $obj) { |
|
| 907 | - if ($obj instanceof EE_Form_Section_Proper) { |
|
| 908 | - $form_sections[$name] = $obj; |
|
| 909 | - } |
|
| 910 | - } |
|
| 911 | - return $form_sections; |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - |
|
| 915 | - |
|
| 916 | - /** |
|
| 917 | - * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
| 918 | - * Consider using inputs() or subforms() |
|
| 919 | - * if you only want form inputs or proper form sections. |
|
| 920 | - * |
|
| 921 | - * @return EE_Form_Section_Proper[] |
|
| 922 | - */ |
|
| 923 | - public function subsections() |
|
| 924 | - { |
|
| 925 | - $this->ensure_construct_finalized_called(); |
|
| 926 | - return $this->_subsections; |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - |
|
| 930 | - |
|
| 931 | - /** |
|
| 932 | - * Returns a simple array where keys are input names, and values are their normalized |
|
| 933 | - * values. (Similar to calling get_input_value on inputs) |
|
| 934 | - * |
|
| 935 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 936 | - * or just this forms' direct children inputs |
|
| 937 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 938 | - * or allow multidimensional array |
|
| 939 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 940 | - * with array keys being input names |
|
| 941 | - * (regardless of whether they are from a subsection or not), |
|
| 942 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 943 | - * where keys are always subsection names and values are either |
|
| 944 | - * the input's normalized value, or an array like the top-level array |
|
| 945 | - */ |
|
| 946 | - public function input_values($include_subform_inputs = false, $flatten = false) |
|
| 947 | - { |
|
| 948 | - return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
| 955 | - * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
| 956 | - * is not necessarily the value we want to display to users. This creates an array |
|
| 957 | - * where keys are the input names, and values are their display values |
|
| 958 | - * |
|
| 959 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 960 | - * or just this forms' direct children inputs |
|
| 961 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 962 | - * or allow multidimensional array |
|
| 963 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 964 | - * with array keys being input names |
|
| 965 | - * (regardless of whether they are from a subsection or not), |
|
| 966 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 967 | - * where keys are always subsection names and values are either |
|
| 968 | - * the input's normalized value, or an array like the top-level array |
|
| 969 | - */ |
|
| 970 | - public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
| 971 | - { |
|
| 972 | - return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - |
|
| 976 | - |
|
| 977 | - /** |
|
| 978 | - * Gets the input values from the form |
|
| 979 | - * |
|
| 980 | - * @param boolean $pretty Whether to retrieve the pretty value, |
|
| 981 | - * or just the normalized value |
|
| 982 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 983 | - * or just this forms' direct children inputs |
|
| 984 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 985 | - * or allow multidimensional array |
|
| 986 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
| 987 | - * input names (regardless of whether they are from a subsection or not), |
|
| 988 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 989 | - * where keys are always subsection names and values are either |
|
| 990 | - * the input's normalized value, or an array like the top-level array |
|
| 991 | - */ |
|
| 992 | - public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
| 993 | - { |
|
| 994 | - $input_values = array(); |
|
| 995 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 996 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 997 | - $input_values[$subsection_name] = $pretty |
|
| 998 | - ? $subsection->pretty_value() |
|
| 999 | - : $subsection->normalized_value(); |
|
| 1000 | - } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
| 1001 | - $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten); |
|
| 1002 | - if ($flatten) { |
|
| 1003 | - $input_values = array_merge($input_values, $subform_input_values); |
|
| 1004 | - } else { |
|
| 1005 | - $input_values[$subsection_name] = $subform_input_values; |
|
| 1006 | - } |
|
| 1007 | - } |
|
| 1008 | - } |
|
| 1009 | - return $input_values; |
|
| 1010 | - } |
|
| 1011 | - |
|
| 1012 | - |
|
| 1013 | - |
|
| 1014 | - /** |
|
| 1015 | - * Gets the originally submitted input values from the form |
|
| 1016 | - * |
|
| 1017 | - * @param boolean $include_subforms Whether to include inputs from subforms, |
|
| 1018 | - * or just this forms' direct children inputs |
|
| 1019 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1020 | - * with array keys being input names |
|
| 1021 | - * (regardless of whether they are from a subsection or not), |
|
| 1022 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1023 | - * where keys are always subsection names and values are either |
|
| 1024 | - * the input's normalized value, or an array like the top-level array |
|
| 1025 | - */ |
|
| 1026 | - public function submitted_values($include_subforms = false) |
|
| 1027 | - { |
|
| 1028 | - $submitted_values = array(); |
|
| 1029 | - foreach ($this->subsections() as $subsection) { |
|
| 1030 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1031 | - // is this input part of an array of inputs? |
|
| 1032 | - if (strpos($subsection->html_name(), '[') !== false) { |
|
| 1033 | - $full_input_name = \EEH_Array::convert_array_values_to_keys( |
|
| 1034 | - explode('[', str_replace(']', '', $subsection->html_name())), |
|
| 1035 | - $subsection->raw_value() |
|
| 1036 | - ); |
|
| 1037 | - $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
| 1038 | - } else { |
|
| 1039 | - $submitted_values[$subsection->html_name()] = $subsection->raw_value(); |
|
| 1040 | - } |
|
| 1041 | - } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
| 1042 | - $subform_input_values = $subsection->submitted_values($include_subforms); |
|
| 1043 | - $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
| 1044 | - } |
|
| 1045 | - } |
|
| 1046 | - return $submitted_values; |
|
| 1047 | - } |
|
| 1048 | - |
|
| 1049 | - |
|
| 1050 | - |
|
| 1051 | - /** |
|
| 1052 | - * Indicates whether or not this form has received a submission yet |
|
| 1053 | - * (ie, had receive_form_submission called on it yet) |
|
| 1054 | - * |
|
| 1055 | - * @return boolean |
|
| 1056 | - * @throws \EE_Error |
|
| 1057 | - */ |
|
| 1058 | - public function has_received_submission() |
|
| 1059 | - { |
|
| 1060 | - $this->ensure_construct_finalized_called(); |
|
| 1061 | - return $this->_received_submission; |
|
| 1062 | - } |
|
| 1063 | - |
|
| 1064 | - |
|
| 1065 | - |
|
| 1066 | - /** |
|
| 1067 | - * Equivalent to passing 'exclude' in the constructor's options array. |
|
| 1068 | - * Removes the listed inputs from the form |
|
| 1069 | - * |
|
| 1070 | - * @param array $inputs_to_exclude values are the input names |
|
| 1071 | - * @return void |
|
| 1072 | - */ |
|
| 1073 | - public function exclude(array $inputs_to_exclude = array()) |
|
| 1074 | - { |
|
| 1075 | - foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
| 1076 | - unset($this->_subsections[$input_to_exclude_name]); |
|
| 1077 | - } |
|
| 1078 | - } |
|
| 1079 | - |
|
| 1080 | - |
|
| 1081 | - |
|
| 1082 | - /** |
|
| 1083 | - * @param array $inputs_to_hide |
|
| 1084 | - * @throws \EE_Error |
|
| 1085 | - */ |
|
| 1086 | - public function hide($inputs_to_hide = array()) |
|
| 1087 | - { |
|
| 1088 | - foreach ($inputs_to_hide as $input_to_hide) { |
|
| 1089 | - $input = $this->get_input($input_to_hide); |
|
| 1090 | - $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
| 1091 | - } |
|
| 1092 | - } |
|
| 1093 | - |
|
| 1094 | - |
|
| 1095 | - |
|
| 1096 | - /** |
|
| 1097 | - * add_subsections |
|
| 1098 | - * Adds the listed subsections to the form section. |
|
| 1099 | - * If $subsection_name_to_target is provided, |
|
| 1100 | - * then new subsections are added before or after that subsection, |
|
| 1101 | - * otherwise to the start or end of the entire subsections array. |
|
| 1102 | - * |
|
| 1103 | - * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
| 1104 | - * where keys are their names |
|
| 1105 | - * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
| 1106 | - * should be added before or after |
|
| 1107 | - * IF $subsection_name_to_target is null, |
|
| 1108 | - * then $new_subsections will be added to |
|
| 1109 | - * the beginning or end of the entire subsections array |
|
| 1110 | - * @param boolean $add_before whether to add $new_subsections, before or after |
|
| 1111 | - * $subsection_name_to_target, |
|
| 1112 | - * or if $subsection_name_to_target is null, |
|
| 1113 | - * before or after entire subsections array |
|
| 1114 | - * @return void |
|
| 1115 | - * @throws \EE_Error |
|
| 1116 | - */ |
|
| 1117 | - public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
| 1118 | - { |
|
| 1119 | - foreach ($new_subsections as $subsection_name => $subsection) { |
|
| 1120 | - if ( ! $subsection instanceof EE_Form_Section_Base) { |
|
| 1121 | - EE_Error::add_error( |
|
| 1122 | - sprintf( |
|
| 1123 | - __( |
|
| 1124 | - "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
| 1125 | - "event_espresso" |
|
| 1126 | - ), |
|
| 1127 | - get_class($subsection), |
|
| 1128 | - $subsection_name, |
|
| 1129 | - $this->name() |
|
| 1130 | - ) |
|
| 1131 | - ); |
|
| 1132 | - unset($new_subsections[$subsection_name]); |
|
| 1133 | - } |
|
| 1134 | - } |
|
| 1135 | - $this->_subsections = EEH_Array::insert_into_array( |
|
| 1136 | - $this->_subsections, |
|
| 1137 | - $new_subsections, |
|
| 1138 | - $subsection_name_to_target, |
|
| 1139 | - $add_before |
|
| 1140 | - ); |
|
| 1141 | - if ($this->_construction_finalized) { |
|
| 1142 | - foreach ($this->_subsections as $name => $subsection) { |
|
| 1143 | - $subsection->_construct_finalize($this, $name); |
|
| 1144 | - } |
|
| 1145 | - } |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - |
|
| 1149 | - |
|
| 1150 | - /** |
|
| 1151 | - * Just gets all validatable subsections to clean their sensitive data |
|
| 1152 | - */ |
|
| 1153 | - public function clean_sensitive_data() |
|
| 1154 | - { |
|
| 1155 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1156 | - $subsection->clean_sensitive_data(); |
|
| 1157 | - } |
|
| 1158 | - } |
|
| 1159 | - |
|
| 1160 | - |
|
| 1161 | - |
|
| 1162 | - /** |
|
| 1163 | - * @param string $form_submission_error_message |
|
| 1164 | - */ |
|
| 1165 | - public function set_submission_error_message($form_submission_error_message = '') |
|
| 1166 | - { |
|
| 1167 | - $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
| 1168 | - ? $form_submission_error_message |
|
| 1169 | - : __('Form submission failed due to errors', 'event_espresso'); |
|
| 1170 | - } |
|
| 1171 | - |
|
| 1172 | - |
|
| 1173 | - |
|
| 1174 | - /** |
|
| 1175 | - * @return string |
|
| 1176 | - */ |
|
| 1177 | - public function submission_error_message() |
|
| 1178 | - { |
|
| 1179 | - return $this->_form_submission_error_message; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - |
|
| 1183 | - |
|
| 1184 | - /** |
|
| 1185 | - * @param string $form_submission_success_message |
|
| 1186 | - */ |
|
| 1187 | - public function set_submission_success_message($form_submission_success_message) |
|
| 1188 | - { |
|
| 1189 | - $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
| 1190 | - ? $form_submission_success_message |
|
| 1191 | - : __('Form submitted successfully', 'event_espresso'); |
|
| 1192 | - } |
|
| 1193 | - |
|
| 1194 | - |
|
| 1195 | - |
|
| 1196 | - /** |
|
| 1197 | - * @return string |
|
| 1198 | - */ |
|
| 1199 | - public function submission_success_message() |
|
| 1200 | - { |
|
| 1201 | - return $this->_form_submission_success_message; |
|
| 1202 | - } |
|
| 1203 | - |
|
| 1204 | - |
|
| 1205 | - |
|
| 1206 | - /** |
|
| 1207 | - * Returns the prefix that should be used on child of this form section for |
|
| 1208 | - * their html names. If this form section itself has a parent, prepends ITS |
|
| 1209 | - * prefix onto this form section's prefix. Used primarily by |
|
| 1210 | - * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 1211 | - * |
|
| 1212 | - * @return string |
|
| 1213 | - * @throws \EE_Error |
|
| 1214 | - */ |
|
| 1215 | - public function html_name_prefix() |
|
| 1216 | - { |
|
| 1217 | - if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
| 1218 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1219 | - } else { |
|
| 1220 | - return $this->name(); |
|
| 1221 | - } |
|
| 1222 | - } |
|
| 1223 | - |
|
| 1224 | - |
|
| 1225 | - |
|
| 1226 | - /** |
|
| 1227 | - * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 1228 | - * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 1229 | - * was set, which is probably nothing, or the classname) |
|
| 1230 | - * |
|
| 1231 | - * @return string |
|
| 1232 | - * @throws \EE_Error |
|
| 1233 | - */ |
|
| 1234 | - public function name() |
|
| 1235 | - { |
|
| 1236 | - $this->ensure_construct_finalized_called(); |
|
| 1237 | - return parent::name(); |
|
| 1238 | - } |
|
| 1239 | - |
|
| 1240 | - |
|
| 1241 | - |
|
| 1242 | - /** |
|
| 1243 | - * @return EE_Form_Section_Proper |
|
| 1244 | - * @throws \EE_Error |
|
| 1245 | - */ |
|
| 1246 | - public function parent_section() |
|
| 1247 | - { |
|
| 1248 | - $this->ensure_construct_finalized_called(); |
|
| 1249 | - return parent::parent_section(); |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - |
|
| 1253 | - |
|
| 1254 | - /** |
|
| 1255 | - * make sure construction finalized was called, otherwise children might not be ready |
|
| 1256 | - * |
|
| 1257 | - * @return void |
|
| 1258 | - * @throws \EE_Error |
|
| 1259 | - */ |
|
| 1260 | - public function ensure_construct_finalized_called() |
|
| 1261 | - { |
|
| 1262 | - if ( ! $this->_construction_finalized) { |
|
| 1263 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 1264 | - } |
|
| 1265 | - } |
|
| 1266 | - |
|
| 1267 | - |
|
| 1268 | - |
|
| 1269 | - /** |
|
| 1270 | - * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 1271 | - * are in teh form data. If any are found, returns true. Else false |
|
| 1272 | - * |
|
| 1273 | - * @param array $req_data |
|
| 1274 | - * @return boolean |
|
| 1275 | - */ |
|
| 1276 | - public function form_data_present_in($req_data = null) |
|
| 1277 | - { |
|
| 1278 | - if ($req_data === null) { |
|
| 1279 | - $req_data = $_POST; |
|
| 1280 | - } |
|
| 1281 | - foreach ($this->subsections() as $subsection) { |
|
| 1282 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1283 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 1284 | - return true; |
|
| 1285 | - } |
|
| 1286 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1287 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 1288 | - return true; |
|
| 1289 | - } |
|
| 1290 | - } |
|
| 1291 | - } |
|
| 1292 | - return false; |
|
| 1293 | - } |
|
| 1294 | - |
|
| 1295 | - |
|
| 1296 | - |
|
| 1297 | - /** |
|
| 1298 | - * Gets validation errors for this form section and subsections |
|
| 1299 | - * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 1300 | - * gets the validation errors for ALL subsection |
|
| 1301 | - * |
|
| 1302 | - * @return EE_Validation_Error[] |
|
| 1303 | - */ |
|
| 1304 | - public function get_validation_errors_accumulated() |
|
| 1305 | - { |
|
| 1306 | - $validation_errors = $this->get_validation_errors(); |
|
| 1307 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1308 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1309 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
| 1310 | - } else { |
|
| 1311 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
| 1312 | - } |
|
| 1313 | - if ($validation_errors_on_this_subsection) { |
|
| 1314 | - $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
| 1315 | - } |
|
| 1316 | - } |
|
| 1317 | - return $validation_errors; |
|
| 1318 | - } |
|
| 1319 | - |
|
| 1320 | - |
|
| 1321 | - |
|
| 1322 | - /** |
|
| 1323 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 1324 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 1325 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
| 1326 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 1327 | - * which will be returned. |
|
| 1328 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 1329 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 1330 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 1331 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 1332 | - * Etc |
|
| 1333 | - * |
|
| 1334 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 1335 | - * @return EE_Form_Section_Base |
|
| 1336 | - */ |
|
| 1337 | - public function find_section_from_path($form_section_path) |
|
| 1338 | - { |
|
| 1339 | - //check if we can find the input from purely going straight up the tree |
|
| 1340 | - $input = parent::find_section_from_path($form_section_path); |
|
| 1341 | - if ($input instanceof EE_Form_Section_Base) { |
|
| 1342 | - return $input; |
|
| 1343 | - } |
|
| 1344 | - $next_slash_pos = strpos($form_section_path, '/'); |
|
| 1345 | - if ($next_slash_pos !== false) { |
|
| 1346 | - $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
| 1347 | - $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
| 1348 | - } else { |
|
| 1349 | - $child_section_name = $form_section_path; |
|
| 1350 | - $subpath = ''; |
|
| 1351 | - } |
|
| 1352 | - $child_section = $this->get_subsection($child_section_name); |
|
| 1353 | - if ($child_section instanceof EE_Form_Section_Base) { |
|
| 1354 | - return $child_section->find_section_from_path($subpath); |
|
| 1355 | - } else { |
|
| 1356 | - return null; |
|
| 1357 | - } |
|
| 1358 | - } |
|
| 16 | + const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * Subsections |
|
| 20 | + * |
|
| 21 | + * @var EE_Form_Section_Validatable[] |
|
| 22 | + */ |
|
| 23 | + protected $_subsections = array(); |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Strategy for laying out the form |
|
| 27 | + * |
|
| 28 | + * @var EE_Form_Section_Layout_Base |
|
| 29 | + */ |
|
| 30 | + protected $_layout_strategy; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Whether or not this form has received and validated a form submission yet |
|
| 34 | + * |
|
| 35 | + * @var boolean |
|
| 36 | + */ |
|
| 37 | + protected $_received_submission = false; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * message displayed to users upon successful form submission |
|
| 41 | + * |
|
| 42 | + * @var string |
|
| 43 | + */ |
|
| 44 | + protected $_form_submission_success_message = ''; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * message displayed to users upon unsuccessful form submission |
|
| 48 | + * |
|
| 49 | + * @var string |
|
| 50 | + */ |
|
| 51 | + protected $_form_submission_error_message = ''; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Stores all the data that will localized for form validation |
|
| 55 | + * |
|
| 56 | + * @var array |
|
| 57 | + */ |
|
| 58 | + static protected $_js_localization = array(); |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * whether or not the form's localized validation JS vars have been set |
|
| 62 | + * |
|
| 63 | + * @type boolean |
|
| 64 | + */ |
|
| 65 | + static protected $_scripts_localized = false; |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * when constructing a proper form section, calls _construct_finalize on children |
|
| 71 | + * so that they know who their parent is, and what name they've been given. |
|
| 72 | + * |
|
| 73 | + * @param array $options_array { |
|
| 74 | + * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
| 75 | + * @type $include string[] numerically-indexed where values are section names to be included, |
|
| 76 | + * and in that order. This is handy if you want |
|
| 77 | + * the subsections to be ordered differently than the default, and if you override |
|
| 78 | + * which fields are shown |
|
| 79 | + * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
| 80 | + * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
| 81 | + * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
| 82 | + * items from that list of inclusions) |
|
| 83 | + * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
| 84 | + * } @see EE_Form_Section_Validatable::__construct() |
|
| 85 | + * @throws \EE_Error |
|
| 86 | + */ |
|
| 87 | + public function __construct($options_array = array()) |
|
| 88 | + { |
|
| 89 | + $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
| 90 | + $this); |
|
| 91 | + //call parent first, as it may be setting the name |
|
| 92 | + parent::__construct($options_array); |
|
| 93 | + //if they've included subsections in the constructor, add them now |
|
| 94 | + if (isset($options_array['include'])) { |
|
| 95 | + //we are going to make sure we ONLY have those subsections to include |
|
| 96 | + //AND we are going to make sure they're in that specified order |
|
| 97 | + $reordered_subsections = array(); |
|
| 98 | + foreach ($options_array['include'] as $input_name) { |
|
| 99 | + if (isset($this->_subsections[$input_name])) { |
|
| 100 | + $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + $this->_subsections = $reordered_subsections; |
|
| 104 | + } |
|
| 105 | + if (isset($options_array['exclude'])) { |
|
| 106 | + $exclude = $options_array['exclude']; |
|
| 107 | + $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
| 108 | + } |
|
| 109 | + if (isset($options_array['layout_strategy'])) { |
|
| 110 | + $this->_layout_strategy = $options_array['layout_strategy']; |
|
| 111 | + } |
|
| 112 | + if ( ! $this->_layout_strategy) { |
|
| 113 | + $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
| 114 | + } |
|
| 115 | + $this->_layout_strategy->_construct_finalize($this); |
|
| 116 | + //ok so we are definitely going to want the forms JS, |
|
| 117 | + //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
| 118 | + if (did_action('wp_enqueue_scripts') |
|
| 119 | + || did_action('admin_enqueue_scripts') |
|
| 120 | + ) { |
|
| 121 | + //ok so they've constructed this object after when they should have. |
|
| 122 | + //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
| 123 | + \EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
| 124 | + } else { |
|
| 125 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 126 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 127 | + } |
|
| 128 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
| 129 | + if (isset($options_array['name'])) { |
|
| 130 | + $this->_construct_finalize(null, $options_array['name']); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Finishes construction given the parent form section and this form section's name |
|
| 138 | + * |
|
| 139 | + * @param EE_Form_Section_Proper $parent_form_section |
|
| 140 | + * @param string $name |
|
| 141 | + * @throws \EE_Error |
|
| 142 | + */ |
|
| 143 | + public function _construct_finalize($parent_form_section, $name) |
|
| 144 | + { |
|
| 145 | + parent::_construct_finalize($parent_form_section, $name); |
|
| 146 | + $this->_set_default_name_if_empty(); |
|
| 147 | + $this->_set_default_html_id_if_empty(); |
|
| 148 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
| 149 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
| 150 | + $subsection->_construct_finalize($this, $subsection_name); |
|
| 151 | + } else { |
|
| 152 | + throw new EE_Error( |
|
| 153 | + sprintf( |
|
| 154 | + __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
| 155 | + 'event_espresso'), |
|
| 156 | + $subsection_name, |
|
| 157 | + get_class($this), |
|
| 158 | + $subsection ? get_class($subsection) : __('NULL', 'event_espresso') |
|
| 159 | + ) |
|
| 160 | + ); |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Gets the layout strategy for this form section |
|
| 170 | + * |
|
| 171 | + * @return EE_Form_Section_Layout_Base |
|
| 172 | + */ |
|
| 173 | + public function get_layout_strategy() |
|
| 174 | + { |
|
| 175 | + return $this->_layout_strategy; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Gets the HTML for a single input for this form section according |
|
| 182 | + * to the layout strategy |
|
| 183 | + * |
|
| 184 | + * @param EE_Form_Input_Base $input |
|
| 185 | + * @return string |
|
| 186 | + */ |
|
| 187 | + public function get_html_for_input($input) |
|
| 188 | + { |
|
| 189 | + return $this->_layout_strategy->layout_input($input); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * was_submitted - checks if form inputs are present in request data |
|
| 196 | + * Basically an alias for form_data_present_in() (which is used by both |
|
| 197 | + * proper form sections and form inputs) |
|
| 198 | + * |
|
| 199 | + * @param null $form_data |
|
| 200 | + * @return boolean |
|
| 201 | + */ |
|
| 202 | + public function was_submitted($form_data = null) |
|
| 203 | + { |
|
| 204 | + return $this->form_data_present_in($form_data); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * After the form section is initially created, call this to sanitize the data in the submission |
|
| 211 | + * which relates to this form section, validate it, and set it as properties on the form. |
|
| 212 | + * |
|
| 213 | + * @param array|null $req_data should usually be $_POST (the default). |
|
| 214 | + * However, you CAN supply a different array. |
|
| 215 | + * Consider using set_defaults() instead however. |
|
| 216 | + * (If you rendered the form in the page using echo $form_x->get_html() |
|
| 217 | + * the inputs will have the correct name in the request data for this function |
|
| 218 | + * to find them and populate the form with them. |
|
| 219 | + * If you have a flat form (with only input subsections), |
|
| 220 | + * you can supply a flat array where keys |
|
| 221 | + * are the form input names and values are their values) |
|
| 222 | + * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
| 223 | + * of course, to validate that data, and set errors on the invalid values. |
|
| 224 | + * But if the data has already been validated |
|
| 225 | + * (eg you validated the data then stored it in the DB) |
|
| 226 | + * you may want to skip this step. |
|
| 227 | + */ |
|
| 228 | + public function receive_form_submission($req_data = null, $validate = true) |
|
| 229 | + { |
|
| 230 | + $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this, |
|
| 231 | + $validate); |
|
| 232 | + if ($req_data === null) { |
|
| 233 | + $req_data = array_merge($_GET, $_POST); |
|
| 234 | + } |
|
| 235 | + $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data, |
|
| 236 | + $this); |
|
| 237 | + $this->_normalize($req_data); |
|
| 238 | + if ($validate) { |
|
| 239 | + $this->_validate(); |
|
| 240 | + //if it's invalid, we're going to want to re-display so remember what they submitted |
|
| 241 | + if ( ! $this->is_valid()) { |
|
| 242 | + $this->store_submitted_form_data_in_session(); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * caches the originally submitted input values in the session |
|
| 252 | + * so that they can be used to repopulate the form if it failed validation |
|
| 253 | + * |
|
| 254 | + * @return boolean whether or not the data was successfully stored in the session |
|
| 255 | + */ |
|
| 256 | + protected function store_submitted_form_data_in_session() |
|
| 257 | + { |
|
| 258 | + return EE_Registry::instance()->SSN->set_session_data( |
|
| 259 | + array( |
|
| 260 | + \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
| 261 | + ) |
|
| 262 | + ); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * retrieves the originally submitted input values in the session |
|
| 269 | + * so that they can be used to repopulate the form if it failed validation |
|
| 270 | + * |
|
| 271 | + * @return array |
|
| 272 | + */ |
|
| 273 | + protected function get_submitted_form_data_from_session() |
|
| 274 | + { |
|
| 275 | + $session = EE_Registry::instance()->SSN; |
|
| 276 | + if ($session instanceof EE_Session) { |
|
| 277 | + return $session->get_session_data( |
|
| 278 | + \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
| 279 | + ); |
|
| 280 | + } else { |
|
| 281 | + return array(); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * flushed the originally submitted input values from the session |
|
| 289 | + * |
|
| 290 | + * @return boolean whether or not the data was successfully removed from the session |
|
| 291 | + */ |
|
| 292 | + protected function flush_submitted_form_data_from_session() |
|
| 293 | + { |
|
| 294 | + return EE_Registry::instance()->SSN->reset_data( |
|
| 295 | + array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
| 296 | + ); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Populates this form and its subsections with data from the session. |
|
| 303 | + * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
| 304 | + * validation errors when displaying too) |
|
| 305 | + * Returns true if the form was populated from the session, false otherwise |
|
| 306 | + * |
|
| 307 | + * @return boolean |
|
| 308 | + */ |
|
| 309 | + public function populate_from_session() |
|
| 310 | + { |
|
| 311 | + $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
| 312 | + if (empty($form_data_in_session)) { |
|
| 313 | + return false; |
|
| 314 | + } |
|
| 315 | + $this->receive_form_submission($form_data_in_session); |
|
| 316 | + $this->flush_submitted_form_data_from_session(); |
|
| 317 | + if ($this->form_data_present_in($form_data_in_session)) { |
|
| 318 | + return true; |
|
| 319 | + } else { |
|
| 320 | + return false; |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Populates the default data for the form, given an array where keys are |
|
| 328 | + * the input names, and values are their values (preferably normalized to be their |
|
| 329 | + * proper PHP types, not all strings... although that should be ok too). |
|
| 330 | + * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
| 331 | + * the value being an array formatted in teh same way |
|
| 332 | + * |
|
| 333 | + * @param array $default_data |
|
| 334 | + */ |
|
| 335 | + public function populate_defaults($default_data) |
|
| 336 | + { |
|
| 337 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 338 | + if (isset($default_data[$subsection_name])) { |
|
| 339 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 340 | + $subsection->set_default($default_data[$subsection_name]); |
|
| 341 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 342 | + $subsection->populate_defaults($default_data[$subsection_name]); |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * returns true if subsection exists |
|
| 352 | + * |
|
| 353 | + * @param string $name |
|
| 354 | + * @return boolean |
|
| 355 | + */ |
|
| 356 | + public function subsection_exists($name) |
|
| 357 | + { |
|
| 358 | + return isset($this->_subsections[$name]) ? true : false; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Gets the subsection specified by its name |
|
| 365 | + * |
|
| 366 | + * @param string $name |
|
| 367 | + * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
| 368 | + * so that the inputs will be properly configured. |
|
| 369 | + * However, some client code may be ok |
|
| 370 | + * with construction finalize being called later |
|
| 371 | + * (realizing that the subsections' html names |
|
| 372 | + * might not be set yet, etc.) |
|
| 373 | + * @return EE_Form_Section_Base |
|
| 374 | + * @throws \EE_Error |
|
| 375 | + */ |
|
| 376 | + public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
| 377 | + { |
|
| 378 | + if ($require_construction_to_be_finalized) { |
|
| 379 | + $this->ensure_construct_finalized_called(); |
|
| 380 | + } |
|
| 381 | + return $this->subsection_exists($name) ? $this->_subsections[$name] : null; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * Gets all the validatable subsections of this form section |
|
| 388 | + * |
|
| 389 | + * @return EE_Form_Section_Validatable[] |
|
| 390 | + */ |
|
| 391 | + public function get_validatable_subsections() |
|
| 392 | + { |
|
| 393 | + $validatable_subsections = array(); |
|
| 394 | + foreach ($this->subsections() as $name => $obj) { |
|
| 395 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
| 396 | + $validatable_subsections[$name] = $obj; |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + return $validatable_subsections; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
| 406 | + * throw an EE_Error. |
|
| 407 | + * |
|
| 408 | + * @param string $name |
|
| 409 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 410 | + * leave this as TRUE so that the inputs will be properly |
|
| 411 | + * configured. However, some client code may be ok with |
|
| 412 | + * construction finalize being called later |
|
| 413 | + * (realizing that the subsections' html names might not be |
|
| 414 | + * set yet, etc.) |
|
| 415 | + * @return EE_Form_Input_Base |
|
| 416 | + * @throws EE_Error |
|
| 417 | + */ |
|
| 418 | + public function get_input($name, $require_construction_to_be_finalized = true) |
|
| 419 | + { |
|
| 420 | + $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
| 421 | + if ( ! $subsection instanceof EE_Form_Input_Base) { |
|
| 422 | + throw new EE_Error( |
|
| 423 | + sprintf( |
|
| 424 | + __( |
|
| 425 | + "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
| 426 | + 'event_espresso' |
|
| 427 | + ), |
|
| 428 | + $name, |
|
| 429 | + get_class($this), |
|
| 430 | + $subsection ? get_class($subsection) : __("NULL", 'event_espresso') |
|
| 431 | + ) |
|
| 432 | + ); |
|
| 433 | + } |
|
| 434 | + return $subsection; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * Like get_input(), gets the proper subsection of the form given the name, |
|
| 441 | + * otherwise throws an EE_Error |
|
| 442 | + * |
|
| 443 | + * @param string $name |
|
| 444 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 445 | + * leave this as TRUE so that the inputs will be properly |
|
| 446 | + * configured. However, some client code may be ok with |
|
| 447 | + * construction finalize being called later |
|
| 448 | + * (realizing that the subsections' html names might not be |
|
| 449 | + * set yet, etc.) |
|
| 450 | + * @return EE_Form_Section_Proper |
|
| 451 | + * @throws EE_Error |
|
| 452 | + */ |
|
| 453 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
| 454 | + { |
|
| 455 | + $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
| 456 | + if ( ! $subsection instanceof EE_Form_Section_Proper) { |
|
| 457 | + throw new EE_Error( |
|
| 458 | + sprintf( |
|
| 459 | + __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), |
|
| 460 | + $name, |
|
| 461 | + get_class($this) |
|
| 462 | + ) |
|
| 463 | + ); |
|
| 464 | + } |
|
| 465 | + return $subsection; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * Gets the value of the specified input. Should be called after receive_form_submission() |
|
| 472 | + * or populate_defaults() on the form, where the normalized value on the input is set. |
|
| 473 | + * |
|
| 474 | + * @param string $name |
|
| 475 | + * @return mixed depending on the input's type and its normalization strategy |
|
| 476 | + * @throws \EE_Error |
|
| 477 | + */ |
|
| 478 | + public function get_input_value($name) |
|
| 479 | + { |
|
| 480 | + $input = $this->get_input($name); |
|
| 481 | + return $input->normalized_value(); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * Checks if this form section itself is valid, and then checks its subsections |
|
| 488 | + * |
|
| 489 | + * @throws EE_Error |
|
| 490 | + * @return boolean |
|
| 491 | + */ |
|
| 492 | + public function is_valid() |
|
| 493 | + { |
|
| 494 | + if ( ! $this->has_received_submission()) { |
|
| 495 | + throw new EE_Error( |
|
| 496 | + sprintf( |
|
| 497 | + __( |
|
| 498 | + "You cannot check if a form is valid before receiving the form submission using receive_form_submission", |
|
| 499 | + "event_espresso" |
|
| 500 | + ) |
|
| 501 | + ) |
|
| 502 | + ); |
|
| 503 | + } |
|
| 504 | + if ( ! parent::is_valid()) { |
|
| 505 | + return false; |
|
| 506 | + } |
|
| 507 | + // ok so no general errors to this entire form section. |
|
| 508 | + // so let's check the subsections, but only set errors if that hasn't been done yet |
|
| 509 | + $set_submission_errors = $this->submission_error_message() === '' ? true : false; |
|
| 510 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 511 | + if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
| 512 | + if ($set_submission_errors) { |
|
| 513 | + $this->set_submission_error_message($subsection->get_validation_error_string()); |
|
| 514 | + } |
|
| 515 | + return false; |
|
| 516 | + } |
|
| 517 | + } |
|
| 518 | + return true; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * gets teh default name of this form section if none is specified |
|
| 525 | + * |
|
| 526 | + * @return string |
|
| 527 | + */ |
|
| 528 | + protected function _set_default_name_if_empty() |
|
| 529 | + { |
|
| 530 | + if ( ! $this->_name) { |
|
| 531 | + $classname = get_class($this); |
|
| 532 | + $default_name = str_replace("EE_", "", $classname); |
|
| 533 | + $this->_name = $default_name; |
|
| 534 | + } |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * Returns the JS for validating the form (and subsections) inside script tags. |
|
| 541 | + * Also returns the HTML for the form, except for the form opening and closing tags |
|
| 542 | + * (as the form section doesn't know where you necessarily want to send the information to), |
|
| 543 | + * and except for a submit button. |
|
| 544 | + * |
|
| 545 | + * @deprecated since 4.9.0. You should instead call enqueue_js during the "wp_enqueue_scripts" |
|
| 546 | + * and get_html when you are about to display the form. |
|
| 547 | + * @throws \EE_Error |
|
| 548 | + */ |
|
| 549 | + public function get_html_and_js() |
|
| 550 | + { |
|
| 551 | + //no doing_it_wrong yet because we ourselves are still doing it wrong... |
|
| 552 | + //and theoretically this CAN be used properly, provided its used during "wp_enqueue_scripts" |
|
| 553 | + $this->enqueue_js(); |
|
| 554 | + return $this->get_html(); |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
| 561 | + * |
|
| 562 | + * @param bool $display_previously_submitted_data |
|
| 563 | + * @return string |
|
| 564 | + */ |
|
| 565 | + public function get_html($display_previously_submitted_data = true) |
|
| 566 | + { |
|
| 567 | + $this->ensure_construct_finalized_called(); |
|
| 568 | + if ($display_previously_submitted_data) { |
|
| 569 | + $this->populate_from_session(); |
|
| 570 | + } |
|
| 571 | + return $this->_layout_strategy->layout_form(); |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + |
|
| 575 | + |
|
| 576 | + /** |
|
| 577 | + * enqueues JS for the form |
|
| 578 | + * |
|
| 579 | + * @return string |
|
| 580 | + * @throws \EE_Error |
|
| 581 | + */ |
|
| 582 | + public function enqueue_js() |
|
| 583 | + { |
|
| 584 | + $this->_enqueue_and_localize_form_js(); |
|
| 585 | + foreach ($this->subsections() as $subsection) { |
|
| 586 | + $subsection->enqueue_js(); |
|
| 587 | + } |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
| 594 | + * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
| 595 | + * the wp_enqueue_scripts hook. |
|
| 596 | + * However, registering the form js and localizing it can happen when we |
|
| 597 | + * actually output the form (which is preferred, seeing how teh form's fields |
|
| 598 | + * could change until it's actually outputted) |
|
| 599 | + * |
|
| 600 | + * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
| 601 | + * to be triggered automatically or not |
|
| 602 | + * @return void |
|
| 603 | + */ |
|
| 604 | + public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
| 605 | + { |
|
| 606 | + add_filter('FHEE_load_jquery_validate', '__return_true'); |
|
| 607 | + wp_register_script( |
|
| 608 | + 'ee_form_section_validation', |
|
| 609 | + EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
| 610 | + array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
| 611 | + EVENT_ESPRESSO_VERSION, |
|
| 612 | + true |
|
| 613 | + ); |
|
| 614 | + wp_localize_script( |
|
| 615 | + 'ee_form_section_validation', |
|
| 616 | + 'ee_form_section_validation_init', |
|
| 617 | + array('init' => $init_form_validation_automatically ? true : false) |
|
| 618 | + ); |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + |
|
| 622 | + |
|
| 623 | + /** |
|
| 624 | + * gets the variables used by form_section_validation.js. |
|
| 625 | + * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
| 626 | + * but before the wordpress hook wp_loaded |
|
| 627 | + * |
|
| 628 | + * @throws \EE_Error |
|
| 629 | + */ |
|
| 630 | + public function _enqueue_and_localize_form_js() |
|
| 631 | + { |
|
| 632 | + $this->ensure_construct_finalized_called(); |
|
| 633 | + //actually, we don't want to localize just yet. There may be other forms on the page. |
|
| 634 | + //so we need to add our form section data to a static variable accessible by all form sections |
|
| 635 | + //and localize it just before the footer |
|
| 636 | + $this->localize_validation_rules(); |
|
| 637 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
| 638 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + |
|
| 642 | + |
|
| 643 | + /** |
|
| 644 | + * add our form section data to a static variable accessible by all form sections |
|
| 645 | + * |
|
| 646 | + * @param bool $return_for_subsection |
|
| 647 | + * @return void |
|
| 648 | + * @throws \EE_Error |
|
| 649 | + */ |
|
| 650 | + public function localize_validation_rules($return_for_subsection = false) |
|
| 651 | + { |
|
| 652 | + // we only want to localize vars ONCE for the entire form, |
|
| 653 | + // so if the form section doesn't have a parent, then it must be the top dog |
|
| 654 | + if ($return_for_subsection || ! $this->parent_section()) { |
|
| 655 | + EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
| 656 | + 'form_section_id' => $this->html_id(true), |
|
| 657 | + 'validation_rules' => $this->get_jquery_validation_rules(), |
|
| 658 | + 'other_data' => $this->get_other_js_data(), |
|
| 659 | + 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
| 660 | + ); |
|
| 661 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 662 | + } |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * Gets an array of extra data that will be useful for client-side javascript. |
|
| 669 | + * This is primarily data added by inputs and forms in addition to any |
|
| 670 | + * scripts they might enqueue |
|
| 671 | + * |
|
| 672 | + * @param array $form_other_js_data |
|
| 673 | + * @return array |
|
| 674 | + */ |
|
| 675 | + public function get_other_js_data($form_other_js_data = array()) |
|
| 676 | + { |
|
| 677 | + foreach ($this->subsections() as $subsection) { |
|
| 678 | + $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
| 679 | + } |
|
| 680 | + return $form_other_js_data; |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * Gets a flat array of inputs for this form section and its subsections. |
|
| 687 | + * Keys are their form names, and values are the inputs themselves |
|
| 688 | + * |
|
| 689 | + * @return EE_Form_Input_Base |
|
| 690 | + */ |
|
| 691 | + public function inputs_in_subsections() |
|
| 692 | + { |
|
| 693 | + $inputs = array(); |
|
| 694 | + foreach ($this->subsections() as $subsection) { |
|
| 695 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 696 | + $inputs[$subsection->html_name()] = $subsection; |
|
| 697 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 698 | + $inputs += $subsection->inputs_in_subsections(); |
|
| 699 | + } |
|
| 700 | + } |
|
| 701 | + return $inputs; |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + |
|
| 705 | + |
|
| 706 | + /** |
|
| 707 | + * Gets a flat array of all the validation errors. |
|
| 708 | + * Keys are html names (because those should be unique) |
|
| 709 | + * and values are a string of all their validation errors |
|
| 710 | + * |
|
| 711 | + * @return string[] |
|
| 712 | + */ |
|
| 713 | + public function subsection_validation_errors_by_html_name() |
|
| 714 | + { |
|
| 715 | + $inputs = $this->inputs(); |
|
| 716 | + $errors = array(); |
|
| 717 | + foreach ($inputs as $form_input) { |
|
| 718 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
| 719 | + $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
| 720 | + } |
|
| 721 | + } |
|
| 722 | + return $errors; |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + |
|
| 726 | + |
|
| 727 | + /** |
|
| 728 | + * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
| 729 | + * Should be setup by each form during the _enqueues_and_localize_form_js |
|
| 730 | + */ |
|
| 731 | + public static function localize_script_for_all_forms() |
|
| 732 | + { |
|
| 733 | + //allow inputs and stuff to hook in their JS and stuff here |
|
| 734 | + do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
| 735 | + EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
| 736 | + $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
| 737 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 738 | + : 'wp_default'; |
|
| 739 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 740 | + wp_enqueue_script('ee_form_section_validation'); |
|
| 741 | + wp_localize_script( |
|
| 742 | + 'ee_form_section_validation', |
|
| 743 | + 'ee_form_section_vars', |
|
| 744 | + EE_Form_Section_Proper::$_js_localization |
|
| 745 | + ); |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * ensure_scripts_localized |
|
| 752 | + */ |
|
| 753 | + public function ensure_scripts_localized() |
|
| 754 | + { |
|
| 755 | + if ( ! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 756 | + $this->_enqueue_and_localize_form_js(); |
|
| 757 | + } |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + |
|
| 761 | + |
|
| 762 | + /** |
|
| 763 | + * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
| 764 | + * is that the key here should be the same as the custom validation rule put in the JS file |
|
| 765 | + * |
|
| 766 | + * @return array keys are custom validation rules, and values are internationalized strings |
|
| 767 | + */ |
|
| 768 | + private static function _get_localized_error_messages() |
|
| 769 | + { |
|
| 770 | + return array( |
|
| 771 | + 'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"), |
|
| 772 | + 'regex' => __('Please check your input', 'event_espresso'), |
|
| 773 | + ); |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + |
|
| 777 | + |
|
| 778 | + /** |
|
| 779 | + * @return array |
|
| 780 | + */ |
|
| 781 | + public static function js_localization() |
|
| 782 | + { |
|
| 783 | + return self::$_js_localization; |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + |
|
| 787 | + |
|
| 788 | + /** |
|
| 789 | + * @return array |
|
| 790 | + */ |
|
| 791 | + public static function reset_js_localization() |
|
| 792 | + { |
|
| 793 | + self::$_js_localization = array(); |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + |
|
| 797 | + |
|
| 798 | + /** |
|
| 799 | + * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
| 800 | + * See parent function for more... |
|
| 801 | + * |
|
| 802 | + * @return array |
|
| 803 | + */ |
|
| 804 | + public function get_jquery_validation_rules() |
|
| 805 | + { |
|
| 806 | + $jquery_validation_rules = array(); |
|
| 807 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 808 | + $jquery_validation_rules = array_merge( |
|
| 809 | + $jquery_validation_rules, |
|
| 810 | + $subsection->get_jquery_validation_rules() |
|
| 811 | + ); |
|
| 812 | + } |
|
| 813 | + return $jquery_validation_rules; |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + |
|
| 817 | + |
|
| 818 | + /** |
|
| 819 | + * Sanitizes all the data and sets the sanitized value of each field |
|
| 820 | + * |
|
| 821 | + * @param array $req_data like $_POST |
|
| 822 | + * @return void |
|
| 823 | + */ |
|
| 824 | + protected function _normalize($req_data) |
|
| 825 | + { |
|
| 826 | + $this->_received_submission = true; |
|
| 827 | + $this->_validation_errors = array(); |
|
| 828 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 829 | + try { |
|
| 830 | + $subsection->_normalize($req_data); |
|
| 831 | + } catch (EE_Validation_Error $e) { |
|
| 832 | + $subsection->add_validation_error($e); |
|
| 833 | + } |
|
| 834 | + } |
|
| 835 | + } |
|
| 836 | + |
|
| 837 | + |
|
| 838 | + |
|
| 839 | + /** |
|
| 840 | + * Performs validation on this form section and its subsections. |
|
| 841 | + * For each subsection, |
|
| 842 | + * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
| 843 | + * and passes it the subsection, then calls _validate on that subsection. |
|
| 844 | + * If you need to perform validation on the form as a whole (considering multiple) |
|
| 845 | + * you would be best to override this _validate method, |
|
| 846 | + * calling parent::_validate() first. |
|
| 847 | + */ |
|
| 848 | + protected function _validate() |
|
| 849 | + { |
|
| 850 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
| 851 | + if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 852 | + call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 853 | + } |
|
| 854 | + $subsection->_validate(); |
|
| 855 | + } |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + |
|
| 859 | + |
|
| 860 | + /** |
|
| 861 | + * Gets all the validated inputs for the form section |
|
| 862 | + * |
|
| 863 | + * @return array |
|
| 864 | + */ |
|
| 865 | + public function valid_data() |
|
| 866 | + { |
|
| 867 | + $inputs = array(); |
|
| 868 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 869 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 870 | + $inputs[$subsection_name] = $subsection->valid_data(); |
|
| 871 | + } else if ($subsection instanceof EE_Form_Input_Base) { |
|
| 872 | + $inputs[$subsection_name] = $subsection->normalized_value(); |
|
| 873 | + } |
|
| 874 | + } |
|
| 875 | + return $inputs; |
|
| 876 | + } |
|
| 877 | + |
|
| 878 | + |
|
| 879 | + |
|
| 880 | + /** |
|
| 881 | + * Gets all the inputs on this form section |
|
| 882 | + * |
|
| 883 | + * @return EE_Form_Input_Base[] |
|
| 884 | + */ |
|
| 885 | + public function inputs() |
|
| 886 | + { |
|
| 887 | + $inputs = array(); |
|
| 888 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 889 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 890 | + $inputs[$subsection_name] = $subsection; |
|
| 891 | + } |
|
| 892 | + } |
|
| 893 | + return $inputs; |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + |
|
| 897 | + |
|
| 898 | + /** |
|
| 899 | + * Gets all the subsections which are a proper form |
|
| 900 | + * |
|
| 901 | + * @return EE_Form_Section_Proper[] |
|
| 902 | + */ |
|
| 903 | + public function subforms() |
|
| 904 | + { |
|
| 905 | + $form_sections = array(); |
|
| 906 | + foreach ($this->subsections() as $name => $obj) { |
|
| 907 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
| 908 | + $form_sections[$name] = $obj; |
|
| 909 | + } |
|
| 910 | + } |
|
| 911 | + return $form_sections; |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + |
|
| 915 | + |
|
| 916 | + /** |
|
| 917 | + * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
| 918 | + * Consider using inputs() or subforms() |
|
| 919 | + * if you only want form inputs or proper form sections. |
|
| 920 | + * |
|
| 921 | + * @return EE_Form_Section_Proper[] |
|
| 922 | + */ |
|
| 923 | + public function subsections() |
|
| 924 | + { |
|
| 925 | + $this->ensure_construct_finalized_called(); |
|
| 926 | + return $this->_subsections; |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + |
|
| 930 | + |
|
| 931 | + /** |
|
| 932 | + * Returns a simple array where keys are input names, and values are their normalized |
|
| 933 | + * values. (Similar to calling get_input_value on inputs) |
|
| 934 | + * |
|
| 935 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 936 | + * or just this forms' direct children inputs |
|
| 937 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 938 | + * or allow multidimensional array |
|
| 939 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 940 | + * with array keys being input names |
|
| 941 | + * (regardless of whether they are from a subsection or not), |
|
| 942 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 943 | + * where keys are always subsection names and values are either |
|
| 944 | + * the input's normalized value, or an array like the top-level array |
|
| 945 | + */ |
|
| 946 | + public function input_values($include_subform_inputs = false, $flatten = false) |
|
| 947 | + { |
|
| 948 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
| 955 | + * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
| 956 | + * is not necessarily the value we want to display to users. This creates an array |
|
| 957 | + * where keys are the input names, and values are their display values |
|
| 958 | + * |
|
| 959 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 960 | + * or just this forms' direct children inputs |
|
| 961 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 962 | + * or allow multidimensional array |
|
| 963 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 964 | + * with array keys being input names |
|
| 965 | + * (regardless of whether they are from a subsection or not), |
|
| 966 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 967 | + * where keys are always subsection names and values are either |
|
| 968 | + * the input's normalized value, or an array like the top-level array |
|
| 969 | + */ |
|
| 970 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
| 971 | + { |
|
| 972 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + |
|
| 976 | + |
|
| 977 | + /** |
|
| 978 | + * Gets the input values from the form |
|
| 979 | + * |
|
| 980 | + * @param boolean $pretty Whether to retrieve the pretty value, |
|
| 981 | + * or just the normalized value |
|
| 982 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 983 | + * or just this forms' direct children inputs |
|
| 984 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 985 | + * or allow multidimensional array |
|
| 986 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
| 987 | + * input names (regardless of whether they are from a subsection or not), |
|
| 988 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 989 | + * where keys are always subsection names and values are either |
|
| 990 | + * the input's normalized value, or an array like the top-level array |
|
| 991 | + */ |
|
| 992 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
| 993 | + { |
|
| 994 | + $input_values = array(); |
|
| 995 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 996 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 997 | + $input_values[$subsection_name] = $pretty |
|
| 998 | + ? $subsection->pretty_value() |
|
| 999 | + : $subsection->normalized_value(); |
|
| 1000 | + } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
| 1001 | + $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten); |
|
| 1002 | + if ($flatten) { |
|
| 1003 | + $input_values = array_merge($input_values, $subform_input_values); |
|
| 1004 | + } else { |
|
| 1005 | + $input_values[$subsection_name] = $subform_input_values; |
|
| 1006 | + } |
|
| 1007 | + } |
|
| 1008 | + } |
|
| 1009 | + return $input_values; |
|
| 1010 | + } |
|
| 1011 | + |
|
| 1012 | + |
|
| 1013 | + |
|
| 1014 | + /** |
|
| 1015 | + * Gets the originally submitted input values from the form |
|
| 1016 | + * |
|
| 1017 | + * @param boolean $include_subforms Whether to include inputs from subforms, |
|
| 1018 | + * or just this forms' direct children inputs |
|
| 1019 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1020 | + * with array keys being input names |
|
| 1021 | + * (regardless of whether they are from a subsection or not), |
|
| 1022 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1023 | + * where keys are always subsection names and values are either |
|
| 1024 | + * the input's normalized value, or an array like the top-level array |
|
| 1025 | + */ |
|
| 1026 | + public function submitted_values($include_subforms = false) |
|
| 1027 | + { |
|
| 1028 | + $submitted_values = array(); |
|
| 1029 | + foreach ($this->subsections() as $subsection) { |
|
| 1030 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1031 | + // is this input part of an array of inputs? |
|
| 1032 | + if (strpos($subsection->html_name(), '[') !== false) { |
|
| 1033 | + $full_input_name = \EEH_Array::convert_array_values_to_keys( |
|
| 1034 | + explode('[', str_replace(']', '', $subsection->html_name())), |
|
| 1035 | + $subsection->raw_value() |
|
| 1036 | + ); |
|
| 1037 | + $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
| 1038 | + } else { |
|
| 1039 | + $submitted_values[$subsection->html_name()] = $subsection->raw_value(); |
|
| 1040 | + } |
|
| 1041 | + } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
| 1042 | + $subform_input_values = $subsection->submitted_values($include_subforms); |
|
| 1043 | + $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
| 1044 | + } |
|
| 1045 | + } |
|
| 1046 | + return $submitted_values; |
|
| 1047 | + } |
|
| 1048 | + |
|
| 1049 | + |
|
| 1050 | + |
|
| 1051 | + /** |
|
| 1052 | + * Indicates whether or not this form has received a submission yet |
|
| 1053 | + * (ie, had receive_form_submission called on it yet) |
|
| 1054 | + * |
|
| 1055 | + * @return boolean |
|
| 1056 | + * @throws \EE_Error |
|
| 1057 | + */ |
|
| 1058 | + public function has_received_submission() |
|
| 1059 | + { |
|
| 1060 | + $this->ensure_construct_finalized_called(); |
|
| 1061 | + return $this->_received_submission; |
|
| 1062 | + } |
|
| 1063 | + |
|
| 1064 | + |
|
| 1065 | + |
|
| 1066 | + /** |
|
| 1067 | + * Equivalent to passing 'exclude' in the constructor's options array. |
|
| 1068 | + * Removes the listed inputs from the form |
|
| 1069 | + * |
|
| 1070 | + * @param array $inputs_to_exclude values are the input names |
|
| 1071 | + * @return void |
|
| 1072 | + */ |
|
| 1073 | + public function exclude(array $inputs_to_exclude = array()) |
|
| 1074 | + { |
|
| 1075 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
| 1076 | + unset($this->_subsections[$input_to_exclude_name]); |
|
| 1077 | + } |
|
| 1078 | + } |
|
| 1079 | + |
|
| 1080 | + |
|
| 1081 | + |
|
| 1082 | + /** |
|
| 1083 | + * @param array $inputs_to_hide |
|
| 1084 | + * @throws \EE_Error |
|
| 1085 | + */ |
|
| 1086 | + public function hide($inputs_to_hide = array()) |
|
| 1087 | + { |
|
| 1088 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
| 1089 | + $input = $this->get_input($input_to_hide); |
|
| 1090 | + $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
| 1091 | + } |
|
| 1092 | + } |
|
| 1093 | + |
|
| 1094 | + |
|
| 1095 | + |
|
| 1096 | + /** |
|
| 1097 | + * add_subsections |
|
| 1098 | + * Adds the listed subsections to the form section. |
|
| 1099 | + * If $subsection_name_to_target is provided, |
|
| 1100 | + * then new subsections are added before or after that subsection, |
|
| 1101 | + * otherwise to the start or end of the entire subsections array. |
|
| 1102 | + * |
|
| 1103 | + * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
| 1104 | + * where keys are their names |
|
| 1105 | + * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
| 1106 | + * should be added before or after |
|
| 1107 | + * IF $subsection_name_to_target is null, |
|
| 1108 | + * then $new_subsections will be added to |
|
| 1109 | + * the beginning or end of the entire subsections array |
|
| 1110 | + * @param boolean $add_before whether to add $new_subsections, before or after |
|
| 1111 | + * $subsection_name_to_target, |
|
| 1112 | + * or if $subsection_name_to_target is null, |
|
| 1113 | + * before or after entire subsections array |
|
| 1114 | + * @return void |
|
| 1115 | + * @throws \EE_Error |
|
| 1116 | + */ |
|
| 1117 | + public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
| 1118 | + { |
|
| 1119 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
| 1120 | + if ( ! $subsection instanceof EE_Form_Section_Base) { |
|
| 1121 | + EE_Error::add_error( |
|
| 1122 | + sprintf( |
|
| 1123 | + __( |
|
| 1124 | + "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
| 1125 | + "event_espresso" |
|
| 1126 | + ), |
|
| 1127 | + get_class($subsection), |
|
| 1128 | + $subsection_name, |
|
| 1129 | + $this->name() |
|
| 1130 | + ) |
|
| 1131 | + ); |
|
| 1132 | + unset($new_subsections[$subsection_name]); |
|
| 1133 | + } |
|
| 1134 | + } |
|
| 1135 | + $this->_subsections = EEH_Array::insert_into_array( |
|
| 1136 | + $this->_subsections, |
|
| 1137 | + $new_subsections, |
|
| 1138 | + $subsection_name_to_target, |
|
| 1139 | + $add_before |
|
| 1140 | + ); |
|
| 1141 | + if ($this->_construction_finalized) { |
|
| 1142 | + foreach ($this->_subsections as $name => $subsection) { |
|
| 1143 | + $subsection->_construct_finalize($this, $name); |
|
| 1144 | + } |
|
| 1145 | + } |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + |
|
| 1149 | + |
|
| 1150 | + /** |
|
| 1151 | + * Just gets all validatable subsections to clean their sensitive data |
|
| 1152 | + */ |
|
| 1153 | + public function clean_sensitive_data() |
|
| 1154 | + { |
|
| 1155 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1156 | + $subsection->clean_sensitive_data(); |
|
| 1157 | + } |
|
| 1158 | + } |
|
| 1159 | + |
|
| 1160 | + |
|
| 1161 | + |
|
| 1162 | + /** |
|
| 1163 | + * @param string $form_submission_error_message |
|
| 1164 | + */ |
|
| 1165 | + public function set_submission_error_message($form_submission_error_message = '') |
|
| 1166 | + { |
|
| 1167 | + $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
| 1168 | + ? $form_submission_error_message |
|
| 1169 | + : __('Form submission failed due to errors', 'event_espresso'); |
|
| 1170 | + } |
|
| 1171 | + |
|
| 1172 | + |
|
| 1173 | + |
|
| 1174 | + /** |
|
| 1175 | + * @return string |
|
| 1176 | + */ |
|
| 1177 | + public function submission_error_message() |
|
| 1178 | + { |
|
| 1179 | + return $this->_form_submission_error_message; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + |
|
| 1183 | + |
|
| 1184 | + /** |
|
| 1185 | + * @param string $form_submission_success_message |
|
| 1186 | + */ |
|
| 1187 | + public function set_submission_success_message($form_submission_success_message) |
|
| 1188 | + { |
|
| 1189 | + $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
| 1190 | + ? $form_submission_success_message |
|
| 1191 | + : __('Form submitted successfully', 'event_espresso'); |
|
| 1192 | + } |
|
| 1193 | + |
|
| 1194 | + |
|
| 1195 | + |
|
| 1196 | + /** |
|
| 1197 | + * @return string |
|
| 1198 | + */ |
|
| 1199 | + public function submission_success_message() |
|
| 1200 | + { |
|
| 1201 | + return $this->_form_submission_success_message; |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + |
|
| 1205 | + |
|
| 1206 | + /** |
|
| 1207 | + * Returns the prefix that should be used on child of this form section for |
|
| 1208 | + * their html names. If this form section itself has a parent, prepends ITS |
|
| 1209 | + * prefix onto this form section's prefix. Used primarily by |
|
| 1210 | + * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 1211 | + * |
|
| 1212 | + * @return string |
|
| 1213 | + * @throws \EE_Error |
|
| 1214 | + */ |
|
| 1215 | + public function html_name_prefix() |
|
| 1216 | + { |
|
| 1217 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
| 1218 | + return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1219 | + } else { |
|
| 1220 | + return $this->name(); |
|
| 1221 | + } |
|
| 1222 | + } |
|
| 1223 | + |
|
| 1224 | + |
|
| 1225 | + |
|
| 1226 | + /** |
|
| 1227 | + * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 1228 | + * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 1229 | + * was set, which is probably nothing, or the classname) |
|
| 1230 | + * |
|
| 1231 | + * @return string |
|
| 1232 | + * @throws \EE_Error |
|
| 1233 | + */ |
|
| 1234 | + public function name() |
|
| 1235 | + { |
|
| 1236 | + $this->ensure_construct_finalized_called(); |
|
| 1237 | + return parent::name(); |
|
| 1238 | + } |
|
| 1239 | + |
|
| 1240 | + |
|
| 1241 | + |
|
| 1242 | + /** |
|
| 1243 | + * @return EE_Form_Section_Proper |
|
| 1244 | + * @throws \EE_Error |
|
| 1245 | + */ |
|
| 1246 | + public function parent_section() |
|
| 1247 | + { |
|
| 1248 | + $this->ensure_construct_finalized_called(); |
|
| 1249 | + return parent::parent_section(); |
|
| 1250 | + } |
|
| 1251 | + |
|
| 1252 | + |
|
| 1253 | + |
|
| 1254 | + /** |
|
| 1255 | + * make sure construction finalized was called, otherwise children might not be ready |
|
| 1256 | + * |
|
| 1257 | + * @return void |
|
| 1258 | + * @throws \EE_Error |
|
| 1259 | + */ |
|
| 1260 | + public function ensure_construct_finalized_called() |
|
| 1261 | + { |
|
| 1262 | + if ( ! $this->_construction_finalized) { |
|
| 1263 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 1264 | + } |
|
| 1265 | + } |
|
| 1266 | + |
|
| 1267 | + |
|
| 1268 | + |
|
| 1269 | + /** |
|
| 1270 | + * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 1271 | + * are in teh form data. If any are found, returns true. Else false |
|
| 1272 | + * |
|
| 1273 | + * @param array $req_data |
|
| 1274 | + * @return boolean |
|
| 1275 | + */ |
|
| 1276 | + public function form_data_present_in($req_data = null) |
|
| 1277 | + { |
|
| 1278 | + if ($req_data === null) { |
|
| 1279 | + $req_data = $_POST; |
|
| 1280 | + } |
|
| 1281 | + foreach ($this->subsections() as $subsection) { |
|
| 1282 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1283 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 1284 | + return true; |
|
| 1285 | + } |
|
| 1286 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1287 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 1288 | + return true; |
|
| 1289 | + } |
|
| 1290 | + } |
|
| 1291 | + } |
|
| 1292 | + return false; |
|
| 1293 | + } |
|
| 1294 | + |
|
| 1295 | + |
|
| 1296 | + |
|
| 1297 | + /** |
|
| 1298 | + * Gets validation errors for this form section and subsections |
|
| 1299 | + * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 1300 | + * gets the validation errors for ALL subsection |
|
| 1301 | + * |
|
| 1302 | + * @return EE_Validation_Error[] |
|
| 1303 | + */ |
|
| 1304 | + public function get_validation_errors_accumulated() |
|
| 1305 | + { |
|
| 1306 | + $validation_errors = $this->get_validation_errors(); |
|
| 1307 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1308 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1309 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
| 1310 | + } else { |
|
| 1311 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
| 1312 | + } |
|
| 1313 | + if ($validation_errors_on_this_subsection) { |
|
| 1314 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
| 1315 | + } |
|
| 1316 | + } |
|
| 1317 | + return $validation_errors; |
|
| 1318 | + } |
|
| 1319 | + |
|
| 1320 | + |
|
| 1321 | + |
|
| 1322 | + /** |
|
| 1323 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 1324 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 1325 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
| 1326 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 1327 | + * which will be returned. |
|
| 1328 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 1329 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 1330 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 1331 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 1332 | + * Etc |
|
| 1333 | + * |
|
| 1334 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 1335 | + * @return EE_Form_Section_Base |
|
| 1336 | + */ |
|
| 1337 | + public function find_section_from_path($form_section_path) |
|
| 1338 | + { |
|
| 1339 | + //check if we can find the input from purely going straight up the tree |
|
| 1340 | + $input = parent::find_section_from_path($form_section_path); |
|
| 1341 | + if ($input instanceof EE_Form_Section_Base) { |
|
| 1342 | + return $input; |
|
| 1343 | + } |
|
| 1344 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
| 1345 | + if ($next_slash_pos !== false) { |
|
| 1346 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
| 1347 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
| 1348 | + } else { |
|
| 1349 | + $child_section_name = $form_section_path; |
|
| 1350 | + $subpath = ''; |
|
| 1351 | + } |
|
| 1352 | + $child_section = $this->get_subsection($child_section_name); |
|
| 1353 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
| 1354 | + return $child_section->find_section_from_path($subpath); |
|
| 1355 | + } else { |
|
| 1356 | + return null; |
|
| 1357 | + } |
|
| 1358 | + } |
|
| 1359 | 1359 | |
| 1360 | 1360 | } |
| 1361 | 1361 | |
@@ -1430,7 +1430,7 @@ discard block |
||
| 1430 | 1430 | * This just returns whatever is set as the _event object property |
| 1431 | 1431 | * //todo this will become obsolete once the models are in place |
| 1432 | 1432 | * |
| 1433 | - * @return object |
|
| 1433 | + * @return EE_Event |
|
| 1434 | 1434 | */ |
| 1435 | 1435 | public function get_event_object() |
| 1436 | 1436 | { |
@@ -2375,7 +2375,7 @@ discard block |
||
| 2375 | 2375 | |
| 2376 | 2376 | |
| 2377 | 2377 | /** |
| 2378 | - * @return mixed |
|
| 2378 | + * @return string |
|
| 2379 | 2379 | */ |
| 2380 | 2380 | protected function _category_details_content() |
| 2381 | 2381 | { |
@@ -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 | |
@@ -16,2536 +16,2536 @@ discard block |
||
| 16 | 16 | class Events_Admin_Page extends EE_Admin_Page_CPT |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * This will hold the event object for event_details screen. |
|
| 21 | - * |
|
| 22 | - * @access protected |
|
| 23 | - * @var EE_Event $_event |
|
| 24 | - */ |
|
| 25 | - protected $_event; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * This will hold the category object for category_details screen. |
|
| 30 | - * |
|
| 31 | - * @var stdClass $_category |
|
| 32 | - */ |
|
| 33 | - protected $_category; |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * This will hold the event model instance |
|
| 38 | - * |
|
| 39 | - * @var EEM_Event $_event_model |
|
| 40 | - */ |
|
| 41 | - protected $_event_model; |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var EE_Event |
|
| 46 | - */ |
|
| 47 | - protected $_cpt_model_obj = false; |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - protected function _init_page_props() |
|
| 51 | - { |
|
| 52 | - $this->page_slug = EVENTS_PG_SLUG; |
|
| 53 | - $this->page_label = EVENTS_LABEL; |
|
| 54 | - $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 55 | - $this->_admin_base_path = EVENTS_ADMIN; |
|
| 56 | - $this->_cpt_model_names = array( |
|
| 57 | - 'create_new' => 'EEM_Event', |
|
| 58 | - 'edit' => 'EEM_Event', |
|
| 59 | - ); |
|
| 60 | - $this->_cpt_edit_routes = array( |
|
| 61 | - 'espresso_events' => 'edit', |
|
| 62 | - ); |
|
| 63 | - add_action( |
|
| 64 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 65 | - array($this, 'verify_event_edit') |
|
| 66 | - ); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - protected function _ajax_hooks() |
|
| 71 | - { |
|
| 72 | - //todo: all hooks for events ajax goes in here. |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - protected function _define_page_props() |
|
| 77 | - { |
|
| 78 | - $this->_admin_page_title = EVENTS_LABEL; |
|
| 79 | - $this->_labels = array( |
|
| 80 | - 'buttons' => array( |
|
| 81 | - 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 82 | - 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 83 | - 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 84 | - 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 85 | - 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 86 | - 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 87 | - ), |
|
| 88 | - 'editor_title' => array( |
|
| 89 | - 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 90 | - ), |
|
| 91 | - 'publishbox' => array( |
|
| 92 | - 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 93 | - 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 94 | - 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 95 | - 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 96 | - 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 97 | - ), |
|
| 98 | - ); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - protected function _set_page_routes() |
|
| 103 | - { |
|
| 104 | - //load formatter helper |
|
| 105 | - //load field generator helper |
|
| 106 | - //is there a evt_id in the request? |
|
| 107 | - $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 108 | - ? $this->_req_data['EVT_ID'] : 0; |
|
| 109 | - $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 110 | - $this->_page_routes = array( |
|
| 111 | - 'default' => array( |
|
| 112 | - 'func' => '_events_overview_list_table', |
|
| 113 | - 'capability' => 'ee_read_events', |
|
| 114 | - ), |
|
| 115 | - 'create_new' => array( |
|
| 116 | - 'func' => '_create_new_cpt_item', |
|
| 117 | - 'capability' => 'ee_edit_events', |
|
| 118 | - ), |
|
| 119 | - 'edit' => array( |
|
| 120 | - 'func' => '_edit_cpt_item', |
|
| 121 | - 'capability' => 'ee_edit_event', |
|
| 122 | - 'obj_id' => $evt_id, |
|
| 123 | - ), |
|
| 124 | - 'copy_event' => array( |
|
| 125 | - 'func' => '_copy_events', |
|
| 126 | - 'capability' => 'ee_edit_event', |
|
| 127 | - 'obj_id' => $evt_id, |
|
| 128 | - 'noheader' => true, |
|
| 129 | - ), |
|
| 130 | - 'trash_event' => array( |
|
| 131 | - 'func' => '_trash_or_restore_event', |
|
| 132 | - 'args' => array('event_status' => 'trash'), |
|
| 133 | - 'capability' => 'ee_delete_event', |
|
| 134 | - 'obj_id' => $evt_id, |
|
| 135 | - 'noheader' => true, |
|
| 136 | - ), |
|
| 137 | - 'trash_events' => array( |
|
| 138 | - 'func' => '_trash_or_restore_events', |
|
| 139 | - 'args' => array('event_status' => 'trash'), |
|
| 140 | - 'capability' => 'ee_delete_events', |
|
| 141 | - 'noheader' => true, |
|
| 142 | - ), |
|
| 143 | - 'restore_event' => array( |
|
| 144 | - 'func' => '_trash_or_restore_event', |
|
| 145 | - 'args' => array('event_status' => 'draft'), |
|
| 146 | - 'capability' => 'ee_delete_event', |
|
| 147 | - 'obj_id' => $evt_id, |
|
| 148 | - 'noheader' => true, |
|
| 149 | - ), |
|
| 150 | - 'restore_events' => array( |
|
| 151 | - 'func' => '_trash_or_restore_events', |
|
| 152 | - 'args' => array('event_status' => 'draft'), |
|
| 153 | - 'capability' => 'ee_delete_events', |
|
| 154 | - 'noheader' => true, |
|
| 155 | - ), |
|
| 156 | - 'delete_event' => array( |
|
| 157 | - 'func' => '_delete_event', |
|
| 158 | - 'capability' => 'ee_delete_event', |
|
| 159 | - 'obj_id' => $evt_id, |
|
| 160 | - 'noheader' => true, |
|
| 161 | - ), |
|
| 162 | - 'delete_events' => array( |
|
| 163 | - 'func' => '_delete_events', |
|
| 164 | - 'capability' => 'ee_delete_events', |
|
| 165 | - 'noheader' => true, |
|
| 166 | - ), |
|
| 167 | - 'view_report' => array( |
|
| 168 | - 'func' => '_view_report', |
|
| 169 | - 'capablity' => 'ee_edit_events', |
|
| 170 | - ), |
|
| 171 | - 'default_event_settings' => array( |
|
| 172 | - 'func' => '_default_event_settings', |
|
| 173 | - 'capability' => 'manage_options', |
|
| 174 | - ), |
|
| 175 | - 'update_default_event_settings' => array( |
|
| 176 | - 'func' => '_update_default_event_settings', |
|
| 177 | - 'capability' => 'manage_options', |
|
| 178 | - 'noheader' => true, |
|
| 179 | - ), |
|
| 180 | - 'template_settings' => array( |
|
| 181 | - 'func' => '_template_settings', |
|
| 182 | - 'capability' => 'manage_options', |
|
| 183 | - ), |
|
| 184 | - //event category tab related |
|
| 185 | - 'add_category' => array( |
|
| 186 | - 'func' => '_category_details', |
|
| 187 | - 'capability' => 'ee_edit_event_category', |
|
| 188 | - 'args' => array('add'), |
|
| 189 | - ), |
|
| 190 | - 'edit_category' => array( |
|
| 191 | - 'func' => '_category_details', |
|
| 192 | - 'capability' => 'ee_edit_event_category', |
|
| 193 | - 'args' => array('edit'), |
|
| 194 | - ), |
|
| 195 | - 'delete_categories' => array( |
|
| 196 | - 'func' => '_delete_categories', |
|
| 197 | - 'capability' => 'ee_delete_event_category', |
|
| 198 | - 'noheader' => true, |
|
| 199 | - ), |
|
| 200 | - 'delete_category' => array( |
|
| 201 | - 'func' => '_delete_categories', |
|
| 202 | - 'capability' => 'ee_delete_event_category', |
|
| 203 | - 'noheader' => true, |
|
| 204 | - ), |
|
| 205 | - 'insert_category' => array( |
|
| 206 | - 'func' => '_insert_or_update_category', |
|
| 207 | - 'args' => array('new_category' => true), |
|
| 208 | - 'capability' => 'ee_edit_event_category', |
|
| 209 | - 'noheader' => true, |
|
| 210 | - ), |
|
| 211 | - 'update_category' => array( |
|
| 212 | - 'func' => '_insert_or_update_category', |
|
| 213 | - 'args' => array('new_category' => false), |
|
| 214 | - 'capability' => 'ee_edit_event_category', |
|
| 215 | - 'noheader' => true, |
|
| 216 | - ), |
|
| 217 | - 'category_list' => array( |
|
| 218 | - 'func' => '_category_list_table', |
|
| 219 | - 'capability' => 'ee_manage_event_categories', |
|
| 220 | - ), |
|
| 221 | - ); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - protected function _set_page_config() |
|
| 226 | - { |
|
| 227 | - $this->_page_config = array( |
|
| 228 | - 'default' => array( |
|
| 229 | - 'nav' => array( |
|
| 230 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 231 | - 'order' => 10, |
|
| 232 | - ), |
|
| 233 | - 'list_table' => 'Events_Admin_List_Table', |
|
| 234 | - 'help_tabs' => array( |
|
| 235 | - 'events_overview_help_tab' => array( |
|
| 236 | - 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 237 | - 'filename' => 'events_overview', |
|
| 238 | - ), |
|
| 239 | - 'events_overview_table_column_headings_help_tab' => array( |
|
| 240 | - 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 241 | - 'filename' => 'events_overview_table_column_headings', |
|
| 242 | - ), |
|
| 243 | - 'events_overview_filters_help_tab' => array( |
|
| 244 | - 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 245 | - 'filename' => 'events_overview_filters', |
|
| 246 | - ), |
|
| 247 | - 'events_overview_view_help_tab' => array( |
|
| 248 | - 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 249 | - 'filename' => 'events_overview_views', |
|
| 250 | - ), |
|
| 251 | - 'events_overview_other_help_tab' => array( |
|
| 252 | - 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 253 | - 'filename' => 'events_overview_other', |
|
| 254 | - ), |
|
| 255 | - ), |
|
| 256 | - 'help_tour' => array( |
|
| 257 | - 'Event_Overview_Help_Tour', |
|
| 258 | - //'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 259 | - ), |
|
| 260 | - 'qtips' => array( |
|
| 261 | - 'EE_Event_List_Table_Tips', |
|
| 262 | - ), |
|
| 263 | - 'require_nonce' => false, |
|
| 264 | - ), |
|
| 265 | - 'create_new' => array( |
|
| 266 | - 'nav' => array( |
|
| 267 | - 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 268 | - 'order' => 5, |
|
| 269 | - 'persistent' => false, |
|
| 270 | - ), |
|
| 271 | - 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 272 | - 'help_tabs' => array( |
|
| 273 | - 'event_editor_help_tab' => array( |
|
| 274 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 275 | - 'filename' => 'event_editor', |
|
| 276 | - ), |
|
| 277 | - 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 278 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 279 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 280 | - ), |
|
| 281 | - 'event_editor_venue_details_help_tab' => array( |
|
| 282 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 283 | - 'filename' => 'event_editor_venue_details', |
|
| 284 | - ), |
|
| 285 | - 'event_editor_event_datetimes_help_tab' => array( |
|
| 286 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 287 | - 'filename' => 'event_editor_event_datetimes', |
|
| 288 | - ), |
|
| 289 | - 'event_editor_event_tickets_help_tab' => array( |
|
| 290 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 291 | - 'filename' => 'event_editor_event_tickets', |
|
| 292 | - ), |
|
| 293 | - 'event_editor_event_registration_options_help_tab' => array( |
|
| 294 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 295 | - 'filename' => 'event_editor_event_registration_options', |
|
| 296 | - ), |
|
| 297 | - 'event_editor_tags_categories_help_tab' => array( |
|
| 298 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 299 | - 'filename' => 'event_editor_tags_categories', |
|
| 300 | - ), |
|
| 301 | - 'event_editor_questions_registrants_help_tab' => array( |
|
| 302 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 303 | - 'filename' => 'event_editor_questions_registrants', |
|
| 304 | - ), |
|
| 305 | - 'event_editor_save_new_event_help_tab' => array( |
|
| 306 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 307 | - 'filename' => 'event_editor_save_new_event', |
|
| 308 | - ), |
|
| 309 | - 'event_editor_other_help_tab' => array( |
|
| 310 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 311 | - 'filename' => 'event_editor_other', |
|
| 312 | - ), |
|
| 313 | - ), |
|
| 314 | - 'help_tour' => array( |
|
| 315 | - 'Event_Editor_Help_Tour', |
|
| 316 | - ), |
|
| 317 | - 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 318 | - 'require_nonce' => false, |
|
| 319 | - ), |
|
| 320 | - 'edit' => array( |
|
| 321 | - 'nav' => array( |
|
| 322 | - 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 323 | - 'order' => 5, |
|
| 324 | - 'persistent' => false, |
|
| 325 | - 'url' => isset($this->_req_data['post']) |
|
| 326 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 327 | - array('post' => $this->_req_data['post'], 'action' => 'edit'), |
|
| 328 | - $this->_current_page_view_url |
|
| 329 | - ) |
|
| 330 | - : $this->_admin_base_url, |
|
| 331 | - ), |
|
| 332 | - 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 333 | - 'help_tabs' => array( |
|
| 334 | - 'event_editor_help_tab' => array( |
|
| 335 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 336 | - 'filename' => 'event_editor', |
|
| 337 | - ), |
|
| 338 | - 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 339 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 340 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 341 | - ), |
|
| 342 | - 'event_editor_venue_details_help_tab' => array( |
|
| 343 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 344 | - 'filename' => 'event_editor_venue_details', |
|
| 345 | - ), |
|
| 346 | - 'event_editor_event_datetimes_help_tab' => array( |
|
| 347 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 348 | - 'filename' => 'event_editor_event_datetimes', |
|
| 349 | - ), |
|
| 350 | - 'event_editor_event_tickets_help_tab' => array( |
|
| 351 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 352 | - 'filename' => 'event_editor_event_tickets', |
|
| 353 | - ), |
|
| 354 | - 'event_editor_event_registration_options_help_tab' => array( |
|
| 355 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 356 | - 'filename' => 'event_editor_event_registration_options', |
|
| 357 | - ), |
|
| 358 | - 'event_editor_tags_categories_help_tab' => array( |
|
| 359 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 360 | - 'filename' => 'event_editor_tags_categories', |
|
| 361 | - ), |
|
| 362 | - 'event_editor_questions_registrants_help_tab' => array( |
|
| 363 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 364 | - 'filename' => 'event_editor_questions_registrants', |
|
| 365 | - ), |
|
| 366 | - 'event_editor_save_new_event_help_tab' => array( |
|
| 367 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 368 | - 'filename' => 'event_editor_save_new_event', |
|
| 369 | - ), |
|
| 370 | - 'event_editor_other_help_tab' => array( |
|
| 371 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 372 | - 'filename' => 'event_editor_other', |
|
| 373 | - ), |
|
| 374 | - ), |
|
| 375 | - /*'help_tour' => array( |
|
| 19 | + /** |
|
| 20 | + * This will hold the event object for event_details screen. |
|
| 21 | + * |
|
| 22 | + * @access protected |
|
| 23 | + * @var EE_Event $_event |
|
| 24 | + */ |
|
| 25 | + protected $_event; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * This will hold the category object for category_details screen. |
|
| 30 | + * |
|
| 31 | + * @var stdClass $_category |
|
| 32 | + */ |
|
| 33 | + protected $_category; |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * This will hold the event model instance |
|
| 38 | + * |
|
| 39 | + * @var EEM_Event $_event_model |
|
| 40 | + */ |
|
| 41 | + protected $_event_model; |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var EE_Event |
|
| 46 | + */ |
|
| 47 | + protected $_cpt_model_obj = false; |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + protected function _init_page_props() |
|
| 51 | + { |
|
| 52 | + $this->page_slug = EVENTS_PG_SLUG; |
|
| 53 | + $this->page_label = EVENTS_LABEL; |
|
| 54 | + $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 55 | + $this->_admin_base_path = EVENTS_ADMIN; |
|
| 56 | + $this->_cpt_model_names = array( |
|
| 57 | + 'create_new' => 'EEM_Event', |
|
| 58 | + 'edit' => 'EEM_Event', |
|
| 59 | + ); |
|
| 60 | + $this->_cpt_edit_routes = array( |
|
| 61 | + 'espresso_events' => 'edit', |
|
| 62 | + ); |
|
| 63 | + add_action( |
|
| 64 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 65 | + array($this, 'verify_event_edit') |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + protected function _ajax_hooks() |
|
| 71 | + { |
|
| 72 | + //todo: all hooks for events ajax goes in here. |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + protected function _define_page_props() |
|
| 77 | + { |
|
| 78 | + $this->_admin_page_title = EVENTS_LABEL; |
|
| 79 | + $this->_labels = array( |
|
| 80 | + 'buttons' => array( |
|
| 81 | + 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 82 | + 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 83 | + 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 84 | + 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 85 | + 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 86 | + 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 87 | + ), |
|
| 88 | + 'editor_title' => array( |
|
| 89 | + 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 90 | + ), |
|
| 91 | + 'publishbox' => array( |
|
| 92 | + 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 93 | + 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 94 | + 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 95 | + 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 96 | + 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 97 | + ), |
|
| 98 | + ); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + protected function _set_page_routes() |
|
| 103 | + { |
|
| 104 | + //load formatter helper |
|
| 105 | + //load field generator helper |
|
| 106 | + //is there a evt_id in the request? |
|
| 107 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 108 | + ? $this->_req_data['EVT_ID'] : 0; |
|
| 109 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 110 | + $this->_page_routes = array( |
|
| 111 | + 'default' => array( |
|
| 112 | + 'func' => '_events_overview_list_table', |
|
| 113 | + 'capability' => 'ee_read_events', |
|
| 114 | + ), |
|
| 115 | + 'create_new' => array( |
|
| 116 | + 'func' => '_create_new_cpt_item', |
|
| 117 | + 'capability' => 'ee_edit_events', |
|
| 118 | + ), |
|
| 119 | + 'edit' => array( |
|
| 120 | + 'func' => '_edit_cpt_item', |
|
| 121 | + 'capability' => 'ee_edit_event', |
|
| 122 | + 'obj_id' => $evt_id, |
|
| 123 | + ), |
|
| 124 | + 'copy_event' => array( |
|
| 125 | + 'func' => '_copy_events', |
|
| 126 | + 'capability' => 'ee_edit_event', |
|
| 127 | + 'obj_id' => $evt_id, |
|
| 128 | + 'noheader' => true, |
|
| 129 | + ), |
|
| 130 | + 'trash_event' => array( |
|
| 131 | + 'func' => '_trash_or_restore_event', |
|
| 132 | + 'args' => array('event_status' => 'trash'), |
|
| 133 | + 'capability' => 'ee_delete_event', |
|
| 134 | + 'obj_id' => $evt_id, |
|
| 135 | + 'noheader' => true, |
|
| 136 | + ), |
|
| 137 | + 'trash_events' => array( |
|
| 138 | + 'func' => '_trash_or_restore_events', |
|
| 139 | + 'args' => array('event_status' => 'trash'), |
|
| 140 | + 'capability' => 'ee_delete_events', |
|
| 141 | + 'noheader' => true, |
|
| 142 | + ), |
|
| 143 | + 'restore_event' => array( |
|
| 144 | + 'func' => '_trash_or_restore_event', |
|
| 145 | + 'args' => array('event_status' => 'draft'), |
|
| 146 | + 'capability' => 'ee_delete_event', |
|
| 147 | + 'obj_id' => $evt_id, |
|
| 148 | + 'noheader' => true, |
|
| 149 | + ), |
|
| 150 | + 'restore_events' => array( |
|
| 151 | + 'func' => '_trash_or_restore_events', |
|
| 152 | + 'args' => array('event_status' => 'draft'), |
|
| 153 | + 'capability' => 'ee_delete_events', |
|
| 154 | + 'noheader' => true, |
|
| 155 | + ), |
|
| 156 | + 'delete_event' => array( |
|
| 157 | + 'func' => '_delete_event', |
|
| 158 | + 'capability' => 'ee_delete_event', |
|
| 159 | + 'obj_id' => $evt_id, |
|
| 160 | + 'noheader' => true, |
|
| 161 | + ), |
|
| 162 | + 'delete_events' => array( |
|
| 163 | + 'func' => '_delete_events', |
|
| 164 | + 'capability' => 'ee_delete_events', |
|
| 165 | + 'noheader' => true, |
|
| 166 | + ), |
|
| 167 | + 'view_report' => array( |
|
| 168 | + 'func' => '_view_report', |
|
| 169 | + 'capablity' => 'ee_edit_events', |
|
| 170 | + ), |
|
| 171 | + 'default_event_settings' => array( |
|
| 172 | + 'func' => '_default_event_settings', |
|
| 173 | + 'capability' => 'manage_options', |
|
| 174 | + ), |
|
| 175 | + 'update_default_event_settings' => array( |
|
| 176 | + 'func' => '_update_default_event_settings', |
|
| 177 | + 'capability' => 'manage_options', |
|
| 178 | + 'noheader' => true, |
|
| 179 | + ), |
|
| 180 | + 'template_settings' => array( |
|
| 181 | + 'func' => '_template_settings', |
|
| 182 | + 'capability' => 'manage_options', |
|
| 183 | + ), |
|
| 184 | + //event category tab related |
|
| 185 | + 'add_category' => array( |
|
| 186 | + 'func' => '_category_details', |
|
| 187 | + 'capability' => 'ee_edit_event_category', |
|
| 188 | + 'args' => array('add'), |
|
| 189 | + ), |
|
| 190 | + 'edit_category' => array( |
|
| 191 | + 'func' => '_category_details', |
|
| 192 | + 'capability' => 'ee_edit_event_category', |
|
| 193 | + 'args' => array('edit'), |
|
| 194 | + ), |
|
| 195 | + 'delete_categories' => array( |
|
| 196 | + 'func' => '_delete_categories', |
|
| 197 | + 'capability' => 'ee_delete_event_category', |
|
| 198 | + 'noheader' => true, |
|
| 199 | + ), |
|
| 200 | + 'delete_category' => array( |
|
| 201 | + 'func' => '_delete_categories', |
|
| 202 | + 'capability' => 'ee_delete_event_category', |
|
| 203 | + 'noheader' => true, |
|
| 204 | + ), |
|
| 205 | + 'insert_category' => array( |
|
| 206 | + 'func' => '_insert_or_update_category', |
|
| 207 | + 'args' => array('new_category' => true), |
|
| 208 | + 'capability' => 'ee_edit_event_category', |
|
| 209 | + 'noheader' => true, |
|
| 210 | + ), |
|
| 211 | + 'update_category' => array( |
|
| 212 | + 'func' => '_insert_or_update_category', |
|
| 213 | + 'args' => array('new_category' => false), |
|
| 214 | + 'capability' => 'ee_edit_event_category', |
|
| 215 | + 'noheader' => true, |
|
| 216 | + ), |
|
| 217 | + 'category_list' => array( |
|
| 218 | + 'func' => '_category_list_table', |
|
| 219 | + 'capability' => 'ee_manage_event_categories', |
|
| 220 | + ), |
|
| 221 | + ); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + protected function _set_page_config() |
|
| 226 | + { |
|
| 227 | + $this->_page_config = array( |
|
| 228 | + 'default' => array( |
|
| 229 | + 'nav' => array( |
|
| 230 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 231 | + 'order' => 10, |
|
| 232 | + ), |
|
| 233 | + 'list_table' => 'Events_Admin_List_Table', |
|
| 234 | + 'help_tabs' => array( |
|
| 235 | + 'events_overview_help_tab' => array( |
|
| 236 | + 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 237 | + 'filename' => 'events_overview', |
|
| 238 | + ), |
|
| 239 | + 'events_overview_table_column_headings_help_tab' => array( |
|
| 240 | + 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 241 | + 'filename' => 'events_overview_table_column_headings', |
|
| 242 | + ), |
|
| 243 | + 'events_overview_filters_help_tab' => array( |
|
| 244 | + 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 245 | + 'filename' => 'events_overview_filters', |
|
| 246 | + ), |
|
| 247 | + 'events_overview_view_help_tab' => array( |
|
| 248 | + 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 249 | + 'filename' => 'events_overview_views', |
|
| 250 | + ), |
|
| 251 | + 'events_overview_other_help_tab' => array( |
|
| 252 | + 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 253 | + 'filename' => 'events_overview_other', |
|
| 254 | + ), |
|
| 255 | + ), |
|
| 256 | + 'help_tour' => array( |
|
| 257 | + 'Event_Overview_Help_Tour', |
|
| 258 | + //'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 259 | + ), |
|
| 260 | + 'qtips' => array( |
|
| 261 | + 'EE_Event_List_Table_Tips', |
|
| 262 | + ), |
|
| 263 | + 'require_nonce' => false, |
|
| 264 | + ), |
|
| 265 | + 'create_new' => array( |
|
| 266 | + 'nav' => array( |
|
| 267 | + 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 268 | + 'order' => 5, |
|
| 269 | + 'persistent' => false, |
|
| 270 | + ), |
|
| 271 | + 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 272 | + 'help_tabs' => array( |
|
| 273 | + 'event_editor_help_tab' => array( |
|
| 274 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 275 | + 'filename' => 'event_editor', |
|
| 276 | + ), |
|
| 277 | + 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 278 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 279 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 280 | + ), |
|
| 281 | + 'event_editor_venue_details_help_tab' => array( |
|
| 282 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 283 | + 'filename' => 'event_editor_venue_details', |
|
| 284 | + ), |
|
| 285 | + 'event_editor_event_datetimes_help_tab' => array( |
|
| 286 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 287 | + 'filename' => 'event_editor_event_datetimes', |
|
| 288 | + ), |
|
| 289 | + 'event_editor_event_tickets_help_tab' => array( |
|
| 290 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 291 | + 'filename' => 'event_editor_event_tickets', |
|
| 292 | + ), |
|
| 293 | + 'event_editor_event_registration_options_help_tab' => array( |
|
| 294 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 295 | + 'filename' => 'event_editor_event_registration_options', |
|
| 296 | + ), |
|
| 297 | + 'event_editor_tags_categories_help_tab' => array( |
|
| 298 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 299 | + 'filename' => 'event_editor_tags_categories', |
|
| 300 | + ), |
|
| 301 | + 'event_editor_questions_registrants_help_tab' => array( |
|
| 302 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 303 | + 'filename' => 'event_editor_questions_registrants', |
|
| 304 | + ), |
|
| 305 | + 'event_editor_save_new_event_help_tab' => array( |
|
| 306 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 307 | + 'filename' => 'event_editor_save_new_event', |
|
| 308 | + ), |
|
| 309 | + 'event_editor_other_help_tab' => array( |
|
| 310 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 311 | + 'filename' => 'event_editor_other', |
|
| 312 | + ), |
|
| 313 | + ), |
|
| 314 | + 'help_tour' => array( |
|
| 315 | + 'Event_Editor_Help_Tour', |
|
| 316 | + ), |
|
| 317 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 318 | + 'require_nonce' => false, |
|
| 319 | + ), |
|
| 320 | + 'edit' => array( |
|
| 321 | + 'nav' => array( |
|
| 322 | + 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 323 | + 'order' => 5, |
|
| 324 | + 'persistent' => false, |
|
| 325 | + 'url' => isset($this->_req_data['post']) |
|
| 326 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 327 | + array('post' => $this->_req_data['post'], 'action' => 'edit'), |
|
| 328 | + $this->_current_page_view_url |
|
| 329 | + ) |
|
| 330 | + : $this->_admin_base_url, |
|
| 331 | + ), |
|
| 332 | + 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 333 | + 'help_tabs' => array( |
|
| 334 | + 'event_editor_help_tab' => array( |
|
| 335 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 336 | + 'filename' => 'event_editor', |
|
| 337 | + ), |
|
| 338 | + 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 339 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 340 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 341 | + ), |
|
| 342 | + 'event_editor_venue_details_help_tab' => array( |
|
| 343 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 344 | + 'filename' => 'event_editor_venue_details', |
|
| 345 | + ), |
|
| 346 | + 'event_editor_event_datetimes_help_tab' => array( |
|
| 347 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 348 | + 'filename' => 'event_editor_event_datetimes', |
|
| 349 | + ), |
|
| 350 | + 'event_editor_event_tickets_help_tab' => array( |
|
| 351 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 352 | + 'filename' => 'event_editor_event_tickets', |
|
| 353 | + ), |
|
| 354 | + 'event_editor_event_registration_options_help_tab' => array( |
|
| 355 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 356 | + 'filename' => 'event_editor_event_registration_options', |
|
| 357 | + ), |
|
| 358 | + 'event_editor_tags_categories_help_tab' => array( |
|
| 359 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 360 | + 'filename' => 'event_editor_tags_categories', |
|
| 361 | + ), |
|
| 362 | + 'event_editor_questions_registrants_help_tab' => array( |
|
| 363 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 364 | + 'filename' => 'event_editor_questions_registrants', |
|
| 365 | + ), |
|
| 366 | + 'event_editor_save_new_event_help_tab' => array( |
|
| 367 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 368 | + 'filename' => 'event_editor_save_new_event', |
|
| 369 | + ), |
|
| 370 | + 'event_editor_other_help_tab' => array( |
|
| 371 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 372 | + 'filename' => 'event_editor_other', |
|
| 373 | + ), |
|
| 374 | + ), |
|
| 375 | + /*'help_tour' => array( |
|
| 376 | 376 | 'Event_Edit_Help_Tour' |
| 377 | 377 | ),*/ |
| 378 | - 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 379 | - 'require_nonce' => false, |
|
| 380 | - ), |
|
| 381 | - 'default_event_settings' => array( |
|
| 382 | - 'nav' => array( |
|
| 383 | - 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 384 | - 'order' => 40, |
|
| 385 | - ), |
|
| 386 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 387 | - 'labels' => array( |
|
| 388 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 389 | - ), |
|
| 390 | - 'help_tabs' => array( |
|
| 391 | - 'default_settings_help_tab' => array( |
|
| 392 | - 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 393 | - 'filename' => 'events_default_settings', |
|
| 394 | - ), |
|
| 395 | - 'default_settings_status_help_tab' => array( |
|
| 396 | - 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 397 | - 'filename' => 'events_default_settings_status', |
|
| 398 | - ), |
|
| 399 | - ), |
|
| 400 | - 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
| 401 | - 'require_nonce' => false, |
|
| 402 | - ), |
|
| 403 | - //template settings |
|
| 404 | - 'template_settings' => array( |
|
| 405 | - 'nav' => array( |
|
| 406 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 407 | - 'order' => 30, |
|
| 408 | - ), |
|
| 409 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 410 | - 'help_tabs' => array( |
|
| 411 | - 'general_settings_templates_help_tab' => array( |
|
| 412 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 413 | - 'filename' => 'general_settings_templates', |
|
| 414 | - ), |
|
| 415 | - ), |
|
| 416 | - 'help_tour' => array('Templates_Help_Tour'), |
|
| 417 | - 'require_nonce' => false, |
|
| 418 | - ), |
|
| 419 | - //event category stuff |
|
| 420 | - 'add_category' => array( |
|
| 421 | - 'nav' => array( |
|
| 422 | - 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 423 | - 'order' => 15, |
|
| 424 | - 'persistent' => false, |
|
| 425 | - ), |
|
| 426 | - 'help_tabs' => array( |
|
| 427 | - 'add_category_help_tab' => array( |
|
| 428 | - 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 429 | - 'filename' => 'events_add_category', |
|
| 430 | - ), |
|
| 431 | - ), |
|
| 432 | - 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
| 433 | - 'metaboxes' => array('_publish_post_box'), |
|
| 434 | - 'require_nonce' => false, |
|
| 435 | - ), |
|
| 436 | - 'edit_category' => array( |
|
| 437 | - 'nav' => array( |
|
| 438 | - 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 439 | - 'order' => 15, |
|
| 440 | - 'persistent' => false, |
|
| 441 | - 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
| 442 | - ? add_query_arg( |
|
| 443 | - array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), |
|
| 444 | - $this->_current_page_view_url |
|
| 445 | - ) |
|
| 446 | - : $this->_admin_base_url, |
|
| 447 | - ), |
|
| 448 | - 'help_tabs' => array( |
|
| 449 | - 'edit_category_help_tab' => array( |
|
| 450 | - 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 451 | - 'filename' => 'events_edit_category', |
|
| 452 | - ), |
|
| 453 | - ), |
|
| 454 | - /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
| 455 | - 'metaboxes' => array('_publish_post_box'), |
|
| 456 | - 'require_nonce' => false, |
|
| 457 | - ), |
|
| 458 | - 'category_list' => array( |
|
| 459 | - 'nav' => array( |
|
| 460 | - 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 461 | - 'order' => 20, |
|
| 462 | - ), |
|
| 463 | - 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 464 | - 'help_tabs' => array( |
|
| 465 | - 'events_categories_help_tab' => array( |
|
| 466 | - 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 467 | - 'filename' => 'events_categories', |
|
| 468 | - ), |
|
| 469 | - 'events_categories_table_column_headings_help_tab' => array( |
|
| 470 | - 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 471 | - 'filename' => 'events_categories_table_column_headings', |
|
| 472 | - ), |
|
| 473 | - 'events_categories_view_help_tab' => array( |
|
| 474 | - 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 475 | - 'filename' => 'events_categories_views', |
|
| 476 | - ), |
|
| 477 | - 'events_categories_other_help_tab' => array( |
|
| 478 | - 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 479 | - 'filename' => 'events_categories_other', |
|
| 480 | - ), |
|
| 481 | - ), |
|
| 482 | - 'help_tour' => array( |
|
| 483 | - 'Event_Categories_Help_Tour', |
|
| 484 | - ), |
|
| 485 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 486 | - 'require_nonce' => false, |
|
| 487 | - ), |
|
| 488 | - ); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - |
|
| 492 | - protected function _add_screen_options() |
|
| 493 | - { |
|
| 494 | - //todo |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - |
|
| 498 | - protected function _add_screen_options_default() |
|
| 499 | - { |
|
| 500 | - $this->_per_page_screen_option(); |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - |
|
| 504 | - protected function _add_screen_options_category_list() |
|
| 505 | - { |
|
| 506 | - $page_title = $this->_admin_page_title; |
|
| 507 | - $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 508 | - $this->_per_page_screen_option(); |
|
| 509 | - $this->_admin_page_title = $page_title; |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - protected function _add_feature_pointers() |
|
| 514 | - { |
|
| 515 | - //todo |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - |
|
| 519 | - public function load_scripts_styles() |
|
| 520 | - { |
|
| 521 | - wp_register_style( |
|
| 522 | - 'events-admin-css', |
|
| 523 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 524 | - array(), |
|
| 525 | - EVENT_ESPRESSO_VERSION |
|
| 526 | - ); |
|
| 527 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 528 | - wp_enqueue_style('events-admin-css'); |
|
| 529 | - wp_enqueue_style('ee-cat-admin'); |
|
| 530 | - //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
| 531 | - //registers for all views |
|
| 532 | - //scripts |
|
| 533 | - wp_register_script( |
|
| 534 | - 'event_editor_js', |
|
| 535 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 536 | - array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
|
| 537 | - EVENT_ESPRESSO_VERSION, |
|
| 538 | - true |
|
| 539 | - ); |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * enqueuing scripts and styles specific to this view |
|
| 545 | - * |
|
| 546 | - * @return void |
|
| 547 | - */ |
|
| 548 | - public function load_scripts_styles_create_new() |
|
| 549 | - { |
|
| 550 | - $this->load_scripts_styles_edit(); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * enqueuing scripts and styles specific to this view |
|
| 556 | - * |
|
| 557 | - * @return void |
|
| 558 | - */ |
|
| 559 | - public function load_scripts_styles_edit() |
|
| 560 | - { |
|
| 561 | - //styles |
|
| 562 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 563 | - wp_register_style( |
|
| 564 | - 'event-editor-css', |
|
| 565 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 566 | - array('ee-admin-css'), |
|
| 567 | - EVENT_ESPRESSO_VERSION |
|
| 568 | - ); |
|
| 569 | - wp_enqueue_style('event-editor-css'); |
|
| 570 | - //scripts |
|
| 571 | - wp_register_script( |
|
| 572 | - 'event-datetime-metabox', |
|
| 573 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 574 | - array('event_editor_js', 'ee-datepicker'), |
|
| 575 | - EVENT_ESPRESSO_VERSION |
|
| 576 | - ); |
|
| 577 | - wp_enqueue_script('event-datetime-metabox'); |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - public function load_scripts_styles_add_category() |
|
| 582 | - { |
|
| 583 | - $this->load_scripts_styles_edit_category(); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - public function load_scripts_styles_edit_category() |
|
| 588 | - { |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - protected function _set_list_table_views_category_list() |
|
| 593 | - { |
|
| 594 | - $this->_views = array( |
|
| 595 | - 'all' => array( |
|
| 596 | - 'slug' => 'all', |
|
| 597 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 598 | - 'count' => 0, |
|
| 599 | - 'bulk_action' => array( |
|
| 600 | - 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 601 | - ), |
|
| 602 | - ), |
|
| 603 | - ); |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - |
|
| 607 | - public function admin_init() |
|
| 608 | - { |
|
| 609 | - EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 610 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 611 | - 'event_espresso' |
|
| 612 | - ); |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - //nothing needed for events with these methods. |
|
| 617 | - public function admin_notices() |
|
| 618 | - { |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - |
|
| 622 | - public function admin_footer_scripts() |
|
| 623 | - { |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 629 | - * warning (via EE_Error::add_error()); |
|
| 630 | - * |
|
| 631 | - * @param EE_Event $event Event object |
|
| 632 | - * |
|
| 633 | - * @access public |
|
| 634 | - * @return void |
|
| 635 | - */ |
|
| 636 | - public function verify_event_edit($event = null) |
|
| 637 | - { |
|
| 638 | - // no event? |
|
| 639 | - if (empty($event)) { |
|
| 640 | - // set event |
|
| 641 | - $event = $this->_cpt_model_obj; |
|
| 642 | - } |
|
| 643 | - // STILL no event? |
|
| 644 | - if (empty ($event)) { |
|
| 645 | - return; |
|
| 646 | - } |
|
| 647 | - $orig_status = $event->status(); |
|
| 648 | - // first check if event is active. |
|
| 649 | - if ( |
|
| 650 | - $orig_status === EEM_Event::cancelled |
|
| 651 | - || $orig_status === EEM_Event::postponed |
|
| 652 | - || $event->is_expired() |
|
| 653 | - || $event->is_inactive() |
|
| 654 | - ) { |
|
| 655 | - return; |
|
| 656 | - } |
|
| 657 | - //made it here so it IS active... next check that any of the tickets are sold. |
|
| 658 | - if ($event->is_sold_out(true)) { |
|
| 659 | - if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 660 | - EE_Error::add_attention( |
|
| 661 | - sprintf( |
|
| 662 | - esc_html__( |
|
| 663 | - 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
| 664 | - 'event_espresso' |
|
| 665 | - ), |
|
| 666 | - EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 667 | - ) |
|
| 668 | - ); |
|
| 669 | - } |
|
| 378 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 379 | + 'require_nonce' => false, |
|
| 380 | + ), |
|
| 381 | + 'default_event_settings' => array( |
|
| 382 | + 'nav' => array( |
|
| 383 | + 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 384 | + 'order' => 40, |
|
| 385 | + ), |
|
| 386 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 387 | + 'labels' => array( |
|
| 388 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 389 | + ), |
|
| 390 | + 'help_tabs' => array( |
|
| 391 | + 'default_settings_help_tab' => array( |
|
| 392 | + 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 393 | + 'filename' => 'events_default_settings', |
|
| 394 | + ), |
|
| 395 | + 'default_settings_status_help_tab' => array( |
|
| 396 | + 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 397 | + 'filename' => 'events_default_settings_status', |
|
| 398 | + ), |
|
| 399 | + ), |
|
| 400 | + 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
| 401 | + 'require_nonce' => false, |
|
| 402 | + ), |
|
| 403 | + //template settings |
|
| 404 | + 'template_settings' => array( |
|
| 405 | + 'nav' => array( |
|
| 406 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 407 | + 'order' => 30, |
|
| 408 | + ), |
|
| 409 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 410 | + 'help_tabs' => array( |
|
| 411 | + 'general_settings_templates_help_tab' => array( |
|
| 412 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 413 | + 'filename' => 'general_settings_templates', |
|
| 414 | + ), |
|
| 415 | + ), |
|
| 416 | + 'help_tour' => array('Templates_Help_Tour'), |
|
| 417 | + 'require_nonce' => false, |
|
| 418 | + ), |
|
| 419 | + //event category stuff |
|
| 420 | + 'add_category' => array( |
|
| 421 | + 'nav' => array( |
|
| 422 | + 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 423 | + 'order' => 15, |
|
| 424 | + 'persistent' => false, |
|
| 425 | + ), |
|
| 426 | + 'help_tabs' => array( |
|
| 427 | + 'add_category_help_tab' => array( |
|
| 428 | + 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 429 | + 'filename' => 'events_add_category', |
|
| 430 | + ), |
|
| 431 | + ), |
|
| 432 | + 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
| 433 | + 'metaboxes' => array('_publish_post_box'), |
|
| 434 | + 'require_nonce' => false, |
|
| 435 | + ), |
|
| 436 | + 'edit_category' => array( |
|
| 437 | + 'nav' => array( |
|
| 438 | + 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 439 | + 'order' => 15, |
|
| 440 | + 'persistent' => false, |
|
| 441 | + 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
| 442 | + ? add_query_arg( |
|
| 443 | + array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), |
|
| 444 | + $this->_current_page_view_url |
|
| 445 | + ) |
|
| 446 | + : $this->_admin_base_url, |
|
| 447 | + ), |
|
| 448 | + 'help_tabs' => array( |
|
| 449 | + 'edit_category_help_tab' => array( |
|
| 450 | + 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 451 | + 'filename' => 'events_edit_category', |
|
| 452 | + ), |
|
| 453 | + ), |
|
| 454 | + /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
| 455 | + 'metaboxes' => array('_publish_post_box'), |
|
| 456 | + 'require_nonce' => false, |
|
| 457 | + ), |
|
| 458 | + 'category_list' => array( |
|
| 459 | + 'nav' => array( |
|
| 460 | + 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 461 | + 'order' => 20, |
|
| 462 | + ), |
|
| 463 | + 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 464 | + 'help_tabs' => array( |
|
| 465 | + 'events_categories_help_tab' => array( |
|
| 466 | + 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 467 | + 'filename' => 'events_categories', |
|
| 468 | + ), |
|
| 469 | + 'events_categories_table_column_headings_help_tab' => array( |
|
| 470 | + 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 471 | + 'filename' => 'events_categories_table_column_headings', |
|
| 472 | + ), |
|
| 473 | + 'events_categories_view_help_tab' => array( |
|
| 474 | + 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 475 | + 'filename' => 'events_categories_views', |
|
| 476 | + ), |
|
| 477 | + 'events_categories_other_help_tab' => array( |
|
| 478 | + 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 479 | + 'filename' => 'events_categories_other', |
|
| 480 | + ), |
|
| 481 | + ), |
|
| 482 | + 'help_tour' => array( |
|
| 483 | + 'Event_Categories_Help_Tour', |
|
| 484 | + ), |
|
| 485 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 486 | + 'require_nonce' => false, |
|
| 487 | + ), |
|
| 488 | + ); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + |
|
| 492 | + protected function _add_screen_options() |
|
| 493 | + { |
|
| 494 | + //todo |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + |
|
| 498 | + protected function _add_screen_options_default() |
|
| 499 | + { |
|
| 500 | + $this->_per_page_screen_option(); |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + |
|
| 504 | + protected function _add_screen_options_category_list() |
|
| 505 | + { |
|
| 506 | + $page_title = $this->_admin_page_title; |
|
| 507 | + $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 508 | + $this->_per_page_screen_option(); |
|
| 509 | + $this->_admin_page_title = $page_title; |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + protected function _add_feature_pointers() |
|
| 514 | + { |
|
| 515 | + //todo |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + |
|
| 519 | + public function load_scripts_styles() |
|
| 520 | + { |
|
| 521 | + wp_register_style( |
|
| 522 | + 'events-admin-css', |
|
| 523 | + EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 524 | + array(), |
|
| 525 | + EVENT_ESPRESSO_VERSION |
|
| 526 | + ); |
|
| 527 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 528 | + wp_enqueue_style('events-admin-css'); |
|
| 529 | + wp_enqueue_style('ee-cat-admin'); |
|
| 530 | + //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
| 531 | + //registers for all views |
|
| 532 | + //scripts |
|
| 533 | + wp_register_script( |
|
| 534 | + 'event_editor_js', |
|
| 535 | + EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 536 | + array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
|
| 537 | + EVENT_ESPRESSO_VERSION, |
|
| 538 | + true |
|
| 539 | + ); |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * enqueuing scripts and styles specific to this view |
|
| 545 | + * |
|
| 546 | + * @return void |
|
| 547 | + */ |
|
| 548 | + public function load_scripts_styles_create_new() |
|
| 549 | + { |
|
| 550 | + $this->load_scripts_styles_edit(); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * enqueuing scripts and styles specific to this view |
|
| 556 | + * |
|
| 557 | + * @return void |
|
| 558 | + */ |
|
| 559 | + public function load_scripts_styles_edit() |
|
| 560 | + { |
|
| 561 | + //styles |
|
| 562 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 563 | + wp_register_style( |
|
| 564 | + 'event-editor-css', |
|
| 565 | + EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 566 | + array('ee-admin-css'), |
|
| 567 | + EVENT_ESPRESSO_VERSION |
|
| 568 | + ); |
|
| 569 | + wp_enqueue_style('event-editor-css'); |
|
| 570 | + //scripts |
|
| 571 | + wp_register_script( |
|
| 572 | + 'event-datetime-metabox', |
|
| 573 | + EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 574 | + array('event_editor_js', 'ee-datepicker'), |
|
| 575 | + EVENT_ESPRESSO_VERSION |
|
| 576 | + ); |
|
| 577 | + wp_enqueue_script('event-datetime-metabox'); |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + public function load_scripts_styles_add_category() |
|
| 582 | + { |
|
| 583 | + $this->load_scripts_styles_edit_category(); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + public function load_scripts_styles_edit_category() |
|
| 588 | + { |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + protected function _set_list_table_views_category_list() |
|
| 593 | + { |
|
| 594 | + $this->_views = array( |
|
| 595 | + 'all' => array( |
|
| 596 | + 'slug' => 'all', |
|
| 597 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 598 | + 'count' => 0, |
|
| 599 | + 'bulk_action' => array( |
|
| 600 | + 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 601 | + ), |
|
| 602 | + ), |
|
| 603 | + ); |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + |
|
| 607 | + public function admin_init() |
|
| 608 | + { |
|
| 609 | + EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 610 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 611 | + 'event_espresso' |
|
| 612 | + ); |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + //nothing needed for events with these methods. |
|
| 617 | + public function admin_notices() |
|
| 618 | + { |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + |
|
| 622 | + public function admin_footer_scripts() |
|
| 623 | + { |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 629 | + * warning (via EE_Error::add_error()); |
|
| 630 | + * |
|
| 631 | + * @param EE_Event $event Event object |
|
| 632 | + * |
|
| 633 | + * @access public |
|
| 634 | + * @return void |
|
| 635 | + */ |
|
| 636 | + public function verify_event_edit($event = null) |
|
| 637 | + { |
|
| 638 | + // no event? |
|
| 639 | + if (empty($event)) { |
|
| 640 | + // set event |
|
| 641 | + $event = $this->_cpt_model_obj; |
|
| 642 | + } |
|
| 643 | + // STILL no event? |
|
| 644 | + if (empty ($event)) { |
|
| 645 | + return; |
|
| 646 | + } |
|
| 647 | + $orig_status = $event->status(); |
|
| 648 | + // first check if event is active. |
|
| 649 | + if ( |
|
| 650 | + $orig_status === EEM_Event::cancelled |
|
| 651 | + || $orig_status === EEM_Event::postponed |
|
| 652 | + || $event->is_expired() |
|
| 653 | + || $event->is_inactive() |
|
| 654 | + ) { |
|
| 655 | + return; |
|
| 656 | + } |
|
| 657 | + //made it here so it IS active... next check that any of the tickets are sold. |
|
| 658 | + if ($event->is_sold_out(true)) { |
|
| 659 | + if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 660 | + EE_Error::add_attention( |
|
| 661 | + sprintf( |
|
| 662 | + esc_html__( |
|
| 663 | + 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
| 664 | + 'event_espresso' |
|
| 665 | + ), |
|
| 666 | + EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 667 | + ) |
|
| 668 | + ); |
|
| 669 | + } |
|
| 670 | 670 | |
| 671 | - return; |
|
| 672 | - } else if ($orig_status === EEM_Event::sold_out) { |
|
| 673 | - EE_Error::add_attention( |
|
| 674 | - sprintf( |
|
| 675 | - esc_html__( |
|
| 676 | - 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
| 677 | - 'event_espresso' |
|
| 678 | - ), |
|
| 679 | - EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 680 | - ) |
|
| 681 | - ); |
|
| 682 | - } |
|
| 683 | - //now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 684 | - if ( ! $event->tickets_on_sale()) { |
|
| 685 | - return; |
|
| 686 | - } |
|
| 687 | - //made it here so show warning |
|
| 688 | - $this->_edit_event_warning(); |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - |
|
| 692 | - /** |
|
| 693 | - * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 694 | - * When needed, hook this into a EE_Error::add_error() notice. |
|
| 695 | - * |
|
| 696 | - * @access protected |
|
| 697 | - * @return void |
|
| 698 | - */ |
|
| 699 | - protected function _edit_event_warning() |
|
| 700 | - { |
|
| 701 | - // we don't want to add warnings during these requests |
|
| 702 | - if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
| 703 | - return; |
|
| 704 | - } |
|
| 705 | - EE_Error::add_attention( |
|
| 706 | - esc_html__( |
|
| 707 | - 'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.', |
|
| 708 | - 'event_espresso' |
|
| 709 | - ) |
|
| 710 | - ); |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - |
|
| 714 | - /** |
|
| 715 | - * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 716 | - * Otherwise, do the normal logic |
|
| 717 | - * @return string |
|
| 718 | - */ |
|
| 719 | - protected function _create_new_cpt_item() |
|
| 720 | - { |
|
| 721 | - $gmt_offset = get_option('gmt_offset'); |
|
| 722 | - //only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 723 | - if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) { |
|
| 724 | - EE_Error::add_attention( |
|
| 725 | - sprintf( |
|
| 726 | - __( |
|
| 727 | - 'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city |
|
| 671 | + return; |
|
| 672 | + } else if ($orig_status === EEM_Event::sold_out) { |
|
| 673 | + EE_Error::add_attention( |
|
| 674 | + sprintf( |
|
| 675 | + esc_html__( |
|
| 676 | + 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
| 677 | + 'event_espresso' |
|
| 678 | + ), |
|
| 679 | + EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 680 | + ) |
|
| 681 | + ); |
|
| 682 | + } |
|
| 683 | + //now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 684 | + if ( ! $event->tickets_on_sale()) { |
|
| 685 | + return; |
|
| 686 | + } |
|
| 687 | + //made it here so show warning |
|
| 688 | + $this->_edit_event_warning(); |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + |
|
| 692 | + /** |
|
| 693 | + * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 694 | + * When needed, hook this into a EE_Error::add_error() notice. |
|
| 695 | + * |
|
| 696 | + * @access protected |
|
| 697 | + * @return void |
|
| 698 | + */ |
|
| 699 | + protected function _edit_event_warning() |
|
| 700 | + { |
|
| 701 | + // we don't want to add warnings during these requests |
|
| 702 | + if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
| 703 | + return; |
|
| 704 | + } |
|
| 705 | + EE_Error::add_attention( |
|
| 706 | + esc_html__( |
|
| 707 | + 'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.', |
|
| 708 | + 'event_espresso' |
|
| 709 | + ) |
|
| 710 | + ); |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + |
|
| 714 | + /** |
|
| 715 | + * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 716 | + * Otherwise, do the normal logic |
|
| 717 | + * @return string |
|
| 718 | + */ |
|
| 719 | + protected function _create_new_cpt_item() |
|
| 720 | + { |
|
| 721 | + $gmt_offset = get_option('gmt_offset'); |
|
| 722 | + //only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 723 | + if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) { |
|
| 724 | + EE_Error::add_attention( |
|
| 725 | + sprintf( |
|
| 726 | + __( |
|
| 727 | + 'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city |
|
| 728 | 728 | or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.' |
| 729 | - ), |
|
| 730 | - '<a href="' . admin_url('options-general.php') . '">', |
|
| 731 | - '</a>' |
|
| 732 | - ), |
|
| 733 | - __FILE__, |
|
| 734 | - __FUNCTION__, |
|
| 735 | - __LINE__ |
|
| 736 | - ); |
|
| 737 | - } |
|
| 738 | - return parent::_create_new_cpt_item(); |
|
| 739 | - } |
|
| 729 | + ), |
|
| 730 | + '<a href="' . admin_url('options-general.php') . '">', |
|
| 731 | + '</a>' |
|
| 732 | + ), |
|
| 733 | + __FILE__, |
|
| 734 | + __FUNCTION__, |
|
| 735 | + __LINE__ |
|
| 736 | + ); |
|
| 737 | + } |
|
| 738 | + return parent::_create_new_cpt_item(); |
|
| 739 | + } |
|
| 740 | 740 | |
| 741 | 741 | |
| 742 | 742 | |
| 743 | - protected function _set_list_table_views_default() |
|
| 744 | - { |
|
| 745 | - $this->_views = array( |
|
| 746 | - 'all' => array( |
|
| 747 | - 'slug' => 'all', |
|
| 748 | - 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 749 | - 'count' => 0, |
|
| 750 | - 'bulk_action' => array( |
|
| 751 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 752 | - ), |
|
| 753 | - ), |
|
| 754 | - 'draft' => array( |
|
| 755 | - 'slug' => 'draft', |
|
| 756 | - 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 757 | - 'count' => 0, |
|
| 758 | - 'bulk_action' => array( |
|
| 759 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 760 | - ), |
|
| 761 | - ), |
|
| 762 | - ); |
|
| 763 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 764 | - $this->_views['trash'] = array( |
|
| 765 | - 'slug' => 'trash', |
|
| 766 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 767 | - 'count' => 0, |
|
| 768 | - 'bulk_action' => array( |
|
| 769 | - 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 770 | - 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 771 | - ), |
|
| 772 | - ); |
|
| 773 | - } |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - |
|
| 777 | - /** |
|
| 778 | - * @return array |
|
| 779 | - */ |
|
| 780 | - protected function _event_legend_items() |
|
| 781 | - { |
|
| 782 | - $items = array( |
|
| 783 | - 'view_details' => array( |
|
| 784 | - 'class' => 'dashicons dashicons-search', |
|
| 785 | - 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 786 | - ), |
|
| 787 | - 'edit_event' => array( |
|
| 788 | - 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 789 | - 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 790 | - ), |
|
| 791 | - 'view_attendees' => array( |
|
| 792 | - 'class' => 'dashicons dashicons-groups', |
|
| 793 | - 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 794 | - ), |
|
| 795 | - ); |
|
| 796 | - $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 797 | - $statuses = array( |
|
| 798 | - 'sold_out_status' => array( |
|
| 799 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 800 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 801 | - ), |
|
| 802 | - 'active_status' => array( |
|
| 803 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 804 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 805 | - ), |
|
| 806 | - 'upcoming_status' => array( |
|
| 807 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 808 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 809 | - ), |
|
| 810 | - 'postponed_status' => array( |
|
| 811 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 812 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 813 | - ), |
|
| 814 | - 'cancelled_status' => array( |
|
| 815 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 816 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 817 | - ), |
|
| 818 | - 'expired_status' => array( |
|
| 819 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 820 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 821 | - ), |
|
| 822 | - 'inactive_status' => array( |
|
| 823 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 824 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 825 | - ), |
|
| 826 | - ); |
|
| 827 | - $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 743 | + protected function _set_list_table_views_default() |
|
| 744 | + { |
|
| 745 | + $this->_views = array( |
|
| 746 | + 'all' => array( |
|
| 747 | + 'slug' => 'all', |
|
| 748 | + 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 749 | + 'count' => 0, |
|
| 750 | + 'bulk_action' => array( |
|
| 751 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 752 | + ), |
|
| 753 | + ), |
|
| 754 | + 'draft' => array( |
|
| 755 | + 'slug' => 'draft', |
|
| 756 | + 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 757 | + 'count' => 0, |
|
| 758 | + 'bulk_action' => array( |
|
| 759 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 760 | + ), |
|
| 761 | + ), |
|
| 762 | + ); |
|
| 763 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 764 | + $this->_views['trash'] = array( |
|
| 765 | + 'slug' => 'trash', |
|
| 766 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 767 | + 'count' => 0, |
|
| 768 | + 'bulk_action' => array( |
|
| 769 | + 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 770 | + 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 771 | + ), |
|
| 772 | + ); |
|
| 773 | + } |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + |
|
| 777 | + /** |
|
| 778 | + * @return array |
|
| 779 | + */ |
|
| 780 | + protected function _event_legend_items() |
|
| 781 | + { |
|
| 782 | + $items = array( |
|
| 783 | + 'view_details' => array( |
|
| 784 | + 'class' => 'dashicons dashicons-search', |
|
| 785 | + 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 786 | + ), |
|
| 787 | + 'edit_event' => array( |
|
| 788 | + 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 789 | + 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 790 | + ), |
|
| 791 | + 'view_attendees' => array( |
|
| 792 | + 'class' => 'dashicons dashicons-groups', |
|
| 793 | + 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 794 | + ), |
|
| 795 | + ); |
|
| 796 | + $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 797 | + $statuses = array( |
|
| 798 | + 'sold_out_status' => array( |
|
| 799 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 800 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 801 | + ), |
|
| 802 | + 'active_status' => array( |
|
| 803 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 804 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 805 | + ), |
|
| 806 | + 'upcoming_status' => array( |
|
| 807 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 808 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 809 | + ), |
|
| 810 | + 'postponed_status' => array( |
|
| 811 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 812 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 813 | + ), |
|
| 814 | + 'cancelled_status' => array( |
|
| 815 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 816 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 817 | + ), |
|
| 818 | + 'expired_status' => array( |
|
| 819 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 820 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 821 | + ), |
|
| 822 | + 'inactive_status' => array( |
|
| 823 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 824 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 825 | + ), |
|
| 826 | + ); |
|
| 827 | + $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 828 | 828 | |
| 829 | - return array_merge($items, $statuses); |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - |
|
| 833 | - /** |
|
| 834 | - * _event_model |
|
| 835 | - * |
|
| 836 | - * @return EEM_Event |
|
| 837 | - */ |
|
| 838 | - private function _event_model() |
|
| 839 | - { |
|
| 840 | - if ( ! $this->_event_model instanceof EEM_Event) { |
|
| 841 | - $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 842 | - } |
|
| 829 | + return array_merge($items, $statuses); |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + |
|
| 833 | + /** |
|
| 834 | + * _event_model |
|
| 835 | + * |
|
| 836 | + * @return EEM_Event |
|
| 837 | + */ |
|
| 838 | + private function _event_model() |
|
| 839 | + { |
|
| 840 | + if ( ! $this->_event_model instanceof EEM_Event) { |
|
| 841 | + $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 842 | + } |
|
| 843 | 843 | |
| 844 | - return $this->_event_model; |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * Adds extra buttons to the WP CPT permalink field row. |
|
| 850 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 851 | - * |
|
| 852 | - * @param string $return the current html |
|
| 853 | - * @param int $id the post id for the page |
|
| 854 | - * @param string $new_title What the title is |
|
| 855 | - * @param string $new_slug what the slug is |
|
| 856 | - * |
|
| 857 | - * @return string The new html string for the permalink area |
|
| 858 | - */ |
|
| 859 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 860 | - { |
|
| 861 | - //make sure this is only when editing |
|
| 862 | - if ( ! empty($id)) { |
|
| 863 | - $post = get_post($id); |
|
| 864 | - $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 865 | - . esc_html__('Shortcode', 'event_espresso') |
|
| 866 | - . '</a> '; |
|
| 867 | - $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 868 | - . $post->ID |
|
| 869 | - . ']">'; |
|
| 870 | - } |
|
| 844 | + return $this->_event_model; |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + /** |
|
| 849 | + * Adds extra buttons to the WP CPT permalink field row. |
|
| 850 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 851 | + * |
|
| 852 | + * @param string $return the current html |
|
| 853 | + * @param int $id the post id for the page |
|
| 854 | + * @param string $new_title What the title is |
|
| 855 | + * @param string $new_slug what the slug is |
|
| 856 | + * |
|
| 857 | + * @return string The new html string for the permalink area |
|
| 858 | + */ |
|
| 859 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 860 | + { |
|
| 861 | + //make sure this is only when editing |
|
| 862 | + if ( ! empty($id)) { |
|
| 863 | + $post = get_post($id); |
|
| 864 | + $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 865 | + . esc_html__('Shortcode', 'event_espresso') |
|
| 866 | + . '</a> '; |
|
| 867 | + $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 868 | + . $post->ID |
|
| 869 | + . ']">'; |
|
| 870 | + } |
|
| 871 | 871 | |
| 872 | - return $return; |
|
| 873 | - } |
|
| 874 | - |
|
| 875 | - |
|
| 876 | - /** |
|
| 877 | - * _events_overview_list_table |
|
| 878 | - * This contains the logic for showing the events_overview list |
|
| 879 | - * |
|
| 880 | - * @access protected |
|
| 881 | - * @return void |
|
| 882 | - */ |
|
| 883 | - protected function _events_overview_list_table() |
|
| 884 | - { |
|
| 885 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 886 | - $this->_template_args['after_list_table'] = EEH_Template::get_button_or_link( |
|
| 887 | - get_post_type_archive_link('espresso_events'), |
|
| 888 | - esc_html__("View Event Archive Page", "event_espresso"), |
|
| 889 | - 'button' |
|
| 890 | - ); |
|
| 891 | - $this->_template_args['after_list_table'] .= $this->_display_legend($this->_event_legend_items()); |
|
| 892 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 893 | - 'create_new', |
|
| 894 | - 'add', |
|
| 895 | - array(), |
|
| 896 | - 'add-new-h2' |
|
| 897 | - ); |
|
| 898 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 899 | - } |
|
| 900 | - |
|
| 901 | - |
|
| 902 | - /** |
|
| 903 | - * this allows for extra misc actions in the default WP publish box |
|
| 904 | - * |
|
| 905 | - * @return void |
|
| 906 | - */ |
|
| 907 | - public function extra_misc_actions_publish_box() |
|
| 908 | - { |
|
| 909 | - $this->_generate_publish_box_extra_content(); |
|
| 910 | - } |
|
| 911 | - |
|
| 912 | - |
|
| 913 | - /** |
|
| 914 | - * @param string $post_id |
|
| 915 | - * @param object $post |
|
| 916 | - */ |
|
| 917 | - protected function _insert_update_cpt_item($post_id, $post) |
|
| 918 | - { |
|
| 919 | - if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 920 | - //get out we're not processing an event save. |
|
| 921 | - return; |
|
| 922 | - } |
|
| 923 | - $event_values = array( |
|
| 924 | - 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
| 925 | - 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
| 926 | - 'EVT_additional_limit' => min( |
|
| 927 | - apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 928 | - ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null |
|
| 929 | - ), |
|
| 930 | - 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) |
|
| 931 | - ? $this->_req_data['EVT_default_registration_status'] |
|
| 932 | - : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 933 | - 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
| 934 | - 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
| 935 | - 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
| 936 | - ? $this->_req_data['timezone_string'] : null, |
|
| 937 | - 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) |
|
| 938 | - ? $this->_req_data['externalURL'] : null, |
|
| 939 | - 'EVT_phone' => ! empty($this->_req_data['event_phone']) |
|
| 940 | - ? $this->_req_data['event_phone'] : null, |
|
| 941 | - ); |
|
| 942 | - //update event |
|
| 943 | - $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 944 | - //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
|
| 945 | - $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status); |
|
| 946 | - $event = $this->_event_model()->get_one(array($get_one_where)); |
|
| 947 | - //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
| 948 | - $event_update_callbacks = apply_filters( |
|
| 949 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 950 | - array(array($this, '_default_venue_update'), array($this, '_default_tickets_update')) |
|
| 951 | - ); |
|
| 952 | - $att_success = true; |
|
| 953 | - foreach ($event_update_callbacks as $e_callback) { |
|
| 954 | - $_succ = call_user_func_array($e_callback, array($event, $this->_req_data)); |
|
| 955 | - $att_success = ! $att_success ? $att_success |
|
| 956 | - : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
|
| 957 | - } |
|
| 958 | - //any errors? |
|
| 959 | - if ($success && false === $att_success) { |
|
| 960 | - EE_Error::add_error( |
|
| 961 | - esc_html__( |
|
| 962 | - 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 963 | - 'event_espresso' |
|
| 964 | - ), |
|
| 965 | - __FILE__, |
|
| 966 | - __FUNCTION__, |
|
| 967 | - __LINE__ |
|
| 968 | - ); |
|
| 969 | - } else if ($success === false) { |
|
| 970 | - EE_Error::add_error( |
|
| 971 | - esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 972 | - __FILE__, |
|
| 973 | - __FUNCTION__, |
|
| 974 | - __LINE__ |
|
| 975 | - ); |
|
| 976 | - } |
|
| 977 | - } |
|
| 978 | - |
|
| 979 | - |
|
| 980 | - /** |
|
| 981 | - * @see parent::restore_item() |
|
| 982 | - * |
|
| 983 | - * @param int $post_id |
|
| 984 | - * @param int $revision_id |
|
| 985 | - */ |
|
| 986 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
| 987 | - { |
|
| 988 | - //copy existing event meta to new post |
|
| 989 | - $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 990 | - if ($post_evt instanceof EE_Event) { |
|
| 991 | - //meta revision restore |
|
| 992 | - $post_evt->restore_revision($revision_id); |
|
| 993 | - //related objs restore |
|
| 994 | - $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
| 995 | - } |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - |
|
| 999 | - /** |
|
| 1000 | - * Attach the venue to the Event |
|
| 1001 | - * |
|
| 1002 | - * @param \EE_Event $evtobj Event Object to add the venue to |
|
| 1003 | - * @param array $data The request data from the form |
|
| 1004 | - * |
|
| 1005 | - * @return bool Success or fail. |
|
| 1006 | - */ |
|
| 1007 | - protected function _default_venue_update(\EE_Event $evtobj, $data) |
|
| 1008 | - { |
|
| 1009 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1010 | - $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1011 | - $rows_affected = null; |
|
| 1012 | - $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1013 | - // very important. If we don't have a venue name... |
|
| 1014 | - // then we'll get out because not necessary to create empty venue |
|
| 1015 | - if (empty($data['venue_title'])) { |
|
| 1016 | - return false; |
|
| 1017 | - } |
|
| 1018 | - $venue_array = array( |
|
| 1019 | - 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
| 1020 | - 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
| 1021 | - 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1022 | - 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1023 | - 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
| 1024 | - : null, |
|
| 1025 | - 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1026 | - 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1027 | - 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1028 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1029 | - 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1030 | - 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1031 | - 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1032 | - 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1033 | - 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1034 | - 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1035 | - 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1036 | - 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1037 | - 'status' => 'publish', |
|
| 1038 | - ); |
|
| 1039 | - //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1040 | - if ( ! empty($venue_id)) { |
|
| 1041 | - $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
| 1042 | - $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
| 1043 | - //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
| 1044 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 872 | + return $return; |
|
| 873 | + } |
|
| 874 | + |
|
| 875 | + |
|
| 876 | + /** |
|
| 877 | + * _events_overview_list_table |
|
| 878 | + * This contains the logic for showing the events_overview list |
|
| 879 | + * |
|
| 880 | + * @access protected |
|
| 881 | + * @return void |
|
| 882 | + */ |
|
| 883 | + protected function _events_overview_list_table() |
|
| 884 | + { |
|
| 885 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 886 | + $this->_template_args['after_list_table'] = EEH_Template::get_button_or_link( |
|
| 887 | + get_post_type_archive_link('espresso_events'), |
|
| 888 | + esc_html__("View Event Archive Page", "event_espresso"), |
|
| 889 | + 'button' |
|
| 890 | + ); |
|
| 891 | + $this->_template_args['after_list_table'] .= $this->_display_legend($this->_event_legend_items()); |
|
| 892 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 893 | + 'create_new', |
|
| 894 | + 'add', |
|
| 895 | + array(), |
|
| 896 | + 'add-new-h2' |
|
| 897 | + ); |
|
| 898 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 899 | + } |
|
| 900 | + |
|
| 901 | + |
|
| 902 | + /** |
|
| 903 | + * this allows for extra misc actions in the default WP publish box |
|
| 904 | + * |
|
| 905 | + * @return void |
|
| 906 | + */ |
|
| 907 | + public function extra_misc_actions_publish_box() |
|
| 908 | + { |
|
| 909 | + $this->_generate_publish_box_extra_content(); |
|
| 910 | + } |
|
| 911 | + |
|
| 912 | + |
|
| 913 | + /** |
|
| 914 | + * @param string $post_id |
|
| 915 | + * @param object $post |
|
| 916 | + */ |
|
| 917 | + protected function _insert_update_cpt_item($post_id, $post) |
|
| 918 | + { |
|
| 919 | + if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 920 | + //get out we're not processing an event save. |
|
| 921 | + return; |
|
| 922 | + } |
|
| 923 | + $event_values = array( |
|
| 924 | + 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
| 925 | + 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
| 926 | + 'EVT_additional_limit' => min( |
|
| 927 | + apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 928 | + ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null |
|
| 929 | + ), |
|
| 930 | + 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) |
|
| 931 | + ? $this->_req_data['EVT_default_registration_status'] |
|
| 932 | + : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 933 | + 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
| 934 | + 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
| 935 | + 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
| 936 | + ? $this->_req_data['timezone_string'] : null, |
|
| 937 | + 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) |
|
| 938 | + ? $this->_req_data['externalURL'] : null, |
|
| 939 | + 'EVT_phone' => ! empty($this->_req_data['event_phone']) |
|
| 940 | + ? $this->_req_data['event_phone'] : null, |
|
| 941 | + ); |
|
| 942 | + //update event |
|
| 943 | + $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 944 | + //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
|
| 945 | + $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status); |
|
| 946 | + $event = $this->_event_model()->get_one(array($get_one_where)); |
|
| 947 | + //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
| 948 | + $event_update_callbacks = apply_filters( |
|
| 949 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 950 | + array(array($this, '_default_venue_update'), array($this, '_default_tickets_update')) |
|
| 951 | + ); |
|
| 952 | + $att_success = true; |
|
| 953 | + foreach ($event_update_callbacks as $e_callback) { |
|
| 954 | + $_succ = call_user_func_array($e_callback, array($event, $this->_req_data)); |
|
| 955 | + $att_success = ! $att_success ? $att_success |
|
| 956 | + : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
|
| 957 | + } |
|
| 958 | + //any errors? |
|
| 959 | + if ($success && false === $att_success) { |
|
| 960 | + EE_Error::add_error( |
|
| 961 | + esc_html__( |
|
| 962 | + 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 963 | + 'event_espresso' |
|
| 964 | + ), |
|
| 965 | + __FILE__, |
|
| 966 | + __FUNCTION__, |
|
| 967 | + __LINE__ |
|
| 968 | + ); |
|
| 969 | + } else if ($success === false) { |
|
| 970 | + EE_Error::add_error( |
|
| 971 | + esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 972 | + __FILE__, |
|
| 973 | + __FUNCTION__, |
|
| 974 | + __LINE__ |
|
| 975 | + ); |
|
| 976 | + } |
|
| 977 | + } |
|
| 978 | + |
|
| 979 | + |
|
| 980 | + /** |
|
| 981 | + * @see parent::restore_item() |
|
| 982 | + * |
|
| 983 | + * @param int $post_id |
|
| 984 | + * @param int $revision_id |
|
| 985 | + */ |
|
| 986 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
| 987 | + { |
|
| 988 | + //copy existing event meta to new post |
|
| 989 | + $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 990 | + if ($post_evt instanceof EE_Event) { |
|
| 991 | + //meta revision restore |
|
| 992 | + $post_evt->restore_revision($revision_id); |
|
| 993 | + //related objs restore |
|
| 994 | + $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
| 995 | + } |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + |
|
| 999 | + /** |
|
| 1000 | + * Attach the venue to the Event |
|
| 1001 | + * |
|
| 1002 | + * @param \EE_Event $evtobj Event Object to add the venue to |
|
| 1003 | + * @param array $data The request data from the form |
|
| 1004 | + * |
|
| 1005 | + * @return bool Success or fail. |
|
| 1006 | + */ |
|
| 1007 | + protected function _default_venue_update(\EE_Event $evtobj, $data) |
|
| 1008 | + { |
|
| 1009 | + require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1010 | + $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1011 | + $rows_affected = null; |
|
| 1012 | + $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1013 | + // very important. If we don't have a venue name... |
|
| 1014 | + // then we'll get out because not necessary to create empty venue |
|
| 1015 | + if (empty($data['venue_title'])) { |
|
| 1016 | + return false; |
|
| 1017 | + } |
|
| 1018 | + $venue_array = array( |
|
| 1019 | + 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
| 1020 | + 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
| 1021 | + 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1022 | + 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1023 | + 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
| 1024 | + : null, |
|
| 1025 | + 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1026 | + 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1027 | + 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1028 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1029 | + 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1030 | + 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1031 | + 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1032 | + 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1033 | + 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1034 | + 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1035 | + 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1036 | + 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1037 | + 'status' => 'publish', |
|
| 1038 | + ); |
|
| 1039 | + //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1040 | + if ( ! empty($venue_id)) { |
|
| 1041 | + $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
| 1042 | + $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
| 1043 | + //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
| 1044 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1045 | 1045 | |
| 1046 | - return $rows_affected > 0 ? true : false; |
|
| 1047 | - } else { |
|
| 1048 | - //we insert the venue |
|
| 1049 | - $venue_id = $venue_model->insert($venue_array); |
|
| 1050 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1046 | + return $rows_affected > 0 ? true : false; |
|
| 1047 | + } else { |
|
| 1048 | + //we insert the venue |
|
| 1049 | + $venue_id = $venue_model->insert($venue_array); |
|
| 1050 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1051 | 1051 | |
| 1052 | - return ! empty($venue_id) ? true : false; |
|
| 1053 | - } |
|
| 1054 | - //when we have the ancestor come in it's already been handled by the revision save. |
|
| 1055 | - } |
|
| 1056 | - |
|
| 1057 | - |
|
| 1058 | - /** |
|
| 1059 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1060 | - * |
|
| 1061 | - * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 1062 | - * @param array $data The request data from the form |
|
| 1063 | - * |
|
| 1064 | - * @return array |
|
| 1065 | - */ |
|
| 1066 | - protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
| 1067 | - { |
|
| 1068 | - $success = true; |
|
| 1069 | - $saved_dtt = null; |
|
| 1070 | - $saved_tickets = array(); |
|
| 1071 | - $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1072 | - foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 1073 | - //trim all values to ensure any excess whitespace is removed. |
|
| 1074 | - $dtt = array_map('trim', $dtt); |
|
| 1075 | - $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
| 1076 | - : $dtt['DTT_EVT_start']; |
|
| 1077 | - $datetime_values = array( |
|
| 1078 | - 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 1079 | - 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 1080 | - 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 1081 | - 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 1082 | - 'DTT_order' => $row, |
|
| 1083 | - ); |
|
| 1084 | - //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. |
|
| 1085 | - if ( ! empty($dtt['DTT_ID'])) { |
|
| 1086 | - $DTM = EE_Registry::instance() |
|
| 1087 | - ->load_model('Datetime', array($evtobj->get_timezone())) |
|
| 1088 | - ->get_one_by_ID($dtt['DTT_ID']); |
|
| 1089 | - $DTM->set_date_format($incoming_date_formats[0]); |
|
| 1090 | - $DTM->set_time_format($incoming_date_formats[1]); |
|
| 1091 | - foreach ($datetime_values as $field => $value) { |
|
| 1092 | - $DTM->set($field, $value); |
|
| 1093 | - } |
|
| 1094 | - //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
|
| 1095 | - $saved_dtts[ $DTM->ID() ] = $DTM; |
|
| 1096 | - } else { |
|
| 1097 | - $DTM = EE_Registry::instance()->load_class( |
|
| 1098 | - 'Datetime', |
|
| 1099 | - array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats), |
|
| 1100 | - false, |
|
| 1101 | - false |
|
| 1102 | - ); |
|
| 1103 | - foreach ($datetime_values as $field => $value) { |
|
| 1104 | - $DTM->set($field, $value); |
|
| 1105 | - } |
|
| 1106 | - } |
|
| 1107 | - $DTM->save(); |
|
| 1108 | - $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
| 1109 | - //load DTT helper |
|
| 1110 | - //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. |
|
| 1111 | - if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
| 1112 | - $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
| 1113 | - $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
| 1114 | - $DTT->save(); |
|
| 1115 | - } |
|
| 1116 | - //now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave. |
|
| 1117 | - $saved_dtt = $DTT; |
|
| 1118 | - $success = ! $success ? $success : $DTT; |
|
| 1119 | - //if ANY of these updates fail then we want the appropriate global error message. |
|
| 1120 | - // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
| 1121 | - } |
|
| 1122 | - //no dtts get deleted so we don't do any of that logic here. |
|
| 1123 | - //update tickets next |
|
| 1124 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 1125 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 1126 | - $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1127 | - $update_prices = false; |
|
| 1128 | - $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
| 1129 | - ? $data['edit_prices'][$row][1]['PRC_amount'] : 0; |
|
| 1130 | - // trim inputs to ensure any excess whitespace is removed. |
|
| 1131 | - $tkt = array_map('trim', $tkt); |
|
| 1132 | - if (empty($tkt['TKT_start_date'])) { |
|
| 1133 | - //let's use now in the set timezone. |
|
| 1134 | - $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
| 1135 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1136 | - } |
|
| 1137 | - if (empty($tkt['TKT_end_date'])) { |
|
| 1138 | - //use the start date of the first datetime |
|
| 1139 | - $dtt = $evtobj->first_datetime(); |
|
| 1140 | - $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
| 1141 | - $incoming_date_formats[0], |
|
| 1142 | - $incoming_date_formats[1] |
|
| 1143 | - ); |
|
| 1144 | - } |
|
| 1145 | - $TKT_values = array( |
|
| 1146 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 1147 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 1148 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 1149 | - 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
| 1150 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 1151 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 1152 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 1153 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 1154 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 1155 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 1156 | - 'TKT_row' => $row, |
|
| 1157 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
| 1158 | - 'TKT_price' => $ticket_price, |
|
| 1159 | - ); |
|
| 1160 | - //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. |
|
| 1161 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 1162 | - $TKT_values['TKT_ID'] = 0; |
|
| 1163 | - $TKT_values['TKT_is_default'] = 0; |
|
| 1164 | - $TKT_values['TKT_price'] = $ticket_price; |
|
| 1165 | - $update_prices = true; |
|
| 1166 | - } |
|
| 1167 | - //if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1168 | - //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
| 1169 | - //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1170 | - if ( ! empty($tkt['TKT_ID'])) { |
|
| 1171 | - $TKT = EE_Registry::instance() |
|
| 1172 | - ->load_model('Ticket', array($evtobj->get_timezone())) |
|
| 1173 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
| 1174 | - if ($TKT instanceof EE_Ticket) { |
|
| 1175 | - $ticket_sold = $TKT->count_related( |
|
| 1176 | - 'Registration', |
|
| 1177 | - array( |
|
| 1178 | - array( |
|
| 1179 | - 'STS_ID' => array( |
|
| 1180 | - 'NOT IN', |
|
| 1181 | - array(EEM_Registration::status_id_incomplete), |
|
| 1182 | - ), |
|
| 1183 | - ), |
|
| 1184 | - ) |
|
| 1185 | - ) > 0 ? true : false; |
|
| 1186 | - //let's just check the total price for the existing ticket and determine if it matches the new total price. if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket. |
|
| 1187 | - $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') |
|
| 1188 | - && ! $TKT->get( |
|
| 1189 | - 'TKT_deleted' |
|
| 1190 | - ) ? true : false; |
|
| 1191 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1192 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1193 | - //set new values |
|
| 1194 | - foreach ($TKT_values as $field => $value) { |
|
| 1195 | - if ($field == 'TKT_qty') { |
|
| 1196 | - $TKT->set_qty($value); |
|
| 1197 | - } else { |
|
| 1198 | - $TKT->set($field, $value); |
|
| 1199 | - } |
|
| 1200 | - } |
|
| 1201 | - //if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
| 1202 | - if ($create_new_TKT) { |
|
| 1203 | - //archive the old ticket first |
|
| 1204 | - $TKT->set('TKT_deleted', 1); |
|
| 1205 | - $TKT->save(); |
|
| 1206 | - //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
| 1207 | - $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1208 | - //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
|
| 1209 | - $TKT = clone $TKT; |
|
| 1210 | - $TKT->set('TKT_ID', 0); |
|
| 1211 | - $TKT->set('TKT_deleted', 0); |
|
| 1212 | - $TKT->set('TKT_price', $ticket_price); |
|
| 1213 | - $TKT->set('TKT_sold', 0); |
|
| 1214 | - //now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1215 | - $update_prices = true; |
|
| 1216 | - } |
|
| 1217 | - //make sure price is set if it hasn't been already |
|
| 1218 | - $TKT->set('TKT_price', $ticket_price); |
|
| 1219 | - } |
|
| 1220 | - } else { |
|
| 1221 | - //no TKT_id so a new TKT |
|
| 1222 | - $TKT_values['TKT_price'] = $ticket_price; |
|
| 1223 | - $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); |
|
| 1224 | - if ($TKT instanceof EE_Ticket) { |
|
| 1225 | - //need to reset values to properly account for the date formats |
|
| 1226 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1227 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1228 | - $TKT->set_timezone($evtobj->get_timezone()); |
|
| 1229 | - //set new values |
|
| 1230 | - foreach ($TKT_values as $field => $value) { |
|
| 1231 | - if ($field == 'TKT_qty') { |
|
| 1232 | - $TKT->set_qty($value); |
|
| 1233 | - } else { |
|
| 1234 | - $TKT->set($field, $value); |
|
| 1235 | - } |
|
| 1236 | - } |
|
| 1237 | - $update_prices = true; |
|
| 1238 | - } |
|
| 1239 | - } |
|
| 1240 | - // cap ticket qty by datetime reg limits |
|
| 1241 | - $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
| 1242 | - //update ticket. |
|
| 1243 | - $TKT->save(); |
|
| 1244 | - //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. |
|
| 1245 | - if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 1246 | - $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 1247 | - $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 1248 | - $TKT->save(); |
|
| 1249 | - } |
|
| 1250 | - //initially let's add the ticket to the dtt |
|
| 1251 | - $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
| 1252 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1253 | - //add prices to ticket |
|
| 1254 | - $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices); |
|
| 1255 | - } |
|
| 1256 | - //however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1257 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
| 1258 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1259 | - foreach ($tickets_removed as $id) { |
|
| 1260 | - $id = absint($id); |
|
| 1261 | - //get the ticket for this id |
|
| 1262 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 1263 | - //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 1264 | - $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 1265 | - foreach ($dtts as $dtt) { |
|
| 1266 | - $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 1267 | - } |
|
| 1268 | - //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1269 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
| 1270 | - //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1271 | - $tkt_to_remove->delete_permanently(); |
|
| 1272 | - } |
|
| 1052 | + return ! empty($venue_id) ? true : false; |
|
| 1053 | + } |
|
| 1054 | + //when we have the ancestor come in it's already been handled by the revision save. |
|
| 1055 | + } |
|
| 1056 | + |
|
| 1057 | + |
|
| 1058 | + /** |
|
| 1059 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1060 | + * |
|
| 1061 | + * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 1062 | + * @param array $data The request data from the form |
|
| 1063 | + * |
|
| 1064 | + * @return array |
|
| 1065 | + */ |
|
| 1066 | + protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
| 1067 | + { |
|
| 1068 | + $success = true; |
|
| 1069 | + $saved_dtt = null; |
|
| 1070 | + $saved_tickets = array(); |
|
| 1071 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1072 | + foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 1073 | + //trim all values to ensure any excess whitespace is removed. |
|
| 1074 | + $dtt = array_map('trim', $dtt); |
|
| 1075 | + $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
| 1076 | + : $dtt['DTT_EVT_start']; |
|
| 1077 | + $datetime_values = array( |
|
| 1078 | + 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 1079 | + 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 1080 | + 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 1081 | + 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 1082 | + 'DTT_order' => $row, |
|
| 1083 | + ); |
|
| 1084 | + //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. |
|
| 1085 | + if ( ! empty($dtt['DTT_ID'])) { |
|
| 1086 | + $DTM = EE_Registry::instance() |
|
| 1087 | + ->load_model('Datetime', array($evtobj->get_timezone())) |
|
| 1088 | + ->get_one_by_ID($dtt['DTT_ID']); |
|
| 1089 | + $DTM->set_date_format($incoming_date_formats[0]); |
|
| 1090 | + $DTM->set_time_format($incoming_date_formats[1]); |
|
| 1091 | + foreach ($datetime_values as $field => $value) { |
|
| 1092 | + $DTM->set($field, $value); |
|
| 1093 | + } |
|
| 1094 | + //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
|
| 1095 | + $saved_dtts[ $DTM->ID() ] = $DTM; |
|
| 1096 | + } else { |
|
| 1097 | + $DTM = EE_Registry::instance()->load_class( |
|
| 1098 | + 'Datetime', |
|
| 1099 | + array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats), |
|
| 1100 | + false, |
|
| 1101 | + false |
|
| 1102 | + ); |
|
| 1103 | + foreach ($datetime_values as $field => $value) { |
|
| 1104 | + $DTM->set($field, $value); |
|
| 1105 | + } |
|
| 1106 | + } |
|
| 1107 | + $DTM->save(); |
|
| 1108 | + $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
| 1109 | + //load DTT helper |
|
| 1110 | + //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. |
|
| 1111 | + if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
| 1112 | + $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
| 1113 | + $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
| 1114 | + $DTT->save(); |
|
| 1115 | + } |
|
| 1116 | + //now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave. |
|
| 1117 | + $saved_dtt = $DTT; |
|
| 1118 | + $success = ! $success ? $success : $DTT; |
|
| 1119 | + //if ANY of these updates fail then we want the appropriate global error message. |
|
| 1120 | + // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
| 1121 | + } |
|
| 1122 | + //no dtts get deleted so we don't do any of that logic here. |
|
| 1123 | + //update tickets next |
|
| 1124 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 1125 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 1126 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1127 | + $update_prices = false; |
|
| 1128 | + $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
| 1129 | + ? $data['edit_prices'][$row][1]['PRC_amount'] : 0; |
|
| 1130 | + // trim inputs to ensure any excess whitespace is removed. |
|
| 1131 | + $tkt = array_map('trim', $tkt); |
|
| 1132 | + if (empty($tkt['TKT_start_date'])) { |
|
| 1133 | + //let's use now in the set timezone. |
|
| 1134 | + $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
| 1135 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1136 | + } |
|
| 1137 | + if (empty($tkt['TKT_end_date'])) { |
|
| 1138 | + //use the start date of the first datetime |
|
| 1139 | + $dtt = $evtobj->first_datetime(); |
|
| 1140 | + $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
| 1141 | + $incoming_date_formats[0], |
|
| 1142 | + $incoming_date_formats[1] |
|
| 1143 | + ); |
|
| 1144 | + } |
|
| 1145 | + $TKT_values = array( |
|
| 1146 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 1147 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 1148 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 1149 | + 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
| 1150 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 1151 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 1152 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 1153 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 1154 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 1155 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 1156 | + 'TKT_row' => $row, |
|
| 1157 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
| 1158 | + 'TKT_price' => $ticket_price, |
|
| 1159 | + ); |
|
| 1160 | + //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. |
|
| 1161 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 1162 | + $TKT_values['TKT_ID'] = 0; |
|
| 1163 | + $TKT_values['TKT_is_default'] = 0; |
|
| 1164 | + $TKT_values['TKT_price'] = $ticket_price; |
|
| 1165 | + $update_prices = true; |
|
| 1166 | + } |
|
| 1167 | + //if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1168 | + //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
| 1169 | + //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1170 | + if ( ! empty($tkt['TKT_ID'])) { |
|
| 1171 | + $TKT = EE_Registry::instance() |
|
| 1172 | + ->load_model('Ticket', array($evtobj->get_timezone())) |
|
| 1173 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
| 1174 | + if ($TKT instanceof EE_Ticket) { |
|
| 1175 | + $ticket_sold = $TKT->count_related( |
|
| 1176 | + 'Registration', |
|
| 1177 | + array( |
|
| 1178 | + array( |
|
| 1179 | + 'STS_ID' => array( |
|
| 1180 | + 'NOT IN', |
|
| 1181 | + array(EEM_Registration::status_id_incomplete), |
|
| 1182 | + ), |
|
| 1183 | + ), |
|
| 1184 | + ) |
|
| 1185 | + ) > 0 ? true : false; |
|
| 1186 | + //let's just check the total price for the existing ticket and determine if it matches the new total price. if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket. |
|
| 1187 | + $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') |
|
| 1188 | + && ! $TKT->get( |
|
| 1189 | + 'TKT_deleted' |
|
| 1190 | + ) ? true : false; |
|
| 1191 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1192 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1193 | + //set new values |
|
| 1194 | + foreach ($TKT_values as $field => $value) { |
|
| 1195 | + if ($field == 'TKT_qty') { |
|
| 1196 | + $TKT->set_qty($value); |
|
| 1197 | + } else { |
|
| 1198 | + $TKT->set($field, $value); |
|
| 1199 | + } |
|
| 1200 | + } |
|
| 1201 | + //if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
| 1202 | + if ($create_new_TKT) { |
|
| 1203 | + //archive the old ticket first |
|
| 1204 | + $TKT->set('TKT_deleted', 1); |
|
| 1205 | + $TKT->save(); |
|
| 1206 | + //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
| 1207 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1208 | + //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
|
| 1209 | + $TKT = clone $TKT; |
|
| 1210 | + $TKT->set('TKT_ID', 0); |
|
| 1211 | + $TKT->set('TKT_deleted', 0); |
|
| 1212 | + $TKT->set('TKT_price', $ticket_price); |
|
| 1213 | + $TKT->set('TKT_sold', 0); |
|
| 1214 | + //now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1215 | + $update_prices = true; |
|
| 1216 | + } |
|
| 1217 | + //make sure price is set if it hasn't been already |
|
| 1218 | + $TKT->set('TKT_price', $ticket_price); |
|
| 1219 | + } |
|
| 1220 | + } else { |
|
| 1221 | + //no TKT_id so a new TKT |
|
| 1222 | + $TKT_values['TKT_price'] = $ticket_price; |
|
| 1223 | + $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); |
|
| 1224 | + if ($TKT instanceof EE_Ticket) { |
|
| 1225 | + //need to reset values to properly account for the date formats |
|
| 1226 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1227 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1228 | + $TKT->set_timezone($evtobj->get_timezone()); |
|
| 1229 | + //set new values |
|
| 1230 | + foreach ($TKT_values as $field => $value) { |
|
| 1231 | + if ($field == 'TKT_qty') { |
|
| 1232 | + $TKT->set_qty($value); |
|
| 1233 | + } else { |
|
| 1234 | + $TKT->set($field, $value); |
|
| 1235 | + } |
|
| 1236 | + } |
|
| 1237 | + $update_prices = true; |
|
| 1238 | + } |
|
| 1239 | + } |
|
| 1240 | + // cap ticket qty by datetime reg limits |
|
| 1241 | + $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
| 1242 | + //update ticket. |
|
| 1243 | + $TKT->save(); |
|
| 1244 | + //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. |
|
| 1245 | + if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 1246 | + $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 1247 | + $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 1248 | + $TKT->save(); |
|
| 1249 | + } |
|
| 1250 | + //initially let's add the ticket to the dtt |
|
| 1251 | + $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
| 1252 | + $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1253 | + //add prices to ticket |
|
| 1254 | + $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices); |
|
| 1255 | + } |
|
| 1256 | + //however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1257 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
| 1258 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1259 | + foreach ($tickets_removed as $id) { |
|
| 1260 | + $id = absint($id); |
|
| 1261 | + //get the ticket for this id |
|
| 1262 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 1263 | + //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 1264 | + $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 1265 | + foreach ($dtts as $dtt) { |
|
| 1266 | + $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 1267 | + } |
|
| 1268 | + //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1269 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
| 1270 | + //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1271 | + $tkt_to_remove->delete_permanently(); |
|
| 1272 | + } |
|
| 1273 | 1273 | |
| 1274 | - return array($saved_dtt, $saved_tickets); |
|
| 1275 | - } |
|
| 1276 | - |
|
| 1277 | - |
|
| 1278 | - /** |
|
| 1279 | - * This attaches a list of given prices to a ticket. |
|
| 1280 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 1281 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 1282 | - * price info and prices are automatically "archived" via the ticket. |
|
| 1283 | - * |
|
| 1284 | - * @access private |
|
| 1285 | - * |
|
| 1286 | - * @param array $prices Array of prices from the form. |
|
| 1287 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1288 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1289 | - * |
|
| 1290 | - * @return void |
|
| 1291 | - */ |
|
| 1292 | - private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
| 1293 | - { |
|
| 1294 | - foreach ($prices as $row => $prc) { |
|
| 1295 | - $PRC_values = array( |
|
| 1296 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 1297 | - 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
| 1298 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 1299 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 1300 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 1301 | - 'PRC_is_default' => 0, //make sure prices are NOT set as default from this context |
|
| 1302 | - 'PRC_order' => $row, |
|
| 1303 | - ); |
|
| 1304 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 1305 | - $PRC_values['PRC_ID'] = 0; |
|
| 1306 | - $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
| 1307 | - } else { |
|
| 1308 | - $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 1309 | - //update this price with new values |
|
| 1310 | - foreach ($PRC_values as $field => $newprc) { |
|
| 1311 | - $PRC->set($field, $newprc); |
|
| 1312 | - } |
|
| 1313 | - $PRC->save(); |
|
| 1314 | - } |
|
| 1315 | - $ticket->_add_relation_to($PRC, 'Price'); |
|
| 1316 | - } |
|
| 1317 | - } |
|
| 1318 | - |
|
| 1319 | - |
|
| 1320 | - /** |
|
| 1321 | - * Add in our autosave ajax handlers |
|
| 1322 | - * |
|
| 1323 | - * @return void |
|
| 1324 | - */ |
|
| 1325 | - protected function _ee_autosave_create_new() |
|
| 1326 | - { |
|
| 1327 | - // $this->_ee_autosave_edit(); |
|
| 1328 | - } |
|
| 1329 | - |
|
| 1330 | - |
|
| 1331 | - protected function _ee_autosave_edit() |
|
| 1332 | - { |
|
| 1333 | - return; //TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
| 1334 | - } |
|
| 1335 | - |
|
| 1336 | - |
|
| 1337 | - /** |
|
| 1338 | - * _generate_publish_box_extra_content |
|
| 1339 | - * |
|
| 1340 | - * @access private |
|
| 1341 | - * @return void |
|
| 1342 | - */ |
|
| 1343 | - private function _generate_publish_box_extra_content() |
|
| 1344 | - { |
|
| 1345 | - //load formatter helper |
|
| 1346 | - //args for getting related registrations |
|
| 1347 | - $approved_query_args = array( |
|
| 1348 | - array( |
|
| 1349 | - 'REG_deleted' => 0, |
|
| 1350 | - 'STS_ID' => EEM_Registration::status_id_approved |
|
| 1351 | - ) |
|
| 1352 | - ); |
|
| 1353 | - $not_approved_query_args = array( |
|
| 1354 | - array( |
|
| 1355 | - 'REG_deleted' => 0, |
|
| 1356 | - 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1357 | - ), |
|
| 1358 | - ); |
|
| 1359 | - $pending_payment_query_args = array( |
|
| 1360 | - array( |
|
| 1361 | - 'REG_deleted' => 0, |
|
| 1362 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1363 | - ), |
|
| 1364 | - ); |
|
| 1365 | - // publish box |
|
| 1366 | - $publish_box_extra_args = array( |
|
| 1367 | - 'view_approved_reg_url' => add_query_arg( |
|
| 1368 | - array( |
|
| 1369 | - 'action' => 'default', |
|
| 1370 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1371 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1372 | - ), |
|
| 1373 | - REG_ADMIN_URL |
|
| 1374 | - ), |
|
| 1375 | - 'view_not_approved_reg_url' => add_query_arg( |
|
| 1376 | - array( |
|
| 1377 | - 'action' => 'default', |
|
| 1378 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1379 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1380 | - ), |
|
| 1381 | - REG_ADMIN_URL |
|
| 1382 | - ), |
|
| 1383 | - 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1384 | - array( |
|
| 1385 | - 'action' => 'default', |
|
| 1386 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1387 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1388 | - ), |
|
| 1389 | - REG_ADMIN_URL |
|
| 1390 | - ), |
|
| 1391 | - 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1392 | - 'Registration', |
|
| 1393 | - $approved_query_args |
|
| 1394 | - ), |
|
| 1395 | - 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1396 | - 'Registration', |
|
| 1397 | - $not_approved_query_args |
|
| 1398 | - ), |
|
| 1399 | - 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1400 | - 'Registration', |
|
| 1401 | - $pending_payment_query_args |
|
| 1402 | - ), |
|
| 1403 | - 'misc_pub_section_class' => apply_filters( |
|
| 1404 | - 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1405 | - 'misc-pub-section' |
|
| 1406 | - ), |
|
| 1407 | - //'email_attendees_url' => add_query_arg( |
|
| 1408 | - // array( |
|
| 1409 | - // 'event_admin_reports' => 'event_newsletter', |
|
| 1410 | - // 'event_id' => $this->_cpt_model_obj->id |
|
| 1411 | - // ), |
|
| 1412 | - // 'admin.php?page=espresso_registrations' |
|
| 1413 | - //), |
|
| 1414 | - ); |
|
| 1415 | - ob_start(); |
|
| 1416 | - do_action( |
|
| 1417 | - 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1418 | - $this->_cpt_model_obj |
|
| 1419 | - ); |
|
| 1420 | - $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1421 | - // load template |
|
| 1422 | - EEH_Template::display_template( |
|
| 1423 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1424 | - $publish_box_extra_args |
|
| 1425 | - ); |
|
| 1426 | - } |
|
| 1427 | - |
|
| 1428 | - |
|
| 1429 | - /** |
|
| 1430 | - * This just returns whatever is set as the _event object property |
|
| 1431 | - * //todo this will become obsolete once the models are in place |
|
| 1432 | - * |
|
| 1433 | - * @return object |
|
| 1434 | - */ |
|
| 1435 | - public function get_event_object() |
|
| 1436 | - { |
|
| 1437 | - return $this->_cpt_model_obj; |
|
| 1438 | - } |
|
| 1439 | - |
|
| 1440 | - |
|
| 1441 | - |
|
| 1442 | - |
|
| 1443 | - /** METABOXES * */ |
|
| 1444 | - |
|
| 1445 | - |
|
| 1446 | - /** |
|
| 1447 | - * _register_event_editor_meta_boxes |
|
| 1448 | - * add all metaboxes related to the event_editor |
|
| 1449 | - * |
|
| 1450 | - * @return void |
|
| 1451 | - */ |
|
| 1452 | - protected function _register_event_editor_meta_boxes() |
|
| 1453 | - { |
|
| 1454 | - $this->verify_cpt_object(); |
|
| 1455 | - add_meta_box( |
|
| 1456 | - 'espresso_event_editor_tickets', |
|
| 1457 | - esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1458 | - array($this, 'ticket_metabox'), |
|
| 1459 | - $this->page_slug, |
|
| 1460 | - 'normal', |
|
| 1461 | - 'high' |
|
| 1462 | - ); |
|
| 1463 | - add_meta_box( |
|
| 1464 | - 'espresso_event_editor_event_options', |
|
| 1465 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1466 | - array($this, 'registration_options_meta_box'), |
|
| 1467 | - $this->page_slug, |
|
| 1468 | - 'side', |
|
| 1469 | - 'default' |
|
| 1470 | - ); |
|
| 1471 | - // NOTE: if you're looking for other metaboxes in here, |
|
| 1472 | - // where a metabox has a related management page in the admin |
|
| 1473 | - // you will find it setup in the related management page's "_Hooks" file. |
|
| 1474 | - // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1475 | - } |
|
| 1476 | - |
|
| 1477 | - |
|
| 1478 | - public function ticket_metabox() |
|
| 1479 | - { |
|
| 1480 | - $existing_datetime_ids = $existing_ticket_ids = array(); |
|
| 1481 | - //defaults for template args |
|
| 1482 | - $template_args = array( |
|
| 1483 | - 'existing_datetime_ids' => '', |
|
| 1484 | - 'event_datetime_help_link' => '', |
|
| 1485 | - 'ticket_options_help_link' => '', |
|
| 1486 | - 'time' => null, |
|
| 1487 | - 'ticket_rows' => '', |
|
| 1488 | - 'existing_ticket_ids' => '', |
|
| 1489 | - 'total_ticket_rows' => 1, |
|
| 1490 | - 'ticket_js_structure' => '', |
|
| 1491 | - 'trash_icon' => 'ee-lock-icon', |
|
| 1492 | - 'disabled' => '', |
|
| 1493 | - ); |
|
| 1494 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1495 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1496 | - /** |
|
| 1497 | - * 1. Start with retrieving Datetimes |
|
| 1498 | - * 2. Fore each datetime get related tickets |
|
| 1499 | - * 3. For each ticket get related prices |
|
| 1500 | - */ |
|
| 1501 | - $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
| 1502 | - /** @type EE_Datetime $first_datetime */ |
|
| 1503 | - $first_datetime = reset($times); |
|
| 1504 | - //do we get related tickets? |
|
| 1505 | - if ($first_datetime instanceof EE_Datetime |
|
| 1506 | - && $first_datetime->ID() !== 0 |
|
| 1507 | - ) { |
|
| 1508 | - $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1509 | - $template_args['time'] = $first_datetime; |
|
| 1510 | - $related_tickets = $first_datetime->tickets( |
|
| 1511 | - array( |
|
| 1512 | - array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
| 1513 | - 'default_where_conditions' => 'none', |
|
| 1514 | - ) |
|
| 1515 | - ); |
|
| 1516 | - if ( ! empty($related_tickets)) { |
|
| 1517 | - $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1518 | - $row = 0; |
|
| 1519 | - foreach ($related_tickets as $ticket) { |
|
| 1520 | - $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1521 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1522 | - $row++; |
|
| 1523 | - } |
|
| 1524 | - } else { |
|
| 1525 | - $template_args['total_ticket_rows'] = 1; |
|
| 1526 | - /** @type EE_Ticket $ticket */ |
|
| 1527 | - $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
| 1528 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1529 | - } |
|
| 1530 | - } else { |
|
| 1531 | - $template_args['time'] = $times[0]; |
|
| 1532 | - /** @type EE_Ticket $ticket */ |
|
| 1533 | - $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
| 1534 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
| 1535 | - // NOTE: we're just sending the first default row |
|
| 1536 | - // (decaf can't manage default tickets so this should be sufficient); |
|
| 1537 | - } |
|
| 1538 | - $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1539 | - 'event_editor_event_datetimes_help_tab' |
|
| 1540 | - ); |
|
| 1541 | - $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1542 | - $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1543 | - $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1544 | - $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1545 | - EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
|
| 1546 | - true |
|
| 1547 | - ); |
|
| 1548 | - $template = apply_filters( |
|
| 1549 | - 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1550 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1551 | - ); |
|
| 1552 | - EEH_Template::display_template($template, $template_args); |
|
| 1553 | - } |
|
| 1554 | - |
|
| 1555 | - |
|
| 1556 | - /** |
|
| 1557 | - * Setup an individual ticket form for the decaf event editor page |
|
| 1558 | - * |
|
| 1559 | - * @access private |
|
| 1560 | - * @param EE_Ticket $ticket the ticket object |
|
| 1561 | - * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1562 | - * @param int $row |
|
| 1563 | - * @return string generated html for the ticket row. |
|
| 1564 | - */ |
|
| 1565 | - private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1566 | - { |
|
| 1567 | - $template_args = array( |
|
| 1568 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1569 | - 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1570 | - : '', |
|
| 1571 | - 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1572 | - 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1573 | - 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1574 | - 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1575 | - 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1576 | - 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1577 | - 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1578 | - 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1579 | - 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1580 | - 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1581 | - && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1582 | - ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
| 1583 | - 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1584 | - : ' disabled=disabled', |
|
| 1585 | - ); |
|
| 1586 | - $price = $ticket->ID() !== 0 |
|
| 1587 | - ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) |
|
| 1588 | - : EE_Registry::instance()->load_model('Price')->create_default_object(); |
|
| 1589 | - $price_args = array( |
|
| 1590 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1591 | - 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1592 | - 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1593 | - 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1594 | - 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1595 | - ); |
|
| 1596 | - //make sure we have default start and end dates if skeleton |
|
| 1597 | - //handle rows that should NOT be empty |
|
| 1598 | - if (empty($template_args['TKT_start_date'])) { |
|
| 1599 | - //if empty then the start date will be now. |
|
| 1600 | - $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1601 | - } |
|
| 1602 | - if (empty($template_args['TKT_end_date'])) { |
|
| 1603 | - //get the earliest datetime (if present); |
|
| 1604 | - $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
| 1605 | - ? $this->_cpt_model_obj->get_first_related( |
|
| 1606 | - 'Datetime', |
|
| 1607 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1608 | - ) |
|
| 1609 | - : null; |
|
| 1610 | - if ( ! empty($earliest_dtt)) { |
|
| 1611 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
| 1612 | - } else { |
|
| 1613 | - $template_args['TKT_end_date'] = date( |
|
| 1614 | - 'Y-m-d h:i a', |
|
| 1615 | - mktime(0, 0, 0, date("m"), date("d") + 7, date("Y")) |
|
| 1616 | - ); |
|
| 1617 | - } |
|
| 1618 | - } |
|
| 1619 | - $template_args = array_merge($template_args, $price_args); |
|
| 1620 | - $template = apply_filters( |
|
| 1621 | - 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1622 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1623 | - $ticket |
|
| 1624 | - ); |
|
| 1274 | + return array($saved_dtt, $saved_tickets); |
|
| 1275 | + } |
|
| 1276 | + |
|
| 1277 | + |
|
| 1278 | + /** |
|
| 1279 | + * This attaches a list of given prices to a ticket. |
|
| 1280 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 1281 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 1282 | + * price info and prices are automatically "archived" via the ticket. |
|
| 1283 | + * |
|
| 1284 | + * @access private |
|
| 1285 | + * |
|
| 1286 | + * @param array $prices Array of prices from the form. |
|
| 1287 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1288 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1289 | + * |
|
| 1290 | + * @return void |
|
| 1291 | + */ |
|
| 1292 | + private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
| 1293 | + { |
|
| 1294 | + foreach ($prices as $row => $prc) { |
|
| 1295 | + $PRC_values = array( |
|
| 1296 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 1297 | + 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
| 1298 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 1299 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 1300 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 1301 | + 'PRC_is_default' => 0, //make sure prices are NOT set as default from this context |
|
| 1302 | + 'PRC_order' => $row, |
|
| 1303 | + ); |
|
| 1304 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 1305 | + $PRC_values['PRC_ID'] = 0; |
|
| 1306 | + $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
| 1307 | + } else { |
|
| 1308 | + $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 1309 | + //update this price with new values |
|
| 1310 | + foreach ($PRC_values as $field => $newprc) { |
|
| 1311 | + $PRC->set($field, $newprc); |
|
| 1312 | + } |
|
| 1313 | + $PRC->save(); |
|
| 1314 | + } |
|
| 1315 | + $ticket->_add_relation_to($PRC, 'Price'); |
|
| 1316 | + } |
|
| 1317 | + } |
|
| 1318 | + |
|
| 1319 | + |
|
| 1320 | + /** |
|
| 1321 | + * Add in our autosave ajax handlers |
|
| 1322 | + * |
|
| 1323 | + * @return void |
|
| 1324 | + */ |
|
| 1325 | + protected function _ee_autosave_create_new() |
|
| 1326 | + { |
|
| 1327 | + // $this->_ee_autosave_edit(); |
|
| 1328 | + } |
|
| 1329 | + |
|
| 1330 | + |
|
| 1331 | + protected function _ee_autosave_edit() |
|
| 1332 | + { |
|
| 1333 | + return; //TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
| 1334 | + } |
|
| 1335 | + |
|
| 1336 | + |
|
| 1337 | + /** |
|
| 1338 | + * _generate_publish_box_extra_content |
|
| 1339 | + * |
|
| 1340 | + * @access private |
|
| 1341 | + * @return void |
|
| 1342 | + */ |
|
| 1343 | + private function _generate_publish_box_extra_content() |
|
| 1344 | + { |
|
| 1345 | + //load formatter helper |
|
| 1346 | + //args for getting related registrations |
|
| 1347 | + $approved_query_args = array( |
|
| 1348 | + array( |
|
| 1349 | + 'REG_deleted' => 0, |
|
| 1350 | + 'STS_ID' => EEM_Registration::status_id_approved |
|
| 1351 | + ) |
|
| 1352 | + ); |
|
| 1353 | + $not_approved_query_args = array( |
|
| 1354 | + array( |
|
| 1355 | + 'REG_deleted' => 0, |
|
| 1356 | + 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1357 | + ), |
|
| 1358 | + ); |
|
| 1359 | + $pending_payment_query_args = array( |
|
| 1360 | + array( |
|
| 1361 | + 'REG_deleted' => 0, |
|
| 1362 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1363 | + ), |
|
| 1364 | + ); |
|
| 1365 | + // publish box |
|
| 1366 | + $publish_box_extra_args = array( |
|
| 1367 | + 'view_approved_reg_url' => add_query_arg( |
|
| 1368 | + array( |
|
| 1369 | + 'action' => 'default', |
|
| 1370 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1371 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1372 | + ), |
|
| 1373 | + REG_ADMIN_URL |
|
| 1374 | + ), |
|
| 1375 | + 'view_not_approved_reg_url' => add_query_arg( |
|
| 1376 | + array( |
|
| 1377 | + 'action' => 'default', |
|
| 1378 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1379 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1380 | + ), |
|
| 1381 | + REG_ADMIN_URL |
|
| 1382 | + ), |
|
| 1383 | + 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1384 | + array( |
|
| 1385 | + 'action' => 'default', |
|
| 1386 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1387 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1388 | + ), |
|
| 1389 | + REG_ADMIN_URL |
|
| 1390 | + ), |
|
| 1391 | + 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1392 | + 'Registration', |
|
| 1393 | + $approved_query_args |
|
| 1394 | + ), |
|
| 1395 | + 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1396 | + 'Registration', |
|
| 1397 | + $not_approved_query_args |
|
| 1398 | + ), |
|
| 1399 | + 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1400 | + 'Registration', |
|
| 1401 | + $pending_payment_query_args |
|
| 1402 | + ), |
|
| 1403 | + 'misc_pub_section_class' => apply_filters( |
|
| 1404 | + 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1405 | + 'misc-pub-section' |
|
| 1406 | + ), |
|
| 1407 | + //'email_attendees_url' => add_query_arg( |
|
| 1408 | + // array( |
|
| 1409 | + // 'event_admin_reports' => 'event_newsletter', |
|
| 1410 | + // 'event_id' => $this->_cpt_model_obj->id |
|
| 1411 | + // ), |
|
| 1412 | + // 'admin.php?page=espresso_registrations' |
|
| 1413 | + //), |
|
| 1414 | + ); |
|
| 1415 | + ob_start(); |
|
| 1416 | + do_action( |
|
| 1417 | + 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1418 | + $this->_cpt_model_obj |
|
| 1419 | + ); |
|
| 1420 | + $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1421 | + // load template |
|
| 1422 | + EEH_Template::display_template( |
|
| 1423 | + EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1424 | + $publish_box_extra_args |
|
| 1425 | + ); |
|
| 1426 | + } |
|
| 1427 | + |
|
| 1428 | + |
|
| 1429 | + /** |
|
| 1430 | + * This just returns whatever is set as the _event object property |
|
| 1431 | + * //todo this will become obsolete once the models are in place |
|
| 1432 | + * |
|
| 1433 | + * @return object |
|
| 1434 | + */ |
|
| 1435 | + public function get_event_object() |
|
| 1436 | + { |
|
| 1437 | + return $this->_cpt_model_obj; |
|
| 1438 | + } |
|
| 1439 | + |
|
| 1440 | + |
|
| 1441 | + |
|
| 1442 | + |
|
| 1443 | + /** METABOXES * */ |
|
| 1444 | + |
|
| 1445 | + |
|
| 1446 | + /** |
|
| 1447 | + * _register_event_editor_meta_boxes |
|
| 1448 | + * add all metaboxes related to the event_editor |
|
| 1449 | + * |
|
| 1450 | + * @return void |
|
| 1451 | + */ |
|
| 1452 | + protected function _register_event_editor_meta_boxes() |
|
| 1453 | + { |
|
| 1454 | + $this->verify_cpt_object(); |
|
| 1455 | + add_meta_box( |
|
| 1456 | + 'espresso_event_editor_tickets', |
|
| 1457 | + esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1458 | + array($this, 'ticket_metabox'), |
|
| 1459 | + $this->page_slug, |
|
| 1460 | + 'normal', |
|
| 1461 | + 'high' |
|
| 1462 | + ); |
|
| 1463 | + add_meta_box( |
|
| 1464 | + 'espresso_event_editor_event_options', |
|
| 1465 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1466 | + array($this, 'registration_options_meta_box'), |
|
| 1467 | + $this->page_slug, |
|
| 1468 | + 'side', |
|
| 1469 | + 'default' |
|
| 1470 | + ); |
|
| 1471 | + // NOTE: if you're looking for other metaboxes in here, |
|
| 1472 | + // where a metabox has a related management page in the admin |
|
| 1473 | + // you will find it setup in the related management page's "_Hooks" file. |
|
| 1474 | + // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1475 | + } |
|
| 1476 | + |
|
| 1477 | + |
|
| 1478 | + public function ticket_metabox() |
|
| 1479 | + { |
|
| 1480 | + $existing_datetime_ids = $existing_ticket_ids = array(); |
|
| 1481 | + //defaults for template args |
|
| 1482 | + $template_args = array( |
|
| 1483 | + 'existing_datetime_ids' => '', |
|
| 1484 | + 'event_datetime_help_link' => '', |
|
| 1485 | + 'ticket_options_help_link' => '', |
|
| 1486 | + 'time' => null, |
|
| 1487 | + 'ticket_rows' => '', |
|
| 1488 | + 'existing_ticket_ids' => '', |
|
| 1489 | + 'total_ticket_rows' => 1, |
|
| 1490 | + 'ticket_js_structure' => '', |
|
| 1491 | + 'trash_icon' => 'ee-lock-icon', |
|
| 1492 | + 'disabled' => '', |
|
| 1493 | + ); |
|
| 1494 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1495 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1496 | + /** |
|
| 1497 | + * 1. Start with retrieving Datetimes |
|
| 1498 | + * 2. Fore each datetime get related tickets |
|
| 1499 | + * 3. For each ticket get related prices |
|
| 1500 | + */ |
|
| 1501 | + $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
| 1502 | + /** @type EE_Datetime $first_datetime */ |
|
| 1503 | + $first_datetime = reset($times); |
|
| 1504 | + //do we get related tickets? |
|
| 1505 | + if ($first_datetime instanceof EE_Datetime |
|
| 1506 | + && $first_datetime->ID() !== 0 |
|
| 1507 | + ) { |
|
| 1508 | + $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1509 | + $template_args['time'] = $first_datetime; |
|
| 1510 | + $related_tickets = $first_datetime->tickets( |
|
| 1511 | + array( |
|
| 1512 | + array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
| 1513 | + 'default_where_conditions' => 'none', |
|
| 1514 | + ) |
|
| 1515 | + ); |
|
| 1516 | + if ( ! empty($related_tickets)) { |
|
| 1517 | + $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1518 | + $row = 0; |
|
| 1519 | + foreach ($related_tickets as $ticket) { |
|
| 1520 | + $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1521 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1522 | + $row++; |
|
| 1523 | + } |
|
| 1524 | + } else { |
|
| 1525 | + $template_args['total_ticket_rows'] = 1; |
|
| 1526 | + /** @type EE_Ticket $ticket */ |
|
| 1527 | + $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
| 1528 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1529 | + } |
|
| 1530 | + } else { |
|
| 1531 | + $template_args['time'] = $times[0]; |
|
| 1532 | + /** @type EE_Ticket $ticket */ |
|
| 1533 | + $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
| 1534 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
| 1535 | + // NOTE: we're just sending the first default row |
|
| 1536 | + // (decaf can't manage default tickets so this should be sufficient); |
|
| 1537 | + } |
|
| 1538 | + $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1539 | + 'event_editor_event_datetimes_help_tab' |
|
| 1540 | + ); |
|
| 1541 | + $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1542 | + $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1543 | + $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1544 | + $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1545 | + EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
|
| 1546 | + true |
|
| 1547 | + ); |
|
| 1548 | + $template = apply_filters( |
|
| 1549 | + 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1550 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1551 | + ); |
|
| 1552 | + EEH_Template::display_template($template, $template_args); |
|
| 1553 | + } |
|
| 1554 | + |
|
| 1555 | + |
|
| 1556 | + /** |
|
| 1557 | + * Setup an individual ticket form for the decaf event editor page |
|
| 1558 | + * |
|
| 1559 | + * @access private |
|
| 1560 | + * @param EE_Ticket $ticket the ticket object |
|
| 1561 | + * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1562 | + * @param int $row |
|
| 1563 | + * @return string generated html for the ticket row. |
|
| 1564 | + */ |
|
| 1565 | + private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1566 | + { |
|
| 1567 | + $template_args = array( |
|
| 1568 | + 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1569 | + 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1570 | + : '', |
|
| 1571 | + 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1572 | + 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1573 | + 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1574 | + 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1575 | + 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1576 | + 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1577 | + 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1578 | + 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1579 | + 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1580 | + 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1581 | + && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1582 | + ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
| 1583 | + 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1584 | + : ' disabled=disabled', |
|
| 1585 | + ); |
|
| 1586 | + $price = $ticket->ID() !== 0 |
|
| 1587 | + ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) |
|
| 1588 | + : EE_Registry::instance()->load_model('Price')->create_default_object(); |
|
| 1589 | + $price_args = array( |
|
| 1590 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1591 | + 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1592 | + 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1593 | + 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1594 | + 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1595 | + ); |
|
| 1596 | + //make sure we have default start and end dates if skeleton |
|
| 1597 | + //handle rows that should NOT be empty |
|
| 1598 | + if (empty($template_args['TKT_start_date'])) { |
|
| 1599 | + //if empty then the start date will be now. |
|
| 1600 | + $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1601 | + } |
|
| 1602 | + if (empty($template_args['TKT_end_date'])) { |
|
| 1603 | + //get the earliest datetime (if present); |
|
| 1604 | + $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
| 1605 | + ? $this->_cpt_model_obj->get_first_related( |
|
| 1606 | + 'Datetime', |
|
| 1607 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1608 | + ) |
|
| 1609 | + : null; |
|
| 1610 | + if ( ! empty($earliest_dtt)) { |
|
| 1611 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
| 1612 | + } else { |
|
| 1613 | + $template_args['TKT_end_date'] = date( |
|
| 1614 | + 'Y-m-d h:i a', |
|
| 1615 | + mktime(0, 0, 0, date("m"), date("d") + 7, date("Y")) |
|
| 1616 | + ); |
|
| 1617 | + } |
|
| 1618 | + } |
|
| 1619 | + $template_args = array_merge($template_args, $price_args); |
|
| 1620 | + $template = apply_filters( |
|
| 1621 | + 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1622 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1623 | + $ticket |
|
| 1624 | + ); |
|
| 1625 | 1625 | |
| 1626 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1627 | - } |
|
| 1628 | - |
|
| 1629 | - |
|
| 1630 | - public function registration_options_meta_box() |
|
| 1631 | - { |
|
| 1632 | - $yes_no_values = array( |
|
| 1633 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 1634 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 1635 | - ); |
|
| 1636 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1637 | - array( |
|
| 1638 | - EEM_Registration::status_id_cancelled, |
|
| 1639 | - EEM_Registration::status_id_declined, |
|
| 1640 | - EEM_Registration::status_id_incomplete, |
|
| 1641 | - ), |
|
| 1642 | - true |
|
| 1643 | - ); |
|
| 1644 | - //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1645 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1646 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1647 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1648 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1649 | - 'default_reg_status', |
|
| 1650 | - $default_reg_status_values, |
|
| 1651 | - $this->_cpt_model_obj->default_registration_status() |
|
| 1652 | - ); |
|
| 1653 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1654 | - 'display_desc', |
|
| 1655 | - $yes_no_values, |
|
| 1656 | - $this->_cpt_model_obj->display_description() |
|
| 1657 | - ); |
|
| 1658 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1659 | - 'display_ticket_selector', |
|
| 1660 | - $yes_no_values, |
|
| 1661 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1662 | - '', |
|
| 1663 | - '', |
|
| 1664 | - false |
|
| 1665 | - ); |
|
| 1666 | - $template_args['additional_registration_options'] = apply_filters( |
|
| 1667 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1668 | - '', |
|
| 1669 | - $template_args, |
|
| 1670 | - $yes_no_values, |
|
| 1671 | - $default_reg_status_values |
|
| 1672 | - ); |
|
| 1673 | - EEH_Template::display_template( |
|
| 1674 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1675 | - $template_args |
|
| 1676 | - ); |
|
| 1677 | - } |
|
| 1678 | - |
|
| 1679 | - |
|
| 1680 | - /** |
|
| 1681 | - * _get_events() |
|
| 1682 | - * This method simply returns all the events (for the given _view and paging) |
|
| 1683 | - * |
|
| 1684 | - * @access public |
|
| 1685 | - * |
|
| 1686 | - * @param int $per_page count of items per page (20 default); |
|
| 1687 | - * @param int $current_page what is the current page being viewed. |
|
| 1688 | - * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1689 | - * If FALSE then we return an array of event objects |
|
| 1690 | - * that match the given _view and paging parameters. |
|
| 1691 | - * |
|
| 1692 | - * @return array an array of event objects. |
|
| 1693 | - */ |
|
| 1694 | - public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1695 | - { |
|
| 1696 | - $EEME = $this->_event_model(); |
|
| 1697 | - $offset = ($current_page - 1) * $per_page; |
|
| 1698 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1699 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
| 1700 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
|
| 1701 | - if (isset($this->_req_data['month_range'])) { |
|
| 1702 | - $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
| 1703 | - $month_r = ! empty($pieces[0]) ? date('m', strtotime($pieces[0])) : ''; |
|
| 1704 | - $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1705 | - } |
|
| 1706 | - $where = array(); |
|
| 1707 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1708 | - //determine what post_status our condition will have for the query. |
|
| 1709 | - switch ($status) { |
|
| 1710 | - case 'month' : |
|
| 1711 | - case 'today' : |
|
| 1712 | - case null : |
|
| 1713 | - case 'all' : |
|
| 1714 | - break; |
|
| 1715 | - case 'draft' : |
|
| 1716 | - $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
| 1717 | - break; |
|
| 1718 | - default : |
|
| 1719 | - $where['status'] = $status; |
|
| 1720 | - } |
|
| 1721 | - //categories? |
|
| 1722 | - $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 1723 | - ? $this->_req_data['EVT_CAT'] : null; |
|
| 1724 | - if ( ! empty ($category)) { |
|
| 1725 | - $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1726 | - $where['Term_Taxonomy.term_id'] = $category; |
|
| 1727 | - } |
|
| 1728 | - //date where conditions |
|
| 1729 | - $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1730 | - if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
|
| 1731 | - $DateTime = new DateTime( |
|
| 1732 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1733 | - new DateTimeZone(EEM_Datetime::instance()->get_timezone()) |
|
| 1734 | - ); |
|
| 1735 | - $start = $DateTime->format(implode(' ', $start_formats)); |
|
| 1736 | - $end = $DateTime->setDate($year_r, $month_r, $DateTime->format('t'))->setTime(23, 59, 59)->format( |
|
| 1737 | - implode(' ', $start_formats) |
|
| 1738 | - ); |
|
| 1739 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1740 | - } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { |
|
| 1741 | - $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1742 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1743 | - $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1744 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1745 | - } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { |
|
| 1746 | - $now = date('Y-m-01'); |
|
| 1747 | - $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1748 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1749 | - $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1750 | - ->setTime(23, 59, 59) |
|
| 1751 | - ->format(implode(' ', $start_formats)); |
|
| 1752 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1753 | - } |
|
| 1754 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1755 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1756 | - } else { |
|
| 1757 | - if ( ! isset($where['status'])) { |
|
| 1758 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1759 | - $where['OR'] = array( |
|
| 1760 | - 'status*restrict_private' => array('!=', 'private'), |
|
| 1761 | - 'AND' => array( |
|
| 1762 | - 'status*inclusive' => array('=', 'private'), |
|
| 1763 | - 'EVT_wp_user' => get_current_user_id(), |
|
| 1764 | - ), |
|
| 1765 | - ); |
|
| 1766 | - } |
|
| 1767 | - } |
|
| 1768 | - } |
|
| 1769 | - if (isset($this->_req_data['EVT_wp_user'])) { |
|
| 1770 | - if ($this->_req_data['EVT_wp_user'] != get_current_user_id() |
|
| 1771 | - && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 1772 | - ) { |
|
| 1773 | - $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
| 1774 | - } |
|
| 1775 | - } |
|
| 1776 | - //search query handling |
|
| 1777 | - if (isset($this->_req_data['s'])) { |
|
| 1778 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1779 | - $where['OR'] = array( |
|
| 1780 | - 'EVT_name' => array('LIKE', $search_string), |
|
| 1781 | - 'EVT_desc' => array('LIKE', $search_string), |
|
| 1782 | - 'EVT_short_desc' => array('LIKE', $search_string), |
|
| 1783 | - ); |
|
| 1784 | - } |
|
| 1785 | - $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
| 1786 | - $query_params = apply_filters( |
|
| 1787 | - 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 1788 | - array( |
|
| 1789 | - $where, |
|
| 1790 | - 'limit' => $limit, |
|
| 1791 | - 'order_by' => $orderby, |
|
| 1792 | - 'order' => $order, |
|
| 1793 | - 'group_by' => 'EVT_ID', |
|
| 1794 | - ), |
|
| 1795 | - $this->_req_data |
|
| 1796 | - ); |
|
| 1797 | - //let's first check if we have special requests coming in. |
|
| 1798 | - if (isset($this->_req_data['active_status'])) { |
|
| 1799 | - switch ($this->_req_data['active_status']) { |
|
| 1800 | - case 'upcoming' : |
|
| 1801 | - return $EEME->get_upcoming_events($query_params, $count); |
|
| 1802 | - break; |
|
| 1803 | - case 'expired' : |
|
| 1804 | - return $EEME->get_expired_events($query_params, $count); |
|
| 1805 | - break; |
|
| 1806 | - case 'active' : |
|
| 1807 | - return $EEME->get_active_events($query_params, $count); |
|
| 1808 | - break; |
|
| 1809 | - case 'inactive' : |
|
| 1810 | - return $EEME->get_inactive_events($query_params, $count); |
|
| 1811 | - break; |
|
| 1812 | - } |
|
| 1813 | - } |
|
| 1814 | - $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
| 1626 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1627 | + } |
|
| 1628 | + |
|
| 1629 | + |
|
| 1630 | + public function registration_options_meta_box() |
|
| 1631 | + { |
|
| 1632 | + $yes_no_values = array( |
|
| 1633 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 1634 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 1635 | + ); |
|
| 1636 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1637 | + array( |
|
| 1638 | + EEM_Registration::status_id_cancelled, |
|
| 1639 | + EEM_Registration::status_id_declined, |
|
| 1640 | + EEM_Registration::status_id_incomplete, |
|
| 1641 | + ), |
|
| 1642 | + true |
|
| 1643 | + ); |
|
| 1644 | + //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1645 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1646 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1647 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1648 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1649 | + 'default_reg_status', |
|
| 1650 | + $default_reg_status_values, |
|
| 1651 | + $this->_cpt_model_obj->default_registration_status() |
|
| 1652 | + ); |
|
| 1653 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1654 | + 'display_desc', |
|
| 1655 | + $yes_no_values, |
|
| 1656 | + $this->_cpt_model_obj->display_description() |
|
| 1657 | + ); |
|
| 1658 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1659 | + 'display_ticket_selector', |
|
| 1660 | + $yes_no_values, |
|
| 1661 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1662 | + '', |
|
| 1663 | + '', |
|
| 1664 | + false |
|
| 1665 | + ); |
|
| 1666 | + $template_args['additional_registration_options'] = apply_filters( |
|
| 1667 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1668 | + '', |
|
| 1669 | + $template_args, |
|
| 1670 | + $yes_no_values, |
|
| 1671 | + $default_reg_status_values |
|
| 1672 | + ); |
|
| 1673 | + EEH_Template::display_template( |
|
| 1674 | + EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1675 | + $template_args |
|
| 1676 | + ); |
|
| 1677 | + } |
|
| 1678 | + |
|
| 1679 | + |
|
| 1680 | + /** |
|
| 1681 | + * _get_events() |
|
| 1682 | + * This method simply returns all the events (for the given _view and paging) |
|
| 1683 | + * |
|
| 1684 | + * @access public |
|
| 1685 | + * |
|
| 1686 | + * @param int $per_page count of items per page (20 default); |
|
| 1687 | + * @param int $current_page what is the current page being viewed. |
|
| 1688 | + * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1689 | + * If FALSE then we return an array of event objects |
|
| 1690 | + * that match the given _view and paging parameters. |
|
| 1691 | + * |
|
| 1692 | + * @return array an array of event objects. |
|
| 1693 | + */ |
|
| 1694 | + public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1695 | + { |
|
| 1696 | + $EEME = $this->_event_model(); |
|
| 1697 | + $offset = ($current_page - 1) * $per_page; |
|
| 1698 | + $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1699 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
| 1700 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
|
| 1701 | + if (isset($this->_req_data['month_range'])) { |
|
| 1702 | + $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
| 1703 | + $month_r = ! empty($pieces[0]) ? date('m', strtotime($pieces[0])) : ''; |
|
| 1704 | + $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1705 | + } |
|
| 1706 | + $where = array(); |
|
| 1707 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1708 | + //determine what post_status our condition will have for the query. |
|
| 1709 | + switch ($status) { |
|
| 1710 | + case 'month' : |
|
| 1711 | + case 'today' : |
|
| 1712 | + case null : |
|
| 1713 | + case 'all' : |
|
| 1714 | + break; |
|
| 1715 | + case 'draft' : |
|
| 1716 | + $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
| 1717 | + break; |
|
| 1718 | + default : |
|
| 1719 | + $where['status'] = $status; |
|
| 1720 | + } |
|
| 1721 | + //categories? |
|
| 1722 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 1723 | + ? $this->_req_data['EVT_CAT'] : null; |
|
| 1724 | + if ( ! empty ($category)) { |
|
| 1725 | + $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1726 | + $where['Term_Taxonomy.term_id'] = $category; |
|
| 1727 | + } |
|
| 1728 | + //date where conditions |
|
| 1729 | + $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1730 | + if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
|
| 1731 | + $DateTime = new DateTime( |
|
| 1732 | + $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1733 | + new DateTimeZone(EEM_Datetime::instance()->get_timezone()) |
|
| 1734 | + ); |
|
| 1735 | + $start = $DateTime->format(implode(' ', $start_formats)); |
|
| 1736 | + $end = $DateTime->setDate($year_r, $month_r, $DateTime->format('t'))->setTime(23, 59, 59)->format( |
|
| 1737 | + implode(' ', $start_formats) |
|
| 1738 | + ); |
|
| 1739 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1740 | + } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { |
|
| 1741 | + $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1742 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1743 | + $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1744 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1745 | + } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { |
|
| 1746 | + $now = date('Y-m-01'); |
|
| 1747 | + $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1748 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1749 | + $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1750 | + ->setTime(23, 59, 59) |
|
| 1751 | + ->format(implode(' ', $start_formats)); |
|
| 1752 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1753 | + } |
|
| 1754 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1755 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1756 | + } else { |
|
| 1757 | + if ( ! isset($where['status'])) { |
|
| 1758 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1759 | + $where['OR'] = array( |
|
| 1760 | + 'status*restrict_private' => array('!=', 'private'), |
|
| 1761 | + 'AND' => array( |
|
| 1762 | + 'status*inclusive' => array('=', 'private'), |
|
| 1763 | + 'EVT_wp_user' => get_current_user_id(), |
|
| 1764 | + ), |
|
| 1765 | + ); |
|
| 1766 | + } |
|
| 1767 | + } |
|
| 1768 | + } |
|
| 1769 | + if (isset($this->_req_data['EVT_wp_user'])) { |
|
| 1770 | + if ($this->_req_data['EVT_wp_user'] != get_current_user_id() |
|
| 1771 | + && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 1772 | + ) { |
|
| 1773 | + $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
| 1774 | + } |
|
| 1775 | + } |
|
| 1776 | + //search query handling |
|
| 1777 | + if (isset($this->_req_data['s'])) { |
|
| 1778 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1779 | + $where['OR'] = array( |
|
| 1780 | + 'EVT_name' => array('LIKE', $search_string), |
|
| 1781 | + 'EVT_desc' => array('LIKE', $search_string), |
|
| 1782 | + 'EVT_short_desc' => array('LIKE', $search_string), |
|
| 1783 | + ); |
|
| 1784 | + } |
|
| 1785 | + $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
| 1786 | + $query_params = apply_filters( |
|
| 1787 | + 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 1788 | + array( |
|
| 1789 | + $where, |
|
| 1790 | + 'limit' => $limit, |
|
| 1791 | + 'order_by' => $orderby, |
|
| 1792 | + 'order' => $order, |
|
| 1793 | + 'group_by' => 'EVT_ID', |
|
| 1794 | + ), |
|
| 1795 | + $this->_req_data |
|
| 1796 | + ); |
|
| 1797 | + //let's first check if we have special requests coming in. |
|
| 1798 | + if (isset($this->_req_data['active_status'])) { |
|
| 1799 | + switch ($this->_req_data['active_status']) { |
|
| 1800 | + case 'upcoming' : |
|
| 1801 | + return $EEME->get_upcoming_events($query_params, $count); |
|
| 1802 | + break; |
|
| 1803 | + case 'expired' : |
|
| 1804 | + return $EEME->get_expired_events($query_params, $count); |
|
| 1805 | + break; |
|
| 1806 | + case 'active' : |
|
| 1807 | + return $EEME->get_active_events($query_params, $count); |
|
| 1808 | + break; |
|
| 1809 | + case 'inactive' : |
|
| 1810 | + return $EEME->get_inactive_events($query_params, $count); |
|
| 1811 | + break; |
|
| 1812 | + } |
|
| 1813 | + } |
|
| 1814 | + $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
| 1815 | 1815 | |
| 1816 | - return $events; |
|
| 1817 | - } |
|
| 1818 | - |
|
| 1819 | - |
|
| 1820 | - /** |
|
| 1821 | - * handling for WordPress CPT actions (trash, restore, delete) |
|
| 1822 | - * |
|
| 1823 | - * @param string $post_id |
|
| 1824 | - */ |
|
| 1825 | - public function trash_cpt_item($post_id) |
|
| 1826 | - { |
|
| 1827 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1828 | - $this->_trash_or_restore_event('trash', false); |
|
| 1829 | - } |
|
| 1830 | - |
|
| 1831 | - |
|
| 1832 | - /** |
|
| 1833 | - * @param string $post_id |
|
| 1834 | - */ |
|
| 1835 | - public function restore_cpt_item($post_id) |
|
| 1836 | - { |
|
| 1837 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1838 | - $this->_trash_or_restore_event('draft', false); |
|
| 1839 | - } |
|
| 1840 | - |
|
| 1841 | - |
|
| 1842 | - /** |
|
| 1843 | - * @param string $post_id |
|
| 1844 | - */ |
|
| 1845 | - public function delete_cpt_item($post_id) |
|
| 1846 | - { |
|
| 1847 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1848 | - $this->_delete_event(false); |
|
| 1849 | - } |
|
| 1850 | - |
|
| 1851 | - |
|
| 1852 | - /** |
|
| 1853 | - * _trash_or_restore_event |
|
| 1854 | - * |
|
| 1855 | - * @access protected |
|
| 1856 | - * |
|
| 1857 | - * @param string $event_status |
|
| 1858 | - * @param bool $redirect_after |
|
| 1859 | - */ |
|
| 1860 | - protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 1861 | - { |
|
| 1862 | - //determine the event id and set to array. |
|
| 1863 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
| 1864 | - // loop thru events |
|
| 1865 | - if ($EVT_ID) { |
|
| 1866 | - // clean status |
|
| 1867 | - $event_status = sanitize_key($event_status); |
|
| 1868 | - // grab status |
|
| 1869 | - if ( ! empty($event_status)) { |
|
| 1870 | - $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1871 | - } else { |
|
| 1872 | - $success = false; |
|
| 1873 | - $msg = esc_html__( |
|
| 1874 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1875 | - 'event_espresso' |
|
| 1876 | - ); |
|
| 1877 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1878 | - } |
|
| 1879 | - } else { |
|
| 1880 | - $success = false; |
|
| 1881 | - $msg = esc_html__( |
|
| 1882 | - 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1883 | - 'event_espresso' |
|
| 1884 | - ); |
|
| 1885 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1886 | - } |
|
| 1887 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1888 | - if ($redirect_after) { |
|
| 1889 | - $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
|
| 1890 | - } |
|
| 1891 | - } |
|
| 1892 | - |
|
| 1893 | - |
|
| 1894 | - /** |
|
| 1895 | - * _trash_or_restore_events |
|
| 1896 | - * |
|
| 1897 | - * @access protected |
|
| 1898 | - * |
|
| 1899 | - * @param string $event_status |
|
| 1900 | - * |
|
| 1901 | - * @return void |
|
| 1902 | - */ |
|
| 1903 | - protected function _trash_or_restore_events($event_status = 'trash') |
|
| 1904 | - { |
|
| 1905 | - // clean status |
|
| 1906 | - $event_status = sanitize_key($event_status); |
|
| 1907 | - // grab status |
|
| 1908 | - if ( ! empty($event_status)) { |
|
| 1909 | - $success = true; |
|
| 1910 | - //determine the event id and set to array. |
|
| 1911 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 1912 | - // loop thru events |
|
| 1913 | - foreach ($EVT_IDs as $EVT_ID) { |
|
| 1914 | - if ($EVT_ID = absint($EVT_ID)) { |
|
| 1915 | - $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1916 | - $success = $results !== false ? $success : false; |
|
| 1917 | - } else { |
|
| 1918 | - $msg = sprintf( |
|
| 1919 | - esc_html__( |
|
| 1920 | - 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1921 | - 'event_espresso' |
|
| 1922 | - ), |
|
| 1923 | - $EVT_ID |
|
| 1924 | - ); |
|
| 1925 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1926 | - $success = false; |
|
| 1927 | - } |
|
| 1928 | - } |
|
| 1929 | - } else { |
|
| 1930 | - $success = false; |
|
| 1931 | - $msg = esc_html__( |
|
| 1932 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1933 | - 'event_espresso' |
|
| 1934 | - ); |
|
| 1935 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1936 | - } |
|
| 1937 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 1938 | - $success = $success ? 2 : false; |
|
| 1939 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1940 | - $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); |
|
| 1941 | - } |
|
| 1942 | - |
|
| 1943 | - |
|
| 1944 | - /** |
|
| 1945 | - * _trash_or_restore_events |
|
| 1946 | - * |
|
| 1947 | - * @access private |
|
| 1948 | - * |
|
| 1949 | - * @param int $EVT_ID |
|
| 1950 | - * @param string $event_status |
|
| 1951 | - * |
|
| 1952 | - * @return bool |
|
| 1953 | - */ |
|
| 1954 | - private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 1955 | - { |
|
| 1956 | - // grab event id |
|
| 1957 | - if ( ! $EVT_ID) { |
|
| 1958 | - $msg = esc_html__( |
|
| 1959 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 1960 | - 'event_espresso' |
|
| 1961 | - ); |
|
| 1962 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1816 | + return $events; |
|
| 1817 | + } |
|
| 1818 | + |
|
| 1819 | + |
|
| 1820 | + /** |
|
| 1821 | + * handling for WordPress CPT actions (trash, restore, delete) |
|
| 1822 | + * |
|
| 1823 | + * @param string $post_id |
|
| 1824 | + */ |
|
| 1825 | + public function trash_cpt_item($post_id) |
|
| 1826 | + { |
|
| 1827 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1828 | + $this->_trash_or_restore_event('trash', false); |
|
| 1829 | + } |
|
| 1830 | + |
|
| 1831 | + |
|
| 1832 | + /** |
|
| 1833 | + * @param string $post_id |
|
| 1834 | + */ |
|
| 1835 | + public function restore_cpt_item($post_id) |
|
| 1836 | + { |
|
| 1837 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1838 | + $this->_trash_or_restore_event('draft', false); |
|
| 1839 | + } |
|
| 1840 | + |
|
| 1841 | + |
|
| 1842 | + /** |
|
| 1843 | + * @param string $post_id |
|
| 1844 | + */ |
|
| 1845 | + public function delete_cpt_item($post_id) |
|
| 1846 | + { |
|
| 1847 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1848 | + $this->_delete_event(false); |
|
| 1849 | + } |
|
| 1850 | + |
|
| 1851 | + |
|
| 1852 | + /** |
|
| 1853 | + * _trash_or_restore_event |
|
| 1854 | + * |
|
| 1855 | + * @access protected |
|
| 1856 | + * |
|
| 1857 | + * @param string $event_status |
|
| 1858 | + * @param bool $redirect_after |
|
| 1859 | + */ |
|
| 1860 | + protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 1861 | + { |
|
| 1862 | + //determine the event id and set to array. |
|
| 1863 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
| 1864 | + // loop thru events |
|
| 1865 | + if ($EVT_ID) { |
|
| 1866 | + // clean status |
|
| 1867 | + $event_status = sanitize_key($event_status); |
|
| 1868 | + // grab status |
|
| 1869 | + if ( ! empty($event_status)) { |
|
| 1870 | + $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1871 | + } else { |
|
| 1872 | + $success = false; |
|
| 1873 | + $msg = esc_html__( |
|
| 1874 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1875 | + 'event_espresso' |
|
| 1876 | + ); |
|
| 1877 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1878 | + } |
|
| 1879 | + } else { |
|
| 1880 | + $success = false; |
|
| 1881 | + $msg = esc_html__( |
|
| 1882 | + 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1883 | + 'event_espresso' |
|
| 1884 | + ); |
|
| 1885 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1886 | + } |
|
| 1887 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1888 | + if ($redirect_after) { |
|
| 1889 | + $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
|
| 1890 | + } |
|
| 1891 | + } |
|
| 1892 | + |
|
| 1893 | + |
|
| 1894 | + /** |
|
| 1895 | + * _trash_or_restore_events |
|
| 1896 | + * |
|
| 1897 | + * @access protected |
|
| 1898 | + * |
|
| 1899 | + * @param string $event_status |
|
| 1900 | + * |
|
| 1901 | + * @return void |
|
| 1902 | + */ |
|
| 1903 | + protected function _trash_or_restore_events($event_status = 'trash') |
|
| 1904 | + { |
|
| 1905 | + // clean status |
|
| 1906 | + $event_status = sanitize_key($event_status); |
|
| 1907 | + // grab status |
|
| 1908 | + if ( ! empty($event_status)) { |
|
| 1909 | + $success = true; |
|
| 1910 | + //determine the event id and set to array. |
|
| 1911 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 1912 | + // loop thru events |
|
| 1913 | + foreach ($EVT_IDs as $EVT_ID) { |
|
| 1914 | + if ($EVT_ID = absint($EVT_ID)) { |
|
| 1915 | + $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1916 | + $success = $results !== false ? $success : false; |
|
| 1917 | + } else { |
|
| 1918 | + $msg = sprintf( |
|
| 1919 | + esc_html__( |
|
| 1920 | + 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1921 | + 'event_espresso' |
|
| 1922 | + ), |
|
| 1923 | + $EVT_ID |
|
| 1924 | + ); |
|
| 1925 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1926 | + $success = false; |
|
| 1927 | + } |
|
| 1928 | + } |
|
| 1929 | + } else { |
|
| 1930 | + $success = false; |
|
| 1931 | + $msg = esc_html__( |
|
| 1932 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1933 | + 'event_espresso' |
|
| 1934 | + ); |
|
| 1935 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1936 | + } |
|
| 1937 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 1938 | + $success = $success ? 2 : false; |
|
| 1939 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1940 | + $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); |
|
| 1941 | + } |
|
| 1942 | + |
|
| 1943 | + |
|
| 1944 | + /** |
|
| 1945 | + * _trash_or_restore_events |
|
| 1946 | + * |
|
| 1947 | + * @access private |
|
| 1948 | + * |
|
| 1949 | + * @param int $EVT_ID |
|
| 1950 | + * @param string $event_status |
|
| 1951 | + * |
|
| 1952 | + * @return bool |
|
| 1953 | + */ |
|
| 1954 | + private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 1955 | + { |
|
| 1956 | + // grab event id |
|
| 1957 | + if ( ! $EVT_ID) { |
|
| 1958 | + $msg = esc_html__( |
|
| 1959 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 1960 | + 'event_espresso' |
|
| 1961 | + ); |
|
| 1962 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1963 | 1963 | |
| 1964 | - return false; |
|
| 1965 | - } |
|
| 1966 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 1967 | - // clean status |
|
| 1968 | - $event_status = sanitize_key($event_status); |
|
| 1969 | - // grab status |
|
| 1970 | - if (empty($event_status)) { |
|
| 1971 | - $msg = esc_html__( |
|
| 1972 | - 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 1973 | - 'event_espresso' |
|
| 1974 | - ); |
|
| 1975 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1964 | + return false; |
|
| 1965 | + } |
|
| 1966 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 1967 | + // clean status |
|
| 1968 | + $event_status = sanitize_key($event_status); |
|
| 1969 | + // grab status |
|
| 1970 | + if (empty($event_status)) { |
|
| 1971 | + $msg = esc_html__( |
|
| 1972 | + 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 1973 | + 'event_espresso' |
|
| 1974 | + ); |
|
| 1975 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1976 | 1976 | |
| 1977 | - return false; |
|
| 1978 | - } |
|
| 1979 | - // was event trashed or restored ? |
|
| 1980 | - switch ($event_status) { |
|
| 1981 | - case 'draft' : |
|
| 1982 | - $action = 'restored from the trash'; |
|
| 1983 | - $hook = 'AHEE_event_restored_from_trash'; |
|
| 1984 | - break; |
|
| 1985 | - case 'trash' : |
|
| 1986 | - $action = 'moved to the trash'; |
|
| 1987 | - $hook = 'AHEE_event_moved_to_trash'; |
|
| 1988 | - break; |
|
| 1989 | - default : |
|
| 1990 | - $action = 'updated'; |
|
| 1991 | - $hook = false; |
|
| 1992 | - } |
|
| 1993 | - //use class to change status |
|
| 1994 | - $this->_cpt_model_obj->set_status($event_status); |
|
| 1995 | - $success = $this->_cpt_model_obj->save(); |
|
| 1996 | - if ($success === false) { |
|
| 1997 | - $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 1998 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1977 | + return false; |
|
| 1978 | + } |
|
| 1979 | + // was event trashed or restored ? |
|
| 1980 | + switch ($event_status) { |
|
| 1981 | + case 'draft' : |
|
| 1982 | + $action = 'restored from the trash'; |
|
| 1983 | + $hook = 'AHEE_event_restored_from_trash'; |
|
| 1984 | + break; |
|
| 1985 | + case 'trash' : |
|
| 1986 | + $action = 'moved to the trash'; |
|
| 1987 | + $hook = 'AHEE_event_moved_to_trash'; |
|
| 1988 | + break; |
|
| 1989 | + default : |
|
| 1990 | + $action = 'updated'; |
|
| 1991 | + $hook = false; |
|
| 1992 | + } |
|
| 1993 | + //use class to change status |
|
| 1994 | + $this->_cpt_model_obj->set_status($event_status); |
|
| 1995 | + $success = $this->_cpt_model_obj->save(); |
|
| 1996 | + if ($success === false) { |
|
| 1997 | + $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 1998 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1999 | 1999 | |
| 2000 | - return false; |
|
| 2001 | - } |
|
| 2002 | - if ($hook) { |
|
| 2003 | - do_action($hook); |
|
| 2004 | - } |
|
| 2000 | + return false; |
|
| 2001 | + } |
|
| 2002 | + if ($hook) { |
|
| 2003 | + do_action($hook); |
|
| 2004 | + } |
|
| 2005 | 2005 | |
| 2006 | - return true; |
|
| 2007 | - } |
|
| 2008 | - |
|
| 2009 | - |
|
| 2010 | - /** |
|
| 2011 | - * _delete_event |
|
| 2012 | - * |
|
| 2013 | - * @access protected |
|
| 2014 | - * |
|
| 2015 | - * @param bool $redirect_after |
|
| 2016 | - */ |
|
| 2017 | - protected function _delete_event($redirect_after = true) |
|
| 2018 | - { |
|
| 2019 | - //determine the event id and set to array. |
|
| 2020 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null; |
|
| 2021 | - $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID; |
|
| 2022 | - // loop thru events |
|
| 2023 | - if ($EVT_ID) { |
|
| 2024 | - $success = $this->_permanently_delete_event($EVT_ID); |
|
| 2025 | - // get list of events with no prices |
|
| 2026 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2027 | - // remove this event from the list of events with no prices |
|
| 2028 | - if (isset($espresso_no_ticket_prices[ $EVT_ID ])) { |
|
| 2029 | - unset($espresso_no_ticket_prices[ $EVT_ID ]); |
|
| 2030 | - } |
|
| 2031 | - update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2032 | - } else { |
|
| 2033 | - $success = false; |
|
| 2034 | - $msg = esc_html__( |
|
| 2035 | - 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2036 | - 'event_espresso' |
|
| 2037 | - ); |
|
| 2038 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2039 | - } |
|
| 2040 | - if ($redirect_after) { |
|
| 2041 | - $this->_redirect_after_action( |
|
| 2042 | - $success, |
|
| 2043 | - 'Event', |
|
| 2044 | - 'deleted', |
|
| 2045 | - array('action' => 'default', 'status' => 'trash') |
|
| 2046 | - ); |
|
| 2047 | - } |
|
| 2048 | - } |
|
| 2049 | - |
|
| 2050 | - |
|
| 2051 | - /** |
|
| 2052 | - * _delete_events |
|
| 2053 | - * |
|
| 2054 | - * @access protected |
|
| 2055 | - * @return void |
|
| 2056 | - */ |
|
| 2057 | - protected function _delete_events() |
|
| 2058 | - { |
|
| 2059 | - $success = true; |
|
| 2060 | - // get list of events with no prices |
|
| 2061 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2062 | - //determine the event id and set to array. |
|
| 2063 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 2064 | - // loop thru events |
|
| 2065 | - foreach ($EVT_IDs as $EVT_ID) { |
|
| 2066 | - $EVT_ID = absint($EVT_ID); |
|
| 2067 | - if ($EVT_ID) { |
|
| 2068 | - $results = $this->_permanently_delete_event($EVT_ID); |
|
| 2069 | - $success = $results !== false ? $success : false; |
|
| 2070 | - // remove this event from the list of events with no prices |
|
| 2071 | - unset($espresso_no_ticket_prices[ $EVT_ID ]); |
|
| 2072 | - } else { |
|
| 2073 | - $success = false; |
|
| 2074 | - $msg = esc_html__( |
|
| 2075 | - 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2076 | - 'event_espresso' |
|
| 2077 | - ); |
|
| 2078 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2079 | - } |
|
| 2080 | - } |
|
| 2081 | - update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2082 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2083 | - $success = $success ? 2 : false; |
|
| 2084 | - $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default')); |
|
| 2085 | - } |
|
| 2086 | - |
|
| 2087 | - |
|
| 2088 | - /** |
|
| 2089 | - * _permanently_delete_event |
|
| 2090 | - * |
|
| 2091 | - * @access private |
|
| 2092 | - * |
|
| 2093 | - * @param int $EVT_ID |
|
| 2094 | - * |
|
| 2095 | - * @return bool |
|
| 2096 | - */ |
|
| 2097 | - private function _permanently_delete_event($EVT_ID = 0) |
|
| 2098 | - { |
|
| 2099 | - // grab event id |
|
| 2100 | - if ( ! $EVT_ID) { |
|
| 2101 | - $msg = esc_html__( |
|
| 2102 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2103 | - 'event_espresso' |
|
| 2104 | - ); |
|
| 2105 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2006 | + return true; |
|
| 2007 | + } |
|
| 2008 | + |
|
| 2009 | + |
|
| 2010 | + /** |
|
| 2011 | + * _delete_event |
|
| 2012 | + * |
|
| 2013 | + * @access protected |
|
| 2014 | + * |
|
| 2015 | + * @param bool $redirect_after |
|
| 2016 | + */ |
|
| 2017 | + protected function _delete_event($redirect_after = true) |
|
| 2018 | + { |
|
| 2019 | + //determine the event id and set to array. |
|
| 2020 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null; |
|
| 2021 | + $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID; |
|
| 2022 | + // loop thru events |
|
| 2023 | + if ($EVT_ID) { |
|
| 2024 | + $success = $this->_permanently_delete_event($EVT_ID); |
|
| 2025 | + // get list of events with no prices |
|
| 2026 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2027 | + // remove this event from the list of events with no prices |
|
| 2028 | + if (isset($espresso_no_ticket_prices[ $EVT_ID ])) { |
|
| 2029 | + unset($espresso_no_ticket_prices[ $EVT_ID ]); |
|
| 2030 | + } |
|
| 2031 | + update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2032 | + } else { |
|
| 2033 | + $success = false; |
|
| 2034 | + $msg = esc_html__( |
|
| 2035 | + 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2036 | + 'event_espresso' |
|
| 2037 | + ); |
|
| 2038 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2039 | + } |
|
| 2040 | + if ($redirect_after) { |
|
| 2041 | + $this->_redirect_after_action( |
|
| 2042 | + $success, |
|
| 2043 | + 'Event', |
|
| 2044 | + 'deleted', |
|
| 2045 | + array('action' => 'default', 'status' => 'trash') |
|
| 2046 | + ); |
|
| 2047 | + } |
|
| 2048 | + } |
|
| 2049 | + |
|
| 2050 | + |
|
| 2051 | + /** |
|
| 2052 | + * _delete_events |
|
| 2053 | + * |
|
| 2054 | + * @access protected |
|
| 2055 | + * @return void |
|
| 2056 | + */ |
|
| 2057 | + protected function _delete_events() |
|
| 2058 | + { |
|
| 2059 | + $success = true; |
|
| 2060 | + // get list of events with no prices |
|
| 2061 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2062 | + //determine the event id and set to array. |
|
| 2063 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 2064 | + // loop thru events |
|
| 2065 | + foreach ($EVT_IDs as $EVT_ID) { |
|
| 2066 | + $EVT_ID = absint($EVT_ID); |
|
| 2067 | + if ($EVT_ID) { |
|
| 2068 | + $results = $this->_permanently_delete_event($EVT_ID); |
|
| 2069 | + $success = $results !== false ? $success : false; |
|
| 2070 | + // remove this event from the list of events with no prices |
|
| 2071 | + unset($espresso_no_ticket_prices[ $EVT_ID ]); |
|
| 2072 | + } else { |
|
| 2073 | + $success = false; |
|
| 2074 | + $msg = esc_html__( |
|
| 2075 | + 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2076 | + 'event_espresso' |
|
| 2077 | + ); |
|
| 2078 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2079 | + } |
|
| 2080 | + } |
|
| 2081 | + update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2082 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2083 | + $success = $success ? 2 : false; |
|
| 2084 | + $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default')); |
|
| 2085 | + } |
|
| 2086 | + |
|
| 2087 | + |
|
| 2088 | + /** |
|
| 2089 | + * _permanently_delete_event |
|
| 2090 | + * |
|
| 2091 | + * @access private |
|
| 2092 | + * |
|
| 2093 | + * @param int $EVT_ID |
|
| 2094 | + * |
|
| 2095 | + * @return bool |
|
| 2096 | + */ |
|
| 2097 | + private function _permanently_delete_event($EVT_ID = 0) |
|
| 2098 | + { |
|
| 2099 | + // grab event id |
|
| 2100 | + if ( ! $EVT_ID) { |
|
| 2101 | + $msg = esc_html__( |
|
| 2102 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2103 | + 'event_espresso' |
|
| 2104 | + ); |
|
| 2105 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2106 | 2106 | |
| 2107 | - return false; |
|
| 2108 | - } |
|
| 2109 | - if ( |
|
| 2110 | - ! $this->_cpt_model_obj instanceof EE_Event |
|
| 2111 | - || $this->_cpt_model_obj->ID() !== $EVT_ID |
|
| 2112 | - ) { |
|
| 2113 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2114 | - } |
|
| 2115 | - if ( ! $this->_cpt_model_obj instanceof EE_Event) { |
|
| 2116 | - return false; |
|
| 2117 | - } |
|
| 2118 | - //need to delete related tickets and prices first. |
|
| 2119 | - $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); |
|
| 2120 | - foreach ($datetimes as $datetime) { |
|
| 2121 | - $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime'); |
|
| 2122 | - $tickets = $datetime->get_many_related('Ticket'); |
|
| 2123 | - foreach ($tickets as $ticket) { |
|
| 2124 | - $ticket->_remove_relation_to($datetime, 'Datetime'); |
|
| 2125 | - $ticket->delete_related_permanently('Price'); |
|
| 2126 | - $ticket->delete_permanently(); |
|
| 2127 | - } |
|
| 2128 | - $datetime->delete(); |
|
| 2129 | - } |
|
| 2130 | - //what about related venues or terms? |
|
| 2131 | - $venues = $this->_cpt_model_obj->get_many_related('Venue'); |
|
| 2132 | - foreach ($venues as $venue) { |
|
| 2133 | - $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue'); |
|
| 2134 | - } |
|
| 2135 | - //any attached question groups? |
|
| 2136 | - $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
|
| 2137 | - if ( ! empty($question_groups)) { |
|
| 2138 | - foreach ($question_groups as $question_group) { |
|
| 2139 | - $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
|
| 2140 | - } |
|
| 2141 | - } |
|
| 2142 | - //Message Template Groups |
|
| 2143 | - $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); |
|
| 2144 | - /** @type EE_Term_Taxonomy[] $term_taxonomies */ |
|
| 2145 | - $term_taxonomies = $this->_cpt_model_obj->term_taxonomies(); |
|
| 2146 | - foreach ($term_taxonomies as $term_taxonomy) { |
|
| 2147 | - $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy); |
|
| 2148 | - } |
|
| 2149 | - $success = $this->_cpt_model_obj->delete_permanently(); |
|
| 2150 | - // did it all go as planned ? |
|
| 2151 | - if ($success) { |
|
| 2152 | - $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID); |
|
| 2153 | - EE_Error::add_success($msg); |
|
| 2154 | - } else { |
|
| 2155 | - $msg = sprintf( |
|
| 2156 | - esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'), |
|
| 2157 | - $EVT_ID |
|
| 2158 | - ); |
|
| 2159 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2107 | + return false; |
|
| 2108 | + } |
|
| 2109 | + if ( |
|
| 2110 | + ! $this->_cpt_model_obj instanceof EE_Event |
|
| 2111 | + || $this->_cpt_model_obj->ID() !== $EVT_ID |
|
| 2112 | + ) { |
|
| 2113 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2114 | + } |
|
| 2115 | + if ( ! $this->_cpt_model_obj instanceof EE_Event) { |
|
| 2116 | + return false; |
|
| 2117 | + } |
|
| 2118 | + //need to delete related tickets and prices first. |
|
| 2119 | + $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); |
|
| 2120 | + foreach ($datetimes as $datetime) { |
|
| 2121 | + $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime'); |
|
| 2122 | + $tickets = $datetime->get_many_related('Ticket'); |
|
| 2123 | + foreach ($tickets as $ticket) { |
|
| 2124 | + $ticket->_remove_relation_to($datetime, 'Datetime'); |
|
| 2125 | + $ticket->delete_related_permanently('Price'); |
|
| 2126 | + $ticket->delete_permanently(); |
|
| 2127 | + } |
|
| 2128 | + $datetime->delete(); |
|
| 2129 | + } |
|
| 2130 | + //what about related venues or terms? |
|
| 2131 | + $venues = $this->_cpt_model_obj->get_many_related('Venue'); |
|
| 2132 | + foreach ($venues as $venue) { |
|
| 2133 | + $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue'); |
|
| 2134 | + } |
|
| 2135 | + //any attached question groups? |
|
| 2136 | + $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
|
| 2137 | + if ( ! empty($question_groups)) { |
|
| 2138 | + foreach ($question_groups as $question_group) { |
|
| 2139 | + $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
|
| 2140 | + } |
|
| 2141 | + } |
|
| 2142 | + //Message Template Groups |
|
| 2143 | + $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); |
|
| 2144 | + /** @type EE_Term_Taxonomy[] $term_taxonomies */ |
|
| 2145 | + $term_taxonomies = $this->_cpt_model_obj->term_taxonomies(); |
|
| 2146 | + foreach ($term_taxonomies as $term_taxonomy) { |
|
| 2147 | + $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy); |
|
| 2148 | + } |
|
| 2149 | + $success = $this->_cpt_model_obj->delete_permanently(); |
|
| 2150 | + // did it all go as planned ? |
|
| 2151 | + if ($success) { |
|
| 2152 | + $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID); |
|
| 2153 | + EE_Error::add_success($msg); |
|
| 2154 | + } else { |
|
| 2155 | + $msg = sprintf( |
|
| 2156 | + esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'), |
|
| 2157 | + $EVT_ID |
|
| 2158 | + ); |
|
| 2159 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2160 | 2160 | |
| 2161 | - return false; |
|
| 2162 | - } |
|
| 2163 | - do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); |
|
| 2161 | + return false; |
|
| 2162 | + } |
|
| 2163 | + do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); |
|
| 2164 | 2164 | |
| 2165 | - return true; |
|
| 2166 | - } |
|
| 2167 | - |
|
| 2168 | - |
|
| 2169 | - /** |
|
| 2170 | - * get total number of events |
|
| 2171 | - * |
|
| 2172 | - * @access public |
|
| 2173 | - * @return int |
|
| 2174 | - */ |
|
| 2175 | - public function total_events() |
|
| 2176 | - { |
|
| 2177 | - $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2165 | + return true; |
|
| 2166 | + } |
|
| 2167 | + |
|
| 2168 | + |
|
| 2169 | + /** |
|
| 2170 | + * get total number of events |
|
| 2171 | + * |
|
| 2172 | + * @access public |
|
| 2173 | + * @return int |
|
| 2174 | + */ |
|
| 2175 | + public function total_events() |
|
| 2176 | + { |
|
| 2177 | + $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2178 | 2178 | |
| 2179 | - return $count; |
|
| 2180 | - } |
|
| 2181 | - |
|
| 2182 | - |
|
| 2183 | - /** |
|
| 2184 | - * get total number of draft events |
|
| 2185 | - * |
|
| 2186 | - * @access public |
|
| 2187 | - * @return int |
|
| 2188 | - */ |
|
| 2189 | - public function total_events_draft() |
|
| 2190 | - { |
|
| 2191 | - $where = array( |
|
| 2192 | - 'status' => array('IN', array('draft', 'auto-draft')), |
|
| 2193 | - ); |
|
| 2194 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2179 | + return $count; |
|
| 2180 | + } |
|
| 2181 | + |
|
| 2182 | + |
|
| 2183 | + /** |
|
| 2184 | + * get total number of draft events |
|
| 2185 | + * |
|
| 2186 | + * @access public |
|
| 2187 | + * @return int |
|
| 2188 | + */ |
|
| 2189 | + public function total_events_draft() |
|
| 2190 | + { |
|
| 2191 | + $where = array( |
|
| 2192 | + 'status' => array('IN', array('draft', 'auto-draft')), |
|
| 2193 | + ); |
|
| 2194 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2195 | 2195 | |
| 2196 | - return $count; |
|
| 2197 | - } |
|
| 2198 | - |
|
| 2199 | - |
|
| 2200 | - /** |
|
| 2201 | - * get total number of trashed events |
|
| 2202 | - * |
|
| 2203 | - * @access public |
|
| 2204 | - * @return int |
|
| 2205 | - */ |
|
| 2206 | - public function total_trashed_events() |
|
| 2207 | - { |
|
| 2208 | - $where = array( |
|
| 2209 | - 'status' => 'trash', |
|
| 2210 | - ); |
|
| 2211 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2196 | + return $count; |
|
| 2197 | + } |
|
| 2198 | + |
|
| 2199 | + |
|
| 2200 | + /** |
|
| 2201 | + * get total number of trashed events |
|
| 2202 | + * |
|
| 2203 | + * @access public |
|
| 2204 | + * @return int |
|
| 2205 | + */ |
|
| 2206 | + public function total_trashed_events() |
|
| 2207 | + { |
|
| 2208 | + $where = array( |
|
| 2209 | + 'status' => 'trash', |
|
| 2210 | + ); |
|
| 2211 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2212 | 2212 | |
| 2213 | - return $count; |
|
| 2214 | - } |
|
| 2215 | - |
|
| 2216 | - |
|
| 2217 | - /** |
|
| 2218 | - * _default_event_settings |
|
| 2219 | - * This generates the Default Settings Tab |
|
| 2220 | - * |
|
| 2221 | - * @return void |
|
| 2222 | - */ |
|
| 2223 | - protected function _default_event_settings() |
|
| 2224 | - { |
|
| 2225 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 2226 | - $this->_template_args['reg_status_array'] = EEM_Registration::reg_status_array( |
|
| 2227 | - // exclude array |
|
| 2228 | - array( |
|
| 2229 | - EEM_Registration::status_id_cancelled, |
|
| 2230 | - EEM_Registration::status_id_declined, |
|
| 2231 | - EEM_Registration::status_id_incomplete, |
|
| 2232 | - EEM_Registration::status_id_wait_list, |
|
| 2233 | - ), |
|
| 2234 | - // translated |
|
| 2235 | - true |
|
| 2236 | - ); |
|
| 2237 | - $this->_template_args['default_reg_status'] = isset( |
|
| 2238 | - EE_Registry::instance()->CFG->registration->default_STS_ID |
|
| 2239 | - ) && in_array( |
|
| 2240 | - EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 2241 | - $this->_template_args['reg_status_array'] |
|
| 2242 | - ) |
|
| 2243 | - ? sanitize_text_field(EE_Registry::instance()->CFG->registration->default_STS_ID) |
|
| 2244 | - : EEM_Registration::status_id_pending_payment; |
|
| 2245 | - $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2246 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2247 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2248 | - EVENTS_TEMPLATE_PATH . 'event_settings.template.php', |
|
| 2249 | - $this->_template_args, |
|
| 2250 | - true |
|
| 2251 | - ); |
|
| 2252 | - $this->display_admin_page_with_sidebar(); |
|
| 2253 | - } |
|
| 2254 | - |
|
| 2255 | - |
|
| 2256 | - /** |
|
| 2257 | - * _update_default_event_settings |
|
| 2258 | - * |
|
| 2259 | - * @access protected |
|
| 2260 | - * @return void |
|
| 2261 | - */ |
|
| 2262 | - protected function _update_default_event_settings() |
|
| 2263 | - { |
|
| 2264 | - EE_Config::instance()->registration->default_STS_ID = isset($this->_req_data['default_reg_status']) |
|
| 2265 | - ? sanitize_text_field($this->_req_data['default_reg_status']) |
|
| 2266 | - : EEM_Registration::status_id_pending_payment; |
|
| 2267 | - $what = 'Default Event Settings'; |
|
| 2268 | - $success = $this->_update_espresso_configuration( |
|
| 2269 | - $what, |
|
| 2270 | - EE_Config::instance(), |
|
| 2271 | - __FILE__, |
|
| 2272 | - __FUNCTION__, |
|
| 2273 | - __LINE__ |
|
| 2274 | - ); |
|
| 2275 | - $this->_redirect_after_action($success, $what, 'updated', array('action' => 'default_event_settings')); |
|
| 2276 | - } |
|
| 2277 | - |
|
| 2278 | - |
|
| 2279 | - /************* Templates *************/ |
|
| 2280 | - |
|
| 2281 | - |
|
| 2282 | - protected function _template_settings() |
|
| 2283 | - { |
|
| 2284 | - $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2285 | - $this->_template_args['preview_img'] = '<img src="' |
|
| 2286 | - . EVENTS_ASSETS_URL |
|
| 2287 | - . DS |
|
| 2288 | - . 'images' |
|
| 2289 | - . DS |
|
| 2290 | - . 'caffeinated_template_features.jpg" alt="' |
|
| 2291 | - . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2292 | - . '" />'; |
|
| 2293 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__( |
|
| 2294 | - 'Template Settings is a feature that is only available in the Caffeinated version of Event Espresso. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
| 2295 | - 'event_espresso' |
|
| 2296 | - ) . '</strong>'; |
|
| 2297 | - $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2298 | - } |
|
| 2299 | - |
|
| 2300 | - |
|
| 2301 | - /** Event Category Stuff **/ |
|
| 2302 | - /** |
|
| 2303 | - * set the _category property with the category object for the loaded page. |
|
| 2304 | - * |
|
| 2305 | - * @access private |
|
| 2306 | - * @return void |
|
| 2307 | - */ |
|
| 2308 | - private function _set_category_object() |
|
| 2309 | - { |
|
| 2310 | - if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2311 | - return; |
|
| 2312 | - } //already have the category object so get out. |
|
| 2313 | - //set default category object |
|
| 2314 | - $this->_set_empty_category_object(); |
|
| 2315 | - //only set if we've got an id |
|
| 2316 | - if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2317 | - return; |
|
| 2318 | - } |
|
| 2319 | - $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
| 2320 | - $term = get_term($category_id, 'espresso_event_categories'); |
|
| 2321 | - if ( ! empty($term)) { |
|
| 2322 | - $this->_category->category_name = $term->name; |
|
| 2323 | - $this->_category->category_identifier = $term->slug; |
|
| 2324 | - $this->_category->category_desc = $term->description; |
|
| 2325 | - $this->_category->id = $term->term_id; |
|
| 2326 | - $this->_category->parent = $term->parent; |
|
| 2327 | - } |
|
| 2328 | - } |
|
| 2329 | - |
|
| 2330 | - |
|
| 2331 | - private function _set_empty_category_object() |
|
| 2332 | - { |
|
| 2333 | - $this->_category = new stdClass(); |
|
| 2334 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2335 | - $this->_category->id = $this->_category->parent = 0; |
|
| 2336 | - } |
|
| 2337 | - |
|
| 2338 | - |
|
| 2339 | - protected function _category_list_table() |
|
| 2340 | - { |
|
| 2341 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2342 | - $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2343 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2344 | - 'add_category', |
|
| 2345 | - 'add_category', |
|
| 2346 | - array(), |
|
| 2347 | - 'add-new-h2' |
|
| 2348 | - ); |
|
| 2349 | - $this->display_admin_list_table_page_with_sidebar(); |
|
| 2350 | - } |
|
| 2351 | - |
|
| 2352 | - |
|
| 2353 | - /** |
|
| 2354 | - * @param $view |
|
| 2355 | - */ |
|
| 2356 | - protected function _category_details($view) |
|
| 2357 | - { |
|
| 2358 | - //load formatter helper |
|
| 2359 | - //load field generator helper |
|
| 2360 | - $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
| 2361 | - $this->_set_add_edit_form_tags($route); |
|
| 2362 | - $this->_set_category_object(); |
|
| 2363 | - $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2364 | - $delete_action = 'delete_category'; |
|
| 2365 | - //custom redirect |
|
| 2366 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2367 | - array('action' => 'category_list'), |
|
| 2368 | - $this->_admin_base_url |
|
| 2369 | - ); |
|
| 2370 | - $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2371 | - //take care of contents |
|
| 2372 | - $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2373 | - $this->display_admin_page_with_sidebar(); |
|
| 2374 | - } |
|
| 2375 | - |
|
| 2376 | - |
|
| 2377 | - /** |
|
| 2378 | - * @return mixed |
|
| 2379 | - */ |
|
| 2380 | - protected function _category_details_content() |
|
| 2381 | - { |
|
| 2382 | - $editor_args['category_desc'] = array( |
|
| 2383 | - 'type' => 'wp_editor', |
|
| 2384 | - 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2385 | - 'class' => 'my_editor_custom', |
|
| 2386 | - 'wpeditor_args' => array('media_buttons' => false), |
|
| 2387 | - ); |
|
| 2388 | - $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2389 | - $all_terms = get_terms( |
|
| 2390 | - array('espresso_event_categories'), |
|
| 2391 | - array('hide_empty' => 0, 'exclude' => array($this->_category->id)) |
|
| 2392 | - ); |
|
| 2393 | - //setup category select for term parents. |
|
| 2394 | - $category_select_values[] = array( |
|
| 2395 | - 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2396 | - 'id' => 0, |
|
| 2397 | - ); |
|
| 2398 | - foreach ($all_terms as $term) { |
|
| 2399 | - $category_select_values[] = array( |
|
| 2400 | - 'text' => $term->name, |
|
| 2401 | - 'id' => $term->term_id, |
|
| 2402 | - ); |
|
| 2403 | - } |
|
| 2404 | - $category_select = EEH_Form_Fields::select_input( |
|
| 2405 | - 'category_parent', |
|
| 2406 | - $category_select_values, |
|
| 2407 | - $this->_category->parent |
|
| 2408 | - ); |
|
| 2409 | - $template_args = array( |
|
| 2410 | - 'category' => $this->_category, |
|
| 2411 | - 'category_select' => $category_select, |
|
| 2412 | - 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2413 | - 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2414 | - 'disable' => '', |
|
| 2415 | - 'disabled_message' => false, |
|
| 2416 | - ); |
|
| 2417 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2213 | + return $count; |
|
| 2214 | + } |
|
| 2215 | + |
|
| 2216 | + |
|
| 2217 | + /** |
|
| 2218 | + * _default_event_settings |
|
| 2219 | + * This generates the Default Settings Tab |
|
| 2220 | + * |
|
| 2221 | + * @return void |
|
| 2222 | + */ |
|
| 2223 | + protected function _default_event_settings() |
|
| 2224 | + { |
|
| 2225 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 2226 | + $this->_template_args['reg_status_array'] = EEM_Registration::reg_status_array( |
|
| 2227 | + // exclude array |
|
| 2228 | + array( |
|
| 2229 | + EEM_Registration::status_id_cancelled, |
|
| 2230 | + EEM_Registration::status_id_declined, |
|
| 2231 | + EEM_Registration::status_id_incomplete, |
|
| 2232 | + EEM_Registration::status_id_wait_list, |
|
| 2233 | + ), |
|
| 2234 | + // translated |
|
| 2235 | + true |
|
| 2236 | + ); |
|
| 2237 | + $this->_template_args['default_reg_status'] = isset( |
|
| 2238 | + EE_Registry::instance()->CFG->registration->default_STS_ID |
|
| 2239 | + ) && in_array( |
|
| 2240 | + EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 2241 | + $this->_template_args['reg_status_array'] |
|
| 2242 | + ) |
|
| 2243 | + ? sanitize_text_field(EE_Registry::instance()->CFG->registration->default_STS_ID) |
|
| 2244 | + : EEM_Registration::status_id_pending_payment; |
|
| 2245 | + $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2246 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2247 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2248 | + EVENTS_TEMPLATE_PATH . 'event_settings.template.php', |
|
| 2249 | + $this->_template_args, |
|
| 2250 | + true |
|
| 2251 | + ); |
|
| 2252 | + $this->display_admin_page_with_sidebar(); |
|
| 2253 | + } |
|
| 2254 | + |
|
| 2255 | + |
|
| 2256 | + /** |
|
| 2257 | + * _update_default_event_settings |
|
| 2258 | + * |
|
| 2259 | + * @access protected |
|
| 2260 | + * @return void |
|
| 2261 | + */ |
|
| 2262 | + protected function _update_default_event_settings() |
|
| 2263 | + { |
|
| 2264 | + EE_Config::instance()->registration->default_STS_ID = isset($this->_req_data['default_reg_status']) |
|
| 2265 | + ? sanitize_text_field($this->_req_data['default_reg_status']) |
|
| 2266 | + : EEM_Registration::status_id_pending_payment; |
|
| 2267 | + $what = 'Default Event Settings'; |
|
| 2268 | + $success = $this->_update_espresso_configuration( |
|
| 2269 | + $what, |
|
| 2270 | + EE_Config::instance(), |
|
| 2271 | + __FILE__, |
|
| 2272 | + __FUNCTION__, |
|
| 2273 | + __LINE__ |
|
| 2274 | + ); |
|
| 2275 | + $this->_redirect_after_action($success, $what, 'updated', array('action' => 'default_event_settings')); |
|
| 2276 | + } |
|
| 2277 | + |
|
| 2278 | + |
|
| 2279 | + /************* Templates *************/ |
|
| 2280 | + |
|
| 2281 | + |
|
| 2282 | + protected function _template_settings() |
|
| 2283 | + { |
|
| 2284 | + $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2285 | + $this->_template_args['preview_img'] = '<img src="' |
|
| 2286 | + . EVENTS_ASSETS_URL |
|
| 2287 | + . DS |
|
| 2288 | + . 'images' |
|
| 2289 | + . DS |
|
| 2290 | + . 'caffeinated_template_features.jpg" alt="' |
|
| 2291 | + . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2292 | + . '" />'; |
|
| 2293 | + $this->_template_args['preview_text'] = '<strong>' . esc_html__( |
|
| 2294 | + 'Template Settings is a feature that is only available in the Caffeinated version of Event Espresso. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
| 2295 | + 'event_espresso' |
|
| 2296 | + ) . '</strong>'; |
|
| 2297 | + $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2298 | + } |
|
| 2299 | + |
|
| 2300 | + |
|
| 2301 | + /** Event Category Stuff **/ |
|
| 2302 | + /** |
|
| 2303 | + * set the _category property with the category object for the loaded page. |
|
| 2304 | + * |
|
| 2305 | + * @access private |
|
| 2306 | + * @return void |
|
| 2307 | + */ |
|
| 2308 | + private function _set_category_object() |
|
| 2309 | + { |
|
| 2310 | + if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2311 | + return; |
|
| 2312 | + } //already have the category object so get out. |
|
| 2313 | + //set default category object |
|
| 2314 | + $this->_set_empty_category_object(); |
|
| 2315 | + //only set if we've got an id |
|
| 2316 | + if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2317 | + return; |
|
| 2318 | + } |
|
| 2319 | + $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
| 2320 | + $term = get_term($category_id, 'espresso_event_categories'); |
|
| 2321 | + if ( ! empty($term)) { |
|
| 2322 | + $this->_category->category_name = $term->name; |
|
| 2323 | + $this->_category->category_identifier = $term->slug; |
|
| 2324 | + $this->_category->category_desc = $term->description; |
|
| 2325 | + $this->_category->id = $term->term_id; |
|
| 2326 | + $this->_category->parent = $term->parent; |
|
| 2327 | + } |
|
| 2328 | + } |
|
| 2329 | + |
|
| 2330 | + |
|
| 2331 | + private function _set_empty_category_object() |
|
| 2332 | + { |
|
| 2333 | + $this->_category = new stdClass(); |
|
| 2334 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2335 | + $this->_category->id = $this->_category->parent = 0; |
|
| 2336 | + } |
|
| 2337 | + |
|
| 2338 | + |
|
| 2339 | + protected function _category_list_table() |
|
| 2340 | + { |
|
| 2341 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2342 | + $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2343 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2344 | + 'add_category', |
|
| 2345 | + 'add_category', |
|
| 2346 | + array(), |
|
| 2347 | + 'add-new-h2' |
|
| 2348 | + ); |
|
| 2349 | + $this->display_admin_list_table_page_with_sidebar(); |
|
| 2350 | + } |
|
| 2351 | + |
|
| 2352 | + |
|
| 2353 | + /** |
|
| 2354 | + * @param $view |
|
| 2355 | + */ |
|
| 2356 | + protected function _category_details($view) |
|
| 2357 | + { |
|
| 2358 | + //load formatter helper |
|
| 2359 | + //load field generator helper |
|
| 2360 | + $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
| 2361 | + $this->_set_add_edit_form_tags($route); |
|
| 2362 | + $this->_set_category_object(); |
|
| 2363 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2364 | + $delete_action = 'delete_category'; |
|
| 2365 | + //custom redirect |
|
| 2366 | + $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2367 | + array('action' => 'category_list'), |
|
| 2368 | + $this->_admin_base_url |
|
| 2369 | + ); |
|
| 2370 | + $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2371 | + //take care of contents |
|
| 2372 | + $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2373 | + $this->display_admin_page_with_sidebar(); |
|
| 2374 | + } |
|
| 2375 | + |
|
| 2376 | + |
|
| 2377 | + /** |
|
| 2378 | + * @return mixed |
|
| 2379 | + */ |
|
| 2380 | + protected function _category_details_content() |
|
| 2381 | + { |
|
| 2382 | + $editor_args['category_desc'] = array( |
|
| 2383 | + 'type' => 'wp_editor', |
|
| 2384 | + 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2385 | + 'class' => 'my_editor_custom', |
|
| 2386 | + 'wpeditor_args' => array('media_buttons' => false), |
|
| 2387 | + ); |
|
| 2388 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2389 | + $all_terms = get_terms( |
|
| 2390 | + array('espresso_event_categories'), |
|
| 2391 | + array('hide_empty' => 0, 'exclude' => array($this->_category->id)) |
|
| 2392 | + ); |
|
| 2393 | + //setup category select for term parents. |
|
| 2394 | + $category_select_values[] = array( |
|
| 2395 | + 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2396 | + 'id' => 0, |
|
| 2397 | + ); |
|
| 2398 | + foreach ($all_terms as $term) { |
|
| 2399 | + $category_select_values[] = array( |
|
| 2400 | + 'text' => $term->name, |
|
| 2401 | + 'id' => $term->term_id, |
|
| 2402 | + ); |
|
| 2403 | + } |
|
| 2404 | + $category_select = EEH_Form_Fields::select_input( |
|
| 2405 | + 'category_parent', |
|
| 2406 | + $category_select_values, |
|
| 2407 | + $this->_category->parent |
|
| 2408 | + ); |
|
| 2409 | + $template_args = array( |
|
| 2410 | + 'category' => $this->_category, |
|
| 2411 | + 'category_select' => $category_select, |
|
| 2412 | + 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2413 | + 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2414 | + 'disable' => '', |
|
| 2415 | + 'disabled_message' => false, |
|
| 2416 | + ); |
|
| 2417 | + $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2418 | 2418 | |
| 2419 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 2420 | - } |
|
| 2421 | - |
|
| 2422 | - |
|
| 2423 | - protected function _delete_categories() |
|
| 2424 | - { |
|
| 2425 | - $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID'] |
|
| 2426 | - : (array)$this->_req_data['category_id']; |
|
| 2427 | - foreach ($cat_ids as $cat_id) { |
|
| 2428 | - $this->_delete_category($cat_id); |
|
| 2429 | - } |
|
| 2430 | - //doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2431 | - $query_args = array( |
|
| 2432 | - 'action' => 'category_list', |
|
| 2433 | - ); |
|
| 2434 | - $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2435 | - } |
|
| 2436 | - |
|
| 2437 | - |
|
| 2438 | - /** |
|
| 2439 | - * @param $cat_id |
|
| 2440 | - */ |
|
| 2441 | - protected function _delete_category($cat_id) |
|
| 2442 | - { |
|
| 2443 | - $cat_id = absint($cat_id); |
|
| 2444 | - wp_delete_term($cat_id, 'espresso_event_categories'); |
|
| 2445 | - } |
|
| 2446 | - |
|
| 2447 | - |
|
| 2448 | - /** |
|
| 2449 | - * @param $new_category |
|
| 2450 | - */ |
|
| 2451 | - protected function _insert_or_update_category($new_category) |
|
| 2452 | - { |
|
| 2453 | - $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2454 | - $success = 0; //we already have a success message so lets not send another. |
|
| 2455 | - if ($cat_id) { |
|
| 2456 | - $query_args = array( |
|
| 2457 | - 'action' => 'edit_category', |
|
| 2458 | - 'EVT_CAT_ID' => $cat_id, |
|
| 2459 | - ); |
|
| 2460 | - } else { |
|
| 2461 | - $query_args = array('action' => 'add_category'); |
|
| 2462 | - } |
|
| 2463 | - $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2464 | - } |
|
| 2465 | - |
|
| 2466 | - |
|
| 2467 | - /** |
|
| 2468 | - * @param bool $update |
|
| 2469 | - * |
|
| 2470 | - * @return bool|mixed|string |
|
| 2471 | - */ |
|
| 2472 | - private function _insert_category($update = false) |
|
| 2473 | - { |
|
| 2474 | - $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
| 2475 | - $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
| 2476 | - $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
| 2477 | - $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
| 2478 | - if (empty($category_name)) { |
|
| 2479 | - $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2480 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2419 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 2420 | + } |
|
| 2421 | + |
|
| 2422 | + |
|
| 2423 | + protected function _delete_categories() |
|
| 2424 | + { |
|
| 2425 | + $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID'] |
|
| 2426 | + : (array)$this->_req_data['category_id']; |
|
| 2427 | + foreach ($cat_ids as $cat_id) { |
|
| 2428 | + $this->_delete_category($cat_id); |
|
| 2429 | + } |
|
| 2430 | + //doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2431 | + $query_args = array( |
|
| 2432 | + 'action' => 'category_list', |
|
| 2433 | + ); |
|
| 2434 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2435 | + } |
|
| 2436 | + |
|
| 2437 | + |
|
| 2438 | + /** |
|
| 2439 | + * @param $cat_id |
|
| 2440 | + */ |
|
| 2441 | + protected function _delete_category($cat_id) |
|
| 2442 | + { |
|
| 2443 | + $cat_id = absint($cat_id); |
|
| 2444 | + wp_delete_term($cat_id, 'espresso_event_categories'); |
|
| 2445 | + } |
|
| 2446 | + |
|
| 2447 | + |
|
| 2448 | + /** |
|
| 2449 | + * @param $new_category |
|
| 2450 | + */ |
|
| 2451 | + protected function _insert_or_update_category($new_category) |
|
| 2452 | + { |
|
| 2453 | + $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2454 | + $success = 0; //we already have a success message so lets not send another. |
|
| 2455 | + if ($cat_id) { |
|
| 2456 | + $query_args = array( |
|
| 2457 | + 'action' => 'edit_category', |
|
| 2458 | + 'EVT_CAT_ID' => $cat_id, |
|
| 2459 | + ); |
|
| 2460 | + } else { |
|
| 2461 | + $query_args = array('action' => 'add_category'); |
|
| 2462 | + } |
|
| 2463 | + $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2464 | + } |
|
| 2465 | + |
|
| 2466 | + |
|
| 2467 | + /** |
|
| 2468 | + * @param bool $update |
|
| 2469 | + * |
|
| 2470 | + * @return bool|mixed|string |
|
| 2471 | + */ |
|
| 2472 | + private function _insert_category($update = false) |
|
| 2473 | + { |
|
| 2474 | + $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
| 2475 | + $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
| 2476 | + $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
| 2477 | + $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
| 2478 | + if (empty($category_name)) { |
|
| 2479 | + $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2480 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2481 | 2481 | |
| 2482 | - return false; |
|
| 2483 | - } |
|
| 2484 | - $term_args = array( |
|
| 2485 | - 'name' => $category_name, |
|
| 2486 | - 'description' => $category_desc, |
|
| 2487 | - 'parent' => $category_parent, |
|
| 2488 | - ); |
|
| 2489 | - //was the category_identifier input disabled? |
|
| 2490 | - if (isset($this->_req_data['category_identifier'])) { |
|
| 2491 | - $term_args['slug'] = $this->_req_data['category_identifier']; |
|
| 2492 | - } |
|
| 2493 | - $insert_ids = $update |
|
| 2494 | - ? wp_update_term($cat_id, 'espresso_event_categories', $term_args) |
|
| 2495 | - : wp_insert_term($category_name, 'espresso_event_categories', $term_args); |
|
| 2496 | - if ( ! is_array($insert_ids)) { |
|
| 2497 | - $msg = esc_html__( |
|
| 2498 | - 'An error occurred and the category has not been saved to the database.', |
|
| 2499 | - 'event_espresso' |
|
| 2500 | - ); |
|
| 2501 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2502 | - } else { |
|
| 2503 | - $cat_id = $insert_ids['term_id']; |
|
| 2504 | - $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
| 2505 | - EE_Error::add_success($msg); |
|
| 2506 | - } |
|
| 2482 | + return false; |
|
| 2483 | + } |
|
| 2484 | + $term_args = array( |
|
| 2485 | + 'name' => $category_name, |
|
| 2486 | + 'description' => $category_desc, |
|
| 2487 | + 'parent' => $category_parent, |
|
| 2488 | + ); |
|
| 2489 | + //was the category_identifier input disabled? |
|
| 2490 | + if (isset($this->_req_data['category_identifier'])) { |
|
| 2491 | + $term_args['slug'] = $this->_req_data['category_identifier']; |
|
| 2492 | + } |
|
| 2493 | + $insert_ids = $update |
|
| 2494 | + ? wp_update_term($cat_id, 'espresso_event_categories', $term_args) |
|
| 2495 | + : wp_insert_term($category_name, 'espresso_event_categories', $term_args); |
|
| 2496 | + if ( ! is_array($insert_ids)) { |
|
| 2497 | + $msg = esc_html__( |
|
| 2498 | + 'An error occurred and the category has not been saved to the database.', |
|
| 2499 | + 'event_espresso' |
|
| 2500 | + ); |
|
| 2501 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2502 | + } else { |
|
| 2503 | + $cat_id = $insert_ids['term_id']; |
|
| 2504 | + $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
| 2505 | + EE_Error::add_success($msg); |
|
| 2506 | + } |
|
| 2507 | 2507 | |
| 2508 | - return $cat_id; |
|
| 2509 | - } |
|
| 2510 | - |
|
| 2511 | - |
|
| 2512 | - /** |
|
| 2513 | - * @param int $per_page |
|
| 2514 | - * @param int $current_page |
|
| 2515 | - * @param bool $count |
|
| 2516 | - * |
|
| 2517 | - * @return \EE_Base_Class[]|int |
|
| 2518 | - */ |
|
| 2519 | - public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2520 | - { |
|
| 2521 | - //testing term stuff |
|
| 2522 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
| 2523 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2524 | - $limit = ($current_page - 1) * $per_page; |
|
| 2525 | - $where = array('taxonomy' => 'espresso_event_categories'); |
|
| 2526 | - if (isset($this->_req_data['s'])) { |
|
| 2527 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2528 | - $where['OR'] = array( |
|
| 2529 | - 'Term.name' => array('LIKE', $sstr), |
|
| 2530 | - 'description' => array('LIKE', $sstr), |
|
| 2531 | - ); |
|
| 2532 | - } |
|
| 2533 | - $query_params = array( |
|
| 2534 | - $where, |
|
| 2535 | - 'order_by' => array($orderby => $order), |
|
| 2536 | - 'limit' => $limit . ',' . $per_page, |
|
| 2537 | - 'force_join' => array('Term'), |
|
| 2538 | - ); |
|
| 2539 | - $categories = $count |
|
| 2540 | - ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2541 | - : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2508 | + return $cat_id; |
|
| 2509 | + } |
|
| 2510 | + |
|
| 2511 | + |
|
| 2512 | + /** |
|
| 2513 | + * @param int $per_page |
|
| 2514 | + * @param int $current_page |
|
| 2515 | + * @param bool $count |
|
| 2516 | + * |
|
| 2517 | + * @return \EE_Base_Class[]|int |
|
| 2518 | + */ |
|
| 2519 | + public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2520 | + { |
|
| 2521 | + //testing term stuff |
|
| 2522 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
| 2523 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2524 | + $limit = ($current_page - 1) * $per_page; |
|
| 2525 | + $where = array('taxonomy' => 'espresso_event_categories'); |
|
| 2526 | + if (isset($this->_req_data['s'])) { |
|
| 2527 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2528 | + $where['OR'] = array( |
|
| 2529 | + 'Term.name' => array('LIKE', $sstr), |
|
| 2530 | + 'description' => array('LIKE', $sstr), |
|
| 2531 | + ); |
|
| 2532 | + } |
|
| 2533 | + $query_params = array( |
|
| 2534 | + $where, |
|
| 2535 | + 'order_by' => array($orderby => $order), |
|
| 2536 | + 'limit' => $limit . ',' . $per_page, |
|
| 2537 | + 'force_join' => array('Term'), |
|
| 2538 | + ); |
|
| 2539 | + $categories = $count |
|
| 2540 | + ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2541 | + : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2542 | 2542 | |
| 2543 | - return $categories; |
|
| 2544 | - } |
|
| 2543 | + return $categories; |
|
| 2544 | + } |
|
| 2545 | 2545 | |
| 2546 | 2546 | |
| 2547 | 2547 | |
| 2548 | - /* end category stuff */ |
|
| 2549 | - /**************/ |
|
| 2548 | + /* end category stuff */ |
|
| 2549 | + /**************/ |
|
| 2550 | 2550 | } |
| 2551 | 2551 | //end class Events_Admin_Page |
@@ -520,11 +520,11 @@ discard block |
||
| 520 | 520 | { |
| 521 | 521 | wp_register_style( |
| 522 | 522 | 'events-admin-css', |
| 523 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 523 | + EVENTS_ASSETS_URL.'events-admin-page.css', |
|
| 524 | 524 | array(), |
| 525 | 525 | EVENT_ESPRESSO_VERSION |
| 526 | 526 | ); |
| 527 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 527 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 528 | 528 | wp_enqueue_style('events-admin-css'); |
| 529 | 529 | wp_enqueue_style('ee-cat-admin'); |
| 530 | 530 | //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | //scripts |
| 533 | 533 | wp_register_script( |
| 534 | 534 | 'event_editor_js', |
| 535 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 535 | + EVENTS_ASSETS_URL.'event_editor.js', |
|
| 536 | 536 | array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
| 537 | 537 | EVENT_ESPRESSO_VERSION, |
| 538 | 538 | true |
@@ -562,7 +562,7 @@ discard block |
||
| 562 | 562 | wp_enqueue_style('espresso-ui-theme'); |
| 563 | 563 | wp_register_style( |
| 564 | 564 | 'event-editor-css', |
| 565 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 565 | + EVENTS_ASSETS_URL.'event-editor.css', |
|
| 566 | 566 | array('ee-admin-css'), |
| 567 | 567 | EVENT_ESPRESSO_VERSION |
| 568 | 568 | ); |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | //scripts |
| 571 | 571 | wp_register_script( |
| 572 | 572 | 'event-datetime-metabox', |
| 573 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 573 | + EVENTS_ASSETS_URL.'event-datetime-metabox.js', |
|
| 574 | 574 | array('event_editor_js', 'ee-datepicker'), |
| 575 | 575 | EVENT_ESPRESSO_VERSION |
| 576 | 576 | ); |
@@ -727,7 +727,7 @@ discard block |
||
| 727 | 727 | 'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city |
| 728 | 728 | or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.' |
| 729 | 729 | ), |
| 730 | - '<a href="' . admin_url('options-general.php') . '">', |
|
| 730 | + '<a href="'.admin_url('options-general.php').'">', |
|
| 731 | 731 | '</a>' |
| 732 | 732 | ), |
| 733 | 733 | __FILE__, |
@@ -779,7 +779,7 @@ discard block |
||
| 779 | 779 | */ |
| 780 | 780 | protected function _event_legend_items() |
| 781 | 781 | { |
| 782 | - $items = array( |
|
| 782 | + $items = array( |
|
| 783 | 783 | 'view_details' => array( |
| 784 | 784 | 'class' => 'dashicons dashicons-search', |
| 785 | 785 | 'desc' => esc_html__('View Event', 'event_espresso'), |
@@ -796,31 +796,31 @@ discard block |
||
| 796 | 796 | $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
| 797 | 797 | $statuses = array( |
| 798 | 798 | 'sold_out_status' => array( |
| 799 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 799 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out, |
|
| 800 | 800 | 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
| 801 | 801 | ), |
| 802 | 802 | 'active_status' => array( |
| 803 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 803 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active, |
|
| 804 | 804 | 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
| 805 | 805 | ), |
| 806 | 806 | 'upcoming_status' => array( |
| 807 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 807 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming, |
|
| 808 | 808 | 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
| 809 | 809 | ), |
| 810 | 810 | 'postponed_status' => array( |
| 811 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 811 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed, |
|
| 812 | 812 | 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
| 813 | 813 | ), |
| 814 | 814 | 'cancelled_status' => array( |
| 815 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 815 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled, |
|
| 816 | 816 | 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
| 817 | 817 | ), |
| 818 | 818 | 'expired_status' => array( |
| 819 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 819 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired, |
|
| 820 | 820 | 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
| 821 | 821 | ), |
| 822 | 822 | 'inactive_status' => array( |
| 823 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 823 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive, |
|
| 824 | 824 | 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
| 825 | 825 | ), |
| 826 | 826 | ); |
@@ -889,7 +889,7 @@ discard block |
||
| 889 | 889 | 'button' |
| 890 | 890 | ); |
| 891 | 891 | $this->_template_args['after_list_table'] .= $this->_display_legend($this->_event_legend_items()); |
| 892 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 892 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 893 | 893 | 'create_new', |
| 894 | 894 | 'add', |
| 895 | 895 | array(), |
@@ -949,7 +949,7 @@ discard block |
||
| 949 | 949 | 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
| 950 | 950 | array(array($this, '_default_venue_update'), array($this, '_default_tickets_update')) |
| 951 | 951 | ); |
| 952 | - $att_success = true; |
|
| 952 | + $att_success = true; |
|
| 953 | 953 | foreach ($event_update_callbacks as $e_callback) { |
| 954 | 954 | $_succ = call_user_func_array($e_callback, array($event, $this->_req_data)); |
| 955 | 955 | $att_success = ! $att_success ? $att_success |
@@ -1006,7 +1006,7 @@ discard block |
||
| 1006 | 1006 | */ |
| 1007 | 1007 | protected function _default_venue_update(\EE_Event $evtobj, $data) |
| 1008 | 1008 | { |
| 1009 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1009 | + require_once(EE_MODELS.'EEM_Venue.model.php'); |
|
| 1010 | 1010 | $venue_model = EE_Registry::instance()->load_model('Venue'); |
| 1011 | 1011 | $rows_affected = null; |
| 1012 | 1012 | $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
@@ -1092,7 +1092,7 @@ discard block |
||
| 1092 | 1092 | $DTM->set($field, $value); |
| 1093 | 1093 | } |
| 1094 | 1094 | //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
| 1095 | - $saved_dtts[ $DTM->ID() ] = $DTM; |
|
| 1095 | + $saved_dtts[$DTM->ID()] = $DTM; |
|
| 1096 | 1096 | } else { |
| 1097 | 1097 | $DTM = EE_Registry::instance()->load_class( |
| 1098 | 1098 | 'Datetime', |
@@ -1132,7 +1132,7 @@ discard block |
||
| 1132 | 1132 | if (empty($tkt['TKT_start_date'])) { |
| 1133 | 1133 | //let's use now in the set timezone. |
| 1134 | 1134 | $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
| 1135 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1135 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]); |
|
| 1136 | 1136 | } |
| 1137 | 1137 | if (empty($tkt['TKT_end_date'])) { |
| 1138 | 1138 | //use the start date of the first datetime |
@@ -1249,9 +1249,9 @@ discard block |
||
| 1249 | 1249 | } |
| 1250 | 1250 | //initially let's add the ticket to the dtt |
| 1251 | 1251 | $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
| 1252 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1252 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1253 | 1253 | //add prices to ticket |
| 1254 | - $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices); |
|
| 1254 | + $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices); |
|
| 1255 | 1255 | } |
| 1256 | 1256 | //however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
| 1257 | 1257 | $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
@@ -1344,13 +1344,13 @@ discard block |
||
| 1344 | 1344 | { |
| 1345 | 1345 | //load formatter helper |
| 1346 | 1346 | //args for getting related registrations |
| 1347 | - $approved_query_args = array( |
|
| 1347 | + $approved_query_args = array( |
|
| 1348 | 1348 | array( |
| 1349 | 1349 | 'REG_deleted' => 0, |
| 1350 | 1350 | 'STS_ID' => EEM_Registration::status_id_approved |
| 1351 | 1351 | ) |
| 1352 | 1352 | ); |
| 1353 | - $not_approved_query_args = array( |
|
| 1353 | + $not_approved_query_args = array( |
|
| 1354 | 1354 | array( |
| 1355 | 1355 | 'REG_deleted' => 0, |
| 1356 | 1356 | 'STS_ID' => EEM_Registration::status_id_not_approved, |
@@ -1420,7 +1420,7 @@ discard block |
||
| 1420 | 1420 | $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
| 1421 | 1421 | // load template |
| 1422 | 1422 | EEH_Template::display_template( |
| 1423 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1423 | + EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php', |
|
| 1424 | 1424 | $publish_box_extra_args |
| 1425 | 1425 | ); |
| 1426 | 1426 | } |
@@ -1491,7 +1491,7 @@ discard block |
||
| 1491 | 1491 | 'trash_icon' => 'ee-lock-icon', |
| 1492 | 1492 | 'disabled' => '', |
| 1493 | 1493 | ); |
| 1494 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1494 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1495 | 1495 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 1496 | 1496 | /** |
| 1497 | 1497 | * 1. Start with retrieving Datetimes |
@@ -1545,9 +1545,9 @@ discard block |
||
| 1545 | 1545 | EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
| 1546 | 1546 | true |
| 1547 | 1547 | ); |
| 1548 | - $template = apply_filters( |
|
| 1548 | + $template = apply_filters( |
|
| 1549 | 1549 | 'FHEE__Events_Admin_Page__ticket_metabox__template', |
| 1550 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1550 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php' |
|
| 1551 | 1551 | ); |
| 1552 | 1552 | EEH_Template::display_template($template, $template_args); |
| 1553 | 1553 | } |
@@ -1565,7 +1565,7 @@ discard block |
||
| 1565 | 1565 | private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
| 1566 | 1566 | { |
| 1567 | 1567 | $template_args = array( |
| 1568 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1568 | + 'tkt_status_class' => ' tkt-status-'.$ticket->ticket_status(), |
|
| 1569 | 1569 | 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
| 1570 | 1570 | : '', |
| 1571 | 1571 | 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
@@ -1619,7 +1619,7 @@ discard block |
||
| 1619 | 1619 | $template_args = array_merge($template_args, $price_args); |
| 1620 | 1620 | $template = apply_filters( |
| 1621 | 1621 | 'FHEE__Events_Admin_Page__get_ticket_row__template', |
| 1622 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1622 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php', |
|
| 1623 | 1623 | $ticket |
| 1624 | 1624 | ); |
| 1625 | 1625 | |
@@ -1629,7 +1629,7 @@ discard block |
||
| 1629 | 1629 | |
| 1630 | 1630 | public function registration_options_meta_box() |
| 1631 | 1631 | { |
| 1632 | - $yes_no_values = array( |
|
| 1632 | + $yes_no_values = array( |
|
| 1633 | 1633 | array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
| 1634 | 1634 | array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
| 1635 | 1635 | ); |
@@ -1650,12 +1650,12 @@ discard block |
||
| 1650 | 1650 | $default_reg_status_values, |
| 1651 | 1651 | $this->_cpt_model_obj->default_registration_status() |
| 1652 | 1652 | ); |
| 1653 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1653 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1654 | 1654 | 'display_desc', |
| 1655 | 1655 | $yes_no_values, |
| 1656 | 1656 | $this->_cpt_model_obj->display_description() |
| 1657 | 1657 | ); |
| 1658 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1658 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1659 | 1659 | 'display_ticket_selector', |
| 1660 | 1660 | $yes_no_values, |
| 1661 | 1661 | $this->_cpt_model_obj->display_ticket_selector(), |
@@ -1671,7 +1671,7 @@ discard block |
||
| 1671 | 1671 | $default_reg_status_values |
| 1672 | 1672 | ); |
| 1673 | 1673 | EEH_Template::display_template( |
| 1674 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1674 | + EVENTS_TEMPLATE_PATH.'event_registration_options.template.php', |
|
| 1675 | 1675 | $template_args |
| 1676 | 1676 | ); |
| 1677 | 1677 | } |
@@ -1695,7 +1695,7 @@ discard block |
||
| 1695 | 1695 | { |
| 1696 | 1696 | $EEME = $this->_event_model(); |
| 1697 | 1697 | $offset = ($current_page - 1) * $per_page; |
| 1698 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1698 | + $limit = $count ? null : $offset.','.$per_page; |
|
| 1699 | 1699 | $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
| 1700 | 1700 | $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
| 1701 | 1701 | if (isset($this->_req_data['month_range'])) { |
@@ -1729,7 +1729,7 @@ discard block |
||
| 1729 | 1729 | $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
| 1730 | 1730 | if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
| 1731 | 1731 | $DateTime = new DateTime( |
| 1732 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1732 | + $year_r.'-'.$month_r.'-01 00:00:00', |
|
| 1733 | 1733 | new DateTimeZone(EEM_Datetime::instance()->get_timezone()) |
| 1734 | 1734 | ); |
| 1735 | 1735 | $start = $DateTime->format(implode(' ', $start_formats)); |
@@ -1775,7 +1775,7 @@ discard block |
||
| 1775 | 1775 | } |
| 1776 | 1776 | //search query handling |
| 1777 | 1777 | if (isset($this->_req_data['s'])) { |
| 1778 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1778 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
| 1779 | 1779 | $where['OR'] = array( |
| 1780 | 1780 | 'EVT_name' => array('LIKE', $search_string), |
| 1781 | 1781 | 'EVT_desc' => array('LIKE', $search_string), |
@@ -1908,7 +1908,7 @@ discard block |
||
| 1908 | 1908 | if ( ! empty($event_status)) { |
| 1909 | 1909 | $success = true; |
| 1910 | 1910 | //determine the event id and set to array. |
| 1911 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 1911 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
|
| 1912 | 1912 | // loop thru events |
| 1913 | 1913 | foreach ($EVT_IDs as $EVT_ID) { |
| 1914 | 1914 | if ($EVT_ID = absint($EVT_ID)) { |
@@ -2025,8 +2025,8 @@ discard block |
||
| 2025 | 2025 | // get list of events with no prices |
| 2026 | 2026 | $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
| 2027 | 2027 | // remove this event from the list of events with no prices |
| 2028 | - if (isset($espresso_no_ticket_prices[ $EVT_ID ])) { |
|
| 2029 | - unset($espresso_no_ticket_prices[ $EVT_ID ]); |
|
| 2028 | + if (isset($espresso_no_ticket_prices[$EVT_ID])) { |
|
| 2029 | + unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2030 | 2030 | } |
| 2031 | 2031 | update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
| 2032 | 2032 | } else { |
@@ -2060,7 +2060,7 @@ discard block |
||
| 2060 | 2060 | // get list of events with no prices |
| 2061 | 2061 | $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
| 2062 | 2062 | //determine the event id and set to array. |
| 2063 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 2063 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
|
| 2064 | 2064 | // loop thru events |
| 2065 | 2065 | foreach ($EVT_IDs as $EVT_ID) { |
| 2066 | 2066 | $EVT_ID = absint($EVT_ID); |
@@ -2068,7 +2068,7 @@ discard block |
||
| 2068 | 2068 | $results = $this->_permanently_delete_event($EVT_ID); |
| 2069 | 2069 | $success = $results !== false ? $success : false; |
| 2070 | 2070 | // remove this event from the list of events with no prices |
| 2071 | - unset($espresso_no_ticket_prices[ $EVT_ID ]); |
|
| 2071 | + unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2072 | 2072 | } else { |
| 2073 | 2073 | $success = false; |
| 2074 | 2074 | $msg = esc_html__( |
@@ -2245,7 +2245,7 @@ discard block |
||
| 2245 | 2245 | $this->_set_add_edit_form_tags('update_default_event_settings'); |
| 2246 | 2246 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
| 2247 | 2247 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 2248 | - EVENTS_TEMPLATE_PATH . 'event_settings.template.php', |
|
| 2248 | + EVENTS_TEMPLATE_PATH.'event_settings.template.php', |
|
| 2249 | 2249 | $this->_template_args, |
| 2250 | 2250 | true |
| 2251 | 2251 | ); |
@@ -2290,10 +2290,10 @@ discard block |
||
| 2290 | 2290 | . 'caffeinated_template_features.jpg" alt="' |
| 2291 | 2291 | . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
| 2292 | 2292 | . '" />'; |
| 2293 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__( |
|
| 2293 | + $this->_template_args['preview_text'] = '<strong>'.esc_html__( |
|
| 2294 | 2294 | 'Template Settings is a feature that is only available in the Caffeinated version of Event Espresso. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
| 2295 | 2295 | 'event_espresso' |
| 2296 | - ) . '</strong>'; |
|
| 2296 | + ).'</strong>'; |
|
| 2297 | 2297 | $this->display_admin_caf_preview_page('template_settings_tab'); |
| 2298 | 2298 | } |
| 2299 | 2299 | |
@@ -2340,7 +2340,7 @@ discard block |
||
| 2340 | 2340 | { |
| 2341 | 2341 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2342 | 2342 | $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
| 2343 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2343 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 2344 | 2344 | 'add_category', |
| 2345 | 2345 | 'add_category', |
| 2346 | 2346 | array(), |
@@ -2406,7 +2406,7 @@ discard block |
||
| 2406 | 2406 | $category_select_values, |
| 2407 | 2407 | $this->_category->parent |
| 2408 | 2408 | ); |
| 2409 | - $template_args = array( |
|
| 2409 | + $template_args = array( |
|
| 2410 | 2410 | 'category' => $this->_category, |
| 2411 | 2411 | 'category_select' => $category_select, |
| 2412 | 2412 | 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
@@ -2414,7 +2414,7 @@ discard block |
||
| 2414 | 2414 | 'disable' => '', |
| 2415 | 2415 | 'disabled_message' => false, |
| 2416 | 2416 | ); |
| 2417 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2417 | + $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php'; |
|
| 2418 | 2418 | |
| 2419 | 2419 | return EEH_Template::display_template($template, $template_args, true); |
| 2420 | 2420 | } |
@@ -2422,8 +2422,8 @@ discard block |
||
| 2422 | 2422 | |
| 2423 | 2423 | protected function _delete_categories() |
| 2424 | 2424 | { |
| 2425 | - $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID'] |
|
| 2426 | - : (array)$this->_req_data['category_id']; |
|
| 2425 | + $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID'] |
|
| 2426 | + : (array) $this->_req_data['category_id']; |
|
| 2427 | 2427 | foreach ($cat_ids as $cat_id) { |
| 2428 | 2428 | $this->_delete_category($cat_id); |
| 2429 | 2429 | } |
@@ -2524,7 +2524,7 @@ discard block |
||
| 2524 | 2524 | $limit = ($current_page - 1) * $per_page; |
| 2525 | 2525 | $where = array('taxonomy' => 'espresso_event_categories'); |
| 2526 | 2526 | if (isset($this->_req_data['s'])) { |
| 2527 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2527 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
| 2528 | 2528 | $where['OR'] = array( |
| 2529 | 2529 | 'Term.name' => array('LIKE', $sstr), |
| 2530 | 2530 | 'description' => array('LIKE', $sstr), |
@@ -2533,10 +2533,10 @@ discard block |
||
| 2533 | 2533 | $query_params = array( |
| 2534 | 2534 | $where, |
| 2535 | 2535 | 'order_by' => array($orderby => $order), |
| 2536 | - 'limit' => $limit . ',' . $per_page, |
|
| 2536 | + 'limit' => $limit.','.$per_page, |
|
| 2537 | 2537 | 'force_join' => array('Term'), |
| 2538 | 2538 | ); |
| 2539 | - $categories = $count |
|
| 2539 | + $categories = $count |
|
| 2540 | 2540 | ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
| 2541 | 2541 | : EEM_Term_Taxonomy::instance()->get_all($query_params); |
| 2542 | 2542 | |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | * @param $template |
| 337 | 337 | * @param $template_args |
| 338 | 338 | * |
| 339 | - * @return mixed |
|
| 339 | + * @return string |
|
| 340 | 340 | */ |
| 341 | 341 | public function add_additional_datetime_button($template, $template_args) |
| 342 | 342 | { |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | * @param $template |
| 353 | 353 | * @param $template_args |
| 354 | 354 | * |
| 355 | - * @return mixed |
|
| 355 | + * @return string |
|
| 356 | 356 | */ |
| 357 | 357 | public function add_datetime_clone_button($template, $template_args) |
| 358 | 358 | { |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | * @param $template |
| 369 | 369 | * @param $template_args |
| 370 | 370 | * |
| 371 | - * @return mixed |
|
| 371 | + * @return string |
|
| 372 | 372 | */ |
| 373 | 373 | public function datetime_timezones_template($template, $template_args) |
| 374 | 374 | { |
@@ -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 | |
@@ -16,1218 +16,1218 @@ discard block |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Extend_Events_Admin_Page constructor. |
|
| 21 | - * |
|
| 22 | - * @param bool $routing |
|
| 23 | - */ |
|
| 24 | - public function __construct($routing = true) |
|
| 25 | - { |
|
| 26 | - parent::__construct($routing); |
|
| 27 | - if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
| 28 | - define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
| 29 | - define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
| 30 | - define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
| 31 | - } |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - protected function _extend_page_config() |
|
| 36 | - { |
|
| 37 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
| 38 | - //is there a evt_id in the request? |
|
| 39 | - $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 40 | - ? $this->_req_data['EVT_ID'] |
|
| 41 | - : 0; |
|
| 42 | - $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 43 | - //tkt_id? |
|
| 44 | - $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID']) |
|
| 45 | - ? $this->_req_data['TKT_ID'] |
|
| 46 | - : 0; |
|
| 47 | - $new_page_routes = array( |
|
| 48 | - 'duplicate_event' => array( |
|
| 49 | - 'func' => '_duplicate_event', |
|
| 50 | - 'capability' => 'ee_edit_event', |
|
| 51 | - 'obj_id' => $evt_id, |
|
| 52 | - 'noheader' => true, |
|
| 53 | - ), |
|
| 54 | - 'ticket_list_table' => array( |
|
| 55 | - 'func' => '_tickets_overview_list_table', |
|
| 56 | - 'capability' => 'ee_read_default_tickets', |
|
| 57 | - ), |
|
| 58 | - 'trash_ticket' => array( |
|
| 59 | - 'func' => '_trash_or_restore_ticket', |
|
| 60 | - 'capability' => 'ee_delete_default_ticket', |
|
| 61 | - 'obj_id' => $tkt_id, |
|
| 62 | - 'noheader' => true, |
|
| 63 | - 'args' => array('trash' => true), |
|
| 64 | - ), |
|
| 65 | - 'trash_tickets' => array( |
|
| 66 | - 'func' => '_trash_or_restore_ticket', |
|
| 67 | - 'capability' => 'ee_delete_default_tickets', |
|
| 68 | - 'noheader' => true, |
|
| 69 | - 'args' => array('trash' => true), |
|
| 70 | - ), |
|
| 71 | - 'restore_ticket' => array( |
|
| 72 | - 'func' => '_trash_or_restore_ticket', |
|
| 73 | - 'capability' => 'ee_delete_default_ticket', |
|
| 74 | - 'obj_id' => $tkt_id, |
|
| 75 | - 'noheader' => true, |
|
| 76 | - ), |
|
| 77 | - 'restore_tickets' => array( |
|
| 78 | - 'func' => '_trash_or_restore_ticket', |
|
| 79 | - 'capability' => 'ee_delete_default_tickets', |
|
| 80 | - 'noheader' => true, |
|
| 81 | - ), |
|
| 82 | - 'delete_ticket' => array( |
|
| 83 | - 'func' => '_delete_ticket', |
|
| 84 | - 'capability' => 'ee_delete_default_ticket', |
|
| 85 | - 'obj_id' => $tkt_id, |
|
| 86 | - 'noheader' => true, |
|
| 87 | - ), |
|
| 88 | - 'delete_tickets' => array( |
|
| 89 | - 'func' => '_delete_ticket', |
|
| 90 | - 'capability' => 'ee_delete_default_tickets', |
|
| 91 | - 'noheader' => true, |
|
| 92 | - ), |
|
| 93 | - 'import_page' => array( |
|
| 94 | - 'func' => '_import_page', |
|
| 95 | - 'capability' => 'import', |
|
| 96 | - ), |
|
| 97 | - 'import' => array( |
|
| 98 | - 'func' => '_import_events', |
|
| 99 | - 'capability' => 'import', |
|
| 100 | - 'noheader' => true, |
|
| 101 | - ), |
|
| 102 | - 'import_events' => array( |
|
| 103 | - 'func' => '_import_events', |
|
| 104 | - 'capability' => 'import', |
|
| 105 | - 'noheader' => true, |
|
| 106 | - ), |
|
| 107 | - 'export_events' => array( |
|
| 108 | - 'func' => '_events_export', |
|
| 109 | - 'capability' => 'export', |
|
| 110 | - 'noheader' => true, |
|
| 111 | - ), |
|
| 112 | - 'export_categories' => array( |
|
| 113 | - 'func' => '_categories_export', |
|
| 114 | - 'capability' => 'export', |
|
| 115 | - 'noheader' => true, |
|
| 116 | - ), |
|
| 117 | - 'sample_export_file' => array( |
|
| 118 | - 'func' => '_sample_export_file', |
|
| 119 | - 'capability' => 'export', |
|
| 120 | - 'noheader' => true, |
|
| 121 | - ), |
|
| 122 | - 'update_template_settings' => array( |
|
| 123 | - 'func' => '_update_template_settings', |
|
| 124 | - 'capability' => 'manage_options', |
|
| 125 | - 'noheader' => true, |
|
| 126 | - ), |
|
| 127 | - ); |
|
| 128 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 129 | - //partial route/config override |
|
| 130 | - $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes; |
|
| 131 | - $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
| 132 | - $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
| 133 | - $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
| 134 | - $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
| 135 | - $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table'; |
|
| 136 | - //add tickets tab but only if there are more than one default ticket! |
|
| 137 | - $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
| 138 | - array(array('TKT_is_default' => 1)), |
|
| 139 | - 'TKT_ID', |
|
| 140 | - true |
|
| 141 | - ); |
|
| 142 | - if ($tkt_count > 1) { |
|
| 143 | - $new_page_config = array( |
|
| 144 | - 'ticket_list_table' => array( |
|
| 145 | - 'nav' => array( |
|
| 146 | - 'label' => esc_html__('Default Tickets', 'event_espresso'), |
|
| 147 | - 'order' => 60, |
|
| 148 | - ), |
|
| 149 | - 'list_table' => 'Tickets_List_Table', |
|
| 150 | - 'require_nonce' => false, |
|
| 151 | - ), |
|
| 152 | - ); |
|
| 153 | - } |
|
| 154 | - //template settings |
|
| 155 | - $new_page_config['template_settings'] = array( |
|
| 156 | - 'nav' => array( |
|
| 157 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 158 | - 'order' => 30, |
|
| 159 | - ), |
|
| 160 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 161 | - 'help_tabs' => array( |
|
| 162 | - 'general_settings_templates_help_tab' => array( |
|
| 163 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 164 | - 'filename' => 'general_settings_templates', |
|
| 165 | - ), |
|
| 166 | - ), |
|
| 167 | - 'help_tour' => array('Templates_Help_Tour'), |
|
| 168 | - 'require_nonce' => false, |
|
| 169 | - ); |
|
| 170 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 171 | - //add filters and actions |
|
| 172 | - //modifying _views |
|
| 173 | - add_filter( |
|
| 174 | - 'FHEE_event_datetime_metabox_add_additional_date_time_template', |
|
| 175 | - array($this, 'add_additional_datetime_button'), |
|
| 176 | - 10, |
|
| 177 | - 2 |
|
| 178 | - ); |
|
| 179 | - add_filter( |
|
| 180 | - 'FHEE_event_datetime_metabox_clone_button_template', |
|
| 181 | - array($this, 'add_datetime_clone_button'), |
|
| 182 | - 10, |
|
| 183 | - 2 |
|
| 184 | - ); |
|
| 185 | - add_filter( |
|
| 186 | - 'FHEE_event_datetime_metabox_timezones_template', |
|
| 187 | - array($this, 'datetime_timezones_template'), |
|
| 188 | - 10, |
|
| 189 | - 2 |
|
| 190 | - ); |
|
| 191 | - //filters for event list table |
|
| 192 | - add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2); |
|
| 193 | - add_filter( |
|
| 194 | - 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
| 195 | - array($this, 'extra_list_table_actions'), |
|
| 196 | - 10, |
|
| 197 | - 2 |
|
| 198 | - ); |
|
| 199 | - //legend item |
|
| 200 | - add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items')); |
|
| 201 | - add_action('admin_init', array($this, 'admin_init')); |
|
| 202 | - //heartbeat stuff |
|
| 203 | - add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * admin_init |
|
| 209 | - */ |
|
| 210 | - public function admin_init() |
|
| 211 | - { |
|
| 212 | - EE_Registry::$i18n_js_strings = array_merge( |
|
| 213 | - EE_Registry::$i18n_js_strings, |
|
| 214 | - array( |
|
| 215 | - 'image_confirm' => esc_html__( |
|
| 216 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 217 | - 'event_espresso' |
|
| 218 | - ), |
|
| 219 | - 'event_starts_on' => esc_html__('Event Starts on', 'event_espresso'), |
|
| 220 | - 'event_ends_on' => esc_html__('Event Ends on', 'event_espresso'), |
|
| 221 | - 'event_datetime_actions' => esc_html__('Actions', 'event_espresso'), |
|
| 222 | - 'event_clone_dt_msg' => esc_html__('Clone this Event Date and Time', 'event_espresso'), |
|
| 223 | - 'remove_event_dt_msg' => esc_html__('Remove this Event Time', 'event_espresso'), |
|
| 224 | - ) |
|
| 225 | - ); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle |
|
| 231 | - * accordingly. |
|
| 232 | - * |
|
| 233 | - * @param array $response The existing heartbeat response array. |
|
| 234 | - * @param array $data The incoming data package. |
|
| 235 | - * |
|
| 236 | - * @return array possibly appended response. |
|
| 237 | - */ |
|
| 238 | - public function heartbeat_response($response, $data) |
|
| 239 | - { |
|
| 240 | - /** |
|
| 241 | - * check whether count of tickets is approaching the potential |
|
| 242 | - * limits for the server. |
|
| 243 | - */ |
|
| 244 | - if ( ! empty($data['input_count'])) { |
|
| 245 | - $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check( |
|
| 246 | - $data['input_count'] |
|
| 247 | - ); |
|
| 248 | - } |
|
| 19 | + /** |
|
| 20 | + * Extend_Events_Admin_Page constructor. |
|
| 21 | + * |
|
| 22 | + * @param bool $routing |
|
| 23 | + */ |
|
| 24 | + public function __construct($routing = true) |
|
| 25 | + { |
|
| 26 | + parent::__construct($routing); |
|
| 27 | + if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
| 28 | + define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
| 29 | + define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
| 30 | + define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
| 31 | + } |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + protected function _extend_page_config() |
|
| 36 | + { |
|
| 37 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
| 38 | + //is there a evt_id in the request? |
|
| 39 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 40 | + ? $this->_req_data['EVT_ID'] |
|
| 41 | + : 0; |
|
| 42 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 43 | + //tkt_id? |
|
| 44 | + $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID']) |
|
| 45 | + ? $this->_req_data['TKT_ID'] |
|
| 46 | + : 0; |
|
| 47 | + $new_page_routes = array( |
|
| 48 | + 'duplicate_event' => array( |
|
| 49 | + 'func' => '_duplicate_event', |
|
| 50 | + 'capability' => 'ee_edit_event', |
|
| 51 | + 'obj_id' => $evt_id, |
|
| 52 | + 'noheader' => true, |
|
| 53 | + ), |
|
| 54 | + 'ticket_list_table' => array( |
|
| 55 | + 'func' => '_tickets_overview_list_table', |
|
| 56 | + 'capability' => 'ee_read_default_tickets', |
|
| 57 | + ), |
|
| 58 | + 'trash_ticket' => array( |
|
| 59 | + 'func' => '_trash_or_restore_ticket', |
|
| 60 | + 'capability' => 'ee_delete_default_ticket', |
|
| 61 | + 'obj_id' => $tkt_id, |
|
| 62 | + 'noheader' => true, |
|
| 63 | + 'args' => array('trash' => true), |
|
| 64 | + ), |
|
| 65 | + 'trash_tickets' => array( |
|
| 66 | + 'func' => '_trash_or_restore_ticket', |
|
| 67 | + 'capability' => 'ee_delete_default_tickets', |
|
| 68 | + 'noheader' => true, |
|
| 69 | + 'args' => array('trash' => true), |
|
| 70 | + ), |
|
| 71 | + 'restore_ticket' => array( |
|
| 72 | + 'func' => '_trash_or_restore_ticket', |
|
| 73 | + 'capability' => 'ee_delete_default_ticket', |
|
| 74 | + 'obj_id' => $tkt_id, |
|
| 75 | + 'noheader' => true, |
|
| 76 | + ), |
|
| 77 | + 'restore_tickets' => array( |
|
| 78 | + 'func' => '_trash_or_restore_ticket', |
|
| 79 | + 'capability' => 'ee_delete_default_tickets', |
|
| 80 | + 'noheader' => true, |
|
| 81 | + ), |
|
| 82 | + 'delete_ticket' => array( |
|
| 83 | + 'func' => '_delete_ticket', |
|
| 84 | + 'capability' => 'ee_delete_default_ticket', |
|
| 85 | + 'obj_id' => $tkt_id, |
|
| 86 | + 'noheader' => true, |
|
| 87 | + ), |
|
| 88 | + 'delete_tickets' => array( |
|
| 89 | + 'func' => '_delete_ticket', |
|
| 90 | + 'capability' => 'ee_delete_default_tickets', |
|
| 91 | + 'noheader' => true, |
|
| 92 | + ), |
|
| 93 | + 'import_page' => array( |
|
| 94 | + 'func' => '_import_page', |
|
| 95 | + 'capability' => 'import', |
|
| 96 | + ), |
|
| 97 | + 'import' => array( |
|
| 98 | + 'func' => '_import_events', |
|
| 99 | + 'capability' => 'import', |
|
| 100 | + 'noheader' => true, |
|
| 101 | + ), |
|
| 102 | + 'import_events' => array( |
|
| 103 | + 'func' => '_import_events', |
|
| 104 | + 'capability' => 'import', |
|
| 105 | + 'noheader' => true, |
|
| 106 | + ), |
|
| 107 | + 'export_events' => array( |
|
| 108 | + 'func' => '_events_export', |
|
| 109 | + 'capability' => 'export', |
|
| 110 | + 'noheader' => true, |
|
| 111 | + ), |
|
| 112 | + 'export_categories' => array( |
|
| 113 | + 'func' => '_categories_export', |
|
| 114 | + 'capability' => 'export', |
|
| 115 | + 'noheader' => true, |
|
| 116 | + ), |
|
| 117 | + 'sample_export_file' => array( |
|
| 118 | + 'func' => '_sample_export_file', |
|
| 119 | + 'capability' => 'export', |
|
| 120 | + 'noheader' => true, |
|
| 121 | + ), |
|
| 122 | + 'update_template_settings' => array( |
|
| 123 | + 'func' => '_update_template_settings', |
|
| 124 | + 'capability' => 'manage_options', |
|
| 125 | + 'noheader' => true, |
|
| 126 | + ), |
|
| 127 | + ); |
|
| 128 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 129 | + //partial route/config override |
|
| 130 | + $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes; |
|
| 131 | + $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
| 132 | + $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
| 133 | + $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
| 134 | + $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
| 135 | + $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table'; |
|
| 136 | + //add tickets tab but only if there are more than one default ticket! |
|
| 137 | + $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
| 138 | + array(array('TKT_is_default' => 1)), |
|
| 139 | + 'TKT_ID', |
|
| 140 | + true |
|
| 141 | + ); |
|
| 142 | + if ($tkt_count > 1) { |
|
| 143 | + $new_page_config = array( |
|
| 144 | + 'ticket_list_table' => array( |
|
| 145 | + 'nav' => array( |
|
| 146 | + 'label' => esc_html__('Default Tickets', 'event_espresso'), |
|
| 147 | + 'order' => 60, |
|
| 148 | + ), |
|
| 149 | + 'list_table' => 'Tickets_List_Table', |
|
| 150 | + 'require_nonce' => false, |
|
| 151 | + ), |
|
| 152 | + ); |
|
| 153 | + } |
|
| 154 | + //template settings |
|
| 155 | + $new_page_config['template_settings'] = array( |
|
| 156 | + 'nav' => array( |
|
| 157 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 158 | + 'order' => 30, |
|
| 159 | + ), |
|
| 160 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 161 | + 'help_tabs' => array( |
|
| 162 | + 'general_settings_templates_help_tab' => array( |
|
| 163 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 164 | + 'filename' => 'general_settings_templates', |
|
| 165 | + ), |
|
| 166 | + ), |
|
| 167 | + 'help_tour' => array('Templates_Help_Tour'), |
|
| 168 | + 'require_nonce' => false, |
|
| 169 | + ); |
|
| 170 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 171 | + //add filters and actions |
|
| 172 | + //modifying _views |
|
| 173 | + add_filter( |
|
| 174 | + 'FHEE_event_datetime_metabox_add_additional_date_time_template', |
|
| 175 | + array($this, 'add_additional_datetime_button'), |
|
| 176 | + 10, |
|
| 177 | + 2 |
|
| 178 | + ); |
|
| 179 | + add_filter( |
|
| 180 | + 'FHEE_event_datetime_metabox_clone_button_template', |
|
| 181 | + array($this, 'add_datetime_clone_button'), |
|
| 182 | + 10, |
|
| 183 | + 2 |
|
| 184 | + ); |
|
| 185 | + add_filter( |
|
| 186 | + 'FHEE_event_datetime_metabox_timezones_template', |
|
| 187 | + array($this, 'datetime_timezones_template'), |
|
| 188 | + 10, |
|
| 189 | + 2 |
|
| 190 | + ); |
|
| 191 | + //filters for event list table |
|
| 192 | + add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2); |
|
| 193 | + add_filter( |
|
| 194 | + 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
| 195 | + array($this, 'extra_list_table_actions'), |
|
| 196 | + 10, |
|
| 197 | + 2 |
|
| 198 | + ); |
|
| 199 | + //legend item |
|
| 200 | + add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items')); |
|
| 201 | + add_action('admin_init', array($this, 'admin_init')); |
|
| 202 | + //heartbeat stuff |
|
| 203 | + add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * admin_init |
|
| 209 | + */ |
|
| 210 | + public function admin_init() |
|
| 211 | + { |
|
| 212 | + EE_Registry::$i18n_js_strings = array_merge( |
|
| 213 | + EE_Registry::$i18n_js_strings, |
|
| 214 | + array( |
|
| 215 | + 'image_confirm' => esc_html__( |
|
| 216 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 217 | + 'event_espresso' |
|
| 218 | + ), |
|
| 219 | + 'event_starts_on' => esc_html__('Event Starts on', 'event_espresso'), |
|
| 220 | + 'event_ends_on' => esc_html__('Event Ends on', 'event_espresso'), |
|
| 221 | + 'event_datetime_actions' => esc_html__('Actions', 'event_espresso'), |
|
| 222 | + 'event_clone_dt_msg' => esc_html__('Clone this Event Date and Time', 'event_espresso'), |
|
| 223 | + 'remove_event_dt_msg' => esc_html__('Remove this Event Time', 'event_espresso'), |
|
| 224 | + ) |
|
| 225 | + ); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle |
|
| 231 | + * accordingly. |
|
| 232 | + * |
|
| 233 | + * @param array $response The existing heartbeat response array. |
|
| 234 | + * @param array $data The incoming data package. |
|
| 235 | + * |
|
| 236 | + * @return array possibly appended response. |
|
| 237 | + */ |
|
| 238 | + public function heartbeat_response($response, $data) |
|
| 239 | + { |
|
| 240 | + /** |
|
| 241 | + * check whether count of tickets is approaching the potential |
|
| 242 | + * limits for the server. |
|
| 243 | + */ |
|
| 244 | + if ( ! empty($data['input_count'])) { |
|
| 245 | + $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check( |
|
| 246 | + $data['input_count'] |
|
| 247 | + ); |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - return $response; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - protected function _add_screen_options_ticket_list_table() |
|
| 255 | - { |
|
| 256 | - $this->_per_page_screen_option(); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * @param string $return |
|
| 262 | - * @param int $id |
|
| 263 | - * @param string $new_title |
|
| 264 | - * @param string $new_slug |
|
| 265 | - * |
|
| 266 | - * @return string |
|
| 267 | - */ |
|
| 268 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 269 | - { |
|
| 270 | - $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
|
| 271 | - //make sure this is only when editing |
|
| 272 | - if ( ! empty($id)) { |
|
| 273 | - $href = EE_Admin_Page::add_query_args_and_nonce( |
|
| 274 | - array('action' => 'duplicate_event', 'EVT_ID' => $id), |
|
| 275 | - $this->_admin_base_url |
|
| 276 | - ); |
|
| 277 | - $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
| 278 | - $return .= '<a href="' |
|
| 279 | - . $href |
|
| 280 | - . '" title="' |
|
| 281 | - . $title |
|
| 282 | - . '" id="ee-duplicate-event-button" class="button button-small" value="duplicate_event">' |
|
| 283 | - . $title |
|
| 284 | - . '</button>'; |
|
| 285 | - } |
|
| 250 | + return $response; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + protected function _add_screen_options_ticket_list_table() |
|
| 255 | + { |
|
| 256 | + $this->_per_page_screen_option(); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * @param string $return |
|
| 262 | + * @param int $id |
|
| 263 | + * @param string $new_title |
|
| 264 | + * @param string $new_slug |
|
| 265 | + * |
|
| 266 | + * @return string |
|
| 267 | + */ |
|
| 268 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 269 | + { |
|
| 270 | + $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
|
| 271 | + //make sure this is only when editing |
|
| 272 | + if ( ! empty($id)) { |
|
| 273 | + $href = EE_Admin_Page::add_query_args_and_nonce( |
|
| 274 | + array('action' => 'duplicate_event', 'EVT_ID' => $id), |
|
| 275 | + $this->_admin_base_url |
|
| 276 | + ); |
|
| 277 | + $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
| 278 | + $return .= '<a href="' |
|
| 279 | + . $href |
|
| 280 | + . '" title="' |
|
| 281 | + . $title |
|
| 282 | + . '" id="ee-duplicate-event-button" class="button button-small" value="duplicate_event">' |
|
| 283 | + . $title |
|
| 284 | + . '</button>'; |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - return $return; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - public function _set_list_table_views_ticket_list_table() |
|
| 292 | - { |
|
| 293 | - $this->_views = array( |
|
| 294 | - 'all' => array( |
|
| 295 | - 'slug' => 'all', |
|
| 296 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 297 | - 'count' => 0, |
|
| 298 | - 'bulk_action' => array( |
|
| 299 | - 'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 300 | - ), |
|
| 301 | - ), |
|
| 302 | - 'trashed' => array( |
|
| 303 | - 'slug' => 'trashed', |
|
| 304 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 305 | - 'count' => 0, |
|
| 306 | - 'bulk_action' => array( |
|
| 307 | - 'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'), |
|
| 308 | - 'delete_tickets' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 309 | - ), |
|
| 310 | - ), |
|
| 311 | - ); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - public function load_scripts_styles_edit() |
|
| 316 | - { |
|
| 317 | - wp_register_script( |
|
| 318 | - 'ee-event-editor-heartbeat', |
|
| 319 | - EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
| 320 | - array('ee_admin_js', 'heartbeat'), |
|
| 321 | - EVENT_ESPRESSO_VERSION, |
|
| 322 | - true |
|
| 323 | - ); |
|
| 324 | - /** |
|
| 325 | - * load accounting js. |
|
| 326 | - */ |
|
| 327 | - add_filter('FHEE_load_accounting_js', '__return_true'); |
|
| 328 | - //styles |
|
| 329 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 330 | - wp_enqueue_script('event_editor_js'); |
|
| 331 | - wp_enqueue_script('ee-event-editor-heartbeat'); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * @param $template |
|
| 337 | - * @param $template_args |
|
| 338 | - * |
|
| 339 | - * @return mixed |
|
| 340 | - */ |
|
| 341 | - public function add_additional_datetime_button($template, $template_args) |
|
| 342 | - { |
|
| 343 | - return EEH_Template::display_template( |
|
| 344 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
| 345 | - $template_args, |
|
| 346 | - true |
|
| 347 | - ); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * @param $template |
|
| 353 | - * @param $template_args |
|
| 354 | - * |
|
| 355 | - * @return mixed |
|
| 356 | - */ |
|
| 357 | - public function add_datetime_clone_button($template, $template_args) |
|
| 358 | - { |
|
| 359 | - return EEH_Template::display_template( |
|
| 360 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
| 361 | - $template_args, |
|
| 362 | - true |
|
| 363 | - ); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * @param $template |
|
| 369 | - * @param $template_args |
|
| 370 | - * |
|
| 371 | - * @return mixed |
|
| 372 | - */ |
|
| 373 | - public function datetime_timezones_template($template, $template_args) |
|
| 374 | - { |
|
| 375 | - return EEH_Template::display_template( |
|
| 376 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
| 377 | - $template_args, |
|
| 378 | - true |
|
| 379 | - ); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - protected function _set_list_table_views_default() |
|
| 384 | - { |
|
| 385 | - parent::_set_list_table_views_default(); |
|
| 386 | - $new_views = array( |
|
| 387 | - 'today' => array( |
|
| 388 | - 'slug' => 'today', |
|
| 389 | - 'label' => esc_html__('Today', 'event_espresso'), |
|
| 390 | - 'count' => $this->total_events_today(), |
|
| 391 | - 'bulk_action' => array( |
|
| 392 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 393 | - ), |
|
| 394 | - ), |
|
| 395 | - 'month' => array( |
|
| 396 | - 'slug' => 'month', |
|
| 397 | - 'label' => esc_html__('This Month', 'event_espresso'), |
|
| 398 | - 'count' => $this->total_events_this_month(), |
|
| 399 | - 'bulk_action' => array( |
|
| 400 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 401 | - ), |
|
| 402 | - ), |
|
| 403 | - ); |
|
| 404 | - $this->_views = array_merge($this->_views, $new_views); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * @param array $action_links |
|
| 410 | - * @param \EE_Event $event |
|
| 411 | - * |
|
| 412 | - * @return array |
|
| 413 | - */ |
|
| 414 | - public function extra_list_table_actions(array $action_links, \EE_Event $event) |
|
| 415 | - { |
|
| 416 | - if ( |
|
| 417 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 418 | - 'ee_read_registrations', |
|
| 419 | - 'espresso_registrations_reports', |
|
| 420 | - $event->ID() |
|
| 421 | - ) |
|
| 422 | - ) { |
|
| 423 | - $reports_query_args = array( |
|
| 424 | - 'action' => 'reports', |
|
| 425 | - 'EVT_ID' => $event->ID(), |
|
| 426 | - ); |
|
| 427 | - $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL); |
|
| 428 | - $action_links[] = '<a href="' |
|
| 429 | - . $reports_link |
|
| 430 | - . '" title="' |
|
| 431 | - . esc_attr__('View Report', 'event_espresso') |
|
| 432 | - . '"><div class="dashicons dashicons-chart-bar"></div></a>' |
|
| 433 | - . "\n\t"; |
|
| 434 | - } |
|
| 435 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 436 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 437 | - $action_links[] = EEH_MSG_Template::get_message_action_link( |
|
| 438 | - 'see_notifications_for', |
|
| 439 | - null, |
|
| 440 | - array('EVT_ID' => $event->ID()) |
|
| 441 | - ); |
|
| 442 | - } |
|
| 287 | + return $return; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + public function _set_list_table_views_ticket_list_table() |
|
| 292 | + { |
|
| 293 | + $this->_views = array( |
|
| 294 | + 'all' => array( |
|
| 295 | + 'slug' => 'all', |
|
| 296 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 297 | + 'count' => 0, |
|
| 298 | + 'bulk_action' => array( |
|
| 299 | + 'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 300 | + ), |
|
| 301 | + ), |
|
| 302 | + 'trashed' => array( |
|
| 303 | + 'slug' => 'trashed', |
|
| 304 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 305 | + 'count' => 0, |
|
| 306 | + 'bulk_action' => array( |
|
| 307 | + 'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'), |
|
| 308 | + 'delete_tickets' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 309 | + ), |
|
| 310 | + ), |
|
| 311 | + ); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + public function load_scripts_styles_edit() |
|
| 316 | + { |
|
| 317 | + wp_register_script( |
|
| 318 | + 'ee-event-editor-heartbeat', |
|
| 319 | + EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
| 320 | + array('ee_admin_js', 'heartbeat'), |
|
| 321 | + EVENT_ESPRESSO_VERSION, |
|
| 322 | + true |
|
| 323 | + ); |
|
| 324 | + /** |
|
| 325 | + * load accounting js. |
|
| 326 | + */ |
|
| 327 | + add_filter('FHEE_load_accounting_js', '__return_true'); |
|
| 328 | + //styles |
|
| 329 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 330 | + wp_enqueue_script('event_editor_js'); |
|
| 331 | + wp_enqueue_script('ee-event-editor-heartbeat'); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * @param $template |
|
| 337 | + * @param $template_args |
|
| 338 | + * |
|
| 339 | + * @return mixed |
|
| 340 | + */ |
|
| 341 | + public function add_additional_datetime_button($template, $template_args) |
|
| 342 | + { |
|
| 343 | + return EEH_Template::display_template( |
|
| 344 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
| 345 | + $template_args, |
|
| 346 | + true |
|
| 347 | + ); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * @param $template |
|
| 353 | + * @param $template_args |
|
| 354 | + * |
|
| 355 | + * @return mixed |
|
| 356 | + */ |
|
| 357 | + public function add_datetime_clone_button($template, $template_args) |
|
| 358 | + { |
|
| 359 | + return EEH_Template::display_template( |
|
| 360 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
| 361 | + $template_args, |
|
| 362 | + true |
|
| 363 | + ); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * @param $template |
|
| 369 | + * @param $template_args |
|
| 370 | + * |
|
| 371 | + * @return mixed |
|
| 372 | + */ |
|
| 373 | + public function datetime_timezones_template($template, $template_args) |
|
| 374 | + { |
|
| 375 | + return EEH_Template::display_template( |
|
| 376 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
| 377 | + $template_args, |
|
| 378 | + true |
|
| 379 | + ); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + protected function _set_list_table_views_default() |
|
| 384 | + { |
|
| 385 | + parent::_set_list_table_views_default(); |
|
| 386 | + $new_views = array( |
|
| 387 | + 'today' => array( |
|
| 388 | + 'slug' => 'today', |
|
| 389 | + 'label' => esc_html__('Today', 'event_espresso'), |
|
| 390 | + 'count' => $this->total_events_today(), |
|
| 391 | + 'bulk_action' => array( |
|
| 392 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 393 | + ), |
|
| 394 | + ), |
|
| 395 | + 'month' => array( |
|
| 396 | + 'slug' => 'month', |
|
| 397 | + 'label' => esc_html__('This Month', 'event_espresso'), |
|
| 398 | + 'count' => $this->total_events_this_month(), |
|
| 399 | + 'bulk_action' => array( |
|
| 400 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 401 | + ), |
|
| 402 | + ), |
|
| 403 | + ); |
|
| 404 | + $this->_views = array_merge($this->_views, $new_views); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * @param array $action_links |
|
| 410 | + * @param \EE_Event $event |
|
| 411 | + * |
|
| 412 | + * @return array |
|
| 413 | + */ |
|
| 414 | + public function extra_list_table_actions(array $action_links, \EE_Event $event) |
|
| 415 | + { |
|
| 416 | + if ( |
|
| 417 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 418 | + 'ee_read_registrations', |
|
| 419 | + 'espresso_registrations_reports', |
|
| 420 | + $event->ID() |
|
| 421 | + ) |
|
| 422 | + ) { |
|
| 423 | + $reports_query_args = array( |
|
| 424 | + 'action' => 'reports', |
|
| 425 | + 'EVT_ID' => $event->ID(), |
|
| 426 | + ); |
|
| 427 | + $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL); |
|
| 428 | + $action_links[] = '<a href="' |
|
| 429 | + . $reports_link |
|
| 430 | + . '" title="' |
|
| 431 | + . esc_attr__('View Report', 'event_espresso') |
|
| 432 | + . '"><div class="dashicons dashicons-chart-bar"></div></a>' |
|
| 433 | + . "\n\t"; |
|
| 434 | + } |
|
| 435 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 436 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 437 | + $action_links[] = EEH_MSG_Template::get_message_action_link( |
|
| 438 | + 'see_notifications_for', |
|
| 439 | + null, |
|
| 440 | + array('EVT_ID' => $event->ID()) |
|
| 441 | + ); |
|
| 442 | + } |
|
| 443 | 443 | |
| 444 | - return $action_links; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * @param $items |
|
| 450 | - * |
|
| 451 | - * @return mixed |
|
| 452 | - */ |
|
| 453 | - public function additional_legend_items($items) |
|
| 454 | - { |
|
| 455 | - if ( |
|
| 456 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 457 | - 'ee_read_registrations', |
|
| 458 | - 'espresso_registrations_reports' |
|
| 459 | - ) |
|
| 460 | - ) { |
|
| 461 | - $items['reports'] = array( |
|
| 462 | - 'class' => 'dashicons dashicons-chart-bar', |
|
| 463 | - 'desc' => esc_html__('Event Reports', 'event_espresso'), |
|
| 464 | - ); |
|
| 465 | - } |
|
| 466 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 467 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 468 | - if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 469 | - $items['view_related_messages'] = array( |
|
| 470 | - 'class' => $related_for_icon['css_class'], |
|
| 471 | - 'desc' => $related_for_icon['label'], |
|
| 472 | - ); |
|
| 473 | - } |
|
| 474 | - } |
|
| 444 | + return $action_links; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * @param $items |
|
| 450 | + * |
|
| 451 | + * @return mixed |
|
| 452 | + */ |
|
| 453 | + public function additional_legend_items($items) |
|
| 454 | + { |
|
| 455 | + if ( |
|
| 456 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 457 | + 'ee_read_registrations', |
|
| 458 | + 'espresso_registrations_reports' |
|
| 459 | + ) |
|
| 460 | + ) { |
|
| 461 | + $items['reports'] = array( |
|
| 462 | + 'class' => 'dashicons dashicons-chart-bar', |
|
| 463 | + 'desc' => esc_html__('Event Reports', 'event_espresso'), |
|
| 464 | + ); |
|
| 465 | + } |
|
| 466 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 467 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 468 | + if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 469 | + $items['view_related_messages'] = array( |
|
| 470 | + 'class' => $related_for_icon['css_class'], |
|
| 471 | + 'desc' => $related_for_icon['label'], |
|
| 472 | + ); |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | 475 | |
| 476 | - return $items; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - |
|
| 480 | - /** |
|
| 481 | - * This is the callback method for the duplicate event route |
|
| 482 | - * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them |
|
| 483 | - * into a new event. We add a hook so that any plugins that add extra event details can hook into this |
|
| 484 | - * action. Note that the dupe will have **DUPLICATE** as its title and slug. |
|
| 485 | - * After duplication the redirect is to the new event edit page. |
|
| 486 | - * |
|
| 487 | - * @return void |
|
| 488 | - * @access protected |
|
| 489 | - * @throws EE_Error If EE_Event is not available with given ID |
|
| 490 | - */ |
|
| 491 | - protected function _duplicate_event() |
|
| 492 | - { |
|
| 493 | - // first make sure the ID for the event is in the request. |
|
| 494 | - // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
|
| 495 | - if ( ! isset($this->_req_data['EVT_ID'])) { |
|
| 496 | - EE_Error::add_error( |
|
| 497 | - esc_html__( |
|
| 498 | - 'In order to duplicate an event an Event ID is required. None was given.', |
|
| 499 | - 'event_espresso' |
|
| 500 | - ), |
|
| 501 | - __FILE__, |
|
| 502 | - __FUNCTION__, |
|
| 503 | - __LINE__ |
|
| 504 | - ); |
|
| 505 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 476 | + return $items; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + |
|
| 480 | + /** |
|
| 481 | + * This is the callback method for the duplicate event route |
|
| 482 | + * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them |
|
| 483 | + * into a new event. We add a hook so that any plugins that add extra event details can hook into this |
|
| 484 | + * action. Note that the dupe will have **DUPLICATE** as its title and slug. |
|
| 485 | + * After duplication the redirect is to the new event edit page. |
|
| 486 | + * |
|
| 487 | + * @return void |
|
| 488 | + * @access protected |
|
| 489 | + * @throws EE_Error If EE_Event is not available with given ID |
|
| 490 | + */ |
|
| 491 | + protected function _duplicate_event() |
|
| 492 | + { |
|
| 493 | + // first make sure the ID for the event is in the request. |
|
| 494 | + // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
|
| 495 | + if ( ! isset($this->_req_data['EVT_ID'])) { |
|
| 496 | + EE_Error::add_error( |
|
| 497 | + esc_html__( |
|
| 498 | + 'In order to duplicate an event an Event ID is required. None was given.', |
|
| 499 | + 'event_espresso' |
|
| 500 | + ), |
|
| 501 | + __FILE__, |
|
| 502 | + __FUNCTION__, |
|
| 503 | + __LINE__ |
|
| 504 | + ); |
|
| 505 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 506 | 506 | |
| 507 | - return; |
|
| 508 | - } |
|
| 509 | - //k we've got EVT_ID so let's use that to get the event we'll duplicate |
|
| 510 | - $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']); |
|
| 511 | - if ( ! $orig_event instanceof EE_Event) { |
|
| 512 | - throw new EE_Error( |
|
| 513 | - sprintf( |
|
| 514 | - esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
|
| 515 | - $this->_req_data['EVT_ID'] |
|
| 516 | - ) |
|
| 517 | - ); |
|
| 518 | - } |
|
| 519 | - //k now let's clone the $orig_event before getting relations |
|
| 520 | - $new_event = clone $orig_event; |
|
| 521 | - //original datetimes |
|
| 522 | - $orig_datetimes = $orig_event->get_many_related('Datetime'); |
|
| 523 | - //other original relations |
|
| 524 | - $orig_ven = $orig_event->get_many_related('Venue'); |
|
| 525 | - //reset the ID and modify other details to make it clear this is a dupe |
|
| 526 | - $new_event->set('EVT_ID', 0); |
|
| 527 | - $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
| 528 | - $new_event->set('EVT_name', $new_name); |
|
| 529 | - $new_event->set( |
|
| 530 | - 'EVT_slug', |
|
| 531 | - wp_unique_post_slug( |
|
| 532 | - sanitize_title($orig_event->name()), |
|
| 533 | - 0, |
|
| 534 | - 'publish', |
|
| 535 | - 'espresso_events', |
|
| 536 | - 0 |
|
| 537 | - ) |
|
| 538 | - ); |
|
| 539 | - $new_event->set('status', 'draft'); |
|
| 540 | - //duplicate discussion settings |
|
| 541 | - $new_event->set('comment_status', $orig_event->get('comment_status')); |
|
| 542 | - $new_event->set('ping_status', $orig_event->get('ping_status')); |
|
| 543 | - //save the new event |
|
| 544 | - $new_event->save(); |
|
| 545 | - //venues |
|
| 546 | - foreach ($orig_ven as $ven) { |
|
| 547 | - $new_event->_add_relation_to($ven, 'Venue'); |
|
| 548 | - } |
|
| 549 | - $new_event->save(); |
|
| 550 | - //now we need to get the question group relations and handle that |
|
| 551 | - //first primary question groups |
|
| 552 | - $orig_primary_qgs = $orig_event->get_many_related( |
|
| 553 | - 'Question_Group', |
|
| 554 | - array(array('Event_Question_Group.EQG_primary' => 1)) |
|
| 555 | - ); |
|
| 556 | - if ( ! empty($orig_primary_qgs)) { |
|
| 557 | - foreach ($orig_primary_qgs as $id => $obj) { |
|
| 558 | - if ($obj instanceof EE_Question_Group) { |
|
| 559 | - $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1)); |
|
| 560 | - } |
|
| 561 | - } |
|
| 562 | - } |
|
| 563 | - //next additional attendee question groups |
|
| 564 | - $orig_additional_qgs = $orig_event->get_many_related( |
|
| 565 | - 'Question_Group', |
|
| 566 | - array(array('Event_Question_Group.EQG_primary' => 0)) |
|
| 567 | - ); |
|
| 568 | - if ( ! empty($orig_additional_qgs)) { |
|
| 569 | - foreach ($orig_additional_qgs as $id => $obj) { |
|
| 570 | - if ($obj instanceof EE_Question_Group) { |
|
| 571 | - $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0)); |
|
| 572 | - } |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - //now save |
|
| 576 | - $new_event->save(); |
|
| 577 | - //k now that we have the new event saved we can loop through the datetimes and start adding relations. |
|
| 578 | - $cloned_tickets = array(); |
|
| 579 | - foreach ($orig_datetimes as $orig_dtt) { |
|
| 580 | - if ( ! $orig_dtt instanceof EE_Datetime) { |
|
| 581 | - continue; |
|
| 582 | - } |
|
| 583 | - $new_dtt = clone $orig_dtt; |
|
| 584 | - $orig_tkts = $orig_dtt->tickets(); |
|
| 585 | - //save new dtt then add to event |
|
| 586 | - $new_dtt->set('DTT_ID', 0); |
|
| 587 | - $new_dtt->set('DTT_sold', 0); |
|
| 588 | - $new_dtt->save(); |
|
| 589 | - $new_event->_add_relation_to($new_dtt, 'Datetime'); |
|
| 590 | - $new_event->save(); |
|
| 591 | - //now let's get the ticket relations setup. |
|
| 592 | - foreach ((array)$orig_tkts as $orig_tkt) { |
|
| 593 | - //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
|
| 594 | - if ( ! $orig_tkt instanceof EE_Ticket) { |
|
| 595 | - continue; |
|
| 596 | - } |
|
| 597 | - //is this ticket archived? If it is then let's skip |
|
| 598 | - if ($orig_tkt->get('TKT_deleted')) { |
|
| 599 | - continue; |
|
| 600 | - } |
|
| 601 | - // does this original ticket already exist in the clone_tickets cache? |
|
| 602 | - // If so we'll just use the new ticket from it. |
|
| 603 | - if (isset($cloned_tickets[$orig_tkt->ID()])) { |
|
| 604 | - $new_tkt = $cloned_tickets[$orig_tkt->ID()]; |
|
| 605 | - } else { |
|
| 606 | - $new_tkt = clone $orig_tkt; |
|
| 607 | - //get relations on the $orig_tkt that we need to setup. |
|
| 608 | - $orig_prices = $orig_tkt->prices(); |
|
| 609 | - $new_tkt->set('TKT_ID', 0); |
|
| 610 | - $new_tkt->set('TKT_sold', 0); |
|
| 611 | - $new_tkt->save(); //make sure new ticket has ID. |
|
| 612 | - //price relations on new ticket need to be setup. |
|
| 613 | - foreach ($orig_prices as $orig_price) { |
|
| 614 | - $new_price = clone $orig_price; |
|
| 615 | - $new_price->set('PRC_ID', 0); |
|
| 616 | - $new_price->save(); |
|
| 617 | - $new_tkt->_add_relation_to($new_price, 'Price'); |
|
| 618 | - $new_tkt->save(); |
|
| 619 | - } |
|
| 620 | - } |
|
| 621 | - // k now we can add the new ticket as a relation to the new datetime |
|
| 622 | - // and make sure its added to our cached $cloned_tickets array |
|
| 623 | - // for use with later datetimes that have the same ticket. |
|
| 624 | - $new_dtt->_add_relation_to($new_tkt, 'Ticket'); |
|
| 625 | - $new_dtt->save(); |
|
| 626 | - $cloned_tickets[$orig_tkt->ID()] = $new_tkt; |
|
| 627 | - } |
|
| 628 | - } |
|
| 629 | - //clone taxonomy information |
|
| 630 | - $taxonomies_to_clone_with = apply_filters( |
|
| 631 | - 'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone', |
|
| 632 | - array('espresso_event_categories', 'espresso_event_type', 'post_tag') |
|
| 633 | - ); |
|
| 634 | - //get terms for original event (notice) |
|
| 635 | - $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with); |
|
| 636 | - //loop through terms and add them to new event. |
|
| 637 | - foreach ($orig_terms as $term) { |
|
| 638 | - wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true); |
|
| 639 | - } |
|
| 640 | - do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event); |
|
| 641 | - //now let's redirect to the edit page for this duplicated event if we have a new event id. |
|
| 642 | - if ($new_event->ID()) { |
|
| 643 | - $redirect_args = array( |
|
| 644 | - 'post' => $new_event->ID(), |
|
| 645 | - 'action' => 'edit', |
|
| 646 | - ); |
|
| 647 | - EE_Error::add_success( |
|
| 648 | - esc_html__( |
|
| 649 | - 'Event successfully duplicated. Please review the details below and make any necessary edits', |
|
| 650 | - 'event_espresso' |
|
| 651 | - ) |
|
| 652 | - ); |
|
| 653 | - } else { |
|
| 654 | - $redirect_args = array( |
|
| 655 | - 'action' => 'default', |
|
| 656 | - ); |
|
| 657 | - EE_Error::add_error( |
|
| 658 | - esc_html__('Not able to duplicate event. Something went wrong.', 'event_espresso'), |
|
| 659 | - __FILE__, |
|
| 660 | - __FUNCTION__, |
|
| 661 | - __LINE__ |
|
| 662 | - ); |
|
| 663 | - } |
|
| 664 | - $this->_redirect_after_action(false, '', '', $redirect_args, true); |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - |
|
| 668 | - protected function _import_page() |
|
| 669 | - { |
|
| 670 | - $title = esc_html__('Import', 'event_espresso'); |
|
| 671 | - $intro = esc_html__( |
|
| 672 | - 'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ', |
|
| 673 | - 'event_espresso' |
|
| 674 | - ); |
|
| 675 | - $form_url = EVENTS_ADMIN_URL; |
|
| 676 | - $action = 'import_events'; |
|
| 677 | - $type = 'csv'; |
|
| 678 | - $this->_template_args['form'] = EE_Import::instance()->upload_form($title, $intro, $form_url, |
|
| 679 | - $action, $type); |
|
| 680 | - $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 681 | - array('action' => 'sample_export_file'), |
|
| 682 | - $this->_admin_base_url |
|
| 683 | - ); |
|
| 684 | - $content = EEH_Template::display_template( |
|
| 685 | - EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
| 686 | - $this->_template_args, |
|
| 687 | - true |
|
| 688 | - ); |
|
| 689 | - $this->_template_args['admin_page_content'] = $content; |
|
| 690 | - $this->display_admin_page_with_sidebar(); |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * _import_events |
|
| 696 | - * This handles displaying the screen and running imports for importing events. |
|
| 697 | - * |
|
| 698 | - * @return void |
|
| 699 | - */ |
|
| 700 | - protected function _import_events() |
|
| 701 | - { |
|
| 702 | - require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
| 703 | - $success = EE_Import::instance()->import(); |
|
| 704 | - $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true); |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - |
|
| 708 | - /** |
|
| 709 | - * _events_export |
|
| 710 | - * Will export all (or just the given event) to a Excel compatible file. |
|
| 711 | - * |
|
| 712 | - * @access protected |
|
| 713 | - * @return void |
|
| 714 | - */ |
|
| 715 | - protected function _events_export() |
|
| 716 | - { |
|
| 717 | - if (isset($this->_req_data['EVT_ID'])) { |
|
| 718 | - $event_ids = $this->_req_data['EVT_ID']; |
|
| 719 | - } elseif (isset($this->_req_data['EVT_IDs'])) { |
|
| 720 | - $event_ids = $this->_req_data['EVT_IDs']; |
|
| 721 | - } else { |
|
| 722 | - $event_ids = null; |
|
| 723 | - } |
|
| 724 | - //todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
| 725 | - $new_request_args = array( |
|
| 726 | - 'export' => 'report', |
|
| 727 | - 'action' => 'all_event_data', |
|
| 728 | - 'EVT_ID' => $event_ids, |
|
| 729 | - ); |
|
| 730 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 731 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 732 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 733 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 734 | - $EE_Export->export(); |
|
| 735 | - } |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - |
|
| 739 | - /** |
|
| 740 | - * handle category exports() |
|
| 741 | - * |
|
| 742 | - * @return void |
|
| 743 | - */ |
|
| 744 | - protected function _categories_export() |
|
| 745 | - { |
|
| 746 | - //todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
| 747 | - $new_request_args = array( |
|
| 748 | - 'export' => 'report', |
|
| 749 | - 'action' => 'categories', |
|
| 750 | - 'category_ids' => $this->_req_data['EVT_CAT_ID'], |
|
| 751 | - ); |
|
| 752 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 753 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 754 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 755 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 756 | - $EE_Export->export(); |
|
| 757 | - } |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - |
|
| 761 | - /** |
|
| 762 | - * Creates a sample CSV file for importing |
|
| 763 | - */ |
|
| 764 | - protected function _sample_export_file() |
|
| 765 | - { |
|
| 507 | + return; |
|
| 508 | + } |
|
| 509 | + //k we've got EVT_ID so let's use that to get the event we'll duplicate |
|
| 510 | + $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']); |
|
| 511 | + if ( ! $orig_event instanceof EE_Event) { |
|
| 512 | + throw new EE_Error( |
|
| 513 | + sprintf( |
|
| 514 | + esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
|
| 515 | + $this->_req_data['EVT_ID'] |
|
| 516 | + ) |
|
| 517 | + ); |
|
| 518 | + } |
|
| 519 | + //k now let's clone the $orig_event before getting relations |
|
| 520 | + $new_event = clone $orig_event; |
|
| 521 | + //original datetimes |
|
| 522 | + $orig_datetimes = $orig_event->get_many_related('Datetime'); |
|
| 523 | + //other original relations |
|
| 524 | + $orig_ven = $orig_event->get_many_related('Venue'); |
|
| 525 | + //reset the ID and modify other details to make it clear this is a dupe |
|
| 526 | + $new_event->set('EVT_ID', 0); |
|
| 527 | + $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
| 528 | + $new_event->set('EVT_name', $new_name); |
|
| 529 | + $new_event->set( |
|
| 530 | + 'EVT_slug', |
|
| 531 | + wp_unique_post_slug( |
|
| 532 | + sanitize_title($orig_event->name()), |
|
| 533 | + 0, |
|
| 534 | + 'publish', |
|
| 535 | + 'espresso_events', |
|
| 536 | + 0 |
|
| 537 | + ) |
|
| 538 | + ); |
|
| 539 | + $new_event->set('status', 'draft'); |
|
| 540 | + //duplicate discussion settings |
|
| 541 | + $new_event->set('comment_status', $orig_event->get('comment_status')); |
|
| 542 | + $new_event->set('ping_status', $orig_event->get('ping_status')); |
|
| 543 | + //save the new event |
|
| 544 | + $new_event->save(); |
|
| 545 | + //venues |
|
| 546 | + foreach ($orig_ven as $ven) { |
|
| 547 | + $new_event->_add_relation_to($ven, 'Venue'); |
|
| 548 | + } |
|
| 549 | + $new_event->save(); |
|
| 550 | + //now we need to get the question group relations and handle that |
|
| 551 | + //first primary question groups |
|
| 552 | + $orig_primary_qgs = $orig_event->get_many_related( |
|
| 553 | + 'Question_Group', |
|
| 554 | + array(array('Event_Question_Group.EQG_primary' => 1)) |
|
| 555 | + ); |
|
| 556 | + if ( ! empty($orig_primary_qgs)) { |
|
| 557 | + foreach ($orig_primary_qgs as $id => $obj) { |
|
| 558 | + if ($obj instanceof EE_Question_Group) { |
|
| 559 | + $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1)); |
|
| 560 | + } |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | + //next additional attendee question groups |
|
| 564 | + $orig_additional_qgs = $orig_event->get_many_related( |
|
| 565 | + 'Question_Group', |
|
| 566 | + array(array('Event_Question_Group.EQG_primary' => 0)) |
|
| 567 | + ); |
|
| 568 | + if ( ! empty($orig_additional_qgs)) { |
|
| 569 | + foreach ($orig_additional_qgs as $id => $obj) { |
|
| 570 | + if ($obj instanceof EE_Question_Group) { |
|
| 571 | + $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0)); |
|
| 572 | + } |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + //now save |
|
| 576 | + $new_event->save(); |
|
| 577 | + //k now that we have the new event saved we can loop through the datetimes and start adding relations. |
|
| 578 | + $cloned_tickets = array(); |
|
| 579 | + foreach ($orig_datetimes as $orig_dtt) { |
|
| 580 | + if ( ! $orig_dtt instanceof EE_Datetime) { |
|
| 581 | + continue; |
|
| 582 | + } |
|
| 583 | + $new_dtt = clone $orig_dtt; |
|
| 584 | + $orig_tkts = $orig_dtt->tickets(); |
|
| 585 | + //save new dtt then add to event |
|
| 586 | + $new_dtt->set('DTT_ID', 0); |
|
| 587 | + $new_dtt->set('DTT_sold', 0); |
|
| 588 | + $new_dtt->save(); |
|
| 589 | + $new_event->_add_relation_to($new_dtt, 'Datetime'); |
|
| 590 | + $new_event->save(); |
|
| 591 | + //now let's get the ticket relations setup. |
|
| 592 | + foreach ((array)$orig_tkts as $orig_tkt) { |
|
| 593 | + //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
|
| 594 | + if ( ! $orig_tkt instanceof EE_Ticket) { |
|
| 595 | + continue; |
|
| 596 | + } |
|
| 597 | + //is this ticket archived? If it is then let's skip |
|
| 598 | + if ($orig_tkt->get('TKT_deleted')) { |
|
| 599 | + continue; |
|
| 600 | + } |
|
| 601 | + // does this original ticket already exist in the clone_tickets cache? |
|
| 602 | + // If so we'll just use the new ticket from it. |
|
| 603 | + if (isset($cloned_tickets[$orig_tkt->ID()])) { |
|
| 604 | + $new_tkt = $cloned_tickets[$orig_tkt->ID()]; |
|
| 605 | + } else { |
|
| 606 | + $new_tkt = clone $orig_tkt; |
|
| 607 | + //get relations on the $orig_tkt that we need to setup. |
|
| 608 | + $orig_prices = $orig_tkt->prices(); |
|
| 609 | + $new_tkt->set('TKT_ID', 0); |
|
| 610 | + $new_tkt->set('TKT_sold', 0); |
|
| 611 | + $new_tkt->save(); //make sure new ticket has ID. |
|
| 612 | + //price relations on new ticket need to be setup. |
|
| 613 | + foreach ($orig_prices as $orig_price) { |
|
| 614 | + $new_price = clone $orig_price; |
|
| 615 | + $new_price->set('PRC_ID', 0); |
|
| 616 | + $new_price->save(); |
|
| 617 | + $new_tkt->_add_relation_to($new_price, 'Price'); |
|
| 618 | + $new_tkt->save(); |
|
| 619 | + } |
|
| 620 | + } |
|
| 621 | + // k now we can add the new ticket as a relation to the new datetime |
|
| 622 | + // and make sure its added to our cached $cloned_tickets array |
|
| 623 | + // for use with later datetimes that have the same ticket. |
|
| 624 | + $new_dtt->_add_relation_to($new_tkt, 'Ticket'); |
|
| 625 | + $new_dtt->save(); |
|
| 626 | + $cloned_tickets[$orig_tkt->ID()] = $new_tkt; |
|
| 627 | + } |
|
| 628 | + } |
|
| 629 | + //clone taxonomy information |
|
| 630 | + $taxonomies_to_clone_with = apply_filters( |
|
| 631 | + 'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone', |
|
| 632 | + array('espresso_event_categories', 'espresso_event_type', 'post_tag') |
|
| 633 | + ); |
|
| 634 | + //get terms for original event (notice) |
|
| 635 | + $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with); |
|
| 636 | + //loop through terms and add them to new event. |
|
| 637 | + foreach ($orig_terms as $term) { |
|
| 638 | + wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true); |
|
| 639 | + } |
|
| 640 | + do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event); |
|
| 641 | + //now let's redirect to the edit page for this duplicated event if we have a new event id. |
|
| 642 | + if ($new_event->ID()) { |
|
| 643 | + $redirect_args = array( |
|
| 644 | + 'post' => $new_event->ID(), |
|
| 645 | + 'action' => 'edit', |
|
| 646 | + ); |
|
| 647 | + EE_Error::add_success( |
|
| 648 | + esc_html__( |
|
| 649 | + 'Event successfully duplicated. Please review the details below and make any necessary edits', |
|
| 650 | + 'event_espresso' |
|
| 651 | + ) |
|
| 652 | + ); |
|
| 653 | + } else { |
|
| 654 | + $redirect_args = array( |
|
| 655 | + 'action' => 'default', |
|
| 656 | + ); |
|
| 657 | + EE_Error::add_error( |
|
| 658 | + esc_html__('Not able to duplicate event. Something went wrong.', 'event_espresso'), |
|
| 659 | + __FILE__, |
|
| 660 | + __FUNCTION__, |
|
| 661 | + __LINE__ |
|
| 662 | + ); |
|
| 663 | + } |
|
| 664 | + $this->_redirect_after_action(false, '', '', $redirect_args, true); |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + |
|
| 668 | + protected function _import_page() |
|
| 669 | + { |
|
| 670 | + $title = esc_html__('Import', 'event_espresso'); |
|
| 671 | + $intro = esc_html__( |
|
| 672 | + 'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ', |
|
| 673 | + 'event_espresso' |
|
| 674 | + ); |
|
| 675 | + $form_url = EVENTS_ADMIN_URL; |
|
| 676 | + $action = 'import_events'; |
|
| 677 | + $type = 'csv'; |
|
| 678 | + $this->_template_args['form'] = EE_Import::instance()->upload_form($title, $intro, $form_url, |
|
| 679 | + $action, $type); |
|
| 680 | + $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 681 | + array('action' => 'sample_export_file'), |
|
| 682 | + $this->_admin_base_url |
|
| 683 | + ); |
|
| 684 | + $content = EEH_Template::display_template( |
|
| 685 | + EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
| 686 | + $this->_template_args, |
|
| 687 | + true |
|
| 688 | + ); |
|
| 689 | + $this->_template_args['admin_page_content'] = $content; |
|
| 690 | + $this->display_admin_page_with_sidebar(); |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * _import_events |
|
| 696 | + * This handles displaying the screen and running imports for importing events. |
|
| 697 | + * |
|
| 698 | + * @return void |
|
| 699 | + */ |
|
| 700 | + protected function _import_events() |
|
| 701 | + { |
|
| 702 | + require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
| 703 | + $success = EE_Import::instance()->import(); |
|
| 704 | + $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true); |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + |
|
| 708 | + /** |
|
| 709 | + * _events_export |
|
| 710 | + * Will export all (or just the given event) to a Excel compatible file. |
|
| 711 | + * |
|
| 712 | + * @access protected |
|
| 713 | + * @return void |
|
| 714 | + */ |
|
| 715 | + protected function _events_export() |
|
| 716 | + { |
|
| 717 | + if (isset($this->_req_data['EVT_ID'])) { |
|
| 718 | + $event_ids = $this->_req_data['EVT_ID']; |
|
| 719 | + } elseif (isset($this->_req_data['EVT_IDs'])) { |
|
| 720 | + $event_ids = $this->_req_data['EVT_IDs']; |
|
| 721 | + } else { |
|
| 722 | + $event_ids = null; |
|
| 723 | + } |
|
| 724 | + //todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
| 725 | + $new_request_args = array( |
|
| 726 | + 'export' => 'report', |
|
| 727 | + 'action' => 'all_event_data', |
|
| 728 | + 'EVT_ID' => $event_ids, |
|
| 729 | + ); |
|
| 730 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 731 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 732 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 733 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 734 | + $EE_Export->export(); |
|
| 735 | + } |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + |
|
| 739 | + /** |
|
| 740 | + * handle category exports() |
|
| 741 | + * |
|
| 742 | + * @return void |
|
| 743 | + */ |
|
| 744 | + protected function _categories_export() |
|
| 745 | + { |
|
| 746 | + //todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
| 747 | + $new_request_args = array( |
|
| 748 | + 'export' => 'report', |
|
| 749 | + 'action' => 'categories', |
|
| 750 | + 'category_ids' => $this->_req_data['EVT_CAT_ID'], |
|
| 751 | + ); |
|
| 752 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 753 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 754 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 755 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 756 | + $EE_Export->export(); |
|
| 757 | + } |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + |
|
| 761 | + /** |
|
| 762 | + * Creates a sample CSV file for importing |
|
| 763 | + */ |
|
| 764 | + protected function _sample_export_file() |
|
| 765 | + { |
|
| 766 | 766 | // require_once(EE_CLASSES . 'EE_Export.class.php'); |
| 767 | - EE_Export::instance()->export_sample(); |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - |
|
| 771 | - /************* Template Settings *************/ |
|
| 772 | - protected function _template_settings() |
|
| 773 | - { |
|
| 774 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 775 | - /** |
|
| 776 | - * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
| 777 | - * from General_Settings_Admin_Page to here. |
|
| 778 | - */ |
|
| 779 | - $this->_template_args = apply_filters( |
|
| 780 | - 'FHEE__General_Settings_Admin_Page__template_settings__template_args', |
|
| 781 | - $this->_template_args |
|
| 782 | - ); |
|
| 783 | - $this->_set_add_edit_form_tags('update_template_settings'); |
|
| 784 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 785 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 786 | - EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
| 787 | - $this->_template_args, |
|
| 788 | - true |
|
| 789 | - ); |
|
| 790 | - $this->display_admin_page_with_sidebar(); |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - |
|
| 794 | - protected function _update_template_settings() |
|
| 795 | - { |
|
| 796 | - /** |
|
| 797 | - * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
| 798 | - * from General_Settings_Admin_Page to here. |
|
| 799 | - */ |
|
| 800 | - EE_Registry::instance()->CFG->template_settings = apply_filters( |
|
| 801 | - 'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
| 802 | - EE_Registry::instance()->CFG->template_settings, |
|
| 803 | - $this->_req_data |
|
| 804 | - ); |
|
| 805 | - //update custom post type slugs and detect if we need to flush rewrite rules |
|
| 806 | - $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
| 807 | - EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug']) |
|
| 808 | - ? EE_Registry::instance()->CFG->core->event_cpt_slug |
|
| 809 | - : sanitize_title_with_dashes($this->_req_data['event_cpt_slug']); |
|
| 810 | - $what = 'Template Settings'; |
|
| 811 | - $success = $this->_update_espresso_configuration( |
|
| 812 | - $what, |
|
| 813 | - EE_Registry::instance()->CFG->template_settings, |
|
| 814 | - __FILE__, |
|
| 815 | - __FUNCTION__, |
|
| 816 | - __LINE__ |
|
| 817 | - ); |
|
| 818 | - if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) { |
|
| 819 | - update_option('ee_flush_rewrite_rules', true); |
|
| 820 | - } |
|
| 821 | - $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings')); |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - |
|
| 825 | - /** |
|
| 826 | - * _premium_event_editor_meta_boxes |
|
| 827 | - * add all metaboxes related to the event_editor |
|
| 828 | - * |
|
| 829 | - * @access protected |
|
| 830 | - * @return void |
|
| 831 | - */ |
|
| 832 | - protected function _premium_event_editor_meta_boxes() |
|
| 833 | - { |
|
| 834 | - $this->verify_cpt_object(); |
|
| 835 | - add_meta_box( |
|
| 836 | - 'espresso_event_editor_event_options', |
|
| 837 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
| 838 | - array($this, 'registration_options_meta_box'), |
|
| 839 | - $this->page_slug, |
|
| 840 | - 'side', |
|
| 841 | - 'core' |
|
| 842 | - ); |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - |
|
| 846 | - /** |
|
| 847 | - * override caf metabox |
|
| 848 | - * |
|
| 849 | - * @return void |
|
| 850 | - */ |
|
| 851 | - public function registration_options_meta_box() |
|
| 852 | - { |
|
| 853 | - $yes_no_values = array( |
|
| 854 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 855 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 856 | - ); |
|
| 857 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 858 | - array( |
|
| 859 | - EEM_Registration::status_id_cancelled, |
|
| 860 | - EEM_Registration::status_id_declined, |
|
| 861 | - EEM_Registration::status_id_incomplete, |
|
| 862 | - EEM_Registration::status_id_wait_list, |
|
| 863 | - ), |
|
| 864 | - true |
|
| 865 | - ); |
|
| 866 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 867 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
| 868 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 869 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 870 | - 'default_reg_status', |
|
| 871 | - $default_reg_status_values, |
|
| 872 | - $this->_cpt_model_obj->default_registration_status() |
|
| 873 | - ); |
|
| 874 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 875 | - 'display_desc', |
|
| 876 | - $yes_no_values, |
|
| 877 | - $this->_cpt_model_obj->display_description() |
|
| 878 | - ); |
|
| 879 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 880 | - 'display_ticket_selector', |
|
| 881 | - $yes_no_values, |
|
| 882 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
| 883 | - '', |
|
| 884 | - '', |
|
| 885 | - false |
|
| 886 | - ); |
|
| 887 | - $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 888 | - 'EVT_default_registration_status', |
|
| 889 | - $default_reg_status_values, |
|
| 890 | - $this->_cpt_model_obj->default_registration_status() |
|
| 891 | - ); |
|
| 892 | - $template_args['additional_registration_options'] = apply_filters( |
|
| 893 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 894 | - '', |
|
| 895 | - $template_args, |
|
| 896 | - $yes_no_values, |
|
| 897 | - $default_reg_status_values |
|
| 898 | - ); |
|
| 899 | - EEH_Template::display_template( |
|
| 900 | - EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 901 | - $template_args |
|
| 902 | - ); |
|
| 903 | - } |
|
| 904 | - |
|
| 905 | - |
|
| 906 | - |
|
| 907 | - /** |
|
| 908 | - * wp_list_table_mods for caf |
|
| 909 | - * ============================ |
|
| 910 | - */ |
|
| 911 | - /** |
|
| 912 | - * hook into list table filters and provide filters for caffeinated list table |
|
| 913 | - * |
|
| 914 | - * @param array $old_filters any existing filters present |
|
| 915 | - * @param array $list_table_obj the list table object |
|
| 916 | - * |
|
| 917 | - * @return array new filters |
|
| 918 | - */ |
|
| 919 | - public function list_table_filters($old_filters, $list_table_obj) |
|
| 920 | - { |
|
| 921 | - $filters = array(); |
|
| 922 | - //first month/year filters |
|
| 923 | - $filters[] = $this->espresso_event_months_dropdown(); |
|
| 924 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 925 | - //active status dropdown |
|
| 926 | - if ($status !== 'draft') { |
|
| 927 | - $filters[] = $this->active_status_dropdown( |
|
| 928 | - isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : '' |
|
| 929 | - ); |
|
| 930 | - } |
|
| 931 | - //category filter |
|
| 932 | - $filters[] = $this->category_dropdown(); |
|
| 767 | + EE_Export::instance()->export_sample(); |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + |
|
| 771 | + /************* Template Settings *************/ |
|
| 772 | + protected function _template_settings() |
|
| 773 | + { |
|
| 774 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 775 | + /** |
|
| 776 | + * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
| 777 | + * from General_Settings_Admin_Page to here. |
|
| 778 | + */ |
|
| 779 | + $this->_template_args = apply_filters( |
|
| 780 | + 'FHEE__General_Settings_Admin_Page__template_settings__template_args', |
|
| 781 | + $this->_template_args |
|
| 782 | + ); |
|
| 783 | + $this->_set_add_edit_form_tags('update_template_settings'); |
|
| 784 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 785 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 786 | + EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
| 787 | + $this->_template_args, |
|
| 788 | + true |
|
| 789 | + ); |
|
| 790 | + $this->display_admin_page_with_sidebar(); |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + |
|
| 794 | + protected function _update_template_settings() |
|
| 795 | + { |
|
| 796 | + /** |
|
| 797 | + * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
| 798 | + * from General_Settings_Admin_Page to here. |
|
| 799 | + */ |
|
| 800 | + EE_Registry::instance()->CFG->template_settings = apply_filters( |
|
| 801 | + 'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
| 802 | + EE_Registry::instance()->CFG->template_settings, |
|
| 803 | + $this->_req_data |
|
| 804 | + ); |
|
| 805 | + //update custom post type slugs and detect if we need to flush rewrite rules |
|
| 806 | + $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
| 807 | + EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug']) |
|
| 808 | + ? EE_Registry::instance()->CFG->core->event_cpt_slug |
|
| 809 | + : sanitize_title_with_dashes($this->_req_data['event_cpt_slug']); |
|
| 810 | + $what = 'Template Settings'; |
|
| 811 | + $success = $this->_update_espresso_configuration( |
|
| 812 | + $what, |
|
| 813 | + EE_Registry::instance()->CFG->template_settings, |
|
| 814 | + __FILE__, |
|
| 815 | + __FUNCTION__, |
|
| 816 | + __LINE__ |
|
| 817 | + ); |
|
| 818 | + if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) { |
|
| 819 | + update_option('ee_flush_rewrite_rules', true); |
|
| 820 | + } |
|
| 821 | + $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings')); |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + |
|
| 825 | + /** |
|
| 826 | + * _premium_event_editor_meta_boxes |
|
| 827 | + * add all metaboxes related to the event_editor |
|
| 828 | + * |
|
| 829 | + * @access protected |
|
| 830 | + * @return void |
|
| 831 | + */ |
|
| 832 | + protected function _premium_event_editor_meta_boxes() |
|
| 833 | + { |
|
| 834 | + $this->verify_cpt_object(); |
|
| 835 | + add_meta_box( |
|
| 836 | + 'espresso_event_editor_event_options', |
|
| 837 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
| 838 | + array($this, 'registration_options_meta_box'), |
|
| 839 | + $this->page_slug, |
|
| 840 | + 'side', |
|
| 841 | + 'core' |
|
| 842 | + ); |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + |
|
| 846 | + /** |
|
| 847 | + * override caf metabox |
|
| 848 | + * |
|
| 849 | + * @return void |
|
| 850 | + */ |
|
| 851 | + public function registration_options_meta_box() |
|
| 852 | + { |
|
| 853 | + $yes_no_values = array( |
|
| 854 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 855 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 856 | + ); |
|
| 857 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 858 | + array( |
|
| 859 | + EEM_Registration::status_id_cancelled, |
|
| 860 | + EEM_Registration::status_id_declined, |
|
| 861 | + EEM_Registration::status_id_incomplete, |
|
| 862 | + EEM_Registration::status_id_wait_list, |
|
| 863 | + ), |
|
| 864 | + true |
|
| 865 | + ); |
|
| 866 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 867 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
| 868 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 869 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 870 | + 'default_reg_status', |
|
| 871 | + $default_reg_status_values, |
|
| 872 | + $this->_cpt_model_obj->default_registration_status() |
|
| 873 | + ); |
|
| 874 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 875 | + 'display_desc', |
|
| 876 | + $yes_no_values, |
|
| 877 | + $this->_cpt_model_obj->display_description() |
|
| 878 | + ); |
|
| 879 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 880 | + 'display_ticket_selector', |
|
| 881 | + $yes_no_values, |
|
| 882 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
| 883 | + '', |
|
| 884 | + '', |
|
| 885 | + false |
|
| 886 | + ); |
|
| 887 | + $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 888 | + 'EVT_default_registration_status', |
|
| 889 | + $default_reg_status_values, |
|
| 890 | + $this->_cpt_model_obj->default_registration_status() |
|
| 891 | + ); |
|
| 892 | + $template_args['additional_registration_options'] = apply_filters( |
|
| 893 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 894 | + '', |
|
| 895 | + $template_args, |
|
| 896 | + $yes_no_values, |
|
| 897 | + $default_reg_status_values |
|
| 898 | + ); |
|
| 899 | + EEH_Template::display_template( |
|
| 900 | + EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 901 | + $template_args |
|
| 902 | + ); |
|
| 903 | + } |
|
| 904 | + |
|
| 905 | + |
|
| 906 | + |
|
| 907 | + /** |
|
| 908 | + * wp_list_table_mods for caf |
|
| 909 | + * ============================ |
|
| 910 | + */ |
|
| 911 | + /** |
|
| 912 | + * hook into list table filters and provide filters for caffeinated list table |
|
| 913 | + * |
|
| 914 | + * @param array $old_filters any existing filters present |
|
| 915 | + * @param array $list_table_obj the list table object |
|
| 916 | + * |
|
| 917 | + * @return array new filters |
|
| 918 | + */ |
|
| 919 | + public function list_table_filters($old_filters, $list_table_obj) |
|
| 920 | + { |
|
| 921 | + $filters = array(); |
|
| 922 | + //first month/year filters |
|
| 923 | + $filters[] = $this->espresso_event_months_dropdown(); |
|
| 924 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 925 | + //active status dropdown |
|
| 926 | + if ($status !== 'draft') { |
|
| 927 | + $filters[] = $this->active_status_dropdown( |
|
| 928 | + isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : '' |
|
| 929 | + ); |
|
| 930 | + } |
|
| 931 | + //category filter |
|
| 932 | + $filters[] = $this->category_dropdown(); |
|
| 933 | 933 | |
| 934 | - return array_merge($old_filters, $filters); |
|
| 935 | - } |
|
| 936 | - |
|
| 937 | - |
|
| 938 | - /** |
|
| 939 | - * espresso_event_months_dropdown |
|
| 940 | - * |
|
| 941 | - * @access public |
|
| 942 | - * @return string dropdown listing month/year selections for events. |
|
| 943 | - */ |
|
| 944 | - public function espresso_event_months_dropdown() |
|
| 945 | - { |
|
| 946 | - // what we need to do is get all PRIMARY datetimes for all events to filter on. |
|
| 947 | - // Note we need to include any other filters that are set! |
|
| 948 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 949 | - //categories? |
|
| 950 | - $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 951 | - ? $this->_req_data['EVT_CAT'] |
|
| 952 | - : null; |
|
| 953 | - //active status? |
|
| 954 | - $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null; |
|
| 955 | - $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
| 934 | + return array_merge($old_filters, $filters); |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + |
|
| 938 | + /** |
|
| 939 | + * espresso_event_months_dropdown |
|
| 940 | + * |
|
| 941 | + * @access public |
|
| 942 | + * @return string dropdown listing month/year selections for events. |
|
| 943 | + */ |
|
| 944 | + public function espresso_event_months_dropdown() |
|
| 945 | + { |
|
| 946 | + // what we need to do is get all PRIMARY datetimes for all events to filter on. |
|
| 947 | + // Note we need to include any other filters that are set! |
|
| 948 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 949 | + //categories? |
|
| 950 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 951 | + ? $this->_req_data['EVT_CAT'] |
|
| 952 | + : null; |
|
| 953 | + //active status? |
|
| 954 | + $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null; |
|
| 955 | + $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
| 956 | 956 | |
| 957 | - return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status); |
|
| 958 | - } |
|
| 959 | - |
|
| 960 | - |
|
| 961 | - /** |
|
| 962 | - * returns a list of "active" statuses on the event |
|
| 963 | - * |
|
| 964 | - * @param string $current_value whatever the current active status is |
|
| 965 | - * |
|
| 966 | - * @return string |
|
| 967 | - */ |
|
| 968 | - public function active_status_dropdown($current_value = '') |
|
| 969 | - { |
|
| 970 | - $select_name = 'active_status'; |
|
| 971 | - $values = array( |
|
| 972 | - 'none' => esc_html__('Show Active/Inactive', 'event_espresso'), |
|
| 973 | - 'active' => esc_html__('Active', 'event_espresso'), |
|
| 974 | - 'upcoming' => esc_html__('Upcoming', 'event_espresso'), |
|
| 975 | - 'expired' => esc_html__('Expired', 'event_espresso'), |
|
| 976 | - 'inactive' => esc_html__('Inactive', 'event_espresso'), |
|
| 977 | - ); |
|
| 978 | - $id = 'id="espresso-active-status-dropdown-filter"'; |
|
| 979 | - $class = 'wide'; |
|
| 957 | + return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status); |
|
| 958 | + } |
|
| 959 | + |
|
| 960 | + |
|
| 961 | + /** |
|
| 962 | + * returns a list of "active" statuses on the event |
|
| 963 | + * |
|
| 964 | + * @param string $current_value whatever the current active status is |
|
| 965 | + * |
|
| 966 | + * @return string |
|
| 967 | + */ |
|
| 968 | + public function active_status_dropdown($current_value = '') |
|
| 969 | + { |
|
| 970 | + $select_name = 'active_status'; |
|
| 971 | + $values = array( |
|
| 972 | + 'none' => esc_html__('Show Active/Inactive', 'event_espresso'), |
|
| 973 | + 'active' => esc_html__('Active', 'event_espresso'), |
|
| 974 | + 'upcoming' => esc_html__('Upcoming', 'event_espresso'), |
|
| 975 | + 'expired' => esc_html__('Expired', 'event_espresso'), |
|
| 976 | + 'inactive' => esc_html__('Inactive', 'event_espresso'), |
|
| 977 | + ); |
|
| 978 | + $id = 'id="espresso-active-status-dropdown-filter"'; |
|
| 979 | + $class = 'wide'; |
|
| 980 | 980 | |
| 981 | - return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class); |
|
| 982 | - } |
|
| 983 | - |
|
| 984 | - |
|
| 985 | - /** |
|
| 986 | - * output a dropdown of the categories for the category filter on the event admin list table |
|
| 987 | - * |
|
| 988 | - * @access public |
|
| 989 | - * @return string html |
|
| 990 | - */ |
|
| 991 | - public function category_dropdown() |
|
| 992 | - { |
|
| 993 | - $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
| 981 | + return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class); |
|
| 982 | + } |
|
| 983 | + |
|
| 984 | + |
|
| 985 | + /** |
|
| 986 | + * output a dropdown of the categories for the category filter on the event admin list table |
|
| 987 | + * |
|
| 988 | + * @access public |
|
| 989 | + * @return string html |
|
| 990 | + */ |
|
| 991 | + public function category_dropdown() |
|
| 992 | + { |
|
| 993 | + $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
| 994 | 994 | |
| 995 | - return EEH_Form_Fields::generate_event_category_dropdown($cur_cat); |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - |
|
| 999 | - /** |
|
| 1000 | - * get total number of events today |
|
| 1001 | - * |
|
| 1002 | - * @access public |
|
| 1003 | - * @return int |
|
| 1004 | - */ |
|
| 1005 | - public function total_events_today() |
|
| 1006 | - { |
|
| 1007 | - $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1008 | - 'DTT_EVT_start', |
|
| 1009 | - date('Y-m-d') . ' 00:00:00', |
|
| 1010 | - 'Y-m-d H:i:s', |
|
| 1011 | - 'UTC' |
|
| 1012 | - ); |
|
| 1013 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1014 | - 'DTT_EVT_start', |
|
| 1015 | - date('Y-m-d') . ' 23:59:59', |
|
| 1016 | - 'Y-m-d H:i:s', |
|
| 1017 | - 'UTC' |
|
| 1018 | - ); |
|
| 1019 | - $where = array( |
|
| 1020 | - 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
| 1021 | - ); |
|
| 1022 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 995 | + return EEH_Form_Fields::generate_event_category_dropdown($cur_cat); |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + |
|
| 999 | + /** |
|
| 1000 | + * get total number of events today |
|
| 1001 | + * |
|
| 1002 | + * @access public |
|
| 1003 | + * @return int |
|
| 1004 | + */ |
|
| 1005 | + public function total_events_today() |
|
| 1006 | + { |
|
| 1007 | + $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1008 | + 'DTT_EVT_start', |
|
| 1009 | + date('Y-m-d') . ' 00:00:00', |
|
| 1010 | + 'Y-m-d H:i:s', |
|
| 1011 | + 'UTC' |
|
| 1012 | + ); |
|
| 1013 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1014 | + 'DTT_EVT_start', |
|
| 1015 | + date('Y-m-d') . ' 23:59:59', |
|
| 1016 | + 'Y-m-d H:i:s', |
|
| 1017 | + 'UTC' |
|
| 1018 | + ); |
|
| 1019 | + $where = array( |
|
| 1020 | + 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
| 1021 | + ); |
|
| 1022 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 1023 | 1023 | |
| 1024 | - return $count; |
|
| 1025 | - } |
|
| 1026 | - |
|
| 1027 | - |
|
| 1028 | - /** |
|
| 1029 | - * get total number of events this month |
|
| 1030 | - * |
|
| 1031 | - * @access public |
|
| 1032 | - * @return int |
|
| 1033 | - */ |
|
| 1034 | - public function total_events_this_month() |
|
| 1035 | - { |
|
| 1036 | - //Dates |
|
| 1037 | - $this_year_r = date('Y'); |
|
| 1038 | - $this_month_r = date('m'); |
|
| 1039 | - $days_this_month = date('t'); |
|
| 1040 | - $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1041 | - 'DTT_EVT_start', |
|
| 1042 | - $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
| 1043 | - 'Y-m-d H:i:s', |
|
| 1044 | - 'UTC' |
|
| 1045 | - ); |
|
| 1046 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1047 | - 'DTT_EVT_start', |
|
| 1048 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
| 1049 | - 'Y-m-d H:i:s', |
|
| 1050 | - 'UTC' |
|
| 1051 | - ); |
|
| 1052 | - $where = array( |
|
| 1053 | - 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
| 1054 | - ); |
|
| 1055 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 1024 | + return $count; |
|
| 1025 | + } |
|
| 1026 | + |
|
| 1027 | + |
|
| 1028 | + /** |
|
| 1029 | + * get total number of events this month |
|
| 1030 | + * |
|
| 1031 | + * @access public |
|
| 1032 | + * @return int |
|
| 1033 | + */ |
|
| 1034 | + public function total_events_this_month() |
|
| 1035 | + { |
|
| 1036 | + //Dates |
|
| 1037 | + $this_year_r = date('Y'); |
|
| 1038 | + $this_month_r = date('m'); |
|
| 1039 | + $days_this_month = date('t'); |
|
| 1040 | + $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1041 | + 'DTT_EVT_start', |
|
| 1042 | + $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
| 1043 | + 'Y-m-d H:i:s', |
|
| 1044 | + 'UTC' |
|
| 1045 | + ); |
|
| 1046 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1047 | + 'DTT_EVT_start', |
|
| 1048 | + $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
| 1049 | + 'Y-m-d H:i:s', |
|
| 1050 | + 'UTC' |
|
| 1051 | + ); |
|
| 1052 | + $where = array( |
|
| 1053 | + 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
| 1054 | + ); |
|
| 1055 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 1056 | 1056 | |
| 1057 | - return $count; |
|
| 1058 | - } |
|
| 1059 | - |
|
| 1060 | - |
|
| 1061 | - /** DEFAULT TICKETS STUFF **/ |
|
| 1062 | - public function _tickets_overview_list_table() |
|
| 1063 | - { |
|
| 1064 | - $this->_search_btn_label = esc_html__('Tickets', 'event_espresso'); |
|
| 1065 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1066 | - } |
|
| 1067 | - |
|
| 1068 | - |
|
| 1069 | - /** |
|
| 1070 | - * @param int $per_page |
|
| 1071 | - * @param bool $count |
|
| 1072 | - * @param bool $trashed |
|
| 1073 | - * |
|
| 1074 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
| 1075 | - */ |
|
| 1076 | - public function get_default_tickets($per_page = 10, $count = false, $trashed = false) |
|
| 1077 | - { |
|
| 1078 | - $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby']; |
|
| 1079 | - $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order']; |
|
| 1080 | - switch ($orderby) { |
|
| 1081 | - case 'TKT_name' : |
|
| 1082 | - $orderby = array('TKT_name' => $order); |
|
| 1083 | - break; |
|
| 1084 | - case 'TKT_price' : |
|
| 1085 | - $orderby = array('TKT_price' => $order); |
|
| 1086 | - break; |
|
| 1087 | - case 'TKT_uses' : |
|
| 1088 | - $orderby = array('TKT_uses' => $order); |
|
| 1089 | - break; |
|
| 1090 | - case 'TKT_min' : |
|
| 1091 | - $orderby = array('TKT_min' => $order); |
|
| 1092 | - break; |
|
| 1093 | - case 'TKT_max' : |
|
| 1094 | - $orderby = array('TKT_max' => $order); |
|
| 1095 | - break; |
|
| 1096 | - case 'TKT_qty' : |
|
| 1097 | - $orderby = array('TKT_qty' => $order); |
|
| 1098 | - break; |
|
| 1099 | - } |
|
| 1100 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1101 | - ? $this->_req_data['paged'] |
|
| 1102 | - : 1; |
|
| 1103 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1104 | - ? $this->_req_data['perpage'] |
|
| 1105 | - : $per_page; |
|
| 1106 | - $_where = array( |
|
| 1107 | - 'TKT_is_default' => 1, |
|
| 1108 | - 'TKT_deleted' => $trashed, |
|
| 1109 | - ); |
|
| 1110 | - $offset = ($current_page - 1) * $per_page; |
|
| 1111 | - $limit = array($offset, $per_page); |
|
| 1112 | - if (isset($this->_req_data['s'])) { |
|
| 1113 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 1114 | - $_where['OR'] = array( |
|
| 1115 | - 'TKT_name' => array('LIKE', $sstr), |
|
| 1116 | - 'TKT_description' => array('LIKE', $sstr), |
|
| 1117 | - ); |
|
| 1118 | - } |
|
| 1119 | - $query_params = array( |
|
| 1120 | - $_where, |
|
| 1121 | - 'order_by' => $orderby, |
|
| 1122 | - 'limit' => $limit, |
|
| 1123 | - 'group_by' => 'TKT_ID', |
|
| 1124 | - ); |
|
| 1125 | - if ($count) { |
|
| 1126 | - return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where)); |
|
| 1127 | - } else { |
|
| 1128 | - return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params); |
|
| 1129 | - } |
|
| 1130 | - } |
|
| 1131 | - |
|
| 1132 | - |
|
| 1133 | - /** |
|
| 1134 | - * @param bool $trash |
|
| 1135 | - */ |
|
| 1136 | - protected function _trash_or_restore_ticket($trash = false) |
|
| 1137 | - { |
|
| 1138 | - $success = 1; |
|
| 1139 | - $TKT = EEM_Ticket::instance(); |
|
| 1140 | - //checkboxes? |
|
| 1141 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1142 | - //if array has more than one element then success message should be plural |
|
| 1143 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1144 | - //cycle thru the boxes |
|
| 1145 | - while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1146 | - if ($trash) { |
|
| 1147 | - if ( ! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1148 | - $success = 0; |
|
| 1149 | - } |
|
| 1150 | - } else { |
|
| 1151 | - if ( ! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1152 | - $success = 0; |
|
| 1153 | - } |
|
| 1154 | - } |
|
| 1155 | - } |
|
| 1156 | - } else { |
|
| 1157 | - //grab single id and trash |
|
| 1158 | - $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
| 1159 | - if ($trash) { |
|
| 1160 | - if ( ! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1161 | - $success = 0; |
|
| 1162 | - } |
|
| 1163 | - } else { |
|
| 1164 | - if ( ! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1165 | - $success = 0; |
|
| 1166 | - } |
|
| 1167 | - } |
|
| 1168 | - } |
|
| 1169 | - $action_desc = $trash ? 'moved to the trash' : 'restored'; |
|
| 1170 | - $query_args = array( |
|
| 1171 | - 'action' => 'ticket_list_table', |
|
| 1172 | - 'status' => $trash ? '' : 'trashed', |
|
| 1173 | - ); |
|
| 1174 | - $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
| 1175 | - } |
|
| 1176 | - |
|
| 1177 | - |
|
| 1178 | - protected function _delete_ticket() |
|
| 1179 | - { |
|
| 1180 | - $success = 1; |
|
| 1181 | - //checkboxes? |
|
| 1182 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1183 | - //if array has more than one element then success message should be plural |
|
| 1184 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1185 | - //cycle thru the boxes |
|
| 1186 | - while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1187 | - //delete |
|
| 1188 | - if ( ! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1189 | - $success = 0; |
|
| 1190 | - } |
|
| 1191 | - } |
|
| 1192 | - } else { |
|
| 1193 | - //grab single id and trash |
|
| 1194 | - $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
| 1195 | - if ( ! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1196 | - $success = 0; |
|
| 1197 | - } |
|
| 1198 | - } |
|
| 1199 | - $action_desc = 'deleted'; |
|
| 1200 | - $query_args = array( |
|
| 1201 | - 'action' => 'ticket_list_table', |
|
| 1202 | - 'status' => 'trashed', |
|
| 1203 | - ); |
|
| 1204 | - //fail safe. If the default ticket count === 1 then we need to redirect to event overview. |
|
| 1205 | - if (EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
| 1206 | - array(array('TKT_is_default' => 1)), |
|
| 1207 | - 'TKT_ID', |
|
| 1208 | - true |
|
| 1209 | - ) |
|
| 1210 | - ) { |
|
| 1211 | - $query_args = array(); |
|
| 1212 | - } |
|
| 1213 | - $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - |
|
| 1217 | - /** |
|
| 1218 | - * @param int $TKT_ID |
|
| 1219 | - * |
|
| 1220 | - * @return bool|int |
|
| 1221 | - */ |
|
| 1222 | - protected function _delete_the_ticket($TKT_ID) |
|
| 1223 | - { |
|
| 1224 | - $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
|
| 1225 | - $tkt->_remove_relations('Datetime'); |
|
| 1226 | - //delete all related prices first |
|
| 1227 | - $tkt->delete_related_permanently('Price'); |
|
| 1057 | + return $count; |
|
| 1058 | + } |
|
| 1059 | + |
|
| 1060 | + |
|
| 1061 | + /** DEFAULT TICKETS STUFF **/ |
|
| 1062 | + public function _tickets_overview_list_table() |
|
| 1063 | + { |
|
| 1064 | + $this->_search_btn_label = esc_html__('Tickets', 'event_espresso'); |
|
| 1065 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1066 | + } |
|
| 1067 | + |
|
| 1068 | + |
|
| 1069 | + /** |
|
| 1070 | + * @param int $per_page |
|
| 1071 | + * @param bool $count |
|
| 1072 | + * @param bool $trashed |
|
| 1073 | + * |
|
| 1074 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
| 1075 | + */ |
|
| 1076 | + public function get_default_tickets($per_page = 10, $count = false, $trashed = false) |
|
| 1077 | + { |
|
| 1078 | + $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby']; |
|
| 1079 | + $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order']; |
|
| 1080 | + switch ($orderby) { |
|
| 1081 | + case 'TKT_name' : |
|
| 1082 | + $orderby = array('TKT_name' => $order); |
|
| 1083 | + break; |
|
| 1084 | + case 'TKT_price' : |
|
| 1085 | + $orderby = array('TKT_price' => $order); |
|
| 1086 | + break; |
|
| 1087 | + case 'TKT_uses' : |
|
| 1088 | + $orderby = array('TKT_uses' => $order); |
|
| 1089 | + break; |
|
| 1090 | + case 'TKT_min' : |
|
| 1091 | + $orderby = array('TKT_min' => $order); |
|
| 1092 | + break; |
|
| 1093 | + case 'TKT_max' : |
|
| 1094 | + $orderby = array('TKT_max' => $order); |
|
| 1095 | + break; |
|
| 1096 | + case 'TKT_qty' : |
|
| 1097 | + $orderby = array('TKT_qty' => $order); |
|
| 1098 | + break; |
|
| 1099 | + } |
|
| 1100 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1101 | + ? $this->_req_data['paged'] |
|
| 1102 | + : 1; |
|
| 1103 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1104 | + ? $this->_req_data['perpage'] |
|
| 1105 | + : $per_page; |
|
| 1106 | + $_where = array( |
|
| 1107 | + 'TKT_is_default' => 1, |
|
| 1108 | + 'TKT_deleted' => $trashed, |
|
| 1109 | + ); |
|
| 1110 | + $offset = ($current_page - 1) * $per_page; |
|
| 1111 | + $limit = array($offset, $per_page); |
|
| 1112 | + if (isset($this->_req_data['s'])) { |
|
| 1113 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 1114 | + $_where['OR'] = array( |
|
| 1115 | + 'TKT_name' => array('LIKE', $sstr), |
|
| 1116 | + 'TKT_description' => array('LIKE', $sstr), |
|
| 1117 | + ); |
|
| 1118 | + } |
|
| 1119 | + $query_params = array( |
|
| 1120 | + $_where, |
|
| 1121 | + 'order_by' => $orderby, |
|
| 1122 | + 'limit' => $limit, |
|
| 1123 | + 'group_by' => 'TKT_ID', |
|
| 1124 | + ); |
|
| 1125 | + if ($count) { |
|
| 1126 | + return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where)); |
|
| 1127 | + } else { |
|
| 1128 | + return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params); |
|
| 1129 | + } |
|
| 1130 | + } |
|
| 1131 | + |
|
| 1132 | + |
|
| 1133 | + /** |
|
| 1134 | + * @param bool $trash |
|
| 1135 | + */ |
|
| 1136 | + protected function _trash_or_restore_ticket($trash = false) |
|
| 1137 | + { |
|
| 1138 | + $success = 1; |
|
| 1139 | + $TKT = EEM_Ticket::instance(); |
|
| 1140 | + //checkboxes? |
|
| 1141 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1142 | + //if array has more than one element then success message should be plural |
|
| 1143 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1144 | + //cycle thru the boxes |
|
| 1145 | + while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1146 | + if ($trash) { |
|
| 1147 | + if ( ! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1148 | + $success = 0; |
|
| 1149 | + } |
|
| 1150 | + } else { |
|
| 1151 | + if ( ! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1152 | + $success = 0; |
|
| 1153 | + } |
|
| 1154 | + } |
|
| 1155 | + } |
|
| 1156 | + } else { |
|
| 1157 | + //grab single id and trash |
|
| 1158 | + $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
| 1159 | + if ($trash) { |
|
| 1160 | + if ( ! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1161 | + $success = 0; |
|
| 1162 | + } |
|
| 1163 | + } else { |
|
| 1164 | + if ( ! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1165 | + $success = 0; |
|
| 1166 | + } |
|
| 1167 | + } |
|
| 1168 | + } |
|
| 1169 | + $action_desc = $trash ? 'moved to the trash' : 'restored'; |
|
| 1170 | + $query_args = array( |
|
| 1171 | + 'action' => 'ticket_list_table', |
|
| 1172 | + 'status' => $trash ? '' : 'trashed', |
|
| 1173 | + ); |
|
| 1174 | + $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
| 1175 | + } |
|
| 1176 | + |
|
| 1177 | + |
|
| 1178 | + protected function _delete_ticket() |
|
| 1179 | + { |
|
| 1180 | + $success = 1; |
|
| 1181 | + //checkboxes? |
|
| 1182 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1183 | + //if array has more than one element then success message should be plural |
|
| 1184 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1185 | + //cycle thru the boxes |
|
| 1186 | + while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1187 | + //delete |
|
| 1188 | + if ( ! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1189 | + $success = 0; |
|
| 1190 | + } |
|
| 1191 | + } |
|
| 1192 | + } else { |
|
| 1193 | + //grab single id and trash |
|
| 1194 | + $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
| 1195 | + if ( ! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1196 | + $success = 0; |
|
| 1197 | + } |
|
| 1198 | + } |
|
| 1199 | + $action_desc = 'deleted'; |
|
| 1200 | + $query_args = array( |
|
| 1201 | + 'action' => 'ticket_list_table', |
|
| 1202 | + 'status' => 'trashed', |
|
| 1203 | + ); |
|
| 1204 | + //fail safe. If the default ticket count === 1 then we need to redirect to event overview. |
|
| 1205 | + if (EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
| 1206 | + array(array('TKT_is_default' => 1)), |
|
| 1207 | + 'TKT_ID', |
|
| 1208 | + true |
|
| 1209 | + ) |
|
| 1210 | + ) { |
|
| 1211 | + $query_args = array(); |
|
| 1212 | + } |
|
| 1213 | + $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + |
|
| 1217 | + /** |
|
| 1218 | + * @param int $TKT_ID |
|
| 1219 | + * |
|
| 1220 | + * @return bool|int |
|
| 1221 | + */ |
|
| 1222 | + protected function _delete_the_ticket($TKT_ID) |
|
| 1223 | + { |
|
| 1224 | + $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
|
| 1225 | + $tkt->_remove_relations('Datetime'); |
|
| 1226 | + //delete all related prices first |
|
| 1227 | + $tkt->delete_related_permanently('Price'); |
|
| 1228 | 1228 | |
| 1229 | - return $tkt->delete_permanently(); |
|
| 1230 | - } |
|
| 1229 | + return $tkt->delete_permanently(); |
|
| 1230 | + } |
|
| 1231 | 1231 | |
| 1232 | 1232 | |
| 1233 | 1233 | } |
@@ -25,16 +25,16 @@ discard block |
||
| 25 | 25 | { |
| 26 | 26 | parent::__construct($routing); |
| 27 | 27 | if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
| 28 | - define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
| 29 | - define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
| 30 | - define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
| 28 | + define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'events/templates/'); |
|
| 29 | + define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'events/assets/'); |
|
| 30 | + define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'events/assets/'); |
|
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | |
| 35 | 35 | protected function _extend_page_config() |
| 36 | 36 | { |
| 37 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
| 37 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'events'; |
|
| 38 | 38 | //is there a evt_id in the request? |
| 39 | 39 | $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
| 40 | 40 | ? $this->_req_data['EVT_ID'] |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | 'help_tour' => array('Templates_Help_Tour'), |
| 168 | 168 | 'require_nonce' => false, |
| 169 | 169 | ); |
| 170 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 170 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 171 | 171 | //add filters and actions |
| 172 | 172 | //modifying _views |
| 173 | 173 | add_filter( |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
| 271 | 271 | //make sure this is only when editing |
| 272 | 272 | if ( ! empty($id)) { |
| 273 | - $href = EE_Admin_Page::add_query_args_and_nonce( |
|
| 273 | + $href = EE_Admin_Page::add_query_args_and_nonce( |
|
| 274 | 274 | array('action' => 'duplicate_event', 'EVT_ID' => $id), |
| 275 | 275 | $this->_admin_base_url |
| 276 | 276 | ); |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | { |
| 317 | 317 | wp_register_script( |
| 318 | 318 | 'ee-event-editor-heartbeat', |
| 319 | - EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
| 319 | + EVENTS_CAF_ASSETS_URL.'event-editor-heartbeat.js', |
|
| 320 | 320 | array('ee_admin_js', 'heartbeat'), |
| 321 | 321 | EVENT_ESPRESSO_VERSION, |
| 322 | 322 | true |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | public function add_additional_datetime_button($template, $template_args) |
| 342 | 342 | { |
| 343 | 343 | return EEH_Template::display_template( |
| 344 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
| 344 | + EVENTS_CAF_TEMPLATE_PATH.'event_datetime_add_additional_time.template.php', |
|
| 345 | 345 | $template_args, |
| 346 | 346 | true |
| 347 | 347 | ); |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | public function add_datetime_clone_button($template, $template_args) |
| 358 | 358 | { |
| 359 | 359 | return EEH_Template::display_template( |
| 360 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
| 360 | + EVENTS_CAF_TEMPLATE_PATH.'event_datetime_metabox_clone_button.template.php', |
|
| 361 | 361 | $template_args, |
| 362 | 362 | true |
| 363 | 363 | ); |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | public function datetime_timezones_template($template, $template_args) |
| 374 | 374 | { |
| 375 | 375 | return EEH_Template::display_template( |
| 376 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
| 376 | + EVENTS_CAF_TEMPLATE_PATH.'event_datetime_timezones.template.php', |
|
| 377 | 377 | $template_args, |
| 378 | 378 | true |
| 379 | 379 | ); |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | protected function _set_list_table_views_default() |
| 384 | 384 | { |
| 385 | 385 | parent::_set_list_table_views_default(); |
| 386 | - $new_views = array( |
|
| 386 | + $new_views = array( |
|
| 387 | 387 | 'today' => array( |
| 388 | 388 | 'slug' => 'today', |
| 389 | 389 | 'label' => esc_html__('Today', 'event_espresso'), |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | $orig_ven = $orig_event->get_many_related('Venue'); |
| 525 | 525 | //reset the ID and modify other details to make it clear this is a dupe |
| 526 | 526 | $new_event->set('EVT_ID', 0); |
| 527 | - $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
| 527 | + $new_name = $new_event->name().' '.esc_html__('**DUPLICATE**', 'event_espresso'); |
|
| 528 | 528 | $new_event->set('EVT_name', $new_name); |
| 529 | 529 | $new_event->set( |
| 530 | 530 | 'EVT_slug', |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | $new_event->_add_relation_to($new_dtt, 'Datetime'); |
| 590 | 590 | $new_event->save(); |
| 591 | 591 | //now let's get the ticket relations setup. |
| 592 | - foreach ((array)$orig_tkts as $orig_tkt) { |
|
| 592 | + foreach ((array) $orig_tkts as $orig_tkt) { |
|
| 593 | 593 | //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
| 594 | 594 | if ( ! $orig_tkt instanceof EE_Ticket) { |
| 595 | 595 | continue; |
@@ -681,8 +681,8 @@ discard block |
||
| 681 | 681 | array('action' => 'sample_export_file'), |
| 682 | 682 | $this->_admin_base_url |
| 683 | 683 | ); |
| 684 | - $content = EEH_Template::display_template( |
|
| 685 | - EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
| 684 | + $content = EEH_Template::display_template( |
|
| 685 | + EVENTS_CAF_TEMPLATE_PATH.'import_page.template.php', |
|
| 686 | 686 | $this->_template_args, |
| 687 | 687 | true |
| 688 | 688 | ); |
@@ -699,7 +699,7 @@ discard block |
||
| 699 | 699 | */ |
| 700 | 700 | protected function _import_events() |
| 701 | 701 | { |
| 702 | - require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
| 702 | + require_once(EE_CLASSES.'EE_Import.class.php'); |
|
| 703 | 703 | $success = EE_Import::instance()->import(); |
| 704 | 704 | $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true); |
| 705 | 705 | } |
@@ -727,9 +727,9 @@ discard block |
||
| 727 | 727 | 'action' => 'all_event_data', |
| 728 | 728 | 'EVT_ID' => $event_ids, |
| 729 | 729 | ); |
| 730 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 731 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 732 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 730 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 731 | + if (is_readable(EE_CLASSES.'EE_Export.class.php')) { |
|
| 732 | + require_once(EE_CLASSES.'EE_Export.class.php'); |
|
| 733 | 733 | $EE_Export = EE_Export::instance($this->_req_data); |
| 734 | 734 | $EE_Export->export(); |
| 735 | 735 | } |
@@ -749,9 +749,9 @@ discard block |
||
| 749 | 749 | 'action' => 'categories', |
| 750 | 750 | 'category_ids' => $this->_req_data['EVT_CAT_ID'], |
| 751 | 751 | ); |
| 752 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 753 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 754 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 752 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 753 | + if (is_readable(EE_CLASSES.'EE_Export.class.php')) { |
|
| 754 | + require_once(EE_CLASSES.'EE_Export.class.php'); |
|
| 755 | 755 | $EE_Export = EE_Export::instance($this->_req_data); |
| 756 | 756 | $EE_Export->export(); |
| 757 | 757 | } |
@@ -783,7 +783,7 @@ discard block |
||
| 783 | 783 | $this->_set_add_edit_form_tags('update_template_settings'); |
| 784 | 784 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
| 785 | 785 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 786 | - EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
| 786 | + EVENTS_CAF_TEMPLATE_PATH.'template_settings.template.php', |
|
| 787 | 787 | $this->_template_args, |
| 788 | 788 | true |
| 789 | 789 | ); |
@@ -850,11 +850,11 @@ discard block |
||
| 850 | 850 | */ |
| 851 | 851 | public function registration_options_meta_box() |
| 852 | 852 | { |
| 853 | - $yes_no_values = array( |
|
| 853 | + $yes_no_values = array( |
|
| 854 | 854 | array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
| 855 | 855 | array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
| 856 | 856 | ); |
| 857 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 857 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 858 | 858 | array( |
| 859 | 859 | EEM_Registration::status_id_cancelled, |
| 860 | 860 | EEM_Registration::status_id_declined, |
@@ -871,12 +871,12 @@ discard block |
||
| 871 | 871 | $default_reg_status_values, |
| 872 | 872 | $this->_cpt_model_obj->default_registration_status() |
| 873 | 873 | ); |
| 874 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 874 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 875 | 875 | 'display_desc', |
| 876 | 876 | $yes_no_values, |
| 877 | 877 | $this->_cpt_model_obj->display_description() |
| 878 | 878 | ); |
| 879 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 879 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 880 | 880 | 'display_ticket_selector', |
| 881 | 881 | $yes_no_values, |
| 882 | 882 | $this->_cpt_model_obj->display_ticket_selector(), |
@@ -897,7 +897,7 @@ discard block |
||
| 897 | 897 | $default_reg_status_values |
| 898 | 898 | ); |
| 899 | 899 | EEH_Template::display_template( |
| 900 | - EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 900 | + EVENTS_CAF_TEMPLATE_PATH.'event_registration_options.template.php', |
|
| 901 | 901 | $template_args |
| 902 | 902 | ); |
| 903 | 903 | } |
@@ -1006,13 +1006,13 @@ discard block |
||
| 1006 | 1006 | { |
| 1007 | 1007 | $start = EEM_Datetime::instance()->convert_datetime_for_query( |
| 1008 | 1008 | 'DTT_EVT_start', |
| 1009 | - date('Y-m-d') . ' 00:00:00', |
|
| 1009 | + date('Y-m-d').' 00:00:00', |
|
| 1010 | 1010 | 'Y-m-d H:i:s', |
| 1011 | 1011 | 'UTC' |
| 1012 | 1012 | ); |
| 1013 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1013 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1014 | 1014 | 'DTT_EVT_start', |
| 1015 | - date('Y-m-d') . ' 23:59:59', |
|
| 1015 | + date('Y-m-d').' 23:59:59', |
|
| 1016 | 1016 | 'Y-m-d H:i:s', |
| 1017 | 1017 | 'UTC' |
| 1018 | 1018 | ); |
@@ -1039,13 +1039,13 @@ discard block |
||
| 1039 | 1039 | $days_this_month = date('t'); |
| 1040 | 1040 | $start = EEM_Datetime::instance()->convert_datetime_for_query( |
| 1041 | 1041 | 'DTT_EVT_start', |
| 1042 | - $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
| 1042 | + $this_year_r.'-'.$this_month_r.'-01 00:00:00', |
|
| 1043 | 1043 | 'Y-m-d H:i:s', |
| 1044 | 1044 | 'UTC' |
| 1045 | 1045 | ); |
| 1046 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1046 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1047 | 1047 | 'DTT_EVT_start', |
| 1048 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
| 1048 | + $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' 23:59:59', |
|
| 1049 | 1049 | 'Y-m-d H:i:s', |
| 1050 | 1050 | 'UTC' |
| 1051 | 1051 | ); |
@@ -1110,7 +1110,7 @@ discard block |
||
| 1110 | 1110 | $offset = ($current_page - 1) * $per_page; |
| 1111 | 1111 | $limit = array($offset, $per_page); |
| 1112 | 1112 | if (isset($this->_req_data['s'])) { |
| 1113 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 1113 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
| 1114 | 1114 | $_where['OR'] = array( |
| 1115 | 1115 | 'TKT_name' => array('LIKE', $sstr), |
| 1116 | 1116 | 'TKT_description' => array('LIKE', $sstr), |
@@ -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,5 +1,5 @@ discard block |
||
| 1 | -<?php if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | - exit( 'No direct script access allowed' ); |
|
| 1 | +<?php if ( ! defined('ABSPATH')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /* |
| 5 | 5 | Plugin Name: Event Espresso |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @link {@link http://www.eventespresso.com} |
| 40 | 40 | * @since 4.0 |
| 41 | 41 | */ |
| 42 | -if ( function_exists( 'espresso_version' ) ) { |
|
| 42 | +if (function_exists('espresso_version')) { |
|
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * espresso_duplicate_plugin_error |
@@ -56,15 +56,15 @@ discard block |
||
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin( plugin_basename( __FILE__ ) ); |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | 60 | } |
| 61 | - add_action( 'admin_notices', 'espresso_duplicate_plugin_error', 1 ); |
|
| 61 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 62 | 62 | |
| 63 | 63 | } else { |
| 64 | 64 | |
| 65 | - define( 'EE_MIN_PHP_VER_REQUIRED', '5.3.0' ); |
|
| 65 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.0'); |
|
| 66 | 66 | |
| 67 | - if ( ! version_compare( PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=' ) ) { |
|
| 67 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * espresso_minimum_php_version_error |
@@ -90,9 +90,9 @@ discard block |
||
| 90 | 90 | </p> |
| 91 | 91 | </div> |
| 92 | 92 | <?php |
| 93 | - espresso_deactivate_plugin( plugin_basename( __FILE__ ) ); |
|
| 93 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 94 | 94 | } |
| 95 | - add_action( 'admin_notices', 'espresso_minimum_php_version_error', 1 ); |
|
| 95 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 96 | 96 | |
| 97 | 97 | } else { |
| 98 | 98 | |
@@ -103,99 +103,99 @@ discard block |
||
| 103 | 103 | * @return string |
| 104 | 104 | */ |
| 105 | 105 | function espresso_version() { |
| 106 | - return apply_filters( 'FHEE__espresso__espresso_version', '4.9.22.rc.007' ); |
|
| 106 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.22.rc.007'); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | // define versions |
| 110 | - define( 'EVENT_ESPRESSO_VERSION', espresso_version() ); |
|
| 111 | - define( 'EE_MIN_WP_VER_REQUIRED', '4.1' ); |
|
| 112 | - define( 'EE_MIN_WP_VER_RECOMMENDED', '4.4.2' ); |
|
| 113 | - define( 'EE_MIN_PHP_VER_RECOMMENDED', '5.4.44' ); |
|
| 114 | - define( 'EVENT_ESPRESSO_MAIN_FILE', __FILE__ ); |
|
| 110 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
| 111 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
| 112 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
| 113 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
| 114 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 115 | 115 | |
| 116 | 116 | //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
| 117 | - if ( ! defined( 'DS' ) ) { |
|
| 118 | - define( 'DS', '/' ); |
|
| 117 | + if ( ! defined('DS')) { |
|
| 118 | + define('DS', '/'); |
|
| 119 | 119 | } |
| 120 | - if ( ! defined( 'PS' ) ) { |
|
| 121 | - define( 'PS', PATH_SEPARATOR ); |
|
| 120 | + if ( ! defined('PS')) { |
|
| 121 | + define('PS', PATH_SEPARATOR); |
|
| 122 | 122 | } |
| 123 | - if ( ! defined( 'SP' ) ) { |
|
| 124 | - define( 'SP', ' ' ); |
|
| 123 | + if ( ! defined('SP')) { |
|
| 124 | + define('SP', ' '); |
|
| 125 | 125 | } |
| 126 | - if ( ! defined( 'EENL' ) ) { |
|
| 127 | - define( 'EENL', "\n" ); |
|
| 126 | + if ( ! defined('EENL')) { |
|
| 127 | + define('EENL', "\n"); |
|
| 128 | 128 | } |
| 129 | - define( 'EE_SUPPORT_EMAIL', '[email protected]' ); |
|
| 129 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
| 130 | 130 | // define the plugin directory and URL |
| 131 | - define( 'EE_PLUGIN_BASENAME', plugin_basename( EVENT_ESPRESSO_MAIN_FILE ) ); |
|
| 132 | - define( 'EE_PLUGIN_DIR_PATH', plugin_dir_path( EVENT_ESPRESSO_MAIN_FILE ) ); |
|
| 133 | - define( 'EE_PLUGIN_DIR_URL', plugin_dir_url( EVENT_ESPRESSO_MAIN_FILE ) ); |
|
| 131 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 132 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 133 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 134 | 134 | // main root folder paths |
| 135 | - define( 'EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS ); |
|
| 136 | - define( 'EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS ); |
|
| 137 | - define( 'EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS ); |
|
| 138 | - define( 'EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS ); |
|
| 139 | - define( 'EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS ); |
|
| 140 | - define( 'EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS ); |
|
| 141 | - define( 'EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS ); |
|
| 142 | - define( 'EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS ); |
|
| 135 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH.'admin_pages'.DS); |
|
| 136 | + define('EE_CORE', EE_PLUGIN_DIR_PATH.'core'.DS); |
|
| 137 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH.'modules'.DS); |
|
| 138 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH.'public'.DS); |
|
| 139 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH.'shortcodes'.DS); |
|
| 140 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH.'widgets'.DS); |
|
| 141 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH.'payment_methods'.DS); |
|
| 142 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH.'caffeinated'.DS); |
|
| 143 | 143 | // core system paths |
| 144 | - define( 'EE_ADMIN', EE_CORE . 'admin' . DS ); |
|
| 145 | - define( 'EE_CPTS', EE_CORE . 'CPTs' . DS ); |
|
| 146 | - define( 'EE_CLASSES', EE_CORE . 'db_classes' . DS ); |
|
| 147 | - define( 'EE_INTERFACES', EE_CORE . 'interfaces' . DS ); |
|
| 148 | - define( 'EE_BUSINESS', EE_CORE . 'business' . DS ); |
|
| 149 | - define( 'EE_MODELS', EE_CORE . 'db_models' . DS ); |
|
| 150 | - define( 'EE_HELPERS', EE_CORE . 'helpers' . DS ); |
|
| 151 | - define( 'EE_LIBRARIES', EE_CORE . 'libraries' . DS ); |
|
| 152 | - define( 'EE_TEMPLATES', EE_CORE . 'templates' . DS ); |
|
| 153 | - define( 'EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS ); |
|
| 154 | - define( 'EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS ); |
|
| 155 | - define( 'EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS ); |
|
| 144 | + define('EE_ADMIN', EE_CORE.'admin'.DS); |
|
| 145 | + define('EE_CPTS', EE_CORE.'CPTs'.DS); |
|
| 146 | + define('EE_CLASSES', EE_CORE.'db_classes'.DS); |
|
| 147 | + define('EE_INTERFACES', EE_CORE.'interfaces'.DS); |
|
| 148 | + define('EE_BUSINESS', EE_CORE.'business'.DS); |
|
| 149 | + define('EE_MODELS', EE_CORE.'db_models'.DS); |
|
| 150 | + define('EE_HELPERS', EE_CORE.'helpers'.DS); |
|
| 151 | + define('EE_LIBRARIES', EE_CORE.'libraries'.DS); |
|
| 152 | + define('EE_TEMPLATES', EE_CORE.'templates'.DS); |
|
| 153 | + define('EE_THIRD_PARTY', EE_CORE.'third_party_libs'.DS); |
|
| 154 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES.'global_assets'.DS); |
|
| 155 | + define('EE_FORM_SECTIONS', EE_LIBRARIES.'form_sections'.DS); |
|
| 156 | 156 | // gateways |
| 157 | - define( 'EE_GATEWAYS', EE_MODULES . 'gateways' . DS ); |
|
| 158 | - define( 'EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS ); |
|
| 157 | + define('EE_GATEWAYS', EE_MODULES.'gateways'.DS); |
|
| 158 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL.'modules'.DS.'gateways'.DS); |
|
| 159 | 159 | // asset URL paths |
| 160 | - define( 'EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS ); |
|
| 161 | - define( 'EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS ); |
|
| 162 | - define( 'EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS ); |
|
| 163 | - define( 'EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS ); |
|
| 164 | - define( 'EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/' ); |
|
| 165 | - define( 'EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/' ); |
|
| 160 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL.'core'.DS.'templates'.DS); |
|
| 161 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL.'global_assets'.DS); |
|
| 162 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL.'images'.DS); |
|
| 163 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL.'core'.DS.'third_party_libs'.DS); |
|
| 164 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL.'core/helpers/assets/'); |
|
| 165 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL.'core/libraries/'); |
|
| 166 | 166 | // define upload paths |
| 167 | 167 | $uploads = wp_upload_dir(); |
| 168 | 168 | // define the uploads directory and URL |
| 169 | - define( 'EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS ); |
|
| 170 | - define( 'EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS ); |
|
| 169 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'].DS.'espresso'.DS); |
|
| 170 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'].DS.'espresso'.DS); |
|
| 171 | 171 | // define the templates directory and URL |
| 172 | - define( 'EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS ); |
|
| 173 | - define( 'EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS ); |
|
| 172 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'].DS.'espresso'.DS.'templates'.DS); |
|
| 173 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'].DS.'espresso'.DS.'templates'.DS); |
|
| 174 | 174 | // define the gateway directory and URL |
| 175 | - define( 'EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS ); |
|
| 176 | - define( 'EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS ); |
|
| 175 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'].DS.'espresso'.DS.'gateways'.DS); |
|
| 176 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'].DS.'espresso'.DS.'gateways'.DS); |
|
| 177 | 177 | // languages folder/path |
| 178 | - define( 'EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS ); |
|
| 179 | - define( 'EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS ); |
|
| 178 | + define('EE_LANGUAGES_SAFE_LOC', '..'.DS.'uploads'.DS.'espresso'.DS.'languages'.DS); |
|
| 179 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'languages'.DS); |
|
| 180 | 180 | //check for dompdf fonts in uploads |
| 181 | - if ( file_exists( EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS ) ) { |
|
| 182 | - define( 'DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS ); |
|
| 181 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR.'fonts'.DS)) { |
|
| 182 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'fonts'.DS); |
|
| 183 | 183 | } |
| 184 | 184 | //ajax constants |
| 185 | 185 | define( |
| 186 | 186 | 'EE_FRONT_AJAX', |
| 187 | - isset( $_REQUEST['ee_front_ajax'] ) || isset( $_REQUEST['data']['ee_front_ajax'] ) ? true : false |
|
| 187 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
| 188 | 188 | ); |
| 189 | 189 | define( |
| 190 | 190 | 'EE_ADMIN_AJAX', |
| 191 | - isset( $_REQUEST['ee_admin_ajax'] ) || isset( $_REQUEST['data']['ee_admin_ajax'] ) ? true : false |
|
| 191 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
| 192 | 192 | ); |
| 193 | 193 | //just a handy constant occasionally needed for finding values representing infinity in the DB |
| 194 | 194 | //you're better to use this than its straight value (currently -1) in case you ever |
| 195 | 195 | //want to change its default value! or find when -1 means infinity |
| 196 | - define( 'EE_INF_IN_DB', -1 ); |
|
| 197 | - define( 'EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX ); |
|
| 198 | - define( 'EE_DEBUG', false ); |
|
| 196 | + define('EE_INF_IN_DB', -1); |
|
| 197 | + define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
| 198 | + define('EE_DEBUG', false); |
|
| 199 | 199 | |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -203,9 +203,9 @@ discard block |
||
| 203 | 203 | * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
| 204 | 204 | */ |
| 205 | 205 | function espresso_plugin_activation() { |
| 206 | - update_option( 'ee_espresso_activation', true ); |
|
| 206 | + update_option('ee_espresso_activation', true); |
|
| 207 | 207 | } |
| 208 | - register_activation_hook( EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation' ); |
|
| 208 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 209 | 209 | |
| 210 | 210 | |
| 211 | 211 | |
@@ -215,15 +215,15 @@ discard block |
||
| 215 | 215 | */ |
| 216 | 216 | function espresso_load_error_handling() { |
| 217 | 217 | // load debugging tools |
| 218 | - if ( WP_DEBUG === true && is_readable( EE_HELPERS . 'EEH_Debug_Tools.helper.php' ) ) { |
|
| 219 | - require_once( EE_HELPERS . 'EEH_Debug_Tools.helper.php' ); |
|
| 218 | + if (WP_DEBUG === true && is_readable(EE_HELPERS.'EEH_Debug_Tools.helper.php')) { |
|
| 219 | + require_once(EE_HELPERS.'EEH_Debug_Tools.helper.php'); |
|
| 220 | 220 | EEH_Debug_Tools::instance(); |
| 221 | 221 | } |
| 222 | 222 | // load error handling |
| 223 | - if ( is_readable( EE_CORE . 'EE_Error.core.php' ) ) { |
|
| 224 | - require_once( EE_CORE . 'EE_Error.core.php' ); |
|
| 223 | + if (is_readable(EE_CORE.'EE_Error.core.php')) { |
|
| 224 | + require_once(EE_CORE.'EE_Error.core.php'); |
|
| 225 | 225 | } else { |
| 226 | - wp_die( esc_html__( 'The EE_Error core class could not be loaded.', 'event_espresso' ) ); |
|
| 226 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 227 | 227 | } |
| 228 | 228 | } |
| 229 | 229 | |
@@ -237,16 +237,16 @@ discard block |
||
| 237 | 237 | * @param string $full_path_to_file |
| 238 | 238 | * @throws EE_Error |
| 239 | 239 | */ |
| 240 | - function espresso_load_required( $classname, $full_path_to_file ) { |
|
| 240 | + function espresso_load_required($classname, $full_path_to_file) { |
|
| 241 | 241 | static $error_handling_loaded = false; |
| 242 | - if ( ! $error_handling_loaded ) { |
|
| 242 | + if ( ! $error_handling_loaded) { |
|
| 243 | 243 | espresso_load_error_handling(); |
| 244 | 244 | $error_handling_loaded = true; |
| 245 | 245 | } |
| 246 | - if ( is_readable( $full_path_to_file ) ) { |
|
| 247 | - require_once( $full_path_to_file ); |
|
| 246 | + if (is_readable($full_path_to_file)) { |
|
| 247 | + require_once($full_path_to_file); |
|
| 248 | 248 | } else { |
| 249 | - throw new EE_Error ( |
|
| 249 | + throw new EE_Error( |
|
| 250 | 250 | sprintf( |
| 251 | 251 | esc_html__( |
| 252 | 252 | 'The %s class file could not be located or is not readable due to file permissions.', |
@@ -258,15 +258,15 @@ discard block |
||
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - espresso_load_required( 'EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' ); |
|
| 262 | - espresso_load_required( 'EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' ); |
|
| 263 | - espresso_load_required( 'EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php' ); |
|
| 261 | + espresso_load_required('EEH_Base', EE_CORE.'helpers'.DS.'EEH_Base.helper.php'); |
|
| 262 | + espresso_load_required('EEH_File', EE_CORE.'helpers'.DS.'EEH_File.helper.php'); |
|
| 263 | + espresso_load_required('EE_Bootstrap', EE_CORE.'EE_Bootstrap.core.php'); |
|
| 264 | 264 | new EE_Bootstrap(); |
| 265 | 265 | |
| 266 | 266 | } |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | -if ( ! function_exists( 'espresso_deactivate_plugin' ) ) { |
|
| 269 | +if ( ! function_exists('espresso_deactivate_plugin')) { |
|
| 270 | 270 | |
| 271 | 271 | /** |
| 272 | 272 | * deactivate_plugin |
@@ -276,12 +276,12 @@ discard block |
||
| 276 | 276 | * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
| 277 | 277 | * @return void |
| 278 | 278 | */ |
| 279 | - function espresso_deactivate_plugin( $plugin_basename = '' ) { |
|
| 280 | - if ( ! function_exists( 'deactivate_plugins' ) ) { |
|
| 281 | - require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
| 279 | + function espresso_deactivate_plugin($plugin_basename = '') { |
|
| 280 | + if ( ! function_exists('deactivate_plugins')) { |
|
| 281 | + require_once(ABSPATH.'wp-admin/includes/plugin.php'); |
|
| 282 | 282 | } |
| 283 | - unset( $_GET['activate'], $_REQUEST['activate'] ); |
|
| 284 | - deactivate_plugins( $plugin_basename ); |
|
| 283 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 284 | + deactivate_plugins($plugin_basename); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | } |
@@ -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,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | require_once(EE_MODELS . 'EEM_CPT_Base.model.php'); |
| 5 | 5 | |
@@ -17,451 +17,451 @@ discard block |
||
| 17 | 17 | class EEM_Event extends EEM_CPT_Base |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
| 22 | - * event |
|
| 23 | - */ |
|
| 24 | - const sold_out = 'sold_out'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
| 28 | - * date) |
|
| 29 | - */ |
|
| 30 | - const postponed = 'postponed'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * constant used by status(), indicating that the event will no longer occur |
|
| 34 | - */ |
|
| 35 | - const cancelled = 'cancelled'; |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 41 | - protected static $_default_reg_status = null; |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * private instance of the Event object |
|
| 46 | - * @var EEM_Event |
|
| 47 | - */ |
|
| 48 | - protected static $_instance = null; |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * This function is a singleton method used to instantiate the EEM_Event object |
|
| 53 | - * |
|
| 54 | - * @access public |
|
| 55 | - * |
|
| 56 | - * @param string $timezone |
|
| 57 | - * |
|
| 58 | - * @return EEM_Event |
|
| 59 | - */ |
|
| 60 | - public static function instance($timezone = null) |
|
| 61 | - { |
|
| 62 | - |
|
| 63 | - // check if instance of EEM_Event already exists |
|
| 64 | - if ( ! self::$_instance instanceof EEM_Event) { |
|
| 65 | - // instantiate Espresso_model |
|
| 66 | - self::$_instance = new self($timezone); |
|
| 67 | - } |
|
| 68 | - //we might have a timezone set, let set_timezone decide what to do with it |
|
| 69 | - self::$_instance->set_timezone($timezone); |
|
| 70 | - |
|
| 71 | - // EEM_Event object |
|
| 72 | - return self::$_instance; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
| 78 | - * |
|
| 79 | - * @param string $timezone |
|
| 80 | - * |
|
| 81 | - * @return EEM_Event |
|
| 82 | - */ |
|
| 83 | - protected function __construct($timezone = null) |
|
| 84 | - { |
|
| 85 | - |
|
| 86 | - EE_Registry::instance()->load_model('Registration'); |
|
| 87 | - |
|
| 88 | - $this->singular_item = __('Event', 'event_espresso'); |
|
| 89 | - $this->plural_item = __('Events', 'event_espresso'); |
|
| 90 | - |
|
| 91 | - // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
| 92 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
| 93 | - // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
| 94 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
| 95 | - // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
| 96 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
| 97 | - |
|
| 98 | - $this->_custom_stati = apply_filters( |
|
| 99 | - 'AFEE__EEM_Event__construct___custom_stati', |
|
| 100 | - array( |
|
| 101 | - EEM_Event::cancelled => array( |
|
| 102 | - 'label' => __('Cancelled', 'event_espresso'), |
|
| 103 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true) |
|
| 104 | - ), |
|
| 105 | - EEM_Event::postponed => array( |
|
| 106 | - 'label' => __('Postponed', 'event_espresso'), |
|
| 107 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true) |
|
| 108 | - ), |
|
| 109 | - EEM_Event::sold_out => array( |
|
| 110 | - 'label' => __('Sold Out', 'event_espresso'), |
|
| 111 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true) |
|
| 112 | - ) |
|
| 113 | - ) |
|
| 114 | - ); |
|
| 115 | - |
|
| 116 | - self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment : self::$_default_reg_status; |
|
| 117 | - |
|
| 118 | - $this->_tables = array( |
|
| 119 | - 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
| 120 | - 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID') |
|
| 121 | - ); |
|
| 122 | - |
|
| 123 | - $this->_fields = array( |
|
| 124 | - 'Event_CPT' => array( |
|
| 125 | - 'EVT_ID' => new EE_Primary_Key_Int_Field('ID', __('Post ID for Event', 'event_espresso')), |
|
| 126 | - 'EVT_name' => new EE_Plain_Text_Field('post_title', __('Event Name', 'event_espresso'), false, |
|
| 127 | - ''), |
|
| 128 | - 'EVT_desc' => new EE_Post_Content_Field('post_content', __('Event Description', 'event_espresso'), |
|
| 129 | - false, ''), |
|
| 130 | - 'EVT_slug' => new EE_Slug_Field('post_name', __('Event Slug', 'event_espresso'), false, ''), |
|
| 131 | - 'EVT_created' => new EE_Datetime_Field('post_date', __('Date/Time Event Created', 'event_espresso'), |
|
| 132 | - false, EE_Datetime_Field::now), |
|
| 133 | - 'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt', |
|
| 134 | - __('Event Short Description', 'event_espresso'), false, ''), |
|
| 135 | - 'EVT_modified' => new EE_Datetime_Field('post_modified', |
|
| 136 | - __('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now), |
|
| 137 | - 'EVT_wp_user' => new EE_WP_User_Field('post_author', __('Event Creator ID', 'event_espresso'), |
|
| 138 | - false), |
|
| 139 | - 'parent' => new EE_Integer_Field('post_parent', __('Event Parent ID', 'event_espresso'), false, |
|
| 140 | - 0), |
|
| 141 | - 'EVT_order' => new EE_Integer_Field('menu_order', __('Event Menu Order', 'event_espresso'), false, |
|
| 142 | - 1), |
|
| 143 | - 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
| 144 | - // EE_Plain_Text_Field( 'post_type', __( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
| 145 | - 'status' => new EE_WP_Post_Status_Field('post_status', __('Event Status', 'event_espresso'), |
|
| 146 | - false, 'draft', $this->_custom_stati) |
|
| 147 | - ), |
|
| 148 | - 'Event_Meta' => array( |
|
| 149 | - 'EVTM_ID' => new EE_DB_Only_Float_Field('EVTM_ID', |
|
| 150 | - __('Event Meta Row ID', 'event_espresso'), false), |
|
| 151 | - 'EVT_ID_fk' => new EE_DB_Only_Int_Field('EVT_ID', |
|
| 152 | - __('Foreign key to Event ID from Event Meta table', 'event_espresso'), false), |
|
| 153 | - 'EVT_display_desc' => new EE_Boolean_Field('EVT_display_desc', |
|
| 154 | - __('Display Description Flag', 'event_espresso'), false, 1), |
|
| 155 | - 'EVT_display_ticket_selector' => new EE_Boolean_Field('EVT_display_ticket_selector', |
|
| 156 | - __('Display Ticket Selector Flag', 'event_espresso'), false, 1), |
|
| 157 | - 'EVT_visible_on' => new EE_Datetime_Field('EVT_visible_on', |
|
| 158 | - __('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now), |
|
| 159 | - 'EVT_additional_limit' => new EE_Integer_Field('EVT_additional_limit', |
|
| 160 | - __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), true, 10), |
|
| 161 | - 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
| 162 | - 'EVT_default_registration_status', |
|
| 163 | - __('Default Registration Status on this Event', 'event_espresso'), false, |
|
| 164 | - EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array() |
|
| 165 | - ), |
|
| 166 | - 'EVT_member_only' => new EE_Boolean_Field('EVT_member_only', |
|
| 167 | - __('Member-Only Event Flag', 'event_espresso'), false, false), |
|
| 168 | - 'EVT_phone' => new EE_Plain_Text_Field('EVT_phone', |
|
| 169 | - __('Event Phone Number', 'event_espresso'), false), |
|
| 170 | - 'EVT_allow_overflow' => new EE_Boolean_Field('EVT_allow_overflow', |
|
| 171 | - __('Allow Overflow on Event', 'event_espresso'), false, false), |
|
| 172 | - 'EVT_timezone_string' => new EE_Plain_Text_Field('EVT_timezone_string', |
|
| 173 | - __('Timezone (name) for Event times', 'event_espresso'), false), |
|
| 174 | - 'EVT_external_URL' => new EE_Plain_Text_Field('EVT_external_URL', |
|
| 175 | - __('URL of Event Page if hosted elsewhere', 'event_espresso'), true), |
|
| 176 | - 'EVT_donations' => new EE_Boolean_Field('EVT_donations', |
|
| 177 | - __('Accept Donations?', 'event_espresso'), false, false) |
|
| 20 | + /** |
|
| 21 | + * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
| 22 | + * event |
|
| 23 | + */ |
|
| 24 | + const sold_out = 'sold_out'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
| 28 | + * date) |
|
| 29 | + */ |
|
| 30 | + const postponed = 'postponed'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * constant used by status(), indicating that the event will no longer occur |
|
| 34 | + */ |
|
| 35 | + const cancelled = 'cancelled'; |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | + protected static $_default_reg_status = null; |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * private instance of the Event object |
|
| 46 | + * @var EEM_Event |
|
| 47 | + */ |
|
| 48 | + protected static $_instance = null; |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * This function is a singleton method used to instantiate the EEM_Event object |
|
| 53 | + * |
|
| 54 | + * @access public |
|
| 55 | + * |
|
| 56 | + * @param string $timezone |
|
| 57 | + * |
|
| 58 | + * @return EEM_Event |
|
| 59 | + */ |
|
| 60 | + public static function instance($timezone = null) |
|
| 61 | + { |
|
| 62 | + |
|
| 63 | + // check if instance of EEM_Event already exists |
|
| 64 | + if ( ! self::$_instance instanceof EEM_Event) { |
|
| 65 | + // instantiate Espresso_model |
|
| 66 | + self::$_instance = new self($timezone); |
|
| 67 | + } |
|
| 68 | + //we might have a timezone set, let set_timezone decide what to do with it |
|
| 69 | + self::$_instance->set_timezone($timezone); |
|
| 70 | + |
|
| 71 | + // EEM_Event object |
|
| 72 | + return self::$_instance; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
| 78 | + * |
|
| 79 | + * @param string $timezone |
|
| 80 | + * |
|
| 81 | + * @return EEM_Event |
|
| 82 | + */ |
|
| 83 | + protected function __construct($timezone = null) |
|
| 84 | + { |
|
| 85 | + |
|
| 86 | + EE_Registry::instance()->load_model('Registration'); |
|
| 87 | + |
|
| 88 | + $this->singular_item = __('Event', 'event_espresso'); |
|
| 89 | + $this->plural_item = __('Events', 'event_espresso'); |
|
| 90 | + |
|
| 91 | + // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
| 92 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
| 93 | + // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
| 94 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
| 95 | + // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
| 96 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
| 97 | + |
|
| 98 | + $this->_custom_stati = apply_filters( |
|
| 99 | + 'AFEE__EEM_Event__construct___custom_stati', |
|
| 100 | + array( |
|
| 101 | + EEM_Event::cancelled => array( |
|
| 102 | + 'label' => __('Cancelled', 'event_espresso'), |
|
| 103 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true) |
|
| 104 | + ), |
|
| 105 | + EEM_Event::postponed => array( |
|
| 106 | + 'label' => __('Postponed', 'event_espresso'), |
|
| 107 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true) |
|
| 108 | + ), |
|
| 109 | + EEM_Event::sold_out => array( |
|
| 110 | + 'label' => __('Sold Out', 'event_espresso'), |
|
| 111 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true) |
|
| 112 | + ) |
|
| 113 | + ) |
|
| 114 | + ); |
|
| 115 | + |
|
| 116 | + self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment : self::$_default_reg_status; |
|
| 117 | + |
|
| 118 | + $this->_tables = array( |
|
| 119 | + 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
| 120 | + 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID') |
|
| 121 | + ); |
|
| 122 | + |
|
| 123 | + $this->_fields = array( |
|
| 124 | + 'Event_CPT' => array( |
|
| 125 | + 'EVT_ID' => new EE_Primary_Key_Int_Field('ID', __('Post ID for Event', 'event_espresso')), |
|
| 126 | + 'EVT_name' => new EE_Plain_Text_Field('post_title', __('Event Name', 'event_espresso'), false, |
|
| 127 | + ''), |
|
| 128 | + 'EVT_desc' => new EE_Post_Content_Field('post_content', __('Event Description', 'event_espresso'), |
|
| 129 | + false, ''), |
|
| 130 | + 'EVT_slug' => new EE_Slug_Field('post_name', __('Event Slug', 'event_espresso'), false, ''), |
|
| 131 | + 'EVT_created' => new EE_Datetime_Field('post_date', __('Date/Time Event Created', 'event_espresso'), |
|
| 132 | + false, EE_Datetime_Field::now), |
|
| 133 | + 'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt', |
|
| 134 | + __('Event Short Description', 'event_espresso'), false, ''), |
|
| 135 | + 'EVT_modified' => new EE_Datetime_Field('post_modified', |
|
| 136 | + __('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now), |
|
| 137 | + 'EVT_wp_user' => new EE_WP_User_Field('post_author', __('Event Creator ID', 'event_espresso'), |
|
| 138 | + false), |
|
| 139 | + 'parent' => new EE_Integer_Field('post_parent', __('Event Parent ID', 'event_espresso'), false, |
|
| 140 | + 0), |
|
| 141 | + 'EVT_order' => new EE_Integer_Field('menu_order', __('Event Menu Order', 'event_espresso'), false, |
|
| 142 | + 1), |
|
| 143 | + 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
| 144 | + // EE_Plain_Text_Field( 'post_type', __( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
| 145 | + 'status' => new EE_WP_Post_Status_Field('post_status', __('Event Status', 'event_espresso'), |
|
| 146 | + false, 'draft', $this->_custom_stati) |
|
| 147 | + ), |
|
| 148 | + 'Event_Meta' => array( |
|
| 149 | + 'EVTM_ID' => new EE_DB_Only_Float_Field('EVTM_ID', |
|
| 150 | + __('Event Meta Row ID', 'event_espresso'), false), |
|
| 151 | + 'EVT_ID_fk' => new EE_DB_Only_Int_Field('EVT_ID', |
|
| 152 | + __('Foreign key to Event ID from Event Meta table', 'event_espresso'), false), |
|
| 153 | + 'EVT_display_desc' => new EE_Boolean_Field('EVT_display_desc', |
|
| 154 | + __('Display Description Flag', 'event_espresso'), false, 1), |
|
| 155 | + 'EVT_display_ticket_selector' => new EE_Boolean_Field('EVT_display_ticket_selector', |
|
| 156 | + __('Display Ticket Selector Flag', 'event_espresso'), false, 1), |
|
| 157 | + 'EVT_visible_on' => new EE_Datetime_Field('EVT_visible_on', |
|
| 158 | + __('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now), |
|
| 159 | + 'EVT_additional_limit' => new EE_Integer_Field('EVT_additional_limit', |
|
| 160 | + __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), true, 10), |
|
| 161 | + 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
| 162 | + 'EVT_default_registration_status', |
|
| 163 | + __('Default Registration Status on this Event', 'event_espresso'), false, |
|
| 164 | + EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array() |
|
| 165 | + ), |
|
| 166 | + 'EVT_member_only' => new EE_Boolean_Field('EVT_member_only', |
|
| 167 | + __('Member-Only Event Flag', 'event_espresso'), false, false), |
|
| 168 | + 'EVT_phone' => new EE_Plain_Text_Field('EVT_phone', |
|
| 169 | + __('Event Phone Number', 'event_espresso'), false), |
|
| 170 | + 'EVT_allow_overflow' => new EE_Boolean_Field('EVT_allow_overflow', |
|
| 171 | + __('Allow Overflow on Event', 'event_espresso'), false, false), |
|
| 172 | + 'EVT_timezone_string' => new EE_Plain_Text_Field('EVT_timezone_string', |
|
| 173 | + __('Timezone (name) for Event times', 'event_espresso'), false), |
|
| 174 | + 'EVT_external_URL' => new EE_Plain_Text_Field('EVT_external_URL', |
|
| 175 | + __('URL of Event Page if hosted elsewhere', 'event_espresso'), true), |
|
| 176 | + 'EVT_donations' => new EE_Boolean_Field('EVT_donations', |
|
| 177 | + __('Accept Donations?', 'event_espresso'), false, false) |
|
| 178 | 178 | |
| 179 | - ) |
|
| 180 | - ); |
|
| 181 | - |
|
| 182 | - $this->_model_relations = array( |
|
| 183 | - 'Registration' => new EE_Has_Many_Relation(), |
|
| 184 | - 'Datetime' => new EE_Has_Many_Relation(), |
|
| 185 | - 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
| 186 | - 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
| 187 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
| 188 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
| 189 | - 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
| 190 | - 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
| 191 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 192 | - ); |
|
| 193 | - //this model is generally available for reading |
|
| 194 | - $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
| 195 | - parent::__construct($timezone); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * @param string $default_reg_status |
|
| 201 | - */ |
|
| 202 | - public static function set_default_reg_status($default_reg_status) |
|
| 203 | - { |
|
| 204 | - self::$_default_reg_status = $default_reg_status; |
|
| 205 | - //if EEM_Event has already been instantiated, then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
| 206 | - if (self::$_instance instanceof EEM_Event) { |
|
| 207 | - self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = new EE_Enum_Text_Field( |
|
| 208 | - 'EVT_default_registration_status', __('Default Registration Status on this Event', 'event_espresso'), |
|
| 209 | - false, $default_reg_status, EEM_Registration::reg_status_array() |
|
| 210 | - ); |
|
| 211 | - self::$_instance->_fields['Event_Meta']['EVT_default_registration_status']->_construct_finalize('Event_Meta', |
|
| 212 | - 'EVT_default_registration_status', 'EEM_Event'); |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * get_question_groups |
|
| 219 | - * |
|
| 220 | - * @access public |
|
| 221 | - * @return array |
|
| 222 | - */ |
|
| 223 | - public function get_all_question_groups() |
|
| 224 | - { |
|
| 225 | - return EE_Registry::instance()->load_model('Question_Group')->get_all(array( |
|
| 226 | - array('QSG_deleted' => false), |
|
| 227 | - 'order_by' => array('QSG_order' => 'ASC') |
|
| 228 | - )); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * get_question_groups |
|
| 234 | - * |
|
| 235 | - * @access public |
|
| 236 | - * |
|
| 237 | - * @param int $EVT_ID |
|
| 238 | - * |
|
| 239 | - * @return array |
|
| 240 | - */ |
|
| 241 | - public function get_all_event_question_groups($EVT_ID = 0) |
|
| 242 | - { |
|
| 243 | - if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 244 | - EE_Error::add_error(__('An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
| 245 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 179 | + ) |
|
| 180 | + ); |
|
| 181 | + |
|
| 182 | + $this->_model_relations = array( |
|
| 183 | + 'Registration' => new EE_Has_Many_Relation(), |
|
| 184 | + 'Datetime' => new EE_Has_Many_Relation(), |
|
| 185 | + 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
| 186 | + 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
| 187 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
| 188 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
| 189 | + 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
| 190 | + 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
| 191 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 192 | + ); |
|
| 193 | + //this model is generally available for reading |
|
| 194 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
| 195 | + parent::__construct($timezone); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * @param string $default_reg_status |
|
| 201 | + */ |
|
| 202 | + public static function set_default_reg_status($default_reg_status) |
|
| 203 | + { |
|
| 204 | + self::$_default_reg_status = $default_reg_status; |
|
| 205 | + //if EEM_Event has already been instantiated, then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
| 206 | + if (self::$_instance instanceof EEM_Event) { |
|
| 207 | + self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = new EE_Enum_Text_Field( |
|
| 208 | + 'EVT_default_registration_status', __('Default Registration Status on this Event', 'event_espresso'), |
|
| 209 | + false, $default_reg_status, EEM_Registration::reg_status_array() |
|
| 210 | + ); |
|
| 211 | + self::$_instance->_fields['Event_Meta']['EVT_default_registration_status']->_construct_finalize('Event_Meta', |
|
| 212 | + 'EVT_default_registration_status', 'EEM_Event'); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * get_question_groups |
|
| 219 | + * |
|
| 220 | + * @access public |
|
| 221 | + * @return array |
|
| 222 | + */ |
|
| 223 | + public function get_all_question_groups() |
|
| 224 | + { |
|
| 225 | + return EE_Registry::instance()->load_model('Question_Group')->get_all(array( |
|
| 226 | + array('QSG_deleted' => false), |
|
| 227 | + 'order_by' => array('QSG_order' => 'ASC') |
|
| 228 | + )); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * get_question_groups |
|
| 234 | + * |
|
| 235 | + * @access public |
|
| 236 | + * |
|
| 237 | + * @param int $EVT_ID |
|
| 238 | + * |
|
| 239 | + * @return array |
|
| 240 | + */ |
|
| 241 | + public function get_all_event_question_groups($EVT_ID = 0) |
|
| 242 | + { |
|
| 243 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 244 | + EE_Error::add_error(__('An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
| 245 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 246 | 246 | |
| 247 | - return false; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(array( |
|
| 251 | - array('EVT_ID' => $EVT_ID) |
|
| 252 | - )); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * get_question_groups |
|
| 258 | - * |
|
| 259 | - * @access public |
|
| 260 | - * |
|
| 261 | - * @param int $EVT_ID |
|
| 262 | - * @param boolean $for_primary_attendee |
|
| 263 | - * |
|
| 264 | - * @return array |
|
| 265 | - */ |
|
| 266 | - public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
| 267 | - { |
|
| 268 | - if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 269 | - EE_Error::add_error(__('An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
| 270 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 247 | + return false; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(array( |
|
| 251 | + array('EVT_ID' => $EVT_ID) |
|
| 252 | + )); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * get_question_groups |
|
| 258 | + * |
|
| 259 | + * @access public |
|
| 260 | + * |
|
| 261 | + * @param int $EVT_ID |
|
| 262 | + * @param boolean $for_primary_attendee |
|
| 263 | + * |
|
| 264 | + * @return array |
|
| 265 | + */ |
|
| 266 | + public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
| 267 | + { |
|
| 268 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 269 | + EE_Error::add_error(__('An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
| 270 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 271 | 271 | |
| 272 | - return false; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(array( |
|
| 276 | - array('EVT_ID' => $EVT_ID, 'EQG_primary' => $for_primary_attendee) |
|
| 277 | - )); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * get_question_groups |
|
| 283 | - * |
|
| 284 | - * @access public |
|
| 285 | - * |
|
| 286 | - * @param int $EVT_ID |
|
| 287 | - * @param EE_Registration $registration |
|
| 288 | - * |
|
| 289 | - * @return array |
|
| 290 | - */ |
|
| 291 | - public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
| 292 | - { |
|
| 293 | - |
|
| 294 | - if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 295 | - EE_Error::add_error(__('An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
| 296 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 272 | + return false; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(array( |
|
| 276 | + array('EVT_ID' => $EVT_ID, 'EQG_primary' => $for_primary_attendee) |
|
| 277 | + )); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * get_question_groups |
|
| 283 | + * |
|
| 284 | + * @access public |
|
| 285 | + * |
|
| 286 | + * @param int $EVT_ID |
|
| 287 | + * @param EE_Registration $registration |
|
| 288 | + * |
|
| 289 | + * @return array |
|
| 290 | + */ |
|
| 291 | + public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
| 292 | + { |
|
| 293 | + |
|
| 294 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 295 | + EE_Error::add_error(__('An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
| 296 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 297 | 297 | |
| 298 | - return false; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - $where_params = array( |
|
| 302 | - 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
| 303 | - 'Event_Question_Group.EQG_primary' => $registration->count() == 1 ? true : false, |
|
| 304 | - 'QSG_deleted' => false |
|
| 305 | - ); |
|
| 306 | - |
|
| 307 | - return EE_Registry::instance()->load_model('Question_Group')->get_all(array( |
|
| 308 | - $where_params, |
|
| 309 | - 'order_by' => array('QSG_order' => 'ASC') |
|
| 310 | - )); |
|
| 311 | - |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * get_question_target_db_column |
|
| 317 | - * |
|
| 318 | - * @access public |
|
| 319 | - * |
|
| 320 | - * @param string $QSG_IDs csv list of $QSG IDs |
|
| 321 | - * |
|
| 322 | - * @return array |
|
| 323 | - */ |
|
| 324 | - public function get_questions_in_groups($QSG_IDs = '') |
|
| 325 | - { |
|
| 326 | - |
|
| 327 | - if (empty($QSG_IDs)) { |
|
| 328 | - EE_Error::add_error(__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
| 329 | - __FILE__, __FUNCTION__, __LINE__); |
|
| 298 | + return false; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + $where_params = array( |
|
| 302 | + 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
| 303 | + 'Event_Question_Group.EQG_primary' => $registration->count() == 1 ? true : false, |
|
| 304 | + 'QSG_deleted' => false |
|
| 305 | + ); |
|
| 306 | + |
|
| 307 | + return EE_Registry::instance()->load_model('Question_Group')->get_all(array( |
|
| 308 | + $where_params, |
|
| 309 | + 'order_by' => array('QSG_order' => 'ASC') |
|
| 310 | + )); |
|
| 311 | + |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * get_question_target_db_column |
|
| 317 | + * |
|
| 318 | + * @access public |
|
| 319 | + * |
|
| 320 | + * @param string $QSG_IDs csv list of $QSG IDs |
|
| 321 | + * |
|
| 322 | + * @return array |
|
| 323 | + */ |
|
| 324 | + public function get_questions_in_groups($QSG_IDs = '') |
|
| 325 | + { |
|
| 326 | + |
|
| 327 | + if (empty($QSG_IDs)) { |
|
| 328 | + EE_Error::add_error(__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
| 329 | + __FILE__, __FUNCTION__, __LINE__); |
|
| 330 | 330 | |
| 331 | - return false; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - return EE_Registry::instance()->load_model('Question')->get_all(array( |
|
| 335 | - array( |
|
| 336 | - 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
| 337 | - 'QST_deleted' => false, |
|
| 338 | - 'QST_admin_only' => is_admin() |
|
| 339 | - ), |
|
| 340 | - 'order_by' => 'QST_order' |
|
| 341 | - )); |
|
| 342 | - |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * get_options_for_question |
|
| 348 | - * |
|
| 349 | - * @access public |
|
| 350 | - * |
|
| 351 | - * @param string $QST_IDs csv list of $QST IDs |
|
| 352 | - * |
|
| 353 | - * @return array |
|
| 354 | - */ |
|
| 355 | - public function get_options_for_question($QST_IDs) |
|
| 356 | - { |
|
| 357 | - |
|
| 358 | - if (empty($QST_IDs)) { |
|
| 359 | - EE_Error::add_error(__('An error occurred. No Question IDs were received.', 'event_espresso'), __FILE__, |
|
| 360 | - __FUNCTION__, __LINE__); |
|
| 331 | + return false; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + return EE_Registry::instance()->load_model('Question')->get_all(array( |
|
| 335 | + array( |
|
| 336 | + 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
| 337 | + 'QST_deleted' => false, |
|
| 338 | + 'QST_admin_only' => is_admin() |
|
| 339 | + ), |
|
| 340 | + 'order_by' => 'QST_order' |
|
| 341 | + )); |
|
| 342 | + |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * get_options_for_question |
|
| 348 | + * |
|
| 349 | + * @access public |
|
| 350 | + * |
|
| 351 | + * @param string $QST_IDs csv list of $QST IDs |
|
| 352 | + * |
|
| 353 | + * @return array |
|
| 354 | + */ |
|
| 355 | + public function get_options_for_question($QST_IDs) |
|
| 356 | + { |
|
| 357 | + |
|
| 358 | + if (empty($QST_IDs)) { |
|
| 359 | + EE_Error::add_error(__('An error occurred. No Question IDs were received.', 'event_espresso'), __FILE__, |
|
| 360 | + __FUNCTION__, __LINE__); |
|
| 361 | 361 | |
| 362 | - return false; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - return EE_Registry::instance()->load_model('Question_Option')->get_all(array( |
|
| 366 | - array( |
|
| 367 | - 'Question.QST_ID' => array('IN', $QST_IDs), |
|
| 368 | - 'QSO_deleted' => false |
|
| 369 | - ), |
|
| 370 | - 'order_by' => 'QSO_ID' |
|
| 371 | - )); |
|
| 372 | - |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * _get_question_target_db_column |
|
| 378 | - * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
| 379 | - * EE_Registration_Custom_Questions_Form located in |
|
| 380 | - * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
| 381 | - * @access public |
|
| 382 | - * |
|
| 383 | - * @param EE_Registration $registration (so existing answers for registration are included) |
|
| 384 | - * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
| 385 | - * registration). |
|
| 386 | - * |
|
| 387 | - * @throws EE_Error |
|
| 388 | - * @return array |
|
| 389 | - */ |
|
| 390 | - public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
| 391 | - { |
|
| 392 | - |
|
| 393 | - if (empty($EVT_ID)) { |
|
| 394 | - throw new EE_Error(__('An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
| 395 | - 'event_espresso')); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - $questions = array(); |
|
| 399 | - |
|
| 400 | - // get all question groups for event |
|
| 401 | - $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
| 402 | - if ( ! empty($qgs)) { |
|
| 403 | - foreach ($qgs as $qg) { |
|
| 404 | - $qsts = $qg->questions(); |
|
| 405 | - $questions[$qg->ID()] = $qg->model_field_array(); |
|
| 406 | - $questions[$qg->ID()]['QSG_questions'] = array(); |
|
| 407 | - foreach ($qsts as $qst) { |
|
| 408 | - if ($qst->is_system_question()) { |
|
| 409 | - continue; |
|
| 410 | - } |
|
| 411 | - $answer = EEM_Answer::instance()->get_one(array( |
|
| 412 | - array( |
|
| 413 | - 'QST_ID' => $qst->ID(), |
|
| 414 | - 'REG_ID' => $registration->ID() |
|
| 415 | - ) |
|
| 416 | - )); |
|
| 417 | - $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
| 418 | - $qst_name = $qstn_id = $qst->ID(); |
|
| 419 | - $ans_id = $answer->ID(); |
|
| 420 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
| 421 | - $input_name = ''; |
|
| 422 | - $input_id = sanitize_key($qst->display_text()); |
|
| 423 | - $input_class = ''; |
|
| 424 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
|
| 425 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' . $input_name . $qst_name; |
|
| 426 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
| 427 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
|
| 428 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
|
| 429 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
|
| 430 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer; |
|
| 431 | - //leave responses as-is, don't convert stuff into html entities please! |
|
| 432 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false; |
|
| 433 | - if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
| 434 | - $QSOs = $qst->options(true, $answer->value()); |
|
| 435 | - if (is_array($QSOs)) { |
|
| 436 | - foreach ($QSOs as $QSO_ID => $QSO) { |
|
| 437 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array(); |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - } |
|
| 362 | + return false; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + return EE_Registry::instance()->load_model('Question_Option')->get_all(array( |
|
| 366 | + array( |
|
| 367 | + 'Question.QST_ID' => array('IN', $QST_IDs), |
|
| 368 | + 'QSO_deleted' => false |
|
| 369 | + ), |
|
| 370 | + 'order_by' => 'QSO_ID' |
|
| 371 | + )); |
|
| 372 | + |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * _get_question_target_db_column |
|
| 378 | + * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
| 379 | + * EE_Registration_Custom_Questions_Form located in |
|
| 380 | + * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
| 381 | + * @access public |
|
| 382 | + * |
|
| 383 | + * @param EE_Registration $registration (so existing answers for registration are included) |
|
| 384 | + * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
| 385 | + * registration). |
|
| 386 | + * |
|
| 387 | + * @throws EE_Error |
|
| 388 | + * @return array |
|
| 389 | + */ |
|
| 390 | + public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
| 391 | + { |
|
| 392 | + |
|
| 393 | + if (empty($EVT_ID)) { |
|
| 394 | + throw new EE_Error(__('An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
| 395 | + 'event_espresso')); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + $questions = array(); |
|
| 399 | + |
|
| 400 | + // get all question groups for event |
|
| 401 | + $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
| 402 | + if ( ! empty($qgs)) { |
|
| 403 | + foreach ($qgs as $qg) { |
|
| 404 | + $qsts = $qg->questions(); |
|
| 405 | + $questions[$qg->ID()] = $qg->model_field_array(); |
|
| 406 | + $questions[$qg->ID()]['QSG_questions'] = array(); |
|
| 407 | + foreach ($qsts as $qst) { |
|
| 408 | + if ($qst->is_system_question()) { |
|
| 409 | + continue; |
|
| 410 | + } |
|
| 411 | + $answer = EEM_Answer::instance()->get_one(array( |
|
| 412 | + array( |
|
| 413 | + 'QST_ID' => $qst->ID(), |
|
| 414 | + 'REG_ID' => $registration->ID() |
|
| 415 | + ) |
|
| 416 | + )); |
|
| 417 | + $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
| 418 | + $qst_name = $qstn_id = $qst->ID(); |
|
| 419 | + $ans_id = $answer->ID(); |
|
| 420 | + $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
| 421 | + $input_name = ''; |
|
| 422 | + $input_id = sanitize_key($qst->display_text()); |
|
| 423 | + $input_class = ''; |
|
| 424 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
|
| 425 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' . $input_name . $qst_name; |
|
| 426 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
| 427 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
|
| 428 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
|
| 429 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
|
| 430 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer; |
|
| 431 | + //leave responses as-is, don't convert stuff into html entities please! |
|
| 432 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false; |
|
| 433 | + if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
| 434 | + $QSOs = $qst->options(true, $answer->value()); |
|
| 435 | + if (is_array($QSOs)) { |
|
| 436 | + foreach ($QSOs as $QSO_ID => $QSO) { |
|
| 437 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array(); |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | 441 | |
| 442 | - } |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - return $questions; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * _get_question_target_db_column |
|
| 452 | - * |
|
| 453 | - * @access private |
|
| 454 | - * |
|
| 455 | - * @param $QST |
|
| 456 | - * |
|
| 457 | - * @return string string |
|
| 458 | - */ |
|
| 459 | - private function _generate_question_input_name($QST) |
|
| 460 | - { |
|
| 461 | - |
|
| 462 | - if ($QST->QST_system) { |
|
| 463 | - $qst_name = $QST->QST_system; |
|
| 464 | - /* switch( $QST->QST_system ) { |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + return $questions; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * _get_question_target_db_column |
|
| 452 | + * |
|
| 453 | + * @access private |
|
| 454 | + * |
|
| 455 | + * @param $QST |
|
| 456 | + * |
|
| 457 | + * @return string string |
|
| 458 | + */ |
|
| 459 | + private function _generate_question_input_name($QST) |
|
| 460 | + { |
|
| 461 | + |
|
| 462 | + if ($QST->QST_system) { |
|
| 463 | + $qst_name = $QST->QST_system; |
|
| 464 | + /* switch( $QST->QST_system ) { |
|
| 465 | 465 | |
| 466 | 466 | case 1 : |
| 467 | 467 | $qst_name = $QST->QST_ID . '-fname'; |
@@ -505,261 +505,261 @@ discard block |
||
| 505 | 505 | |
| 506 | 506 | }*/ |
| 507 | 507 | |
| 508 | - } else { |
|
| 509 | - //$qst_name = $QST->QST_ID . '-' . str_replace( array( ' ', '-', '.' ), '_', strtolower( $QST->QST_display_text )); |
|
| 510 | - $qst_name = $QST->QST_ID; |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - return $qst_name; |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * Gets all events that are published and have event start time earlier than now and an event end time later than |
|
| 519 | - * now |
|
| 520 | - * |
|
| 521 | - * @access public |
|
| 522 | - * |
|
| 523 | - * @param array $query_params An array of query params to further filter on (note that status and DTT_EVT_start |
|
| 524 | - * and DTT_EVT_end will be overridden) |
|
| 525 | - * @param bool $count whether to return the count or not (default FALSE) |
|
| 526 | - * |
|
| 527 | - * @return array EE_Event objects |
|
| 528 | - */ |
|
| 529 | - public function get_active_events($query_params, $count = false) |
|
| 530 | - { |
|
| 531 | - if (array_key_exists(0, $query_params)) { |
|
| 532 | - $where_params = $query_params[0]; |
|
| 533 | - unset($query_params[0]); |
|
| 534 | - } else { |
|
| 535 | - $where_params = array(); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - //if we have count make sure we don't include group by |
|
| 539 | - if ($count && isset($query_params['group_by'])) { |
|
| 540 | - unset($query_params['group_by']); |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - //let's add specific query_params for active_events - keep in mind this will override any sent status in the query AND any date queries. |
|
| 544 | - $where_params['status'] = array( 'IN', array( 'publish', EEM_Event::sold_out ) ); |
|
| 545 | - //if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
| 546 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 547 | - $where_params['Datetime.DTT_EVT_start******'] = array( |
|
| 548 | - '<', |
|
| 549 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
|
| 550 | - ); |
|
| 551 | - } else { |
|
| 552 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
| 553 | - '<', |
|
| 554 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
|
| 555 | - ); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 559 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
| 560 | - '>', |
|
| 561 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end') |
|
| 562 | - ); |
|
| 563 | - } else { |
|
| 564 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
| 565 | - '>', |
|
| 566 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end') |
|
| 567 | - ); |
|
| 568 | - } |
|
| 569 | - $query_params[0] = $where_params; |
|
| 570 | - |
|
| 571 | - // don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY" |
|
| 572 | - return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - |
|
| 576 | - /** |
|
| 577 | - * get all events that are published and have an event start time later than now |
|
| 578 | - * |
|
| 579 | - * @access public |
|
| 580 | - * |
|
| 581 | - * @param array $query_params An array of query params to further filter on (Note that status and DTT_EVT_start |
|
| 582 | - * will be overridden) |
|
| 583 | - * @param bool $count whether to return the count or not (default FALSE) |
|
| 584 | - * |
|
| 585 | - * @return array EE_Event objects |
|
| 586 | - */ |
|
| 587 | - public function get_upcoming_events($query_params, $count = false) |
|
| 588 | - { |
|
| 589 | - if (array_key_exists(0, $query_params)) { |
|
| 590 | - $where_params = $query_params[0]; |
|
| 591 | - unset($query_params[0]); |
|
| 592 | - } else { |
|
| 593 | - $where_params = array(); |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - //if we have count make sure we don't include group by |
|
| 597 | - if ($count && isset($query_params['group_by'])) { |
|
| 598 | - unset($query_params['group_by']); |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - //let's add specific query_params for active_events - keep in mind this will override any sent status in the query AND any date queries. |
|
| 602 | - $where_params['status'] = array( 'IN', array( 'publish', EEM_Event::sold_out ) ); |
|
| 603 | - //if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
| 604 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 605 | - $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
| 606 | - '>', |
|
| 607 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
|
| 608 | - ); |
|
| 609 | - } else { |
|
| 610 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
| 611 | - '>', |
|
| 612 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
|
| 613 | - ); |
|
| 614 | - } |
|
| 615 | - $query_params[0] = $where_params; |
|
| 616 | - |
|
| 617 | - // don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY" |
|
| 618 | - return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params); |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - |
|
| 622 | - /** |
|
| 623 | - * This only returns events that are expired. They may still be published but all their datetimes have expired. |
|
| 624 | - * |
|
| 625 | - * @access public |
|
| 626 | - * |
|
| 627 | - * @param array $query_params An array of query params to further filter on (note that status and DTT_EVT_end will |
|
| 628 | - * be overridden) |
|
| 629 | - * @param bool $count whether to return the count or not (default FALSE) |
|
| 630 | - * |
|
| 631 | - * @return array EE_Event objects |
|
| 632 | - */ |
|
| 633 | - public function get_expired_events($query_params, $count = false) |
|
| 634 | - { |
|
| 635 | - |
|
| 636 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 637 | - |
|
| 638 | - //if we have count make sure we don't include group by |
|
| 639 | - if ($count && isset($query_params['group_by'])) { |
|
| 640 | - unset($query_params['group_by']); |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - //let's add specific query_params for active_events - keep in mind this will override any sent status in the query AND any date queries. |
|
| 644 | - if (isset($where_params['status'])) { |
|
| 645 | - unset($where_params['status']); |
|
| 646 | - } |
|
| 647 | - $exclude_query = $query_params; |
|
| 648 | - if (isset($exclude_query[0])) { |
|
| 649 | - unset($exclude_query[0]); |
|
| 650 | - } |
|
| 651 | - $exclude_query[0] = array( |
|
| 652 | - 'Datetime.DTT_EVT_end' => array( |
|
| 653 | - '>', |
|
| 654 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end') |
|
| 655 | - ) |
|
| 656 | - ); |
|
| 657 | - //first get all events that have datetimes where its not expired. |
|
| 658 | - $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
| 659 | - $event_ids = array_keys($event_ids); |
|
| 660 | - |
|
| 661 | - //if we have any additional query_params, let's add them to the 'AND' condition |
|
| 662 | - $and_condition = array( |
|
| 663 | - 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
| 664 | - 'EVT_ID' => array('NOT IN', $event_ids) |
|
| 665 | - ); |
|
| 666 | - |
|
| 667 | - if (isset($where_params['OR'])) { |
|
| 668 | - $and_condition['OR'] = $where_params['OR']; |
|
| 669 | - unset($where_params['OR']); |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 673 | - $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
| 674 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
| 675 | - } |
|
| 676 | - |
|
| 677 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 678 | - $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
| 679 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - //merge remaining $where params with the and conditions. |
|
| 683 | - $where_params['AND'] = array_merge($and_condition, $where_params); |
|
| 684 | - $query_params[0] = $where_params; |
|
| 685 | - |
|
| 686 | - // don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY" |
|
| 687 | - return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params); |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * This basically just returns the events that do not have the publish status. |
|
| 693 | - * |
|
| 694 | - * @param array $query_params An array of query params to further filter on (note that status will be |
|
| 695 | - * overwritten) |
|
| 696 | - * @param boolean $count whether to return the count or not (default FALSE) |
|
| 697 | - * |
|
| 698 | - * @return EE_Event[] array of EE_Event objects |
|
| 699 | - */ |
|
| 700 | - public function get_inactive_events($query_params, $count = false) |
|
| 701 | - { |
|
| 702 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 703 | - |
|
| 704 | - //let's add in specific query_params for inactive events. |
|
| 705 | - if (isset($where_params['status'])) { |
|
| 706 | - unset($where_params['status']); |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - //if we have count make sure we don't include group by |
|
| 710 | - if ($count && isset($query_params['group_by'])) { |
|
| 711 | - unset($query_params['group_by']); |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - //if we have any additional query_params, let's add them to the 'AND' condition |
|
| 715 | - $where_params['AND']['status'] = array('!=', 'publish'); |
|
| 716 | - |
|
| 717 | - if (isset($where_params['OR'])) { |
|
| 718 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
| 719 | - unset($where_params['OR']); |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 723 | - $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
| 724 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 728 | - $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
| 729 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - $query_params[0] = $where_params; |
|
| 733 | - |
|
| 734 | - // don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY" |
|
| 735 | - return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params); |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - |
|
| 739 | - /** |
|
| 740 | - * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
| 741 | - * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
| 742 | - * attached to the event. See parent for param descriptions |
|
| 743 | - */ |
|
| 744 | - public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
| 745 | - { |
|
| 746 | - |
|
| 747 | - if ($relationName == 'Price') { |
|
| 748 | - //let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
| 749 | - $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
| 750 | - //if EVT_ID = 0, then this is a default |
|
| 751 | - if ($prc_chk->get('EVT_ID') == 0) { |
|
| 752 | - //let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
| 753 | - $prc_chk->set('PRC_ID', 0); |
|
| 754 | - } |
|
| 508 | + } else { |
|
| 509 | + //$qst_name = $QST->QST_ID . '-' . str_replace( array( ' ', '-', '.' ), '_', strtolower( $QST->QST_display_text )); |
|
| 510 | + $qst_name = $QST->QST_ID; |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + return $qst_name; |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * Gets all events that are published and have event start time earlier than now and an event end time later than |
|
| 519 | + * now |
|
| 520 | + * |
|
| 521 | + * @access public |
|
| 522 | + * |
|
| 523 | + * @param array $query_params An array of query params to further filter on (note that status and DTT_EVT_start |
|
| 524 | + * and DTT_EVT_end will be overridden) |
|
| 525 | + * @param bool $count whether to return the count or not (default FALSE) |
|
| 526 | + * |
|
| 527 | + * @return array EE_Event objects |
|
| 528 | + */ |
|
| 529 | + public function get_active_events($query_params, $count = false) |
|
| 530 | + { |
|
| 531 | + if (array_key_exists(0, $query_params)) { |
|
| 532 | + $where_params = $query_params[0]; |
|
| 533 | + unset($query_params[0]); |
|
| 534 | + } else { |
|
| 535 | + $where_params = array(); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + //if we have count make sure we don't include group by |
|
| 539 | + if ($count && isset($query_params['group_by'])) { |
|
| 540 | + unset($query_params['group_by']); |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + //let's add specific query_params for active_events - keep in mind this will override any sent status in the query AND any date queries. |
|
| 544 | + $where_params['status'] = array( 'IN', array( 'publish', EEM_Event::sold_out ) ); |
|
| 545 | + //if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
| 546 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 547 | + $where_params['Datetime.DTT_EVT_start******'] = array( |
|
| 548 | + '<', |
|
| 549 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
|
| 550 | + ); |
|
| 551 | + } else { |
|
| 552 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
| 553 | + '<', |
|
| 554 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
|
| 555 | + ); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 559 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
| 560 | + '>', |
|
| 561 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end') |
|
| 562 | + ); |
|
| 563 | + } else { |
|
| 564 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
| 565 | + '>', |
|
| 566 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end') |
|
| 567 | + ); |
|
| 568 | + } |
|
| 569 | + $query_params[0] = $where_params; |
|
| 570 | + |
|
| 571 | + // don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY" |
|
| 572 | + return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + |
|
| 576 | + /** |
|
| 577 | + * get all events that are published and have an event start time later than now |
|
| 578 | + * |
|
| 579 | + * @access public |
|
| 580 | + * |
|
| 581 | + * @param array $query_params An array of query params to further filter on (Note that status and DTT_EVT_start |
|
| 582 | + * will be overridden) |
|
| 583 | + * @param bool $count whether to return the count or not (default FALSE) |
|
| 584 | + * |
|
| 585 | + * @return array EE_Event objects |
|
| 586 | + */ |
|
| 587 | + public function get_upcoming_events($query_params, $count = false) |
|
| 588 | + { |
|
| 589 | + if (array_key_exists(0, $query_params)) { |
|
| 590 | + $where_params = $query_params[0]; |
|
| 591 | + unset($query_params[0]); |
|
| 592 | + } else { |
|
| 593 | + $where_params = array(); |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + //if we have count make sure we don't include group by |
|
| 597 | + if ($count && isset($query_params['group_by'])) { |
|
| 598 | + unset($query_params['group_by']); |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + //let's add specific query_params for active_events - keep in mind this will override any sent status in the query AND any date queries. |
|
| 602 | + $where_params['status'] = array( 'IN', array( 'publish', EEM_Event::sold_out ) ); |
|
| 603 | + //if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
| 604 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 605 | + $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
| 606 | + '>', |
|
| 607 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
|
| 608 | + ); |
|
| 609 | + } else { |
|
| 610 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
| 611 | + '>', |
|
| 612 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
|
| 613 | + ); |
|
| 614 | + } |
|
| 615 | + $query_params[0] = $where_params; |
|
| 616 | + |
|
| 617 | + // don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY" |
|
| 618 | + return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params); |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + |
|
| 622 | + /** |
|
| 623 | + * This only returns events that are expired. They may still be published but all their datetimes have expired. |
|
| 624 | + * |
|
| 625 | + * @access public |
|
| 626 | + * |
|
| 627 | + * @param array $query_params An array of query params to further filter on (note that status and DTT_EVT_end will |
|
| 628 | + * be overridden) |
|
| 629 | + * @param bool $count whether to return the count or not (default FALSE) |
|
| 630 | + * |
|
| 631 | + * @return array EE_Event objects |
|
| 632 | + */ |
|
| 633 | + public function get_expired_events($query_params, $count = false) |
|
| 634 | + { |
|
| 635 | + |
|
| 636 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 637 | + |
|
| 638 | + //if we have count make sure we don't include group by |
|
| 639 | + if ($count && isset($query_params['group_by'])) { |
|
| 640 | + unset($query_params['group_by']); |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + //let's add specific query_params for active_events - keep in mind this will override any sent status in the query AND any date queries. |
|
| 644 | + if (isset($where_params['status'])) { |
|
| 645 | + unset($where_params['status']); |
|
| 646 | + } |
|
| 647 | + $exclude_query = $query_params; |
|
| 648 | + if (isset($exclude_query[0])) { |
|
| 649 | + unset($exclude_query[0]); |
|
| 650 | + } |
|
| 651 | + $exclude_query[0] = array( |
|
| 652 | + 'Datetime.DTT_EVT_end' => array( |
|
| 653 | + '>', |
|
| 654 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end') |
|
| 655 | + ) |
|
| 656 | + ); |
|
| 657 | + //first get all events that have datetimes where its not expired. |
|
| 658 | + $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
| 659 | + $event_ids = array_keys($event_ids); |
|
| 660 | + |
|
| 661 | + //if we have any additional query_params, let's add them to the 'AND' condition |
|
| 662 | + $and_condition = array( |
|
| 663 | + 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
| 664 | + 'EVT_ID' => array('NOT IN', $event_ids) |
|
| 665 | + ); |
|
| 666 | + |
|
| 667 | + if (isset($where_params['OR'])) { |
|
| 668 | + $and_condition['OR'] = $where_params['OR']; |
|
| 669 | + unset($where_params['OR']); |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 673 | + $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
| 674 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
| 675 | + } |
|
| 676 | + |
|
| 677 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 678 | + $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
| 679 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + //merge remaining $where params with the and conditions. |
|
| 683 | + $where_params['AND'] = array_merge($and_condition, $where_params); |
|
| 684 | + $query_params[0] = $where_params; |
|
| 685 | + |
|
| 686 | + // don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY" |
|
| 687 | + return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params); |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * This basically just returns the events that do not have the publish status. |
|
| 693 | + * |
|
| 694 | + * @param array $query_params An array of query params to further filter on (note that status will be |
|
| 695 | + * overwritten) |
|
| 696 | + * @param boolean $count whether to return the count or not (default FALSE) |
|
| 697 | + * |
|
| 698 | + * @return EE_Event[] array of EE_Event objects |
|
| 699 | + */ |
|
| 700 | + public function get_inactive_events($query_params, $count = false) |
|
| 701 | + { |
|
| 702 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 703 | + |
|
| 704 | + //let's add in specific query_params for inactive events. |
|
| 705 | + if (isset($where_params['status'])) { |
|
| 706 | + unset($where_params['status']); |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + //if we have count make sure we don't include group by |
|
| 710 | + if ($count && isset($query_params['group_by'])) { |
|
| 711 | + unset($query_params['group_by']); |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + //if we have any additional query_params, let's add them to the 'AND' condition |
|
| 715 | + $where_params['AND']['status'] = array('!=', 'publish'); |
|
| 716 | + |
|
| 717 | + if (isset($where_params['OR'])) { |
|
| 718 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
| 719 | + unset($where_params['OR']); |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 723 | + $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
| 724 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 728 | + $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
| 729 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + $query_params[0] = $where_params; |
|
| 733 | + |
|
| 734 | + // don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY" |
|
| 735 | + return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params); |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + |
|
| 739 | + /** |
|
| 740 | + * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
| 741 | + * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
| 742 | + * attached to the event. See parent for param descriptions |
|
| 743 | + */ |
|
| 744 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
| 745 | + { |
|
| 746 | + |
|
| 747 | + if ($relationName == 'Price') { |
|
| 748 | + //let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
| 749 | + $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
| 750 | + //if EVT_ID = 0, then this is a default |
|
| 751 | + if ($prc_chk->get('EVT_ID') == 0) { |
|
| 752 | + //let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
| 753 | + $prc_chk->set('PRC_ID', 0); |
|
| 754 | + } |
|
| 755 | 755 | |
| 756 | - //run parent |
|
| 757 | - return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
| 758 | - } |
|
| 756 | + //run parent |
|
| 757 | + return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
| 758 | + } |
|
| 759 | 759 | |
| 760 | - //otherwise carry on as normal |
|
| 761 | - return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
| 762 | - } |
|
| 760 | + //otherwise carry on as normal |
|
| 761 | + return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
| 762 | + } |
|
| 763 | 763 | |
| 764 | 764 | |
| 765 | 765 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | 2 | exit('No direct script access allowed'); |
| 3 | 3 | } |
| 4 | -require_once(EE_MODELS . 'EEM_CPT_Base.model.php'); |
|
| 4 | +require_once(EE_MODELS.'EEM_CPT_Base.model.php'); |
|
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | if ($qst->is_system_question()) { |
| 409 | 409 | continue; |
| 410 | 410 | } |
| 411 | - $answer = EEM_Answer::instance()->get_one(array( |
|
| 411 | + $answer = EEM_Answer::instance()->get_one(array( |
|
| 412 | 412 | array( |
| 413 | 413 | 'QST_ID' => $qst->ID(), |
| 414 | 414 | 'REG_ID' => $registration->ID() |
@@ -417,13 +417,13 @@ discard block |
||
| 417 | 417 | $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
| 418 | 418 | $qst_name = $qstn_id = $qst->ID(); |
| 419 | 419 | $ans_id = $answer->ID(); |
| 420 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
| 420 | + $qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']'; |
|
| 421 | 421 | $input_name = ''; |
| 422 | 422 | $input_id = sanitize_key($qst->display_text()); |
| 423 | 423 | $input_class = ''; |
| 424 | 424 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
| 425 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' . $input_name . $qst_name; |
|
| 426 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
| 425 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'.$input_name.$qst_name; |
|
| 426 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id; |
|
| 427 | 427 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
| 428 | 428 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
| 429 | 429 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
@@ -541,7 +541,7 @@ discard block |
||
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | //let's add specific query_params for active_events - keep in mind this will override any sent status in the query AND any date queries. |
| 544 | - $where_params['status'] = array( 'IN', array( 'publish', EEM_Event::sold_out ) ); |
|
| 544 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 545 | 545 | //if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
| 546 | 546 | if (isset($where_params['Datetime.DTT_EVT_start'])) { |
| 547 | 547 | $where_params['Datetime.DTT_EVT_start******'] = array( |
@@ -599,7 +599,7 @@ discard block |
||
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | //let's add specific query_params for active_events - keep in mind this will override any sent status in the query AND any date queries. |
| 602 | - $where_params['status'] = array( 'IN', array( 'publish', EEM_Event::sold_out ) ); |
|
| 602 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 603 | 603 | //if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
| 604 | 604 | if (isset($where_params['Datetime.DTT_EVT_start'])) { |
| 605 | 605 | $where_params['Datetime.DTT_EVT_start*****'] = array( |