Completed
Branch FET/extract-activation-detecti... (285969)
by
unknown
11:10 queued 08:02
created
core/data_migration_scripts/EE_DMS_Core_4_9_0.dms.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -9,12 +9,12 @@  discard block
 block discarded – undo
9 9
 // unfortunately, this needs to be done upon INCLUSION of this file,
10 10
 // instead of construction, because it only gets constructed on first page load
11 11
 // (all other times it gets resurrected from a wordpress option)
12
-$stages = glob(EE_CORE . 'data_migration_scripts/4_9_0_stages/*');
12
+$stages = glob(EE_CORE.'data_migration_scripts/4_9_0_stages/*');
13 13
 $class_to_filepath = array();
14 14
 foreach ($stages as $filepath) {
15 15
     $matches = array();
16 16
     preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches);
17
-    $class_to_filepath[ $matches[1] ] = $filepath;
17
+    $class_to_filepath[$matches[1]] = $filepath;
18 18
 }
19 19
 // give addons a chance to autoload their stages too
20 20
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_9_0__autoloaded_stages', $class_to_filepath);
@@ -65,10 +65,10 @@  discard block
 block discarded – undo
65 65
         if (version_compare($version_string, '4.9.0.decaf', '<') && version_compare($version_string, '4.8.0.decaf', '>=')) {
66 66
             //          echo "$version_string can be migrated from";
67 67
             return true;
68
-        } elseif (! $version_string) {
68
+        } elseif ( ! $version_string) {
69 69
             //          echo "no version string provided: $version_string";
70 70
             // no version string provided... this must be pre 4.3
71
-            return false;// changed mind. dont want people thinking they should migrate yet because they cant
71
+            return false; // changed mind. dont want people thinking they should migrate yet because they cant
72 72
         } else {
73 73
             //          echo "$version_string doesnt apply";
74 74
             return false;
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function schema_changes_before_migration()
84 84
     {
85
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
85
+        require_once(EE_HELPERS.'EEH_Activation.helper.php');
86 86
         $now_in_mysql = current_time('mysql', true);
87 87
         $table_name = 'esp_answer';
88 88
         $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
Please login to merge, or discard this patch.
Indentation   +310 added lines, -310 removed lines patch added patch discarded remove patch
@@ -12,9 +12,9 @@  discard block
 block discarded – undo
12 12
 $stages = glob(EE_CORE . 'data_migration_scripts/4_9_0_stages/*');
13 13
 $class_to_filepath = array();
14 14
 foreach ($stages as $filepath) {
15
-    $matches = array();
16
-    preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches);
17
-    $class_to_filepath[ $matches[1] ] = $filepath;
15
+	$matches = array();
16
+	preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches);
17
+	$class_to_filepath[ $matches[1] ] = $filepath;
18 18
 }
19 19
 // give addons a chance to autoload their stages too
20 20
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_9_0__autoloaded_stages', $class_to_filepath);
@@ -33,68 +33,68 @@  discard block
 block discarded – undo
33 33
  */
34 34
 class EE_DMS_Core_4_9_0 extends EE_Data_Migration_Script_Base
35 35
 {
36
-    /**
37
-     * return EE_DMS_Core_4_9_0
38
-     *
39
-     * @param TableManager  $table_manager
40
-     * @param TableAnalysis $table_analysis
41
-     */
42
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
43
-    {
44
-        $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso");
45
-        $this->_priority = 10;
46
-        $this->_migration_stages = array(
47
-            new EE_DMS_4_9_0_Email_System_Question(),
48
-            new EE_DMS_4_9_0_Answers_With_No_Registration(),
49
-        );
50
-        parent::__construct($table_manager, $table_analysis);
51
-    }
36
+	/**
37
+	 * return EE_DMS_Core_4_9_0
38
+	 *
39
+	 * @param TableManager  $table_manager
40
+	 * @param TableAnalysis $table_analysis
41
+	 */
42
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
43
+	{
44
+		$this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso");
45
+		$this->_priority = 10;
46
+		$this->_migration_stages = array(
47
+			new EE_DMS_4_9_0_Email_System_Question(),
48
+			new EE_DMS_4_9_0_Answers_With_No_Registration(),
49
+		);
50
+		parent::__construct($table_manager, $table_analysis);
51
+	}
52 52
 
53 53
 
54 54
 
55
-    /**
56
-     * Whether to migrate or not.
57
-     *
58
-     * @param array $version_array
59
-     * @return bool
60
-     */
61
-    public function can_migrate_from_version($version_array)
62
-    {
63
-        $version_string = $version_array['Core'];
64
-        if (version_compare($version_string, '4.9.0.decaf', '<') && version_compare($version_string, '4.8.0.decaf', '>=')) {
65
-            //          echo "$version_string can be migrated from";
66
-            return true;
67
-        } elseif (! $version_string) {
68
-            //          echo "no version string provided: $version_string";
69
-            // no version string provided... this must be pre 4.3
70
-            return false;// changed mind. dont want people thinking they should migrate yet because they cant
71
-        } else {
72
-            //          echo "$version_string doesnt apply";
73
-            return false;
74
-        }
75
-    }
55
+	/**
56
+	 * Whether to migrate or not.
57
+	 *
58
+	 * @param array $version_array
59
+	 * @return bool
60
+	 */
61
+	public function can_migrate_from_version($version_array)
62
+	{
63
+		$version_string = $version_array['Core'];
64
+		if (version_compare($version_string, '4.9.0.decaf', '<') && version_compare($version_string, '4.8.0.decaf', '>=')) {
65
+			//          echo "$version_string can be migrated from";
66
+			return true;
67
+		} elseif (! $version_string) {
68
+			//          echo "no version string provided: $version_string";
69
+			// no version string provided... this must be pre 4.3
70
+			return false;// changed mind. dont want people thinking they should migrate yet because they cant
71
+		} else {
72
+			//          echo "$version_string doesnt apply";
73
+			return false;
74
+		}
75
+	}
76 76
 
77 77
 
78 78
 
79
-    /**
80
-     * @return bool
81
-     */
82
-    public function schema_changes_before_migration()
83
-    {
84
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
85
-        $now_in_mysql = current_time('mysql', true);
86
-        $table_name = 'esp_answer';
87
-        $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
79
+	/**
80
+	 * @return bool
81
+	 */
82
+	public function schema_changes_before_migration()
83
+	{
84
+		require_once(EE_HELPERS . 'EEH_Activation.helper.php');
85
+		$now_in_mysql = current_time('mysql', true);
86
+		$table_name = 'esp_answer';
87
+		$sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
88 88
 					REG_ID int(10) unsigned NOT NULL,
89 89
 					QST_ID int(10) unsigned NOT NULL,
90 90
 					ANS_value text NOT NULL,
91 91
 					PRIMARY KEY  (ANS_ID),
92 92
 					KEY REG_ID (REG_ID),
93 93
 					KEY QST_ID (QST_ID)";
94
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
95
-        $table_name = 'esp_attendee_meta';
96
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email');
97
-        $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
94
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
95
+		$table_name = 'esp_attendee_meta';
96
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email');
97
+		$sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
98 98
 				ATT_ID bigint(20) unsigned NOT NULL,
99 99
 				ATT_fname varchar(45) NOT NULL,
100 100
 				ATT_lname varchar(45) NOT NULL,
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
 				KEY ATT_email (ATT_email(191)),
112 112
 				KEY ATT_lname (ATT_lname),
113 113
 				KEY ATT_fname (ATT_fname)";
114
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
115
-        $table_name = 'esp_checkin';
116
-        $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
114
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
115
+		$table_name = 'esp_checkin';
116
+		$sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
117 117
 				REG_ID int(10) unsigned NOT NULL,
118 118
 				DTT_ID int(10) unsigned NOT NULL,
119 119
 				CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
 				PRIMARY KEY  (CHK_ID),
122 122
 				KEY REG_ID (REG_ID),
123 123
 				KEY DTT_ID (DTT_ID)";
124
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
125
-        $table_name = 'esp_country';
126
-        $sql = "CNT_ISO varchar(2) NOT NULL,
124
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
125
+		$table_name = 'esp_country';
126
+		$sql = "CNT_ISO varchar(2) NOT NULL,
127 127
 				CNT_ISO3 varchar(3) NOT NULL,
128 128
 				RGN_ID tinyint(3) unsigned DEFAULT NULL,
129 129
 				CNT_name varchar(45) NOT NULL,
@@ -139,29 +139,29 @@  discard block
 block discarded – undo
139 139
 				CNT_is_EU tinyint(1) DEFAULT '0',
140 140
 				CNT_active tinyint(1) DEFAULT '0',
141 141
 				PRIMARY KEY  (CNT_ISO)";
142
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
143
-        $table_name = 'esp_currency';
144
-        $sql = "CUR_code varchar(6) NOT NULL,
142
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
143
+		$table_name = 'esp_currency';
144
+		$sql = "CUR_code varchar(6) NOT NULL,
145 145
 				CUR_single varchar(45) DEFAULT 'dollar',
146 146
 				CUR_plural varchar(45) DEFAULT 'dollars',
147 147
 				CUR_sign varchar(45) DEFAULT '$',
148 148
 				CUR_dec_plc varchar(1) NOT NULL DEFAULT '2',
149 149
 				CUR_active tinyint(1) DEFAULT '0',
150 150
 				PRIMARY KEY  (CUR_code)";
151
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
152
-        // note: although this table is no longer in use,
153
-        // it hasn't been removed because then queries to the model will have errors.
154
-        // but you should expect this table and its corresponding model to be removed in
155
-        // the next few months
156
-        $table_name = 'esp_currency_payment_method';
157
-        $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT,
151
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
152
+		// note: although this table is no longer in use,
153
+		// it hasn't been removed because then queries to the model will have errors.
154
+		// but you should expect this table and its corresponding model to be removed in
155
+		// the next few months
156
+		$table_name = 'esp_currency_payment_method';
157
+		$sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT,
158 158
 				CUR_code varchar(6) NOT NULL,
159 159
 				PMD_ID int(11) NOT NULL,
160 160
 				PRIMARY KEY  (CPM_ID),
161 161
 				KEY PMD_ID (PMD_ID)";
162
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
163
-        $table_name = 'esp_datetime';
164
-        $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
162
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
163
+		$table_name = 'esp_datetime';
164
+		$sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
165 165
 				EVT_ID bigint(20) unsigned NOT NULL,
166 166
 				DTT_name varchar(255) NOT NULL DEFAULT '',
167 167
 				DTT_description text NOT NULL,
@@ -178,25 +178,25 @@  discard block
 block discarded – undo
178 178
 				KEY DTT_EVT_start (DTT_EVT_start),
179 179
 				KEY EVT_ID (EVT_ID),
180 180
 				KEY DTT_is_primary (DTT_is_primary)";
181
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
182
-        $table_name = "esp_datetime_ticket";
183
-        $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
181
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
182
+		$table_name = "esp_datetime_ticket";
183
+		$sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
184 184
 				DTT_ID int(10) unsigned NOT NULL,
185 185
 				TKT_ID int(10) unsigned NOT NULL,
186 186
 				PRIMARY KEY  (DTK_ID),
187 187
 				KEY DTT_ID (DTT_ID),
188 188
 				KEY TKT_ID (TKT_ID)";
189
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
190
-        $table_name = 'esp_event_message_template';
191
-        $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
189
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
190
+		$table_name = 'esp_event_message_template';
191
+		$sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
192 192
 				EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0,
193 193
 				GRP_ID int(10) unsigned NOT NULL DEFAULT 0,
194 194
 				PRIMARY KEY  (EMT_ID),
195 195
 				KEY EVT_ID (EVT_ID),
196 196
 				KEY GRP_ID (GRP_ID)";
197
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
198
-        $table_name = 'esp_event_meta';
199
-        $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
197
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
198
+		$table_name = 'esp_event_meta';
199
+		$sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
200 200
 				EVT_ID bigint(20) unsigned NOT NULL,
201 201
 				EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1,
202 202
 				EVT_display_ticket_selector tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -211,34 +211,34 @@  discard block
 block discarded – undo
211 211
 				EVT_donations tinyint(1) NULL,
212 212
 				PRIMARY KEY  (EVTM_ID),
213 213
 				KEY EVT_ID (EVT_ID)";
214
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
215
-        $table_name = 'esp_event_question_group';
216
-        $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
214
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
215
+		$table_name = 'esp_event_question_group';
216
+		$sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
217 217
 				EVT_ID bigint(20) unsigned NOT NULL,
218 218
 				QSG_ID int(10) unsigned NOT NULL,
219 219
 				EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
220 220
 				PRIMARY KEY  (EQG_ID),
221 221
 				KEY EVT_ID (EVT_ID),
222 222
 				KEY QSG_ID (QSG_ID)";
223
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
224
-        $table_name = 'esp_event_venue';
225
-        $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
223
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
224
+		$table_name = 'esp_event_venue';
225
+		$sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
226 226
 				EVT_ID bigint(20) unsigned NOT NULL,
227 227
 				VNU_ID bigint(20) unsigned NOT NULL,
228 228
 				EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
229 229
 				PRIMARY KEY  (EVV_ID)";
230
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
231
-        $table_name = 'esp_extra_meta';
232
-        $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
230
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
231
+		$table_name = 'esp_extra_meta';
232
+		$sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
233 233
 				OBJ_ID int(11) DEFAULT NULL,
234 234
 				EXM_type varchar(45) DEFAULT NULL,
235 235
 				EXM_key varchar(45) DEFAULT NULL,
236 236
 				EXM_value text,
237 237
 				PRIMARY KEY  (EXM_ID),
238 238
 				KEY EXM_type (EXM_type,OBJ_ID,EXM_key)";
239
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
240
-        $table_name = 'esp_extra_join';
241
-        $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT,
239
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
240
+		$table_name = 'esp_extra_join';
241
+		$sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT,
242 242
 				EXJ_first_model_id varchar(6) NOT NULL,
243 243
 				EXJ_first_model_name varchar(20) NOT NULL,
244 244
 				EXJ_second_model_id varchar(6) NOT NULL,
@@ -246,9 +246,9 @@  discard block
 block discarded – undo
246 246
 				PRIMARY KEY  (EXJ_ID),
247 247
 				KEY first_model (EXJ_first_model_name,EXJ_first_model_id),
248 248
 				KEY second_model (EXJ_second_model_name,EXJ_second_model_id)";
249
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
250
-        $table_name = 'esp_line_item';
251
-        $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
249
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
250
+		$table_name = 'esp_line_item';
251
+		$sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
252 252
 				LIN_code varchar(245) NOT NULL DEFAULT '',
253 253
 				TXN_ID int(11) DEFAULT NULL,
254 254
 				LIN_name varchar(245) NOT NULL DEFAULT '',
@@ -269,11 +269,11 @@  discard block
 block discarded – undo
269 269
 				KEY txn_type_timestamp (TXN_ID,LIN_type,LIN_timestamp),
270 270
 				KEY txn_obj_id_obj_type (TXN_ID,OBJ_ID,OBJ_type),
271 271
 				KEY obj_id_obj_type (OBJ_ID,OBJ_type)";
272
-        $this->_get_table_manager()->dropIndex('esp_line_item', 'TXN_ID');
273
-        $this->_get_table_manager()->dropIndex('esp_line_item', 'LIN_code');
274
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
275
-        $table_name = 'esp_log';
276
-        $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT,
272
+		$this->_get_table_manager()->dropIndex('esp_line_item', 'TXN_ID');
273
+		$this->_get_table_manager()->dropIndex('esp_line_item', 'LIN_code');
274
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
275
+		$table_name = 'esp_log';
276
+		$sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT,
277 277
 				LOG_time datetime DEFAULT NULL,
278 278
 				OBJ_ID varchar(45) DEFAULT NULL,
279 279
 				OBJ_type varchar(45) DEFAULT NULL,
@@ -284,12 +284,12 @@  discard block
 block discarded – undo
284 284
 				KEY LOG_time (LOG_time),
285 285
 				KEY OBJ (OBJ_type,OBJ_ID),
286 286
 				KEY LOG_type (LOG_type)";
287
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
288
-        $table_name = 'esp_message';
289
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to');
290
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from');
291
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject');
292
-        $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
287
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
288
+		$table_name = 'esp_message';
289
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to');
290
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from');
291
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject');
292
+		$sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
293 293
 				GRP_ID int(10) unsigned NULL,
294 294
 				MSG_token varchar(255) NULL,
295 295
 				TXN_ID int(10) unsigned NULL,
@@ -321,18 +321,18 @@  discard block
 block discarded – undo
321 321
 				KEY STS_ID (STS_ID),
322 322
 				KEY MSG_created (MSG_created),
323 323
 				KEY MSG_modified (MSG_modified)";
324
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
325
-        $table_name = 'esp_message_template';
326
-        $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
324
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
325
+		$table_name = 'esp_message_template';
326
+		$sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
327 327
 				GRP_ID int(10) unsigned NOT NULL,
328 328
 				MTP_context varchar(50) NOT NULL,
329 329
 				MTP_template_field varchar(30) NOT NULL,
330 330
 				MTP_content text NOT NULL,
331 331
 				PRIMARY KEY  (MTP_ID),
332 332
 				KEY GRP_ID (GRP_ID)";
333
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
334
-        $table_name = 'esp_message_template_group';
335
-        $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
333
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
334
+		$table_name = 'esp_message_template_group';
335
+		$sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
336 336
 				MTP_user_id int(10) NOT NULL DEFAULT '1',
337 337
 				MTP_name varchar(245) NOT NULL DEFAULT '',
338 338
 				MTP_description varchar(245) NOT NULL DEFAULT '',
@@ -344,9 +344,9 @@  discard block
 block discarded – undo
344 344
 				MTP_is_active tinyint(1) NOT NULL DEFAULT '1',
345 345
 				PRIMARY KEY  (GRP_ID),
346 346
 				KEY MTP_user_id (MTP_user_id)";
347
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
348
-        $table_name = 'esp_payment';
349
-        $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
347
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
348
+		$table_name = 'esp_payment';
349
+		$sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
350 350
 				TXN_ID int(10) unsigned DEFAULT NULL,
351 351
 				STS_ID varchar(3) DEFAULT NULL,
352 352
 				PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
@@ -363,9 +363,9 @@  discard block
 block discarded – undo
363 363
 				PRIMARY KEY  (PAY_ID),
364 364
 				KEY PAY_timestamp (PAY_timestamp),
365 365
 				KEY TXN_ID (TXN_ID)";
366
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
367
-        $table_name = 'esp_payment_method';
368
-        $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT,
366
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
367
+		$table_name = 'esp_payment_method';
368
+		$sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT,
369 369
 				PMD_type varchar(124) DEFAULT NULL,
370 370
 				PMD_name varchar(255) DEFAULT NULL,
371 371
 				PMD_desc text,
@@ -381,24 +381,24 @@  discard block
 block discarded – undo
381 381
 				PRIMARY KEY  (PMD_ID),
382 382
 				UNIQUE KEY PMD_slug_UNIQUE (PMD_slug),
383 383
 				KEY PMD_type (PMD_type)";
384
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
385
-        $table_name = "esp_ticket_price";
386
-        $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
384
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
385
+		$table_name = "esp_ticket_price";
386
+		$sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
387 387
 				TKT_ID int(10) unsigned NOT NULL,
388 388
 				PRC_ID int(10) unsigned NOT NULL,
389 389
 				PRIMARY KEY  (TKP_ID),
390 390
 				KEY TKT_ID (TKT_ID),
391 391
 				KEY PRC_ID (PRC_ID)";
392
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
393
-        $table_name = "esp_ticket_template";
394
-        $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
392
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
393
+		$table_name = "esp_ticket_template";
394
+		$sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
395 395
 				TTM_name varchar(45) NOT NULL,
396 396
 				TTM_description text,
397 397
 				TTM_file varchar(45),
398 398
 				PRIMARY KEY  (TTM_ID)";
399
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
400
-        $table_name = 'esp_question';
401
-        $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
399
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
400
+		$table_name = 'esp_question';
401
+		$sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
402 402
 				QST_display_text text NOT NULL,
403 403
 				QST_admin_label varchar(255) NOT NULL,
404 404
 				QST_system varchar(25) DEFAULT NULL,
@@ -412,18 +412,18 @@  discard block
 block discarded – undo
412 412
 				QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0,
413 413
 				PRIMARY KEY  (QST_ID),
414 414
 				KEY QST_order (QST_order)';
415
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
416
-        $table_name = 'esp_question_group_question';
417
-        $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
415
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
416
+		$table_name = 'esp_question_group_question';
417
+		$sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
418 418
 				QSG_ID int(10) unsigned NOT NULL,
419 419
 				QST_ID int(10) unsigned NOT NULL,
420 420
 				QGQ_order int(10) unsigned NOT NULL DEFAULT 0,
421 421
 				PRIMARY KEY  (QGQ_ID),
422 422
 				KEY QST_ID (QST_ID),
423 423
 				KEY QSG_ID_order (QSG_ID,QGQ_order)";
424
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
425
-        $table_name = 'esp_question_option';
426
-        $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
424
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
425
+		$table_name = 'esp_question_option';
426
+		$sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
427 427
 				QSO_value varchar(255) NOT NULL,
428 428
 				QSO_desc text NOT NULL,
429 429
 				QST_ID int(10) unsigned NOT NULL,
@@ -433,9 +433,9 @@  discard block
 block discarded – undo
433 433
 				PRIMARY KEY  (QSO_ID),
434 434
 				KEY QST_ID (QST_ID),
435 435
 				KEY QSO_order (QSO_order)";
436
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
437
-        $table_name = 'esp_registration';
438
-        $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
436
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
437
+		$table_name = 'esp_registration';
438
+		$sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
439 439
 				EVT_ID bigint(20) unsigned NOT NULL,
440 440
 				ATT_ID bigint(20) unsigned NOT NULL,
441 441
 				TXN_ID int(10) unsigned NOT NULL,
@@ -459,18 +459,18 @@  discard block
 block discarded – undo
459 459
 				KEY TKT_ID (TKT_ID),
460 460
 				KEY EVT_ID (EVT_ID),
461 461
 				KEY STS_ID (STS_ID)";
462
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
463
-        $table_name = 'esp_registration_payment';
464
-        $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
462
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
463
+		$table_name = 'esp_registration_payment';
464
+		$sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
465 465
 					  REG_ID int(10) unsigned NOT NULL,
466 466
 					  PAY_ID int(10) unsigned NULL,
467 467
 					  RPY_amount decimal(12,3) NOT NULL DEFAULT '0.00',
468 468
 					  PRIMARY KEY  (RPY_ID),
469 469
 					  KEY REG_ID (REG_ID),
470 470
 					  KEY PAY_ID (PAY_ID)";
471
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
472
-        $table_name = 'esp_state';
473
-        $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
471
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
472
+		$table_name = 'esp_state';
473
+		$sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
474 474
 				CNT_ISO varchar(2) NOT NULL,
475 475
 				STA_abbrev varchar(24) NOT NULL,
476 476
 				STA_name varchar(100) NOT NULL,
@@ -478,9 +478,9 @@  discard block
 block discarded – undo
478 478
 				PRIMARY KEY  (STA_ID),
479 479
 				KEY STA_abbrev (STA_abbrev),
480 480
 				KEY CNT_ISO (CNT_ISO)";
481
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
482
-        $table_name = 'esp_status';
483
-        $sql = "STS_ID varchar(3) NOT NULL,
481
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
482
+		$table_name = 'esp_status';
483
+		$sql = "STS_ID varchar(3) NOT NULL,
484 484
 				STS_code varchar(45) NOT NULL,
485 485
 				STS_type varchar(45) NOT NULL,
486 486
 				STS_can_edit tinyint(1) NOT NULL DEFAULT 0,
@@ -488,9 +488,9 @@  discard block
 block discarded – undo
488 488
 				STS_open tinyint(1) NOT NULL DEFAULT 1,
489 489
 				UNIQUE KEY STS_ID_UNIQUE (STS_ID),
490 490
 				KEY STS_type (STS_type)";
491
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
492
-        $table_name = 'esp_transaction';
493
-        $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
491
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
492
+		$table_name = 'esp_transaction';
493
+		$sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
494 494
 				TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
495 495
 				TXN_total decimal(12,3) DEFAULT '0.00',
496 496
 				TXN_paid decimal(12,3) NOT NULL DEFAULT '0.00',
@@ -502,9 +502,9 @@  discard block
 block discarded – undo
502 502
 				PRIMARY KEY  (TXN_ID),
503 503
 				KEY TXN_timestamp (TXN_timestamp),
504 504
 				KEY STS_ID (STS_ID)";
505
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
506
-        $table_name = 'esp_venue_meta';
507
-        $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
505
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
506
+		$table_name = 'esp_venue_meta';
507
+		$sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
508 508
 			VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0,
509 509
 			VNU_address varchar(255) DEFAULT NULL,
510 510
 			VNU_address2 varchar(255) DEFAULT NULL,
@@ -523,10 +523,10 @@  discard block
 block discarded – undo
523 523
 			KEY VNU_ID (VNU_ID),
524 524
 			KEY STA_ID (STA_ID),
525 525
 			KEY CNT_ISO (CNT_ISO)";
526
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
527
-        // modified tables
528
-        $table_name = "esp_price";
529
-        $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
526
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
527
+		// modified tables
528
+		$table_name = "esp_price";
529
+		$sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
530 530
 				PRT_ID tinyint(3) unsigned NOT NULL,
531 531
 				PRC_amount decimal(12,3) NOT NULL DEFAULT '0.00',
532 532
 				PRC_name varchar(245) NOT NULL,
@@ -539,9 +539,9 @@  discard block
 block discarded – undo
539 539
 				PRC_parent int(10) unsigned DEFAULT 0,
540 540
 				PRIMARY KEY  (PRC_ID),
541 541
 				KEY PRT_ID (PRT_ID)";
542
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
543
-        $table_name = "esp_price_type";
544
-        $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
542
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
543
+		$table_name = "esp_price_type";
544
+		$sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
545 545
 				PRT_name varchar(45) NOT NULL,
546 546
 				PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1',
547 547
 				PRT_is_percent tinyint(1) NOT NULL DEFAULT '0',
@@ -550,9 +550,9 @@  discard block
 block discarded – undo
550 550
 				PRT_deleted tinyint(1) NOT NULL DEFAULT '0',
551 551
 				UNIQUE KEY PRT_name_UNIQUE (PRT_name),
552 552
 				PRIMARY KEY  (PRT_ID)";
553
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
554
-        $table_name = "esp_ticket";
555
-        $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
553
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
554
+		$table_name = "esp_ticket";
555
+		$sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
556 556
 				TTM_ID int(10) unsigned NOT NULL,
557 557
 				TKT_name varchar(245) NOT NULL DEFAULT '',
558 558
 				TKT_description text NOT NULL,
@@ -575,9 +575,9 @@  discard block
 block discarded – undo
575 575
 				TKT_deleted tinyint(1) NOT NULL DEFAULT '0',
576 576
 				PRIMARY KEY  (TKT_ID),
577 577
 				KEY TKT_start_date (TKT_start_date)";
578
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
579
-        $table_name = 'esp_question_group';
580
-        $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
578
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
579
+		$table_name = 'esp_question_group';
580
+		$sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
581 581
 				QSG_name varchar(255) NOT NULL,
582 582
 				QSG_identifier varchar(100) NOT NULL,
583 583
 				QSG_desc text NULL,
@@ -590,165 +590,165 @@  discard block
 block discarded – undo
590 590
 				PRIMARY KEY  (QSG_ID),
591 591
 				UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier),
592 592
 				KEY QSG_order (QSG_order)';
593
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
594
-        $this->insert_default_data();
595
-        return true;
596
-    }
593
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
594
+		$this->insert_default_data();
595
+		return true;
596
+	}
597 597
 
598
-    /**
599
-     * Inserts default data after parent was called.
600
-     * @since 4.10.0.p
601
-     * @throws EE_Error
602
-     * @throws InvalidArgumentException
603
-     * @throws ReflectionException
604
-     * @throws InvalidDataTypeException
605
-     * @throws InvalidInterfaceException
606
-     */
607
-    public function insert_default_data()
608
-    {
609
-        /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */
610
-        $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
611
-        // (because many need to convert old string states to foreign keys into the states table)
612
-        $script_4_1_defaults->insert_default_states();
613
-        $script_4_1_defaults->insert_default_countries();
614
-        /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */
615
-        $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0');
616
-        $script_4_5_defaults->insert_default_price_types();
617
-        $script_4_5_defaults->insert_default_prices();
618
-        $script_4_5_defaults->insert_default_tickets();
619
-        /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */
620
-        $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0');
621
-        $script_4_6_defaults->add_default_admin_only_payments();
622
-        $script_4_6_defaults->insert_default_currencies();
623
-        /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */
624
-        $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0');
625
-        $script_4_8_defaults->verify_new_countries();
626
-        $script_4_8_defaults->verify_new_currencies();
627
-        $this->verify_db_collations();
628
-        $this->verify_db_collations_again();
629
-    }
598
+	/**
599
+	 * Inserts default data after parent was called.
600
+	 * @since 4.10.0.p
601
+	 * @throws EE_Error
602
+	 * @throws InvalidArgumentException
603
+	 * @throws ReflectionException
604
+	 * @throws InvalidDataTypeException
605
+	 * @throws InvalidInterfaceException
606
+	 */
607
+	public function insert_default_data()
608
+	{
609
+		/** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */
610
+		$script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
611
+		// (because many need to convert old string states to foreign keys into the states table)
612
+		$script_4_1_defaults->insert_default_states();
613
+		$script_4_1_defaults->insert_default_countries();
614
+		/** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */
615
+		$script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0');
616
+		$script_4_5_defaults->insert_default_price_types();
617
+		$script_4_5_defaults->insert_default_prices();
618
+		$script_4_5_defaults->insert_default_tickets();
619
+		/** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */
620
+		$script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0');
621
+		$script_4_6_defaults->add_default_admin_only_payments();
622
+		$script_4_6_defaults->insert_default_currencies();
623
+		/** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */
624
+		$script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0');
625
+		$script_4_8_defaults->verify_new_countries();
626
+		$script_4_8_defaults->verify_new_currencies();
627
+		$this->verify_db_collations();
628
+		$this->verify_db_collations_again();
629
+	}
630 630
 
631 631
 
632 632
 
633
-    /**
634
-     * @return boolean
635
-     */
636
-    public function schema_changes_after_migration()
637
-    {
638
-        return true;
639
-    }
633
+	/**
634
+	 * @return boolean
635
+	 */
636
+	public function schema_changes_after_migration()
637
+	{
638
+		return true;
639
+	}
640 640
 
641 641
 
642 642
 
643
-    public function migration_page_hooks()
644
-    {
645
-    }
643
+	public function migration_page_hooks()
644
+	{
645
+	}
646 646
 
647 647
 
648 648
 
649
-    /**
650
-     * Verify all EE4 models' tables use utf8mb4 collation
651
-     *
652
-     * @return void
653
-     */
654
-    public function verify_db_collations()
655
-    {
656
-        global $wpdb;
657
-        // double-check we haven't already done it or that that the DB doesn't support utf8mb4
658
-        if (
659
-            'utf8mb4' !== $wpdb->charset
660
-            || get_option('ee_verified_db_collations', false)
661
-        ) {
662
-            return;
663
-        }
664
-        // grab tables from each model
665
-        $tables_to_check = array();
666
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
667
-            if (method_exists($model_name, 'instance')) {
668
-                $model_obj = call_user_func(array($model_name, 'instance'));
669
-                if ($model_obj instanceof EEM_Base) {
670
-                    foreach ($model_obj->get_tables() as $table) {
671
-                        if (
672
-                            strpos($table->get_table_name(), 'esp_')
673
-                            && (is_main_site()// for main tables, verify global tables
674
-                                || ! $table->is_global()// if not the main site, then only verify non-global tables (avoid doubling up)
675
-                            )
676
-                            && function_exists('maybe_convert_table_to_utf8mb4')
677
-                        ) {
678
-                            $tables_to_check[] = $table->get_table_name();
679
-                        }
680
-                    }
681
-                }
682
-            }
683
-        }
684
-        // and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active
685
-        // when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead
686
-        // of hard-coding this
687
-        $addon_tables = array(
688
-            // mailchimp
689
-            'esp_event_mailchimp_list_group',
690
-            'esp_event_question_mailchimp_field',
691
-            // multisite
692
-            'esp_blog_meta',
693
-            // people
694
-            'esp_people_to_post',
695
-            // promotions
696
-            'esp_promotion',
697
-            'esp_promotion_object',
698
-        );
699
-        foreach ($addon_tables as $table_name) {
700
-                $tables_to_check[] = $table_name;
701
-        }
702
-        $this->_verify_db_collations_for_tables(array_unique($tables_to_check));
703
-        // ok and now let's remember this was done (without needing to check the db schemas all over again)
704
-        add_option('ee_verified_db_collations', true, null, 'no');
705
-        // seeing how this ran with the fix from 10435, no need to check again
706
-        add_option('ee_verified_db_collations_again', true, null, 'no');
707
-    }
649
+	/**
650
+	 * Verify all EE4 models' tables use utf8mb4 collation
651
+	 *
652
+	 * @return void
653
+	 */
654
+	public function verify_db_collations()
655
+	{
656
+		global $wpdb;
657
+		// double-check we haven't already done it or that that the DB doesn't support utf8mb4
658
+		if (
659
+			'utf8mb4' !== $wpdb->charset
660
+			|| get_option('ee_verified_db_collations', false)
661
+		) {
662
+			return;
663
+		}
664
+		// grab tables from each model
665
+		$tables_to_check = array();
666
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
667
+			if (method_exists($model_name, 'instance')) {
668
+				$model_obj = call_user_func(array($model_name, 'instance'));
669
+				if ($model_obj instanceof EEM_Base) {
670
+					foreach ($model_obj->get_tables() as $table) {
671
+						if (
672
+							strpos($table->get_table_name(), 'esp_')
673
+							&& (is_main_site()// for main tables, verify global tables
674
+								|| ! $table->is_global()// if not the main site, then only verify non-global tables (avoid doubling up)
675
+							)
676
+							&& function_exists('maybe_convert_table_to_utf8mb4')
677
+						) {
678
+							$tables_to_check[] = $table->get_table_name();
679
+						}
680
+					}
681
+				}
682
+			}
683
+		}
684
+		// and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active
685
+		// when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead
686
+		// of hard-coding this
687
+		$addon_tables = array(
688
+			// mailchimp
689
+			'esp_event_mailchimp_list_group',
690
+			'esp_event_question_mailchimp_field',
691
+			// multisite
692
+			'esp_blog_meta',
693
+			// people
694
+			'esp_people_to_post',
695
+			// promotions
696
+			'esp_promotion',
697
+			'esp_promotion_object',
698
+		);
699
+		foreach ($addon_tables as $table_name) {
700
+				$tables_to_check[] = $table_name;
701
+		}
702
+		$this->_verify_db_collations_for_tables(array_unique($tables_to_check));
703
+		// ok and now let's remember this was done (without needing to check the db schemas all over again)
704
+		add_option('ee_verified_db_collations', true, null, 'no');
705
+		// seeing how this ran with the fix from 10435, no need to check again
706
+		add_option('ee_verified_db_collations_again', true, null, 'no');
707
+	}
708 708
 
709 709
 
710 710
 
711
-    /**
712
-     * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435
713
-     * which meant some DB collations might not have been updated
714
-     * @return void
715
-     */
716
-    public function verify_db_collations_again()
717
-    {
718
-        global $wpdb;
719
-        // double-check we haven't already done this or that the DB doesn't support it
720
-        // compare to how WordPress' upgrade_430() function does this check
721
-        if (
722
-            'utf8mb4' !== $wpdb->charset
723
-            || get_option('ee_verified_db_collations_again', false)
724
-        ) {
725
-            return;
726
-        }
727
-        $tables_to_check = array(
728
-            'esp_attendee_meta',
729
-            'esp_message'
730
-        );
731
-        $this->_verify_db_collations_for_tables(array_unique($tables_to_check));
732
-        add_option('ee_verified_db_collations_again', true, null, 'no');
733
-    }
711
+	/**
712
+	 * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435
713
+	 * which meant some DB collations might not have been updated
714
+	 * @return void
715
+	 */
716
+	public function verify_db_collations_again()
717
+	{
718
+		global $wpdb;
719
+		// double-check we haven't already done this or that the DB doesn't support it
720
+		// compare to how WordPress' upgrade_430() function does this check
721
+		if (
722
+			'utf8mb4' !== $wpdb->charset
723
+			|| get_option('ee_verified_db_collations_again', false)
724
+		) {
725
+			return;
726
+		}
727
+		$tables_to_check = array(
728
+			'esp_attendee_meta',
729
+			'esp_message'
730
+		);
731
+		$this->_verify_db_collations_for_tables(array_unique($tables_to_check));
732
+		add_option('ee_verified_db_collations_again', true, null, 'no');
733
+	}
734 734
 
735 735
 
736 736
 
737
-    /**
738
-     * Runs maybe_convert_table_to_utf8mb4 on the specified tables
739
-     * @param $tables_to_check
740
-     * @return boolean true if logic ran, false if it didn't
741
-     */
742
-    protected function _verify_db_collations_for_tables($tables_to_check)
743
-    {
744
-        foreach ($tables_to_check as $table_name) {
745
-            $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name);
746
-            if (
747
-                ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name)
748
-                && $this->_get_table_analysis()->tableExists($table_name)
749
-            ) {
750
-                maybe_convert_table_to_utf8mb4($table_name);
751
-            }
752
-        }
753
-    }
737
+	/**
738
+	 * Runs maybe_convert_table_to_utf8mb4 on the specified tables
739
+	 * @param $tables_to_check
740
+	 * @return boolean true if logic ran, false if it didn't
741
+	 */
742
+	protected function _verify_db_collations_for_tables($tables_to_check)
743
+	{
744
+		foreach ($tables_to_check as $table_name) {
745
+			$table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name);
746
+			if (
747
+				! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name)
748
+				&& $this->_get_table_analysis()->tableExists($table_name)
749
+			) {
750
+				maybe_convert_table_to_utf8mb4($table_name);
751
+			}
752
+		}
753
+	}
754 754
 }
Please login to merge, or discard this patch.
4_6_0_stages/EE_DMS_4_6_0_invoice_settings.dmsstage.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -66,8 +66,8 @@
 block discarded – undo
