@@ -10,138 +10,138 @@ |
||
| 10 | 10 | class EE_Taxes extends EE_Base |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * This is used for when EE_Taxes is used statically by the admin |
|
| 15 | - * |
|
| 16 | - * @var array |
|
| 17 | - */ |
|
| 18 | - private static $_subtotal = array(); |
|
| 13 | + /** |
|
| 14 | + * This is used for when EE_Taxes is used statically by the admin |
|
| 15 | + * |
|
| 16 | + * @var array |
|
| 17 | + */ |
|
| 18 | + private static $_subtotal = array(); |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * This holds an array of EE_Price objects that are of PRT_ID == 4 (tax price types) |
|
| 22 | - * |
|
| 23 | - * @var EE_Price[] |
|
| 24 | - */ |
|
| 25 | - private static $_default_taxes = array(); |
|
| 20 | + /** |
|
| 21 | + * This holds an array of EE_Price objects that are of PRT_ID == 4 (tax price types) |
|
| 22 | + * |
|
| 23 | + * @var EE_Price[] |
|
| 24 | + */ |
|
| 25 | + private static $_default_taxes = array(); |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket |
|
| 30 | - * and applying default taxes to it). Note: this is just an intermediary helper method added to facilitate quick |
|
| 31 | - * calc of taxes for tickets listed in the event editor. |
|
| 32 | - * |
|
| 33 | - * @param EE_Ticket $ticket incoming EE_Ticket |
|
| 34 | - * @return float total taxes to apply to ticket. |
|
| 35 | - * @throws \EE_Error |
|
| 36 | - */ |
|
| 37 | - public static function get_total_taxes_for_admin(EE_Ticket $ticket) |
|
| 38 | - { |
|
| 39 | - $tax = 0; |
|
| 40 | - $total_tax = 0; |
|
| 41 | - // This first checks to see if the given ticket is taxable. |
|
| 42 | - if (! $ticket->get('TKT_taxable')) { |
|
| 43 | - return $tax; |
|
| 44 | - } |
|
| 45 | - // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
|
| 46 | - $subtotal = self::get_subtotal_for_admin($ticket); |
|
| 47 | - // get taxes |
|
| 48 | - $taxes = self::get_taxes_for_admin(); |
|
| 49 | - // apply taxes to subtotal |
|
| 50 | - foreach ($taxes as $tax) { |
|
| 51 | - // assuming taxes are not cumulative |
|
| 52 | - $total_tax += $subtotal * $tax->get('PRC_amount') / 100; |
|
| 53 | - } |
|
| 54 | - return $total_tax; |
|
| 55 | - } |
|
| 28 | + /** |
|
| 29 | + * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket |
|
| 30 | + * and applying default taxes to it). Note: this is just an intermediary helper method added to facilitate quick |
|
| 31 | + * calc of taxes for tickets listed in the event editor. |
|
| 32 | + * |
|
| 33 | + * @param EE_Ticket $ticket incoming EE_Ticket |
|
| 34 | + * @return float total taxes to apply to ticket. |
|
| 35 | + * @throws \EE_Error |
|
| 36 | + */ |
|
| 37 | + public static function get_total_taxes_for_admin(EE_Ticket $ticket) |
|
| 38 | + { |
|
| 39 | + $tax = 0; |
|
| 40 | + $total_tax = 0; |
|
| 41 | + // This first checks to see if the given ticket is taxable. |
|
| 42 | + if (! $ticket->get('TKT_taxable')) { |
|
| 43 | + return $tax; |
|
| 44 | + } |
|
| 45 | + // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
|
| 46 | + $subtotal = self::get_subtotal_for_admin($ticket); |
|
| 47 | + // get taxes |
|
| 48 | + $taxes = self::get_taxes_for_admin(); |
|
| 49 | + // apply taxes to subtotal |
|
| 50 | + foreach ($taxes as $tax) { |
|
| 51 | + // assuming taxes are not cumulative |
|
| 52 | + $total_tax += $subtotal * $tax->get('PRC_amount') / 100; |
|
| 53 | + } |
|
| 54 | + return $total_tax; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Gets the total percentage of tax that should be applied to taxable line items |
|
| 60 | - * |
|
| 61 | - * @return float the percentage of tax that should be added to taxable items |
|
| 62 | - * @throws \EE_Error |
|
| 63 | - * eg 20 for %20 tax (NOT 0.20, which |
|
| 64 | - */ |
|
| 65 | - public static function get_total_taxes_percentage() |
|
| 66 | - { |
|
| 67 | - $total_tax_percent = 0; |
|
| 68 | - foreach (self::get_taxes_for_admin() as $tax_price) { |
|
| 69 | - $total_tax_percent += $tax_price->get('PRC_amount'); |
|
| 70 | - } |
|
| 71 | - return $total_tax_percent; |
|
| 72 | - } |
|
| 58 | + /** |
|
| 59 | + * Gets the total percentage of tax that should be applied to taxable line items |
|
| 60 | + * |
|
| 61 | + * @return float the percentage of tax that should be added to taxable items |
|
| 62 | + * @throws \EE_Error |
|
| 63 | + * eg 20 for %20 tax (NOT 0.20, which |
|
| 64 | + */ |
|
| 65 | + public static function get_total_taxes_percentage() |
|
| 66 | + { |
|
| 67 | + $total_tax_percent = 0; |
|
| 68 | + foreach (self::get_taxes_for_admin() as $tax_price) { |
|
| 69 | + $total_tax_percent += $tax_price->get('PRC_amount'); |
|
| 70 | + } |
|
| 71 | + return $total_tax_percent; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @param EE_Ticket $ticket |
|
| 77 | - * @return float |
|
| 78 | - * @throws \EE_Error |
|
| 79 | - */ |
|
| 80 | - public static function get_subtotal_for_admin(EE_Ticket $ticket) |
|
| 81 | - { |
|
| 82 | - $TKT_ID = $ticket->ID(); |
|
| 83 | - return isset(self::$_subtotal[ $TKT_ID ]) |
|
| 84 | - ? self::$_subtotal[ $TKT_ID ] |
|
| 85 | - : self::_get_subtotal_for_admin($ticket); |
|
| 86 | - } |
|
| 75 | + /** |
|
| 76 | + * @param EE_Ticket $ticket |
|
| 77 | + * @return float |
|
| 78 | + * @throws \EE_Error |
|
| 79 | + */ |
|
| 80 | + public static function get_subtotal_for_admin(EE_Ticket $ticket) |
|
| 81 | + { |
|
| 82 | + $TKT_ID = $ticket->ID(); |
|
| 83 | + return isset(self::$_subtotal[ $TKT_ID ]) |
|
| 84 | + ? self::$_subtotal[ $TKT_ID ] |
|
| 85 | + : self::_get_subtotal_for_admin($ticket); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * simply take an incoming ticket and calculate the subtotal for the ticket |
|
| 91 | - * |
|
| 92 | - * @param EE_Ticket $ticket |
|
| 93 | - * @return float subtotal calculated from all EE_Price[] on Ticket. |
|
| 94 | - * @throws \EE_Error |
|
| 95 | - */ |
|
| 96 | - private static function _get_subtotal_for_admin(EE_Ticket $ticket) |
|
| 97 | - { |
|
| 98 | - $subtotal = 0; |
|
| 99 | - // get all prices |
|
| 100 | - $prices = $ticket->get_many_related( |
|
| 101 | - 'Price', |
|
| 102 | - array( |
|
| 103 | - 'default_where_conditions' => 'none', |
|
| 104 | - 'order_by' => array('PRC_order' => 'ASC'), |
|
| 105 | - ) |
|
| 106 | - ); |
|
| 107 | - // let's loop through them (base price is always the first item) |
|
| 108 | - foreach ($prices as $price) { |
|
| 109 | - if ($price instanceof EE_Price) { |
|
| 110 | - $price_type = $price->type_obj(); |
|
| 111 | - if ($price_type instanceof EE_Price_Type) { |
|
| 112 | - switch ($price->type_obj()->base_type()) { |
|
| 113 | - case 1: // base price |
|
| 114 | - case 3: // surcharges |
|
| 115 | - $subtotal += $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 |
|
| 116 | - : $price->get('PRC_amount'); |
|
| 117 | - break; |
|
| 118 | - case 2: // discounts |
|
| 119 | - $subtotal -= $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 |
|
| 120 | - : $price->get('PRC_amount'); |
|
| 121 | - break; |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - $TKT_ID = $ticket->ID(); |
|
| 127 | - self::$_subtotal = array($TKT_ID => $subtotal); |
|
| 128 | - return $subtotal; |
|
| 129 | - } |
|
| 89 | + /** |
|
| 90 | + * simply take an incoming ticket and calculate the subtotal for the ticket |
|
| 91 | + * |
|
| 92 | + * @param EE_Ticket $ticket |
|
| 93 | + * @return float subtotal calculated from all EE_Price[] on Ticket. |
|
| 94 | + * @throws \EE_Error |
|
| 95 | + */ |
|
| 96 | + private static function _get_subtotal_for_admin(EE_Ticket $ticket) |
|
| 97 | + { |
|
| 98 | + $subtotal = 0; |
|
| 99 | + // get all prices |
|
| 100 | + $prices = $ticket->get_many_related( |
|
| 101 | + 'Price', |
|
| 102 | + array( |
|
| 103 | + 'default_where_conditions' => 'none', |
|
| 104 | + 'order_by' => array('PRC_order' => 'ASC'), |
|
| 105 | + ) |
|
| 106 | + ); |
|
| 107 | + // let's loop through them (base price is always the first item) |
|
| 108 | + foreach ($prices as $price) { |
|
| 109 | + if ($price instanceof EE_Price) { |
|
| 110 | + $price_type = $price->type_obj(); |
|
| 111 | + if ($price_type instanceof EE_Price_Type) { |
|
| 112 | + switch ($price->type_obj()->base_type()) { |
|
| 113 | + case 1: // base price |
|
| 114 | + case 3: // surcharges |
|
| 115 | + $subtotal += $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 |
|
| 116 | + : $price->get('PRC_amount'); |
|
| 117 | + break; |
|
| 118 | + case 2: // discounts |
|
| 119 | + $subtotal -= $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 |
|
| 120 | + : $price->get('PRC_amount'); |
|
| 121 | + break; |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + $TKT_ID = $ticket->ID(); |
|
| 127 | + self::$_subtotal = array($TKT_ID => $subtotal); |
|
| 128 | + return $subtotal; |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * get all default prices that are a Tax price type (PRT_ID = 4) and return |
|
| 134 | - * |
|
| 135 | - * @return EE_Price[] EE_Price objects that have PRT_ID == 4 |
|
| 136 | - * @throws \EE_Error |
|
| 137 | - */ |
|
| 138 | - public static function get_taxes_for_admin() |
|
| 139 | - { |
|
| 140 | - if (empty(self::$_default_taxes)) { |
|
| 141 | - self::$_default_taxes = EEM_Price::instance()->get_all( |
|
| 142 | - [['Price_Type.PBT_ID' => 4, 'PRC_is_default' => 1]] |
|
| 143 | - ); |
|
| 144 | - } |
|
| 145 | - return self::$_default_taxes; |
|
| 146 | - } |
|
| 132 | + /** |
|
| 133 | + * get all default prices that are a Tax price type (PRT_ID = 4) and return |
|
| 134 | + * |
|
| 135 | + * @return EE_Price[] EE_Price objects that have PRT_ID == 4 |
|
| 136 | + * @throws \EE_Error |
|
| 137 | + */ |
|
| 138 | + public static function get_taxes_for_admin() |
|
| 139 | + { |
|
| 140 | + if (empty(self::$_default_taxes)) { |
|
| 141 | + self::$_default_taxes = EEM_Price::instance()->get_all( |
|
| 142 | + [['Price_Type.PBT_ID' => 4, 'PRC_is_default' => 1]] |
|
| 143 | + ); |
|
| 144 | + } |
|
| 145 | + return self::$_default_taxes; |
|
| 146 | + } |
|
| 147 | 147 | } |
@@ -10,279 +10,279 @@ |
||
| 10 | 10 | class EEM_Price extends EEM_Soft_Delete_Base |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - // private instance of the EEM_Price object |
|
| 14 | - protected static $_instance = null; |
|
| 15 | - |
|
| 16 | - |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * private constructor to prevent direct creation |
|
| 20 | - * @Constructor |
|
| 21 | - * @access protected |
|
| 22 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
| 23 | - * @return EEM_Price |
|
| 24 | - */ |
|
| 25 | - protected function __construct($timezone) |
|
| 26 | - { |
|
| 27 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 28 | - $this->singular_item = esc_html__('Price', 'event_espresso'); |
|
| 29 | - $this->plural_item = esc_html__('Prices', 'event_espresso'); |
|
| 30 | - |
|
| 31 | - $this->_tables = array( |
|
| 32 | - 'Price' => new EE_Primary_Table('esp_price', 'PRC_ID') |
|
| 33 | - ); |
|
| 34 | - $this->_fields = array( |
|
| 35 | - 'Price' => array( |
|
| 36 | - 'PRC_ID' => new EE_Primary_Key_Int_Field('PRC_ID', 'Price ID'), |
|
| 37 | - 'PRT_ID' => new EE_Foreign_Key_Int_Field('PRT_ID', 'Price type Id', false, null, 'Price_Type'), |
|
| 38 | - 'PRC_amount' => new EE_Money_Field('PRC_amount', 'Price Amount', false, 0), |
|
| 39 | - 'PRC_name' => new EE_Plain_Text_Field('PRC_name', 'Name of Price', false, ''), |
|
| 40 | - 'PRC_desc' => new EE_Post_Content_Field('PRC_desc', 'Price Description', false, ''), |
|
| 41 | - 'PRC_is_default' => new EE_Boolean_Field('PRC_is_default', 'Flag indicating whether price is a default price', false, false), |
|
| 42 | - 'PRC_overrides' => new EE_Integer_Field('PRC_overrides', 'Price ID for a global Price that will be overridden by this Price ( for replacing default prices )', true, 0), |
|
| 43 | - 'PRC_order' => new EE_Integer_Field('PRC_order', 'Order of Application of Price (lower numbers apply first?)', false, 1), |
|
| 44 | - 'PRC_deleted' => new EE_Trashed_Flag_Field('PRC_deleted', 'Flag Indicating if this has been deleted or not', false, false), |
|
| 45 | - 'PRC_parent' => new EE_Integer_Field('PRC_parent', esc_html__('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), true, 0), |
|
| 46 | - 'PRC_wp_user' => new EE_WP_User_Field('PRC_wp_user', esc_html__('Price Creator ID', 'event_espresso'), false), |
|
| 47 | - ) |
|
| 48 | - ); |
|
| 49 | - $this->_model_relations = array( |
|
| 50 | - 'Ticket' => new EE_HABTM_Relation('Ticket_Price'), |
|
| 51 | - 'Price_Type' => new EE_Belongs_To_Relation(), |
|
| 52 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 53 | - ); |
|
| 54 | - // this model is generally available for reading |
|
| 55 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event'); |
|
| 56 | - // account for default tickets in the caps |
|
| 57 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
| 58 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
| 59 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
| 60 | - parent::__construct($timezone); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * instantiate a new price object with blank/empty properties |
|
| 67 | - * |
|
| 68 | - * @access public |
|
| 69 | - * @return mixed array on success, FALSE on fail |
|
| 70 | - */ |
|
| 71 | - public function get_new_price() |
|
| 72 | - { |
|
| 73 | - return $this->create_default_object(); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * retrieve ALL prices from db |
|
| 82 | - * |
|
| 83 | - * @access public |
|
| 84 | - * @return EE_PRice[] |
|
| 85 | - */ |
|
| 86 | - public function get_all_prices() |
|
| 87 | - { |
|
| 88 | - // retrieve all prices |
|
| 89 | - return $this->get_all(array('order_by' => array('PRC_amount' => 'ASC'))); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * retrieve all active prices for a particular event |
|
| 96 | - * |
|
| 97 | - * @access public |
|
| 98 | - * @param int $EVT_ID |
|
| 99 | - * @return array on success |
|
| 100 | - */ |
|
| 101 | - public function get_all_event_prices($EVT_ID = 0) |
|
| 102 | - { |
|
| 103 | - return $this->get_all(array( |
|
| 104 | - array( |
|
| 105 | - 'EVT_ID' => $EVT_ID, |
|
| 106 | - 'Price_Type.PBT_ID' => array('!=', EEM_Price_Type::base_type_tax) |
|
| 107 | - ), |
|
| 108 | - 'order_by' => $this->_order_by_array_for_get_all_method() |
|
| 109 | - )); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * retrieve all active global prices (that are not taxes (PBT_ID=4)) for a particular event |
|
| 115 | - * |
|
| 116 | - * @access public |
|
| 117 | - * @param boolean $count return count |
|
| 118 | - * @return array on success |
|
| 119 | - * @return boolean false on fail |
|
| 120 | - */ |
|
| 121 | - public function get_all_default_prices($count = false) |
|
| 122 | - { |
|
| 123 | - $_where = array( |
|
| 124 | - 'Price_Type.PBT_ID' => array('!=',4), |
|
| 125 | - 'PRC_deleted' => 0, |
|
| 126 | - 'PRC_is_default' => 1 |
|
| 127 | - ); |
|
| 128 | - $_query_params = array( |
|
| 129 | - $_where, |
|
| 130 | - 'order_by' => $this->_order_by_array_for_get_all_method() |
|
| 131 | - ); |
|
| 132 | - return $count ? $this->count(array($_where)) : $this->get_all($_query_params); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * retrieve all prices that are taxes |
|
| 146 | - * |
|
| 147 | - * @access public |
|
| 148 | - * @return array on success |
|
| 149 | - * @return array top-level keys are the price's order and their values are an array, |
|
| 150 | - * next-level keys are the price's ID, and their values are EE_Price objects |
|
| 151 | - */ |
|
| 152 | - public function get_all_prices_that_are_taxes() |
|
| 153 | - { |
|
| 154 | - $taxes = array(); |
|
| 155 | - $all_taxes = $this->get_all(array( |
|
| 156 | - array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax, 'PRC_is_default' => true ), |
|
| 157 | - 'order_by' => array( 'Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC' ) |
|
| 158 | - )); |
|
| 159 | - foreach ($all_taxes as $tax) { |
|
| 160 | - if ($tax instanceof EE_Price) { |
|
| 161 | - $taxes[ $tax->order() ][ $tax->ID() ] = $tax; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - return $taxes; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * retrieve all prices for an ticket plus default global prices, but not taxes |
|
| 173 | - * |
|
| 174 | - * @access public |
|
| 175 | - * @param int $TKT_ID the id of the event. If not included then we assume that this is a new ticket. |
|
| 176 | - * @return boolean false on fail |
|
| 177 | - */ |
|
| 178 | - public function get_all_ticket_prices_for_admin($TKT_ID = 0) |
|
| 179 | - { |
|
| 180 | - $array_of_price_objects = array(); |
|
| 181 | - if (empty($TKT_ID)) { |
|
| 182 | - // if there is no tkt, get prices with no tkt ID, are global, are not a tax, and are active |
|
| 183 | - // return that list |
|
| 184 | - $default_prices = $this->get_all_default_prices(); |
|
| 185 | - |
|
| 186 | - if ($default_prices) { |
|
| 187 | - foreach ($default_prices as $price) { |
|
| 188 | - if ($price instanceof EE_Price) { |
|
| 189 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - return $array_of_price_objects; |
|
| 193 | - } else { |
|
| 194 | - return array(); |
|
| 195 | - } |
|
| 196 | - } else { |
|
| 197 | - $ticket_prices = $this->get_all(array( |
|
| 198 | - array( |
|
| 199 | - 'TKT_ID' => $TKT_ID, |
|
| 200 | - 'PRC_deleted' => 0 |
|
| 201 | - ), |
|
| 202 | - 'order_by' => array('PRC_order' => 'ASC') |
|
| 203 | - )); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if (!empty($ticket_prices)) { |
|
| 207 | - foreach ($ticket_prices as $price) { |
|
| 208 | - if ($price instanceof EE_Price) { |
|
| 209 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - return $array_of_price_objects; |
|
| 213 | - } else { |
|
| 214 | - return false; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * _sort_event_prices_by_type |
|
| 222 | - * |
|
| 223 | - * @access public |
|
| 224 | - * @param \EE_Price $price_a |
|
| 225 | - * @param \EE_Price $price_b |
|
| 226 | - * @return bool false on fail |
|
| 227 | - */ |
|
| 228 | - public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b) |
|
| 229 | - { |
|
| 230 | - if ($price_a->type_obj()->order() == $price_b->type_obj()->order()) { |
|
| 231 | - return $this->_sort_event_prices_by_order($price_a, $price_b); |
|
| 232 | - } |
|
| 233 | - return $price_a->type_obj()->order() < $price_b->type_obj()->order() ? -1 : 1; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * _sort_event_prices_by_order |
|
| 240 | - * |
|
| 241 | - * @access public |
|
| 242 | - * @param \EE_Price $price_a |
|
| 243 | - * @param \EE_Price $price_b |
|
| 244 | - * @return bool false on fail |
|
| 245 | - */ |
|
| 246 | - public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b) |
|
| 247 | - { |
|
| 248 | - if ($price_a->order() == $price_b->order()) { |
|
| 249 | - return 0; |
|
| 250 | - } |
|
| 251 | - return $price_a->order() < $price_b->order() ? -1 : 1; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * get all prices of a specific type |
|
| 258 | - * |
|
| 259 | - * @access public |
|
| 260 | - * @param int $type - PRT_ID |
|
| 261 | - * @return boolean false on fail |
|
| 262 | - */ |
|
| 263 | - public function get_all_prices_that_are_type($type = 0) |
|
| 264 | - { |
|
| 265 | - return $this->get_all(array( |
|
| 266 | - array( |
|
| 267 | - 'PRT_ID' => $type |
|
| 268 | - ), |
|
| 269 | - 'order_by' => $this->_order_by_array_for_get_all_method() |
|
| 270 | - )); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * Returns an array of the normal 'order_by' query parameter provided to the get_all query. |
|
| 277 | - * Of course you don't have to use it, but this is the order we usually want to sort prices by |
|
| 278 | - * @return array which can be used like so: $this->get_all(array(array(...where stuff...),'order_by'=>$this->_order_by_array_for_get_all_method())); |
|
| 279 | - */ |
|
| 280 | - public function _order_by_array_for_get_all_method() |
|
| 281 | - { |
|
| 282 | - return array( |
|
| 283 | - 'PRC_order' => 'ASC', |
|
| 284 | - 'Price_Type.PRT_order' => 'ASC', |
|
| 285 | - 'PRC_ID' => 'ASC' |
|
| 286 | - ); |
|
| 287 | - } |
|
| 13 | + // private instance of the EEM_Price object |
|
| 14 | + protected static $_instance = null; |
|
| 15 | + |
|
| 16 | + |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * private constructor to prevent direct creation |
|
| 20 | + * @Constructor |
|
| 21 | + * @access protected |
|
| 22 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
| 23 | + * @return EEM_Price |
|
| 24 | + */ |
|
| 25 | + protected function __construct($timezone) |
|
| 26 | + { |
|
| 27 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 28 | + $this->singular_item = esc_html__('Price', 'event_espresso'); |
|
| 29 | + $this->plural_item = esc_html__('Prices', 'event_espresso'); |
|
| 30 | + |
|
| 31 | + $this->_tables = array( |
|
| 32 | + 'Price' => new EE_Primary_Table('esp_price', 'PRC_ID') |
|
| 33 | + ); |
|
| 34 | + $this->_fields = array( |
|
| 35 | + 'Price' => array( |
|
| 36 | + 'PRC_ID' => new EE_Primary_Key_Int_Field('PRC_ID', 'Price ID'), |
|
| 37 | + 'PRT_ID' => new EE_Foreign_Key_Int_Field('PRT_ID', 'Price type Id', false, null, 'Price_Type'), |
|
| 38 | + 'PRC_amount' => new EE_Money_Field('PRC_amount', 'Price Amount', false, 0), |
|
| 39 | + 'PRC_name' => new EE_Plain_Text_Field('PRC_name', 'Name of Price', false, ''), |
|
| 40 | + 'PRC_desc' => new EE_Post_Content_Field('PRC_desc', 'Price Description', false, ''), |
|
| 41 | + 'PRC_is_default' => new EE_Boolean_Field('PRC_is_default', 'Flag indicating whether price is a default price', false, false), |
|
| 42 | + 'PRC_overrides' => new EE_Integer_Field('PRC_overrides', 'Price ID for a global Price that will be overridden by this Price ( for replacing default prices )', true, 0), |
|
| 43 | + 'PRC_order' => new EE_Integer_Field('PRC_order', 'Order of Application of Price (lower numbers apply first?)', false, 1), |
|
| 44 | + 'PRC_deleted' => new EE_Trashed_Flag_Field('PRC_deleted', 'Flag Indicating if this has been deleted or not', false, false), |
|
| 45 | + 'PRC_parent' => new EE_Integer_Field('PRC_parent', esc_html__('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), true, 0), |
|
| 46 | + 'PRC_wp_user' => new EE_WP_User_Field('PRC_wp_user', esc_html__('Price Creator ID', 'event_espresso'), false), |
|
| 47 | + ) |
|
| 48 | + ); |
|
| 49 | + $this->_model_relations = array( |
|
| 50 | + 'Ticket' => new EE_HABTM_Relation('Ticket_Price'), |
|
| 51 | + 'Price_Type' => new EE_Belongs_To_Relation(), |
|
| 52 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 53 | + ); |
|
| 54 | + // this model is generally available for reading |
|
| 55 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event'); |
|
| 56 | + // account for default tickets in the caps |
|
| 57 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
| 58 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
| 59 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
| 60 | + parent::__construct($timezone); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * instantiate a new price object with blank/empty properties |
|
| 67 | + * |
|
| 68 | + * @access public |
|
| 69 | + * @return mixed array on success, FALSE on fail |
|
| 70 | + */ |
|
| 71 | + public function get_new_price() |
|
| 72 | + { |
|
| 73 | + return $this->create_default_object(); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * retrieve ALL prices from db |
|
| 82 | + * |
|
| 83 | + * @access public |
|
| 84 | + * @return EE_PRice[] |
|
| 85 | + */ |
|
| 86 | + public function get_all_prices() |
|
| 87 | + { |
|
| 88 | + // retrieve all prices |
|
| 89 | + return $this->get_all(array('order_by' => array('PRC_amount' => 'ASC'))); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * retrieve all active prices for a particular event |
|
| 96 | + * |
|
| 97 | + * @access public |
|
| 98 | + * @param int $EVT_ID |
|
| 99 | + * @return array on success |
|
| 100 | + */ |
|
| 101 | + public function get_all_event_prices($EVT_ID = 0) |
|
| 102 | + { |
|
| 103 | + return $this->get_all(array( |
|
| 104 | + array( |
|
| 105 | + 'EVT_ID' => $EVT_ID, |
|
| 106 | + 'Price_Type.PBT_ID' => array('!=', EEM_Price_Type::base_type_tax) |
|
| 107 | + ), |
|
| 108 | + 'order_by' => $this->_order_by_array_for_get_all_method() |
|
| 109 | + )); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * retrieve all active global prices (that are not taxes (PBT_ID=4)) for a particular event |
|
| 115 | + * |
|
| 116 | + * @access public |
|
| 117 | + * @param boolean $count return count |
|
| 118 | + * @return array on success |
|
| 119 | + * @return boolean false on fail |
|
| 120 | + */ |
|
| 121 | + public function get_all_default_prices($count = false) |
|
| 122 | + { |
|
| 123 | + $_where = array( |
|
| 124 | + 'Price_Type.PBT_ID' => array('!=',4), |
|
| 125 | + 'PRC_deleted' => 0, |
|
| 126 | + 'PRC_is_default' => 1 |
|
| 127 | + ); |
|
| 128 | + $_query_params = array( |
|
| 129 | + $_where, |
|
| 130 | + 'order_by' => $this->_order_by_array_for_get_all_method() |
|
| 131 | + ); |
|
| 132 | + return $count ? $this->count(array($_where)) : $this->get_all($_query_params); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * retrieve all prices that are taxes |
|
| 146 | + * |
|
| 147 | + * @access public |
|
| 148 | + * @return array on success |
|
| 149 | + * @return array top-level keys are the price's order and their values are an array, |
|
| 150 | + * next-level keys are the price's ID, and their values are EE_Price objects |
|
| 151 | + */ |
|
| 152 | + public function get_all_prices_that_are_taxes() |
|
| 153 | + { |
|
| 154 | + $taxes = array(); |
|
| 155 | + $all_taxes = $this->get_all(array( |
|
| 156 | + array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax, 'PRC_is_default' => true ), |
|
| 157 | + 'order_by' => array( 'Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC' ) |
|
| 158 | + )); |
|
| 159 | + foreach ($all_taxes as $tax) { |
|
| 160 | + if ($tax instanceof EE_Price) { |
|
| 161 | + $taxes[ $tax->order() ][ $tax->ID() ] = $tax; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + return $taxes; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * retrieve all prices for an ticket plus default global prices, but not taxes |
|
| 173 | + * |
|
| 174 | + * @access public |
|
| 175 | + * @param int $TKT_ID the id of the event. If not included then we assume that this is a new ticket. |
|
| 176 | + * @return boolean false on fail |
|
| 177 | + */ |
|
| 178 | + public function get_all_ticket_prices_for_admin($TKT_ID = 0) |
|
| 179 | + { |
|
| 180 | + $array_of_price_objects = array(); |
|
| 181 | + if (empty($TKT_ID)) { |
|
| 182 | + // if there is no tkt, get prices with no tkt ID, are global, are not a tax, and are active |
|
| 183 | + // return that list |
|
| 184 | + $default_prices = $this->get_all_default_prices(); |
|
| 185 | + |
|
| 186 | + if ($default_prices) { |
|
| 187 | + foreach ($default_prices as $price) { |
|
| 188 | + if ($price instanceof EE_Price) { |
|
| 189 | + $array_of_price_objects[ $price->type() ][] = $price; |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + return $array_of_price_objects; |
|
| 193 | + } else { |
|
| 194 | + return array(); |
|
| 195 | + } |
|
| 196 | + } else { |
|
| 197 | + $ticket_prices = $this->get_all(array( |
|
| 198 | + array( |
|
| 199 | + 'TKT_ID' => $TKT_ID, |
|
| 200 | + 'PRC_deleted' => 0 |
|
| 201 | + ), |
|
| 202 | + 'order_by' => array('PRC_order' => 'ASC') |
|
| 203 | + )); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if (!empty($ticket_prices)) { |
|
| 207 | + foreach ($ticket_prices as $price) { |
|
| 208 | + if ($price instanceof EE_Price) { |
|
| 209 | + $array_of_price_objects[ $price->type() ][] = $price; |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + return $array_of_price_objects; |
|
| 213 | + } else { |
|
| 214 | + return false; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * _sort_event_prices_by_type |
|
| 222 | + * |
|
| 223 | + * @access public |
|
| 224 | + * @param \EE_Price $price_a |
|
| 225 | + * @param \EE_Price $price_b |
|
| 226 | + * @return bool false on fail |
|
| 227 | + */ |
|
| 228 | + public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b) |
|
| 229 | + { |
|
| 230 | + if ($price_a->type_obj()->order() == $price_b->type_obj()->order()) { |
|
| 231 | + return $this->_sort_event_prices_by_order($price_a, $price_b); |
|
| 232 | + } |
|
| 233 | + return $price_a->type_obj()->order() < $price_b->type_obj()->order() ? -1 : 1; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * _sort_event_prices_by_order |
|
| 240 | + * |
|
| 241 | + * @access public |
|
| 242 | + * @param \EE_Price $price_a |
|
| 243 | + * @param \EE_Price $price_b |
|
| 244 | + * @return bool false on fail |
|
| 245 | + */ |
|
| 246 | + public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b) |
|
| 247 | + { |
|
| 248 | + if ($price_a->order() == $price_b->order()) { |
|
| 249 | + return 0; |
|
| 250 | + } |
|
| 251 | + return $price_a->order() < $price_b->order() ? -1 : 1; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * get all prices of a specific type |
|
| 258 | + * |
|
| 259 | + * @access public |
|
| 260 | + * @param int $type - PRT_ID |
|
| 261 | + * @return boolean false on fail |
|
| 262 | + */ |
|
| 263 | + public function get_all_prices_that_are_type($type = 0) |
|
| 264 | + { |
|
| 265 | + return $this->get_all(array( |
|
| 266 | + array( |
|
| 267 | + 'PRT_ID' => $type |
|
| 268 | + ), |
|
| 269 | + 'order_by' => $this->_order_by_array_for_get_all_method() |
|
| 270 | + )); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * Returns an array of the normal 'order_by' query parameter provided to the get_all query. |
|
| 277 | + * Of course you don't have to use it, but this is the order we usually want to sort prices by |
|
| 278 | + * @return array which can be used like so: $this->get_all(array(array(...where stuff...),'order_by'=>$this->_order_by_array_for_get_all_method())); |
|
| 279 | + */ |
|
| 280 | + public function _order_by_array_for_get_all_method() |
|
| 281 | + { |
|
| 282 | + return array( |
|
| 283 | + 'PRC_order' => 'ASC', |
|
| 284 | + 'Price_Type.PRT_order' => 'ASC', |
|
| 285 | + 'PRC_ID' => 'ASC' |
|
| 286 | + ); |
|
| 287 | + } |
|
| 288 | 288 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | protected function __construct($timezone) |
| 26 | 26 | { |
| 27 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 27 | + require_once(EE_MODELS.'EEM_Price_Type.model.php'); |
|
| 28 | 28 | $this->singular_item = esc_html__('Price', 'event_espresso'); |
| 29 | 29 | $this->plural_item = esc_html__('Prices', 'event_espresso'); |
| 30 | 30 | |
@@ -52,11 +52,11 @@ discard block |
||
| 52 | 52 | 'WP_User' => new EE_Belongs_To_Relation(), |
| 53 | 53 | ); |
| 54 | 54 | // this model is generally available for reading |
| 55 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event'); |
|
| 55 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event'); |
|
| 56 | 56 | // account for default tickets in the caps |
| 57 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
| 58 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
| 59 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
| 57 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
| 58 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
| 59 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
| 60 | 60 | parent::__construct($timezone); |
| 61 | 61 | } |
| 62 | 62 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | return $this->get_all(array( |
| 104 | 104 | array( |
| 105 | 105 | 'EVT_ID' => $EVT_ID, |
| 106 | - 'Price_Type.PBT_ID' => array('!=', EEM_Price_Type::base_type_tax) |
|
| 106 | + 'Price_Type.PBT_ID' => array('!=', EEM_Price_Type::base_type_tax) |
|
| 107 | 107 | ), |
| 108 | 108 | 'order_by' => $this->_order_by_array_for_get_all_method() |
| 109 | 109 | )); |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | public function get_all_default_prices($count = false) |
| 122 | 122 | { |
| 123 | 123 | $_where = array( |
| 124 | - 'Price_Type.PBT_ID' => array('!=',4), |
|
| 124 | + 'Price_Type.PBT_ID' => array('!=', 4), |
|
| 125 | 125 | 'PRC_deleted' => 0, |
| 126 | 126 | 'PRC_is_default' => 1 |
| 127 | 127 | ); |
@@ -153,12 +153,12 @@ discard block |
||
| 153 | 153 | { |
| 154 | 154 | $taxes = array(); |
| 155 | 155 | $all_taxes = $this->get_all(array( |
| 156 | - array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax, 'PRC_is_default' => true ), |
|
| 157 | - 'order_by' => array( 'Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC' ) |
|
| 156 | + array('Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax, 'PRC_is_default' => true), |
|
| 157 | + 'order_by' => array('Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC') |
|
| 158 | 158 | )); |
| 159 | 159 | foreach ($all_taxes as $tax) { |
| 160 | 160 | if ($tax instanceof EE_Price) { |
| 161 | - $taxes[ $tax->order() ][ $tax->ID() ] = $tax; |
|
| 161 | + $taxes[$tax->order()][$tax->ID()] = $tax; |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | return $taxes; |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | if ($default_prices) { |
| 187 | 187 | foreach ($default_prices as $price) { |
| 188 | 188 | if ($price instanceof EE_Price) { |
| 189 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
| 189 | + $array_of_price_objects[$price->type()][] = $price; |
|
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | 192 | return $array_of_price_objects; |
@@ -203,10 +203,10 @@ discard block |
||
| 203 | 203 | )); |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - if (!empty($ticket_prices)) { |
|
| 206 | + if ( ! empty($ticket_prices)) { |
|
| 207 | 207 | foreach ($ticket_prices as $price) { |
| 208 | 208 | if ($price instanceof EE_Price) { |
| 209 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
| 209 | + $array_of_price_objects[$price->type()][] = $price; |
|
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | 212 | return $array_of_price_objects; |
@@ -15,2202 +15,2202 @@ |
||
| 15 | 15 | class espresso_events_Pricing_Hooks extends EE_Admin_Hooks |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * This property is just used to hold the status of whether an event is currently being |
|
| 20 | - * created (true) or edited (false) |
|
| 21 | - * |
|
| 22 | - * @access protected |
|
| 23 | - * @var bool |
|
| 24 | - */ |
|
| 25 | - protected $_is_creating_event; |
|
| 18 | + /** |
|
| 19 | + * This property is just used to hold the status of whether an event is currently being |
|
| 20 | + * created (true) or edited (false) |
|
| 21 | + * |
|
| 22 | + * @access protected |
|
| 23 | + * @var bool |
|
| 24 | + */ |
|
| 25 | + protected $_is_creating_event; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Used to contain the format strings for date and time that will be used for php date and |
|
| 29 | - * time. |
|
| 30 | - * Is set in the _set_hooks_properties() method. |
|
| 31 | - * |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 34 | - protected $_date_format_strings; |
|
| 27 | + /** |
|
| 28 | + * Used to contain the format strings for date and time that will be used for php date and |
|
| 29 | + * time. |
|
| 30 | + * Is set in the _set_hooks_properties() method. |
|
| 31 | + * |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | + protected $_date_format_strings; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var string $_date_time_format |
|
| 38 | - */ |
|
| 39 | - protected $_date_time_format; |
|
| 36 | + /** |
|
| 37 | + * @var string $_date_time_format |
|
| 38 | + */ |
|
| 39 | + protected $_date_time_format; |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @throws InvalidArgumentException |
|
| 44 | - * @throws InvalidInterfaceException |
|
| 45 | - * @throws InvalidDataTypeException |
|
| 46 | - */ |
|
| 47 | - protected function _set_hooks_properties() |
|
| 48 | - { |
|
| 49 | - $this->_name = 'pricing'; |
|
| 50 | - // capability check |
|
| 51 | - if ( |
|
| 52 | - ! EE_Registry::instance()->CAP->current_user_can( |
|
| 53 | - 'ee_read_default_prices', |
|
| 54 | - 'advanced_ticket_datetime_metabox' |
|
| 55 | - ) |
|
| 56 | - ) { |
|
| 57 | - return; |
|
| 58 | - } |
|
| 59 | - $this->_setup_metaboxes(); |
|
| 60 | - $this->_set_date_time_formats(); |
|
| 61 | - $this->_validate_format_strings(); |
|
| 62 | - $this->_set_scripts_styles(); |
|
| 63 | - // commented out temporarily until logic is implemented in callback |
|
| 64 | - // add_action( |
|
| 65 | - // 'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
| 66 | - // array($this, 'autosave_handling') |
|
| 67 | - // ); |
|
| 68 | - add_filter( |
|
| 69 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 70 | - array($this, 'caf_updates') |
|
| 71 | - ); |
|
| 72 | - } |
|
| 42 | + /** |
|
| 43 | + * @throws InvalidArgumentException |
|
| 44 | + * @throws InvalidInterfaceException |
|
| 45 | + * @throws InvalidDataTypeException |
|
| 46 | + */ |
|
| 47 | + protected function _set_hooks_properties() |
|
| 48 | + { |
|
| 49 | + $this->_name = 'pricing'; |
|
| 50 | + // capability check |
|
| 51 | + if ( |
|
| 52 | + ! EE_Registry::instance()->CAP->current_user_can( |
|
| 53 | + 'ee_read_default_prices', |
|
| 54 | + 'advanced_ticket_datetime_metabox' |
|
| 55 | + ) |
|
| 56 | + ) { |
|
| 57 | + return; |
|
| 58 | + } |
|
| 59 | + $this->_setup_metaboxes(); |
|
| 60 | + $this->_set_date_time_formats(); |
|
| 61 | + $this->_validate_format_strings(); |
|
| 62 | + $this->_set_scripts_styles(); |
|
| 63 | + // commented out temporarily until logic is implemented in callback |
|
| 64 | + // add_action( |
|
| 65 | + // 'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
| 66 | + // array($this, 'autosave_handling') |
|
| 67 | + // ); |
|
| 68 | + add_filter( |
|
| 69 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 70 | + array($this, 'caf_updates') |
|
| 71 | + ); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @return void |
|
| 77 | - */ |
|
| 78 | - protected function _setup_metaboxes() |
|
| 79 | - { |
|
| 80 | - // if we were going to add our own metaboxes we'd use the below. |
|
| 81 | - $this->_metaboxes = array( |
|
| 82 | - 0 => array( |
|
| 83 | - 'page_route' => array('edit', 'create_new'), |
|
| 84 | - 'func' => 'pricing_metabox', |
|
| 85 | - 'label' => esc_html__('Event Tickets & Datetimes', 'event_espresso'), |
|
| 86 | - 'priority' => 'high', |
|
| 87 | - 'context' => 'normal', |
|
| 88 | - ), |
|
| 89 | - ); |
|
| 90 | - $this->_remove_metaboxes = array( |
|
| 91 | - 0 => array( |
|
| 92 | - 'page_route' => array('edit', 'create_new'), |
|
| 93 | - 'id' => 'espresso_event_editor_tickets', |
|
| 94 | - 'context' => 'normal', |
|
| 95 | - ), |
|
| 96 | - ); |
|
| 97 | - } |
|
| 75 | + /** |
|
| 76 | + * @return void |
|
| 77 | + */ |
|
| 78 | + protected function _setup_metaboxes() |
|
| 79 | + { |
|
| 80 | + // if we were going to add our own metaboxes we'd use the below. |
|
| 81 | + $this->_metaboxes = array( |
|
| 82 | + 0 => array( |
|
| 83 | + 'page_route' => array('edit', 'create_new'), |
|
| 84 | + 'func' => 'pricing_metabox', |
|
| 85 | + 'label' => esc_html__('Event Tickets & Datetimes', 'event_espresso'), |
|
| 86 | + 'priority' => 'high', |
|
| 87 | + 'context' => 'normal', |
|
| 88 | + ), |
|
| 89 | + ); |
|
| 90 | + $this->_remove_metaboxes = array( |
|
| 91 | + 0 => array( |
|
| 92 | + 'page_route' => array('edit', 'create_new'), |
|
| 93 | + 'id' => 'espresso_event_editor_tickets', |
|
| 94 | + 'context' => 'normal', |
|
| 95 | + ), |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * @return void |
|
| 102 | - */ |
|
| 103 | - protected function _set_date_time_formats() |
|
| 104 | - { |
|
| 105 | - /** |
|
| 106 | - * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
| 107 | - * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
| 108 | - * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
| 109 | - * |
|
| 110 | - * @since 4.6.7 |
|
| 111 | - * @var array Expected an array returned with 'date' and 'time' keys. |
|
| 112 | - */ |
|
| 113 | - $this->_date_format_strings = apply_filters( |
|
| 114 | - 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
| 115 | - array( |
|
| 116 | - 'date' => 'Y-m-d', |
|
| 117 | - 'time' => 'h:i a', |
|
| 118 | - ) |
|
| 119 | - ); |
|
| 120 | - // validate |
|
| 121 | - $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) |
|
| 122 | - ? $this->_date_format_strings['date'] |
|
| 123 | - : null; |
|
| 124 | - $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
|
| 125 | - ? $this->_date_format_strings['time'] |
|
| 126 | - : null; |
|
| 127 | - $this->_date_time_format = $this->_date_format_strings['date'] |
|
| 128 | - . ' ' |
|
| 129 | - . $this->_date_format_strings['time']; |
|
| 130 | - } |
|
| 100 | + /** |
|
| 101 | + * @return void |
|
| 102 | + */ |
|
| 103 | + protected function _set_date_time_formats() |
|
| 104 | + { |
|
| 105 | + /** |
|
| 106 | + * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
| 107 | + * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
| 108 | + * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
| 109 | + * |
|
| 110 | + * @since 4.6.7 |
|
| 111 | + * @var array Expected an array returned with 'date' and 'time' keys. |
|
| 112 | + */ |
|
| 113 | + $this->_date_format_strings = apply_filters( |
|
| 114 | + 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
| 115 | + array( |
|
| 116 | + 'date' => 'Y-m-d', |
|
| 117 | + 'time' => 'h:i a', |
|
| 118 | + ) |
|
| 119 | + ); |
|
| 120 | + // validate |
|
| 121 | + $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) |
|
| 122 | + ? $this->_date_format_strings['date'] |
|
| 123 | + : null; |
|
| 124 | + $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
|
| 125 | + ? $this->_date_format_strings['time'] |
|
| 126 | + : null; |
|
| 127 | + $this->_date_time_format = $this->_date_format_strings['date'] |
|
| 128 | + . ' ' |
|
| 129 | + . $this->_date_format_strings['time']; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * @return void |
|
| 135 | - */ |
|
| 136 | - protected function _validate_format_strings() |
|
| 137 | - { |
|
| 138 | - // validate format strings |
|
| 139 | - $format_validation = EEH_DTT_Helper::validate_format_string( |
|
| 140 | - $this->_date_time_format |
|
| 141 | - ); |
|
| 142 | - if (is_array($format_validation)) { |
|
| 143 | - $msg = '<p>'; |
|
| 144 | - $msg .= sprintf( |
|
| 145 | - esc_html__( |
|
| 146 | - 'The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
| 147 | - 'event_espresso' |
|
| 148 | - ), |
|
| 149 | - $this->_date_time_format |
|
| 150 | - ); |
|
| 151 | - $msg .= '</p><ul>'; |
|
| 152 | - foreach ($format_validation as $error) { |
|
| 153 | - $msg .= '<li>' . $error . '</li>'; |
|
| 154 | - } |
|
| 155 | - $msg .= '</ul><p>'; |
|
| 156 | - $msg .= sprintf( |
|
| 157 | - esc_html__( |
|
| 158 | - '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
| 159 | - 'event_espresso' |
|
| 160 | - ), |
|
| 161 | - '<span style="color:#D54E21;">', |
|
| 162 | - '</span>' |
|
| 163 | - ); |
|
| 164 | - $msg .= '</p>'; |
|
| 165 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 166 | - $this->_date_format_strings = array( |
|
| 167 | - 'date' => 'Y-m-d', |
|
| 168 | - 'time' => 'h:i a', |
|
| 169 | - ); |
|
| 170 | - } |
|
| 171 | - } |
|
| 133 | + /** |
|
| 134 | + * @return void |
|
| 135 | + */ |
|
| 136 | + protected function _validate_format_strings() |
|
| 137 | + { |
|
| 138 | + // validate format strings |
|
| 139 | + $format_validation = EEH_DTT_Helper::validate_format_string( |
|
| 140 | + $this->_date_time_format |
|
| 141 | + ); |
|
| 142 | + if (is_array($format_validation)) { |
|
| 143 | + $msg = '<p>'; |
|
| 144 | + $msg .= sprintf( |
|
| 145 | + esc_html__( |
|
| 146 | + 'The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
| 147 | + 'event_espresso' |
|
| 148 | + ), |
|
| 149 | + $this->_date_time_format |
|
| 150 | + ); |
|
| 151 | + $msg .= '</p><ul>'; |
|
| 152 | + foreach ($format_validation as $error) { |
|
| 153 | + $msg .= '<li>' . $error . '</li>'; |
|
| 154 | + } |
|
| 155 | + $msg .= '</ul><p>'; |
|
| 156 | + $msg .= sprintf( |
|
| 157 | + esc_html__( |
|
| 158 | + '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
| 159 | + 'event_espresso' |
|
| 160 | + ), |
|
| 161 | + '<span style="color:#D54E21;">', |
|
| 162 | + '</span>' |
|
| 163 | + ); |
|
| 164 | + $msg .= '</p>'; |
|
| 165 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 166 | + $this->_date_format_strings = array( |
|
| 167 | + 'date' => 'Y-m-d', |
|
| 168 | + 'time' => 'h:i a', |
|
| 169 | + ); |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | 173 | |
| 174 | - /** |
|
| 175 | - * @return void |
|
| 176 | - */ |
|
| 177 | - protected function _set_scripts_styles() |
|
| 178 | - { |
|
| 179 | - $this->_scripts_styles = array( |
|
| 180 | - 'registers' => array( |
|
| 181 | - 'ee-tickets-datetimes-css' => array( |
|
| 182 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
| 183 | - 'type' => 'css', |
|
| 184 | - ), |
|
| 185 | - 'ee-dtt-ticket-metabox' => array( |
|
| 186 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
| 187 | - 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
|
| 188 | - ), |
|
| 189 | - ), |
|
| 190 | - 'deregisters' => array( |
|
| 191 | - 'event-editor-css' => array('type' => 'css'), |
|
| 192 | - 'event-datetime-metabox' => array('type' => 'js'), |
|
| 193 | - ), |
|
| 194 | - 'enqueues' => array( |
|
| 195 | - 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
| 196 | - 'ee-dtt-ticket-metabox' => array('edit', 'create_new'), |
|
| 197 | - ), |
|
| 198 | - 'localize' => array( |
|
| 199 | - 'ee-dtt-ticket-metabox' => array( |
|
| 200 | - 'DTT_TRASH_BLOCK' => array( |
|
| 201 | - 'main_warning' => esc_html__( |
|
| 202 | - 'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
| 203 | - 'event_espresso' |
|
| 204 | - ), |
|
| 205 | - 'after_warning' => esc_html__( |
|
| 206 | - 'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
| 207 | - 'event_espresso' |
|
| 208 | - ), |
|
| 209 | - 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 210 | - . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
| 211 | - 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 212 | - . esc_html__('Close', 'event_espresso') . '</button>', |
|
| 213 | - 'single_warning_from_tkt' => esc_html__( |
|
| 214 | - 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
| 215 | - 'event_espresso' |
|
| 216 | - ), |
|
| 217 | - 'single_warning_from_dtt' => esc_html__( |
|
| 218 | - 'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
| 219 | - 'event_espresso' |
|
| 220 | - ), |
|
| 221 | - 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 222 | - . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
| 223 | - ), |
|
| 224 | - 'DTT_ERROR_MSG' => array( |
|
| 225 | - 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
|
| 226 | - 'dismiss_button' => '<div class="save-cancel-button-container">' |
|
| 227 | - . '<button class="button-secondary ee-modal-cancel">' |
|
| 228 | - . esc_html__('Dismiss', 'event_espresso') |
|
| 229 | - . '</button></div>', |
|
| 230 | - ), |
|
| 231 | - 'DTT_OVERSELL_WARNING' => array( |
|
| 232 | - 'datetime_ticket' => esc_html__( |
|
| 233 | - 'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
| 234 | - 'event_espresso' |
|
| 235 | - ), |
|
| 236 | - 'ticket_datetime' => esc_html__( |
|
| 237 | - 'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
| 238 | - 'event_espresso' |
|
| 239 | - ), |
|
| 240 | - ), |
|
| 241 | - 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( |
|
| 242 | - $this->_date_format_strings['date'], |
|
| 243 | - $this->_date_format_strings['time'] |
|
| 244 | - ), |
|
| 245 | - 'DTT_START_OF_WEEK' => array('dayValue' => (int) get_option('start_of_week')), |
|
| 246 | - ), |
|
| 247 | - ), |
|
| 248 | - ); |
|
| 249 | - } |
|
| 174 | + /** |
|
| 175 | + * @return void |
|
| 176 | + */ |
|
| 177 | + protected function _set_scripts_styles() |
|
| 178 | + { |
|
| 179 | + $this->_scripts_styles = array( |
|
| 180 | + 'registers' => array( |
|
| 181 | + 'ee-tickets-datetimes-css' => array( |
|
| 182 | + 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
| 183 | + 'type' => 'css', |
|
| 184 | + ), |
|
| 185 | + 'ee-dtt-ticket-metabox' => array( |
|
| 186 | + 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
| 187 | + 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
|
| 188 | + ), |
|
| 189 | + ), |
|
| 190 | + 'deregisters' => array( |
|
| 191 | + 'event-editor-css' => array('type' => 'css'), |
|
| 192 | + 'event-datetime-metabox' => array('type' => 'js'), |
|
| 193 | + ), |
|
| 194 | + 'enqueues' => array( |
|
| 195 | + 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
| 196 | + 'ee-dtt-ticket-metabox' => array('edit', 'create_new'), |
|
| 197 | + ), |
|
| 198 | + 'localize' => array( |
|
| 199 | + 'ee-dtt-ticket-metabox' => array( |
|
| 200 | + 'DTT_TRASH_BLOCK' => array( |
|
| 201 | + 'main_warning' => esc_html__( |
|
| 202 | + 'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
| 203 | + 'event_espresso' |
|
| 204 | + ), |
|
| 205 | + 'after_warning' => esc_html__( |
|
| 206 | + 'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
| 207 | + 'event_espresso' |
|
| 208 | + ), |
|
| 209 | + 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 210 | + . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
| 211 | + 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 212 | + . esc_html__('Close', 'event_espresso') . '</button>', |
|
| 213 | + 'single_warning_from_tkt' => esc_html__( |
|
| 214 | + 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
| 215 | + 'event_espresso' |
|
| 216 | + ), |
|
| 217 | + 'single_warning_from_dtt' => esc_html__( |
|
| 218 | + 'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
| 219 | + 'event_espresso' |
|
| 220 | + ), |
|
| 221 | + 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 222 | + . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
| 223 | + ), |
|
| 224 | + 'DTT_ERROR_MSG' => array( |
|
| 225 | + 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
|
| 226 | + 'dismiss_button' => '<div class="save-cancel-button-container">' |
|
| 227 | + . '<button class="button-secondary ee-modal-cancel">' |
|
| 228 | + . esc_html__('Dismiss', 'event_espresso') |
|
| 229 | + . '</button></div>', |
|
| 230 | + ), |
|
| 231 | + 'DTT_OVERSELL_WARNING' => array( |
|
| 232 | + 'datetime_ticket' => esc_html__( |
|
| 233 | + 'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
| 234 | + 'event_espresso' |
|
| 235 | + ), |
|
| 236 | + 'ticket_datetime' => esc_html__( |
|
| 237 | + 'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
| 238 | + 'event_espresso' |
|
| 239 | + ), |
|
| 240 | + ), |
|
| 241 | + 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( |
|
| 242 | + $this->_date_format_strings['date'], |
|
| 243 | + $this->_date_format_strings['time'] |
|
| 244 | + ), |
|
| 245 | + 'DTT_START_OF_WEEK' => array('dayValue' => (int) get_option('start_of_week')), |
|
| 246 | + ), |
|
| 247 | + ), |
|
| 248 | + ); |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | 251 | |
| 252 | - /** |
|
| 253 | - * @param array $update_callbacks |
|
| 254 | - * @return array |
|
| 255 | - */ |
|
| 256 | - public function caf_updates(array $update_callbacks) |
|
| 257 | - { |
|
| 258 | - foreach ($update_callbacks as $key => $callback) { |
|
| 259 | - if ($callback[1] === '_default_tickets_update') { |
|
| 260 | - unset($update_callbacks[ $key ]); |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
|
| 264 | - return $update_callbacks; |
|
| 265 | - } |
|
| 252 | + /** |
|
| 253 | + * @param array $update_callbacks |
|
| 254 | + * @return array |
|
| 255 | + */ |
|
| 256 | + public function caf_updates(array $update_callbacks) |
|
| 257 | + { |
|
| 258 | + foreach ($update_callbacks as $key => $callback) { |
|
| 259 | + if ($callback[1] === '_default_tickets_update') { |
|
| 260 | + unset($update_callbacks[ $key ]); |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
|
| 264 | + return $update_callbacks; |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | 267 | |
| 268 | - /** |
|
| 269 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 270 | - * |
|
| 271 | - * @param EE_Event $event The Event object we're attaching data to |
|
| 272 | - * @param array $data The request data from the form |
|
| 273 | - * @throws ReflectionException |
|
| 274 | - * @throws Exception |
|
| 275 | - * @throws InvalidInterfaceException |
|
| 276 | - * @throws InvalidDataTypeException |
|
| 277 | - * @throws EE_Error |
|
| 278 | - * @throws InvalidArgumentException |
|
| 279 | - */ |
|
| 280 | - public function datetime_and_tickets_caf_update($event, $data) |
|
| 281 | - { |
|
| 282 | - // first we need to start with datetimes cause they are the "root" items attached to events. |
|
| 283 | - $saved_datetimes = $this->_update_datetimes($event, $data); |
|
| 284 | - // next tackle the tickets (and prices?) |
|
| 285 | - $this->_update_tickets($event, $saved_datetimes, $data); |
|
| 286 | - } |
|
| 268 | + /** |
|
| 269 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 270 | + * |
|
| 271 | + * @param EE_Event $event The Event object we're attaching data to |
|
| 272 | + * @param array $data The request data from the form |
|
| 273 | + * @throws ReflectionException |
|
| 274 | + * @throws Exception |
|
| 275 | + * @throws InvalidInterfaceException |
|
| 276 | + * @throws InvalidDataTypeException |
|
| 277 | + * @throws EE_Error |
|
| 278 | + * @throws InvalidArgumentException |
|
| 279 | + */ |
|
| 280 | + public function datetime_and_tickets_caf_update($event, $data) |
|
| 281 | + { |
|
| 282 | + // first we need to start with datetimes cause they are the "root" items attached to events. |
|
| 283 | + $saved_datetimes = $this->_update_datetimes($event, $data); |
|
| 284 | + // next tackle the tickets (and prices?) |
|
| 285 | + $this->_update_tickets($event, $saved_datetimes, $data); |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | 288 | |
| 289 | - /** |
|
| 290 | - * update event_datetimes |
|
| 291 | - * |
|
| 292 | - * @param EE_Event $event Event being updated |
|
| 293 | - * @param array $data the request data from the form |
|
| 294 | - * @return EE_Datetime[] |
|
| 295 | - * @throws Exception |
|
| 296 | - * @throws ReflectionException |
|
| 297 | - * @throws InvalidInterfaceException |
|
| 298 | - * @throws InvalidDataTypeException |
|
| 299 | - * @throws InvalidArgumentException |
|
| 300 | - * @throws EE_Error |
|
| 301 | - */ |
|
| 302 | - protected function _update_datetimes($event, $data) |
|
| 303 | - { |
|
| 304 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 305 | - $saved_dtt_ids = array(); |
|
| 306 | - $saved_dtt_objs = array(); |
|
| 307 | - if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) { |
|
| 308 | - throw new InvalidArgumentException( |
|
| 309 | - esc_html__( |
|
| 310 | - 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
|
| 311 | - 'event_espresso' |
|
| 312 | - ) |
|
| 313 | - ); |
|
| 314 | - } |
|
| 315 | - foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
| 316 | - // trim all values to ensure any excess whitespace is removed. |
|
| 317 | - $datetime_data = array_map( |
|
| 318 | - function ($datetime_data) { |
|
| 319 | - return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
| 320 | - }, |
|
| 321 | - $datetime_data |
|
| 322 | - ); |
|
| 323 | - $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end']) |
|
| 324 | - && ! empty($datetime_data['DTT_EVT_end']) |
|
| 325 | - ? $datetime_data['DTT_EVT_end'] |
|
| 326 | - : $datetime_data['DTT_EVT_start']; |
|
| 327 | - $datetime_values = array( |
|
| 328 | - 'DTT_ID' => ! empty($datetime_data['DTT_ID']) |
|
| 329 | - ? $datetime_data['DTT_ID'] |
|
| 330 | - : null, |
|
| 331 | - 'DTT_name' => ! empty($datetime_data['DTT_name']) |
|
| 332 | - ? $datetime_data['DTT_name'] |
|
| 333 | - : '', |
|
| 334 | - 'DTT_description' => ! empty($datetime_data['DTT_description']) |
|
| 335 | - ? $datetime_data['DTT_description'] |
|
| 336 | - : '', |
|
| 337 | - 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
| 338 | - 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
| 339 | - 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) |
|
| 340 | - ? EE_INF |
|
| 341 | - : $datetime_data['DTT_reg_limit'], |
|
| 342 | - 'DTT_order' => ! isset($datetime_data['DTT_order']) |
|
| 343 | - ? $row |
|
| 344 | - : $datetime_data['DTT_order'], |
|
| 345 | - ); |
|
| 346 | - // if we have an id then let's get existing object first and then set the new values. |
|
| 347 | - // Otherwise we instantiate a new object for save. |
|
| 348 | - if (! empty($datetime_data['DTT_ID'])) { |
|
| 349 | - $datetime = EE_Registry::instance() |
|
| 350 | - ->load_model('Datetime', array($timezone)) |
|
| 351 | - ->get_one_by_ID($datetime_data['DTT_ID']); |
|
| 352 | - // set date and time format according to what is set in this class. |
|
| 353 | - $datetime->set_date_format($this->_date_format_strings['date']); |
|
| 354 | - $datetime->set_time_format($this->_date_format_strings['time']); |
|
| 355 | - foreach ($datetime_values as $field => $value) { |
|
| 356 | - $datetime->set($field, $value); |
|
| 357 | - } |
|
| 358 | - // make sure the $dtt_id here is saved just in case |
|
| 359 | - // after the add_relation_to() the autosave replaces it. |
|
| 360 | - // We need to do this so we dont' TRASH the parent DTT. |
|
| 361 | - // (save the ID for both key and value to avoid duplications) |
|
| 362 | - $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID(); |
|
| 363 | - } else { |
|
| 364 | - $datetime = EE_Registry::instance()->load_class( |
|
| 365 | - 'Datetime', |
|
| 366 | - array( |
|
| 367 | - $datetime_values, |
|
| 368 | - $timezone, |
|
| 369 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
| 370 | - ), |
|
| 371 | - false, |
|
| 372 | - false |
|
| 373 | - ); |
|
| 374 | - foreach ($datetime_values as $field => $value) { |
|
| 375 | - $datetime->set($field, $value); |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - $datetime->save(); |
|
| 379 | - do_action( |
|
| 380 | - 'AHEE__espresso_events_Pricing_Hooks___update_datetimes_after_save', |
|
| 381 | - $datetime, |
|
| 382 | - $row, |
|
| 383 | - $datetime_data, |
|
| 384 | - $data |
|
| 385 | - ); |
|
| 386 | - $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
| 387 | - // before going any further make sure our dates are setup correctly |
|
| 388 | - // so that the end date is always equal or greater than the start date. |
|
| 389 | - if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
| 390 | - $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
| 391 | - $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
| 392 | - $datetime->save(); |
|
| 393 | - } |
|
| 394 | - // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
| 395 | - // because it is possible there was a new one created for the autosave. |
|
| 396 | - // (save the ID for both key and value to avoid duplications) |
|
| 397 | - $DTT_ID = $datetime->ID(); |
|
| 398 | - $saved_dtt_ids[ $DTT_ID ] = $DTT_ID; |
|
| 399 | - $saved_dtt_objs[ $row ] = $datetime; |
|
| 400 | - // @todo if ANY of these updates fail then we want the appropriate global error message. |
|
| 401 | - } |
|
| 402 | - $event->save(); |
|
| 403 | - // now we need to REMOVE any datetimes that got deleted. |
|
| 404 | - // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
| 405 | - // So its safe to permanently delete at this point. |
|
| 406 | - $old_datetimes = explode(',', $data['datetime_IDs']); |
|
| 407 | - $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
| 408 | - if (is_array($old_datetimes)) { |
|
| 409 | - $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
| 410 | - foreach ($datetimes_to_delete as $id) { |
|
| 411 | - $id = absint($id); |
|
| 412 | - if (empty($id)) { |
|
| 413 | - continue; |
|
| 414 | - } |
|
| 415 | - $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
| 416 | - // remove tkt relationships. |
|
| 417 | - $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
| 418 | - foreach ($related_tickets as $tkt) { |
|
| 419 | - $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
| 420 | - } |
|
| 421 | - $event->_remove_relation_to($id, 'Datetime'); |
|
| 422 | - $dtt_to_remove->refresh_cache_of_related_objects(); |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - return $saved_dtt_objs; |
|
| 426 | - } |
|
| 289 | + /** |
|
| 290 | + * update event_datetimes |
|
| 291 | + * |
|
| 292 | + * @param EE_Event $event Event being updated |
|
| 293 | + * @param array $data the request data from the form |
|
| 294 | + * @return EE_Datetime[] |
|
| 295 | + * @throws Exception |
|
| 296 | + * @throws ReflectionException |
|
| 297 | + * @throws InvalidInterfaceException |
|
| 298 | + * @throws InvalidDataTypeException |
|
| 299 | + * @throws InvalidArgumentException |
|
| 300 | + * @throws EE_Error |
|
| 301 | + */ |
|
| 302 | + protected function _update_datetimes($event, $data) |
|
| 303 | + { |
|
| 304 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 305 | + $saved_dtt_ids = array(); |
|
| 306 | + $saved_dtt_objs = array(); |
|
| 307 | + if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) { |
|
| 308 | + throw new InvalidArgumentException( |
|
| 309 | + esc_html__( |
|
| 310 | + 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
|
| 311 | + 'event_espresso' |
|
| 312 | + ) |
|
| 313 | + ); |
|
| 314 | + } |
|
| 315 | + foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
| 316 | + // trim all values to ensure any excess whitespace is removed. |
|
| 317 | + $datetime_data = array_map( |
|
| 318 | + function ($datetime_data) { |
|
| 319 | + return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
| 320 | + }, |
|
| 321 | + $datetime_data |
|
| 322 | + ); |
|
| 323 | + $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end']) |
|
| 324 | + && ! empty($datetime_data['DTT_EVT_end']) |
|
| 325 | + ? $datetime_data['DTT_EVT_end'] |
|
| 326 | + : $datetime_data['DTT_EVT_start']; |
|
| 327 | + $datetime_values = array( |
|
| 328 | + 'DTT_ID' => ! empty($datetime_data['DTT_ID']) |
|
| 329 | + ? $datetime_data['DTT_ID'] |
|
| 330 | + : null, |
|
| 331 | + 'DTT_name' => ! empty($datetime_data['DTT_name']) |
|
| 332 | + ? $datetime_data['DTT_name'] |
|
| 333 | + : '', |
|
| 334 | + 'DTT_description' => ! empty($datetime_data['DTT_description']) |
|
| 335 | + ? $datetime_data['DTT_description'] |
|
| 336 | + : '', |
|
| 337 | + 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
| 338 | + 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
| 339 | + 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) |
|
| 340 | + ? EE_INF |
|
| 341 | + : $datetime_data['DTT_reg_limit'], |
|
| 342 | + 'DTT_order' => ! isset($datetime_data['DTT_order']) |
|
| 343 | + ? $row |
|
| 344 | + : $datetime_data['DTT_order'], |
|
| 345 | + ); |
|
| 346 | + // if we have an id then let's get existing object first and then set the new values. |
|
| 347 | + // Otherwise we instantiate a new object for save. |
|
| 348 | + if (! empty($datetime_data['DTT_ID'])) { |
|
| 349 | + $datetime = EE_Registry::instance() |
|
| 350 | + ->load_model('Datetime', array($timezone)) |
|
| 351 | + ->get_one_by_ID($datetime_data['DTT_ID']); |
|
| 352 | + // set date and time format according to what is set in this class. |
|
| 353 | + $datetime->set_date_format($this->_date_format_strings['date']); |
|
| 354 | + $datetime->set_time_format($this->_date_format_strings['time']); |
|
| 355 | + foreach ($datetime_values as $field => $value) { |
|
| 356 | + $datetime->set($field, $value); |
|
| 357 | + } |
|
| 358 | + // make sure the $dtt_id here is saved just in case |
|
| 359 | + // after the add_relation_to() the autosave replaces it. |
|
| 360 | + // We need to do this so we dont' TRASH the parent DTT. |
|
| 361 | + // (save the ID for both key and value to avoid duplications) |
|
| 362 | + $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID(); |
|
| 363 | + } else { |
|
| 364 | + $datetime = EE_Registry::instance()->load_class( |
|
| 365 | + 'Datetime', |
|
| 366 | + array( |
|
| 367 | + $datetime_values, |
|
| 368 | + $timezone, |
|
| 369 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
| 370 | + ), |
|
| 371 | + false, |
|
| 372 | + false |
|
| 373 | + ); |
|
| 374 | + foreach ($datetime_values as $field => $value) { |
|
| 375 | + $datetime->set($field, $value); |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + $datetime->save(); |
|
| 379 | + do_action( |
|
| 380 | + 'AHEE__espresso_events_Pricing_Hooks___update_datetimes_after_save', |
|
| 381 | + $datetime, |
|
| 382 | + $row, |
|
| 383 | + $datetime_data, |
|
| 384 | + $data |
|
| 385 | + ); |
|
| 386 | + $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
| 387 | + // before going any further make sure our dates are setup correctly |
|
| 388 | + // so that the end date is always equal or greater than the start date. |
|
| 389 | + if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
| 390 | + $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
| 391 | + $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
| 392 | + $datetime->save(); |
|
| 393 | + } |
|
| 394 | + // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
| 395 | + // because it is possible there was a new one created for the autosave. |
|
| 396 | + // (save the ID for both key and value to avoid duplications) |
|
| 397 | + $DTT_ID = $datetime->ID(); |
|
| 398 | + $saved_dtt_ids[ $DTT_ID ] = $DTT_ID; |
|
| 399 | + $saved_dtt_objs[ $row ] = $datetime; |
|
| 400 | + // @todo if ANY of these updates fail then we want the appropriate global error message. |
|
| 401 | + } |
|
| 402 | + $event->save(); |
|
| 403 | + // now we need to REMOVE any datetimes that got deleted. |
|
| 404 | + // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
| 405 | + // So its safe to permanently delete at this point. |
|
| 406 | + $old_datetimes = explode(',', $data['datetime_IDs']); |
|
| 407 | + $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
| 408 | + if (is_array($old_datetimes)) { |
|
| 409 | + $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
| 410 | + foreach ($datetimes_to_delete as $id) { |
|
| 411 | + $id = absint($id); |
|
| 412 | + if (empty($id)) { |
|
| 413 | + continue; |
|
| 414 | + } |
|
| 415 | + $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
| 416 | + // remove tkt relationships. |
|
| 417 | + $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
| 418 | + foreach ($related_tickets as $tkt) { |
|
| 419 | + $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
| 420 | + } |
|
| 421 | + $event->_remove_relation_to($id, 'Datetime'); |
|
| 422 | + $dtt_to_remove->refresh_cache_of_related_objects(); |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + return $saved_dtt_objs; |
|
| 426 | + } |
|
| 427 | 427 | |
| 428 | 428 | |
| 429 | - /** |
|
| 430 | - * update tickets |
|
| 431 | - * |
|
| 432 | - * @param EE_Event $event Event object being updated |
|
| 433 | - * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
| 434 | - * @param array $data incoming request data |
|
| 435 | - * @return EE_Ticket[] |
|
| 436 | - * @throws Exception |
|
| 437 | - * @throws ReflectionException |
|
| 438 | - * @throws InvalidInterfaceException |
|
| 439 | - * @throws InvalidDataTypeException |
|
| 440 | - * @throws InvalidArgumentException |
|
| 441 | - * @throws EE_Error |
|
| 442 | - */ |
|
| 443 | - protected function _update_tickets($event, $saved_datetimes, $data) |
|
| 444 | - { |
|
| 445 | - $new_tkt = null; |
|
| 446 | - $new_default = null; |
|
| 447 | - // stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
| 448 | - $data = stripslashes_deep($data); |
|
| 449 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 450 | - $saved_tickets = $datetimes_on_existing = array(); |
|
| 451 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 452 | - if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) { |
|
| 453 | - throw new InvalidArgumentException( |
|
| 454 | - esc_html__( |
|
| 455 | - 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
|
| 456 | - 'event_espresso' |
|
| 457 | - ) |
|
| 458 | - ); |
|
| 459 | - } |
|
| 460 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 461 | - $update_prices = $create_new_TKT = false; |
|
| 462 | - // figure out what datetimes were added to the ticket |
|
| 463 | - // and what datetimes were removed from the ticket in the session. |
|
| 464 | - $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]); |
|
| 465 | - $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]); |
|
| 466 | - $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
| 467 | - $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
| 468 | - // trim inputs to ensure any excess whitespace is removed. |
|
| 469 | - $tkt = array_map( |
|
| 470 | - function ($ticket_data) { |
|
| 471 | - return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
| 472 | - }, |
|
| 473 | - $tkt |
|
| 474 | - ); |
|
| 475 | - // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
| 476 | - // because we're doing calculations prior to using the models. |
|
| 477 | - // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
| 478 | - $ticket_price = isset($tkt['TKT_price']) |
|
| 479 | - ? round((float) $tkt['TKT_price'], 3) |
|
| 480 | - : 0; |
|
| 481 | - // note incoming base price needs converted from localized value. |
|
| 482 | - $base_price = isset($tkt['TKT_base_price']) |
|
| 483 | - ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
| 484 | - : 0; |
|
| 485 | - // if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
| 486 | - $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
| 487 | - ? $base_price |
|
| 488 | - : $ticket_price; |
|
| 489 | - $base_price_id = isset($tkt['TKT_base_price_ID']) |
|
| 490 | - ? $tkt['TKT_base_price_ID'] |
|
| 491 | - : 0; |
|
| 492 | - $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ]) |
|
| 493 | - ? $data['edit_prices'][ $row ] |
|
| 494 | - : array(); |
|
| 495 | - $now = null; |
|
| 496 | - if (empty($tkt['TKT_start_date'])) { |
|
| 497 | - // lets' use now in the set timezone. |
|
| 498 | - $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
| 499 | - $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
| 500 | - } |
|
| 501 | - if (empty($tkt['TKT_end_date'])) { |
|
| 502 | - /** |
|
| 503 | - * set the TKT_end_date to the first datetime attached to the ticket. |
|
| 504 | - */ |
|
| 505 | - $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ]; |
|
| 506 | - $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
| 507 | - } |
|
| 508 | - $TKT_values = array( |
|
| 509 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 510 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 511 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 512 | - 'TKT_description' => ! empty($tkt['TKT_description']) |
|
| 513 | - && $tkt['TKT_description'] !== esc_html__( |
|
| 514 | - 'You can modify this description', |
|
| 515 | - 'event_espresso' |
|
| 516 | - ) |
|
| 517 | - ? $tkt['TKT_description'] |
|
| 518 | - : '', |
|
| 519 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 520 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 521 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
| 522 | - ? EE_INF |
|
| 523 | - : $tkt['TKT_qty'], |
|
| 524 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
| 525 | - ? EE_INF |
|
| 526 | - : $tkt['TKT_uses'], |
|
| 527 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 528 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 529 | - 'TKT_row' => $row, |
|
| 530 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
| 531 | - 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
| 532 | - 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
| 533 | - 'TKT_price' => $ticket_price, |
|
| 534 | - ); |
|
| 535 | - // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
| 536 | - // which means in turn that the prices will become new prices as well. |
|
| 537 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 538 | - $TKT_values['TKT_ID'] = 0; |
|
| 539 | - $TKT_values['TKT_is_default'] = 0; |
|
| 540 | - $update_prices = true; |
|
| 541 | - } |
|
| 542 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 543 | - // we actually do our saves ahead of doing any add_relations to |
|
| 544 | - // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
| 545 | - // but DID have it's items modified. |
|
| 546 | - // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
| 547 | - // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 548 | - if (absint($TKT_values['TKT_ID'])) { |
|
| 549 | - $ticket = EE_Registry::instance() |
|
| 550 | - ->load_model('Ticket', array($timezone)) |
|
| 551 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
| 552 | - if ($ticket instanceof EE_Ticket) { |
|
| 553 | - $ticket = $this->_update_ticket_datetimes( |
|
| 554 | - $ticket, |
|
| 555 | - $saved_datetimes, |
|
| 556 | - $datetimes_added, |
|
| 557 | - $datetimes_removed |
|
| 558 | - ); |
|
| 559 | - // are there any registrations using this ticket ? |
|
| 560 | - $tickets_sold = $ticket->count_related( |
|
| 561 | - 'Registration', |
|
| 562 | - array( |
|
| 563 | - array( |
|
| 564 | - 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
| 565 | - ), |
|
| 566 | - ) |
|
| 567 | - ); |
|
| 568 | - // set ticket formats |
|
| 569 | - $ticket->set_date_format($this->_date_format_strings['date']); |
|
| 570 | - $ticket->set_time_format($this->_date_format_strings['time']); |
|
| 571 | - // let's just check the total price for the existing ticket |
|
| 572 | - // and determine if it matches the new total price. |
|
| 573 | - // if they are different then we create a new ticket (if tickets sold) |
|
| 574 | - // if they aren't different then we go ahead and modify existing ticket. |
|
| 575 | - $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted(); |
|
| 576 | - // set new values |
|
| 577 | - foreach ($TKT_values as $field => $value) { |
|
| 578 | - if ($field === 'TKT_qty') { |
|
| 579 | - $ticket->set_qty($value); |
|
| 580 | - } else { |
|
| 581 | - $ticket->set($field, $value); |
|
| 582 | - } |
|
| 583 | - } |
|
| 584 | - // if $create_new_TKT is false then we can safely update the existing ticket. |
|
| 585 | - // Otherwise we have to create a new ticket. |
|
| 586 | - if ($create_new_TKT) { |
|
| 587 | - $new_tkt = $this->_duplicate_ticket( |
|
| 588 | - $ticket, |
|
| 589 | - $price_rows, |
|
| 590 | - $ticket_price, |
|
| 591 | - $base_price, |
|
| 592 | - $base_price_id |
|
| 593 | - ); |
|
| 594 | - } |
|
| 595 | - } |
|
| 596 | - } else { |
|
| 597 | - // no TKT_id so a new TKT |
|
| 598 | - $ticket = EE_Ticket::new_instance( |
|
| 599 | - $TKT_values, |
|
| 600 | - $timezone, |
|
| 601 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
| 602 | - ); |
|
| 603 | - if ($ticket instanceof EE_Ticket) { |
|
| 604 | - // make sure ticket has an ID of setting relations won't work |
|
| 605 | - $ticket->save(); |
|
| 606 | - $ticket = $this->_update_ticket_datetimes( |
|
| 607 | - $ticket, |
|
| 608 | - $saved_datetimes, |
|
| 609 | - $datetimes_added, |
|
| 610 | - $datetimes_removed |
|
| 611 | - ); |
|
| 612 | - $update_prices = true; |
|
| 613 | - } |
|
| 614 | - } |
|
| 615 | - // make sure any current values have been saved. |
|
| 616 | - // $ticket->save(); |
|
| 617 | - // before going any further make sure our dates are setup correctly |
|
| 618 | - // so that the end date is always equal or greater than the start date. |
|
| 619 | - if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
| 620 | - $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
| 621 | - $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
| 622 | - } |
|
| 623 | - // let's make sure the base price is handled |
|
| 624 | - $ticket = ! $create_new_TKT |
|
| 625 | - ? $this->_add_prices_to_ticket( |
|
| 626 | - array(), |
|
| 627 | - $ticket, |
|
| 628 | - $update_prices, |
|
| 629 | - $base_price, |
|
| 630 | - $base_price_id |
|
| 631 | - ) |
|
| 632 | - : $ticket; |
|
| 633 | - // add/update price_modifiers |
|
| 634 | - $ticket = ! $create_new_TKT |
|
| 635 | - ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) |
|
| 636 | - : $ticket; |
|
| 637 | - // need to make sue that the TKT_price is accurate after saving the prices. |
|
| 638 | - $ticket->ensure_TKT_Price_correct(); |
|
| 639 | - // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
| 640 | - if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
| 641 | - $update_prices = true; |
|
| 642 | - $new_default = clone $ticket; |
|
| 643 | - $new_default->set('TKT_ID', 0); |
|
| 644 | - $new_default->set('TKT_is_default', 1); |
|
| 645 | - $new_default->set('TKT_row', 1); |
|
| 646 | - $new_default->set('TKT_price', $ticket_price); |
|
| 647 | - // remove any dtt relations cause we DON'T want dtt relations attached |
|
| 648 | - // (note this is just removing the cached relations in the object) |
|
| 649 | - $new_default->_remove_relations('Datetime'); |
|
| 650 | - // @todo we need to add the current attached prices as new prices to the new default ticket. |
|
| 651 | - $new_default = $this->_add_prices_to_ticket( |
|
| 652 | - $price_rows, |
|
| 653 | - $new_default, |
|
| 654 | - $update_prices |
|
| 655 | - ); |
|
| 656 | - // don't forget the base price! |
|
| 657 | - $new_default = $this->_add_prices_to_ticket( |
|
| 658 | - array(), |
|
| 659 | - $new_default, |
|
| 660 | - $update_prices, |
|
| 661 | - $base_price, |
|
| 662 | - $base_price_id |
|
| 663 | - ); |
|
| 664 | - $new_default->save(); |
|
| 665 | - do_action( |
|
| 666 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
| 667 | - $new_default, |
|
| 668 | - $row, |
|
| 669 | - $ticket, |
|
| 670 | - $data |
|
| 671 | - ); |
|
| 672 | - } |
|
| 673 | - // DO ALL dtt relationships for both current tickets and any archived tickets |
|
| 674 | - // for the given dtt that are related to the current ticket. |
|
| 675 | - // TODO... not sure exactly how we're going to do this considering we don't know |
|
| 676 | - // what current ticket the archived tickets are related to |
|
| 677 | - // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
| 678 | - // let's assign any tickets that have been setup to the saved_tickets tracker |
|
| 679 | - // save existing TKT |
|
| 680 | - $ticket->save(); |
|
| 681 | - if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
| 682 | - // save new TKT |
|
| 683 | - $new_tkt->save(); |
|
| 684 | - // add new ticket to array |
|
| 685 | - $saved_tickets[ $new_tkt->ID() ] = $new_tkt; |
|
| 686 | - do_action( |
|
| 687 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
| 688 | - $new_tkt, |
|
| 689 | - $row, |
|
| 690 | - $tkt, |
|
| 691 | - $data |
|
| 692 | - ); |
|
| 693 | - } else { |
|
| 694 | - // add tkt to saved tkts |
|
| 695 | - $saved_tickets[ $ticket->ID() ] = $ticket; |
|
| 696 | - do_action( |
|
| 697 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
| 698 | - $ticket, |
|
| 699 | - $row, |
|
| 700 | - $tkt, |
|
| 701 | - $data |
|
| 702 | - ); |
|
| 703 | - } |
|
| 704 | - } |
|
| 705 | - // now we need to handle tickets actually "deleted permanently". |
|
| 706 | - // There are cases where we'd want this to happen |
|
| 707 | - // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
| 708 | - // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
| 709 | - // No sense in keeping all the related data in the db! |
|
| 710 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
| 711 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 712 | - foreach ($tickets_removed as $id) { |
|
| 713 | - $id = absint($id); |
|
| 714 | - // get the ticket for this id |
|
| 715 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 716 | - // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
| 717 | - if ($tkt_to_remove->get('TKT_is_default')) { |
|
| 718 | - continue; |
|
| 719 | - } |
|
| 720 | - // if this tkt has any registrations attached so then we just ARCHIVE |
|
| 721 | - // because we don't actually permanently delete these tickets. |
|
| 722 | - if ($tkt_to_remove->count_related('Registration') > 0) { |
|
| 723 | - $tkt_to_remove->delete(); |
|
| 724 | - continue; |
|
| 725 | - } |
|
| 726 | - // need to get all the related datetimes on this ticket and remove from every single one of them |
|
| 727 | - // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 728 | - $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
| 729 | - foreach ($datetimes as $datetime) { |
|
| 730 | - $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
| 731 | - } |
|
| 732 | - // need to do the same for prices (except these prices can also be deleted because again, |
|
| 733 | - // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 734 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
| 735 | - do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
| 736 | - // finally let's delete this ticket |
|
| 737 | - // (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 738 | - $tkt_to_remove->delete_permanently(); |
|
| 739 | - } |
|
| 740 | - return $saved_tickets; |
|
| 741 | - } |
|
| 429 | + /** |
|
| 430 | + * update tickets |
|
| 431 | + * |
|
| 432 | + * @param EE_Event $event Event object being updated |
|
| 433 | + * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
| 434 | + * @param array $data incoming request data |
|
| 435 | + * @return EE_Ticket[] |
|
| 436 | + * @throws Exception |
|
| 437 | + * @throws ReflectionException |
|
| 438 | + * @throws InvalidInterfaceException |
|
| 439 | + * @throws InvalidDataTypeException |
|
| 440 | + * @throws InvalidArgumentException |
|
| 441 | + * @throws EE_Error |
|
| 442 | + */ |
|
| 443 | + protected function _update_tickets($event, $saved_datetimes, $data) |
|
| 444 | + { |
|
| 445 | + $new_tkt = null; |
|
| 446 | + $new_default = null; |
|
| 447 | + // stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
| 448 | + $data = stripslashes_deep($data); |
|
| 449 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 450 | + $saved_tickets = $datetimes_on_existing = array(); |
|
| 451 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 452 | + if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) { |
|
| 453 | + throw new InvalidArgumentException( |
|
| 454 | + esc_html__( |
|
| 455 | + 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
|
| 456 | + 'event_espresso' |
|
| 457 | + ) |
|
| 458 | + ); |
|
| 459 | + } |
|
| 460 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 461 | + $update_prices = $create_new_TKT = false; |
|
| 462 | + // figure out what datetimes were added to the ticket |
|
| 463 | + // and what datetimes were removed from the ticket in the session. |
|
| 464 | + $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]); |
|
| 465 | + $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]); |
|
| 466 | + $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
| 467 | + $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
| 468 | + // trim inputs to ensure any excess whitespace is removed. |
|
| 469 | + $tkt = array_map( |
|
| 470 | + function ($ticket_data) { |
|
| 471 | + return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
| 472 | + }, |
|
| 473 | + $tkt |
|
| 474 | + ); |
|
| 475 | + // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
| 476 | + // because we're doing calculations prior to using the models. |
|
| 477 | + // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
| 478 | + $ticket_price = isset($tkt['TKT_price']) |
|
| 479 | + ? round((float) $tkt['TKT_price'], 3) |
|
| 480 | + : 0; |
|
| 481 | + // note incoming base price needs converted from localized value. |
|
| 482 | + $base_price = isset($tkt['TKT_base_price']) |
|
| 483 | + ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
| 484 | + : 0; |
|
| 485 | + // if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
| 486 | + $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
| 487 | + ? $base_price |
|
| 488 | + : $ticket_price; |
|
| 489 | + $base_price_id = isset($tkt['TKT_base_price_ID']) |
|
| 490 | + ? $tkt['TKT_base_price_ID'] |
|
| 491 | + : 0; |
|
| 492 | + $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ]) |
|
| 493 | + ? $data['edit_prices'][ $row ] |
|
| 494 | + : array(); |
|
| 495 | + $now = null; |
|
| 496 | + if (empty($tkt['TKT_start_date'])) { |
|
| 497 | + // lets' use now in the set timezone. |
|
| 498 | + $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
| 499 | + $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
| 500 | + } |
|
| 501 | + if (empty($tkt['TKT_end_date'])) { |
|
| 502 | + /** |
|
| 503 | + * set the TKT_end_date to the first datetime attached to the ticket. |
|
| 504 | + */ |
|
| 505 | + $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ]; |
|
| 506 | + $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
| 507 | + } |
|
| 508 | + $TKT_values = array( |
|
| 509 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 510 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 511 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 512 | + 'TKT_description' => ! empty($tkt['TKT_description']) |
|
| 513 | + && $tkt['TKT_description'] !== esc_html__( |
|
| 514 | + 'You can modify this description', |
|
| 515 | + 'event_espresso' |
|
| 516 | + ) |
|
| 517 | + ? $tkt['TKT_description'] |
|
| 518 | + : '', |
|
| 519 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 520 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 521 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
| 522 | + ? EE_INF |
|
| 523 | + : $tkt['TKT_qty'], |
|
| 524 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
| 525 | + ? EE_INF |
|
| 526 | + : $tkt['TKT_uses'], |
|
| 527 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 528 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 529 | + 'TKT_row' => $row, |
|
| 530 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
| 531 | + 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
| 532 | + 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
| 533 | + 'TKT_price' => $ticket_price, |
|
| 534 | + ); |
|
| 535 | + // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
| 536 | + // which means in turn that the prices will become new prices as well. |
|
| 537 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 538 | + $TKT_values['TKT_ID'] = 0; |
|
| 539 | + $TKT_values['TKT_is_default'] = 0; |
|
| 540 | + $update_prices = true; |
|
| 541 | + } |
|
| 542 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 543 | + // we actually do our saves ahead of doing any add_relations to |
|
| 544 | + // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
| 545 | + // but DID have it's items modified. |
|
| 546 | + // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
| 547 | + // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 548 | + if (absint($TKT_values['TKT_ID'])) { |
|
| 549 | + $ticket = EE_Registry::instance() |
|
| 550 | + ->load_model('Ticket', array($timezone)) |
|
| 551 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
| 552 | + if ($ticket instanceof EE_Ticket) { |
|
| 553 | + $ticket = $this->_update_ticket_datetimes( |
|
| 554 | + $ticket, |
|
| 555 | + $saved_datetimes, |
|
| 556 | + $datetimes_added, |
|
| 557 | + $datetimes_removed |
|
| 558 | + ); |
|
| 559 | + // are there any registrations using this ticket ? |
|
| 560 | + $tickets_sold = $ticket->count_related( |
|
| 561 | + 'Registration', |
|
| 562 | + array( |
|
| 563 | + array( |
|
| 564 | + 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
| 565 | + ), |
|
| 566 | + ) |
|
| 567 | + ); |
|
| 568 | + // set ticket formats |
|
| 569 | + $ticket->set_date_format($this->_date_format_strings['date']); |
|
| 570 | + $ticket->set_time_format($this->_date_format_strings['time']); |
|
| 571 | + // let's just check the total price for the existing ticket |
|
| 572 | + // and determine if it matches the new total price. |
|
| 573 | + // if they are different then we create a new ticket (if tickets sold) |
|
| 574 | + // if they aren't different then we go ahead and modify existing ticket. |
|
| 575 | + $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted(); |
|
| 576 | + // set new values |
|
| 577 | + foreach ($TKT_values as $field => $value) { |
|
| 578 | + if ($field === 'TKT_qty') { |
|
| 579 | + $ticket->set_qty($value); |
|
| 580 | + } else { |
|
| 581 | + $ticket->set($field, $value); |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + // if $create_new_TKT is false then we can safely update the existing ticket. |
|
| 585 | + // Otherwise we have to create a new ticket. |
|
| 586 | + if ($create_new_TKT) { |
|
| 587 | + $new_tkt = $this->_duplicate_ticket( |
|
| 588 | + $ticket, |
|
| 589 | + $price_rows, |
|
| 590 | + $ticket_price, |
|
| 591 | + $base_price, |
|
| 592 | + $base_price_id |
|
| 593 | + ); |
|
| 594 | + } |
|
| 595 | + } |
|
| 596 | + } else { |
|
| 597 | + // no TKT_id so a new TKT |
|
| 598 | + $ticket = EE_Ticket::new_instance( |
|
| 599 | + $TKT_values, |
|
| 600 | + $timezone, |
|
| 601 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
| 602 | + ); |
|
| 603 | + if ($ticket instanceof EE_Ticket) { |
|
| 604 | + // make sure ticket has an ID of setting relations won't work |
|
| 605 | + $ticket->save(); |
|
| 606 | + $ticket = $this->_update_ticket_datetimes( |
|
| 607 | + $ticket, |
|
| 608 | + $saved_datetimes, |
|
| 609 | + $datetimes_added, |
|
| 610 | + $datetimes_removed |
|
| 611 | + ); |
|
| 612 | + $update_prices = true; |
|
| 613 | + } |
|
| 614 | + } |
|
| 615 | + // make sure any current values have been saved. |
|
| 616 | + // $ticket->save(); |
|
| 617 | + // before going any further make sure our dates are setup correctly |
|
| 618 | + // so that the end date is always equal or greater than the start date. |
|
| 619 | + if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
| 620 | + $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
| 621 | + $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
| 622 | + } |
|
| 623 | + // let's make sure the base price is handled |
|
| 624 | + $ticket = ! $create_new_TKT |
|
| 625 | + ? $this->_add_prices_to_ticket( |
|
| 626 | + array(), |
|
| 627 | + $ticket, |
|
| 628 | + $update_prices, |
|
| 629 | + $base_price, |
|
| 630 | + $base_price_id |
|
| 631 | + ) |
|
| 632 | + : $ticket; |
|
| 633 | + // add/update price_modifiers |
|
| 634 | + $ticket = ! $create_new_TKT |
|
| 635 | + ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) |
|
| 636 | + : $ticket; |
|
| 637 | + // need to make sue that the TKT_price is accurate after saving the prices. |
|
| 638 | + $ticket->ensure_TKT_Price_correct(); |
|
| 639 | + // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
| 640 | + if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
| 641 | + $update_prices = true; |
|
| 642 | + $new_default = clone $ticket; |
|
| 643 | + $new_default->set('TKT_ID', 0); |
|
| 644 | + $new_default->set('TKT_is_default', 1); |
|
| 645 | + $new_default->set('TKT_row', 1); |
|
| 646 | + $new_default->set('TKT_price', $ticket_price); |
|
| 647 | + // remove any dtt relations cause we DON'T want dtt relations attached |
|
| 648 | + // (note this is just removing the cached relations in the object) |
|
| 649 | + $new_default->_remove_relations('Datetime'); |
|
| 650 | + // @todo we need to add the current attached prices as new prices to the new default ticket. |
|
| 651 | + $new_default = $this->_add_prices_to_ticket( |
|
| 652 | + $price_rows, |
|
| 653 | + $new_default, |
|
| 654 | + $update_prices |
|
| 655 | + ); |
|
| 656 | + // don't forget the base price! |
|
| 657 | + $new_default = $this->_add_prices_to_ticket( |
|
| 658 | + array(), |
|
| 659 | + $new_default, |
|
| 660 | + $update_prices, |
|
| 661 | + $base_price, |
|
| 662 | + $base_price_id |
|
| 663 | + ); |
|
| 664 | + $new_default->save(); |
|
| 665 | + do_action( |
|
| 666 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
| 667 | + $new_default, |
|
| 668 | + $row, |
|
| 669 | + $ticket, |
|
| 670 | + $data |
|
| 671 | + ); |
|
| 672 | + } |
|
| 673 | + // DO ALL dtt relationships for both current tickets and any archived tickets |
|
| 674 | + // for the given dtt that are related to the current ticket. |
|
| 675 | + // TODO... not sure exactly how we're going to do this considering we don't know |
|
| 676 | + // what current ticket the archived tickets are related to |
|
| 677 | + // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
| 678 | + // let's assign any tickets that have been setup to the saved_tickets tracker |
|
| 679 | + // save existing TKT |
|
| 680 | + $ticket->save(); |
|
| 681 | + if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
| 682 | + // save new TKT |
|
| 683 | + $new_tkt->save(); |
|
| 684 | + // add new ticket to array |
|
| 685 | + $saved_tickets[ $new_tkt->ID() ] = $new_tkt; |
|
| 686 | + do_action( |
|
| 687 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
| 688 | + $new_tkt, |
|
| 689 | + $row, |
|
| 690 | + $tkt, |
|
| 691 | + $data |
|
| 692 | + ); |
|
| 693 | + } else { |
|
| 694 | + // add tkt to saved tkts |
|
| 695 | + $saved_tickets[ $ticket->ID() ] = $ticket; |
|
| 696 | + do_action( |
|
| 697 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
| 698 | + $ticket, |
|
| 699 | + $row, |
|
| 700 | + $tkt, |
|
| 701 | + $data |
|
| 702 | + ); |
|
| 703 | + } |
|
| 704 | + } |
|
| 705 | + // now we need to handle tickets actually "deleted permanently". |
|
| 706 | + // There are cases where we'd want this to happen |
|
| 707 | + // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
| 708 | + // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
| 709 | + // No sense in keeping all the related data in the db! |
|
| 710 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
| 711 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 712 | + foreach ($tickets_removed as $id) { |
|
| 713 | + $id = absint($id); |
|
| 714 | + // get the ticket for this id |
|
| 715 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 716 | + // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
| 717 | + if ($tkt_to_remove->get('TKT_is_default')) { |
|
| 718 | + continue; |
|
| 719 | + } |
|
| 720 | + // if this tkt has any registrations attached so then we just ARCHIVE |
|
| 721 | + // because we don't actually permanently delete these tickets. |
|
| 722 | + if ($tkt_to_remove->count_related('Registration') > 0) { |
|
| 723 | + $tkt_to_remove->delete(); |
|
| 724 | + continue; |
|
| 725 | + } |
|
| 726 | + // need to get all the related datetimes on this ticket and remove from every single one of them |
|
| 727 | + // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 728 | + $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
| 729 | + foreach ($datetimes as $datetime) { |
|
| 730 | + $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
| 731 | + } |
|
| 732 | + // need to do the same for prices (except these prices can also be deleted because again, |
|
| 733 | + // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 734 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
| 735 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
| 736 | + // finally let's delete this ticket |
|
| 737 | + // (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 738 | + $tkt_to_remove->delete_permanently(); |
|
| 739 | + } |
|
| 740 | + return $saved_tickets; |
|
| 741 | + } |
|
| 742 | 742 | |
| 743 | 743 | |
| 744 | - /** |
|
| 745 | - * @access protected |
|
| 746 | - * @param EE_Ticket $ticket |
|
| 747 | - * @param \EE_Datetime[] $saved_datetimes |
|
| 748 | - * @param \EE_Datetime[] $added_datetimes |
|
| 749 | - * @param \EE_Datetime[] $removed_datetimes |
|
| 750 | - * @return EE_Ticket |
|
| 751 | - * @throws EE_Error |
|
| 752 | - */ |
|
| 753 | - protected function _update_ticket_datetimes( |
|
| 754 | - EE_Ticket $ticket, |
|
| 755 | - $saved_datetimes = array(), |
|
| 756 | - $added_datetimes = array(), |
|
| 757 | - $removed_datetimes = array() |
|
| 758 | - ) { |
|
| 759 | - // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
| 760 | - // and removing the ticket from datetimes it got removed from. |
|
| 761 | - // first let's add datetimes |
|
| 762 | - if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
| 763 | - foreach ($added_datetimes as $row_id) { |
|
| 764 | - $row_id = (int) $row_id; |
|
| 765 | - if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
| 766 | - $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
| 767 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 768 | - // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
| 769 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 770 | - $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false); |
|
| 771 | - } |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - } |
|
| 775 | - // then remove datetimes |
|
| 776 | - if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
| 777 | - foreach ($removed_datetimes as $row_id) { |
|
| 778 | - $row_id = (int) $row_id; |
|
| 779 | - // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
| 780 | - // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
| 781 | - if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
| 782 | - $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
| 783 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 784 | - // If so, then we need to remove it's sold from the DTT_sold. |
|
| 785 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 786 | - $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold()); |
|
| 787 | - } |
|
| 788 | - } |
|
| 789 | - } |
|
| 790 | - } |
|
| 791 | - // cap ticket qty by datetime reg limits |
|
| 792 | - $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
| 793 | - return $ticket; |
|
| 794 | - } |
|
| 744 | + /** |
|
| 745 | + * @access protected |
|
| 746 | + * @param EE_Ticket $ticket |
|
| 747 | + * @param \EE_Datetime[] $saved_datetimes |
|
| 748 | + * @param \EE_Datetime[] $added_datetimes |
|
| 749 | + * @param \EE_Datetime[] $removed_datetimes |
|
| 750 | + * @return EE_Ticket |
|
| 751 | + * @throws EE_Error |
|
| 752 | + */ |
|
| 753 | + protected function _update_ticket_datetimes( |
|
| 754 | + EE_Ticket $ticket, |
|
| 755 | + $saved_datetimes = array(), |
|
| 756 | + $added_datetimes = array(), |
|
| 757 | + $removed_datetimes = array() |
|
| 758 | + ) { |
|
| 759 | + // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
| 760 | + // and removing the ticket from datetimes it got removed from. |
|
| 761 | + // first let's add datetimes |
|
| 762 | + if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
| 763 | + foreach ($added_datetimes as $row_id) { |
|
| 764 | + $row_id = (int) $row_id; |
|
| 765 | + if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
| 766 | + $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
| 767 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 768 | + // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
| 769 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 770 | + $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false); |
|
| 771 | + } |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + } |
|
| 775 | + // then remove datetimes |
|
| 776 | + if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
| 777 | + foreach ($removed_datetimes as $row_id) { |
|
| 778 | + $row_id = (int) $row_id; |
|
| 779 | + // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
| 780 | + // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
| 781 | + if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
| 782 | + $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
| 783 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 784 | + // If so, then we need to remove it's sold from the DTT_sold. |
|
| 785 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 786 | + $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold()); |
|
| 787 | + } |
|
| 788 | + } |
|
| 789 | + } |
|
| 790 | + } |
|
| 791 | + // cap ticket qty by datetime reg limits |
|
| 792 | + $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
| 793 | + return $ticket; |
|
| 794 | + } |
|
| 795 | 795 | |
| 796 | 796 | |
| 797 | - /** |
|
| 798 | - * @access protected |
|
| 799 | - * @param EE_Ticket $ticket |
|
| 800 | - * @param array $price_rows |
|
| 801 | - * @param int $ticket_price |
|
| 802 | - * @param int $base_price |
|
| 803 | - * @param int $base_price_id |
|
| 804 | - * @return EE_Ticket |
|
| 805 | - * @throws ReflectionException |
|
| 806 | - * @throws InvalidArgumentException |
|
| 807 | - * @throws InvalidInterfaceException |
|
| 808 | - * @throws InvalidDataTypeException |
|
| 809 | - * @throws EE_Error |
|
| 810 | - */ |
|
| 811 | - protected function _duplicate_ticket( |
|
| 812 | - EE_Ticket $ticket, |
|
| 813 | - $price_rows = array(), |
|
| 814 | - $ticket_price = 0, |
|
| 815 | - $base_price = 0, |
|
| 816 | - $base_price_id = 0 |
|
| 817 | - ) { |
|
| 818 | - // create new ticket that's a copy of the existing |
|
| 819 | - // except a new id of course (and not archived) |
|
| 820 | - // AND has the new TKT_price associated with it. |
|
| 821 | - $new_ticket = clone $ticket; |
|
| 822 | - $new_ticket->set('TKT_ID', 0); |
|
| 823 | - $new_ticket->set_deleted(0); |
|
| 824 | - $new_ticket->set_price($ticket_price); |
|
| 825 | - $new_ticket->set_sold(0); |
|
| 826 | - // let's get a new ID for this ticket |
|
| 827 | - $new_ticket->save(); |
|
| 828 | - // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
| 829 | - $datetimes_on_existing = $ticket->datetimes(); |
|
| 830 | - $new_ticket = $this->_update_ticket_datetimes( |
|
| 831 | - $new_ticket, |
|
| 832 | - $datetimes_on_existing, |
|
| 833 | - array_keys($datetimes_on_existing) |
|
| 834 | - ); |
|
| 835 | - // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
| 836 | - // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
| 837 | - // available. |
|
| 838 | - if ($ticket->sold() > 0) { |
|
| 839 | - $new_qty = $ticket->qty() - $ticket->sold(); |
|
| 840 | - $new_ticket->set_qty($new_qty); |
|
| 841 | - } |
|
| 842 | - // now we update the prices just for this ticket |
|
| 843 | - $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
| 844 | - // and we update the base price |
|
| 845 | - $new_ticket = $this->_add_prices_to_ticket( |
|
| 846 | - array(), |
|
| 847 | - $new_ticket, |
|
| 848 | - true, |
|
| 849 | - $base_price, |
|
| 850 | - $base_price_id |
|
| 851 | - ); |
|
| 852 | - return $new_ticket; |
|
| 853 | - } |
|
| 797 | + /** |
|
| 798 | + * @access protected |
|
| 799 | + * @param EE_Ticket $ticket |
|
| 800 | + * @param array $price_rows |
|
| 801 | + * @param int $ticket_price |
|
| 802 | + * @param int $base_price |
|
| 803 | + * @param int $base_price_id |
|
| 804 | + * @return EE_Ticket |
|
| 805 | + * @throws ReflectionException |
|
| 806 | + * @throws InvalidArgumentException |
|
| 807 | + * @throws InvalidInterfaceException |
|
| 808 | + * @throws InvalidDataTypeException |
|
| 809 | + * @throws EE_Error |
|
| 810 | + */ |
|
| 811 | + protected function _duplicate_ticket( |
|
| 812 | + EE_Ticket $ticket, |
|
| 813 | + $price_rows = array(), |
|
| 814 | + $ticket_price = 0, |
|
| 815 | + $base_price = 0, |
|
| 816 | + $base_price_id = 0 |
|
| 817 | + ) { |
|
| 818 | + // create new ticket that's a copy of the existing |
|
| 819 | + // except a new id of course (and not archived) |
|
| 820 | + // AND has the new TKT_price associated with it. |
|
| 821 | + $new_ticket = clone $ticket; |
|
| 822 | + $new_ticket->set('TKT_ID', 0); |
|
| 823 | + $new_ticket->set_deleted(0); |
|
| 824 | + $new_ticket->set_price($ticket_price); |
|
| 825 | + $new_ticket->set_sold(0); |
|
| 826 | + // let's get a new ID for this ticket |
|
| 827 | + $new_ticket->save(); |
|
| 828 | + // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
| 829 | + $datetimes_on_existing = $ticket->datetimes(); |
|
| 830 | + $new_ticket = $this->_update_ticket_datetimes( |
|
| 831 | + $new_ticket, |
|
| 832 | + $datetimes_on_existing, |
|
| 833 | + array_keys($datetimes_on_existing) |
|
| 834 | + ); |
|
| 835 | + // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
| 836 | + // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
| 837 | + // available. |
|
| 838 | + if ($ticket->sold() > 0) { |
|
| 839 | + $new_qty = $ticket->qty() - $ticket->sold(); |
|
| 840 | + $new_ticket->set_qty($new_qty); |
|
| 841 | + } |
|
| 842 | + // now we update the prices just for this ticket |
|
| 843 | + $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
| 844 | + // and we update the base price |
|
| 845 | + $new_ticket = $this->_add_prices_to_ticket( |
|
| 846 | + array(), |
|
| 847 | + $new_ticket, |
|
| 848 | + true, |
|
| 849 | + $base_price, |
|
| 850 | + $base_price_id |
|
| 851 | + ); |
|
| 852 | + return $new_ticket; |
|
| 853 | + } |
|
| 854 | 854 | |
| 855 | 855 | |
| 856 | - /** |
|
| 857 | - * This attaches a list of given prices to a ticket. |
|
| 858 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 859 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 860 | - * price info and prices are automatically "archived" via the ticket. |
|
| 861 | - * |
|
| 862 | - * @access private |
|
| 863 | - * @param array $prices Array of prices from the form. |
|
| 864 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 865 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 866 | - * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
| 867 | - * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
| 868 | - * @return EE_Ticket |
|
| 869 | - * @throws ReflectionException |
|
| 870 | - * @throws InvalidArgumentException |
|
| 871 | - * @throws InvalidInterfaceException |
|
| 872 | - * @throws InvalidDataTypeException |
|
| 873 | - * @throws EE_Error |
|
| 874 | - */ |
|
| 875 | - protected function _add_prices_to_ticket( |
|
| 876 | - $prices = array(), |
|
| 877 | - EE_Ticket $ticket, |
|
| 878 | - $new_prices = false, |
|
| 879 | - $base_price = false, |
|
| 880 | - $base_price_id = false |
|
| 881 | - ) { |
|
| 882 | - // let's just get any current prices that may exist on the given ticket |
|
| 883 | - // so we can remove any prices that got trashed in this session. |
|
| 884 | - $current_prices_on_ticket = $base_price !== false |
|
| 885 | - ? $ticket->base_price(true) |
|
| 886 | - : $ticket->price_modifiers(); |
|
| 887 | - $updated_prices = array(); |
|
| 888 | - // if $base_price ! FALSE then updating a base price. |
|
| 889 | - if ($base_price !== false) { |
|
| 890 | - $prices[1] = array( |
|
| 891 | - 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
| 892 | - 'PRT_ID' => 1, |
|
| 893 | - 'PRC_amount' => $base_price, |
|
| 894 | - 'PRC_name' => $ticket->get('TKT_name'), |
|
| 895 | - 'PRC_desc' => $ticket->get('TKT_description'), |
|
| 896 | - ); |
|
| 897 | - } |
|
| 898 | - // possibly need to save tkt |
|
| 899 | - if (! $ticket->ID()) { |
|
| 900 | - $ticket->save(); |
|
| 901 | - } |
|
| 902 | - foreach ($prices as $row => $prc) { |
|
| 903 | - $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
| 904 | - if (empty($prt_id)) { |
|
| 905 | - continue; |
|
| 906 | - } //prices MUST have a price type id. |
|
| 907 | - $PRC_values = array( |
|
| 908 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 909 | - 'PRT_ID' => $prt_id, |
|
| 910 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 911 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 912 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 913 | - 'PRC_is_default' => false, |
|
| 914 | - // make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
| 915 | - 'PRC_order' => $row, |
|
| 916 | - ); |
|
| 917 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 918 | - $PRC_values['PRC_ID'] = 0; |
|
| 919 | - $price = EE_Registry::instance()->load_class( |
|
| 920 | - 'Price', |
|
| 921 | - array($PRC_values), |
|
| 922 | - false, |
|
| 923 | - false |
|
| 924 | - ); |
|
| 925 | - } else { |
|
| 926 | - $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 927 | - // update this price with new values |
|
| 928 | - foreach ($PRC_values as $field => $value) { |
|
| 929 | - $price->set($field, $value); |
|
| 930 | - } |
|
| 931 | - } |
|
| 932 | - $price->save(); |
|
| 933 | - $updated_prices[ $price->ID() ] = $price; |
|
| 934 | - $ticket->_add_relation_to($price, 'Price'); |
|
| 935 | - } |
|
| 936 | - // now let's remove any prices that got removed from the ticket |
|
| 937 | - if (! empty($current_prices_on_ticket)) { |
|
| 938 | - $current = array_keys($current_prices_on_ticket); |
|
| 939 | - $updated = array_keys($updated_prices); |
|
| 940 | - $prices_to_remove = array_diff($current, $updated); |
|
| 941 | - if (! empty($prices_to_remove)) { |
|
| 942 | - foreach ($prices_to_remove as $prc_id) { |
|
| 943 | - $p = $current_prices_on_ticket[ $prc_id ]; |
|
| 944 | - $ticket->_remove_relation_to($p, 'Price'); |
|
| 945 | - // delete permanently the price |
|
| 946 | - $p->delete_permanently(); |
|
| 947 | - } |
|
| 948 | - } |
|
| 949 | - } |
|
| 950 | - return $ticket; |
|
| 951 | - } |
|
| 856 | + /** |
|
| 857 | + * This attaches a list of given prices to a ticket. |
|
| 858 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 859 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 860 | + * price info and prices are automatically "archived" via the ticket. |
|
| 861 | + * |
|
| 862 | + * @access private |
|
| 863 | + * @param array $prices Array of prices from the form. |
|
| 864 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 865 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 866 | + * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
| 867 | + * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
| 868 | + * @return EE_Ticket |
|
| 869 | + * @throws ReflectionException |
|
| 870 | + * @throws InvalidArgumentException |
|
| 871 | + * @throws InvalidInterfaceException |
|
| 872 | + * @throws InvalidDataTypeException |
|
| 873 | + * @throws EE_Error |
|
| 874 | + */ |
|
| 875 | + protected function _add_prices_to_ticket( |
|
| 876 | + $prices = array(), |
|
| 877 | + EE_Ticket $ticket, |
|
| 878 | + $new_prices = false, |
|
| 879 | + $base_price = false, |
|
| 880 | + $base_price_id = false |
|
| 881 | + ) { |
|
| 882 | + // let's just get any current prices that may exist on the given ticket |
|
| 883 | + // so we can remove any prices that got trashed in this session. |
|
| 884 | + $current_prices_on_ticket = $base_price !== false |
|
| 885 | + ? $ticket->base_price(true) |
|
| 886 | + : $ticket->price_modifiers(); |
|
| 887 | + $updated_prices = array(); |
|
| 888 | + // if $base_price ! FALSE then updating a base price. |
|
| 889 | + if ($base_price !== false) { |
|
| 890 | + $prices[1] = array( |
|
| 891 | + 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
| 892 | + 'PRT_ID' => 1, |
|
| 893 | + 'PRC_amount' => $base_price, |
|
| 894 | + 'PRC_name' => $ticket->get('TKT_name'), |
|
| 895 | + 'PRC_desc' => $ticket->get('TKT_description'), |
|
| 896 | + ); |
|
| 897 | + } |
|
| 898 | + // possibly need to save tkt |
|
| 899 | + if (! $ticket->ID()) { |
|
| 900 | + $ticket->save(); |
|
| 901 | + } |
|
| 902 | + foreach ($prices as $row => $prc) { |
|
| 903 | + $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
| 904 | + if (empty($prt_id)) { |
|
| 905 | + continue; |
|
| 906 | + } //prices MUST have a price type id. |
|
| 907 | + $PRC_values = array( |
|
| 908 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 909 | + 'PRT_ID' => $prt_id, |
|
| 910 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 911 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 912 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 913 | + 'PRC_is_default' => false, |
|
| 914 | + // make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
| 915 | + 'PRC_order' => $row, |
|
| 916 | + ); |
|
| 917 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 918 | + $PRC_values['PRC_ID'] = 0; |
|
| 919 | + $price = EE_Registry::instance()->load_class( |
|
| 920 | + 'Price', |
|
| 921 | + array($PRC_values), |
|
| 922 | + false, |
|
| 923 | + false |
|
| 924 | + ); |
|
| 925 | + } else { |
|
| 926 | + $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 927 | + // update this price with new values |
|
| 928 | + foreach ($PRC_values as $field => $value) { |
|
| 929 | + $price->set($field, $value); |
|
| 930 | + } |
|
| 931 | + } |
|
| 932 | + $price->save(); |
|
| 933 | + $updated_prices[ $price->ID() ] = $price; |
|
| 934 | + $ticket->_add_relation_to($price, 'Price'); |
|
| 935 | + } |
|
| 936 | + // now let's remove any prices that got removed from the ticket |
|
| 937 | + if (! empty($current_prices_on_ticket)) { |
|
| 938 | + $current = array_keys($current_prices_on_ticket); |
|
| 939 | + $updated = array_keys($updated_prices); |
|
| 940 | + $prices_to_remove = array_diff($current, $updated); |
|
| 941 | + if (! empty($prices_to_remove)) { |
|
| 942 | + foreach ($prices_to_remove as $prc_id) { |
|
| 943 | + $p = $current_prices_on_ticket[ $prc_id ]; |
|
| 944 | + $ticket->_remove_relation_to($p, 'Price'); |
|
| 945 | + // delete permanently the price |
|
| 946 | + $p->delete_permanently(); |
|
| 947 | + } |
|
| 948 | + } |
|
| 949 | + } |
|
| 950 | + return $ticket; |
|
| 951 | + } |
|
| 952 | 952 | |
| 953 | 953 | |
| 954 | - /** |
|
| 955 | - * @param Events_Admin_Page $event_admin_obj |
|
| 956 | - * @return Events_Admin_Page |
|
| 957 | - */ |
|
| 958 | - public function autosave_handling(Events_Admin_Page $event_admin_obj) |
|
| 959 | - { |
|
| 960 | - return $event_admin_obj; |
|
| 961 | - // doing nothing for the moment. |
|
| 962 | - // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
| 963 | - // (use the set_template_args() method) |
|
| 964 | - /** |
|
| 965 | - * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
| 966 | - * 1. TKT_is_default_selector (visible) |
|
| 967 | - * 2. TKT_is_default (hidden) |
|
| 968 | - * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
| 969 | - * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
| 970 | - * this ticket to be saved as a default. |
|
| 971 | - * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
| 972 | - * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
| 973 | - * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
| 974 | - * the TKT HAS been saved as a default.. |
|
| 975 | - * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
| 976 | - * On Autosave: |
|
| 977 | - * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
| 978 | - * then set the TKT_is_default to false. |
|
| 979 | - * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
| 980 | - * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
| 981 | - * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
| 982 | - */ |
|
| 983 | - } |
|
| 954 | + /** |
|
| 955 | + * @param Events_Admin_Page $event_admin_obj |
|
| 956 | + * @return Events_Admin_Page |
|
| 957 | + */ |
|
| 958 | + public function autosave_handling(Events_Admin_Page $event_admin_obj) |
|
| 959 | + { |
|
| 960 | + return $event_admin_obj; |
|
| 961 | + // doing nothing for the moment. |
|
| 962 | + // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
| 963 | + // (use the set_template_args() method) |
|
| 964 | + /** |
|
| 965 | + * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
| 966 | + * 1. TKT_is_default_selector (visible) |
|
| 967 | + * 2. TKT_is_default (hidden) |
|
| 968 | + * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
| 969 | + * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
| 970 | + * this ticket to be saved as a default. |
|
| 971 | + * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
| 972 | + * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
| 973 | + * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
| 974 | + * the TKT HAS been saved as a default.. |
|
| 975 | + * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
| 976 | + * On Autosave: |
|
| 977 | + * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
| 978 | + * then set the TKT_is_default to false. |
|
| 979 | + * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
| 980 | + * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
| 981 | + * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
| 982 | + */ |
|
| 983 | + } |
|
| 984 | 984 | |
| 985 | 985 | |
| 986 | - /** |
|
| 987 | - * @throws ReflectionException |
|
| 988 | - * @throws InvalidArgumentException |
|
| 989 | - * @throws InvalidInterfaceException |
|
| 990 | - * @throws InvalidDataTypeException |
|
| 991 | - * @throws DomainException |
|
| 992 | - * @throws EE_Error |
|
| 993 | - */ |
|
| 994 | - public function pricing_metabox() |
|
| 995 | - { |
|
| 996 | - $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
| 997 | - $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
| 998 | - // set is_creating_event property. |
|
| 999 | - $EVT_ID = $event->ID(); |
|
| 1000 | - $this->_is_creating_event = empty($this->_req_data['post']); |
|
| 1001 | - // default main template args |
|
| 1002 | - $main_template_args = array( |
|
| 1003 | - 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
| 1004 | - 'event_editor_event_datetimes_help_tab', |
|
| 1005 | - $this->_adminpage_obj->page_slug, |
|
| 1006 | - $this->_adminpage_obj->get_req_action(), |
|
| 1007 | - false, |
|
| 1008 | - false |
|
| 1009 | - ), |
|
| 1010 | - // todo need to add a filter to the template for the help text |
|
| 1011 | - // in the Events_Admin_Page core file so we can add further help |
|
| 1012 | - 'existing_datetime_ids' => '', |
|
| 1013 | - 'total_dtt_rows' => 1, |
|
| 1014 | - 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
| 1015 | - 'add_new_dtt_info', |
|
| 1016 | - $this->_adminpage_obj->page_slug, |
|
| 1017 | - $this->_adminpage_obj->get_req_action(), |
|
| 1018 | - false, |
|
| 1019 | - false |
|
| 1020 | - ), |
|
| 1021 | - // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 1022 | - 'datetime_rows' => '', |
|
| 1023 | - 'show_tickets_container' => '', |
|
| 1024 | - // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
| 1025 | - 'ticket_rows' => '', |
|
| 1026 | - 'existing_ticket_ids' => '', |
|
| 1027 | - 'total_ticket_rows' => 1, |
|
| 1028 | - 'ticket_js_structure' => '', |
|
| 1029 | - 'ee_collapsible_status' => ' ee-collapsible-open' |
|
| 1030 | - // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
| 1031 | - ); |
|
| 1032 | - $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
| 1033 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1034 | - /** |
|
| 1035 | - * 1. Start with retrieving Datetimes |
|
| 1036 | - * 2. For each datetime get related tickets |
|
| 1037 | - * 3. For each ticket get related prices |
|
| 1038 | - */ |
|
| 1039 | - /** @var EEM_Datetime $datetime_model */ |
|
| 1040 | - $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
| 1041 | - $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
| 1042 | - $main_template_args['total_dtt_rows'] = count($datetimes); |
|
| 1043 | - /** |
|
| 1044 | - * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
| 1045 | - * for why we are counting $datetime_row and then setting that on the Datetime object |
|
| 1046 | - */ |
|
| 1047 | - $datetime_row = 1; |
|
| 1048 | - foreach ($datetimes as $datetime) { |
|
| 1049 | - $DTT_ID = $datetime->get('DTT_ID'); |
|
| 1050 | - $datetime->set('DTT_order', $datetime_row); |
|
| 1051 | - $existing_datetime_ids[] = $DTT_ID; |
|
| 1052 | - // tickets attached |
|
| 1053 | - $related_tickets = $datetime->ID() > 0 |
|
| 1054 | - ? $datetime->get_many_related( |
|
| 1055 | - 'Ticket', |
|
| 1056 | - array( |
|
| 1057 | - array( |
|
| 1058 | - 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
| 1059 | - ), |
|
| 1060 | - 'default_where_conditions' => 'none', |
|
| 1061 | - 'order_by' => array('TKT_order' => 'ASC'), |
|
| 1062 | - ) |
|
| 1063 | - ) |
|
| 1064 | - : array(); |
|
| 1065 | - // if there are no related tickets this is likely a new event OR autodraft |
|
| 1066 | - // event so we need to generate the default tickets because datetimes |
|
| 1067 | - // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
| 1068 | - // datetime on the event. |
|
| 1069 | - if (empty($related_tickets) && count($datetimes) < 2) { |
|
| 1070 | - /** @var EEM_Ticket $ticket_model */ |
|
| 1071 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
| 1072 | - $related_tickets = $ticket_model->get_all_default_tickets(); |
|
| 1073 | - // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
| 1074 | - // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
| 1075 | - $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
| 1076 | - $main_default_ticket = reset($related_tickets); |
|
| 1077 | - if ($main_default_ticket instanceof EE_Ticket) { |
|
| 1078 | - foreach ($default_prices as $default_price) { |
|
| 1079 | - if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
| 1080 | - continue; |
|
| 1081 | - } |
|
| 1082 | - $main_default_ticket->cache('Price', $default_price); |
|
| 1083 | - } |
|
| 1084 | - } |
|
| 1085 | - } |
|
| 1086 | - // we can't actually setup rows in this loop yet cause we don't know all |
|
| 1087 | - // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
| 1088 | - // So we're going to temporarily cache some of that information. |
|
| 1089 | - // loop through and setup the ticket rows and make sure the order is set. |
|
| 1090 | - foreach ($related_tickets as $ticket) { |
|
| 1091 | - $TKT_ID = $ticket->get('TKT_ID'); |
|
| 1092 | - $ticket_row = $ticket->get('TKT_row'); |
|
| 1093 | - // we only want unique tickets in our final display!! |
|
| 1094 | - if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
| 1095 | - $existing_ticket_ids[] = $TKT_ID; |
|
| 1096 | - $all_tickets[] = $ticket; |
|
| 1097 | - } |
|
| 1098 | - // temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
| 1099 | - $datetime_tickets[ $DTT_ID ][] = $ticket_row; |
|
| 1100 | - // temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
| 1101 | - if ( |
|
| 1102 | - ! isset($ticket_datetimes[ $TKT_ID ]) |
|
| 1103 | - || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true) |
|
| 1104 | - ) { |
|
| 1105 | - $ticket_datetimes[ $TKT_ID ][] = $datetime_row; |
|
| 1106 | - } |
|
| 1107 | - } |
|
| 1108 | - $datetime_row++; |
|
| 1109 | - } |
|
| 1110 | - $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
| 1111 | - $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1112 | - $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1113 | - // sort $all_tickets by order |
|
| 1114 | - usort( |
|
| 1115 | - $all_tickets, |
|
| 1116 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
| 1117 | - $a_order = (int) $a->get('TKT_order'); |
|
| 1118 | - $b_order = (int) $b->get('TKT_order'); |
|
| 1119 | - if ($a_order === $b_order) { |
|
| 1120 | - return 0; |
|
| 1121 | - } |
|
| 1122 | - return ($a_order < $b_order) ? -1 : 1; |
|
| 1123 | - } |
|
| 1124 | - ); |
|
| 1125 | - // k NOW we have all the data we need for setting up the dtt rows |
|
| 1126 | - // and ticket rows so we start our dtt loop again. |
|
| 1127 | - $datetime_row = 1; |
|
| 1128 | - foreach ($datetimes as $datetime) { |
|
| 1129 | - $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
| 1130 | - $datetime_row, |
|
| 1131 | - $datetime, |
|
| 1132 | - $datetime_tickets, |
|
| 1133 | - $all_tickets, |
|
| 1134 | - false, |
|
| 1135 | - $datetimes |
|
| 1136 | - ); |
|
| 1137 | - $datetime_row++; |
|
| 1138 | - } |
|
| 1139 | - // then loop through all tickets for the ticket rows. |
|
| 1140 | - $ticket_row = 1; |
|
| 1141 | - foreach ($all_tickets as $ticket) { |
|
| 1142 | - $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
| 1143 | - $ticket_row, |
|
| 1144 | - $ticket, |
|
| 1145 | - $ticket_datetimes, |
|
| 1146 | - $datetimes, |
|
| 1147 | - false, |
|
| 1148 | - $all_tickets |
|
| 1149 | - ); |
|
| 1150 | - $ticket_row++; |
|
| 1151 | - } |
|
| 1152 | - $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
| 1153 | - EEH_Template::display_template( |
|
| 1154 | - PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
| 1155 | - $main_template_args |
|
| 1156 | - ); |
|
| 1157 | - } |
|
| 986 | + /** |
|
| 987 | + * @throws ReflectionException |
|
| 988 | + * @throws InvalidArgumentException |
|
| 989 | + * @throws InvalidInterfaceException |
|
| 990 | + * @throws InvalidDataTypeException |
|
| 991 | + * @throws DomainException |
|
| 992 | + * @throws EE_Error |
|
| 993 | + */ |
|
| 994 | + public function pricing_metabox() |
|
| 995 | + { |
|
| 996 | + $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
| 997 | + $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
| 998 | + // set is_creating_event property. |
|
| 999 | + $EVT_ID = $event->ID(); |
|
| 1000 | + $this->_is_creating_event = empty($this->_req_data['post']); |
|
| 1001 | + // default main template args |
|
| 1002 | + $main_template_args = array( |
|
| 1003 | + 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
| 1004 | + 'event_editor_event_datetimes_help_tab', |
|
| 1005 | + $this->_adminpage_obj->page_slug, |
|
| 1006 | + $this->_adminpage_obj->get_req_action(), |
|
| 1007 | + false, |
|
| 1008 | + false |
|
| 1009 | + ), |
|
| 1010 | + // todo need to add a filter to the template for the help text |
|
| 1011 | + // in the Events_Admin_Page core file so we can add further help |
|
| 1012 | + 'existing_datetime_ids' => '', |
|
| 1013 | + 'total_dtt_rows' => 1, |
|
| 1014 | + 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
| 1015 | + 'add_new_dtt_info', |
|
| 1016 | + $this->_adminpage_obj->page_slug, |
|
| 1017 | + $this->_adminpage_obj->get_req_action(), |
|
| 1018 | + false, |
|
| 1019 | + false |
|
| 1020 | + ), |
|
| 1021 | + // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 1022 | + 'datetime_rows' => '', |
|
| 1023 | + 'show_tickets_container' => '', |
|
| 1024 | + // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
| 1025 | + 'ticket_rows' => '', |
|
| 1026 | + 'existing_ticket_ids' => '', |
|
| 1027 | + 'total_ticket_rows' => 1, |
|
| 1028 | + 'ticket_js_structure' => '', |
|
| 1029 | + 'ee_collapsible_status' => ' ee-collapsible-open' |
|
| 1030 | + // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
| 1031 | + ); |
|
| 1032 | + $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
| 1033 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1034 | + /** |
|
| 1035 | + * 1. Start with retrieving Datetimes |
|
| 1036 | + * 2. For each datetime get related tickets |
|
| 1037 | + * 3. For each ticket get related prices |
|
| 1038 | + */ |
|
| 1039 | + /** @var EEM_Datetime $datetime_model */ |
|
| 1040 | + $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
| 1041 | + $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
| 1042 | + $main_template_args['total_dtt_rows'] = count($datetimes); |
|
| 1043 | + /** |
|
| 1044 | + * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
| 1045 | + * for why we are counting $datetime_row and then setting that on the Datetime object |
|
| 1046 | + */ |
|
| 1047 | + $datetime_row = 1; |
|
| 1048 | + foreach ($datetimes as $datetime) { |
|
| 1049 | + $DTT_ID = $datetime->get('DTT_ID'); |
|
| 1050 | + $datetime->set('DTT_order', $datetime_row); |
|
| 1051 | + $existing_datetime_ids[] = $DTT_ID; |
|
| 1052 | + // tickets attached |
|
| 1053 | + $related_tickets = $datetime->ID() > 0 |
|
| 1054 | + ? $datetime->get_many_related( |
|
| 1055 | + 'Ticket', |
|
| 1056 | + array( |
|
| 1057 | + array( |
|
| 1058 | + 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
| 1059 | + ), |
|
| 1060 | + 'default_where_conditions' => 'none', |
|
| 1061 | + 'order_by' => array('TKT_order' => 'ASC'), |
|
| 1062 | + ) |
|
| 1063 | + ) |
|
| 1064 | + : array(); |
|
| 1065 | + // if there are no related tickets this is likely a new event OR autodraft |
|
| 1066 | + // event so we need to generate the default tickets because datetimes |
|
| 1067 | + // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
| 1068 | + // datetime on the event. |
|
| 1069 | + if (empty($related_tickets) && count($datetimes) < 2) { |
|
| 1070 | + /** @var EEM_Ticket $ticket_model */ |
|
| 1071 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
| 1072 | + $related_tickets = $ticket_model->get_all_default_tickets(); |
|
| 1073 | + // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
| 1074 | + // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
| 1075 | + $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
| 1076 | + $main_default_ticket = reset($related_tickets); |
|
| 1077 | + if ($main_default_ticket instanceof EE_Ticket) { |
|
| 1078 | + foreach ($default_prices as $default_price) { |
|
| 1079 | + if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
| 1080 | + continue; |
|
| 1081 | + } |
|
| 1082 | + $main_default_ticket->cache('Price', $default_price); |
|
| 1083 | + } |
|
| 1084 | + } |
|
| 1085 | + } |
|
| 1086 | + // we can't actually setup rows in this loop yet cause we don't know all |
|
| 1087 | + // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
| 1088 | + // So we're going to temporarily cache some of that information. |
|
| 1089 | + // loop through and setup the ticket rows and make sure the order is set. |
|
| 1090 | + foreach ($related_tickets as $ticket) { |
|
| 1091 | + $TKT_ID = $ticket->get('TKT_ID'); |
|
| 1092 | + $ticket_row = $ticket->get('TKT_row'); |
|
| 1093 | + // we only want unique tickets in our final display!! |
|
| 1094 | + if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
| 1095 | + $existing_ticket_ids[] = $TKT_ID; |
|
| 1096 | + $all_tickets[] = $ticket; |
|
| 1097 | + } |
|
| 1098 | + // temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
| 1099 | + $datetime_tickets[ $DTT_ID ][] = $ticket_row; |
|
| 1100 | + // temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
| 1101 | + if ( |
|
| 1102 | + ! isset($ticket_datetimes[ $TKT_ID ]) |
|
| 1103 | + || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true) |
|
| 1104 | + ) { |
|
| 1105 | + $ticket_datetimes[ $TKT_ID ][] = $datetime_row; |
|
| 1106 | + } |
|
| 1107 | + } |
|
| 1108 | + $datetime_row++; |
|
| 1109 | + } |
|
| 1110 | + $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
| 1111 | + $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1112 | + $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1113 | + // sort $all_tickets by order |
|
| 1114 | + usort( |
|
| 1115 | + $all_tickets, |
|
| 1116 | + function (EE_Ticket $a, EE_Ticket $b) { |
|
| 1117 | + $a_order = (int) $a->get('TKT_order'); |
|
| 1118 | + $b_order = (int) $b->get('TKT_order'); |
|
| 1119 | + if ($a_order === $b_order) { |
|
| 1120 | + return 0; |
|
| 1121 | + } |
|
| 1122 | + return ($a_order < $b_order) ? -1 : 1; |
|
| 1123 | + } |
|
| 1124 | + ); |
|
| 1125 | + // k NOW we have all the data we need for setting up the dtt rows |
|
| 1126 | + // and ticket rows so we start our dtt loop again. |
|
| 1127 | + $datetime_row = 1; |
|
| 1128 | + foreach ($datetimes as $datetime) { |
|
| 1129 | + $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
| 1130 | + $datetime_row, |
|
| 1131 | + $datetime, |
|
| 1132 | + $datetime_tickets, |
|
| 1133 | + $all_tickets, |
|
| 1134 | + false, |
|
| 1135 | + $datetimes |
|
| 1136 | + ); |
|
| 1137 | + $datetime_row++; |
|
| 1138 | + } |
|
| 1139 | + // then loop through all tickets for the ticket rows. |
|
| 1140 | + $ticket_row = 1; |
|
| 1141 | + foreach ($all_tickets as $ticket) { |
|
| 1142 | + $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
| 1143 | + $ticket_row, |
|
| 1144 | + $ticket, |
|
| 1145 | + $ticket_datetimes, |
|
| 1146 | + $datetimes, |
|
| 1147 | + false, |
|
| 1148 | + $all_tickets |
|
| 1149 | + ); |
|
| 1150 | + $ticket_row++; |
|
| 1151 | + } |
|
| 1152 | + $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
| 1153 | + EEH_Template::display_template( |
|
| 1154 | + PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
| 1155 | + $main_template_args |
|
| 1156 | + ); |
|
| 1157 | + } |
|
| 1158 | 1158 | |
| 1159 | 1159 | |
| 1160 | - /** |
|
| 1161 | - * @param int $datetime_row |
|
| 1162 | - * @param EE_Datetime $datetime |
|
| 1163 | - * @param array $datetime_tickets |
|
| 1164 | - * @param array $all_tickets |
|
| 1165 | - * @param bool $default |
|
| 1166 | - * @param array $all_datetimes |
|
| 1167 | - * @return mixed |
|
| 1168 | - * @throws DomainException |
|
| 1169 | - * @throws EE_Error |
|
| 1170 | - */ |
|
| 1171 | - protected function _get_datetime_row( |
|
| 1172 | - $datetime_row, |
|
| 1173 | - EE_Datetime $datetime, |
|
| 1174 | - $datetime_tickets = array(), |
|
| 1175 | - $all_tickets = array(), |
|
| 1176 | - $default = false, |
|
| 1177 | - $all_datetimes = array() |
|
| 1178 | - ) { |
|
| 1179 | - $dtt_display_template_args = array( |
|
| 1180 | - 'dtt_edit_row' => $this->_get_dtt_edit_row( |
|
| 1181 | - $datetime_row, |
|
| 1182 | - $datetime, |
|
| 1183 | - $default, |
|
| 1184 | - $all_datetimes |
|
| 1185 | - ), |
|
| 1186 | - 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
| 1187 | - $datetime_row, |
|
| 1188 | - $datetime, |
|
| 1189 | - $datetime_tickets, |
|
| 1190 | - $all_tickets, |
|
| 1191 | - $default |
|
| 1192 | - ), |
|
| 1193 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1194 | - ); |
|
| 1195 | - return EEH_Template::display_template( |
|
| 1196 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
| 1197 | - $dtt_display_template_args, |
|
| 1198 | - true |
|
| 1199 | - ); |
|
| 1200 | - } |
|
| 1160 | + /** |
|
| 1161 | + * @param int $datetime_row |
|
| 1162 | + * @param EE_Datetime $datetime |
|
| 1163 | + * @param array $datetime_tickets |
|
| 1164 | + * @param array $all_tickets |
|
| 1165 | + * @param bool $default |
|
| 1166 | + * @param array $all_datetimes |
|
| 1167 | + * @return mixed |
|
| 1168 | + * @throws DomainException |
|
| 1169 | + * @throws EE_Error |
|
| 1170 | + */ |
|
| 1171 | + protected function _get_datetime_row( |
|
| 1172 | + $datetime_row, |
|
| 1173 | + EE_Datetime $datetime, |
|
| 1174 | + $datetime_tickets = array(), |
|
| 1175 | + $all_tickets = array(), |
|
| 1176 | + $default = false, |
|
| 1177 | + $all_datetimes = array() |
|
| 1178 | + ) { |
|
| 1179 | + $dtt_display_template_args = array( |
|
| 1180 | + 'dtt_edit_row' => $this->_get_dtt_edit_row( |
|
| 1181 | + $datetime_row, |
|
| 1182 | + $datetime, |
|
| 1183 | + $default, |
|
| 1184 | + $all_datetimes |
|
| 1185 | + ), |
|
| 1186 | + 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
| 1187 | + $datetime_row, |
|
| 1188 | + $datetime, |
|
| 1189 | + $datetime_tickets, |
|
| 1190 | + $all_tickets, |
|
| 1191 | + $default |
|
| 1192 | + ), |
|
| 1193 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1194 | + ); |
|
| 1195 | + return EEH_Template::display_template( |
|
| 1196 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
| 1197 | + $dtt_display_template_args, |
|
| 1198 | + true |
|
| 1199 | + ); |
|
| 1200 | + } |
|
| 1201 | 1201 | |
| 1202 | 1202 | |
| 1203 | - /** |
|
| 1204 | - * This method is used to generate a dtt fields edit row. |
|
| 1205 | - * The same row is used to generate a row with valid DTT objects |
|
| 1206 | - * and the default row that is used as the skeleton by the js. |
|
| 1207 | - * |
|
| 1208 | - * @param int $datetime_row The row number for the row being generated. |
|
| 1209 | - * @param EE_Datetime $datetime |
|
| 1210 | - * @param bool $default Whether a default row is being generated or not. |
|
| 1211 | - * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
| 1212 | - * @return string |
|
| 1213 | - * @throws DomainException |
|
| 1214 | - * @throws EE_Error |
|
| 1215 | - */ |
|
| 1216 | - protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
| 1217 | - { |
|
| 1218 | - // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
| 1219 | - $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
| 1220 | - $template_args = array( |
|
| 1221 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1222 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1223 | - 'edit_dtt_expanded' => '', |
|
| 1224 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
| 1225 | - 'DTT_name' => $default ? '' : $datetime->get_f('DTT_name'), |
|
| 1226 | - 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
| 1227 | - 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
| 1228 | - 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
| 1229 | - 'DTT_reg_limit' => $default |
|
| 1230 | - ? '' |
|
| 1231 | - : $datetime->get_pretty( |
|
| 1232 | - 'DTT_reg_limit', |
|
| 1233 | - 'input' |
|
| 1234 | - ), |
|
| 1235 | - 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1236 | - 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
| 1237 | - 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
| 1238 | - 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
| 1239 | - ? '' |
|
| 1240 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
| 1241 | - 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
| 1242 | - ? 'ee-lock-icon' |
|
| 1243 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1244 | - 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
| 1245 | - ? '' |
|
| 1246 | - : EE_Admin_Page::add_query_args_and_nonce( |
|
| 1247 | - array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()), |
|
| 1248 | - REG_ADMIN_URL |
|
| 1249 | - ), |
|
| 1250 | - ); |
|
| 1251 | - $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
| 1252 | - ? ' style="display:none"' |
|
| 1253 | - : ''; |
|
| 1254 | - // allow filtering of template args at this point. |
|
| 1255 | - $template_args = apply_filters( |
|
| 1256 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
| 1257 | - $template_args, |
|
| 1258 | - $datetime_row, |
|
| 1259 | - $datetime, |
|
| 1260 | - $default, |
|
| 1261 | - $all_datetimes, |
|
| 1262 | - $this->_is_creating_event |
|
| 1263 | - ); |
|
| 1264 | - return EEH_Template::display_template( |
|
| 1265 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
| 1266 | - $template_args, |
|
| 1267 | - true |
|
| 1268 | - ); |
|
| 1269 | - } |
|
| 1203 | + /** |
|
| 1204 | + * This method is used to generate a dtt fields edit row. |
|
| 1205 | + * The same row is used to generate a row with valid DTT objects |
|
| 1206 | + * and the default row that is used as the skeleton by the js. |
|
| 1207 | + * |
|
| 1208 | + * @param int $datetime_row The row number for the row being generated. |
|
| 1209 | + * @param EE_Datetime $datetime |
|
| 1210 | + * @param bool $default Whether a default row is being generated or not. |
|
| 1211 | + * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
| 1212 | + * @return string |
|
| 1213 | + * @throws DomainException |
|
| 1214 | + * @throws EE_Error |
|
| 1215 | + */ |
|
| 1216 | + protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
| 1217 | + { |
|
| 1218 | + // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
| 1219 | + $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
| 1220 | + $template_args = array( |
|
| 1221 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1222 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1223 | + 'edit_dtt_expanded' => '', |
|
| 1224 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
| 1225 | + 'DTT_name' => $default ? '' : $datetime->get_f('DTT_name'), |
|
| 1226 | + 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
| 1227 | + 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
| 1228 | + 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
| 1229 | + 'DTT_reg_limit' => $default |
|
| 1230 | + ? '' |
|
| 1231 | + : $datetime->get_pretty( |
|
| 1232 | + 'DTT_reg_limit', |
|
| 1233 | + 'input' |
|
| 1234 | + ), |
|
| 1235 | + 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1236 | + 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
| 1237 | + 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
| 1238 | + 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
| 1239 | + ? '' |
|
| 1240 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
| 1241 | + 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
| 1242 | + ? 'ee-lock-icon' |
|
| 1243 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1244 | + 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
| 1245 | + ? '' |
|
| 1246 | + : EE_Admin_Page::add_query_args_and_nonce( |
|
| 1247 | + array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()), |
|
| 1248 | + REG_ADMIN_URL |
|
| 1249 | + ), |
|
| 1250 | + ); |
|
| 1251 | + $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
| 1252 | + ? ' style="display:none"' |
|
| 1253 | + : ''; |
|
| 1254 | + // allow filtering of template args at this point. |
|
| 1255 | + $template_args = apply_filters( |
|
| 1256 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
| 1257 | + $template_args, |
|
| 1258 | + $datetime_row, |
|
| 1259 | + $datetime, |
|
| 1260 | + $default, |
|
| 1261 | + $all_datetimes, |
|
| 1262 | + $this->_is_creating_event |
|
| 1263 | + ); |
|
| 1264 | + return EEH_Template::display_template( |
|
| 1265 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
| 1266 | + $template_args, |
|
| 1267 | + true |
|
| 1268 | + ); |
|
| 1269 | + } |
|
| 1270 | 1270 | |
| 1271 | 1271 | |
| 1272 | - /** |
|
| 1273 | - * @param int $datetime_row |
|
| 1274 | - * @param EE_Datetime $datetime |
|
| 1275 | - * @param array $datetime_tickets |
|
| 1276 | - * @param array $all_tickets |
|
| 1277 | - * @param bool $default |
|
| 1278 | - * @return mixed |
|
| 1279 | - * @throws DomainException |
|
| 1280 | - * @throws EE_Error |
|
| 1281 | - */ |
|
| 1282 | - protected function _get_dtt_attached_tickets_row( |
|
| 1283 | - $datetime_row, |
|
| 1284 | - $datetime, |
|
| 1285 | - $datetime_tickets = array(), |
|
| 1286 | - $all_tickets = array(), |
|
| 1287 | - $default |
|
| 1288 | - ) { |
|
| 1289 | - $template_args = array( |
|
| 1290 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1291 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1292 | - 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
| 1293 | - 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1294 | - 'show_tickets_row' => ' style="display:none;"', |
|
| 1295 | - 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
| 1296 | - 'add_new_ticket_via_datetime', |
|
| 1297 | - $this->_adminpage_obj->page_slug, |
|
| 1298 | - $this->_adminpage_obj->get_req_action(), |
|
| 1299 | - false, |
|
| 1300 | - false |
|
| 1301 | - ), |
|
| 1302 | - // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 1303 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
| 1304 | - ); |
|
| 1305 | - // need to setup the list items (but only if this isn't a default skeleton setup) |
|
| 1306 | - if (! $default) { |
|
| 1307 | - $ticket_row = 1; |
|
| 1308 | - foreach ($all_tickets as $ticket) { |
|
| 1309 | - $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
| 1310 | - $datetime_row, |
|
| 1311 | - $ticket_row, |
|
| 1312 | - $datetime, |
|
| 1313 | - $ticket, |
|
| 1314 | - $datetime_tickets, |
|
| 1315 | - $default |
|
| 1316 | - ); |
|
| 1317 | - $ticket_row++; |
|
| 1318 | - } |
|
| 1319 | - } |
|
| 1320 | - // filter template args at this point |
|
| 1321 | - $template_args = apply_filters( |
|
| 1322 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
| 1323 | - $template_args, |
|
| 1324 | - $datetime_row, |
|
| 1325 | - $datetime, |
|
| 1326 | - $datetime_tickets, |
|
| 1327 | - $all_tickets, |
|
| 1328 | - $default, |
|
| 1329 | - $this->_is_creating_event |
|
| 1330 | - ); |
|
| 1331 | - return EEH_Template::display_template( |
|
| 1332 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
| 1333 | - $template_args, |
|
| 1334 | - true |
|
| 1335 | - ); |
|
| 1336 | - } |
|
| 1272 | + /** |
|
| 1273 | + * @param int $datetime_row |
|
| 1274 | + * @param EE_Datetime $datetime |
|
| 1275 | + * @param array $datetime_tickets |
|
| 1276 | + * @param array $all_tickets |
|
| 1277 | + * @param bool $default |
|
| 1278 | + * @return mixed |
|
| 1279 | + * @throws DomainException |
|
| 1280 | + * @throws EE_Error |
|
| 1281 | + */ |
|
| 1282 | + protected function _get_dtt_attached_tickets_row( |
|
| 1283 | + $datetime_row, |
|
| 1284 | + $datetime, |
|
| 1285 | + $datetime_tickets = array(), |
|
| 1286 | + $all_tickets = array(), |
|
| 1287 | + $default |
|
| 1288 | + ) { |
|
| 1289 | + $template_args = array( |
|
| 1290 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1291 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1292 | + 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
| 1293 | + 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1294 | + 'show_tickets_row' => ' style="display:none;"', |
|
| 1295 | + 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
| 1296 | + 'add_new_ticket_via_datetime', |
|
| 1297 | + $this->_adminpage_obj->page_slug, |
|
| 1298 | + $this->_adminpage_obj->get_req_action(), |
|
| 1299 | + false, |
|
| 1300 | + false |
|
| 1301 | + ), |
|
| 1302 | + // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 1303 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
| 1304 | + ); |
|
| 1305 | + // need to setup the list items (but only if this isn't a default skeleton setup) |
|
| 1306 | + if (! $default) { |
|
| 1307 | + $ticket_row = 1; |
|
| 1308 | + foreach ($all_tickets as $ticket) { |
|
| 1309 | + $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
| 1310 | + $datetime_row, |
|
| 1311 | + $ticket_row, |
|
| 1312 | + $datetime, |
|
| 1313 | + $ticket, |
|
| 1314 | + $datetime_tickets, |
|
| 1315 | + $default |
|
| 1316 | + ); |
|
| 1317 | + $ticket_row++; |
|
| 1318 | + } |
|
| 1319 | + } |
|
| 1320 | + // filter template args at this point |
|
| 1321 | + $template_args = apply_filters( |
|
| 1322 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
| 1323 | + $template_args, |
|
| 1324 | + $datetime_row, |
|
| 1325 | + $datetime, |
|
| 1326 | + $datetime_tickets, |
|
| 1327 | + $all_tickets, |
|
| 1328 | + $default, |
|
| 1329 | + $this->_is_creating_event |
|
| 1330 | + ); |
|
| 1331 | + return EEH_Template::display_template( |
|
| 1332 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
| 1333 | + $template_args, |
|
| 1334 | + true |
|
| 1335 | + ); |
|
| 1336 | + } |
|
| 1337 | 1337 | |
| 1338 | 1338 | |
| 1339 | - /** |
|
| 1340 | - * @param int $datetime_row |
|
| 1341 | - * @param int $ticket_row |
|
| 1342 | - * @param EE_Datetime $datetime |
|
| 1343 | - * @param EE_Ticket $ticket |
|
| 1344 | - * @param array $datetime_tickets |
|
| 1345 | - * @param bool $default |
|
| 1346 | - * @return mixed |
|
| 1347 | - * @throws DomainException |
|
| 1348 | - * @throws EE_Error |
|
| 1349 | - */ |
|
| 1350 | - protected function _get_datetime_tickets_list_item( |
|
| 1351 | - $datetime_row, |
|
| 1352 | - $ticket_row, |
|
| 1353 | - $datetime, |
|
| 1354 | - $ticket, |
|
| 1355 | - $datetime_tickets = array(), |
|
| 1356 | - $default |
|
| 1357 | - ) { |
|
| 1358 | - $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ]) |
|
| 1359 | - ? $datetime_tickets[ $datetime->ID() ] |
|
| 1360 | - : array(); |
|
| 1361 | - $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
| 1362 | - $no_ticket = $default && empty($ticket); |
|
| 1363 | - $template_args = array( |
|
| 1364 | - 'dtt_row' => $default |
|
| 1365 | - ? 'DTTNUM' |
|
| 1366 | - : $datetime_row, |
|
| 1367 | - 'tkt_row' => $no_ticket |
|
| 1368 | - ? 'TICKETNUM' |
|
| 1369 | - : $ticket_row, |
|
| 1370 | - 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
| 1371 | - ? ' checked="checked"' |
|
| 1372 | - : '', |
|
| 1373 | - 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
| 1374 | - ? ' ticket-selected' |
|
| 1375 | - : '', |
|
| 1376 | - 'TKT_name' => $no_ticket |
|
| 1377 | - ? 'TKTNAME' |
|
| 1378 | - : $ticket->get('TKT_name'), |
|
| 1379 | - 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
| 1380 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1381 | - : ' tkt-status-' . $ticket->ticket_status(), |
|
| 1382 | - ); |
|
| 1383 | - // filter template args |
|
| 1384 | - $template_args = apply_filters( |
|
| 1385 | - 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
| 1386 | - $template_args, |
|
| 1387 | - $datetime_row, |
|
| 1388 | - $ticket_row, |
|
| 1389 | - $datetime, |
|
| 1390 | - $ticket, |
|
| 1391 | - $datetime_tickets, |
|
| 1392 | - $default, |
|
| 1393 | - $this->_is_creating_event |
|
| 1394 | - ); |
|
| 1395 | - return EEH_Template::display_template( |
|
| 1396 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
| 1397 | - $template_args, |
|
| 1398 | - true |
|
| 1399 | - ); |
|
| 1400 | - } |
|
| 1339 | + /** |
|
| 1340 | + * @param int $datetime_row |
|
| 1341 | + * @param int $ticket_row |
|
| 1342 | + * @param EE_Datetime $datetime |
|
| 1343 | + * @param EE_Ticket $ticket |
|
| 1344 | + * @param array $datetime_tickets |
|
| 1345 | + * @param bool $default |
|
| 1346 | + * @return mixed |
|
| 1347 | + * @throws DomainException |
|
| 1348 | + * @throws EE_Error |
|
| 1349 | + */ |
|
| 1350 | + protected function _get_datetime_tickets_list_item( |
|
| 1351 | + $datetime_row, |
|
| 1352 | + $ticket_row, |
|
| 1353 | + $datetime, |
|
| 1354 | + $ticket, |
|
| 1355 | + $datetime_tickets = array(), |
|
| 1356 | + $default |
|
| 1357 | + ) { |
|
| 1358 | + $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ]) |
|
| 1359 | + ? $datetime_tickets[ $datetime->ID() ] |
|
| 1360 | + : array(); |
|
| 1361 | + $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
| 1362 | + $no_ticket = $default && empty($ticket); |
|
| 1363 | + $template_args = array( |
|
| 1364 | + 'dtt_row' => $default |
|
| 1365 | + ? 'DTTNUM' |
|
| 1366 | + : $datetime_row, |
|
| 1367 | + 'tkt_row' => $no_ticket |
|
| 1368 | + ? 'TICKETNUM' |
|
| 1369 | + : $ticket_row, |
|
| 1370 | + 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
| 1371 | + ? ' checked="checked"' |
|
| 1372 | + : '', |
|
| 1373 | + 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
| 1374 | + ? ' ticket-selected' |
|
| 1375 | + : '', |
|
| 1376 | + 'TKT_name' => $no_ticket |
|
| 1377 | + ? 'TKTNAME' |
|
| 1378 | + : $ticket->get('TKT_name'), |
|
| 1379 | + 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
| 1380 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1381 | + : ' tkt-status-' . $ticket->ticket_status(), |
|
| 1382 | + ); |
|
| 1383 | + // filter template args |
|
| 1384 | + $template_args = apply_filters( |
|
| 1385 | + 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
| 1386 | + $template_args, |
|
| 1387 | + $datetime_row, |
|
| 1388 | + $ticket_row, |
|
| 1389 | + $datetime, |
|
| 1390 | + $ticket, |
|
| 1391 | + $datetime_tickets, |
|
| 1392 | + $default, |
|
| 1393 | + $this->_is_creating_event |
|
| 1394 | + ); |
|
| 1395 | + return EEH_Template::display_template( |
|
| 1396 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
| 1397 | + $template_args, |
|
| 1398 | + true |
|
| 1399 | + ); |
|
| 1400 | + } |
|
| 1401 | 1401 | |
| 1402 | 1402 | |
| 1403 | - /** |
|
| 1404 | - * This generates the ticket row for tickets. |
|
| 1405 | - * This same method is used to generate both the actual rows and the js skeleton row |
|
| 1406 | - * (when default === true) |
|
| 1407 | - * |
|
| 1408 | - * @param int $ticket_row Represents the row number being generated. |
|
| 1409 | - * @param $ticket |
|
| 1410 | - * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
| 1411 | - * or empty for default |
|
| 1412 | - * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
| 1413 | - * @param bool $default Whether default row being generated or not. |
|
| 1414 | - * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
| 1415 | - * (or empty in the case of defaults) |
|
| 1416 | - * @return mixed |
|
| 1417 | - * @throws InvalidArgumentException |
|
| 1418 | - * @throws InvalidInterfaceException |
|
| 1419 | - * @throws InvalidDataTypeException |
|
| 1420 | - * @throws DomainException |
|
| 1421 | - * @throws EE_Error |
|
| 1422 | - * @throws ReflectionException |
|
| 1423 | - */ |
|
| 1424 | - protected function _get_ticket_row( |
|
| 1425 | - $ticket_row, |
|
| 1426 | - $ticket, |
|
| 1427 | - $ticket_datetimes, |
|
| 1428 | - $all_datetimes, |
|
| 1429 | - $default = false, |
|
| 1430 | - $all_tickets = array() |
|
| 1431 | - ) { |
|
| 1432 | - // if $ticket is not an instance of EE_Ticket then force default to true. |
|
| 1433 | - $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
| 1434 | - $prices = ! empty($ticket) && ! $default |
|
| 1435 | - ? $ticket->get_many_related( |
|
| 1436 | - 'Price', |
|
| 1437 | - array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC')) |
|
| 1438 | - ) |
|
| 1439 | - : array(); |
|
| 1440 | - // if there is only one price (which would be the base price) |
|
| 1441 | - // or NO prices and this ticket is a default ticket, |
|
| 1442 | - // let's just make sure there are no cached default prices on the object. |
|
| 1443 | - // This is done by not including any query_params. |
|
| 1444 | - if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
| 1445 | - $prices = $ticket->prices(); |
|
| 1446 | - } |
|
| 1447 | - // check if we're dealing with a default ticket in which case |
|
| 1448 | - // we don't want any starting_ticket_datetime_row values set |
|
| 1449 | - // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
| 1450 | - // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
| 1451 | - $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default()); |
|
| 1452 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
| 1453 | - ? $ticket_datetimes[ $ticket->ID() ] |
|
| 1454 | - : array(); |
|
| 1455 | - $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1456 | - $base_price = $default ? null : $ticket->base_price(); |
|
| 1457 | - $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
| 1458 | - // breaking out complicated condition for ticket_status |
|
| 1459 | - if ($default) { |
|
| 1460 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1461 | - } else { |
|
| 1462 | - $ticket_status_class = $ticket->is_default() |
|
| 1463 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1464 | - : ' tkt-status-' . $ticket->ticket_status(); |
|
| 1465 | - } |
|
| 1466 | - // breaking out complicated condition for TKT_taxable |
|
| 1467 | - if ($default) { |
|
| 1468 | - $TKT_taxable = ''; |
|
| 1469 | - } else { |
|
| 1470 | - $TKT_taxable = $ticket->taxable() |
|
| 1471 | - ? ' checked="checked"' |
|
| 1472 | - : ''; |
|
| 1473 | - } |
|
| 1474 | - if ($default) { |
|
| 1475 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
| 1476 | - } elseif ($ticket->is_default()) { |
|
| 1477 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
| 1478 | - } else { |
|
| 1479 | - $TKT_status = $ticket->ticket_status(true); |
|
| 1480 | - } |
|
| 1481 | - if ($default) { |
|
| 1482 | - $TKT_min = ''; |
|
| 1483 | - } else { |
|
| 1484 | - $TKT_min = $ticket->min(); |
|
| 1485 | - if ($TKT_min === -1 || $TKT_min === 0) { |
|
| 1486 | - $TKT_min = ''; |
|
| 1487 | - } |
|
| 1488 | - } |
|
| 1489 | - $template_args = array( |
|
| 1490 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1491 | - 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1492 | - // on initial page load this will always be the correct order. |
|
| 1493 | - 'tkt_status_class' => $ticket_status_class, |
|
| 1494 | - 'display_edit_tkt_row' => ' style="display:none;"', |
|
| 1495 | - 'edit_tkt_expanded' => '', |
|
| 1496 | - 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1497 | - 'TKT_name' => $default ? '' : $ticket->get_f('TKT_name'), |
|
| 1498 | - 'TKT_start_date' => $default |
|
| 1499 | - ? '' |
|
| 1500 | - : $ticket->get_date('TKT_start_date', $this->_date_time_format), |
|
| 1501 | - 'TKT_end_date' => $default |
|
| 1502 | - ? '' |
|
| 1503 | - : $ticket->get_date('TKT_end_date', $this->_date_time_format), |
|
| 1504 | - 'TKT_status' => $TKT_status, |
|
| 1505 | - 'TKT_price' => $default |
|
| 1506 | - ? '' |
|
| 1507 | - : EEH_Template::format_currency( |
|
| 1508 | - $ticket->get_ticket_total_with_taxes(), |
|
| 1509 | - false, |
|
| 1510 | - false |
|
| 1511 | - ), |
|
| 1512 | - 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
| 1513 | - 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
| 1514 | - 'TKT_qty' => $default |
|
| 1515 | - ? '' |
|
| 1516 | - : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
| 1517 | - 'TKT_qty_for_input' => $default |
|
| 1518 | - ? '' |
|
| 1519 | - : $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1520 | - 'TKT_uses' => $default |
|
| 1521 | - ? '' |
|
| 1522 | - : $ticket->get_pretty('TKT_uses', 'input'), |
|
| 1523 | - 'TKT_min' => $TKT_min, |
|
| 1524 | - 'TKT_max' => $default |
|
| 1525 | - ? '' |
|
| 1526 | - : $ticket->get_pretty('TKT_max', 'input'), |
|
| 1527 | - 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
| 1528 | - 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
| 1529 | - 'TKT_registrations' => $default |
|
| 1530 | - ? 0 |
|
| 1531 | - : $ticket->count_registrations( |
|
| 1532 | - array( |
|
| 1533 | - array( |
|
| 1534 | - 'STS_ID' => array( |
|
| 1535 | - '!=', |
|
| 1536 | - EEM_Registration::status_id_incomplete, |
|
| 1537 | - ), |
|
| 1538 | - ), |
|
| 1539 | - ) |
|
| 1540 | - ), |
|
| 1541 | - 'TKT_ID' => $default ? 0 : $ticket->ID(), |
|
| 1542 | - 'TKT_description' => $default ? '' : $ticket->get_f('TKT_description'), |
|
| 1543 | - 'TKT_is_default' => $default ? 0 : $ticket->is_default(), |
|
| 1544 | - 'TKT_required' => $default ? 0 : $ticket->required(), |
|
| 1545 | - 'TKT_is_default_selector' => '', |
|
| 1546 | - 'ticket_price_rows' => '', |
|
| 1547 | - 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
| 1548 | - ? '' |
|
| 1549 | - : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
| 1550 | - 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
| 1551 | - 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
| 1552 | - ? '' |
|
| 1553 | - : ' style="display:none;"', |
|
| 1554 | - 'show_price_mod_button' => count($prices) > 1 |
|
| 1555 | - || ($default && $count_price_mods > 0) |
|
| 1556 | - || (! $default && $ticket->deleted()) |
|
| 1557 | - ? ' style="display:none;"' |
|
| 1558 | - : '', |
|
| 1559 | - 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
| 1560 | - 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1561 | - 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
| 1562 | - 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
| 1563 | - 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
| 1564 | - 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
| 1565 | - 'TKT_taxable' => $TKT_taxable, |
|
| 1566 | - 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->taxable() |
|
| 1567 | - ? '' |
|
| 1568 | - : ' style="display:none"', |
|
| 1569 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1570 | - 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
| 1571 | - $ticket_subtotal, |
|
| 1572 | - false, |
|
| 1573 | - false |
|
| 1574 | - ), |
|
| 1575 | - 'TKT_subtotal_amount' => $ticket_subtotal, |
|
| 1576 | - 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
| 1577 | - 'disabled' => $ticket instanceof EE_Ticket && $ticket->deleted(), |
|
| 1578 | - 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
| 1579 | - ? ' ticket-archived' |
|
| 1580 | - : '', |
|
| 1581 | - 'trash_icon' => $ticket instanceof EE_Ticket |
|
| 1582 | - && $ticket->deleted() |
|
| 1583 | - && ! $ticket->is_permanently_deleteable() |
|
| 1584 | - ? 'ee-lock-icon ' |
|
| 1585 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1586 | - 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
| 1587 | - ? '' |
|
| 1588 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
| 1589 | - ); |
|
| 1590 | - $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
| 1591 | - ? ' style="display:none"' |
|
| 1592 | - : ''; |
|
| 1593 | - // handle rows that should NOT be empty |
|
| 1594 | - if (empty($template_args['TKT_start_date'])) { |
|
| 1595 | - // if empty then the start date will be now. |
|
| 1596 | - $template_args['TKT_start_date'] = date( |
|
| 1597 | - $this->_date_time_format, |
|
| 1598 | - current_time('timestamp') |
|
| 1599 | - ); |
|
| 1600 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1601 | - } |
|
| 1602 | - if (empty($template_args['TKT_end_date'])) { |
|
| 1603 | - // get the earliest datetime (if present); |
|
| 1604 | - $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
| 1605 | - ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
| 1606 | - 'Datetime', |
|
| 1607 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1608 | - ) |
|
| 1609 | - : null; |
|
| 1610 | - if (! empty($earliest_dtt)) { |
|
| 1611 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
| 1612 | - 'DTT_EVT_start', |
|
| 1613 | - $this->_date_time_format |
|
| 1614 | - ); |
|
| 1615 | - } else { |
|
| 1616 | - // default so let's just use what's been set for the default date-time which is 30 days from now. |
|
| 1617 | - $template_args['TKT_end_date'] = date( |
|
| 1618 | - $this->_date_time_format, |
|
| 1619 | - mktime( |
|
| 1620 | - 24, |
|
| 1621 | - 0, |
|
| 1622 | - 0, |
|
| 1623 | - date('m'), |
|
| 1624 | - date('d') + 29, |
|
| 1625 | - date('Y') |
|
| 1626 | - ) |
|
| 1627 | - ); |
|
| 1628 | - } |
|
| 1629 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1630 | - } |
|
| 1631 | - // generate ticket_datetime items |
|
| 1632 | - if (! $default) { |
|
| 1633 | - $datetime_row = 1; |
|
| 1634 | - foreach ($all_datetimes as $datetime) { |
|
| 1635 | - $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
| 1636 | - $datetime_row, |
|
| 1637 | - $ticket_row, |
|
| 1638 | - $datetime, |
|
| 1639 | - $ticket, |
|
| 1640 | - $ticket_datetimes, |
|
| 1641 | - $default |
|
| 1642 | - ); |
|
| 1643 | - $datetime_row++; |
|
| 1644 | - } |
|
| 1645 | - } |
|
| 1646 | - $price_row = 0; |
|
| 1647 | - foreach ($prices as $price) { |
|
| 1648 | - if (! $price instanceof EE_Price) { |
|
| 1649 | - continue; |
|
| 1650 | - } |
|
| 1651 | - if ($price->is_base_price()) { |
|
| 1652 | - $price_row++; |
|
| 1653 | - continue; |
|
| 1654 | - } |
|
| 1655 | - $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
| 1656 | - $ticket_row, |
|
| 1657 | - $price_row, |
|
| 1658 | - $price, |
|
| 1659 | - $default, |
|
| 1660 | - $ticket, |
|
| 1661 | - // base prices are never displayed, so always show the trash button |
|
| 1662 | - true, |
|
| 1663 | - // show the add button on the last row only... |
|
| 1664 | - // modifier count starts at 1, but the base price is still in the prices array, |
|
| 1665 | - // so if we have two modifiers, then the last one is 2 but there are 3 prices, |
|
| 1666 | - // so the following would work out to: 2 === 3 -1 |
|
| 1667 | - $price_row === (count($prices) - 1) |
|
| 1668 | - ); |
|
| 1669 | - $price_row++; |
|
| 1670 | - } |
|
| 1671 | - // filter $template_args |
|
| 1672 | - $template_args = apply_filters( |
|
| 1673 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
| 1674 | - $template_args, |
|
| 1675 | - $ticket_row, |
|
| 1676 | - $ticket, |
|
| 1677 | - $ticket_datetimes, |
|
| 1678 | - $all_datetimes, |
|
| 1679 | - $default, |
|
| 1680 | - $all_tickets, |
|
| 1681 | - $this->_is_creating_event |
|
| 1682 | - ); |
|
| 1683 | - return EEH_Template::display_template( |
|
| 1684 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
| 1685 | - $template_args, |
|
| 1686 | - true |
|
| 1687 | - ); |
|
| 1688 | - } |
|
| 1403 | + /** |
|
| 1404 | + * This generates the ticket row for tickets. |
|
| 1405 | + * This same method is used to generate both the actual rows and the js skeleton row |
|
| 1406 | + * (when default === true) |
|
| 1407 | + * |
|
| 1408 | + * @param int $ticket_row Represents the row number being generated. |
|
| 1409 | + * @param $ticket |
|
| 1410 | + * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
| 1411 | + * or empty for default |
|
| 1412 | + * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
| 1413 | + * @param bool $default Whether default row being generated or not. |
|
| 1414 | + * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
| 1415 | + * (or empty in the case of defaults) |
|
| 1416 | + * @return mixed |
|
| 1417 | + * @throws InvalidArgumentException |
|
| 1418 | + * @throws InvalidInterfaceException |
|
| 1419 | + * @throws InvalidDataTypeException |
|
| 1420 | + * @throws DomainException |
|
| 1421 | + * @throws EE_Error |
|
| 1422 | + * @throws ReflectionException |
|
| 1423 | + */ |
|
| 1424 | + protected function _get_ticket_row( |
|
| 1425 | + $ticket_row, |
|
| 1426 | + $ticket, |
|
| 1427 | + $ticket_datetimes, |
|
| 1428 | + $all_datetimes, |
|
| 1429 | + $default = false, |
|
| 1430 | + $all_tickets = array() |
|
| 1431 | + ) { |
|
| 1432 | + // if $ticket is not an instance of EE_Ticket then force default to true. |
|
| 1433 | + $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
| 1434 | + $prices = ! empty($ticket) && ! $default |
|
| 1435 | + ? $ticket->get_many_related( |
|
| 1436 | + 'Price', |
|
| 1437 | + array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC')) |
|
| 1438 | + ) |
|
| 1439 | + : array(); |
|
| 1440 | + // if there is only one price (which would be the base price) |
|
| 1441 | + // or NO prices and this ticket is a default ticket, |
|
| 1442 | + // let's just make sure there are no cached default prices on the object. |
|
| 1443 | + // This is done by not including any query_params. |
|
| 1444 | + if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
| 1445 | + $prices = $ticket->prices(); |
|
| 1446 | + } |
|
| 1447 | + // check if we're dealing with a default ticket in which case |
|
| 1448 | + // we don't want any starting_ticket_datetime_row values set |
|
| 1449 | + // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
| 1450 | + // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
| 1451 | + $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default()); |
|
| 1452 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
| 1453 | + ? $ticket_datetimes[ $ticket->ID() ] |
|
| 1454 | + : array(); |
|
| 1455 | + $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1456 | + $base_price = $default ? null : $ticket->base_price(); |
|
| 1457 | + $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
| 1458 | + // breaking out complicated condition for ticket_status |
|
| 1459 | + if ($default) { |
|
| 1460 | + $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1461 | + } else { |
|
| 1462 | + $ticket_status_class = $ticket->is_default() |
|
| 1463 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1464 | + : ' tkt-status-' . $ticket->ticket_status(); |
|
| 1465 | + } |
|
| 1466 | + // breaking out complicated condition for TKT_taxable |
|
| 1467 | + if ($default) { |
|
| 1468 | + $TKT_taxable = ''; |
|
| 1469 | + } else { |
|
| 1470 | + $TKT_taxable = $ticket->taxable() |
|
| 1471 | + ? ' checked="checked"' |
|
| 1472 | + : ''; |
|
| 1473 | + } |
|
| 1474 | + if ($default) { |
|
| 1475 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
| 1476 | + } elseif ($ticket->is_default()) { |
|
| 1477 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
| 1478 | + } else { |
|
| 1479 | + $TKT_status = $ticket->ticket_status(true); |
|
| 1480 | + } |
|
| 1481 | + if ($default) { |
|
| 1482 | + $TKT_min = ''; |
|
| 1483 | + } else { |
|
| 1484 | + $TKT_min = $ticket->min(); |
|
| 1485 | + if ($TKT_min === -1 || $TKT_min === 0) { |
|
| 1486 | + $TKT_min = ''; |
|
| 1487 | + } |
|
| 1488 | + } |
|
| 1489 | + $template_args = array( |
|
| 1490 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1491 | + 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1492 | + // on initial page load this will always be the correct order. |
|
| 1493 | + 'tkt_status_class' => $ticket_status_class, |
|
| 1494 | + 'display_edit_tkt_row' => ' style="display:none;"', |
|
| 1495 | + 'edit_tkt_expanded' => '', |
|
| 1496 | + 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1497 | + 'TKT_name' => $default ? '' : $ticket->get_f('TKT_name'), |
|
| 1498 | + 'TKT_start_date' => $default |
|
| 1499 | + ? '' |
|
| 1500 | + : $ticket->get_date('TKT_start_date', $this->_date_time_format), |
|
| 1501 | + 'TKT_end_date' => $default |
|
| 1502 | + ? '' |
|
| 1503 | + : $ticket->get_date('TKT_end_date', $this->_date_time_format), |
|
| 1504 | + 'TKT_status' => $TKT_status, |
|
| 1505 | + 'TKT_price' => $default |
|
| 1506 | + ? '' |
|
| 1507 | + : EEH_Template::format_currency( |
|
| 1508 | + $ticket->get_ticket_total_with_taxes(), |
|
| 1509 | + false, |
|
| 1510 | + false |
|
| 1511 | + ), |
|
| 1512 | + 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
| 1513 | + 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
| 1514 | + 'TKT_qty' => $default |
|
| 1515 | + ? '' |
|
| 1516 | + : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
| 1517 | + 'TKT_qty_for_input' => $default |
|
| 1518 | + ? '' |
|
| 1519 | + : $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1520 | + 'TKT_uses' => $default |
|
| 1521 | + ? '' |
|
| 1522 | + : $ticket->get_pretty('TKT_uses', 'input'), |
|
| 1523 | + 'TKT_min' => $TKT_min, |
|
| 1524 | + 'TKT_max' => $default |
|
| 1525 | + ? '' |
|
| 1526 | + : $ticket->get_pretty('TKT_max', 'input'), |
|
| 1527 | + 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
| 1528 | + 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
| 1529 | + 'TKT_registrations' => $default |
|
| 1530 | + ? 0 |
|
| 1531 | + : $ticket->count_registrations( |
|
| 1532 | + array( |
|
| 1533 | + array( |
|
| 1534 | + 'STS_ID' => array( |
|
| 1535 | + '!=', |
|
| 1536 | + EEM_Registration::status_id_incomplete, |
|
| 1537 | + ), |
|
| 1538 | + ), |
|
| 1539 | + ) |
|
| 1540 | + ), |
|
| 1541 | + 'TKT_ID' => $default ? 0 : $ticket->ID(), |
|
| 1542 | + 'TKT_description' => $default ? '' : $ticket->get_f('TKT_description'), |
|
| 1543 | + 'TKT_is_default' => $default ? 0 : $ticket->is_default(), |
|
| 1544 | + 'TKT_required' => $default ? 0 : $ticket->required(), |
|
| 1545 | + 'TKT_is_default_selector' => '', |
|
| 1546 | + 'ticket_price_rows' => '', |
|
| 1547 | + 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
| 1548 | + ? '' |
|
| 1549 | + : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
| 1550 | + 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
| 1551 | + 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
| 1552 | + ? '' |
|
| 1553 | + : ' style="display:none;"', |
|
| 1554 | + 'show_price_mod_button' => count($prices) > 1 |
|
| 1555 | + || ($default && $count_price_mods > 0) |
|
| 1556 | + || (! $default && $ticket->deleted()) |
|
| 1557 | + ? ' style="display:none;"' |
|
| 1558 | + : '', |
|
| 1559 | + 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
| 1560 | + 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1561 | + 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
| 1562 | + 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
| 1563 | + 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
| 1564 | + 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
| 1565 | + 'TKT_taxable' => $TKT_taxable, |
|
| 1566 | + 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->taxable() |
|
| 1567 | + ? '' |
|
| 1568 | + : ' style="display:none"', |
|
| 1569 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1570 | + 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
| 1571 | + $ticket_subtotal, |
|
| 1572 | + false, |
|
| 1573 | + false |
|
| 1574 | + ), |
|
| 1575 | + 'TKT_subtotal_amount' => $ticket_subtotal, |
|
| 1576 | + 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
| 1577 | + 'disabled' => $ticket instanceof EE_Ticket && $ticket->deleted(), |
|
| 1578 | + 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
| 1579 | + ? ' ticket-archived' |
|
| 1580 | + : '', |
|
| 1581 | + 'trash_icon' => $ticket instanceof EE_Ticket |
|
| 1582 | + && $ticket->deleted() |
|
| 1583 | + && ! $ticket->is_permanently_deleteable() |
|
| 1584 | + ? 'ee-lock-icon ' |
|
| 1585 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1586 | + 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
| 1587 | + ? '' |
|
| 1588 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
| 1589 | + ); |
|
| 1590 | + $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
| 1591 | + ? ' style="display:none"' |
|
| 1592 | + : ''; |
|
| 1593 | + // handle rows that should NOT be empty |
|
| 1594 | + if (empty($template_args['TKT_start_date'])) { |
|
| 1595 | + // if empty then the start date will be now. |
|
| 1596 | + $template_args['TKT_start_date'] = date( |
|
| 1597 | + $this->_date_time_format, |
|
| 1598 | + current_time('timestamp') |
|
| 1599 | + ); |
|
| 1600 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1601 | + } |
|
| 1602 | + if (empty($template_args['TKT_end_date'])) { |
|
| 1603 | + // get the earliest datetime (if present); |
|
| 1604 | + $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
| 1605 | + ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
| 1606 | + 'Datetime', |
|
| 1607 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1608 | + ) |
|
| 1609 | + : null; |
|
| 1610 | + if (! empty($earliest_dtt)) { |
|
| 1611 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
| 1612 | + 'DTT_EVT_start', |
|
| 1613 | + $this->_date_time_format |
|
| 1614 | + ); |
|
| 1615 | + } else { |
|
| 1616 | + // default so let's just use what's been set for the default date-time which is 30 days from now. |
|
| 1617 | + $template_args['TKT_end_date'] = date( |
|
| 1618 | + $this->_date_time_format, |
|
| 1619 | + mktime( |
|
| 1620 | + 24, |
|
| 1621 | + 0, |
|
| 1622 | + 0, |
|
| 1623 | + date('m'), |
|
| 1624 | + date('d') + 29, |
|
| 1625 | + date('Y') |
|
| 1626 | + ) |
|
| 1627 | + ); |
|
| 1628 | + } |
|
| 1629 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1630 | + } |
|
| 1631 | + // generate ticket_datetime items |
|
| 1632 | + if (! $default) { |
|
| 1633 | + $datetime_row = 1; |
|
| 1634 | + foreach ($all_datetimes as $datetime) { |
|
| 1635 | + $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
| 1636 | + $datetime_row, |
|
| 1637 | + $ticket_row, |
|
| 1638 | + $datetime, |
|
| 1639 | + $ticket, |
|
| 1640 | + $ticket_datetimes, |
|
| 1641 | + $default |
|
| 1642 | + ); |
|
| 1643 | + $datetime_row++; |
|
| 1644 | + } |
|
| 1645 | + } |
|
| 1646 | + $price_row = 0; |
|
| 1647 | + foreach ($prices as $price) { |
|
| 1648 | + if (! $price instanceof EE_Price) { |
|
| 1649 | + continue; |
|
| 1650 | + } |
|
| 1651 | + if ($price->is_base_price()) { |
|
| 1652 | + $price_row++; |
|
| 1653 | + continue; |
|
| 1654 | + } |
|
| 1655 | + $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
| 1656 | + $ticket_row, |
|
| 1657 | + $price_row, |
|
| 1658 | + $price, |
|
| 1659 | + $default, |
|
| 1660 | + $ticket, |
|
| 1661 | + // base prices are never displayed, so always show the trash button |
|
| 1662 | + true, |
|
| 1663 | + // show the add button on the last row only... |
|
| 1664 | + // modifier count starts at 1, but the base price is still in the prices array, |
|
| 1665 | + // so if we have two modifiers, then the last one is 2 but there are 3 prices, |
|
| 1666 | + // so the following would work out to: 2 === 3 -1 |
|
| 1667 | + $price_row === (count($prices) - 1) |
|
| 1668 | + ); |
|
| 1669 | + $price_row++; |
|
| 1670 | + } |
|
| 1671 | + // filter $template_args |
|
| 1672 | + $template_args = apply_filters( |
|
| 1673 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
| 1674 | + $template_args, |
|
| 1675 | + $ticket_row, |
|
| 1676 | + $ticket, |
|
| 1677 | + $ticket_datetimes, |
|
| 1678 | + $all_datetimes, |
|
| 1679 | + $default, |
|
| 1680 | + $all_tickets, |
|
| 1681 | + $this->_is_creating_event |
|
| 1682 | + ); |
|
| 1683 | + return EEH_Template::display_template( |
|
| 1684 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
| 1685 | + $template_args, |
|
| 1686 | + true |
|
| 1687 | + ); |
|
| 1688 | + } |
|
| 1689 | 1689 | |
| 1690 | 1690 | |
| 1691 | - /** |
|
| 1692 | - * @param int $ticket_row |
|
| 1693 | - * @param EE_Ticket|null $ticket |
|
| 1694 | - * @return string |
|
| 1695 | - * @throws DomainException |
|
| 1696 | - * @throws EE_Error |
|
| 1697 | - */ |
|
| 1698 | - protected function _get_tax_rows($ticket_row, $ticket) |
|
| 1699 | - { |
|
| 1700 | - $tax_rows = ''; |
|
| 1701 | - /** @var EE_Price[] $taxes */ |
|
| 1702 | - $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
| 1703 | - foreach ($taxes as $tax) { |
|
| 1704 | - $tax_added = $this->_get_tax_added($tax, $ticket); |
|
| 1705 | - $template_args = array( |
|
| 1706 | - 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
| 1707 | - ? '' |
|
| 1708 | - : ' style="display:none;"', |
|
| 1709 | - 'tax_id' => $tax->ID(), |
|
| 1710 | - 'tkt_row' => $ticket_row, |
|
| 1711 | - 'tax_label' => $tax->get('PRC_name'), |
|
| 1712 | - 'tax_added' => $tax_added, |
|
| 1713 | - 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
| 1714 | - 'tax_amount' => $tax->get('PRC_amount'), |
|
| 1715 | - ); |
|
| 1716 | - $template_args = apply_filters( |
|
| 1717 | - 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
| 1718 | - $template_args, |
|
| 1719 | - $ticket_row, |
|
| 1720 | - $ticket, |
|
| 1721 | - $this->_is_creating_event |
|
| 1722 | - ); |
|
| 1723 | - $tax_rows .= EEH_Template::display_template( |
|
| 1724 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
| 1725 | - $template_args, |
|
| 1726 | - true |
|
| 1727 | - ); |
|
| 1728 | - } |
|
| 1729 | - return $tax_rows; |
|
| 1730 | - } |
|
| 1691 | + /** |
|
| 1692 | + * @param int $ticket_row |
|
| 1693 | + * @param EE_Ticket|null $ticket |
|
| 1694 | + * @return string |
|
| 1695 | + * @throws DomainException |
|
| 1696 | + * @throws EE_Error |
|
| 1697 | + */ |
|
| 1698 | + protected function _get_tax_rows($ticket_row, $ticket) |
|
| 1699 | + { |
|
| 1700 | + $tax_rows = ''; |
|
| 1701 | + /** @var EE_Price[] $taxes */ |
|
| 1702 | + $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
| 1703 | + foreach ($taxes as $tax) { |
|
| 1704 | + $tax_added = $this->_get_tax_added($tax, $ticket); |
|
| 1705 | + $template_args = array( |
|
| 1706 | + 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
| 1707 | + ? '' |
|
| 1708 | + : ' style="display:none;"', |
|
| 1709 | + 'tax_id' => $tax->ID(), |
|
| 1710 | + 'tkt_row' => $ticket_row, |
|
| 1711 | + 'tax_label' => $tax->get('PRC_name'), |
|
| 1712 | + 'tax_added' => $tax_added, |
|
| 1713 | + 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
| 1714 | + 'tax_amount' => $tax->get('PRC_amount'), |
|
| 1715 | + ); |
|
| 1716 | + $template_args = apply_filters( |
|
| 1717 | + 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
| 1718 | + $template_args, |
|
| 1719 | + $ticket_row, |
|
| 1720 | + $ticket, |
|
| 1721 | + $this->_is_creating_event |
|
| 1722 | + ); |
|
| 1723 | + $tax_rows .= EEH_Template::display_template( |
|
| 1724 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
| 1725 | + $template_args, |
|
| 1726 | + true |
|
| 1727 | + ); |
|
| 1728 | + } |
|
| 1729 | + return $tax_rows; |
|
| 1730 | + } |
|
| 1731 | 1731 | |
| 1732 | 1732 | |
| 1733 | - /** |
|
| 1734 | - * @param EE_Price $tax |
|
| 1735 | - * @param EE_Ticket|null $ticket |
|
| 1736 | - * @return float|int |
|
| 1737 | - * @throws EE_Error |
|
| 1738 | - */ |
|
| 1739 | - protected function _get_tax_added(EE_Price $tax, $ticket) |
|
| 1740 | - { |
|
| 1741 | - $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1742 | - return $subtotal * $tax->get('PRC_amount') / 100; |
|
| 1743 | - } |
|
| 1733 | + /** |
|
| 1734 | + * @param EE_Price $tax |
|
| 1735 | + * @param EE_Ticket|null $ticket |
|
| 1736 | + * @return float|int |
|
| 1737 | + * @throws EE_Error |
|
| 1738 | + */ |
|
| 1739 | + protected function _get_tax_added(EE_Price $tax, $ticket) |
|
| 1740 | + { |
|
| 1741 | + $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1742 | + return $subtotal * $tax->get('PRC_amount') / 100; |
|
| 1743 | + } |
|
| 1744 | 1744 | |
| 1745 | 1745 | |
| 1746 | - /** |
|
| 1747 | - * @param int $ticket_row |
|
| 1748 | - * @param int $price_row |
|
| 1749 | - * @param EE_Price|null $price |
|
| 1750 | - * @param bool $default |
|
| 1751 | - * @param EE_Ticket|null $ticket |
|
| 1752 | - * @param bool $show_trash |
|
| 1753 | - * @param bool $show_create |
|
| 1754 | - * @return mixed |
|
| 1755 | - * @throws InvalidArgumentException |
|
| 1756 | - * @throws InvalidInterfaceException |
|
| 1757 | - * @throws InvalidDataTypeException |
|
| 1758 | - * @throws DomainException |
|
| 1759 | - * @throws EE_Error |
|
| 1760 | - * @throws ReflectionException |
|
| 1761 | - */ |
|
| 1762 | - protected function _get_ticket_price_row( |
|
| 1763 | - $ticket_row, |
|
| 1764 | - $price_row, |
|
| 1765 | - $price, |
|
| 1766 | - $default, |
|
| 1767 | - $ticket, |
|
| 1768 | - $show_trash = true, |
|
| 1769 | - $show_create = true |
|
| 1770 | - ) { |
|
| 1771 | - $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted'); |
|
| 1772 | - $template_args = array( |
|
| 1773 | - 'tkt_row' => $default && empty($ticket) |
|
| 1774 | - ? 'TICKETNUM' |
|
| 1775 | - : $ticket_row, |
|
| 1776 | - 'PRC_order' => $default && empty($price) |
|
| 1777 | - ? 'PRICENUM' |
|
| 1778 | - : $price_row, |
|
| 1779 | - 'edit_prices_name' => $default && empty($price) |
|
| 1780 | - ? 'PRICENAMEATTR' |
|
| 1781 | - : 'edit_prices', |
|
| 1782 | - 'price_type_selector' => $default && empty($price) |
|
| 1783 | - ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
| 1784 | - : $this->_get_price_type_selector( |
|
| 1785 | - $ticket_row, |
|
| 1786 | - $price_row, |
|
| 1787 | - $price, |
|
| 1788 | - $default, |
|
| 1789 | - $send_disabled |
|
| 1790 | - ), |
|
| 1791 | - 'PRC_ID' => $default && empty($price) |
|
| 1792 | - ? 0 |
|
| 1793 | - : $price->ID(), |
|
| 1794 | - 'PRC_is_default' => $default && empty($price) |
|
| 1795 | - ? 0 |
|
| 1796 | - : $price->get('PRC_is_default'), |
|
| 1797 | - 'PRC_name' => $default && empty($price) |
|
| 1798 | - ? '' |
|
| 1799 | - : $price->get('PRC_name'), |
|
| 1800 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1801 | - 'show_plus_or_minus' => $default && empty($price) |
|
| 1802 | - ? '' |
|
| 1803 | - : ' style="display:none;"', |
|
| 1804 | - 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
| 1805 | - ? ' style="display:none;"' |
|
| 1806 | - : '', |
|
| 1807 | - 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
| 1808 | - ? ' style="display:none;"' |
|
| 1809 | - : '', |
|
| 1810 | - 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
| 1811 | - ? ' style="display:none"' |
|
| 1812 | - : '', |
|
| 1813 | - 'PRC_amount' => $default && empty($price) |
|
| 1814 | - ? 0 |
|
| 1815 | - : $price->get_pretty('PRC_amount', 'localized_float'), |
|
| 1816 | - 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
| 1817 | - ? ' style="display:none;"' |
|
| 1818 | - : '', |
|
| 1819 | - 'show_trash_icon' => $show_trash |
|
| 1820 | - ? '' |
|
| 1821 | - : ' style="display:none;"', |
|
| 1822 | - 'show_create_button' => $show_create |
|
| 1823 | - ? '' |
|
| 1824 | - : ' style="display:none;"', |
|
| 1825 | - 'PRC_desc' => $default && empty($price) |
|
| 1826 | - ? '' |
|
| 1827 | - : $price->get('PRC_desc'), |
|
| 1828 | - 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted'), |
|
| 1829 | - 'current_price_type_id' => $price instanceof EE_Price ? $price->type() : 0, |
|
| 1830 | - ); |
|
| 1831 | - $template_args = apply_filters( |
|
| 1832 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
| 1833 | - $template_args, |
|
| 1834 | - $ticket_row, |
|
| 1835 | - $price_row, |
|
| 1836 | - $price, |
|
| 1837 | - $default, |
|
| 1838 | - $ticket, |
|
| 1839 | - $show_trash, |
|
| 1840 | - $show_create, |
|
| 1841 | - $this->_is_creating_event |
|
| 1842 | - ); |
|
| 1843 | - return EEH_Template::display_template( |
|
| 1844 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
| 1845 | - $template_args, |
|
| 1846 | - true |
|
| 1847 | - ); |
|
| 1848 | - } |
|
| 1746 | + /** |
|
| 1747 | + * @param int $ticket_row |
|
| 1748 | + * @param int $price_row |
|
| 1749 | + * @param EE_Price|null $price |
|
| 1750 | + * @param bool $default |
|
| 1751 | + * @param EE_Ticket|null $ticket |
|
| 1752 | + * @param bool $show_trash |
|
| 1753 | + * @param bool $show_create |
|
| 1754 | + * @return mixed |
|
| 1755 | + * @throws InvalidArgumentException |
|
| 1756 | + * @throws InvalidInterfaceException |
|
| 1757 | + * @throws InvalidDataTypeException |
|
| 1758 | + * @throws DomainException |
|
| 1759 | + * @throws EE_Error |
|
| 1760 | + * @throws ReflectionException |
|
| 1761 | + */ |
|
| 1762 | + protected function _get_ticket_price_row( |
|
| 1763 | + $ticket_row, |
|
| 1764 | + $price_row, |
|
| 1765 | + $price, |
|
| 1766 | + $default, |
|
| 1767 | + $ticket, |
|
| 1768 | + $show_trash = true, |
|
| 1769 | + $show_create = true |
|
| 1770 | + ) { |
|
| 1771 | + $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted'); |
|
| 1772 | + $template_args = array( |
|
| 1773 | + 'tkt_row' => $default && empty($ticket) |
|
| 1774 | + ? 'TICKETNUM' |
|
| 1775 | + : $ticket_row, |
|
| 1776 | + 'PRC_order' => $default && empty($price) |
|
| 1777 | + ? 'PRICENUM' |
|
| 1778 | + : $price_row, |
|
| 1779 | + 'edit_prices_name' => $default && empty($price) |
|
| 1780 | + ? 'PRICENAMEATTR' |
|
| 1781 | + : 'edit_prices', |
|
| 1782 | + 'price_type_selector' => $default && empty($price) |
|
| 1783 | + ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
| 1784 | + : $this->_get_price_type_selector( |
|
| 1785 | + $ticket_row, |
|
| 1786 | + $price_row, |
|
| 1787 | + $price, |
|
| 1788 | + $default, |
|
| 1789 | + $send_disabled |
|
| 1790 | + ), |
|
| 1791 | + 'PRC_ID' => $default && empty($price) |
|
| 1792 | + ? 0 |
|
| 1793 | + : $price->ID(), |
|
| 1794 | + 'PRC_is_default' => $default && empty($price) |
|
| 1795 | + ? 0 |
|
| 1796 | + : $price->get('PRC_is_default'), |
|
| 1797 | + 'PRC_name' => $default && empty($price) |
|
| 1798 | + ? '' |
|
| 1799 | + : $price->get('PRC_name'), |
|
| 1800 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1801 | + 'show_plus_or_minus' => $default && empty($price) |
|
| 1802 | + ? '' |
|
| 1803 | + : ' style="display:none;"', |
|
| 1804 | + 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
| 1805 | + ? ' style="display:none;"' |
|
| 1806 | + : '', |
|
| 1807 | + 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
| 1808 | + ? ' style="display:none;"' |
|
| 1809 | + : '', |
|
| 1810 | + 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
| 1811 | + ? ' style="display:none"' |
|
| 1812 | + : '', |
|
| 1813 | + 'PRC_amount' => $default && empty($price) |
|
| 1814 | + ? 0 |
|
| 1815 | + : $price->get_pretty('PRC_amount', 'localized_float'), |
|
| 1816 | + 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
| 1817 | + ? ' style="display:none;"' |
|
| 1818 | + : '', |
|
| 1819 | + 'show_trash_icon' => $show_trash |
|
| 1820 | + ? '' |
|
| 1821 | + : ' style="display:none;"', |
|
| 1822 | + 'show_create_button' => $show_create |
|
| 1823 | + ? '' |
|
| 1824 | + : ' style="display:none;"', |
|
| 1825 | + 'PRC_desc' => $default && empty($price) |
|
| 1826 | + ? '' |
|
| 1827 | + : $price->get('PRC_desc'), |
|
| 1828 | + 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted'), |
|
| 1829 | + 'current_price_type_id' => $price instanceof EE_Price ? $price->type() : 0, |
|
| 1830 | + ); |
|
| 1831 | + $template_args = apply_filters( |
|
| 1832 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
| 1833 | + $template_args, |
|
| 1834 | + $ticket_row, |
|
| 1835 | + $price_row, |
|
| 1836 | + $price, |
|
| 1837 | + $default, |
|
| 1838 | + $ticket, |
|
| 1839 | + $show_trash, |
|
| 1840 | + $show_create, |
|
| 1841 | + $this->_is_creating_event |
|
| 1842 | + ); |
|
| 1843 | + return EEH_Template::display_template( |
|
| 1844 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
| 1845 | + $template_args, |
|
| 1846 | + true |
|
| 1847 | + ); |
|
| 1848 | + } |
|
| 1849 | 1849 | |
| 1850 | 1850 | |
| 1851 | - /** |
|
| 1852 | - * @param int $ticket_row |
|
| 1853 | - * @param int $price_row |
|
| 1854 | - * @param EE_Price $price |
|
| 1855 | - * @param bool $default |
|
| 1856 | - * @param bool $disabled |
|
| 1857 | - * @return mixed |
|
| 1858 | - * @throws ReflectionException |
|
| 1859 | - * @throws InvalidArgumentException |
|
| 1860 | - * @throws InvalidInterfaceException |
|
| 1861 | - * @throws InvalidDataTypeException |
|
| 1862 | - * @throws DomainException |
|
| 1863 | - * @throws EE_Error |
|
| 1864 | - */ |
|
| 1865 | - protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
| 1866 | - { |
|
| 1867 | - if ($price->is_base_price()) { |
|
| 1868 | - return $this->_get_base_price_template( |
|
| 1869 | - $ticket_row, |
|
| 1870 | - $price_row, |
|
| 1871 | - $price, |
|
| 1872 | - $default |
|
| 1873 | - ); |
|
| 1874 | - } |
|
| 1875 | - return $this->_get_price_modifier_template( |
|
| 1876 | - $ticket_row, |
|
| 1877 | - $price_row, |
|
| 1878 | - $price, |
|
| 1879 | - $default, |
|
| 1880 | - $disabled |
|
| 1881 | - ); |
|
| 1882 | - } |
|
| 1851 | + /** |
|
| 1852 | + * @param int $ticket_row |
|
| 1853 | + * @param int $price_row |
|
| 1854 | + * @param EE_Price $price |
|
| 1855 | + * @param bool $default |
|
| 1856 | + * @param bool $disabled |
|
| 1857 | + * @return mixed |
|
| 1858 | + * @throws ReflectionException |
|
| 1859 | + * @throws InvalidArgumentException |
|
| 1860 | + * @throws InvalidInterfaceException |
|
| 1861 | + * @throws InvalidDataTypeException |
|
| 1862 | + * @throws DomainException |
|
| 1863 | + * @throws EE_Error |
|
| 1864 | + */ |
|
| 1865 | + protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
| 1866 | + { |
|
| 1867 | + if ($price->is_base_price()) { |
|
| 1868 | + return $this->_get_base_price_template( |
|
| 1869 | + $ticket_row, |
|
| 1870 | + $price_row, |
|
| 1871 | + $price, |
|
| 1872 | + $default |
|
| 1873 | + ); |
|
| 1874 | + } |
|
| 1875 | + return $this->_get_price_modifier_template( |
|
| 1876 | + $ticket_row, |
|
| 1877 | + $price_row, |
|
| 1878 | + $price, |
|
| 1879 | + $default, |
|
| 1880 | + $disabled |
|
| 1881 | + ); |
|
| 1882 | + } |
|
| 1883 | 1883 | |
| 1884 | 1884 | |
| 1885 | - /** |
|
| 1886 | - * @param int $ticket_row |
|
| 1887 | - * @param int $price_row |
|
| 1888 | - * @param EE_Price $price |
|
| 1889 | - * @param bool $default |
|
| 1890 | - * @return mixed |
|
| 1891 | - * @throws DomainException |
|
| 1892 | - * @throws EE_Error |
|
| 1893 | - */ |
|
| 1894 | - protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
| 1895 | - { |
|
| 1896 | - $template_args = array( |
|
| 1897 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1898 | - 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
| 1899 | - 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
| 1900 | - 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
| 1901 | - 'price_selected_operator' => '+', |
|
| 1902 | - 'price_selected_is_percent' => 0, |
|
| 1903 | - ); |
|
| 1904 | - $template_args = apply_filters( |
|
| 1905 | - 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
| 1906 | - $template_args, |
|
| 1907 | - $ticket_row, |
|
| 1908 | - $price_row, |
|
| 1909 | - $price, |
|
| 1910 | - $default, |
|
| 1911 | - $this->_is_creating_event |
|
| 1912 | - ); |
|
| 1913 | - return EEH_Template::display_template( |
|
| 1914 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
| 1915 | - $template_args, |
|
| 1916 | - true |
|
| 1917 | - ); |
|
| 1918 | - } |
|
| 1885 | + /** |
|
| 1886 | + * @param int $ticket_row |
|
| 1887 | + * @param int $price_row |
|
| 1888 | + * @param EE_Price $price |
|
| 1889 | + * @param bool $default |
|
| 1890 | + * @return mixed |
|
| 1891 | + * @throws DomainException |
|
| 1892 | + * @throws EE_Error |
|
| 1893 | + */ |
|
| 1894 | + protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
| 1895 | + { |
|
| 1896 | + $template_args = array( |
|
| 1897 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1898 | + 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
| 1899 | + 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
| 1900 | + 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
| 1901 | + 'price_selected_operator' => '+', |
|
| 1902 | + 'price_selected_is_percent' => 0, |
|
| 1903 | + ); |
|
| 1904 | + $template_args = apply_filters( |
|
| 1905 | + 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
| 1906 | + $template_args, |
|
| 1907 | + $ticket_row, |
|
| 1908 | + $price_row, |
|
| 1909 | + $price, |
|
| 1910 | + $default, |
|
| 1911 | + $this->_is_creating_event |
|
| 1912 | + ); |
|
| 1913 | + return EEH_Template::display_template( |
|
| 1914 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
| 1915 | + $template_args, |
|
| 1916 | + true |
|
| 1917 | + ); |
|
| 1918 | + } |
|
| 1919 | 1919 | |
| 1920 | 1920 | |
| 1921 | - /** |
|
| 1922 | - * @param int $ticket_row |
|
| 1923 | - * @param int $price_row |
|
| 1924 | - * @param EE_Price $price |
|
| 1925 | - * @param bool $default |
|
| 1926 | - * @param bool $disabled |
|
| 1927 | - * @return mixed |
|
| 1928 | - * @throws ReflectionException |
|
| 1929 | - * @throws InvalidArgumentException |
|
| 1930 | - * @throws InvalidInterfaceException |
|
| 1931 | - * @throws InvalidDataTypeException |
|
| 1932 | - * @throws DomainException |
|
| 1933 | - * @throws EE_Error |
|
| 1934 | - */ |
|
| 1935 | - protected function _get_price_modifier_template( |
|
| 1936 | - $ticket_row, |
|
| 1937 | - $price_row, |
|
| 1938 | - $price, |
|
| 1939 | - $default, |
|
| 1940 | - $disabled = false |
|
| 1941 | - ) { |
|
| 1942 | - $select_name = $default && ! $price instanceof EE_Price |
|
| 1943 | - ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
| 1944 | - : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
| 1945 | - /** @var EEM_Price_Type $price_type_model */ |
|
| 1946 | - $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
| 1947 | - $price_types = $price_type_model->get_all([['PBT_ID' => ['!=', 1]]]); |
|
| 1948 | - $all_price_types = $default && ! $price instanceof EE_Price |
|
| 1949 | - ? array(esc_html__('Select Modifier', 'event_espresso')) |
|
| 1950 | - : array(); |
|
| 1951 | - $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
| 1952 | - $price_option_spans = ''; |
|
| 1953 | - // setup price types for selector |
|
| 1954 | - foreach ($price_types as $price_type) { |
|
| 1955 | - if (! $price_type instanceof EE_Price_Type) { |
|
| 1956 | - continue; |
|
| 1957 | - } |
|
| 1958 | - $all_price_types[ $price_type->ID() ] = $price_type->name(); |
|
| 1959 | - // while we're in the loop let's setup the option spans used by js |
|
| 1960 | - $span_args = array( |
|
| 1961 | - 'PRT_ID' => $price_type->ID(), |
|
| 1962 | - 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
| 1963 | - 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
| 1964 | - ); |
|
| 1965 | - $price_option_spans .= EEH_Template::display_template( |
|
| 1966 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
| 1967 | - $span_args, |
|
| 1968 | - true |
|
| 1969 | - ); |
|
| 1970 | - } |
|
| 1971 | - $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' |
|
| 1972 | - : $select_name; |
|
| 1973 | - $select_input = new EE_Select_Input( |
|
| 1974 | - $all_price_types, |
|
| 1975 | - array( |
|
| 1976 | - 'default' => $selected_price_type_id, |
|
| 1977 | - 'html_name' => $select_name, |
|
| 1978 | - 'html_class' => 'edit-price-PRT_ID', |
|
| 1979 | - 'html_id' => "edit-price-type-{$ticket_row}-{$price_row}", |
|
| 1980 | - 'other_html_attributes' => $disabled ? 'disabled' : '', |
|
| 1981 | - ) |
|
| 1982 | - ); |
|
| 1983 | - $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
| 1984 | - $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
| 1985 | - $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
| 1986 | - $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
| 1987 | - $template_args = array( |
|
| 1988 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1989 | - 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
| 1990 | - 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
| 1991 | - 'main_name' => $select_name, |
|
| 1992 | - 'selected_price_type_id' => $selected_price_type_id, |
|
| 1993 | - 'price_option_spans' => $price_option_spans, |
|
| 1994 | - 'price_selected_operator' => $price_selected_operator, |
|
| 1995 | - 'price_selected_is_percent' => $price_selected_is_percent, |
|
| 1996 | - 'disabled' => $disabled, |
|
| 1997 | - ); |
|
| 1998 | - $template_args = apply_filters( |
|
| 1999 | - 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
| 2000 | - $template_args, |
|
| 2001 | - $ticket_row, |
|
| 2002 | - $price_row, |
|
| 2003 | - $price, |
|
| 2004 | - $default, |
|
| 2005 | - $disabled, |
|
| 2006 | - $this->_is_creating_event |
|
| 2007 | - ); |
|
| 2008 | - return EEH_Template::display_template( |
|
| 2009 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
| 2010 | - $template_args, |
|
| 2011 | - true |
|
| 2012 | - ); |
|
| 2013 | - } |
|
| 1921 | + /** |
|
| 1922 | + * @param int $ticket_row |
|
| 1923 | + * @param int $price_row |
|
| 1924 | + * @param EE_Price $price |
|
| 1925 | + * @param bool $default |
|
| 1926 | + * @param bool $disabled |
|
| 1927 | + * @return mixed |
|
| 1928 | + * @throws ReflectionException |
|
| 1929 | + * @throws InvalidArgumentException |
|
| 1930 | + * @throws InvalidInterfaceException |
|
| 1931 | + * @throws InvalidDataTypeException |
|
| 1932 | + * @throws DomainException |
|
| 1933 | + * @throws EE_Error |
|
| 1934 | + */ |
|
| 1935 | + protected function _get_price_modifier_template( |
|
| 1936 | + $ticket_row, |
|
| 1937 | + $price_row, |
|
| 1938 | + $price, |
|
| 1939 | + $default, |
|
| 1940 | + $disabled = false |
|
| 1941 | + ) { |
|
| 1942 | + $select_name = $default && ! $price instanceof EE_Price |
|
| 1943 | + ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
| 1944 | + : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
| 1945 | + /** @var EEM_Price_Type $price_type_model */ |
|
| 1946 | + $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
| 1947 | + $price_types = $price_type_model->get_all([['PBT_ID' => ['!=', 1]]]); |
|
| 1948 | + $all_price_types = $default && ! $price instanceof EE_Price |
|
| 1949 | + ? array(esc_html__('Select Modifier', 'event_espresso')) |
|
| 1950 | + : array(); |
|
| 1951 | + $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
| 1952 | + $price_option_spans = ''; |
|
| 1953 | + // setup price types for selector |
|
| 1954 | + foreach ($price_types as $price_type) { |
|
| 1955 | + if (! $price_type instanceof EE_Price_Type) { |
|
| 1956 | + continue; |
|
| 1957 | + } |
|
| 1958 | + $all_price_types[ $price_type->ID() ] = $price_type->name(); |
|
| 1959 | + // while we're in the loop let's setup the option spans used by js |
|
| 1960 | + $span_args = array( |
|
| 1961 | + 'PRT_ID' => $price_type->ID(), |
|
| 1962 | + 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
| 1963 | + 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
| 1964 | + ); |
|
| 1965 | + $price_option_spans .= EEH_Template::display_template( |
|
| 1966 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
| 1967 | + $span_args, |
|
| 1968 | + true |
|
| 1969 | + ); |
|
| 1970 | + } |
|
| 1971 | + $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' |
|
| 1972 | + : $select_name; |
|
| 1973 | + $select_input = new EE_Select_Input( |
|
| 1974 | + $all_price_types, |
|
| 1975 | + array( |
|
| 1976 | + 'default' => $selected_price_type_id, |
|
| 1977 | + 'html_name' => $select_name, |
|
| 1978 | + 'html_class' => 'edit-price-PRT_ID', |
|
| 1979 | + 'html_id' => "edit-price-type-{$ticket_row}-{$price_row}", |
|
| 1980 | + 'other_html_attributes' => $disabled ? 'disabled' : '', |
|
| 1981 | + ) |
|
| 1982 | + ); |
|
| 1983 | + $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
| 1984 | + $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
| 1985 | + $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
| 1986 | + $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
| 1987 | + $template_args = array( |
|
| 1988 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1989 | + 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
| 1990 | + 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
| 1991 | + 'main_name' => $select_name, |
|
| 1992 | + 'selected_price_type_id' => $selected_price_type_id, |
|
| 1993 | + 'price_option_spans' => $price_option_spans, |
|
| 1994 | + 'price_selected_operator' => $price_selected_operator, |
|
| 1995 | + 'price_selected_is_percent' => $price_selected_is_percent, |
|
| 1996 | + 'disabled' => $disabled, |
|
| 1997 | + ); |
|
| 1998 | + $template_args = apply_filters( |
|
| 1999 | + 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
| 2000 | + $template_args, |
|
| 2001 | + $ticket_row, |
|
| 2002 | + $price_row, |
|
| 2003 | + $price, |
|
| 2004 | + $default, |
|
| 2005 | + $disabled, |
|
| 2006 | + $this->_is_creating_event |
|
| 2007 | + ); |
|
| 2008 | + return EEH_Template::display_template( |
|
| 2009 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
| 2010 | + $template_args, |
|
| 2011 | + true |
|
| 2012 | + ); |
|
| 2013 | + } |
|
| 2014 | 2014 | |
| 2015 | 2015 | |
| 2016 | - /** |
|
| 2017 | - * @param int $datetime_row |
|
| 2018 | - * @param int $ticket_row |
|
| 2019 | - * @param EE_Datetime|null $datetime |
|
| 2020 | - * @param EE_Ticket|null $ticket |
|
| 2021 | - * @param array $ticket_datetimes |
|
| 2022 | - * @param bool $default |
|
| 2023 | - * @return mixed |
|
| 2024 | - * @throws DomainException |
|
| 2025 | - * @throws EE_Error |
|
| 2026 | - */ |
|
| 2027 | - protected function _get_ticket_datetime_list_item( |
|
| 2028 | - $datetime_row, |
|
| 2029 | - $ticket_row, |
|
| 2030 | - $datetime, |
|
| 2031 | - $ticket, |
|
| 2032 | - $ticket_datetimes = array(), |
|
| 2033 | - $default |
|
| 2034 | - ) { |
|
| 2035 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
| 2036 | - ? $ticket_datetimes[ $ticket->ID() ] |
|
| 2037 | - : array(); |
|
| 2038 | - $template_args = array( |
|
| 2039 | - 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
| 2040 | - ? 'DTTNUM' |
|
| 2041 | - : $datetime_row, |
|
| 2042 | - 'tkt_row' => $default |
|
| 2043 | - ? 'TICKETNUM' |
|
| 2044 | - : $ticket_row, |
|
| 2045 | - 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
| 2046 | - ? ' ticket-selected' |
|
| 2047 | - : '', |
|
| 2048 | - 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
| 2049 | - ? ' checked="checked"' |
|
| 2050 | - : '', |
|
| 2051 | - 'DTT_name' => $default && empty($datetime) |
|
| 2052 | - ? 'DTTNAME' |
|
| 2053 | - : $datetime->get_dtt_display_name(true), |
|
| 2054 | - 'tkt_status_class' => '', |
|
| 2055 | - ); |
|
| 2056 | - $template_args = apply_filters( |
|
| 2057 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
| 2058 | - $template_args, |
|
| 2059 | - $datetime_row, |
|
| 2060 | - $ticket_row, |
|
| 2061 | - $datetime, |
|
| 2062 | - $ticket, |
|
| 2063 | - $ticket_datetimes, |
|
| 2064 | - $default, |
|
| 2065 | - $this->_is_creating_event |
|
| 2066 | - ); |
|
| 2067 | - return EEH_Template::display_template( |
|
| 2068 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
| 2069 | - $template_args, |
|
| 2070 | - true |
|
| 2071 | - ); |
|
| 2072 | - } |
|
| 2016 | + /** |
|
| 2017 | + * @param int $datetime_row |
|
| 2018 | + * @param int $ticket_row |
|
| 2019 | + * @param EE_Datetime|null $datetime |
|
| 2020 | + * @param EE_Ticket|null $ticket |
|
| 2021 | + * @param array $ticket_datetimes |
|
| 2022 | + * @param bool $default |
|
| 2023 | + * @return mixed |
|
| 2024 | + * @throws DomainException |
|
| 2025 | + * @throws EE_Error |
|
| 2026 | + */ |
|
| 2027 | + protected function _get_ticket_datetime_list_item( |
|
| 2028 | + $datetime_row, |
|
| 2029 | + $ticket_row, |
|
| 2030 | + $datetime, |
|
| 2031 | + $ticket, |
|
| 2032 | + $ticket_datetimes = array(), |
|
| 2033 | + $default |
|
| 2034 | + ) { |
|
| 2035 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
| 2036 | + ? $ticket_datetimes[ $ticket->ID() ] |
|
| 2037 | + : array(); |
|
| 2038 | + $template_args = array( |
|
| 2039 | + 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
| 2040 | + ? 'DTTNUM' |
|
| 2041 | + : $datetime_row, |
|
| 2042 | + 'tkt_row' => $default |
|
| 2043 | + ? 'TICKETNUM' |
|
| 2044 | + : $ticket_row, |
|
| 2045 | + 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
| 2046 | + ? ' ticket-selected' |
|
| 2047 | + : '', |
|
| 2048 | + 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
| 2049 | + ? ' checked="checked"' |
|
| 2050 | + : '', |
|
| 2051 | + 'DTT_name' => $default && empty($datetime) |
|
| 2052 | + ? 'DTTNAME' |
|
| 2053 | + : $datetime->get_dtt_display_name(true), |
|
| 2054 | + 'tkt_status_class' => '', |
|
| 2055 | + ); |
|
| 2056 | + $template_args = apply_filters( |
|
| 2057 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
| 2058 | + $template_args, |
|
| 2059 | + $datetime_row, |
|
| 2060 | + $ticket_row, |
|
| 2061 | + $datetime, |
|
| 2062 | + $ticket, |
|
| 2063 | + $ticket_datetimes, |
|
| 2064 | + $default, |
|
| 2065 | + $this->_is_creating_event |
|
| 2066 | + ); |
|
| 2067 | + return EEH_Template::display_template( |
|
| 2068 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
| 2069 | + $template_args, |
|
| 2070 | + true |
|
| 2071 | + ); |
|
| 2072 | + } |
|
| 2073 | 2073 | |
| 2074 | 2074 | |
| 2075 | - /** |
|
| 2076 | - * @param array $all_datetimes |
|
| 2077 | - * @param array $all_tickets |
|
| 2078 | - * @return mixed |
|
| 2079 | - * @throws ReflectionException |
|
| 2080 | - * @throws InvalidArgumentException |
|
| 2081 | - * @throws InvalidInterfaceException |
|
| 2082 | - * @throws InvalidDataTypeException |
|
| 2083 | - * @throws DomainException |
|
| 2084 | - * @throws EE_Error |
|
| 2085 | - */ |
|
| 2086 | - protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
| 2087 | - { |
|
| 2088 | - $template_args = array( |
|
| 2089 | - 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
| 2090 | - 'DTTNUM', |
|
| 2091 | - null, |
|
| 2092 | - true, |
|
| 2093 | - $all_datetimes |
|
| 2094 | - ), |
|
| 2095 | - 'default_ticket_row' => $this->_get_ticket_row( |
|
| 2096 | - 'TICKETNUM', |
|
| 2097 | - null, |
|
| 2098 | - array(), |
|
| 2099 | - array(), |
|
| 2100 | - true |
|
| 2101 | - ), |
|
| 2102 | - 'default_price_row' => $this->_get_ticket_price_row( |
|
| 2103 | - 'TICKETNUM', |
|
| 2104 | - 'PRICENUM', |
|
| 2105 | - null, |
|
| 2106 | - true, |
|
| 2107 | - null |
|
| 2108 | - ), |
|
| 2109 | - 'default_price_rows' => '', |
|
| 2110 | - 'default_base_price_amount' => 0, |
|
| 2111 | - 'default_base_price_name' => '', |
|
| 2112 | - 'default_base_price_description' => '', |
|
| 2113 | - 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
| 2114 | - 'TICKETNUM', |
|
| 2115 | - 'PRICENUM', |
|
| 2116 | - null, |
|
| 2117 | - true |
|
| 2118 | - ), |
|
| 2119 | - 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
| 2120 | - 'DTTNUM', |
|
| 2121 | - null, |
|
| 2122 | - array(), |
|
| 2123 | - array(), |
|
| 2124 | - true |
|
| 2125 | - ), |
|
| 2126 | - 'existing_available_datetime_tickets_list' => '', |
|
| 2127 | - 'existing_available_ticket_datetimes_list' => '', |
|
| 2128 | - 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
| 2129 | - 'DTTNUM', |
|
| 2130 | - 'TICKETNUM', |
|
| 2131 | - null, |
|
| 2132 | - null, |
|
| 2133 | - array(), |
|
| 2134 | - true |
|
| 2135 | - ), |
|
| 2136 | - 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
| 2137 | - 'DTTNUM', |
|
| 2138 | - 'TICKETNUM', |
|
| 2139 | - null, |
|
| 2140 | - null, |
|
| 2141 | - array(), |
|
| 2142 | - true |
|
| 2143 | - ), |
|
| 2144 | - ); |
|
| 2145 | - $ticket_row = 1; |
|
| 2146 | - foreach ($all_tickets as $ticket) { |
|
| 2147 | - $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
| 2148 | - 'DTTNUM', |
|
| 2149 | - $ticket_row, |
|
| 2150 | - null, |
|
| 2151 | - $ticket, |
|
| 2152 | - array(), |
|
| 2153 | - true |
|
| 2154 | - ); |
|
| 2155 | - $ticket_row++; |
|
| 2156 | - } |
|
| 2157 | - $datetime_row = 1; |
|
| 2158 | - foreach ($all_datetimes as $datetime) { |
|
| 2159 | - $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
| 2160 | - $datetime_row, |
|
| 2161 | - 'TICKETNUM', |
|
| 2162 | - $datetime, |
|
| 2163 | - null, |
|
| 2164 | - array(), |
|
| 2165 | - true |
|
| 2166 | - ); |
|
| 2167 | - $datetime_row++; |
|
| 2168 | - } |
|
| 2169 | - /** @var EEM_Price $price_model */ |
|
| 2170 | - $price_model = EE_Registry::instance()->load_model('Price'); |
|
| 2171 | - $default_prices = $price_model->get_all_default_prices(); |
|
| 2172 | - $price_row = 0; |
|
| 2173 | - foreach ($default_prices as $price) { |
|
| 2174 | - if (! $price instanceof EE_Price) { |
|
| 2175 | - continue; |
|
| 2176 | - } |
|
| 2177 | - if ($price->is_base_price()) { |
|
| 2178 | - $template_args['default_base_price_amount'] = $price->get_pretty( |
|
| 2179 | - 'PRC_amount', |
|
| 2180 | - 'localized_float' |
|
| 2181 | - ); |
|
| 2182 | - $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
| 2183 | - $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
| 2184 | - $price_row++; |
|
| 2185 | - continue; |
|
| 2186 | - } |
|
| 2187 | - $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
| 2188 | - 'TICKETNUM', |
|
| 2189 | - $price_row, |
|
| 2190 | - $price, |
|
| 2191 | - true, |
|
| 2192 | - null, |
|
| 2193 | - // base prices are never displayed, so always show the trash button |
|
| 2194 | - true, |
|
| 2195 | - // show the add button on the last row only... |
|
| 2196 | - // modifier count starts at 1, but the base price is still in the prices array, |
|
| 2197 | - // so if we have two modifiers, then the last one is 2 but there are 3 prices, |
|
| 2198 | - // so the following would work out to: 2 === 3 -1 |
|
| 2199 | - $price_row === (count($default_prices) - 1) |
|
| 2200 | - ); |
|
| 2201 | - $price_row++; |
|
| 2202 | - } |
|
| 2203 | - $template_args = apply_filters( |
|
| 2204 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
| 2205 | - $template_args, |
|
| 2206 | - $all_datetimes, |
|
| 2207 | - $all_tickets, |
|
| 2208 | - $this->_is_creating_event |
|
| 2209 | - ); |
|
| 2210 | - return EEH_Template::display_template( |
|
| 2211 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
| 2212 | - $template_args, |
|
| 2213 | - true |
|
| 2214 | - ); |
|
| 2215 | - } |
|
| 2075 | + /** |
|
| 2076 | + * @param array $all_datetimes |
|
| 2077 | + * @param array $all_tickets |
|
| 2078 | + * @return mixed |
|
| 2079 | + * @throws ReflectionException |
|
| 2080 | + * @throws InvalidArgumentException |
|
| 2081 | + * @throws InvalidInterfaceException |
|
| 2082 | + * @throws InvalidDataTypeException |
|
| 2083 | + * @throws DomainException |
|
| 2084 | + * @throws EE_Error |
|
| 2085 | + */ |
|
| 2086 | + protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
| 2087 | + { |
|
| 2088 | + $template_args = array( |
|
| 2089 | + 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
| 2090 | + 'DTTNUM', |
|
| 2091 | + null, |
|
| 2092 | + true, |
|
| 2093 | + $all_datetimes |
|
| 2094 | + ), |
|
| 2095 | + 'default_ticket_row' => $this->_get_ticket_row( |
|
| 2096 | + 'TICKETNUM', |
|
| 2097 | + null, |
|
| 2098 | + array(), |
|
| 2099 | + array(), |
|
| 2100 | + true |
|
| 2101 | + ), |
|
| 2102 | + 'default_price_row' => $this->_get_ticket_price_row( |
|
| 2103 | + 'TICKETNUM', |
|
| 2104 | + 'PRICENUM', |
|
| 2105 | + null, |
|
| 2106 | + true, |
|
| 2107 | + null |
|
| 2108 | + ), |
|
| 2109 | + 'default_price_rows' => '', |
|
| 2110 | + 'default_base_price_amount' => 0, |
|
| 2111 | + 'default_base_price_name' => '', |
|
| 2112 | + 'default_base_price_description' => '', |
|
| 2113 | + 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
| 2114 | + 'TICKETNUM', |
|
| 2115 | + 'PRICENUM', |
|
| 2116 | + null, |
|
| 2117 | + true |
|
| 2118 | + ), |
|
| 2119 | + 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
| 2120 | + 'DTTNUM', |
|
| 2121 | + null, |
|
| 2122 | + array(), |
|
| 2123 | + array(), |
|
| 2124 | + true |
|
| 2125 | + ), |
|
| 2126 | + 'existing_available_datetime_tickets_list' => '', |
|
| 2127 | + 'existing_available_ticket_datetimes_list' => '', |
|
| 2128 | + 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
| 2129 | + 'DTTNUM', |
|
| 2130 | + 'TICKETNUM', |
|
| 2131 | + null, |
|
| 2132 | + null, |
|
| 2133 | + array(), |
|
| 2134 | + true |
|
| 2135 | + ), |
|
| 2136 | + 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
| 2137 | + 'DTTNUM', |
|
| 2138 | + 'TICKETNUM', |
|
| 2139 | + null, |
|
| 2140 | + null, |
|
| 2141 | + array(), |
|
| 2142 | + true |
|
| 2143 | + ), |
|
| 2144 | + ); |
|
| 2145 | + $ticket_row = 1; |
|
| 2146 | + foreach ($all_tickets as $ticket) { |
|
| 2147 | + $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
| 2148 | + 'DTTNUM', |
|
| 2149 | + $ticket_row, |
|
| 2150 | + null, |
|
| 2151 | + $ticket, |
|
| 2152 | + array(), |
|
| 2153 | + true |
|
| 2154 | + ); |
|
| 2155 | + $ticket_row++; |
|
| 2156 | + } |
|
| 2157 | + $datetime_row = 1; |
|
| 2158 | + foreach ($all_datetimes as $datetime) { |
|
| 2159 | + $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
| 2160 | + $datetime_row, |
|
| 2161 | + 'TICKETNUM', |
|
| 2162 | + $datetime, |
|
| 2163 | + null, |
|
| 2164 | + array(), |
|
| 2165 | + true |
|
| 2166 | + ); |
|
| 2167 | + $datetime_row++; |
|
| 2168 | + } |
|
| 2169 | + /** @var EEM_Price $price_model */ |
|
| 2170 | + $price_model = EE_Registry::instance()->load_model('Price'); |
|
| 2171 | + $default_prices = $price_model->get_all_default_prices(); |
|
| 2172 | + $price_row = 0; |
|
| 2173 | + foreach ($default_prices as $price) { |
|
| 2174 | + if (! $price instanceof EE_Price) { |
|
| 2175 | + continue; |
|
| 2176 | + } |
|
| 2177 | + if ($price->is_base_price()) { |
|
| 2178 | + $template_args['default_base_price_amount'] = $price->get_pretty( |
|
| 2179 | + 'PRC_amount', |
|
| 2180 | + 'localized_float' |
|
| 2181 | + ); |
|
| 2182 | + $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
| 2183 | + $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
| 2184 | + $price_row++; |
|
| 2185 | + continue; |
|
| 2186 | + } |
|
| 2187 | + $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
| 2188 | + 'TICKETNUM', |
|
| 2189 | + $price_row, |
|
| 2190 | + $price, |
|
| 2191 | + true, |
|
| 2192 | + null, |
|
| 2193 | + // base prices are never displayed, so always show the trash button |
|
| 2194 | + true, |
|
| 2195 | + // show the add button on the last row only... |
|
| 2196 | + // modifier count starts at 1, but the base price is still in the prices array, |
|
| 2197 | + // so if we have two modifiers, then the last one is 2 but there are 3 prices, |
|
| 2198 | + // so the following would work out to: 2 === 3 -1 |
|
| 2199 | + $price_row === (count($default_prices) - 1) |
|
| 2200 | + ); |
|
| 2201 | + $price_row++; |
|
| 2202 | + } |
|
| 2203 | + $template_args = apply_filters( |
|
| 2204 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
| 2205 | + $template_args, |
|
| 2206 | + $all_datetimes, |
|
| 2207 | + $all_tickets, |
|
| 2208 | + $this->_is_creating_event |
|
| 2209 | + ); |
|
| 2210 | + return EEH_Template::display_template( |
|
| 2211 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
| 2212 | + $template_args, |
|
| 2213 | + true |
|
| 2214 | + ); |
|
| 2215 | + } |
|
| 2216 | 2216 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | ); |
| 151 | 151 | $msg .= '</p><ul>'; |
| 152 | 152 | foreach ($format_validation as $error) { |
| 153 | - $msg .= '<li>' . $error . '</li>'; |
|
| 153 | + $msg .= '<li>'.$error.'</li>'; |
|
| 154 | 154 | } |
| 155 | 155 | $msg .= '</ul><p>'; |
| 156 | 156 | $msg .= sprintf( |
@@ -179,11 +179,11 @@ discard block |
||
| 179 | 179 | $this->_scripts_styles = array( |
| 180 | 180 | 'registers' => array( |
| 181 | 181 | 'ee-tickets-datetimes-css' => array( |
| 182 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
| 182 | + 'url' => PRICING_ASSETS_URL.'event-tickets-datetimes.css', |
|
| 183 | 183 | 'type' => 'css', |
| 184 | 184 | ), |
| 185 | 185 | 'ee-dtt-ticket-metabox' => array( |
| 186 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
| 186 | + 'url' => PRICING_ASSETS_URL.'ee-datetime-ticket-metabox.js', |
|
| 187 | 187 | 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
| 188 | 188 | ), |
| 189 | 189 | ), |
@@ -207,9 +207,9 @@ discard block |
||
| 207 | 207 | 'event_espresso' |
| 208 | 208 | ), |
| 209 | 209 | 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
| 210 | - . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
| 210 | + . esc_html__('Cancel', 'event_espresso').'</button>', |
|
| 211 | 211 | 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
| 212 | - . esc_html__('Close', 'event_espresso') . '</button>', |
|
| 212 | + . esc_html__('Close', 'event_espresso').'</button>', |
|
| 213 | 213 | 'single_warning_from_tkt' => esc_html__( |
| 214 | 214 | 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
| 215 | 215 | 'event_espresso' |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | 'event_espresso' |
| 220 | 220 | ), |
| 221 | 221 | 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
| 222 | - . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
| 222 | + . esc_html__('Dismiss', 'event_espresso').'</button>', |
|
| 223 | 223 | ), |
| 224 | 224 | 'DTT_ERROR_MSG' => array( |
| 225 | 225 | 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | { |
| 258 | 258 | foreach ($update_callbacks as $key => $callback) { |
| 259 | 259 | if ($callback[1] === '_default_tickets_update') { |
| 260 | - unset($update_callbacks[ $key ]); |
|
| 260 | + unset($update_callbacks[$key]); |
|
| 261 | 261 | } |
| 262 | 262 | } |
| 263 | 263 | $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
| 316 | 316 | // trim all values to ensure any excess whitespace is removed. |
| 317 | 317 | $datetime_data = array_map( |
| 318 | - function ($datetime_data) { |
|
| 318 | + function($datetime_data) { |
|
| 319 | 319 | return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
| 320 | 320 | }, |
| 321 | 321 | $datetime_data |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | ); |
| 346 | 346 | // if we have an id then let's get existing object first and then set the new values. |
| 347 | 347 | // Otherwise we instantiate a new object for save. |
| 348 | - if (! empty($datetime_data['DTT_ID'])) { |
|
| 348 | + if ( ! empty($datetime_data['DTT_ID'])) { |
|
| 349 | 349 | $datetime = EE_Registry::instance() |
| 350 | 350 | ->load_model('Datetime', array($timezone)) |
| 351 | 351 | ->get_one_by_ID($datetime_data['DTT_ID']); |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | // after the add_relation_to() the autosave replaces it. |
| 360 | 360 | // We need to do this so we dont' TRASH the parent DTT. |
| 361 | 361 | // (save the ID for both key and value to avoid duplications) |
| 362 | - $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID(); |
|
| 362 | + $saved_dtt_ids[$datetime->ID()] = $datetime->ID(); |
|
| 363 | 363 | } else { |
| 364 | 364 | $datetime = EE_Registry::instance()->load_class( |
| 365 | 365 | 'Datetime', |
@@ -395,8 +395,8 @@ discard block |
||
| 395 | 395 | // because it is possible there was a new one created for the autosave. |
| 396 | 396 | // (save the ID for both key and value to avoid duplications) |
| 397 | 397 | $DTT_ID = $datetime->ID(); |
| 398 | - $saved_dtt_ids[ $DTT_ID ] = $DTT_ID; |
|
| 399 | - $saved_dtt_objs[ $row ] = $datetime; |
|
| 398 | + $saved_dtt_ids[$DTT_ID] = $DTT_ID; |
|
| 399 | + $saved_dtt_objs[$row] = $datetime; |
|
| 400 | 400 | // @todo if ANY of these updates fail then we want the appropriate global error message. |
| 401 | 401 | } |
| 402 | 402 | $event->save(); |
@@ -461,13 +461,13 @@ discard block |
||
| 461 | 461 | $update_prices = $create_new_TKT = false; |
| 462 | 462 | // figure out what datetimes were added to the ticket |
| 463 | 463 | // and what datetimes were removed from the ticket in the session. |
| 464 | - $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]); |
|
| 465 | - $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]); |
|
| 464 | + $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]); |
|
| 465 | + $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]); |
|
| 466 | 466 | $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
| 467 | 467 | $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
| 468 | 468 | // trim inputs to ensure any excess whitespace is removed. |
| 469 | 469 | $tkt = array_map( |
| 470 | - function ($ticket_data) { |
|
| 470 | + function($ticket_data) { |
|
| 471 | 471 | return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
| 472 | 472 | }, |
| 473 | 473 | $tkt |
@@ -489,8 +489,8 @@ discard block |
||
| 489 | 489 | $base_price_id = isset($tkt['TKT_base_price_ID']) |
| 490 | 490 | ? $tkt['TKT_base_price_ID'] |
| 491 | 491 | : 0; |
| 492 | - $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ]) |
|
| 493 | - ? $data['edit_prices'][ $row ] |
|
| 492 | + $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) |
|
| 493 | + ? $data['edit_prices'][$row] |
|
| 494 | 494 | : array(); |
| 495 | 495 | $now = null; |
| 496 | 496 | if (empty($tkt['TKT_start_date'])) { |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | /** |
| 503 | 503 | * set the TKT_end_date to the first datetime attached to the ticket. |
| 504 | 504 | */ |
| 505 | - $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ]; |
|
| 505 | + $first_dtt = $saved_datetimes[reset($tkt_dtt_rows)]; |
|
| 506 | 506 | $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
| 507 | 507 | } |
| 508 | 508 | $TKT_values = array( |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | // need to make sue that the TKT_price is accurate after saving the prices. |
| 638 | 638 | $ticket->ensure_TKT_Price_correct(); |
| 639 | 639 | // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
| 640 | - if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
| 640 | + if ( ! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
| 641 | 641 | $update_prices = true; |
| 642 | 642 | $new_default = clone $ticket; |
| 643 | 643 | $new_default->set('TKT_ID', 0); |
@@ -682,7 +682,7 @@ discard block |
||
| 682 | 682 | // save new TKT |
| 683 | 683 | $new_tkt->save(); |
| 684 | 684 | // add new ticket to array |
| 685 | - $saved_tickets[ $new_tkt->ID() ] = $new_tkt; |
|
| 685 | + $saved_tickets[$new_tkt->ID()] = $new_tkt; |
|
| 686 | 686 | do_action( |
| 687 | 687 | 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
| 688 | 688 | $new_tkt, |
@@ -692,7 +692,7 @@ discard block |
||
| 692 | 692 | ); |
| 693 | 693 | } else { |
| 694 | 694 | // add tkt to saved tkts |
| 695 | - $saved_tickets[ $ticket->ID() ] = $ticket; |
|
| 695 | + $saved_tickets[$ticket->ID()] = $ticket; |
|
| 696 | 696 | do_action( |
| 697 | 697 | 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
| 698 | 698 | $ticket, |
@@ -759,31 +759,31 @@ discard block |
||
| 759 | 759 | // to start we have to add the ticket to all the datetimes its supposed to be with, |
| 760 | 760 | // and removing the ticket from datetimes it got removed from. |
| 761 | 761 | // first let's add datetimes |
| 762 | - if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
| 762 | + if ( ! empty($added_datetimes) && is_array($added_datetimes)) { |
|
| 763 | 763 | foreach ($added_datetimes as $row_id) { |
| 764 | 764 | $row_id = (int) $row_id; |
| 765 | - if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
| 766 | - $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
| 765 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
| 766 | + $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
| 767 | 767 | // Is this an existing ticket (has an ID) and does it have any sold? |
| 768 | 768 | // If so, then we need to add that to the DTT sold because this DTT is getting added. |
| 769 | 769 | if ($ticket->ID() && $ticket->sold() > 0) { |
| 770 | - $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false); |
|
| 770 | + $saved_datetimes[$row_id]->increaseSold($ticket->sold(), false); |
|
| 771 | 771 | } |
| 772 | 772 | } |
| 773 | 773 | } |
| 774 | 774 | } |
| 775 | 775 | // then remove datetimes |
| 776 | - if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
| 776 | + if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
| 777 | 777 | foreach ($removed_datetimes as $row_id) { |
| 778 | 778 | $row_id = (int) $row_id; |
| 779 | 779 | // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
| 780 | 780 | // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
| 781 | - if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
| 782 | - $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
| 781 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
| 782 | + $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
| 783 | 783 | // Is this an existing ticket (has an ID) and does it have any sold? |
| 784 | 784 | // If so, then we need to remove it's sold from the DTT_sold. |
| 785 | 785 | if ($ticket->ID() && $ticket->sold() > 0) { |
| 786 | - $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold()); |
|
| 786 | + $saved_datetimes[$row_id]->decreaseSold($ticket->sold()); |
|
| 787 | 787 | } |
| 788 | 788 | } |
| 789 | 789 | } |
@@ -896,7 +896,7 @@ discard block |
||
| 896 | 896 | ); |
| 897 | 897 | } |
| 898 | 898 | // possibly need to save tkt |
| 899 | - if (! $ticket->ID()) { |
|
| 899 | + if ( ! $ticket->ID()) { |
|
| 900 | 900 | $ticket->save(); |
| 901 | 901 | } |
| 902 | 902 | foreach ($prices as $row => $prc) { |
@@ -930,17 +930,17 @@ discard block |
||
| 930 | 930 | } |
| 931 | 931 | } |
| 932 | 932 | $price->save(); |
| 933 | - $updated_prices[ $price->ID() ] = $price; |
|
| 933 | + $updated_prices[$price->ID()] = $price; |
|
| 934 | 934 | $ticket->_add_relation_to($price, 'Price'); |
| 935 | 935 | } |
| 936 | 936 | // now let's remove any prices that got removed from the ticket |
| 937 | - if (! empty($current_prices_on_ticket)) { |
|
| 937 | + if ( ! empty($current_prices_on_ticket)) { |
|
| 938 | 938 | $current = array_keys($current_prices_on_ticket); |
| 939 | 939 | $updated = array_keys($updated_prices); |
| 940 | 940 | $prices_to_remove = array_diff($current, $updated); |
| 941 | - if (! empty($prices_to_remove)) { |
|
| 941 | + if ( ! empty($prices_to_remove)) { |
|
| 942 | 942 | foreach ($prices_to_remove as $prc_id) { |
| 943 | - $p = $current_prices_on_ticket[ $prc_id ]; |
|
| 943 | + $p = $current_prices_on_ticket[$prc_id]; |
|
| 944 | 944 | $ticket->_remove_relation_to($p, 'Price'); |
| 945 | 945 | // delete permanently the price |
| 946 | 946 | $p->delete_permanently(); |
@@ -1091,18 +1091,18 @@ discard block |
||
| 1091 | 1091 | $TKT_ID = $ticket->get('TKT_ID'); |
| 1092 | 1092 | $ticket_row = $ticket->get('TKT_row'); |
| 1093 | 1093 | // we only want unique tickets in our final display!! |
| 1094 | - if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
| 1094 | + if ( ! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
| 1095 | 1095 | $existing_ticket_ids[] = $TKT_ID; |
| 1096 | 1096 | $all_tickets[] = $ticket; |
| 1097 | 1097 | } |
| 1098 | 1098 | // temporary cache of this ticket info for this datetime for later processing of datetime rows. |
| 1099 | - $datetime_tickets[ $DTT_ID ][] = $ticket_row; |
|
| 1099 | + $datetime_tickets[$DTT_ID][] = $ticket_row; |
|
| 1100 | 1100 | // temporary cache of this datetime info for this ticket for later processing of ticket rows. |
| 1101 | 1101 | if ( |
| 1102 | - ! isset($ticket_datetimes[ $TKT_ID ]) |
|
| 1103 | - || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true) |
|
| 1102 | + ! isset($ticket_datetimes[$TKT_ID]) |
|
| 1103 | + || ! in_array($datetime_row, $ticket_datetimes[$TKT_ID], true) |
|
| 1104 | 1104 | ) { |
| 1105 | - $ticket_datetimes[ $TKT_ID ][] = $datetime_row; |
|
| 1105 | + $ticket_datetimes[$TKT_ID][] = $datetime_row; |
|
| 1106 | 1106 | } |
| 1107 | 1107 | } |
| 1108 | 1108 | $datetime_row++; |
@@ -1113,7 +1113,7 @@ discard block |
||
| 1113 | 1113 | // sort $all_tickets by order |
| 1114 | 1114 | usort( |
| 1115 | 1115 | $all_tickets, |
| 1116 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
| 1116 | + function(EE_Ticket $a, EE_Ticket $b) { |
|
| 1117 | 1117 | $a_order = (int) $a->get('TKT_order'); |
| 1118 | 1118 | $b_order = (int) $b->get('TKT_order'); |
| 1119 | 1119 | if ($a_order === $b_order) { |
@@ -1151,7 +1151,7 @@ discard block |
||
| 1151 | 1151 | } |
| 1152 | 1152 | $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
| 1153 | 1153 | EEH_Template::display_template( |
| 1154 | - PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
| 1154 | + PRICING_TEMPLATE_PATH.'event_tickets_metabox_main.template.php', |
|
| 1155 | 1155 | $main_template_args |
| 1156 | 1156 | ); |
| 1157 | 1157 | } |
@@ -1193,7 +1193,7 @@ discard block |
||
| 1193 | 1193 | 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
| 1194 | 1194 | ); |
| 1195 | 1195 | return EEH_Template::display_template( |
| 1196 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
| 1196 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_row_wrapper.template.php', |
|
| 1197 | 1197 | $dtt_display_template_args, |
| 1198 | 1198 | true |
| 1199 | 1199 | ); |
@@ -1262,7 +1262,7 @@ discard block |
||
| 1262 | 1262 | $this->_is_creating_event |
| 1263 | 1263 | ); |
| 1264 | 1264 | return EEH_Template::display_template( |
| 1265 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
| 1265 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_edit_row.template.php', |
|
| 1266 | 1266 | $template_args, |
| 1267 | 1267 | true |
| 1268 | 1268 | ); |
@@ -1303,7 +1303,7 @@ discard block |
||
| 1303 | 1303 | 'DTT_ID' => $default ? '' : $datetime->ID(), |
| 1304 | 1304 | ); |
| 1305 | 1305 | // need to setup the list items (but only if this isn't a default skeleton setup) |
| 1306 | - if (! $default) { |
|
| 1306 | + if ( ! $default) { |
|
| 1307 | 1307 | $ticket_row = 1; |
| 1308 | 1308 | foreach ($all_tickets as $ticket) { |
| 1309 | 1309 | $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
@@ -1329,7 +1329,7 @@ discard block |
||
| 1329 | 1329 | $this->_is_creating_event |
| 1330 | 1330 | ); |
| 1331 | 1331 | return EEH_Template::display_template( |
| 1332 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
| 1332 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_attached_tickets_row.template.php', |
|
| 1333 | 1333 | $template_args, |
| 1334 | 1334 | true |
| 1335 | 1335 | ); |
@@ -1355,8 +1355,8 @@ discard block |
||
| 1355 | 1355 | $datetime_tickets = array(), |
| 1356 | 1356 | $default |
| 1357 | 1357 | ) { |
| 1358 | - $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ]) |
|
| 1359 | - ? $datetime_tickets[ $datetime->ID() ] |
|
| 1358 | + $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[$datetime->ID()]) |
|
| 1359 | + ? $datetime_tickets[$datetime->ID()] |
|
| 1360 | 1360 | : array(); |
| 1361 | 1361 | $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
| 1362 | 1362 | $no_ticket = $default && empty($ticket); |
@@ -1377,8 +1377,8 @@ discard block |
||
| 1377 | 1377 | ? 'TKTNAME' |
| 1378 | 1378 | : $ticket->get('TKT_name'), |
| 1379 | 1379 | 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
| 1380 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1381 | - : ' tkt-status-' . $ticket->ticket_status(), |
|
| 1380 | + ? ' tkt-status-'.EE_Ticket::onsale |
|
| 1381 | + : ' tkt-status-'.$ticket->ticket_status(), |
|
| 1382 | 1382 | ); |
| 1383 | 1383 | // filter template args |
| 1384 | 1384 | $template_args = apply_filters( |
@@ -1393,7 +1393,7 @@ discard block |
||
| 1393 | 1393 | $this->_is_creating_event |
| 1394 | 1394 | ); |
| 1395 | 1395 | return EEH_Template::display_template( |
| 1396 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
| 1396 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_dtt_tickets_list.template.php', |
|
| 1397 | 1397 | $template_args, |
| 1398 | 1398 | true |
| 1399 | 1399 | ); |
@@ -1449,19 +1449,19 @@ discard block |
||
| 1449 | 1449 | // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
| 1450 | 1450 | // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
| 1451 | 1451 | $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default()); |
| 1452 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
| 1453 | - ? $ticket_datetimes[ $ticket->ID() ] |
|
| 1452 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
| 1453 | + ? $ticket_datetimes[$ticket->ID()] |
|
| 1454 | 1454 | : array(); |
| 1455 | 1455 | $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
| 1456 | 1456 | $base_price = $default ? null : $ticket->base_price(); |
| 1457 | 1457 | $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
| 1458 | 1458 | // breaking out complicated condition for ticket_status |
| 1459 | 1459 | if ($default) { |
| 1460 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1460 | + $ticket_status_class = ' tkt-status-'.EE_Ticket::onsale; |
|
| 1461 | 1461 | } else { |
| 1462 | 1462 | $ticket_status_class = $ticket->is_default() |
| 1463 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1464 | - : ' tkt-status-' . $ticket->ticket_status(); |
|
| 1463 | + ? ' tkt-status-'.EE_Ticket::onsale |
|
| 1464 | + : ' tkt-status-'.$ticket->ticket_status(); |
|
| 1465 | 1465 | } |
| 1466 | 1466 | // breaking out complicated condition for TKT_taxable |
| 1467 | 1467 | if ($default) { |
@@ -1553,7 +1553,7 @@ discard block |
||
| 1553 | 1553 | : ' style="display:none;"', |
| 1554 | 1554 | 'show_price_mod_button' => count($prices) > 1 |
| 1555 | 1555 | || ($default && $count_price_mods > 0) |
| 1556 | - || (! $default && $ticket->deleted()) |
|
| 1556 | + || ( ! $default && $ticket->deleted()) |
|
| 1557 | 1557 | ? ' style="display:none;"' |
| 1558 | 1558 | : '', |
| 1559 | 1559 | 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
@@ -1597,7 +1597,7 @@ discard block |
||
| 1597 | 1597 | $this->_date_time_format, |
| 1598 | 1598 | current_time('timestamp') |
| 1599 | 1599 | ); |
| 1600 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1600 | + $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale; |
|
| 1601 | 1601 | } |
| 1602 | 1602 | if (empty($template_args['TKT_end_date'])) { |
| 1603 | 1603 | // get the earliest datetime (if present); |
@@ -1607,7 +1607,7 @@ discard block |
||
| 1607 | 1607 | array('order_by' => array('DTT_EVT_start' => 'ASC')) |
| 1608 | 1608 | ) |
| 1609 | 1609 | : null; |
| 1610 | - if (! empty($earliest_dtt)) { |
|
| 1610 | + if ( ! empty($earliest_dtt)) { |
|
| 1611 | 1611 | $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
| 1612 | 1612 | 'DTT_EVT_start', |
| 1613 | 1613 | $this->_date_time_format |
@@ -1626,10 +1626,10 @@ discard block |
||
| 1626 | 1626 | ) |
| 1627 | 1627 | ); |
| 1628 | 1628 | } |
| 1629 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1629 | + $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale; |
|
| 1630 | 1630 | } |
| 1631 | 1631 | // generate ticket_datetime items |
| 1632 | - if (! $default) { |
|
| 1632 | + if ( ! $default) { |
|
| 1633 | 1633 | $datetime_row = 1; |
| 1634 | 1634 | foreach ($all_datetimes as $datetime) { |
| 1635 | 1635 | $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
@@ -1645,7 +1645,7 @@ discard block |
||
| 1645 | 1645 | } |
| 1646 | 1646 | $price_row = 0; |
| 1647 | 1647 | foreach ($prices as $price) { |
| 1648 | - if (! $price instanceof EE_Price) { |
|
| 1648 | + if ( ! $price instanceof EE_Price) { |
|
| 1649 | 1649 | continue; |
| 1650 | 1650 | } |
| 1651 | 1651 | if ($price->is_base_price()) { |
@@ -1681,7 +1681,7 @@ discard block |
||
| 1681 | 1681 | $this->_is_creating_event |
| 1682 | 1682 | ); |
| 1683 | 1683 | return EEH_Template::display_template( |
| 1684 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
| 1684 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_row.template.php', |
|
| 1685 | 1685 | $template_args, |
| 1686 | 1686 | true |
| 1687 | 1687 | ); |
@@ -1721,7 +1721,7 @@ discard block |
||
| 1721 | 1721 | $this->_is_creating_event |
| 1722 | 1722 | ); |
| 1723 | 1723 | $tax_rows .= EEH_Template::display_template( |
| 1724 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
| 1724 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_tax_row.template.php', |
|
| 1725 | 1725 | $template_args, |
| 1726 | 1726 | true |
| 1727 | 1727 | ); |
@@ -1841,7 +1841,7 @@ discard block |
||
| 1841 | 1841 | $this->_is_creating_event |
| 1842 | 1842 | ); |
| 1843 | 1843 | return EEH_Template::display_template( |
| 1844 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
| 1844 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_price_row.template.php', |
|
| 1845 | 1845 | $template_args, |
| 1846 | 1846 | true |
| 1847 | 1847 | ); |
@@ -1911,7 +1911,7 @@ discard block |
||
| 1911 | 1911 | $this->_is_creating_event |
| 1912 | 1912 | ); |
| 1913 | 1913 | return EEH_Template::display_template( |
| 1914 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
| 1914 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_type_base.template.php', |
|
| 1915 | 1915 | $template_args, |
| 1916 | 1916 | true |
| 1917 | 1917 | ); |
@@ -1941,7 +1941,7 @@ discard block |
||
| 1941 | 1941 | ) { |
| 1942 | 1942 | $select_name = $default && ! $price instanceof EE_Price |
| 1943 | 1943 | ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
| 1944 | - : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
| 1944 | + : 'edit_prices['.$ticket_row.']['.$price_row.'][PRT_ID]'; |
|
| 1945 | 1945 | /** @var EEM_Price_Type $price_type_model */ |
| 1946 | 1946 | $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
| 1947 | 1947 | $price_types = $price_type_model->get_all([['PBT_ID' => ['!=', 1]]]); |
@@ -1952,10 +1952,10 @@ discard block |
||
| 1952 | 1952 | $price_option_spans = ''; |
| 1953 | 1953 | // setup price types for selector |
| 1954 | 1954 | foreach ($price_types as $price_type) { |
| 1955 | - if (! $price_type instanceof EE_Price_Type) { |
|
| 1955 | + if ( ! $price_type instanceof EE_Price_Type) { |
|
| 1956 | 1956 | continue; |
| 1957 | 1957 | } |
| 1958 | - $all_price_types[ $price_type->ID() ] = $price_type->name(); |
|
| 1958 | + $all_price_types[$price_type->ID()] = $price_type->name(); |
|
| 1959 | 1959 | // while we're in the loop let's setup the option spans used by js |
| 1960 | 1960 | $span_args = array( |
| 1961 | 1961 | 'PRT_ID' => $price_type->ID(), |
@@ -1963,12 +1963,12 @@ discard block |
||
| 1963 | 1963 | 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
| 1964 | 1964 | ); |
| 1965 | 1965 | $price_option_spans .= EEH_Template::display_template( |
| 1966 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
| 1966 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_option_span.template.php', |
|
| 1967 | 1967 | $span_args, |
| 1968 | 1968 | true |
| 1969 | 1969 | ); |
| 1970 | 1970 | } |
| 1971 | - $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' |
|
| 1971 | + $select_name = $disabled ? 'archive_price['.$ticket_row.']['.$price_row.'][PRT_ID]' |
|
| 1972 | 1972 | : $select_name; |
| 1973 | 1973 | $select_input = new EE_Select_Input( |
| 1974 | 1974 | $all_price_types, |
@@ -2006,7 +2006,7 @@ discard block |
||
| 2006 | 2006 | $this->_is_creating_event |
| 2007 | 2007 | ); |
| 2008 | 2008 | return EEH_Template::display_template( |
| 2009 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
| 2009 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_modifier_selector.template.php', |
|
| 2010 | 2010 | $template_args, |
| 2011 | 2011 | true |
| 2012 | 2012 | ); |
@@ -2032,8 +2032,8 @@ discard block |
||
| 2032 | 2032 | $ticket_datetimes = array(), |
| 2033 | 2033 | $default |
| 2034 | 2034 | ) { |
| 2035 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
| 2036 | - ? $ticket_datetimes[ $ticket->ID() ] |
|
| 2035 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
| 2036 | + ? $ticket_datetimes[$ticket->ID()] |
|
| 2037 | 2037 | : array(); |
| 2038 | 2038 | $template_args = array( |
| 2039 | 2039 | 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
@@ -2065,7 +2065,7 @@ discard block |
||
| 2065 | 2065 | $this->_is_creating_event |
| 2066 | 2066 | ); |
| 2067 | 2067 | return EEH_Template::display_template( |
| 2068 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
| 2068 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
| 2069 | 2069 | $template_args, |
| 2070 | 2070 | true |
| 2071 | 2071 | ); |
@@ -2171,7 +2171,7 @@ discard block |
||
| 2171 | 2171 | $default_prices = $price_model->get_all_default_prices(); |
| 2172 | 2172 | $price_row = 0; |
| 2173 | 2173 | foreach ($default_prices as $price) { |
| 2174 | - if (! $price instanceof EE_Price) { |
|
| 2174 | + if ( ! $price instanceof EE_Price) { |
|
| 2175 | 2175 | continue; |
| 2176 | 2176 | } |
| 2177 | 2177 | if ($price->is_base_price()) { |
@@ -2208,7 +2208,7 @@ discard block |
||
| 2208 | 2208 | $this->_is_creating_event |
| 2209 | 2209 | ); |
| 2210 | 2210 | return EEH_Template::display_template( |
| 2211 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
| 2211 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_js_structure.template.php', |
|
| 2212 | 2212 | $template_args, |
| 2213 | 2213 | true |
| 2214 | 2214 | ); |
@@ -68,9 +68,12 @@ discard block |
||
| 68 | 68 | <input type="text" size="1" class="edit-price-PRC_amount ee-numeric" |
| 69 | 69 | name="prices_archive[<?php echo $tkt_row; ?>][<?php echo $PRC_order; ?>][PRC_amount]" |
| 70 | 70 | value="<?php echo $PRC_amount; ?>" disabled> |
| 71 | - <?php else : ?> |
|
| 71 | + <?php else { |
|
| 72 | + : ?> |
|
| 72 | 73 | <input type="text" size="1" class="edit-price-PRC_amount ee-numeric" |
| 73 | - name="<?php echo $edit_prices_name; ?>[<?php echo $tkt_row; ?>][<?php echo $PRC_order; ?>][PRC_amount]" |
|
| 74 | + name="<?php echo $edit_prices_name; |
|
| 75 | +} |
|
| 76 | +?>[<?php echo $tkt_row; ?>][<?php echo $PRC_order; ?>][PRC_amount]" |
|
| 74 | 77 | value="<?php echo $PRC_amount; ?>"> |
| 75 | 78 | <?php endif; ?> |
| 76 | 79 | </td> |
@@ -82,10 +85,13 @@ discard block |
||
| 82 | 85 | <td class='ticket-price-col-micro'> |
| 83 | 86 | <?php if ($disabled) : ?> |
| 84 | 87 | <span class="ee-lock-icon"></span> |
| 85 | - <?php else : ?> |
|
| 88 | + <?php else { |
|
| 89 | + : ?> |
|
| 86 | 90 | <div class="ticket-price-actions"> |
| 87 | 91 | <button class="trash-icon ee-trash-button button-secondary clickable" |
| 88 | - data-ticket-row="<?php echo $tkt_row; ?>" |
|
| 92 | + data-ticket-row="<?php echo $tkt_row; |
|
| 93 | +} |
|
| 94 | +?>" |
|
| 89 | 95 | data-context="price" |
| 90 | 96 | data-price-row="<?php echo $PRC_order; ?>" |
| 91 | 97 | <?php echo $show_trash_icon; ?> |
@@ -15,955 +15,955 @@ |
||
| 15 | 15 | class EEM_Event extends EEM_CPT_Base |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
| 20 | - * event |
|
| 21 | - */ |
|
| 22 | - const sold_out = 'sold_out'; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
| 26 | - * date) |
|
| 27 | - */ |
|
| 28 | - const postponed = 'postponed'; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * constant used by status(), indicating that the event will no longer occur |
|
| 32 | - */ |
|
| 33 | - const cancelled = 'cancelled'; |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - protected static $_default_reg_status; |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * This is the default for the additional limit field. |
|
| 44 | - * @var int |
|
| 45 | - */ |
|
| 46 | - protected static $_default_additional_limit = 10; |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * private instance of the Event object |
|
| 51 | - * |
|
| 52 | - * @var EEM_Event |
|
| 53 | - */ |
|
| 54 | - protected static $_instance; |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
| 61 | - * |
|
| 62 | - * @param string $timezone |
|
| 63 | - * @throws \EE_Error |
|
| 64 | - */ |
|
| 65 | - protected function __construct($timezone = null) |
|
| 66 | - { |
|
| 67 | - EE_Registry::instance()->load_model('Registration'); |
|
| 68 | - $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
| 69 | - $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
| 70 | - // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
| 71 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
| 72 | - // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
| 73 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
| 74 | - // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
| 75 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
| 76 | - $this->_custom_stati = apply_filters( |
|
| 77 | - 'AFEE__EEM_Event__construct___custom_stati', |
|
| 78 | - array( |
|
| 79 | - EEM_Event::cancelled => array( |
|
| 80 | - 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
| 81 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
| 82 | - ), |
|
| 83 | - EEM_Event::postponed => array( |
|
| 84 | - 'label' => esc_html__('Postponed', 'event_espresso'), |
|
| 85 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
| 86 | - ), |
|
| 87 | - EEM_Event::sold_out => array( |
|
| 88 | - 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
| 89 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
| 90 | - ), |
|
| 91 | - ) |
|
| 92 | - ); |
|
| 93 | - self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
| 94 | - : self::$_default_reg_status; |
|
| 95 | - $this->_tables = array( |
|
| 96 | - 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
| 97 | - 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
| 98 | - ); |
|
| 99 | - $this->_fields = array( |
|
| 100 | - 'Event_CPT' => array( |
|
| 101 | - 'EVT_ID' => new EE_Primary_Key_Int_Field( |
|
| 102 | - 'ID', |
|
| 103 | - esc_html__('Post ID for Event', 'event_espresso') |
|
| 104 | - ), |
|
| 105 | - 'EVT_name' => new EE_Plain_Text_Field( |
|
| 106 | - 'post_title', |
|
| 107 | - esc_html__('Event Name', 'event_espresso'), |
|
| 108 | - false, |
|
| 109 | - '' |
|
| 110 | - ), |
|
| 111 | - 'EVT_desc' => new EE_Post_Content_Field( |
|
| 112 | - 'post_content', |
|
| 113 | - esc_html__('Event Description', 'event_espresso'), |
|
| 114 | - false, |
|
| 115 | - '' |
|
| 116 | - ), |
|
| 117 | - 'EVT_slug' => new EE_Slug_Field( |
|
| 118 | - 'post_name', |
|
| 119 | - esc_html__('Event Slug', 'event_espresso'), |
|
| 120 | - false, |
|
| 121 | - '' |
|
| 122 | - ), |
|
| 123 | - 'EVT_created' => new EE_Datetime_Field( |
|
| 124 | - 'post_date', |
|
| 125 | - esc_html__('Date/Time Event Created', 'event_espresso'), |
|
| 126 | - false, |
|
| 127 | - EE_Datetime_Field::now |
|
| 128 | - ), |
|
| 129 | - 'EVT_short_desc' => new EE_Simple_HTML_Field( |
|
| 130 | - 'post_excerpt', |
|
| 131 | - esc_html__('Event Short Description', 'event_espresso'), |
|
| 132 | - false, |
|
| 133 | - '' |
|
| 134 | - ), |
|
| 135 | - 'EVT_modified' => new EE_Datetime_Field( |
|
| 136 | - 'post_modified', |
|
| 137 | - esc_html__('Date/Time Event Modified', 'event_espresso'), |
|
| 138 | - false, |
|
| 139 | - EE_Datetime_Field::now |
|
| 140 | - ), |
|
| 141 | - 'EVT_wp_user' => new EE_WP_User_Field( |
|
| 142 | - 'post_author', |
|
| 143 | - esc_html__('Event Creator ID', 'event_espresso'), |
|
| 144 | - false |
|
| 145 | - ), |
|
| 146 | - 'parent' => new EE_Integer_Field( |
|
| 147 | - 'post_parent', |
|
| 148 | - esc_html__('Event Parent ID', 'event_espresso'), |
|
| 149 | - false, |
|
| 150 | - 0 |
|
| 151 | - ), |
|
| 152 | - 'EVT_order' => new EE_Integer_Field( |
|
| 153 | - 'menu_order', |
|
| 154 | - esc_html__('Event Menu Order', 'event_espresso'), |
|
| 155 | - false, |
|
| 156 | - 1 |
|
| 157 | - ), |
|
| 158 | - 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
| 159 | - // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
| 160 | - 'status' => new EE_WP_Post_Status_Field( |
|
| 161 | - 'post_status', |
|
| 162 | - esc_html__('Event Status', 'event_espresso'), |
|
| 163 | - false, |
|
| 164 | - 'draft', |
|
| 165 | - $this->_custom_stati |
|
| 166 | - ), |
|
| 167 | - 'password' => new EE_Password_Field( |
|
| 168 | - 'post_password', |
|
| 169 | - esc_html__('Password', 'event_espresso'), |
|
| 170 | - false, |
|
| 171 | - '', |
|
| 172 | - array( |
|
| 173 | - 'EVT_desc', |
|
| 174 | - 'EVT_short_desc', |
|
| 175 | - 'EVT_display_desc', |
|
| 176 | - 'EVT_display_ticket_selector', |
|
| 177 | - 'EVT_visible_on', |
|
| 178 | - 'EVT_additional_limit', |
|
| 179 | - 'EVT_default_registration_status', |
|
| 180 | - 'EVT_member_only', |
|
| 181 | - 'EVT_phone', |
|
| 182 | - 'EVT_allow_overflow', |
|
| 183 | - 'EVT_timezone_string', |
|
| 184 | - 'EVT_external_URL', |
|
| 185 | - 'EVT_donations' |
|
| 186 | - ) |
|
| 187 | - ) |
|
| 188 | - ), |
|
| 189 | - 'Event_Meta' => array( |
|
| 190 | - 'EVTM_ID' => new EE_DB_Only_Float_Field( |
|
| 191 | - 'EVTM_ID', |
|
| 192 | - esc_html__('Event Meta Row ID', 'event_espresso'), |
|
| 193 | - false |
|
| 194 | - ), |
|
| 195 | - 'EVT_ID_fk' => new EE_DB_Only_Int_Field( |
|
| 196 | - 'EVT_ID', |
|
| 197 | - esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), |
|
| 198 | - false |
|
| 199 | - ), |
|
| 200 | - 'EVT_display_desc' => new EE_Boolean_Field( |
|
| 201 | - 'EVT_display_desc', |
|
| 202 | - esc_html__('Display Description Flag', 'event_espresso'), |
|
| 203 | - false, |
|
| 204 | - true |
|
| 205 | - ), |
|
| 206 | - 'EVT_display_ticket_selector' => new EE_Boolean_Field( |
|
| 207 | - 'EVT_display_ticket_selector', |
|
| 208 | - esc_html__('Display Ticket Selector Flag', 'event_espresso'), |
|
| 209 | - false, |
|
| 210 | - true |
|
| 211 | - ), |
|
| 212 | - 'EVT_visible_on' => new EE_Datetime_Field( |
|
| 213 | - 'EVT_visible_on', |
|
| 214 | - esc_html__('Event Visible Date', 'event_espresso'), |
|
| 215 | - true, |
|
| 216 | - EE_Datetime_Field::now |
|
| 217 | - ), |
|
| 218 | - 'EVT_additional_limit' => new EE_Integer_Field( |
|
| 219 | - 'EVT_additional_limit', |
|
| 220 | - esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
| 221 | - true, |
|
| 222 | - self::$_default_additional_limit |
|
| 223 | - ), |
|
| 224 | - 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
| 225 | - 'EVT_default_registration_status', |
|
| 226 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
| 227 | - false, |
|
| 228 | - EEM_Event::$_default_reg_status, |
|
| 229 | - EEM_Registration::reg_status_array() |
|
| 230 | - ), |
|
| 231 | - 'EVT_member_only' => new EE_Boolean_Field( |
|
| 232 | - 'EVT_member_only', |
|
| 233 | - esc_html__('Member-Only Event Flag', 'event_espresso'), |
|
| 234 | - false, |
|
| 235 | - false |
|
| 236 | - ), |
|
| 237 | - 'EVT_phone' => new EE_Plain_Text_Field( |
|
| 238 | - 'EVT_phone', |
|
| 239 | - esc_html__('Event Phone Number', 'event_espresso'), |
|
| 240 | - false, |
|
| 241 | - '' |
|
| 242 | - ), |
|
| 243 | - 'EVT_allow_overflow' => new EE_Boolean_Field( |
|
| 244 | - 'EVT_allow_overflow', |
|
| 245 | - esc_html__('Allow Overflow on Event', 'event_espresso'), |
|
| 246 | - false, |
|
| 247 | - false |
|
| 248 | - ), |
|
| 249 | - 'EVT_timezone_string' => new EE_Plain_Text_Field( |
|
| 250 | - 'EVT_timezone_string', |
|
| 251 | - esc_html__('Timezone (name) for Event times', 'event_espresso'), |
|
| 252 | - false, |
|
| 253 | - '' |
|
| 254 | - ), |
|
| 255 | - 'EVT_external_URL' => new EE_Plain_Text_Field( |
|
| 256 | - 'EVT_external_URL', |
|
| 257 | - esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), |
|
| 258 | - true |
|
| 259 | - ), |
|
| 260 | - 'EVT_donations' => new EE_Boolean_Field( |
|
| 261 | - 'EVT_donations', |
|
| 262 | - esc_html__('Accept Donations?', 'event_espresso'), |
|
| 263 | - false, |
|
| 264 | - false |
|
| 265 | - ), |
|
| 266 | - ), |
|
| 267 | - ); |
|
| 268 | - $this->_model_relations = array( |
|
| 269 | - 'Registration' => new EE_Has_Many_Relation(), |
|
| 270 | - 'Datetime' => new EE_Has_Many_Relation(), |
|
| 271 | - 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
| 272 | - 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
| 273 | - 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
| 274 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
| 275 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
| 276 | - 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
| 277 | - 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
| 278 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 279 | - ); |
|
| 280 | - // this model is generally available for reading |
|
| 281 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 282 | - $this->model_chain_to_password = ''; |
|
| 283 | - parent::__construct($timezone); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * @param string $default_reg_status |
|
| 290 | - */ |
|
| 291 | - public static function set_default_reg_status($default_reg_status) |
|
| 292 | - { |
|
| 293 | - self::$_default_reg_status = $default_reg_status; |
|
| 294 | - // if EEM_Event has already been instantiated, |
|
| 295 | - // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
| 296 | - if (self::$_instance instanceof EEM_Event) { |
|
| 297 | - $default_reg_status = new EE_Enum_Text_Field( |
|
| 298 | - 'EVT_default_registration_status', |
|
| 299 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
| 300 | - false, |
|
| 301 | - $default_reg_status, |
|
| 302 | - EEM_Registration::reg_status_array() |
|
| 303 | - ); |
|
| 304 | - $default_reg_status->_construct_finalize( |
|
| 305 | - 'Event_Meta', |
|
| 306 | - 'EVT_default_registration_status', |
|
| 307 | - 'EEM_Event' |
|
| 308 | - ); |
|
| 309 | - self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * Used to override the default for the additional limit field. |
|
| 316 | - * @param $additional_limit |
|
| 317 | - */ |
|
| 318 | - public static function set_default_additional_limit($additional_limit) |
|
| 319 | - { |
|
| 320 | - self::$_default_additional_limit = (int) $additional_limit; |
|
| 321 | - if (self::$_instance instanceof EEM_Event) { |
|
| 322 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
| 323 | - 'EVT_additional_limit', |
|
| 324 | - esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
| 325 | - true, |
|
| 326 | - self::$_default_additional_limit |
|
| 327 | - ); |
|
| 328 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
| 329 | - 'Event_Meta', |
|
| 330 | - 'EVT_additional_limit', |
|
| 331 | - 'EEM_Event' |
|
| 332 | - ); |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * Return what is currently set as the default additional limit for the event. |
|
| 339 | - * @return int |
|
| 340 | - */ |
|
| 341 | - public static function get_default_additional_limit() |
|
| 342 | - { |
|
| 343 | - return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * get_question_groups |
|
| 349 | - * |
|
| 350 | - * @return array |
|
| 351 | - * @throws \EE_Error |
|
| 352 | - */ |
|
| 353 | - public function get_all_question_groups() |
|
| 354 | - { |
|
| 355 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
| 356 | - array( |
|
| 357 | - array('QSG_deleted' => false), |
|
| 358 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
| 359 | - ) |
|
| 360 | - ); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * get_question_groups |
|
| 367 | - * |
|
| 368 | - * @param int $EVT_ID |
|
| 369 | - * @return array|bool |
|
| 370 | - * @throws \EE_Error |
|
| 371 | - */ |
|
| 372 | - public function get_all_event_question_groups($EVT_ID = 0) |
|
| 373 | - { |
|
| 374 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 375 | - EE_Error::add_error( |
|
| 376 | - esc_html__( |
|
| 377 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
| 378 | - 'event_espresso' |
|
| 379 | - ), |
|
| 380 | - __FILE__, |
|
| 381 | - __FUNCTION__, |
|
| 382 | - __LINE__ |
|
| 383 | - ); |
|
| 384 | - return false; |
|
| 385 | - } |
|
| 386 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
| 387 | - array( |
|
| 388 | - array('EVT_ID' => $EVT_ID), |
|
| 389 | - ) |
|
| 390 | - ); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * get_question_groups |
|
| 396 | - * |
|
| 397 | - * @param int $EVT_ID |
|
| 398 | - * @param boolean $for_primary_attendee |
|
| 399 | - * @return array|bool |
|
| 400 | - * @throws EE_Error |
|
| 401 | - * @throws InvalidArgumentException |
|
| 402 | - * @throws ReflectionException |
|
| 403 | - * @throws InvalidDataTypeException |
|
| 404 | - * @throws InvalidInterfaceException |
|
| 405 | - */ |
|
| 406 | - public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
| 407 | - { |
|
| 408 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 409 | - EE_Error::add_error( |
|
| 410 | - esc_html__( |
|
| 411 | - // @codingStandardsIgnoreStart |
|
| 412 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
| 413 | - // @codingStandardsIgnoreEnd |
|
| 414 | - 'event_espresso' |
|
| 415 | - ), |
|
| 416 | - __FILE__, |
|
| 417 | - __FUNCTION__, |
|
| 418 | - __LINE__ |
|
| 419 | - ); |
|
| 420 | - return false; |
|
| 421 | - } |
|
| 422 | - $query_params = [ |
|
| 423 | - [ |
|
| 424 | - 'EVT_ID' => $EVT_ID, |
|
| 425 | - EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true |
|
| 426 | - ] |
|
| 427 | - ]; |
|
| 428 | - if ($for_primary_attendee) { |
|
| 429 | - $query_params[0]['EQG_primary'] = true; |
|
| 430 | - } else { |
|
| 431 | - $query_params[0]['EQG_additional'] = true; |
|
| 432 | - } |
|
| 433 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * get_question_groups |
|
| 439 | - * |
|
| 440 | - * @param int $EVT_ID |
|
| 441 | - * @param EE_Registration $registration |
|
| 442 | - * @return array|bool |
|
| 443 | - * @throws EE_Error |
|
| 444 | - * @throws InvalidArgumentException |
|
| 445 | - * @throws InvalidDataTypeException |
|
| 446 | - * @throws InvalidInterfaceException |
|
| 447 | - * @throws ReflectionException |
|
| 448 | - */ |
|
| 449 | - public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
| 450 | - { |
|
| 451 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 452 | - EE_Error::add_error( |
|
| 453 | - esc_html__( |
|
| 454 | - 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
| 455 | - 'event_espresso' |
|
| 456 | - ), |
|
| 457 | - __FILE__, |
|
| 458 | - __FUNCTION__, |
|
| 459 | - __LINE__ |
|
| 460 | - ); |
|
| 461 | - return false; |
|
| 462 | - } |
|
| 463 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
| 464 | - [ |
|
| 465 | - [ |
|
| 466 | - 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
| 467 | - 'Event_Question_Group.' |
|
| 468 | - . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
| 469 | - $registration->is_primary_registrant() |
|
| 470 | - ) => true |
|
| 471 | - ], |
|
| 472 | - 'order_by' => ['QSG_order' => 'ASC'], |
|
| 473 | - ] |
|
| 474 | - ); |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * get_question_target_db_column |
|
| 481 | - * |
|
| 482 | - * @param string $QSG_IDs csv list of $QSG IDs |
|
| 483 | - * @return array|bool |
|
| 484 | - * @throws \EE_Error |
|
| 485 | - */ |
|
| 486 | - public function get_questions_in_groups($QSG_IDs = '') |
|
| 487 | - { |
|
| 488 | - if (empty($QSG_IDs)) { |
|
| 489 | - EE_Error::add_error( |
|
| 490 | - esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
| 491 | - __FILE__, |
|
| 492 | - __FUNCTION__, |
|
| 493 | - __LINE__ |
|
| 494 | - ); |
|
| 495 | - return false; |
|
| 496 | - } |
|
| 497 | - return EE_Registry::instance()->load_model('Question')->get_all( |
|
| 498 | - array( |
|
| 499 | - array( |
|
| 500 | - 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
| 501 | - 'QST_deleted' => false, |
|
| 502 | - 'QST_admin_only' => is_admin(), |
|
| 503 | - ), |
|
| 504 | - 'order_by' => 'QST_order', |
|
| 505 | - ) |
|
| 506 | - ); |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * get_options_for_question |
|
| 513 | - * |
|
| 514 | - * @param string $QST_IDs csv list of $QST IDs |
|
| 515 | - * @return array|bool |
|
| 516 | - * @throws \EE_Error |
|
| 517 | - */ |
|
| 518 | - public function get_options_for_question($QST_IDs) |
|
| 519 | - { |
|
| 520 | - if (empty($QST_IDs)) { |
|
| 521 | - EE_Error::add_error( |
|
| 522 | - esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
| 523 | - __FILE__, |
|
| 524 | - __FUNCTION__, |
|
| 525 | - __LINE__ |
|
| 526 | - ); |
|
| 527 | - return false; |
|
| 528 | - } |
|
| 529 | - return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
| 530 | - array( |
|
| 531 | - array( |
|
| 532 | - 'Question.QST_ID' => array('IN', $QST_IDs), |
|
| 533 | - 'QSO_deleted' => false, |
|
| 534 | - ), |
|
| 535 | - 'order_by' => 'QSO_ID', |
|
| 536 | - ) |
|
| 537 | - ); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - |
|
| 543 | - |
|
| 544 | - |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Gets all events that are published |
|
| 548 | - * and have event start time earlier than now and an event end time later than now |
|
| 549 | - * |
|
| 550 | - * @param array $query_params An array of query params to further filter on |
|
| 551 | - * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
| 552 | - * @param bool $count whether to return the count or not (default FALSE) |
|
| 553 | - * @return EE_Event[]|int |
|
| 554 | - * @throws \EE_Error |
|
| 555 | - */ |
|
| 556 | - public function get_active_events($query_params, $count = false) |
|
| 557 | - { |
|
| 558 | - if (array_key_exists(0, $query_params)) { |
|
| 559 | - $where_params = $query_params[0]; |
|
| 560 | - unset($query_params[0]); |
|
| 561 | - } else { |
|
| 562 | - $where_params = array(); |
|
| 563 | - } |
|
| 564 | - // if we have count make sure we don't include group by |
|
| 565 | - if ($count && isset($query_params['group_by'])) { |
|
| 566 | - unset($query_params['group_by']); |
|
| 567 | - } |
|
| 568 | - // let's add specific query_params for active_events |
|
| 569 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
| 570 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 571 | - // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
| 572 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 573 | - $where_params['Datetime.DTT_EVT_start******'] = array( |
|
| 574 | - '<', |
|
| 575 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 576 | - ); |
|
| 577 | - } else { |
|
| 578 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
| 579 | - '<', |
|
| 580 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 581 | - ); |
|
| 582 | - } |
|
| 583 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 584 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
| 585 | - '>', |
|
| 586 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 587 | - ); |
|
| 588 | - } else { |
|
| 589 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
| 590 | - '>', |
|
| 591 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 592 | - ); |
|
| 593 | - } |
|
| 594 | - $query_params[0] = $where_params; |
|
| 595 | - // don't use $query_params with count() |
|
| 596 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
| 597 | - return $count |
|
| 598 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 599 | - : $this->get_all($query_params); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * get all events that are published and have an event start time later than now |
|
| 606 | - * |
|
| 607 | - * @param array $query_params An array of query params to further filter on |
|
| 608 | - * (Note that status and DTT_EVT_start will be overridden) |
|
| 609 | - * @param bool $count whether to return the count or not (default FALSE) |
|
| 610 | - * @return EE_Event[]|int |
|
| 611 | - * @throws \EE_Error |
|
| 612 | - */ |
|
| 613 | - public function get_upcoming_events($query_params, $count = false) |
|
| 614 | - { |
|
| 615 | - if (array_key_exists(0, $query_params)) { |
|
| 616 | - $where_params = $query_params[0]; |
|
| 617 | - unset($query_params[0]); |
|
| 618 | - } else { |
|
| 619 | - $where_params = array(); |
|
| 620 | - } |
|
| 621 | - // if we have count make sure we don't include group by |
|
| 622 | - if ($count && isset($query_params['group_by'])) { |
|
| 623 | - unset($query_params['group_by']); |
|
| 624 | - } |
|
| 625 | - // let's add specific query_params for active_events |
|
| 626 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
| 627 | - // we need to pull events with a status of publish and sold_out |
|
| 628 | - $event_status = array('publish', EEM_Event::sold_out); |
|
| 629 | - // check if the user can read private events and if so add the 'private status to the were params' |
|
| 630 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) { |
|
| 631 | - $event_status[] = 'private'; |
|
| 632 | - } |
|
| 633 | - $where_params['status'] = array('IN', $event_status); |
|
| 634 | - // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
| 635 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 636 | - $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
| 637 | - '>', |
|
| 638 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 639 | - ); |
|
| 640 | - } else { |
|
| 641 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
| 642 | - '>', |
|
| 643 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 644 | - ); |
|
| 645 | - } |
|
| 646 | - $query_params[0] = $where_params; |
|
| 647 | - // don't use $query_params with count() |
|
| 648 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
| 649 | - return $count |
|
| 650 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 651 | - : $this->get_all($query_params); |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - |
|
| 655 | - |
|
| 656 | - /** |
|
| 657 | - * Gets all events that are published |
|
| 658 | - * and have an event end time later than now |
|
| 659 | - * |
|
| 660 | - * @param array $query_params An array of query params to further filter on |
|
| 661 | - * (note that status and DTT_EVT_end will be overridden) |
|
| 662 | - * @param bool $count whether to return the count or not (default FALSE) |
|
| 663 | - * @return EE_Event[]|int |
|
| 664 | - * @throws \EE_Error |
|
| 665 | - */ |
|
| 666 | - public function get_active_and_upcoming_events($query_params, $count = false) |
|
| 667 | - { |
|
| 668 | - if (array_key_exists(0, $query_params)) { |
|
| 669 | - $where_params = $query_params[0]; |
|
| 670 | - unset($query_params[0]); |
|
| 671 | - } else { |
|
| 672 | - $where_params = array(); |
|
| 673 | - } |
|
| 674 | - // if we have count make sure we don't include group by |
|
| 675 | - if ($count && isset($query_params['group_by'])) { |
|
| 676 | - unset($query_params['group_by']); |
|
| 677 | - } |
|
| 678 | - // let's add specific query_params for active_events |
|
| 679 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
| 680 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 681 | - // add where params for DTT_EVT_end |
|
| 682 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 683 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
| 684 | - '>', |
|
| 685 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 686 | - ); |
|
| 687 | - } else { |
|
| 688 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
| 689 | - '>', |
|
| 690 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 691 | - ); |
|
| 692 | - } |
|
| 693 | - $query_params[0] = $where_params; |
|
| 694 | - // don't use $query_params with count() |
|
| 695 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
| 696 | - return $count |
|
| 697 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 698 | - : $this->get_all($query_params); |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - |
|
| 702 | - |
|
| 703 | - /** |
|
| 704 | - * This only returns events that are expired. |
|
| 705 | - * They may still be published but all their datetimes have expired. |
|
| 706 | - * |
|
| 707 | - * @param array $query_params An array of query params to further filter on |
|
| 708 | - * (note that status and DTT_EVT_end will be overridden) |
|
| 709 | - * @param bool $count whether to return the count or not (default FALSE) |
|
| 710 | - * @return EE_Event[]|int |
|
| 711 | - * @throws \EE_Error |
|
| 712 | - */ |
|
| 713 | - public function get_expired_events($query_params, $count = false) |
|
| 714 | - { |
|
| 715 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 716 | - // if we have count make sure we don't include group by |
|
| 717 | - if ($count && isset($query_params['group_by'])) { |
|
| 718 | - unset($query_params['group_by']); |
|
| 719 | - } |
|
| 720 | - // let's add specific query_params for active_events |
|
| 721 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
| 722 | - if (isset($where_params['status'])) { |
|
| 723 | - unset($where_params['status']); |
|
| 724 | - } |
|
| 725 | - $exclude_query = $query_params; |
|
| 726 | - if (isset($exclude_query[0])) { |
|
| 727 | - unset($exclude_query[0]); |
|
| 728 | - } |
|
| 729 | - $exclude_query[0] = array( |
|
| 730 | - 'Datetime.DTT_EVT_end' => array( |
|
| 731 | - '>', |
|
| 732 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 733 | - ), |
|
| 734 | - ); |
|
| 735 | - // first get all events that have datetimes where its not expired. |
|
| 736 | - $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
| 737 | - $event_ids = array_keys($event_ids); |
|
| 738 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
| 739 | - $and_condition = array( |
|
| 740 | - 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
| 741 | - 'EVT_ID' => array('NOT IN', $event_ids), |
|
| 742 | - ); |
|
| 743 | - if (isset($where_params['OR'])) { |
|
| 744 | - $and_condition['OR'] = $where_params['OR']; |
|
| 745 | - unset($where_params['OR']); |
|
| 746 | - } |
|
| 747 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 748 | - $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
| 749 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
| 750 | - } |
|
| 751 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 752 | - $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
| 753 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
| 754 | - } |
|
| 755 | - // merge remaining $where params with the and conditions. |
|
| 756 | - $where_params['AND'] = array_merge($and_condition, $where_params); |
|
| 757 | - $query_params[0] = $where_params; |
|
| 758 | - // don't use $query_params with count() |
|
| 759 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
| 760 | - return $count |
|
| 761 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 762 | - : $this->get_all($query_params); |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - |
|
| 766 | - |
|
| 767 | - /** |
|
| 768 | - * This basically just returns the events that do not have the publish status. |
|
| 769 | - * |
|
| 770 | - * @param array $query_params An array of query params to further filter on |
|
| 771 | - * (note that status will be overwritten) |
|
| 772 | - * @param boolean $count whether to return the count or not (default FALSE) |
|
| 773 | - * @return EE_Event[]|int |
|
| 774 | - * @throws \EE_Error |
|
| 775 | - */ |
|
| 776 | - public function get_inactive_events($query_params, $count = false) |
|
| 777 | - { |
|
| 778 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 779 | - // let's add in specific query_params for inactive events. |
|
| 780 | - if (isset($where_params['status'])) { |
|
| 781 | - unset($where_params['status']); |
|
| 782 | - } |
|
| 783 | - // if we have count make sure we don't include group by |
|
| 784 | - if ($count && isset($query_params['group_by'])) { |
|
| 785 | - unset($query_params['group_by']); |
|
| 786 | - } |
|
| 787 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
| 788 | - $where_params['AND']['status'] = array('!=', 'publish'); |
|
| 789 | - if (isset($where_params['OR'])) { |
|
| 790 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
| 791 | - unset($where_params['OR']); |
|
| 792 | - } |
|
| 793 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 794 | - $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
| 795 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
| 796 | - } |
|
| 797 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 798 | - $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
| 799 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
| 800 | - } |
|
| 801 | - $query_params[0] = $where_params; |
|
| 802 | - // don't use $query_params with count() |
|
| 803 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
| 804 | - return $count |
|
| 805 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 806 | - : $this->get_all($query_params); |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - |
|
| 810 | - |
|
| 811 | - /** |
|
| 812 | - * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
| 813 | - * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
| 814 | - * attached to the event. See parent for param descriptions |
|
| 815 | - * |
|
| 816 | - * @param $id_or_obj |
|
| 817 | - * @param $other_model_id_or_obj |
|
| 818 | - * @param string $relationName |
|
| 819 | - * @param array $where_query |
|
| 820 | - * @return EE_Base_Class |
|
| 821 | - * @throws EE_Error |
|
| 822 | - */ |
|
| 823 | - public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
| 824 | - { |
|
| 825 | - if ($relationName === 'Price') { |
|
| 826 | - // let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
| 827 | - $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
| 828 | - // if EVT_ID = 0, then this is a default |
|
| 829 | - if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
| 830 | - // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
| 831 | - $prc_chk->set('PRC_ID', 0); |
|
| 832 | - } |
|
| 833 | - // run parent |
|
| 834 | - return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
| 835 | - } |
|
| 836 | - // otherwise carry on as normal |
|
| 837 | - return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
| 838 | - } |
|
| 839 | - |
|
| 840 | - |
|
| 841 | - |
|
| 842 | - /******************** DEPRECATED METHODS ********************/ |
|
| 843 | - |
|
| 844 | - |
|
| 845 | - |
|
| 846 | - /** |
|
| 847 | - * _get_question_target_db_column |
|
| 848 | - * |
|
| 849 | - * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
| 850 | - * EE_Registration_Custom_Questions_Form located in |
|
| 851 | - * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
| 852 | - * @access public |
|
| 853 | - * @param EE_Registration $registration (so existing answers for registration are included) |
|
| 854 | - * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
| 855 | - * registration). |
|
| 856 | - * @throws EE_Error |
|
| 857 | - * @return array |
|
| 858 | - */ |
|
| 859 | - public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
| 860 | - { |
|
| 861 | - if (empty($EVT_ID)) { |
|
| 862 | - throw new EE_Error(esc_html__( |
|
| 863 | - 'An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
| 864 | - 'event_espresso' |
|
| 865 | - )); |
|
| 866 | - } |
|
| 867 | - $questions = array(); |
|
| 868 | - // get all question groups for event |
|
| 869 | - $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
| 870 | - if (! empty($qgs)) { |
|
| 871 | - foreach ($qgs as $qg) { |
|
| 872 | - $qsts = $qg->questions(); |
|
| 873 | - $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
| 874 | - $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
| 875 | - foreach ($qsts as $qst) { |
|
| 876 | - if ($qst->is_system_question()) { |
|
| 877 | - continue; |
|
| 878 | - } |
|
| 879 | - $answer = EEM_Answer::instance()->get_one(array( |
|
| 880 | - array( |
|
| 881 | - 'QST_ID' => $qst->ID(), |
|
| 882 | - 'REG_ID' => $registration->ID(), |
|
| 883 | - ), |
|
| 884 | - )); |
|
| 885 | - $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
| 886 | - $qst_name = $qstn_id = $qst->ID(); |
|
| 887 | - $ans_id = $answer->ID(); |
|
| 888 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
| 889 | - $input_name = ''; |
|
| 890 | - $input_id = sanitize_key($qst->display_text()); |
|
| 891 | - $input_class = ''; |
|
| 892 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
| 893 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
| 894 | - . $input_name |
|
| 895 | - . $qst_name; |
|
| 896 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
| 897 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
| 898 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
| 899 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
| 900 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
| 901 | - // leave responses as-is, don't convert stuff into html entities please! |
|
| 902 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
| 903 | - if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
| 904 | - $QSOs = $qst->options(true, $answer->value()); |
|
| 905 | - if (is_array($QSOs)) { |
|
| 906 | - foreach ($QSOs as $QSO_ID => $QSO) { |
|
| 907 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
| 908 | - } |
|
| 909 | - } |
|
| 910 | - } |
|
| 911 | - } |
|
| 912 | - } |
|
| 913 | - } |
|
| 914 | - return $questions; |
|
| 915 | - } |
|
| 916 | - |
|
| 917 | - |
|
| 918 | - /** |
|
| 919 | - * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value |
|
| 920 | - * or an stdClass where each property is the name of a column, |
|
| 921 | - * @return EE_Base_Class |
|
| 922 | - * @throws \EE_Error |
|
| 923 | - */ |
|
| 924 | - public function instantiate_class_from_array_or_object($cols_n_values) |
|
| 925 | - { |
|
| 926 | - $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
| 927 | - if ($classInstance instanceof EE_Event) { |
|
| 928 | - // events have their timezone defined in the DB, so use it immediately |
|
| 929 | - $this->set_timezone($classInstance->get_timezone()); |
|
| 930 | - } |
|
| 931 | - return $classInstance; |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - |
|
| 935 | - /** |
|
| 936 | - * Deletes the model objects that meet the query params. Note: this method is overridden |
|
| 937 | - * in EEM_Soft_Delete_Base so that soft-deleted model objects are instead only flagged |
|
| 938 | - * as archived, not actually deleted |
|
| 939 | - * |
|
| 940 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 941 | - * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info |
|
| 942 | - * that blocks it (ie, there' sno other data that depends on this data); if false, |
|
| 943 | - * deletes regardless of other objects which may depend on it. Its generally |
|
| 944 | - * advisable to always leave this as TRUE, otherwise you could easily corrupt your |
|
| 945 | - * DB |
|
| 946 | - * @return int number of rows deleted |
|
| 947 | - * @throws EE_Error |
|
| 948 | - */ |
|
| 949 | - public function delete_permanently($query_params, $allow_blocking = true) |
|
| 950 | - { |
|
| 951 | - $deleted = parent::delete_permanently($query_params, $allow_blocking); |
|
| 952 | - if ($deleted) { |
|
| 953 | - // get list of events with no prices |
|
| 954 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', []); |
|
| 955 | - $where = isset($query_params[0]) ? $query_params[0] : []; |
|
| 956 | - $where_event = isset($where['EVT_ID']) ? $where['EVT_ID'] : ['', '']; |
|
| 957 | - $where_event_ids = isset($where_event[1]) ? $where_event[1] : ''; |
|
| 958 | - $event_ids = is_string($where_event_ids) |
|
| 959 | - ? explode(',', $where_event_ids) |
|
| 960 | - : (array) $where_event_ids; |
|
| 961 | - array_walk($event_ids, 'trim'); |
|
| 962 | - $event_ids = array_filter($event_ids); |
|
| 963 | - // remove events from list of events with no prices |
|
| 964 | - $espresso_no_ticket_prices = array_diff($espresso_no_ticket_prices, $event_ids); |
|
| 965 | - update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 966 | - } |
|
| 967 | - return $deleted; |
|
| 968 | - } |
|
| 18 | + /** |
|
| 19 | + * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
| 20 | + * event |
|
| 21 | + */ |
|
| 22 | + const sold_out = 'sold_out'; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
| 26 | + * date) |
|
| 27 | + */ |
|
| 28 | + const postponed = 'postponed'; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * constant used by status(), indicating that the event will no longer occur |
|
| 32 | + */ |
|
| 33 | + const cancelled = 'cancelled'; |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + protected static $_default_reg_status; |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * This is the default for the additional limit field. |
|
| 44 | + * @var int |
|
| 45 | + */ |
|
| 46 | + protected static $_default_additional_limit = 10; |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * private instance of the Event object |
|
| 51 | + * |
|
| 52 | + * @var EEM_Event |
|
| 53 | + */ |
|
| 54 | + protected static $_instance; |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
| 61 | + * |
|
| 62 | + * @param string $timezone |
|
| 63 | + * @throws \EE_Error |
|
| 64 | + */ |
|
| 65 | + protected function __construct($timezone = null) |
|
| 66 | + { |
|
| 67 | + EE_Registry::instance()->load_model('Registration'); |
|
| 68 | + $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
| 69 | + $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
| 70 | + // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
| 71 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
| 72 | + // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
| 73 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
| 74 | + // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
| 75 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
| 76 | + $this->_custom_stati = apply_filters( |
|
| 77 | + 'AFEE__EEM_Event__construct___custom_stati', |
|
| 78 | + array( |
|
| 79 | + EEM_Event::cancelled => array( |
|
| 80 | + 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
| 81 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
| 82 | + ), |
|
| 83 | + EEM_Event::postponed => array( |
|
| 84 | + 'label' => esc_html__('Postponed', 'event_espresso'), |
|
| 85 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
| 86 | + ), |
|
| 87 | + EEM_Event::sold_out => array( |
|
| 88 | + 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
| 89 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
| 90 | + ), |
|
| 91 | + ) |
|
| 92 | + ); |
|
| 93 | + self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
| 94 | + : self::$_default_reg_status; |
|
| 95 | + $this->_tables = array( |
|
| 96 | + 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
| 97 | + 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
| 98 | + ); |
|
| 99 | + $this->_fields = array( |
|
| 100 | + 'Event_CPT' => array( |
|
| 101 | + 'EVT_ID' => new EE_Primary_Key_Int_Field( |
|
| 102 | + 'ID', |
|
| 103 | + esc_html__('Post ID for Event', 'event_espresso') |
|
| 104 | + ), |
|
| 105 | + 'EVT_name' => new EE_Plain_Text_Field( |
|
| 106 | + 'post_title', |
|
| 107 | + esc_html__('Event Name', 'event_espresso'), |
|
| 108 | + false, |
|
| 109 | + '' |
|
| 110 | + ), |
|
| 111 | + 'EVT_desc' => new EE_Post_Content_Field( |
|
| 112 | + 'post_content', |
|
| 113 | + esc_html__('Event Description', 'event_espresso'), |
|
| 114 | + false, |
|
| 115 | + '' |
|
| 116 | + ), |
|
| 117 | + 'EVT_slug' => new EE_Slug_Field( |
|
| 118 | + 'post_name', |
|
| 119 | + esc_html__('Event Slug', 'event_espresso'), |
|
| 120 | + false, |
|
| 121 | + '' |
|
| 122 | + ), |
|
| 123 | + 'EVT_created' => new EE_Datetime_Field( |
|
| 124 | + 'post_date', |
|
| 125 | + esc_html__('Date/Time Event Created', 'event_espresso'), |
|
| 126 | + false, |
|
| 127 | + EE_Datetime_Field::now |
|
| 128 | + ), |
|
| 129 | + 'EVT_short_desc' => new EE_Simple_HTML_Field( |
|
| 130 | + 'post_excerpt', |
|
| 131 | + esc_html__('Event Short Description', 'event_espresso'), |
|
| 132 | + false, |
|
| 133 | + '' |
|
| 134 | + ), |
|
| 135 | + 'EVT_modified' => new EE_Datetime_Field( |
|
| 136 | + 'post_modified', |
|
| 137 | + esc_html__('Date/Time Event Modified', 'event_espresso'), |
|
| 138 | + false, |
|
| 139 | + EE_Datetime_Field::now |
|
| 140 | + ), |
|
| 141 | + 'EVT_wp_user' => new EE_WP_User_Field( |
|
| 142 | + 'post_author', |
|
| 143 | + esc_html__('Event Creator ID', 'event_espresso'), |
|
| 144 | + false |
|
| 145 | + ), |
|
| 146 | + 'parent' => new EE_Integer_Field( |
|
| 147 | + 'post_parent', |
|
| 148 | + esc_html__('Event Parent ID', 'event_espresso'), |
|
| 149 | + false, |
|
| 150 | + 0 |
|
| 151 | + ), |
|
| 152 | + 'EVT_order' => new EE_Integer_Field( |
|
| 153 | + 'menu_order', |
|
| 154 | + esc_html__('Event Menu Order', 'event_espresso'), |
|
| 155 | + false, |
|
| 156 | + 1 |
|
| 157 | + ), |
|
| 158 | + 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
| 159 | + // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
| 160 | + 'status' => new EE_WP_Post_Status_Field( |
|
| 161 | + 'post_status', |
|
| 162 | + esc_html__('Event Status', 'event_espresso'), |
|
| 163 | + false, |
|
| 164 | + 'draft', |
|
| 165 | + $this->_custom_stati |
|
| 166 | + ), |
|
| 167 | + 'password' => new EE_Password_Field( |
|
| 168 | + 'post_password', |
|
| 169 | + esc_html__('Password', 'event_espresso'), |
|
| 170 | + false, |
|
| 171 | + '', |
|
| 172 | + array( |
|
| 173 | + 'EVT_desc', |
|
| 174 | + 'EVT_short_desc', |
|
| 175 | + 'EVT_display_desc', |
|
| 176 | + 'EVT_display_ticket_selector', |
|
| 177 | + 'EVT_visible_on', |
|
| 178 | + 'EVT_additional_limit', |
|
| 179 | + 'EVT_default_registration_status', |
|
| 180 | + 'EVT_member_only', |
|
| 181 | + 'EVT_phone', |
|
| 182 | + 'EVT_allow_overflow', |
|
| 183 | + 'EVT_timezone_string', |
|
| 184 | + 'EVT_external_URL', |
|
| 185 | + 'EVT_donations' |
|
| 186 | + ) |
|
| 187 | + ) |
|
| 188 | + ), |
|
| 189 | + 'Event_Meta' => array( |
|
| 190 | + 'EVTM_ID' => new EE_DB_Only_Float_Field( |
|
| 191 | + 'EVTM_ID', |
|
| 192 | + esc_html__('Event Meta Row ID', 'event_espresso'), |
|
| 193 | + false |
|
| 194 | + ), |
|
| 195 | + 'EVT_ID_fk' => new EE_DB_Only_Int_Field( |
|
| 196 | + 'EVT_ID', |
|
| 197 | + esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), |
|
| 198 | + false |
|
| 199 | + ), |
|
| 200 | + 'EVT_display_desc' => new EE_Boolean_Field( |
|
| 201 | + 'EVT_display_desc', |
|
| 202 | + esc_html__('Display Description Flag', 'event_espresso'), |
|
| 203 | + false, |
|
| 204 | + true |
|
| 205 | + ), |
|
| 206 | + 'EVT_display_ticket_selector' => new EE_Boolean_Field( |
|
| 207 | + 'EVT_display_ticket_selector', |
|
| 208 | + esc_html__('Display Ticket Selector Flag', 'event_espresso'), |
|
| 209 | + false, |
|
| 210 | + true |
|
| 211 | + ), |
|
| 212 | + 'EVT_visible_on' => new EE_Datetime_Field( |
|
| 213 | + 'EVT_visible_on', |
|
| 214 | + esc_html__('Event Visible Date', 'event_espresso'), |
|
| 215 | + true, |
|
| 216 | + EE_Datetime_Field::now |
|
| 217 | + ), |
|
| 218 | + 'EVT_additional_limit' => new EE_Integer_Field( |
|
| 219 | + 'EVT_additional_limit', |
|
| 220 | + esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
| 221 | + true, |
|
| 222 | + self::$_default_additional_limit |
|
| 223 | + ), |
|
| 224 | + 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
| 225 | + 'EVT_default_registration_status', |
|
| 226 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
| 227 | + false, |
|
| 228 | + EEM_Event::$_default_reg_status, |
|
| 229 | + EEM_Registration::reg_status_array() |
|
| 230 | + ), |
|
| 231 | + 'EVT_member_only' => new EE_Boolean_Field( |
|
| 232 | + 'EVT_member_only', |
|
| 233 | + esc_html__('Member-Only Event Flag', 'event_espresso'), |
|
| 234 | + false, |
|
| 235 | + false |
|
| 236 | + ), |
|
| 237 | + 'EVT_phone' => new EE_Plain_Text_Field( |
|
| 238 | + 'EVT_phone', |
|
| 239 | + esc_html__('Event Phone Number', 'event_espresso'), |
|
| 240 | + false, |
|
| 241 | + '' |
|
| 242 | + ), |
|
| 243 | + 'EVT_allow_overflow' => new EE_Boolean_Field( |
|
| 244 | + 'EVT_allow_overflow', |
|
| 245 | + esc_html__('Allow Overflow on Event', 'event_espresso'), |
|
| 246 | + false, |
|
| 247 | + false |
|
| 248 | + ), |
|
| 249 | + 'EVT_timezone_string' => new EE_Plain_Text_Field( |
|
| 250 | + 'EVT_timezone_string', |
|
| 251 | + esc_html__('Timezone (name) for Event times', 'event_espresso'), |
|
| 252 | + false, |
|
| 253 | + '' |
|
| 254 | + ), |
|
| 255 | + 'EVT_external_URL' => new EE_Plain_Text_Field( |
|
| 256 | + 'EVT_external_URL', |
|
| 257 | + esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), |
|
| 258 | + true |
|
| 259 | + ), |
|
| 260 | + 'EVT_donations' => new EE_Boolean_Field( |
|
| 261 | + 'EVT_donations', |
|
| 262 | + esc_html__('Accept Donations?', 'event_espresso'), |
|
| 263 | + false, |
|
| 264 | + false |
|
| 265 | + ), |
|
| 266 | + ), |
|
| 267 | + ); |
|
| 268 | + $this->_model_relations = array( |
|
| 269 | + 'Registration' => new EE_Has_Many_Relation(), |
|
| 270 | + 'Datetime' => new EE_Has_Many_Relation(), |
|
| 271 | + 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
| 272 | + 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
| 273 | + 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
| 274 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
| 275 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
| 276 | + 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
| 277 | + 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
| 278 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 279 | + ); |
|
| 280 | + // this model is generally available for reading |
|
| 281 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 282 | + $this->model_chain_to_password = ''; |
|
| 283 | + parent::__construct($timezone); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * @param string $default_reg_status |
|
| 290 | + */ |
|
| 291 | + public static function set_default_reg_status($default_reg_status) |
|
| 292 | + { |
|
| 293 | + self::$_default_reg_status = $default_reg_status; |
|
| 294 | + // if EEM_Event has already been instantiated, |
|
| 295 | + // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
| 296 | + if (self::$_instance instanceof EEM_Event) { |
|
| 297 | + $default_reg_status = new EE_Enum_Text_Field( |
|
| 298 | + 'EVT_default_registration_status', |
|
| 299 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
| 300 | + false, |
|
| 301 | + $default_reg_status, |
|
| 302 | + EEM_Registration::reg_status_array() |
|
| 303 | + ); |
|
| 304 | + $default_reg_status->_construct_finalize( |
|
| 305 | + 'Event_Meta', |
|
| 306 | + 'EVT_default_registration_status', |
|
| 307 | + 'EEM_Event' |
|
| 308 | + ); |
|
| 309 | + self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * Used to override the default for the additional limit field. |
|
| 316 | + * @param $additional_limit |
|
| 317 | + */ |
|
| 318 | + public static function set_default_additional_limit($additional_limit) |
|
| 319 | + { |
|
| 320 | + self::$_default_additional_limit = (int) $additional_limit; |
|
| 321 | + if (self::$_instance instanceof EEM_Event) { |
|
| 322 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
| 323 | + 'EVT_additional_limit', |
|
| 324 | + esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
| 325 | + true, |
|
| 326 | + self::$_default_additional_limit |
|
| 327 | + ); |
|
| 328 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
| 329 | + 'Event_Meta', |
|
| 330 | + 'EVT_additional_limit', |
|
| 331 | + 'EEM_Event' |
|
| 332 | + ); |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * Return what is currently set as the default additional limit for the event. |
|
| 339 | + * @return int |
|
| 340 | + */ |
|
| 341 | + public static function get_default_additional_limit() |
|
| 342 | + { |
|
| 343 | + return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * get_question_groups |
|
| 349 | + * |
|
| 350 | + * @return array |
|
| 351 | + * @throws \EE_Error |
|
| 352 | + */ |
|
| 353 | + public function get_all_question_groups() |
|
| 354 | + { |
|
| 355 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
| 356 | + array( |
|
| 357 | + array('QSG_deleted' => false), |
|
| 358 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
| 359 | + ) |
|
| 360 | + ); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * get_question_groups |
|
| 367 | + * |
|
| 368 | + * @param int $EVT_ID |
|
| 369 | + * @return array|bool |
|
| 370 | + * @throws \EE_Error |
|
| 371 | + */ |
|
| 372 | + public function get_all_event_question_groups($EVT_ID = 0) |
|
| 373 | + { |
|
| 374 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 375 | + EE_Error::add_error( |
|
| 376 | + esc_html__( |
|
| 377 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
| 378 | + 'event_espresso' |
|
| 379 | + ), |
|
| 380 | + __FILE__, |
|
| 381 | + __FUNCTION__, |
|
| 382 | + __LINE__ |
|
| 383 | + ); |
|
| 384 | + return false; |
|
| 385 | + } |
|
| 386 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
| 387 | + array( |
|
| 388 | + array('EVT_ID' => $EVT_ID), |
|
| 389 | + ) |
|
| 390 | + ); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * get_question_groups |
|
| 396 | + * |
|
| 397 | + * @param int $EVT_ID |
|
| 398 | + * @param boolean $for_primary_attendee |
|
| 399 | + * @return array|bool |
|
| 400 | + * @throws EE_Error |
|
| 401 | + * @throws InvalidArgumentException |
|
| 402 | + * @throws ReflectionException |
|
| 403 | + * @throws InvalidDataTypeException |
|
| 404 | + * @throws InvalidInterfaceException |
|
| 405 | + */ |
|
| 406 | + public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
| 407 | + { |
|
| 408 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 409 | + EE_Error::add_error( |
|
| 410 | + esc_html__( |
|
| 411 | + // @codingStandardsIgnoreStart |
|
| 412 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
| 413 | + // @codingStandardsIgnoreEnd |
|
| 414 | + 'event_espresso' |
|
| 415 | + ), |
|
| 416 | + __FILE__, |
|
| 417 | + __FUNCTION__, |
|
| 418 | + __LINE__ |
|
| 419 | + ); |
|
| 420 | + return false; |
|
| 421 | + } |
|
| 422 | + $query_params = [ |
|
| 423 | + [ |
|
| 424 | + 'EVT_ID' => $EVT_ID, |
|
| 425 | + EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true |
|
| 426 | + ] |
|
| 427 | + ]; |
|
| 428 | + if ($for_primary_attendee) { |
|
| 429 | + $query_params[0]['EQG_primary'] = true; |
|
| 430 | + } else { |
|
| 431 | + $query_params[0]['EQG_additional'] = true; |
|
| 432 | + } |
|
| 433 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * get_question_groups |
|
| 439 | + * |
|
| 440 | + * @param int $EVT_ID |
|
| 441 | + * @param EE_Registration $registration |
|
| 442 | + * @return array|bool |
|
| 443 | + * @throws EE_Error |
|
| 444 | + * @throws InvalidArgumentException |
|
| 445 | + * @throws InvalidDataTypeException |
|
| 446 | + * @throws InvalidInterfaceException |
|
| 447 | + * @throws ReflectionException |
|
| 448 | + */ |
|
| 449 | + public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
| 450 | + { |
|
| 451 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 452 | + EE_Error::add_error( |
|
| 453 | + esc_html__( |
|
| 454 | + 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
| 455 | + 'event_espresso' |
|
| 456 | + ), |
|
| 457 | + __FILE__, |
|
| 458 | + __FUNCTION__, |
|
| 459 | + __LINE__ |
|
| 460 | + ); |
|
| 461 | + return false; |
|
| 462 | + } |
|
| 463 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
| 464 | + [ |
|
| 465 | + [ |
|
| 466 | + 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
| 467 | + 'Event_Question_Group.' |
|
| 468 | + . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
| 469 | + $registration->is_primary_registrant() |
|
| 470 | + ) => true |
|
| 471 | + ], |
|
| 472 | + 'order_by' => ['QSG_order' => 'ASC'], |
|
| 473 | + ] |
|
| 474 | + ); |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * get_question_target_db_column |
|
| 481 | + * |
|
| 482 | + * @param string $QSG_IDs csv list of $QSG IDs |
|
| 483 | + * @return array|bool |
|
| 484 | + * @throws \EE_Error |
|
| 485 | + */ |
|
| 486 | + public function get_questions_in_groups($QSG_IDs = '') |
|
| 487 | + { |
|
| 488 | + if (empty($QSG_IDs)) { |
|
| 489 | + EE_Error::add_error( |
|
| 490 | + esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
| 491 | + __FILE__, |
|
| 492 | + __FUNCTION__, |
|
| 493 | + __LINE__ |
|
| 494 | + ); |
|
| 495 | + return false; |
|
| 496 | + } |
|
| 497 | + return EE_Registry::instance()->load_model('Question')->get_all( |
|
| 498 | + array( |
|
| 499 | + array( |
|
| 500 | + 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
| 501 | + 'QST_deleted' => false, |
|
| 502 | + 'QST_admin_only' => is_admin(), |
|
| 503 | + ), |
|
| 504 | + 'order_by' => 'QST_order', |
|
| 505 | + ) |
|
| 506 | + ); |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * get_options_for_question |
|
| 513 | + * |
|
| 514 | + * @param string $QST_IDs csv list of $QST IDs |
|
| 515 | + * @return array|bool |
|
| 516 | + * @throws \EE_Error |
|
| 517 | + */ |
|
| 518 | + public function get_options_for_question($QST_IDs) |
|
| 519 | + { |
|
| 520 | + if (empty($QST_IDs)) { |
|
| 521 | + EE_Error::add_error( |
|
| 522 | + esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
| 523 | + __FILE__, |
|
| 524 | + __FUNCTION__, |
|
| 525 | + __LINE__ |
|
| 526 | + ); |
|
| 527 | + return false; |
|
| 528 | + } |
|
| 529 | + return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
| 530 | + array( |
|
| 531 | + array( |
|
| 532 | + 'Question.QST_ID' => array('IN', $QST_IDs), |
|
| 533 | + 'QSO_deleted' => false, |
|
| 534 | + ), |
|
| 535 | + 'order_by' => 'QSO_ID', |
|
| 536 | + ) |
|
| 537 | + ); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + |
|
| 543 | + |
|
| 544 | + |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Gets all events that are published |
|
| 548 | + * and have event start time earlier than now and an event end time later than now |
|
| 549 | + * |
|
| 550 | + * @param array $query_params An array of query params to further filter on |
|
| 551 | + * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
| 552 | + * @param bool $count whether to return the count or not (default FALSE) |
|
| 553 | + * @return EE_Event[]|int |
|
| 554 | + * @throws \EE_Error |
|
| 555 | + */ |
|
| 556 | + public function get_active_events($query_params, $count = false) |
|
| 557 | + { |
|
| 558 | + if (array_key_exists(0, $query_params)) { |
|
| 559 | + $where_params = $query_params[0]; |
|
| 560 | + unset($query_params[0]); |
|
| 561 | + } else { |
|
| 562 | + $where_params = array(); |
|
| 563 | + } |
|
| 564 | + // if we have count make sure we don't include group by |
|
| 565 | + if ($count && isset($query_params['group_by'])) { |
|
| 566 | + unset($query_params['group_by']); |
|
| 567 | + } |
|
| 568 | + // let's add specific query_params for active_events |
|
| 569 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
| 570 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 571 | + // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
| 572 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 573 | + $where_params['Datetime.DTT_EVT_start******'] = array( |
|
| 574 | + '<', |
|
| 575 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 576 | + ); |
|
| 577 | + } else { |
|
| 578 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
| 579 | + '<', |
|
| 580 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 581 | + ); |
|
| 582 | + } |
|
| 583 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 584 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
| 585 | + '>', |
|
| 586 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 587 | + ); |
|
| 588 | + } else { |
|
| 589 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
| 590 | + '>', |
|
| 591 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 592 | + ); |
|
| 593 | + } |
|
| 594 | + $query_params[0] = $where_params; |
|
| 595 | + // don't use $query_params with count() |
|
| 596 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
| 597 | + return $count |
|
| 598 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 599 | + : $this->get_all($query_params); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * get all events that are published and have an event start time later than now |
|
| 606 | + * |
|
| 607 | + * @param array $query_params An array of query params to further filter on |
|
| 608 | + * (Note that status and DTT_EVT_start will be overridden) |
|
| 609 | + * @param bool $count whether to return the count or not (default FALSE) |
|
| 610 | + * @return EE_Event[]|int |
|
| 611 | + * @throws \EE_Error |
|
| 612 | + */ |
|
| 613 | + public function get_upcoming_events($query_params, $count = false) |
|
| 614 | + { |
|
| 615 | + if (array_key_exists(0, $query_params)) { |
|
| 616 | + $where_params = $query_params[0]; |
|
| 617 | + unset($query_params[0]); |
|
| 618 | + } else { |
|
| 619 | + $where_params = array(); |
|
| 620 | + } |
|
| 621 | + // if we have count make sure we don't include group by |
|
| 622 | + if ($count && isset($query_params['group_by'])) { |
|
| 623 | + unset($query_params['group_by']); |
|
| 624 | + } |
|
| 625 | + // let's add specific query_params for active_events |
|
| 626 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
| 627 | + // we need to pull events with a status of publish and sold_out |
|
| 628 | + $event_status = array('publish', EEM_Event::sold_out); |
|
| 629 | + // check if the user can read private events and if so add the 'private status to the were params' |
|
| 630 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) { |
|
| 631 | + $event_status[] = 'private'; |
|
| 632 | + } |
|
| 633 | + $where_params['status'] = array('IN', $event_status); |
|
| 634 | + // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
| 635 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 636 | + $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
| 637 | + '>', |
|
| 638 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 639 | + ); |
|
| 640 | + } else { |
|
| 641 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
| 642 | + '>', |
|
| 643 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 644 | + ); |
|
| 645 | + } |
|
| 646 | + $query_params[0] = $where_params; |
|
| 647 | + // don't use $query_params with count() |
|
| 648 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
| 649 | + return $count |
|
| 650 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 651 | + : $this->get_all($query_params); |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + |
|
| 655 | + |
|
| 656 | + /** |
|
| 657 | + * Gets all events that are published |
|
| 658 | + * and have an event end time later than now |
|
| 659 | + * |
|
| 660 | + * @param array $query_params An array of query params to further filter on |
|
| 661 | + * (note that status and DTT_EVT_end will be overridden) |
|
| 662 | + * @param bool $count whether to return the count or not (default FALSE) |
|
| 663 | + * @return EE_Event[]|int |
|
| 664 | + * @throws \EE_Error |
|
| 665 | + */ |
|
| 666 | + public function get_active_and_upcoming_events($query_params, $count = false) |
|
| 667 | + { |
|
| 668 | + if (array_key_exists(0, $query_params)) { |
|
| 669 | + $where_params = $query_params[0]; |
|
| 670 | + unset($query_params[0]); |
|
| 671 | + } else { |
|
| 672 | + $where_params = array(); |
|
| 673 | + } |
|
| 674 | + // if we have count make sure we don't include group by |
|
| 675 | + if ($count && isset($query_params['group_by'])) { |
|
| 676 | + unset($query_params['group_by']); |
|
| 677 | + } |
|
| 678 | + // let's add specific query_params for active_events |
|
| 679 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
| 680 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 681 | + // add where params for DTT_EVT_end |
|
| 682 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 683 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
| 684 | + '>', |
|
| 685 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 686 | + ); |
|
| 687 | + } else { |
|
| 688 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
| 689 | + '>', |
|
| 690 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 691 | + ); |
|
| 692 | + } |
|
| 693 | + $query_params[0] = $where_params; |
|
| 694 | + // don't use $query_params with count() |
|
| 695 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
| 696 | + return $count |
|
| 697 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 698 | + : $this->get_all($query_params); |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + |
|
| 702 | + |
|
| 703 | + /** |
|
| 704 | + * This only returns events that are expired. |
|
| 705 | + * They may still be published but all their datetimes have expired. |
|
| 706 | + * |
|
| 707 | + * @param array $query_params An array of query params to further filter on |
|
| 708 | + * (note that status and DTT_EVT_end will be overridden) |
|
| 709 | + * @param bool $count whether to return the count or not (default FALSE) |
|
| 710 | + * @return EE_Event[]|int |
|
| 711 | + * @throws \EE_Error |
|
| 712 | + */ |
|
| 713 | + public function get_expired_events($query_params, $count = false) |
|
| 714 | + { |
|
| 715 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 716 | + // if we have count make sure we don't include group by |
|
| 717 | + if ($count && isset($query_params['group_by'])) { |
|
| 718 | + unset($query_params['group_by']); |
|
| 719 | + } |
|
| 720 | + // let's add specific query_params for active_events |
|
| 721 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
| 722 | + if (isset($where_params['status'])) { |
|
| 723 | + unset($where_params['status']); |
|
| 724 | + } |
|
| 725 | + $exclude_query = $query_params; |
|
| 726 | + if (isset($exclude_query[0])) { |
|
| 727 | + unset($exclude_query[0]); |
|
| 728 | + } |
|
| 729 | + $exclude_query[0] = array( |
|
| 730 | + 'Datetime.DTT_EVT_end' => array( |
|
| 731 | + '>', |
|
| 732 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 733 | + ), |
|
| 734 | + ); |
|
| 735 | + // first get all events that have datetimes where its not expired. |
|
| 736 | + $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
| 737 | + $event_ids = array_keys($event_ids); |
|
| 738 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
| 739 | + $and_condition = array( |
|
| 740 | + 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
| 741 | + 'EVT_ID' => array('NOT IN', $event_ids), |
|
| 742 | + ); |
|
| 743 | + if (isset($where_params['OR'])) { |
|
| 744 | + $and_condition['OR'] = $where_params['OR']; |
|
| 745 | + unset($where_params['OR']); |
|
| 746 | + } |
|
| 747 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 748 | + $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
| 749 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
| 750 | + } |
|
| 751 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 752 | + $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
| 753 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
| 754 | + } |
|
| 755 | + // merge remaining $where params with the and conditions. |
|
| 756 | + $where_params['AND'] = array_merge($and_condition, $where_params); |
|
| 757 | + $query_params[0] = $where_params; |
|
| 758 | + // don't use $query_params with count() |
|
| 759 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
| 760 | + return $count |
|
| 761 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 762 | + : $this->get_all($query_params); |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + |
|
| 766 | + |
|
| 767 | + /** |
|
| 768 | + * This basically just returns the events that do not have the publish status. |
|
| 769 | + * |
|
| 770 | + * @param array $query_params An array of query params to further filter on |
|
| 771 | + * (note that status will be overwritten) |
|
| 772 | + * @param boolean $count whether to return the count or not (default FALSE) |
|
| 773 | + * @return EE_Event[]|int |
|
| 774 | + * @throws \EE_Error |
|
| 775 | + */ |
|
| 776 | + public function get_inactive_events($query_params, $count = false) |
|
| 777 | + { |
|
| 778 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 779 | + // let's add in specific query_params for inactive events. |
|
| 780 | + if (isset($where_params['status'])) { |
|
| 781 | + unset($where_params['status']); |
|
| 782 | + } |
|
| 783 | + // if we have count make sure we don't include group by |
|
| 784 | + if ($count && isset($query_params['group_by'])) { |
|
| 785 | + unset($query_params['group_by']); |
|
| 786 | + } |
|
| 787 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
| 788 | + $where_params['AND']['status'] = array('!=', 'publish'); |
|
| 789 | + if (isset($where_params['OR'])) { |
|
| 790 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
| 791 | + unset($where_params['OR']); |
|
| 792 | + } |
|
| 793 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 794 | + $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
| 795 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
| 796 | + } |
|
| 797 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 798 | + $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
| 799 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
| 800 | + } |
|
| 801 | + $query_params[0] = $where_params; |
|
| 802 | + // don't use $query_params with count() |
|
| 803 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
| 804 | + return $count |
|
| 805 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 806 | + : $this->get_all($query_params); |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + |
|
| 810 | + |
|
| 811 | + /** |
|
| 812 | + * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
| 813 | + * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
| 814 | + * attached to the event. See parent for param descriptions |
|
| 815 | + * |
|
| 816 | + * @param $id_or_obj |
|
| 817 | + * @param $other_model_id_or_obj |
|
| 818 | + * @param string $relationName |
|
| 819 | + * @param array $where_query |
|
| 820 | + * @return EE_Base_Class |
|
| 821 | + * @throws EE_Error |
|
| 822 | + */ |
|
| 823 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
| 824 | + { |
|
| 825 | + if ($relationName === 'Price') { |
|
| 826 | + // let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
| 827 | + $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
| 828 | + // if EVT_ID = 0, then this is a default |
|
| 829 | + if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
| 830 | + // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
| 831 | + $prc_chk->set('PRC_ID', 0); |
|
| 832 | + } |
|
| 833 | + // run parent |
|
| 834 | + return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
| 835 | + } |
|
| 836 | + // otherwise carry on as normal |
|
| 837 | + return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
| 838 | + } |
|
| 839 | + |
|
| 840 | + |
|
| 841 | + |
|
| 842 | + /******************** DEPRECATED METHODS ********************/ |
|
| 843 | + |
|
| 844 | + |
|
| 845 | + |
|
| 846 | + /** |
|
| 847 | + * _get_question_target_db_column |
|
| 848 | + * |
|
| 849 | + * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
| 850 | + * EE_Registration_Custom_Questions_Form located in |
|
| 851 | + * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
| 852 | + * @access public |
|
| 853 | + * @param EE_Registration $registration (so existing answers for registration are included) |
|
| 854 | + * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
| 855 | + * registration). |
|
| 856 | + * @throws EE_Error |
|
| 857 | + * @return array |
|
| 858 | + */ |
|
| 859 | + public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
| 860 | + { |
|
| 861 | + if (empty($EVT_ID)) { |
|
| 862 | + throw new EE_Error(esc_html__( |
|
| 863 | + 'An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
| 864 | + 'event_espresso' |
|
| 865 | + )); |
|
| 866 | + } |
|
| 867 | + $questions = array(); |
|
| 868 | + // get all question groups for event |
|
| 869 | + $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
| 870 | + if (! empty($qgs)) { |
|
| 871 | + foreach ($qgs as $qg) { |
|
| 872 | + $qsts = $qg->questions(); |
|
| 873 | + $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
| 874 | + $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
| 875 | + foreach ($qsts as $qst) { |
|
| 876 | + if ($qst->is_system_question()) { |
|
| 877 | + continue; |
|
| 878 | + } |
|
| 879 | + $answer = EEM_Answer::instance()->get_one(array( |
|
| 880 | + array( |
|
| 881 | + 'QST_ID' => $qst->ID(), |
|
| 882 | + 'REG_ID' => $registration->ID(), |
|
| 883 | + ), |
|
| 884 | + )); |
|
| 885 | + $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
| 886 | + $qst_name = $qstn_id = $qst->ID(); |
|
| 887 | + $ans_id = $answer->ID(); |
|
| 888 | + $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
| 889 | + $input_name = ''; |
|
| 890 | + $input_id = sanitize_key($qst->display_text()); |
|
| 891 | + $input_class = ''; |
|
| 892 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
| 893 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
| 894 | + . $input_name |
|
| 895 | + . $qst_name; |
|
| 896 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
| 897 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
| 898 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
| 899 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
| 900 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
| 901 | + // leave responses as-is, don't convert stuff into html entities please! |
|
| 902 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
| 903 | + if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
| 904 | + $QSOs = $qst->options(true, $answer->value()); |
|
| 905 | + if (is_array($QSOs)) { |
|
| 906 | + foreach ($QSOs as $QSO_ID => $QSO) { |
|
| 907 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
| 908 | + } |
|
| 909 | + } |
|
| 910 | + } |
|
| 911 | + } |
|
| 912 | + } |
|
| 913 | + } |
|
| 914 | + return $questions; |
|
| 915 | + } |
|
| 916 | + |
|
| 917 | + |
|
| 918 | + /** |
|
| 919 | + * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value |
|
| 920 | + * or an stdClass where each property is the name of a column, |
|
| 921 | + * @return EE_Base_Class |
|
| 922 | + * @throws \EE_Error |
|
| 923 | + */ |
|
| 924 | + public function instantiate_class_from_array_or_object($cols_n_values) |
|
| 925 | + { |
|
| 926 | + $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
| 927 | + if ($classInstance instanceof EE_Event) { |
|
| 928 | + // events have their timezone defined in the DB, so use it immediately |
|
| 929 | + $this->set_timezone($classInstance->get_timezone()); |
|
| 930 | + } |
|
| 931 | + return $classInstance; |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + |
|
| 935 | + /** |
|
| 936 | + * Deletes the model objects that meet the query params. Note: this method is overridden |
|
| 937 | + * in EEM_Soft_Delete_Base so that soft-deleted model objects are instead only flagged |
|
| 938 | + * as archived, not actually deleted |
|
| 939 | + * |
|
| 940 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 941 | + * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info |
|
| 942 | + * that blocks it (ie, there' sno other data that depends on this data); if false, |
|
| 943 | + * deletes regardless of other objects which may depend on it. Its generally |
|
| 944 | + * advisable to always leave this as TRUE, otherwise you could easily corrupt your |
|
| 945 | + * DB |
|
| 946 | + * @return int number of rows deleted |
|
| 947 | + * @throws EE_Error |
|
| 948 | + */ |
|
| 949 | + public function delete_permanently($query_params, $allow_blocking = true) |
|
| 950 | + { |
|
| 951 | + $deleted = parent::delete_permanently($query_params, $allow_blocking); |
|
| 952 | + if ($deleted) { |
|
| 953 | + // get list of events with no prices |
|
| 954 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', []); |
|
| 955 | + $where = isset($query_params[0]) ? $query_params[0] : []; |
|
| 956 | + $where_event = isset($where['EVT_ID']) ? $where['EVT_ID'] : ['', '']; |
|
| 957 | + $where_event_ids = isset($where_event[1]) ? $where_event[1] : ''; |
|
| 958 | + $event_ids = is_string($where_event_ids) |
|
| 959 | + ? explode(',', $where_event_ids) |
|
| 960 | + : (array) $where_event_ids; |
|
| 961 | + array_walk($event_ids, 'trim'); |
|
| 962 | + $event_ids = array_filter($event_ids); |
|
| 963 | + // remove events from list of events with no prices |
|
| 964 | + $espresso_no_ticket_prices = array_diff($espresso_no_ticket_prices, $event_ids); |
|
| 965 | + update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 966 | + } |
|
| 967 | + return $deleted; |
|
| 968 | + } |
|
| 969 | 969 | } |
@@ -27,365 +27,365 @@ |
||
| 27 | 27 | abstract class EEM_Soft_Delete_Base extends EEM_Base |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @param null $timezone |
|
| 32 | - */ |
|
| 33 | - protected function __construct($timezone = null) |
|
| 34 | - { |
|
| 35 | - if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
| 36 | - $this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions(); |
|
| 37 | - } |
|
| 38 | - parent::__construct($timezone); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Searches for field on this model of type 'deleted_flag'. if it is found, |
|
| 45 | - * returns it's name. |
|
| 46 | - * |
|
| 47 | - * @return string |
|
| 48 | - * @throws EE_Error |
|
| 49 | - */ |
|
| 50 | - public function deleted_field_name() |
|
| 51 | - { |
|
| 52 | - $field = $this->get_a_field_of_type('EE_Trashed_Flag_Field'); |
|
| 53 | - if ($field) { |
|
| 54 | - return $field->get_name(); |
|
| 55 | - } else { |
|
| 56 | - throw new EE_Error(sprintf(esc_html__( |
|
| 57 | - 'We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?', |
|
| 58 | - 'event_espresso' |
|
| 59 | - ), get_class($this), get_class($this))); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Gets one item that's been deleted, according to $query_params |
|
| 67 | - * |
|
| 68 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 69 | - * @return EE_Soft_Delete_Base_Class |
|
| 70 | - */ |
|
| 71 | - public function get_one_deleted($query_params = array()) |
|
| 72 | - { |
|
| 73 | - $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
|
| 74 | - return parent::get_one($query_params); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Gets one item from the DB, regardless of whether it's been soft-deleted or not |
|
| 81 | - * |
|
| 82 | - * @param array $query_params like EEM_base::get_all's $query_params |
|
| 83 | - * @return EE_Soft_Delete_Base_Class |
|
| 84 | - */ |
|
| 85 | - public function get_one_deleted_or_undeleted($query_params = array()) |
|
| 86 | - { |
|
| 87 | - $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
| 88 | - return parent::get_one($query_params); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Gets the item indicated by its ID. But if it's soft-deleted, pretends it doesn't exist. |
|
| 95 | - * |
|
| 96 | - * @param int|string $id |
|
| 97 | - * @return EE_Soft_Delete_Base_Class |
|
| 98 | - */ |
|
| 99 | - public function get_one_by_ID_but_ignore_deleted($id) |
|
| 100 | - { |
|
| 101 | - return $this->get_one( |
|
| 102 | - $this->alter_query_params_to_restrict_by_ID( |
|
| 103 | - $id, |
|
| 104 | - array('default_where_conditions' => 'default') |
|
| 105 | - ) |
|
| 106 | - ); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Counts all the deleted/trashed items |
|
| 113 | - * |
|
| 114 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 115 | - * @param string $field_to_count |
|
| 116 | - * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
|
| 117 | - * @return int |
|
| 118 | - */ |
|
| 119 | - public function count_deleted($query_params = null, $field_to_count = null, $distinct = false) |
|
| 120 | - { |
|
| 121 | - $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
|
| 122 | - return parent::count($query_params, $field_to_count, $distinct); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Alters the query params so that only trashed/soft-deleted items are considered |
|
| 129 | - * |
|
| 130 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 131 | - * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 132 | - */ |
|
| 133 | - protected function _alter_query_params_so_only_trashed_items_included($query_params) |
|
| 134 | - { |
|
| 135 | - $deletedFlagFieldName = $this->deleted_field_name(); |
|
| 136 | - $query_params[0][ $deletedFlagFieldName ] = true; |
|
| 137 | - return $query_params; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Alters the query params so that only trashed/soft-deleted items are considered |
|
| 144 | - * |
|
| 145 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 146 | - * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 147 | - */ |
|
| 148 | - public function alter_query_params_so_only_trashed_items_included($query_params) |
|
| 149 | - { |
|
| 150 | - return $this->_alter_query_params_so_only_trashed_items_included($query_params); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Alters the query params so each item's deleted status is ignored. |
|
| 157 | - * |
|
| 158 | - * @param array $query_params |
|
| 159 | - * @return array |
|
| 160 | - */ |
|
| 161 | - public function alter_query_params_so_deleted_and_undeleted_items_included($query_params = array()) |
|
| 162 | - { |
|
| 163 | - return $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Alters the query params so each item's deleted status is ignored. |
|
| 170 | - * |
|
| 171 | - * @param array $query_params |
|
| 172 | - * @return array |
|
| 173 | - */ |
|
| 174 | - protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params) |
|
| 175 | - { |
|
| 176 | - if (! isset($query_params['default_where_conditions'])) { |
|
| 177 | - $query_params['default_where_conditions'] = 'minimum'; |
|
| 178 | - } |
|
| 179 | - return $query_params; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Counts all deleted and undeleted items |
|
| 186 | - * |
|
| 187 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 188 | - * @param string $field_to_count |
|
| 189 | - * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
|
| 190 | - * @return int |
|
| 191 | - */ |
|
| 192 | - public function count_deleted_and_undeleted($query_params = null, $field_to_count = null, $distinct = false) |
|
| 193 | - { |
|
| 194 | - $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
| 195 | - return parent::count($query_params, $field_to_count, $distinct); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Sum all the deleted items. |
|
| 202 | - * |
|
| 203 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 204 | - * @param string $field_to_sum |
|
| 205 | - * @return int |
|
| 206 | - */ |
|
| 207 | - public function sum_deleted($query_params = null, $field_to_sum = null) |
|
| 208 | - { |
|
| 209 | - $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
|
| 210 | - return parent::sum($query_params, $field_to_sum); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Sums all the deleted and undeleted items. |
|
| 217 | - * |
|
| 218 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 219 | - * @param string $field_to_sum |
|
| 220 | - * @return int |
|
| 221 | - */ |
|
| 222 | - public function sum_deleted_and_undeleted($query_params = null, $field_to_sum = null) |
|
| 223 | - { |
|
| 224 | - $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
| 225 | - parent::sum($query_params, $field_to_sum); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * Gets all deleted and undeleted mode objects from the db that meet the criteria, regardless of |
|
| 232 | - * whether they've been soft-deleted or not |
|
| 233 | - * |
|
| 234 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 235 | - * @return EE_Soft_Delete_Base_Class[] |
|
| 236 | - */ |
|
| 237 | - public function get_all_deleted_and_undeleted($query_params = array()) |
|
| 238 | - { |
|
| 239 | - $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
| 240 | - return parent::get_all($query_params); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * For 'soft deletable' models, gets all which ARE deleted, according to conditions specified in $query_params. |
|
| 247 | - * |
|
| 248 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 249 | - * @return EE_Soft_Delete_Base_Class[] |
|
| 250 | - */ |
|
| 251 | - public function get_all_deleted($query_params = array()) |
|
| 252 | - { |
|
| 253 | - $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
|
| 254 | - return parent::get_all($query_params); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Permanently deletes the selected rows. When selecting rows for deletion, ignores |
|
| 261 | - * whether they've been soft-deleted or not. (ie, you don't have to soft-delete objects |
|
| 262 | - * before you can permanently delete them). |
|
| 263 | - * Because this will cause a real deletion, related models may block this deletion (ie, add an error |
|
| 264 | - * and abort the delete) |
|
| 265 | - * |
|
| 266 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 267 | - * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info |
|
| 268 | - * that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects |
|
| 269 | - * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB |
|
| 270 | - * @return int number of rows deleted |
|
| 271 | - * @throws EE_Error |
|
| 272 | - */ |
|
| 273 | - public function delete_permanently($query_params, $allow_blocking = true) |
|
| 274 | - { |
|
| 275 | - $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
| 276 | - return parent::delete_permanently($query_params, $allow_blocking); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * Restores a particular item by its ID (primary key). Ignores the fact whether the item |
|
| 283 | - * has been soft-deleted or not. |
|
| 284 | - * |
|
| 285 | - * @param mixed $ID int if primary key is an int, string otherwise |
|
| 286 | - * @return boolean success |
|
| 287 | - */ |
|
| 288 | - public function restore_by_ID($ID = false) |
|
| 289 | - { |
|
| 290 | - return $this->delete_or_restore_by_ID(false, $ID); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * For deleting or restoring a particular item. Note that this model is a SOFT-DELETABLE model! However, |
|
| 297 | - * this function will ignore whether the items have been soft-deleted or not. |
|
| 298 | - * |
|
| 299 | - * @param boolean $delete true for delete, false for restore |
|
| 300 | - * @param mixed $ID int if primary key is an int, string otherwise |
|
| 301 | - * @return boolean |
|
| 302 | - */ |
|
| 303 | - public function delete_or_restore_by_ID($delete = true, $ID = false) |
|
| 304 | - { |
|
| 305 | - if (! $ID) { |
|
| 306 | - return false; |
|
| 307 | - } |
|
| 308 | - if ( |
|
| 309 | - $this->delete_or_restore( |
|
| 310 | - $delete, |
|
| 311 | - $this->alter_query_params_to_restrict_by_ID($ID) |
|
| 312 | - ) |
|
| 313 | - ) { |
|
| 314 | - return true; |
|
| 315 | - } else { |
|
| 316 | - return false; |
|
| 317 | - } |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Overrides parent's 'delete' method to instead do a soft delete on all rows that |
|
| 324 | - * meet the criteria in $where_col_n_values. This particular function ignores whether the items have been soft-deleted or not. |
|
| 325 | - * Note: because this item will be soft-deleted only, |
|
| 326 | - * doesn't block because of model dependencies |
|
| 327 | - * |
|
| 328 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 329 | - * @param bool $block_deletes |
|
| 330 | - * @return boolean |
|
| 331 | - */ |
|
| 332 | - public function delete($query_params = array(), $block_deletes = false) |
|
| 333 | - { |
|
| 334 | - // no matter what, we WON'T block soft deletes. |
|
| 335 | - return $this->delete_or_restore(true, $query_params); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * 'Un-deletes' the chosen items. Note that this model is a SOFT-DELETABLE model! That means that, by default, trashed/soft-deleted |
|
| 342 | - * items are ignored in queries. However, this particular function ignores whether the items have been soft-deleted or not. |
|
| 343 | - * |
|
| 344 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 345 | - * @return boolean |
|
| 346 | - */ |
|
| 347 | - public function restore($query_params = array()) |
|
| 348 | - { |
|
| 349 | - return $this->delete_or_restore(false, $query_params); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered. |
|
| 356 | - * |
|
| 357 | - * @param boolean $delete true to indicate deletion, false to indicate restoration |
|
| 358 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 359 | - * @return boolean |
|
| 360 | - */ |
|
| 361 | - public function delete_or_restore($delete = true, $query_params = array()) |
|
| 362 | - { |
|
| 363 | - $deletedFlagFieldName = $this->deleted_field_name(); |
|
| 364 | - $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
| 365 | - if ($this->update(array($deletedFlagFieldName => $delete), $query_params)) { |
|
| 366 | - return true; |
|
| 367 | - } else { |
|
| 368 | - return false; |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Updates all the items of this model which match the $query params, regardless of whether |
|
| 376 | - * they've been soft-deleted or not |
|
| 377 | - * |
|
| 378 | - * @param array $fields_n_values like EEM_Base::update's $fields_n_value |
|
| 379 | - * @param array $query_params like EEM_base::get_all's $query_params |
|
| 380 | - * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects |
|
| 381 | - * in this model's entity map according to $fields_n_values that match $query_params. This |
|
| 382 | - * obviously has some overhead, so you can disable it by setting this to FALSE, but |
|
| 383 | - * be aware that model objects being used could get out-of-sync with the database |
|
| 384 | - * @return int number of items updated |
|
| 385 | - */ |
|
| 386 | - public function update_deleted_and_undeleted($fields_n_values, $query_params, $keep_model_objs_in_sync = true) |
|
| 387 | - { |
|
| 388 | - $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
| 389 | - return $this->update($fields_n_values, $query_params, $keep_model_objs_in_sync); |
|
| 390 | - } |
|
| 30 | + /** |
|
| 31 | + * @param null $timezone |
|
| 32 | + */ |
|
| 33 | + protected function __construct($timezone = null) |
|
| 34 | + { |
|
| 35 | + if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
| 36 | + $this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions(); |
|
| 37 | + } |
|
| 38 | + parent::__construct($timezone); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Searches for field on this model of type 'deleted_flag'. if it is found, |
|
| 45 | + * returns it's name. |
|
| 46 | + * |
|
| 47 | + * @return string |
|
| 48 | + * @throws EE_Error |
|
| 49 | + */ |
|
| 50 | + public function deleted_field_name() |
|
| 51 | + { |
|
| 52 | + $field = $this->get_a_field_of_type('EE_Trashed_Flag_Field'); |
|
| 53 | + if ($field) { |
|
| 54 | + return $field->get_name(); |
|
| 55 | + } else { |
|
| 56 | + throw new EE_Error(sprintf(esc_html__( |
|
| 57 | + 'We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?', |
|
| 58 | + 'event_espresso' |
|
| 59 | + ), get_class($this), get_class($this))); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Gets one item that's been deleted, according to $query_params |
|
| 67 | + * |
|
| 68 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 69 | + * @return EE_Soft_Delete_Base_Class |
|
| 70 | + */ |
|
| 71 | + public function get_one_deleted($query_params = array()) |
|
| 72 | + { |
|
| 73 | + $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
|
| 74 | + return parent::get_one($query_params); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Gets one item from the DB, regardless of whether it's been soft-deleted or not |
|
| 81 | + * |
|
| 82 | + * @param array $query_params like EEM_base::get_all's $query_params |
|
| 83 | + * @return EE_Soft_Delete_Base_Class |
|
| 84 | + */ |
|
| 85 | + public function get_one_deleted_or_undeleted($query_params = array()) |
|
| 86 | + { |
|
| 87 | + $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
| 88 | + return parent::get_one($query_params); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Gets the item indicated by its ID. But if it's soft-deleted, pretends it doesn't exist. |
|
| 95 | + * |
|
| 96 | + * @param int|string $id |
|
| 97 | + * @return EE_Soft_Delete_Base_Class |
|
| 98 | + */ |
|
| 99 | + public function get_one_by_ID_but_ignore_deleted($id) |
|
| 100 | + { |
|
| 101 | + return $this->get_one( |
|
| 102 | + $this->alter_query_params_to_restrict_by_ID( |
|
| 103 | + $id, |
|
| 104 | + array('default_where_conditions' => 'default') |
|
| 105 | + ) |
|
| 106 | + ); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Counts all the deleted/trashed items |
|
| 113 | + * |
|
| 114 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 115 | + * @param string $field_to_count |
|
| 116 | + * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
|
| 117 | + * @return int |
|
| 118 | + */ |
|
| 119 | + public function count_deleted($query_params = null, $field_to_count = null, $distinct = false) |
|
| 120 | + { |
|
| 121 | + $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
|
| 122 | + return parent::count($query_params, $field_to_count, $distinct); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Alters the query params so that only trashed/soft-deleted items are considered |
|
| 129 | + * |
|
| 130 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 131 | + * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 132 | + */ |
|
| 133 | + protected function _alter_query_params_so_only_trashed_items_included($query_params) |
|
| 134 | + { |
|
| 135 | + $deletedFlagFieldName = $this->deleted_field_name(); |
|
| 136 | + $query_params[0][ $deletedFlagFieldName ] = true; |
|
| 137 | + return $query_params; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Alters the query params so that only trashed/soft-deleted items are considered |
|
| 144 | + * |
|
| 145 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 146 | + * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 147 | + */ |
|
| 148 | + public function alter_query_params_so_only_trashed_items_included($query_params) |
|
| 149 | + { |
|
| 150 | + return $this->_alter_query_params_so_only_trashed_items_included($query_params); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Alters the query params so each item's deleted status is ignored. |
|
| 157 | + * |
|
| 158 | + * @param array $query_params |
|
| 159 | + * @return array |
|
| 160 | + */ |
|
| 161 | + public function alter_query_params_so_deleted_and_undeleted_items_included($query_params = array()) |
|
| 162 | + { |
|
| 163 | + return $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Alters the query params so each item's deleted status is ignored. |
|
| 170 | + * |
|
| 171 | + * @param array $query_params |
|
| 172 | + * @return array |
|
| 173 | + */ |
|
| 174 | + protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params) |
|
| 175 | + { |
|
| 176 | + if (! isset($query_params['default_where_conditions'])) { |
|
| 177 | + $query_params['default_where_conditions'] = 'minimum'; |
|
| 178 | + } |
|
| 179 | + return $query_params; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Counts all deleted and undeleted items |
|
| 186 | + * |
|
| 187 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 188 | + * @param string $field_to_count |
|
| 189 | + * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
|
| 190 | + * @return int |
|
| 191 | + */ |
|
| 192 | + public function count_deleted_and_undeleted($query_params = null, $field_to_count = null, $distinct = false) |
|
| 193 | + { |
|
| 194 | + $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
| 195 | + return parent::count($query_params, $field_to_count, $distinct); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Sum all the deleted items. |
|
| 202 | + * |
|
| 203 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 204 | + * @param string $field_to_sum |
|
| 205 | + * @return int |
|
| 206 | + */ |
|
| 207 | + public function sum_deleted($query_params = null, $field_to_sum = null) |
|
| 208 | + { |
|
| 209 | + $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
|
| 210 | + return parent::sum($query_params, $field_to_sum); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Sums all the deleted and undeleted items. |
|
| 217 | + * |
|
| 218 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 219 | + * @param string $field_to_sum |
|
| 220 | + * @return int |
|
| 221 | + */ |
|
| 222 | + public function sum_deleted_and_undeleted($query_params = null, $field_to_sum = null) |
|
| 223 | + { |
|
| 224 | + $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
| 225 | + parent::sum($query_params, $field_to_sum); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Gets all deleted and undeleted mode objects from the db that meet the criteria, regardless of |
|
| 232 | + * whether they've been soft-deleted or not |
|
| 233 | + * |
|
| 234 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 235 | + * @return EE_Soft_Delete_Base_Class[] |
|
| 236 | + */ |
|
| 237 | + public function get_all_deleted_and_undeleted($query_params = array()) |
|
| 238 | + { |
|
| 239 | + $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
| 240 | + return parent::get_all($query_params); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * For 'soft deletable' models, gets all which ARE deleted, according to conditions specified in $query_params. |
|
| 247 | + * |
|
| 248 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 249 | + * @return EE_Soft_Delete_Base_Class[] |
|
| 250 | + */ |
|
| 251 | + public function get_all_deleted($query_params = array()) |
|
| 252 | + { |
|
| 253 | + $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
|
| 254 | + return parent::get_all($query_params); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Permanently deletes the selected rows. When selecting rows for deletion, ignores |
|
| 261 | + * whether they've been soft-deleted or not. (ie, you don't have to soft-delete objects |
|
| 262 | + * before you can permanently delete them). |
|
| 263 | + * Because this will cause a real deletion, related models may block this deletion (ie, add an error |
|
| 264 | + * and abort the delete) |
|
| 265 | + * |
|
| 266 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 267 | + * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info |
|
| 268 | + * that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects |
|
| 269 | + * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB |
|
| 270 | + * @return int number of rows deleted |
|
| 271 | + * @throws EE_Error |
|
| 272 | + */ |
|
| 273 | + public function delete_permanently($query_params, $allow_blocking = true) |
|
| 274 | + { |
|
| 275 | + $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
| 276 | + return parent::delete_permanently($query_params, $allow_blocking); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * Restores a particular item by its ID (primary key). Ignores the fact whether the item |
|
| 283 | + * has been soft-deleted or not. |
|
| 284 | + * |
|
| 285 | + * @param mixed $ID int if primary key is an int, string otherwise |
|
| 286 | + * @return boolean success |
|
| 287 | + */ |
|
| 288 | + public function restore_by_ID($ID = false) |
|
| 289 | + { |
|
| 290 | + return $this->delete_or_restore_by_ID(false, $ID); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * For deleting or restoring a particular item. Note that this model is a SOFT-DELETABLE model! However, |
|
| 297 | + * this function will ignore whether the items have been soft-deleted or not. |
|
| 298 | + * |
|
| 299 | + * @param boolean $delete true for delete, false for restore |
|
| 300 | + * @param mixed $ID int if primary key is an int, string otherwise |
|
| 301 | + * @return boolean |
|
| 302 | + */ |
|
| 303 | + public function delete_or_restore_by_ID($delete = true, $ID = false) |
|
| 304 | + { |
|
| 305 | + if (! $ID) { |
|
| 306 | + return false; |
|
| 307 | + } |
|
| 308 | + if ( |
|
| 309 | + $this->delete_or_restore( |
|
| 310 | + $delete, |
|
| 311 | + $this->alter_query_params_to_restrict_by_ID($ID) |
|
| 312 | + ) |
|
| 313 | + ) { |
|
| 314 | + return true; |
|
| 315 | + } else { |
|
| 316 | + return false; |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Overrides parent's 'delete' method to instead do a soft delete on all rows that |
|
| 324 | + * meet the criteria in $where_col_n_values. This particular function ignores whether the items have been soft-deleted or not. |
|
| 325 | + * Note: because this item will be soft-deleted only, |
|
| 326 | + * doesn't block because of model dependencies |
|
| 327 | + * |
|
| 328 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 329 | + * @param bool $block_deletes |
|
| 330 | + * @return boolean |
|
| 331 | + */ |
|
| 332 | + public function delete($query_params = array(), $block_deletes = false) |
|
| 333 | + { |
|
| 334 | + // no matter what, we WON'T block soft deletes. |
|
| 335 | + return $this->delete_or_restore(true, $query_params); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * 'Un-deletes' the chosen items. Note that this model is a SOFT-DELETABLE model! That means that, by default, trashed/soft-deleted |
|
| 342 | + * items are ignored in queries. However, this particular function ignores whether the items have been soft-deleted or not. |
|
| 343 | + * |
|
| 344 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 345 | + * @return boolean |
|
| 346 | + */ |
|
| 347 | + public function restore($query_params = array()) |
|
| 348 | + { |
|
| 349 | + return $this->delete_or_restore(false, $query_params); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered. |
|
| 356 | + * |
|
| 357 | + * @param boolean $delete true to indicate deletion, false to indicate restoration |
|
| 358 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 359 | + * @return boolean |
|
| 360 | + */ |
|
| 361 | + public function delete_or_restore($delete = true, $query_params = array()) |
|
| 362 | + { |
|
| 363 | + $deletedFlagFieldName = $this->deleted_field_name(); |
|
| 364 | + $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
| 365 | + if ($this->update(array($deletedFlagFieldName => $delete), $query_params)) { |
|
| 366 | + return true; |
|
| 367 | + } else { |
|
| 368 | + return false; |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Updates all the items of this model which match the $query params, regardless of whether |
|
| 376 | + * they've been soft-deleted or not |
|
| 377 | + * |
|
| 378 | + * @param array $fields_n_values like EEM_Base::update's $fields_n_value |
|
| 379 | + * @param array $query_params like EEM_base::get_all's $query_params |
|
| 380 | + * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects |
|
| 381 | + * in this model's entity map according to $fields_n_values that match $query_params. This |
|
| 382 | + * obviously has some overhead, so you can disable it by setting this to FALSE, but |
|
| 383 | + * be aware that model objects being used could get out-of-sync with the database |
|
| 384 | + * @return int number of items updated |
|
| 385 | + */ |
|
| 386 | + public function update_deleted_and_undeleted($fields_n_values, $query_params, $keep_model_objs_in_sync = true) |
|
| 387 | + { |
|
| 388 | + $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
| 389 | + return $this->update($fields_n_values, $query_params, $keep_model_objs_in_sync); |
|
| 390 | + } |
|
| 391 | 391 | } |
@@ -19,2678 +19,2678 @@ |
||
| 19 | 19 | class Events_Admin_Page extends EE_Admin_Page_CPT |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * This will hold the event object for event_details screen. |
|
| 24 | - * |
|
| 25 | - * @var EE_Event $_event |
|
| 26 | - */ |
|
| 27 | - protected $_event; |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * This will hold the category object for category_details screen. |
|
| 32 | - * |
|
| 33 | - * @var stdClass $_category |
|
| 34 | - */ |
|
| 35 | - protected $_category; |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * This will hold the event model instance |
|
| 40 | - * |
|
| 41 | - * @var EEM_Event $_event_model |
|
| 42 | - */ |
|
| 43 | - protected $_event_model; |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var EE_Event |
|
| 48 | - */ |
|
| 49 | - protected $_cpt_model_obj = false; |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var NodeGroupDao |
|
| 54 | - */ |
|
| 55 | - protected $model_obj_node_group_persister; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Initialize page props for this admin page group. |
|
| 59 | - */ |
|
| 60 | - protected function _init_page_props() |
|
| 61 | - { |
|
| 62 | - $this->page_slug = EVENTS_PG_SLUG; |
|
| 63 | - $this->page_label = EVENTS_LABEL; |
|
| 64 | - $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 65 | - $this->_admin_base_path = EVENTS_ADMIN; |
|
| 66 | - $this->_cpt_model_names = array( |
|
| 67 | - 'create_new' => 'EEM_Event', |
|
| 68 | - 'edit' => 'EEM_Event', |
|
| 69 | - ); |
|
| 70 | - $this->_cpt_edit_routes = array( |
|
| 71 | - 'espresso_events' => 'edit', |
|
| 72 | - ); |
|
| 73 | - add_action( |
|
| 74 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 75 | - array($this, 'verify_event_edit'), |
|
| 76 | - 10, |
|
| 77 | - 2 |
|
| 78 | - ); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Sets the ajax hooks used for this admin page group. |
|
| 84 | - */ |
|
| 85 | - protected function _ajax_hooks() |
|
| 86 | - { |
|
| 87 | - add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting')); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Sets the page properties for this admin page group. |
|
| 93 | - */ |
|
| 94 | - protected function _define_page_props() |
|
| 95 | - { |
|
| 96 | - $this->_admin_page_title = EVENTS_LABEL; |
|
| 97 | - $this->_labels = array( |
|
| 98 | - 'buttons' => array( |
|
| 99 | - 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 100 | - 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 101 | - 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 102 | - 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 103 | - 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 104 | - 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 105 | - ), |
|
| 106 | - 'editor_title' => array( |
|
| 107 | - 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 108 | - ), |
|
| 109 | - 'publishbox' => array( |
|
| 110 | - 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 111 | - 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 112 | - 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 113 | - 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 114 | - 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 115 | - ), |
|
| 116 | - ); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Sets the page routes property for this admin page group. |
|
| 122 | - */ |
|
| 123 | - protected function _set_page_routes() |
|
| 124 | - { |
|
| 125 | - // load formatter helper |
|
| 126 | - // load field generator helper |
|
| 127 | - // is there a evt_id in the request? |
|
| 128 | - $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 129 | - ? $this->_req_data['EVT_ID'] |
|
| 130 | - : 0; |
|
| 131 | - $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 132 | - $this->_page_routes = array( |
|
| 133 | - 'default' => array( |
|
| 134 | - 'func' => '_events_overview_list_table', |
|
| 135 | - 'capability' => 'ee_read_events', |
|
| 136 | - ), |
|
| 137 | - 'create_new' => array( |
|
| 138 | - 'func' => '_create_new_cpt_item', |
|
| 139 | - 'capability' => 'ee_edit_events', |
|
| 140 | - ), |
|
| 141 | - 'edit' => array( |
|
| 142 | - 'func' => '_edit_cpt_item', |
|
| 143 | - 'capability' => 'ee_edit_event', |
|
| 144 | - 'obj_id' => $evt_id, |
|
| 145 | - ), |
|
| 146 | - 'copy_event' => array( |
|
| 147 | - 'func' => '_copy_events', |
|
| 148 | - 'capability' => 'ee_edit_event', |
|
| 149 | - 'obj_id' => $evt_id, |
|
| 150 | - 'noheader' => true, |
|
| 151 | - ), |
|
| 152 | - 'trash_event' => array( |
|
| 153 | - 'func' => '_trash_or_restore_event', |
|
| 154 | - 'args' => array('event_status' => 'trash'), |
|
| 155 | - 'capability' => 'ee_delete_event', |
|
| 156 | - 'obj_id' => $evt_id, |
|
| 157 | - 'noheader' => true, |
|
| 158 | - ), |
|
| 159 | - 'trash_events' => array( |
|
| 160 | - 'func' => '_trash_or_restore_events', |
|
| 161 | - 'args' => array('event_status' => 'trash'), |
|
| 162 | - 'capability' => 'ee_delete_events', |
|
| 163 | - 'noheader' => true, |
|
| 164 | - ), |
|
| 165 | - 'restore_event' => array( |
|
| 166 | - 'func' => '_trash_or_restore_event', |
|
| 167 | - 'args' => array('event_status' => 'draft'), |
|
| 168 | - 'capability' => 'ee_delete_event', |
|
| 169 | - 'obj_id' => $evt_id, |
|
| 170 | - 'noheader' => true, |
|
| 171 | - ), |
|
| 172 | - 'restore_events' => array( |
|
| 173 | - 'func' => '_trash_or_restore_events', |
|
| 174 | - 'args' => array('event_status' => 'draft'), |
|
| 175 | - 'capability' => 'ee_delete_events', |
|
| 176 | - 'noheader' => true, |
|
| 177 | - ), |
|
| 178 | - 'delete_event' => array( |
|
| 179 | - 'func' => '_delete_event', |
|
| 180 | - 'capability' => 'ee_delete_event', |
|
| 181 | - 'obj_id' => $evt_id, |
|
| 182 | - 'noheader' => true, |
|
| 183 | - ), |
|
| 184 | - 'delete_events' => array( |
|
| 185 | - 'func' => '_delete_events', |
|
| 186 | - 'capability' => 'ee_delete_events', |
|
| 187 | - 'noheader' => true, |
|
| 188 | - ), |
|
| 189 | - 'view_report' => array( |
|
| 190 | - 'func' => '_view_report', |
|
| 191 | - 'capablity' => 'ee_edit_events', |
|
| 192 | - ), |
|
| 193 | - 'default_event_settings' => array( |
|
| 194 | - 'func' => '_default_event_settings', |
|
| 195 | - 'capability' => 'manage_options', |
|
| 196 | - ), |
|
| 197 | - 'update_default_event_settings' => array( |
|
| 198 | - 'func' => '_update_default_event_settings', |
|
| 199 | - 'capability' => 'manage_options', |
|
| 200 | - 'noheader' => true, |
|
| 201 | - ), |
|
| 202 | - 'template_settings' => array( |
|
| 203 | - 'func' => '_template_settings', |
|
| 204 | - 'capability' => 'manage_options', |
|
| 205 | - ), |
|
| 206 | - // event category tab related |
|
| 207 | - 'add_category' => array( |
|
| 208 | - 'func' => '_category_details', |
|
| 209 | - 'capability' => 'ee_edit_event_category', |
|
| 210 | - 'args' => array('add'), |
|
| 211 | - ), |
|
| 212 | - 'edit_category' => array( |
|
| 213 | - 'func' => '_category_details', |
|
| 214 | - 'capability' => 'ee_edit_event_category', |
|
| 215 | - 'args' => array('edit'), |
|
| 216 | - ), |
|
| 217 | - 'delete_categories' => array( |
|
| 218 | - 'func' => '_delete_categories', |
|
| 219 | - 'capability' => 'ee_delete_event_category', |
|
| 220 | - 'noheader' => true, |
|
| 221 | - ), |
|
| 222 | - 'delete_category' => array( |
|
| 223 | - 'func' => '_delete_categories', |
|
| 224 | - 'capability' => 'ee_delete_event_category', |
|
| 225 | - 'noheader' => true, |
|
| 226 | - ), |
|
| 227 | - 'insert_category' => array( |
|
| 228 | - 'func' => '_insert_or_update_category', |
|
| 229 | - 'args' => array('new_category' => true), |
|
| 230 | - 'capability' => 'ee_edit_event_category', |
|
| 231 | - 'noheader' => true, |
|
| 232 | - ), |
|
| 233 | - 'update_category' => array( |
|
| 234 | - 'func' => '_insert_or_update_category', |
|
| 235 | - 'args' => array('new_category' => false), |
|
| 236 | - 'capability' => 'ee_edit_event_category', |
|
| 237 | - 'noheader' => true, |
|
| 238 | - ), |
|
| 239 | - 'category_list' => array( |
|
| 240 | - 'func' => '_category_list_table', |
|
| 241 | - 'capability' => 'ee_manage_event_categories', |
|
| 242 | - ), |
|
| 243 | - 'preview_deletion' => [ |
|
| 244 | - 'func' => 'previewDeletion', |
|
| 245 | - 'capability' => 'ee_delete_events', |
|
| 246 | - ], |
|
| 247 | - 'confirm_deletion' => [ |
|
| 248 | - 'func' => 'confirmDeletion', |
|
| 249 | - 'capability' => 'ee_delete_events', |
|
| 250 | - 'noheader' => true, |
|
| 251 | - ] |
|
| 252 | - ); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * Set the _page_config property for this admin page group. |
|
| 258 | - */ |
|
| 259 | - protected function _set_page_config() |
|
| 260 | - { |
|
| 261 | - $this->_page_config = array( |
|
| 262 | - 'default' => array( |
|
| 263 | - 'nav' => array( |
|
| 264 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 265 | - 'order' => 10, |
|
| 266 | - ), |
|
| 267 | - 'list_table' => 'Events_Admin_List_Table', |
|
| 268 | - 'help_tabs' => array( |
|
| 269 | - 'events_overview_help_tab' => array( |
|
| 270 | - 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 271 | - 'filename' => 'events_overview', |
|
| 272 | - ), |
|
| 273 | - 'events_overview_table_column_headings_help_tab' => array( |
|
| 274 | - 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 275 | - 'filename' => 'events_overview_table_column_headings', |
|
| 276 | - ), |
|
| 277 | - 'events_overview_filters_help_tab' => array( |
|
| 278 | - 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 279 | - 'filename' => 'events_overview_filters', |
|
| 280 | - ), |
|
| 281 | - 'events_overview_view_help_tab' => array( |
|
| 282 | - 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 283 | - 'filename' => 'events_overview_views', |
|
| 284 | - ), |
|
| 285 | - 'events_overview_other_help_tab' => array( |
|
| 286 | - 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 287 | - 'filename' => 'events_overview_other', |
|
| 288 | - ), |
|
| 289 | - ), |
|
| 290 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 291 | - // 'help_tour' => array( |
|
| 292 | - // 'Event_Overview_Help_Tour', |
|
| 293 | - // // 'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 294 | - // ), |
|
| 295 | - 'qtips' => array( |
|
| 296 | - 'EE_Event_List_Table_Tips', |
|
| 297 | - ), |
|
| 298 | - 'require_nonce' => false, |
|
| 299 | - ), |
|
| 300 | - 'create_new' => array( |
|
| 301 | - 'nav' => array( |
|
| 302 | - 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 303 | - 'order' => 5, |
|
| 304 | - 'persistent' => false, |
|
| 305 | - ), |
|
| 306 | - 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 307 | - 'help_tabs' => array( |
|
| 308 | - 'event_editor_help_tab' => array( |
|
| 309 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 310 | - 'filename' => 'event_editor', |
|
| 311 | - ), |
|
| 312 | - 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 313 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 314 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 315 | - ), |
|
| 316 | - 'event_editor_venue_details_help_tab' => array( |
|
| 317 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 318 | - 'filename' => 'event_editor_venue_details', |
|
| 319 | - ), |
|
| 320 | - 'event_editor_event_datetimes_help_tab' => array( |
|
| 321 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 322 | - 'filename' => 'event_editor_event_datetimes', |
|
| 323 | - ), |
|
| 324 | - 'event_editor_event_tickets_help_tab' => array( |
|
| 325 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 326 | - 'filename' => 'event_editor_event_tickets', |
|
| 327 | - ), |
|
| 328 | - 'event_editor_event_registration_options_help_tab' => array( |
|
| 329 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 330 | - 'filename' => 'event_editor_event_registration_options', |
|
| 331 | - ), |
|
| 332 | - 'event_editor_tags_categories_help_tab' => array( |
|
| 333 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 334 | - 'filename' => 'event_editor_tags_categories', |
|
| 335 | - ), |
|
| 336 | - 'event_editor_questions_registrants_help_tab' => array( |
|
| 337 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 338 | - 'filename' => 'event_editor_questions_registrants', |
|
| 339 | - ), |
|
| 340 | - 'event_editor_save_new_event_help_tab' => array( |
|
| 341 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 342 | - 'filename' => 'event_editor_save_new_event', |
|
| 343 | - ), |
|
| 344 | - 'event_editor_other_help_tab' => array( |
|
| 345 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 346 | - 'filename' => 'event_editor_other', |
|
| 347 | - ), |
|
| 348 | - ), |
|
| 349 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 350 | - // 'help_tour' => array( |
|
| 351 | - // 'Event_Editor_Help_Tour', |
|
| 352 | - // ), |
|
| 353 | - 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 354 | - 'require_nonce' => false, |
|
| 355 | - ), |
|
| 356 | - 'edit' => array( |
|
| 357 | - 'nav' => array( |
|
| 358 | - 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 359 | - 'order' => 5, |
|
| 360 | - 'persistent' => false, |
|
| 361 | - 'url' => isset($this->_req_data['post']) |
|
| 362 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 363 | - array('post' => $this->_req_data['post'], 'action' => 'edit'), |
|
| 364 | - $this->_current_page_view_url |
|
| 365 | - ) |
|
| 366 | - : $this->_admin_base_url, |
|
| 367 | - ), |
|
| 368 | - 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 369 | - 'help_tabs' => array( |
|
| 370 | - 'event_editor_help_tab' => array( |
|
| 371 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 372 | - 'filename' => 'event_editor', |
|
| 373 | - ), |
|
| 374 | - 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 375 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 376 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 377 | - ), |
|
| 378 | - 'event_editor_venue_details_help_tab' => array( |
|
| 379 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 380 | - 'filename' => 'event_editor_venue_details', |
|
| 381 | - ), |
|
| 382 | - 'event_editor_event_datetimes_help_tab' => array( |
|
| 383 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 384 | - 'filename' => 'event_editor_event_datetimes', |
|
| 385 | - ), |
|
| 386 | - 'event_editor_event_tickets_help_tab' => array( |
|
| 387 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 388 | - 'filename' => 'event_editor_event_tickets', |
|
| 389 | - ), |
|
| 390 | - 'event_editor_event_registration_options_help_tab' => array( |
|
| 391 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 392 | - 'filename' => 'event_editor_event_registration_options', |
|
| 393 | - ), |
|
| 394 | - 'event_editor_tags_categories_help_tab' => array( |
|
| 395 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 396 | - 'filename' => 'event_editor_tags_categories', |
|
| 397 | - ), |
|
| 398 | - 'event_editor_questions_registrants_help_tab' => array( |
|
| 399 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 400 | - 'filename' => 'event_editor_questions_registrants', |
|
| 401 | - ), |
|
| 402 | - 'event_editor_save_new_event_help_tab' => array( |
|
| 403 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 404 | - 'filename' => 'event_editor_save_new_event', |
|
| 405 | - ), |
|
| 406 | - 'event_editor_other_help_tab' => array( |
|
| 407 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 408 | - 'filename' => 'event_editor_other', |
|
| 409 | - ), |
|
| 410 | - ), |
|
| 411 | - 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 412 | - 'require_nonce' => false, |
|
| 413 | - ), |
|
| 414 | - 'default_event_settings' => array( |
|
| 415 | - 'nav' => array( |
|
| 416 | - 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 417 | - 'order' => 40, |
|
| 418 | - ), |
|
| 419 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 420 | - 'labels' => array( |
|
| 421 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 422 | - ), |
|
| 423 | - 'help_tabs' => array( |
|
| 424 | - 'default_settings_help_tab' => array( |
|
| 425 | - 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 426 | - 'filename' => 'events_default_settings', |
|
| 427 | - ), |
|
| 428 | - 'default_settings_status_help_tab' => array( |
|
| 429 | - 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 430 | - 'filename' => 'events_default_settings_status', |
|
| 431 | - ), |
|
| 432 | - 'default_maximum_tickets_help_tab' => array( |
|
| 433 | - 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
| 434 | - 'filename' => 'events_default_settings_max_tickets', |
|
| 435 | - ), |
|
| 436 | - ), |
|
| 437 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 438 | - // 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
| 439 | - 'require_nonce' => false, |
|
| 440 | - ), |
|
| 441 | - // template settings |
|
| 442 | - 'template_settings' => array( |
|
| 443 | - 'nav' => array( |
|
| 444 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 445 | - 'order' => 30, |
|
| 446 | - ), |
|
| 447 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 448 | - 'help_tabs' => array( |
|
| 449 | - 'general_settings_templates_help_tab' => array( |
|
| 450 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 451 | - 'filename' => 'general_settings_templates', |
|
| 452 | - ), |
|
| 453 | - ), |
|
| 454 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 455 | - // 'help_tour' => array('Templates_Help_Tour'), |
|
| 456 | - 'require_nonce' => false, |
|
| 457 | - ), |
|
| 458 | - // event category stuff |
|
| 459 | - 'add_category' => array( |
|
| 460 | - 'nav' => array( |
|
| 461 | - 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 462 | - 'order' => 15, |
|
| 463 | - 'persistent' => false, |
|
| 464 | - ), |
|
| 465 | - 'help_tabs' => array( |
|
| 466 | - 'add_category_help_tab' => array( |
|
| 467 | - 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 468 | - 'filename' => 'events_add_category', |
|
| 469 | - ), |
|
| 470 | - ), |
|
| 471 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 472 | - // 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
| 473 | - 'metaboxes' => array('_publish_post_box'), |
|
| 474 | - 'require_nonce' => false, |
|
| 475 | - ), |
|
| 476 | - 'edit_category' => array( |
|
| 477 | - 'nav' => array( |
|
| 478 | - 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 479 | - 'order' => 15, |
|
| 480 | - 'persistent' => false, |
|
| 481 | - 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
| 482 | - ? add_query_arg( |
|
| 483 | - array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), |
|
| 484 | - $this->_current_page_view_url |
|
| 485 | - ) |
|
| 486 | - : $this->_admin_base_url, |
|
| 487 | - ), |
|
| 488 | - 'help_tabs' => array( |
|
| 489 | - 'edit_category_help_tab' => array( |
|
| 490 | - 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 491 | - 'filename' => 'events_edit_category', |
|
| 492 | - ), |
|
| 493 | - ), |
|
| 494 | - /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
| 495 | - 'metaboxes' => array('_publish_post_box'), |
|
| 496 | - 'require_nonce' => false, |
|
| 497 | - ), |
|
| 498 | - 'category_list' => array( |
|
| 499 | - 'nav' => array( |
|
| 500 | - 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 501 | - 'order' => 20, |
|
| 502 | - ), |
|
| 503 | - 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 504 | - 'help_tabs' => array( |
|
| 505 | - 'events_categories_help_tab' => array( |
|
| 506 | - 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 507 | - 'filename' => 'events_categories', |
|
| 508 | - ), |
|
| 509 | - 'events_categories_table_column_headings_help_tab' => array( |
|
| 510 | - 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 511 | - 'filename' => 'events_categories_table_column_headings', |
|
| 512 | - ), |
|
| 513 | - 'events_categories_view_help_tab' => array( |
|
| 514 | - 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 515 | - 'filename' => 'events_categories_views', |
|
| 516 | - ), |
|
| 517 | - 'events_categories_other_help_tab' => array( |
|
| 518 | - 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 519 | - 'filename' => 'events_categories_other', |
|
| 520 | - ), |
|
| 521 | - ), |
|
| 522 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 523 | - // 'help_tour' => array( |
|
| 524 | - // 'Event_Categories_Help_Tour', |
|
| 525 | - // ), |
|
| 526 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 527 | - 'require_nonce' => false, |
|
| 528 | - ), |
|
| 529 | - 'preview_deletion' => array( |
|
| 530 | - 'nav' => array( |
|
| 531 | - 'label' => esc_html__('Preview Deletion', 'event_espresso'), |
|
| 532 | - 'order' => 15, |
|
| 533 | - 'persistent' => false, |
|
| 534 | - 'url' => '', |
|
| 535 | - ), |
|
| 536 | - 'require_nonce' => false |
|
| 537 | - ) |
|
| 538 | - ); |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * Used to register any global screen options if necessary for every route in this admin page group. |
|
| 544 | - */ |
|
| 545 | - protected function _add_screen_options() |
|
| 546 | - { |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - |
|
| 550 | - /** |
|
| 551 | - * Implementing the screen options for the 'default' route. |
|
| 552 | - */ |
|
| 553 | - protected function _add_screen_options_default() |
|
| 554 | - { |
|
| 555 | - $this->_per_page_screen_option(); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * Implementing screen options for the category list route. |
|
| 561 | - */ |
|
| 562 | - protected function _add_screen_options_category_list() |
|
| 563 | - { |
|
| 564 | - $page_title = $this->_admin_page_title; |
|
| 565 | - $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 566 | - $this->_per_page_screen_option(); |
|
| 567 | - $this->_admin_page_title = $page_title; |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * Used to register any global feature pointers for the admin page group. |
|
| 573 | - */ |
|
| 574 | - protected function _add_feature_pointers() |
|
| 575 | - { |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * Registers and enqueues any global scripts and styles for the entire admin page group. |
|
| 581 | - */ |
|
| 582 | - public function load_scripts_styles() |
|
| 583 | - { |
|
| 584 | - wp_register_style( |
|
| 585 | - 'events-admin-css', |
|
| 586 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 587 | - array(), |
|
| 588 | - EVENT_ESPRESSO_VERSION |
|
| 589 | - ); |
|
| 590 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 591 | - wp_enqueue_style('events-admin-css'); |
|
| 592 | - wp_enqueue_style('ee-cat-admin'); |
|
| 593 | - // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
| 594 | - // registers for all views |
|
| 595 | - // scripts |
|
| 596 | - wp_register_script( |
|
| 597 | - 'event_editor_js', |
|
| 598 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 599 | - array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
|
| 600 | - EVENT_ESPRESSO_VERSION, |
|
| 601 | - true |
|
| 602 | - ); |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - |
|
| 606 | - /** |
|
| 607 | - * Enqueuing scripts and styles specific to this view |
|
| 608 | - */ |
|
| 609 | - public function load_scripts_styles_create_new() |
|
| 610 | - { |
|
| 611 | - $this->load_scripts_styles_edit(); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * Enqueuing scripts and styles specific to this view |
|
| 617 | - */ |
|
| 618 | - public function load_scripts_styles_edit() |
|
| 619 | - { |
|
| 620 | - // styles |
|
| 621 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 622 | - wp_register_style( |
|
| 623 | - 'event-editor-css', |
|
| 624 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 625 | - array('ee-admin-css'), |
|
| 626 | - EVENT_ESPRESSO_VERSION |
|
| 627 | - ); |
|
| 628 | - wp_enqueue_style('event-editor-css'); |
|
| 629 | - // scripts |
|
| 630 | - wp_register_script( |
|
| 631 | - 'event-datetime-metabox', |
|
| 632 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 633 | - array('event_editor_js', 'ee-datepicker'), |
|
| 634 | - EVENT_ESPRESSO_VERSION |
|
| 635 | - ); |
|
| 636 | - wp_enqueue_script('event-datetime-metabox'); |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - |
|
| 640 | - /** |
|
| 641 | - * Populating the _views property for the category list table view. |
|
| 642 | - */ |
|
| 643 | - protected function _set_list_table_views_category_list() |
|
| 644 | - { |
|
| 645 | - $this->_views = array( |
|
| 646 | - 'all' => array( |
|
| 647 | - 'slug' => 'all', |
|
| 648 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 649 | - 'count' => 0, |
|
| 650 | - 'bulk_action' => array( |
|
| 651 | - 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 652 | - ), |
|
| 653 | - ), |
|
| 654 | - ); |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - |
|
| 658 | - /** |
|
| 659 | - * For adding anything that fires on the admin_init hook for any route within this admin page group. |
|
| 660 | - */ |
|
| 661 | - public function admin_init() |
|
| 662 | - { |
|
| 663 | - EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 664 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 665 | - 'event_espresso' |
|
| 666 | - ); |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * For adding anything that should be triggered on the admin_notices hook for any route within this admin page |
|
| 672 | - * group. |
|
| 673 | - */ |
|
| 674 | - public function admin_notices() |
|
| 675 | - { |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within |
|
| 681 | - * this admin page group. |
|
| 682 | - */ |
|
| 683 | - public function admin_footer_scripts() |
|
| 684 | - { |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 690 | - * warning (via EE_Error::add_error()); |
|
| 691 | - * |
|
| 692 | - * @param EE_Event $event Event object |
|
| 693 | - * @param string $req_type |
|
| 694 | - * @return void |
|
| 695 | - * @throws EE_Error |
|
| 696 | - * @access public |
|
| 697 | - */ |
|
| 698 | - public function verify_event_edit($event = null, $req_type = '') |
|
| 699 | - { |
|
| 700 | - // don't need to do this when processing |
|
| 701 | - if (! empty($req_type)) { |
|
| 702 | - return; |
|
| 703 | - } |
|
| 704 | - // no event? |
|
| 705 | - if (empty($event)) { |
|
| 706 | - // set event |
|
| 707 | - $event = $this->_cpt_model_obj; |
|
| 708 | - } |
|
| 709 | - // STILL no event? |
|
| 710 | - if (! $event instanceof EE_Event) { |
|
| 711 | - return; |
|
| 712 | - } |
|
| 713 | - $orig_status = $event->status(); |
|
| 714 | - // first check if event is active. |
|
| 715 | - if ( |
|
| 716 | - $orig_status === EEM_Event::cancelled |
|
| 717 | - || $orig_status === EEM_Event::postponed |
|
| 718 | - || $event->is_expired() |
|
| 719 | - || $event->is_inactive() |
|
| 720 | - ) { |
|
| 721 | - return; |
|
| 722 | - } |
|
| 723 | - // made it here so it IS active... next check that any of the tickets are sold. |
|
| 724 | - if ($event->is_sold_out(true)) { |
|
| 725 | - if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 726 | - EE_Error::add_attention( |
|
| 727 | - sprintf( |
|
| 728 | - esc_html__( |
|
| 729 | - 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
| 730 | - 'event_espresso' |
|
| 731 | - ), |
|
| 732 | - EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 733 | - ) |
|
| 734 | - ); |
|
| 735 | - } |
|
| 736 | - return; |
|
| 737 | - } elseif ($orig_status === EEM_Event::sold_out) { |
|
| 738 | - EE_Error::add_attention( |
|
| 739 | - sprintf( |
|
| 740 | - esc_html__( |
|
| 741 | - 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
| 742 | - 'event_espresso' |
|
| 743 | - ), |
|
| 744 | - EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 745 | - ) |
|
| 746 | - ); |
|
| 747 | - } |
|
| 748 | - // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 749 | - if (! $event->tickets_on_sale()) { |
|
| 750 | - return; |
|
| 751 | - } |
|
| 752 | - // made it here so show warning |
|
| 753 | - $this->_edit_event_warning(); |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - |
|
| 757 | - /** |
|
| 758 | - * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 759 | - * When needed, hook this into a EE_Error::add_error() notice. |
|
| 760 | - * |
|
| 761 | - * @access protected |
|
| 762 | - * @return void |
|
| 763 | - */ |
|
| 764 | - protected function _edit_event_warning() |
|
| 765 | - { |
|
| 766 | - // we don't want to add warnings during these requests |
|
| 767 | - if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
| 768 | - return; |
|
| 769 | - } |
|
| 770 | - EE_Error::add_attention( |
|
| 771 | - sprintf( |
|
| 772 | - esc_html__( |
|
| 773 | - 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s', |
|
| 774 | - 'event_espresso' |
|
| 775 | - ), |
|
| 776 | - '<a class="espresso-help-tab-lnk">', |
|
| 777 | - '</a>' |
|
| 778 | - ) |
|
| 779 | - ); |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - |
|
| 783 | - /** |
|
| 784 | - * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 785 | - * Otherwise, do the normal logic |
|
| 786 | - * |
|
| 787 | - * @return string |
|
| 788 | - * @throws \EE_Error |
|
| 789 | - */ |
|
| 790 | - protected function _create_new_cpt_item() |
|
| 791 | - { |
|
| 792 | - $has_timezone_string = get_option('timezone_string'); |
|
| 793 | - // only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 794 | - if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) { |
|
| 795 | - EE_Error::add_attention( |
|
| 796 | - sprintf( |
|
| 797 | - esc_html__( |
|
| 798 | - 'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s', |
|
| 799 | - 'event_espresso' |
|
| 800 | - ), |
|
| 801 | - '<br>', |
|
| 802 | - '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">' |
|
| 803 | - . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) |
|
| 804 | - . '</select>', |
|
| 805 | - '<button class="button button-secondary timezone-submit">', |
|
| 806 | - '</button><span class="spinner"></span>' |
|
| 807 | - ), |
|
| 808 | - __FILE__, |
|
| 809 | - __FUNCTION__, |
|
| 810 | - __LINE__ |
|
| 811 | - ); |
|
| 812 | - } |
|
| 813 | - return parent::_create_new_cpt_item(); |
|
| 814 | - } |
|
| 815 | - |
|
| 816 | - |
|
| 817 | - /** |
|
| 818 | - * Sets the _views property for the default route in this admin page group. |
|
| 819 | - */ |
|
| 820 | - protected function _set_list_table_views_default() |
|
| 821 | - { |
|
| 822 | - $this->_views = array( |
|
| 823 | - 'all' => array( |
|
| 824 | - 'slug' => 'all', |
|
| 825 | - 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 826 | - 'count' => 0, |
|
| 827 | - 'bulk_action' => array( |
|
| 828 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 829 | - ), |
|
| 830 | - ), |
|
| 831 | - 'draft' => array( |
|
| 832 | - 'slug' => 'draft', |
|
| 833 | - 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 834 | - 'count' => 0, |
|
| 835 | - 'bulk_action' => array( |
|
| 836 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 837 | - ), |
|
| 838 | - ), |
|
| 839 | - ); |
|
| 840 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 841 | - $this->_views['trash'] = array( |
|
| 842 | - 'slug' => 'trash', |
|
| 843 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 844 | - 'count' => 0, |
|
| 845 | - 'bulk_action' => array( |
|
| 846 | - 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 847 | - 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 848 | - ), |
|
| 849 | - ); |
|
| 850 | - } |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - |
|
| 854 | - /** |
|
| 855 | - * Provides the legend item array for the default list table view. |
|
| 856 | - * |
|
| 857 | - * @return array |
|
| 858 | - */ |
|
| 859 | - protected function _event_legend_items() |
|
| 860 | - { |
|
| 861 | - $items = array( |
|
| 862 | - 'view_details' => array( |
|
| 863 | - 'class' => 'dashicons dashicons-search', |
|
| 864 | - 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 865 | - ), |
|
| 866 | - 'edit_event' => array( |
|
| 867 | - 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 868 | - 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 869 | - ), |
|
| 870 | - 'view_attendees' => array( |
|
| 871 | - 'class' => 'dashicons dashicons-groups', |
|
| 872 | - 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 873 | - ), |
|
| 874 | - ); |
|
| 875 | - $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 876 | - $statuses = array( |
|
| 877 | - 'sold_out_status' => array( |
|
| 878 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 879 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 880 | - ), |
|
| 881 | - 'active_status' => array( |
|
| 882 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 883 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 884 | - ), |
|
| 885 | - 'upcoming_status' => array( |
|
| 886 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 887 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 888 | - ), |
|
| 889 | - 'postponed_status' => array( |
|
| 890 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 891 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 892 | - ), |
|
| 893 | - 'cancelled_status' => array( |
|
| 894 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 895 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 896 | - ), |
|
| 897 | - 'expired_status' => array( |
|
| 898 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 899 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 900 | - ), |
|
| 901 | - 'inactive_status' => array( |
|
| 902 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 903 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 904 | - ), |
|
| 905 | - ); |
|
| 906 | - $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 907 | - return array_merge($items, $statuses); |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - |
|
| 911 | - /** |
|
| 912 | - * @return EEM_Event |
|
| 913 | - */ |
|
| 914 | - private function _event_model() |
|
| 915 | - { |
|
| 916 | - if (! $this->_event_model instanceof EEM_Event) { |
|
| 917 | - $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 918 | - } |
|
| 919 | - return $this->_event_model; |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - |
|
| 923 | - /** |
|
| 924 | - * Adds extra buttons to the WP CPT permalink field row. |
|
| 925 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 926 | - * |
|
| 927 | - * @param string $return the current html |
|
| 928 | - * @param int $id the post id for the page |
|
| 929 | - * @param string $new_title What the title is |
|
| 930 | - * @param string $new_slug what the slug is |
|
| 931 | - * @return string The new html string for the permalink area |
|
| 932 | - */ |
|
| 933 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 934 | - { |
|
| 935 | - // make sure this is only when editing |
|
| 936 | - if (! empty($id)) { |
|
| 937 | - $post = get_post($id); |
|
| 938 | - $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 939 | - . esc_html__('Shortcode', 'event_espresso') |
|
| 940 | - . '</a> '; |
|
| 941 | - $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 942 | - . $post->ID |
|
| 943 | - . ']">'; |
|
| 944 | - } |
|
| 945 | - return $return; |
|
| 946 | - } |
|
| 947 | - |
|
| 948 | - |
|
| 949 | - /** |
|
| 950 | - * _events_overview_list_table |
|
| 951 | - * This contains the logic for showing the events_overview list |
|
| 952 | - * |
|
| 953 | - * @access protected |
|
| 954 | - * @return void |
|
| 955 | - * @throws \EE_Error |
|
| 956 | - */ |
|
| 957 | - protected function _events_overview_list_table() |
|
| 958 | - { |
|
| 959 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 960 | - $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
|
| 961 | - ? (array) $this->_template_args['after_list_table'] |
|
| 962 | - : array(); |
|
| 963 | - $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
| 964 | - . EEH_Template::get_button_or_link( |
|
| 965 | - get_post_type_archive_link('espresso_events'), |
|
| 966 | - esc_html__("View Event Archive Page", "event_espresso"), |
|
| 967 | - 'button' |
|
| 968 | - ); |
|
| 969 | - $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
| 970 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 971 | - 'create_new', |
|
| 972 | - 'add', |
|
| 973 | - array(), |
|
| 974 | - 'add-new-h2' |
|
| 975 | - ); |
|
| 976 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 977 | - } |
|
| 978 | - |
|
| 979 | - |
|
| 980 | - /** |
|
| 981 | - * this allows for extra misc actions in the default WP publish box |
|
| 982 | - * |
|
| 983 | - * @return void |
|
| 984 | - */ |
|
| 985 | - public function extra_misc_actions_publish_box() |
|
| 986 | - { |
|
| 987 | - $this->_generate_publish_box_extra_content(); |
|
| 988 | - } |
|
| 989 | - |
|
| 990 | - |
|
| 991 | - /** |
|
| 992 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 993 | - * saved. |
|
| 994 | - * Typically you would use this to save any additional data. |
|
| 995 | - * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 996 | - * ALSO very important. When a post transitions from scheduled to published, |
|
| 997 | - * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from |
|
| 998 | - * other meta saves. So MAKE sure that you handle this accordingly. |
|
| 999 | - * |
|
| 1000 | - * @access protected |
|
| 1001 | - * @abstract |
|
| 1002 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 1003 | - * @param object $post The post object of the cpt that was saved. |
|
| 1004 | - * @return void |
|
| 1005 | - * @throws \EE_Error |
|
| 1006 | - */ |
|
| 1007 | - protected function _insert_update_cpt_item($post_id, $post) |
|
| 1008 | - { |
|
| 1009 | - if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 1010 | - // get out we're not processing an event save. |
|
| 1011 | - return; |
|
| 1012 | - } |
|
| 1013 | - $event_values = array( |
|
| 1014 | - 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
| 1015 | - 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
| 1016 | - 'EVT_additional_limit' => min( |
|
| 1017 | - apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 1018 | - ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null |
|
| 1019 | - ), |
|
| 1020 | - 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) |
|
| 1021 | - ? $this->_req_data['EVT_default_registration_status'] |
|
| 1022 | - : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 1023 | - 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
| 1024 | - 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
| 1025 | - 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
| 1026 | - ? $this->_req_data['timezone_string'] : null, |
|
| 1027 | - 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) |
|
| 1028 | - ? $this->_req_data['externalURL'] : null, |
|
| 1029 | - 'EVT_phone' => ! empty($this->_req_data['event_phone']) |
|
| 1030 | - ? $this->_req_data['event_phone'] : null, |
|
| 1031 | - ); |
|
| 1032 | - // update event |
|
| 1033 | - $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 1034 | - // get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
|
| 1035 | - $get_one_where = array( |
|
| 1036 | - $this->_event_model()->primary_key_name() => $post_id, |
|
| 1037 | - 'OR' => array( |
|
| 1038 | - 'status' => $post->post_status, |
|
| 1039 | - // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db, |
|
| 1040 | - // but the returned object here has a status of "publish", so use the original post status as well |
|
| 1041 | - 'status*1' => $this->_req_data['original_post_status'], |
|
| 1042 | - ), |
|
| 1043 | - ); |
|
| 1044 | - $event = $this->_event_model()->get_one(array($get_one_where)); |
|
| 1045 | - // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
| 1046 | - $event_update_callbacks = apply_filters( |
|
| 1047 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 1048 | - array( |
|
| 1049 | - array($this, '_default_venue_update'), |
|
| 1050 | - array($this, '_default_tickets_update'), |
|
| 1051 | - ) |
|
| 1052 | - ); |
|
| 1053 | - $att_success = true; |
|
| 1054 | - foreach ($event_update_callbacks as $e_callback) { |
|
| 1055 | - $_success = is_callable($e_callback) |
|
| 1056 | - ? call_user_func($e_callback, $event, $this->_req_data) |
|
| 1057 | - : false; |
|
| 1058 | - // if ANY of these updates fail then we want the appropriate global error message |
|
| 1059 | - $att_success = ! $att_success ? $att_success : $_success; |
|
| 1060 | - } |
|
| 1061 | - // any errors? |
|
| 1062 | - if ($success && false === $att_success) { |
|
| 1063 | - EE_Error::add_error( |
|
| 1064 | - esc_html__( |
|
| 1065 | - 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1066 | - 'event_espresso' |
|
| 1067 | - ), |
|
| 1068 | - __FILE__, |
|
| 1069 | - __FUNCTION__, |
|
| 1070 | - __LINE__ |
|
| 1071 | - ); |
|
| 1072 | - } elseif ($success === false) { |
|
| 1073 | - EE_Error::add_error( |
|
| 1074 | - esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1075 | - __FILE__, |
|
| 1076 | - __FUNCTION__, |
|
| 1077 | - __LINE__ |
|
| 1078 | - ); |
|
| 1079 | - } |
|
| 1080 | - } |
|
| 1081 | - |
|
| 1082 | - |
|
| 1083 | - /** |
|
| 1084 | - * @see parent::restore_item() |
|
| 1085 | - * @param int $post_id |
|
| 1086 | - * @param int $revision_id |
|
| 1087 | - */ |
|
| 1088 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
| 1089 | - { |
|
| 1090 | - // copy existing event meta to new post |
|
| 1091 | - $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 1092 | - if ($post_evt instanceof EE_Event) { |
|
| 1093 | - // meta revision restore |
|
| 1094 | - $post_evt->restore_revision($revision_id); |
|
| 1095 | - // related objs restore |
|
| 1096 | - $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
| 1097 | - } |
|
| 1098 | - } |
|
| 1099 | - |
|
| 1100 | - |
|
| 1101 | - /** |
|
| 1102 | - * Attach the venue to the Event |
|
| 1103 | - * |
|
| 1104 | - * @param \EE_Event $evtobj Event Object to add the venue to |
|
| 1105 | - * @param array $data The request data from the form |
|
| 1106 | - * @return bool Success or fail. |
|
| 1107 | - */ |
|
| 1108 | - protected function _default_venue_update(\EE_Event $evtobj, $data) |
|
| 1109 | - { |
|
| 1110 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1111 | - $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1112 | - $rows_affected = null; |
|
| 1113 | - $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1114 | - // very important. If we don't have a venue name... |
|
| 1115 | - // then we'll get out because not necessary to create empty venue |
|
| 1116 | - if (empty($data['venue_title'])) { |
|
| 1117 | - return false; |
|
| 1118 | - } |
|
| 1119 | - $venue_array = array( |
|
| 1120 | - 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
| 1121 | - 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
| 1122 | - 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1123 | - 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1124 | - 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
| 1125 | - : null, |
|
| 1126 | - 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1127 | - 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1128 | - 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1129 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1130 | - 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1131 | - 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1132 | - 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1133 | - 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1134 | - 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1135 | - 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1136 | - 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1137 | - 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1138 | - 'status' => 'publish', |
|
| 1139 | - ); |
|
| 1140 | - // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1141 | - if (! empty($venue_id)) { |
|
| 1142 | - $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
| 1143 | - $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
| 1144 | - // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
| 1145 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1146 | - return $rows_affected > 0 ? true : false; |
|
| 1147 | - } else { |
|
| 1148 | - // we insert the venue |
|
| 1149 | - $venue_id = $venue_model->insert($venue_array); |
|
| 1150 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1151 | - return ! empty($venue_id) ? true : false; |
|
| 1152 | - } |
|
| 1153 | - // when we have the ancestor come in it's already been handled by the revision save. |
|
| 1154 | - } |
|
| 1155 | - |
|
| 1156 | - |
|
| 1157 | - /** |
|
| 1158 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1159 | - * |
|
| 1160 | - * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 1161 | - * @param array $data The request data from the form |
|
| 1162 | - * @return array |
|
| 1163 | - */ |
|
| 1164 | - protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
| 1165 | - { |
|
| 1166 | - $success = true; |
|
| 1167 | - $saved_dtt = null; |
|
| 1168 | - $saved_tickets = array(); |
|
| 1169 | - $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1170 | - foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 1171 | - // trim all values to ensure any excess whitespace is removed. |
|
| 1172 | - $dtt = array_map('trim', $dtt); |
|
| 1173 | - $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
| 1174 | - : $dtt['DTT_EVT_start']; |
|
| 1175 | - $datetime_values = array( |
|
| 1176 | - 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 1177 | - 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 1178 | - 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 1179 | - 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 1180 | - 'DTT_order' => $row, |
|
| 1181 | - ); |
|
| 1182 | - // if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
| 1183 | - if (! empty($dtt['DTT_ID'])) { |
|
| 1184 | - $DTM = EE_Registry::instance() |
|
| 1185 | - ->load_model('Datetime', array($evtobj->get_timezone())) |
|
| 1186 | - ->get_one_by_ID($dtt['DTT_ID']); |
|
| 1187 | - $DTM->set_date_format($incoming_date_formats[0]); |
|
| 1188 | - $DTM->set_time_format($incoming_date_formats[1]); |
|
| 1189 | - foreach ($datetime_values as $field => $value) { |
|
| 1190 | - $DTM->set($field, $value); |
|
| 1191 | - } |
|
| 1192 | - // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
|
| 1193 | - $saved_dtts[ $DTM->ID() ] = $DTM; |
|
| 1194 | - } else { |
|
| 1195 | - $DTM = EE_Registry::instance()->load_class( |
|
| 1196 | - 'Datetime', |
|
| 1197 | - array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats), |
|
| 1198 | - false, |
|
| 1199 | - false |
|
| 1200 | - ); |
|
| 1201 | - foreach ($datetime_values as $field => $value) { |
|
| 1202 | - $DTM->set($field, $value); |
|
| 1203 | - } |
|
| 1204 | - } |
|
| 1205 | - $DTM->save(); |
|
| 1206 | - $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
| 1207 | - // load DTT helper |
|
| 1208 | - // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1209 | - if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
| 1210 | - $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
| 1211 | - $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
| 1212 | - $DTT->save(); |
|
| 1213 | - } |
|
| 1214 | - // now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave. |
|
| 1215 | - $saved_dtt = $DTT; |
|
| 1216 | - $success = ! $success ? $success : $DTT; |
|
| 1217 | - // if ANY of these updates fail then we want the appropriate global error message. |
|
| 1218 | - // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
| 1219 | - } |
|
| 1220 | - // no dtts get deleted so we don't do any of that logic here. |
|
| 1221 | - // update tickets next |
|
| 1222 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 1223 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 1224 | - $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1225 | - $update_prices = false; |
|
| 1226 | - $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
| 1227 | - ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0; |
|
| 1228 | - // trim inputs to ensure any excess whitespace is removed. |
|
| 1229 | - $tkt = array_map('trim', $tkt); |
|
| 1230 | - if (empty($tkt['TKT_start_date'])) { |
|
| 1231 | - // let's use now in the set timezone. |
|
| 1232 | - $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
| 1233 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1234 | - } |
|
| 1235 | - if (empty($tkt['TKT_end_date'])) { |
|
| 1236 | - // use the start date of the first datetime |
|
| 1237 | - $dtt = $evtobj->first_datetime(); |
|
| 1238 | - $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
| 1239 | - $incoming_date_formats[0], |
|
| 1240 | - $incoming_date_formats[1] |
|
| 1241 | - ); |
|
| 1242 | - } |
|
| 1243 | - $TKT_values = array( |
|
| 1244 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 1245 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 1246 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 1247 | - 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
| 1248 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 1249 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 1250 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 1251 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 1252 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 1253 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 1254 | - 'TKT_row' => $row, |
|
| 1255 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
| 1256 | - 'TKT_price' => $ticket_price, |
|
| 1257 | - ); |
|
| 1258 | - // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
| 1259 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 1260 | - $TKT_values['TKT_ID'] = 0; |
|
| 1261 | - $TKT_values['TKT_is_default'] = 0; |
|
| 1262 | - $TKT_values['TKT_price'] = $ticket_price; |
|
| 1263 | - $update_prices = true; |
|
| 1264 | - } |
|
| 1265 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1266 | - // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
| 1267 | - // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1268 | - if (! empty($tkt['TKT_ID'])) { |
|
| 1269 | - $TKT = EE_Registry::instance() |
|
| 1270 | - ->load_model('Ticket', array($evtobj->get_timezone())) |
|
| 1271 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
| 1272 | - if ($TKT instanceof EE_Ticket) { |
|
| 1273 | - $ticket_sold = $TKT->count_related( |
|
| 1274 | - 'Registration', |
|
| 1275 | - array( |
|
| 1276 | - array( |
|
| 1277 | - 'STS_ID' => array( |
|
| 1278 | - 'NOT IN', |
|
| 1279 | - array(EEM_Registration::status_id_incomplete), |
|
| 1280 | - ), |
|
| 1281 | - ), |
|
| 1282 | - ) |
|
| 1283 | - ) > 0 ? true : false; |
|
| 1284 | - // let's just check the total price for the existing ticket and determine if it matches the new total price. if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket. |
|
| 1285 | - $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') |
|
| 1286 | - && ! $TKT->get('TKT_deleted'); |
|
| 1287 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1288 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1289 | - // set new values |
|
| 1290 | - foreach ($TKT_values as $field => $value) { |
|
| 1291 | - if ($field == 'TKT_qty') { |
|
| 1292 | - $TKT->set_qty($value); |
|
| 1293 | - } else { |
|
| 1294 | - $TKT->set($field, $value); |
|
| 1295 | - } |
|
| 1296 | - } |
|
| 1297 | - // if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
| 1298 | - if ($create_new_TKT) { |
|
| 1299 | - // archive the old ticket first |
|
| 1300 | - $TKT->set('TKT_deleted', 1); |
|
| 1301 | - $TKT->save(); |
|
| 1302 | - // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
| 1303 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1304 | - // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
|
| 1305 | - $TKT = clone $TKT; |
|
| 1306 | - $TKT->set('TKT_ID', 0); |
|
| 1307 | - $TKT->set('TKT_deleted', 0); |
|
| 1308 | - $TKT->set('TKT_price', $ticket_price); |
|
| 1309 | - $TKT->set('TKT_sold', 0); |
|
| 1310 | - // now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1311 | - $update_prices = true; |
|
| 1312 | - } |
|
| 1313 | - // make sure price is set if it hasn't been already |
|
| 1314 | - $TKT->set('TKT_price', $ticket_price); |
|
| 1315 | - } |
|
| 1316 | - } else { |
|
| 1317 | - // no TKT_id so a new TKT |
|
| 1318 | - $TKT_values['TKT_price'] = $ticket_price; |
|
| 1319 | - $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); |
|
| 1320 | - if ($TKT instanceof EE_Ticket) { |
|
| 1321 | - // need to reset values to properly account for the date formats |
|
| 1322 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1323 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1324 | - $TKT->set_timezone($evtobj->get_timezone()); |
|
| 1325 | - // set new values |
|
| 1326 | - foreach ($TKT_values as $field => $value) { |
|
| 1327 | - if ($field == 'TKT_qty') { |
|
| 1328 | - $TKT->set_qty($value); |
|
| 1329 | - } else { |
|
| 1330 | - $TKT->set($field, $value); |
|
| 1331 | - } |
|
| 1332 | - } |
|
| 1333 | - $update_prices = true; |
|
| 1334 | - } |
|
| 1335 | - } |
|
| 1336 | - // cap ticket qty by datetime reg limits |
|
| 1337 | - $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
| 1338 | - // update ticket. |
|
| 1339 | - $TKT->save(); |
|
| 1340 | - // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1341 | - if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 1342 | - $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 1343 | - $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 1344 | - $TKT->save(); |
|
| 1345 | - } |
|
| 1346 | - // initially let's add the ticket to the dtt |
|
| 1347 | - $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
| 1348 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1349 | - // add prices to ticket |
|
| 1350 | - $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices); |
|
| 1351 | - } |
|
| 1352 | - // however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1353 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
| 1354 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1355 | - foreach ($tickets_removed as $id) { |
|
| 1356 | - $id = absint($id); |
|
| 1357 | - // get the ticket for this id |
|
| 1358 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 1359 | - if (! $tkt_to_remove instanceof EE_Ticket) { |
|
| 1360 | - continue; |
|
| 1361 | - } |
|
| 1362 | - |
|
| 1363 | - // need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 1364 | - $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 1365 | - foreach ($dtts as $dtt) { |
|
| 1366 | - $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 1367 | - } |
|
| 1368 | - // need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1369 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
| 1370 | - // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1371 | - $tkt_to_remove->delete_permanently(); |
|
| 1372 | - } |
|
| 1373 | - return array($saved_dtt, $saved_tickets); |
|
| 1374 | - } |
|
| 1375 | - |
|
| 1376 | - |
|
| 1377 | - /** |
|
| 1378 | - * This attaches a list of given prices to a ticket. |
|
| 1379 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 1380 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 1381 | - * price info and prices are automatically "archived" via the ticket. |
|
| 1382 | - * |
|
| 1383 | - * @access private |
|
| 1384 | - * @param array $prices Array of prices from the form. |
|
| 1385 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1386 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1387 | - * @return void |
|
| 1388 | - */ |
|
| 1389 | - private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
| 1390 | - { |
|
| 1391 | - foreach ($prices as $row => $prc) { |
|
| 1392 | - $PRC_values = array( |
|
| 1393 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 1394 | - 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
| 1395 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 1396 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 1397 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 1398 | - 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context |
|
| 1399 | - 'PRC_order' => $row, |
|
| 1400 | - ); |
|
| 1401 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 1402 | - $PRC_values['PRC_ID'] = 0; |
|
| 1403 | - $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
| 1404 | - } else { |
|
| 1405 | - $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 1406 | - // update this price with new values |
|
| 1407 | - foreach ($PRC_values as $field => $newprc) { |
|
| 1408 | - $PRC->set($field, $newprc); |
|
| 1409 | - } |
|
| 1410 | - $PRC->save(); |
|
| 1411 | - } |
|
| 1412 | - $ticket->_add_relation_to($PRC, 'Price'); |
|
| 1413 | - } |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - |
|
| 1417 | - /** |
|
| 1418 | - * Add in our autosave ajax handlers |
|
| 1419 | - * |
|
| 1420 | - */ |
|
| 1421 | - protected function _ee_autosave_create_new() |
|
| 1422 | - { |
|
| 1423 | - } |
|
| 1424 | - |
|
| 1425 | - |
|
| 1426 | - /** |
|
| 1427 | - * More autosave handlers. |
|
| 1428 | - */ |
|
| 1429 | - protected function _ee_autosave_edit() |
|
| 1430 | - { |
|
| 1431 | - return; // TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
| 1432 | - } |
|
| 1433 | - |
|
| 1434 | - |
|
| 1435 | - /** |
|
| 1436 | - * _generate_publish_box_extra_content |
|
| 1437 | - */ |
|
| 1438 | - private function _generate_publish_box_extra_content() |
|
| 1439 | - { |
|
| 1440 | - // load formatter helper |
|
| 1441 | - // args for getting related registrations |
|
| 1442 | - $approved_query_args = array( |
|
| 1443 | - array( |
|
| 1444 | - 'REG_deleted' => 0, |
|
| 1445 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1446 | - ), |
|
| 1447 | - ); |
|
| 1448 | - $not_approved_query_args = array( |
|
| 1449 | - array( |
|
| 1450 | - 'REG_deleted' => 0, |
|
| 1451 | - 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1452 | - ), |
|
| 1453 | - ); |
|
| 1454 | - $pending_payment_query_args = array( |
|
| 1455 | - array( |
|
| 1456 | - 'REG_deleted' => 0, |
|
| 1457 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1458 | - ), |
|
| 1459 | - ); |
|
| 1460 | - // publish box |
|
| 1461 | - $publish_box_extra_args = array( |
|
| 1462 | - 'view_approved_reg_url' => add_query_arg( |
|
| 1463 | - array( |
|
| 1464 | - 'action' => 'default', |
|
| 1465 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1466 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1467 | - ), |
|
| 1468 | - REG_ADMIN_URL |
|
| 1469 | - ), |
|
| 1470 | - 'view_not_approved_reg_url' => add_query_arg( |
|
| 1471 | - array( |
|
| 1472 | - 'action' => 'default', |
|
| 1473 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1474 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1475 | - ), |
|
| 1476 | - REG_ADMIN_URL |
|
| 1477 | - ), |
|
| 1478 | - 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1479 | - array( |
|
| 1480 | - 'action' => 'default', |
|
| 1481 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1482 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1483 | - ), |
|
| 1484 | - REG_ADMIN_URL |
|
| 1485 | - ), |
|
| 1486 | - 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1487 | - 'Registration', |
|
| 1488 | - $approved_query_args |
|
| 1489 | - ), |
|
| 1490 | - 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1491 | - 'Registration', |
|
| 1492 | - $not_approved_query_args |
|
| 1493 | - ), |
|
| 1494 | - 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1495 | - 'Registration', |
|
| 1496 | - $pending_payment_query_args |
|
| 1497 | - ), |
|
| 1498 | - 'misc_pub_section_class' => apply_filters( |
|
| 1499 | - 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1500 | - 'misc-pub-section' |
|
| 1501 | - ), |
|
| 1502 | - ); |
|
| 1503 | - ob_start(); |
|
| 1504 | - do_action( |
|
| 1505 | - 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1506 | - $this->_cpt_model_obj |
|
| 1507 | - ); |
|
| 1508 | - $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1509 | - // load template |
|
| 1510 | - EEH_Template::display_template( |
|
| 1511 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1512 | - $publish_box_extra_args |
|
| 1513 | - ); |
|
| 1514 | - } |
|
| 1515 | - |
|
| 1516 | - |
|
| 1517 | - /** |
|
| 1518 | - * @return EE_Event |
|
| 1519 | - */ |
|
| 1520 | - public function get_event_object() |
|
| 1521 | - { |
|
| 1522 | - return $this->_cpt_model_obj; |
|
| 1523 | - } |
|
| 1524 | - |
|
| 1525 | - |
|
| 1526 | - |
|
| 1527 | - |
|
| 1528 | - /** METABOXES * */ |
|
| 1529 | - /** |
|
| 1530 | - * _register_event_editor_meta_boxes |
|
| 1531 | - * add all metaboxes related to the event_editor |
|
| 1532 | - * |
|
| 1533 | - * @return void |
|
| 1534 | - */ |
|
| 1535 | - protected function _register_event_editor_meta_boxes() |
|
| 1536 | - { |
|
| 1537 | - $this->verify_cpt_object(); |
|
| 1538 | - add_meta_box( |
|
| 1539 | - 'espresso_event_editor_tickets', |
|
| 1540 | - esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1541 | - array($this, 'ticket_metabox'), |
|
| 1542 | - $this->page_slug, |
|
| 1543 | - 'normal', |
|
| 1544 | - 'high' |
|
| 1545 | - ); |
|
| 1546 | - add_meta_box( |
|
| 1547 | - 'espresso_event_editor_event_options', |
|
| 1548 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1549 | - array($this, 'registration_options_meta_box'), |
|
| 1550 | - $this->page_slug, |
|
| 1551 | - 'side', |
|
| 1552 | - 'default' |
|
| 1553 | - ); |
|
| 1554 | - // NOTE: if you're looking for other metaboxes in here, |
|
| 1555 | - // where a metabox has a related management page in the admin |
|
| 1556 | - // you will find it setup in the related management page's "_Hooks" file. |
|
| 1557 | - // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1558 | - } |
|
| 1559 | - |
|
| 1560 | - |
|
| 1561 | - /** |
|
| 1562 | - * @throws DomainException |
|
| 1563 | - * @throws EE_Error |
|
| 1564 | - */ |
|
| 1565 | - public function ticket_metabox() |
|
| 1566 | - { |
|
| 1567 | - $existing_datetime_ids = $existing_ticket_ids = array(); |
|
| 1568 | - // defaults for template args |
|
| 1569 | - $template_args = array( |
|
| 1570 | - 'existing_datetime_ids' => '', |
|
| 1571 | - 'event_datetime_help_link' => '', |
|
| 1572 | - 'ticket_options_help_link' => '', |
|
| 1573 | - 'time' => null, |
|
| 1574 | - 'ticket_rows' => '', |
|
| 1575 | - 'existing_ticket_ids' => '', |
|
| 1576 | - 'total_ticket_rows' => 1, |
|
| 1577 | - 'ticket_js_structure' => '', |
|
| 1578 | - 'trash_icon' => 'ee-lock-icon', |
|
| 1579 | - 'disabled' => '', |
|
| 1580 | - ); |
|
| 1581 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1582 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1583 | - /** |
|
| 1584 | - * 1. Start with retrieving Datetimes |
|
| 1585 | - * 2. Fore each datetime get related tickets |
|
| 1586 | - * 3. For each ticket get related prices |
|
| 1587 | - */ |
|
| 1588 | - $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
| 1589 | - /** @type EE_Datetime $first_datetime */ |
|
| 1590 | - $first_datetime = reset($times); |
|
| 1591 | - // do we get related tickets? |
|
| 1592 | - if ( |
|
| 1593 | - $first_datetime instanceof EE_Datetime |
|
| 1594 | - && $first_datetime->ID() !== 0 |
|
| 1595 | - ) { |
|
| 1596 | - $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1597 | - $template_args['time'] = $first_datetime; |
|
| 1598 | - $related_tickets = $first_datetime->tickets( |
|
| 1599 | - array( |
|
| 1600 | - array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
| 1601 | - 'default_where_conditions' => 'none', |
|
| 1602 | - ) |
|
| 1603 | - ); |
|
| 1604 | - if (! empty($related_tickets)) { |
|
| 1605 | - $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1606 | - $row = 0; |
|
| 1607 | - foreach ($related_tickets as $ticket) { |
|
| 1608 | - $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1609 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1610 | - $row++; |
|
| 1611 | - } |
|
| 1612 | - } else { |
|
| 1613 | - $template_args['total_ticket_rows'] = 1; |
|
| 1614 | - /** @type EE_Ticket $ticket */ |
|
| 1615 | - $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
| 1616 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1617 | - } |
|
| 1618 | - } else { |
|
| 1619 | - $template_args['time'] = $times[0]; |
|
| 1620 | - /** @type EE_Ticket $ticket */ |
|
| 1621 | - $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
| 1622 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
| 1623 | - // NOTE: we're just sending the first default row |
|
| 1624 | - // (decaf can't manage default tickets so this should be sufficient); |
|
| 1625 | - } |
|
| 1626 | - $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1627 | - 'event_editor_event_datetimes_help_tab' |
|
| 1628 | - ); |
|
| 1629 | - $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1630 | - $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1631 | - $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1632 | - $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1633 | - EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
|
| 1634 | - true |
|
| 1635 | - ); |
|
| 1636 | - $template = apply_filters( |
|
| 1637 | - 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1638 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1639 | - ); |
|
| 1640 | - EEH_Template::display_template($template, $template_args); |
|
| 1641 | - } |
|
| 1642 | - |
|
| 1643 | - |
|
| 1644 | - /** |
|
| 1645 | - * Setup an individual ticket form for the decaf event editor page |
|
| 1646 | - * |
|
| 1647 | - * @access private |
|
| 1648 | - * @param EE_Ticket $ticket the ticket object |
|
| 1649 | - * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1650 | - * @param int $row |
|
| 1651 | - * @return string generated html for the ticket row. |
|
| 1652 | - */ |
|
| 1653 | - private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1654 | - { |
|
| 1655 | - $template_args = array( |
|
| 1656 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1657 | - 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1658 | - : '', |
|
| 1659 | - 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1660 | - 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1661 | - 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1662 | - 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1663 | - 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1664 | - 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1665 | - 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1666 | - 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1667 | - 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1668 | - 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1669 | - && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1670 | - ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
| 1671 | - 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1672 | - : ' disabled=disabled', |
|
| 1673 | - ); |
|
| 1674 | - $price = $ticket->ID() !== 0 |
|
| 1675 | - ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) |
|
| 1676 | - : null; |
|
| 1677 | - $price = $price instanceof EE_Price |
|
| 1678 | - ? $price |
|
| 1679 | - : EEM_Price::instance()->create_default_object(); |
|
| 1680 | - $price_args = array( |
|
| 1681 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1682 | - 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1683 | - 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1684 | - 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1685 | - 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1686 | - ); |
|
| 1687 | - // make sure we have default start and end dates if skeleton |
|
| 1688 | - // handle rows that should NOT be empty |
|
| 1689 | - if (empty($template_args['TKT_start_date'])) { |
|
| 1690 | - // if empty then the start date will be now. |
|
| 1691 | - $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1692 | - } |
|
| 1693 | - if (empty($template_args['TKT_end_date'])) { |
|
| 1694 | - // get the earliest datetime (if present); |
|
| 1695 | - $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
| 1696 | - ? $this->_cpt_model_obj->get_first_related( |
|
| 1697 | - 'Datetime', |
|
| 1698 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1699 | - ) |
|
| 1700 | - : null; |
|
| 1701 | - if (! empty($earliest_dtt)) { |
|
| 1702 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
| 1703 | - } else { |
|
| 1704 | - $template_args['TKT_end_date'] = date( |
|
| 1705 | - 'Y-m-d h:i a', |
|
| 1706 | - mktime(0, 0, 0, date("m"), date("d") + 7, date("Y")) |
|
| 1707 | - ); |
|
| 1708 | - } |
|
| 1709 | - } |
|
| 1710 | - $template_args = array_merge($template_args, $price_args); |
|
| 1711 | - $template = apply_filters( |
|
| 1712 | - 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1713 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1714 | - $ticket |
|
| 1715 | - ); |
|
| 1716 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1717 | - } |
|
| 1718 | - |
|
| 1719 | - |
|
| 1720 | - /** |
|
| 1721 | - * @throws DomainException |
|
| 1722 | - */ |
|
| 1723 | - public function registration_options_meta_box() |
|
| 1724 | - { |
|
| 1725 | - $yes_no_values = array( |
|
| 1726 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 1727 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 1728 | - ); |
|
| 1729 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1730 | - array( |
|
| 1731 | - EEM_Registration::status_id_cancelled, |
|
| 1732 | - EEM_Registration::status_id_declined, |
|
| 1733 | - EEM_Registration::status_id_incomplete, |
|
| 1734 | - ), |
|
| 1735 | - true |
|
| 1736 | - ); |
|
| 1737 | - // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1738 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1739 | - $template_args['event'] = $this->_cpt_model_obj; |
|
| 1740 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1741 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1742 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1743 | - 'default_reg_status', |
|
| 1744 | - $default_reg_status_values, |
|
| 1745 | - $this->_cpt_model_obj->default_registration_status() |
|
| 1746 | - ); |
|
| 1747 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1748 | - 'display_desc', |
|
| 1749 | - $yes_no_values, |
|
| 1750 | - $this->_cpt_model_obj->display_description() |
|
| 1751 | - ); |
|
| 1752 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1753 | - 'display_ticket_selector', |
|
| 1754 | - $yes_no_values, |
|
| 1755 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1756 | - '', |
|
| 1757 | - '', |
|
| 1758 | - false |
|
| 1759 | - ); |
|
| 1760 | - $template_args['additional_registration_options'] = apply_filters( |
|
| 1761 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1762 | - '', |
|
| 1763 | - $template_args, |
|
| 1764 | - $yes_no_values, |
|
| 1765 | - $default_reg_status_values |
|
| 1766 | - ); |
|
| 1767 | - EEH_Template::display_template( |
|
| 1768 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1769 | - $template_args |
|
| 1770 | - ); |
|
| 1771 | - } |
|
| 1772 | - |
|
| 1773 | - |
|
| 1774 | - /** |
|
| 1775 | - * _get_events() |
|
| 1776 | - * This method simply returns all the events (for the given _view and paging) |
|
| 1777 | - * |
|
| 1778 | - * @access public |
|
| 1779 | - * @param int $per_page count of items per page (20 default); |
|
| 1780 | - * @param int $current_page what is the current page being viewed. |
|
| 1781 | - * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1782 | - * If FALSE then we return an array of event objects |
|
| 1783 | - * that match the given _view and paging parameters. |
|
| 1784 | - * @return array an array of event objects. |
|
| 1785 | - */ |
|
| 1786 | - public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1787 | - { |
|
| 1788 | - $EEME = $this->_event_model(); |
|
| 1789 | - $offset = ($current_page - 1) * $per_page; |
|
| 1790 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1791 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
| 1792 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
|
| 1793 | - if (isset($this->_req_data['month_range'])) { |
|
| 1794 | - $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
| 1795 | - // simulate the FIRST day of the month, that fixes issues for months like February |
|
| 1796 | - // where PHP doesn't know what to assume for date. |
|
| 1797 | - // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
| 1798 | - $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
| 1799 | - $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1800 | - } |
|
| 1801 | - $where = array(); |
|
| 1802 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1803 | - // determine what post_status our condition will have for the query. |
|
| 1804 | - switch ($status) { |
|
| 1805 | - case 'month': |
|
| 1806 | - case 'today': |
|
| 1807 | - case null: |
|
| 1808 | - case 'all': |
|
| 1809 | - break; |
|
| 1810 | - case 'draft': |
|
| 1811 | - $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
| 1812 | - break; |
|
| 1813 | - default: |
|
| 1814 | - $where['status'] = $status; |
|
| 1815 | - } |
|
| 1816 | - // categories? |
|
| 1817 | - $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 1818 | - ? $this->_req_data['EVT_CAT'] : null; |
|
| 1819 | - if (! empty($category)) { |
|
| 1820 | - $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
|
| 1821 | - $where['Term_Taxonomy.term_id'] = $category; |
|
| 1822 | - } |
|
| 1823 | - // date where conditions |
|
| 1824 | - $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1825 | - if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
|
| 1826 | - $DateTime = new DateTime( |
|
| 1827 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1828 | - new DateTimeZone('UTC') |
|
| 1829 | - ); |
|
| 1830 | - $start = $DateTime->getTimestamp(); |
|
| 1831 | - // set the datetime to be the end of the month |
|
| 1832 | - $DateTime->setDate( |
|
| 1833 | - $year_r, |
|
| 1834 | - $month_r, |
|
| 1835 | - $DateTime->format('t') |
|
| 1836 | - )->setTime(23, 59, 59); |
|
| 1837 | - $end = $DateTime->getTimestamp(); |
|
| 1838 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1839 | - } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { |
|
| 1840 | - $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1841 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1842 | - $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1843 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1844 | - } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { |
|
| 1845 | - $now = date('Y-m-01'); |
|
| 1846 | - $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1847 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1848 | - $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1849 | - ->setTime(23, 59, 59) |
|
| 1850 | - ->format(implode(' ', $start_formats)); |
|
| 1851 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1852 | - } |
|
| 1853 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1854 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1855 | - } else { |
|
| 1856 | - if (! isset($where['status'])) { |
|
| 1857 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1858 | - $where['OR'] = array( |
|
| 1859 | - 'status*restrict_private' => array('!=', 'private'), |
|
| 1860 | - 'AND' => array( |
|
| 1861 | - 'status*inclusive' => array('=', 'private'), |
|
| 1862 | - 'EVT_wp_user' => get_current_user_id(), |
|
| 1863 | - ), |
|
| 1864 | - ); |
|
| 1865 | - } |
|
| 1866 | - } |
|
| 1867 | - } |
|
| 1868 | - if (isset($this->_req_data['EVT_wp_user'])) { |
|
| 1869 | - if ( |
|
| 1870 | - $this->_req_data['EVT_wp_user'] != get_current_user_id() |
|
| 1871 | - && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 1872 | - ) { |
|
| 1873 | - $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
| 1874 | - } |
|
| 1875 | - } |
|
| 1876 | - // search query handling |
|
| 1877 | - if (isset($this->_req_data['s'])) { |
|
| 1878 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1879 | - $where['OR'] = array( |
|
| 1880 | - 'EVT_name' => array('LIKE', $search_string), |
|
| 1881 | - 'EVT_desc' => array('LIKE', $search_string), |
|
| 1882 | - 'EVT_short_desc' => array('LIKE', $search_string), |
|
| 1883 | - ); |
|
| 1884 | - } |
|
| 1885 | - // filter events by venue. |
|
| 1886 | - if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) { |
|
| 1887 | - $where['Venue.VNU_ID'] = absint($this->_req_data['venue']); |
|
| 1888 | - } |
|
| 1889 | - $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
| 1890 | - $query_params = apply_filters( |
|
| 1891 | - 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 1892 | - array( |
|
| 1893 | - $where, |
|
| 1894 | - 'limit' => $limit, |
|
| 1895 | - 'order_by' => $orderby, |
|
| 1896 | - 'order' => $order, |
|
| 1897 | - 'group_by' => 'EVT_ID', |
|
| 1898 | - ), |
|
| 1899 | - $this->_req_data |
|
| 1900 | - ); |
|
| 1901 | - |
|
| 1902 | - // let's first check if we have special requests coming in. |
|
| 1903 | - if (isset($this->_req_data['active_status'])) { |
|
| 1904 | - switch ($this->_req_data['active_status']) { |
|
| 1905 | - case 'upcoming': |
|
| 1906 | - return $EEME->get_upcoming_events($query_params, $count); |
|
| 1907 | - break; |
|
| 1908 | - case 'expired': |
|
| 1909 | - return $EEME->get_expired_events($query_params, $count); |
|
| 1910 | - break; |
|
| 1911 | - case 'active': |
|
| 1912 | - return $EEME->get_active_events($query_params, $count); |
|
| 1913 | - break; |
|
| 1914 | - case 'inactive': |
|
| 1915 | - return $EEME->get_inactive_events($query_params, $count); |
|
| 1916 | - break; |
|
| 1917 | - } |
|
| 1918 | - } |
|
| 1919 | - |
|
| 1920 | - $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
| 1921 | - return $events; |
|
| 1922 | - } |
|
| 1923 | - |
|
| 1924 | - |
|
| 1925 | - /** |
|
| 1926 | - * handling for WordPress CPT actions (trash, restore, delete) |
|
| 1927 | - * |
|
| 1928 | - * @param string $post_id |
|
| 1929 | - */ |
|
| 1930 | - public function trash_cpt_item($post_id) |
|
| 1931 | - { |
|
| 1932 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1933 | - $this->_trash_or_restore_event('trash', false); |
|
| 1934 | - } |
|
| 1935 | - |
|
| 1936 | - |
|
| 1937 | - /** |
|
| 1938 | - * @param string $post_id |
|
| 1939 | - */ |
|
| 1940 | - public function restore_cpt_item($post_id) |
|
| 1941 | - { |
|
| 1942 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1943 | - $this->_trash_or_restore_event('draft', false); |
|
| 1944 | - } |
|
| 1945 | - |
|
| 1946 | - |
|
| 1947 | - /** |
|
| 1948 | - * @param string $post_id |
|
| 1949 | - */ |
|
| 1950 | - public function delete_cpt_item($post_id) |
|
| 1951 | - { |
|
| 1952 | - throw new EE_Error(esc_html__('Please contact Event Espresso support with the details of the steps taken to produce this error.', 'event_espresso')); |
|
| 1953 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1954 | - $this->_delete_event(); |
|
| 1955 | - } |
|
| 1956 | - |
|
| 1957 | - |
|
| 1958 | - /** |
|
| 1959 | - * _trash_or_restore_event |
|
| 1960 | - * |
|
| 1961 | - * @access protected |
|
| 1962 | - * @param string $event_status |
|
| 1963 | - * @param bool $redirect_after |
|
| 1964 | - */ |
|
| 1965 | - protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 1966 | - { |
|
| 1967 | - // determine the event id and set to array. |
|
| 1968 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
| 1969 | - // loop thru events |
|
| 1970 | - if ($EVT_ID) { |
|
| 1971 | - // clean status |
|
| 1972 | - $event_status = sanitize_key($event_status); |
|
| 1973 | - // grab status |
|
| 1974 | - if (! empty($event_status)) { |
|
| 1975 | - $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1976 | - } else { |
|
| 1977 | - $success = false; |
|
| 1978 | - $msg = esc_html__( |
|
| 1979 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1980 | - 'event_espresso' |
|
| 1981 | - ); |
|
| 1982 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1983 | - } |
|
| 1984 | - } else { |
|
| 1985 | - $success = false; |
|
| 1986 | - $msg = esc_html__( |
|
| 1987 | - 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1988 | - 'event_espresso' |
|
| 1989 | - ); |
|
| 1990 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1991 | - } |
|
| 1992 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1993 | - if ($redirect_after) { |
|
| 1994 | - $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
|
| 1995 | - } |
|
| 1996 | - } |
|
| 1997 | - |
|
| 1998 | - |
|
| 1999 | - /** |
|
| 2000 | - * _trash_or_restore_events |
|
| 2001 | - * |
|
| 2002 | - * @access protected |
|
| 2003 | - * @param string $event_status |
|
| 2004 | - * @return void |
|
| 2005 | - */ |
|
| 2006 | - protected function _trash_or_restore_events($event_status = 'trash') |
|
| 2007 | - { |
|
| 2008 | - // clean status |
|
| 2009 | - $event_status = sanitize_key($event_status); |
|
| 2010 | - // grab status |
|
| 2011 | - if (! empty($event_status)) { |
|
| 2012 | - $success = true; |
|
| 2013 | - // determine the event id and set to array. |
|
| 2014 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
|
| 2015 | - // loop thru events |
|
| 2016 | - foreach ($EVT_IDs as $EVT_ID) { |
|
| 2017 | - if ($EVT_ID = absint($EVT_ID)) { |
|
| 2018 | - $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 2019 | - $success = $results !== false ? $success : false; |
|
| 2020 | - } else { |
|
| 2021 | - $msg = sprintf( |
|
| 2022 | - esc_html__( |
|
| 2023 | - 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2024 | - 'event_espresso' |
|
| 2025 | - ), |
|
| 2026 | - $EVT_ID |
|
| 2027 | - ); |
|
| 2028 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2029 | - $success = false; |
|
| 2030 | - } |
|
| 2031 | - } |
|
| 2032 | - } else { |
|
| 2033 | - $success = false; |
|
| 2034 | - $msg = esc_html__( |
|
| 2035 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2036 | - 'event_espresso' |
|
| 2037 | - ); |
|
| 2038 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2039 | - } |
|
| 2040 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2041 | - $success = $success ? 2 : false; |
|
| 2042 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2043 | - $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); |
|
| 2044 | - } |
|
| 2045 | - |
|
| 2046 | - |
|
| 2047 | - /** |
|
| 2048 | - * @param int $EVT_ID |
|
| 2049 | - * @param string $event_status |
|
| 2050 | - * @return bool |
|
| 2051 | - */ |
|
| 2052 | - private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 2053 | - { |
|
| 2054 | - // grab event id |
|
| 2055 | - if (! $EVT_ID) { |
|
| 2056 | - $msg = esc_html__( |
|
| 2057 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2058 | - 'event_espresso' |
|
| 2059 | - ); |
|
| 2060 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2061 | - return false; |
|
| 2062 | - } |
|
| 2063 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2064 | - // clean status |
|
| 2065 | - $event_status = sanitize_key($event_status); |
|
| 2066 | - // grab status |
|
| 2067 | - if (empty($event_status)) { |
|
| 2068 | - $msg = esc_html__( |
|
| 2069 | - 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2070 | - 'event_espresso' |
|
| 2071 | - ); |
|
| 2072 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2073 | - return false; |
|
| 2074 | - } |
|
| 2075 | - // was event trashed or restored ? |
|
| 2076 | - switch ($event_status) { |
|
| 2077 | - case 'draft': |
|
| 2078 | - $action = 'restored from the trash'; |
|
| 2079 | - $hook = 'AHEE_event_restored_from_trash'; |
|
| 2080 | - break; |
|
| 2081 | - case 'trash': |
|
| 2082 | - $action = 'moved to the trash'; |
|
| 2083 | - $hook = 'AHEE_event_moved_to_trash'; |
|
| 2084 | - break; |
|
| 2085 | - default: |
|
| 2086 | - $action = 'updated'; |
|
| 2087 | - $hook = false; |
|
| 2088 | - } |
|
| 2089 | - // use class to change status |
|
| 2090 | - $this->_cpt_model_obj->set_status($event_status); |
|
| 2091 | - $success = $this->_cpt_model_obj->save(); |
|
| 2092 | - if (! $success) { |
|
| 2093 | - $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2094 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2095 | - return false; |
|
| 2096 | - } |
|
| 2097 | - if ($hook) { |
|
| 2098 | - do_action($hook); |
|
| 2099 | - } |
|
| 2100 | - return true; |
|
| 2101 | - } |
|
| 2102 | - |
|
| 2103 | - |
|
| 2104 | - /** |
|
| 2105 | - * @param array $event_ids |
|
| 2106 | - * @return array |
|
| 2107 | - * @since $VID:$ |
|
| 2108 | - */ |
|
| 2109 | - private function cleanEventIds(array $event_ids) |
|
| 2110 | - { |
|
| 2111 | - return array_map('absint', $event_ids); |
|
| 2112 | - } |
|
| 2113 | - |
|
| 2114 | - |
|
| 2115 | - /** |
|
| 2116 | - * @return array |
|
| 2117 | - * @since $VID:$ |
|
| 2118 | - */ |
|
| 2119 | - private function getEventIdsFromRequest() |
|
| 2120 | - { |
|
| 2121 | - $event_ids = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : []; |
|
| 2122 | - $event_ids = is_string($event_ids) ? explode(',', $event_ids) : (array) $event_ids; |
|
| 2123 | - return $this->cleanEventIds($event_ids); |
|
| 2124 | - } |
|
| 2125 | - |
|
| 2126 | - |
|
| 2127 | - /** |
|
| 2128 | - * @param bool $preview_delete |
|
| 2129 | - * @throws EE_Error |
|
| 2130 | - */ |
|
| 2131 | - protected function _delete_event($preview_delete = true) |
|
| 2132 | - { |
|
| 2133 | - $this->_delete_events($preview_delete); |
|
| 2134 | - } |
|
| 2135 | - |
|
| 2136 | - |
|
| 2137 | - /** |
|
| 2138 | - * Gets the tree traversal batch persister. |
|
| 2139 | - * @since 4.10.12.p |
|
| 2140 | - * @return NodeGroupDao |
|
| 2141 | - * @throws InvalidArgumentException |
|
| 2142 | - * @throws InvalidDataTypeException |
|
| 2143 | - * @throws InvalidInterfaceException |
|
| 2144 | - */ |
|
| 2145 | - protected function getModelObjNodeGroupPersister() |
|
| 2146 | - { |
|
| 2147 | - if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
| 2148 | - $this->model_obj_node_group_persister = $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
|
| 2149 | - } |
|
| 2150 | - return $this->model_obj_node_group_persister; |
|
| 2151 | - } |
|
| 2152 | - |
|
| 2153 | - |
|
| 2154 | - /** |
|
| 2155 | - * @param bool $preview_delete |
|
| 2156 | - * @return void |
|
| 2157 | - * @throws EE_Error |
|
| 2158 | - */ |
|
| 2159 | - protected function _delete_events($preview_delete = true) |
|
| 2160 | - { |
|
| 2161 | - $event_ids = $this->getEventIdsFromRequest(); |
|
| 2162 | - if ($preview_delete) { |
|
| 2163 | - $this->generateDeletionPreview($event_ids); |
|
| 2164 | - } else { |
|
| 2165 | - EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]); |
|
| 2166 | - } |
|
| 2167 | - } |
|
| 2168 | - |
|
| 2169 | - |
|
| 2170 | - /** |
|
| 2171 | - * @param array $event_ids |
|
| 2172 | - */ |
|
| 2173 | - protected function generateDeletionPreview(array $event_ids) |
|
| 2174 | - { |
|
| 2175 | - $event_ids = $this->cleanEventIds($event_ids); |
|
| 2176 | - // Set a code we can use to reference this deletion task in the batch jobs and preview page. |
|
| 2177 | - $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode(); |
|
| 2178 | - $return_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2179 | - [ |
|
| 2180 | - 'action' => 'preview_deletion', |
|
| 2181 | - 'deletion_job_code' => $deletion_job_code, |
|
| 2182 | - ], |
|
| 2183 | - $this->_admin_base_url |
|
| 2184 | - ); |
|
| 2185 | - EEH_URL::safeRedirectAndExit( |
|
| 2186 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 2187 | - [ |
|
| 2188 | - 'page' => 'espresso_batch', |
|
| 2189 | - 'batch' => EED_Batch::batch_job, |
|
| 2190 | - 'EVT_IDs' => $event_ids, |
|
| 2191 | - 'deletion_job_code' => $deletion_job_code, |
|
| 2192 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'), |
|
| 2193 | - 'return_url' => urlencode($return_url), |
|
| 2194 | - ], |
|
| 2195 | - admin_url() |
|
| 2196 | - ) |
|
| 2197 | - ); |
|
| 2198 | - } |
|
| 2199 | - |
|
| 2200 | - /** |
|
| 2201 | - * Checks for a POST submission |
|
| 2202 | - * @since 4.10.12.p |
|
| 2203 | - */ |
|
| 2204 | - protected function confirmDeletion() |
|
| 2205 | - { |
|
| 2206 | - $deletion_redirect_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion'); |
|
| 2207 | - $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url()); |
|
| 2208 | - } |
|
| 2209 | - |
|
| 2210 | - /** |
|
| 2211 | - * A page for users to preview what exactly will be deleted, and confirm they want to delete it. |
|
| 2212 | - * @since 4.10.12.p |
|
| 2213 | - * @throws EE_Error |
|
| 2214 | - */ |
|
| 2215 | - protected function previewDeletion() |
|
| 2216 | - { |
|
| 2217 | - $preview_deletion_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion'); |
|
| 2218 | - $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url())); |
|
| 2219 | - $this->display_admin_page_with_no_sidebar(); |
|
| 2220 | - } |
|
| 2221 | - |
|
| 2222 | - /** |
|
| 2223 | - * get total number of events |
|
| 2224 | - * |
|
| 2225 | - * @access public |
|
| 2226 | - * @return int |
|
| 2227 | - */ |
|
| 2228 | - public function total_events() |
|
| 2229 | - { |
|
| 2230 | - $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2231 | - return $count; |
|
| 2232 | - } |
|
| 2233 | - |
|
| 2234 | - |
|
| 2235 | - /** |
|
| 2236 | - * get total number of draft events |
|
| 2237 | - * |
|
| 2238 | - * @access public |
|
| 2239 | - * @return int |
|
| 2240 | - */ |
|
| 2241 | - public function total_events_draft() |
|
| 2242 | - { |
|
| 2243 | - $where = array( |
|
| 2244 | - 'status' => array('IN', array('draft', 'auto-draft')), |
|
| 2245 | - ); |
|
| 2246 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2247 | - return $count; |
|
| 2248 | - } |
|
| 2249 | - |
|
| 2250 | - |
|
| 2251 | - /** |
|
| 2252 | - * get total number of trashed events |
|
| 2253 | - * |
|
| 2254 | - * @access public |
|
| 2255 | - * @return int |
|
| 2256 | - */ |
|
| 2257 | - public function total_trashed_events() |
|
| 2258 | - { |
|
| 2259 | - $where = array( |
|
| 2260 | - 'status' => 'trash', |
|
| 2261 | - ); |
|
| 2262 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2263 | - return $count; |
|
| 2264 | - } |
|
| 2265 | - |
|
| 2266 | - |
|
| 2267 | - /** |
|
| 2268 | - * _default_event_settings |
|
| 2269 | - * This generates the Default Settings Tab |
|
| 2270 | - * |
|
| 2271 | - * @return void |
|
| 2272 | - * @throws EE_Error |
|
| 2273 | - */ |
|
| 2274 | - protected function _default_event_settings() |
|
| 2275 | - { |
|
| 2276 | - $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2277 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2278 | - $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html(); |
|
| 2279 | - $this->display_admin_page_with_sidebar(); |
|
| 2280 | - } |
|
| 2281 | - |
|
| 2282 | - |
|
| 2283 | - /** |
|
| 2284 | - * Return the form for event settings. |
|
| 2285 | - * |
|
| 2286 | - * @return EE_Form_Section_Proper |
|
| 2287 | - * @throws EE_Error |
|
| 2288 | - */ |
|
| 2289 | - protected function _default_event_settings_form() |
|
| 2290 | - { |
|
| 2291 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2292 | - $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
| 2293 | - // exclude |
|
| 2294 | - array( |
|
| 2295 | - EEM_Registration::status_id_cancelled, |
|
| 2296 | - EEM_Registration::status_id_declined, |
|
| 2297 | - EEM_Registration::status_id_incomplete, |
|
| 2298 | - EEM_Registration::status_id_wait_list, |
|
| 2299 | - ), |
|
| 2300 | - true |
|
| 2301 | - ); |
|
| 2302 | - return new EE_Form_Section_Proper( |
|
| 2303 | - array( |
|
| 2304 | - 'name' => 'update_default_event_settings', |
|
| 2305 | - 'html_id' => 'update_default_event_settings', |
|
| 2306 | - 'html_class' => 'form-table', |
|
| 2307 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 2308 | - 'subsections' => apply_filters( |
|
| 2309 | - 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
| 2310 | - array( |
|
| 2311 | - 'default_reg_status' => new EE_Select_Input( |
|
| 2312 | - $registration_stati_for_selection, |
|
| 2313 | - array( |
|
| 2314 | - 'default' => isset($registration_config->default_STS_ID) |
|
| 2315 | - && array_key_exists( |
|
| 2316 | - $registration_config->default_STS_ID, |
|
| 2317 | - $registration_stati_for_selection |
|
| 2318 | - ) |
|
| 2319 | - ? sanitize_text_field($registration_config->default_STS_ID) |
|
| 2320 | - : EEM_Registration::status_id_pending_payment, |
|
| 2321 | - 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
| 2322 | - . EEH_Template::get_help_tab_link( |
|
| 2323 | - 'default_settings_status_help_tab' |
|
| 2324 | - ), |
|
| 2325 | - 'html_help_text' => esc_html__( |
|
| 2326 | - 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
| 2327 | - 'event_espresso' |
|
| 2328 | - ), |
|
| 2329 | - ) |
|
| 2330 | - ), |
|
| 2331 | - 'default_max_tickets' => new EE_Integer_Input( |
|
| 2332 | - array( |
|
| 2333 | - 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
| 2334 | - ? $registration_config->default_maximum_number_of_tickets |
|
| 2335 | - : EEM_Event::get_default_additional_limit(), |
|
| 2336 | - 'html_label_text' => esc_html__( |
|
| 2337 | - 'Default Maximum Tickets Allowed Per Order:', |
|
| 2338 | - 'event_espresso' |
|
| 2339 | - ) |
|
| 2340 | - . EEH_Template::get_help_tab_link( |
|
| 2341 | - 'default_maximum_tickets_help_tab"' |
|
| 2342 | - ), |
|
| 2343 | - 'html_help_text' => esc_html__( |
|
| 2344 | - 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
| 2345 | - 'event_espresso' |
|
| 2346 | - ), |
|
| 2347 | - ) |
|
| 2348 | - ), |
|
| 2349 | - ) |
|
| 2350 | - ), |
|
| 2351 | - ) |
|
| 2352 | - ); |
|
| 2353 | - } |
|
| 2354 | - |
|
| 2355 | - |
|
| 2356 | - /** |
|
| 2357 | - * _update_default_event_settings |
|
| 2358 | - * |
|
| 2359 | - * @access protected |
|
| 2360 | - * @return void |
|
| 2361 | - * @throws EE_Error |
|
| 2362 | - */ |
|
| 2363 | - protected function _update_default_event_settings() |
|
| 2364 | - { |
|
| 2365 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2366 | - $form = $this->_default_event_settings_form(); |
|
| 2367 | - if ($form->was_submitted()) { |
|
| 2368 | - $form->receive_form_submission(); |
|
| 2369 | - if ($form->is_valid()) { |
|
| 2370 | - $valid_data = $form->valid_data(); |
|
| 2371 | - if (isset($valid_data['default_reg_status'])) { |
|
| 2372 | - $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
| 2373 | - } |
|
| 2374 | - if (isset($valid_data['default_max_tickets'])) { |
|
| 2375 | - $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
| 2376 | - } |
|
| 2377 | - // update because data was valid! |
|
| 2378 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 2379 | - EE_Error::overwrite_success(); |
|
| 2380 | - EE_Error::add_success( |
|
| 2381 | - esc_html__('Default Event Settings were updated', 'event_espresso') |
|
| 2382 | - ); |
|
| 2383 | - } |
|
| 2384 | - } |
|
| 2385 | - $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true); |
|
| 2386 | - } |
|
| 2387 | - |
|
| 2388 | - |
|
| 2389 | - /************* Templates *************/ |
|
| 2390 | - protected function _template_settings() |
|
| 2391 | - { |
|
| 2392 | - $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2393 | - $this->_template_args['preview_img'] = '<img src="' |
|
| 2394 | - . EVENTS_ASSETS_URL |
|
| 2395 | - . '/images/' |
|
| 2396 | - . 'caffeinated_template_features.jpg" alt="' |
|
| 2397 | - . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2398 | - . '" />'; |
|
| 2399 | - $this->_template_args['preview_text'] = '<strong>' |
|
| 2400 | - . esc_html__( |
|
| 2401 | - 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
| 2402 | - 'event_espresso' |
|
| 2403 | - ) . '</strong>'; |
|
| 2404 | - $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2405 | - } |
|
| 2406 | - |
|
| 2407 | - |
|
| 2408 | - /** Event Category Stuff **/ |
|
| 2409 | - /** |
|
| 2410 | - * set the _category property with the category object for the loaded page. |
|
| 2411 | - * |
|
| 2412 | - * @access private |
|
| 2413 | - * @return void |
|
| 2414 | - */ |
|
| 2415 | - private function _set_category_object() |
|
| 2416 | - { |
|
| 2417 | - if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2418 | - return; |
|
| 2419 | - } //already have the category object so get out. |
|
| 2420 | - // set default category object |
|
| 2421 | - $this->_set_empty_category_object(); |
|
| 2422 | - // only set if we've got an id |
|
| 2423 | - if (! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2424 | - return; |
|
| 2425 | - } |
|
| 2426 | - $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
| 2427 | - $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2428 | - if (! empty($term)) { |
|
| 2429 | - $this->_category->category_name = $term->name; |
|
| 2430 | - $this->_category->category_identifier = $term->slug; |
|
| 2431 | - $this->_category->category_desc = $term->description; |
|
| 2432 | - $this->_category->id = $term->term_id; |
|
| 2433 | - $this->_category->parent = $term->parent; |
|
| 2434 | - } |
|
| 2435 | - } |
|
| 2436 | - |
|
| 2437 | - |
|
| 2438 | - /** |
|
| 2439 | - * Clears out category properties. |
|
| 2440 | - */ |
|
| 2441 | - private function _set_empty_category_object() |
|
| 2442 | - { |
|
| 2443 | - $this->_category = new stdClass(); |
|
| 2444 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2445 | - $this->_category->id = $this->_category->parent = 0; |
|
| 2446 | - } |
|
| 2447 | - |
|
| 2448 | - |
|
| 2449 | - /** |
|
| 2450 | - * @throws EE_Error |
|
| 2451 | - */ |
|
| 2452 | - protected function _category_list_table() |
|
| 2453 | - { |
|
| 2454 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2455 | - $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2456 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2457 | - 'add_category', |
|
| 2458 | - 'add_category', |
|
| 2459 | - array(), |
|
| 2460 | - 'add-new-h2' |
|
| 2461 | - ); |
|
| 2462 | - $this->display_admin_list_table_page_with_sidebar(); |
|
| 2463 | - } |
|
| 2464 | - |
|
| 2465 | - |
|
| 2466 | - /** |
|
| 2467 | - * Output category details view. |
|
| 2468 | - */ |
|
| 2469 | - protected function _category_details($view) |
|
| 2470 | - { |
|
| 2471 | - // load formatter helper |
|
| 2472 | - // load field generator helper |
|
| 2473 | - $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
| 2474 | - $this->_set_add_edit_form_tags($route); |
|
| 2475 | - $this->_set_category_object(); |
|
| 2476 | - $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2477 | - $delete_action = 'delete_category'; |
|
| 2478 | - // custom redirect |
|
| 2479 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2480 | - array('action' => 'category_list'), |
|
| 2481 | - $this->_admin_base_url |
|
| 2482 | - ); |
|
| 2483 | - $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2484 | - // take care of contents |
|
| 2485 | - $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2486 | - $this->display_admin_page_with_sidebar(); |
|
| 2487 | - } |
|
| 2488 | - |
|
| 2489 | - |
|
| 2490 | - /** |
|
| 2491 | - * Output category details content. |
|
| 2492 | - */ |
|
| 2493 | - protected function _category_details_content() |
|
| 2494 | - { |
|
| 2495 | - $editor_args['category_desc'] = array( |
|
| 2496 | - 'type' => 'wp_editor', |
|
| 2497 | - 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2498 | - 'class' => 'my_editor_custom', |
|
| 2499 | - 'wpeditor_args' => array('media_buttons' => false), |
|
| 2500 | - ); |
|
| 2501 | - $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2502 | - $all_terms = get_terms( |
|
| 2503 | - array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY), |
|
| 2504 | - array('hide_empty' => 0, 'exclude' => array($this->_category->id)) |
|
| 2505 | - ); |
|
| 2506 | - // setup category select for term parents. |
|
| 2507 | - $category_select_values[] = array( |
|
| 2508 | - 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2509 | - 'id' => 0, |
|
| 2510 | - ); |
|
| 2511 | - foreach ($all_terms as $term) { |
|
| 2512 | - $category_select_values[] = array( |
|
| 2513 | - 'text' => $term->name, |
|
| 2514 | - 'id' => $term->term_id, |
|
| 2515 | - ); |
|
| 2516 | - } |
|
| 2517 | - $category_select = EEH_Form_Fields::select_input( |
|
| 2518 | - 'category_parent', |
|
| 2519 | - $category_select_values, |
|
| 2520 | - $this->_category->parent |
|
| 2521 | - ); |
|
| 2522 | - $template_args = array( |
|
| 2523 | - 'category' => $this->_category, |
|
| 2524 | - 'category_select' => $category_select, |
|
| 2525 | - 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2526 | - 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2527 | - 'disable' => '', |
|
| 2528 | - 'disabled_message' => false, |
|
| 2529 | - ); |
|
| 2530 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2531 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 2532 | - } |
|
| 2533 | - |
|
| 2534 | - |
|
| 2535 | - /** |
|
| 2536 | - * Handles deleting categories. |
|
| 2537 | - */ |
|
| 2538 | - protected function _delete_categories() |
|
| 2539 | - { |
|
| 2540 | - $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID'] |
|
| 2541 | - : (array) $this->_req_data['category_id']; |
|
| 2542 | - foreach ($cat_ids as $cat_id) { |
|
| 2543 | - $this->_delete_category($cat_id); |
|
| 2544 | - } |
|
| 2545 | - // doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2546 | - $query_args = array( |
|
| 2547 | - 'action' => 'category_list', |
|
| 2548 | - ); |
|
| 2549 | - $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2550 | - } |
|
| 2551 | - |
|
| 2552 | - |
|
| 2553 | - /** |
|
| 2554 | - * Handles deleting specific category. |
|
| 2555 | - * |
|
| 2556 | - * @param int $cat_id |
|
| 2557 | - */ |
|
| 2558 | - protected function _delete_category($cat_id) |
|
| 2559 | - { |
|
| 2560 | - $cat_id = absint($cat_id); |
|
| 2561 | - wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2562 | - } |
|
| 2563 | - |
|
| 2564 | - |
|
| 2565 | - /** |
|
| 2566 | - * Handles triggering the update or insertion of a new category. |
|
| 2567 | - * |
|
| 2568 | - * @param bool $new_category true means we're triggering the insert of a new category. |
|
| 2569 | - */ |
|
| 2570 | - protected function _insert_or_update_category($new_category) |
|
| 2571 | - { |
|
| 2572 | - $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2573 | - $success = 0; // we already have a success message so lets not send another. |
|
| 2574 | - if ($cat_id) { |
|
| 2575 | - $query_args = array( |
|
| 2576 | - 'action' => 'edit_category', |
|
| 2577 | - 'EVT_CAT_ID' => $cat_id, |
|
| 2578 | - ); |
|
| 2579 | - } else { |
|
| 2580 | - $query_args = array('action' => 'add_category'); |
|
| 2581 | - } |
|
| 2582 | - $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2583 | - } |
|
| 2584 | - |
|
| 2585 | - |
|
| 2586 | - /** |
|
| 2587 | - * Inserts or updates category |
|
| 2588 | - * |
|
| 2589 | - * @param bool $update (true indicates we're updating a category). |
|
| 2590 | - * @return bool|mixed|string |
|
| 2591 | - */ |
|
| 2592 | - private function _insert_category($update = false) |
|
| 2593 | - { |
|
| 2594 | - $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
| 2595 | - $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
| 2596 | - $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
| 2597 | - $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
| 2598 | - if (empty($category_name)) { |
|
| 2599 | - $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2600 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2601 | - return false; |
|
| 2602 | - } |
|
| 2603 | - $term_args = array( |
|
| 2604 | - 'name' => $category_name, |
|
| 2605 | - 'description' => $category_desc, |
|
| 2606 | - 'parent' => $category_parent, |
|
| 2607 | - ); |
|
| 2608 | - // was the category_identifier input disabled? |
|
| 2609 | - if (isset($this->_req_data['category_identifier'])) { |
|
| 2610 | - $term_args['slug'] = $this->_req_data['category_identifier']; |
|
| 2611 | - } |
|
| 2612 | - $insert_ids = $update |
|
| 2613 | - ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
|
| 2614 | - : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
|
| 2615 | - if (! is_array($insert_ids)) { |
|
| 2616 | - $msg = esc_html__( |
|
| 2617 | - 'An error occurred and the category has not been saved to the database.', |
|
| 2618 | - 'event_espresso' |
|
| 2619 | - ); |
|
| 2620 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2621 | - } else { |
|
| 2622 | - $cat_id = $insert_ids['term_id']; |
|
| 2623 | - $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
| 2624 | - EE_Error::add_success($msg); |
|
| 2625 | - } |
|
| 2626 | - return $cat_id; |
|
| 2627 | - } |
|
| 2628 | - |
|
| 2629 | - |
|
| 2630 | - /** |
|
| 2631 | - * Gets categories or count of categories matching the arguments in the request. |
|
| 2632 | - * |
|
| 2633 | - * @param int $per_page |
|
| 2634 | - * @param int $current_page |
|
| 2635 | - * @param bool $count |
|
| 2636 | - * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int |
|
| 2637 | - */ |
|
| 2638 | - public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2639 | - { |
|
| 2640 | - // testing term stuff |
|
| 2641 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
| 2642 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2643 | - $limit = ($current_page - 1) * $per_page; |
|
| 2644 | - $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2645 | - if (isset($this->_req_data['s'])) { |
|
| 2646 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2647 | - $where['OR'] = array( |
|
| 2648 | - 'Term.name' => array('LIKE', $sstr), |
|
| 2649 | - 'description' => array('LIKE', $sstr), |
|
| 2650 | - ); |
|
| 2651 | - } |
|
| 2652 | - $query_params = array( |
|
| 2653 | - $where, |
|
| 2654 | - 'order_by' => array($orderby => $order), |
|
| 2655 | - 'limit' => $limit . ',' . $per_page, |
|
| 2656 | - 'force_join' => array('Term'), |
|
| 2657 | - ); |
|
| 2658 | - $categories = $count |
|
| 2659 | - ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2660 | - : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2661 | - return $categories; |
|
| 2662 | - } |
|
| 2663 | - |
|
| 2664 | - /* end category stuff */ |
|
| 2665 | - /**************/ |
|
| 2666 | - |
|
| 2667 | - |
|
| 2668 | - /** |
|
| 2669 | - * Callback for the `ee_save_timezone_setting` ajax action. |
|
| 2670 | - * |
|
| 2671 | - * @throws EE_Error |
|
| 2672 | - */ |
|
| 2673 | - public function save_timezonestring_setting() |
|
| 2674 | - { |
|
| 2675 | - $timezone_string = isset($this->_req_data['timezone_selected']) |
|
| 2676 | - ? $this->_req_data['timezone_selected'] |
|
| 2677 | - : ''; |
|
| 2678 | - if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { |
|
| 2679 | - EE_Error::add_error( |
|
| 2680 | - esc_html__('An invalid timezone string submitted.', 'event_espresso'), |
|
| 2681 | - __FILE__, |
|
| 2682 | - __FUNCTION__, |
|
| 2683 | - __LINE__ |
|
| 2684 | - ); |
|
| 2685 | - $this->_template_args['error'] = true; |
|
| 2686 | - $this->_return_json(); |
|
| 2687 | - } |
|
| 2688 | - |
|
| 2689 | - update_option('timezone_string', $timezone_string); |
|
| 2690 | - EE_Error::add_success( |
|
| 2691 | - esc_html__('Your timezone string was updated.', 'event_espresso') |
|
| 2692 | - ); |
|
| 2693 | - $this->_template_args['success'] = true; |
|
| 2694 | - $this->_return_json(true, array('action' => 'create_new')); |
|
| 2695 | - } |
|
| 22 | + /** |
|
| 23 | + * This will hold the event object for event_details screen. |
|
| 24 | + * |
|
| 25 | + * @var EE_Event $_event |
|
| 26 | + */ |
|
| 27 | + protected $_event; |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * This will hold the category object for category_details screen. |
|
| 32 | + * |
|
| 33 | + * @var stdClass $_category |
|
| 34 | + */ |
|
| 35 | + protected $_category; |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * This will hold the event model instance |
|
| 40 | + * |
|
| 41 | + * @var EEM_Event $_event_model |
|
| 42 | + */ |
|
| 43 | + protected $_event_model; |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var EE_Event |
|
| 48 | + */ |
|
| 49 | + protected $_cpt_model_obj = false; |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var NodeGroupDao |
|
| 54 | + */ |
|
| 55 | + protected $model_obj_node_group_persister; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Initialize page props for this admin page group. |
|
| 59 | + */ |
|
| 60 | + protected function _init_page_props() |
|
| 61 | + { |
|
| 62 | + $this->page_slug = EVENTS_PG_SLUG; |
|
| 63 | + $this->page_label = EVENTS_LABEL; |
|
| 64 | + $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 65 | + $this->_admin_base_path = EVENTS_ADMIN; |
|
| 66 | + $this->_cpt_model_names = array( |
|
| 67 | + 'create_new' => 'EEM_Event', |
|
| 68 | + 'edit' => 'EEM_Event', |
|
| 69 | + ); |
|
| 70 | + $this->_cpt_edit_routes = array( |
|
| 71 | + 'espresso_events' => 'edit', |
|
| 72 | + ); |
|
| 73 | + add_action( |
|
| 74 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 75 | + array($this, 'verify_event_edit'), |
|
| 76 | + 10, |
|
| 77 | + 2 |
|
| 78 | + ); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Sets the ajax hooks used for this admin page group. |
|
| 84 | + */ |
|
| 85 | + protected function _ajax_hooks() |
|
| 86 | + { |
|
| 87 | + add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting')); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Sets the page properties for this admin page group. |
|
| 93 | + */ |
|
| 94 | + protected function _define_page_props() |
|
| 95 | + { |
|
| 96 | + $this->_admin_page_title = EVENTS_LABEL; |
|
| 97 | + $this->_labels = array( |
|
| 98 | + 'buttons' => array( |
|
| 99 | + 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 100 | + 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 101 | + 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 102 | + 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 103 | + 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 104 | + 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 105 | + ), |
|
| 106 | + 'editor_title' => array( |
|
| 107 | + 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 108 | + ), |
|
| 109 | + 'publishbox' => array( |
|
| 110 | + 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 111 | + 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 112 | + 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 113 | + 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 114 | + 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 115 | + ), |
|
| 116 | + ); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Sets the page routes property for this admin page group. |
|
| 122 | + */ |
|
| 123 | + protected function _set_page_routes() |
|
| 124 | + { |
|
| 125 | + // load formatter helper |
|
| 126 | + // load field generator helper |
|
| 127 | + // is there a evt_id in the request? |
|
| 128 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 129 | + ? $this->_req_data['EVT_ID'] |
|
| 130 | + : 0; |
|
| 131 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 132 | + $this->_page_routes = array( |
|
| 133 | + 'default' => array( |
|
| 134 | + 'func' => '_events_overview_list_table', |
|
| 135 | + 'capability' => 'ee_read_events', |
|
| 136 | + ), |
|
| 137 | + 'create_new' => array( |
|
| 138 | + 'func' => '_create_new_cpt_item', |
|
| 139 | + 'capability' => 'ee_edit_events', |
|
| 140 | + ), |
|
| 141 | + 'edit' => array( |
|
| 142 | + 'func' => '_edit_cpt_item', |
|
| 143 | + 'capability' => 'ee_edit_event', |
|
| 144 | + 'obj_id' => $evt_id, |
|
| 145 | + ), |
|
| 146 | + 'copy_event' => array( |
|
| 147 | + 'func' => '_copy_events', |
|
| 148 | + 'capability' => 'ee_edit_event', |
|
| 149 | + 'obj_id' => $evt_id, |
|
| 150 | + 'noheader' => true, |
|
| 151 | + ), |
|
| 152 | + 'trash_event' => array( |
|
| 153 | + 'func' => '_trash_or_restore_event', |
|
| 154 | + 'args' => array('event_status' => 'trash'), |
|
| 155 | + 'capability' => 'ee_delete_event', |
|
| 156 | + 'obj_id' => $evt_id, |
|
| 157 | + 'noheader' => true, |
|
| 158 | + ), |
|
| 159 | + 'trash_events' => array( |
|
| 160 | + 'func' => '_trash_or_restore_events', |
|
| 161 | + 'args' => array('event_status' => 'trash'), |
|
| 162 | + 'capability' => 'ee_delete_events', |
|
| 163 | + 'noheader' => true, |
|
| 164 | + ), |
|
| 165 | + 'restore_event' => array( |
|
| 166 | + 'func' => '_trash_or_restore_event', |
|
| 167 | + 'args' => array('event_status' => 'draft'), |
|
| 168 | + 'capability' => 'ee_delete_event', |
|
| 169 | + 'obj_id' => $evt_id, |
|
| 170 | + 'noheader' => true, |
|
| 171 | + ), |
|
| 172 | + 'restore_events' => array( |
|
| 173 | + 'func' => '_trash_or_restore_events', |
|
| 174 | + 'args' => array('event_status' => 'draft'), |
|
| 175 | + 'capability' => 'ee_delete_events', |
|
| 176 | + 'noheader' => true, |
|
| 177 | + ), |
|
| 178 | + 'delete_event' => array( |
|
| 179 | + 'func' => '_delete_event', |
|
| 180 | + 'capability' => 'ee_delete_event', |
|
| 181 | + 'obj_id' => $evt_id, |
|
| 182 | + 'noheader' => true, |
|
| 183 | + ), |
|
| 184 | + 'delete_events' => array( |
|
| 185 | + 'func' => '_delete_events', |
|
| 186 | + 'capability' => 'ee_delete_events', |
|
| 187 | + 'noheader' => true, |
|
| 188 | + ), |
|
| 189 | + 'view_report' => array( |
|
| 190 | + 'func' => '_view_report', |
|
| 191 | + 'capablity' => 'ee_edit_events', |
|
| 192 | + ), |
|
| 193 | + 'default_event_settings' => array( |
|
| 194 | + 'func' => '_default_event_settings', |
|
| 195 | + 'capability' => 'manage_options', |
|
| 196 | + ), |
|
| 197 | + 'update_default_event_settings' => array( |
|
| 198 | + 'func' => '_update_default_event_settings', |
|
| 199 | + 'capability' => 'manage_options', |
|
| 200 | + 'noheader' => true, |
|
| 201 | + ), |
|
| 202 | + 'template_settings' => array( |
|
| 203 | + 'func' => '_template_settings', |
|
| 204 | + 'capability' => 'manage_options', |
|
| 205 | + ), |
|
| 206 | + // event category tab related |
|
| 207 | + 'add_category' => array( |
|
| 208 | + 'func' => '_category_details', |
|
| 209 | + 'capability' => 'ee_edit_event_category', |
|
| 210 | + 'args' => array('add'), |
|
| 211 | + ), |
|
| 212 | + 'edit_category' => array( |
|
| 213 | + 'func' => '_category_details', |
|
| 214 | + 'capability' => 'ee_edit_event_category', |
|
| 215 | + 'args' => array('edit'), |
|
| 216 | + ), |
|
| 217 | + 'delete_categories' => array( |
|
| 218 | + 'func' => '_delete_categories', |
|
| 219 | + 'capability' => 'ee_delete_event_category', |
|
| 220 | + 'noheader' => true, |
|
| 221 | + ), |
|
| 222 | + 'delete_category' => array( |
|
| 223 | + 'func' => '_delete_categories', |
|
| 224 | + 'capability' => 'ee_delete_event_category', |
|
| 225 | + 'noheader' => true, |
|
| 226 | + ), |
|
| 227 | + 'insert_category' => array( |
|
| 228 | + 'func' => '_insert_or_update_category', |
|
| 229 | + 'args' => array('new_category' => true), |
|
| 230 | + 'capability' => 'ee_edit_event_category', |
|
| 231 | + 'noheader' => true, |
|
| 232 | + ), |
|
| 233 | + 'update_category' => array( |
|
| 234 | + 'func' => '_insert_or_update_category', |
|
| 235 | + 'args' => array('new_category' => false), |
|
| 236 | + 'capability' => 'ee_edit_event_category', |
|
| 237 | + 'noheader' => true, |
|
| 238 | + ), |
|
| 239 | + 'category_list' => array( |
|
| 240 | + 'func' => '_category_list_table', |
|
| 241 | + 'capability' => 'ee_manage_event_categories', |
|
| 242 | + ), |
|
| 243 | + 'preview_deletion' => [ |
|
| 244 | + 'func' => 'previewDeletion', |
|
| 245 | + 'capability' => 'ee_delete_events', |
|
| 246 | + ], |
|
| 247 | + 'confirm_deletion' => [ |
|
| 248 | + 'func' => 'confirmDeletion', |
|
| 249 | + 'capability' => 'ee_delete_events', |
|
| 250 | + 'noheader' => true, |
|
| 251 | + ] |
|
| 252 | + ); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * Set the _page_config property for this admin page group. |
|
| 258 | + */ |
|
| 259 | + protected function _set_page_config() |
|
| 260 | + { |
|
| 261 | + $this->_page_config = array( |
|
| 262 | + 'default' => array( |
|
| 263 | + 'nav' => array( |
|
| 264 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 265 | + 'order' => 10, |
|
| 266 | + ), |
|
| 267 | + 'list_table' => 'Events_Admin_List_Table', |
|
| 268 | + 'help_tabs' => array( |
|
| 269 | + 'events_overview_help_tab' => array( |
|
| 270 | + 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 271 | + 'filename' => 'events_overview', |
|
| 272 | + ), |
|
| 273 | + 'events_overview_table_column_headings_help_tab' => array( |
|
| 274 | + 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 275 | + 'filename' => 'events_overview_table_column_headings', |
|
| 276 | + ), |
|
| 277 | + 'events_overview_filters_help_tab' => array( |
|
| 278 | + 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 279 | + 'filename' => 'events_overview_filters', |
|
| 280 | + ), |
|
| 281 | + 'events_overview_view_help_tab' => array( |
|
| 282 | + 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 283 | + 'filename' => 'events_overview_views', |
|
| 284 | + ), |
|
| 285 | + 'events_overview_other_help_tab' => array( |
|
| 286 | + 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 287 | + 'filename' => 'events_overview_other', |
|
| 288 | + ), |
|
| 289 | + ), |
|
| 290 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 291 | + // 'help_tour' => array( |
|
| 292 | + // 'Event_Overview_Help_Tour', |
|
| 293 | + // // 'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 294 | + // ), |
|
| 295 | + 'qtips' => array( |
|
| 296 | + 'EE_Event_List_Table_Tips', |
|
| 297 | + ), |
|
| 298 | + 'require_nonce' => false, |
|
| 299 | + ), |
|
| 300 | + 'create_new' => array( |
|
| 301 | + 'nav' => array( |
|
| 302 | + 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 303 | + 'order' => 5, |
|
| 304 | + 'persistent' => false, |
|
| 305 | + ), |
|
| 306 | + 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 307 | + 'help_tabs' => array( |
|
| 308 | + 'event_editor_help_tab' => array( |
|
| 309 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 310 | + 'filename' => 'event_editor', |
|
| 311 | + ), |
|
| 312 | + 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 313 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 314 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 315 | + ), |
|
| 316 | + 'event_editor_venue_details_help_tab' => array( |
|
| 317 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 318 | + 'filename' => 'event_editor_venue_details', |
|
| 319 | + ), |
|
| 320 | + 'event_editor_event_datetimes_help_tab' => array( |
|
| 321 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 322 | + 'filename' => 'event_editor_event_datetimes', |
|
| 323 | + ), |
|
| 324 | + 'event_editor_event_tickets_help_tab' => array( |
|
| 325 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 326 | + 'filename' => 'event_editor_event_tickets', |
|
| 327 | + ), |
|
| 328 | + 'event_editor_event_registration_options_help_tab' => array( |
|
| 329 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 330 | + 'filename' => 'event_editor_event_registration_options', |
|
| 331 | + ), |
|
| 332 | + 'event_editor_tags_categories_help_tab' => array( |
|
| 333 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 334 | + 'filename' => 'event_editor_tags_categories', |
|
| 335 | + ), |
|
| 336 | + 'event_editor_questions_registrants_help_tab' => array( |
|
| 337 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 338 | + 'filename' => 'event_editor_questions_registrants', |
|
| 339 | + ), |
|
| 340 | + 'event_editor_save_new_event_help_tab' => array( |
|
| 341 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 342 | + 'filename' => 'event_editor_save_new_event', |
|
| 343 | + ), |
|
| 344 | + 'event_editor_other_help_tab' => array( |
|
| 345 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 346 | + 'filename' => 'event_editor_other', |
|
| 347 | + ), |
|
| 348 | + ), |
|
| 349 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 350 | + // 'help_tour' => array( |
|
| 351 | + // 'Event_Editor_Help_Tour', |
|
| 352 | + // ), |
|
| 353 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 354 | + 'require_nonce' => false, |
|
| 355 | + ), |
|
| 356 | + 'edit' => array( |
|
| 357 | + 'nav' => array( |
|
| 358 | + 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 359 | + 'order' => 5, |
|
| 360 | + 'persistent' => false, |
|
| 361 | + 'url' => isset($this->_req_data['post']) |
|
| 362 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 363 | + array('post' => $this->_req_data['post'], 'action' => 'edit'), |
|
| 364 | + $this->_current_page_view_url |
|
| 365 | + ) |
|
| 366 | + : $this->_admin_base_url, |
|
| 367 | + ), |
|
| 368 | + 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 369 | + 'help_tabs' => array( |
|
| 370 | + 'event_editor_help_tab' => array( |
|
| 371 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 372 | + 'filename' => 'event_editor', |
|
| 373 | + ), |
|
| 374 | + 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 375 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 376 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 377 | + ), |
|
| 378 | + 'event_editor_venue_details_help_tab' => array( |
|
| 379 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 380 | + 'filename' => 'event_editor_venue_details', |
|
| 381 | + ), |
|
| 382 | + 'event_editor_event_datetimes_help_tab' => array( |
|
| 383 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 384 | + 'filename' => 'event_editor_event_datetimes', |
|
| 385 | + ), |
|
| 386 | + 'event_editor_event_tickets_help_tab' => array( |
|
| 387 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 388 | + 'filename' => 'event_editor_event_tickets', |
|
| 389 | + ), |
|
| 390 | + 'event_editor_event_registration_options_help_tab' => array( |
|
| 391 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 392 | + 'filename' => 'event_editor_event_registration_options', |
|
| 393 | + ), |
|
| 394 | + 'event_editor_tags_categories_help_tab' => array( |
|
| 395 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 396 | + 'filename' => 'event_editor_tags_categories', |
|
| 397 | + ), |
|
| 398 | + 'event_editor_questions_registrants_help_tab' => array( |
|
| 399 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 400 | + 'filename' => 'event_editor_questions_registrants', |
|
| 401 | + ), |
|
| 402 | + 'event_editor_save_new_event_help_tab' => array( |
|
| 403 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 404 | + 'filename' => 'event_editor_save_new_event', |
|
| 405 | + ), |
|
| 406 | + 'event_editor_other_help_tab' => array( |
|
| 407 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 408 | + 'filename' => 'event_editor_other', |
|
| 409 | + ), |
|
| 410 | + ), |
|
| 411 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 412 | + 'require_nonce' => false, |
|
| 413 | + ), |
|
| 414 | + 'default_event_settings' => array( |
|
| 415 | + 'nav' => array( |
|
| 416 | + 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 417 | + 'order' => 40, |
|
| 418 | + ), |
|
| 419 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 420 | + 'labels' => array( |
|
| 421 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 422 | + ), |
|
| 423 | + 'help_tabs' => array( |
|
| 424 | + 'default_settings_help_tab' => array( |
|
| 425 | + 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 426 | + 'filename' => 'events_default_settings', |
|
| 427 | + ), |
|
| 428 | + 'default_settings_status_help_tab' => array( |
|
| 429 | + 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 430 | + 'filename' => 'events_default_settings_status', |
|
| 431 | + ), |
|
| 432 | + 'default_maximum_tickets_help_tab' => array( |
|
| 433 | + 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
| 434 | + 'filename' => 'events_default_settings_max_tickets', |
|
| 435 | + ), |
|
| 436 | + ), |
|
| 437 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 438 | + // 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
| 439 | + 'require_nonce' => false, |
|
| 440 | + ), |
|
| 441 | + // template settings |
|
| 442 | + 'template_settings' => array( |
|
| 443 | + 'nav' => array( |
|
| 444 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 445 | + 'order' => 30, |
|
| 446 | + ), |
|
| 447 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 448 | + 'help_tabs' => array( |
|
| 449 | + 'general_settings_templates_help_tab' => array( |
|
| 450 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 451 | + 'filename' => 'general_settings_templates', |
|
| 452 | + ), |
|
| 453 | + ), |
|
| 454 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 455 | + // 'help_tour' => array('Templates_Help_Tour'), |
|
| 456 | + 'require_nonce' => false, |
|
| 457 | + ), |
|
| 458 | + // event category stuff |
|
| 459 | + 'add_category' => array( |
|
| 460 | + 'nav' => array( |
|
| 461 | + 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 462 | + 'order' => 15, |
|
| 463 | + 'persistent' => false, |
|
| 464 | + ), |
|
| 465 | + 'help_tabs' => array( |
|
| 466 | + 'add_category_help_tab' => array( |
|
| 467 | + 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 468 | + 'filename' => 'events_add_category', |
|
| 469 | + ), |
|
| 470 | + ), |
|
| 471 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 472 | + // 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
| 473 | + 'metaboxes' => array('_publish_post_box'), |
|
| 474 | + 'require_nonce' => false, |
|
| 475 | + ), |
|
| 476 | + 'edit_category' => array( |
|
| 477 | + 'nav' => array( |
|
| 478 | + 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 479 | + 'order' => 15, |
|
| 480 | + 'persistent' => false, |
|
| 481 | + 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
| 482 | + ? add_query_arg( |
|
| 483 | + array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), |
|
| 484 | + $this->_current_page_view_url |
|
| 485 | + ) |
|
| 486 | + : $this->_admin_base_url, |
|
| 487 | + ), |
|
| 488 | + 'help_tabs' => array( |
|
| 489 | + 'edit_category_help_tab' => array( |
|
| 490 | + 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 491 | + 'filename' => 'events_edit_category', |
|
| 492 | + ), |
|
| 493 | + ), |
|
| 494 | + /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
| 495 | + 'metaboxes' => array('_publish_post_box'), |
|
| 496 | + 'require_nonce' => false, |
|
| 497 | + ), |
|
| 498 | + 'category_list' => array( |
|
| 499 | + 'nav' => array( |
|
| 500 | + 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 501 | + 'order' => 20, |
|
| 502 | + ), |
|
| 503 | + 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 504 | + 'help_tabs' => array( |
|
| 505 | + 'events_categories_help_tab' => array( |
|
| 506 | + 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 507 | + 'filename' => 'events_categories', |
|
| 508 | + ), |
|
| 509 | + 'events_categories_table_column_headings_help_tab' => array( |
|
| 510 | + 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 511 | + 'filename' => 'events_categories_table_column_headings', |
|
| 512 | + ), |
|
| 513 | + 'events_categories_view_help_tab' => array( |
|
| 514 | + 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 515 | + 'filename' => 'events_categories_views', |
|
| 516 | + ), |
|
| 517 | + 'events_categories_other_help_tab' => array( |
|
| 518 | + 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 519 | + 'filename' => 'events_categories_other', |
|
| 520 | + ), |
|
| 521 | + ), |
|
| 522 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 523 | + // 'help_tour' => array( |
|
| 524 | + // 'Event_Categories_Help_Tour', |
|
| 525 | + // ), |
|
| 526 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 527 | + 'require_nonce' => false, |
|
| 528 | + ), |
|
| 529 | + 'preview_deletion' => array( |
|
| 530 | + 'nav' => array( |
|
| 531 | + 'label' => esc_html__('Preview Deletion', 'event_espresso'), |
|
| 532 | + 'order' => 15, |
|
| 533 | + 'persistent' => false, |
|
| 534 | + 'url' => '', |
|
| 535 | + ), |
|
| 536 | + 'require_nonce' => false |
|
| 537 | + ) |
|
| 538 | + ); |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * Used to register any global screen options if necessary for every route in this admin page group. |
|
| 544 | + */ |
|
| 545 | + protected function _add_screen_options() |
|
| 546 | + { |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * Implementing the screen options for the 'default' route. |
|
| 552 | + */ |
|
| 553 | + protected function _add_screen_options_default() |
|
| 554 | + { |
|
| 555 | + $this->_per_page_screen_option(); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * Implementing screen options for the category list route. |
|
| 561 | + */ |
|
| 562 | + protected function _add_screen_options_category_list() |
|
| 563 | + { |
|
| 564 | + $page_title = $this->_admin_page_title; |
|
| 565 | + $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 566 | + $this->_per_page_screen_option(); |
|
| 567 | + $this->_admin_page_title = $page_title; |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * Used to register any global feature pointers for the admin page group. |
|
| 573 | + */ |
|
| 574 | + protected function _add_feature_pointers() |
|
| 575 | + { |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * Registers and enqueues any global scripts and styles for the entire admin page group. |
|
| 581 | + */ |
|
| 582 | + public function load_scripts_styles() |
|
| 583 | + { |
|
| 584 | + wp_register_style( |
|
| 585 | + 'events-admin-css', |
|
| 586 | + EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 587 | + array(), |
|
| 588 | + EVENT_ESPRESSO_VERSION |
|
| 589 | + ); |
|
| 590 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 591 | + wp_enqueue_style('events-admin-css'); |
|
| 592 | + wp_enqueue_style('ee-cat-admin'); |
|
| 593 | + // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
| 594 | + // registers for all views |
|
| 595 | + // scripts |
|
| 596 | + wp_register_script( |
|
| 597 | + 'event_editor_js', |
|
| 598 | + EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 599 | + array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
|
| 600 | + EVENT_ESPRESSO_VERSION, |
|
| 601 | + true |
|
| 602 | + ); |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + |
|
| 606 | + /** |
|
| 607 | + * Enqueuing scripts and styles specific to this view |
|
| 608 | + */ |
|
| 609 | + public function load_scripts_styles_create_new() |
|
| 610 | + { |
|
| 611 | + $this->load_scripts_styles_edit(); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * Enqueuing scripts and styles specific to this view |
|
| 617 | + */ |
|
| 618 | + public function load_scripts_styles_edit() |
|
| 619 | + { |
|
| 620 | + // styles |
|
| 621 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 622 | + wp_register_style( |
|
| 623 | + 'event-editor-css', |
|
| 624 | + EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 625 | + array('ee-admin-css'), |
|
| 626 | + EVENT_ESPRESSO_VERSION |
|
| 627 | + ); |
|
| 628 | + wp_enqueue_style('event-editor-css'); |
|
| 629 | + // scripts |
|
| 630 | + wp_register_script( |
|
| 631 | + 'event-datetime-metabox', |
|
| 632 | + EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 633 | + array('event_editor_js', 'ee-datepicker'), |
|
| 634 | + EVENT_ESPRESSO_VERSION |
|
| 635 | + ); |
|
| 636 | + wp_enqueue_script('event-datetime-metabox'); |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + |
|
| 640 | + /** |
|
| 641 | + * Populating the _views property for the category list table view. |
|
| 642 | + */ |
|
| 643 | + protected function _set_list_table_views_category_list() |
|
| 644 | + { |
|
| 645 | + $this->_views = array( |
|
| 646 | + 'all' => array( |
|
| 647 | + 'slug' => 'all', |
|
| 648 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 649 | + 'count' => 0, |
|
| 650 | + 'bulk_action' => array( |
|
| 651 | + 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 652 | + ), |
|
| 653 | + ), |
|
| 654 | + ); |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + |
|
| 658 | + /** |
|
| 659 | + * For adding anything that fires on the admin_init hook for any route within this admin page group. |
|
| 660 | + */ |
|
| 661 | + public function admin_init() |
|
| 662 | + { |
|
| 663 | + EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 664 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 665 | + 'event_espresso' |
|
| 666 | + ); |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * For adding anything that should be triggered on the admin_notices hook for any route within this admin page |
|
| 672 | + * group. |
|
| 673 | + */ |
|
| 674 | + public function admin_notices() |
|
| 675 | + { |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within |
|
| 681 | + * this admin page group. |
|
| 682 | + */ |
|
| 683 | + public function admin_footer_scripts() |
|
| 684 | + { |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 690 | + * warning (via EE_Error::add_error()); |
|
| 691 | + * |
|
| 692 | + * @param EE_Event $event Event object |
|
| 693 | + * @param string $req_type |
|
| 694 | + * @return void |
|
| 695 | + * @throws EE_Error |
|
| 696 | + * @access public |
|
| 697 | + */ |
|
| 698 | + public function verify_event_edit($event = null, $req_type = '') |
|
| 699 | + { |
|
| 700 | + // don't need to do this when processing |
|
| 701 | + if (! empty($req_type)) { |
|
| 702 | + return; |
|
| 703 | + } |
|
| 704 | + // no event? |
|
| 705 | + if (empty($event)) { |
|
| 706 | + // set event |
|
| 707 | + $event = $this->_cpt_model_obj; |
|
| 708 | + } |
|
| 709 | + // STILL no event? |
|
| 710 | + if (! $event instanceof EE_Event) { |
|
| 711 | + return; |
|
| 712 | + } |
|
| 713 | + $orig_status = $event->status(); |
|
| 714 | + // first check if event is active. |
|
| 715 | + if ( |
|
| 716 | + $orig_status === EEM_Event::cancelled |
|
| 717 | + || $orig_status === EEM_Event::postponed |
|
| 718 | + || $event->is_expired() |
|
| 719 | + || $event->is_inactive() |
|
| 720 | + ) { |
|
| 721 | + return; |
|
| 722 | + } |
|
| 723 | + // made it here so it IS active... next check that any of the tickets are sold. |
|
| 724 | + if ($event->is_sold_out(true)) { |
|
| 725 | + if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 726 | + EE_Error::add_attention( |
|
| 727 | + sprintf( |
|
| 728 | + esc_html__( |
|
| 729 | + 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
| 730 | + 'event_espresso' |
|
| 731 | + ), |
|
| 732 | + EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 733 | + ) |
|
| 734 | + ); |
|
| 735 | + } |
|
| 736 | + return; |
|
| 737 | + } elseif ($orig_status === EEM_Event::sold_out) { |
|
| 738 | + EE_Error::add_attention( |
|
| 739 | + sprintf( |
|
| 740 | + esc_html__( |
|
| 741 | + 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
| 742 | + 'event_espresso' |
|
| 743 | + ), |
|
| 744 | + EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 745 | + ) |
|
| 746 | + ); |
|
| 747 | + } |
|
| 748 | + // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 749 | + if (! $event->tickets_on_sale()) { |
|
| 750 | + return; |
|
| 751 | + } |
|
| 752 | + // made it here so show warning |
|
| 753 | + $this->_edit_event_warning(); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + |
|
| 757 | + /** |
|
| 758 | + * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 759 | + * When needed, hook this into a EE_Error::add_error() notice. |
|
| 760 | + * |
|
| 761 | + * @access protected |
|
| 762 | + * @return void |
|
| 763 | + */ |
|
| 764 | + protected function _edit_event_warning() |
|
| 765 | + { |
|
| 766 | + // we don't want to add warnings during these requests |
|
| 767 | + if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
| 768 | + return; |
|
| 769 | + } |
|
| 770 | + EE_Error::add_attention( |
|
| 771 | + sprintf( |
|
| 772 | + esc_html__( |
|
| 773 | + 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s', |
|
| 774 | + 'event_espresso' |
|
| 775 | + ), |
|
| 776 | + '<a class="espresso-help-tab-lnk">', |
|
| 777 | + '</a>' |
|
| 778 | + ) |
|
| 779 | + ); |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + |
|
| 783 | + /** |
|
| 784 | + * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 785 | + * Otherwise, do the normal logic |
|
| 786 | + * |
|
| 787 | + * @return string |
|
| 788 | + * @throws \EE_Error |
|
| 789 | + */ |
|
| 790 | + protected function _create_new_cpt_item() |
|
| 791 | + { |
|
| 792 | + $has_timezone_string = get_option('timezone_string'); |
|
| 793 | + // only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 794 | + if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) { |
|
| 795 | + EE_Error::add_attention( |
|
| 796 | + sprintf( |
|
| 797 | + esc_html__( |
|
| 798 | + 'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s', |
|
| 799 | + 'event_espresso' |
|
| 800 | + ), |
|
| 801 | + '<br>', |
|
| 802 | + '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">' |
|
| 803 | + . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) |
|
| 804 | + . '</select>', |
|
| 805 | + '<button class="button button-secondary timezone-submit">', |
|
| 806 | + '</button><span class="spinner"></span>' |
|
| 807 | + ), |
|
| 808 | + __FILE__, |
|
| 809 | + __FUNCTION__, |
|
| 810 | + __LINE__ |
|
| 811 | + ); |
|
| 812 | + } |
|
| 813 | + return parent::_create_new_cpt_item(); |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + |
|
| 817 | + /** |
|
| 818 | + * Sets the _views property for the default route in this admin page group. |
|
| 819 | + */ |
|
| 820 | + protected function _set_list_table_views_default() |
|
| 821 | + { |
|
| 822 | + $this->_views = array( |
|
| 823 | + 'all' => array( |
|
| 824 | + 'slug' => 'all', |
|
| 825 | + 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 826 | + 'count' => 0, |
|
| 827 | + 'bulk_action' => array( |
|
| 828 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 829 | + ), |
|
| 830 | + ), |
|
| 831 | + 'draft' => array( |
|
| 832 | + 'slug' => 'draft', |
|
| 833 | + 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 834 | + 'count' => 0, |
|
| 835 | + 'bulk_action' => array( |
|
| 836 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 837 | + ), |
|
| 838 | + ), |
|
| 839 | + ); |
|
| 840 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 841 | + $this->_views['trash'] = array( |
|
| 842 | + 'slug' => 'trash', |
|
| 843 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 844 | + 'count' => 0, |
|
| 845 | + 'bulk_action' => array( |
|
| 846 | + 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 847 | + 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 848 | + ), |
|
| 849 | + ); |
|
| 850 | + } |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + |
|
| 854 | + /** |
|
| 855 | + * Provides the legend item array for the default list table view. |
|
| 856 | + * |
|
| 857 | + * @return array |
|
| 858 | + */ |
|
| 859 | + protected function _event_legend_items() |
|
| 860 | + { |
|
| 861 | + $items = array( |
|
| 862 | + 'view_details' => array( |
|
| 863 | + 'class' => 'dashicons dashicons-search', |
|
| 864 | + 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 865 | + ), |
|
| 866 | + 'edit_event' => array( |
|
| 867 | + 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 868 | + 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 869 | + ), |
|
| 870 | + 'view_attendees' => array( |
|
| 871 | + 'class' => 'dashicons dashicons-groups', |
|
| 872 | + 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 873 | + ), |
|
| 874 | + ); |
|
| 875 | + $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 876 | + $statuses = array( |
|
| 877 | + 'sold_out_status' => array( |
|
| 878 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 879 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 880 | + ), |
|
| 881 | + 'active_status' => array( |
|
| 882 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 883 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 884 | + ), |
|
| 885 | + 'upcoming_status' => array( |
|
| 886 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 887 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 888 | + ), |
|
| 889 | + 'postponed_status' => array( |
|
| 890 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 891 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 892 | + ), |
|
| 893 | + 'cancelled_status' => array( |
|
| 894 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 895 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 896 | + ), |
|
| 897 | + 'expired_status' => array( |
|
| 898 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 899 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 900 | + ), |
|
| 901 | + 'inactive_status' => array( |
|
| 902 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 903 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 904 | + ), |
|
| 905 | + ); |
|
| 906 | + $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 907 | + return array_merge($items, $statuses); |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + |
|
| 911 | + /** |
|
| 912 | + * @return EEM_Event |
|
| 913 | + */ |
|
| 914 | + private function _event_model() |
|
| 915 | + { |
|
| 916 | + if (! $this->_event_model instanceof EEM_Event) { |
|
| 917 | + $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 918 | + } |
|
| 919 | + return $this->_event_model; |
|
| 920 | + } |
|
| 921 | + |
|
| 922 | + |
|
| 923 | + /** |
|
| 924 | + * Adds extra buttons to the WP CPT permalink field row. |
|
| 925 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 926 | + * |
|
| 927 | + * @param string $return the current html |
|
| 928 | + * @param int $id the post id for the page |
|
| 929 | + * @param string $new_title What the title is |
|
| 930 | + * @param string $new_slug what the slug is |
|
| 931 | + * @return string The new html string for the permalink area |
|
| 932 | + */ |
|
| 933 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 934 | + { |
|
| 935 | + // make sure this is only when editing |
|
| 936 | + if (! empty($id)) { |
|
| 937 | + $post = get_post($id); |
|
| 938 | + $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 939 | + . esc_html__('Shortcode', 'event_espresso') |
|
| 940 | + . '</a> '; |
|
| 941 | + $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 942 | + . $post->ID |
|
| 943 | + . ']">'; |
|
| 944 | + } |
|
| 945 | + return $return; |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + |
|
| 949 | + /** |
|
| 950 | + * _events_overview_list_table |
|
| 951 | + * This contains the logic for showing the events_overview list |
|
| 952 | + * |
|
| 953 | + * @access protected |
|
| 954 | + * @return void |
|
| 955 | + * @throws \EE_Error |
|
| 956 | + */ |
|
| 957 | + protected function _events_overview_list_table() |
|
| 958 | + { |
|
| 959 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 960 | + $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
|
| 961 | + ? (array) $this->_template_args['after_list_table'] |
|
| 962 | + : array(); |
|
| 963 | + $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
| 964 | + . EEH_Template::get_button_or_link( |
|
| 965 | + get_post_type_archive_link('espresso_events'), |
|
| 966 | + esc_html__("View Event Archive Page", "event_espresso"), |
|
| 967 | + 'button' |
|
| 968 | + ); |
|
| 969 | + $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
| 970 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 971 | + 'create_new', |
|
| 972 | + 'add', |
|
| 973 | + array(), |
|
| 974 | + 'add-new-h2' |
|
| 975 | + ); |
|
| 976 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 977 | + } |
|
| 978 | + |
|
| 979 | + |
|
| 980 | + /** |
|
| 981 | + * this allows for extra misc actions in the default WP publish box |
|
| 982 | + * |
|
| 983 | + * @return void |
|
| 984 | + */ |
|
| 985 | + public function extra_misc_actions_publish_box() |
|
| 986 | + { |
|
| 987 | + $this->_generate_publish_box_extra_content(); |
|
| 988 | + } |
|
| 989 | + |
|
| 990 | + |
|
| 991 | + /** |
|
| 992 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 993 | + * saved. |
|
| 994 | + * Typically you would use this to save any additional data. |
|
| 995 | + * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 996 | + * ALSO very important. When a post transitions from scheduled to published, |
|
| 997 | + * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from |
|
| 998 | + * other meta saves. So MAKE sure that you handle this accordingly. |
|
| 999 | + * |
|
| 1000 | + * @access protected |
|
| 1001 | + * @abstract |
|
| 1002 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 1003 | + * @param object $post The post object of the cpt that was saved. |
|
| 1004 | + * @return void |
|
| 1005 | + * @throws \EE_Error |
|
| 1006 | + */ |
|
| 1007 | + protected function _insert_update_cpt_item($post_id, $post) |
|
| 1008 | + { |
|
| 1009 | + if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 1010 | + // get out we're not processing an event save. |
|
| 1011 | + return; |
|
| 1012 | + } |
|
| 1013 | + $event_values = array( |
|
| 1014 | + 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
| 1015 | + 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
| 1016 | + 'EVT_additional_limit' => min( |
|
| 1017 | + apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 1018 | + ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null |
|
| 1019 | + ), |
|
| 1020 | + 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) |
|
| 1021 | + ? $this->_req_data['EVT_default_registration_status'] |
|
| 1022 | + : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 1023 | + 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
| 1024 | + 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
| 1025 | + 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
| 1026 | + ? $this->_req_data['timezone_string'] : null, |
|
| 1027 | + 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) |
|
| 1028 | + ? $this->_req_data['externalURL'] : null, |
|
| 1029 | + 'EVT_phone' => ! empty($this->_req_data['event_phone']) |
|
| 1030 | + ? $this->_req_data['event_phone'] : null, |
|
| 1031 | + ); |
|
| 1032 | + // update event |
|
| 1033 | + $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 1034 | + // get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
|
| 1035 | + $get_one_where = array( |
|
| 1036 | + $this->_event_model()->primary_key_name() => $post_id, |
|
| 1037 | + 'OR' => array( |
|
| 1038 | + 'status' => $post->post_status, |
|
| 1039 | + // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db, |
|
| 1040 | + // but the returned object here has a status of "publish", so use the original post status as well |
|
| 1041 | + 'status*1' => $this->_req_data['original_post_status'], |
|
| 1042 | + ), |
|
| 1043 | + ); |
|
| 1044 | + $event = $this->_event_model()->get_one(array($get_one_where)); |
|
| 1045 | + // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
| 1046 | + $event_update_callbacks = apply_filters( |
|
| 1047 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 1048 | + array( |
|
| 1049 | + array($this, '_default_venue_update'), |
|
| 1050 | + array($this, '_default_tickets_update'), |
|
| 1051 | + ) |
|
| 1052 | + ); |
|
| 1053 | + $att_success = true; |
|
| 1054 | + foreach ($event_update_callbacks as $e_callback) { |
|
| 1055 | + $_success = is_callable($e_callback) |
|
| 1056 | + ? call_user_func($e_callback, $event, $this->_req_data) |
|
| 1057 | + : false; |
|
| 1058 | + // if ANY of these updates fail then we want the appropriate global error message |
|
| 1059 | + $att_success = ! $att_success ? $att_success : $_success; |
|
| 1060 | + } |
|
| 1061 | + // any errors? |
|
| 1062 | + if ($success && false === $att_success) { |
|
| 1063 | + EE_Error::add_error( |
|
| 1064 | + esc_html__( |
|
| 1065 | + 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1066 | + 'event_espresso' |
|
| 1067 | + ), |
|
| 1068 | + __FILE__, |
|
| 1069 | + __FUNCTION__, |
|
| 1070 | + __LINE__ |
|
| 1071 | + ); |
|
| 1072 | + } elseif ($success === false) { |
|
| 1073 | + EE_Error::add_error( |
|
| 1074 | + esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1075 | + __FILE__, |
|
| 1076 | + __FUNCTION__, |
|
| 1077 | + __LINE__ |
|
| 1078 | + ); |
|
| 1079 | + } |
|
| 1080 | + } |
|
| 1081 | + |
|
| 1082 | + |
|
| 1083 | + /** |
|
| 1084 | + * @see parent::restore_item() |
|
| 1085 | + * @param int $post_id |
|
| 1086 | + * @param int $revision_id |
|
| 1087 | + */ |
|
| 1088 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
| 1089 | + { |
|
| 1090 | + // copy existing event meta to new post |
|
| 1091 | + $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 1092 | + if ($post_evt instanceof EE_Event) { |
|
| 1093 | + // meta revision restore |
|
| 1094 | + $post_evt->restore_revision($revision_id); |
|
| 1095 | + // related objs restore |
|
| 1096 | + $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
| 1097 | + } |
|
| 1098 | + } |
|
| 1099 | + |
|
| 1100 | + |
|
| 1101 | + /** |
|
| 1102 | + * Attach the venue to the Event |
|
| 1103 | + * |
|
| 1104 | + * @param \EE_Event $evtobj Event Object to add the venue to |
|
| 1105 | + * @param array $data The request data from the form |
|
| 1106 | + * @return bool Success or fail. |
|
| 1107 | + */ |
|
| 1108 | + protected function _default_venue_update(\EE_Event $evtobj, $data) |
|
| 1109 | + { |
|
| 1110 | + require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1111 | + $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1112 | + $rows_affected = null; |
|
| 1113 | + $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1114 | + // very important. If we don't have a venue name... |
|
| 1115 | + // then we'll get out because not necessary to create empty venue |
|
| 1116 | + if (empty($data['venue_title'])) { |
|
| 1117 | + return false; |
|
| 1118 | + } |
|
| 1119 | + $venue_array = array( |
|
| 1120 | + 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
| 1121 | + 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
| 1122 | + 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1123 | + 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1124 | + 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
| 1125 | + : null, |
|
| 1126 | + 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1127 | + 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1128 | + 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1129 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1130 | + 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1131 | + 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1132 | + 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1133 | + 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1134 | + 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1135 | + 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1136 | + 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1137 | + 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1138 | + 'status' => 'publish', |
|
| 1139 | + ); |
|
| 1140 | + // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1141 | + if (! empty($venue_id)) { |
|
| 1142 | + $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
| 1143 | + $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
| 1144 | + // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
| 1145 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1146 | + return $rows_affected > 0 ? true : false; |
|
| 1147 | + } else { |
|
| 1148 | + // we insert the venue |
|
| 1149 | + $venue_id = $venue_model->insert($venue_array); |
|
| 1150 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1151 | + return ! empty($venue_id) ? true : false; |
|
| 1152 | + } |
|
| 1153 | + // when we have the ancestor come in it's already been handled by the revision save. |
|
| 1154 | + } |
|
| 1155 | + |
|
| 1156 | + |
|
| 1157 | + /** |
|
| 1158 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1159 | + * |
|
| 1160 | + * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 1161 | + * @param array $data The request data from the form |
|
| 1162 | + * @return array |
|
| 1163 | + */ |
|
| 1164 | + protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
| 1165 | + { |
|
| 1166 | + $success = true; |
|
| 1167 | + $saved_dtt = null; |
|
| 1168 | + $saved_tickets = array(); |
|
| 1169 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1170 | + foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 1171 | + // trim all values to ensure any excess whitespace is removed. |
|
| 1172 | + $dtt = array_map('trim', $dtt); |
|
| 1173 | + $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
| 1174 | + : $dtt['DTT_EVT_start']; |
|
| 1175 | + $datetime_values = array( |
|
| 1176 | + 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 1177 | + 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 1178 | + 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 1179 | + 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 1180 | + 'DTT_order' => $row, |
|
| 1181 | + ); |
|
| 1182 | + // if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
| 1183 | + if (! empty($dtt['DTT_ID'])) { |
|
| 1184 | + $DTM = EE_Registry::instance() |
|
| 1185 | + ->load_model('Datetime', array($evtobj->get_timezone())) |
|
| 1186 | + ->get_one_by_ID($dtt['DTT_ID']); |
|
| 1187 | + $DTM->set_date_format($incoming_date_formats[0]); |
|
| 1188 | + $DTM->set_time_format($incoming_date_formats[1]); |
|
| 1189 | + foreach ($datetime_values as $field => $value) { |
|
| 1190 | + $DTM->set($field, $value); |
|
| 1191 | + } |
|
| 1192 | + // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
|
| 1193 | + $saved_dtts[ $DTM->ID() ] = $DTM; |
|
| 1194 | + } else { |
|
| 1195 | + $DTM = EE_Registry::instance()->load_class( |
|
| 1196 | + 'Datetime', |
|
| 1197 | + array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats), |
|
| 1198 | + false, |
|
| 1199 | + false |
|
| 1200 | + ); |
|
| 1201 | + foreach ($datetime_values as $field => $value) { |
|
| 1202 | + $DTM->set($field, $value); |
|
| 1203 | + } |
|
| 1204 | + } |
|
| 1205 | + $DTM->save(); |
|
| 1206 | + $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
| 1207 | + // load DTT helper |
|
| 1208 | + // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1209 | + if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
| 1210 | + $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
| 1211 | + $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
| 1212 | + $DTT->save(); |
|
| 1213 | + } |
|
| 1214 | + // now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave. |
|
| 1215 | + $saved_dtt = $DTT; |
|
| 1216 | + $success = ! $success ? $success : $DTT; |
|
| 1217 | + // if ANY of these updates fail then we want the appropriate global error message. |
|
| 1218 | + // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
| 1219 | + } |
|
| 1220 | + // no dtts get deleted so we don't do any of that logic here. |
|
| 1221 | + // update tickets next |
|
| 1222 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 1223 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 1224 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1225 | + $update_prices = false; |
|
| 1226 | + $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
| 1227 | + ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0; |
|
| 1228 | + // trim inputs to ensure any excess whitespace is removed. |
|
| 1229 | + $tkt = array_map('trim', $tkt); |
|
| 1230 | + if (empty($tkt['TKT_start_date'])) { |
|
| 1231 | + // let's use now in the set timezone. |
|
| 1232 | + $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
| 1233 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1234 | + } |
|
| 1235 | + if (empty($tkt['TKT_end_date'])) { |
|
| 1236 | + // use the start date of the first datetime |
|
| 1237 | + $dtt = $evtobj->first_datetime(); |
|
| 1238 | + $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
| 1239 | + $incoming_date_formats[0], |
|
| 1240 | + $incoming_date_formats[1] |
|
| 1241 | + ); |
|
| 1242 | + } |
|
| 1243 | + $TKT_values = array( |
|
| 1244 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 1245 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 1246 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 1247 | + 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
| 1248 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 1249 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 1250 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 1251 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 1252 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 1253 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 1254 | + 'TKT_row' => $row, |
|
| 1255 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
| 1256 | + 'TKT_price' => $ticket_price, |
|
| 1257 | + ); |
|
| 1258 | + // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
| 1259 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 1260 | + $TKT_values['TKT_ID'] = 0; |
|
| 1261 | + $TKT_values['TKT_is_default'] = 0; |
|
| 1262 | + $TKT_values['TKT_price'] = $ticket_price; |
|
| 1263 | + $update_prices = true; |
|
| 1264 | + } |
|
| 1265 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1266 | + // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
| 1267 | + // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1268 | + if (! empty($tkt['TKT_ID'])) { |
|
| 1269 | + $TKT = EE_Registry::instance() |
|
| 1270 | + ->load_model('Ticket', array($evtobj->get_timezone())) |
|
| 1271 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
| 1272 | + if ($TKT instanceof EE_Ticket) { |
|
| 1273 | + $ticket_sold = $TKT->count_related( |
|
| 1274 | + 'Registration', |
|
| 1275 | + array( |
|
| 1276 | + array( |
|
| 1277 | + 'STS_ID' => array( |
|
| 1278 | + 'NOT IN', |
|
| 1279 | + array(EEM_Registration::status_id_incomplete), |
|
| 1280 | + ), |
|
| 1281 | + ), |
|
| 1282 | + ) |
|
| 1283 | + ) > 0 ? true : false; |
|
| 1284 | + // let's just check the total price for the existing ticket and determine if it matches the new total price. if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket. |
|
| 1285 | + $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') |
|
| 1286 | + && ! $TKT->get('TKT_deleted'); |
|
| 1287 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1288 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1289 | + // set new values |
|
| 1290 | + foreach ($TKT_values as $field => $value) { |
|
| 1291 | + if ($field == 'TKT_qty') { |
|
| 1292 | + $TKT->set_qty($value); |
|
| 1293 | + } else { |
|
| 1294 | + $TKT->set($field, $value); |
|
| 1295 | + } |
|
| 1296 | + } |
|
| 1297 | + // if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
| 1298 | + if ($create_new_TKT) { |
|
| 1299 | + // archive the old ticket first |
|
| 1300 | + $TKT->set('TKT_deleted', 1); |
|
| 1301 | + $TKT->save(); |
|
| 1302 | + // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
| 1303 | + $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1304 | + // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
|
| 1305 | + $TKT = clone $TKT; |
|
| 1306 | + $TKT->set('TKT_ID', 0); |
|
| 1307 | + $TKT->set('TKT_deleted', 0); |
|
| 1308 | + $TKT->set('TKT_price', $ticket_price); |
|
| 1309 | + $TKT->set('TKT_sold', 0); |
|
| 1310 | + // now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1311 | + $update_prices = true; |
|
| 1312 | + } |
|
| 1313 | + // make sure price is set if it hasn't been already |
|
| 1314 | + $TKT->set('TKT_price', $ticket_price); |
|
| 1315 | + } |
|
| 1316 | + } else { |
|
| 1317 | + // no TKT_id so a new TKT |
|
| 1318 | + $TKT_values['TKT_price'] = $ticket_price; |
|
| 1319 | + $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); |
|
| 1320 | + if ($TKT instanceof EE_Ticket) { |
|
| 1321 | + // need to reset values to properly account for the date formats |
|
| 1322 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1323 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1324 | + $TKT->set_timezone($evtobj->get_timezone()); |
|
| 1325 | + // set new values |
|
| 1326 | + foreach ($TKT_values as $field => $value) { |
|
| 1327 | + if ($field == 'TKT_qty') { |
|
| 1328 | + $TKT->set_qty($value); |
|
| 1329 | + } else { |
|
| 1330 | + $TKT->set($field, $value); |
|
| 1331 | + } |
|
| 1332 | + } |
|
| 1333 | + $update_prices = true; |
|
| 1334 | + } |
|
| 1335 | + } |
|
| 1336 | + // cap ticket qty by datetime reg limits |
|
| 1337 | + $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
| 1338 | + // update ticket. |
|
| 1339 | + $TKT->save(); |
|
| 1340 | + // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1341 | + if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 1342 | + $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 1343 | + $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 1344 | + $TKT->save(); |
|
| 1345 | + } |
|
| 1346 | + // initially let's add the ticket to the dtt |
|
| 1347 | + $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
| 1348 | + $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1349 | + // add prices to ticket |
|
| 1350 | + $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices); |
|
| 1351 | + } |
|
| 1352 | + // however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1353 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
| 1354 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1355 | + foreach ($tickets_removed as $id) { |
|
| 1356 | + $id = absint($id); |
|
| 1357 | + // get the ticket for this id |
|
| 1358 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 1359 | + if (! $tkt_to_remove instanceof EE_Ticket) { |
|
| 1360 | + continue; |
|
| 1361 | + } |
|
| 1362 | + |
|
| 1363 | + // need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 1364 | + $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 1365 | + foreach ($dtts as $dtt) { |
|
| 1366 | + $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 1367 | + } |
|
| 1368 | + // need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1369 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
| 1370 | + // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1371 | + $tkt_to_remove->delete_permanently(); |
|
| 1372 | + } |
|
| 1373 | + return array($saved_dtt, $saved_tickets); |
|
| 1374 | + } |
|
| 1375 | + |
|
| 1376 | + |
|
| 1377 | + /** |
|
| 1378 | + * This attaches a list of given prices to a ticket. |
|
| 1379 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 1380 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 1381 | + * price info and prices are automatically "archived" via the ticket. |
|
| 1382 | + * |
|
| 1383 | + * @access private |
|
| 1384 | + * @param array $prices Array of prices from the form. |
|
| 1385 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1386 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1387 | + * @return void |
|
| 1388 | + */ |
|
| 1389 | + private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
| 1390 | + { |
|
| 1391 | + foreach ($prices as $row => $prc) { |
|
| 1392 | + $PRC_values = array( |
|
| 1393 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 1394 | + 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
| 1395 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 1396 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 1397 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 1398 | + 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context |
|
| 1399 | + 'PRC_order' => $row, |
|
| 1400 | + ); |
|
| 1401 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 1402 | + $PRC_values['PRC_ID'] = 0; |
|
| 1403 | + $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
| 1404 | + } else { |
|
| 1405 | + $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 1406 | + // update this price with new values |
|
| 1407 | + foreach ($PRC_values as $field => $newprc) { |
|
| 1408 | + $PRC->set($field, $newprc); |
|
| 1409 | + } |
|
| 1410 | + $PRC->save(); |
|
| 1411 | + } |
|
| 1412 | + $ticket->_add_relation_to($PRC, 'Price'); |
|
| 1413 | + } |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + |
|
| 1417 | + /** |
|
| 1418 | + * Add in our autosave ajax handlers |
|
| 1419 | + * |
|
| 1420 | + */ |
|
| 1421 | + protected function _ee_autosave_create_new() |
|
| 1422 | + { |
|
| 1423 | + } |
|
| 1424 | + |
|
| 1425 | + |
|
| 1426 | + /** |
|
| 1427 | + * More autosave handlers. |
|
| 1428 | + */ |
|
| 1429 | + protected function _ee_autosave_edit() |
|
| 1430 | + { |
|
| 1431 | + return; // TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
| 1432 | + } |
|
| 1433 | + |
|
| 1434 | + |
|
| 1435 | + /** |
|
| 1436 | + * _generate_publish_box_extra_content |
|
| 1437 | + */ |
|
| 1438 | + private function _generate_publish_box_extra_content() |
|
| 1439 | + { |
|
| 1440 | + // load formatter helper |
|
| 1441 | + // args for getting related registrations |
|
| 1442 | + $approved_query_args = array( |
|
| 1443 | + array( |
|
| 1444 | + 'REG_deleted' => 0, |
|
| 1445 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1446 | + ), |
|
| 1447 | + ); |
|
| 1448 | + $not_approved_query_args = array( |
|
| 1449 | + array( |
|
| 1450 | + 'REG_deleted' => 0, |
|
| 1451 | + 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1452 | + ), |
|
| 1453 | + ); |
|
| 1454 | + $pending_payment_query_args = array( |
|
| 1455 | + array( |
|
| 1456 | + 'REG_deleted' => 0, |
|
| 1457 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1458 | + ), |
|
| 1459 | + ); |
|
| 1460 | + // publish box |
|
| 1461 | + $publish_box_extra_args = array( |
|
| 1462 | + 'view_approved_reg_url' => add_query_arg( |
|
| 1463 | + array( |
|
| 1464 | + 'action' => 'default', |
|
| 1465 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1466 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1467 | + ), |
|
| 1468 | + REG_ADMIN_URL |
|
| 1469 | + ), |
|
| 1470 | + 'view_not_approved_reg_url' => add_query_arg( |
|
| 1471 | + array( |
|
| 1472 | + 'action' => 'default', |
|
| 1473 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1474 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1475 | + ), |
|
| 1476 | + REG_ADMIN_URL |
|
| 1477 | + ), |
|
| 1478 | + 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1479 | + array( |
|
| 1480 | + 'action' => 'default', |
|
| 1481 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1482 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1483 | + ), |
|
| 1484 | + REG_ADMIN_URL |
|
| 1485 | + ), |
|
| 1486 | + 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1487 | + 'Registration', |
|
| 1488 | + $approved_query_args |
|
| 1489 | + ), |
|
| 1490 | + 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1491 | + 'Registration', |
|
| 1492 | + $not_approved_query_args |
|
| 1493 | + ), |
|
| 1494 | + 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1495 | + 'Registration', |
|
| 1496 | + $pending_payment_query_args |
|
| 1497 | + ), |
|
| 1498 | + 'misc_pub_section_class' => apply_filters( |
|
| 1499 | + 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1500 | + 'misc-pub-section' |
|
| 1501 | + ), |
|
| 1502 | + ); |
|
| 1503 | + ob_start(); |
|
| 1504 | + do_action( |
|
| 1505 | + 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1506 | + $this->_cpt_model_obj |
|
| 1507 | + ); |
|
| 1508 | + $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1509 | + // load template |
|
| 1510 | + EEH_Template::display_template( |
|
| 1511 | + EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1512 | + $publish_box_extra_args |
|
| 1513 | + ); |
|
| 1514 | + } |
|
| 1515 | + |
|
| 1516 | + |
|
| 1517 | + /** |
|
| 1518 | + * @return EE_Event |
|
| 1519 | + */ |
|
| 1520 | + public function get_event_object() |
|
| 1521 | + { |
|
| 1522 | + return $this->_cpt_model_obj; |
|
| 1523 | + } |
|
| 1524 | + |
|
| 1525 | + |
|
| 1526 | + |
|
| 1527 | + |
|
| 1528 | + /** METABOXES * */ |
|
| 1529 | + /** |
|
| 1530 | + * _register_event_editor_meta_boxes |
|
| 1531 | + * add all metaboxes related to the event_editor |
|
| 1532 | + * |
|
| 1533 | + * @return void |
|
| 1534 | + */ |
|
| 1535 | + protected function _register_event_editor_meta_boxes() |
|
| 1536 | + { |
|
| 1537 | + $this->verify_cpt_object(); |
|
| 1538 | + add_meta_box( |
|
| 1539 | + 'espresso_event_editor_tickets', |
|
| 1540 | + esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1541 | + array($this, 'ticket_metabox'), |
|
| 1542 | + $this->page_slug, |
|
| 1543 | + 'normal', |
|
| 1544 | + 'high' |
|
| 1545 | + ); |
|
| 1546 | + add_meta_box( |
|
| 1547 | + 'espresso_event_editor_event_options', |
|
| 1548 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1549 | + array($this, 'registration_options_meta_box'), |
|
| 1550 | + $this->page_slug, |
|
| 1551 | + 'side', |
|
| 1552 | + 'default' |
|
| 1553 | + ); |
|
| 1554 | + // NOTE: if you're looking for other metaboxes in here, |
|
| 1555 | + // where a metabox has a related management page in the admin |
|
| 1556 | + // you will find it setup in the related management page's "_Hooks" file. |
|
| 1557 | + // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1558 | + } |
|
| 1559 | + |
|
| 1560 | + |
|
| 1561 | + /** |
|
| 1562 | + * @throws DomainException |
|
| 1563 | + * @throws EE_Error |
|
| 1564 | + */ |
|
| 1565 | + public function ticket_metabox() |
|
| 1566 | + { |
|
| 1567 | + $existing_datetime_ids = $existing_ticket_ids = array(); |
|
| 1568 | + // defaults for template args |
|
| 1569 | + $template_args = array( |
|
| 1570 | + 'existing_datetime_ids' => '', |
|
| 1571 | + 'event_datetime_help_link' => '', |
|
| 1572 | + 'ticket_options_help_link' => '', |
|
| 1573 | + 'time' => null, |
|
| 1574 | + 'ticket_rows' => '', |
|
| 1575 | + 'existing_ticket_ids' => '', |
|
| 1576 | + 'total_ticket_rows' => 1, |
|
| 1577 | + 'ticket_js_structure' => '', |
|
| 1578 | + 'trash_icon' => 'ee-lock-icon', |
|
| 1579 | + 'disabled' => '', |
|
| 1580 | + ); |
|
| 1581 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1582 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1583 | + /** |
|
| 1584 | + * 1. Start with retrieving Datetimes |
|
| 1585 | + * 2. Fore each datetime get related tickets |
|
| 1586 | + * 3. For each ticket get related prices |
|
| 1587 | + */ |
|
| 1588 | + $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
| 1589 | + /** @type EE_Datetime $first_datetime */ |
|
| 1590 | + $first_datetime = reset($times); |
|
| 1591 | + // do we get related tickets? |
|
| 1592 | + if ( |
|
| 1593 | + $first_datetime instanceof EE_Datetime |
|
| 1594 | + && $first_datetime->ID() !== 0 |
|
| 1595 | + ) { |
|
| 1596 | + $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1597 | + $template_args['time'] = $first_datetime; |
|
| 1598 | + $related_tickets = $first_datetime->tickets( |
|
| 1599 | + array( |
|
| 1600 | + array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
| 1601 | + 'default_where_conditions' => 'none', |
|
| 1602 | + ) |
|
| 1603 | + ); |
|
| 1604 | + if (! empty($related_tickets)) { |
|
| 1605 | + $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1606 | + $row = 0; |
|
| 1607 | + foreach ($related_tickets as $ticket) { |
|
| 1608 | + $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1609 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1610 | + $row++; |
|
| 1611 | + } |
|
| 1612 | + } else { |
|
| 1613 | + $template_args['total_ticket_rows'] = 1; |
|
| 1614 | + /** @type EE_Ticket $ticket */ |
|
| 1615 | + $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
| 1616 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1617 | + } |
|
| 1618 | + } else { |
|
| 1619 | + $template_args['time'] = $times[0]; |
|
| 1620 | + /** @type EE_Ticket $ticket */ |
|
| 1621 | + $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
| 1622 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
| 1623 | + // NOTE: we're just sending the first default row |
|
| 1624 | + // (decaf can't manage default tickets so this should be sufficient); |
|
| 1625 | + } |
|
| 1626 | + $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1627 | + 'event_editor_event_datetimes_help_tab' |
|
| 1628 | + ); |
|
| 1629 | + $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1630 | + $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1631 | + $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1632 | + $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1633 | + EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
|
| 1634 | + true |
|
| 1635 | + ); |
|
| 1636 | + $template = apply_filters( |
|
| 1637 | + 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1638 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1639 | + ); |
|
| 1640 | + EEH_Template::display_template($template, $template_args); |
|
| 1641 | + } |
|
| 1642 | + |
|
| 1643 | + |
|
| 1644 | + /** |
|
| 1645 | + * Setup an individual ticket form for the decaf event editor page |
|
| 1646 | + * |
|
| 1647 | + * @access private |
|
| 1648 | + * @param EE_Ticket $ticket the ticket object |
|
| 1649 | + * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1650 | + * @param int $row |
|
| 1651 | + * @return string generated html for the ticket row. |
|
| 1652 | + */ |
|
| 1653 | + private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1654 | + { |
|
| 1655 | + $template_args = array( |
|
| 1656 | + 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1657 | + 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1658 | + : '', |
|
| 1659 | + 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1660 | + 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1661 | + 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1662 | + 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1663 | + 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1664 | + 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1665 | + 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1666 | + 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1667 | + 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1668 | + 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1669 | + && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1670 | + ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
| 1671 | + 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1672 | + : ' disabled=disabled', |
|
| 1673 | + ); |
|
| 1674 | + $price = $ticket->ID() !== 0 |
|
| 1675 | + ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) |
|
| 1676 | + : null; |
|
| 1677 | + $price = $price instanceof EE_Price |
|
| 1678 | + ? $price |
|
| 1679 | + : EEM_Price::instance()->create_default_object(); |
|
| 1680 | + $price_args = array( |
|
| 1681 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1682 | + 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1683 | + 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1684 | + 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1685 | + 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1686 | + ); |
|
| 1687 | + // make sure we have default start and end dates if skeleton |
|
| 1688 | + // handle rows that should NOT be empty |
|
| 1689 | + if (empty($template_args['TKT_start_date'])) { |
|
| 1690 | + // if empty then the start date will be now. |
|
| 1691 | + $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1692 | + } |
|
| 1693 | + if (empty($template_args['TKT_end_date'])) { |
|
| 1694 | + // get the earliest datetime (if present); |
|
| 1695 | + $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
| 1696 | + ? $this->_cpt_model_obj->get_first_related( |
|
| 1697 | + 'Datetime', |
|
| 1698 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1699 | + ) |
|
| 1700 | + : null; |
|
| 1701 | + if (! empty($earliest_dtt)) { |
|
| 1702 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
| 1703 | + } else { |
|
| 1704 | + $template_args['TKT_end_date'] = date( |
|
| 1705 | + 'Y-m-d h:i a', |
|
| 1706 | + mktime(0, 0, 0, date("m"), date("d") + 7, date("Y")) |
|
| 1707 | + ); |
|
| 1708 | + } |
|
| 1709 | + } |
|
| 1710 | + $template_args = array_merge($template_args, $price_args); |
|
| 1711 | + $template = apply_filters( |
|
| 1712 | + 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1713 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1714 | + $ticket |
|
| 1715 | + ); |
|
| 1716 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1717 | + } |
|
| 1718 | + |
|
| 1719 | + |
|
| 1720 | + /** |
|
| 1721 | + * @throws DomainException |
|
| 1722 | + */ |
|
| 1723 | + public function registration_options_meta_box() |
|
| 1724 | + { |
|
| 1725 | + $yes_no_values = array( |
|
| 1726 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 1727 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 1728 | + ); |
|
| 1729 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1730 | + array( |
|
| 1731 | + EEM_Registration::status_id_cancelled, |
|
| 1732 | + EEM_Registration::status_id_declined, |
|
| 1733 | + EEM_Registration::status_id_incomplete, |
|
| 1734 | + ), |
|
| 1735 | + true |
|
| 1736 | + ); |
|
| 1737 | + // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1738 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1739 | + $template_args['event'] = $this->_cpt_model_obj; |
|
| 1740 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1741 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1742 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1743 | + 'default_reg_status', |
|
| 1744 | + $default_reg_status_values, |
|
| 1745 | + $this->_cpt_model_obj->default_registration_status() |
|
| 1746 | + ); |
|
| 1747 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1748 | + 'display_desc', |
|
| 1749 | + $yes_no_values, |
|
| 1750 | + $this->_cpt_model_obj->display_description() |
|
| 1751 | + ); |
|
| 1752 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1753 | + 'display_ticket_selector', |
|
| 1754 | + $yes_no_values, |
|
| 1755 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1756 | + '', |
|
| 1757 | + '', |
|
| 1758 | + false |
|
| 1759 | + ); |
|
| 1760 | + $template_args['additional_registration_options'] = apply_filters( |
|
| 1761 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1762 | + '', |
|
| 1763 | + $template_args, |
|
| 1764 | + $yes_no_values, |
|
| 1765 | + $default_reg_status_values |
|
| 1766 | + ); |
|
| 1767 | + EEH_Template::display_template( |
|
| 1768 | + EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1769 | + $template_args |
|
| 1770 | + ); |
|
| 1771 | + } |
|
| 1772 | + |
|
| 1773 | + |
|
| 1774 | + /** |
|
| 1775 | + * _get_events() |
|
| 1776 | + * This method simply returns all the events (for the given _view and paging) |
|
| 1777 | + * |
|
| 1778 | + * @access public |
|
| 1779 | + * @param int $per_page count of items per page (20 default); |
|
| 1780 | + * @param int $current_page what is the current page being viewed. |
|
| 1781 | + * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1782 | + * If FALSE then we return an array of event objects |
|
| 1783 | + * that match the given _view and paging parameters. |
|
| 1784 | + * @return array an array of event objects. |
|
| 1785 | + */ |
|
| 1786 | + public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1787 | + { |
|
| 1788 | + $EEME = $this->_event_model(); |
|
| 1789 | + $offset = ($current_page - 1) * $per_page; |
|
| 1790 | + $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1791 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
| 1792 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
|
| 1793 | + if (isset($this->_req_data['month_range'])) { |
|
| 1794 | + $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
| 1795 | + // simulate the FIRST day of the month, that fixes issues for months like February |
|
| 1796 | + // where PHP doesn't know what to assume for date. |
|
| 1797 | + // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
| 1798 | + $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
| 1799 | + $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1800 | + } |
|
| 1801 | + $where = array(); |
|
| 1802 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1803 | + // determine what post_status our condition will have for the query. |
|
| 1804 | + switch ($status) { |
|
| 1805 | + case 'month': |
|
| 1806 | + case 'today': |
|
| 1807 | + case null: |
|
| 1808 | + case 'all': |
|
| 1809 | + break; |
|
| 1810 | + case 'draft': |
|
| 1811 | + $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
| 1812 | + break; |
|
| 1813 | + default: |
|
| 1814 | + $where['status'] = $status; |
|
| 1815 | + } |
|
| 1816 | + // categories? |
|
| 1817 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 1818 | + ? $this->_req_data['EVT_CAT'] : null; |
|
| 1819 | + if (! empty($category)) { |
|
| 1820 | + $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
|
| 1821 | + $where['Term_Taxonomy.term_id'] = $category; |
|
| 1822 | + } |
|
| 1823 | + // date where conditions |
|
| 1824 | + $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1825 | + if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
|
| 1826 | + $DateTime = new DateTime( |
|
| 1827 | + $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1828 | + new DateTimeZone('UTC') |
|
| 1829 | + ); |
|
| 1830 | + $start = $DateTime->getTimestamp(); |
|
| 1831 | + // set the datetime to be the end of the month |
|
| 1832 | + $DateTime->setDate( |
|
| 1833 | + $year_r, |
|
| 1834 | + $month_r, |
|
| 1835 | + $DateTime->format('t') |
|
| 1836 | + )->setTime(23, 59, 59); |
|
| 1837 | + $end = $DateTime->getTimestamp(); |
|
| 1838 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1839 | + } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { |
|
| 1840 | + $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1841 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1842 | + $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1843 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1844 | + } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { |
|
| 1845 | + $now = date('Y-m-01'); |
|
| 1846 | + $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1847 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1848 | + $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1849 | + ->setTime(23, 59, 59) |
|
| 1850 | + ->format(implode(' ', $start_formats)); |
|
| 1851 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1852 | + } |
|
| 1853 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1854 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1855 | + } else { |
|
| 1856 | + if (! isset($where['status'])) { |
|
| 1857 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1858 | + $where['OR'] = array( |
|
| 1859 | + 'status*restrict_private' => array('!=', 'private'), |
|
| 1860 | + 'AND' => array( |
|
| 1861 | + 'status*inclusive' => array('=', 'private'), |
|
| 1862 | + 'EVT_wp_user' => get_current_user_id(), |
|
| 1863 | + ), |
|
| 1864 | + ); |
|
| 1865 | + } |
|
| 1866 | + } |
|
| 1867 | + } |
|
| 1868 | + if (isset($this->_req_data['EVT_wp_user'])) { |
|
| 1869 | + if ( |
|
| 1870 | + $this->_req_data['EVT_wp_user'] != get_current_user_id() |
|
| 1871 | + && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 1872 | + ) { |
|
| 1873 | + $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
| 1874 | + } |
|
| 1875 | + } |
|
| 1876 | + // search query handling |
|
| 1877 | + if (isset($this->_req_data['s'])) { |
|
| 1878 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1879 | + $where['OR'] = array( |
|
| 1880 | + 'EVT_name' => array('LIKE', $search_string), |
|
| 1881 | + 'EVT_desc' => array('LIKE', $search_string), |
|
| 1882 | + 'EVT_short_desc' => array('LIKE', $search_string), |
|
| 1883 | + ); |
|
| 1884 | + } |
|
| 1885 | + // filter events by venue. |
|
| 1886 | + if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) { |
|
| 1887 | + $where['Venue.VNU_ID'] = absint($this->_req_data['venue']); |
|
| 1888 | + } |
|
| 1889 | + $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
| 1890 | + $query_params = apply_filters( |
|
| 1891 | + 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 1892 | + array( |
|
| 1893 | + $where, |
|
| 1894 | + 'limit' => $limit, |
|
| 1895 | + 'order_by' => $orderby, |
|
| 1896 | + 'order' => $order, |
|
| 1897 | + 'group_by' => 'EVT_ID', |
|
| 1898 | + ), |
|
| 1899 | + $this->_req_data |
|
| 1900 | + ); |
|
| 1901 | + |
|
| 1902 | + // let's first check if we have special requests coming in. |
|
| 1903 | + if (isset($this->_req_data['active_status'])) { |
|
| 1904 | + switch ($this->_req_data['active_status']) { |
|
| 1905 | + case 'upcoming': |
|
| 1906 | + return $EEME->get_upcoming_events($query_params, $count); |
|
| 1907 | + break; |
|
| 1908 | + case 'expired': |
|
| 1909 | + return $EEME->get_expired_events($query_params, $count); |
|
| 1910 | + break; |
|
| 1911 | + case 'active': |
|
| 1912 | + return $EEME->get_active_events($query_params, $count); |
|
| 1913 | + break; |
|
| 1914 | + case 'inactive': |
|
| 1915 | + return $EEME->get_inactive_events($query_params, $count); |
|
| 1916 | + break; |
|
| 1917 | + } |
|
| 1918 | + } |
|
| 1919 | + |
|
| 1920 | + $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
| 1921 | + return $events; |
|
| 1922 | + } |
|
| 1923 | + |
|
| 1924 | + |
|
| 1925 | + /** |
|
| 1926 | + * handling for WordPress CPT actions (trash, restore, delete) |
|
| 1927 | + * |
|
| 1928 | + * @param string $post_id |
|
| 1929 | + */ |
|
| 1930 | + public function trash_cpt_item($post_id) |
|
| 1931 | + { |
|
| 1932 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1933 | + $this->_trash_or_restore_event('trash', false); |
|
| 1934 | + } |
|
| 1935 | + |
|
| 1936 | + |
|
| 1937 | + /** |
|
| 1938 | + * @param string $post_id |
|
| 1939 | + */ |
|
| 1940 | + public function restore_cpt_item($post_id) |
|
| 1941 | + { |
|
| 1942 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1943 | + $this->_trash_or_restore_event('draft', false); |
|
| 1944 | + } |
|
| 1945 | + |
|
| 1946 | + |
|
| 1947 | + /** |
|
| 1948 | + * @param string $post_id |
|
| 1949 | + */ |
|
| 1950 | + public function delete_cpt_item($post_id) |
|
| 1951 | + { |
|
| 1952 | + throw new EE_Error(esc_html__('Please contact Event Espresso support with the details of the steps taken to produce this error.', 'event_espresso')); |
|
| 1953 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1954 | + $this->_delete_event(); |
|
| 1955 | + } |
|
| 1956 | + |
|
| 1957 | + |
|
| 1958 | + /** |
|
| 1959 | + * _trash_or_restore_event |
|
| 1960 | + * |
|
| 1961 | + * @access protected |
|
| 1962 | + * @param string $event_status |
|
| 1963 | + * @param bool $redirect_after |
|
| 1964 | + */ |
|
| 1965 | + protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 1966 | + { |
|
| 1967 | + // determine the event id and set to array. |
|
| 1968 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
| 1969 | + // loop thru events |
|
| 1970 | + if ($EVT_ID) { |
|
| 1971 | + // clean status |
|
| 1972 | + $event_status = sanitize_key($event_status); |
|
| 1973 | + // grab status |
|
| 1974 | + if (! empty($event_status)) { |
|
| 1975 | + $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1976 | + } else { |
|
| 1977 | + $success = false; |
|
| 1978 | + $msg = esc_html__( |
|
| 1979 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1980 | + 'event_espresso' |
|
| 1981 | + ); |
|
| 1982 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1983 | + } |
|
| 1984 | + } else { |
|
| 1985 | + $success = false; |
|
| 1986 | + $msg = esc_html__( |
|
| 1987 | + 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1988 | + 'event_espresso' |
|
| 1989 | + ); |
|
| 1990 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1991 | + } |
|
| 1992 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1993 | + if ($redirect_after) { |
|
| 1994 | + $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
|
| 1995 | + } |
|
| 1996 | + } |
|
| 1997 | + |
|
| 1998 | + |
|
| 1999 | + /** |
|
| 2000 | + * _trash_or_restore_events |
|
| 2001 | + * |
|
| 2002 | + * @access protected |
|
| 2003 | + * @param string $event_status |
|
| 2004 | + * @return void |
|
| 2005 | + */ |
|
| 2006 | + protected function _trash_or_restore_events($event_status = 'trash') |
|
| 2007 | + { |
|
| 2008 | + // clean status |
|
| 2009 | + $event_status = sanitize_key($event_status); |
|
| 2010 | + // grab status |
|
| 2011 | + if (! empty($event_status)) { |
|
| 2012 | + $success = true; |
|
| 2013 | + // determine the event id and set to array. |
|
| 2014 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
|
| 2015 | + // loop thru events |
|
| 2016 | + foreach ($EVT_IDs as $EVT_ID) { |
|
| 2017 | + if ($EVT_ID = absint($EVT_ID)) { |
|
| 2018 | + $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 2019 | + $success = $results !== false ? $success : false; |
|
| 2020 | + } else { |
|
| 2021 | + $msg = sprintf( |
|
| 2022 | + esc_html__( |
|
| 2023 | + 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2024 | + 'event_espresso' |
|
| 2025 | + ), |
|
| 2026 | + $EVT_ID |
|
| 2027 | + ); |
|
| 2028 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2029 | + $success = false; |
|
| 2030 | + } |
|
| 2031 | + } |
|
| 2032 | + } else { |
|
| 2033 | + $success = false; |
|
| 2034 | + $msg = esc_html__( |
|
| 2035 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2036 | + 'event_espresso' |
|
| 2037 | + ); |
|
| 2038 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2039 | + } |
|
| 2040 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2041 | + $success = $success ? 2 : false; |
|
| 2042 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2043 | + $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); |
|
| 2044 | + } |
|
| 2045 | + |
|
| 2046 | + |
|
| 2047 | + /** |
|
| 2048 | + * @param int $EVT_ID |
|
| 2049 | + * @param string $event_status |
|
| 2050 | + * @return bool |
|
| 2051 | + */ |
|
| 2052 | + private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 2053 | + { |
|
| 2054 | + // grab event id |
|
| 2055 | + if (! $EVT_ID) { |
|
| 2056 | + $msg = esc_html__( |
|
| 2057 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2058 | + 'event_espresso' |
|
| 2059 | + ); |
|
| 2060 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2061 | + return false; |
|
| 2062 | + } |
|
| 2063 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2064 | + // clean status |
|
| 2065 | + $event_status = sanitize_key($event_status); |
|
| 2066 | + // grab status |
|
| 2067 | + if (empty($event_status)) { |
|
| 2068 | + $msg = esc_html__( |
|
| 2069 | + 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2070 | + 'event_espresso' |
|
| 2071 | + ); |
|
| 2072 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2073 | + return false; |
|
| 2074 | + } |
|
| 2075 | + // was event trashed or restored ? |
|
| 2076 | + switch ($event_status) { |
|
| 2077 | + case 'draft': |
|
| 2078 | + $action = 'restored from the trash'; |
|
| 2079 | + $hook = 'AHEE_event_restored_from_trash'; |
|
| 2080 | + break; |
|
| 2081 | + case 'trash': |
|
| 2082 | + $action = 'moved to the trash'; |
|
| 2083 | + $hook = 'AHEE_event_moved_to_trash'; |
|
| 2084 | + break; |
|
| 2085 | + default: |
|
| 2086 | + $action = 'updated'; |
|
| 2087 | + $hook = false; |
|
| 2088 | + } |
|
| 2089 | + // use class to change status |
|
| 2090 | + $this->_cpt_model_obj->set_status($event_status); |
|
| 2091 | + $success = $this->_cpt_model_obj->save(); |
|
| 2092 | + if (! $success) { |
|
| 2093 | + $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2094 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2095 | + return false; |
|
| 2096 | + } |
|
| 2097 | + if ($hook) { |
|
| 2098 | + do_action($hook); |
|
| 2099 | + } |
|
| 2100 | + return true; |
|
| 2101 | + } |
|
| 2102 | + |
|
| 2103 | + |
|
| 2104 | + /** |
|
| 2105 | + * @param array $event_ids |
|
| 2106 | + * @return array |
|
| 2107 | + * @since $VID:$ |
|
| 2108 | + */ |
|
| 2109 | + private function cleanEventIds(array $event_ids) |
|
| 2110 | + { |
|
| 2111 | + return array_map('absint', $event_ids); |
|
| 2112 | + } |
|
| 2113 | + |
|
| 2114 | + |
|
| 2115 | + /** |
|
| 2116 | + * @return array |
|
| 2117 | + * @since $VID:$ |
|
| 2118 | + */ |
|
| 2119 | + private function getEventIdsFromRequest() |
|
| 2120 | + { |
|
| 2121 | + $event_ids = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : []; |
|
| 2122 | + $event_ids = is_string($event_ids) ? explode(',', $event_ids) : (array) $event_ids; |
|
| 2123 | + return $this->cleanEventIds($event_ids); |
|
| 2124 | + } |
|
| 2125 | + |
|
| 2126 | + |
|
| 2127 | + /** |
|
| 2128 | + * @param bool $preview_delete |
|
| 2129 | + * @throws EE_Error |
|
| 2130 | + */ |
|
| 2131 | + protected function _delete_event($preview_delete = true) |
|
| 2132 | + { |
|
| 2133 | + $this->_delete_events($preview_delete); |
|
| 2134 | + } |
|
| 2135 | + |
|
| 2136 | + |
|
| 2137 | + /** |
|
| 2138 | + * Gets the tree traversal batch persister. |
|
| 2139 | + * @since 4.10.12.p |
|
| 2140 | + * @return NodeGroupDao |
|
| 2141 | + * @throws InvalidArgumentException |
|
| 2142 | + * @throws InvalidDataTypeException |
|
| 2143 | + * @throws InvalidInterfaceException |
|
| 2144 | + */ |
|
| 2145 | + protected function getModelObjNodeGroupPersister() |
|
| 2146 | + { |
|
| 2147 | + if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
| 2148 | + $this->model_obj_node_group_persister = $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
|
| 2149 | + } |
|
| 2150 | + return $this->model_obj_node_group_persister; |
|
| 2151 | + } |
|
| 2152 | + |
|
| 2153 | + |
|
| 2154 | + /** |
|
| 2155 | + * @param bool $preview_delete |
|
| 2156 | + * @return void |
|
| 2157 | + * @throws EE_Error |
|
| 2158 | + */ |
|
| 2159 | + protected function _delete_events($preview_delete = true) |
|
| 2160 | + { |
|
| 2161 | + $event_ids = $this->getEventIdsFromRequest(); |
|
| 2162 | + if ($preview_delete) { |
|
| 2163 | + $this->generateDeletionPreview($event_ids); |
|
| 2164 | + } else { |
|
| 2165 | + EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]); |
|
| 2166 | + } |
|
| 2167 | + } |
|
| 2168 | + |
|
| 2169 | + |
|
| 2170 | + /** |
|
| 2171 | + * @param array $event_ids |
|
| 2172 | + */ |
|
| 2173 | + protected function generateDeletionPreview(array $event_ids) |
|
| 2174 | + { |
|
| 2175 | + $event_ids = $this->cleanEventIds($event_ids); |
|
| 2176 | + // Set a code we can use to reference this deletion task in the batch jobs and preview page. |
|
| 2177 | + $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode(); |
|
| 2178 | + $return_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2179 | + [ |
|
| 2180 | + 'action' => 'preview_deletion', |
|
| 2181 | + 'deletion_job_code' => $deletion_job_code, |
|
| 2182 | + ], |
|
| 2183 | + $this->_admin_base_url |
|
| 2184 | + ); |
|
| 2185 | + EEH_URL::safeRedirectAndExit( |
|
| 2186 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 2187 | + [ |
|
| 2188 | + 'page' => 'espresso_batch', |
|
| 2189 | + 'batch' => EED_Batch::batch_job, |
|
| 2190 | + 'EVT_IDs' => $event_ids, |
|
| 2191 | + 'deletion_job_code' => $deletion_job_code, |
|
| 2192 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'), |
|
| 2193 | + 'return_url' => urlencode($return_url), |
|
| 2194 | + ], |
|
| 2195 | + admin_url() |
|
| 2196 | + ) |
|
| 2197 | + ); |
|
| 2198 | + } |
|
| 2199 | + |
|
| 2200 | + /** |
|
| 2201 | + * Checks for a POST submission |
|
| 2202 | + * @since 4.10.12.p |
|
| 2203 | + */ |
|
| 2204 | + protected function confirmDeletion() |
|
| 2205 | + { |
|
| 2206 | + $deletion_redirect_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion'); |
|
| 2207 | + $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url()); |
|
| 2208 | + } |
|
| 2209 | + |
|
| 2210 | + /** |
|
| 2211 | + * A page for users to preview what exactly will be deleted, and confirm they want to delete it. |
|
| 2212 | + * @since 4.10.12.p |
|
| 2213 | + * @throws EE_Error |
|
| 2214 | + */ |
|
| 2215 | + protected function previewDeletion() |
|
| 2216 | + { |
|
| 2217 | + $preview_deletion_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion'); |
|
| 2218 | + $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url())); |
|
| 2219 | + $this->display_admin_page_with_no_sidebar(); |
|
| 2220 | + } |
|
| 2221 | + |
|
| 2222 | + /** |
|
| 2223 | + * get total number of events |
|
| 2224 | + * |
|
| 2225 | + * @access public |
|
| 2226 | + * @return int |
|
| 2227 | + */ |
|
| 2228 | + public function total_events() |
|
| 2229 | + { |
|
| 2230 | + $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2231 | + return $count; |
|
| 2232 | + } |
|
| 2233 | + |
|
| 2234 | + |
|
| 2235 | + /** |
|
| 2236 | + * get total number of draft events |
|
| 2237 | + * |
|
| 2238 | + * @access public |
|
| 2239 | + * @return int |
|
| 2240 | + */ |
|
| 2241 | + public function total_events_draft() |
|
| 2242 | + { |
|
| 2243 | + $where = array( |
|
| 2244 | + 'status' => array('IN', array('draft', 'auto-draft')), |
|
| 2245 | + ); |
|
| 2246 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2247 | + return $count; |
|
| 2248 | + } |
|
| 2249 | + |
|
| 2250 | + |
|
| 2251 | + /** |
|
| 2252 | + * get total number of trashed events |
|
| 2253 | + * |
|
| 2254 | + * @access public |
|
| 2255 | + * @return int |
|
| 2256 | + */ |
|
| 2257 | + public function total_trashed_events() |
|
| 2258 | + { |
|
| 2259 | + $where = array( |
|
| 2260 | + 'status' => 'trash', |
|
| 2261 | + ); |
|
| 2262 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2263 | + return $count; |
|
| 2264 | + } |
|
| 2265 | + |
|
| 2266 | + |
|
| 2267 | + /** |
|
| 2268 | + * _default_event_settings |
|
| 2269 | + * This generates the Default Settings Tab |
|
| 2270 | + * |
|
| 2271 | + * @return void |
|
| 2272 | + * @throws EE_Error |
|
| 2273 | + */ |
|
| 2274 | + protected function _default_event_settings() |
|
| 2275 | + { |
|
| 2276 | + $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2277 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2278 | + $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html(); |
|
| 2279 | + $this->display_admin_page_with_sidebar(); |
|
| 2280 | + } |
|
| 2281 | + |
|
| 2282 | + |
|
| 2283 | + /** |
|
| 2284 | + * Return the form for event settings. |
|
| 2285 | + * |
|
| 2286 | + * @return EE_Form_Section_Proper |
|
| 2287 | + * @throws EE_Error |
|
| 2288 | + */ |
|
| 2289 | + protected function _default_event_settings_form() |
|
| 2290 | + { |
|
| 2291 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2292 | + $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
| 2293 | + // exclude |
|
| 2294 | + array( |
|
| 2295 | + EEM_Registration::status_id_cancelled, |
|
| 2296 | + EEM_Registration::status_id_declined, |
|
| 2297 | + EEM_Registration::status_id_incomplete, |
|
| 2298 | + EEM_Registration::status_id_wait_list, |
|
| 2299 | + ), |
|
| 2300 | + true |
|
| 2301 | + ); |
|
| 2302 | + return new EE_Form_Section_Proper( |
|
| 2303 | + array( |
|
| 2304 | + 'name' => 'update_default_event_settings', |
|
| 2305 | + 'html_id' => 'update_default_event_settings', |
|
| 2306 | + 'html_class' => 'form-table', |
|
| 2307 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 2308 | + 'subsections' => apply_filters( |
|
| 2309 | + 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
| 2310 | + array( |
|
| 2311 | + 'default_reg_status' => new EE_Select_Input( |
|
| 2312 | + $registration_stati_for_selection, |
|
| 2313 | + array( |
|
| 2314 | + 'default' => isset($registration_config->default_STS_ID) |
|
| 2315 | + && array_key_exists( |
|
| 2316 | + $registration_config->default_STS_ID, |
|
| 2317 | + $registration_stati_for_selection |
|
| 2318 | + ) |
|
| 2319 | + ? sanitize_text_field($registration_config->default_STS_ID) |
|
| 2320 | + : EEM_Registration::status_id_pending_payment, |
|
| 2321 | + 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
| 2322 | + . EEH_Template::get_help_tab_link( |
|
| 2323 | + 'default_settings_status_help_tab' |
|
| 2324 | + ), |
|
| 2325 | + 'html_help_text' => esc_html__( |
|
| 2326 | + 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
| 2327 | + 'event_espresso' |
|
| 2328 | + ), |
|
| 2329 | + ) |
|
| 2330 | + ), |
|
| 2331 | + 'default_max_tickets' => new EE_Integer_Input( |
|
| 2332 | + array( |
|
| 2333 | + 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
| 2334 | + ? $registration_config->default_maximum_number_of_tickets |
|
| 2335 | + : EEM_Event::get_default_additional_limit(), |
|
| 2336 | + 'html_label_text' => esc_html__( |
|
| 2337 | + 'Default Maximum Tickets Allowed Per Order:', |
|
| 2338 | + 'event_espresso' |
|
| 2339 | + ) |
|
| 2340 | + . EEH_Template::get_help_tab_link( |
|
| 2341 | + 'default_maximum_tickets_help_tab"' |
|
| 2342 | + ), |
|
| 2343 | + 'html_help_text' => esc_html__( |
|
| 2344 | + 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
| 2345 | + 'event_espresso' |
|
| 2346 | + ), |
|
| 2347 | + ) |
|
| 2348 | + ), |
|
| 2349 | + ) |
|
| 2350 | + ), |
|
| 2351 | + ) |
|
| 2352 | + ); |
|
| 2353 | + } |
|
| 2354 | + |
|
| 2355 | + |
|
| 2356 | + /** |
|
| 2357 | + * _update_default_event_settings |
|
| 2358 | + * |
|
| 2359 | + * @access protected |
|
| 2360 | + * @return void |
|
| 2361 | + * @throws EE_Error |
|
| 2362 | + */ |
|
| 2363 | + protected function _update_default_event_settings() |
|
| 2364 | + { |
|
| 2365 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2366 | + $form = $this->_default_event_settings_form(); |
|
| 2367 | + if ($form->was_submitted()) { |
|
| 2368 | + $form->receive_form_submission(); |
|
| 2369 | + if ($form->is_valid()) { |
|
| 2370 | + $valid_data = $form->valid_data(); |
|
| 2371 | + if (isset($valid_data['default_reg_status'])) { |
|
| 2372 | + $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
| 2373 | + } |
|
| 2374 | + if (isset($valid_data['default_max_tickets'])) { |
|
| 2375 | + $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
| 2376 | + } |
|
| 2377 | + // update because data was valid! |
|
| 2378 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 2379 | + EE_Error::overwrite_success(); |
|
| 2380 | + EE_Error::add_success( |
|
| 2381 | + esc_html__('Default Event Settings were updated', 'event_espresso') |
|
| 2382 | + ); |
|
| 2383 | + } |
|
| 2384 | + } |
|
| 2385 | + $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true); |
|
| 2386 | + } |
|
| 2387 | + |
|
| 2388 | + |
|
| 2389 | + /************* Templates *************/ |
|
| 2390 | + protected function _template_settings() |
|
| 2391 | + { |
|
| 2392 | + $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2393 | + $this->_template_args['preview_img'] = '<img src="' |
|
| 2394 | + . EVENTS_ASSETS_URL |
|
| 2395 | + . '/images/' |
|
| 2396 | + . 'caffeinated_template_features.jpg" alt="' |
|
| 2397 | + . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2398 | + . '" />'; |
|
| 2399 | + $this->_template_args['preview_text'] = '<strong>' |
|
| 2400 | + . esc_html__( |
|
| 2401 | + 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
| 2402 | + 'event_espresso' |
|
| 2403 | + ) . '</strong>'; |
|
| 2404 | + $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2405 | + } |
|
| 2406 | + |
|
| 2407 | + |
|
| 2408 | + /** Event Category Stuff **/ |
|
| 2409 | + /** |
|
| 2410 | + * set the _category property with the category object for the loaded page. |
|
| 2411 | + * |
|
| 2412 | + * @access private |
|
| 2413 | + * @return void |
|
| 2414 | + */ |
|
| 2415 | + private function _set_category_object() |
|
| 2416 | + { |
|
| 2417 | + if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2418 | + return; |
|
| 2419 | + } //already have the category object so get out. |
|
| 2420 | + // set default category object |
|
| 2421 | + $this->_set_empty_category_object(); |
|
| 2422 | + // only set if we've got an id |
|
| 2423 | + if (! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2424 | + return; |
|
| 2425 | + } |
|
| 2426 | + $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
| 2427 | + $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2428 | + if (! empty($term)) { |
|
| 2429 | + $this->_category->category_name = $term->name; |
|
| 2430 | + $this->_category->category_identifier = $term->slug; |
|
| 2431 | + $this->_category->category_desc = $term->description; |
|
| 2432 | + $this->_category->id = $term->term_id; |
|
| 2433 | + $this->_category->parent = $term->parent; |
|
| 2434 | + } |
|
| 2435 | + } |
|
| 2436 | + |
|
| 2437 | + |
|
| 2438 | + /** |
|
| 2439 | + * Clears out category properties. |
|
| 2440 | + */ |
|
| 2441 | + private function _set_empty_category_object() |
|
| 2442 | + { |
|
| 2443 | + $this->_category = new stdClass(); |
|
| 2444 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2445 | + $this->_category->id = $this->_category->parent = 0; |
|
| 2446 | + } |
|
| 2447 | + |
|
| 2448 | + |
|
| 2449 | + /** |
|
| 2450 | + * @throws EE_Error |
|
| 2451 | + */ |
|
| 2452 | + protected function _category_list_table() |
|
| 2453 | + { |
|
| 2454 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2455 | + $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2456 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2457 | + 'add_category', |
|
| 2458 | + 'add_category', |
|
| 2459 | + array(), |
|
| 2460 | + 'add-new-h2' |
|
| 2461 | + ); |
|
| 2462 | + $this->display_admin_list_table_page_with_sidebar(); |
|
| 2463 | + } |
|
| 2464 | + |
|
| 2465 | + |
|
| 2466 | + /** |
|
| 2467 | + * Output category details view. |
|
| 2468 | + */ |
|
| 2469 | + protected function _category_details($view) |
|
| 2470 | + { |
|
| 2471 | + // load formatter helper |
|
| 2472 | + // load field generator helper |
|
| 2473 | + $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
| 2474 | + $this->_set_add_edit_form_tags($route); |
|
| 2475 | + $this->_set_category_object(); |
|
| 2476 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2477 | + $delete_action = 'delete_category'; |
|
| 2478 | + // custom redirect |
|
| 2479 | + $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2480 | + array('action' => 'category_list'), |
|
| 2481 | + $this->_admin_base_url |
|
| 2482 | + ); |
|
| 2483 | + $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2484 | + // take care of contents |
|
| 2485 | + $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2486 | + $this->display_admin_page_with_sidebar(); |
|
| 2487 | + } |
|
| 2488 | + |
|
| 2489 | + |
|
| 2490 | + /** |
|
| 2491 | + * Output category details content. |
|
| 2492 | + */ |
|
| 2493 | + protected function _category_details_content() |
|
| 2494 | + { |
|
| 2495 | + $editor_args['category_desc'] = array( |
|
| 2496 | + 'type' => 'wp_editor', |
|
| 2497 | + 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2498 | + 'class' => 'my_editor_custom', |
|
| 2499 | + 'wpeditor_args' => array('media_buttons' => false), |
|
| 2500 | + ); |
|
| 2501 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2502 | + $all_terms = get_terms( |
|
| 2503 | + array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY), |
|
| 2504 | + array('hide_empty' => 0, 'exclude' => array($this->_category->id)) |
|
| 2505 | + ); |
|
| 2506 | + // setup category select for term parents. |
|
| 2507 | + $category_select_values[] = array( |
|
| 2508 | + 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2509 | + 'id' => 0, |
|
| 2510 | + ); |
|
| 2511 | + foreach ($all_terms as $term) { |
|
| 2512 | + $category_select_values[] = array( |
|
| 2513 | + 'text' => $term->name, |
|
| 2514 | + 'id' => $term->term_id, |
|
| 2515 | + ); |
|
| 2516 | + } |
|
| 2517 | + $category_select = EEH_Form_Fields::select_input( |
|
| 2518 | + 'category_parent', |
|
| 2519 | + $category_select_values, |
|
| 2520 | + $this->_category->parent |
|
| 2521 | + ); |
|
| 2522 | + $template_args = array( |
|
| 2523 | + 'category' => $this->_category, |
|
| 2524 | + 'category_select' => $category_select, |
|
| 2525 | + 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2526 | + 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2527 | + 'disable' => '', |
|
| 2528 | + 'disabled_message' => false, |
|
| 2529 | + ); |
|
| 2530 | + $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2531 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 2532 | + } |
|
| 2533 | + |
|
| 2534 | + |
|
| 2535 | + /** |
|
| 2536 | + * Handles deleting categories. |
|
| 2537 | + */ |
|
| 2538 | + protected function _delete_categories() |
|
| 2539 | + { |
|
| 2540 | + $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID'] |
|
| 2541 | + : (array) $this->_req_data['category_id']; |
|
| 2542 | + foreach ($cat_ids as $cat_id) { |
|
| 2543 | + $this->_delete_category($cat_id); |
|
| 2544 | + } |
|
| 2545 | + // doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2546 | + $query_args = array( |
|
| 2547 | + 'action' => 'category_list', |
|
| 2548 | + ); |
|
| 2549 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2550 | + } |
|
| 2551 | + |
|
| 2552 | + |
|
| 2553 | + /** |
|
| 2554 | + * Handles deleting specific category. |
|
| 2555 | + * |
|
| 2556 | + * @param int $cat_id |
|
| 2557 | + */ |
|
| 2558 | + protected function _delete_category($cat_id) |
|
| 2559 | + { |
|
| 2560 | + $cat_id = absint($cat_id); |
|
| 2561 | + wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2562 | + } |
|
| 2563 | + |
|
| 2564 | + |
|
| 2565 | + /** |
|
| 2566 | + * Handles triggering the update or insertion of a new category. |
|
| 2567 | + * |
|
| 2568 | + * @param bool $new_category true means we're triggering the insert of a new category. |
|
| 2569 | + */ |
|
| 2570 | + protected function _insert_or_update_category($new_category) |
|
| 2571 | + { |
|
| 2572 | + $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2573 | + $success = 0; // we already have a success message so lets not send another. |
|
| 2574 | + if ($cat_id) { |
|
| 2575 | + $query_args = array( |
|
| 2576 | + 'action' => 'edit_category', |
|
| 2577 | + 'EVT_CAT_ID' => $cat_id, |
|
| 2578 | + ); |
|
| 2579 | + } else { |
|
| 2580 | + $query_args = array('action' => 'add_category'); |
|
| 2581 | + } |
|
| 2582 | + $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2583 | + } |
|
| 2584 | + |
|
| 2585 | + |
|
| 2586 | + /** |
|
| 2587 | + * Inserts or updates category |
|
| 2588 | + * |
|
| 2589 | + * @param bool $update (true indicates we're updating a category). |
|
| 2590 | + * @return bool|mixed|string |
|
| 2591 | + */ |
|
| 2592 | + private function _insert_category($update = false) |
|
| 2593 | + { |
|
| 2594 | + $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
| 2595 | + $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
| 2596 | + $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
| 2597 | + $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
| 2598 | + if (empty($category_name)) { |
|
| 2599 | + $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2600 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2601 | + return false; |
|
| 2602 | + } |
|
| 2603 | + $term_args = array( |
|
| 2604 | + 'name' => $category_name, |
|
| 2605 | + 'description' => $category_desc, |
|
| 2606 | + 'parent' => $category_parent, |
|
| 2607 | + ); |
|
| 2608 | + // was the category_identifier input disabled? |
|
| 2609 | + if (isset($this->_req_data['category_identifier'])) { |
|
| 2610 | + $term_args['slug'] = $this->_req_data['category_identifier']; |
|
| 2611 | + } |
|
| 2612 | + $insert_ids = $update |
|
| 2613 | + ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
|
| 2614 | + : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
|
| 2615 | + if (! is_array($insert_ids)) { |
|
| 2616 | + $msg = esc_html__( |
|
| 2617 | + 'An error occurred and the category has not been saved to the database.', |
|
| 2618 | + 'event_espresso' |
|
| 2619 | + ); |
|
| 2620 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2621 | + } else { |
|
| 2622 | + $cat_id = $insert_ids['term_id']; |
|
| 2623 | + $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
| 2624 | + EE_Error::add_success($msg); |
|
| 2625 | + } |
|
| 2626 | + return $cat_id; |
|
| 2627 | + } |
|
| 2628 | + |
|
| 2629 | + |
|
| 2630 | + /** |
|
| 2631 | + * Gets categories or count of categories matching the arguments in the request. |
|
| 2632 | + * |
|
| 2633 | + * @param int $per_page |
|
| 2634 | + * @param int $current_page |
|
| 2635 | + * @param bool $count |
|
| 2636 | + * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int |
|
| 2637 | + */ |
|
| 2638 | + public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2639 | + { |
|
| 2640 | + // testing term stuff |
|
| 2641 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
| 2642 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2643 | + $limit = ($current_page - 1) * $per_page; |
|
| 2644 | + $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2645 | + if (isset($this->_req_data['s'])) { |
|
| 2646 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2647 | + $where['OR'] = array( |
|
| 2648 | + 'Term.name' => array('LIKE', $sstr), |
|
| 2649 | + 'description' => array('LIKE', $sstr), |
|
| 2650 | + ); |
|
| 2651 | + } |
|
| 2652 | + $query_params = array( |
|
| 2653 | + $where, |
|
| 2654 | + 'order_by' => array($orderby => $order), |
|
| 2655 | + 'limit' => $limit . ',' . $per_page, |
|
| 2656 | + 'force_join' => array('Term'), |
|
| 2657 | + ); |
|
| 2658 | + $categories = $count |
|
| 2659 | + ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2660 | + : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2661 | + return $categories; |
|
| 2662 | + } |
|
| 2663 | + |
|
| 2664 | + /* end category stuff */ |
|
| 2665 | + /**************/ |
|
| 2666 | + |
|
| 2667 | + |
|
| 2668 | + /** |
|
| 2669 | + * Callback for the `ee_save_timezone_setting` ajax action. |
|
| 2670 | + * |
|
| 2671 | + * @throws EE_Error |
|
| 2672 | + */ |
|
| 2673 | + public function save_timezonestring_setting() |
|
| 2674 | + { |
|
| 2675 | + $timezone_string = isset($this->_req_data['timezone_selected']) |
|
| 2676 | + ? $this->_req_data['timezone_selected'] |
|
| 2677 | + : ''; |
|
| 2678 | + if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { |
|
| 2679 | + EE_Error::add_error( |
|
| 2680 | + esc_html__('An invalid timezone string submitted.', 'event_espresso'), |
|
| 2681 | + __FILE__, |
|
| 2682 | + __FUNCTION__, |
|
| 2683 | + __LINE__ |
|
| 2684 | + ); |
|
| 2685 | + $this->_template_args['error'] = true; |
|
| 2686 | + $this->_return_json(); |
|
| 2687 | + } |
|
| 2688 | + |
|
| 2689 | + update_option('timezone_string', $timezone_string); |
|
| 2690 | + EE_Error::add_success( |
|
| 2691 | + esc_html__('Your timezone string was updated.', 'event_espresso') |
|
| 2692 | + ); |
|
| 2693 | + $this->_template_args['success'] = true; |
|
| 2694 | + $this->_return_json(true, array('action' => 'create_new')); |
|
| 2695 | + } |
|
| 2696 | 2696 | } |
@@ -583,11 +583,11 @@ discard block |
||
| 583 | 583 | { |
| 584 | 584 | wp_register_style( |
| 585 | 585 | 'events-admin-css', |
| 586 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 586 | + EVENTS_ASSETS_URL.'events-admin-page.css', |
|
| 587 | 587 | array(), |
| 588 | 588 | EVENT_ESPRESSO_VERSION |
| 589 | 589 | ); |
| 590 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 590 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 591 | 591 | wp_enqueue_style('events-admin-css'); |
| 592 | 592 | wp_enqueue_style('ee-cat-admin'); |
| 593 | 593 | // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | // scripts |
| 596 | 596 | wp_register_script( |
| 597 | 597 | 'event_editor_js', |
| 598 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 598 | + EVENTS_ASSETS_URL.'event_editor.js', |
|
| 599 | 599 | array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
| 600 | 600 | EVENT_ESPRESSO_VERSION, |
| 601 | 601 | true |
@@ -621,7 +621,7 @@ discard block |
||
| 621 | 621 | wp_enqueue_style('espresso-ui-theme'); |
| 622 | 622 | wp_register_style( |
| 623 | 623 | 'event-editor-css', |
| 624 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 624 | + EVENTS_ASSETS_URL.'event-editor.css', |
|
| 625 | 625 | array('ee-admin-css'), |
| 626 | 626 | EVENT_ESPRESSO_VERSION |
| 627 | 627 | ); |
@@ -629,7 +629,7 @@ discard block |
||
| 629 | 629 | // scripts |
| 630 | 630 | wp_register_script( |
| 631 | 631 | 'event-datetime-metabox', |
| 632 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 632 | + EVENTS_ASSETS_URL.'event-datetime-metabox.js', |
|
| 633 | 633 | array('event_editor_js', 'ee-datepicker'), |
| 634 | 634 | EVENT_ESPRESSO_VERSION |
| 635 | 635 | ); |
@@ -698,7 +698,7 @@ discard block |
||
| 698 | 698 | public function verify_event_edit($event = null, $req_type = '') |
| 699 | 699 | { |
| 700 | 700 | // don't need to do this when processing |
| 701 | - if (! empty($req_type)) { |
|
| 701 | + if ( ! empty($req_type)) { |
|
| 702 | 702 | return; |
| 703 | 703 | } |
| 704 | 704 | // no event? |
@@ -707,7 +707,7 @@ discard block |
||
| 707 | 707 | $event = $this->_cpt_model_obj; |
| 708 | 708 | } |
| 709 | 709 | // STILL no event? |
| 710 | - if (! $event instanceof EE_Event) { |
|
| 710 | + if ( ! $event instanceof EE_Event) { |
|
| 711 | 711 | return; |
| 712 | 712 | } |
| 713 | 713 | $orig_status = $event->status(); |
@@ -746,7 +746,7 @@ discard block |
||
| 746 | 746 | ); |
| 747 | 747 | } |
| 748 | 748 | // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
| 749 | - if (! $event->tickets_on_sale()) { |
|
| 749 | + if ( ! $event->tickets_on_sale()) { |
|
| 750 | 750 | return; |
| 751 | 751 | } |
| 752 | 752 | // made it here so show warning |
@@ -791,7 +791,7 @@ discard block |
||
| 791 | 791 | { |
| 792 | 792 | $has_timezone_string = get_option('timezone_string'); |
| 793 | 793 | // only nag them about setting their timezone if it's their first event, and they haven't already done it |
| 794 | - if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) { |
|
| 794 | + if ( ! $has_timezone_string && ! EEM_Event::instance()->exists(array())) { |
|
| 795 | 795 | EE_Error::add_attention( |
| 796 | 796 | sprintf( |
| 797 | 797 | esc_html__( |
@@ -875,31 +875,31 @@ discard block |
||
| 875 | 875 | $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
| 876 | 876 | $statuses = array( |
| 877 | 877 | 'sold_out_status' => array( |
| 878 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 878 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out, |
|
| 879 | 879 | 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
| 880 | 880 | ), |
| 881 | 881 | 'active_status' => array( |
| 882 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 882 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active, |
|
| 883 | 883 | 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
| 884 | 884 | ), |
| 885 | 885 | 'upcoming_status' => array( |
| 886 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 886 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming, |
|
| 887 | 887 | 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
| 888 | 888 | ), |
| 889 | 889 | 'postponed_status' => array( |
| 890 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 890 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed, |
|
| 891 | 891 | 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
| 892 | 892 | ), |
| 893 | 893 | 'cancelled_status' => array( |
| 894 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 894 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled, |
|
| 895 | 895 | 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
| 896 | 896 | ), |
| 897 | 897 | 'expired_status' => array( |
| 898 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 898 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired, |
|
| 899 | 899 | 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
| 900 | 900 | ), |
| 901 | 901 | 'inactive_status' => array( |
| 902 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 902 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive, |
|
| 903 | 903 | 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
| 904 | 904 | ), |
| 905 | 905 | ); |
@@ -913,7 +913,7 @@ discard block |
||
| 913 | 913 | */ |
| 914 | 914 | private function _event_model() |
| 915 | 915 | { |
| 916 | - if (! $this->_event_model instanceof EEM_Event) { |
|
| 916 | + if ( ! $this->_event_model instanceof EEM_Event) { |
|
| 917 | 917 | $this->_event_model = EE_Registry::instance()->load_model('Event'); |
| 918 | 918 | } |
| 919 | 919 | return $this->_event_model; |
@@ -933,7 +933,7 @@ discard block |
||
| 933 | 933 | public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
| 934 | 934 | { |
| 935 | 935 | // make sure this is only when editing |
| 936 | - if (! empty($id)) { |
|
| 936 | + if ( ! empty($id)) { |
|
| 937 | 937 | $post = get_post($id); |
| 938 | 938 | $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
| 939 | 939 | . esc_html__('Shortcode', 'event_espresso') |
@@ -967,7 +967,7 @@ discard block |
||
| 967 | 967 | 'button' |
| 968 | 968 | ); |
| 969 | 969 | $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
| 970 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 970 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 971 | 971 | 'create_new', |
| 972 | 972 | 'add', |
| 973 | 973 | array(), |
@@ -1107,7 +1107,7 @@ discard block |
||
| 1107 | 1107 | */ |
| 1108 | 1108 | protected function _default_venue_update(\EE_Event $evtobj, $data) |
| 1109 | 1109 | { |
| 1110 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1110 | + require_once(EE_MODELS.'EEM_Venue.model.php'); |
|
| 1111 | 1111 | $venue_model = EE_Registry::instance()->load_model('Venue'); |
| 1112 | 1112 | $rows_affected = null; |
| 1113 | 1113 | $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
@@ -1138,7 +1138,7 @@ discard block |
||
| 1138 | 1138 | 'status' => 'publish', |
| 1139 | 1139 | ); |
| 1140 | 1140 | // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
| 1141 | - if (! empty($venue_id)) { |
|
| 1141 | + if ( ! empty($venue_id)) { |
|
| 1142 | 1142 | $update_where = array($venue_model->primary_key_name() => $venue_id); |
| 1143 | 1143 | $rows_affected = $venue_model->update($venue_array, array($update_where)); |
| 1144 | 1144 | // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
@@ -1180,7 +1180,7 @@ discard block |
||
| 1180 | 1180 | 'DTT_order' => $row, |
| 1181 | 1181 | ); |
| 1182 | 1182 | // if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
| 1183 | - if (! empty($dtt['DTT_ID'])) { |
|
| 1183 | + if ( ! empty($dtt['DTT_ID'])) { |
|
| 1184 | 1184 | $DTM = EE_Registry::instance() |
| 1185 | 1185 | ->load_model('Datetime', array($evtobj->get_timezone())) |
| 1186 | 1186 | ->get_one_by_ID($dtt['DTT_ID']); |
@@ -1190,7 +1190,7 @@ discard block |
||
| 1190 | 1190 | $DTM->set($field, $value); |
| 1191 | 1191 | } |
| 1192 | 1192 | // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
| 1193 | - $saved_dtts[ $DTM->ID() ] = $DTM; |
|
| 1193 | + $saved_dtts[$DTM->ID()] = $DTM; |
|
| 1194 | 1194 | } else { |
| 1195 | 1195 | $DTM = EE_Registry::instance()->load_class( |
| 1196 | 1196 | 'Datetime', |
@@ -1223,14 +1223,14 @@ discard block |
||
| 1223 | 1223 | foreach ($data['edit_tickets'] as $row => $tkt) { |
| 1224 | 1224 | $incoming_date_formats = array('Y-m-d', 'h:i a'); |
| 1225 | 1225 | $update_prices = false; |
| 1226 | - $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
| 1227 | - ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0; |
|
| 1226 | + $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
| 1227 | + ? $data['edit_prices'][$row][1]['PRC_amount'] : 0; |
|
| 1228 | 1228 | // trim inputs to ensure any excess whitespace is removed. |
| 1229 | 1229 | $tkt = array_map('trim', $tkt); |
| 1230 | 1230 | if (empty($tkt['TKT_start_date'])) { |
| 1231 | 1231 | // let's use now in the set timezone. |
| 1232 | 1232 | $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
| 1233 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1233 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]); |
|
| 1234 | 1234 | } |
| 1235 | 1235 | if (empty($tkt['TKT_end_date'])) { |
| 1236 | 1236 | // use the start date of the first datetime |
@@ -1265,7 +1265,7 @@ discard block |
||
| 1265 | 1265 | // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
| 1266 | 1266 | // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
| 1267 | 1267 | // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
| 1268 | - if (! empty($tkt['TKT_ID'])) { |
|
| 1268 | + if ( ! empty($tkt['TKT_ID'])) { |
|
| 1269 | 1269 | $TKT = EE_Registry::instance() |
| 1270 | 1270 | ->load_model('Ticket', array($evtobj->get_timezone())) |
| 1271 | 1271 | ->get_one_by_ID($tkt['TKT_ID']); |
@@ -1300,7 +1300,7 @@ discard block |
||
| 1300 | 1300 | $TKT->set('TKT_deleted', 1); |
| 1301 | 1301 | $TKT->save(); |
| 1302 | 1302 | // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
| 1303 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1303 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1304 | 1304 | // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
| 1305 | 1305 | $TKT = clone $TKT; |
| 1306 | 1306 | $TKT->set('TKT_ID', 0); |
@@ -1345,9 +1345,9 @@ discard block |
||
| 1345 | 1345 | } |
| 1346 | 1346 | // initially let's add the ticket to the dtt |
| 1347 | 1347 | $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
| 1348 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1348 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1349 | 1349 | // add prices to ticket |
| 1350 | - $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices); |
|
| 1350 | + $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices); |
|
| 1351 | 1351 | } |
| 1352 | 1352 | // however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
| 1353 | 1353 | $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
@@ -1356,7 +1356,7 @@ discard block |
||
| 1356 | 1356 | $id = absint($id); |
| 1357 | 1357 | // get the ticket for this id |
| 1358 | 1358 | $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
| 1359 | - if (! $tkt_to_remove instanceof EE_Ticket) { |
|
| 1359 | + if ( ! $tkt_to_remove instanceof EE_Ticket) { |
|
| 1360 | 1360 | continue; |
| 1361 | 1361 | } |
| 1362 | 1362 | |
@@ -1508,7 +1508,7 @@ discard block |
||
| 1508 | 1508 | $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
| 1509 | 1509 | // load template |
| 1510 | 1510 | EEH_Template::display_template( |
| 1511 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1511 | + EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php', |
|
| 1512 | 1512 | $publish_box_extra_args |
| 1513 | 1513 | ); |
| 1514 | 1514 | } |
@@ -1601,7 +1601,7 @@ discard block |
||
| 1601 | 1601 | 'default_where_conditions' => 'none', |
| 1602 | 1602 | ) |
| 1603 | 1603 | ); |
| 1604 | - if (! empty($related_tickets)) { |
|
| 1604 | + if ( ! empty($related_tickets)) { |
|
| 1605 | 1605 | $template_args['total_ticket_rows'] = count($related_tickets); |
| 1606 | 1606 | $row = 0; |
| 1607 | 1607 | foreach ($related_tickets as $ticket) { |
@@ -1635,7 +1635,7 @@ discard block |
||
| 1635 | 1635 | ); |
| 1636 | 1636 | $template = apply_filters( |
| 1637 | 1637 | 'FHEE__Events_Admin_Page__ticket_metabox__template', |
| 1638 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1638 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php' |
|
| 1639 | 1639 | ); |
| 1640 | 1640 | EEH_Template::display_template($template, $template_args); |
| 1641 | 1641 | } |
@@ -1653,7 +1653,7 @@ discard block |
||
| 1653 | 1653 | private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
| 1654 | 1654 | { |
| 1655 | 1655 | $template_args = array( |
| 1656 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1656 | + 'tkt_status_class' => ' tkt-status-'.$ticket->ticket_status(), |
|
| 1657 | 1657 | 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
| 1658 | 1658 | : '', |
| 1659 | 1659 | 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
@@ -1665,10 +1665,10 @@ discard block |
||
| 1665 | 1665 | 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
| 1666 | 1666 | 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
| 1667 | 1667 | 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
| 1668 | - 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1669 | - && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1668 | + 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1669 | + && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1670 | 1670 | ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
| 1671 | - 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1671 | + 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1672 | 1672 | : ' disabled=disabled', |
| 1673 | 1673 | ); |
| 1674 | 1674 | $price = $ticket->ID() !== 0 |
@@ -1698,7 +1698,7 @@ discard block |
||
| 1698 | 1698 | array('order_by' => array('DTT_EVT_start' => 'ASC')) |
| 1699 | 1699 | ) |
| 1700 | 1700 | : null; |
| 1701 | - if (! empty($earliest_dtt)) { |
|
| 1701 | + if ( ! empty($earliest_dtt)) { |
|
| 1702 | 1702 | $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
| 1703 | 1703 | } else { |
| 1704 | 1704 | $template_args['TKT_end_date'] = date( |
@@ -1710,7 +1710,7 @@ discard block |
||
| 1710 | 1710 | $template_args = array_merge($template_args, $price_args); |
| 1711 | 1711 | $template = apply_filters( |
| 1712 | 1712 | 'FHEE__Events_Admin_Page__get_ticket_row__template', |
| 1713 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1713 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php', |
|
| 1714 | 1714 | $ticket |
| 1715 | 1715 | ); |
| 1716 | 1716 | return EEH_Template::display_template($template, $template_args, true); |
@@ -1765,7 +1765,7 @@ discard block |
||
| 1765 | 1765 | $default_reg_status_values |
| 1766 | 1766 | ); |
| 1767 | 1767 | EEH_Template::display_template( |
| 1768 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1768 | + EVENTS_TEMPLATE_PATH.'event_registration_options.template.php', |
|
| 1769 | 1769 | $template_args |
| 1770 | 1770 | ); |
| 1771 | 1771 | } |
@@ -1787,7 +1787,7 @@ discard block |
||
| 1787 | 1787 | { |
| 1788 | 1788 | $EEME = $this->_event_model(); |
| 1789 | 1789 | $offset = ($current_page - 1) * $per_page; |
| 1790 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1790 | + $limit = $count ? null : $offset.','.$per_page; |
|
| 1791 | 1791 | $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
| 1792 | 1792 | $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
| 1793 | 1793 | if (isset($this->_req_data['month_range'])) { |
@@ -1816,7 +1816,7 @@ discard block |
||
| 1816 | 1816 | // categories? |
| 1817 | 1817 | $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
| 1818 | 1818 | ? $this->_req_data['EVT_CAT'] : null; |
| 1819 | - if (! empty($category)) { |
|
| 1819 | + if ( ! empty($category)) { |
|
| 1820 | 1820 | $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
| 1821 | 1821 | $where['Term_Taxonomy.term_id'] = $category; |
| 1822 | 1822 | } |
@@ -1824,7 +1824,7 @@ discard block |
||
| 1824 | 1824 | $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
| 1825 | 1825 | if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
| 1826 | 1826 | $DateTime = new DateTime( |
| 1827 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1827 | + $year_r.'-'.$month_r.'-01 00:00:00', |
|
| 1828 | 1828 | new DateTimeZone('UTC') |
| 1829 | 1829 | ); |
| 1830 | 1830 | $start = $DateTime->getTimestamp(); |
@@ -1850,11 +1850,11 @@ discard block |
||
| 1850 | 1850 | ->format(implode(' ', $start_formats)); |
| 1851 | 1851 | $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
| 1852 | 1852 | } |
| 1853 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1853 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1854 | 1854 | $where['EVT_wp_user'] = get_current_user_id(); |
| 1855 | 1855 | } else { |
| 1856 | - if (! isset($where['status'])) { |
|
| 1857 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1856 | + if ( ! isset($where['status'])) { |
|
| 1857 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1858 | 1858 | $where['OR'] = array( |
| 1859 | 1859 | 'status*restrict_private' => array('!=', 'private'), |
| 1860 | 1860 | 'AND' => array( |
@@ -1875,7 +1875,7 @@ discard block |
||
| 1875 | 1875 | } |
| 1876 | 1876 | // search query handling |
| 1877 | 1877 | if (isset($this->_req_data['s'])) { |
| 1878 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1878 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
| 1879 | 1879 | $where['OR'] = array( |
| 1880 | 1880 | 'EVT_name' => array('LIKE', $search_string), |
| 1881 | 1881 | 'EVT_desc' => array('LIKE', $search_string), |
@@ -1971,7 +1971,7 @@ discard block |
||
| 1971 | 1971 | // clean status |
| 1972 | 1972 | $event_status = sanitize_key($event_status); |
| 1973 | 1973 | // grab status |
| 1974 | - if (! empty($event_status)) { |
|
| 1974 | + if ( ! empty($event_status)) { |
|
| 1975 | 1975 | $success = $this->_change_event_status($EVT_ID, $event_status); |
| 1976 | 1976 | } else { |
| 1977 | 1977 | $success = false; |
@@ -2008,7 +2008,7 @@ discard block |
||
| 2008 | 2008 | // clean status |
| 2009 | 2009 | $event_status = sanitize_key($event_status); |
| 2010 | 2010 | // grab status |
| 2011 | - if (! empty($event_status)) { |
|
| 2011 | + if ( ! empty($event_status)) { |
|
| 2012 | 2012 | $success = true; |
| 2013 | 2013 | // determine the event id and set to array. |
| 2014 | 2014 | $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
@@ -2052,7 +2052,7 @@ discard block |
||
| 2052 | 2052 | private function _change_event_status($EVT_ID = 0, $event_status = '') |
| 2053 | 2053 | { |
| 2054 | 2054 | // grab event id |
| 2055 | - if (! $EVT_ID) { |
|
| 2055 | + if ( ! $EVT_ID) { |
|
| 2056 | 2056 | $msg = esc_html__( |
| 2057 | 2057 | 'An error occurred. No Event ID or an invalid Event ID was received.', |
| 2058 | 2058 | 'event_espresso' |
@@ -2089,7 +2089,7 @@ discard block |
||
| 2089 | 2089 | // use class to change status |
| 2090 | 2090 | $this->_cpt_model_obj->set_status($event_status); |
| 2091 | 2091 | $success = $this->_cpt_model_obj->save(); |
| 2092 | - if (! $success) { |
|
| 2092 | + if ( ! $success) { |
|
| 2093 | 2093 | $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
| 2094 | 2094 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
| 2095 | 2095 | return false; |
@@ -2144,7 +2144,7 @@ discard block |
||
| 2144 | 2144 | */ |
| 2145 | 2145 | protected function getModelObjNodeGroupPersister() |
| 2146 | 2146 | { |
| 2147 | - if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
| 2147 | + if ( ! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
| 2148 | 2148 | $this->model_obj_node_group_persister = $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
| 2149 | 2149 | } |
| 2150 | 2150 | return $this->model_obj_node_group_persister; |
@@ -2400,7 +2400,7 @@ discard block |
||
| 2400 | 2400 | . esc_html__( |
| 2401 | 2401 | 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
| 2402 | 2402 | 'event_espresso' |
| 2403 | - ) . '</strong>'; |
|
| 2403 | + ).'</strong>'; |
|
| 2404 | 2404 | $this->display_admin_caf_preview_page('template_settings_tab'); |
| 2405 | 2405 | } |
| 2406 | 2406 | |
@@ -2420,12 +2420,12 @@ discard block |
||
| 2420 | 2420 | // set default category object |
| 2421 | 2421 | $this->_set_empty_category_object(); |
| 2422 | 2422 | // only set if we've got an id |
| 2423 | - if (! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2423 | + if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2424 | 2424 | return; |
| 2425 | 2425 | } |
| 2426 | 2426 | $category_id = absint($this->_req_data['EVT_CAT_ID']); |
| 2427 | 2427 | $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
| 2428 | - if (! empty($term)) { |
|
| 2428 | + if ( ! empty($term)) { |
|
| 2429 | 2429 | $this->_category->category_name = $term->name; |
| 2430 | 2430 | $this->_category->category_identifier = $term->slug; |
| 2431 | 2431 | $this->_category->category_desc = $term->description; |
@@ -2453,7 +2453,7 @@ discard block |
||
| 2453 | 2453 | { |
| 2454 | 2454 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2455 | 2455 | $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
| 2456 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2456 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 2457 | 2457 | 'add_category', |
| 2458 | 2458 | 'add_category', |
| 2459 | 2459 | array(), |
@@ -2527,7 +2527,7 @@ discard block |
||
| 2527 | 2527 | 'disable' => '', |
| 2528 | 2528 | 'disabled_message' => false, |
| 2529 | 2529 | ); |
| 2530 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2530 | + $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php'; |
|
| 2531 | 2531 | return EEH_Template::display_template($template, $template_args, true); |
| 2532 | 2532 | } |
| 2533 | 2533 | |
@@ -2612,7 +2612,7 @@ discard block |
||
| 2612 | 2612 | $insert_ids = $update |
| 2613 | 2613 | ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
| 2614 | 2614 | : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
| 2615 | - if (! is_array($insert_ids)) { |
|
| 2615 | + if ( ! is_array($insert_ids)) { |
|
| 2616 | 2616 | $msg = esc_html__( |
| 2617 | 2617 | 'An error occurred and the category has not been saved to the database.', |
| 2618 | 2618 | 'event_espresso' |
@@ -2643,7 +2643,7 @@ discard block |
||
| 2643 | 2643 | $limit = ($current_page - 1) * $per_page; |
| 2644 | 2644 | $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
| 2645 | 2645 | if (isset($this->_req_data['s'])) { |
| 2646 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2646 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
| 2647 | 2647 | $where['OR'] = array( |
| 2648 | 2648 | 'Term.name' => array('LIKE', $sstr), |
| 2649 | 2649 | 'description' => array('LIKE', $sstr), |
@@ -2652,7 +2652,7 @@ discard block |
||
| 2652 | 2652 | $query_params = array( |
| 2653 | 2653 | $where, |
| 2654 | 2654 | 'order_by' => array($orderby => $order), |
| 2655 | - 'limit' => $limit . ',' . $per_page, |
|
| 2655 | + 'limit' => $limit.','.$per_page, |
|
| 2656 | 2656 | 'force_join' => array('Term'), |
| 2657 | 2657 | ); |
| 2658 | 2658 | $categories = $count |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | ?> |
| 59 | 59 | <tr valign="top" class="ee-ticket-sortable ticket-row<?php echo $ticket_archive_class; |
| 60 | 60 | if (WP_DEBUG) { |
| 61 | - echo ' ee-wp-debug'; |
|
| 61 | + echo ' ee-wp-debug'; |
|
| 62 | 62 | } ?>" id="display-ticketrow-<?php echo $tkt_row; ?>"> |
| 63 | 63 | <!--<td class="ee-tkt-order-field"><span class="dashicons dashicons-sort<?php echo $tkt_status_class; ?>"> |
| 64 | 64 | <input type="hidden" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_order]" class="edit-ticket-TKT_order" value ="<?php echo $TKT_order; ?>" ></span></td>--> |
@@ -167,9 +167,9 @@ discard block |
||
| 167 | 167 | class="edit-ticket-TKT_row" value="<?php echo $tkt_row; ?>"> |
| 168 | 168 | |
| 169 | 169 | <!--<div class="total-price-container"><?php printf( |
| 170 | - esc_html__('Total Final Price: %s', 'event_espresso'), |
|
| 171 | - '<span class="ticket-price-amount">' . $TKT_price . '</span>' |
|
| 172 | - ); ?> </div>--> |
|
| 170 | + esc_html__('Total Final Price: %s', 'event_espresso'), |
|
| 171 | + '<span class="ticket-price-amount">' . $TKT_price . '</span>' |
|
| 172 | + ); ?> </div>--> |
|
| 173 | 173 | <textarea name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_description]" |
| 174 | 174 | class="edit-ticket-TKT_description ee-full-textarea-inp" |
| 175 | 175 | placeholder="Ticket Description"><?php echo $TKT_description; ?></textarea> |
@@ -183,20 +183,20 @@ discard block |
||
| 183 | 183 | <thead> |
| 184 | 184 | <tr valign="bottom"> |
| 185 | 185 | <td><span class="TD_TKT_number_datetimes_label"><?php |
| 186 | - esc_html_e( |
|
| 187 | - '# Datetimes', |
|
| 188 | - 'event_espresso' |
|
| 189 | - ); ?></span></td> |
|
| 186 | + esc_html_e( |
|
| 187 | + '# Datetimes', |
|
| 188 | + 'event_espresso' |
|
| 189 | + ); ?></span></td> |
|
| 190 | 190 | <td><span class="TD_TKT_min_qty_label"><?php |
| 191 | - esc_html_e( |
|
| 192 | - 'Minimum Quantity', |
|
| 193 | - 'event_espresso' |
|
| 194 | - ); ?></span></td> |
|
| 191 | + esc_html_e( |
|
| 192 | + 'Minimum Quantity', |
|
| 193 | + 'event_espresso' |
|
| 194 | + ); ?></span></td> |
|
| 195 | 195 | <td><span class="TD_TKT_max_qty_label"><?php |
| 196 | - esc_html_e( |
|
| 197 | - 'Maximum Quantity', |
|
| 198 | - 'event_espresso' |
|
| 199 | - ); ?></span></td> |
|
| 196 | + esc_html_e( |
|
| 197 | + 'Maximum Quantity', |
|
| 198 | + 'event_espresso' |
|
| 199 | + ); ?></span></td> |
|
| 200 | 200 | </tr> |
| 201 | 201 | </thead> |
| 202 | 202 | <tbody> |
@@ -254,24 +254,24 @@ discard block |
||
| 254 | 254 | <input type="checkbox" |
| 255 | 255 | name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_required]" |
| 256 | 256 | class="edit-ticket-TKT_required" value="1"<?php |
| 257 | - echo $TKT_required |
|
| 258 | - ? ' checked="checked"' |
|
| 259 | - : ''; |
|
| 260 | - echo $disabled |
|
| 261 | - ? ' disabled' |
|
| 262 | - : ''; ?>> |
|
| 257 | + echo $TKT_required |
|
| 258 | + ? ' checked="checked"' |
|
| 259 | + : ''; |
|
| 260 | + echo $disabled |
|
| 261 | + ? ' disabled' |
|
| 262 | + : ''; ?>> |
|
| 263 | 263 | <label for="edit-ticket-TKT_required"><?php |
| 264 | - esc_html_e( |
|
| 265 | - 'This ticket is required (will appear first in frontend ticket lists).', |
|
| 266 | - 'event_espresso' |
|
| 267 | - ); ?></label> |
|
| 264 | + esc_html_e( |
|
| 265 | + 'This ticket is required (will appear first in frontend ticket lists).', |
|
| 266 | + 'event_espresso' |
|
| 267 | + ); ?></label> |
|
| 268 | 268 | </div> |
| 269 | 269 | <div class="ticket-is-taxable-container"> |
| 270 | 270 | <?php if (! empty($tax_rows)) { ?> |
| 271 | 271 | <?php if ($disabled) : ?> |
| 272 | 272 | <?php |
| 273 | - $tax_value = ! empty($TKT_taxable) ? 1 : 0; |
|
| 274 | - ?> |
|
| 273 | + $tax_value = ! empty($TKT_taxable) ? 1 : 0; |
|
| 274 | + ?> |
|
| 275 | 275 | <input class="TKT-taxable-checkbox" type="hidden" |
| 276 | 276 | name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_taxable]" |
| 277 | 277 | value="<?php echo $tax_value; ?>"> |
@@ -285,19 +285,19 @@ discard block |
||
| 285 | 285 | value="1"<?php echo $TKT_taxable; ?>> |
| 286 | 286 | <?php endif; ?> |
| 287 | 287 | <label for="edit-ticket-TKT_taxable-<?php echo $tkt_row; ?>"> <?php |
| 288 | - esc_html_e( |
|
| 289 | - 'Use Global Taxes (those defined in the Pricing admin). If unchecked you can apply taxes below.', |
|
| 290 | - 'event_espresso' |
|
| 291 | - ); ?> |
|
| 288 | + esc_html_e( |
|
| 289 | + 'Use Global Taxes (those defined in the Pricing admin). If unchecked you can apply taxes below.', |
|
| 290 | + 'event_espresso' |
|
| 291 | + ); ?> |
|
| 292 | 292 | <?php } //end tax_rows check ?> |
| 293 | 293 | </div> |
| 294 | 294 | </div> |
| 295 | 295 | <div class="price-table-container"> |
| 296 | 296 | <h4 class="tickets-heading price-table-info"<?php echo $show_price_modifier; ?>><?php |
| 297 | - esc_html_e( |
|
| 298 | - 'Price Modifiers', |
|
| 299 | - 'event_espresso' |
|
| 300 | - ); ?></h4> |
|
| 297 | + esc_html_e( |
|
| 298 | + 'Price Modifiers', |
|
| 299 | + 'event_espresso' |
|
| 300 | + ); ?></h4> |
|
| 301 | 301 | <table class="price-table"> |
| 302 | 302 | <thead class="price-table-info"<?php echo $show_price_modifier; ?>> |
| 303 | 303 | <tr> |
@@ -317,10 +317,10 @@ discard block |
||
| 317 | 317 | <tr class="price-subtotal-row TKT-taxes-display"<?php echo $display_subtotal; ?>> |
| 318 | 318 | <td colspan="4" class="ee-numeric"> |
| 319 | 319 | <span class="TKT-taxable-subtotal-label"><strong><?php |
| 320 | - esc_html_e( |
|
| 321 | - 'Subtotal', |
|
| 322 | - 'event_espresso' |
|
| 323 | - ); ?></strong></span> |
|
| 320 | + esc_html_e( |
|
| 321 | + 'Subtotal', |
|
| 322 | + 'event_espresso' |
|
| 323 | + ); ?></strong></span> |
|
| 324 | 324 | </td> |
| 325 | 325 | <td class="ee-numeric"> |
| 326 | 326 | <span |
@@ -353,51 +353,51 @@ discard block |
||
| 353 | 353 | <div style="clear:both"></div> |
| 354 | 354 | <h4 class="tickets-heading"><?php esc_html_e('Event Datetimes', 'event_espresso'); ?></h4> |
| 355 | 355 | <p><?php |
| 356 | - esc_html_e( |
|
| 357 | - 'This ticket will be usable (allow entrance) for the following selected event datetimes (click to select). The "# Datetimes" amount (above) indicates how many of the assigned datetimes the ticket holder can gain access to:', |
|
| 358 | - 'event_espresso' |
|
| 359 | - ); ?></p> |
|
| 356 | + esc_html_e( |
|
| 357 | + 'This ticket will be usable (allow entrance) for the following selected event datetimes (click to select). The "# Datetimes" amount (above) indicates how many of the assigned datetimes the ticket holder can gain access to:', |
|
| 358 | + 'event_espresso' |
|
| 359 | + ); ?></p> |
|
| 360 | 360 | <ul class="datetime-tickets-list"> |
| 361 | 361 | <?php echo $ticket_datetimes_list; ?> |
| 362 | 362 | </ul> |
| 363 | 363 | |
| 364 | 364 | <?php do_action( |
| 365 | - 'AHEE__event_tickets_datetime_ticket_row_template__advanced_details_end', |
|
| 366 | - $tkt_row, |
|
| 367 | - $TKT_ID |
|
| 368 | - ); ?> |
|
| 365 | + 'AHEE__event_tickets_datetime_ticket_row_template__advanced_details_end', |
|
| 366 | + $tkt_row, |
|
| 367 | + $TKT_ID |
|
| 368 | + ); ?> |
|
| 369 | 369 | <div class="ee-editor-footer-container"> |
| 370 | 370 | <div class="ee-editor-id-container"> |
| 371 | 371 | <span class="ee-item-id"><?php echo |
| 372 | - $TKT_ID |
|
| 373 | - ? sprintf( |
|
| 374 | - esc_html__('Ticket ID: %d', 'event_espresso'), |
|
| 375 | - $TKT_ID |
|
| 376 | - ) |
|
| 377 | - : ''; ?></span> |
|
| 372 | + $TKT_ID |
|
| 373 | + ? sprintf( |
|
| 374 | + esc_html__('Ticket ID: %d', 'event_espresso'), |
|
| 375 | + $TKT_ID |
|
| 376 | + ) |
|
| 377 | + : ''; ?></span> |
|
| 378 | 378 | </div> |
| 379 | 379 | <div class="save-cancel-button-container"> |
| 380 | 380 | <label for="edit-ticket-TKT_is_default_selector"><?php |
| 381 | - esc_html_e( |
|
| 382 | - 'use this new ticket as a default ticket for any new events', |
|
| 383 | - 'event_espresso' |
|
| 384 | - ); ?></label> |
|
| 381 | + esc_html_e( |
|
| 382 | + 'use this new ticket as a default ticket for any new events', |
|
| 383 | + 'event_espresso' |
|
| 384 | + ); ?></label> |
|
| 385 | 385 | <input type="checkbox" |
| 386 | 386 | name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_is_default_selector]" |
| 387 | 387 | class="edit-ticket-TKT_is_default_selector" value="1"<?php |
| 388 | - echo $disabled |
|
| 389 | - ? ' disabled' |
|
| 390 | - : ''; ?>> |
|
| 388 | + echo $disabled |
|
| 389 | + ? ' disabled' |
|
| 390 | + : ''; ?>> |
|
| 391 | 391 | <input type="hidden" |
| 392 | 392 | name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_is_default]" |
| 393 | 393 | class="edit-ticket-TKT_is_default" value="<?php echo $TKT_is_default; ?>"> |
| 394 | 394 | <!--<button class="button-primary ee-save-button" data-context="ticket" data-ticket-row="<?php echo $tkt_row; ?>"><?php esc_html_e( |
| 395 | - 'Update Ticket', |
|
| 396 | - 'event_espresso' |
|
| 397 | - ); ?></button>--> |
|
| 395 | + 'Update Ticket', |
|
| 396 | + 'event_espresso' |
|
| 397 | + ); ?></button>--> |
|
| 398 | 398 | <button class="button-secondary ee-cancel-button" data-context="ticket" |
| 399 | 399 | data-ticket-row="<?php echo $tkt_row; ?>"><?php |
| 400 | - esc_html_e('Close', 'event_espresso'); ?></button> |
|
| 400 | + esc_html_e('Close', 'event_espresso'); ?></button> |
|
| 401 | 401 | </div> |
| 402 | 402 | </div> |
| 403 | 403 | <!-- these hidden inputs are for tracking changes in dtts attached to tickets during a js session --> |
@@ -38,103 +38,103 @@ |
||
| 38 | 38 | * @since 4.0 |
| 39 | 39 | */ |
| 40 | 40 | if (function_exists('espresso_version')) { |
| 41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | - /** |
|
| 43 | - * espresso_duplicate_plugin_error |
|
| 44 | - * displays if more than one version of EE is activated at the same time |
|
| 45 | - */ |
|
| 46 | - function espresso_duplicate_plugin_error() |
|
| 47 | - { |
|
| 48 | - ?> |
|
| 41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | + /** |
|
| 43 | + * espresso_duplicate_plugin_error |
|
| 44 | + * displays if more than one version of EE is activated at the same time |
|
| 45 | + */ |
|
| 46 | + function espresso_duplicate_plugin_error() |
|
| 47 | + { |
|
| 48 | + ?> |
|
| 49 | 49 | <div class="error"> |
| 50 | 50 | <p> |
| 51 | 51 | <?php |
| 52 | - echo esc_html__( |
|
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 52 | + echo esc_html__( |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | } else { |
| 64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
| 65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | - /** |
|
| 67 | - * espresso_minimum_php_version_error |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
| 65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | + /** |
|
| 67 | + * espresso_minimum_php_version_error |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | - /** |
|
| 98 | - * espresso_version |
|
| 99 | - * Returns the plugin version |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - function espresso_version() |
|
| 104 | - { |
|
| 105 | - return apply_filters('FHEE__espresso__espresso_version', '4.10.23.rc.002'); |
|
| 106 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | + /** |
|
| 98 | + * espresso_version |
|
| 99 | + * Returns the plugin version |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + function espresso_version() |
|
| 104 | + { |
|
| 105 | + return apply_filters('FHEE__espresso__espresso_version', '4.10.23.rc.002'); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * espresso_plugin_activation |
|
| 110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | - */ |
|
| 112 | - function espresso_plugin_activation() |
|
| 113 | - { |
|
| 114 | - update_option('ee_espresso_activation', true); |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * espresso_plugin_activation |
|
| 110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | + */ |
|
| 112 | + function espresso_plugin_activation() |
|
| 113 | + { |
|
| 114 | + update_option('ee_espresso_activation', true); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 118 | 118 | |
| 119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | - bootstrap_espresso(); |
|
| 121 | - } |
|
| 119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | + bootstrap_espresso(); |
|
| 121 | + } |
|
| 122 | 122 | } |
| 123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
| 124 | - /** |
|
| 125 | - * deactivate_plugin |
|
| 126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | - * |
|
| 128 | - * @access public |
|
| 129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | - * @return void |
|
| 131 | - */ |
|
| 132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | - { |
|
| 134 | - if (! function_exists('deactivate_plugins')) { |
|
| 135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | - } |
|
| 137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | - deactivate_plugins($plugin_basename); |
|
| 139 | - } |
|
| 124 | + /** |
|
| 125 | + * deactivate_plugin |
|
| 126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | + * |
|
| 128 | + * @access public |
|
| 129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | + * @return void |
|
| 131 | + */ |
|
| 132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | + { |
|
| 134 | + if (! function_exists('deactivate_plugins')) { |
|
| 135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | + } |
|
| 137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | + deactivate_plugins($plugin_basename); |
|
| 139 | + } |
|
| 140 | 140 | } |