@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | ) { |
120 | 120 | // TO approved |
121 | 121 | if ( $new_STS_ID === EEM_Registration::status_id_approved ) { |
122 | - \EEH_Debug_Tools::printr(__FUNCTION__, 'BEFORE HOOK ' . __CLASS__, __FILE__, __LINE__, 2); |
|
123 | - // reserve a space by incrementing ticket and datetime sold values |
|
122 | + \EEH_Debug_Tools::printr(__FUNCTION__, 'BEFORE HOOK ' . __CLASS__, __FILE__, __LINE__, 2); |
|
123 | + // reserve a space by incrementing ticket and datetime sold values |
|
124 | 124 | $this->_reserve_registration_space(); |
125 | 125 | do_action( 'AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID ); |
126 | - \EEH_Debug_Tools::printr(__FUNCTION__, 'AFTER HOOK ' . __CLASS__, __FILE__, __LINE__, 2); |
|
126 | + \EEH_Debug_Tools::printr(__FUNCTION__, 'AFTER HOOK ' . __CLASS__, __FILE__, __LINE__, 2); |
|
127 | 127 | exit(); |
128 | 128 | // OR FROM approved |
129 | 129 | } else if ( $old_STS_ID === EEM_Registration::status_id_approved ) { |
@@ -648,9 +648,9 @@ discard block |
||
648 | 648 | |
649 | 649 | |
650 | 650 | /** |
651 | - * get Attendee Number |
|
652 | - * @access public |
|
653 | - */ |
|
651 | + * get Attendee Number |
|
652 | + * @access public |
|
653 | + */ |
|
654 | 654 | public function count() { |
655 | 655 | return $this->get( 'REG_count' ); |
656 | 656 | } |
@@ -1032,20 +1032,20 @@ discard block |
||
1032 | 1032 | |
1033 | 1033 | |
1034 | 1034 | |
1035 | - /** |
|
1036 | - * toggle Check-in status for this registration |
|
1037 | - * Check-ins are toggled in the following order: |
|
1038 | - * never checked in -> checked in |
|
1039 | - * checked in -> checked out |
|
1040 | - * checked out -> checked in |
|
1041 | - * |
|
1042 | - * @param int $DTT_ID include specific datetime to toggle Check-in for. |
|
1043 | - * If not included or null, then it is assumed latest datetime is being toggled. |
|
1044 | - * @param bool $verify If true then can_checkin() is used to verify whether the person |
|
1045 | - * can be checked in or not. Otherwise this forces change in checkin status. |
|
1046 | - * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
|
1047 | - * @throws EE_Error |
|
1048 | - */ |
|
1035 | + /** |
|
1036 | + * toggle Check-in status for this registration |
|
1037 | + * Check-ins are toggled in the following order: |
|
1038 | + * never checked in -> checked in |
|
1039 | + * checked in -> checked out |
|
1040 | + * checked out -> checked in |
|
1041 | + * |
|
1042 | + * @param int $DTT_ID include specific datetime to toggle Check-in for. |
|
1043 | + * If not included or null, then it is assumed latest datetime is being toggled. |
|
1044 | + * @param bool $verify If true then can_checkin() is used to verify whether the person |
|
1045 | + * can be checked in or not. Otherwise this forces change in checkin status. |
|
1046 | + * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
|
1047 | + * @throws EE_Error |
|
1048 | + */ |
|
1049 | 1049 | public function toggle_checkin_status( $DTT_ID = null, $verify = false ) { |
1050 | 1050 | if ( empty( $DTT_ID ) ) { |
1051 | 1051 | $datetime = $this->get_latest_related_datetime(); |
@@ -1102,13 +1102,13 @@ discard block |
||
1102 | 1102 | |
1103 | 1103 | |
1104 | 1104 | |
1105 | - /** |
|
1106 | - * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
|
1107 | - * "Latest" is defined by the `DTT_EVT_start` column. |
|
1108 | - * |
|
1109 | - * @return EE_Datetime|null |
|
1110 | - * @throws \EE_Error |
|
1111 | - */ |
|
1105 | + /** |
|
1106 | + * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
|
1107 | + * "Latest" is defined by the `DTT_EVT_start` column. |
|
1108 | + * |
|
1109 | + * @return EE_Datetime|null |
|
1110 | + * @throws \EE_Error |
|
1111 | + */ |
|
1112 | 1112 | public function get_latest_related_datetime() { |
1113 | 1113 | return EEM_Datetime::instance()->get_one( |
1114 | 1114 | array( |
@@ -1122,12 +1122,12 @@ discard block |
||
1122 | 1122 | |
1123 | 1123 | |
1124 | 1124 | |
1125 | - /** |
|
1126 | - * Returns the earliest datetime related to this registration (via the ticket attached to the registration). |
|
1127 | - * "Earliest" is defined by the `DTT_EVT_start` column. |
|
1128 | - * |
|
1129 | - * @throws \EE_Error |
|
1130 | - */ |
|
1125 | + /** |
|
1126 | + * Returns the earliest datetime related to this registration (via the ticket attached to the registration). |
|
1127 | + * "Earliest" is defined by the `DTT_EVT_start` column. |
|
1128 | + * |
|
1129 | + * @throws \EE_Error |
|
1130 | + */ |
|
1131 | 1131 | public function get_earliest_related_datetime() { |
1132 | 1132 | return EEM_Datetime::instance()->get_one( |
1133 | 1133 | array( |
@@ -1141,18 +1141,18 @@ discard block |
||
1141 | 1141 | |
1142 | 1142 | |
1143 | 1143 | |
1144 | - /** |
|
1145 | - * This method simply returns the check-in status for this registration and the given datetime. |
|
1146 | - * If neither the datetime nor the checkin values are provided as arguments, |
|
1147 | - * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. |
|
1148 | - * |
|
1149 | - * @param int $DTT_ID The ID of the datetime we're checking against |
|
1150 | - * (if empty we'll get the primary datetime for |
|
1151 | - * this registration (via event) and use it's ID); |
|
1152 | - * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. |
|
1153 | - * @return int Integer representing Check-in status. |
|
1154 | - * @throws \EE_Error |
|
1155 | - */ |
|
1144 | + /** |
|
1145 | + * This method simply returns the check-in status for this registration and the given datetime. |
|
1146 | + * If neither the datetime nor the checkin values are provided as arguments, |
|
1147 | + * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. |
|
1148 | + * |
|
1149 | + * @param int $DTT_ID The ID of the datetime we're checking against |
|
1150 | + * (if empty we'll get the primary datetime for |
|
1151 | + * this registration (via event) and use it's ID); |
|
1152 | + * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. |
|
1153 | + * @return int Integer representing Check-in status. |
|
1154 | + * @throws \EE_Error |
|
1155 | + */ |
|
1156 | 1156 | public function check_in_status_for_datetime( $DTT_ID = 0, $checkin = null ) { |
1157 | 1157 | $checkin_query_params = array( |
1158 | 1158 | 'order_by' => array( 'CHK_timestamp' => 'DESC' ) |
@@ -1164,8 +1164,8 @@ discard block |
||
1164 | 1164 | |
1165 | 1165 | //get checkin object (if exists) |
1166 | 1166 | $checkin = $checkin instanceof EE_Checkin |
1167 | - ? $checkin |
|
1168 | - : $this->get_first_related( 'Checkin', $checkin_query_params ); |
|
1167 | + ? $checkin |
|
1168 | + : $this->get_first_related( 'Checkin', $checkin_query_params ); |
|
1169 | 1169 | if ( $checkin instanceof EE_Checkin ) { |
1170 | 1170 | if ( $checkin->get( 'CHK_in' ) ) { |
1171 | 1171 | return EE_Registration::checkin_status_in; //checked in |
@@ -1418,7 +1418,7 @@ discard block |
||
1418 | 1418 | |
1419 | 1419 | |
1420 | 1420 | |
1421 | - /*************************** DEPRECATED ***************************/ |
|
1421 | + /*************************** DEPRECATED ***************************/ |
|
1422 | 1422 | |
1423 | 1423 | |
1424 | 1424 | |
@@ -1468,24 +1468,24 @@ discard block |
||
1468 | 1468 | |
1469 | 1469 | |
1470 | 1470 | |
1471 | - /** |
|
1472 | - * Gets the primary datetime related to this registration via the related Event to this registration |
|
1473 | - * |
|
1474 | - * @deprecated 4.9.17 |
|
1475 | - * @return EE_Datetime |
|
1476 | - */ |
|
1477 | - public function get_related_primary_datetime() { |
|
1478 | - EE_Error::doing_it_wrong( |
|
1479 | - __METHOD__, |
|
1480 | - esc_html__( |
|
1481 | - 'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()', |
|
1482 | - 'event_espresso' |
|
1483 | - ), |
|
1484 | - '4.9.17', |
|
1485 | - '5.0.0' |
|
1486 | - ); |
|
1487 | - return $this->event()->primary_datetime(); |
|
1488 | - } |
|
1471 | + /** |
|
1472 | + * Gets the primary datetime related to this registration via the related Event to this registration |
|
1473 | + * |
|
1474 | + * @deprecated 4.9.17 |
|
1475 | + * @return EE_Datetime |
|
1476 | + */ |
|
1477 | + public function get_related_primary_datetime() { |
|
1478 | + EE_Error::doing_it_wrong( |
|
1479 | + __METHOD__, |
|
1480 | + esc_html__( |
|
1481 | + 'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()', |
|
1482 | + 'event_espresso' |
|
1483 | + ), |
|
1484 | + '4.9.17', |
|
1485 | + '5.0.0' |
|
1486 | + ); |
|
1487 | + return $this->event()->primary_datetime(); |
|
1488 | + } |
|
1489 | 1489 | |
1490 | 1490 | |
1491 | 1491 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\exceptions\EntityNotFoundException; |
2 | 2 | |
3 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
4 | - exit( 'No direct script access allowed' ); |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | /** |
7 | 7 | * EE_Registration class |
@@ -43,9 +43,9 @@ discard block |
||
43 | 43 | * date_format and the second value is the time format |
44 | 44 | * @return EE_Registration |
45 | 45 | */ |
46 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
47 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
|
48 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
46 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
47 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
48 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | * the website will be used. |
57 | 57 | * @return EE_Registration |
58 | 58 | */ |
59 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
60 | - return new self( $props_n_values, TRUE, $timezone ); |
|
59 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
60 | + return new self($props_n_values, TRUE, $timezone); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @param int $EVT_ID Event ID |
69 | 69 | */ |
70 | - public function set_event( $EVT_ID = 0 ) { |
|
71 | - $this->set( 'EVT_ID', $EVT_ID ); |
|
70 | + public function set_event($EVT_ID = 0) { |
|
71 | + $this->set('EVT_ID', $EVT_ID); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | |
@@ -79,18 +79,18 @@ discard block |
||
79 | 79 | * @param mixed $field_value |
80 | 80 | * @param bool $use_default |
81 | 81 | */ |
82 | - public function set( $field_name, $field_value, $use_default = FALSE ) { |
|
83 | - switch( $field_name ) { |
|
82 | + public function set($field_name, $field_value, $use_default = FALSE) { |
|
83 | + switch ($field_name) { |
|
84 | 84 | case 'REG_code' : |
85 | - if ( ! empty( $field_value ) && $this->reg_code() == '' ) { |
|
86 | - $this->set_reg_code( $field_value, $use_default ); |
|
85 | + if ( ! empty($field_value) && $this->reg_code() == '') { |
|
86 | + $this->set_reg_code($field_value, $use_default); |
|
87 | 87 | } |
88 | 88 | break; |
89 | 89 | case 'STS_ID' : |
90 | - $this->set_status( $field_value, $use_default ); |
|
90 | + $this->set_status($field_value, $use_default); |
|
91 | 91 | break; |
92 | 92 | default : |
93 | - parent::set( $field_name, $field_value, $use_default ); |
|
93 | + parent::set($field_name, $field_value, $use_default); |
|
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
@@ -107,45 +107,45 @@ discard block |
||
107 | 107 | * @return bool |
108 | 108 | * @throws \EE_Error |
109 | 109 | */ |
110 | - public function set_status( $new_STS_ID = NULL, $use_default = FALSE ) { |
|
110 | + public function set_status($new_STS_ID = NULL, $use_default = FALSE) { |
|
111 | 111 | // get current REG_Status |
112 | 112 | $old_STS_ID = $this->status_ID(); |
113 | 113 | // if status has changed |
114 | 114 | if ( |
115 | 115 | $this->ID() // ensure registration is in the db |
116 | 116 | && $old_STS_ID != $new_STS_ID // and that status has actually changed |
117 | - && ! empty( $old_STS_ID ) // and that old status is actually set |
|
118 | - && ! empty( $new_STS_ID ) // as well as the new status |
|
117 | + && ! empty($old_STS_ID) // and that old status is actually set |
|
118 | + && ! empty($new_STS_ID) // as well as the new status |
|
119 | 119 | ) { |
120 | 120 | // TO approved |
121 | - if ( $new_STS_ID === EEM_Registration::status_id_approved ) { |
|
122 | - \EEH_Debug_Tools::printr(__FUNCTION__, 'BEFORE HOOK ' . __CLASS__, __FILE__, __LINE__, 2); |
|
121 | + if ($new_STS_ID === EEM_Registration::status_id_approved) { |
|
122 | + \EEH_Debug_Tools::printr(__FUNCTION__, 'BEFORE HOOK '.__CLASS__, __FILE__, __LINE__, 2); |
|
123 | 123 | // reserve a space by incrementing ticket and datetime sold values |
124 | 124 | $this->_reserve_registration_space(); |
125 | - do_action( 'AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID ); |
|
126 | - \EEH_Debug_Tools::printr(__FUNCTION__, 'AFTER HOOK ' . __CLASS__, __FILE__, __LINE__, 2); |
|
125 | + do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID); |
|
126 | + \EEH_Debug_Tools::printr(__FUNCTION__, 'AFTER HOOK '.__CLASS__, __FILE__, __LINE__, 2); |
|
127 | 127 | exit(); |
128 | 128 | // OR FROM approved |
129 | - } else if ( $old_STS_ID === EEM_Registration::status_id_approved ) { |
|
129 | + } else if ($old_STS_ID === EEM_Registration::status_id_approved) { |
|
130 | 130 | // release a space by decrementing ticket and datetime sold values |
131 | 131 | $this->_release_registration_space(); |
132 | - do_action( 'AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID ); |
|
132 | + do_action('AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID); |
|
133 | 133 | } |
134 | 134 | // update status |
135 | - parent::set( 'STS_ID', $new_STS_ID, $use_default ); |
|
135 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
136 | 136 | /** @type EE_Registration_Processor $registration_processor */ |
137 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
137 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
138 | 138 | /** @type EE_Transaction_Processor $transaction_processor */ |
139 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
139 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
140 | 140 | /** @type EE_Transaction_Payments $transaction_payments */ |
141 | - $transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' ); |
|
141 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
142 | 142 | // these reg statuses should not be considered in any calculations involving monies owing |
143 | - $closed_reg_statuses = ! empty( $closed_reg_statuses ) |
|
143 | + $closed_reg_statuses = ! empty($closed_reg_statuses) |
|
144 | 144 | ? $closed_reg_statuses |
145 | 145 | : EEM_Registration::closed_reg_statuses(); |
146 | 146 | if ( |
147 | - in_array( $new_STS_ID, $closed_reg_statuses ) |
|
148 | - && ! in_array( $old_STS_ID, $closed_reg_statuses ) |
|
147 | + in_array($new_STS_ID, $closed_reg_statuses) |
|
148 | + && ! in_array($old_STS_ID, $closed_reg_statuses) |
|
149 | 149 | ) { |
150 | 150 | // cancelled or declined registration |
151 | 151 | $registration_processor->update_registration_after_being_canceled_or_declined( |
@@ -158,24 +158,24 @@ discard block |
||
158 | 158 | false |
159 | 159 | ); |
160 | 160 | } else if ( |
161 | - in_array( $old_STS_ID, $closed_reg_statuses ) |
|
162 | - && ! in_array( $new_STS_ID, $closed_reg_statuses ) |
|
161 | + in_array($old_STS_ID, $closed_reg_statuses) |
|
162 | + && ! in_array($new_STS_ID, $closed_reg_statuses) |
|
163 | 163 | ) { |
164 | 164 | // reinstating cancelled or declined registration |
165 | 165 | $registration_processor->update_canceled_or_declined_registration_after_being_reinstated( |
166 | 166 | $this, |
167 | 167 | $closed_reg_statuses |
168 | 168 | ); |
169 | - $transaction_processor->update_transaction_after_reinstating_canceled_registration( $this ); |
|
169 | + $transaction_processor->update_transaction_after_reinstating_canceled_registration($this); |
|
170 | 170 | } |
171 | - $transaction_payments->recalculate_transaction_total( $this->transaction(), false ); |
|
172 | - $this->transaction()->update_status_based_on_total_paid( true ); |
|
173 | - do_action( 'AHEE__EE_Registration__set_status__after_update', $this ); |
|
171 | + $transaction_payments->recalculate_transaction_total($this->transaction(), false); |
|
172 | + $this->transaction()->update_status_based_on_total_paid(true); |
|
173 | + do_action('AHEE__EE_Registration__set_status__after_update', $this); |
|
174 | 174 | return TRUE; |
175 | 175 | } else { |
176 | 176 | //even though the old value matches the new value, it's still good to |
177 | 177 | //allow the parent set method to have a say |
178 | - parent::set( 'STS_ID', $new_STS_ID, $use_default ); |
|
178 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
179 | 179 | return TRUE; |
180 | 180 | } |
181 | 181 | } |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | * get Status ID |
187 | 187 | */ |
188 | 188 | public function status_ID() { |
189 | - return $this->get( 'STS_ID' ); |
|
189 | + return $this->get('STS_ID'); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | |
@@ -211,12 +211,12 @@ discard block |
||
211 | 211 | * @param boolean $include_archived whether to include archived tickets or not. |
212 | 212 | * @return EE_Ticket |
213 | 213 | */ |
214 | - public function ticket( $include_archived = TRUE ) { |
|
214 | + public function ticket($include_archived = TRUE) { |
|
215 | 215 | $query_params = array(); |
216 | - if ( $include_archived ) { |
|
217 | - $query_params[ 'default_where_conditions' ] = 'none'; |
|
216 | + if ($include_archived) { |
|
217 | + $query_params['default_where_conditions'] = 'none'; |
|
218 | 218 | } |
219 | - return $this->get_first_related( 'Ticket', $query_params ); |
|
219 | + return $this->get_first_related('Ticket', $query_params); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | */ |
245 | 245 | public function wp_user() { |
246 | 246 | $event = $this->event(); |
247 | - if ( $event instanceof EE_Event ) { |
|
247 | + if ($event instanceof EE_Event) { |
|
248 | 248 | return $event->wp_user(); |
249 | 249 | } |
250 | 250 | return 0; |
@@ -269,8 +269,8 @@ discard block |
||
269 | 269 | * |
270 | 270 | * @param int $ATT_ID Attendee ID |
271 | 271 | */ |
272 | - public function set_attendee_id( $ATT_ID = 0 ) { |
|
273 | - $this->set( 'ATT_ID', $ATT_ID ); |
|
272 | + public function set_attendee_id($ATT_ID = 0) { |
|
273 | + $this->set('ATT_ID', $ATT_ID); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | |
@@ -280,8 +280,8 @@ discard block |
||
280 | 280 | * |
281 | 281 | * @param int $TXN_ID Transaction ID |
282 | 282 | */ |
283 | - public function set_transaction_id( $TXN_ID = 0 ) { |
|
284 | - $this->set( 'TXN_ID', $TXN_ID ); |
|
283 | + public function set_transaction_id($TXN_ID = 0) { |
|
284 | + $this->set('TXN_ID', $TXN_ID); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | |
@@ -291,8 +291,8 @@ discard block |
||
291 | 291 | * |
292 | 292 | * @param string $REG_session PHP Session ID |
293 | 293 | */ |
294 | - public function set_session( $REG_session = '' ) { |
|
295 | - $this->set( 'REG_session', $REG_session ); |
|
294 | + public function set_session($REG_session = '') { |
|
295 | + $this->set('REG_session', $REG_session); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | |
@@ -302,8 +302,8 @@ discard block |
||
302 | 302 | * |
303 | 303 | * @param string $REG_url_link Registration URL Link |
304 | 304 | */ |
305 | - public function set_reg_url_link( $REG_url_link = '' ) { |
|
306 | - $this->set( 'REG_url_link', $REG_url_link ); |
|
305 | + public function set_reg_url_link($REG_url_link = '') { |
|
306 | + $this->set('REG_url_link', $REG_url_link); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | |
@@ -313,8 +313,8 @@ discard block |
||
313 | 313 | * |
314 | 314 | * @param int $REG_count Primary Attendee |
315 | 315 | */ |
316 | - public function set_count( $REG_count = 1 ) { |
|
317 | - $this->set( 'REG_count', $REG_count ); |
|
316 | + public function set_count($REG_count = 1) { |
|
317 | + $this->set('REG_count', $REG_count); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | |
@@ -324,8 +324,8 @@ discard block |
||
324 | 324 | * |
325 | 325 | * @param boolean $REG_group_size Group Registration |
326 | 326 | */ |
327 | - public function set_group_size( $REG_group_size = FALSE ) { |
|
328 | - $this->set( 'REG_group_size', $REG_group_size ); |
|
327 | + public function set_group_size($REG_group_size = FALSE) { |
|
328 | + $this->set('REG_group_size', $REG_group_size); |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | |
@@ -401,8 +401,8 @@ discard block |
||
401 | 401 | * |
402 | 402 | * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of Date |
403 | 403 | */ |
404 | - public function set_reg_date( $REG_date = FALSE ) { |
|
405 | - $this->set( 'REG_date', $REG_date ); |
|
404 | + public function set_reg_date($REG_date = FALSE) { |
|
405 | + $this->set('REG_date', $REG_date); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | |
@@ -413,8 +413,8 @@ discard block |
||
413 | 413 | * @access public |
414 | 414 | * @param float $REG_final_price |
415 | 415 | */ |
416 | - public function set_final_price( $REG_final_price = 0.00 ) { |
|
417 | - $this->set( 'REG_final_price', $REG_final_price ); |
|
416 | + public function set_final_price($REG_final_price = 0.00) { |
|
417 | + $this->set('REG_final_price', $REG_final_price); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | |
@@ -425,8 +425,8 @@ discard block |
||
425 | 425 | * @access public |
426 | 426 | * @param float $REG_paid |
427 | 427 | */ |
428 | - public function set_paid( $REG_paid = 0.00 ) { |
|
429 | - $this->set( 'REG_paid', $REG_paid ); |
|
428 | + public function set_paid($REG_paid = 0.00) { |
|
429 | + $this->set('REG_paid', $REG_paid); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | |
@@ -436,8 +436,8 @@ discard block |
||
436 | 436 | * |
437 | 437 | * @param boolean $REG_att_is_going Attendee Is Going |
438 | 438 | */ |
439 | - public function set_att_is_going( $REG_att_is_going = FALSE ) { |
|
440 | - $this->set( 'REG_att_is_going', $REG_att_is_going ); |
|
439 | + public function set_att_is_going($REG_att_is_going = FALSE) { |
|
440 | + $this->set('REG_att_is_going', $REG_att_is_going); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | * @return EE_Attendee |
448 | 448 | */ |
449 | 449 | public function attendee() { |
450 | - return $this->get_first_related( 'Attendee' ); |
|
450 | + return $this->get_first_related('Attendee'); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | * get Event ID |
457 | 457 | */ |
458 | 458 | public function event_ID() { |
459 | - return $this->get( 'EVT_ID' ); |
|
459 | + return $this->get('EVT_ID'); |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | */ |
467 | 467 | public function event_name() { |
468 | 468 | $event = $this->event_obj(); |
469 | - if ( $event ) { |
|
469 | + if ($event) { |
|
470 | 470 | return $event->name(); |
471 | 471 | } else { |
472 | 472 | return NULL; |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | * @return EE_Event |
481 | 481 | */ |
482 | 482 | public function event_obj() { |
483 | - return $this->get_first_related( 'Event' ); |
|
483 | + return $this->get_first_related('Event'); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | * get Attendee ID |
490 | 490 | */ |
491 | 491 | public function attendee_ID() { |
492 | - return $this->get( 'ATT_ID' ); |
|
492 | + return $this->get('ATT_ID'); |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | * get PHP Session ID |
499 | 499 | */ |
500 | 500 | public function session_ID() { |
501 | - return $this->get( 'REG_session' ); |
|
501 | + return $this->get('REG_session'); |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | * @param string $messenger 'pdf' or 'html'. Default 'html'. |
509 | 509 | * @return string |
510 | 510 | */ |
511 | - public function receipt_url( $messenger = 'html' ) { |
|
511 | + public function receipt_url($messenger = 'html') { |
|
512 | 512 | |
513 | 513 | /** |
514 | 514 | * The below will be deprecated one version after this. We check first if there is a custom receipt template already in use on old system. If there is then we just return the standard url for it. |
@@ -516,12 +516,12 @@ discard block |
||
516 | 516 | * @since 4.5.0 |
517 | 517 | */ |
518 | 518 | $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php'; |
519 | - $has_custom = EEH_Template::locate_template( $template_relative_path , array(), TRUE, TRUE, TRUE ); |
|
519 | + $has_custom = EEH_Template::locate_template($template_relative_path, array(), TRUE, TRUE, TRUE); |
|
520 | 520 | |
521 | - if ( $has_custom ) { |
|
522 | - return add_query_arg( array( 'receipt' => 'true' ), $this->invoice_url( 'launch' ) ); |
|
521 | + if ($has_custom) { |
|
522 | + return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch')); |
|
523 | 523 | } |
524 | - return apply_filters( 'FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt' ); |
|
524 | + return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt'); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | |
@@ -532,28 +532,28 @@ discard block |
||
532 | 532 | * @param string $messenger 'pdf' or 'html'. Default 'html'. |
533 | 533 | * @return string |
534 | 534 | */ |
535 | - public function invoice_url( $messenger = 'html' ) { |
|
535 | + public function invoice_url($messenger = 'html') { |
|
536 | 536 | /** |
537 | 537 | * The below will be deprecated one version after this. We check first if there is a custom invoice template already in use on old system. If there is then we just return the standard url for it. |
538 | 538 | * |
539 | 539 | * @since 4.5.0 |
540 | 540 | */ |
541 | 541 | $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php'; |
542 | - $has_custom = EEH_Template::locate_template( $template_relative_path , array(), TRUE, TRUE, TRUE ); |
|
542 | + $has_custom = EEH_Template::locate_template($template_relative_path, array(), TRUE, TRUE, TRUE); |
|
543 | 543 | |
544 | - if ( $has_custom ) { |
|
545 | - if ( $messenger == 'html' ) { |
|
546 | - return $this->invoice_url( 'launch' ); |
|
544 | + if ($has_custom) { |
|
545 | + if ($messenger == 'html') { |
|
546 | + return $this->invoice_url('launch'); |
|
547 | 547 | } |
548 | 548 | $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice'; |
549 | 549 | |
550 | - $query_args = array( 'ee' => $route, 'id' => $this->reg_url_link() ); |
|
551 | - if ( $messenger == 'html' ) { |
|
550 | + $query_args = array('ee' => $route, 'id' => $this->reg_url_link()); |
|
551 | + if ($messenger == 'html') { |
|
552 | 552 | $query_args['html'] = TRUE; |
553 | 553 | } |
554 | - return add_query_arg( $query_args, get_permalink( EE_Registry::instance()->CFG->core->thank_you_page_id ) ); |
|
554 | + return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id)); |
|
555 | 555 | } |
556 | - return apply_filters( 'FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice' ); |
|
556 | + return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice'); |
|
557 | 557 | } |
558 | 558 | |
559 | 559 | |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | * @throws \EE_Error |
567 | 567 | */ |
568 | 568 | public function reg_url_link() { |
569 | - return (string)$this->get( 'REG_url_link' ); |
|
569 | + return (string) $this->get('REG_url_link'); |
|
570 | 570 | } |
571 | 571 | |
572 | 572 | |
@@ -576,8 +576,8 @@ discard block |
||
576 | 576 | * @param string $type 'download','launch', or 'html' (default is 'launch') |
577 | 577 | * @return void |
578 | 578 | */ |
579 | - public function e_invoice_url( $type = 'launch' ) { |
|
580 | - echo $this->invoice_url( $type ); |
|
579 | + public function e_invoice_url($type = 'launch') { |
|
580 | + echo $this->invoice_url($type); |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | |
@@ -597,7 +597,7 @@ discard block |
||
597 | 597 | * @return string |
598 | 598 | */ |
599 | 599 | public function payment_overview_url() { |
600 | - return add_query_arg( array( 'e_reg_url_link' => $this->reg_url_link(), 'step' => 'payment_options', 'revisit' => TRUE ), EE_Registry::instance()->CFG->core->reg_page_url() ); |
|
600 | + return add_query_arg(array('e_reg_url_link' => $this->reg_url_link(), 'step' => 'payment_options', 'revisit' => TRUE), EE_Registry::instance()->CFG->core->reg_page_url()); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | |
@@ -608,7 +608,7 @@ discard block |
||
608 | 608 | * @return string |
609 | 609 | */ |
610 | 610 | public function edit_attendee_information_url() { |
611 | - return add_query_arg( array( 'e_reg_url_link' => $this->reg_url_link(), 'step' => 'attendee_information', 'revisit' => TRUE ), EE_Registry::instance()->CFG->core->reg_page_url() ); |
|
611 | + return add_query_arg(array('e_reg_url_link' => $this->reg_url_link(), 'step' => 'attendee_information', 'revisit' => TRUE), EE_Registry::instance()->CFG->core->reg_page_url()); |
|
612 | 612 | } |
613 | 613 | |
614 | 614 | |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | * @return string |
619 | 619 | */ |
620 | 620 | public function get_admin_edit_url() { |
621 | - return EEH_URL::add_query_args_and_nonce( array( 'page' => 'espresso_registrations', 'action' => 'view_registration', '_REG_ID' => $this->ID() ), admin_url( 'admin.php' ) ); |
|
621 | + return EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_registrations', 'action' => 'view_registration', '_REG_ID' => $this->ID()), admin_url('admin.php')); |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | * is_primary_registrant? |
628 | 628 | */ |
629 | 629 | public function is_primary_registrant() { |
630 | - return $this->get( 'REG_count' ) == 1 ? TRUE : FALSE; |
|
630 | + return $this->get('REG_count') == 1 ? TRUE : FALSE; |
|
631 | 631 | } |
632 | 632 | |
633 | 633 | |
@@ -636,12 +636,12 @@ discard block |
||
636 | 636 | * This returns the primary registration object for this registration group (which may be this object). |
637 | 637 | * @return EE_Registration |
638 | 638 | */ |
639 | - public function get_primary_registration() { |
|
640 | - if ( $this->is_primary_registrant() ) |
|
639 | + public function get_primary_registration() { |
|
640 | + if ($this->is_primary_registrant()) |
|
641 | 641 | return $this; |
642 | 642 | |
643 | 643 | //k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1 |
644 | - $primary_registrant = EEM_Registration::instance()->get_one( array( array('TXN_ID' => $this->transaction_ID(), 'REG_count' => 1 ) ) ); |
|
644 | + $primary_registrant = EEM_Registration::instance()->get_one(array(array('TXN_ID' => $this->transaction_ID(), 'REG_count' => 1))); |
|
645 | 645 | return $primary_registrant; |
646 | 646 | } |
647 | 647 | |
@@ -652,7 +652,7 @@ discard block |
||
652 | 652 | * @access public |
653 | 653 | */ |
654 | 654 | public function count() { |
655 | - return $this->get( 'REG_count' ); |
|
655 | + return $this->get('REG_count'); |
|
656 | 656 | } |
657 | 657 | |
658 | 658 | |
@@ -661,7 +661,7 @@ discard block |
||
661 | 661 | * get Group Size |
662 | 662 | */ |
663 | 663 | public function group_size() { |
664 | - return $this->get( 'REG_group_size' ); |
|
664 | + return $this->get('REG_group_size'); |
|
665 | 665 | } |
666 | 666 | |
667 | 667 | |
@@ -670,7 +670,7 @@ discard block |
||
670 | 670 | * get Registration Date |
671 | 671 | */ |
672 | 672 | public function date() { |
673 | - return $this->get( 'REG_date' ); |
|
673 | + return $this->get('REG_date'); |
|
674 | 674 | } |
675 | 675 | |
676 | 676 | |
@@ -681,8 +681,8 @@ discard block |
||
681 | 681 | * @param string $time_format |
682 | 682 | * @return string |
683 | 683 | */ |
684 | - public function pretty_date( $date_format = NULL, $time_format = NULL ) { |
|
685 | - return $this->get_datetime( 'REG_date', $date_format, $time_format ); |
|
684 | + public function pretty_date($date_format = NULL, $time_format = NULL) { |
|
685 | + return $this->get_datetime('REG_date', $date_format, $time_format); |
|
686 | 686 | } |
687 | 687 | |
688 | 688 | |
@@ -694,7 +694,7 @@ discard block |
||
694 | 694 | * @return float |
695 | 695 | */ |
696 | 696 | public function final_price() { |
697 | - return $this->get( 'REG_final_price' ); |
|
697 | + return $this->get('REG_final_price'); |
|
698 | 698 | } |
699 | 699 | |
700 | 700 | |
@@ -705,7 +705,7 @@ discard block |
||
705 | 705 | * @return string |
706 | 706 | */ |
707 | 707 | public function pretty_final_price() { |
708 | - return $this->get_pretty( 'REG_final_price' ); |
|
708 | + return $this->get_pretty('REG_final_price'); |
|
709 | 709 | } |
710 | 710 | |
711 | 711 | |
@@ -715,7 +715,7 @@ discard block |
||
715 | 715 | * @return float |
716 | 716 | */ |
717 | 717 | public function paid() { |
718 | - return $this->get( 'REG_paid' ); |
|
718 | + return $this->get('REG_paid'); |
|
719 | 719 | } |
720 | 720 | |
721 | 721 | |
@@ -725,7 +725,7 @@ discard block |
||
725 | 725 | * @return float |
726 | 726 | */ |
727 | 727 | public function pretty_paid() { |
728 | - return $this->get_pretty( 'REG_paid' ); |
|
728 | + return $this->get_pretty('REG_paid'); |
|
729 | 729 | } |
730 | 730 | |
731 | 731 | |
@@ -736,11 +736,11 @@ discard block |
||
736 | 736 | * @param array $requires_payment |
737 | 737 | * @return bool |
738 | 738 | */ |
739 | - public function owes_monies_and_can_pay( $requires_payment = array()) { |
|
739 | + public function owes_monies_and_can_pay($requires_payment = array()) { |
|
740 | 740 | // these reg statuses require payment (if event is not free) |
741 | - $requires_payment = ! empty( $requires_payment ) ? $requires_payment : EEM_Registration::reg_statuses_that_allow_payment(); |
|
741 | + $requires_payment = ! empty($requires_payment) ? $requires_payment : EEM_Registration::reg_statuses_that_allow_payment(); |
|
742 | 742 | if ( |
743 | - in_array( $this->status_ID(), $requires_payment ) && |
|
743 | + in_array($this->status_ID(), $requires_payment) && |
|
744 | 744 | $this->final_price() != 0 && |
745 | 745 | $this->final_price() != $this->paid() |
746 | 746 | ) { |
@@ -757,8 +757,8 @@ discard block |
||
757 | 757 | * @param bool $show_icons |
758 | 758 | * @return void |
759 | 759 | */ |
760 | - public function e_pretty_status( $show_icons = FALSE ) { |
|
761 | - echo $this->pretty_status( $show_icons ); |
|
760 | + public function e_pretty_status($show_icons = FALSE) { |
|
761 | + echo $this->pretty_status($show_icons); |
|
762 | 762 | } |
763 | 763 | |
764 | 764 | |
@@ -769,10 +769,10 @@ discard block |
||
769 | 769 | * @param bool $show_icons |
770 | 770 | * @return string |
771 | 771 | */ |
772 | - public function pretty_status( $show_icons = FALSE ) { |
|
773 | - $status = EEM_Status::instance()->localized_status( array( $this->status_ID() => __( 'unknown', 'event_espresso' ) ), FALSE, 'sentence' ); |
|
772 | + public function pretty_status($show_icons = FALSE) { |
|
773 | + $status = EEM_Status::instance()->localized_status(array($this->status_ID() => __('unknown', 'event_espresso')), FALSE, 'sentence'); |
|
774 | 774 | $icon = ''; |
775 | - switch ( $this->status_ID() ) { |
|
775 | + switch ($this->status_ID()) { |
|
776 | 776 | case EEM_Registration::status_id_approved: |
777 | 777 | $icon = $show_icons ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' : ''; |
778 | 778 | break; |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | $icon = $show_icons ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' : ''; |
796 | 796 | break; |
797 | 797 | } |
798 | - return $icon . $status[ $this->status_ID() ]; |
|
798 | + return $icon.$status[$this->status_ID()]; |
|
799 | 799 | } |
800 | 800 | |
801 | 801 | |
@@ -804,7 +804,7 @@ discard block |
||
804 | 804 | * get Attendee Is Going |
805 | 805 | */ |
806 | 806 | public function att_is_going() { |
807 | - return $this->get( 'REG_att_is_going' ); |
|
807 | + return $this->get('REG_att_is_going'); |
|
808 | 808 | } |
809 | 809 | |
810 | 810 | |
@@ -814,8 +814,8 @@ discard block |
||
814 | 814 | * @param array $query_params like EEM_Base::get_all |
815 | 815 | * @return EE_Answer[] |
816 | 816 | */ |
817 | - public function answers( $query_params = NULL ) { |
|
818 | - return $this->get_many_related( 'Answer', $query_params ); |
|
817 | + public function answers($query_params = NULL) { |
|
818 | + return $this->get_many_related('Answer', $query_params); |
|
819 | 819 | } |
820 | 820 | |
821 | 821 | |
@@ -829,9 +829,9 @@ discard block |
||
829 | 829 | * (because the answer might be an array of answer values, so passing pretty_value=true |
830 | 830 | * will convert it into some kind of string) |
831 | 831 | */ |
832 | - public function answer_value_to_question( $question, $pretty_value=true ) { |
|
832 | + public function answer_value_to_question($question, $pretty_value = true) { |
|
833 | 833 | $question_id = EEM_Question::instance()->ensure_is_ID($question); |
834 | - return EEM_Answer::instance()->get_answer_value_to_question($this,$question_id,$pretty_value); |
|
834 | + return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value); |
|
835 | 835 | } |
836 | 836 | |
837 | 837 | |
@@ -844,13 +844,13 @@ discard block |
||
844 | 844 | */ |
845 | 845 | public function question_groups() { |
846 | 846 | $question_groups = array(); |
847 | - if ( $this->event() instanceof EE_Event ) { |
|
847 | + if ($this->event() instanceof EE_Event) { |
|
848 | 848 | $question_groups = $this->event()->question_groups( |
849 | 849 | array( |
850 | 850 | array( |
851 | 851 | 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false |
852 | 852 | ), |
853 | - 'order_by' => array( 'QSG_order' => 'ASC' ) |
|
853 | + 'order_by' => array('QSG_order' => 'ASC') |
|
854 | 854 | ) |
855 | 855 | ); |
856 | 856 | } |
@@ -867,7 +867,7 @@ discard block |
||
867 | 867 | */ |
868 | 868 | public function count_question_groups() { |
869 | 869 | $qg_count = 0; |
870 | - if ( $this->event() instanceof EE_Event ) { |
|
870 | + if ($this->event() instanceof EE_Event) { |
|
871 | 871 | $qg_count = $this->event()->count_related( |
872 | 872 | 'Question_Group', |
873 | 873 | array( |
@@ -888,7 +888,7 @@ discard block |
||
888 | 888 | * @return string |
889 | 889 | */ |
890 | 890 | public function reg_date() { |
891 | - return $this->get_datetime( 'REG_date' ); |
|
891 | + return $this->get_datetime('REG_date'); |
|
892 | 892 | } |
893 | 893 | |
894 | 894 | |
@@ -900,7 +900,7 @@ discard block |
||
900 | 900 | * @return EE_Datetime_Ticket |
901 | 901 | */ |
902 | 902 | public function datetime_ticket() { |
903 | - return $this->get_first_related( 'Datetime_Ticket' ); |
|
903 | + return $this->get_first_related('Datetime_Ticket'); |
|
904 | 904 | } |
905 | 905 | |
906 | 906 | |
@@ -910,15 +910,15 @@ discard block |
||
910 | 910 | * @param EE_Datetime_Ticket $datetime_ticket |
911 | 911 | * @return EE_Datetime_Ticket |
912 | 912 | */ |
913 | - public function set_datetime_ticket( $datetime_ticket ) { |
|
914 | - return $this->_add_relation_to( $datetime_ticket, 'Datetime_Ticket' ); |
|
913 | + public function set_datetime_ticket($datetime_ticket) { |
|
914 | + return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket'); |
|
915 | 915 | } |
916 | 916 | /** |
917 | 917 | * Gets deleted |
918 | 918 | * @return boolean |
919 | 919 | */ |
920 | 920 | public function deleted() { |
921 | - return $this->get( 'REG_deleted' ); |
|
921 | + return $this->get('REG_deleted'); |
|
922 | 922 | } |
923 | 923 | |
924 | 924 | /** |
@@ -927,7 +927,7 @@ discard block |
||
927 | 927 | * @return boolean |
928 | 928 | */ |
929 | 929 | public function set_deleted($deleted) { |
930 | - $this->set( 'REG_deleted', $deleted ); |
|
930 | + $this->set('REG_deleted', $deleted); |
|
931 | 931 | } |
932 | 932 | |
933 | 933 | |
@@ -937,7 +937,7 @@ discard block |
||
937 | 937 | * @return EE_Status |
938 | 938 | */ |
939 | 939 | public function status_obj() { |
940 | - return $this->get_first_related( 'Status' ); |
|
940 | + return $this->get_first_related('Status'); |
|
941 | 941 | } |
942 | 942 | |
943 | 943 | |
@@ -948,7 +948,7 @@ discard block |
||
948 | 948 | * @return int |
949 | 949 | */ |
950 | 950 | public function count_checkins() { |
951 | - return $this->get_model()->count_related( $this, 'Checkin' ); |
|
951 | + return $this->get_model()->count_related($this, 'Checkin'); |
|
952 | 952 | } |
953 | 953 | |
954 | 954 | |
@@ -958,7 +958,7 @@ discard block |
||
958 | 958 | * @return int |
959 | 959 | */ |
960 | 960 | public function count_checkins_not_checkedout() { |
961 | - return $this->get_model()->count_related( $this, 'Checkin', array( array( 'CHK_in' => 1 ) ) ); |
|
961 | + return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1))); |
|
962 | 962 | } |
963 | 963 | |
964 | 964 | |
@@ -971,20 +971,20 @@ discard block |
||
971 | 971 | * |
972 | 972 | * @return bool |
973 | 973 | */ |
974 | - public function can_checkin( $DTT_OR_ID, $check_approved = TRUE ) { |
|
975 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID( $DTT_OR_ID ); |
|
974 | + public function can_checkin($DTT_OR_ID, $check_approved = TRUE) { |
|
975 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
976 | 976 | |
977 | 977 | //first check registration status |
978 | - if ( ( $check_approved && ! $this->is_approved() ) || ! $DTT_ID ) { |
|
978 | + if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) { |
|
979 | 979 | return false; |
980 | 980 | } |
981 | 981 | //is there a datetime ticket that matches this dtt_ID? |
982 | - if ( ! ( EEM_Datetime_Ticket::instance()->exists( array( array( 'TKT_ID' => $this->get('TKT_ID' ), 'DTT_ID' => $DTT_ID ) ) ) ) ) { |
|
982 | + if ( ! (EEM_Datetime_Ticket::instance()->exists(array(array('TKT_ID' => $this->get('TKT_ID'), 'DTT_ID' => $DTT_ID))))) { |
|
983 | 983 | return false; |
984 | 984 | } |
985 | 985 | |
986 | 986 | //final check is against TKT_uses |
987 | - return $this->verify_can_checkin_against_TKT_uses( $DTT_ID ); |
|
987 | + return $this->verify_can_checkin_against_TKT_uses($DTT_ID); |
|
988 | 988 | } |
989 | 989 | |
990 | 990 | |
@@ -997,10 +997,10 @@ discard block |
||
997 | 997 | * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
998 | 998 | * @return bool true means can checkin. false means cannot checkin. |
999 | 999 | */ |
1000 | - public function verify_can_checkin_against_TKT_uses( $DTT_OR_ID ) { |
|
1001 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID( $DTT_OR_ID ); |
|
1000 | + public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) { |
|
1001 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
1002 | 1002 | |
1003 | - if ( ! $DTT_ID ) { |
|
1003 | + if ( ! $DTT_ID) { |
|
1004 | 1004 | return false; |
1005 | 1005 | } |
1006 | 1006 | |
@@ -1008,23 +1008,23 @@ discard block |
||
1008 | 1008 | |
1009 | 1009 | // if max uses is not set or equals infinity then return true cause its not a factor for whether user can check-in |
1010 | 1010 | // or not. |
1011 | - if ( ! $max_uses || $max_uses === EE_INF ) { |
|
1011 | + if ( ! $max_uses || $max_uses === EE_INF) { |
|
1012 | 1012 | return true; |
1013 | 1013 | } |
1014 | 1014 | |
1015 | 1015 | //does this datetime have a checkin record? If so, then the dtt count has already been verified so we can just |
1016 | 1016 | //go ahead and toggle. |
1017 | - if ( EEM_Checkin::instance()->exists( array( array( 'REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID ) ) ) ) { |
|
1017 | + if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) { |
|
1018 | 1018 | return true; |
1019 | 1019 | } |
1020 | 1020 | |
1021 | 1021 | //made it here so the last check is whether the number of checkins per unique datetime on this registration |
1022 | 1022 | //disallows further check-ins. |
1023 | - $count_unique_dtt_checkins = EEM_Checkin::instance()->count( array( array( 'REG_ID' => $this->ID(), 'CHK_in' => true ) ), 'DTT_ID', true ); |
|
1023 | + $count_unique_dtt_checkins = EEM_Checkin::instance()->count(array(array('REG_ID' => $this->ID(), 'CHK_in' => true)), 'DTT_ID', true); |
|
1024 | 1024 | // checkins have already reached their max number of uses |
1025 | 1025 | // so registrant can NOT checkin |
1026 | - if ( $count_unique_dtt_checkins >= $max_uses ) { |
|
1027 | - EE_Error::add_error( __( 'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
1026 | + if ($count_unique_dtt_checkins >= $max_uses) { |
|
1027 | + EE_Error::add_error(__('Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1028 | 1028 | return false; |
1029 | 1029 | } |
1030 | 1030 | return true; |
@@ -1046,15 +1046,15 @@ discard block |
||
1046 | 1046 | * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
1047 | 1047 | * @throws EE_Error |
1048 | 1048 | */ |
1049 | - public function toggle_checkin_status( $DTT_ID = null, $verify = false ) { |
|
1050 | - if ( empty( $DTT_ID ) ) { |
|
1049 | + public function toggle_checkin_status($DTT_ID = null, $verify = false) { |
|
1050 | + if (empty($DTT_ID)) { |
|
1051 | 1051 | $datetime = $this->get_latest_related_datetime(); |
1052 | 1052 | $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
1053 | 1053 | // verify the registration can checkin for the given DTT_ID |
1054 | - } elseif ( ! $this->can_checkin( $DTT_ID, $verify ) ) { |
|
1054 | + } elseif ( ! $this->can_checkin($DTT_ID, $verify)) { |
|
1055 | 1055 | EE_Error::add_error( |
1056 | 1056 | sprintf( |
1057 | - __( 'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', 'event_espresso'), |
|
1057 | + __('The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', 'event_espresso'), |
|
1058 | 1058 | $this->ID(), |
1059 | 1059 | $DTT_ID |
1060 | 1060 | ), |
@@ -1068,8 +1068,8 @@ discard block |
||
1068 | 1068 | EE_Registration::checkin_status_out => EE_Registration::checkin_status_in |
1069 | 1069 | ); |
1070 | 1070 | //start by getting the current status so we know what status we'll be changing to. |
1071 | - $cur_status = $this->check_in_status_for_datetime( $DTT_ID, NULL ); |
|
1072 | - $status_to = $status_paths[ $cur_status ]; |
|
1071 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID, NULL); |
|
1072 | + $status_to = $status_paths[$cur_status]; |
|
1073 | 1073 | // database only records true for checked IN or false for checked OUT |
1074 | 1074 | // no record ( null ) means checked in NEVER, but we obviously don't save that |
1075 | 1075 | $new_status = $status_to === EE_Registration::checkin_status_in ? true : false; |
@@ -1077,24 +1077,24 @@ discard block |
||
1077 | 1077 | // because we are keeping track of Check-ins over time. |
1078 | 1078 | // Eventually we'll probably want to show a list table |
1079 | 1079 | // for the individual Check-ins so that they can be managed. |
1080 | - $checkin = EE_Checkin::new_instance( array( |
|
1080 | + $checkin = EE_Checkin::new_instance(array( |
|
1081 | 1081 | 'REG_ID' => $this->ID(), |
1082 | 1082 | 'DTT_ID' => $DTT_ID, |
1083 | 1083 | 'CHK_in' => $new_status |
1084 | - ) ); |
|
1084 | + )); |
|
1085 | 1085 | // if the record could not be saved then return false |
1086 | - if ( $checkin->save() === 0 ) { |
|
1087 | - if ( WP_DEBUG ) { |
|
1086 | + if ($checkin->save() === 0) { |
|
1087 | + if (WP_DEBUG) { |
|
1088 | 1088 | global $wpdb; |
1089 | 1089 | $error = sprintf( |
1090 | - __( 'Registration check in update failed because of the following database error: %1$s%2$s', 'event_espresso' ), |
|
1090 | + __('Registration check in update failed because of the following database error: %1$s%2$s', 'event_espresso'), |
|
1091 | 1091 | '<br />', |
1092 | 1092 | $wpdb->last_error |
1093 | 1093 | ); |
1094 | 1094 | } else { |
1095 | - $error = __( 'Registration check in update failed because of an unknown database error', 'event_espresso' ); |
|
1095 | + $error = __('Registration check in update failed because of an unknown database error', 'event_espresso'); |
|
1096 | 1096 | } |
1097 | - EE_Error::add_error( $error, __FILE__, __FUNCTION__, __LINE__ ); |
|
1097 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
1098 | 1098 | return false; |
1099 | 1099 | } |
1100 | 1100 | return $status_to; |
@@ -1115,7 +1115,7 @@ discard block |
||
1115 | 1115 | array( |
1116 | 1116 | 'Ticket.Registration.REG_ID' => $this->ID() |
1117 | 1117 | ), |
1118 | - 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) |
|
1118 | + 'order_by' => array('DTT_EVT_start' => 'DESC') |
|
1119 | 1119 | ) |
1120 | 1120 | ); |
1121 | 1121 | } |
@@ -1134,7 +1134,7 @@ discard block |
||
1134 | 1134 | array( |
1135 | 1135 | 'Ticket.Registration.REG_ID' => $this->ID() |
1136 | 1136 | ), |
1137 | - 'order_by' => array( 'DTT_EVT_start' => 'ASC' ) |
|
1137 | + 'order_by' => array('DTT_EVT_start' => 'ASC') |
|
1138 | 1138 | ) |
1139 | 1139 | ); |
1140 | 1140 | } |
@@ -1153,21 +1153,21 @@ discard block |
||
1153 | 1153 | * @return int Integer representing Check-in status. |
1154 | 1154 | * @throws \EE_Error |
1155 | 1155 | */ |
1156 | - public function check_in_status_for_datetime( $DTT_ID = 0, $checkin = null ) { |
|
1156 | + public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) { |
|
1157 | 1157 | $checkin_query_params = array( |
1158 | - 'order_by' => array( 'CHK_timestamp' => 'DESC' ) |
|
1158 | + 'order_by' => array('CHK_timestamp' => 'DESC') |
|
1159 | 1159 | ); |
1160 | 1160 | |
1161 | - if ( $DTT_ID > 0 ) { |
|
1162 | - $checkin_query_params[0] = array( 'DTT_ID' => $DTT_ID ); |
|
1161 | + if ($DTT_ID > 0) { |
|
1162 | + $checkin_query_params[0] = array('DTT_ID' => $DTT_ID); |
|
1163 | 1163 | } |
1164 | 1164 | |
1165 | 1165 | //get checkin object (if exists) |
1166 | 1166 | $checkin = $checkin instanceof EE_Checkin |
1167 | 1167 | ? $checkin |
1168 | - : $this->get_first_related( 'Checkin', $checkin_query_params ); |
|
1169 | - if ( $checkin instanceof EE_Checkin ) { |
|
1170 | - if ( $checkin->get( 'CHK_in' ) ) { |
|
1168 | + : $this->get_first_related('Checkin', $checkin_query_params); |
|
1169 | + if ($checkin instanceof EE_Checkin) { |
|
1170 | + if ($checkin->get('CHK_in')) { |
|
1171 | 1171 | return EE_Registration::checkin_status_in; //checked in |
1172 | 1172 | } |
1173 | 1173 | return EE_Registration::checkin_status_out; //had checked in but is now checked out. |
@@ -1183,28 +1183,28 @@ discard block |
||
1183 | 1183 | * @param bool $error This just flags that you want an error message returned. This is put in so that the error message can be customized with the attendee name. |
1184 | 1184 | * @return string internationalized message |
1185 | 1185 | */ |
1186 | - public function get_checkin_msg( $DTT_ID, $error = FALSE ) { |
|
1186 | + public function get_checkin_msg($DTT_ID, $error = FALSE) { |
|
1187 | 1187 | //let's get the attendee first so we can include the name of the attendee |
1188 | - $attendee = $this->get_first_related( 'Attendee' ); |
|
1189 | - if ( $attendee instanceof EE_Attendee ) { |
|
1190 | - if ( $error ) { |
|
1191 | - return sprintf( __( "%s's check-in status was not changed.", "event_espresso" ), $attendee->full_name() ); |
|
1188 | + $attendee = $this->get_first_related('Attendee'); |
|
1189 | + if ($attendee instanceof EE_Attendee) { |
|
1190 | + if ($error) { |
|
1191 | + return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name()); |
|
1192 | 1192 | } |
1193 | - $cur_status = $this->check_in_status_for_datetime( $DTT_ID ); |
|
1193 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID); |
|
1194 | 1194 | //what is the status message going to be? |
1195 | - switch ( $cur_status ) { |
|
1195 | + switch ($cur_status) { |
|
1196 | 1196 | case EE_Registration::checkin_status_never : |
1197 | - return sprintf( __( "%s has been removed from Check-in records", "event_espresso" ), $attendee->full_name() ); |
|
1197 | + return sprintf(__("%s has been removed from Check-in records", "event_espresso"), $attendee->full_name()); |
|
1198 | 1198 | break; |
1199 | 1199 | case EE_Registration::checkin_status_in : |
1200 | - return sprintf( __( '%s has been checked in', 'event_espresso' ), $attendee->full_name() ); |
|
1200 | + return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name()); |
|
1201 | 1201 | break; |
1202 | 1202 | case EE_Registration::checkin_status_out : |
1203 | - return sprintf( __( '%s has been checked out', 'event_espresso' ), $attendee->full_name() ); |
|
1203 | + return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name()); |
|
1204 | 1204 | break; |
1205 | 1205 | } |
1206 | 1206 | } |
1207 | - return __( "The check-in status could not be determined.", "event_espresso" ); |
|
1207 | + return __("The check-in status could not be determined.", "event_espresso"); |
|
1208 | 1208 | } |
1209 | 1209 | |
1210 | 1210 | |
@@ -1228,7 +1228,7 @@ discard block |
||
1228 | 1228 | * get Registration Code |
1229 | 1229 | */ |
1230 | 1230 | public function reg_code() { |
1231 | - return $this->get( 'REG_code' ); |
|
1231 | + return $this->get('REG_code'); |
|
1232 | 1232 | } |
1233 | 1233 | |
1234 | 1234 | |
@@ -1237,7 +1237,7 @@ discard block |
||
1237 | 1237 | * get Transaction ID |
1238 | 1238 | */ |
1239 | 1239 | public function transaction_ID() { |
1240 | - return $this->get( 'TXN_ID' ); |
|
1240 | + return $this->get('TXN_ID'); |
|
1241 | 1241 | } |
1242 | 1242 | |
1243 | 1243 | |
@@ -1246,7 +1246,7 @@ discard block |
||
1246 | 1246 | * @return int |
1247 | 1247 | */ |
1248 | 1248 | public function ticket_ID() { |
1249 | - return $this->get( 'TKT_ID' ); |
|
1249 | + return $this->get('TKT_ID'); |
|
1250 | 1250 | } |
1251 | 1251 | |
1252 | 1252 | |
@@ -1258,17 +1258,17 @@ discard block |
||
1258 | 1258 | * @param string $REG_code Registration Code |
1259 | 1259 | * @param boolean $use_default |
1260 | 1260 | */ |
1261 | - public function set_reg_code( $REG_code, $use_default = FALSE ) { |
|
1262 | - if ( empty( $REG_code )) { |
|
1263 | - EE_Error::add_error( __( 'REG_code can not be empty.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
1261 | + public function set_reg_code($REG_code, $use_default = FALSE) { |
|
1262 | + if (empty($REG_code)) { |
|
1263 | + EE_Error::add_error(__('REG_code can not be empty.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1264 | 1264 | return; |
1265 | 1265 | } |
1266 | - if ( ! $this->reg_code() ) { |
|
1267 | - parent::set( 'REG_code', $REG_code, $use_default ); |
|
1266 | + if ( ! $this->reg_code()) { |
|
1267 | + parent::set('REG_code', $REG_code, $use_default); |
|
1268 | 1268 | } else { |
1269 | 1269 | EE_Error::doing_it_wrong( |
1270 | - __CLASS__ . '::' . __FUNCTION__, |
|
1271 | - __( 'Can not change a registration REG_code once it has been set.', 'event_espresso' ), |
|
1270 | + __CLASS__.'::'.__FUNCTION__, |
|
1271 | + __('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
|
1272 | 1272 | '4.6.0' |
1273 | 1273 | ); |
1274 | 1274 | } |
@@ -1288,17 +1288,17 @@ discard block |
||
1288 | 1288 | * @return EE_Registration[] or empty array if this isn't a group registration. |
1289 | 1289 | */ |
1290 | 1290 | public function get_all_other_registrations_in_group() { |
1291 | - if ( $this->group_size() < 2 ) { |
|
1291 | + if ($this->group_size() < 2) { |
|
1292 | 1292 | return array(); |
1293 | 1293 | } |
1294 | 1294 | |
1295 | 1295 | $query[0] = array( |
1296 | 1296 | 'TXN_ID' => $this->transaction_ID(), |
1297 | - 'REG_ID' => array( '!=', $this->ID() ), |
|
1297 | + 'REG_ID' => array('!=', $this->ID()), |
|
1298 | 1298 | 'TKT_ID' => $this->ticket_ID() |
1299 | 1299 | ); |
1300 | 1300 | |
1301 | - $registrations = $this->get_model()->get_all( $query ); |
|
1301 | + $registrations = $this->get_model()->get_all($query); |
|
1302 | 1302 | return $registrations; |
1303 | 1303 | } |
1304 | 1304 | |
@@ -1307,14 +1307,14 @@ discard block |
||
1307 | 1307 | * @return string |
1308 | 1308 | */ |
1309 | 1309 | public function get_admin_details_link() { |
1310 | - EE_Registry::instance()->load_helper( 'URL' ); |
|
1310 | + EE_Registry::instance()->load_helper('URL'); |
|
1311 | 1311 | return EEH_URL::add_query_args_and_nonce( |
1312 | 1312 | array( |
1313 | 1313 | 'page' => 'espresso_registrations', |
1314 | 1314 | 'action' => 'view_registration', |
1315 | 1315 | '_REG_ID' => $this->ID() |
1316 | 1316 | ), |
1317 | - admin_url( 'admin.php' ) |
|
1317 | + admin_url('admin.php') |
|
1318 | 1318 | ); |
1319 | 1319 | } |
1320 | 1320 | |
@@ -1339,12 +1339,12 @@ discard block |
||
1339 | 1339 | * @return string |
1340 | 1340 | */ |
1341 | 1341 | public function get_admin_overview_link() { |
1342 | - EE_Registry::instance()->load_helper( 'URL' ); |
|
1342 | + EE_Registry::instance()->load_helper('URL'); |
|
1343 | 1343 | return EEH_URL::add_query_args_and_nonce( |
1344 | 1344 | array( |
1345 | 1345 | 'page' => 'espresso_registrations' |
1346 | 1346 | ), |
1347 | - admin_url( 'admin.php' ) |
|
1347 | + admin_url('admin.php') |
|
1348 | 1348 | ); |
1349 | 1349 | } |
1350 | 1350 | |
@@ -1355,8 +1355,8 @@ discard block |
||
1355 | 1355 | * @return \EE_Registration[] |
1356 | 1356 | * @throws \EE_Error |
1357 | 1357 | */ |
1358 | - public function payments( $query_params = array() ) { |
|
1359 | - return $this->get_many_related( 'Payment', $query_params ); |
|
1358 | + public function payments($query_params = array()) { |
|
1359 | + return $this->get_many_related('Payment', $query_params); |
|
1360 | 1360 | } |
1361 | 1361 | |
1362 | 1362 | |
@@ -1366,8 +1366,8 @@ discard block |
||
1366 | 1366 | * @return \EE_Registration_Payment[] |
1367 | 1367 | * @throws \EE_Error |
1368 | 1368 | */ |
1369 | - public function registration_payments( $query_params = array() ) { |
|
1370 | - return $this->get_many_related( 'Registration_Payment', $query_params ); |
|
1369 | + public function registration_payments($query_params = array()) { |
|
1370 | + return $this->get_many_related('Registration_Payment', $query_params); |
|
1371 | 1371 | } |
1372 | 1372 | |
1373 | 1373 | |
@@ -1380,7 +1380,7 @@ discard block |
||
1380 | 1380 | * @return EE_Payment_Method|null |
1381 | 1381 | */ |
1382 | 1382 | public function payment_method() { |
1383 | - return EEM_Payment_Method::instance()->get_last_used_for_registration( $this ); |
|
1383 | + return EEM_Payment_Method::instance()->get_last_used_for_registration($this); |
|
1384 | 1384 | } |
1385 | 1385 | |
1386 | 1386 |
@@ -23,52 +23,52 @@ |
||
23 | 23 | |
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * when a trigger has been "pulled", |
|
28 | - * either by a do_action or scheduled cron, |
|
29 | - * this is the callback method that will run |
|
30 | - * to actually execute the logic |
|
31 | - * for the automated action |
|
32 | - * |
|
33 | - * @throws InvalidEntityException |
|
34 | - * @throws InvalidArgumentException |
|
35 | - */ |
|
36 | - public function execute() |
|
37 | - { |
|
38 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
39 | - $params = $this->getParams(); |
|
40 | - if ( ! isset($params[0], $params[1], $params[2], $params['query_params']) ) { |
|
41 | - throw new InvalidArgumentException(); |
|
42 | - } |
|
43 | - if ( ! $params[0] instanceof EE_Registration) { |
|
44 | - throw new InvalidEntityException($params[0], 'EE_Registration'); |
|
45 | - } |
|
46 | - /** @var EE_Registration $registration */ |
|
47 | - list($registration, $old_STS_ID, $new_STS_ID) = $params; |
|
48 | - // $registration = $params[0]; |
|
49 | - // $old_STS_ID = $params[1]; |
|
50 | - // $new_STS_ID = $params[2]; |
|
51 | - $query_params = $params['query_params']; |
|
52 | - \EEH_Debug_Tools::printr($registration, '$registration', __FILE__, __LINE__); |
|
53 | - \EEH_Debug_Tools::printr($old_STS_ID, '$old_STS_ID', __FILE__, __LINE__); |
|
54 | - \EEH_Debug_Tools::printr($new_STS_ID, '$new_STS_ID', __FILE__, __LINE__); |
|
55 | - \EEH_Debug_Tools::printr($query_params, 'Trigger Rules query_params', __FILE__, __LINE__); |
|
56 | - $where = array(); |
|
57 | - foreach ($query_params as $key => $query_param) { |
|
58 | - \EEH_Debug_Tools::printr($key, '$key', __FILE__, __LINE__); |
|
59 | - \EEH_Debug_Tools::printr($query_param, '$query_param', __FILE__, __LINE__); |
|
60 | - if($key === 0 ) { |
|
61 | - $where[0] = isset($where[0]) ? array_merge($where[0], $query_param) : $query_param; |
|
62 | - } else if( is_int($key) ) { |
|
63 | - $where["AND*{$key}"]= $query_param; |
|
64 | - } else { |
|
65 | - $where[$key] = $query_param; |
|
66 | - } |
|
67 | - \EEH_Debug_Tools::printr($where, '$where', __FILE__, __LINE__); |
|
68 | - } |
|
69 | - $this->setHasRun(); |
|
70 | - exit(); |
|
71 | - } |
|
26 | + /** |
|
27 | + * when a trigger has been "pulled", |
|
28 | + * either by a do_action or scheduled cron, |
|
29 | + * this is the callback method that will run |
|
30 | + * to actually execute the logic |
|
31 | + * for the automated action |
|
32 | + * |
|
33 | + * @throws InvalidEntityException |
|
34 | + * @throws InvalidArgumentException |
|
35 | + */ |
|
36 | + public function execute() |
|
37 | + { |
|
38 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
39 | + $params = $this->getParams(); |
|
40 | + if ( ! isset($params[0], $params[1], $params[2], $params['query_params']) ) { |
|
41 | + throw new InvalidArgumentException(); |
|
42 | + } |
|
43 | + if ( ! $params[0] instanceof EE_Registration) { |
|
44 | + throw new InvalidEntityException($params[0], 'EE_Registration'); |
|
45 | + } |
|
46 | + /** @var EE_Registration $registration */ |
|
47 | + list($registration, $old_STS_ID, $new_STS_ID) = $params; |
|
48 | + // $registration = $params[0]; |
|
49 | + // $old_STS_ID = $params[1]; |
|
50 | + // $new_STS_ID = $params[2]; |
|
51 | + $query_params = $params['query_params']; |
|
52 | + \EEH_Debug_Tools::printr($registration, '$registration', __FILE__, __LINE__); |
|
53 | + \EEH_Debug_Tools::printr($old_STS_ID, '$old_STS_ID', __FILE__, __LINE__); |
|
54 | + \EEH_Debug_Tools::printr($new_STS_ID, '$new_STS_ID', __FILE__, __LINE__); |
|
55 | + \EEH_Debug_Tools::printr($query_params, 'Trigger Rules query_params', __FILE__, __LINE__); |
|
56 | + $where = array(); |
|
57 | + foreach ($query_params as $key => $query_param) { |
|
58 | + \EEH_Debug_Tools::printr($key, '$key', __FILE__, __LINE__); |
|
59 | + \EEH_Debug_Tools::printr($query_param, '$query_param', __FILE__, __LINE__); |
|
60 | + if($key === 0 ) { |
|
61 | + $where[0] = isset($where[0]) ? array_merge($where[0], $query_param) : $query_param; |
|
62 | + } else if( is_int($key) ) { |
|
63 | + $where["AND*{$key}"]= $query_param; |
|
64 | + } else { |
|
65 | + $where[$key] = $query_param; |
|
66 | + } |
|
67 | + \EEH_Debug_Tools::printr($where, '$where', __FILE__, __LINE__); |
|
68 | + } |
|
69 | + $this->setHasRun(); |
|
70 | + exit(); |
|
71 | + } |
|
72 | 72 | |
73 | 73 | |
74 | 74 |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | { |
38 | 38 | \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
39 | 39 | $params = $this->getParams(); |
40 | - if ( ! isset($params[0], $params[1], $params[2], $params['query_params']) ) { |
|
40 | + if ( ! isset($params[0], $params[1], $params[2], $params['query_params'])) { |
|
41 | 41 | throw new InvalidArgumentException(); |
42 | 42 | } |
43 | 43 | if ( ! $params[0] instanceof EE_Registration) { |
@@ -57,10 +57,10 @@ discard block |
||
57 | 57 | foreach ($query_params as $key => $query_param) { |
58 | 58 | \EEH_Debug_Tools::printr($key, '$key', __FILE__, __LINE__); |
59 | 59 | \EEH_Debug_Tools::printr($query_param, '$query_param', __FILE__, __LINE__); |
60 | - if($key === 0 ) { |
|
60 | + if ($key === 0) { |
|
61 | 61 | $where[0] = isset($where[0]) ? array_merge($where[0], $query_param) : $query_param; |
62 | - } else if( is_int($key) ) { |
|
63 | - $where["AND*{$key}"]= $query_param; |
|
62 | + } else if (is_int($key)) { |
|
63 | + $where["AND*{$key}"] = $query_param; |
|
64 | 64 | } else { |
65 | 65 | $where[$key] = $query_param; |
66 | 66 | } |
@@ -21,44 +21,44 @@ |
||
21 | 21 | |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * @return \EEM_Event |
|
26 | - */ |
|
27 | - protected function get_model() |
|
28 | - { |
|
29 | - if (!$this->model instanceof EEM_Event) { |
|
30 | - return EEM_Event::instance(); |
|
31 | - } |
|
32 | - return $this->model; |
|
33 | - } |
|
24 | + /** |
|
25 | + * @return \EEM_Event |
|
26 | + */ |
|
27 | + protected function get_model() |
|
28 | + { |
|
29 | + if (!$this->model instanceof EEM_Event) { |
|
30 | + return EEM_Event::instance(); |
|
31 | + } |
|
32 | + return $this->model; |
|
33 | + } |
|
34 | 34 | |
35 | 35 | |
36 | 36 | |
37 | - public function eventCategory() |
|
38 | - { |
|
39 | - return array( |
|
40 | - 'Term_Taxonomy.taxonomy' => array($this->comparison, 'espresso_event_categories' ), |
|
41 | - 'Term_Taxonomy.term_id' => array($this->comparison, $this->value), |
|
42 | - ); |
|
43 | - } |
|
37 | + public function eventCategory() |
|
38 | + { |
|
39 | + return array( |
|
40 | + 'Term_Taxonomy.taxonomy' => array($this->comparison, 'espresso_event_categories' ), |
|
41 | + 'Term_Taxonomy.term_id' => array($this->comparison, $this->value), |
|
42 | + ); |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | 46 | |
47 | - public function eventStart() |
|
48 | - { |
|
49 | - return array( |
|
50 | - 'Datetime.DTT_EVT_start' => array($this->comparison, $this->value), |
|
51 | - ); |
|
52 | - } |
|
47 | + public function eventStart() |
|
48 | + { |
|
49 | + return array( |
|
50 | + 'Datetime.DTT_EVT_start' => array($this->comparison, $this->value), |
|
51 | + ); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | 55 | |
56 | - public function eventEnd() |
|
57 | - { |
|
58 | - return array( |
|
59 | - 'Datetime.DTT_EVT_end' => array($this->comparison, $this->value), |
|
60 | - ); |
|
61 | - } |
|
56 | + public function eventEnd() |
|
57 | + { |
|
58 | + return array( |
|
59 | + 'Datetime.DTT_EVT_end' => array($this->comparison, $this->value), |
|
60 | + ); |
|
61 | + } |
|
62 | 62 | |
63 | 63 | } |
64 | 64 | // End of file EventQuery.php |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | protected function get_model() |
28 | 28 | { |
29 | - if (!$this->model instanceof EEM_Event) { |
|
29 | + if ( ! $this->model instanceof EEM_Event) { |
|
30 | 30 | return EEM_Event::instance(); |
31 | 31 | } |
32 | 32 | return $this->model; |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | public function eventCategory() |
38 | 38 | { |
39 | 39 | return array( |
40 | - 'Term_Taxonomy.taxonomy' => array($this->comparison, 'espresso_event_categories' ), |
|
40 | + 'Term_Taxonomy.taxonomy' => array($this->comparison, 'espresso_event_categories'), |
|
41 | 41 | 'Term_Taxonomy.term_id' => array($this->comparison, $this->value), |
42 | 42 | ); |
43 | 43 | } |
@@ -27,136 +27,136 @@ |
||
27 | 27 | { |
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * @var Collection $automated_actions |
|
32 | - */ |
|
33 | - private $automated_actions; |
|
34 | - |
|
35 | - /** |
|
36 | - * @type CapabilitiesChecker $capabilities_checker |
|
37 | - */ |
|
38 | - private $capabilities_checker; |
|
39 | - |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * AutomatedActionManager constructor |
|
44 | - * |
|
45 | - * @param CapabilitiesChecker $capabilities_checker |
|
46 | - * @param Collection $automated_actions |
|
47 | - * @throws InvalidInterfaceException |
|
48 | - */ |
|
49 | - public function __construct(CapabilitiesChecker $capabilities_checker, Collection $automated_actions = null) |
|
50 | - { |
|
51 | - Benchmark::startTimer(__METHOD__); |
|
52 | - $this->capabilities_checker = $capabilities_checker; |
|
53 | - $this->automated_actions = $automated_actions instanceof Collection |
|
54 | - ? $automated_actions |
|
55 | - : new Collection('EventEspresso\core\services\automated_actions\AutomatedActionInterface'); |
|
56 | - add_action('AHEE__EE_System__initialize', array($this, 'initialize')); |
|
57 | - Benchmark::stopTimer(__METHOD__); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @throws \DomainException |
|
64 | - * @throws InvalidEntityException |
|
65 | - * @throws InsufficientPermissionsException |
|
66 | - * @throws InvalidClassException |
|
67 | - */ |
|
68 | - public function initialize() |
|
69 | - { |
|
70 | - $results = $this->getActiveActions(); |
|
71 | - $this->generateActionObjects($results); |
|
72 | - $this->setTriggers(); |
|
73 | - add_action('shutdown', array($this, 'processActions')); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * @return array |
|
80 | - * @throws \DomainException |
|
81 | - */ |
|
82 | - protected function getActiveActions() |
|
83 | - { |
|
84 | - Benchmark::startTimer(__METHOD__); |
|
85 | - global $wpdb; |
|
86 | - $results = $wpdb->get_results( |
|
87 | - "SELECT * FROM {$wpdb->prefix}esp_automated_action WHERE AMA_is_active = 1;" |
|
88 | - ); |
|
89 | - if ($results instanceof \WP_Error) { |
|
90 | - throw new \DomainException( |
|
91 | - $results->get_error_message() |
|
92 | - ); |
|
93 | - } |
|
94 | - $results = is_array($results) ? $results : array($results); |
|
95 | - Benchmark::stopTimer(__METHOD__); |
|
96 | - return $results; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @param array $results |
|
103 | - * @throws InvalidEntityException |
|
104 | - * @throws \DomainException |
|
105 | - */ |
|
106 | - protected function generateActionObjects(array $results) |
|
107 | - { |
|
108 | - Benchmark::startTimer(__METHOD__); |
|
109 | - foreach ($results as $result) { |
|
110 | - $this->automated_actions->add( |
|
111 | - AutomatedActionFactory::create($result), |
|
112 | - $result->AMA_name |
|
113 | - ); |
|
114 | - } |
|
115 | - Benchmark::stopTimer(__METHOD__); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * @throws InsufficientPermissionsException |
|
122 | - * @throws InvalidClassException |
|
123 | - */ |
|
124 | - public function setTriggers() |
|
125 | - { |
|
126 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
127 | - Benchmark::startTimer(__METHOD__); |
|
128 | - foreach ($this->automated_actions as $automated_action) { |
|
129 | - /** @var AutomatedActionInterface $automated_action */ |
|
130 | - if ($automated_action instanceof RequiresCapCheckInterface) { |
|
131 | - $this->capabilities_checker->processCapCheck( |
|
132 | - $automated_action->getCapCheck() |
|
133 | - ); |
|
134 | - } |
|
135 | - $automated_action->setTrigger(); |
|
136 | - } |
|
137 | - Benchmark::stopTimer(__METHOD__); |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * |
|
144 | - */ |
|
145 | - public function processActions() |
|
146 | - { |
|
147 | - \EEH_Debug_Tools::printr('', 'SHUTDOWN HOOK', __FILE__, __LINE__, 2); |
|
148 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
149 | - Benchmark::startTimer(__METHOD__); |
|
150 | - foreach ($this->automated_actions as $automated_action) { |
|
151 | - /** @var AutomatedActionInterface $automated_action */ |
|
152 | - if ( ! $automated_action->triggerPulled() || $automated_action->hasRun()) { |
|
153 | - continue; |
|
154 | - } |
|
155 | - $automated_action->process(); |
|
156 | - } |
|
157 | - Benchmark::stopTimer(__METHOD__); |
|
158 | - Benchmark::displayResults(); |
|
159 | - } |
|
30 | + /** |
|
31 | + * @var Collection $automated_actions |
|
32 | + */ |
|
33 | + private $automated_actions; |
|
34 | + |
|
35 | + /** |
|
36 | + * @type CapabilitiesChecker $capabilities_checker |
|
37 | + */ |
|
38 | + private $capabilities_checker; |
|
39 | + |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * AutomatedActionManager constructor |
|
44 | + * |
|
45 | + * @param CapabilitiesChecker $capabilities_checker |
|
46 | + * @param Collection $automated_actions |
|
47 | + * @throws InvalidInterfaceException |
|
48 | + */ |
|
49 | + public function __construct(CapabilitiesChecker $capabilities_checker, Collection $automated_actions = null) |
|
50 | + { |
|
51 | + Benchmark::startTimer(__METHOD__); |
|
52 | + $this->capabilities_checker = $capabilities_checker; |
|
53 | + $this->automated_actions = $automated_actions instanceof Collection |
|
54 | + ? $automated_actions |
|
55 | + : new Collection('EventEspresso\core\services\automated_actions\AutomatedActionInterface'); |
|
56 | + add_action('AHEE__EE_System__initialize', array($this, 'initialize')); |
|
57 | + Benchmark::stopTimer(__METHOD__); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @throws \DomainException |
|
64 | + * @throws InvalidEntityException |
|
65 | + * @throws InsufficientPermissionsException |
|
66 | + * @throws InvalidClassException |
|
67 | + */ |
|
68 | + public function initialize() |
|
69 | + { |
|
70 | + $results = $this->getActiveActions(); |
|
71 | + $this->generateActionObjects($results); |
|
72 | + $this->setTriggers(); |
|
73 | + add_action('shutdown', array($this, 'processActions')); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * @return array |
|
80 | + * @throws \DomainException |
|
81 | + */ |
|
82 | + protected function getActiveActions() |
|
83 | + { |
|
84 | + Benchmark::startTimer(__METHOD__); |
|
85 | + global $wpdb; |
|
86 | + $results = $wpdb->get_results( |
|
87 | + "SELECT * FROM {$wpdb->prefix}esp_automated_action WHERE AMA_is_active = 1;" |
|
88 | + ); |
|
89 | + if ($results instanceof \WP_Error) { |
|
90 | + throw new \DomainException( |
|
91 | + $results->get_error_message() |
|
92 | + ); |
|
93 | + } |
|
94 | + $results = is_array($results) ? $results : array($results); |
|
95 | + Benchmark::stopTimer(__METHOD__); |
|
96 | + return $results; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @param array $results |
|
103 | + * @throws InvalidEntityException |
|
104 | + * @throws \DomainException |
|
105 | + */ |
|
106 | + protected function generateActionObjects(array $results) |
|
107 | + { |
|
108 | + Benchmark::startTimer(__METHOD__); |
|
109 | + foreach ($results as $result) { |
|
110 | + $this->automated_actions->add( |
|
111 | + AutomatedActionFactory::create($result), |
|
112 | + $result->AMA_name |
|
113 | + ); |
|
114 | + } |
|
115 | + Benchmark::stopTimer(__METHOD__); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * @throws InsufficientPermissionsException |
|
122 | + * @throws InvalidClassException |
|
123 | + */ |
|
124 | + public function setTriggers() |
|
125 | + { |
|
126 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
127 | + Benchmark::startTimer(__METHOD__); |
|
128 | + foreach ($this->automated_actions as $automated_action) { |
|
129 | + /** @var AutomatedActionInterface $automated_action */ |
|
130 | + if ($automated_action instanceof RequiresCapCheckInterface) { |
|
131 | + $this->capabilities_checker->processCapCheck( |
|
132 | + $automated_action->getCapCheck() |
|
133 | + ); |
|
134 | + } |
|
135 | + $automated_action->setTrigger(); |
|
136 | + } |
|
137 | + Benchmark::stopTimer(__METHOD__); |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * |
|
144 | + */ |
|
145 | + public function processActions() |
|
146 | + { |
|
147 | + \EEH_Debug_Tools::printr('', 'SHUTDOWN HOOK', __FILE__, __LINE__, 2); |
|
148 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
149 | + Benchmark::startTimer(__METHOD__); |
|
150 | + foreach ($this->automated_actions as $automated_action) { |
|
151 | + /** @var AutomatedActionInterface $automated_action */ |
|
152 | + if ( ! $automated_action->triggerPulled() || $automated_action->hasRun()) { |
|
153 | + continue; |
|
154 | + } |
|
155 | + $automated_action->process(); |
|
156 | + } |
|
157 | + Benchmark::stopTimer(__METHOD__); |
|
158 | + Benchmark::displayResults(); |
|
159 | + } |
|
160 | 160 | |
161 | 161 | |
162 | 162 | } |
@@ -18,268 +18,268 @@ |
||
18 | 18 | class AutomatedAction implements AutomatedActionInterface |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var int $ID |
|
23 | - */ |
|
24 | - protected $ID; |
|
21 | + /** |
|
22 | + * @var int $ID |
|
23 | + */ |
|
24 | + protected $ID; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @var string $name |
|
28 | - */ |
|
29 | - protected $name; |
|
26 | + /** |
|
27 | + * @var string $name |
|
28 | + */ |
|
29 | + protected $name; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @var string $description |
|
33 | - */ |
|
34 | - protected $description; |
|
31 | + /** |
|
32 | + * @var string $description |
|
33 | + */ |
|
34 | + protected $description; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var AutomatedActionStrategy $strategy |
|
38 | - */ |
|
39 | - protected $strategy; |
|
36 | + /** |
|
37 | + * @var AutomatedActionStrategy $strategy |
|
38 | + */ |
|
39 | + protected $strategy; |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * @var TriggerStrategy $trigger |
|
44 | - */ |
|
45 | - protected $trigger; |
|
42 | + /** |
|
43 | + * @var TriggerStrategy $trigger |
|
44 | + */ |
|
45 | + protected $trigger; |
|
46 | 46 | |
47 | - /** |
|
48 | - * @var string $trigger_value |
|
49 | - */ |
|
50 | - protected $trigger_value; |
|
47 | + /** |
|
48 | + * @var string $trigger_value |
|
49 | + */ |
|
50 | + protected $trigger_value; |
|
51 | 51 | |
52 | - /** |
|
53 | - * @var string $data |
|
54 | - */ |
|
55 | - protected $data; |
|
52 | + /** |
|
53 | + * @var string $data |
|
54 | + */ |
|
55 | + protected $data; |
|
56 | 56 | |
57 | 57 | |
58 | - /* |
|
58 | + /* |
|
59 | 59 | * @var CapCheckInterface $cap_check |
60 | 60 | */ |
61 | - protected $cap_check; |
|
61 | + protected $cap_check; |
|
62 | 62 | |
63 | 63 | |
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * AutomatedAction constructor. |
|
68 | - * |
|
69 | - * @param \stdClass $args |
|
70 | - * @param AutomatedActionStrategy $strategy |
|
71 | - * @param TriggerStrategy $trigger |
|
72 | - * @throws \DomainException |
|
73 | - */ |
|
74 | - public function __construct(\stdClass $args, AutomatedActionStrategy $strategy, TriggerStrategy $trigger) |
|
75 | - { |
|
76 | - $this->setID($args); |
|
77 | - $this->setName($args); |
|
78 | - $this->setDescription($args); |
|
79 | - $this->strategy = $strategy; |
|
80 | - $this->trigger = $trigger; |
|
81 | - $this->setTriggerValue($args); |
|
82 | - $this->setData($args); |
|
83 | - } |
|
66 | + /** |
|
67 | + * AutomatedAction constructor. |
|
68 | + * |
|
69 | + * @param \stdClass $args |
|
70 | + * @param AutomatedActionStrategy $strategy |
|
71 | + * @param TriggerStrategy $trigger |
|
72 | + * @throws \DomainException |
|
73 | + */ |
|
74 | + public function __construct(\stdClass $args, AutomatedActionStrategy $strategy, TriggerStrategy $trigger) |
|
75 | + { |
|
76 | + $this->setID($args); |
|
77 | + $this->setName($args); |
|
78 | + $this->setDescription($args); |
|
79 | + $this->strategy = $strategy; |
|
80 | + $this->trigger = $trigger; |
|
81 | + $this->setTriggerValue($args); |
|
82 | + $this->setData($args); |
|
83 | + } |
|
84 | 84 | |
85 | 85 | |
86 | 86 | |
87 | - /** |
|
88 | - * @return int |
|
89 | - */ |
|
90 | - public function getID() |
|
91 | - { |
|
92 | - return $this->ID; |
|
93 | - } |
|
87 | + /** |
|
88 | + * @return int |
|
89 | + */ |
|
90 | + public function getID() |
|
91 | + { |
|
92 | + return $this->ID; |
|
93 | + } |
|
94 | 94 | |
95 | 95 | |
96 | 96 | |
97 | - /** |
|
98 | - * @param \stdClass $args |
|
99 | - * @throws \DomainException |
|
100 | - */ |
|
101 | - protected function setID(\stdClass $args) |
|
102 | - { |
|
103 | - $this->ID = isset($args->AMA_ID) ? absint($args->AMA_ID) : 0; |
|
104 | - if (! $this->ID){ |
|
105 | - throw new \DomainException(); |
|
106 | - } |
|
97 | + /** |
|
98 | + * @param \stdClass $args |
|
99 | + * @throws \DomainException |
|
100 | + */ |
|
101 | + protected function setID(\stdClass $args) |
|
102 | + { |
|
103 | + $this->ID = isset($args->AMA_ID) ? absint($args->AMA_ID) : 0; |
|
104 | + if (! $this->ID){ |
|
105 | + throw new \DomainException(); |
|
106 | + } |
|
107 | 107 | |
108 | - } |
|
108 | + } |
|
109 | 109 | |
110 | 110 | |
111 | 111 | |
112 | - /** |
|
113 | - * @return string |
|
114 | - */ |
|
115 | - public function getName() |
|
116 | - { |
|
117 | - return $this->name; |
|
118 | - } |
|
112 | + /** |
|
113 | + * @return string |
|
114 | + */ |
|
115 | + public function getName() |
|
116 | + { |
|
117 | + return $this->name; |
|
118 | + } |
|
119 | 119 | |
120 | 120 | |
121 | 121 | |
122 | - /** |
|
123 | - * @param \stdClass $args |
|
124 | - * @throws \DomainException |
|
125 | - */ |
|
126 | - protected function setName(\stdClass $args) |
|
127 | - { |
|
128 | - $this->name = isset($args->AMA_name) ? sanitize_text_field($args->AMA_name) : ''; |
|
129 | - if (empty($this->name)) { |
|
130 | - throw new \DomainException(); |
|
131 | - } |
|
132 | - } |
|
122 | + /** |
|
123 | + * @param \stdClass $args |
|
124 | + * @throws \DomainException |
|
125 | + */ |
|
126 | + protected function setName(\stdClass $args) |
|
127 | + { |
|
128 | + $this->name = isset($args->AMA_name) ? sanitize_text_field($args->AMA_name) : ''; |
|
129 | + if (empty($this->name)) { |
|
130 | + throw new \DomainException(); |
|
131 | + } |
|
132 | + } |
|
133 | 133 | |
134 | 134 | |
135 | 135 | |
136 | - /** |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - public function getDescription() |
|
140 | - { |
|
141 | - return $this->description; |
|
142 | - } |
|
136 | + /** |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + public function getDescription() |
|
140 | + { |
|
141 | + return $this->description; |
|
142 | + } |
|
143 | 143 | |
144 | 144 | |
145 | 145 | |
146 | - /** |
|
147 | - * @param \stdClass $args |
|
148 | - */ |
|
149 | - protected function setDescription(\stdClass $args) |
|
150 | - { |
|
151 | - $this->description = isset($args->AMA_description) ? sanitize_text_field($args->AMA_description) : ''; |
|
152 | - } |
|
146 | + /** |
|
147 | + * @param \stdClass $args |
|
148 | + */ |
|
149 | + protected function setDescription(\stdClass $args) |
|
150 | + { |
|
151 | + $this->description = isset($args->AMA_description) ? sanitize_text_field($args->AMA_description) : ''; |
|
152 | + } |
|
153 | 153 | |
154 | 154 | |
155 | 155 | |
156 | - /** |
|
157 | - * @return AutomatedActionStrategy |
|
158 | - */ |
|
159 | - public function getStrategy() |
|
160 | - { |
|
161 | - return $this->strategy; |
|
162 | - } |
|
156 | + /** |
|
157 | + * @return AutomatedActionStrategy |
|
158 | + */ |
|
159 | + public function getStrategy() |
|
160 | + { |
|
161 | + return $this->strategy; |
|
162 | + } |
|
163 | 163 | |
164 | 164 | |
165 | 165 | |
166 | 166 | |
167 | - /** |
|
168 | - * @return TriggerStrategy |
|
169 | - */ |
|
170 | - public function getTrigger() |
|
171 | - { |
|
172 | - return $this->trigger; |
|
173 | - } |
|
167 | + /** |
|
168 | + * @return TriggerStrategy |
|
169 | + */ |
|
170 | + public function getTrigger() |
|
171 | + { |
|
172 | + return $this->trigger; |
|
173 | + } |
|
174 | 174 | |
175 | 175 | |
176 | 176 | |
177 | - /** |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - public function getTriggerValue() |
|
181 | - { |
|
182 | - return $this->trigger_value; |
|
183 | - } |
|
184 | - |
|
177 | + /** |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + public function getTriggerValue() |
|
181 | + { |
|
182 | + return $this->trigger_value; |
|
183 | + } |
|
185 | 184 | |
186 | - /** |
|
187 | - * @param \stdClass $args |
|
188 | - */ |
|
189 | - protected function setTriggerValue(\stdClass $args) |
|
190 | - { |
|
191 | - $this->trigger_value = isset($args->AMA_trigger_value) ? sanitize_text_field($args->AMA_trigger_value) : ''; |
|
192 | - } |
|
193 | 185 | |
186 | + /** |
|
187 | + * @param \stdClass $args |
|
188 | + */ |
|
189 | + protected function setTriggerValue(\stdClass $args) |
|
190 | + { |
|
191 | + $this->trigger_value = isset($args->AMA_trigger_value) ? sanitize_text_field($args->AMA_trigger_value) : ''; |
|
192 | + } |
|
194 | 193 | |
195 | 194 | |
196 | - /** |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - public function getData() |
|
200 | - { |
|
201 | - return $this->data; |
|
202 | - } |
|
203 | 195 | |
196 | + /** |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + public function getData() |
|
200 | + { |
|
201 | + return $this->data; |
|
202 | + } |
|
204 | 203 | |
205 | 204 | |
206 | - /** |
|
207 | - * @param \stdClass $args |
|
208 | - * @throws \DomainException |
|
209 | - */ |
|
210 | - protected function setData(\stdClass $args) |
|
211 | - { |
|
212 | - $this->data = isset($args->AMA_data) ? sanitize_text_field($args->AMA_data) : ''; |
|
213 | - if ($this->data !== null) { |
|
214 | - $this->data = json_decode($this->data); |
|
215 | - if (json_last_error() !== JSON_ERROR_NONE) { |
|
216 | - throw new \DomainException(json_last_error_msg()); |
|
217 | - } |
|
218 | - } |
|
219 | - } |
|
220 | 205 | |
206 | + /** |
|
207 | + * @param \stdClass $args |
|
208 | + * @throws \DomainException |
|
209 | + */ |
|
210 | + protected function setData(\stdClass $args) |
|
211 | + { |
|
212 | + $this->data = isset($args->AMA_data) ? sanitize_text_field($args->AMA_data) : ''; |
|
213 | + if ($this->data !== null) { |
|
214 | + $this->data = json_decode($this->data); |
|
215 | + if (json_last_error() !== JSON_ERROR_NONE) { |
|
216 | + throw new \DomainException(json_last_error_msg()); |
|
217 | + } |
|
218 | + } |
|
219 | + } |
|
221 | 220 | |
222 | 221 | |
223 | - /** |
|
224 | - * @param CapCheckInterface $cap_check |
|
225 | - */ |
|
226 | - public function setCapCheck(CapCheckInterface $cap_check) |
|
227 | - { |
|
228 | - $this->cap_check = $cap_check; |
|
229 | - } |
|
222 | + |
|
223 | + /** |
|
224 | + * @param CapCheckInterface $cap_check |
|
225 | + */ |
|
226 | + public function setCapCheck(CapCheckInterface $cap_check) |
|
227 | + { |
|
228 | + $this->cap_check = $cap_check; |
|
229 | + } |
|
230 | 230 | |
231 | 231 | |
232 | 232 | |
233 | - /** |
|
234 | - * not to be confused with being a setter for the $trigger property, |
|
235 | - * but instead informs the trigger to set hooks or similar initialization |
|
236 | - * |
|
237 | - * @return void |
|
238 | - */ |
|
239 | - public function setTrigger() |
|
240 | - { |
|
241 | - $this->trigger->set($this); |
|
242 | - } |
|
233 | + /** |
|
234 | + * not to be confused with being a setter for the $trigger property, |
|
235 | + * but instead informs the trigger to set hooks or similar initialization |
|
236 | + * |
|
237 | + * @return void |
|
238 | + */ |
|
239 | + public function setTrigger() |
|
240 | + { |
|
241 | + $this->trigger->set($this); |
|
242 | + } |
|
243 | 243 | |
244 | 244 | |
245 | 245 | |
246 | - /** |
|
247 | - * @return bool |
|
248 | - */ |
|
249 | - public function triggerPulled() |
|
250 | - { |
|
251 | - // \EEH_Debug_Tools::printr($this->trigger->pulled(), '$this->trigger->pulled()', __FILE__, __LINE__); |
|
252 | - return $this->trigger->pulled(); |
|
253 | - } |
|
246 | + /** |
|
247 | + * @return bool |
|
248 | + */ |
|
249 | + public function triggerPulled() |
|
250 | + { |
|
251 | + // \EEH_Debug_Tools::printr($this->trigger->pulled(), '$this->trigger->pulled()', __FILE__, __LINE__); |
|
252 | + return $this->trigger->pulled(); |
|
253 | + } |
|
254 | 254 | |
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * @return bool |
|
259 | - */ |
|
260 | - public function hasRun() |
|
261 | - { |
|
262 | - // \EEH_Debug_Tools::printr($this->strategy->hasRun(), '$this->strategy->hasRun()', __FILE__, __LINE__); |
|
263 | - return $this->strategy->hasRun(); |
|
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * by default this is called during the "shutdown" |
|
270 | - * in AutomatedActionManager::processActions(), |
|
271 | - * but individual AutomatedActionStrategy classes |
|
272 | - * can run their callback() method whenever it is best, |
|
273 | - * as long as they call setHasRun() to avoid duplication |
|
274 | - */ |
|
275 | - public function process() |
|
276 | - { |
|
277 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
278 | - // \EEH_Debug_Tools::printr($this->description, $this->name, __FILE__, __LINE__); |
|
279 | - $this->strategy->callback( |
|
280 | - $this->trigger->getCallbackArgs() |
|
281 | - ); |
|
282 | - } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * @return bool |
|
259 | + */ |
|
260 | + public function hasRun() |
|
261 | + { |
|
262 | + // \EEH_Debug_Tools::printr($this->strategy->hasRun(), '$this->strategy->hasRun()', __FILE__, __LINE__); |
|
263 | + return $this->strategy->hasRun(); |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * by default this is called during the "shutdown" |
|
270 | + * in AutomatedActionManager::processActions(), |
|
271 | + * but individual AutomatedActionStrategy classes |
|
272 | + * can run their callback() method whenever it is best, |
|
273 | + * as long as they call setHasRun() to avoid duplication |
|
274 | + */ |
|
275 | + public function process() |
|
276 | + { |
|
277 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
278 | + // \EEH_Debug_Tools::printr($this->description, $this->name, __FILE__, __LINE__); |
|
279 | + $this->strategy->callback( |
|
280 | + $this->trigger->getCallbackArgs() |
|
281 | + ); |
|
282 | + } |
|
283 | 283 | |
284 | 284 | } |
285 | 285 | // End of file AutomatedAction.php |
@@ -23,221 +23,221 @@ |
||
23 | 23 | abstract class TriggerStrategy |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var RuleManager $rule_manager |
|
28 | - */ |
|
29 | - private $rule_manager; |
|
26 | + /** |
|
27 | + * @var RuleManager $rule_manager |
|
28 | + */ |
|
29 | + private $rule_manager; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @var AutomatedActionInterface $automated_action |
|
33 | - */ |
|
34 | - private $automated_action; |
|
31 | + /** |
|
32 | + * @var AutomatedActionInterface $automated_action |
|
33 | + */ |
|
34 | + private $automated_action; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var array $callback_args |
|
38 | - */ |
|
39 | - private $callback_args = array(); |
|
36 | + /** |
|
37 | + * @var array $callback_args |
|
38 | + */ |
|
39 | + private $callback_args = array(); |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var boolean $pulled |
|
43 | - */ |
|
44 | - private $pulled = false; |
|
41 | + /** |
|
42 | + * @var boolean $pulled |
|
43 | + */ |
|
44 | + private $pulled = false; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @var Collection $rules |
|
48 | - */ |
|
49 | - private $rules; |
|
46 | + /** |
|
47 | + * @var Collection $rules |
|
48 | + */ |
|
49 | + private $rules; |
|
50 | 50 | |
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * TriggerStrategy constructor. |
|
55 | - * |
|
56 | - * @param RuleManager $rule_manager |
|
57 | - */ |
|
58 | - public function __construct(RuleManager $rule_manager) |
|
59 | - { |
|
60 | - $this->rule_manager = $rule_manager; |
|
61 | - } |
|
53 | + /** |
|
54 | + * TriggerStrategy constructor. |
|
55 | + * |
|
56 | + * @param RuleManager $rule_manager |
|
57 | + */ |
|
58 | + public function __construct(RuleManager $rule_manager) |
|
59 | + { |
|
60 | + $this->rule_manager = $rule_manager; |
|
61 | + } |
|
62 | 62 | |
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * @return AutomatedActionInterface |
|
67 | - */ |
|
68 | - public function getAutomatedAction() |
|
69 | - { |
|
70 | - return $this->automated_action; |
|
71 | - } |
|
65 | + /** |
|
66 | + * @return AutomatedActionInterface |
|
67 | + */ |
|
68 | + public function getAutomatedAction() |
|
69 | + { |
|
70 | + return $this->automated_action; |
|
71 | + } |
|
72 | 72 | |
73 | 73 | |
74 | 74 | |
75 | - /** |
|
76 | - * @param \EventEspresso\core\services\automated_actions\AutomatedActionInterface $automated_action |
|
77 | - */ |
|
78 | - public function setAutomatedAction(AutomatedActionInterface $automated_action) { |
|
79 | - $this->automated_action = $automated_action; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @return array |
|
87 | - */ |
|
88 | - public function getCallbackArgs() |
|
89 | - { |
|
90 | - return $this->callback_args; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @param array $callback_args |
|
97 | - */ |
|
98 | - public function setCallbackArgs(array $callback_args = array()) |
|
99 | - { |
|
100 | - $this->callback_args = $callback_args; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @return bool |
|
107 | - */ |
|
108 | - public function pulled() |
|
109 | - { |
|
110 | - return $this->pulled; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @param bool $pulled |
|
117 | - */ |
|
118 | - public function setPulled($pulled = true) |
|
119 | - { |
|
120 | - $this->pulled = filter_var($pulled, FILTER_VALIDATE_BOOLEAN); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @return Collection |
|
127 | - * @throws InvalidArgumentException |
|
128 | - * @throws InvalidInterfaceException |
|
129 | - * @throws InvalidEntityException |
|
130 | - * @throws DomainException |
|
131 | - */ |
|
132 | - public function getRules() |
|
133 | - { |
|
134 | - if ($this->rules === null) { |
|
135 | - $this->setRules(); |
|
136 | - } |
|
137 | - return $this->rules; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @return void |
|
144 | - * @throws InvalidArgumentException |
|
145 | - * @throws InvalidInterfaceException |
|
146 | - * @throws InvalidEntityException |
|
147 | - * @throws DomainException |
|
148 | - */ |
|
149 | - private function setRules() |
|
150 | - { |
|
151 | - $this->rules = $this->rule_manager->retrieveRulesForObject( |
|
152 | - 'Automated Action', |
|
153 | - $this->automated_action->getID() |
|
154 | - ); |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * This is required and should be overridden by all non-cron type triggers, |
|
161 | - * as it allows strategies to set up whatever hooks are necessary to trigger their logic. |
|
162 | - * Cron related strategies do not need to implement this method |
|
163 | - * as this one will be used and do nothing but capture the incoming data |
|
164 | - * |
|
165 | - * @param AutomatedActionInterface $automated_action |
|
166 | - */ |
|
167 | - public function set(AutomatedActionInterface $automated_action) |
|
168 | - { |
|
169 | - $this->automated_action = $automated_action; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * callback method for all strategies (regardless of type), |
|
176 | - * that runs when the trigger is "pulled". |
|
177 | - * At this point strategies should ONLY proceed to collect data |
|
178 | - * required for the action, store it for later processing, |
|
179 | - * and call setPulled() to indicate that the trigger was successful |
|
180 | - * (meaning data results for the action were retrieved). |
|
181 | - * This allows control over when that happens |
|
182 | - * because the moment the trigger is pulled |
|
183 | - * may not be the most optimum time for data processing. |
|
184 | - * By default, logic processing will occur during "shutdown", |
|
185 | - * but can be overridden by an AutomatedActionStrategy class |
|
186 | - * |
|
187 | - * @throws InvalidArgumentException |
|
188 | - * @throws InvalidInterfaceException |
|
189 | - * @throws InvalidEntityException |
|
190 | - * @throws DomainException |
|
191 | - */ |
|
192 | - public function triggerCallback() { |
|
193 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
194 | - $this->setCallbackArgs(func_get_args()); |
|
195 | - $this->execute( |
|
196 | - $this->getQueryParamsForRules() |
|
197 | - ); |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @return array |
|
204 | - * @throws InvalidArgumentException |
|
205 | - * @throws InvalidInterfaceException |
|
206 | - * @throws InvalidEntityException |
|
207 | - * @throws DomainException |
|
208 | - */ |
|
209 | - public function getQueryParamsForRules() |
|
210 | - { |
|
211 | - return $this->rule_manager->getQueryParamsForRules( |
|
212 | - $this->getRules() |
|
213 | - ); |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * when a trigger has been "pulled", |
|
220 | - * either by a do_action or scheduled cron, |
|
221 | - * this is the TriggerStrategy method that will run |
|
222 | - * to continue processing the trigger. |
|
223 | - * This will typically mean retrieving objects from the db. |
|
224 | - * By default, this method does nothing but set callback args |
|
225 | - * to be used for querying during the 'shutdown' hook when |
|
226 | - * AutomatedActionManager::processActions() runs, |
|
227 | - * but can be overridden to perform querying now. |
|
228 | - * |
|
229 | - * @param array $query_params |
|
230 | - * @return void |
|
231 | - */ |
|
232 | - public function execute(array $query_params) |
|
233 | - { |
|
234 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
235 | - $this->setCallbackArgs( |
|
236 | - array_merge($this->callback_args, array('query_params' => $query_params)) |
|
237 | - ); |
|
238 | - // \EEH_Debug_Tools::printr($this->callback_args, '$this->callback_args', __FILE__, __LINE__); |
|
239 | - $this->setPulled(); |
|
240 | - } |
|
75 | + /** |
|
76 | + * @param \EventEspresso\core\services\automated_actions\AutomatedActionInterface $automated_action |
|
77 | + */ |
|
78 | + public function setAutomatedAction(AutomatedActionInterface $automated_action) { |
|
79 | + $this->automated_action = $automated_action; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @return array |
|
87 | + */ |
|
88 | + public function getCallbackArgs() |
|
89 | + { |
|
90 | + return $this->callback_args; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @param array $callback_args |
|
97 | + */ |
|
98 | + public function setCallbackArgs(array $callback_args = array()) |
|
99 | + { |
|
100 | + $this->callback_args = $callback_args; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @return bool |
|
107 | + */ |
|
108 | + public function pulled() |
|
109 | + { |
|
110 | + return $this->pulled; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @param bool $pulled |
|
117 | + */ |
|
118 | + public function setPulled($pulled = true) |
|
119 | + { |
|
120 | + $this->pulled = filter_var($pulled, FILTER_VALIDATE_BOOLEAN); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @return Collection |
|
127 | + * @throws InvalidArgumentException |
|
128 | + * @throws InvalidInterfaceException |
|
129 | + * @throws InvalidEntityException |
|
130 | + * @throws DomainException |
|
131 | + */ |
|
132 | + public function getRules() |
|
133 | + { |
|
134 | + if ($this->rules === null) { |
|
135 | + $this->setRules(); |
|
136 | + } |
|
137 | + return $this->rules; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @return void |
|
144 | + * @throws InvalidArgumentException |
|
145 | + * @throws InvalidInterfaceException |
|
146 | + * @throws InvalidEntityException |
|
147 | + * @throws DomainException |
|
148 | + */ |
|
149 | + private function setRules() |
|
150 | + { |
|
151 | + $this->rules = $this->rule_manager->retrieveRulesForObject( |
|
152 | + 'Automated Action', |
|
153 | + $this->automated_action->getID() |
|
154 | + ); |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * This is required and should be overridden by all non-cron type triggers, |
|
161 | + * as it allows strategies to set up whatever hooks are necessary to trigger their logic. |
|
162 | + * Cron related strategies do not need to implement this method |
|
163 | + * as this one will be used and do nothing but capture the incoming data |
|
164 | + * |
|
165 | + * @param AutomatedActionInterface $automated_action |
|
166 | + */ |
|
167 | + public function set(AutomatedActionInterface $automated_action) |
|
168 | + { |
|
169 | + $this->automated_action = $automated_action; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * callback method for all strategies (regardless of type), |
|
176 | + * that runs when the trigger is "pulled". |
|
177 | + * At this point strategies should ONLY proceed to collect data |
|
178 | + * required for the action, store it for later processing, |
|
179 | + * and call setPulled() to indicate that the trigger was successful |
|
180 | + * (meaning data results for the action were retrieved). |
|
181 | + * This allows control over when that happens |
|
182 | + * because the moment the trigger is pulled |
|
183 | + * may not be the most optimum time for data processing. |
|
184 | + * By default, logic processing will occur during "shutdown", |
|
185 | + * but can be overridden by an AutomatedActionStrategy class |
|
186 | + * |
|
187 | + * @throws InvalidArgumentException |
|
188 | + * @throws InvalidInterfaceException |
|
189 | + * @throws InvalidEntityException |
|
190 | + * @throws DomainException |
|
191 | + */ |
|
192 | + public function triggerCallback() { |
|
193 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
194 | + $this->setCallbackArgs(func_get_args()); |
|
195 | + $this->execute( |
|
196 | + $this->getQueryParamsForRules() |
|
197 | + ); |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @return array |
|
204 | + * @throws InvalidArgumentException |
|
205 | + * @throws InvalidInterfaceException |
|
206 | + * @throws InvalidEntityException |
|
207 | + * @throws DomainException |
|
208 | + */ |
|
209 | + public function getQueryParamsForRules() |
|
210 | + { |
|
211 | + return $this->rule_manager->getQueryParamsForRules( |
|
212 | + $this->getRules() |
|
213 | + ); |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * when a trigger has been "pulled", |
|
220 | + * either by a do_action or scheduled cron, |
|
221 | + * this is the TriggerStrategy method that will run |
|
222 | + * to continue processing the trigger. |
|
223 | + * This will typically mean retrieving objects from the db. |
|
224 | + * By default, this method does nothing but set callback args |
|
225 | + * to be used for querying during the 'shutdown' hook when |
|
226 | + * AutomatedActionManager::processActions() runs, |
|
227 | + * but can be overridden to perform querying now. |
|
228 | + * |
|
229 | + * @param array $query_params |
|
230 | + * @return void |
|
231 | + */ |
|
232 | + public function execute(array $query_params) |
|
233 | + { |
|
234 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
235 | + $this->setCallbackArgs( |
|
236 | + array_merge($this->callback_args, array('query_params' => $query_params)) |
|
237 | + ); |
|
238 | + // \EEH_Debug_Tools::printr($this->callback_args, '$this->callback_args', __FILE__, __LINE__); |
|
239 | + $this->setPulled(); |
|
240 | + } |
|
241 | 241 | |
242 | 242 | |
243 | 243 | } |
@@ -23,134 +23,134 @@ |
||
23 | 23 | class RuleManager |
24 | 24 | { |
25 | 25 | |
26 | - const RULE_TYPE_QUERY = 'query'; |
|
27 | - const RULE_TYPE_OBJECT = 'object'; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var QueryParamGenerator $query_generator |
|
31 | - */ |
|
32 | - private $query_generator; |
|
33 | - |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * RuleManager constructor |
|
38 | - * |
|
39 | - * @param QueryParamGenerator $query_generator |
|
40 | - * @throws InvalidInterfaceException |
|
41 | - */ |
|
42 | - public function __construct(QueryParamGenerator $query_generator) |
|
43 | - { |
|
44 | - $this->query_generator = $query_generator; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * @param \stdClass[] $results |
|
51 | - * @return Collection |
|
52 | - * @throws InvalidInterfaceException |
|
53 | - * @throws InvalidArgumentException |
|
54 | - * @throws InvalidEntityException |
|
55 | - */ |
|
56 | - protected function getRulesCollection(array $results) |
|
57 | - { |
|
58 | - Benchmark::startTimer(__METHOD__); |
|
59 | - $rules = new Collection('EventEspresso\core\services\conditional_logic\rules\Rule'); |
|
60 | - foreach ($results as $result) { |
|
61 | - $rules->add(new Rule($result)); |
|
62 | - } |
|
63 | - Benchmark::stopTimer(__METHOD__); |
|
64 | - return $rules; |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @param string $OBJ_name |
|
71 | - * @param mixed $OBJ_ID |
|
72 | - * @return array |
|
73 | - * @throws DomainException |
|
74 | - */ |
|
75 | - public function retrieveRules($OBJ_name, $OBJ_ID) |
|
76 | - { |
|
77 | - Benchmark::startTimer(__METHOD__); |
|
78 | - global $wpdb; |
|
79 | - $results = $wpdb->get_results( |
|
80 | - $wpdb->prepare( |
|
81 | - "SELECT * FROM {$wpdb->prefix}esp_object_rule AS object_rule |
|
26 | + const RULE_TYPE_QUERY = 'query'; |
|
27 | + const RULE_TYPE_OBJECT = 'object'; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var QueryParamGenerator $query_generator |
|
31 | + */ |
|
32 | + private $query_generator; |
|
33 | + |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * RuleManager constructor |
|
38 | + * |
|
39 | + * @param QueryParamGenerator $query_generator |
|
40 | + * @throws InvalidInterfaceException |
|
41 | + */ |
|
42 | + public function __construct(QueryParamGenerator $query_generator) |
|
43 | + { |
|
44 | + $this->query_generator = $query_generator; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * @param \stdClass[] $results |
|
51 | + * @return Collection |
|
52 | + * @throws InvalidInterfaceException |
|
53 | + * @throws InvalidArgumentException |
|
54 | + * @throws InvalidEntityException |
|
55 | + */ |
|
56 | + protected function getRulesCollection(array $results) |
|
57 | + { |
|
58 | + Benchmark::startTimer(__METHOD__); |
|
59 | + $rules = new Collection('EventEspresso\core\services\conditional_logic\rules\Rule'); |
|
60 | + foreach ($results as $result) { |
|
61 | + $rules->add(new Rule($result)); |
|
62 | + } |
|
63 | + Benchmark::stopTimer(__METHOD__); |
|
64 | + return $rules; |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @param string $OBJ_name |
|
71 | + * @param mixed $OBJ_ID |
|
72 | + * @return array |
|
73 | + * @throws DomainException |
|
74 | + */ |
|
75 | + public function retrieveRules($OBJ_name, $OBJ_ID) |
|
76 | + { |
|
77 | + Benchmark::startTimer(__METHOD__); |
|
78 | + global $wpdb; |
|
79 | + $results = $wpdb->get_results( |
|
80 | + $wpdb->prepare( |
|
81 | + "SELECT * FROM {$wpdb->prefix}esp_object_rule AS object_rule |
|
82 | 82 | LEFT JOIN {$wpdb->prefix}esp_rule AS rule |
83 | 83 | ON object_rule.RUL_ID = rule.RUL_ID |
84 | 84 | WHERE object_rule.ORL_OBJ_name = %s |
85 | 85 | AND object_rule.ORL_OBJ_ID = %d |
86 | 86 | ORDER BY object_rule.ORL_order", |
87 | - $OBJ_name, |
|
88 | - $OBJ_ID |
|
89 | - ) |
|
90 | - ); |
|
91 | - // \EEH_Debug_Tools::printr($results, '$results', __FILE__, __LINE__); |
|
92 | - if ($results instanceof \WP_Error) { |
|
93 | - throw new DomainException( |
|
94 | - $results->get_error_message() |
|
95 | - ); |
|
96 | - } |
|
97 | - $results = is_array($results) ? $results : array($results); |
|
98 | - Benchmark::stopTimer(__METHOD__); |
|
99 | - return $results; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * @param string $OBJ_name |
|
106 | - * @param mixed $OBJ_ID |
|
107 | - * @return Collection |
|
108 | - * @throws InvalidArgumentException |
|
109 | - * @throws InvalidInterfaceException |
|
110 | - * @throws InvalidEntityException |
|
111 | - * @throws DomainException |
|
112 | - */ |
|
113 | - public function retrieveRulesForObject( $OBJ_name = '', $OBJ_ID ) |
|
114 | - { |
|
115 | - return $this->getRulesCollection( |
|
116 | - $this->retrieveRules($OBJ_name, $OBJ_ID) |
|
117 | - ); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @param string $OBJ_name |
|
124 | - * @param mixed $OBJ_ID |
|
125 | - * @return array |
|
126 | - * @throws InvalidArgumentException |
|
127 | - * @throws InvalidInterfaceException |
|
128 | - * @throws InvalidEntityException |
|
129 | - * @throws DomainException |
|
130 | - */ |
|
131 | - public function getQueryParamsForObjectRules( $OBJ_name = '', $OBJ_ID ) |
|
132 | - { |
|
133 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
134 | - return $this->getQueryParamsForRules( |
|
135 | - $this->getRulesCollection( |
|
136 | - $this->retrieveRules($OBJ_name, $OBJ_ID) |
|
137 | - ) |
|
138 | - ); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @param Collection $rules |
|
145 | - * @return array |
|
146 | - */ |
|
147 | - public function getQueryParamsForRules(Collection $rules) |
|
148 | - { |
|
149 | - $this->query_generator->addRules($rules); |
|
150 | - $SQL = $this->query_generator->generateQueryParams(RuleManager::RULE_TYPE_QUERY); |
|
151 | - // \EEH_Debug_Tools::printr($SQL, '$SQL', __FILE__, __LINE__); |
|
152 | - return $SQL; |
|
153 | - } |
|
87 | + $OBJ_name, |
|
88 | + $OBJ_ID |
|
89 | + ) |
|
90 | + ); |
|
91 | + // \EEH_Debug_Tools::printr($results, '$results', __FILE__, __LINE__); |
|
92 | + if ($results instanceof \WP_Error) { |
|
93 | + throw new DomainException( |
|
94 | + $results->get_error_message() |
|
95 | + ); |
|
96 | + } |
|
97 | + $results = is_array($results) ? $results : array($results); |
|
98 | + Benchmark::stopTimer(__METHOD__); |
|
99 | + return $results; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * @param string $OBJ_name |
|
106 | + * @param mixed $OBJ_ID |
|
107 | + * @return Collection |
|
108 | + * @throws InvalidArgumentException |
|
109 | + * @throws InvalidInterfaceException |
|
110 | + * @throws InvalidEntityException |
|
111 | + * @throws DomainException |
|
112 | + */ |
|
113 | + public function retrieveRulesForObject( $OBJ_name = '', $OBJ_ID ) |
|
114 | + { |
|
115 | + return $this->getRulesCollection( |
|
116 | + $this->retrieveRules($OBJ_name, $OBJ_ID) |
|
117 | + ); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @param string $OBJ_name |
|
124 | + * @param mixed $OBJ_ID |
|
125 | + * @return array |
|
126 | + * @throws InvalidArgumentException |
|
127 | + * @throws InvalidInterfaceException |
|
128 | + * @throws InvalidEntityException |
|
129 | + * @throws DomainException |
|
130 | + */ |
|
131 | + public function getQueryParamsForObjectRules( $OBJ_name = '', $OBJ_ID ) |
|
132 | + { |
|
133 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
134 | + return $this->getQueryParamsForRules( |
|
135 | + $this->getRulesCollection( |
|
136 | + $this->retrieveRules($OBJ_name, $OBJ_ID) |
|
137 | + ) |
|
138 | + ); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @param Collection $rules |
|
145 | + * @return array |
|
146 | + */ |
|
147 | + public function getQueryParamsForRules(Collection $rules) |
|
148 | + { |
|
149 | + $this->query_generator->addRules($rules); |
|
150 | + $SQL = $this->query_generator->generateQueryParams(RuleManager::RULE_TYPE_QUERY); |
|
151 | + // \EEH_Debug_Tools::printr($SQL, '$SQL', __FILE__, __LINE__); |
|
152 | + return $SQL; |
|
153 | + } |
|
154 | 154 | |
155 | 155 | |
156 | 156 | } |
@@ -8,35 +8,35 @@ |
||
8 | 8 | abstract class RuleStrategy |
9 | 9 | { |
10 | 10 | |
11 | - /** |
|
12 | - * @var string $target |
|
13 | - */ |
|
14 | - protected $target = ''; |
|
15 | - |
|
16 | - /** |
|
17 | - * @var string $comparison |
|
18 | - */ |
|
19 | - protected $comparison = ''; |
|
20 | - |
|
21 | - /** |
|
22 | - * @var string $value |
|
23 | - */ |
|
24 | - protected $value = ''; |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * @param \EventEspresso\core\services\conditional_logic\rules\Rule $rule |
|
29 | - * @return mixed |
|
30 | - */ |
|
31 | - public function getQueryParamForRule(Rule $rule) { |
|
32 | - $this->comparison = $rule->getComparison(); |
|
33 | - $this->value = $rule->getValue(); |
|
34 | - $target = $rule->getTarget(); |
|
35 | - // \EEH_Debug_Tools::printr($target, '$target', __FILE__, __LINE__); |
|
36 | - return method_exists($this, $target) |
|
37 | - ? $this->{$target}() |
|
38 | - : "{$target} {$this->comparison} {$this->value}"; |
|
39 | - } |
|
11 | + /** |
|
12 | + * @var string $target |
|
13 | + */ |
|
14 | + protected $target = ''; |
|
15 | + |
|
16 | + /** |
|
17 | + * @var string $comparison |
|
18 | + */ |
|
19 | + protected $comparison = ''; |
|
20 | + |
|
21 | + /** |
|
22 | + * @var string $value |
|
23 | + */ |
|
24 | + protected $value = ''; |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * @param \EventEspresso\core\services\conditional_logic\rules\Rule $rule |
|
29 | + * @return mixed |
|
30 | + */ |
|
31 | + public function getQueryParamForRule(Rule $rule) { |
|
32 | + $this->comparison = $rule->getComparison(); |
|
33 | + $this->value = $rule->getValue(); |
|
34 | + $target = $rule->getTarget(); |
|
35 | + // \EEH_Debug_Tools::printr($target, '$target', __FILE__, __LINE__); |
|
36 | + return method_exists($this, $target) |
|
37 | + ? $this->{$target}() |
|
38 | + : "{$target} {$this->comparison} {$this->value}"; |
|
39 | + } |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | // End of file RuleStrategy.php |
@@ -18,184 +18,184 @@ |
||
18 | 18 | class QueryParamGenerator |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var Collection $rules |
|
23 | - */ |
|
24 | - private $rules; |
|
25 | - |
|
26 | - // /** |
|
27 | - // * @var array $query_params |
|
28 | - // */ |
|
29 | - // private $query_params; |
|
30 | - |
|
31 | - |
|
32 | - |
|
33 | - public function addRules(Collection $rules) |
|
34 | - { |
|
35 | - $this->rules = $rules; |
|
36 | - } |
|
37 | - |
|
38 | - |
|
39 | - |
|
40 | - public function resetRules() |
|
41 | - { |
|
42 | - $this->rules = null; |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - public function generateQueryParams($type = '') |
|
48 | - { |
|
49 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
50 | - $rules = $this->getRulesAsArray($type); |
|
51 | - // \EEH_Debug_Tools::printr($rules, 'Rules As Array', __FILE__, __LINE__); |
|
52 | - $query_params = $this->addQueryParamForRule($rules, array()); |
|
53 | - // \EEH_Debug_Tools::printr($query_params, '>>> $QUERY_PARAMS', __FILE__, __LINE__); |
|
54 | - return $query_params; |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - private function getRulesAsArray($type = '') |
|
60 | - { |
|
61 | - // \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
62 | - $rules_array = array(); |
|
63 | - foreach ($this->rules as $rule) { |
|
64 | - /** @var Rule $rule */ |
|
65 | - if ($type && $rule->getType() !== $type){ |
|
66 | - continue; |
|
67 | - } |
|
68 | - $rules_array = $this->addRuleToArray($rules_array, $rule); |
|
69 | - } |
|
70 | - return $rules_array; |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - |
|
75 | - private function addRuleToArray(array $rules_array, Rule $rule) |
|
76 | - { |
|
77 | - // static $level = 0; |
|
78 | - // \EEH_Debug_Tools::printr(__FUNCTION__, $level . ') ' .__CLASS__, __FILE__, __LINE__, 2); |
|
79 | - // \EEH_Debug_Tools::printr((string)$rule->getID(), 'ID', __FILE__, __LINE__); |
|
80 | - $parent = $rule->getParent(); |
|
81 | - // \EEH_Debug_Tools::printr((string)$parent, 'Parent', __FILE__, __LINE__); |
|
82 | - if ($rule->getOperator() === ')') { |
|
83 | - // $level--; |
|
84 | - // \EEH_Debug_Tools::printr('SUBGROUP', 'CLOSE', __FILE__, __LINE__); |
|
85 | - return $rules_array; |
|
86 | - } else if ( isset($rules_array[$parent])) { |
|
87 | - // $level++; |
|
88 | - // \EEH_Debug_Tools::printr('PARENT', 'FOUND', __FILE__, __LINE__); |
|
89 | - $rules_array[$parent] = $this->addRuleToArray($rules_array[$parent], $rule); |
|
90 | - return $rules_array; |
|
91 | - } else if (! empty($rules_array)){ |
|
92 | - // \EEH_Debug_Tools::printr('SUB ARRAY', 'FOUND', __FILE__, __LINE__); |
|
93 | - // \EEH_Debug_Tools::printr($rules_array, '$rules_array', __FILE__, __LINE__); |
|
94 | - foreach($rules_array as $ID => $rules) { |
|
95 | - // \EEH_Debug_Tools::printr($ID, '$rules_array $ID', __FILE__, __LINE__); |
|
96 | - if($ID === $parent) { |
|
97 | - // \EEH_Debug_Tools::printr($ID === $parent, '$ID === $parent', __FILE__, __LINE__); |
|
98 | - $rules_array[$ID] = $this->addRuleToArray($rules[$ID], $rule); |
|
99 | - return $rules_array; |
|
100 | - } |
|
101 | - } |
|
102 | - } |
|
103 | - // \EEH_Debug_Tools::printr( |
|
104 | - // $rule->getOperator() |
|
105 | - // . ' ' |
|
106 | - // . $rule->getTarget() |
|
107 | - // . ' ' |
|
108 | - // . $rule->getComparison() |
|
109 | - // . ' ' |
|
110 | - // . $rule->getValue(), 'ADD RULE', |
|
111 | - // __FILE__, __LINE__ |
|
112 | - // ); |
|
113 | - $rules_array[$rule->getID()] = array(); |
|
114 | - $rules_array[$rule->getID()]['rule'] = $rule; |
|
115 | - return $rules_array; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - |
|
120 | - public function addQueryParamForRule($rules, array $query_params, $operator = ' AND ') |
|
121 | - { |
|
122 | - // \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
123 | - // \EEH_Debug_Tools::printr($rule, '$rule', __FILE__, __LINE__); |
|
124 | - foreach ($rules as $key => $rule) { |
|
125 | - // \EEH_Debug_Tools::printr((string)$key, '2) $key', __FILE__, __LINE__); |
|
126 | - if (is_array($rule)) { |
|
127 | - // \EEH_Debug_Tools::printr(is_array($rule), 'is_array($rule)', __FILE__, __LINE__); |
|
128 | - $query_params = $this->addQueryParamForRule($rule, $query_params, $operator); |
|
129 | - } else { |
|
130 | - /** @var Rule $rule */ |
|
131 | - // \EEH_Debug_Tools::printr($rule, 'getQueryParamForRule', __FILE__, __LINE__); |
|
132 | - $operator = $rule->getOperator(); |
|
133 | - $parent = $rule->getParent(); |
|
134 | - $parent = $parent ? $parent : 0; |
|
135 | - if ( ! isset($query_params[$parent])) { |
|
136 | - $query_params[$parent] = array(); |
|
137 | - } |
|
138 | - \EEH_Debug_Tools::printr($operator, '$operator', __FILE__, __LINE__); |
|
139 | - \EEH_Debug_Tools::printr((string)$parent, '$parent', __FILE__, __LINE__); |
|
140 | - switch ($operator) { |
|
141 | - default : |
|
142 | - case ' '; |
|
143 | - case ' AND '; |
|
144 | - $query_params[$parent] = array_merge( |
|
145 | - $query_params[$parent], |
|
146 | - $this->getQueryParamForRule($rule) |
|
147 | - ); |
|
148 | - break; |
|
149 | - case ' OR '; |
|
150 | - $query_params[$parent] = array_merge( |
|
151 | - $query_params[$parent], |
|
152 | - array('OR' => $this->getQueryParamForRule($rule)) |
|
153 | - ); |
|
154 | - break; |
|
155 | - case ' AND ( '; |
|
156 | - $query_params[$parent] = array_merge( |
|
157 | - $query_params[$parent], |
|
158 | - array( $this->getQueryParamForRule($rule) ) |
|
159 | - ); |
|
160 | - break; |
|
161 | - case ' OR ( '; |
|
162 | - $query_params['OR'][$parent] = array_merge( |
|
163 | - $query_params['OR'][$parent], |
|
164 | - $this->getQueryParamForRule($rule) |
|
165 | - ); |
|
166 | - break; |
|
167 | - case ' ) '; |
|
168 | - break; |
|
169 | - } |
|
170 | - } |
|
171 | - } |
|
172 | - // \EEH_Debug_Tools::printr($query_params, '$query_params', __FILE__, __LINE__); |
|
173 | - return $query_params; |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - |
|
178 | - protected function getQueryParamForRule(Rule $rule) |
|
179 | - { |
|
180 | - // \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
181 | - $strategy = $rule->getStrategy(); |
|
182 | - if ( |
|
183 | - ! class_exists($strategy) |
|
184 | - || ! is_subclass_of($strategy, '\EventEspresso\core\services\conditional_logic\rules\RuleStrategy') |
|
185 | - ){ |
|
186 | - throw new \DomainException( |
|
187 | - sprintf( |
|
188 | - esc_html__('The "%1$s" class is either missing or not a valid Rule Strategy.', 'event_espresso'), |
|
189 | - $strategy |
|
190 | - ) |
|
191 | - ); |
|
192 | - } |
|
193 | - /** @var RuleStrategy $strategy */ |
|
194 | - $strategy = new $strategy(); |
|
195 | - $query_param = $strategy->getQueryParamForRule($rule); |
|
196 | - // \EEH_Debug_Tools::printr($query_param, '$query_param', __FILE__, __LINE__); |
|
197 | - return $query_param; |
|
198 | - } |
|
21 | + /** |
|
22 | + * @var Collection $rules |
|
23 | + */ |
|
24 | + private $rules; |
|
25 | + |
|
26 | + // /** |
|
27 | + // * @var array $query_params |
|
28 | + // */ |
|
29 | + // private $query_params; |
|
30 | + |
|
31 | + |
|
32 | + |
|
33 | + public function addRules(Collection $rules) |
|
34 | + { |
|
35 | + $this->rules = $rules; |
|
36 | + } |
|
37 | + |
|
38 | + |
|
39 | + |
|
40 | + public function resetRules() |
|
41 | + { |
|
42 | + $this->rules = null; |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + public function generateQueryParams($type = '') |
|
48 | + { |
|
49 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
50 | + $rules = $this->getRulesAsArray($type); |
|
51 | + // \EEH_Debug_Tools::printr($rules, 'Rules As Array', __FILE__, __LINE__); |
|
52 | + $query_params = $this->addQueryParamForRule($rules, array()); |
|
53 | + // \EEH_Debug_Tools::printr($query_params, '>>> $QUERY_PARAMS', __FILE__, __LINE__); |
|
54 | + return $query_params; |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + private function getRulesAsArray($type = '') |
|
60 | + { |
|
61 | + // \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
62 | + $rules_array = array(); |
|
63 | + foreach ($this->rules as $rule) { |
|
64 | + /** @var Rule $rule */ |
|
65 | + if ($type && $rule->getType() !== $type){ |
|
66 | + continue; |
|
67 | + } |
|
68 | + $rules_array = $this->addRuleToArray($rules_array, $rule); |
|
69 | + } |
|
70 | + return $rules_array; |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + |
|
75 | + private function addRuleToArray(array $rules_array, Rule $rule) |
|
76 | + { |
|
77 | + // static $level = 0; |
|
78 | + // \EEH_Debug_Tools::printr(__FUNCTION__, $level . ') ' .__CLASS__, __FILE__, __LINE__, 2); |
|
79 | + // \EEH_Debug_Tools::printr((string)$rule->getID(), 'ID', __FILE__, __LINE__); |
|
80 | + $parent = $rule->getParent(); |
|
81 | + // \EEH_Debug_Tools::printr((string)$parent, 'Parent', __FILE__, __LINE__); |
|
82 | + if ($rule->getOperator() === ')') { |
|
83 | + // $level--; |
|
84 | + // \EEH_Debug_Tools::printr('SUBGROUP', 'CLOSE', __FILE__, __LINE__); |
|
85 | + return $rules_array; |
|
86 | + } else if ( isset($rules_array[$parent])) { |
|
87 | + // $level++; |
|
88 | + // \EEH_Debug_Tools::printr('PARENT', 'FOUND', __FILE__, __LINE__); |
|
89 | + $rules_array[$parent] = $this->addRuleToArray($rules_array[$parent], $rule); |
|
90 | + return $rules_array; |
|
91 | + } else if (! empty($rules_array)){ |
|
92 | + // \EEH_Debug_Tools::printr('SUB ARRAY', 'FOUND', __FILE__, __LINE__); |
|
93 | + // \EEH_Debug_Tools::printr($rules_array, '$rules_array', __FILE__, __LINE__); |
|
94 | + foreach($rules_array as $ID => $rules) { |
|
95 | + // \EEH_Debug_Tools::printr($ID, '$rules_array $ID', __FILE__, __LINE__); |
|
96 | + if($ID === $parent) { |
|
97 | + // \EEH_Debug_Tools::printr($ID === $parent, '$ID === $parent', __FILE__, __LINE__); |
|
98 | + $rules_array[$ID] = $this->addRuleToArray($rules[$ID], $rule); |
|
99 | + return $rules_array; |
|
100 | + } |
|
101 | + } |
|
102 | + } |
|
103 | + // \EEH_Debug_Tools::printr( |
|
104 | + // $rule->getOperator() |
|
105 | + // . ' ' |
|
106 | + // . $rule->getTarget() |
|
107 | + // . ' ' |
|
108 | + // . $rule->getComparison() |
|
109 | + // . ' ' |
|
110 | + // . $rule->getValue(), 'ADD RULE', |
|
111 | + // __FILE__, __LINE__ |
|
112 | + // ); |
|
113 | + $rules_array[$rule->getID()] = array(); |
|
114 | + $rules_array[$rule->getID()]['rule'] = $rule; |
|
115 | + return $rules_array; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + |
|
120 | + public function addQueryParamForRule($rules, array $query_params, $operator = ' AND ') |
|
121 | + { |
|
122 | + // \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
123 | + // \EEH_Debug_Tools::printr($rule, '$rule', __FILE__, __LINE__); |
|
124 | + foreach ($rules as $key => $rule) { |
|
125 | + // \EEH_Debug_Tools::printr((string)$key, '2) $key', __FILE__, __LINE__); |
|
126 | + if (is_array($rule)) { |
|
127 | + // \EEH_Debug_Tools::printr(is_array($rule), 'is_array($rule)', __FILE__, __LINE__); |
|
128 | + $query_params = $this->addQueryParamForRule($rule, $query_params, $operator); |
|
129 | + } else { |
|
130 | + /** @var Rule $rule */ |
|
131 | + // \EEH_Debug_Tools::printr($rule, 'getQueryParamForRule', __FILE__, __LINE__); |
|
132 | + $operator = $rule->getOperator(); |
|
133 | + $parent = $rule->getParent(); |
|
134 | + $parent = $parent ? $parent : 0; |
|
135 | + if ( ! isset($query_params[$parent])) { |
|
136 | + $query_params[$parent] = array(); |
|
137 | + } |
|
138 | + \EEH_Debug_Tools::printr($operator, '$operator', __FILE__, __LINE__); |
|
139 | + \EEH_Debug_Tools::printr((string)$parent, '$parent', __FILE__, __LINE__); |
|
140 | + switch ($operator) { |
|
141 | + default : |
|
142 | + case ' '; |
|
143 | + case ' AND '; |
|
144 | + $query_params[$parent] = array_merge( |
|
145 | + $query_params[$parent], |
|
146 | + $this->getQueryParamForRule($rule) |
|
147 | + ); |
|
148 | + break; |
|
149 | + case ' OR '; |
|
150 | + $query_params[$parent] = array_merge( |
|
151 | + $query_params[$parent], |
|
152 | + array('OR' => $this->getQueryParamForRule($rule)) |
|
153 | + ); |
|
154 | + break; |
|
155 | + case ' AND ( '; |
|
156 | + $query_params[$parent] = array_merge( |
|
157 | + $query_params[$parent], |
|
158 | + array( $this->getQueryParamForRule($rule) ) |
|
159 | + ); |
|
160 | + break; |
|
161 | + case ' OR ( '; |
|
162 | + $query_params['OR'][$parent] = array_merge( |
|
163 | + $query_params['OR'][$parent], |
|
164 | + $this->getQueryParamForRule($rule) |
|
165 | + ); |
|
166 | + break; |
|
167 | + case ' ) '; |
|
168 | + break; |
|
169 | + } |
|
170 | + } |
|
171 | + } |
|
172 | + // \EEH_Debug_Tools::printr($query_params, '$query_params', __FILE__, __LINE__); |
|
173 | + return $query_params; |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + |
|
178 | + protected function getQueryParamForRule(Rule $rule) |
|
179 | + { |
|
180 | + // \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
181 | + $strategy = $rule->getStrategy(); |
|
182 | + if ( |
|
183 | + ! class_exists($strategy) |
|
184 | + || ! is_subclass_of($strategy, '\EventEspresso\core\services\conditional_logic\rules\RuleStrategy') |
|
185 | + ){ |
|
186 | + throw new \DomainException( |
|
187 | + sprintf( |
|
188 | + esc_html__('The "%1$s" class is either missing or not a valid Rule Strategy.', 'event_espresso'), |
|
189 | + $strategy |
|
190 | + ) |
|
191 | + ); |
|
192 | + } |
|
193 | + /** @var RuleStrategy $strategy */ |
|
194 | + $strategy = new $strategy(); |
|
195 | + $query_param = $strategy->getQueryParamForRule($rule); |
|
196 | + // \EEH_Debug_Tools::printr($query_param, '$query_param', __FILE__, __LINE__); |
|
197 | + return $query_param; |
|
198 | + } |
|
199 | 199 | |
200 | 200 | } |
201 | 201 | // End of file QueryParamGenerator.php |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $rules_array = array(); |
63 | 63 | foreach ($this->rules as $rule) { |
64 | 64 | /** @var Rule $rule */ |
65 | - if ($type && $rule->getType() !== $type){ |
|
65 | + if ($type && $rule->getType() !== $type) { |
|
66 | 66 | continue; |
67 | 67 | } |
68 | 68 | $rules_array = $this->addRuleToArray($rules_array, $rule); |
@@ -83,17 +83,17 @@ discard block |
||
83 | 83 | // $level--; |
84 | 84 | // \EEH_Debug_Tools::printr('SUBGROUP', 'CLOSE', __FILE__, __LINE__); |
85 | 85 | return $rules_array; |
86 | - } else if ( isset($rules_array[$parent])) { |
|
86 | + } else if (isset($rules_array[$parent])) { |
|
87 | 87 | // $level++; |
88 | 88 | // \EEH_Debug_Tools::printr('PARENT', 'FOUND', __FILE__, __LINE__); |
89 | 89 | $rules_array[$parent] = $this->addRuleToArray($rules_array[$parent], $rule); |
90 | 90 | return $rules_array; |
91 | - } else if (! empty($rules_array)){ |
|
91 | + } else if ( ! empty($rules_array)) { |
|
92 | 92 | // \EEH_Debug_Tools::printr('SUB ARRAY', 'FOUND', __FILE__, __LINE__); |
93 | 93 | // \EEH_Debug_Tools::printr($rules_array, '$rules_array', __FILE__, __LINE__); |
94 | - foreach($rules_array as $ID => $rules) { |
|
94 | + foreach ($rules_array as $ID => $rules) { |
|
95 | 95 | // \EEH_Debug_Tools::printr($ID, '$rules_array $ID', __FILE__, __LINE__); |
96 | - if($ID === $parent) { |
|
96 | + if ($ID === $parent) { |
|
97 | 97 | // \EEH_Debug_Tools::printr($ID === $parent, '$ID === $parent', __FILE__, __LINE__); |
98 | 98 | $rules_array[$ID] = $this->addRuleToArray($rules[$ID], $rule); |
99 | 99 | return $rules_array; |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | $query_params[$parent] = array(); |
137 | 137 | } |
138 | 138 | \EEH_Debug_Tools::printr($operator, '$operator', __FILE__, __LINE__); |
139 | - \EEH_Debug_Tools::printr((string)$parent, '$parent', __FILE__, __LINE__); |
|
139 | + \EEH_Debug_Tools::printr((string) $parent, '$parent', __FILE__, __LINE__); |
|
140 | 140 | switch ($operator) { |
141 | 141 | default : |
142 | 142 | case ' '; |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | case ' AND ( '; |
156 | 156 | $query_params[$parent] = array_merge( |
157 | 157 | $query_params[$parent], |
158 | - array( $this->getQueryParamForRule($rule) ) |
|
158 | + array($this->getQueryParamForRule($rule)) |
|
159 | 159 | ); |
160 | 160 | break; |
161 | 161 | case ' OR ( '; |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | if ( |
183 | 183 | ! class_exists($strategy) |
184 | 184 | || ! is_subclass_of($strategy, '\EventEspresso\core\services\conditional_logic\rules\RuleStrategy') |
185 | - ){ |
|
185 | + ) { |
|
186 | 186 | throw new \DomainException( |
187 | 187 | sprintf( |
188 | 188 | esc_html__('The "%1$s" class is either missing or not a valid Rule Strategy.', 'event_espresso'), |