66 66
     {
67 67
 
68 68
         $templates_relative_path = 'modules/gateways/Invoice/lib/templates/';
69
-        $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true);
70
-        $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true);
69
+        $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path.'invoice_body.template.php', null, false, false, true);
70
+        $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path.'receipt_body.template.php', null, false, false, true);
71 71
         if ($overridden_invoice_body || $overridden_receipt_body) {
72 72
             new PersistentAdminNotice(
73 73
                 'invoice_overriding_templates',
Please login to merge, or discard this patch.
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -27,59 +27,59 @@
 block discarded – undo
27 27
  */
28 28
 class EE_DMS_4_6_0_invoice_settings extends EE_Data_Migration_Script_Stage
29 29
 {
30
-    /**
31
-     * Just initializes the status of the migration
32
-     */
33
-    public function __construct()
34
-    {
35
-        $this->_pretty_name = esc_html__('Update Invoice Settings', 'event_espresso');
36
-        parent::__construct();
37
-    }
30
+	/**
31
+	 * Just initializes the status of the migration
32
+	 */
33
+	public function __construct()
34
+	{
35
+		$this->_pretty_name = esc_html__('Update Invoice Settings', 'event_espresso');
36
+		parent::__construct();
37
+	}
38 38
 
39 39
 
40 40
 
41
-    /**
42
-     * _count_records_to_migrate
43
-     * Counts the records to migrate; the public version may cache it
44
-     *
45
-     * @access protected
46
-     * @return int
47
-     */
48
-    protected function _count_records_to_migrate()
49
-    {
50
-        return 1;
51
-    }
41
+	/**
42
+	 * _count_records_to_migrate
43
+	 * Counts the records to migrate; the public version may cache it
44
+	 *
45
+	 * @access protected
46
+	 * @return int
47
+	 */
48
+	protected function _count_records_to_migrate()
49
+	{
50
+		return 1;
51
+	}
52 52
 
53 53
 
54 54
 
55
-    /**
56
-     *    _migration_step
57
-     *
58
-     * @access protected
59
-     * @param int $num_items
60
-     * @throws EE_Error
61
-     * @return int number of items ACTUALLY migrated
62
-     * @throws InvalidDataTypeException
63
-     */
64
-    protected function _migration_step($num_items = 1)
65
-    {
55
+	/**
56
+	 *    _migration_step
57
+	 *
58
+	 * @access protected
59
+	 * @param int $num_items
60
+	 * @throws EE_Error
61
+	 * @return int number of items ACTUALLY migrated
62
+	 * @throws InvalidDataTypeException
63
+	 */
64
+	protected function _migration_step($num_items = 1)
65
+	{
66 66
 
67
-        $templates_relative_path = 'modules/gateways/Invoice/lib/templates/';
68
-        $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true);
69
-        $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true);
70
-        if ($overridden_invoice_body || $overridden_receipt_body) {
71
-            new PersistentAdminNotice(
72
-                'invoice_overriding_templates',
73
-                esc_html__(
74
-                    'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents (but this will be removed in an upcoming version). We recommend deleting your old Invoice/Receipt templates and using the new messages system. Then modify the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.',
75
-                    'event_espresso'
76
-                ),
77
-                true
78
-            );
79
-        }
67
+		$templates_relative_path = 'modules/gateways/Invoice/lib/templates/';
68
+		$overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true);
69
+		$overridden_receipt_body = EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true);
70
+		if ($overridden_invoice_body || $overridden_receipt_body) {
71
+			new PersistentAdminNotice(
72
+				'invoice_overriding_templates',
73
+				esc_html__(
74
+					'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents (but this will be removed in an upcoming version). We recommend deleting your old Invoice/Receipt templates and using the new messages system. Then modify the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.',
75
+					'event_espresso'
76
+				),
77
+				true
78
+			);
79
+		}
80 80
 
81
-        // regardless of whether it worked or not, we ought to continue the migration
82
-        $this->set_completed();
83
-        return 1;
84
-    }
81
+		// regardless of whether it worked or not, we ought to continue the migration
82
+		$this->set_completed();
83
+		return 1;
84
+	}
85 85
 }
Please login to merge, or discard this patch.
core/EE_Load_Textdomain.core.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -36,19 +36,19 @@  discard block
 block discarded – undo
36 36
     {
37 37
         EE_Load_Textdomain::loadTranslationsForLocale();
38 38
         // now load the textdomain
39
-        if (!empty(EE_Load_Textdomain::$locale)) {
40
-            $github_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-' . EE_Load_Textdomain::$locale . '.mo';
39
+        if ( ! empty(EE_Load_Textdomain::$locale)) {
40
+            $github_mo_path = EE_LANGUAGES_SAFE_DIR.'event_espresso-'.EE_Load_Textdomain::$locale.'.mo';
41 41
             if (is_readable($github_mo_path)) {
42 42
                 load_plugin_textdomain('event_espresso', false, EE_LANGUAGES_SAFE_LOC);
43 43
                 return;
44 44
             }
45
-            $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR . 'event-espresso-4-' . EE_Load_Textdomain::$locale . '.mo';
45
+            $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR.'event-espresso-4-'.EE_Load_Textdomain::$locale.'.mo';
46 46
             if (is_readable($glotpress_mo_path)) {
47 47
                 load_textdomain('event_espresso', $glotpress_mo_path);
48 48
                 return;
49 49
             }
50 50
         }
51
-        load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME) . '/languages/');
51
+        load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME).'/languages/');
52 52
     }
53 53
 
54 54
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
         if (empty(EE_Load_Textdomain::$locale)) {
72 72
             return;
73 73
         }
74
-        $language_check_option_name = 'ee_lang_check_' . EE_Load_Textdomain::$locale . '_' . EVENT_ESPRESSO_VERSION;
74
+        $language_check_option_name = 'ee_lang_check_'.EE_Load_Textdomain::$locale.'_'.EVENT_ESPRESSO_VERSION;
75 75
         // check if language files has already been sideloaded
76 76
         if (get_option($language_check_option_name)) {
77 77
             return;
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
 
82 82
         // load sideloader and sideload the .POT file as this should always be included.
83 83
         $sideloader_args = array(
84
-            '_upload_to'     => EE_PLUGIN_DIR_PATH . 'languages/',
85
-            '_download_from'   => $repo_base_URL . '.pot?raw=true',
84
+            '_upload_to'     => EE_PLUGIN_DIR_PATH.'languages/',
85
+            '_download_from'   => $repo_base_URL.'.pot?raw=true',
86 86
             '_new_file_name' => 'event_espresso.pot',
87 87
         );
88 88
         /** @var EEH_Sideloader $sideloader */
@@ -98,8 +98,8 @@  discard block
 block discarded – undo
98 98
             update_option($language_check_option_name, 1);
99 99
             return;
100 100
         }
101
-        $repo_locale_URL = $repo_base_URL . '-' . EE_Load_Textdomain::$locale;
102
-        $file_name_base = 'event_espresso-' . EE_Load_Textdomain::$locale;
101
+        $repo_locale_URL = $repo_base_URL.'-'.EE_Load_Textdomain::$locale;
102
+        $file_name_base = 'event_espresso-'.EE_Load_Textdomain::$locale;
103 103
 
104 104
         // made it here so let's get the language files from the github repo, first the .mo file
105 105
         $sideloader->set_download_from("{$repo_locale_URL}.mo?raw=true");
Please login to merge, or discard this patch.
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -12,105 +12,105 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Load_Textdomain extends EE_Base
14 14
 {
15
-    /**
16
-     * holds the current lang in WP
17
-     *
18
-     * @var string
19
-     */
20
-    private static $locale;
15
+	/**
16
+	 * holds the current lang in WP
17
+	 *
18
+	 * @var string
19
+	 */
20
+	private static $locale;
21 21
 
22 22
 
23
-    /**
24
-     * this takes care of retrieving a matching textdomain for event espresso for the current WPLANG from EE GitHub
25
-     * repo (if necessary) and then loading it for translations. should only be called in wp plugins_loaded callback
26
-     *
27
-     * @return void
28
-     * @throws EE_Error
29
-     * @throws InvalidArgumentException
30
-     * @throws ReflectionException
31
-     * @throws InvalidDataTypeException
32
-     * @throws InvalidInterfaceException
33
-     */
34
-    public static function load_textdomain()
35
-    {
36
-        EE_Load_Textdomain::loadTranslationsForLocale();
37
-        // now load the textdomain
38
-        if (!empty(EE_Load_Textdomain::$locale)) {
39
-            $github_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-' . EE_Load_Textdomain::$locale . '.mo';
40
-            if (is_readable($github_mo_path)) {
41
-                load_plugin_textdomain('event_espresso', false, EE_LANGUAGES_SAFE_LOC);
42
-                return;
43
-            }
44
-            $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR . 'event-espresso-4-' . EE_Load_Textdomain::$locale . '.mo';
45
-            if (is_readable($glotpress_mo_path)) {
46
-                load_textdomain('event_espresso', $glotpress_mo_path);
47
-                return;
48
-            }
49
-        }
50
-        load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME) . '/languages/');
51
-    }
23
+	/**
24
+	 * this takes care of retrieving a matching textdomain for event espresso for the current WPLANG from EE GitHub
25
+	 * repo (if necessary) and then loading it for translations. should only be called in wp plugins_loaded callback
26
+	 *
27
+	 * @return void
28
+	 * @throws EE_Error
29
+	 * @throws InvalidArgumentException
30
+	 * @throws ReflectionException
31
+	 * @throws InvalidDataTypeException
32
+	 * @throws InvalidInterfaceException
33
+	 */
34
+	public static function load_textdomain()
35
+	{
36
+		EE_Load_Textdomain::loadTranslationsForLocale();
37
+		// now load the textdomain
38
+		if (!empty(EE_Load_Textdomain::$locale)) {
39
+			$github_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-' . EE_Load_Textdomain::$locale . '.mo';
40
+			if (is_readable($github_mo_path)) {
41
+				load_plugin_textdomain('event_espresso', false, EE_LANGUAGES_SAFE_LOC);
42
+				return;
43
+			}
44
+			$glotpress_mo_path = EE_LANGUAGES_SAFE_DIR . 'event-espresso-4-' . EE_Load_Textdomain::$locale . '.mo';
45
+			if (is_readable($glotpress_mo_path)) {
46
+				load_textdomain('event_espresso', $glotpress_mo_path);
47
+				return;
48
+			}
49
+		}
50
+		load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME) . '/languages/');
51
+	}
52 52
 
53 53
 
54
-    /**
55
-     * The purpose of this method is to sideload all of the lang files for EE, this includes the POT file and also the PO/MO files for the given WPLANG locale (if necessary).
56
-     *
57
-     * @access private
58
-     * @static
59
-     * @return void
60
-     * @throws EE_Error
61
-     * @throws InvalidArgumentException
62
-     * @throws ReflectionException
63
-     * @throws InvalidDataTypeException
64
-     * @throws InvalidInterfaceException
65
-     */
66
-    private static function loadTranslationsForLocale()
67
-    {
68
-        EE_Load_Textdomain::$locale = get_locale();
69
-        // can't download a language file if a language isn't set <taps temple>
70
-        if (empty(EE_Load_Textdomain::$locale)) {
71
-            return;
72
-        }
73
-        $language_check_option_name = 'ee_lang_check_' . EE_Load_Textdomain::$locale . '_' . EVENT_ESPRESSO_VERSION;
74
-        // check if language files has already been sideloaded
75
-        if (get_option($language_check_option_name)) {
76
-            return;
77
-        }
54
+	/**
55
+	 * The purpose of this method is to sideload all of the lang files for EE, this includes the POT file and also the PO/MO files for the given WPLANG locale (if necessary).
56
+	 *
57
+	 * @access private
58
+	 * @static
59
+	 * @return void
60
+	 * @throws EE_Error
61
+	 * @throws InvalidArgumentException
62
+	 * @throws ReflectionException
63
+	 * @throws InvalidDataTypeException
64
+	 * @throws InvalidInterfaceException
65
+	 */
66
+	private static function loadTranslationsForLocale()
67
+	{
68
+		EE_Load_Textdomain::$locale = get_locale();
69
+		// can't download a language file if a language isn't set <taps temple>
70
+		if (empty(EE_Load_Textdomain::$locale)) {
71
+			return;
72
+		}
73
+		$language_check_option_name = 'ee_lang_check_' . EE_Load_Textdomain::$locale . '_' . EVENT_ESPRESSO_VERSION;
74
+		// check if language files has already been sideloaded
75
+		if (get_option($language_check_option_name)) {
76
+			return;
77
+		}
78 78
 
79
-        $repo_base_URL = 'https://github.com/eventespresso/languages-ee4/blob/master/event_espresso';
79
+		$repo_base_URL = 'https://github.com/eventespresso/languages-ee4/blob/master/event_espresso';
80 80
 
81
-        // load sideloader and sideload the .POT file as this should always be included.
82
-        $sideloader_args = array(
83
-            '_upload_to'     => EE_PLUGIN_DIR_PATH . 'languages/',
84
-            '_download_from'   => $repo_base_URL . '.pot?raw=true',
85
-            '_new_file_name' => 'event_espresso.pot',
86
-        );
87
-        /** @var EEH_Sideloader $sideloader */
88
-        $sideloader = EE_Registry::instance()->load_helper('Sideloader', $sideloader_args, false);
89
-        // sideload the .POT file only for main site of the network, or if not running Multisite.
90
-        if (is_main_site()) {
91
-            $sideloader->sideload();
92
-        }
81
+		// load sideloader and sideload the .POT file as this should always be included.
82
+		$sideloader_args = array(
83
+			'_upload_to'     => EE_PLUGIN_DIR_PATH . 'languages/',
84
+			'_download_from'   => $repo_base_URL . '.pot?raw=true',
85
+			'_new_file_name' => 'event_espresso.pot',
86
+		);
87
+		/** @var EEH_Sideloader $sideloader */
88
+		$sideloader = EE_Registry::instance()->load_helper('Sideloader', $sideloader_args, false);
89
+		// sideload the .POT file only for main site of the network, or if not running Multisite.
90
+		if (is_main_site()) {
91
+			$sideloader->sideload();
92
+		}
93 93
 
94
-        // if locale is "en_US" then lets just get out, since Event Espresso core is already "en_US"
95
-        if (EE_Load_Textdomain::$locale === 'en_US') {
96
-            // but set option first else we'll forever be downloading the pot file
97
-            update_option($language_check_option_name, 1);
98
-            return;
99
-        }
100
-        $repo_locale_URL = $repo_base_URL . '-' . EE_Load_Textdomain::$locale;
101
-        $file_name_base = 'event_espresso-' . EE_Load_Textdomain::$locale;
94
+		// if locale is "en_US" then lets just get out, since Event Espresso core is already "en_US"
95
+		if (EE_Load_Textdomain::$locale === 'en_US') {
96
+			// but set option first else we'll forever be downloading the pot file
97
+			update_option($language_check_option_name, 1);
98
+			return;
99
+		}
100
+		$repo_locale_URL = $repo_base_URL . '-' . EE_Load_Textdomain::$locale;
101
+		$file_name_base = 'event_espresso-' . EE_Load_Textdomain::$locale;
102 102
 
103
-        // made it here so let's get the language files from the github repo, first the .mo file
104
-        $sideloader->set_download_from("{$repo_locale_URL}.mo?raw=true");
105
-        $sideloader->set_new_file_name("{$file_name_base}.mo");
106
-        $sideloader->sideload();
103
+		// made it here so let's get the language files from the github repo, first the .mo file
104
+		$sideloader->set_download_from("{$repo_locale_URL}.mo?raw=true");
105
+		$sideloader->set_new_file_name("{$file_name_base}.mo");
106
+		$sideloader->sideload();
107 107
 
108
-        // now the .po file:
109
-        $sideloader->set_download_from("{$repo_locale_URL}.po?raw=true");
110
-        $sideloader->set_new_file_name("{$file_name_base}.po");
111
-        $sideloader->sideload();
108
+		// now the .po file:
109
+		$sideloader->set_download_from("{$repo_locale_URL}.po?raw=true");
110
+		$sideloader->set_new_file_name("{$file_name_base}.po");
111
+		$sideloader->sideload();
112 112
 
113
-        // set option so the above only runs when EE updates.
114
-        update_option($language_check_option_name, 1);
115
-    }
113
+		// set option so the above only runs when EE updates.
114
+		update_option($language_check_option_name, 1);
115
+	}
116 116
 }
Please login to merge, or discard this patch.
admin_pages/transactions/EE_Admin_Transactions_List_Table.class.php 2 patches
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
     {
97 97
         $class = parent::_get_row_class($transaction);
98 98
         // add status class
99
-        $class .= ' ee-status-strip txn-status-' . $transaction->status_ID();
99
+        $class .= ' ee-status-strip txn-status-'.$transaction->status_ID();
100 100
         if ($this->_has_checkbox_column) {
101 101
             $class .= ' has-checkbox-column';
102 102
         }
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
     protected function _add_view_counts()
150 150
     {
151 151
         foreach ($this->_views as $view) {
152
-            $this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']);
152
+            $this->_views[$view['slug']]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']);
153 153
         }
154 154
     }
155 155
 
@@ -170,13 +170,13 @@  discard block
 block discarded – undo
170 170
             ),
171 171
             TXN_ADMIN_URL
172 172
         );
173
-        $content = '<a href="' . $view_lnk_url . '"'
174
-                   . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">'
173
+        $content = '<a href="'.$view_lnk_url.'"'
174
+                   . ' title="'.esc_attr__('Go to Transaction Details', 'event_espresso').'">'
175 175
                    . $transaction->ID()
176 176
                    . '</a>';
177 177
 
178 178
         // txn timestamp
179
-        $content .= '  <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>';
179
+        $content .= '  <span class="show-on-mobile-view-only">'.$this->_get_txn_timestamp($transaction).'</span>';
180 180
         return $content;
181 181
     }
182 182
 
@@ -237,9 +237,9 @@  discard block
 block discarded – undo
237 237
             ),
238 238
             TXN_ADMIN_URL
239 239
         );
240
-        $txn_date = '<a href="' . $view_lnk_url . '"'
240
+        $txn_date = '<a href="'.$view_lnk_url.'"'
241 241
                     . ' title="'
242
-                    . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">'
242
+                    . esc_attr__('View Transaction Details for TXN #', 'event_espresso').$transaction->ID().'">'
243 243
                     . $this->_get_txn_timestamp($transaction)
244 244
                     . '</a>';
245 245
         // status
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
                    )
273 273
                    . '</span>';
274 274
         } else {
275
-            return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
275
+            return '<span class="txn-overview-free-event-spn">'.esc_html__('free', 'event_espresso').'</span>';
276 276
         }
277 277
     }
278 278
 
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
             ? $payment_method->admin_name()
310 310
             : esc_html__('Unknown', 'event_espresso');
311 311
 
312
-        $content = '<span class="' . $span_class . ' txn-pad-rght">'
312
+        $content = '<span class="'.$span_class.' txn-pad-rght">'
313 313
                    . $transaction->get_pretty('TXN_paid')
314 314
                    . '</span>';
315 315
         if ($transaction_paid > 0) {
@@ -351,12 +351,12 @@  discard block
 block discarded – undo
351 351
                 'espresso_registrations_view_registration',
352 352
                 $primary_reg->ID()
353 353
             )
354
-                ? '<a href="' . $edit_lnk_url . '"'
355
-                  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
354
+                ? '<a href="'.$edit_lnk_url.'"'
355
+                  . ' title="'.esc_attr__('View Registration Details', 'event_espresso').'">'
356 356
                   . $attendee->full_name()
357 357
                   . '</a>'
358 358
                 : $attendee->full_name();
359
-            $content .= '<br>' . $attendee->email();
359
+            $content .= '<br>'.$attendee->email();
360 360
             return $content;
361 361
         }
362 362
         return $transaction->failed() || $transaction->is_abandoned()
@@ -378,8 +378,8 @@  discard block
 block discarded – undo
378 378
     public function column_ATT_email(EE_Transaction $transaction)
379 379
     {
380 380
         $attendee = $transaction->primary_registration()->get_first_related('Attendee');
381
-        if (! empty($attendee)) {
382
-            return '<a href="mailto:' . $attendee->get('ATT_email') . '">'
381
+        if ( ! empty($attendee)) {
382
+            return '<a href="mailto:'.$attendee->get('ATT_email').'">'
383 383
                    . $attendee->get('ATT_email')
384 384
                    . '</a>';
385 385
         } else {
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
     {
408 408
         $actions = array();
409 409
         $event = $transaction->primary_registration()->get_first_related('Event');
410
-        if (! empty($event)) {
410
+        if ( ! empty($event)) {
411 411
             $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
412 412
                 array('action' => 'edit', 'post' => $event->ID()),
413 413
                 EVENTS_ADMIN_URL
@@ -429,11 +429,11 @@  discard block
 block discarded – undo
429 429
                     $event->ID()
430 430
                 )
431 431
             ) {
432
-                $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"'
433
-                                              . ' title="' . esc_attr__(
432
+                $actions['filter_by_event'] = '<a href="'.$txn_by_event_lnk.'"'
433
+                                              . ' title="'.esc_attr__(
434 434
                                                   'Filter transactions by this event',
435 435
                                                   'event_espresso'
436
-                                              ) . '">'
436
+                                              ).'">'
437 437
                                               . esc_html__('View Transactions for this event', 'event_espresso')
438 438
                                               . '</a>';
439 439
             }
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
                     'espresso_events_edit',
446 446
                     $event->ID()
447 447
                 )
448
-                    ? '<a href="' . $edit_event_url . '"'
448
+                    ? '<a href="'.$edit_event_url.'"'
449 449
                       . ' title="'
450 450
                       . sprintf(
451 451
                           esc_attr__('Edit Event: %s', 'event_espresso'),
@@ -512,8 +512,8 @@  discard block
 block discarded – undo
512 512
         );
513 513
         return '
514 514
 			<li>
515
-				<a href="' . $url . '"'
516
-               . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text">
515
+				<a href="' . $url.'"'
516
+               . ' title="'.esc_attr__('View Transaction Details', 'event_espresso').'" class="tiny-text">
517 517
 					<span class="dashicons dashicons-cart"></span>
518 518
 				</a>
519 519
 			</li>';
@@ -539,8 +539,8 @@  discard block
 block discarded – undo
539 539
             ) {
540 540
                 return '
541 541
                 <li>
542
-                    <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"'
543
-                       . ' target="_blank" href="' . $url . '" class="tiny-text">
542
+                    <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso').'"'
543
+                       . ' target="_blank" href="'.$url.'" class="tiny-text">
544 544
                         <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span>
545 545
                     </a>
546 546
                 </li>';
@@ -569,8 +569,8 @@  discard block
 block discarded – undo
569 569
             ) {
570 570
                 return '
571 571
 			<li>
572
-				<a title="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"'
573
-                       . ' target="_blank" href="' . $url . '" class="tiny-text">
572
+				<a title="' . esc_attr__('View Transaction Receipt', 'event_espresso').'"'
573
+                       . ' target="_blank" href="'.$url.'" class="tiny-text">
574 574
 					<span class="dashicons dashicons-media-default ee-icon-size-18"></span>
575 575
 				</a>
576 576
 			</li>';
@@ -608,8 +608,8 @@  discard block
 block discarded – undo
608 608
             )
609 609
                 ? '
610 610
 				<li>
611
-					<a href="' . $url . '"'
612
-                  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text">
611
+					<a href="' . $url.'"'
612
+                  . ' title="'.esc_attr__('View Registration Details', 'event_espresso').'" class="tiny-text">
613 613
 						<span class="dashicons dashicons-clipboard"></span>
614 614
 					</a>
615 615
 				</li>'
@@ -655,8 +655,8 @@  discard block
 block discarded – undo
655 655
             );
656 656
             return '
657 657
             <li>
658
-                <a href="' . $url . '"'
659
-                   . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text">
658
+                <a href="' . $url.'"'
659
+                   . ' title="'.esc_attr__('Send Payment Reminder', 'event_espresso').'" class="tiny-text">
660 660
                     <span class="dashicons dashicons-email-alt"></span>
661 661
                 </a>
662 662
             </li>';
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
             'ee_read_global_messages',
687 687
             'view_filtered_messages'
688 688
         )
689
-            ? '<li>' . $url . '</li>'
689
+            ? '<li>'.$url.'</li>'
690 690
             : '';
691 691
     }
692 692
 
@@ -708,8 +708,8 @@  discard block
 block discarded – undo
