@@ -18,14 +18,14 @@ discard block |
||
| 18 | 18 | <input type="hidden" id="ee-msg-current-context" name="MTP_context" value="<?php echo esc_attr($context); ?>" /> |
| 19 | 19 | <!-- if this is not a global template then let's show the name and description fields --> |
| 20 | 20 | <?php |
| 21 | - if (! $MTP->is_global()) : ?> |
|
| 21 | + if (! $MTP->is_global()) : ?> |
|
| 22 | 22 | <div class="non-global-mtp-fields"> |
| 23 | 23 | <div class="ee-info-box"> |
| 24 | 24 | <p> |
| 25 | 25 | <?php esc_html_e( |
| 26 | - 'This is a custom template. Custom Templates have an editable name and description to help you differentiate between templates.', |
|
| 27 | - 'event_espresso' |
|
| 28 | - ); ?> |
|
| 26 | + 'This is a custom template. Custom Templates have an editable name and description to help you differentiate between templates.', |
|
| 27 | + 'event_espresso' |
|
| 28 | + ); ?> |
|
| 29 | 29 | </p> |
| 30 | 30 | </div> |
| 31 | 31 | <div id="titlediv"> |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - else : |
|
| 60 | - ?> |
|
| 59 | + else : |
|
| 60 | + ?> |
|
| 61 | 61 | <input type="hidden" name="ee_msg_non_global_fields[MTP_name]" value="<?php echo esc_attr($MTP->name()); ?>"> |
| 62 | 62 | <input type="hidden" |
| 63 | 63 | name="ee_msg_non_global_fields[MTP_description]" |
@@ -66,18 +66,18 @@ discard block |
||
| 66 | 66 | <?php endif; ?> |
| 67 | 67 | <!-- we need to loop through the template_fields so we know our structure --> |
| 68 | 68 | <?php |
| 69 | - if (isset($template_fields) && ! empty($template_fields) && ! is_wp_error($template_fields)) { |
|
| 70 | - echo $template_fields; // already escaped |
|
| 71 | - } else { |
|
| 72 | - ?> |
|
| 69 | + if (isset($template_fields) && ! empty($template_fields) && ! is_wp_error($template_fields)) { |
|
| 70 | + echo $template_fields; // already escaped |
|
| 71 | + } else { |
|
| 72 | + ?> |
|
| 73 | 73 | <p> |
| 74 | 74 | <?php esc_html_e( |
| 75 | - 'Something has gone wrong, there are no template fields to output.', |
|
| 76 | - 'event_espresso' |
|
| 77 | - ); ?> |
|
| 75 | + 'Something has gone wrong, there are no template fields to output.', |
|
| 76 | + 'event_espresso' |
|
| 77 | + ); ?> |
|
| 78 | 78 | </p> |
| 79 | 79 | <?php |
| 80 | - } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - ?> |
|
| 82 | + ?> |
|
| 83 | 83 | </div> <!-- end #admin-primary-mbox-dv --> |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | <input type="hidden" id="ee-msg-current-context" name="MTP_context" value="<?php echo esc_attr($context); ?>" /> |
| 19 | 19 | <!-- if this is not a global template then let's show the name and description fields --> |
| 20 | 20 | <?php |
| 21 | - if (! $MTP->is_global()) : ?> |
|
| 21 | + if ( ! $MTP->is_global()) : ?> |
|
| 22 | 22 | <div class="non-global-mtp-fields"> |
| 23 | 23 | <div class="ee-info-box"> |
| 24 | 24 | <p> |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * @var string $action_message |
| 9 | 9 | * @var string $edit_message_template_form_url |
| 10 | 10 | */ |
| 11 | -$header = $event_name ? esc_html($event_name . ' Custom Template') : ''; |
|
| 11 | +$header = $event_name ? esc_html($event_name.' Custom Template') : ''; |
|
| 12 | 12 | ?> |
| 13 | 13 | |
| 14 | 14 | <div id="admin-primary-mbox-dv" class="admin-primary-mbox-dv"> |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | </select> |
| 50 | 50 | |
| 51 | 51 | <!-- events if we don't have an EVENT_ID --> |
| 52 | - <?php if (! empty($active_events)) : ?> |
|
| 52 | + <?php if ( ! empty($active_events)) : ?> |
|
| 53 | 53 | <label for="EVT_ID_select"><?php esc_html_e('Select Event', 'event_espresso'); ?></label> |
| 54 | 54 | <select name="EVT_ID" id="EVT_ID_select"> |
| 55 | 55 | <?php foreach ($active_events as $event) : ?> |
@@ -16,98 +16,98 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class CheckinStatusDashicon |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * @var int $checkin_status |
|
| 21 | - */ |
|
| 22 | - private $checkin_status; |
|
| 19 | + /** |
|
| 20 | + * @var int $checkin_status |
|
| 21 | + */ |
|
| 22 | + private $checkin_status; |
|
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * CheckinStatusDashicon constructor. |
|
| 27 | - * |
|
| 28 | - * @param int $checkin_status |
|
| 29 | - */ |
|
| 30 | - public function __construct($checkin_status = EE_Checkin::status_checked_never) |
|
| 31 | - { |
|
| 32 | - $this->checkin_status = $checkin_status; |
|
| 33 | - } |
|
| 25 | + /** |
|
| 26 | + * CheckinStatusDashicon constructor. |
|
| 27 | + * |
|
| 28 | + * @param int $checkin_status |
|
| 29 | + */ |
|
| 30 | + public function __construct($checkin_status = EE_Checkin::status_checked_never) |
|
| 31 | + { |
|
| 32 | + $this->checkin_status = $checkin_status; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param EE_Checkin $checkin |
|
| 38 | - * @return CheckinStatusDashicon |
|
| 39 | - * @throws EE_Error |
|
| 40 | - */ |
|
| 41 | - public static function fromCheckin(EE_Checkin $checkin) |
|
| 42 | - { |
|
| 43 | - return new CheckinStatusDashicon( |
|
| 44 | - $checkin->status() |
|
| 45 | - ? EE_Checkin::status_checked_in |
|
| 46 | - : EE_Checkin::status_checked_out |
|
| 47 | - ); |
|
| 48 | - } |
|
| 36 | + /** |
|
| 37 | + * @param EE_Checkin $checkin |
|
| 38 | + * @return CheckinStatusDashicon |
|
| 39 | + * @throws EE_Error |
|
| 40 | + */ |
|
| 41 | + public static function fromCheckin(EE_Checkin $checkin) |
|
| 42 | + { |
|
| 43 | + return new CheckinStatusDashicon( |
|
| 44 | + $checkin->status() |
|
| 45 | + ? EE_Checkin::status_checked_in |
|
| 46 | + : EE_Checkin::status_checked_out |
|
| 47 | + ); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param EE_Registration $registration |
|
| 53 | - * @param EE_Datetime $datetime |
|
| 54 | - * @return CheckinStatusDashicon |
|
| 55 | - * @throws EE_Error |
|
| 56 | - */ |
|
| 57 | - public static function fromRegistrationAndDatetime(EE_Registration $registration, EE_Datetime $datetime) |
|
| 58 | - { |
|
| 59 | - return new CheckinStatusDashicon( |
|
| 60 | - $registration->check_in_status_for_datetime( |
|
| 61 | - $datetime->ID() |
|
| 62 | - ) |
|
| 63 | - ); |
|
| 64 | - } |
|
| 51 | + /** |
|
| 52 | + * @param EE_Registration $registration |
|
| 53 | + * @param EE_Datetime $datetime |
|
| 54 | + * @return CheckinStatusDashicon |
|
| 55 | + * @throws EE_Error |
|
| 56 | + */ |
|
| 57 | + public static function fromRegistrationAndDatetime(EE_Registration $registration, EE_Datetime $datetime) |
|
| 58 | + { |
|
| 59 | + return new CheckinStatusDashicon( |
|
| 60 | + $registration->check_in_status_for_datetime( |
|
| 61 | + $datetime->ID() |
|
| 62 | + ) |
|
| 63 | + ); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @param EE_Registration $registration |
|
| 69 | - * @param int $DTT_ID |
|
| 70 | - * @return CheckinStatusDashicon |
|
| 71 | - * @throws EE_Error |
|
| 72 | - */ |
|
| 73 | - public static function fromRegistrationAndDatetimeId(EE_Registration $registration, $DTT_ID = 0) |
|
| 74 | - { |
|
| 75 | - return new CheckinStatusDashicon( |
|
| 76 | - $registration->check_in_status_for_datetime( |
|
| 77 | - absint($DTT_ID) |
|
| 78 | - ) |
|
| 79 | - ); |
|
| 80 | - } |
|
| 67 | + /** |
|
| 68 | + * @param EE_Registration $registration |
|
| 69 | + * @param int $DTT_ID |
|
| 70 | + * @return CheckinStatusDashicon |
|
| 71 | + * @throws EE_Error |
|
| 72 | + */ |
|
| 73 | + public static function fromRegistrationAndDatetimeId(EE_Registration $registration, $DTT_ID = 0) |
|
| 74 | + { |
|
| 75 | + return new CheckinStatusDashicon( |
|
| 76 | + $registration->check_in_status_for_datetime( |
|
| 77 | + absint($DTT_ID) |
|
| 78 | + ) |
|
| 79 | + ); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Will return the correct set of dashicon css classes for the set checkin status |
|
| 84 | - * |
|
| 85 | - * @return string |
|
| 86 | - */ |
|
| 87 | - public function cssClasses() |
|
| 88 | - { |
|
| 89 | - if ($this->checkin_status === EE_Checkin::status_checked_in) { |
|
| 90 | - return "dashicons dashicons-yes-alt checkin-icons checkedin-status-{$this->checkin_status}"; |
|
| 91 | - } |
|
| 92 | - if ($this->checkin_status === EE_Checkin::status_checked_out) { |
|
| 93 | - return "dashicons dashicons-marker checkin-icons checkedin-status-{$this->checkin_status}"; |
|
| 94 | - } |
|
| 95 | - return "dashicons dashicons-no checkin-icons checkedin-status-{$this->checkin_status}"; |
|
| 96 | - } |
|
| 82 | + /** |
|
| 83 | + * Will return the correct set of dashicon css classes for the set checkin status |
|
| 84 | + * |
|
| 85 | + * @return string |
|
| 86 | + */ |
|
| 87 | + public function cssClasses() |
|
| 88 | + { |
|
| 89 | + if ($this->checkin_status === EE_Checkin::status_checked_in) { |
|
| 90 | + return "dashicons dashicons-yes-alt checkin-icons checkedin-status-{$this->checkin_status}"; |
|
| 91 | + } |
|
| 92 | + if ($this->checkin_status === EE_Checkin::status_checked_out) { |
|
| 93 | + return "dashicons dashicons-marker checkin-icons checkedin-status-{$this->checkin_status}"; |
|
| 94 | + } |
|
| 95 | + return "dashicons dashicons-no checkin-icons checkedin-status-{$this->checkin_status}"; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * returns a description for the Checkin Status Dashicon that can be used in List Table Legends |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - public function legendLabel() |
|
| 104 | - { |
|
| 105 | - if ($this->checkin_status === EE_Checkin::status_checked_in) { |
|
| 106 | - return esc_html__('This Registrant has been Checked In', 'event_espresso'); |
|
| 107 | - } |
|
| 108 | - if ($this->checkin_status === EE_Checkin::status_checked_out) { |
|
| 109 | - return esc_html__('This Registrant has been Checked Out', 'event_espresso'); |
|
| 110 | - } |
|
| 111 | - return esc_html__('No Check-in Record has been Created for this Registrant', 'event_espresso'); |
|
| 112 | - } |
|
| 98 | + /** |
|
| 99 | + * returns a description for the Checkin Status Dashicon that can be used in List Table Legends |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + public function legendLabel() |
|
| 104 | + { |
|
| 105 | + if ($this->checkin_status === EE_Checkin::status_checked_in) { |
|
| 106 | + return esc_html__('This Registrant has been Checked In', 'event_espresso'); |
|
| 107 | + } |
|
| 108 | + if ($this->checkin_status === EE_Checkin::status_checked_out) { |
|
| 109 | + return esc_html__('This Registrant has been Checked Out', 'event_espresso'); |
|
| 110 | + } |
|
| 111 | + return esc_html__('No Check-in Record has been Created for this Registrant', 'event_espresso'); |
|
| 112 | + } |
|
| 113 | 113 | } |
@@ -16,1533 +16,1533 @@ |
||
| 16 | 16 | class EE_Event extends EE_CPT_Base implements EEI_Line_Item_Object, EEI_Admin_Links, EEI_Has_Icon, EEI_Event |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * cached value for the the logical active status for the event |
|
| 21 | - * |
|
| 22 | - * @see get_active_status() |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - protected $_active_status = ''; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * This is just used for caching the Primary Datetime for the Event on initial retrieval |
|
| 29 | - * |
|
| 30 | - * @var EE_Datetime |
|
| 31 | - */ |
|
| 32 | - protected $_Primary_Datetime; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var EventSpacesCalculator $available_spaces_calculator |
|
| 36 | - */ |
|
| 37 | - protected $available_spaces_calculator; |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @param array $props_n_values incoming values |
|
| 42 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 43 | - * used.) |
|
| 44 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 45 | - * date_format and the second value is the time format |
|
| 46 | - * @return EE_Event |
|
| 47 | - * @throws EE_Error |
|
| 48 | - * @throws ReflectionException |
|
| 49 | - */ |
|
| 50 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 51 | - { |
|
| 52 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 53 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param array $props_n_values incoming values from the database |
|
| 59 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 60 | - * the website will be used. |
|
| 61 | - * @return EE_Event |
|
| 62 | - * @throws EE_Error |
|
| 63 | - * @throws ReflectionException |
|
| 64 | - */ |
|
| 65 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 66 | - { |
|
| 67 | - return new self($props_n_values, true, $timezone); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @return EventSpacesCalculator |
|
| 73 | - * @throws \EE_Error |
|
| 74 | - */ |
|
| 75 | - public function getAvailableSpacesCalculator() |
|
| 76 | - { |
|
| 77 | - if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
| 78 | - $this->available_spaces_calculator = new EventSpacesCalculator($this); |
|
| 79 | - } |
|
| 80 | - return $this->available_spaces_calculator; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods |
|
| 86 | - * |
|
| 87 | - * @param string $field_name |
|
| 88 | - * @param mixed $field_value |
|
| 89 | - * @param bool $use_default |
|
| 90 | - * @throws EE_Error |
|
| 91 | - * @throws ReflectionException |
|
| 92 | - */ |
|
| 93 | - public function set($field_name, $field_value, $use_default = false) |
|
| 94 | - { |
|
| 95 | - switch ($field_name) { |
|
| 96 | - case 'status': |
|
| 97 | - $this->set_status($field_value, $use_default); |
|
| 98 | - break; |
|
| 99 | - default: |
|
| 100 | - parent::set($field_name, $field_value, $use_default); |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * set_status |
|
| 107 | - * Checks if event status is being changed to SOLD OUT |
|
| 108 | - * and updates event meta data with previous event status |
|
| 109 | - * so that we can revert things if/when the event is no longer sold out |
|
| 110 | - * |
|
| 111 | - * @access public |
|
| 112 | - * @param string $new_status |
|
| 113 | - * @param bool $use_default |
|
| 114 | - * @return void |
|
| 115 | - * @throws EE_Error |
|
| 116 | - * @throws ReflectionException |
|
| 117 | - */ |
|
| 118 | - public function set_status($new_status = null, $use_default = false) |
|
| 119 | - { |
|
| 120 | - // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave |
|
| 121 | - if (empty($new_status) && ! $use_default) { |
|
| 122 | - return; |
|
| 123 | - } |
|
| 124 | - // get current Event status |
|
| 125 | - $old_status = $this->status(); |
|
| 126 | - // if status has changed |
|
| 127 | - if ($old_status !== $new_status) { |
|
| 128 | - // TO sold_out |
|
| 129 | - if ($new_status === EEM_Event::sold_out) { |
|
| 130 | - // save the previous event status so that we can revert if the event is no longer sold out |
|
| 131 | - $this->add_post_meta('_previous_event_status', $old_status); |
|
| 132 | - do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status); |
|
| 133 | - // OR FROM sold_out |
|
| 134 | - } elseif ($old_status === EEM_Event::sold_out) { |
|
| 135 | - $this->delete_post_meta('_previous_event_status'); |
|
| 136 | - do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status); |
|
| 137 | - } |
|
| 138 | - // clear out the active status so that it gets reset the next time it is requested |
|
| 139 | - $this->_active_status = null; |
|
| 140 | - // update status |
|
| 141 | - parent::set('status', $new_status, $use_default); |
|
| 142 | - do_action('AHEE__EE_Event__set_status__after_update', $this); |
|
| 143 | - return; |
|
| 144 | - } |
|
| 145 | - // even though the old value matches the new value, it's still good to |
|
| 146 | - // allow the parent set method to have a say |
|
| 147 | - parent::set('status', $new_status, $use_default); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Gets all the datetimes for this event |
|
| 153 | - * |
|
| 154 | - * @param array $query_params @see |
|
| 155 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 156 | - * @return EE_Base_Class[]|EE_Datetime[] |
|
| 157 | - * @throws EE_Error |
|
| 158 | - * @throws ReflectionException |
|
| 159 | - */ |
|
| 160 | - public function datetimes($query_params = array()) |
|
| 161 | - { |
|
| 162 | - return $this->get_many_related('Datetime', $query_params); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order |
|
| 168 | - * |
|
| 169 | - * @return EE_Base_Class[]|EE_Datetime[] |
|
| 170 | - * @throws EE_Error |
|
| 171 | - * @throws ReflectionException |
|
| 172 | - */ |
|
| 173 | - public function datetimes_in_chronological_order() |
|
| 174 | - { |
|
| 175 | - return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Gets all the datetimes for this event, ordered by the DTT_order on the datetime. |
|
| 181 | - * @darren, we should probably UNSET timezone on the EEM_Datetime model |
|
| 182 | - * after running our query, so that this timezone isn't set for EVERY query |
|
| 183 | - * on EEM_Datetime for the rest of the request, no? |
|
| 184 | - * |
|
| 185 | - * @param boolean $show_expired whether or not to include expired events |
|
| 186 | - * @param boolean $show_deleted whether or not to include deleted events |
|
| 187 | - * @param null $limit |
|
| 188 | - * @return EE_Datetime[] |
|
| 189 | - * @throws EE_Error |
|
| 190 | - * @throws ReflectionException |
|
| 191 | - */ |
|
| 192 | - public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null) |
|
| 193 | - { |
|
| 194 | - return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order( |
|
| 195 | - $this->ID(), |
|
| 196 | - $show_expired, |
|
| 197 | - $show_deleted, |
|
| 198 | - $limit |
|
| 199 | - ); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Returns one related datetime. Mostly only used by some legacy code. |
|
| 205 | - * |
|
| 206 | - * @return EE_Base_Class|EE_Datetime |
|
| 207 | - * @throws EE_Error |
|
| 208 | - * @throws ReflectionException |
|
| 209 | - */ |
|
| 210 | - public function first_datetime() |
|
| 211 | - { |
|
| 212 | - return $this->get_first_related('Datetime'); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Returns the 'primary' datetime for the event |
|
| 218 | - * |
|
| 219 | - * @param bool $try_to_exclude_expired |
|
| 220 | - * @param bool $try_to_exclude_deleted |
|
| 221 | - * @return EE_Datetime |
|
| 222 | - * @throws EE_Error |
|
| 223 | - * @throws ReflectionException |
|
| 224 | - */ |
|
| 225 | - public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
|
| 226 | - { |
|
| 227 | - if (! empty($this->_Primary_Datetime)) { |
|
| 228 | - return $this->_Primary_Datetime; |
|
| 229 | - } |
|
| 230 | - $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
|
| 231 | - $this->ID(), |
|
| 232 | - $try_to_exclude_expired, |
|
| 233 | - $try_to_exclude_deleted |
|
| 234 | - ); |
|
| 235 | - return $this->_Primary_Datetime; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Gets all the tickets available for purchase of this event |
|
| 241 | - * |
|
| 242 | - * @param array $query_params @see |
|
| 243 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 244 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
| 245 | - * @throws EE_Error |
|
| 246 | - * @throws ReflectionException |
|
| 247 | - */ |
|
| 248 | - public function tickets($query_params = array()) |
|
| 249 | - { |
|
| 250 | - // first get all datetimes |
|
| 251 | - $datetimes = $this->datetimes_ordered(); |
|
| 252 | - if (! $datetimes) { |
|
| 253 | - return array(); |
|
| 254 | - } |
|
| 255 | - $datetime_ids = array(); |
|
| 256 | - foreach ($datetimes as $datetime) { |
|
| 257 | - $datetime_ids[] = $datetime->ID(); |
|
| 258 | - } |
|
| 259 | - $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids)); |
|
| 260 | - // if incoming $query_params has where conditions let's merge but not override existing. |
|
| 261 | - if (is_array($query_params) && isset($query_params[0])) { |
|
| 262 | - $where_params = array_merge($query_params[0], $where_params); |
|
| 263 | - unset($query_params[0]); |
|
| 264 | - } |
|
| 265 | - // now add $where_params to $query_params |
|
| 266 | - $query_params[0] = $where_params; |
|
| 267 | - return EEM_Ticket::instance()->get_all($query_params); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * get all unexpired untrashed tickets |
|
| 273 | - * |
|
| 274 | - * @return EE_Ticket[] |
|
| 275 | - * @throws EE_Error |
|
| 276 | - */ |
|
| 277 | - public function active_tickets() |
|
| 278 | - { |
|
| 279 | - return $this->tickets( |
|
| 280 | - array( |
|
| 281 | - array( |
|
| 282 | - 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 283 | - 'TKT_deleted' => false, |
|
| 284 | - ), |
|
| 285 | - ) |
|
| 286 | - ); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * @return bool |
|
| 292 | - * @throws EE_Error |
|
| 293 | - * @throws ReflectionException |
|
| 294 | - */ |
|
| 295 | - public function additional_limit() |
|
| 296 | - { |
|
| 297 | - return $this->get('EVT_additional_limit'); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * @return bool |
|
| 303 | - * @throws EE_Error |
|
| 304 | - * @throws ReflectionException |
|
| 305 | - */ |
|
| 306 | - public function allow_overflow() |
|
| 307 | - { |
|
| 308 | - return $this->get('EVT_allow_overflow'); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * @return bool |
|
| 314 | - * @throws EE_Error |
|
| 315 | - * @throws ReflectionException |
|
| 316 | - */ |
|
| 317 | - public function created() |
|
| 318 | - { |
|
| 319 | - return $this->get('EVT_created'); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * @return bool |
|
| 325 | - * @throws EE_Error |
|
| 326 | - * @throws ReflectionException |
|
| 327 | - */ |
|
| 328 | - public function description() |
|
| 329 | - { |
|
| 330 | - return $this->get('EVT_desc'); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * Runs do_shortcode and wpautop on the description |
|
| 336 | - * |
|
| 337 | - * @return string of html |
|
| 338 | - * @throws EE_Error |
|
| 339 | - * @throws ReflectionException |
|
| 340 | - */ |
|
| 341 | - public function description_filtered() |
|
| 342 | - { |
|
| 343 | - return $this->get_pretty('EVT_desc'); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * @return bool |
|
| 349 | - * @throws EE_Error |
|
| 350 | - * @throws ReflectionException |
|
| 351 | - */ |
|
| 352 | - public function display_description() |
|
| 353 | - { |
|
| 354 | - return $this->get('EVT_display_desc'); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * @return bool |
|
| 360 | - * @throws EE_Error |
|
| 361 | - * @throws ReflectionException |
|
| 362 | - */ |
|
| 363 | - public function display_ticket_selector() |
|
| 364 | - { |
|
| 365 | - return (bool) $this->get('EVT_display_ticket_selector'); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * @return string |
|
| 371 | - * @throws EE_Error |
|
| 372 | - * @throws ReflectionException |
|
| 373 | - */ |
|
| 374 | - public function external_url() |
|
| 375 | - { |
|
| 376 | - return $this->get('EVT_external_URL'); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * @return bool |
|
| 382 | - * @throws EE_Error |
|
| 383 | - * @throws ReflectionException |
|
| 384 | - */ |
|
| 385 | - public function member_only() |
|
| 386 | - { |
|
| 387 | - return $this->get('EVT_member_only'); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * @return bool |
|
| 393 | - * @throws EE_Error |
|
| 394 | - * @throws ReflectionException |
|
| 395 | - */ |
|
| 396 | - public function phone() |
|
| 397 | - { |
|
| 398 | - return $this->get('EVT_phone'); |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * @return bool |
|
| 404 | - * @throws EE_Error |
|
| 405 | - * @throws ReflectionException |
|
| 406 | - */ |
|
| 407 | - public function modified() |
|
| 408 | - { |
|
| 409 | - return $this->get('EVT_modified'); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * @return bool |
|
| 415 | - * @throws EE_Error |
|
| 416 | - * @throws ReflectionException |
|
| 417 | - */ |
|
| 418 | - public function name() |
|
| 419 | - { |
|
| 420 | - return $this->get('EVT_name'); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * @return bool |
|
| 426 | - * @throws EE_Error |
|
| 427 | - * @throws ReflectionException |
|
| 428 | - */ |
|
| 429 | - public function order() |
|
| 430 | - { |
|
| 431 | - return $this->get('EVT_order'); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * @return bool|string |
|
| 437 | - * @throws EE_Error |
|
| 438 | - * @throws ReflectionException |
|
| 439 | - */ |
|
| 440 | - public function default_registration_status() |
|
| 441 | - { |
|
| 442 | - $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
| 443 | - return ! empty($event_default_registration_status) |
|
| 444 | - ? $event_default_registration_status |
|
| 445 | - : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * @param int $num_words |
|
| 451 | - * @param null $more |
|
| 452 | - * @param bool $not_full_desc |
|
| 453 | - * @return bool|string |
|
| 454 | - * @throws EE_Error |
|
| 455 | - * @throws ReflectionException |
|
| 456 | - */ |
|
| 457 | - public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
|
| 458 | - { |
|
| 459 | - $short_desc = $this->get('EVT_short_desc'); |
|
| 460 | - if (! empty($short_desc) || $not_full_desc) { |
|
| 461 | - return $short_desc; |
|
| 462 | - } |
|
| 463 | - $full_desc = $this->get('EVT_desc'); |
|
| 464 | - return wp_trim_words($full_desc, $num_words, $more); |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * @return bool |
|
| 470 | - * @throws EE_Error |
|
| 471 | - * @throws ReflectionException |
|
| 472 | - */ |
|
| 473 | - public function slug() |
|
| 474 | - { |
|
| 475 | - return $this->get('EVT_slug'); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * @return bool |
|
| 481 | - * @throws EE_Error |
|
| 482 | - * @throws ReflectionException |
|
| 483 | - */ |
|
| 484 | - public function timezone_string() |
|
| 485 | - { |
|
| 486 | - return $this->get('EVT_timezone_string'); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * @return bool |
|
| 492 | - * @throws EE_Error |
|
| 493 | - * @throws ReflectionException |
|
| 494 | - */ |
|
| 495 | - public function visible_on() |
|
| 496 | - { |
|
| 497 | - return $this->get('EVT_visible_on'); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * @return int |
|
| 503 | - * @throws EE_Error |
|
| 504 | - * @throws ReflectionException |
|
| 505 | - */ |
|
| 506 | - public function wp_user() |
|
| 507 | - { |
|
| 508 | - return $this->get('EVT_wp_user'); |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * @return bool |
|
| 514 | - * @throws EE_Error |
|
| 515 | - * @throws ReflectionException |
|
| 516 | - */ |
|
| 517 | - public function donations() |
|
| 518 | - { |
|
| 519 | - return $this->get('EVT_donations'); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * @param $limit |
|
| 525 | - * @throws EE_Error |
|
| 526 | - */ |
|
| 527 | - public function set_additional_limit($limit) |
|
| 528 | - { |
|
| 529 | - $this->set('EVT_additional_limit', $limit); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * @param $created |
|
| 535 | - * @throws EE_Error |
|
| 536 | - */ |
|
| 537 | - public function set_created($created) |
|
| 538 | - { |
|
| 539 | - $this->set('EVT_created', $created); |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * @param $desc |
|
| 545 | - * @throws EE_Error |
|
| 546 | - */ |
|
| 547 | - public function set_description($desc) |
|
| 548 | - { |
|
| 549 | - $this->set('EVT_desc', $desc); |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - |
|
| 553 | - /** |
|
| 554 | - * @param $display_desc |
|
| 555 | - * @throws EE_Error |
|
| 556 | - */ |
|
| 557 | - public function set_display_description($display_desc) |
|
| 558 | - { |
|
| 559 | - $this->set('EVT_display_desc', $display_desc); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - |
|
| 563 | - /** |
|
| 564 | - * @param $display_ticket_selector |
|
| 565 | - * @throws EE_Error |
|
| 566 | - */ |
|
| 567 | - public function set_display_ticket_selector($display_ticket_selector) |
|
| 568 | - { |
|
| 569 | - $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - |
|
| 573 | - /** |
|
| 574 | - * @param $external_url |
|
| 575 | - * @throws EE_Error |
|
| 576 | - */ |
|
| 577 | - public function set_external_url($external_url) |
|
| 578 | - { |
|
| 579 | - $this->set('EVT_external_URL', $external_url); |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * @param $member_only |
|
| 585 | - * @throws EE_Error |
|
| 586 | - */ |
|
| 587 | - public function set_member_only($member_only) |
|
| 588 | - { |
|
| 589 | - $this->set('EVT_member_only', $member_only); |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - |
|
| 593 | - /** |
|
| 594 | - * @param $event_phone |
|
| 595 | - * @throws EE_Error |
|
| 596 | - */ |
|
| 597 | - public function set_event_phone($event_phone) |
|
| 598 | - { |
|
| 599 | - $this->set('EVT_phone', $event_phone); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - /** |
|
| 604 | - * @param $modified |
|
| 605 | - * @throws EE_Error |
|
| 606 | - */ |
|
| 607 | - public function set_modified($modified) |
|
| 608 | - { |
|
| 609 | - $this->set('EVT_modified', $modified); |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - |
|
| 613 | - /** |
|
| 614 | - * @param $name |
|
| 615 | - * @throws EE_Error |
|
| 616 | - */ |
|
| 617 | - public function set_name($name) |
|
| 618 | - { |
|
| 619 | - $this->set('EVT_name', $name); |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - |
|
| 623 | - /** |
|
| 624 | - * @param $order |
|
| 625 | - * @throws EE_Error |
|
| 626 | - */ |
|
| 627 | - public function set_order($order) |
|
| 628 | - { |
|
| 629 | - $this->set('EVT_order', $order); |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - |
|
| 633 | - /** |
|
| 634 | - * @param $short_desc |
|
| 635 | - * @throws EE_Error |
|
| 636 | - */ |
|
| 637 | - public function set_short_description($short_desc) |
|
| 638 | - { |
|
| 639 | - $this->set('EVT_short_desc', $short_desc); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - |
|
| 643 | - /** |
|
| 644 | - * @param $slug |
|
| 645 | - * @throws EE_Error |
|
| 646 | - */ |
|
| 647 | - public function set_slug($slug) |
|
| 648 | - { |
|
| 649 | - $this->set('EVT_slug', $slug); |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * @param $timezone_string |
|
| 655 | - * @throws EE_Error |
|
| 656 | - */ |
|
| 657 | - public function set_timezone_string($timezone_string) |
|
| 658 | - { |
|
| 659 | - $this->set('EVT_timezone_string', $timezone_string); |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * @param $visible_on |
|
| 665 | - * @throws EE_Error |
|
| 666 | - */ |
|
| 667 | - public function set_visible_on($visible_on) |
|
| 668 | - { |
|
| 669 | - $this->set('EVT_visible_on', $visible_on); |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * @param $wp_user |
|
| 675 | - * @throws EE_Error |
|
| 676 | - */ |
|
| 677 | - public function set_wp_user($wp_user) |
|
| 678 | - { |
|
| 679 | - $this->set('EVT_wp_user', $wp_user); |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * @param $default_registration_status |
|
| 685 | - * @throws EE_Error |
|
| 686 | - */ |
|
| 687 | - public function set_default_registration_status($default_registration_status) |
|
| 688 | - { |
|
| 689 | - $this->set('EVT_default_registration_status', $default_registration_status); |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - /** |
|
| 694 | - * @param $donations |
|
| 695 | - * @throws EE_Error |
|
| 696 | - */ |
|
| 697 | - public function set_donations($donations) |
|
| 698 | - { |
|
| 699 | - $this->set('EVT_donations', $donations); |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - |
|
| 703 | - /** |
|
| 704 | - * Adds a venue to this event |
|
| 705 | - * |
|
| 706 | - * @param int|EE_Venue /int $venue_id_or_obj |
|
| 707 | - * @return EE_Base_Class|EE_Venue |
|
| 708 | - * @throws EE_Error |
|
| 709 | - * @throws ReflectionException |
|
| 710 | - */ |
|
| 711 | - public function add_venue($venue_id_or_obj): EE_Venue |
|
| 712 | - { |
|
| 713 | - return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - |
|
| 717 | - /** |
|
| 718 | - * Removes a venue from the event |
|
| 719 | - * |
|
| 720 | - * @param EE_Venue /int $venue_id_or_obj |
|
| 721 | - * @return EE_Base_Class|EE_Venue |
|
| 722 | - * @throws EE_Error |
|
| 723 | - * @throws ReflectionException |
|
| 724 | - */ |
|
| 725 | - public function remove_venue($venue_id_or_obj): EE_Venue |
|
| 726 | - { |
|
| 727 | - $venue_id_or_obj = ! empty($venue_id_or_obj) ? $venue_id_or_obj : $this->venue(); |
|
| 728 | - return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - |
|
| 732 | - /** |
|
| 733 | - * Gets the venue related to the event. May provide additional $query_params if desired |
|
| 734 | - * |
|
| 735 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 736 | - * @return int |
|
| 737 | - * @throws EE_Error |
|
| 738 | - * @throws ReflectionException |
|
| 739 | - */ |
|
| 740 | - public function venue_ID(array $query_params = array()): int |
|
| 741 | - { |
|
| 742 | - $venue = $this->get_first_related('Venue', $query_params); |
|
| 743 | - return $venue instanceof EE_Venue ? $venue->ID() : 0; |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - |
|
| 747 | - /** |
|
| 748 | - * Gets the venue related to the event. May provide additional $query_params if desired |
|
| 749 | - * |
|
| 750 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 751 | - * @return EE_Base_Class|EE_Venue |
|
| 752 | - * @throws EE_Error |
|
| 753 | - * @throws ReflectionException |
|
| 754 | - */ |
|
| 755 | - public function venue(array $query_params = array()) |
|
| 756 | - { |
|
| 757 | - return $this->get_first_related('Venue', $query_params); |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - |
|
| 761 | - /** |
|
| 762 | - * @param array $query_params |
|
| 763 | - * @return EE_Base_Class[]|EE_Venue[] |
|
| 764 | - * @throws EE_Error |
|
| 765 | - * @throws ReflectionException |
|
| 766 | - * @deprecated $VID:$ |
|
| 767 | - */ |
|
| 768 | - public function venues(array $query_params = array()): array |
|
| 769 | - { |
|
| 770 | - return [$this->venue($query_params)]; |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - |
|
| 774 | - /** |
|
| 775 | - * check if event id is present and if event is published |
|
| 776 | - * |
|
| 777 | - * @access public |
|
| 778 | - * @return boolean true yes, false no |
|
| 779 | - * @throws EE_Error |
|
| 780 | - * @throws ReflectionException |
|
| 781 | - */ |
|
| 782 | - private function _has_ID_and_is_published() |
|
| 783 | - { |
|
| 784 | - // first check if event id is present and not NULL, |
|
| 785 | - // then check if this event is published (or any of the equivalent "published" statuses) |
|
| 786 | - return |
|
| 787 | - $this->ID() && $this->ID() !== null |
|
| 788 | - && ( |
|
| 789 | - $this->status() === 'publish' |
|
| 790 | - || $this->status() === EEM_Event::sold_out |
|
| 791 | - || $this->status() === EEM_Event::postponed |
|
| 792 | - || $this->status() === EEM_Event::cancelled |
|
| 793 | - ); |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - |
|
| 797 | - /** |
|
| 798 | - * This simply compares the internal dates with NOW and determines if the event is upcoming or not. |
|
| 799 | - * |
|
| 800 | - * @access public |
|
| 801 | - * @return boolean true yes, false no |
|
| 802 | - * @throws EE_Error |
|
| 803 | - * @throws ReflectionException |
|
| 804 | - */ |
|
| 805 | - public function is_upcoming() |
|
| 806 | - { |
|
| 807 | - // check if event id is present and if this event is published |
|
| 808 | - if ($this->is_inactive()) { |
|
| 809 | - return false; |
|
| 810 | - } |
|
| 811 | - // set initial value |
|
| 812 | - $upcoming = false; |
|
| 813 | - // next let's get all datetimes and loop through them |
|
| 814 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
| 815 | - foreach ($datetimes as $datetime) { |
|
| 816 | - if ($datetime instanceof EE_Datetime) { |
|
| 817 | - // if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
|
| 818 | - if ($datetime->is_expired()) { |
|
| 819 | - continue; |
|
| 820 | - } |
|
| 821 | - // if this dtt is active then we return false. |
|
| 822 | - if ($datetime->is_active()) { |
|
| 823 | - return false; |
|
| 824 | - } |
|
| 825 | - // otherwise let's check upcoming status |
|
| 826 | - $upcoming = $datetime->is_upcoming(); |
|
| 827 | - } |
|
| 828 | - } |
|
| 829 | - return $upcoming; |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - |
|
| 833 | - /** |
|
| 834 | - * @return bool |
|
| 835 | - * @throws EE_Error |
|
| 836 | - * @throws ReflectionException |
|
| 837 | - */ |
|
| 838 | - public function is_active() |
|
| 839 | - { |
|
| 840 | - // check if event id is present and if this event is published |
|
| 841 | - if ($this->is_inactive()) { |
|
| 842 | - return false; |
|
| 843 | - } |
|
| 844 | - // set initial value |
|
| 845 | - $active = false; |
|
| 846 | - // next let's get all datetimes and loop through them |
|
| 847 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
| 848 | - foreach ($datetimes as $datetime) { |
|
| 849 | - if ($datetime instanceof EE_Datetime) { |
|
| 850 | - // if this dtt is expired then we continue cause one of the other datetimes might be active. |
|
| 851 | - if ($datetime->is_expired()) { |
|
| 852 | - continue; |
|
| 853 | - } |
|
| 854 | - // if this dtt is upcoming then we return false. |
|
| 855 | - if ($datetime->is_upcoming()) { |
|
| 856 | - return false; |
|
| 857 | - } |
|
| 858 | - // otherwise let's check active status |
|
| 859 | - $active = $datetime->is_active(); |
|
| 860 | - } |
|
| 861 | - } |
|
| 862 | - return $active; |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - |
|
| 866 | - /** |
|
| 867 | - * @return bool |
|
| 868 | - * @throws EE_Error |
|
| 869 | - * @throws ReflectionException |
|
| 870 | - */ |
|
| 871 | - public function is_expired() |
|
| 872 | - { |
|
| 873 | - // check if event id is present and if this event is published |
|
| 874 | - if ($this->is_inactive()) { |
|
| 875 | - return false; |
|
| 876 | - } |
|
| 877 | - // set initial value |
|
| 878 | - $expired = false; |
|
| 879 | - // first let's get all datetimes and loop through them |
|
| 880 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
| 881 | - foreach ($datetimes as $datetime) { |
|
| 882 | - if ($datetime instanceof EE_Datetime) { |
|
| 883 | - // if this dtt is upcoming or active then we return false. |
|
| 884 | - if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
| 885 | - return false; |
|
| 886 | - } |
|
| 887 | - // otherwise let's check active status |
|
| 888 | - $expired = $datetime->is_expired(); |
|
| 889 | - } |
|
| 890 | - } |
|
| 891 | - return $expired; |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - |
|
| 895 | - /** |
|
| 896 | - * @return bool |
|
| 897 | - * @throws EE_Error |
|
| 898 | - */ |
|
| 899 | - public function is_inactive() |
|
| 900 | - { |
|
| 901 | - // check if event id is present and if this event is published |
|
| 902 | - if ($this->_has_ID_and_is_published()) { |
|
| 903 | - return false; |
|
| 904 | - } |
|
| 905 | - return true; |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - |
|
| 909 | - /** |
|
| 910 | - * calculate spaces remaining based on "saleable" tickets |
|
| 911 | - * |
|
| 912 | - * @param array $tickets |
|
| 913 | - * @param bool $filtered |
|
| 914 | - * @return int|float |
|
| 915 | - * @throws EE_Error |
|
| 916 | - * @throws DomainException |
|
| 917 | - * @throws UnexpectedEntityException |
|
| 918 | - */ |
|
| 919 | - public function spaces_remaining($tickets = array(), $filtered = true) |
|
| 920 | - { |
|
| 921 | - $this->getAvailableSpacesCalculator()->setActiveTickets($tickets); |
|
| 922 | - $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining(); |
|
| 923 | - return $filtered |
|
| 924 | - ? apply_filters( |
|
| 925 | - 'FHEE_EE_Event__spaces_remaining', |
|
| 926 | - $spaces_remaining, |
|
| 927 | - $this, |
|
| 928 | - $tickets |
|
| 929 | - ) |
|
| 930 | - : $spaces_remaining; |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - |
|
| 934 | - /** |
|
| 935 | - * perform_sold_out_status_check |
|
| 936 | - * checks all of this events's datetime reg_limit - sold values to determine if ANY datetimes have spaces |
|
| 937 | - * available... if NOT, then the event status will get toggled to 'sold_out' |
|
| 938 | - * |
|
| 939 | - * @return bool return the ACTUAL sold out state. |
|
| 940 | - * @throws EE_Error |
|
| 941 | - * @throws DomainException |
|
| 942 | - * @throws UnexpectedEntityException |
|
| 943 | - * @throws ReflectionException |
|
| 944 | - */ |
|
| 945 | - public function perform_sold_out_status_check() |
|
| 946 | - { |
|
| 947 | - // get all tickets |
|
| 948 | - $tickets = $this->tickets( |
|
| 949 | - array( |
|
| 950 | - 'default_where_conditions' => 'none', |
|
| 951 | - 'order_by' => array('TKT_qty' => 'ASC'), |
|
| 952 | - ) |
|
| 953 | - ); |
|
| 954 | - $all_expired = true; |
|
| 955 | - foreach ($tickets as $ticket) { |
|
| 956 | - if (! $ticket->is_expired()) { |
|
| 957 | - $all_expired = false; |
|
| 958 | - break; |
|
| 959 | - } |
|
| 960 | - } |
|
| 961 | - // if all the tickets are just expired, then don't update the event status to sold out |
|
| 962 | - if ($all_expired) { |
|
| 963 | - return true; |
|
| 964 | - } |
|
| 965 | - $spaces_remaining = $this->spaces_remaining($tickets); |
|
| 966 | - if ($spaces_remaining < 1) { |
|
| 967 | - if ($this->status() !== EEM_Event::post_status_private) { |
|
| 968 | - $this->set_status(EEM_Event::sold_out); |
|
| 969 | - $this->save(); |
|
| 970 | - } |
|
| 971 | - $sold_out = true; |
|
| 972 | - } else { |
|
| 973 | - $sold_out = false; |
|
| 974 | - // was event previously marked as sold out ? |
|
| 975 | - if ($this->status() === EEM_Event::sold_out) { |
|
| 976 | - // revert status to previous value, if it was set |
|
| 977 | - $previous_event_status = $this->get_post_meta('_previous_event_status', true); |
|
| 978 | - if ($previous_event_status) { |
|
| 979 | - $this->set_status($previous_event_status); |
|
| 980 | - $this->save(); |
|
| 981 | - } |
|
| 982 | - } |
|
| 983 | - } |
|
| 984 | - do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets); |
|
| 985 | - return $sold_out; |
|
| 986 | - } |
|
| 987 | - |
|
| 988 | - |
|
| 989 | - /** |
|
| 990 | - * This returns the total remaining spaces for sale on this event. |
|
| 991 | - * |
|
| 992 | - * @uses EE_Event::total_available_spaces() |
|
| 993 | - * @return float|int |
|
| 994 | - * @throws EE_Error |
|
| 995 | - * @throws DomainException |
|
| 996 | - * @throws UnexpectedEntityException |
|
| 997 | - */ |
|
| 998 | - public function spaces_remaining_for_sale() |
|
| 999 | - { |
|
| 1000 | - return $this->total_available_spaces(true); |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - |
|
| 1004 | - /** |
|
| 1005 | - * This returns the total spaces available for an event |
|
| 1006 | - * while considering all the qtys on the tickets and the reg limits |
|
| 1007 | - * on the datetimes attached to this event. |
|
| 1008 | - * |
|
| 1009 | - * @param bool $consider_sold Whether to consider any tickets that have already sold in our calculation. |
|
| 1010 | - * If this is false, then we return the most tickets that could ever be sold |
|
| 1011 | - * for this event with the datetime and tickets setup on the event under optimal |
|
| 1012 | - * selling conditions. Otherwise we return a live calculation of spaces available |
|
| 1013 | - * based on tickets sold. Depending on setup and stage of sales, this |
|
| 1014 | - * may appear to equal remaining tickets. However, the more tickets are |
|
| 1015 | - * sold out, the more accurate the "live" total is. |
|
| 1016 | - * @return float|int |
|
| 1017 | - * @throws EE_Error |
|
| 1018 | - * @throws DomainException |
|
| 1019 | - * @throws UnexpectedEntityException |
|
| 1020 | - */ |
|
| 1021 | - public function total_available_spaces($consider_sold = false) |
|
| 1022 | - { |
|
| 1023 | - $spaces_available = $consider_sold |
|
| 1024 | - ? $this->getAvailableSpacesCalculator()->spacesRemaining() |
|
| 1025 | - : $this->getAvailableSpacesCalculator()->totalSpacesAvailable(); |
|
| 1026 | - return apply_filters( |
|
| 1027 | - 'FHEE_EE_Event__total_available_spaces__spaces_available', |
|
| 1028 | - $spaces_available, |
|
| 1029 | - $this, |
|
| 1030 | - $this->getAvailableSpacesCalculator()->getDatetimes(), |
|
| 1031 | - $this->getAvailableSpacesCalculator()->getActiveTickets() |
|
| 1032 | - ); |
|
| 1033 | - } |
|
| 1034 | - |
|
| 1035 | - |
|
| 1036 | - /** |
|
| 1037 | - * Checks if the event is set to sold out |
|
| 1038 | - * |
|
| 1039 | - * @param bool $actual whether or not to perform calculations to not only figure the |
|
| 1040 | - * actual status but also to flip the status if necessary to sold |
|
| 1041 | - * out If false, we just check the existing status of the event |
|
| 1042 | - * @return boolean |
|
| 1043 | - * @throws EE_Error |
|
| 1044 | - */ |
|
| 1045 | - public function is_sold_out($actual = false) |
|
| 1046 | - { |
|
| 1047 | - if (! $actual) { |
|
| 1048 | - return $this->status() === EEM_Event::sold_out; |
|
| 1049 | - } |
|
| 1050 | - return $this->perform_sold_out_status_check(); |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - |
|
| 1054 | - /** |
|
| 1055 | - * Checks if the event is marked as postponed |
|
| 1056 | - * |
|
| 1057 | - * @return boolean |
|
| 1058 | - */ |
|
| 1059 | - public function is_postponed() |
|
| 1060 | - { |
|
| 1061 | - return $this->status() === EEM_Event::postponed; |
|
| 1062 | - } |
|
| 1063 | - |
|
| 1064 | - |
|
| 1065 | - /** |
|
| 1066 | - * Checks if the event is marked as cancelled |
|
| 1067 | - * |
|
| 1068 | - * @return boolean |
|
| 1069 | - */ |
|
| 1070 | - public function is_cancelled() |
|
| 1071 | - { |
|
| 1072 | - return $this->status() === EEM_Event::cancelled; |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - |
|
| 1076 | - /** |
|
| 1077 | - * Get the logical active status in a hierarchical order for all the datetimes. Note |
|
| 1078 | - * Basically, we order the datetimes by EVT_start_date. Then first test on whether the event is published. If its |
|
| 1079 | - * NOT published then we test for whether its expired or not. IF it IS published then we test first on whether an |
|
| 1080 | - * event has any active dates. If no active dates then we check for any upcoming dates. If no upcoming dates then |
|
| 1081 | - * the event is considered expired. |
|
| 1082 | - * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published. Sold Out is a |
|
| 1083 | - * status set on the EVENT when it is not published and thus is done |
|
| 1084 | - * |
|
| 1085 | - * @param bool $reset |
|
| 1086 | - * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
|
| 1087 | - * @throws EE_Error |
|
| 1088 | - * @throws ReflectionException |
|
| 1089 | - */ |
|
| 1090 | - public function get_active_status($reset = false) |
|
| 1091 | - { |
|
| 1092 | - // if the active status has already been set, then just use that value (unless we are resetting it) |
|
| 1093 | - if (! empty($this->_active_status) && ! $reset) { |
|
| 1094 | - return $this->_active_status; |
|
| 1095 | - } |
|
| 1096 | - // first check if event id is present on this object |
|
| 1097 | - if (! $this->ID()) { |
|
| 1098 | - return false; |
|
| 1099 | - } |
|
| 1100 | - $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
|
| 1101 | - // if event is published: |
|
| 1102 | - if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) { |
|
| 1103 | - // active? |
|
| 1104 | - if ( |
|
| 1105 | - EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1106 | - EE_Datetime::active, |
|
| 1107 | - $where_params_for_event |
|
| 1108 | - ) > 0 |
|
| 1109 | - ) { |
|
| 1110 | - $this->_active_status = EE_Datetime::active; |
|
| 1111 | - } else { |
|
| 1112 | - // upcoming? |
|
| 1113 | - if ( |
|
| 1114 | - EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1115 | - EE_Datetime::upcoming, |
|
| 1116 | - $where_params_for_event |
|
| 1117 | - ) > 0 |
|
| 1118 | - ) { |
|
| 1119 | - $this->_active_status = EE_Datetime::upcoming; |
|
| 1120 | - } else { |
|
| 1121 | - // expired? |
|
| 1122 | - if ( |
|
| 1123 | - EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1124 | - EE_Datetime::expired, |
|
| 1125 | - $where_params_for_event |
|
| 1126 | - ) > 0 |
|
| 1127 | - ) { |
|
| 1128 | - $this->_active_status = EE_Datetime::expired; |
|
| 1129 | - } else { |
|
| 1130 | - // it would be odd if things make it this far because it basically means there are no datetime's |
|
| 1131 | - // attached to the event. So in this case it will just be considered inactive. |
|
| 1132 | - $this->_active_status = EE_Datetime::inactive; |
|
| 1133 | - } |
|
| 1134 | - } |
|
| 1135 | - } |
|
| 1136 | - } else { |
|
| 1137 | - // the event is not published, so let's just set it's active status according to its' post status |
|
| 1138 | - switch ($this->status()) { |
|
| 1139 | - case EEM_Event::sold_out: |
|
| 1140 | - $this->_active_status = EE_Datetime::sold_out; |
|
| 1141 | - break; |
|
| 1142 | - case EEM_Event::cancelled: |
|
| 1143 | - $this->_active_status = EE_Datetime::cancelled; |
|
| 1144 | - break; |
|
| 1145 | - case EEM_Event::postponed: |
|
| 1146 | - $this->_active_status = EE_Datetime::postponed; |
|
| 1147 | - break; |
|
| 1148 | - default: |
|
| 1149 | - $this->_active_status = EE_Datetime::inactive; |
|
| 1150 | - } |
|
| 1151 | - } |
|
| 1152 | - return $this->_active_status; |
|
| 1153 | - } |
|
| 1154 | - |
|
| 1155 | - |
|
| 1156 | - /** |
|
| 1157 | - * pretty_active_status |
|
| 1158 | - * |
|
| 1159 | - * @access public |
|
| 1160 | - * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
|
| 1161 | - * @return mixed void|string |
|
| 1162 | - * @throws EE_Error |
|
| 1163 | - * @throws ReflectionException |
|
| 1164 | - */ |
|
| 1165 | - public function pretty_active_status($echo = true) |
|
| 1166 | - { |
|
| 1167 | - $active_status = $this->get_active_status(); |
|
| 1168 | - $status = '<span class="ee-status ee-status-bg--' . esc_attr($active_status) . ' event-active-status--' . |
|
| 1169 | - esc_attr($active_status) . '">' |
|
| 1170 | - . EEH_Template::pretty_status($active_status, false, 'sentence') |
|
| 1171 | - . '</span>'; |
|
| 1172 | - if ($echo) { |
|
| 1173 | - echo $status; // already escaped |
|
| 1174 | - return ''; |
|
| 1175 | - } |
|
| 1176 | - return $status; // already escaped |
|
| 1177 | - } |
|
| 1178 | - |
|
| 1179 | - |
|
| 1180 | - /** |
|
| 1181 | - * @return bool|int |
|
| 1182 | - * @throws EE_Error |
|
| 1183 | - * @throws ReflectionException |
|
| 1184 | - */ |
|
| 1185 | - public function get_number_of_tickets_sold() |
|
| 1186 | - { |
|
| 1187 | - $tkt_sold = 0; |
|
| 1188 | - if (! $this->ID()) { |
|
| 1189 | - return 0; |
|
| 1190 | - } |
|
| 1191 | - $datetimes = $this->datetimes(); |
|
| 1192 | - foreach ($datetimes as $datetime) { |
|
| 1193 | - if ($datetime instanceof EE_Datetime) { |
|
| 1194 | - $tkt_sold += $datetime->sold(); |
|
| 1195 | - } |
|
| 1196 | - } |
|
| 1197 | - return $tkt_sold; |
|
| 1198 | - } |
|
| 1199 | - |
|
| 1200 | - |
|
| 1201 | - /** |
|
| 1202 | - * This just returns a count of all the registrations for this event |
|
| 1203 | - * |
|
| 1204 | - * @access public |
|
| 1205 | - * @return int |
|
| 1206 | - * @throws EE_Error |
|
| 1207 | - */ |
|
| 1208 | - public function get_count_of_all_registrations() |
|
| 1209 | - { |
|
| 1210 | - return EEM_Event::instance()->count_related($this, 'Registration'); |
|
| 1211 | - } |
|
| 1212 | - |
|
| 1213 | - |
|
| 1214 | - /** |
|
| 1215 | - * This returns the ticket with the earliest start time that is |
|
| 1216 | - * available for this event (across all datetimes attached to the event) |
|
| 1217 | - * |
|
| 1218 | - * @return EE_Base_Class|EE_Ticket|null |
|
| 1219 | - * @throws EE_Error |
|
| 1220 | - * @throws ReflectionException |
|
| 1221 | - */ |
|
| 1222 | - public function get_ticket_with_earliest_start_time() |
|
| 1223 | - { |
|
| 1224 | - $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1225 | - $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
| 1226 | - return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - |
|
| 1230 | - /** |
|
| 1231 | - * This returns the ticket with the latest end time that is available |
|
| 1232 | - * for this event (across all datetimes attached to the event) |
|
| 1233 | - * |
|
| 1234 | - * @return EE_Base_Class|EE_Ticket|null |
|
| 1235 | - * @throws EE_Error |
|
| 1236 | - * @throws ReflectionException |
|
| 1237 | - */ |
|
| 1238 | - public function get_ticket_with_latest_end_time() |
|
| 1239 | - { |
|
| 1240 | - $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1241 | - $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
| 1242 | - return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1243 | - } |
|
| 1244 | - |
|
| 1245 | - |
|
| 1246 | - /** |
|
| 1247 | - * This returns the number of different ticket types currently on sale for this event. |
|
| 1248 | - * |
|
| 1249 | - * @return int |
|
| 1250 | - * @throws EE_Error |
|
| 1251 | - * @throws ReflectionException |
|
| 1252 | - */ |
|
| 1253 | - public function countTicketsOnSale() |
|
| 1254 | - { |
|
| 1255 | - $where = array( |
|
| 1256 | - 'Datetime.EVT_ID' => $this->ID(), |
|
| 1257 | - 'TKT_start_date' => array('<', time()), |
|
| 1258 | - 'TKT_end_date' => array('>', time()), |
|
| 1259 | - ); |
|
| 1260 | - return EEM_Ticket::instance()->count(array($where)); |
|
| 1261 | - } |
|
| 1262 | - |
|
| 1263 | - |
|
| 1264 | - /** |
|
| 1265 | - * This returns whether there are any tickets on sale for this event. |
|
| 1266 | - * |
|
| 1267 | - * @return bool true = YES tickets on sale. |
|
| 1268 | - * @throws EE_Error |
|
| 1269 | - */ |
|
| 1270 | - public function tickets_on_sale() |
|
| 1271 | - { |
|
| 1272 | - return $this->countTicketsOnSale() > 0; |
|
| 1273 | - } |
|
| 1274 | - |
|
| 1275 | - |
|
| 1276 | - /** |
|
| 1277 | - * Gets the URL for viewing this event on the front-end. Overrides parent |
|
| 1278 | - * to check for an external URL first |
|
| 1279 | - * |
|
| 1280 | - * @return string |
|
| 1281 | - * @throws EE_Error |
|
| 1282 | - */ |
|
| 1283 | - public function get_permalink() |
|
| 1284 | - { |
|
| 1285 | - if ($this->external_url()) { |
|
| 1286 | - return $this->external_url(); |
|
| 1287 | - } |
|
| 1288 | - return parent::get_permalink(); |
|
| 1289 | - } |
|
| 1290 | - |
|
| 1291 | - |
|
| 1292 | - /** |
|
| 1293 | - * Gets the first term for 'espresso_event_categories' we can find |
|
| 1294 | - * |
|
| 1295 | - * @param array $query_params @see |
|
| 1296 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1297 | - * @return EE_Base_Class|EE_Term|null |
|
| 1298 | - * @throws EE_Error |
|
| 1299 | - * @throws ReflectionException |
|
| 1300 | - */ |
|
| 1301 | - public function first_event_category($query_params = array()) |
|
| 1302 | - { |
|
| 1303 | - $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1304 | - $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1305 | - return EEM_Term::instance()->get_one($query_params); |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - |
|
| 1309 | - /** |
|
| 1310 | - * Gets all terms for 'espresso_event_categories' we can find |
|
| 1311 | - * |
|
| 1312 | - * @param array $query_params |
|
| 1313 | - * @return EE_Base_Class[]|EE_Term[] |
|
| 1314 | - * @throws EE_Error |
|
| 1315 | - * @throws ReflectionException |
|
| 1316 | - */ |
|
| 1317 | - public function get_all_event_categories($query_params = array()) |
|
| 1318 | - { |
|
| 1319 | - $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1320 | - $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1321 | - return EEM_Term::instance()->get_all($query_params); |
|
| 1322 | - } |
|
| 1323 | - |
|
| 1324 | - |
|
| 1325 | - /** |
|
| 1326 | - * Adds a question group to this event |
|
| 1327 | - * |
|
| 1328 | - * @param EE_Question_Group|int $question_group_id_or_obj |
|
| 1329 | - * @param bool $for_primary if true, the question group will be added for the primary |
|
| 1330 | - * registrant, if false will be added for others. default: false |
|
| 1331 | - * @return EE_Base_Class|EE_Question_Group |
|
| 1332 | - * @throws EE_Error |
|
| 1333 | - * @throws InvalidArgumentException |
|
| 1334 | - * @throws InvalidDataTypeException |
|
| 1335 | - * @throws InvalidInterfaceException |
|
| 1336 | - * @throws ReflectionException |
|
| 1337 | - */ |
|
| 1338 | - public function add_question_group($question_group_id_or_obj, $for_primary = false) |
|
| 1339 | - { |
|
| 1340 | - // If the row already exists, it will be updated. If it doesn't, it will be inserted. |
|
| 1341 | - // That's in EE_HABTM_Relation::add_relation_to(). |
|
| 1342 | - return $this->_add_relation_to( |
|
| 1343 | - $question_group_id_or_obj, |
|
| 1344 | - 'Question_Group', |
|
| 1345 | - [ |
|
| 1346 | - EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary) => true |
|
| 1347 | - ] |
|
| 1348 | - ); |
|
| 1349 | - } |
|
| 1350 | - |
|
| 1351 | - |
|
| 1352 | - /** |
|
| 1353 | - * Removes a question group from the event |
|
| 1354 | - * |
|
| 1355 | - * @param EE_Question_Group|int $question_group_id_or_obj |
|
| 1356 | - * @param bool $for_primary if true, the question group will be removed from the primary |
|
| 1357 | - * registrant, if false will be removed from others. default: false |
|
| 1358 | - * @return EE_Base_Class|EE_Question_Group |
|
| 1359 | - * @throws EE_Error |
|
| 1360 | - * @throws InvalidArgumentException |
|
| 1361 | - * @throws ReflectionException |
|
| 1362 | - * @throws InvalidDataTypeException |
|
| 1363 | - * @throws InvalidInterfaceException |
|
| 1364 | - */ |
|
| 1365 | - public function remove_question_group($question_group_id_or_obj, $for_primary = false) |
|
| 1366 | - { |
|
| 1367 | - // If the question group is used for the other type (primary or additional) |
|
| 1368 | - // then just update it. If not, delete it outright. |
|
| 1369 | - $existing_relation = $this->get_first_related( |
|
| 1370 | - 'Event_Question_Group', |
|
| 1371 | - [ |
|
| 1372 | - [ |
|
| 1373 | - 'QSG_ID' => EEM_Question_Group::instance()->ensure_is_ID($question_group_id_or_obj) |
|
| 1374 | - ] |
|
| 1375 | - ] |
|
| 1376 | - ); |
|
| 1377 | - $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary); |
|
| 1378 | - $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary); |
|
| 1379 | - if ($existing_relation->get($other_field) === false) { |
|
| 1380 | - // Delete it. It's now no longer for primary or additional question groups. |
|
| 1381 | - return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group'); |
|
| 1382 | - } |
|
| 1383 | - // Just update it. They'll still use this question group for the other category |
|
| 1384 | - $existing_relation->save( |
|
| 1385 | - [ |
|
| 1386 | - $field_to_update => false |
|
| 1387 | - ] |
|
| 1388 | - ); |
|
| 1389 | - } |
|
| 1390 | - |
|
| 1391 | - |
|
| 1392 | - /** |
|
| 1393 | - * Gets all the question groups, ordering them by QSG_order ascending |
|
| 1394 | - * |
|
| 1395 | - * @param array $query_params @see |
|
| 1396 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1397 | - * @return EE_Base_Class[]|EE_Question_Group[] |
|
| 1398 | - * @throws EE_Error |
|
| 1399 | - * @throws ReflectionException |
|
| 1400 | - */ |
|
| 1401 | - public function question_groups($query_params = array()) |
|
| 1402 | - { |
|
| 1403 | - $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
| 1404 | - return $this->get_many_related('Question_Group', $query_params); |
|
| 1405 | - } |
|
| 1406 | - |
|
| 1407 | - |
|
| 1408 | - /** |
|
| 1409 | - * Implementation for EEI_Has_Icon interface method. |
|
| 1410 | - * |
|
| 1411 | - * @see EEI_Visual_Representation for comments |
|
| 1412 | - * @return string |
|
| 1413 | - */ |
|
| 1414 | - public function get_icon() |
|
| 1415 | - { |
|
| 1416 | - return '<span class="dashicons dashicons-flag"></span>'; |
|
| 1417 | - } |
|
| 1418 | - |
|
| 1419 | - |
|
| 1420 | - /** |
|
| 1421 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1422 | - * |
|
| 1423 | - * @see EEI_Admin_Links for comments |
|
| 1424 | - * @return string |
|
| 1425 | - * @throws EE_Error |
|
| 1426 | - */ |
|
| 1427 | - public function get_admin_details_link() |
|
| 1428 | - { |
|
| 1429 | - return $this->get_admin_edit_link(); |
|
| 1430 | - } |
|
| 1431 | - |
|
| 1432 | - |
|
| 1433 | - /** |
|
| 1434 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1435 | - * |
|
| 1436 | - * @return string |
|
| 1437 | - * @throws EE_Error*@throws ReflectionException |
|
| 1438 | - * @see EEI_Admin_Links for comments |
|
| 1439 | - */ |
|
| 1440 | - public function get_admin_edit_link() |
|
| 1441 | - { |
|
| 1442 | - return EEH_URL::add_query_args_and_nonce( |
|
| 1443 | - array( |
|
| 1444 | - 'page' => 'espresso_events', |
|
| 1445 | - 'action' => 'edit', |
|
| 1446 | - 'post' => $this->ID(), |
|
| 1447 | - ), |
|
| 1448 | - admin_url('admin.php') |
|
| 1449 | - ); |
|
| 1450 | - } |
|
| 1451 | - |
|
| 1452 | - |
|
| 1453 | - /** |
|
| 1454 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1455 | - * |
|
| 1456 | - * @see EEI_Admin_Links for comments |
|
| 1457 | - * @return string |
|
| 1458 | - */ |
|
| 1459 | - public function get_admin_settings_link() |
|
| 1460 | - { |
|
| 1461 | - return EEH_URL::add_query_args_and_nonce( |
|
| 1462 | - array( |
|
| 1463 | - 'page' => 'espresso_events', |
|
| 1464 | - 'action' => 'default_event_settings', |
|
| 1465 | - ), |
|
| 1466 | - admin_url('admin.php') |
|
| 1467 | - ); |
|
| 1468 | - } |
|
| 1469 | - |
|
| 1470 | - |
|
| 1471 | - /** |
|
| 1472 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1473 | - * |
|
| 1474 | - * @see EEI_Admin_Links for comments |
|
| 1475 | - * @return string |
|
| 1476 | - */ |
|
| 1477 | - public function get_admin_overview_link() |
|
| 1478 | - { |
|
| 1479 | - return EEH_URL::add_query_args_and_nonce( |
|
| 1480 | - array( |
|
| 1481 | - 'page' => 'espresso_events', |
|
| 1482 | - 'action' => 'default', |
|
| 1483 | - ), |
|
| 1484 | - admin_url('admin.php') |
|
| 1485 | - ); |
|
| 1486 | - } |
|
| 1487 | - |
|
| 1488 | - |
|
| 1489 | - /** |
|
| 1490 | - * @return string|null |
|
| 1491 | - * @throws EE_Error |
|
| 1492 | - * @throws ReflectionException |
|
| 1493 | - */ |
|
| 1494 | - public function registrationFormUuid(): ?string |
|
| 1495 | - { |
|
| 1496 | - return $this->get('FSC_UUID'); |
|
| 1497 | - } |
|
| 1498 | - |
|
| 1499 | - |
|
| 1500 | - /** |
|
| 1501 | - * Gets all the form sections for this event |
|
| 1502 | - * |
|
| 1503 | - * @return EE_Base_Class[]|EE_Form_Section[] |
|
| 1504 | - * @throws EE_Error |
|
| 1505 | - * @throws ReflectionException |
|
| 1506 | - */ |
|
| 1507 | - public function registrationForm() |
|
| 1508 | - { |
|
| 1509 | - $FSC_UUID = $this->registrationFormUuid(); |
|
| 1510 | - |
|
| 1511 | - if (empty($FSC_UUID)) { |
|
| 1512 | - return []; |
|
| 1513 | - } |
|
| 1514 | - |
|
| 1515 | - return EEM_Form_Section::instance()->get_all([ |
|
| 1516 | - [ |
|
| 1517 | - 'OR' => [ |
|
| 1518 | - 'FSC_UUID' => $FSC_UUID, // top level form |
|
| 1519 | - 'FSC_belongsTo' => $FSC_UUID, // child form sections |
|
| 1520 | - ] |
|
| 1521 | - ], |
|
| 1522 | - 'order_by' => ['FSC_order' => 'ASC'], |
|
| 1523 | - ]); |
|
| 1524 | - } |
|
| 1525 | - |
|
| 1526 | - |
|
| 1527 | - /** |
|
| 1528 | - * @param string $UUID |
|
| 1529 | - * @throws EE_Error |
|
| 1530 | - */ |
|
| 1531 | - public function setRegistrationFormUuid(string $UUID): void |
|
| 1532 | - { |
|
| 1533 | - if (! Cuid::isCuid($UUID)) { |
|
| 1534 | - throw new InvalidArgumentException( |
|
| 1535 | - sprintf( |
|
| 1536 | - /* translators: 1: UUID value, 2: UUID generator function. */ |
|
| 1537 | - esc_html__( |
|
| 1538 | - 'The supplied UUID "%1$s" is invalid or missing. Please use %2$s to generate a valid one.', |
|
| 1539 | - 'event_espresso' |
|
| 1540 | - ), |
|
| 1541 | - $UUID, |
|
| 1542 | - '`Cuid::cuid()`' |
|
| 1543 | - ) |
|
| 1544 | - ); |
|
| 1545 | - } |
|
| 1546 | - $this->set('FSC_UUID', $UUID); |
|
| 1547 | - } |
|
| 19 | + /** |
|
| 20 | + * cached value for the the logical active status for the event |
|
| 21 | + * |
|
| 22 | + * @see get_active_status() |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + protected $_active_status = ''; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * This is just used for caching the Primary Datetime for the Event on initial retrieval |
|
| 29 | + * |
|
| 30 | + * @var EE_Datetime |
|
| 31 | + */ |
|
| 32 | + protected $_Primary_Datetime; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var EventSpacesCalculator $available_spaces_calculator |
|
| 36 | + */ |
|
| 37 | + protected $available_spaces_calculator; |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @param array $props_n_values incoming values |
|
| 42 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 43 | + * used.) |
|
| 44 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 45 | + * date_format and the second value is the time format |
|
| 46 | + * @return EE_Event |
|
| 47 | + * @throws EE_Error |
|
| 48 | + * @throws ReflectionException |
|
| 49 | + */ |
|
| 50 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 51 | + { |
|
| 52 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 53 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param array $props_n_values incoming values from the database |
|
| 59 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 60 | + * the website will be used. |
|
| 61 | + * @return EE_Event |
|
| 62 | + * @throws EE_Error |
|
| 63 | + * @throws ReflectionException |
|
| 64 | + */ |
|
| 65 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 66 | + { |
|
| 67 | + return new self($props_n_values, true, $timezone); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @return EventSpacesCalculator |
|
| 73 | + * @throws \EE_Error |
|
| 74 | + */ |
|
| 75 | + public function getAvailableSpacesCalculator() |
|
| 76 | + { |
|
| 77 | + if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
| 78 | + $this->available_spaces_calculator = new EventSpacesCalculator($this); |
|
| 79 | + } |
|
| 80 | + return $this->available_spaces_calculator; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods |
|
| 86 | + * |
|
| 87 | + * @param string $field_name |
|
| 88 | + * @param mixed $field_value |
|
| 89 | + * @param bool $use_default |
|
| 90 | + * @throws EE_Error |
|
| 91 | + * @throws ReflectionException |
|
| 92 | + */ |
|
| 93 | + public function set($field_name, $field_value, $use_default = false) |
|
| 94 | + { |
|
| 95 | + switch ($field_name) { |
|
| 96 | + case 'status': |
|
| 97 | + $this->set_status($field_value, $use_default); |
|
| 98 | + break; |
|
| 99 | + default: |
|
| 100 | + parent::set($field_name, $field_value, $use_default); |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * set_status |
|
| 107 | + * Checks if event status is being changed to SOLD OUT |
|
| 108 | + * and updates event meta data with previous event status |
|
| 109 | + * so that we can revert things if/when the event is no longer sold out |
|
| 110 | + * |
|
| 111 | + * @access public |
|
| 112 | + * @param string $new_status |
|
| 113 | + * @param bool $use_default |
|
| 114 | + * @return void |
|
| 115 | + * @throws EE_Error |
|
| 116 | + * @throws ReflectionException |
|
| 117 | + */ |
|
| 118 | + public function set_status($new_status = null, $use_default = false) |
|
| 119 | + { |
|
| 120 | + // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave |
|
| 121 | + if (empty($new_status) && ! $use_default) { |
|
| 122 | + return; |
|
| 123 | + } |
|
| 124 | + // get current Event status |
|
| 125 | + $old_status = $this->status(); |
|
| 126 | + // if status has changed |
|
| 127 | + if ($old_status !== $new_status) { |
|
| 128 | + // TO sold_out |
|
| 129 | + if ($new_status === EEM_Event::sold_out) { |
|
| 130 | + // save the previous event status so that we can revert if the event is no longer sold out |
|
| 131 | + $this->add_post_meta('_previous_event_status', $old_status); |
|
| 132 | + do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status); |
|
| 133 | + // OR FROM sold_out |
|
| 134 | + } elseif ($old_status === EEM_Event::sold_out) { |
|
| 135 | + $this->delete_post_meta('_previous_event_status'); |
|
| 136 | + do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status); |
|
| 137 | + } |
|
| 138 | + // clear out the active status so that it gets reset the next time it is requested |
|
| 139 | + $this->_active_status = null; |
|
| 140 | + // update status |
|
| 141 | + parent::set('status', $new_status, $use_default); |
|
| 142 | + do_action('AHEE__EE_Event__set_status__after_update', $this); |
|
| 143 | + return; |
|
| 144 | + } |
|
| 145 | + // even though the old value matches the new value, it's still good to |
|
| 146 | + // allow the parent set method to have a say |
|
| 147 | + parent::set('status', $new_status, $use_default); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Gets all the datetimes for this event |
|
| 153 | + * |
|
| 154 | + * @param array $query_params @see |
|
| 155 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 156 | + * @return EE_Base_Class[]|EE_Datetime[] |
|
| 157 | + * @throws EE_Error |
|
| 158 | + * @throws ReflectionException |
|
| 159 | + */ |
|
| 160 | + public function datetimes($query_params = array()) |
|
| 161 | + { |
|
| 162 | + return $this->get_many_related('Datetime', $query_params); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order |
|
| 168 | + * |
|
| 169 | + * @return EE_Base_Class[]|EE_Datetime[] |
|
| 170 | + * @throws EE_Error |
|
| 171 | + * @throws ReflectionException |
|
| 172 | + */ |
|
| 173 | + public function datetimes_in_chronological_order() |
|
| 174 | + { |
|
| 175 | + return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Gets all the datetimes for this event, ordered by the DTT_order on the datetime. |
|
| 181 | + * @darren, we should probably UNSET timezone on the EEM_Datetime model |
|
| 182 | + * after running our query, so that this timezone isn't set for EVERY query |
|
| 183 | + * on EEM_Datetime for the rest of the request, no? |
|
| 184 | + * |
|
| 185 | + * @param boolean $show_expired whether or not to include expired events |
|
| 186 | + * @param boolean $show_deleted whether or not to include deleted events |
|
| 187 | + * @param null $limit |
|
| 188 | + * @return EE_Datetime[] |
|
| 189 | + * @throws EE_Error |
|
| 190 | + * @throws ReflectionException |
|
| 191 | + */ |
|
| 192 | + public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null) |
|
| 193 | + { |
|
| 194 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order( |
|
| 195 | + $this->ID(), |
|
| 196 | + $show_expired, |
|
| 197 | + $show_deleted, |
|
| 198 | + $limit |
|
| 199 | + ); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Returns one related datetime. Mostly only used by some legacy code. |
|
| 205 | + * |
|
| 206 | + * @return EE_Base_Class|EE_Datetime |
|
| 207 | + * @throws EE_Error |
|
| 208 | + * @throws ReflectionException |
|
| 209 | + */ |
|
| 210 | + public function first_datetime() |
|
| 211 | + { |
|
| 212 | + return $this->get_first_related('Datetime'); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Returns the 'primary' datetime for the event |
|
| 218 | + * |
|
| 219 | + * @param bool $try_to_exclude_expired |
|
| 220 | + * @param bool $try_to_exclude_deleted |
|
| 221 | + * @return EE_Datetime |
|
| 222 | + * @throws EE_Error |
|
| 223 | + * @throws ReflectionException |
|
| 224 | + */ |
|
| 225 | + public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
|
| 226 | + { |
|
| 227 | + if (! empty($this->_Primary_Datetime)) { |
|
| 228 | + return $this->_Primary_Datetime; |
|
| 229 | + } |
|
| 230 | + $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
|
| 231 | + $this->ID(), |
|
| 232 | + $try_to_exclude_expired, |
|
| 233 | + $try_to_exclude_deleted |
|
| 234 | + ); |
|
| 235 | + return $this->_Primary_Datetime; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Gets all the tickets available for purchase of this event |
|
| 241 | + * |
|
| 242 | + * @param array $query_params @see |
|
| 243 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 244 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
| 245 | + * @throws EE_Error |
|
| 246 | + * @throws ReflectionException |
|
| 247 | + */ |
|
| 248 | + public function tickets($query_params = array()) |
|
| 249 | + { |
|
| 250 | + // first get all datetimes |
|
| 251 | + $datetimes = $this->datetimes_ordered(); |
|
| 252 | + if (! $datetimes) { |
|
| 253 | + return array(); |
|
| 254 | + } |
|
| 255 | + $datetime_ids = array(); |
|
| 256 | + foreach ($datetimes as $datetime) { |
|
| 257 | + $datetime_ids[] = $datetime->ID(); |
|
| 258 | + } |
|
| 259 | + $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids)); |
|
| 260 | + // if incoming $query_params has where conditions let's merge but not override existing. |
|
| 261 | + if (is_array($query_params) && isset($query_params[0])) { |
|
| 262 | + $where_params = array_merge($query_params[0], $where_params); |
|
| 263 | + unset($query_params[0]); |
|
| 264 | + } |
|
| 265 | + // now add $where_params to $query_params |
|
| 266 | + $query_params[0] = $where_params; |
|
| 267 | + return EEM_Ticket::instance()->get_all($query_params); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * get all unexpired untrashed tickets |
|
| 273 | + * |
|
| 274 | + * @return EE_Ticket[] |
|
| 275 | + * @throws EE_Error |
|
| 276 | + */ |
|
| 277 | + public function active_tickets() |
|
| 278 | + { |
|
| 279 | + return $this->tickets( |
|
| 280 | + array( |
|
| 281 | + array( |
|
| 282 | + 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 283 | + 'TKT_deleted' => false, |
|
| 284 | + ), |
|
| 285 | + ) |
|
| 286 | + ); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * @return bool |
|
| 292 | + * @throws EE_Error |
|
| 293 | + * @throws ReflectionException |
|
| 294 | + */ |
|
| 295 | + public function additional_limit() |
|
| 296 | + { |
|
| 297 | + return $this->get('EVT_additional_limit'); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * @return bool |
|
| 303 | + * @throws EE_Error |
|
| 304 | + * @throws ReflectionException |
|
| 305 | + */ |
|
| 306 | + public function allow_overflow() |
|
| 307 | + { |
|
| 308 | + return $this->get('EVT_allow_overflow'); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * @return bool |
|
| 314 | + * @throws EE_Error |
|
| 315 | + * @throws ReflectionException |
|
| 316 | + */ |
|
| 317 | + public function created() |
|
| 318 | + { |
|
| 319 | + return $this->get('EVT_created'); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * @return bool |
|
| 325 | + * @throws EE_Error |
|
| 326 | + * @throws ReflectionException |
|
| 327 | + */ |
|
| 328 | + public function description() |
|
| 329 | + { |
|
| 330 | + return $this->get('EVT_desc'); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * Runs do_shortcode and wpautop on the description |
|
| 336 | + * |
|
| 337 | + * @return string of html |
|
| 338 | + * @throws EE_Error |
|
| 339 | + * @throws ReflectionException |
|
| 340 | + */ |
|
| 341 | + public function description_filtered() |
|
| 342 | + { |
|
| 343 | + return $this->get_pretty('EVT_desc'); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * @return bool |
|
| 349 | + * @throws EE_Error |
|
| 350 | + * @throws ReflectionException |
|
| 351 | + */ |
|
| 352 | + public function display_description() |
|
| 353 | + { |
|
| 354 | + return $this->get('EVT_display_desc'); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * @return bool |
|
| 360 | + * @throws EE_Error |
|
| 361 | + * @throws ReflectionException |
|
| 362 | + */ |
|
| 363 | + public function display_ticket_selector() |
|
| 364 | + { |
|
| 365 | + return (bool) $this->get('EVT_display_ticket_selector'); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * @return string |
|
| 371 | + * @throws EE_Error |
|
| 372 | + * @throws ReflectionException |
|
| 373 | + */ |
|
| 374 | + public function external_url() |
|
| 375 | + { |
|
| 376 | + return $this->get('EVT_external_URL'); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * @return bool |
|
| 382 | + * @throws EE_Error |
|
| 383 | + * @throws ReflectionException |
|
| 384 | + */ |
|
| 385 | + public function member_only() |
|
| 386 | + { |
|
| 387 | + return $this->get('EVT_member_only'); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * @return bool |
|
| 393 | + * @throws EE_Error |
|
| 394 | + * @throws ReflectionException |
|
| 395 | + */ |
|
| 396 | + public function phone() |
|
| 397 | + { |
|
| 398 | + return $this->get('EVT_phone'); |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * @return bool |
|
| 404 | + * @throws EE_Error |
|
| 405 | + * @throws ReflectionException |
|
| 406 | + */ |
|
| 407 | + public function modified() |
|
| 408 | + { |
|
| 409 | + return $this->get('EVT_modified'); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * @return bool |
|
| 415 | + * @throws EE_Error |
|
| 416 | + * @throws ReflectionException |
|
| 417 | + */ |
|
| 418 | + public function name() |
|
| 419 | + { |
|
| 420 | + return $this->get('EVT_name'); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * @return bool |
|
| 426 | + * @throws EE_Error |
|
| 427 | + * @throws ReflectionException |
|
| 428 | + */ |
|
| 429 | + public function order() |
|
| 430 | + { |
|
| 431 | + return $this->get('EVT_order'); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * @return bool|string |
|
| 437 | + * @throws EE_Error |
|
| 438 | + * @throws ReflectionException |
|
| 439 | + */ |
|
| 440 | + public function default_registration_status() |
|
| 441 | + { |
|
| 442 | + $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
| 443 | + return ! empty($event_default_registration_status) |
|
| 444 | + ? $event_default_registration_status |
|
| 445 | + : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * @param int $num_words |
|
| 451 | + * @param null $more |
|
| 452 | + * @param bool $not_full_desc |
|
| 453 | + * @return bool|string |
|
| 454 | + * @throws EE_Error |
|
| 455 | + * @throws ReflectionException |
|
| 456 | + */ |
|
| 457 | + public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
|
| 458 | + { |
|
| 459 | + $short_desc = $this->get('EVT_short_desc'); |
|
| 460 | + if (! empty($short_desc) || $not_full_desc) { |
|
| 461 | + return $short_desc; |
|
| 462 | + } |
|
| 463 | + $full_desc = $this->get('EVT_desc'); |
|
| 464 | + return wp_trim_words($full_desc, $num_words, $more); |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * @return bool |
|
| 470 | + * @throws EE_Error |
|
| 471 | + * @throws ReflectionException |
|
| 472 | + */ |
|
| 473 | + public function slug() |
|
| 474 | + { |
|
| 475 | + return $this->get('EVT_slug'); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * @return bool |
|
| 481 | + * @throws EE_Error |
|
| 482 | + * @throws ReflectionException |
|
| 483 | + */ |
|
| 484 | + public function timezone_string() |
|
| 485 | + { |
|
| 486 | + return $this->get('EVT_timezone_string'); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * @return bool |
|
| 492 | + * @throws EE_Error |
|
| 493 | + * @throws ReflectionException |
|
| 494 | + */ |
|
| 495 | + public function visible_on() |
|
| 496 | + { |
|
| 497 | + return $this->get('EVT_visible_on'); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * @return int |
|
| 503 | + * @throws EE_Error |
|
| 504 | + * @throws ReflectionException |
|
| 505 | + */ |
|
| 506 | + public function wp_user() |
|
| 507 | + { |
|
| 508 | + return $this->get('EVT_wp_user'); |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * @return bool |
|
| 514 | + * @throws EE_Error |
|
| 515 | + * @throws ReflectionException |
|
| 516 | + */ |
|
| 517 | + public function donations() |
|
| 518 | + { |
|
| 519 | + return $this->get('EVT_donations'); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * @param $limit |
|
| 525 | + * @throws EE_Error |
|
| 526 | + */ |
|
| 527 | + public function set_additional_limit($limit) |
|
| 528 | + { |
|
| 529 | + $this->set('EVT_additional_limit', $limit); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * @param $created |
|
| 535 | + * @throws EE_Error |
|
| 536 | + */ |
|
| 537 | + public function set_created($created) |
|
| 538 | + { |
|
| 539 | + $this->set('EVT_created', $created); |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * @param $desc |
|
| 545 | + * @throws EE_Error |
|
| 546 | + */ |
|
| 547 | + public function set_description($desc) |
|
| 548 | + { |
|
| 549 | + $this->set('EVT_desc', $desc); |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + |
|
| 553 | + /** |
|
| 554 | + * @param $display_desc |
|
| 555 | + * @throws EE_Error |
|
| 556 | + */ |
|
| 557 | + public function set_display_description($display_desc) |
|
| 558 | + { |
|
| 559 | + $this->set('EVT_display_desc', $display_desc); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + |
|
| 563 | + /** |
|
| 564 | + * @param $display_ticket_selector |
|
| 565 | + * @throws EE_Error |
|
| 566 | + */ |
|
| 567 | + public function set_display_ticket_selector($display_ticket_selector) |
|
| 568 | + { |
|
| 569 | + $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + |
|
| 573 | + /** |
|
| 574 | + * @param $external_url |
|
| 575 | + * @throws EE_Error |
|
| 576 | + */ |
|
| 577 | + public function set_external_url($external_url) |
|
| 578 | + { |
|
| 579 | + $this->set('EVT_external_URL', $external_url); |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * @param $member_only |
|
| 585 | + * @throws EE_Error |
|
| 586 | + */ |
|
| 587 | + public function set_member_only($member_only) |
|
| 588 | + { |
|
| 589 | + $this->set('EVT_member_only', $member_only); |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + |
|
| 593 | + /** |
|
| 594 | + * @param $event_phone |
|
| 595 | + * @throws EE_Error |
|
| 596 | + */ |
|
| 597 | + public function set_event_phone($event_phone) |
|
| 598 | + { |
|
| 599 | + $this->set('EVT_phone', $event_phone); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | + * @param $modified |
|
| 605 | + * @throws EE_Error |
|
| 606 | + */ |
|
| 607 | + public function set_modified($modified) |
|
| 608 | + { |
|
| 609 | + $this->set('EVT_modified', $modified); |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + |
|
| 613 | + /** |
|
| 614 | + * @param $name |
|
| 615 | + * @throws EE_Error |
|
| 616 | + */ |
|
| 617 | + public function set_name($name) |
|
| 618 | + { |
|
| 619 | + $this->set('EVT_name', $name); |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + |
|
| 623 | + /** |
|
| 624 | + * @param $order |
|
| 625 | + * @throws EE_Error |
|
| 626 | + */ |
|
| 627 | + public function set_order($order) |
|
| 628 | + { |
|
| 629 | + $this->set('EVT_order', $order); |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + |
|
| 633 | + /** |
|
| 634 | + * @param $short_desc |
|
| 635 | + * @throws EE_Error |
|
| 636 | + */ |
|
| 637 | + public function set_short_description($short_desc) |
|
| 638 | + { |
|
| 639 | + $this->set('EVT_short_desc', $short_desc); |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + |
|
| 643 | + /** |
|
| 644 | + * @param $slug |
|
| 645 | + * @throws EE_Error |
|
| 646 | + */ |
|
| 647 | + public function set_slug($slug) |
|
| 648 | + { |
|
| 649 | + $this->set('EVT_slug', $slug); |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * @param $timezone_string |
|
| 655 | + * @throws EE_Error |
|
| 656 | + */ |
|
| 657 | + public function set_timezone_string($timezone_string) |
|
| 658 | + { |
|
| 659 | + $this->set('EVT_timezone_string', $timezone_string); |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + |
|
| 663 | + /** |
|
| 664 | + * @param $visible_on |
|
| 665 | + * @throws EE_Error |
|
| 666 | + */ |
|
| 667 | + public function set_visible_on($visible_on) |
|
| 668 | + { |
|
| 669 | + $this->set('EVT_visible_on', $visible_on); |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + |
|
| 673 | + /** |
|
| 674 | + * @param $wp_user |
|
| 675 | + * @throws EE_Error |
|
| 676 | + */ |
|
| 677 | + public function set_wp_user($wp_user) |
|
| 678 | + { |
|
| 679 | + $this->set('EVT_wp_user', $wp_user); |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + /** |
|
| 684 | + * @param $default_registration_status |
|
| 685 | + * @throws EE_Error |
|
| 686 | + */ |
|
| 687 | + public function set_default_registration_status($default_registration_status) |
|
| 688 | + { |
|
| 689 | + $this->set('EVT_default_registration_status', $default_registration_status); |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + /** |
|
| 694 | + * @param $donations |
|
| 695 | + * @throws EE_Error |
|
| 696 | + */ |
|
| 697 | + public function set_donations($donations) |
|
| 698 | + { |
|
| 699 | + $this->set('EVT_donations', $donations); |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + |
|
| 703 | + /** |
|
| 704 | + * Adds a venue to this event |
|
| 705 | + * |
|
| 706 | + * @param int|EE_Venue /int $venue_id_or_obj |
|
| 707 | + * @return EE_Base_Class|EE_Venue |
|
| 708 | + * @throws EE_Error |
|
| 709 | + * @throws ReflectionException |
|
| 710 | + */ |
|
| 711 | + public function add_venue($venue_id_or_obj): EE_Venue |
|
| 712 | + { |
|
| 713 | + return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + |
|
| 717 | + /** |
|
| 718 | + * Removes a venue from the event |
|
| 719 | + * |
|
| 720 | + * @param EE_Venue /int $venue_id_or_obj |
|
| 721 | + * @return EE_Base_Class|EE_Venue |
|
| 722 | + * @throws EE_Error |
|
| 723 | + * @throws ReflectionException |
|
| 724 | + */ |
|
| 725 | + public function remove_venue($venue_id_or_obj): EE_Venue |
|
| 726 | + { |
|
| 727 | + $venue_id_or_obj = ! empty($venue_id_or_obj) ? $venue_id_or_obj : $this->venue(); |
|
| 728 | + return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + |
|
| 732 | + /** |
|
| 733 | + * Gets the venue related to the event. May provide additional $query_params if desired |
|
| 734 | + * |
|
| 735 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 736 | + * @return int |
|
| 737 | + * @throws EE_Error |
|
| 738 | + * @throws ReflectionException |
|
| 739 | + */ |
|
| 740 | + public function venue_ID(array $query_params = array()): int |
|
| 741 | + { |
|
| 742 | + $venue = $this->get_first_related('Venue', $query_params); |
|
| 743 | + return $venue instanceof EE_Venue ? $venue->ID() : 0; |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + |
|
| 747 | + /** |
|
| 748 | + * Gets the venue related to the event. May provide additional $query_params if desired |
|
| 749 | + * |
|
| 750 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 751 | + * @return EE_Base_Class|EE_Venue |
|
| 752 | + * @throws EE_Error |
|
| 753 | + * @throws ReflectionException |
|
| 754 | + */ |
|
| 755 | + public function venue(array $query_params = array()) |
|
| 756 | + { |
|
| 757 | + return $this->get_first_related('Venue', $query_params); |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + |
|
| 761 | + /** |
|
| 762 | + * @param array $query_params |
|
| 763 | + * @return EE_Base_Class[]|EE_Venue[] |
|
| 764 | + * @throws EE_Error |
|
| 765 | + * @throws ReflectionException |
|
| 766 | + * @deprecated $VID:$ |
|
| 767 | + */ |
|
| 768 | + public function venues(array $query_params = array()): array |
|
| 769 | + { |
|
| 770 | + return [$this->venue($query_params)]; |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + |
|
| 774 | + /** |
|
| 775 | + * check if event id is present and if event is published |
|
| 776 | + * |
|
| 777 | + * @access public |
|
| 778 | + * @return boolean true yes, false no |
|
| 779 | + * @throws EE_Error |
|
| 780 | + * @throws ReflectionException |
|
| 781 | + */ |
|
| 782 | + private function _has_ID_and_is_published() |
|
| 783 | + { |
|
| 784 | + // first check if event id is present and not NULL, |
|
| 785 | + // then check if this event is published (or any of the equivalent "published" statuses) |
|
| 786 | + return |
|
| 787 | + $this->ID() && $this->ID() !== null |
|
| 788 | + && ( |
|
| 789 | + $this->status() === 'publish' |
|
| 790 | + || $this->status() === EEM_Event::sold_out |
|
| 791 | + || $this->status() === EEM_Event::postponed |
|
| 792 | + || $this->status() === EEM_Event::cancelled |
|
| 793 | + ); |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + |
|
| 797 | + /** |
|
| 798 | + * This simply compares the internal dates with NOW and determines if the event is upcoming or not. |
|
| 799 | + * |
|
| 800 | + * @access public |
|
| 801 | + * @return boolean true yes, false no |
|
| 802 | + * @throws EE_Error |
|
| 803 | + * @throws ReflectionException |
|
| 804 | + */ |
|
| 805 | + public function is_upcoming() |
|
| 806 | + { |
|
| 807 | + // check if event id is present and if this event is published |
|
| 808 | + if ($this->is_inactive()) { |
|
| 809 | + return false; |
|
| 810 | + } |
|
| 811 | + // set initial value |
|
| 812 | + $upcoming = false; |
|
| 813 | + // next let's get all datetimes and loop through them |
|
| 814 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
| 815 | + foreach ($datetimes as $datetime) { |
|
| 816 | + if ($datetime instanceof EE_Datetime) { |
|
| 817 | + // if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
|
| 818 | + if ($datetime->is_expired()) { |
|
| 819 | + continue; |
|
| 820 | + } |
|
| 821 | + // if this dtt is active then we return false. |
|
| 822 | + if ($datetime->is_active()) { |
|
| 823 | + return false; |
|
| 824 | + } |
|
| 825 | + // otherwise let's check upcoming status |
|
| 826 | + $upcoming = $datetime->is_upcoming(); |
|
| 827 | + } |
|
| 828 | + } |
|
| 829 | + return $upcoming; |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + |
|
| 833 | + /** |
|
| 834 | + * @return bool |
|
| 835 | + * @throws EE_Error |
|
| 836 | + * @throws ReflectionException |
|
| 837 | + */ |
|
| 838 | + public function is_active() |
|
| 839 | + { |
|
| 840 | + // check if event id is present and if this event is published |
|
| 841 | + if ($this->is_inactive()) { |
|
| 842 | + return false; |
|
| 843 | + } |
|
| 844 | + // set initial value |
|
| 845 | + $active = false; |
|
| 846 | + // next let's get all datetimes and loop through them |
|
| 847 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
| 848 | + foreach ($datetimes as $datetime) { |
|
| 849 | + if ($datetime instanceof EE_Datetime) { |
|
| 850 | + // if this dtt is expired then we continue cause one of the other datetimes might be active. |
|
| 851 | + if ($datetime->is_expired()) { |
|
| 852 | + continue; |
|
| 853 | + } |
|
| 854 | + // if this dtt is upcoming then we return false. |
|
| 855 | + if ($datetime->is_upcoming()) { |
|
| 856 | + return false; |
|
| 857 | + } |
|
| 858 | + // otherwise let's check active status |
|
| 859 | + $active = $datetime->is_active(); |
|
| 860 | + } |
|
| 861 | + } |
|
| 862 | + return $active; |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + |
|
| 866 | + /** |
|
| 867 | + * @return bool |
|
| 868 | + * @throws EE_Error |
|
| 869 | + * @throws ReflectionException |
|
| 870 | + */ |
|
| 871 | + public function is_expired() |
|
| 872 | + { |
|
| 873 | + // check if event id is present and if this event is published |
|
| 874 | + if ($this->is_inactive()) { |
|
| 875 | + return false; |
|
| 876 | + } |
|
| 877 | + // set initial value |
|
| 878 | + $expired = false; |
|
| 879 | + // first let's get all datetimes and loop through them |
|
| 880 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
| 881 | + foreach ($datetimes as $datetime) { |
|
| 882 | + if ($datetime instanceof EE_Datetime) { |
|
| 883 | + // if this dtt is upcoming or active then we return false. |
|
| 884 | + if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
| 885 | + return false; |
|
| 886 | + } |
|
| 887 | + // otherwise let's check active status |
|
| 888 | + $expired = $datetime->is_expired(); |
|
| 889 | + } |
|
| 890 | + } |
|
| 891 | + return $expired; |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + |
|
| 895 | + /** |
|
| 896 | + * @return bool |
|
| 897 | + * @throws EE_Error |
|
| 898 | + */ |
|
| 899 | + public function is_inactive() |
|
| 900 | + { |
|
| 901 | + // check if event id is present and if this event is published |
|
| 902 | + if ($this->_has_ID_and_is_published()) { |
|
| 903 | + return false; |
|
| 904 | + } |
|
| 905 | + return true; |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + |
|
| 909 | + /** |
|
| 910 | + * calculate spaces remaining based on "saleable" tickets |
|
| 911 | + * |
|
| 912 | + * @param array $tickets |
|
| 913 | + * @param bool $filtered |
|
| 914 | + * @return int|float |
|
| 915 | + * @throws EE_Error |
|
| 916 | + * @throws DomainException |
|
| 917 | + * @throws UnexpectedEntityException |
|
| 918 | + */ |
|
| 919 | + public function spaces_remaining($tickets = array(), $filtered = true) |
|
| 920 | + { |
|
| 921 | + $this->getAvailableSpacesCalculator()->setActiveTickets($tickets); |
|
| 922 | + $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining(); |
|
| 923 | + return $filtered |
|
| 924 | + ? apply_filters( |
|
| 925 | + 'FHEE_EE_Event__spaces_remaining', |
|
| 926 | + $spaces_remaining, |
|
| 927 | + $this, |
|
| 928 | + $tickets |
|
| 929 | + ) |
|
| 930 | + : $spaces_remaining; |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + |
|
| 934 | + /** |
|
| 935 | + * perform_sold_out_status_check |
|
| 936 | + * checks all of this events's datetime reg_limit - sold values to determine if ANY datetimes have spaces |
|
| 937 | + * available... if NOT, then the event status will get toggled to 'sold_out' |
|
| 938 | + * |
|
| 939 | + * @return bool return the ACTUAL sold out state. |
|
| 940 | + * @throws EE_Error |
|
| 941 | + * @throws DomainException |
|
| 942 | + * @throws UnexpectedEntityException |
|
| 943 | + * @throws ReflectionException |
|
| 944 | + */ |
|
| 945 | + public function perform_sold_out_status_check() |
|
| 946 | + { |
|
| 947 | + // get all tickets |
|
| 948 | + $tickets = $this->tickets( |
|
| 949 | + array( |
|
| 950 | + 'default_where_conditions' => 'none', |
|
| 951 | + 'order_by' => array('TKT_qty' => 'ASC'), |
|
| 952 | + ) |
|
| 953 | + ); |
|
| 954 | + $all_expired = true; |
|
| 955 | + foreach ($tickets as $ticket) { |
|
| 956 | + if (! $ticket->is_expired()) { |
|
| 957 | + $all_expired = false; |
|
| 958 | + break; |
|
| 959 | + } |
|
| 960 | + } |
|
| 961 | + // if all the tickets are just expired, then don't update the event status to sold out |
|
| 962 | + if ($all_expired) { |
|
| 963 | + return true; |
|
| 964 | + } |
|
| 965 | + $spaces_remaining = $this->spaces_remaining($tickets); |
|
| 966 | + if ($spaces_remaining < 1) { |
|
| 967 | + if ($this->status() !== EEM_Event::post_status_private) { |
|
| 968 | + $this->set_status(EEM_Event::sold_out); |
|
| 969 | + $this->save(); |
|
| 970 | + } |
|
| 971 | + $sold_out = true; |
|
| 972 | + } else { |
|
| 973 | + $sold_out = false; |
|
| 974 | + // was event previously marked as sold out ? |
|
| 975 | + if ($this->status() === EEM_Event::sold_out) { |
|
| 976 | + // revert status to previous value, if it was set |
|
| 977 | + $previous_event_status = $this->get_post_meta('_previous_event_status', true); |
|
| 978 | + if ($previous_event_status) { |
|
| 979 | + $this->set_status($previous_event_status); |
|
| 980 | + $this->save(); |
|
| 981 | + } |
|
| 982 | + } |
|
| 983 | + } |
|
| 984 | + do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets); |
|
| 985 | + return $sold_out; |
|
| 986 | + } |
|
| 987 | + |
|
| 988 | + |
|
| 989 | + /** |
|
| 990 | + * This returns the total remaining spaces for sale on this event. |
|
| 991 | + * |
|
| 992 | + * @uses EE_Event::total_available_spaces() |
|
| 993 | + * @return float|int |
|
| 994 | + * @throws EE_Error |
|
| 995 | + * @throws DomainException |
|
| 996 | + * @throws UnexpectedEntityException |
|
| 997 | + */ |
|
| 998 | + public function spaces_remaining_for_sale() |
|
| 999 | + { |
|
| 1000 | + return $this->total_available_spaces(true); |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + |
|
| 1004 | + /** |
|
| 1005 | + * This returns the total spaces available for an event |
|
| 1006 | + * while considering all the qtys on the tickets and the reg limits |
|
| 1007 | + * on the datetimes attached to this event. |
|
| 1008 | + * |
|
| 1009 | + * @param bool $consider_sold Whether to consider any tickets that have already sold in our calculation. |
|
| 1010 | + * If this is false, then we return the most tickets that could ever be sold |
|
| 1011 | + * for this event with the datetime and tickets setup on the event under optimal |
|
| 1012 | + * selling conditions. Otherwise we return a live calculation of spaces available |
|
| 1013 | + * based on tickets sold. Depending on setup and stage of sales, this |
|
| 1014 | + * may appear to equal remaining tickets. However, the more tickets are |
|
| 1015 | + * sold out, the more accurate the "live" total is. |
|
| 1016 | + * @return float|int |
|
| 1017 | + * @throws EE_Error |
|
| 1018 | + * @throws DomainException |
|
| 1019 | + * @throws UnexpectedEntityException |
|
| 1020 | + */ |
|
| 1021 | + public function total_available_spaces($consider_sold = false) |
|
| 1022 | + { |
|
| 1023 | + $spaces_available = $consider_sold |
|
| 1024 | + ? $this->getAvailableSpacesCalculator()->spacesRemaining() |
|
| 1025 | + : $this->getAvailableSpacesCalculator()->totalSpacesAvailable(); |
|
| 1026 | + return apply_filters( |
|
| 1027 | + 'FHEE_EE_Event__total_available_spaces__spaces_available', |
|
| 1028 | + $spaces_available, |
|
| 1029 | + $this, |
|
| 1030 | + $this->getAvailableSpacesCalculator()->getDatetimes(), |
|
| 1031 | + $this->getAvailableSpacesCalculator()->getActiveTickets() |
|
| 1032 | + ); |
|
| 1033 | + } |
|
| 1034 | + |
|
| 1035 | + |
|
| 1036 | + /** |
|
| 1037 | + * Checks if the event is set to sold out |
|
| 1038 | + * |
|
| 1039 | + * @param bool $actual whether or not to perform calculations to not only figure the |
|
| 1040 | + * actual status but also to flip the status if necessary to sold |
|
| 1041 | + * out If false, we just check the existing status of the event |
|
| 1042 | + * @return boolean |
|
| 1043 | + * @throws EE_Error |
|
| 1044 | + */ |
|
| 1045 | + public function is_sold_out($actual = false) |
|
| 1046 | + { |
|
| 1047 | + if (! $actual) { |
|
| 1048 | + return $this->status() === EEM_Event::sold_out; |
|
| 1049 | + } |
|
| 1050 | + return $this->perform_sold_out_status_check(); |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + |
|
| 1054 | + /** |
|
| 1055 | + * Checks if the event is marked as postponed |
|
| 1056 | + * |
|
| 1057 | + * @return boolean |
|
| 1058 | + */ |
|
| 1059 | + public function is_postponed() |
|
| 1060 | + { |
|
| 1061 | + return $this->status() === EEM_Event::postponed; |
|
| 1062 | + } |
|
| 1063 | + |
|
| 1064 | + |
|
| 1065 | + /** |
|
| 1066 | + * Checks if the event is marked as cancelled |
|
| 1067 | + * |
|
| 1068 | + * @return boolean |
|
| 1069 | + */ |
|
| 1070 | + public function is_cancelled() |
|
| 1071 | + { |
|
| 1072 | + return $this->status() === EEM_Event::cancelled; |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + |
|
| 1076 | + /** |
|
| 1077 | + * Get the logical active status in a hierarchical order for all the datetimes. Note |
|
| 1078 | + * Basically, we order the datetimes by EVT_start_date. Then first test on whether the event is published. If its |
|
| 1079 | + * NOT published then we test for whether its expired or not. IF it IS published then we test first on whether an |
|
| 1080 | + * event has any active dates. If no active dates then we check for any upcoming dates. If no upcoming dates then |
|
| 1081 | + * the event is considered expired. |
|
| 1082 | + * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published. Sold Out is a |
|
| 1083 | + * status set on the EVENT when it is not published and thus is done |
|
| 1084 | + * |
|
| 1085 | + * @param bool $reset |
|
| 1086 | + * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
|
| 1087 | + * @throws EE_Error |
|
| 1088 | + * @throws ReflectionException |
|
| 1089 | + */ |
|
| 1090 | + public function get_active_status($reset = false) |
|
| 1091 | + { |
|
| 1092 | + // if the active status has already been set, then just use that value (unless we are resetting it) |
|
| 1093 | + if (! empty($this->_active_status) && ! $reset) { |
|
| 1094 | + return $this->_active_status; |
|
| 1095 | + } |
|
| 1096 | + // first check if event id is present on this object |
|
| 1097 | + if (! $this->ID()) { |
|
| 1098 | + return false; |
|
| 1099 | + } |
|
| 1100 | + $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
|
| 1101 | + // if event is published: |
|
| 1102 | + if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) { |
|
| 1103 | + // active? |
|
| 1104 | + if ( |
|
| 1105 | + EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1106 | + EE_Datetime::active, |
|
| 1107 | + $where_params_for_event |
|
| 1108 | + ) > 0 |
|
| 1109 | + ) { |
|
| 1110 | + $this->_active_status = EE_Datetime::active; |
|
| 1111 | + } else { |
|
| 1112 | + // upcoming? |
|
| 1113 | + if ( |
|
| 1114 | + EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1115 | + EE_Datetime::upcoming, |
|
| 1116 | + $where_params_for_event |
|
| 1117 | + ) > 0 |
|
| 1118 | + ) { |
|
| 1119 | + $this->_active_status = EE_Datetime::upcoming; |
|
| 1120 | + } else { |
|
| 1121 | + // expired? |
|
| 1122 | + if ( |
|
| 1123 | + EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1124 | + EE_Datetime::expired, |
|
| 1125 | + $where_params_for_event |
|
| 1126 | + ) > 0 |
|
| 1127 | + ) { |
|
| 1128 | + $this->_active_status = EE_Datetime::expired; |
|
| 1129 | + } else { |
|
| 1130 | + // it would be odd if things make it this far because it basically means there are no datetime's |
|
| 1131 | + // attached to the event. So in this case it will just be considered inactive. |
|
| 1132 | + $this->_active_status = EE_Datetime::inactive; |
|
| 1133 | + } |
|
| 1134 | + } |
|
| 1135 | + } |
|
| 1136 | + } else { |
|
| 1137 | + // the event is not published, so let's just set it's active status according to its' post status |
|
| 1138 | + switch ($this->status()) { |
|
| 1139 | + case EEM_Event::sold_out: |
|
| 1140 | + $this->_active_status = EE_Datetime::sold_out; |
|
| 1141 | + break; |
|
| 1142 | + case EEM_Event::cancelled: |
|
| 1143 | + $this->_active_status = EE_Datetime::cancelled; |
|
| 1144 | + break; |
|
| 1145 | + case EEM_Event::postponed: |
|
| 1146 | + $this->_active_status = EE_Datetime::postponed; |
|
| 1147 | + break; |
|
| 1148 | + default: |
|
| 1149 | + $this->_active_status = EE_Datetime::inactive; |
|
| 1150 | + } |
|
| 1151 | + } |
|
| 1152 | + return $this->_active_status; |
|
| 1153 | + } |
|
| 1154 | + |
|
| 1155 | + |
|
| 1156 | + /** |
|
| 1157 | + * pretty_active_status |
|
| 1158 | + * |
|
| 1159 | + * @access public |
|
| 1160 | + * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
|
| 1161 | + * @return mixed void|string |
|
| 1162 | + * @throws EE_Error |
|
| 1163 | + * @throws ReflectionException |
|
| 1164 | + */ |
|
| 1165 | + public function pretty_active_status($echo = true) |
|
| 1166 | + { |
|
| 1167 | + $active_status = $this->get_active_status(); |
|
| 1168 | + $status = '<span class="ee-status ee-status-bg--' . esc_attr($active_status) . ' event-active-status--' . |
|
| 1169 | + esc_attr($active_status) . '">' |
|
| 1170 | + . EEH_Template::pretty_status($active_status, false, 'sentence') |
|
| 1171 | + . '</span>'; |
|
| 1172 | + if ($echo) { |
|
| 1173 | + echo $status; // already escaped |
|
| 1174 | + return ''; |
|
| 1175 | + } |
|
| 1176 | + return $status; // already escaped |
|
| 1177 | + } |
|
| 1178 | + |
|
| 1179 | + |
|
| 1180 | + /** |
|
| 1181 | + * @return bool|int |
|
| 1182 | + * @throws EE_Error |
|
| 1183 | + * @throws ReflectionException |
|
| 1184 | + */ |
|
| 1185 | + public function get_number_of_tickets_sold() |
|
| 1186 | + { |
|
| 1187 | + $tkt_sold = 0; |
|
| 1188 | + if (! $this->ID()) { |
|
| 1189 | + return 0; |
|
| 1190 | + } |
|
| 1191 | + $datetimes = $this->datetimes(); |
|
| 1192 | + foreach ($datetimes as $datetime) { |
|
| 1193 | + if ($datetime instanceof EE_Datetime) { |
|
| 1194 | + $tkt_sold += $datetime->sold(); |
|
| 1195 | + } |
|
| 1196 | + } |
|
| 1197 | + return $tkt_sold; |
|
| 1198 | + } |
|
| 1199 | + |
|
| 1200 | + |
|
| 1201 | + /** |
|
| 1202 | + * This just returns a count of all the registrations for this event |
|
| 1203 | + * |
|
| 1204 | + * @access public |
|
| 1205 | + * @return int |
|
| 1206 | + * @throws EE_Error |
|
| 1207 | + */ |
|
| 1208 | + public function get_count_of_all_registrations() |
|
| 1209 | + { |
|
| 1210 | + return EEM_Event::instance()->count_related($this, 'Registration'); |
|
| 1211 | + } |
|
| 1212 | + |
|
| 1213 | + |
|
| 1214 | + /** |
|
| 1215 | + * This returns the ticket with the earliest start time that is |
|
| 1216 | + * available for this event (across all datetimes attached to the event) |
|
| 1217 | + * |
|
| 1218 | + * @return EE_Base_Class|EE_Ticket|null |
|
| 1219 | + * @throws EE_Error |
|
| 1220 | + * @throws ReflectionException |
|
| 1221 | + */ |
|
| 1222 | + public function get_ticket_with_earliest_start_time() |
|
| 1223 | + { |
|
| 1224 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1225 | + $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
| 1226 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + |
|
| 1230 | + /** |
|
| 1231 | + * This returns the ticket with the latest end time that is available |
|
| 1232 | + * for this event (across all datetimes attached to the event) |
|
| 1233 | + * |
|
| 1234 | + * @return EE_Base_Class|EE_Ticket|null |
|
| 1235 | + * @throws EE_Error |
|
| 1236 | + * @throws ReflectionException |
|
| 1237 | + */ |
|
| 1238 | + public function get_ticket_with_latest_end_time() |
|
| 1239 | + { |
|
| 1240 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1241 | + $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
| 1242 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1243 | + } |
|
| 1244 | + |
|
| 1245 | + |
|
| 1246 | + /** |
|
| 1247 | + * This returns the number of different ticket types currently on sale for this event. |
|
| 1248 | + * |
|
| 1249 | + * @return int |
|
| 1250 | + * @throws EE_Error |
|
| 1251 | + * @throws ReflectionException |
|
| 1252 | + */ |
|
| 1253 | + public function countTicketsOnSale() |
|
| 1254 | + { |
|
| 1255 | + $where = array( |
|
| 1256 | + 'Datetime.EVT_ID' => $this->ID(), |
|
| 1257 | + 'TKT_start_date' => array('<', time()), |
|
| 1258 | + 'TKT_end_date' => array('>', time()), |
|
| 1259 | + ); |
|
| 1260 | + return EEM_Ticket::instance()->count(array($where)); |
|
| 1261 | + } |
|
| 1262 | + |
|
| 1263 | + |
|
| 1264 | + /** |
|
| 1265 | + * This returns whether there are any tickets on sale for this event. |
|
| 1266 | + * |
|
| 1267 | + * @return bool true = YES tickets on sale. |
|
| 1268 | + * @throws EE_Error |
|
| 1269 | + */ |
|
| 1270 | + public function tickets_on_sale() |
|
| 1271 | + { |
|
| 1272 | + return $this->countTicketsOnSale() > 0; |
|
| 1273 | + } |
|
| 1274 | + |
|
| 1275 | + |
|
| 1276 | + /** |
|
| 1277 | + * Gets the URL for viewing this event on the front-end. Overrides parent |
|
| 1278 | + * to check for an external URL first |
|
| 1279 | + * |
|
| 1280 | + * @return string |
|
| 1281 | + * @throws EE_Error |
|
| 1282 | + */ |
|
| 1283 | + public function get_permalink() |
|
| 1284 | + { |
|
| 1285 | + if ($this->external_url()) { |
|
| 1286 | + return $this->external_url(); |
|
| 1287 | + } |
|
| 1288 | + return parent::get_permalink(); |
|
| 1289 | + } |
|
| 1290 | + |
|
| 1291 | + |
|
| 1292 | + /** |
|
| 1293 | + * Gets the first term for 'espresso_event_categories' we can find |
|
| 1294 | + * |
|
| 1295 | + * @param array $query_params @see |
|
| 1296 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1297 | + * @return EE_Base_Class|EE_Term|null |
|
| 1298 | + * @throws EE_Error |
|
| 1299 | + * @throws ReflectionException |
|
| 1300 | + */ |
|
| 1301 | + public function first_event_category($query_params = array()) |
|
| 1302 | + { |
|
| 1303 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1304 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1305 | + return EEM_Term::instance()->get_one($query_params); |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + |
|
| 1309 | + /** |
|
| 1310 | + * Gets all terms for 'espresso_event_categories' we can find |
|
| 1311 | + * |
|
| 1312 | + * @param array $query_params |
|
| 1313 | + * @return EE_Base_Class[]|EE_Term[] |
|
| 1314 | + * @throws EE_Error |
|
| 1315 | + * @throws ReflectionException |
|
| 1316 | + */ |
|
| 1317 | + public function get_all_event_categories($query_params = array()) |
|
| 1318 | + { |
|
| 1319 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1320 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1321 | + return EEM_Term::instance()->get_all($query_params); |
|
| 1322 | + } |
|
| 1323 | + |
|
| 1324 | + |
|
| 1325 | + /** |
|
| 1326 | + * Adds a question group to this event |
|
| 1327 | + * |
|
| 1328 | + * @param EE_Question_Group|int $question_group_id_or_obj |
|
| 1329 | + * @param bool $for_primary if true, the question group will be added for the primary |
|
| 1330 | + * registrant, if false will be added for others. default: false |
|
| 1331 | + * @return EE_Base_Class|EE_Question_Group |
|
| 1332 | + * @throws EE_Error |
|
| 1333 | + * @throws InvalidArgumentException |
|
| 1334 | + * @throws InvalidDataTypeException |
|
| 1335 | + * @throws InvalidInterfaceException |
|
| 1336 | + * @throws ReflectionException |
|
| 1337 | + */ |
|
| 1338 | + public function add_question_group($question_group_id_or_obj, $for_primary = false) |
|
| 1339 | + { |
|
| 1340 | + // If the row already exists, it will be updated. If it doesn't, it will be inserted. |
|
| 1341 | + // That's in EE_HABTM_Relation::add_relation_to(). |
|
| 1342 | + return $this->_add_relation_to( |
|
| 1343 | + $question_group_id_or_obj, |
|
| 1344 | + 'Question_Group', |
|
| 1345 | + [ |
|
| 1346 | + EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary) => true |
|
| 1347 | + ] |
|
| 1348 | + ); |
|
| 1349 | + } |
|
| 1350 | + |
|
| 1351 | + |
|
| 1352 | + /** |
|
| 1353 | + * Removes a question group from the event |
|
| 1354 | + * |
|
| 1355 | + * @param EE_Question_Group|int $question_group_id_or_obj |
|
| 1356 | + * @param bool $for_primary if true, the question group will be removed from the primary |
|
| 1357 | + * registrant, if false will be removed from others. default: false |
|
| 1358 | + * @return EE_Base_Class|EE_Question_Group |
|
| 1359 | + * @throws EE_Error |
|
| 1360 | + * @throws InvalidArgumentException |
|
| 1361 | + * @throws ReflectionException |
|
| 1362 | + * @throws InvalidDataTypeException |
|
| 1363 | + * @throws InvalidInterfaceException |
|
| 1364 | + */ |
|
| 1365 | + public function remove_question_group($question_group_id_or_obj, $for_primary = false) |
|
| 1366 | + { |
|
| 1367 | + // If the question group is used for the other type (primary or additional) |
|
| 1368 | + // then just update it. If not, delete it outright. |
|
| 1369 | + $existing_relation = $this->get_first_related( |
|
| 1370 | + 'Event_Question_Group', |
|
| 1371 | + [ |
|
| 1372 | + [ |
|
| 1373 | + 'QSG_ID' => EEM_Question_Group::instance()->ensure_is_ID($question_group_id_or_obj) |
|
| 1374 | + ] |
|
| 1375 | + ] |
|
| 1376 | + ); |
|
| 1377 | + $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary); |
|
| 1378 | + $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary); |
|
| 1379 | + if ($existing_relation->get($other_field) === false) { |
|
| 1380 | + // Delete it. It's now no longer for primary or additional question groups. |
|
| 1381 | + return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group'); |
|
| 1382 | + } |
|
| 1383 | + // Just update it. They'll still use this question group for the other category |
|
| 1384 | + $existing_relation->save( |
|
| 1385 | + [ |
|
| 1386 | + $field_to_update => false |
|
| 1387 | + ] |
|
| 1388 | + ); |
|
| 1389 | + } |
|
| 1390 | + |
|
| 1391 | + |
|
| 1392 | + /** |
|
| 1393 | + * Gets all the question groups, ordering them by QSG_order ascending |
|
| 1394 | + * |
|
| 1395 | + * @param array $query_params @see |
|
| 1396 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1397 | + * @return EE_Base_Class[]|EE_Question_Group[] |
|
| 1398 | + * @throws EE_Error |
|
| 1399 | + * @throws ReflectionException |
|
| 1400 | + */ |
|
| 1401 | + public function question_groups($query_params = array()) |
|
| 1402 | + { |
|
| 1403 | + $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
| 1404 | + return $this->get_many_related('Question_Group', $query_params); |
|
| 1405 | + } |
|
| 1406 | + |
|
| 1407 | + |
|
| 1408 | + /** |
|
| 1409 | + * Implementation for EEI_Has_Icon interface method. |
|
| 1410 | + * |
|
| 1411 | + * @see EEI_Visual_Representation for comments |
|
| 1412 | + * @return string |
|
| 1413 | + */ |
|
| 1414 | + public function get_icon() |
|
| 1415 | + { |
|
| 1416 | + return '<span class="dashicons dashicons-flag"></span>'; |
|
| 1417 | + } |
|
| 1418 | + |
|
| 1419 | + |
|
| 1420 | + /** |
|
| 1421 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1422 | + * |
|
| 1423 | + * @see EEI_Admin_Links for comments |
|
| 1424 | + * @return string |
|
| 1425 | + * @throws EE_Error |
|
| 1426 | + */ |
|
| 1427 | + public function get_admin_details_link() |
|
| 1428 | + { |
|
| 1429 | + return $this->get_admin_edit_link(); |
|
| 1430 | + } |
|
| 1431 | + |
|
| 1432 | + |
|
| 1433 | + /** |
|
| 1434 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1435 | + * |
|
| 1436 | + * @return string |
|
| 1437 | + * @throws EE_Error*@throws ReflectionException |
|
| 1438 | + * @see EEI_Admin_Links for comments |
|
| 1439 | + */ |
|
| 1440 | + public function get_admin_edit_link() |
|
| 1441 | + { |
|
| 1442 | + return EEH_URL::add_query_args_and_nonce( |
|
| 1443 | + array( |
|
| 1444 | + 'page' => 'espresso_events', |
|
| 1445 | + 'action' => 'edit', |
|
| 1446 | + 'post' => $this->ID(), |
|
| 1447 | + ), |
|
| 1448 | + admin_url('admin.php') |
|
| 1449 | + ); |
|
| 1450 | + } |
|
| 1451 | + |
|
| 1452 | + |
|
| 1453 | + /** |
|
| 1454 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1455 | + * |
|
| 1456 | + * @see EEI_Admin_Links for comments |
|
| 1457 | + * @return string |
|
| 1458 | + */ |
|
| 1459 | + public function get_admin_settings_link() |
|
| 1460 | + { |
|
| 1461 | + return EEH_URL::add_query_args_and_nonce( |
|
| 1462 | + array( |
|
| 1463 | + 'page' => 'espresso_events', |
|
| 1464 | + 'action' => 'default_event_settings', |
|
| 1465 | + ), |
|
| 1466 | + admin_url('admin.php') |
|
| 1467 | + ); |
|
| 1468 | + } |
|
| 1469 | + |
|
| 1470 | + |
|
| 1471 | + /** |
|
| 1472 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1473 | + * |
|
| 1474 | + * @see EEI_Admin_Links for comments |
|
| 1475 | + * @return string |
|
| 1476 | + */ |
|
| 1477 | + public function get_admin_overview_link() |
|
| 1478 | + { |
|
| 1479 | + return EEH_URL::add_query_args_and_nonce( |
|
| 1480 | + array( |
|
| 1481 | + 'page' => 'espresso_events', |
|
| 1482 | + 'action' => 'default', |
|
| 1483 | + ), |
|
| 1484 | + admin_url('admin.php') |
|
| 1485 | + ); |
|
| 1486 | + } |
|
| 1487 | + |
|
| 1488 | + |
|
| 1489 | + /** |
|
| 1490 | + * @return string|null |
|
| 1491 | + * @throws EE_Error |
|
| 1492 | + * @throws ReflectionException |
|
| 1493 | + */ |
|
| 1494 | + public function registrationFormUuid(): ?string |
|
| 1495 | + { |
|
| 1496 | + return $this->get('FSC_UUID'); |
|
| 1497 | + } |
|
| 1498 | + |
|
| 1499 | + |
|
| 1500 | + /** |
|
| 1501 | + * Gets all the form sections for this event |
|
| 1502 | + * |
|
| 1503 | + * @return EE_Base_Class[]|EE_Form_Section[] |
|
| 1504 | + * @throws EE_Error |
|
| 1505 | + * @throws ReflectionException |
|
| 1506 | + */ |
|
| 1507 | + public function registrationForm() |
|
| 1508 | + { |
|
| 1509 | + $FSC_UUID = $this->registrationFormUuid(); |
|
| 1510 | + |
|
| 1511 | + if (empty($FSC_UUID)) { |
|
| 1512 | + return []; |
|
| 1513 | + } |
|
| 1514 | + |
|
| 1515 | + return EEM_Form_Section::instance()->get_all([ |
|
| 1516 | + [ |
|
| 1517 | + 'OR' => [ |
|
| 1518 | + 'FSC_UUID' => $FSC_UUID, // top level form |
|
| 1519 | + 'FSC_belongsTo' => $FSC_UUID, // child form sections |
|
| 1520 | + ] |
|
| 1521 | + ], |
|
| 1522 | + 'order_by' => ['FSC_order' => 'ASC'], |
|
| 1523 | + ]); |
|
| 1524 | + } |
|
| 1525 | + |
|
| 1526 | + |
|
| 1527 | + /** |
|
| 1528 | + * @param string $UUID |
|
| 1529 | + * @throws EE_Error |
|
| 1530 | + */ |
|
| 1531 | + public function setRegistrationFormUuid(string $UUID): void |
|
| 1532 | + { |
|
| 1533 | + if (! Cuid::isCuid($UUID)) { |
|
| 1534 | + throw new InvalidArgumentException( |
|
| 1535 | + sprintf( |
|
| 1536 | + /* translators: 1: UUID value, 2: UUID generator function. */ |
|
| 1537 | + esc_html__( |
|
| 1538 | + 'The supplied UUID "%1$s" is invalid or missing. Please use %2$s to generate a valid one.', |
|
| 1539 | + 'event_espresso' |
|
| 1540 | + ), |
|
| 1541 | + $UUID, |
|
| 1542 | + '`Cuid::cuid()`' |
|
| 1543 | + ) |
|
| 1544 | + ); |
|
| 1545 | + } |
|
| 1546 | + $this->set('FSC_UUID', $UUID); |
|
| 1547 | + } |
|
| 1548 | 1548 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function getAvailableSpacesCalculator() |
| 76 | 76 | { |
| 77 | - if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
| 77 | + if ( ! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
| 78 | 78 | $this->available_spaces_calculator = new EventSpacesCalculator($this); |
| 79 | 79 | } |
| 80 | 80 | return $this->available_spaces_calculator; |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
| 226 | 226 | { |
| 227 | - if (! empty($this->_Primary_Datetime)) { |
|
| 227 | + if ( ! empty($this->_Primary_Datetime)) { |
|
| 228 | 228 | return $this->_Primary_Datetime; |
| 229 | 229 | } |
| 230 | 230 | $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | { |
| 250 | 250 | // first get all datetimes |
| 251 | 251 | $datetimes = $this->datetimes_ordered(); |
| 252 | - if (! $datetimes) { |
|
| 252 | + if ( ! $datetimes) { |
|
| 253 | 253 | return array(); |
| 254 | 254 | } |
| 255 | 255 | $datetime_ids = array(); |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
| 458 | 458 | { |
| 459 | 459 | $short_desc = $this->get('EVT_short_desc'); |
| 460 | - if (! empty($short_desc) || $not_full_desc) { |
|
| 460 | + if ( ! empty($short_desc) || $not_full_desc) { |
|
| 461 | 461 | return $short_desc; |
| 462 | 462 | } |
| 463 | 463 | $full_desc = $this->get('EVT_desc'); |
@@ -953,7 +953,7 @@ discard block |
||
| 953 | 953 | ); |
| 954 | 954 | $all_expired = true; |
| 955 | 955 | foreach ($tickets as $ticket) { |
| 956 | - if (! $ticket->is_expired()) { |
|
| 956 | + if ( ! $ticket->is_expired()) { |
|
| 957 | 957 | $all_expired = false; |
| 958 | 958 | break; |
| 959 | 959 | } |
@@ -1044,7 +1044,7 @@ discard block |
||
| 1044 | 1044 | */ |
| 1045 | 1045 | public function is_sold_out($actual = false) |
| 1046 | 1046 | { |
| 1047 | - if (! $actual) { |
|
| 1047 | + if ( ! $actual) { |
|
| 1048 | 1048 | return $this->status() === EEM_Event::sold_out; |
| 1049 | 1049 | } |
| 1050 | 1050 | return $this->perform_sold_out_status_check(); |
@@ -1090,11 +1090,11 @@ discard block |
||
| 1090 | 1090 | public function get_active_status($reset = false) |
| 1091 | 1091 | { |
| 1092 | 1092 | // if the active status has already been set, then just use that value (unless we are resetting it) |
| 1093 | - if (! empty($this->_active_status) && ! $reset) { |
|
| 1093 | + if ( ! empty($this->_active_status) && ! $reset) { |
|
| 1094 | 1094 | return $this->_active_status; |
| 1095 | 1095 | } |
| 1096 | 1096 | // first check if event id is present on this object |
| 1097 | - if (! $this->ID()) { |
|
| 1097 | + if ( ! $this->ID()) { |
|
| 1098 | 1098 | return false; |
| 1099 | 1099 | } |
| 1100 | 1100 | $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
@@ -1165,8 +1165,8 @@ discard block |
||
| 1165 | 1165 | public function pretty_active_status($echo = true) |
| 1166 | 1166 | { |
| 1167 | 1167 | $active_status = $this->get_active_status(); |
| 1168 | - $status = '<span class="ee-status ee-status-bg--' . esc_attr($active_status) . ' event-active-status--' . |
|
| 1169 | - esc_attr($active_status) . '">' |
|
| 1168 | + $status = '<span class="ee-status ee-status-bg--'.esc_attr($active_status).' event-active-status--'. |
|
| 1169 | + esc_attr($active_status).'">' |
|
| 1170 | 1170 | . EEH_Template::pretty_status($active_status, false, 'sentence') |
| 1171 | 1171 | . '</span>'; |
| 1172 | 1172 | if ($echo) { |
@@ -1185,7 +1185,7 @@ discard block |
||
| 1185 | 1185 | public function get_number_of_tickets_sold() |
| 1186 | 1186 | { |
| 1187 | 1187 | $tkt_sold = 0; |
| 1188 | - if (! $this->ID()) { |
|
| 1188 | + if ( ! $this->ID()) { |
|
| 1189 | 1189 | return 0; |
| 1190 | 1190 | } |
| 1191 | 1191 | $datetimes = $this->datetimes(); |
@@ -1375,7 +1375,7 @@ discard block |
||
| 1375 | 1375 | ] |
| 1376 | 1376 | ); |
| 1377 | 1377 | $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary); |
| 1378 | - $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary); |
|
| 1378 | + $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext( ! $for_primary); |
|
| 1379 | 1379 | if ($existing_relation->get($other_field) === false) { |
| 1380 | 1380 | // Delete it. It's now no longer for primary or additional question groups. |
| 1381 | 1381 | return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group'); |
@@ -1530,7 +1530,7 @@ discard block |
||
| 1530 | 1530 | */ |
| 1531 | 1531 | public function setRegistrationFormUuid(string $UUID): void |
| 1532 | 1532 | { |
| 1533 | - if (! Cuid::isCuid($UUID)) { |
|
| 1533 | + if ( ! Cuid::isCuid($UUID)) { |
|
| 1534 | 1534 | throw new InvalidArgumentException( |
| 1535 | 1535 | sprintf( |
| 1536 | 1536 | /* translators: 1: UUID value, 2: UUID generator function. */ |
@@ -15,1256 +15,1256 @@ |
||
| 15 | 15 | { |
| 16 | 16 | |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Holds a collection of EE_Message_Template_Pack objects. |
|
| 20 | - * @type EE_Messages_Template_Pack_Collection |
|
| 21 | - */ |
|
| 22 | - protected static $_template_pack_collection; |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @throws EE_Error |
|
| 27 | - */ |
|
| 28 | - private static function _set_autoloader() |
|
| 29 | - { |
|
| 30 | - EED_Messages::set_autoloaders(); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * generate_new_templates |
|
| 36 | - * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 37 | - * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 38 | - * for the event. |
|
| 39 | - * |
|
| 40 | - * @access protected |
|
| 41 | - * @param string $messenger the messenger we are generating templates for |
|
| 42 | - * @param array $message_types array of message types that the templates are generated for. |
|
| 43 | - * @param int $GRP_ID If a non global template is being generated then it is expected we'll have a GRP_ID |
|
| 44 | - * to use as the base for the new generated template. |
|
| 45 | - * @param bool $global true indicates generating templates on messenger activation. false requires GRP_ID |
|
| 46 | - * for event specific template generation. |
|
| 47 | - * @return array @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array |
|
| 48 | - * for templates that are generated. If this is an empty array then it means no templates were |
|
| 49 | - * generated which usually means there was an error. Anything in the array with an empty value for |
|
| 50 | - * `MTP_context` means that it was not a new generated template but just reactivated (which only |
|
| 51 | - * happens for global templates that already exist in the database. |
|
| 52 | - * @throws EE_Error |
|
| 53 | - * @throws ReflectionException |
|
| 54 | - */ |
|
| 55 | - public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 56 | - { |
|
| 57 | - // make sure message_type is an array. |
|
| 58 | - $message_types = (array) $message_types; |
|
| 59 | - $templates = array(); |
|
| 60 | - |
|
| 61 | - if (empty($messenger)) { |
|
| 62 | - throw new EE_Error(esc_html__('We need a messenger to generate templates!', 'event_espresso')); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - // if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files. |
|
| 66 | - if (empty($message_types)) { |
|
| 67 | - throw new EE_Error(esc_html__('We need at least one message type to generate templates!', 'event_espresso')); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - EEH_MSG_Template::_set_autoloader(); |
|
| 71 | - foreach ($message_types as $message_type) { |
|
| 72 | - // if global then let's attempt to get the GRP_ID for this combo IF GRP_ID is empty. |
|
| 73 | - if ($global && empty($GRP_ID)) { |
|
| 74 | - $GRP_ID = EEM_Message_Template_Group::instance()->get_one( |
|
| 75 | - array( |
|
| 76 | - array( |
|
| 77 | - 'MTP_messenger' => $messenger, |
|
| 78 | - 'MTP_message_type' => $message_type, |
|
| 79 | - 'MTP_is_global' => true, |
|
| 80 | - ), |
|
| 81 | - ) |
|
| 82 | - ); |
|
| 83 | - $GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0; |
|
| 84 | - } |
|
| 85 | - // if this is global template generation. |
|
| 86 | - // First let's determine if we already HAVE global templates for this messenger and message_type combination. |
|
| 87 | - // If we do then NO generation!! |
|
| 88 | - if ($global && EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) { |
|
| 89 | - $templates[] = array( |
|
| 90 | - 'GRP_ID' => $GRP_ID, |
|
| 91 | - 'MTP_context' => '', |
|
| 92 | - ); |
|
| 93 | - // we already have generated templates for this so let's go to the next message type. |
|
| 94 | - continue; |
|
| 95 | - } |
|
| 96 | - $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global); |
|
| 97 | - |
|
| 98 | - if (! $new_message_template_group) { |
|
| 99 | - continue; |
|
| 100 | - } |
|
| 101 | - $templates[] = $new_message_template_group; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - return $templates; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * The purpose of this method is to determine if there are already generated templates in the database for the |
|
| 110 | - * given variables. |
|
| 111 | - * |
|
| 112 | - * @param string $messenger messenger |
|
| 113 | - * @param string $message_type message type |
|
| 114 | - * @param int $GRP_ID GRP ID ( if a custom template) (if not provided then we're just doing global |
|
| 115 | - * template check) |
|
| 116 | - * @return bool true = generated, false = hasn't been generated. |
|
| 117 | - * @throws EE_Error |
|
| 118 | - */ |
|
| 119 | - public static function already_generated($messenger, $message_type, $GRP_ID = 0) |
|
| 120 | - { |
|
| 121 | - EEH_MSG_Template::_set_autoloader(); |
|
| 122 | - // what method we use depends on whether we have an GRP_ID or not |
|
| 123 | - $count = empty($GRP_ID) |
|
| 124 | - ? EEM_Message_Template::instance()->count( |
|
| 125 | - array( |
|
| 126 | - array( |
|
| 127 | - 'Message_Template_Group.MTP_messenger' => $messenger, |
|
| 128 | - 'Message_Template_Group.MTP_message_type' => $message_type, |
|
| 129 | - 'Message_Template_Group.MTP_is_global' => true |
|
| 130 | - ) |
|
| 131 | - ) |
|
| 132 | - ) |
|
| 133 | - : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) )); |
|
| 134 | - |
|
| 135 | - return $count > 0; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Updates all message templates matching the incoming messengers and message types to active status. |
|
| 141 | - * |
|
| 142 | - * @static |
|
| 143 | - * @param array $messenger_names Messenger slug |
|
| 144 | - * @param array $message_type_names Message type slug |
|
| 145 | - * @return int count of updated records. |
|
| 146 | - * @throws EE_Error |
|
| 147 | - */ |
|
| 148 | - public static function update_to_active($messenger_names, $message_type_names) |
|
| 149 | - { |
|
| 150 | - $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names ); |
|
| 151 | - $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names ); |
|
| 152 | - return EEM_Message_Template_Group::instance()->update( |
|
| 153 | - array( 'MTP_is_active' => 1 ), |
|
| 154 | - array( |
|
| 155 | - array( |
|
| 156 | - 'MTP_messenger' => array( 'IN', $messenger_names ), |
|
| 157 | - 'MTP_message_type' => array( 'IN', $message_type_names ) |
|
| 158 | - ) |
|
| 159 | - ) |
|
| 160 | - ); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Updates all message template groups matching the incoming arguments to inactive status. |
|
| 166 | - * |
|
| 167 | - * @static |
|
| 168 | - * @param array $messenger_names The messenger slugs. |
|
| 169 | - * If empty then all templates matching the message types are marked inactive. |
|
| 170 | - * Otherwise only templates matching the messengers and message types. |
|
| 171 | - * @param array $message_type_names The message type slugs. |
|
| 172 | - * If empty then all templates matching the messengers are marked inactive. |
|
| 173 | - * Otherwise only templates matching the messengers and message types. |
|
| 174 | - * |
|
| 175 | - * @return int count of updated records. |
|
| 176 | - * @throws EE_Error |
|
| 177 | - */ |
|
| 178 | - public static function update_to_inactive($messenger_names = array(), $message_type_names = array()) |
|
| 179 | - { |
|
| 180 | - return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for( |
|
| 181 | - $messenger_names, |
|
| 182 | - $message_type_names |
|
| 183 | - ); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * The purpose of this function is to return all installed message objects |
|
| 189 | - * (messengers and message type regardless of whether they are ACTIVE or not) |
|
| 190 | - * |
|
| 191 | - * @param string $type |
|
| 192 | - * @return array array consisting of installed messenger objects and installed message type objects. |
|
| 193 | - * @throws EE_Error |
|
| 194 | - * @throws ReflectionException |
|
| 195 | - * @deprecated 4.9.0 |
|
| 196 | - * @static |
|
| 197 | - */ |
|
| 198 | - public static function get_installed_message_objects($type = 'all') |
|
| 199 | - { |
|
| 200 | - self::_set_autoloader(); |
|
| 201 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 202 | - return array( |
|
| 203 | - 'messenger' => $message_resource_manager->installed_messengers(), |
|
| 204 | - 'message_type' => $message_resource_manager->installed_message_types() |
|
| 205 | - ); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * This will return an array of shortcodes => labels from the |
|
| 211 | - * messenger and message_type objects associated with this |
|
| 212 | - * template. |
|
| 213 | - * |
|
| 214 | - * @param string $message_type |
|
| 215 | - * @param string $messenger |
|
| 216 | - * @param array $fields What fields we're returning valid shortcodes for. |
|
| 217 | - * If empty then we assume all fields are to be returned. Optional. |
|
| 218 | - * @param string $context What context we're going to return shortcodes for. Optional. |
|
| 219 | - * @param bool $merged If TRUE then we don't return shortcodes indexed by field, |
|
| 220 | - * but instead an array of the unique shortcodes for all the given ( |
|
| 221 | - * or all) fields. Optional. |
|
| 222 | - * @return array an array of shortcodes in the format |
|
| 223 | - * array( '[shortcode] => 'label') |
|
| 224 | - * OR |
|
| 225 | - * FALSE if no shortcodes found. |
|
| 226 | - * @throws ReflectionException |
|
| 227 | - * @throws EE_Error*@since 4.3.0 |
|
| 228 | - * |
|
| 229 | - */ |
|
| 230 | - public static function get_shortcodes( |
|
| 231 | - $message_type, |
|
| 232 | - $messenger, |
|
| 233 | - $fields = array(), |
|
| 234 | - $context = 'admin', |
|
| 235 | - $merged = false |
|
| 236 | - ) { |
|
| 237 | - $messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger))); |
|
| 238 | - $mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type))); |
|
| 239 | - /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
| 240 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 241 | - // convert slug to object |
|
| 242 | - $messenger = $message_resource_manager->get_messenger($messenger); |
|
| 243 | - |
|
| 244 | - // if messenger isn't a EE_messenger resource then bail. |
|
| 245 | - if (! $messenger instanceof EE_messenger) { |
|
| 246 | - return array(); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - // validate class for getting our list of shortcodes |
|
| 250 | - $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator'; |
|
| 251 | - if (! class_exists($classname)) { |
|
| 252 | - $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); |
|
| 253 | - $msg[] = sprintf( |
|
| 254 | - esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'), |
|
| 255 | - $classname |
|
| 256 | - ); |
|
| 257 | - throw new EE_Error(implode('||', $msg)); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** @type EE_Messages_Validator $_VLD */ |
|
| 261 | - $_VLD = new $classname(array(), $context); |
|
| 262 | - $valid_shortcodes = $_VLD->get_validators(); |
|
| 263 | - |
|
| 264 | - // let's make sure we're only getting the shortcode part of the validators |
|
| 265 | - $shortcodes = array(); |
|
| 266 | - foreach ($valid_shortcodes as $field => $validators) { |
|
| 267 | - $shortcodes[ $field ] = $validators['shortcodes']; |
|
| 268 | - } |
|
| 269 | - $valid_shortcodes = $shortcodes; |
|
| 270 | - |
|
| 271 | - // if not all fields let's make sure we ONLY include the shortcodes for the specified fields. |
|
| 272 | - if (! empty($fields)) { |
|
| 273 | - $specified_shortcodes = array(); |
|
| 274 | - foreach ($fields as $field) { |
|
| 275 | - if (isset($valid_shortcodes[ $field ])) { |
|
| 276 | - $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ]; |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - $valid_shortcodes = $specified_shortcodes; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - // if not merged then let's replace the fields with the localized fields |
|
| 283 | - if (! $merged) { |
|
| 284 | - // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array. |
|
| 285 | - $field_settings = $messenger->get_template_fields(); |
|
| 286 | - $localized = array(); |
|
| 287 | - foreach ($valid_shortcodes as $field => $shortcodes) { |
|
| 288 | - // get localized field label |
|
| 289 | - if (isset($field_settings[ $field ])) { |
|
| 290 | - // possible that this is used as a main field. |
|
| 291 | - if (empty($field_settings[ $field ])) { |
|
| 292 | - if (isset($field_settings['extra'][ $field ])) { |
|
| 293 | - $_field = $field_settings['extra'][ $field ]['main']['label']; |
|
| 294 | - } else { |
|
| 295 | - $_field = $field; |
|
| 296 | - } |
|
| 297 | - } else { |
|
| 298 | - $_field = $field_settings[ $field ]['label']; |
|
| 299 | - } |
|
| 300 | - } elseif (isset($field_settings['extra'])) { |
|
| 301 | - // loop through extra "main fields" and see if any of their children have our field |
|
| 302 | - foreach ($field_settings['extra'] as $fields) { |
|
| 303 | - if (isset($fields[ $field ])) { |
|
| 304 | - $_field = $fields[ $field ]['label']; |
|
| 305 | - } else { |
|
| 306 | - $_field = $field; |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - } else { |
|
| 310 | - $_field = $field; |
|
| 311 | - } |
|
| 312 | - if (isset($_field)) { |
|
| 313 | - $localized[ (string) $_field ] = $shortcodes; |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - $valid_shortcodes = $localized; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - // if $merged then let's merge all the shortcodes into one list NOT indexed by field. |
|
| 320 | - if ($merged) { |
|
| 321 | - $merged_codes = array(); |
|
| 322 | - foreach ($valid_shortcodes as $shortcode) { |
|
| 323 | - foreach ($shortcode as $code => $label) { |
|
| 324 | - if (isset($merged_codes[ $code ])) { |
|
| 325 | - continue; |
|
| 326 | - } else { |
|
| 327 | - $merged_codes[ $code ] = $label; |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - } |
|
| 331 | - $valid_shortcodes = $merged_codes; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - return $valid_shortcodes; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * Get Messenger object. |
|
| 340 | - * |
|
| 341 | - * @param string $messenger messenger slug for the messenger object we want to retrieve. |
|
| 342 | - * @return EE_messenger |
|
| 343 | - * @throws ReflectionException |
|
| 344 | - * @throws EE_Error*@since 4.3.0 |
|
| 345 | - * @deprecated 4.9.0 |
|
| 346 | - */ |
|
| 347 | - public static function messenger_obj($messenger) |
|
| 348 | - { |
|
| 349 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 350 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 351 | - return $Message_Resource_Manager->get_messenger($messenger); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * get Message type object |
|
| 357 | - * |
|
| 358 | - * @param string $message_type the slug for the message type object to retrieve |
|
| 359 | - * @return EE_message_type |
|
| 360 | - * @throws ReflectionException |
|
| 361 | - * @throws EE_Error*@since 4.3.0 |
|
| 362 | - * @deprecated 4.9.0 |
|
| 363 | - */ |
|
| 364 | - public static function message_type_obj($message_type) |
|
| 365 | - { |
|
| 366 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 367 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 368 | - return $Message_Resource_Manager->get_message_type($message_type); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Given a message_type slug, will return whether that message type is active in the system or not. |
|
| 374 | - * |
|
| 375 | - * @since 4.3.0 |
|
| 376 | - * @param string $message_type message type to check for. |
|
| 377 | - * @return boolean |
|
| 378 | - * @throws EE_Error |
|
| 379 | - * @throws ReflectionException |
|
| 380 | - */ |
|
| 381 | - public static function is_mt_active($message_type) |
|
| 382 | - { |
|
| 383 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 384 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 385 | - $active_mts = $Message_Resource_Manager->list_of_active_message_types(); |
|
| 386 | - return in_array($message_type, $active_mts); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Given a messenger slug, will return whether that messenger is active in the system or not. |
|
| 392 | - * |
|
| 393 | - * @since 4.3.0 |
|
| 394 | - * |
|
| 395 | - * @param string $messenger slug for messenger to check. |
|
| 396 | - * @return boolean |
|
| 397 | - * @throws EE_Error |
|
| 398 | - * @throws ReflectionException |
|
| 399 | - */ |
|
| 400 | - public static function is_messenger_active($messenger) |
|
| 401 | - { |
|
| 402 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 403 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 404 | - $active_messenger = $Message_Resource_Manager->get_active_messenger($messenger); |
|
| 405 | - return $active_messenger instanceof EE_messenger; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Used to return active messengers array stored in the wp options table. |
|
| 411 | - * If no value is present in the option then an empty array is returned. |
|
| 412 | - * |
|
| 413 | - * @deprecated 4.9 |
|
| 414 | - * @since 4.3.1 |
|
| 415 | - * |
|
| 416 | - * @return array |
|
| 417 | - * @throws EE_Error |
|
| 418 | - * @throws ReflectionException |
|
| 419 | - */ |
|
| 420 | - public static function get_active_messengers_in_db() |
|
| 421 | - { |
|
| 422 | - EE_Error::doing_it_wrong( |
|
| 423 | - __METHOD__, |
|
| 424 | - esc_html__('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'), |
|
| 425 | - '4.9.0' |
|
| 426 | - ); |
|
| 427 | - /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 428 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 429 | - return $Message_Resource_Manager->get_active_messengers_option(); |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * Used to update the active messengers array stored in the wp options table. |
|
| 435 | - * |
|
| 436 | - * @since 4.3.1 |
|
| 437 | - * @deprecated 4.9.0 |
|
| 438 | - * |
|
| 439 | - * @param array $data_to_save Incoming data to save. |
|
| 440 | - * |
|
| 441 | - * @return bool FALSE if not updated, TRUE if updated. |
|
| 442 | - * @throws EE_Error |
|
| 443 | - * @throws ReflectionException |
|
| 444 | - */ |
|
| 445 | - public static function update_active_messengers_in_db($data_to_save) |
|
| 446 | - { |
|
| 447 | - EE_Error::doing_it_wrong( |
|
| 448 | - __METHOD__, |
|
| 449 | - esc_html__('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'), |
|
| 450 | - '4.9.0' |
|
| 451 | - ); |
|
| 452 | - /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 453 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 454 | - return $Message_Resource_Manager->update_active_messengers_option($data_to_save); |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * This does some validation of incoming params, determines what type of url is being prepped and returns the |
|
| 460 | - * appropriate url trigger |
|
| 461 | - * |
|
| 462 | - * @param EE_message_type $message_type |
|
| 463 | - * @param EE_Message $message |
|
| 464 | - * @param EE_Registration | null $registration The registration object must be included if this |
|
| 465 | - * is going to be a registration trigger url. |
|
| 466 | - * @param string $sending_messenger The (optional) sending messenger for the url. |
|
| 467 | - * |
|
| 468 | - * @return string |
|
| 469 | - * @throws EE_Error |
|
| 470 | - */ |
|
| 471 | - public static function get_url_trigger( |
|
| 472 | - EE_message_type $message_type, |
|
| 473 | - EE_Message $message, |
|
| 474 | - $registration = null, |
|
| 475 | - $sending_messenger = '' |
|
| 476 | - ) { |
|
| 477 | - // first determine if the url can be to the EE_Message object. |
|
| 478 | - if (! $message_type->always_generate()) { |
|
| 479 | - return EEH_MSG_Template::generate_browser_trigger($message); |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - // if $registration object is not valid then exit early because there's nothing that can be generated. |
|
| 483 | - if (! $registration instanceof EE_Registration) { |
|
| 484 | - throw new EE_Error( |
|
| 485 | - esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso') |
|
| 486 | - ); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - // validate given context |
|
| 490 | - $contexts = $message_type->get_contexts(); |
|
| 491 | - if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) { |
|
| 492 | - throw new EE_Error( |
|
| 493 | - sprintf( |
|
| 494 | - esc_html__('The context %s is not a valid context for %s.', 'event_espresso'), |
|
| 495 | - $message->context(), |
|
| 496 | - get_class($message_type) |
|
| 497 | - ) |
|
| 498 | - ); |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - // valid sending messenger but only if sending messenger set. Otherwise generating messenger is used. |
|
| 502 | - if (! empty($sending_messenger)) { |
|
| 503 | - $with_messengers = $message_type->with_messengers(); |
|
| 504 | - if ( |
|
| 505 | - ! isset($with_messengers[ $message->messenger() ]) |
|
| 506 | - || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ]) |
|
| 507 | - ) { |
|
| 508 | - throw new EE_Error( |
|
| 509 | - sprintf( |
|
| 510 | - esc_html__( |
|
| 511 | - 'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s. If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.', |
|
| 512 | - 'event_espresso' |
|
| 513 | - ), |
|
| 514 | - $sending_messenger, |
|
| 515 | - get_class($message_type) |
|
| 516 | - ) |
|
| 517 | - ); |
|
| 518 | - } |
|
| 519 | - } else { |
|
| 520 | - $sending_messenger = $message->messenger(); |
|
| 521 | - } |
|
| 522 | - return EEH_MSG_Template::generate_url_trigger( |
|
| 523 | - $sending_messenger, |
|
| 524 | - $message->messenger(), |
|
| 525 | - $message->context(), |
|
| 526 | - $message->message_type(), |
|
| 527 | - $registration, |
|
| 528 | - $message->GRP_ID() |
|
| 529 | - ); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * This returns the url for triggering a in browser view of a specific EE_Message object. |
|
| 535 | - * @param EE_Message $message |
|
| 536 | - * @return string. |
|
| 537 | - */ |
|
| 538 | - public static function generate_browser_trigger(EE_Message $message) |
|
| 539 | - { |
|
| 540 | - $query_args = array( |
|
| 541 | - 'ee' => 'msg_browser_trigger', |
|
| 542 | - 'token' => $message->MSG_token() |
|
| 543 | - ); |
|
| 544 | - return apply_filters( |
|
| 545 | - 'FHEE__EEH_MSG_Template__generate_browser_trigger', |
|
| 546 | - add_query_arg($query_args, site_url()), |
|
| 547 | - $message |
|
| 548 | - ); |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * This returns the url for triggering an in browser view of the error saved on the incoming message object. |
|
| 558 | - * @param EE_Message $message |
|
| 559 | - * @return string |
|
| 560 | - */ |
|
| 561 | - public static function generate_error_display_trigger(EE_Message $message) |
|
| 562 | - { |
|
| 563 | - return apply_filters( |
|
| 564 | - 'FHEE__EEH_MSG_Template__generate_error_display_trigger', |
|
| 565 | - add_query_arg( |
|
| 566 | - array( |
|
| 567 | - 'ee' => 'msg_browser_error_trigger', |
|
| 568 | - 'token' => $message->MSG_token() |
|
| 569 | - ), |
|
| 570 | - site_url() |
|
| 571 | - ), |
|
| 572 | - $message |
|
| 573 | - ); |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * This generates a url trigger for the msg_url_trigger route using the given arguments |
|
| 579 | - * |
|
| 580 | - * @param string $sending_messenger The sending messenger slug. |
|
| 581 | - * @param string $generating_messenger The generating messenger slug. |
|
| 582 | - * @param string $context The context for the template. |
|
| 583 | - * @param string $message_type The message type slug |
|
| 584 | - * @param EE_Registration $registration |
|
| 585 | - * @param integer $message_template_group id The EE_Message_Template_Group ID for the template. |
|
| 586 | - * @param integer $data_id The id to the EE_Base_Class for getting the data used by the |
|
| 587 | - * trigger. |
|
| 588 | - * @return string The generated url. |
|
| 589 | - * @throws EE_Error |
|
| 590 | - */ |
|
| 591 | - public static function generate_url_trigger( |
|
| 592 | - $sending_messenger, |
|
| 593 | - $generating_messenger, |
|
| 594 | - $context, |
|
| 595 | - $message_type, |
|
| 596 | - EE_Registration $registration, |
|
| 597 | - $message_template_group, |
|
| 598 | - $data_id = 0 |
|
| 599 | - ) { |
|
| 600 | - $query_args = array( |
|
| 601 | - 'ee' => 'msg_url_trigger', |
|
| 602 | - 'snd_msgr' => $sending_messenger, |
|
| 603 | - 'gen_msgr' => $generating_messenger, |
|
| 604 | - 'message_type' => $message_type, |
|
| 605 | - 'context' => $context, |
|
| 606 | - 'token' => $registration->reg_url_link(), |
|
| 607 | - 'GRP_ID' => $message_template_group, |
|
| 608 | - 'id' => $data_id |
|
| 609 | - ); |
|
| 610 | - $url = add_query_arg($query_args, get_home_url()); |
|
| 611 | - |
|
| 612 | - // made it here so now we can just get the url and filter it. Filtered globally and by message type. |
|
| 613 | - return apply_filters( |
|
| 614 | - 'FHEE__EEH_MSG_Template__generate_url_trigger', |
|
| 615 | - $url, |
|
| 616 | - $sending_messenger, |
|
| 617 | - $generating_messenger, |
|
| 618 | - $context, |
|
| 619 | - $message_type, |
|
| 620 | - $registration, |
|
| 621 | - $message_template_group, |
|
| 622 | - $data_id |
|
| 623 | - ); |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - |
|
| 628 | - |
|
| 629 | - /** |
|
| 630 | - * Return the specific css for the action icon given. |
|
| 631 | - * |
|
| 632 | - * @param string $type What action to return. |
|
| 633 | - * @return string[] |
|
| 634 | - * @since 4.9.0 |
|
| 635 | - */ |
|
| 636 | - public static function get_message_action_icon($type) |
|
| 637 | - { |
|
| 638 | - $action_icons = self::get_message_action_icons(); |
|
| 639 | - return isset($action_icons[ $type ]) ? $action_icons[ $type ] : []; |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - |
|
| 643 | - /** |
|
| 644 | - * This is used for retrieving the css classes used for the icons representing message actions. |
|
| 645 | - * |
|
| 646 | - * @since 4.9.0 |
|
| 647 | - * |
|
| 648 | - * @return array |
|
| 649 | - */ |
|
| 650 | - public static function get_message_action_icons() |
|
| 651 | - { |
|
| 652 | - return apply_filters( |
|
| 653 | - 'FHEE__EEH_MSG_Template__message_action_icons', |
|
| 654 | - array( |
|
| 655 | - 'view' => array( |
|
| 656 | - 'label' => esc_html__('View Message', 'event_espresso'), |
|
| 657 | - 'css_class' => 'dashicons dashicons-welcome-view-site', |
|
| 658 | - ), |
|
| 659 | - 'error' => array( |
|
| 660 | - 'label' => esc_html__('View Error Message', 'event_espresso'), |
|
| 661 | - 'css_class' => 'dashicons dashicons-info', |
|
| 662 | - ), |
|
| 663 | - 'see_notifications_for' => array( |
|
| 664 | - 'label' => esc_html__('View Related Messages', 'event_espresso'), |
|
| 665 | - 'css_class' => 'dashicons dashicons-megaphone', |
|
| 666 | - ), |
|
| 667 | - 'generate_now' => array( |
|
| 668 | - 'label' => esc_html__('Generate the message now.', 'event_espresso'), |
|
| 669 | - 'css_class' => 'dashicons dashicons-admin-tools', |
|
| 670 | - ), |
|
| 671 | - 'send_now' => array( |
|
| 672 | - 'label' => esc_html__('Send Immediately', 'event_espresso'), |
|
| 673 | - 'css_class' => 'dashicons dashicons-controls-forward', |
|
| 674 | - ), |
|
| 675 | - 'queue_for_resending' => array( |
|
| 676 | - 'label' => esc_html__('Queue for Resending', 'event_espresso'), |
|
| 677 | - 'css_class' => 'dashicons dashicons-controls-repeat', |
|
| 678 | - ), |
|
| 679 | - 'view_transaction' => array( |
|
| 680 | - 'label' => esc_html__('View related Transaction', 'event_espresso'), |
|
| 681 | - 'css_class' => 'dashicons dashicons-cart', |
|
| 682 | - ) |
|
| 683 | - ) |
|
| 684 | - ); |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * This returns the url for a given action related to EE_Message. |
|
| 690 | - * |
|
| 691 | - * @param string $type What type of action to return the url for. |
|
| 692 | - * @param EE_Message $message Required for generating the correct url for some types. |
|
| 693 | - * @param array $query_params Any additional query params to be included with the generated url. |
|
| 694 | - * |
|
| 695 | - * @return string |
|
| 696 | - * @throws EE_Error |
|
| 697 | - * @throws ReflectionException |
|
| 698 | - * @since 4.9.0 |
|
| 699 | - * |
|
| 700 | - */ |
|
| 701 | - public static function get_message_action_url($type, EE_Message $message = null, $query_params = array()) |
|
| 702 | - { |
|
| 703 | - $action_urls = self::get_message_action_urls($message, $query_params); |
|
| 704 | - return isset($action_urls[ $type ]) ? $action_urls[ $type ] : ''; |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - |
|
| 708 | - /** |
|
| 709 | - * This returns all the current urls for EE_Message actions. |
|
| 710 | - * |
|
| 711 | - * @since 4.9.0 |
|
| 712 | - * |
|
| 713 | - * @param EE_Message $message The EE_Message object required to generate correct urls for some types. |
|
| 714 | - * @param array $query_params Any additional query_params to be included with the generated url. |
|
| 715 | - * |
|
| 716 | - * @return array |
|
| 717 | - * @throws EE_Error |
|
| 718 | - * @throws ReflectionException |
|
| 719 | - */ |
|
| 720 | - public static function get_message_action_urls(EE_Message $message = null, $query_params = array()) |
|
| 721 | - { |
|
| 722 | - EE_Registry::instance()->load_helper('URL'); |
|
| 723 | - // if $message is not an instance of EE_Message then let's just do a dummy. |
|
| 724 | - $message = empty($message) ? EE_Message_Factory::create() : $message; |
|
| 725 | - $action_urls = apply_filters( |
|
| 726 | - 'FHEE__EEH_MSG_Template__get_message_action_url', |
|
| 727 | - array( |
|
| 728 | - 'view' => EEH_MSG_Template::generate_browser_trigger($message), |
|
| 729 | - 'error' => EEH_MSG_Template::generate_error_display_trigger($message), |
|
| 730 | - 'see_notifications_for' => EEH_URL::add_query_args_and_nonce( |
|
| 731 | - array_merge( |
|
| 732 | - array( |
|
| 733 | - 'page' => 'espresso_messages', |
|
| 734 | - 'action' => 'default', |
|
| 735 | - 'filterby' => 1, |
|
| 736 | - ), |
|
| 737 | - $query_params |
|
| 738 | - ), |
|
| 739 | - admin_url('admin.php') |
|
| 740 | - ), |
|
| 741 | - 'generate_now' => EEH_URL::add_query_args_and_nonce( |
|
| 742 | - array( |
|
| 743 | - 'page' => 'espresso_messages', |
|
| 744 | - 'action' => 'generate_now', |
|
| 745 | - 'MSG_ID' => $message->ID() |
|
| 746 | - ), |
|
| 747 | - admin_url('admin.php') |
|
| 748 | - ), |
|
| 749 | - 'send_now' => EEH_URL::add_query_args_and_nonce( |
|
| 750 | - array( |
|
| 751 | - 'page' => 'espresso_messages', |
|
| 752 | - 'action' => 'send_now', |
|
| 753 | - 'MSG_ID' => $message->ID() |
|
| 754 | - ), |
|
| 755 | - admin_url('admin.php') |
|
| 756 | - ), |
|
| 757 | - 'queue_for_resending' => EEH_URL::add_query_args_and_nonce( |
|
| 758 | - array( |
|
| 759 | - 'page' => 'espresso_messages', |
|
| 760 | - 'action' => 'queue_for_resending', |
|
| 761 | - 'MSG_ID' => $message->ID() |
|
| 762 | - ), |
|
| 763 | - admin_url('admin.php') |
|
| 764 | - ), |
|
| 765 | - ) |
|
| 766 | - ); |
|
| 767 | - if ( |
|
| 768 | - $message->TXN_ID() > 0 |
|
| 769 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 770 | - 'ee_read_transaction', |
|
| 771 | - 'espresso_transactions_default', |
|
| 772 | - $message->TXN_ID() |
|
| 773 | - ) |
|
| 774 | - ) { |
|
| 775 | - $action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce( |
|
| 776 | - array( |
|
| 777 | - 'page' => 'espresso_transactions', |
|
| 778 | - 'action' => 'view_transaction', |
|
| 779 | - 'TXN_ID' => $message->TXN_ID() |
|
| 780 | - ), |
|
| 781 | - admin_url('admin.php') |
|
| 782 | - ); |
|
| 783 | - } else { |
|
| 784 | - $action_urls['view_transaction'] = ''; |
|
| 785 | - } |
|
| 786 | - return $action_urls; |
|
| 787 | - } |
|
| 788 | - |
|
| 789 | - |
|
| 790 | - /** |
|
| 791 | - * This returns a generated link html including the icon used for the action link for EE_Message actions. |
|
| 792 | - * |
|
| 793 | - * @param string $type What type of action the link is for (if invalid type is passed in then an |
|
| 794 | - * empty string is returned) |
|
| 795 | - * @param EE_Message|null $message The EE_Message object (required for some actions to generate correctly) |
|
| 796 | - * @param array $query_params Any extra query params to include in the generated link. |
|
| 797 | - * |
|
| 798 | - * @return string |
|
| 799 | - * @throws EE_Error |
|
| 800 | - * @throws ReflectionException |
|
| 801 | - * @since 4.9.0 |
|
| 802 | - * |
|
| 803 | - */ |
|
| 804 | - public static function get_message_action_link($type, EE_Message $message = null, $query_params = array()) |
|
| 805 | - { |
|
| 806 | - $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params); |
|
| 807 | - $icon_css = EEH_MSG_Template::get_message_action_icon($type); |
|
| 808 | - $label = $icon_css['label'] ?? null; |
|
| 809 | - $label = $label ? 'aria-label="' . $label . '"' : ''; |
|
| 810 | - $class = $label ? ' ee-aria-tooltip' : ''; |
|
| 811 | - |
|
| 812 | - if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) { |
|
| 813 | - return ''; |
|
| 814 | - } |
|
| 815 | - |
|
| 816 | - $icon_css['css_class'] .= esc_attr( |
|
| 817 | - apply_filters( |
|
| 818 | - 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class', |
|
| 819 | - ' js-ee-message-action-link ee-message-action-link-' . $type, |
|
| 820 | - $type, |
|
| 821 | - $message, |
|
| 822 | - $query_params |
|
| 823 | - ) |
|
| 824 | - ); |
|
| 825 | - |
|
| 826 | - return ' |
|
| 18 | + /** |
|
| 19 | + * Holds a collection of EE_Message_Template_Pack objects. |
|
| 20 | + * @type EE_Messages_Template_Pack_Collection |
|
| 21 | + */ |
|
| 22 | + protected static $_template_pack_collection; |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @throws EE_Error |
|
| 27 | + */ |
|
| 28 | + private static function _set_autoloader() |
|
| 29 | + { |
|
| 30 | + EED_Messages::set_autoloaders(); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * generate_new_templates |
|
| 36 | + * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 37 | + * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 38 | + * for the event. |
|
| 39 | + * |
|
| 40 | + * @access protected |
|
| 41 | + * @param string $messenger the messenger we are generating templates for |
|
| 42 | + * @param array $message_types array of message types that the templates are generated for. |
|
| 43 | + * @param int $GRP_ID If a non global template is being generated then it is expected we'll have a GRP_ID |
|
| 44 | + * to use as the base for the new generated template. |
|
| 45 | + * @param bool $global true indicates generating templates on messenger activation. false requires GRP_ID |
|
| 46 | + * for event specific template generation. |
|
| 47 | + * @return array @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array |
|
| 48 | + * for templates that are generated. If this is an empty array then it means no templates were |
|
| 49 | + * generated which usually means there was an error. Anything in the array with an empty value for |
|
| 50 | + * `MTP_context` means that it was not a new generated template but just reactivated (which only |
|
| 51 | + * happens for global templates that already exist in the database. |
|
| 52 | + * @throws EE_Error |
|
| 53 | + * @throws ReflectionException |
|
| 54 | + */ |
|
| 55 | + public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 56 | + { |
|
| 57 | + // make sure message_type is an array. |
|
| 58 | + $message_types = (array) $message_types; |
|
| 59 | + $templates = array(); |
|
| 60 | + |
|
| 61 | + if (empty($messenger)) { |
|
| 62 | + throw new EE_Error(esc_html__('We need a messenger to generate templates!', 'event_espresso')); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + // if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files. |
|
| 66 | + if (empty($message_types)) { |
|
| 67 | + throw new EE_Error(esc_html__('We need at least one message type to generate templates!', 'event_espresso')); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + EEH_MSG_Template::_set_autoloader(); |
|
| 71 | + foreach ($message_types as $message_type) { |
|
| 72 | + // if global then let's attempt to get the GRP_ID for this combo IF GRP_ID is empty. |
|
| 73 | + if ($global && empty($GRP_ID)) { |
|
| 74 | + $GRP_ID = EEM_Message_Template_Group::instance()->get_one( |
|
| 75 | + array( |
|
| 76 | + array( |
|
| 77 | + 'MTP_messenger' => $messenger, |
|
| 78 | + 'MTP_message_type' => $message_type, |
|
| 79 | + 'MTP_is_global' => true, |
|
| 80 | + ), |
|
| 81 | + ) |
|
| 82 | + ); |
|
| 83 | + $GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0; |
|
| 84 | + } |
|
| 85 | + // if this is global template generation. |
|
| 86 | + // First let's determine if we already HAVE global templates for this messenger and message_type combination. |
|
| 87 | + // If we do then NO generation!! |
|
| 88 | + if ($global && EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) { |
|
| 89 | + $templates[] = array( |
|
| 90 | + 'GRP_ID' => $GRP_ID, |
|
| 91 | + 'MTP_context' => '', |
|
| 92 | + ); |
|
| 93 | + // we already have generated templates for this so let's go to the next message type. |
|
| 94 | + continue; |
|
| 95 | + } |
|
| 96 | + $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global); |
|
| 97 | + |
|
| 98 | + if (! $new_message_template_group) { |
|
| 99 | + continue; |
|
| 100 | + } |
|
| 101 | + $templates[] = $new_message_template_group; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + return $templates; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * The purpose of this method is to determine if there are already generated templates in the database for the |
|
| 110 | + * given variables. |
|
| 111 | + * |
|
| 112 | + * @param string $messenger messenger |
|
| 113 | + * @param string $message_type message type |
|
| 114 | + * @param int $GRP_ID GRP ID ( if a custom template) (if not provided then we're just doing global |
|
| 115 | + * template check) |
|
| 116 | + * @return bool true = generated, false = hasn't been generated. |
|
| 117 | + * @throws EE_Error |
|
| 118 | + */ |
|
| 119 | + public static function already_generated($messenger, $message_type, $GRP_ID = 0) |
|
| 120 | + { |
|
| 121 | + EEH_MSG_Template::_set_autoloader(); |
|
| 122 | + // what method we use depends on whether we have an GRP_ID or not |
|
| 123 | + $count = empty($GRP_ID) |
|
| 124 | + ? EEM_Message_Template::instance()->count( |
|
| 125 | + array( |
|
| 126 | + array( |
|
| 127 | + 'Message_Template_Group.MTP_messenger' => $messenger, |
|
| 128 | + 'Message_Template_Group.MTP_message_type' => $message_type, |
|
| 129 | + 'Message_Template_Group.MTP_is_global' => true |
|
| 130 | + ) |
|
| 131 | + ) |
|
| 132 | + ) |
|
| 133 | + : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) )); |
|
| 134 | + |
|
| 135 | + return $count > 0; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Updates all message templates matching the incoming messengers and message types to active status. |
|
| 141 | + * |
|
| 142 | + * @static |
|
| 143 | + * @param array $messenger_names Messenger slug |
|
| 144 | + * @param array $message_type_names Message type slug |
|
| 145 | + * @return int count of updated records. |
|
| 146 | + * @throws EE_Error |
|
| 147 | + */ |
|
| 148 | + public static function update_to_active($messenger_names, $message_type_names) |
|
| 149 | + { |
|
| 150 | + $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names ); |
|
| 151 | + $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names ); |
|
| 152 | + return EEM_Message_Template_Group::instance()->update( |
|
| 153 | + array( 'MTP_is_active' => 1 ), |
|
| 154 | + array( |
|
| 155 | + array( |
|
| 156 | + 'MTP_messenger' => array( 'IN', $messenger_names ), |
|
| 157 | + 'MTP_message_type' => array( 'IN', $message_type_names ) |
|
| 158 | + ) |
|
| 159 | + ) |
|
| 160 | + ); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Updates all message template groups matching the incoming arguments to inactive status. |
|
| 166 | + * |
|
| 167 | + * @static |
|
| 168 | + * @param array $messenger_names The messenger slugs. |
|
| 169 | + * If empty then all templates matching the message types are marked inactive. |
|
| 170 | + * Otherwise only templates matching the messengers and message types. |
|
| 171 | + * @param array $message_type_names The message type slugs. |
|
| 172 | + * If empty then all templates matching the messengers are marked inactive. |
|
| 173 | + * Otherwise only templates matching the messengers and message types. |
|
| 174 | + * |
|
| 175 | + * @return int count of updated records. |
|
| 176 | + * @throws EE_Error |
|
| 177 | + */ |
|
| 178 | + public static function update_to_inactive($messenger_names = array(), $message_type_names = array()) |
|
| 179 | + { |
|
| 180 | + return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for( |
|
| 181 | + $messenger_names, |
|
| 182 | + $message_type_names |
|
| 183 | + ); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * The purpose of this function is to return all installed message objects |
|
| 189 | + * (messengers and message type regardless of whether they are ACTIVE or not) |
|
| 190 | + * |
|
| 191 | + * @param string $type |
|
| 192 | + * @return array array consisting of installed messenger objects and installed message type objects. |
|
| 193 | + * @throws EE_Error |
|
| 194 | + * @throws ReflectionException |
|
| 195 | + * @deprecated 4.9.0 |
|
| 196 | + * @static |
|
| 197 | + */ |
|
| 198 | + public static function get_installed_message_objects($type = 'all') |
|
| 199 | + { |
|
| 200 | + self::_set_autoloader(); |
|
| 201 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 202 | + return array( |
|
| 203 | + 'messenger' => $message_resource_manager->installed_messengers(), |
|
| 204 | + 'message_type' => $message_resource_manager->installed_message_types() |
|
| 205 | + ); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * This will return an array of shortcodes => labels from the |
|
| 211 | + * messenger and message_type objects associated with this |
|
| 212 | + * template. |
|
| 213 | + * |
|
| 214 | + * @param string $message_type |
|
| 215 | + * @param string $messenger |
|
| 216 | + * @param array $fields What fields we're returning valid shortcodes for. |
|
| 217 | + * If empty then we assume all fields are to be returned. Optional. |
|
| 218 | + * @param string $context What context we're going to return shortcodes for. Optional. |
|
| 219 | + * @param bool $merged If TRUE then we don't return shortcodes indexed by field, |
|
| 220 | + * but instead an array of the unique shortcodes for all the given ( |
|
| 221 | + * or all) fields. Optional. |
|
| 222 | + * @return array an array of shortcodes in the format |
|
| 223 | + * array( '[shortcode] => 'label') |
|
| 224 | + * OR |
|
| 225 | + * FALSE if no shortcodes found. |
|
| 226 | + * @throws ReflectionException |
|
| 227 | + * @throws EE_Error*@since 4.3.0 |
|
| 228 | + * |
|
| 229 | + */ |
|
| 230 | + public static function get_shortcodes( |
|
| 231 | + $message_type, |
|
| 232 | + $messenger, |
|
| 233 | + $fields = array(), |
|
| 234 | + $context = 'admin', |
|
| 235 | + $merged = false |
|
| 236 | + ) { |
|
| 237 | + $messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger))); |
|
| 238 | + $mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type))); |
|
| 239 | + /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
| 240 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 241 | + // convert slug to object |
|
| 242 | + $messenger = $message_resource_manager->get_messenger($messenger); |
|
| 243 | + |
|
| 244 | + // if messenger isn't a EE_messenger resource then bail. |
|
| 245 | + if (! $messenger instanceof EE_messenger) { |
|
| 246 | + return array(); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + // validate class for getting our list of shortcodes |
|
| 250 | + $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator'; |
|
| 251 | + if (! class_exists($classname)) { |
|
| 252 | + $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); |
|
| 253 | + $msg[] = sprintf( |
|
| 254 | + esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'), |
|
| 255 | + $classname |
|
| 256 | + ); |
|
| 257 | + throw new EE_Error(implode('||', $msg)); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** @type EE_Messages_Validator $_VLD */ |
|
| 261 | + $_VLD = new $classname(array(), $context); |
|
| 262 | + $valid_shortcodes = $_VLD->get_validators(); |
|
| 263 | + |
|
| 264 | + // let's make sure we're only getting the shortcode part of the validators |
|
| 265 | + $shortcodes = array(); |
|
| 266 | + foreach ($valid_shortcodes as $field => $validators) { |
|
| 267 | + $shortcodes[ $field ] = $validators['shortcodes']; |
|
| 268 | + } |
|
| 269 | + $valid_shortcodes = $shortcodes; |
|
| 270 | + |
|
| 271 | + // if not all fields let's make sure we ONLY include the shortcodes for the specified fields. |
|
| 272 | + if (! empty($fields)) { |
|
| 273 | + $specified_shortcodes = array(); |
|
| 274 | + foreach ($fields as $field) { |
|
| 275 | + if (isset($valid_shortcodes[ $field ])) { |
|
| 276 | + $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ]; |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + $valid_shortcodes = $specified_shortcodes; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + // if not merged then let's replace the fields with the localized fields |
|
| 283 | + if (! $merged) { |
|
| 284 | + // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array. |
|
| 285 | + $field_settings = $messenger->get_template_fields(); |
|
| 286 | + $localized = array(); |
|
| 287 | + foreach ($valid_shortcodes as $field => $shortcodes) { |
|
| 288 | + // get localized field label |
|
| 289 | + if (isset($field_settings[ $field ])) { |
|
| 290 | + // possible that this is used as a main field. |
|
| 291 | + if (empty($field_settings[ $field ])) { |
|
| 292 | + if (isset($field_settings['extra'][ $field ])) { |
|
| 293 | + $_field = $field_settings['extra'][ $field ]['main']['label']; |
|
| 294 | + } else { |
|
| 295 | + $_field = $field; |
|
| 296 | + } |
|
| 297 | + } else { |
|
| 298 | + $_field = $field_settings[ $field ]['label']; |
|
| 299 | + } |
|
| 300 | + } elseif (isset($field_settings['extra'])) { |
|
| 301 | + // loop through extra "main fields" and see if any of their children have our field |
|
| 302 | + foreach ($field_settings['extra'] as $fields) { |
|
| 303 | + if (isset($fields[ $field ])) { |
|
| 304 | + $_field = $fields[ $field ]['label']; |
|
| 305 | + } else { |
|
| 306 | + $_field = $field; |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + } else { |
|
| 310 | + $_field = $field; |
|
| 311 | + } |
|
| 312 | + if (isset($_field)) { |
|
| 313 | + $localized[ (string) $_field ] = $shortcodes; |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + $valid_shortcodes = $localized; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + // if $merged then let's merge all the shortcodes into one list NOT indexed by field. |
|
| 320 | + if ($merged) { |
|
| 321 | + $merged_codes = array(); |
|
| 322 | + foreach ($valid_shortcodes as $shortcode) { |
|
| 323 | + foreach ($shortcode as $code => $label) { |
|
| 324 | + if (isset($merged_codes[ $code ])) { |
|
| 325 | + continue; |
|
| 326 | + } else { |
|
| 327 | + $merged_codes[ $code ] = $label; |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + } |
|
| 331 | + $valid_shortcodes = $merged_codes; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + return $valid_shortcodes; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * Get Messenger object. |
|
| 340 | + * |
|
| 341 | + * @param string $messenger messenger slug for the messenger object we want to retrieve. |
|
| 342 | + * @return EE_messenger |
|
| 343 | + * @throws ReflectionException |
|
| 344 | + * @throws EE_Error*@since 4.3.0 |
|
| 345 | + * @deprecated 4.9.0 |
|
| 346 | + */ |
|
| 347 | + public static function messenger_obj($messenger) |
|
| 348 | + { |
|
| 349 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 350 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 351 | + return $Message_Resource_Manager->get_messenger($messenger); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * get Message type object |
|
| 357 | + * |
|
| 358 | + * @param string $message_type the slug for the message type object to retrieve |
|
| 359 | + * @return EE_message_type |
|
| 360 | + * @throws ReflectionException |
|
| 361 | + * @throws EE_Error*@since 4.3.0 |
|
| 362 | + * @deprecated 4.9.0 |
|
| 363 | + */ |
|
| 364 | + public static function message_type_obj($message_type) |
|
| 365 | + { |
|
| 366 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 367 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 368 | + return $Message_Resource_Manager->get_message_type($message_type); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Given a message_type slug, will return whether that message type is active in the system or not. |
|
| 374 | + * |
|
| 375 | + * @since 4.3.0 |
|
| 376 | + * @param string $message_type message type to check for. |
|
| 377 | + * @return boolean |
|
| 378 | + * @throws EE_Error |
|
| 379 | + * @throws ReflectionException |
|
| 380 | + */ |
|
| 381 | + public static function is_mt_active($message_type) |
|
| 382 | + { |
|
| 383 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 384 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 385 | + $active_mts = $Message_Resource_Manager->list_of_active_message_types(); |
|
| 386 | + return in_array($message_type, $active_mts); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Given a messenger slug, will return whether that messenger is active in the system or not. |
|
| 392 | + * |
|
| 393 | + * @since 4.3.0 |
|
| 394 | + * |
|
| 395 | + * @param string $messenger slug for messenger to check. |
|
| 396 | + * @return boolean |
|
| 397 | + * @throws EE_Error |
|
| 398 | + * @throws ReflectionException |
|
| 399 | + */ |
|
| 400 | + public static function is_messenger_active($messenger) |
|
| 401 | + { |
|
| 402 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 403 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 404 | + $active_messenger = $Message_Resource_Manager->get_active_messenger($messenger); |
|
| 405 | + return $active_messenger instanceof EE_messenger; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Used to return active messengers array stored in the wp options table. |
|
| 411 | + * If no value is present in the option then an empty array is returned. |
|
| 412 | + * |
|
| 413 | + * @deprecated 4.9 |
|
| 414 | + * @since 4.3.1 |
|
| 415 | + * |
|
| 416 | + * @return array |
|
| 417 | + * @throws EE_Error |
|
| 418 | + * @throws ReflectionException |
|
| 419 | + */ |
|
| 420 | + public static function get_active_messengers_in_db() |
|
| 421 | + { |
|
| 422 | + EE_Error::doing_it_wrong( |
|
| 423 | + __METHOD__, |
|
| 424 | + esc_html__('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'), |
|
| 425 | + '4.9.0' |
|
| 426 | + ); |
|
| 427 | + /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 428 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 429 | + return $Message_Resource_Manager->get_active_messengers_option(); |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * Used to update the active messengers array stored in the wp options table. |
|
| 435 | + * |
|
| 436 | + * @since 4.3.1 |
|
| 437 | + * @deprecated 4.9.0 |
|
| 438 | + * |
|
| 439 | + * @param array $data_to_save Incoming data to save. |
|
| 440 | + * |
|
| 441 | + * @return bool FALSE if not updated, TRUE if updated. |
|
| 442 | + * @throws EE_Error |
|
| 443 | + * @throws ReflectionException |
|
| 444 | + */ |
|
| 445 | + public static function update_active_messengers_in_db($data_to_save) |
|
| 446 | + { |
|
| 447 | + EE_Error::doing_it_wrong( |
|
| 448 | + __METHOD__, |
|
| 449 | + esc_html__('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'), |
|
| 450 | + '4.9.0' |
|
| 451 | + ); |
|
| 452 | + /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 453 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 454 | + return $Message_Resource_Manager->update_active_messengers_option($data_to_save); |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * This does some validation of incoming params, determines what type of url is being prepped and returns the |
|
| 460 | + * appropriate url trigger |
|
| 461 | + * |
|
| 462 | + * @param EE_message_type $message_type |
|
| 463 | + * @param EE_Message $message |
|
| 464 | + * @param EE_Registration | null $registration The registration object must be included if this |
|
| 465 | + * is going to be a registration trigger url. |
|
| 466 | + * @param string $sending_messenger The (optional) sending messenger for the url. |
|
| 467 | + * |
|
| 468 | + * @return string |
|
| 469 | + * @throws EE_Error |
|
| 470 | + */ |
|
| 471 | + public static function get_url_trigger( |
|
| 472 | + EE_message_type $message_type, |
|
| 473 | + EE_Message $message, |
|
| 474 | + $registration = null, |
|
| 475 | + $sending_messenger = '' |
|
| 476 | + ) { |
|
| 477 | + // first determine if the url can be to the EE_Message object. |
|
| 478 | + if (! $message_type->always_generate()) { |
|
| 479 | + return EEH_MSG_Template::generate_browser_trigger($message); |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + // if $registration object is not valid then exit early because there's nothing that can be generated. |
|
| 483 | + if (! $registration instanceof EE_Registration) { |
|
| 484 | + throw new EE_Error( |
|
| 485 | + esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso') |
|
| 486 | + ); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + // validate given context |
|
| 490 | + $contexts = $message_type->get_contexts(); |
|
| 491 | + if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) { |
|
| 492 | + throw new EE_Error( |
|
| 493 | + sprintf( |
|
| 494 | + esc_html__('The context %s is not a valid context for %s.', 'event_espresso'), |
|
| 495 | + $message->context(), |
|
| 496 | + get_class($message_type) |
|
| 497 | + ) |
|
| 498 | + ); |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + // valid sending messenger but only if sending messenger set. Otherwise generating messenger is used. |
|
| 502 | + if (! empty($sending_messenger)) { |
|
| 503 | + $with_messengers = $message_type->with_messengers(); |
|
| 504 | + if ( |
|
| 505 | + ! isset($with_messengers[ $message->messenger() ]) |
|
| 506 | + || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ]) |
|
| 507 | + ) { |
|
| 508 | + throw new EE_Error( |
|
| 509 | + sprintf( |
|
| 510 | + esc_html__( |
|
| 511 | + 'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s. If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.', |
|
| 512 | + 'event_espresso' |
|
| 513 | + ), |
|
| 514 | + $sending_messenger, |
|
| 515 | + get_class($message_type) |
|
| 516 | + ) |
|
| 517 | + ); |
|
| 518 | + } |
|
| 519 | + } else { |
|
| 520 | + $sending_messenger = $message->messenger(); |
|
| 521 | + } |
|
| 522 | + return EEH_MSG_Template::generate_url_trigger( |
|
| 523 | + $sending_messenger, |
|
| 524 | + $message->messenger(), |
|
| 525 | + $message->context(), |
|
| 526 | + $message->message_type(), |
|
| 527 | + $registration, |
|
| 528 | + $message->GRP_ID() |
|
| 529 | + ); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * This returns the url for triggering a in browser view of a specific EE_Message object. |
|
| 535 | + * @param EE_Message $message |
|
| 536 | + * @return string. |
|
| 537 | + */ |
|
| 538 | + public static function generate_browser_trigger(EE_Message $message) |
|
| 539 | + { |
|
| 540 | + $query_args = array( |
|
| 541 | + 'ee' => 'msg_browser_trigger', |
|
| 542 | + 'token' => $message->MSG_token() |
|
| 543 | + ); |
|
| 544 | + return apply_filters( |
|
| 545 | + 'FHEE__EEH_MSG_Template__generate_browser_trigger', |
|
| 546 | + add_query_arg($query_args, site_url()), |
|
| 547 | + $message |
|
| 548 | + ); |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * This returns the url for triggering an in browser view of the error saved on the incoming message object. |
|
| 558 | + * @param EE_Message $message |
|
| 559 | + * @return string |
|
| 560 | + */ |
|
| 561 | + public static function generate_error_display_trigger(EE_Message $message) |
|
| 562 | + { |
|
| 563 | + return apply_filters( |
|
| 564 | + 'FHEE__EEH_MSG_Template__generate_error_display_trigger', |
|
| 565 | + add_query_arg( |
|
| 566 | + array( |
|
| 567 | + 'ee' => 'msg_browser_error_trigger', |
|
| 568 | + 'token' => $message->MSG_token() |
|
| 569 | + ), |
|
| 570 | + site_url() |
|
| 571 | + ), |
|
| 572 | + $message |
|
| 573 | + ); |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * This generates a url trigger for the msg_url_trigger route using the given arguments |
|
| 579 | + * |
|
| 580 | + * @param string $sending_messenger The sending messenger slug. |
|
| 581 | + * @param string $generating_messenger The generating messenger slug. |
|
| 582 | + * @param string $context The context for the template. |
|
| 583 | + * @param string $message_type The message type slug |
|
| 584 | + * @param EE_Registration $registration |
|
| 585 | + * @param integer $message_template_group id The EE_Message_Template_Group ID for the template. |
|
| 586 | + * @param integer $data_id The id to the EE_Base_Class for getting the data used by the |
|
| 587 | + * trigger. |
|
| 588 | + * @return string The generated url. |
|
| 589 | + * @throws EE_Error |
|
| 590 | + */ |
|
| 591 | + public static function generate_url_trigger( |
|
| 592 | + $sending_messenger, |
|
| 593 | + $generating_messenger, |
|
| 594 | + $context, |
|
| 595 | + $message_type, |
|
| 596 | + EE_Registration $registration, |
|
| 597 | + $message_template_group, |
|
| 598 | + $data_id = 0 |
|
| 599 | + ) { |
|
| 600 | + $query_args = array( |
|
| 601 | + 'ee' => 'msg_url_trigger', |
|
| 602 | + 'snd_msgr' => $sending_messenger, |
|
| 603 | + 'gen_msgr' => $generating_messenger, |
|
| 604 | + 'message_type' => $message_type, |
|
| 605 | + 'context' => $context, |
|
| 606 | + 'token' => $registration->reg_url_link(), |
|
| 607 | + 'GRP_ID' => $message_template_group, |
|
| 608 | + 'id' => $data_id |
|
| 609 | + ); |
|
| 610 | + $url = add_query_arg($query_args, get_home_url()); |
|
| 611 | + |
|
| 612 | + // made it here so now we can just get the url and filter it. Filtered globally and by message type. |
|
| 613 | + return apply_filters( |
|
| 614 | + 'FHEE__EEH_MSG_Template__generate_url_trigger', |
|
| 615 | + $url, |
|
| 616 | + $sending_messenger, |
|
| 617 | + $generating_messenger, |
|
| 618 | + $context, |
|
| 619 | + $message_type, |
|
| 620 | + $registration, |
|
| 621 | + $message_template_group, |
|
| 622 | + $data_id |
|
| 623 | + ); |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + |
|
| 628 | + |
|
| 629 | + /** |
|
| 630 | + * Return the specific css for the action icon given. |
|
| 631 | + * |
|
| 632 | + * @param string $type What action to return. |
|
| 633 | + * @return string[] |
|
| 634 | + * @since 4.9.0 |
|
| 635 | + */ |
|
| 636 | + public static function get_message_action_icon($type) |
|
| 637 | + { |
|
| 638 | + $action_icons = self::get_message_action_icons(); |
|
| 639 | + return isset($action_icons[ $type ]) ? $action_icons[ $type ] : []; |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + |
|
| 643 | + /** |
|
| 644 | + * This is used for retrieving the css classes used for the icons representing message actions. |
|
| 645 | + * |
|
| 646 | + * @since 4.9.0 |
|
| 647 | + * |
|
| 648 | + * @return array |
|
| 649 | + */ |
|
| 650 | + public static function get_message_action_icons() |
|
| 651 | + { |
|
| 652 | + return apply_filters( |
|
| 653 | + 'FHEE__EEH_MSG_Template__message_action_icons', |
|
| 654 | + array( |
|
| 655 | + 'view' => array( |
|
| 656 | + 'label' => esc_html__('View Message', 'event_espresso'), |
|
| 657 | + 'css_class' => 'dashicons dashicons-welcome-view-site', |
|
| 658 | + ), |
|
| 659 | + 'error' => array( |
|
| 660 | + 'label' => esc_html__('View Error Message', 'event_espresso'), |
|
| 661 | + 'css_class' => 'dashicons dashicons-info', |
|
| 662 | + ), |
|
| 663 | + 'see_notifications_for' => array( |
|
| 664 | + 'label' => esc_html__('View Related Messages', 'event_espresso'), |
|
| 665 | + 'css_class' => 'dashicons dashicons-megaphone', |
|
| 666 | + ), |
|
| 667 | + 'generate_now' => array( |
|
| 668 | + 'label' => esc_html__('Generate the message now.', 'event_espresso'), |
|
| 669 | + 'css_class' => 'dashicons dashicons-admin-tools', |
|
| 670 | + ), |
|
| 671 | + 'send_now' => array( |
|
| 672 | + 'label' => esc_html__('Send Immediately', 'event_espresso'), |
|
| 673 | + 'css_class' => 'dashicons dashicons-controls-forward', |
|
| 674 | + ), |
|
| 675 | + 'queue_for_resending' => array( |
|
| 676 | + 'label' => esc_html__('Queue for Resending', 'event_espresso'), |
|
| 677 | + 'css_class' => 'dashicons dashicons-controls-repeat', |
|
| 678 | + ), |
|
| 679 | + 'view_transaction' => array( |
|
| 680 | + 'label' => esc_html__('View related Transaction', 'event_espresso'), |
|
| 681 | + 'css_class' => 'dashicons dashicons-cart', |
|
| 682 | + ) |
|
| 683 | + ) |
|
| 684 | + ); |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * This returns the url for a given action related to EE_Message. |
|
| 690 | + * |
|
| 691 | + * @param string $type What type of action to return the url for. |
|
| 692 | + * @param EE_Message $message Required for generating the correct url for some types. |
|
| 693 | + * @param array $query_params Any additional query params to be included with the generated url. |
|
| 694 | + * |
|
| 695 | + * @return string |
|
| 696 | + * @throws EE_Error |
|
| 697 | + * @throws ReflectionException |
|
| 698 | + * @since 4.9.0 |
|
| 699 | + * |
|
| 700 | + */ |
|
| 701 | + public static function get_message_action_url($type, EE_Message $message = null, $query_params = array()) |
|
| 702 | + { |
|
| 703 | + $action_urls = self::get_message_action_urls($message, $query_params); |
|
| 704 | + return isset($action_urls[ $type ]) ? $action_urls[ $type ] : ''; |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + |
|
| 708 | + /** |
|
| 709 | + * This returns all the current urls for EE_Message actions. |
|
| 710 | + * |
|
| 711 | + * @since 4.9.0 |
|
| 712 | + * |
|
| 713 | + * @param EE_Message $message The EE_Message object required to generate correct urls for some types. |
|
| 714 | + * @param array $query_params Any additional query_params to be included with the generated url. |
|
| 715 | + * |
|
| 716 | + * @return array |
|
| 717 | + * @throws EE_Error |
|
| 718 | + * @throws ReflectionException |
|
| 719 | + */ |
|
| 720 | + public static function get_message_action_urls(EE_Message $message = null, $query_params = array()) |
|
| 721 | + { |
|
| 722 | + EE_Registry::instance()->load_helper('URL'); |
|
| 723 | + // if $message is not an instance of EE_Message then let's just do a dummy. |
|
| 724 | + $message = empty($message) ? EE_Message_Factory::create() : $message; |
|
| 725 | + $action_urls = apply_filters( |
|
| 726 | + 'FHEE__EEH_MSG_Template__get_message_action_url', |
|
| 727 | + array( |
|
| 728 | + 'view' => EEH_MSG_Template::generate_browser_trigger($message), |
|
| 729 | + 'error' => EEH_MSG_Template::generate_error_display_trigger($message), |
|
| 730 | + 'see_notifications_for' => EEH_URL::add_query_args_and_nonce( |
|
| 731 | + array_merge( |
|
| 732 | + array( |
|
| 733 | + 'page' => 'espresso_messages', |
|
| 734 | + 'action' => 'default', |
|
| 735 | + 'filterby' => 1, |
|
| 736 | + ), |
|
| 737 | + $query_params |
|
| 738 | + ), |
|
| 739 | + admin_url('admin.php') |
|
| 740 | + ), |
|
| 741 | + 'generate_now' => EEH_URL::add_query_args_and_nonce( |
|
| 742 | + array( |
|
| 743 | + 'page' => 'espresso_messages', |
|
| 744 | + 'action' => 'generate_now', |
|
| 745 | + 'MSG_ID' => $message->ID() |
|
| 746 | + ), |
|
| 747 | + admin_url('admin.php') |
|
| 748 | + ), |
|
| 749 | + 'send_now' => EEH_URL::add_query_args_and_nonce( |
|
| 750 | + array( |
|
| 751 | + 'page' => 'espresso_messages', |
|
| 752 | + 'action' => 'send_now', |
|
| 753 | + 'MSG_ID' => $message->ID() |
|
| 754 | + ), |
|
| 755 | + admin_url('admin.php') |
|
| 756 | + ), |
|
| 757 | + 'queue_for_resending' => EEH_URL::add_query_args_and_nonce( |
|
| 758 | + array( |
|
| 759 | + 'page' => 'espresso_messages', |
|
| 760 | + 'action' => 'queue_for_resending', |
|
| 761 | + 'MSG_ID' => $message->ID() |
|
| 762 | + ), |
|
| 763 | + admin_url('admin.php') |
|
| 764 | + ), |
|
| 765 | + ) |
|
| 766 | + ); |
|
| 767 | + if ( |
|
| 768 | + $message->TXN_ID() > 0 |
|
| 769 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 770 | + 'ee_read_transaction', |
|
| 771 | + 'espresso_transactions_default', |
|
| 772 | + $message->TXN_ID() |
|
| 773 | + ) |
|
| 774 | + ) { |
|
| 775 | + $action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce( |
|
| 776 | + array( |
|
| 777 | + 'page' => 'espresso_transactions', |
|
| 778 | + 'action' => 'view_transaction', |
|
| 779 | + 'TXN_ID' => $message->TXN_ID() |
|
| 780 | + ), |
|
| 781 | + admin_url('admin.php') |
|
| 782 | + ); |
|
| 783 | + } else { |
|
| 784 | + $action_urls['view_transaction'] = ''; |
|
| 785 | + } |
|
| 786 | + return $action_urls; |
|
| 787 | + } |
|
| 788 | + |
|
| 789 | + |
|
| 790 | + /** |
|
| 791 | + * This returns a generated link html including the icon used for the action link for EE_Message actions. |
|
| 792 | + * |
|
| 793 | + * @param string $type What type of action the link is for (if invalid type is passed in then an |
|
| 794 | + * empty string is returned) |
|
| 795 | + * @param EE_Message|null $message The EE_Message object (required for some actions to generate correctly) |
|
| 796 | + * @param array $query_params Any extra query params to include in the generated link. |
|
| 797 | + * |
|
| 798 | + * @return string |
|
| 799 | + * @throws EE_Error |
|
| 800 | + * @throws ReflectionException |
|
| 801 | + * @since 4.9.0 |
|
| 802 | + * |
|
| 803 | + */ |
|
| 804 | + public static function get_message_action_link($type, EE_Message $message = null, $query_params = array()) |
|
| 805 | + { |
|
| 806 | + $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params); |
|
| 807 | + $icon_css = EEH_MSG_Template::get_message_action_icon($type); |
|
| 808 | + $label = $icon_css['label'] ?? null; |
|
| 809 | + $label = $label ? 'aria-label="' . $label . '"' : ''; |
|
| 810 | + $class = $label ? ' ee-aria-tooltip' : ''; |
|
| 811 | + |
|
| 812 | + if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) { |
|
| 813 | + return ''; |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + $icon_css['css_class'] .= esc_attr( |
|
| 817 | + apply_filters( |
|
| 818 | + 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class', |
|
| 819 | + ' js-ee-message-action-link ee-message-action-link-' . $type, |
|
| 820 | + $type, |
|
| 821 | + $message, |
|
| 822 | + $query_params |
|
| 823 | + ) |
|
| 824 | + ); |
|
| 825 | + |
|
| 826 | + return ' |
|
| 827 | 827 | <a href="' . $url . '" ' . $label . ' class="button button--icon-only' . $class . '"> |
| 828 | 828 | <span class="' . esc_attr($icon_css['css_class']) . '"></span> |
| 829 | 829 | </a>'; |
| 830 | - } |
|
| 831 | - |
|
| 832 | - |
|
| 833 | - |
|
| 834 | - |
|
| 835 | - |
|
| 836 | - /** |
|
| 837 | - * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered). |
|
| 838 | - * |
|
| 839 | - * @since 4.9.0 |
|
| 840 | - * @return array |
|
| 841 | - */ |
|
| 842 | - public static function reg_status_to_message_type_array() |
|
| 843 | - { |
|
| 844 | - return (array) apply_filters( |
|
| 845 | - 'FHEE__EEH_MSG_Template__reg_status_to_message_type_array', |
|
| 846 | - array( |
|
| 847 | - EEM_Registration::status_id_approved => 'registration', |
|
| 848 | - EEM_Registration::status_id_pending_payment => 'pending_approval', |
|
| 849 | - EEM_Registration::status_id_not_approved => 'not_approved_registration', |
|
| 850 | - EEM_Registration::status_id_cancelled => 'cancelled_registration', |
|
| 851 | - EEM_Registration::status_id_declined => 'declined_registration' |
|
| 852 | - ) |
|
| 853 | - ); |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - |
|
| 857 | - |
|
| 858 | - |
|
| 859 | - /** |
|
| 860 | - * This returns the corresponding registration message type slug to the given reg status. If there isn't a |
|
| 861 | - * match, then returns an empty string. |
|
| 862 | - * |
|
| 863 | - * @since 4.9.0 |
|
| 864 | - * @param $reg_status |
|
| 865 | - * @return string |
|
| 866 | - */ |
|
| 867 | - public static function convert_reg_status_to_message_type($reg_status) |
|
| 868 | - { |
|
| 869 | - $reg_status_array = self::reg_status_to_message_type_array(); |
|
| 870 | - return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : ''; |
|
| 871 | - } |
|
| 872 | - |
|
| 873 | - |
|
| 874 | - /** |
|
| 875 | - * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered). |
|
| 876 | - * |
|
| 877 | - * @since 4.9.0 |
|
| 878 | - * @return array |
|
| 879 | - */ |
|
| 880 | - public static function payment_status_to_message_type_array() |
|
| 881 | - { |
|
| 882 | - return (array) apply_filters( |
|
| 883 | - 'FHEE__EEH_MSG_Template__payment_status_to_message_type_array', |
|
| 884 | - array( |
|
| 885 | - EEM_Payment::status_id_approved => 'payment', |
|
| 886 | - EEM_Payment::status_id_pending => 'payment_pending', |
|
| 887 | - EEM_Payment::status_id_cancelled => 'payment_cancelled', |
|
| 888 | - EEM_Payment::status_id_declined => 'payment_declined', |
|
| 889 | - EEM_Payment::status_id_failed => 'payment_failed' |
|
| 890 | - ) |
|
| 891 | - ); |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - |
|
| 895 | - |
|
| 896 | - |
|
| 897 | - /** |
|
| 898 | - * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then |
|
| 899 | - * an empty string is returned |
|
| 900 | - * |
|
| 901 | - * @since 4.9.0 |
|
| 902 | - * @param $payment_status |
|
| 903 | - * @return string |
|
| 904 | - */ |
|
| 905 | - public static function convert_payment_status_to_message_type($payment_status) |
|
| 906 | - { |
|
| 907 | - $payment_status_array = self::payment_status_to_message_type_array(); |
|
| 908 | - return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : ''; |
|
| 909 | - } |
|
| 910 | - |
|
| 911 | - |
|
| 912 | - /** |
|
| 913 | - * This is used to retrieve the template pack for the given name. |
|
| 914 | - * |
|
| 915 | - * @param string $template_pack_name should match the set `dbref` property value on the EE_Messages_Template_Pack. |
|
| 916 | - * |
|
| 917 | - * @return EE_Messages_Template_Pack |
|
| 918 | - */ |
|
| 919 | - public static function get_template_pack($template_pack_name) |
|
| 920 | - { |
|
| 921 | - if (! self::$_template_pack_collection instanceof EE_Object_Collection) { |
|
| 922 | - self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - // first see if in collection already |
|
| 926 | - $template_pack = self::$_template_pack_collection->get_by_name($template_pack_name); |
|
| 927 | - |
|
| 928 | - if ($template_pack instanceof EE_Messages_Template_Pack) { |
|
| 929 | - return $template_pack; |
|
| 930 | - } |
|
| 931 | - |
|
| 932 | - // nope...let's get it. |
|
| 933 | - // not set yet so let's attempt to get it. |
|
| 934 | - $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
| 935 | - ' ', |
|
| 936 | - '_', |
|
| 937 | - ucwords( |
|
| 938 | - str_replace('_', ' ', $template_pack_name) |
|
| 939 | - ) |
|
| 940 | - ); |
|
| 941 | - if (! class_exists($pack_class_name) && $template_pack_name !== 'default') { |
|
| 942 | - return self::get_template_pack('default'); |
|
| 943 | - } else { |
|
| 944 | - $template_pack = new $pack_class_name(); |
|
| 945 | - self::$_template_pack_collection->add($template_pack); |
|
| 946 | - return $template_pack; |
|
| 947 | - } |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * Globs template packs installed in core and returns the template pack collection with all installed template packs |
|
| 955 | - * in it. |
|
| 956 | - * |
|
| 957 | - * @since 4.9.0 |
|
| 958 | - * |
|
| 959 | - * @return EE_Messages_Template_Pack_Collection |
|
| 960 | - */ |
|
| 961 | - public static function get_template_pack_collection() |
|
| 962 | - { |
|
| 963 | - $new_collection = false; |
|
| 964 | - if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { |
|
| 965 | - self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
|
| 966 | - $new_collection = true; |
|
| 967 | - } |
|
| 968 | - |
|
| 969 | - // glob the defaults directory for messages |
|
| 970 | - $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR); |
|
| 971 | - foreach ($templates as $template_path) { |
|
| 972 | - // grab folder name |
|
| 973 | - $template = basename($template_path); |
|
| 974 | - |
|
| 975 | - if (! $new_collection) { |
|
| 976 | - // already have it? |
|
| 977 | - if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) { |
|
| 978 | - continue; |
|
| 979 | - } |
|
| 980 | - } |
|
| 981 | - |
|
| 982 | - // setup classname. |
|
| 983 | - $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
| 984 | - ' ', |
|
| 985 | - '_', |
|
| 986 | - ucwords( |
|
| 987 | - str_replace( |
|
| 988 | - '_', |
|
| 989 | - ' ', |
|
| 990 | - $template |
|
| 991 | - ) |
|
| 992 | - ) |
|
| 993 | - ); |
|
| 994 | - if (! class_exists($template_pack_class_name)) { |
|
| 995 | - continue; |
|
| 996 | - } |
|
| 997 | - self::$_template_pack_collection->add(new $template_pack_class_name()); |
|
| 998 | - } |
|
| 999 | - |
|
| 1000 | - /** |
|
| 1001 | - * Filter for plugins to add in any additional template packs |
|
| 1002 | - * Note the filter name here is for backward compat, this used to be found in EED_Messages. |
|
| 1003 | - */ |
|
| 1004 | - $additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array()); |
|
| 1005 | - foreach ((array) $additional_template_packs as $template_pack) { |
|
| 1006 | - if ( |
|
| 1007 | - self::$_template_pack_collection->get_by_name( |
|
| 1008 | - $template_pack->dbref |
|
| 1009 | - ) instanceof EE_Messages_Template_Pack |
|
| 1010 | - ) { |
|
| 1011 | - continue; |
|
| 1012 | - } |
|
| 1013 | - self::$_template_pack_collection->add($template_pack); |
|
| 1014 | - } |
|
| 1015 | - return self::$_template_pack_collection; |
|
| 1016 | - } |
|
| 1017 | - |
|
| 1018 | - |
|
| 1019 | - /** |
|
| 1020 | - * This is a wrapper for the protected _create_new_templates function |
|
| 1021 | - * |
|
| 1022 | - * @param string $messenger_name |
|
| 1023 | - * @param string $message_type_name message type that the templates are being created for |
|
| 1024 | - * @param int $GRP_ID |
|
| 1025 | - * @param bool $global |
|
| 1026 | - * @return array |
|
| 1027 | - * @throws EE_Error |
|
| 1028 | - * @throws ReflectionException |
|
| 1029 | - */ |
|
| 1030 | - public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false) |
|
| 1031 | - { |
|
| 1032 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 1033 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1034 | - $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
|
| 1035 | - $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
|
| 1036 | - if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { |
|
| 1037 | - return array(); |
|
| 1038 | - } |
|
| 1039 | - // whew made it this far! Okay, let's go ahead and create the templates then |
|
| 1040 | - return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global); |
|
| 1041 | - } |
|
| 1042 | - |
|
| 1043 | - |
|
| 1044 | - /** |
|
| 1045 | - * @param EE_messenger $messenger |
|
| 1046 | - * @param EE_message_type $message_type |
|
| 1047 | - * @param $GRP_ID |
|
| 1048 | - * @param $global |
|
| 1049 | - * @return array|mixed |
|
| 1050 | - * @throws EE_Error |
|
| 1051 | - * @throws ReflectionException |
|
| 1052 | - */ |
|
| 1053 | - protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global) |
|
| 1054 | - { |
|
| 1055 | - // if we're creating a custom template then we don't need to use the defaults class |
|
| 1056 | - if (! $global) { |
|
| 1057 | - return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID); |
|
| 1058 | - } |
|
| 1059 | - /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */ |
|
| 1060 | - $Message_Template_Defaults = EE_Registry::factory( |
|
| 1061 | - 'EE_Messages_Template_Defaults', |
|
| 1062 | - array( $messenger, $message_type, $GRP_ID ) |
|
| 1063 | - ); |
|
| 1064 | - // generate templates |
|
| 1065 | - $success = $Message_Template_Defaults->create_new_templates(); |
|
| 1066 | - |
|
| 1067 | - // if creating the template failed. Then we should deactivate the related message_type for the messenger because |
|
| 1068 | - // its not active if it doesn't have a template. Note this is only happening for GLOBAL template creation |
|
| 1069 | - // attempts. |
|
| 1070 | - if (! $success) { |
|
| 1071 | - /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1072 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1073 | - $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name); |
|
| 1074 | - } |
|
| 1075 | - |
|
| 1076 | - /** |
|
| 1077 | - * $success is in an array in the following format |
|
| 1078 | - * array( |
|
| 1079 | - * 'GRP_ID' => $new_grp_id, |
|
| 1080 | - * 'MTP_context' => $first_context_in_new_templates, |
|
| 1081 | - * ) |
|
| 1082 | - */ |
|
| 1083 | - return $success; |
|
| 1084 | - } |
|
| 1085 | - |
|
| 1086 | - |
|
| 1087 | - /** |
|
| 1088 | - * This creates a custom template using the incoming GRP_ID |
|
| 1089 | - * |
|
| 1090 | - * @param EE_messenger $messenger |
|
| 1091 | - * @param EE_message_type $message_type |
|
| 1092 | - * @param int $GRP_ID GRP_ID for the template_group being used as the base |
|
| 1093 | - * @return array $success This will be an array in the format: |
|
| 1094 | - * array( |
|
| 1095 | - * 'GRP_ID' => $new_grp_id, |
|
| 1096 | - * 'MTP_context' => $first_context_in_created_template |
|
| 1097 | - * ) |
|
| 1098 | - * @throws EE_Error |
|
| 1099 | - * @throws ReflectionException |
|
| 1100 | - * @access private |
|
| 1101 | - */ |
|
| 1102 | - private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID) |
|
| 1103 | - { |
|
| 1104 | - // defaults |
|
| 1105 | - $success = array( 'GRP_ID' => null, 'MTP_context' => '' ); |
|
| 1106 | - // get the template group to use as a template from the db. If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type. |
|
| 1107 | - $Message_Template_Group = empty($GRP_ID) |
|
| 1108 | - ? EEM_Message_Template_Group::instance()->get_one( |
|
| 1109 | - array( |
|
| 1110 | - array( |
|
| 1111 | - 'MTP_messenger' => $messenger->name, |
|
| 1112 | - 'MTP_message_type' => $message_type->name, |
|
| 1113 | - 'MTP_is_global' => true |
|
| 1114 | - ) |
|
| 1115 | - ) |
|
| 1116 | - ) |
|
| 1117 | - : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1118 | - // if we don't have a mtg at this point then we need to bail. |
|
| 1119 | - if (! $Message_Template_Group instanceof EE_Message_Template_Group) { |
|
| 1120 | - EE_Error::add_error( |
|
| 1121 | - sprintf( |
|
| 1122 | - esc_html__( |
|
| 1123 | - 'Something went wrong with generating the custom template from this group id: %s. This usually happens when there is no matching message template group in the db.', |
|
| 1124 | - 'event_espresso' |
|
| 1125 | - ), |
|
| 1126 | - $GRP_ID |
|
| 1127 | - ), |
|
| 1128 | - __FILE__, |
|
| 1129 | - __FUNCTION__, |
|
| 1130 | - __LINE__ |
|
| 1131 | - ); |
|
| 1132 | - return $success; |
|
| 1133 | - } |
|
| 1134 | - // let's get all the related message_template objects for this group. |
|
| 1135 | - $message_templates = $Message_Template_Group->message_templates(); |
|
| 1136 | - // now we have what we need to setup the new template |
|
| 1137 | - $new_mtg = clone $Message_Template_Group; |
|
| 1138 | - $new_mtg->set('GRP_ID', 0); |
|
| 1139 | - $new_mtg->set('MTP_is_global', false); |
|
| 1140 | - |
|
| 1141 | - /** @var RequestInterface $request */ |
|
| 1142 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 1143 | - $template_name = $request->isAjax() && $request->requestParamIsSet('templateName') |
|
| 1144 | - ? $request->getRequestParam('templateName') |
|
| 1145 | - : esc_html__('New Custom Template', 'event_espresso'); |
|
| 1146 | - $template_description = $request->isAjax() && $request->requestParamIsSet('templateDescription') |
|
| 1147 | - ? $request->getRequestParam('templateDescription') |
|
| 1148 | - : sprintf( |
|
| 1149 | - esc_html__( |
|
| 1150 | - 'This is a custom template that was created for the %s messenger and %s message type.', |
|
| 1151 | - 'event_espresso' |
|
| 1152 | - ), |
|
| 1153 | - $new_mtg->messenger_obj()->label['singular'], |
|
| 1154 | - $new_mtg->message_type_obj()->label['singular'] |
|
| 1155 | - ); |
|
| 1156 | - $new_mtg->set('MTP_name', $template_name); |
|
| 1157 | - $new_mtg->set('MTP_description', $template_description); |
|
| 1158 | - // remove ALL relations on this template group so they don't get saved! |
|
| 1159 | - $new_mtg->_remove_relations('Message_Template'); |
|
| 1160 | - $new_mtg->save(); |
|
| 1161 | - $success['GRP_ID'] = $new_mtg->ID(); |
|
| 1162 | - $success['template_name'] = $template_name; |
|
| 1163 | - // add new message templates and add relation to. |
|
| 1164 | - foreach ($message_templates as $message_template) { |
|
| 1165 | - if (! $message_template instanceof EE_Message_Template) { |
|
| 1166 | - continue; |
|
| 1167 | - } |
|
| 1168 | - $new_message_template = clone $message_template; |
|
| 1169 | - $new_message_template->set('MTP_ID', 0); |
|
| 1170 | - $new_message_template->set('GRP_ID', $new_mtg->ID()); // relation |
|
| 1171 | - $new_message_template->save(); |
|
| 1172 | - if (empty($success['MTP_context'])) { |
|
| 1173 | - $success['MTP_context'] = $new_message_template->get('MTP_context'); |
|
| 1174 | - } |
|
| 1175 | - } |
|
| 1176 | - return $success; |
|
| 1177 | - } |
|
| 1178 | - |
|
| 1179 | - |
|
| 1180 | - /** |
|
| 1181 | - * message_type_has_active_templates_for_messenger |
|
| 1182 | - * |
|
| 1183 | - * @param EE_messenger $messenger |
|
| 1184 | - * @param EE_message_type $message_type |
|
| 1185 | - * @param bool $global |
|
| 1186 | - * @return bool |
|
| 1187 | - * @throws EE_Error |
|
| 1188 | - */ |
|
| 1189 | - public static function message_type_has_active_templates_for_messenger( |
|
| 1190 | - EE_messenger $messenger, |
|
| 1191 | - EE_message_type $message_type, |
|
| 1192 | - $global = false |
|
| 1193 | - ) { |
|
| 1194 | - // is given message_type valid for given messenger (if this is not a global save) |
|
| 1195 | - if ($global) { |
|
| 1196 | - return true; |
|
| 1197 | - } |
|
| 1198 | - $active_templates = EEM_Message_Template_Group::instance()->count( |
|
| 1199 | - array( |
|
| 1200 | - array( |
|
| 1201 | - 'MTP_is_active' => true, |
|
| 1202 | - 'MTP_messenger' => $messenger->name, |
|
| 1203 | - 'MTP_message_type' => $message_type->name |
|
| 1204 | - ) |
|
| 1205 | - ) |
|
| 1206 | - ); |
|
| 1207 | - if ($active_templates > 0) { |
|
| 1208 | - return true; |
|
| 1209 | - } |
|
| 1210 | - EE_Error::add_error( |
|
| 1211 | - sprintf( |
|
| 1212 | - esc_html__( |
|
| 1213 | - 'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.', |
|
| 1214 | - 'event_espresso' |
|
| 1215 | - ), |
|
| 1216 | - $message_type->name, |
|
| 1217 | - $messenger->name |
|
| 1218 | - ), |
|
| 1219 | - __FILE__, |
|
| 1220 | - __FUNCTION__, |
|
| 1221 | - __LINE__ |
|
| 1222 | - ); |
|
| 1223 | - return false; |
|
| 1224 | - } |
|
| 1225 | - |
|
| 1226 | - |
|
| 1227 | - /** |
|
| 1228 | - * get_fields |
|
| 1229 | - * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type). |
|
| 1230 | - * |
|
| 1231 | - * @param string $messenger_name name of EE_messenger |
|
| 1232 | - * @param string $message_type_name name of EE_message_type |
|
| 1233 | - * @return array |
|
| 1234 | - * @throws EE_Error |
|
| 1235 | - * @throws ReflectionException |
|
| 1236 | - */ |
|
| 1237 | - public static function get_fields($messenger_name, $message_type_name) |
|
| 1238 | - { |
|
| 1239 | - $template_fields = array(); |
|
| 1240 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 1241 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1242 | - $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
|
| 1243 | - $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
|
| 1244 | - if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { |
|
| 1245 | - return array(); |
|
| 1246 | - } |
|
| 1247 | - |
|
| 1248 | - $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name); |
|
| 1249 | - |
|
| 1250 | - // okay now let's assemble an array with the messenger template fields added to the message_type contexts. |
|
| 1251 | - foreach ($message_type->get_contexts() as $context => $details) { |
|
| 1252 | - foreach ($messenger->get_template_fields() as $field => $value) { |
|
| 1253 | - if (in_array($field, $excluded_fields_for_messenger, true)) { |
|
| 1254 | - continue; |
|
| 1255 | - } |
|
| 1256 | - $template_fields[ $context ][ $field ] = $value; |
|
| 1257 | - } |
|
| 1258 | - } |
|
| 1259 | - if (empty($template_fields)) { |
|
| 1260 | - EE_Error::add_error( |
|
| 1261 | - esc_html__('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'), |
|
| 1262 | - __FILE__, |
|
| 1263 | - __FUNCTION__, |
|
| 1264 | - __LINE__ |
|
| 1265 | - ); |
|
| 1266 | - return array(); |
|
| 1267 | - } |
|
| 1268 | - return $template_fields; |
|
| 1269 | - } |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + |
|
| 833 | + |
|
| 834 | + |
|
| 835 | + |
|
| 836 | + /** |
|
| 837 | + * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered). |
|
| 838 | + * |
|
| 839 | + * @since 4.9.0 |
|
| 840 | + * @return array |
|
| 841 | + */ |
|
| 842 | + public static function reg_status_to_message_type_array() |
|
| 843 | + { |
|
| 844 | + return (array) apply_filters( |
|
| 845 | + 'FHEE__EEH_MSG_Template__reg_status_to_message_type_array', |
|
| 846 | + array( |
|
| 847 | + EEM_Registration::status_id_approved => 'registration', |
|
| 848 | + EEM_Registration::status_id_pending_payment => 'pending_approval', |
|
| 849 | + EEM_Registration::status_id_not_approved => 'not_approved_registration', |
|
| 850 | + EEM_Registration::status_id_cancelled => 'cancelled_registration', |
|
| 851 | + EEM_Registration::status_id_declined => 'declined_registration' |
|
| 852 | + ) |
|
| 853 | + ); |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + |
|
| 857 | + |
|
| 858 | + |
|
| 859 | + /** |
|
| 860 | + * This returns the corresponding registration message type slug to the given reg status. If there isn't a |
|
| 861 | + * match, then returns an empty string. |
|
| 862 | + * |
|
| 863 | + * @since 4.9.0 |
|
| 864 | + * @param $reg_status |
|
| 865 | + * @return string |
|
| 866 | + */ |
|
| 867 | + public static function convert_reg_status_to_message_type($reg_status) |
|
| 868 | + { |
|
| 869 | + $reg_status_array = self::reg_status_to_message_type_array(); |
|
| 870 | + return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : ''; |
|
| 871 | + } |
|
| 872 | + |
|
| 873 | + |
|
| 874 | + /** |
|
| 875 | + * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered). |
|
| 876 | + * |
|
| 877 | + * @since 4.9.0 |
|
| 878 | + * @return array |
|
| 879 | + */ |
|
| 880 | + public static function payment_status_to_message_type_array() |
|
| 881 | + { |
|
| 882 | + return (array) apply_filters( |
|
| 883 | + 'FHEE__EEH_MSG_Template__payment_status_to_message_type_array', |
|
| 884 | + array( |
|
| 885 | + EEM_Payment::status_id_approved => 'payment', |
|
| 886 | + EEM_Payment::status_id_pending => 'payment_pending', |
|
| 887 | + EEM_Payment::status_id_cancelled => 'payment_cancelled', |
|
| 888 | + EEM_Payment::status_id_declined => 'payment_declined', |
|
| 889 | + EEM_Payment::status_id_failed => 'payment_failed' |
|
| 890 | + ) |
|
| 891 | + ); |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + |
|
| 895 | + |
|
| 896 | + |
|
| 897 | + /** |
|
| 898 | + * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then |
|
| 899 | + * an empty string is returned |
|
| 900 | + * |
|
| 901 | + * @since 4.9.0 |
|
| 902 | + * @param $payment_status |
|
| 903 | + * @return string |
|
| 904 | + */ |
|
| 905 | + public static function convert_payment_status_to_message_type($payment_status) |
|
| 906 | + { |
|
| 907 | + $payment_status_array = self::payment_status_to_message_type_array(); |
|
| 908 | + return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : ''; |
|
| 909 | + } |
|
| 910 | + |
|
| 911 | + |
|
| 912 | + /** |
|
| 913 | + * This is used to retrieve the template pack for the given name. |
|
| 914 | + * |
|
| 915 | + * @param string $template_pack_name should match the set `dbref` property value on the EE_Messages_Template_Pack. |
|
| 916 | + * |
|
| 917 | + * @return EE_Messages_Template_Pack |
|
| 918 | + */ |
|
| 919 | + public static function get_template_pack($template_pack_name) |
|
| 920 | + { |
|
| 921 | + if (! self::$_template_pack_collection instanceof EE_Object_Collection) { |
|
| 922 | + self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + // first see if in collection already |
|
| 926 | + $template_pack = self::$_template_pack_collection->get_by_name($template_pack_name); |
|
| 927 | + |
|
| 928 | + if ($template_pack instanceof EE_Messages_Template_Pack) { |
|
| 929 | + return $template_pack; |
|
| 930 | + } |
|
| 931 | + |
|
| 932 | + // nope...let's get it. |
|
| 933 | + // not set yet so let's attempt to get it. |
|
| 934 | + $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
| 935 | + ' ', |
|
| 936 | + '_', |
|
| 937 | + ucwords( |
|
| 938 | + str_replace('_', ' ', $template_pack_name) |
|
| 939 | + ) |
|
| 940 | + ); |
|
| 941 | + if (! class_exists($pack_class_name) && $template_pack_name !== 'default') { |
|
| 942 | + return self::get_template_pack('default'); |
|
| 943 | + } else { |
|
| 944 | + $template_pack = new $pack_class_name(); |
|
| 945 | + self::$_template_pack_collection->add($template_pack); |
|
| 946 | + return $template_pack; |
|
| 947 | + } |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * Globs template packs installed in core and returns the template pack collection with all installed template packs |
|
| 955 | + * in it. |
|
| 956 | + * |
|
| 957 | + * @since 4.9.0 |
|
| 958 | + * |
|
| 959 | + * @return EE_Messages_Template_Pack_Collection |
|
| 960 | + */ |
|
| 961 | + public static function get_template_pack_collection() |
|
| 962 | + { |
|
| 963 | + $new_collection = false; |
|
| 964 | + if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { |
|
| 965 | + self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
|
| 966 | + $new_collection = true; |
|
| 967 | + } |
|
| 968 | + |
|
| 969 | + // glob the defaults directory for messages |
|
| 970 | + $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR); |
|
| 971 | + foreach ($templates as $template_path) { |
|
| 972 | + // grab folder name |
|
| 973 | + $template = basename($template_path); |
|
| 974 | + |
|
| 975 | + if (! $new_collection) { |
|
| 976 | + // already have it? |
|
| 977 | + if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) { |
|
| 978 | + continue; |
|
| 979 | + } |
|
| 980 | + } |
|
| 981 | + |
|
| 982 | + // setup classname. |
|
| 983 | + $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
| 984 | + ' ', |
|
| 985 | + '_', |
|
| 986 | + ucwords( |
|
| 987 | + str_replace( |
|
| 988 | + '_', |
|
| 989 | + ' ', |
|
| 990 | + $template |
|
| 991 | + ) |
|
| 992 | + ) |
|
| 993 | + ); |
|
| 994 | + if (! class_exists($template_pack_class_name)) { |
|
| 995 | + continue; |
|
| 996 | + } |
|
| 997 | + self::$_template_pack_collection->add(new $template_pack_class_name()); |
|
| 998 | + } |
|
| 999 | + |
|
| 1000 | + /** |
|
| 1001 | + * Filter for plugins to add in any additional template packs |
|
| 1002 | + * Note the filter name here is for backward compat, this used to be found in EED_Messages. |
|
| 1003 | + */ |
|
| 1004 | + $additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array()); |
|
| 1005 | + foreach ((array) $additional_template_packs as $template_pack) { |
|
| 1006 | + if ( |
|
| 1007 | + self::$_template_pack_collection->get_by_name( |
|
| 1008 | + $template_pack->dbref |
|
| 1009 | + ) instanceof EE_Messages_Template_Pack |
|
| 1010 | + ) { |
|
| 1011 | + continue; |
|
| 1012 | + } |
|
| 1013 | + self::$_template_pack_collection->add($template_pack); |
|
| 1014 | + } |
|
| 1015 | + return self::$_template_pack_collection; |
|
| 1016 | + } |
|
| 1017 | + |
|
| 1018 | + |
|
| 1019 | + /** |
|
| 1020 | + * This is a wrapper for the protected _create_new_templates function |
|
| 1021 | + * |
|
| 1022 | + * @param string $messenger_name |
|
| 1023 | + * @param string $message_type_name message type that the templates are being created for |
|
| 1024 | + * @param int $GRP_ID |
|
| 1025 | + * @param bool $global |
|
| 1026 | + * @return array |
|
| 1027 | + * @throws EE_Error |
|
| 1028 | + * @throws ReflectionException |
|
| 1029 | + */ |
|
| 1030 | + public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false) |
|
| 1031 | + { |
|
| 1032 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 1033 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1034 | + $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
|
| 1035 | + $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
|
| 1036 | + if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { |
|
| 1037 | + return array(); |
|
| 1038 | + } |
|
| 1039 | + // whew made it this far! Okay, let's go ahead and create the templates then |
|
| 1040 | + return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global); |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + |
|
| 1044 | + /** |
|
| 1045 | + * @param EE_messenger $messenger |
|
| 1046 | + * @param EE_message_type $message_type |
|
| 1047 | + * @param $GRP_ID |
|
| 1048 | + * @param $global |
|
| 1049 | + * @return array|mixed |
|
| 1050 | + * @throws EE_Error |
|
| 1051 | + * @throws ReflectionException |
|
| 1052 | + */ |
|
| 1053 | + protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global) |
|
| 1054 | + { |
|
| 1055 | + // if we're creating a custom template then we don't need to use the defaults class |
|
| 1056 | + if (! $global) { |
|
| 1057 | + return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID); |
|
| 1058 | + } |
|
| 1059 | + /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */ |
|
| 1060 | + $Message_Template_Defaults = EE_Registry::factory( |
|
| 1061 | + 'EE_Messages_Template_Defaults', |
|
| 1062 | + array( $messenger, $message_type, $GRP_ID ) |
|
| 1063 | + ); |
|
| 1064 | + // generate templates |
|
| 1065 | + $success = $Message_Template_Defaults->create_new_templates(); |
|
| 1066 | + |
|
| 1067 | + // if creating the template failed. Then we should deactivate the related message_type for the messenger because |
|
| 1068 | + // its not active if it doesn't have a template. Note this is only happening for GLOBAL template creation |
|
| 1069 | + // attempts. |
|
| 1070 | + if (! $success) { |
|
| 1071 | + /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1072 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1073 | + $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name); |
|
| 1074 | + } |
|
| 1075 | + |
|
| 1076 | + /** |
|
| 1077 | + * $success is in an array in the following format |
|
| 1078 | + * array( |
|
| 1079 | + * 'GRP_ID' => $new_grp_id, |
|
| 1080 | + * 'MTP_context' => $first_context_in_new_templates, |
|
| 1081 | + * ) |
|
| 1082 | + */ |
|
| 1083 | + return $success; |
|
| 1084 | + } |
|
| 1085 | + |
|
| 1086 | + |
|
| 1087 | + /** |
|
| 1088 | + * This creates a custom template using the incoming GRP_ID |
|
| 1089 | + * |
|
| 1090 | + * @param EE_messenger $messenger |
|
| 1091 | + * @param EE_message_type $message_type |
|
| 1092 | + * @param int $GRP_ID GRP_ID for the template_group being used as the base |
|
| 1093 | + * @return array $success This will be an array in the format: |
|
| 1094 | + * array( |
|
| 1095 | + * 'GRP_ID' => $new_grp_id, |
|
| 1096 | + * 'MTP_context' => $first_context_in_created_template |
|
| 1097 | + * ) |
|
| 1098 | + * @throws EE_Error |
|
| 1099 | + * @throws ReflectionException |
|
| 1100 | + * @access private |
|
| 1101 | + */ |
|
| 1102 | + private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID) |
|
| 1103 | + { |
|
| 1104 | + // defaults |
|
| 1105 | + $success = array( 'GRP_ID' => null, 'MTP_context' => '' ); |
|
| 1106 | + // get the template group to use as a template from the db. If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type. |
|
| 1107 | + $Message_Template_Group = empty($GRP_ID) |
|
| 1108 | + ? EEM_Message_Template_Group::instance()->get_one( |
|
| 1109 | + array( |
|
| 1110 | + array( |
|
| 1111 | + 'MTP_messenger' => $messenger->name, |
|
| 1112 | + 'MTP_message_type' => $message_type->name, |
|
| 1113 | + 'MTP_is_global' => true |
|
| 1114 | + ) |
|
| 1115 | + ) |
|
| 1116 | + ) |
|
| 1117 | + : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1118 | + // if we don't have a mtg at this point then we need to bail. |
|
| 1119 | + if (! $Message_Template_Group instanceof EE_Message_Template_Group) { |
|
| 1120 | + EE_Error::add_error( |
|
| 1121 | + sprintf( |
|
| 1122 | + esc_html__( |
|
| 1123 | + 'Something went wrong with generating the custom template from this group id: %s. This usually happens when there is no matching message template group in the db.', |
|
| 1124 | + 'event_espresso' |
|
| 1125 | + ), |
|
| 1126 | + $GRP_ID |
|
| 1127 | + ), |
|
| 1128 | + __FILE__, |
|
| 1129 | + __FUNCTION__, |
|
| 1130 | + __LINE__ |
|
| 1131 | + ); |
|
| 1132 | + return $success; |
|
| 1133 | + } |
|
| 1134 | + // let's get all the related message_template objects for this group. |
|
| 1135 | + $message_templates = $Message_Template_Group->message_templates(); |
|
| 1136 | + // now we have what we need to setup the new template |
|
| 1137 | + $new_mtg = clone $Message_Template_Group; |
|
| 1138 | + $new_mtg->set('GRP_ID', 0); |
|
| 1139 | + $new_mtg->set('MTP_is_global', false); |
|
| 1140 | + |
|
| 1141 | + /** @var RequestInterface $request */ |
|
| 1142 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 1143 | + $template_name = $request->isAjax() && $request->requestParamIsSet('templateName') |
|
| 1144 | + ? $request->getRequestParam('templateName') |
|
| 1145 | + : esc_html__('New Custom Template', 'event_espresso'); |
|
| 1146 | + $template_description = $request->isAjax() && $request->requestParamIsSet('templateDescription') |
|
| 1147 | + ? $request->getRequestParam('templateDescription') |
|
| 1148 | + : sprintf( |
|
| 1149 | + esc_html__( |
|
| 1150 | + 'This is a custom template that was created for the %s messenger and %s message type.', |
|
| 1151 | + 'event_espresso' |
|
| 1152 | + ), |
|
| 1153 | + $new_mtg->messenger_obj()->label['singular'], |
|
| 1154 | + $new_mtg->message_type_obj()->label['singular'] |
|
| 1155 | + ); |
|
| 1156 | + $new_mtg->set('MTP_name', $template_name); |
|
| 1157 | + $new_mtg->set('MTP_description', $template_description); |
|
| 1158 | + // remove ALL relations on this template group so they don't get saved! |
|
| 1159 | + $new_mtg->_remove_relations('Message_Template'); |
|
| 1160 | + $new_mtg->save(); |
|
| 1161 | + $success['GRP_ID'] = $new_mtg->ID(); |
|
| 1162 | + $success['template_name'] = $template_name; |
|
| 1163 | + // add new message templates and add relation to. |
|
| 1164 | + foreach ($message_templates as $message_template) { |
|
| 1165 | + if (! $message_template instanceof EE_Message_Template) { |
|
| 1166 | + continue; |
|
| 1167 | + } |
|
| 1168 | + $new_message_template = clone $message_template; |
|
| 1169 | + $new_message_template->set('MTP_ID', 0); |
|
| 1170 | + $new_message_template->set('GRP_ID', $new_mtg->ID()); // relation |
|
| 1171 | + $new_message_template->save(); |
|
| 1172 | + if (empty($success['MTP_context'])) { |
|
| 1173 | + $success['MTP_context'] = $new_message_template->get('MTP_context'); |
|
| 1174 | + } |
|
| 1175 | + } |
|
| 1176 | + return $success; |
|
| 1177 | + } |
|
| 1178 | + |
|
| 1179 | + |
|
| 1180 | + /** |
|
| 1181 | + * message_type_has_active_templates_for_messenger |
|
| 1182 | + * |
|
| 1183 | + * @param EE_messenger $messenger |
|
| 1184 | + * @param EE_message_type $message_type |
|
| 1185 | + * @param bool $global |
|
| 1186 | + * @return bool |
|
| 1187 | + * @throws EE_Error |
|
| 1188 | + */ |
|
| 1189 | + public static function message_type_has_active_templates_for_messenger( |
|
| 1190 | + EE_messenger $messenger, |
|
| 1191 | + EE_message_type $message_type, |
|
| 1192 | + $global = false |
|
| 1193 | + ) { |
|
| 1194 | + // is given message_type valid for given messenger (if this is not a global save) |
|
| 1195 | + if ($global) { |
|
| 1196 | + return true; |
|
| 1197 | + } |
|
| 1198 | + $active_templates = EEM_Message_Template_Group::instance()->count( |
|
| 1199 | + array( |
|
| 1200 | + array( |
|
| 1201 | + 'MTP_is_active' => true, |
|
| 1202 | + 'MTP_messenger' => $messenger->name, |
|
| 1203 | + 'MTP_message_type' => $message_type->name |
|
| 1204 | + ) |
|
| 1205 | + ) |
|
| 1206 | + ); |
|
| 1207 | + if ($active_templates > 0) { |
|
| 1208 | + return true; |
|
| 1209 | + } |
|
| 1210 | + EE_Error::add_error( |
|
| 1211 | + sprintf( |
|
| 1212 | + esc_html__( |
|
| 1213 | + 'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.', |
|
| 1214 | + 'event_espresso' |
|
| 1215 | + ), |
|
| 1216 | + $message_type->name, |
|
| 1217 | + $messenger->name |
|
| 1218 | + ), |
|
| 1219 | + __FILE__, |
|
| 1220 | + __FUNCTION__, |
|
| 1221 | + __LINE__ |
|
| 1222 | + ); |
|
| 1223 | + return false; |
|
| 1224 | + } |
|
| 1225 | + |
|
| 1226 | + |
|
| 1227 | + /** |
|
| 1228 | + * get_fields |
|
| 1229 | + * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type). |
|
| 1230 | + * |
|
| 1231 | + * @param string $messenger_name name of EE_messenger |
|
| 1232 | + * @param string $message_type_name name of EE_message_type |
|
| 1233 | + * @return array |
|
| 1234 | + * @throws EE_Error |
|
| 1235 | + * @throws ReflectionException |
|
| 1236 | + */ |
|
| 1237 | + public static function get_fields($messenger_name, $message_type_name) |
|
| 1238 | + { |
|
| 1239 | + $template_fields = array(); |
|
| 1240 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 1241 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1242 | + $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
|
| 1243 | + $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
|
| 1244 | + if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { |
|
| 1245 | + return array(); |
|
| 1246 | + } |
|
| 1247 | + |
|
| 1248 | + $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name); |
|
| 1249 | + |
|
| 1250 | + // okay now let's assemble an array with the messenger template fields added to the message_type contexts. |
|
| 1251 | + foreach ($message_type->get_contexts() as $context => $details) { |
|
| 1252 | + foreach ($messenger->get_template_fields() as $field => $value) { |
|
| 1253 | + if (in_array($field, $excluded_fields_for_messenger, true)) { |
|
| 1254 | + continue; |
|
| 1255 | + } |
|
| 1256 | + $template_fields[ $context ][ $field ] = $value; |
|
| 1257 | + } |
|
| 1258 | + } |
|
| 1259 | + if (empty($template_fields)) { |
|
| 1260 | + EE_Error::add_error( |
|
| 1261 | + esc_html__('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'), |
|
| 1262 | + __FILE__, |
|
| 1263 | + __FUNCTION__, |
|
| 1264 | + __LINE__ |
|
| 1265 | + ); |
|
| 1266 | + return array(); |
|
| 1267 | + } |
|
| 1268 | + return $template_fields; |
|
| 1269 | + } |
|
| 1270 | 1270 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | } |
| 96 | 96 | $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global); |
| 97 | 97 | |
| 98 | - if (! $new_message_template_group) { |
|
| 98 | + if ( ! $new_message_template_group) { |
|
| 99 | 99 | continue; |
| 100 | 100 | } |
| 101 | 101 | $templates[] = $new_message_template_group; |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | ) |
| 131 | 131 | ) |
| 132 | 132 | ) |
| 133 | - : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) )); |
|
| 133 | + : EEM_Message_Template::instance()->count(array(array('GRP_ID' => $GRP_ID))); |
|
| 134 | 134 | |
| 135 | 135 | return $count > 0; |
| 136 | 136 | } |
@@ -147,14 +147,14 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | public static function update_to_active($messenger_names, $message_type_names) |
| 149 | 149 | { |
| 150 | - $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names ); |
|
| 151 | - $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names ); |
|
| 150 | + $messenger_names = is_array($messenger_names) ? $messenger_names : array($messenger_names); |
|
| 151 | + $message_type_names = is_array($message_type_names) ? $message_type_names : array($message_type_names); |
|
| 152 | 152 | return EEM_Message_Template_Group::instance()->update( |
| 153 | - array( 'MTP_is_active' => 1 ), |
|
| 153 | + array('MTP_is_active' => 1), |
|
| 154 | 154 | array( |
| 155 | 155 | array( |
| 156 | - 'MTP_messenger' => array( 'IN', $messenger_names ), |
|
| 157 | - 'MTP_message_type' => array( 'IN', $message_type_names ) |
|
| 156 | + 'MTP_messenger' => array('IN', $messenger_names), |
|
| 157 | + 'MTP_message_type' => array('IN', $message_type_names) |
|
| 158 | 158 | ) |
| 159 | 159 | ) |
| 160 | 160 | ); |
@@ -242,13 +242,13 @@ discard block |
||
| 242 | 242 | $messenger = $message_resource_manager->get_messenger($messenger); |
| 243 | 243 | |
| 244 | 244 | // if messenger isn't a EE_messenger resource then bail. |
| 245 | - if (! $messenger instanceof EE_messenger) { |
|
| 245 | + if ( ! $messenger instanceof EE_messenger) { |
|
| 246 | 246 | return array(); |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | // validate class for getting our list of shortcodes |
| 250 | - $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator'; |
|
| 251 | - if (! class_exists($classname)) { |
|
| 250 | + $classname = 'EE_Messages_'.$messenger_name.'_'.$mt_name.'_Validator'; |
|
| 251 | + if ( ! class_exists($classname)) { |
|
| 252 | 252 | $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); |
| 253 | 253 | $msg[] = sprintf( |
| 254 | 254 | esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'), |
@@ -264,44 +264,44 @@ discard block |
||
| 264 | 264 | // let's make sure we're only getting the shortcode part of the validators |
| 265 | 265 | $shortcodes = array(); |
| 266 | 266 | foreach ($valid_shortcodes as $field => $validators) { |
| 267 | - $shortcodes[ $field ] = $validators['shortcodes']; |
|
| 267 | + $shortcodes[$field] = $validators['shortcodes']; |
|
| 268 | 268 | } |
| 269 | 269 | $valid_shortcodes = $shortcodes; |
| 270 | 270 | |
| 271 | 271 | // if not all fields let's make sure we ONLY include the shortcodes for the specified fields. |
| 272 | - if (! empty($fields)) { |
|
| 272 | + if ( ! empty($fields)) { |
|
| 273 | 273 | $specified_shortcodes = array(); |
| 274 | 274 | foreach ($fields as $field) { |
| 275 | - if (isset($valid_shortcodes[ $field ])) { |
|
| 276 | - $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ]; |
|
| 275 | + if (isset($valid_shortcodes[$field])) { |
|
| 276 | + $specified_shortcodes[$field] = $valid_shortcodes[$field]; |
|
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | 279 | $valid_shortcodes = $specified_shortcodes; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | // if not merged then let's replace the fields with the localized fields |
| 283 | - if (! $merged) { |
|
| 283 | + if ( ! $merged) { |
|
| 284 | 284 | // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array. |
| 285 | 285 | $field_settings = $messenger->get_template_fields(); |
| 286 | 286 | $localized = array(); |
| 287 | 287 | foreach ($valid_shortcodes as $field => $shortcodes) { |
| 288 | 288 | // get localized field label |
| 289 | - if (isset($field_settings[ $field ])) { |
|
| 289 | + if (isset($field_settings[$field])) { |
|
| 290 | 290 | // possible that this is used as a main field. |
| 291 | - if (empty($field_settings[ $field ])) { |
|
| 292 | - if (isset($field_settings['extra'][ $field ])) { |
|
| 293 | - $_field = $field_settings['extra'][ $field ]['main']['label']; |
|
| 291 | + if (empty($field_settings[$field])) { |
|
| 292 | + if (isset($field_settings['extra'][$field])) { |
|
| 293 | + $_field = $field_settings['extra'][$field]['main']['label']; |
|
| 294 | 294 | } else { |
| 295 | 295 | $_field = $field; |
| 296 | 296 | } |
| 297 | 297 | } else { |
| 298 | - $_field = $field_settings[ $field ]['label']; |
|
| 298 | + $_field = $field_settings[$field]['label']; |
|
| 299 | 299 | } |
| 300 | 300 | } elseif (isset($field_settings['extra'])) { |
| 301 | 301 | // loop through extra "main fields" and see if any of their children have our field |
| 302 | 302 | foreach ($field_settings['extra'] as $fields) { |
| 303 | - if (isset($fields[ $field ])) { |
|
| 304 | - $_field = $fields[ $field ]['label']; |
|
| 303 | + if (isset($fields[$field])) { |
|
| 304 | + $_field = $fields[$field]['label']; |
|
| 305 | 305 | } else { |
| 306 | 306 | $_field = $field; |
| 307 | 307 | } |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | $_field = $field; |
| 311 | 311 | } |
| 312 | 312 | if (isset($_field)) { |
| 313 | - $localized[ (string) $_field ] = $shortcodes; |
|
| 313 | + $localized[(string) $_field] = $shortcodes; |
|
| 314 | 314 | } |
| 315 | 315 | } |
| 316 | 316 | $valid_shortcodes = $localized; |
@@ -321,10 +321,10 @@ discard block |
||
| 321 | 321 | $merged_codes = array(); |
| 322 | 322 | foreach ($valid_shortcodes as $shortcode) { |
| 323 | 323 | foreach ($shortcode as $code => $label) { |
| 324 | - if (isset($merged_codes[ $code ])) { |
|
| 324 | + if (isset($merged_codes[$code])) { |
|
| 325 | 325 | continue; |
| 326 | 326 | } else { |
| 327 | - $merged_codes[ $code ] = $label; |
|
| 327 | + $merged_codes[$code] = $label; |
|
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | } |
@@ -475,12 +475,12 @@ discard block |
||
| 475 | 475 | $sending_messenger = '' |
| 476 | 476 | ) { |
| 477 | 477 | // first determine if the url can be to the EE_Message object. |
| 478 | - if (! $message_type->always_generate()) { |
|
| 478 | + if ( ! $message_type->always_generate()) { |
|
| 479 | 479 | return EEH_MSG_Template::generate_browser_trigger($message); |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | // if $registration object is not valid then exit early because there's nothing that can be generated. |
| 483 | - if (! $registration instanceof EE_Registration) { |
|
| 483 | + if ( ! $registration instanceof EE_Registration) { |
|
| 484 | 484 | throw new EE_Error( |
| 485 | 485 | esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso') |
| 486 | 486 | ); |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | |
| 489 | 489 | // validate given context |
| 490 | 490 | $contexts = $message_type->get_contexts(); |
| 491 | - if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) { |
|
| 491 | + if ($message->context() !== '' && ! isset($contexts[$message->context()])) { |
|
| 492 | 492 | throw new EE_Error( |
| 493 | 493 | sprintf( |
| 494 | 494 | esc_html__('The context %s is not a valid context for %s.', 'event_espresso'), |
@@ -499,11 +499,11 @@ discard block |
||
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | // valid sending messenger but only if sending messenger set. Otherwise generating messenger is used. |
| 502 | - if (! empty($sending_messenger)) { |
|
| 502 | + if ( ! empty($sending_messenger)) { |
|
| 503 | 503 | $with_messengers = $message_type->with_messengers(); |
| 504 | 504 | if ( |
| 505 | - ! isset($with_messengers[ $message->messenger() ]) |
|
| 506 | - || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ]) |
|
| 505 | + ! isset($with_messengers[$message->messenger()]) |
|
| 506 | + || ! in_array($sending_messenger, $with_messengers[$message->messenger()]) |
|
| 507 | 507 | ) { |
| 508 | 508 | throw new EE_Error( |
| 509 | 509 | sprintf( |
@@ -636,7 +636,7 @@ discard block |
||
| 636 | 636 | public static function get_message_action_icon($type) |
| 637 | 637 | { |
| 638 | 638 | $action_icons = self::get_message_action_icons(); |
| 639 | - return isset($action_icons[ $type ]) ? $action_icons[ $type ] : []; |
|
| 639 | + return isset($action_icons[$type]) ? $action_icons[$type] : []; |
|
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | |
@@ -701,7 +701,7 @@ discard block |
||
| 701 | 701 | public static function get_message_action_url($type, EE_Message $message = null, $query_params = array()) |
| 702 | 702 | { |
| 703 | 703 | $action_urls = self::get_message_action_urls($message, $query_params); |
| 704 | - return isset($action_urls[ $type ]) ? $action_urls[ $type ] : ''; |
|
| 704 | + return isset($action_urls[$type]) ? $action_urls[$type] : ''; |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | |
@@ -722,7 +722,7 @@ discard block |
||
| 722 | 722 | EE_Registry::instance()->load_helper('URL'); |
| 723 | 723 | // if $message is not an instance of EE_Message then let's just do a dummy. |
| 724 | 724 | $message = empty($message) ? EE_Message_Factory::create() : $message; |
| 725 | - $action_urls = apply_filters( |
|
| 725 | + $action_urls = apply_filters( |
|
| 726 | 726 | 'FHEE__EEH_MSG_Template__get_message_action_url', |
| 727 | 727 | array( |
| 728 | 728 | 'view' => EEH_MSG_Template::generate_browser_trigger($message), |
@@ -806,7 +806,7 @@ discard block |
||
| 806 | 806 | $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params); |
| 807 | 807 | $icon_css = EEH_MSG_Template::get_message_action_icon($type); |
| 808 | 808 | $label = $icon_css['label'] ?? null; |
| 809 | - $label = $label ? 'aria-label="' . $label . '"' : ''; |
|
| 809 | + $label = $label ? 'aria-label="'.$label.'"' : ''; |
|
| 810 | 810 | $class = $label ? ' ee-aria-tooltip' : ''; |
| 811 | 811 | |
| 812 | 812 | if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) { |
@@ -816,7 +816,7 @@ discard block |
||
| 816 | 816 | $icon_css['css_class'] .= esc_attr( |
| 817 | 817 | apply_filters( |
| 818 | 818 | 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class', |
| 819 | - ' js-ee-message-action-link ee-message-action-link-' . $type, |
|
| 819 | + ' js-ee-message-action-link ee-message-action-link-'.$type, |
|
| 820 | 820 | $type, |
| 821 | 821 | $message, |
| 822 | 822 | $query_params |
@@ -824,8 +824,8 @@ discard block |
||
| 824 | 824 | ); |
| 825 | 825 | |
| 826 | 826 | return ' |
| 827 | - <a href="' . $url . '" ' . $label . ' class="button button--icon-only' . $class . '"> |
|
| 828 | - <span class="' . esc_attr($icon_css['css_class']) . '"></span> |
|
| 827 | + <a href="' . $url.'" '.$label.' class="button button--icon-only'.$class.'"> |
|
| 828 | + <span class="' . esc_attr($icon_css['css_class']).'"></span> |
|
| 829 | 829 | </a>'; |
| 830 | 830 | } |
| 831 | 831 | |
@@ -867,7 +867,7 @@ discard block |
||
| 867 | 867 | public static function convert_reg_status_to_message_type($reg_status) |
| 868 | 868 | { |
| 869 | 869 | $reg_status_array = self::reg_status_to_message_type_array(); |
| 870 | - return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : ''; |
|
| 870 | + return isset($reg_status_array[$reg_status]) ? $reg_status_array[$reg_status] : ''; |
|
| 871 | 871 | } |
| 872 | 872 | |
| 873 | 873 | |
@@ -905,7 +905,7 @@ discard block |
||
| 905 | 905 | public static function convert_payment_status_to_message_type($payment_status) |
| 906 | 906 | { |
| 907 | 907 | $payment_status_array = self::payment_status_to_message_type_array(); |
| 908 | - return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : ''; |
|
| 908 | + return isset($payment_status_array[$payment_status]) ? $payment_status_array[$payment_status] : ''; |
|
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | |
@@ -918,7 +918,7 @@ discard block |
||
| 918 | 918 | */ |
| 919 | 919 | public static function get_template_pack($template_pack_name) |
| 920 | 920 | { |
| 921 | - if (! self::$_template_pack_collection instanceof EE_Object_Collection) { |
|
| 921 | + if ( ! self::$_template_pack_collection instanceof EE_Object_Collection) { |
|
| 922 | 922 | self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
| 923 | 923 | } |
| 924 | 924 | |
@@ -931,14 +931,14 @@ discard block |
||
| 931 | 931 | |
| 932 | 932 | // nope...let's get it. |
| 933 | 933 | // not set yet so let's attempt to get it. |
| 934 | - $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
| 934 | + $pack_class_name = 'EE_Messages_Template_Pack_'.str_replace( |
|
| 935 | 935 | ' ', |
| 936 | 936 | '_', |
| 937 | 937 | ucwords( |
| 938 | 938 | str_replace('_', ' ', $template_pack_name) |
| 939 | 939 | ) |
| 940 | 940 | ); |
| 941 | - if (! class_exists($pack_class_name) && $template_pack_name !== 'default') { |
|
| 941 | + if ( ! class_exists($pack_class_name) && $template_pack_name !== 'default') { |
|
| 942 | 942 | return self::get_template_pack('default'); |
| 943 | 943 | } else { |
| 944 | 944 | $template_pack = new $pack_class_name(); |
@@ -961,18 +961,18 @@ discard block |
||
| 961 | 961 | public static function get_template_pack_collection() |
| 962 | 962 | { |
| 963 | 963 | $new_collection = false; |
| 964 | - if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { |
|
| 964 | + if ( ! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { |
|
| 965 | 965 | self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
| 966 | 966 | $new_collection = true; |
| 967 | 967 | } |
| 968 | 968 | |
| 969 | 969 | // glob the defaults directory for messages |
| 970 | - $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR); |
|
| 970 | + $templates = glob(EE_LIBRARIES.'messages/defaults/*', GLOB_ONLYDIR); |
|
| 971 | 971 | foreach ($templates as $template_path) { |
| 972 | 972 | // grab folder name |
| 973 | 973 | $template = basename($template_path); |
| 974 | 974 | |
| 975 | - if (! $new_collection) { |
|
| 975 | + if ( ! $new_collection) { |
|
| 976 | 976 | // already have it? |
| 977 | 977 | if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) { |
| 978 | 978 | continue; |
@@ -980,7 +980,7 @@ discard block |
||
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | // setup classname. |
| 983 | - $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
| 983 | + $template_pack_class_name = 'EE_Messages_Template_Pack_'.str_replace( |
|
| 984 | 984 | ' ', |
| 985 | 985 | '_', |
| 986 | 986 | ucwords( |
@@ -991,7 +991,7 @@ discard block |
||
| 991 | 991 | ) |
| 992 | 992 | ) |
| 993 | 993 | ); |
| 994 | - if (! class_exists($template_pack_class_name)) { |
|
| 994 | + if ( ! class_exists($template_pack_class_name)) { |
|
| 995 | 995 | continue; |
| 996 | 996 | } |
| 997 | 997 | self::$_template_pack_collection->add(new $template_pack_class_name()); |
@@ -1033,7 +1033,7 @@ discard block |
||
| 1033 | 1033 | $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
| 1034 | 1034 | $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
| 1035 | 1035 | $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
| 1036 | - if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { |
|
| 1036 | + if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { |
|
| 1037 | 1037 | return array(); |
| 1038 | 1038 | } |
| 1039 | 1039 | // whew made it this far! Okay, let's go ahead and create the templates then |
@@ -1053,13 +1053,13 @@ discard block |
||
| 1053 | 1053 | protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global) |
| 1054 | 1054 | { |
| 1055 | 1055 | // if we're creating a custom template then we don't need to use the defaults class |
| 1056 | - if (! $global) { |
|
| 1056 | + if ( ! $global) { |
|
| 1057 | 1057 | return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID); |
| 1058 | 1058 | } |
| 1059 | 1059 | /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */ |
| 1060 | 1060 | $Message_Template_Defaults = EE_Registry::factory( |
| 1061 | 1061 | 'EE_Messages_Template_Defaults', |
| 1062 | - array( $messenger, $message_type, $GRP_ID ) |
|
| 1062 | + array($messenger, $message_type, $GRP_ID) |
|
| 1063 | 1063 | ); |
| 1064 | 1064 | // generate templates |
| 1065 | 1065 | $success = $Message_Template_Defaults->create_new_templates(); |
@@ -1067,7 +1067,7 @@ discard block |
||
| 1067 | 1067 | // if creating the template failed. Then we should deactivate the related message_type for the messenger because |
| 1068 | 1068 | // its not active if it doesn't have a template. Note this is only happening for GLOBAL template creation |
| 1069 | 1069 | // attempts. |
| 1070 | - if (! $success) { |
|
| 1070 | + if ( ! $success) { |
|
| 1071 | 1071 | /** @var EE_Message_Resource_Manager $message_resource_manager */ |
| 1072 | 1072 | $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
| 1073 | 1073 | $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name); |
@@ -1102,7 +1102,7 @@ discard block |
||
| 1102 | 1102 | private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID) |
| 1103 | 1103 | { |
| 1104 | 1104 | // defaults |
| 1105 | - $success = array( 'GRP_ID' => null, 'MTP_context' => '' ); |
|
| 1105 | + $success = array('GRP_ID' => null, 'MTP_context' => ''); |
|
| 1106 | 1106 | // get the template group to use as a template from the db. If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type. |
| 1107 | 1107 | $Message_Template_Group = empty($GRP_ID) |
| 1108 | 1108 | ? EEM_Message_Template_Group::instance()->get_one( |
@@ -1116,7 +1116,7 @@ discard block |
||
| 1116 | 1116 | ) |
| 1117 | 1117 | : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
| 1118 | 1118 | // if we don't have a mtg at this point then we need to bail. |
| 1119 | - if (! $Message_Template_Group instanceof EE_Message_Template_Group) { |
|
| 1119 | + if ( ! $Message_Template_Group instanceof EE_Message_Template_Group) { |
|
| 1120 | 1120 | EE_Error::add_error( |
| 1121 | 1121 | sprintf( |
| 1122 | 1122 | esc_html__( |
@@ -1162,7 +1162,7 @@ discard block |
||
| 1162 | 1162 | $success['template_name'] = $template_name; |
| 1163 | 1163 | // add new message templates and add relation to. |
| 1164 | 1164 | foreach ($message_templates as $message_template) { |
| 1165 | - if (! $message_template instanceof EE_Message_Template) { |
|
| 1165 | + if ( ! $message_template instanceof EE_Message_Template) { |
|
| 1166 | 1166 | continue; |
| 1167 | 1167 | } |
| 1168 | 1168 | $new_message_template = clone $message_template; |
@@ -1241,7 +1241,7 @@ discard block |
||
| 1241 | 1241 | $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
| 1242 | 1242 | $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
| 1243 | 1243 | $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
| 1244 | - if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { |
|
| 1244 | + if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { |
|
| 1245 | 1245 | return array(); |
| 1246 | 1246 | } |
| 1247 | 1247 | |
@@ -1253,7 +1253,7 @@ discard block |
||
| 1253 | 1253 | if (in_array($field, $excluded_fields_for_messenger, true)) { |
| 1254 | 1254 | continue; |
| 1255 | 1255 | } |
| 1256 | - $template_fields[ $context ][ $field ] = $value; |
|
| 1256 | + $template_fields[$context][$field] = $value; |
|
| 1257 | 1257 | } |
| 1258 | 1258 | } |
| 1259 | 1259 | if (empty($template_fields)) { |
@@ -6,36 +6,36 @@ discard block |
||
| 6 | 6 | use EventEspresso\core\services\request\RequestInterface; |
| 7 | 7 | |
| 8 | 8 | if (! function_exists('espresso_get_template_part')) { |
| 9 | - /** |
|
| 10 | - * espresso_get_template_part |
|
| 11 | - * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
|
| 12 | - * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name |
|
| 13 | - * |
|
| 14 | - * @param string $slug The slug name for the generic template. |
|
| 15 | - * @param string $name The name of the specialised template. |
|
| 16 | - */ |
|
| 17 | - function espresso_get_template_part($slug = null, $name = null) |
|
| 18 | - { |
|
| 19 | - EEH_Template::get_template_part($slug, $name); |
|
| 20 | - } |
|
| 9 | + /** |
|
| 10 | + * espresso_get_template_part |
|
| 11 | + * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
|
| 12 | + * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name |
|
| 13 | + * |
|
| 14 | + * @param string $slug The slug name for the generic template. |
|
| 15 | + * @param string $name The name of the specialised template. |
|
| 16 | + */ |
|
| 17 | + function espresso_get_template_part($slug = null, $name = null) |
|
| 18 | + { |
|
| 19 | + EEH_Template::get_template_part($slug, $name); |
|
| 20 | + } |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
| 24 | 24 | if (! function_exists('espresso_get_object_css_class')) { |
| 25 | - /** |
|
| 26 | - * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
| 27 | - * |
|
| 28 | - * @param EE_Base_Class $object the EE object the css class is being generated for |
|
| 29 | - * @param string $prefix added to the beginning of the generated class |
|
| 30 | - * @param string $suffix added to the end of the generated class |
|
| 31 | - * @return string |
|
| 32 | - * @throws EE_Error |
|
| 33 | - * @throws ReflectionException |
|
| 34 | - */ |
|
| 35 | - function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
| 36 | - { |
|
| 37 | - return EEH_Template::get_object_css_class($object, $prefix, $suffix); |
|
| 38 | - } |
|
| 25 | + /** |
|
| 26 | + * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
| 27 | + * |
|
| 28 | + * @param EE_Base_Class $object the EE object the css class is being generated for |
|
| 29 | + * @param string $prefix added to the beginning of the generated class |
|
| 30 | + * @param string $suffix added to the end of the generated class |
|
| 31 | + * @return string |
|
| 32 | + * @throws EE_Error |
|
| 33 | + * @throws ReflectionException |
|
| 34 | + */ |
|
| 35 | + function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
| 36 | + { |
|
| 37 | + return EEH_Template::get_object_css_class($object, $prefix, $suffix); |
|
| 38 | + } |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | |
@@ -50,708 +50,708 @@ discard block |
||
| 50 | 50 | class EEH_Template |
| 51 | 51 | { |
| 52 | 52 | |
| 53 | - private static $_espresso_themes = []; |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme |
|
| 58 | - * |
|
| 59 | - * @return boolean |
|
| 60 | - */ |
|
| 61 | - public static function is_espresso_theme() |
|
| 62 | - { |
|
| 63 | - return wp_get_theme()->get('TextDomain') === 'event_espresso'; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then |
|
| 69 | - * load its functions.php file ( if not already loaded ) |
|
| 70 | - * |
|
| 71 | - * @return void |
|
| 72 | - */ |
|
| 73 | - public static function load_espresso_theme_functions() |
|
| 74 | - { |
|
| 75 | - if (! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
| 76 | - if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) { |
|
| 77 | - require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php'); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory |
|
| 85 | - * |
|
| 86 | - * @return array |
|
| 87 | - */ |
|
| 88 | - public static function get_espresso_themes() |
|
| 89 | - { |
|
| 90 | - if (empty(EEH_Template::$_espresso_themes)) { |
|
| 91 | - $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
| 92 | - if (empty($espresso_themes)) { |
|
| 93 | - return []; |
|
| 94 | - } |
|
| 95 | - if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
|
| 96 | - unset($espresso_themes[ $key ]); |
|
| 97 | - } |
|
| 98 | - EEH_Template::$_espresso_themes = []; |
|
| 99 | - foreach ($espresso_themes as $espresso_theme) { |
|
| 100 | - EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - return EEH_Template::$_espresso_themes; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * EEH_Template::get_template_part |
|
| 109 | - * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, |
|
| 110 | - * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS |
|
| 111 | - * filtering based off of the entire template part name |
|
| 112 | - * |
|
| 113 | - * @param string $slug The slug name for the generic template. |
|
| 114 | - * @param string $name The name of the specialised template. |
|
| 115 | - * @param array $template_args |
|
| 116 | - * @param bool $return_string |
|
| 117 | - * @return string the html output for the formatted money value |
|
| 118 | - */ |
|
| 119 | - public static function get_template_part( |
|
| 120 | - $slug = null, |
|
| 121 | - $name = null, |
|
| 122 | - $template_args = [], |
|
| 123 | - $return_string = false |
|
| 124 | - ) { |
|
| 125 | - do_action("get_template_part_{$slug}-{$name}", $slug, $name); |
|
| 126 | - $templates = []; |
|
| 127 | - $name = (string) $name; |
|
| 128 | - if ($name != '') { |
|
| 129 | - $templates[] = "{$slug}-{$name}.php"; |
|
| 130 | - } |
|
| 131 | - // allow template parts to be turned off via something like: |
|
| 132 | - // add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' ); |
|
| 133 | - if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) { |
|
| 134 | - return EEH_Template::locate_template($templates, $template_args, true, $return_string); |
|
| 135 | - } |
|
| 136 | - return ''; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * locate_template |
|
| 142 | - * locate a template file by looking in the following places, in the following order: |
|
| 143 | - * <server path up to>/wp-content/themes/<current active WordPress theme>/ |
|
| 144 | - * <assumed full absolute server path> |
|
| 145 | - * <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/ |
|
| 146 | - * <server path up to>/wp-content/uploads/espresso/templates/ |
|
| 147 | - * <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/ |
|
| 148 | - * <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/ |
|
| 149 | - * <server path up to>/wp-content/plugins/<EE4 folder>/ |
|
| 150 | - * as soon as the template is found in one of these locations, it will be returned or loaded |
|
| 151 | - * Example: |
|
| 152 | - * You are using the WordPress Twenty Sixteen theme, |
|
| 153 | - * and you want to customize the "some-event.template.php" template, |
|
| 154 | - * which is located in the "/relative/path/to/" folder relative to the main EE plugin folder. |
|
| 155 | - * Assuming WP is installed on your server in the "/home/public_html/" folder, |
|
| 156 | - * EEH_Template::locate_template() will look at the following paths in order until the template is found: |
|
| 157 | - * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
| 158 | - * /relative/path/to/some-event.template.php |
|
| 159 | - * /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 160 | - * /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php |
|
| 161 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 162 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 163 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php |
|
| 164 | - * Had you passed an absolute path to your template that was in some other location, |
|
| 165 | - * ie: "/absolute/path/to/some-event.template.php" |
|
| 166 | - * then the search would have been : |
|
| 167 | - * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
| 168 | - * /absolute/path/to/some-event.template.php |
|
| 169 | - * and stopped there upon finding it in the second location |
|
| 170 | - * |
|
| 171 | - * @param array|string $templates array of template file names including extension (or just a single string) |
|
| 172 | - * @param array $template_args an array of arguments to be extracted for use in the template |
|
| 173 | - * @param boolean $load whether to pass the located template path on to the |
|
| 174 | - * EEH_Template::display_template() method or simply return it |
|
| 175 | - * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
| 176 | - * string |
|
| 177 | - * @param boolean $check_if_custom If TRUE, this flags this method to return boolean for whether this will |
|
| 178 | - * generate a custom template or not. Used in places where you don't actually |
|
| 179 | - * load the template, you just want to know if there's a custom version of it. |
|
| 180 | - * @return mixed |
|
| 181 | - * @throws DomainException |
|
| 182 | - * @throws InvalidArgumentException |
|
| 183 | - * @throws InvalidDataTypeException |
|
| 184 | - * @throws InvalidInterfaceException |
|
| 185 | - */ |
|
| 186 | - public static function locate_template( |
|
| 187 | - $templates = [], |
|
| 188 | - $template_args = [], |
|
| 189 | - $load = true, |
|
| 190 | - $return_string = true, |
|
| 191 | - $check_if_custom = false |
|
| 192 | - ) { |
|
| 193 | - // first use WP locate_template to check for template in the current theme folder |
|
| 194 | - $template_path = locate_template($templates); |
|
| 195 | - |
|
| 196 | - if ($check_if_custom && ! empty($template_path)) { |
|
| 197 | - return true; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // not in the theme |
|
| 201 | - if (empty($template_path)) { |
|
| 202 | - // not even a template to look for ? |
|
| 203 | - if (empty($templates)) { |
|
| 204 | - $loader = LoaderFactory::getLoader(); |
|
| 205 | - /** @var RequestInterface $request */ |
|
| 206 | - $request = $loader->getShared(RequestInterface::class); |
|
| 207 | - // get post_type |
|
| 208 | - $post_type = $request->getRequestParam('post_type'); |
|
| 209 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
| 210 | - $custom_post_types = $loader->getShared( |
|
| 211 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 212 | - ); |
|
| 213 | - // get array of EE Custom Post Types |
|
| 214 | - $EE_CPTs = $custom_post_types->getDefinitions(); |
|
| 215 | - // build template name based on request |
|
| 216 | - if (isset($EE_CPTs[ $post_type ])) { |
|
| 217 | - $archive_or_single = is_archive() ? 'archive' : ''; |
|
| 218 | - $archive_or_single = is_single() ? 'single' : $archive_or_single; |
|
| 219 | - $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - // currently active EE template theme |
|
| 223 | - $current_theme = EE_Config::get_current_theme(); |
|
| 224 | - |
|
| 225 | - // array of paths to folders that may contain templates |
|
| 226 | - $template_folder_paths = [ |
|
| 227 | - // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
|
| 228 | - EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
| 229 | - // then in the root of the /wp-content/uploads/espresso/templates/ folder |
|
| 230 | - EVENT_ESPRESSO_TEMPLATE_DIR, |
|
| 231 | - ]; |
|
| 232 | - |
|
| 233 | - // add core plugin folders for checking only if we're not $check_if_custom |
|
| 234 | - if (! $check_if_custom) { |
|
| 235 | - $core_paths = [ |
|
| 236 | - // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
|
| 237 | - EE_PUBLIC . $current_theme, |
|
| 238 | - // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
|
| 239 | - EE_TEMPLATES . $current_theme, |
|
| 240 | - // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
|
| 241 | - EE_PLUGIN_DIR_PATH, |
|
| 242 | - ]; |
|
| 243 | - $template_folder_paths = array_merge($template_folder_paths, $core_paths); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - // now filter that array |
|
| 247 | - $template_folder_paths = apply_filters( |
|
| 248 | - 'FHEE__EEH_Template__locate_template__template_folder_paths', |
|
| 249 | - $template_folder_paths |
|
| 250 | - ); |
|
| 251 | - $templates = is_array($templates) ? $templates : [$templates]; |
|
| 252 | - $template_folder_paths = |
|
| 253 | - is_array($template_folder_paths) ? $template_folder_paths : [$template_folder_paths]; |
|
| 254 | - // array to hold all possible template paths |
|
| 255 | - $full_template_paths = []; |
|
| 256 | - $file_name = ''; |
|
| 257 | - |
|
| 258 | - // loop through $templates |
|
| 259 | - foreach ($templates as $template) { |
|
| 260 | - // normalize directory separators |
|
| 261 | - $template = EEH_File::standardise_directory_separators($template); |
|
| 262 | - $file_name = basename($template); |
|
| 263 | - $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1)); |
|
| 264 | - // while looping through all template folder paths |
|
| 265 | - foreach ($template_folder_paths as $template_folder_path) { |
|
| 266 | - // normalize directory separators |
|
| 267 | - $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path); |
|
| 268 | - // determine if any common base path exists between the two paths |
|
| 269 | - $common_base_path = EEH_Template::_find_common_base_path( |
|
| 270 | - [$template_folder_path, $template_path_minus_file_name] |
|
| 271 | - ); |
|
| 272 | - if ($common_base_path !== '') { |
|
| 273 | - // both paths have a common base, so just tack the filename onto our search path |
|
| 274 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
| 275 | - } else { |
|
| 276 | - // no common base path, so let's just concatenate |
|
| 277 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
| 278 | - } |
|
| 279 | - // build up our template locations array by adding our resolved paths |
|
| 280 | - $full_template_paths[] = $resolved_path; |
|
| 281 | - } |
|
| 282 | - // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
|
| 283 | - array_unshift($full_template_paths, $template); |
|
| 284 | - // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
|
| 285 | - array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name); |
|
| 286 | - } |
|
| 287 | - // filter final array of full template paths |
|
| 288 | - $full_template_paths = apply_filters( |
|
| 289 | - 'FHEE__EEH_Template__locate_template__full_template_paths', |
|
| 290 | - $full_template_paths, |
|
| 291 | - $file_name |
|
| 292 | - ); |
|
| 293 | - // now loop through our final array of template location paths and check each location |
|
| 294 | - foreach ((array) $full_template_paths as $full_template_path) { |
|
| 295 | - if (is_readable($full_template_path)) { |
|
| 296 | - $template_path = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $full_template_path); |
|
| 297 | - break; |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - // hook that can be used to display the full template path that will be used |
|
| 303 | - do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path); |
|
| 304 | - |
|
| 305 | - // if we got it and you want to see it... |
|
| 306 | - if ($template_path && $load && ! $check_if_custom) { |
|
| 307 | - if ($return_string) { |
|
| 308 | - return EEH_Template::display_template($template_path, $template_args, true); |
|
| 309 | - } |
|
| 310 | - EEH_Template::display_template($template_path, $template_args); |
|
| 311 | - } |
|
| 312 | - return $check_if_custom && ! empty($template_path) ? true : $template_path; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * _find_common_base_path |
|
| 318 | - * given two paths, this determines if there is a common base path between the two |
|
| 319 | - * |
|
| 320 | - * @param array $paths |
|
| 321 | - * @return string |
|
| 322 | - */ |
|
| 323 | - protected static function _find_common_base_path($paths) |
|
| 324 | - { |
|
| 325 | - $last_offset = 0; |
|
| 326 | - $common_base_path = ''; |
|
| 327 | - while (($index = strpos($paths[0], '/', $last_offset)) !== false) { |
|
| 328 | - $dir_length = $index - $last_offset + 1; |
|
| 329 | - $directory = substr($paths[0], $last_offset, $dir_length); |
|
| 330 | - foreach ($paths as $path) { |
|
| 331 | - if (substr($path, $last_offset, $dir_length) != $directory) { |
|
| 332 | - return $common_base_path; |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - $common_base_path .= $directory; |
|
| 336 | - $last_offset = $index + 1; |
|
| 337 | - } |
|
| 338 | - return substr($common_base_path, 0, -1); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * load and display a template |
|
| 344 | - * |
|
| 345 | - * @param bool|string $template_path server path to the file to be loaded, including file name and extension |
|
| 346 | - * @param array $template_args an array of arguments to be extracted for use in the template |
|
| 347 | - * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
| 348 | - * string |
|
| 349 | - * @param bool $throw_exceptions if set to true, will throw an exception if the template is either |
|
| 350 | - * not found or is not readable |
|
| 351 | - * @return string |
|
| 352 | - * @throws DomainException |
|
| 353 | - */ |
|
| 354 | - public static function display_template( |
|
| 355 | - $template_path = false, |
|
| 356 | - $template_args = [], |
|
| 357 | - $return_string = false, |
|
| 358 | - $throw_exceptions = false |
|
| 359 | - ) { |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * These two filters are intended for last minute changes to templates being loaded and/or template arg |
|
| 363 | - * modifications. NOTE... modifying these things can cause breakage as most templates running through |
|
| 364 | - * the display_template method are templates we DON'T want modified (usually because of js |
|
| 365 | - * dependencies etc). So unless you know what you are doing, do NOT filter templates or template args |
|
| 366 | - * using this. |
|
| 367 | - * |
|
| 368 | - * @since 4.6.0 |
|
| 369 | - */ |
|
| 370 | - $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path); |
|
| 371 | - $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
|
| 372 | - |
|
| 373 | - // you gimme nuttin - YOU GET NUTTIN !! |
|
| 374 | - if (! $template_path || ! is_readable($template_path)) { |
|
| 375 | - // ignore whether template is accessible ? |
|
| 376 | - if ($throw_exceptions) { |
|
| 377 | - throw new DomainException( |
|
| 378 | - esc_html__('Invalid, unreadable, or missing file.', 'event_espresso') |
|
| 379 | - ); |
|
| 380 | - } |
|
| 381 | - return ''; |
|
| 382 | - } |
|
| 383 | - // if $template_args are not in an array, then make it so |
|
| 384 | - if (! is_array($template_args) && ! is_object($template_args)) { |
|
| 385 | - $template_args = [$template_args]; |
|
| 386 | - } |
|
| 387 | - extract($template_args, EXTR_SKIP); |
|
| 388 | - |
|
| 389 | - if ($return_string) { |
|
| 390 | - // because we want to return a string, we are going to capture the output |
|
| 391 | - ob_start(); |
|
| 392 | - include($template_path); |
|
| 393 | - return ob_get_clean(); |
|
| 394 | - } |
|
| 395 | - include($template_path); |
|
| 396 | - return ''; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
| 402 | - * |
|
| 403 | - * @param EE_Base_Class $object the EE object the css class is being generated for |
|
| 404 | - * @param string $prefix added to the beginning of the generated class |
|
| 405 | - * @param string $suffix added to the end of the generated class |
|
| 406 | - * @return string |
|
| 407 | - * @throws EE_Error |
|
| 408 | - * @throws ReflectionException |
|
| 409 | - */ |
|
| 410 | - public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
| 411 | - { |
|
| 412 | - // in the beginning... |
|
| 413 | - $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
| 414 | - // da muddle |
|
| 415 | - $class = ''; |
|
| 416 | - // the end |
|
| 417 | - $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
| 418 | - // is the passed object an EE object ? |
|
| 419 | - if ($object instanceof EE_Base_Class) { |
|
| 420 | - // grab the exact type of object |
|
| 421 | - $obj_class = get_class($object); |
|
| 422 | - // depending on the type of object... |
|
| 423 | - switch ($obj_class) { |
|
| 424 | - // no specifics just yet... |
|
| 425 | - default: |
|
| 426 | - $class = strtolower(str_replace('_', '-', $obj_class)); |
|
| 427 | - $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - return $prefix . $class . $suffix; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * EEH_Template::format_currency |
|
| 436 | - * This helper takes a raw float value and formats it according to the default config country currency settings, or |
|
| 437 | - * the country currency settings from the supplied country ISO code |
|
| 438 | - * |
|
| 439 | - * @param float $amount raw money value |
|
| 440 | - * @param boolean $return_raw whether to return the formatted float value only with no currency sign or code |
|
| 441 | - * @param boolean $display_code whether to display the country code (USD). Default = TRUE |
|
| 442 | - * @param string $CNT_ISO 2 letter ISO code for a country |
|
| 443 | - * @param string $cur_code_span_class |
|
| 444 | - * @return string the html output for the formatted money value |
|
| 445 | - */ |
|
| 446 | - public static function format_currency( |
|
| 447 | - $amount = null, |
|
| 448 | - $return_raw = false, |
|
| 449 | - $display_code = true, |
|
| 450 | - $CNT_ISO = '', |
|
| 451 | - $cur_code_span_class = 'currency-code' |
|
| 452 | - ) { |
|
| 453 | - // ensure amount was received |
|
| 454 | - if ($amount === null) { |
|
| 455 | - $msg = esc_html__('In order to format currency, an amount needs to be passed.', 'event_espresso'); |
|
| 456 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 457 | - return ''; |
|
| 458 | - } |
|
| 459 | - // ensure amount is float |
|
| 460 | - $amount = (float) apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount); |
|
| 461 | - $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
|
| 462 | - // filter raw amount (allows 0.00 to be changed to "free" for example) |
|
| 463 | - $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
|
| 464 | - // still a number, or was amount converted to a string like "free" ? |
|
| 465 | - if (! is_float($amount_formatted)) { |
|
| 466 | - return esc_html($amount_formatted); |
|
| 467 | - } |
|
| 468 | - try { |
|
| 469 | - // was a country ISO code passed ? if so generate currency config object for that country |
|
| 470 | - $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
| 471 | - } catch (Exception $e) { |
|
| 472 | - // eat exception |
|
| 473 | - $mny = null; |
|
| 474 | - } |
|
| 475 | - // verify results |
|
| 476 | - if (! $mny instanceof EE_Currency_Config) { |
|
| 477 | - // set default config country currency settings |
|
| 478 | - $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
| 479 | - ? EE_Registry::instance()->CFG->currency |
|
| 480 | - : new EE_Currency_Config(); |
|
| 481 | - } |
|
| 482 | - // format float |
|
| 483 | - $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
|
| 484 | - // add formatting ? |
|
| 485 | - if (! $return_raw) { |
|
| 486 | - // add currency sign |
|
| 487 | - if ($mny->sign_b4) { |
|
| 488 | - if ($amount >= 0) { |
|
| 489 | - $amount_formatted = $mny->sign . $amount_formatted; |
|
| 490 | - } else { |
|
| 491 | - $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
| 492 | - } |
|
| 493 | - } else { |
|
| 494 | - $amount_formatted = $amount_formatted . $mny->sign; |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - // filter to allow global setting of display_code |
|
| 498 | - $display_code = (bool) apply_filters( |
|
| 499 | - 'FHEE__EEH_Template__format_currency__display_code', |
|
| 500 | - $display_code |
|
| 501 | - ); |
|
| 502 | - |
|
| 503 | - // add currency code ? |
|
| 504 | - $amount_formatted = $display_code |
|
| 505 | - ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' |
|
| 506 | - : $amount_formatted; |
|
| 507 | - } |
|
| 508 | - // filter results |
|
| 509 | - $amount_formatted = apply_filters( |
|
| 510 | - 'FHEE__EEH_Template__format_currency__amount_formatted', |
|
| 511 | - $amount_formatted, |
|
| 512 | - $mny, |
|
| 513 | - $return_raw |
|
| 514 | - ); |
|
| 515 | - // clean up vars |
|
| 516 | - unset($mny); |
|
| 517 | - // return formatted currency amount |
|
| 518 | - return $amount_formatted; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * This function is used for outputting the localized label for a given status id in the schema requested (and |
|
| 524 | - * possibly plural). The intended use of this function is only for cases where wanting a label outside of a |
|
| 525 | - * related status model or model object (i.e. in documentation etc.) |
|
| 526 | - * |
|
| 527 | - * @param string $status_id Status ID matching a registered status in the esp_status table. If there is no |
|
| 528 | - * match, then 'Unknown' will be returned. |
|
| 529 | - * @param boolean $plural Whether to return plural or not |
|
| 530 | - * @param string $schema 'UPPER', 'lower', or 'Sentence' |
|
| 531 | - * @return string The localized label for the status id. |
|
| 532 | - * @throws EE_Error |
|
| 533 | - */ |
|
| 534 | - public static function pretty_status($status_id, $plural = false, $schema = 'upper') |
|
| 535 | - { |
|
| 536 | - $status = EEM_Status::instance()->localized_status( |
|
| 537 | - [$status_id => esc_html__('unknown', 'event_espresso')], |
|
| 538 | - $plural, |
|
| 539 | - $schema |
|
| 540 | - ); |
|
| 541 | - return $status[ $status_id ]; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * This helper just returns a button or link for the given parameters |
|
| 547 | - * |
|
| 548 | - * @param string $url the url for the link, note that `esc_url` will be called on it |
|
| 549 | - * @param string $label What is the label you want displayed for the button |
|
| 550 | - * @param string $class what class is used for the button (defaults to 'button--primary') |
|
| 551 | - * @param string $icon |
|
| 552 | - * @param string $title |
|
| 553 | - * @return string the html output for the button |
|
| 554 | - */ |
|
| 555 | - public static function get_button_or_link($url, $label, $class = 'button--primary', $icon = '', $title = '') |
|
| 556 | - { |
|
| 557 | - $icon_html = ''; |
|
| 558 | - if (! empty($icon)) { |
|
| 559 | - $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
|
| 560 | - $dashicons = array_filter($dashicons); |
|
| 561 | - $count = count($dashicons); |
|
| 562 | - $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
|
| 563 | - foreach ($dashicons as $dashicon) { |
|
| 564 | - $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
| 565 | - $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
| 566 | - } |
|
| 567 | - $icon_html .= $count > 1 ? '</span>' : ''; |
|
| 568 | - } |
|
| 569 | - // sanitize & escape |
|
| 570 | - $id = sanitize_title_with_dashes($label); |
|
| 571 | - $url = esc_url_raw($url); |
|
| 572 | - $class = esc_attr($class); |
|
| 573 | - $title = esc_attr($title); |
|
| 574 | - $label = esc_html($label); |
|
| 575 | - return "<a id='{$id}' href='{$url}' class='{$class}' title='{$title}'>{$icon_html}{$label}</a>"; |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * This returns a generated link that will load the related help tab on admin pages. |
|
| 581 | - * |
|
| 582 | - * @param string $help_tab_id the id for the connected help tab |
|
| 583 | - * @param bool|string $page The page identifier for the page the help tab is on |
|
| 584 | - * @param bool|string $action The action (route) for the admin page the help tab is on. |
|
| 585 | - * @param bool|string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 586 | - * @param bool|string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 587 | - * @return string generated link |
|
| 588 | - */ |
|
| 589 | - public static function get_help_tab_link( |
|
| 590 | - $help_tab_id, |
|
| 591 | - $page = false, |
|
| 592 | - $action = false, |
|
| 593 | - $icon_style = false, |
|
| 594 | - $help_text = false |
|
| 595 | - ) { |
|
| 596 | - global $allowedtags; |
|
| 597 | - /** @var RequestInterface $request */ |
|
| 598 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 599 | - $page = $page ?: $request->getRequestParam('page', '', 'key'); |
|
| 600 | - $action = $action ?: $request->getRequestParam('action', 'default', 'key'); |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
| 604 | - $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
|
| 605 | - $help_text = ! $help_text ? '' : $help_text; |
|
| 606 | - return '<a id="' |
|
| 607 | - . esc_attr($help_tab_lnk) |
|
| 608 | - . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' |
|
| 609 | - . esc_attr($icon) |
|
| 610 | - . '" title="' |
|
| 611 | - . esc_attr__( |
|
| 612 | - 'Click to open the \'Help\' tab for more information about this feature.', |
|
| 613 | - 'event_espresso' |
|
| 614 | - ) |
|
| 615 | - . '" > ' |
|
| 616 | - . wp_kses($help_text, $allowedtags) |
|
| 617 | - . ' </a>'; |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * This helper generates the html structure for the jquery joyride plugin with the given params. |
|
| 623 | - * |
|
| 624 | - * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 625 | - * @see EE_Admin_Page->_stop_callback() for the construct expected for the $stops param. |
|
| 626 | - * @param EE_Help_Tour |
|
| 627 | - * @return string html |
|
| 628 | - * @throws EE_Error |
|
| 629 | - */ |
|
| 630 | - public static function help_tour_stops_generator(EE_Help_Tour $tour) |
|
| 631 | - { |
|
| 632 | - global $allowedtags; |
|
| 633 | - $id = $tour->get_slug(); |
|
| 634 | - $stops = $tour->get_stops(); |
|
| 635 | - |
|
| 636 | - $content = '<ol style="display:none" id="' . esc_attr($id) . '">'; |
|
| 637 | - |
|
| 638 | - foreach ($stops as $stop) { |
|
| 639 | - $data_id = ! empty($stop['id']) |
|
| 640 | - ? ' data-id="' . esc_attr($stop['id']) . '"' |
|
| 641 | - : ''; |
|
| 642 | - |
|
| 643 | - $data_class = empty($data_id) && ! empty($stop['class']) |
|
| 644 | - ? ' data-class="' . esc_attr($stop['class']) . '"' |
|
| 645 | - : ''; |
|
| 646 | - |
|
| 647 | - // if container is set to modal then let's make sure we set the options accordingly |
|
| 648 | - if (empty($data_id) && empty($data_class)) { |
|
| 649 | - $stop['options']['modal'] = true; |
|
| 650 | - $stop['options']['expose'] = true; |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - $custom_class = ! empty($stop['custom_class']) |
|
| 654 | - ? ' class="' . esc_attr($stop['custom_class']) . '"' |
|
| 655 | - : ''; |
|
| 656 | - $button_text = ! empty($stop['button_text']) |
|
| 657 | - ? ' data-button="' . esc_html($stop['button_text']) . '"' |
|
| 658 | - : ''; |
|
| 659 | - $inner_content = isset($stop['content']) ? wp_kses($stop['content'], $allowedtags) : ''; |
|
| 660 | - |
|
| 661 | - // options |
|
| 662 | - if (isset($stop['options']) && is_array($stop['options'])) { |
|
| 663 | - $options = ' data-options="'; |
|
| 664 | - foreach ($stop['options'] as $option => $value) { |
|
| 665 | - $options .= esc_attr($option) . ':' . esc_attr($value) . ';'; |
|
| 666 | - } |
|
| 667 | - $options .= '"'; |
|
| 668 | - } else { |
|
| 669 | - $options = ''; |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - // let's put all together |
|
| 673 | - $content .= '<li' |
|
| 674 | - . $data_id |
|
| 675 | - . $data_class |
|
| 676 | - . $custom_class |
|
| 677 | - . $button_text |
|
| 678 | - . $options |
|
| 679 | - . '>' |
|
| 680 | - . $inner_content |
|
| 681 | - . '</li>'; |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - $content .= '</ol>'; |
|
| 685 | - return $content; |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - |
|
| 689 | - /** |
|
| 690 | - * This is a helper method to generate a status legend for a given status array. |
|
| 691 | - * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods |
|
| 692 | - * status_array. |
|
| 693 | - * |
|
| 694 | - * @param array $status_array array of statuses that will make up the legend. In format: |
|
| 695 | - * array( |
|
| 696 | - * 'status_item' => 'status_name' |
|
| 697 | - * ) |
|
| 698 | - * @param string $active_status This is used to indicate what the active status is IF that is to be highlighted in |
|
| 699 | - * the legend. |
|
| 700 | - * @return string html structure for status. |
|
| 701 | - * @throws EE_Error |
|
| 702 | - */ |
|
| 703 | - public static function status_legend($status_array, $active_status = '') |
|
| 704 | - { |
|
| 705 | - if (! is_array($status_array)) { |
|
| 706 | - throw new EE_Error( |
|
| 707 | - esc_html__( |
|
| 708 | - 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
|
| 709 | - 'event_espresso' |
|
| 710 | - ) |
|
| 711 | - ); |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - $content = ' |
|
| 53 | + private static $_espresso_themes = []; |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme |
|
| 58 | + * |
|
| 59 | + * @return boolean |
|
| 60 | + */ |
|
| 61 | + public static function is_espresso_theme() |
|
| 62 | + { |
|
| 63 | + return wp_get_theme()->get('TextDomain') === 'event_espresso'; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then |
|
| 69 | + * load its functions.php file ( if not already loaded ) |
|
| 70 | + * |
|
| 71 | + * @return void |
|
| 72 | + */ |
|
| 73 | + public static function load_espresso_theme_functions() |
|
| 74 | + { |
|
| 75 | + if (! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
| 76 | + if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) { |
|
| 77 | + require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php'); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory |
|
| 85 | + * |
|
| 86 | + * @return array |
|
| 87 | + */ |
|
| 88 | + public static function get_espresso_themes() |
|
| 89 | + { |
|
| 90 | + if (empty(EEH_Template::$_espresso_themes)) { |
|
| 91 | + $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
| 92 | + if (empty($espresso_themes)) { |
|
| 93 | + return []; |
|
| 94 | + } |
|
| 95 | + if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
|
| 96 | + unset($espresso_themes[ $key ]); |
|
| 97 | + } |
|
| 98 | + EEH_Template::$_espresso_themes = []; |
|
| 99 | + foreach ($espresso_themes as $espresso_theme) { |
|
| 100 | + EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + return EEH_Template::$_espresso_themes; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * EEH_Template::get_template_part |
|
| 109 | + * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, |
|
| 110 | + * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS |
|
| 111 | + * filtering based off of the entire template part name |
|
| 112 | + * |
|
| 113 | + * @param string $slug The slug name for the generic template. |
|
| 114 | + * @param string $name The name of the specialised template. |
|
| 115 | + * @param array $template_args |
|
| 116 | + * @param bool $return_string |
|
| 117 | + * @return string the html output for the formatted money value |
|
| 118 | + */ |
|
| 119 | + public static function get_template_part( |
|
| 120 | + $slug = null, |
|
| 121 | + $name = null, |
|
| 122 | + $template_args = [], |
|
| 123 | + $return_string = false |
|
| 124 | + ) { |
|
| 125 | + do_action("get_template_part_{$slug}-{$name}", $slug, $name); |
|
| 126 | + $templates = []; |
|
| 127 | + $name = (string) $name; |
|
| 128 | + if ($name != '') { |
|
| 129 | + $templates[] = "{$slug}-{$name}.php"; |
|
| 130 | + } |
|
| 131 | + // allow template parts to be turned off via something like: |
|
| 132 | + // add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' ); |
|
| 133 | + if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) { |
|
| 134 | + return EEH_Template::locate_template($templates, $template_args, true, $return_string); |
|
| 135 | + } |
|
| 136 | + return ''; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * locate_template |
|
| 142 | + * locate a template file by looking in the following places, in the following order: |
|
| 143 | + * <server path up to>/wp-content/themes/<current active WordPress theme>/ |
|
| 144 | + * <assumed full absolute server path> |
|
| 145 | + * <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/ |
|
| 146 | + * <server path up to>/wp-content/uploads/espresso/templates/ |
|
| 147 | + * <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/ |
|
| 148 | + * <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/ |
|
| 149 | + * <server path up to>/wp-content/plugins/<EE4 folder>/ |
|
| 150 | + * as soon as the template is found in one of these locations, it will be returned or loaded |
|
| 151 | + * Example: |
|
| 152 | + * You are using the WordPress Twenty Sixteen theme, |
|
| 153 | + * and you want to customize the "some-event.template.php" template, |
|
| 154 | + * which is located in the "/relative/path/to/" folder relative to the main EE plugin folder. |
|
| 155 | + * Assuming WP is installed on your server in the "/home/public_html/" folder, |
|
| 156 | + * EEH_Template::locate_template() will look at the following paths in order until the template is found: |
|
| 157 | + * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
| 158 | + * /relative/path/to/some-event.template.php |
|
| 159 | + * /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 160 | + * /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php |
|
| 161 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 162 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 163 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php |
|
| 164 | + * Had you passed an absolute path to your template that was in some other location, |
|
| 165 | + * ie: "/absolute/path/to/some-event.template.php" |
|
| 166 | + * then the search would have been : |
|
| 167 | + * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
| 168 | + * /absolute/path/to/some-event.template.php |
|
| 169 | + * and stopped there upon finding it in the second location |
|
| 170 | + * |
|
| 171 | + * @param array|string $templates array of template file names including extension (or just a single string) |
|
| 172 | + * @param array $template_args an array of arguments to be extracted for use in the template |
|
| 173 | + * @param boolean $load whether to pass the located template path on to the |
|
| 174 | + * EEH_Template::display_template() method or simply return it |
|
| 175 | + * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
| 176 | + * string |
|
| 177 | + * @param boolean $check_if_custom If TRUE, this flags this method to return boolean for whether this will |
|
| 178 | + * generate a custom template or not. Used in places where you don't actually |
|
| 179 | + * load the template, you just want to know if there's a custom version of it. |
|
| 180 | + * @return mixed |
|
| 181 | + * @throws DomainException |
|
| 182 | + * @throws InvalidArgumentException |
|
| 183 | + * @throws InvalidDataTypeException |
|
| 184 | + * @throws InvalidInterfaceException |
|
| 185 | + */ |
|
| 186 | + public static function locate_template( |
|
| 187 | + $templates = [], |
|
| 188 | + $template_args = [], |
|
| 189 | + $load = true, |
|
| 190 | + $return_string = true, |
|
| 191 | + $check_if_custom = false |
|
| 192 | + ) { |
|
| 193 | + // first use WP locate_template to check for template in the current theme folder |
|
| 194 | + $template_path = locate_template($templates); |
|
| 195 | + |
|
| 196 | + if ($check_if_custom && ! empty($template_path)) { |
|
| 197 | + return true; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // not in the theme |
|
| 201 | + if (empty($template_path)) { |
|
| 202 | + // not even a template to look for ? |
|
| 203 | + if (empty($templates)) { |
|
| 204 | + $loader = LoaderFactory::getLoader(); |
|
| 205 | + /** @var RequestInterface $request */ |
|
| 206 | + $request = $loader->getShared(RequestInterface::class); |
|
| 207 | + // get post_type |
|
| 208 | + $post_type = $request->getRequestParam('post_type'); |
|
| 209 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
| 210 | + $custom_post_types = $loader->getShared( |
|
| 211 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 212 | + ); |
|
| 213 | + // get array of EE Custom Post Types |
|
| 214 | + $EE_CPTs = $custom_post_types->getDefinitions(); |
|
| 215 | + // build template name based on request |
|
| 216 | + if (isset($EE_CPTs[ $post_type ])) { |
|
| 217 | + $archive_or_single = is_archive() ? 'archive' : ''; |
|
| 218 | + $archive_or_single = is_single() ? 'single' : $archive_or_single; |
|
| 219 | + $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + // currently active EE template theme |
|
| 223 | + $current_theme = EE_Config::get_current_theme(); |
|
| 224 | + |
|
| 225 | + // array of paths to folders that may contain templates |
|
| 226 | + $template_folder_paths = [ |
|
| 227 | + // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
|
| 228 | + EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
| 229 | + // then in the root of the /wp-content/uploads/espresso/templates/ folder |
|
| 230 | + EVENT_ESPRESSO_TEMPLATE_DIR, |
|
| 231 | + ]; |
|
| 232 | + |
|
| 233 | + // add core plugin folders for checking only if we're not $check_if_custom |
|
| 234 | + if (! $check_if_custom) { |
|
| 235 | + $core_paths = [ |
|
| 236 | + // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
|
| 237 | + EE_PUBLIC . $current_theme, |
|
| 238 | + // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
|
| 239 | + EE_TEMPLATES . $current_theme, |
|
| 240 | + // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
|
| 241 | + EE_PLUGIN_DIR_PATH, |
|
| 242 | + ]; |
|
| 243 | + $template_folder_paths = array_merge($template_folder_paths, $core_paths); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + // now filter that array |
|
| 247 | + $template_folder_paths = apply_filters( |
|
| 248 | + 'FHEE__EEH_Template__locate_template__template_folder_paths', |
|
| 249 | + $template_folder_paths |
|
| 250 | + ); |
|
| 251 | + $templates = is_array($templates) ? $templates : [$templates]; |
|
| 252 | + $template_folder_paths = |
|
| 253 | + is_array($template_folder_paths) ? $template_folder_paths : [$template_folder_paths]; |
|
| 254 | + // array to hold all possible template paths |
|
| 255 | + $full_template_paths = []; |
|
| 256 | + $file_name = ''; |
|
| 257 | + |
|
| 258 | + // loop through $templates |
|
| 259 | + foreach ($templates as $template) { |
|
| 260 | + // normalize directory separators |
|
| 261 | + $template = EEH_File::standardise_directory_separators($template); |
|
| 262 | + $file_name = basename($template); |
|
| 263 | + $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1)); |
|
| 264 | + // while looping through all template folder paths |
|
| 265 | + foreach ($template_folder_paths as $template_folder_path) { |
|
| 266 | + // normalize directory separators |
|
| 267 | + $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path); |
|
| 268 | + // determine if any common base path exists between the two paths |
|
| 269 | + $common_base_path = EEH_Template::_find_common_base_path( |
|
| 270 | + [$template_folder_path, $template_path_minus_file_name] |
|
| 271 | + ); |
|
| 272 | + if ($common_base_path !== '') { |
|
| 273 | + // both paths have a common base, so just tack the filename onto our search path |
|
| 274 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
| 275 | + } else { |
|
| 276 | + // no common base path, so let's just concatenate |
|
| 277 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
| 278 | + } |
|
| 279 | + // build up our template locations array by adding our resolved paths |
|
| 280 | + $full_template_paths[] = $resolved_path; |
|
| 281 | + } |
|
| 282 | + // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
|
| 283 | + array_unshift($full_template_paths, $template); |
|
| 284 | + // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
|
| 285 | + array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name); |
|
| 286 | + } |
|
| 287 | + // filter final array of full template paths |
|
| 288 | + $full_template_paths = apply_filters( |
|
| 289 | + 'FHEE__EEH_Template__locate_template__full_template_paths', |
|
| 290 | + $full_template_paths, |
|
| 291 | + $file_name |
|
| 292 | + ); |
|
| 293 | + // now loop through our final array of template location paths and check each location |
|
| 294 | + foreach ((array) $full_template_paths as $full_template_path) { |
|
| 295 | + if (is_readable($full_template_path)) { |
|
| 296 | + $template_path = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $full_template_path); |
|
| 297 | + break; |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + // hook that can be used to display the full template path that will be used |
|
| 303 | + do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path); |
|
| 304 | + |
|
| 305 | + // if we got it and you want to see it... |
|
| 306 | + if ($template_path && $load && ! $check_if_custom) { |
|
| 307 | + if ($return_string) { |
|
| 308 | + return EEH_Template::display_template($template_path, $template_args, true); |
|
| 309 | + } |
|
| 310 | + EEH_Template::display_template($template_path, $template_args); |
|
| 311 | + } |
|
| 312 | + return $check_if_custom && ! empty($template_path) ? true : $template_path; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * _find_common_base_path |
|
| 318 | + * given two paths, this determines if there is a common base path between the two |
|
| 319 | + * |
|
| 320 | + * @param array $paths |
|
| 321 | + * @return string |
|
| 322 | + */ |
|
| 323 | + protected static function _find_common_base_path($paths) |
|
| 324 | + { |
|
| 325 | + $last_offset = 0; |
|
| 326 | + $common_base_path = ''; |
|
| 327 | + while (($index = strpos($paths[0], '/', $last_offset)) !== false) { |
|
| 328 | + $dir_length = $index - $last_offset + 1; |
|
| 329 | + $directory = substr($paths[0], $last_offset, $dir_length); |
|
| 330 | + foreach ($paths as $path) { |
|
| 331 | + if (substr($path, $last_offset, $dir_length) != $directory) { |
|
| 332 | + return $common_base_path; |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + $common_base_path .= $directory; |
|
| 336 | + $last_offset = $index + 1; |
|
| 337 | + } |
|
| 338 | + return substr($common_base_path, 0, -1); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * load and display a template |
|
| 344 | + * |
|
| 345 | + * @param bool|string $template_path server path to the file to be loaded, including file name and extension |
|
| 346 | + * @param array $template_args an array of arguments to be extracted for use in the template |
|
| 347 | + * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
| 348 | + * string |
|
| 349 | + * @param bool $throw_exceptions if set to true, will throw an exception if the template is either |
|
| 350 | + * not found or is not readable |
|
| 351 | + * @return string |
|
| 352 | + * @throws DomainException |
|
| 353 | + */ |
|
| 354 | + public static function display_template( |
|
| 355 | + $template_path = false, |
|
| 356 | + $template_args = [], |
|
| 357 | + $return_string = false, |
|
| 358 | + $throw_exceptions = false |
|
| 359 | + ) { |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * These two filters are intended for last minute changes to templates being loaded and/or template arg |
|
| 363 | + * modifications. NOTE... modifying these things can cause breakage as most templates running through |
|
| 364 | + * the display_template method are templates we DON'T want modified (usually because of js |
|
| 365 | + * dependencies etc). So unless you know what you are doing, do NOT filter templates or template args |
|
| 366 | + * using this. |
|
| 367 | + * |
|
| 368 | + * @since 4.6.0 |
|
| 369 | + */ |
|
| 370 | + $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path); |
|
| 371 | + $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
|
| 372 | + |
|
| 373 | + // you gimme nuttin - YOU GET NUTTIN !! |
|
| 374 | + if (! $template_path || ! is_readable($template_path)) { |
|
| 375 | + // ignore whether template is accessible ? |
|
| 376 | + if ($throw_exceptions) { |
|
| 377 | + throw new DomainException( |
|
| 378 | + esc_html__('Invalid, unreadable, or missing file.', 'event_espresso') |
|
| 379 | + ); |
|
| 380 | + } |
|
| 381 | + return ''; |
|
| 382 | + } |
|
| 383 | + // if $template_args are not in an array, then make it so |
|
| 384 | + if (! is_array($template_args) && ! is_object($template_args)) { |
|
| 385 | + $template_args = [$template_args]; |
|
| 386 | + } |
|
| 387 | + extract($template_args, EXTR_SKIP); |
|
| 388 | + |
|
| 389 | + if ($return_string) { |
|
| 390 | + // because we want to return a string, we are going to capture the output |
|
| 391 | + ob_start(); |
|
| 392 | + include($template_path); |
|
| 393 | + return ob_get_clean(); |
|
| 394 | + } |
|
| 395 | + include($template_path); |
|
| 396 | + return ''; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
| 402 | + * |
|
| 403 | + * @param EE_Base_Class $object the EE object the css class is being generated for |
|
| 404 | + * @param string $prefix added to the beginning of the generated class |
|
| 405 | + * @param string $suffix added to the end of the generated class |
|
| 406 | + * @return string |
|
| 407 | + * @throws EE_Error |
|
| 408 | + * @throws ReflectionException |
|
| 409 | + */ |
|
| 410 | + public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
| 411 | + { |
|
| 412 | + // in the beginning... |
|
| 413 | + $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
| 414 | + // da muddle |
|
| 415 | + $class = ''; |
|
| 416 | + // the end |
|
| 417 | + $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
| 418 | + // is the passed object an EE object ? |
|
| 419 | + if ($object instanceof EE_Base_Class) { |
|
| 420 | + // grab the exact type of object |
|
| 421 | + $obj_class = get_class($object); |
|
| 422 | + // depending on the type of object... |
|
| 423 | + switch ($obj_class) { |
|
| 424 | + // no specifics just yet... |
|
| 425 | + default: |
|
| 426 | + $class = strtolower(str_replace('_', '-', $obj_class)); |
|
| 427 | + $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + return $prefix . $class . $suffix; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * EEH_Template::format_currency |
|
| 436 | + * This helper takes a raw float value and formats it according to the default config country currency settings, or |
|
| 437 | + * the country currency settings from the supplied country ISO code |
|
| 438 | + * |
|
| 439 | + * @param float $amount raw money value |
|
| 440 | + * @param boolean $return_raw whether to return the formatted float value only with no currency sign or code |
|
| 441 | + * @param boolean $display_code whether to display the country code (USD). Default = TRUE |
|
| 442 | + * @param string $CNT_ISO 2 letter ISO code for a country |
|
| 443 | + * @param string $cur_code_span_class |
|
| 444 | + * @return string the html output for the formatted money value |
|
| 445 | + */ |
|
| 446 | + public static function format_currency( |
|
| 447 | + $amount = null, |
|
| 448 | + $return_raw = false, |
|
| 449 | + $display_code = true, |
|
| 450 | + $CNT_ISO = '', |
|
| 451 | + $cur_code_span_class = 'currency-code' |
|
| 452 | + ) { |
|
| 453 | + // ensure amount was received |
|
| 454 | + if ($amount === null) { |
|
| 455 | + $msg = esc_html__('In order to format currency, an amount needs to be passed.', 'event_espresso'); |
|
| 456 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 457 | + return ''; |
|
| 458 | + } |
|
| 459 | + // ensure amount is float |
|
| 460 | + $amount = (float) apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount); |
|
| 461 | + $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
|
| 462 | + // filter raw amount (allows 0.00 to be changed to "free" for example) |
|
| 463 | + $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
|
| 464 | + // still a number, or was amount converted to a string like "free" ? |
|
| 465 | + if (! is_float($amount_formatted)) { |
|
| 466 | + return esc_html($amount_formatted); |
|
| 467 | + } |
|
| 468 | + try { |
|
| 469 | + // was a country ISO code passed ? if so generate currency config object for that country |
|
| 470 | + $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
| 471 | + } catch (Exception $e) { |
|
| 472 | + // eat exception |
|
| 473 | + $mny = null; |
|
| 474 | + } |
|
| 475 | + // verify results |
|
| 476 | + if (! $mny instanceof EE_Currency_Config) { |
|
| 477 | + // set default config country currency settings |
|
| 478 | + $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
| 479 | + ? EE_Registry::instance()->CFG->currency |
|
| 480 | + : new EE_Currency_Config(); |
|
| 481 | + } |
|
| 482 | + // format float |
|
| 483 | + $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
|
| 484 | + // add formatting ? |
|
| 485 | + if (! $return_raw) { |
|
| 486 | + // add currency sign |
|
| 487 | + if ($mny->sign_b4) { |
|
| 488 | + if ($amount >= 0) { |
|
| 489 | + $amount_formatted = $mny->sign . $amount_formatted; |
|
| 490 | + } else { |
|
| 491 | + $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
| 492 | + } |
|
| 493 | + } else { |
|
| 494 | + $amount_formatted = $amount_formatted . $mny->sign; |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + // filter to allow global setting of display_code |
|
| 498 | + $display_code = (bool) apply_filters( |
|
| 499 | + 'FHEE__EEH_Template__format_currency__display_code', |
|
| 500 | + $display_code |
|
| 501 | + ); |
|
| 502 | + |
|
| 503 | + // add currency code ? |
|
| 504 | + $amount_formatted = $display_code |
|
| 505 | + ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' |
|
| 506 | + : $amount_formatted; |
|
| 507 | + } |
|
| 508 | + // filter results |
|
| 509 | + $amount_formatted = apply_filters( |
|
| 510 | + 'FHEE__EEH_Template__format_currency__amount_formatted', |
|
| 511 | + $amount_formatted, |
|
| 512 | + $mny, |
|
| 513 | + $return_raw |
|
| 514 | + ); |
|
| 515 | + // clean up vars |
|
| 516 | + unset($mny); |
|
| 517 | + // return formatted currency amount |
|
| 518 | + return $amount_formatted; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * This function is used for outputting the localized label for a given status id in the schema requested (and |
|
| 524 | + * possibly plural). The intended use of this function is only for cases where wanting a label outside of a |
|
| 525 | + * related status model or model object (i.e. in documentation etc.) |
|
| 526 | + * |
|
| 527 | + * @param string $status_id Status ID matching a registered status in the esp_status table. If there is no |
|
| 528 | + * match, then 'Unknown' will be returned. |
|
| 529 | + * @param boolean $plural Whether to return plural or not |
|
| 530 | + * @param string $schema 'UPPER', 'lower', or 'Sentence' |
|
| 531 | + * @return string The localized label for the status id. |
|
| 532 | + * @throws EE_Error |
|
| 533 | + */ |
|
| 534 | + public static function pretty_status($status_id, $plural = false, $schema = 'upper') |
|
| 535 | + { |
|
| 536 | + $status = EEM_Status::instance()->localized_status( |
|
| 537 | + [$status_id => esc_html__('unknown', 'event_espresso')], |
|
| 538 | + $plural, |
|
| 539 | + $schema |
|
| 540 | + ); |
|
| 541 | + return $status[ $status_id ]; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * This helper just returns a button or link for the given parameters |
|
| 547 | + * |
|
| 548 | + * @param string $url the url for the link, note that `esc_url` will be called on it |
|
| 549 | + * @param string $label What is the label you want displayed for the button |
|
| 550 | + * @param string $class what class is used for the button (defaults to 'button--primary') |
|
| 551 | + * @param string $icon |
|
| 552 | + * @param string $title |
|
| 553 | + * @return string the html output for the button |
|
| 554 | + */ |
|
| 555 | + public static function get_button_or_link($url, $label, $class = 'button--primary', $icon = '', $title = '') |
|
| 556 | + { |
|
| 557 | + $icon_html = ''; |
|
| 558 | + if (! empty($icon)) { |
|
| 559 | + $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
|
| 560 | + $dashicons = array_filter($dashicons); |
|
| 561 | + $count = count($dashicons); |
|
| 562 | + $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
|
| 563 | + foreach ($dashicons as $dashicon) { |
|
| 564 | + $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
| 565 | + $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
| 566 | + } |
|
| 567 | + $icon_html .= $count > 1 ? '</span>' : ''; |
|
| 568 | + } |
|
| 569 | + // sanitize & escape |
|
| 570 | + $id = sanitize_title_with_dashes($label); |
|
| 571 | + $url = esc_url_raw($url); |
|
| 572 | + $class = esc_attr($class); |
|
| 573 | + $title = esc_attr($title); |
|
| 574 | + $label = esc_html($label); |
|
| 575 | + return "<a id='{$id}' href='{$url}' class='{$class}' title='{$title}'>{$icon_html}{$label}</a>"; |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * This returns a generated link that will load the related help tab on admin pages. |
|
| 581 | + * |
|
| 582 | + * @param string $help_tab_id the id for the connected help tab |
|
| 583 | + * @param bool|string $page The page identifier for the page the help tab is on |
|
| 584 | + * @param bool|string $action The action (route) for the admin page the help tab is on. |
|
| 585 | + * @param bool|string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 586 | + * @param bool|string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 587 | + * @return string generated link |
|
| 588 | + */ |
|
| 589 | + public static function get_help_tab_link( |
|
| 590 | + $help_tab_id, |
|
| 591 | + $page = false, |
|
| 592 | + $action = false, |
|
| 593 | + $icon_style = false, |
|
| 594 | + $help_text = false |
|
| 595 | + ) { |
|
| 596 | + global $allowedtags; |
|
| 597 | + /** @var RequestInterface $request */ |
|
| 598 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 599 | + $page = $page ?: $request->getRequestParam('page', '', 'key'); |
|
| 600 | + $action = $action ?: $request->getRequestParam('action', 'default', 'key'); |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
| 604 | + $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
|
| 605 | + $help_text = ! $help_text ? '' : $help_text; |
|
| 606 | + return '<a id="' |
|
| 607 | + . esc_attr($help_tab_lnk) |
|
| 608 | + . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' |
|
| 609 | + . esc_attr($icon) |
|
| 610 | + . '" title="' |
|
| 611 | + . esc_attr__( |
|
| 612 | + 'Click to open the \'Help\' tab for more information about this feature.', |
|
| 613 | + 'event_espresso' |
|
| 614 | + ) |
|
| 615 | + . '" > ' |
|
| 616 | + . wp_kses($help_text, $allowedtags) |
|
| 617 | + . ' </a>'; |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * This helper generates the html structure for the jquery joyride plugin with the given params. |
|
| 623 | + * |
|
| 624 | + * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 625 | + * @see EE_Admin_Page->_stop_callback() for the construct expected for the $stops param. |
|
| 626 | + * @param EE_Help_Tour |
|
| 627 | + * @return string html |
|
| 628 | + * @throws EE_Error |
|
| 629 | + */ |
|
| 630 | + public static function help_tour_stops_generator(EE_Help_Tour $tour) |
|
| 631 | + { |
|
| 632 | + global $allowedtags; |
|
| 633 | + $id = $tour->get_slug(); |
|
| 634 | + $stops = $tour->get_stops(); |
|
| 635 | + |
|
| 636 | + $content = '<ol style="display:none" id="' . esc_attr($id) . '">'; |
|
| 637 | + |
|
| 638 | + foreach ($stops as $stop) { |
|
| 639 | + $data_id = ! empty($stop['id']) |
|
| 640 | + ? ' data-id="' . esc_attr($stop['id']) . '"' |
|
| 641 | + : ''; |
|
| 642 | + |
|
| 643 | + $data_class = empty($data_id) && ! empty($stop['class']) |
|
| 644 | + ? ' data-class="' . esc_attr($stop['class']) . '"' |
|
| 645 | + : ''; |
|
| 646 | + |
|
| 647 | + // if container is set to modal then let's make sure we set the options accordingly |
|
| 648 | + if (empty($data_id) && empty($data_class)) { |
|
| 649 | + $stop['options']['modal'] = true; |
|
| 650 | + $stop['options']['expose'] = true; |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + $custom_class = ! empty($stop['custom_class']) |
|
| 654 | + ? ' class="' . esc_attr($stop['custom_class']) . '"' |
|
| 655 | + : ''; |
|
| 656 | + $button_text = ! empty($stop['button_text']) |
|
| 657 | + ? ' data-button="' . esc_html($stop['button_text']) . '"' |
|
| 658 | + : ''; |
|
| 659 | + $inner_content = isset($stop['content']) ? wp_kses($stop['content'], $allowedtags) : ''; |
|
| 660 | + |
|
| 661 | + // options |
|
| 662 | + if (isset($stop['options']) && is_array($stop['options'])) { |
|
| 663 | + $options = ' data-options="'; |
|
| 664 | + foreach ($stop['options'] as $option => $value) { |
|
| 665 | + $options .= esc_attr($option) . ':' . esc_attr($value) . ';'; |
|
| 666 | + } |
|
| 667 | + $options .= '"'; |
|
| 668 | + } else { |
|
| 669 | + $options = ''; |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + // let's put all together |
|
| 673 | + $content .= '<li' |
|
| 674 | + . $data_id |
|
| 675 | + . $data_class |
|
| 676 | + . $custom_class |
|
| 677 | + . $button_text |
|
| 678 | + . $options |
|
| 679 | + . '>' |
|
| 680 | + . $inner_content |
|
| 681 | + . '</li>'; |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + $content .= '</ol>'; |
|
| 685 | + return $content; |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + /** |
|
| 690 | + * This is a helper method to generate a status legend for a given status array. |
|
| 691 | + * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods |
|
| 692 | + * status_array. |
|
| 693 | + * |
|
| 694 | + * @param array $status_array array of statuses that will make up the legend. In format: |
|
| 695 | + * array( |
|
| 696 | + * 'status_item' => 'status_name' |
|
| 697 | + * ) |
|
| 698 | + * @param string $active_status This is used to indicate what the active status is IF that is to be highlighted in |
|
| 699 | + * the legend. |
|
| 700 | + * @return string html structure for status. |
|
| 701 | + * @throws EE_Error |
|
| 702 | + */ |
|
| 703 | + public static function status_legend($status_array, $active_status = '') |
|
| 704 | + { |
|
| 705 | + if (! is_array($status_array)) { |
|
| 706 | + throw new EE_Error( |
|
| 707 | + esc_html__( |
|
| 708 | + 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
|
| 709 | + 'event_espresso' |
|
| 710 | + ) |
|
| 711 | + ); |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + $content = ' |
|
| 715 | 715 | <div class="ee-list-table-legend-container"> |
| 716 | 716 | <h4 class="status-legend-title"> |
| 717 | 717 | ' . esc_html__('Status Legend', 'event_espresso') . ' |
| 718 | 718 | </h4> |
| 719 | 719 | <dl class="ee-list-table-legend">'; |
| 720 | 720 | |
| 721 | - foreach ($status_array as $item => $status) { |
|
| 722 | - $active_class = $active_status == $status ? 'class="ee-is-active-status"' : ''; |
|
| 723 | - $content .= ' |
|
| 721 | + foreach ($status_array as $item => $status) { |
|
| 722 | + $active_class = $active_status == $status ? 'class="ee-is-active-status"' : ''; |
|
| 723 | + $content .= ' |
|
| 724 | 724 | <dt id="' . esc_attr('ee-legend-item-tooltip-' . $item) . '" ' . $active_class . '> |
| 725 | 725 | <span class="' . esc_attr('ee-status-legend ee-status-bg--' . $status) . '"></span> |
| 726 | 726 | <span class="ee-legend-description"> |
| 727 | 727 | ' . EEH_Template::pretty_status($status, false, 'sentence') . ' |
| 728 | 728 | </span> |
| 729 | 729 | </dt>'; |
| 730 | - } |
|
| 730 | + } |
|
| 731 | 731 | |
| 732 | - $content .= ' |
|
| 732 | + $content .= ' |
|
| 733 | 733 | </dl> |
| 734 | 734 | </div> |
| 735 | 735 | '; |
| 736 | - return $content; |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - |
|
| 740 | - /** |
|
| 741 | - * Gets HTML for laying out a deeply-nested array (and objects) in a format |
|
| 742 | - * that's nice for presenting in the wp admin |
|
| 743 | - * |
|
| 744 | - * @param mixed $data |
|
| 745 | - * @return string |
|
| 746 | - */ |
|
| 747 | - public static function layout_array_as_table($data) |
|
| 748 | - { |
|
| 749 | - if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
| 750 | - $data = (array) $data; |
|
| 751 | - } |
|
| 752 | - ob_start(); |
|
| 753 | - if (is_array($data)) { |
|
| 754 | - if (EEH_Array::is_associative_array($data)) { ?> |
|
| 736 | + return $content; |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * Gets HTML for laying out a deeply-nested array (and objects) in a format |
|
| 742 | + * that's nice for presenting in the wp admin |
|
| 743 | + * |
|
| 744 | + * @param mixed $data |
|
| 745 | + * @return string |
|
| 746 | + */ |
|
| 747 | + public static function layout_array_as_table($data) |
|
| 748 | + { |
|
| 749 | + if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
| 750 | + $data = (array) $data; |
|
| 751 | + } |
|
| 752 | + ob_start(); |
|
| 753 | + if (is_array($data)) { |
|
| 754 | + if (EEH_Array::is_associative_array($data)) { ?> |
|
| 755 | 755 | <table class="widefat"> |
| 756 | 756 | <tbody> |
| 757 | 757 | <?php foreach ($data as $data_key => $data_values) { ?> |
@@ -769,292 +769,292 @@ discard block |
||
| 769 | 769 | <?php } else { ?> |
| 770 | 770 | <ul> |
| 771 | 771 | <?php |
| 772 | - foreach ($data as $datum) { |
|
| 773 | - echo "<li>"; |
|
| 774 | - echo self::layout_array_as_table($datum); |
|
| 775 | - echo "</li>"; |
|
| 776 | - } ?> |
|
| 772 | + foreach ($data as $datum) { |
|
| 773 | + echo "<li>"; |
|
| 774 | + echo self::layout_array_as_table($datum); |
|
| 775 | + echo "</li>"; |
|
| 776 | + } ?> |
|
| 777 | 777 | </ul> |
| 778 | 778 | <?php } |
| 779 | - } else { |
|
| 780 | - // simple value |
|
| 781 | - echo esc_html($data); |
|
| 782 | - } |
|
| 783 | - return ob_get_clean(); |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - |
|
| 787 | - /** |
|
| 788 | - * wrapper for self::get_paging_html() that simply echos the generated paging html |
|
| 789 | - * |
|
| 790 | - * @param $total_items |
|
| 791 | - * @param $current |
|
| 792 | - * @param $per_page |
|
| 793 | - * @param $url |
|
| 794 | - * @param bool $show_num_field |
|
| 795 | - * @param string $paged_arg_name |
|
| 796 | - * @param array $items_label |
|
| 797 | - * @see self:get_paging_html() for argument docs. |
|
| 798 | - * @since 4.4.0 |
|
| 799 | - */ |
|
| 800 | - public static function paging_html( |
|
| 801 | - $total_items, |
|
| 802 | - $current, |
|
| 803 | - $per_page, |
|
| 804 | - $url, |
|
| 805 | - $show_num_field = true, |
|
| 806 | - $paged_arg_name = 'paged', |
|
| 807 | - $items_label = [] |
|
| 808 | - ) { |
|
| 809 | - echo self::get_paging_html( |
|
| 810 | - $total_items, |
|
| 811 | - $current, |
|
| 812 | - $per_page, |
|
| 813 | - $url, |
|
| 814 | - $show_num_field, |
|
| 815 | - $paged_arg_name, |
|
| 816 | - $items_label |
|
| 817 | - ); |
|
| 818 | - } |
|
| 819 | - |
|
| 820 | - |
|
| 821 | - /** |
|
| 822 | - * A method for generating paging similar to WP_List_Table |
|
| 823 | - * |
|
| 824 | - * @param integer $total_items How many total items there are to page. |
|
| 825 | - * @param integer $current What the current page is. |
|
| 826 | - * @param integer $per_page How many items per page. |
|
| 827 | - * @param string $url What the base url for page links is. |
|
| 828 | - * @param boolean $show_num_field Whether to show the input for changing page number. |
|
| 829 | - * @param string $paged_arg_name The name of the key for the paged query argument. |
|
| 830 | - * @param array $items_label An array of singular/plural values for the items label: |
|
| 831 | - * array( |
|
| 832 | - * 'single' => 'item', |
|
| 833 | - * 'plural' => 'items' |
|
| 834 | - * ) |
|
| 835 | - * @return string |
|
| 836 | - * @since 4.4.0 |
|
| 837 | - * @see wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination() |
|
| 838 | - */ |
|
| 839 | - public static function get_paging_html( |
|
| 840 | - $total_items, |
|
| 841 | - $current, |
|
| 842 | - $per_page, |
|
| 843 | - $url, |
|
| 844 | - $show_num_field = true, |
|
| 845 | - $paged_arg_name = 'paged', |
|
| 846 | - $items_label = [] |
|
| 847 | - ) { |
|
| 848 | - $page_links = []; |
|
| 849 | - $disable_first = $disable_last = ''; |
|
| 850 | - $total_items = (int) $total_items; |
|
| 851 | - $per_page = (int) $per_page; |
|
| 852 | - $current = (int) $current; |
|
| 853 | - $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
|
| 854 | - |
|
| 855 | - // filter items_label |
|
| 856 | - $items_label = apply_filters( |
|
| 857 | - 'FHEE__EEH_Template__get_paging_html__items_label', |
|
| 858 | - $items_label |
|
| 859 | - ); |
|
| 860 | - |
|
| 861 | - if ( |
|
| 862 | - empty($items_label) |
|
| 863 | - || ! is_array($items_label) |
|
| 864 | - || ! isset($items_label['single']) |
|
| 865 | - || ! isset($items_label['plural']) |
|
| 866 | - ) { |
|
| 867 | - $items_label = [ |
|
| 868 | - 'single' => esc_html__('1 item', 'event_espresso'), |
|
| 869 | - 'plural' => esc_html__('%s items', 'event_espresso'), |
|
| 870 | - ]; |
|
| 871 | - } else { |
|
| 872 | - $items_label = [ |
|
| 873 | - 'single' => '1 ' . esc_html($items_label['single']), |
|
| 874 | - 'plural' => '%s ' . esc_html($items_label['plural']), |
|
| 875 | - ]; |
|
| 876 | - } |
|
| 877 | - |
|
| 878 | - $total_pages = ceil($total_items / $per_page); |
|
| 879 | - |
|
| 880 | - if ($total_pages <= 1) { |
|
| 881 | - return ''; |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
|
| 885 | - |
|
| 886 | - $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
| 887 | - |
|
| 888 | - if ($current === 1) { |
|
| 889 | - $disable_first = ' disabled'; |
|
| 890 | - } |
|
| 891 | - if ($current == $total_pages) { |
|
| 892 | - $disable_last = ' disabled'; |
|
| 893 | - } |
|
| 894 | - |
|
| 895 | - $page_links[] = sprintf( |
|
| 896 | - "<a class='%s' title='%s' href='%s'>%s</a>", |
|
| 897 | - 'first-page' . $disable_first, |
|
| 898 | - esc_attr__('Go to the first page', 'event_espresso'), |
|
| 899 | - esc_url_raw(remove_query_arg($paged_arg_name, $url)), |
|
| 900 | - '«' |
|
| 901 | - ); |
|
| 902 | - |
|
| 903 | - $page_links[] = sprintf( |
|
| 904 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 905 | - 'prev-page' . $disable_first, |
|
| 906 | - esc_attr__('Go to the previous page', 'event_espresso'), |
|
| 907 | - esc_url_raw(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
|
| 908 | - '‹' |
|
| 909 | - ); |
|
| 910 | - |
|
| 911 | - if (! $show_num_field) { |
|
| 912 | - $html_current_page = $current; |
|
| 913 | - } else { |
|
| 914 | - $html_current_page = sprintf( |
|
| 915 | - "<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />", |
|
| 916 | - esc_attr__('Current page', 'event_espresso'), |
|
| 917 | - esc_attr($current), |
|
| 918 | - strlen($total_pages) |
|
| 919 | - ); |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - $html_total_pages = sprintf( |
|
| 923 | - '<span class="total-pages">%s</span>', |
|
| 924 | - number_format_i18n($total_pages) |
|
| 925 | - ); |
|
| 926 | - $page_links[] = sprintf( |
|
| 927 | - _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'), |
|
| 928 | - $html_current_page, |
|
| 929 | - $html_total_pages, |
|
| 930 | - '<span class="paging-input">', |
|
| 931 | - '</span>' |
|
| 932 | - ); |
|
| 933 | - |
|
| 934 | - $page_links[] = sprintf( |
|
| 935 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 936 | - 'next-page' . $disable_last, |
|
| 937 | - esc_attr__('Go to the next page', 'event_espresso'), |
|
| 938 | - esc_url_raw(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
|
| 939 | - '›' |
|
| 940 | - ); |
|
| 941 | - |
|
| 942 | - $page_links[] = sprintf( |
|
| 943 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 944 | - 'last-page' . $disable_last, |
|
| 945 | - esc_attr__('Go to the last page', 'event_espresso'), |
|
| 946 | - esc_url_raw(add_query_arg($paged_arg_name, $total_pages, $url)), |
|
| 947 | - '»' |
|
| 948 | - ); |
|
| 949 | - |
|
| 950 | - $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
| 951 | - // set page class |
|
| 952 | - if ($total_pages) { |
|
| 953 | - $page_class = $total_pages < 2 ? ' one-page' : ''; |
|
| 954 | - } else { |
|
| 955 | - $page_class = ' no-pages'; |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
| 959 | - } |
|
| 960 | - |
|
| 961 | - |
|
| 962 | - /** |
|
| 963 | - * @param string $wrap_class |
|
| 964 | - * @param string $wrap_id |
|
| 965 | - * @return string |
|
| 966 | - */ |
|
| 967 | - public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = []) |
|
| 968 | - { |
|
| 969 | - $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
|
| 970 | - if ( |
|
| 971 | - ! $admin |
|
| 972 | - && ! apply_filters( |
|
| 973 | - 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
|
| 974 | - EE_Registry::instance()->CFG->admin->show_reg_footer |
|
| 975 | - ) |
|
| 976 | - ) { |
|
| 977 | - return ''; |
|
| 978 | - } |
|
| 979 | - $tag = $admin ? 'span' : 'div'; |
|
| 980 | - $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : ''; |
|
| 981 | - $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class; |
|
| 982 | - $attributes .= ! empty($wrap_class) |
|
| 983 | - ? " class=\"{$wrap_class} powered-by-event-espresso-credit\"" |
|
| 984 | - : ' class="powered-by-event-espresso-credit"'; |
|
| 985 | - $query_args = array_merge( |
|
| 986 | - [ |
|
| 987 | - 'ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id(), |
|
| 988 | - 'utm_source' => 'powered_by_event_espresso', |
|
| 989 | - 'utm_medium' => 'link', |
|
| 990 | - 'utm_campaign' => 'powered_by', |
|
| 991 | - ], |
|
| 992 | - $query_args |
|
| 993 | - ); |
|
| 994 | - $powered_by = apply_filters( |
|
| 995 | - 'FHEE__EEH_Template__powered_by_event_espresso_text', |
|
| 996 | - $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
| 997 | - ); |
|
| 998 | - $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
|
| 999 | - $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
|
| 1000 | - return (string) apply_filters( |
|
| 1001 | - 'FHEE__EEH_Template__powered_by_event_espresso__html', |
|
| 1002 | - sprintf( |
|
| 1003 | - esc_html_x( |
|
| 1004 | - '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s', |
|
| 1005 | - 'Online event registration and ticketing powered by [link to eventespresso.com]', |
|
| 1006 | - 'event_espresso' |
|
| 1007 | - ), |
|
| 1008 | - "<{$tag}{$attributes}>", |
|
| 1009 | - "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>", |
|
| 1010 | - $admin ? '' : '<br />' |
|
| 1011 | - ), |
|
| 1012 | - $wrap_class, |
|
| 1013 | - $wrap_id |
|
| 1014 | - ); |
|
| 1015 | - } |
|
| 1016 | - |
|
| 1017 | - |
|
| 1018 | - /** |
|
| 1019 | - * @param string $image_name |
|
| 1020 | - * @return string|null |
|
| 1021 | - * @since 4.10.14.p |
|
| 1022 | - */ |
|
| 1023 | - public static function getScreenshotUrl($image_name) |
|
| 1024 | - { |
|
| 1025 | - return esc_url_raw(EE_GLOBAL_ASSETS_URL . 'images/screenshots/' . $image_name . '.jpg'); |
|
| 1026 | - } |
|
| 779 | + } else { |
|
| 780 | + // simple value |
|
| 781 | + echo esc_html($data); |
|
| 782 | + } |
|
| 783 | + return ob_get_clean(); |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + |
|
| 787 | + /** |
|
| 788 | + * wrapper for self::get_paging_html() that simply echos the generated paging html |
|
| 789 | + * |
|
| 790 | + * @param $total_items |
|
| 791 | + * @param $current |
|
| 792 | + * @param $per_page |
|
| 793 | + * @param $url |
|
| 794 | + * @param bool $show_num_field |
|
| 795 | + * @param string $paged_arg_name |
|
| 796 | + * @param array $items_label |
|
| 797 | + * @see self:get_paging_html() for argument docs. |
|
| 798 | + * @since 4.4.0 |
|
| 799 | + */ |
|
| 800 | + public static function paging_html( |
|
| 801 | + $total_items, |
|
| 802 | + $current, |
|
| 803 | + $per_page, |
|
| 804 | + $url, |
|
| 805 | + $show_num_field = true, |
|
| 806 | + $paged_arg_name = 'paged', |
|
| 807 | + $items_label = [] |
|
| 808 | + ) { |
|
| 809 | + echo self::get_paging_html( |
|
| 810 | + $total_items, |
|
| 811 | + $current, |
|
| 812 | + $per_page, |
|
| 813 | + $url, |
|
| 814 | + $show_num_field, |
|
| 815 | + $paged_arg_name, |
|
| 816 | + $items_label |
|
| 817 | + ); |
|
| 818 | + } |
|
| 819 | + |
|
| 820 | + |
|
| 821 | + /** |
|
| 822 | + * A method for generating paging similar to WP_List_Table |
|
| 823 | + * |
|
| 824 | + * @param integer $total_items How many total items there are to page. |
|
| 825 | + * @param integer $current What the current page is. |
|
| 826 | + * @param integer $per_page How many items per page. |
|
| 827 | + * @param string $url What the base url for page links is. |
|
| 828 | + * @param boolean $show_num_field Whether to show the input for changing page number. |
|
| 829 | + * @param string $paged_arg_name The name of the key for the paged query argument. |
|
| 830 | + * @param array $items_label An array of singular/plural values for the items label: |
|
| 831 | + * array( |
|
| 832 | + * 'single' => 'item', |
|
| 833 | + * 'plural' => 'items' |
|
| 834 | + * ) |
|
| 835 | + * @return string |
|
| 836 | + * @since 4.4.0 |
|
| 837 | + * @see wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination() |
|
| 838 | + */ |
|
| 839 | + public static function get_paging_html( |
|
| 840 | + $total_items, |
|
| 841 | + $current, |
|
| 842 | + $per_page, |
|
| 843 | + $url, |
|
| 844 | + $show_num_field = true, |
|
| 845 | + $paged_arg_name = 'paged', |
|
| 846 | + $items_label = [] |
|
| 847 | + ) { |
|
| 848 | + $page_links = []; |
|
| 849 | + $disable_first = $disable_last = ''; |
|
| 850 | + $total_items = (int) $total_items; |
|
| 851 | + $per_page = (int) $per_page; |
|
| 852 | + $current = (int) $current; |
|
| 853 | + $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
|
| 854 | + |
|
| 855 | + // filter items_label |
|
| 856 | + $items_label = apply_filters( |
|
| 857 | + 'FHEE__EEH_Template__get_paging_html__items_label', |
|
| 858 | + $items_label |
|
| 859 | + ); |
|
| 860 | + |
|
| 861 | + if ( |
|
| 862 | + empty($items_label) |
|
| 863 | + || ! is_array($items_label) |
|
| 864 | + || ! isset($items_label['single']) |
|
| 865 | + || ! isset($items_label['plural']) |
|
| 866 | + ) { |
|
| 867 | + $items_label = [ |
|
| 868 | + 'single' => esc_html__('1 item', 'event_espresso'), |
|
| 869 | + 'plural' => esc_html__('%s items', 'event_espresso'), |
|
| 870 | + ]; |
|
| 871 | + } else { |
|
| 872 | + $items_label = [ |
|
| 873 | + 'single' => '1 ' . esc_html($items_label['single']), |
|
| 874 | + 'plural' => '%s ' . esc_html($items_label['plural']), |
|
| 875 | + ]; |
|
| 876 | + } |
|
| 877 | + |
|
| 878 | + $total_pages = ceil($total_items / $per_page); |
|
| 879 | + |
|
| 880 | + if ($total_pages <= 1) { |
|
| 881 | + return ''; |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
|
| 885 | + |
|
| 886 | + $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
| 887 | + |
|
| 888 | + if ($current === 1) { |
|
| 889 | + $disable_first = ' disabled'; |
|
| 890 | + } |
|
| 891 | + if ($current == $total_pages) { |
|
| 892 | + $disable_last = ' disabled'; |
|
| 893 | + } |
|
| 894 | + |
|
| 895 | + $page_links[] = sprintf( |
|
| 896 | + "<a class='%s' title='%s' href='%s'>%s</a>", |
|
| 897 | + 'first-page' . $disable_first, |
|
| 898 | + esc_attr__('Go to the first page', 'event_espresso'), |
|
| 899 | + esc_url_raw(remove_query_arg($paged_arg_name, $url)), |
|
| 900 | + '«' |
|
| 901 | + ); |
|
| 902 | + |
|
| 903 | + $page_links[] = sprintf( |
|
| 904 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 905 | + 'prev-page' . $disable_first, |
|
| 906 | + esc_attr__('Go to the previous page', 'event_espresso'), |
|
| 907 | + esc_url_raw(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
|
| 908 | + '‹' |
|
| 909 | + ); |
|
| 910 | + |
|
| 911 | + if (! $show_num_field) { |
|
| 912 | + $html_current_page = $current; |
|
| 913 | + } else { |
|
| 914 | + $html_current_page = sprintf( |
|
| 915 | + "<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />", |
|
| 916 | + esc_attr__('Current page', 'event_espresso'), |
|
| 917 | + esc_attr($current), |
|
| 918 | + strlen($total_pages) |
|
| 919 | + ); |
|
| 920 | + } |
|
| 921 | + |
|
| 922 | + $html_total_pages = sprintf( |
|
| 923 | + '<span class="total-pages">%s</span>', |
|
| 924 | + number_format_i18n($total_pages) |
|
| 925 | + ); |
|
| 926 | + $page_links[] = sprintf( |
|
| 927 | + _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'), |
|
| 928 | + $html_current_page, |
|
| 929 | + $html_total_pages, |
|
| 930 | + '<span class="paging-input">', |
|
| 931 | + '</span>' |
|
| 932 | + ); |
|
| 933 | + |
|
| 934 | + $page_links[] = sprintf( |
|
| 935 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 936 | + 'next-page' . $disable_last, |
|
| 937 | + esc_attr__('Go to the next page', 'event_espresso'), |
|
| 938 | + esc_url_raw(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
|
| 939 | + '›' |
|
| 940 | + ); |
|
| 941 | + |
|
| 942 | + $page_links[] = sprintf( |
|
| 943 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 944 | + 'last-page' . $disable_last, |
|
| 945 | + esc_attr__('Go to the last page', 'event_espresso'), |
|
| 946 | + esc_url_raw(add_query_arg($paged_arg_name, $total_pages, $url)), |
|
| 947 | + '»' |
|
| 948 | + ); |
|
| 949 | + |
|
| 950 | + $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
| 951 | + // set page class |
|
| 952 | + if ($total_pages) { |
|
| 953 | + $page_class = $total_pages < 2 ? ' one-page' : ''; |
|
| 954 | + } else { |
|
| 955 | + $page_class = ' no-pages'; |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
| 959 | + } |
|
| 960 | + |
|
| 961 | + |
|
| 962 | + /** |
|
| 963 | + * @param string $wrap_class |
|
| 964 | + * @param string $wrap_id |
|
| 965 | + * @return string |
|
| 966 | + */ |
|
| 967 | + public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = []) |
|
| 968 | + { |
|
| 969 | + $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
|
| 970 | + if ( |
|
| 971 | + ! $admin |
|
| 972 | + && ! apply_filters( |
|
| 973 | + 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
|
| 974 | + EE_Registry::instance()->CFG->admin->show_reg_footer |
|
| 975 | + ) |
|
| 976 | + ) { |
|
| 977 | + return ''; |
|
| 978 | + } |
|
| 979 | + $tag = $admin ? 'span' : 'div'; |
|
| 980 | + $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : ''; |
|
| 981 | + $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class; |
|
| 982 | + $attributes .= ! empty($wrap_class) |
|
| 983 | + ? " class=\"{$wrap_class} powered-by-event-espresso-credit\"" |
|
| 984 | + : ' class="powered-by-event-espresso-credit"'; |
|
| 985 | + $query_args = array_merge( |
|
| 986 | + [ |
|
| 987 | + 'ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id(), |
|
| 988 | + 'utm_source' => 'powered_by_event_espresso', |
|
| 989 | + 'utm_medium' => 'link', |
|
| 990 | + 'utm_campaign' => 'powered_by', |
|
| 991 | + ], |
|
| 992 | + $query_args |
|
| 993 | + ); |
|
| 994 | + $powered_by = apply_filters( |
|
| 995 | + 'FHEE__EEH_Template__powered_by_event_espresso_text', |
|
| 996 | + $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
| 997 | + ); |
|
| 998 | + $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
|
| 999 | + $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
|
| 1000 | + return (string) apply_filters( |
|
| 1001 | + 'FHEE__EEH_Template__powered_by_event_espresso__html', |
|
| 1002 | + sprintf( |
|
| 1003 | + esc_html_x( |
|
| 1004 | + '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s', |
|
| 1005 | + 'Online event registration and ticketing powered by [link to eventespresso.com]', |
|
| 1006 | + 'event_espresso' |
|
| 1007 | + ), |
|
| 1008 | + "<{$tag}{$attributes}>", |
|
| 1009 | + "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>", |
|
| 1010 | + $admin ? '' : '<br />' |
|
| 1011 | + ), |
|
| 1012 | + $wrap_class, |
|
| 1013 | + $wrap_id |
|
| 1014 | + ); |
|
| 1015 | + } |
|
| 1016 | + |
|
| 1017 | + |
|
| 1018 | + /** |
|
| 1019 | + * @param string $image_name |
|
| 1020 | + * @return string|null |
|
| 1021 | + * @since 4.10.14.p |
|
| 1022 | + */ |
|
| 1023 | + public static function getScreenshotUrl($image_name) |
|
| 1024 | + { |
|
| 1025 | + return esc_url_raw(EE_GLOBAL_ASSETS_URL . 'images/screenshots/' . $image_name . '.jpg'); |
|
| 1026 | + } |
|
| 1027 | 1027 | } |
| 1028 | 1028 | |
| 1029 | 1029 | |
| 1030 | 1030 | if (! function_exists('espresso_pagination')) { |
| 1031 | - /** |
|
| 1032 | - * espresso_pagination |
|
| 1033 | - * |
|
| 1034 | - * @access public |
|
| 1035 | - * @return void |
|
| 1036 | - */ |
|
| 1037 | - function espresso_pagination() |
|
| 1038 | - { |
|
| 1039 | - global $wp_query; |
|
| 1040 | - $big = 999999999; // need an unlikely integer |
|
| 1041 | - $pagination = paginate_links( |
|
| 1042 | - [ |
|
| 1043 | - 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
| 1044 | - 'format' => '?paged=%#%', |
|
| 1045 | - 'current' => max(1, get_query_var('paged')), |
|
| 1046 | - 'total' => $wp_query->max_num_pages, |
|
| 1047 | - 'show_all' => true, |
|
| 1048 | - 'end_size' => 10, |
|
| 1049 | - 'mid_size' => 6, |
|
| 1050 | - 'prev_next' => true, |
|
| 1051 | - 'prev_text' => esc_html__('‹ PREV', 'event_espresso'), |
|
| 1052 | - 'next_text' => esc_html__('NEXT ›', 'event_espresso'), |
|
| 1053 | - 'type' => 'plain', |
|
| 1054 | - 'add_args' => false, |
|
| 1055 | - 'add_fragment' => '', |
|
| 1056 | - ] |
|
| 1057 | - ); |
|
| 1058 | - echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
| 1059 | - } |
|
| 1031 | + /** |
|
| 1032 | + * espresso_pagination |
|
| 1033 | + * |
|
| 1034 | + * @access public |
|
| 1035 | + * @return void |
|
| 1036 | + */ |
|
| 1037 | + function espresso_pagination() |
|
| 1038 | + { |
|
| 1039 | + global $wp_query; |
|
| 1040 | + $big = 999999999; // need an unlikely integer |
|
| 1041 | + $pagination = paginate_links( |
|
| 1042 | + [ |
|
| 1043 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
| 1044 | + 'format' => '?paged=%#%', |
|
| 1045 | + 'current' => max(1, get_query_var('paged')), |
|
| 1046 | + 'total' => $wp_query->max_num_pages, |
|
| 1047 | + 'show_all' => true, |
|
| 1048 | + 'end_size' => 10, |
|
| 1049 | + 'mid_size' => 6, |
|
| 1050 | + 'prev_next' => true, |
|
| 1051 | + 'prev_text' => esc_html__('‹ PREV', 'event_espresso'), |
|
| 1052 | + 'next_text' => esc_html__('NEXT ›', 'event_espresso'), |
|
| 1053 | + 'type' => 'plain', |
|
| 1054 | + 'add_args' => false, |
|
| 1055 | + 'add_fragment' => '', |
|
| 1056 | + ] |
|
| 1057 | + ); |
|
| 1058 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
| 1059 | + } |
|
| 1060 | 1060 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | use EventEspresso\core\services\loaders\LoaderFactory; |
| 6 | 6 | use EventEspresso\core\services\request\RequestInterface; |
| 7 | 7 | |
| 8 | -if (! function_exists('espresso_get_template_part')) { |
|
| 8 | +if ( ! function_exists('espresso_get_template_part')) { |
|
| 9 | 9 | /** |
| 10 | 10 | * espresso_get_template_part |
| 11 | 11 | * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
| 24 | -if (! function_exists('espresso_get_object_css_class')) { |
|
| 24 | +if ( ! function_exists('espresso_get_object_css_class')) { |
|
| 25 | 25 | /** |
| 26 | 26 | * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
| 27 | 27 | * |
@@ -72,9 +72,9 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public static function load_espresso_theme_functions() |
| 74 | 74 | { |
| 75 | - if (! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
| 76 | - if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) { |
|
| 77 | - require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php'); |
|
| 75 | + if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
| 76 | + if (is_readable(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php')) { |
|
| 77 | + require_once(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php'); |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | } |
@@ -88,16 +88,16 @@ discard block |
||
| 88 | 88 | public static function get_espresso_themes() |
| 89 | 89 | { |
| 90 | 90 | if (empty(EEH_Template::$_espresso_themes)) { |
| 91 | - $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
| 91 | + $espresso_themes = glob(EE_PUBLIC.'*', GLOB_ONLYDIR); |
|
| 92 | 92 | if (empty($espresso_themes)) { |
| 93 | 93 | return []; |
| 94 | 94 | } |
| 95 | 95 | if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
| 96 | - unset($espresso_themes[ $key ]); |
|
| 96 | + unset($espresso_themes[$key]); |
|
| 97 | 97 | } |
| 98 | 98 | EEH_Template::$_espresso_themes = []; |
| 99 | 99 | foreach ($espresso_themes as $espresso_theme) { |
| 100 | - EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme; |
|
| 100 | + EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme; |
|
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | return EEH_Template::$_espresso_themes; |
@@ -213,10 +213,10 @@ discard block |
||
| 213 | 213 | // get array of EE Custom Post Types |
| 214 | 214 | $EE_CPTs = $custom_post_types->getDefinitions(); |
| 215 | 215 | // build template name based on request |
| 216 | - if (isset($EE_CPTs[ $post_type ])) { |
|
| 216 | + if (isset($EE_CPTs[$post_type])) { |
|
| 217 | 217 | $archive_or_single = is_archive() ? 'archive' : ''; |
| 218 | 218 | $archive_or_single = is_single() ? 'single' : $archive_or_single; |
| 219 | - $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
| 219 | + $templates = $archive_or_single.'-'.$post_type.'.php'; |
|
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | // currently active EE template theme |
@@ -225,18 +225,18 @@ discard block |
||
| 225 | 225 | // array of paths to folders that may contain templates |
| 226 | 226 | $template_folder_paths = [ |
| 227 | 227 | // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
| 228 | - EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
| 228 | + EVENT_ESPRESSO_TEMPLATE_DIR.$current_theme, |
|
| 229 | 229 | // then in the root of the /wp-content/uploads/espresso/templates/ folder |
| 230 | 230 | EVENT_ESPRESSO_TEMPLATE_DIR, |
| 231 | 231 | ]; |
| 232 | 232 | |
| 233 | 233 | // add core plugin folders for checking only if we're not $check_if_custom |
| 234 | - if (! $check_if_custom) { |
|
| 235 | - $core_paths = [ |
|
| 234 | + if ( ! $check_if_custom) { |
|
| 235 | + $core_paths = [ |
|
| 236 | 236 | // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
| 237 | - EE_PUBLIC . $current_theme, |
|
| 237 | + EE_PUBLIC.$current_theme, |
|
| 238 | 238 | // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
| 239 | - EE_TEMPLATES . $current_theme, |
|
| 239 | + EE_TEMPLATES.$current_theme, |
|
| 240 | 240 | // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
| 241 | 241 | EE_PLUGIN_DIR_PATH, |
| 242 | 242 | ]; |
@@ -271,10 +271,10 @@ discard block |
||
| 271 | 271 | ); |
| 272 | 272 | if ($common_base_path !== '') { |
| 273 | 273 | // both paths have a common base, so just tack the filename onto our search path |
| 274 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
| 274 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$file_name; |
|
| 275 | 275 | } else { |
| 276 | 276 | // no common base path, so let's just concatenate |
| 277 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
| 277 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$template; |
|
| 278 | 278 | } |
| 279 | 279 | // build up our template locations array by adding our resolved paths |
| 280 | 280 | $full_template_paths[] = $resolved_path; |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
| 283 | 283 | array_unshift($full_template_paths, $template); |
| 284 | 284 | // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
| 285 | - array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name); |
|
| 285 | + array_unshift($full_template_paths, get_stylesheet_directory().'/'.$file_name); |
|
| 286 | 286 | } |
| 287 | 287 | // filter final array of full template paths |
| 288 | 288 | $full_template_paths = apply_filters( |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | 335 | $common_base_path .= $directory; |
| 336 | - $last_offset = $index + 1; |
|
| 336 | + $last_offset = $index + 1; |
|
| 337 | 337 | } |
| 338 | 338 | return substr($common_base_path, 0, -1); |
| 339 | 339 | } |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
| 372 | 372 | |
| 373 | 373 | // you gimme nuttin - YOU GET NUTTIN !! |
| 374 | - if (! $template_path || ! is_readable($template_path)) { |
|
| 374 | + if ( ! $template_path || ! is_readable($template_path)) { |
|
| 375 | 375 | // ignore whether template is accessible ? |
| 376 | 376 | if ($throw_exceptions) { |
| 377 | 377 | throw new DomainException( |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | return ''; |
| 382 | 382 | } |
| 383 | 383 | // if $template_args are not in an array, then make it so |
| 384 | - if (! is_array($template_args) && ! is_object($template_args)) { |
|
| 384 | + if ( ! is_array($template_args) && ! is_object($template_args)) { |
|
| 385 | 385 | $template_args = [$template_args]; |
| 386 | 386 | } |
| 387 | 387 | extract($template_args, EXTR_SKIP); |
@@ -410,11 +410,11 @@ discard block |
||
| 410 | 410 | public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
| 411 | 411 | { |
| 412 | 412 | // in the beginning... |
| 413 | - $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
| 413 | + $prefix = ! empty($prefix) ? rtrim($prefix, '-').'-' : ''; |
|
| 414 | 414 | // da muddle |
| 415 | 415 | $class = ''; |
| 416 | 416 | // the end |
| 417 | - $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
| 417 | + $suffix = ! empty($suffix) ? '-'.ltrim($suffix, '-') : ''; |
|
| 418 | 418 | // is the passed object an EE object ? |
| 419 | 419 | if ($object instanceof EE_Base_Class) { |
| 420 | 420 | // grab the exact type of object |
@@ -424,10 +424,10 @@ discard block |
||
| 424 | 424 | // no specifics just yet... |
| 425 | 425 | default: |
| 426 | 426 | $class = strtolower(str_replace('_', '-', $obj_class)); |
| 427 | - $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
| 427 | + $class .= method_exists($obj_class, 'name') ? '-'.sanitize_title($object->name()) : ''; |
|
| 428 | 428 | } |
| 429 | 429 | } |
| 430 | - return $prefix . $class . $suffix; |
|
| 430 | + return $prefix.$class.$suffix; |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | // filter raw amount (allows 0.00 to be changed to "free" for example) |
| 463 | 463 | $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
| 464 | 464 | // still a number, or was amount converted to a string like "free" ? |
| 465 | - if (! is_float($amount_formatted)) { |
|
| 465 | + if ( ! is_float($amount_formatted)) { |
|
| 466 | 466 | return esc_html($amount_formatted); |
| 467 | 467 | } |
| 468 | 468 | try { |
@@ -473,7 +473,7 @@ discard block |
||
| 473 | 473 | $mny = null; |
| 474 | 474 | } |
| 475 | 475 | // verify results |
| 476 | - if (! $mny instanceof EE_Currency_Config) { |
|
| 476 | + if ( ! $mny instanceof EE_Currency_Config) { |
|
| 477 | 477 | // set default config country currency settings |
| 478 | 478 | $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
| 479 | 479 | ? EE_Registry::instance()->CFG->currency |
@@ -482,16 +482,16 @@ discard block |
||
| 482 | 482 | // format float |
| 483 | 483 | $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
| 484 | 484 | // add formatting ? |
| 485 | - if (! $return_raw) { |
|
| 485 | + if ( ! $return_raw) { |
|
| 486 | 486 | // add currency sign |
| 487 | 487 | if ($mny->sign_b4) { |
| 488 | 488 | if ($amount >= 0) { |
| 489 | - $amount_formatted = $mny->sign . $amount_formatted; |
|
| 489 | + $amount_formatted = $mny->sign.$amount_formatted; |
|
| 490 | 490 | } else { |
| 491 | - $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
| 491 | + $amount_formatted = '-'.$mny->sign.str_replace('-', '', $amount_formatted); |
|
| 492 | 492 | } |
| 493 | 493 | } else { |
| 494 | - $amount_formatted = $amount_formatted . $mny->sign; |
|
| 494 | + $amount_formatted = $amount_formatted.$mny->sign; |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | // filter to allow global setting of display_code |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | |
| 503 | 503 | // add currency code ? |
| 504 | 504 | $amount_formatted = $display_code |
| 505 | - ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' |
|
| 505 | + ? $amount_formatted.' <span class="'.$cur_code_span_class.'">('.$mny->code.')</span>' |
|
| 506 | 506 | : $amount_formatted; |
| 507 | 507 | } |
| 508 | 508 | // filter results |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | $plural, |
| 539 | 539 | $schema |
| 540 | 540 | ); |
| 541 | - return $status[ $status_id ]; |
|
| 541 | + return $status[$status_id]; |
|
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | |
@@ -555,14 +555,14 @@ discard block |
||
| 555 | 555 | public static function get_button_or_link($url, $label, $class = 'button--primary', $icon = '', $title = '') |
| 556 | 556 | { |
| 557 | 557 | $icon_html = ''; |
| 558 | - if (! empty($icon)) { |
|
| 558 | + if ( ! empty($icon)) { |
|
| 559 | 559 | $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
| 560 | 560 | $dashicons = array_filter($dashicons); |
| 561 | 561 | $count = count($dashicons); |
| 562 | 562 | $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
| 563 | 563 | foreach ($dashicons as $dashicon) { |
| 564 | - $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
| 565 | - $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
| 564 | + $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
| 565 | + $icon_html .= '<span class="'.$type.$dashicon.'"></span>'; |
|
| 566 | 566 | } |
| 567 | 567 | $icon_html .= $count > 1 ? '</span>' : ''; |
| 568 | 568 | } |
@@ -600,7 +600,7 @@ discard block |
||
| 600 | 600 | $action = $action ?: $request->getRequestParam('action', 'default', 'key'); |
| 601 | 601 | |
| 602 | 602 | |
| 603 | - $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
| 603 | + $help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id; |
|
| 604 | 604 | $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
| 605 | 605 | $help_text = ! $help_text ? '' : $help_text; |
| 606 | 606 | return '<a id="' |
@@ -633,15 +633,15 @@ discard block |
||
| 633 | 633 | $id = $tour->get_slug(); |
| 634 | 634 | $stops = $tour->get_stops(); |
| 635 | 635 | |
| 636 | - $content = '<ol style="display:none" id="' . esc_attr($id) . '">'; |
|
| 636 | + $content = '<ol style="display:none" id="'.esc_attr($id).'">'; |
|
| 637 | 637 | |
| 638 | 638 | foreach ($stops as $stop) { |
| 639 | - $data_id = ! empty($stop['id']) |
|
| 640 | - ? ' data-id="' . esc_attr($stop['id']) . '"' |
|
| 639 | + $data_id = ! empty($stop['id']) |
|
| 640 | + ? ' data-id="'.esc_attr($stop['id']).'"' |
|
| 641 | 641 | : ''; |
| 642 | 642 | |
| 643 | 643 | $data_class = empty($data_id) && ! empty($stop['class']) |
| 644 | - ? ' data-class="' . esc_attr($stop['class']) . '"' |
|
| 644 | + ? ' data-class="'.esc_attr($stop['class']).'"' |
|
| 645 | 645 | : ''; |
| 646 | 646 | |
| 647 | 647 | // if container is set to modal then let's make sure we set the options accordingly |
@@ -651,10 +651,10 @@ discard block |
||
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | $custom_class = ! empty($stop['custom_class']) |
| 654 | - ? ' class="' . esc_attr($stop['custom_class']) . '"' |
|
| 654 | + ? ' class="'.esc_attr($stop['custom_class']).'"' |
|
| 655 | 655 | : ''; |
| 656 | 656 | $button_text = ! empty($stop['button_text']) |
| 657 | - ? ' data-button="' . esc_html($stop['button_text']) . '"' |
|
| 657 | + ? ' data-button="'.esc_html($stop['button_text']).'"' |
|
| 658 | 658 | : ''; |
| 659 | 659 | $inner_content = isset($stop['content']) ? wp_kses($stop['content'], $allowedtags) : ''; |
| 660 | 660 | |
@@ -662,7 +662,7 @@ discard block |
||
| 662 | 662 | if (isset($stop['options']) && is_array($stop['options'])) { |
| 663 | 663 | $options = ' data-options="'; |
| 664 | 664 | foreach ($stop['options'] as $option => $value) { |
| 665 | - $options .= esc_attr($option) . ':' . esc_attr($value) . ';'; |
|
| 665 | + $options .= esc_attr($option).':'.esc_attr($value).';'; |
|
| 666 | 666 | } |
| 667 | 667 | $options .= '"'; |
| 668 | 668 | } else { |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | */ |
| 703 | 703 | public static function status_legend($status_array, $active_status = '') |
| 704 | 704 | { |
| 705 | - if (! is_array($status_array)) { |
|
| 705 | + if ( ! is_array($status_array)) { |
|
| 706 | 706 | throw new EE_Error( |
| 707 | 707 | esc_html__( |
| 708 | 708 | 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
@@ -714,17 +714,17 @@ discard block |
||
| 714 | 714 | $content = ' |
| 715 | 715 | <div class="ee-list-table-legend-container"> |
| 716 | 716 | <h4 class="status-legend-title"> |
| 717 | - ' . esc_html__('Status Legend', 'event_espresso') . ' |
|
| 717 | + ' . esc_html__('Status Legend', 'event_espresso').' |
|
| 718 | 718 | </h4> |
| 719 | 719 | <dl class="ee-list-table-legend">'; |
| 720 | 720 | |
| 721 | 721 | foreach ($status_array as $item => $status) { |
| 722 | 722 | $active_class = $active_status == $status ? 'class="ee-is-active-status"' : ''; |
| 723 | - $content .= ' |
|
| 724 | - <dt id="' . esc_attr('ee-legend-item-tooltip-' . $item) . '" ' . $active_class . '> |
|
| 725 | - <span class="' . esc_attr('ee-status-legend ee-status-bg--' . $status) . '"></span> |
|
| 723 | + $content .= ' |
|
| 724 | + <dt id="' . esc_attr('ee-legend-item-tooltip-'.$item).'" '.$active_class.'> |
|
| 725 | + <span class="' . esc_attr('ee-status-legend ee-status-bg--'.$status).'"></span> |
|
| 726 | 726 | <span class="ee-legend-description"> |
| 727 | - ' . EEH_Template::pretty_status($status, false, 'sentence') . ' |
|
| 727 | + ' . EEH_Template::pretty_status($status, false, 'sentence').' |
|
| 728 | 728 | </span> |
| 729 | 729 | </dt>'; |
| 730 | 730 | } |
@@ -870,8 +870,8 @@ discard block |
||
| 870 | 870 | ]; |
| 871 | 871 | } else { |
| 872 | 872 | $items_label = [ |
| 873 | - 'single' => '1 ' . esc_html($items_label['single']), |
|
| 874 | - 'plural' => '%s ' . esc_html($items_label['plural']), |
|
| 873 | + 'single' => '1 '.esc_html($items_label['single']), |
|
| 874 | + 'plural' => '%s '.esc_html($items_label['plural']), |
|
| 875 | 875 | ]; |
| 876 | 876 | } |
| 877 | 877 | |
@@ -883,7 +883,7 @@ discard block |
||
| 883 | 883 | |
| 884 | 884 | $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
| 885 | 885 | |
| 886 | - $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
| 886 | + $output = '<span class="displaying-num">'.$item_label.'</span>'; |
|
| 887 | 887 | |
| 888 | 888 | if ($current === 1) { |
| 889 | 889 | $disable_first = ' disabled'; |
@@ -894,7 +894,7 @@ discard block |
||
| 894 | 894 | |
| 895 | 895 | $page_links[] = sprintf( |
| 896 | 896 | "<a class='%s' title='%s' href='%s'>%s</a>", |
| 897 | - 'first-page' . $disable_first, |
|
| 897 | + 'first-page'.$disable_first, |
|
| 898 | 898 | esc_attr__('Go to the first page', 'event_espresso'), |
| 899 | 899 | esc_url_raw(remove_query_arg($paged_arg_name, $url)), |
| 900 | 900 | '«' |
@@ -902,13 +902,13 @@ discard block |
||
| 902 | 902 | |
| 903 | 903 | $page_links[] = sprintf( |
| 904 | 904 | '<a class="%s" title="%s" href="%s">%s</a>', |
| 905 | - 'prev-page' . $disable_first, |
|
| 905 | + 'prev-page'.$disable_first, |
|
| 906 | 906 | esc_attr__('Go to the previous page', 'event_espresso'), |
| 907 | 907 | esc_url_raw(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
| 908 | 908 | '‹' |
| 909 | 909 | ); |
| 910 | 910 | |
| 911 | - if (! $show_num_field) { |
|
| 911 | + if ( ! $show_num_field) { |
|
| 912 | 912 | $html_current_page = $current; |
| 913 | 913 | } else { |
| 914 | 914 | $html_current_page = sprintf( |
@@ -923,7 +923,7 @@ discard block |
||
| 923 | 923 | '<span class="total-pages">%s</span>', |
| 924 | 924 | number_format_i18n($total_pages) |
| 925 | 925 | ); |
| 926 | - $page_links[] = sprintf( |
|
| 926 | + $page_links[] = sprintf( |
|
| 927 | 927 | _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'), |
| 928 | 928 | $html_current_page, |
| 929 | 929 | $html_total_pages, |
@@ -933,7 +933,7 @@ discard block |
||
| 933 | 933 | |
| 934 | 934 | $page_links[] = sprintf( |
| 935 | 935 | '<a class="%s" title="%s" href="%s">%s</a>', |
| 936 | - 'next-page' . $disable_last, |
|
| 936 | + 'next-page'.$disable_last, |
|
| 937 | 937 | esc_attr__('Go to the next page', 'event_espresso'), |
| 938 | 938 | esc_url_raw(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
| 939 | 939 | '›' |
@@ -941,13 +941,13 @@ discard block |
||
| 941 | 941 | |
| 942 | 942 | $page_links[] = sprintf( |
| 943 | 943 | '<a class="%s" title="%s" href="%s">%s</a>', |
| 944 | - 'last-page' . $disable_last, |
|
| 944 | + 'last-page'.$disable_last, |
|
| 945 | 945 | esc_attr__('Go to the last page', 'event_espresso'), |
| 946 | 946 | esc_url_raw(add_query_arg($paged_arg_name, $total_pages, $url)), |
| 947 | 947 | '»' |
| 948 | 948 | ); |
| 949 | 949 | |
| 950 | - $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
| 950 | + $output .= "\n".'<span class="pagination-links">'.join("\n", $page_links).'</span>'; |
|
| 951 | 951 | // set page class |
| 952 | 952 | if ($total_pages) { |
| 953 | 953 | $page_class = $total_pages < 2 ? ' one-page' : ''; |
@@ -955,7 +955,7 @@ discard block |
||
| 955 | 955 | $page_class = ' no-pages'; |
| 956 | 956 | } |
| 957 | 957 | |
| 958 | - return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
| 958 | + return '<div class="tablenav"><div class="tablenav-pages'.$page_class.'">'.$output.'</div></div>'; |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | |
@@ -993,7 +993,7 @@ discard block |
||
| 993 | 993 | ); |
| 994 | 994 | $powered_by = apply_filters( |
| 995 | 995 | 'FHEE__EEH_Template__powered_by_event_espresso_text', |
| 996 | - $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
| 996 | + $admin ? 'Event Espresso - '.EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
| 997 | 997 | ); |
| 998 | 998 | $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
| 999 | 999 | $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
@@ -1022,12 +1022,12 @@ discard block |
||
| 1022 | 1022 | */ |
| 1023 | 1023 | public static function getScreenshotUrl($image_name) |
| 1024 | 1024 | { |
| 1025 | - return esc_url_raw(EE_GLOBAL_ASSETS_URL . 'images/screenshots/' . $image_name . '.jpg'); |
|
| 1025 | + return esc_url_raw(EE_GLOBAL_ASSETS_URL.'images/screenshots/'.$image_name.'.jpg'); |
|
| 1026 | 1026 | } |
| 1027 | 1027 | } |
| 1028 | 1028 | |
| 1029 | 1029 | |
| 1030 | -if (! function_exists('espresso_pagination')) { |
|
| 1030 | +if ( ! function_exists('espresso_pagination')) { |
|
| 1031 | 1031 | /** |
| 1032 | 1032 | * espresso_pagination |
| 1033 | 1033 | * |
@@ -1055,6 +1055,6 @@ discard block |
||
| 1055 | 1055 | 'add_fragment' => '', |
| 1056 | 1056 | ] |
| 1057 | 1057 | ); |
| 1058 | - echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
| 1058 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : ''; |
|
| 1059 | 1059 | } |
| 1060 | 1060 | } |
@@ -13,124 +13,124 @@ |
||
| 13 | 13 | class Extend_EE_Registrations_List_Table extends EE_Registrations_List_Table |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @param EE_Registration $registration |
|
| 18 | - * @return string |
|
| 19 | - * @throws EE_Error |
|
| 20 | - * @throws InvalidArgumentException |
|
| 21 | - * @throws ReflectionException |
|
| 22 | - * @throws InvalidDataTypeException |
|
| 23 | - * @throws InvalidInterfaceException |
|
| 24 | - */ |
|
| 25 | - public function column__REG_date(EE_Registration $registration, $prep_content = true) |
|
| 26 | - { |
|
| 27 | - $date_linked = parent::column__REG_date($registration, false); |
|
| 28 | - $actions = array(); |
|
| 29 | - // Build row actions |
|
| 30 | - $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 31 | - 'action' => 'event_registrations', |
|
| 32 | - 'event_id' => $registration->event_ID(), |
|
| 33 | - ), REG_ADMIN_URL); |
|
| 34 | - $actions['check_in'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 35 | - 'ee_read_registration', |
|
| 36 | - 'espresso_registrations_registration_checkins', |
|
| 37 | - $registration->ID() |
|
| 38 | - ) && EE_Registry::instance()->CAP->current_user_can( |
|
| 39 | - 'ee_read_checkins', |
|
| 40 | - 'espresso_registrations_registration_checkins' |
|
| 41 | - ) |
|
| 42 | - ? ' |
|
| 16 | + /** |
|
| 17 | + * @param EE_Registration $registration |
|
| 18 | + * @return string |
|
| 19 | + * @throws EE_Error |
|
| 20 | + * @throws InvalidArgumentException |
|
| 21 | + * @throws ReflectionException |
|
| 22 | + * @throws InvalidDataTypeException |
|
| 23 | + * @throws InvalidInterfaceException |
|
| 24 | + */ |
|
| 25 | + public function column__REG_date(EE_Registration $registration, $prep_content = true) |
|
| 26 | + { |
|
| 27 | + $date_linked = parent::column__REG_date($registration, false); |
|
| 28 | + $actions = array(); |
|
| 29 | + // Build row actions |
|
| 30 | + $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 31 | + 'action' => 'event_registrations', |
|
| 32 | + 'event_id' => $registration->event_ID(), |
|
| 33 | + ), REG_ADMIN_URL); |
|
| 34 | + $actions['check_in'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 35 | + 'ee_read_registration', |
|
| 36 | + 'espresso_registrations_registration_checkins', |
|
| 37 | + $registration->ID() |
|
| 38 | + ) && EE_Registry::instance()->CAP->current_user_can( |
|
| 39 | + 'ee_read_checkins', |
|
| 40 | + 'espresso_registrations_registration_checkins' |
|
| 41 | + ) |
|
| 42 | + ? ' |
|
| 43 | 43 | <a class="ee-aria-tooltip ee-event-filter-link" href="' . $check_in_url . '"' |
| 44 | - . ' aria-label="' . esc_attr__( |
|
| 45 | - 'The Check-In List allows you to easily toggle check-in status for this event', |
|
| 46 | - 'event_espresso' |
|
| 47 | - ) |
|
| 48 | - . '"> |
|
| 44 | + . ' aria-label="' . esc_attr__( |
|
| 45 | + 'The Check-In List allows you to easily toggle check-in status for this event', |
|
| 46 | + 'event_espresso' |
|
| 47 | + ) |
|
| 48 | + . '"> |
|
| 49 | 49 | <span class="dashicons dashicons-groups dashicons--small"></span>' |
| 50 | - . esc_html__('View Check-ins', 'event_espresso') . ' |
|
| 50 | + . esc_html__('View Check-ins', 'event_espresso') . ' |
|
| 51 | 51 | </a>' |
| 52 | - : ''; |
|
| 52 | + : ''; |
|
| 53 | 53 | |
| 54 | - $content = sprintf('%1$s %2$s', $date_linked, $this->row_actions($actions)); |
|
| 54 | + $content = sprintf('%1$s %2$s', $date_linked, $this->row_actions($actions)); |
|
| 55 | 55 | |
| 56 | - return $prep_content ? $this->columnContent('_REG_date', $content) : $content; |
|
| 57 | - } |
|
| 56 | + return $prep_content ? $this->columnContent('_REG_date', $content) : $content; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * column_default |
|
| 62 | - * |
|
| 63 | - * @param \EE_Registration $registration |
|
| 64 | - * @return string |
|
| 65 | - * @throws EE_Error |
|
| 66 | - * @throws InvalidArgumentException |
|
| 67 | - * @throws InvalidDataTypeException |
|
| 68 | - * @throws InvalidInterfaceException |
|
| 69 | - * @throws ReflectionException |
|
| 70 | - */ |
|
| 71 | - public function column_DTT_EVT_start(EE_Registration $registration) |
|
| 72 | - { |
|
| 73 | - $remove_defaults = array('default_where_conditions' => 'none'); |
|
| 74 | - $ticket = $registration->ticket(); |
|
| 75 | - $datetimes = $ticket instanceof EE_Ticket ? $ticket->datetimes($remove_defaults) : array(); |
|
| 76 | - $EVT_ID = $registration->event_ID(); |
|
| 77 | - $datetimes_for_display = array(); |
|
| 78 | - foreach ($datetimes as $datetime) { |
|
| 79 | - $datetime_string = '<div class="ee-reg-list-dates-list-date">'; |
|
| 80 | - if ( |
|
| 81 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 82 | - 'ee_read_checkin', |
|
| 83 | - 'espresso_registrations_registration_checkins', |
|
| 84 | - $registration->ID() |
|
| 85 | - ) |
|
| 86 | - ) { |
|
| 87 | - $checkins_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 88 | - [ |
|
| 89 | - 'action' => 'event_registrations', |
|
| 90 | - 'event_id' => $EVT_ID, |
|
| 91 | - 'DTT_ID' => $datetime->ID(), |
|
| 92 | - ], |
|
| 93 | - REG_ADMIN_URL |
|
| 94 | - ); |
|
| 95 | - // open "a" tag and "href" |
|
| 96 | - $datetime_string .= ' |
|
| 60 | + /** |
|
| 61 | + * column_default |
|
| 62 | + * |
|
| 63 | + * @param \EE_Registration $registration |
|
| 64 | + * @return string |
|
| 65 | + * @throws EE_Error |
|
| 66 | + * @throws InvalidArgumentException |
|
| 67 | + * @throws InvalidDataTypeException |
|
| 68 | + * @throws InvalidInterfaceException |
|
| 69 | + * @throws ReflectionException |
|
| 70 | + */ |
|
| 71 | + public function column_DTT_EVT_start(EE_Registration $registration) |
|
| 72 | + { |
|
| 73 | + $remove_defaults = array('default_where_conditions' => 'none'); |
|
| 74 | + $ticket = $registration->ticket(); |
|
| 75 | + $datetimes = $ticket instanceof EE_Ticket ? $ticket->datetimes($remove_defaults) : array(); |
|
| 76 | + $EVT_ID = $registration->event_ID(); |
|
| 77 | + $datetimes_for_display = array(); |
|
| 78 | + foreach ($datetimes as $datetime) { |
|
| 79 | + $datetime_string = '<div class="ee-reg-list-dates-list-date">'; |
|
| 80 | + if ( |
|
| 81 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 82 | + 'ee_read_checkin', |
|
| 83 | + 'espresso_registrations_registration_checkins', |
|
| 84 | + $registration->ID() |
|
| 85 | + ) |
|
| 86 | + ) { |
|
| 87 | + $checkins_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 88 | + [ |
|
| 89 | + 'action' => 'event_registrations', |
|
| 90 | + 'event_id' => $EVT_ID, |
|
| 91 | + 'DTT_ID' => $datetime->ID(), |
|
| 92 | + ], |
|
| 93 | + REG_ADMIN_URL |
|
| 94 | + ); |
|
| 95 | + // open "a" tag and "href" |
|
| 96 | + $datetime_string .= ' |
|
| 97 | 97 | <a class="ee-aria-tooltip ee-status-color--' . $datetime->get_active_status() . '" |
| 98 | 98 | href="' . $checkins_url . '" |
| 99 | 99 | aria-label="' . esc_attr__('View Checkins for this Event', 'event_espresso') . '" |
| 100 | 100 | > |
| 101 | 101 | ' . $datetime->get_i18n_datetime('DTT_EVT_start', 'M jS Y g:i a') . ' |
| 102 | 102 | </a>'; |
| 103 | - } else { |
|
| 104 | - $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start', 'M jS Y g:i a'); |
|
| 105 | - } |
|
| 106 | - // add a "View Registrations" link that filters list by event AND datetime |
|
| 107 | - $filter_list_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 108 | - ['event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()], |
|
| 109 | - REG_ADMIN_URL |
|
| 110 | - ); |
|
| 111 | - $datetime_string .= $this->row_actions( |
|
| 112 | - array( |
|
| 113 | - 'event_datetime_filter' => ' |
|
| 103 | + } else { |
|
| 104 | + $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start', 'M jS Y g:i a'); |
|
| 105 | + } |
|
| 106 | + // add a "View Registrations" link that filters list by event AND datetime |
|
| 107 | + $filter_list_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 108 | + ['event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()], |
|
| 109 | + REG_ADMIN_URL |
|
| 110 | + ); |
|
| 111 | + $datetime_string .= $this->row_actions( |
|
| 112 | + array( |
|
| 113 | + 'event_datetime_filter' => ' |
|
| 114 | 114 | <a class="ee-aria-tooltip ee-event-filter-link" |
| 115 | 115 | href="' . $filter_list_url . '" |
| 116 | 116 | aria-label="' . sprintf( |
| 117 | - esc_attr__( |
|
| 118 | - 'Filter this list to only show registrations for this datetime %s', |
|
| 119 | - 'event_espresso' |
|
| 120 | - ), |
|
| 121 | - $datetime->name() |
|
| 122 | - ) . '"> |
|
| 117 | + esc_attr__( |
|
| 118 | + 'Filter this list to only show registrations for this datetime %s', |
|
| 119 | + 'event_espresso' |
|
| 120 | + ), |
|
| 121 | + $datetime->name() |
|
| 122 | + ) . '"> |
|
| 123 | 123 | <span class="dashicons dashicons-groups dashicons--small"></span> |
| 124 | 124 | </a>', |
| 125 | - ) |
|
| 126 | - ); |
|
| 127 | - // ' . esc_html__('View Registrations', 'event_espresso') . ' |
|
| 128 | - $datetime_string .= '</div>'; |
|
| 129 | - $datetimes_for_display[] = $datetime_string; |
|
| 130 | - } |
|
| 131 | - return $this->columnContent( |
|
| 132 | - 'DTT_EVT_start', |
|
| 133 | - $this->generateDisplayForDateTimes($datetimes_for_display) |
|
| 134 | - ); |
|
| 135 | - } |
|
| 125 | + ) |
|
| 126 | + ); |
|
| 127 | + // ' . esc_html__('View Registrations', 'event_espresso') . ' |
|
| 128 | + $datetime_string .= '</div>'; |
|
| 129 | + $datetimes_for_display[] = $datetime_string; |
|
| 130 | + } |
|
| 131 | + return $this->columnContent( |
|
| 132 | + 'DTT_EVT_start', |
|
| 133 | + $this->generateDisplayForDateTimes($datetimes_for_display) |
|
| 134 | + ); |
|
| 135 | + } |
|
| 136 | 136 | } |
@@ -40,14 +40,14 @@ discard block |
||
| 40 | 40 | 'espresso_registrations_registration_checkins' |
| 41 | 41 | ) |
| 42 | 42 | ? ' |
| 43 | - <a class="ee-aria-tooltip ee-event-filter-link" href="' . $check_in_url . '"' |
|
| 44 | - . ' aria-label="' . esc_attr__( |
|
| 43 | + <a class="ee-aria-tooltip ee-event-filter-link" href="' . $check_in_url.'"' |
|
| 44 | + . ' aria-label="'.esc_attr__( |
|
| 45 | 45 | 'The Check-In List allows you to easily toggle check-in status for this event', |
| 46 | 46 | 'event_espresso' |
| 47 | 47 | ) |
| 48 | 48 | . '"> |
| 49 | 49 | <span class="dashicons dashicons-groups dashicons--small"></span>' |
| 50 | - . esc_html__('View Check-ins', 'event_espresso') . ' |
|
| 50 | + . esc_html__('View Check-ins', 'event_espresso').' |
|
| 51 | 51 | </a>' |
| 52 | 52 | : ''; |
| 53 | 53 | |
@@ -94,11 +94,11 @@ discard block |
||
| 94 | 94 | ); |
| 95 | 95 | // open "a" tag and "href" |
| 96 | 96 | $datetime_string .= ' |
| 97 | - <a class="ee-aria-tooltip ee-status-color--' . $datetime->get_active_status() . '" |
|
| 98 | - href="' . $checkins_url . '" |
|
| 99 | - aria-label="' . esc_attr__('View Checkins for this Event', 'event_espresso') . '" |
|
| 97 | + <a class="ee-aria-tooltip ee-status-color--' . $datetime->get_active_status().'" |
|
| 98 | + href="' . $checkins_url.'" |
|
| 99 | + aria-label="' . esc_attr__('View Checkins for this Event', 'event_espresso').'" |
|
| 100 | 100 | > |
| 101 | - ' . $datetime->get_i18n_datetime('DTT_EVT_start', 'M jS Y g:i a') . ' |
|
| 101 | + ' . $datetime->get_i18n_datetime('DTT_EVT_start', 'M jS Y g:i a').' |
|
| 102 | 102 | </a>'; |
| 103 | 103 | } else { |
| 104 | 104 | $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start', 'M jS Y g:i a'); |
@@ -112,14 +112,14 @@ discard block |
||
| 112 | 112 | array( |
| 113 | 113 | 'event_datetime_filter' => ' |
| 114 | 114 | <a class="ee-aria-tooltip ee-event-filter-link" |
| 115 | - href="' . $filter_list_url . '" |
|
| 115 | + href="' . $filter_list_url.'" |
|
| 116 | 116 | aria-label="' . sprintf( |
| 117 | 117 | esc_attr__( |
| 118 | 118 | 'Filter this list to only show registrations for this datetime %s', |
| 119 | 119 | 'event_espresso' |
| 120 | 120 | ), |
| 121 | 121 | $datetime->name() |
| 122 | - ) . '"> |
|
| 122 | + ).'"> |
|
| 123 | 123 | <span class="dashicons dashicons-groups dashicons--small"></span> |
| 124 | 124 | </a>', |
| 125 | 125 | ) |
@@ -16,1278 +16,1278 @@ |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * This is used to hold the reports template data which is setup early in the request. |
|
| 21 | - * |
|
| 22 | - * @type array |
|
| 23 | - */ |
|
| 24 | - protected $_reports_template_data = array(); |
|
| 19 | + /** |
|
| 20 | + * This is used to hold the reports template data which is setup early in the request. |
|
| 21 | + * |
|
| 22 | + * @type array |
|
| 23 | + */ |
|
| 24 | + protected $_reports_template_data = array(); |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Extend_Registrations_Admin_Page constructor. |
|
| 29 | - * |
|
| 30 | - * @param bool $routing |
|
| 31 | - */ |
|
| 32 | - public function __construct($routing = true) |
|
| 33 | - { |
|
| 34 | - parent::__construct($routing); |
|
| 35 | - if (! defined('REG_CAF_TEMPLATE_PATH')) { |
|
| 36 | - define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
| 37 | - define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
| 38 | - define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
| 39 | - } |
|
| 40 | - } |
|
| 27 | + /** |
|
| 28 | + * Extend_Registrations_Admin_Page constructor. |
|
| 29 | + * |
|
| 30 | + * @param bool $routing |
|
| 31 | + */ |
|
| 32 | + public function __construct($routing = true) |
|
| 33 | + { |
|
| 34 | + parent::__construct($routing); |
|
| 35 | + if (! defined('REG_CAF_TEMPLATE_PATH')) { |
|
| 36 | + define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
| 37 | + define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
| 38 | + define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Extending page configuration. |
|
| 45 | - */ |
|
| 46 | - protected function _extend_page_config() |
|
| 47 | - { |
|
| 48 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
| 49 | - $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
| 50 | - ? $this->_req_data['_REG_ID'] |
|
| 51 | - : 0; |
|
| 52 | - $new_page_routes = array( |
|
| 53 | - 'reports' => array( |
|
| 54 | - 'func' => '_registration_reports', |
|
| 55 | - 'capability' => 'ee_read_registrations', |
|
| 56 | - ), |
|
| 57 | - 'registration_checkins' => array( |
|
| 58 | - 'func' => '_registration_checkin_list_table', |
|
| 59 | - 'capability' => 'ee_read_checkins', |
|
| 60 | - ), |
|
| 61 | - 'newsletter_selected_send' => array( |
|
| 62 | - 'func' => '_newsletter_selected_send', |
|
| 63 | - 'noheader' => true, |
|
| 64 | - 'capability' => 'ee_send_message', |
|
| 65 | - ), |
|
| 66 | - 'delete_checkin_rows' => array( |
|
| 67 | - 'func' => '_delete_checkin_rows', |
|
| 68 | - 'noheader' => true, |
|
| 69 | - 'capability' => 'ee_delete_checkins', |
|
| 70 | - ), |
|
| 71 | - 'delete_checkin_row' => array( |
|
| 72 | - 'func' => '_delete_checkin_row', |
|
| 73 | - 'noheader' => true, |
|
| 74 | - 'capability' => 'ee_delete_checkin', |
|
| 75 | - 'obj_id' => $reg_id, |
|
| 76 | - ), |
|
| 77 | - 'toggle_checkin_status' => array( |
|
| 78 | - 'func' => '_toggle_checkin_status', |
|
| 79 | - 'noheader' => true, |
|
| 80 | - 'capability' => 'ee_edit_checkin', |
|
| 81 | - 'obj_id' => $reg_id, |
|
| 82 | - ), |
|
| 83 | - 'toggle_checkin_status_bulk' => array( |
|
| 84 | - 'func' => '_toggle_checkin_status', |
|
| 85 | - 'noheader' => true, |
|
| 86 | - 'capability' => 'ee_edit_checkins', |
|
| 87 | - ), |
|
| 88 | - 'event_registrations' => array( |
|
| 89 | - 'func' => '_event_registrations_list_table', |
|
| 90 | - 'capability' => 'ee_read_checkins', |
|
| 91 | - ), |
|
| 92 | - 'registrations_checkin_report' => array( |
|
| 93 | - 'func' => '_registrations_checkin_report', |
|
| 94 | - 'noheader' => true, |
|
| 95 | - 'capability' => 'ee_read_registrations', |
|
| 96 | - ), |
|
| 97 | - ); |
|
| 98 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 99 | - $new_page_config = array( |
|
| 100 | - 'reports' => array( |
|
| 101 | - 'nav' => array( |
|
| 102 | - 'label' => esc_html__('Reports', 'event_espresso'), |
|
| 103 | - 'order' => 30, |
|
| 104 | - ), |
|
| 105 | - 'help_tabs' => array( |
|
| 106 | - 'registrations_reports_help_tab' => array( |
|
| 107 | - 'title' => esc_html__('Registration Reports', 'event_espresso'), |
|
| 108 | - 'filename' => 'registrations_reports', |
|
| 109 | - ), |
|
| 110 | - ), |
|
| 111 | - /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/ |
|
| 112 | - 'require_nonce' => false, |
|
| 113 | - ), |
|
| 114 | - 'event_registrations' => array( |
|
| 115 | - 'nav' => array( |
|
| 116 | - 'label' => esc_html__('Event Check-In', 'event_espresso'), |
|
| 117 | - 'order' => 10, |
|
| 118 | - 'persistent' => true, |
|
| 119 | - ), |
|
| 120 | - 'help_tabs' => array( |
|
| 121 | - 'registrations_event_checkin_help_tab' => array( |
|
| 122 | - 'title' => esc_html__('Registrations Event Check-In', 'event_espresso'), |
|
| 123 | - 'filename' => 'registrations_event_checkin', |
|
| 124 | - ), |
|
| 125 | - 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
| 126 | - 'title' => esc_html__('Event Check-In Table Column Headings', 'event_espresso'), |
|
| 127 | - 'filename' => 'registrations_event_checkin_table_column_headings', |
|
| 128 | - ), |
|
| 129 | - 'registrations_event_checkin_filters_help_tab' => array( |
|
| 130 | - 'title' => esc_html__('Event Check-In Filters', 'event_espresso'), |
|
| 131 | - 'filename' => 'registrations_event_checkin_filters', |
|
| 132 | - ), |
|
| 133 | - 'registrations_event_checkin_views_help_tab' => array( |
|
| 134 | - 'title' => esc_html__('Event Check-In Views', 'event_espresso'), |
|
| 135 | - 'filename' => 'registrations_event_checkin_views', |
|
| 136 | - ), |
|
| 137 | - 'registrations_event_checkin_other_help_tab' => array( |
|
| 138 | - 'title' => esc_html__('Event Check-In Other', 'event_espresso'), |
|
| 139 | - 'filename' => 'registrations_event_checkin_other', |
|
| 140 | - ), |
|
| 141 | - ), |
|
| 142 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 143 | - // 'help_tour' => array('Event_Checkin_Help_Tour'), |
|
| 144 | - 'qtips' => array('Registration_List_Table_Tips'), |
|
| 145 | - 'list_table' => 'EE_Event_Registrations_List_Table', |
|
| 146 | - 'metaboxes' => array(), |
|
| 147 | - 'require_nonce' => false, |
|
| 148 | - ), |
|
| 149 | - 'registration_checkins' => array( |
|
| 150 | - 'nav' => array( |
|
| 151 | - 'label' => esc_html__('Check-In Records', 'event_espresso'), |
|
| 152 | - 'order' => 15, |
|
| 153 | - 'persistent' => false, |
|
| 154 | - 'url' => '', |
|
| 155 | - ), |
|
| 156 | - 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
| 157 | - // 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ), |
|
| 158 | - 'metaboxes' => array(), |
|
| 159 | - 'require_nonce' => false, |
|
| 160 | - ), |
|
| 161 | - ); |
|
| 162 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 163 | - $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
| 164 | - $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
| 165 | - } |
|
| 43 | + /** |
|
| 44 | + * Extending page configuration. |
|
| 45 | + */ |
|
| 46 | + protected function _extend_page_config() |
|
| 47 | + { |
|
| 48 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
| 49 | + $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
| 50 | + ? $this->_req_data['_REG_ID'] |
|
| 51 | + : 0; |
|
| 52 | + $new_page_routes = array( |
|
| 53 | + 'reports' => array( |
|
| 54 | + 'func' => '_registration_reports', |
|
| 55 | + 'capability' => 'ee_read_registrations', |
|
| 56 | + ), |
|
| 57 | + 'registration_checkins' => array( |
|
| 58 | + 'func' => '_registration_checkin_list_table', |
|
| 59 | + 'capability' => 'ee_read_checkins', |
|
| 60 | + ), |
|
| 61 | + 'newsletter_selected_send' => array( |
|
| 62 | + 'func' => '_newsletter_selected_send', |
|
| 63 | + 'noheader' => true, |
|
| 64 | + 'capability' => 'ee_send_message', |
|
| 65 | + ), |
|
| 66 | + 'delete_checkin_rows' => array( |
|
| 67 | + 'func' => '_delete_checkin_rows', |
|
| 68 | + 'noheader' => true, |
|
| 69 | + 'capability' => 'ee_delete_checkins', |
|
| 70 | + ), |
|
| 71 | + 'delete_checkin_row' => array( |
|
| 72 | + 'func' => '_delete_checkin_row', |
|
| 73 | + 'noheader' => true, |
|
| 74 | + 'capability' => 'ee_delete_checkin', |
|
| 75 | + 'obj_id' => $reg_id, |
|
| 76 | + ), |
|
| 77 | + 'toggle_checkin_status' => array( |
|
| 78 | + 'func' => '_toggle_checkin_status', |
|
| 79 | + 'noheader' => true, |
|
| 80 | + 'capability' => 'ee_edit_checkin', |
|
| 81 | + 'obj_id' => $reg_id, |
|
| 82 | + ), |
|
| 83 | + 'toggle_checkin_status_bulk' => array( |
|
| 84 | + 'func' => '_toggle_checkin_status', |
|
| 85 | + 'noheader' => true, |
|
| 86 | + 'capability' => 'ee_edit_checkins', |
|
| 87 | + ), |
|
| 88 | + 'event_registrations' => array( |
|
| 89 | + 'func' => '_event_registrations_list_table', |
|
| 90 | + 'capability' => 'ee_read_checkins', |
|
| 91 | + ), |
|
| 92 | + 'registrations_checkin_report' => array( |
|
| 93 | + 'func' => '_registrations_checkin_report', |
|
| 94 | + 'noheader' => true, |
|
| 95 | + 'capability' => 'ee_read_registrations', |
|
| 96 | + ), |
|
| 97 | + ); |
|
| 98 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 99 | + $new_page_config = array( |
|
| 100 | + 'reports' => array( |
|
| 101 | + 'nav' => array( |
|
| 102 | + 'label' => esc_html__('Reports', 'event_espresso'), |
|
| 103 | + 'order' => 30, |
|
| 104 | + ), |
|
| 105 | + 'help_tabs' => array( |
|
| 106 | + 'registrations_reports_help_tab' => array( |
|
| 107 | + 'title' => esc_html__('Registration Reports', 'event_espresso'), |
|
| 108 | + 'filename' => 'registrations_reports', |
|
| 109 | + ), |
|
| 110 | + ), |
|
| 111 | + /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/ |
|
| 112 | + 'require_nonce' => false, |
|
| 113 | + ), |
|
| 114 | + 'event_registrations' => array( |
|
| 115 | + 'nav' => array( |
|
| 116 | + 'label' => esc_html__('Event Check-In', 'event_espresso'), |
|
| 117 | + 'order' => 10, |
|
| 118 | + 'persistent' => true, |
|
| 119 | + ), |
|
| 120 | + 'help_tabs' => array( |
|
| 121 | + 'registrations_event_checkin_help_tab' => array( |
|
| 122 | + 'title' => esc_html__('Registrations Event Check-In', 'event_espresso'), |
|
| 123 | + 'filename' => 'registrations_event_checkin', |
|
| 124 | + ), |
|
| 125 | + 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
| 126 | + 'title' => esc_html__('Event Check-In Table Column Headings', 'event_espresso'), |
|
| 127 | + 'filename' => 'registrations_event_checkin_table_column_headings', |
|
| 128 | + ), |
|
| 129 | + 'registrations_event_checkin_filters_help_tab' => array( |
|
| 130 | + 'title' => esc_html__('Event Check-In Filters', 'event_espresso'), |
|
| 131 | + 'filename' => 'registrations_event_checkin_filters', |
|
| 132 | + ), |
|
| 133 | + 'registrations_event_checkin_views_help_tab' => array( |
|
| 134 | + 'title' => esc_html__('Event Check-In Views', 'event_espresso'), |
|
| 135 | + 'filename' => 'registrations_event_checkin_views', |
|
| 136 | + ), |
|
| 137 | + 'registrations_event_checkin_other_help_tab' => array( |
|
| 138 | + 'title' => esc_html__('Event Check-In Other', 'event_espresso'), |
|
| 139 | + 'filename' => 'registrations_event_checkin_other', |
|
| 140 | + ), |
|
| 141 | + ), |
|
| 142 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 143 | + // 'help_tour' => array('Event_Checkin_Help_Tour'), |
|
| 144 | + 'qtips' => array('Registration_List_Table_Tips'), |
|
| 145 | + 'list_table' => 'EE_Event_Registrations_List_Table', |
|
| 146 | + 'metaboxes' => array(), |
|
| 147 | + 'require_nonce' => false, |
|
| 148 | + ), |
|
| 149 | + 'registration_checkins' => array( |
|
| 150 | + 'nav' => array( |
|
| 151 | + 'label' => esc_html__('Check-In Records', 'event_espresso'), |
|
| 152 | + 'order' => 15, |
|
| 153 | + 'persistent' => false, |
|
| 154 | + 'url' => '', |
|
| 155 | + ), |
|
| 156 | + 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
| 157 | + // 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ), |
|
| 158 | + 'metaboxes' => array(), |
|
| 159 | + 'require_nonce' => false, |
|
| 160 | + ), |
|
| 161 | + ); |
|
| 162 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 163 | + $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
| 164 | + $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * Ajax hooks for all routes in this page. |
|
| 170 | - */ |
|
| 171 | - protected function _ajax_hooks() |
|
| 172 | - { |
|
| 173 | - parent::_ajax_hooks(); |
|
| 174 | - add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
| 175 | - } |
|
| 168 | + /** |
|
| 169 | + * Ajax hooks for all routes in this page. |
|
| 170 | + */ |
|
| 171 | + protected function _ajax_hooks() |
|
| 172 | + { |
|
| 173 | + parent::_ajax_hooks(); |
|
| 174 | + add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * Global scripts for all routes in this page. |
|
| 180 | - */ |
|
| 181 | - public function load_scripts_styles() |
|
| 182 | - { |
|
| 183 | - parent::load_scripts_styles(); |
|
| 184 | - // if newsletter message type is active then let's add filter and load js for it. |
|
| 185 | - if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
| 186 | - // enqueue newsletter js |
|
| 187 | - wp_enqueue_script( |
|
| 188 | - 'ee-newsletter-trigger', |
|
| 189 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
| 190 | - array('ee-dialog'), |
|
| 191 | - EVENT_ESPRESSO_VERSION, |
|
| 192 | - true |
|
| 193 | - ); |
|
| 194 | - wp_enqueue_style( |
|
| 195 | - 'ee-newsletter-trigger-css', |
|
| 196 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
| 197 | - array(), |
|
| 198 | - EVENT_ESPRESSO_VERSION |
|
| 199 | - ); |
|
| 200 | - // hook in buttons for newsletter message type trigger. |
|
| 201 | - add_action( |
|
| 202 | - 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
| 203 | - array($this, 'add_newsletter_action_buttons'), |
|
| 204 | - 10 |
|
| 205 | - ); |
|
| 206 | - } |
|
| 207 | - } |
|
| 178 | + /** |
|
| 179 | + * Global scripts for all routes in this page. |
|
| 180 | + */ |
|
| 181 | + public function load_scripts_styles() |
|
| 182 | + { |
|
| 183 | + parent::load_scripts_styles(); |
|
| 184 | + // if newsletter message type is active then let's add filter and load js for it. |
|
| 185 | + if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
| 186 | + // enqueue newsletter js |
|
| 187 | + wp_enqueue_script( |
|
| 188 | + 'ee-newsletter-trigger', |
|
| 189 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
| 190 | + array('ee-dialog'), |
|
| 191 | + EVENT_ESPRESSO_VERSION, |
|
| 192 | + true |
|
| 193 | + ); |
|
| 194 | + wp_enqueue_style( |
|
| 195 | + 'ee-newsletter-trigger-css', |
|
| 196 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
| 197 | + array(), |
|
| 198 | + EVENT_ESPRESSO_VERSION |
|
| 199 | + ); |
|
| 200 | + // hook in buttons for newsletter message type trigger. |
|
| 201 | + add_action( |
|
| 202 | + 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
| 203 | + array($this, 'add_newsletter_action_buttons'), |
|
| 204 | + 10 |
|
| 205 | + ); |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * Scripts and styles for just the reports route. |
|
| 212 | - */ |
|
| 213 | - public function load_scripts_styles_reports() |
|
| 214 | - { |
|
| 215 | - wp_register_script( |
|
| 216 | - 'ee-reg-reports-js', |
|
| 217 | - REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
| 218 | - array('google-charts'), |
|
| 219 | - EVENT_ESPRESSO_VERSION, |
|
| 220 | - true |
|
| 221 | - ); |
|
| 222 | - wp_enqueue_script('ee-reg-reports-js'); |
|
| 223 | - $this->_registration_reports_js_setup(); |
|
| 224 | - } |
|
| 210 | + /** |
|
| 211 | + * Scripts and styles for just the reports route. |
|
| 212 | + */ |
|
| 213 | + public function load_scripts_styles_reports() |
|
| 214 | + { |
|
| 215 | + wp_register_script( |
|
| 216 | + 'ee-reg-reports-js', |
|
| 217 | + REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
| 218 | + array('google-charts'), |
|
| 219 | + EVENT_ESPRESSO_VERSION, |
|
| 220 | + true |
|
| 221 | + ); |
|
| 222 | + wp_enqueue_script('ee-reg-reports-js'); |
|
| 223 | + $this->_registration_reports_js_setup(); |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | 226 | |
| 227 | - /** |
|
| 228 | - * Register screen options for event_registrations route. |
|
| 229 | - */ |
|
| 230 | - protected function _add_screen_options_event_registrations() |
|
| 231 | - { |
|
| 232 | - $this->_per_page_screen_option(); |
|
| 233 | - } |
|
| 227 | + /** |
|
| 228 | + * Register screen options for event_registrations route. |
|
| 229 | + */ |
|
| 230 | + protected function _add_screen_options_event_registrations() |
|
| 231 | + { |
|
| 232 | + $this->_per_page_screen_option(); |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | 235 | |
| 236 | - /** |
|
| 237 | - * Register screen options for registration_checkins route |
|
| 238 | - */ |
|
| 239 | - protected function _add_screen_options_registration_checkins() |
|
| 240 | - { |
|
| 241 | - $page_title = $this->_admin_page_title; |
|
| 242 | - $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso'); |
|
| 243 | - $this->_per_page_screen_option(); |
|
| 244 | - $this->_admin_page_title = $page_title; |
|
| 245 | - } |
|
| 236 | + /** |
|
| 237 | + * Register screen options for registration_checkins route |
|
| 238 | + */ |
|
| 239 | + protected function _add_screen_options_registration_checkins() |
|
| 240 | + { |
|
| 241 | + $page_title = $this->_admin_page_title; |
|
| 242 | + $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso'); |
|
| 243 | + $this->_per_page_screen_option(); |
|
| 244 | + $this->_admin_page_title = $page_title; |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | 247 | |
| 248 | - /** |
|
| 249 | - * Set views property for event_registrations route. |
|
| 250 | - */ |
|
| 251 | - protected function _set_list_table_views_event_registrations() |
|
| 252 | - { |
|
| 253 | - $this->_views = array( |
|
| 254 | - 'all' => array( |
|
| 255 | - 'slug' => 'all', |
|
| 256 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 257 | - 'count' => 0, |
|
| 258 | - 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
| 259 | - ? array() |
|
| 260 | - : array( |
|
| 261 | - 'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'), |
|
| 262 | - ), |
|
| 263 | - ), |
|
| 264 | - ); |
|
| 265 | - } |
|
| 248 | + /** |
|
| 249 | + * Set views property for event_registrations route. |
|
| 250 | + */ |
|
| 251 | + protected function _set_list_table_views_event_registrations() |
|
| 252 | + { |
|
| 253 | + $this->_views = array( |
|
| 254 | + 'all' => array( |
|
| 255 | + 'slug' => 'all', |
|
| 256 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 257 | + 'count' => 0, |
|
| 258 | + 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
| 259 | + ? array() |
|
| 260 | + : array( |
|
| 261 | + 'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'), |
|
| 262 | + ), |
|
| 263 | + ), |
|
| 264 | + ); |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | 267 | |
| 268 | - /** |
|
| 269 | - * Set views property for registration_checkins route. |
|
| 270 | - */ |
|
| 271 | - protected function _set_list_table_views_registration_checkins() |
|
| 272 | - { |
|
| 273 | - $this->_views = array( |
|
| 274 | - 'all' => array( |
|
| 275 | - 'slug' => 'all', |
|
| 276 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 277 | - 'count' => 0, |
|
| 278 | - 'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')), |
|
| 279 | - ), |
|
| 280 | - ); |
|
| 281 | - } |
|
| 268 | + /** |
|
| 269 | + * Set views property for registration_checkins route. |
|
| 270 | + */ |
|
| 271 | + protected function _set_list_table_views_registration_checkins() |
|
| 272 | + { |
|
| 273 | + $this->_views = array( |
|
| 274 | + 'all' => array( |
|
| 275 | + 'slug' => 'all', |
|
| 276 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 277 | + 'count' => 0, |
|
| 278 | + 'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')), |
|
| 279 | + ), |
|
| 280 | + ); |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | 283 | |
| 284 | - /** |
|
| 285 | - * callback for ajax action. |
|
| 286 | - * |
|
| 287 | - * @since 4.3.0 |
|
| 288 | - * @return void (JSON) |
|
| 289 | - * @throws EE_Error |
|
| 290 | - * @throws InvalidArgumentException |
|
| 291 | - * @throws InvalidDataTypeException |
|
| 292 | - * @throws InvalidInterfaceException |
|
| 293 | - */ |
|
| 294 | - public function get_newsletter_form_content() |
|
| 295 | - { |
|
| 296 | - // do a nonce check cause we're not coming in from an normal route here. |
|
| 297 | - $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
| 298 | - $this->_req_data['get_newsletter_form_content_nonce'] |
|
| 299 | - ) : ''; |
|
| 300 | - $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
| 301 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 302 | - // let's get the mtp for the incoming MTP_ ID |
|
| 303 | - if (! isset($this->_req_data['GRP_ID'])) { |
|
| 304 | - EE_Error::add_error( |
|
| 305 | - esc_html__( |
|
| 306 | - 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
| 307 | - 'event_espresso' |
|
| 308 | - ), |
|
| 309 | - __FILE__, |
|
| 310 | - __FUNCTION__, |
|
| 311 | - __LINE__ |
|
| 312 | - ); |
|
| 313 | - $this->_template_args['success'] = false; |
|
| 314 | - $this->_template_args['error'] = true; |
|
| 315 | - $this->_return_json(); |
|
| 316 | - } |
|
| 317 | - $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
| 318 | - if (! $MTPG instanceof EE_Message_Template_Group) { |
|
| 319 | - EE_Error::add_error( |
|
| 320 | - sprintf( |
|
| 321 | - esc_html__( |
|
| 322 | - 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
| 323 | - 'event_espresso' |
|
| 324 | - ), |
|
| 325 | - $this->_req_data['GRP_ID'] |
|
| 326 | - ), |
|
| 327 | - __FILE__, |
|
| 328 | - __FUNCTION__, |
|
| 329 | - __LINE__ |
|
| 330 | - ); |
|
| 331 | - $this->_template_args['success'] = false; |
|
| 332 | - $this->_template_args['error'] = true; |
|
| 333 | - $this->_return_json(); |
|
| 334 | - } |
|
| 335 | - $MTPs = $MTPG->context_templates(); |
|
| 336 | - $MTPs = $MTPs['attendee']; |
|
| 337 | - $template_fields = array(); |
|
| 338 | - /** @var EE_Message_Template $MTP */ |
|
| 339 | - foreach ($MTPs as $MTP) { |
|
| 340 | - $field = $MTP->get('MTP_template_field'); |
|
| 341 | - if ($field === 'content') { |
|
| 342 | - $content = $MTP->get('MTP_content'); |
|
| 343 | - if (! empty($content['newsletter_content'])) { |
|
| 344 | - $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
| 345 | - } |
|
| 346 | - continue; |
|
| 347 | - } |
|
| 348 | - $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content'); |
|
| 349 | - } |
|
| 350 | - $this->_template_args['success'] = true; |
|
| 351 | - $this->_template_args['error'] = false; |
|
| 352 | - $this->_template_args['data'] = array( |
|
| 353 | - 'batch_message_from' => isset($template_fields['from']) |
|
| 354 | - ? $template_fields['from'] |
|
| 355 | - : '', |
|
| 356 | - 'batch_message_subject' => isset($template_fields['subject']) |
|
| 357 | - ? $template_fields['subject'] |
|
| 358 | - : '', |
|
| 359 | - 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
| 360 | - ? $template_fields['newsletter_content'] |
|
| 361 | - : '', |
|
| 362 | - ); |
|
| 363 | - $this->_return_json(); |
|
| 364 | - } |
|
| 284 | + /** |
|
| 285 | + * callback for ajax action. |
|
| 286 | + * |
|
| 287 | + * @since 4.3.0 |
|
| 288 | + * @return void (JSON) |
|
| 289 | + * @throws EE_Error |
|
| 290 | + * @throws InvalidArgumentException |
|
| 291 | + * @throws InvalidDataTypeException |
|
| 292 | + * @throws InvalidInterfaceException |
|
| 293 | + */ |
|
| 294 | + public function get_newsletter_form_content() |
|
| 295 | + { |
|
| 296 | + // do a nonce check cause we're not coming in from an normal route here. |
|
| 297 | + $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
| 298 | + $this->_req_data['get_newsletter_form_content_nonce'] |
|
| 299 | + ) : ''; |
|
| 300 | + $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
| 301 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 302 | + // let's get the mtp for the incoming MTP_ ID |
|
| 303 | + if (! isset($this->_req_data['GRP_ID'])) { |
|
| 304 | + EE_Error::add_error( |
|
| 305 | + esc_html__( |
|
| 306 | + 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
| 307 | + 'event_espresso' |
|
| 308 | + ), |
|
| 309 | + __FILE__, |
|
| 310 | + __FUNCTION__, |
|
| 311 | + __LINE__ |
|
| 312 | + ); |
|
| 313 | + $this->_template_args['success'] = false; |
|
| 314 | + $this->_template_args['error'] = true; |
|
| 315 | + $this->_return_json(); |
|
| 316 | + } |
|
| 317 | + $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
| 318 | + if (! $MTPG instanceof EE_Message_Template_Group) { |
|
| 319 | + EE_Error::add_error( |
|
| 320 | + sprintf( |
|
| 321 | + esc_html__( |
|
| 322 | + 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
| 323 | + 'event_espresso' |
|
| 324 | + ), |
|
| 325 | + $this->_req_data['GRP_ID'] |
|
| 326 | + ), |
|
| 327 | + __FILE__, |
|
| 328 | + __FUNCTION__, |
|
| 329 | + __LINE__ |
|
| 330 | + ); |
|
| 331 | + $this->_template_args['success'] = false; |
|
| 332 | + $this->_template_args['error'] = true; |
|
| 333 | + $this->_return_json(); |
|
| 334 | + } |
|
| 335 | + $MTPs = $MTPG->context_templates(); |
|
| 336 | + $MTPs = $MTPs['attendee']; |
|
| 337 | + $template_fields = array(); |
|
| 338 | + /** @var EE_Message_Template $MTP */ |
|
| 339 | + foreach ($MTPs as $MTP) { |
|
| 340 | + $field = $MTP->get('MTP_template_field'); |
|
| 341 | + if ($field === 'content') { |
|
| 342 | + $content = $MTP->get('MTP_content'); |
|
| 343 | + if (! empty($content['newsletter_content'])) { |
|
| 344 | + $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
| 345 | + } |
|
| 346 | + continue; |
|
| 347 | + } |
|
| 348 | + $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content'); |
|
| 349 | + } |
|
| 350 | + $this->_template_args['success'] = true; |
|
| 351 | + $this->_template_args['error'] = false; |
|
| 352 | + $this->_template_args['data'] = array( |
|
| 353 | + 'batch_message_from' => isset($template_fields['from']) |
|
| 354 | + ? $template_fields['from'] |
|
| 355 | + : '', |
|
| 356 | + 'batch_message_subject' => isset($template_fields['subject']) |
|
| 357 | + ? $template_fields['subject'] |
|
| 358 | + : '', |
|
| 359 | + 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
| 360 | + ? $template_fields['newsletter_content'] |
|
| 361 | + : '', |
|
| 362 | + ); |
|
| 363 | + $this->_return_json(); |
|
| 364 | + } |
|
| 365 | 365 | |
| 366 | 366 | |
| 367 | - /** |
|
| 368 | - * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
| 369 | - * |
|
| 370 | - * @since 4.3.0 |
|
| 371 | - * @param EE_Admin_List_Table $list_table |
|
| 372 | - * @return void |
|
| 373 | - * @throws InvalidArgumentException |
|
| 374 | - * @throws InvalidDataTypeException |
|
| 375 | - * @throws InvalidInterfaceException |
|
| 376 | - */ |
|
| 377 | - public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
| 378 | - { |
|
| 379 | - if ( |
|
| 380 | - ! EE_Registry::instance()->CAP->current_user_can( |
|
| 381 | - 'ee_send_message', |
|
| 382 | - 'espresso_registrations_newsletter_selected_send' |
|
| 383 | - ) |
|
| 384 | - ) { |
|
| 385 | - return; |
|
| 386 | - } |
|
| 387 | - $routes_to_add_to = array( |
|
| 388 | - 'contact_list', |
|
| 389 | - 'event_registrations', |
|
| 390 | - 'default', |
|
| 391 | - ); |
|
| 392 | - if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
| 393 | - if ( |
|
| 394 | - ($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
| 395 | - || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
| 396 | - ) { |
|
| 397 | - echo ''; |
|
| 398 | - } else { |
|
| 399 | - $button_text = sprintf( |
|
| 400 | - esc_html__('Send Batch Message (%s selected)', 'event_espresso'), |
|
| 401 | - '<span class="send-selected-newsletter-count">0</span>' |
|
| 402 | - ); |
|
| 403 | - echo '<button id="selected-batch-send-trigger" class="button button--secondary">' |
|
| 404 | - . '<span class="dashicons dashicons-email "></span>' |
|
| 405 | - . $button_text |
|
| 406 | - . '</button>'; |
|
| 407 | - add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
| 408 | - } |
|
| 409 | - } |
|
| 410 | - } |
|
| 367 | + /** |
|
| 368 | + * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
| 369 | + * |
|
| 370 | + * @since 4.3.0 |
|
| 371 | + * @param EE_Admin_List_Table $list_table |
|
| 372 | + * @return void |
|
| 373 | + * @throws InvalidArgumentException |
|
| 374 | + * @throws InvalidDataTypeException |
|
| 375 | + * @throws InvalidInterfaceException |
|
| 376 | + */ |
|
| 377 | + public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
| 378 | + { |
|
| 379 | + if ( |
|
| 380 | + ! EE_Registry::instance()->CAP->current_user_can( |
|
| 381 | + 'ee_send_message', |
|
| 382 | + 'espresso_registrations_newsletter_selected_send' |
|
| 383 | + ) |
|
| 384 | + ) { |
|
| 385 | + return; |
|
| 386 | + } |
|
| 387 | + $routes_to_add_to = array( |
|
| 388 | + 'contact_list', |
|
| 389 | + 'event_registrations', |
|
| 390 | + 'default', |
|
| 391 | + ); |
|
| 392 | + if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
| 393 | + if ( |
|
| 394 | + ($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
| 395 | + || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
| 396 | + ) { |
|
| 397 | + echo ''; |
|
| 398 | + } else { |
|
| 399 | + $button_text = sprintf( |
|
| 400 | + esc_html__('Send Batch Message (%s selected)', 'event_espresso'), |
|
| 401 | + '<span class="send-selected-newsletter-count">0</span>' |
|
| 402 | + ); |
|
| 403 | + echo '<button id="selected-batch-send-trigger" class="button button--secondary">' |
|
| 404 | + . '<span class="dashicons dashicons-email "></span>' |
|
| 405 | + . $button_text |
|
| 406 | + . '</button>'; |
|
| 407 | + add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | 411 | |
| 412 | 412 | |
| 413 | - /** |
|
| 414 | - * @throws DomainException |
|
| 415 | - * @throws EE_Error |
|
| 416 | - * @throws InvalidArgumentException |
|
| 417 | - * @throws InvalidDataTypeException |
|
| 418 | - * @throws InvalidInterfaceException |
|
| 419 | - */ |
|
| 420 | - public function newsletter_send_form_skeleton() |
|
| 421 | - { |
|
| 422 | - $list_table = $this->_list_table_object; |
|
| 423 | - $codes = array(); |
|
| 424 | - // need to templates for the newsletter message type for the template selector. |
|
| 425 | - $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
| 426 | - $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
| 427 | - array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
| 428 | - ); |
|
| 429 | - foreach ($mtps as $mtp) { |
|
| 430 | - $name = $mtp->name(); |
|
| 431 | - $values[] = array( |
|
| 432 | - 'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name, |
|
| 433 | - 'id' => $mtp->ID(), |
|
| 434 | - ); |
|
| 435 | - } |
|
| 436 | - // need to get a list of shortcodes that are available for the newsletter message type. |
|
| 437 | - $shortcodes = EEH_MSG_Template::get_shortcodes( |
|
| 438 | - 'newsletter', |
|
| 439 | - 'email', |
|
| 440 | - array(), |
|
| 441 | - 'attendee', |
|
| 442 | - false |
|
| 443 | - ); |
|
| 444 | - foreach ($shortcodes as $field => $shortcode_array) { |
|
| 445 | - $available_shortcodes = array(); |
|
| 446 | - foreach ($shortcode_array as $shortcode => $shortcode_details) { |
|
| 447 | - $field_id = $field === '[NEWSLETTER_CONTENT]' |
|
| 448 | - ? 'content' |
|
| 449 | - : $field; |
|
| 450 | - $field_id = 'batch-message-' . strtolower($field_id); |
|
| 451 | - $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="' |
|
| 452 | - . $shortcode |
|
| 453 | - . '" data-linked-input-id="' . $field_id . '">' |
|
| 454 | - . $shortcode |
|
| 455 | - . '</span>'; |
|
| 456 | - } |
|
| 457 | - $codes[ $field ] = implode(', ', $available_shortcodes); |
|
| 458 | - } |
|
| 459 | - $shortcodes = $codes; |
|
| 460 | - $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
| 461 | - $form_template_args = array( |
|
| 462 | - 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
| 463 | - 'form_route' => 'newsletter_selected_send', |
|
| 464 | - 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
| 465 | - 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
| 466 | - 'redirect_back_to' => $this->_req_action, |
|
| 467 | - 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
| 468 | - 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
| 469 | - 'shortcodes' => $shortcodes, |
|
| 470 | - 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
| 471 | - ); |
|
| 472 | - EEH_Template::display_template($form_template, $form_template_args); |
|
| 473 | - } |
|
| 413 | + /** |
|
| 414 | + * @throws DomainException |
|
| 415 | + * @throws EE_Error |
|
| 416 | + * @throws InvalidArgumentException |
|
| 417 | + * @throws InvalidDataTypeException |
|
| 418 | + * @throws InvalidInterfaceException |
|
| 419 | + */ |
|
| 420 | + public function newsletter_send_form_skeleton() |
|
| 421 | + { |
|
| 422 | + $list_table = $this->_list_table_object; |
|
| 423 | + $codes = array(); |
|
| 424 | + // need to templates for the newsletter message type for the template selector. |
|
| 425 | + $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
| 426 | + $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
| 427 | + array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
| 428 | + ); |
|
| 429 | + foreach ($mtps as $mtp) { |
|
| 430 | + $name = $mtp->name(); |
|
| 431 | + $values[] = array( |
|
| 432 | + 'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name, |
|
| 433 | + 'id' => $mtp->ID(), |
|
| 434 | + ); |
|
| 435 | + } |
|
| 436 | + // need to get a list of shortcodes that are available for the newsletter message type. |
|
| 437 | + $shortcodes = EEH_MSG_Template::get_shortcodes( |
|
| 438 | + 'newsletter', |
|
| 439 | + 'email', |
|
| 440 | + array(), |
|
| 441 | + 'attendee', |
|
| 442 | + false |
|
| 443 | + ); |
|
| 444 | + foreach ($shortcodes as $field => $shortcode_array) { |
|
| 445 | + $available_shortcodes = array(); |
|
| 446 | + foreach ($shortcode_array as $shortcode => $shortcode_details) { |
|
| 447 | + $field_id = $field === '[NEWSLETTER_CONTENT]' |
|
| 448 | + ? 'content' |
|
| 449 | + : $field; |
|
| 450 | + $field_id = 'batch-message-' . strtolower($field_id); |
|
| 451 | + $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="' |
|
| 452 | + . $shortcode |
|
| 453 | + . '" data-linked-input-id="' . $field_id . '">' |
|
| 454 | + . $shortcode |
|
| 455 | + . '</span>'; |
|
| 456 | + } |
|
| 457 | + $codes[ $field ] = implode(', ', $available_shortcodes); |
|
| 458 | + } |
|
| 459 | + $shortcodes = $codes; |
|
| 460 | + $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
| 461 | + $form_template_args = array( |
|
| 462 | + 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
| 463 | + 'form_route' => 'newsletter_selected_send', |
|
| 464 | + 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
| 465 | + 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
| 466 | + 'redirect_back_to' => $this->_req_action, |
|
| 467 | + 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
| 468 | + 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
| 469 | + 'shortcodes' => $shortcodes, |
|
| 470 | + 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
| 471 | + ); |
|
| 472 | + EEH_Template::display_template($form_template, $form_template_args); |
|
| 473 | + } |
|
| 474 | 474 | |
| 475 | 475 | |
| 476 | - /** |
|
| 477 | - * Handles sending selected registrations/contacts a newsletter. |
|
| 478 | - * |
|
| 479 | - * @since 4.3.0 |
|
| 480 | - * @return void |
|
| 481 | - * @throws EE_Error |
|
| 482 | - * @throws InvalidArgumentException |
|
| 483 | - * @throws InvalidDataTypeException |
|
| 484 | - * @throws InvalidInterfaceException |
|
| 485 | - */ |
|
| 486 | - protected function _newsletter_selected_send() |
|
| 487 | - { |
|
| 488 | - $success = true; |
|
| 489 | - // first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
| 490 | - if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
| 491 | - EE_Error::add_error( |
|
| 492 | - esc_html__( |
|
| 493 | - 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
| 494 | - 'event_espresso' |
|
| 495 | - ), |
|
| 496 | - __FILE__, |
|
| 497 | - __FUNCTION__, |
|
| 498 | - __LINE__ |
|
| 499 | - ); |
|
| 500 | - $success = false; |
|
| 501 | - } |
|
| 502 | - if ($success) { |
|
| 503 | - // update Message template in case there are any changes |
|
| 504 | - $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 505 | - $this->_req_data['newsletter_mtp_selected'] |
|
| 506 | - ); |
|
| 507 | - $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
| 508 | - ? $Message_Template_Group->context_templates() |
|
| 509 | - : array(); |
|
| 510 | - if (empty($Message_Templates)) { |
|
| 511 | - EE_Error::add_error( |
|
| 512 | - esc_html__( |
|
| 513 | - 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
| 514 | - 'event_espresso' |
|
| 515 | - ), |
|
| 516 | - __FILE__, |
|
| 517 | - __FUNCTION__, |
|
| 518 | - __LINE__ |
|
| 519 | - ); |
|
| 520 | - } |
|
| 521 | - // let's just update the specific fields |
|
| 522 | - foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
| 523 | - if ($Message_Template instanceof EE_Message_Template) { |
|
| 524 | - $field = $Message_Template->get('MTP_template_field'); |
|
| 525 | - $content = $Message_Template->get('MTP_content'); |
|
| 526 | - $new_content = $content; |
|
| 527 | - switch ($field) { |
|
| 528 | - case 'from': |
|
| 529 | - $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
| 530 | - ? $this->_req_data['batch_message']['from'] |
|
| 531 | - : $content; |
|
| 532 | - break; |
|
| 533 | - case 'subject': |
|
| 534 | - $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
| 535 | - ? $this->_req_data['batch_message']['subject'] |
|
| 536 | - : $content; |
|
| 537 | - break; |
|
| 538 | - case 'content': |
|
| 539 | - $new_content = $content; |
|
| 540 | - $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
| 541 | - ? $this->_req_data['batch_message']['content'] |
|
| 542 | - : $content['newsletter_content']; |
|
| 543 | - break; |
|
| 544 | - default: |
|
| 545 | - // continue the foreach loop, we don't want to set $new_content nor save. |
|
| 546 | - continue 2; |
|
| 547 | - } |
|
| 548 | - $Message_Template->set('MTP_content', $new_content); |
|
| 549 | - $Message_Template->save(); |
|
| 550 | - } |
|
| 551 | - } |
|
| 552 | - // great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
| 553 | - $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
| 554 | - ? $this->_req_data['batch_message']['id_type'] |
|
| 555 | - : 'registration'; |
|
| 556 | - // id_type will affect how we assemble the ids. |
|
| 557 | - $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
| 558 | - ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
| 559 | - : array(); |
|
| 560 | - $registrations_used_for_contact_data = array(); |
|
| 561 | - // using switch because eventually we'll have other contexts that will be used for generating messages. |
|
| 562 | - switch ($id_type) { |
|
| 563 | - case 'registration': |
|
| 564 | - $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
| 565 | - array( |
|
| 566 | - array( |
|
| 567 | - 'REG_ID' => array('IN', $ids), |
|
| 568 | - ), |
|
| 569 | - ) |
|
| 570 | - ); |
|
| 571 | - break; |
|
| 572 | - case 'contact': |
|
| 573 | - $registrations_used_for_contact_data = EEM_Registration::instance() |
|
| 574 | - ->get_latest_registration_for_each_of_given_contacts( |
|
| 575 | - $ids |
|
| 576 | - ); |
|
| 577 | - break; |
|
| 578 | - } |
|
| 579 | - do_action_ref_array( |
|
| 580 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 581 | - array( |
|
| 582 | - $registrations_used_for_contact_data, |
|
| 583 | - $Message_Template_Group->ID(), |
|
| 584 | - ) |
|
| 585 | - ); |
|
| 586 | - // kept for backward compat, internally we no longer use this action. |
|
| 587 | - // @deprecated 4.8.36.rc.002 |
|
| 588 | - $contacts = $id_type === 'registration' |
|
| 589 | - ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
| 590 | - : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
| 591 | - do_action_ref_array( |
|
| 592 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
| 593 | - array( |
|
| 594 | - $contacts, |
|
| 595 | - $Message_Template_Group->ID(), |
|
| 596 | - ) |
|
| 597 | - ); |
|
| 598 | - } |
|
| 599 | - $query_args = array( |
|
| 600 | - 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
| 601 | - ? $this->_req_data['redirect_back_to'] |
|
| 602 | - : 'default', |
|
| 603 | - ); |
|
| 604 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 605 | - } |
|
| 476 | + /** |
|
| 477 | + * Handles sending selected registrations/contacts a newsletter. |
|
| 478 | + * |
|
| 479 | + * @since 4.3.0 |
|
| 480 | + * @return void |
|
| 481 | + * @throws EE_Error |
|
| 482 | + * @throws InvalidArgumentException |
|
| 483 | + * @throws InvalidDataTypeException |
|
| 484 | + * @throws InvalidInterfaceException |
|
| 485 | + */ |
|
| 486 | + protected function _newsletter_selected_send() |
|
| 487 | + { |
|
| 488 | + $success = true; |
|
| 489 | + // first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
| 490 | + if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
| 491 | + EE_Error::add_error( |
|
| 492 | + esc_html__( |
|
| 493 | + 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
| 494 | + 'event_espresso' |
|
| 495 | + ), |
|
| 496 | + __FILE__, |
|
| 497 | + __FUNCTION__, |
|
| 498 | + __LINE__ |
|
| 499 | + ); |
|
| 500 | + $success = false; |
|
| 501 | + } |
|
| 502 | + if ($success) { |
|
| 503 | + // update Message template in case there are any changes |
|
| 504 | + $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 505 | + $this->_req_data['newsletter_mtp_selected'] |
|
| 506 | + ); |
|
| 507 | + $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
| 508 | + ? $Message_Template_Group->context_templates() |
|
| 509 | + : array(); |
|
| 510 | + if (empty($Message_Templates)) { |
|
| 511 | + EE_Error::add_error( |
|
| 512 | + esc_html__( |
|
| 513 | + 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
| 514 | + 'event_espresso' |
|
| 515 | + ), |
|
| 516 | + __FILE__, |
|
| 517 | + __FUNCTION__, |
|
| 518 | + __LINE__ |
|
| 519 | + ); |
|
| 520 | + } |
|
| 521 | + // let's just update the specific fields |
|
| 522 | + foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
| 523 | + if ($Message_Template instanceof EE_Message_Template) { |
|
| 524 | + $field = $Message_Template->get('MTP_template_field'); |
|
| 525 | + $content = $Message_Template->get('MTP_content'); |
|
| 526 | + $new_content = $content; |
|
| 527 | + switch ($field) { |
|
| 528 | + case 'from': |
|
| 529 | + $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
| 530 | + ? $this->_req_data['batch_message']['from'] |
|
| 531 | + : $content; |
|
| 532 | + break; |
|
| 533 | + case 'subject': |
|
| 534 | + $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
| 535 | + ? $this->_req_data['batch_message']['subject'] |
|
| 536 | + : $content; |
|
| 537 | + break; |
|
| 538 | + case 'content': |
|
| 539 | + $new_content = $content; |
|
| 540 | + $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
| 541 | + ? $this->_req_data['batch_message']['content'] |
|
| 542 | + : $content['newsletter_content']; |
|
| 543 | + break; |
|
| 544 | + default: |
|
| 545 | + // continue the foreach loop, we don't want to set $new_content nor save. |
|
| 546 | + continue 2; |
|
| 547 | + } |
|
| 548 | + $Message_Template->set('MTP_content', $new_content); |
|
| 549 | + $Message_Template->save(); |
|
| 550 | + } |
|
| 551 | + } |
|
| 552 | + // great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
| 553 | + $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
| 554 | + ? $this->_req_data['batch_message']['id_type'] |
|
| 555 | + : 'registration'; |
|
| 556 | + // id_type will affect how we assemble the ids. |
|
| 557 | + $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
| 558 | + ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
| 559 | + : array(); |
|
| 560 | + $registrations_used_for_contact_data = array(); |
|
| 561 | + // using switch because eventually we'll have other contexts that will be used for generating messages. |
|
| 562 | + switch ($id_type) { |
|
| 563 | + case 'registration': |
|
| 564 | + $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
| 565 | + array( |
|
| 566 | + array( |
|
| 567 | + 'REG_ID' => array('IN', $ids), |
|
| 568 | + ), |
|
| 569 | + ) |
|
| 570 | + ); |
|
| 571 | + break; |
|
| 572 | + case 'contact': |
|
| 573 | + $registrations_used_for_contact_data = EEM_Registration::instance() |
|
| 574 | + ->get_latest_registration_for_each_of_given_contacts( |
|
| 575 | + $ids |
|
| 576 | + ); |
|
| 577 | + break; |
|
| 578 | + } |
|
| 579 | + do_action_ref_array( |
|
| 580 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 581 | + array( |
|
| 582 | + $registrations_used_for_contact_data, |
|
| 583 | + $Message_Template_Group->ID(), |
|
| 584 | + ) |
|
| 585 | + ); |
|
| 586 | + // kept for backward compat, internally we no longer use this action. |
|
| 587 | + // @deprecated 4.8.36.rc.002 |
|
| 588 | + $contacts = $id_type === 'registration' |
|
| 589 | + ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
| 590 | + : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
| 591 | + do_action_ref_array( |
|
| 592 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
| 593 | + array( |
|
| 594 | + $contacts, |
|
| 595 | + $Message_Template_Group->ID(), |
|
| 596 | + ) |
|
| 597 | + ); |
|
| 598 | + } |
|
| 599 | + $query_args = array( |
|
| 600 | + 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
| 601 | + ? $this->_req_data['redirect_back_to'] |
|
| 602 | + : 'default', |
|
| 603 | + ); |
|
| 604 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 605 | + } |
|
| 606 | 606 | |
| 607 | 607 | |
| 608 | - /** |
|
| 609 | - * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
| 610 | - * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
| 611 | - */ |
|
| 612 | - protected function _registration_reports_js_setup() |
|
| 613 | - { |
|
| 614 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
| 615 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
| 616 | - } |
|
| 608 | + /** |
|
| 609 | + * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
| 610 | + * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
| 611 | + */ |
|
| 612 | + protected function _registration_reports_js_setup() |
|
| 613 | + { |
|
| 614 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
| 615 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
| 616 | + } |
|
| 617 | 617 | |
| 618 | 618 | |
| 619 | - /** |
|
| 620 | - * generates Business Reports regarding Registrations |
|
| 621 | - * |
|
| 622 | - * @access protected |
|
| 623 | - * @return void |
|
| 624 | - * @throws DomainException |
|
| 625 | - */ |
|
| 626 | - protected function _registration_reports() |
|
| 627 | - { |
|
| 628 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
| 629 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 630 | - $template_path, |
|
| 631 | - $this->_reports_template_data, |
|
| 632 | - true |
|
| 633 | - ); |
|
| 634 | - // the final template wrapper |
|
| 635 | - $this->display_admin_page_with_no_sidebar(); |
|
| 636 | - } |
|
| 619 | + /** |
|
| 620 | + * generates Business Reports regarding Registrations |
|
| 621 | + * |
|
| 622 | + * @access protected |
|
| 623 | + * @return void |
|
| 624 | + * @throws DomainException |
|
| 625 | + */ |
|
| 626 | + protected function _registration_reports() |
|
| 627 | + { |
|
| 628 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
| 629 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 630 | + $template_path, |
|
| 631 | + $this->_reports_template_data, |
|
| 632 | + true |
|
| 633 | + ); |
|
| 634 | + // the final template wrapper |
|
| 635 | + $this->display_admin_page_with_no_sidebar(); |
|
| 636 | + } |
|
| 637 | 637 | |
| 638 | 638 | |
| 639 | - /** |
|
| 640 | - * Generates Business Report showing total registrations per day. |
|
| 641 | - * |
|
| 642 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
| 643 | - * @return string |
|
| 644 | - * @throws EE_Error |
|
| 645 | - * @throws InvalidArgumentException |
|
| 646 | - * @throws InvalidDataTypeException |
|
| 647 | - * @throws InvalidInterfaceException |
|
| 648 | - */ |
|
| 649 | - private function _registrations_per_day_report($period = '-1 month') |
|
| 650 | - { |
|
| 651 | - $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
| 652 | - $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
| 653 | - $results = (array) $results; |
|
| 654 | - $regs = array(); |
|
| 655 | - $subtitle = ''; |
|
| 656 | - if ($results) { |
|
| 657 | - $column_titles = array(); |
|
| 658 | - $tracker = 0; |
|
| 659 | - foreach ($results as $result) { |
|
| 660 | - $report_column_values = array(); |
|
| 661 | - foreach ($result as $property_name => $property_value) { |
|
| 662 | - $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
| 663 | - : (int) $property_value; |
|
| 664 | - $report_column_values[] = $property_value; |
|
| 665 | - if ($tracker === 0) { |
|
| 666 | - if ($property_name === 'Registration_REG_date') { |
|
| 667 | - $column_titles[] = esc_html__( |
|
| 668 | - 'Date (only days with registrations are shown)', |
|
| 669 | - 'event_espresso' |
|
| 670 | - ); |
|
| 671 | - } else { |
|
| 672 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
| 673 | - } |
|
| 674 | - } |
|
| 675 | - } |
|
| 676 | - $tracker++; |
|
| 677 | - $regs[] = $report_column_values; |
|
| 678 | - } |
|
| 679 | - // make sure the column_titles is pushed to the beginning of the array |
|
| 680 | - array_unshift($regs, $column_titles); |
|
| 681 | - // setup the date range. |
|
| 682 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
| 683 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 684 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
| 685 | - $subtitle = sprintf( |
|
| 686 | - wp_strip_all_tags( |
|
| 687 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso') |
|
| 688 | - ), |
|
| 689 | - $beginning_date->format('Y-m-d'), |
|
| 690 | - $ending_date->format('Y-m-d') |
|
| 691 | - ); |
|
| 692 | - } |
|
| 693 | - $report_title = wp_strip_all_tags(__('Total Registrations per Day', 'event_espresso')); |
|
| 694 | - $report_params = array( |
|
| 695 | - 'title' => $report_title, |
|
| 696 | - 'subtitle' => $subtitle, |
|
| 697 | - 'id' => $report_ID, |
|
| 698 | - 'regs' => $regs, |
|
| 699 | - 'noResults' => empty($regs), |
|
| 700 | - 'noRegsMsg' => sprintf( |
|
| 701 | - wp_strip_all_tags( |
|
| 702 | - __( |
|
| 703 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
| 704 | - 'event_espresso' |
|
| 705 | - ) |
|
| 706 | - ), |
|
| 707 | - '<h2>' . $report_title . '</h2><p>', |
|
| 708 | - '</p>' |
|
| 709 | - ), |
|
| 710 | - ); |
|
| 711 | - wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
| 712 | - return $report_ID; |
|
| 713 | - } |
|
| 639 | + /** |
|
| 640 | + * Generates Business Report showing total registrations per day. |
|
| 641 | + * |
|
| 642 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
| 643 | + * @return string |
|
| 644 | + * @throws EE_Error |
|
| 645 | + * @throws InvalidArgumentException |
|
| 646 | + * @throws InvalidDataTypeException |
|
| 647 | + * @throws InvalidInterfaceException |
|
| 648 | + */ |
|
| 649 | + private function _registrations_per_day_report($period = '-1 month') |
|
| 650 | + { |
|
| 651 | + $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
| 652 | + $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
| 653 | + $results = (array) $results; |
|
| 654 | + $regs = array(); |
|
| 655 | + $subtitle = ''; |
|
| 656 | + if ($results) { |
|
| 657 | + $column_titles = array(); |
|
| 658 | + $tracker = 0; |
|
| 659 | + foreach ($results as $result) { |
|
| 660 | + $report_column_values = array(); |
|
| 661 | + foreach ($result as $property_name => $property_value) { |
|
| 662 | + $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
| 663 | + : (int) $property_value; |
|
| 664 | + $report_column_values[] = $property_value; |
|
| 665 | + if ($tracker === 0) { |
|
| 666 | + if ($property_name === 'Registration_REG_date') { |
|
| 667 | + $column_titles[] = esc_html__( |
|
| 668 | + 'Date (only days with registrations are shown)', |
|
| 669 | + 'event_espresso' |
|
| 670 | + ); |
|
| 671 | + } else { |
|
| 672 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
| 673 | + } |
|
| 674 | + } |
|
| 675 | + } |
|
| 676 | + $tracker++; |
|
| 677 | + $regs[] = $report_column_values; |
|
| 678 | + } |
|
| 679 | + // make sure the column_titles is pushed to the beginning of the array |
|
| 680 | + array_unshift($regs, $column_titles); |
|
| 681 | + // setup the date range. |
|
| 682 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
| 683 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 684 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
| 685 | + $subtitle = sprintf( |
|
| 686 | + wp_strip_all_tags( |
|
| 687 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso') |
|
| 688 | + ), |
|
| 689 | + $beginning_date->format('Y-m-d'), |
|
| 690 | + $ending_date->format('Y-m-d') |
|
| 691 | + ); |
|
| 692 | + } |
|
| 693 | + $report_title = wp_strip_all_tags(__('Total Registrations per Day', 'event_espresso')); |
|
| 694 | + $report_params = array( |
|
| 695 | + 'title' => $report_title, |
|
| 696 | + 'subtitle' => $subtitle, |
|
| 697 | + 'id' => $report_ID, |
|
| 698 | + 'regs' => $regs, |
|
| 699 | + 'noResults' => empty($regs), |
|
| 700 | + 'noRegsMsg' => sprintf( |
|
| 701 | + wp_strip_all_tags( |
|
| 702 | + __( |
|
| 703 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
| 704 | + 'event_espresso' |
|
| 705 | + ) |
|
| 706 | + ), |
|
| 707 | + '<h2>' . $report_title . '</h2><p>', |
|
| 708 | + '</p>' |
|
| 709 | + ), |
|
| 710 | + ); |
|
| 711 | + wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
| 712 | + return $report_ID; |
|
| 713 | + } |
|
| 714 | 714 | |
| 715 | 715 | |
| 716 | - /** |
|
| 717 | - * Generates Business Report showing total registrations per event. |
|
| 718 | - * |
|
| 719 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
| 720 | - * @return string |
|
| 721 | - * @throws EE_Error |
|
| 722 | - * @throws InvalidArgumentException |
|
| 723 | - * @throws InvalidDataTypeException |
|
| 724 | - * @throws InvalidInterfaceException |
|
| 725 | - */ |
|
| 726 | - private function _registrations_per_event_report($period = '-1 month') |
|
| 727 | - { |
|
| 728 | - $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
| 729 | - $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
| 730 | - $results = (array) $results; |
|
| 731 | - $regs = array(); |
|
| 732 | - $subtitle = ''; |
|
| 733 | - if ($results) { |
|
| 734 | - $column_titles = array(); |
|
| 735 | - $tracker = 0; |
|
| 736 | - foreach ($results as $result) { |
|
| 737 | - $report_column_values = array(); |
|
| 738 | - foreach ($result as $property_name => $property_value) { |
|
| 739 | - $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
| 740 | - $property_value, |
|
| 741 | - 4, |
|
| 742 | - '...' |
|
| 743 | - ) : (int) $property_value; |
|
| 744 | - $report_column_values[] = $property_value; |
|
| 745 | - if ($tracker === 0) { |
|
| 746 | - if ($property_name === 'Registration_Event') { |
|
| 747 | - $column_titles[] = esc_html__('Event', 'event_espresso'); |
|
| 748 | - } else { |
|
| 749 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
| 750 | - } |
|
| 751 | - } |
|
| 752 | - } |
|
| 753 | - $tracker++; |
|
| 754 | - $regs[] = $report_column_values; |
|
| 755 | - } |
|
| 756 | - // make sure the column_titles is pushed to the beginning of the array |
|
| 757 | - array_unshift($regs, $column_titles); |
|
| 758 | - // setup the date range. |
|
| 759 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
| 760 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 761 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
| 762 | - $subtitle = sprintf( |
|
| 763 | - wp_strip_all_tags( |
|
| 764 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso') |
|
| 765 | - ), |
|
| 766 | - $beginning_date->format('Y-m-d'), |
|
| 767 | - $ending_date->format('Y-m-d') |
|
| 768 | - ); |
|
| 769 | - } |
|
| 770 | - $report_title = wp_strip_all_tags(__('Total Registrations per Event', 'event_espresso')); |
|
| 771 | - $report_params = array( |
|
| 772 | - 'title' => $report_title, |
|
| 773 | - 'subtitle' => $subtitle, |
|
| 774 | - 'id' => $report_ID, |
|
| 775 | - 'regs' => $regs, |
|
| 776 | - 'noResults' => empty($regs), |
|
| 777 | - 'noRegsMsg' => sprintf( |
|
| 778 | - wp_strip_all_tags( |
|
| 779 | - __( |
|
| 780 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
| 781 | - 'event_espresso' |
|
| 782 | - ) |
|
| 783 | - ), |
|
| 784 | - '<h2>' . $report_title . '</h2><p>', |
|
| 785 | - '</p>' |
|
| 786 | - ), |
|
| 787 | - ); |
|
| 788 | - wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
| 789 | - return $report_ID; |
|
| 790 | - } |
|
| 716 | + /** |
|
| 717 | + * Generates Business Report showing total registrations per event. |
|
| 718 | + * |
|
| 719 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
| 720 | + * @return string |
|
| 721 | + * @throws EE_Error |
|
| 722 | + * @throws InvalidArgumentException |
|
| 723 | + * @throws InvalidDataTypeException |
|
| 724 | + * @throws InvalidInterfaceException |
|
| 725 | + */ |
|
| 726 | + private function _registrations_per_event_report($period = '-1 month') |
|
| 727 | + { |
|
| 728 | + $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
| 729 | + $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
| 730 | + $results = (array) $results; |
|
| 731 | + $regs = array(); |
|
| 732 | + $subtitle = ''; |
|
| 733 | + if ($results) { |
|
| 734 | + $column_titles = array(); |
|
| 735 | + $tracker = 0; |
|
| 736 | + foreach ($results as $result) { |
|
| 737 | + $report_column_values = array(); |
|
| 738 | + foreach ($result as $property_name => $property_value) { |
|
| 739 | + $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
| 740 | + $property_value, |
|
| 741 | + 4, |
|
| 742 | + '...' |
|
| 743 | + ) : (int) $property_value; |
|
| 744 | + $report_column_values[] = $property_value; |
|
| 745 | + if ($tracker === 0) { |
|
| 746 | + if ($property_name === 'Registration_Event') { |
|
| 747 | + $column_titles[] = esc_html__('Event', 'event_espresso'); |
|
| 748 | + } else { |
|
| 749 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
| 750 | + } |
|
| 751 | + } |
|
| 752 | + } |
|
| 753 | + $tracker++; |
|
| 754 | + $regs[] = $report_column_values; |
|
| 755 | + } |
|
| 756 | + // make sure the column_titles is pushed to the beginning of the array |
|
| 757 | + array_unshift($regs, $column_titles); |
|
| 758 | + // setup the date range. |
|
| 759 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
| 760 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 761 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
| 762 | + $subtitle = sprintf( |
|
| 763 | + wp_strip_all_tags( |
|
| 764 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso') |
|
| 765 | + ), |
|
| 766 | + $beginning_date->format('Y-m-d'), |
|
| 767 | + $ending_date->format('Y-m-d') |
|
| 768 | + ); |
|
| 769 | + } |
|
| 770 | + $report_title = wp_strip_all_tags(__('Total Registrations per Event', 'event_espresso')); |
|
| 771 | + $report_params = array( |
|
| 772 | + 'title' => $report_title, |
|
| 773 | + 'subtitle' => $subtitle, |
|
| 774 | + 'id' => $report_ID, |
|
| 775 | + 'regs' => $regs, |
|
| 776 | + 'noResults' => empty($regs), |
|
| 777 | + 'noRegsMsg' => sprintf( |
|
| 778 | + wp_strip_all_tags( |
|
| 779 | + __( |
|
| 780 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
| 781 | + 'event_espresso' |
|
| 782 | + ) |
|
| 783 | + ), |
|
| 784 | + '<h2>' . $report_title . '</h2><p>', |
|
| 785 | + '</p>' |
|
| 786 | + ), |
|
| 787 | + ); |
|
| 788 | + wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
| 789 | + return $report_ID; |
|
| 790 | + } |
|
| 791 | 791 | |
| 792 | 792 | |
| 793 | - /** |
|
| 794 | - * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
| 795 | - * |
|
| 796 | - * @access protected |
|
| 797 | - * @return void |
|
| 798 | - * @throws EE_Error |
|
| 799 | - * @throws InvalidArgumentException |
|
| 800 | - * @throws InvalidDataTypeException |
|
| 801 | - * @throws InvalidInterfaceException |
|
| 802 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 803 | - */ |
|
| 804 | - protected function _registration_checkin_list_table() |
|
| 805 | - { |
|
| 806 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 807 | - $reg_id = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : null; |
|
| 808 | - /** @var EE_Registration $registration */ |
|
| 809 | - $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
| 810 | - if (! $registration instanceof EE_Registration) { |
|
| 811 | - throw new EE_Error( |
|
| 812 | - sprintf( |
|
| 813 | - esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'), |
|
| 814 | - $reg_id |
|
| 815 | - ) |
|
| 816 | - ); |
|
| 817 | - } |
|
| 818 | - $attendee = $registration->attendee(); |
|
| 819 | - $this->_admin_page_title .= $this->get_action_link_or_button( |
|
| 820 | - 'new_registration', |
|
| 821 | - 'add-registrant', |
|
| 822 | - array('event_id' => $registration->event_ID()), |
|
| 823 | - 'add-new-h2' |
|
| 824 | - ); |
|
| 825 | - $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
| 826 | - $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
| 827 | - $legend_items = array( |
|
| 828 | - 'checkin' => array( |
|
| 829 | - 'class' => $checked_in->cssClasses(), |
|
| 830 | - 'desc' => $checked_in->legendLabel(), |
|
| 831 | - ), |
|
| 832 | - 'checkout' => array( |
|
| 833 | - 'class' => $checked_out->cssClasses(), |
|
| 834 | - 'desc' => $checked_out->legendLabel(), |
|
| 835 | - ), |
|
| 836 | - ); |
|
| 837 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
| 838 | - $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 839 | - /** @var EE_Datetime $datetime */ |
|
| 840 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id); |
|
| 841 | - $datetime_label = ''; |
|
| 842 | - if ($datetime instanceof EE_Datetime) { |
|
| 843 | - $datetime_label = $datetime->get_dtt_display_name(true); |
|
| 844 | - $datetime_label .= ! empty($datetime_label) |
|
| 845 | - ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
| 846 | - : $datetime->get_dtt_display_name(); |
|
| 847 | - } |
|
| 848 | - $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
|
| 849 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 850 | - array( |
|
| 851 | - 'action' => 'event_registrations', |
|
| 852 | - 'event_id' => $registration->event_ID(), |
|
| 853 | - 'DTT_ID' => $dtt_id, |
|
| 854 | - ), |
|
| 855 | - $this->_admin_base_url |
|
| 856 | - ) |
|
| 857 | - : ''; |
|
| 858 | - $datetime_link = ! empty($datetime_link) |
|
| 859 | - ? '<a href="' . $datetime_link . '">' |
|
| 860 | - . '<span id="checkin-dtt">' |
|
| 861 | - . $datetime_label |
|
| 862 | - . '</span></a>' |
|
| 863 | - : $datetime_label; |
|
| 864 | - $attendee_name = $attendee instanceof EE_Attendee |
|
| 865 | - ? $attendee->full_name() |
|
| 866 | - : ''; |
|
| 867 | - $attendee_link = $attendee instanceof EE_Attendee |
|
| 868 | - ? $attendee->get_admin_details_link() |
|
| 869 | - : ''; |
|
| 870 | - $attendee_link = ! empty($attendee_link) |
|
| 871 | - ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
| 872 | - . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
| 873 | - . '<span id="checkin-attendee-name">' |
|
| 874 | - . $attendee_name |
|
| 875 | - . '</span></a>' |
|
| 876 | - : ''; |
|
| 877 | - $event_link = $registration->event() instanceof EE_Event |
|
| 878 | - ? $registration->event()->get_admin_details_link() |
|
| 879 | - : ''; |
|
| 880 | - $event_link = ! empty($event_link) |
|
| 881 | - ? '<a href="' . $event_link . '"' |
|
| 882 | - . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
| 883 | - . '<span id="checkin-event-name">' |
|
| 884 | - . $registration->event_name() |
|
| 885 | - . '</span>' |
|
| 886 | - . '</a>' |
|
| 887 | - : ''; |
|
| 888 | - $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
| 889 | - ? '<h2>' . sprintf( |
|
| 890 | - esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
|
| 891 | - $attendee_link, |
|
| 892 | - $datetime_link, |
|
| 893 | - $event_link |
|
| 894 | - ) . '</h2>' |
|
| 895 | - : ''; |
|
| 896 | - $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
| 897 | - ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : ''; |
|
| 898 | - $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
| 899 | - ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
| 900 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 901 | - } |
|
| 793 | + /** |
|
| 794 | + * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
| 795 | + * |
|
| 796 | + * @access protected |
|
| 797 | + * @return void |
|
| 798 | + * @throws EE_Error |
|
| 799 | + * @throws InvalidArgumentException |
|
| 800 | + * @throws InvalidDataTypeException |
|
| 801 | + * @throws InvalidInterfaceException |
|
| 802 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 803 | + */ |
|
| 804 | + protected function _registration_checkin_list_table() |
|
| 805 | + { |
|
| 806 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 807 | + $reg_id = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : null; |
|
| 808 | + /** @var EE_Registration $registration */ |
|
| 809 | + $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
| 810 | + if (! $registration instanceof EE_Registration) { |
|
| 811 | + throw new EE_Error( |
|
| 812 | + sprintf( |
|
| 813 | + esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'), |
|
| 814 | + $reg_id |
|
| 815 | + ) |
|
| 816 | + ); |
|
| 817 | + } |
|
| 818 | + $attendee = $registration->attendee(); |
|
| 819 | + $this->_admin_page_title .= $this->get_action_link_or_button( |
|
| 820 | + 'new_registration', |
|
| 821 | + 'add-registrant', |
|
| 822 | + array('event_id' => $registration->event_ID()), |
|
| 823 | + 'add-new-h2' |
|
| 824 | + ); |
|
| 825 | + $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
| 826 | + $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
| 827 | + $legend_items = array( |
|
| 828 | + 'checkin' => array( |
|
| 829 | + 'class' => $checked_in->cssClasses(), |
|
| 830 | + 'desc' => $checked_in->legendLabel(), |
|
| 831 | + ), |
|
| 832 | + 'checkout' => array( |
|
| 833 | + 'class' => $checked_out->cssClasses(), |
|
| 834 | + 'desc' => $checked_out->legendLabel(), |
|
| 835 | + ), |
|
| 836 | + ); |
|
| 837 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
| 838 | + $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 839 | + /** @var EE_Datetime $datetime */ |
|
| 840 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id); |
|
| 841 | + $datetime_label = ''; |
|
| 842 | + if ($datetime instanceof EE_Datetime) { |
|
| 843 | + $datetime_label = $datetime->get_dtt_display_name(true); |
|
| 844 | + $datetime_label .= ! empty($datetime_label) |
|
| 845 | + ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
| 846 | + : $datetime->get_dtt_display_name(); |
|
| 847 | + } |
|
| 848 | + $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
|
| 849 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 850 | + array( |
|
| 851 | + 'action' => 'event_registrations', |
|
| 852 | + 'event_id' => $registration->event_ID(), |
|
| 853 | + 'DTT_ID' => $dtt_id, |
|
| 854 | + ), |
|
| 855 | + $this->_admin_base_url |
|
| 856 | + ) |
|
| 857 | + : ''; |
|
| 858 | + $datetime_link = ! empty($datetime_link) |
|
| 859 | + ? '<a href="' . $datetime_link . '">' |
|
| 860 | + . '<span id="checkin-dtt">' |
|
| 861 | + . $datetime_label |
|
| 862 | + . '</span></a>' |
|
| 863 | + : $datetime_label; |
|
| 864 | + $attendee_name = $attendee instanceof EE_Attendee |
|
| 865 | + ? $attendee->full_name() |
|
| 866 | + : ''; |
|
| 867 | + $attendee_link = $attendee instanceof EE_Attendee |
|
| 868 | + ? $attendee->get_admin_details_link() |
|
| 869 | + : ''; |
|
| 870 | + $attendee_link = ! empty($attendee_link) |
|
| 871 | + ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
| 872 | + . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
| 873 | + . '<span id="checkin-attendee-name">' |
|
| 874 | + . $attendee_name |
|
| 875 | + . '</span></a>' |
|
| 876 | + : ''; |
|
| 877 | + $event_link = $registration->event() instanceof EE_Event |
|
| 878 | + ? $registration->event()->get_admin_details_link() |
|
| 879 | + : ''; |
|
| 880 | + $event_link = ! empty($event_link) |
|
| 881 | + ? '<a href="' . $event_link . '"' |
|
| 882 | + . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
| 883 | + . '<span id="checkin-event-name">' |
|
| 884 | + . $registration->event_name() |
|
| 885 | + . '</span>' |
|
| 886 | + . '</a>' |
|
| 887 | + : ''; |
|
| 888 | + $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
| 889 | + ? '<h2>' . sprintf( |
|
| 890 | + esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
|
| 891 | + $attendee_link, |
|
| 892 | + $datetime_link, |
|
| 893 | + $event_link |
|
| 894 | + ) . '</h2>' |
|
| 895 | + : ''; |
|
| 896 | + $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
| 897 | + ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : ''; |
|
| 898 | + $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
| 899 | + ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
| 900 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 901 | + } |
|
| 902 | 902 | |
| 903 | 903 | |
| 904 | - /** |
|
| 905 | - * toggle the Check-in status for the given registration (coming from ajax) |
|
| 906 | - * |
|
| 907 | - * @return void (JSON) |
|
| 908 | - * @throws EE_Error |
|
| 909 | - * @throws InvalidArgumentException |
|
| 910 | - * @throws InvalidDataTypeException |
|
| 911 | - * @throws InvalidInterfaceException |
|
| 912 | - */ |
|
| 913 | - public function toggle_checkin_status() |
|
| 914 | - { |
|
| 915 | - // first make sure we have the necessary data |
|
| 916 | - if (! isset($this->_req_data['_regid'])) { |
|
| 917 | - EE_Error::add_error( |
|
| 918 | - esc_html__( |
|
| 919 | - 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
| 920 | - 'event_espresso' |
|
| 921 | - ), |
|
| 922 | - __FILE__, |
|
| 923 | - __FUNCTION__, |
|
| 924 | - __LINE__ |
|
| 925 | - ); |
|
| 926 | - $this->_template_args['success'] = false; |
|
| 927 | - $this->_template_args['error'] = true; |
|
| 928 | - $this->_return_json(); |
|
| 929 | - }; |
|
| 930 | - // do a nonce check cause we're not coming in from an normal route here. |
|
| 931 | - $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
| 932 | - : ''; |
|
| 933 | - $nonce_ref = 'checkin_nonce'; |
|
| 934 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 935 | - // beautiful! Made it this far so let's get the status. |
|
| 936 | - $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
|
| 937 | - // setup new class to return via ajax |
|
| 938 | - $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
| 939 | - $this->_template_args['success'] = true; |
|
| 940 | - $this->_return_json(); |
|
| 941 | - } |
|
| 904 | + /** |
|
| 905 | + * toggle the Check-in status for the given registration (coming from ajax) |
|
| 906 | + * |
|
| 907 | + * @return void (JSON) |
|
| 908 | + * @throws EE_Error |
|
| 909 | + * @throws InvalidArgumentException |
|
| 910 | + * @throws InvalidDataTypeException |
|
| 911 | + * @throws InvalidInterfaceException |
|
| 912 | + */ |
|
| 913 | + public function toggle_checkin_status() |
|
| 914 | + { |
|
| 915 | + // first make sure we have the necessary data |
|
| 916 | + if (! isset($this->_req_data['_regid'])) { |
|
| 917 | + EE_Error::add_error( |
|
| 918 | + esc_html__( |
|
| 919 | + 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
| 920 | + 'event_espresso' |
|
| 921 | + ), |
|
| 922 | + __FILE__, |
|
| 923 | + __FUNCTION__, |
|
| 924 | + __LINE__ |
|
| 925 | + ); |
|
| 926 | + $this->_template_args['success'] = false; |
|
| 927 | + $this->_template_args['error'] = true; |
|
| 928 | + $this->_return_json(); |
|
| 929 | + }; |
|
| 930 | + // do a nonce check cause we're not coming in from an normal route here. |
|
| 931 | + $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
| 932 | + : ''; |
|
| 933 | + $nonce_ref = 'checkin_nonce'; |
|
| 934 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 935 | + // beautiful! Made it this far so let's get the status. |
|
| 936 | + $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
|
| 937 | + // setup new class to return via ajax |
|
| 938 | + $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
| 939 | + $this->_template_args['success'] = true; |
|
| 940 | + $this->_return_json(); |
|
| 941 | + } |
|
| 942 | 942 | |
| 943 | 943 | |
| 944 | - /** |
|
| 945 | - * handles toggling the checkin status for the registration, |
|
| 946 | - * |
|
| 947 | - * @access protected |
|
| 948 | - * @return int|void |
|
| 949 | - * @throws EE_Error |
|
| 950 | - * @throws InvalidArgumentException |
|
| 951 | - * @throws InvalidDataTypeException |
|
| 952 | - * @throws InvalidInterfaceException |
|
| 953 | - */ |
|
| 954 | - protected function _toggle_checkin_status() |
|
| 955 | - { |
|
| 956 | - // first let's get the query args out of the way for the redirect |
|
| 957 | - $query_args = array( |
|
| 958 | - 'action' => 'event_registrations', |
|
| 959 | - 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
| 960 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
| 961 | - ); |
|
| 962 | - $new_status = false; |
|
| 963 | - // bulk action check in toggle |
|
| 964 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 965 | - // cycle thru checkboxes |
|
| 966 | - while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 967 | - $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 968 | - $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
| 969 | - } |
|
| 970 | - } elseif (isset($this->_req_data['_regid'])) { |
|
| 971 | - // coming from ajax request |
|
| 972 | - $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
| 973 | - $query_args['DTT_ID'] = $DTT_ID; |
|
| 974 | - $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
| 975 | - } else { |
|
| 976 | - EE_Error::add_error( |
|
| 977 | - esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
| 978 | - __FILE__, |
|
| 979 | - __FUNCTION__, |
|
| 980 | - __LINE__ |
|
| 981 | - ); |
|
| 982 | - } |
|
| 983 | - if (defined('DOING_AJAX')) { |
|
| 984 | - return $new_status; |
|
| 985 | - } |
|
| 986 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 987 | - } |
|
| 944 | + /** |
|
| 945 | + * handles toggling the checkin status for the registration, |
|
| 946 | + * |
|
| 947 | + * @access protected |
|
| 948 | + * @return int|void |
|
| 949 | + * @throws EE_Error |
|
| 950 | + * @throws InvalidArgumentException |
|
| 951 | + * @throws InvalidDataTypeException |
|
| 952 | + * @throws InvalidInterfaceException |
|
| 953 | + */ |
|
| 954 | + protected function _toggle_checkin_status() |
|
| 955 | + { |
|
| 956 | + // first let's get the query args out of the way for the redirect |
|
| 957 | + $query_args = array( |
|
| 958 | + 'action' => 'event_registrations', |
|
| 959 | + 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
| 960 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
| 961 | + ); |
|
| 962 | + $new_status = false; |
|
| 963 | + // bulk action check in toggle |
|
| 964 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 965 | + // cycle thru checkboxes |
|
| 966 | + while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 967 | + $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 968 | + $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
| 969 | + } |
|
| 970 | + } elseif (isset($this->_req_data['_regid'])) { |
|
| 971 | + // coming from ajax request |
|
| 972 | + $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
| 973 | + $query_args['DTT_ID'] = $DTT_ID; |
|
| 974 | + $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
| 975 | + } else { |
|
| 976 | + EE_Error::add_error( |
|
| 977 | + esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
| 978 | + __FILE__, |
|
| 979 | + __FUNCTION__, |
|
| 980 | + __LINE__ |
|
| 981 | + ); |
|
| 982 | + } |
|
| 983 | + if (defined('DOING_AJAX')) { |
|
| 984 | + return $new_status; |
|
| 985 | + } |
|
| 986 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 987 | + } |
|
| 988 | 988 | |
| 989 | 989 | |
| 990 | - /** |
|
| 991 | - * This is toggles a single Check-in for the given registration and datetime. |
|
| 992 | - * |
|
| 993 | - * @param int $REG_ID The registration we're toggling |
|
| 994 | - * @param int $DTT_ID The datetime we're toggling |
|
| 995 | - * @return int The new status toggled to. |
|
| 996 | - * @throws EE_Error |
|
| 997 | - * @throws InvalidArgumentException |
|
| 998 | - * @throws InvalidDataTypeException |
|
| 999 | - * @throws InvalidInterfaceException |
|
| 1000 | - */ |
|
| 1001 | - private function _toggle_checkin($REG_ID, $DTT_ID) |
|
| 1002 | - { |
|
| 1003 | - /** @var EE_Registration $REG */ |
|
| 1004 | - $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 1005 | - $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
| 1006 | - if ($new_status !== false) { |
|
| 1007 | - EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
| 1008 | - } else { |
|
| 1009 | - EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
| 1010 | - $new_status = false; |
|
| 1011 | - } |
|
| 1012 | - return $new_status; |
|
| 1013 | - } |
|
| 990 | + /** |
|
| 991 | + * This is toggles a single Check-in for the given registration and datetime. |
|
| 992 | + * |
|
| 993 | + * @param int $REG_ID The registration we're toggling |
|
| 994 | + * @param int $DTT_ID The datetime we're toggling |
|
| 995 | + * @return int The new status toggled to. |
|
| 996 | + * @throws EE_Error |
|
| 997 | + * @throws InvalidArgumentException |
|
| 998 | + * @throws InvalidDataTypeException |
|
| 999 | + * @throws InvalidInterfaceException |
|
| 1000 | + */ |
|
| 1001 | + private function _toggle_checkin($REG_ID, $DTT_ID) |
|
| 1002 | + { |
|
| 1003 | + /** @var EE_Registration $REG */ |
|
| 1004 | + $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 1005 | + $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
| 1006 | + if ($new_status !== false) { |
|
| 1007 | + EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
| 1008 | + } else { |
|
| 1009 | + EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
| 1010 | + $new_status = false; |
|
| 1011 | + } |
|
| 1012 | + return $new_status; |
|
| 1013 | + } |
|
| 1014 | 1014 | |
| 1015 | 1015 | |
| 1016 | - /** |
|
| 1017 | - * Takes care of deleting multiple EE_Checkin table rows |
|
| 1018 | - * |
|
| 1019 | - * @access protected |
|
| 1020 | - * @return void |
|
| 1021 | - * @throws EE_Error |
|
| 1022 | - * @throws InvalidArgumentException |
|
| 1023 | - * @throws InvalidDataTypeException |
|
| 1024 | - * @throws InvalidInterfaceException |
|
| 1025 | - */ |
|
| 1026 | - protected function _delete_checkin_rows() |
|
| 1027 | - { |
|
| 1028 | - $query_args = array( |
|
| 1029 | - 'action' => 'registration_checkins', |
|
| 1030 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
| 1031 | - '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
| 1032 | - ); |
|
| 1033 | - $errors = 0; |
|
| 1034 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1035 | - while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1036 | - if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
| 1037 | - $errors++; |
|
| 1038 | - } |
|
| 1039 | - } |
|
| 1040 | - } else { |
|
| 1041 | - EE_Error::add_error( |
|
| 1042 | - esc_html__( |
|
| 1043 | - 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
| 1044 | - 'event_espresso' |
|
| 1045 | - ), |
|
| 1046 | - __FILE__, |
|
| 1047 | - __FUNCTION__, |
|
| 1048 | - __LINE__ |
|
| 1049 | - ); |
|
| 1050 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1051 | - } |
|
| 1052 | - if ($errors > 0) { |
|
| 1053 | - EE_Error::add_error( |
|
| 1054 | - sprintf(esc_html__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
| 1055 | - __FILE__, |
|
| 1056 | - __FUNCTION__, |
|
| 1057 | - __LINE__ |
|
| 1058 | - ); |
|
| 1059 | - } else { |
|
| 1060 | - EE_Error::add_success(esc_html__('Records were successfully deleted', 'event_espresso')); |
|
| 1061 | - } |
|
| 1062 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1063 | - } |
|
| 1016 | + /** |
|
| 1017 | + * Takes care of deleting multiple EE_Checkin table rows |
|
| 1018 | + * |
|
| 1019 | + * @access protected |
|
| 1020 | + * @return void |
|
| 1021 | + * @throws EE_Error |
|
| 1022 | + * @throws InvalidArgumentException |
|
| 1023 | + * @throws InvalidDataTypeException |
|
| 1024 | + * @throws InvalidInterfaceException |
|
| 1025 | + */ |
|
| 1026 | + protected function _delete_checkin_rows() |
|
| 1027 | + { |
|
| 1028 | + $query_args = array( |
|
| 1029 | + 'action' => 'registration_checkins', |
|
| 1030 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
| 1031 | + '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
| 1032 | + ); |
|
| 1033 | + $errors = 0; |
|
| 1034 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1035 | + while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1036 | + if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
| 1037 | + $errors++; |
|
| 1038 | + } |
|
| 1039 | + } |
|
| 1040 | + } else { |
|
| 1041 | + EE_Error::add_error( |
|
| 1042 | + esc_html__( |
|
| 1043 | + 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
| 1044 | + 'event_espresso' |
|
| 1045 | + ), |
|
| 1046 | + __FILE__, |
|
| 1047 | + __FUNCTION__, |
|
| 1048 | + __LINE__ |
|
| 1049 | + ); |
|
| 1050 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1051 | + } |
|
| 1052 | + if ($errors > 0) { |
|
| 1053 | + EE_Error::add_error( |
|
| 1054 | + sprintf(esc_html__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
| 1055 | + __FILE__, |
|
| 1056 | + __FUNCTION__, |
|
| 1057 | + __LINE__ |
|
| 1058 | + ); |
|
| 1059 | + } else { |
|
| 1060 | + EE_Error::add_success(esc_html__('Records were successfully deleted', 'event_espresso')); |
|
| 1061 | + } |
|
| 1062 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1063 | + } |
|
| 1064 | 1064 | |
| 1065 | 1065 | |
| 1066 | - /** |
|
| 1067 | - * Deletes a single EE_Checkin row |
|
| 1068 | - * |
|
| 1069 | - * @return void |
|
| 1070 | - * @throws EE_Error |
|
| 1071 | - * @throws InvalidArgumentException |
|
| 1072 | - * @throws InvalidDataTypeException |
|
| 1073 | - * @throws InvalidInterfaceException |
|
| 1074 | - */ |
|
| 1075 | - protected function _delete_checkin_row() |
|
| 1076 | - { |
|
| 1077 | - $query_args = array( |
|
| 1078 | - 'action' => 'registration_checkins', |
|
| 1079 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
| 1080 | - '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
| 1081 | - ); |
|
| 1082 | - if (! empty($this->_req_data['CHK_ID'])) { |
|
| 1083 | - if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
| 1084 | - EE_Error::add_error( |
|
| 1085 | - esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
| 1086 | - __FILE__, |
|
| 1087 | - __FUNCTION__, |
|
| 1088 | - __LINE__ |
|
| 1089 | - ); |
|
| 1090 | - } else { |
|
| 1091 | - EE_Error::add_success(esc_html__('Check-In record successfully deleted', 'event_espresso')); |
|
| 1092 | - } |
|
| 1093 | - } else { |
|
| 1094 | - EE_Error::add_error( |
|
| 1095 | - esc_html__( |
|
| 1096 | - 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
| 1097 | - 'event_espresso' |
|
| 1098 | - ), |
|
| 1099 | - __FILE__, |
|
| 1100 | - __FUNCTION__, |
|
| 1101 | - __LINE__ |
|
| 1102 | - ); |
|
| 1103 | - } |
|
| 1104 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1105 | - } |
|
| 1066 | + /** |
|
| 1067 | + * Deletes a single EE_Checkin row |
|
| 1068 | + * |
|
| 1069 | + * @return void |
|
| 1070 | + * @throws EE_Error |
|
| 1071 | + * @throws InvalidArgumentException |
|
| 1072 | + * @throws InvalidDataTypeException |
|
| 1073 | + * @throws InvalidInterfaceException |
|
| 1074 | + */ |
|
| 1075 | + protected function _delete_checkin_row() |
|
| 1076 | + { |
|
| 1077 | + $query_args = array( |
|
| 1078 | + 'action' => 'registration_checkins', |
|
| 1079 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
| 1080 | + '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
| 1081 | + ); |
|
| 1082 | + if (! empty($this->_req_data['CHK_ID'])) { |
|
| 1083 | + if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
| 1084 | + EE_Error::add_error( |
|
| 1085 | + esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
| 1086 | + __FILE__, |
|
| 1087 | + __FUNCTION__, |
|
| 1088 | + __LINE__ |
|
| 1089 | + ); |
|
| 1090 | + } else { |
|
| 1091 | + EE_Error::add_success(esc_html__('Check-In record successfully deleted', 'event_espresso')); |
|
| 1092 | + } |
|
| 1093 | + } else { |
|
| 1094 | + EE_Error::add_error( |
|
| 1095 | + esc_html__( |
|
| 1096 | + 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
| 1097 | + 'event_espresso' |
|
| 1098 | + ), |
|
| 1099 | + __FILE__, |
|
| 1100 | + __FUNCTION__, |
|
| 1101 | + __LINE__ |
|
| 1102 | + ); |
|
| 1103 | + } |
|
| 1104 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1105 | + } |
|
| 1106 | 1106 | |
| 1107 | 1107 | |
| 1108 | - /** |
|
| 1109 | - * generates HTML for the Event Registrations List Table |
|
| 1110 | - * |
|
| 1111 | - * @access protected |
|
| 1112 | - * @return void |
|
| 1113 | - * @throws EE_Error |
|
| 1114 | - * @throws InvalidArgumentException |
|
| 1115 | - * @throws InvalidDataTypeException |
|
| 1116 | - * @throws InvalidInterfaceException |
|
| 1117 | - */ |
|
| 1118 | - protected function _event_registrations_list_table() |
|
| 1119 | - { |
|
| 1120 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1121 | - $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
| 1122 | - ? $this->get_action_link_or_button( |
|
| 1123 | - 'new_registration', |
|
| 1124 | - 'add-registrant', |
|
| 1125 | - array('event_id' => $this->_req_data['event_id']), |
|
| 1126 | - 'add-new-h2', |
|
| 1127 | - '', |
|
| 1128 | - false |
|
| 1129 | - ) |
|
| 1130 | - : ''; |
|
| 1131 | - $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
| 1132 | - $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
| 1133 | - $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never); |
|
| 1134 | - $legend_items = array( |
|
| 1135 | - 'star-icon' => array( |
|
| 1136 | - 'class' => 'dashicons dashicons-star-filled gold-icon', |
|
| 1137 | - 'desc' => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'), |
|
| 1138 | - ), |
|
| 1139 | - 'checkin' => array( |
|
| 1140 | - 'class' => $checked_in->cssClasses(), |
|
| 1141 | - 'desc' => $checked_in->legendLabel(), |
|
| 1142 | - ), |
|
| 1143 | - 'checkout' => array( |
|
| 1144 | - 'class' => $checked_out->cssClasses(), |
|
| 1145 | - 'desc' => $checked_out->legendLabel(), |
|
| 1146 | - ), |
|
| 1147 | - 'nocheckinrecord' => array( |
|
| 1148 | - 'class' => $checked_never->cssClasses(), |
|
| 1149 | - 'desc' => $checked_never->legendLabel(), |
|
| 1150 | - ), |
|
| 1151 | - 'approved_status' => array( |
|
| 1152 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_approved, |
|
| 1153 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
| 1154 | - ), |
|
| 1155 | - 'cancelled_status' => array( |
|
| 1156 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_cancelled, |
|
| 1157 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
| 1158 | - ), |
|
| 1159 | - 'declined_status' => array( |
|
| 1160 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_declined, |
|
| 1161 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
| 1162 | - ), |
|
| 1163 | - 'not_approved' => array( |
|
| 1164 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_not_approved, |
|
| 1165 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
| 1166 | - ), |
|
| 1167 | - 'pending_status' => array( |
|
| 1168 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_pending_payment, |
|
| 1169 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
| 1170 | - ), |
|
| 1171 | - 'wait_list' => array( |
|
| 1172 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_wait_list, |
|
| 1173 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
| 1174 | - ), |
|
| 1175 | - ); |
|
| 1176 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
| 1177 | - $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
| 1178 | - /** @var EE_Event $event */ |
|
| 1179 | - $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
| 1180 | - $this->_template_args['before_list_table'] = $event instanceof EE_Event |
|
| 1181 | - ? '<h2>' . sprintf( |
|
| 1182 | - esc_html__('Viewing Registrations for Event: %s', 'event_espresso'), |
|
| 1183 | - EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
| 1184 | - ) . '</h2>' |
|
| 1185 | - : ''; |
|
| 1186 | - // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on |
|
| 1187 | - // the event. |
|
| 1188 | - $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
| 1189 | - $datetime = null; |
|
| 1190 | - if ($event instanceof EE_Event) { |
|
| 1191 | - $datetimes_on_event = $event->datetimes(); |
|
| 1192 | - if (count($datetimes_on_event) === 1) { |
|
| 1193 | - $datetime = reset($datetimes_on_event); |
|
| 1194 | - } |
|
| 1195 | - } |
|
| 1196 | - $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
| 1197 | - if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
| 1198 | - $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
| 1199 | - $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
| 1200 | - $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
| 1201 | - $this->_template_args['before_list_table'] .= $datetime->name(); |
|
| 1202 | - $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
| 1203 | - $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
| 1204 | - } |
|
| 1205 | - // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status |
|
| 1206 | - // column represents |
|
| 1207 | - if (! $datetime instanceof EE_Datetime) { |
|
| 1208 | - $this->_template_args['before_list_table'] .= '<h3 class="description">' |
|
| 1209 | - . esc_html__( |
|
| 1210 | - 'In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
| 1211 | - 'event_espresso' |
|
| 1212 | - ) |
|
| 1213 | - . '</h3>'; |
|
| 1214 | - } |
|
| 1215 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1216 | - } |
|
| 1108 | + /** |
|
| 1109 | + * generates HTML for the Event Registrations List Table |
|
| 1110 | + * |
|
| 1111 | + * @access protected |
|
| 1112 | + * @return void |
|
| 1113 | + * @throws EE_Error |
|
| 1114 | + * @throws InvalidArgumentException |
|
| 1115 | + * @throws InvalidDataTypeException |
|
| 1116 | + * @throws InvalidInterfaceException |
|
| 1117 | + */ |
|
| 1118 | + protected function _event_registrations_list_table() |
|
| 1119 | + { |
|
| 1120 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1121 | + $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
| 1122 | + ? $this->get_action_link_or_button( |
|
| 1123 | + 'new_registration', |
|
| 1124 | + 'add-registrant', |
|
| 1125 | + array('event_id' => $this->_req_data['event_id']), |
|
| 1126 | + 'add-new-h2', |
|
| 1127 | + '', |
|
| 1128 | + false |
|
| 1129 | + ) |
|
| 1130 | + : ''; |
|
| 1131 | + $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
| 1132 | + $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
| 1133 | + $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never); |
|
| 1134 | + $legend_items = array( |
|
| 1135 | + 'star-icon' => array( |
|
| 1136 | + 'class' => 'dashicons dashicons-star-filled gold-icon', |
|
| 1137 | + 'desc' => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'), |
|
| 1138 | + ), |
|
| 1139 | + 'checkin' => array( |
|
| 1140 | + 'class' => $checked_in->cssClasses(), |
|
| 1141 | + 'desc' => $checked_in->legendLabel(), |
|
| 1142 | + ), |
|
| 1143 | + 'checkout' => array( |
|
| 1144 | + 'class' => $checked_out->cssClasses(), |
|
| 1145 | + 'desc' => $checked_out->legendLabel(), |
|
| 1146 | + ), |
|
| 1147 | + 'nocheckinrecord' => array( |
|
| 1148 | + 'class' => $checked_never->cssClasses(), |
|
| 1149 | + 'desc' => $checked_never->legendLabel(), |
|
| 1150 | + ), |
|
| 1151 | + 'approved_status' => array( |
|
| 1152 | + 'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_approved, |
|
| 1153 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
| 1154 | + ), |
|
| 1155 | + 'cancelled_status' => array( |
|
| 1156 | + 'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_cancelled, |
|
| 1157 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
| 1158 | + ), |
|
| 1159 | + 'declined_status' => array( |
|
| 1160 | + 'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_declined, |
|
| 1161 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
| 1162 | + ), |
|
| 1163 | + 'not_approved' => array( |
|
| 1164 | + 'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_not_approved, |
|
| 1165 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
| 1166 | + ), |
|
| 1167 | + 'pending_status' => array( |
|
| 1168 | + 'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_pending_payment, |
|
| 1169 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
| 1170 | + ), |
|
| 1171 | + 'wait_list' => array( |
|
| 1172 | + 'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_wait_list, |
|
| 1173 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
| 1174 | + ), |
|
| 1175 | + ); |
|
| 1176 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
| 1177 | + $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
| 1178 | + /** @var EE_Event $event */ |
|
| 1179 | + $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
| 1180 | + $this->_template_args['before_list_table'] = $event instanceof EE_Event |
|
| 1181 | + ? '<h2>' . sprintf( |
|
| 1182 | + esc_html__('Viewing Registrations for Event: %s', 'event_espresso'), |
|
| 1183 | + EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
| 1184 | + ) . '</h2>' |
|
| 1185 | + : ''; |
|
| 1186 | + // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on |
|
| 1187 | + // the event. |
|
| 1188 | + $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
| 1189 | + $datetime = null; |
|
| 1190 | + if ($event instanceof EE_Event) { |
|
| 1191 | + $datetimes_on_event = $event->datetimes(); |
|
| 1192 | + if (count($datetimes_on_event) === 1) { |
|
| 1193 | + $datetime = reset($datetimes_on_event); |
|
| 1194 | + } |
|
| 1195 | + } |
|
| 1196 | + $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
| 1197 | + if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
| 1198 | + $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
| 1199 | + $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
| 1200 | + $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
| 1201 | + $this->_template_args['before_list_table'] .= $datetime->name(); |
|
| 1202 | + $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
| 1203 | + $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
| 1204 | + } |
|
| 1205 | + // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status |
|
| 1206 | + // column represents |
|
| 1207 | + if (! $datetime instanceof EE_Datetime) { |
|
| 1208 | + $this->_template_args['before_list_table'] .= '<h3 class="description">' |
|
| 1209 | + . esc_html__( |
|
| 1210 | + 'In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
| 1211 | + 'event_espresso' |
|
| 1212 | + ) |
|
| 1213 | + . '</h3>'; |
|
| 1214 | + } |
|
| 1215 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1216 | + } |
|
| 1217 | 1217 | |
| 1218 | - /** |
|
| 1219 | - * Download the registrations check-in report (same as the normal registration report, but with different where |
|
| 1220 | - * conditions) |
|
| 1221 | - * |
|
| 1222 | - * @return void ends the request by a redirect or download |
|
| 1223 | - */ |
|
| 1224 | - public function _registrations_checkin_report() |
|
| 1225 | - { |
|
| 1226 | - $this->_registrations_report_base('_get_checkin_query_params_from_request'); |
|
| 1227 | - } |
|
| 1218 | + /** |
|
| 1219 | + * Download the registrations check-in report (same as the normal registration report, but with different where |
|
| 1220 | + * conditions) |
|
| 1221 | + * |
|
| 1222 | + * @return void ends the request by a redirect or download |
|
| 1223 | + */ |
|
| 1224 | + public function _registrations_checkin_report() |
|
| 1225 | + { |
|
| 1226 | + $this->_registrations_report_base('_get_checkin_query_params_from_request'); |
|
| 1227 | + } |
|
| 1228 | 1228 | |
| 1229 | - /** |
|
| 1230 | - * Gets the query params from the request, plus adds a where condition for the registration status, |
|
| 1231 | - * because on the checkin page we only ever want to see approved and pending-approval registrations |
|
| 1232 | - * |
|
| 1233 | - * @param array $request |
|
| 1234 | - * @param int $per_page |
|
| 1235 | - * @param bool $count |
|
| 1236 | - * @return array |
|
| 1237 | - * @throws EE_Error |
|
| 1238 | - */ |
|
| 1239 | - protected function _get_checkin_query_params_from_request( |
|
| 1240 | - $request, |
|
| 1241 | - $per_page = 10, |
|
| 1242 | - $count = false |
|
| 1243 | - ) { |
|
| 1244 | - $query_params = $this->_get_registration_query_parameters($request, $per_page, $count); |
|
| 1245 | - // unlike the regular registrations list table, |
|
| 1246 | - $status_ids_array = apply_filters( |
|
| 1247 | - 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
| 1248 | - array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
| 1249 | - ); |
|
| 1250 | - $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
| 1251 | - return $query_params; |
|
| 1252 | - } |
|
| 1229 | + /** |
|
| 1230 | + * Gets the query params from the request, plus adds a where condition for the registration status, |
|
| 1231 | + * because on the checkin page we only ever want to see approved and pending-approval registrations |
|
| 1232 | + * |
|
| 1233 | + * @param array $request |
|
| 1234 | + * @param int $per_page |
|
| 1235 | + * @param bool $count |
|
| 1236 | + * @return array |
|
| 1237 | + * @throws EE_Error |
|
| 1238 | + */ |
|
| 1239 | + protected function _get_checkin_query_params_from_request( |
|
| 1240 | + $request, |
|
| 1241 | + $per_page = 10, |
|
| 1242 | + $count = false |
|
| 1243 | + ) { |
|
| 1244 | + $query_params = $this->_get_registration_query_parameters($request, $per_page, $count); |
|
| 1245 | + // unlike the regular registrations list table, |
|
| 1246 | + $status_ids_array = apply_filters( |
|
| 1247 | + 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
| 1248 | + array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
| 1249 | + ); |
|
| 1250 | + $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
| 1251 | + return $query_params; |
|
| 1252 | + } |
|
| 1253 | 1253 | |
| 1254 | 1254 | |
| 1255 | - /** |
|
| 1256 | - * Gets registrations for an event |
|
| 1257 | - * |
|
| 1258 | - * @param int $per_page |
|
| 1259 | - * @param bool $count whether to return count or data. |
|
| 1260 | - * @param bool $trash |
|
| 1261 | - * @param string $orderby |
|
| 1262 | - * @return EE_Registration[]|int |
|
| 1263 | - * @throws EE_Error |
|
| 1264 | - * @throws InvalidArgumentException |
|
| 1265 | - * @throws InvalidDataTypeException |
|
| 1266 | - * @throws InvalidInterfaceException |
|
| 1267 | - */ |
|
| 1268 | - public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname') |
|
| 1269 | - { |
|
| 1270 | - // normalize some request params that get setup by the parent `get_registrations` method. |
|
| 1271 | - $request = $this->_req_data; |
|
| 1272 | - $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
| 1273 | - $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
| 1274 | - if ($trash) { |
|
| 1275 | - $request['status'] = 'trash'; |
|
| 1276 | - } |
|
| 1277 | - $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count); |
|
| 1278 | - /** |
|
| 1279 | - * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
| 1280 | - * |
|
| 1281 | - * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
| 1282 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1283 | - * or if you have the development copy of EE you can view this at the path: |
|
| 1284 | - * /docs/G--Model-System/model-query-params.md |
|
| 1285 | - */ |
|
| 1286 | - $query_params['group_by'] = ''; |
|
| 1255 | + /** |
|
| 1256 | + * Gets registrations for an event |
|
| 1257 | + * |
|
| 1258 | + * @param int $per_page |
|
| 1259 | + * @param bool $count whether to return count or data. |
|
| 1260 | + * @param bool $trash |
|
| 1261 | + * @param string $orderby |
|
| 1262 | + * @return EE_Registration[]|int |
|
| 1263 | + * @throws EE_Error |
|
| 1264 | + * @throws InvalidArgumentException |
|
| 1265 | + * @throws InvalidDataTypeException |
|
| 1266 | + * @throws InvalidInterfaceException |
|
| 1267 | + */ |
|
| 1268 | + public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname') |
|
| 1269 | + { |
|
| 1270 | + // normalize some request params that get setup by the parent `get_registrations` method. |
|
| 1271 | + $request = $this->_req_data; |
|
| 1272 | + $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
| 1273 | + $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
| 1274 | + if ($trash) { |
|
| 1275 | + $request['status'] = 'trash'; |
|
| 1276 | + } |
|
| 1277 | + $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count); |
|
| 1278 | + /** |
|
| 1279 | + * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
| 1280 | + * |
|
| 1281 | + * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
| 1282 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1283 | + * or if you have the development copy of EE you can view this at the path: |
|
| 1284 | + * /docs/G--Model-System/model-query-params.md |
|
| 1285 | + */ |
|
| 1286 | + $query_params['group_by'] = ''; |
|
| 1287 | 1287 | |
| 1288 | - return $count |
|
| 1289 | - ? EEM_Registration::instance()->count($query_params) |
|
| 1290 | - /** @type EE_Registration[] */ |
|
| 1291 | - : EEM_Registration::instance()->get_all($query_params); |
|
| 1292 | - } |
|
| 1288 | + return $count |
|
| 1289 | + ? EEM_Registration::instance()->count($query_params) |
|
| 1290 | + /** @type EE_Registration[] */ |
|
| 1291 | + : EEM_Registration::instance()->get_all($query_params); |
|
| 1292 | + } |
|
| 1293 | 1293 | } |
@@ -32,10 +32,10 @@ discard block |
||
| 32 | 32 | public function __construct($routing = true) |
| 33 | 33 | { |
| 34 | 34 | parent::__construct($routing); |
| 35 | - if (! defined('REG_CAF_TEMPLATE_PATH')) { |
|
| 36 | - define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
| 37 | - define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
| 38 | - define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
| 35 | + if ( ! defined('REG_CAF_TEMPLATE_PATH')) { |
|
| 36 | + define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'registrations/templates/'); |
|
| 37 | + define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'registrations/assets/'); |
|
| 38 | + define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registrations/assets/'); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | protected function _extend_page_config() |
| 47 | 47 | { |
| 48 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
| 48 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'registrations'; |
|
| 49 | 49 | $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
| 50 | 50 | ? $this->_req_data['_REG_ID'] |
| 51 | 51 | : 0; |
@@ -186,14 +186,14 @@ discard block |
||
| 186 | 186 | // enqueue newsletter js |
| 187 | 187 | wp_enqueue_script( |
| 188 | 188 | 'ee-newsletter-trigger', |
| 189 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
| 189 | + REG_CAF_ASSETS_URL.'ee-newsletter-trigger.js', |
|
| 190 | 190 | array('ee-dialog'), |
| 191 | 191 | EVENT_ESPRESSO_VERSION, |
| 192 | 192 | true |
| 193 | 193 | ); |
| 194 | 194 | wp_enqueue_style( |
| 195 | 195 | 'ee-newsletter-trigger-css', |
| 196 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
| 196 | + REG_CAF_ASSETS_URL.'ee-newsletter-trigger.css', |
|
| 197 | 197 | array(), |
| 198 | 198 | EVENT_ESPRESSO_VERSION |
| 199 | 199 | ); |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | { |
| 215 | 215 | wp_register_script( |
| 216 | 216 | 'ee-reg-reports-js', |
| 217 | - REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
| 217 | + REG_CAF_ASSETS_URL.'ee-registration-admin-reports.js', |
|
| 218 | 218 | array('google-charts'), |
| 219 | 219 | EVENT_ESPRESSO_VERSION, |
| 220 | 220 | true |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | $nonce_ref = 'get_newsletter_form_content_nonce'; |
| 301 | 301 | $this->_verify_nonce($nonce, $nonce_ref); |
| 302 | 302 | // let's get the mtp for the incoming MTP_ ID |
| 303 | - if (! isset($this->_req_data['GRP_ID'])) { |
|
| 303 | + if ( ! isset($this->_req_data['GRP_ID'])) { |
|
| 304 | 304 | EE_Error::add_error( |
| 305 | 305 | esc_html__( |
| 306 | 306 | 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | $this->_return_json(); |
| 316 | 316 | } |
| 317 | 317 | $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
| 318 | - if (! $MTPG instanceof EE_Message_Template_Group) { |
|
| 318 | + if ( ! $MTPG instanceof EE_Message_Template_Group) { |
|
| 319 | 319 | EE_Error::add_error( |
| 320 | 320 | sprintf( |
| 321 | 321 | esc_html__( |
@@ -340,12 +340,12 @@ discard block |
||
| 340 | 340 | $field = $MTP->get('MTP_template_field'); |
| 341 | 341 | if ($field === 'content') { |
| 342 | 342 | $content = $MTP->get('MTP_content'); |
| 343 | - if (! empty($content['newsletter_content'])) { |
|
| 343 | + if ( ! empty($content['newsletter_content'])) { |
|
| 344 | 344 | $template_fields['newsletter_content'] = $content['newsletter_content']; |
| 345 | 345 | } |
| 346 | 346 | continue; |
| 347 | 347 | } |
| 348 | - $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content'); |
|
| 348 | + $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content'); |
|
| 349 | 349 | } |
| 350 | 350 | $this->_template_args['success'] = true; |
| 351 | 351 | $this->_template_args['error'] = false; |
@@ -447,17 +447,17 @@ discard block |
||
| 447 | 447 | $field_id = $field === '[NEWSLETTER_CONTENT]' |
| 448 | 448 | ? 'content' |
| 449 | 449 | : $field; |
| 450 | - $field_id = 'batch-message-' . strtolower($field_id); |
|
| 450 | + $field_id = 'batch-message-'.strtolower($field_id); |
|
| 451 | 451 | $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="' |
| 452 | 452 | . $shortcode |
| 453 | - . '" data-linked-input-id="' . $field_id . '">' |
|
| 453 | + . '" data-linked-input-id="'.$field_id.'">' |
|
| 454 | 454 | . $shortcode |
| 455 | 455 | . '</span>'; |
| 456 | 456 | } |
| 457 | - $codes[ $field ] = implode(', ', $available_shortcodes); |
|
| 457 | + $codes[$field] = implode(', ', $available_shortcodes); |
|
| 458 | 458 | } |
| 459 | 459 | $shortcodes = $codes; |
| 460 | - $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
| 460 | + $form_template = REG_CAF_TEMPLATE_PATH.'newsletter-send-form.template.php'; |
|
| 461 | 461 | $form_template_args = array( |
| 462 | 462 | 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
| 463 | 463 | 'form_route' => 'newsletter_selected_send', |
@@ -625,7 +625,7 @@ discard block |
||
| 625 | 625 | */ |
| 626 | 626 | protected function _registration_reports() |
| 627 | 627 | { |
| 628 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
| 628 | + $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php'; |
|
| 629 | 629 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 630 | 630 | $template_path, |
| 631 | 631 | $this->_reports_template_data, |
@@ -680,7 +680,7 @@ discard block |
||
| 680 | 680 | array_unshift($regs, $column_titles); |
| 681 | 681 | // setup the date range. |
| 682 | 682 | $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
| 683 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 683 | + $beginning_date = new DateTime("now ".$period, $DateTimeZone); |
|
| 684 | 684 | $ending_date = new DateTime("now", $DateTimeZone); |
| 685 | 685 | $subtitle = sprintf( |
| 686 | 686 | wp_strip_all_tags( |
@@ -704,7 +704,7 @@ discard block |
||
| 704 | 704 | 'event_espresso' |
| 705 | 705 | ) |
| 706 | 706 | ), |
| 707 | - '<h2>' . $report_title . '</h2><p>', |
|
| 707 | + '<h2>'.$report_title.'</h2><p>', |
|
| 708 | 708 | '</p>' |
| 709 | 709 | ), |
| 710 | 710 | ); |
@@ -757,7 +757,7 @@ discard block |
||
| 757 | 757 | array_unshift($regs, $column_titles); |
| 758 | 758 | // setup the date range. |
| 759 | 759 | $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
| 760 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 760 | + $beginning_date = new DateTime("now ".$period, $DateTimeZone); |
|
| 761 | 761 | $ending_date = new DateTime("now", $DateTimeZone); |
| 762 | 762 | $subtitle = sprintf( |
| 763 | 763 | wp_strip_all_tags( |
@@ -781,7 +781,7 @@ discard block |
||
| 781 | 781 | 'event_espresso' |
| 782 | 782 | ) |
| 783 | 783 | ), |
| 784 | - '<h2>' . $report_title . '</h2><p>', |
|
| 784 | + '<h2>'.$report_title.'</h2><p>', |
|
| 785 | 785 | '</p>' |
| 786 | 786 | ), |
| 787 | 787 | ); |
@@ -807,7 +807,7 @@ discard block |
||
| 807 | 807 | $reg_id = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : null; |
| 808 | 808 | /** @var EE_Registration $registration */ |
| 809 | 809 | $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
| 810 | - if (! $registration instanceof EE_Registration) { |
|
| 810 | + if ( ! $registration instanceof EE_Registration) { |
|
| 811 | 811 | throw new EE_Error( |
| 812 | 812 | sprintf( |
| 813 | 813 | esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'), |
@@ -842,7 +842,7 @@ discard block |
||
| 842 | 842 | if ($datetime instanceof EE_Datetime) { |
| 843 | 843 | $datetime_label = $datetime->get_dtt_display_name(true); |
| 844 | 844 | $datetime_label .= ! empty($datetime_label) |
| 845 | - ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
| 845 | + ? ' ('.$datetime->get_dtt_display_name().')' |
|
| 846 | 846 | : $datetime->get_dtt_display_name(); |
| 847 | 847 | } |
| 848 | 848 | $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
@@ -856,7 +856,7 @@ discard block |
||
| 856 | 856 | ) |
| 857 | 857 | : ''; |
| 858 | 858 | $datetime_link = ! empty($datetime_link) |
| 859 | - ? '<a href="' . $datetime_link . '">' |
|
| 859 | + ? '<a href="'.$datetime_link.'">' |
|
| 860 | 860 | . '<span id="checkin-dtt">' |
| 861 | 861 | . $datetime_label |
| 862 | 862 | . '</span></a>' |
@@ -868,8 +868,8 @@ discard block |
||
| 868 | 868 | ? $attendee->get_admin_details_link() |
| 869 | 869 | : ''; |
| 870 | 870 | $attendee_link = ! empty($attendee_link) |
| 871 | - ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
| 872 | - . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
| 871 | + ? '<a href="'.$attendee->get_admin_details_link().'"' |
|
| 872 | + . ' title="'.esc_html__('Click for attendee details', 'event_espresso').'">' |
|
| 873 | 873 | . '<span id="checkin-attendee-name">' |
| 874 | 874 | . $attendee_name |
| 875 | 875 | . '</span></a>' |
@@ -878,25 +878,25 @@ discard block |
||
| 878 | 878 | ? $registration->event()->get_admin_details_link() |
| 879 | 879 | : ''; |
| 880 | 880 | $event_link = ! empty($event_link) |
| 881 | - ? '<a href="' . $event_link . '"' |
|
| 882 | - . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
| 881 | + ? '<a href="'.$event_link.'"' |
|
| 882 | + . ' title="'.esc_html__('Click here to edit event.', 'event_espresso').'">' |
|
| 883 | 883 | . '<span id="checkin-event-name">' |
| 884 | 884 | . $registration->event_name() |
| 885 | 885 | . '</span>' |
| 886 | 886 | . '</a>' |
| 887 | 887 | : ''; |
| 888 | 888 | $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
| 889 | - ? '<h2>' . sprintf( |
|
| 889 | + ? '<h2>'.sprintf( |
|
| 890 | 890 | esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
| 891 | 891 | $attendee_link, |
| 892 | 892 | $datetime_link, |
| 893 | 893 | $event_link |
| 894 | - ) . '</h2>' |
|
| 894 | + ).'</h2>' |
|
| 895 | 895 | : ''; |
| 896 | 896 | $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
| 897 | - ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : ''; |
|
| 897 | + ? '<input type="hidden" name="_REG_ID" value="'.$reg_id.'">' : ''; |
|
| 898 | 898 | $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
| 899 | - ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
| 899 | + ? '<input type="hidden" name="DTT_ID" value="'.$dtt_id.'">' : ''; |
|
| 900 | 900 | $this->display_admin_list_table_page_with_no_sidebar(); |
| 901 | 901 | } |
| 902 | 902 | |
@@ -913,7 +913,7 @@ discard block |
||
| 913 | 913 | public function toggle_checkin_status() |
| 914 | 914 | { |
| 915 | 915 | // first make sure we have the necessary data |
| 916 | - if (! isset($this->_req_data['_regid'])) { |
|
| 916 | + if ( ! isset($this->_req_data['_regid'])) { |
|
| 917 | 917 | EE_Error::add_error( |
| 918 | 918 | esc_html__( |
| 919 | 919 | 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
@@ -935,7 +935,7 @@ discard block |
||
| 935 | 935 | // beautiful! Made it this far so let's get the status. |
| 936 | 936 | $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
| 937 | 937 | // setup new class to return via ajax |
| 938 | - $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
| 938 | + $this->_template_args['admin_page_content'] = 'clickable trigger-checkin '.$new_status->cssClasses(); |
|
| 939 | 939 | $this->_template_args['success'] = true; |
| 940 | 940 | $this->_return_json(); |
| 941 | 941 | } |
@@ -961,7 +961,7 @@ discard block |
||
| 961 | 961 | ); |
| 962 | 962 | $new_status = false; |
| 963 | 963 | // bulk action check in toggle |
| 964 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 964 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 965 | 965 | // cycle thru checkboxes |
| 966 | 966 | while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
| 967 | 967 | $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
@@ -1031,9 +1031,9 @@ discard block |
||
| 1031 | 1031 | '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
| 1032 | 1032 | ); |
| 1033 | 1033 | $errors = 0; |
| 1034 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1034 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1035 | 1035 | while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
| 1036 | - if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
| 1036 | + if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
| 1037 | 1037 | $errors++; |
| 1038 | 1038 | } |
| 1039 | 1039 | } |
@@ -1079,8 +1079,8 @@ discard block |
||
| 1079 | 1079 | 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
| 1080 | 1080 | '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
| 1081 | 1081 | ); |
| 1082 | - if (! empty($this->_req_data['CHK_ID'])) { |
|
| 1083 | - if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
| 1082 | + if ( ! empty($this->_req_data['CHK_ID'])) { |
|
| 1083 | + if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
| 1084 | 1084 | EE_Error::add_error( |
| 1085 | 1085 | esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
| 1086 | 1086 | __FILE__, |
@@ -1149,27 +1149,27 @@ discard block |
||
| 1149 | 1149 | 'desc' => $checked_never->legendLabel(), |
| 1150 | 1150 | ), |
| 1151 | 1151 | 'approved_status' => array( |
| 1152 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_approved, |
|
| 1152 | + 'class' => 'ee-status-legend ee-status-bg--'.EEM_Registration::status_id_approved, |
|
| 1153 | 1153 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
| 1154 | 1154 | ), |
| 1155 | 1155 | 'cancelled_status' => array( |
| 1156 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_cancelled, |
|
| 1156 | + 'class' => 'ee-status-legend ee-status-bg--'.EEM_Registration::status_id_cancelled, |
|
| 1157 | 1157 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
| 1158 | 1158 | ), |
| 1159 | 1159 | 'declined_status' => array( |
| 1160 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_declined, |
|
| 1160 | + 'class' => 'ee-status-legend ee-status-bg--'.EEM_Registration::status_id_declined, |
|
| 1161 | 1161 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
| 1162 | 1162 | ), |
| 1163 | 1163 | 'not_approved' => array( |
| 1164 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_not_approved, |
|
| 1164 | + 'class' => 'ee-status-legend ee-status-bg--'.EEM_Registration::status_id_not_approved, |
|
| 1165 | 1165 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
| 1166 | 1166 | ), |
| 1167 | 1167 | 'pending_status' => array( |
| 1168 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_pending_payment, |
|
| 1168 | + 'class' => 'ee-status-legend ee-status-bg--'.EEM_Registration::status_id_pending_payment, |
|
| 1169 | 1169 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
| 1170 | 1170 | ), |
| 1171 | 1171 | 'wait_list' => array( |
| 1172 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_wait_list, |
|
| 1172 | + 'class' => 'ee-status-legend ee-status-bg--'.EEM_Registration::status_id_wait_list, |
|
| 1173 | 1173 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
| 1174 | 1174 | ), |
| 1175 | 1175 | ); |
@@ -1178,10 +1178,10 @@ discard block |
||
| 1178 | 1178 | /** @var EE_Event $event */ |
| 1179 | 1179 | $event = EEM_Event::instance()->get_one_by_ID($event_id); |
| 1180 | 1180 | $this->_template_args['before_list_table'] = $event instanceof EE_Event |
| 1181 | - ? '<h2>' . sprintf( |
|
| 1181 | + ? '<h2>'.sprintf( |
|
| 1182 | 1182 | esc_html__('Viewing Registrations for Event: %s', 'event_espresso'), |
| 1183 | 1183 | EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
| 1184 | - ) . '</h2>' |
|
| 1184 | + ).'</h2>' |
|
| 1185 | 1185 | : ''; |
| 1186 | 1186 | // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on |
| 1187 | 1187 | // the event. |
@@ -1199,12 +1199,12 @@ discard block |
||
| 1199 | 1199 | $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
| 1200 | 1200 | $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
| 1201 | 1201 | $this->_template_args['before_list_table'] .= $datetime->name(); |
| 1202 | - $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
| 1202 | + $this->_template_args['before_list_table'] .= ' ( '.$datetime->date_and_time_range().' )'; |
|
| 1203 | 1203 | $this->_template_args['before_list_table'] .= '</span></h2>'; |
| 1204 | 1204 | } |
| 1205 | 1205 | // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status |
| 1206 | 1206 | // column represents |
| 1207 | - if (! $datetime instanceof EE_Datetime) { |
|
| 1207 | + if ( ! $datetime instanceof EE_Datetime) { |
|
| 1208 | 1208 | $this->_template_args['before_list_table'] .= '<h3 class="description">' |
| 1209 | 1209 | . esc_html__( |
| 1210 | 1210 | 'In this view, the check-in status represents the latest check-in record for the registration in that row.', |
@@ -12,336 +12,336 @@ discard block |
||
| 12 | 12 | class EE_Event_Registrations_List_Table extends EE_Admin_List_Table |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * This property will hold the related Datetimes on an event IF the event id is included in the request. |
|
| 17 | - * |
|
| 18 | - * @var EE_Datetime[] |
|
| 19 | - */ |
|
| 20 | - protected $_dtts_for_event = []; |
|
| 21 | - |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * The event if one is specified in the request |
|
| 25 | - * |
|
| 26 | - * @var EE_Event |
|
| 27 | - */ |
|
| 28 | - protected $_evt = null; |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * The DTT_ID if the current view has a specified datetime. |
|
| 33 | - * |
|
| 34 | - * @var int $_cur_dtt_id |
|
| 35 | - */ |
|
| 36 | - protected $_cur_dtt_id = 0; |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * EE_Event_Registrations_List_Table constructor. |
|
| 41 | - * |
|
| 42 | - * @param Registrations_Admin_Page $admin_page |
|
| 43 | - */ |
|
| 44 | - public function __construct($admin_page) |
|
| 45 | - { |
|
| 46 | - parent::__construct($admin_page); |
|
| 47 | - $this->_status = $this->_admin_page->get_registration_status_array(); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - protected function _setup_data() |
|
| 52 | - { |
|
| 53 | - $this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees($this->_per_page) |
|
| 54 | - : $this->_admin_page->get_event_attendees($this->_per_page, false, true); |
|
| 55 | - $this->_all_data_count = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees( |
|
| 56 | - $this->_per_page, |
|
| 57 | - true |
|
| 58 | - ) : $this->_admin_page->get_event_attendees($this->_per_page, true, true); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - protected function _set_properties() |
|
| 63 | - { |
|
| 64 | - $return_url = $this->getReturnUrl(); |
|
| 65 | - |
|
| 66 | - $evt_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
| 67 | - $this->_wp_list_args = [ |
|
| 68 | - 'singular' => esc_html__('registrant', 'event_espresso'), |
|
| 69 | - 'plural' => esc_html__('registrants', 'event_espresso'), |
|
| 70 | - 'ajax' => true, |
|
| 71 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 72 | - ]; |
|
| 73 | - $columns = []; |
|
| 74 | - $this->_columns = [ |
|
| 75 | - '_REG_att_checked_in' => esc_html__('Check In', 'event_espresso'), |
|
| 76 | - 'ATT_name' => esc_html__('Registrant', 'event_espresso'), |
|
| 77 | - 'ATT_email' => esc_html__('Email Address', 'event_espresso'), |
|
| 78 | - 'Event' => esc_html__('Event', 'event_espresso'), |
|
| 79 | - 'PRC_name' => esc_html__('TKT Option', 'event_espresso'), |
|
| 80 | - '_REG_final_price' => esc_html__('Price', 'event_espresso'), |
|
| 81 | - 'TXN_paid' => esc_html__('Paid', 'event_espresso'), |
|
| 82 | - 'TXN_total' => esc_html__('Total', 'event_espresso'), |
|
| 83 | - ]; |
|
| 84 | - // Add/remove columns when an event has been selected |
|
| 85 | - if (! empty($evt_id)) { |
|
| 86 | - // Render a checkbox column |
|
| 87 | - $columns['cb'] = '<input type="checkbox" />'; |
|
| 88 | - $this->_has_checkbox_column = true; |
|
| 89 | - // Remove the 'Event' column |
|
| 90 | - unset($this->_columns['Event']); |
|
| 91 | - } |
|
| 92 | - $this->_columns = array_merge($columns, $this->_columns); |
|
| 93 | - $this->_primary_column = '_REG_att_checked_in'; |
|
| 94 | - if ( |
|
| 95 | - ! empty($evt_id) |
|
| 96 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 97 | - 'ee_read_registrations', |
|
| 98 | - 'espresso_registrations_registrations_reports', |
|
| 99 | - $evt_id |
|
| 100 | - ) |
|
| 101 | - ) { |
|
| 102 | - $this->_bottom_buttons = [ |
|
| 103 | - 'report' => [ |
|
| 104 | - 'route' => 'registrations_report', |
|
| 105 | - 'extra_request' => |
|
| 106 | - [ |
|
| 107 | - 'EVT_ID' => $evt_id, |
|
| 108 | - 'return_url' => $return_url, |
|
| 109 | - ], |
|
| 110 | - ], |
|
| 111 | - ]; |
|
| 112 | - } |
|
| 113 | - $this->_bottom_buttons['report_filtered'] = [ |
|
| 114 | - 'route' => 'registrations_checkin_report', |
|
| 115 | - 'extra_request' => [ |
|
| 116 | - 'use_filters' => true, |
|
| 117 | - 'filters' => array_merge( |
|
| 118 | - [ |
|
| 119 | - 'EVT_ID' => $evt_id, |
|
| 120 | - ], |
|
| 121 | - array_diff_key( |
|
| 122 | - $this->_req_data, |
|
| 123 | - array_flip( |
|
| 124 | - [ |
|
| 125 | - 'page', |
|
| 126 | - 'action', |
|
| 127 | - 'default_nonce', |
|
| 128 | - ] |
|
| 129 | - ) |
|
| 130 | - ) |
|
| 131 | - ), |
|
| 132 | - 'return_url' => $return_url, |
|
| 133 | - ], |
|
| 134 | - ]; |
|
| 135 | - $this->_sortable_columns = [ |
|
| 136 | - /** |
|
| 137 | - * Allows users to change the default sort if they wish. |
|
| 138 | - * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name. |
|
| 139 | - * |
|
| 140 | - * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to |
|
| 141 | - * change the sorts on any list table involving registration contacts. If you want to only change the filter |
|
| 142 | - * for a specific list table you can use the provided reference to this object instance. |
|
| 143 | - */ |
|
| 144 | - 'ATT_name' => [ |
|
| 145 | - 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
| 146 | - true, |
|
| 147 | - $this, |
|
| 148 | - ] |
|
| 149 | - ? ['ATT_lname' => true] |
|
| 150 | - : ['ATT_fname' => true], |
|
| 151 | - 'Event' => ['Event.EVT_name' => false], |
|
| 152 | - ]; |
|
| 153 | - $this->_hidden_columns = []; |
|
| 154 | - $this->_evt = EEM_Event::instance()->get_one_by_ID($evt_id); |
|
| 155 | - $this->_dtts_for_event = |
|
| 156 | - $this->_evt instanceof EE_Event ? $this->_evt->datetimes_ordered() : []; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * @param EE_Registration $registration |
|
| 162 | - * @return string |
|
| 163 | - */ |
|
| 164 | - protected function _get_row_class($registration) |
|
| 165 | - { |
|
| 166 | - $class = parent::_get_row_class($registration); |
|
| 167 | - if ($this->_has_checkbox_column) { |
|
| 168 | - $class .= ' has-checkbox-column'; |
|
| 169 | - } |
|
| 170 | - return $class; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * @return array |
|
| 176 | - * @throws EE_Error |
|
| 177 | - * @throws ReflectionException |
|
| 178 | - */ |
|
| 179 | - protected function _get_table_filters() |
|
| 180 | - { |
|
| 181 | - $filters = $where = []; |
|
| 182 | - $current_EVT_ID = isset($this->_req_data['event_id']) ? (int) $this->_req_data['event_id'] : 0; |
|
| 183 | - if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) { |
|
| 184 | - // this means we don't have an event so let's setup a filter dropdown for all the events to select |
|
| 185 | - // note possible capability restrictions |
|
| 186 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 187 | - $where['status**'] = ['!=', 'private']; |
|
| 188 | - } |
|
| 189 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 190 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
| 191 | - } |
|
| 192 | - $events = EEM_Event::instance()->get_all( |
|
| 193 | - [ |
|
| 194 | - $where, |
|
| 195 | - 'order_by' => ['Datetime.DTT_EVT_start' => 'DESC'], |
|
| 196 | - ] |
|
| 197 | - ); |
|
| 198 | - $evts[] = [ |
|
| 199 | - 'id' => 0, |
|
| 200 | - 'text' => esc_html__(' - select an event - ', 'event_espresso'), |
|
| 201 | - ]; |
|
| 202 | - $checked = 'checked'; |
|
| 203 | - /** @var EE_Event $evt */ |
|
| 204 | - foreach ($events as $evt) { |
|
| 205 | - // any registrations for this event? |
|
| 206 | - if (! $evt->get_count_of_all_registrations()) { |
|
| 207 | - continue; |
|
| 208 | - } |
|
| 209 | - $evts[] = [ |
|
| 210 | - 'id' => $evt->ID(), |
|
| 211 | - 'text' => apply_filters( |
|
| 212 | - 'FHEE__EE_Event_Registrations___get_table_filters__event_name', |
|
| 213 | - $evt->get('EVT_name'), |
|
| 214 | - $evt |
|
| 215 | - ), |
|
| 216 | - 'class' => $evt->is_expired() ? 'ee-expired-event' : '', |
|
| 217 | - ]; |
|
| 218 | - if ($evt->ID() === $current_EVT_ID && $evt->is_expired()) { |
|
| 219 | - $checked = ''; |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - $event_filter = '<div class="ee-event-filter">'; |
|
| 223 | - $event_filter .= '<label for="event_id">'; |
|
| 224 | - $event_filter .= esc_html__('Check-in Status for', 'event_espresso'); |
|
| 225 | - $event_filter .= '</label> '; |
|
| 226 | - $event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID); |
|
| 227 | - $event_filter .= '<span class="ee-event-filter-toggle">'; |
|
| 228 | - $event_filter .= '<label for="js-ee-hide-expired-events">'; |
|
| 229 | - $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> '; |
|
| 230 | - $event_filter .= esc_html__('Hide Expired Events', 'event_espresso'); |
|
| 231 | - $event_filter .= '</label>'; |
|
| 232 | - $event_filter .= '</span>'; |
|
| 233 | - $event_filter .= '</div>'; |
|
| 234 | - $filters[] = $event_filter; |
|
| 235 | - } |
|
| 236 | - if (! empty($this->_dtts_for_event)) { |
|
| 237 | - // DTT datetimes filter |
|
| 238 | - $this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0; |
|
| 239 | - if (count($this->_dtts_for_event) > 1) { |
|
| 240 | - $dtts[0] = esc_html__('To toggle check-in status, select a datetime.', 'event_espresso'); |
|
| 241 | - foreach ($this->_dtts_for_event as $dtt) { |
|
| 242 | - $datetime_string = $dtt->name(); |
|
| 243 | - $datetime_string = ! empty($datetime_string) ? ' (' . $datetime_string . ')' : ''; |
|
| 244 | - $datetime_string = |
|
| 245 | - $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string; |
|
| 246 | - $dtts[ $dtt->ID() ] = $datetime_string; |
|
| 247 | - } |
|
| 248 | - $input = new EE_Select_Input( |
|
| 249 | - $dtts, |
|
| 250 | - [ |
|
| 251 | - 'html_name' => 'DTT_ID', |
|
| 252 | - 'html_id' => 'DTT_ID', |
|
| 253 | - 'default' => $this->_cur_dtt_id, |
|
| 254 | - ] |
|
| 255 | - ); |
|
| 256 | - $filters[] = $input->get_html_for_input(); |
|
| 257 | - $filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">'; |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - return $filters; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - protected function _add_view_counts() |
|
| 265 | - { |
|
| 266 | - $this->_views['all']['count'] = $this->_get_total_event_attendees(); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * @return int |
|
| 272 | - * @throws EE_Error |
|
| 273 | - * @throws ReflectionException |
|
| 274 | - */ |
|
| 275 | - protected function _get_total_event_attendees() |
|
| 276 | - { |
|
| 277 | - $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
| 278 | - $DTT_ID = $this->_cur_dtt_id; |
|
| 279 | - $query_params = []; |
|
| 280 | - if ($EVT_ID) { |
|
| 281 | - $query_params[0]['EVT_ID'] = $EVT_ID; |
|
| 282 | - } |
|
| 283 | - // if DTT is included we only show for that datetime. Otherwise we're showing for all datetimes (the event). |
|
| 284 | - if ($DTT_ID) { |
|
| 285 | - $query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID; |
|
| 286 | - } |
|
| 287 | - $status_ids_array = apply_filters( |
|
| 288 | - 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
| 289 | - [EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved] |
|
| 290 | - ); |
|
| 291 | - $query_params[0]['STS_ID'] = ['IN', $status_ids_array]; |
|
| 292 | - return EEM_Registration::instance()->count($query_params); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * @param EE_Registration $registration |
|
| 298 | - * @return string |
|
| 299 | - * @throws EE_Error |
|
| 300 | - * @throws ReflectionException |
|
| 301 | - */ |
|
| 302 | - public function column_cb($registration) |
|
| 303 | - { |
|
| 304 | - return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $registration->ID()); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * column_REG_att_checked_in |
|
| 310 | - * |
|
| 311 | - * @param EE_Registration $registration |
|
| 312 | - * @return string |
|
| 313 | - * @throws EE_Error |
|
| 314 | - * @throws InvalidArgumentException |
|
| 315 | - * @throws InvalidDataTypeException |
|
| 316 | - * @throws InvalidInterfaceException |
|
| 317 | - * @throws ReflectionException |
|
| 318 | - */ |
|
| 319 | - public function column__REG_att_checked_in(EE_Registration $registration) |
|
| 320 | - { |
|
| 321 | - $attendee = $registration->attendee(); |
|
| 322 | - $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
| 323 | - |
|
| 324 | - if ($this->_cur_dtt_id === 0 && count($this->_dtts_for_event) === 1) { |
|
| 325 | - $latest_related_datetime = $registration->get_latest_related_datetime(); |
|
| 326 | - if ($latest_related_datetime instanceof EE_Datetime) { |
|
| 327 | - $this->_cur_dtt_id = $latest_related_datetime->ID(); |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - $checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId( |
|
| 331 | - $registration, |
|
| 332 | - $this->_cur_dtt_id |
|
| 333 | - ); |
|
| 334 | - $nonce = wp_create_nonce('checkin_nonce'); |
|
| 335 | - $toggle_active = ! empty($this->_cur_dtt_id) |
|
| 336 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 337 | - 'ee_edit_checkin', |
|
| 338 | - 'espresso_registrations_toggle_checkin_status', |
|
| 339 | - $registration->ID() |
|
| 340 | - ) |
|
| 341 | - ? ' clickable trigger-checkin' |
|
| 342 | - : ''; |
|
| 343 | - $mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
|
| 344 | - return ' |
|
| 15 | + /** |
|
| 16 | + * This property will hold the related Datetimes on an event IF the event id is included in the request. |
|
| 17 | + * |
|
| 18 | + * @var EE_Datetime[] |
|
| 19 | + */ |
|
| 20 | + protected $_dtts_for_event = []; |
|
| 21 | + |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * The event if one is specified in the request |
|
| 25 | + * |
|
| 26 | + * @var EE_Event |
|
| 27 | + */ |
|
| 28 | + protected $_evt = null; |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * The DTT_ID if the current view has a specified datetime. |
|
| 33 | + * |
|
| 34 | + * @var int $_cur_dtt_id |
|
| 35 | + */ |
|
| 36 | + protected $_cur_dtt_id = 0; |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * EE_Event_Registrations_List_Table constructor. |
|
| 41 | + * |
|
| 42 | + * @param Registrations_Admin_Page $admin_page |
|
| 43 | + */ |
|
| 44 | + public function __construct($admin_page) |
|
| 45 | + { |
|
| 46 | + parent::__construct($admin_page); |
|
| 47 | + $this->_status = $this->_admin_page->get_registration_status_array(); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + protected function _setup_data() |
|
| 52 | + { |
|
| 53 | + $this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees($this->_per_page) |
|
| 54 | + : $this->_admin_page->get_event_attendees($this->_per_page, false, true); |
|
| 55 | + $this->_all_data_count = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees( |
|
| 56 | + $this->_per_page, |
|
| 57 | + true |
|
| 58 | + ) : $this->_admin_page->get_event_attendees($this->_per_page, true, true); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + protected function _set_properties() |
|
| 63 | + { |
|
| 64 | + $return_url = $this->getReturnUrl(); |
|
| 65 | + |
|
| 66 | + $evt_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
| 67 | + $this->_wp_list_args = [ |
|
| 68 | + 'singular' => esc_html__('registrant', 'event_espresso'), |
|
| 69 | + 'plural' => esc_html__('registrants', 'event_espresso'), |
|
| 70 | + 'ajax' => true, |
|
| 71 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 72 | + ]; |
|
| 73 | + $columns = []; |
|
| 74 | + $this->_columns = [ |
|
| 75 | + '_REG_att_checked_in' => esc_html__('Check In', 'event_espresso'), |
|
| 76 | + 'ATT_name' => esc_html__('Registrant', 'event_espresso'), |
|
| 77 | + 'ATT_email' => esc_html__('Email Address', 'event_espresso'), |
|
| 78 | + 'Event' => esc_html__('Event', 'event_espresso'), |
|
| 79 | + 'PRC_name' => esc_html__('TKT Option', 'event_espresso'), |
|
| 80 | + '_REG_final_price' => esc_html__('Price', 'event_espresso'), |
|
| 81 | + 'TXN_paid' => esc_html__('Paid', 'event_espresso'), |
|
| 82 | + 'TXN_total' => esc_html__('Total', 'event_espresso'), |
|
| 83 | + ]; |
|
| 84 | + // Add/remove columns when an event has been selected |
|
| 85 | + if (! empty($evt_id)) { |
|
| 86 | + // Render a checkbox column |
|
| 87 | + $columns['cb'] = '<input type="checkbox" />'; |
|
| 88 | + $this->_has_checkbox_column = true; |
|
| 89 | + // Remove the 'Event' column |
|
| 90 | + unset($this->_columns['Event']); |
|
| 91 | + } |
|
| 92 | + $this->_columns = array_merge($columns, $this->_columns); |
|
| 93 | + $this->_primary_column = '_REG_att_checked_in'; |
|
| 94 | + if ( |
|
| 95 | + ! empty($evt_id) |
|
| 96 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 97 | + 'ee_read_registrations', |
|
| 98 | + 'espresso_registrations_registrations_reports', |
|
| 99 | + $evt_id |
|
| 100 | + ) |
|
| 101 | + ) { |
|
| 102 | + $this->_bottom_buttons = [ |
|
| 103 | + 'report' => [ |
|
| 104 | + 'route' => 'registrations_report', |
|
| 105 | + 'extra_request' => |
|
| 106 | + [ |
|
| 107 | + 'EVT_ID' => $evt_id, |
|
| 108 | + 'return_url' => $return_url, |
|
| 109 | + ], |
|
| 110 | + ], |
|
| 111 | + ]; |
|
| 112 | + } |
|
| 113 | + $this->_bottom_buttons['report_filtered'] = [ |
|
| 114 | + 'route' => 'registrations_checkin_report', |
|
| 115 | + 'extra_request' => [ |
|
| 116 | + 'use_filters' => true, |
|
| 117 | + 'filters' => array_merge( |
|
| 118 | + [ |
|
| 119 | + 'EVT_ID' => $evt_id, |
|
| 120 | + ], |
|
| 121 | + array_diff_key( |
|
| 122 | + $this->_req_data, |
|
| 123 | + array_flip( |
|
| 124 | + [ |
|
| 125 | + 'page', |
|
| 126 | + 'action', |
|
| 127 | + 'default_nonce', |
|
| 128 | + ] |
|
| 129 | + ) |
|
| 130 | + ) |
|
| 131 | + ), |
|
| 132 | + 'return_url' => $return_url, |
|
| 133 | + ], |
|
| 134 | + ]; |
|
| 135 | + $this->_sortable_columns = [ |
|
| 136 | + /** |
|
| 137 | + * Allows users to change the default sort if they wish. |
|
| 138 | + * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name. |
|
| 139 | + * |
|
| 140 | + * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to |
|
| 141 | + * change the sorts on any list table involving registration contacts. If you want to only change the filter |
|
| 142 | + * for a specific list table you can use the provided reference to this object instance. |
|
| 143 | + */ |
|
| 144 | + 'ATT_name' => [ |
|
| 145 | + 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
| 146 | + true, |
|
| 147 | + $this, |
|
| 148 | + ] |
|
| 149 | + ? ['ATT_lname' => true] |
|
| 150 | + : ['ATT_fname' => true], |
|
| 151 | + 'Event' => ['Event.EVT_name' => false], |
|
| 152 | + ]; |
|
| 153 | + $this->_hidden_columns = []; |
|
| 154 | + $this->_evt = EEM_Event::instance()->get_one_by_ID($evt_id); |
|
| 155 | + $this->_dtts_for_event = |
|
| 156 | + $this->_evt instanceof EE_Event ? $this->_evt->datetimes_ordered() : []; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * @param EE_Registration $registration |
|
| 162 | + * @return string |
|
| 163 | + */ |
|
| 164 | + protected function _get_row_class($registration) |
|
| 165 | + { |
|
| 166 | + $class = parent::_get_row_class($registration); |
|
| 167 | + if ($this->_has_checkbox_column) { |
|
| 168 | + $class .= ' has-checkbox-column'; |
|
| 169 | + } |
|
| 170 | + return $class; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * @return array |
|
| 176 | + * @throws EE_Error |
|
| 177 | + * @throws ReflectionException |
|
| 178 | + */ |
|
| 179 | + protected function _get_table_filters() |
|
| 180 | + { |
|
| 181 | + $filters = $where = []; |
|
| 182 | + $current_EVT_ID = isset($this->_req_data['event_id']) ? (int) $this->_req_data['event_id'] : 0; |
|
| 183 | + if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) { |
|
| 184 | + // this means we don't have an event so let's setup a filter dropdown for all the events to select |
|
| 185 | + // note possible capability restrictions |
|
| 186 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 187 | + $where['status**'] = ['!=', 'private']; |
|
| 188 | + } |
|
| 189 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 190 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
| 191 | + } |
|
| 192 | + $events = EEM_Event::instance()->get_all( |
|
| 193 | + [ |
|
| 194 | + $where, |
|
| 195 | + 'order_by' => ['Datetime.DTT_EVT_start' => 'DESC'], |
|
| 196 | + ] |
|
| 197 | + ); |
|
| 198 | + $evts[] = [ |
|
| 199 | + 'id' => 0, |
|
| 200 | + 'text' => esc_html__(' - select an event - ', 'event_espresso'), |
|
| 201 | + ]; |
|
| 202 | + $checked = 'checked'; |
|
| 203 | + /** @var EE_Event $evt */ |
|
| 204 | + foreach ($events as $evt) { |
|
| 205 | + // any registrations for this event? |
|
| 206 | + if (! $evt->get_count_of_all_registrations()) { |
|
| 207 | + continue; |
|
| 208 | + } |
|
| 209 | + $evts[] = [ |
|
| 210 | + 'id' => $evt->ID(), |
|
| 211 | + 'text' => apply_filters( |
|
| 212 | + 'FHEE__EE_Event_Registrations___get_table_filters__event_name', |
|
| 213 | + $evt->get('EVT_name'), |
|
| 214 | + $evt |
|
| 215 | + ), |
|
| 216 | + 'class' => $evt->is_expired() ? 'ee-expired-event' : '', |
|
| 217 | + ]; |
|
| 218 | + if ($evt->ID() === $current_EVT_ID && $evt->is_expired()) { |
|
| 219 | + $checked = ''; |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + $event_filter = '<div class="ee-event-filter">'; |
|
| 223 | + $event_filter .= '<label for="event_id">'; |
|
| 224 | + $event_filter .= esc_html__('Check-in Status for', 'event_espresso'); |
|
| 225 | + $event_filter .= '</label> '; |
|
| 226 | + $event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID); |
|
| 227 | + $event_filter .= '<span class="ee-event-filter-toggle">'; |
|
| 228 | + $event_filter .= '<label for="js-ee-hide-expired-events">'; |
|
| 229 | + $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> '; |
|
| 230 | + $event_filter .= esc_html__('Hide Expired Events', 'event_espresso'); |
|
| 231 | + $event_filter .= '</label>'; |
|
| 232 | + $event_filter .= '</span>'; |
|
| 233 | + $event_filter .= '</div>'; |
|
| 234 | + $filters[] = $event_filter; |
|
| 235 | + } |
|
| 236 | + if (! empty($this->_dtts_for_event)) { |
|
| 237 | + // DTT datetimes filter |
|
| 238 | + $this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0; |
|
| 239 | + if (count($this->_dtts_for_event) > 1) { |
|
| 240 | + $dtts[0] = esc_html__('To toggle check-in status, select a datetime.', 'event_espresso'); |
|
| 241 | + foreach ($this->_dtts_for_event as $dtt) { |
|
| 242 | + $datetime_string = $dtt->name(); |
|
| 243 | + $datetime_string = ! empty($datetime_string) ? ' (' . $datetime_string . ')' : ''; |
|
| 244 | + $datetime_string = |
|
| 245 | + $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string; |
|
| 246 | + $dtts[ $dtt->ID() ] = $datetime_string; |
|
| 247 | + } |
|
| 248 | + $input = new EE_Select_Input( |
|
| 249 | + $dtts, |
|
| 250 | + [ |
|
| 251 | + 'html_name' => 'DTT_ID', |
|
| 252 | + 'html_id' => 'DTT_ID', |
|
| 253 | + 'default' => $this->_cur_dtt_id, |
|
| 254 | + ] |
|
| 255 | + ); |
|
| 256 | + $filters[] = $input->get_html_for_input(); |
|
| 257 | + $filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">'; |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + return $filters; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + protected function _add_view_counts() |
|
| 265 | + { |
|
| 266 | + $this->_views['all']['count'] = $this->_get_total_event_attendees(); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * @return int |
|
| 272 | + * @throws EE_Error |
|
| 273 | + * @throws ReflectionException |
|
| 274 | + */ |
|
| 275 | + protected function _get_total_event_attendees() |
|
| 276 | + { |
|
| 277 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
| 278 | + $DTT_ID = $this->_cur_dtt_id; |
|
| 279 | + $query_params = []; |
|
| 280 | + if ($EVT_ID) { |
|
| 281 | + $query_params[0]['EVT_ID'] = $EVT_ID; |
|
| 282 | + } |
|
| 283 | + // if DTT is included we only show for that datetime. Otherwise we're showing for all datetimes (the event). |
|
| 284 | + if ($DTT_ID) { |
|
| 285 | + $query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID; |
|
| 286 | + } |
|
| 287 | + $status_ids_array = apply_filters( |
|
| 288 | + 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
| 289 | + [EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved] |
|
| 290 | + ); |
|
| 291 | + $query_params[0]['STS_ID'] = ['IN', $status_ids_array]; |
|
| 292 | + return EEM_Registration::instance()->count($query_params); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * @param EE_Registration $registration |
|
| 298 | + * @return string |
|
| 299 | + * @throws EE_Error |
|
| 300 | + * @throws ReflectionException |
|
| 301 | + */ |
|
| 302 | + public function column_cb($registration) |
|
| 303 | + { |
|
| 304 | + return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $registration->ID()); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * column_REG_att_checked_in |
|
| 310 | + * |
|
| 311 | + * @param EE_Registration $registration |
|
| 312 | + * @return string |
|
| 313 | + * @throws EE_Error |
|
| 314 | + * @throws InvalidArgumentException |
|
| 315 | + * @throws InvalidDataTypeException |
|
| 316 | + * @throws InvalidInterfaceException |
|
| 317 | + * @throws ReflectionException |
|
| 318 | + */ |
|
| 319 | + public function column__REG_att_checked_in(EE_Registration $registration) |
|
| 320 | + { |
|
| 321 | + $attendee = $registration->attendee(); |
|
| 322 | + $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
| 323 | + |
|
| 324 | + if ($this->_cur_dtt_id === 0 && count($this->_dtts_for_event) === 1) { |
|
| 325 | + $latest_related_datetime = $registration->get_latest_related_datetime(); |
|
| 326 | + if ($latest_related_datetime instanceof EE_Datetime) { |
|
| 327 | + $this->_cur_dtt_id = $latest_related_datetime->ID(); |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + $checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId( |
|
| 331 | + $registration, |
|
| 332 | + $this->_cur_dtt_id |
|
| 333 | + ); |
|
| 334 | + $nonce = wp_create_nonce('checkin_nonce'); |
|
| 335 | + $toggle_active = ! empty($this->_cur_dtt_id) |
|
| 336 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 337 | + 'ee_edit_checkin', |
|
| 338 | + 'espresso_registrations_toggle_checkin_status', |
|
| 339 | + $registration->ID() |
|
| 340 | + ) |
|
| 341 | + ? ' clickable trigger-checkin' |
|
| 342 | + : ''; |
|
| 343 | + $mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
|
| 344 | + return ' |
|
| 345 | 345 | <button class="button button--secondary button--icon-only ' . $toggle_active . '" |
| 346 | 346 | data-_regid="' . $registration->ID() . '" |
| 347 | 347 | data-dttid="' . $this->_cur_dtt_id . '" |
@@ -350,262 +350,262 @@ discard block |
||
| 350 | 350 | <span class="' . $checkin_status_dashicon->cssClasses() . '"></span> |
| 351 | 351 | </button> |
| 352 | 352 | ' |
| 353 | - . $mobile_view_content; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * @param EE_Registration $registration |
|
| 359 | - * @return string |
|
| 360 | - * @throws EE_Error |
|
| 361 | - * @throws ReflectionException |
|
| 362 | - */ |
|
| 363 | - public function column_ATT_name(EE_Registration $registration) |
|
| 364 | - { |
|
| 365 | - $attendee = $registration->attendee(); |
|
| 366 | - if (! $attendee instanceof EE_Attendee) { |
|
| 367 | - return esc_html__('No contact record for this registration.', 'event_espresso'); |
|
| 368 | - } |
|
| 369 | - // edit attendee link |
|
| 370 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 371 | - ['action' => 'view_registration', '_REG_ID' => $registration->ID()], |
|
| 372 | - REG_ADMIN_URL |
|
| 373 | - ); |
|
| 374 | - $name_link = ' |
|
| 353 | + . $mobile_view_content; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * @param EE_Registration $registration |
|
| 359 | + * @return string |
|
| 360 | + * @throws EE_Error |
|
| 361 | + * @throws ReflectionException |
|
| 362 | + */ |
|
| 363 | + public function column_ATT_name(EE_Registration $registration) |
|
| 364 | + { |
|
| 365 | + $attendee = $registration->attendee(); |
|
| 366 | + if (! $attendee instanceof EE_Attendee) { |
|
| 367 | + return esc_html__('No contact record for this registration.', 'event_espresso'); |
|
| 368 | + } |
|
| 369 | + // edit attendee link |
|
| 370 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 371 | + ['action' => 'view_registration', '_REG_ID' => $registration->ID()], |
|
| 372 | + REG_ADMIN_URL |
|
| 373 | + ); |
|
| 374 | + $name_link = ' |
|
| 375 | 375 | <span class="ee-status-dot ee-status-bg--' . esc_attr($registration->status_ID()) . ' ee-aria-tooltip" |
| 376 | 376 | aria-label="' . EEH_Template::pretty_status($registration->status_ID(), false, 'sentence') . '"> |
| 377 | 377 | </span>'; |
| 378 | - $name_link .= EE_Registry::instance()->CAP->current_user_can( |
|
| 379 | - 'ee_edit_contacts', |
|
| 380 | - 'espresso_registrations_edit_attendee' |
|
| 381 | - ) |
|
| 382 | - ? '<a class="ee-aria-tooltip" href="' . $edit_lnk_url . '" aria-label="' . esc_attr__( |
|
| 383 | - 'View Registration Details', |
|
| 384 | - 'event_espresso' |
|
| 385 | - ) . '">' |
|
| 386 | - . $registration->attendee()->full_name() |
|
| 387 | - . '</a>' |
|
| 388 | - : $registration->attendee()->full_name(); |
|
| 389 | - $name_link .= $registration->count() === 1 |
|
| 390 | - ? ' <sup><div class="dashicons dashicons-star-filled gold-icon"></div></sup> ' |
|
| 391 | - : ''; |
|
| 392 | - // add group details |
|
| 393 | - $name_link .= ' ' . sprintf( |
|
| 394 | - esc_html__('(%s of %s)', 'event_espresso'), |
|
| 395 | - $registration->count(), |
|
| 396 | - $registration->group_size() |
|
| 397 | - ); |
|
| 398 | - // add regcode |
|
| 399 | - $link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 400 | - ['action' => 'view_registration', '_REG_ID' => $registration->ID()], |
|
| 401 | - REG_ADMIN_URL |
|
| 402 | - ); |
|
| 403 | - $name_link .= '<br>'; |
|
| 404 | - $name_link .= EE_Registry::instance()->instance()->CAP->current_user_can( |
|
| 405 | - 'ee_read_registration', |
|
| 406 | - 'view_registration', |
|
| 407 | - $registration->ID() |
|
| 408 | - ) |
|
| 409 | - ? '<a class="ee-aria-tooltip" href="' . $link . '" aria-label="' . esc_attr__( |
|
| 410 | - 'View Registration Details', |
|
| 411 | - 'event_espresso' |
|
| 412 | - ) . '">' |
|
| 413 | - . $registration->reg_code() |
|
| 414 | - . '</a>' |
|
| 415 | - : $registration->reg_code(); |
|
| 416 | - // status |
|
| 417 | - // $name_link .= '<br><span class="ee-status-text-small">'; |
|
| 418 | - // $name_link .= EEH_Template::pretty_status($registration->status_ID(), false, 'sentence'); |
|
| 419 | - // $name_link .= '</span>'; |
|
| 420 | - $actions = []; |
|
| 421 | - $DTT_ID = $this->_cur_dtt_id; |
|
| 422 | - $latest_related_datetime = |
|
| 423 | - empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $registration instanceof EE_Registration |
|
| 424 | - ? $registration->get_latest_related_datetime() |
|
| 425 | - : null; |
|
| 426 | - $DTT_ID = $latest_related_datetime instanceof EE_Datetime |
|
| 427 | - ? $latest_related_datetime->ID() |
|
| 428 | - : $DTT_ID; |
|
| 429 | - if ( |
|
| 430 | - ! empty($DTT_ID) |
|
| 431 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 432 | - 'ee_read_checkins', |
|
| 433 | - 'espresso_registrations_registration_checkins' |
|
| 434 | - ) |
|
| 435 | - ) { |
|
| 436 | - $checkin_list_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 437 | - ['action' => 'registration_checkins', '_REG_ID' => $registration->ID(), 'DTT_ID' => $DTT_ID], |
|
| 438 | - REG_ADMIN_URL |
|
| 439 | - ); |
|
| 440 | - // get the timestamps for this registration's checkins, related to the selected datetime |
|
| 441 | - $timestamps = $registration->get_many_related('Checkin', [['DTT_ID' => $DTT_ID]]); |
|
| 442 | - if (! empty($timestamps)) { |
|
| 443 | - // get the last timestamp |
|
| 444 | - $last_timestamp = end($timestamps); |
|
| 445 | - // checked in or checked out? |
|
| 446 | - $checkin_status = $last_timestamp->get('CHK_in') |
|
| 447 | - ? esc_html__('Checked In', 'event_espresso') |
|
| 448 | - : esc_html__('Checked Out', 'event_espresso'); |
|
| 449 | - // get timestamp string |
|
| 450 | - $timestamp_string = $last_timestamp->get_datetime('CHK_timestamp'); |
|
| 451 | - $actions['checkin'] = '<a class="ee-aria-tooltip" href="' . $checkin_list_url . '" aria-label="' |
|
| 452 | - . esc_attr__( |
|
| 453 | - 'View this registrant\'s check-ins/checkouts for the datetime', |
|
| 454 | - 'event_espresso' |
|
| 455 | - ) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>'; |
|
| 456 | - } |
|
| 457 | - } |
|
| 458 | - return (! empty($DTT_ID) && ! empty($timestamps)) |
|
| 459 | - ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true)) |
|
| 460 | - : $name_link; |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - |
|
| 464 | - /** |
|
| 465 | - * @param EE_Registration $registration |
|
| 466 | - * @return string |
|
| 467 | - * @throws EE_Error |
|
| 468 | - * @throws EE_Error |
|
| 469 | - */ |
|
| 470 | - public function column_ATT_email(EE_Registration $registration) |
|
| 471 | - { |
|
| 472 | - $attendee = $registration->attendee(); |
|
| 473 | - return $attendee instanceof EE_Attendee ? $attendee->email() : ''; |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * @param EE_Registration $registration |
|
| 479 | - * @return bool|string |
|
| 480 | - * @throws EE_Error |
|
| 481 | - * @throws ReflectionException |
|
| 482 | - */ |
|
| 483 | - public function column_Event(EE_Registration $registration) |
|
| 484 | - { |
|
| 485 | - try { |
|
| 486 | - $event = $this->_evt instanceof EE_Event ? $this->_evt : $registration->event(); |
|
| 487 | - $chkin_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 488 | - ['action' => 'event_registrations', 'event_id' => $event->ID()], |
|
| 489 | - REG_ADMIN_URL |
|
| 490 | - ); |
|
| 491 | - $event_label = EE_Registry::instance()->CAP->current_user_can( |
|
| 492 | - 'ee_read_checkins', |
|
| 493 | - 'espresso_registrations_registration_checkins' |
|
| 494 | - ) ? '<a class="ee-aria-tooltip" href="' . $chkin_lnk_url . '" aria-label="' |
|
| 495 | - . esc_attr__( |
|
| 496 | - 'View Checkins for this Event', |
|
| 497 | - 'event_espresso' |
|
| 498 | - ) . '">' . $event->name() . '</a>' : $event->name(); |
|
| 499 | - } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) { |
|
| 500 | - $event_label = esc_html__('Unknown', 'event_espresso'); |
|
| 501 | - } |
|
| 502 | - return $event_label; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * @param EE_Registration $registration |
|
| 508 | - * @return mixed|string|void |
|
| 509 | - */ |
|
| 510 | - public function column_PRC_name(EE_Registration $registration) |
|
| 511 | - { |
|
| 512 | - return $registration->ticket() instanceof EE_Ticket |
|
| 513 | - ? $registration->ticket()->name() |
|
| 514 | - : esc_html__( |
|
| 515 | - "Unknown", |
|
| 516 | - "event_espresso" |
|
| 517 | - ); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * column_REG_final_price |
|
| 523 | - * |
|
| 524 | - * @param EE_Registration $registration |
|
| 525 | - * @return string |
|
| 526 | - * @throws EE_Error |
|
| 527 | - * @throws EE_Error |
|
| 528 | - */ |
|
| 529 | - public function column__REG_final_price(EE_Registration $registration) |
|
| 530 | - { |
|
| 531 | - return '<span class="reg-pad-rght">' . ' ' . $registration->pretty_final_price() . '</span>'; |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * column_TXN_paid |
|
| 537 | - * |
|
| 538 | - * @param EE_Registration $registration |
|
| 539 | - * @return string |
|
| 540 | - * @throws EE_Error |
|
| 541 | - * @throws ReflectionException |
|
| 542 | - */ |
|
| 543 | - public function column_TXN_paid(EE_Registration $registration) |
|
| 544 | - { |
|
| 545 | - if ($registration->count() === 1) { |
|
| 546 | - if ($registration->transaction()->paid() >= $registration->transaction()->total()) { |
|
| 547 | - return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>'; |
|
| 548 | - } else { |
|
| 549 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 550 | - ['action' => 'view_transaction', 'TXN_ID' => $registration->transaction_ID()], |
|
| 551 | - TXN_ADMIN_URL |
|
| 552 | - ); |
|
| 553 | - return EE_Registry::instance()->CAP->current_user_can( |
|
| 554 | - 'ee_read_transaction', |
|
| 555 | - 'espresso_transactions_view_transaction' |
|
| 556 | - ) ? ' |
|
| 378 | + $name_link .= EE_Registry::instance()->CAP->current_user_can( |
|
| 379 | + 'ee_edit_contacts', |
|
| 380 | + 'espresso_registrations_edit_attendee' |
|
| 381 | + ) |
|
| 382 | + ? '<a class="ee-aria-tooltip" href="' . $edit_lnk_url . '" aria-label="' . esc_attr__( |
|
| 383 | + 'View Registration Details', |
|
| 384 | + 'event_espresso' |
|
| 385 | + ) . '">' |
|
| 386 | + . $registration->attendee()->full_name() |
|
| 387 | + . '</a>' |
|
| 388 | + : $registration->attendee()->full_name(); |
|
| 389 | + $name_link .= $registration->count() === 1 |
|
| 390 | + ? ' <sup><div class="dashicons dashicons-star-filled gold-icon"></div></sup> ' |
|
| 391 | + : ''; |
|
| 392 | + // add group details |
|
| 393 | + $name_link .= ' ' . sprintf( |
|
| 394 | + esc_html__('(%s of %s)', 'event_espresso'), |
|
| 395 | + $registration->count(), |
|
| 396 | + $registration->group_size() |
|
| 397 | + ); |
|
| 398 | + // add regcode |
|
| 399 | + $link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 400 | + ['action' => 'view_registration', '_REG_ID' => $registration->ID()], |
|
| 401 | + REG_ADMIN_URL |
|
| 402 | + ); |
|
| 403 | + $name_link .= '<br>'; |
|
| 404 | + $name_link .= EE_Registry::instance()->instance()->CAP->current_user_can( |
|
| 405 | + 'ee_read_registration', |
|
| 406 | + 'view_registration', |
|
| 407 | + $registration->ID() |
|
| 408 | + ) |
|
| 409 | + ? '<a class="ee-aria-tooltip" href="' . $link . '" aria-label="' . esc_attr__( |
|
| 410 | + 'View Registration Details', |
|
| 411 | + 'event_espresso' |
|
| 412 | + ) . '">' |
|
| 413 | + . $registration->reg_code() |
|
| 414 | + . '</a>' |
|
| 415 | + : $registration->reg_code(); |
|
| 416 | + // status |
|
| 417 | + // $name_link .= '<br><span class="ee-status-text-small">'; |
|
| 418 | + // $name_link .= EEH_Template::pretty_status($registration->status_ID(), false, 'sentence'); |
|
| 419 | + // $name_link .= '</span>'; |
|
| 420 | + $actions = []; |
|
| 421 | + $DTT_ID = $this->_cur_dtt_id; |
|
| 422 | + $latest_related_datetime = |
|
| 423 | + empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $registration instanceof EE_Registration |
|
| 424 | + ? $registration->get_latest_related_datetime() |
|
| 425 | + : null; |
|
| 426 | + $DTT_ID = $latest_related_datetime instanceof EE_Datetime |
|
| 427 | + ? $latest_related_datetime->ID() |
|
| 428 | + : $DTT_ID; |
|
| 429 | + if ( |
|
| 430 | + ! empty($DTT_ID) |
|
| 431 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 432 | + 'ee_read_checkins', |
|
| 433 | + 'espresso_registrations_registration_checkins' |
|
| 434 | + ) |
|
| 435 | + ) { |
|
| 436 | + $checkin_list_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 437 | + ['action' => 'registration_checkins', '_REG_ID' => $registration->ID(), 'DTT_ID' => $DTT_ID], |
|
| 438 | + REG_ADMIN_URL |
|
| 439 | + ); |
|
| 440 | + // get the timestamps for this registration's checkins, related to the selected datetime |
|
| 441 | + $timestamps = $registration->get_many_related('Checkin', [['DTT_ID' => $DTT_ID]]); |
|
| 442 | + if (! empty($timestamps)) { |
|
| 443 | + // get the last timestamp |
|
| 444 | + $last_timestamp = end($timestamps); |
|
| 445 | + // checked in or checked out? |
|
| 446 | + $checkin_status = $last_timestamp->get('CHK_in') |
|
| 447 | + ? esc_html__('Checked In', 'event_espresso') |
|
| 448 | + : esc_html__('Checked Out', 'event_espresso'); |
|
| 449 | + // get timestamp string |
|
| 450 | + $timestamp_string = $last_timestamp->get_datetime('CHK_timestamp'); |
|
| 451 | + $actions['checkin'] = '<a class="ee-aria-tooltip" href="' . $checkin_list_url . '" aria-label="' |
|
| 452 | + . esc_attr__( |
|
| 453 | + 'View this registrant\'s check-ins/checkouts for the datetime', |
|
| 454 | + 'event_espresso' |
|
| 455 | + ) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>'; |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | + return (! empty($DTT_ID) && ! empty($timestamps)) |
|
| 459 | + ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true)) |
|
| 460 | + : $name_link; |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + |
|
| 464 | + /** |
|
| 465 | + * @param EE_Registration $registration |
|
| 466 | + * @return string |
|
| 467 | + * @throws EE_Error |
|
| 468 | + * @throws EE_Error |
|
| 469 | + */ |
|
| 470 | + public function column_ATT_email(EE_Registration $registration) |
|
| 471 | + { |
|
| 472 | + $attendee = $registration->attendee(); |
|
| 473 | + return $attendee instanceof EE_Attendee ? $attendee->email() : ''; |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * @param EE_Registration $registration |
|
| 479 | + * @return bool|string |
|
| 480 | + * @throws EE_Error |
|
| 481 | + * @throws ReflectionException |
|
| 482 | + */ |
|
| 483 | + public function column_Event(EE_Registration $registration) |
|
| 484 | + { |
|
| 485 | + try { |
|
| 486 | + $event = $this->_evt instanceof EE_Event ? $this->_evt : $registration->event(); |
|
| 487 | + $chkin_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 488 | + ['action' => 'event_registrations', 'event_id' => $event->ID()], |
|
| 489 | + REG_ADMIN_URL |
|
| 490 | + ); |
|
| 491 | + $event_label = EE_Registry::instance()->CAP->current_user_can( |
|
| 492 | + 'ee_read_checkins', |
|
| 493 | + 'espresso_registrations_registration_checkins' |
|
| 494 | + ) ? '<a class="ee-aria-tooltip" href="' . $chkin_lnk_url . '" aria-label="' |
|
| 495 | + . esc_attr__( |
|
| 496 | + 'View Checkins for this Event', |
|
| 497 | + 'event_espresso' |
|
| 498 | + ) . '">' . $event->name() . '</a>' : $event->name(); |
|
| 499 | + } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) { |
|
| 500 | + $event_label = esc_html__('Unknown', 'event_espresso'); |
|
| 501 | + } |
|
| 502 | + return $event_label; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * @param EE_Registration $registration |
|
| 508 | + * @return mixed|string|void |
|
| 509 | + */ |
|
| 510 | + public function column_PRC_name(EE_Registration $registration) |
|
| 511 | + { |
|
| 512 | + return $registration->ticket() instanceof EE_Ticket |
|
| 513 | + ? $registration->ticket()->name() |
|
| 514 | + : esc_html__( |
|
| 515 | + "Unknown", |
|
| 516 | + "event_espresso" |
|
| 517 | + ); |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * column_REG_final_price |
|
| 523 | + * |
|
| 524 | + * @param EE_Registration $registration |
|
| 525 | + * @return string |
|
| 526 | + * @throws EE_Error |
|
| 527 | + * @throws EE_Error |
|
| 528 | + */ |
|
| 529 | + public function column__REG_final_price(EE_Registration $registration) |
|
| 530 | + { |
|
| 531 | + return '<span class="reg-pad-rght">' . ' ' . $registration->pretty_final_price() . '</span>'; |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * column_TXN_paid |
|
| 537 | + * |
|
| 538 | + * @param EE_Registration $registration |
|
| 539 | + * @return string |
|
| 540 | + * @throws EE_Error |
|
| 541 | + * @throws ReflectionException |
|
| 542 | + */ |
|
| 543 | + public function column_TXN_paid(EE_Registration $registration) |
|
| 544 | + { |
|
| 545 | + if ($registration->count() === 1) { |
|
| 546 | + if ($registration->transaction()->paid() >= $registration->transaction()->total()) { |
|
| 547 | + return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>'; |
|
| 548 | + } else { |
|
| 549 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 550 | + ['action' => 'view_transaction', 'TXN_ID' => $registration->transaction_ID()], |
|
| 551 | + TXN_ADMIN_URL |
|
| 552 | + ); |
|
| 553 | + return EE_Registry::instance()->CAP->current_user_can( |
|
| 554 | + 'ee_read_transaction', |
|
| 555 | + 'espresso_transactions_view_transaction' |
|
| 556 | + ) ? ' |
|
| 557 | 557 | <span class="reg-pad-rght"> |
| 558 | 558 | <a class="ee-aria-tooltip ee-status-color--' |
| 559 | - . $registration->transaction()->status_ID() |
|
| 560 | - . '" href="' |
|
| 561 | - . $view_txn_lnk_url |
|
| 562 | - . '" aria-label="' |
|
| 563 | - . esc_attr__('View Transaction', 'event_espresso') |
|
| 564 | - . '"> |
|
| 559 | + . $registration->transaction()->status_ID() |
|
| 560 | + . '" href="' |
|
| 561 | + . $view_txn_lnk_url |
|
| 562 | + . '" aria-label="' |
|
| 563 | + . esc_attr__('View Transaction', 'event_espresso') |
|
| 564 | + . '"> |
|
| 565 | 565 | ' |
| 566 | - . $registration->transaction()->pretty_paid() |
|
| 567 | - . ' |
|
| 566 | + . $registration->transaction()->pretty_paid() |
|
| 567 | + . ' |
|
| 568 | 568 | </a> |
| 569 | 569 | <span>' : '<span class="reg-pad-rght">' . $registration->transaction()->pretty_paid() . '</span>'; |
| 570 | - } |
|
| 571 | - } else { |
|
| 572 | - return '<span class="reg-pad-rght"></span>'; |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * column_TXN_total |
|
| 579 | - * |
|
| 580 | - * @param EE_Registration $registration |
|
| 581 | - * @return string |
|
| 582 | - * @throws EE_Error |
|
| 583 | - * @throws ReflectionException |
|
| 584 | - */ |
|
| 585 | - public function column_TXN_total(EE_Registration $registration) |
|
| 586 | - { |
|
| 587 | - $txn = $registration->transaction(); |
|
| 588 | - $view_txn_url = add_query_arg(['action' => 'view_transaction', 'TXN_ID' => $txn->ID()], TXN_ADMIN_URL); |
|
| 589 | - if ($registration->get('REG_count') === 1) { |
|
| 590 | - $line_total_obj = $txn->total_line_item(); |
|
| 591 | - $txn_total = $line_total_obj instanceof EE_Line_Item |
|
| 592 | - ? $line_total_obj->get_pretty('LIN_total') |
|
| 593 | - : esc_html__( |
|
| 594 | - 'View Transaction', |
|
| 595 | - 'event_espresso' |
|
| 596 | - ); |
|
| 597 | - return EE_Registry::instance()->CAP->current_user_can( |
|
| 598 | - 'ee_read_transaction', |
|
| 599 | - 'espresso_transactions_view_transaction' |
|
| 600 | - ) ? '<a class="ee-aria-tooltip" href="' |
|
| 601 | - . $view_txn_url |
|
| 602 | - . '" aria-label="' |
|
| 603 | - . esc_attr__('View Transaction', 'event_espresso') |
|
| 604 | - . '"><span class="reg-pad-rght">' |
|
| 605 | - . $txn_total |
|
| 606 | - . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>'; |
|
| 607 | - } else { |
|
| 608 | - return '<span class="reg-pad-rght"></span>'; |
|
| 609 | - } |
|
| 610 | - } |
|
| 570 | + } |
|
| 571 | + } else { |
|
| 572 | + return '<span class="reg-pad-rght"></span>'; |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * column_TXN_total |
|
| 579 | + * |
|
| 580 | + * @param EE_Registration $registration |
|
| 581 | + * @return string |
|
| 582 | + * @throws EE_Error |
|
| 583 | + * @throws ReflectionException |
|
| 584 | + */ |
|
| 585 | + public function column_TXN_total(EE_Registration $registration) |
|
| 586 | + { |
|
| 587 | + $txn = $registration->transaction(); |
|
| 588 | + $view_txn_url = add_query_arg(['action' => 'view_transaction', 'TXN_ID' => $txn->ID()], TXN_ADMIN_URL); |
|
| 589 | + if ($registration->get('REG_count') === 1) { |
|
| 590 | + $line_total_obj = $txn->total_line_item(); |
|
| 591 | + $txn_total = $line_total_obj instanceof EE_Line_Item |
|
| 592 | + ? $line_total_obj->get_pretty('LIN_total') |
|
| 593 | + : esc_html__( |
|
| 594 | + 'View Transaction', |
|
| 595 | + 'event_espresso' |
|
| 596 | + ); |
|
| 597 | + return EE_Registry::instance()->CAP->current_user_can( |
|
| 598 | + 'ee_read_transaction', |
|
| 599 | + 'espresso_transactions_view_transaction' |
|
| 600 | + ) ? '<a class="ee-aria-tooltip" href="' |
|
| 601 | + . $view_txn_url |
|
| 602 | + . '" aria-label="' |
|
| 603 | + . esc_attr__('View Transaction', 'event_espresso') |
|
| 604 | + . '"><span class="reg-pad-rght">' |
|
| 605 | + . $txn_total |
|
| 606 | + . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>'; |
|
| 607 | + } else { |
|
| 608 | + return '<span class="reg-pad-rght"></span>'; |
|
| 609 | + } |
|
| 610 | + } |
|
| 611 | 611 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | 'TXN_total' => esc_html__('Total', 'event_espresso'), |
| 83 | 83 | ]; |
| 84 | 84 | // Add/remove columns when an event has been selected |
| 85 | - if (! empty($evt_id)) { |
|
| 85 | + if ( ! empty($evt_id)) { |
|
| 86 | 86 | // Render a checkbox column |
| 87 | 87 | $columns['cb'] = '<input type="checkbox" />'; |
| 88 | 88 | $this->_has_checkbox_column = true; |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | 'return_url' => $return_url, |
| 133 | 133 | ], |
| 134 | 134 | ]; |
| 135 | - $this->_sortable_columns = [ |
|
| 135 | + $this->_sortable_columns = [ |
|
| 136 | 136 | /** |
| 137 | 137 | * Allows users to change the default sort if they wish. |
| 138 | 138 | * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name. |
@@ -183,19 +183,19 @@ discard block |
||
| 183 | 183 | if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) { |
| 184 | 184 | // this means we don't have an event so let's setup a filter dropdown for all the events to select |
| 185 | 185 | // note possible capability restrictions |
| 186 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 186 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 187 | 187 | $where['status**'] = ['!=', 'private']; |
| 188 | 188 | } |
| 189 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 189 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 190 | 190 | $where['EVT_wp_user'] = get_current_user_id(); |
| 191 | 191 | } |
| 192 | - $events = EEM_Event::instance()->get_all( |
|
| 192 | + $events = EEM_Event::instance()->get_all( |
|
| 193 | 193 | [ |
| 194 | 194 | $where, |
| 195 | 195 | 'order_by' => ['Datetime.DTT_EVT_start' => 'DESC'], |
| 196 | 196 | ] |
| 197 | 197 | ); |
| 198 | - $evts[] = [ |
|
| 198 | + $evts[] = [ |
|
| 199 | 199 | 'id' => 0, |
| 200 | 200 | 'text' => esc_html__(' - select an event - ', 'event_espresso'), |
| 201 | 201 | ]; |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | /** @var EE_Event $evt */ |
| 204 | 204 | foreach ($events as $evt) { |
| 205 | 205 | // any registrations for this event? |
| 206 | - if (! $evt->get_count_of_all_registrations()) { |
|
| 206 | + if ( ! $evt->get_count_of_all_registrations()) { |
|
| 207 | 207 | continue; |
| 208 | 208 | } |
| 209 | 209 | $evts[] = [ |
@@ -226,26 +226,26 @@ discard block |
||
| 226 | 226 | $event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID); |
| 227 | 227 | $event_filter .= '<span class="ee-event-filter-toggle">'; |
| 228 | 228 | $event_filter .= '<label for="js-ee-hide-expired-events">'; |
| 229 | - $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> '; |
|
| 229 | + $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" '.$checked.'> '; |
|
| 230 | 230 | $event_filter .= esc_html__('Hide Expired Events', 'event_espresso'); |
| 231 | 231 | $event_filter .= '</label>'; |
| 232 | 232 | $event_filter .= '</span>'; |
| 233 | 233 | $event_filter .= '</div>'; |
| 234 | - $filters[] = $event_filter; |
|
| 234 | + $filters[] = $event_filter; |
|
| 235 | 235 | } |
| 236 | - if (! empty($this->_dtts_for_event)) { |
|
| 236 | + if ( ! empty($this->_dtts_for_event)) { |
|
| 237 | 237 | // DTT datetimes filter |
| 238 | 238 | $this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0; |
| 239 | 239 | if (count($this->_dtts_for_event) > 1) { |
| 240 | 240 | $dtts[0] = esc_html__('To toggle check-in status, select a datetime.', 'event_espresso'); |
| 241 | 241 | foreach ($this->_dtts_for_event as $dtt) { |
| 242 | 242 | $datetime_string = $dtt->name(); |
| 243 | - $datetime_string = ! empty($datetime_string) ? ' (' . $datetime_string . ')' : ''; |
|
| 243 | + $datetime_string = ! empty($datetime_string) ? ' ('.$datetime_string.')' : ''; |
|
| 244 | 244 | $datetime_string = |
| 245 | - $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string; |
|
| 246 | - $dtts[ $dtt->ID() ] = $datetime_string; |
|
| 245 | + $dtt->start_date_and_time().' - '.$dtt->end_date_and_time().$datetime_string; |
|
| 246 | + $dtts[$dtt->ID()] = $datetime_string; |
|
| 247 | 247 | } |
| 248 | - $input = new EE_Select_Input( |
|
| 248 | + $input = new EE_Select_Input( |
|
| 249 | 249 | $dtts, |
| 250 | 250 | [ |
| 251 | 251 | 'html_name' => 'DTT_ID', |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | ] |
| 255 | 255 | ); |
| 256 | 256 | $filters[] = $input->get_html_for_input(); |
| 257 | - $filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">'; |
|
| 257 | + $filters[] = '<input type="hidden" name="event_id" value="'.$current_EVT_ID.'">'; |
|
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | return $filters; |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | if ($DTT_ID) { |
| 285 | 285 | $query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID; |
| 286 | 286 | } |
| 287 | - $status_ids_array = apply_filters( |
|
| 287 | + $status_ids_array = apply_filters( |
|
| 288 | 288 | 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
| 289 | 289 | [EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved] |
| 290 | 290 | ); |
@@ -340,14 +340,14 @@ discard block |
||
| 340 | 340 | ) |
| 341 | 341 | ? ' clickable trigger-checkin' |
| 342 | 342 | : ''; |
| 343 | - $mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
|
| 343 | + $mobile_view_content = ' <span class="show-on-mobile-view-only">'.$attendee_name.'</span>'; |
|
| 344 | 344 | return ' |
| 345 | - <button class="button button--secondary button--icon-only ' . $toggle_active . '" |
|
| 346 | - data-_regid="' . $registration->ID() . '" |
|
| 347 | - data-dttid="' . $this->_cur_dtt_id . '" |
|
| 348 | - data-nonce="' . $nonce . '" |
|
| 345 | + <button class="button button--secondary button--icon-only ' . $toggle_active.'" |
|
| 346 | + data-_regid="' . $registration->ID().'" |
|
| 347 | + data-dttid="' . $this->_cur_dtt_id.'" |
|
| 348 | + data-nonce="' . $nonce.'" |
|
| 349 | 349 | > |
| 350 | - <span class="' . $checkin_status_dashicon->cssClasses() . '"></span> |
|
| 350 | + <span class="' . $checkin_status_dashicon->cssClasses().'"></span> |
|
| 351 | 351 | </button> |
| 352 | 352 | ' |
| 353 | 353 | . $mobile_view_content; |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | public function column_ATT_name(EE_Registration $registration) |
| 364 | 364 | { |
| 365 | 365 | $attendee = $registration->attendee(); |
| 366 | - if (! $attendee instanceof EE_Attendee) { |
|
| 366 | + if ( ! $attendee instanceof EE_Attendee) { |
|
| 367 | 367 | return esc_html__('No contact record for this registration.', 'event_espresso'); |
| 368 | 368 | } |
| 369 | 369 | // edit attendee link |
@@ -371,32 +371,32 @@ discard block |
||
| 371 | 371 | ['action' => 'view_registration', '_REG_ID' => $registration->ID()], |
| 372 | 372 | REG_ADMIN_URL |
| 373 | 373 | ); |
| 374 | - $name_link = ' |
|
| 375 | - <span class="ee-status-dot ee-status-bg--' . esc_attr($registration->status_ID()) . ' ee-aria-tooltip" |
|
| 376 | - aria-label="' . EEH_Template::pretty_status($registration->status_ID(), false, 'sentence') . '"> |
|
| 374 | + $name_link = ' |
|
| 375 | + <span class="ee-status-dot ee-status-bg--' . esc_attr($registration->status_ID()).' ee-aria-tooltip" |
|
| 376 | + aria-label="' . EEH_Template::pretty_status($registration->status_ID(), false, 'sentence').'"> |
|
| 377 | 377 | </span>'; |
| 378 | - $name_link .= EE_Registry::instance()->CAP->current_user_can( |
|
| 378 | + $name_link .= EE_Registry::instance()->CAP->current_user_can( |
|
| 379 | 379 | 'ee_edit_contacts', |
| 380 | 380 | 'espresso_registrations_edit_attendee' |
| 381 | 381 | ) |
| 382 | - ? '<a class="ee-aria-tooltip" href="' . $edit_lnk_url . '" aria-label="' . esc_attr__( |
|
| 382 | + ? '<a class="ee-aria-tooltip" href="'.$edit_lnk_url.'" aria-label="'.esc_attr__( |
|
| 383 | 383 | 'View Registration Details', |
| 384 | 384 | 'event_espresso' |
| 385 | - ) . '">' |
|
| 385 | + ).'">' |
|
| 386 | 386 | . $registration->attendee()->full_name() |
| 387 | 387 | . '</a>' |
| 388 | 388 | : $registration->attendee()->full_name(); |
| 389 | - $name_link .= $registration->count() === 1 |
|
| 389 | + $name_link .= $registration->count() === 1 |
|
| 390 | 390 | ? ' <sup><div class="dashicons dashicons-star-filled gold-icon"></div></sup> ' |
| 391 | 391 | : ''; |
| 392 | 392 | // add group details |
| 393 | - $name_link .= ' ' . sprintf( |
|
| 393 | + $name_link .= ' '.sprintf( |
|
| 394 | 394 | esc_html__('(%s of %s)', 'event_espresso'), |
| 395 | 395 | $registration->count(), |
| 396 | 396 | $registration->group_size() |
| 397 | 397 | ); |
| 398 | 398 | // add regcode |
| 399 | - $link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 399 | + $link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 400 | 400 | ['action' => 'view_registration', '_REG_ID' => $registration->ID()], |
| 401 | 401 | REG_ADMIN_URL |
| 402 | 402 | ); |
@@ -406,10 +406,10 @@ discard block |
||
| 406 | 406 | 'view_registration', |
| 407 | 407 | $registration->ID() |
| 408 | 408 | ) |
| 409 | - ? '<a class="ee-aria-tooltip" href="' . $link . '" aria-label="' . esc_attr__( |
|
| 409 | + ? '<a class="ee-aria-tooltip" href="'.$link.'" aria-label="'.esc_attr__( |
|
| 410 | 410 | 'View Registration Details', |
| 411 | 411 | 'event_espresso' |
| 412 | - ) . '">' |
|
| 412 | + ).'">' |
|
| 413 | 413 | . $registration->reg_code() |
| 414 | 414 | . '</a>' |
| 415 | 415 | : $registration->reg_code(); |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $registration instanceof EE_Registration |
| 424 | 424 | ? $registration->get_latest_related_datetime() |
| 425 | 425 | : null; |
| 426 | - $DTT_ID = $latest_related_datetime instanceof EE_Datetime |
|
| 426 | + $DTT_ID = $latest_related_datetime instanceof EE_Datetime |
|
| 427 | 427 | ? $latest_related_datetime->ID() |
| 428 | 428 | : $DTT_ID; |
| 429 | 429 | if ( |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | ); |
| 440 | 440 | // get the timestamps for this registration's checkins, related to the selected datetime |
| 441 | 441 | $timestamps = $registration->get_many_related('Checkin', [['DTT_ID' => $DTT_ID]]); |
| 442 | - if (! empty($timestamps)) { |
|
| 442 | + if ( ! empty($timestamps)) { |
|
| 443 | 443 | // get the last timestamp |
| 444 | 444 | $last_timestamp = end($timestamps); |
| 445 | 445 | // checked in or checked out? |
@@ -448,14 +448,14 @@ discard block |
||
| 448 | 448 | : esc_html__('Checked Out', 'event_espresso'); |
| 449 | 449 | // get timestamp string |
| 450 | 450 | $timestamp_string = $last_timestamp->get_datetime('CHK_timestamp'); |
| 451 | - $actions['checkin'] = '<a class="ee-aria-tooltip" href="' . $checkin_list_url . '" aria-label="' |
|
| 451 | + $actions['checkin'] = '<a class="ee-aria-tooltip" href="'.$checkin_list_url.'" aria-label="' |
|
| 452 | 452 | . esc_attr__( |
| 453 | 453 | 'View this registrant\'s check-ins/checkouts for the datetime', |
| 454 | 454 | 'event_espresso' |
| 455 | - ) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>'; |
|
| 455 | + ).'">'.$checkin_status.': '.$timestamp_string.'</a>'; |
|
| 456 | 456 | } |
| 457 | 457 | } |
| 458 | - return (! empty($DTT_ID) && ! empty($timestamps)) |
|
| 458 | + return ( ! empty($DTT_ID) && ! empty($timestamps)) |
|
| 459 | 459 | ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true)) |
| 460 | 460 | : $name_link; |
| 461 | 461 | } |
@@ -488,14 +488,14 @@ discard block |
||
| 488 | 488 | ['action' => 'event_registrations', 'event_id' => $event->ID()], |
| 489 | 489 | REG_ADMIN_URL |
| 490 | 490 | ); |
| 491 | - $event_label = EE_Registry::instance()->CAP->current_user_can( |
|
| 491 | + $event_label = EE_Registry::instance()->CAP->current_user_can( |
|
| 492 | 492 | 'ee_read_checkins', |
| 493 | 493 | 'espresso_registrations_registration_checkins' |
| 494 | - ) ? '<a class="ee-aria-tooltip" href="' . $chkin_lnk_url . '" aria-label="' |
|
| 494 | + ) ? '<a class="ee-aria-tooltip" href="'.$chkin_lnk_url.'" aria-label="' |
|
| 495 | 495 | . esc_attr__( |
| 496 | 496 | 'View Checkins for this Event', |
| 497 | 497 | 'event_espresso' |
| 498 | - ) . '">' . $event->name() . '</a>' : $event->name(); |
|
| 498 | + ).'">'.$event->name().'</a>' : $event->name(); |
|
| 499 | 499 | } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) { |
| 500 | 500 | $event_label = esc_html__('Unknown', 'event_espresso'); |
| 501 | 501 | } |
@@ -528,7 +528,7 @@ discard block |
||
| 528 | 528 | */ |
| 529 | 529 | public function column__REG_final_price(EE_Registration $registration) |
| 530 | 530 | { |
| 531 | - return '<span class="reg-pad-rght">' . ' ' . $registration->pretty_final_price() . '</span>'; |
|
| 531 | + return '<span class="reg-pad-rght">'.' '.$registration->pretty_final_price().'</span>'; |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | |
@@ -566,7 +566,7 @@ discard block |
||
| 566 | 566 | . $registration->transaction()->pretty_paid() |
| 567 | 567 | . ' |
| 568 | 568 | </a> |
| 569 | - <span>' : '<span class="reg-pad-rght">' . $registration->transaction()->pretty_paid() . '</span>'; |
|
| 569 | + <span>' : '<span class="reg-pad-rght">'.$registration->transaction()->pretty_paid().'</span>'; |
|
| 570 | 570 | } |
| 571 | 571 | } else { |
| 572 | 572 | return '<span class="reg-pad-rght"></span>'; |
@@ -603,7 +603,7 @@ discard block |
||
| 603 | 603 | . esc_attr__('View Transaction', 'event_espresso') |
| 604 | 604 | . '"><span class="reg-pad-rght">' |
| 605 | 605 | . $txn_total |
| 606 | - . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>'; |
|
| 606 | + . '</span></a>' : '<span class="reg-pad-rght">'.$txn_total.'</span>'; |
|
| 607 | 607 | } else { |
| 608 | 608 | return '<span class="reg-pad-rght"></span>'; |
| 609 | 609 | } |