Completed
Branch fix-dummy-related-question-qst... (e5efcf)
by
unknown
07:49 queued 03:45
created
core/data_migration_scripts/EE_DMS_Core_4_5_0.dms.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -15,12 +15,12 @@  discard block
 block discarded – undo
15 15
 // unfortunately, this needs to be done upon INCLUSION of this file,
16 16
 // instead of construction, because it only gets constructed on first page load
17 17
 // (all other times it gets resurrected from a wordpress option)
18
-$stages = glob(EE_CORE . 'data_migration_scripts/4_5_0_stages/*');
18
+$stages = glob(EE_CORE.'data_migration_scripts/4_5_0_stages/*');
19 19
 $class_to_filepath = array();
20 20
 foreach ($stages as $filepath) {
21 21
     $matches = array();
22 22
     preg_match('~4_5_0_stages/(.*).dmsstage.php~', $filepath, $matches);
23
-    $class_to_filepath[ $matches[1] ] = $filepath;
23
+    $class_to_filepath[$matches[1]] = $filepath;
24 24
 }
25 25
 // give addons a chance to autoload their stages too
26 26
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_5_0__autoloaded_stages', $class_to_filepath);
@@ -61,10 +61,10 @@  discard block
 block discarded – undo
61 61
         if (version_compare($version_string, '4.5.0.decaf', '<') && version_compare($version_string, '4.3.0.decaf', '>=')) {
62 62
 //          echo "$version_string can be migrated from";
63 63
             return true;
64
-        } elseif (! $version_string) {
64
+        } elseif ( ! $version_string) {
65 65
 //          echo "no version string provided: $version_string";
66 66
             // no version string provided... this must be pre 4.3
67
-            return false;// changed mind. dont want people thinking they should migrate yet because they cant
67
+            return false; // changed mind. dont want people thinking they should migrate yet because they cant
68 68
         } else {
69 69
 //          echo "$version_string doesnt apply";
70 70
             return false;
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
     public function schema_changes_before_migration()
77 77
     {
78 78
         // relies on 4.1's EEH_Activation::create_table
79
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
79
+        require_once(EE_HELPERS.'EEH_Activation.helper.php');
80 80
         $table_name = 'esp_answer';
81 81
         $sql = "ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
82 82
 					REG_ID int(10) unsigned NOT NULL,
@@ -481,18 +481,18 @@  discard block
 block discarded – undo
481 481
     public function insert_default_price_types()
482 482
     {
483 483
         global $wpdb;
484
-        $price_type_table = $wpdb->prefix . "esp_price_type";
484
+        $price_type_table = $wpdb->prefix."esp_price_type";
485 485
         if ($this->_get_table_analysis()->tableExists($price_type_table)) {
486
-            $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table;
486
+            $SQL = 'SELECT COUNT(PRT_ID) FROM '.$price_type_table;
487 487
             $price_types_exist = $wpdb->get_var($SQL);
488
-            if (! $price_types_exist) {
488
+            if ( ! $price_types_exist) {
489 489
                 $user_id = EEH_Activation::get_default_creator_id();
490 490
                 $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_wp_user, PRT_deleted ) VALUES
491
-							(1, '" . esc_html__('Base Price', 'event_espresso') . "', 1,  0, 0, $user_id, 0),
492
-							(2, '" . esc_html__('Percent Discount', 'event_espresso') . "', 2,  1, 20, $user_id, 0),
493
-							(3, '" . esc_html__('Dollar Discount', 'event_espresso') . "', 2,  0, 30, $user_id, 0),
494
-							(4, '" . esc_html__('Percent Surcharge', 'event_espresso') . "', 3,  1, 40, $user_id,  0),
495
-							(5, '" . esc_html__('Dollar Surcharge', 'event_espresso') . "', 3,  0, 50, $user_id, 0);";
491
+							(1, '".esc_html__('Base Price', 'event_espresso')."', 1,  0, 0, $user_id, 0),
492
+							(2, '".esc_html__('Percent Discount', 'event_espresso')."', 2,  1, 20, $user_id, 0),
493
+							(3, '".esc_html__('Dollar Discount', 'event_espresso')."', 2,  0, 30, $user_id, 0),
494
+							(4, '".esc_html__('Percent Surcharge', 'event_espresso')."', 3,  1, 40, $user_id,  0),
495
+							(5, '".esc_html__('Dollar Surcharge', 'event_espresso')."', 3,  0, 50, $user_id, 0);";
496 496
                 $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_price_types__SQL', $SQL);
497 497
                 $wpdb->query($SQL);
498 498
             }
@@ -513,11 +513,11 @@  discard block
 block discarded – undo
513 513
     public function insert_default_prices()
514 514
     {
515 515
         global $wpdb;
516
-        $price_table = $wpdb->prefix . "esp_price";
516
+        $price_table = $wpdb->prefix."esp_price";
517 517
         if ($this->_get_table_analysis()->tableExists($price_table)) {
518
-            $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table;
518
+            $SQL = 'SELECT COUNT(PRC_ID) FROM '.$price_table;
519 519
             $prices_exist = $wpdb->get_var($SQL);
520
-            if (! $prices_exist) {
520
+            if ( ! $prices_exist) {
521 521
                 $user_id = EEH_Activation::get_default_creator_id();
522 522
                 $SQL = "INSERT INTO $price_table
523 523
 							(PRC_ID, PRT_ID, PRC_amount, PRC_name, PRC_desc,  PRC_is_default, PRC_overrides, PRC_wp_user, PRC_order, PRC_deleted, PRC_parent ) VALUES
@@ -540,11 +540,11 @@  discard block
 block discarded – undo
540 540
     public function insert_default_tickets()
541 541
     {
542 542
         global $wpdb;
543
-        $ticket_table = $wpdb->prefix . "esp_ticket";
543
+        $ticket_table = $wpdb->prefix."esp_ticket";
544 544
         if ($this->_get_table_analysis()->tableExists($ticket_table)) {
545
-            $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table;
545
+            $SQL = 'SELECT COUNT(TKT_ID) FROM '.$ticket_table;
546 546
             $tickets_exist = $wpdb->get_var($SQL);
547
-            if (! $tickets_exist) {
547
+            if ( ! $tickets_exist) {
548 548
                 $user_id = EEH_Activation::get_default_creator_id();
549 549
                 $SQL = "INSERT INTO $ticket_table
550 550
 					( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_required, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_wp_user, TKT_deleted ) VALUES
@@ -555,11 +555,11 @@  discard block
 block discarded – undo
555 555
                 $wpdb->query($SQL);
556 556
             }
557 557
         }
558
-        $ticket_price_table = $wpdb->prefix . "esp_ticket_price";
558
+        $ticket_price_table = $wpdb->prefix."esp_ticket_price";
559 559
         if ($this->_get_table_analysis()->tableExists($ticket_price_table)) {
560
-            $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table;
560
+            $SQL = 'SELECT COUNT(TKP_ID) FROM '.$ticket_price_table;
561 561
             $ticket_prc_exist = $wpdb->get_var($SQL);
562
-            if (! $ticket_prc_exist) {
562
+            if ( ! $ticket_prc_exist) {
563 563
                 $SQL = "INSERT INTO $ticket_price_table
564 564
 				( TKP_ID, TKT_ID, PRC_ID ) VALUES
565 565
 				( 1, 1, 1 )
Please login to merge, or discard this patch.
Indentation   +229 added lines, -229 removed lines patch added patch discarded remove patch
@@ -18,9 +18,9 @@  discard block
 block discarded – undo
18 18
 $stages = glob(EE_CORE . 'data_migration_scripts/4_5_0_stages/*');
19 19
 $class_to_filepath = array();
20 20
 foreach ($stages as $filepath) {
21
-    $matches = array();
22
-    preg_match('~4_5_0_stages/(.*).dmsstage.php~', $filepath, $matches);
23
-    $class_to_filepath[ $matches[1] ] = $filepath;
21
+	$matches = array();
22
+	preg_match('~4_5_0_stages/(.*).dmsstage.php~', $filepath, $matches);
23
+	$class_to_filepath[ $matches[1] ] = $filepath;
24 24
 }
25 25
 // give addons a chance to autoload their stages too
26 26
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_5_0__autoloaded_stages', $class_to_filepath);
@@ -30,59 +30,59 @@  discard block
 block discarded – undo
30 30
 
31 31
 class EE_DMS_Core_4_5_0 extends EE_Data_Migration_Script_Base
32 32
 {
33
-    /**
34
-     * EE_DMS_Core_4_5_0 constructor.
35
-     *
36
-     * @param TableManager  $table_manager
37
-     * @param TableAnalysis $table_analysis
38
-     */
39
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
40
-    {
41
-        $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.5.0", "event_espresso");
42
-        $this->_priority = 10;
43
-        $this->_migration_stages = array(
44
-            new EE_DMS_4_5_0_update_wp_user_for_tickets(),
45
-            new EE_DMS_4_5_0_update_wp_user_for_prices(),
46
-            new EE_DMS_4_5_0_update_wp_user_for_price_types(),
47
-            new EE_DMS_4_5_0_update_wp_user_for_question_groups(),
48
-            new EE_DMS_4_5_0_invoice_settings(),
49
-        );
50
-        parent::__construct($table_manager, $table_analysis);
51
-    }
33
+	/**
34
+	 * EE_DMS_Core_4_5_0 constructor.
35
+	 *
36
+	 * @param TableManager  $table_manager
37
+	 * @param TableAnalysis $table_analysis
38
+	 */
39
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
40
+	{
41
+		$this->_pretty_name = esc_html__("Data Update to Event Espresso 4.5.0", "event_espresso");
42
+		$this->_priority = 10;
43
+		$this->_migration_stages = array(
44
+			new EE_DMS_4_5_0_update_wp_user_for_tickets(),
45
+			new EE_DMS_4_5_0_update_wp_user_for_prices(),
46
+			new EE_DMS_4_5_0_update_wp_user_for_price_types(),
47
+			new EE_DMS_4_5_0_update_wp_user_for_question_groups(),
48
+			new EE_DMS_4_5_0_invoice_settings(),
49
+		);
50
+		parent::__construct($table_manager, $table_analysis);
51
+	}
52 52
 
53 53
 
54 54
 
55
-    public function can_migrate_from_version($version_array)
56
-    {
57
-        $version_string = $version_array['Core'];
58
-        if (version_compare($version_string, '4.5.0.decaf', '<') && version_compare($version_string, '4.3.0.decaf', '>=')) {
55
+	public function can_migrate_from_version($version_array)
56
+	{
57
+		$version_string = $version_array['Core'];
58
+		if (version_compare($version_string, '4.5.0.decaf', '<') && version_compare($version_string, '4.3.0.decaf', '>=')) {
59 59
 //          echo "$version_string can be migrated from";
60
-            return true;
61
-        } elseif (! $version_string) {
60
+			return true;
61
+		} elseif (! $version_string) {
62 62
 //          echo "no version string provided: $version_string";
63
-            // no version string provided... this must be pre 4.3
64
-            return false;// changed mind. dont want people thinking they should migrate yet because they cant
65
-        } else {
63
+			// no version string provided... this must be pre 4.3
64
+			return false;// changed mind. dont want people thinking they should migrate yet because they cant
65
+		} else {
66 66
 //          echo "$version_string doesnt apply";
67
-            return false;
68
-        }
69
-    }
67
+			return false;
68
+		}
69
+	}
70 70
 
71 71
 
72 72
 
73
-    public function schema_changes_before_migration()
74
-    {
75
-        // relies on 4.1's EEH_Activation::create_table
76
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
77
-        $table_name = 'esp_answer';
78
-        $sql = "ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
73
+	public function schema_changes_before_migration()
74
+	{
75
+		// relies on 4.1's EEH_Activation::create_table
76
+		require_once(EE_HELPERS . 'EEH_Activation.helper.php');
77
+		$table_name = 'esp_answer';
78
+		$sql = "ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
79 79
 					REG_ID int(10) unsigned NOT NULL,
80 80
 					QST_ID int(10) unsigned NOT NULL,
81 81
 					ANS_value text NOT NULL,
82 82
 					PRIMARY KEY  (ANS_ID)";
83
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
84
-        $table_name = 'esp_attendee_meta';
85
-        $sql = "ATTM_ID int(10) unsigned NOT	NULL AUTO_INCREMENT,
83
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
84
+		$table_name = 'esp_attendee_meta';
85
+		$sql = "ATTM_ID int(10) unsigned NOT	NULL AUTO_INCREMENT,
86 86
 						ATT_ID bigint(20) unsigned NOT NULL,
87 87
 						ATT_fname varchar(45) NOT NULL,
88 88
 						ATT_lname varchar(45) NOT	NULL,
@@ -98,9 +98,9 @@  discard block
 block discarded – undo
98 98
 								KEY ATT_fname (ATT_fname),
99 99
 								KEY ATT_lname (ATT_lname),
100 100
 								KEY ATT_email (ATT_email(191))";
101
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
102
-        $table_name = 'esp_country';
103
-        $sql = "CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL,
101
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
102
+		$table_name = 'esp_country';
103
+		$sql = "CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL,
104 104
 					  CNT_ISO3 varchar(3) COLLATE utf8_bin NOT NULL,
105 105
 					  RGN_ID tinyint(3) unsigned DEFAULT NULL,
106 106
 					  CNT_name varchar(45) COLLATE utf8_bin NOT NULL,
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
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_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
120
-        $table_name = 'esp_datetime';
121
-        $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
119
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
120
+		$table_name = 'esp_datetime';
121
+		$sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
122 122
 				  EVT_ID bigint(20) unsigned NOT NULL,
123 123
 				  DTT_name varchar(255) NOT NULL DEFAULT '',
124 124
 				  DTT_description text NOT NULL,
@@ -133,9 +133,9 @@  discard block
 block discarded – undo
133 133
 						PRIMARY KEY  (DTT_ID),
134 134
 						KEY EVT_ID (EVT_ID),
135 135
 						KEY DTT_is_primary (DTT_is_primary)";
136
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
137
-        $table_name = 'esp_event_meta';
138
-        $sql = "
136
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
137
+		$table_name = 'esp_event_meta';
138
+		$sql = "
139 139
 			EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
140 140
 			EVT_ID bigint(20) unsigned NOT NULL,
141 141
 			EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -150,31 +150,31 @@  discard block
 block discarded – undo
150 150
 			EVT_external_URL varchar(200) NULL,
151 151
 			EVT_donations tinyint(1) NULL,
152 152
 			PRIMARY KEY  (EVTM_ID)";
153
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
154
-        $table_name = 'esp_event_question_group';
155
-        $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
153
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
154
+		$table_name = 'esp_event_question_group';
155
+		$sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
156 156
 					EVT_ID bigint(20) unsigned NOT NULL,
157 157
 					QSG_ID int(10) unsigned NOT NULL,
158 158
 					EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
159 159
 					PRIMARY KEY  (EQG_ID)";
160
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
161
-        $table_name = 'esp_event_venue';
162
-        $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
160
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
161
+		$table_name = 'esp_event_venue';
162
+		$sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
163 163
 				EVT_ID bigint(20) unsigned NOT NULL,
164 164
 				VNU_ID bigint(20) unsigned NOT NULL,
165 165
 				EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
166 166
 				PRIMARY KEY  (EVV_ID)";
167
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
168
-        $table_name = 'esp_extra_meta';
169
-        $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
167
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
168
+		$table_name = 'esp_extra_meta';
169
+		$sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
170 170
 				OBJ_ID int(11) DEFAULT NULL,
171 171
 				EXM_type varchar(45) DEFAULT NULL,
172 172
 				EXM_key varchar(45) DEFAULT NULL,
173 173
 				EXM_value text,
174 174
 				PRIMARY KEY  (EXM_ID)";
175
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
176
-        $table_name = 'esp_line_item';
177
-        $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
175
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
176
+		$table_name = 'esp_line_item';
177
+		$sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
178 178
 				LIN_code varchar(245) NOT NULL DEFAULT '',
179 179
 				TXN_ID int(11) DEFAULT NULL,
180 180
 				LIN_name varchar(245) NOT NULL DEFAULT '',
@@ -190,19 +190,19 @@  discard block
 block discarded – undo
190 190
 				OBJ_ID int(11) DEFAULT NULL,
191 191
 				OBJ_type varchar(45)DEFAULT NULL,
192 192
 				PRIMARY KEY  (LIN_ID)";
193
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
194
-        $table_name = 'esp_message_template';
195
-        $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
193
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
194
+		$table_name = 'esp_message_template';
195
+		$sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
196 196
 					GRP_ID int(10) unsigned NOT NULL,
197 197
 					MTP_context varchar(50) NOT NULL,
198 198
 					MTP_template_field varchar(30) NOT NULL,
199 199
 					MTP_content text NOT NULL,
200 200
 					PRIMARY KEY  (MTP_ID),
201 201
 					KEY GRP_ID (GRP_ID)";
202
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
203
-        $this->_get_table_manager()->dropIndex('esp_message_template_group', 'EVT_ID');
204
-        $table_name = 'esp_message_template_group';
205
-        $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
202
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
203
+		$this->_get_table_manager()->dropIndex('esp_message_template_group', 'EVT_ID');
204
+		$table_name = 'esp_message_template_group';
205
+		$sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
206 206
 					MTP_user_id int(10) NOT NULL DEFAULT '1',
207 207
 					MTP_name varchar(245) NOT NULL DEFAULT '',
208 208
 					MTP_description varchar(245) NOT NULL DEFAULT '',
@@ -214,17 +214,17 @@  discard block
 block discarded – undo
214 214
 					MTP_is_active tinyint(1) NOT NULL DEFAULT '1',
215 215
 					PRIMARY KEY  (GRP_ID),
216 216
 					KEY MTP_user_id (MTP_user_id)";
217
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
218
-        $table_name = 'esp_event_message_template';
219
-        $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
217
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
218
+		$table_name = 'esp_event_message_template';
219
+		$sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
220 220
 					EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0,
221 221
 					GRP_ID int(10) unsigned NOT NULL DEFAULT 0,
222 222
 					PRIMARY KEY  (EMT_ID),
223 223
 					KEY EVT_ID (EVT_ID),
224 224
 					KEY GRP_ID (GRP_ID)";
225
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
226
-        $table_name = 'esp_payment';
227
-        $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
225
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
226
+		$table_name = 'esp_payment';
227
+		$sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
228 228
 					TXN_ID int(10) unsigned DEFAULT NULL,
229 229
 					STS_ID varchar(3) COLLATE utf8_bin DEFAULT NULL,
230 230
 					PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
@@ -240,28 +240,28 @@  discard block
 block discarded – undo
240 240
 					PRIMARY KEY  (PAY_ID),
241 241
 					KEY TXN_ID (TXN_ID),
242 242
 					KEY PAY_timestamp (PAY_timestamp)";
243
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
244
-        $table_name = "esp_ticket_price";
245
-        $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
243
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
244
+		$table_name = "esp_ticket_price";
245
+		$sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
246 246
 					  TKT_ID int(10) unsigned NOT NULL,
247 247
 					  PRC_ID int(10) unsigned NOT NULL,
248 248
 					  PRIMARY KEY  (TKP_ID)";
249
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
250
-        $table_name = "esp_datetime_ticket";
251
-        $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
249
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
250
+		$table_name = "esp_datetime_ticket";
251
+		$sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
252 252
 					  DTT_ID int(10) unsigned NOT NULL,
253 253
 					  TKT_ID int(10) unsigned NOT NULL,
254 254
 					  PRIMARY KEY  (DTK_ID)";
255
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
256
-        $table_name = "esp_ticket_template";
257
-        $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
255
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
256
+		$table_name = "esp_ticket_template";
257
+		$sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
258 258
 					  TTM_name varchar(45) NOT NULL,
259 259
 					  TTM_description text,
260 260
 					  TTM_file varchar(45),
261 261
 					  PRIMARY KEY  (TTM_ID)";
262
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
263
-        $table_name = 'esp_question';
264
-        $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
262
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
263
+		$table_name = 'esp_question';
264
+		$sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
265 265
 					QST_display_text text NOT NULL,
266 266
 					QST_admin_label varchar(255) NOT NULL,
267 267
 					QST_system varchar(25) DEFAULT NULL,
@@ -273,25 +273,25 @@  discard block
 block discarded – undo
273 273
 					QST_wp_user bigint(20) unsigned NULL,
274 274
 					QST_deleted tinyint(1) unsigned NOT NULL DEFAULT 0,
275 275
 					PRIMARY KEY  (QST_ID)';
276
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
277
-        $table_name = 'esp_question_group_question';
278
-        $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
276
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
277
+		$table_name = 'esp_question_group_question';
278
+		$sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
279 279
 					QSG_ID int(10) unsigned NOT NULL,
280 280
 					QST_ID int(10) unsigned NOT NULL,
281 281
 					QGQ_order int(10) unsigned NOT NULL DEFAULT 0,
282 282
 					PRIMARY KEY  (QGQ_ID) ";
283
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
284
-        $table_name = 'esp_question_option';
285
-        $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
283
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
284
+		$table_name = 'esp_question_option';
285
+		$sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
286 286
 					QSO_value varchar(255) NOT NULL,
287 287
 					QSO_desc text NOT NULL,
288 288
 					QST_ID int(10) unsigned NOT NULL,
289 289
 					QSO_order int(10) unsigned NOT NULL DEFAULT 0,
290 290
 					QSO_deleted tinyint(1) unsigned NOT NULL DEFAULT 0,
291 291
 					PRIMARY KEY  (QSO_ID)";
292
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
293
-        $table_name = 'esp_registration';
294
-        $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
292
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
293
+		$table_name = 'esp_registration';
294
+		$sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
295 295
 					  EVT_ID bigint(20) unsigned NOT NULL,
296 296
 					  ATT_ID bigint(20) unsigned NOT NULL,
297 297
 					  TXN_ID int(10) unsigned NOT NULL,
@@ -314,25 +314,25 @@  discard block
 block discarded – undo
314 314
 					  KEY STS_ID (STS_ID),
315 315
 					  KEY REG_url_link (REG_url_link),
316 316
 					  KEY REG_code (REG_code)";
317
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
318
-        $table_name = 'esp_checkin';
319
-        $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
317
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
318
+		$table_name = 'esp_checkin';
319
+		$sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
320 320
 					REG_ID int(10) unsigned NOT NULL,
321 321
 					DTT_ID int(10) unsigned NOT NULL,
322 322
 					CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1,
323 323
 					CHK_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
324 324
 					PRIMARY KEY  (CHK_ID)";
325
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
326
-        $table_name = 'esp_state';
327
-        $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
325
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
326
+		$table_name = 'esp_state';
327
+		$sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
328 328
 					  CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL,
329 329
 					  STA_abbrev varchar(6) COLLATE utf8_bin NOT NULL,
330 330
 					  STA_name varchar(100) COLLATE utf8_bin NOT NULL,
331 331
 					  STA_active tinyint(1) DEFAULT '1',
332 332
 					  PRIMARY KEY  (STA_ID)";
333
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
334
-        $table_name = 'esp_status';
335
-        $sql = "STS_ID varchar(3) COLLATE utf8_bin NOT NULL,
333
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
334
+		$table_name = 'esp_status';
335
+		$sql = "STS_ID varchar(3) COLLATE utf8_bin NOT NULL,
336 336
 					  STS_code varchar(45) COLLATE utf8_bin NOT NULL,
337 337
 					  STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL,
338 338
 					  STS_can_edit tinyint(1) NOT NULL DEFAULT 0,
@@ -340,9 +340,9 @@  discard block
 block discarded – undo
340 340
 					  STS_open tinyint(1) NOT NULL DEFAULT 1,
341 341
 					  UNIQUE KEY STS_ID_UNIQUE (STS_ID),
342 342
 					  KEY STS_type (STS_type)";
343
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
344
-        $table_name = 'esp_transaction';
345
-        $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
343
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
344
+		$table_name = 'esp_transaction';
345
+		$sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
346 346
 					  TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
347 347
 					  TXN_total decimal(10,3) DEFAULT '0.00',
348 348
 					  TXN_paid decimal(10,3) NOT NULL DEFAULT '0.00',
@@ -353,9 +353,9 @@  discard block
 block discarded – undo
353 353
 					  PRIMARY KEY  (TXN_ID),
354 354
 					  KEY TXN_timestamp (TXN_timestamp),
355 355
 					  KEY STS_ID (STS_ID)";
356
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
357
-        $table_name = 'esp_venue_meta';
358
-        $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
356
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
357
+		$table_name = 'esp_venue_meta';
358
+		$sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
359 359
 			VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0,
360 360
 			VNU_address varchar(255) DEFAULT NULL,
361 361
 			VNU_address2 varchar(255) DEFAULT NULL,
@@ -373,10 +373,10 @@  discard block
 block discarded – undo
373 373
 			PRIMARY KEY  (VNUM_ID),
374 374
 			KEY STA_ID (STA_ID),
375 375
 			KEY CNT_ISO (CNT_ISO)";
376
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
377
-        // modified tables
378
-        $table_name = "esp_price";
379
-        $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
376
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
377
+		// modified tables
378
+		$table_name = "esp_price";
379
+		$sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
380 380
 					  PRT_ID tinyint(3) unsigned NOT NULL,
381 381
 					  PRC_amount decimal(10,3) NOT NULL DEFAULT '0.00',
382 382
 					  PRC_name varchar(245) NOT NULL,
@@ -388,9 +388,9 @@  discard block
 block discarded – undo
388 388
 					  PRC_wp_user bigint(20) unsigned NULL,
389 389
 					  PRC_parent int(10) unsigned DEFAULT 0,
390 390
 					  PRIMARY KEY  (PRC_ID)";
391
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
392
-        $table_name = "esp_price_type";
393
-        $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
391
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
392
+		$table_name = "esp_price_type";
393
+		$sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
394 394
 				  PRT_name varchar(45) NOT NULL,
395 395
 				  PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1',
396 396
 				  PRT_is_percent tinyint(1) NOT NULL DEFAULT '0',
@@ -399,9 +399,9 @@  discard block
 block discarded – undo
399 399
 				  PRT_deleted tinyint(1) NOT NULL DEFAULT '0',
400 400
 				  UNIQUE KEY PRT_name_UNIQUE (PRT_name),
401 401
 				  PRIMARY KEY  (PRT_ID)";
402
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
403
-        $table_name = "esp_ticket";
404
-        $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
402
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
403
+		$table_name = "esp_ticket";
404
+		$sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
405 405
 					  TTM_ID int(10) unsigned NOT NULL,
406 406
 					  TKT_name varchar(245) NOT NULL DEFAULT '',
407 407
 					  TKT_description text NOT NULL,
@@ -422,10 +422,10 @@  discard block
 block discarded – undo
422 422
 					  TKT_parent int(10) unsigned DEFAULT '0',
423 423
 					  TKT_deleted tinyint(1) NOT NULL DEFAULT '0',
424 424
 					  PRIMARY KEY  (TKT_ID)";
425
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
426
-        $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE');
427
-        $table_name = 'esp_question_group';
428
-        $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
425
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
426
+		$this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE');
427
+		$table_name = 'esp_question_group';
428
+		$sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
429 429
 					QSG_name varchar(255) NOT NULL,
430 430
 					QSG_identifier varchar(100) NOT NULL,
431 431
 					QSG_desc text NULL,
@@ -437,133 +437,133 @@  discard block
 block discarded – undo
437 437
 					QSG_wp_user bigint(20) unsigned NULL,
438 438
 					PRIMARY KEY  (QSG_ID),
439 439
 					UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier ASC)';
440
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
441
-        $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
442
-        // (because many need to convert old string states to foreign keys into the states table)
443
-        $script_4_1_defaults->insert_default_states();
444
-        $script_4_1_defaults->insert_default_countries();
445
-        // schema on price, price_types and tickets has changed so use the DEFAULT method in here instead of 4.1's and later.
446
-        $this->insert_default_price_types();
447
-        $this->insert_default_prices();
448
-        $this->insert_default_tickets();
449
-        // setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre
450
-        EE_Config::instance()->update_espresso_config(false, true);
451
-        return true;
452
-    }
440
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
441
+		$script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
442
+		// (because many need to convert old string states to foreign keys into the states table)
443
+		$script_4_1_defaults->insert_default_states();
444
+		$script_4_1_defaults->insert_default_countries();
445
+		// schema on price, price_types and tickets has changed so use the DEFAULT method in here instead of 4.1's and later.
446
+		$this->insert_default_price_types();
447
+		$this->insert_default_prices();
448
+		$this->insert_default_tickets();
449
+		// setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre
450
+		EE_Config::instance()->update_espresso_config(false, true);
451
+		return true;
452
+	}
453 453
 
454 454
 
455 455
 
456
-    /**
457
-     * @return boolean
458
-     */
459
-    public function schema_changes_after_migration()
460
-    {
461
-        return true;
462
-    }
456
+	/**
457
+	 * @return boolean
458
+	 */
459
+	public function schema_changes_after_migration()
460
+	{
461
+		return true;
462
+	}
463 463
 
464 464
 
465 465
 
466
-    public function migration_page_hooks()
467
-    {
468
-    }
466
+	public function migration_page_hooks()
467
+	{
468
+	}
469 469
 
470 470
 
471 471
 
472
-    /**
473
-     * insert_default_price_types
474
-     *
475
-     * @since 4.5.0
476
-     * @return void
477
-     */
478
-    public function insert_default_price_types()
479
-    {
480
-        global $wpdb;
481
-        $price_type_table = $wpdb->prefix . "esp_price_type";
482
-        if ($this->_get_table_analysis()->tableExists($price_type_table)) {
483
-            $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table;
484
-            $price_types_exist = $wpdb->get_var($SQL);
485
-            if (! $price_types_exist) {
486
-                $user_id = EEH_Activation::get_default_creator_id();
487
-                $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_wp_user, PRT_deleted ) VALUES
472
+	/**
473
+	 * insert_default_price_types
474
+	 *
475
+	 * @since 4.5.0
476
+	 * @return void
477
+	 */
478
+	public function insert_default_price_types()
479
+	{
480
+		global $wpdb;
481
+		$price_type_table = $wpdb->prefix . "esp_price_type";
482
+		if ($this->_get_table_analysis()->tableExists($price_type_table)) {
483
+			$SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table;
484
+			$price_types_exist = $wpdb->get_var($SQL);
485
+			if (! $price_types_exist) {
486
+				$user_id = EEH_Activation::get_default_creator_id();
487
+				$SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_wp_user, PRT_deleted ) VALUES
488 488
 							(1, '" . esc_html__('Base Price', 'event_espresso') . "', 1,  0, 0, $user_id, 0),
489 489
 							(2, '" . esc_html__('Percent Discount', 'event_espresso') . "', 2,  1, 20, $user_id, 0),
490 490
 							(3, '" . esc_html__('Dollar Discount', 'event_espresso') . "', 2,  0, 30, $user_id, 0),
491 491
 							(4, '" . esc_html__('Percent Surcharge', 'event_espresso') . "', 3,  1, 40, $user_id,  0),
492 492
 							(5, '" . esc_html__('Dollar Surcharge', 'event_espresso') . "', 3,  0, 50, $user_id, 0);";
493
-                $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_price_types__SQL', $SQL);
494
-                $wpdb->query($SQL);
495
-            }
496
-        }
497
-    }
493
+				$SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_price_types__SQL', $SQL);
494
+				$wpdb->query($SQL);
495
+			}
496
+		}
497
+	}
498 498
 
499 499
 
500 500
 
501
-    /**
502
-     * insert DEFAULT prices.
503
-     *  If we're INSTALLING 4.x CAF, then we add a few extra DEFAULT prices
504
-     * when EEH_Activaion's initialize_db_content is called via  ahook in
505
-     * EE_Brewing_regular
506
-     *
507
-     * @since 4.5.0
508
-     * @return void
509
-     */
510
-    public function insert_default_prices()
511
-    {
512
-        global $wpdb;
513
-        $price_table = $wpdb->prefix . "esp_price";
514
-        if ($this->_get_table_analysis()->tableExists($price_table)) {
515
-            $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table;
516
-            $prices_exist = $wpdb->get_var($SQL);
517
-            if (! $prices_exist) {
518
-                $user_id = EEH_Activation::get_default_creator_id();
519
-                $SQL = "INSERT INTO $price_table
501
+	/**
502
+	 * insert DEFAULT prices.
503
+	 *  If we're INSTALLING 4.x CAF, then we add a few extra DEFAULT prices
504
+	 * when EEH_Activaion's initialize_db_content is called via  ahook in
505
+	 * EE_Brewing_regular
506
+	 *
507
+	 * @since 4.5.0
508
+	 * @return void
509
+	 */
510
+	public function insert_default_prices()
511
+	{
512
+		global $wpdb;
513
+		$price_table = $wpdb->prefix . "esp_price";
514
+		if ($this->_get_table_analysis()->tableExists($price_table)) {
515
+			$SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table;
516
+			$prices_exist = $wpdb->get_var($SQL);
517
+			if (! $prices_exist) {
518
+				$user_id = EEH_Activation::get_default_creator_id();
519
+				$SQL = "INSERT INTO $price_table
520 520
 							(PRC_ID, PRT_ID, PRC_amount, PRC_name, PRC_desc,  PRC_is_default, PRC_overrides, PRC_wp_user, PRC_order, PRC_deleted, PRC_parent ) VALUES
521 521
 							(1, 1, '0.00', 'Admission', '', 1, NULL, $user_id, 0, 0, 0);";
522
-                $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_prices__SQL', $SQL);
523
-                $wpdb->query($SQL);
524
-            }
525
-        }
526
-    }
522
+				$SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_prices__SQL', $SQL);
523
+				$wpdb->query($SQL);
524
+			}
525
+		}
526
+	}
527 527
 
528 528
 
529 529
 
530
-    /**
531
-     * insert DEFAULT ticket
532
-     * Almost identical to EE_DMS_Core_4_3_0::insert_default_tickets, except is aware of the TKT_wp_user field
533
-     *
534
-     * @since 4.5.0
535
-     * @return void
536
-     */
537
-    public function insert_default_tickets()
538
-    {
539
-        global $wpdb;
540
-        $ticket_table = $wpdb->prefix . "esp_ticket";
541
-        if ($this->_get_table_analysis()->tableExists($ticket_table)) {
542
-            $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table;
543
-            $tickets_exist = $wpdb->get_var($SQL);
544
-            if (! $tickets_exist) {
545
-                $user_id = EEH_Activation::get_default_creator_id();
546
-                $SQL = "INSERT INTO $ticket_table
530
+	/**
531
+	 * insert DEFAULT ticket
532
+	 * Almost identical to EE_DMS_Core_4_3_0::insert_default_tickets, except is aware of the TKT_wp_user field
533
+	 *
534
+	 * @since 4.5.0
535
+	 * @return void
536
+	 */
537
+	public function insert_default_tickets()
538
+	{
539
+		global $wpdb;
540
+		$ticket_table = $wpdb->prefix . "esp_ticket";
541
+		if ($this->_get_table_analysis()->tableExists($ticket_table)) {
542
+			$SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table;
543
+			$tickets_exist = $wpdb->get_var($SQL);
544
+			if (! $tickets_exist) {
545
+				$user_id = EEH_Activation::get_default_creator_id();
546
+				$SQL = "INSERT INTO $ticket_table
547 547
 					( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_required, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_wp_user, TKT_deleted ) VALUES
548 548
 					( 1, 0, '"
549
-                       . esc_html__("Free Ticket", "event_espresso")
550
-                       . "', '', 100, 0, -1, 0, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, $user_id, 0);";
551
-                $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL', $SQL);
552
-                $wpdb->query($SQL);
553
-            }
554
-        }
555
-        $ticket_price_table = $wpdb->prefix . "esp_ticket_price";
556
-        if ($this->_get_table_analysis()->tableExists($ticket_price_table)) {
557
-            $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table;
558
-            $ticket_prc_exist = $wpdb->get_var($SQL);
559
-            if (! $ticket_prc_exist) {
560
-                $SQL = "INSERT INTO $ticket_price_table
549
+					   . esc_html__("Free Ticket", "event_espresso")
550
+					   . "', '', 100, 0, -1, 0, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, $user_id, 0);";
551
+				$SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL', $SQL);
552
+				$wpdb->query($SQL);
553
+			}
554
+		}
555
+		$ticket_price_table = $wpdb->prefix . "esp_ticket_price";
556
+		if ($this->_get_table_analysis()->tableExists($ticket_price_table)) {
557
+			$SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table;
558
+			$ticket_prc_exist = $wpdb->get_var($SQL);
559
+			if (! $ticket_prc_exist) {
560
+				$SQL = "INSERT INTO $ticket_price_table
561 561
 				( TKP_ID, TKT_ID, PRC_ID ) VALUES
562 562
 				( 1, 1, 1 )
563 563
 				";
564
-                $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL__ticket_price', $SQL);
565
-                $wpdb->query($SQL);
566
-            }
567
-        }
568
-    }
564
+				$SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL__ticket_price', $SQL);
565
+				$wpdb->query($SQL);
566
+			}
567
+		}
568
+	}
569 569
 }
Please login to merge, or discard this patch.
4_9_0_stages/EE_DMS_4_9_0_Email_System_Question.dmsstage.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
     {
24 24
         global $wpdb;
25 25
         $this->_pretty_name = esc_html__('Email - System Question', 'event_espresso');
26
-        $this->_old_table = $wpdb->prefix . 'esp_question';
26
+        $this->_old_table = $wpdb->prefix.'esp_question';
27 27
         $this->_extra_where_sql = "WHERE QST_system = 'email'";
28 28
         parent::__construct();
29 29
     }
@@ -41,12 +41,12 @@  discard block
 block discarded – undo
41 41
             global $wpdb;
42 42
             $success = $wpdb->update(
43 43
                 $this->_old_table,
44
-                array( 'QST_type' => 'EMAIL' ),  // data
45
-                array( 'QST_ID' => $question['QST_ID'] ),  // where
46
-                array( '%s' ),   // data format
47
-                array( '%d' )  // where format
44
+                array('QST_type' => 'EMAIL'), // data
45
+                array('QST_ID' => $question['QST_ID']), // where
46
+                array('%s'), // data format
47
+                array('%d')  // where format
48 48
             );
49
-            if (! $success) {
49
+            if ( ! $success) {
50 50
                 $this->add_error(
51 51
                     sprintf(
52 52
                         esc_html__('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'),
Please login to merge, or discard this patch.
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -11,48 +11,48 @@
 block discarded – undo
11 11
  */
12 12
 class EE_DMS_4_9_0_Email_System_Question extends EE_Data_Migration_Script_Stage_Table
13 13
 {
14
-    /**
15
-     * Just initializes the status of the migration
16
-     *
17
-     * @return EE_DMS_4_9_0_Email_System_Question
18
-     */
19
-    public function __construct()
20
-    {
21
-        global $wpdb;
22
-        $this->_pretty_name = esc_html__('Email - System Question', 'event_espresso');
23
-        $this->_old_table = $wpdb->prefix . 'esp_question';
24
-        $this->_extra_where_sql = "WHERE QST_system = 'email'";
25
-        parent::__construct();
26
-    }
14
+	/**
15
+	 * Just initializes the status of the migration
16
+	 *
17
+	 * @return EE_DMS_4_9_0_Email_System_Question
18
+	 */
19
+	public function __construct()
20
+	{
21
+		global $wpdb;
22
+		$this->_pretty_name = esc_html__('Email - System Question', 'event_espresso');
23
+		$this->_old_table = $wpdb->prefix . 'esp_question';
24
+		$this->_extra_where_sql = "WHERE QST_system = 'email'";
25
+		parent::__construct();
26
+	}
27 27
 
28 28
 
29 29
 
30
-    /**
31
-     * updates the question with the new question type
32
-     * @param array $question an associative array where keys are column names and values are their values.
33
-     * @return null
34
-     */
35
-    protected function _migrate_old_row($question)
36
-    {
37
-        if ($question['QST_ID'] && $question['QST_system'] == 'email') {
38
-            global $wpdb;
39
-            $success = $wpdb->update(
40
-                $this->_old_table,
41
-                array( 'QST_type' => 'EMAIL' ),  // data
42
-                array( 'QST_ID' => $question['QST_ID'] ),  // where
43
-                array( '%s' ),   // data format
44
-                array( '%d' )  // where format
45
-            );
46
-            if (! $success) {
47
-                $this->add_error(
48
-                    sprintf(
49
-                        esc_html__('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'),
50
-                        wp_json_encode($question['QST_system']),
51
-                        $question['QST_ID'],
52
-                        $wpdb->last_error
53
-                    )
54
-                );
55
-            }
56
-        }
57
-    }
30
+	/**
31
+	 * updates the question with the new question type
32
+	 * @param array $question an associative array where keys are column names and values are their values.
33
+	 * @return null
34
+	 */
35
+	protected function _migrate_old_row($question)
36
+	{
37
+		if ($question['QST_ID'] && $question['QST_system'] == 'email') {
38
+			global $wpdb;
39
+			$success = $wpdb->update(
40
+				$this->_old_table,
41
+				array( 'QST_type' => 'EMAIL' ),  // data
42
+				array( 'QST_ID' => $question['QST_ID'] ),  // where
43
+				array( '%s' ),   // data format
44
+				array( '%d' )  // where format
45
+			);
46
+			if (! $success) {
47
+				$this->add_error(
48
+					sprintf(
49
+						esc_html__('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'),
50
+						wp_json_encode($question['QST_system']),
51
+						$question['QST_ID'],
52
+						$wpdb->last_error
53
+					)
54
+				);
55
+			}
56
+		}
57
+	}
58 58
 }
Please login to merge, or discard this patch.
core/db_classes/EE_CPT_Base.class.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
     public function wp_post()
41 41
     {
42 42
         global $wpdb;
43
-        if (! $this->_wp_post instanceof WP_Post) {
43
+        if ( ! $this->_wp_post instanceof WP_Post) {
44 44
             if ($this->ID()) {
45 45
                 $this->_wp_post = get_post($this->ID());
46 46
             } else {
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
             }
67 67
             // and let's make retrieving the EE CPT object easy too
68 68
             $classname = get_class($this);
69
-            if (! isset($this->_wp_post->{$classname})) {
69
+            if ( ! isset($this->_wp_post->{$classname})) {
70 70
                 $this->_wp_post->{$classname} = $this;
71 71
             }
72 72
         }
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
      */
148 148
     public function remove_relation_to_term_taxonomy($term_taxonomy)
149 149
     {
150
-        if (! $term_taxonomy) {
150
+        if ( ! $term_taxonomy) {
151 151
             EE_Error::add_error(
152 152
                 sprintf(
153 153
                     esc_html__(
@@ -228,10 +228,10 @@  discard block
 block discarded – undo
228 228
     {
229 229
         // first let's see if we already have the _feature_image property set AND if it has a cached element on it FOR the given size
230 230
         $attr_key = is_array($attr) ? implode('_', $attr) : $attr;
231
-        $cache_key = is_array($size) ? implode('_', $size) . $attr_key : $size . $attr_key;
232
-        $this->_feature_image[ $cache_key ] = isset($this->_feature_image[ $cache_key ])
233
-            ? $this->_feature_image[ $cache_key ] : $this->get_model()->get_feature_image($this->ID(), $size, $attr);
234
-        return $this->_feature_image[ $cache_key ];
231
+        $cache_key = is_array($size) ? implode('_', $size).$attr_key : $size.$attr_key;
232
+        $this->_feature_image[$cache_key] = isset($this->_feature_image[$cache_key])
233
+            ? $this->_feature_image[$cache_key] : $this->get_model()->get_feature_image($this->ID(), $size, $attr);
234
+        return $this->_feature_image[$cache_key];
235 235
     }
236 236
 
237 237
 
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
             foreach ($related_obj_names as $related_name) {
299 299
                 // related_obj_name so we're saving a revision on an object related to this object
300 300
                 // do we have $where_query params for this related object?  If we do then we include that.
301
-                $cols_n_values = isset($where_query[ $related_name ]) ? $where_query[ $related_name ] : array();
301
+                $cols_n_values = isset($where_query[$related_name]) ? $where_query[$related_name] : array();
302 302
                 $where_params = ! empty($cols_n_values) ? array($cols_n_values) : array();
303 303
                 $related_objs = $this->get_many_related($related_name, $where_params);
304 304
                 $revision_related_objs = $revision_obj->get_many_related($related_name, $where_params);
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
      */
348 348
     public function update_post_meta($meta_key, $meta_value, $prev_value = null)
349 349
     {
350
-        if (! $this->ID()) {
350
+        if ( ! $this->ID()) {
351 351
             $this->save();
352 352
         }
353 353
         return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value);
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
      */
382 382
     public function delete_post_meta($meta_key, $meta_value = '')
383 383
     {
384
-        if (! $this->ID()) {
384
+        if ( ! $this->ID()) {
385 385
             // there are obviously no postmetas for this if it's not saved
386 386
             // so let's just report this as a success
387 387
             return true;
Please login to merge, or discard this patch.
Indentation   +428 added lines, -428 removed lines patch added patch discarded remove patch
@@ -13,432 +13,432 @@
 block discarded – undo
13 13
  */
14 14
 abstract class EE_CPT_Base extends EE_Soft_Delete_Base_Class
15 15
 {
16
-    /**
17
-     * This is a property for holding cached feature images on CPT objects.  Cache's are set on the first
18
-     * "feature_image()" method call.  Each key in the array corresponds to the requested size.
19
-     *
20
-     * @var array
21
-     */
22
-    protected $_feature_image = array();
23
-
24
-    /**
25
-     * @var WP_Post the WP_Post that corresponds with this CPT model object
26
-     */
27
-    protected $_wp_post;
28
-
29
-
30
-    abstract public function wp_user();
31
-
32
-
33
-    /**
34
-     * Returns the WP post associated with this CPT model object. If this CPT is saved, fetches it
35
-     * from the DB. Otherwise, create an unsaved WP_POst object. Caches the post internally.
36
-     *
37
-     * @return WP_Post
38
-     */
39
-    public function wp_post()
40
-    {
41
-        global $wpdb;
42
-        if (! $this->_wp_post instanceof WP_Post) {
43
-            if ($this->ID()) {
44
-                $this->_wp_post = get_post($this->ID());
45
-            } else {
46
-                $simulated_db_result = new stdClass();
47
-                foreach ($this->get_model()->field_settings(true) as $field_name => $field_obj) {
48
-                    if (
49
-                        $this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name()
50
-                        === $wpdb->posts
51
-                    ) {
52
-                        $column = $field_obj->get_table_column();
53
-
54
-                        if ($field_obj instanceof EE_Datetime_Field) {
55
-                            $value_on_model_obj = $this->get_DateTime_object($field_name);
56
-                        } elseif ($field_obj->is_db_only_field()) {
57
-                            $value_on_model_obj = $field_obj->get_default_value();
58
-                        } else {
59
-                            $value_on_model_obj = $this->get_raw($field_name);
60
-                        }
61
-                        $simulated_db_result->{$column} = $field_obj->prepare_for_use_in_db($value_on_model_obj);
62
-                    }
63
-                }
64
-                $this->_wp_post = new WP_Post($simulated_db_result);
65
-            }
66
-            // and let's make retrieving the EE CPT object easy too
67
-            $classname = get_class($this);
68
-            if (! isset($this->_wp_post->{$classname})) {
69
-                $this->_wp_post->{$classname} = $this;
70
-            }
71
-        }
72
-        return $this->_wp_post;
73
-    }
74
-
75
-    /**
76
-     * When fetching a new value for a post field that uses the global $post for rendering,
77
-     * set the global $post temporarily to be this model object; and afterwards restore it
78
-     *
79
-     * @param string $fieldname
80
-     * @param bool   $pretty
81
-     * @param string $extra_cache_ref
82
-     * @return mixed
83
-     */
84
-    protected function _get_fresh_property($fieldname, $pretty = false, $extra_cache_ref = null)
85
-    {
86
-        global $post;
87
-
88
-        if (
89
-            $pretty
90
-            && (
91
-                ! (
92
-                    $post instanceof WP_Post
93
-                    && $post->ID
94
-                )
95
-                || (int) $post->ID !== $this->ID()
96
-            )
97
-            && $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field
98
-        ) {
99
-            $old_post = $post;
100
-            $post = $this->wp_post();
101
-            $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref);
102
-            $post = $old_post;
103
-        } else {
104
-            $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref);
105
-        }
106
-        return $return_value;
107
-    }
108
-
109
-    /**
110
-     * Adds to the specified event category. If it category doesn't exist, creates it.
111
-     *
112
-     * @param string $category_name
113
-     * @param string $category_description    optional
114
-     * @param int    $parent_term_taxonomy_id optional
115
-     * @return EE_Term_Taxonomy
116
-     */
117
-    public function add_event_category($category_name, $category_description = null, $parent_term_taxonomy_id = null)
118
-    {
119
-        return $this->get_model()->add_event_category(
120
-            $this,
121
-            $category_name,
122
-            $category_description,
123
-            $parent_term_taxonomy_id
124
-        );
125
-    }
126
-
127
-
128
-    /**
129
-     * Removes the event category by specified name from being related ot this event
130
-     *
131
-     * @param string $category_name
132
-     * @return bool
133
-     */
134
-    public function remove_event_category($category_name)
135
-    {
136
-        return $this->get_model()->remove_event_category($this, $category_name);
137
-    }
138
-
139
-
140
-    /**
141
-     * Removes the relation to the specified term taxonomy, and maintains the
142
-     * data integrity of the term taxonomy provided
143
-     *
144
-     * @param EE_Term_Taxonomy $term_taxonomy
145
-     * @return EE_Base_Class the relation was removed from
146
-     */
147
-    public function remove_relation_to_term_taxonomy($term_taxonomy)
148
-    {
149
-        if (! $term_taxonomy) {
150
-            EE_Error::add_error(
151
-                sprintf(
152
-                    esc_html__(
153
-                        "No Term_Taxonomy provided which to remove from model object of type %s and id %d",
154
-                        "event_espresso"
155
-                    ),
156
-                    get_class($this),
157
-                    $this->ID()
158
-                ),
159
-                __FILE__,
160
-                __FUNCTION__,
161
-                __LINE__
162
-            );
163
-            return null;
164
-        }
165
-        $term_taxonomy->set_count($term_taxonomy->count() - 1);
166
-        $term_taxonomy->save();
167
-        return $this->_remove_relation_to($term_taxonomy, 'Term_Taxonomy');
168
-    }
169
-
170
-
171
-    /**
172
-     * The main purpose of this method is to return the post type for the model object
173
-     *
174
-     * @access public
175
-     * @return string
176
-     */
177
-    public function post_type()
178
-    {
179
-        return $this->get_model()->post_type();
180
-    }
181
-
182
-
183
-    /**
184
-     * The main purpose of this method is to return the parent for the model object
185
-     *
186
-     * @access public
187
-     * @return int
188
-     */
189
-    public function parent()
190
-    {
191
-        return $this->get('parent');
192
-    }
193
-
194
-
195
-    /**
196
-     * return the _status property
197
-     *
198
-     * @return string
199
-     */
200
-    public function status()
201
-    {
202
-        return $this->get('status');
203
-    }
204
-
205
-
206
-    /**
207
-     * @param string $status
208
-     */
209
-    public function set_status($status)
210
-    {
211
-        $this->set('status', $status);
212
-    }
213
-
214
-
215
-    /**
216
-     * This calls the equivalent model method for retrieving the feature image which in turn is a wrapper for
217
-     * WordPress' get_the_post_thumbnail() function.
218
-     *
219
-     * @link   http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
220
-     * @access protected
221
-     * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array
222
-     *                           representing width and height in pixels (i.e. array(32,32) ).
223
-     * @param string|array $attr Optional. Query string or array of attributes.
224
-     * @return string HTML image element
225
-     */
226
-    protected function _get_feature_image($size, $attr)
227
-    {
228
-        // first let's see if we already have the _feature_image property set AND if it has a cached element on it FOR the given size
229
-        $attr_key = is_array($attr) ? implode('_', $attr) : $attr;
230
-        $cache_key = is_array($size) ? implode('_', $size) . $attr_key : $size . $attr_key;
231
-        $this->_feature_image[ $cache_key ] = isset($this->_feature_image[ $cache_key ])
232
-            ? $this->_feature_image[ $cache_key ] : $this->get_model()->get_feature_image($this->ID(), $size, $attr);
233
-        return $this->_feature_image[ $cache_key ];
234
-    }
235
-
236
-
237
-    /**
238
-     * See _get_feature_image. Returns the HTML to display a featured image
239
-     *
240
-     * @param string       $size
241
-     * @param string|array $attr
242
-     * @return string of html
243
-     */
244
-    public function feature_image($size = 'thumbnail', $attr = '')
245
-    {
246
-        return $this->_get_feature_image($size, $attr);
247
-    }
248
-
249
-
250
-    /**
251
-     * This uses the wp "wp_get_attachment_image_src()" function to return the feature image for the current class
252
-     * using the given size params.
253
-     *
254
-     * @param  string|array $size can either be a string: 'thumbnail', 'medium', 'large', 'full' OR 2-item array
255
-     *                            representing width and height in pixels eg. array(32,32).
256
-     * @return string|boolean          the url of the image or false if not found
257
-     */
258
-    public function feature_image_url($size = 'thumbnail')
259
-    {
260
-        $attachment = wp_get_attachment_image_src(get_post_thumbnail_id($this->ID()), $size);
261
-        return ! empty($attachment) ? $attachment[0] : false;
262
-    }
263
-
264
-
265
-    /**
266
-     * This is a method for restoring this_obj using details from the given $revision_id
267
-     *
268
-     * @param int   $revision_id       ID of the revision we're getting data from
269
-     * @param array $related_obj_names if included this will be used to restore for related obj
270
-     *                                 if not included then we just do restore on the meta.
271
-     *                                 We will accept an array of related_obj_names for restoration here.
272
-     * @param array $where_query       You can optionally include an array of key=>value pairs
273
-     *                                 that allow you to further constrict the relation to being added.
274
-     *                                 However, keep in mind that the columns (keys) given
275
-     *                                 must match a column on the JOIN table and currently
276
-     *                                 only the HABTM models accept these additional conditions.
277
-     *                                 Also remember that if an exact match isn't found for these extra cols/val pairs,
278
-     *                                 then a NEW row is created in the join table.
279
-     *                                 This array is INDEXED by RELATED OBJ NAME (so it corresponds with the obj_names
280
-     *                                 sent);
281
-     * @return void
282
-     */
283
-    public function restore_revision($revision_id, $related_obj_names = array(), $where_query = array())
284
-    {
285
-        // get revision object
286
-        $revision_obj = $this->get_model()->get_one_by_ID($revision_id);
287
-        if ($revision_obj instanceof EE_CPT_Base) {
288
-            // no related_obj_name so we assume we're saving a revision on this object.
289
-            if (empty($related_obj_names)) {
290
-                $fields = $this->get_model()->get_meta_table_fields();
291
-                foreach ($fields as $field) {
292
-                    $this->set($field, $revision_obj->get($field));
293
-                }
294
-                $this->save();
295
-            }
296
-            $related_obj_names = (array) $related_obj_names;
297
-            foreach ($related_obj_names as $related_name) {
298
-                // related_obj_name so we're saving a revision on an object related to this object
299
-                // do we have $where_query params for this related object?  If we do then we include that.
300
-                $cols_n_values = isset($where_query[ $related_name ]) ? $where_query[ $related_name ] : array();
301
-                $where_params = ! empty($cols_n_values) ? array($cols_n_values) : array();
302
-                $related_objs = $this->get_many_related($related_name, $where_params);
303
-                $revision_related_objs = $revision_obj->get_many_related($related_name, $where_params);
304
-                // load helper
305
-                // remove related objs from this object that are not in revision
306
-                // array_diff *should* work cause I think objects are indexed by ID?
307
-                $related_to_remove = EEH_Array::object_array_diff($related_objs, $revision_related_objs);
308
-                foreach ($related_to_remove as $rr) {
309
-                    $this->_remove_relation_to($rr, $related_name, $cols_n_values);
310
-                }
311
-                // add all related objs attached to revision to this object
312
-                foreach ($revision_related_objs as $r_obj) {
313
-                    $this->_add_relation_to($r_obj, $related_name, $cols_n_values);
314
-                }
315
-            }
316
-        }
317
-    }
318
-
319
-
320
-    /**
321
-     * Wrapper for get_post_meta, http://codex.wordpress.org/Function_Reference/get_post_meta
322
-     *
323
-     * @param string  $meta_key
324
-     * @param boolean $single
325
-     * @return mixed <ul><li>If only $id is set it will return all meta values in an associative array.</li>
326
-     * <li>If $single is set to false, or left blank, the function returns an array containing all values of the
327
-     * specified key.</li>
328
-     * <li>If $single is set to true, the function returns the first value of the specified key (not in an
329
-     * array</li></ul>
330
-     */
331
-    public function get_post_meta($meta_key = null, $single = false)
332
-    {
333
-        return get_post_meta($this->ID(), $meta_key, $single);
334
-    }
335
-
336
-
337
-    /**
338
-     * Wrapper for update_post_meta, http://codex.wordpress.org/Function_Reference/update_post_meta
339
-     *
340
-     * @param string $meta_key
341
-     * @param mixed  $meta_value
342
-     * @param mixed  $prev_value
343
-     * @return mixed Returns meta_id if the meta doesn't exist, otherwise returns true on success and false on failure.
344
-     *               NOTE: If the meta_value passed to this function is the same as the value that is already in the
345
-     *               database, this function returns false.
346
-     */
347
-    public function update_post_meta($meta_key, $meta_value, $prev_value = null)
348
-    {
349
-        if (! $this->ID()) {
350
-            $this->save();
351
-        }
352
-        return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value);
353
-    }
354
-
355
-
356
-    /**
357
-     * Wrapper for add_post_meta, http://codex.wordpress.org/Function_Reference/add_post_meta
358
-     *
359
-     * @param mixed $meta_key
360
-     * @param mixed $meta_value
361
-     * @param bool  $unique . If postmeta for this $meta_key already exists, whether to add an additional item or not
362
-     * @return boolean Boolean true, except if the $unique argument was set to true and a custom field with the given
363
-     *                 key already exists, in which case false is returned.
364
-     */
365
-    public function add_post_meta($meta_key, $meta_value, $unique = false)
366
-    {
367
-        if ($this->ID()) {
368
-            $this->save();
369
-        }
370
-        return add_post_meta($this->ID(), $meta_key, $meta_value, $unique);
371
-    }
372
-
373
-
374
-    /**
375
-     * Wrapper for delete_post_meta, http://codex.wordpress.org/Function_Reference/delete_post_meta
376
-     *
377
-     * @param mixed $meta_key
378
-     * @param mixed $meta_value
379
-     * @return boolean False for failure. True for success.
380
-     */
381
-    public function delete_post_meta($meta_key, $meta_value = '')
382
-    {
383
-        if (! $this->ID()) {
384
-            // there are obviously no postmetas for this if it's not saved
385
-            // so let's just report this as a success
386
-            return true;
387
-        }
388
-        return delete_post_meta($this->ID(), $meta_key, $meta_value);
389
-    }
390
-
391
-
392
-    /**
393
-     * Gets the URL for viewing this event on the front-end
394
-     *
395
-     * @return string
396
-     */
397
-    public function get_permalink()
398
-    {
399
-        return get_permalink($this->ID());
400
-    }
401
-
402
-
403
-    /**
404
-     * Gets all the term-taxonomies for this CPT
405
-     *
406
-     * @param array $query_params
407
-     * @return EE_Term_Taxonomy
408
-     */
409
-    public function term_taxonomies($query_params = array())
410
-    {
411
-        return $this->get_many_related('Term_Taxonomy', $query_params);
412
-    }
413
-
414
-
415
-    /**
416
-     * @return mixed
417
-     */
418
-    public function get_custom_post_statuses()
419
-    {
420
-        return $this->get_model()->get_custom_post_statuses();
421
-    }
422
-
423
-
424
-    /**
425
-     * @return mixed
426
-     */
427
-    public function get_all_post_statuses()
428
-    {
429
-        return $this->get_model()->get_status_array();
430
-    }
431
-
432
-
433
-    /**
434
-     * Don't serialize the WP Post. That's just duplicate data and we want to avoid recursion
435
-     *
436
-     * @return array
437
-     */
438
-    public function __sleep()
439
-    {
440
-        $properties_to_serialize = parent::__sleep();
441
-        $properties_to_serialize = array_diff($properties_to_serialize, array('_wp_post'));
442
-        return $properties_to_serialize;
443
-    }
16
+	/**
17
+	 * This is a property for holding cached feature images on CPT objects.  Cache's are set on the first
18
+	 * "feature_image()" method call.  Each key in the array corresponds to the requested size.
19
+	 *
20
+	 * @var array
21
+	 */
22
+	protected $_feature_image = array();
23
+
24
+	/**
25
+	 * @var WP_Post the WP_Post that corresponds with this CPT model object
26
+	 */
27
+	protected $_wp_post;
28
+
29
+
30
+	abstract public function wp_user();
31
+
32
+
33
+	/**
34
+	 * Returns the WP post associated with this CPT model object. If this CPT is saved, fetches it
35
+	 * from the DB. Otherwise, create an unsaved WP_POst object. Caches the post internally.
36
+	 *
37
+	 * @return WP_Post
38
+	 */
39
+	public function wp_post()
40
+	{
41
+		global $wpdb;
42
+		if (! $this->_wp_post instanceof WP_Post) {
43
+			if ($this->ID()) {
44
+				$this->_wp_post = get_post($this->ID());
45
+			} else {
46
+				$simulated_db_result = new stdClass();
47
+				foreach ($this->get_model()->field_settings(true) as $field_name => $field_obj) {
48
+					if (
49
+						$this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name()
50
+						=== $wpdb->posts
51
+					) {
52
+						$column = $field_obj->get_table_column();
53
+
54
+						if ($field_obj instanceof EE_Datetime_Field) {
55
+							$value_on_model_obj = $this->get_DateTime_object($field_name);
56
+						} elseif ($field_obj->is_db_only_field()) {
57
+							$value_on_model_obj = $field_obj->get_default_value();
58
+						} else {
59
+							$value_on_model_obj = $this->get_raw($field_name);
60
+						}
61
+						$simulated_db_result->{$column} = $field_obj->prepare_for_use_in_db($value_on_model_obj);
62
+					}
63
+				}
64
+				$this->_wp_post = new WP_Post($simulated_db_result);
65
+			}
66
+			// and let's make retrieving the EE CPT object easy too
67
+			$classname = get_class($this);
68
+			if (! isset($this->_wp_post->{$classname})) {
69
+				$this->_wp_post->{$classname} = $this;
70
+			}
71
+		}
72
+		return $this->_wp_post;
73
+	}
74
+
75
+	/**
76
+	 * When fetching a new value for a post field that uses the global $post for rendering,
77
+	 * set the global $post temporarily to be this model object; and afterwards restore it
78
+	 *
79
+	 * @param string $fieldname
80
+	 * @param bool   $pretty
81
+	 * @param string $extra_cache_ref
82
+	 * @return mixed
83
+	 */
84
+	protected function _get_fresh_property($fieldname, $pretty = false, $extra_cache_ref = null)
85
+	{
86
+		global $post;
87
+
88
+		if (
89
+			$pretty
90
+			&& (
91
+				! (
92
+					$post instanceof WP_Post
93
+					&& $post->ID
94
+				)
95
+				|| (int) $post->ID !== $this->ID()
96
+			)
97
+			&& $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field
98
+		) {
99
+			$old_post = $post;
100
+			$post = $this->wp_post();
101
+			$return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref);
102
+			$post = $old_post;
103
+		} else {
104
+			$return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref);
105
+		}
106
+		return $return_value;
107
+	}
108
+
109
+	/**
110
+	 * Adds to the specified event category. If it category doesn't exist, creates it.
111
+	 *
112
+	 * @param string $category_name
113
+	 * @param string $category_description    optional
114
+	 * @param int    $parent_term_taxonomy_id optional
115
+	 * @return EE_Term_Taxonomy
116
+	 */
117
+	public function add_event_category($category_name, $category_description = null, $parent_term_taxonomy_id = null)
118
+	{
119
+		return $this->get_model()->add_event_category(
120
+			$this,
121
+			$category_name,
122
+			$category_description,
123
+			$parent_term_taxonomy_id
124
+		);
125
+	}
126
+
127
+
128
+	/**
129
+	 * Removes the event category by specified name from being related ot this event
130
+	 *
131
+	 * @param string $category_name
132
+	 * @return bool
133
+	 */
134
+	public function remove_event_category($category_name)
135
+	{
136
+		return $this->get_model()->remove_event_category($this, $category_name);
137
+	}
138
+
139
+
140
+	/**
141
+	 * Removes the relation to the specified term taxonomy, and maintains the
142
+	 * data integrity of the term taxonomy provided
143
+	 *
144
+	 * @param EE_Term_Taxonomy $term_taxonomy
145
+	 * @return EE_Base_Class the relation was removed from
146
+	 */
147
+	public function remove_relation_to_term_taxonomy($term_taxonomy)
148
+	{
149
+		if (! $term_taxonomy) {
150
+			EE_Error::add_error(
151
+				sprintf(
152
+					esc_html__(
153
+						"No Term_Taxonomy provided which to remove from model object of type %s and id %d",
154
+						"event_espresso"
155
+					),
156
+					get_class($this),
157
+					$this->ID()
158
+				),
159
+				__FILE__,
160
+				__FUNCTION__,
161
+				__LINE__
162
+			);
163
+			return null;
164
+		}
165
+		$term_taxonomy->set_count($term_taxonomy->count() - 1);
166
+		$term_taxonomy->save();
167
+		return $this->_remove_relation_to($term_taxonomy, 'Term_Taxonomy');
168
+	}
169
+
170
+
171
+	/**
172
+	 * The main purpose of this method is to return the post type for the model object
173
+	 *
174
+	 * @access public
175
+	 * @return string
176
+	 */
177
+	public function post_type()
178
+	{
179
+		return $this->get_model()->post_type();
180
+	}
181
+
182
+
183
+	/**
184
+	 * The main purpose of this method is to return the parent for the model object
185
+	 *
186
+	 * @access public
187
+	 * @return int
188
+	 */
189
+	public function parent()
190
+	{
191
+		return $this->get('parent');
192
+	}
193
+
194
+
195
+	/**
196
+	 * return the _status property
197
+	 *
198
+	 * @return string
199
+	 */
200
+	public function status()
201
+	{
202
+		return $this->get('status');
203
+	}
204
+
205
+
206
+	/**
207
+	 * @param string $status
208
+	 */
209
+	public function set_status($status)
210
+	{
211
+		$this->set('status', $status);
212
+	}
213
+
214
+
215
+	/**
216
+	 * This calls the equivalent model method for retrieving the feature image which in turn is a wrapper for
217
+	 * WordPress' get_the_post_thumbnail() function.
218
+	 *
219
+	 * @link   http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
220
+	 * @access protected
221
+	 * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array
222
+	 *                           representing width and height in pixels (i.e. array(32,32) ).
223
+	 * @param string|array $attr Optional. Query string or array of attributes.
224
+	 * @return string HTML image element
225
+	 */
226
+	protected function _get_feature_image($size, $attr)
227
+	{
228
+		// first let's see if we already have the _feature_image property set AND if it has a cached element on it FOR the given size
229
+		$attr_key = is_array($attr) ? implode('_', $attr) : $attr;
230
+		$cache_key = is_array($size) ? implode('_', $size) . $attr_key : $size . $attr_key;
231
+		$this->_feature_image[ $cache_key ] = isset($this->_feature_image[ $cache_key ])
232
+			? $this->_feature_image[ $cache_key ] : $this->get_model()->get_feature_image($this->ID(), $size, $attr);
233
+		return $this->_feature_image[ $cache_key ];
234
+	}
235
+
236
+
237
+	/**
238
+	 * See _get_feature_image. Returns the HTML to display a featured image
239
+	 *
240
+	 * @param string       $size
241
+	 * @param string|array $attr
242
+	 * @return string of html
243
+	 */
244
+	public function feature_image($size = 'thumbnail', $attr = '')
245
+	{
246
+		return $this->_get_feature_image($size, $attr);
247
+	}
248
+
249
+
250
+	/**
251
+	 * This uses the wp "wp_get_attachment_image_src()" function to return the feature image for the current class
252
+	 * using the given size params.
253
+	 *
254
+	 * @param  string|array $size can either be a string: 'thumbnail', 'medium', 'large', 'full' OR 2-item array
255
+	 *                            representing width and height in pixels eg. array(32,32).
256
+	 * @return string|boolean          the url of the image or false if not found
257
+	 */
258
+	public function feature_image_url($size = 'thumbnail')
259
+	{
260
+		$attachment = wp_get_attachment_image_src(get_post_thumbnail_id($this->ID()), $size);
261
+		return ! empty($attachment) ? $attachment[0] : false;
262
+	}
263
+
264
+
265
+	/**
266
+	 * This is a method for restoring this_obj using details from the given $revision_id
267
+	 *
268
+	 * @param int   $revision_id       ID of the revision we're getting data from
269
+	 * @param array $related_obj_names if included this will be used to restore for related obj
270
+	 *                                 if not included then we just do restore on the meta.
271
+	 *                                 We will accept an array of related_obj_names for restoration here.
272
+	 * @param array $where_query       You can optionally include an array of key=>value pairs
273
+	 *                                 that allow you to further constrict the relation to being added.
274
+	 *                                 However, keep in mind that the columns (keys) given
275
+	 *                                 must match a column on the JOIN table and currently
276
+	 *                                 only the HABTM models accept these additional conditions.
277
+	 *                                 Also remember that if an exact match isn't found for these extra cols/val pairs,
278
+	 *                                 then a NEW row is created in the join table.
279
+	 *                                 This array is INDEXED by RELATED OBJ NAME (so it corresponds with the obj_names
280
+	 *                                 sent);
281
+	 * @return void
282
+	 */
283
+	public function restore_revision($revision_id, $related_obj_names = array(), $where_query = array())
284
+	{
285
+		// get revision object
286
+		$revision_obj = $this->get_model()->get_one_by_ID($revision_id);
287
+		if ($revision_obj instanceof EE_CPT_Base) {
288
+			// no related_obj_name so we assume we're saving a revision on this object.
289
+			if (empty($related_obj_names)) {
290
+				$fields = $this->get_model()->get_meta_table_fields();
291
+				foreach ($fields as $field) {
292
+					$this->set($field, $revision_obj->get($field));
293
+				}
294
+				$this->save();
295
+			}
296
+			$related_obj_names = (array) $related_obj_names;
297
+			foreach ($related_obj_names as $related_name) {
298
+				// related_obj_name so we're saving a revision on an object related to this object
299
+				// do we have $where_query params for this related object?  If we do then we include that.
300
+				$cols_n_values = isset($where_query[ $related_name ]) ? $where_query[ $related_name ] : array();
301
+				$where_params = ! empty($cols_n_values) ? array($cols_n_values) : array();
302
+				$related_objs = $this->get_many_related($related_name, $where_params);
303
+				$revision_related_objs = $revision_obj->get_many_related($related_name, $where_params);
304
+				// load helper
305
+				// remove related objs from this object that are not in revision
306
+				// array_diff *should* work cause I think objects are indexed by ID?
307
+				$related_to_remove = EEH_Array::object_array_diff($related_objs, $revision_related_objs);
308
+				foreach ($related_to_remove as $rr) {
309
+					$this->_remove_relation_to($rr, $related_name, $cols_n_values);
310
+				}
311
+				// add all related objs attached to revision to this object
312
+				foreach ($revision_related_objs as $r_obj) {
313
+					$this->_add_relation_to($r_obj, $related_name, $cols_n_values);
314
+				}
315
+			}
316
+		}
317
+	}
318
+
319
+
320
+	/**
321
+	 * Wrapper for get_post_meta, http://codex.wordpress.org/Function_Reference/get_post_meta
322
+	 *
323
+	 * @param string  $meta_key
324
+	 * @param boolean $single
325
+	 * @return mixed <ul><li>If only $id is set it will return all meta values in an associative array.</li>
326
+	 * <li>If $single is set to false, or left blank, the function returns an array containing all values of the
327
+	 * specified key.</li>
328
+	 * <li>If $single is set to true, the function returns the first value of the specified key (not in an
329
+	 * array</li></ul>
330
+	 */
331
+	public function get_post_meta($meta_key = null, $single = false)
332
+	{
333
+		return get_post_meta($this->ID(), $meta_key, $single);
334
+	}
335
+
336
+
337
+	/**
338
+	 * Wrapper for update_post_meta, http://codex.wordpress.org/Function_Reference/update_post_meta
339
+	 *
340
+	 * @param string $meta_key
341
+	 * @param mixed  $meta_value
342
+	 * @param mixed  $prev_value
343
+	 * @return mixed Returns meta_id if the meta doesn't exist, otherwise returns true on success and false on failure.
344
+	 *               NOTE: If the meta_value passed to this function is the same as the value that is already in the
345
+	 *               database, this function returns false.
346
+	 */
347
+	public function update_post_meta($meta_key, $meta_value, $prev_value = null)
348
+	{
349
+		if (! $this->ID()) {
350
+			$this->save();
351
+		}
352
+		return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value);
353
+	}
354
+
355
+
356
+	/**
357
+	 * Wrapper for add_post_meta, http://codex.wordpress.org/Function_Reference/add_post_meta
358
+	 *
359
+	 * @param mixed $meta_key
360
+	 * @param mixed $meta_value
361
+	 * @param bool  $unique . If postmeta for this $meta_key already exists, whether to add an additional item or not
362
+	 * @return boolean Boolean true, except if the $unique argument was set to true and a custom field with the given
363
+	 *                 key already exists, in which case false is returned.
364
+	 */
365
+	public function add_post_meta($meta_key, $meta_value, $unique = false)
366
+	{
367
+		if ($this->ID()) {
368
+			$this->save();
369
+		}
370
+		return add_post_meta($this->ID(), $meta_key, $meta_value, $unique);
371
+	}
372
+
373
+
374
+	/**
375
+	 * Wrapper for delete_post_meta, http://codex.wordpress.org/Function_Reference/delete_post_meta
376
+	 *
377
+	 * @param mixed $meta_key
378
+	 * @param mixed $meta_value
379
+	 * @return boolean False for failure. True for success.
380
+	 */
381
+	public function delete_post_meta($meta_key, $meta_value = '')
382
+	{
383
+		if (! $this->ID()) {
384
+			// there are obviously no postmetas for this if it's not saved
385
+			// so let's just report this as a success
386
+			return true;
387
+		}
388
+		return delete_post_meta($this->ID(), $meta_key, $meta_value);
389
+	}
390
+
391
+
392
+	/**
393
+	 * Gets the URL for viewing this event on the front-end
394
+	 *
395
+	 * @return string
396
+	 */
397
+	public function get_permalink()
398
+	{
399
+		return get_permalink($this->ID());
400
+	}
401
+
402
+
403
+	/**
404
+	 * Gets all the term-taxonomies for this CPT
405
+	 *
406
+	 * @param array $query_params
407
+	 * @return EE_Term_Taxonomy
408
+	 */
409
+	public function term_taxonomies($query_params = array())
410
+	{
411
+		return $this->get_many_related('Term_Taxonomy', $query_params);
412
+	}
413
+
414
+
415
+	/**
416
+	 * @return mixed
417
+	 */
418
+	public function get_custom_post_statuses()
419
+	{
420
+		return $this->get_model()->get_custom_post_statuses();
421
+	}
422
+
423
+
424
+	/**
425
+	 * @return mixed
426
+	 */
427
+	public function get_all_post_statuses()
428
+	{
429
+		return $this->get_model()->get_status_array();
430
+	}
431
+
432
+
433
+	/**
434
+	 * Don't serialize the WP Post. That's just duplicate data and we want to avoid recursion
435
+	 *
436
+	 * @return array
437
+	 */
438
+	public function __sleep()
439
+	{
440
+		$properties_to_serialize = parent::__sleep();
441
+		$properties_to_serialize = array_diff($properties_to_serialize, array('_wp_post'));
442
+		return $properties_to_serialize;
443
+	}
444 444
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Message.class.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
     {
52 52
         $has_object = parent::_check_for_object($props_n_values, __CLASS__);
53 53
         // if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db.
54
-        if (! $has_object) {
54
+        if ( ! $has_object) {
55 55
             EE_Registry::instance()->load_helper('URL');
56 56
             $props_n_values['MSG_token'] = EEH_URL::generate_unique_token();
57 57
         }
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
     {
220 220
         $label_type = $plural ? 'plural' : 'singular';
221 221
         $messenger = $this->messenger_object();
222
-        return $messenger instanceof EE_messenger ? $messenger->label[ $label_type ] : $this->messenger();
222
+        return $messenger instanceof EE_messenger ? $messenger->label[$label_type] : $this->messenger();
223 223
     }
224 224
 
225 225
 
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
                 $this->messenger(),
337 337
                 $this->message_type()
338 338
             );
339
-            if (! $valid && $throw_exceptions) {
339
+            if ( ! $valid && $throw_exceptions) {
340 340
                 throw new EE_Error(
341 341
                     sprintf(
342 342
                         esc_html__(
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
         $label_type = $plural ? 'plural' : 'singular';
367 367
         $message_type = $this->message_type_object();
368 368
         return $message_type instanceof EE_message_type
369
-            ? $message_type->label[ $label_type ]
369
+            ? $message_type->label[$label_type]
370 370
             : str_replace(
371 371
                 '_',
372 372
                 ' ',
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
         /** @type EE_Message_Resource_Manager $message_resource_manager */
398 398
         $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
399 399
         $contexts = $message_resource_manager->get_all_contexts();
400
-        return isset($contexts[ $this->context() ]) ? $contexts[ $this->context() ] : $this->context();
400
+        return isset($contexts[$this->context()]) ? $contexts[$this->context()] : $this->context();
401 401
     }
402 402
 
403 403
 
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
      */
453 453
     public function recipient_object()
454 454
     {
455
-        if (! $this->recipient_type() || ! $this->recipient_ID()) {
455
+        if ( ! $this->recipient_type() || ! $this->recipient_ID()) {
456 456
             return null;
457 457
         }
458 458
 
@@ -736,13 +736,13 @@  discard block
 block discarded – undo
736 736
         /**
737 737
          * This is deprecated functionality that will be removed eventually but included here now for backward compat.
738 738
          */
739
-        if (! empty($this->template_pack)) {
739
+        if ( ! empty($this->template_pack)) {
740 740
             return $this->template_pack;
741 741
         }
742 742
         /** @type EE_Message_Template_Group $grp */
743 743
         $grp = $this->get_first_related('Message_Template_Group');
744 744
         // if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
745
-        if (! $grp instanceof EE_Message_Template_Group) {
745
+        if ( ! $grp instanceof EE_Message_Template_Group) {
746 746
             $grp = EEM_Message_Template_Group::instance()->get_one(
747 747
                 array(
748 748
                     array(
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
         /**
769 769
          * This is deprecated functionality that will be removed eventually but included here now for backward compat.
770 770
          */
771
-        if (! empty($this->template_variation)) {
771
+        if ( ! empty($this->template_variation)) {
772 772
             return $this->template_variation;
773 773
         }
774 774
 
@@ -776,7 +776,7 @@  discard block
 block discarded – undo
776 776
         $grp = $this->get_first_related('Message_Template_Group');
777 777
 
778 778
         // if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
779
-        if (! $grp instanceof EE_Message_Template_Group) {
779
+        if ( ! $grp instanceof EE_Message_Template_Group) {
780 780
             $grp = EEM_Message_Template_Group::instance()->get_one(
781 781
                 array(
782 782
                     array(
Please login to merge, or discard this patch.
Indentation   +867 added lines, -867 removed lines patch added patch discarded remove patch
@@ -9,875 +9,875 @@
 block discarded – undo
9 9
  */
10 10
 class EE_Message extends EE_Base_Class implements EEI_Admin_Links
11 11
 {
12
-    /**
13
-     * @deprecated 4.9.0  Added for backward compat with add-on's
14
-     * @type null
15
-     */
16
-    public $template_pack;
17
-
18
-    /**
19
-     * @deprecated 4.9.0 Added for backward compat with add-on's
20
-     * @type null
21
-     */
22
-    public $template_variation;
23
-
24
-    /**
25
-     * @deprecated 4.9.0 Added for backward compat with add-on's
26
-     * @type string
27
-     */
28
-    public $content = '';
29
-
30
-
31
-    /**
32
-     * @type EE_messenger $_messenger
33
-     */
34
-    protected $_messenger = null;
35
-
36
-    /**
37
-     * @type EE_message_type $_message_type
38
-     */
39
-    protected $_message_type = null;
40
-
41
-
42
-    /**
43
-     * @param array  $props_n_values
44
-     * @param string $timezone
45
-     * @param array  $date_formats incoming date formats in an array.  First value is the date_format, second is time
46
-     *                             format.
47
-     * @return EE_Message
48
-     */
49
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
50
-    {
51
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
52
-        // if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db.
53
-        if (! $has_object) {
54
-            EE_Registry::instance()->load_helper('URL');
55
-            $props_n_values['MSG_token'] = EEH_URL::generate_unique_token();
56
-        }
57
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
58
-    }
59
-
60
-
61
-    /**
62
-     * @param array  $props_n_values
63
-     * @param string $timezone
64
-     * @return EE_Message
65
-     */
66
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
67
-    {
68
-        return new self($props_n_values, true, $timezone);
69
-    }
70
-
71
-
72
-    /**
73
-     * Gets MSG_token
74
-     *
75
-     * @return int
76
-     */
77
-    public function MSG_token()
78
-    {
79
-        return $this->get('MSG_token');
80
-    }
81
-
82
-
83
-    /**
84
-     * Sets MSG_token
85
-     *
86
-     * @param int $MSG_token
87
-     */
88
-    public function set_MSG_token($MSG_token)
89
-    {
90
-        $this->set('MSG_token', $MSG_token);
91
-    }
92
-
93
-
94
-    /**
95
-     * Gets GRP_ID
96
-     *
97
-     * @return int
98
-     */
99
-    public function GRP_ID()
100
-    {
101
-        return $this->get('GRP_ID');
102
-    }
103
-
104
-
105
-    /**
106
-     * Sets GRP_ID
107
-     *
108
-     * @param int $GRP_ID
109
-     */
110
-    public function set_GRP_ID($GRP_ID)
111
-    {
112
-        $this->set('GRP_ID', $GRP_ID);
113
-    }
114
-
115
-
116
-    /**
117
-     * Gets TXN_ID
118
-     *
119
-     * @return int
120
-     */
121
-    public function TXN_ID()
122
-    {
123
-        return $this->get('TXN_ID');
124
-    }
125
-
126
-
127
-    /**
128
-     * Sets TXN_ID
129
-     *
130
-     * @param int $TXN_ID
131
-     */
132
-    public function set_TXN_ID($TXN_ID)
133
-    {
134
-        $this->set('TXN_ID', $TXN_ID);
135
-    }
136
-
137
-
138
-    /**
139
-     * Gets messenger
140
-     *
141
-     * @return string
142
-     */
143
-    public function messenger()
144
-    {
145
-        return $this->get('MSG_messenger');
146
-    }
147
-
148
-
149
-    /**
150
-     * Sets messenger
151
-     *
152
-     * @param string $messenger
153
-     */
154
-    public function set_messenger($messenger)
155
-    {
156
-        $this->set('MSG_messenger', $messenger);
157
-    }
158
-
159
-
160
-    /**
161
-     * Returns corresponding messenger object for the set messenger on this message
162
-     *
163
-     * @return EE_messenger | null
164
-     */
165
-    public function messenger_object()
166
-    {
167
-        return $this->_messenger;
168
-    }
169
-
170
-
171
-    /**
172
-     * Sets messenger
173
-     *
174
-     * @param EE_messenger $messenger
175
-     */
176
-    public function set_messenger_object(EE_messenger $messenger)
177
-    {
178
-        $this->_messenger = $messenger;
179
-    }
180
-
181
-
182
-    /**
183
-     * validates messenger
184
-     *
185
-     * @param bool $throw_exceptions
186
-     * @return bool
187
-     * @throws \EE_Error
188
-     */
189
-    public function valid_messenger($throw_exceptions = false)
190
-    {
191
-        if ($this->_messenger instanceof EE_messenger) {
192
-            return true;
193
-        }
194
-        if ($throw_exceptions) {
195
-            throw new EE_Error(
196
-                sprintf(
197
-                    esc_html__(
198
-                        'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
199
-                        'event_espresso'
200
-                    ),
201
-                    $this->messenger()
202
-                )
203
-            );
204
-        }
205
-        return false;
206
-    }
207
-
208
-
209
-    /**
210
-     * This returns the set localized label for the messenger on this message.
211
-     * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved
212
-     * with this message.
213
-     *
214
-     * @param   bool $plural whether to return the plural label or not.
215
-     * @return string
216
-     */
217
-    public function messenger_label($plural = false)
218
-    {
219
-        $label_type = $plural ? 'plural' : 'singular';
220
-        $messenger = $this->messenger_object();
221
-        return $messenger instanceof EE_messenger ? $messenger->label[ $label_type ] : $this->messenger();
222
-    }
223
-
224
-
225
-    /**
226
-     * Gets message_type
227
-     *
228
-     * @return string
229
-     */
230
-    public function message_type()
231
-    {
232
-        return $this->get('MSG_message_type');
233
-    }
234
-
235
-
236
-    /**
237
-     * Sets message_type
238
-     *
239
-     * @param string $message_type
240
-     */
241
-    public function set_message_type($message_type)
242
-    {
243
-        $this->set('MSG_message_type', $message_type);
244
-    }
245
-
246
-
247
-    /**
248
-     * Returns the message type object for the set message type on this message
249
-     *
250
-     * @return EE_message_type | null
251
-     */
252
-    public function message_type_object()
253
-    {
254
-        return $this->_message_type;
255
-    }
256
-
257
-
258
-    /**
259
-     * Sets message_type
260
-     *
261
-     * @param EE_message_type $message_type
262
-     * @param bool            $set_priority   This indicates whether to set the priority to whatever the priority is on
263
-     *                                        the message type or not.
264
-     */
265
-    public function set_message_type_object(EE_message_type $message_type, $set_priority = false)
266
-    {
267
-        $this->_message_type = $message_type;
268
-        if ($set_priority) {
269
-            $this->set_priority($this->_message_type->get_priority());
270
-        }
271
-    }
272
-
273
-
274
-    /**
275
-     * validates message_type
276
-     *
277
-     * @param bool $throw_exceptions
278
-     * @return bool
279
-     * @throws \EE_Error
280
-     */
281
-    public function valid_message_type($throw_exceptions = false)
282
-    {
283
-        if ($this->_message_type instanceof EE_message_type) {
284
-            return true;
285
-        }
286
-        if ($throw_exceptions) {
287
-            throw new EE_Error(
288
-                sprintf(
289
-                    esc_html__(
290
-                        'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
291
-                        'event_espresso'
292
-                    ),
293
-                    $this->message_type()
294
-                )
295
-            );
296
-        }
297
-        return false;
298
-    }
299
-
300
-
301
-    /**
302
-     * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects).
303
-     *
304
-     * @param bool $throw_exceptions
305
-     * @return bool
306
-     * @throws \EE_Error
307
-     */
308
-    public function is_valid($throw_exceptions = false)
309
-    {
310
-        if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) {
311
-            return true;
312
-        }
313
-        return false;
314
-    }
315
-
316
-
317
-    /**
318
-     * This validates whether the internal messenger and message type objects are valid for sending.
319
-     * Three checks are done:
320
-     * 1. There is a valid messenger object.
321
-     * 2. There is a valid message type object.
322
-     * 3. The message type object is active for the messenger.
323
-     *
324
-     * @throws EE_Error  But only if $throw_exceptions is set to true.
325
-     * @param bool $throw_exceptions
326
-     * @return bool
327
-     */
328
-    public function is_valid_for_sending_or_generation($throw_exceptions = false)
329
-    {
330
-        $valid = false;
331
-        if ($this->is_valid($throw_exceptions)) {
332
-            /** @var EE_Message_Resource_Manager $message_resource_manager */
333
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
334
-            $valid = $message_resource_manager->is_message_type_active_for_messenger(
335
-                $this->messenger(),
336
-                $this->message_type()
337
-            );
338
-            if (! $valid && $throw_exceptions) {
339
-                throw new EE_Error(
340
-                    sprintf(
341
-                        esc_html__(
342
-                            'The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.',
343
-                            'event_espresso'
344
-                        ),
345
-                        $this->message_type(),
346
-                        $this->messenger()
347
-                    )
348
-                );
349
-            }
350
-        }
351
-        return $valid;
352
-    }
353
-
354
-
355
-    /**
356
-     * This returns the set localized label for the message type on this message.
357
-     * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved
358
-     * with this message.
359
-     *
360
-     * @param   bool $plural whether to return the plural label or not.
361
-     * @return string
362
-     */
363
-    public function message_type_label($plural = false)
364
-    {
365
-        $label_type = $plural ? 'plural' : 'singular';
366
-        $message_type = $this->message_type_object();
367
-        return $message_type instanceof EE_message_type
368
-            ? $message_type->label[ $label_type ]
369
-            : str_replace(
370
-                '_',
371
-                ' ',
372
-                $this->message_type()
373
-            );
374
-    }
375
-
376
-
377
-    /**
378
-     * Gets context
379
-     *
380
-     * @return string
381
-     */
382
-    public function context()
383
-    {
384
-        return $this->get('MSG_context');
385
-    }
386
-
387
-
388
-    /**
389
-     * This returns the corresponding localized label for the given context slug, if possible from installed message
390
-     * types. Otherwise, this will just return the set context slug on this object.
391
-     *
392
-     * @return string
393
-     */
394
-    public function context_label()
395
-    {
396
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
397
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
398
-        $contexts = $message_resource_manager->get_all_contexts();
399
-        return isset($contexts[ $this->context() ]) ? $contexts[ $this->context() ] : $this->context();
400
-    }
401
-
402
-
403
-    /**
404
-     * Sets context
405
-     *
406
-     * @param string $context
407
-     */
408
-    public function set_context($context)
409
-    {
410
-        $this->set('MSG_context', $context);
411
-    }
412
-
413
-
414
-    /**
415
-     * Gets recipient_ID
416
-     *
417
-     * @return int
418
-     */
419
-    public function recipient_ID()
420
-    {
421
-        return $this->get('MSG_recipient_ID');
422
-    }
423
-
424
-
425
-    /**
426
-     * Sets recipient_ID
427
-     *
428
-     * @param string $recipient_ID
429
-     */
430
-    public function set_recipient_ID($recipient_ID)
431
-    {
432
-        $this->set('MSG_recipient_ID', $recipient_ID);
433
-    }
434
-
435
-
436
-    /**
437
-     * Gets recipient_type
438
-     *
439
-     * @return string
440
-     */
441
-    public function recipient_type()
442
-    {
443
-        return $this->get('MSG_recipient_type');
444
-    }
445
-
446
-
447
-    /**
448
-     * Return the related object matching the recipient type and ID.
449
-     *
450
-     * @return EE_Base_Class | null
451
-     */
452
-    public function recipient_object()
453
-    {
454
-        if (! $this->recipient_type() || ! $this->recipient_ID()) {
455
-            return null;
456
-        }
457
-
458
-        return $this->get_first_related($this->recipient_type());
459
-    }
460
-
461
-
462
-    /**
463
-     * Sets recipient_type
464
-     *
465
-     * @param string $recipient_type
466
-     */
467
-    public function set_recipient_type($recipient_type)
468
-    {
469
-        $this->set('MSG_recipient_type', $recipient_type);
470
-    }
471
-
472
-
473
-    /**
474
-     * Gets content
475
-     *
476
-     * @return string
477
-     */
478
-    public function content()
479
-    {
480
-        return $this->get('MSG_content');
481
-    }
482
-
483
-
484
-    /**
485
-     * Sets content
486
-     *
487
-     * @param string $content
488
-     */
489
-    public function set_content($content)
490
-    {
491
-        $this->set('MSG_content', $content);
492
-    }
493
-
494
-
495
-    /**
496
-     * Gets subject
497
-     *
498
-     * @return string
499
-     */
500
-    public function subject()
501
-    {
502
-        return $this->get('MSG_subject');
503
-    }
504
-
505
-
506
-    /**
507
-     * Sets subject
508
-     *
509
-     * @param string $subject
510
-     */
511
-    public function set_subject($subject)
512
-    {
513
-        $this->set('MSG_subject', $subject);
514
-    }
515
-
516
-
517
-    /**
518
-     * Gets to
519
-     *
520
-     * @return string
521
-     */
522
-    public function to()
523
-    {
524
-        $to = $this->get('MSG_to');
525
-        return empty($to) ? esc_html__('No recipient', 'event_espresso') : $to;
526
-    }
527
-
528
-
529
-    /**
530
-     * Sets to
531
-     *
532
-     * @param string $to
533
-     */
534
-    public function set_to($to)
535
-    {
536
-        $this->set('MSG_to', $to);
537
-    }
538
-
539
-
540
-    /**
541
-     * Gets from
542
-     *
543
-     * @return string
544
-     */
545
-    public function from()
546
-    {
547
-        return $this->get('MSG_from');
548
-    }
549
-
550
-
551
-    /**
552
-     * Sets from
553
-     *
554
-     * @param string $from
555
-     */
556
-    public function set_from($from)
557
-    {
558
-        $this->set('MSG_from', $from);
559
-    }
560
-
561
-
562
-    /**
563
-     * Gets priority
564
-     *
565
-     * @return int
566
-     */
567
-    public function priority()
568
-    {
569
-        return $this->get('MSG_priority');
570
-    }
571
-
572
-
573
-    /**
574
-     * Sets priority
575
-     * Note.  Send Now Messengers always override any priority that may be set on a Message.  So
576
-     * this method calls the send_now method to verify that.
577
-     *
578
-     * @param int $priority
579
-     */
580
-    public function set_priority($priority)
581
-    {
582
-        $priority = $this->send_now() ? EEM_Message::priority_high : $priority;
583
-        parent::set('MSG_priority', $priority);
584
-    }
585
-
586
-
587
-    /**
588
-     * Overrides parent::set method so we can capture any sets for priority.
589
-     *
590
-     * @see parent::set() for phpdocs
591
-     * @param string $field_name
592
-     * @param mixed  $field_value
593
-     * @param bool   $use_default
594
-     * @throws EE_Error
595
-     */
596
-    public function set($field_name, $field_value, $use_default = false)
597
-    {
598
-        if ($field_name === 'MSG_priority') {
599
-            $this->set_priority($field_value);
600
-        }
601
-        parent::set($field_name, $field_value, $use_default);
602
-    }
603
-
604
-
605
-    /**
606
-     * @return bool
607
-     * @throws \EE_Error
608
-     */
609
-    public function send_now()
610
-    {
611
-        $send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high
612
-            : $this->priority();
613
-        return $send_now === EEM_Message::priority_high ? true : false;
614
-    }
615
-
616
-
617
-    /**
618
-     * Gets STS_ID
619
-     *
620
-     * @return string
621
-     */
622
-    public function STS_ID()
623
-    {
624
-        return $this->get('STS_ID');
625
-    }
626
-
627
-
628
-    /**
629
-     * Sets STS_ID
630
-     *
631
-     * @param string $STS_ID
632
-     */
633
-    public function set_STS_ID($STS_ID)
634
-    {
635
-        $this->set('STS_ID', $STS_ID);
636
-    }
637
-
638
-
639
-    /**
640
-     * Gets created
641
-     *
642
-     * @return string
643
-     */
644
-    public function created()
645
-    {
646
-        return $this->get('MSG_created');
647
-    }
648
-
649
-
650
-    /**
651
-     * Sets created
652
-     *
653
-     * @param string $created
654
-     */
655
-    public function set_created($created)
656
-    {
657
-        $this->set('MSG_created', $created);
658
-    }
659
-
660
-
661
-    /**
662
-     * Gets modified
663
-     *
664
-     * @return string
665
-     */
666
-    public function modified()
667
-    {
668
-        return $this->get('MSG_modified');
669
-    }
670
-
671
-
672
-    /**
673
-     * Sets modified
674
-     *
675
-     * @param string $modified
676
-     */
677
-    public function set_modified($modified)
678
-    {
679
-        $this->set('MSG_modified', $modified);
680
-    }
681
-
682
-
683
-    /**
684
-     * Sets generation data for this message.
685
-     *
686
-     * @param mixed $data
687
-     */
688
-    public function set_generation_data($data)
689
-    {
690
-        $this->set_field_or_extra_meta('MSG_generation_data', $data);
691
-    }
692
-
693
-
694
-    /**
695
-     * Returns any set generation data for this message.
696
-     *
697
-     * @return mixed|null
698
-     */
699
-    public function get_generation_data()
700
-    {
701
-        return $this->get_field_or_extra_meta('MSG_generation_data');
702
-    }
703
-
704
-
705
-    /**
706
-     * Gets any error message.
707
-     *
708
-     * @return mixed|null
709
-     */
710
-    public function error_message()
711
-    {
712
-        return $this->get_field_or_extra_meta('MSG_error');
713
-    }
714
-
715
-
716
-    /**
717
-     * Sets an error message.
718
-     *
719
-     * @param $message
720
-     * @return bool|int
721
-     */
722
-    public function set_error_message($message)
723
-    {
724
-        return $this->set_field_or_extra_meta('MSG_error', $message);
725
-    }
726
-
727
-
728
-    /**
729
-     * This retrieves the associated template pack with this message.
730
-     *
731
-     * @return EE_Messages_Template_Pack | null
732
-     */
733
-    public function get_template_pack()
734
-    {
735
-        /**
736
-         * This is deprecated functionality that will be removed eventually but included here now for backward compat.
737
-         */
738
-        if (! empty($this->template_pack)) {
739
-            return $this->template_pack;
740
-        }
741
-        /** @type EE_Message_Template_Group $grp */
742
-        $grp = $this->get_first_related('Message_Template_Group');
743
-        // if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
744
-        if (! $grp instanceof EE_Message_Template_Group) {
745
-            $grp = EEM_Message_Template_Group::instance()->get_one(
746
-                array(
747
-                    array(
748
-                        'MTP_messenger'    => $this->messenger(),
749
-                        'MTP_message_type' => $this->message_type(),
750
-                        'MTP_is_global'    => true,
751
-                    ),
752
-                )
753
-            );
754
-        }
755
-
756
-        return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null;
757
-    }
758
-
759
-
760
-    /**
761
-     * Retrieves the variation used for generating this message.
762
-     *
763
-     * @return string
764
-     */
765
-    public function get_template_pack_variation()
766
-    {
767
-        /**
768
-         * This is deprecated functionality that will be removed eventually but included here now for backward compat.
769
-         */
770
-        if (! empty($this->template_variation)) {
771
-            return $this->template_variation;
772
-        }
773
-
774
-        /** @type EE_Message_Template_Group $grp */
775
-        $grp = $this->get_first_related('Message_Template_Group');
776
-
777
-        // if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
778
-        if (! $grp instanceof EE_Message_Template_Group) {
779
-            $grp = EEM_Message_Template_Group::instance()->get_one(
780
-                array(
781
-                    array(
782
-                        'MTP_messenger'    => $this->messenger(),
783
-                        'MTP_message_type' => $this->message_type(),
784
-                        'MTP_is_global'    => true,
785
-                    ),
786
-                )
787
-            );
788
-        }
789
-
790
-        return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : '';
791
-    }
792
-
793
-    /**
794
-     * Return the link to the admin details for the object.
795
-     *
796
-     * @return string
797
-     */
798
-    public function get_admin_details_link()
799
-    {
800
-        EE_Registry::instance()->load_helper('URL');
801
-        EE_Registry::instance()->load_helper('MSG_Template');
802
-        switch ($this->STS_ID()) {
803
-            case EEM_Message::status_failed:
804
-            case EEM_Message::status_debug_only:
805
-                return EEH_MSG_Template::generate_error_display_trigger($this);
806
-                break;
807
-
808
-            case EEM_Message::status_sent:
809
-                return EEH_MSG_Template::generate_browser_trigger($this);
810
-                break;
811
-
812
-            default:
813
-                return '';
814
-        }
815
-    }
816
-
817
-    /**
818
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
819
-     *
820
-     * @return string
821
-     */
822
-    public function get_admin_edit_link()
823
-    {
824
-        return $this->get_admin_details_link();
825
-    }
826
-
827
-    /**
828
-     * Returns the link to a settings page for the object.
829
-     *
830
-     * @return string
831
-     */
832
-    public function get_admin_settings_link()
833
-    {
834
-        EE_Registry::instance()->load_helper('URL');
835
-        return EEH_URL::add_query_args_and_nonce(
836
-            array(
837
-                'page'   => 'espresso_messages',
838
-                'action' => 'settings',
839
-            ),
840
-            admin_url('admin.php')
841
-        );
842
-    }
843
-
844
-    /**
845
-     * Returns the link to the "overview" for the object (typically the "list table" view).
846
-     *
847
-     * @return string
848
-     */
849
-    public function get_admin_overview_link()
850
-    {
851
-        EE_Registry::instance()->load_helper('URL');
852
-        return EEH_URL::add_query_args_and_nonce(
853
-            array(
854
-                'page'   => 'espresso_messages',
855
-                'action' => 'default',
856
-            ),
857
-            admin_url('admin.php')
858
-        );
859
-    }
860
-
861
-
862
-    /**
863
-     * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for
864
-     * it.
865
-     * Note this also SAVES the current message object to the db because it adds an error message to accompany the
866
-     * status.
867
-     *
868
-     */
869
-    public function set_messenger_is_executing()
870
-    {
871
-        $this->set_STS_ID(EEM_Message::status_messenger_executing);
872
-        $this->set_error_message(
873
-            esc_html__(
874
-                'A message with this status indicates that there was a problem that occurred while the message was being
12
+	/**
13
+	 * @deprecated 4.9.0  Added for backward compat with add-on's
14
+	 * @type null
15
+	 */
16
+	public $template_pack;
17
+
18
+	/**
19
+	 * @deprecated 4.9.0 Added for backward compat with add-on's
20
+	 * @type null
21
+	 */
22
+	public $template_variation;
23
+
24
+	/**
25
+	 * @deprecated 4.9.0 Added for backward compat with add-on's
26
+	 * @type string
27
+	 */
28
+	public $content = '';
29
+
30
+
31
+	/**
32
+	 * @type EE_messenger $_messenger
33
+	 */
34
+	protected $_messenger = null;
35
+
36
+	/**
37
+	 * @type EE_message_type $_message_type
38
+	 */
39
+	protected $_message_type = null;
40
+
41
+
42
+	/**
43
+	 * @param array  $props_n_values
44
+	 * @param string $timezone
45
+	 * @param array  $date_formats incoming date formats in an array.  First value is the date_format, second is time
46
+	 *                             format.
47
+	 * @return EE_Message
48
+	 */
49
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
50
+	{
51
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
52
+		// if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db.
53
+		if (! $has_object) {
54
+			EE_Registry::instance()->load_helper('URL');
55
+			$props_n_values['MSG_token'] = EEH_URL::generate_unique_token();
56
+		}
57
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
58
+	}
59
+
60
+
61
+	/**
62
+	 * @param array  $props_n_values
63
+	 * @param string $timezone
64
+	 * @return EE_Message
65
+	 */
66
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
67
+	{
68
+		return new self($props_n_values, true, $timezone);
69
+	}
70
+
71
+
72
+	/**
73
+	 * Gets MSG_token
74
+	 *
75
+	 * @return int
76
+	 */
77
+	public function MSG_token()
78
+	{
79
+		return $this->get('MSG_token');
80
+	}
81
+
82
+
83
+	/**
84
+	 * Sets MSG_token
85
+	 *
86
+	 * @param int $MSG_token
87
+	 */
88
+	public function set_MSG_token($MSG_token)
89
+	{
90
+		$this->set('MSG_token', $MSG_token);
91
+	}
92
+
93
+
94
+	/**
95
+	 * Gets GRP_ID
96
+	 *
97
+	 * @return int
98
+	 */
99
+	public function GRP_ID()
100
+	{
101
+		return $this->get('GRP_ID');
102
+	}
103
+
104
+
105
+	/**
106
+	 * Sets GRP_ID
107
+	 *
108
+	 * @param int $GRP_ID
109
+	 */
110
+	public function set_GRP_ID($GRP_ID)
111
+	{
112
+		$this->set('GRP_ID', $GRP_ID);
113
+	}
114
+
115
+
116
+	/**
117
+	 * Gets TXN_ID
118
+	 *
119
+	 * @return int
120
+	 */
121
+	public function TXN_ID()
122
+	{
123
+		return $this->get('TXN_ID');
124
+	}
125
+
126
+
127
+	/**
128
+	 * Sets TXN_ID
129
+	 *
130
+	 * @param int $TXN_ID
131
+	 */
132
+	public function set_TXN_ID($TXN_ID)
133
+	{
134
+		$this->set('TXN_ID', $TXN_ID);
135
+	}
136
+
137
+
138
+	/**
139
+	 * Gets messenger
140
+	 *
141
+	 * @return string
142
+	 */
143
+	public function messenger()
144
+	{
145
+		return $this->get('MSG_messenger');
146
+	}
147
+
148
+
149
+	/**
150
+	 * Sets messenger
151
+	 *
152
+	 * @param string $messenger
153
+	 */
154
+	public function set_messenger($messenger)
155
+	{
156
+		$this->set('MSG_messenger', $messenger);
157
+	}
158
+
159
+
160
+	/**
161
+	 * Returns corresponding messenger object for the set messenger on this message
162
+	 *
163
+	 * @return EE_messenger | null
164
+	 */
165
+	public function messenger_object()
166
+	{
167
+		return $this->_messenger;
168
+	}
169
+
170
+
171
+	/**
172
+	 * Sets messenger
173
+	 *
174
+	 * @param EE_messenger $messenger
175
+	 */
176
+	public function set_messenger_object(EE_messenger $messenger)
177
+	{
178
+		$this->_messenger = $messenger;
179
+	}
180
+
181
+
182
+	/**
183
+	 * validates messenger
184
+	 *
185
+	 * @param bool $throw_exceptions
186
+	 * @return bool
187
+	 * @throws \EE_Error
188
+	 */
189
+	public function valid_messenger($throw_exceptions = false)
190
+	{
191
+		if ($this->_messenger instanceof EE_messenger) {
192
+			return true;
193
+		}
194
+		if ($throw_exceptions) {
195
+			throw new EE_Error(
196
+				sprintf(
197
+					esc_html__(
198
+						'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
199
+						'event_espresso'
200
+					),
201
+					$this->messenger()
202
+				)
203
+			);
204
+		}
205
+		return false;
206
+	}
207
+
208
+
209
+	/**
210
+	 * This returns the set localized label for the messenger on this message.
211
+	 * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved
212
+	 * with this message.
213
+	 *
214
+	 * @param   bool $plural whether to return the plural label or not.
215
+	 * @return string
216
+	 */
217
+	public function messenger_label($plural = false)
218
+	{
219
+		$label_type = $plural ? 'plural' : 'singular';
220
+		$messenger = $this->messenger_object();
221
+		return $messenger instanceof EE_messenger ? $messenger->label[ $label_type ] : $this->messenger();
222
+	}
223
+
224
+
225
+	/**
226
+	 * Gets message_type
227
+	 *
228
+	 * @return string
229
+	 */
230
+	public function message_type()
231
+	{
232
+		return $this->get('MSG_message_type');
233
+	}
234
+
235
+
236
+	/**
237
+	 * Sets message_type
238
+	 *
239
+	 * @param string $message_type
240
+	 */
241
+	public function set_message_type($message_type)
242
+	{
243
+		$this->set('MSG_message_type', $message_type);
244
+	}
245
+
246
+
247
+	/**
248
+	 * Returns the message type object for the set message type on this message
249
+	 *
250
+	 * @return EE_message_type | null
251
+	 */
252
+	public function message_type_object()
253
+	{
254
+		return $this->_message_type;
255
+	}
256
+
257
+
258
+	/**
259
+	 * Sets message_type
260
+	 *
261
+	 * @param EE_message_type $message_type
262
+	 * @param bool            $set_priority   This indicates whether to set the priority to whatever the priority is on
263
+	 *                                        the message type or not.
264
+	 */
265
+	public function set_message_type_object(EE_message_type $message_type, $set_priority = false)
266
+	{
267
+		$this->_message_type = $message_type;
268
+		if ($set_priority) {
269
+			$this->set_priority($this->_message_type->get_priority());
270
+		}
271
+	}
272
+
273
+
274
+	/**
275
+	 * validates message_type
276
+	 *
277
+	 * @param bool $throw_exceptions
278
+	 * @return bool
279
+	 * @throws \EE_Error
280
+	 */
281
+	public function valid_message_type($throw_exceptions = false)
282
+	{
283
+		if ($this->_message_type instanceof EE_message_type) {
284
+			return true;
285
+		}
286
+		if ($throw_exceptions) {
287
+			throw new EE_Error(
288
+				sprintf(
289
+					esc_html__(
290
+						'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
291
+						'event_espresso'
292
+					),
293
+					$this->message_type()
294
+				)
295
+			);
296
+		}
297
+		return false;
298
+	}
299
+
300
+
301
+	/**
302
+	 * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects).
303
+	 *
304
+	 * @param bool $throw_exceptions
305
+	 * @return bool
306
+	 * @throws \EE_Error
307
+	 */
308
+	public function is_valid($throw_exceptions = false)
309
+	{
310
+		if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) {
311
+			return true;
312
+		}
313
+		return false;
314
+	}
315
+
316
+
317
+	/**
318
+	 * This validates whether the internal messenger and message type objects are valid for sending.
319
+	 * Three checks are done:
320
+	 * 1. There is a valid messenger object.
321
+	 * 2. There is a valid message type object.
322
+	 * 3. The message type object is active for the messenger.
323
+	 *
324
+	 * @throws EE_Error  But only if $throw_exceptions is set to true.
325
+	 * @param bool $throw_exceptions
326
+	 * @return bool
327
+	 */
328
+	public function is_valid_for_sending_or_generation($throw_exceptions = false)
329
+	{
330
+		$valid = false;
331
+		if ($this->is_valid($throw_exceptions)) {
332
+			/** @var EE_Message_Resource_Manager $message_resource_manager */
333
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
334
+			$valid = $message_resource_manager->is_message_type_active_for_messenger(
335
+				$this->messenger(),
336
+				$this->message_type()
337
+			);
338
+			if (! $valid && $throw_exceptions) {
339
+				throw new EE_Error(
340
+					sprintf(
341
+						esc_html__(
342
+							'The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.',
343
+							'event_espresso'
344
+						),
345
+						$this->message_type(),
346
+						$this->messenger()
347
+					)
348
+				);
349
+			}
350
+		}
351
+		return $valid;
352
+	}
353
+
354
+
355
+	/**
356
+	 * This returns the set localized label for the message type on this message.
357
+	 * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved
358
+	 * with this message.
359
+	 *
360
+	 * @param   bool $plural whether to return the plural label or not.
361
+	 * @return string
362
+	 */
363
+	public function message_type_label($plural = false)
364
+	{
365
+		$label_type = $plural ? 'plural' : 'singular';
366
+		$message_type = $this->message_type_object();
367
+		return $message_type instanceof EE_message_type
368
+			? $message_type->label[ $label_type ]
369
+			: str_replace(
370
+				'_',
371
+				' ',
372
+				$this->message_type()
373
+			);
374
+	}
375
+
376
+
377
+	/**
378
+	 * Gets context
379
+	 *
380
+	 * @return string
381
+	 */
382
+	public function context()
383
+	{
384
+		return $this->get('MSG_context');
385
+	}
386
+
387
+
388
+	/**
389
+	 * This returns the corresponding localized label for the given context slug, if possible from installed message
390
+	 * types. Otherwise, this will just return the set context slug on this object.
391
+	 *
392
+	 * @return string
393
+	 */
394
+	public function context_label()
395
+	{
396
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
397
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
398
+		$contexts = $message_resource_manager->get_all_contexts();
399
+		return isset($contexts[ $this->context() ]) ? $contexts[ $this->context() ] : $this->context();
400
+	}
401
+
402
+
403
+	/**
404
+	 * Sets context
405
+	 *
406
+	 * @param string $context
407
+	 */
408
+	public function set_context($context)
409
+	{
410
+		$this->set('MSG_context', $context);
411
+	}
412
+
413
+
414
+	/**
415
+	 * Gets recipient_ID
416
+	 *
417
+	 * @return int
418
+	 */
419
+	public function recipient_ID()
420
+	{
421
+		return $this->get('MSG_recipient_ID');
422
+	}
423
+
424
+
425
+	/**
426
+	 * Sets recipient_ID
427
+	 *
428
+	 * @param string $recipient_ID
429
+	 */
430
+	public function set_recipient_ID($recipient_ID)
431
+	{
432
+		$this->set('MSG_recipient_ID', $recipient_ID);
433
+	}
434
+
435
+
436
+	/**
437
+	 * Gets recipient_type
438
+	 *
439
+	 * @return string
440
+	 */
441
+	public function recipient_type()
442
+	{
443
+		return $this->get('MSG_recipient_type');
444
+	}
445
+
446
+
447
+	/**
448
+	 * Return the related object matching the recipient type and ID.
449
+	 *
450
+	 * @return EE_Base_Class | null
451
+	 */
452
+	public function recipient_object()
453
+	{
454
+		if (! $this->recipient_type() || ! $this->recipient_ID()) {
455
+			return null;
456
+		}
457
+
458
+		return $this->get_first_related($this->recipient_type());
459
+	}
460
+
461
+
462
+	/**
463
+	 * Sets recipient_type
464
+	 *
465
+	 * @param string $recipient_type
466
+	 */
467
+	public function set_recipient_type($recipient_type)
468
+	{
469
+		$this->set('MSG_recipient_type', $recipient_type);
470
+	}
471
+
472
+
473
+	/**
474
+	 * Gets content
475
+	 *
476
+	 * @return string
477
+	 */
478
+	public function content()
479
+	{
480
+		return $this->get('MSG_content');
481
+	}
482
+
483
+
484
+	/**
485
+	 * Sets content
486
+	 *
487
+	 * @param string $content
488
+	 */
489
+	public function set_content($content)
490
+	{
491
+		$this->set('MSG_content', $content);
492
+	}
493
+
494
+
495
+	/**
496
+	 * Gets subject
497
+	 *
498
+	 * @return string
499
+	 */
500
+	public function subject()
501
+	{
502
+		return $this->get('MSG_subject');
503
+	}
504
+
505
+
506
+	/**
507
+	 * Sets subject
508
+	 *
509
+	 * @param string $subject
510
+	 */
511
+	public function set_subject($subject)
512
+	{
513
+		$this->set('MSG_subject', $subject);
514
+	}
515
+
516
+
517
+	/**
518
+	 * Gets to
519
+	 *
520
+	 * @return string
521
+	 */
522
+	public function to()
523
+	{
524
+		$to = $this->get('MSG_to');
525
+		return empty($to) ? esc_html__('No recipient', 'event_espresso') : $to;
526
+	}
527
+
528
+
529
+	/**
530
+	 * Sets to
531
+	 *
532
+	 * @param string $to
533
+	 */
534
+	public function set_to($to)
535
+	{
536
+		$this->set('MSG_to', $to);
537
+	}
538
+
539
+
540
+	/**
541
+	 * Gets from
542
+	 *
543
+	 * @return string
544
+	 */
545
+	public function from()
546
+	{
547
+		return $this->get('MSG_from');
548
+	}
549
+
550
+
551
+	/**
552
+	 * Sets from
553
+	 *
554
+	 * @param string $from
555
+	 */
556
+	public function set_from($from)
557
+	{
558
+		$this->set('MSG_from', $from);
559
+	}
560
+
561
+
562
+	/**
563
+	 * Gets priority
564
+	 *
565
+	 * @return int
566
+	 */
567
+	public function priority()
568
+	{
569
+		return $this->get('MSG_priority');
570
+	}
571
+
572
+
573
+	/**
574
+	 * Sets priority
575
+	 * Note.  Send Now Messengers always override any priority that may be set on a Message.  So
576
+	 * this method calls the send_now method to verify that.
577
+	 *
578
+	 * @param int $priority
579
+	 */
580
+	public function set_priority($priority)
581
+	{
582
+		$priority = $this->send_now() ? EEM_Message::priority_high : $priority;
583
+		parent::set('MSG_priority', $priority);
584
+	}
585
+
586
+
587
+	/**
588
+	 * Overrides parent::set method so we can capture any sets for priority.
589
+	 *
590
+	 * @see parent::set() for phpdocs
591
+	 * @param string $field_name
592
+	 * @param mixed  $field_value
593
+	 * @param bool   $use_default
594
+	 * @throws EE_Error
595
+	 */
596
+	public function set($field_name, $field_value, $use_default = false)
597
+	{
598
+		if ($field_name === 'MSG_priority') {
599
+			$this->set_priority($field_value);
600
+		}
601
+		parent::set($field_name, $field_value, $use_default);
602
+	}
603
+
604
+
605
+	/**
606
+	 * @return bool
607
+	 * @throws \EE_Error
608
+	 */
609
+	public function send_now()
610
+	{
611
+		$send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high
612
+			: $this->priority();
613
+		return $send_now === EEM_Message::priority_high ? true : false;
614
+	}
615
+
616
+
617
+	/**
618
+	 * Gets STS_ID
619
+	 *
620
+	 * @return string
621
+	 */
622
+	public function STS_ID()
623
+	{
624
+		return $this->get('STS_ID');
625
+	}
626
+
627
+
628
+	/**
629
+	 * Sets STS_ID
630
+	 *
631
+	 * @param string $STS_ID
632
+	 */
633
+	public function set_STS_ID($STS_ID)
634
+	{
635
+		$this->set('STS_ID', $STS_ID);
636
+	}
637
+
638
+
639
+	/**
640
+	 * Gets created
641
+	 *
642
+	 * @return string
643
+	 */
644
+	public function created()
645
+	{
646
+		return $this->get('MSG_created');
647
+	}
648
+
649
+
650
+	/**
651
+	 * Sets created
652
+	 *
653
+	 * @param string $created
654
+	 */
655
+	public function set_created($created)
656
+	{
657
+		$this->set('MSG_created', $created);
658
+	}
659
+
660
+
661
+	/**
662
+	 * Gets modified
663
+	 *
664
+	 * @return string
665
+	 */
666
+	public function modified()
667
+	{
668
+		return $this->get('MSG_modified');
669
+	}
670
+
671
+
672
+	/**
673
+	 * Sets modified
674
+	 *
675
+	 * @param string $modified
676
+	 */
677
+	public function set_modified($modified)
678
+	{
679
+		$this->set('MSG_modified', $modified);
680
+	}
681
+
682
+
683
+	/**
684
+	 * Sets generation data for this message.
685
+	 *
686
+	 * @param mixed $data
687
+	 */
688
+	public function set_generation_data($data)
689
+	{
690
+		$this->set_field_or_extra_meta('MSG_generation_data', $data);
691
+	}
692
+
693
+
694
+	/**
695
+	 * Returns any set generation data for this message.
696
+	 *
697
+	 * @return mixed|null
698
+	 */
699
+	public function get_generation_data()
700
+	{
701
+		return $this->get_field_or_extra_meta('MSG_generation_data');
702
+	}
703
+
704
+
705
+	/**
706
+	 * Gets any error message.
707
+	 *
708
+	 * @return mixed|null
709
+	 */
710
+	public function error_message()
711
+	{
712
+		return $this->get_field_or_extra_meta('MSG_error');
713
+	}
714
+
715
+
716
+	/**
717
+	 * Sets an error message.
718
+	 *
719
+	 * @param $message
720
+	 * @return bool|int
721
+	 */
722
+	public function set_error_message($message)
723
+	{
724
+		return $this->set_field_or_extra_meta('MSG_error', $message);
725
+	}
726
+
727
+
728
+	/**
729
+	 * This retrieves the associated template pack with this message.
730
+	 *
731
+	 * @return EE_Messages_Template_Pack | null
732
+	 */
733
+	public function get_template_pack()
734
+	{
735
+		/**
736
+		 * This is deprecated functionality that will be removed eventually but included here now for backward compat.
737
+		 */
738
+		if (! empty($this->template_pack)) {
739
+			return $this->template_pack;
740
+		}
741
+		/** @type EE_Message_Template_Group $grp */
742
+		$grp = $this->get_first_related('Message_Template_Group');
743
+		// if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
744
+		if (! $grp instanceof EE_Message_Template_Group) {
745
+			$grp = EEM_Message_Template_Group::instance()->get_one(
746
+				array(
747
+					array(
748
+						'MTP_messenger'    => $this->messenger(),
749
+						'MTP_message_type' => $this->message_type(),
750
+						'MTP_is_global'    => true,
751
+					),
752
+				)
753
+			);
754
+		}
755
+
756
+		return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null;
757
+	}
758
+
759
+
760
+	/**
761
+	 * Retrieves the variation used for generating this message.
762
+	 *
763
+	 * @return string
764
+	 */
765
+	public function get_template_pack_variation()
766
+	{
767
+		/**
768
+		 * This is deprecated functionality that will be removed eventually but included here now for backward compat.
769
+		 */
770
+		if (! empty($this->template_variation)) {
771
+			return $this->template_variation;
772
+		}
773
+
774
+		/** @type EE_Message_Template_Group $grp */
775
+		$grp = $this->get_first_related('Message_Template_Group');
776
+
777
+		// if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
778
+		if (! $grp instanceof EE_Message_Template_Group) {
779
+			$grp = EEM_Message_Template_Group::instance()->get_one(
780
+				array(
781
+					array(
782
+						'MTP_messenger'    => $this->messenger(),
783
+						'MTP_message_type' => $this->message_type(),
784
+						'MTP_is_global'    => true,
785
+					),
786
+				)
787
+			);
788
+		}
789
+
790
+		return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : '';
791
+	}
792
+
793
+	/**
794
+	 * Return the link to the admin details for the object.
795
+	 *
796
+	 * @return string
797
+	 */
798
+	public function get_admin_details_link()
799
+	{
800
+		EE_Registry::instance()->load_helper('URL');
801
+		EE_Registry::instance()->load_helper('MSG_Template');
802
+		switch ($this->STS_ID()) {
803
+			case EEM_Message::status_failed:
804
+			case EEM_Message::status_debug_only:
805
+				return EEH_MSG_Template::generate_error_display_trigger($this);
806
+				break;
807
+
808
+			case EEM_Message::status_sent:
809
+				return EEH_MSG_Template::generate_browser_trigger($this);
810
+				break;
811
+
812
+			default:
813
+				return '';
814
+		}
815
+	}
816
+
817
+	/**
818
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
819
+	 *
820
+	 * @return string
821
+	 */
822
+	public function get_admin_edit_link()
823
+	{
824
+		return $this->get_admin_details_link();
825
+	}
826
+
827
+	/**
828
+	 * Returns the link to a settings page for the object.
829
+	 *
830
+	 * @return string
831
+	 */
832
+	public function get_admin_settings_link()
833
+	{
834
+		EE_Registry::instance()->load_helper('URL');
835
+		return EEH_URL::add_query_args_and_nonce(
836
+			array(
837
+				'page'   => 'espresso_messages',
838
+				'action' => 'settings',
839
+			),
840
+			admin_url('admin.php')
841
+		);
842
+	}
843
+
844
+	/**
845
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
846
+	 *
847
+	 * @return string
848
+	 */
849
+	public function get_admin_overview_link()
850
+	{
851
+		EE_Registry::instance()->load_helper('URL');
852
+		return EEH_URL::add_query_args_and_nonce(
853
+			array(
854
+				'page'   => 'espresso_messages',
855
+				'action' => 'default',
856
+			),
857
+			admin_url('admin.php')
858
+		);
859
+	}
860
+
861
+
862
+	/**
863
+	 * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for
864
+	 * it.
865
+	 * Note this also SAVES the current message object to the db because it adds an error message to accompany the
866
+	 * status.
867
+	 *
868
+	 */
869
+	public function set_messenger_is_executing()
870
+	{
871
+		$this->set_STS_ID(EEM_Message::status_messenger_executing);
872
+		$this->set_error_message(
873
+			esc_html__(
874
+				'A message with this status indicates that there was a problem that occurred while the message was being
875 875
                 processed by the messenger.  It is still possible that the message was sent successfully, but at some
876 876
                 point during the processing there was a failure.  This usually is indicative of a timeout issue with PHP 
877 877
                 or memory limits being reached.  If you see this repeatedly you may want to consider upgrading the memory 
878 878
                 available to PHP on your server.',
879
-                'event_espresso'
880
-            )
881
-        );
882
-    }
879
+				'event_espresso'
880
+			)
881
+		);
882
+	}
883 883
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Message_Template.class.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@
 block discarded – undo
42 42
      */
43 43
     public function set_group_template_id($GRP_ID = false)
44 44
     {
45
-        if (! $GRP_ID) {
45
+        if ( ! $GRP_ID) {
46 46
             throw new EE_Error(esc_html__('Missing required value for the message template group id', 'event_espresso'));
47 47
         }
48 48
         $this->set('GRP_ID', $GRP_ID);
Please login to merge, or discard this patch.
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -12,173 +12,173 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Message_Template extends EE_Base_Class
14 14
 {
15
-    /**
16
-     * @param array  $props_n_values
17
-     * @param string $timezone
18
-     * @return EE_Message_Template|mixed
19
-     */
20
-    public static function new_instance($props_n_values = array(), $timezone = '')
21
-    {
22
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone);
23
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone);
24
-    }
25
-
26
-
27
-    /**
28
-     * @param array  $props_n_values
29
-     * @param string $timezone
30
-     * @return EE_Message_Template
31
-     */
32
-    public static function new_instance_from_db($props_n_values = array(), $timezone = '')
33
-    {
34
-        return new self($props_n_values, true, $timezone);
35
-    }
36
-
37
-
38
-    /**
39
-     * @param bool $GRP_ID
40
-     * @throws EE_Error
41
-     */
42
-    public function set_group_template_id($GRP_ID = false)
43
-    {
44
-        if (! $GRP_ID) {
45
-            throw new EE_Error(esc_html__('Missing required value for the message template group id', 'event_espresso'));
46
-        }
47
-        $this->set('GRP_ID', $GRP_ID);
48
-    }
49
-
50
-
51
-    /**
52
-     * get Group ID
53
-     *
54
-     * @access public
55
-     * @return int
56
-     */
57
-    public function GRP_ID()
58
-    {
59
-        return $this->get('GRP_ID');
60
-    }
61
-
62
-
63
-    /**
64
-     * get User ID
65
-     *
66
-     * @access public
67
-     * @return int
68
-     */
69
-    public function user()
70
-    {
71
-        return $this->get_first_related('Message_Template_Group')->get('MTP_user_id');
72
-    }
73
-
74
-
75
-    /**
76
-     * get Message Messenger
77
-     *
78
-     * @access public
79
-     * @return string
80
-     */
81
-    public function messenger()
82
-    {
83
-        return $this->get_first_related('Message_Template_Group')->messenger();
84
-    }
85
-
86
-
87
-    /**
88
-     * get Message Messenger OBJECT
89
-     *
90
-     * @access public
91
-     * @return object Messenger Object for the given messenger
92
-     */
93
-    public function messenger_obj()
94
-    {
95
-        return $this->get_first_related('Message_Template_Group')->messenger_obj();
96
-    }
97
-
98
-
99
-    /**
100
-     * get Message Type
101
-     *
102
-     * @access public
103
-     * @return string
104
-     */
105
-    public function message_type()
106
-    {
107
-        return $this->get_first_related('Message_Template_Group')->message_type();
108
-    }
109
-
110
-
111
-    /**
112
-     * get Message type OBJECT
113
-     *
114
-     * @access public
115
-     * @return object  Message Type object for the given message type
116
-     */
117
-    public function message_type_obj()
118
-    {
119
-        return $this->get_first_related('Message_Template_Group')->message_type_obj();
120
-    }
121
-
122
-
123
-    /**
124
-     * This returns the set context array configured in the message type object
125
-     *
126
-     * @access public
127
-     * @return array array of contexts and their configuration.
128
-     */
129
-    public function contexts_config()
130
-    {
131
-        return $this->get_first_related('Message_Template_Group')->contexts_config();
132
-    }
133
-
134
-
135
-    /**
136
-     * This returns the context_label for contexts as set in the message type object
137
-     *
138
-     * @access public
139
-     * @return string label for "context"
140
-     */
141
-    public function context_label()
142
-    {
143
-        return $this->get_first_related('Message_Template_Group')->context_label();
144
-    }
145
-
146
-
147
-    /**
148
-     * this returns if the template group this template belongs to is global
149
-     *
150
-     * @return boolean true if it is, false if it isn't
151
-     */
152
-    public function is_global()
153
-    {
154
-        return $this->get_first_related('Message_Template_Group')->is_global();
155
-    }
156
-
157
-
158
-    /**
159
-     * this returns if the template group this template belongs to is active (i.e. turned "on" or not)
160
-     *
161
-     * @return boolean true if it is, false if it isn't
162
-     */
163
-    public function is_active()
164
-    {
165
-        return $this->get_first_related('Message_Template_Group')->is_active();
166
-    }
167
-
168
-
169
-    /**
170
-     * This will return an array of shortcodes => labels from the messenger and message_type objects associated with
171
-     * this template.
172
-     *
173
-     * @access public
174
-     * @param string $context what context we're going to return shortcodes for
175
-     * @param array  $fields  what fields we're returning valid shortcodes for.  If empty then we assume all fields are
176
-     *                        to be merged and returned.
177
-     * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no
178
-     *               shortcodes found.
179
-     */
180
-    public function get_shortcodes($context, $fields = array())
181
-    {
182
-        return $this->get_first_related('Message_Template_Group')->get_shortcodes($context, $fields);
183
-    }
15
+	/**
16
+	 * @param array  $props_n_values
17
+	 * @param string $timezone
18
+	 * @return EE_Message_Template|mixed
19
+	 */
20
+	public static function new_instance($props_n_values = array(), $timezone = '')
21
+	{
22
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone);
23
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone);
24
+	}
25
+
26
+
27
+	/**
28
+	 * @param array  $props_n_values
29
+	 * @param string $timezone
30
+	 * @return EE_Message_Template
31
+	 */
32
+	public static function new_instance_from_db($props_n_values = array(), $timezone = '')
33
+	{
34
+		return new self($props_n_values, true, $timezone);
35
+	}
36
+
37
+
38
+	/**
39
+	 * @param bool $GRP_ID
40
+	 * @throws EE_Error
41
+	 */
42
+	public function set_group_template_id($GRP_ID = false)
43
+	{
44
+		if (! $GRP_ID) {
45
+			throw new EE_Error(esc_html__('Missing required value for the message template group id', 'event_espresso'));
46
+		}
47
+		$this->set('GRP_ID', $GRP_ID);
48
+	}
49
+
50
+
51
+	/**
52
+	 * get Group ID
53
+	 *
54
+	 * @access public
55
+	 * @return int
56
+	 */
57
+	public function GRP_ID()
58
+	{
59
+		return $this->get('GRP_ID');
60
+	}
61
+
62
+
63
+	/**
64
+	 * get User ID
65
+	 *
66
+	 * @access public
67
+	 * @return int
68
+	 */
69
+	public function user()
70
+	{
71
+		return $this->get_first_related('Message_Template_Group')->get('MTP_user_id');
72
+	}
73
+
74
+
75
+	/**
76
+	 * get Message Messenger
77
+	 *
78
+	 * @access public
79
+	 * @return string
80
+	 */
81
+	public function messenger()
82
+	{
83
+		return $this->get_first_related('Message_Template_Group')->messenger();
84
+	}
85
+
86
+
87
+	/**
88
+	 * get Message Messenger OBJECT
89
+	 *
90
+	 * @access public
91
+	 * @return object Messenger Object for the given messenger
92
+	 */
93
+	public function messenger_obj()
94
+	{
95
+		return $this->get_first_related('Message_Template_Group')->messenger_obj();
96
+	}
97
+
98
+
99
+	/**
100
+	 * get Message Type
101
+	 *
102
+	 * @access public
103
+	 * @return string
104
+	 */
105
+	public function message_type()
106
+	{
107
+		return $this->get_first_related('Message_Template_Group')->message_type();
108
+	}
109
+
110
+
111
+	/**
112
+	 * get Message type OBJECT
113
+	 *
114
+	 * @access public
115
+	 * @return object  Message Type object for the given message type
116
+	 */
117
+	public function message_type_obj()
118
+	{
119
+		return $this->get_first_related('Message_Template_Group')->message_type_obj();
120
+	}
121
+
122
+
123
+	/**
124
+	 * This returns the set context array configured in the message type object
125
+	 *
126
+	 * @access public
127
+	 * @return array array of contexts and their configuration.
128
+	 */
129
+	public function contexts_config()
130
+	{
131
+		return $this->get_first_related('Message_Template_Group')->contexts_config();
132
+	}
133
+
134
+
135
+	/**
136
+	 * This returns the context_label for contexts as set in the message type object
137
+	 *
138
+	 * @access public
139
+	 * @return string label for "context"
140
+	 */
141
+	public function context_label()
142
+	{
143
+		return $this->get_first_related('Message_Template_Group')->context_label();
144
+	}
145
+
146
+
147
+	/**
148
+	 * this returns if the template group this template belongs to is global
149
+	 *
150
+	 * @return boolean true if it is, false if it isn't
151
+	 */
152
+	public function is_global()
153
+	{
154
+		return $this->get_first_related('Message_Template_Group')->is_global();
155
+	}
156
+
157
+
158
+	/**
159
+	 * this returns if the template group this template belongs to is active (i.e. turned "on" or not)
160
+	 *
161
+	 * @return boolean true if it is, false if it isn't
162
+	 */
163
+	public function is_active()
164
+	{
165
+		return $this->get_first_related('Message_Template_Group')->is_active();
166
+	}
167
+
168
+
169
+	/**
170
+	 * This will return an array of shortcodes => labels from the messenger and message_type objects associated with
171
+	 * this template.
172
+	 *
173
+	 * @access public
174
+	 * @param string $context what context we're going to return shortcodes for
175
+	 * @param array  $fields  what fields we're returning valid shortcodes for.  If empty then we assume all fields are
176
+	 *                        to be merged and returned.
177
+	 * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no
178
+	 *               shortcodes found.
179
+	 */
180
+	public function get_shortcodes($context, $fields = array())
181
+	{
182
+		return $this->get_first_related('Message_Template_Group')->get_shortcodes($context, $fields);
183
+	}
184 184
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Attendee.class.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -36,16 +36,16 @@  discard block
 block discarded – undo
36 36
      */
37 37
     protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array())
38 38
     {
39
-        if (! isset($fieldValues['ATT_full_name'])) {
40
-            $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : '';
39
+        if ( ! isset($fieldValues['ATT_full_name'])) {
40
+            $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'].' ' : '';
41 41
             $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : '';
42
-            $fieldValues['ATT_full_name'] = $fname . $lname;
42
+            $fieldValues['ATT_full_name'] = $fname.$lname;
43 43
         }
44
-        if (! isset($fieldValues['ATT_slug'])) {
44
+        if ( ! isset($fieldValues['ATT_slug'])) {
45 45
             // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20));
46 46
             $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']);
47 47
         }
48
-        if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
48
+        if ( ! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
49 49
             $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50);
50 50
         }
51 51
         parent::__construct($fieldValues, $bydb, $timezone, $date_formats);
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
         $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',);
326 326
         foreach ($initial_address_fields as $address_field_name) {
327 327
             $address_fields_value = $this->get($address_field_name);
328
-            if (! empty($address_fields_value)) {
328
+            if ( ! empty($address_fields_value)) {
329 329
                 $full_address_array[] = $address_fields_value;
330 330
             }
331 331
         }
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
         }
341 341
         // lastly get the xip
342 342
         $zip_value = $this->zip();
343
-        if (! empty($zip_value)) {
343
+        if ( ! empty($zip_value)) {
344 344
             $full_address_array[] = $zip_value;
345 345
         }
346 346
         return $full_address_array;
@@ -622,18 +622,18 @@  discard block
 block discarded – undo
622 622
     public function billing_info_for_payment_method($payment_method)
623 623
     {
624 624
         $pm_type = $payment_method->type_obj();
625
-        if (! $pm_type instanceof EE_PMT_Base) {
625
+        if ( ! $pm_type instanceof EE_PMT_Base) {
626 626
             return null;
627 627
         }
628 628
         $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true);
629
-        if (! $billing_info) {
629
+        if ( ! $billing_info) {
630 630
             return null;
631 631
         }
632 632
         $billing_form = $pm_type->billing_form();
633 633
         // double-check the form isn't totally hidden, in which case pretend there is no form
634 634
         $form_totally_hidden = true;
635 635
         foreach ($billing_form->inputs_in_subsections() as $input) {
636
-            if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
636
+            if ( ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
637 637
                 $form_totally_hidden = false;
638 638
                 break;
639 639
             }
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
     public function get_billing_info_postmeta_name($payment_method)
661 661
     {
662 662
         if ($payment_method->type_obj() instanceof EE_PMT_Base) {
663
-            return 'billing_info_' . $payment_method->type_obj()->system_name();
663
+            return 'billing_info_'.$payment_method->type_obj()->system_name();
664 664
         }
665 665
         return null;
666 666
     }
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
      */
678 678
     public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method)
679 679
     {
680
-        if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
680
+        if ( ! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
681 681
             EE_Error::add_error(esc_html__('Cannot save billing info because there is none.', 'event_espresso'));
682 682
             return false;
683 683
         }
Please login to merge, or discard this patch.
Indentation   +742 added lines, -742 removed lines patch added patch discarded remove patch
@@ -24,746 +24,746 @@
 block discarded – undo
24 24
  */
25 25
 class EE_Attendee extends EE_CPT_Base implements EEI_Contact, EEI_Address, EEI_Admin_Links, EEI_Attendee
26 26
 {
27
-    /**
28
-     * Sets some dynamic defaults
29
-     *
30
-     * @param array  $fieldValues
31
-     * @param bool   $bydb
32
-     * @param string $timezone
33
-     * @param array  $date_formats
34
-     * @throws EE_Error
35
-     */
36
-    protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array())
37
-    {
38
-        if (! isset($fieldValues['ATT_full_name'])) {
39
-            $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : '';
40
-            $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : '';
41
-            $fieldValues['ATT_full_name'] = $fname . $lname;
42
-        }
43
-        if (! isset($fieldValues['ATT_slug'])) {
44
-            // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20));
45
-            $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']);
46
-        }
47
-        if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
48
-            $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50);
49
-        }
50
-        parent::__construct($fieldValues, $bydb, $timezone, $date_formats);
51
-    }
52
-
53
-
54
-    /**
55
-     * @param array  $props_n_values          incoming values
56
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
57
-     *                                        used.)
58
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
59
-     *                                        date_format and the second value is the time format
60
-     * @return EE_Attendee
61
-     * @throws EE_Error
62
-     */
63
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
64
-    {
65
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
66
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
67
-    }
68
-
69
-
70
-    /**
71
-     * @param array  $props_n_values  incoming values from the database
72
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
73
-     *                                the website will be used.
74
-     * @return EE_Attendee
75
-     */
76
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
77
-    {
78
-        return new self($props_n_values, true, $timezone);
79
-    }
80
-
81
-
82
-    /**
83
-     *        Set Attendee First Name
84
-     *
85
-     * @access        public
86
-     * @param string $fname
87
-     * @throws EE_Error
88
-     */
89
-    public function set_fname($fname = '')
90
-    {
91
-        $this->set('ATT_fname', $fname);
92
-    }
93
-
94
-
95
-    /**
96
-     *        Set Attendee Last Name
97
-     *
98
-     * @access        public
99
-     * @param string $lname
100
-     * @throws EE_Error
101
-     */
102
-    public function set_lname($lname = '')
103
-    {
104
-        $this->set('ATT_lname', $lname);
105
-    }
106
-
107
-
108
-    /**
109
-     *        Set Attendee Address
110
-     *
111
-     * @access        public
112
-     * @param string $address
113
-     * @throws EE_Error
114
-     */
115
-    public function set_address($address = '')
116
-    {
117
-        $this->set('ATT_address', $address);
118
-    }
119
-
120
-
121
-    /**
122
-     *        Set Attendee Address2
123
-     *
124
-     * @access        public
125
-     * @param        string $address2
126
-     * @throws EE_Error
127
-     */
128
-    public function set_address2($address2 = '')
129
-    {
130
-        $this->set('ATT_address2', $address2);
131
-    }
132
-
133
-
134
-    /**
135
-     *        Set Attendee City
136
-     *
137
-     * @access        public
138
-     * @param        string $city
139
-     * @throws EE_Error
140
-     */
141
-    public function set_city($city = '')
142
-    {
143
-        $this->set('ATT_city', $city);
144
-    }
145
-
146
-
147
-    /**
148
-     *        Set Attendee State ID
149
-     *
150
-     * @access        public
151
-     * @param        int $STA_ID
152
-     * @throws EE_Error
153
-     */
154
-    public function set_state($STA_ID = 0)
155
-    {
156
-        $this->set('STA_ID', $STA_ID);
157
-    }
158
-
159
-
160
-    /**
161
-     *        Set Attendee Country ISO Code
162
-     *
163
-     * @access        public
164
-     * @param        string $CNT_ISO
165
-     * @throws EE_Error
166
-     */
167
-    public function set_country($CNT_ISO = '')
168
-    {
169
-        $this->set('CNT_ISO', $CNT_ISO);
170
-    }
171
-
172
-
173
-    /**
174
-     *        Set Attendee Zip/Postal Code
175
-     *
176
-     * @access        public
177
-     * @param        string $zip
178
-     * @throws EE_Error
179
-     */
180
-    public function set_zip($zip = '')
181
-    {
182
-        $this->set('ATT_zip', $zip);
183
-    }
184
-
185
-
186
-    /**
187
-     *        Set Attendee Email Address
188
-     *
189
-     * @access        public
190
-     * @param        string $email
191
-     * @throws EE_Error
192
-     */
193
-    public function set_email($email = '')
194
-    {
195
-        $this->set('ATT_email', $email);
196
-    }
197
-
198
-
199
-    /**
200
-     *        Set Attendee Phone
201
-     *
202
-     * @access        public
203
-     * @param        string $phone
204
-     * @throws EE_Error
205
-     */
206
-    public function set_phone($phone = '')
207
-    {
208
-        $this->set('ATT_phone', $phone);
209
-    }
210
-
211
-
212
-    /**
213
-     *        set deleted
214
-     *
215
-     * @access        public
216
-     * @param        bool $ATT_deleted
217
-     * @throws EE_Error
218
-     */
219
-    public function set_deleted($ATT_deleted = false)
220
-    {
221
-        $this->set('ATT_deleted', $ATT_deleted);
222
-    }
223
-
224
-
225
-    /**
226
-     * Returns the value for the post_author id saved with the cpt
227
-     *
228
-     * @since 4.5.0
229
-     * @return int
230
-     * @throws EE_Error
231
-     */
232
-    public function wp_user()
233
-    {
234
-        return $this->get('ATT_author');
235
-    }
236
-
237
-
238
-    /**
239
-     *        get Attendee First Name
240
-     *
241
-     * @access        public
242
-     * @return string
243
-     * @throws EE_Error
244
-     */
245
-    public function fname()
246
-    {
247
-        return $this->get('ATT_fname');
248
-    }
249
-
250
-
251
-    /**
252
-     * echoes out the attendee's first name
253
-     *
254
-     * @return void
255
-     * @throws EE_Error
256
-     */
257
-    public function e_full_name()
258
-    {
259
-        echo esc_html($this->full_name());
260
-    }
261
-
262
-
263
-    /**
264
-     * Returns the first and last name concatenated together with a space.
265
-     *
266
-     * @param bool $apply_html_entities
267
-     * @return string
268
-     * @throws EE_Error
269
-     */
270
-    public function full_name($apply_html_entities = false)
271
-    {
272
-        $full_name = array(
273
-            $this->fname(),
274
-            $this->lname(),
275
-        );
276
-        $full_name = array_filter($full_name);
277
-        $full_name = implode(' ', $full_name);
278
-        return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name;
279
-    }
280
-
281
-
282
-    /**
283
-     * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless
284
-     * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this
285
-     * attendee.
286
-     *
287
-     * @param bool $apply_html_entities
288
-     * @return string
289
-     * @throws EE_Error
290
-     */
291
-    public function ATT_full_name($apply_html_entities = false)
292
-    {
293
-        return $apply_html_entities
294
-            ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8')
295
-            : $this->get('ATT_full_name');
296
-    }
297
-
298
-
299
-    /**
300
-     *        get Attendee Last Name
301
-     *
302
-     * @access        public
303
-     * @return string
304
-     * @throws EE_Error
305
-     */
306
-    public function lname()
307
-    {
308
-        return $this->get('ATT_lname');
309
-    }
310
-
311
-
312
-    /**
313
-     * Gets the attendee's full address as an array so client code can decide hwo to display it
314
-     *
315
-     * @return array numerically indexed, with each part of the address that is known.
316
-     * Eg, if the user only responded to state and country,
317
-     * it would be array(0=>'Alabama',1=>'USA')
318
-     * @return array
319
-     * @throws EE_Error
320
-     */
321
-    public function full_address_as_array()
322
-    {
323
-        $full_address_array = array();
324
-        $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',);
325
-        foreach ($initial_address_fields as $address_field_name) {
326
-            $address_fields_value = $this->get($address_field_name);
327
-            if (! empty($address_fields_value)) {
328
-                $full_address_array[] = $address_fields_value;
329
-            }
330
-        }
331
-        // now handle state and country
332
-        $state_obj = $this->state_obj();
333
-        if ($state_obj instanceof EE_State) {
334
-            $full_address_array[] = $state_obj->name();
335
-        }
336
-        $country_obj = $this->country_obj();
337
-        if ($country_obj instanceof EE_Country) {
338
-            $full_address_array[] = $country_obj->name();
339
-        }
340
-        // lastly get the xip
341
-        $zip_value = $this->zip();
342
-        if (! empty($zip_value)) {
343
-            $full_address_array[] = $zip_value;
344
-        }
345
-        return $full_address_array;
346
-    }
347
-
348
-
349
-    /**
350
-     *        get Attendee Address
351
-     *
352
-     * @return string
353
-     * @throws EE_Error
354
-     */
355
-    public function address()
356
-    {
357
-        return $this->get('ATT_address');
358
-    }
359
-
360
-
361
-    /**
362
-     *        get Attendee Address2
363
-     *
364
-     * @return string
365
-     * @throws EE_Error
366
-     */
367
-    public function address2()
368
-    {
369
-        return $this->get('ATT_address2');
370
-    }
371
-
372
-
373
-    /**
374
-     *        get Attendee City
375
-     *
376
-     * @return string
377
-     * @throws EE_Error
378
-     */
379
-    public function city()
380
-    {
381
-        return $this->get('ATT_city');
382
-    }
383
-
384
-
385
-    /**
386
-     *        get Attendee State ID
387
-     *
388
-     * @return string
389
-     * @throws EE_Error
390
-     */
391
-    public function state_ID()
392
-    {
393
-        return $this->get('STA_ID');
394
-    }
395
-
396
-
397
-    /**
398
-     * @return string
399
-     * @throws EE_Error
400
-     */
401
-    public function state_abbrev()
402
-    {
403
-        return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : '';
404
-    }
405
-
406
-
407
-    /**
408
-     * Gets the state set to this attendee
409
-     *
410
-     * @return EE_State
411
-     * @throws EE_Error
412
-     */
413
-    public function state_obj()
414
-    {
415
-        return $this->get_first_related('State');
416
-    }
417
-
418
-
419
-    /**
420
-     * Returns the state's name, otherwise 'Unknown'
421
-     *
422
-     * @return string
423
-     * @throws EE_Error
424
-     */
425
-    public function state_name()
426
-    {
427
-        if ($this->state_obj()) {
428
-            return $this->state_obj()->name();
429
-        } else {
430
-            return '';
431
-        }
432
-    }
433
-
434
-
435
-    /**
436
-     * either displays the state abbreviation or the state name, as determined
437
-     * by the "FHEE__EEI_Address__state__use_abbreviation" filter.
438
-     * defaults to abbreviation
439
-     *
440
-     * @return string
441
-     * @throws EE_Error
442
-     */
443
-    public function state()
444
-    {
445
-        if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) {
446
-            return $this->state_abbrev();
447
-        }
448
-        return $this->state_name();
449
-    }
450
-
451
-
452
-    /**
453
-     *    get Attendee Country ISO Code
454
-     *
455
-     * @return string
456
-     * @throws EE_Error
457
-     */
458
-    public function country_ID()
459
-    {
460
-        return $this->get('CNT_ISO');
461
-    }
462
-
463
-
464
-    /**
465
-     * Gets country set for this attendee
466
-     *
467
-     * @return EE_Country
468
-     * @throws EE_Error
469
-     */
470
-    public function country_obj()
471
-    {
472
-        return $this->get_first_related('Country');
473
-    }
474
-
475
-
476
-    /**
477
-     * Returns the country's name if known, otherwise 'Unknown'
478
-     *
479
-     * @return string
480
-     * @throws EE_Error
481
-     */
482
-    public function country_name()
483
-    {
484
-        if ($this->country_obj()) {
485
-            return $this->country_obj()->name();
486
-        }
487
-        return '';
488
-    }
489
-
490
-
491
-    /**
492
-     * either displays the country ISO2 code or the country name, as determined
493
-     * by the "FHEE__EEI_Address__country__use_abbreviation" filter.
494
-     * defaults to abbreviation
495
-     *
496
-     * @return string
497
-     * @throws EE_Error
498
-     */
499
-    public function country()
500
-    {
501
-        if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) {
502
-            return $this->country_ID();
503
-        }
504
-        return $this->country_name();
505
-    }
506
-
507
-
508
-    /**
509
-     *        get Attendee Zip/Postal Code
510
-     *
511
-     * @return string
512
-     * @throws EE_Error
513
-     */
514
-    public function zip()
515
-    {
516
-        return $this->get('ATT_zip');
517
-    }
518
-
519
-
520
-    /**
521
-     *        get Attendee Email Address
522
-     *
523
-     * @return string
524
-     * @throws EE_Error
525
-     */
526
-    public function email()
527
-    {
528
-        return $this->get('ATT_email');
529
-    }
530
-
531
-
532
-    /**
533
-     *        get Attendee Phone #
534
-     *
535
-     * @return string
536
-     * @throws EE_Error
537
-     */
538
-    public function phone()
539
-    {
540
-        return $this->get('ATT_phone');
541
-    }
542
-
543
-
544
-    /**
545
-     *    get deleted
546
-     *
547
-     * @return        bool
548
-     * @throws EE_Error
549
-     */
550
-    public function deleted()
551
-    {
552
-        return $this->get('ATT_deleted');
553
-    }
554
-
555
-
556
-    /**
557
-     * Gets registrations of this attendee
558
-     *
559
-     * @param array $query_params
560
-     * @return EE_Registration[]
561
-     * @throws EE_Error
562
-     */
563
-    public function get_registrations($query_params = array())
564
-    {
565
-        return $this->get_many_related('Registration', $query_params);
566
-    }
567
-
568
-
569
-    /**
570
-     * Gets the most recent registration of this attendee
571
-     *
572
-     * @return EE_Registration
573
-     * @throws EE_Error
574
-     */
575
-    public function get_most_recent_registration()
576
-    {
577
-        return $this->get_first_related(
578
-            'Registration',
579
-            array('order_by' => array('REG_date' => 'DESC'))
580
-        ); // null, 'REG_date', 'DESC', '=', 'OBJECT_K');
581
-    }
582
-
583
-
584
-    /**
585
-     * Gets the most recent registration for this attend at this event
586
-     *
587
-     * @param int $event_id
588
-     * @return EE_Registration
589
-     * @throws EE_Error
590
-     */
591
-    public function get_most_recent_registration_for_event($event_id)
592
-    {
593
-        return $this->get_first_related(
594
-            'Registration',
595
-            array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC'))
596
-        );
597
-    }
598
-
599
-
600
-    /**
601
-     * returns any events attached to this attendee ($_Event property);
602
-     *
603
-     * @return array
604
-     * @throws EE_Error
605
-     */
606
-    public function events()
607
-    {
608
-        return $this->get_many_related('Event');
609
-    }
610
-
611
-
612
-    /**
613
-     * Gets the billing info array where keys match espresso_reg_page_billing_inputs(),
614
-     * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was
615
-     * used to save the billing info
616
-     *
617
-     * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class
618
-     * @return EE_Form_Section_Proper|null
619
-     * @throws EE_Error
620
-     */
621
-    public function billing_info_for_payment_method($payment_method)
622
-    {
623
-        $pm_type = $payment_method->type_obj();
624
-        if (! $pm_type instanceof EE_PMT_Base) {
625
-            return null;
626
-        }
627
-        $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true);
628
-        if (! $billing_info) {
629
-            return null;
630
-        }
631
-        $billing_form = $pm_type->billing_form();
632
-        // double-check the form isn't totally hidden, in which case pretend there is no form
633
-        $form_totally_hidden = true;
634
-        foreach ($billing_form->inputs_in_subsections() as $input) {
635
-            if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
636
-                $form_totally_hidden = false;
637
-                break;
638
-            }
639
-        }
640
-        if ($form_totally_hidden) {
641
-            return null;
642
-        }
643
-        if ($billing_form instanceof EE_Form_Section_Proper) {
644
-            $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false);
645
-        }
646
-
647
-        return $billing_form;
648
-    }
649
-
650
-
651
-    /**
652
-     * Gets the postmeta key that holds this attendee's billing info for the
653
-     * specified payment method
654
-     *
655
-     * @param EE_Payment_Method $payment_method
656
-     * @return string
657
-     * @throws EE_Error
658
-     */
659
-    public function get_billing_info_postmeta_name($payment_method)
660
-    {
661
-        if ($payment_method->type_obj() instanceof EE_PMT_Base) {
662
-            return 'billing_info_' . $payment_method->type_obj()->system_name();
663
-        }
664
-        return null;
665
-    }
666
-
667
-
668
-    /**
669
-     * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to
670
-     * retrieve it
671
-     *
672
-     * @param EE_Billing_Attendee_Info_Form $billing_form
673
-     * @param EE_Payment_Method             $payment_method
674
-     * @return boolean
675
-     * @throws EE_Error
676
-     */
677
-    public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method)
678
-    {
679
-        if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
680
-            EE_Error::add_error(esc_html__('Cannot save billing info because there is none.', 'event_espresso'));
681
-            return false;
682
-        }
683
-        $billing_form->clean_sensitive_data();
684
-        return update_post_meta(
685
-            $this->ID(),
686
-            $this->get_billing_info_postmeta_name($payment_method),
687
-            $billing_form->input_values(true)
688
-        );
689
-    }
690
-
691
-
692
-    /**
693
-     * Return the link to the admin details for the object.
694
-     *
695
-     * @return string
696
-     * @throws EE_Error
697
-     * @throws InvalidArgumentException
698
-     * @throws InvalidDataTypeException
699
-     * @throws InvalidInterfaceException
700
-     * @throws ReflectionException
701
-     */
702
-    public function get_admin_details_link()
703
-    {
704
-        return $this->get_admin_edit_link();
705
-    }
706
-
707
-
708
-    /**
709
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
710
-     *
711
-     * @return string
712
-     * @throws EE_Error
713
-     * @throws InvalidArgumentException
714
-     * @throws ReflectionException
715
-     * @throws InvalidDataTypeException
716
-     * @throws InvalidInterfaceException
717
-     */
718
-    public function get_admin_edit_link()
719
-    {
720
-        EE_Registry::instance()->load_helper('URL');
721
-        return EEH_URL::add_query_args_and_nonce(
722
-            array(
723
-                'page'   => 'espresso_registrations',
724
-                'action' => 'edit_attendee',
725
-                'post'   => $this->ID(),
726
-            ),
727
-            admin_url('admin.php')
728
-        );
729
-    }
730
-
731
-
732
-    /**
733
-     * Returns the link to a settings page for the object.
734
-     *
735
-     * @return string
736
-     * @throws EE_Error
737
-     * @throws InvalidArgumentException
738
-     * @throws InvalidDataTypeException
739
-     * @throws InvalidInterfaceException
740
-     * @throws ReflectionException
741
-     */
742
-    public function get_admin_settings_link()
743
-    {
744
-        return $this->get_admin_edit_link();
745
-    }
746
-
747
-
748
-    /**
749
-     * Returns the link to the "overview" for the object (typically the "list table" view).
750
-     *
751
-     * @return string
752
-     * @throws EE_Error
753
-     * @throws InvalidArgumentException
754
-     * @throws ReflectionException
755
-     * @throws InvalidDataTypeException
756
-     * @throws InvalidInterfaceException
757
-     */
758
-    public function get_admin_overview_link()
759
-    {
760
-        EE_Registry::instance()->load_helper('URL');
761
-        return EEH_URL::add_query_args_and_nonce(
762
-            array(
763
-                'page'   => 'espresso_registrations',
764
-                'action' => 'contact_list',
765
-            ),
766
-            admin_url('admin.php')
767
-        );
768
-    }
27
+	/**
28
+	 * Sets some dynamic defaults
29
+	 *
30
+	 * @param array  $fieldValues
31
+	 * @param bool   $bydb
32
+	 * @param string $timezone
33
+	 * @param array  $date_formats
34
+	 * @throws EE_Error
35
+	 */
36
+	protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array())
37
+	{
38
+		if (! isset($fieldValues['ATT_full_name'])) {
39
+			$fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : '';
40
+			$lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : '';
41
+			$fieldValues['ATT_full_name'] = $fname . $lname;
42
+		}
43
+		if (! isset($fieldValues['ATT_slug'])) {
44
+			// $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20));
45
+			$fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']);
46
+		}
47
+		if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
48
+			$fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50);
49
+		}
50
+		parent::__construct($fieldValues, $bydb, $timezone, $date_formats);
51
+	}
52
+
53
+
54
+	/**
55
+	 * @param array  $props_n_values          incoming values
56
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
57
+	 *                                        used.)
58
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
59
+	 *                                        date_format and the second value is the time format
60
+	 * @return EE_Attendee
61
+	 * @throws EE_Error
62
+	 */
63
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
64
+	{
65
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
66
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
67
+	}
68
+
69
+
70
+	/**
71
+	 * @param array  $props_n_values  incoming values from the database
72
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
73
+	 *                                the website will be used.
74
+	 * @return EE_Attendee
75
+	 */
76
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
77
+	{
78
+		return new self($props_n_values, true, $timezone);
79
+	}
80
+
81
+
82
+	/**
83
+	 *        Set Attendee First Name
84
+	 *
85
+	 * @access        public
86
+	 * @param string $fname
87
+	 * @throws EE_Error
88
+	 */
89
+	public function set_fname($fname = '')
90
+	{
91
+		$this->set('ATT_fname', $fname);
92
+	}
93
+
94
+
95
+	/**
96
+	 *        Set Attendee Last Name
97
+	 *
98
+	 * @access        public
99
+	 * @param string $lname
100
+	 * @throws EE_Error
101
+	 */
102
+	public function set_lname($lname = '')
103
+	{
104
+		$this->set('ATT_lname', $lname);
105
+	}
106
+
107
+
108
+	/**
109
+	 *        Set Attendee Address
110
+	 *
111
+	 * @access        public
112
+	 * @param string $address
113
+	 * @throws EE_Error
114
+	 */
115
+	public function set_address($address = '')
116
+	{
117
+		$this->set('ATT_address', $address);
118
+	}
119
+
120
+
121
+	/**
122
+	 *        Set Attendee Address2
123
+	 *
124
+	 * @access        public
125
+	 * @param        string $address2
126
+	 * @throws EE_Error
127
+	 */
128
+	public function set_address2($address2 = '')
129
+	{
130
+		$this->set('ATT_address2', $address2);
131
+	}
132
+
133
+
134
+	/**
135
+	 *        Set Attendee City
136
+	 *
137
+	 * @access        public
138
+	 * @param        string $city
139
+	 * @throws EE_Error
140
+	 */
141
+	public function set_city($city = '')
142
+	{
143
+		$this->set('ATT_city', $city);
144
+	}
145
+
146
+
147
+	/**
148
+	 *        Set Attendee State ID
149
+	 *
150
+	 * @access        public
151
+	 * @param        int $STA_ID
152
+	 * @throws EE_Error
153
+	 */
154
+	public function set_state($STA_ID = 0)
155
+	{
156
+		$this->set('STA_ID', $STA_ID);
157
+	}
158
+
159
+
160
+	/**
161
+	 *        Set Attendee Country ISO Code
162
+	 *
163
+	 * @access        public
164
+	 * @param        string $CNT_ISO
165
+	 * @throws EE_Error
166
+	 */
167
+	public function set_country($CNT_ISO = '')
168
+	{
169
+		$this->set('CNT_ISO', $CNT_ISO);
170
+	}
171
+
172
+
173
+	/**
174
+	 *        Set Attendee Zip/Postal Code
175
+	 *
176
+	 * @access        public
177
+	 * @param        string $zip
178
+	 * @throws EE_Error
179
+	 */
180
+	public function set_zip($zip = '')
181
+	{
182
+		$this->set('ATT_zip', $zip);
183
+	}
184
+
185
+
186
+	/**
187
+	 *        Set Attendee Email Address
188
+	 *
189
+	 * @access        public
190
+	 * @param        string $email
191
+	 * @throws EE_Error
192
+	 */
193
+	public function set_email($email = '')
194
+	{
195
+		$this->set('ATT_email', $email);
196
+	}
197
+
198
+
199
+	/**
200
+	 *        Set Attendee Phone
201
+	 *
202
+	 * @access        public
203
+	 * @param        string $phone
204
+	 * @throws EE_Error
205
+	 */
206
+	public function set_phone($phone = '')
207
+	{
208
+		$this->set('ATT_phone', $phone);
209
+	}
210
+
211
+
212
+	/**
213
+	 *        set deleted
214
+	 *
215
+	 * @access        public
216
+	 * @param        bool $ATT_deleted
217
+	 * @throws EE_Error
218
+	 */
219
+	public function set_deleted($ATT_deleted = false)
220
+	{
221
+		$this->set('ATT_deleted', $ATT_deleted);
222
+	}
223
+
224
+
225
+	/**
226
+	 * Returns the value for the post_author id saved with the cpt
227
+	 *
228
+	 * @since 4.5.0
229
+	 * @return int
230
+	 * @throws EE_Error
231
+	 */
232
+	public function wp_user()
233
+	{
234
+		return $this->get('ATT_author');
235
+	}
236
+
237
+
238
+	/**
239
+	 *        get Attendee First Name
240
+	 *
241
+	 * @access        public
242
+	 * @return string
243
+	 * @throws EE_Error
244
+	 */
245
+	public function fname()
246
+	{
247
+		return $this->get('ATT_fname');
248
+	}
249
+
250
+
251
+	/**
252
+	 * echoes out the attendee's first name
253
+	 *
254
+	 * @return void
255
+	 * @throws EE_Error
256
+	 */
257
+	public function e_full_name()
258
+	{
259
+		echo esc_html($this->full_name());
260
+	}
261
+
262
+
263
+	/**
264
+	 * Returns the first and last name concatenated together with a space.
265
+	 *
266
+	 * @param bool $apply_html_entities
267
+	 * @return string
268
+	 * @throws EE_Error
269
+	 */
270
+	public function full_name($apply_html_entities = false)
271
+	{
272
+		$full_name = array(
273
+			$this->fname(),
274
+			$this->lname(),
275
+		);
276
+		$full_name = array_filter($full_name);
277
+		$full_name = implode(' ', $full_name);
278
+		return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name;
279
+	}
280
+
281
+
282
+	/**
283
+	 * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless
284
+	 * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this
285
+	 * attendee.
286
+	 *
287
+	 * @param bool $apply_html_entities
288
+	 * @return string
289
+	 * @throws EE_Error
290
+	 */
291
+	public function ATT_full_name($apply_html_entities = false)
292
+	{
293
+		return $apply_html_entities
294
+			? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8')
295
+			: $this->get('ATT_full_name');
296
+	}
297
+
298
+
299
+	/**
300
+	 *        get Attendee Last Name
301
+	 *
302
+	 * @access        public
303
+	 * @return string
304
+	 * @throws EE_Error
305
+	 */
306
+	public function lname()
307
+	{
308
+		return $this->get('ATT_lname');
309
+	}
310
+
311
+
312
+	/**
313
+	 * Gets the attendee's full address as an array so client code can decide hwo to display it
314
+	 *
315
+	 * @return array numerically indexed, with each part of the address that is known.
316
+	 * Eg, if the user only responded to state and country,
317
+	 * it would be array(0=>'Alabama',1=>'USA')
318
+	 * @return array
319
+	 * @throws EE_Error
320
+	 */
321
+	public function full_address_as_array()
322
+	{
323
+		$full_address_array = array();
324
+		$initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',);
325
+		foreach ($initial_address_fields as $address_field_name) {
326
+			$address_fields_value = $this->get($address_field_name);
327
+			if (! empty($address_fields_value)) {
328
+				$full_address_array[] = $address_fields_value;
329
+			}
330
+		}
331
+		// now handle state and country
332
+		$state_obj = $this->state_obj();
333
+		if ($state_obj instanceof EE_State) {
334
+			$full_address_array[] = $state_obj->name();
335
+		}
336
+		$country_obj = $this->country_obj();
337
+		if ($country_obj instanceof EE_Country) {
338
+			$full_address_array[] = $country_obj->name();
339
+		}
340
+		// lastly get the xip
341
+		$zip_value = $this->zip();
342
+		if (! empty($zip_value)) {
343
+			$full_address_array[] = $zip_value;
344
+		}
345
+		return $full_address_array;
346
+	}
347
+
348
+
349
+	/**
350
+	 *        get Attendee Address
351
+	 *
352
+	 * @return string
353
+	 * @throws EE_Error
354
+	 */
355
+	public function address()
356
+	{
357
+		return $this->get('ATT_address');
358
+	}
359
+
360
+
361
+	/**
362
+	 *        get Attendee Address2
363
+	 *
364
+	 * @return string
365
+	 * @throws EE_Error
366
+	 */
367
+	public function address2()
368
+	{
369
+		return $this->get('ATT_address2');
370
+	}
371
+
372
+
373
+	/**
374
+	 *        get Attendee City
375
+	 *
376
+	 * @return string
377
+	 * @throws EE_Error
378
+	 */
379
+	public function city()
380
+	{
381
+		return $this->get('ATT_city');
382
+	}
383
+
384
+
385
+	/**
386
+	 *        get Attendee State ID
387
+	 *
388
+	 * @return string
389
+	 * @throws EE_Error
390
+	 */
391
+	public function state_ID()
392
+	{
393
+		return $this->get('STA_ID');
394
+	}
395
+
396
+
397
+	/**
398
+	 * @return string
399
+	 * @throws EE_Error
400
+	 */
401
+	public function state_abbrev()
402
+	{
403
+		return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : '';
404
+	}
405
+
406
+
407
+	/**
408
+	 * Gets the state set to this attendee
409
+	 *
410
+	 * @return EE_State
411
+	 * @throws EE_Error
412
+	 */
413
+	public function state_obj()
414
+	{
415
+		return $this->get_first_related('State');
416
+	}
417
+
418
+
419
+	/**
420
+	 * Returns the state's name, otherwise 'Unknown'
421
+	 *
422
+	 * @return string
423
+	 * @throws EE_Error
424
+	 */
425
+	public function state_name()
426
+	{
427
+		if ($this->state_obj()) {
428
+			return $this->state_obj()->name();
429
+		} else {
430
+			return '';
431
+		}
432
+	}
433
+
434
+
435
+	/**
436
+	 * either displays the state abbreviation or the state name, as determined
437
+	 * by the "FHEE__EEI_Address__state__use_abbreviation" filter.
438
+	 * defaults to abbreviation
439
+	 *
440
+	 * @return string
441
+	 * @throws EE_Error
442
+	 */
443
+	public function state()
444
+	{
445
+		if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) {
446
+			return $this->state_abbrev();
447
+		}
448
+		return $this->state_name();
449
+	}
450
+
451
+
452
+	/**
453
+	 *    get Attendee Country ISO Code
454
+	 *
455
+	 * @return string
456
+	 * @throws EE_Error
457
+	 */
458
+	public function country_ID()
459
+	{
460
+		return $this->get('CNT_ISO');
461
+	}
462
+
463
+
464
+	/**
465
+	 * Gets country set for this attendee
466
+	 *
467
+	 * @return EE_Country
468
+	 * @throws EE_Error
469
+	 */
470
+	public function country_obj()
471
+	{
472
+		return $this->get_first_related('Country');
473
+	}
474
+
475
+
476
+	/**
477
+	 * Returns the country's name if known, otherwise 'Unknown'
478
+	 *
479
+	 * @return string
480
+	 * @throws EE_Error
481
+	 */
482
+	public function country_name()
483
+	{
484
+		if ($this->country_obj()) {
485
+			return $this->country_obj()->name();
486
+		}
487
+		return '';
488
+	}
489
+
490
+
491
+	/**
492
+	 * either displays the country ISO2 code or the country name, as determined
493
+	 * by the "FHEE__EEI_Address__country__use_abbreviation" filter.
494
+	 * defaults to abbreviation
495
+	 *
496
+	 * @return string
497
+	 * @throws EE_Error
498
+	 */
499
+	public function country()
500
+	{
501
+		if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) {
502
+			return $this->country_ID();
503
+		}
504
+		return $this->country_name();
505
+	}
506
+
507
+
508
+	/**
509
+	 *        get Attendee Zip/Postal Code
510
+	 *
511
+	 * @return string
512
+	 * @throws EE_Error
513
+	 */
514
+	public function zip()
515
+	{
516
+		return $this->get('ATT_zip');
517
+	}
518
+
519
+
520
+	/**
521
+	 *        get Attendee Email Address
522
+	 *
523
+	 * @return string
524
+	 * @throws EE_Error
525
+	 */
526
+	public function email()
527
+	{
528
+		return $this->get('ATT_email');
529
+	}
530
+
531
+
532
+	/**
533
+	 *        get Attendee Phone #
534
+	 *
535
+	 * @return string
536
+	 * @throws EE_Error
537
+	 */
538
+	public function phone()
539
+	{
540
+		return $this->get('ATT_phone');
541
+	}
542
+
543
+
544
+	/**
545
+	 *    get deleted
546
+	 *
547
+	 * @return        bool
548
+	 * @throws EE_Error
549
+	 */
550
+	public function deleted()
551
+	{
552
+		return $this->get('ATT_deleted');
553
+	}
554
+
555
+
556
+	/**
557
+	 * Gets registrations of this attendee
558
+	 *
559
+	 * @param array $query_params
560
+	 * @return EE_Registration[]
561
+	 * @throws EE_Error
562
+	 */
563
+	public function get_registrations($query_params = array())
564
+	{
565
+		return $this->get_many_related('Registration', $query_params);
566
+	}
567
+
568
+
569
+	/**
570
+	 * Gets the most recent registration of this attendee
571
+	 *
572
+	 * @return EE_Registration
573
+	 * @throws EE_Error
574
+	 */
575
+	public function get_most_recent_registration()
576
+	{
577
+		return $this->get_first_related(
578
+			'Registration',
579
+			array('order_by' => array('REG_date' => 'DESC'))
580
+		); // null, 'REG_date', 'DESC', '=', 'OBJECT_K');
581
+	}
582
+
583
+
584
+	/**
585
+	 * Gets the most recent registration for this attend at this event
586
+	 *
587
+	 * @param int $event_id
588
+	 * @return EE_Registration
589
+	 * @throws EE_Error
590
+	 */
591
+	public function get_most_recent_registration_for_event($event_id)
592
+	{
593
+		return $this->get_first_related(
594
+			'Registration',
595
+			array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC'))
596
+		);
597
+	}
598
+
599
+
600
+	/**
601
+	 * returns any events attached to this attendee ($_Event property);
602
+	 *
603
+	 * @return array
604
+	 * @throws EE_Error
605
+	 */
606
+	public function events()
607
+	{
608
+		return $this->get_many_related('Event');
609
+	}
610
+
611
+
612
+	/**
613
+	 * Gets the billing info array where keys match espresso_reg_page_billing_inputs(),
614
+	 * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was
615
+	 * used to save the billing info
616
+	 *
617
+	 * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class
618
+	 * @return EE_Form_Section_Proper|null
619
+	 * @throws EE_Error
620
+	 */
621
+	public function billing_info_for_payment_method($payment_method)
622
+	{
623
+		$pm_type = $payment_method->type_obj();
624
+		if (! $pm_type instanceof EE_PMT_Base) {
625
+			return null;
626
+		}
627
+		$billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true);
628
+		if (! $billing_info) {
629
+			return null;
630
+		}
631
+		$billing_form = $pm_type->billing_form();
632
+		// double-check the form isn't totally hidden, in which case pretend there is no form
633
+		$form_totally_hidden = true;
634
+		foreach ($billing_form->inputs_in_subsections() as $input) {
635
+			if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
636
+				$form_totally_hidden = false;
637
+				break;
638
+			}
639
+		}
640
+		if ($form_totally_hidden) {
641
+			return null;
642
+		}
643
+		if ($billing_form instanceof EE_Form_Section_Proper) {
644
+			$billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false);
645
+		}
646
+
647
+		return $billing_form;
648
+	}
649
+
650
+
651
+	/**
652
+	 * Gets the postmeta key that holds this attendee's billing info for the
653
+	 * specified payment method
654
+	 *
655
+	 * @param EE_Payment_Method $payment_method
656
+	 * @return string
657
+	 * @throws EE_Error
658
+	 */
659
+	public function get_billing_info_postmeta_name($payment_method)
660
+	{
661
+		if ($payment_method->type_obj() instanceof EE_PMT_Base) {
662
+			return 'billing_info_' . $payment_method->type_obj()->system_name();
663
+		}
664
+		return null;
665
+	}
666
+
667
+
668
+	/**
669
+	 * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to
670
+	 * retrieve it
671
+	 *
672
+	 * @param EE_Billing_Attendee_Info_Form $billing_form
673
+	 * @param EE_Payment_Method             $payment_method
674
+	 * @return boolean
675
+	 * @throws EE_Error
676
+	 */
677
+	public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method)
678
+	{
679
+		if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
680
+			EE_Error::add_error(esc_html__('Cannot save billing info because there is none.', 'event_espresso'));
681
+			return false;
682
+		}
683
+		$billing_form->clean_sensitive_data();
684
+		return update_post_meta(
685
+			$this->ID(),
686
+			$this->get_billing_info_postmeta_name($payment_method),
687
+			$billing_form->input_values(true)
688
+		);
689
+	}
690
+
691
+
692
+	/**
693
+	 * Return the link to the admin details for the object.
694
+	 *
695
+	 * @return string
696
+	 * @throws EE_Error
697
+	 * @throws InvalidArgumentException
698
+	 * @throws InvalidDataTypeException
699
+	 * @throws InvalidInterfaceException
700
+	 * @throws ReflectionException
701
+	 */
702
+	public function get_admin_details_link()
703
+	{
704
+		return $this->get_admin_edit_link();
705
+	}
706
+
707
+
708
+	/**
709
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
710
+	 *
711
+	 * @return string
712
+	 * @throws EE_Error
713
+	 * @throws InvalidArgumentException
714
+	 * @throws ReflectionException
715
+	 * @throws InvalidDataTypeException
716
+	 * @throws InvalidInterfaceException
717
+	 */
718
+	public function get_admin_edit_link()
719
+	{
720
+		EE_Registry::instance()->load_helper('URL');
721
+		return EEH_URL::add_query_args_and_nonce(
722
+			array(
723
+				'page'   => 'espresso_registrations',
724
+				'action' => 'edit_attendee',
725
+				'post'   => $this->ID(),
726
+			),
727
+			admin_url('admin.php')
728
+		);
729
+	}
730
+
731
+
732
+	/**
733
+	 * Returns the link to a settings page for the object.
734
+	 *
735
+	 * @return string
736
+	 * @throws EE_Error
737
+	 * @throws InvalidArgumentException
738
+	 * @throws InvalidDataTypeException
739
+	 * @throws InvalidInterfaceException
740
+	 * @throws ReflectionException
741
+	 */
742
+	public function get_admin_settings_link()
743
+	{
744
+		return $this->get_admin_edit_link();
745
+	}
746
+
747
+
748
+	/**
749
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
750
+	 *
751
+	 * @return string
752
+	 * @throws EE_Error
753
+	 * @throws InvalidArgumentException
754
+	 * @throws ReflectionException
755
+	 * @throws InvalidDataTypeException
756
+	 * @throws InvalidInterfaceException
757
+	 */
758
+	public function get_admin_overview_link()
759
+	{
760
+		EE_Registry::instance()->load_helper('URL');
761
+		return EEH_URL::add_query_args_and_nonce(
762
+			array(
763
+				'page'   => 'espresso_registrations',
764
+				'action' => 'contact_list',
765
+			),
766
+			admin_url('admin.php')
767
+		);
768
+	}
769 769
 }
Please login to merge, or discard this patch.
core/EE_Payment_Processor.core.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
     public static function instance()
34 34
     {
35 35
         // check if class object is instantiated
36
-        if (! self::$_instance instanceof EE_Payment_Processor) {
36
+        if ( ! self::$_instance instanceof EE_Payment_Processor) {
37 37
             self::$_instance = new self();
38 38
         }
39 39
         return self::$_instance;
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
         /** @type \EE_Transaction $transaction */
171 171
         $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
172 172
         $primary_reg = $transaction->primary_registration();
173
-        if (! $primary_reg instanceof EE_Registration) {
173
+        if ( ! $primary_reg instanceof EE_Registration) {
174 174
             throw new EE_Error(
175 175
                 sprintf(
176 176
                     esc_html__(
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
                         EEM_Change_Log::instance()->log(
266 266
                             EEM_Change_Log::type_gateway,
267 267
                             array(
268
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
268
+                                'message'     => 'IPN Exception: '.$e->getMessage(),
269 269
                                 'current_url' => EEH_URL::current_url(),
270 270
                                 'payment'     => $e->getPaymentProperties(),
271 271
                                 'IPN_data'    => $e->getIpnData(),
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
                         EEM_Change_Log::instance()->log(
310 310
                             EEM_Change_Log::type_gateway,
311 311
                             array(
312
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
312
+                                'message'     => 'IPN Exception: '.$e->getMessage(),
313 313
                                 'current_url' => EEH_URL::current_url(),
314 314
                                 'payment'     => $e->getPaymentProperties(),
315 315
                                 'IPN_data'    => $e->getIpnData(),
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
     {
381 381
         $return_data = array();
382 382
         foreach ($request_data as $key => $value) {
383
-            $return_data[ $this->_remove_unusable_characters($key) ] = $this->_remove_unusable_characters(
383
+            $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters(
384 384
                 $value
385 385
             );
386 386
         }
Please login to merge, or discard this patch.
Indentation   +842 added lines, -842 removed lines patch added patch discarded remove patch
@@ -17,846 +17,846 @@
 block discarded – undo
17 17
  */
18 18
 class EE_Payment_Processor extends EE_Processor_Base implements ResettableInterface
19 19
 {
20
-    /**
21
-     * @var EE_Payment_Processor $_instance
22
-     * @access    private
23
-     */
24
-    private static $_instance;
25
-
26
-
27
-    /**
28
-     * @singleton method used to instantiate class object
29
-     * @access    public
30
-     * @return EE_Payment_Processor instance
31
-     */
32
-    public static function instance()
33
-    {
34
-        // check if class object is instantiated
35
-        if (! self::$_instance instanceof EE_Payment_Processor) {
36
-            self::$_instance = new self();
37
-        }
38
-        return self::$_instance;
39
-    }
40
-
41
-
42
-    /**
43
-     * @return EE_Payment_Processor
44
-     */
45
-    public static function reset()
46
-    {
47
-        self::$_instance = null;
48
-        return self::instance();
49
-    }
50
-
51
-
52
-    /**
53
-     *private constructor to prevent direct creation
54
-     *
55
-     * @Constructor
56
-     * @access private
57
-     */
58
-    private function __construct()
59
-    {
60
-        do_action('AHEE__EE_Payment_Processor__construct');
61
-        add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3);
62
-    }
63
-
64
-
65
-    /**
66
-     * Using the selected gateway, processes the payment for that transaction, and updates the transaction
67
-     * appropriately. Saves the payment that is generated
68
-     *
69
-     * @param EE_Payment_Method    $payment_method
70
-     * @param EE_Transaction       $transaction
71
-     * @param float                $amount       if only part of the transaction is to be paid for, how much.
72
-     *                                           Leave null if payment is for the full amount owing
73
-     * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method).
74
-     *                                           Receive_form_submission() should have
75
-     *                                           already been called on the billing form
76
-     *                                           (ie, its inputs should have their normalized values set).
77
-     * @param string               $return_url   string used mostly by offsite gateways to specify
78
-     *                                           where to go AFTER the offsite gateway
79
-     * @param string               $method       like 'CART', indicates who the client who called this was
80
-     * @param bool                 $by_admin     TRUE if payment is being attempted from the admin
81
-     * @param boolean              $update_txn   whether or not to call
82
-     *                                           EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
83
-     * @param string               $cancel_url   URL to return to if off-site payments are cancelled
84
-     * @return EE_Payment
85
-     * @throws EE_Error
86
-     * @throws InvalidArgumentException
87
-     * @throws ReflectionException
88
-     * @throws RuntimeException
89
-     * @throws InvalidDataTypeException
90
-     * @throws InvalidInterfaceException
91
-     */
92
-    public function process_payment(
93
-        EE_Payment_Method $payment_method,
94
-        EE_Transaction $transaction,
95
-        $amount = null,
96
-        $billing_form = null,
97
-        $return_url = null,
98
-        $method = 'CART',
99
-        $by_admin = false,
100
-        $update_txn = true,
101
-        $cancel_url = ''
102
-    ) {
103
-        if ((float) $amount < 0) {
104
-            throw new EE_Error(
105
-                sprintf(
106
-                    esc_html__(
107
-                        'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund',
108
-                        'event_espresso'
109
-                    ),
110
-                    $amount,
111
-                    $transaction->ID()
112
-                )
113
-            );
114
-        }
115
-        // verify payment method
116
-        $payment_method = EEM_Payment_Method::instance()->ensure_is_obj(
117
-            $payment_method,
118
-            true
119
-        );
120
-        // verify transaction
121
-        EEM_Transaction::instance()->ensure_is_obj($transaction);
122
-        $transaction->set_payment_method_ID($payment_method->ID());
123
-        // verify payment method type
124
-        if ($payment_method->type_obj() instanceof EE_PMT_Base) {
125
-            $payment = $payment_method->type_obj()->process_payment(
126
-                $transaction,
127
-                min($amount, $transaction->remaining()), // make sure we don't overcharge
128
-                $billing_form,
129
-                $return_url,
130
-                add_query_arg(array('ee_cancel_payment' => true), $cancel_url),
131
-                $method,
132
-                $by_admin
133
-            );
134
-            // check if payment method uses an off-site gateway
135
-            if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) {
136
-                // don't process payments for off-site gateways yet because no payment has occurred yet
137
-                $this->update_txn_based_on_payment($transaction, $payment, $update_txn);
138
-            }
139
-            return $payment;
140
-        }
141
-        EE_Error::add_error(
142
-            sprintf(
143
-                esc_html__(
144
-                    'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
145
-                    'event_espresso'
146
-                ),
147
-                '<br/>',
148
-                EE_Registry::instance()->CFG->organization->get_pretty('email')
149
-            ),
150
-            __FILE__,
151
-            __FUNCTION__,
152
-            __LINE__
153
-        );
154
-        return null;
155
-    }
156
-
157
-
158
-    /**
159
-     * @param EE_Transaction|int $transaction
160
-     * @param EE_Payment_Method  $payment_method
161
-     * @return string
162
-     * @throws EE_Error
163
-     * @throws InvalidArgumentException
164
-     * @throws InvalidDataTypeException
165
-     * @throws InvalidInterfaceException
166
-     */
167
-    public function get_ipn_url_for_payment_method($transaction, $payment_method)
168
-    {
169
-        /** @type \EE_Transaction $transaction */
170
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
171
-        $primary_reg = $transaction->primary_registration();
172
-        if (! $primary_reg instanceof EE_Registration) {
173
-            throw new EE_Error(
174
-                sprintf(
175
-                    esc_html__(
176
-                        'Cannot get IPN URL for transaction with ID %d because it has no primary registration',
177
-                        'event_espresso'
178
-                    ),
179
-                    $transaction->ID()
180
-                )
181
-            );
182
-        }
183
-        $payment_method = EEM_Payment_Method::instance()->ensure_is_obj(
184
-            $payment_method,
185
-            true
186
-        );
187
-        $url = add_query_arg(
188
-            array(
189
-                'e_reg_url_link'    => $primary_reg->reg_url_link(),
190
-                'ee_payment_method' => $payment_method->slug(),
191
-            ),
192
-            EE_Registry::instance()->CFG->core->txn_page_url()
193
-        );
194
-        return $url;
195
-    }
196
-
197
-
198
-    /**
199
-     * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so
200
-     * we can easily find what registration the IPN is for and what payment method.
201
-     * However, if not, we'll give all payment methods a chance to claim it and process it.
202
-     * If a payment is found for the IPN info, it is saved.
203
-     *
204
-     * @param array              $_req_data            form post data
205
-     * @param EE_Transaction|int $transaction          optional (or a transactions id)
206
-     * @param EE_Payment_Method  $payment_method       (or a slug or id of one)
207
-     * @param boolean            $update_txn           whether or not to call
208
-     *                                                 EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
209
-     * @param bool               $separate_IPN_request whether the IPN uses a separate request (true, like PayPal)
210
-     *                                                 or is processed manually (false, like Authorize.net)
211
-     * @throws EE_Error
212
-     * @throws Exception
213
-     * @return EE_Payment
214
-     * @throws \RuntimeException
215
-     * @throws \ReflectionException
216
-     * @throws \InvalidArgumentException
217
-     * @throws InvalidInterfaceException
218
-     * @throws InvalidDataTypeException
219
-     */
220
-    public function process_ipn(
221
-        $_req_data,
222
-        $transaction = null,
223
-        $payment_method = null,
224
-        $update_txn = true,
225
-        $separate_IPN_request = true
226
-    ) {
227
-        EE_Registry::instance()->load_model('Change_Log');
228
-        $_req_data = $this->_remove_unusable_characters_from_array((array) $_req_data);
229
-        EE_Processor_Base::set_IPN($separate_IPN_request);
230
-        $obj_for_log = null;
231
-        if ($transaction instanceof EE_Transaction) {
232
-            $obj_for_log = $transaction;
233
-            if ($payment_method instanceof EE_Payment_Method) {
234
-                $obj_for_log = EEM_Payment::instance()->get_one(
235
-                    array(
236
-                        array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()),
237
-                        'order_by' => array('PAY_timestamp' => 'desc'),
238
-                    )
239
-                );
240
-            }
241
-        } elseif ($payment_method instanceof EE_Payment) {
242
-            $obj_for_log = $payment_method;
243
-        }
244
-        $log = EEM_Change_Log::instance()->log(
245
-            EEM_Change_Log::type_gateway,
246
-            array('IPN data received' => $_req_data),
247
-            $obj_for_log
248
-        );
249
-        try {
250
-            /**
251
-             * @var EE_Payment $payment
252
-             */
253
-            $payment = null;
254
-            if ($transaction && $payment_method) {
255
-                /** @type EE_Transaction $transaction */
256
-                $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
257
-                /** @type EE_Payment_Method $payment_method */
258
-                $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method);
259
-                if ($payment_method->type_obj() instanceof EE_PMT_Base) {
260
-                    try {
261
-                        $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction);
262
-                        $log->set_object($payment);
263
-                    } catch (EventEspresso\core\exceptions\IpnException $e) {
264
-                        EEM_Change_Log::instance()->log(
265
-                            EEM_Change_Log::type_gateway,
266
-                            array(
267
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
268
-                                'current_url' => EEH_URL::current_url(),
269
-                                'payment'     => $e->getPaymentProperties(),
270
-                                'IPN_data'    => $e->getIpnData(),
271
-                            ),
272
-                            $obj_for_log
273
-                        );
274
-                        return $e->getPayment();
275
-                    }
276
-                } else {
277
-                    // not a payment
278
-                    EE_Error::add_error(
279
-                        sprintf(
280
-                            esc_html__(
281
-                                'A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.',
282
-                                'event_espresso'
283
-                            ),
284
-                            '<br/>',
285
-                            EE_Registry::instance()->CFG->organization->get_pretty('email')
286
-                        ),
287
-                        __FILE__,
288
-                        __FUNCTION__,
289
-                        __LINE__
290
-                    );
291
-                }
292
-            } else {
293
-                // that's actually pretty ok. The IPN just wasn't able
294
-                // to identify which transaction or payment method this was for
295
-                // give all active payment methods a chance to claim it
296
-                $active_payment_methods = EEM_Payment_Method::instance()->get_all_active();
297
-                foreach ($active_payment_methods as $active_payment_method) {
298
-                    try {
299
-                        $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data);
300
-                        $payment_method = $active_payment_method;
301
-                        EEM_Change_Log::instance()->log(
302
-                            EEM_Change_Log::type_gateway,
303
-                            array('IPN data' => $_req_data),
304
-                            $payment
305
-                        );
306
-                        break;
307
-                    } catch (EventEspresso\core\exceptions\IpnException $e) {
308
-                        EEM_Change_Log::instance()->log(
309
-                            EEM_Change_Log::type_gateway,
310
-                            array(
311
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
312
-                                'current_url' => EEH_URL::current_url(),
313
-                                'payment'     => $e->getPaymentProperties(),
314
-                                'IPN_data'    => $e->getIpnData(),
315
-                            ),
316
-                            $obj_for_log
317
-                        );
318
-                        return $e->getPayment();
319
-                    } catch (EE_Error $e) {
320
-                        // that's fine- it apparently couldn't handle the IPN
321
-                    }
322
-                }
323
-            }
324
-            // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method);
325
-            if ($payment instanceof EE_Payment) {
326
-                $payment->save();
327
-                //  update the TXN
328
-                $this->update_txn_based_on_payment(
329
-                    $transaction,
330
-                    $payment,
331
-                    $update_txn,
332
-                    $separate_IPN_request
333
-                );
334
-            } else {
335
-                // we couldn't find the payment for this IPN... let's try and log at least SOMETHING
336
-                if ($payment_method) {
337
-                    EEM_Change_Log::instance()->log(
338
-                        EEM_Change_Log::type_gateway,
339
-                        array('IPN data' => $_req_data),
340
-                        $payment_method
341
-                    );
342
-                } elseif ($transaction) {
343
-                    EEM_Change_Log::instance()->log(
344
-                        EEM_Change_Log::type_gateway,
345
-                        array('IPN data' => $_req_data),
346
-                        $transaction
347
-                    );
348
-                }
349
-            }
350
-            return $payment;
351
-        } catch (EE_Error $e) {
352
-            do_action(
353
-                'AHEE__log',
354
-                __FILE__,
355
-                __FUNCTION__,
356
-                sprintf(
357
-                    esc_html__(
358
-                        'Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"',
359
-                        'event_espresso'
360
-                    ),
361
-                    print_r($transaction, true),
362
-                    print_r($_req_data, true),
363
-                    $e->getMessage()
364
-                )
365
-            );
366
-            throw $e;
367
-        }
368
-    }
369
-
370
-
371
-    /**
372
-     * Removes any non-printable illegal characters from the input,
373
-     * which might cause a raucous when trying to insert into the database
374
-     *
375
-     * @param  array $request_data
376
-     * @return array
377
-     */
378
-    protected function _remove_unusable_characters_from_array(array $request_data)
379
-    {
380
-        $return_data = array();
381
-        foreach ($request_data as $key => $value) {
382
-            $return_data[ $this->_remove_unusable_characters($key) ] = $this->_remove_unusable_characters(
383
-                $value
384
-            );
385
-        }
386
-        return $return_data;
387
-    }
388
-
389
-
390
-    /**
391
-     * Removes any non-printable illegal characters from the input,
392
-     * which might cause a raucous when trying to insert into the database
393
-     *
394
-     * @param string $request_data
395
-     * @return string
396
-     */
397
-    protected function _remove_unusable_characters($request_data)
398
-    {
399
-        return preg_replace('/[^[:print:]]/', '', $request_data);
400
-    }
401
-
402
-
403
-    /**
404
-     * Should be called just before displaying the payment attempt results to the user,
405
-     * when the payment attempt has finished. Some payment methods may have special
406
-     * logic to perform here. For example, if process_payment() happens on a special request
407
-     * and then the user is redirected to a page that displays the payment's status, this
408
-     * should be called while loading the page that displays the payment's status. If the user is
409
-     * sent to an offsite payment provider, this should be called upon returning from that offsite payment
410
-     * provider.
411
-     *
412
-     * @param EE_Transaction|int $transaction
413
-     * @param bool               $update_txn whether or not to call
414
-     *                                       EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
415
-     * @return EE_Payment
416
-     * @throws EE_Error
417
-     * @throws InvalidArgumentException
418
-     * @throws ReflectionException
419
-     * @throws RuntimeException
420
-     * @throws InvalidDataTypeException
421
-     * @throws InvalidInterfaceException
422
-     * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO,
423
-     *                                       to call handle_ipn() for offsite gateways that don't receive separate IPNs
424
-     */
425
-    public function finalize_payment_for($transaction, $update_txn = true)
426
-    {
427
-        /** @var $transaction EE_Transaction */
428
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
429
-        $last_payment_method = $transaction->payment_method();
430
-        if ($last_payment_method instanceof EE_Payment_Method) {
431
-            $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction);
432
-            $this->update_txn_based_on_payment($transaction, $payment, $update_txn);
433
-            return $payment;
434
-        }
435
-        return null;
436
-    }
437
-
438
-
439
-    /**
440
-     * Processes a direct refund request, saves the payment, and updates the transaction appropriately.
441
-     *
442
-     * @param EE_Payment_Method $payment_method
443
-     * @param EE_Payment        $payment_to_refund
444
-     * @param array             $refund_info
445
-     * @return EE_Payment
446
-     * @throws EE_Error
447
-     * @throws InvalidArgumentException
448
-     * @throws ReflectionException
449
-     * @throws RuntimeException
450
-     * @throws InvalidDataTypeException
451
-     * @throws InvalidInterfaceException
452
-     */
453
-    public function process_refund(
454
-        EE_Payment_Method $payment_method,
455
-        EE_Payment $payment_to_refund,
456
-        array $refund_info = array()
457
-    ) {
458
-        if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) {
459
-            $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info);
460
-            $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund);
461
-        }
462
-        return $payment_to_refund;
463
-    }
464
-
465
-
466
-    /**
467
-     * This should be called each time there may have been an update to a
468
-     * payment on a transaction (ie, we asked for a payment to process a
469
-     * payment for a transaction, or we told a payment method about an IPN, or
470
-     * we told a payment method to
471
-     * "finalize_payment_for" (a transaction), or we told a payment method to
472
-     * process a refund. This should handle firing the correct hooks to
473
-     * indicate
474
-     * what exactly happened and updating the transaction appropriately). This
475
-     * could be integrated directly into EE_Transaction upon save, but we want
476
-     * this logic to be separate from 'normal' plain-jane saving and updating
477
-     * of transactions and payments, and to be tied to payment processing.
478
-     * Note: this method DOES NOT save the payment passed into it. It is the responsibility
479
-     * of previous code to decide whether or not to save (because the payment passed into
480
-     * this method might be a temporary, never-to-be-saved payment from an offline gateway,
481
-     * in which case we only want that payment object for some temporary usage during this request,
482
-     * but we don't want it to be saved).
483
-     *
484
-     * @param EE_Transaction|int $transaction
485
-     * @param EE_Payment         $payment
486
-     * @param boolean            $update_txn
487
-     *                        whether or not to call
488
-     *                        EE_Transaction_Processor::
489
-     *                        update_transaction_and_registrations_after_checkout_or_payment()
490
-     *                        (you can save 1 DB query if you know you're going
491
-     *                        to save it later instead)
492
-     * @param bool               $IPN
493
-     *                        if processing IPNs or other similar payment
494
-     *                        related activities that occur in alternate
495
-     *                        requests than the main one that is processing the
496
-     *                        TXN, then set this to true to check whether the
497
-     *                        TXN is locked before updating
498
-     * @throws EE_Error
499
-     * @throws InvalidArgumentException
500
-     * @throws ReflectionException
501
-     * @throws RuntimeException
502
-     * @throws InvalidDataTypeException
503
-     * @throws InvalidInterfaceException
504
-     */
505
-    public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false)
506
-    {
507
-        $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful';
508
-        /** @type EE_Transaction $transaction */
509
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
510
-        // can we freely update the TXN at this moment?
511
-        if ($IPN && $transaction->is_locked()) {
512
-            // don't update the transaction at this exact moment
513
-            // because the TXN is active in another request
514
-            EE_Cron_Tasks::schedule_update_transaction_with_payment(
515
-                time(),
516
-                $transaction->ID(),
517
-                $payment->ID()
518
-            );
519
-        } else {
520
-            // verify payment and that it has been saved
521
-            if ($payment instanceof EE_Payment && $payment->ID()) {
522
-                if (
523
-                    $payment->payment_method() instanceof EE_Payment_Method
524
-                    && $payment->payment_method()->type_obj() instanceof EE_PMT_Base
525
-                ) {
526
-                    $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment);
527
-                    // update TXN registrations with payment info
528
-                    $this->process_registration_payments($transaction, $payment);
529
-                }
530
-                $do_action = $payment->just_approved()
531
-                    ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful'
532
-                    : $do_action;
533
-            } else {
534
-                // send out notifications
535
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
536
-                $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made';
537
-            }
538
-            if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) {
539
-                /** @type EE_Transaction_Payments $transaction_payments */
540
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
541
-                // set new value for total paid
542
-                $transaction_payments->calculate_total_payments_and_update_status($transaction);
543
-                // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ???
544
-                if ($update_txn) {
545
-                    $this->_post_payment_processing($transaction, $payment, $IPN);
546
-                }
547
-            }
548
-            // granular hook for others to use.
549
-            do_action($do_action, $transaction, $payment);
550
-            do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action');
551
-            // global hook for others to use.
552
-            do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment);
553
-        }
554
-    }
555
-
556
-
557
-    /**
558
-     * update registrations REG_paid field after successful payment and link registrations with payment
559
-     *
560
-     * @param EE_Transaction    $transaction
561
-     * @param EE_Payment        $payment
562
-     * @param EE_Registration[] $registrations
563
-     * @throws EE_Error
564
-     * @throws InvalidArgumentException
565
-     * @throws RuntimeException
566
-     * @throws InvalidDataTypeException
567
-     * @throws InvalidInterfaceException
568
-     */
569
-    public function process_registration_payments(
570
-        EE_Transaction $transaction,
571
-        EE_Payment $payment,
572
-        array $registrations = array()
573
-    ) {
574
-        // only process if payment was successful
575
-        if ($payment->status() !== EEM_Payment::status_id_approved) {
576
-            return;
577
-        }
578
-        // EEM_Registration::instance()->show_next_x_db_queries();
579
-        if (empty($registrations)) {
580
-            // find registrations with monies owing that can receive a payment
581
-            $registrations = $transaction->registrations(
582
-                array(
583
-                    array(
584
-                        // only these reg statuses can receive payments
585
-                        'STS_ID'           => array('IN', EEM_Registration::reg_statuses_that_allow_payment()),
586
-                        'REG_final_price'  => array('!=', 0),
587
-                        'REG_final_price*' => array('!=', 'REG_paid', true),
588
-                    ),
589
-                )
590
-            );
591
-        }
592
-        // still nothing ??!??
593
-        if (empty($registrations)) {
594
-            return;
595
-        }
596
-        // todo: break out the following logic into a separate strategy class
597
-        // todo: named something like "Sequential_Reg_Payment_Strategy"
598
-        // todo: which would apply payments using the capitalist "first come first paid" approach
599
-        // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy"
600
-        // todo: which would be the socialist "everybody gets a piece of pie" approach,
601
-        // todo: which would be better for deposits, where you want a bit of the payment applied to each registration
602
-        $refund = $payment->is_a_refund();
603
-        // how much is available to apply to registrations?
604
-        $available_payment_amount = abs($payment->amount());
605
-        foreach ($registrations as $registration) {
606
-            if ($registration instanceof EE_Registration) {
607
-                // nothing left?
608
-                if ($available_payment_amount <= 0) {
609
-                    break;
610
-                }
611
-                if ($refund) {
612
-                    $available_payment_amount = $this->process_registration_refund(
613
-                        $registration,
614
-                        $payment,
615
-                        $available_payment_amount
616
-                    );
617
-                } else {
618
-                    $available_payment_amount = $this->process_registration_payment(
619
-                        $registration,
620
-                        $payment,
621
-                        $available_payment_amount
622
-                    );
623
-                }
624
-            }
625
-        }
626
-        if (
627
-            $available_payment_amount > 0
628
-            && apply_filters(
629
-                'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications',
630
-                false
631
-            )
632
-        ) {
633
-            EE_Error::add_attention(
634
-                sprintf(
635
-                    esc_html__(
636
-                        'A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).',
637
-                        'event_espresso'
638
-                    ),
639
-                    EEH_Template::format_currency($available_payment_amount),
640
-                    implode(', ', array_keys($registrations)),
641
-                    '<br/>',
642
-                    EEH_Template::format_currency($payment->amount())
643
-                ),
644
-                __FILE__,
645
-                __FUNCTION__,
646
-                __LINE__
647
-            );
648
-        }
649
-    }
650
-
651
-
652
-    /**
653
-     * update registration REG_paid field after successful payment and link registration with payment
654
-     *
655
-     * @param EE_Registration $registration
656
-     * @param EE_Payment      $payment
657
-     * @param float           $available_payment_amount
658
-     * @return float
659
-     * @throws EE_Error
660
-     * @throws InvalidArgumentException
661
-     * @throws RuntimeException
662
-     * @throws InvalidDataTypeException
663
-     * @throws InvalidInterfaceException
664
-     */
665
-    public function process_registration_payment(
666
-        EE_Registration $registration,
667
-        EE_Payment $payment,
668
-        $available_payment_amount = 0.00
669
-    ) {
670
-        $owing = $registration->final_price() - $registration->paid();
671
-        if ($owing > 0) {
672
-            // don't allow payment amount to exceed the available payment amount, OR the amount owing
673
-            $payment_amount = min($available_payment_amount, $owing);
674
-            // update $available_payment_amount
675
-            $available_payment_amount -= $payment_amount;
676
-            // calculate and set new REG_paid
677
-            $registration->set_paid($registration->paid() + $payment_amount);
678
-            // now save it
679
-            $this->_apply_registration_payment($registration, $payment, $payment_amount);
680
-        }
681
-        return $available_payment_amount;
682
-    }
683
-
684
-
685
-    /**
686
-     * update registration REG_paid field after successful payment and link registration with payment
687
-     *
688
-     * @param EE_Registration $registration
689
-     * @param EE_Payment      $payment
690
-     * @param float           $payment_amount
691
-     * @return void
692
-     * @throws EE_Error
693
-     * @throws InvalidArgumentException
694
-     * @throws InvalidDataTypeException
695
-     * @throws InvalidInterfaceException
696
-     */
697
-    protected function _apply_registration_payment(
698
-        EE_Registration $registration,
699
-        EE_Payment $payment,
700
-        $payment_amount = 0.00
701
-    ) {
702
-        // find any existing reg payment records for this registration and payment
703
-        $existing_reg_payment = EEM_Registration_Payment::instance()->get_one(
704
-            array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID()))
705
-        );
706
-        // if existing registration payment exists
707
-        if ($existing_reg_payment instanceof EE_Registration_Payment) {
708
-            // then update that record
709
-            $existing_reg_payment->set_amount($payment_amount);
710
-            $existing_reg_payment->save();
711
-        } else {
712
-            // or add new relation between registration and payment and set amount
713
-            $registration->_add_relation_to(
714
-                $payment,
715
-                'Payment',
716
-                array('RPY_amount' => $payment_amount)
717
-            );
718
-            // make it stick
719
-            $registration->save();
720
-        }
721
-    }
722
-
723
-
724
-    /**
725
-     * update registration REG_paid field after refund and link registration with payment
726
-     *
727
-     * @param EE_Registration $registration
728
-     * @param EE_Payment      $payment
729
-     * @param float           $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER
730
-     * @return float
731
-     * @throws EE_Error
732
-     * @throws InvalidArgumentException
733
-     * @throws RuntimeException
734
-     * @throws InvalidDataTypeException
735
-     * @throws InvalidInterfaceException
736
-     */
737
-    public function process_registration_refund(
738
-        EE_Registration $registration,
739
-        EE_Payment $payment,
740
-        $available_refund_amount = 0.00
741
-    ) {
742
-        // EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ );
743
-        if ($registration->paid() > 0) {
744
-            // ensure $available_refund_amount is NOT negative
745
-            $available_refund_amount = (float) abs($available_refund_amount);
746
-            // don't allow refund amount to exceed the available payment amount, OR the amount paid
747
-            $refund_amount = min($available_refund_amount, (float) $registration->paid());
748
-            // update $available_payment_amount
749
-            $available_refund_amount -= $refund_amount;
750
-            // calculate and set new REG_paid
751
-            $registration->set_paid($registration->paid() - $refund_amount);
752
-            // convert payment amount back to a negative value for storage in the db
753
-            $refund_amount = (float) abs($refund_amount) * -1;
754
-            // now save it
755
-            $this->_apply_registration_payment($registration, $payment, $refund_amount);
756
-        }
757
-        return $available_refund_amount;
758
-    }
759
-
760
-
761
-    /**
762
-     * Process payments and transaction after payment process completed.
763
-     * ultimately this will send the TXN and payment details off so that notifications can be sent out.
764
-     * if this request happens to be processing an IPN,
765
-     * then we will also set the Payment Options Reg Step to completed,
766
-     * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well.
767
-     *
768
-     * @param EE_Transaction $transaction
769
-     * @param EE_Payment     $payment
770
-     * @param bool           $IPN
771
-     * @throws EE_Error
772
-     * @throws InvalidArgumentException
773
-     * @throws ReflectionException
774
-     * @throws RuntimeException
775
-     * @throws InvalidDataTypeException
776
-     * @throws InvalidInterfaceException
777
-     */
778
-    protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false)
779
-    {
780
-        /** @type EE_Transaction_Processor $transaction_processor */
781
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
782
-        // is the Payment Options Reg Step completed ?
783
-        $payment_options_step_completed = $transaction->reg_step_completed('payment_options');
784
-        // if the Payment Options Reg Step is completed...
785
-        $revisit = $payment_options_step_completed === true;
786
-        // then this is kinda sorta a revisit with regards to payments at least
787
-        $transaction_processor->set_revisit($revisit);
788
-        // if this is an IPN, let's consider the Payment Options Reg Step completed if not already
789
-        if (
790
-            $IPN
791
-            && $payment_options_step_completed !== true
792
-            && ($payment->is_approved() || $payment->is_pending())
793
-        ) {
794
-            $payment_options_step_completed = $transaction->set_reg_step_completed(
795
-                'payment_options'
796
-            );
797
-        }
798
-        // maybe update status, but don't save transaction just yet
799
-        $transaction->update_status_based_on_total_paid(false);
800
-        // check if 'finalize_registration' step has been completed...
801
-        $finalized = $transaction->reg_step_completed('finalize_registration');
802
-        //  if this is an IPN and the final step has not been initiated
803
-        if ($IPN && $payment_options_step_completed && $finalized === false) {
804
-            // and if it hasn't already been set as being started...
805
-            $finalized = $transaction->set_reg_step_initiated('finalize_registration');
806
-        }
807
-        $transaction->save();
808
-        // because the above will return false if the final step was not fully completed, we need to check again...
809
-        if ($IPN && $finalized !== false) {
810
-            // and if we are all good to go, then send out notifications
811
-            add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
812
-            // ok, now process the transaction according to the payment
813
-            $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
814
-                $transaction,
815
-                $payment
816
-            );
817
-        }
818
-        // DEBUG LOG
819
-        $payment_method = $payment->payment_method();
820
-        if ($payment_method instanceof EE_Payment_Method) {
821
-            $payment_method_type_obj = $payment_method->type_obj();
822
-            if ($payment_method_type_obj instanceof EE_PMT_Base) {
823
-                $gateway = $payment_method_type_obj->get_gateway();
824
-                if ($gateway instanceof EE_Gateway) {
825
-                    $gateway->log(
826
-                        array(
827
-                            'message'               => (string) esc_html__('Post Payment Transaction Details', 'event_espresso'),
828
-                            'transaction'           => $transaction->model_field_array(),
829
-                            'finalized'             => $finalized,
830
-                            'IPN'                   => $IPN,
831
-                            'deliver_notifications' => has_filter(
832
-                                'FHEE__EED_Messages___maybe_registration__deliver_notifications'
833
-                            ),
834
-                        ),
835
-                        $payment
836
-                    );
837
-                }
838
-            }
839
-        }
840
-    }
841
-
842
-
843
-    /**
844
-     * Force posts to PayPal to use TLS v1.2. See:
845
-     * https://core.trac.wordpress.org/ticket/36320
846
-     * https://core.trac.wordpress.org/ticket/34924#comment:15
847
-     * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
848
-     * This will affect PayPal standard, pro, express, and Payflow.
849
-     *
850
-     * @param $handle
851
-     * @param $r
852
-     * @param $url
853
-     */
854
-    public static function _curl_requests_to_paypal_use_tls($handle, $r, $url)
855
-    {
856
-        if (strpos($url, 'https://') !== false && strpos($url, '.paypal.com') !== false) {
857
-            // Use the value of the constant CURL_SSLVERSION_TLSv1 = 1
858
-            // instead of the constant because it might not be defined
859
-            curl_setopt($handle, CURLOPT_SSLVERSION, 6);
860
-        }
861
-    }
20
+	/**
21
+	 * @var EE_Payment_Processor $_instance
22
+	 * @access    private
23
+	 */
24
+	private static $_instance;
25
+
26
+
27
+	/**
28
+	 * @singleton method used to instantiate class object
29
+	 * @access    public
30
+	 * @return EE_Payment_Processor instance
31
+	 */
32
+	public static function instance()
33
+	{
34
+		// check if class object is instantiated
35
+		if (! self::$_instance instanceof EE_Payment_Processor) {
36
+			self::$_instance = new self();
37
+		}
38
+		return self::$_instance;
39
+	}
40
+
41
+
42
+	/**
43
+	 * @return EE_Payment_Processor
44
+	 */
45
+	public static function reset()
46
+	{
47
+		self::$_instance = null;
48
+		return self::instance();
49
+	}
50
+
51
+
52
+	/**
53
+	 *private constructor to prevent direct creation
54
+	 *
55
+	 * @Constructor
56
+	 * @access private
57
+	 */
58
+	private function __construct()
59
+	{
60
+		do_action('AHEE__EE_Payment_Processor__construct');
61
+		add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3);
62
+	}
63
+
64
+
65
+	/**
66
+	 * Using the selected gateway, processes the payment for that transaction, and updates the transaction
67
+	 * appropriately. Saves the payment that is generated
68
+	 *
69
+	 * @param EE_Payment_Method    $payment_method
70
+	 * @param EE_Transaction       $transaction
71
+	 * @param float                $amount       if only part of the transaction is to be paid for, how much.
72
+	 *                                           Leave null if payment is for the full amount owing
73
+	 * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method).
74
+	 *                                           Receive_form_submission() should have
75
+	 *                                           already been called on the billing form
76
+	 *                                           (ie, its inputs should have their normalized values set).
77
+	 * @param string               $return_url   string used mostly by offsite gateways to specify
78
+	 *                                           where to go AFTER the offsite gateway
79
+	 * @param string               $method       like 'CART', indicates who the client who called this was
80
+	 * @param bool                 $by_admin     TRUE if payment is being attempted from the admin
81
+	 * @param boolean              $update_txn   whether or not to call
82
+	 *                                           EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
83
+	 * @param string               $cancel_url   URL to return to if off-site payments are cancelled
84
+	 * @return EE_Payment
85
+	 * @throws EE_Error
86
+	 * @throws InvalidArgumentException
87
+	 * @throws ReflectionException
88
+	 * @throws RuntimeException
89
+	 * @throws InvalidDataTypeException
90
+	 * @throws InvalidInterfaceException
91
+	 */
92
+	public function process_payment(
93
+		EE_Payment_Method $payment_method,
94
+		EE_Transaction $transaction,
95
+		$amount = null,
96
+		$billing_form = null,
97
+		$return_url = null,
98
+		$method = 'CART',
99
+		$by_admin = false,
100
+		$update_txn = true,
101
+		$cancel_url = ''
102
+	) {
103
+		if ((float) $amount < 0) {
104
+			throw new EE_Error(
105
+				sprintf(
106
+					esc_html__(
107
+						'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund',
108
+						'event_espresso'
109
+					),
110
+					$amount,
111
+					$transaction->ID()
112
+				)
113
+			);
114
+		}
115
+		// verify payment method
116
+		$payment_method = EEM_Payment_Method::instance()->ensure_is_obj(
117
+			$payment_method,
118
+			true
119
+		);
120
+		// verify transaction
121
+		EEM_Transaction::instance()->ensure_is_obj($transaction);
122
+		$transaction->set_payment_method_ID($payment_method->ID());
123
+		// verify payment method type
124
+		if ($payment_method->type_obj() instanceof EE_PMT_Base) {
125
+			$payment = $payment_method->type_obj()->process_payment(
126
+				$transaction,
127
+				min($amount, $transaction->remaining()), // make sure we don't overcharge
128
+				$billing_form,
129
+				$return_url,
130
+				add_query_arg(array('ee_cancel_payment' => true), $cancel_url),
131
+				$method,
132
+				$by_admin
133
+			);
134
+			// check if payment method uses an off-site gateway
135
+			if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) {
136
+				// don't process payments for off-site gateways yet because no payment has occurred yet
137
+				$this->update_txn_based_on_payment($transaction, $payment, $update_txn);
138
+			}
139
+			return $payment;
140
+		}
141
+		EE_Error::add_error(
142
+			sprintf(
143
+				esc_html__(
144
+					'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
145
+					'event_espresso'
146
+				),
147
+				'<br/>',
148
+				EE_Registry::instance()->CFG->organization->get_pretty('email')
149
+			),
150
+			__FILE__,
151
+			__FUNCTION__,
152
+			__LINE__
153
+		);
154
+		return null;
155
+	}
156
+
157
+
158
+	/**
159
+	 * @param EE_Transaction|int $transaction
160
+	 * @param EE_Payment_Method  $payment_method
161
+	 * @return string
162
+	 * @throws EE_Error
163
+	 * @throws InvalidArgumentException
164
+	 * @throws InvalidDataTypeException
165
+	 * @throws InvalidInterfaceException
166
+	 */
167
+	public function get_ipn_url_for_payment_method($transaction, $payment_method)
168
+	{
169
+		/** @type \EE_Transaction $transaction */
170
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
171
+		$primary_reg = $transaction->primary_registration();
172
+		if (! $primary_reg instanceof EE_Registration) {
173
+			throw new EE_Error(
174
+				sprintf(
175
+					esc_html__(
176
+						'Cannot get IPN URL for transaction with ID %d because it has no primary registration',
177
+						'event_espresso'
178
+					),
179
+					$transaction->ID()
180
+				)
181
+			);
182
+		}
183
+		$payment_method = EEM_Payment_Method::instance()->ensure_is_obj(
184
+			$payment_method,
185
+			true
186
+		);
187
+		$url = add_query_arg(
188
+			array(
189
+				'e_reg_url_link'    => $primary_reg->reg_url_link(),
190
+				'ee_payment_method' => $payment_method->slug(),
191
+			),
192
+			EE_Registry::instance()->CFG->core->txn_page_url()
193
+		);
194
+		return $url;
195
+	}
196
+
197
+
198
+	/**
199
+	 * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so
200
+	 * we can easily find what registration the IPN is for and what payment method.
201
+	 * However, if not, we'll give all payment methods a chance to claim it and process it.
202
+	 * If a payment is found for the IPN info, it is saved.
203
+	 *
204
+	 * @param array              $_req_data            form post data
205
+	 * @param EE_Transaction|int $transaction          optional (or a transactions id)
206
+	 * @param EE_Payment_Method  $payment_method       (or a slug or id of one)
207
+	 * @param boolean            $update_txn           whether or not to call
208
+	 *                                                 EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
209
+	 * @param bool               $separate_IPN_request whether the IPN uses a separate request (true, like PayPal)
210
+	 *                                                 or is processed manually (false, like Authorize.net)
211
+	 * @throws EE_Error
212
+	 * @throws Exception
213
+	 * @return EE_Payment
214
+	 * @throws \RuntimeException
215
+	 * @throws \ReflectionException
216
+	 * @throws \InvalidArgumentException
217
+	 * @throws InvalidInterfaceException
218
+	 * @throws InvalidDataTypeException
219
+	 */
220
+	public function process_ipn(
221
+		$_req_data,
222
+		$transaction = null,
223
+		$payment_method = null,
224
+		$update_txn = true,
225
+		$separate_IPN_request = true
226
+	) {
227
+		EE_Registry::instance()->load_model('Change_Log');
228
+		$_req_data = $this->_remove_unusable_characters_from_array((array) $_req_data);
229
+		EE_Processor_Base::set_IPN($separate_IPN_request);
230
+		$obj_for_log = null;
231
+		if ($transaction instanceof EE_Transaction) {
232
+			$obj_for_log = $transaction;
233
+			if ($payment_method instanceof EE_Payment_Method) {
234
+				$obj_for_log = EEM_Payment::instance()->get_one(
235
+					array(
236
+						array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()),
237
+						'order_by' => array('PAY_timestamp' => 'desc'),
238
+					)
239
+				);
240
+			}
241
+		} elseif ($payment_method instanceof EE_Payment) {
242
+			$obj_for_log = $payment_method;
243
+		}
244
+		$log = EEM_Change_Log::instance()->log(
245
+			EEM_Change_Log::type_gateway,
246
+			array('IPN data received' => $_req_data),
247
+			$obj_for_log
248
+		);
249
+		try {
250
+			/**
251
+			 * @var EE_Payment $payment
252
+			 */
253
+			$payment = null;
254
+			if ($transaction && $payment_method) {
255
+				/** @type EE_Transaction $transaction */
256
+				$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
257
+				/** @type EE_Payment_Method $payment_method */
258
+				$payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method);
259
+				if ($payment_method->type_obj() instanceof EE_PMT_Base) {
260
+					try {
261
+						$payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction);
262
+						$log->set_object($payment);
263
+					} catch (EventEspresso\core\exceptions\IpnException $e) {
264
+						EEM_Change_Log::instance()->log(
265
+							EEM_Change_Log::type_gateway,
266
+							array(
267
+								'message'     => 'IPN Exception: ' . $e->getMessage(),
268
+								'current_url' => EEH_URL::current_url(),
269
+								'payment'     => $e->getPaymentProperties(),
270
+								'IPN_data'    => $e->getIpnData(),
271
+							),
272
+							$obj_for_log
273
+						);
274
+						return $e->getPayment();
275
+					}
276
+				} else {
277
+					// not a payment
278
+					EE_Error::add_error(
279
+						sprintf(
280
+							esc_html__(
281
+								'A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.',
282
+								'event_espresso'
283
+							),
284
+							'<br/>',
285
+							EE_Registry::instance()->CFG->organization->get_pretty('email')
286
+						),
287
+						__FILE__,
288
+						__FUNCTION__,
289
+						__LINE__
290
+					);
291
+				}
292
+			} else {
293
+				// that's actually pretty ok. The IPN just wasn't able
294
+				// to identify which transaction or payment method this was for
295
+				// give all active payment methods a chance to claim it
296
+				$active_payment_methods = EEM_Payment_Method::instance()->get_all_active();
297
+				foreach ($active_payment_methods as $active_payment_method) {
298
+					try {
299
+						$payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data);
300
+						$payment_method = $active_payment_method;
301
+						EEM_Change_Log::instance()->log(
302
+							EEM_Change_Log::type_gateway,
303
+							array('IPN data' => $_req_data),
304
+							$payment
305
+						);
306
+						break;
307
+					} catch (EventEspresso\core\exceptions\IpnException $e) {
308
+						EEM_Change_Log::instance()->log(
309
+							EEM_Change_Log::type_gateway,
310
+							array(
311
+								'message'     => 'IPN Exception: ' . $e->getMessage(),
312
+								'current_url' => EEH_URL::current_url(),
313
+								'payment'     => $e->getPaymentProperties(),
314
+								'IPN_data'    => $e->getIpnData(),
315
+							),
316
+							$obj_for_log
317
+						);
318
+						return $e->getPayment();
319
+					} catch (EE_Error $e) {
320
+						// that's fine- it apparently couldn't handle the IPN
321
+					}
322
+				}
323
+			}
324
+			// EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method);
325
+			if ($payment instanceof EE_Payment) {
326
+				$payment->save();
327
+				//  update the TXN
328
+				$this->update_txn_based_on_payment(
329
+					$transaction,
330
+					$payment,
331
+					$update_txn,
332
+					$separate_IPN_request
333
+				);
334
+			} else {
335
+				// we couldn't find the payment for this IPN... let's try and log at least SOMETHING
336
+				if ($payment_method) {
337
+					EEM_Change_Log::instance()->log(
338
+						EEM_Change_Log::type_gateway,
339
+						array('IPN data' => $_req_data),
340
+						$payment_method
341
+					);
342
+				} elseif ($transaction) {
343
+					EEM_Change_Log::instance()->log(
344
+						EEM_Change_Log::type_gateway,
345
+						array('IPN data' => $_req_data),
346
+						$transaction
347
+					);
348
+				}
349
+			}
350
+			return $payment;
351
+		} catch (EE_Error $e) {
352
+			do_action(
353
+				'AHEE__log',
354
+				__FILE__,
355
+				__FUNCTION__,
356
+				sprintf(
357
+					esc_html__(
358
+						'Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"',
359
+						'event_espresso'
360
+					),
361
+					print_r($transaction, true),
362
+					print_r($_req_data, true),
363
+					$e->getMessage()
364
+				)
365
+			);
366
+			throw $e;
367
+		}
368
+	}
369
+
370
+
371
+	/**
372
+	 * Removes any non-printable illegal characters from the input,
373
+	 * which might cause a raucous when trying to insert into the database
374
+	 *
375
+	 * @param  array $request_data
376
+	 * @return array
377
+	 */
378
+	protected function _remove_unusable_characters_from_array(array $request_data)
379
+	{
380
+		$return_data = array();
381
+		foreach ($request_data as $key => $value) {
382
+			$return_data[ $this->_remove_unusable_characters($key) ] = $this->_remove_unusable_characters(
383
+				$value
384
+			);
385
+		}
386
+		return $return_data;
387
+	}
388
+
389
+
390
+	/**
391
+	 * Removes any non-printable illegal characters from the input,
392
+	 * which might cause a raucous when trying to insert into the database
393
+	 *
394
+	 * @param string $request_data
395
+	 * @return string
396
+	 */
397
+	protected function _remove_unusable_characters($request_data)
398
+	{
399
+		return preg_replace('/[^[:print:]]/', '', $request_data);
400
+	}
401
+
402
+
403
+	/**
404
+	 * Should be called just before displaying the payment attempt results to the user,
405
+	 * when the payment attempt has finished. Some payment methods may have special
406
+	 * logic to perform here. For example, if process_payment() happens on a special request
407
+	 * and then the user is redirected to a page that displays the payment's status, this
408
+	 * should be called while loading the page that displays the payment's status. If the user is
409
+	 * sent to an offsite payment provider, this should be called upon returning from that offsite payment
410
+	 * provider.
411
+	 *
412
+	 * @param EE_Transaction|int $transaction
413
+	 * @param bool               $update_txn whether or not to call
414
+	 *                                       EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
415
+	 * @return EE_Payment
416
+	 * @throws EE_Error
417
+	 * @throws InvalidArgumentException
418
+	 * @throws ReflectionException
419
+	 * @throws RuntimeException
420
+	 * @throws InvalidDataTypeException
421
+	 * @throws InvalidInterfaceException
422
+	 * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO,
423
+	 *                                       to call handle_ipn() for offsite gateways that don't receive separate IPNs
424
+	 */
425
+	public function finalize_payment_for($transaction, $update_txn = true)
426
+	{
427
+		/** @var $transaction EE_Transaction */
428
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
429
+		$last_payment_method = $transaction->payment_method();
430
+		if ($last_payment_method instanceof EE_Payment_Method) {
431
+			$payment = $last_payment_method->type_obj()->finalize_payment_for($transaction);
432
+			$this->update_txn_based_on_payment($transaction, $payment, $update_txn);
433
+			return $payment;
434
+		}
435
+		return null;
436
+	}
437
+
438
+
439
+	/**
440
+	 * Processes a direct refund request, saves the payment, and updates the transaction appropriately.
441
+	 *
442
+	 * @param EE_Payment_Method $payment_method
443
+	 * @param EE_Payment        $payment_to_refund
444
+	 * @param array             $refund_info
445
+	 * @return EE_Payment
446
+	 * @throws EE_Error
447
+	 * @throws InvalidArgumentException
448
+	 * @throws ReflectionException
449
+	 * @throws RuntimeException
450
+	 * @throws InvalidDataTypeException
451
+	 * @throws InvalidInterfaceException
452
+	 */
453
+	public function process_refund(
454
+		EE_Payment_Method $payment_method,
455
+		EE_Payment $payment_to_refund,
456
+		array $refund_info = array()
457
+	) {
458
+		if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) {
459
+			$payment_method->type_obj()->process_refund($payment_to_refund, $refund_info);
460
+			$this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund);
461
+		}
462
+		return $payment_to_refund;
463
+	}
464
+
465
+
466
+	/**
467
+	 * This should be called each time there may have been an update to a
468
+	 * payment on a transaction (ie, we asked for a payment to process a
469
+	 * payment for a transaction, or we told a payment method about an IPN, or
470
+	 * we told a payment method to
471
+	 * "finalize_payment_for" (a transaction), or we told a payment method to
472
+	 * process a refund. This should handle firing the correct hooks to
473
+	 * indicate
474
+	 * what exactly happened and updating the transaction appropriately). This
475
+	 * could be integrated directly into EE_Transaction upon save, but we want
476
+	 * this logic to be separate from 'normal' plain-jane saving and updating
477
+	 * of transactions and payments, and to be tied to payment processing.
478
+	 * Note: this method DOES NOT save the payment passed into it. It is the responsibility
479
+	 * of previous code to decide whether or not to save (because the payment passed into
480
+	 * this method might be a temporary, never-to-be-saved payment from an offline gateway,
481
+	 * in which case we only want that payment object for some temporary usage during this request,
482
+	 * but we don't want it to be saved).
483
+	 *
484
+	 * @param EE_Transaction|int $transaction
485
+	 * @param EE_Payment         $payment
486
+	 * @param boolean            $update_txn
487
+	 *                        whether or not to call
488
+	 *                        EE_Transaction_Processor::
489
+	 *                        update_transaction_and_registrations_after_checkout_or_payment()
490
+	 *                        (you can save 1 DB query if you know you're going
491
+	 *                        to save it later instead)
492
+	 * @param bool               $IPN
493
+	 *                        if processing IPNs or other similar payment
494
+	 *                        related activities that occur in alternate
495
+	 *                        requests than the main one that is processing the
496
+	 *                        TXN, then set this to true to check whether the
497
+	 *                        TXN is locked before updating
498
+	 * @throws EE_Error
499
+	 * @throws InvalidArgumentException
500
+	 * @throws ReflectionException
501
+	 * @throws RuntimeException
502
+	 * @throws InvalidDataTypeException
503
+	 * @throws InvalidInterfaceException
504
+	 */
505
+	public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false)
506
+	{
507
+		$do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful';
508
+		/** @type EE_Transaction $transaction */
509
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
510
+		// can we freely update the TXN at this moment?
511
+		if ($IPN && $transaction->is_locked()) {
512
+			// don't update the transaction at this exact moment
513
+			// because the TXN is active in another request
514
+			EE_Cron_Tasks::schedule_update_transaction_with_payment(
515
+				time(),
516
+				$transaction->ID(),
517
+				$payment->ID()
518
+			);
519
+		} else {
520
+			// verify payment and that it has been saved
521
+			if ($payment instanceof EE_Payment && $payment->ID()) {
522
+				if (
523
+					$payment->payment_method() instanceof EE_Payment_Method
524
+					&& $payment->payment_method()->type_obj() instanceof EE_PMT_Base
525
+				) {
526
+					$payment->payment_method()->type_obj()->update_txn_based_on_payment($payment);
527
+					// update TXN registrations with payment info
528
+					$this->process_registration_payments($transaction, $payment);
529
+				}
530
+				$do_action = $payment->just_approved()
531
+					? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful'
532
+					: $do_action;
533
+			} else {
534
+				// send out notifications
535
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
536
+				$do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made';
537
+			}
538
+			if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) {
539
+				/** @type EE_Transaction_Payments $transaction_payments */
540
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
541
+				// set new value for total paid
542
+				$transaction_payments->calculate_total_payments_and_update_status($transaction);
543
+				// call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ???
544
+				if ($update_txn) {
545
+					$this->_post_payment_processing($transaction, $payment, $IPN);
546
+				}
547
+			}
548
+			// granular hook for others to use.
549
+			do_action($do_action, $transaction, $payment);
550
+			do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action');
551
+			// global hook for others to use.
552
+			do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment);
553
+		}
554
+	}
555
+
556
+
557
+	/**
558
+	 * update registrations REG_paid field after successful payment and link registrations with payment
559
+	 *
560
+	 * @param EE_Transaction    $transaction
561
+	 * @param EE_Payment        $payment
562
+	 * @param EE_Registration[] $registrations
563
+	 * @throws EE_Error
564
+	 * @throws InvalidArgumentException
565
+	 * @throws RuntimeException
566
+	 * @throws InvalidDataTypeException
567
+	 * @throws InvalidInterfaceException
568
+	 */
569
+	public function process_registration_payments(
570
+		EE_Transaction $transaction,
571
+		EE_Payment $payment,
572
+		array $registrations = array()
573
+	) {
574
+		// only process if payment was successful
575
+		if ($payment->status() !== EEM_Payment::status_id_approved) {
576
+			return;
577
+		}
578
+		// EEM_Registration::instance()->show_next_x_db_queries();
579
+		if (empty($registrations)) {
580
+			// find registrations with monies owing that can receive a payment
581
+			$registrations = $transaction->registrations(
582
+				array(
583
+					array(
584
+						// only these reg statuses can receive payments
585
+						'STS_ID'           => array('IN', EEM_Registration::reg_statuses_that_allow_payment()),
586
+						'REG_final_price'  => array('!=', 0),
587
+						'REG_final_price*' => array('!=', 'REG_paid', true),
588
+					),
589
+				)
590
+			);
591
+		}
592
+		// still nothing ??!??
593
+		if (empty($registrations)) {
594
+			return;
595
+		}
596
+		// todo: break out the following logic into a separate strategy class
597
+		// todo: named something like "Sequential_Reg_Payment_Strategy"
598
+		// todo: which would apply payments using the capitalist "first come first paid" approach
599
+		// todo: then have another strategy class like "Distributed_Reg_Payment_Strategy"
600
+		// todo: which would be the socialist "everybody gets a piece of pie" approach,
601
+		// todo: which would be better for deposits, where you want a bit of the payment applied to each registration
602
+		$refund = $payment->is_a_refund();
603
+		// how much is available to apply to registrations?
604
+		$available_payment_amount = abs($payment->amount());
605
+		foreach ($registrations as $registration) {
606
+			if ($registration instanceof EE_Registration) {
607
+				// nothing left?
608
+				if ($available_payment_amount <= 0) {
609
+					break;
610
+				}
611
+				if ($refund) {
612
+					$available_payment_amount = $this->process_registration_refund(
613
+						$registration,
614
+						$payment,
615
+						$available_payment_amount
616
+					);
617
+				} else {
618
+					$available_payment_amount = $this->process_registration_payment(
619
+						$registration,
620
+						$payment,
621
+						$available_payment_amount
622
+					);
623
+				}
624
+			}
625
+		}
626
+		if (
627
+			$available_payment_amount > 0
628
+			&& apply_filters(
629
+				'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications',
630
+				false
631
+			)
632
+		) {
633
+			EE_Error::add_attention(
634
+				sprintf(
635
+					esc_html__(
636
+						'A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).',
637
+						'event_espresso'
638
+					),
639
+					EEH_Template::format_currency($available_payment_amount),
640
+					implode(', ', array_keys($registrations)),
641
+					'<br/>',
642
+					EEH_Template::format_currency($payment->amount())
643
+				),
644
+				__FILE__,
645
+				__FUNCTION__,
646
+				__LINE__
647
+			);
648
+		}
649
+	}
650
+
651
+
652
+	/**
653
+	 * update registration REG_paid field after successful payment and link registration with payment
654
+	 *
655
+	 * @param EE_Registration $registration
656
+	 * @param EE_Payment      $payment
657
+	 * @param float           $available_payment_amount
658
+	 * @return float
659
+	 * @throws EE_Error
660
+	 * @throws InvalidArgumentException
661
+	 * @throws RuntimeException
662
+	 * @throws InvalidDataTypeException
663
+	 * @throws InvalidInterfaceException
664
+	 */
665
+	public function process_registration_payment(
666
+		EE_Registration $registration,
667
+		EE_Payment $payment,
668
+		$available_payment_amount = 0.00
669
+	) {
670
+		$owing = $registration->final_price() - $registration->paid();
671
+		if ($owing > 0) {
672
+			// don't allow payment amount to exceed the available payment amount, OR the amount owing
673
+			$payment_amount = min($available_payment_amount, $owing);
674
+			// update $available_payment_amount
675
+			$available_payment_amount -= $payment_amount;
676
+			// calculate and set new REG_paid
677
+			$registration->set_paid($registration->paid() + $payment_amount);
678
+			// now save it
679
+			$this->_apply_registration_payment($registration, $payment, $payment_amount);
680
+		}
681
+		return $available_payment_amount;
682
+	}
683
+
684
+
685
+	/**
686
+	 * update registration REG_paid field after successful payment and link registration with payment
687
+	 *
688
+	 * @param EE_Registration $registration
689
+	 * @param EE_Payment      $payment
690
+	 * @param float           $payment_amount
691
+	 * @return void
692
+	 * @throws EE_Error
693
+	 * @throws InvalidArgumentException
694
+	 * @throws InvalidDataTypeException
695
+	 * @throws InvalidInterfaceException
696
+	 */
697
+	protected function _apply_registration_payment(
698
+		EE_Registration $registration,
699
+		EE_Payment $payment,
700
+		$payment_amount = 0.00
701
+	) {
702
+		// find any existing reg payment records for this registration and payment
703
+		$existing_reg_payment = EEM_Registration_Payment::instance()->get_one(
704
+			array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID()))
705
+		);
706
+		// if existing registration payment exists
707
+		if ($existing_reg_payment instanceof EE_Registration_Payment) {
708
+			// then update that record
709
+			$existing_reg_payment->set_amount($payment_amount);
710
+			$existing_reg_payment->save();
711
+		} else {
712
+			// or add new relation between registration and payment and set amount
713
+			$registration->_add_relation_to(
714
+				$payment,
715
+				'Payment',
716
+				array('RPY_amount' => $payment_amount)
717
+			);
718
+			// make it stick
719
+			$registration->save();
720
+		}
721
+	}
722
+
723
+
724
+	/**
725
+	 * update registration REG_paid field after refund and link registration with payment
726
+	 *
727
+	 * @param EE_Registration $registration
728
+	 * @param EE_Payment      $payment
729
+	 * @param float           $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER
730
+	 * @return float
731
+	 * @throws EE_Error
732
+	 * @throws InvalidArgumentException
733
+	 * @throws RuntimeException
734
+	 * @throws InvalidDataTypeException
735
+	 * @throws InvalidInterfaceException
736
+	 */
737
+	public function process_registration_refund(
738
+		EE_Registration $registration,
739
+		EE_Payment $payment,
740
+		$available_refund_amount = 0.00
741
+	) {
742
+		// EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ );
743
+		if ($registration->paid() > 0) {
744
+			// ensure $available_refund_amount is NOT negative
745
+			$available_refund_amount = (float) abs($available_refund_amount);
746
+			// don't allow refund amount to exceed the available payment amount, OR the amount paid
747
+			$refund_amount = min($available_refund_amount, (float) $registration->paid());
748
+			// update $available_payment_amount
749
+			$available_refund_amount -= $refund_amount;
750
+			// calculate and set new REG_paid
751
+			$registration->set_paid($registration->paid() - $refund_amount);
752
+			// convert payment amount back to a negative value for storage in the db
753
+			$refund_amount = (float) abs($refund_amount) * -1;
754
+			// now save it
755
+			$this->_apply_registration_payment($registration, $payment, $refund_amount);
756
+		}
757
+		return $available_refund_amount;
758
+	}
759
+
760
+
761
+	/**
762
+	 * Process payments and transaction after payment process completed.
763
+	 * ultimately this will send the TXN and payment details off so that notifications can be sent out.
764
+	 * if this request happens to be processing an IPN,
765
+	 * then we will also set the Payment Options Reg Step to completed,
766
+	 * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well.
767
+	 *
768
+	 * @param EE_Transaction $transaction
769
+	 * @param EE_Payment     $payment
770
+	 * @param bool           $IPN
771
+	 * @throws EE_Error
772
+	 * @throws InvalidArgumentException
773
+	 * @throws ReflectionException
774
+	 * @throws RuntimeException
775
+	 * @throws InvalidDataTypeException
776
+	 * @throws InvalidInterfaceException
777
+	 */
778
+	protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false)
779
+	{
780
+		/** @type EE_Transaction_Processor $transaction_processor */
781
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
782
+		// is the Payment Options Reg Step completed ?
783
+		$payment_options_step_completed = $transaction->reg_step_completed('payment_options');
784
+		// if the Payment Options Reg Step is completed...
785
+		$revisit = $payment_options_step_completed === true;
786
+		// then this is kinda sorta a revisit with regards to payments at least
787
+		$transaction_processor->set_revisit($revisit);
788
+		// if this is an IPN, let's consider the Payment Options Reg Step completed if not already
789
+		if (
790
+			$IPN
791
+			&& $payment_options_step_completed !== true
792
+			&& ($payment->is_approved() || $payment->is_pending())
793
+		) {
794
+			$payment_options_step_completed = $transaction->set_reg_step_completed(
795
+				'payment_options'
796
+			);
797
+		}
798
+		// maybe update status, but don't save transaction just yet
799
+		$transaction->update_status_based_on_total_paid(false);
800
+		// check if 'finalize_registration' step has been completed...
801
+		$finalized = $transaction->reg_step_completed('finalize_registration');
802
+		//  if this is an IPN and the final step has not been initiated
803
+		if ($IPN && $payment_options_step_completed && $finalized === false) {
804
+			// and if it hasn't already been set as being started...
805
+			$finalized = $transaction->set_reg_step_initiated('finalize_registration');
806
+		}
807
+		$transaction->save();
808
+		// because the above will return false if the final step was not fully completed, we need to check again...
809
+		if ($IPN && $finalized !== false) {
810
+			// and if we are all good to go, then send out notifications
811
+			add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
812
+			// ok, now process the transaction according to the payment
813
+			$transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
814
+				$transaction,
815
+				$payment
816
+			);
817
+		}
818
+		// DEBUG LOG
819
+		$payment_method = $payment->payment_method();
820
+		if ($payment_method instanceof EE_Payment_Method) {
821
+			$payment_method_type_obj = $payment_method->type_obj();
822
+			if ($payment_method_type_obj instanceof EE_PMT_Base) {
823
+				$gateway = $payment_method_type_obj->get_gateway();
824
+				if ($gateway instanceof EE_Gateway) {
825
+					$gateway->log(
826
+						array(
827
+							'message'               => (string) esc_html__('Post Payment Transaction Details', 'event_espresso'),
828
+							'transaction'           => $transaction->model_field_array(),
829
+							'finalized'             => $finalized,
830
+							'IPN'                   => $IPN,
831
+							'deliver_notifications' => has_filter(
832
+								'FHEE__EED_Messages___maybe_registration__deliver_notifications'
833
+							),
834
+						),
835
+						$payment
836
+					);
837
+				}
838
+			}
839
+		}
840
+	}
841
+
842
+
843
+	/**
844
+	 * Force posts to PayPal to use TLS v1.2. See:
845
+	 * https://core.trac.wordpress.org/ticket/36320
846
+	 * https://core.trac.wordpress.org/ticket/34924#comment:15
847
+	 * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
848
+	 * This will affect PayPal standard, pro, express, and Payflow.
849
+	 *
850
+	 * @param $handle
851
+	 * @param $r
852
+	 * @param $url
853
+	 */
854
+	public static function _curl_requests_to_paypal_use_tls($handle, $r, $url)
855
+	{
856
+		if (strpos($url, 'https://') !== false && strpos($url, '.paypal.com') !== false) {
857
+			// Use the value of the constant CURL_SSLVERSION_TLSv1 = 1
858
+			// instead of the constant because it might not be defined
859
+			curl_setopt($handle, CURLOPT_SSLVERSION, 6);
860
+		}
861
+	}
862 862
 }
Please login to merge, or discard this patch.
core/services/container/CoffeeMaker.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     public static function validateType($type)
69 69
     {
70 70
         $types = CoffeeMaker::getTypes();
71
-        if (! in_array($type, $types, true)) {
71
+        if ( ! in_array($type, $types, true)) {
72 72
             throw new InvalidIdentifierException(
73 73
                 is_object($type) ? get_class($type) : gettype($type),
74 74
                 esc_html__(
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
     protected function resolveClassAndFilepath(RecipeInterface $recipe)
152 152
     {
153 153
         $paths = $recipe->paths();
154
-        if (! empty($paths)) {
154
+        if ( ! empty($paths)) {
155 155
             foreach ($paths as $path) {
156 156
                 if (strpos($path, '*') === false && is_readable($path)) {
157 157
                     require_once($path);
Please login to merge, or discard this patch.
Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -17,156 +17,156 @@
 block discarded – undo
17 17
  */
18 18
 abstract class CoffeeMaker implements CoffeeMakerInterface
19 19
 {
20
-    /**
21
-     * Indicates that CoffeeMaker should construct a NEW entity instance from the provided arguments (if given)
22
-     */
23
-    const BREW_NEW = 'new';
24
-
25
-    /**
26
-     * Indicates that CoffeeMaker should always return a SHARED instance
27
-     */
28
-    const BREW_SHARED = 'shared';
29
-
30
-    /**
31
-     * Indicates that CoffeeMaker should only load the file/class/interface but NOT instantiate
32
-     */
33
-    const BREW_LOAD_ONLY = 'load_only';
34
-
35
-
36
-    /**
37
-     * @var CoffeePotInterface $coffee_pot
38
-     */
39
-    private $coffee_pot;
40
-
41
-    /**
42
-     * @var DependencyInjector $injector
43
-     */
44
-    private $injector;
45
-
46
-
47
-    /**
48
-     * @return array
49
-     */
50
-    public static function getTypes()
51
-    {
52
-        return (array) apply_filters(
53
-            'FHEE__EventEspresso\core\services\container\CoffeeMaker__getTypes',
54
-            array(
55
-                CoffeeMaker::BREW_NEW,
56
-                CoffeeMaker::BREW_SHARED,
57
-                CoffeeMaker::BREW_LOAD_ONLY,
58
-            )
59
-        );
60
-    }
61
-
62
-
63
-    /**
64
-     * @param $type
65
-     * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
66
-     */
67
-    public static function validateType($type)
68
-    {
69
-        $types = CoffeeMaker::getTypes();
70
-        if (! in_array($type, $types, true)) {
71
-            throw new InvalidIdentifierException(
72
-                is_object($type) ? get_class($type) : gettype($type),
73
-                esc_html__(
74
-                    'recipe type (one of the class constants on \EventEspresso\core\services\container\CoffeeMaker)',
75
-                    'event_espresso'
76
-                )
77
-            );
78
-        }
79
-        return $type;
80
-    }
81
-
82
-
83
-    /**
84
-     * CoffeeMaker constructor.
85
-     *
86
-     * @param CoffeePotInterface $coffee_pot
87
-     * @param InjectorInterface  $injector
88
-     */
89
-    public function __construct(CoffeePotInterface $coffee_pot, InjectorInterface $injector)
90
-    {
91
-        $this->coffee_pot = $coffee_pot;
92
-        $this->injector = $injector;
93
-    }
94
-
95
-
96
-    /**
97
-     * @return \EventEspresso\core\services\container\CoffeePotInterface
98
-     */
99
-    protected function coffeePot()
100
-    {
101
-        return $this->coffee_pot;
102
-    }
103
-
104
-
105
-    /**
106
-     * @return \EventEspresso\core\services\container\DependencyInjector
107
-     */
108
-    protected function injector()
109
-    {
110
-        return $this->injector;
111
-    }
112
-
113
-
114
-    /**
115
-     * Examines the constructor to determine which method should be used for instantiation
116
-     *
117
-     * @param \ReflectionClass $reflector
118
-     * @return mixed
119
-     * @throws InstantiationException
120
-     */
121
-    protected function resolveInstantiationMethod(\ReflectionClass $reflector)
122
-    {
123
-        if ($reflector->getConstructor() === null) {
124
-            return 'NewInstance';
125
-        }
126
-        if ($reflector->isInstantiable()) {
127
-            return 'NewInstanceArgs';
128
-        }
129
-        if (method_exists($reflector->getName(), 'instance')) {
130
-            return 'instance';
131
-        }
132
-        if (method_exists($reflector->getName(), 'new_instance')) {
133
-            return 'new_instance';
134
-        }
135
-        if (method_exists($reflector->getName(), 'new_instance_from_db')) {
136
-            return 'new_instance_from_db';
137
-        }
138
-        throw new InstantiationException($reflector->getName());
139
-    }
140
-
141
-
142
-    /**
143
-     * Ensures files for classes that are not PSR-4 compatible are loaded
144
-     * and then verifies that classes exist where applicable
145
-     *
146
-     * @param RecipeInterface $recipe
147
-     * @return bool
148
-     * @throws InvalidClassException
149
-     */
150
-    protected function resolveClassAndFilepath(RecipeInterface $recipe)
151
-    {
152
-        $paths = $recipe->paths();
153
-        if (! empty($paths)) {
154
-            foreach ($paths as $path) {
155
-                if (strpos($path, '*') === false && is_readable($path)) {
156
-                    require_once($path);
157
-                }
158
-            }
159
-        }
160
-        // re: using "false" for class_exists() second param:
161
-        // if a class name is not already known to PHP, then class_exists() will run through
162
-        // all of the registered spl_autoload functions until it either finds the class,
163
-        // or gets to the end of the registered spl_autoload functions.
164
-        // When the second parameter is true, it will also attempt to load the class file,
165
-        // but it will also trigger an error if the class can not be loaded.
166
-        // We don't want that extra error in the mix, so we have set the second param to "false"
167
-        if ($recipe->type() !== CoffeeMaker::BREW_LOAD_ONLY && ! class_exists($recipe->fqcn(), false)) {
168
-            throw new InvalidClassException($recipe->identifier());
169
-        }
170
-        return true;
171
-    }
20
+	/**
21
+	 * Indicates that CoffeeMaker should construct a NEW entity instance from the provided arguments (if given)
22
+	 */
23
+	const BREW_NEW = 'new';
24
+
25
+	/**
26
+	 * Indicates that CoffeeMaker should always return a SHARED instance
27
+	 */
28
+	const BREW_SHARED = 'shared';
29
+
30
+	/**
31
+	 * Indicates that CoffeeMaker should only load the file/class/interface but NOT instantiate
32
+	 */
33
+	const BREW_LOAD_ONLY = 'load_only';
34
+
35
+
36
+	/**
37
+	 * @var CoffeePotInterface $coffee_pot
38
+	 */
39
+	private $coffee_pot;
40
+
41
+	/**
42
+	 * @var DependencyInjector $injector
43
+	 */
44
+	private $injector;
45
+
46
+
47
+	/**
48
+	 * @return array
49
+	 */
50
+	public static function getTypes()
51
+	{
52
+		return (array) apply_filters(
53
+			'FHEE__EventEspresso\core\services\container\CoffeeMaker__getTypes',
54
+			array(
55
+				CoffeeMaker::BREW_NEW,
56
+				CoffeeMaker::BREW_SHARED,
57
+				CoffeeMaker::BREW_LOAD_ONLY,
58
+			)
59
+		);
60
+	}
61
+
62
+
63
+	/**
64
+	 * @param $type
65
+	 * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
66
+	 */
67
+	public static function validateType($type)
68
+	{
69
+		$types = CoffeeMaker::getTypes();
70
+		if (! in_array($type, $types, true)) {
71
+			throw new InvalidIdentifierException(
72
+				is_object($type) ? get_class($type) : gettype($type),
73
+				esc_html__(
74
+					'recipe type (one of the class constants on \EventEspresso\core\services\container\CoffeeMaker)',
75
+					'event_espresso'
76
+				)
77
+			);
78
+		}
79
+		return $type;
80
+	}
81
+
82
+
83
+	/**
84
+	 * CoffeeMaker constructor.
85
+	 *
86
+	 * @param CoffeePotInterface $coffee_pot
87
+	 * @param InjectorInterface  $injector
88
+	 */
89
+	public function __construct(CoffeePotInterface $coffee_pot, InjectorInterface $injector)
90
+	{
91
+		$this->coffee_pot = $coffee_pot;
92
+		$this->injector = $injector;
93
+	}
94
+
95
+
96
+	/**
97
+	 * @return \EventEspresso\core\services\container\CoffeePotInterface
98
+	 */
99
+	protected function coffeePot()
100
+	{
101
+		return $this->coffee_pot;
102
+	}
103
+
104
+
105
+	/**
106
+	 * @return \EventEspresso\core\services\container\DependencyInjector
107
+	 */
108
+	protected function injector()
109
+	{
110
+		return $this->injector;
111
+	}
112
+
113
+
114
+	/**
115
+	 * Examines the constructor to determine which method should be used for instantiation
116
+	 *
117
+	 * @param \ReflectionClass $reflector
118
+	 * @return mixed
119
+	 * @throws InstantiationException
120
+	 */
121
+	protected function resolveInstantiationMethod(\ReflectionClass $reflector)
122
+	{
123
+		if ($reflector->getConstructor() === null) {
124
+			return 'NewInstance';
125
+		}
126
+		if ($reflector->isInstantiable()) {
127
+			return 'NewInstanceArgs';
128
+		}
129
+		if (method_exists($reflector->getName(), 'instance')) {
130
+			return 'instance';
131
+		}
132
+		if (method_exists($reflector->getName(), 'new_instance')) {
133
+			return 'new_instance';
134
+		}
135
+		if (method_exists($reflector->getName(), 'new_instance_from_db')) {
136
+			return 'new_instance_from_db';
137
+		}
138
+		throw new InstantiationException($reflector->getName());
139
+	}
140
+
141
+
142
+	/**
143
+	 * Ensures files for classes that are not PSR-4 compatible are loaded
144
+	 * and then verifies that classes exist where applicable
145
+	 *
146
+	 * @param RecipeInterface $recipe
147
+	 * @return bool
148
+	 * @throws InvalidClassException
149
+	 */
150
+	protected function resolveClassAndFilepath(RecipeInterface $recipe)
151
+	{
152
+		$paths = $recipe->paths();
153
+		if (! empty($paths)) {
154
+			foreach ($paths as $path) {
155
+				if (strpos($path, '*') === false && is_readable($path)) {
156
+					require_once($path);
157
+				}
158
+			}
159
+		}
160
+		// re: using "false" for class_exists() second param:
161
+		// if a class name is not already known to PHP, then class_exists() will run through
162
+		// all of the registered spl_autoload functions until it either finds the class,
163
+		// or gets to the end of the registered spl_autoload functions.
164
+		// When the second parameter is true, it will also attempt to load the class file,
165
+		// but it will also trigger an error if the class can not be loaded.
166
+		// We don't want that extra error in the mix, so we have set the second param to "false"
167
+		if ($recipe->type() !== CoffeeMaker::BREW_LOAD_ONLY && ! class_exists($recipe->fqcn(), false)) {
168
+			throw new InvalidClassException($recipe->identifier());
169
+		}
170
+		return true;
171
+	}
172 172
 }
Please login to merge, or discard this patch.
core/services/container/Recipe.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
      */
190 190
     public function setIdentifier($identifier)
191 191
     {
192
-        if (! is_string($identifier) || empty($identifier)) {
192
+        if ( ! is_string($identifier) || empty($identifier)) {
193 193
             throw new InvalidIdentifierException(
194 194
                 is_object($identifier) ? get_class($identifier) : gettype($identifier),
195 195
                 esc_html__('class identifier (typically a \Fully\Qualified\ClassName)', 'event_espresso')
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
     public function setFqcn($fqcn)
217 217
     {
218 218
         $fqcn = ! empty($fqcn) ? $fqcn : $this->identifier;
219
-        if (! is_string($fqcn)) {
219
+        if ( ! is_string($fqcn)) {
220 220
             throw new InvalidDataTypeException(
221 221
                 '$fqcn',
222 222
                 is_object($fqcn) ? get_class($fqcn) : gettype($fqcn),
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
         if (empty($ingredients)) {
248 248
             return;
249 249
         }
250
-        if (! is_array($ingredients)) {
250
+        if ( ! is_array($ingredients)) {
251 251
             throw new InvalidDataTypeException(
252 252
                 '$ingredients',
253 253
                 is_object($ingredients) ? get_class($ingredients) : gettype($ingredients),
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
         if (empty($filters)) {
280 280
             return;
281 281
         }
282
-        if (! is_array($filters)) {
282
+        if ( ! is_array($filters)) {
283 283
             throw new InvalidDataTypeException(
284 284
                 '$filters',
285 285
                 is_object($filters) ? get_class($filters) : gettype($filters),
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
         if (empty($paths)) {
307 307
             return;
308 308
         }
309
-        if (! (is_string($paths) || is_array($paths))) {
309
+        if ( ! (is_string($paths) || is_array($paths))) {
310 310
             throw new InvalidDataTypeException(
311 311
                 '$path',
312 312
                 is_object($paths) ? get_class($paths) : gettype($paths),
Please login to merge, or discard this patch.
Indentation   +307 added lines, -307 removed lines patch added patch discarded remove patch
@@ -18,311 +18,311 @@
 block discarded – undo
18 18
  */
19 19
 class Recipe implements RecipeInterface
20 20
 {
21
-    /**
22
-     * A default Recipe to use if none is specified for a class
23
-     */
24
-    const DEFAULT_ID = '*';
25
-
26
-    /**
27
-     * Identifier for the entity class to be constructed.
28
-     * Typically a Fully Qualified Class Name
29
-     *
30
-     * @var string $identifier
31
-     */
32
-    private $identifier;
33
-
34
-    /**
35
-     * Fully Qualified Class Name
36
-     *
37
-     * @var string $fqcn
38
-     */
39
-    private $fqcn;
40
-
41
-    /**
42
-     * a dependency class map array
43
-     * If a Recipe is for a single class (or group of classes that shares the EXACT SAME constructor arguments),
44
-     * and that class type hints for an interface, then this property allows you to configure what dependencies
45
-     * get used when instantiating the class.
46
-     * For example:
47
-     *  There's a class called Coffee, and one of its constructor arguments is BeanInterface
48
-     *  There are two implementations of BeanInterface: HonduranBean, and KenyanBean
49
-     *  We want one Coffee object to use HonduranBean for its BeanInterface,
50
-     *  and the 2nd Coffee object to use KenyanBean for its BeanInterface.
51
-     *  To do this, we need to create two Recipes:
52
-     *      one with an identifier of 'HonduranCoffee' using the following ingredients :
53
-     *          array('BeanInterface' => 'HonduranBean')
54
-     *      and the other with an identifier of 'KenyanCoffee' using the following ingredients :
55
-     *          array('BeanInterface' => 'KenyanBean')
56
-     *  Then, whenever the CoffeeShop brews an instance of HonduranCoffee,
57
-     *  an instance of HonduranBean will get injected for the BeanInterface dependency,
58
-     *  and whenever the CoffeeShop brews an instance of KenyanCoffee,
59
-     *  an instance of KenyanBean will get injected for the BeanInterface dependency
60
-     *
61
-     * @var array $ingredients
62
-     */
63
-    private $ingredients = array();
64
-
65
-    /**
66
-     * one of the class constants from CoffeeShop:
67
-     *  CoffeeMaker::BREW_NEW - creates a new instance
68
-     *  CoffeeMaker::BREW_SHARED - creates a shared instance
69
-     *  CoffeeMaker::BREW_LOAD_ONLY - loads but does not instantiate
70
-     *
71
-     * @var string $type
72
-     */
73
-    private $type;
74
-
75
-    /**
76
-     * class name aliases - typically a Fully Qualified Interface that the class implements
77
-     * identifiers passed to the CoffeeShop will be run through the filters to find the correct class name
78
-     *
79
-     * @var array $filters
80
-     */
81
-    private $filters = array();
82
-
83
-    /**
84
-     * array of full server filepaths to files that may contain the class
85
-     *
86
-     * @var array $paths
87
-     */
88
-    private $paths = array();
89
-
90
-
91
-    /**
92
-     * Recipe constructor.
93
-     *
94
-     * @param string $identifier    class identifier, can be an alias, or FQCN, or whatever
95
-     * @param string $fqcn          \Fully\Qualified\ClassName, optional if $identifier is FQCN
96
-     * @param array  $ingredients   array of dependencies that can not be resolved automatically,
97
-     *                              used for resolving concrete classes for type hinted interfaces
98
-     *                              for the dependencies of THIS class
99
-     * @param string $type          recipe type: one of the class constants on
100
-     *                              \EventEspresso\core\services\container\CoffeeMaker
101
-     * @param array  $filters       array of class aliases, or class interfaces
102
-     *                              this works somewhat opposite to the $ingredients array above,
103
-     *                              in that this array specifies interfaces or aliases
104
-     *                              that this Recipe can be used for when resolving OTHER class's dependencies
105
-     * @param array  $paths         if class can not be loaded via PSR-4 autoloading,
106
-     *                              then supply a filepath, or array of filepaths, so that it can be included
107
-     * @throws InvalidIdentifierException
108
-     * @throws RuntimeException
109
-     * @throws InvalidInterfaceException
110
-     * @throws InvalidClassException
111
-     * @throws InvalidDataTypeException
112
-     */
113
-    public function __construct(
114
-        $identifier,
115
-        $fqcn = '',
116
-        array $filters = array(),
117
-        array $ingredients = array(),
118
-        $type = CoffeeMaker::BREW_NEW,
119
-        array $paths = array()
120
-    ) {
121
-        $this->setIdentifier($identifier);
122
-        $this->setFilters($filters);
123
-        $this->setIngredients($ingredients);
124
-        $this->setType($type);
125
-        $this->setPaths($paths);
126
-        $this->setFqcn($fqcn);
127
-    }
128
-
129
-
130
-    /**
131
-     * @return string
132
-     */
133
-    public function identifier()
134
-    {
135
-        return $this->identifier;
136
-    }
137
-
138
-
139
-    /**
140
-     * @return string
141
-     */
142
-    public function fqcn()
143
-    {
144
-        return $this->fqcn;
145
-    }
146
-
147
-
148
-    /**
149
-     * @return array
150
-     */
151
-    public function filters()
152
-    {
153
-        return $this->filters;
154
-    }
155
-
156
-
157
-    /**
158
-     * @return array
159
-     */
160
-    public function ingredients()
161
-    {
162
-        return $this->ingredients;
163
-    }
164
-
165
-
166
-    /**
167
-     * @return string
168
-     */
169
-    public function type()
170
-    {
171
-        return $this->type;
172
-    }
173
-
174
-
175
-    /**
176
-     * @return array
177
-     */
178
-    public function paths()
179
-    {
180
-        return $this->paths;
181
-    }
182
-
183
-
184
-    /**
185
-     * @param  string $identifier Identifier for the entity class that the Recipe applies to
186
-     *                            Typically a Fully Qualified Class Name
187
-     * @throws InvalidIdentifierException
188
-     */
189
-    public function setIdentifier($identifier)
190
-    {
191
-        if (! is_string($identifier) || empty($identifier)) {
192
-            throw new InvalidIdentifierException(
193
-                is_object($identifier) ? get_class($identifier) : gettype($identifier),
194
-                esc_html__('class identifier (typically a \Fully\Qualified\ClassName)', 'event_espresso')
195
-            );
196
-        }
197
-        $this->identifier = $identifier;
198
-    }
199
-
200
-
201
-    /**
202
-     * Ensures incoming string is a valid Fully Qualified Class Name,
203
-     * except if this is the default wildcard Recipe ( * ),
204
-     * or it's NOT an actual FQCN because the Recipe is using filepaths
205
-     * for classes that are not PSR-4 compatible
206
-     * PLZ NOTE:
207
-     *  Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not,
208
-     *  therefore you should always call Recipe::setPaths() before Recipe::setFqcn()
209
-     *
210
-     * @param string $fqcn
211
-     * @throws InvalidDataTypeException
212
-     * @throws InvalidClassException
213
-     * @throws InvalidInterfaceException
214
-     */
215
-    public function setFqcn($fqcn)
216
-    {
217
-        $fqcn = ! empty($fqcn) ? $fqcn : $this->identifier;
218
-        if (! is_string($fqcn)) {
219
-            throw new InvalidDataTypeException(
220
-                '$fqcn',
221
-                is_object($fqcn) ? get_class($fqcn) : gettype($fqcn),
222
-                esc_html__('string (Fully\Qualified\ClassName)', 'event_espresso')
223
-            );
224
-        }
225
-        $fqcn = ltrim($fqcn, '\\');
226
-        if (
227
-            $fqcn !== Recipe::DEFAULT_ID
228
-            && ! empty($fqcn)
229
-            && empty($this->paths)
230
-            && ! (class_exists($fqcn) || interface_exists($fqcn))
231
-        ) {
232
-            throw new InvalidClassException($fqcn);
233
-        }
234
-        $this->fqcn = $fqcn;
235
-    }
236
-
237
-
238
-    /**
239
-     * @param array $ingredients    an array of dependencies where keys are the aliases and values are the FQCNs
240
-     *                              example:
241
-     *                              array( 'ClassInterface' => 'Fully\Qualified\ClassName' )
242
-     * @throws InvalidDataTypeException
243
-     */
244
-    public function setIngredients(array $ingredients)
245
-    {
246
-        if (empty($ingredients)) {
247
-            return;
248
-        }
249
-        if (! is_array($ingredients)) {
250
-            throw new InvalidDataTypeException(
251
-                '$ingredients',
252
-                is_object($ingredients) ? get_class($ingredients) : gettype($ingredients),
253
-                esc_html__('array of class dependencies', 'event_espresso')
254
-            );
255
-        }
256
-        $this->ingredients = array_merge($this->ingredients, $ingredients);
257
-    }
258
-
259
-
260
-    /**
261
-     * @param string $type one of the class constants returned from CoffeeMaker::getTypes()
262
-     * @throws InvalidIdentifierException
263
-     */
264
-    public function setType($type = CoffeeMaker::BREW_NEW)
265
-    {
266
-        $this->type = CoffeeMaker::validateType($type);
267
-    }
268
-
269
-
270
-    /**
271
-     * @param array $filters    an array of filters where keys are the aliases and values are the FQCNs
272
-     *                          example:
273
-     *                          array( 'ClassInterface' => 'Fully\Qualified\ClassName' )
274
-     * @throws InvalidDataTypeException
275
-     */
276
-    public function setFilters(array $filters)
277
-    {
278
-        if (empty($filters)) {
279
-            return;
280
-        }
281
-        if (! is_array($filters)) {
282
-            throw new InvalidDataTypeException(
283
-                '$filters',
284
-                is_object($filters) ? get_class($filters) : gettype($filters),
285
-                esc_html__('array of class aliases', 'event_espresso')
286
-            );
287
-        }
288
-        $this->filters = array_merge($this->filters, $filters);
289
-    }
290
-
291
-
292
-    /**
293
-     * Ensures incoming paths is a valid filepath, or array of valid filepaths,
294
-     * and merges them in with any existing filepaths
295
-     * PLZ NOTE:
296
-     *  Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not,
297
-     *  therefore you should always call Recipe::setPaths() before Recipe::setFqcn()
298
-     *
299
-     * @param string|array $paths
300
-     * @throws RuntimeException
301
-     * @throws InvalidDataTypeException
302
-     */
303
-    public function setPaths($paths = array())
304
-    {
305
-        if (empty($paths)) {
306
-            return;
307
-        }
308
-        if (! (is_string($paths) || is_array($paths))) {
309
-            throw new InvalidDataTypeException(
310
-                '$path',
311
-                is_object($paths) ? get_class($paths) : gettype($paths),
312
-                esc_html__('string or array of strings (full server filepath(s))', 'event_espresso')
313
-            );
314
-        }
315
-        $paths = (array) $paths;
316
-        foreach ($paths as $path) {
317
-            if (strpos($path, '*') === false && ! is_readable($path)) {
318
-                throw new RuntimeException(
319
-                    sprintf(
320
-                        esc_html__('The following filepath is not readable: "%1$s"', 'event_espresso'),
321
-                        $path
322
-                    )
323
-                );
324
-            }
325
-        }
326
-        $this->paths = array_merge($this->paths, $paths);
327
-    }
21
+	/**
22
+	 * A default Recipe to use if none is specified for a class
23
+	 */
24
+	const DEFAULT_ID = '*';
25
+
26
+	/**
27
+	 * Identifier for the entity class to be constructed.
28
+	 * Typically a Fully Qualified Class Name
29
+	 *
30
+	 * @var string $identifier
31
+	 */
32
+	private $identifier;
33
+
34
+	/**
35
+	 * Fully Qualified Class Name
36
+	 *
37
+	 * @var string $fqcn
38
+	 */
39
+	private $fqcn;
40
+
41
+	/**
42
+	 * a dependency class map array
43
+	 * If a Recipe is for a single class (or group of classes that shares the EXACT SAME constructor arguments),
44
+	 * and that class type hints for an interface, then this property allows you to configure what dependencies
45
+	 * get used when instantiating the class.
46
+	 * For example:
47
+	 *  There's a class called Coffee, and one of its constructor arguments is BeanInterface
48
+	 *  There are two implementations of BeanInterface: HonduranBean, and KenyanBean
49
+	 *  We want one Coffee object to use HonduranBean for its BeanInterface,
50
+	 *  and the 2nd Coffee object to use KenyanBean for its BeanInterface.
51
+	 *  To do this, we need to create two Recipes:
52
+	 *      one with an identifier of 'HonduranCoffee' using the following ingredients :
53
+	 *          array('BeanInterface' => 'HonduranBean')
54
+	 *      and the other with an identifier of 'KenyanCoffee' using the following ingredients :
55
+	 *          array('BeanInterface' => 'KenyanBean')
56
+	 *  Then, whenever the CoffeeShop brews an instance of HonduranCoffee,
57
+	 *  an instance of HonduranBean will get injected for the BeanInterface dependency,
58
+	 *  and whenever the CoffeeShop brews an instance of KenyanCoffee,
59
+	 *  an instance of KenyanBean will get injected for the BeanInterface dependency
60
+	 *
61
+	 * @var array $ingredients
62
+	 */
63
+	private $ingredients = array();
64
+
65
+	/**
66
+	 * one of the class constants from CoffeeShop:
67
+	 *  CoffeeMaker::BREW_NEW - creates a new instance
68
+	 *  CoffeeMaker::BREW_SHARED - creates a shared instance
69
+	 *  CoffeeMaker::BREW_LOAD_ONLY - loads but does not instantiate
70
+	 *
71
+	 * @var string $type
72
+	 */
73
+	private $type;
74
+
75
+	/**
76
+	 * class name aliases - typically a Fully Qualified Interface that the class implements
77
+	 * identifiers passed to the CoffeeShop will be run through the filters to find the correct class name
78
+	 *
79
+	 * @var array $filters
80
+	 */
81
+	private $filters = array();
82
+
83
+	/**
84
+	 * array of full server filepaths to files that may contain the class
85
+	 *
86
+	 * @var array $paths
87
+	 */
88
+	private $paths = array();
89
+
90
+
91
+	/**
92
+	 * Recipe constructor.
93
+	 *
94
+	 * @param string $identifier    class identifier, can be an alias, or FQCN, or whatever
95
+	 * @param string $fqcn          \Fully\Qualified\ClassName, optional if $identifier is FQCN
96
+	 * @param array  $ingredients   array of dependencies that can not be resolved automatically,
97
+	 *                              used for resolving concrete classes for type hinted interfaces
98
+	 *                              for the dependencies of THIS class
99
+	 * @param string $type          recipe type: one of the class constants on
100
+	 *                              \EventEspresso\core\services\container\CoffeeMaker
101
+	 * @param array  $filters       array of class aliases, or class interfaces
102
+	 *                              this works somewhat opposite to the $ingredients array above,
103
+	 *                              in that this array specifies interfaces or aliases
104
+	 *                              that this Recipe can be used for when resolving OTHER class's dependencies
105
+	 * @param array  $paths         if class can not be loaded via PSR-4 autoloading,
106
+	 *                              then supply a filepath, or array of filepaths, so that it can be included
107
+	 * @throws InvalidIdentifierException
108
+	 * @throws RuntimeException
109
+	 * @throws InvalidInterfaceException
110
+	 * @throws InvalidClassException
111
+	 * @throws InvalidDataTypeException
112
+	 */
113
+	public function __construct(
114
+		$identifier,
115
+		$fqcn = '',
116
+		array $filters = array(),
117
+		array $ingredients = array(),
118
+		$type = CoffeeMaker::BREW_NEW,
119
+		array $paths = array()
120
+	) {
121
+		$this->setIdentifier($identifier);
122
+		$this->setFilters($filters);
123
+		$this->setIngredients($ingredients);
124
+		$this->setType($type);
125
+		$this->setPaths($paths);
126
+		$this->setFqcn($fqcn);
127
+	}
128
+
129
+
130
+	/**
131
+	 * @return string
132
+	 */
133
+	public function identifier()
134
+	{
135
+		return $this->identifier;
136
+	}
137
+
138
+
139
+	/**
140
+	 * @return string
141
+	 */
142
+	public function fqcn()
143
+	{
144
+		return $this->fqcn;
145
+	}
146
+
147
+
148
+	/**
149
+	 * @return array
150
+	 */
151
+	public function filters()
152
+	{
153
+		return $this->filters;
154
+	}
155
+
156
+
157
+	/**
158
+	 * @return array
159
+	 */
160
+	public function ingredients()
161
+	{
162
+		return $this->ingredients;
163
+	}
164
+
165
+
166
+	/**
167
+	 * @return string
168
+	 */
169
+	public function type()
170
+	{
171
+		return $this->type;
172
+	}
173
+
174
+
175
+	/**
176
+	 * @return array
177
+	 */
178
+	public function paths()
179
+	{
180
+		return $this->paths;
181
+	}
182
+
183
+
184
+	/**
185
+	 * @param  string $identifier Identifier for the entity class that the Recipe applies to
186
+	 *                            Typically a Fully Qualified Class Name
187
+	 * @throws InvalidIdentifierException
188
+	 */
189
+	public function setIdentifier($identifier)
190
+	{
191
+		if (! is_string($identifier) || empty($identifier)) {
192
+			throw new InvalidIdentifierException(
193
+				is_object($identifier) ? get_class($identifier) : gettype($identifier),
194
+				esc_html__('class identifier (typically a \Fully\Qualified\ClassName)', 'event_espresso')
195
+			);
196
+		}
197
+		$this->identifier = $identifier;
198
+	}
199
+
200
+
201
+	/**
202
+	 * Ensures incoming string is a valid Fully Qualified Class Name,
203
+	 * except if this is the default wildcard Recipe ( * ),
204
+	 * or it's NOT an actual FQCN because the Recipe is using filepaths
205
+	 * for classes that are not PSR-4 compatible
206
+	 * PLZ NOTE:
207
+	 *  Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not,
208
+	 *  therefore you should always call Recipe::setPaths() before Recipe::setFqcn()
209
+	 *
210
+	 * @param string $fqcn
211
+	 * @throws InvalidDataTypeException
212
+	 * @throws InvalidClassException
213
+	 * @throws InvalidInterfaceException
214
+	 */
215
+	public function setFqcn($fqcn)
216
+	{
217
+		$fqcn = ! empty($fqcn) ? $fqcn : $this->identifier;
218
+		if (! is_string($fqcn)) {
219
+			throw new InvalidDataTypeException(
220
+				'$fqcn',
221
+				is_object($fqcn) ? get_class($fqcn) : gettype($fqcn),
222
+				esc_html__('string (Fully\Qualified\ClassName)', 'event_espresso')
223
+			);
224
+		}
225
+		$fqcn = ltrim($fqcn, '\\');
226
+		if (
227
+			$fqcn !== Recipe::DEFAULT_ID
228
+			&& ! empty($fqcn)
229
+			&& empty($this->paths)
230
+			&& ! (class_exists($fqcn) || interface_exists($fqcn))
231
+		) {
232
+			throw new InvalidClassException($fqcn);
233
+		}
234
+		$this->fqcn = $fqcn;
235
+	}
236
+
237
+
238
+	/**
239
+	 * @param array $ingredients    an array of dependencies where keys are the aliases and values are the FQCNs
240
+	 *                              example:
241
+	 *                              array( 'ClassInterface' => 'Fully\Qualified\ClassName' )
242
+	 * @throws InvalidDataTypeException
243
+	 */
244
+	public function setIngredients(array $ingredients)
245
+	{
246
+		if (empty($ingredients)) {
247
+			return;
248
+		}
249
+		if (! is_array($ingredients)) {
250
+			throw new InvalidDataTypeException(
251
+				'$ingredients',
252
+				is_object($ingredients) ? get_class($ingredients) : gettype($ingredients),
253
+				esc_html__('array of class dependencies', 'event_espresso')
254
+			);
255
+		}
256
+		$this->ingredients = array_merge($this->ingredients, $ingredients);
257
+	}
258
+
259
+
260
+	/**
261
+	 * @param string $type one of the class constants returned from CoffeeMaker::getTypes()
262
+	 * @throws InvalidIdentifierException
263
+	 */
264
+	public function setType($type = CoffeeMaker::BREW_NEW)
265
+	{
266
+		$this->type = CoffeeMaker::validateType($type);
267
+	}
268
+
269
+
270
+	/**
271
+	 * @param array $filters    an array of filters where keys are the aliases and values are the FQCNs
272
+	 *                          example:
273
+	 *                          array( 'ClassInterface' => 'Fully\Qualified\ClassName' )
274
+	 * @throws InvalidDataTypeException
275
+	 */
276
+	public function setFilters(array $filters)
277
+	{
278
+		if (empty($filters)) {
279
+			return;
280
+		}
281
+		if (! is_array($filters)) {
282
+			throw new InvalidDataTypeException(
283
+				'$filters',
284
+				is_object($filters) ? get_class($filters) : gettype($filters),
285
+				esc_html__('array of class aliases', 'event_espresso')
286
+			);
287
+		}
288
+		$this->filters = array_merge($this->filters, $filters);
289
+	}
290
+
291
+
292
+	/**
293
+	 * Ensures incoming paths is a valid filepath, or array of valid filepaths,
294
+	 * and merges them in with any existing filepaths
295
+	 * PLZ NOTE:
296
+	 *  Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not,
297
+	 *  therefore you should always call Recipe::setPaths() before Recipe::setFqcn()
298
+	 *
299
+	 * @param string|array $paths
300
+	 * @throws RuntimeException
301
+	 * @throws InvalidDataTypeException
302
+	 */
303
+	public function setPaths($paths = array())
304
+	{
305
+		if (empty($paths)) {
306
+			return;
307
+		}
308
+		if (! (is_string($paths) || is_array($paths))) {
309
+			throw new InvalidDataTypeException(
310
+				'$path',
311
+				is_object($paths) ? get_class($paths) : gettype($paths),
312
+				esc_html__('string or array of strings (full server filepath(s))', 'event_espresso')
313
+			);
314
+		}
315
+		$paths = (array) $paths;
316
+		foreach ($paths as $path) {
317
+			if (strpos($path, '*') === false && ! is_readable($path)) {
318
+				throw new RuntimeException(
319
+					sprintf(
320
+						esc_html__('The following filepath is not readable: "%1$s"', 'event_espresso'),
321
+						$path
322
+					)
323
+				);
324
+			}
325
+		}
326
+		$this->paths = array_merge($this->paths, $paths);
327
+	}
328 328
 }
Please login to merge, or discard this patch.