708 708
         ) {
709 709
             return '
710 710
             <li>
711
-                <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"'
712
-                   . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"'
711
+                <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso').'"'
712
+                   . ' target="_blank" href="'.$registration->payment_overview_url(true).'"'
713 713
                    . ' class="tiny-text">
714 714
                     <span class="dashicons dashicons-money ee-icon-size-18"></span>
715 715
                 </a>
Please login to merge, or discard this patch.
Indentation   +665 added lines, -665 removed lines patch added patch discarded remove patch
@@ -14,121 +14,121 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class EE_Admin_Transactions_List_Table extends EE_Admin_List_Table
16 16
 {
17
-    /**
18
-     * @var SessionLifespan $session_lifespan
19
-     */
20
-    private $session_lifespan;
21
-
22
-    private $_status;
23
-
24
-
25
-    /**
26
-     * @param \Transactions_Admin_Page $admin_page
27
-     * @param SessionLifespan          $lifespan
28
-     */
29
-    public function __construct(\Transactions_Admin_Page $admin_page, SessionLifespan $lifespan)
30
-    {
31
-        parent::__construct($admin_page);
32
-        $this->session_lifespan = $lifespan;
33
-        $this->_status = $this->_admin_page->get_transaction_status_array();
34
-    }
35
-
36
-
37
-    /**
38
-     *_setup_data
39
-     */
40
-    protected function _setup_data()
41
-    {
42
-        $this->_data = $this->_admin_page->get_transactions($this->_per_page);
43
-        $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all';
44
-        $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status);
45
-    }
46
-
47
-
48
-    /**
49
-     *_set_properties
50
-     */
51
-    protected function _set_properties()
52
-    {
53
-        $this->_wp_list_args = array(
54
-            'singular' => esc_html__('transaction', 'event_espresso'),
55
-            'plural'   => esc_html__('transactions', 'event_espresso'),
56
-            'ajax'     => true,
57
-            'screen'   => $this->_admin_page->get_current_screen()->id,
58
-        );
59
-        $ID_column_name = esc_html__('ID', 'event_espresso');
60
-        $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">';
61
-        $ID_column_name .= esc_html__('Transaction Date', 'event_espresso');
62
-        $ID_column_name .= '</span> ';
63
-        $this->_columns = array(
64
-            'TXN_ID'        => $ID_column_name,
65
-            'TXN_timestamp' => esc_html__('Transaction Date', 'event_espresso'),
66
-            'TXN_total'     => esc_html__('Total', 'event_espresso'),
67
-            'TXN_paid'      => esc_html__('Paid', 'event_espresso'),
68
-            'ATT_fname'     => esc_html__('Primary Registrant', 'event_espresso'),
69
-            'event_name'    => esc_html__('Event', 'event_espresso'),
70
-            'actions'       => esc_html__('Actions', 'event_espresso'),
71
-        );
72
-
73
-        $this->_sortable_columns = array(
74
-            'TXN_ID'        => array('TXN_ID' => false),
75
-            'event_name'    => array('event_name' => false),
76
-            'ATT_fname'     => array('ATT_fname' => false),
77
-            'TXN_timestamp' => array('TXN_timestamp' => true) // true means its already sorted
78
-        );
79
-
80
-        $this->_primary_column = 'TXN_ID';
81
-
82
-        $this->_hidden_columns = array();
83
-    }
84
-
85
-
86
-    /**
87
-     * This simply sets up the row class for the table rows.
88
-     * Allows for easier overriding of child methods for setting up sorting.
89
-     *
90
-     * @param  EE_Transaction $transaction the current item
91
-     * @return string
92
-     * @throws \EE_Error
93
-     */
94
-    protected function _get_row_class($transaction)
95
-    {
96
-        $class = parent::_get_row_class($transaction);
97
-        // add status class
98
-        $class .= ' ee-status-strip txn-status-' . $transaction->status_ID();
99
-        if ($this->_has_checkbox_column) {
100
-            $class .= ' has-checkbox-column';
101
-        }
102
-        return $class;
103
-    }
104
-
105
-
106
-    /**
107
-     * _get_table_filters
108
-     * We use this to assemble and return any filters that are associated with this table that help further refine what
109
-     * get's shown in the table.
110
-     *
111
-     * @abstract
112
-     * @access protected
113
-     * @return array
114
-     */
115
-    protected function _get_table_filters()
116
-    {
117
-        $filters = array();
118
-        $start_date = isset($this->_req_data['txn-filter-start-date'])
119
-            ? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
120
-            : date(
121
-                'm/d/Y',
122
-                strtotime('-10 year')
123
-            );
124
-        $end_date = isset($this->_req_data['txn-filter-end-date'])
125
-            ? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
126
-            : date(
127
-                'm/d/Y',
128
-                current_time('timestamp')
129
-            );
130
-        ob_start();
131
-        ?>
17
+	/**
18
+	 * @var SessionLifespan $session_lifespan
19
+	 */
20
+	private $session_lifespan;
21
+
22
+	private $_status;
23
+
24
+
25
+	/**
26
+	 * @param \Transactions_Admin_Page $admin_page
27
+	 * @param SessionLifespan          $lifespan
28
+	 */
29
+	public function __construct(\Transactions_Admin_Page $admin_page, SessionLifespan $lifespan)
30
+	{
31
+		parent::__construct($admin_page);
32
+		$this->session_lifespan = $lifespan;
33
+		$this->_status = $this->_admin_page->get_transaction_status_array();
34
+	}
35
+
36
+
37
+	/**
38
+	 *_setup_data
39
+	 */
40
+	protected function _setup_data()
41
+	{
42
+		$this->_data = $this->_admin_page->get_transactions($this->_per_page);
43
+		$status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all';
44
+		$this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status);
45
+	}
46
+
47
+
48
+	/**
49
+	 *_set_properties
50
+	 */
51
+	protected function _set_properties()
52
+	{
53
+		$this->_wp_list_args = array(
54
+			'singular' => esc_html__('transaction', 'event_espresso'),
55
+			'plural'   => esc_html__('transactions', 'event_espresso'),
56
+			'ajax'     => true,
57
+			'screen'   => $this->_admin_page->get_current_screen()->id,
58
+		);
59
+		$ID_column_name = esc_html__('ID', 'event_espresso');
60
+		$ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">';
61
+		$ID_column_name .= esc_html__('Transaction Date', 'event_espresso');
62
+		$ID_column_name .= '</span> ';
63
+		$this->_columns = array(
64
+			'TXN_ID'        => $ID_column_name,
65
+			'TXN_timestamp' => esc_html__('Transaction Date', 'event_espresso'),
66
+			'TXN_total'     => esc_html__('Total', 'event_espresso'),
67
+			'TXN_paid'      => esc_html__('Paid', 'event_espresso'),
68
+			'ATT_fname'     => esc_html__('Primary Registrant', 'event_espresso'),
69
+			'event_name'    => esc_html__('Event', 'event_espresso'),
70
+			'actions'       => esc_html__('Actions', 'event_espresso'),
71
+		);
72
+
73
+		$this->_sortable_columns = array(
74
+			'TXN_ID'        => array('TXN_ID' => false),
75
+			'event_name'    => array('event_name' => false),
76
+			'ATT_fname'     => array('ATT_fname' => false),
77
+			'TXN_timestamp' => array('TXN_timestamp' => true) // true means its already sorted
78
+		);
79
+
80
+		$this->_primary_column = 'TXN_ID';
81
+
82
+		$this->_hidden_columns = array();
83
+	}
84
+
85
+
86
+	/**
87
+	 * This simply sets up the row class for the table rows.
88
+	 * Allows for easier overriding of child methods for setting up sorting.
89
+	 *
90
+	 * @param  EE_Transaction $transaction the current item
91
+	 * @return string
92
+	 * @throws \EE_Error
93
+	 */
94
+	protected function _get_row_class($transaction)
95
+	{
96
+		$class = parent::_get_row_class($transaction);
97
+		// add status class
98
+		$class .= ' ee-status-strip txn-status-' . $transaction->status_ID();
99
+		if ($this->_has_checkbox_column) {
100
+			$class .= ' has-checkbox-column';
101
+		}
102
+		return $class;
103
+	}
104
+
105
+
106
+	/**
107
+	 * _get_table_filters
108
+	 * We use this to assemble and return any filters that are associated with this table that help further refine what
109
+	 * get's shown in the table.
110
+	 *
111
+	 * @abstract
112
+	 * @access protected
113
+	 * @return array
114
+	 */
115
+	protected function _get_table_filters()
116
+	{
117
+		$filters = array();
118
+		$start_date = isset($this->_req_data['txn-filter-start-date'])
119
+			? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
120
+			: date(
121
+				'm/d/Y',
122
+				strtotime('-10 year')
123
+			);
124
+		$end_date = isset($this->_req_data['txn-filter-end-date'])
125
+			? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
126
+			: date(
127
+				'm/d/Y',
128
+				current_time('timestamp')
129
+			);
130
+		ob_start();
131
+		?>
132 132
         <label for="txn-filter-start-date">Display Transactions from </label>
133 133
         <input class="datepicker"
134 134
                id="txn-filter-start-date"
@@ -146,585 +146,585 @@  discard block
 block discarded – undo
146 146
                value="<?php echo esc_html($end_date); ?>"
147 147
         />
148 148
         <?php
149
-        $filters[] = ob_get_contents();
150
-        ob_end_clean();
151
-        return $filters;
152
-    }
153
-
154
-
155
-    /**
156
-     *_add_view_counts
157
-     */
158
-    protected function _add_view_counts()
159
-    {
160
-        foreach ($this->_views as $view) {
161
-            $this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']);
162
-        }
163
-    }
164
-
165
-
166
-    /**
167
-     *    column TXN_ID
168
-     *
169
-     * @param \EE_Transaction $transaction
170
-     * @return string
171
-     * @throws \EE_Error
172
-     */
173
-    public function column_TXN_ID(EE_Transaction $transaction)
174
-    {
175
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
176
-            array(
177
-                'action' => 'view_transaction',
178
-                'TXN_ID' => $transaction->ID(),
179
-            ),
180
-            TXN_ADMIN_URL
181
-        );
182
-        $content = '<a href="' . $view_lnk_url . '"'
183
-                   . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">'
184
-                   . $transaction->ID()
185
-                   . '</a>';
186
-
187
-        // txn timestamp
188
-        $content .= '  <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>';
189
-        return $content;
190
-    }
191
-
192
-
193
-    /**
194
-     * @param \EE_Transaction $transaction
195
-     * @return string
196
-     * @throws EE_Error
197
-     * @throws InvalidArgumentException
198
-     * @throws InvalidDataTypeException
199
-     * @throws InvalidInterfaceException
200
-     */
201
-    protected function _get_txn_timestamp(EE_Transaction $transaction)
202
-    {
203
-        // is TXN less than 2 hours old ?
204
-        if (
205
-            ($transaction->failed() || $transaction->is_abandoned())
206
-            && $this->session_lifespan->expiration() < $transaction->datetime(false, true)
207
-        ) {
208
-            $timestamp = esc_html__('TXN in progress...', 'event_espresso');
209
-        } else {
210
-            $timestamp = $transaction->get_i18n_datetime('TXN_timestamp');
211
-        }
212
-        return $timestamp;
213
-    }
214
-
215
-
216
-    /**
217
-     *    column_cb
218
-     *
219
-     * @param \EE_Transaction $transaction
220
-     * @return string
221
-     * @throws \EE_Error
222
-     */
223
-    public function column_cb($transaction)
224
-    {
225
-        return sprintf(
226
-            '<input type="checkbox" name="%1$s[]" value="%2$s" />',
227
-            $this->_wp_list_args['singular'],
228
-            $transaction->ID()
229
-        );
230
-    }
231
-
232
-
233
-    /**
234
-     *    column_TXN_timestamp
235
-     *
236
-     * @param \EE_Transaction $transaction
237
-     * @return string
238
-     * @throws \EE_Error
239
-     */
240
-    public function column_TXN_timestamp(EE_Transaction $transaction)
241
-    {
242
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
243
-            array(
244
-                'action' => 'view_transaction',
245
-                'TXN_ID' => $transaction->ID(),
246
-            ),
247
-            TXN_ADMIN_URL
248
-        );
249
-        $txn_date = '<a href="' . $view_lnk_url . '"'
250
-                    . ' title="'
251
-                    . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">'
252
-                    . $this->_get_txn_timestamp($transaction)
253
-                    . '</a>';
254
-        // status
255
-        $txn_date .= '<br><span class="ee-status-text-small">'
256
-                    . EEH_Template::pretty_status(
257
-                        $transaction->status_ID(),
258
-                        false,
259
-                        'sentence'
260
-                    )
261
-                     . '</span>';
262
-        return $txn_date;
263
-    }
264
-
265
-
266
-    /**
267
-     *    column_TXN_total
268
-     *
269
-     * @param \EE_Transaction $transaction
270
-     * @return string
271
-     * @throws \EE_Error
272
-     */
273
-    public function column_TXN_total(EE_Transaction $transaction)
274
-    {
275
-        if ($transaction->get('TXN_total') > 0) {
276
-            return '<span class="txn-pad-rght">'
277
-                   . apply_filters(
278
-                       'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total',
279
-                       $transaction->get_pretty('TXN_total'),
280
-                       $transaction
281
-                   )
282
-                   . '</span>';
283
-        } else {
284
-            return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
285
-        }
286
-    }
287
-
288
-
289
-    /**
290
-     *    column_TXN_paid
291
-     *
292
-     * @param \EE_Transaction $transaction
293
-     * @return mixed|string
294
-     * @throws \EE_Error
295
-     */
296
-    public function column_TXN_paid(EE_Transaction $transaction)
297
-    {
298
-        $transaction_total = $transaction->get('TXN_total');
299
-        $transaction_paid = $transaction->get('TXN_paid');
300
-
301
-        if (\EEH_Money::compare_floats($transaction_total, 0, '>')) {
302
-            // monies owing
303
-            $span_class = 'txn-overview-part-payment-spn';
304
-            if (\EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) {
305
-                // paid in full
306
-                $span_class = 'txn-overview-full-payment-spn';
307
-            } elseif (\EEH_Money::compare_floats($transaction_paid, 0, '==')) {
308
-                // no payments made
309
-                $span_class = 'txn-overview-no-payment-spn';
310
-            }
311
-        } else {
312
-            // transaction_total == 0 so this is a free event
313
-            $span_class = 'txn-overview-free-event-spn';
314
-        }
315
-
316
-        $payment_method = $transaction->payment_method();
317
-        $payment_method_name = $payment_method instanceof EE_Payment_Method
318
-            ? $payment_method->admin_name()
319
-            : esc_html__('Unknown', 'event_espresso');
320
-
321
-        $content = '<span class="' . $span_class . ' txn-pad-rght">'
322
-                   . $transaction->get_pretty('TXN_paid')
323
-                   . '</span>';
324
-        if ($transaction_paid > 0) {
325
-            $content .= '<br><span class="ee-status-text-small">'
326
-                        . sprintf(
327
-                            esc_html__('...via %s', 'event_espresso'),
328
-                            $payment_method_name
329
-                        )
330
-                        . '</span>';
331
-        }
332
-        return $content;
333
-    }
334
-
335
-
336
-    /**
337
-     *    column_ATT_fname
338
-     *
339
-     * @param \EE_Transaction $transaction
340
-     * @return string
341
-     * @throws EE_Error
342
-     * @throws InvalidArgumentException
343
-     * @throws InvalidDataTypeException
344
-     * @throws InvalidInterfaceException
345
-     */
346
-    public function column_ATT_fname(EE_Transaction $transaction)
347
-    {
348
-        $primary_reg = $transaction->primary_registration();
349
-        $attendee = $primary_reg->get_first_related('Attendee');
350
-        if ($attendee instanceof EE_Attendee) {
351
-            $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
352
-                array(
353
-                    'action'  => 'view_registration',
354
-                    '_REG_ID' => $primary_reg->ID(),
355
-                ),
356
-                REG_ADMIN_URL
357
-            );
358
-            $content = EE_Registry::instance()->CAP->current_user_can(
359
-                'ee_read_registration',
360
-                'espresso_registrations_view_registration',
361
-                $primary_reg->ID()
362
-            )
363
-                ? '<a href="' . $edit_lnk_url . '"'
364
-                  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
365
-                  . $attendee->full_name()
366
-                  . '</a>'
367
-                : $attendee->full_name();
368
-            $content .= '<br>' . $attendee->email();
369
-            return $content;
370
-        }
371
-        return $transaction->failed() || $transaction->is_abandoned()
372
-            ? esc_html__('no contact record.', 'event_espresso')
373
-            : esc_html__(
374
-                'No contact record, because the transaction was abandoned or the registration process failed.',
375
-                'event_espresso'
376
-            );
377
-    }
378
-
379
-
380
-    /**
381
-     *    column_ATT_email
382
-     *
383
-     * @param \EE_Transaction $transaction
384
-     * @return string
385
-     * @throws \EE_Error
386
-     */
387
-    public function column_ATT_email(EE_Transaction $transaction)
388
-    {
389
-        $attendee = $transaction->primary_registration()->get_first_related('Attendee');
390
-        if (! empty($attendee)) {
391
-            return '<a href="mailto:' . $attendee->get('ATT_email') . '">'
392
-                   . $attendee->get('ATT_email')
393
-                   . '</a>';
394
-        } else {
395
-            return $transaction->failed() || $transaction->is_abandoned()
396
-                ? esc_html__('no contact record.', 'event_espresso')
397
-                : esc_html__(
398
-                    'No contact record, because the transaction was abandoned or the registration process failed.',
399
-                    'event_espresso'
400
-                );
401
-        }
402
-    }
403
-
404
-
405
-    /**
406
-     *    column_event_name
407
-     *
408
-     * @param \EE_Transaction $transaction
409
-     * @return string
410
-     * @throws EE_Error
411
-     * @throws InvalidArgumentException
412
-     * @throws InvalidDataTypeException
413
-     * @throws InvalidInterfaceException
414
-     */
415
-    public function column_event_name(EE_Transaction $transaction)
416
-    {
417
-        $actions = array();
418
-        $event = $transaction->primary_registration()->get_first_related('Event');
419
-        if (! empty($event)) {
420
-            $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
421
-                array('action' => 'edit', 'post' => $event->ID()),
422
-                EVENTS_ADMIN_URL
423
-            );
424
-            $event_name = $event->get('EVT_name');
425
-
426
-            // filter this view by transactions for this event
427
-            $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(
428
-                array(
429
-                    'action' => 'default',
430
-                    'EVT_ID' => $event->ID(),
431
-                )
432
-            );
433
-            if (
434
-                empty($this->_req_data['EVT_ID'])
435
-                && EE_Registry::instance()->CAP->current_user_can(
436
-                    'ee_edit_event',
437
-                    'espresso_events_edit',
438
-                    $event->ID()
439
-                )
440
-            ) {
441
-                $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"'
442
-                                              . ' title="' . esc_attr__(
443
-                                                  'Filter transactions by this event',
444
-                                                  'event_espresso'
445
-                                              ) . '">'
446
-                                              . esc_html__('View Transactions for this event', 'event_espresso')
447
-                                              . '</a>';
448
-            }
449
-
450
-            return sprintf(
451
-                '%1$s %2$s',
452
-                EE_Registry::instance()->CAP->current_user_can(
453
-                    'ee_edit_event',
454
-                    'espresso_events_edit',
455
-                    $event->ID()
456
-                )
457
-                    ? '<a href="' . $edit_event_url . '"'
458
-                      . ' title="'
459
-                      . sprintf(
460
-                          esc_attr__('Edit Event: %s', 'event_espresso'),
461
-                          $event->get('EVT_name')
462
-                      )
463
-                      . '">'
464
-                      . wp_trim_words(
465
-                          $event_name,
466
-                          30,
467
-                          '...'
468
-                      )
469
-                      . '</a>'
470
-                    : wp_trim_words($event_name, 30, '...'),
471
-                $this->row_actions($actions)
472
-            );
473
-        } else {
474
-            return esc_html__(
475
-                'The event associated with this transaction via the primary registration cannot be retrieved.',
476
-                'event_espresso'
477
-            );
478
-        }
479
-    }
480
-
481
-
482
-    /**
483
-     *    column_actions
484
-     *
485
-     * @param \EE_Transaction $transaction
486
-     * @return string
487
-     * @throws \EE_Error
488
-     */
489
-    public function column_actions(EE_Transaction $transaction)
490
-    {
491
-        return $this->_action_string(
492
-            $this->get_transaction_details_link($transaction)
493
-            . $this->get_invoice_link($transaction)
494
-            . $this->get_receipt_link($transaction)
495
-            . $this->get_primary_registration_details_link($transaction)
496
-            . $this->get_send_payment_reminder_trigger_link($transaction)
497
-            . $this->get_payment_overview_link($transaction)
498
-            . $this->get_related_messages_link($transaction),
499
-            $transaction,
500
-            'ul',
501
-            'txn-overview-actions-ul'
502
-        );
503
-    }
504
-
505
-
506
-    /**
507
-     * Get the transaction details link.
508
-     *
509
-     * @param EE_Transaction $transaction
510
-     * @return string
511
-     * @throws EE_Error
512
-     */
513
-    protected function get_transaction_details_link(EE_Transaction $transaction)
514
-    {
515
-        $url = EE_Admin_Page::add_query_args_and_nonce(
516
-            array(
517
-                'action' => 'view_transaction',
518
-                'TXN_ID' => $transaction->ID(),
519
-            ),
520
-            TXN_ADMIN_URL
521
-        );
522
-        return '
149
+		$filters[] = ob_get_contents();
150
+		ob_end_clean();
151
+		return $filters;
152
+	}
153
+
154
+
155
+	/**
156
+	 *_add_view_counts
157
+	 */
158
+	protected function _add_view_counts()
159
+	{
160
+		foreach ($this->_views as $view) {
161
+			$this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']);
162
+		}
163
+	}
164
+
165
+
166
+	/**
167
+	 *    column TXN_ID
168
+	 *
169
+	 * @param \EE_Transaction $transaction
170
+	 * @return string
171
+	 * @throws \EE_Error
172
+	 */
173
+	public function column_TXN_ID(EE_Transaction $transaction)
174
+	{
175
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
176
+			array(
177
+				'action' => 'view_transaction',
178
+				'TXN_ID' => $transaction->ID(),
179
+			),
180
+			TXN_ADMIN_URL
181
+		);
182
+		$content = '<a href="' . $view_lnk_url . '"'
183
+				   . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">'
184
+				   . $transaction->ID()
185
+				   . '</a>';
186
+
187
+		// txn timestamp
188
+		$content .= '  <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>';
189
+		return $content;
190
+	}
191
+
192
+
193
+	/**
194
+	 * @param \EE_Transaction $transaction
195
+	 * @return string
196
+	 * @throws EE_Error
197
+	 * @throws InvalidArgumentException
198
+	 * @throws InvalidDataTypeException
199
+	 * @throws InvalidInterfaceException
200
+	 */
201
+	protected function _get_txn_timestamp(EE_Transaction $transaction)
202
+	{
203
+		// is TXN less than 2 hours old ?
204
+		if (
205
+			($transaction->failed() || $transaction->is_abandoned())
206
+			&& $this->session_lifespan->expiration() < $transaction->datetime(false, true)
207
+		) {
208
+			$timestamp = esc_html__('TXN in progress...', 'event_espresso');
209
+		} else {
210
+			$timestamp = $transaction->get_i18n_datetime('TXN_timestamp');
211
+		}
212
+		return $timestamp;
213
+	}
214
+
215
+
216
+	/**
217
+	 *    column_cb
218
+	 *
219
+	 * @param \EE_Transaction $transaction
220
+	 * @return string
221
+	 * @throws \EE_Error
222
+	 */
223
+	public function column_cb($transaction)
224
+	{
225
+		return sprintf(
226
+			'<input type="checkbox" name="%1$s[]" value="%2$s" />',
227
+			$this->_wp_list_args['singular'],
228
+			$transaction->ID()
229
+		);
230
+	}
231
+
232
+
233
+	/**
234
+	 *    column_TXN_timestamp
235
+	 *
236
+	 * @param \EE_Transaction $transaction
237
+	 * @return string
238
+	 * @throws \EE_Error
239
+	 */
240
+	public function column_TXN_timestamp(EE_Transaction $transaction)
241
+	{
242
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
243
+			array(
244
+				'action' => 'view_transaction',
245
+				'TXN_ID' => $transaction->ID(),
246
+			),
247
+			TXN_ADMIN_URL
248
+		);
249
+		$txn_date = '<a href="' . $view_lnk_url . '"'
250
+					. ' title="'
251
+					. esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">'
252
+					. $this->_get_txn_timestamp($transaction)
253
+					. '</a>';
254
+		// status
255
+		$txn_date .= '<br><span class="ee-status-text-small">'
256
+					. EEH_Template::pretty_status(
257
+						$transaction->status_ID(),
258
+						false,
259
+						'sentence'
260
+					)
261
+					 . '</span>';
262
+		return $txn_date;
263
+	}
264
+
265
+
266
+	/**
267
+	 *    column_TXN_total
268
+	 *
269
+	 * @param \EE_Transaction $transaction
270
+	 * @return string
271
+	 * @throws \EE_Error
272
+	 */
273
+	public function column_TXN_total(EE_Transaction $transaction)
274
+	{
275
+		if ($transaction->get('TXN_total') > 0) {
276
+			return '<span class="txn-pad-rght">'
277
+				   . apply_filters(
278
+					   'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total',
279
+					   $transaction->get_pretty('TXN_total'),
280
+					   $transaction
281
+				   )
282
+				   . '</span>';
283
+		} else {
284
+			return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
285
+		}
286
+	}
287
+
288
+
289
+	/**
290
+	 *    column_TXN_paid
291
+	 *
292
+	 * @param \EE_Transaction $transaction
293
+	 * @return mixed|string
294
+	 * @throws \EE_Error
295
+	 */
296
+	public function column_TXN_paid(EE_Transaction $transaction)
297
+	{
298
+		$transaction_total = $transaction->get('TXN_total');
299
+		$transaction_paid = $transaction->get('TXN_paid');
300
+
301
+		if (\EEH_Money::compare_floats($transaction_total, 0, '>')) {
302
+			// monies owing
303
+			$span_class = 'txn-overview-part-payment-spn';
304
+			if (\EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) {
305
+				// paid in full
306
+				$span_class = 'txn-overview-full-payment-spn';
307
+			} elseif (\EEH_Money::compare_floats($transaction_paid, 0, '==')) {
308
+				// no payments made
309
+				$span_class = 'txn-overview-no-payment-spn';
310
+			}
311
+		} else {
312
+			// transaction_total == 0 so this is a free event
313
+			$span_class = 'txn-overview-free-event-spn';
314
+		}
315
+
316
+		$payment_method = $transaction->payment_method();
317
+		$payment_method_name = $payment_method instanceof EE_Payment_Method
318
+			? $payment_method->admin_name()
319
+			: esc_html__('Unknown', 'event_espresso');
320
+
321
+		$content = '<span class="' . $span_class . ' txn-pad-rght">'
322
+				   . $transaction->get_pretty('TXN_paid')
323
+				   . '</span>';
324
+		if ($transaction_paid > 0) {
325
+			$content .= '<br><span class="ee-status-text-small">'
326
+						. sprintf(
327
+							esc_html__('...via %s', 'event_espresso'),
328
+							$payment_method_name
329
+						)
330
+						. '</span>';
331
+		}
332
+		return $content;
333
+	}
334
+
335
+
336
+	/**
337
+	 *    column_ATT_fname
338
+	 *
339
+	 * @param \EE_Transaction $transaction
340
+	 * @return string
341
+	 * @throws EE_Error
342
+	 * @throws InvalidArgumentException
343
+	 * @throws InvalidDataTypeException
344
+	 * @throws InvalidInterfaceException
345
+	 */
346
+	public function column_ATT_fname(EE_Transaction $transaction)
347
+	{
348
+		$primary_reg = $transaction->primary_registration();
349
+		$attendee = $primary_reg->get_first_related('Attendee');
350
+		if ($attendee instanceof EE_Attendee) {
351
+			$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
352
+				array(
353
+					'action'  => 'view_registration',
354
+					'_REG_ID' => $primary_reg->ID(),
355
+				),
356
+				REG_ADMIN_URL
357
+			);
358
+			$content = EE_Registry::instance()->CAP->current_user_can(
359
+				'ee_read_registration',
360
+				'espresso_registrations_view_registration',
361
+				$primary_reg->ID()
362
+			)
363
+				? '<a href="' . $edit_lnk_url . '"'
364
+				  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
365
+				  . $attendee->full_name()
366
+				  . '</a>'
367
+				: $attendee->full_name();
368
+			$content .= '<br>' . $attendee->email();
369
+			return $content;
370
+		}
371
+		return $transaction->failed() || $transaction->is_abandoned()
372
+			? esc_html__('no contact record.', 'event_espresso')
373
+			: esc_html__(
374
+				'No contact record, because the transaction was abandoned or the registration process failed.',
375
+				'event_espresso'
376
+			);
377
+	}
378
+
379
+
380
+	/**
381
+	 *    column_ATT_email
382
+	 *
383
+	 * @param \EE_Transaction $transaction
384
+	 * @return string
385
+	 * @throws \EE_Error
386
+	 */
387
+	public function column_ATT_email(EE_Transaction $transaction)
388
+	{
389
+		$attendee = $transaction->primary_registration()->get_first_related('Attendee');
390
+		if (! empty($attendee)) {
391
+			return '<a href="mailto:' . $attendee->get('ATT_email') . '">'
392
+				   . $attendee->get('ATT_email')
393
+				   . '</a>';
394
+		} else {
395
+			return $transaction->failed() || $transaction->is_abandoned()
396
+				? esc_html__('no contact record.', 'event_espresso')
397
+				: esc_html__(
398
+					'No contact record, because the transaction was abandoned or the registration process failed.',
399
+					'event_espresso'
400
+				);
401
+		}
402
+	}
403
+
404
+
405
+	/**
406
+	 *    column_event_name
407
+	 *
408
+	 * @param \EE_Transaction $transaction
409
+	 * @return string
410
+	 * @throws EE_Error
411
+	 * @throws InvalidArgumentException
412
+	 * @throws InvalidDataTypeException
413
+	 * @throws InvalidInterfaceException
414
+	 */
415
+	public function column_event_name(EE_Transaction $transaction)
416
+	{
417
+		$actions = array();
418
+		$event = $transaction->primary_registration()->get_first_related('Event');
419
+		if (! empty($event)) {
420
+			$edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
421
+				array('action' => 'edit', 'post' => $event->ID()),
422
+				EVENTS_ADMIN_URL
423
+			);
424
+			$event_name = $event->get('EVT_name');
425
+
426
+			// filter this view by transactions for this event
427
+			$txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(
428
+				array(
429
+					'action' => 'default',
430
+					'EVT_ID' => $event->ID(),
431
+				)
432
+			);
433
+			if (
434
+				empty($this->_req_data['EVT_ID'])
435
+				&& EE_Registry::instance()->CAP->current_user_can(
436
+					'ee_edit_event',
437
+					'espresso_events_edit',
438
+					$event->ID()
439
+				)
440
+			) {
441
+				$actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"'
442
+											  . ' title="' . esc_attr__(
443
+												  'Filter transactions by this event',
444
+												  'event_espresso'
445
+											  ) . '">'
446
+											  . esc_html__('View Transactions for this event', 'event_espresso')
447
+											  . '</a>';
448
+			}
449
+
450
+			return sprintf(
451
+				'%1$s %2$s',
452
+				EE_Registry::instance()->CAP->current_user_can(
453
+					'ee_edit_event',
454
+					'espresso_events_edit',
455
+					$event->ID()
456
+				)
457
+					? '<a href="' . $edit_event_url . '"'
458
+					  . ' title="'
459
+					  . sprintf(
460
+						  esc_attr__('Edit Event: %s', 'event_espresso'),
461
+						  $event->get('EVT_name')
462
+					  )
463
+					  . '">'
464
+					  . wp_trim_words(
465
+						  $event_name,
466
+						  30,
467
+						  '...'
468
+					  )
469
+					  . '</a>'
470
+					: wp_trim_words($event_name, 30, '...'),
471
+				$this->row_actions($actions)
472
+			);
473
+		} else {
474
+			return esc_html__(
475
+				'The event associated with this transaction via the primary registration cannot be retrieved.',
476
+				'event_espresso'
477
+			);
478
+		}
479
+	}
480
+
481
+
482
+	/**
483
+	 *    column_actions
484
+	 *
485
+	 * @param \EE_Transaction $transaction
486
+	 * @return string
487
+	 * @throws \EE_Error
488
+	 */
489
+	public function column_actions(EE_Transaction $transaction)
490
+	{
491
+		return $this->_action_string(
492
+			$this->get_transaction_details_link($transaction)
493
+			. $this->get_invoice_link($transaction)
494
+			. $this->get_receipt_link($transaction)
495
+			. $this->get_primary_registration_details_link($transaction)
496
+			. $this->get_send_payment_reminder_trigger_link($transaction)
497
+			. $this->get_payment_overview_link($transaction)
498
+			. $this->get_related_messages_link($transaction),
499
+			$transaction,
500
+			'ul',
501
+			'txn-overview-actions-ul'
502
+		);
503
+	}
504
+
505
+
506
+	/**
507
+	 * Get the transaction details link.
508
+	 *
509
+	 * @param EE_Transaction $transaction
510
+	 * @return string
511
+	 * @throws EE_Error
512
+	 */
513
+	protected function get_transaction_details_link(EE_Transaction $transaction)
514
+	{
515
+		$url = EE_Admin_Page::add_query_args_and_nonce(
516
+			array(
517
+				'action' => 'view_transaction',
518
+				'TXN_ID' => $transaction->ID(),
519
+			),
520
+			TXN_ADMIN_URL
521
+		);
522
+		return '
523 523
 			<li>
524 524
 				<a href="' . $url . '"'
525
-               . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text">
525
+			   . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text">
526 526
 					<span class="dashicons dashicons-cart"></span>
527 527
 				</a>
528 528
 			</li>';
529
-    }
530
-
531
-
532
-    /**
533
-     * Get the invoice link for the given registration.
534
-     *
535
-     * @param EE_Transaction $transaction
536
-     * @return string
537
-     * @throws EE_Error
538
-     */
539
-    protected function get_invoice_link(EE_Transaction $transaction)
540
-    {
541
-        $registration = $transaction->primary_registration();
542
-        if ($registration instanceof EE_Registration) {
543
-            $url = $registration->invoice_url();
544
-            // only show invoice link if message type is active.
545
-            if (
546
-                $registration->attendee() instanceof EE_Attendee
547
-                && EEH_MSG_Template::is_mt_active('invoice')
548
-            ) {
549
-                return '
529
+	}
530
+
531
+
532
+	/**
533
+	 * Get the invoice link for the given registration.
534
+	 *
535
+	 * @param EE_Transaction $transaction
536
+	 * @return string
537
+	 * @throws EE_Error
538
+	 */
539
+	protected function get_invoice_link(EE_Transaction $transaction)
540
+	{
541
+		$registration = $transaction->primary_registration();
542
+		if ($registration instanceof EE_Registration) {
543
+			$url = $registration->invoice_url();
544
+			// only show invoice link if message type is active.
545
+			if (
546
+				$registration->attendee() instanceof EE_Attendee
547
+				&& EEH_MSG_Template::is_mt_active('invoice')
548
+			) {
549
+				return '
550 550
                 <li>
551 551
                     <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"'
552
-                       . ' target="_blank" href="' . $url . '" class="tiny-text">
552
+					   . ' target="_blank" href="' . $url . '" class="tiny-text">
553 553
                         <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span>
554 554
                     </a>
555 555
                 </li>';
556
-            }
557
-        }
558
-        return '';
559
-    }
560
-
561
-
562
-    /**
563
-     * Get the receipt link for the transaction.
564
-     *
565
-     * @param EE_Transaction $transaction
566
-     * @return string
567
-     * @throws EE_Error
568
-     */
569
-    protected function get_receipt_link(EE_Transaction $transaction)
570
-    {
571
-        $registration = $transaction->primary_registration();
572
-        if ($registration instanceof EE_Registration) {
573
-            $url = $registration->receipt_url();
574
-            // only show receipt link if message type is active.
575
-            if (
576
-                $registration->attendee() instanceof EE_Attendee
577
-                && EEH_MSG_Template::is_mt_active('receipt')
578
-            ) {
579
-                return '
556
+			}
557
+		}
558
+		return '';
559
+	}
560
+
561
+
562
+	/**
563
+	 * Get the receipt link for the transaction.
564
+	 *
565
+	 * @param EE_Transaction $transaction
566
+	 * @return string
567
+	 * @throws EE_Error
568
+	 */
569
+	protected function get_receipt_link(EE_Transaction $transaction)
570
+	{
571
+		$registration = $transaction->primary_registration();
572
+		if ($registration instanceof EE_Registration) {
573
+			$url = $registration->receipt_url();
574
+			// only show receipt link if message type is active.
575
+			if (
576
+				$registration->attendee() instanceof EE_Attendee
577
+				&& EEH_MSG_Template::is_mt_active('receipt')
578
+			) {
579
+				return '
580 580
 			<li>
581 581
 				<a title="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"'
582
-                       . ' target="_blank" href="' . $url . '" class="tiny-text">
582
+					   . ' target="_blank" href="' . $url . '" class="tiny-text">
583 583
 					<span class="dashicons dashicons-media-default ee-icon-size-18"></span>
584 584
 				</a>
585 585
 			</li>';
586
-            }
587
-        }
588
-        return '';
589
-    }
590
-
591
-
592
-    /**
593
-     * Get the link to view the details for the primary registration.
594
-     *
595
-     * @param EE_Transaction $transaction
596
-     * @return string
597
-     * @throws EE_Error
598
-     * @throws InvalidArgumentException
599
-     * @throws InvalidDataTypeException
600
-     * @throws InvalidInterfaceException
601
-     */
602
-    protected function get_primary_registration_details_link(EE_Transaction $transaction)
603
-    {
604
-        $registration = $transaction->primary_registration();
605
-        if ($registration instanceof EE_Registration) {
606
-            $url = EE_Admin_Page::add_query_args_and_nonce(
607
-                array(
608
-                    'action'  => 'view_registration',
609
-                    '_REG_ID' => $registration->ID(),
610
-                ),
611
-                REG_ADMIN_URL
612
-            );
613
-            return EE_Registry::instance()->CAP->current_user_can(
614
-                'ee_read_registration',
615
-                'espresso_registrations_view_registration',
616
-                $registration->ID()
617
-            )
618
-                ? '
586
+			}
587
+		}
588
+		return '';
589
+	}
590
+
591
+
592
+	/**
593
+	 * Get the link to view the details for the primary registration.
594
+	 *
595
+	 * @param EE_Transaction $transaction
596
+	 * @return string
597
+	 * @throws EE_Error
598
+	 * @throws InvalidArgumentException
599
+	 * @throws InvalidDataTypeException
600
+	 * @throws InvalidInterfaceException
601
+	 */
602
+	protected function get_primary_registration_details_link(EE_Transaction $transaction)
603
+	{
604
+		$registration = $transaction->primary_registration();
605
+		if ($registration instanceof EE_Registration) {
606
+			$url = EE_Admin_Page::add_query_args_and_nonce(
607
+				array(
608
+					'action'  => 'view_registration',
609
+					'_REG_ID' => $registration->ID(),
610
+				),
611
+				REG_ADMIN_URL
612
+			);
613
+			return EE_Registry::instance()->CAP->current_user_can(
614
+				'ee_read_registration',
615
+				'espresso_registrations_view_registration',
616
+				$registration->ID()
617
+			)
618
+				? '
619 619
 				<li>
620 620
 					<a href="' . $url . '"'
621
-                  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text">
621
+				  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text">
622 622
 						<span class="dashicons dashicons-clipboard"></span>
623 623
 					</a>
624 624
 				</li>'
625
-                : '';
626
-        }
627
-        return '';
628
-    }
629
-
630
-
631
-    /**
632
-     * Get send payment reminder trigger link
633
-     *
634
-     * @param EE_Transaction $transaction
635
-     * @return string
636
-     * @throws EE_Error
637
-     * @throws InvalidArgumentException
638
-     * @throws InvalidDataTypeException
639
-     * @throws InvalidInterfaceException
640
-     */
641
-    protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction)
642
-    {
643
-        $registration = $transaction->primary_registration();
644
-        if (
645
-            $registration instanceof EE_Registration
646
-            && $registration->attendee() instanceof EE_Attendee
647
-            && EEH_MSG_Template::is_mt_active('payment_reminder')
648
-            && ! in_array(
649
-                $transaction->status_ID(),
650
-                array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code),
651
-                true
652
-            )
653
-            && EE_Registry::instance()->CAP->current_user_can(
654
-                'ee_send_message',
655
-                'espresso_transactions_send_payment_reminder'
656
-            )
657
-        ) {
658
-            $url = EE_Admin_Page::add_query_args_and_nonce(
659
-                array(
660
-                    'action' => 'send_payment_reminder',
661
-                    'TXN_ID' => $transaction->ID(),
662
-                ),
663
-                TXN_ADMIN_URL
664
-            );
665
-            return '
625
+				: '';
626
+		}
627
+		return '';
628
+	}
629
+
630
+
631
+	/**
632
+	 * Get send payment reminder trigger link
633
+	 *
634
+	 * @param EE_Transaction $transaction
635
+	 * @return string
636
+	 * @throws EE_Error
637
+	 * @throws InvalidArgumentException
638
+	 * @throws InvalidDataTypeException
639
+	 * @throws InvalidInterfaceException
640
+	 */
641
+	protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction)
642
+	{
643
+		$registration = $transaction->primary_registration();
644
+		if (
645
+			$registration instanceof EE_Registration
646
+			&& $registration->attendee() instanceof EE_Attendee
647
+			&& EEH_MSG_Template::is_mt_active('payment_reminder')
648
+			&& ! in_array(
649
+				$transaction->status_ID(),
650
+				array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code),
651
+				true
652
+			)
653
+			&& EE_Registry::instance()->CAP->current_user_can(
654
+				'ee_send_message',
655
+				'espresso_transactions_send_payment_reminder'
656
+			)
657
+		) {
658
+			$url = EE_Admin_Page::add_query_args_and_nonce(
659
+				array(
660
+					'action' => 'send_payment_reminder',
661
+					'TXN_ID' => $transaction->ID(),
662
+				),
663
+				TXN_ADMIN_URL
664
+			);
665
+			return '
666 666
             <li>
667 667
                 <a href="' . $url . '"'
668
-                   . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text">
668
+				   . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text">
669 669
                     <span class="dashicons dashicons-email-alt"></span>
670 670
                 </a>
671 671
             </li>';
672
-        }
673
-        return '';
674
-    }
675
-
676
-
677
-    /**
678
-     * Get link to filtered view in the message activity list table of messages for this transaction.
679
-     *
680
-     * @param EE_Transaction $transaction
681
-     * @return string
682
-     * @throws EE_Error
683
-     * @throws InvalidArgumentException
684
-     * @throws InvalidDataTypeException
685
-     * @throws InvalidInterfaceException
686
-     */
687
-    protected function get_related_messages_link(EE_Transaction $transaction)
688
-    {
689
-        $url = EEH_MSG_Template::get_message_action_link(
690
-            'see_notifications_for',
691
-            null,
692
-            array('TXN_ID' => $transaction->ID())
693
-        );
694
-        return EE_Registry::instance()->CAP->current_user_can(
695
-            'ee_read_global_messages',
696
-            'view_filtered_messages'
697
-        )
698
-            ? '<li>' . $url . '</li>'
699
-            : '';
700
-    }
701
-
702
-
703
-    /**
704
-     * Return the link to make a payment on the frontend
705
-     *
706
-     * @param EE_Transaction $transaction
707
-     * @return string
708
-     * @throws EE_Error
709
-     */
710
-    protected function get_payment_overview_link(EE_Transaction $transaction)
711
-    {
712
-        $registration = $transaction->primary_registration();
713
-        if (
714
-            $registration instanceof EE_Registration
715
-            && $transaction->status_ID() !== EEM_Transaction::complete_status_code
716
-            && $registration->owes_monies_and_can_pay()
717
-        ) {
718
-            return '
672
+		}
673
+		return '';
674
+	}
675
+
676
+
677
+	/**
678
+	 * Get link to filtered view in the message activity list table of messages for this transaction.
679
+	 *
680
+	 * @param EE_Transaction $transaction
681
+	 * @return string
682
+	 * @throws EE_Error
683
+	 * @throws InvalidArgumentException
684
+	 * @throws InvalidDataTypeException
685
+	 * @throws InvalidInterfaceException
686
+	 */
687
+	protected function get_related_messages_link(EE_Transaction $transaction)
688
+	{
689
+		$url = EEH_MSG_Template::get_message_action_link(
690
+			'see_notifications_for',
691
+			null,
692
+			array('TXN_ID' => $transaction->ID())
693
+		);
694
+		return EE_Registry::instance()->CAP->current_user_can(
695
+			'ee_read_global_messages',
696
+			'view_filtered_messages'
697
+		)
698
+			? '<li>' . $url . '</li>'
699
+			: '';
700
+	}
701
+
702
+
703
+	/**
704
+	 * Return the link to make a payment on the frontend
705
+	 *
706
+	 * @param EE_Transaction $transaction
707
+	 * @return string
708
+	 * @throws EE_Error
709
+	 */
710
+	protected function get_payment_overview_link(EE_Transaction $transaction)
711
+	{
712
+		$registration = $transaction->primary_registration();
713
+		if (
714
+			$registration instanceof EE_Registration
715
+			&& $transaction->status_ID() !== EEM_Transaction::complete_status_code
716
+			&& $registration->owes_monies_and_can_pay()
717
+		) {
718
+			return '
719 719
             <li>
720 720
                 <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"'
721
-                   . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"'
722
-                   . ' class="tiny-text">
721
+				   . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"'
722
+				   . ' class="tiny-text">
723 723
                     <span class="dashicons dashicons-money ee-icon-size-18"></span>
724 724
                 </a>
725 725
             </li>
726 726
             ';
727
-        }
728
-        return '';
729
-    }
727
+		}
728
+		return '';
729
+	}
730 730
 }
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_List_Table.class.php 2 patches
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         $class = parent::_get_row_class($item);
115 115
         // add status class
116 116
         $class .= $item instanceof EE_Event
117
-            ? ' ee-status-strip event-status-' . $item->get_active_status()
117
+            ? ' ee-status-strip event-status-'.$item->get_active_status()
118 118
             : '';
119 119
         if ($this->_has_checkbox_column) {
120 120
             $class .= ' has-checkbox-column';
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
      */
144 144
     public function column_cb($item)
145 145
     {
146
-        if (! $item instanceof EE_Event) {
146
+        if ( ! $item instanceof EE_Event) {
147 147
             return '';
148 148
         }
149 149
         $this->_dtt = $item->primary_datetime(); // set this for use in other columns
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
     public function column_id(EE_Event $item)
167 167
     {
168 168
         $content = $item->ID();
169
-        $content .= '  <span class="show-on-mobile-view-only">' . $item->name() . '</span>';
169
+        $content .= '  <span class="show-on-mobile-view-only">'.$item->name().'</span>';
170 170
         return $content;
171 171
     }
172 172
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
         $actions = $this->_column_name_action_setup($item);
190 190
         $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : '';
191 191
         $content = '<strong><a class="row-title" href="'
192
-                   . $edit_link . '">'
192
+                   . $edit_link.'">'
193 193
                    . $item->name()
194 194
                    . '</a></strong>'
195 195
                    . $status;
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
     protected function _column_name_action_setup(EE_Event $item)
219 219
     {
220 220
         // todo: remove when attendees is active
221
-        if (! defined('REG_ADMIN_URL')) {
221
+        if ( ! defined('REG_ADMIN_URL')) {
222 222
             define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
223 223
         }
224 224
         $actions = array();
@@ -237,8 +237,8 @@  discard block
 block discarded – undo
237 237
                 'post'   => $item->ID(),
238 238
             );
239 239
             $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
240
-            $actions['edit'] = '<a href="' . $edit_link . '"'
241
-                               . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
240
+            $actions['edit'] = '<a href="'.$edit_link.'"'
241
+                               . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">'
242 242
                                . esc_html__('Edit', 'event_espresso')
243 243
                                . '</a>';
244 244
         }
@@ -258,8 +258,8 @@  discard block
 block discarded – undo
258 258
                 'event_id' => $item->ID(),
259 259
             );
260 260
             $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
261
-            $actions['attendees'] = '<a href="' . $attendees_link . '"'
262
-                                    . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">'
261
+            $actions['attendees'] = '<a href="'.$attendees_link.'"'
262
+                                    . ' title="'.esc_attr__('View Registrations', 'event_espresso').'">'
263 263
                                     . esc_html__('Registrations', 'event_espresso')
264 264
                                     . '</a>';
265 265
         }
@@ -312,8 +312,8 @@  discard block
 block discarded – undo
312 312
             );
313 313
         }
314 314
         $view_link = get_permalink($item->ID());
315
-        $actions['view'] = '<a href="' . $view_link . '"'
316
-                           . ' title="' . esc_attr__('View Event', 'event_espresso') . '">'
315
+        $actions['view'] = '<a href="'.$view_link.'"'
316
+                           . ' title="'.esc_attr__('View Event', 'event_espresso').'">'
317 317
                            . esc_html__('View', 'event_espresso')
318 318
                            . '</a>';
319 319
         if ($item->get('status') === 'trash') {
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
                     $item->ID()
325 325
                 )
326 326
             ) {
327
-                $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"'
328
-                                                 . ' title="' . esc_attr__('Restore from Trash', 'event_espresso')
327
+                $actions['restore_from_trash'] = '<a href="'.$restore_event_link.'"'
328
+                                                 . ' title="'.esc_attr__('Restore from Trash', 'event_espresso')
329 329
                                                  . '">'
330 330
                                                  . esc_html__('Restore from Trash', 'event_espresso')
331 331
                                                  . '</a>';
@@ -338,8 +338,8 @@  discard block
 block discarded – undo
338 338
                     $item->ID()
339 339
                 )
340 340
             ) {
341
-                $actions['delete'] = '<a href="' . $delete_event_link . '"'
342
-                                     . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">'
341
+                $actions['delete'] = '<a href="'.$delete_event_link.'"'
342
+                                     . ' title="'.esc_attr__('Delete Permanently', 'event_espresso').'">'
343 343
                                      . esc_html__('Delete Permanently', 'event_espresso')
344 344
                                      . '</a>';
345 345
             }
@@ -351,8 +351,8 @@  discard block
 block discarded – undo
351 351
                     $item->ID()
352 352
                 )
353 353
             ) {
354
-                $actions['move to trash'] = '<a href="' . $trash_event_link . '"'
355
-                                            . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">'
354
+                $actions['move to trash'] = '<a href="'.$trash_event_link.'"'
355
+                                            . ' title="'.esc_attr__('Trash Event', 'event_espresso').'">'
356 356
                                             . esc_html__('Trash', 'event_espresso')
357 357
                                             . '</a>';
358 358
             }
@@ -377,8 +377,8 @@  discard block
 block discarded – undo
377 377
             'EVT_wp_user' => $item->wp_user(),
378 378
         );
379 379
         $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);
380
-        return $gravatar . '  <a href="' . $filter_url . '"'
381
-               . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">'
380
+        return $gravatar.'  <a href="'.$filter_url.'"'
381
+               . ' title="'.esc_attr__('Click to filter events by this author.', 'event_espresso').'">'
382 382
                . $event_author->display_name
383 383
                . '</a>';
384 384
     }
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
         return implode(
396 396
             ', ',
397 397
             array_map(
398
-                function (EE_Term $category) {
398
+                function(EE_Term $category) {
399 399
                     return $category->name();
400 400
                 },
401 401
                 $event_categories
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
                    'ee_read_registrations',
471 471
                    'espresso_registrations_view_registration'
472 472
                )
473
-            ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'
473
+            ? '<a href="'.$attendees_link.'">'.$registered_attendees.'</a>'
474 474
             : $registered_attendees;
475 475
     }
476 476
 
@@ -500,13 +500,13 @@  discard block
 block discarded – undo
500 500
     public function column_actions(EE_Event $item)
501 501
     {
502 502
         // todo: remove when attendees is active
503
-        if (! defined('REG_ADMIN_URL')) {
503
+        if ( ! defined('REG_ADMIN_URL')) {
504 504
             define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
505 505
         }
506 506
         $action_links = array();
507 507
         $view_link = get_permalink($item->ID());
508
-        $action_links[] = '<a href="' . $view_link . '"'
509
-                          . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">';
508
+        $action_links[] = '<a href="'.$view_link.'"'
509
+                          . ' title="'.esc_attr__('View Event', 'event_espresso').'" target="_blank">';
510 510
         $action_links[] = '<div class="dashicons dashicons-search"></div></a>';
511 511
         if (
512 512
             EE_Registry::instance()->CAP->current_user_can(
@@ -520,8 +520,8 @@  discard block
 block discarded – undo
520 520
                 'post'   => $item->ID(),
521 521
             );
522 522
             $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
523
-            $action_links[] = '<a href="' . $edit_link . '"'
524
-                              . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
523
+            $action_links[] = '<a href="'.$edit_link.'"'
524
+                              . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">'
525 525
                               . '<div class="ee-icon ee-icon-calendar-edit"></div>'
526 526
                               . '</a>';
527 527
         }
@@ -540,8 +540,8 @@  discard block
 block discarded – undo
540 540
                 'event_id' => $item->ID(),
541 541
             );
542 542
             $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
543
-            $action_links[] = '<a href="' . $attendees_link . '"'
544
-                              . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">'
543
+            $action_links[] = '<a href="'.$attendees_link.'"'
544
+                              . ' title="'.esc_attr__('View Registrants', 'event_espresso').'">'
545 545
                               . '<div class="dashicons dashicons-groups"></div>'
546 546
                               . '</a>';
547 547
         }
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
         }
577 577
         $column_array = [];
