@@ -13,63 +13,63 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | class EE_DMS_Core_4_11_0 extends EE_Data_Migration_Script_Base |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * |
|
| 18 | - * @param EE_DMS_Core_4_10_0 $dms_4_10 |
|
| 19 | - * @param TableManager|null $table_manager |
|
| 20 | - * @param TableAnalysis|null $table_analysis |
|
| 21 | - */ |
|
| 22 | - public function __construct( |
|
| 23 | - EE_DMS_Core_4_10_0 $dms_4_10, |
|
| 24 | - TableManager $table_manager = null, |
|
| 25 | - TableAnalysis $table_analysis = null |
|
| 26 | - ) { |
|
| 27 | - $this->previous_dms = $dms_4_10; |
|
| 28 | - $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.11.0", "event_espresso"); |
|
| 29 | - $this->_priority = 10; |
|
| 30 | - $this->_migration_stages = [ |
|
| 31 | - |
|
| 32 | - ]; |
|
| 33 | - parent::__construct($table_manager, $table_analysis); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Whether to migrate or not. |
|
| 39 | - * |
|
| 40 | - * @param array $version_array |
|
| 41 | - * @return bool |
|
| 42 | - */ |
|
| 43 | - public function can_migrate_from_version($version_array) |
|
| 44 | - { |
|
| 45 | - $version_string = $version_array['Core']; |
|
| 46 | - return $version_string |
|
| 47 | - && version_compare($version_string, '4.11.0.decaf', '<') |
|
| 48 | - && version_compare($version_string, '4.10.0.decaf', '>='); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @return bool |
|
| 54 | - * @throws EE_Error |
|
| 55 | - * @throws ReflectionException |
|
| 56 | - */ |
|
| 57 | - public function schema_changes_before_migration() |
|
| 58 | - { |
|
| 59 | - require_once EE_HELPERS . 'EEH_Activation.helper.php'; |
|
| 60 | - |
|
| 61 | - $table_name = 'esp_answer'; |
|
| 62 | - $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 16 | + /** |
|
| 17 | + * |
|
| 18 | + * @param EE_DMS_Core_4_10_0 $dms_4_10 |
|
| 19 | + * @param TableManager|null $table_manager |
|
| 20 | + * @param TableAnalysis|null $table_analysis |
|
| 21 | + */ |
|
| 22 | + public function __construct( |
|
| 23 | + EE_DMS_Core_4_10_0 $dms_4_10, |
|
| 24 | + TableManager $table_manager = null, |
|
| 25 | + TableAnalysis $table_analysis = null |
|
| 26 | + ) { |
|
| 27 | + $this->previous_dms = $dms_4_10; |
|
| 28 | + $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.11.0", "event_espresso"); |
|
| 29 | + $this->_priority = 10; |
|
| 30 | + $this->_migration_stages = [ |
|
| 31 | + |
|
| 32 | + ]; |
|
| 33 | + parent::__construct($table_manager, $table_analysis); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Whether to migrate or not. |
|
| 39 | + * |
|
| 40 | + * @param array $version_array |
|
| 41 | + * @return bool |
|
| 42 | + */ |
|
| 43 | + public function can_migrate_from_version($version_array) |
|
| 44 | + { |
|
| 45 | + $version_string = $version_array['Core']; |
|
| 46 | + return $version_string |
|
| 47 | + && version_compare($version_string, '4.11.0.decaf', '<') |
|
| 48 | + && version_compare($version_string, '4.10.0.decaf', '>='); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @return bool |
|
| 54 | + * @throws EE_Error |
|
| 55 | + * @throws ReflectionException |
|
| 56 | + */ |
|
| 57 | + public function schema_changes_before_migration() |
|
| 58 | + { |
|
| 59 | + require_once EE_HELPERS . 'EEH_Activation.helper.php'; |
|
| 60 | + |
|
| 61 | + $table_name = 'esp_answer'; |
|
| 62 | + $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 63 | 63 | REG_ID int(10) unsigned NOT NULL, |
| 64 | 64 | QST_ID int(10) unsigned NOT NULL, |
| 65 | 65 | ANS_value text NOT NULL, |
| 66 | 66 | PRIMARY KEY (ANS_ID), |
| 67 | 67 | KEY REG_ID (REG_ID), |
| 68 | 68 | KEY QST_ID (QST_ID)"; |
| 69 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 69 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 70 | 70 | |
| 71 | - $table_name = 'esp_attendee_meta'; |
|
| 72 | - $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 71 | + $table_name = 'esp_attendee_meta'; |
|
| 72 | + $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 73 | 73 | ATT_ID bigint(20) unsigned NOT NULL, |
| 74 | 74 | ATT_fname varchar(45) NOT NULL, |
| 75 | 75 | ATT_lname varchar(45) NOT NULL, |
@@ -86,10 +86,10 @@ discard block |
||
| 86 | 86 | KEY ATT_email (ATT_email(191)), |
| 87 | 87 | KEY ATT_lname (ATT_lname), |
| 88 | 88 | KEY ATT_fname (ATT_fname)"; |
| 89 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 89 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 90 | 90 | |
| 91 | - $table_name = 'esp_checkin'; |
|
| 92 | - $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 91 | + $table_name = 'esp_checkin'; |
|
| 92 | + $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 93 | 93 | REG_ID int(10) unsigned NOT NULL, |
| 94 | 94 | DTT_ID int(10) unsigned NOT NULL, |
| 95 | 95 | CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -97,10 +97,10 @@ discard block |
||
| 97 | 97 | PRIMARY KEY (CHK_ID), |
| 98 | 98 | KEY REG_ID (REG_ID), |
| 99 | 99 | KEY DTT_ID (DTT_ID)"; |
| 100 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 100 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 101 | 101 | |
| 102 | - $table_name = 'esp_country'; |
|
| 103 | - $sql = "CNT_ISO varchar(2) NOT NULL, |
|
| 102 | + $table_name = 'esp_country'; |
|
| 103 | + $sql = "CNT_ISO varchar(2) NOT NULL, |
|
| 104 | 104 | CNT_ISO3 varchar(3) NOT NULL, |
| 105 | 105 | RGN_ID tinyint(3) unsigned DEFAULT NULL, |
| 106 | 106 | CNT_name varchar(45) NOT NULL, |
@@ -116,32 +116,32 @@ discard block |
||
| 116 | 116 | CNT_is_EU tinyint(1) DEFAULT '0', |
| 117 | 117 | CNT_active tinyint(1) DEFAULT '0', |
| 118 | 118 | PRIMARY KEY (CNT_ISO)"; |
| 119 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 119 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 120 | 120 | |
| 121 | - $table_name = 'esp_currency'; |
|
| 122 | - $sql = "CUR_code varchar(6) NOT NULL, |
|
| 121 | + $table_name = 'esp_currency'; |
|
| 122 | + $sql = "CUR_code varchar(6) NOT NULL, |
|
| 123 | 123 | CUR_single varchar(45) DEFAULT 'dollar', |
| 124 | 124 | CUR_plural varchar(45) DEFAULT 'dollars', |
| 125 | 125 | CUR_sign varchar(45) DEFAULT '$', |
| 126 | 126 | CUR_dec_plc varchar(1) NOT NULL DEFAULT '2', |
| 127 | 127 | CUR_active tinyint(1) DEFAULT '0', |
| 128 | 128 | PRIMARY KEY (CUR_code)"; |
| 129 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 130 | - |
|
| 131 | - // note: although this table is no longer in use, |
|
| 132 | - // it hasn't been removed because then queries to the model will have errors. |
|
| 133 | - // but you should expect this table and its corresponding model to be removed in |
|
| 134 | - // the next few months |
|
| 135 | - $table_name = 'esp_currency_payment_method'; |
|
| 136 | - $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 129 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 130 | + |
|
| 131 | + // note: although this table is no longer in use, |
|
| 132 | + // it hasn't been removed because then queries to the model will have errors. |
|
| 133 | + // but you should expect this table and its corresponding model to be removed in |
|
| 134 | + // the next few months |
|
| 135 | + $table_name = 'esp_currency_payment_method'; |
|
| 136 | + $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 137 | 137 | CUR_code varchar(6) NOT NULL, |
| 138 | 138 | PMD_ID int(11) NOT NULL, |
| 139 | 139 | PRIMARY KEY (CPM_ID), |
| 140 | 140 | KEY PMD_ID (PMD_ID)"; |
| 141 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 141 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 142 | 142 | |
| 143 | - $table_name = 'esp_datetime'; |
|
| 144 | - $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 143 | + $table_name = 'esp_datetime'; |
|
| 144 | + $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 145 | 145 | EVT_ID bigint(20) unsigned NOT NULL, |
| 146 | 146 | DTT_name varchar(255) NOT NULL DEFAULT '', |
| 147 | 147 | DTT_description text NOT NULL, |
@@ -158,28 +158,28 @@ discard block |
||
| 158 | 158 | KEY DTT_EVT_start (DTT_EVT_start), |
| 159 | 159 | KEY EVT_ID (EVT_ID), |
| 160 | 160 | KEY DTT_is_primary (DTT_is_primary)"; |
| 161 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 161 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 162 | 162 | |
| 163 | - $table_name = "esp_datetime_ticket"; |
|
| 164 | - $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 163 | + $table_name = "esp_datetime_ticket"; |
|
| 164 | + $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 165 | 165 | DTT_ID int(10) unsigned NOT NULL, |
| 166 | 166 | TKT_ID int(10) unsigned NOT NULL, |
| 167 | 167 | PRIMARY KEY (DTK_ID), |
| 168 | 168 | KEY DTT_ID (DTT_ID), |
| 169 | 169 | KEY TKT_ID (TKT_ID)"; |
| 170 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 170 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 171 | 171 | |
| 172 | - $table_name = 'esp_event_message_template'; |
|
| 173 | - $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
| 172 | + $table_name = 'esp_event_message_template'; |
|
| 173 | + $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
| 174 | 174 | EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
| 175 | 175 | GRP_ID int(10) unsigned NOT NULL DEFAULT 0, |
| 176 | 176 | PRIMARY KEY (EMT_ID), |
| 177 | 177 | KEY EVT_ID (EVT_ID), |
| 178 | 178 | KEY GRP_ID (GRP_ID)"; |
| 179 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 179 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 180 | 180 | |
| 181 | - $table_name = 'esp_event_meta'; |
|
| 182 | - $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
| 181 | + $table_name = 'esp_event_meta'; |
|
| 182 | + $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
| 183 | 183 | EVT_ID bigint(20) unsigned NOT NULL, |
| 184 | 184 | EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1, |
| 185 | 185 | EVT_display_ticket_selector tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -194,10 +194,10 @@ discard block |
||
| 194 | 194 | EVT_donations tinyint(1) NULL, |
| 195 | 195 | PRIMARY KEY (EVTM_ID), |
| 196 | 196 | KEY EVT_ID (EVT_ID)"; |
| 197 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 197 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 198 | 198 | |
| 199 | - $table_name = 'esp_event_question_group'; |
|
| 200 | - $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 199 | + $table_name = 'esp_event_question_group'; |
|
| 200 | + $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 201 | 201 | EVT_ID bigint(20) unsigned NOT NULL, |
| 202 | 202 | QSG_ID int(10) unsigned NOT NULL, |
| 203 | 203 | EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
@@ -205,28 +205,28 @@ discard block |
||
| 205 | 205 | PRIMARY KEY (EQG_ID), |
| 206 | 206 | KEY EVT_ID (EVT_ID), |
| 207 | 207 | KEY QSG_ID (QSG_ID)"; |
| 208 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 208 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 209 | 209 | |
| 210 | - $table_name = 'esp_event_venue'; |
|
| 211 | - $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 210 | + $table_name = 'esp_event_venue'; |
|
| 211 | + $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 212 | 212 | EVT_ID bigint(20) unsigned NOT NULL, |
| 213 | 213 | VNU_ID bigint(20) unsigned NOT NULL, |
| 214 | 214 | EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
| 215 | 215 | PRIMARY KEY (EVV_ID)"; |
| 216 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 216 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 217 | 217 | |
| 218 | - $table_name = 'esp_extra_meta'; |
|
| 219 | - $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 218 | + $table_name = 'esp_extra_meta'; |
|
| 219 | + $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 220 | 220 | OBJ_ID int(11) DEFAULT NULL, |
| 221 | 221 | EXM_type varchar(45) DEFAULT NULL, |
| 222 | 222 | EXM_key varchar(45) DEFAULT NULL, |
| 223 | 223 | EXM_value text, |
| 224 | 224 | PRIMARY KEY (EXM_ID), |
| 225 | 225 | KEY EXM_type (EXM_type,OBJ_ID,EXM_key)"; |
| 226 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 226 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 227 | 227 | |
| 228 | - $table_name = 'esp_extra_join'; |
|
| 229 | - $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 228 | + $table_name = 'esp_extra_join'; |
|
| 229 | + $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 230 | 230 | EXJ_first_model_id varchar(6) NOT NULL, |
| 231 | 231 | EXJ_first_model_name varchar(20) NOT NULL, |
| 232 | 232 | EXJ_second_model_id varchar(6) NOT NULL, |
@@ -234,11 +234,11 @@ discard block |
||
| 234 | 234 | PRIMARY KEY (EXJ_ID), |
| 235 | 235 | KEY first_model (EXJ_first_model_name,EXJ_first_model_id), |
| 236 | 236 | KEY second_model (EXJ_second_model_name,EXJ_second_model_id)"; |
| 237 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 237 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 238 | 238 | |
| 239 | - $now_in_mysql = current_time('mysql', true); |
|
| 240 | - $table_name = 'esp_line_item'; |
|
| 241 | - $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 239 | + $now_in_mysql = current_time('mysql', true); |
|
| 240 | + $table_name = 'esp_line_item'; |
|
| 241 | + $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 242 | 242 | LIN_code varchar(245) NOT NULL DEFAULT '', |
| 243 | 243 | TXN_ID int(11) DEFAULT NULL, |
| 244 | 244 | LIN_name varchar(245) NOT NULL DEFAULT '', |
@@ -259,10 +259,10 @@ discard block |
||
| 259 | 259 | KEY txn_type_timestamp (TXN_ID,LIN_type,LIN_timestamp), |
| 260 | 260 | KEY txn_obj_id_obj_type (TXN_ID,OBJ_ID,OBJ_type), |
| 261 | 261 | KEY obj_id_obj_type (OBJ_ID,OBJ_type)"; |
| 262 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 262 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 263 | 263 | |
| 264 | - $table_name = 'esp_log'; |
|
| 265 | - $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 264 | + $table_name = 'esp_log'; |
|
| 265 | + $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 266 | 266 | LOG_time datetime DEFAULT NULL, |
| 267 | 267 | OBJ_ID varchar(45) DEFAULT NULL, |
| 268 | 268 | OBJ_type varchar(45) DEFAULT NULL, |
@@ -273,10 +273,10 @@ discard block |
||
| 273 | 273 | KEY LOG_time (LOG_time), |
| 274 | 274 | KEY OBJ (OBJ_type,OBJ_ID), |
| 275 | 275 | KEY LOG_type (LOG_type)"; |
| 276 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 276 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 277 | 277 | |
| 278 | - $table_name = 'esp_message'; |
|
| 279 | - $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
| 278 | + $table_name = 'esp_message'; |
|
| 279 | + $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
| 280 | 280 | GRP_ID int(10) unsigned NULL, |
| 281 | 281 | MSG_token varchar(255) NULL, |
| 282 | 282 | TXN_ID int(10) unsigned NULL, |
@@ -308,20 +308,20 @@ discard block |
||
| 308 | 308 | KEY STS_ID (STS_ID), |
| 309 | 309 | KEY MSG_created (MSG_created), |
| 310 | 310 | KEY MSG_modified (MSG_modified)"; |
| 311 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 311 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 312 | 312 | |
| 313 | - $table_name = 'esp_message_template'; |
|
| 314 | - $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 313 | + $table_name = 'esp_message_template'; |
|
| 314 | + $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 315 | 315 | GRP_ID int(10) unsigned NOT NULL, |
| 316 | 316 | MTP_context varchar(50) NOT NULL, |
| 317 | 317 | MTP_template_field varchar(30) NOT NULL, |
| 318 | 318 | MTP_content text NOT NULL, |
| 319 | 319 | PRIMARY KEY (MTP_ID), |
| 320 | 320 | KEY GRP_ID (GRP_ID)"; |
| 321 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 321 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 322 | 322 | |
| 323 | - $table_name = 'esp_message_template_group'; |
|
| 324 | - $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 323 | + $table_name = 'esp_message_template_group'; |
|
| 324 | + $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 325 | 325 | MTP_user_id int(10) NOT NULL DEFAULT '1', |
| 326 | 326 | MTP_name varchar(245) NOT NULL DEFAULT '', |
| 327 | 327 | MTP_description varchar(245) NOT NULL DEFAULT '', |
@@ -333,10 +333,10 @@ discard block |
||
| 333 | 333 | MTP_is_active tinyint(1) NOT NULL DEFAULT '1', |
| 334 | 334 | PRIMARY KEY (GRP_ID), |
| 335 | 335 | KEY MTP_user_id (MTP_user_id)"; |
| 336 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 336 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 337 | 337 | |
| 338 | - $table_name = 'esp_payment'; |
|
| 339 | - $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 338 | + $table_name = 'esp_payment'; |
|
| 339 | + $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 340 | 340 | TXN_ID int(10) unsigned DEFAULT NULL, |
| 341 | 341 | STS_ID varchar(3) DEFAULT NULL, |
| 342 | 342 | PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -353,10 +353,10 @@ discard block |
||
| 353 | 353 | PRIMARY KEY (PAY_ID), |
| 354 | 354 | KEY PAY_timestamp (PAY_timestamp), |
| 355 | 355 | KEY TXN_ID (TXN_ID)"; |
| 356 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 356 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 357 | 357 | |
| 358 | - $table_name = 'esp_payment_method'; |
|
| 359 | - $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 358 | + $table_name = 'esp_payment_method'; |
|
| 359 | + $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 360 | 360 | PMD_type varchar(124) DEFAULT NULL, |
| 361 | 361 | PMD_name varchar(255) DEFAULT NULL, |
| 362 | 362 | PMD_desc text, |
@@ -372,10 +372,10 @@ discard block |
||
| 372 | 372 | PRIMARY KEY (PMD_ID), |
| 373 | 373 | UNIQUE KEY PMD_slug_UNIQUE (PMD_slug), |
| 374 | 374 | KEY PMD_type (PMD_type)"; |
| 375 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 375 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 376 | 376 | |
| 377 | - $table_name = "esp_price"; |
|
| 378 | - $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 377 | + $table_name = "esp_price"; |
|
| 378 | + $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 379 | 379 | PRT_ID tinyint(3) unsigned NOT NULL, |
| 380 | 380 | PRC_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
| 381 | 381 | PRC_name varchar(245) NOT NULL, |
@@ -388,10 +388,10 @@ discard block |
||
| 388 | 388 | PRC_parent int(10) unsigned DEFAULT 0, |
| 389 | 389 | PRIMARY KEY (PRC_ID), |
| 390 | 390 | KEY PRT_ID (PRT_ID)"; |
| 391 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 391 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 392 | 392 | |
| 393 | - $table_name = "esp_price_type"; |
|
| 394 | - $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
| 393 | + $table_name = "esp_price_type"; |
|
| 394 | + $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
| 395 | 395 | PRT_name varchar(45) NOT NULL, |
| 396 | 396 | PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1', |
| 397 | 397 | PRT_is_percent tinyint(1) NOT NULL DEFAULT '0', |
@@ -400,27 +400,27 @@ discard block |
||
| 400 | 400 | PRT_deleted tinyint(1) NOT NULL DEFAULT '0', |
| 401 | 401 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
| 402 | 402 | PRIMARY KEY (PRT_ID)"; |
| 403 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 403 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 404 | 404 | |
| 405 | - $table_name = "esp_ticket_price"; |
|
| 406 | - $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 405 | + $table_name = "esp_ticket_price"; |
|
| 406 | + $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 407 | 407 | TKT_ID int(10) unsigned NOT NULL, |
| 408 | 408 | PRC_ID int(10) unsigned NOT NULL, |
| 409 | 409 | PRIMARY KEY (TKP_ID), |
| 410 | 410 | KEY TKT_ID (TKT_ID), |
| 411 | 411 | KEY PRC_ID (PRC_ID)"; |
| 412 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 412 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 413 | 413 | |
| 414 | - $table_name = "esp_ticket_template"; |
|
| 415 | - $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 414 | + $table_name = "esp_ticket_template"; |
|
| 415 | + $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 416 | 416 | TTM_name varchar(45) NOT NULL, |
| 417 | 417 | TTM_description text, |
| 418 | 418 | TTM_file varchar(45), |
| 419 | 419 | PRIMARY KEY (TTM_ID)"; |
| 420 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 420 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 421 | 421 | |
| 422 | - $table_name = 'esp_question'; |
|
| 423 | - $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 422 | + $table_name = 'esp_question'; |
|
| 423 | + $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 424 | 424 | QST_display_text text NOT NULL, |
| 425 | 425 | QST_admin_label varchar(255) NOT NULL, |
| 426 | 426 | QST_system varchar(25) DEFAULT NULL, |
@@ -434,10 +434,10 @@ discard block |
||
| 434 | 434 | QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0, |
| 435 | 435 | PRIMARY KEY (QST_ID), |
| 436 | 436 | KEY QST_order (QST_order)'; |
| 437 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 437 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 438 | 438 | |
| 439 | - $table_name = 'esp_question_group'; |
|
| 440 | - $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 439 | + $table_name = 'esp_question_group'; |
|
| 440 | + $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 441 | 441 | QSG_name varchar(255) NOT NULL, |
| 442 | 442 | QSG_identifier varchar(100) NOT NULL, |
| 443 | 443 | QSG_desc text NULL, |
@@ -450,20 +450,20 @@ discard block |
||
| 450 | 450 | PRIMARY KEY (QSG_ID), |
| 451 | 451 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier), |
| 452 | 452 | KEY QSG_order (QSG_order)'; |
| 453 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 453 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 454 | 454 | |
| 455 | - $table_name = 'esp_question_group_question'; |
|
| 456 | - $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 455 | + $table_name = 'esp_question_group_question'; |
|
| 456 | + $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 457 | 457 | QSG_ID int(10) unsigned NOT NULL, |
| 458 | 458 | QST_ID int(10) unsigned NOT NULL, |
| 459 | 459 | QGQ_order int(10) unsigned NOT NULL DEFAULT 0, |
| 460 | 460 | PRIMARY KEY (QGQ_ID), |
| 461 | 461 | KEY QST_ID (QST_ID), |
| 462 | 462 | KEY QSG_ID_order (QSG_ID,QGQ_order)"; |
| 463 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 463 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 464 | 464 | |
| 465 | - $table_name = 'esp_question_option'; |
|
| 466 | - $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 465 | + $table_name = 'esp_question_option'; |
|
| 466 | + $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 467 | 467 | QSO_value varchar(255) NOT NULL, |
| 468 | 468 | QSO_desc text NOT NULL, |
| 469 | 469 | QST_ID int(10) unsigned NOT NULL, |
@@ -473,10 +473,10 @@ discard block |
||
| 473 | 473 | PRIMARY KEY (QSO_ID), |
| 474 | 474 | KEY QST_ID (QST_ID), |
| 475 | 475 | KEY QSO_order (QSO_order)"; |
| 476 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 476 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 477 | 477 | |
| 478 | - $table_name = 'esp_registration'; |
|
| 479 | - $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 478 | + $table_name = 'esp_registration'; |
|
| 479 | + $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 480 | 480 | EVT_ID bigint(20) unsigned NOT NULL, |
| 481 | 481 | ATT_ID bigint(20) unsigned NOT NULL, |
| 482 | 482 | TXN_ID int(10) unsigned NOT NULL, |
@@ -500,20 +500,20 @@ discard block |
||
| 500 | 500 | KEY TKT_ID (TKT_ID), |
| 501 | 501 | KEY EVT_ID (EVT_ID), |
| 502 | 502 | KEY STS_ID (STS_ID)"; |
| 503 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 503 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 504 | 504 | |
| 505 | - $table_name = 'esp_registration_payment'; |
|
| 506 | - $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 505 | + $table_name = 'esp_registration_payment'; |
|
| 506 | + $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 507 | 507 | REG_ID int(10) unsigned NOT NULL, |
| 508 | 508 | PAY_ID int(10) unsigned NULL, |
| 509 | 509 | RPY_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
| 510 | 510 | PRIMARY KEY (RPY_ID), |
| 511 | 511 | KEY REG_ID (REG_ID), |
| 512 | 512 | KEY PAY_ID (PAY_ID)"; |
| 513 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 513 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 514 | 514 | |
| 515 | - $table_name = 'esp_state'; |
|
| 516 | - $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
| 515 | + $table_name = 'esp_state'; |
|
| 516 | + $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
| 517 | 517 | CNT_ISO varchar(2) NOT NULL, |
| 518 | 518 | STA_abbrev varchar(24) NOT NULL, |
| 519 | 519 | STA_name varchar(100) NOT NULL, |
@@ -521,10 +521,10 @@ discard block |
||
| 521 | 521 | PRIMARY KEY (STA_ID), |
| 522 | 522 | KEY STA_abbrev (STA_abbrev), |
| 523 | 523 | KEY CNT_ISO (CNT_ISO)"; |
| 524 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 524 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 525 | 525 | |
| 526 | - $table_name = 'esp_status'; |
|
| 527 | - $sql = "STS_ID varchar(3) NOT NULL, |
|
| 526 | + $table_name = 'esp_status'; |
|
| 527 | + $sql = "STS_ID varchar(3) NOT NULL, |
|
| 528 | 528 | STS_code varchar(45) NOT NULL, |
| 529 | 529 | STS_type varchar(45) NOT NULL, |
| 530 | 530 | STS_can_edit tinyint(1) NOT NULL DEFAULT 0, |
@@ -532,10 +532,10 @@ discard block |
||
| 532 | 532 | STS_open tinyint(1) NOT NULL DEFAULT 1, |
| 533 | 533 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
| 534 | 534 | KEY STS_type (STS_type)"; |
| 535 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 535 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 536 | 536 | |
| 537 | - $table_name = "esp_ticket"; |
|
| 538 | - $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 537 | + $table_name = "esp_ticket"; |
|
| 538 | + $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 539 | 539 | TTM_ID int(10) unsigned NOT NULL, |
| 540 | 540 | TKT_name varchar(245) NOT NULL DEFAULT '', |
| 541 | 541 | TKT_description text NOT NULL, |
@@ -560,10 +560,10 @@ discard block |
||
| 560 | 560 | TKT_visibility smallint(6) unsigned NOT NULL DEFAULT 100, |
| 561 | 561 | PRIMARY KEY (TKT_ID), |
| 562 | 562 | KEY TKT_start_date (TKT_start_date)"; |
| 563 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 563 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 564 | 564 | |
| 565 | - $table_name = 'esp_transaction'; |
|
| 566 | - $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 565 | + $table_name = 'esp_transaction'; |
|
| 566 | + $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 567 | 567 | TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
| 568 | 568 | TXN_total decimal(12,3) DEFAULT '0.00', |
| 569 | 569 | TXN_paid decimal(12,3) NOT NULL DEFAULT '0.00', |
@@ -575,10 +575,10 @@ discard block |
||
| 575 | 575 | PRIMARY KEY (TXN_ID), |
| 576 | 576 | KEY TXN_timestamp (TXN_timestamp), |
| 577 | 577 | KEY STS_ID (STS_ID)"; |
| 578 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 578 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 579 | 579 | |
| 580 | - $table_name = 'esp_venue_meta'; |
|
| 581 | - $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 580 | + $table_name = 'esp_venue_meta'; |
|
| 581 | + $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 582 | 582 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
| 583 | 583 | VNU_address varchar(255) DEFAULT NULL, |
| 584 | 584 | VNU_address2 varchar(255) DEFAULT NULL, |
@@ -597,36 +597,36 @@ discard block |
||
| 597 | 597 | KEY VNU_ID (VNU_ID), |
| 598 | 598 | KEY STA_ID (STA_ID), |
| 599 | 599 | KEY CNT_ISO (CNT_ISO)"; |
| 600 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 601 | - |
|
| 602 | - $this->insert_default_data(); |
|
| 603 | - return true; |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * Inserts default data on new installs |
|
| 609 | - * |
|
| 610 | - * @throws EE_Error |
|
| 611 | - * @throws ReflectionException |
|
| 612 | - * @since 4.10.0.p |
|
| 613 | - */ |
|
| 614 | - public function insert_default_data() |
|
| 615 | - { |
|
| 616 | - $this->previous_dms->insert_default_data(); |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * @return boolean |
|
| 622 | - */ |
|
| 623 | - public function schema_changes_after_migration() |
|
| 624 | - { |
|
| 625 | - return true; |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - |
|
| 629 | - public function migration_page_hooks() |
|
| 630 | - { |
|
| 631 | - } |
|
| 600 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 601 | + |
|
| 602 | + $this->insert_default_data(); |
|
| 603 | + return true; |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * Inserts default data on new installs |
|
| 609 | + * |
|
| 610 | + * @throws EE_Error |
|
| 611 | + * @throws ReflectionException |
|
| 612 | + * @since 4.10.0.p |
|
| 613 | + */ |
|
| 614 | + public function insert_default_data() |
|
| 615 | + { |
|
| 616 | + $this->previous_dms->insert_default_data(); |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + |
|
| 620 | + /** |
|
| 621 | + * @return boolean |
|
| 622 | + */ |
|
| 623 | + public function schema_changes_after_migration() |
|
| 624 | + { |
|
| 625 | + return true; |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + |
|
| 629 | + public function migration_page_hooks() |
|
| 630 | + { |
|
| 631 | + } |
|
| 632 | 632 | } |
@@ -10,384 +10,384 @@ |
||
| 10 | 10 | class EEM_Ticket extends EEM_Soft_Delete_Base |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * the following constants define where tickets can be viewed throughout the UI |
|
| 15 | - * |
|
| 16 | - * TICKET_VISIBILITY_PUBLIC - displayed basically anywhere |
|
| 17 | - * TICKET_VISIBILITY_MEMBERS_ONLY - displayed to any logged in user |
|
| 18 | - * TICKET_VISIBILITY_ADMINS_ONLY - displayed to any logged in user that is an admin |
|
| 19 | - * TICKET_VISIBILITY_ADMIN_UI_ONLY - only displayed in the admin, never publicly |
|
| 20 | - * TICKET_VISIBILITY_NONE - will not be displayed anywhere |
|
| 21 | - */ |
|
| 22 | - public const TICKET_VISIBILITY_PUBLIC = 100; |
|
| 13 | + /** |
|
| 14 | + * the following constants define where tickets can be viewed throughout the UI |
|
| 15 | + * |
|
| 16 | + * TICKET_VISIBILITY_PUBLIC - displayed basically anywhere |
|
| 17 | + * TICKET_VISIBILITY_MEMBERS_ONLY - displayed to any logged in user |
|
| 18 | + * TICKET_VISIBILITY_ADMINS_ONLY - displayed to any logged in user that is an admin |
|
| 19 | + * TICKET_VISIBILITY_ADMIN_UI_ONLY - only displayed in the admin, never publicly |
|
| 20 | + * TICKET_VISIBILITY_NONE - will not be displayed anywhere |
|
| 21 | + */ |
|
| 22 | + public const TICKET_VISIBILITY_PUBLIC = 100; |
|
| 23 | 23 | |
| 24 | - public const TICKET_VISIBILITY_MEMBERS_ONLY = 200; |
|
| 24 | + public const TICKET_VISIBILITY_MEMBERS_ONLY = 200; |
|
| 25 | 25 | |
| 26 | - public const TICKET_VISIBILITY_ADMINS_ONLY = 300; |
|
| 26 | + public const TICKET_VISIBILITY_ADMINS_ONLY = 300; |
|
| 27 | 27 | |
| 28 | - public const TICKET_VISIBILITY_ADMIN_UI_ONLY = 400; |
|
| 28 | + public const TICKET_VISIBILITY_ADMIN_UI_ONLY = 400; |
|
| 29 | 29 | |
| 30 | - public const TICKET_VISIBILITY_NONE = 500; |
|
| 30 | + public const TICKET_VISIBILITY_NONE = 500; |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * defines where tickets can be viewed throughout the UI |
|
| 35 | - * |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - private $ticket_visibility; |
|
| 33 | + /** |
|
| 34 | + * defines where tickets can be viewed throughout the UI |
|
| 35 | + * |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + private $ticket_visibility; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * private instance of the EEM_Ticket object |
|
| 42 | - * |
|
| 43 | - * @var EEM_Ticket $_instance |
|
| 44 | - */ |
|
| 45 | - protected static $_instance; |
|
| 40 | + /** |
|
| 41 | + * private instance of the EEM_Ticket object |
|
| 42 | + * |
|
| 43 | + * @var EEM_Ticket $_instance |
|
| 44 | + */ |
|
| 45 | + protected static $_instance; |
|
| 46 | 46 | |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * private constructor to prevent direct creation |
|
| 50 | - * |
|
| 51 | - * @Constructor |
|
| 52 | - * @access private |
|
| 53 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
| 54 | - * (and any incoming timezone data that gets saved). |
|
| 55 | - * Note this just sends the timezone info to the date time model field objects. |
|
| 56 | - * Default is NULL |
|
| 57 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
| 58 | - * @throws EE_Error |
|
| 59 | - */ |
|
| 60 | - protected function __construct($timezone) |
|
| 61 | - { |
|
| 62 | - $this->singular_item = esc_html__('Ticket', 'event_espresso'); |
|
| 63 | - $this->plural_item = esc_html__('Tickets', 'event_espresso'); |
|
| 64 | - $this->_tables = array( |
|
| 65 | - 'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'), |
|
| 66 | - ); |
|
| 67 | - $this->ticket_visibility = (array) apply_filters( |
|
| 68 | - 'FHEE__EEM_Ticket__construct__ticket_visibility', |
|
| 69 | - [ |
|
| 70 | - EEM_Ticket::TICKET_VISIBILITY_PUBLIC => esc_html__('Public', 'event_espresso'), |
|
| 71 | - EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY => esc_html__('Members only', 'event_espresso'), |
|
| 72 | - EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY => esc_html__('Admins only', 'event_espresso'), |
|
| 73 | - EEM_Ticket::TICKET_VISIBILITY_ADMIN_UI_ONLY => esc_html__('Admin UI only', 'event_espresso'), |
|
| 74 | - EEM_Ticket::TICKET_VISIBILITY_NONE => esc_html__('None', 'event_espresso'), |
|
| 75 | - ] |
|
| 76 | - ); |
|
| 77 | - $this->_fields = array( |
|
| 78 | - 'Ticket' => array( |
|
| 79 | - 'TKT_ID' => new EE_Primary_Key_Int_Field( |
|
| 80 | - 'TKT_ID', |
|
| 81 | - esc_html__('Ticket ID', 'event_espresso') |
|
| 82 | - ), |
|
| 83 | - 'TTM_ID' => new EE_Foreign_Key_Int_Field( |
|
| 84 | - 'TTM_ID', |
|
| 85 | - esc_html__('Ticket Template ID', 'event_espresso'), |
|
| 86 | - false, |
|
| 87 | - 0, |
|
| 88 | - 'Ticket_Template' |
|
| 89 | - ), |
|
| 90 | - 'TKT_name' => new EE_Plain_Text_Field( |
|
| 91 | - 'TKT_name', |
|
| 92 | - esc_html__('Ticket Name', 'event_espresso'), |
|
| 93 | - false, |
|
| 94 | - '' |
|
| 95 | - ), |
|
| 96 | - 'TKT_description' => new EE_Post_Content_Field( |
|
| 97 | - 'TKT_description', |
|
| 98 | - esc_html__('Description of Ticket', 'event_espresso'), |
|
| 99 | - false, |
|
| 100 | - '' |
|
| 101 | - ), |
|
| 102 | - 'TKT_start_date' => new EE_Datetime_Field( |
|
| 103 | - 'TKT_start_date', |
|
| 104 | - esc_html__('Start time/date of Ticket', 'event_espresso'), |
|
| 105 | - false, |
|
| 106 | - EE_Datetime_Field::now, |
|
| 107 | - $timezone |
|
| 108 | - ), |
|
| 109 | - 'TKT_end_date' => new EE_Datetime_Field( |
|
| 110 | - 'TKT_end_date', |
|
| 111 | - esc_html__('End time/date of Ticket', 'event_espresso'), |
|
| 112 | - false, |
|
| 113 | - EE_Datetime_Field::now, |
|
| 114 | - $timezone |
|
| 115 | - ), |
|
| 116 | - 'TKT_min' => new EE_Integer_Field( |
|
| 117 | - 'TKT_min', |
|
| 118 | - esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'), |
|
| 119 | - false, |
|
| 120 | - 0 |
|
| 121 | - ), |
|
| 122 | - 'TKT_max' => new EE_Infinite_Integer_Field( |
|
| 123 | - 'TKT_max', |
|
| 124 | - esc_html__( |
|
| 125 | - 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
| 126 | - 'event_espresso' |
|
| 127 | - ), |
|
| 128 | - false, |
|
| 129 | - EE_INF |
|
| 130 | - ), |
|
| 131 | - 'TKT_price' => new EE_Money_Field( |
|
| 132 | - 'TKT_price', |
|
| 133 | - esc_html__('Final calculated price for ticket', 'event_espresso'), |
|
| 134 | - false, |
|
| 135 | - 0 |
|
| 136 | - ), |
|
| 137 | - 'TKT_sold' => new EE_Integer_Field( |
|
| 138 | - 'TKT_sold', |
|
| 139 | - esc_html__('Number of this ticket sold', 'event_espresso'), |
|
| 140 | - false, |
|
| 141 | - 0 |
|
| 142 | - ), |
|
| 143 | - 'TKT_qty' => new EE_Infinite_Integer_Field( |
|
| 144 | - 'TKT_qty', |
|
| 145 | - esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
| 146 | - false, |
|
| 147 | - EE_INF |
|
| 148 | - ), |
|
| 149 | - 'TKT_reserved' => new EE_Integer_Field( |
|
| 150 | - 'TKT_reserved', |
|
| 151 | - esc_html__( |
|
| 152 | - 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
| 153 | - 'event_espresso' |
|
| 154 | - ), |
|
| 155 | - false, |
|
| 156 | - 0 |
|
| 157 | - ), |
|
| 158 | - 'TKT_uses' => new EE_Infinite_Integer_Field( |
|
| 159 | - 'TKT_uses', |
|
| 160 | - esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
| 161 | - false, |
|
| 162 | - EE_INF |
|
| 163 | - ), |
|
| 164 | - 'TKT_required' => new EE_Boolean_Field( |
|
| 165 | - 'TKT_required', |
|
| 166 | - esc_html__( |
|
| 167 | - 'Flag indicating whether this ticket must be purchased with a transaction', |
|
| 168 | - 'event_espresso' |
|
| 169 | - ), |
|
| 170 | - false, |
|
| 171 | - false |
|
| 172 | - ), |
|
| 173 | - 'TKT_taxable' => new EE_Boolean_Field( |
|
| 174 | - 'TKT_taxable', |
|
| 175 | - esc_html__( |
|
| 176 | - 'Flag indicating whether there is tax applied on this ticket', |
|
| 177 | - 'event_espresso' |
|
| 178 | - ), |
|
| 179 | - false, |
|
| 180 | - false |
|
| 181 | - ), |
|
| 182 | - 'TKT_is_default' => new EE_Boolean_Field( |
|
| 183 | - 'TKT_is_default', |
|
| 184 | - esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'), |
|
| 185 | - false, |
|
| 186 | - false |
|
| 187 | - ), |
|
| 188 | - 'TKT_order' => new EE_Integer_Field( |
|
| 189 | - 'TKT_order', |
|
| 190 | - esc_html__( |
|
| 191 | - 'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)', |
|
| 192 | - 'event_espresso' |
|
| 193 | - ), |
|
| 194 | - false, |
|
| 195 | - 0 |
|
| 196 | - ), |
|
| 197 | - 'TKT_row' => new EE_Integer_Field( |
|
| 198 | - 'TKT_row', |
|
| 199 | - esc_html__('How tickets are displayed in the ui', 'event_espresso'), |
|
| 200 | - false, |
|
| 201 | - 0 |
|
| 202 | - ), |
|
| 203 | - 'TKT_deleted' => new EE_Trashed_Flag_Field( |
|
| 204 | - 'TKT_deleted', |
|
| 205 | - esc_html__('Flag indicating if this has been archived or not', 'event_espresso'), |
|
| 206 | - false, |
|
| 207 | - false |
|
| 208 | - ), |
|
| 209 | - 'TKT_wp_user' => new EE_WP_User_Field( |
|
| 210 | - 'TKT_wp_user', |
|
| 211 | - esc_html__('Ticket Creator ID', 'event_espresso'), |
|
| 212 | - false |
|
| 213 | - ), |
|
| 214 | - 'TKT_parent' => new EE_Integer_Field( |
|
| 215 | - 'TKT_parent', |
|
| 216 | - esc_html__( |
|
| 217 | - 'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)', |
|
| 218 | - 'event_espresso' |
|
| 219 | - ), |
|
| 220 | - true, |
|
| 221 | - 0 |
|
| 222 | - ), |
|
| 223 | - 'TKT_reverse_calculate' => new EE_Boolean_Field( |
|
| 224 | - 'TKT_reverse_calculate', |
|
| 225 | - esc_html__( |
|
| 226 | - 'Flag indicating whether ticket calculations should run in reverse and calculate the base ticket price from the provided ticket total.', |
|
| 227 | - 'event_espresso' |
|
| 228 | - ), |
|
| 229 | - false, |
|
| 230 | - false |
|
| 231 | - ), |
|
| 232 | - 'TKT_visibility' => new EE_Enum_Integer_Field( |
|
| 233 | - 'TKT_visibility', |
|
| 234 | - esc_html__('Defines where the ticket can be viewed throughout the UI.', 'event_espresso'), |
|
| 235 | - false, |
|
| 236 | - EEM_Ticket::TICKET_VISIBILITY_PUBLIC, |
|
| 237 | - $this->ticket_visibility |
|
| 238 | - ), |
|
| 239 | - ), |
|
| 240 | - ); |
|
| 241 | - $this->_model_relations = array( |
|
| 242 | - 'Datetime' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
| 243 | - 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
| 244 | - 'Price' => new EE_HABTM_Relation('Ticket_Price'), |
|
| 245 | - 'Ticket_Template' => new EE_Belongs_To_Relation(), |
|
| 246 | - 'Registration' => new EE_Has_Many_Relation(), |
|
| 247 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 248 | - ); |
|
| 249 | - // this model is generally available for reading |
|
| 250 | - $path_to_event = 'Datetime.Event'; |
|
| 251 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public( |
|
| 252 | - 'TKT_is_default', |
|
| 253 | - $path_to_event |
|
| 254 | - ); |
|
| 255 | - // account for default tickets in the caps |
|
| 256 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected( |
|
| 257 | - 'TKT_is_default', |
|
| 258 | - $path_to_event |
|
| 259 | - ); |
|
| 260 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected( |
|
| 261 | - 'TKT_is_default', |
|
| 262 | - $path_to_event |
|
| 263 | - ); |
|
| 264 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected( |
|
| 265 | - 'TKT_is_default', |
|
| 266 | - $path_to_event |
|
| 267 | - ); |
|
| 268 | - $this->model_chain_to_password = $path_to_event; |
|
| 269 | - parent::__construct($timezone); |
|
| 270 | - } |
|
| 48 | + /** |
|
| 49 | + * private constructor to prevent direct creation |
|
| 50 | + * |
|
| 51 | + * @Constructor |
|
| 52 | + * @access private |
|
| 53 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
| 54 | + * (and any incoming timezone data that gets saved). |
|
| 55 | + * Note this just sends the timezone info to the date time model field objects. |
|
| 56 | + * Default is NULL |
|
| 57 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
| 58 | + * @throws EE_Error |
|
| 59 | + */ |
|
| 60 | + protected function __construct($timezone) |
|
| 61 | + { |
|
| 62 | + $this->singular_item = esc_html__('Ticket', 'event_espresso'); |
|
| 63 | + $this->plural_item = esc_html__('Tickets', 'event_espresso'); |
|
| 64 | + $this->_tables = array( |
|
| 65 | + 'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'), |
|
| 66 | + ); |
|
| 67 | + $this->ticket_visibility = (array) apply_filters( |
|
| 68 | + 'FHEE__EEM_Ticket__construct__ticket_visibility', |
|
| 69 | + [ |
|
| 70 | + EEM_Ticket::TICKET_VISIBILITY_PUBLIC => esc_html__('Public', 'event_espresso'), |
|
| 71 | + EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY => esc_html__('Members only', 'event_espresso'), |
|
| 72 | + EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY => esc_html__('Admins only', 'event_espresso'), |
|
| 73 | + EEM_Ticket::TICKET_VISIBILITY_ADMIN_UI_ONLY => esc_html__('Admin UI only', 'event_espresso'), |
|
| 74 | + EEM_Ticket::TICKET_VISIBILITY_NONE => esc_html__('None', 'event_espresso'), |
|
| 75 | + ] |
|
| 76 | + ); |
|
| 77 | + $this->_fields = array( |
|
| 78 | + 'Ticket' => array( |
|
| 79 | + 'TKT_ID' => new EE_Primary_Key_Int_Field( |
|
| 80 | + 'TKT_ID', |
|
| 81 | + esc_html__('Ticket ID', 'event_espresso') |
|
| 82 | + ), |
|
| 83 | + 'TTM_ID' => new EE_Foreign_Key_Int_Field( |
|
| 84 | + 'TTM_ID', |
|
| 85 | + esc_html__('Ticket Template ID', 'event_espresso'), |
|
| 86 | + false, |
|
| 87 | + 0, |
|
| 88 | + 'Ticket_Template' |
|
| 89 | + ), |
|
| 90 | + 'TKT_name' => new EE_Plain_Text_Field( |
|
| 91 | + 'TKT_name', |
|
| 92 | + esc_html__('Ticket Name', 'event_espresso'), |
|
| 93 | + false, |
|
| 94 | + '' |
|
| 95 | + ), |
|
| 96 | + 'TKT_description' => new EE_Post_Content_Field( |
|
| 97 | + 'TKT_description', |
|
| 98 | + esc_html__('Description of Ticket', 'event_espresso'), |
|
| 99 | + false, |
|
| 100 | + '' |
|
| 101 | + ), |
|
| 102 | + 'TKT_start_date' => new EE_Datetime_Field( |
|
| 103 | + 'TKT_start_date', |
|
| 104 | + esc_html__('Start time/date of Ticket', 'event_espresso'), |
|
| 105 | + false, |
|
| 106 | + EE_Datetime_Field::now, |
|
| 107 | + $timezone |
|
| 108 | + ), |
|
| 109 | + 'TKT_end_date' => new EE_Datetime_Field( |
|
| 110 | + 'TKT_end_date', |
|
| 111 | + esc_html__('End time/date of Ticket', 'event_espresso'), |
|
| 112 | + false, |
|
| 113 | + EE_Datetime_Field::now, |
|
| 114 | + $timezone |
|
| 115 | + ), |
|
| 116 | + 'TKT_min' => new EE_Integer_Field( |
|
| 117 | + 'TKT_min', |
|
| 118 | + esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'), |
|
| 119 | + false, |
|
| 120 | + 0 |
|
| 121 | + ), |
|
| 122 | + 'TKT_max' => new EE_Infinite_Integer_Field( |
|
| 123 | + 'TKT_max', |
|
| 124 | + esc_html__( |
|
| 125 | + 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
| 126 | + 'event_espresso' |
|
| 127 | + ), |
|
| 128 | + false, |
|
| 129 | + EE_INF |
|
| 130 | + ), |
|
| 131 | + 'TKT_price' => new EE_Money_Field( |
|
| 132 | + 'TKT_price', |
|
| 133 | + esc_html__('Final calculated price for ticket', 'event_espresso'), |
|
| 134 | + false, |
|
| 135 | + 0 |
|
| 136 | + ), |
|
| 137 | + 'TKT_sold' => new EE_Integer_Field( |
|
| 138 | + 'TKT_sold', |
|
| 139 | + esc_html__('Number of this ticket sold', 'event_espresso'), |
|
| 140 | + false, |
|
| 141 | + 0 |
|
| 142 | + ), |
|
| 143 | + 'TKT_qty' => new EE_Infinite_Integer_Field( |
|
| 144 | + 'TKT_qty', |
|
| 145 | + esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
| 146 | + false, |
|
| 147 | + EE_INF |
|
| 148 | + ), |
|
| 149 | + 'TKT_reserved' => new EE_Integer_Field( |
|
| 150 | + 'TKT_reserved', |
|
| 151 | + esc_html__( |
|
| 152 | + 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
| 153 | + 'event_espresso' |
|
| 154 | + ), |
|
| 155 | + false, |
|
| 156 | + 0 |
|
| 157 | + ), |
|
| 158 | + 'TKT_uses' => new EE_Infinite_Integer_Field( |
|
| 159 | + 'TKT_uses', |
|
| 160 | + esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
| 161 | + false, |
|
| 162 | + EE_INF |
|
| 163 | + ), |
|
| 164 | + 'TKT_required' => new EE_Boolean_Field( |
|
| 165 | + 'TKT_required', |
|
| 166 | + esc_html__( |
|
| 167 | + 'Flag indicating whether this ticket must be purchased with a transaction', |
|
| 168 | + 'event_espresso' |
|
| 169 | + ), |
|
| 170 | + false, |
|
| 171 | + false |
|
| 172 | + ), |
|
| 173 | + 'TKT_taxable' => new EE_Boolean_Field( |
|
| 174 | + 'TKT_taxable', |
|
| 175 | + esc_html__( |
|
| 176 | + 'Flag indicating whether there is tax applied on this ticket', |
|
| 177 | + 'event_espresso' |
|
| 178 | + ), |
|
| 179 | + false, |
|
| 180 | + false |
|
| 181 | + ), |
|
| 182 | + 'TKT_is_default' => new EE_Boolean_Field( |
|
| 183 | + 'TKT_is_default', |
|
| 184 | + esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'), |
|
| 185 | + false, |
|
| 186 | + false |
|
| 187 | + ), |
|
| 188 | + 'TKT_order' => new EE_Integer_Field( |
|
| 189 | + 'TKT_order', |
|
| 190 | + esc_html__( |
|
| 191 | + 'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)', |
|
| 192 | + 'event_espresso' |
|
| 193 | + ), |
|
| 194 | + false, |
|
| 195 | + 0 |
|
| 196 | + ), |
|
| 197 | + 'TKT_row' => new EE_Integer_Field( |
|
| 198 | + 'TKT_row', |
|
| 199 | + esc_html__('How tickets are displayed in the ui', 'event_espresso'), |
|
| 200 | + false, |
|
| 201 | + 0 |
|
| 202 | + ), |
|
| 203 | + 'TKT_deleted' => new EE_Trashed_Flag_Field( |
|
| 204 | + 'TKT_deleted', |
|
| 205 | + esc_html__('Flag indicating if this has been archived or not', 'event_espresso'), |
|
| 206 | + false, |
|
| 207 | + false |
|
| 208 | + ), |
|
| 209 | + 'TKT_wp_user' => new EE_WP_User_Field( |
|
| 210 | + 'TKT_wp_user', |
|
| 211 | + esc_html__('Ticket Creator ID', 'event_espresso'), |
|
| 212 | + false |
|
| 213 | + ), |
|
| 214 | + 'TKT_parent' => new EE_Integer_Field( |
|
| 215 | + 'TKT_parent', |
|
| 216 | + esc_html__( |
|
| 217 | + 'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)', |
|
| 218 | + 'event_espresso' |
|
| 219 | + ), |
|
| 220 | + true, |
|
| 221 | + 0 |
|
| 222 | + ), |
|
| 223 | + 'TKT_reverse_calculate' => new EE_Boolean_Field( |
|
| 224 | + 'TKT_reverse_calculate', |
|
| 225 | + esc_html__( |
|
| 226 | + 'Flag indicating whether ticket calculations should run in reverse and calculate the base ticket price from the provided ticket total.', |
|
| 227 | + 'event_espresso' |
|
| 228 | + ), |
|
| 229 | + false, |
|
| 230 | + false |
|
| 231 | + ), |
|
| 232 | + 'TKT_visibility' => new EE_Enum_Integer_Field( |
|
| 233 | + 'TKT_visibility', |
|
| 234 | + esc_html__('Defines where the ticket can be viewed throughout the UI.', 'event_espresso'), |
|
| 235 | + false, |
|
| 236 | + EEM_Ticket::TICKET_VISIBILITY_PUBLIC, |
|
| 237 | + $this->ticket_visibility |
|
| 238 | + ), |
|
| 239 | + ), |
|
| 240 | + ); |
|
| 241 | + $this->_model_relations = array( |
|
| 242 | + 'Datetime' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
| 243 | + 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
| 244 | + 'Price' => new EE_HABTM_Relation('Ticket_Price'), |
|
| 245 | + 'Ticket_Template' => new EE_Belongs_To_Relation(), |
|
| 246 | + 'Registration' => new EE_Has_Many_Relation(), |
|
| 247 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 248 | + ); |
|
| 249 | + // this model is generally available for reading |
|
| 250 | + $path_to_event = 'Datetime.Event'; |
|
| 251 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public( |
|
| 252 | + 'TKT_is_default', |
|
| 253 | + $path_to_event |
|
| 254 | + ); |
|
| 255 | + // account for default tickets in the caps |
|
| 256 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected( |
|
| 257 | + 'TKT_is_default', |
|
| 258 | + $path_to_event |
|
| 259 | + ); |
|
| 260 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected( |
|
| 261 | + 'TKT_is_default', |
|
| 262 | + $path_to_event |
|
| 263 | + ); |
|
| 264 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected( |
|
| 265 | + 'TKT_is_default', |
|
| 266 | + $path_to_event |
|
| 267 | + ); |
|
| 268 | + $this->model_chain_to_password = $path_to_event; |
|
| 269 | + parent::__construct($timezone); |
|
| 270 | + } |
|
| 271 | 271 | |
| 272 | 272 | |
| 273 | - /** |
|
| 274 | - * This returns all tickets that are defaults from the db |
|
| 275 | - * |
|
| 276 | - * @return EE_Ticket[] |
|
| 277 | - * @throws EE_Error |
|
| 278 | - */ |
|
| 279 | - public function get_all_default_tickets() |
|
| 280 | - { |
|
| 281 | - /** @type EE_Ticket[] $tickets */ |
|
| 282 | - $tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_ID' => 'ASC'))); |
|
| 283 | - // we need to set the start date and end date to today's date and the start of the default dtt |
|
| 284 | - return $this->_set_default_dates($tickets); |
|
| 285 | - } |
|
| 273 | + /** |
|
| 274 | + * This returns all tickets that are defaults from the db |
|
| 275 | + * |
|
| 276 | + * @return EE_Ticket[] |
|
| 277 | + * @throws EE_Error |
|
| 278 | + */ |
|
| 279 | + public function get_all_default_tickets() |
|
| 280 | + { |
|
| 281 | + /** @type EE_Ticket[] $tickets */ |
|
| 282 | + $tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_ID' => 'ASC'))); |
|
| 283 | + // we need to set the start date and end date to today's date and the start of the default dtt |
|
| 284 | + return $this->_set_default_dates($tickets); |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | 287 | |
| 288 | - /** |
|
| 289 | - * sets up relevant start and end date for EE_Ticket (s) |
|
| 290 | - * |
|
| 291 | - * @param EE_Ticket[] $tickets |
|
| 292 | - * @return EE_Ticket[] |
|
| 293 | - * @throws EE_Error |
|
| 294 | - */ |
|
| 295 | - private function _set_default_dates($tickets) |
|
| 296 | - { |
|
| 297 | - foreach ($tickets as $ticket) { |
|
| 298 | - $ticket->set( |
|
| 299 | - 'TKT_start_date', |
|
| 300 | - (int) $this->current_time_for_query('TKT_start_date', true) |
|
| 301 | - ); |
|
| 302 | - $ticket->set( |
|
| 303 | - 'TKT_end_date', |
|
| 304 | - (int) $this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
| 305 | - ); |
|
| 306 | - $ticket->set_end_time( |
|
| 307 | - $this->convert_datetime_for_query( |
|
| 308 | - 'TKT_end_date', |
|
| 309 | - '11:59 pm', |
|
| 310 | - 'g:i a', |
|
| 311 | - $this->_timezone |
|
| 312 | - ) |
|
| 313 | - ); |
|
| 314 | - } |
|
| 315 | - return $tickets; |
|
| 316 | - } |
|
| 288 | + /** |
|
| 289 | + * sets up relevant start and end date for EE_Ticket (s) |
|
| 290 | + * |
|
| 291 | + * @param EE_Ticket[] $tickets |
|
| 292 | + * @return EE_Ticket[] |
|
| 293 | + * @throws EE_Error |
|
| 294 | + */ |
|
| 295 | + private function _set_default_dates($tickets) |
|
| 296 | + { |
|
| 297 | + foreach ($tickets as $ticket) { |
|
| 298 | + $ticket->set( |
|
| 299 | + 'TKT_start_date', |
|
| 300 | + (int) $this->current_time_for_query('TKT_start_date', true) |
|
| 301 | + ); |
|
| 302 | + $ticket->set( |
|
| 303 | + 'TKT_end_date', |
|
| 304 | + (int) $this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
| 305 | + ); |
|
| 306 | + $ticket->set_end_time( |
|
| 307 | + $this->convert_datetime_for_query( |
|
| 308 | + 'TKT_end_date', |
|
| 309 | + '11:59 pm', |
|
| 310 | + 'g:i a', |
|
| 311 | + $this->_timezone |
|
| 312 | + ) |
|
| 313 | + ); |
|
| 314 | + } |
|
| 315 | + return $tickets; |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | 318 | |
| 319 | - /** |
|
| 320 | - * Gets the total number of tickets available at a particular datetime (does |
|
| 321 | - * NOT take int account the datetime's spaces available) |
|
| 322 | - * |
|
| 323 | - * @param int $DTT_ID |
|
| 324 | - * @param array $query_params |
|
| 325 | - * @return int |
|
| 326 | - */ |
|
| 327 | - public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()) |
|
| 328 | - { |
|
| 329 | - return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params); |
|
| 330 | - } |
|
| 319 | + /** |
|
| 320 | + * Gets the total number of tickets available at a particular datetime (does |
|
| 321 | + * NOT take int account the datetime's spaces available) |
|
| 322 | + * |
|
| 323 | + * @param int $DTT_ID |
|
| 324 | + * @param array $query_params |
|
| 325 | + * @return int |
|
| 326 | + */ |
|
| 327 | + public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()) |
|
| 328 | + { |
|
| 329 | + return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params); |
|
| 330 | + } |
|
| 331 | 331 | |
| 332 | 332 | |
| 333 | - /** |
|
| 334 | - * Updates the TKT_sold quantity on all the tickets matching $query_params |
|
| 335 | - * |
|
| 336 | - * @param EE_Ticket[] $tickets |
|
| 337 | - * @return void |
|
| 338 | - * @throws EE_Error |
|
| 339 | - */ |
|
| 340 | - public function update_tickets_sold($tickets) |
|
| 341 | - { |
|
| 342 | - foreach ($tickets as $ticket) { |
|
| 343 | - /* @var $ticket EE_Ticket */ |
|
| 344 | - $ticket->update_tickets_sold(); |
|
| 345 | - } |
|
| 346 | - } |
|
| 333 | + /** |
|
| 334 | + * Updates the TKT_sold quantity on all the tickets matching $query_params |
|
| 335 | + * |
|
| 336 | + * @param EE_Ticket[] $tickets |
|
| 337 | + * @return void |
|
| 338 | + * @throws EE_Error |
|
| 339 | + */ |
|
| 340 | + public function update_tickets_sold($tickets) |
|
| 341 | + { |
|
| 342 | + foreach ($tickets as $ticket) { |
|
| 343 | + /* @var $ticket EE_Ticket */ |
|
| 344 | + $ticket->update_tickets_sold(); |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | 347 | |
| 348 | 348 | |
| 349 | - /** |
|
| 350 | - * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved |
|
| 351 | - * |
|
| 352 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
| 353 | - * @throws EE_Error |
|
| 354 | - */ |
|
| 355 | - public function get_tickets_with_reservations() |
|
| 356 | - { |
|
| 357 | - return $this->get_all( |
|
| 358 | - array( |
|
| 359 | - array( |
|
| 360 | - 'TKT_reserved' => array('>', 0), |
|
| 361 | - ), |
|
| 362 | - ) |
|
| 363 | - ); |
|
| 364 | - } |
|
| 349 | + /** |
|
| 350 | + * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved |
|
| 351 | + * |
|
| 352 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
| 353 | + * @throws EE_Error |
|
| 354 | + */ |
|
| 355 | + public function get_tickets_with_reservations() |
|
| 356 | + { |
|
| 357 | + return $this->get_all( |
|
| 358 | + array( |
|
| 359 | + array( |
|
| 360 | + 'TKT_reserved' => array('>', 0), |
|
| 361 | + ), |
|
| 362 | + ) |
|
| 363 | + ); |
|
| 364 | + } |
|
| 365 | 365 | |
| 366 | 366 | |
| 367 | - /** |
|
| 368 | - * returns an array of EE_Ticket objects matching the supplied list of IDs |
|
| 369 | - * |
|
| 370 | - * @param array $ticket_IDs |
|
| 371 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
| 372 | - * @throws EE_Error |
|
| 373 | - */ |
|
| 374 | - public function get_tickets_with_IDs(array $ticket_IDs) |
|
| 375 | - { |
|
| 376 | - return $this->get_all( |
|
| 377 | - array( |
|
| 378 | - array( |
|
| 379 | - 'TKT_ID' => array('IN', $ticket_IDs), |
|
| 380 | - ), |
|
| 381 | - ) |
|
| 382 | - ); |
|
| 383 | - } |
|
| 367 | + /** |
|
| 368 | + * returns an array of EE_Ticket objects matching the supplied list of IDs |
|
| 369 | + * |
|
| 370 | + * @param array $ticket_IDs |
|
| 371 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
| 372 | + * @throws EE_Error |
|
| 373 | + */ |
|
| 374 | + public function get_tickets_with_IDs(array $ticket_IDs) |
|
| 375 | + { |
|
| 376 | + return $this->get_all( |
|
| 377 | + array( |
|
| 378 | + array( |
|
| 379 | + 'TKT_ID' => array('IN', $ticket_IDs), |
|
| 380 | + ), |
|
| 381 | + ) |
|
| 382 | + ); |
|
| 383 | + } |
|
| 384 | 384 | |
| 385 | 385 | |
| 386 | - /** |
|
| 387 | - * @return array |
|
| 388 | - */ |
|
| 389 | - public function ticketVisibility(): array |
|
| 390 | - { |
|
| 391 | - return $this->ticket_visibility; |
|
| 392 | - } |
|
| 386 | + /** |
|
| 387 | + * @return array |
|
| 388 | + */ |
|
| 389 | + public function ticketVisibility(): array |
|
| 390 | + { |
|
| 391 | + return $this->ticket_visibility; |
|
| 392 | + } |
|
| 393 | 393 | } |
@@ -14,1917 +14,1917 @@ |
||
| 14 | 14 | class EE_Ticket extends EE_Soft_Delete_Base_Class implements EEI_Line_Item_Object, EEI_Event_Relation, EEI_Has_Icon |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * TicKet Sold out: |
|
| 19 | - * constant used by ticket_status() to indicate that a ticket is sold out |
|
| 20 | - * and no longer available for purchases |
|
| 21 | - */ |
|
| 22 | - const sold_out = 'TKS'; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * TicKet Expired: |
|
| 26 | - * constant used by ticket_status() to indicate that a ticket is expired |
|
| 27 | - * and no longer available for purchase |
|
| 28 | - */ |
|
| 29 | - const expired = 'TKE'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * TicKet Archived: |
|
| 33 | - * constant used by ticket_status() to indicate that a ticket is archived |
|
| 34 | - * and no longer available for purchase |
|
| 35 | - */ |
|
| 36 | - const archived = 'TKA'; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * TicKet Pending: |
|
| 40 | - * constant used by ticket_status() to indicate that a ticket is pending |
|
| 41 | - * and is NOT YET available for purchase |
|
| 42 | - */ |
|
| 43 | - const pending = 'TKP'; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * TicKet On sale: |
|
| 47 | - * constant used by ticket_status() to indicate that a ticket is On Sale |
|
| 48 | - * and IS available for purchase |
|
| 49 | - */ |
|
| 50 | - const onsale = 'TKO'; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * extra meta key for tracking ticket reservations |
|
| 54 | - * |
|
| 55 | - * @type string |
|
| 56 | - */ |
|
| 57 | - const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations'; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * cached result from method of the same name |
|
| 61 | - * |
|
| 62 | - * @var float $_ticket_total_with_taxes |
|
| 63 | - */ |
|
| 64 | - private $_ticket_total_with_taxes; |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @param array $props_n_values incoming values |
|
| 69 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 70 | - * used.) |
|
| 71 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 72 | - * date_format and the second value is the time format |
|
| 73 | - * @return EE_Ticket |
|
| 74 | - * @throws EE_Error |
|
| 75 | - * @throws ReflectionException |
|
| 76 | - */ |
|
| 77 | - public static function new_instance($props_n_values = [], $timezone = null, $date_formats = []) |
|
| 78 | - { |
|
| 79 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 80 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @param array $props_n_values incoming values from the database |
|
| 86 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 87 | - * the website will be used. |
|
| 88 | - * @return EE_Ticket |
|
| 89 | - * @throws EE_Error |
|
| 90 | - * @throws ReflectionException |
|
| 91 | - */ |
|
| 92 | - public static function new_instance_from_db($props_n_values = [], $timezone = null) |
|
| 93 | - { |
|
| 94 | - return new self($props_n_values, true, $timezone); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @return bool |
|
| 100 | - * @throws EE_Error |
|
| 101 | - * @throws ReflectionException |
|
| 102 | - */ |
|
| 103 | - public function parent() |
|
| 104 | - { |
|
| 105 | - return $this->get('TKT_parent'); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * return if a ticket has quantities available for purchase |
|
| 111 | - * |
|
| 112 | - * @param int $DTT_ID the primary key for a particular datetime |
|
| 113 | - * @return boolean |
|
| 114 | - * @throws EE_Error |
|
| 115 | - * @throws ReflectionException |
|
| 116 | - */ |
|
| 117 | - public function available($DTT_ID = 0) |
|
| 118 | - { |
|
| 119 | - // are we checking availability for a particular datetime ? |
|
| 120 | - if ($DTT_ID) { |
|
| 121 | - // get that datetime object |
|
| 122 | - $datetime = $this->get_first_related('Datetime', [['DTT_ID' => $DTT_ID]]); |
|
| 123 | - // if ticket sales for this datetime have exceeded the reg limit... |
|
| 124 | - if ($datetime instanceof EE_Datetime && $datetime->sold_out()) { |
|
| 125 | - return false; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - // datetime is still open for registration, but is this ticket sold out ? |
|
| 129 | - return $this->qty() < 1 || $this->qty() > $this->sold(); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
|
| 135 | - * |
|
| 136 | - * @param bool $display true = we'll return a localized string, otherwise we just return the value of the |
|
| 137 | - * relevant status const |
|
| 138 | - * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save |
|
| 139 | - * further processing |
|
| 140 | - * @return mixed status int if the display string isn't requested |
|
| 141 | - * @throws EE_Error |
|
| 142 | - * @throws ReflectionException |
|
| 143 | - */ |
|
| 144 | - public function ticket_status($display = false, $remaining = null) |
|
| 145 | - { |
|
| 146 | - $remaining = is_bool($remaining) ? $remaining : $this->is_remaining(); |
|
| 147 | - if (! $remaining) { |
|
| 148 | - return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out; |
|
| 149 | - } |
|
| 150 | - if ($this->get('TKT_deleted')) { |
|
| 151 | - return $display ? EEH_Template::pretty_status(EE_Ticket::archived, false, 'sentence') : EE_Ticket::archived; |
|
| 152 | - } |
|
| 153 | - if ($this->is_expired()) { |
|
| 154 | - return $display ? EEH_Template::pretty_status(EE_Ticket::expired, false, 'sentence') : EE_Ticket::expired; |
|
| 155 | - } |
|
| 156 | - if ($this->is_pending()) { |
|
| 157 | - return $display ? EEH_Template::pretty_status(EE_Ticket::pending, false, 'sentence') : EE_Ticket::pending; |
|
| 158 | - } |
|
| 159 | - if ($this->is_on_sale()) { |
|
| 160 | - return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence') : EE_Ticket::onsale; |
|
| 161 | - } |
|
| 162 | - return ''; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale |
|
| 168 | - * considering ALL the factors used for figuring that out. |
|
| 169 | - * |
|
| 170 | - * @access public |
|
| 171 | - * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
|
| 172 | - * @return boolean true = tickets remaining, false not. |
|
| 173 | - * @throws EE_Error |
|
| 174 | - * @throws ReflectionException |
|
| 175 | - */ |
|
| 176 | - public function is_remaining($DTT_ID = 0) |
|
| 177 | - { |
|
| 178 | - $num_remaining = $this->remaining($DTT_ID); |
|
| 179 | - if ($num_remaining === 0) { |
|
| 180 | - return false; |
|
| 181 | - } |
|
| 182 | - if ($num_remaining > 0 && $num_remaining < $this->min()) { |
|
| 183 | - return false; |
|
| 184 | - } |
|
| 185 | - return true; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * return the total number of tickets available for purchase |
|
| 191 | - * |
|
| 192 | - * @param int $DTT_ID the primary key for a particular datetime. |
|
| 193 | - * set to 0 for all related datetimes |
|
| 194 | - * @return int |
|
| 195 | - * @throws EE_Error |
|
| 196 | - * @throws ReflectionException |
|
| 197 | - */ |
|
| 198 | - public function remaining($DTT_ID = 0) |
|
| 199 | - { |
|
| 200 | - return $this->real_quantity_on_ticket('saleable', $DTT_ID); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Gets min |
|
| 206 | - * |
|
| 207 | - * @return int |
|
| 208 | - * @throws EE_Error |
|
| 209 | - * @throws ReflectionException |
|
| 210 | - */ |
|
| 211 | - public function min() |
|
| 212 | - { |
|
| 213 | - return $this->get('TKT_min'); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * return if a ticket is no longer available cause its available dates have expired. |
|
| 219 | - * |
|
| 220 | - * @return boolean |
|
| 221 | - * @throws EE_Error |
|
| 222 | - * @throws ReflectionException |
|
| 223 | - */ |
|
| 224 | - public function is_expired() |
|
| 225 | - { |
|
| 226 | - return ($this->get_raw('TKT_end_date') < time()); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * Return if a ticket is yet to go on sale or not |
|
| 232 | - * |
|
| 233 | - * @return boolean |
|
| 234 | - * @throws EE_Error |
|
| 235 | - * @throws ReflectionException |
|
| 236 | - */ |
|
| 237 | - public function is_pending() |
|
| 238 | - { |
|
| 239 | - return ($this->get_raw('TKT_start_date') >= time()); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Return if a ticket is on sale or not |
|
| 245 | - * |
|
| 246 | - * @return boolean |
|
| 247 | - * @throws EE_Error |
|
| 248 | - * @throws ReflectionException |
|
| 249 | - */ |
|
| 250 | - public function is_on_sale() |
|
| 251 | - { |
|
| 252 | - return ($this->get_raw('TKT_start_date') <= time() && $this->get_raw('TKT_end_date') >= time()); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * This returns the chronologically last datetime that this ticket is associated with |
|
| 258 | - * |
|
| 259 | - * @param string $date_format |
|
| 260 | - * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with |
|
| 261 | - * the end date ie: Jan 01 "to" Dec 31 |
|
| 262 | - * @return string |
|
| 263 | - * @throws EE_Error |
|
| 264 | - * @throws ReflectionException |
|
| 265 | - */ |
|
| 266 | - public function date_range($date_format = '', $conjunction = ' - ') |
|
| 267 | - { |
|
| 268 | - $date_format = ! empty($date_format) ? $date_format : $this->_dt_frmt; |
|
| 269 | - $first_date = $this->first_datetime() instanceof EE_Datetime |
|
| 270 | - ? $this->first_datetime()->get_i18n_datetime('DTT_EVT_start', $date_format) |
|
| 271 | - : ''; |
|
| 272 | - $last_date = $this->last_datetime() instanceof EE_Datetime |
|
| 273 | - ? $this->last_datetime()->get_i18n_datetime('DTT_EVT_end', $date_format) |
|
| 274 | - : ''; |
|
| 275 | - |
|
| 276 | - return $first_date && $last_date ? $first_date . $conjunction . $last_date : ''; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * This returns the chronologically first datetime that this ticket is associated with |
|
| 282 | - * |
|
| 283 | - * @return EE_Datetime |
|
| 284 | - * @throws EE_Error |
|
| 285 | - * @throws ReflectionException |
|
| 286 | - */ |
|
| 287 | - public function first_datetime() |
|
| 288 | - { |
|
| 289 | - $datetimes = $this->datetimes(['limit' => 1]); |
|
| 290 | - return reset($datetimes); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * Gets all the datetimes this ticket can be used for attending. |
|
| 296 | - * Unless otherwise specified, orders datetimes by start date. |
|
| 297 | - * |
|
| 298 | - * @param array $query_params @see |
|
| 299 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 300 | - * @return EE_Datetime[]|EE_Base_Class[] |
|
| 301 | - * @throws EE_Error |
|
| 302 | - * @throws ReflectionException |
|
| 303 | - */ |
|
| 304 | - public function datetimes($query_params = []) |
|
| 305 | - { |
|
| 306 | - if (! isset($query_params['order_by'])) { |
|
| 307 | - $query_params['order_by']['DTT_order'] = 'ASC'; |
|
| 308 | - } |
|
| 309 | - return $this->get_many_related('Datetime', $query_params); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * This returns the chronologically last datetime that this ticket is associated with |
|
| 315 | - * |
|
| 316 | - * @return EE_Datetime |
|
| 317 | - * @throws EE_Error |
|
| 318 | - * @throws ReflectionException |
|
| 319 | - */ |
|
| 320 | - public function last_datetime() |
|
| 321 | - { |
|
| 322 | - $datetimes = $this->datetimes(['limit' => 1, 'order_by' => ['DTT_EVT_start' => 'DESC']]); |
|
| 323 | - return end($datetimes); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * This returns the total tickets sold depending on the given parameters. |
|
| 329 | - * |
|
| 330 | - * @param string $what Can be one of two options: 'ticket', 'datetime'. |
|
| 331 | - * 'ticket' = total ticket sales for all datetimes this ticket is related to |
|
| 332 | - * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
|
| 333 | - * 'datetime' = total ticket sales in the datetime_ticket table. |
|
| 334 | - * If $dtt_id is not given then we return an array of sales indexed by datetime. |
|
| 335 | - * If $dtt_id IS given then we return the tickets sold for that given datetime. |
|
| 336 | - * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
|
| 337 | - * @return mixed (array|int) how many tickets have sold |
|
| 338 | - * @throws EE_Error |
|
| 339 | - * @throws ReflectionException |
|
| 340 | - */ |
|
| 341 | - public function tickets_sold($what = 'ticket', $dtt_id = null) |
|
| 342 | - { |
|
| 343 | - $total = 0; |
|
| 344 | - $tickets_sold = $this->_all_tickets_sold(); |
|
| 345 | - switch ($what) { |
|
| 346 | - case 'ticket': |
|
| 347 | - return $tickets_sold['ticket']; |
|
| 348 | - break; |
|
| 349 | - case 'datetime': |
|
| 350 | - if (empty($tickets_sold['datetime'])) { |
|
| 351 | - return $total; |
|
| 352 | - } |
|
| 353 | - if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) { |
|
| 354 | - EE_Error::add_error( |
|
| 355 | - __( |
|
| 356 | - 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?', |
|
| 357 | - 'event_espresso' |
|
| 358 | - ), |
|
| 359 | - __FILE__, |
|
| 360 | - __FUNCTION__, |
|
| 361 | - __LINE__ |
|
| 362 | - ); |
|
| 363 | - return $total; |
|
| 364 | - } |
|
| 365 | - return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ]; |
|
| 366 | - break; |
|
| 367 | - default: |
|
| 368 | - return $total; |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * This returns an array indexed by datetime_id for tickets sold with this ticket. |
|
| 375 | - * |
|
| 376 | - * @return EE_Ticket[] |
|
| 377 | - * @throws EE_Error |
|
| 378 | - * @throws ReflectionException |
|
| 379 | - */ |
|
| 380 | - protected function _all_tickets_sold() |
|
| 381 | - { |
|
| 382 | - $datetimes = $this->get_many_related('Datetime'); |
|
| 383 | - $tickets_sold = []; |
|
| 384 | - if (! empty($datetimes)) { |
|
| 385 | - foreach ($datetimes as $datetime) { |
|
| 386 | - $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold'); |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - // Tickets sold |
|
| 390 | - $tickets_sold['ticket'] = $this->sold(); |
|
| 391 | - return $tickets_sold; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * This returns the base price object for the ticket. |
|
| 397 | - * |
|
| 398 | - * @param bool $return_array whether to return as an array indexed by price id or just the object. |
|
| 399 | - * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
|
| 400 | - * @throws EE_Error |
|
| 401 | - * @throws ReflectionException |
|
| 402 | - */ |
|
| 403 | - public function base_price($return_array = false) |
|
| 404 | - { |
|
| 405 | - $_where = ['Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price]; |
|
| 406 | - return $return_array |
|
| 407 | - ? $this->get_many_related('Price', [$_where]) |
|
| 408 | - : $this->get_first_related('Price', [$_where]); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
| 414 | - * |
|
| 415 | - * @access public |
|
| 416 | - * @return EE_Price[] |
|
| 417 | - * @throws EE_Error |
|
| 418 | - * @throws ReflectionException |
|
| 419 | - */ |
|
| 420 | - public function price_modifiers() |
|
| 421 | - { |
|
| 422 | - $query_params = [ |
|
| 423 | - 0 => [ |
|
| 424 | - 'Price_Type.PBT_ID' => [ |
|
| 425 | - 'NOT IN', |
|
| 426 | - [EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax], |
|
| 427 | - ], |
|
| 428 | - ], |
|
| 429 | - ]; |
|
| 430 | - return $this->prices($query_params); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
| 436 | - * |
|
| 437 | - * @access public |
|
| 438 | - * @return EE_Price[] |
|
| 439 | - * @throws EE_Error |
|
| 440 | - * @throws ReflectionException |
|
| 441 | - */ |
|
| 442 | - public function tax_price_modifiers() |
|
| 443 | - { |
|
| 444 | - $query_params = [ |
|
| 445 | - 0 => [ |
|
| 446 | - 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax, |
|
| 447 | - ], |
|
| 448 | - ]; |
|
| 449 | - return $this->prices($query_params); |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * Gets all the prices that combine to form the final price of this ticket |
|
| 455 | - * |
|
| 456 | - * @param array $query_params @see |
|
| 457 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 458 | - * @return EE_Price[]|EE_Base_Class[] |
|
| 459 | - * @throws EE_Error |
|
| 460 | - * @throws ReflectionException |
|
| 461 | - */ |
|
| 462 | - public function prices($query_params = []) |
|
| 463 | - { |
|
| 464 | - return $this->get_many_related('Price', $query_params); |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * Gets all the ticket datetimes (ie, relations between datetimes and tickets) |
|
| 470 | - * |
|
| 471 | - * @param array $query_params @see |
|
| 472 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 473 | - * @return EE_Datetime_Ticket|EE_Base_Class[] |
|
| 474 | - * @throws EE_Error |
|
| 475 | - * @throws ReflectionException |
|
| 476 | - */ |
|
| 477 | - public function datetime_tickets($query_params = []) |
|
| 478 | - { |
|
| 479 | - return $this->get_many_related('Datetime_Ticket', $query_params); |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * Gets all the datetimes from the db ordered by DTT_order |
|
| 485 | - * |
|
| 486 | - * @param boolean $show_expired |
|
| 487 | - * @param boolean $show_deleted |
|
| 488 | - * @return EE_Datetime[] |
|
| 489 | - * @throws EE_Error |
|
| 490 | - * @throws ReflectionException |
|
| 491 | - */ |
|
| 492 | - public function datetimes_ordered($show_expired = true, $show_deleted = false) |
|
| 493 | - { |
|
| 494 | - return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order( |
|
| 495 | - $this->ID(), |
|
| 496 | - $show_expired, |
|
| 497 | - $show_deleted |
|
| 498 | - ); |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * Gets ID |
|
| 504 | - * |
|
| 505 | - * @return string |
|
| 506 | - * @throws EE_Error |
|
| 507 | - * @throws ReflectionException |
|
| 508 | - */ |
|
| 509 | - public function ID() |
|
| 510 | - { |
|
| 511 | - return $this->get('TKT_ID'); |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * get the author of the ticket. |
|
| 517 | - * |
|
| 518 | - * @return int |
|
| 519 | - * @throws EE_Error |
|
| 520 | - * @throws ReflectionException |
|
| 521 | - * @since 4.5.0 |
|
| 522 | - */ |
|
| 523 | - public function wp_user() |
|
| 524 | - { |
|
| 525 | - return $this->get('TKT_wp_user'); |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * Gets the template for the ticket |
|
| 531 | - * |
|
| 532 | - * @return EE_Ticket_Template|EE_Base_Class |
|
| 533 | - * @throws EE_Error |
|
| 534 | - * @throws ReflectionException |
|
| 535 | - */ |
|
| 536 | - public function template() |
|
| 537 | - { |
|
| 538 | - return $this->get_first_related('Ticket_Template'); |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * Simply returns an array of EE_Price objects that are taxes. |
|
| 544 | - * |
|
| 545 | - * @return EE_Price[] |
|
| 546 | - * @throws EE_Error |
|
| 547 | - */ |
|
| 548 | - public function get_ticket_taxes_for_admin() |
|
| 549 | - { |
|
| 550 | - return EE_Taxes::get_taxes_for_admin(); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * @return float |
|
| 556 | - * @throws EE_Error |
|
| 557 | - * @throws ReflectionException |
|
| 558 | - */ |
|
| 559 | - public function ticket_price() |
|
| 560 | - { |
|
| 561 | - return $this->get('TKT_price'); |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * @return mixed |
|
| 567 | - * @throws EE_Error |
|
| 568 | - * @throws ReflectionException |
|
| 569 | - */ |
|
| 570 | - public function pretty_price() |
|
| 571 | - { |
|
| 572 | - return $this->get_pretty('TKT_price'); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - |
|
| 576 | - /** |
|
| 577 | - * @return bool |
|
| 578 | - * @throws EE_Error |
|
| 579 | - * @throws ReflectionException |
|
| 580 | - */ |
|
| 581 | - public function is_free() |
|
| 582 | - { |
|
| 583 | - return $this->get_ticket_total_with_taxes() === (float) 0; |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * get_ticket_total_with_taxes |
|
| 589 | - * |
|
| 590 | - * @param bool $no_cache |
|
| 591 | - * @return float |
|
| 592 | - * @throws EE_Error |
|
| 593 | - * @throws ReflectionException |
|
| 594 | - */ |
|
| 595 | - public function get_ticket_total_with_taxes($no_cache = false) |
|
| 596 | - { |
|
| 597 | - if ($this->_ticket_total_with_taxes === null || $no_cache) { |
|
| 598 | - $this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin(); |
|
| 599 | - } |
|
| 600 | - return (float) $this->_ticket_total_with_taxes; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * @throws EE_Error |
|
| 606 | - * @throws ReflectionException |
|
| 607 | - */ |
|
| 608 | - public function ensure_TKT_Price_correct() |
|
| 609 | - { |
|
| 610 | - $this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this)); |
|
| 611 | - $this->save(); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * @return float |
|
| 617 | - * @throws EE_Error |
|
| 618 | - * @throws ReflectionException |
|
| 619 | - */ |
|
| 620 | - public function get_ticket_subtotal() |
|
| 621 | - { |
|
| 622 | - return EE_Taxes::get_subtotal_for_admin($this); |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * Returns the total taxes applied to this ticket |
|
| 628 | - * |
|
| 629 | - * @return float |
|
| 630 | - * @throws EE_Error |
|
| 631 | - * @throws ReflectionException |
|
| 632 | - */ |
|
| 633 | - public function get_ticket_taxes_total_for_admin() |
|
| 634 | - { |
|
| 635 | - return EE_Taxes::get_total_taxes_for_admin($this); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - /** |
|
| 640 | - * Sets name |
|
| 641 | - * |
|
| 642 | - * @param string $name |
|
| 643 | - * @throws EE_Error |
|
| 644 | - * @throws ReflectionException |
|
| 645 | - */ |
|
| 646 | - public function set_name($name) |
|
| 647 | - { |
|
| 648 | - $this->set('TKT_name', $name); |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - |
|
| 652 | - /** |
|
| 653 | - * Gets description |
|
| 654 | - * |
|
| 655 | - * @return string |
|
| 656 | - * @throws EE_Error |
|
| 657 | - * @throws ReflectionException |
|
| 658 | - */ |
|
| 659 | - public function description() |
|
| 660 | - { |
|
| 661 | - return $this->get('TKT_description'); |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - |
|
| 665 | - /** |
|
| 666 | - * Sets description |
|
| 667 | - * |
|
| 668 | - * @param string $description |
|
| 669 | - * @throws EE_Error |
|
| 670 | - * @throws ReflectionException |
|
| 671 | - */ |
|
| 672 | - public function set_description($description) |
|
| 673 | - { |
|
| 674 | - $this->set('TKT_description', $description); |
|
| 675 | - } |
|
| 676 | - |
|
| 677 | - |
|
| 678 | - /** |
|
| 679 | - * Gets start_date |
|
| 680 | - * |
|
| 681 | - * @param string $date_format |
|
| 682 | - * @param string $time_format |
|
| 683 | - * @return string |
|
| 684 | - * @throws EE_Error |
|
| 685 | - * @throws ReflectionException |
|
| 686 | - */ |
|
| 687 | - public function start_date($date_format = '', $time_format = '') |
|
| 688 | - { |
|
| 689 | - return $this->_get_datetime('TKT_start_date', $date_format, $time_format); |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - /** |
|
| 694 | - * Sets start_date |
|
| 695 | - * |
|
| 696 | - * @param string $start_date |
|
| 697 | - * @return void |
|
| 698 | - * @throws EE_Error |
|
| 699 | - * @throws ReflectionException |
|
| 700 | - */ |
|
| 701 | - public function set_start_date($start_date) |
|
| 702 | - { |
|
| 703 | - $this->_set_date_time('B', $start_date, 'TKT_start_date'); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - |
|
| 707 | - /** |
|
| 708 | - * Gets end_date |
|
| 709 | - * |
|
| 710 | - * @param string $date_format |
|
| 711 | - * @param string $time_format |
|
| 712 | - * @return string |
|
| 713 | - * @throws EE_Error |
|
| 714 | - * @throws ReflectionException |
|
| 715 | - */ |
|
| 716 | - public function end_date($date_format = '', $time_format = '') |
|
| 717 | - { |
|
| 718 | - return $this->_get_datetime('TKT_end_date', $date_format, $time_format); |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - |
|
| 722 | - /** |
|
| 723 | - * Sets end_date |
|
| 724 | - * |
|
| 725 | - * @param string $end_date |
|
| 726 | - * @return void |
|
| 727 | - * @throws EE_Error |
|
| 728 | - * @throws ReflectionException |
|
| 729 | - */ |
|
| 730 | - public function set_end_date($end_date) |
|
| 731 | - { |
|
| 732 | - $this->_set_date_time('B', $end_date, 'TKT_end_date'); |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - |
|
| 736 | - /** |
|
| 737 | - * Sets sell until time |
|
| 738 | - * |
|
| 739 | - * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
|
| 740 | - * @throws EE_Error |
|
| 741 | - * @throws ReflectionException |
|
| 742 | - * @since 4.5.0 |
|
| 743 | - */ |
|
| 744 | - public function set_end_time($time) |
|
| 745 | - { |
|
| 746 | - $this->_set_time_for($time, 'TKT_end_date'); |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * Sets min |
|
| 752 | - * |
|
| 753 | - * @param int $min |
|
| 754 | - * @return void |
|
| 755 | - * @throws EE_Error |
|
| 756 | - * @throws ReflectionException |
|
| 757 | - */ |
|
| 758 | - public function set_min($min) |
|
| 759 | - { |
|
| 760 | - $this->set('TKT_min', $min); |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - |
|
| 764 | - /** |
|
| 765 | - * Gets max |
|
| 766 | - * |
|
| 767 | - * @return int |
|
| 768 | - * @throws EE_Error |
|
| 769 | - * @throws ReflectionException |
|
| 770 | - */ |
|
| 771 | - public function max() |
|
| 772 | - { |
|
| 773 | - return $this->get('TKT_max'); |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - |
|
| 777 | - /** |
|
| 778 | - * Sets max |
|
| 779 | - * |
|
| 780 | - * @param int $max |
|
| 781 | - * @return void |
|
| 782 | - * @throws EE_Error |
|
| 783 | - * @throws ReflectionException |
|
| 784 | - */ |
|
| 785 | - public function set_max($max) |
|
| 786 | - { |
|
| 787 | - $this->set('TKT_max', $max); |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - |
|
| 791 | - /** |
|
| 792 | - * Sets price |
|
| 793 | - * |
|
| 794 | - * @param float $price |
|
| 795 | - * @return void |
|
| 796 | - * @throws EE_Error |
|
| 797 | - * @throws ReflectionException |
|
| 798 | - */ |
|
| 799 | - public function set_price($price) |
|
| 800 | - { |
|
| 801 | - $this->set('TKT_price', $price); |
|
| 802 | - } |
|
| 803 | - |
|
| 804 | - |
|
| 805 | - /** |
|
| 806 | - * Gets sold |
|
| 807 | - * |
|
| 808 | - * @return int |
|
| 809 | - * @throws EE_Error |
|
| 810 | - * @throws ReflectionException |
|
| 811 | - */ |
|
| 812 | - public function sold() |
|
| 813 | - { |
|
| 814 | - return $this->get_raw('TKT_sold'); |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - |
|
| 818 | - /** |
|
| 819 | - * Sets sold |
|
| 820 | - * |
|
| 821 | - * @param int $sold |
|
| 822 | - * @return void |
|
| 823 | - * @throws EE_Error |
|
| 824 | - * @throws ReflectionException |
|
| 825 | - */ |
|
| 826 | - public function set_sold($sold) |
|
| 827 | - { |
|
| 828 | - // sold can not go below zero |
|
| 829 | - $sold = max(0, $sold); |
|
| 830 | - $this->set('TKT_sold', $sold); |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - |
|
| 834 | - /** |
|
| 835 | - * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
|
| 836 | - * associated datetimes. |
|
| 837 | - * |
|
| 838 | - * @param int $qty |
|
| 839 | - * @return boolean |
|
| 840 | - * @throws EE_Error |
|
| 841 | - * @throws InvalidArgumentException |
|
| 842 | - * @throws InvalidDataTypeException |
|
| 843 | - * @throws InvalidInterfaceException |
|
| 844 | - * @throws ReflectionException |
|
| 845 | - * @since 4.9.80.p |
|
| 846 | - */ |
|
| 847 | - public function increaseSold($qty = 1) |
|
| 848 | - { |
|
| 849 | - $qty = absint($qty); |
|
| 850 | - // increment sold and decrement reserved datetime quantities simultaneously |
|
| 851 | - // don't worry about failures, because they must have already had a spot reserved |
|
| 852 | - $this->increaseSoldForDatetimes($qty); |
|
| 853 | - // Increment and decrement ticket quantities simultaneously |
|
| 854 | - $success = $this->adjustNumericFieldsInDb( |
|
| 855 | - [ |
|
| 856 | - 'TKT_reserved' => $qty * -1, |
|
| 857 | - 'TKT_sold' => $qty, |
|
| 858 | - ] |
|
| 859 | - ); |
|
| 860 | - do_action( |
|
| 861 | - 'AHEE__EE_Ticket__increase_sold', |
|
| 862 | - $this, |
|
| 863 | - $qty, |
|
| 864 | - $this->sold(), |
|
| 865 | - $success |
|
| 866 | - ); |
|
| 867 | - return $success; |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - |
|
| 871 | - /** |
|
| 872 | - * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
|
| 873 | - * |
|
| 874 | - * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved |
|
| 875 | - * counts), Negative means to decreases old counts (and increase reserved counts). |
|
| 876 | - * @param EE_Datetime[] $datetimes |
|
| 877 | - * @throws EE_Error |
|
| 878 | - * @throws InvalidArgumentException |
|
| 879 | - * @throws InvalidDataTypeException |
|
| 880 | - * @throws InvalidInterfaceException |
|
| 881 | - * @throws ReflectionException |
|
| 882 | - * @since 4.9.80.p |
|
| 883 | - */ |
|
| 884 | - protected function increaseSoldForDatetimes($qty, array $datetimes = []) |
|
| 885 | - { |
|
| 886 | - $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 887 | - foreach ($datetimes as $datetime) { |
|
| 888 | - $datetime->increaseSold($qty); |
|
| 889 | - } |
|
| 890 | - } |
|
| 891 | - |
|
| 892 | - |
|
| 893 | - /** |
|
| 894 | - * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
|
| 895 | - * DB and then updates the model objects. |
|
| 896 | - * Does not affect the reserved counts. |
|
| 897 | - * |
|
| 898 | - * @param int $qty |
|
| 899 | - * @return boolean |
|
| 900 | - * @throws EE_Error |
|
| 901 | - * @throws InvalidArgumentException |
|
| 902 | - * @throws InvalidDataTypeException |
|
| 903 | - * @throws InvalidInterfaceException |
|
| 904 | - * @throws ReflectionException |
|
| 905 | - * @since 4.9.80.p |
|
| 906 | - */ |
|
| 907 | - public function decreaseSold($qty = 1) |
|
| 908 | - { |
|
| 909 | - $qty = absint($qty); |
|
| 910 | - $this->decreaseSoldForDatetimes($qty); |
|
| 911 | - $success = $this->adjustNumericFieldsInDb( |
|
| 912 | - [ |
|
| 913 | - 'TKT_sold' => $qty * -1, |
|
| 914 | - ] |
|
| 915 | - ); |
|
| 916 | - do_action( |
|
| 917 | - 'AHEE__EE_Ticket__decrease_sold', |
|
| 918 | - $this, |
|
| 919 | - $qty, |
|
| 920 | - $this->sold(), |
|
| 921 | - $success |
|
| 922 | - ); |
|
| 923 | - return $success; |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - |
|
| 927 | - /** |
|
| 928 | - * Decreases sold on related datetimes |
|
| 929 | - * |
|
| 930 | - * @param int $qty |
|
| 931 | - * @param EE_Datetime[] $datetimes |
|
| 932 | - * @return void |
|
| 933 | - * @throws EE_Error |
|
| 934 | - * @throws InvalidArgumentException |
|
| 935 | - * @throws InvalidDataTypeException |
|
| 936 | - * @throws InvalidInterfaceException |
|
| 937 | - * @throws ReflectionException |
|
| 938 | - * @since 4.9.80.p |
|
| 939 | - */ |
|
| 940 | - protected function decreaseSoldForDatetimes($qty = 1, array $datetimes = []) |
|
| 941 | - { |
|
| 942 | - $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 943 | - if (is_array($datetimes)) { |
|
| 944 | - foreach ($datetimes as $datetime) { |
|
| 945 | - if ($datetime instanceof EE_Datetime) { |
|
| 946 | - $datetime->decreaseSold($qty); |
|
| 947 | - } |
|
| 948 | - } |
|
| 949 | - } |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * Gets qty of reserved tickets |
|
| 955 | - * |
|
| 956 | - * @return int |
|
| 957 | - * @throws EE_Error |
|
| 958 | - * @throws ReflectionException |
|
| 959 | - */ |
|
| 960 | - public function reserved() |
|
| 961 | - { |
|
| 962 | - return $this->get_raw('TKT_reserved'); |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - |
|
| 966 | - /** |
|
| 967 | - * Sets reserved |
|
| 968 | - * |
|
| 969 | - * @param int $reserved |
|
| 970 | - * @return void |
|
| 971 | - * @throws EE_Error |
|
| 972 | - * @throws ReflectionException |
|
| 973 | - */ |
|
| 974 | - public function set_reserved($reserved) |
|
| 975 | - { |
|
| 976 | - // reserved can not go below zero |
|
| 977 | - $reserved = max(0, (int) $reserved); |
|
| 978 | - $this->set('TKT_reserved', $reserved); |
|
| 979 | - } |
|
| 980 | - |
|
| 981 | - |
|
| 982 | - /** |
|
| 983 | - * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 984 | - * |
|
| 985 | - * @param int $qty |
|
| 986 | - * @param string $source |
|
| 987 | - * @return bool whether we successfully reserved the ticket or not. |
|
| 988 | - * @throws EE_Error |
|
| 989 | - * @throws InvalidArgumentException |
|
| 990 | - * @throws ReflectionException |
|
| 991 | - * @throws InvalidDataTypeException |
|
| 992 | - * @throws InvalidInterfaceException |
|
| 993 | - * @since 4.9.80.p |
|
| 994 | - */ |
|
| 995 | - public function increaseReserved($qty = 1, $source = 'unknown') |
|
| 996 | - { |
|
| 997 | - $qty = absint($qty); |
|
| 998 | - do_action( |
|
| 999 | - 'AHEE__EE_Ticket__increase_reserved__begin', |
|
| 1000 | - $this, |
|
| 1001 | - $qty, |
|
| 1002 | - $source |
|
| 1003 | - ); |
|
| 1004 | - $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "{$qty} from {$source}"); |
|
| 1005 | - $success = false; |
|
| 1006 | - $datetimes_adjusted_successfully = $this->increaseReservedForDatetimes($qty); |
|
| 1007 | - if ($datetimes_adjusted_successfully) { |
|
| 1008 | - $success = $this->incrementFieldConditionallyInDb( |
|
| 1009 | - 'TKT_reserved', |
|
| 1010 | - 'TKT_sold', |
|
| 1011 | - 'TKT_qty', |
|
| 1012 | - $qty |
|
| 1013 | - ); |
|
| 1014 | - if (! $success) { |
|
| 1015 | - // The datetimes were successfully bumped, but not the |
|
| 1016 | - // ticket. So we need to manually rollback the datetimes. |
|
| 1017 | - $this->decreaseReservedForDatetimes($qty); |
|
| 1018 | - } |
|
| 1019 | - } |
|
| 1020 | - do_action( |
|
| 1021 | - 'AHEE__EE_Ticket__increase_reserved', |
|
| 1022 | - $this, |
|
| 1023 | - $qty, |
|
| 1024 | - $this->reserved(), |
|
| 1025 | - $success |
|
| 1026 | - ); |
|
| 1027 | - return $success; |
|
| 1028 | - } |
|
| 1029 | - |
|
| 1030 | - |
|
| 1031 | - /** |
|
| 1032 | - * Increases reserved counts on related datetimes |
|
| 1033 | - * |
|
| 1034 | - * @param int $qty |
|
| 1035 | - * @param EE_Datetime[] $datetimes |
|
| 1036 | - * @return boolean indicating success |
|
| 1037 | - * @throws EE_Error |
|
| 1038 | - * @throws InvalidArgumentException |
|
| 1039 | - * @throws InvalidDataTypeException |
|
| 1040 | - * @throws InvalidInterfaceException |
|
| 1041 | - * @throws ReflectionException |
|
| 1042 | - * @since 4.9.80.p |
|
| 1043 | - */ |
|
| 1044 | - protected function increaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
| 1045 | - { |
|
| 1046 | - $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 1047 | - $datetimes_updated = []; |
|
| 1048 | - $limit_exceeded = false; |
|
| 1049 | - if (is_array($datetimes)) { |
|
| 1050 | - foreach ($datetimes as $datetime) { |
|
| 1051 | - if ($datetime instanceof EE_Datetime) { |
|
| 1052 | - if ($datetime->increaseReserved($qty)) { |
|
| 1053 | - $datetimes_updated[] = $datetime; |
|
| 1054 | - } else { |
|
| 1055 | - $limit_exceeded = true; |
|
| 1056 | - break; |
|
| 1057 | - } |
|
| 1058 | - } |
|
| 1059 | - } |
|
| 1060 | - // If somewhere along the way we detected a datetime whose |
|
| 1061 | - // limit was exceeded, do a manual rollback. |
|
| 1062 | - if ($limit_exceeded) { |
|
| 1063 | - $this->decreaseReservedForDatetimes($qty, $datetimes_updated); |
|
| 1064 | - return false; |
|
| 1065 | - } |
|
| 1066 | - } |
|
| 1067 | - return true; |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - |
|
| 1071 | - /** |
|
| 1072 | - * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1073 | - * |
|
| 1074 | - * @param int $qty |
|
| 1075 | - * @param bool $adjust_datetimes |
|
| 1076 | - * @param string $source |
|
| 1077 | - * @return boolean |
|
| 1078 | - * @throws EE_Error |
|
| 1079 | - * @throws InvalidArgumentException |
|
| 1080 | - * @throws ReflectionException |
|
| 1081 | - * @throws InvalidDataTypeException |
|
| 1082 | - * @throws InvalidInterfaceException |
|
| 1083 | - * @since 4.9.80.p |
|
| 1084 | - */ |
|
| 1085 | - public function decreaseReserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
| 1086 | - { |
|
| 1087 | - $qty = absint($qty); |
|
| 1088 | - $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "-{$qty} from {$source}"); |
|
| 1089 | - if ($adjust_datetimes) { |
|
| 1090 | - $this->decreaseReservedForDatetimes($qty); |
|
| 1091 | - } |
|
| 1092 | - $success = $this->adjustNumericFieldsInDb( |
|
| 1093 | - [ |
|
| 1094 | - 'TKT_reserved' => $qty * -1, |
|
| 1095 | - ] |
|
| 1096 | - ); |
|
| 1097 | - do_action( |
|
| 1098 | - 'AHEE__EE_Ticket__decrease_reserved', |
|
| 1099 | - $this, |
|
| 1100 | - $qty, |
|
| 1101 | - $this->reserved(), |
|
| 1102 | - $success |
|
| 1103 | - ); |
|
| 1104 | - return $success; |
|
| 1105 | - } |
|
| 1106 | - |
|
| 1107 | - |
|
| 1108 | - /** |
|
| 1109 | - * Decreases the reserved count on the specified datetimes. |
|
| 1110 | - * |
|
| 1111 | - * @param int $qty |
|
| 1112 | - * @param EE_Datetime[] $datetimes |
|
| 1113 | - * @throws EE_Error |
|
| 1114 | - * @throws InvalidArgumentException |
|
| 1115 | - * @throws ReflectionException |
|
| 1116 | - * @throws InvalidDataTypeException |
|
| 1117 | - * @throws InvalidInterfaceException |
|
| 1118 | - * @since 4.9.80.p |
|
| 1119 | - */ |
|
| 1120 | - protected function decreaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
| 1121 | - { |
|
| 1122 | - $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 1123 | - foreach ($datetimes as $datetime) { |
|
| 1124 | - if ($datetime instanceof EE_Datetime) { |
|
| 1125 | - $datetime->decreaseReserved($qty); |
|
| 1126 | - } |
|
| 1127 | - } |
|
| 1128 | - } |
|
| 1129 | - |
|
| 1130 | - |
|
| 1131 | - /** |
|
| 1132 | - * Gets ticket quantity |
|
| 1133 | - * |
|
| 1134 | - * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 1135 | - * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
|
| 1136 | - * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
|
| 1137 | - * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 1138 | - * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 1139 | - * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 1140 | - * @return int |
|
| 1141 | - * @throws EE_Error |
|
| 1142 | - * @throws ReflectionException |
|
| 1143 | - */ |
|
| 1144 | - public function qty($context = '') |
|
| 1145 | - { |
|
| 1146 | - switch ($context) { |
|
| 1147 | - case 'reg_limit': |
|
| 1148 | - return $this->real_quantity_on_ticket(); |
|
| 1149 | - case 'saleable': |
|
| 1150 | - return $this->real_quantity_on_ticket('saleable'); |
|
| 1151 | - default: |
|
| 1152 | - return $this->get_raw('TKT_qty'); |
|
| 1153 | - } |
|
| 1154 | - } |
|
| 1155 | - |
|
| 1156 | - |
|
| 1157 | - /** |
|
| 1158 | - * Gets ticket quantity |
|
| 1159 | - * |
|
| 1160 | - * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 1161 | - * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
|
| 1162 | - * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 1163 | - * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 1164 | - * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 1165 | - * @param int $DTT_ID the primary key for a particular datetime. |
|
| 1166 | - * set to 0 for all related datetimes |
|
| 1167 | - * @return int |
|
| 1168 | - * @throws EE_Error |
|
| 1169 | - * @throws ReflectionException |
|
| 1170 | - */ |
|
| 1171 | - public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) |
|
| 1172 | - { |
|
| 1173 | - $raw = $this->get_raw('TKT_qty'); |
|
| 1174 | - // return immediately if it's zero |
|
| 1175 | - if ($raw === 0) { |
|
| 1176 | - return $raw; |
|
| 1177 | - } |
|
| 1178 | - // echo "\n\n<br />Ticket: " . $this->name() . '<br />'; |
|
| 1179 | - // ensure qty doesn't exceed raw value for THIS ticket |
|
| 1180 | - $qty = min(EE_INF, $raw); |
|
| 1181 | - // echo "\n . qty: " . $qty . '<br />'; |
|
| 1182 | - // calculate this ticket's total sales and reservations |
|
| 1183 | - $sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved(); |
|
| 1184 | - // echo "\n . sold: " . $this->sold() . '<br />'; |
|
| 1185 | - // echo "\n . reserved: " . $this->reserved() . '<br />'; |
|
| 1186 | - // echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />'; |
|
| 1187 | - // first we need to calculate the maximum number of tickets available for the datetime |
|
| 1188 | - // do we want data for one datetime or all of them ? |
|
| 1189 | - $query_params = $DTT_ID ? [['DTT_ID' => $DTT_ID]] : []; |
|
| 1190 | - $datetimes = $this->datetimes($query_params); |
|
| 1191 | - if (is_array($datetimes) && ! empty($datetimes)) { |
|
| 1192 | - foreach ($datetimes as $datetime) { |
|
| 1193 | - if ($datetime instanceof EE_Datetime) { |
|
| 1194 | - $datetime->refresh_from_db(); |
|
| 1195 | - // echo "\n . . datetime name: " . $datetime->name() . '<br />'; |
|
| 1196 | - // echo "\n . . datetime ID: " . $datetime->ID() . '<br />'; |
|
| 1197 | - // initialize with no restrictions for each datetime |
|
| 1198 | - // but adjust datetime qty based on datetime reg limit |
|
| 1199 | - $datetime_qty = min(EE_INF, $datetime->reg_limit()); |
|
| 1200 | - // echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />'; |
|
| 1201 | - // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1202 | - // if we want the actual saleable amount, then we need to consider OTHER ticket sales |
|
| 1203 | - // and reservations for this datetime, that do NOT include sales and reservations |
|
| 1204 | - // for this ticket (so we add $this->sold() and $this->reserved() back in) |
|
| 1205 | - if ($context === 'saleable') { |
|
| 1206 | - $datetime_qty = max( |
|
| 1207 | - $datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket, |
|
| 1208 | - 0 |
|
| 1209 | - ); |
|
| 1210 | - // echo "\n . . . datetime sold: " . $datetime->sold() . '<br />'; |
|
| 1211 | - // echo "\n . . . datetime reserved: " . $datetime->reserved() . '<br />'; |
|
| 1212 | - // echo "\n . . . datetime sold_and_reserved: " . $datetime->sold_and_reserved() . '<br />'; |
|
| 1213 | - // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1214 | - $datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0; |
|
| 1215 | - // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1216 | - } |
|
| 1217 | - $qty = min($datetime_qty, $qty); |
|
| 1218 | - // echo "\n . . qty: " . $qty . '<br />'; |
|
| 1219 | - } |
|
| 1220 | - } |
|
| 1221 | - } |
|
| 1222 | - // NOW that we know the maximum number of tickets available for the datetime |
|
| 1223 | - // we can finally factor in the details for this specific ticket |
|
| 1224 | - if ($qty > 0 && $context === 'saleable') { |
|
| 1225 | - // and subtract the sales for THIS ticket |
|
| 1226 | - $qty = max($qty - $sold_and_reserved_for_this_ticket, 0); |
|
| 1227 | - // echo "\n . qty: " . $qty . '<br />'; |
|
| 1228 | - } |
|
| 1229 | - // echo "\nFINAL QTY: " . $qty . "<br /><br />"; |
|
| 1230 | - return $qty; |
|
| 1231 | - } |
|
| 1232 | - |
|
| 1233 | - |
|
| 1234 | - /** |
|
| 1235 | - * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes |
|
| 1236 | - * |
|
| 1237 | - * @param int $qty |
|
| 1238 | - * @return void |
|
| 1239 | - * @throws EE_Error |
|
| 1240 | - * @throws ReflectionException |
|
| 1241 | - */ |
|
| 1242 | - public function set_qty($qty) |
|
| 1243 | - { |
|
| 1244 | - $datetimes = $this->datetimes(); |
|
| 1245 | - foreach ($datetimes as $datetime) { |
|
| 1246 | - if ($datetime instanceof EE_Datetime) { |
|
| 1247 | - $qty = min($qty, $datetime->reg_limit()); |
|
| 1248 | - } |
|
| 1249 | - } |
|
| 1250 | - $this->set('TKT_qty', $qty); |
|
| 1251 | - } |
|
| 1252 | - |
|
| 1253 | - |
|
| 1254 | - /** |
|
| 1255 | - * Gets uses |
|
| 1256 | - * |
|
| 1257 | - * @return int |
|
| 1258 | - * @throws EE_Error |
|
| 1259 | - * @throws ReflectionException |
|
| 1260 | - */ |
|
| 1261 | - public function uses() |
|
| 1262 | - { |
|
| 1263 | - return $this->get('TKT_uses'); |
|
| 1264 | - } |
|
| 1265 | - |
|
| 1266 | - |
|
| 1267 | - /** |
|
| 1268 | - * Sets uses |
|
| 1269 | - * |
|
| 1270 | - * @param int $uses |
|
| 1271 | - * @return void |
|
| 1272 | - * @throws EE_Error |
|
| 1273 | - * @throws ReflectionException |
|
| 1274 | - */ |
|
| 1275 | - public function set_uses($uses) |
|
| 1276 | - { |
|
| 1277 | - $this->set('TKT_uses', $uses); |
|
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - |
|
| 1281 | - /** |
|
| 1282 | - * returns whether ticket is required or not. |
|
| 1283 | - * |
|
| 1284 | - * @return boolean |
|
| 1285 | - * @throws EE_Error |
|
| 1286 | - * @throws ReflectionException |
|
| 1287 | - */ |
|
| 1288 | - public function required() |
|
| 1289 | - { |
|
| 1290 | - return $this->get('TKT_required'); |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - |
|
| 1294 | - /** |
|
| 1295 | - * sets the TKT_required property |
|
| 1296 | - * |
|
| 1297 | - * @param boolean $required |
|
| 1298 | - * @return void |
|
| 1299 | - * @throws EE_Error |
|
| 1300 | - * @throws ReflectionException |
|
| 1301 | - */ |
|
| 1302 | - public function set_required($required) |
|
| 1303 | - { |
|
| 1304 | - $this->set('TKT_required', $required); |
|
| 1305 | - } |
|
| 1306 | - |
|
| 1307 | - |
|
| 1308 | - /** |
|
| 1309 | - * Gets taxable |
|
| 1310 | - * |
|
| 1311 | - * @return boolean |
|
| 1312 | - * @throws EE_Error |
|
| 1313 | - * @throws ReflectionException |
|
| 1314 | - */ |
|
| 1315 | - public function taxable() |
|
| 1316 | - { |
|
| 1317 | - return $this->get('TKT_taxable'); |
|
| 1318 | - } |
|
| 1319 | - |
|
| 1320 | - |
|
| 1321 | - /** |
|
| 1322 | - * Sets taxable |
|
| 1323 | - * |
|
| 1324 | - * @param boolean $taxable |
|
| 1325 | - * @return void |
|
| 1326 | - * @throws EE_Error |
|
| 1327 | - * @throws ReflectionException |
|
| 1328 | - */ |
|
| 1329 | - public function set_taxable($taxable) |
|
| 1330 | - { |
|
| 1331 | - $this->set('TKT_taxable', $taxable); |
|
| 1332 | - } |
|
| 1333 | - |
|
| 1334 | - |
|
| 1335 | - /** |
|
| 1336 | - * Gets is_default |
|
| 1337 | - * |
|
| 1338 | - * @return boolean |
|
| 1339 | - * @throws EE_Error |
|
| 1340 | - * @throws ReflectionException |
|
| 1341 | - */ |
|
| 1342 | - public function is_default() |
|
| 1343 | - { |
|
| 1344 | - return $this->get('TKT_is_default'); |
|
| 1345 | - } |
|
| 1346 | - |
|
| 1347 | - |
|
| 1348 | - /** |
|
| 1349 | - * Sets is_default |
|
| 1350 | - * |
|
| 1351 | - * @param boolean $is_default |
|
| 1352 | - * @return void |
|
| 1353 | - * @throws EE_Error |
|
| 1354 | - * @throws ReflectionException |
|
| 1355 | - */ |
|
| 1356 | - public function set_is_default($is_default) |
|
| 1357 | - { |
|
| 1358 | - $this->set('TKT_is_default', $is_default); |
|
| 1359 | - } |
|
| 1360 | - |
|
| 1361 | - |
|
| 1362 | - /** |
|
| 1363 | - * Gets order |
|
| 1364 | - * |
|
| 1365 | - * @return int |
|
| 1366 | - * @throws EE_Error |
|
| 1367 | - * @throws ReflectionException |
|
| 1368 | - */ |
|
| 1369 | - public function order() |
|
| 1370 | - { |
|
| 1371 | - return $this->get('TKT_order'); |
|
| 1372 | - } |
|
| 1373 | - |
|
| 1374 | - |
|
| 1375 | - /** |
|
| 1376 | - * Sets order |
|
| 1377 | - * |
|
| 1378 | - * @param int $order |
|
| 1379 | - * @return void |
|
| 1380 | - * @throws EE_Error |
|
| 1381 | - * @throws ReflectionException |
|
| 1382 | - */ |
|
| 1383 | - public function set_order($order) |
|
| 1384 | - { |
|
| 1385 | - $this->set('TKT_order', $order); |
|
| 1386 | - } |
|
| 1387 | - |
|
| 1388 | - |
|
| 1389 | - /** |
|
| 1390 | - * Gets row |
|
| 1391 | - * |
|
| 1392 | - * @return int |
|
| 1393 | - * @throws EE_Error |
|
| 1394 | - * @throws ReflectionException |
|
| 1395 | - */ |
|
| 1396 | - public function row() |
|
| 1397 | - { |
|
| 1398 | - return $this->get('TKT_row'); |
|
| 1399 | - } |
|
| 1400 | - |
|
| 1401 | - |
|
| 1402 | - /** |
|
| 1403 | - * Sets row |
|
| 1404 | - * |
|
| 1405 | - * @param int $row |
|
| 1406 | - * @return void |
|
| 1407 | - * @throws EE_Error |
|
| 1408 | - * @throws ReflectionException |
|
| 1409 | - */ |
|
| 1410 | - public function set_row($row) |
|
| 1411 | - { |
|
| 1412 | - $this->set('TKT_row', $row); |
|
| 1413 | - } |
|
| 1414 | - |
|
| 1415 | - |
|
| 1416 | - /** |
|
| 1417 | - * Gets deleted |
|
| 1418 | - * |
|
| 1419 | - * @return boolean |
|
| 1420 | - * @throws EE_Error |
|
| 1421 | - * @throws ReflectionException |
|
| 1422 | - */ |
|
| 1423 | - public function deleted() |
|
| 1424 | - { |
|
| 1425 | - return $this->get('TKT_deleted'); |
|
| 1426 | - } |
|
| 1427 | - |
|
| 1428 | - |
|
| 1429 | - /** |
|
| 1430 | - * Sets deleted |
|
| 1431 | - * |
|
| 1432 | - * @param boolean $deleted |
|
| 1433 | - * @return void |
|
| 1434 | - * @throws EE_Error |
|
| 1435 | - * @throws ReflectionException |
|
| 1436 | - */ |
|
| 1437 | - public function set_deleted($deleted) |
|
| 1438 | - { |
|
| 1439 | - $this->set('TKT_deleted', $deleted); |
|
| 1440 | - } |
|
| 1441 | - |
|
| 1442 | - |
|
| 1443 | - /** |
|
| 1444 | - * Gets parent |
|
| 1445 | - * |
|
| 1446 | - * @return int |
|
| 1447 | - * @throws EE_Error |
|
| 1448 | - * @throws ReflectionException |
|
| 1449 | - */ |
|
| 1450 | - public function parent_ID() |
|
| 1451 | - { |
|
| 1452 | - return $this->get('TKT_parent'); |
|
| 1453 | - } |
|
| 1454 | - |
|
| 1455 | - |
|
| 1456 | - /** |
|
| 1457 | - * Sets parent |
|
| 1458 | - * |
|
| 1459 | - * @param int $parent |
|
| 1460 | - * @return void |
|
| 1461 | - * @throws EE_Error |
|
| 1462 | - * @throws ReflectionException |
|
| 1463 | - */ |
|
| 1464 | - public function set_parent_ID($parent) |
|
| 1465 | - { |
|
| 1466 | - $this->set('TKT_parent', $parent); |
|
| 1467 | - } |
|
| 1468 | - |
|
| 1469 | - |
|
| 1470 | - /** |
|
| 1471 | - * @return boolean |
|
| 1472 | - * @throws EE_Error |
|
| 1473 | - * @throws InvalidArgumentException |
|
| 1474 | - * @throws InvalidDataTypeException |
|
| 1475 | - * @throws InvalidInterfaceException |
|
| 1476 | - * @throws ReflectionException |
|
| 1477 | - */ |
|
| 1478 | - public function reverse_calculate() |
|
| 1479 | - { |
|
| 1480 | - return $this->get('TKT_reverse_calculate'); |
|
| 1481 | - } |
|
| 1482 | - |
|
| 1483 | - |
|
| 1484 | - /** |
|
| 1485 | - * @param boolean $reverse_calculate |
|
| 1486 | - * @throws EE_Error |
|
| 1487 | - * @throws InvalidArgumentException |
|
| 1488 | - * @throws InvalidDataTypeException |
|
| 1489 | - * @throws InvalidInterfaceException |
|
| 1490 | - * @throws ReflectionException |
|
| 1491 | - */ |
|
| 1492 | - public function set_reverse_calculate($reverse_calculate) |
|
| 1493 | - { |
|
| 1494 | - $this->set('TKT_reverse_calculate', $reverse_calculate); |
|
| 1495 | - } |
|
| 1496 | - |
|
| 1497 | - |
|
| 1498 | - /** |
|
| 1499 | - * Gets a string which is handy for showing in gateways etc that describes the ticket. |
|
| 1500 | - * |
|
| 1501 | - * @return string |
|
| 1502 | - * @throws EE_Error |
|
| 1503 | - * @throws ReflectionException |
|
| 1504 | - */ |
|
| 1505 | - public function name_and_info() |
|
| 1506 | - { |
|
| 1507 | - $times = []; |
|
| 1508 | - foreach ($this->datetimes() as $datetime) { |
|
| 1509 | - $times[] = $datetime->start_date_and_time(); |
|
| 1510 | - } |
|
| 1511 | - return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price(); |
|
| 1512 | - } |
|
| 1513 | - |
|
| 1514 | - |
|
| 1515 | - /** |
|
| 1516 | - * Gets name |
|
| 1517 | - * |
|
| 1518 | - * @return string |
|
| 1519 | - * @throws EE_Error |
|
| 1520 | - * @throws ReflectionException |
|
| 1521 | - */ |
|
| 1522 | - public function name() |
|
| 1523 | - { |
|
| 1524 | - return $this->get('TKT_name'); |
|
| 1525 | - } |
|
| 1526 | - |
|
| 1527 | - |
|
| 1528 | - /** |
|
| 1529 | - * Gets price |
|
| 1530 | - * |
|
| 1531 | - * @return float |
|
| 1532 | - * @throws EE_Error |
|
| 1533 | - * @throws ReflectionException |
|
| 1534 | - */ |
|
| 1535 | - public function price() |
|
| 1536 | - { |
|
| 1537 | - return $this->get('TKT_price'); |
|
| 1538 | - } |
|
| 1539 | - |
|
| 1540 | - |
|
| 1541 | - /** |
|
| 1542 | - * Gets all the registrations for this ticket |
|
| 1543 | - * |
|
| 1544 | - * @param array $query_params @see |
|
| 1545 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1546 | - * @return EE_Registration[]|EE_Base_Class[] |
|
| 1547 | - * @throws EE_Error |
|
| 1548 | - * @throws ReflectionException |
|
| 1549 | - */ |
|
| 1550 | - public function registrations($query_params = []) |
|
| 1551 | - { |
|
| 1552 | - return $this->get_many_related('Registration', $query_params); |
|
| 1553 | - } |
|
| 1554 | - |
|
| 1555 | - |
|
| 1556 | - /** |
|
| 1557 | - * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
|
| 1558 | - * |
|
| 1559 | - * @return int |
|
| 1560 | - * @throws EE_Error |
|
| 1561 | - * @throws ReflectionException |
|
| 1562 | - */ |
|
| 1563 | - public function update_tickets_sold() |
|
| 1564 | - { |
|
| 1565 | - $count_regs_for_this_ticket = $this->count_registrations( |
|
| 1566 | - [ |
|
| 1567 | - [ |
|
| 1568 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1569 | - 'REG_deleted' => 0, |
|
| 1570 | - ], |
|
| 1571 | - ] |
|
| 1572 | - ); |
|
| 1573 | - $this->set_sold($count_regs_for_this_ticket); |
|
| 1574 | - $this->save(); |
|
| 1575 | - return $count_regs_for_this_ticket; |
|
| 1576 | - } |
|
| 1577 | - |
|
| 1578 | - |
|
| 1579 | - /** |
|
| 1580 | - * Counts the registrations for this ticket |
|
| 1581 | - * |
|
| 1582 | - * @param array $query_params @see |
|
| 1583 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1584 | - * @return int |
|
| 1585 | - * @throws EE_Error |
|
| 1586 | - * @throws ReflectionException |
|
| 1587 | - */ |
|
| 1588 | - public function count_registrations($query_params = []) |
|
| 1589 | - { |
|
| 1590 | - return $this->count_related('Registration', $query_params); |
|
| 1591 | - } |
|
| 1592 | - |
|
| 1593 | - |
|
| 1594 | - /** |
|
| 1595 | - * Implementation for EEI_Has_Icon interface method. |
|
| 1596 | - * |
|
| 1597 | - * @return string |
|
| 1598 | - * @see EEI_Visual_Representation for comments |
|
| 1599 | - */ |
|
| 1600 | - public function get_icon() |
|
| 1601 | - { |
|
| 1602 | - return '<span class="dashicons dashicons-tickets-alt"/>'; |
|
| 1603 | - } |
|
| 1604 | - |
|
| 1605 | - |
|
| 1606 | - /** |
|
| 1607 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1608 | - * |
|
| 1609 | - * @return EE_Event |
|
| 1610 | - * @throws EE_Error |
|
| 1611 | - * @throws UnexpectedEntityException |
|
| 1612 | - * @throws ReflectionException |
|
| 1613 | - * @see EEI_Event_Relation for comments |
|
| 1614 | - */ |
|
| 1615 | - public function get_related_event() |
|
| 1616 | - { |
|
| 1617 | - // get one datetime to use for getting the event |
|
| 1618 | - $datetime = $this->first_datetime(); |
|
| 1619 | - if (! $datetime instanceof EE_Datetime) { |
|
| 1620 | - throw new UnexpectedEntityException( |
|
| 1621 | - $datetime, |
|
| 1622 | - 'EE_Datetime', |
|
| 1623 | - sprintf( |
|
| 1624 | - __('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
|
| 1625 | - $this->name() |
|
| 1626 | - ) |
|
| 1627 | - ); |
|
| 1628 | - } |
|
| 1629 | - $event = $datetime->event(); |
|
| 1630 | - if (! $event instanceof EE_Event) { |
|
| 1631 | - throw new UnexpectedEntityException( |
|
| 1632 | - $event, |
|
| 1633 | - 'EE_Event', |
|
| 1634 | - sprintf( |
|
| 1635 | - __('The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
|
| 1636 | - $this->name() |
|
| 1637 | - ) |
|
| 1638 | - ); |
|
| 1639 | - } |
|
| 1640 | - return $event; |
|
| 1641 | - } |
|
| 1642 | - |
|
| 1643 | - |
|
| 1644 | - /** |
|
| 1645 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1646 | - * |
|
| 1647 | - * @return string |
|
| 1648 | - * @throws UnexpectedEntityException |
|
| 1649 | - * @throws EE_Error |
|
| 1650 | - * @throws ReflectionException |
|
| 1651 | - * @see EEI_Event_Relation for comments |
|
| 1652 | - */ |
|
| 1653 | - public function get_event_name() |
|
| 1654 | - { |
|
| 1655 | - $event = $this->get_related_event(); |
|
| 1656 | - return $event instanceof EE_Event ? $event->name() : ''; |
|
| 1657 | - } |
|
| 1658 | - |
|
| 1659 | - |
|
| 1660 | - /** |
|
| 1661 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1662 | - * |
|
| 1663 | - * @return int |
|
| 1664 | - * @throws UnexpectedEntityException |
|
| 1665 | - * @throws EE_Error |
|
| 1666 | - * @throws ReflectionException |
|
| 1667 | - * @see EEI_Event_Relation for comments |
|
| 1668 | - */ |
|
| 1669 | - public function get_event_ID() |
|
| 1670 | - { |
|
| 1671 | - $event = $this->get_related_event(); |
|
| 1672 | - return $event instanceof EE_Event ? $event->ID() : 0; |
|
| 1673 | - } |
|
| 1674 | - |
|
| 1675 | - |
|
| 1676 | - /** |
|
| 1677 | - * This simply returns whether a ticket can be permanently deleted or not. |
|
| 1678 | - * The criteria for determining this is whether the ticket has any related registrations. |
|
| 1679 | - * If there are none then it can be permanently deleted. |
|
| 1680 | - * |
|
| 1681 | - * @return bool |
|
| 1682 | - * @throws EE_Error |
|
| 1683 | - * @throws ReflectionException |
|
| 1684 | - */ |
|
| 1685 | - public function is_permanently_deleteable() |
|
| 1686 | - { |
|
| 1687 | - return $this->count_registrations() === 0; |
|
| 1688 | - } |
|
| 1689 | - |
|
| 1690 | - |
|
| 1691 | - /** |
|
| 1692 | - * @return int |
|
| 1693 | - * @throws EE_Error |
|
| 1694 | - * @throws ReflectionException |
|
| 1695 | - * @since $VID:$ |
|
| 1696 | - */ |
|
| 1697 | - public function visibility(): int |
|
| 1698 | - { |
|
| 1699 | - return $this->get('TKT_visibility'); |
|
| 1700 | - } |
|
| 1701 | - |
|
| 1702 | - |
|
| 1703 | - /** |
|
| 1704 | - * @param int $visibility |
|
| 1705 | - * @throws EE_Error |
|
| 1706 | - * @throws ReflectionException |
|
| 1707 | - * @since $VID:$ |
|
| 1708 | - */ |
|
| 1709 | - public function set_visibility(int $visibility) |
|
| 1710 | - { |
|
| 1711 | - $ticket_visibility = EEM_Ticket::instance()->ticketVisibility(); |
|
| 1712 | - if (! isset($ticket_visibility[ $visibility ])) { |
|
| 1713 | - throw new DomainException( |
|
| 1714 | - sprintf( |
|
| 1715 | - esc_html__( |
|
| 1716 | - 'The supplied ticket visibility setting of "%1$s" is not valid. It needs to match one of the keys in the following array:%2$s %3$s ', |
|
| 1717 | - 'event_espresso' |
|
| 1718 | - ), |
|
| 1719 | - $visibility, |
|
| 1720 | - '<br />', |
|
| 1721 | - var_export($ticket_visibility, true) |
|
| 1722 | - ) |
|
| 1723 | - ); |
|
| 1724 | - } |
|
| 1725 | - $this->set('TKT_visibility', $visibility); |
|
| 1726 | - } |
|
| 1727 | - |
|
| 1728 | - |
|
| 1729 | - /******************************************************************* |
|
| 17 | + /** |
|
| 18 | + * TicKet Sold out: |
|
| 19 | + * constant used by ticket_status() to indicate that a ticket is sold out |
|
| 20 | + * and no longer available for purchases |
|
| 21 | + */ |
|
| 22 | + const sold_out = 'TKS'; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * TicKet Expired: |
|
| 26 | + * constant used by ticket_status() to indicate that a ticket is expired |
|
| 27 | + * and no longer available for purchase |
|
| 28 | + */ |
|
| 29 | + const expired = 'TKE'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * TicKet Archived: |
|
| 33 | + * constant used by ticket_status() to indicate that a ticket is archived |
|
| 34 | + * and no longer available for purchase |
|
| 35 | + */ |
|
| 36 | + const archived = 'TKA'; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * TicKet Pending: |
|
| 40 | + * constant used by ticket_status() to indicate that a ticket is pending |
|
| 41 | + * and is NOT YET available for purchase |
|
| 42 | + */ |
|
| 43 | + const pending = 'TKP'; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * TicKet On sale: |
|
| 47 | + * constant used by ticket_status() to indicate that a ticket is On Sale |
|
| 48 | + * and IS available for purchase |
|
| 49 | + */ |
|
| 50 | + const onsale = 'TKO'; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * extra meta key for tracking ticket reservations |
|
| 54 | + * |
|
| 55 | + * @type string |
|
| 56 | + */ |
|
| 57 | + const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations'; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * cached result from method of the same name |
|
| 61 | + * |
|
| 62 | + * @var float $_ticket_total_with_taxes |
|
| 63 | + */ |
|
| 64 | + private $_ticket_total_with_taxes; |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @param array $props_n_values incoming values |
|
| 69 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 70 | + * used.) |
|
| 71 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 72 | + * date_format and the second value is the time format |
|
| 73 | + * @return EE_Ticket |
|
| 74 | + * @throws EE_Error |
|
| 75 | + * @throws ReflectionException |
|
| 76 | + */ |
|
| 77 | + public static function new_instance($props_n_values = [], $timezone = null, $date_formats = []) |
|
| 78 | + { |
|
| 79 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 80 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @param array $props_n_values incoming values from the database |
|
| 86 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 87 | + * the website will be used. |
|
| 88 | + * @return EE_Ticket |
|
| 89 | + * @throws EE_Error |
|
| 90 | + * @throws ReflectionException |
|
| 91 | + */ |
|
| 92 | + public static function new_instance_from_db($props_n_values = [], $timezone = null) |
|
| 93 | + { |
|
| 94 | + return new self($props_n_values, true, $timezone); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @return bool |
|
| 100 | + * @throws EE_Error |
|
| 101 | + * @throws ReflectionException |
|
| 102 | + */ |
|
| 103 | + public function parent() |
|
| 104 | + { |
|
| 105 | + return $this->get('TKT_parent'); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * return if a ticket has quantities available for purchase |
|
| 111 | + * |
|
| 112 | + * @param int $DTT_ID the primary key for a particular datetime |
|
| 113 | + * @return boolean |
|
| 114 | + * @throws EE_Error |
|
| 115 | + * @throws ReflectionException |
|
| 116 | + */ |
|
| 117 | + public function available($DTT_ID = 0) |
|
| 118 | + { |
|
| 119 | + // are we checking availability for a particular datetime ? |
|
| 120 | + if ($DTT_ID) { |
|
| 121 | + // get that datetime object |
|
| 122 | + $datetime = $this->get_first_related('Datetime', [['DTT_ID' => $DTT_ID]]); |
|
| 123 | + // if ticket sales for this datetime have exceeded the reg limit... |
|
| 124 | + if ($datetime instanceof EE_Datetime && $datetime->sold_out()) { |
|
| 125 | + return false; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + // datetime is still open for registration, but is this ticket sold out ? |
|
| 129 | + return $this->qty() < 1 || $this->qty() > $this->sold(); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
|
| 135 | + * |
|
| 136 | + * @param bool $display true = we'll return a localized string, otherwise we just return the value of the |
|
| 137 | + * relevant status const |
|
| 138 | + * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save |
|
| 139 | + * further processing |
|
| 140 | + * @return mixed status int if the display string isn't requested |
|
| 141 | + * @throws EE_Error |
|
| 142 | + * @throws ReflectionException |
|
| 143 | + */ |
|
| 144 | + public function ticket_status($display = false, $remaining = null) |
|
| 145 | + { |
|
| 146 | + $remaining = is_bool($remaining) ? $remaining : $this->is_remaining(); |
|
| 147 | + if (! $remaining) { |
|
| 148 | + return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out; |
|
| 149 | + } |
|
| 150 | + if ($this->get('TKT_deleted')) { |
|
| 151 | + return $display ? EEH_Template::pretty_status(EE_Ticket::archived, false, 'sentence') : EE_Ticket::archived; |
|
| 152 | + } |
|
| 153 | + if ($this->is_expired()) { |
|
| 154 | + return $display ? EEH_Template::pretty_status(EE_Ticket::expired, false, 'sentence') : EE_Ticket::expired; |
|
| 155 | + } |
|
| 156 | + if ($this->is_pending()) { |
|
| 157 | + return $display ? EEH_Template::pretty_status(EE_Ticket::pending, false, 'sentence') : EE_Ticket::pending; |
|
| 158 | + } |
|
| 159 | + if ($this->is_on_sale()) { |
|
| 160 | + return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence') : EE_Ticket::onsale; |
|
| 161 | + } |
|
| 162 | + return ''; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale |
|
| 168 | + * considering ALL the factors used for figuring that out. |
|
| 169 | + * |
|
| 170 | + * @access public |
|
| 171 | + * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
|
| 172 | + * @return boolean true = tickets remaining, false not. |
|
| 173 | + * @throws EE_Error |
|
| 174 | + * @throws ReflectionException |
|
| 175 | + */ |
|
| 176 | + public function is_remaining($DTT_ID = 0) |
|
| 177 | + { |
|
| 178 | + $num_remaining = $this->remaining($DTT_ID); |
|
| 179 | + if ($num_remaining === 0) { |
|
| 180 | + return false; |
|
| 181 | + } |
|
| 182 | + if ($num_remaining > 0 && $num_remaining < $this->min()) { |
|
| 183 | + return false; |
|
| 184 | + } |
|
| 185 | + return true; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * return the total number of tickets available for purchase |
|
| 191 | + * |
|
| 192 | + * @param int $DTT_ID the primary key for a particular datetime. |
|
| 193 | + * set to 0 for all related datetimes |
|
| 194 | + * @return int |
|
| 195 | + * @throws EE_Error |
|
| 196 | + * @throws ReflectionException |
|
| 197 | + */ |
|
| 198 | + public function remaining($DTT_ID = 0) |
|
| 199 | + { |
|
| 200 | + return $this->real_quantity_on_ticket('saleable', $DTT_ID); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Gets min |
|
| 206 | + * |
|
| 207 | + * @return int |
|
| 208 | + * @throws EE_Error |
|
| 209 | + * @throws ReflectionException |
|
| 210 | + */ |
|
| 211 | + public function min() |
|
| 212 | + { |
|
| 213 | + return $this->get('TKT_min'); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * return if a ticket is no longer available cause its available dates have expired. |
|
| 219 | + * |
|
| 220 | + * @return boolean |
|
| 221 | + * @throws EE_Error |
|
| 222 | + * @throws ReflectionException |
|
| 223 | + */ |
|
| 224 | + public function is_expired() |
|
| 225 | + { |
|
| 226 | + return ($this->get_raw('TKT_end_date') < time()); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Return if a ticket is yet to go on sale or not |
|
| 232 | + * |
|
| 233 | + * @return boolean |
|
| 234 | + * @throws EE_Error |
|
| 235 | + * @throws ReflectionException |
|
| 236 | + */ |
|
| 237 | + public function is_pending() |
|
| 238 | + { |
|
| 239 | + return ($this->get_raw('TKT_start_date') >= time()); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Return if a ticket is on sale or not |
|
| 245 | + * |
|
| 246 | + * @return boolean |
|
| 247 | + * @throws EE_Error |
|
| 248 | + * @throws ReflectionException |
|
| 249 | + */ |
|
| 250 | + public function is_on_sale() |
|
| 251 | + { |
|
| 252 | + return ($this->get_raw('TKT_start_date') <= time() && $this->get_raw('TKT_end_date') >= time()); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * This returns the chronologically last datetime that this ticket is associated with |
|
| 258 | + * |
|
| 259 | + * @param string $date_format |
|
| 260 | + * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with |
|
| 261 | + * the end date ie: Jan 01 "to" Dec 31 |
|
| 262 | + * @return string |
|
| 263 | + * @throws EE_Error |
|
| 264 | + * @throws ReflectionException |
|
| 265 | + */ |
|
| 266 | + public function date_range($date_format = '', $conjunction = ' - ') |
|
| 267 | + { |
|
| 268 | + $date_format = ! empty($date_format) ? $date_format : $this->_dt_frmt; |
|
| 269 | + $first_date = $this->first_datetime() instanceof EE_Datetime |
|
| 270 | + ? $this->first_datetime()->get_i18n_datetime('DTT_EVT_start', $date_format) |
|
| 271 | + : ''; |
|
| 272 | + $last_date = $this->last_datetime() instanceof EE_Datetime |
|
| 273 | + ? $this->last_datetime()->get_i18n_datetime('DTT_EVT_end', $date_format) |
|
| 274 | + : ''; |
|
| 275 | + |
|
| 276 | + return $first_date && $last_date ? $first_date . $conjunction . $last_date : ''; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * This returns the chronologically first datetime that this ticket is associated with |
|
| 282 | + * |
|
| 283 | + * @return EE_Datetime |
|
| 284 | + * @throws EE_Error |
|
| 285 | + * @throws ReflectionException |
|
| 286 | + */ |
|
| 287 | + public function first_datetime() |
|
| 288 | + { |
|
| 289 | + $datetimes = $this->datetimes(['limit' => 1]); |
|
| 290 | + return reset($datetimes); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * Gets all the datetimes this ticket can be used for attending. |
|
| 296 | + * Unless otherwise specified, orders datetimes by start date. |
|
| 297 | + * |
|
| 298 | + * @param array $query_params @see |
|
| 299 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 300 | + * @return EE_Datetime[]|EE_Base_Class[] |
|
| 301 | + * @throws EE_Error |
|
| 302 | + * @throws ReflectionException |
|
| 303 | + */ |
|
| 304 | + public function datetimes($query_params = []) |
|
| 305 | + { |
|
| 306 | + if (! isset($query_params['order_by'])) { |
|
| 307 | + $query_params['order_by']['DTT_order'] = 'ASC'; |
|
| 308 | + } |
|
| 309 | + return $this->get_many_related('Datetime', $query_params); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * This returns the chronologically last datetime that this ticket is associated with |
|
| 315 | + * |
|
| 316 | + * @return EE_Datetime |
|
| 317 | + * @throws EE_Error |
|
| 318 | + * @throws ReflectionException |
|
| 319 | + */ |
|
| 320 | + public function last_datetime() |
|
| 321 | + { |
|
| 322 | + $datetimes = $this->datetimes(['limit' => 1, 'order_by' => ['DTT_EVT_start' => 'DESC']]); |
|
| 323 | + return end($datetimes); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * This returns the total tickets sold depending on the given parameters. |
|
| 329 | + * |
|
| 330 | + * @param string $what Can be one of two options: 'ticket', 'datetime'. |
|
| 331 | + * 'ticket' = total ticket sales for all datetimes this ticket is related to |
|
| 332 | + * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
|
| 333 | + * 'datetime' = total ticket sales in the datetime_ticket table. |
|
| 334 | + * If $dtt_id is not given then we return an array of sales indexed by datetime. |
|
| 335 | + * If $dtt_id IS given then we return the tickets sold for that given datetime. |
|
| 336 | + * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
|
| 337 | + * @return mixed (array|int) how many tickets have sold |
|
| 338 | + * @throws EE_Error |
|
| 339 | + * @throws ReflectionException |
|
| 340 | + */ |
|
| 341 | + public function tickets_sold($what = 'ticket', $dtt_id = null) |
|
| 342 | + { |
|
| 343 | + $total = 0; |
|
| 344 | + $tickets_sold = $this->_all_tickets_sold(); |
|
| 345 | + switch ($what) { |
|
| 346 | + case 'ticket': |
|
| 347 | + return $tickets_sold['ticket']; |
|
| 348 | + break; |
|
| 349 | + case 'datetime': |
|
| 350 | + if (empty($tickets_sold['datetime'])) { |
|
| 351 | + return $total; |
|
| 352 | + } |
|
| 353 | + if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) { |
|
| 354 | + EE_Error::add_error( |
|
| 355 | + __( |
|
| 356 | + 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?', |
|
| 357 | + 'event_espresso' |
|
| 358 | + ), |
|
| 359 | + __FILE__, |
|
| 360 | + __FUNCTION__, |
|
| 361 | + __LINE__ |
|
| 362 | + ); |
|
| 363 | + return $total; |
|
| 364 | + } |
|
| 365 | + return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ]; |
|
| 366 | + break; |
|
| 367 | + default: |
|
| 368 | + return $total; |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * This returns an array indexed by datetime_id for tickets sold with this ticket. |
|
| 375 | + * |
|
| 376 | + * @return EE_Ticket[] |
|
| 377 | + * @throws EE_Error |
|
| 378 | + * @throws ReflectionException |
|
| 379 | + */ |
|
| 380 | + protected function _all_tickets_sold() |
|
| 381 | + { |
|
| 382 | + $datetimes = $this->get_many_related('Datetime'); |
|
| 383 | + $tickets_sold = []; |
|
| 384 | + if (! empty($datetimes)) { |
|
| 385 | + foreach ($datetimes as $datetime) { |
|
| 386 | + $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold'); |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + // Tickets sold |
|
| 390 | + $tickets_sold['ticket'] = $this->sold(); |
|
| 391 | + return $tickets_sold; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * This returns the base price object for the ticket. |
|
| 397 | + * |
|
| 398 | + * @param bool $return_array whether to return as an array indexed by price id or just the object. |
|
| 399 | + * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
|
| 400 | + * @throws EE_Error |
|
| 401 | + * @throws ReflectionException |
|
| 402 | + */ |
|
| 403 | + public function base_price($return_array = false) |
|
| 404 | + { |
|
| 405 | + $_where = ['Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price]; |
|
| 406 | + return $return_array |
|
| 407 | + ? $this->get_many_related('Price', [$_where]) |
|
| 408 | + : $this->get_first_related('Price', [$_where]); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
| 414 | + * |
|
| 415 | + * @access public |
|
| 416 | + * @return EE_Price[] |
|
| 417 | + * @throws EE_Error |
|
| 418 | + * @throws ReflectionException |
|
| 419 | + */ |
|
| 420 | + public function price_modifiers() |
|
| 421 | + { |
|
| 422 | + $query_params = [ |
|
| 423 | + 0 => [ |
|
| 424 | + 'Price_Type.PBT_ID' => [ |
|
| 425 | + 'NOT IN', |
|
| 426 | + [EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax], |
|
| 427 | + ], |
|
| 428 | + ], |
|
| 429 | + ]; |
|
| 430 | + return $this->prices($query_params); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
| 436 | + * |
|
| 437 | + * @access public |
|
| 438 | + * @return EE_Price[] |
|
| 439 | + * @throws EE_Error |
|
| 440 | + * @throws ReflectionException |
|
| 441 | + */ |
|
| 442 | + public function tax_price_modifiers() |
|
| 443 | + { |
|
| 444 | + $query_params = [ |
|
| 445 | + 0 => [ |
|
| 446 | + 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax, |
|
| 447 | + ], |
|
| 448 | + ]; |
|
| 449 | + return $this->prices($query_params); |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * Gets all the prices that combine to form the final price of this ticket |
|
| 455 | + * |
|
| 456 | + * @param array $query_params @see |
|
| 457 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 458 | + * @return EE_Price[]|EE_Base_Class[] |
|
| 459 | + * @throws EE_Error |
|
| 460 | + * @throws ReflectionException |
|
| 461 | + */ |
|
| 462 | + public function prices($query_params = []) |
|
| 463 | + { |
|
| 464 | + return $this->get_many_related('Price', $query_params); |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * Gets all the ticket datetimes (ie, relations between datetimes and tickets) |
|
| 470 | + * |
|
| 471 | + * @param array $query_params @see |
|
| 472 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 473 | + * @return EE_Datetime_Ticket|EE_Base_Class[] |
|
| 474 | + * @throws EE_Error |
|
| 475 | + * @throws ReflectionException |
|
| 476 | + */ |
|
| 477 | + public function datetime_tickets($query_params = []) |
|
| 478 | + { |
|
| 479 | + return $this->get_many_related('Datetime_Ticket', $query_params); |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * Gets all the datetimes from the db ordered by DTT_order |
|
| 485 | + * |
|
| 486 | + * @param boolean $show_expired |
|
| 487 | + * @param boolean $show_deleted |
|
| 488 | + * @return EE_Datetime[] |
|
| 489 | + * @throws EE_Error |
|
| 490 | + * @throws ReflectionException |
|
| 491 | + */ |
|
| 492 | + public function datetimes_ordered($show_expired = true, $show_deleted = false) |
|
| 493 | + { |
|
| 494 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order( |
|
| 495 | + $this->ID(), |
|
| 496 | + $show_expired, |
|
| 497 | + $show_deleted |
|
| 498 | + ); |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * Gets ID |
|
| 504 | + * |
|
| 505 | + * @return string |
|
| 506 | + * @throws EE_Error |
|
| 507 | + * @throws ReflectionException |
|
| 508 | + */ |
|
| 509 | + public function ID() |
|
| 510 | + { |
|
| 511 | + return $this->get('TKT_ID'); |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * get the author of the ticket. |
|
| 517 | + * |
|
| 518 | + * @return int |
|
| 519 | + * @throws EE_Error |
|
| 520 | + * @throws ReflectionException |
|
| 521 | + * @since 4.5.0 |
|
| 522 | + */ |
|
| 523 | + public function wp_user() |
|
| 524 | + { |
|
| 525 | + return $this->get('TKT_wp_user'); |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * Gets the template for the ticket |
|
| 531 | + * |
|
| 532 | + * @return EE_Ticket_Template|EE_Base_Class |
|
| 533 | + * @throws EE_Error |
|
| 534 | + * @throws ReflectionException |
|
| 535 | + */ |
|
| 536 | + public function template() |
|
| 537 | + { |
|
| 538 | + return $this->get_first_related('Ticket_Template'); |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * Simply returns an array of EE_Price objects that are taxes. |
|
| 544 | + * |
|
| 545 | + * @return EE_Price[] |
|
| 546 | + * @throws EE_Error |
|
| 547 | + */ |
|
| 548 | + public function get_ticket_taxes_for_admin() |
|
| 549 | + { |
|
| 550 | + return EE_Taxes::get_taxes_for_admin(); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * @return float |
|
| 556 | + * @throws EE_Error |
|
| 557 | + * @throws ReflectionException |
|
| 558 | + */ |
|
| 559 | + public function ticket_price() |
|
| 560 | + { |
|
| 561 | + return $this->get('TKT_price'); |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * @return mixed |
|
| 567 | + * @throws EE_Error |
|
| 568 | + * @throws ReflectionException |
|
| 569 | + */ |
|
| 570 | + public function pretty_price() |
|
| 571 | + { |
|
| 572 | + return $this->get_pretty('TKT_price'); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + |
|
| 576 | + /** |
|
| 577 | + * @return bool |
|
| 578 | + * @throws EE_Error |
|
| 579 | + * @throws ReflectionException |
|
| 580 | + */ |
|
| 581 | + public function is_free() |
|
| 582 | + { |
|
| 583 | + return $this->get_ticket_total_with_taxes() === (float) 0; |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * get_ticket_total_with_taxes |
|
| 589 | + * |
|
| 590 | + * @param bool $no_cache |
|
| 591 | + * @return float |
|
| 592 | + * @throws EE_Error |
|
| 593 | + * @throws ReflectionException |
|
| 594 | + */ |
|
| 595 | + public function get_ticket_total_with_taxes($no_cache = false) |
|
| 596 | + { |
|
| 597 | + if ($this->_ticket_total_with_taxes === null || $no_cache) { |
|
| 598 | + $this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin(); |
|
| 599 | + } |
|
| 600 | + return (float) $this->_ticket_total_with_taxes; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * @throws EE_Error |
|
| 606 | + * @throws ReflectionException |
|
| 607 | + */ |
|
| 608 | + public function ensure_TKT_Price_correct() |
|
| 609 | + { |
|
| 610 | + $this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this)); |
|
| 611 | + $this->save(); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * @return float |
|
| 617 | + * @throws EE_Error |
|
| 618 | + * @throws ReflectionException |
|
| 619 | + */ |
|
| 620 | + public function get_ticket_subtotal() |
|
| 621 | + { |
|
| 622 | + return EE_Taxes::get_subtotal_for_admin($this); |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * Returns the total taxes applied to this ticket |
|
| 628 | + * |
|
| 629 | + * @return float |
|
| 630 | + * @throws EE_Error |
|
| 631 | + * @throws ReflectionException |
|
| 632 | + */ |
|
| 633 | + public function get_ticket_taxes_total_for_admin() |
|
| 634 | + { |
|
| 635 | + return EE_Taxes::get_total_taxes_for_admin($this); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + /** |
|
| 640 | + * Sets name |
|
| 641 | + * |
|
| 642 | + * @param string $name |
|
| 643 | + * @throws EE_Error |
|
| 644 | + * @throws ReflectionException |
|
| 645 | + */ |
|
| 646 | + public function set_name($name) |
|
| 647 | + { |
|
| 648 | + $this->set('TKT_name', $name); |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + |
|
| 652 | + /** |
|
| 653 | + * Gets description |
|
| 654 | + * |
|
| 655 | + * @return string |
|
| 656 | + * @throws EE_Error |
|
| 657 | + * @throws ReflectionException |
|
| 658 | + */ |
|
| 659 | + public function description() |
|
| 660 | + { |
|
| 661 | + return $this->get('TKT_description'); |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + |
|
| 665 | + /** |
|
| 666 | + * Sets description |
|
| 667 | + * |
|
| 668 | + * @param string $description |
|
| 669 | + * @throws EE_Error |
|
| 670 | + * @throws ReflectionException |
|
| 671 | + */ |
|
| 672 | + public function set_description($description) |
|
| 673 | + { |
|
| 674 | + $this->set('TKT_description', $description); |
|
| 675 | + } |
|
| 676 | + |
|
| 677 | + |
|
| 678 | + /** |
|
| 679 | + * Gets start_date |
|
| 680 | + * |
|
| 681 | + * @param string $date_format |
|
| 682 | + * @param string $time_format |
|
| 683 | + * @return string |
|
| 684 | + * @throws EE_Error |
|
| 685 | + * @throws ReflectionException |
|
| 686 | + */ |
|
| 687 | + public function start_date($date_format = '', $time_format = '') |
|
| 688 | + { |
|
| 689 | + return $this->_get_datetime('TKT_start_date', $date_format, $time_format); |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + /** |
|
| 694 | + * Sets start_date |
|
| 695 | + * |
|
| 696 | + * @param string $start_date |
|
| 697 | + * @return void |
|
| 698 | + * @throws EE_Error |
|
| 699 | + * @throws ReflectionException |
|
| 700 | + */ |
|
| 701 | + public function set_start_date($start_date) |
|
| 702 | + { |
|
| 703 | + $this->_set_date_time('B', $start_date, 'TKT_start_date'); |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + |
|
| 707 | + /** |
|
| 708 | + * Gets end_date |
|
| 709 | + * |
|
| 710 | + * @param string $date_format |
|
| 711 | + * @param string $time_format |
|
| 712 | + * @return string |
|
| 713 | + * @throws EE_Error |
|
| 714 | + * @throws ReflectionException |
|
| 715 | + */ |
|
| 716 | + public function end_date($date_format = '', $time_format = '') |
|
| 717 | + { |
|
| 718 | + return $this->_get_datetime('TKT_end_date', $date_format, $time_format); |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + |
|
| 722 | + /** |
|
| 723 | + * Sets end_date |
|
| 724 | + * |
|
| 725 | + * @param string $end_date |
|
| 726 | + * @return void |
|
| 727 | + * @throws EE_Error |
|
| 728 | + * @throws ReflectionException |
|
| 729 | + */ |
|
| 730 | + public function set_end_date($end_date) |
|
| 731 | + { |
|
| 732 | + $this->_set_date_time('B', $end_date, 'TKT_end_date'); |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + |
|
| 736 | + /** |
|
| 737 | + * Sets sell until time |
|
| 738 | + * |
|
| 739 | + * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
|
| 740 | + * @throws EE_Error |
|
| 741 | + * @throws ReflectionException |
|
| 742 | + * @since 4.5.0 |
|
| 743 | + */ |
|
| 744 | + public function set_end_time($time) |
|
| 745 | + { |
|
| 746 | + $this->_set_time_for($time, 'TKT_end_date'); |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * Sets min |
|
| 752 | + * |
|
| 753 | + * @param int $min |
|
| 754 | + * @return void |
|
| 755 | + * @throws EE_Error |
|
| 756 | + * @throws ReflectionException |
|
| 757 | + */ |
|
| 758 | + public function set_min($min) |
|
| 759 | + { |
|
| 760 | + $this->set('TKT_min', $min); |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + |
|
| 764 | + /** |
|
| 765 | + * Gets max |
|
| 766 | + * |
|
| 767 | + * @return int |
|
| 768 | + * @throws EE_Error |
|
| 769 | + * @throws ReflectionException |
|
| 770 | + */ |
|
| 771 | + public function max() |
|
| 772 | + { |
|
| 773 | + return $this->get('TKT_max'); |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + |
|
| 777 | + /** |
|
| 778 | + * Sets max |
|
| 779 | + * |
|
| 780 | + * @param int $max |
|
| 781 | + * @return void |
|
| 782 | + * @throws EE_Error |
|
| 783 | + * @throws ReflectionException |
|
| 784 | + */ |
|
| 785 | + public function set_max($max) |
|
| 786 | + { |
|
| 787 | + $this->set('TKT_max', $max); |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + |
|
| 791 | + /** |
|
| 792 | + * Sets price |
|
| 793 | + * |
|
| 794 | + * @param float $price |
|
| 795 | + * @return void |
|
| 796 | + * @throws EE_Error |
|
| 797 | + * @throws ReflectionException |
|
| 798 | + */ |
|
| 799 | + public function set_price($price) |
|
| 800 | + { |
|
| 801 | + $this->set('TKT_price', $price); |
|
| 802 | + } |
|
| 803 | + |
|
| 804 | + |
|
| 805 | + /** |
|
| 806 | + * Gets sold |
|
| 807 | + * |
|
| 808 | + * @return int |
|
| 809 | + * @throws EE_Error |
|
| 810 | + * @throws ReflectionException |
|
| 811 | + */ |
|
| 812 | + public function sold() |
|
| 813 | + { |
|
| 814 | + return $this->get_raw('TKT_sold'); |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + |
|
| 818 | + /** |
|
| 819 | + * Sets sold |
|
| 820 | + * |
|
| 821 | + * @param int $sold |
|
| 822 | + * @return void |
|
| 823 | + * @throws EE_Error |
|
| 824 | + * @throws ReflectionException |
|
| 825 | + */ |
|
| 826 | + public function set_sold($sold) |
|
| 827 | + { |
|
| 828 | + // sold can not go below zero |
|
| 829 | + $sold = max(0, $sold); |
|
| 830 | + $this->set('TKT_sold', $sold); |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + |
|
| 834 | + /** |
|
| 835 | + * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
|
| 836 | + * associated datetimes. |
|
| 837 | + * |
|
| 838 | + * @param int $qty |
|
| 839 | + * @return boolean |
|
| 840 | + * @throws EE_Error |
|
| 841 | + * @throws InvalidArgumentException |
|
| 842 | + * @throws InvalidDataTypeException |
|
| 843 | + * @throws InvalidInterfaceException |
|
| 844 | + * @throws ReflectionException |
|
| 845 | + * @since 4.9.80.p |
|
| 846 | + */ |
|
| 847 | + public function increaseSold($qty = 1) |
|
| 848 | + { |
|
| 849 | + $qty = absint($qty); |
|
| 850 | + // increment sold and decrement reserved datetime quantities simultaneously |
|
| 851 | + // don't worry about failures, because they must have already had a spot reserved |
|
| 852 | + $this->increaseSoldForDatetimes($qty); |
|
| 853 | + // Increment and decrement ticket quantities simultaneously |
|
| 854 | + $success = $this->adjustNumericFieldsInDb( |
|
| 855 | + [ |
|
| 856 | + 'TKT_reserved' => $qty * -1, |
|
| 857 | + 'TKT_sold' => $qty, |
|
| 858 | + ] |
|
| 859 | + ); |
|
| 860 | + do_action( |
|
| 861 | + 'AHEE__EE_Ticket__increase_sold', |
|
| 862 | + $this, |
|
| 863 | + $qty, |
|
| 864 | + $this->sold(), |
|
| 865 | + $success |
|
| 866 | + ); |
|
| 867 | + return $success; |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + |
|
| 871 | + /** |
|
| 872 | + * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
|
| 873 | + * |
|
| 874 | + * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved |
|
| 875 | + * counts), Negative means to decreases old counts (and increase reserved counts). |
|
| 876 | + * @param EE_Datetime[] $datetimes |
|
| 877 | + * @throws EE_Error |
|
| 878 | + * @throws InvalidArgumentException |
|
| 879 | + * @throws InvalidDataTypeException |
|
| 880 | + * @throws InvalidInterfaceException |
|
| 881 | + * @throws ReflectionException |
|
| 882 | + * @since 4.9.80.p |
|
| 883 | + */ |
|
| 884 | + protected function increaseSoldForDatetimes($qty, array $datetimes = []) |
|
| 885 | + { |
|
| 886 | + $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 887 | + foreach ($datetimes as $datetime) { |
|
| 888 | + $datetime->increaseSold($qty); |
|
| 889 | + } |
|
| 890 | + } |
|
| 891 | + |
|
| 892 | + |
|
| 893 | + /** |
|
| 894 | + * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
|
| 895 | + * DB and then updates the model objects. |
|
| 896 | + * Does not affect the reserved counts. |
|
| 897 | + * |
|
| 898 | + * @param int $qty |
|
| 899 | + * @return boolean |
|
| 900 | + * @throws EE_Error |
|
| 901 | + * @throws InvalidArgumentException |
|
| 902 | + * @throws InvalidDataTypeException |
|
| 903 | + * @throws InvalidInterfaceException |
|
| 904 | + * @throws ReflectionException |
|
| 905 | + * @since 4.9.80.p |
|
| 906 | + */ |
|
| 907 | + public function decreaseSold($qty = 1) |
|
| 908 | + { |
|
| 909 | + $qty = absint($qty); |
|
| 910 | + $this->decreaseSoldForDatetimes($qty); |
|
| 911 | + $success = $this->adjustNumericFieldsInDb( |
|
| 912 | + [ |
|
| 913 | + 'TKT_sold' => $qty * -1, |
|
| 914 | + ] |
|
| 915 | + ); |
|
| 916 | + do_action( |
|
| 917 | + 'AHEE__EE_Ticket__decrease_sold', |
|
| 918 | + $this, |
|
| 919 | + $qty, |
|
| 920 | + $this->sold(), |
|
| 921 | + $success |
|
| 922 | + ); |
|
| 923 | + return $success; |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + |
|
| 927 | + /** |
|
| 928 | + * Decreases sold on related datetimes |
|
| 929 | + * |
|
| 930 | + * @param int $qty |
|
| 931 | + * @param EE_Datetime[] $datetimes |
|
| 932 | + * @return void |
|
| 933 | + * @throws EE_Error |
|
| 934 | + * @throws InvalidArgumentException |
|
| 935 | + * @throws InvalidDataTypeException |
|
| 936 | + * @throws InvalidInterfaceException |
|
| 937 | + * @throws ReflectionException |
|
| 938 | + * @since 4.9.80.p |
|
| 939 | + */ |
|
| 940 | + protected function decreaseSoldForDatetimes($qty = 1, array $datetimes = []) |
|
| 941 | + { |
|
| 942 | + $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 943 | + if (is_array($datetimes)) { |
|
| 944 | + foreach ($datetimes as $datetime) { |
|
| 945 | + if ($datetime instanceof EE_Datetime) { |
|
| 946 | + $datetime->decreaseSold($qty); |
|
| 947 | + } |
|
| 948 | + } |
|
| 949 | + } |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * Gets qty of reserved tickets |
|
| 955 | + * |
|
| 956 | + * @return int |
|
| 957 | + * @throws EE_Error |
|
| 958 | + * @throws ReflectionException |
|
| 959 | + */ |
|
| 960 | + public function reserved() |
|
| 961 | + { |
|
| 962 | + return $this->get_raw('TKT_reserved'); |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + |
|
| 966 | + /** |
|
| 967 | + * Sets reserved |
|
| 968 | + * |
|
| 969 | + * @param int $reserved |
|
| 970 | + * @return void |
|
| 971 | + * @throws EE_Error |
|
| 972 | + * @throws ReflectionException |
|
| 973 | + */ |
|
| 974 | + public function set_reserved($reserved) |
|
| 975 | + { |
|
| 976 | + // reserved can not go below zero |
|
| 977 | + $reserved = max(0, (int) $reserved); |
|
| 978 | + $this->set('TKT_reserved', $reserved); |
|
| 979 | + } |
|
| 980 | + |
|
| 981 | + |
|
| 982 | + /** |
|
| 983 | + * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 984 | + * |
|
| 985 | + * @param int $qty |
|
| 986 | + * @param string $source |
|
| 987 | + * @return bool whether we successfully reserved the ticket or not. |
|
| 988 | + * @throws EE_Error |
|
| 989 | + * @throws InvalidArgumentException |
|
| 990 | + * @throws ReflectionException |
|
| 991 | + * @throws InvalidDataTypeException |
|
| 992 | + * @throws InvalidInterfaceException |
|
| 993 | + * @since 4.9.80.p |
|
| 994 | + */ |
|
| 995 | + public function increaseReserved($qty = 1, $source = 'unknown') |
|
| 996 | + { |
|
| 997 | + $qty = absint($qty); |
|
| 998 | + do_action( |
|
| 999 | + 'AHEE__EE_Ticket__increase_reserved__begin', |
|
| 1000 | + $this, |
|
| 1001 | + $qty, |
|
| 1002 | + $source |
|
| 1003 | + ); |
|
| 1004 | + $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "{$qty} from {$source}"); |
|
| 1005 | + $success = false; |
|
| 1006 | + $datetimes_adjusted_successfully = $this->increaseReservedForDatetimes($qty); |
|
| 1007 | + if ($datetimes_adjusted_successfully) { |
|
| 1008 | + $success = $this->incrementFieldConditionallyInDb( |
|
| 1009 | + 'TKT_reserved', |
|
| 1010 | + 'TKT_sold', |
|
| 1011 | + 'TKT_qty', |
|
| 1012 | + $qty |
|
| 1013 | + ); |
|
| 1014 | + if (! $success) { |
|
| 1015 | + // The datetimes were successfully bumped, but not the |
|
| 1016 | + // ticket. So we need to manually rollback the datetimes. |
|
| 1017 | + $this->decreaseReservedForDatetimes($qty); |
|
| 1018 | + } |
|
| 1019 | + } |
|
| 1020 | + do_action( |
|
| 1021 | + 'AHEE__EE_Ticket__increase_reserved', |
|
| 1022 | + $this, |
|
| 1023 | + $qty, |
|
| 1024 | + $this->reserved(), |
|
| 1025 | + $success |
|
| 1026 | + ); |
|
| 1027 | + return $success; |
|
| 1028 | + } |
|
| 1029 | + |
|
| 1030 | + |
|
| 1031 | + /** |
|
| 1032 | + * Increases reserved counts on related datetimes |
|
| 1033 | + * |
|
| 1034 | + * @param int $qty |
|
| 1035 | + * @param EE_Datetime[] $datetimes |
|
| 1036 | + * @return boolean indicating success |
|
| 1037 | + * @throws EE_Error |
|
| 1038 | + * @throws InvalidArgumentException |
|
| 1039 | + * @throws InvalidDataTypeException |
|
| 1040 | + * @throws InvalidInterfaceException |
|
| 1041 | + * @throws ReflectionException |
|
| 1042 | + * @since 4.9.80.p |
|
| 1043 | + */ |
|
| 1044 | + protected function increaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
| 1045 | + { |
|
| 1046 | + $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 1047 | + $datetimes_updated = []; |
|
| 1048 | + $limit_exceeded = false; |
|
| 1049 | + if (is_array($datetimes)) { |
|
| 1050 | + foreach ($datetimes as $datetime) { |
|
| 1051 | + if ($datetime instanceof EE_Datetime) { |
|
| 1052 | + if ($datetime->increaseReserved($qty)) { |
|
| 1053 | + $datetimes_updated[] = $datetime; |
|
| 1054 | + } else { |
|
| 1055 | + $limit_exceeded = true; |
|
| 1056 | + break; |
|
| 1057 | + } |
|
| 1058 | + } |
|
| 1059 | + } |
|
| 1060 | + // If somewhere along the way we detected a datetime whose |
|
| 1061 | + // limit was exceeded, do a manual rollback. |
|
| 1062 | + if ($limit_exceeded) { |
|
| 1063 | + $this->decreaseReservedForDatetimes($qty, $datetimes_updated); |
|
| 1064 | + return false; |
|
| 1065 | + } |
|
| 1066 | + } |
|
| 1067 | + return true; |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + |
|
| 1071 | + /** |
|
| 1072 | + * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1073 | + * |
|
| 1074 | + * @param int $qty |
|
| 1075 | + * @param bool $adjust_datetimes |
|
| 1076 | + * @param string $source |
|
| 1077 | + * @return boolean |
|
| 1078 | + * @throws EE_Error |
|
| 1079 | + * @throws InvalidArgumentException |
|
| 1080 | + * @throws ReflectionException |
|
| 1081 | + * @throws InvalidDataTypeException |
|
| 1082 | + * @throws InvalidInterfaceException |
|
| 1083 | + * @since 4.9.80.p |
|
| 1084 | + */ |
|
| 1085 | + public function decreaseReserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
| 1086 | + { |
|
| 1087 | + $qty = absint($qty); |
|
| 1088 | + $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "-{$qty} from {$source}"); |
|
| 1089 | + if ($adjust_datetimes) { |
|
| 1090 | + $this->decreaseReservedForDatetimes($qty); |
|
| 1091 | + } |
|
| 1092 | + $success = $this->adjustNumericFieldsInDb( |
|
| 1093 | + [ |
|
| 1094 | + 'TKT_reserved' => $qty * -1, |
|
| 1095 | + ] |
|
| 1096 | + ); |
|
| 1097 | + do_action( |
|
| 1098 | + 'AHEE__EE_Ticket__decrease_reserved', |
|
| 1099 | + $this, |
|
| 1100 | + $qty, |
|
| 1101 | + $this->reserved(), |
|
| 1102 | + $success |
|
| 1103 | + ); |
|
| 1104 | + return $success; |
|
| 1105 | + } |
|
| 1106 | + |
|
| 1107 | + |
|
| 1108 | + /** |
|
| 1109 | + * Decreases the reserved count on the specified datetimes. |
|
| 1110 | + * |
|
| 1111 | + * @param int $qty |
|
| 1112 | + * @param EE_Datetime[] $datetimes |
|
| 1113 | + * @throws EE_Error |
|
| 1114 | + * @throws InvalidArgumentException |
|
| 1115 | + * @throws ReflectionException |
|
| 1116 | + * @throws InvalidDataTypeException |
|
| 1117 | + * @throws InvalidInterfaceException |
|
| 1118 | + * @since 4.9.80.p |
|
| 1119 | + */ |
|
| 1120 | + protected function decreaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
| 1121 | + { |
|
| 1122 | + $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 1123 | + foreach ($datetimes as $datetime) { |
|
| 1124 | + if ($datetime instanceof EE_Datetime) { |
|
| 1125 | + $datetime->decreaseReserved($qty); |
|
| 1126 | + } |
|
| 1127 | + } |
|
| 1128 | + } |
|
| 1129 | + |
|
| 1130 | + |
|
| 1131 | + /** |
|
| 1132 | + * Gets ticket quantity |
|
| 1133 | + * |
|
| 1134 | + * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 1135 | + * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
|
| 1136 | + * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
|
| 1137 | + * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 1138 | + * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 1139 | + * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 1140 | + * @return int |
|
| 1141 | + * @throws EE_Error |
|
| 1142 | + * @throws ReflectionException |
|
| 1143 | + */ |
|
| 1144 | + public function qty($context = '') |
|
| 1145 | + { |
|
| 1146 | + switch ($context) { |
|
| 1147 | + case 'reg_limit': |
|
| 1148 | + return $this->real_quantity_on_ticket(); |
|
| 1149 | + case 'saleable': |
|
| 1150 | + return $this->real_quantity_on_ticket('saleable'); |
|
| 1151 | + default: |
|
| 1152 | + return $this->get_raw('TKT_qty'); |
|
| 1153 | + } |
|
| 1154 | + } |
|
| 1155 | + |
|
| 1156 | + |
|
| 1157 | + /** |
|
| 1158 | + * Gets ticket quantity |
|
| 1159 | + * |
|
| 1160 | + * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 1161 | + * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
|
| 1162 | + * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 1163 | + * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 1164 | + * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 1165 | + * @param int $DTT_ID the primary key for a particular datetime. |
|
| 1166 | + * set to 0 for all related datetimes |
|
| 1167 | + * @return int |
|
| 1168 | + * @throws EE_Error |
|
| 1169 | + * @throws ReflectionException |
|
| 1170 | + */ |
|
| 1171 | + public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) |
|
| 1172 | + { |
|
| 1173 | + $raw = $this->get_raw('TKT_qty'); |
|
| 1174 | + // return immediately if it's zero |
|
| 1175 | + if ($raw === 0) { |
|
| 1176 | + return $raw; |
|
| 1177 | + } |
|
| 1178 | + // echo "\n\n<br />Ticket: " . $this->name() . '<br />'; |
|
| 1179 | + // ensure qty doesn't exceed raw value for THIS ticket |
|
| 1180 | + $qty = min(EE_INF, $raw); |
|
| 1181 | + // echo "\n . qty: " . $qty . '<br />'; |
|
| 1182 | + // calculate this ticket's total sales and reservations |
|
| 1183 | + $sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved(); |
|
| 1184 | + // echo "\n . sold: " . $this->sold() . '<br />'; |
|
| 1185 | + // echo "\n . reserved: " . $this->reserved() . '<br />'; |
|
| 1186 | + // echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />'; |
|
| 1187 | + // first we need to calculate the maximum number of tickets available for the datetime |
|
| 1188 | + // do we want data for one datetime or all of them ? |
|
| 1189 | + $query_params = $DTT_ID ? [['DTT_ID' => $DTT_ID]] : []; |
|
| 1190 | + $datetimes = $this->datetimes($query_params); |
|
| 1191 | + if (is_array($datetimes) && ! empty($datetimes)) { |
|
| 1192 | + foreach ($datetimes as $datetime) { |
|
| 1193 | + if ($datetime instanceof EE_Datetime) { |
|
| 1194 | + $datetime->refresh_from_db(); |
|
| 1195 | + // echo "\n . . datetime name: " . $datetime->name() . '<br />'; |
|
| 1196 | + // echo "\n . . datetime ID: " . $datetime->ID() . '<br />'; |
|
| 1197 | + // initialize with no restrictions for each datetime |
|
| 1198 | + // but adjust datetime qty based on datetime reg limit |
|
| 1199 | + $datetime_qty = min(EE_INF, $datetime->reg_limit()); |
|
| 1200 | + // echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />'; |
|
| 1201 | + // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1202 | + // if we want the actual saleable amount, then we need to consider OTHER ticket sales |
|
| 1203 | + // and reservations for this datetime, that do NOT include sales and reservations |
|
| 1204 | + // for this ticket (so we add $this->sold() and $this->reserved() back in) |
|
| 1205 | + if ($context === 'saleable') { |
|
| 1206 | + $datetime_qty = max( |
|
| 1207 | + $datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket, |
|
| 1208 | + 0 |
|
| 1209 | + ); |
|
| 1210 | + // echo "\n . . . datetime sold: " . $datetime->sold() . '<br />'; |
|
| 1211 | + // echo "\n . . . datetime reserved: " . $datetime->reserved() . '<br />'; |
|
| 1212 | + // echo "\n . . . datetime sold_and_reserved: " . $datetime->sold_and_reserved() . '<br />'; |
|
| 1213 | + // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1214 | + $datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0; |
|
| 1215 | + // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1216 | + } |
|
| 1217 | + $qty = min($datetime_qty, $qty); |
|
| 1218 | + // echo "\n . . qty: " . $qty . '<br />'; |
|
| 1219 | + } |
|
| 1220 | + } |
|
| 1221 | + } |
|
| 1222 | + // NOW that we know the maximum number of tickets available for the datetime |
|
| 1223 | + // we can finally factor in the details for this specific ticket |
|
| 1224 | + if ($qty > 0 && $context === 'saleable') { |
|
| 1225 | + // and subtract the sales for THIS ticket |
|
| 1226 | + $qty = max($qty - $sold_and_reserved_for_this_ticket, 0); |
|
| 1227 | + // echo "\n . qty: " . $qty . '<br />'; |
|
| 1228 | + } |
|
| 1229 | + // echo "\nFINAL QTY: " . $qty . "<br /><br />"; |
|
| 1230 | + return $qty; |
|
| 1231 | + } |
|
| 1232 | + |
|
| 1233 | + |
|
| 1234 | + /** |
|
| 1235 | + * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes |
|
| 1236 | + * |
|
| 1237 | + * @param int $qty |
|
| 1238 | + * @return void |
|
| 1239 | + * @throws EE_Error |
|
| 1240 | + * @throws ReflectionException |
|
| 1241 | + */ |
|
| 1242 | + public function set_qty($qty) |
|
| 1243 | + { |
|
| 1244 | + $datetimes = $this->datetimes(); |
|
| 1245 | + foreach ($datetimes as $datetime) { |
|
| 1246 | + if ($datetime instanceof EE_Datetime) { |
|
| 1247 | + $qty = min($qty, $datetime->reg_limit()); |
|
| 1248 | + } |
|
| 1249 | + } |
|
| 1250 | + $this->set('TKT_qty', $qty); |
|
| 1251 | + } |
|
| 1252 | + |
|
| 1253 | + |
|
| 1254 | + /** |
|
| 1255 | + * Gets uses |
|
| 1256 | + * |
|
| 1257 | + * @return int |
|
| 1258 | + * @throws EE_Error |
|
| 1259 | + * @throws ReflectionException |
|
| 1260 | + */ |
|
| 1261 | + public function uses() |
|
| 1262 | + { |
|
| 1263 | + return $this->get('TKT_uses'); |
|
| 1264 | + } |
|
| 1265 | + |
|
| 1266 | + |
|
| 1267 | + /** |
|
| 1268 | + * Sets uses |
|
| 1269 | + * |
|
| 1270 | + * @param int $uses |
|
| 1271 | + * @return void |
|
| 1272 | + * @throws EE_Error |
|
| 1273 | + * @throws ReflectionException |
|
| 1274 | + */ |
|
| 1275 | + public function set_uses($uses) |
|
| 1276 | + { |
|
| 1277 | + $this->set('TKT_uses', $uses); |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + |
|
| 1281 | + /** |
|
| 1282 | + * returns whether ticket is required or not. |
|
| 1283 | + * |
|
| 1284 | + * @return boolean |
|
| 1285 | + * @throws EE_Error |
|
| 1286 | + * @throws ReflectionException |
|
| 1287 | + */ |
|
| 1288 | + public function required() |
|
| 1289 | + { |
|
| 1290 | + return $this->get('TKT_required'); |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + |
|
| 1294 | + /** |
|
| 1295 | + * sets the TKT_required property |
|
| 1296 | + * |
|
| 1297 | + * @param boolean $required |
|
| 1298 | + * @return void |
|
| 1299 | + * @throws EE_Error |
|
| 1300 | + * @throws ReflectionException |
|
| 1301 | + */ |
|
| 1302 | + public function set_required($required) |
|
| 1303 | + { |
|
| 1304 | + $this->set('TKT_required', $required); |
|
| 1305 | + } |
|
| 1306 | + |
|
| 1307 | + |
|
| 1308 | + /** |
|
| 1309 | + * Gets taxable |
|
| 1310 | + * |
|
| 1311 | + * @return boolean |
|
| 1312 | + * @throws EE_Error |
|
| 1313 | + * @throws ReflectionException |
|
| 1314 | + */ |
|
| 1315 | + public function taxable() |
|
| 1316 | + { |
|
| 1317 | + return $this->get('TKT_taxable'); |
|
| 1318 | + } |
|
| 1319 | + |
|
| 1320 | + |
|
| 1321 | + /** |
|
| 1322 | + * Sets taxable |
|
| 1323 | + * |
|
| 1324 | + * @param boolean $taxable |
|
| 1325 | + * @return void |
|
| 1326 | + * @throws EE_Error |
|
| 1327 | + * @throws ReflectionException |
|
| 1328 | + */ |
|
| 1329 | + public function set_taxable($taxable) |
|
| 1330 | + { |
|
| 1331 | + $this->set('TKT_taxable', $taxable); |
|
| 1332 | + } |
|
| 1333 | + |
|
| 1334 | + |
|
| 1335 | + /** |
|
| 1336 | + * Gets is_default |
|
| 1337 | + * |
|
| 1338 | + * @return boolean |
|
| 1339 | + * @throws EE_Error |
|
| 1340 | + * @throws ReflectionException |
|
| 1341 | + */ |
|
| 1342 | + public function is_default() |
|
| 1343 | + { |
|
| 1344 | + return $this->get('TKT_is_default'); |
|
| 1345 | + } |
|
| 1346 | + |
|
| 1347 | + |
|
| 1348 | + /** |
|
| 1349 | + * Sets is_default |
|
| 1350 | + * |
|
| 1351 | + * @param boolean $is_default |
|
| 1352 | + * @return void |
|
| 1353 | + * @throws EE_Error |
|
| 1354 | + * @throws ReflectionException |
|
| 1355 | + */ |
|
| 1356 | + public function set_is_default($is_default) |
|
| 1357 | + { |
|
| 1358 | + $this->set('TKT_is_default', $is_default); |
|
| 1359 | + } |
|
| 1360 | + |
|
| 1361 | + |
|
| 1362 | + /** |
|
| 1363 | + * Gets order |
|
| 1364 | + * |
|
| 1365 | + * @return int |
|
| 1366 | + * @throws EE_Error |
|
| 1367 | + * @throws ReflectionException |
|
| 1368 | + */ |
|
| 1369 | + public function order() |
|
| 1370 | + { |
|
| 1371 | + return $this->get('TKT_order'); |
|
| 1372 | + } |
|
| 1373 | + |
|
| 1374 | + |
|
| 1375 | + /** |
|
| 1376 | + * Sets order |
|
| 1377 | + * |
|
| 1378 | + * @param int $order |
|
| 1379 | + * @return void |
|
| 1380 | + * @throws EE_Error |
|
| 1381 | + * @throws ReflectionException |
|
| 1382 | + */ |
|
| 1383 | + public function set_order($order) |
|
| 1384 | + { |
|
| 1385 | + $this->set('TKT_order', $order); |
|
| 1386 | + } |
|
| 1387 | + |
|
| 1388 | + |
|
| 1389 | + /** |
|
| 1390 | + * Gets row |
|
| 1391 | + * |
|
| 1392 | + * @return int |
|
| 1393 | + * @throws EE_Error |
|
| 1394 | + * @throws ReflectionException |
|
| 1395 | + */ |
|
| 1396 | + public function row() |
|
| 1397 | + { |
|
| 1398 | + return $this->get('TKT_row'); |
|
| 1399 | + } |
|
| 1400 | + |
|
| 1401 | + |
|
| 1402 | + /** |
|
| 1403 | + * Sets row |
|
| 1404 | + * |
|
| 1405 | + * @param int $row |
|
| 1406 | + * @return void |
|
| 1407 | + * @throws EE_Error |
|
| 1408 | + * @throws ReflectionException |
|
| 1409 | + */ |
|
| 1410 | + public function set_row($row) |
|
| 1411 | + { |
|
| 1412 | + $this->set('TKT_row', $row); |
|
| 1413 | + } |
|
| 1414 | + |
|
| 1415 | + |
|
| 1416 | + /** |
|
| 1417 | + * Gets deleted |
|
| 1418 | + * |
|
| 1419 | + * @return boolean |
|
| 1420 | + * @throws EE_Error |
|
| 1421 | + * @throws ReflectionException |
|
| 1422 | + */ |
|
| 1423 | + public function deleted() |
|
| 1424 | + { |
|
| 1425 | + return $this->get('TKT_deleted'); |
|
| 1426 | + } |
|
| 1427 | + |
|
| 1428 | + |
|
| 1429 | + /** |
|
| 1430 | + * Sets deleted |
|
| 1431 | + * |
|
| 1432 | + * @param boolean $deleted |
|
| 1433 | + * @return void |
|
| 1434 | + * @throws EE_Error |
|
| 1435 | + * @throws ReflectionException |
|
| 1436 | + */ |
|
| 1437 | + public function set_deleted($deleted) |
|
| 1438 | + { |
|
| 1439 | + $this->set('TKT_deleted', $deleted); |
|
| 1440 | + } |
|
| 1441 | + |
|
| 1442 | + |
|
| 1443 | + /** |
|
| 1444 | + * Gets parent |
|
| 1445 | + * |
|
| 1446 | + * @return int |
|
| 1447 | + * @throws EE_Error |
|
| 1448 | + * @throws ReflectionException |
|
| 1449 | + */ |
|
| 1450 | + public function parent_ID() |
|
| 1451 | + { |
|
| 1452 | + return $this->get('TKT_parent'); |
|
| 1453 | + } |
|
| 1454 | + |
|
| 1455 | + |
|
| 1456 | + /** |
|
| 1457 | + * Sets parent |
|
| 1458 | + * |
|
| 1459 | + * @param int $parent |
|
| 1460 | + * @return void |
|
| 1461 | + * @throws EE_Error |
|
| 1462 | + * @throws ReflectionException |
|
| 1463 | + */ |
|
| 1464 | + public function set_parent_ID($parent) |
|
| 1465 | + { |
|
| 1466 | + $this->set('TKT_parent', $parent); |
|
| 1467 | + } |
|
| 1468 | + |
|
| 1469 | + |
|
| 1470 | + /** |
|
| 1471 | + * @return boolean |
|
| 1472 | + * @throws EE_Error |
|
| 1473 | + * @throws InvalidArgumentException |
|
| 1474 | + * @throws InvalidDataTypeException |
|
| 1475 | + * @throws InvalidInterfaceException |
|
| 1476 | + * @throws ReflectionException |
|
| 1477 | + */ |
|
| 1478 | + public function reverse_calculate() |
|
| 1479 | + { |
|
| 1480 | + return $this->get('TKT_reverse_calculate'); |
|
| 1481 | + } |
|
| 1482 | + |
|
| 1483 | + |
|
| 1484 | + /** |
|
| 1485 | + * @param boolean $reverse_calculate |
|
| 1486 | + * @throws EE_Error |
|
| 1487 | + * @throws InvalidArgumentException |
|
| 1488 | + * @throws InvalidDataTypeException |
|
| 1489 | + * @throws InvalidInterfaceException |
|
| 1490 | + * @throws ReflectionException |
|
| 1491 | + */ |
|
| 1492 | + public function set_reverse_calculate($reverse_calculate) |
|
| 1493 | + { |
|
| 1494 | + $this->set('TKT_reverse_calculate', $reverse_calculate); |
|
| 1495 | + } |
|
| 1496 | + |
|
| 1497 | + |
|
| 1498 | + /** |
|
| 1499 | + * Gets a string which is handy for showing in gateways etc that describes the ticket. |
|
| 1500 | + * |
|
| 1501 | + * @return string |
|
| 1502 | + * @throws EE_Error |
|
| 1503 | + * @throws ReflectionException |
|
| 1504 | + */ |
|
| 1505 | + public function name_and_info() |
|
| 1506 | + { |
|
| 1507 | + $times = []; |
|
| 1508 | + foreach ($this->datetimes() as $datetime) { |
|
| 1509 | + $times[] = $datetime->start_date_and_time(); |
|
| 1510 | + } |
|
| 1511 | + return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price(); |
|
| 1512 | + } |
|
| 1513 | + |
|
| 1514 | + |
|
| 1515 | + /** |
|
| 1516 | + * Gets name |
|
| 1517 | + * |
|
| 1518 | + * @return string |
|
| 1519 | + * @throws EE_Error |
|
| 1520 | + * @throws ReflectionException |
|
| 1521 | + */ |
|
| 1522 | + public function name() |
|
| 1523 | + { |
|
| 1524 | + return $this->get('TKT_name'); |
|
| 1525 | + } |
|
| 1526 | + |
|
| 1527 | + |
|
| 1528 | + /** |
|
| 1529 | + * Gets price |
|
| 1530 | + * |
|
| 1531 | + * @return float |
|
| 1532 | + * @throws EE_Error |
|
| 1533 | + * @throws ReflectionException |
|
| 1534 | + */ |
|
| 1535 | + public function price() |
|
| 1536 | + { |
|
| 1537 | + return $this->get('TKT_price'); |
|
| 1538 | + } |
|
| 1539 | + |
|
| 1540 | + |
|
| 1541 | + /** |
|
| 1542 | + * Gets all the registrations for this ticket |
|
| 1543 | + * |
|
| 1544 | + * @param array $query_params @see |
|
| 1545 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1546 | + * @return EE_Registration[]|EE_Base_Class[] |
|
| 1547 | + * @throws EE_Error |
|
| 1548 | + * @throws ReflectionException |
|
| 1549 | + */ |
|
| 1550 | + public function registrations($query_params = []) |
|
| 1551 | + { |
|
| 1552 | + return $this->get_many_related('Registration', $query_params); |
|
| 1553 | + } |
|
| 1554 | + |
|
| 1555 | + |
|
| 1556 | + /** |
|
| 1557 | + * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
|
| 1558 | + * |
|
| 1559 | + * @return int |
|
| 1560 | + * @throws EE_Error |
|
| 1561 | + * @throws ReflectionException |
|
| 1562 | + */ |
|
| 1563 | + public function update_tickets_sold() |
|
| 1564 | + { |
|
| 1565 | + $count_regs_for_this_ticket = $this->count_registrations( |
|
| 1566 | + [ |
|
| 1567 | + [ |
|
| 1568 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1569 | + 'REG_deleted' => 0, |
|
| 1570 | + ], |
|
| 1571 | + ] |
|
| 1572 | + ); |
|
| 1573 | + $this->set_sold($count_regs_for_this_ticket); |
|
| 1574 | + $this->save(); |
|
| 1575 | + return $count_regs_for_this_ticket; |
|
| 1576 | + } |
|
| 1577 | + |
|
| 1578 | + |
|
| 1579 | + /** |
|
| 1580 | + * Counts the registrations for this ticket |
|
| 1581 | + * |
|
| 1582 | + * @param array $query_params @see |
|
| 1583 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1584 | + * @return int |
|
| 1585 | + * @throws EE_Error |
|
| 1586 | + * @throws ReflectionException |
|
| 1587 | + */ |
|
| 1588 | + public function count_registrations($query_params = []) |
|
| 1589 | + { |
|
| 1590 | + return $this->count_related('Registration', $query_params); |
|
| 1591 | + } |
|
| 1592 | + |
|
| 1593 | + |
|
| 1594 | + /** |
|
| 1595 | + * Implementation for EEI_Has_Icon interface method. |
|
| 1596 | + * |
|
| 1597 | + * @return string |
|
| 1598 | + * @see EEI_Visual_Representation for comments |
|
| 1599 | + */ |
|
| 1600 | + public function get_icon() |
|
| 1601 | + { |
|
| 1602 | + return '<span class="dashicons dashicons-tickets-alt"/>'; |
|
| 1603 | + } |
|
| 1604 | + |
|
| 1605 | + |
|
| 1606 | + /** |
|
| 1607 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1608 | + * |
|
| 1609 | + * @return EE_Event |
|
| 1610 | + * @throws EE_Error |
|
| 1611 | + * @throws UnexpectedEntityException |
|
| 1612 | + * @throws ReflectionException |
|
| 1613 | + * @see EEI_Event_Relation for comments |
|
| 1614 | + */ |
|
| 1615 | + public function get_related_event() |
|
| 1616 | + { |
|
| 1617 | + // get one datetime to use for getting the event |
|
| 1618 | + $datetime = $this->first_datetime(); |
|
| 1619 | + if (! $datetime instanceof EE_Datetime) { |
|
| 1620 | + throw new UnexpectedEntityException( |
|
| 1621 | + $datetime, |
|
| 1622 | + 'EE_Datetime', |
|
| 1623 | + sprintf( |
|
| 1624 | + __('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
|
| 1625 | + $this->name() |
|
| 1626 | + ) |
|
| 1627 | + ); |
|
| 1628 | + } |
|
| 1629 | + $event = $datetime->event(); |
|
| 1630 | + if (! $event instanceof EE_Event) { |
|
| 1631 | + throw new UnexpectedEntityException( |
|
| 1632 | + $event, |
|
| 1633 | + 'EE_Event', |
|
| 1634 | + sprintf( |
|
| 1635 | + __('The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
|
| 1636 | + $this->name() |
|
| 1637 | + ) |
|
| 1638 | + ); |
|
| 1639 | + } |
|
| 1640 | + return $event; |
|
| 1641 | + } |
|
| 1642 | + |
|
| 1643 | + |
|
| 1644 | + /** |
|
| 1645 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1646 | + * |
|
| 1647 | + * @return string |
|
| 1648 | + * @throws UnexpectedEntityException |
|
| 1649 | + * @throws EE_Error |
|
| 1650 | + * @throws ReflectionException |
|
| 1651 | + * @see EEI_Event_Relation for comments |
|
| 1652 | + */ |
|
| 1653 | + public function get_event_name() |
|
| 1654 | + { |
|
| 1655 | + $event = $this->get_related_event(); |
|
| 1656 | + return $event instanceof EE_Event ? $event->name() : ''; |
|
| 1657 | + } |
|
| 1658 | + |
|
| 1659 | + |
|
| 1660 | + /** |
|
| 1661 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1662 | + * |
|
| 1663 | + * @return int |
|
| 1664 | + * @throws UnexpectedEntityException |
|
| 1665 | + * @throws EE_Error |
|
| 1666 | + * @throws ReflectionException |
|
| 1667 | + * @see EEI_Event_Relation for comments |
|
| 1668 | + */ |
|
| 1669 | + public function get_event_ID() |
|
| 1670 | + { |
|
| 1671 | + $event = $this->get_related_event(); |
|
| 1672 | + return $event instanceof EE_Event ? $event->ID() : 0; |
|
| 1673 | + } |
|
| 1674 | + |
|
| 1675 | + |
|
| 1676 | + /** |
|
| 1677 | + * This simply returns whether a ticket can be permanently deleted or not. |
|
| 1678 | + * The criteria for determining this is whether the ticket has any related registrations. |
|
| 1679 | + * If there are none then it can be permanently deleted. |
|
| 1680 | + * |
|
| 1681 | + * @return bool |
|
| 1682 | + * @throws EE_Error |
|
| 1683 | + * @throws ReflectionException |
|
| 1684 | + */ |
|
| 1685 | + public function is_permanently_deleteable() |
|
| 1686 | + { |
|
| 1687 | + return $this->count_registrations() === 0; |
|
| 1688 | + } |
|
| 1689 | + |
|
| 1690 | + |
|
| 1691 | + /** |
|
| 1692 | + * @return int |
|
| 1693 | + * @throws EE_Error |
|
| 1694 | + * @throws ReflectionException |
|
| 1695 | + * @since $VID:$ |
|
| 1696 | + */ |
|
| 1697 | + public function visibility(): int |
|
| 1698 | + { |
|
| 1699 | + return $this->get('TKT_visibility'); |
|
| 1700 | + } |
|
| 1701 | + |
|
| 1702 | + |
|
| 1703 | + /** |
|
| 1704 | + * @param int $visibility |
|
| 1705 | + * @throws EE_Error |
|
| 1706 | + * @throws ReflectionException |
|
| 1707 | + * @since $VID:$ |
|
| 1708 | + */ |
|
| 1709 | + public function set_visibility(int $visibility) |
|
| 1710 | + { |
|
| 1711 | + $ticket_visibility = EEM_Ticket::instance()->ticketVisibility(); |
|
| 1712 | + if (! isset($ticket_visibility[ $visibility ])) { |
|
| 1713 | + throw new DomainException( |
|
| 1714 | + sprintf( |
|
| 1715 | + esc_html__( |
|
| 1716 | + 'The supplied ticket visibility setting of "%1$s" is not valid. It needs to match one of the keys in the following array:%2$s %3$s ', |
|
| 1717 | + 'event_espresso' |
|
| 1718 | + ), |
|
| 1719 | + $visibility, |
|
| 1720 | + '<br />', |
|
| 1721 | + var_export($ticket_visibility, true) |
|
| 1722 | + ) |
|
| 1723 | + ); |
|
| 1724 | + } |
|
| 1725 | + $this->set('TKT_visibility', $visibility); |
|
| 1726 | + } |
|
| 1727 | + |
|
| 1728 | + |
|
| 1729 | + /******************************************************************* |
|
| 1730 | 1730 | *********************** DEPRECATED METHODS ********************** |
| 1731 | 1731 | *******************************************************************/ |
| 1732 | 1732 | |
| 1733 | 1733 | |
| 1734 | - /** |
|
| 1735 | - * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
|
| 1736 | - * associated datetimes. |
|
| 1737 | - * |
|
| 1738 | - * @param int $qty |
|
| 1739 | - * @return void |
|
| 1740 | - * @throws EE_Error |
|
| 1741 | - * @throws InvalidArgumentException |
|
| 1742 | - * @throws InvalidDataTypeException |
|
| 1743 | - * @throws InvalidInterfaceException |
|
| 1744 | - * @throws ReflectionException |
|
| 1745 | - * @deprecated 4.9.80.p |
|
| 1746 | - */ |
|
| 1747 | - public function increase_sold($qty = 1) |
|
| 1748 | - { |
|
| 1749 | - EE_Error::doing_it_wrong( |
|
| 1750 | - __FUNCTION__, |
|
| 1751 | - esc_html__('Please use EE_Ticket::increaseSold() instead', 'event_espresso'), |
|
| 1752 | - '4.9.80.p', |
|
| 1753 | - '5.0.0.p' |
|
| 1754 | - ); |
|
| 1755 | - $this->increaseSold($qty); |
|
| 1756 | - } |
|
| 1757 | - |
|
| 1758 | - |
|
| 1759 | - /** |
|
| 1760 | - * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
|
| 1761 | - * |
|
| 1762 | - * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved counts), |
|
| 1763 | - * Negative means to decreases old counts (and increase reserved counts). |
|
| 1764 | - * @throws EE_Error |
|
| 1765 | - * @throws InvalidArgumentException |
|
| 1766 | - * @throws InvalidDataTypeException |
|
| 1767 | - * @throws InvalidInterfaceException |
|
| 1768 | - * @throws ReflectionException |
|
| 1769 | - * @deprecated 4.9.80.p |
|
| 1770 | - */ |
|
| 1771 | - protected function _increase_sold_for_datetimes($qty) |
|
| 1772 | - { |
|
| 1773 | - EE_Error::doing_it_wrong( |
|
| 1774 | - __FUNCTION__, |
|
| 1775 | - esc_html__('Please use EE_Ticket::increaseSoldForDatetimes() instead', 'event_espresso'), |
|
| 1776 | - '4.9.80.p', |
|
| 1777 | - '5.0.0.p' |
|
| 1778 | - ); |
|
| 1779 | - $this->increaseSoldForDatetimes($qty); |
|
| 1780 | - } |
|
| 1781 | - |
|
| 1782 | - |
|
| 1783 | - /** |
|
| 1784 | - * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
|
| 1785 | - * DB and then updates the model objects. |
|
| 1786 | - * Does not affect the reserved counts. |
|
| 1787 | - * |
|
| 1788 | - * @param int $qty |
|
| 1789 | - * @return void |
|
| 1790 | - * @throws EE_Error |
|
| 1791 | - * @throws InvalidArgumentException |
|
| 1792 | - * @throws InvalidDataTypeException |
|
| 1793 | - * @throws InvalidInterfaceException |
|
| 1794 | - * @throws ReflectionException |
|
| 1795 | - * @deprecated 4.9.80.p |
|
| 1796 | - */ |
|
| 1797 | - public function decrease_sold($qty = 1) |
|
| 1798 | - { |
|
| 1799 | - EE_Error::doing_it_wrong( |
|
| 1800 | - __FUNCTION__, |
|
| 1801 | - esc_html__('Please use EE_Ticket::decreaseSold() instead', 'event_espresso'), |
|
| 1802 | - '4.9.80.p', |
|
| 1803 | - '5.0.0.p' |
|
| 1804 | - ); |
|
| 1805 | - $this->decreaseSold($qty); |
|
| 1806 | - } |
|
| 1807 | - |
|
| 1808 | - |
|
| 1809 | - /** |
|
| 1810 | - * Decreases sold on related datetimes |
|
| 1811 | - * |
|
| 1812 | - * @param int $qty |
|
| 1813 | - * @return void |
|
| 1814 | - * @throws EE_Error |
|
| 1815 | - * @throws InvalidArgumentException |
|
| 1816 | - * @throws InvalidDataTypeException |
|
| 1817 | - * @throws InvalidInterfaceException |
|
| 1818 | - * @throws ReflectionException |
|
| 1819 | - * @deprecated 4.9.80.p |
|
| 1820 | - */ |
|
| 1821 | - protected function _decrease_sold_for_datetimes($qty = 1) |
|
| 1822 | - { |
|
| 1823 | - EE_Error::doing_it_wrong( |
|
| 1824 | - __FUNCTION__, |
|
| 1825 | - esc_html__('Please use EE_Ticket::decreaseSoldForDatetimes() instead', 'event_espresso'), |
|
| 1826 | - '4.9.80.p', |
|
| 1827 | - '5.0.0.p' |
|
| 1828 | - ); |
|
| 1829 | - $this->decreaseSoldForDatetimes($qty); |
|
| 1830 | - } |
|
| 1831 | - |
|
| 1832 | - |
|
| 1833 | - /** |
|
| 1834 | - * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1835 | - * |
|
| 1836 | - * @param int $qty |
|
| 1837 | - * @param string $source |
|
| 1838 | - * @return bool whether we successfully reserved the ticket or not. |
|
| 1839 | - * @throws EE_Error |
|
| 1840 | - * @throws InvalidArgumentException |
|
| 1841 | - * @throws ReflectionException |
|
| 1842 | - * @throws InvalidDataTypeException |
|
| 1843 | - * @throws InvalidInterfaceException |
|
| 1844 | - * @deprecated 4.9.80.p |
|
| 1845 | - */ |
|
| 1846 | - public function increase_reserved($qty = 1, $source = 'unknown') |
|
| 1847 | - { |
|
| 1848 | - EE_Error::doing_it_wrong( |
|
| 1849 | - __FUNCTION__, |
|
| 1850 | - esc_html__('Please use EE_Ticket::increaseReserved() instead', 'event_espresso'), |
|
| 1851 | - '4.9.80.p', |
|
| 1852 | - '5.0.0.p' |
|
| 1853 | - ); |
|
| 1854 | - return $this->increaseReserved($qty); |
|
| 1855 | - } |
|
| 1856 | - |
|
| 1857 | - |
|
| 1858 | - /** |
|
| 1859 | - * Increases sold on related datetimes |
|
| 1860 | - * |
|
| 1861 | - * @param int $qty |
|
| 1862 | - * @return boolean indicating success |
|
| 1863 | - * @throws EE_Error |
|
| 1864 | - * @throws InvalidArgumentException |
|
| 1865 | - * @throws InvalidDataTypeException |
|
| 1866 | - * @throws InvalidInterfaceException |
|
| 1867 | - * @throws ReflectionException |
|
| 1868 | - * @deprecated 4.9.80.p |
|
| 1869 | - */ |
|
| 1870 | - protected function _increase_reserved_for_datetimes($qty = 1) |
|
| 1871 | - { |
|
| 1872 | - EE_Error::doing_it_wrong( |
|
| 1873 | - __FUNCTION__, |
|
| 1874 | - esc_html__('Please use EE_Ticket::increaseReservedForDatetimes() instead', 'event_espresso'), |
|
| 1875 | - '4.9.80.p', |
|
| 1876 | - '5.0.0.p' |
|
| 1877 | - ); |
|
| 1878 | - return $this->increaseReservedForDatetimes($qty); |
|
| 1879 | - } |
|
| 1880 | - |
|
| 1881 | - |
|
| 1882 | - /** |
|
| 1883 | - * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1884 | - * |
|
| 1885 | - * @param int $qty |
|
| 1886 | - * @param bool $adjust_datetimes |
|
| 1887 | - * @param string $source |
|
| 1888 | - * @return void |
|
| 1889 | - * @throws EE_Error |
|
| 1890 | - * @throws InvalidArgumentException |
|
| 1891 | - * @throws ReflectionException |
|
| 1892 | - * @throws InvalidDataTypeException |
|
| 1893 | - * @throws InvalidInterfaceException |
|
| 1894 | - * @deprecated 4.9.80.p |
|
| 1895 | - */ |
|
| 1896 | - public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
| 1897 | - { |
|
| 1898 | - EE_Error::doing_it_wrong( |
|
| 1899 | - __FUNCTION__, |
|
| 1900 | - esc_html__('Please use EE_Ticket::decreaseReserved() instead', 'event_espresso'), |
|
| 1901 | - '4.9.80.p', |
|
| 1902 | - '5.0.0.p' |
|
| 1903 | - ); |
|
| 1904 | - $this->decreaseReserved($qty); |
|
| 1905 | - } |
|
| 1906 | - |
|
| 1907 | - |
|
| 1908 | - /** |
|
| 1909 | - * Decreases reserved on related datetimes |
|
| 1910 | - * |
|
| 1911 | - * @param int $qty |
|
| 1912 | - * @return void |
|
| 1913 | - * @throws EE_Error |
|
| 1914 | - * @throws InvalidArgumentException |
|
| 1915 | - * @throws ReflectionException |
|
| 1916 | - * @throws InvalidDataTypeException |
|
| 1917 | - * @throws InvalidInterfaceException |
|
| 1918 | - * @deprecated 4.9.80.p |
|
| 1919 | - */ |
|
| 1920 | - protected function _decrease_reserved_for_datetimes($qty = 1) |
|
| 1921 | - { |
|
| 1922 | - EE_Error::doing_it_wrong( |
|
| 1923 | - __FUNCTION__, |
|
| 1924 | - esc_html__('Please use EE_Ticket::decreaseReservedForDatetimes() instead', 'event_espresso'), |
|
| 1925 | - '4.9.80.p', |
|
| 1926 | - '5.0.0.p' |
|
| 1927 | - ); |
|
| 1928 | - $this->decreaseReservedForDatetimes($qty); |
|
| 1929 | - } |
|
| 1734 | + /** |
|
| 1735 | + * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
|
| 1736 | + * associated datetimes. |
|
| 1737 | + * |
|
| 1738 | + * @param int $qty |
|
| 1739 | + * @return void |
|
| 1740 | + * @throws EE_Error |
|
| 1741 | + * @throws InvalidArgumentException |
|
| 1742 | + * @throws InvalidDataTypeException |
|
| 1743 | + * @throws InvalidInterfaceException |
|
| 1744 | + * @throws ReflectionException |
|
| 1745 | + * @deprecated 4.9.80.p |
|
| 1746 | + */ |
|
| 1747 | + public function increase_sold($qty = 1) |
|
| 1748 | + { |
|
| 1749 | + EE_Error::doing_it_wrong( |
|
| 1750 | + __FUNCTION__, |
|
| 1751 | + esc_html__('Please use EE_Ticket::increaseSold() instead', 'event_espresso'), |
|
| 1752 | + '4.9.80.p', |
|
| 1753 | + '5.0.0.p' |
|
| 1754 | + ); |
|
| 1755 | + $this->increaseSold($qty); |
|
| 1756 | + } |
|
| 1757 | + |
|
| 1758 | + |
|
| 1759 | + /** |
|
| 1760 | + * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
|
| 1761 | + * |
|
| 1762 | + * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved counts), |
|
| 1763 | + * Negative means to decreases old counts (and increase reserved counts). |
|
| 1764 | + * @throws EE_Error |
|
| 1765 | + * @throws InvalidArgumentException |
|
| 1766 | + * @throws InvalidDataTypeException |
|
| 1767 | + * @throws InvalidInterfaceException |
|
| 1768 | + * @throws ReflectionException |
|
| 1769 | + * @deprecated 4.9.80.p |
|
| 1770 | + */ |
|
| 1771 | + protected function _increase_sold_for_datetimes($qty) |
|
| 1772 | + { |
|
| 1773 | + EE_Error::doing_it_wrong( |
|
| 1774 | + __FUNCTION__, |
|
| 1775 | + esc_html__('Please use EE_Ticket::increaseSoldForDatetimes() instead', 'event_espresso'), |
|
| 1776 | + '4.9.80.p', |
|
| 1777 | + '5.0.0.p' |
|
| 1778 | + ); |
|
| 1779 | + $this->increaseSoldForDatetimes($qty); |
|
| 1780 | + } |
|
| 1781 | + |
|
| 1782 | + |
|
| 1783 | + /** |
|
| 1784 | + * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
|
| 1785 | + * DB and then updates the model objects. |
|
| 1786 | + * Does not affect the reserved counts. |
|
| 1787 | + * |
|
| 1788 | + * @param int $qty |
|
| 1789 | + * @return void |
|
| 1790 | + * @throws EE_Error |
|
| 1791 | + * @throws InvalidArgumentException |
|
| 1792 | + * @throws InvalidDataTypeException |
|
| 1793 | + * @throws InvalidInterfaceException |
|
| 1794 | + * @throws ReflectionException |
|
| 1795 | + * @deprecated 4.9.80.p |
|
| 1796 | + */ |
|
| 1797 | + public function decrease_sold($qty = 1) |
|
| 1798 | + { |
|
| 1799 | + EE_Error::doing_it_wrong( |
|
| 1800 | + __FUNCTION__, |
|
| 1801 | + esc_html__('Please use EE_Ticket::decreaseSold() instead', 'event_espresso'), |
|
| 1802 | + '4.9.80.p', |
|
| 1803 | + '5.0.0.p' |
|
| 1804 | + ); |
|
| 1805 | + $this->decreaseSold($qty); |
|
| 1806 | + } |
|
| 1807 | + |
|
| 1808 | + |
|
| 1809 | + /** |
|
| 1810 | + * Decreases sold on related datetimes |
|
| 1811 | + * |
|
| 1812 | + * @param int $qty |
|
| 1813 | + * @return void |
|
| 1814 | + * @throws EE_Error |
|
| 1815 | + * @throws InvalidArgumentException |
|
| 1816 | + * @throws InvalidDataTypeException |
|
| 1817 | + * @throws InvalidInterfaceException |
|
| 1818 | + * @throws ReflectionException |
|
| 1819 | + * @deprecated 4.9.80.p |
|
| 1820 | + */ |
|
| 1821 | + protected function _decrease_sold_for_datetimes($qty = 1) |
|
| 1822 | + { |
|
| 1823 | + EE_Error::doing_it_wrong( |
|
| 1824 | + __FUNCTION__, |
|
| 1825 | + esc_html__('Please use EE_Ticket::decreaseSoldForDatetimes() instead', 'event_espresso'), |
|
| 1826 | + '4.9.80.p', |
|
| 1827 | + '5.0.0.p' |
|
| 1828 | + ); |
|
| 1829 | + $this->decreaseSoldForDatetimes($qty); |
|
| 1830 | + } |
|
| 1831 | + |
|
| 1832 | + |
|
| 1833 | + /** |
|
| 1834 | + * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1835 | + * |
|
| 1836 | + * @param int $qty |
|
| 1837 | + * @param string $source |
|
| 1838 | + * @return bool whether we successfully reserved the ticket or not. |
|
| 1839 | + * @throws EE_Error |
|
| 1840 | + * @throws InvalidArgumentException |
|
| 1841 | + * @throws ReflectionException |
|
| 1842 | + * @throws InvalidDataTypeException |
|
| 1843 | + * @throws InvalidInterfaceException |
|
| 1844 | + * @deprecated 4.9.80.p |
|
| 1845 | + */ |
|
| 1846 | + public function increase_reserved($qty = 1, $source = 'unknown') |
|
| 1847 | + { |
|
| 1848 | + EE_Error::doing_it_wrong( |
|
| 1849 | + __FUNCTION__, |
|
| 1850 | + esc_html__('Please use EE_Ticket::increaseReserved() instead', 'event_espresso'), |
|
| 1851 | + '4.9.80.p', |
|
| 1852 | + '5.0.0.p' |
|
| 1853 | + ); |
|
| 1854 | + return $this->increaseReserved($qty); |
|
| 1855 | + } |
|
| 1856 | + |
|
| 1857 | + |
|
| 1858 | + /** |
|
| 1859 | + * Increases sold on related datetimes |
|
| 1860 | + * |
|
| 1861 | + * @param int $qty |
|
| 1862 | + * @return boolean indicating success |
|
| 1863 | + * @throws EE_Error |
|
| 1864 | + * @throws InvalidArgumentException |
|
| 1865 | + * @throws InvalidDataTypeException |
|
| 1866 | + * @throws InvalidInterfaceException |
|
| 1867 | + * @throws ReflectionException |
|
| 1868 | + * @deprecated 4.9.80.p |
|
| 1869 | + */ |
|
| 1870 | + protected function _increase_reserved_for_datetimes($qty = 1) |
|
| 1871 | + { |
|
| 1872 | + EE_Error::doing_it_wrong( |
|
| 1873 | + __FUNCTION__, |
|
| 1874 | + esc_html__('Please use EE_Ticket::increaseReservedForDatetimes() instead', 'event_espresso'), |
|
| 1875 | + '4.9.80.p', |
|
| 1876 | + '5.0.0.p' |
|
| 1877 | + ); |
|
| 1878 | + return $this->increaseReservedForDatetimes($qty); |
|
| 1879 | + } |
|
| 1880 | + |
|
| 1881 | + |
|
| 1882 | + /** |
|
| 1883 | + * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1884 | + * |
|
| 1885 | + * @param int $qty |
|
| 1886 | + * @param bool $adjust_datetimes |
|
| 1887 | + * @param string $source |
|
| 1888 | + * @return void |
|
| 1889 | + * @throws EE_Error |
|
| 1890 | + * @throws InvalidArgumentException |
|
| 1891 | + * @throws ReflectionException |
|
| 1892 | + * @throws InvalidDataTypeException |
|
| 1893 | + * @throws InvalidInterfaceException |
|
| 1894 | + * @deprecated 4.9.80.p |
|
| 1895 | + */ |
|
| 1896 | + public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
| 1897 | + { |
|
| 1898 | + EE_Error::doing_it_wrong( |
|
| 1899 | + __FUNCTION__, |
|
| 1900 | + esc_html__('Please use EE_Ticket::decreaseReserved() instead', 'event_espresso'), |
|
| 1901 | + '4.9.80.p', |
|
| 1902 | + '5.0.0.p' |
|
| 1903 | + ); |
|
| 1904 | + $this->decreaseReserved($qty); |
|
| 1905 | + } |
|
| 1906 | + |
|
| 1907 | + |
|
| 1908 | + /** |
|
| 1909 | + * Decreases reserved on related datetimes |
|
| 1910 | + * |
|
| 1911 | + * @param int $qty |
|
| 1912 | + * @return void |
|
| 1913 | + * @throws EE_Error |
|
| 1914 | + * @throws InvalidArgumentException |
|
| 1915 | + * @throws ReflectionException |
|
| 1916 | + * @throws InvalidDataTypeException |
|
| 1917 | + * @throws InvalidInterfaceException |
|
| 1918 | + * @deprecated 4.9.80.p |
|
| 1919 | + */ |
|
| 1920 | + protected function _decrease_reserved_for_datetimes($qty = 1) |
|
| 1921 | + { |
|
| 1922 | + EE_Error::doing_it_wrong( |
|
| 1923 | + __FUNCTION__, |
|
| 1924 | + esc_html__('Please use EE_Ticket::decreaseReservedForDatetimes() instead', 'event_espresso'), |
|
| 1925 | + '4.9.80.p', |
|
| 1926 | + '5.0.0.p' |
|
| 1927 | + ); |
|
| 1928 | + $this->decreaseReservedForDatetimes($qty); |
|
| 1929 | + } |
|
| 1930 | 1930 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | public function ticket_status($display = false, $remaining = null) |
| 145 | 145 | { |
| 146 | 146 | $remaining = is_bool($remaining) ? $remaining : $this->is_remaining(); |
| 147 | - if (! $remaining) { |
|
| 147 | + if ( ! $remaining) { |
|
| 148 | 148 | return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out; |
| 149 | 149 | } |
| 150 | 150 | if ($this->get('TKT_deleted')) { |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | ? $this->last_datetime()->get_i18n_datetime('DTT_EVT_end', $date_format) |
| 274 | 274 | : ''; |
| 275 | 275 | |
| 276 | - return $first_date && $last_date ? $first_date . $conjunction . $last_date : ''; |
|
| 276 | + return $first_date && $last_date ? $first_date.$conjunction.$last_date : ''; |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | */ |
| 304 | 304 | public function datetimes($query_params = []) |
| 305 | 305 | { |
| 306 | - if (! isset($query_params['order_by'])) { |
|
| 306 | + if ( ! isset($query_params['order_by'])) { |
|
| 307 | 307 | $query_params['order_by']['DTT_order'] = 'ASC'; |
| 308 | 308 | } |
| 309 | 309 | return $this->get_many_related('Datetime', $query_params); |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | if (empty($tickets_sold['datetime'])) { |
| 351 | 351 | return $total; |
| 352 | 352 | } |
| 353 | - if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) { |
|
| 353 | + if ( ! empty($dtt_id) && ! isset($tickets_sold['datetime'][$dtt_id])) { |
|
| 354 | 354 | EE_Error::add_error( |
| 355 | 355 | __( |
| 356 | 356 | 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?', |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | ); |
| 363 | 363 | return $total; |
| 364 | 364 | } |
| 365 | - return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ]; |
|
| 365 | + return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][$dtt_id]; |
|
| 366 | 366 | break; |
| 367 | 367 | default: |
| 368 | 368 | return $total; |
@@ -381,9 +381,9 @@ discard block |
||
| 381 | 381 | { |
| 382 | 382 | $datetimes = $this->get_many_related('Datetime'); |
| 383 | 383 | $tickets_sold = []; |
| 384 | - if (! empty($datetimes)) { |
|
| 384 | + if ( ! empty($datetimes)) { |
|
| 385 | 385 | foreach ($datetimes as $datetime) { |
| 386 | - $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold'); |
|
| 386 | + $tickets_sold['datetime'][$datetime->ID()] = $datetime->get('DTT_sold'); |
|
| 387 | 387 | } |
| 388 | 388 | } |
| 389 | 389 | // Tickets sold |
@@ -1011,7 +1011,7 @@ discard block |
||
| 1011 | 1011 | 'TKT_qty', |
| 1012 | 1012 | $qty |
| 1013 | 1013 | ); |
| 1014 | - if (! $success) { |
|
| 1014 | + if ( ! $success) { |
|
| 1015 | 1015 | // The datetimes were successfully bumped, but not the |
| 1016 | 1016 | // ticket. So we need to manually rollback the datetimes. |
| 1017 | 1017 | $this->decreaseReservedForDatetimes($qty); |
@@ -1508,7 +1508,7 @@ discard block |
||
| 1508 | 1508 | foreach ($this->datetimes() as $datetime) { |
| 1509 | 1509 | $times[] = $datetime->start_date_and_time(); |
| 1510 | 1510 | } |
| 1511 | - return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price(); |
|
| 1511 | + return $this->name().' @ '.implode(', ', $times).' for '.$this->pretty_price(); |
|
| 1512 | 1512 | } |
| 1513 | 1513 | |
| 1514 | 1514 | |
@@ -1616,7 +1616,7 @@ discard block |
||
| 1616 | 1616 | { |
| 1617 | 1617 | // get one datetime to use for getting the event |
| 1618 | 1618 | $datetime = $this->first_datetime(); |
| 1619 | - if (! $datetime instanceof EE_Datetime) { |
|
| 1619 | + if ( ! $datetime instanceof EE_Datetime) { |
|
| 1620 | 1620 | throw new UnexpectedEntityException( |
| 1621 | 1621 | $datetime, |
| 1622 | 1622 | 'EE_Datetime', |
@@ -1627,7 +1627,7 @@ discard block |
||
| 1627 | 1627 | ); |
| 1628 | 1628 | } |
| 1629 | 1629 | $event = $datetime->event(); |
| 1630 | - if (! $event instanceof EE_Event) { |
|
| 1630 | + if ( ! $event instanceof EE_Event) { |
|
| 1631 | 1631 | throw new UnexpectedEntityException( |
| 1632 | 1632 | $event, |
| 1633 | 1633 | 'EE_Event', |
@@ -1709,7 +1709,7 @@ discard block |
||
| 1709 | 1709 | public function set_visibility(int $visibility) |
| 1710 | 1710 | { |
| 1711 | 1711 | $ticket_visibility = EEM_Ticket::instance()->ticketVisibility(); |
| 1712 | - if (! isset($ticket_visibility[ $visibility ])) { |
|
| 1712 | + if ( ! isset($ticket_visibility[$visibility])) { |
|
| 1713 | 1713 | throw new DomainException( |
| 1714 | 1714 | sprintf( |
| 1715 | 1715 | esc_html__( |