@@ -14,126 +14,126 @@ |
||
14 | 14 | { |
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * @see parent::get_priority() for documentation. |
|
19 | - * @return int |
|
20 | - */ |
|
21 | - public function get_priority() |
|
22 | - { |
|
23 | - return EEM_Message::priority_medium; |
|
24 | - } |
|
25 | - |
|
26 | - |
|
27 | - |
|
28 | - protected function _set_admin_pages() |
|
29 | - { |
|
30 | - $this->admin_registered_pages = array( |
|
31 | - 'events_edit' => true |
|
32 | - ); |
|
33 | - } |
|
34 | - |
|
35 | - |
|
36 | - protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger) |
|
37 | - { |
|
38 | - // this is just a test |
|
39 | - return $this->name . ' Message Type for ' . $messenger->name . ' Messenger '; |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - protected function _set_data_handler() |
|
46 | - { |
|
47 | - if (is_array($this->_data)) { |
|
48 | - $data_type = reset($this->_data); |
|
49 | - |
|
50 | - if (is_array($data_type)) { |
|
51 | - // grab the first item and see if its a registration. |
|
52 | - $maybe_reg = isset($data_type[0]) && is_array($data_type[0]) ? reset($data_type[0]) : reset($data_type); |
|
53 | - if ($maybe_reg instanceof EE_Registration) { |
|
54 | - // is $data_type itself just an array of registrations? |
|
55 | - if (isset($data_type[1]) && $data_type[1] instanceof EE_Registration) { |
|
56 | - $regs = $data_type; |
|
57 | - } else { |
|
58 | - $regs = is_array($data_type[0]) ? $data_type[0] : array( $maybe_reg ); |
|
59 | - } |
|
60 | - |
|
61 | - foreach ($regs as $reg) { |
|
62 | - if ($reg instanceof EE_Registration) { |
|
63 | - $this->_regs_for_sending[] = $reg->ID(); |
|
64 | - } |
|
65 | - } |
|
66 | - $this->_data = isset($this->_data[1]) ? array( $maybe_reg->transaction(), null, $this->_data[1] ) : array( $maybe_reg->transaction() ); |
|
67 | - $this->_data_handler = 'Gateways'; |
|
68 | - } else { |
|
69 | - $this->_data_handler = 'Gateways'; |
|
70 | - } |
|
71 | - } else { |
|
72 | - $this->_data_handler = $data_type instanceof EE_Registration ? 'REG' : 'Gateways'; |
|
73 | - } |
|
74 | - } else { |
|
75 | - $this->_data_handler = $this->_data instanceof EE_Registration ? 'REG' : 'Gateways'; |
|
76 | - } |
|
77 | - |
|
78 | - $this->_single_message = $this->_data_handler == 'REG' ? true : false; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - |
|
83 | - protected function _get_data_for_context($context, EE_Registration $registration, $id) |
|
84 | - { |
|
85 | - if ($context == 'admin') { |
|
86 | - // use the registration to get the transaction. |
|
87 | - $transaction = $registration->transaction(); |
|
88 | - |
|
89 | - // bail early if no transaction |
|
90 | - if (! $transaction instanceof EE_Transaction) { |
|
91 | - throw new EE_Error(esc_html__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso')); |
|
92 | - } |
|
93 | - |
|
94 | - $payment = !empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0; |
|
95 | - return array( $transaction, $payment ); |
|
96 | - } else { |
|
97 | - return $registration; |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Setup admin settings for this message type. |
|
105 | - */ |
|
106 | - protected function _set_admin_settings_fields() |
|
107 | - { |
|
108 | - $this->_admin_settings_fields = array(); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * returns an array of addressee objects for event_admins |
|
117 | - * |
|
118 | - * @access protected |
|
119 | - * @return array array of EE_Messages_Addressee objects |
|
120 | - */ |
|
121 | - protected function _admin_addressees() |
|
122 | - { |
|
123 | - if ($this->_single_message) { |
|
124 | - return array(); |
|
125 | - } |
|
126 | - return parent::_admin_addressees(); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - |
|
131 | - protected function _primary_attendee_addressees() |
|
132 | - { |
|
133 | - if ($this->_single_message) { |
|
134 | - return array(); |
|
135 | - } |
|
136 | - |
|
137 | - return parent::_primary_attendee_addressees(); |
|
138 | - } |
|
17 | + /** |
|
18 | + * @see parent::get_priority() for documentation. |
|
19 | + * @return int |
|
20 | + */ |
|
21 | + public function get_priority() |
|
22 | + { |
|
23 | + return EEM_Message::priority_medium; |
|
24 | + } |
|
25 | + |
|
26 | + |
|
27 | + |
|
28 | + protected function _set_admin_pages() |
|
29 | + { |
|
30 | + $this->admin_registered_pages = array( |
|
31 | + 'events_edit' => true |
|
32 | + ); |
|
33 | + } |
|
34 | + |
|
35 | + |
|
36 | + protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger) |
|
37 | + { |
|
38 | + // this is just a test |
|
39 | + return $this->name . ' Message Type for ' . $messenger->name . ' Messenger '; |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + protected function _set_data_handler() |
|
46 | + { |
|
47 | + if (is_array($this->_data)) { |
|
48 | + $data_type = reset($this->_data); |
|
49 | + |
|
50 | + if (is_array($data_type)) { |
|
51 | + // grab the first item and see if its a registration. |
|
52 | + $maybe_reg = isset($data_type[0]) && is_array($data_type[0]) ? reset($data_type[0]) : reset($data_type); |
|
53 | + if ($maybe_reg instanceof EE_Registration) { |
|
54 | + // is $data_type itself just an array of registrations? |
|
55 | + if (isset($data_type[1]) && $data_type[1] instanceof EE_Registration) { |
|
56 | + $regs = $data_type; |
|
57 | + } else { |
|
58 | + $regs = is_array($data_type[0]) ? $data_type[0] : array( $maybe_reg ); |
|
59 | + } |
|
60 | + |
|
61 | + foreach ($regs as $reg) { |
|
62 | + if ($reg instanceof EE_Registration) { |
|
63 | + $this->_regs_for_sending[] = $reg->ID(); |
|
64 | + } |
|
65 | + } |
|
66 | + $this->_data = isset($this->_data[1]) ? array( $maybe_reg->transaction(), null, $this->_data[1] ) : array( $maybe_reg->transaction() ); |
|
67 | + $this->_data_handler = 'Gateways'; |
|
68 | + } else { |
|
69 | + $this->_data_handler = 'Gateways'; |
|
70 | + } |
|
71 | + } else { |
|
72 | + $this->_data_handler = $data_type instanceof EE_Registration ? 'REG' : 'Gateways'; |
|
73 | + } |
|
74 | + } else { |
|
75 | + $this->_data_handler = $this->_data instanceof EE_Registration ? 'REG' : 'Gateways'; |
|
76 | + } |
|
77 | + |
|
78 | + $this->_single_message = $this->_data_handler == 'REG' ? true : false; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + |
|
83 | + protected function _get_data_for_context($context, EE_Registration $registration, $id) |
|
84 | + { |
|
85 | + if ($context == 'admin') { |
|
86 | + // use the registration to get the transaction. |
|
87 | + $transaction = $registration->transaction(); |
|
88 | + |
|
89 | + // bail early if no transaction |
|
90 | + if (! $transaction instanceof EE_Transaction) { |
|
91 | + throw new EE_Error(esc_html__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso')); |
|
92 | + } |
|
93 | + |
|
94 | + $payment = !empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0; |
|
95 | + return array( $transaction, $payment ); |
|
96 | + } else { |
|
97 | + return $registration; |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Setup admin settings for this message type. |
|
105 | + */ |
|
106 | + protected function _set_admin_settings_fields() |
|
107 | + { |
|
108 | + $this->_admin_settings_fields = array(); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * returns an array of addressee objects for event_admins |
|
117 | + * |
|
118 | + * @access protected |
|
119 | + * @return array array of EE_Messages_Addressee objects |
|
120 | + */ |
|
121 | + protected function _admin_addressees() |
|
122 | + { |
|
123 | + if ($this->_single_message) { |
|
124 | + return array(); |
|
125 | + } |
|
126 | + return parent::_admin_addressees(); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + |
|
131 | + protected function _primary_attendee_addressees() |
|
132 | + { |
|
133 | + if ($this->_single_message) { |
|
134 | + return array(); |
|
135 | + } |
|
136 | + |
|
137 | + return parent::_primary_attendee_addressees(); |
|
138 | + } |
|
139 | 139 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger) |
37 | 37 | { |
38 | 38 | // this is just a test |
39 | - return $this->name . ' Message Type for ' . $messenger->name . ' Messenger '; |
|
39 | + return $this->name.' Message Type for '.$messenger->name.' Messenger '; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | if (isset($data_type[1]) && $data_type[1] instanceof EE_Registration) { |
56 | 56 | $regs = $data_type; |
57 | 57 | } else { |
58 | - $regs = is_array($data_type[0]) ? $data_type[0] : array( $maybe_reg ); |
|
58 | + $regs = is_array($data_type[0]) ? $data_type[0] : array($maybe_reg); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | foreach ($regs as $reg) { |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | $this->_regs_for_sending[] = $reg->ID(); |
64 | 64 | } |
65 | 65 | } |
66 | - $this->_data = isset($this->_data[1]) ? array( $maybe_reg->transaction(), null, $this->_data[1] ) : array( $maybe_reg->transaction() ); |
|
66 | + $this->_data = isset($this->_data[1]) ? array($maybe_reg->transaction(), null, $this->_data[1]) : array($maybe_reg->transaction()); |
|
67 | 67 | $this->_data_handler = 'Gateways'; |
68 | 68 | } else { |
69 | 69 | $this->_data_handler = 'Gateways'; |
@@ -82,17 +82,17 @@ discard block |
||
82 | 82 | |
83 | 83 | protected function _get_data_for_context($context, EE_Registration $registration, $id) |
84 | 84 | { |
85 | - if ($context == 'admin') { |
|
85 | + if ($context == 'admin') { |
|
86 | 86 | // use the registration to get the transaction. |
87 | 87 | $transaction = $registration->transaction(); |
88 | 88 | |
89 | 89 | // bail early if no transaction |
90 | - if (! $transaction instanceof EE_Transaction) { |
|
90 | + if ( ! $transaction instanceof EE_Transaction) { |
|
91 | 91 | throw new EE_Error(esc_html__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso')); |
92 | 92 | } |
93 | 93 | |
94 | - $payment = !empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0; |
|
95 | - return array( $transaction, $payment ); |
|
94 | + $payment = ! empty($id) ? EEM_Payment::instance()->get_one(array(array('PAY_ID' => $id, 'TXN_ID' => $transaction->ID()))) : 0; |
|
95 | + return array($transaction, $payment); |
|
96 | 96 | } else { |
97 | 97 | return $registration; |
98 | 98 | } |
@@ -19,106 +19,106 @@ |
||
19 | 19 | class AttendeesReport extends JobHandlerFile |
20 | 20 | { |
21 | 21 | |
22 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
23 | - public function create_job(JobParameters $job_parameters) |
|
24 | - { |
|
25 | - if (! \EE_Capabilities::instance()->current_user_can('ee_read_contacts', 'generating_report')) { |
|
26 | - throw new BatchRequestException( |
|
27 | - esc_html__('You do not have permission to view contacts', 'event_espresso') |
|
28 | - ); |
|
29 | - } |
|
30 | - $filepath = $this->create_file_from_job_with_name( |
|
31 | - $job_parameters->job_id(), |
|
32 | - esc_html__('contact-list-report.csv', 'event_espresso') |
|
33 | - ); |
|
34 | - $job_parameters->add_extra_data('filepath', $filepath); |
|
35 | - $job_parameters->set_job_size($this->count_units_to_process()); |
|
36 | - // we should also set the header columns |
|
37 | - $csv_data_for_row = $this->get_csv_data(0, 1); |
|
38 | - \EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
39 | - // if we actually processed a row there, record it |
|
40 | - if ($job_parameters->job_size()) { |
|
41 | - $job_parameters->mark_processed(1); |
|
42 | - } |
|
43 | - return new JobStepResponse( |
|
44 | - $job_parameters, |
|
45 | - esc_html__('Contacts report started successfully...', 'event_espresso') |
|
46 | - ); |
|
47 | - } |
|
22 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
23 | + public function create_job(JobParameters $job_parameters) |
|
24 | + { |
|
25 | + if (! \EE_Capabilities::instance()->current_user_can('ee_read_contacts', 'generating_report')) { |
|
26 | + throw new BatchRequestException( |
|
27 | + esc_html__('You do not have permission to view contacts', 'event_espresso') |
|
28 | + ); |
|
29 | + } |
|
30 | + $filepath = $this->create_file_from_job_with_name( |
|
31 | + $job_parameters->job_id(), |
|
32 | + esc_html__('contact-list-report.csv', 'event_espresso') |
|
33 | + ); |
|
34 | + $job_parameters->add_extra_data('filepath', $filepath); |
|
35 | + $job_parameters->set_job_size($this->count_units_to_process()); |
|
36 | + // we should also set the header columns |
|
37 | + $csv_data_for_row = $this->get_csv_data(0, 1); |
|
38 | + \EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
39 | + // if we actually processed a row there, record it |
|
40 | + if ($job_parameters->job_size()) { |
|
41 | + $job_parameters->mark_processed(1); |
|
42 | + } |
|
43 | + return new JobStepResponse( |
|
44 | + $job_parameters, |
|
45 | + esc_html__('Contacts report started successfully...', 'event_espresso') |
|
46 | + ); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
51 | - { |
|
52 | - $csv_data = $this->get_csv_data($job_parameters->units_processed(), $batch_size); |
|
53 | - \EEH_Export::write_data_array_to_csv( |
|
54 | - $job_parameters->extra_datum('filepath'), |
|
55 | - $csv_data, |
|
56 | - false |
|
57 | - ); |
|
58 | - $units_processed = count($csv_data); |
|
59 | - $job_parameters->mark_processed($units_processed); |
|
60 | - $extra_response_data = array( |
|
61 | - 'file_url' => '', |
|
62 | - ); |
|
63 | - if ($units_processed < $batch_size) { |
|
64 | - $job_parameters->set_status(JobParameters::status_complete); |
|
65 | - $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
66 | - } |
|
67 | - return new JobStepResponse( |
|
68 | - $job_parameters, |
|
69 | - sprintf( |
|
70 | - esc_html__('Wrote %1$s rows to report CSV file...', 'event_espresso'), |
|
71 | - count($csv_data) |
|
72 | - ), |
|
73 | - $extra_response_data |
|
74 | - ); |
|
75 | - } |
|
50 | + public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
51 | + { |
|
52 | + $csv_data = $this->get_csv_data($job_parameters->units_processed(), $batch_size); |
|
53 | + \EEH_Export::write_data_array_to_csv( |
|
54 | + $job_parameters->extra_datum('filepath'), |
|
55 | + $csv_data, |
|
56 | + false |
|
57 | + ); |
|
58 | + $units_processed = count($csv_data); |
|
59 | + $job_parameters->mark_processed($units_processed); |
|
60 | + $extra_response_data = array( |
|
61 | + 'file_url' => '', |
|
62 | + ); |
|
63 | + if ($units_processed < $batch_size) { |
|
64 | + $job_parameters->set_status(JobParameters::status_complete); |
|
65 | + $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
66 | + } |
|
67 | + return new JobStepResponse( |
|
68 | + $job_parameters, |
|
69 | + sprintf( |
|
70 | + esc_html__('Wrote %1$s rows to report CSV file...', 'event_espresso'), |
|
71 | + count($csv_data) |
|
72 | + ), |
|
73 | + $extra_response_data |
|
74 | + ); |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | - public function cleanup_job(JobParameters $job_parameters) |
|
79 | - { |
|
80 | - $this->_file_helper->delete( |
|
81 | - \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
82 | - true, |
|
83 | - 'd' |
|
84 | - ); |
|
85 | - return new JobStepResponse($job_parameters, esc_html__('Cleaned up temporary file', 'event_espresso')); |
|
86 | - } |
|
78 | + public function cleanup_job(JobParameters $job_parameters) |
|
79 | + { |
|
80 | + $this->_file_helper->delete( |
|
81 | + \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
82 | + true, |
|
83 | + 'd' |
|
84 | + ); |
|
85 | + return new JobStepResponse($job_parameters, esc_html__('Cleaned up temporary file', 'event_espresso')); |
|
86 | + } |
|
87 | 87 | |
88 | - public function count_units_to_process() |
|
89 | - { |
|
90 | - return \EEM_Attendee::instance()->count(array('caps' => \EEM_Base::caps_read_admin)); |
|
91 | - } |
|
88 | + public function count_units_to_process() |
|
89 | + { |
|
90 | + return \EEM_Attendee::instance()->count(array('caps' => \EEM_Base::caps_read_admin)); |
|
91 | + } |
|
92 | 92 | |
93 | - public function get_csv_data($offset, $limit) |
|
94 | - { |
|
95 | - $attendee_rows = \EEM_Attendee::instance()->get_all_wpdb_results( |
|
96 | - array( |
|
97 | - 'limit' => array($offset, $limit), |
|
98 | - 'force_join' => array('State', 'Country'), |
|
99 | - 'caps' => \EEM_Base::caps_read_admin, |
|
100 | - ) |
|
101 | - ); |
|
102 | - $csv_data = array(); |
|
103 | - foreach ($attendee_rows as $attendee_row) { |
|
104 | - $csv_row = array(); |
|
105 | - foreach (\EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) { |
|
106 | - if ($field_name == 'STA_ID') { |
|
107 | - $state_name_field = \EEM_State::instance()->field_settings_for('STA_name'); |
|
108 | - $csv_row[ esc_html__('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column() ]; |
|
109 | - } elseif ($field_name == 'CNT_ISO') { |
|
110 | - $country_name_field = \EEM_Country::instance()->field_settings_for('CNT_name'); |
|
111 | - $csv_row[ esc_html__('Country', 'event_espresso') ] = $attendee_row[ $country_name_field->get_qualified_column() ]; |
|
112 | - } else { |
|
113 | - $csv_row[ wp_specialchars_decode($field_obj->get_nicename(), ENT_QUOTES) ] = $attendee_row[ $field_obj->get_qualified_column() ]; |
|
114 | - } |
|
115 | - } |
|
116 | - $csv_data[] = apply_filters( |
|
117 | - 'FHEE___EventEspresso_core_libraries_batch_JobHandlers_AttendeesReport__get_csv_data__row', |
|
118 | - $csv_row, |
|
119 | - $attendee_row |
|
120 | - ); |
|
121 | - } |
|
122 | - return $csv_data; |
|
123 | - } |
|
93 | + public function get_csv_data($offset, $limit) |
|
94 | + { |
|
95 | + $attendee_rows = \EEM_Attendee::instance()->get_all_wpdb_results( |
|
96 | + array( |
|
97 | + 'limit' => array($offset, $limit), |
|
98 | + 'force_join' => array('State', 'Country'), |
|
99 | + 'caps' => \EEM_Base::caps_read_admin, |
|
100 | + ) |
|
101 | + ); |
|
102 | + $csv_data = array(); |
|
103 | + foreach ($attendee_rows as $attendee_row) { |
|
104 | + $csv_row = array(); |
|
105 | + foreach (\EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) { |
|
106 | + if ($field_name == 'STA_ID') { |
|
107 | + $state_name_field = \EEM_State::instance()->field_settings_for('STA_name'); |
|
108 | + $csv_row[ esc_html__('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column() ]; |
|
109 | + } elseif ($field_name == 'CNT_ISO') { |
|
110 | + $country_name_field = \EEM_Country::instance()->field_settings_for('CNT_name'); |
|
111 | + $csv_row[ esc_html__('Country', 'event_espresso') ] = $attendee_row[ $country_name_field->get_qualified_column() ]; |
|
112 | + } else { |
|
113 | + $csv_row[ wp_specialchars_decode($field_obj->get_nicename(), ENT_QUOTES) ] = $attendee_row[ $field_obj->get_qualified_column() ]; |
|
114 | + } |
|
115 | + } |
|
116 | + $csv_data[] = apply_filters( |
|
117 | + 'FHEE___EventEspresso_core_libraries_batch_JobHandlers_AttendeesReport__get_csv_data__row', |
|
118 | + $csv_row, |
|
119 | + $attendee_row |
|
120 | + ); |
|
121 | + } |
|
122 | + return $csv_data; |
|
123 | + } |
|
124 | 124 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
23 | 23 | public function create_job(JobParameters $job_parameters) |
24 | 24 | { |
25 | - if (! \EE_Capabilities::instance()->current_user_can('ee_read_contacts', 'generating_report')) { |
|
25 | + if ( ! \EE_Capabilities::instance()->current_user_can('ee_read_contacts', 'generating_report')) { |
|
26 | 26 | throw new BatchRequestException( |
27 | 27 | esc_html__('You do not have permission to view contacts', 'event_espresso') |
28 | 28 | ); |
@@ -105,12 +105,12 @@ discard block |
||
105 | 105 | foreach (\EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) { |
106 | 106 | if ($field_name == 'STA_ID') { |
107 | 107 | $state_name_field = \EEM_State::instance()->field_settings_for('STA_name'); |
108 | - $csv_row[ esc_html__('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column() ]; |
|
108 | + $csv_row[esc_html__('State', 'event_espresso')] = $attendee_row[$state_name_field->get_qualified_column()]; |
|
109 | 109 | } elseif ($field_name == 'CNT_ISO') { |
110 | 110 | $country_name_field = \EEM_Country::instance()->field_settings_for('CNT_name'); |
111 | - $csv_row[ esc_html__('Country', 'event_espresso') ] = $attendee_row[ $country_name_field->get_qualified_column() ]; |
|
111 | + $csv_row[esc_html__('Country', 'event_espresso')] = $attendee_row[$country_name_field->get_qualified_column()]; |
|
112 | 112 | } else { |
113 | - $csv_row[ wp_specialchars_decode($field_obj->get_nicename(), ENT_QUOTES) ] = $attendee_row[ $field_obj->get_qualified_column() ]; |
|
113 | + $csv_row[wp_specialchars_decode($field_obj->get_nicename(), ENT_QUOTES)] = $attendee_row[$field_obj->get_qualified_column()]; |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | $csv_data[] = apply_filters( |
@@ -31,541 +31,541 @@ |
||
31 | 31 | */ |
32 | 32 | class RegistrationsReport extends JobHandlerFile |
33 | 33 | { |
34 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
35 | - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
36 | - /** |
|
37 | - * Performs any necessary setup for starting the job. This is also a good |
|
38 | - * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
39 | - * when continue_job will be called |
|
40 | - * |
|
41 | - * @param JobParameters $job_parameters |
|
42 | - * @throws BatchRequestException |
|
43 | - * @return JobStepResponse |
|
44 | - */ |
|
45 | - public function create_job(JobParameters $job_parameters) |
|
46 | - { |
|
47 | - $event_id = intval($job_parameters->request_datum('EVT_ID', '0')); |
|
48 | - if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
49 | - throw new BatchRequestException(esc_html__('You do not have permission to view registrations', 'event_espresso')); |
|
50 | - } |
|
51 | - $filepath = $this->create_file_from_job_with_name( |
|
52 | - $job_parameters->job_id(), |
|
53 | - $this->get_filename($event_id) |
|
54 | - ); |
|
55 | - $job_parameters->add_extra_data('filepath', $filepath); |
|
56 | - if ($job_parameters->request_datum('use_filters', false)) { |
|
57 | - $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array()))); |
|
58 | - } else { |
|
59 | - $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array( |
|
60 | - array( |
|
61 | - 'OR' => array( |
|
62 | - // don't include registrations from failed or abandoned transactions... |
|
63 | - 'Transaction.STS_ID' => array( |
|
64 | - 'NOT IN', |
|
65 | - array( |
|
66 | - EEM_Transaction::failed_status_code, |
|
67 | - EEM_Transaction::abandoned_status_code, |
|
68 | - ), |
|
69 | - ), |
|
70 | - // unless the registration is approved, in which case include it regardless of transaction status |
|
71 | - 'STS_ID' => \EEM_Registration::status_id_approved, |
|
72 | - ), |
|
73 | - 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
74 | - ), |
|
75 | - 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
76 | - 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
77 | - 'caps' => \EEM_Base::caps_read_admin, |
|
78 | - ), $event_id); |
|
79 | - if ($event_id) { |
|
80 | - $query_params[0]['EVT_ID'] = $event_id; |
|
81 | - } else { |
|
82 | - $query_params['force_join'][] = 'Event'; |
|
83 | - } |
|
84 | - } |
|
85 | - if (! isset($query_params['force_join'])) { |
|
86 | - $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
|
87 | - } |
|
88 | - $job_parameters->add_extra_data('query_params', $query_params); |
|
89 | - $question_labels = $this->_get_question_labels($query_params); |
|
90 | - $job_parameters->add_extra_data('question_labels', $question_labels); |
|
91 | - $job_parameters->set_job_size( |
|
92 | - \EEM_Registration::instance()->count( |
|
93 | - array_diff_key( |
|
94 | - $query_params, |
|
95 | - array_flip( |
|
96 | - array('limit') |
|
97 | - ) |
|
98 | - ) |
|
99 | - ) |
|
100 | - ); |
|
101 | - // we should also set the header columns |
|
102 | - $csv_data_for_row = $this->get_csv_data_for( |
|
103 | - $event_id, |
|
104 | - 0, |
|
105 | - 1, |
|
106 | - $job_parameters->extra_datum('question_labels'), |
|
107 | - $job_parameters->extra_datum('query_params') |
|
108 | - ); |
|
109 | - EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
110 | - // if we actually processed a row there, record it |
|
111 | - if ($job_parameters->job_size()) { |
|
112 | - $job_parameters->mark_processed(1); |
|
113 | - } |
|
114 | - return new JobStepResponse( |
|
115 | - $job_parameters, |
|
116 | - esc_html__('Registrations report started successfully...', 'event_espresso') |
|
117 | - ); |
|
118 | - } |
|
34 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
35 | + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
36 | + /** |
|
37 | + * Performs any necessary setup for starting the job. This is also a good |
|
38 | + * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
39 | + * when continue_job will be called |
|
40 | + * |
|
41 | + * @param JobParameters $job_parameters |
|
42 | + * @throws BatchRequestException |
|
43 | + * @return JobStepResponse |
|
44 | + */ |
|
45 | + public function create_job(JobParameters $job_parameters) |
|
46 | + { |
|
47 | + $event_id = intval($job_parameters->request_datum('EVT_ID', '0')); |
|
48 | + if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
49 | + throw new BatchRequestException(esc_html__('You do not have permission to view registrations', 'event_espresso')); |
|
50 | + } |
|
51 | + $filepath = $this->create_file_from_job_with_name( |
|
52 | + $job_parameters->job_id(), |
|
53 | + $this->get_filename($event_id) |
|
54 | + ); |
|
55 | + $job_parameters->add_extra_data('filepath', $filepath); |
|
56 | + if ($job_parameters->request_datum('use_filters', false)) { |
|
57 | + $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array()))); |
|
58 | + } else { |
|
59 | + $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array( |
|
60 | + array( |
|
61 | + 'OR' => array( |
|
62 | + // don't include registrations from failed or abandoned transactions... |
|
63 | + 'Transaction.STS_ID' => array( |
|
64 | + 'NOT IN', |
|
65 | + array( |
|
66 | + EEM_Transaction::failed_status_code, |
|
67 | + EEM_Transaction::abandoned_status_code, |
|
68 | + ), |
|
69 | + ), |
|
70 | + // unless the registration is approved, in which case include it regardless of transaction status |
|
71 | + 'STS_ID' => \EEM_Registration::status_id_approved, |
|
72 | + ), |
|
73 | + 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
74 | + ), |
|
75 | + 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
76 | + 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
77 | + 'caps' => \EEM_Base::caps_read_admin, |
|
78 | + ), $event_id); |
|
79 | + if ($event_id) { |
|
80 | + $query_params[0]['EVT_ID'] = $event_id; |
|
81 | + } else { |
|
82 | + $query_params['force_join'][] = 'Event'; |
|
83 | + } |
|
84 | + } |
|
85 | + if (! isset($query_params['force_join'])) { |
|
86 | + $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
|
87 | + } |
|
88 | + $job_parameters->add_extra_data('query_params', $query_params); |
|
89 | + $question_labels = $this->_get_question_labels($query_params); |
|
90 | + $job_parameters->add_extra_data('question_labels', $question_labels); |
|
91 | + $job_parameters->set_job_size( |
|
92 | + \EEM_Registration::instance()->count( |
|
93 | + array_diff_key( |
|
94 | + $query_params, |
|
95 | + array_flip( |
|
96 | + array('limit') |
|
97 | + ) |
|
98 | + ) |
|
99 | + ) |
|
100 | + ); |
|
101 | + // we should also set the header columns |
|
102 | + $csv_data_for_row = $this->get_csv_data_for( |
|
103 | + $event_id, |
|
104 | + 0, |
|
105 | + 1, |
|
106 | + $job_parameters->extra_datum('question_labels'), |
|
107 | + $job_parameters->extra_datum('query_params') |
|
108 | + ); |
|
109 | + EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
110 | + // if we actually processed a row there, record it |
|
111 | + if ($job_parameters->job_size()) { |
|
112 | + $job_parameters->mark_processed(1); |
|
113 | + } |
|
114 | + return new JobStepResponse( |
|
115 | + $job_parameters, |
|
116 | + esc_html__('Registrations report started successfully...', 'event_espresso') |
|
117 | + ); |
|
118 | + } |
|
119 | 119 | |
120 | 120 | |
121 | - /** |
|
122 | - * Gets the filename |
|
123 | - * |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - protected function get_filename() |
|
127 | - { |
|
128 | - return apply_filters( |
|
129 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__get_filename', |
|
130 | - sprintf( |
|
131 | - "event-espresso-registrations-%s.csv", |
|
132 | - str_replace(array(':', ' '), '-', current_time('mysql')) |
|
133 | - ) |
|
134 | - ); |
|
135 | - } |
|
121 | + /** |
|
122 | + * Gets the filename |
|
123 | + * |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + protected function get_filename() |
|
127 | + { |
|
128 | + return apply_filters( |
|
129 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__get_filename', |
|
130 | + sprintf( |
|
131 | + "event-espresso-registrations-%s.csv", |
|
132 | + str_replace(array(':', ' '), '-', current_time('mysql')) |
|
133 | + ) |
|
134 | + ); |
|
135 | + } |
|
136 | 136 | |
137 | 137 | |
138 | - /** |
|
139 | - * Gets the questions which are to be used for this report, so they |
|
140 | - * can be remembered for later |
|
141 | - * |
|
142 | - * @param array $registration_query_params |
|
143 | - * @return array question admin labels to be used for this report |
|
144 | - */ |
|
145 | - protected function _get_question_labels($registration_query_params) |
|
146 | - { |
|
147 | - $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null; |
|
148 | - $question_query_params = array(); |
|
149 | - if ($where !== null) { |
|
150 | - $question_query_params = array( |
|
151 | - $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
152 | - ); |
|
153 | - } |
|
154 | - // Make sure it's not a system question |
|
155 | - $question_query_params[0]['OR*not-system-questions'] = [ |
|
156 | - 'QST_system' => '', |
|
157 | - 'QST_system*null' => ['IS_NULL'] |
|
158 | - ]; |
|
159 | - if ( |
|
160 | - apply_filters( |
|
161 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', |
|
162 | - false, |
|
163 | - $registration_query_params |
|
164 | - ) |
|
165 | - ) { |
|
166 | - $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL'); |
|
167 | - } |
|
168 | - $question_query_params['group_by'] = array('QST_ID'); |
|
169 | - return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label')); |
|
170 | - } |
|
138 | + /** |
|
139 | + * Gets the questions which are to be used for this report, so they |
|
140 | + * can be remembered for later |
|
141 | + * |
|
142 | + * @param array $registration_query_params |
|
143 | + * @return array question admin labels to be used for this report |
|
144 | + */ |
|
145 | + protected function _get_question_labels($registration_query_params) |
|
146 | + { |
|
147 | + $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null; |
|
148 | + $question_query_params = array(); |
|
149 | + if ($where !== null) { |
|
150 | + $question_query_params = array( |
|
151 | + $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
152 | + ); |
|
153 | + } |
|
154 | + // Make sure it's not a system question |
|
155 | + $question_query_params[0]['OR*not-system-questions'] = [ |
|
156 | + 'QST_system' => '', |
|
157 | + 'QST_system*null' => ['IS_NULL'] |
|
158 | + ]; |
|
159 | + if ( |
|
160 | + apply_filters( |
|
161 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', |
|
162 | + false, |
|
163 | + $registration_query_params |
|
164 | + ) |
|
165 | + ) { |
|
166 | + $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL'); |
|
167 | + } |
|
168 | + $question_query_params['group_by'] = array('QST_ID'); |
|
169 | + return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label')); |
|
170 | + } |
|
171 | 171 | |
172 | 172 | |
173 | - /** |
|
174 | - * Takes where params meant for registrations and changes them to work for questions |
|
175 | - * |
|
176 | - * @param array $reg_where_params |
|
177 | - * @return array |
|
178 | - */ |
|
179 | - protected function _change_registration_where_params_to_question_where_params($reg_where_params) |
|
180 | - { |
|
181 | - $question_where_params = array(); |
|
182 | - foreach ($reg_where_params as $key => $val) { |
|
183 | - if (\EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
184 | - $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val); |
|
185 | - } else { |
|
186 | - // it's a normal where condition |
|
187 | - $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
188 | - } |
|
189 | - } |
|
190 | - return $question_where_params; |
|
191 | - } |
|
173 | + /** |
|
174 | + * Takes where params meant for registrations and changes them to work for questions |
|
175 | + * |
|
176 | + * @param array $reg_where_params |
|
177 | + * @return array |
|
178 | + */ |
|
179 | + protected function _change_registration_where_params_to_question_where_params($reg_where_params) |
|
180 | + { |
|
181 | + $question_where_params = array(); |
|
182 | + foreach ($reg_where_params as $key => $val) { |
|
183 | + if (\EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
184 | + $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val); |
|
185 | + } else { |
|
186 | + // it's a normal where condition |
|
187 | + $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
188 | + } |
|
189 | + } |
|
190 | + return $question_where_params; |
|
191 | + } |
|
192 | 192 | |
193 | 193 | |
194 | - /** |
|
195 | - * Performs another step of the job |
|
196 | - * |
|
197 | - * @param JobParameters $job_parameters |
|
198 | - * @param int $batch_size |
|
199 | - * @return JobStepResponse |
|
200 | - * @throws \EE_Error |
|
201 | - */ |
|
202 | - public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
203 | - { |
|
204 | - if ($job_parameters->units_processed() < $job_parameters->job_size()) { |
|
205 | - $csv_data = $this->get_csv_data_for( |
|
206 | - $job_parameters->request_datum('EVT_ID', '0'), |
|
207 | - $job_parameters->units_processed(), |
|
208 | - $batch_size, |
|
209 | - $job_parameters->extra_datum('question_labels'), |
|
210 | - $job_parameters->extra_datum('query_params') |
|
211 | - ); |
|
212 | - EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
|
213 | - $units_processed = count($csv_data); |
|
214 | - } else { |
|
215 | - $csv_data = array(); |
|
216 | - $units_processed = 0; |
|
217 | - } |
|
218 | - $job_parameters->mark_processed($units_processed); |
|
219 | - $extra_response_data = array( |
|
220 | - 'file_url' => '', |
|
221 | - ); |
|
222 | - if ($units_processed < $batch_size) { |
|
223 | - $job_parameters->set_status(JobParameters::status_complete); |
|
224 | - $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
225 | - } |
|
194 | + /** |
|
195 | + * Performs another step of the job |
|
196 | + * |
|
197 | + * @param JobParameters $job_parameters |
|
198 | + * @param int $batch_size |
|
199 | + * @return JobStepResponse |
|
200 | + * @throws \EE_Error |
|
201 | + */ |
|
202 | + public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
203 | + { |
|
204 | + if ($job_parameters->units_processed() < $job_parameters->job_size()) { |
|
205 | + $csv_data = $this->get_csv_data_for( |
|
206 | + $job_parameters->request_datum('EVT_ID', '0'), |
|
207 | + $job_parameters->units_processed(), |
|
208 | + $batch_size, |
|
209 | + $job_parameters->extra_datum('question_labels'), |
|
210 | + $job_parameters->extra_datum('query_params') |
|
211 | + ); |
|
212 | + EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
|
213 | + $units_processed = count($csv_data); |
|
214 | + } else { |
|
215 | + $csv_data = array(); |
|
216 | + $units_processed = 0; |
|
217 | + } |
|
218 | + $job_parameters->mark_processed($units_processed); |
|
219 | + $extra_response_data = array( |
|
220 | + 'file_url' => '', |
|
221 | + ); |
|
222 | + if ($units_processed < $batch_size) { |
|
223 | + $job_parameters->set_status(JobParameters::status_complete); |
|
224 | + $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
225 | + } |
|
226 | 226 | |
227 | - return new JobStepResponse( |
|
228 | - $job_parameters, |
|
229 | - sprintf(esc_html__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)), |
|
230 | - $extra_response_data |
|
231 | - ); |
|
232 | - } |
|
227 | + return new JobStepResponse( |
|
228 | + $job_parameters, |
|
229 | + sprintf(esc_html__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)), |
|
230 | + $extra_response_data |
|
231 | + ); |
|
232 | + } |
|
233 | 233 | |
234 | 234 | |
235 | - /** |
|
236 | - * Gets the csv data for a batch of registrations |
|
237 | - * |
|
238 | - * @param int|null $event_id |
|
239 | - * @param int $offset |
|
240 | - * @param int $limit |
|
241 | - * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
242 | - * @param array $query_params for using where querying the model |
|
243 | - * @return array top-level keys are numeric, next-level keys are column headers |
|
244 | - * @throws \EE_Error |
|
245 | - */ |
|
246 | - public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params) |
|
247 | - { |
|
248 | - $reg_fields_to_include = array( |
|
249 | - 'TXN_ID', |
|
250 | - 'ATT_ID', |
|
251 | - 'REG_ID', |
|
252 | - 'REG_date', |
|
253 | - 'REG_code', |
|
254 | - 'REG_count', |
|
255 | - 'REG_final_price', |
|
256 | - ); |
|
257 | - $att_fields_to_include = array( |
|
258 | - 'ATT_fname', |
|
259 | - 'ATT_lname', |
|
260 | - 'ATT_email', |
|
261 | - 'ATT_address', |
|
262 | - 'ATT_address2', |
|
263 | - 'ATT_city', |
|
264 | - 'STA_ID', |
|
265 | - 'CNT_ISO', |
|
266 | - 'ATT_zip', |
|
267 | - 'ATT_phone', |
|
268 | - ); |
|
269 | - $registrations_csv_ready_array = array(); |
|
270 | - $reg_model = EE_Registry::instance()->load_model('Registration'); |
|
271 | - $query_params['limit'] = array($offset, $limit); |
|
272 | - $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
273 | - $registration_ids = array(); |
|
274 | - foreach ($registration_rows as $reg_row) { |
|
275 | - $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
276 | - } |
|
277 | - foreach ($registration_rows as $reg_row) { |
|
278 | - if (is_array($reg_row)) { |
|
279 | - $reg_csv_array = array(); |
|
280 | - if (! $event_id) { |
|
281 | - // get the event's name and Id |
|
282 | - $reg_csv_array[ (string) esc_html__('Event', 'event_espresso') ] = sprintf( |
|
283 | - /* translators: 1: event name, 2: event ID */ |
|
284 | - esc_html__('%1$s (%2$s)', 'event_espresso'), |
|
285 | - EEH_Export::prepare_value_from_db_for_display( |
|
286 | - EEM_Event::instance(), |
|
287 | - 'EVT_name', |
|
288 | - $reg_row['Event_CPT.post_title'] |
|
289 | - ), |
|
290 | - $reg_row['Event_CPT.ID'] |
|
291 | - ); |
|
292 | - } |
|
293 | - $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
294 | - /*@var $reg_row EE_Registration */ |
|
295 | - foreach ($reg_fields_to_include as $field_name) { |
|
296 | - $field = $reg_model->field_settings_for($field_name); |
|
297 | - if ($field_name == 'REG_final_price') { |
|
298 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
299 | - $reg_model, |
|
300 | - $field_name, |
|
301 | - $reg_row['Registration.REG_final_price'], |
|
302 | - 'localized_float' |
|
303 | - ); |
|
304 | - } elseif ($field_name == 'REG_count') { |
|
305 | - $value = sprintf( |
|
306 | - /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */ |
|
307 | - esc_html__('%1$s of %2$s', 'event_espresso'), |
|
308 | - EEH_Export::prepare_value_from_db_for_display( |
|
309 | - $reg_model, |
|
310 | - 'REG_count', |
|
311 | - $reg_row['Registration.REG_count'] |
|
312 | - ), |
|
313 | - EEH_Export::prepare_value_from_db_for_display( |
|
314 | - $reg_model, |
|
315 | - 'REG_group_size', |
|
316 | - $reg_row['Registration.REG_group_size'] |
|
317 | - ) |
|
318 | - ); |
|
319 | - } elseif ($field_name == 'REG_date') { |
|
320 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
321 | - $reg_model, |
|
322 | - $field_name, |
|
323 | - $reg_row['Registration.REG_date'], |
|
324 | - 'no_html' |
|
325 | - ); |
|
326 | - } else { |
|
327 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
328 | - $reg_model, |
|
329 | - $field_name, |
|
330 | - $reg_row[ $field->get_qualified_column() ] |
|
331 | - ); |
|
332 | - } |
|
333 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value; |
|
334 | - if ($field_name == 'REG_final_price') { |
|
335 | - // add a column named Currency after the final price |
|
336 | - $reg_csv_array[ (string) esc_html__("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code; |
|
337 | - } |
|
338 | - } |
|
339 | - // get pretty status |
|
340 | - $stati = EEM_Status::instance()->localized_status( |
|
341 | - array( |
|
342 | - $reg_row['Registration.STS_ID'] => esc_html__('unknown', 'event_espresso'), |
|
343 | - $reg_row['TransactionTable.STS_ID'] => esc_html__('unknown', 'event_espresso'), |
|
344 | - ), |
|
345 | - false, |
|
346 | - 'sentence' |
|
347 | - ); |
|
348 | - $reg_csv_array[ (string) esc_html__("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
349 | - // get pretty transaction status |
|
350 | - $reg_csv_array[ (string) esc_html__("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
351 | - $reg_csv_array[ (string) esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
352 | - ? EEH_Export::prepare_value_from_db_for_display( |
|
353 | - EEM_Transaction::instance(), |
|
354 | - 'TXN_total', |
|
355 | - $reg_row['TransactionTable.TXN_total'], |
|
356 | - 'localized_float' |
|
357 | - ) : '0.00'; |
|
358 | - $reg_csv_array[ (string) esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
359 | - ? EEH_Export::prepare_value_from_db_for_display( |
|
360 | - EEM_Transaction::instance(), |
|
361 | - 'TXN_paid', |
|
362 | - $reg_row['TransactionTable.TXN_paid'], |
|
363 | - 'localized_float' |
|
364 | - ) : '0.00'; |
|
365 | - $payment_methods = array(); |
|
366 | - $gateway_txn_ids_etc = array(); |
|
367 | - $payment_times = array(); |
|
368 | - if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
369 | - $payments_info = EEM_Payment::instance()->get_all_wpdb_results( |
|
370 | - array( |
|
371 | - array( |
|
372 | - 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
373 | - 'STS_ID' => EEM_Payment::status_id_approved, |
|
374 | - ), |
|
375 | - 'force_join' => array('Payment_Method'), |
|
376 | - ), |
|
377 | - ARRAY_A, |
|
378 | - 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
379 | - ); |
|
380 | - foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
381 | - $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
382 | - ? $payment_method_and_gateway_txn_id['name'] : esc_html__('Unknown', 'event_espresso'); |
|
383 | - $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
384 | - ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
385 | - $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
386 | - ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
387 | - } |
|
388 | - } |
|
389 | - $reg_csv_array[ (string) esc_html__('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
390 | - $reg_csv_array[ (string) esc_html__('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
391 | - $reg_csv_array[ (string) esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
392 | - ',', |
|
393 | - $gateway_txn_ids_etc |
|
394 | - ); |
|
395 | - // get whether or not the user has checked in |
|
396 | - $reg_csv_array[ (string) esc_html__("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
397 | - $reg_row['Registration.REG_ID'], |
|
398 | - 'Checkin' |
|
399 | - ); |
|
400 | - // get ticket of registration and its price |
|
401 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
402 | - if ($reg_row['Ticket.TKT_ID']) { |
|
403 | - $ticket_name = EEH_Export::prepare_value_from_db_for_display( |
|
404 | - $ticket_model, |
|
405 | - 'TKT_name', |
|
406 | - $reg_row['Ticket.TKT_name'] |
|
407 | - ); |
|
408 | - $datetimes_strings = array(); |
|
409 | - foreach ( |
|
410 | - EEM_Datetime::instance()->get_all_wpdb_results( |
|
411 | - array( |
|
412 | - array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
413 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
414 | - 'default_where_conditions' => 'none', |
|
415 | - ) |
|
416 | - ) as $datetime |
|
417 | - ) { |
|
418 | - $datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display( |
|
419 | - EEM_Datetime::instance(), |
|
420 | - 'DTT_EVT_start', |
|
421 | - $datetime['Datetime.DTT_EVT_start'] |
|
422 | - ); |
|
423 | - } |
|
424 | - } else { |
|
425 | - $ticket_name = esc_html__('Unknown', 'event_espresso'); |
|
426 | - $datetimes_strings = array(esc_html__('Unknown', 'event_espresso')); |
|
427 | - } |
|
428 | - $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
429 | - $reg_csv_array[ (string) esc_html__("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
430 | - // get datetime(s) of registration |
|
431 | - // add attendee columns |
|
432 | - foreach ($att_fields_to_include as $att_field_name) { |
|
433 | - $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
434 | - if ($reg_row['Attendee_CPT.ID']) { |
|
435 | - if ($att_field_name == 'STA_ID') { |
|
436 | - $value = EEM_State::instance()->get_var( |
|
437 | - array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
438 | - 'STA_name' |
|
439 | - ); |
|
440 | - } elseif ($att_field_name == 'CNT_ISO') { |
|
441 | - $value = EEM_Country::instance()->get_var( |
|
442 | - array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
443 | - 'CNT_name' |
|
444 | - ); |
|
445 | - } else { |
|
446 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
447 | - EEM_Attendee::instance(), |
|
448 | - $att_field_name, |
|
449 | - $reg_row[ $field_obj->get_qualified_column() ] |
|
450 | - ); |
|
451 | - } |
|
452 | - } else { |
|
453 | - $value = ''; |
|
454 | - } |
|
455 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value; |
|
456 | - } |
|
457 | - // make sure each registration has the same questions in the same order |
|
458 | - foreach ($question_labels as $question_label) { |
|
459 | - if (! isset($reg_csv_array[ $question_label ])) { |
|
460 | - $reg_csv_array[ $question_label ] = null; |
|
461 | - } |
|
462 | - } |
|
463 | - $answers = EEM_Answer::instance()->get_all_wpdb_results(array( |
|
464 | - array('REG_ID' => $reg_row['Registration.REG_ID']), |
|
465 | - 'force_join' => array('Question'), |
|
466 | - )); |
|
467 | - // now fill out the questions THEY answered |
|
468 | - foreach ($answers as $answer_row) { |
|
469 | - if ($answer_row['Question.QST_system']) { |
|
470 | - // it's an answer to a system question. That was already displayed as part of the attendee |
|
471 | - // fields, so don't write it out again thanks. |
|
472 | - continue; |
|
473 | - } |
|
474 | - if ($answer_row['Question.QST_ID']) { |
|
475 | - $question_label = EEH_Export::prepare_value_from_db_for_display( |
|
476 | - EEM_Question::instance(), |
|
477 | - 'QST_admin_label', |
|
478 | - $answer_row['Question.QST_admin_label'] |
|
479 | - ); |
|
480 | - } else { |
|
481 | - $question_label = sprintf(esc_html__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
482 | - } |
|
483 | - if ( |
|
484 | - isset($answer_row['Question.QST_type']) |
|
485 | - && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state |
|
486 | - ) { |
|
487 | - $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
488 | - $answer_row['Answer.ANS_value'] |
|
489 | - ); |
|
490 | - } else { |
|
491 | - // this isn't for html, so don't show html entities |
|
492 | - $reg_csv_array[ $question_label ] = html_entity_decode( |
|
493 | - EEH_Export::prepare_value_from_db_for_display( |
|
494 | - EEM_Answer::instance(), |
|
495 | - 'ANS_value', |
|
496 | - $answer_row['Answer.ANS_value'] |
|
497 | - ) |
|
498 | - ); |
|
499 | - } |
|
500 | - } |
|
235 | + /** |
|
236 | + * Gets the csv data for a batch of registrations |
|
237 | + * |
|
238 | + * @param int|null $event_id |
|
239 | + * @param int $offset |
|
240 | + * @param int $limit |
|
241 | + * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
242 | + * @param array $query_params for using where querying the model |
|
243 | + * @return array top-level keys are numeric, next-level keys are column headers |
|
244 | + * @throws \EE_Error |
|
245 | + */ |
|
246 | + public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params) |
|
247 | + { |
|
248 | + $reg_fields_to_include = array( |
|
249 | + 'TXN_ID', |
|
250 | + 'ATT_ID', |
|
251 | + 'REG_ID', |
|
252 | + 'REG_date', |
|
253 | + 'REG_code', |
|
254 | + 'REG_count', |
|
255 | + 'REG_final_price', |
|
256 | + ); |
|
257 | + $att_fields_to_include = array( |
|
258 | + 'ATT_fname', |
|
259 | + 'ATT_lname', |
|
260 | + 'ATT_email', |
|
261 | + 'ATT_address', |
|
262 | + 'ATT_address2', |
|
263 | + 'ATT_city', |
|
264 | + 'STA_ID', |
|
265 | + 'CNT_ISO', |
|
266 | + 'ATT_zip', |
|
267 | + 'ATT_phone', |
|
268 | + ); |
|
269 | + $registrations_csv_ready_array = array(); |
|
270 | + $reg_model = EE_Registry::instance()->load_model('Registration'); |
|
271 | + $query_params['limit'] = array($offset, $limit); |
|
272 | + $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
273 | + $registration_ids = array(); |
|
274 | + foreach ($registration_rows as $reg_row) { |
|
275 | + $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
276 | + } |
|
277 | + foreach ($registration_rows as $reg_row) { |
|
278 | + if (is_array($reg_row)) { |
|
279 | + $reg_csv_array = array(); |
|
280 | + if (! $event_id) { |
|
281 | + // get the event's name and Id |
|
282 | + $reg_csv_array[ (string) esc_html__('Event', 'event_espresso') ] = sprintf( |
|
283 | + /* translators: 1: event name, 2: event ID */ |
|
284 | + esc_html__('%1$s (%2$s)', 'event_espresso'), |
|
285 | + EEH_Export::prepare_value_from_db_for_display( |
|
286 | + EEM_Event::instance(), |
|
287 | + 'EVT_name', |
|
288 | + $reg_row['Event_CPT.post_title'] |
|
289 | + ), |
|
290 | + $reg_row['Event_CPT.ID'] |
|
291 | + ); |
|
292 | + } |
|
293 | + $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
294 | + /*@var $reg_row EE_Registration */ |
|
295 | + foreach ($reg_fields_to_include as $field_name) { |
|
296 | + $field = $reg_model->field_settings_for($field_name); |
|
297 | + if ($field_name == 'REG_final_price') { |
|
298 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
299 | + $reg_model, |
|
300 | + $field_name, |
|
301 | + $reg_row['Registration.REG_final_price'], |
|
302 | + 'localized_float' |
|
303 | + ); |
|
304 | + } elseif ($field_name == 'REG_count') { |
|
305 | + $value = sprintf( |
|
306 | + /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */ |
|
307 | + esc_html__('%1$s of %2$s', 'event_espresso'), |
|
308 | + EEH_Export::prepare_value_from_db_for_display( |
|
309 | + $reg_model, |
|
310 | + 'REG_count', |
|
311 | + $reg_row['Registration.REG_count'] |
|
312 | + ), |
|
313 | + EEH_Export::prepare_value_from_db_for_display( |
|
314 | + $reg_model, |
|
315 | + 'REG_group_size', |
|
316 | + $reg_row['Registration.REG_group_size'] |
|
317 | + ) |
|
318 | + ); |
|
319 | + } elseif ($field_name == 'REG_date') { |
|
320 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
321 | + $reg_model, |
|
322 | + $field_name, |
|
323 | + $reg_row['Registration.REG_date'], |
|
324 | + 'no_html' |
|
325 | + ); |
|
326 | + } else { |
|
327 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
328 | + $reg_model, |
|
329 | + $field_name, |
|
330 | + $reg_row[ $field->get_qualified_column() ] |
|
331 | + ); |
|
332 | + } |
|
333 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value; |
|
334 | + if ($field_name == 'REG_final_price') { |
|
335 | + // add a column named Currency after the final price |
|
336 | + $reg_csv_array[ (string) esc_html__("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code; |
|
337 | + } |
|
338 | + } |
|
339 | + // get pretty status |
|
340 | + $stati = EEM_Status::instance()->localized_status( |
|
341 | + array( |
|
342 | + $reg_row['Registration.STS_ID'] => esc_html__('unknown', 'event_espresso'), |
|
343 | + $reg_row['TransactionTable.STS_ID'] => esc_html__('unknown', 'event_espresso'), |
|
344 | + ), |
|
345 | + false, |
|
346 | + 'sentence' |
|
347 | + ); |
|
348 | + $reg_csv_array[ (string) esc_html__("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
349 | + // get pretty transaction status |
|
350 | + $reg_csv_array[ (string) esc_html__("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
351 | + $reg_csv_array[ (string) esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
352 | + ? EEH_Export::prepare_value_from_db_for_display( |
|
353 | + EEM_Transaction::instance(), |
|
354 | + 'TXN_total', |
|
355 | + $reg_row['TransactionTable.TXN_total'], |
|
356 | + 'localized_float' |
|
357 | + ) : '0.00'; |
|
358 | + $reg_csv_array[ (string) esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
359 | + ? EEH_Export::prepare_value_from_db_for_display( |
|
360 | + EEM_Transaction::instance(), |
|
361 | + 'TXN_paid', |
|
362 | + $reg_row['TransactionTable.TXN_paid'], |
|
363 | + 'localized_float' |
|
364 | + ) : '0.00'; |
|
365 | + $payment_methods = array(); |
|
366 | + $gateway_txn_ids_etc = array(); |
|
367 | + $payment_times = array(); |
|
368 | + if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
369 | + $payments_info = EEM_Payment::instance()->get_all_wpdb_results( |
|
370 | + array( |
|
371 | + array( |
|
372 | + 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
373 | + 'STS_ID' => EEM_Payment::status_id_approved, |
|
374 | + ), |
|
375 | + 'force_join' => array('Payment_Method'), |
|
376 | + ), |
|
377 | + ARRAY_A, |
|
378 | + 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
379 | + ); |
|
380 | + foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
381 | + $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
382 | + ? $payment_method_and_gateway_txn_id['name'] : esc_html__('Unknown', 'event_espresso'); |
|
383 | + $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
384 | + ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
385 | + $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
386 | + ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
387 | + } |
|
388 | + } |
|
389 | + $reg_csv_array[ (string) esc_html__('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
390 | + $reg_csv_array[ (string) esc_html__('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
391 | + $reg_csv_array[ (string) esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
392 | + ',', |
|
393 | + $gateway_txn_ids_etc |
|
394 | + ); |
|
395 | + // get whether or not the user has checked in |
|
396 | + $reg_csv_array[ (string) esc_html__("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
397 | + $reg_row['Registration.REG_ID'], |
|
398 | + 'Checkin' |
|
399 | + ); |
|
400 | + // get ticket of registration and its price |
|
401 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
402 | + if ($reg_row['Ticket.TKT_ID']) { |
|
403 | + $ticket_name = EEH_Export::prepare_value_from_db_for_display( |
|
404 | + $ticket_model, |
|
405 | + 'TKT_name', |
|
406 | + $reg_row['Ticket.TKT_name'] |
|
407 | + ); |
|
408 | + $datetimes_strings = array(); |
|
409 | + foreach ( |
|
410 | + EEM_Datetime::instance()->get_all_wpdb_results( |
|
411 | + array( |
|
412 | + array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
413 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
414 | + 'default_where_conditions' => 'none', |
|
415 | + ) |
|
416 | + ) as $datetime |
|
417 | + ) { |
|
418 | + $datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display( |
|
419 | + EEM_Datetime::instance(), |
|
420 | + 'DTT_EVT_start', |
|
421 | + $datetime['Datetime.DTT_EVT_start'] |
|
422 | + ); |
|
423 | + } |
|
424 | + } else { |
|
425 | + $ticket_name = esc_html__('Unknown', 'event_espresso'); |
|
426 | + $datetimes_strings = array(esc_html__('Unknown', 'event_espresso')); |
|
427 | + } |
|
428 | + $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
429 | + $reg_csv_array[ (string) esc_html__("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
430 | + // get datetime(s) of registration |
|
431 | + // add attendee columns |
|
432 | + foreach ($att_fields_to_include as $att_field_name) { |
|
433 | + $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
434 | + if ($reg_row['Attendee_CPT.ID']) { |
|
435 | + if ($att_field_name == 'STA_ID') { |
|
436 | + $value = EEM_State::instance()->get_var( |
|
437 | + array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
438 | + 'STA_name' |
|
439 | + ); |
|
440 | + } elseif ($att_field_name == 'CNT_ISO') { |
|
441 | + $value = EEM_Country::instance()->get_var( |
|
442 | + array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
443 | + 'CNT_name' |
|
444 | + ); |
|
445 | + } else { |
|
446 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
447 | + EEM_Attendee::instance(), |
|
448 | + $att_field_name, |
|
449 | + $reg_row[ $field_obj->get_qualified_column() ] |
|
450 | + ); |
|
451 | + } |
|
452 | + } else { |
|
453 | + $value = ''; |
|
454 | + } |
|
455 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value; |
|
456 | + } |
|
457 | + // make sure each registration has the same questions in the same order |
|
458 | + foreach ($question_labels as $question_label) { |
|
459 | + if (! isset($reg_csv_array[ $question_label ])) { |
|
460 | + $reg_csv_array[ $question_label ] = null; |
|
461 | + } |
|
462 | + } |
|
463 | + $answers = EEM_Answer::instance()->get_all_wpdb_results(array( |
|
464 | + array('REG_ID' => $reg_row['Registration.REG_ID']), |
|
465 | + 'force_join' => array('Question'), |
|
466 | + )); |
|
467 | + // now fill out the questions THEY answered |
|
468 | + foreach ($answers as $answer_row) { |
|
469 | + if ($answer_row['Question.QST_system']) { |
|
470 | + // it's an answer to a system question. That was already displayed as part of the attendee |
|
471 | + // fields, so don't write it out again thanks. |
|
472 | + continue; |
|
473 | + } |
|
474 | + if ($answer_row['Question.QST_ID']) { |
|
475 | + $question_label = EEH_Export::prepare_value_from_db_for_display( |
|
476 | + EEM_Question::instance(), |
|
477 | + 'QST_admin_label', |
|
478 | + $answer_row['Question.QST_admin_label'] |
|
479 | + ); |
|
480 | + } else { |
|
481 | + $question_label = sprintf(esc_html__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
482 | + } |
|
483 | + if ( |
|
484 | + isset($answer_row['Question.QST_type']) |
|
485 | + && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state |
|
486 | + ) { |
|
487 | + $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
488 | + $answer_row['Answer.ANS_value'] |
|
489 | + ); |
|
490 | + } else { |
|
491 | + // this isn't for html, so don't show html entities |
|
492 | + $reg_csv_array[ $question_label ] = html_entity_decode( |
|
493 | + EEH_Export::prepare_value_from_db_for_display( |
|
494 | + EEM_Answer::instance(), |
|
495 | + 'ANS_value', |
|
496 | + $answer_row['Answer.ANS_value'] |
|
497 | + ) |
|
498 | + ); |
|
499 | + } |
|
500 | + } |
|
501 | 501 | |
502 | - /** |
|
503 | - * Filter to change the contents of each row of the registrations report CSV file. |
|
504 | - * This can be used to add or remote columns from the CSV file, or change their values. |
|
505 | - * Note when using: all rows in the CSV should have the same columns. |
|
506 | - * @param array $reg_csv_array keys are the column names, values are their cell values |
|
507 | - * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results() |
|
508 | - */ |
|
509 | - $registrations_csv_ready_array[] = apply_filters( |
|
510 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', |
|
511 | - $reg_csv_array, |
|
512 | - $reg_row |
|
513 | - ); |
|
514 | - } |
|
515 | - } |
|
516 | - // if we couldn't export anything, we want to at least show the column headers |
|
517 | - if (empty($registrations_csv_ready_array)) { |
|
518 | - $reg_csv_array = array(); |
|
519 | - $model_and_fields_to_include = array( |
|
520 | - 'Registration' => $reg_fields_to_include, |
|
521 | - 'Attendee' => $att_fields_to_include, |
|
522 | - ); |
|
523 | - foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
524 | - $model = EE_Registry::instance()->load_model($model_name); |
|
525 | - foreach ($field_list as $field_name) { |
|
526 | - $field = $model->field_settings_for($field_name); |
|
527 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
528 | - } |
|
529 | - } |
|
530 | - $registrations_csv_ready_array[] = $reg_csv_array; |
|
531 | - } |
|
532 | - return $registrations_csv_ready_array; |
|
533 | - } |
|
502 | + /** |
|
503 | + * Filter to change the contents of each row of the registrations report CSV file. |
|
504 | + * This can be used to add or remote columns from the CSV file, or change their values. |
|
505 | + * Note when using: all rows in the CSV should have the same columns. |
|
506 | + * @param array $reg_csv_array keys are the column names, values are their cell values |
|
507 | + * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results() |
|
508 | + */ |
|
509 | + $registrations_csv_ready_array[] = apply_filters( |
|
510 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', |
|
511 | + $reg_csv_array, |
|
512 | + $reg_row |
|
513 | + ); |
|
514 | + } |
|
515 | + } |
|
516 | + // if we couldn't export anything, we want to at least show the column headers |
|
517 | + if (empty($registrations_csv_ready_array)) { |
|
518 | + $reg_csv_array = array(); |
|
519 | + $model_and_fields_to_include = array( |
|
520 | + 'Registration' => $reg_fields_to_include, |
|
521 | + 'Attendee' => $att_fields_to_include, |
|
522 | + ); |
|
523 | + foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
524 | + $model = EE_Registry::instance()->load_model($model_name); |
|
525 | + foreach ($field_list as $field_name) { |
|
526 | + $field = $model->field_settings_for($field_name); |
|
527 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
528 | + } |
|
529 | + } |
|
530 | + $registrations_csv_ready_array[] = $reg_csv_array; |
|
531 | + } |
|
532 | + return $registrations_csv_ready_array; |
|
533 | + } |
|
534 | 534 | |
535 | 535 | |
536 | - /** |
|
537 | - * Counts total unit to process |
|
538 | - * |
|
539 | - * @deprecated since 4.9.19 |
|
540 | - * @param int|array $event_id |
|
541 | - * @return int |
|
542 | - */ |
|
543 | - public function count_units_to_process($event_id) |
|
544 | - { |
|
545 | - // use the legacy filter |
|
546 | - if ($event_id) { |
|
547 | - $query_params[0]['EVT_ID'] = $event_id; |
|
548 | - } else { |
|
549 | - $query_params['force_join'][] = 'Event'; |
|
550 | - } |
|
551 | - return \EEM_Registration::instance()->count($query_params); |
|
552 | - } |
|
536 | + /** |
|
537 | + * Counts total unit to process |
|
538 | + * |
|
539 | + * @deprecated since 4.9.19 |
|
540 | + * @param int|array $event_id |
|
541 | + * @return int |
|
542 | + */ |
|
543 | + public function count_units_to_process($event_id) |
|
544 | + { |
|
545 | + // use the legacy filter |
|
546 | + if ($event_id) { |
|
547 | + $query_params[0]['EVT_ID'] = $event_id; |
|
548 | + } else { |
|
549 | + $query_params['force_join'][] = 'Event'; |
|
550 | + } |
|
551 | + return \EEM_Registration::instance()->count($query_params); |
|
552 | + } |
|
553 | 553 | |
554 | 554 | |
555 | - /** |
|
556 | - * Performs any clean-up logic when we know the job is completed. |
|
557 | - * In this case, we delete the temporary file |
|
558 | - * |
|
559 | - * @param JobParameters $job_parameters |
|
560 | - * @return boolean |
|
561 | - */ |
|
562 | - public function cleanup_job(JobParameters $job_parameters) |
|
563 | - { |
|
564 | - $this->_file_helper->delete( |
|
565 | - \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
566 | - true, |
|
567 | - 'd' |
|
568 | - ); |
|
569 | - return new JobStepResponse($job_parameters, esc_html__('Cleaned up temporary file', 'event_espresso')); |
|
570 | - } |
|
555 | + /** |
|
556 | + * Performs any clean-up logic when we know the job is completed. |
|
557 | + * In this case, we delete the temporary file |
|
558 | + * |
|
559 | + * @param JobParameters $job_parameters |
|
560 | + * @return boolean |
|
561 | + */ |
|
562 | + public function cleanup_job(JobParameters $job_parameters) |
|
563 | + { |
|
564 | + $this->_file_helper->delete( |
|
565 | + \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
566 | + true, |
|
567 | + 'd' |
|
568 | + ); |
|
569 | + return new JobStepResponse($job_parameters, esc_html__('Cleaned up temporary file', 'event_espresso')); |
|
570 | + } |
|
571 | 571 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | public function create_job(JobParameters $job_parameters) |
46 | 46 | { |
47 | 47 | $event_id = intval($job_parameters->request_datum('EVT_ID', '0')); |
48 | - if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
48 | + if ( ! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
49 | 49 | throw new BatchRequestException(esc_html__('You do not have permission to view registrations', 'event_espresso')); |
50 | 50 | } |
51 | 51 | $filepath = $this->create_file_from_job_with_name( |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $query_params['force_join'][] = 'Event'; |
83 | 83 | } |
84 | 84 | } |
85 | - if (! isset($query_params['force_join'])) { |
|
85 | + if ( ! isset($query_params['force_join'])) { |
|
86 | 86 | $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
87 | 87 | } |
88 | 88 | $job_parameters->add_extra_data('query_params', $query_params); |
@@ -181,10 +181,10 @@ discard block |
||
181 | 181 | $question_where_params = array(); |
182 | 182 | foreach ($reg_where_params as $key => $val) { |
183 | 183 | if (\EEM_Registration::instance()->is_logic_query_param_key($key)) { |
184 | - $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val); |
|
184 | + $question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val); |
|
185 | 185 | } else { |
186 | 186 | // it's a normal where condition |
187 | - $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
187 | + $question_where_params['Question_Group.Event.Registration.'.$key] = $val; |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 | return $question_where_params; |
@@ -277,9 +277,9 @@ discard block |
||
277 | 277 | foreach ($registration_rows as $reg_row) { |
278 | 278 | if (is_array($reg_row)) { |
279 | 279 | $reg_csv_array = array(); |
280 | - if (! $event_id) { |
|
280 | + if ( ! $event_id) { |
|
281 | 281 | // get the event's name and Id |
282 | - $reg_csv_array[ (string) esc_html__('Event', 'event_espresso') ] = sprintf( |
|
282 | + $reg_csv_array[(string) esc_html__('Event', 'event_espresso')] = sprintf( |
|
283 | 283 | /* translators: 1: event name, 2: event ID */ |
284 | 284 | esc_html__('%1$s (%2$s)', 'event_espresso'), |
285 | 285 | EEH_Export::prepare_value_from_db_for_display( |
@@ -327,13 +327,13 @@ discard block |
||
327 | 327 | $value = EEH_Export::prepare_value_from_db_for_display( |
328 | 328 | $reg_model, |
329 | 329 | $field_name, |
330 | - $reg_row[ $field->get_qualified_column() ] |
|
330 | + $reg_row[$field->get_qualified_column()] |
|
331 | 331 | ); |
332 | 332 | } |
333 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value; |
|
333 | + $reg_csv_array[EEH_Export::get_column_name_for_field($field)] = $value; |
|
334 | 334 | if ($field_name == 'REG_final_price') { |
335 | 335 | // add a column named Currency after the final price |
336 | - $reg_csv_array[ (string) esc_html__("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code; |
|
336 | + $reg_csv_array[(string) esc_html__("Currency", "event_espresso")] = \EE_Config::instance()->currency->code; |
|
337 | 337 | } |
338 | 338 | } |
339 | 339 | // get pretty status |
@@ -345,17 +345,17 @@ discard block |
||
345 | 345 | false, |
346 | 346 | 'sentence' |
347 | 347 | ); |
348 | - $reg_csv_array[ (string) esc_html__("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
348 | + $reg_csv_array[(string) esc_html__("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']]; |
|
349 | 349 | // get pretty transaction status |
350 | - $reg_csv_array[ (string) esc_html__("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
351 | - $reg_csv_array[ (string) esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
350 | + $reg_csv_array[(string) esc_html__("Transaction Status", 'event_espresso')] = $stati[$reg_row['TransactionTable.STS_ID']]; |
|
351 | + $reg_csv_array[(string) esc_html__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg |
|
352 | 352 | ? EEH_Export::prepare_value_from_db_for_display( |
353 | 353 | EEM_Transaction::instance(), |
354 | 354 | 'TXN_total', |
355 | 355 | $reg_row['TransactionTable.TXN_total'], |
356 | 356 | 'localized_float' |
357 | 357 | ) : '0.00'; |
358 | - $reg_csv_array[ (string) esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
358 | + $reg_csv_array[(string) esc_html__('Amount Paid', 'event_espresso')] = $is_primary_reg |
|
359 | 359 | ? EEH_Export::prepare_value_from_db_for_display( |
360 | 360 | EEM_Transaction::instance(), |
361 | 361 | 'TXN_paid', |
@@ -386,14 +386,14 @@ discard block |
||
386 | 386 | ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
387 | 387 | } |
388 | 388 | } |
389 | - $reg_csv_array[ (string) esc_html__('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
390 | - $reg_csv_array[ (string) esc_html__('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
391 | - $reg_csv_array[ (string) esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
389 | + $reg_csv_array[(string) esc_html__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times); |
|
390 | + $reg_csv_array[(string) esc_html__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods); |
|
391 | + $reg_csv_array[(string) esc_html__('Gateway Transaction ID(s)', 'event_espresso')] = implode( |
|
392 | 392 | ',', |
393 | 393 | $gateway_txn_ids_etc |
394 | 394 | ); |
395 | 395 | // get whether or not the user has checked in |
396 | - $reg_csv_array[ (string) esc_html__("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
396 | + $reg_csv_array[(string) esc_html__("Check-Ins", "event_espresso")] = $reg_model->count_related( |
|
397 | 397 | $reg_row['Registration.REG_ID'], |
398 | 398 | 'Checkin' |
399 | 399 | ); |
@@ -425,8 +425,8 @@ discard block |
||
425 | 425 | $ticket_name = esc_html__('Unknown', 'event_espresso'); |
426 | 426 | $datetimes_strings = array(esc_html__('Unknown', 'event_espresso')); |
427 | 427 | } |
428 | - $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
429 | - $reg_csv_array[ (string) esc_html__("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
428 | + $reg_csv_array[(string) $ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name; |
|
429 | + $reg_csv_array[(string) esc_html__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings); |
|
430 | 430 | // get datetime(s) of registration |
431 | 431 | // add attendee columns |
432 | 432 | foreach ($att_fields_to_include as $att_field_name) { |
@@ -446,18 +446,18 @@ discard block |
||
446 | 446 | $value = EEH_Export::prepare_value_from_db_for_display( |
447 | 447 | EEM_Attendee::instance(), |
448 | 448 | $att_field_name, |
449 | - $reg_row[ $field_obj->get_qualified_column() ] |
|
449 | + $reg_row[$field_obj->get_qualified_column()] |
|
450 | 450 | ); |
451 | 451 | } |
452 | 452 | } else { |
453 | 453 | $value = ''; |
454 | 454 | } |
455 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value; |
|
455 | + $reg_csv_array[EEH_Export::get_column_name_for_field($field_obj)] = $value; |
|
456 | 456 | } |
457 | 457 | // make sure each registration has the same questions in the same order |
458 | 458 | foreach ($question_labels as $question_label) { |
459 | - if (! isset($reg_csv_array[ $question_label ])) { |
|
460 | - $reg_csv_array[ $question_label ] = null; |
|
459 | + if ( ! isset($reg_csv_array[$question_label])) { |
|
460 | + $reg_csv_array[$question_label] = null; |
|
461 | 461 | } |
462 | 462 | } |
463 | 463 | $answers = EEM_Answer::instance()->get_all_wpdb_results(array( |
@@ -484,12 +484,12 @@ discard block |
||
484 | 484 | isset($answer_row['Question.QST_type']) |
485 | 485 | && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state |
486 | 486 | ) { |
487 | - $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
487 | + $reg_csv_array[$question_label] = EEM_State::instance()->get_state_name_by_ID( |
|
488 | 488 | $answer_row['Answer.ANS_value'] |
489 | 489 | ); |
490 | 490 | } else { |
491 | 491 | // this isn't for html, so don't show html entities |
492 | - $reg_csv_array[ $question_label ] = html_entity_decode( |
|
492 | + $reg_csv_array[$question_label] = html_entity_decode( |
|
493 | 493 | EEH_Export::prepare_value_from_db_for_display( |
494 | 494 | EEM_Answer::instance(), |
495 | 495 | 'ANS_value', |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | $model = EE_Registry::instance()->load_model($model_name); |
525 | 525 | foreach ($field_list as $field_name) { |
526 | 526 | $field = $model->field_settings_for($field_name); |
527 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
527 | + $reg_csv_array[EEH_Export::get_column_name_for_field($field)] = null; |
|
528 | 528 | } |
529 | 529 | } |
530 | 530 | $registrations_csv_ready_array[] = $reg_csv_array; |
@@ -17,135 +17,135 @@ |
||
17 | 17 | */ |
18 | 18 | abstract class JobHandlerFile extends JobHandler |
19 | 19 | { |
20 | - // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
|
21 | - const temp_folder_name = 'batch_temp_folder'; |
|
20 | + // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
|
21 | + const temp_folder_name = 'batch_temp_folder'; |
|
22 | 22 | |
23 | - // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
24 | - /** |
|
25 | - * @var \EEHI_File |
|
26 | - */ |
|
27 | - protected $_file_helper = null; |
|
23 | + // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
24 | + /** |
|
25 | + * @var \EEHI_File |
|
26 | + */ |
|
27 | + protected $_file_helper = null; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * JobHandlerFile constructor. |
|
32 | - * |
|
33 | - * @param \EEHI_File|null $file_helper |
|
34 | - */ |
|
35 | - public function __construct(\EEHI_File $file_helper = null) |
|
36 | - { |
|
37 | - if (! $file_helper) { |
|
38 | - $this->_file_helper = new EEH_File(); |
|
39 | - } |
|
40 | - } |
|
30 | + /** |
|
31 | + * JobHandlerFile constructor. |
|
32 | + * |
|
33 | + * @param \EEHI_File|null $file_helper |
|
34 | + */ |
|
35 | + public function __construct(\EEHI_File $file_helper = null) |
|
36 | + { |
|
37 | + if (! $file_helper) { |
|
38 | + $this->_file_helper = new EEH_File(); |
|
39 | + } |
|
40 | + } |
|
41 | 41 | |
42 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
43 | - /** |
|
44 | - * Creates a file |
|
45 | - * |
|
46 | - * @param string $job_id |
|
47 | - * @param string $filename |
|
48 | - * @param string $filetype |
|
49 | - * @param string $bom initial content to place in the file. |
|
50 | - * @return string |
|
51 | - * @throws \EventEspressoBatchRequest\Helpers\BatchRequestException |
|
52 | - */ |
|
53 | - public function create_file_from_job_with_name( |
|
54 | - $job_id, |
|
55 | - $filename, |
|
56 | - $filetype = 'application/ms-excel', |
|
57 | - $bom = "\xEF\xBB\xBF" |
|
58 | - ) { |
|
59 | - $filepath = ''; |
|
60 | - try { |
|
61 | - $base_folder = $this->get_base_folder(); |
|
62 | - $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
|
63 | - $base_folder . JobHandlerFile::temp_folder_name |
|
64 | - ); |
|
65 | - if ($success) { |
|
66 | - $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
|
67 | - $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id |
|
68 | - ); |
|
69 | - } |
|
70 | - if ($success) { |
|
71 | - $filepath = $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/' . $filename; |
|
72 | - $success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath); |
|
73 | - } |
|
74 | - // let's add the .htaccess file so safari will open the file properly |
|
75 | - if ($success) { |
|
76 | - $extension = EEH_File::get_file_extension($filepath); |
|
77 | - EEH_File::write_to_file( |
|
78 | - $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/.htaccess', |
|
79 | - 'AddType ' . $filetype . ' ' . $extension, |
|
80 | - '.htaccess' |
|
81 | - ); |
|
82 | - } |
|
83 | - /** |
|
84 | - * Filters what initial content will be added to the file. |
|
85 | - * @param string $return_value. By default it's whatever was pased into |
|
86 | - * JobHandlerFile::create_file_from_job_with_name() |
|
87 | - * @param string $filename |
|
88 | - * @param string $filetype default 'application/ms-excel' |
|
89 | - * @param string $filepath |
|
90 | - */ |
|
91 | - EEH_File::write_to_file( |
|
92 | - $filepath, |
|
93 | - apply_filters( |
|
94 | - 'FHEE__EE_CSV__begin_sending_csv__start_writing', |
|
95 | - $bom, |
|
96 | - $filename, |
|
97 | - $filetype, |
|
98 | - $filepath |
|
99 | - ) |
|
100 | - ); |
|
101 | - // those methods normally fail with an exception, but if not, let's do it |
|
102 | - if (! $success) { |
|
103 | - throw new \EE_Error(esc_html__('Could not create temporary file, an unknown error occurred', 'event_espresso')); |
|
104 | - } |
|
105 | - } catch (\EE_Error $e) { |
|
106 | - throw new BatchRequestException( |
|
107 | - sprintf( |
|
108 | - // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment |
|
109 | - esc_html__('Could not create temporary file for job %1$s, because: %2$s ', 'event_espresso'), |
|
110 | - $job_id, |
|
111 | - $e->getMessage() |
|
112 | - ), |
|
113 | - 500, |
|
114 | - $e |
|
115 | - ); |
|
116 | - } |
|
117 | - return $filepath; |
|
118 | - } |
|
42 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
43 | + /** |
|
44 | + * Creates a file |
|
45 | + * |
|
46 | + * @param string $job_id |
|
47 | + * @param string $filename |
|
48 | + * @param string $filetype |
|
49 | + * @param string $bom initial content to place in the file. |
|
50 | + * @return string |
|
51 | + * @throws \EventEspressoBatchRequest\Helpers\BatchRequestException |
|
52 | + */ |
|
53 | + public function create_file_from_job_with_name( |
|
54 | + $job_id, |
|
55 | + $filename, |
|
56 | + $filetype = 'application/ms-excel', |
|
57 | + $bom = "\xEF\xBB\xBF" |
|
58 | + ) { |
|
59 | + $filepath = ''; |
|
60 | + try { |
|
61 | + $base_folder = $this->get_base_folder(); |
|
62 | + $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
|
63 | + $base_folder . JobHandlerFile::temp_folder_name |
|
64 | + ); |
|
65 | + if ($success) { |
|
66 | + $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
|
67 | + $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id |
|
68 | + ); |
|
69 | + } |
|
70 | + if ($success) { |
|
71 | + $filepath = $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/' . $filename; |
|
72 | + $success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath); |
|
73 | + } |
|
74 | + // let's add the .htaccess file so safari will open the file properly |
|
75 | + if ($success) { |
|
76 | + $extension = EEH_File::get_file_extension($filepath); |
|
77 | + EEH_File::write_to_file( |
|
78 | + $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/.htaccess', |
|
79 | + 'AddType ' . $filetype . ' ' . $extension, |
|
80 | + '.htaccess' |
|
81 | + ); |
|
82 | + } |
|
83 | + /** |
|
84 | + * Filters what initial content will be added to the file. |
|
85 | + * @param string $return_value. By default it's whatever was pased into |
|
86 | + * JobHandlerFile::create_file_from_job_with_name() |
|
87 | + * @param string $filename |
|
88 | + * @param string $filetype default 'application/ms-excel' |
|
89 | + * @param string $filepath |
|
90 | + */ |
|
91 | + EEH_File::write_to_file( |
|
92 | + $filepath, |
|
93 | + apply_filters( |
|
94 | + 'FHEE__EE_CSV__begin_sending_csv__start_writing', |
|
95 | + $bom, |
|
96 | + $filename, |
|
97 | + $filetype, |
|
98 | + $filepath |
|
99 | + ) |
|
100 | + ); |
|
101 | + // those methods normally fail with an exception, but if not, let's do it |
|
102 | + if (! $success) { |
|
103 | + throw new \EE_Error(esc_html__('Could not create temporary file, an unknown error occurred', 'event_espresso')); |
|
104 | + } |
|
105 | + } catch (\EE_Error $e) { |
|
106 | + throw new BatchRequestException( |
|
107 | + sprintf( |
|
108 | + // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment |
|
109 | + esc_html__('Could not create temporary file for job %1$s, because: %2$s ', 'event_espresso'), |
|
110 | + $job_id, |
|
111 | + $e->getMessage() |
|
112 | + ), |
|
113 | + 500, |
|
114 | + $e |
|
115 | + ); |
|
116 | + } |
|
117 | + return $filepath; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Gets the URL to download the file |
|
122 | - * |
|
123 | - * @param string $filepath |
|
124 | - * @return string url to file |
|
125 | - */ |
|
126 | - public function get_url_to_file($filepath) |
|
127 | - { |
|
128 | - return str_replace($this->get_base_folder(), $this->get_base_url(), $filepath); |
|
129 | - } |
|
120 | + /** |
|
121 | + * Gets the URL to download the file |
|
122 | + * |
|
123 | + * @param string $filepath |
|
124 | + * @return string url to file |
|
125 | + */ |
|
126 | + public function get_url_to_file($filepath) |
|
127 | + { |
|
128 | + return str_replace($this->get_base_folder(), $this->get_base_url(), $filepath); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * Gets the folder which will contain the "batch_temp_folder" |
|
133 | - * |
|
134 | - * @return string |
|
135 | - */ |
|
136 | - public function get_base_folder() |
|
137 | - { |
|
138 | - return apply_filters( |
|
139 | - 'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_folder', |
|
140 | - EVENT_ESPRESSO_UPLOAD_DIR |
|
141 | - ); |
|
142 | - } |
|
131 | + /** |
|
132 | + * Gets the folder which will contain the "batch_temp_folder" |
|
133 | + * |
|
134 | + * @return string |
|
135 | + */ |
|
136 | + public function get_base_folder() |
|
137 | + { |
|
138 | + return apply_filters( |
|
139 | + 'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_folder', |
|
140 | + EVENT_ESPRESSO_UPLOAD_DIR |
|
141 | + ); |
|
142 | + } |
|
143 | 143 | |
144 | - public function get_base_url() |
|
145 | - { |
|
146 | - return apply_filters( |
|
147 | - 'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_url', |
|
148 | - EVENT_ESPRESSO_UPLOAD_URL |
|
149 | - ); |
|
150 | - } |
|
144 | + public function get_base_url() |
|
145 | + { |
|
146 | + return apply_filters( |
|
147 | + 'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_url', |
|
148 | + EVENT_ESPRESSO_UPLOAD_URL |
|
149 | + ); |
|
150 | + } |
|
151 | 151 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function __construct(\EEHI_File $file_helper = null) |
36 | 36 | { |
37 | - if (! $file_helper) { |
|
37 | + if ( ! $file_helper) { |
|
38 | 38 | $this->_file_helper = new EEH_File(); |
39 | 39 | } |
40 | 40 | } |
@@ -60,23 +60,23 @@ discard block |
||
60 | 60 | try { |
61 | 61 | $base_folder = $this->get_base_folder(); |
62 | 62 | $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
63 | - $base_folder . JobHandlerFile::temp_folder_name |
|
63 | + $base_folder.JobHandlerFile::temp_folder_name |
|
64 | 64 | ); |
65 | 65 | if ($success) { |
66 | 66 | $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
67 | - $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id |
|
67 | + $base_folder.JobHandlerFile::temp_folder_name.'/'.$job_id |
|
68 | 68 | ); |
69 | 69 | } |
70 | 70 | if ($success) { |
71 | - $filepath = $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/' . $filename; |
|
71 | + $filepath = $base_folder.JobHandlerFile::temp_folder_name.'/'.$job_id.'/'.$filename; |
|
72 | 72 | $success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath); |
73 | 73 | } |
74 | 74 | // let's add the .htaccess file so safari will open the file properly |
75 | 75 | if ($success) { |
76 | 76 | $extension = EEH_File::get_file_extension($filepath); |
77 | 77 | EEH_File::write_to_file( |
78 | - $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/.htaccess', |
|
79 | - 'AddType ' . $filetype . ' ' . $extension, |
|
78 | + $base_folder.JobHandlerFile::temp_folder_name.'/'.$job_id.'/.htaccess', |
|
79 | + 'AddType '.$filetype.' '.$extension, |
|
80 | 80 | '.htaccess' |
81 | 81 | ); |
82 | 82 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | ) |
100 | 100 | ); |
101 | 101 | // those methods normally fail with an exception, but if not, let's do it |
102 | - if (! $success) { |
|
102 | + if ( ! $success) { |
|
103 | 103 | throw new \EE_Error(esc_html__('Could not create temporary file, an unknown error occurred', 'event_espresso')); |
104 | 104 | } |
105 | 105 | } catch (\EE_Error $e) { |
@@ -25,215 +25,215 @@ |
||
25 | 25 | */ |
26 | 26 | class BatchRequestProcessor |
27 | 27 | { |
28 | - // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
29 | - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
30 | - /** |
|
31 | - * Current job's ID (if assigned) |
|
32 | - * |
|
33 | - * @var string|null |
|
34 | - */ |
|
35 | - protected $_job_id; |
|
28 | + // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
29 | + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
30 | + /** |
|
31 | + * Current job's ID (if assigned) |
|
32 | + * |
|
33 | + * @var string|null |
|
34 | + */ |
|
35 | + protected $_job_id; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Current job's parameters |
|
39 | - * |
|
40 | - * @var JobParameters|null |
|
41 | - */ |
|
42 | - protected $_job_parameters; |
|
43 | - /** |
|
44 | - * @var LoaderInterface |
|
45 | - */ |
|
46 | - private $loader; |
|
37 | + /** |
|
38 | + * Current job's parameters |
|
39 | + * |
|
40 | + * @var JobParameters|null |
|
41 | + */ |
|
42 | + protected $_job_parameters; |
|
43 | + /** |
|
44 | + * @var LoaderInterface |
|
45 | + */ |
|
46 | + private $loader; |
|
47 | 47 | |
48 | - /** |
|
49 | - * BatchRequestProcessor constructor. |
|
50 | - * @param LoaderInterface $loader |
|
51 | - */ |
|
52 | - public function __construct(LoaderInterface $loader) |
|
53 | - { |
|
54 | - $this->loader = $loader; |
|
55 | - } |
|
56 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
57 | - /** |
|
58 | - * Creates a job for the specified batch handler class (which should be autoloaded) |
|
59 | - * and the specified request data |
|
60 | - * |
|
61 | - * @param string $batch_job_handler_class of an auto-loaded class implementing JobHandlerInterface |
|
62 | - * @param array $request_data to be used by the batch job handler |
|
63 | - * @return JobStepResponse |
|
64 | - */ |
|
65 | - public function create_job($batch_job_handler_class, $request_data) |
|
66 | - { |
|
67 | - try { |
|
68 | - $this->_job_id = wp_generate_password(15, false); |
|
69 | - $obj = $this->instantiate_batch_job_handler_from_classname($batch_job_handler_class); |
|
70 | - $this->_job_parameters = new JobParameters($this->_job_id, $batch_job_handler_class, $request_data); |
|
71 | - $response = $obj->create_job($this->_job_parameters); |
|
72 | - if (! $response instanceof JobStepResponse) { |
|
73 | - throw new BatchRequestException( |
|
74 | - sprintf( |
|
75 | - esc_html__( |
|
76 | - 'The class implementing JobHandlerInterface did not return a JobStepResponse when create_job was called with %1$s. It needs to return one or throw an Exception', |
|
77 | - 'event_espresso' |
|
78 | - ), |
|
79 | - wp_json_encode($request_data) |
|
80 | - ) |
|
81 | - ); |
|
82 | - } |
|
83 | - $success = $this->_job_parameters->save(true); |
|
84 | - if (! $success) { |
|
85 | - throw new BatchRequestException( |
|
86 | - sprintf( |
|
87 | - esc_html__( |
|
88 | - 'Could not save job %1$s to the Wordpress Options table. These were the arguments used: %2$s', |
|
89 | - 'event_espresso' |
|
90 | - ), |
|
91 | - $this->_job_id, |
|
92 | - wp_json_encode($request_data) |
|
93 | - ) |
|
94 | - ); |
|
95 | - } |
|
96 | - } catch (\Exception $e) { |
|
97 | - $response = $this->_get_error_response($e, 'create_job'); |
|
98 | - } |
|
99 | - return $response; |
|
100 | - } |
|
48 | + /** |
|
49 | + * BatchRequestProcessor constructor. |
|
50 | + * @param LoaderInterface $loader |
|
51 | + */ |
|
52 | + public function __construct(LoaderInterface $loader) |
|
53 | + { |
|
54 | + $this->loader = $loader; |
|
55 | + } |
|
56 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
57 | + /** |
|
58 | + * Creates a job for the specified batch handler class (which should be autoloaded) |
|
59 | + * and the specified request data |
|
60 | + * |
|
61 | + * @param string $batch_job_handler_class of an auto-loaded class implementing JobHandlerInterface |
|
62 | + * @param array $request_data to be used by the batch job handler |
|
63 | + * @return JobStepResponse |
|
64 | + */ |
|
65 | + public function create_job($batch_job_handler_class, $request_data) |
|
66 | + { |
|
67 | + try { |
|
68 | + $this->_job_id = wp_generate_password(15, false); |
|
69 | + $obj = $this->instantiate_batch_job_handler_from_classname($batch_job_handler_class); |
|
70 | + $this->_job_parameters = new JobParameters($this->_job_id, $batch_job_handler_class, $request_data); |
|
71 | + $response = $obj->create_job($this->_job_parameters); |
|
72 | + if (! $response instanceof JobStepResponse) { |
|
73 | + throw new BatchRequestException( |
|
74 | + sprintf( |
|
75 | + esc_html__( |
|
76 | + 'The class implementing JobHandlerInterface did not return a JobStepResponse when create_job was called with %1$s. It needs to return one or throw an Exception', |
|
77 | + 'event_espresso' |
|
78 | + ), |
|
79 | + wp_json_encode($request_data) |
|
80 | + ) |
|
81 | + ); |
|
82 | + } |
|
83 | + $success = $this->_job_parameters->save(true); |
|
84 | + if (! $success) { |
|
85 | + throw new BatchRequestException( |
|
86 | + sprintf( |
|
87 | + esc_html__( |
|
88 | + 'Could not save job %1$s to the Wordpress Options table. These were the arguments used: %2$s', |
|
89 | + 'event_espresso' |
|
90 | + ), |
|
91 | + $this->_job_id, |
|
92 | + wp_json_encode($request_data) |
|
93 | + ) |
|
94 | + ); |
|
95 | + } |
|
96 | + } catch (\Exception $e) { |
|
97 | + $response = $this->_get_error_response($e, 'create_job'); |
|
98 | + } |
|
99 | + return $response; |
|
100 | + } |
|
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * Retrieves the job's arguments |
|
105 | - * |
|
106 | - * @param string $job_id |
|
107 | - * @param int $batch_size |
|
108 | - * @return JobStepResponse |
|
109 | - */ |
|
110 | - public function continue_job($job_id, $batch_size = 50) |
|
111 | - { |
|
112 | - try { |
|
113 | - $this->_job_id = $job_id; |
|
114 | - $batch_size = defined('EE_BATCHRUNNER_BATCH_SIZE') ? EE_BATCHRUNNER_BATCH_SIZE : $batch_size; |
|
115 | - // get the corresponding WordPress option for the job |
|
116 | - $this->_job_parameters = JobParameters::load($this->_job_id); |
|
117 | - $handler_obj = $this->instantiate_batch_job_handler_from_classname($this->_job_parameters->classname()); |
|
118 | - // continue it |
|
119 | - $response = $handler_obj->continue_job($this->_job_parameters, $batch_size); |
|
120 | - if (! $response instanceof JobStepResponse) { |
|
121 | - throw new BatchRequestException( |
|
122 | - sprintf( |
|
123 | - esc_html__( |
|
124 | - 'The class implementing JobHandlerInterface did not return a JobStepResponse when continue_job was called with job %1$s. It needs to return one or throw an Exception', |
|
125 | - 'event_espresso' |
|
126 | - ), |
|
127 | - $this->_job_id |
|
128 | - ) |
|
129 | - ); |
|
130 | - } |
|
131 | - $this->_job_parameters->save(); |
|
132 | - } catch (\Exception $e) { |
|
133 | - $response = $this->_get_error_response($e, 'continue_job'); |
|
134 | - } |
|
135 | - return $response; |
|
136 | - } |
|
103 | + /** |
|
104 | + * Retrieves the job's arguments |
|
105 | + * |
|
106 | + * @param string $job_id |
|
107 | + * @param int $batch_size |
|
108 | + * @return JobStepResponse |
|
109 | + */ |
|
110 | + public function continue_job($job_id, $batch_size = 50) |
|
111 | + { |
|
112 | + try { |
|
113 | + $this->_job_id = $job_id; |
|
114 | + $batch_size = defined('EE_BATCHRUNNER_BATCH_SIZE') ? EE_BATCHRUNNER_BATCH_SIZE : $batch_size; |
|
115 | + // get the corresponding WordPress option for the job |
|
116 | + $this->_job_parameters = JobParameters::load($this->_job_id); |
|
117 | + $handler_obj = $this->instantiate_batch_job_handler_from_classname($this->_job_parameters->classname()); |
|
118 | + // continue it |
|
119 | + $response = $handler_obj->continue_job($this->_job_parameters, $batch_size); |
|
120 | + if (! $response instanceof JobStepResponse) { |
|
121 | + throw new BatchRequestException( |
|
122 | + sprintf( |
|
123 | + esc_html__( |
|
124 | + 'The class implementing JobHandlerInterface did not return a JobStepResponse when continue_job was called with job %1$s. It needs to return one or throw an Exception', |
|
125 | + 'event_espresso' |
|
126 | + ), |
|
127 | + $this->_job_id |
|
128 | + ) |
|
129 | + ); |
|
130 | + } |
|
131 | + $this->_job_parameters->save(); |
|
132 | + } catch (\Exception $e) { |
|
133 | + $response = $this->_get_error_response($e, 'continue_job'); |
|
134 | + } |
|
135 | + return $response; |
|
136 | + } |
|
137 | 137 | |
138 | 138 | |
139 | - /** |
|
140 | - * Instantiates an object of type $classname, which implements |
|
141 | - * JobHandlerInterface |
|
142 | - * |
|
143 | - * @param string $classname |
|
144 | - * @return JobHandlerInterface |
|
145 | - * @throws BatchRequestException |
|
146 | - */ |
|
147 | - public function instantiate_batch_job_handler_from_classname($classname) |
|
148 | - { |
|
149 | - if (! class_exists($classname)) { |
|
150 | - throw new BatchRequestException( |
|
151 | - sprintf( |
|
152 | - esc_html__( |
|
153 | - 'The class %1$s does not exist, and so could not be used for running a job. It should implement JobHandlerInterface.', |
|
154 | - 'event_espresso' |
|
155 | - ), |
|
156 | - $classname |
|
157 | - ) |
|
158 | - ); |
|
159 | - } |
|
160 | - $obj = $this->loader->getNew($classname); |
|
161 | - if (! $obj instanceof JobHandlerInterface) { |
|
162 | - throw new BatchRequestException( |
|
163 | - sprintf( |
|
164 | - esc_html__( |
|
165 | - 'The class %1$s does not implement JobHandlerInterface and so could not be used for running a job', |
|
166 | - 'event_espresso' |
|
167 | - ), |
|
168 | - $classname |
|
169 | - ) |
|
170 | - ); |
|
171 | - } |
|
172 | - return $obj; |
|
173 | - } |
|
139 | + /** |
|
140 | + * Instantiates an object of type $classname, which implements |
|
141 | + * JobHandlerInterface |
|
142 | + * |
|
143 | + * @param string $classname |
|
144 | + * @return JobHandlerInterface |
|
145 | + * @throws BatchRequestException |
|
146 | + */ |
|
147 | + public function instantiate_batch_job_handler_from_classname($classname) |
|
148 | + { |
|
149 | + if (! class_exists($classname)) { |
|
150 | + throw new BatchRequestException( |
|
151 | + sprintf( |
|
152 | + esc_html__( |
|
153 | + 'The class %1$s does not exist, and so could not be used for running a job. It should implement JobHandlerInterface.', |
|
154 | + 'event_espresso' |
|
155 | + ), |
|
156 | + $classname |
|
157 | + ) |
|
158 | + ); |
|
159 | + } |
|
160 | + $obj = $this->loader->getNew($classname); |
|
161 | + if (! $obj instanceof JobHandlerInterface) { |
|
162 | + throw new BatchRequestException( |
|
163 | + sprintf( |
|
164 | + esc_html__( |
|
165 | + 'The class %1$s does not implement JobHandlerInterface and so could not be used for running a job', |
|
166 | + 'event_espresso' |
|
167 | + ), |
|
168 | + $classname |
|
169 | + ) |
|
170 | + ); |
|
171 | + } |
|
172 | + return $obj; |
|
173 | + } |
|
174 | 174 | |
175 | 175 | |
176 | - /** |
|
177 | - * Forces a job to be cleaned up |
|
178 | - * |
|
179 | - * @param string $job_id |
|
180 | - * @return JobStepResponse |
|
181 | - * @throws BatchRequestException |
|
182 | - */ |
|
183 | - public function cleanup_job($job_id) |
|
184 | - { |
|
185 | - try { |
|
186 | - $this->_job_id = $job_id; |
|
187 | - $job_parameters = JobParameters::load($this->_job_id); |
|
188 | - $handler_obj = $this->instantiate_batch_job_handler_from_classname($job_parameters->classname()); |
|
189 | - // continue it |
|
190 | - $response = $handler_obj->cleanup_job($job_parameters); |
|
191 | - if (! $response instanceof JobStepResponse) { |
|
192 | - throw new BatchRequestException( |
|
193 | - sprintf( |
|
194 | - esc_html__( |
|
195 | - 'The class implementing JobHandlerInterface did not return a JobStepResponse when cleanup_job was called with job %1$s. It needs to return one or throw an Exception', |
|
196 | - 'event_espresso' |
|
197 | - ), |
|
198 | - $this->_job_id |
|
199 | - ) |
|
200 | - ); |
|
201 | - } |
|
202 | - $job_parameters->set_status(JobParameters::status_cleaned_up); |
|
203 | - $job_parameters->delete(); |
|
204 | - return $response; |
|
205 | - } catch (\Exception $e) { |
|
206 | - $response = $this->_get_error_response($e, 'cleanup_job'); |
|
207 | - } |
|
208 | - return $response; |
|
209 | - } |
|
176 | + /** |
|
177 | + * Forces a job to be cleaned up |
|
178 | + * |
|
179 | + * @param string $job_id |
|
180 | + * @return JobStepResponse |
|
181 | + * @throws BatchRequestException |
|
182 | + */ |
|
183 | + public function cleanup_job($job_id) |
|
184 | + { |
|
185 | + try { |
|
186 | + $this->_job_id = $job_id; |
|
187 | + $job_parameters = JobParameters::load($this->_job_id); |
|
188 | + $handler_obj = $this->instantiate_batch_job_handler_from_classname($job_parameters->classname()); |
|
189 | + // continue it |
|
190 | + $response = $handler_obj->cleanup_job($job_parameters); |
|
191 | + if (! $response instanceof JobStepResponse) { |
|
192 | + throw new BatchRequestException( |
|
193 | + sprintf( |
|
194 | + esc_html__( |
|
195 | + 'The class implementing JobHandlerInterface did not return a JobStepResponse when cleanup_job was called with job %1$s. It needs to return one or throw an Exception', |
|
196 | + 'event_espresso' |
|
197 | + ), |
|
198 | + $this->_job_id |
|
199 | + ) |
|
200 | + ); |
|
201 | + } |
|
202 | + $job_parameters->set_status(JobParameters::status_cleaned_up); |
|
203 | + $job_parameters->delete(); |
|
204 | + return $response; |
|
205 | + } catch (\Exception $e) { |
|
206 | + $response = $this->_get_error_response($e, 'cleanup_job'); |
|
207 | + } |
|
208 | + return $response; |
|
209 | + } |
|
210 | 210 | |
211 | 211 | |
212 | - /** |
|
213 | - * Creates a valid JobStepResponse object from an exception and method name. |
|
214 | - * |
|
215 | - * @param \Exception $exception |
|
216 | - * @param string $method_name |
|
217 | - * @return JobStepResponse |
|
218 | - */ |
|
219 | - protected function _get_error_response(\Exception $exception, $method_name) |
|
220 | - { |
|
221 | - if (! $this->_job_parameters instanceof JobParameters) { |
|
222 | - $this->_job_parameters = new JobParameters($this->_job_id, esc_html__('__Unknown__', 'event_espresso'), array()); |
|
223 | - } |
|
224 | - $this->_job_parameters->set_status(JobParameters::status_error); |
|
225 | - return new JobStepResponse( |
|
226 | - $this->_job_parameters, |
|
227 | - sprintf( |
|
228 | - esc_html__( |
|
229 | - 'An exception of type %1$s occurred while running %2$s. Its message was %3$s and had trace %4$s', |
|
230 | - 'event_espresso' |
|
231 | - ), |
|
232 | - get_class($exception), |
|
233 | - 'BatchRunner::' . $method_name . '()', |
|
234 | - $exception->getMessage(), |
|
235 | - $exception->getTraceAsString() |
|
236 | - ) |
|
237 | - ); |
|
238 | - } |
|
212 | + /** |
|
213 | + * Creates a valid JobStepResponse object from an exception and method name. |
|
214 | + * |
|
215 | + * @param \Exception $exception |
|
216 | + * @param string $method_name |
|
217 | + * @return JobStepResponse |
|
218 | + */ |
|
219 | + protected function _get_error_response(\Exception $exception, $method_name) |
|
220 | + { |
|
221 | + if (! $this->_job_parameters instanceof JobParameters) { |
|
222 | + $this->_job_parameters = new JobParameters($this->_job_id, esc_html__('__Unknown__', 'event_espresso'), array()); |
|
223 | + } |
|
224 | + $this->_job_parameters->set_status(JobParameters::status_error); |
|
225 | + return new JobStepResponse( |
|
226 | + $this->_job_parameters, |
|
227 | + sprintf( |
|
228 | + esc_html__( |
|
229 | + 'An exception of type %1$s occurred while running %2$s. Its message was %3$s and had trace %4$s', |
|
230 | + 'event_espresso' |
|
231 | + ), |
|
232 | + get_class($exception), |
|
233 | + 'BatchRunner::' . $method_name . '()', |
|
234 | + $exception->getMessage(), |
|
235 | + $exception->getTraceAsString() |
|
236 | + ) |
|
237 | + ); |
|
238 | + } |
|
239 | 239 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | $obj = $this->instantiate_batch_job_handler_from_classname($batch_job_handler_class); |
70 | 70 | $this->_job_parameters = new JobParameters($this->_job_id, $batch_job_handler_class, $request_data); |
71 | 71 | $response = $obj->create_job($this->_job_parameters); |
72 | - if (! $response instanceof JobStepResponse) { |
|
72 | + if ( ! $response instanceof JobStepResponse) { |
|
73 | 73 | throw new BatchRequestException( |
74 | 74 | sprintf( |
75 | 75 | esc_html__( |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | ); |
82 | 82 | } |
83 | 83 | $success = $this->_job_parameters->save(true); |
84 | - if (! $success) { |
|
84 | + if ( ! $success) { |
|
85 | 85 | throw new BatchRequestException( |
86 | 86 | sprintf( |
87 | 87 | esc_html__( |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $handler_obj = $this->instantiate_batch_job_handler_from_classname($this->_job_parameters->classname()); |
118 | 118 | // continue it |
119 | 119 | $response = $handler_obj->continue_job($this->_job_parameters, $batch_size); |
120 | - if (! $response instanceof JobStepResponse) { |
|
120 | + if ( ! $response instanceof JobStepResponse) { |
|
121 | 121 | throw new BatchRequestException( |
122 | 122 | sprintf( |
123 | 123 | esc_html__( |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | */ |
147 | 147 | public function instantiate_batch_job_handler_from_classname($classname) |
148 | 148 | { |
149 | - if (! class_exists($classname)) { |
|
149 | + if ( ! class_exists($classname)) { |
|
150 | 150 | throw new BatchRequestException( |
151 | 151 | sprintf( |
152 | 152 | esc_html__( |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | ); |
159 | 159 | } |
160 | 160 | $obj = $this->loader->getNew($classname); |
161 | - if (! $obj instanceof JobHandlerInterface) { |
|
161 | + if ( ! $obj instanceof JobHandlerInterface) { |
|
162 | 162 | throw new BatchRequestException( |
163 | 163 | sprintf( |
164 | 164 | esc_html__( |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | $handler_obj = $this->instantiate_batch_job_handler_from_classname($job_parameters->classname()); |
189 | 189 | // continue it |
190 | 190 | $response = $handler_obj->cleanup_job($job_parameters); |
191 | - if (! $response instanceof JobStepResponse) { |
|
191 | + if ( ! $response instanceof JobStepResponse) { |
|
192 | 192 | throw new BatchRequestException( |
193 | 193 | sprintf( |
194 | 194 | esc_html__( |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | */ |
219 | 219 | protected function _get_error_response(\Exception $exception, $method_name) |
220 | 220 | { |
221 | - if (! $this->_job_parameters instanceof JobParameters) { |
|
221 | + if ( ! $this->_job_parameters instanceof JobParameters) { |
|
222 | 222 | $this->_job_parameters = new JobParameters($this->_job_id, esc_html__('__Unknown__', 'event_espresso'), array()); |
223 | 223 | } |
224 | 224 | $this->_job_parameters->set_status(JobParameters::status_error); |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | 'event_espresso' |
231 | 231 | ), |
232 | 232 | get_class($exception), |
233 | - 'BatchRunner::' . $method_name . '()', |
|
233 | + 'BatchRunner::'.$method_name.'()', |
|
234 | 234 | $exception->getMessage(), |
235 | 235 | $exception->getTraceAsString() |
236 | 236 | ) |
@@ -15,235 +15,235 @@ discard block |
||
15 | 15 | abstract class EE_Qtip_Config extends EE_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * This will hold the qtips setup array (setup by children) |
|
20 | - * |
|
21 | - * @access protected |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $_qtipsa; |
|
18 | + /** |
|
19 | + * This will hold the qtips setup array (setup by children) |
|
20 | + * |
|
21 | + * @access protected |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $_qtipsa; |
|
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * This holds the constructed EE_Qtip objects |
|
29 | - * |
|
30 | - * @access protected |
|
31 | - * @var EE_Qtip |
|
32 | - */ |
|
33 | - protected $_qtips; |
|
27 | + /** |
|
28 | + * This holds the constructed EE_Qtip objects |
|
29 | + * |
|
30 | + * @access protected |
|
31 | + * @var EE_Qtip |
|
32 | + */ |
|
33 | + protected $_qtips; |
|
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * an array of default options for instantiated qtip js objects |
|
38 | - * |
|
39 | - * @access protected |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - protected $_default_options; |
|
36 | + /** |
|
37 | + * an array of default options for instantiated qtip js objects |
|
38 | + * |
|
39 | + * @access protected |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + protected $_default_options; |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * constructor |
|
47 | - * |
|
48 | - * @access public |
|
49 | - */ |
|
50 | - public function __construct() |
|
51 | - { |
|
52 | - $this->_qtipsa = $this->_qtips = array(); |
|
53 | - $this->_set_default_options(); |
|
54 | - $this->_set_tips_array(); |
|
55 | - $this->_construct_tips(); |
|
56 | - } |
|
45 | + /** |
|
46 | + * constructor |
|
47 | + * |
|
48 | + * @access public |
|
49 | + */ |
|
50 | + public function __construct() |
|
51 | + { |
|
52 | + $this->_qtipsa = $this->_qtips = array(); |
|
53 | + $this->_set_default_options(); |
|
54 | + $this->_set_tips_array(); |
|
55 | + $this->_construct_tips(); |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * Children define this method and its purpose is to setup the $_qtipsa property. The format of this property is: |
|
61 | - * |
|
62 | - * $qtipsa = array( |
|
63 | - * 0 => array( |
|
64 | - * 'content_id' => 'some_unique_id_for_referencing_content', //just the string |
|
65 | - * 'content' => 'html/text content for the qtip', |
|
66 | - * 'target' => '#target-element', //use the same schema as jQuery selectors. This will match what the |
|
67 | - * target is for the qTip in the dom (i.e. if class then '.some-class'). |
|
68 | - * 'options' => array() //use this to override any of the default options for this specific qtip. |
|
69 | - * ) |
|
70 | - * ); |
|
71 | - * |
|
72 | - * @abstract |
|
73 | - * @access protected |
|
74 | - * @return void |
|
75 | - */ |
|
76 | - abstract protected function _set_tips_array(); |
|
59 | + /** |
|
60 | + * Children define this method and its purpose is to setup the $_qtipsa property. The format of this property is: |
|
61 | + * |
|
62 | + * $qtipsa = array( |
|
63 | + * 0 => array( |
|
64 | + * 'content_id' => 'some_unique_id_for_referencing_content', //just the string |
|
65 | + * 'content' => 'html/text content for the qtip', |
|
66 | + * 'target' => '#target-element', //use the same schema as jQuery selectors. This will match what the |
|
67 | + * target is for the qTip in the dom (i.e. if class then '.some-class'). |
|
68 | + * 'options' => array() //use this to override any of the default options for this specific qtip. |
|
69 | + * ) |
|
70 | + * ); |
|
71 | + * |
|
72 | + * @abstract |
|
73 | + * @access protected |
|
74 | + * @return void |
|
75 | + */ |
|
76 | + abstract protected function _set_tips_array(); |
|
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * all the default options for the qtip js are defined here. Children class can override the defaults for all the |
|
81 | - * qtips defined in their config OR just leave it and have the parent default options apply. |
|
82 | - * |
|
83 | - * commented out options are there for reference so you know which can be defined by the child. |
|
84 | - * |
|
85 | - * Note: children do NOT have to define all these options. Just define the ones to override. |
|
86 | - * |
|
87 | - * @link http://qtip2.com/options |
|
88 | - * |
|
89 | - * @access protected |
|
90 | - * @return void |
|
91 | - */ |
|
92 | - protected function _set_default_options() |
|
93 | - { |
|
94 | - $this->_default_options = array( |
|
95 | - // 'id' => 'unique_id_referncing_qtip_instance', |
|
96 | - 'prerender' => false, |
|
97 | - // increases page load if true, |
|
98 | - 'suppress' => true, |
|
99 | - // whether default browser tooltips are suppressed. |
|
100 | - 'content' => array( |
|
101 | - 'button' => false, |
|
102 | - // what you want for the close button text/link. |
|
103 | - 'title' => true, |
|
104 | - // Options: "string", true. If TRUE then the title attribute of the target will be used (if available). If "string" then we'll use that as the title. |
|
105 | - 'clone' => true, |
|
106 | - // Options: true|false. if true then the text will be cloned from the content instead of removed from the dom. |
|
107 | - ), |
|
108 | - 'show_only_once' => false, |
|
109 | - // this is NOT a qtip2 library option, but is something added for EE specific use. If set to true, this means that this particular tooltip will only show ONCE for the user and then a cookie will be saved so that it doesn't show again (after exit). |
|
110 | - 'position' => array( |
|
111 | - 'my' => 'top left', |
|
112 | - // top left || top center || top right || right top || right center || right bottom || bottom right || bottom center || bottom left || left bottom || left center || left top |
|
113 | - 'at' => 'bottom right', |
|
114 | - // same options as above. |
|
115 | - 'target' => 'event', |
|
116 | - // if u use jQuery::#selector, js will parse to a jQuery selector || 'mouse' (at mouse cursor position) || 'event' (position at target that triggered the tooltip), or an array containing an absolute x/y position on page. |
|
117 | - 'container' => false, |
|
118 | - // what HTML element the tooltip is appended to (it's containing element). jquery object. Use 'jQuery::#selector' and js will parse' |
|
119 | - 'viewport' => true, |
|
120 | - // @link http://qtip2.com/plugins#viewport |
|
121 | - 'adjust' => array( |
|
122 | - 'x' => 0, |
|
123 | - // adjust position on x axis by 0 pixels. |
|
124 | - 'y' => 0, |
|
125 | - // adjust position on y axis by 0 pixels. |
|
126 | - 'mouse' => true, |
|
127 | - // when position['target'] is set to 'mouse', tooltip will follow mouse when hovering over the target. False, stops following. |
|
128 | - 'resize' => true, |
|
129 | - // adjust tooltip position when window is resized. |
|
130 | - 'scroll' => true, |
|
131 | - // position of tooltip adjusted when window (or position.container) is scrolled. |
|
132 | - 'method' => 'flipinvert', |
|
133 | - // @link http://qtip2.com/plugins#viewport |
|
134 | - ), |
|
135 | - ), |
|
136 | - 'show' => array( |
|
137 | - 'event' => 'mouseenter', |
|
138 | - // what event triggers tooltip to be shown. Any jQuery standard event or custom events can be used. space separated events provide multiple triggers. |
|
139 | - 'target' => false, |
|
140 | - // options jQuery::#selector|false. Used to indicate which html element will trigger show event. When false, the element the qtip() method was called upon is used. |
|
141 | - 'delay' => 90, |
|
142 | - // time in millisecons by which to delay showing of tooltip. |
|
143 | - 'solo' => false, |
|
144 | - // determines whether tooltip will hid all others when triggered. Options: true (hide all) || false (ignore) || string (parent selector for which qtips get hidden) |
|
145 | - 'modal' => array( |
|
146 | - 'on' => false, // does tooltip trigger modal? |
|
147 | - 'blur' => true, // does clicking on the dimmed background hide the tooltip and remove the dim? |
|
148 | - 'escape' => true, // hitting escape key hide the tooltip and cancel modal |
|
149 | - 'stealfocus' => true, // can users focus on inputs and elelments outside of tooltip when modal on? |
|
150 | - ), |
|
151 | - ), |
|
152 | - 'hide' => array( |
|
153 | - 'event' => 'mouseleave', |
|
154 | - // similar as what you do for show.event. |
|
155 | - 'target' => false, |
|
156 | - // Options jQuery::#selector. which html element will trigger hide event. When false, the element the .qtip() method was called upon is used. |
|
157 | - 'delay' => 0, |
|
158 | - // set time in milliseconds for delaying the hide of the tooltip |
|
159 | - 'inactive' => false, |
|
160 | - // if integer, time in millisecons in which the tooltip should be hidden if remains inactive (not interacted with) |
|
161 | - 'fixed' => false, |
|
162 | - // when set to true, the tooltip will not hide if moused over. |
|
163 | - 'leave' => 'window', |
|
164 | - // specify whether the tooltip will hide when leaving the window it's conained within. |
|
165 | - 'distance' => false, |
|
166 | - // if integer, distance in pixels that the tooltip hides when the mouse is moved from the point it triggered the tooltip. |
|
167 | - ), |
|
168 | - 'style' => array( |
|
169 | - 'classes' => 'qtip-tipsy', |
|
170 | - // Options "string", false. A space separated string containing all class names which should be added ot the main qTip element. See options for styles in comment block at end of this class. |
|
171 | - 'def' => true, |
|
172 | - // set to false and the default qtip class does not get applied |
|
173 | - 'widget' => false, |
|
174 | - // whether ui-widget classes of the themeroller UI styles are applied to tooltip. |
|
175 | - 'width' => false, |
|
176 | - // Options: "string", integer, false. with this you can override all applied CSS width styles for tooltip. Can be any valid width CSS value. (does not override min/max width styles) |
|
177 | - 'height' => false, |
|
178 | - // same as above except applies to height. |
|
179 | - 'tip' => array( |
|
180 | - 'corner' => true, |
|
181 | - // where in relation to the tooltip the speech bubble tip is applied. Options: true, "corner string" (see position), false. true inherits |
|
182 | - 'mimic' => false, |
|
183 | - // see documentation @link http://qtip2.com/plugins#tips |
|
184 | - 'border' => true, |
|
185 | - // Options: true, integer. determines the width of the border that surrounds the tip element. True inherits from tooltip. |
|
186 | - 'width' => 6, |
|
187 | - // width of rendered tip in pixels in relation to the side of the tooltip the tip is on. |
|
188 | - 'height' => 6, |
|
189 | - // works the same as tip.width |
|
190 | - 'offset' => 0, |
|
191 | - // use to set the offset of the tip in relation to its corner position. |
|
192 | - ), |
|
193 | - ), |
|
79 | + /** |
|
80 | + * all the default options for the qtip js are defined here. Children class can override the defaults for all the |
|
81 | + * qtips defined in their config OR just leave it and have the parent default options apply. |
|
82 | + * |
|
83 | + * commented out options are there for reference so you know which can be defined by the child. |
|
84 | + * |
|
85 | + * Note: children do NOT have to define all these options. Just define the ones to override. |
|
86 | + * |
|
87 | + * @link http://qtip2.com/options |
|
88 | + * |
|
89 | + * @access protected |
|
90 | + * @return void |
|
91 | + */ |
|
92 | + protected function _set_default_options() |
|
93 | + { |
|
94 | + $this->_default_options = array( |
|
95 | + // 'id' => 'unique_id_referncing_qtip_instance', |
|
96 | + 'prerender' => false, |
|
97 | + // increases page load if true, |
|
98 | + 'suppress' => true, |
|
99 | + // whether default browser tooltips are suppressed. |
|
100 | + 'content' => array( |
|
101 | + 'button' => false, |
|
102 | + // what you want for the close button text/link. |
|
103 | + 'title' => true, |
|
104 | + // Options: "string", true. If TRUE then the title attribute of the target will be used (if available). If "string" then we'll use that as the title. |
|
105 | + 'clone' => true, |
|
106 | + // Options: true|false. if true then the text will be cloned from the content instead of removed from the dom. |
|
107 | + ), |
|
108 | + 'show_only_once' => false, |
|
109 | + // this is NOT a qtip2 library option, but is something added for EE specific use. If set to true, this means that this particular tooltip will only show ONCE for the user and then a cookie will be saved so that it doesn't show again (after exit). |
|
110 | + 'position' => array( |
|
111 | + 'my' => 'top left', |
|
112 | + // top left || top center || top right || right top || right center || right bottom || bottom right || bottom center || bottom left || left bottom || left center || left top |
|
113 | + 'at' => 'bottom right', |
|
114 | + // same options as above. |
|
115 | + 'target' => 'event', |
|
116 | + // if u use jQuery::#selector, js will parse to a jQuery selector || 'mouse' (at mouse cursor position) || 'event' (position at target that triggered the tooltip), or an array containing an absolute x/y position on page. |
|
117 | + 'container' => false, |
|
118 | + // what HTML element the tooltip is appended to (it's containing element). jquery object. Use 'jQuery::#selector' and js will parse' |
|
119 | + 'viewport' => true, |
|
120 | + // @link http://qtip2.com/plugins#viewport |
|
121 | + 'adjust' => array( |
|
122 | + 'x' => 0, |
|
123 | + // adjust position on x axis by 0 pixels. |
|
124 | + 'y' => 0, |
|
125 | + // adjust position on y axis by 0 pixels. |
|
126 | + 'mouse' => true, |
|
127 | + // when position['target'] is set to 'mouse', tooltip will follow mouse when hovering over the target. False, stops following. |
|
128 | + 'resize' => true, |
|
129 | + // adjust tooltip position when window is resized. |
|
130 | + 'scroll' => true, |
|
131 | + // position of tooltip adjusted when window (or position.container) is scrolled. |
|
132 | + 'method' => 'flipinvert', |
|
133 | + // @link http://qtip2.com/plugins#viewport |
|
134 | + ), |
|
135 | + ), |
|
136 | + 'show' => array( |
|
137 | + 'event' => 'mouseenter', |
|
138 | + // what event triggers tooltip to be shown. Any jQuery standard event or custom events can be used. space separated events provide multiple triggers. |
|
139 | + 'target' => false, |
|
140 | + // options jQuery::#selector|false. Used to indicate which html element will trigger show event. When false, the element the qtip() method was called upon is used. |
|
141 | + 'delay' => 90, |
|
142 | + // time in millisecons by which to delay showing of tooltip. |
|
143 | + 'solo' => false, |
|
144 | + // determines whether tooltip will hid all others when triggered. Options: true (hide all) || false (ignore) || string (parent selector for which qtips get hidden) |
|
145 | + 'modal' => array( |
|
146 | + 'on' => false, // does tooltip trigger modal? |
|
147 | + 'blur' => true, // does clicking on the dimmed background hide the tooltip and remove the dim? |
|
148 | + 'escape' => true, // hitting escape key hide the tooltip and cancel modal |
|
149 | + 'stealfocus' => true, // can users focus on inputs and elelments outside of tooltip when modal on? |
|
150 | + ), |
|
151 | + ), |
|
152 | + 'hide' => array( |
|
153 | + 'event' => 'mouseleave', |
|
154 | + // similar as what you do for show.event. |
|
155 | + 'target' => false, |
|
156 | + // Options jQuery::#selector. which html element will trigger hide event. When false, the element the .qtip() method was called upon is used. |
|
157 | + 'delay' => 0, |
|
158 | + // set time in milliseconds for delaying the hide of the tooltip |
|
159 | + 'inactive' => false, |
|
160 | + // if integer, time in millisecons in which the tooltip should be hidden if remains inactive (not interacted with) |
|
161 | + 'fixed' => false, |
|
162 | + // when set to true, the tooltip will not hide if moused over. |
|
163 | + 'leave' => 'window', |
|
164 | + // specify whether the tooltip will hide when leaving the window it's conained within. |
|
165 | + 'distance' => false, |
|
166 | + // if integer, distance in pixels that the tooltip hides when the mouse is moved from the point it triggered the tooltip. |
|
167 | + ), |
|
168 | + 'style' => array( |
|
169 | + 'classes' => 'qtip-tipsy', |
|
170 | + // Options "string", false. A space separated string containing all class names which should be added ot the main qTip element. See options for styles in comment block at end of this class. |
|
171 | + 'def' => true, |
|
172 | + // set to false and the default qtip class does not get applied |
|
173 | + 'widget' => false, |
|
174 | + // whether ui-widget classes of the themeroller UI styles are applied to tooltip. |
|
175 | + 'width' => false, |
|
176 | + // Options: "string", integer, false. with this you can override all applied CSS width styles for tooltip. Can be any valid width CSS value. (does not override min/max width styles) |
|
177 | + 'height' => false, |
|
178 | + // same as above except applies to height. |
|
179 | + 'tip' => array( |
|
180 | + 'corner' => true, |
|
181 | + // where in relation to the tooltip the speech bubble tip is applied. Options: true, "corner string" (see position), false. true inherits |
|
182 | + 'mimic' => false, |
|
183 | + // see documentation @link http://qtip2.com/plugins#tips |
|
184 | + 'border' => true, |
|
185 | + // Options: true, integer. determines the width of the border that surrounds the tip element. True inherits from tooltip. |
|
186 | + 'width' => 6, |
|
187 | + // width of rendered tip in pixels in relation to the side of the tooltip the tip is on. |
|
188 | + 'height' => 6, |
|
189 | + // works the same as tip.width |
|
190 | + 'offset' => 0, |
|
191 | + // use to set the offset of the tip in relation to its corner position. |
|
192 | + ), |
|
193 | + ), |
|
194 | 194 | |
195 | - ); |
|
196 | - } |
|
195 | + ); |
|
196 | + } |
|
197 | 197 | |
198 | 198 | |
199 | - /** |
|
200 | - * This takes the set $_qtipsa array property and loops through it to set the EE_Qtip objects and assign them to |
|
201 | - * the $_qtips property |
|
202 | - * |
|
203 | - * @access protected |
|
204 | - * @return void |
|
205 | - */ |
|
206 | - protected function _construct_tips() |
|
207 | - { |
|
208 | - foreach ($this->_qtipsa as $qt) { |
|
209 | - // make sure we have what we need. |
|
210 | - if (! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) { |
|
211 | - throw new EE_Error( |
|
212 | - sprintf( |
|
213 | - esc_html__( |
|
214 | - 'There is something wrong with the _qtipsa property setup for the %s qtip config class. The dump of the current array index is: %s.<br /><br />Please check that it is setup correctly.', |
|
215 | - 'event_espresso' |
|
216 | - ), |
|
217 | - get_class($this), |
|
218 | - var_export($qt, true) |
|
219 | - ) |
|
220 | - ); |
|
221 | - } |
|
199 | + /** |
|
200 | + * This takes the set $_qtipsa array property and loops through it to set the EE_Qtip objects and assign them to |
|
201 | + * the $_qtips property |
|
202 | + * |
|
203 | + * @access protected |
|
204 | + * @return void |
|
205 | + */ |
|
206 | + protected function _construct_tips() |
|
207 | + { |
|
208 | + foreach ($this->_qtipsa as $qt) { |
|
209 | + // make sure we have what we need. |
|
210 | + if (! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) { |
|
211 | + throw new EE_Error( |
|
212 | + sprintf( |
|
213 | + esc_html__( |
|
214 | + 'There is something wrong with the _qtipsa property setup for the %s qtip config class. The dump of the current array index is: %s.<br /><br />Please check that it is setup correctly.', |
|
215 | + 'event_espresso' |
|
216 | + ), |
|
217 | + get_class($this), |
|
218 | + var_export($qt, true) |
|
219 | + ) |
|
220 | + ); |
|
221 | + } |
|
222 | 222 | |
223 | - // make sure the options include defaults and just override via set config. |
|
224 | - $options_override = isset($qt['options']) ? (array) $qt['options'] : array(); |
|
225 | - $options = array_merge($this->_default_options, $options_override); |
|
226 | - $setup = array( |
|
227 | - 'content_id' => $qt['content_id'], |
|
228 | - 'options' => $options, |
|
229 | - 'target' => $qt['target'], |
|
230 | - 'content' => $qt['content'], |
|
231 | - ); |
|
232 | - $this->_qtips[] = new EE_Qtip($setup); |
|
233 | - } |
|
234 | - } |
|
223 | + // make sure the options include defaults and just override via set config. |
|
224 | + $options_override = isset($qt['options']) ? (array) $qt['options'] : array(); |
|
225 | + $options = array_merge($this->_default_options, $options_override); |
|
226 | + $setup = array( |
|
227 | + 'content_id' => $qt['content_id'], |
|
228 | + 'options' => $options, |
|
229 | + 'target' => $qt['target'], |
|
230 | + 'content' => $qt['content'], |
|
231 | + ); |
|
232 | + $this->_qtips[] = new EE_Qtip($setup); |
|
233 | + } |
|
234 | + } |
|
235 | 235 | |
236 | 236 | |
237 | - /** |
|
238 | - * return the _qtips property contents |
|
239 | - * |
|
240 | - * @access public |
|
241 | - * @return EE_Qtip[] |
|
242 | - */ |
|
243 | - public function get_tips() |
|
244 | - { |
|
245 | - return $this->_qtips; |
|
246 | - } |
|
237 | + /** |
|
238 | + * return the _qtips property contents |
|
239 | + * |
|
240 | + * @access public |
|
241 | + * @return EE_Qtip[] |
|
242 | + */ |
|
243 | + public function get_tips() |
|
244 | + { |
|
245 | + return $this->_qtips; |
|
246 | + } |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | // class names you can use for tooltip styles |
@@ -295,17 +295,17 @@ discard block |
||
295 | 295 | */ |
296 | 296 | class EE_Qtip extends EE_Base |
297 | 297 | { |
298 | - public $content_id; |
|
299 | - public $options; |
|
300 | - public $target; |
|
301 | - public $content; |
|
298 | + public $content_id; |
|
299 | + public $options; |
|
300 | + public $target; |
|
301 | + public $content; |
|
302 | 302 | |
303 | - public function __construct($setup_array) |
|
304 | - { |
|
305 | - foreach ($setup_array as $prop => $value) { |
|
306 | - if (EEH_Class_Tools::has_property($this, $prop)) { |
|
307 | - $this->{$prop} = $value; |
|
308 | - } |
|
309 | - } |
|
310 | - } |
|
303 | + public function __construct($setup_array) |
|
304 | + { |
|
305 | + foreach ($setup_array as $prop => $value) { |
|
306 | + if (EEH_Class_Tools::has_property($this, $prop)) { |
|
307 | + $this->{$prop} = $value; |
|
308 | + } |
|
309 | + } |
|
310 | + } |
|
311 | 311 | } |
@@ -207,7 +207,7 @@ |
||
207 | 207 | { |
208 | 208 | foreach ($this->_qtipsa as $qt) { |
209 | 209 | // make sure we have what we need. |
210 | - if (! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) { |
|
210 | + if ( ! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) { |
|
211 | 211 | throw new EE_Error( |
212 | 212 | sprintf( |
213 | 213 | esc_html__( |
@@ -11,332 +11,332 @@ |
||
11 | 11 | class EE_Register_Messages_Template_Variations implements EEI_Plugin_API |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * Holds values for registered variations |
|
16 | - * |
|
17 | - * @since 4.5.0 |
|
18 | - * |
|
19 | - * @var array |
|
20 | - */ |
|
21 | - protected static $_registry = []; |
|
14 | + /** |
|
15 | + * Holds values for registered variations |
|
16 | + * |
|
17 | + * @since 4.5.0 |
|
18 | + * |
|
19 | + * @var array |
|
20 | + */ |
|
21 | + protected static $_registry = []; |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * Used to register new variations |
|
26 | - * |
|
27 | - * Variations are attached to template packs and do not typically change any structural layout but merely tweak the |
|
28 | - * style of the layout. The most commonly known variation is css. CSS does not affect html structure just the |
|
29 | - * style of existing structure. |
|
30 | - * |
|
31 | - * It's important to remember that when variation files are loaded, the file structure looked for is: |
|
32 | - * '{$messenger}_{$messenger_variation_type}_{$variation_slug}.{$extension}'. |
|
33 | - * |
|
34 | - * - Every variation applies to specific messengers. That's why the variation file includes the messenger name |
|
35 | - * it. This ensures that if a template pack the variation is registered with supports multiple variations that |
|
36 | - * you can have the correct variation loaded. |
|
37 | - * - EE_messengers also implicitly define variation "types" which typically are the context in which a specific |
|
38 | - * variation is loaded. For instance the email messenger has: 'inline', which is the css added inline to the |
|
39 | - * email templates; 'preview', which is the same css only customized for when emails are previewed; and |
|
40 | - * 'wpeditor', which is the same css only customized so that it works with the wpeditor fields for templates to |
|
41 | - * give a accurate representation of the style in the wysiwyg editor. This means that for each variation, if |
|
42 | - * you want it to be accurately represented in various template contexts you need to have that relevant |
|
43 | - * variation file available. |
|
44 | - * - $variation_slug is simply the variation slug for that variation. |
|
45 | - * - $extension = whatever the extension is for the variation used for the messenger calling it. In MOST cases |
|
46 | - * messenger variations are .css files. Note: if your file names are not formatted correctly then they will NOT |
|
47 | - * be loaded. The EE messages template pack system will fallback to corresponding default template pack for the |
|
48 | - * given messenger or as a last resort (i.e. no default variation for the given messenger) will not load any |
|
49 | - * variation (so the template pack would be unstyled) |
|
50 | - * |
|
51 | - * @see /core/libraries/messages/defaults/default/variations/* for example variation files for the email and html |
|
52 | - * messengers. |
|
53 | - * |
|
54 | - * @param string $identifier unique reference used to describe this variation registry. If |
|
55 | - * this ISN'T unique then this method will make it unique (and it |
|
56 | - * becomes harder to deregister). |
|
57 | - * @param array $setup_args { |
|
58 | - * an array of required values for registering the variations. |
|
59 | - * @type array $variations { |
|
60 | - * An array indexed by template_pack->dbref. and values are an array |
|
61 | - * indexed by messenger name and values are an array indexed by |
|
62 | - * message_type and values are an array indexed by variation_slug |
|
63 | - * and value is the localized label for the variation. Note this |
|
64 | - * api reserves the "default" variation name for the default |
|
65 | - * template pack so you can't register a default variation. Also, |
|
66 | - * try to use unique variation slugs to reference your variations |
|
67 | - * because this api checks if any existing variations are in place |
|
68 | - * with that name. If there are then subsequent variations for that |
|
69 | - * template pack with that same name will fail to register with a |
|
70 | - * persistent notice put up for the user. Required. |
|
71 | - * 'default' => array( |
|
72 | - * 'email' => array( |
|
73 | - * 'registration_approved' => array( |
|
74 | - * my_ee_addon_blue_lagoon' => esc_html__('Blue Lagoon', |
|
75 | - * 'text_domain'), |
|
76 | - * 'my_ee_addon_red_sunset' => esc_html__('Red Sunset', |
|
77 | - * 'text_domain') |
|
78 | - * ) |
|
79 | - * ) |
|
80 | - * ) |
|
81 | - * } |
|
82 | - * @type string $base_path The base path for where all your variations are found. Although |
|
83 | - * the full path to your variation files should include |
|
84 | - * '/variations/' in it, do not include the |
|
85 | - * 'variations/' in this. Required. |
|
86 | - * @type string $base_url The base url for where all your variations are found. See note |
|
87 | - * above about the 'variations/' string. Required. |
|
88 | - * } |
|
89 | - * } |
|
90 | - * |
|
91 | - * @throws EE_Error |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - public static function register($identifier = '', array $setup_args = []) |
|
95 | - { |
|
24 | + /** |
|
25 | + * Used to register new variations |
|
26 | + * |
|
27 | + * Variations are attached to template packs and do not typically change any structural layout but merely tweak the |
|
28 | + * style of the layout. The most commonly known variation is css. CSS does not affect html structure just the |
|
29 | + * style of existing structure. |
|
30 | + * |
|
31 | + * It's important to remember that when variation files are loaded, the file structure looked for is: |
|
32 | + * '{$messenger}_{$messenger_variation_type}_{$variation_slug}.{$extension}'. |
|
33 | + * |
|
34 | + * - Every variation applies to specific messengers. That's why the variation file includes the messenger name |
|
35 | + * it. This ensures that if a template pack the variation is registered with supports multiple variations that |
|
36 | + * you can have the correct variation loaded. |
|
37 | + * - EE_messengers also implicitly define variation "types" which typically are the context in which a specific |
|
38 | + * variation is loaded. For instance the email messenger has: 'inline', which is the css added inline to the |
|
39 | + * email templates; 'preview', which is the same css only customized for when emails are previewed; and |
|
40 | + * 'wpeditor', which is the same css only customized so that it works with the wpeditor fields for templates to |
|
41 | + * give a accurate representation of the style in the wysiwyg editor. This means that for each variation, if |
|
42 | + * you want it to be accurately represented in various template contexts you need to have that relevant |
|
43 | + * variation file available. |
|
44 | + * - $variation_slug is simply the variation slug for that variation. |
|
45 | + * - $extension = whatever the extension is for the variation used for the messenger calling it. In MOST cases |
|
46 | + * messenger variations are .css files. Note: if your file names are not formatted correctly then they will NOT |
|
47 | + * be loaded. The EE messages template pack system will fallback to corresponding default template pack for the |
|
48 | + * given messenger or as a last resort (i.e. no default variation for the given messenger) will not load any |
|
49 | + * variation (so the template pack would be unstyled) |
|
50 | + * |
|
51 | + * @see /core/libraries/messages/defaults/default/variations/* for example variation files for the email and html |
|
52 | + * messengers. |
|
53 | + * |
|
54 | + * @param string $identifier unique reference used to describe this variation registry. If |
|
55 | + * this ISN'T unique then this method will make it unique (and it |
|
56 | + * becomes harder to deregister). |
|
57 | + * @param array $setup_args { |
|
58 | + * an array of required values for registering the variations. |
|
59 | + * @type array $variations { |
|
60 | + * An array indexed by template_pack->dbref. and values are an array |
|
61 | + * indexed by messenger name and values are an array indexed by |
|
62 | + * message_type and values are an array indexed by variation_slug |
|
63 | + * and value is the localized label for the variation. Note this |
|
64 | + * api reserves the "default" variation name for the default |
|
65 | + * template pack so you can't register a default variation. Also, |
|
66 | + * try to use unique variation slugs to reference your variations |
|
67 | + * because this api checks if any existing variations are in place |
|
68 | + * with that name. If there are then subsequent variations for that |
|
69 | + * template pack with that same name will fail to register with a |
|
70 | + * persistent notice put up for the user. Required. |
|
71 | + * 'default' => array( |
|
72 | + * 'email' => array( |
|
73 | + * 'registration_approved' => array( |
|
74 | + * my_ee_addon_blue_lagoon' => esc_html__('Blue Lagoon', |
|
75 | + * 'text_domain'), |
|
76 | + * 'my_ee_addon_red_sunset' => esc_html__('Red Sunset', |
|
77 | + * 'text_domain') |
|
78 | + * ) |
|
79 | + * ) |
|
80 | + * ) |
|
81 | + * } |
|
82 | + * @type string $base_path The base path for where all your variations are found. Although |
|
83 | + * the full path to your variation files should include |
|
84 | + * '/variations/' in it, do not include the |
|
85 | + * 'variations/' in this. Required. |
|
86 | + * @type string $base_url The base url for where all your variations are found. See note |
|
87 | + * above about the 'variations/' string. Required. |
|
88 | + * } |
|
89 | + * } |
|
90 | + * |
|
91 | + * @throws EE_Error |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + public static function register($identifier = '', array $setup_args = []) |
|
95 | + { |
|
96 | 96 | |
97 | - // check for required params |
|
98 | - if (empty($identifier)) { |
|
99 | - throw new EE_Error( |
|
100 | - esc_html__( |
|
101 | - 'In order to register variations for a EE_Message_Template_Pack, you must include a value to reference the variations being registered', |
|
102 | - 'event_espresso' |
|
103 | - ) |
|
104 | - ); |
|
105 | - } |
|
97 | + // check for required params |
|
98 | + if (empty($identifier)) { |
|
99 | + throw new EE_Error( |
|
100 | + esc_html__( |
|
101 | + 'In order to register variations for a EE_Message_Template_Pack, you must include a value to reference the variations being registered', |
|
102 | + 'event_espresso' |
|
103 | + ) |
|
104 | + ); |
|
105 | + } |
|
106 | 106 | |
107 | - if ( |
|
108 | - ! is_array($setup_args) |
|
109 | - || empty($setup_args['variations']) |
|
110 | - || empty($setup_args['base_path']) |
|
111 | - || empty($setup_args['base_url']) |
|
112 | - ) { |
|
113 | - throw new EE_Error( |
|
114 | - esc_html__( |
|
115 | - 'In order to register variations for a EE_Message_Template_Pack, you must include an array containing the following keys: "variations", "base_path", "base_url", "extension"', |
|
116 | - 'event_espresso' |
|
117 | - ) |
|
118 | - ); |
|
119 | - } |
|
107 | + if ( |
|
108 | + ! is_array($setup_args) |
|
109 | + || empty($setup_args['variations']) |
|
110 | + || empty($setup_args['base_path']) |
|
111 | + || empty($setup_args['base_url']) |
|
112 | + ) { |
|
113 | + throw new EE_Error( |
|
114 | + esc_html__( |
|
115 | + 'In order to register variations for a EE_Message_Template_Pack, you must include an array containing the following keys: "variations", "base_path", "base_url", "extension"', |
|
116 | + 'event_espresso' |
|
117 | + ) |
|
118 | + ); |
|
119 | + } |
|
120 | 120 | |
121 | - // make sure we don't register twice |
|
122 | - if (isset(self::$_registry[ $identifier ])) { |
|
123 | - return; |
|
124 | - } |
|
121 | + // make sure we don't register twice |
|
122 | + if (isset(self::$_registry[ $identifier ])) { |
|
123 | + return; |
|
124 | + } |
|
125 | 125 | |
126 | - // make sure variation ref is unique. |
|
127 | - if (isset(self::$_registry[ $identifier ])) { |
|
128 | - $identifier = uniqid() . '_' . $identifier; |
|
129 | - } |
|
126 | + // make sure variation ref is unique. |
|
127 | + if (isset(self::$_registry[ $identifier ])) { |
|
128 | + $identifier = uniqid() . '_' . $identifier; |
|
129 | + } |
|
130 | 130 | |
131 | 131 | |
132 | - // make sure this was called in the right place! |
|
133 | - if ( |
|
134 | - ! did_action('EE_Brewing_Regular___messages_caf') |
|
135 | - || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
136 | - ) { |
|
137 | - EE_Error::doing_it_wrong( |
|
138 | - __METHOD__, |
|
139 | - sprintf( |
|
140 | - esc_html__( |
|
141 | - 'Messages Templates Variations given the reference "%s" has been attempted to be registered with the EE Messages Template Pack System. It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.', |
|
142 | - 'event_espresso' |
|
143 | - ), |
|
144 | - $identifier |
|
145 | - ), |
|
146 | - '4.5.0' |
|
147 | - ); |
|
148 | - } |
|
132 | + // make sure this was called in the right place! |
|
133 | + if ( |
|
134 | + ! did_action('EE_Brewing_Regular___messages_caf') |
|
135 | + || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
136 | + ) { |
|
137 | + EE_Error::doing_it_wrong( |
|
138 | + __METHOD__, |
|
139 | + sprintf( |
|
140 | + esc_html__( |
|
141 | + 'Messages Templates Variations given the reference "%s" has been attempted to be registered with the EE Messages Template Pack System. It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.', |
|
142 | + 'event_espresso' |
|
143 | + ), |
|
144 | + $identifier |
|
145 | + ), |
|
146 | + '4.5.0' |
|
147 | + ); |
|
148 | + } |
|
149 | 149 | |
150 | - // validate/sanitize incoming args. |
|
151 | - $validated = [ |
|
152 | - 'variations' => (array) $setup_args['variations'], |
|
153 | - 'base_path' => (string) $setup_args['base_path'], |
|
154 | - 'base_url' => (string) $setup_args['base_url'], |
|
155 | - ]; |
|
150 | + // validate/sanitize incoming args. |
|
151 | + $validated = [ |
|
152 | + 'variations' => (array) $setup_args['variations'], |
|
153 | + 'base_path' => (string) $setup_args['base_path'], |
|
154 | + 'base_url' => (string) $setup_args['base_url'], |
|
155 | + ]; |
|
156 | 156 | |
157 | 157 | |
158 | - // check that no reserved variation names are in use and also checks if there are already existing variation names for a given template pack. The former will throw an error. The latter will remove the conflicting variation name but still register the others and will add EE_Error notice. |
|
159 | - $validated = self::_verify_variations($identifier, $validated); |
|
160 | - self::$_registry[ $identifier ] = $validated; |
|
158 | + // check that no reserved variation names are in use and also checks if there are already existing variation names for a given template pack. The former will throw an error. The latter will remove the conflicting variation name but still register the others and will add EE_Error notice. |
|
159 | + $validated = self::_verify_variations($identifier, $validated); |
|
160 | + self::$_registry[ $identifier ] = $validated; |
|
161 | 161 | |
162 | - add_filter( |
|
163 | - 'FHEE__EE_Messages_Template_Pack__get_variations', |
|
164 | - ['EE_Register_Messages_Template_Variations', 'get_variations'], |
|
165 | - 10, |
|
166 | - 4 |
|
167 | - ); |
|
168 | - add_filter( |
|
169 | - 'FHEE__EE_Messages_Template_Pack__get_variation', |
|
170 | - ['EE_Register_Messages_Template_Variations', 'get_variation'], |
|
171 | - 10, |
|
172 | - 8 |
|
173 | - ); |
|
174 | - } |
|
162 | + add_filter( |
|
163 | + 'FHEE__EE_Messages_Template_Pack__get_variations', |
|
164 | + ['EE_Register_Messages_Template_Variations', 'get_variations'], |
|
165 | + 10, |
|
166 | + 4 |
|
167 | + ); |
|
168 | + add_filter( |
|
169 | + 'FHEE__EE_Messages_Template_Pack__get_variation', |
|
170 | + ['EE_Register_Messages_Template_Variations', 'get_variation'], |
|
171 | + 10, |
|
172 | + 8 |
|
173 | + ); |
|
174 | + } |
|
175 | 175 | |
176 | 176 | |
177 | - /** |
|
178 | - * Cycles through the variations registered and makes sure there are no reserved variations being registered which |
|
179 | - * throws an error. Also checks if there is already a |
|
180 | - * |
|
181 | - * @param string $identifier the reference for the variations being registered |
|
182 | - * @param array $validated_variations The variations setup array that's being registered (and verified). |
|
183 | - * @return array |
|
184 | - * @throws EE_Error |
|
185 | - * @since 4.5.0 |
|
186 | - * |
|
187 | - */ |
|
188 | - private static function _verify_variations($identifier, array $validated_variations) |
|
189 | - { |
|
190 | - foreach (self::$_registry as $settings) { |
|
191 | - foreach ($settings['variations'] as $messenger) { |
|
192 | - foreach ($messenger as $all_variations) { |
|
193 | - if (isset($all_variations['default'])) { |
|
194 | - throw new EE_Error( |
|
195 | - sprintf( |
|
196 | - esc_html__( |
|
197 | - 'Variations registered through the EE_Register_Messages_Template_Variations api cannot override the default variation for the default template. Please check the code registering variations with this reference, "%s" and modify.', |
|
198 | - 'event_espresso' |
|
199 | - ), |
|
200 | - $identifier |
|
201 | - ) |
|
202 | - ); |
|
203 | - } |
|
204 | - } |
|
205 | - } |
|
206 | - } |
|
177 | + /** |
|
178 | + * Cycles through the variations registered and makes sure there are no reserved variations being registered which |
|
179 | + * throws an error. Also checks if there is already a |
|
180 | + * |
|
181 | + * @param string $identifier the reference for the variations being registered |
|
182 | + * @param array $validated_variations The variations setup array that's being registered (and verified). |
|
183 | + * @return array |
|
184 | + * @throws EE_Error |
|
185 | + * @since 4.5.0 |
|
186 | + * |
|
187 | + */ |
|
188 | + private static function _verify_variations($identifier, array $validated_variations) |
|
189 | + { |
|
190 | + foreach (self::$_registry as $settings) { |
|
191 | + foreach ($settings['variations'] as $messenger) { |
|
192 | + foreach ($messenger as $all_variations) { |
|
193 | + if (isset($all_variations['default'])) { |
|
194 | + throw new EE_Error( |
|
195 | + sprintf( |
|
196 | + esc_html__( |
|
197 | + 'Variations registered through the EE_Register_Messages_Template_Variations api cannot override the default variation for the default template. Please check the code registering variations with this reference, "%s" and modify.', |
|
198 | + 'event_espresso' |
|
199 | + ), |
|
200 | + $identifier |
|
201 | + ) |
|
202 | + ); |
|
203 | + } |
|
204 | + } |
|
205 | + } |
|
206 | + } |
|
207 | 207 | |
208 | - // is there already a variation registered with a given variation slug? |
|
209 | - foreach ($validated_variations['variations'] as $template_pack => $messenger) { |
|
210 | - foreach ($messenger as $message_type => $variations) { |
|
211 | - foreach ($variations as $slug => $label) { |
|
212 | - foreach (self::$_registry as $registered_var => $reg_settings) { |
|
213 | - if (isset($reg_settings['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ])) { |
|
214 | - unset($validated_variations['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ]); |
|
215 | - EE_Error::add_error( |
|
216 | - sprintf( |
|
217 | - esc_html__( |
|
218 | - 'Unable to register the %s variation for the %s template pack with the %s messenger and %s message_type because a variation with this slug was already registered for this template pack and messenger and message type by an addon using this key %s.', |
|
219 | - 'event_espresso' |
|
220 | - ), |
|
221 | - $label, |
|
222 | - $template_pack, |
|
223 | - $messenger, |
|
224 | - $message_type, |
|
225 | - $registered_var |
|
226 | - ) |
|
227 | - ); |
|
228 | - } |
|
229 | - } |
|
230 | - } |
|
231 | - } |
|
232 | - } |
|
233 | - return $validated_variations; |
|
234 | - } |
|
208 | + // is there already a variation registered with a given variation slug? |
|
209 | + foreach ($validated_variations['variations'] as $template_pack => $messenger) { |
|
210 | + foreach ($messenger as $message_type => $variations) { |
|
211 | + foreach ($variations as $slug => $label) { |
|
212 | + foreach (self::$_registry as $registered_var => $reg_settings) { |
|
213 | + if (isset($reg_settings['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ])) { |
|
214 | + unset($validated_variations['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ]); |
|
215 | + EE_Error::add_error( |
|
216 | + sprintf( |
|
217 | + esc_html__( |
|
218 | + 'Unable to register the %s variation for the %s template pack with the %s messenger and %s message_type because a variation with this slug was already registered for this template pack and messenger and message type by an addon using this key %s.', |
|
219 | + 'event_espresso' |
|
220 | + ), |
|
221 | + $label, |
|
222 | + $template_pack, |
|
223 | + $messenger, |
|
224 | + $message_type, |
|
225 | + $registered_var |
|
226 | + ) |
|
227 | + ); |
|
228 | + } |
|
229 | + } |
|
230 | + } |
|
231 | + } |
|
232 | + } |
|
233 | + return $validated_variations; |
|
234 | + } |
|
235 | 235 | |
236 | 236 | |
237 | - /** |
|
238 | - * Callback for the FHEE__EE_Messages_Template_Pack__get_variation filter to ensure registered variations are used. |
|
239 | - * |
|
240 | - * @param string $variation_path The path generated for the current variation |
|
241 | - * @param string $messenger The messenger the variation is for |
|
242 | - * @param string $message_type EE_message_type->name |
|
243 | - * @param string $type The type of variation being requested |
|
244 | - * @param string $variation The slug for the variation being requested |
|
245 | - * @param string $file_extension What the file extension is for the variation |
|
246 | - * @param bool $url Whether url or path is being returned. |
|
247 | - * @param EE_Messages_Template_Pack $template_pack |
|
248 | - * |
|
249 | - * @return string The path to the requested variation. |
|
250 | - * @since 4.5.0 |
|
251 | - * |
|
252 | - */ |
|
253 | - public static function get_variation( |
|
254 | - $variation_path, |
|
255 | - $messenger, |
|
256 | - $message_type, |
|
257 | - $type, |
|
258 | - $variation, |
|
259 | - $file_extension, |
|
260 | - $url, |
|
261 | - EE_Messages_Template_Pack $template_pack |
|
262 | - ) { |
|
263 | - // so let's loop through our registered variations and then pull any details matching the request. |
|
264 | - foreach (self::$_registry as $registry_settings) { |
|
265 | - $base = $url ? $registry_settings['base_url'] : $registry_settings['base_path']; |
|
266 | - $file_string = $messenger . '_' . $type . '_' . $variation . $file_extension; |
|
267 | - // see if this file exists |
|
268 | - if (is_readable($registry_settings['base_path'] . $file_string)) { |
|
269 | - return $base . $file_string; |
|
270 | - } |
|
271 | - } |
|
237 | + /** |
|
238 | + * Callback for the FHEE__EE_Messages_Template_Pack__get_variation filter to ensure registered variations are used. |
|
239 | + * |
|
240 | + * @param string $variation_path The path generated for the current variation |
|
241 | + * @param string $messenger The messenger the variation is for |
|
242 | + * @param string $message_type EE_message_type->name |
|
243 | + * @param string $type The type of variation being requested |
|
244 | + * @param string $variation The slug for the variation being requested |
|
245 | + * @param string $file_extension What the file extension is for the variation |
|
246 | + * @param bool $url Whether url or path is being returned. |
|
247 | + * @param EE_Messages_Template_Pack $template_pack |
|
248 | + * |
|
249 | + * @return string The path to the requested variation. |
|
250 | + * @since 4.5.0 |
|
251 | + * |
|
252 | + */ |
|
253 | + public static function get_variation( |
|
254 | + $variation_path, |
|
255 | + $messenger, |
|
256 | + $message_type, |
|
257 | + $type, |
|
258 | + $variation, |
|
259 | + $file_extension, |
|
260 | + $url, |
|
261 | + EE_Messages_Template_Pack $template_pack |
|
262 | + ) { |
|
263 | + // so let's loop through our registered variations and then pull any details matching the request. |
|
264 | + foreach (self::$_registry as $registry_settings) { |
|
265 | + $base = $url ? $registry_settings['base_url'] : $registry_settings['base_path']; |
|
266 | + $file_string = $messenger . '_' . $type . '_' . $variation . $file_extension; |
|
267 | + // see if this file exists |
|
268 | + if (is_readable($registry_settings['base_path'] . $file_string)) { |
|
269 | + return $base . $file_string; |
|
270 | + } |
|
271 | + } |
|
272 | 272 | |
273 | - // no match |
|
274 | - return $variation_path; |
|
275 | - } |
|
273 | + // no match |
|
274 | + return $variation_path; |
|
275 | + } |
|
276 | 276 | |
277 | 277 | |
278 | - /** |
|
279 | - * callback for the FHEE__EE_Messages_Template_Pack__get_variations filter. |
|
280 | - * |
|
281 | - * |
|
282 | - * @param array $variations The original contents for the template pack variations property. |
|
283 | - * @param string $messenger The messenger requesting the variations. |
|
284 | - * @param string $message_type |
|
285 | - * @param EE_Messages_Template_Pack $template_pack |
|
286 | - * |
|
287 | - * @return array new variations array (or existing one if nothing registered) |
|
288 | - * @since 4.5.0 |
|
289 | - * |
|
290 | - * @see $_variation property definition in EE_Messages_Template_Pack |
|
291 | - */ |
|
292 | - public static function get_variations( |
|
293 | - array $variations, |
|
294 | - $messenger, |
|
295 | - $message_type, |
|
296 | - EE_Messages_Template_Pack $template_pack |
|
297 | - ) { |
|
298 | - // first let's check if we even have registered variations and get out early. |
|
299 | - if (empty(self::$_registry)) { |
|
300 | - return $variations; |
|
301 | - } |
|
278 | + /** |
|
279 | + * callback for the FHEE__EE_Messages_Template_Pack__get_variations filter. |
|
280 | + * |
|
281 | + * |
|
282 | + * @param array $variations The original contents for the template pack variations property. |
|
283 | + * @param string $messenger The messenger requesting the variations. |
|
284 | + * @param string $message_type |
|
285 | + * @param EE_Messages_Template_Pack $template_pack |
|
286 | + * |
|
287 | + * @return array new variations array (or existing one if nothing registered) |
|
288 | + * @since 4.5.0 |
|
289 | + * |
|
290 | + * @see $_variation property definition in EE_Messages_Template_Pack |
|
291 | + */ |
|
292 | + public static function get_variations( |
|
293 | + array $variations, |
|
294 | + $messenger, |
|
295 | + $message_type, |
|
296 | + EE_Messages_Template_Pack $template_pack |
|
297 | + ) { |
|
298 | + // first let's check if we even have registered variations and get out early. |
|
299 | + if (empty(self::$_registry)) { |
|
300 | + return $variations; |
|
301 | + } |
|
302 | 302 | |
303 | - // do we have any new variations for the given messenger, $message_type, and template packs |
|
304 | - foreach (self::$_registry as $registry_settings) { |
|
305 | - // allow for different conditions. |
|
306 | - if (empty($messenger)) { |
|
307 | - return array_merge($registry_settings['variations'], $variations); |
|
308 | - } |
|
309 | - if (empty($message_type)) { |
|
310 | - if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ])) { |
|
311 | - return array_merge( |
|
312 | - $registry_settings['variations'][ $template_pack->dbref ][ $messenger ], |
|
313 | - $variations |
|
314 | - ); |
|
315 | - } |
|
316 | - } else { |
|
317 | - if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ])) { |
|
318 | - return array_merge( |
|
319 | - $registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ], |
|
320 | - $variations |
|
321 | - ); |
|
322 | - } |
|
323 | - } |
|
324 | - } |
|
325 | - return $variations; |
|
326 | - } |
|
303 | + // do we have any new variations for the given messenger, $message_type, and template packs |
|
304 | + foreach (self::$_registry as $registry_settings) { |
|
305 | + // allow for different conditions. |
|
306 | + if (empty($messenger)) { |
|
307 | + return array_merge($registry_settings['variations'], $variations); |
|
308 | + } |
|
309 | + if (empty($message_type)) { |
|
310 | + if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ])) { |
|
311 | + return array_merge( |
|
312 | + $registry_settings['variations'][ $template_pack->dbref ][ $messenger ], |
|
313 | + $variations |
|
314 | + ); |
|
315 | + } |
|
316 | + } else { |
|
317 | + if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ])) { |
|
318 | + return array_merge( |
|
319 | + $registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ], |
|
320 | + $variations |
|
321 | + ); |
|
322 | + } |
|
323 | + } |
|
324 | + } |
|
325 | + return $variations; |
|
326 | + } |
|
327 | 327 | |
328 | 328 | |
329 | - /** |
|
330 | - * This deregisters a variation set that was previously registered with the given slug. |
|
331 | - * |
|
332 | - * @param string $identifier The name for the variation set that was previously registered. |
|
333 | - * |
|
334 | - * @return void |
|
335 | - * @since 4.5.0 |
|
336 | - * |
|
337 | - */ |
|
338 | - public static function deregister($identifier = '') |
|
339 | - { |
|
340 | - unset(self::$_registry[ $identifier ]); |
|
341 | - } |
|
329 | + /** |
|
330 | + * This deregisters a variation set that was previously registered with the given slug. |
|
331 | + * |
|
332 | + * @param string $identifier The name for the variation set that was previously registered. |
|
333 | + * |
|
334 | + * @return void |
|
335 | + * @since 4.5.0 |
|
336 | + * |
|
337 | + */ |
|
338 | + public static function deregister($identifier = '') |
|
339 | + { |
|
340 | + unset(self::$_registry[ $identifier ]); |
|
341 | + } |
|
342 | 342 | } |
@@ -119,13 +119,13 @@ discard block |
||
119 | 119 | } |
120 | 120 | |
121 | 121 | // make sure we don't register twice |
122 | - if (isset(self::$_registry[ $identifier ])) { |
|
122 | + if (isset(self::$_registry[$identifier])) { |
|
123 | 123 | return; |
124 | 124 | } |
125 | 125 | |
126 | 126 | // make sure variation ref is unique. |
127 | - if (isset(self::$_registry[ $identifier ])) { |
|
128 | - $identifier = uniqid() . '_' . $identifier; |
|
127 | + if (isset(self::$_registry[$identifier])) { |
|
128 | + $identifier = uniqid().'_'.$identifier; |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | |
158 | 158 | // check that no reserved variation names are in use and also checks if there are already existing variation names for a given template pack. The former will throw an error. The latter will remove the conflicting variation name but still register the others and will add EE_Error notice. |
159 | 159 | $validated = self::_verify_variations($identifier, $validated); |
160 | - self::$_registry[ $identifier ] = $validated; |
|
160 | + self::$_registry[$identifier] = $validated; |
|
161 | 161 | |
162 | 162 | add_filter( |
163 | 163 | 'FHEE__EE_Messages_Template_Pack__get_variations', |
@@ -210,8 +210,8 @@ discard block |
||
210 | 210 | foreach ($messenger as $message_type => $variations) { |
211 | 211 | foreach ($variations as $slug => $label) { |
212 | 212 | foreach (self::$_registry as $registered_var => $reg_settings) { |
213 | - if (isset($reg_settings['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ])) { |
|
214 | - unset($validated_variations['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ]); |
|
213 | + if (isset($reg_settings['variations'][$template_pack][$messenger][$message_type][$slug])) { |
|
214 | + unset($validated_variations['variations'][$template_pack][$messenger][$message_type][$slug]); |
|
215 | 215 | EE_Error::add_error( |
216 | 216 | sprintf( |
217 | 217 | esc_html__( |
@@ -263,10 +263,10 @@ discard block |
||
263 | 263 | // so let's loop through our registered variations and then pull any details matching the request. |
264 | 264 | foreach (self::$_registry as $registry_settings) { |
265 | 265 | $base = $url ? $registry_settings['base_url'] : $registry_settings['base_path']; |
266 | - $file_string = $messenger . '_' . $type . '_' . $variation . $file_extension; |
|
266 | + $file_string = $messenger.'_'.$type.'_'.$variation.$file_extension; |
|
267 | 267 | // see if this file exists |
268 | - if (is_readable($registry_settings['base_path'] . $file_string)) { |
|
269 | - return $base . $file_string; |
|
268 | + if (is_readable($registry_settings['base_path'].$file_string)) { |
|
269 | + return $base.$file_string; |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | |
@@ -307,16 +307,16 @@ discard block |
||
307 | 307 | return array_merge($registry_settings['variations'], $variations); |
308 | 308 | } |
309 | 309 | if (empty($message_type)) { |
310 | - if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ])) { |
|
310 | + if ( ! empty($registry_settings['variations'][$template_pack->dbref][$messenger])) { |
|
311 | 311 | return array_merge( |
312 | - $registry_settings['variations'][ $template_pack->dbref ][ $messenger ], |
|
312 | + $registry_settings['variations'][$template_pack->dbref][$messenger], |
|
313 | 313 | $variations |
314 | 314 | ); |
315 | 315 | } |
316 | 316 | } else { |
317 | - if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ])) { |
|
317 | + if ( ! empty($registry_settings['variations'][$template_pack->dbref][$messenger][$message_type])) { |
|
318 | 318 | return array_merge( |
319 | - $registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ], |
|
319 | + $registry_settings['variations'][$template_pack->dbref][$messenger][$message_type], |
|
320 | 320 | $variations |
321 | 321 | ); |
322 | 322 | } |
@@ -337,6 +337,6 @@ discard block |
||
337 | 337 | */ |
338 | 338 | public static function deregister($identifier = '') |
339 | 339 | { |
340 | - unset(self::$_registry[ $identifier ]); |
|
340 | + unset(self::$_registry[$identifier]); |
|
341 | 341 | } |
342 | 342 | } |
@@ -15,214 +15,214 @@ |
||
15 | 15 | class EE_Register_Capabilities implements EEI_Plugin_API |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Holds the settings for a specific registration. |
|
20 | - * |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected static $_registry = []; |
|
18 | + /** |
|
19 | + * Holds the settings for a specific registration. |
|
20 | + * |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected static $_registry = []; |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * Used to register capability items with EE core. |
|
28 | - * |
|
29 | - * @param string $identifier usually will be a class name |
|
30 | - * that references capability |
|
31 | - * related items setup for |
|
32 | - * something. |
|
33 | - * @param array $setup_args { |
|
34 | - * An array of items related to |
|
35 | - * registering capabilities. |
|
36 | - * @type array $capabilities An array mapping capability |
|
37 | - * strings to core WP Role. |
|
38 | - * Something like: array( |
|
39 | - * 'administrator' => array( |
|
40 | - * 'read_cap', 'edit_cap', |
|
41 | - * 'delete_cap'), |
|
42 | - * 'author' => |
|
43 | - * array( 'read_cap' ) |
|
44 | - * ). |
|
45 | - * @type array $capability_maps EE_Meta_Capability_Map[] |
|
46 | - * @return void |
|
47 | - * @throws EE_Error |
|
48 | - * @since 4.5.0 |
|
49 | - * @see EE_Capabilities.php for php docs on these objects. |
|
50 | - * Should be indexed by the |
|
51 | - * classname for the capability |
|
52 | - * map and values representing |
|
53 | - * the arguments for the map. |
|
54 | - * } |
|
55 | - */ |
|
56 | - public static function register($identifier = '', array $setup_args = []) |
|
57 | - { |
|
58 | - // required fields MUST be present, so let's make sure they are. |
|
59 | - if ($identifier === null || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
60 | - throw new EE_Error( |
|
61 | - esc_html__( |
|
62 | - 'In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', |
|
63 | - 'event_espresso' |
|
64 | - ) |
|
65 | - ); |
|
66 | - } |
|
67 | - // make sure we don't register twice |
|
68 | - if (isset(self::$_registry[ $identifier ])) { |
|
69 | - return; |
|
70 | - } |
|
71 | - // make sure this is not registered too late or too early. |
|
72 | - if ( |
|
73 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
74 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
75 | - ) { |
|
76 | - EE_Error::doing_it_wrong( |
|
77 | - __METHOD__, |
|
78 | - sprintf( |
|
79 | - esc_html__( |
|
80 | - '%s has been registered too late. Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', |
|
81 | - 'event_espresso' |
|
82 | - ), |
|
83 | - $identifier |
|
84 | - ), |
|
85 | - '4.5.0' |
|
86 | - ); |
|
87 | - } |
|
88 | - // some preliminary sanitization and setting to the $_registry property |
|
89 | - self::$_registry[ $identifier ] = [ |
|
90 | - 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) |
|
91 | - ? $setup_args['capabilities'] |
|
92 | - : [], |
|
93 | - 'cap_maps' => isset($setup_args['capability_maps']) ? $setup_args['capability_maps'] : [], |
|
94 | - ]; |
|
95 | - // set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once) |
|
96 | - add_filter( |
|
97 | - 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
98 | - ['EE_Register_Capabilities', 'register_capabilities'] |
|
99 | - ); |
|
100 | - // add filter for cap maps |
|
101 | - add_filter( |
|
102 | - 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
103 | - ['EE_Register_Capabilities', 'register_cap_maps'] |
|
104 | - ); |
|
105 | - } |
|
26 | + /** |
|
27 | + * Used to register capability items with EE core. |
|
28 | + * |
|
29 | + * @param string $identifier usually will be a class name |
|
30 | + * that references capability |
|
31 | + * related items setup for |
|
32 | + * something. |
|
33 | + * @param array $setup_args { |
|
34 | + * An array of items related to |
|
35 | + * registering capabilities. |
|
36 | + * @type array $capabilities An array mapping capability |
|
37 | + * strings to core WP Role. |
|
38 | + * Something like: array( |
|
39 | + * 'administrator' => array( |
|
40 | + * 'read_cap', 'edit_cap', |
|
41 | + * 'delete_cap'), |
|
42 | + * 'author' => |
|
43 | + * array( 'read_cap' ) |
|
44 | + * ). |
|
45 | + * @type array $capability_maps EE_Meta_Capability_Map[] |
|
46 | + * @return void |
|
47 | + * @throws EE_Error |
|
48 | + * @since 4.5.0 |
|
49 | + * @see EE_Capabilities.php for php docs on these objects. |
|
50 | + * Should be indexed by the |
|
51 | + * classname for the capability |
|
52 | + * map and values representing |
|
53 | + * the arguments for the map. |
|
54 | + * } |
|
55 | + */ |
|
56 | + public static function register($identifier = '', array $setup_args = []) |
|
57 | + { |
|
58 | + // required fields MUST be present, so let's make sure they are. |
|
59 | + if ($identifier === null || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
60 | + throw new EE_Error( |
|
61 | + esc_html__( |
|
62 | + 'In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', |
|
63 | + 'event_espresso' |
|
64 | + ) |
|
65 | + ); |
|
66 | + } |
|
67 | + // make sure we don't register twice |
|
68 | + if (isset(self::$_registry[ $identifier ])) { |
|
69 | + return; |
|
70 | + } |
|
71 | + // make sure this is not registered too late or too early. |
|
72 | + if ( |
|
73 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
74 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
75 | + ) { |
|
76 | + EE_Error::doing_it_wrong( |
|
77 | + __METHOD__, |
|
78 | + sprintf( |
|
79 | + esc_html__( |
|
80 | + '%s has been registered too late. Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', |
|
81 | + 'event_espresso' |
|
82 | + ), |
|
83 | + $identifier |
|
84 | + ), |
|
85 | + '4.5.0' |
|
86 | + ); |
|
87 | + } |
|
88 | + // some preliminary sanitization and setting to the $_registry property |
|
89 | + self::$_registry[ $identifier ] = [ |
|
90 | + 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) |
|
91 | + ? $setup_args['capabilities'] |
|
92 | + : [], |
|
93 | + 'cap_maps' => isset($setup_args['capability_maps']) ? $setup_args['capability_maps'] : [], |
|
94 | + ]; |
|
95 | + // set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once) |
|
96 | + add_filter( |
|
97 | + 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
98 | + ['EE_Register_Capabilities', 'register_capabilities'] |
|
99 | + ); |
|
100 | + // add filter for cap maps |
|
101 | + add_filter( |
|
102 | + 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
103 | + ['EE_Register_Capabilities', 'register_cap_maps'] |
|
104 | + ); |
|
105 | + } |
|
106 | 106 | |
107 | 107 | |
108 | - /** |
|
109 | - * callback for FHEE__EE_Capabilities__init_caps_map__caps filter. |
|
110 | - * Takes care of registering additional capabilities to the caps map. Note, that this also on the initial |
|
111 | - * registration ensures that new capabilities are added to existing roles. |
|
112 | - * |
|
113 | - * @param array $incoming_caps The original caps map. |
|
114 | - * @return array merged in new caps. |
|
115 | - */ |
|
116 | - public static function register_capabilities(array $incoming_caps) |
|
117 | - { |
|
118 | - foreach (self::$_registry as $caps_and_cap_map) { |
|
119 | - $incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']); |
|
120 | - } |
|
121 | - return $incoming_caps; |
|
122 | - } |
|
108 | + /** |
|
109 | + * callback for FHEE__EE_Capabilities__init_caps_map__caps filter. |
|
110 | + * Takes care of registering additional capabilities to the caps map. Note, that this also on the initial |
|
111 | + * registration ensures that new capabilities are added to existing roles. |
|
112 | + * |
|
113 | + * @param array $incoming_caps The original caps map. |
|
114 | + * @return array merged in new caps. |
|
115 | + */ |
|
116 | + public static function register_capabilities(array $incoming_caps) |
|
117 | + { |
|
118 | + foreach (self::$_registry as $caps_and_cap_map) { |
|
119 | + $incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']); |
|
120 | + } |
|
121 | + return $incoming_caps; |
|
122 | + } |
|
123 | 123 | |
124 | 124 | |
125 | - /** |
|
126 | - * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of |
|
127 | - * capability maps for the WP meta_caps filter called in EE_Capabilities. |
|
128 | - * |
|
129 | - * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array. |
|
130 | - * @return EE_Meta_Capability_Map[] |
|
131 | - * @throws EE_Error |
|
132 | - * @since 4.5.0 |
|
133 | - */ |
|
134 | - public static function register_cap_maps(array $cap_maps) |
|
135 | - { |
|
136 | - // loop through and instantiate cap maps. |
|
137 | - foreach (self::$_registry as $identifier => $setup) { |
|
138 | - if (! isset($setup['cap_maps'])) { |
|
139 | - continue; |
|
140 | - } |
|
141 | - foreach ($setup['cap_maps'] as $cap_class => $args) { |
|
125 | + /** |
|
126 | + * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of |
|
127 | + * capability maps for the WP meta_caps filter called in EE_Capabilities. |
|
128 | + * |
|
129 | + * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array. |
|
130 | + * @return EE_Meta_Capability_Map[] |
|
131 | + * @throws EE_Error |
|
132 | + * @since 4.5.0 |
|
133 | + */ |
|
134 | + public static function register_cap_maps(array $cap_maps) |
|
135 | + { |
|
136 | + // loop through and instantiate cap maps. |
|
137 | + foreach (self::$_registry as $identifier => $setup) { |
|
138 | + if (! isset($setup['cap_maps'])) { |
|
139 | + continue; |
|
140 | + } |
|
141 | + foreach ($setup['cap_maps'] as $cap_class => $args) { |
|
142 | 142 | |
143 | - /** |
|
144 | - * account for cases where capability maps may be indexed |
|
145 | - * numerically to allow for the same map class to be utilized |
|
146 | - * In those cases, maps will be setup in an array like: |
|
147 | - * array( |
|
148 | - * 0 => array( 'EE_Meta_Capability' => array( |
|
149 | - * 'ee_edit_cap', array( 'Object_Name', |
|
150 | - * 'ee_edit_published_cap', |
|
151 | - * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
152 | - * ) ) |
|
153 | - * 1 => ... |
|
154 | - * ) |
|
155 | - * instead of: |
|
156 | - * array( |
|
157 | - * 'EE_Meta_Capability' => array( |
|
158 | - * 'ee_edit_cap', array( 'Object_Name', |
|
159 | - * 'ee_edit_published_cap', |
|
160 | - * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
161 | - * ), |
|
162 | - * ... |
|
163 | - * ) |
|
164 | - */ |
|
165 | - if (is_numeric($cap_class)) { |
|
166 | - $cap_class = key($args); |
|
167 | - $args = $args[ $cap_class ]; |
|
168 | - } |
|
143 | + /** |
|
144 | + * account for cases where capability maps may be indexed |
|
145 | + * numerically to allow for the same map class to be utilized |
|
146 | + * In those cases, maps will be setup in an array like: |
|
147 | + * array( |
|
148 | + * 0 => array( 'EE_Meta_Capability' => array( |
|
149 | + * 'ee_edit_cap', array( 'Object_Name', |
|
150 | + * 'ee_edit_published_cap', |
|
151 | + * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
152 | + * ) ) |
|
153 | + * 1 => ... |
|
154 | + * ) |
|
155 | + * instead of: |
|
156 | + * array( |
|
157 | + * 'EE_Meta_Capability' => array( |
|
158 | + * 'ee_edit_cap', array( 'Object_Name', |
|
159 | + * 'ee_edit_published_cap', |
|
160 | + * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
161 | + * ), |
|
162 | + * ... |
|
163 | + * ) |
|
164 | + */ |
|
165 | + if (is_numeric($cap_class)) { |
|
166 | + $cap_class = key($args); |
|
167 | + $args = $args[ $cap_class ]; |
|
168 | + } |
|
169 | 169 | |
170 | - if (! class_exists($cap_class)) { |
|
171 | - throw new EE_Error( |
|
172 | - sprintf( |
|
173 | - esc_html__( |
|
174 | - 'An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments', |
|
175 | - 'event_espresso' |
|
176 | - ), |
|
177 | - $identifier |
|
178 | - ) |
|
179 | - ); |
|
180 | - } |
|
170 | + if (! class_exists($cap_class)) { |
|
171 | + throw new EE_Error( |
|
172 | + sprintf( |
|
173 | + esc_html__( |
|
174 | + 'An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments', |
|
175 | + 'event_espresso' |
|
176 | + ), |
|
177 | + $identifier |
|
178 | + ) |
|
179 | + ); |
|
180 | + } |
|
181 | 181 | |
182 | - if (count($args) !== 2) { |
|
183 | - throw new EE_Error( |
|
184 | - sprintf( |
|
185 | - esc_html__( |
|
186 | - 'An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments. The array should have two values the first being a string and the second an array.', |
|
187 | - 'event_espresso' |
|
188 | - ), |
|
189 | - $identifier |
|
190 | - ) |
|
191 | - ); |
|
192 | - } |
|
193 | - $cap_maps[] = new $cap_class($args[0], $args[1]); |
|
194 | - } |
|
195 | - } |
|
196 | - return $cap_maps; |
|
197 | - } |
|
182 | + if (count($args) !== 2) { |
|
183 | + throw new EE_Error( |
|
184 | + sprintf( |
|
185 | + esc_html__( |
|
186 | + 'An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments. The array should have two values the first being a string and the second an array.', |
|
187 | + 'event_espresso' |
|
188 | + ), |
|
189 | + $identifier |
|
190 | + ) |
|
191 | + ); |
|
192 | + } |
|
193 | + $cap_maps[] = new $cap_class($args[0], $args[1]); |
|
194 | + } |
|
195 | + } |
|
196 | + return $cap_maps; |
|
197 | + } |
|
198 | 198 | |
199 | 199 | |
200 | - /** |
|
201 | - * @param string $identifier |
|
202 | - * @throws InvalidArgumentException |
|
203 | - * @throws InvalidDataTypeException |
|
204 | - * @throws InvalidInterfaceException |
|
205 | - */ |
|
206 | - public static function deregister($identifier = '') |
|
207 | - { |
|
208 | - if (! empty(self::$_registry[ $identifier ])) { |
|
209 | - if (! empty(self::$_registry[ $identifier ]['caps'])) { |
|
210 | - // if it's too early to remove capabilities, wait to do this until core is loaded and ready |
|
211 | - $caps_to_remove = self::$_registry[ $identifier ]['caps']; |
|
212 | - if (did_action('AHEE__EE_System__core_loaded_and_ready')) { |
|
213 | - $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
214 | - $capabilities->removeCaps($caps_to_remove); |
|
215 | - } else { |
|
216 | - add_action( |
|
217 | - 'AHEE__EE_System__core_loaded_and_ready', |
|
218 | - function () use ($caps_to_remove) { |
|
219 | - $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
220 | - $capabilities->removeCaps($caps_to_remove); |
|
221 | - } |
|
222 | - ); |
|
223 | - } |
|
224 | - } |
|
225 | - } |
|
226 | - unset(self::$_registry[ $identifier ]); |
|
227 | - } |
|
200 | + /** |
|
201 | + * @param string $identifier |
|
202 | + * @throws InvalidArgumentException |
|
203 | + * @throws InvalidDataTypeException |
|
204 | + * @throws InvalidInterfaceException |
|
205 | + */ |
|
206 | + public static function deregister($identifier = '') |
|
207 | + { |
|
208 | + if (! empty(self::$_registry[ $identifier ])) { |
|
209 | + if (! empty(self::$_registry[ $identifier ]['caps'])) { |
|
210 | + // if it's too early to remove capabilities, wait to do this until core is loaded and ready |
|
211 | + $caps_to_remove = self::$_registry[ $identifier ]['caps']; |
|
212 | + if (did_action('AHEE__EE_System__core_loaded_and_ready')) { |
|
213 | + $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
214 | + $capabilities->removeCaps($caps_to_remove); |
|
215 | + } else { |
|
216 | + add_action( |
|
217 | + 'AHEE__EE_System__core_loaded_and_ready', |
|
218 | + function () use ($caps_to_remove) { |
|
219 | + $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
220 | + $capabilities->removeCaps($caps_to_remove); |
|
221 | + } |
|
222 | + ); |
|
223 | + } |
|
224 | + } |
|
225 | + } |
|
226 | + unset(self::$_registry[ $identifier ]); |
|
227 | + } |
|
228 | 228 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | ); |
66 | 66 | } |
67 | 67 | // make sure we don't register twice |
68 | - if (isset(self::$_registry[ $identifier ])) { |
|
68 | + if (isset(self::$_registry[$identifier])) { |
|
69 | 69 | return; |
70 | 70 | } |
71 | 71 | // make sure this is not registered too late or too early. |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | ); |
87 | 87 | } |
88 | 88 | // some preliminary sanitization and setting to the $_registry property |
89 | - self::$_registry[ $identifier ] = [ |
|
89 | + self::$_registry[$identifier] = [ |
|
90 | 90 | 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) |
91 | 91 | ? $setup_args['capabilities'] |
92 | 92 | : [], |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | { |
136 | 136 | // loop through and instantiate cap maps. |
137 | 137 | foreach (self::$_registry as $identifier => $setup) { |
138 | - if (! isset($setup['cap_maps'])) { |
|
138 | + if ( ! isset($setup['cap_maps'])) { |
|
139 | 139 | continue; |
140 | 140 | } |
141 | 141 | foreach ($setup['cap_maps'] as $cap_class => $args) { |
@@ -164,10 +164,10 @@ discard block |
||
164 | 164 | */ |
165 | 165 | if (is_numeric($cap_class)) { |
166 | 166 | $cap_class = key($args); |
167 | - $args = $args[ $cap_class ]; |
|
167 | + $args = $args[$cap_class]; |
|
168 | 168 | } |
169 | 169 | |
170 | - if (! class_exists($cap_class)) { |
|
170 | + if ( ! class_exists($cap_class)) { |
|
171 | 171 | throw new EE_Error( |
172 | 172 | sprintf( |
173 | 173 | esc_html__( |
@@ -205,17 +205,17 @@ discard block |
||
205 | 205 | */ |
206 | 206 | public static function deregister($identifier = '') |
207 | 207 | { |
208 | - if (! empty(self::$_registry[ $identifier ])) { |
|
209 | - if (! empty(self::$_registry[ $identifier ]['caps'])) { |
|
208 | + if ( ! empty(self::$_registry[$identifier])) { |
|
209 | + if ( ! empty(self::$_registry[$identifier]['caps'])) { |
|
210 | 210 | // if it's too early to remove capabilities, wait to do this until core is loaded and ready |
211 | - $caps_to_remove = self::$_registry[ $identifier ]['caps']; |
|
211 | + $caps_to_remove = self::$_registry[$identifier]['caps']; |
|
212 | 212 | if (did_action('AHEE__EE_System__core_loaded_and_ready')) { |
213 | 213 | $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
214 | 214 | $capabilities->removeCaps($caps_to_remove); |
215 | 215 | } else { |
216 | 216 | add_action( |
217 | 217 | 'AHEE__EE_System__core_loaded_and_ready', |
218 | - function () use ($caps_to_remove) { |
|
218 | + function() use ($caps_to_remove) { |
|
219 | 219 | $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
220 | 220 | $capabilities->removeCaps($caps_to_remove); |
221 | 221 | } |
@@ -223,6 +223,6 @@ discard block |
||
223 | 223 | } |
224 | 224 | } |
225 | 225 | } |
226 | - unset(self::$_registry[ $identifier ]); |
|
226 | + unset(self::$_registry[$identifier]); |
|
227 | 227 | } |
228 | 228 | } |
@@ -12,114 +12,114 @@ |
||
12 | 12 | class EE_Register_Config implements EEI_Plugin_API |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Holds registered EE_Config items |
|
17 | - * |
|
18 | - * @var array |
|
19 | - */ |
|
20 | - protected static $_ee_config_registry = []; |
|
15 | + /** |
|
16 | + * Holds registered EE_Config items |
|
17 | + * |
|
18 | + * @var array |
|
19 | + */ |
|
20 | + protected static $_ee_config_registry = []; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * Handles registering the new config with the EE_Config::instance()->addons property |
|
25 | - * |
|
26 | - * @param string $identifier The name of the Config class being registered. |
|
27 | - * Note this class must extend EE_Config Base and must have |
|
28 | - * already been registered with an autoloader. |
|
29 | - * @param array $setup_args { |
|
30 | - * |
|
31 | - * @type string $config_name Optional. by default the new config will be registered to |
|
32 | - * EE_Config::instance()->addons->{config_class}, but supplying a "config_name" will set the property name |
|
33 | - * that this variable is accessible by. ie: EE_Config::instance()->addons->{config_name} |
|
34 | - * } |
|
35 | - * @return void |
|
36 | - * @throws EE_Error |
|
37 | - * |
|
38 | - * @since 4.3.0 |
|
39 | - */ |
|
40 | - public static function register($identifier = '', array $setup_args = []) |
|
41 | - { |
|
23 | + /** |
|
24 | + * Handles registering the new config with the EE_Config::instance()->addons property |
|
25 | + * |
|
26 | + * @param string $identifier The name of the Config class being registered. |
|
27 | + * Note this class must extend EE_Config Base and must have |
|
28 | + * already been registered with an autoloader. |
|
29 | + * @param array $setup_args { |
|
30 | + * |
|
31 | + * @type string $config_name Optional. by default the new config will be registered to |
|
32 | + * EE_Config::instance()->addons->{config_class}, but supplying a "config_name" will set the property name |
|
33 | + * that this variable is accessible by. ie: EE_Config::instance()->addons->{config_name} |
|
34 | + * } |
|
35 | + * @return void |
|
36 | + * @throws EE_Error |
|
37 | + * |
|
38 | + * @since 4.3.0 |
|
39 | + */ |
|
40 | + public static function register($identifier = '', array $setup_args = []) |
|
41 | + { |
|
42 | 42 | |
43 | - $setup_args['config_name'] = isset($setup_args['config_name']) && ! empty($setup_args['config_name']) |
|
44 | - ? $setup_args['config_name'] : $identifier; |
|
45 | - $setup_args['config_section'] = isset($setup_args['config_section']) && ! empty($setup_args['config_section']) |
|
46 | - ? $setup_args['config_section'] : 'addons'; |
|
43 | + $setup_args['config_name'] = isset($setup_args['config_name']) && ! empty($setup_args['config_name']) |
|
44 | + ? $setup_args['config_name'] : $identifier; |
|
45 | + $setup_args['config_section'] = isset($setup_args['config_section']) && ! empty($setup_args['config_section']) |
|
46 | + ? $setup_args['config_section'] : 'addons'; |
|
47 | 47 | |
48 | - // required fields MUST be present, so let's make sure they are. |
|
49 | - if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['config_name'])) { |
|
50 | - throw new EE_Error( |
|
51 | - esc_html__( |
|
52 | - 'In order to register a Config Class with EE_Register_Config::register(), you must include a "config_class" (the actual class name for this config class). As well, you can supply an array containing the following keys: "config_section" the main section of the config object the settings will be saved under (by default the new config will be registered under EE_Config::instance()->modules or EE_Config::instance()->addons depending on what type of class is calling this), "config_name" (by default the new config will be registered to EE_Config::instance()->{config_section}->{config_class}, but supplying a "config_name" will set the property name that this variable is accessible by. ie: EE_Config::instance()->{config_section}->{config_name})', |
|
53 | - 'event_espresso' |
|
54 | - ) |
|
55 | - ); |
|
56 | - } |
|
48 | + // required fields MUST be present, so let's make sure they are. |
|
49 | + if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['config_name'])) { |
|
50 | + throw new EE_Error( |
|
51 | + esc_html__( |
|
52 | + 'In order to register a Config Class with EE_Register_Config::register(), you must include a "config_class" (the actual class name for this config class). As well, you can supply an array containing the following keys: "config_section" the main section of the config object the settings will be saved under (by default the new config will be registered under EE_Config::instance()->modules or EE_Config::instance()->addons depending on what type of class is calling this), "config_name" (by default the new config will be registered to EE_Config::instance()->{config_section}->{config_class}, but supplying a "config_name" will set the property name that this variable is accessible by. ie: EE_Config::instance()->{config_section}->{config_name})', |
|
53 | + 'event_espresso' |
|
54 | + ) |
|
55 | + ); |
|
56 | + } |
|
57 | 57 | |
58 | - // make sure we don't register twice |
|
59 | - if (isset(self::$_ee_config_registry[ $identifier ])) { |
|
60 | - return; |
|
61 | - } |
|
58 | + // make sure we don't register twice |
|
59 | + if (isset(self::$_ee_config_registry[ $identifier ])) { |
|
60 | + return; |
|
61 | + } |
|
62 | 62 | |
63 | 63 | |
64 | - // first find out if this happened too late. |
|
65 | - if (did_action('AHEE__EE_System__load_core_configuration__begin')) { |
|
66 | - EE_Error::doing_it_wrong( |
|
67 | - __METHOD__, |
|
68 | - sprintf( |
|
69 | - esc_html__( |
|
70 | - 'An attempt to register "%s" as an EE_Config object has failed because it was not registered at the correct hookpoint. Please register before the "AHEE__EE_System__load_core_configuration__begin" hook has fired', |
|
71 | - 'event_espresso' |
|
72 | - ), |
|
73 | - $setup_args['config_name'] |
|
74 | - ), |
|
75 | - '4.3' |
|
76 | - ); |
|
77 | - } |
|
78 | - // add incoming stuff to our registry property |
|
79 | - self::$_ee_config_registry[ $identifier ] = [ |
|
80 | - 'section' => $setup_args['config_section'], |
|
81 | - 'name' => $setup_args['config_name'], |
|
82 | - ]; |
|
64 | + // first find out if this happened too late. |
|
65 | + if (did_action('AHEE__EE_System__load_core_configuration__begin')) { |
|
66 | + EE_Error::doing_it_wrong( |
|
67 | + __METHOD__, |
|
68 | + sprintf( |
|
69 | + esc_html__( |
|
70 | + 'An attempt to register "%s" as an EE_Config object has failed because it was not registered at the correct hookpoint. Please register before the "AHEE__EE_System__load_core_configuration__begin" hook has fired', |
|
71 | + 'event_espresso' |
|
72 | + ), |
|
73 | + $setup_args['config_name'] |
|
74 | + ), |
|
75 | + '4.3' |
|
76 | + ); |
|
77 | + } |
|
78 | + // add incoming stuff to our registry property |
|
79 | + self::$_ee_config_registry[ $identifier ] = [ |
|
80 | + 'section' => $setup_args['config_section'], |
|
81 | + 'name' => $setup_args['config_name'], |
|
82 | + ]; |
|
83 | 83 | |
84 | - add_action('AHEE__EE_Config___load_core_config__end', ['EE_Register_Config', 'set_config'], 15, 1); |
|
85 | - add_action('AHEE__EE_Config__update_espresso_config__end', ['EE_Register_Config', 'set_config'], 15, 1); |
|
86 | - } |
|
84 | + add_action('AHEE__EE_Config___load_core_config__end', ['EE_Register_Config', 'set_config'], 15, 1); |
|
85 | + add_action('AHEE__EE_Config__update_espresso_config__end', ['EE_Register_Config', 'set_config'], 15, 1); |
|
86 | + } |
|
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * Callback for the AHEE__EE_Config___load_core_config__end hook. |
|
91 | - * basically just calls EE_Config->get_config() which will take care of loading or creating our config object for us |
|
92 | - * |
|
93 | - * @param EE_Config $EE_Config |
|
94 | - * @return void |
|
95 | - * @throws EE_Error |
|
96 | - * @since 4.3.0 |
|
97 | - */ |
|
98 | - public static function set_config(EE_Config $EE_Config) |
|
99 | - { |
|
100 | - foreach (self::$_ee_config_registry as $identifier => $settings) { |
|
101 | - // first some validation of our incoming class_name. We'll throw an error early if its' not registered correctly |
|
102 | - if (! class_exists($identifier)) { |
|
103 | - throw new EE_Error( |
|
104 | - sprintf( |
|
105 | - esc_html__( |
|
106 | - 'The "%s" config class can not be registered with EE_Config because it does not exist. Verify that an autoloader has been set for this class', |
|
107 | - 'event_espresso' |
|
108 | - ), |
|
109 | - $identifier |
|
110 | - ) |
|
111 | - ); |
|
112 | - } |
|
113 | - $EE_Config->get_config($settings['section'], $settings['name'], $identifier); |
|
114 | - } |
|
115 | - } |
|
89 | + /** |
|
90 | + * Callback for the AHEE__EE_Config___load_core_config__end hook. |
|
91 | + * basically just calls EE_Config->get_config() which will take care of loading or creating our config object for us |
|
92 | + * |
|
93 | + * @param EE_Config $EE_Config |
|
94 | + * @return void |
|
95 | + * @throws EE_Error |
|
96 | + * @since 4.3.0 |
|
97 | + */ |
|
98 | + public static function set_config(EE_Config $EE_Config) |
|
99 | + { |
|
100 | + foreach (self::$_ee_config_registry as $identifier => $settings) { |
|
101 | + // first some validation of our incoming class_name. We'll throw an error early if its' not registered correctly |
|
102 | + if (! class_exists($identifier)) { |
|
103 | + throw new EE_Error( |
|
104 | + sprintf( |
|
105 | + esc_html__( |
|
106 | + 'The "%s" config class can not be registered with EE_Config because it does not exist. Verify that an autoloader has been set for this class', |
|
107 | + 'event_espresso' |
|
108 | + ), |
|
109 | + $identifier |
|
110 | + ) |
|
111 | + ); |
|
112 | + } |
|
113 | + $EE_Config->get_config($settings['section'], $settings['name'], $identifier); |
|
114 | + } |
|
115 | + } |
|
116 | 116 | |
117 | 117 | |
118 | - /** |
|
119 | - * @param string $identifier |
|
120 | - */ |
|
121 | - public static function deregister($identifier = '') |
|
122 | - { |
|
123 | - unset(self::$_ee_config_registry[ $identifier ]); |
|
124 | - } |
|
118 | + /** |
|
119 | + * @param string $identifier |
|
120 | + */ |
|
121 | + public static function deregister($identifier = '') |
|
122 | + { |
|
123 | + unset(self::$_ee_config_registry[ $identifier ]); |
|
124 | + } |
|
125 | 125 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | // make sure we don't register twice |
59 | - if (isset(self::$_ee_config_registry[ $identifier ])) { |
|
59 | + if (isset(self::$_ee_config_registry[$identifier])) { |
|
60 | 60 | return; |
61 | 61 | } |
62 | 62 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | ); |
77 | 77 | } |
78 | 78 | // add incoming stuff to our registry property |
79 | - self::$_ee_config_registry[ $identifier ] = [ |
|
79 | + self::$_ee_config_registry[$identifier] = [ |
|
80 | 80 | 'section' => $setup_args['config_section'], |
81 | 81 | 'name' => $setup_args['config_name'], |
82 | 82 | ]; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | { |
100 | 100 | foreach (self::$_ee_config_registry as $identifier => $settings) { |
101 | 101 | // first some validation of our incoming class_name. We'll throw an error early if its' not registered correctly |
102 | - if (! class_exists($identifier)) { |
|
102 | + if ( ! class_exists($identifier)) { |
|
103 | 103 | throw new EE_Error( |
104 | 104 | sprintf( |
105 | 105 | esc_html__( |
@@ -120,6 +120,6 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public static function deregister($identifier = '') |
122 | 122 | { |
123 | - unset(self::$_ee_config_registry[ $identifier ]); |
|
123 | + unset(self::$_ee_config_registry[$identifier]); |
|
124 | 124 | } |
125 | 125 | } |