578 578
         foreach ($this->_columns as $column => $column_label) {
579
-            $column_array[ $column ] = $column_label;
579
+            $column_array[$column] = $column_label;
580 580
             if ($column === 'venue') {
581 581
                 $column_array['event_category'] = esc_html__('Event Category', 'event_espresso');
582 582
             }
Please login to merge, or discard this patch.
Indentation   +563 added lines, -563 removed lines patch added patch discarded remove patch
@@ -14,567 +14,567 @@
 block discarded – undo
14 14
  */
15 15
 class Events_Admin_List_Table extends EE_Admin_List_Table
16 16
 {
17
-    /**
18
-     * @var EE_Datetime
19
-     */
20
-    private $_dtt;
21
-
22
-
23
-    /**
24
-     * Initial setup of data properties for the list table.
25
-     */
26
-    protected function _setup_data()
27
-    {
28
-        $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page);
29
-        $this->_all_data_count = $this->_admin_page->get_events(0, 0, true);
30
-    }
31
-
32
-
33
-    /**
34
-     * Set up of additional properties for the list table.
35
-     */
36
-    protected function _set_properties()
37
-    {
38
-        $this->_wp_list_args = array(
39
-            'singular' => esc_html__('event', 'event_espresso'),
40
-            'plural'   => esc_html__('events', 'event_espresso'),
41
-            'ajax'     => true, // for now
42
-            'screen'   => $this->_admin_page->get_current_screen()->id,
43
-        );
44
-        $this->_columns = array(
45
-            'cb'              => '<input type="checkbox" />',
46
-            'id'              => esc_html__('ID', 'event_espresso'),
47
-            'name'            => esc_html__('Name', 'event_espresso'),
48
-            'author'          => esc_html__('Author', 'event_espresso'),
49
-            'venue'           => esc_html__('Venue', 'event_espresso'),
50
-            'start_date_time' => esc_html__('Event Start', 'event_espresso'),
51
-            'reg_begins'      => esc_html__('On Sale', 'event_espresso'),
52
-            'attendees'       => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">'
53
-                                 . '<span class="screen-reader-text">'
54
-                                 . esc_html__('Approved Registrations', 'event_espresso')
55
-                                 . '</span>'
56
-                                 . '</span>',
57
-            // 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'),
58
-            'actions'         => esc_html__('Actions', 'event_espresso'),
59
-        );
60
-        $this->addConditionalColumns();
61
-        $this->_sortable_columns = array(
62
-            'id'              => array('EVT_ID' => true),
63
-            'name'            => array('EVT_name' => false),
64
-            'author'          => array('EVT_wp_user' => false),
65
-            'venue'           => array('Venue.VNU_name' => false),
66
-            'start_date_time' => array('Datetime.DTT_EVT_start' => false),
67
-            'reg_begins'      => array('Datetime.Ticket.TKT_start_date' => false),
68
-        );
69
-
70
-        $this->_primary_column = 'id';
71
-        $this->_hidden_columns = array('author', 'event_category');
72
-    }
73
-
74
-
75
-    /**
76
-     * @return array
77
-     */
78
-    protected function _get_table_filters()
79
-    {
80
-        return array(); // no filters with decaf
81
-    }
82
-
83
-
84
-    /**
85
-     * Setup of views properties.
86
-     *
87
-     * @throws InvalidDataTypeException
88
-     * @throws InvalidInterfaceException
89
-     * @throws InvalidArgumentException
90
-     */
91
-    protected function _add_view_counts()
92
-    {
93
-        $this->_views['all']['count'] = $this->_admin_page->total_events();
94
-        $this->_views['draft']['count'] = $this->_admin_page->total_events_draft();
95
-        if (
96
-            EE_Registry::instance()->CAP->current_user_can(
97
-                'ee_delete_events',
98
-                'espresso_events_trash_events'
99
-            )
100
-        ) {
101
-            $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events();
102
-        }
103
-    }
104
-
105
-
106
-    /**
107
-     * @param EE_Event $item
108
-     * @return string
109
-     * @throws EE_Error
110
-     */
111
-    protected function _get_row_class($item)
112
-    {
113
-        $class = parent::_get_row_class($item);
114
-        // add status class
115
-        $class .= $item instanceof EE_Event
116
-            ? ' ee-status-strip event-status-' . $item->get_active_status()
117
-            : '';
118
-        if ($this->_has_checkbox_column) {
119
-            $class .= ' has-checkbox-column';
120
-        }
121
-        return $class;
122
-    }
123
-
124
-
125
-    /**
126
-     * @param EE_Event $item
127
-     * @return string
128
-     * @throws EE_Error
129
-     */
130
-    public function column_status(EE_Event $item)
131
-    {
132
-        return '<span class="ee-status-strip ee-status-strip-td event-status-'
133
-               . $item->get_active_status()
134
-               . '"></span>';
135
-    }
136
-
137
-
138
-    /**
139
-     * @param  EE_Event $item
140
-     * @return string
141
-     * @throws EE_Error
142
-     */
143
-    public function column_cb($item)
144
-    {
145
-        if (! $item instanceof EE_Event) {
146
-            return '';
147
-        }
148
-        $this->_dtt = $item->primary_datetime(); // set this for use in other columns
149
-        return sprintf(
150
-            '<input type="checkbox" name="EVT_IDs[]" value="%s" />',
151
-            $item->ID()
152
-        );
153
-    }
154
-
155
-
156
-    /**
157
-     * @param EE_Event $item
158
-     * @return mixed|string
159
-     * @throws EE_Error
160
-     */
161
-    public function column_id(EE_Event $item)
162
-    {
163
-        $content = $item->ID();
164
-        $content .= '  <span class="show-on-mobile-view-only">' . $item->name() . '</span>';
165
-        return $content;
166
-    }
167
-
168
-
169
-    /**
170
-     * @param EE_Event $item
171
-     * @return string
172
-     * @throws EE_Error
173
-     * @throws InvalidArgumentException
174
-     * @throws InvalidDataTypeException
175
-     * @throws InvalidInterfaceException
176
-     */
177
-    public function column_name(EE_Event $item)
178
-    {
179
-        $edit_query_args = array(
180
-            'action' => 'edit',
181
-            'post'   => $item->ID(),
182
-        );
183
-        $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
184
-        $actions = $this->_column_name_action_setup($item);
185
-        $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : '';
186
-        $content = '<strong><a class="row-title" href="'
187
-                   . $edit_link . '">'
188
-                   . $item->name()
189
-                   . '</a></strong>'
190
-                   . $status;
191
-        $content .= '<br><span class="ee-status-text-small">'
192
-                    . EEH_Template::pretty_status(
193
-                        $item->get_active_status(),
194
-                        false,
195
-                        'sentence'
196
-                    )
197
-                    . '</span>';
198
-        $content .= $this->row_actions($actions);
199
-        return $content;
200
-    }
201
-
202
-
203
-    /**
204
-     * Just a method for setting up the actions for the name column
205
-     *
206
-     * @param EE_Event $item
207
-     * @return array array of actions
208
-     * @throws EE_Error
209
-     * @throws InvalidArgumentException
210
-     * @throws InvalidDataTypeException
211
-     * @throws InvalidInterfaceException
212
-     */
213
-    protected function _column_name_action_setup(EE_Event $item)
214
-    {
215
-        // todo: remove when attendees is active
216
-        if (! defined('REG_ADMIN_URL')) {
217
-            define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
218
-        }
219
-        $actions = array();
220
-        $restore_event_link = '';
221
-        $delete_event_link = '';
222
-        $trash_event_link = '';
223
-        if (
224
-            EE_Registry::instance()->CAP->current_user_can(
225
-                'ee_edit_event',
226
-                'espresso_events_edit',
227
-                $item->ID()
228
-            )
229
-        ) {
230
-            $edit_query_args = array(
231
-                'action' => 'edit',
232
-                'post'   => $item->ID(),
233
-            );
234
-            $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
235
-            $actions['edit'] = '<a href="' . $edit_link . '"'
236
-                               . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
237
-                               . esc_html__('Edit', 'event_espresso')
238
-                               . '</a>';
239
-        }
240
-        if (
241
-            EE_Registry::instance()->CAP->current_user_can(
242
-                'ee_read_registrations',
243
-                'espresso_registrations_view_registration'
244
-            )
245
-            && EE_Registry::instance()->CAP->current_user_can(
246
-                'ee_read_event',
247
-                'espresso_registrations_view_registration',
248
-                $item->ID()
249
-            )
250
-        ) {
251
-            $attendees_query_args = array(
252
-                'action'   => 'default',
253
-                'event_id' => $item->ID(),
254
-            );
255
-            $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
256
-            $actions['attendees'] = '<a href="' . $attendees_link . '"'
257
-                                    . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">'
258
-                                    . esc_html__('Registrations', 'event_espresso')
259
-                                    . '</a>';
260
-        }
261
-        if (
262
-            EE_Registry::instance()->CAP->current_user_can(
263
-                'ee_delete_event',
264
-                'espresso_events_trash_event',
265
-                $item->ID()
266
-            )
267
-        ) {
268
-            $trash_event_query_args = array(
269
-                'action' => 'trash_event',
270
-                'EVT_ID' => $item->ID(),
271
-            );
272
-            $trash_event_link = EE_Admin_Page::add_query_args_and_nonce(
273
-                $trash_event_query_args,
274
-                EVENTS_ADMIN_URL
275
-            );
276
-        }
277
-        if (
278
-            EE_Registry::instance()->CAP->current_user_can(
279
-                'ee_delete_event',
280
-                'espresso_events_restore_event',
281
-                $item->ID()
282
-            )
283
-        ) {
284
-            $restore_event_query_args = array(
285
-                'action' => 'restore_event',
286
-                'EVT_ID' => $item->ID(),
287
-            );
288
-            $restore_event_link = EE_Admin_Page::add_query_args_and_nonce(
289
-                $restore_event_query_args,
290
-                EVENTS_ADMIN_URL
291
-            );
292
-        }
293
-        if (
294
-            EE_Registry::instance()->CAP->current_user_can(
295
-                'ee_delete_event',
296
-                'espresso_events_delete_event',
297
-                $item->ID()
298
-            )
299
-        ) {
300
-            $delete_event_query_args = array(
301
-                'action' => 'delete_event',
302
-                'EVT_ID' => $item->ID(),
303
-            );
304
-            $delete_event_link = EE_Admin_Page::add_query_args_and_nonce(
305
-                $delete_event_query_args,
306
-                EVENTS_ADMIN_URL
307
-            );
308
-        }
309
-        $view_link = get_permalink($item->ID());
310
-        $actions['view'] = '<a href="' . $view_link . '"'
311
-                           . ' title="' . esc_attr__('View Event', 'event_espresso') . '">'
312
-                           . esc_html__('View', 'event_espresso')
313
-                           . '</a>';
314
-        if ($item->get('status') === 'trash') {
315
-            if (
316
-                EE_Registry::instance()->CAP->current_user_can(
317
-                    'ee_delete_event',
318
-                    'espresso_events_restore_event',
319
-                    $item->ID()
320
-                )
321
-            ) {
322
-                $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"'
323
-                                                 . ' title="' . esc_attr__('Restore from Trash', 'event_espresso')
324
-                                                 . '">'
325
-                                                 . esc_html__('Restore from Trash', 'event_espresso')
326
-                                                 . '</a>';
327
-            }
328
-            if (
329
-                EE_Registry::instance()->CAP->current_user_can(
330
-                    'ee_delete_event',
331
-                    'espresso_events_delete_event',
332
-                    $item->ID()
333
-                )
334
-            ) {
335
-                $actions['delete'] = '<a href="' . $delete_event_link . '"'
336
-                                     . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">'
337
-                                     . esc_html__('Delete Permanently', 'event_espresso')
338
-                                     . '</a>';
339
-            }
340
-        } else {
341
-            if (
342
-                EE_Registry::instance()->CAP->current_user_can(
343
-                    'ee_delete_event',
344
-                    'espresso_events_trash_event',
345
-                    $item->ID()
346
-                )
347
-            ) {
348
-                $actions['move to trash'] = '<a href="' . $trash_event_link . '"'
349
-                                            . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">'
350
-                                            . esc_html__('Trash', 'event_espresso')
351
-                                            . '</a>';
352
-            }
353
-        }
354
-        return $actions;
355
-    }
356
-
357
-
358
-    /**
359
-     * @param EE_Event $item
360
-     * @return string
361
-     * @throws EE_Error
362
-     */
363
-    public function column_author(EE_Event $item)
364
-    {
365
-        // user author info
366
-        $event_author = get_userdata($item->wp_user());
367
-        $gravatar = get_avatar($item->wp_user(), '15');
368
-        // filter link
369
-        $query_args = array(
370
-            'action'      => 'default',
371
-            'EVT_wp_user' => $item->wp_user(),
372
-        );
373
-        $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);
374
-        return $gravatar . '  <a href="' . $filter_url . '"'
375
-               . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">'
376
-               . $event_author->display_name
377
-               . '</a>';
378
-    }
379
-
380
-
381
-    /**
382
-     * @param EE_Event $event
383
-     * @return string
384
-     * @throws EE_Error
385
-     */
386
-    public function column_event_category(EE_Event $event)
387
-    {
388
-        $event_categories = $event->get_all_event_categories();
389
-        return implode(
390
-            ', ',
391
-            array_map(
392
-                function (EE_Term $category) {
393
-                    return $category->name();
394
-                },
395
-                $event_categories
396
-            )
397
-        );
398
-    }
399
-
400
-
401
-    /**
402
-     * @param EE_Event $item
403
-     * @return string
404
-     * @throws EE_Error
405
-     */
406
-    public function column_venue(EE_Event $item)
407
-    {
408
-        $venue = $item->get_first_related('Venue');
409
-        return ! empty($venue)
410
-            ? $venue->name()
411
-            : '';
412
-    }
413
-
414
-
415
-    /**
416
-     * @param EE_Event $item
417
-     * @return string
418
-     * @throws EE_Error
419
-     */
420
-    public function column_start_date_time(EE_Event $item)
421
-    {
422
-        return $this->_dtt instanceof EE_Datetime
423
-            ? $this->_dtt->get_i18n_datetime('DTT_EVT_start')
424
-            : esc_html__('No Date was saved for this Event', 'event_espresso');
425
-    }
426
-
427
-
428
-    /**
429
-     * @param EE_Event $item
430
-     * @return string
431
-     * @throws EE_Error
432
-     */
433
-    public function column_reg_begins(EE_Event $item)
434
-    {
435
-        $reg_start = $item->get_ticket_with_earliest_start_time();
436
-        return $reg_start instanceof EE_Ticket
437
-            ? $reg_start->get_i18n_datetime('TKT_start_date')
438
-            : esc_html__('No Tickets have been setup for this Event', 'event_espresso');
439
-    }
440
-
441
-
442
-    /**
443
-     * @param EE_Event $item
444
-     * @return int|string
445
-     * @throws EE_Error
446
-     * @throws InvalidArgumentException
447
-     * @throws InvalidDataTypeException
448
-     * @throws InvalidInterfaceException
449
-     */
450
-    public function column_attendees(EE_Event $item)
451
-    {
452
-        $attendees_query_args = array(
453
-            'action'   => 'default',
454
-            'event_id' => $item->ID(),
455
-        );
456
-        $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
457
-        $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID());
458
-        return EE_Registry::instance()->CAP->current_user_can(
459
-            'ee_read_event',
460
-            'espresso_registrations_view_registration',
461
-            $item->ID()
462
-        )
463
-               && EE_Registry::instance()->CAP->current_user_can(
464
-                   'ee_read_registrations',
465
-                   'espresso_registrations_view_registration'
466
-               )
467
-            ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'
468
-            : $registered_attendees;
469
-    }
470
-
471
-
472
-    /**
473
-     * @param EE_Event $item
474
-     * @return float
475
-     * @throws EE_Error
476
-     * @throws InvalidArgumentException
477
-     * @throws InvalidDataTypeException
478
-     * @throws InvalidInterfaceException
479
-     */
480
-    public function column_tkts_sold(EE_Event $item)
481
-    {
482
-        return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold');
483
-    }
484
-
485
-
486
-    /**
487
-     * @param EE_Event $item
488
-     * @return string
489
-     * @throws EE_Error
490
-     * @throws InvalidArgumentException
491
-     * @throws InvalidDataTypeException
492
-     * @throws InvalidInterfaceException
493
-     */
494
-    public function column_actions(EE_Event $item)
495
-    {
496
-        // todo: remove when attendees is active
497
-        if (! defined('REG_ADMIN_URL')) {
498
-            define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
499
-        }
500
-        $action_links = array();
501
-        $view_link = get_permalink($item->ID());
502
-        $action_links[] = '<a href="' . $view_link . '"'
503
-                          . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">';
504
-        $action_links[] = '<div class="dashicons dashicons-search"></div></a>';
505
-        if (
506
-            EE_Registry::instance()->CAP->current_user_can(
507
-                'ee_edit_event',
508
-                'espresso_events_edit',
509
-                $item->ID()
510
-            )
511
-        ) {
512
-            $edit_query_args = array(
513
-                'action' => 'edit',
514
-                'post'   => $item->ID(),
515
-            );
516
-            $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
517
-            $action_links[] = '<a href="' . $edit_link . '"'
518
-                              . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
519
-                              . '<div class="ee-icon ee-icon-calendar-edit"></div>'
520
-                              . '</a>';
521
-        }
522
-        if (
523
-            EE_Registry::instance()->CAP->current_user_can(
524
-                'ee_read_registrations',
525
-                'espresso_registrations_view_registration'
526
-            ) && EE_Registry::instance()->CAP->current_user_can(
527
-                'ee_read_event',
528
-                'espresso_registrations_view_registration',
529
-                $item->ID()
530
-            )
531
-        ) {
532
-            $attendees_query_args = array(
533
-                'action'   => 'default',
534
-                'event_id' => $item->ID(),
535
-            );
536
-            $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
537
-            $action_links[] = '<a href="' . $attendees_link . '"'
538
-                              . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">'
539
-                              . '<div class="dashicons dashicons-groups"></div>'
540
-                              . '</a>';
541
-        }
542
-        $action_links = apply_filters(
543
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
544
-            $action_links,
545
-            $item
546
-        );
547
-        return $this->_action_string(
548
-            implode("\n\t", $action_links),
549
-            $item,
550
-            'div'
551
-        );
552
-    }
553
-
554
-
555
-    /**
556
-     * Helper for adding columns conditionally
557
-     *
558
-     * @throws EE_Error
559
-     * @throws InvalidArgumentException
560
-     * @throws InvalidDataTypeException
561
-     * @throws InvalidInterfaceException
562
-     */
563
-    private function addConditionalColumns()
564
-    {
565
-        $event_category_count = EEM_Term::instance()->count(
566
-            [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]]
567
-        );
568
-        if ($event_category_count === 0) {
569
-            return;
570
-        }
571
-        $column_array = [];
572
-        foreach ($this->_columns as $column => $column_label) {
573
-            $column_array[ $column ] = $column_label;
574
-            if ($column === 'venue') {
575
-                $column_array['event_category'] = esc_html__('Event Category', 'event_espresso');
576
-            }
577
-        }
578
-        $this->_columns = $column_array;
579
-    }
17
+	/**
18
+	 * @var EE_Datetime
19
+	 */
20
+	private $_dtt;
21
+
22
+
23
+	/**
24
+	 * Initial setup of data properties for the list table.
25
+	 */
26
+	protected function _setup_data()
27
+	{
28
+		$this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page);
29
+		$this->_all_data_count = $this->_admin_page->get_events(0, 0, true);
30
+	}
31
+
32
+
33
+	/**
34
+	 * Set up of additional properties for the list table.
35
+	 */
36
+	protected function _set_properties()
37
+	{
38
+		$this->_wp_list_args = array(
39
+			'singular' => esc_html__('event', 'event_espresso'),
40
+			'plural'   => esc_html__('events', 'event_espresso'),
41
+			'ajax'     => true, // for now
42
+			'screen'   => $this->_admin_page->get_current_screen()->id,
43
+		);
44
+		$this->_columns = array(
45
+			'cb'              => '<input type="checkbox" />',
46
+			'id'              => esc_html__('ID', 'event_espresso'),
47
+			'name'            => esc_html__('Name', 'event_espresso'),
48
+			'author'          => esc_html__('Author', 'event_espresso'),
49
+			'venue'           => esc_html__('Venue', 'event_espresso'),
50
+			'start_date_time' => esc_html__('Event Start', 'event_espresso'),
51
+			'reg_begins'      => esc_html__('On Sale', 'event_espresso'),
52
+			'attendees'       => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">'
53
+								 . '<span class="screen-reader-text">'
54
+								 . esc_html__('Approved Registrations', 'event_espresso')
55
+								 . '</span>'
56
+								 . '</span>',
57
+			// 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'),
58
+			'actions'         => esc_html__('Actions', 'event_espresso'),
59
+		);
60
+		$this->addConditionalColumns();
61
+		$this->_sortable_columns = array(
62
+			'id'              => array('EVT_ID' => true),
63
+			'name'            => array('EVT_name' => false),
64
+			'author'          => array('EVT_wp_user' => false),
65
+			'venue'           => array('Venue.VNU_name' => false),
66
+			'start_date_time' => array('Datetime.DTT_EVT_start' => false),
67
+			'reg_begins'      => array('Datetime.Ticket.TKT_start_date' => false),
68
+		);
69
+
70
+		$this->_primary_column = 'id';
71
+		$this->_hidden_columns = array('author', 'event_category');
72
+	}
73
+
74
+
75
+	/**
76
+	 * @return array
77
+	 */
78
+	protected function _get_table_filters()
79
+	{
80
+		return array(); // no filters with decaf
81
+	}
82
+
83
+
84
+	/**
85
+	 * Setup of views properties.
86
+	 *
87
+	 * @throws InvalidDataTypeException
88
+	 * @throws InvalidInterfaceException
89
+	 * @throws InvalidArgumentException
90
+	 */
91
+	protected function _add_view_counts()
92
+	{
93
+		$this->_views['all']['count'] = $this->_admin_page->total_events();
94
+		$this->_views['draft']['count'] = $this->_admin_page->total_events_draft();
95
+		if (
96
+			EE_Registry::instance()->CAP->current_user_can(
97
+				'ee_delete_events',
98
+				'espresso_events_trash_events'
99
+			)
100
+		) {
101
+			$this->_views['trash']['count'] = $this->_admin_page->total_trashed_events();
102
+		}
103
+	}
104
+
105
+
106
+	/**
107
+	 * @param EE_Event $item
108
+	 * @return string
109
+	 * @throws EE_Error
110
+	 */
111
+	protected function _get_row_class($item)
112
+	{
113
+		$class = parent::_get_row_class($item);
114
+		// add status class
115
+		$class .= $item instanceof EE_Event
116
+			? ' ee-status-strip event-status-' . $item->get_active_status()
117
+			: '';
118
+		if ($this->_has_checkbox_column) {
119
+			$class .= ' has-checkbox-column';
120
+		}
121
+		return $class;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @param EE_Event $item
127
+	 * @return string
128
+	 * @throws EE_Error
129
+	 */
130
+	public function column_status(EE_Event $item)
131
+	{
132
+		return '<span class="ee-status-strip ee-status-strip-td event-status-'
133
+			   . $item->get_active_status()
134
+			   . '"></span>';
135
+	}
136
+
137
+
138
+	/**
139
+	 * @param  EE_Event $item
140
+	 * @return string
141
+	 * @throws EE_Error
142
+	 */
143
+	public function column_cb($item)
144
+	{
145
+		if (! $item instanceof EE_Event) {
146
+			return '';
147
+		}
148
+		$this->_dtt = $item->primary_datetime(); // set this for use in other columns
149
+		return sprintf(
150
+			'<input type="checkbox" name="EVT_IDs[]" value="%s" />',
151
+			$item->ID()
152
+		);
153
+	}
154
+
155
+
156
+	/**
157
+	 * @param EE_Event $item
158
+	 * @return mixed|string
159
+	 * @throws EE_Error
160
+	 */
161
+	public function column_id(EE_Event $item)
162
+	{
163
+		$content = $item->ID();
164
+		$content .= '  <span class="show-on-mobile-view-only">' . $item->name() . '</span>';
165
+		return $content;
166
+	}
167
+
168
+
169
+	/**
170
+	 * @param EE_Event $item
171
+	 * @return string
172
+	 * @throws EE_Error
173
+	 * @throws InvalidArgumentException
174
+	 * @throws InvalidDataTypeException
175
+	 * @throws InvalidInterfaceException
176
+	 */
177
+	public function column_name(EE_Event $item)
178
+	{
179
+		$edit_query_args = array(
180
+			'action' => 'edit',
181
+			'post'   => $item->ID(),
182
+		);
183
+		$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
184
+		$actions = $this->_column_name_action_setup($item);
185
+		$status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : '';
186
+		$content = '<strong><a class="row-title" href="'
187
+				   . $edit_link . '">'
188
+				   . $item->name()
189
+				   . '</a></strong>'
190
+				   . $status;
191
+		$content .= '<br><span class="ee-status-text-small">'
192
+					. EEH_Template::pretty_status(
193
+						$item->get_active_status(),
194
+						false,
195
+						'sentence'
196
+					)
197
+					. '</span>';
198
+		$content .= $this->row_actions($actions);
199
+		return $content;
200
+	}
201
+
202
+
203
+	/**
204
+	 * Just a method for setting up the actions for the name column
205
+	 *
206
+	 * @param EE_Event $item
207
+	 * @return array array of actions
208
+	 * @throws EE_Error
209
+	 * @throws InvalidArgumentException
210
+	 * @throws InvalidDataTypeException
211
+	 * @throws InvalidInterfaceException
212
+	 */
213
+	protected function _column_name_action_setup(EE_Event $item)
214
+	{
215
+		// todo: remove when attendees is active
216
+		if (! defined('REG_ADMIN_URL')) {
217
+			define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
218
+		}
219
+		$actions = array();
220
+		$restore_event_link = '';
221
+		$delete_event_link = '';
222
+		$trash_event_link = '';
223
+		if (
224
+			EE_Registry::instance()->CAP->current_user_can(
225
+				'ee_edit_event',
226
+				'espresso_events_edit',
227
+				$item->ID()
228
+			)
229
+		) {
230
+			$edit_query_args = array(
231
+				'action' => 'edit',
232
+				'post'   => $item->ID(),
233
+			);
234
+			$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
235
+			$actions['edit'] = '<a href="' . $edit_link . '"'
236
+							   . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
237
+							   . esc_html__('Edit', 'event_espresso')
238
+							   . '</a>';
239
+		}
240
+		if (
241
+			EE_Registry::instance()->CAP->current_user_can(
242
+				'ee_read_registrations',
243
+				'espresso_registrations_view_registration'
244
+			)
245
+			&& EE_Registry::instance()->CAP->current_user_can(
246
+				'ee_read_event',
247
+				'espresso_registrations_view_registration',
248
+				$item->ID()
249
+			)
250
+		) {
251
+			$attendees_query_args = array(
252
+				'action'   => 'default',
253
+				'event_id' => $item->ID(),
254
+			);
255
+			$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
256
+			$actions['attendees'] = '<a href="' . $attendees_link . '"'
257
+									. ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">'
258
+									. esc_html__('Registrations', 'event_espresso')
259
+									. '</a>';
260
+		}
261
+		if (
262
+			EE_Registry::instance()->CAP->current_user_can(
263
+				'ee_delete_event',
264
+				'espresso_events_trash_event',
265
+				$item->ID()
266
+			)
267
+		) {
268
+			$trash_event_query_args = array(
269
+				'action' => 'trash_event',
270
+				'EVT_ID' => $item->ID(),
271
+			);
272
+			$trash_event_link = EE_Admin_Page::add_query_args_and_nonce(
273
+				$trash_event_query_args,
274
+				EVENTS_ADMIN_URL
275
+			);
276
+		}
277
+		if (
278
+			EE_Registry::instance()->CAP->current_user_can(
279
+				'ee_delete_event',
280
+				'espresso_events_restore_event',
281
+				$item->ID()
282
+			)
283
+		) {
284
+			$restore_event_query_args = array(
285
+				'action' => 'restore_event',
286
+				'EVT_ID' => $item->ID(),
287
+			);
288
+			$restore_event_link = EE_Admin_Page::add_query_args_and_nonce(
289
+				$restore_event_query_args,
290
+				EVENTS_ADMIN_URL
291
+			);
292
+		}
293
+		if (
294
+			EE_Registry::instance()->CAP->current_user_can(
295
+				'ee_delete_event',
296
+				'espresso_events_delete_event',
297
+				$item->ID()
298
+			)
299
+		) {
300
+			$delete_event_query_args = array(
301
+				'action' => 'delete_event',
302
+				'EVT_ID' => $item->ID(),
303
+			);
304
+			$delete_event_link = EE_Admin_Page::add_query_args_and_nonce(
305
+				$delete_event_query_args,
306
+				EVENTS_ADMIN_URL
307
+			);
308
+		}
309
+		$view_link = get_permalink($item->ID());
310
+		$actions['view'] = '<a href="' . $view_link . '"'
311
+						   . ' title="' . esc_attr__('View Event', 'event_espresso') . '">'
312
+						   . esc_html__('View', 'event_espresso')
313
+						   . '</a>';
314
+		if ($item->get('status') === 'trash') {
315
+			if (
316
+				EE_Registry::instance()->CAP->current_user_can(
317
+					'ee_delete_event',
318
+					'espresso_events_restore_event',
319
+					$item->ID()
320
+				)
321
+			) {
322
+				$actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"'
323
+												 . ' title="' . esc_attr__('Restore from Trash', 'event_espresso')
324
+												 . '">'
325
+												 . esc_html__('Restore from Trash', 'event_espresso')
326
+												 . '</a>';
327
+			}
328
+			if (
329
+				EE_Registry::instance()->CAP->current_user_can(
330
+					'ee_delete_event',
331
+					'espresso_events_delete_event',
332
+					$item->ID()
333
+				)
334
+			) {
335
+				$actions['delete'] = '<a href="' . $delete_event_link . '"'
336
+									 . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">'
337
+									 . esc_html__('Delete Permanently', 'event_espresso')
338
+									 . '</a>';
339
+			}
340
+		} else {
341
+			if (
342
+				EE_Registry::instance()->CAP->current_user_can(
343
+					'ee_delete_event',
344
+					'espresso_events_trash_event',
345
+					$item->ID()
346
+				)
347
+			) {
348
+				$actions['move to trash'] = '<a href="' . $trash_event_link . '"'
349
+											. ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">'
350
+											. esc_html__('Trash', 'event_espresso')
351
+											. '</a>';
352
+			}
353
+		}
354
+		return $actions;
355
+	}
356
+
357
+
358
+	/**
359
+	 * @param EE_Event $item
360
+	 * @return string
361
+	 * @throws EE_Error
362
+	 */
363
+	public function column_author(EE_Event $item)
364
+	{
365
+		// user author info
366
+		$event_author = get_userdata($item->wp_user());
367
+		$gravatar = get_avatar($item->wp_user(), '15');
368
+		// filter link
369
+		$query_args = array(
370
+			'action'      => 'default',
371
+			'EVT_wp_user' => $item->wp_user(),
372
+		);
373
+		$filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);
374
+		return $gravatar . '  <a href="' . $filter_url . '"'
375
+			   . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">'
376
+			   . $event_author->display_name
377
+			   . '</a>';
378
+	}
379
+
380
+
381
+	/**
382
+	 * @param EE_Event $event
383
+	 * @return string
384
+	 * @throws EE_Error
385
+	 */
386
+	public function column_event_category(EE_Event $event)
387
+	{
388
+		$event_categories = $event->get_all_event_categories();
389
+		return implode(
390
+			', ',
391
+			array_map(
392
+				function (EE_Term $category) {
393
+					return $category->name();
394
+				},
395
+				$event_categories
396
+			)
397
+		);
398
+	}
399
+
400
+
401
+	/**
402
+	 * @param EE_Event $item
403
+	 * @return string
404
+	 * @throws EE_Error
405
+	 */
406
+	public function column_venue(EE_Event $item)
407
+	{
408
+		$venue = $item->get_first_related('Venue');
409
+		return ! empty($venue)
410
+			? $venue->name()
411
+			: '';
412
+	}
413
+
414
+
415
+	/**
416
+	 * @param EE_Event $item
417
+	 * @return string
418
+	 * @throws EE_Error
419
+	 */
420
+	public function column_start_date_time(EE_Event $item)
421
+	{
422
+		return $this->_dtt instanceof EE_Datetime
423
+			? $this->_dtt->get_i18n_datetime('DTT_EVT_start')
424
+			: esc_html__('No Date was saved for this Event', 'event_espresso');
425
+	}
426
+
427
+
428
+	/**
429
+	 * @param EE_Event $item
430
+	 * @return string
431
+	 * @throws EE_Error
432
+	 */
433
+	public function column_reg_begins(EE_Event $item)
434
+	{
435
+		$reg_start = $item->get_ticket_with_earliest_start_time();
436
+		return $reg_start instanceof EE_Ticket
437
+			? $reg_start->get_i18n_datetime('TKT_start_date')
438
+			: esc_html__('No Tickets have been setup for this Event', 'event_espresso');
439
+	}
440
+
441
+
442
+	/**
443
+	 * @param EE_Event $item
444
+	 * @return int|string
445
+	 * @throws EE_Error
446
+	 * @throws InvalidArgumentException
447
+	 * @throws InvalidDataTypeException
448
+	 * @throws InvalidInterfaceException
449
+	 */
450
+	public function column_attendees(EE_Event $item)
451
+	{
452
+		$attendees_query_args = array(
453
+			'action'   => 'default',
454
+			'event_id' => $item->ID(),
455
+		);
456
+		$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
457
+		$registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID());
458
+		return EE_Registry::instance()->CAP->current_user_can(
459
+			'ee_read_event',
460
+			'espresso_registrations_view_registration',
461
+			$item->ID()
462
+		)
463
+			   && EE_Registry::instance()->CAP->current_user_can(
464
+				   'ee_read_registrations',
465
+				   'espresso_registrations_view_registration'
466
+			   )
467
+			? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'
468
+			: $registered_attendees;
469
+	}
470
+
471
+
472
+	/**
473
+	 * @param EE_Event $item
474
+	 * @return float
475
+	 * @throws EE_Error
476
+	 * @throws InvalidArgumentException
477
+	 * @throws InvalidDataTypeException
478
+	 * @throws InvalidInterfaceException
479
+	 */
480
+	public function column_tkts_sold(EE_Event $item)
481
+	{
482
+		return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold');
483
+	}
484
+
485
+
486
+	/**
487
+	 * @param EE_Event $item
488
+	 * @return string
489
+	 * @throws EE_Error
490
+	 * @throws InvalidArgumentException
491
+	 * @throws InvalidDataTypeException
492
+	 * @throws InvalidInterfaceException
493
+	 */
494
+	public function column_actions(EE_Event $item)
495
+	{
496
+		// todo: remove when attendees is active
497
+		if (! defined('REG_ADMIN_URL')) {
498
+			define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
499
+		}
500
+		$action_links = array();
501
+		$view_link = get_permalink($item->ID());
502
+		$action_links[] = '<a href="' . $view_link . '"'
503
+						  . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">';
504
+		$action_links[] = '<div class="dashicons dashicons-search"></div></a>';
505
+		if (
506
+			EE_Registry::instance()->CAP->current_user_can(
507
+				'ee_edit_event',
508
+				'espresso_events_edit',
509
+				$item->ID()
510
+			)
511
+		) {
512
+			$edit_query_args = array(
513
+				'action' => 'edit',
514
+				'post'   => $item->ID(),
515
+			);
516
+			$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
517
+			$action_links[] = '<a href="' . $edit_link . '"'
518
+							  . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
519
+							  . '<div class="ee-icon ee-icon-calendar-edit"></div>'
520
+							  . '</a>';
521
+		}
522
+		if (
523
+			EE_Registry::instance()->CAP->current_user_can(
524
+				'ee_read_registrations',
525
+				'espresso_registrations_view_registration'
526
+			) && EE_Registry::instance()->CAP->current_user_can(
527
+				'ee_read_event',
528
+				'espresso_registrations_view_registration',
529
+				$item->ID()
530
+			)
531
+		) {
532
+			$attendees_query_args = array(
533
+				'action'   => 'default',
534
+				'event_id' => $item->ID(),
535
+			);
536
+			$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
537
+			$action_links[] = '<a href="' . $attendees_link . '"'
538
+							  . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">'
539
+							  . '<div class="dashicons dashicons-groups"></div>'
540
+							  . '</a>';
541
+		}
542
+		$action_links = apply_filters(
543
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
544
+			$action_links,
545
+			$item
546
+		);
547
+		return $this->_action_string(
548
+			implode("\n\t", $action_links),
549
+			$item,
550
+			'div'
551
+		);
552
+	}
553
+
554
+
555
+	/**
556
+	 * Helper for adding columns conditionally
557
+	 *
558
+	 * @throws EE_Error
559
+	 * @throws InvalidArgumentException
560
+	 * @throws InvalidDataTypeException
561
+	 * @throws InvalidInterfaceException
562
+	 */
563
+	private function addConditionalColumns()
564
+	{
565
+		$event_category_count = EEM_Term::instance()->count(
566
+			[['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]]
567
+		);
568
+		if ($event_category_count === 0) {
569
+			return;
570
+		}
571
+		$column_array = [];
572
+		foreach ($this->_columns as $column => $column_label) {
573
+			$column_array[ $column ] = $column_label;
574
+			if ($column === 'venue') {
575
+				$column_array['event_category'] = esc_html__('Event Category', 'event_espresso');
576
+			}
577
+		}
578
+		$this->_columns = $column_array;
579
+	}
580 580
 }
Please login to merge, or discard this patch.
admin_pages/registrations/EE_Attendee_Contact_List_Table.class.php 2 patches
Indentation   +378 added lines, -378 removed lines patch added patch discarded remove patch
@@ -12,382 +12,382 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Attendee_Contact_List_Table extends EE_Admin_List_Table
14 14
 {
15
-    /**
16
-     * Initial setup of data (called by parent).
17
-     */
18
-    protected function _setup_data()
19
-    {
20
-        $this->_data = $this->_view !== 'trash'
21
-            ? $this->_admin_page->get_attendees($this->_per_page)
22
-            : $this->_admin_page->get_attendees($this->_per_page, false, true);
23
-        $this->_all_data_count = $this->_view !== 'trash'
24
-            ? $this->_admin_page->get_attendees($this->_per_page, true)
25
-            : $this->_admin_page->get_attendees($this->_per_page, true, true);
26
-    }
27
-
28
-
29
-    /**
30
-     * Initial setup of properties.
31
-     */
32
-    protected function _set_properties()
33
-    {
34
-        $this->_wp_list_args = array(
35
-            'singular' => esc_html__('attendee', 'event_espresso'),
36
-            'plural'   => esc_html__('attendees', 'event_espresso'),
37
-            'ajax'     => true,
38
-            'screen'   => $this->_admin_page->get_current_screen()->id,
39
-        );
40
-
41
-        $this->_columns = array(
42
-            'cb'                 => '<input type="checkbox" />', // Render a checkbox instead of text
43
-            'ATT_ID'             => esc_html__('ID', 'event_espresso'),
44
-            'ATT_fname'          => esc_html__('First Name', 'event_espresso'),
45
-            'ATT_lname'          => esc_html__('Last Name', 'event_espresso'),
46
-            'ATT_email'          => esc_html__('Email Address', 'event_espresso'),
47
-            'Registration_Count' => esc_html__('# Registrations', 'event_espresso'),
48
-            'ATT_phone'          => esc_html__('Phone', 'event_espresso'),
49
-            'ATT_address'        => esc_html__('Address', 'event_espresso'),
50
-            'ATT_city'           => esc_html__('City', 'event_espresso'),
51
-            'STA_ID'             => esc_html__('State/Province', 'event_espresso'),
52
-            'CNT_ISO'            => esc_html__('Country', 'event_espresso'),
53
-        );
54
-
55
-        $this->_sortable_columns = array(
56
-            'ATT_ID'             => array('ATT_ID' => false),
57
-            'ATT_lname'          => array('ATT_lname' => true), // true means its already sorted
58
-            'ATT_fname'          => array('ATT_fname' => false),
59
-            'ATT_email'          => array('ATT_email' => false),
60
-            'Registration_Count' => array('Registration_Count' => false),
61
-            'ATT_city'           => array('ATT_city' => false),
62
-            'STA_ID'             => array('STA_ID' => false),
63
-            'CNT_ISO'            => array('CNT_ISO' => false),
64
-        );
65
-
66
-        $this->_hidden_columns = array(
67
-            'ATT_phone',
68
-            'ATT_address',
69
-            'ATT_city',
70
-            'STA_ID',
71
-            'CNT_ISO',
72
-        );
73
-    }
74
-
75
-
76
-    /**
77
-     * Initial setup of filters
78
-     *
79
-     * @return array
80
-     */
81
-    protected function _get_table_filters()
82
-    {
83
-        return array();
84
-    }
85
-
86
-
87
-    /**
88
-     * Initial setup of counts for views
89
-     *
90
-     * @throws InvalidArgumentException
91
-     * @throws InvalidDataTypeException
92
-     * @throws InvalidInterfaceException
93
-     */
94
-    protected function _add_view_counts()
95
-    {
96
-        $this->_views['in_use']['count'] = $this->_admin_page->get_attendees($this->_per_page, true);
97
-        if (
98
-            EE_Registry::instance()->CAP->current_user_can(
99
-                'ee_delete_contacts',
100
-                'espresso_registrations_delete_registration'
101
-            )
102
-        ) {
103
-            $this->_views['trash']['count'] = $this->_admin_page->get_attendees($this->_per_page, true, true);
104
-        }
105
-    }
106
-
107
-
108
-    /**
109
-     * Get count of attendees.
110
-     *
111
-     * @return int
112
-     * @throws EE_Error
113
-     * @throws InvalidArgumentException
114
-     * @throws InvalidDataTypeException
115
-     * @throws InvalidInterfaceException
116
-     */
117
-    protected function _get_attendees_count()
118
-    {
119
-        return EEM_Attendee::instance()->count();
120
-    }
121
-
122
-
123
-    /**
124
-     * Checkbox column
125
-     *
126
-     * @param EE_Attendee $attendee Unable to typehint this method because overrides parent.
127
-     * @return string
128
-     * @throws EE_Error
129
-     */
130
-    public function column_cb($attendee)
131
-    {
132
-        if (! $attendee instanceof EE_Attendee) {
133
-            return '';
134
-        }
135
-        return sprintf(
136
-            '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />',
137
-            $attendee->ID()
138
-        );
139
-    }
140
-
141
-
142
-    /**
143
-     * ATT_ID column
144
-     *
145
-     * @param EE_Attendee $attendee
146
-     * @return string
147
-     * @throws EE_Error
148
-     */
149
-    public function column_ATT_ID(EE_Attendee $attendee)
150
-    {
151
-        $content = $attendee->ID();
152
-        $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
153
-        $content .= '  <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
154
-        return $content;
155
-    }
156
-
157
-
158
-    /**
159
-     * ATT_lname column
160
-     *
161
-     * @param EE_Attendee $attendee
162
-     * @return string
163
-     * @throws InvalidArgumentException
164
-     * @throws InvalidDataTypeException
165
-     * @throws InvalidInterfaceException
166
-     * @throws EE_Error
167
-     */
168
-    public function column_ATT_lname(EE_Attendee $attendee)
169
-    {
170
-        // edit attendee link
171
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
172
-            array(
173
-                'action' => 'edit_attendee',
174
-                'post'   => $attendee->ID(),
175
-            ),
176
-            REG_ADMIN_URL
177
-        );
178
-        $name_link = EE_Registry::instance()->CAP->current_user_can(
179
-            'ee_edit_contacts',
180
-            'espresso_registrations_edit_attendee'
181
-        )
182
-            ? '<a href="' . $edit_lnk_url . '" title="'
183
-              . esc_attr__('Edit Contact', 'event_espresso') . '">'
184
-              . $attendee->lname() . '</a>'
185
-            : $attendee->lname();
186
-        return $name_link;
187
-    }
188
-
189
-
190
-    /**
191
-     * ATT_fname column
192
-     *
193
-     * @param EE_Attendee $attendee
194
-     * @return string
195
-     * @throws InvalidArgumentException
196
-     * @throws InvalidDataTypeException
197
-     * @throws InvalidInterfaceException
198
-     * @throws EE_Error
199
-     */
200
-    public function column_ATT_fname(EE_Attendee $attendee)
201
-    {
202
-        // Build row actions
203
-        $actions = array();
204
-        // edit attendee link
205
-        if (
206
-            EE_Registry::instance()->CAP->current_user_can(
207
-                'ee_edit_contacts',
208
-                'espresso_registrations_edit_attendee'
209
-            )
210
-        ) {
211
-            $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
212
-                array(
213
-                    'action' => 'edit_attendee',
214
-                    'post'   => $attendee->ID(),
215
-                ),
216
-                REG_ADMIN_URL
217
-            );
218
-            $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="'
219
-                               . esc_attr__('Edit Contact', 'event_espresso') . '">'
220
-                               . esc_html__('Edit', 'event_espresso') . '</a>';
221
-        }
222
-
223
-        if ($this->_view === 'in_use') {
224
-            // trash attendee link
225
-            if (
226
-                EE_Registry::instance()->CAP->current_user_can(
227
-                    'ee_delete_contacts',
228
-                    'espresso_registrations_trash_attendees'
229
-                )
230
-            ) {
231
-                $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
232
-                    array(
233
-                        'action' => 'trash_attendee',
234
-                        'ATT_ID' => $attendee->ID(),
235
-                    ),
236
-                    REG_ADMIN_URL
237
-                );
238
-                $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="'
239
-                                    . esc_attr__('Move Contact to Trash', 'event_espresso')
240
-                                    . '">' . esc_html__('Trash', 'event_espresso') . '</a>';
241
-            }
242
-        } else {
243
-            if (
244
-                EE_Registry::instance()->CAP->current_user_can(
245
-                    'ee_delete_contacts',
246
-                    'espresso_registrations_restore_attendees'
247
-                )
248
-            ) {
249
-                // restore attendee link
250
-                $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
251
-                    array(
252
-                        'action' => 'restore_attendees',
253
-                        'ATT_ID' => $attendee->ID(),
254
-                    ),
255
-                    REG_ADMIN_URL
256
-                );
257
-                $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="'
258
-                                      . esc_attr__('Restore Contact', 'event_espresso') . '">'
259
-                                      . esc_html__('Restore', 'event_espresso') . '</a>';
260
-            }
261
-        }
262
-
263
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
264
-            array(
265
-                'action' => 'edit_attendee',
266
-                'post'   => $attendee->ID(),
267
-            ),
268
-            REG_ADMIN_URL
269
-        );
270
-        $name_link = EE_Registry::instance()->CAP->current_user_can(
271
-            'ee_edit_contacts',
272
-            'espresso_registrations_edit_attendee'
273
-        )
274
-            ? '<a href="' . $edit_lnk_url . '" title="'
275
-              . esc_attr__('Edit Contact', 'event_espresso') . '">' . $attendee->fname() . '</a>'
276
-            : $attendee->fname();
277
-
278
-        // Return the name contents
279
-        return sprintf('%1$s %2$s', $name_link, $this->row_actions($actions));
280
-    }
281
-
282
-
283
-    /**
284
-     * Email Column
285
-     *
286
-     * @param EE_Attendee $attendee
287
-     * @return string
288
-     * @throws EE_Error
289
-     */
290
-    public function column_ATT_email(EE_Attendee $attendee)
291
-    {
292
-        return '<a href="mailto:' . $attendee->email() . '">' . $attendee->email() . '</a>';
293
-    }
294
-
295
-
296
-    /**
297
-     * Column displaying count of registrations attached to Attendee.
298
-     *
299
-     * @param EE_Attendee $attendee
300
-     * @return string
301
-     * @throws EE_Error
302
-     */
303
-    public function column_Registration_Count(EE_Attendee $attendee)
304
-    {
305
-        $link = EEH_URL::add_query_args_and_nonce(
306
-            array(
307
-                'action' => 'default',
308
-                'ATT_ID' => $attendee->ID(),
309
-            ),
310
-            REG_ADMIN_URL
311
-        );
312
-        return '<a href="' . $link . '">' . $attendee->getCustomSelect('Registration_Count') . '</a>';
313
-    }
314
-
315
-
316
-    /**
317
-     * ATT_address column
318
-     *
319
-     * @param EE_Attendee $attendee
320
-     * @return mixed
321
-     * @throws EE_Error
322
-     */
323
-    public function column_ATT_address(EE_Attendee $attendee)
324
-    {
325
-        return $attendee->address();
326
-    }
327
-
328
-
329
-    /**
330
-     * ATT_city column
331
-     *
332
-     * @param EE_Attendee $attendee
333
-     * @return mixed
334
-     * @throws EE_Error
335
-     */
336
-    public function column_ATT_city(EE_Attendee $attendee)
337
-    {
338
-        return $attendee->city();
339
-    }
340
-
341
-
342
-    /**
343
-     * State Column
344
-     *
345
-     * @param EE_Attendee $attendee
346
-     * @return string
347
-     * @throws EE_Error
348
-     * @throws InvalidArgumentException
349
-     * @throws InvalidDataTypeException
350
-     * @throws InvalidInterfaceException
351
-     */
352
-    public function column_STA_ID(EE_Attendee $attendee)
353
-    {
354
-        $states = EEM_State::instance()->get_all_states();
355
-        $state = isset($states[ $attendee->state_ID() ])
356
-            ? $states[ $attendee->state_ID() ]->get('STA_name')
357
-            : $attendee->state_ID();
358
-        return ! is_numeric($state) ? $state : '';
359
-    }
360
-
361
-
362
-    /**
363
-     * Country Column
364
-     *
365
-     * @param EE_Attendee $attendee
366
-     * @return string
367
-     * @throws EE_Error
368
-     * @throws InvalidArgumentException
369
-     * @throws InvalidDataTypeException
370
-     * @throws InvalidInterfaceException
371
-     */
372
-    public function column_CNT_ISO(EE_Attendee $attendee)
373
-    {
374
-        $countries = EEM_Country::instance()->get_all_countries();
375
-        $country = isset($countries[ $attendee->country_ID() ])
376
-            ? $countries[ $attendee->country_ID() ]->get('CNT_name')
377
-            : $attendee->country_ID();
378
-        return ! is_numeric($country) ? $country : '';
379
-    }
380
-
381
-
382
-    /**
383
-     * Phone Number column
384
-     *
385
-     * @param EE_Attendee $attendee
386
-     * @return mixed
387
-     * @throws EE_Error
388
-     */
389
-    public function column_ATT_phone(EE_Attendee $attendee)
390
-    {
391
-        return $attendee->phone();
392
-    }
15
+	/**
16
+	 * Initial setup of data (called by parent).
17
+	 */
18
+	protected function _setup_data()
19
+	{
20
+		$this->_data = $this->_view !== 'trash'
21
+			? $this->_admin_page->get_attendees($this->_per_page)
22
+			: $this->_admin_page->get_attendees($this->_per_page, false, true);
23
+		$this->_all_data_count = $this->_view !== 'trash'
24
+			? $this->_admin_page->get_attendees($this->_per_page, true)
25
+			: $this->_admin_page->get_attendees($this->_per_page, true, true);
26
+	}
27
+
28
+
29
+	/**
30
+	 * Initial setup of properties.
31
+	 */
32
+	protected function _set_properties()
33
+	{
34
+		$this->_wp_list_args = array(
35
+			'singular' => esc_html__('attendee', 'event_espresso'),
36
+			'plural'   => esc_html__('attendees', 'event_espresso'),
37
+			'ajax'     => true,
38
+			'screen'   => $this->_admin_page->get_current_screen()->id,
39
+		);
40
+
41
+		$this->_columns = array(
42
+			'cb'                 => '<input type="checkbox" />', // Render a checkbox instead of text
43
+			'ATT_ID'             => esc_html__('ID', 'event_espresso'),
44
+			'ATT_fname'          => esc_html__('First Name', 'event_espresso'),
45
+			'ATT_lname'          => esc_html__('Last Name', 'event_espresso'),
46
+			'ATT_email'          => esc_html__('Email Address', 'event_espresso'),
47
+			'Registration_Count' => esc_html__('# Registrations', 'event_espresso'),
48
+			'ATT_phone'          => esc_html__('Phone', 'event_espresso'),
49
+			'ATT_address'        => esc_html__('Address', 'event_espresso'),
50
+			'ATT_city'           => esc_html__('City', 'event_espresso'),
51
+			'STA_ID'             => esc_html__('State/Province', 'event_espresso'),
52
+			'CNT_ISO'            => esc_html__('Country', 'event_espresso'),
53
+		);
54
+
55
+		$this->_sortable_columns = array(
56
+			'ATT_ID'             => array('ATT_ID' => false),
57
+			'ATT_lname'          => array('ATT_lname' => true), // true means its already sorted
58
+			'ATT_fname'          => array('ATT_fname' => false),
59
+			'ATT_email'          => array('ATT_email' => false),
60
+			'Registration_Count' => array('Registration_Count' => false),
61
+			'ATT_city'           => array('ATT_city' => false),
62
+			'STA_ID'             => array('STA_ID' => false),
63
+			'CNT_ISO'            => array('CNT_ISO' => false),
64
+		);
65
+
66
+		$this->_hidden_columns = array(
67
+			'ATT_phone',
68
+			'ATT_address',
69
+			'ATT_city',
70
+			'STA_ID',
71
+			'CNT_ISO',
72
+		);
73
+	}
74
+
75
+
76
+	/**
77
+	 * Initial setup of filters
78
+	 *
79
+	 * @return array
80
+	 */
81
+	protected function _get_table_filters()
82
+	{
83
+		return array();
84
+	}
85
+
86
+
87
+	/**
88
+	 * Initial setup of counts for views
89
+	 *
90
+	 * @throws InvalidArgumentException
91
+	 * @throws InvalidDataTypeException
92
+	 * @throws InvalidInterfaceException
93
+	 */
94
+	protected function _add_view_counts()
95
+	{
96
+		$this->_views['in_use']['count'] = $this->_admin_page->get_attendees($this->_per_page, true);
97
+		if (
98
+			EE_Registry::instance()->CAP->current_user_can(
99
+				'ee_delete_contacts',
100
+				'espresso_registrations_delete_registration'
101
+			)
102
+		) {
103
+			$this->_views['trash']['count'] = $this->_admin_page->get_attendees($this->_per_page, true, true);
104
+		}
105
+	}
106
+
107
+
108
+	/**
109
+	 * Get count of attendees.
110
+	 *
111
+	 * @return int
112
+	 * @throws EE_Error
113
+	 * @throws InvalidArgumentException
114
+	 * @throws InvalidDataTypeException
115
+	 * @throws InvalidInterfaceException
116
+	 */
117
+	protected function _get_attendees_count()
118
+	{
119
+		return EEM_Attendee::instance()->count();
120
+	}
121
+
122
+
123
+	/**
124
+	 * Checkbox column
125
+	 *
126
+	 * @param EE_Attendee $attendee Unable to typehint this method because overrides parent.
127
+	 * @return string
128
+	 * @throws EE_Error
129
+	 */
130
+	public function column_cb($attendee)
131
+	{
132
+		if (! $attendee instanceof EE_Attendee) {
133
+			return '';
134
+		}
135
+		return sprintf(
136
+			'<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />',
137
+			$attendee->ID()
138
+		);
139
+	}
140
+
141
+
142
+	/**
143
+	 * ATT_ID column
144
+	 *
145
+	 * @param EE_Attendee $attendee
146
+	 * @return string
147
+	 * @throws EE_Error
148
+	 */
149
+	public function column_ATT_ID(EE_Attendee $attendee)
150
+	{
151
+		$content = $attendee->ID();
152
+		$attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
153
+		$content .= '  <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
154
+		return $content;
155
+	}
156
+
157
+
158
+	/**
159
+	 * ATT_lname column
160
+	 *
161
+	 * @param EE_Attendee $attendee
162
+	 * @return string
163
+	 * @throws InvalidArgumentException
164
+	 * @throws InvalidDataTypeException
165
+	 * @throws InvalidInterfaceException
166
+	 * @throws EE_Error
167
+	 */
168
+	public function column_ATT_lname(EE_Attendee $attendee)
169
+	{
170
+		// edit attendee link
171
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
172
+			array(
173
+				'action' => 'edit_attendee',
174
+				'post'   => $attendee->ID(),
175
+			),
176
+			REG_ADMIN_URL
177
+		);
178
+		$name_link = EE_Registry::instance()->CAP->current_user_can(
179
+			'ee_edit_contacts',
180
+			'espresso_registrations_edit_attendee'
181
+		)
182
+			? '<a href="' . $edit_lnk_url . '" title="'
183
+			  . esc_attr__('Edit Contact', 'event_espresso') . '">'
184
+			  . $attendee->lname() . '</a>'
185
+			: $attendee->lname();
186
+		return $name_link;
187
+	}
188
+
189
+
190
+	/**
191
+	 * ATT_fname column
192
+	 *
193
+	 * @param EE_Attendee $attendee
194
+	 * @return string
195
+	 * @throws InvalidArgumentException
196
+	 * @throws InvalidDataTypeException
197
+	 * @throws InvalidInterfaceException
198
+	 * @throws EE_Error
199
+	 */
200
+	public function column_ATT_fname(EE_Attendee $attendee)
201
+	{
202
+		// Build row actions
203
+		$actions = array();
204
+		// edit attendee link
205
+		if (
206
+			EE_Registry::instance()->CAP->current_user_can(
207
+				'ee_edit_contacts',
208
+				'espresso_registrations_edit_attendee'
209
+			)
210
+		) {
211
+			$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
212
+				array(
213
+					'action' => 'edit_attendee',
214
+					'post'   => $attendee->ID(),
215
+				),
216
+				REG_ADMIN_URL
217
+			);
218
+			$actions['edit'] = '<a href="' . $edit_lnk_url . '" title="'
219
+							   . esc_attr__('Edit Contact', 'event_espresso') . '">'
220
+							   . esc_html__('Edit', 'event_espresso') . '</a>';
221
+		}
222
+
223
+		if ($this->_view === 'in_use') {
224
+			// trash attendee link
225
+			if (
226
+				EE_Registry::instance()->CAP->current_user_can(
227
+					'ee_delete_contacts',
228
+					'espresso_registrations_trash_attendees'
229
+				)
230
+			) {
231
+				$trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
232
+					array(
233
+						'action' => 'trash_attendee',
234
+						'ATT_ID' => $attendee->ID(),
235
+					),
236
+					REG_ADMIN_URL
237
+				);
238
+				$actions['trash'] = '<a href="' . $trash_lnk_url . '" title="'
239
+									. esc_attr__('Move Contact to Trash', 'event_espresso')
240
+									. '">' . esc_html__('Trash', 'event_espresso') . '</a>';
241
+			}
242
+		} else {
243
+			if (
244
+				EE_Registry::instance()->CAP->current_user_can(
245
+					'ee_delete_contacts',
246
+					'espresso_registrations_restore_attendees'
247
+				)
248
+			) {
249
+				// restore attendee link
250
+				$restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
251
+					array(
252
+						'action' => 'restore_attendees',
253
+						'ATT_ID' => $attendee->ID(),
254
+					),
255
+					REG_ADMIN_URL
256
+				);
257
+				$actions['restore'] = '<a href="' . $restore_lnk_url . '" title="'
258
+									  . esc_attr__('Restore Contact', 'event_espresso') . '">'
259
+									  . esc_html__('Restore', 'event_espresso') . '</a>';
260
+			}
261
+		}
262
+
263
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
264
+			array(
265
+				'action' => 'edit_attendee',
266
+				'post'   => $attendee->ID(),
267
+			),
268
+			REG_ADMIN_URL
269
+		);
270
+		$name_link = EE_Registry::instance()->CAP->current_user_can(
271
+			'ee_edit_contacts',
272
+			'espresso_registrations_edit_attendee'
273
+		)
274
+			? '<a href="' . $edit_lnk_url . '" title="'
275
+			  . esc_attr__('Edit Contact', 'event_espresso') . '">' . $attendee->fname() . '</a>'
276
+			: $attendee->fname();
277
+
278
+		// Return the name contents
279
+		return sprintf('%1$s %2$s', $name_link, $this->row_actions($actions));
280
+	}
281
+
282
+
283
+	/**
284
+	 * Email Column
285
+	 *
286
+	 * @param EE_Attendee $attendee
287
+	 * @return string
288
+	 * @throws EE_Error
289
+	 */
290
+	public function column_ATT_email(EE_Attendee $attendee)
291
+	{
292
+		return '<a href="mailto:' . $attendee->email() . '">' . $attendee->email() . '</a>';
293
+	}
294
+
295
+
296
+	/**
297
+	 * Column displaying count of registrations attached to Attendee.
298
+	 *
299
+	 * @param EE_Attendee $attendee
300
+	 * @return string
301
+	 * @throws EE_Error
302
+	 */
303
+	public function column_Registration_Count(EE_Attendee $attendee)
304
+	{
305
+		$link = EEH_URL::add_query_args_and_nonce(
306
+			array(
307
+				'action' => 'default',
308
+				'ATT_ID' => $attendee->ID(),
309
+			),
310
+			REG_ADMIN_URL
311
+		);
312
+		return '<a href="' . $link . '">' . $attendee->getCustomSelect('Registration_Count') . '</a>';
313
+	}
314
+
315
+
316
+	/**
317
+	 * ATT_address column
318
+	 *
319
+	 * @param EE_Attendee $attendee
320
+	 * @return mixed
321
+	 * @throws EE_Error
322
+	 */
323
+	public function column_ATT_address(EE_Attendee $attendee)
324
+	{
325
+		return $attendee->address();
326
+	}
327
+
328
+
329
+	/**
330
+	 * ATT_city column
331
+	 *
332
+	 * @param EE_Attendee $attendee
333
+	 * @return mixed
334
+	 * @throws EE_Error
335
+	 */
336
+	public function column_ATT_city(EE_Attendee $attendee)
337
+	{
338
+		return $attendee->city();
339
+	}
340
+
341
+
342
+	/**
343
+	 * State Column
344
+	 *
345
+	 * @param EE_Attendee $attendee
346
+	 * @return string
347
+	 * @throws EE_Error
348
+	 * @throws InvalidArgumentException
349
+	 * @throws InvalidDataTypeException
350
+	 * @throws InvalidInterfaceException
351
+	 */
352
+	public function column_STA_ID(EE_Attendee $attendee)
353
+	{
354
+		$states = EEM_State::instance()->get_all_states();
355
+		$state = isset($states[ $attendee->state_ID() ])
356
+			? $states[ $attendee->state_ID() ]->get('STA_name')
357
+			: $attendee->state_ID();
358
+		return ! is_numeric($state) ? $state : '';
359
+	}
360
+
361
+
362
+	/**
363
+	 * Country Column
364
+	 *
365
+	 * @param EE_Attendee $attendee
366
+	 * @return string
367
+	 * @throws EE_Error
368
+	 * @throws InvalidArgumentException
369
+	 * @throws InvalidDataTypeException
370
+	 * @throws InvalidInterfaceException
371
+	 */
372
+	public function column_CNT_ISO(EE_Attendee $attendee)
373
+	{
374
+		$countries = EEM_Country::instance()->get_all_countries();
375
+		$country = isset($countries[ $attendee->country_ID() ])
376
+			? $countries[ $attendee->country_ID() ]->get('CNT_name')
377
+			: $attendee->country_ID();
378
+		return ! is_numeric($country) ? $country : '';
379
+	}
380
+
381
+
382
+	/**
383
+	 * Phone Number column
384
+	 *
385
+	 * @param EE_Attendee $attendee
386
+	 * @return mixed
387
+	 * @throws EE_Error
388
+	 */
389
+	public function column_ATT_phone(EE_Attendee $attendee)
390
+	{
391
+		return $attendee->phone();
392
+	}
393 393
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      */
130 130
     public function column_cb($attendee)
131 131
     {
132
-        if (! $attendee instanceof EE_Attendee) {
132
+        if ( ! $attendee instanceof EE_Attendee) {
133 133
             return '';
134 134
         }
135 135
         return sprintf(
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
     {
151 151
         $content = $attendee->ID();
152 152
         $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
153
-        $content .= '  <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
153
+        $content .= '  <span class="show-on-mobile-view-only">'.$attendee_name.'</span>';
154 154
         return $content;
155 155
     }
156 156
 
@@ -179,9 +179,9 @@  discard block
 block discarded – undo
179 179
             'ee_edit_contacts',
180 180
             'espresso_registrations_edit_attendee'
181 181
         )
182
-            ? '<a href="' . $edit_lnk_url . '" title="'
183
-              . esc_attr__('Edit Contact', 'event_espresso') . '">'
184
-              . $attendee->lname() . '</a>'
182
+            ? '<a href="'.$edit_lnk_url.'" title="'
183
+              . esc_attr__('Edit Contact', 'event_espresso').'">'
184
+              . $attendee->lname().'</a>'
185 185
             : $attendee->lname();
186 186
         return $name_link;
187 187
     }
@@ -215,9 +215,9 @@  discard block
 block discarded – undo
215 215
                 ),
216 216
                 REG_ADMIN_URL
217 217
             );
218
-            $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="'
219
-                               . esc_attr__('Edit Contact', 'event_espresso') . '">'
220
-                               . esc_html__('Edit', 'event_espresso') . '</a>';
218
+            $actions['edit'] = '<a href="'.$edit_lnk_url.'" title="'
219
+                               . esc_attr__('Edit Contact', 'event_espresso').'">'
220
+                               . esc_html__('Edit', 'event_espresso').'</a>';
221 221
         }
222 222
 
223 223
         if ($this->_view === 'in_use') {
@@ -235,9 +235,9 @@  discard block
 block discarded – undo
235 235
                     ),
236 236
                     REG_ADMIN_URL
237 237
                 );
238
-                $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="'
238
+                $actions['trash'] = '<a href="'.$trash_lnk_url.'" title="'
239 239
                                     . esc_attr__('Move Contact to Trash', 'event_espresso')
240
-                                    . '">' . esc_html__('Trash', 'event_espresso') . '</a>';
240
+                                    . '">'.esc_html__('Trash', 'event_espresso').'</a>';
241 241
             }
242 242
         } else {
243 243
             if (
@@ -254,9 +254,9 @@  discard block
 block discarded – undo
254 254
                     ),
255 255
                     REG_ADMIN_URL
256 256
                 );
257
-                $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="'
258
-                                      . esc_attr__('Restore Contact', 'event_espresso') . '">'
259
-                                      . esc_html__('Restore', 'event_espresso') . '</a>';
257
+                $actions['restore'] = '<a href="'.$restore_lnk_url.'" title="'
258
+                                      . esc_attr__('Restore Contact', 'event_espresso').'">'
259
+                                      . esc_html__('Restore', 'event_espresso').'</a>';
260 260
             }
261 261
         }
262 262
 
@@ -271,8 +271,8 @@  discard block
 block discarded – undo
271 271
             'ee_edit_contacts',
272 272
             'espresso_registrations_edit_attendee'
273 273
         )
274
-            ? '<a href="' . $edit_lnk_url . '" title="'
275
-              . esc_attr__('Edit Contact', 'event_espresso') . '">' . $attendee->fname() . '</a>'
274
+            ? '<a href="'.$edit_lnk_url.'" title="'
275
+              . esc_attr__('Edit Contact', 'event_espresso').'">'.$attendee->fname().'</a>'
276 276
             : $attendee->fname();
277 277
 
278 278
         // Return the name contents
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
      */
290 290
     public function column_ATT_email(EE_Attendee $attendee)
291 291
     {
292
-        return '<a href="mailto:' . $attendee->email() . '">' . $attendee->email() . '</a>';
292
+        return '<a href="mailto:'.$attendee->email().'">'.$attendee->email().'</a>';
293 293
     }
294 294
 
295 295
 
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
             ),
310 310
             REG_ADMIN_URL
311 311
         );
312
-        return '<a href="' . $link . '">' . $attendee->getCustomSelect('Registration_Count') . '</a>';
312
+        return '<a href="'.$link.'">'.$attendee->getCustomSelect('Registration_Count').'</a>';
313 313
     }
314 314
 
315 315
 
@@ -352,8 +352,8 @@  discard block
 block discarded – undo
352 352
     public function column_STA_ID(EE_Attendee $attendee)
353 353
     {
354 354
         $states = EEM_State::instance()->get_all_states();
355
-        $state = isset($states[ $attendee->state_ID() ])
356
-            ? $states[ $attendee->state_ID() ]->get('STA_name')
355
+        $state = isset($states[$attendee->state_ID()])
356
+            ? $states[$attendee->state_ID()]->get('STA_name')
357 357
             : $attendee->state_ID();
358 358
         return ! is_numeric($state) ? $state : '';
359 359
     }
@@ -372,8 +372,8 @@  discard block
 block discarded – undo
372 372
     public function column_CNT_ISO(EE_Attendee $attendee)
373 373
     {
374 374
         $countries = EEM_Country::instance()->get_all_countries();
375
-        $country = isset($countries[ $attendee->country_ID() ])
376
-            ? $countries[ $attendee->country_ID() ]->get('CNT_name')
375
+        $country = isset($countries[$attendee->country_ID()])
376
+            ? $countries[$attendee->country_ID()]->get('CNT_name')
377 377
             : $attendee->country_ID();
378 378
         return ! is_numeric($country) ? $country : '';
379 379
     }
Please login to merge, or discard this patch.
core/db_classes/EE_Payment.class.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
      */
297 297
     public function timestamp($dt_frmt = '', $tm_frmt = '')
298 298
     {
299
-        return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt));
299
+        return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt.' '.$tm_frmt));
300 300
     }
301 301
 
302 302
 
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
                     : '';
482 482
                 break;
483 483
         }
484
-        return $icon . $status[ $this->STS_ID() ];
484
+        return $icon.$status[$this->STS_ID()];
485 485
     }
486 486
 
487 487
 
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
     public function redirect_form($inside_form_html = null)
628 628
     {
629 629
         $redirect_url = $this->redirect_url();
630
-        if (! empty($redirect_url)) {
630
+        if ( ! empty($redirect_url)) {
631 631
             // what ? no inner form content?
632 632
             if ($inside_form_html === null) {
633 633
                 $inside_form_html = EEH_HTML::p(
@@ -657,7 +657,7 @@  discard block
 block discarded – undo
657 657
                 $get_params = null;
658 658
                 parse_str($querystring, $get_params);
659 659
                 $inside_form_html .= $this->_args_as_inputs($get_params);
660
-                $redirect_url = str_replace('?' . $querystring, '', $redirect_url);
660
+                $redirect_url = str_replace('?'.$querystring, '', $redirect_url);
661 661
             }
662 662
             $form = EEH_HTML::nl(1)
663 663
                     . '<form method="'
@@ -665,9 +665,9 @@  discard block
 block discarded – undo
665 665
                     . '" name="gateway_form" action="'
666 666
                     . $redirect_url
667 667
                     . '">';
668
-            $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs();
668
+            $form .= EEH_HTML::nl(1).$this->redirect_args_as_inputs();
669 669
             $form .= $inside_form_html;
670
-            $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1);
670
+            $form .= EEH_HTML::nl(-1).'</form>'.EEH_HTML::nl(-1);
671 671
             return $form;
672 672
         } else {
673 673
             return null;
@@ -725,8 +725,8 @@  discard block
 block discarded – undo
725 725
             return $html;
726 726
         }
727 727
         return EEH_HTML::nl()
728
-            . '<input type="hidden" name="' . $name . '"'
729
-            . ' value="' . esc_attr($value) . '"/>';
728
+            . '<input type="hidden" name="'.$name.'"'
729
+            . ' value="'.esc_attr($value).'"/>';
730 730
     }
731 731
 
732 732
 
Please login to merge, or discard this patch.
Indentation   +870 added lines, -870 removed lines patch added patch discarded remove patch
@@ -11,874 +11,874 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Payment extends EE_Base_Class implements EEI_Payment
13 13
 {
14
-    /**
15
-     * @param array  $props_n_values          incoming values
16
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
17
-     *                                        used.)
18
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
19
-     *                                        date_format and the second value is the time format
20
-     * @return EE_Payment
21
-     * @throws \EE_Error
22
-     */
23
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
24
-    {
25
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
26
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
27
-    }
28
-
29
-
30
-    /**
31
-     * @param array  $props_n_values  incoming values from the database
32
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
33
-     *                                the website will be used.
34
-     * @return EE_Payment
35
-     * @throws \EE_Error
36
-     */
37
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
38
-    {
39
-        return new self($props_n_values, true, $timezone);
40
-    }
41
-
42
-
43
-    /**
44
-     * Set Transaction ID
45
-     *
46
-     * @access public
47
-     * @param int $TXN_ID
48
-     * @throws \EE_Error
49
-     */
50
-    public function set_transaction_id($TXN_ID = 0)
51
-    {
52
-        $this->set('TXN_ID', $TXN_ID);
53
-    }
54
-
55
-
56
-    /**
57
-     * Gets the transaction related to this payment
58
-     *
59
-     * @return EE_Transaction
60
-     * @throws \EE_Error
61
-     */
62
-    public function transaction()
63
-    {
64
-        return $this->get_first_related('Transaction');
65
-    }
66
-
67
-
68
-    /**
69
-     * Set Status
70
-     *
71
-     * @access public
72
-     * @param string $STS_ID
73
-     * @throws \EE_Error
74
-     */
75
-    public function set_status($STS_ID = '')
76
-    {
77
-        $this->set('STS_ID', $STS_ID);
78
-    }
79
-
80
-
81
-    /**
82
-     * Set Payment Timestamp
83
-     *
84
-     * @access public
85
-     * @param int $timestamp
86
-     * @throws \EE_Error
87
-     */
88
-    public function set_timestamp($timestamp = 0)
89
-    {
90
-        $this->set('PAY_timestamp', $timestamp);
91
-    }
92
-
93
-
94
-    /**
95
-     * Set Payment Method
96
-     *
97
-     * @access public
98
-     * @param string $PAY_source
99
-     * @throws \EE_Error
100
-     */
101
-    public function set_source($PAY_source = '')
102
-    {
103
-        $this->set('PAY_source', $PAY_source);
104
-    }
105
-
106
-
107
-    /**
108
-     * Set Payment Amount
109
-     *
110
-     * @access public
111
-     * @param float $amount
112
-     * @throws \EE_Error
113
-     */
114
-    public function set_amount($amount = 0.00)
115
-    {
116
-        $this->set('PAY_amount', (float) $amount);
117
-    }
118
-
119
-
120
-    /**
121
-     * Set Payment Gateway Response
122
-     *
123
-     * @access public
124
-     * @param string $gateway_response
125
-     * @throws \EE_Error
126
-     */
127
-    public function set_gateway_response($gateway_response = '')
128
-    {
129
-        $this->set('PAY_gateway_response', $gateway_response);
130
-    }
131
-
132
-
133
-    /**
134
-     * Returns the name of the payment method used on this payment (previously known merely as 'gateway')
135
-     * but since 4.6.0, payment methods are models and the payment keeps a foreign key to the payment method
136
-     * used on it
137
-     *
138
-     * @deprecated
139
-     * @return string
140
-     * @throws \EE_Error
141
-     */
142
-    public function gateway()
143
-    {
144
-        EE_Error::doing_it_wrong(
145
-            'EE_Payment::gateway',
146
-            esc_html__(
147
-                'The method EE_Payment::gateway() has been deprecated. Consider instead using EE_Payment::payment_method()->name()',
148
-                'event_espresso'
149
-            ),
150
-            '4.6.0'
151
-        );
152
-        return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso');
153
-    }
154
-
155
-
156
-    /**
157
-     * Set Gateway Transaction ID
158
-     *
159
-     * @access public
160
-     * @param string $txn_id_chq_nmbr
161
-     * @throws \EE_Error
162
-     */
163
-    public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '')
164
-    {
165
-        $this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr);
166
-    }
167
-
168
-
169
-    /**
170
-     * Set Purchase Order Number
171
-     *
172
-     * @access public
173
-     * @param string $po_number
174
-     * @throws \EE_Error
175
-     */
176
-    public function set_po_number($po_number = '')
177
-    {
178
-        $this->set('PAY_po_number', $po_number);
179
-    }
180
-
181
-
182
-    /**
183
-     * Set Extra Accounting Field
184
-     *
185
-     * @access public
186
-     * @param string $extra_accntng
187
-     * @throws \EE_Error
188
-     */
189
-    public function set_extra_accntng($extra_accntng = '')
190
-    {
191
-        $this->set('PAY_extra_accntng', $extra_accntng);
192
-    }
193
-
194
-
195
-    /**
196
-     * Set Payment made via admin flag
197
-     *
198
-     * @access public
199
-     * @param bool $via_admin
200
-     * @throws \EE_Error
201
-     */
202
-    public function set_payment_made_via_admin($via_admin = false)
203
-    {
204
-        if ($via_admin) {
205
-            $this->set('PAY_source', EEM_Payment_Method::scope_admin);
206
-        } else {
207
-            $this->set('PAY_source', EEM_Payment_Method::scope_cart);
208
-        }
209
-    }
210
-
211
-
212
-    /**
213
-     * Set Payment Details
214
-     *
215
-     * @access public
216
-     * @param string|array $details
217
-     * @throws \EE_Error
218
-     */
219
-    public function set_details($details = '')
220
-    {
221
-        if (is_array($details)) {
222
-            array_walk_recursive($details, array($this, '_strip_all_tags_within_array'));
223
-        } else {
224
-            $details = wp_strip_all_tags($details);
225
-        }
226
-        $this->set('PAY_details', $details);
227
-    }
228
-
229
-
230
-    /**
231
-     * Sets redirect_url
232
-     *
233
-     * @param string $redirect_url
234
-     * @throws \EE_Error
235
-     */
236
-    public function set_redirect_url($redirect_url)
237
-    {
238
-        $this->set('PAY_redirect_url', $redirect_url);
239
-    }
240
-
241
-
242
-    /**
243
-     * Sets redirect_args
244
-     *
245
-     * @param array $redirect_args
246
-     * @throws \EE_Error
247
-     */
248
-    public function set_redirect_args($redirect_args)
249
-    {
250
-        $this->set('PAY_redirect_args', $redirect_args);
251
-    }
252
-
253
-
254
-    /**
255
-     * get Payment Transaction ID
256
-     *
257
-     * @access public
258
-     * @throws \EE_Error
259
-     */
260
-    public function TXN_ID()
261
-    {
262
-        return $this->get('TXN_ID');
263
-    }
264
-
265
-
266
-    /**
267
-     * get Payment Status
268
-     *
269
-     * @access public
270
-     * @throws \EE_Error
271
-     */
272
-    public function status()
273
-    {
274
-        return $this->get('STS_ID');
275
-    }
276
-
277
-
278
-    /**
279
-     * get Payment Status
280
-     *
281
-     * @access public
282
-     * @throws \EE_Error
283
-     */
284
-    public function STS_ID()
285
-    {
286
-        return $this->get('STS_ID');
287
-    }
288
-
289
-
290
-    /**
291
-     * get Payment Timestamp
292
-     *
293
-     * @access public
294
-     * @param string $dt_frmt
295
-     * @param string $tm_frmt
296
-     * @return string
297
-     * @throws \EE_Error
298
-     */
299
-    public function timestamp($dt_frmt = '', $tm_frmt = '')
300
-    {
301
-        return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt));
302
-    }
303
-
304
-
305
-    /**
306
-     * get Payment Source
307
-     *
308
-     * @access public
309
-     * @throws \EE_Error
310
-     */
311
-    public function source()
312
-    {
313
-        return $this->get('PAY_source');
314
-    }
315
-
316
-
317
-    /**
318
-     * get Payment Amount
319
-     *
320
-     * @access public
321
-     * @return float
322
-     * @throws \EE_Error
323
-     */
324
-    public function amount()
325
-    {
326
-        return (float) $this->get('PAY_amount');
327
-    }
328
-
329
-
330
-    /**
331
-     * @return mixed
332
-     * @throws \EE_Error
333
-     */
334
-    public function amount_no_code()
335
-    {
336
-        return $this->get_pretty('PAY_amount', 'no_currency_code');
337
-    }
338
-
339
-
340
-    /**
341
-     * get Payment Gateway Response
342
-     *
343
-     * @access public
344
-     * @throws \EE_Error
345
-     */
346
-    public function gateway_response()
347
-    {
348
-        return $this->get('PAY_gateway_response');
349
-    }
350
-
351
-
352
-    /**
353
-     * get Payment Gateway Transaction ID
354
-     *
355
-     * @access public
356
-     * @throws \EE_Error
357
-     */
358
-    public function txn_id_chq_nmbr()
359
-    {
360
-        return $this->get('PAY_txn_id_chq_nmbr');
361
-    }
362
-
363
-
364
-    /**
365
-     * get Purchase Order Number
366
-     *
367
-     * @access public
368
-     * @throws \EE_Error
369
-     */
370
-    public function po_number()
371
-    {
372
-        return $this->get('PAY_po_number');
373
-    }
374
-
375
-
376
-    /**
377
-     * get Extra Accounting Field
378
-     *
379
-     * @access public
380
-     * @throws \EE_Error
381
-     */
382
-    public function extra_accntng()
383
-    {
384
-        return $this->get('PAY_extra_accntng');
385
-    }
386
-
387
-
388
-    /**
389
-     * get Payment made via admin source
390
-     *
391
-     * @access public
392
-     * @throws \EE_Error
393
-     */
394
-    public function payment_made_via_admin()
395
-    {
396
-        return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin);
397
-    }
398
-
399
-
400
-    /**
401
-     * get Payment Details
402
-     *
403
-     * @access public
404
-     * @throws \EE_Error
405
-     */
406
-    public function details()
407
-    {
408
-        return $this->get('PAY_details');
409
-    }
410
-
411
-
412
-    /**
413
-     * Gets redirect_url
414
-     *
415
-     * @return string
416
-     * @throws \EE_Error
417
-     */
418
-    public function redirect_url()
419
-    {
420
-        return $this->get('PAY_redirect_url');
421
-    }
422
-
423
-
424
-    /**
425
-     * Gets redirect_args
426
-     *
427
-     * @return array
428
-     * @throws \EE_Error
429
-     */
430
-    public function redirect_args()
431
-    {
432
-        return $this->get('PAY_redirect_args');
433
-    }
434
-
435
-
436
-    /**
437
-     * echoes $this->pretty_status()
438
-     *
439
-     * @param bool $show_icons
440
-     * @return void
441
-     * @throws \EE_Error
442
-     */
443
-    public function e_pretty_status($show_icons = false)
444
-    {
445
-        echo wp_kses($this->pretty_status($show_icons), AllowedTags::getAllowedTags());
446
-    }
447
-
448
-
449
-    /**
450
-     * returns a pretty version of the status, good for displaying to users
451
-     *
452
-     * @param bool $show_icons
453
-     * @return string
454
-     * @throws \EE_Error
455
-     */
456
-    public function pretty_status($show_icons = false)
457
-    {
458
-        $status = EEM_Status::instance()->localized_status(
459
-            array($this->STS_ID() => esc_html__('unknown', 'event_espresso')),
460
-            false,
461
-            'sentence'
462
-        );
463
-        $icon = '';
464
-        switch ($this->STS_ID()) {
465
-            case EEM_Payment::status_id_approved:
466
-                $icon = $show_icons
467
-                    ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>'
468
-                    : '';
469
-                break;
470
-            case EEM_Payment::status_id_pending:
471
-                $icon = $show_icons
472
-                    ? '<span class="dashicons dashicons-clock ee-icon-size-16 orange-text"></span>'
473
-                    : '';
474
-                break;
475
-            case EEM_Payment::status_id_cancelled:
476
-                $icon = $show_icons
477
-                    ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>'
478
-                    : '';
479
-                break;
480
-            case EEM_Payment::status_id_declined:
481
-                $icon = $show_icons
482
-                    ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>'
483
-                    : '';
484
-                break;
485
-        }
486
-        return $icon . $status[ $this->STS_ID() ];
487
-    }
488
-
489
-
490
-    /**
491
-     * For determining the status of the payment
492
-     *
493
-     * @return boolean whether the payment is approved or not
494
-     * @throws \EE_Error
495
-     */
496
-    public function is_approved()
497
-    {
498
-        return $this->status_is(EEM_Payment::status_id_approved);
499
-    }
500
-
501
-
502
-    /**
503
-     * Generally determines if the status of this payment equals
504
-     * the $STS_ID string
505
-     *
506
-     * @param string $STS_ID an ID from the esp_status table/
507
-     *                       one of the status_id_* on the EEM_Payment model
508
-     * @return boolean whether the status of this payment equals the status id
509
-     * @throws \EE_Error
510
-     */
511
-    protected function status_is($STS_ID)
512
-    {
513
-        return $STS_ID === $this->STS_ID() ? true : false;
514
-    }
515
-
516
-
517
-    /**
518
-     * For determining the status of the payment
519
-     *
520
-     * @return boolean whether the payment is pending or not
521
-     * @throws \EE_Error
522
-     */
523
-    public function is_pending()
524
-    {
525
-        return $this->status_is(EEM_Payment::status_id_pending);
526
-    }
527
-
528
-
529
-    /**
530
-     * For determining the status of the payment
531
-     *
532
-     * @return boolean
533
-     * @throws \EE_Error
534
-     */
535
-    public function is_cancelled()
536
-    {
537
-        return $this->status_is(EEM_Payment::status_id_cancelled);
538
-    }
539
-
540
-
541
-    /**
542
-     * For determining the status of the payment
543
-     *
544
-     * @return boolean
545
-     * @throws \EE_Error
546
-     */
547
-    public function is_declined()
548
-    {
549
-        return $this->status_is(EEM_Payment::status_id_declined);
550
-    }
551
-
552
-
553
-    /**
554
-     * For determining the status of the payment
555
-     *
556
-     * @return boolean
557
-     * @throws \EE_Error
558
-     */
559
-    public function is_failed()
560
-    {
561
-        return $this->status_is(EEM_Payment::status_id_failed);
562
-    }
563
-
564
-
565
-    /**
566
-     * For determining if the payment is actually a refund ( ie: has a negative value )
567
-     *
568
-     * @return boolean
569
-     * @throws \EE_Error
570
-     */
571
-    public function is_a_refund()
572
-    {
573
-        return $this->amount() < 0 ? true : false;
574
-    }
575
-
576
-
577
-    /**
578
-     * Get the status object of this object
579
-     *
580
-     * @return EE_Status
581
-     * @throws \EE_Error
582
-     */
583
-    public function status_obj()
584
-    {
585
-        return $this->get_first_related('Status');
586
-    }
587
-
588
-
589
-    /**
590
-     * Gets all the extra meta info on this payment
591
-     *
592
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
593
-     * @return EE_Extra_Meta
594
-     * @throws \EE_Error
595
-     */
596
-    public function extra_meta($query_params = array())
597
-    {
598
-        return $this->get_many_related('Extra_Meta', $query_params);
599
-    }
600
-
601
-
602
-    /**
603
-     * Gets the last-used payment method on this transaction
604
-     * (we COULD just use the last-made payment, but some payment methods, namely
605
-     * offline ones, dont' create payments)
606
-     *
607
-     * @return EE_Payment_Method
608
-     * @throws \EE_Error
609
-     */
610
-    public function payment_method()
611
-    {
612
-        return $this->get_first_related('Payment_Method');
613
-    }
614
-
615
-
616
-    /**
617
-     * Gets the HTML for redirecting the user to an offsite gateway
618
-     * You can pass it special content to put inside the form, or use
619
-     * the default inner content (or possibly generate this all yourself using
620
-     * redirect_url() and redirect_args() or redirect_args_as_inputs()).
621
-     * Creates a POST request by default, but if no redirect args are specified, creates a GET request instead
622
-     * (and any querystring variables in the redirect_url are converted into html inputs
623
-     * so browsers submit them properly)
624
-     *
625
-     * @param string $inside_form_html
626
-     * @return string html
627
-     * @throws \EE_Error
628
-     */
629
-    public function redirect_form($inside_form_html = null)
630
-    {
631
-        $redirect_url = $this->redirect_url();
632
-        if (! empty($redirect_url)) {
633
-            // what ? no inner form content?
634
-            if ($inside_form_html === null) {
635
-                $inside_form_html = EEH_HTML::p(
636
-                    sprintf(
637
-                        esc_html__(
638
-                            'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s',
639
-                            'event_espresso'
640
-                        ),
641
-                        EEH_HTML::br(2),
642
-                        '<input type="submit" value="',
643
-                        '">'
644
-                    ),
645
-                    '',
646
-                    '',
647
-                    'text-align:center;'
648
-                );
649
-            }
650
-            $method = apply_filters(
651
-                'FHEE__EE_Payment__redirect_form__method',
652
-                $this->redirect_args() ? 'POST' : 'GET',
653
-                $this
654
-            );
655
-            // if it's a GET request, we need to remove all the GET params in the querystring
656
-            // and put them into the form instead
657
-            if ($method === 'GET') {
658
-                $querystring = parse_url($redirect_url, PHP_URL_QUERY);
659
-                $get_params = null;
660
-                parse_str($querystring, $get_params);
661
-                $inside_form_html .= $this->_args_as_inputs($get_params);
662
-                $redirect_url = str_replace('?' . $querystring, '', $redirect_url);
663
-            }
664
-            $form = EEH_HTML::nl(1)
665
-                    . '<form method="'
666
-                    . $method
667
-                    . '" name="gateway_form" action="'
668
-                    . $redirect_url
669
-                    . '">';
670
-            $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs();
671
-            $form .= $inside_form_html;
672
-            $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1);
673
-            return $form;
674
-        } else {
675
-            return null;
676
-        }
677
-    }
678
-
679
-
680
-    /**
681
-     * Changes all the name-value pairs of the redirect args into html inputs
682
-     * and returns the html as a string
683
-     *
684
-     * @return string
685
-     * @throws \EE_Error
686
-     */
687
-    public function redirect_args_as_inputs()
688
-    {
689
-        return $this->_args_as_inputs($this->redirect_args());
690
-    }
691
-
692
-
693
-    /**
694
-     * Converts a 2d array of key-value pairs into html hidden inputs
695
-     * and returns the string of html
696
-     *
697
-     * @param array $args key-value pairs
698
-     * @return string
699
-     */
700
-    protected function _args_as_inputs($args)
701
-    {
702
-        $html = '';
703
-        if ($args !== null && is_array($args)) {
704
-            foreach ($args as $name => $value) {
705
-                $html .= $this->generateInput($name, $value);
706
-            }
707
-        }
708
-        return $html;
709
-    }
710
-
711
-    /**
712
-     * Converts either a single name and value or array of values into html hidden inputs
713
-     * and returns the string of html
714
-     *
715
-     * @param string $name
716
-     * @param string|array $value
717
-     * @return string
718
-     */
719
-    private function generateInput($name, $value)
720
-    {
721
-        if (is_array($value)) {
722
-            $html = '';
723
-            $name = "{$name}[]";
724
-            foreach ($value as $array_value) {
725
-                $html .= $this->generateInput($name, $array_value);
726
-            }
727
-            return $html;
728
-        }
729
-        return EEH_HTML::nl()
730
-            . '<input type="hidden" name="' . $name . '"'
731
-            . ' value="' . esc_attr($value) . '"/>';
732
-    }
733
-
734
-
735
-    /**
736
-     * Returns the currency of the payment.
737
-     * (At the time of writing, this will always be the currency in the configuration;
738
-     * however in the future it is anticipated that this will be stored on the payment
739
-     * object itself)
740
-     *
741
-     * @return string for the currency code
742
-     */
743
-    public function currency_code()
744
-    {
745
-        return EE_Config::instance()->currency->code;
746
-    }
747
-
748
-
749
-    /**
750
-     * apply wp_strip_all_tags to all elements within an array
751
-     *
752
-     * @access private
753
-     * @param mixed $item
754
-     */
755
-    private function _strip_all_tags_within_array(&$item)
756
-    {
757
-        if (is_object($item)) {
758
-            $item = (array) $item;
759
-        }
760
-        if (is_array($item)) {
761
-            array_walk_recursive($item, array($this, '_strip_all_tags_within_array'));
762
-        } else {
763
-            $item = wp_strip_all_tags($item);
764
-        }
765
-    }
766
-
767
-
768
-    /**
769
-     * Returns TRUE is this payment was set to approved during this request (or
770
-     * is approved and was created during this request). False otherwise.
771
-     *
772
-     * @return boolean
773
-     * @throws \EE_Error
774
-     */
775
-    public function just_approved()
776
-    {
777
-        $original_status = EEH_Array::is_set(
778
-            $this->_props_n_values_provided_in_constructor,
779
-            'STS_ID',
780
-            $this->get_model()->field_settings_for('STS_ID')->get_default_value()
781
-        );
782
-        $current_status = $this->status();
783
-        if (
784
-            $original_status !== EEM_Payment::status_id_approved
785
-            && $current_status === EEM_Payment::status_id_approved
786
-        ) {
787
-            return true;
788
-        } else {
789
-            return false;
790
-        }
791
-    }
792
-
793
-
794
-    /**
795
-     * Overrides parents' get_pretty() function just for legacy reasons
796
-     * (to allow ticket https://events.codebasehq.com/projects/event-espresso/tickets/7420)
797
-     *
798
-     * @param string $field_name
799
-     * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
800
-     *                                (in cases where the same property may be used for different outputs
801
-     *                                - i.e. datetime, money etc.)
802
-     * @return mixed
803
-     * @throws \EE_Error
804
-     */
805
-    public function get_pretty($field_name, $extra_cache_ref = null)
806
-    {
807
-        if ($field_name === 'PAY_gateway') {
808
-            return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso');
809
-        }
810
-        return $this->_get_cached_property($field_name, true, $extra_cache_ref);
811
-    }
812
-
813
-
814
-    /**
815
-     * Gets details regarding which registrations this payment was applied to
816
-     *
817
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
818
-     * @return EE_Registration_Payment[]
819
-     * @throws \EE_Error
820
-     */
821
-    public function registration_payments($query_params = array())
822
-    {
823
-        return $this->get_many_related('Registration_Payment', $query_params);
824
-    }
825
-
826
-
827
-    /**
828
-     * Gets the first event for this payment (it's possible that it could be for multiple)
829
-     *
830
-     * @return EE_Event|null
831
-     */
832
-    public function get_first_event()
833
-    {
834
-        $transaction = $this->transaction();
835
-        if ($transaction instanceof EE_Transaction) {
836
-            $primary_registrant = $transaction->primary_registration();
837
-            if ($primary_registrant instanceof EE_Registration) {
838
-                return $primary_registrant->event_obj();
839
-            }
840
-        }
841
-        return null;
842
-    }
843
-
844
-
845
-    /**
846
-     * Gets the name of the first event for which is being paid
847
-     *
848
-     * @return string
849
-     */
850
-    public function get_first_event_name()
851
-    {
852
-        $event = $this->get_first_event();
853
-        return $event instanceof EE_Event ? $event->name() : esc_html__('Event', 'event_espresso');
854
-    }
855
-
856
-
857
-    /**
858
-     * Returns the payment's transaction's primary registration
859
-     *
860
-     * @return EE_Registration|null
861
-     */
862
-    public function get_primary_registration()
863
-    {
864
-        if ($this->transaction() instanceof EE_Transaction) {
865
-            return $this->transaction()->primary_registration();
866
-        }
867
-        return null;
868
-    }
869
-
870
-
871
-    /**
872
-     * Gets the payment's transaction's primary registration's attendee, or null
873
-     *
874
-     * @return EE_Attendee|null
875
-     */
876
-    public function get_primary_attendee()
877
-    {
878
-        $primary_reg = $this->get_primary_registration();
879
-        if ($primary_reg instanceof EE_Registration) {
880
-            return $primary_reg->attendee();
881
-        }
882
-        return null;
883
-    }
14
+	/**
15
+	 * @param array  $props_n_values          incoming values
16
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
17
+	 *                                        used.)
18
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
19
+	 *                                        date_format and the second value is the time format
20
+	 * @return EE_Payment
21
+	 * @throws \EE_Error
22
+	 */
23
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
24
+	{
25
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
26
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
27
+	}
28
+
29
+
30
+	/**
31
+	 * @param array  $props_n_values  incoming values from the database
32
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
33
+	 *                                the website will be used.
34
+	 * @return EE_Payment
35
+	 * @throws \EE_Error
36
+	 */
37
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
38
+	{
39
+		return new self($props_n_values, true, $timezone);
40
+	}
41
+
42
+
43
+	/**
44
+	 * Set Transaction ID
45
+	 *
46
+	 * @access public
47
+	 * @param int $TXN_ID
48
+	 * @throws \EE_Error
49
+	 */
50
+	public function set_transaction_id($TXN_ID = 0)
51
+	{
52
+		$this->set('TXN_ID', $TXN_ID);
53
+	}
54
+
55
+
56
+	/**
57
+	 * Gets the transaction related to this payment
58
+	 *
59
+	 * @return EE_Transaction
60
+	 * @throws \EE_Error
61
+	 */
62
+	public function transaction()
63
+	{
64
+		return $this->get_first_related('Transaction');
65
+	}
66
+
67
+
68
+	/**
69
+	 * Set Status
70
+	 *
71
+	 * @access public
72
+	 * @param string $STS_ID
73
+	 * @throws \EE_Error
74
+	 */
75
+	public function set_status($STS_ID = '')
76
+	{
77
+		$this->set('STS_ID', $STS_ID);
78
+	}
79
+
80
+
81
+	/**
82
+	 * Set Payment Timestamp
83
+	 *
84
+	 * @access public
85
+	 * @param int $timestamp
86
+	 * @throws \EE_Error
87
+	 */
88
+	public function set_timestamp($timestamp = 0)
89
+	{
90
+		$this->set('PAY_timestamp', $timestamp);
91
+	}
92
+
93
+
94
+	/**
95
+	 * Set Payment Method
96
+	 *
97
+	 * @access public
98
+	 * @param string $PAY_source
99
+	 * @throws \EE_Error
100
+	 */
101
+	public function set_source($PAY_source = '')
102
+	{
103
+		$this->set('PAY_source', $PAY_source);
104
+	}
105
+
106
+
107
+	/**
108
+	 * Set Payment Amount
109
+	 *
110
+	 * @access public
111
+	 * @param float $amount
112
+	 * @throws \EE_Error
113
+	 */
114
+	public function set_amount($amount = 0.00)
115
+	{
116
+		$this->set('PAY_amount', (float) $amount);
117
+	}
118
+
119
+
120
+	/**
121
+	 * Set Payment Gateway Response
122
+	 *
123
+	 * @access public
124
+	 * @param string $gateway_response
125
+	 * @throws \EE_Error
126
+	 */
127
+	public function set_gateway_response($gateway_response = '')
128
+	{
129
+		$this->set('PAY_gateway_response', $gateway_response);
130
+	}
131
+
132
+
133
+	/**
134
+	 * Returns the name of the payment method used on this payment (previously known merely as 'gateway')
135
+	 * but since 4.6.0, payment methods are models and the payment keeps a foreign key to the payment method
136
+	 * used on it
137
+	 *
138
+	 * @deprecated
139
+	 * @return string
140
+	 * @throws \EE_Error
141
+	 */
142
+	public function gateway()
143
+	{
144
+		EE_Error::doing_it_wrong(
145
+			'EE_Payment::gateway',
146
+			esc_html__(
147
+				'The method EE_Payment::gateway() has been deprecated. Consider instead using EE_Payment::payment_method()->name()',
148
+				'event_espresso'
149
+			),
150
+			'4.6.0'
151
+		);
152
+		return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso');
153
+	}
154
+
155
+
156
+	/**
157
+	 * Set Gateway Transaction ID
158
+	 *
159
+	 * @access public
160
+	 * @param string $txn_id_chq_nmbr
161
+	 * @throws \EE_Error
162
+	 */
163
+	public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '')
164
+	{
165
+		$this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr);
166
+	}
167
+
168
+
169
+	/**
170
+	 * Set Purchase Order Number
171
+	 *
172
+	 * @access public
173
+	 * @param string $po_number
174
+	 * @throws \EE_Error
175
+	 */
176
+	public function set_po_number($po_number = '')
177
+	{
178
+		$this->set('PAY_po_number', $po_number);
179
+	}
180
+
181
+
182
+	/**
183
+	 * Set Extra Accounting Field
184
+	 *
185
+	 * @access public
186
+	 * @param string $extra_accntng
187
+	 * @throws \EE_Error
188
+	 */
189
+	public function set_extra_accntng($extra_accntng = '')
190
+	{
191
+		$this->set('PAY_extra_accntng', $extra_accntng);
192
+	}
193
+
194
+
195
+	/**
196
+	 * Set Payment made via admin flag
197
+	 *
198
+	 * @access public
199
+	 * @param bool $via_admin
200
+	 * @throws \EE_Error
201
+	 */
202
+	public function set_payment_made_via_admin($via_admin = false)
203
+	{
204
+		if ($via_admin) {
205
+			$this->set('PAY_source', EEM_Payment_Method::scope_admin);
206
+		} else {
207
+			$this->set('PAY_source', EEM_Payment_Method::scope_cart);
208
+		}
209
+	}
210
+
211
+
212
+	/**
213
+	 * Set Payment Details
214
+	 *
215
+	 * @access public
216
+	 * @param string|array $details
217
+	 * @throws \EE_Error
218
+	 */
219
+	public function set_details($details = '')
220
+	{
221
+		if (is_array($details)) {
222
+			array_walk_recursive($details, array($this, '_strip_all_tags_within_array'));
223
+		} else {
224
+			$details = wp_strip_all_tags($details);
225
+		}
226
+		$this->set('PAY_details', $details);
227
+	}
228
+
229
+
230
+	/**
231
+	 * Sets redirect_url
232
+	 *
233
+	 * @param string $redirect_url
234
+	 * @throws \EE_Error
235
+	 */
236
+	public function set_redirect_url($redirect_url)
237
+	{
238
+		$this->set('PAY_redirect_url', $redirect_url);
239
+	}
240
+
241
+
242
+	/**
243
+	 * Sets redirect_args
244
+	 *
245
+	 * @param array $redirect_args
246
+	 * @throws \EE_Error
247
+	 */
248
+	public function set_redirect_args($redirect_args)
249
+	{
250
+		$this->set('PAY_redirect_args', $redirect_args);
251
+	}
252
+
253
+
254
+	/**
255
+	 * get Payment Transaction ID
256
+	 *
257
+	 * @access public
258
+	 * @throws \EE_Error
259
+	 */
260
+	public function TXN_ID()
261
+	{
262
+		return $this->get('TXN_ID');
263
+	}
264
+
265
+
266
+	/**
267
+	 * get Payment Status
268
+	 *
269
+	 * @access public
270
+	 * @throws \EE_Error
271
+	 */
272
+	public function status()
273
+	{
274
+		return $this->get('STS_ID');
275
+	}
276
+
277
+
278
+	/**
279
+	 * get Payment Status
280
+	 *
281
+	 * @access public
282
+	 * @throws \EE_Error
283
+	 */
284
+	public function STS_ID()
285
+	{
286
+		return $this->get('STS_ID');
287
+	}
288
+
289
+
290
+	/**
291
+	 * get Payment Timestamp
292
+	 *
293
+	 * @access public
294
+	 * @param string $dt_frmt
295
+	 * @param string $tm_frmt
296
+	 * @return string
297
+	 * @throws \EE_Error
298
+	 */
299
+	public function timestamp($dt_frmt = '', $tm_frmt = '')
300
+	{
301
+		return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt));
302
+	}
303
+
304
+
305
+	/**
306
+	 * get Payment Source
307
+	 *
308
+	 * @access public
309
+	 * @throws \EE_Error
310
+	 */
311
+	public function source()
312
+	{
313
+		return $this->get('PAY_source');
314
+	}
315
+
316
+
317
+	/**
318
+	 * get Payment Amount
319
+	 *
320
+	 * @access public
321
+	 * @return float
322
+	 * @throws \EE_Error
323
+	 */
324
+	public function amount()
325
+	{
326
+		return (float) $this->get('PAY_amount');
327
+	}
328
+
329
+
330
+	/**
331
+	 * @return mixed
332
+	 * @throws \EE_Error
333
+	 */
334
+	public function amount_no_code()
335
+	{
336
+		return $this->get_pretty('PAY_amount', 'no_currency_code');
337
+	}
338
+
339
+
340
+	/**
341
+	 * get Payment Gateway Response
342
+	 *
343
+	 * @access public
344
+	 * @throws \EE_Error
345
+	 */
346
+	public function gateway_response()
347
+	{
348
+		return $this->get('PAY_gateway_response');
349
+	}
350
+
351
+
352
+	/**
353
+	 * get Payment Gateway Transaction ID
354
+	 *
355
+	 * @access public
356
+	 * @throws \EE_Error
357
+	 */
358
+	public function txn_id_chq_nmbr()
359
+	{
360
+		return $this->get('PAY_txn_id_chq_nmbr');
361
+	}
362
+
363
+
364
+	/**
365
+	 * get Purchase Order Number
366
+	 *
367
+	 * @access public
368
+	 * @throws \EE_Error
369
+	 */
370
+	public function po_number()
371
+	{
372
+		return $this->get('PAY_po_number');
373
+	}
374
+
375
+
376
+	/**
377
+	 * get Extra Accounting Field
378
+	 *
379
+	 * @access public
380
+	 * @throws \EE_Error
381
+	 */
382
+	public function extra_accntng()
383
+	{
384
+		return $this->get('PAY_extra_accntng');
385
+	}
386
+
387
+
388
+	/**
389
+	 * get Payment made via admin source
390
+	 *
391
+	 * @access public
392
+	 * @throws \EE_Error
393
+	 */
394
+	public function payment_made_via_admin()
395
+	{
396
+		return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin);
397
+	}
398
+
399
+
400
+	/**
401
+	 * get Payment Details
402
+	 *
403
+	 * @access public
404
+	 * @throws \EE_Error
405
+	 */
406
+	public function details()
407
+	{
408
+		return $this->get('PAY_details');
409
+	}
410
+
411
+
412
+	/**
413
+	 * Gets redirect_url
414
+	 *
415
+	 * @return string
416
+	 * @throws \EE_Error
417
+	 */
418
+	public function redirect_url()
419
+	{
420
+		return $this->get('PAY_redirect_url');
421
+	}
422
+
423
+
424
+	/**
425
+	 * Gets redirect_args
426
+	 *
427
+	 * @return array
428
+	 * @throws \EE_Error
429
+	 */
430
+	public function redirect_args()
431
+	{
432
+		return $this->get('PAY_redirect_args');
433
+	}
434
+
435
+
436
+	/**
437
+	 * echoes $this->pretty_status()
438
+	 *
439
+	 * @param bool $show_icons
440
+	 * @return void
441
+	 * @throws \EE_Error
442
+	 */
443
+	public function e_pretty_status($show_icons = false)
444
+	{
445
+		echo wp_kses($this->pretty_status($show_icons), AllowedTags::getAllowedTags());
446
+	}
447
+
448
+
449
+	/**
450
+	 * returns a pretty version of the status, good for displaying to users
451
+	 *
452
+	 * @param bool $show_icons
453
+	 * @return string
454
+	 * @throws \EE_Error
455
+	 */
456
+	public function pretty_status($show_icons = false)
457
+	{
458
+		$status = EEM_Status::instance()->localized_status(
459
+			array($this->STS_ID() => esc_html__('unknown', 'event_espresso')),
460
+			false,
461
+			'sentence'
462
+		);
463
+		$icon = '';
464
+		switch ($this->STS_ID()) {
465
+			case EEM_Payment::status_id_approved:
466
+				$icon = $show_icons
467
+					? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>'
468
+					: '';
469
+				break;
470
+			case EEM_Payment::status_id_pending:
471
+				$icon = $show_icons
472
+					? '<span class="dashicons dashicons-clock ee-icon-size-16 orange-text"></span>'
473
+					: '';
474
+				break;
475
+			case EEM_Payment::status_id_cancelled:
476
+				$icon = $show_icons
477
+					? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>'
478
+					: '';
479
+				break;
480
+			case EEM_Payment::status_id_declined:
481
+				$icon = $show_icons
482
+					? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>'
483
+					: '';
484
+				break;
485
+		}
486
+		return $icon . $status[ $this->STS_ID() ];
487
+	}
488
+
489
+
490
+	/**
491
+	 * For determining the status of the payment
492
+	 *
493
+	 * @return boolean whether the payment is approved or not
494
+	 * @throws \EE_Error
495
+	 */
496
+	public function is_approved()
497
+	{
498
+		return $this->status_is(EEM_Payment::status_id_approved);
499
+	}
500
+
501
+
502
+	/**
503
+	 * Generally determines if the status of this payment equals
504
+	 * the $STS_ID string
505
+	 *
506
+	 * @param string $STS_ID an ID from the esp_status table/
507
+	 *                       one of the status_id_* on the EEM_Payment model
508
+	 * @return boolean whether the status of this payment equals the status id
509
+	 * @throws \EE_Error
510
+	 */
511
+	protected function status_is($STS_ID)
512
+	{
513
+		return $STS_ID === $this->STS_ID() ? true : false;
514
+	}
515
+
516
+
517
+	/**
518
+	 * For determining the status of the payment
519
+	 *
520
+	 * @return boolean whether the payment is pending or not
521
+	 * @throws \EE_Error
522
+	 */
523
+	public function is_pending()
524
+	{
525
+		return $this->status_is(EEM_Payment::status_id_pending);
526
+	}
527
+
528
+
529
+	/**
530
+	 * For determining the status of the payment
531
+	 *
532
+	 * @return boolean
533
+	 * @throws \EE_Error
534
+	 */
535
+	public function is_cancelled()
536
+	{
537
+		return $this->status_is(EEM_Payment::status_id_cancelled);
538
+	}
539
+
540
+
541
+	/**
542
+	 * For determining the status of the payment
543
+	 *
544
+	 * @return boolean
545
+	 * @throws \EE_Error
546
+	 */
547
+	public function is_declined()
548
+	{
549
+		return $this->status_is(EEM_Payment::status_id_declined);
550
+	}
551
+
552
+
553
+	/**
554
+	 * For determining the status of the payment
555
+	 *
556
+	 * @return boolean
557
+	 * @throws \EE_Error
558
+	 */
559
+	public function is_failed()
560
+	{
561
+		return $this->status_is(EEM_Payment::status_id_failed);
562
+	}
563
+
564
+
565
+	/**
566
+	 * For determining if the payment is actually a refund ( ie: has a negative value )
567
+	 *
568
+	 * @return boolean
569
+	 * @throws \EE_Error
570
+	 */
571
+	public function is_a_refund()
572
+	{
573
+		return $this->amount() < 0 ? true : false;
574
+	}
575
+
576
+
577
+	/**
578
+	 * Get the status object of this object
579
+	 *
580
+	 * @return EE_Status
581
+	 * @throws \EE_Error
582
+	 */
583
+	public function status_obj()
584
+	{
585
+		return $this->get_first_related('Status');
586
+	}
587
+
588
+
589
+	/**
590
+	 * Gets all the extra meta info on this payment
591
+	 *
592
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
593
+	 * @return EE_Extra_Meta
594
+	 * @throws \EE_Error
595
+	 */
596
+	public function extra_meta($query_params = array())
597
+	{
598
+		return $this->get_many_related('Extra_Meta', $query_params);
599
+	}
600
+
601
+
602
+	/**
603
+	 * Gets the last-used payment method on this transaction
604
+	 * (we COULD just use the last-made payment, but some payment methods, namely
605
+	 * offline ones, dont' create payments)
606
+	 *
607
+	 * @return EE_Payment_Method
608
+	 * @throws \EE_Error
609
+	 */
610
+	public function payment_method()
611
+	{
612
+		return $this->get_first_related('Payment_Method');
613
+	}
614
+
615
+
616
+	/**
617
+	 * Gets the HTML for redirecting the user to an offsite gateway
618
+	 * You can pass it special content to put inside the form, or use
619
+	 * the default inner content (or possibly generate this all yourself using
620
+	 * redirect_url() and redirect_args() or redirect_args_as_inputs()).
621
+	 * Creates a POST request by default, but if no redirect args are specified, creates a GET request instead
622
+	 * (and any querystring variables in the redirect_url are converted into html inputs
623
+	 * so browsers submit them properly)
624
+	 *
625
+	 * @param string $inside_form_html
626
+	 * @return string html
627
+	 * @throws \EE_Error
628
+	 */
629
+	public function redirect_form($inside_form_html = null)
630
+	{
631
+		$redirect_url = $this->redirect_url();
632
+		if (! empty($redirect_url)) {
633
+			// what ? no inner form content?
634
+			if ($inside_form_html === null) {
635
+				$inside_form_html = EEH_HTML::p(
636
+					sprintf(
637
+						esc_html__(
638
+							'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s',
639
+							'event_espresso'
640
+						),
641
+						EEH_HTML::br(2),
642
+						'<input type="submit" value="',
643
+						'">'
644
+					),
645
+					'',
646
+					'',
647
+					'text-align:center;'
648
+				);
649
+			}
650
+			$method = apply_filters(
651
+				'FHEE__EE_Payment__redirect_form__method',
652
+				$this->redirect_args() ? 'POST' : 'GET',
653
+				$this
654
+			);
655
+			// if it's a GET request, we need to remove all the GET params in the querystring
656
+			// and put them into the form instead
657
+			if ($method === 'GET') {
658
+				$querystring = parse_url($redirect_url, PHP_URL_QUERY);
659
+				$get_params = null;
660
+				parse_str($querystring, $get_params);
661
+				$inside_form_html .= $this->_args_as_inputs($get_params);
662
+				$redirect_url = str_replace('?' . $querystring, '', $redirect_url);
663
+			}
664
+			$form = EEH_HTML::nl(1)
665
+					. '<form method="'
666
+					. $method
667
+					. '" name="gateway_form" action="'
668
+					. $redirect_url
669
+					. '">';
670
+			$form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs();
671
+			$form .= $inside_form_html;
672
+			$form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1);
673
+			return $form;
674
+		} else {
675
+			return null;
676
+		}
677
+	}
678
+
679
+
680
+	/**
681
+	 * Changes all the name-value pairs of the redirect args into html inputs
682
+	 * and returns the html as a string
683
+	 *
684
+	 * @return string
685
+	 * @throws \EE_Error
686
+	 */
687
+	public function redirect_args_as_inputs()
688
+	{
689
+		return $this->_args_as_inputs($this->redirect_args());
690
+	}
691
+
692
+
693
+	/**
694
+	 * Converts a 2d array of key-value pairs into html hidden inputs
695
+	 * and returns the string of html
696
+	 *
697
+	 * @param array $args key-value pairs
698
+	 * @return string
699
+	 */
700
+	protected function _args_as_inputs($args)
701
+	{
702
+		$html = '';
703
+		if ($args !== null && is_array($args)) {
704
+			foreach ($args as $name => $value) {
705
+				$html .= $this->generateInput($name, $value);
706
+			}
707
+		}
708
+		return $html;
709
+	}
710
+
711
+	/**
712
+	 * Converts either a single name and value or array of values into html hidden inputs
713
+	 * and returns the string of html
714
+	 *
715
+	 * @param string $name
716
+	 * @param string|array $value
717
+	 * @return string
718
+	 */
719
+	private function generateInput($name, $value)
720
+	{
721
+		if (is_array($value)) {
722
+			$html = '';
723
+			$name = "{$name}[]";
724
+			foreach ($value as $array_value) {
725
+				$html .= $this->generateInput($name, $array_value);
726
+			}
727
+			return $html;
728
+		}
729
+		return EEH_HTML::nl()
730
+			. '<input type="hidden" name="' . $name . '"'
731
+			. ' value="' . esc_attr($value) . '"/>';
732
+	}
733
+
734
+
735
+	/**
736
+	 * Returns the currency of the payment.
737
+	 * (At the time of writing, this will always be the currency in the configuration;
738
+	 * however in the future it is anticipated that this will be stored on the payment
739
+	 * object itself)
740
+	 *
741
+	 * @return string for the currency code
742
+	 */
743
+	public function currency_code()
744
+	{
745
+		return EE_Config::instance()->currency->code;
746
+	}
747
+
748
+
749
+	/**
750
+	 * apply wp_strip_all_tags to all elements within an array
751
+	 *
752
+	 * @access private
753
+	 * @param mixed $item
754
+	 */
755
+	private function _strip_all_tags_within_array(&$item)
756
+	{
757
+		if (is_object($item)) {
758
+			$item = (array) $item;
759
+		}
760
+		if (is_array($item)) {
761
+			array_walk_recursive($item, array($this, '_strip_all_tags_within_array'));
762
+		} else {
763
+			$item = wp_strip_all_tags($item);
764
+		}
765
+	}
766
+
767
+
768
+	/**
769
+	 * Returns TRUE is this payment was set to approved during this request (or
770
+	 * is approved and was created during this request). False otherwise.
771
+	 *
772
+	 * @return boolean
773
+	 * @throws \EE_Error
774
+	 */
775
+	public function just_approved()
776
+	{
777
+		$original_status = EEH_Array::is_set(
778
+			$this->_props_n_values_provided_in_constructor,
779
+			'STS_ID',
780
+			$this->get_model()->field_settings_for('STS_ID')->get_default_value()
781
+		);
782
+		$current_status = $this->status();
783
+		if (
784
+			$original_status !== EEM_Payment::status_id_approved
785
+			&& $current_status === EEM_Payment::status_id_approved
786
+		) {
787
+			return true;
788
+		} else {
789
+			return false;
790
+		}
791
+	}
792
+
793
+
794
+	/**
795
+	 * Overrides parents' get_pretty() function just for legacy reasons
796
+	 * (to allow ticket https://events.codebasehq.com/projects/event-espresso/tickets/7420)
797
+	 *
798
+	 * @param string $field_name
799
+	 * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
800
+	 *                                (in cases where the same property may be used for different outputs
801
+	 *                                - i.e. datetime, money etc.)
802
+	 * @return mixed
803
+	 * @throws \EE_Error
804
+	 */
805
+	public function get_pretty($field_name, $extra_cache_ref = null)
806
+	{
807
+		if ($field_name === 'PAY_gateway') {
808
+			return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso');
809
+		}
810
+		return $this->_get_cached_property($field_name, true, $extra_cache_ref);
811
+	}
812
+
813
+
814
+	/**
815
+	 * Gets details regarding which registrations this payment was applied to
816
+	 *
817
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
818
+	 * @return EE_Registration_Payment[]
819
+	 * @throws \EE_Error
820
+	 */
821
+	public function registration_payments($query_params = array())
822
+	{
823
+		return $this->get_many_related('Registration_Payment', $query_params);
824
+	}
825
+
826
+
827
+	/**
828
+	 * Gets the first event for this payment (it's possible that it could be for multiple)
829
+	 *
830
+	 * @return EE_Event|null
831
+	 */
832
+	public function get_first_event()
833
+	{
834
+		$transaction = $this->transaction();
835
+		if ($transaction instanceof EE_Transaction) {
836
+			$primary_registrant = $transaction->primary_registration();
837
+			if ($primary_registrant instanceof EE_Registration) {
838
+				return $primary_registrant->event_obj();
839
+			}
840
+		}
841
+		return null;
842
+	}
843
+
844
+
845
+	/**
846
+	 * Gets the name of the first event for which is being paid
847
+	 *
848
+	 * @return string
849
+	 */
850
+	public function get_first_event_name()
851
+	{
852
+		$event = $this->get_first_event();
853
+		return $event instanceof EE_Event ? $event->name() : esc_html__('Event', 'event_espresso');
854
+	}
855
+
856
+
857
+	/**
858
+	 * Returns the payment's transaction's primary registration
859
+	 *
860
+	 * @return EE_Registration|null
861
+	 */
862
+	public function get_primary_registration()
863
+	{
864
+		if ($this->transaction() instanceof EE_Transaction) {
865
+			return $this->transaction()->primary_registration();
866
+		}
867
+		return null;
868
+	}
869
+
870
+
871
+	/**
872
+	 * Gets the payment's transaction's primary registration's attendee, or null
873
+	 *
874
+	 * @return EE_Attendee|null
875
+	 */
876
+	public function get_primary_attendee()
877
+	{
878
+		$primary_reg = $this->get_primary_registration();
879
+		if ($primary_reg instanceof EE_Registration) {
880
+			return $primary_reg->attendee();
881
+		}
882
+		return null;
883
+	}
884 884
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Payment_Method.class.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -445,11 +445,11 @@  discard block
 block discarded – undo
445 445
      */
446 446
     public function type_obj()
447 447
     {
448
-        if (! $this->_type_obj) {
448
+        if ( ! $this->_type_obj) {
449 449
             EE_Registry::instance()->load_lib('Payment_Method_Manager');
450 450
             if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) {
451 451
                 $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type());
452
-                if (! class_exists($class_name)) {
452
+                if ( ! class_exists($class_name)) {
453 453
                     throw new EE_Error(
454 454
                         sprintf(
455 455
                             esc_html__(
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
                             ),
459 459
                             $class_name,
460 460
                             '<br />',
461
-                            '<a href="' . admin_url('plugins.php') . '">',
461
+                            '<a href="'.admin_url('plugins.php').'">',
462 462
                             '</a>'
463 463
                         )
464 464
                     );
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
         foreach ($fields as $key => $value) {
500 500
             if (strpos($key, 'PMD_') === 0) {
501 501
                 $key_sans_model_prefix = str_replace('PMD_', '', $key);
502
-                $combined_settings_array [ $key_sans_model_prefix ] = $value;
502
+                $combined_settings_array [$key_sans_model_prefix] = $value;
503 503
             }
504 504
         }
505 505
         $combined_settings_array = array_merge($extra_meta, $combined_settings_array);
@@ -522,14 +522,14 @@  discard block
 block discarded – undo
522 522
 		 <div id="'
523 523
                . $this->slug()
524 524
                . '-payment-option-dv" class="'
525
-               . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '">
525
+               . $payment_occurs.'-payment-gateway reg-page-payment-option-dv'.$css_class.'">
526 526
 			<a id="payment-gateway-button-' . $this->slug()
527 527
                . '" class="reg-page-payment-option-lnk" rel="'
528
-               . $this->slug() . '" href="' . $url . '" >
529
-				<img src="' . $this->button_url() . '" alt="' . sprintf(
528
+               . $this->slug().'" href="'.$url.'" >
529
+				<img src="' . $this->button_url().'" alt="'.sprintf(
530 530
                    esc_attr__('Pay using %s', 'event_espresso'),
531 531
                    $this->get_pretty('PMD_name', 'form_input')
532
-               ) . '" />
532
+               ).'" />
533 533
 			</a>
534 534
 		</div>
535 535
 ';
Please login to merge, or discard this patch.
Indentation   +572 added lines, -572 removed lines patch added patch discarded remove patch
@@ -13,582 +13,582 @@
 block discarded – undo
13 13
  */
14 14
 class EE_Payment_Method extends EE_Base_Class
15 15
 {
16
-    /**
17
-     * Payment Method type object, which has all the info about this type of payment method,
18
-     * including functions for processing payments, to get settings forms, etc.
19
-     *
20
-     * @var EE_PMT_Base
21
-     */
22
-    protected $_type_obj;
23
-
24
-
25
-    /**
26
-     * @param array $props_n_values
27
-     * @return EE_Payment_Method
28
-     * @throws \EE_Error
29
-     */
30
-    public static function new_instance($props_n_values = array())
31
-    {
32
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
33
-        return $has_object ? $has_object : new self($props_n_values, false);
34
-    }
35
-
36
-
37
-    /**
38
-     * @param array $props_n_values
39
-     * @return EE_Payment_Method
40
-     * @throws \EE_Error
41
-     */
42
-    public static function new_instance_from_db($props_n_values = array())
43
-    {
44
-        return new self($props_n_values, true);
45
-    }
46
-
47
-
48
-
49
-    /**
50
-     * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname.
51
-     * Otherwise returns a normal EE_Payment_Method
52
-     *
53
-     * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically
54
-     *                              the classname minus 'EEPM_')
55
-     * @return string
56
-     */
57
-    // private static function _payment_method_type($props_n_values)
58
-    // {
59
-    //     EE_Registry::instance()->load_lib('Payment_Method_Manager');
60
-    //     $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null;
61
-    //     if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) {
62
-    //         return 'EEPM_' . $type_string;
63
-    //     } else {
64
-    //         return __CLASS__;
65
-    //     }
66
-    // }
67
-
68
-
69
-    /**
70
-     * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc)
71
-     *
72
-     * @return boolean
73
-     */
74
-    public function active()
75
-    {
76
-        return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope());
77
-    }
78
-
79
-
80
-    /**
81
-     * Sets this PM as active by making it usable within the CART scope. Offline gateways
82
-     * are also usable from the admin-scope as well. DOES NOT SAVE it
83
-     *
84
-     * @throws \EE_Error
85
-     */
86
-    public function set_active()
87
-    {
88
-        $default_scopes = array(EEM_Payment_Method::scope_cart);
89
-        if (
90
-            $this->type_obj() &&
91
-            $this->type_obj()->payment_occurs() === EE_PMT_Base::offline
92
-        ) {
93
-            $default_scopes[] = EEM_Payment_Method::scope_admin;
94
-        }
95
-        $this->set_scope($default_scopes);
96
-    }
97
-
98
-
99
-    /**
100
-     * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it.
101
-     */
102
-    public function deactivate()
103
-    {
104
-        $this->set_scope(array());
105
-    }
106
-
107
-
108
-    /**
109
-     * Gets button_url
110
-     *
111
-     * @return string
112
-     */
113
-    public function button_url()
114
-    {
115
-        return $this->get('PMD_button_url');
116
-    }
117
-
118
-
119
-    /**
120
-     * Sets button_url
121
-     *
122
-     * @param string $button_url
123
-     */
124
-    public function set_button_url($button_url)
125
-    {
126
-        $this->set('PMD_button_url', $button_url);
127
-    }
128
-
129
-
130
-    /**
131
-     * Gets debug_mode
132
-     *
133
-     * @return boolean
134
-     */
135
-    public function debug_mode()
136
-    {
137
-        return $this->get('PMD_debug_mode');
138
-    }
139
-
140
-
141
-    /**
142
-     * Sets debug_mode
143
-     *
144
-     * @param boolean $debug_mode
145
-     */
146
-    public function set_debug_mode($debug_mode)
147
-    {
148
-        $this->set('PMD_debug_mode', $debug_mode);
149
-    }
150
-
151
-
152
-    /**
153
-     * Gets description
154
-     *
155
-     * @return string
156
-     */
157
-    public function description()
158
-    {
159
-        return $this->get('PMD_desc');
160
-    }
161
-
162
-
163
-    /**
164
-     * Sets description
165
-     *
166
-     * @param string $description
167
-     */
168
-    public function set_description($description)
169
-    {
170
-        $this->set('PMD_desc', $description);
171
-    }
172
-
173
-
174
-    /**
175
-     * Gets name
176
-     *
177
-     * @return string
178
-     */
179
-    public function name()
180
-    {
181
-        return $this->get('PMD_name');
182
-    }
183
-
184
-
185
-    /**
186
-     * Sets name
187
-     *
188
-     * @param string $name
189
-     */
190
-    public function set_name($name)
191
-    {
192
-        $this->set('PMD_name', $name);
193
-    }
194
-
195
-
196
-    /**
197
-     * Gets open_by_default
198
-     *
199
-     * @return boolean
200
-     */
201
-    public function open_by_default()
202
-    {
203
-        return $this->get('PMD_open_by_default');
204
-    }
205
-
206
-
207
-    /**
208
-     * Sets open_by_default
209
-     *
210
-     * @param boolean $open_by_default
211
-     */
212
-    public function set_open_by_default($open_by_default)
213
-    {
214
-        $this->set('PMD_open_by_default', $open_by_default);
215
-    }
216
-
217
-
218
-    /**
219
-     * Gets order
220
-     *
221
-     * @return int
222
-     */
223
-    public function order()
224
-    {
225
-        return $this->get('PMD_order');
226
-    }
227
-
228
-
229
-    /**
230
-     * Sets order
231
-     *
232
-     * @param int $order
233
-     */
234
-    public function set_order($order)
235
-    {
236
-        $this->set('PMD_order', $order);
237
-    }
238
-
239
-
240
-    /**
241
-     * Gets slug
242
-     *
243
-     * @return string
244
-     */
245
-    public function slug()
246
-    {
247
-        return $this->get('PMD_slug');
248
-    }
249
-
250
-
251
-    /**
252
-     * Sets slug
253
-     *
254
-     * @param string $slug
255
-     */
256
-    public function set_slug($slug)
257
-    {
258
-        $this->set('PMD_slug', $slug);
259
-    }
260
-
261
-
262
-    /**
263
-     * Gets type
264
-     *
265
-     * @return string
266
-     */
267
-    public function type()
268
-    {
269
-        return $this->get('PMD_type');
270
-    }
271
-
272
-
273
-    /**
274
-     * Sets type
275
-     *
276
-     * @param string $type
277
-     */
278
-    public function set_type($type)
279
-    {
280
-        $this->set('PMD_type', $type);
281
-    }
282
-
283
-
284
-    /**
285
-     * Gets wp_user
286
-     *
287
-     * @return int
288
-     */
289
-    public function wp_user()
290
-    {
291
-        return $this->get('PMD_wp_user');
292
-    }
293
-
294
-
295
-    /**
296
-     * Sets wp_user
297
-     *
298
-     * @param int $wp_user_id
299
-     */
300
-    public function set_wp_user($wp_user_id)
301
-    {
302
-        $this->set('PMD_wp_user', $wp_user_id);
303
-    }
304
-
305
-    /**
306
-     * Overrides parent so when PMD_type is changed we refresh the _type_obj
307
-     *
308
-     * @param string $field_name
309
-     * @param mixed $field_value
310
-     * @param boolean $use_default
311
-     */
312
-    public function set($field_name, $field_value, $use_default = false)
313
-    {
314
-        if ($field_name === 'PMD_type') {
315
-            // the type has probably changed, so forget about its old type object
316
-            $this->_type_obj = null;
317
-        }
318
-        parent::set($field_name, $field_value, $use_default);
319
-    }
320
-
321
-
322
-    /**
323
-     * Gets admin_name
324
-     *
325
-     * @return string
326
-     */
327
-    public function admin_name()
328
-    {
329
-        return $this->get('PMD_admin_name');
330
-    }
331
-
332
-
333
-    /**
334
-     * Sets admin_name
335
-     *
336
-     * @param string $admin_name
337
-     */
338
-    public function set_admin_name($admin_name)
339
-    {
340
-        $this->set('PMD_admin_name', $admin_name);
341
-    }
342
-
343
-
344
-    /**
345
-     * Gets admin_desc
346
-     *
347
-     * @return string
348
-     */
349
-    public function admin_desc()
350
-    {
351
-        return $this->get('PMD_admin_desc');
352
-    }
353
-
354
-
355
-    /**
356
-     * Sets admin_desc
357
-     *
358
-     * @param string $admin_desc
359
-     */
360
-    public function set_admin_desc($admin_desc)
361
-    {
362
-        $this->set('PMD_admin_desc', $admin_desc);
363
-    }
364
-
365
-
366
-    /**
367
-     * Gets scope
368
-     *
369
-     * @return array
370
-     */
371
-    public function scope()
372
-    {
373
-        return $this->get('PMD_scope');
374
-    }
375
-
376
-
377
-    /**
378
-     * Sets scope
379
-     *
380
-     * @param array $scope
381
-     */
382
-    public function set_scope($scope)
383
-    {
384
-        $this->set('PMD_scope', $scope);
385
-    }
386
-
387
-
388
-    /**
389
-     * Gets the payment method type for this payment method instance
390
-     *
391
-     * @return EE_PMT_Base
392
-     * @throws EE_Error
393
-     */
394
-    public function type_obj()
395
-    {
396
-        if (! $this->_type_obj) {
397
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
398
-            if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) {
399
-                $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type());
400
-                if (! class_exists($class_name)) {
401
-                    throw new EE_Error(
402
-                        sprintf(
403
-                            esc_html__(
404
-                                'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s',
405
-                                'event_espresso'
406
-                            ),
407
-                            $class_name,
408
-                            '<br />',
409
-                            '<a href="' . admin_url('plugins.php') . '">',
410
-                            '</a>'
411
-                        )
412
-                    );
413
-                }
414
-                $r = new ReflectionClass($class_name);
415
-                $this->_type_obj = $r->newInstanceArgs(array($this));
416
-            } else {
417
-                throw new EE_Error(
418
-                    sprintf(
419
-                        esc_html__(
420
-                            'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s',
421
-                            'event_espresso'
422
-                        ),
423
-                        $this->type(),
424
-                        implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names())
425
-                    )
426
-                );
427
-            }
428
-        }
429
-        return $this->_type_obj;
430
-    }
431
-
432
-
433
-    /**
434
-     * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix)
435
-     * and the extra meta. Mostly used for passing off ot gateways.     *
436
-     *
437
-     * @return array
438
-     */
439
-    public function settings_array()
440
-    {
441
-        $fields = $this->model_field_array();
442
-        $extra_meta = $this->all_extra_meta_array();
443
-        // remove the model's prefix from the fields
444
-        $combined_settings_array = array();
445
-        foreach ($fields as $key => $value) {
446
-            if (strpos($key, 'PMD_') === 0) {
447
-                $key_sans_model_prefix = str_replace('PMD_', '', $key);
448
-                $combined_settings_array [ $key_sans_model_prefix ] = $value;
449
-            }
450
-        }
451
-        $combined_settings_array = array_merge($extra_meta, $combined_settings_array);
452
-        return $combined_settings_array;
453
-    }
454
-
455
-
456
-    /**
457
-     * Gets the HTML for displaying the payment method on a page.
458
-     *
459
-     * @param string $url
460
-     * @param string $css_class
461
-     * @return string of HTML for displaying the button
462
-     * @throws \EE_Error
463
-     */
464
-    public function button_html($url = '', $css_class = '')
465
-    {
466
-        $payment_occurs = $this->type_obj()->payment_occurs();
467
-        return '
16
+	/**
17
+	 * Payment Method type object, which has all the info about this type of payment method,
18
+	 * including functions for processing payments, to get settings forms, etc.
19
+	 *
20
+	 * @var EE_PMT_Base
21
+	 */
22
+	protected $_type_obj;
23
+
24
+
25
+	/**
26
+	 * @param array $props_n_values
27
+	 * @return EE_Payment_Method
28
+	 * @throws \EE_Error
29
+	 */
30
+	public static function new_instance($props_n_values = array())
31
+	{
32
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
33
+		return $has_object ? $has_object : new self($props_n_values, false);
34
+	}
35
+
36
+
37
+	/**
38
+	 * @param array $props_n_values
39
+	 * @return EE_Payment_Method
40
+	 * @throws \EE_Error
41
+	 */
42
+	public static function new_instance_from_db($props_n_values = array())
43
+	{
44
+		return new self($props_n_values, true);
45
+	}
46
+
47
+
48
+
49
+	/**
50
+	 * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname.
51
+	 * Otherwise returns a normal EE_Payment_Method
52
+	 *
53
+	 * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically
54
+	 *                              the classname minus 'EEPM_')
55
+	 * @return string
56
+	 */
57
+	// private static function _payment_method_type($props_n_values)
58
+	// {
59
+	//     EE_Registry::instance()->load_lib('Payment_Method_Manager');
60
+	//     $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null;
61
+	//     if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) {
62
+	//         return 'EEPM_' . $type_string;
63
+	//     } else {
64
+	//         return __CLASS__;
65
+	//     }
66
+	// }
67
+
68
+
69
+	/**
70
+	 * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc)
71
+	 *
72
+	 * @return boolean
73
+	 */
74
+	public function active()
75
+	{
76
+		return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope());
77
+	}
78
+
79
+
80
+	/**
81
+	 * Sets this PM as active by making it usable within the CART scope. Offline gateways
82
+	 * are also usable from the admin-scope as well. DOES NOT SAVE it
83
+	 *
84
+	 * @throws \EE_Error
85
+	 */
86
+	public function set_active()
87
+	{
88
+		$default_scopes = array(EEM_Payment_Method::scope_cart);
89
+		if (
90
+			$this->type_obj() &&
91
+			$this->type_obj()->payment_occurs() === EE_PMT_Base::offline
92
+		) {
93
+			$default_scopes[] = EEM_Payment_Method::scope_admin;
94
+		}
95
+		$this->set_scope($default_scopes);
96
+	}
97
+
98
+
99
+	/**
100
+	 * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it.
101
+	 */
102
+	public function deactivate()
103
+	{
104
+		$this->set_scope(array());
105
+	}
106
+
107
+
108
+	/**
109
+	 * Gets button_url
110
+	 *
111
+	 * @return string
112
+	 */
113
+	public function button_url()
114
+	{
115
+		return $this->get('PMD_button_url');
116
+	}
117
+
118
+
119
+	/**
120
+	 * Sets button_url
121
+	 *
122
+	 * @param string $button_url
123
+	 */
124
+	public function set_button_url($button_url)
125
+	{
126
+		$this->set('PMD_button_url', $button_url);
127
+	}
128
+
129
+
130
+	/**
131
+	 * Gets debug_mode
132
+	 *
133
+	 * @return boolean
134
+	 */
135
+	public function debug_mode()
136
+	{
137
+		return $this->get('PMD_debug_mode');
138
+	}
139
+
140
+
141
+	/**
142
+	 * Sets debug_mode
143
+	 *
144
+	 * @param boolean $debug_mode
145
+	 */
146
+	public function set_debug_mode($debug_mode)
147
+	{
148
+		$this->set('PMD_debug_mode', $debug_mode);
149
+	}
150
+
151
+
152
+	/**
153
+	 * Gets description
154
+	 *
155
+	 * @return string
156
+	 */
157
+	public function description()
158
+	{
159
+		return $this->get('PMD_desc');
160
+	}
161
+
162
+
163
+	/**
164
+	 * Sets description
165
+	 *
166
+	 * @param string $description
167
+	 */
168
+	public function set_description($description)
169
+	{
170
+		$this->set('PMD_desc', $description);
171
+	}
172
+
173
+
174
+	/**
175
+	 * Gets name
176
+	 *
177
+	 * @return string
178
+	 */
179
+	public function name()
180
+	{
181
+		return $this->get('PMD_name');
182
+	}
183
+
184
+
185
+	/**
186
+	 * Sets name
187
+	 *
188
+	 * @param string $name
189
+	 */
190
+	public function set_name($name)
191
+	{
192
+		$this->set('PMD_name', $name);
193
+	}
194
+
195
+
196
+	/**
197
+	 * Gets open_by_default
198
+	 *
199
+	 * @return boolean
200
+	 */
201
+	public function open_by_default()
202
+	{
203
+		return $this->get('PMD_open_by_default');
204
+	}
205
+
206
+
207
+	/**
208
+	 * Sets open_by_default
209
+	 *
210
+	 * @param boolean $open_by_default
211
+	 */
212
+	public function set_open_by_default($open_by_default)
213
+	{
214
+		$this->set('PMD_open_by_default', $open_by_default);
215
+	}
216
+
217
+
218
+	/**
219
+	 * Gets order
220
+	 *
221
+	 * @return int
222
+	 */
223
+	public function order()
224
+	{
225
+		return $this->get('PMD_order');
226
+	}
227
+
228
+
229
+	/**
230
+	 * Sets order
231
+	 *
232
+	 * @param int $order
233
+	 */
234
+	public function set_order($order)
235
+	{
236
+		$this->set('PMD_order', $order);
237
+	}
238
+
239
+
240
+	/**
241
+	 * Gets slug
242
+	 *
243
+	 * @return string
244
+	 */
245
+	public function slug()
246
+	{
247
+		return $this->get('PMD_slug');
248
+	}
249
+
250
+
251
+	/**
252
+	 * Sets slug
253
+	 *
254
+	 * @param string $slug
255
+	 */
256
+	public function set_slug($slug)
257
+	{
258
+		$this->set('PMD_slug', $slug);
259
+	}
260
+
261
+
262
+	/**
263
+	 * Gets type
264
+	 *
265
+	 * @return string
266
+	 */
267
+	public function type()
268
+	{
269
+		return $this->get('PMD_type');
270
+	}
271
+
272
+
273
+	/**
274
+	 * Sets type
275
+	 *
276
+	 * @param string $type
277
+	 */
278
+	public function set_type($type)
279
+	{
280
+		$this->set('PMD_type', $type);
281
+	}
282
+
283
+
284
+	/**
285
+	 * Gets wp_user
286
+	 *
287
+	 * @return int
288
+	 */
289
+	public function wp_user()
290
+	{
291
+		return $this->get('PMD_wp_user');
292
+	}
293
+
294
+
295
+	/**
296
+	 * Sets wp_user
297
+	 *
298
+	 * @param int $wp_user_id
299
+	 */
300
+	public function set_wp_user($wp_user_id)
301
+	{
302
+		$this->set('PMD_wp_user', $wp_user_id);
303
+	}
304
+
305
+	/**
306
+	 * Overrides parent so when PMD_type is changed we refresh the _type_obj
307
+	 *
308
+	 * @param string $field_name
309
+	 * @param mixed $field_value
310
+	 * @param boolean $use_default
311
+	 */
312
+	public function set($field_name, $field_value, $use_default = false)
313
+	{
314
+		if ($field_name === 'PMD_type') {
315
+			// the type has probably changed, so forget about its old type object
316
+			$this->_type_obj = null;
317
+		}
318
+		parent::set($field_name, $field_value, $use_default);
319
+	}
320
+
321
+
322
+	/**
323
+	 * Gets admin_name
324
+	 *
325
+	 * @return string
326
+	 */
327
+	public function admin_name()
328
+	{
329
+		return $this->get('PMD_admin_name');
330
+	}
331
+
332
+
333
+	/**
334
+	 * Sets admin_name
335
+	 *
336
+	 * @param string $admin_name
337
+	 */
338
+	public function set_admin_name($admin_name)
339
+	{
340
+		$this->set('PMD_admin_name', $admin_name);
341
+	}
342
+
343
+
344
+	/**
345
+	 * Gets admin_desc
346
+	 *
347
+	 * @return string
348
+	 */
349
+	public function admin_desc()
350
+	{
351
+		return $this->get('PMD_admin_desc');
352
+	}
353
+
354
+
355
+	/**
356
+	 * Sets admin_desc
357
+	 *
358
+	 * @param string $admin_desc
359
+	 */
360
+	public function set_admin_desc($admin_desc)
361
+	{
362
+		$this->set('PMD_admin_desc', $admin_desc);
363
+	}
364
+
365
+
366
+	/**
367
+	 * Gets scope
368
+	 *
369
+	 * @return array
370
+	 */
371
+	public function scope()
372
+	{
373
+		return $this->get('PMD_scope');
374
+	}
375
+
376
+
377
+	/**
378
+	 * Sets scope
379
+	 *
380
+	 * @param array $scope
381
+	 */
382
+	public function set_scope($scope)
383
+	{
384
+		$this->set('PMD_scope', $scope);
385
+	}
386
+
387
+
388
+	/**
389
+	 * Gets the payment method type for this payment method instance
390
+	 *
391
+	 * @return EE_PMT_Base
392
+	 * @throws EE_Error
393
+	 */
394
+	public function type_obj()
395
+	{
396
+		if (! $this->_type_obj) {
397
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
398
+			if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) {
399
+				$class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type());
400
+				if (! class_exists($class_name)) {
401
+					throw new EE_Error(
402
+						sprintf(
403
+							esc_html__(
404
+								'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s',
405
+								'event_espresso'
406
+							),
407
+							$class_name,
408
+							'<br />',
409
+							'<a href="' . admin_url('plugins.php') . '">',
410
+							'</a>'
411
+						)
412
+					);
413
+				}
414
+				$r = new ReflectionClass($class_name);
415
+				$this->_type_obj = $r->newInstanceArgs(array($this));
416
+			} else {
417
+				throw new EE_Error(
418
+					sprintf(
419
+						esc_html__(
420
+							'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s',
421
+							'event_espresso'
422
+						),
423
+						$this->type(),
424
+						implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names())
425
+					)
426
+				);
427
+			}
428
+		}
429
+		return $this->_type_obj;
430
+	}
431
+
432
+
433
+	/**
434
+	 * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix)
435
+	 * and the extra meta. Mostly used for passing off ot gateways.     *
436
+	 *
437
+	 * @return array
438
+	 */
439
+	public function settings_array()
440
+	{
441
+		$fields = $this->model_field_array();
442
+		$extra_meta = $this->all_extra_meta_array();
443
+		// remove the model's prefix from the fields
444
+		$combined_settings_array = array();
445
+		foreach ($fields as $key => $value) {
446
+			if (strpos($key, 'PMD_') === 0) {
447
+				$key_sans_model_prefix = str_replace('PMD_', '', $key);
448
+				$combined_settings_array [ $key_sans_model_prefix ] = $value;
449
+			}
450
+		}
451
+		$combined_settings_array = array_merge($extra_meta, $combined_settings_array);
452
+		return $combined_settings_array;
453
+	}
454
+
455
+
456
+	/**
457
+	 * Gets the HTML for displaying the payment method on a page.
458
+	 *
459
+	 * @param string $url
460
+	 * @param string $css_class
461
+	 * @return string of HTML for displaying the button
462
+	 * @throws \EE_Error
463
+	 */
464
+	public function button_html($url = '', $css_class = '')
465
+	{
466
+		$payment_occurs = $this->type_obj()->payment_occurs();
467
+		return '
468 468
 		 <div id="'
469
-               . $this->slug()
470
-               . '-payment-option-dv" class="'
471
-               . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '">
469
+			   . $this->slug()
470
+			   . '-payment-option-dv" class="'
471
+			   . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '">
472 472
 			<a id="payment-gateway-button-' . $this->slug()
473
-               . '" class="reg-page-payment-option-lnk" rel="'
474
-               . $this->slug() . '" href="' . $url . '" >
473
+			   . '" class="reg-page-payment-option-lnk" rel="'
474
+			   . $this->slug() . '" href="' . $url . '" >
475 475
 				<img src="' . $this->button_url() . '" alt="' . sprintf(
476
-                   esc_attr__('Pay using %s', 'event_espresso'),
477
-                   $this->get_pretty('PMD_name', 'form_input')
478
-               ) . '" />
476
+				   esc_attr__('Pay using %s', 'event_espresso'),
477
+				   $this->get_pretty('PMD_name', 'form_input')
478
+			   ) . '" />
479 479
 			</a>
480 480
 		</div>
481 481
 ';
482
-    }
483
-
484
-
485
-    /**
486
-     * Gets all the currencies which are an option for this payment method
487
-     * (as defined by the gateway and the currently active currencies)
488
-     *
489
-     * @return EE_Currency[]
490
-     * @throws \EE_Error
491
-     */
492
-    public function get_all_usable_currencies()
493
-    {
494
-        return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj());
495
-    }
496
-
497
-
498
-    /**
499
-     * Reports whether or not this payment method can be used for this payment method
500
-     *
501
-     * @param string $currency_code currency ID (code)
502
-     * @return boolean
503
-     * @throws \EE_Error
504
-     */
505
-    public function usable_for_currency($currency_code)
506
-    {
507
-        foreach ($this->get_all_usable_currencies() as $currency_obj) {
508
-            if ($currency_obj->ID() === $currency_code) {
509
-                return true;
510
-            }
511
-        }
512
-        return false;
513
-    }
514
-
515
-
516
-    /**
517
-     * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway
518
-     *
519
-     * @return bool
520
-     * @throws \EE_Error
521
-     */
522
-    public function is_on_site()
523
-    {
524
-        return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite;
525
-    }
526
-
527
-
528
-    /**
529
-     * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway
530
-     *
531
-     * @return bool
532
-     * @throws \EE_Error
533
-     */
534
-    public function is_off_site()
535
-    {
536
-        return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite;
537
-    }
538
-
539
-
540
-    /**
541
-     * Returns TRUE if this payment method does not utilize a gateway
542
-     *
543
-     * @return bool
544
-     * @throws \EE_Error
545
-     */
546
-    public function is_off_line()
547
-    {
548
-        return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline;
549
-    }
550
-
551
-    /**
552
-     * Overrides default __sleep so the object type is NOT cached.
553
-     * This way we can rely on the normal EE_Payment_Method::type_obj() logic
554
-     * to load the required classes, and don't need them at the time of unserialization
555
-     *
556
-     * @return array
557
-     */
558
-    public function __sleep()
559
-    {
560
-        $properties = get_object_vars($this);
561
-        unset($properties['_type_obj']);
562
-        return array_keys($properties);
563
-    }
564
-
565
-
566
-    /**
567
-     * Overrides parent to add some logging for when payment methods get deactivated
568
-     *
569
-     * @param array $set_cols_n_values
570
-     * @return int @see EE_Base_Class::save()
571
-     * @throws \EE_Error
572
-     */
573
-    public function save($set_cols_n_values = array())
574
-    {
575
-        $results = parent::save($set_cols_n_values);
576
-        if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) {
577
-            /** @var CurrentPage $current_page */
578
-            $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
579
-            EE_Log::instance()->log(
580
-                __FILE__,
581
-                __FUNCTION__,
582
-                sprintf(
583
-                    esc_html__('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'),
584
-                    $this->name(),
585
-                    serialize($this->get_original('PMD_scope')),
586
-                    serialize($this->get('PMD_scope')),
587
-                    $current_page->getPermalink()
588
-                ),
589
-                'payment_method_change'
590
-            );
591
-        }
592
-        return $results;
593
-    }
482
+	}
483
+
484
+
485
+	/**
486
+	 * Gets all the currencies which are an option for this payment method
487
+	 * (as defined by the gateway and the currently active currencies)
488
+	 *
489
+	 * @return EE_Currency[]
490
+	 * @throws \EE_Error
491
+	 */
492
+	public function get_all_usable_currencies()
493
+	{
494
+		return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj());
495
+	}
496
+
497
+
498
+	/**
499
+	 * Reports whether or not this payment method can be used for this payment method
500
+	 *
501
+	 * @param string $currency_code currency ID (code)
502
+	 * @return boolean
503
+	 * @throws \EE_Error
504
+	 */
505
+	public function usable_for_currency($currency_code)
506
+	{
507
+		foreach ($this->get_all_usable_currencies() as $currency_obj) {
508
+			if ($currency_obj->ID() === $currency_code) {
509
+				return true;
510
+			}
511
+		}
512
+		return false;
513
+	}
514
+
515
+
516
+	/**
517
+	 * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway
518
+	 *
519
+	 * @return bool
520
+	 * @throws \EE_Error
521
+	 */
522
+	public function is_on_site()
523
+	{
524
+		return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite;
525
+	}
526
+
527
+
528
+	/**
529
+	 * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway
530
+	 *
531
+	 * @return bool
532
+	 * @throws \EE_Error
533
+	 */
534
+	public function is_off_site()
535
+	{
536
+		return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite;
537
+	}
538
+
539
+
540
+	/**
541
+	 * Returns TRUE if this payment method does not utilize a gateway
542
+	 *
543
+	 * @return bool
544
+	 * @throws \EE_Error
545
+	 */
546
+	public function is_off_line()
547
+	{
548
+		return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline;
549
+	}
550
+
551
+	/**
552
+	 * Overrides default __sleep so the object type is NOT cached.
553
+	 * This way we can rely on the normal EE_Payment_Method::type_obj() logic
554
+	 * to load the required classes, and don't need them at the time of unserialization
555
+	 *
556
+	 * @return array
557
+	 */
558
+	public function __sleep()
559
+	{
560
+		$properties = get_object_vars($this);
561
+		unset($properties['_type_obj']);
562
+		return array_keys($properties);
563
+	}
564
+
565
+
566
+	/**
567
+	 * Overrides parent to add some logging for when payment methods get deactivated
568
+	 *
569
+	 * @param array $set_cols_n_values
570
+	 * @return int @see EE_Base_Class::save()
571
+	 * @throws \EE_Error
572
+	 */
573
+	public function save($set_cols_n_values = array())
574
+	{
575
+		$results = parent::save($set_cols_n_values);
576
+		if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) {
577
+			/** @var CurrentPage $current_page */
578
+			$current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
579
+			EE_Log::instance()->log(
580
+				__FILE__,
581
+				__FUNCTION__,
582
+				sprintf(
583
+					esc_html__('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'),
584
+					$this->name(),
585
+					serialize($this->get_original('PMD_scope')),
586
+					serialize($this->get('PMD_scope')),
587
+					$current_page->getPermalink()
588
+				),
589
+				'payment_method_change'
590
+			);
591
+		}
592
+		return $results;
593
+	}
594 594
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Message.model.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
             self::priority_low    => esc_html__('low', 'event_espresso'),
127 127
         );
128 128
 
129
-        $this->_fields          = array(
129
+        $this->_fields = array(
130 130
             'Message' => array(
131 131
                 'MSG_ID'             => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')),
132 132
                 'MSG_token'          => new EE_Plain_Text_Field(
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
                         );
437 437
                         break;
438 438
                     default:
439
-                        $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value;
439
+                        $query_params[0]['AND**filter_by']['OR**filter_by_'.$request_key][$model_name.'.'.$request_key] = $request_value;
440 440
                         break;
441 441
                 }
442 442
             }
@@ -499,8 +499,8 @@  discard block
 block discarded – undo
499 499
         if ($label_parts) {
500 500
             // prepend to the last element of $label_parts an "and".
501 501
             if (count($label_parts) > 1) {
502
-                $label_parts_index_to_prepend               = count($label_parts) - 1;
503
-                $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ];
502
+                $label_parts_index_to_prepend = count($label_parts) - 1;
503
+                $label_parts[$label_parts_index_to_prepend] = 'and'.$label_parts[$label_parts_index_to_prepend];
504 504
             }
505 505
 
506 506
             $pretty_label .= sprintf(
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
             $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
561 561
         }
562 562
 
563
-        if (! is_null($set_debug)) {
563
+        if ( ! is_null($set_debug)) {
564 564
             $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
565 565
         }
566 566
 
@@ -627,13 +627,13 @@  discard block
 block discarded – undo
627 627
             )
628 628
         );
629 629
 
630
-        if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
630
+        if ( ! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
631 631
             global $wpdb;
632 632
             $number_deleted = $wpdb->query('
633 633
                 DELETE
634
-                FROM ' . $this->table() . '
634
+                FROM ' . $this->table().'
635 635
                 WHERE
636
-                    MSG_ID IN (' . implode(",", $message_ids_to_delete) . ')
636
+                    MSG_ID IN (' . implode(",", $message_ids_to_delete).')
637 637
             ');
638 638
         }
639 639
 
Please login to merge, or discard this patch.
Indentation   +640 added lines, -640 removed lines patch added patch discarded remove patch
@@ -12,649 +12,649 @@
 block discarded – undo
12 12
  */
13 13
 class EEM_Message extends EEM_Base implements EEI_Query_Filter
14 14
 {
15
-    // private instance of the Message object
16
-    protected static $_instance = null;
17
-
18
-
19
-    /**
20
-     * This priority indicates a message should be generated and sent ASAP
21
-     *
22
-     * @type int
23
-     */
24
-    const priority_high = 10;
25
-
26
-
27
-    /**
28
-     * This priority indicates a message should be generated ASAP and queued for sending.
29
-     *
30
-     * @type
31
-     */
32
-    const priority_medium = 20;
33
-
34
-
35
-    /**
36
-     * This priority indicates a message should be queued for generating.
37
-     *
38
-     * @type int
39
-     */
40
-    const priority_low = 30;
41
-
42
-
43
-    /**
44
-     * indicates this message was sent at the time modified
45
-     */
46
-    const status_sent = 'MSN';
47
-
48
-
49
-    /**
50
-     * indicates this message is waiting to be sent
51
-     */
52
-    const status_idle = 'MID';
53
-
54
-
55
-    /**
56
-     * indicates an attempt was a made to send this message
57
-     * at the scheduled time, but it failed at the time modified.  This differs from MDO status in that it will ALWAYS
58
-     * appear to the end user.
59
-     */
60
-    const status_failed = 'MFL';
61
-
62
-
63
-    /**
64
-     * indicates the message has been flagged for resending (at the time modified).
65
-     */
66
-    const status_resend = 'MRS';
67
-
68
-
69
-    /**
70
-     * indicates the message has been flagged for generation but has not been generated yet.  Messages always start as
71
-     * this status when added to the queue.
72
-     */
73
-    const status_incomplete = 'MIC';
74
-
75
-
76
-    /**
77
-     * Indicates everything was generated fine for the message, however, the messenger was unable to send.
78
-     * This status means that its possible to retry sending the message.
79
-     */
80
-    const status_retry = 'MRT';
81
-
82
-
83
-    /**
84
-     * This is used for more informational messages that may not indicate anything is broken but still cannot be
85
-     * generated or sent correctly. An example of a message that would get flagged this way would be when a not
86
-     * approved message was queued for generation, but at time of generation, the attached registration(s) are
87
-     * approved. So the message queued for generation is no longer valid.  Messages for this status will only persist
88
-     * in the db and be viewable in the message activity list table when the messages system is in debug mode.
89
-     *
90
-     * @see EEM_Message::debug()
91
-     */
92
-    const status_debug_only = 'MDO';
93
-
94
-
95
-    /**
96
-     * This status is given to messages it is processed by the messenger send method.
97
-     * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually
98
-     * indicative of a PHP timeout or memory limit issue.
99
-     */
100
-    const status_messenger_executing = 'MEX';
101
-
102
-
103
-    /**
104
-     *    Private constructor to prevent direct creation.
105
-     *
106
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and
107
-     *                         any incoming timezone data that gets saved).  Note this just sends the timezone info to
108
-     *                         the date time model field objects.  Default is null (and will be assumed using the set
109
-     *                         timezone in the 'timezone_string' wp option)
110
-     * @throws EE_Error
111
-     * @throws EE_Error
112
-     * @throws EE_Error
113
-     */
114
-    protected function __construct($timezone = null)
115
-    {
116
-        $this->singular_item = esc_html__('Message', 'event_espresso');
117
-        $this->plural_item   = esc_html__('Messages', 'event_espresso');
118
-
119
-        $this->_tables = array(
120
-            'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'),
121
-        );
122
-
123
-        $allowed_priority = array(
124
-            self::priority_high   => esc_html__('high', 'event_espresso'),
125
-            self::priority_medium => esc_html__('medium', 'event_espresso'),
126
-            self::priority_low    => esc_html__('low', 'event_espresso'),
127
-        );
128
-
129
-        $this->_fields          = array(
130
-            'Message' => array(
131
-                'MSG_ID'             => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')),
132
-                'MSG_token'          => new EE_Plain_Text_Field(
133
-                    'MSG_token',
134
-                    esc_html__(
135
-                        'Unique Token used to represent this row in publicly viewable contexts (eg. a url).',
136
-                        'event_espresso'
137
-                    ),
138
-                    false,
139
-                    EEH_URL::generate_unique_token()
140
-                ),
141
-                'GRP_ID'             => new EE_Foreign_Key_Int_Field(
142
-                    'GRP_ID',
143
-                    esc_html__('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'),
144
-                    true,
145
-                    0,
146
-                    'Message_Template_Group'
147
-                ),
148
-                'TXN_ID'             => new EE_Foreign_Key_Int_Field(
149
-                    'TXN_ID',
150
-                    esc_html__(
151
-                        'Foreign key to the related EE_Transaction.  This is required to give context for regenerating the specific message',
152
-                        'event_espresso'
153
-                    ),
154
-                    true,
155
-                    0,
156
-                    'Transaction'
157
-                ),
158
-                'MSG_messenger'      => new EE_Plain_Text_Field(
159
-                    'MSG_messenger',
160
-                    esc_html__(
161
-                        'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.',
162
-                        'event_espresso'
163
-                    ),
164
-                    false,
165
-                    'email'
166
-                ),
167
-                'MSG_message_type'   => new EE_Plain_Text_Field(
168
-                    'MSG_message_type',
169
-                    esc_html__('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'),
170
-                    false,
171
-                    'receipt'
172
-                ),
173
-                'MSG_context'        => new EE_Plain_Text_Field('MSG_context', esc_html__('Context', 'event_espresso'), false),
174
-                'MSG_recipient_ID'   => new EE_Foreign_Key_Int_Field(
175
-                    'MSG_recipient_ID',
176
-                    esc_html__('Recipient ID', 'event_espresso'),
177
-                    true,
178
-                    null,
179
-                    array('Registration', 'Attendee', 'WP_User')
180
-                ),
181
-                'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field(
182
-                    'MSG_recipient_type',
183
-                    esc_html__('Recipient Type', 'event_espresso'),
184
-                    true,
185
-                    null,
186
-                    array('Registration', 'Attendee', 'WP_User')
187
-                ),
188
-                'MSG_content'        => new EE_Maybe_Serialized_Text_Field(
189
-                    'MSG_content',
190
-                    esc_html__('Content', 'event_espresso'),
191
-                    true,
192
-                    ''
193
-                ),
194
-                'MSG_to'             => new EE_Maybe_Serialized_Text_Field(
195
-                    'MSG_to',
196
-                    esc_html__('Address To', 'event_espresso'),
197
-                    true
198
-                ),
199
-                'MSG_from'           => new EE_Maybe_Serialized_Text_Field(
200
-                    'MSG_from',
201
-                    esc_html__('Address From', 'event_espresso'),
202
-                    true
203
-                ),
204
-                'MSG_subject'        => new EE_Maybe_Serialized_Text_Field(
205
-                    'MSG_subject',
206
-                    esc_html__('Subject', 'event_espresso'),
207
-                    true,
208
-                    ''
209
-                ),
210
-                'MSG_priority'       => new EE_Enum_Integer_Field(
211
-                    'MSG_priority',
212
-                    esc_html__('Priority', 'event_espresso'),
213
-                    false,
214
-                    self::priority_low,
215
-                    $allowed_priority
216
-                ),
217
-                'STS_ID'             => new EE_Foreign_Key_String_Field(
218
-                    'STS_ID',
219
-                    esc_html__('Status', 'event_espresso'),
220
-                    false,
221
-                    self::status_incomplete,
222
-                    'Status'
223
-                ),
224
-                'MSG_created'        => new EE_Datetime_Field(
225
-                    'MSG_created',
226
-                    esc_html__('Created', 'event_espresso'),
227
-                    false,
228
-                    EE_Datetime_Field::now
229
-                ),
230
-                'MSG_modified'       => new EE_Datetime_Field(
231
-                    'MSG_modified',
232
-                    esc_html__('Modified', 'event_espresso'),
233
-                    true,
234
-                    EE_Datetime_Field::now
235
-                ),
236
-            ),
237
-        );
238
-        $this->_model_relations = array(
239
-            'Attendee'               => new EE_Belongs_To_Any_Relation(),
240
-            'Registration'           => new EE_Belongs_To_Any_Relation(),
241
-            'WP_User'                => new EE_Belongs_To_Any_Relation(),
242
-            'Message_Template_Group' => new EE_Belongs_To_Relation(),
243
-            'Transaction'            => new EE_Belongs_To_Relation(),
244
-        );
245
-        parent::__construct($timezone);
246
-    }
247
-
248
-
249
-    /**
250
-     * @return EE_Message
251
-     * @throws EE_Error
252
-     */
253
-    public function create_default_object()
254
-    {
255
-        /** @type EE_Message $message */
256
-        $message = parent::create_default_object();
257
-        if ($message instanceof EE_Message) {
258
-            return EE_Message_Factory::set_messenger_and_message_type($message);
259
-        }
260
-        return null;
261
-    }
262
-
263
-
264
-    /**
265
-     * @param mixed $cols_n_values
266
-     * @return EE_Message
267
-     * @throws EE_Error
268
-     * @throws EE_Error
269
-     */
270
-    public function instantiate_class_from_array_or_object($cols_n_values)
271
-    {
272
-        /** @type EE_Message $message */
273
-        $message = parent::instantiate_class_from_array_or_object($cols_n_values);
274
-        if ($message instanceof EE_Message) {
275
-            return EE_Message_Factory::set_messenger_and_message_type($message);
276
-        }
277
-        return null;
278
-    }
279
-
280
-
281
-    /**
282
-     * Returns whether or not a message of that type was sent for a given attendee.
283
-     *
284
-     * @param EE_Attendee|int $attendee
285
-     * @param string          $message_type the message type slug
286
-     * @return boolean
287
-     * @throws EE_Error
288
-     * @throws EE_Error
289
-     * @throws EE_Error
290
-     */
291
-    public function message_sent_for_attendee($attendee, $message_type)
292
-    {
293
-        $attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee);
294
-        return $this->exists(array(
295
-            array(
296
-                'Attendee.ATT_ID'  => $attendee_ID,
297
-                'MSG_message_type' => $message_type,
298
-                'STS_ID'           => array('IN', $this->stati_indicating_sent()),
299
-            ),
300
-        ));
301
-    }
302
-
303
-
304
-    /**
305
-     * Returns whether or not a message of that type was sent for a given registration
306
-     *
307
-     * @param EE_Registration|int $registration
308
-     * @param string              $message_type the message type slug
309
-     * @return boolean
310
-     * @throws EE_Error
311
-     * @throws EE_Error
312
-     * @throws EE_Error
313
-     */
314
-    public function message_sent_for_registration($registration, $message_type)
315
-    {
316
-        $registrationID = EEM_Registration::instance()->ensure_is_ID($registration);
317
-        return $this->exists(array(
318
-            array(
319
-                'Registration.REG_ID' => $registrationID,
320
-                'MSG_message_type'    => $message_type,
321
-                'STS_ID'              => array('IN', $this->stati_indicating_sent()),
322
-            ),
323
-        ));
324
-    }
325
-
326
-
327
-    /**
328
-     * This retrieves an EE_Message object from the db matching the given token string.
329
-     *
330
-     * @param string $token
331
-     * @return EE_Message
332
-     * @throws EE_Error
333
-     */
334
-    public function get_one_by_token($token)
335
-    {
336
-        return $this->get_one(array(
337
-            array(
338
-                'MSG_token' => $token,
339
-            ),
340
-        ));
341
-    }
342
-
343
-
344
-    /**
345
-     * Returns stati that indicate the message HAS been sent
346
-     *
347
-     * @return array of strings for possible stati
348
-     */
349
-    public function stati_indicating_sent()
350
-    {
351
-        return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent));
352
-    }
353
-
354
-
355
-    /**
356
-     * Returns stati that indicate the message is waiting to be sent.
357
-     *
358
-     * @return array of strings for possible stati.
359
-     */
360
-    public function stati_indicating_to_send()
361
-    {
362
-        return apply_filters(
363
-            'FHEE__EEM_Message__stati_indicating_to_send',
364
-            array(self::status_idle, self::status_resend)
365
-        );
366
-    }
367
-
368
-
369
-    /**
370
-     * Returns stati that indicate the message has failed sending
371
-     *
372
-     * @return array  array of strings for possible stati.
373
-     */
374
-    public function stati_indicating_failed_sending()
375
-    {
376
-        $failed_stati = array(
377
-            self::status_failed,
378
-            self::status_retry,
379
-            self::status_messenger_executing,
380
-        );
381
-        // if WP_DEBUG is set, then let's include debug_only fails
382
-        if (WP_DEBUG) {
383
-            $failed_stati[] = self::status_debug_only;
384
-        }
385
-        return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati);
386
-    }
387
-
388
-
389
-    /**
390
-     * Returns filterable array of all EEM_Message statuses.
391
-     *
392
-     * @return array
393
-     */
394
-    public function all_statuses()
395
-    {
396
-        return apply_filters(
397
-            'FHEE__EEM_Message__all_statuses',
398
-            array(
399
-                EEM_Message::status_sent,
400
-                EEM_Message::status_incomplete,
401
-                EEM_Message::status_idle,
402
-                EEM_Message::status_resend,
403
-                EEM_Message::status_retry,
404
-                EEM_Message::status_failed,
405
-                EEM_Message::status_messenger_executing,
406
-                EEM_Message::status_debug_only,
407
-            )
408
-        );
409
-    }
410
-
411
-    /**
412
-     * Detects any specific query variables in the request and uses those to setup appropriate
413
-     * filter for any queries.
414
-     *
415
-     * @return array
416
-     */
417
-    public function filter_by_query_params()
418
-    {
419
-        /** @var RequestInterface $request */
420
-        $request = EEM_Base::$loader->getShared(RequestInterface::class);
421
-        // expected possible query_vars, the key in this array matches an expected key in the request,
422
-        // the value, matches the corresponding EEM_Base child reference.
423
-        $expected_vars   = $this->_expected_vars_for_query_inject();
424
-        $query_params[0] = array();
425
-        foreach ($expected_vars as $request_key => $model_name) {
426
-            $request_value = $request->getRequestParam($request_key);
427
-            if ($request_value) {
428
-                // special case
429
-                switch ($request_key) {
430
-                    case '_REG_ID':
431
-                        $query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array(
432
-                            'Transaction.Registration.REG_ID' => $request_value,
433
-                        );
434
-                        break;
435
-                    case 'EVT_ID':
436
-                        $query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = array(
437
-                            'Transaction.Registration.EVT_ID' => $request_value,
438
-                        );
439
-                        break;
440
-                    default:
441
-                        $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value;
442
-                        break;
443
-                }
444
-            }
445
-        }
446
-        return $query_params;
447
-    }
448
-
449
-
450
-    /**
451
-     * @return string
452
-     * @throws EE_Error
453
-     * @throws ReflectionException
454
-     */
455
-    public function get_pretty_label_for_results()
456
-    {
457
-        /** @var RequestInterface $request */
458
-        $request = EEM_Base::$loader->getShared(RequestInterface::class);
459
-        $expected_vars = $this->_expected_vars_for_query_inject();
460
-        $pretty_label  = '';
461
-        $label_parts   = array();
462
-        foreach ($expected_vars as $request_key => $model_name) {
463
-            $model_name = strpos($model_name, 'EEM_', true) === 0 ? $model_name : "EEM_{$model_name}";
464
-            $model = EEM_Base::$loader->getShared($model_name);
465
-            $model_field_value = $request->getRequestParam($request_key);
466
-            if ($model instanceof EEM_Base && $model_field_value !== '') {
467
-                switch ($request_key) {
468
-                    case '_REG_ID':
469
-                        $label_parts[] = sprintf(
470
-                            esc_html__('Registration with the ID: %s', 'event_espresso'),
471
-                            $model_field_value
472
-                        );
473
-                        break;
474
-                    case 'ATT_ID':
475
-                        /** @var EE_Attendee $attendee */
476
-                        $attendee      = $model->get_one_by_ID($model_field_value);
477
-                        $label_parts[] = $attendee instanceof EE_Attendee
478
-                            ? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name())
479
-                            : sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value);
480
-                        break;
481
-                    case 'ID':
482
-                        /** @var EE_WP_User $wpUser */
483
-                        $wpUser        = $model->get_one_by_ID($model_field_value);
484
-                        $label_parts[] = $wpUser instanceof EE_WP_User
485
-                            ? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name())
486
-                            : sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value);
487
-                        break;
488
-                    case 'TXN_ID':
489
-                        $label_parts[] = sprintf(
490
-                            esc_html__('Transaction with the ID: %s', 'event_espresso'),
491
-                            $model_field_value
492
-                        );
493
-                        break;
494
-                    case 'EVT_ID':
495
-                        /** @var EE_Event $Event */
496
-                        $Event         = $model->get_one_by_ID($model_field_value);
497
-                        $label_parts[] = $Event instanceof EE_Event
498
-                            ? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name())
499
-                            : sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value);
500
-                        break;
501
-                }
502
-            }
503
-        }
504
-
505
-        if ($label_parts) {
506
-            // prepend to the last element of $label_parts an "and".
507
-            if (count($label_parts) > 1) {
508
-                $label_parts_index_to_prepend               = count($label_parts) - 1;
509
-                $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ];
510
-            }
511
-
512
-            $pretty_label .= sprintf(
513
-                esc_html_x(
514
-                    'Showing messages for %s',
515
-                    'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.',
516
-                    'event_espresso'
517
-                ),
518
-                implode(', ', $label_parts)
519
-            );
520
-        }
521
-        return $pretty_label;
522
-    }
523
-
524
-
525
-    /**
526
-     * This returns the array of expected variables for the EEI_Query_Filter methods being implemented
527
-     * The array is in the format:
528
-     * array(
529
-     *  {$field_name} => {$model_name}
530
-     * );
531
-     *
532
-     * @since 4.9.0
533
-     * @return array
534
-     */
535
-    protected function _expected_vars_for_query_inject()
536
-    {
537
-        return array(
538
-            '_REG_ID' => 'Registration',
539
-            'ATT_ID'  => 'Attendee',
540
-            'ID'      => 'WP_User',
541
-            'TXN_ID'  => 'Transaction',
542
-            'EVT_ID'  => 'Event',
543
-        );
544
-    }
545
-
546
-
547
-    /**
548
-     * This returns whether EEM_Message is in debug mode or not.
549
-     * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when
550
-     * generating/sending messages. Debug mode can be set by either:
551
-     * 1. Sending in a value for the $set_debug argument
552
-     * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php
553
-     * 3. Overriding the above via the provided filter.
554
-     *
555
-     * @param bool|null $set_debug      If provided, then the debug mode will be set internally until reset via the
556
-     *                                  provided boolean. When no argument is provided (default null) then the debug
557
-     *                                  mode will be returned.
558
-     * @return bool         true means Messages is in debug mode.  false means messages system is not in debug mode.
559
-     */
560
-    public static function debug($set_debug = null)
561
-    {
562
-        static $is_debugging = null;
563
-
564
-        // initialize (use constant if set).
565
-        if (is_null($set_debug) && is_null($is_debugging)) {
566
-            $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
567
-        }
568
-
569
-        if (! is_null($set_debug)) {
570
-            $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
571
-        }
572
-
573
-        // return filtered value
574
-        return apply_filters('FHEE__EEM_Message__debug', $is_debugging);
575
-    }
576
-
577
-
578
-    /**
579
-     * Deletes old messages meeting certain criteria for removal from the database.
580
-     * By default, this will delete messages that:
581
-     * - are older than the value of the delete_threshold in months.
582
-     * - have a STS_ID other than EEM_Message::status_idle
583
-     *
584
-     * @param int $delete_threshold This integer will be used to set the boundary for what messages are deleted in
585
-     *                              months.
586
-     * @return bool|false|int Either the number of records affected or false if there was an error (you can call
587
-     *                              $wpdb->last_error to find out what the error was.
588
-     * @throws EE_Error
589
-     * @throws EE_Error
590
-     * @throws EE_Error
591
-     */
592
-    public function delete_old_messages($delete_threshold = 6)
593
-    {
594
-        $number_deleted = 0;
595
-        /**
596
-         * Allows code to change the boundary for what messages are kept.
597
-         * Uses the value of the `delete_threshold` variable by default.
598
-         *
599
-         * @param int $seconds seconds that will be subtracted from the timestamp for now.
600
-         * @return int
601
-         */
602
-        $time_to_leave_alone = absint(
603
-            apply_filters(
604
-                'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone',
605
-                ((int) $delete_threshold) * MONTH_IN_SECONDS
606
-            )
607
-        );
608
-
609
-
610
-        /**
611
-         * Allows code to change what message stati are ignored when deleting.
612
-         * Defaults to only ignore EEM_Message::status_idle messages.
613
-         *
614
-         * @param string $message_stati_to_keep  An array of message statuses that will be ignored when deleting.
615
-         */
616
-        $message_stati_to_keep = (array) apply_filters(
617
-            'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep',
618
-            array(
619
-                EEM_Message::status_idle
620
-            )
621
-        );
622
-
623
-        // first get all the ids of messages being deleted
624
-        $message_ids_to_delete = EEM_Message::instance()->get_col(
625
-            array(
626
-                0 => array(
627
-                    'STS_ID' => array('NOT_IN', $message_stati_to_keep),
628
-                    'MSG_modified' => array('<', time() - $time_to_leave_alone)
629
-                ),
630
-                'limit' => apply_filters(
631
-                    'EEM_Message__delete_old_messages__limit',
632
-                    2000,
633
-                    $delete_threshold
634
-                )
635
-            )
636
-        );
637
-
638
-        if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
639
-            global $wpdb;
640
-            $number_deleted = $wpdb->query('
15
+	// private instance of the Message object
16
+	protected static $_instance = null;
17
+
18
+
19
+	/**
20
+	 * This priority indicates a message should be generated and sent ASAP
21
+	 *
22
+	 * @type int
23
+	 */
24
+	const priority_high = 10;
25
+
26
+
27
+	/**
28
+	 * This priority indicates a message should be generated ASAP and queued for sending.
29
+	 *
30
+	 * @type
31
+	 */
32
+	const priority_medium = 20;
33
+
34
+
35
+	/**
36
+	 * This priority indicates a message should be queued for generating.
37
+	 *
38
+	 * @type int
39
+	 */
40
+	const priority_low = 30;
41
+
42
+
43
+	/**
44
+	 * indicates this message was sent at the time modified
45
+	 */
46
+	const status_sent = 'MSN';
47
+
48
+
49
+	/**
50
+	 * indicates this message is waiting to be sent
51
+	 */
52
+	const status_idle = 'MID';
53
+
54
+
55
+	/**
56
+	 * indicates an attempt was a made to send this message
57
+	 * at the scheduled time, but it failed at the time modified.  This differs from MDO status in that it will ALWAYS
58
+	 * appear to the end user.
59
+	 */
60
+	const status_failed = 'MFL';
61
+
62
+
63
+	/**
64
+	 * indicates the message has been flagged for resending (at the time modified).
65
+	 */
66
+	const status_resend = 'MRS';
67
+
68
+
69
+	/**
70
+	 * indicates the message has been flagged for generation but has not been generated yet.  Messages always start as
71
+	 * this status when added to the queue.
72
+	 */
73
+	const status_incomplete = 'MIC';
74
+
75
+
76
+	/**
77
+	 * Indicates everything was generated fine for the message, however, the messenger was unable to send.
78
+	 * This status means that its possible to retry sending the message.
79
+	 */
80
+	const status_retry = 'MRT';
81
+
82
+
83
+	/**
84
+	 * This is used for more informational messages that may not indicate anything is broken but still cannot be
85
+	 * generated or sent correctly. An example of a message that would get flagged this way would be when a not
86
+	 * approved message was queued for generation, but at time of generation, the attached registration(s) are
87
+	 * approved. So the message queued for generation is no longer valid.  Messages for this status will only persist
88
+	 * in the db and be viewable in the message activity list table when the messages system is in debug mode.
89
+	 *
90
+	 * @see EEM_Message::debug()
91
+	 */
92
+	const status_debug_only = 'MDO';
93
+
94
+
95
+	/**
96
+	 * This status is given to messages it is processed by the messenger send method.
97
+	 * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually
98
+	 * indicative of a PHP timeout or memory limit issue.
99
+	 */
100
+	const status_messenger_executing = 'MEX';
101
+
102
+
103
+	/**
104
+	 *    Private constructor to prevent direct creation.
105
+	 *
106
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and
107
+	 *                         any incoming timezone data that gets saved).  Note this just sends the timezone info to
108
+	 *                         the date time model field objects.  Default is null (and will be assumed using the set
109
+	 *                         timezone in the 'timezone_string' wp option)
110
+	 * @throws EE_Error
111
+	 * @throws EE_Error
112
+	 * @throws EE_Error
113
+	 */
114
+	protected function __construct($timezone = null)
115
+	{
116
+		$this->singular_item = esc_html__('Message', 'event_espresso');
117
+		$this->plural_item   = esc_html__('Messages', 'event_espresso');
118
+
119
+		$this->_tables = array(
120
+			'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'),
121
+		);
122
+
123
+		$allowed_priority = array(
124
+			self::priority_high   => esc_html__('high', 'event_espresso'),
125
+			self::priority_medium => esc_html__('medium', 'event_espresso'),
126
+			self::priority_low    => esc_html__('low', 'event_espresso'),
127
+		);
128
+
129
+		$this->_fields          = array(
130
+			'Message' => array(
131
+				'MSG_ID'             => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')),
132
+				'MSG_token'          => new EE_Plain_Text_Field(
133
+					'MSG_token',
134
+					esc_html__(
135
+						'Unique Token used to represent this row in publicly viewable contexts (eg. a url).',
136
+						'event_espresso'
137
+					),
138
+					false,
139
+					EEH_URL::generate_unique_token()
140
+				),
141
+				'GRP_ID'             => new EE_Foreign_Key_Int_Field(
142
+					'GRP_ID',
143
+					esc_html__('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'),
144
+					true,
145
+					0,
146
+					'Message_Template_Group'
147
+				),
148
+				'TXN_ID'             => new EE_Foreign_Key_Int_Field(
149
+					'TXN_ID',
150
+					esc_html__(
151
+						'Foreign key to the related EE_Transaction.  This is required to give context for regenerating the specific message',
152
+						'event_espresso'
153
+					),
154
+					true,
155
+					0,
156
+					'Transaction'
157
+				),
158
+				'MSG_messenger'      => new EE_Plain_Text_Field(
159
+					'MSG_messenger',
160
+					esc_html__(
161
+						'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.',
162
+						'event_espresso'
163
+					),
164
+					false,
165
+					'email'
166
+				),
167
+				'MSG_message_type'   => new EE_Plain_Text_Field(
168
+					'MSG_message_type',
169
+					esc_html__('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'),
170
+					false,
171
+					'receipt'
172
+				),
173
+				'MSG_context'        => new EE_Plain_Text_Field('MSG_context', esc_html__('Context', 'event_espresso'), false),
174
+				'MSG_recipient_ID'   => new EE_Foreign_Key_Int_Field(
175
+					'MSG_recipient_ID',
176
+					esc_html__('Recipient ID', 'event_espresso'),
177
+					true,
178
+					null,
179
+					array('Registration', 'Attendee', 'WP_User')
180
+				),
181
+				'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field(
182
+					'MSG_recipient_type',
183
+					esc_html__('Recipient Type', 'event_espresso'),
184
+					true,
185
+					null,
186
+					array('Registration', 'Attendee', 'WP_User')
187
+				),
188
+				'MSG_content'        => new EE_Maybe_Serialized_Text_Field(
189
+					'MSG_content',
190
+					esc_html__('Content', 'event_espresso'),
191
+					true,
192
+					''
193
+				),
194
+				'MSG_to'             => new EE_Maybe_Serialized_Text_Field(
195
+					'MSG_to',
196
+					esc_html__('Address To', 'event_espresso'),
197
+					true
198
+				),
199
+				'MSG_from'           => new EE_Maybe_Serialized_Text_Field(
200
+					'MSG_from',
201
+					esc_html__('Address From', 'event_espresso'),
202
+					true
203
+				),
204
+				'MSG_subject'        => new EE_Maybe_Serialized_Text_Field(
205
+					'MSG_subject',
206
+					esc_html__('Subject', 'event_espresso'),
207
+					true,
208
+					''
209
+				),
210
+				'MSG_priority'       => new EE_Enum_Integer_Field(
211
+					'MSG_priority',
212
+					esc_html__('Priority', 'event_espresso'),
213
+					false,
214
+					self::priority_low,
215
+					$allowed_priority
216
+				),
217
+				'STS_ID'             => new EE_Foreign_Key_String_Field(
218
+					'STS_ID',
219
+					esc_html__('Status', 'event_espresso'),
220
+					false,
221
+					self::status_incomplete,
222
+					'Status'
223
+				),
224
+				'MSG_created'        => new EE_Datetime_Field(
225
+					'MSG_created',
226
+					esc_html__('Created', 'event_espresso'),
227
+					false,
228
+					EE_Datetime_Field::now
229
+				),
230
+				'MSG_modified'       => new EE_Datetime_Field(
231
+					'MSG_modified',
232
+					esc_html__('Modified', 'event_espresso'),
233
+					true,
234
+					EE_Datetime_Field::now
235
+				),
236
+			),
237
+		);
238
+		$this->_model_relations = array(
239
+			'Attendee'               => new EE_Belongs_To_Any_Relation(),
240
+			'Registration'           => new EE_Belongs_To_Any_Relation(),
241
+			'WP_User'                => new EE_Belongs_To_Any_Relation(),
242
+			'Message_Template_Group' => new EE_Belongs_To_Relation(),
243
+			'Transaction'            => new EE_Belongs_To_Relation(),
244
+		);
245
+		parent::__construct($timezone);
246
+	}
247
+
248
+
249
+	/**
250
+	 * @return EE_Message
251
+	 * @throws EE_Error
252
+	 */
253
+	public function create_default_object()
254
+	{
255
+		/** @type EE_Message $message */
256
+		$message = parent::create_default_object();
257
+		if ($message instanceof EE_Message) {
258
+			return EE_Message_Factory::set_messenger_and_message_type($message);
259
+		}
260
+		return null;
261
+	}
262
+
263
+
264
+	/**
265
+	 * @param mixed $cols_n_values
266
+	 * @return EE_Message
267
+	 * @throws EE_Error
268
+	 * @throws EE_Error
269
+	 */
270
+	public function instantiate_class_from_array_or_object($cols_n_values)
271
+	{
272
+		/** @type EE_Message $message */
273
+		$message = parent::instantiate_class_from_array_or_object($cols_n_values);
274
+		if ($message instanceof EE_Message) {
275
+			return EE_Message_Factory::set_messenger_and_message_type($message);
276
+		}
277
+		return null;
278
+	}
279
+
280
+
281
+	/**
282
+	 * Returns whether or not a message of that type was sent for a given attendee.
283
+	 *
284
+	 * @param EE_Attendee|int $attendee
285
+	 * @param string          $message_type the message type slug
286
+	 * @return boolean
287
+	 * @throws EE_Error
288
+	 * @throws EE_Error
289
+	 * @throws EE_Error
290
+	 */
291
+	public function message_sent_for_attendee($attendee, $message_type)
292
+	{
293
+		$attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee);
294
+		return $this->exists(array(
295
+			array(
296
+				'Attendee.ATT_ID'  => $attendee_ID,
297
+				'MSG_message_type' => $message_type,
298
+				'STS_ID'           => array('IN', $this->stati_indicating_sent()),
299
+			),
300
+		));
301
+	}
302
+
303
+
304
+	/**
305
+	 * Returns whether or not a message of that type was sent for a given registration
306
+	 *
307
+	 * @param EE_Registration|int $registration
308
+	 * @param string              $message_type the message type slug
309
+	 * @return boolean
310
+	 * @throws EE_Error
311
+	 * @throws EE_Error
312
+	 * @throws EE_Error
313
+	 */
314
+	public function message_sent_for_registration($registration, $message_type)
315
+	{
316
+		$registrationID = EEM_Registration::instance()->ensure_is_ID($registration);
317
+		return $this->exists(array(
318
+			array(
319
+				'Registration.REG_ID' => $registrationID,
320
+				'MSG_message_type'    => $message_type,
321
+				'STS_ID'              => array('IN', $this->stati_indicating_sent()),
322
+			),
323
+		));
324
+	}
325
+
326
+
327
+	/**
328
+	 * This retrieves an EE_Message object from the db matching the given token string.
329
+	 *
330
+	 * @param string $token
331
+	 * @return EE_Message
332
+	 * @throws EE_Error
333
+	 */
334
+	public function get_one_by_token($token)
335
+	{
336
+		return $this->get_one(array(
337
+			array(
338
+				'MSG_token' => $token,
339
+			),
340
+		));
341
+	}
342
+
343
+
344
+	/**
345
+	 * Returns stati that indicate the message HAS been sent
346
+	 *
347
+	 * @return array of strings for possible stati
348
+	 */
349
+	public function stati_indicating_sent()
350
+	{
351
+		return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent));
352
+	}
353
+
354
+
355
+	/**
356
+	 * Returns stati that indicate the message is waiting to be sent.
357
+	 *
358
+	 * @return array of strings for possible stati.
359
+	 */
360
+	public function stati_indicating_to_send()
361
+	{
362
+		return apply_filters(
363
+			'FHEE__EEM_Message__stati_indicating_to_send',
364
+			array(self::status_idle, self::status_resend)
365
+		);
366
+	}
367
+
368
+
369
+	/**
370
+	 * Returns stati that indicate the message has failed sending
371
+	 *
372
+	 * @return array  array of strings for possible stati.
373
+	 */
374
+	public function stati_indicating_failed_sending()
375
+	{
376
+		$failed_stati = array(
377
+			self::status_failed,
378
+			self::status_retry,
379
+			self::status_messenger_executing,
380
+		);
381
+		// if WP_DEBUG is set, then let's include debug_only fails
382
+		if (WP_DEBUG) {
383
+			$failed_stati[] = self::status_debug_only;
384
+		}
385
+		return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati);
386
+	}
387
+
388
+
389
+	/**
390
+	 * Returns filterable array of all EEM_Message statuses.
391
+	 *
392
+	 * @return array
393
+	 */
394
+	public function all_statuses()
395
+	{
396
+		return apply_filters(
397
+			'FHEE__EEM_Message__all_statuses',
398
+			array(
399
+				EEM_Message::status_sent,
400
+				EEM_Message::status_incomplete,
401
+				EEM_Message::status_idle,
402
+				EEM_Message::status_resend,
403
+				EEM_Message::status_retry,
404
+				EEM_Message::status_failed,
405
+				EEM_Message::status_messenger_executing,
406
+				EEM_Message::status_debug_only,
407
+			)
408
+		);
409
+	}
410
+
411
+	/**
412
+	 * Detects any specific query variables in the request and uses those to setup appropriate
413
+	 * filter for any queries.
414
+	 *
415
+	 * @return array
416
+	 */
417
+	public function filter_by_query_params()
418
+	{
419
+		/** @var RequestInterface $request */
420
+		$request = EEM_Base::$loader->getShared(RequestInterface::class);
421
+		// expected possible query_vars, the key in this array matches an expected key in the request,
422
+		// the value, matches the corresponding EEM_Base child reference.
423
+		$expected_vars   = $this->_expected_vars_for_query_inject();
424
+		$query_params[0] = array();
425
+		foreach ($expected_vars as $request_key => $model_name) {
426
+			$request_value = $request->getRequestParam($request_key);
427
+			if ($request_value) {
428
+				// special case
429
+				switch ($request_key) {
430
+					case '_REG_ID':
431
+						$query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array(
432
+							'Transaction.Registration.REG_ID' => $request_value,
433
+						);
434
+						break;
435
+					case 'EVT_ID':
436
+						$query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = array(
437
+							'Transaction.Registration.EVT_ID' => $request_value,
438
+						);
439
+						break;
440
+					default:
441
+						$query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value;
442
+						break;
443
+				}
444
+			}
445
+		}
446
+		return $query_params;
447
+	}
448
+
449
+
450
+	/**
451
+	 * @return string
452
+	 * @throws EE_Error
453
+	 * @throws ReflectionException
454
+	 */
455
+	public function get_pretty_label_for_results()
456
+	{
457
+		/** @var RequestInterface $request */
458
+		$request = EEM_Base::$loader->getShared(RequestInterface::class);
459
+		$expected_vars = $this->_expected_vars_for_query_inject();
460
+		$pretty_label  = '';
461
+		$label_parts   = array();
462
+		foreach ($expected_vars as $request_key => $model_name) {
463
+			$model_name = strpos($model_name, 'EEM_', true) === 0 ? $model_name : "EEM_{$model_name}";
464
+			$model = EEM_Base::$loader->getShared($model_name);
465
+			$model_field_value = $request->getRequestParam($request_key);
466
+			if ($model instanceof EEM_Base && $model_field_value !== '') {
467
+				switch ($request_key) {
468
+					case '_REG_ID':
469
+						$label_parts[] = sprintf(
470
+							esc_html__('Registration with the ID: %s', 'event_espresso'),
471
+							$model_field_value
472
+						);
473
+						break;
474
+					case 'ATT_ID':
475
+						/** @var EE_Attendee $attendee */
476
+						$attendee      = $model->get_one_by_ID($model_field_value);
477
+						$label_parts[] = $attendee instanceof EE_Attendee
478
+							? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name())
479
+							: sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value);
480
+						break;
481
+					case 'ID':
482
+						/** @var EE_WP_User $wpUser */
483
+						$wpUser        = $model->get_one_by_ID($model_field_value);
484
+						$label_parts[] = $wpUser instanceof EE_WP_User
485
+							? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name())
486
+							: sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value);
487
+						break;
488
+					case 'TXN_ID':
489
+						$label_parts[] = sprintf(
490
+							esc_html__('Transaction with the ID: %s', 'event_espresso'),
491
+							$model_field_value
492
+						);
493
+						break;
494
+					case 'EVT_ID':
495
+						/** @var EE_Event $Event */
496
+						$Event         = $model->get_one_by_ID($model_field_value);
497
+						$label_parts[] = $Event instanceof EE_Event
498
+							? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name())
499
+							: sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value);
500
+						break;
501
+				}
502
+			}
503
+		}
504
+
505
+		if ($label_parts) {
506
+			// prepend to the last element of $label_parts an "and".
507
+			if (count($label_parts) > 1) {
508
+				$label_parts_index_to_prepend               = count($label_parts) - 1;
509
+				$label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ];
510
+			}
511
+
512
+			$pretty_label .= sprintf(
513
+				esc_html_x(
514
+					'Showing messages for %s',
515
+					'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.',
516
+					'event_espresso'
517
+				),
518
+				implode(', ', $label_parts)
519
+			);
520
+		}
521
+		return $pretty_label;
522
+	}
523
+
524
+
525
+	/**
526
+	 * This returns the array of expected variables for the EEI_Query_Filter methods being implemented
527
+	 * The array is in the format:
528
+	 * array(
529
+	 *  {$field_name} => {$model_name}
530
+	 * );
531
+	 *
532
+	 * @since 4.9.0
533
+	 * @return array
534
+	 */
535
+	protected function _expected_vars_for_query_inject()
536
+	{
537
+		return array(
538
+			'_REG_ID' => 'Registration',
539
+			'ATT_ID'  => 'Attendee',
540
+			'ID'      => 'WP_User',
541
+			'TXN_ID'  => 'Transaction',
542
+			'EVT_ID'  => 'Event',
543
+		);
544
+	}
545
+
546
+
547
+	/**
548
+	 * This returns whether EEM_Message is in debug mode or not.
549
+	 * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when
550
+	 * generating/sending messages. Debug mode can be set by either:
551
+	 * 1. Sending in a value for the $set_debug argument
552
+	 * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php
553
+	 * 3. Overriding the above via the provided filter.
554
+	 *
555
+	 * @param bool|null $set_debug      If provided, then the debug mode will be set internally until reset via the
556
+	 *                                  provided boolean. When no argument is provided (default null) then the debug
557
+	 *                                  mode will be returned.
558
+	 * @return bool         true means Messages is in debug mode.  false means messages system is not in debug mode.
559
+	 */
560
+	public static function debug($set_debug = null)
561
+	{
562
+		static $is_debugging = null;
563
+
564
+		// initialize (use constant if set).
565
+		if (is_null($set_debug) && is_null($is_debugging)) {
566
+			$is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
567
+		}
568
+
569
+		if (! is_null($set_debug)) {
570
+			$is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
571
+		}
572
+
573
+		// return filtered value
574
+		return apply_filters('FHEE__EEM_Message__debug', $is_debugging);
575
+	}
576
+
577
+
578
+	/**
579
+	 * Deletes old messages meeting certain criteria for removal from the database.
580
+	 * By default, this will delete messages that:
581
+	 * - are older than the value of the delete_threshold in months.
582
+	 * - have a STS_ID other than EEM_Message::status_idle
583
+	 *
584
+	 * @param int $delete_threshold This integer will be used to set the boundary for what messages are deleted in
585
+	 *                              months.
586
+	 * @return bool|false|int Either the number of records affected or false if there was an error (you can call
587
+	 *                              $wpdb->last_error to find out what the error was.
588
+	 * @throws EE_Error
589
+	 * @throws EE_Error
590
+	 * @throws EE_Error
591
+	 */
592
+	public function delete_old_messages($delete_threshold = 6)
593
+	{
594
+		$number_deleted = 0;
595
+		/**
596
+		 * Allows code to change the boundary for what messages are kept.
597
+		 * Uses the value of the `delete_threshold` variable by default.
598
+		 *
599
+		 * @param int $seconds seconds that will be subtracted from the timestamp for now.
600
+		 * @return int
601
+		 */
602
+		$time_to_leave_alone = absint(
603
+			apply_filters(
604
+				'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone',
605
+				((int) $delete_threshold) * MONTH_IN_SECONDS
606
+			)
607
+		);
608
+
609
+
610
+		/**
611
+		 * Allows code to change what message stati are ignored when deleting.
612
+		 * Defaults to only ignore EEM_Message::status_idle messages.
613
+		 *
614
+		 * @param string $message_stati_to_keep  An array of message statuses that will be ignored when deleting.
615
+		 */
616
+		$message_stati_to_keep = (array) apply_filters(
617
+			'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep',
618
+			array(
619
+				EEM_Message::status_idle
620
+			)
621
+		);
622
+
623
+		// first get all the ids of messages being deleted
624
+		$message_ids_to_delete = EEM_Message::instance()->get_col(
625
+			array(
626
+				0 => array(
627
+					'STS_ID' => array('NOT_IN', $message_stati_to_keep),
628
+					'MSG_modified' => array('<', time() - $time_to_leave_alone)
629
+				),
630
+				'limit' => apply_filters(
631
+					'EEM_Message__delete_old_messages__limit',
632
+					2000,
633
+					$delete_threshold
634
+				)
635
+			)
636
+		);
637
+
638
+		if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
639
+			global $wpdb;
640
+			$number_deleted = $wpdb->query('
641 641
                 DELETE
642 642
                 FROM ' . $this->table() . '
643 643
                 WHERE
644 644
                     MSG_ID IN (' . implode(",", $message_ids_to_delete) . ')
645 645
             ');
646
-        }
647
-
648
-        /**
649
-         * This will get called if the number of records deleted 0 or greater.  So a successful deletion is one where
650
-         * there were no errors.  An unsuccessful deletion is where there were errors.  Keep that in mind for the actions
651
-         * below.
652
-         */
653
-        if ($number_deleted !== false) {
654
-            do_action('AHEE__EEM_Message__delete_old_messages__after_successful_deletion', $message_ids_to_delete, $number_deleted);
655
-        } else {
656
-            do_action('AHEE__EEM_Message__delete_old_messages__after_deletion_fail', $message_ids_to_delete, $number_deleted);
657
-        }
658
-        return $number_deleted;
659
-    }
646
+		}
647
+
648
+		/**
649
+		 * This will get called if the number of records deleted 0 or greater.  So a successful deletion is one where
650
+		 * there were no errors.  An unsuccessful deletion is where there were errors.  Keep that in mind for the actions
651
+		 * below.
652
+		 */
653
+		if ($number_deleted !== false) {
654
+			do_action('AHEE__EEM_Message__delete_old_messages__after_successful_deletion', $message_ids_to_delete, $number_deleted);
655
+		} else {
656
+			do_action('AHEE__EEM_Message__delete_old_messages__after_deletion_fail', $message_ids_to_delete, $number_deleted);
657
+		}
658
+		return $number_deleted;
659
+	}
660 660
 }
Please login to merge, or discard this patch.