@@ -27,84 +27,84 @@ |
||
27 | 27 | { |
28 | 28 | |
29 | 29 | |
30 | - protected $attendee; |
|
30 | + protected $attendee; |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * AttendeeContactDetailsMetaboxFormHandler constructor. |
|
35 | - * |
|
36 | - * @param EE_Attendee $attendee |
|
37 | - * @param EE_Registry $registry |
|
38 | - * @throws DomainException |
|
39 | - * @throws InvalidDataTypeException |
|
40 | - * @throws InvalidArgumentException |
|
41 | - */ |
|
42 | - public function __construct(EE_Attendee $attendee, EE_Registry $registry) |
|
43 | - { |
|
44 | - $this->attendee = $attendee; |
|
45 | - $label = esc_html__('Contact Details', 'event_espresso'); |
|
46 | - parent::__construct( |
|
47 | - $label, |
|
48 | - $label, |
|
49 | - 'attendee_contact_details', |
|
50 | - '', |
|
51 | - FormHandler::DO_NOT_SETUP_FORM, |
|
52 | - $registry |
|
53 | - ); |
|
54 | - } |
|
33 | + /** |
|
34 | + * AttendeeContactDetailsMetaboxFormHandler constructor. |
|
35 | + * |
|
36 | + * @param EE_Attendee $attendee |
|
37 | + * @param EE_Registry $registry |
|
38 | + * @throws DomainException |
|
39 | + * @throws InvalidDataTypeException |
|
40 | + * @throws InvalidArgumentException |
|
41 | + */ |
|
42 | + public function __construct(EE_Attendee $attendee, EE_Registry $registry) |
|
43 | + { |
|
44 | + $this->attendee = $attendee; |
|
45 | + $label = esc_html__('Contact Details', 'event_espresso'); |
|
46 | + parent::__construct( |
|
47 | + $label, |
|
48 | + $label, |
|
49 | + 'attendee_contact_details', |
|
50 | + '', |
|
51 | + FormHandler::DO_NOT_SETUP_FORM, |
|
52 | + $registry |
|
53 | + ); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * creates and returns the actual form |
|
58 | - * |
|
59 | - * @return EE_Form_Section_Proper |
|
60 | - * @throws EE_Error |
|
61 | - */ |
|
62 | - public function generate() |
|
63 | - { |
|
64 | - return new EE_Form_Section_Proper( |
|
65 | - array( |
|
66 | - 'name' => 'attendee_contact_details', |
|
67 | - 'html_id' => 'attendee-contact-details', |
|
68 | - 'html_class' => 'form-table', |
|
69 | - 'layout_strategy' => new EE_Admin_One_Column_Layout(), |
|
70 | - 'subsections' => array( |
|
71 | - 'ATT_email' => new EE_Email_Input( |
|
72 | - array( |
|
73 | - 'default' => $this->attendee->email(), |
|
74 | - 'html_label_text' => esc_html__('Email Address', 'event_espresso'), |
|
75 | - 'required' => true, |
|
76 | - ) |
|
77 | - ), |
|
78 | - 'ATT_phone' => new EE_Text_Input( |
|
79 | - array( |
|
80 | - 'default' => $this->attendee->phone(), |
|
81 | - 'html_label_text' => esc_html__('Phone Number', 'event_espresso'), |
|
82 | - ) |
|
83 | - ), |
|
84 | - ), |
|
85 | - ) |
|
86 | - ); |
|
87 | - } |
|
56 | + /** |
|
57 | + * creates and returns the actual form |
|
58 | + * |
|
59 | + * @return EE_Form_Section_Proper |
|
60 | + * @throws EE_Error |
|
61 | + */ |
|
62 | + public function generate() |
|
63 | + { |
|
64 | + return new EE_Form_Section_Proper( |
|
65 | + array( |
|
66 | + 'name' => 'attendee_contact_details', |
|
67 | + 'html_id' => 'attendee-contact-details', |
|
68 | + 'html_class' => 'form-table', |
|
69 | + 'layout_strategy' => new EE_Admin_One_Column_Layout(), |
|
70 | + 'subsections' => array( |
|
71 | + 'ATT_email' => new EE_Email_Input( |
|
72 | + array( |
|
73 | + 'default' => $this->attendee->email(), |
|
74 | + 'html_label_text' => esc_html__('Email Address', 'event_espresso'), |
|
75 | + 'required' => true, |
|
76 | + ) |
|
77 | + ), |
|
78 | + 'ATT_phone' => new EE_Text_Input( |
|
79 | + array( |
|
80 | + 'default' => $this->attendee->phone(), |
|
81 | + 'html_label_text' => esc_html__('Phone Number', 'event_espresso'), |
|
82 | + ) |
|
83 | + ), |
|
84 | + ), |
|
85 | + ) |
|
86 | + ); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * Process form data. |
|
92 | - * |
|
93 | - * @param array $form_data |
|
94 | - * @return bool |
|
95 | - * @throws EE_Error |
|
96 | - * @throws InvalidFormSubmissionException |
|
97 | - * @throws LogicException |
|
98 | - */ |
|
99 | - public function process($form_data = array()) |
|
100 | - { |
|
101 | - $valid_data = (array) parent::process($form_data); |
|
102 | - if (empty($valid_data)) { |
|
103 | - return false; |
|
104 | - } |
|
105 | - $this->attendee->set_email($valid_data['ATT_email']); |
|
106 | - $this->attendee->set_phone($valid_data['ATT_phone']); |
|
107 | - $updated = $this->attendee->save(); |
|
108 | - return $updated !== false; |
|
109 | - } |
|
90 | + /** |
|
91 | + * Process form data. |
|
92 | + * |
|
93 | + * @param array $form_data |
|
94 | + * @return bool |
|
95 | + * @throws EE_Error |
|
96 | + * @throws InvalidFormSubmissionException |
|
97 | + * @throws LogicException |
|
98 | + */ |
|
99 | + public function process($form_data = array()) |
|
100 | + { |
|
101 | + $valid_data = (array) parent::process($form_data); |
|
102 | + if (empty($valid_data)) { |
|
103 | + return false; |
|
104 | + } |
|
105 | + $this->attendee->set_email($valid_data['ATT_email']); |
|
106 | + $this->attendee->set_phone($valid_data['ATT_phone']); |
|
107 | + $updated = $this->attendee->save(); |
|
108 | + return $updated !== false; |
|
109 | + } |
|
110 | 110 | } |
@@ -15,56 +15,56 @@ |
||
15 | 15 | class EmailAddress |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var string $email_address |
|
20 | - */ |
|
21 | - private $email_address; |
|
18 | + /** |
|
19 | + * @var string $email_address |
|
20 | + */ |
|
21 | + private $email_address; |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * EmailAddress constructor. |
|
26 | - * |
|
27 | - * @param string $email_address |
|
28 | - * @param EmailValidatorInterface $validator |
|
29 | - * @throws EmailValidationException |
|
30 | - */ |
|
31 | - public function __construct($email_address, EmailValidatorInterface $validator) |
|
32 | - { |
|
33 | - $validator->validate($email_address); |
|
34 | - $this->email_address = $email_address; |
|
35 | - } |
|
24 | + /** |
|
25 | + * EmailAddress constructor. |
|
26 | + * |
|
27 | + * @param string $email_address |
|
28 | + * @param EmailValidatorInterface $validator |
|
29 | + * @throws EmailValidationException |
|
30 | + */ |
|
31 | + public function __construct($email_address, EmailValidatorInterface $validator) |
|
32 | + { |
|
33 | + $validator->validate($email_address); |
|
34 | + $this->email_address = $email_address; |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * returns the string value for this EmailAddress |
|
40 | - * |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public function get() |
|
44 | - { |
|
45 | - return $this->email_address; |
|
46 | - } |
|
38 | + /** |
|
39 | + * returns the string value for this EmailAddress |
|
40 | + * |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public function get() |
|
44 | + { |
|
45 | + return $this->email_address; |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * compare another EmailAddress to this one to determine if they are the same |
|
51 | - * |
|
52 | - * @param EmailAddress $address |
|
53 | - * @return bool |
|
54 | - */ |
|
55 | - public function equals(EmailAddress $address) |
|
56 | - { |
|
57 | - return strtolower((string) $this) === strtolower((string) $address); |
|
58 | - } |
|
49 | + /** |
|
50 | + * compare another EmailAddress to this one to determine if they are the same |
|
51 | + * |
|
52 | + * @param EmailAddress $address |
|
53 | + * @return bool |
|
54 | + */ |
|
55 | + public function equals(EmailAddress $address) |
|
56 | + { |
|
57 | + return strtolower((string) $this) === strtolower((string) $address); |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * allows an EmailAddress object to be used as a string |
|
63 | - * |
|
64 | - * @return string |
|
65 | - */ |
|
66 | - public function __toString() |
|
67 | - { |
|
68 | - return $this->email_address; |
|
69 | - } |
|
61 | + /** |
|
62 | + * allows an EmailAddress object to be used as a string |
|
63 | + * |
|
64 | + * @return string |
|
65 | + */ |
|
66 | + public function __toString() |
|
67 | + { |
|
68 | + return $this->email_address; |
|
69 | + } |
|
70 | 70 | } |
@@ -17,339 +17,339 @@ |
||
17 | 17 | */ |
18 | 18 | class CustomSelects |
19 | 19 | { |
20 | - const TYPE_SIMPLE = 'simple'; |
|
21 | - const TYPE_COMPLEX = 'complex'; |
|
22 | - const TYPE_STRUCTURED = 'structured'; |
|
23 | - |
|
24 | - private $valid_operators = array('COUNT', 'SUM'); |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * Original incoming select array |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - private $original_selects; |
|
33 | - |
|
34 | - /** |
|
35 | - * Select string that can be added to the query |
|
36 | - * |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - private $columns_to_select_expression; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * An array of aliases for the columns included in the incoming select array. |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - private $column_aliases_in_select; |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * Enum representation of the "type" of array coming into this value object. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - private $type = ''; |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * CustomSelects constructor. |
|
60 | - * Incoming selects can be in one of the following formats: |
|
61 | - * ---- self::TYPE_SIMPLE array ---- |
|
62 | - * This is considered the "simple" type. In this case the array is an numerically indexed array with single or |
|
63 | - * multiple columns to select as the values. |
|
64 | - * eg. array( 'ATT_ID', 'REG_ID' ) |
|
65 | - * eg. array( '*' ) |
|
66 | - * If you want to use the columns in any WHERE, GROUP BY, or HAVING clauses, you must instead use the "complex" or |
|
67 | - * "structured" method. |
|
68 | - * ---- self::TYPE_COMPLEX array ---- |
|
69 | - * This is considered the "complex" type. In this case the array is indexed by arbitrary strings that serve as |
|
70 | - * column alias, and the value is an numerically indexed array where there are two values. The first value (0) is |
|
71 | - * the selection and the second value (1) is the data type. Data types must be one of the types defined in |
|
72 | - * EEM_Base::$_valid_wpdb_data_types. |
|
73 | - * eg. array( 'count' => array('count(REG_ID)', '%d') ) |
|
74 | - * Complex array configuration allows for using the column alias in any WHERE, GROUP BY, or HAVING clauses. |
|
75 | - * ---- self::TYPE_STRUCTURED array --- |
|
76 | - * This is considered the "structured" type. This type is similar to the complex type except that the array attached |
|
77 | - * to the column alias contains three values. The first value is the qualified column name (which can include |
|
78 | - * join syntax for models). The second value is the operator performed on the column (i.e. 'COUNT', 'SUM' etc)., |
|
79 | - * the third value is the data type. Note, if the select does not have an operator, you can use an empty string for |
|
80 | - * the second value. |
|
81 | - * Note: for now SUM is only for simple single column expressions (i.e. SUM(Transaction.TXN_total)) |
|
82 | - * eg. array( 'registration_count' => array('Registration.REG_ID', 'count', '%d') ); |
|
83 | - * NOTE: mixing array types in the incoming $select will cause errors. |
|
84 | - * |
|
85 | - * @param array $selects |
|
86 | - * @throws InvalidArgumentException |
|
87 | - */ |
|
88 | - public function __construct(array $selects) |
|
89 | - { |
|
90 | - $this->original_selects = $selects; |
|
91 | - $this->deriveType($selects); |
|
92 | - $this->deriveParts($selects); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * Derives what type of custom select has been sent in. |
|
98 | - * |
|
99 | - * @param array $selects |
|
100 | - * @throws InvalidArgumentException |
|
101 | - */ |
|
102 | - private function deriveType(array $selects) |
|
103 | - { |
|
104 | - // first if the first key for this array is an integer then its coming in as a simple format, so we'll also |
|
105 | - // ensure all elements of the array are simple. |
|
106 | - if (is_int(key($selects))) { |
|
107 | - // let's ensure all keys are ints |
|
108 | - $invalid_keys = array_filter( |
|
109 | - array_keys($selects), |
|
110 | - function ($value) { |
|
111 | - return ! is_int($value); |
|
112 | - } |
|
113 | - ); |
|
114 | - if (! empty($invalid_keys)) { |
|
115 | - throw new InvalidArgumentException( |
|
116 | - sprintf( |
|
117 | - esc_html__( |
|
118 | - 'Incoming array looks like its formatted for "%1$s" type selects, however it has elements that are not indexed numerically', |
|
119 | - 'event_espresso' |
|
120 | - ), |
|
121 | - self::TYPE_SIMPLE |
|
122 | - ) |
|
123 | - ); |
|
124 | - } |
|
125 | - $this->type = self::TYPE_SIMPLE; |
|
126 | - return; |
|
127 | - } |
|
128 | - // made it here so that means we've got either complex or structured selects. Let's find out which by popping |
|
129 | - // the first array element off. |
|
130 | - $first_element = reset($selects); |
|
131 | - |
|
132 | - if (! is_array($first_element)) { |
|
133 | - throw new InvalidArgumentException( |
|
134 | - sprintf( |
|
135 | - esc_html__( |
|
136 | - 'Incoming array looks like its formatted as a "%1$s" or "%2$s" type. However, the values in the array must be arrays themselves and they are not.', |
|
137 | - 'event_espresso' |
|
138 | - ), |
|
139 | - self::TYPE_COMPLEX, |
|
140 | - self::TYPE_STRUCTURED |
|
141 | - ) |
|
142 | - ); |
|
143 | - } |
|
144 | - $this->type = count($first_element) === 2 |
|
145 | - ? self::TYPE_COMPLEX |
|
146 | - : self::TYPE_STRUCTURED; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * Sets up the various properties for the vo depending on type. |
|
152 | - * |
|
153 | - * @param array $selects |
|
154 | - * @throws InvalidArgumentException |
|
155 | - */ |
|
156 | - private function deriveParts(array $selects) |
|
157 | - { |
|
158 | - $column_parts = array(); |
|
159 | - switch ($this->type) { |
|
160 | - case self::TYPE_SIMPLE: |
|
161 | - $column_parts = $selects; |
|
162 | - $this->column_aliases_in_select = $selects; |
|
163 | - break; |
|
164 | - case self::TYPE_COMPLEX: |
|
165 | - foreach ($selects as $alias => $parts) { |
|
166 | - $this->validateSelectValueForType($parts, $alias); |
|
167 | - $column_parts[] = "{$parts[0]} AS {$alias}"; |
|
168 | - $this->column_aliases_in_select[] = $alias; |
|
169 | - } |
|
170 | - break; |
|
171 | - case self::TYPE_STRUCTURED: |
|
172 | - foreach ($selects as $alias => $parts) { |
|
173 | - $this->validateSelectValueForType($parts, $alias); |
|
174 | - $column_parts[] = $parts[1] !== '' |
|
175 | - ? $this->assembleSelectStringWithOperator($parts, $alias) |
|
176 | - : "{$parts[0]} AS {$alias}"; |
|
177 | - $this->column_aliases_in_select[] = $alias; |
|
178 | - } |
|
179 | - break; |
|
180 | - } |
|
181 | - $this->columns_to_select_expression = implode(', ', $column_parts); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * Validates self::TYPE_COMPLEX and self::TYPE_STRUCTURED select statement parts. |
|
187 | - * |
|
188 | - * @param array $select_parts |
|
189 | - * @param string $alias |
|
190 | - * @throws InvalidArgumentException |
|
191 | - */ |
|
192 | - private function validateSelectValueForType(array $select_parts, $alias) |
|
193 | - { |
|
194 | - $valid_data_types = array('%d', '%s', '%f'); |
|
195 | - if (count($select_parts) !== $this->expectedSelectPartCountForType()) { |
|
196 | - throw new InvalidArgumentException( |
|
197 | - sprintf( |
|
198 | - esc_html__( |
|
199 | - 'The provided select part array for the %1$s column is expected to have a count of %2$d because the incoming select array is of type %3$s. However the count was %4$d.', |
|
200 | - 'event_espresso' |
|
201 | - ), |
|
202 | - $alias, |
|
203 | - $this->expectedSelectPartCountForType(), |
|
204 | - $this->type, |
|
205 | - count($select_parts) |
|
206 | - ) |
|
207 | - ); |
|
208 | - } |
|
209 | - // validate data type. |
|
210 | - $data_type = $this->type === self::TYPE_COMPLEX ? $select_parts[1] : ''; |
|
211 | - $data_type = $this->type === self::TYPE_STRUCTURED ? $select_parts[2] : $data_type; |
|
212 | - |
|
213 | - if (! in_array($data_type, $valid_data_types, true)) { |
|
214 | - throw new InvalidArgumentException( |
|
215 | - sprintf( |
|
216 | - esc_html__( |
|
217 | - 'Datatype %1$s (for selection "%2$s" and alias "%3$s") is not a valid wpdb datatype (eg %%s)', |
|
218 | - 'event_espresso' |
|
219 | - ), |
|
220 | - $data_type, |
|
221 | - $select_parts[0], |
|
222 | - $alias, |
|
223 | - implode(', ', $valid_data_types) |
|
224 | - ) |
|
225 | - ); |
|
226 | - } |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * Each type will have an expected count of array elements, this returns what that expected count is. |
|
232 | - * |
|
233 | - * @param string $type |
|
234 | - * @return int |
|
235 | - */ |
|
236 | - private function expectedSelectPartCountForType($type = '') |
|
237 | - { |
|
238 | - $type = $type === '' ? $this->type : $type; |
|
239 | - $types_count_map = array( |
|
240 | - self::TYPE_COMPLEX => 2, |
|
241 | - self::TYPE_STRUCTURED => 3, |
|
242 | - ); |
|
243 | - return isset($types_count_map[ $type ]) ? $types_count_map[ $type ] : 0; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Prepares the select statement part for for structured type selects. |
|
249 | - * |
|
250 | - * @param array $select_parts |
|
251 | - * @param string $alias |
|
252 | - * @return string |
|
253 | - * @throws InvalidArgumentException |
|
254 | - */ |
|
255 | - private function assembleSelectStringWithOperator(array $select_parts, $alias) |
|
256 | - { |
|
257 | - $operator = strtoupper($select_parts[1]); |
|
258 | - // validate operator |
|
259 | - if (! in_array($operator, $this->valid_operators, true)) { |
|
260 | - throw new InvalidArgumentException( |
|
261 | - sprintf( |
|
262 | - esc_html__( |
|
263 | - 'An invalid operator has been provided (%1$s) for the column %2$s. Valid operators must be one of the following: %3$s.', |
|
264 | - 'event_espresso' |
|
265 | - ), |
|
266 | - $operator, |
|
267 | - $alias, |
|
268 | - implode(', ', $this->valid_operators) |
|
269 | - ) |
|
270 | - ); |
|
271 | - } |
|
272 | - return $operator . '(' . $select_parts[0] . ') AS ' . $alias; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * Return the datatype from the given select part. |
|
278 | - * Remember the select_part has already been validated on object instantiation. |
|
279 | - * |
|
280 | - * @param array $select_part |
|
281 | - * @return string |
|
282 | - */ |
|
283 | - private function getDataTypeForSelectType(array $select_part) |
|
284 | - { |
|
285 | - switch ($this->type) { |
|
286 | - case self::TYPE_COMPLEX: |
|
287 | - return $select_part[1]; |
|
288 | - case self::TYPE_STRUCTURED: |
|
289 | - return $select_part[2]; |
|
290 | - default: |
|
291 | - return ''; |
|
292 | - } |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * Returns the original select array sent into the VO. |
|
298 | - * |
|
299 | - * @return array |
|
300 | - */ |
|
301 | - public function originalSelects() |
|
302 | - { |
|
303 | - return $this->original_selects; |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * Returns the final assembled select expression derived from the incoming select array. |
|
309 | - * |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - public function columnsToSelectExpression() |
|
313 | - { |
|
314 | - return $this->columns_to_select_expression; |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * Returns all the column aliases derived from the incoming select array. |
|
320 | - * |
|
321 | - * @return array |
|
322 | - */ |
|
323 | - public function columnAliases() |
|
324 | - { |
|
325 | - return $this->column_aliases_in_select; |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * Returns the enum type for the incoming select array. |
|
331 | - * |
|
332 | - * @return string |
|
333 | - */ |
|
334 | - public function type() |
|
335 | - { |
|
336 | - return $this->type; |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * Return the datatype for the given column_alias |
|
342 | - * |
|
343 | - * @param string $column_alias |
|
344 | - * @return string (if there's no data type we return string as the default). |
|
345 | - */ |
|
346 | - public function getDataTypeForAlias($column_alias) |
|
347 | - { |
|
348 | - if (isset($this->original_selects[ $column_alias ]) |
|
349 | - && in_array($column_alias, $this->columnAliases(), true) |
|
350 | - ) { |
|
351 | - return $this->getDataTypeForSelectType($this->original_selects[ $column_alias ]); |
|
352 | - } |
|
353 | - return '%s'; |
|
354 | - } |
|
20 | + const TYPE_SIMPLE = 'simple'; |
|
21 | + const TYPE_COMPLEX = 'complex'; |
|
22 | + const TYPE_STRUCTURED = 'structured'; |
|
23 | + |
|
24 | + private $valid_operators = array('COUNT', 'SUM'); |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * Original incoming select array |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + private $original_selects; |
|
33 | + |
|
34 | + /** |
|
35 | + * Select string that can be added to the query |
|
36 | + * |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + private $columns_to_select_expression; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * An array of aliases for the columns included in the incoming select array. |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + private $column_aliases_in_select; |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * Enum representation of the "type" of array coming into this value object. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + private $type = ''; |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * CustomSelects constructor. |
|
60 | + * Incoming selects can be in one of the following formats: |
|
61 | + * ---- self::TYPE_SIMPLE array ---- |
|
62 | + * This is considered the "simple" type. In this case the array is an numerically indexed array with single or |
|
63 | + * multiple columns to select as the values. |
|
64 | + * eg. array( 'ATT_ID', 'REG_ID' ) |
|
65 | + * eg. array( '*' ) |
|
66 | + * If you want to use the columns in any WHERE, GROUP BY, or HAVING clauses, you must instead use the "complex" or |
|
67 | + * "structured" method. |
|
68 | + * ---- self::TYPE_COMPLEX array ---- |
|
69 | + * This is considered the "complex" type. In this case the array is indexed by arbitrary strings that serve as |
|
70 | + * column alias, and the value is an numerically indexed array where there are two values. The first value (0) is |
|
71 | + * the selection and the second value (1) is the data type. Data types must be one of the types defined in |
|
72 | + * EEM_Base::$_valid_wpdb_data_types. |
|
73 | + * eg. array( 'count' => array('count(REG_ID)', '%d') ) |
|
74 | + * Complex array configuration allows for using the column alias in any WHERE, GROUP BY, or HAVING clauses. |
|
75 | + * ---- self::TYPE_STRUCTURED array --- |
|
76 | + * This is considered the "structured" type. This type is similar to the complex type except that the array attached |
|
77 | + * to the column alias contains three values. The first value is the qualified column name (which can include |
|
78 | + * join syntax for models). The second value is the operator performed on the column (i.e. 'COUNT', 'SUM' etc)., |
|
79 | + * the third value is the data type. Note, if the select does not have an operator, you can use an empty string for |
|
80 | + * the second value. |
|
81 | + * Note: for now SUM is only for simple single column expressions (i.e. SUM(Transaction.TXN_total)) |
|
82 | + * eg. array( 'registration_count' => array('Registration.REG_ID', 'count', '%d') ); |
|
83 | + * NOTE: mixing array types in the incoming $select will cause errors. |
|
84 | + * |
|
85 | + * @param array $selects |
|
86 | + * @throws InvalidArgumentException |
|
87 | + */ |
|
88 | + public function __construct(array $selects) |
|
89 | + { |
|
90 | + $this->original_selects = $selects; |
|
91 | + $this->deriveType($selects); |
|
92 | + $this->deriveParts($selects); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * Derives what type of custom select has been sent in. |
|
98 | + * |
|
99 | + * @param array $selects |
|
100 | + * @throws InvalidArgumentException |
|
101 | + */ |
|
102 | + private function deriveType(array $selects) |
|
103 | + { |
|
104 | + // first if the first key for this array is an integer then its coming in as a simple format, so we'll also |
|
105 | + // ensure all elements of the array are simple. |
|
106 | + if (is_int(key($selects))) { |
|
107 | + // let's ensure all keys are ints |
|
108 | + $invalid_keys = array_filter( |
|
109 | + array_keys($selects), |
|
110 | + function ($value) { |
|
111 | + return ! is_int($value); |
|
112 | + } |
|
113 | + ); |
|
114 | + if (! empty($invalid_keys)) { |
|
115 | + throw new InvalidArgumentException( |
|
116 | + sprintf( |
|
117 | + esc_html__( |
|
118 | + 'Incoming array looks like its formatted for "%1$s" type selects, however it has elements that are not indexed numerically', |
|
119 | + 'event_espresso' |
|
120 | + ), |
|
121 | + self::TYPE_SIMPLE |
|
122 | + ) |
|
123 | + ); |
|
124 | + } |
|
125 | + $this->type = self::TYPE_SIMPLE; |
|
126 | + return; |
|
127 | + } |
|
128 | + // made it here so that means we've got either complex or structured selects. Let's find out which by popping |
|
129 | + // the first array element off. |
|
130 | + $first_element = reset($selects); |
|
131 | + |
|
132 | + if (! is_array($first_element)) { |
|
133 | + throw new InvalidArgumentException( |
|
134 | + sprintf( |
|
135 | + esc_html__( |
|
136 | + 'Incoming array looks like its formatted as a "%1$s" or "%2$s" type. However, the values in the array must be arrays themselves and they are not.', |
|
137 | + 'event_espresso' |
|
138 | + ), |
|
139 | + self::TYPE_COMPLEX, |
|
140 | + self::TYPE_STRUCTURED |
|
141 | + ) |
|
142 | + ); |
|
143 | + } |
|
144 | + $this->type = count($first_element) === 2 |
|
145 | + ? self::TYPE_COMPLEX |
|
146 | + : self::TYPE_STRUCTURED; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * Sets up the various properties for the vo depending on type. |
|
152 | + * |
|
153 | + * @param array $selects |
|
154 | + * @throws InvalidArgumentException |
|
155 | + */ |
|
156 | + private function deriveParts(array $selects) |
|
157 | + { |
|
158 | + $column_parts = array(); |
|
159 | + switch ($this->type) { |
|
160 | + case self::TYPE_SIMPLE: |
|
161 | + $column_parts = $selects; |
|
162 | + $this->column_aliases_in_select = $selects; |
|
163 | + break; |
|
164 | + case self::TYPE_COMPLEX: |
|
165 | + foreach ($selects as $alias => $parts) { |
|
166 | + $this->validateSelectValueForType($parts, $alias); |
|
167 | + $column_parts[] = "{$parts[0]} AS {$alias}"; |
|
168 | + $this->column_aliases_in_select[] = $alias; |
|
169 | + } |
|
170 | + break; |
|
171 | + case self::TYPE_STRUCTURED: |
|
172 | + foreach ($selects as $alias => $parts) { |
|
173 | + $this->validateSelectValueForType($parts, $alias); |
|
174 | + $column_parts[] = $parts[1] !== '' |
|
175 | + ? $this->assembleSelectStringWithOperator($parts, $alias) |
|
176 | + : "{$parts[0]} AS {$alias}"; |
|
177 | + $this->column_aliases_in_select[] = $alias; |
|
178 | + } |
|
179 | + break; |
|
180 | + } |
|
181 | + $this->columns_to_select_expression = implode(', ', $column_parts); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * Validates self::TYPE_COMPLEX and self::TYPE_STRUCTURED select statement parts. |
|
187 | + * |
|
188 | + * @param array $select_parts |
|
189 | + * @param string $alias |
|
190 | + * @throws InvalidArgumentException |
|
191 | + */ |
|
192 | + private function validateSelectValueForType(array $select_parts, $alias) |
|
193 | + { |
|
194 | + $valid_data_types = array('%d', '%s', '%f'); |
|
195 | + if (count($select_parts) !== $this->expectedSelectPartCountForType()) { |
|
196 | + throw new InvalidArgumentException( |
|
197 | + sprintf( |
|
198 | + esc_html__( |
|
199 | + 'The provided select part array for the %1$s column is expected to have a count of %2$d because the incoming select array is of type %3$s. However the count was %4$d.', |
|
200 | + 'event_espresso' |
|
201 | + ), |
|
202 | + $alias, |
|
203 | + $this->expectedSelectPartCountForType(), |
|
204 | + $this->type, |
|
205 | + count($select_parts) |
|
206 | + ) |
|
207 | + ); |
|
208 | + } |
|
209 | + // validate data type. |
|
210 | + $data_type = $this->type === self::TYPE_COMPLEX ? $select_parts[1] : ''; |
|
211 | + $data_type = $this->type === self::TYPE_STRUCTURED ? $select_parts[2] : $data_type; |
|
212 | + |
|
213 | + if (! in_array($data_type, $valid_data_types, true)) { |
|
214 | + throw new InvalidArgumentException( |
|
215 | + sprintf( |
|
216 | + esc_html__( |
|
217 | + 'Datatype %1$s (for selection "%2$s" and alias "%3$s") is not a valid wpdb datatype (eg %%s)', |
|
218 | + 'event_espresso' |
|
219 | + ), |
|
220 | + $data_type, |
|
221 | + $select_parts[0], |
|
222 | + $alias, |
|
223 | + implode(', ', $valid_data_types) |
|
224 | + ) |
|
225 | + ); |
|
226 | + } |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * Each type will have an expected count of array elements, this returns what that expected count is. |
|
232 | + * |
|
233 | + * @param string $type |
|
234 | + * @return int |
|
235 | + */ |
|
236 | + private function expectedSelectPartCountForType($type = '') |
|
237 | + { |
|
238 | + $type = $type === '' ? $this->type : $type; |
|
239 | + $types_count_map = array( |
|
240 | + self::TYPE_COMPLEX => 2, |
|
241 | + self::TYPE_STRUCTURED => 3, |
|
242 | + ); |
|
243 | + return isset($types_count_map[ $type ]) ? $types_count_map[ $type ] : 0; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Prepares the select statement part for for structured type selects. |
|
249 | + * |
|
250 | + * @param array $select_parts |
|
251 | + * @param string $alias |
|
252 | + * @return string |
|
253 | + * @throws InvalidArgumentException |
|
254 | + */ |
|
255 | + private function assembleSelectStringWithOperator(array $select_parts, $alias) |
|
256 | + { |
|
257 | + $operator = strtoupper($select_parts[1]); |
|
258 | + // validate operator |
|
259 | + if (! in_array($operator, $this->valid_operators, true)) { |
|
260 | + throw new InvalidArgumentException( |
|
261 | + sprintf( |
|
262 | + esc_html__( |
|
263 | + 'An invalid operator has been provided (%1$s) for the column %2$s. Valid operators must be one of the following: %3$s.', |
|
264 | + 'event_espresso' |
|
265 | + ), |
|
266 | + $operator, |
|
267 | + $alias, |
|
268 | + implode(', ', $this->valid_operators) |
|
269 | + ) |
|
270 | + ); |
|
271 | + } |
|
272 | + return $operator . '(' . $select_parts[0] . ') AS ' . $alias; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * Return the datatype from the given select part. |
|
278 | + * Remember the select_part has already been validated on object instantiation. |
|
279 | + * |
|
280 | + * @param array $select_part |
|
281 | + * @return string |
|
282 | + */ |
|
283 | + private function getDataTypeForSelectType(array $select_part) |
|
284 | + { |
|
285 | + switch ($this->type) { |
|
286 | + case self::TYPE_COMPLEX: |
|
287 | + return $select_part[1]; |
|
288 | + case self::TYPE_STRUCTURED: |
|
289 | + return $select_part[2]; |
|
290 | + default: |
|
291 | + return ''; |
|
292 | + } |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * Returns the original select array sent into the VO. |
|
298 | + * |
|
299 | + * @return array |
|
300 | + */ |
|
301 | + public function originalSelects() |
|
302 | + { |
|
303 | + return $this->original_selects; |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * Returns the final assembled select expression derived from the incoming select array. |
|
309 | + * |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + public function columnsToSelectExpression() |
|
313 | + { |
|
314 | + return $this->columns_to_select_expression; |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * Returns all the column aliases derived from the incoming select array. |
|
320 | + * |
|
321 | + * @return array |
|
322 | + */ |
|
323 | + public function columnAliases() |
|
324 | + { |
|
325 | + return $this->column_aliases_in_select; |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * Returns the enum type for the incoming select array. |
|
331 | + * |
|
332 | + * @return string |
|
333 | + */ |
|
334 | + public function type() |
|
335 | + { |
|
336 | + return $this->type; |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * Return the datatype for the given column_alias |
|
342 | + * |
|
343 | + * @param string $column_alias |
|
344 | + * @return string (if there's no data type we return string as the default). |
|
345 | + */ |
|
346 | + public function getDataTypeForAlias($column_alias) |
|
347 | + { |
|
348 | + if (isset($this->original_selects[ $column_alias ]) |
|
349 | + && in_array($column_alias, $this->columnAliases(), true) |
|
350 | + ) { |
|
351 | + return $this->getDataTypeForSelectType($this->original_selects[ $column_alias ]); |
|
352 | + } |
|
353 | + return '%s'; |
|
354 | + } |
|
355 | 355 | } |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | // let's ensure all keys are ints |
108 | 108 | $invalid_keys = array_filter( |
109 | 109 | array_keys($selects), |
110 | - function ($value) { |
|
110 | + function($value) { |
|
111 | 111 | return ! is_int($value); |
112 | 112 | } |
113 | 113 | ); |
114 | - if (! empty($invalid_keys)) { |
|
114 | + if ( ! empty($invalid_keys)) { |
|
115 | 115 | throw new InvalidArgumentException( |
116 | 116 | sprintf( |
117 | 117 | esc_html__( |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | // the first array element off. |
130 | 130 | $first_element = reset($selects); |
131 | 131 | |
132 | - if (! is_array($first_element)) { |
|
132 | + if ( ! is_array($first_element)) { |
|
133 | 133 | throw new InvalidArgumentException( |
134 | 134 | sprintf( |
135 | 135 | esc_html__( |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | $data_type = $this->type === self::TYPE_COMPLEX ? $select_parts[1] : ''; |
211 | 211 | $data_type = $this->type === self::TYPE_STRUCTURED ? $select_parts[2] : $data_type; |
212 | 212 | |
213 | - if (! in_array($data_type, $valid_data_types, true)) { |
|
213 | + if ( ! in_array($data_type, $valid_data_types, true)) { |
|
214 | 214 | throw new InvalidArgumentException( |
215 | 215 | sprintf( |
216 | 216 | esc_html__( |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | self::TYPE_COMPLEX => 2, |
241 | 241 | self::TYPE_STRUCTURED => 3, |
242 | 242 | ); |
243 | - return isset($types_count_map[ $type ]) ? $types_count_map[ $type ] : 0; |
|
243 | + return isset($types_count_map[$type]) ? $types_count_map[$type] : 0; |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | { |
257 | 257 | $operator = strtoupper($select_parts[1]); |
258 | 258 | // validate operator |
259 | - if (! in_array($operator, $this->valid_operators, true)) { |
|
259 | + if ( ! in_array($operator, $this->valid_operators, true)) { |
|
260 | 260 | throw new InvalidArgumentException( |
261 | 261 | sprintf( |
262 | 262 | esc_html__( |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | ) |
270 | 270 | ); |
271 | 271 | } |
272 | - return $operator . '(' . $select_parts[0] . ') AS ' . $alias; |
|
272 | + return $operator.'('.$select_parts[0].') AS '.$alias; |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | |
@@ -345,10 +345,10 @@ discard block |
||
345 | 345 | */ |
346 | 346 | public function getDataTypeForAlias($column_alias) |
347 | 347 | { |
348 | - if (isset($this->original_selects[ $column_alias ]) |
|
348 | + if (isset($this->original_selects[$column_alias]) |
|
349 | 349 | && in_array($column_alias, $this->columnAliases(), true) |
350 | 350 | ) { |
351 | - return $this->getDataTypeForSelectType($this->original_selects[ $column_alias ]); |
|
351 | + return $this->getDataTypeForSelectType($this->original_selects[$column_alias]); |
|
352 | 352 | } |
353 | 353 | return '%s'; |
354 | 354 | } |
@@ -70,44 +70,44 @@ |
||
70 | 70 | class LoaderFactory |
71 | 71 | { |
72 | 72 | |
73 | - /** |
|
74 | - * @var LoaderInterface $loader ; |
|
75 | - */ |
|
76 | - private static $loader; |
|
73 | + /** |
|
74 | + * @var LoaderInterface $loader ; |
|
75 | + */ |
|
76 | + private static $loader; |
|
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * @param EE_Registry|CoffeeShop $generator provided during very first instantiation in |
|
81 | - * BootstrapDependencyInjectionContainer::buildLoader() |
|
82 | - * otherwise can be left null |
|
83 | - * @param ClassInterfaceCache|null $class_cache also provided during first instantiation |
|
84 | - * @param ObjectIdentifier|null $object_identifier |
|
85 | - * @return LoaderInterface |
|
86 | - * @throws InvalidArgumentException |
|
87 | - * @throws InvalidDataTypeException |
|
88 | - * @throws InvalidInterfaceException |
|
89 | - */ |
|
90 | - public static function getLoader( |
|
91 | - $generator = null, |
|
92 | - ClassInterfaceCache $class_cache = null, |
|
93 | - ObjectIdentifier $object_identifier = null |
|
94 | - ) { |
|
95 | - if (! LoaderFactory::$loader instanceof LoaderInterface |
|
96 | - && ($generator instanceof EE_Registry || $generator instanceof CoffeeShop) |
|
97 | - && $class_cache instanceof ClassInterfaceCache |
|
98 | - && $object_identifier instanceof ObjectIdentifier |
|
99 | - ) { |
|
100 | - $core_loader = new CoreLoader($generator); |
|
101 | - LoaderFactory::$loader = new Loader( |
|
102 | - $core_loader, |
|
103 | - new CachingLoader( |
|
104 | - $core_loader, |
|
105 | - new LooseCollection(''), |
|
106 | - $object_identifier |
|
107 | - ), |
|
108 | - $class_cache |
|
109 | - ); |
|
110 | - } |
|
111 | - return LoaderFactory::$loader; |
|
112 | - } |
|
79 | + /** |
|
80 | + * @param EE_Registry|CoffeeShop $generator provided during very first instantiation in |
|
81 | + * BootstrapDependencyInjectionContainer::buildLoader() |
|
82 | + * otherwise can be left null |
|
83 | + * @param ClassInterfaceCache|null $class_cache also provided during first instantiation |
|
84 | + * @param ObjectIdentifier|null $object_identifier |
|
85 | + * @return LoaderInterface |
|
86 | + * @throws InvalidArgumentException |
|
87 | + * @throws InvalidDataTypeException |
|
88 | + * @throws InvalidInterfaceException |
|
89 | + */ |
|
90 | + public static function getLoader( |
|
91 | + $generator = null, |
|
92 | + ClassInterfaceCache $class_cache = null, |
|
93 | + ObjectIdentifier $object_identifier = null |
|
94 | + ) { |
|
95 | + if (! LoaderFactory::$loader instanceof LoaderInterface |
|
96 | + && ($generator instanceof EE_Registry || $generator instanceof CoffeeShop) |
|
97 | + && $class_cache instanceof ClassInterfaceCache |
|
98 | + && $object_identifier instanceof ObjectIdentifier |
|
99 | + ) { |
|
100 | + $core_loader = new CoreLoader($generator); |
|
101 | + LoaderFactory::$loader = new Loader( |
|
102 | + $core_loader, |
|
103 | + new CachingLoader( |
|
104 | + $core_loader, |
|
105 | + new LooseCollection(''), |
|
106 | + $object_identifier |
|
107 | + ), |
|
108 | + $class_cache |
|
109 | + ); |
|
110 | + } |
|
111 | + return LoaderFactory::$loader; |
|
112 | + } |
|
113 | 113 | } |
@@ -92,7 +92,7 @@ |
||
92 | 92 | ClassInterfaceCache $class_cache = null, |
93 | 93 | ObjectIdentifier $object_identifier = null |
94 | 94 | ) { |
95 | - if (! LoaderFactory::$loader instanceof LoaderInterface |
|
95 | + if ( ! LoaderFactory::$loader instanceof LoaderInterface |
|
96 | 96 | && ($generator instanceof EE_Registry || $generator instanceof CoffeeShop) |
97 | 97 | && $class_cache instanceof ClassInterfaceCache |
98 | 98 | && $object_identifier instanceof ObjectIdentifier |
@@ -10,294 +10,294 @@ |
||
10 | 10 | */ |
11 | 11 | trait MessagesAdmin |
12 | 12 | { |
13 | - /** |
|
14 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
15 | - * a string. |
|
16 | - */ |
|
17 | - public function amOnMessagesActivityListTablePage($additional_params = '') |
|
18 | - { |
|
19 | - $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
20 | - } |
|
21 | - |
|
22 | - /** |
|
23 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
24 | - * a string. |
|
25 | - */ |
|
26 | - public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
27 | - { |
|
28 | - $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
34 | - * a string. |
|
35 | - */ |
|
36 | - public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
37 | - { |
|
38 | - $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * Directs to message settings page |
|
44 | - */ |
|
45 | - public function amOnMessageSettingsPage() |
|
46 | - { |
|
47 | - $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
52 | - { |
|
53 | - $this->actor()->dragAndDrop( |
|
54 | - MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
55 | - MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
56 | - ); |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * Assumes you are already on the list table page that has the ui for editing the template. |
|
62 | - * @param string $message_type_slug |
|
63 | - * @param string $context [optional] if you want to click directly to the given context in the editor |
|
64 | - */ |
|
65 | - public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
66 | - { |
|
67 | - $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
73 | - * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
74 | - * |
|
75 | - * @param int $expected_occurence_count |
|
76 | - * @param string $text_to_check_for |
|
77 | - * @param string $field |
|
78 | - * @param string $message_type_label |
|
79 | - * @param string $message_status |
|
80 | - * @param string $messenger |
|
81 | - * @param string $context |
|
82 | - */ |
|
83 | - public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
84 | - $expected_occurence_count, |
|
85 | - $text_to_check_for, |
|
86 | - $field, |
|
87 | - $message_type_label, |
|
88 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
89 | - $messenger = 'Email', |
|
90 | - $context = 'Event Admin' |
|
91 | - ) { |
|
92 | - $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
93 | - $field, |
|
94 | - $message_type_label, |
|
95 | - $message_status, |
|
96 | - $messenger, |
|
97 | - $context, |
|
98 | - $text_to_check_for, |
|
99 | - 0 |
|
100 | - )); |
|
101 | - $actual_count = count($elements); |
|
102 | - $this->actor()->assertEquals( |
|
103 | - $expected_occurence_count, |
|
104 | - $actual_count, |
|
105 | - sprintf( |
|
106 | - 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
107 | - $expected_occurence_count, |
|
108 | - $text_to_check_for, |
|
109 | - $field, |
|
110 | - $actual_count |
|
111 | - ) |
|
112 | - ); |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * This will create a custom message template for the given messenger and message type from the context of the |
|
118 | - * default (global) message template list table. |
|
119 | - * Also takes care of verifying the template was created. |
|
120 | - * @param string $message_type_label |
|
121 | - * @param string $messenger_label |
|
122 | - */ |
|
123 | - public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label) |
|
124 | - { |
|
125 | - $this->amOnDefaultMessageTemplateListTablePage(); |
|
126 | - $this->actor()->click( |
|
127 | - MessagesPage::createCustomButtonForMessageTypeAndMessenger( |
|
128 | - $message_type_label, |
|
129 | - $messenger_label |
|
130 | - ) |
|
131 | - ); |
|
132 | - $this->actor()->seeInField('#title', 'New Custom Template'); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * This switches the context of the current messages template to the given reference. |
|
138 | - * @param string $context_reference This should be the visible label for the option. |
|
139 | - */ |
|
140 | - public function switchContextTo($context_reference) |
|
141 | - { |
|
142 | - $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference); |
|
143 | - $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR); |
|
144 | - $this->actor()->waitForText($context_reference, 10, 'h1'); |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after |
|
150 | - * toggling. |
|
151 | - * |
|
152 | - * @param string $context_string What context is being switched (used for the expected state text) |
|
153 | - * @param bool $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive |
|
154 | - * (false) |
|
155 | - */ |
|
156 | - public function toggleContextState($context_string, $expected_state_is_active = true) |
|
157 | - { |
|
158 | - $this->actor()->scrollTo(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR); |
|
159 | - $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE); |
|
160 | - if ($expected_state_is_active) { |
|
161 | - $this->actor()->waitForText("The template for $context_string is currently active."); |
|
162 | - } else { |
|
163 | - $this->actor()->waitForText("The template for $context_string is currently inactive"); |
|
164 | - } |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * Triggers saving the message template. |
|
170 | - * @param bool $and_close Use to indicate to click the Save and Close button. |
|
171 | - */ |
|
172 | - public function saveMessageTemplate($and_close = false) |
|
173 | - { |
|
174 | - $this->actor()->scrollTo(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR); |
|
175 | - if ($and_close) { |
|
176 | - $this->actor()->click('Save and Close'); |
|
177 | - } else { |
|
178 | - $this->actor()->click('Save'); |
|
179 | - } |
|
180 | - $this->actor()->waitForText('successfully updated'); |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * This takes care of clicking the View Message icon for the given parameters. |
|
186 | - * Assumes you are already viewing the messages activity list table. |
|
187 | - * @param $message_type_label |
|
188 | - * @param $message_status |
|
189 | - * @param string $messenger |
|
190 | - * @param string $context |
|
191 | - * @param int $number_in_set |
|
192 | - */ |
|
193 | - public function viewMessageInMessagesListTableFor( |
|
194 | - $message_type_label, |
|
195 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
196 | - $messenger = 'Email', |
|
197 | - $context = 'Event Admin', |
|
198 | - $number_in_set = 1 |
|
199 | - ) { |
|
200 | - $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor( |
|
201 | - $message_type_label, |
|
202 | - $message_status, |
|
203 | - $messenger, |
|
204 | - $context, |
|
205 | - $number_in_set |
|
206 | - )); |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * Takes care of deleting a message matching the given parameters via the message activity list table. |
|
212 | - * Assumes you are already viewing the messages activity list table. |
|
213 | - * @param $message_type_label |
|
214 | - * @param $message_status |
|
215 | - * @param string $messenger |
|
216 | - * @param string $context |
|
217 | - * @param int $number_in_set |
|
218 | - */ |
|
219 | - public function deleteMessageInMessagesListTableFor( |
|
220 | - $message_type_label, |
|
221 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
222 | - $messenger = 'Email', |
|
223 | - $context = 'Event Admin', |
|
224 | - $number_in_set = 1 |
|
225 | - ) { |
|
226 | - $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor( |
|
227 | - $message_type_label, |
|
228 | - $message_status, |
|
229 | - $messenger, |
|
230 | - $context, |
|
231 | - $number_in_set |
|
232 | - ); |
|
233 | - $cell_selector = MessagesPage::messagesActivityListTableCellSelectorFor( |
|
234 | - 'to', |
|
235 | - $message_type_label, |
|
236 | - $message_status, |
|
237 | - $messenger, |
|
238 | - $context, |
|
239 | - '', |
|
240 | - $number_in_set |
|
241 | - ); |
|
242 | - $this->actor()->scrollTo($cell_selector, 0, -30); |
|
243 | - $this->actor()->moveMouseOver( |
|
244 | - $cell_selector, |
|
245 | - 5, |
|
246 | - 5 |
|
247 | - ); |
|
248 | - $this->actor()->waitForElementVisible( |
|
249 | - $delete_action_selector |
|
250 | - ); |
|
251 | - $this->actor()->click( |
|
252 | - $delete_action_selector |
|
253 | - ); |
|
254 | - $this->actor()->waitForText('successfully deleted', 20); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
260 | - * list table, this will take care of validating the given text is in that window. |
|
261 | - * @param string $text_to_view |
|
262 | - */ |
|
263 | - public function seeTextInViewMessageModal($text_to_view, $should_not_see = false) |
|
264 | - { |
|
265 | - $this->actor()->wait(2); |
|
266 | - $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
267 | - $this->actor()->switchToIframe('message-view-window'); |
|
268 | - $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view); |
|
269 | - $this->actor()->switchToIframe(); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * This returns the value for the link at the given selector in the message modal. |
|
275 | - * @param string $selector (any selector string accepted by WebDriver) |
|
276 | - */ |
|
277 | - public function observeLinkAtSelectorInMessageModal($selector) |
|
278 | - { |
|
279 | - $this->actor()->wait(2); |
|
280 | - $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
281 | - $this->actor()->switchToIframe('message-view-window'); |
|
282 | - $link = $this->actor()->observeLinkUrlAt($selector); |
|
283 | - $this->actor()->switchToIframe(); |
|
284 | - return $link; |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
290 | - * list table, this will take care of validating the given text is NOT that window. |
|
291 | - * @param string $text_to_view |
|
292 | - */ |
|
293 | - public function dontSeeTextInViewMessageModal($text_to_view) |
|
294 | - { |
|
295 | - $this->seeTextInViewMessageModal($text_to_view, true); |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - public function dismissMessageModal() |
|
300 | - { |
|
301 | - $this->actor()->executeJs('window.dialogHelper.closeModal()'); |
|
302 | - } |
|
13 | + /** |
|
14 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
15 | + * a string. |
|
16 | + */ |
|
17 | + public function amOnMessagesActivityListTablePage($additional_params = '') |
|
18 | + { |
|
19 | + $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
20 | + } |
|
21 | + |
|
22 | + /** |
|
23 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
24 | + * a string. |
|
25 | + */ |
|
26 | + public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
27 | + { |
|
28 | + $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
34 | + * a string. |
|
35 | + */ |
|
36 | + public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
37 | + { |
|
38 | + $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * Directs to message settings page |
|
44 | + */ |
|
45 | + public function amOnMessageSettingsPage() |
|
46 | + { |
|
47 | + $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
52 | + { |
|
53 | + $this->actor()->dragAndDrop( |
|
54 | + MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
55 | + MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
56 | + ); |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * Assumes you are already on the list table page that has the ui for editing the template. |
|
62 | + * @param string $message_type_slug |
|
63 | + * @param string $context [optional] if you want to click directly to the given context in the editor |
|
64 | + */ |
|
65 | + public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
66 | + { |
|
67 | + $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
73 | + * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
74 | + * |
|
75 | + * @param int $expected_occurence_count |
|
76 | + * @param string $text_to_check_for |
|
77 | + * @param string $field |
|
78 | + * @param string $message_type_label |
|
79 | + * @param string $message_status |
|
80 | + * @param string $messenger |
|
81 | + * @param string $context |
|
82 | + */ |
|
83 | + public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
84 | + $expected_occurence_count, |
|
85 | + $text_to_check_for, |
|
86 | + $field, |
|
87 | + $message_type_label, |
|
88 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
89 | + $messenger = 'Email', |
|
90 | + $context = 'Event Admin' |
|
91 | + ) { |
|
92 | + $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
93 | + $field, |
|
94 | + $message_type_label, |
|
95 | + $message_status, |
|
96 | + $messenger, |
|
97 | + $context, |
|
98 | + $text_to_check_for, |
|
99 | + 0 |
|
100 | + )); |
|
101 | + $actual_count = count($elements); |
|
102 | + $this->actor()->assertEquals( |
|
103 | + $expected_occurence_count, |
|
104 | + $actual_count, |
|
105 | + sprintf( |
|
106 | + 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
107 | + $expected_occurence_count, |
|
108 | + $text_to_check_for, |
|
109 | + $field, |
|
110 | + $actual_count |
|
111 | + ) |
|
112 | + ); |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * This will create a custom message template for the given messenger and message type from the context of the |
|
118 | + * default (global) message template list table. |
|
119 | + * Also takes care of verifying the template was created. |
|
120 | + * @param string $message_type_label |
|
121 | + * @param string $messenger_label |
|
122 | + */ |
|
123 | + public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label) |
|
124 | + { |
|
125 | + $this->amOnDefaultMessageTemplateListTablePage(); |
|
126 | + $this->actor()->click( |
|
127 | + MessagesPage::createCustomButtonForMessageTypeAndMessenger( |
|
128 | + $message_type_label, |
|
129 | + $messenger_label |
|
130 | + ) |
|
131 | + ); |
|
132 | + $this->actor()->seeInField('#title', 'New Custom Template'); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * This switches the context of the current messages template to the given reference. |
|
138 | + * @param string $context_reference This should be the visible label for the option. |
|
139 | + */ |
|
140 | + public function switchContextTo($context_reference) |
|
141 | + { |
|
142 | + $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference); |
|
143 | + $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR); |
|
144 | + $this->actor()->waitForText($context_reference, 10, 'h1'); |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after |
|
150 | + * toggling. |
|
151 | + * |
|
152 | + * @param string $context_string What context is being switched (used for the expected state text) |
|
153 | + * @param bool $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive |
|
154 | + * (false) |
|
155 | + */ |
|
156 | + public function toggleContextState($context_string, $expected_state_is_active = true) |
|
157 | + { |
|
158 | + $this->actor()->scrollTo(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR); |
|
159 | + $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE); |
|
160 | + if ($expected_state_is_active) { |
|
161 | + $this->actor()->waitForText("The template for $context_string is currently active."); |
|
162 | + } else { |
|
163 | + $this->actor()->waitForText("The template for $context_string is currently inactive"); |
|
164 | + } |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * Triggers saving the message template. |
|
170 | + * @param bool $and_close Use to indicate to click the Save and Close button. |
|
171 | + */ |
|
172 | + public function saveMessageTemplate($and_close = false) |
|
173 | + { |
|
174 | + $this->actor()->scrollTo(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR); |
|
175 | + if ($and_close) { |
|
176 | + $this->actor()->click('Save and Close'); |
|
177 | + } else { |
|
178 | + $this->actor()->click('Save'); |
|
179 | + } |
|
180 | + $this->actor()->waitForText('successfully updated'); |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * This takes care of clicking the View Message icon for the given parameters. |
|
186 | + * Assumes you are already viewing the messages activity list table. |
|
187 | + * @param $message_type_label |
|
188 | + * @param $message_status |
|
189 | + * @param string $messenger |
|
190 | + * @param string $context |
|
191 | + * @param int $number_in_set |
|
192 | + */ |
|
193 | + public function viewMessageInMessagesListTableFor( |
|
194 | + $message_type_label, |
|
195 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
196 | + $messenger = 'Email', |
|
197 | + $context = 'Event Admin', |
|
198 | + $number_in_set = 1 |
|
199 | + ) { |
|
200 | + $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor( |
|
201 | + $message_type_label, |
|
202 | + $message_status, |
|
203 | + $messenger, |
|
204 | + $context, |
|
205 | + $number_in_set |
|
206 | + )); |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * Takes care of deleting a message matching the given parameters via the message activity list table. |
|
212 | + * Assumes you are already viewing the messages activity list table. |
|
213 | + * @param $message_type_label |
|
214 | + * @param $message_status |
|
215 | + * @param string $messenger |
|
216 | + * @param string $context |
|
217 | + * @param int $number_in_set |
|
218 | + */ |
|
219 | + public function deleteMessageInMessagesListTableFor( |
|
220 | + $message_type_label, |
|
221 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
222 | + $messenger = 'Email', |
|
223 | + $context = 'Event Admin', |
|
224 | + $number_in_set = 1 |
|
225 | + ) { |
|
226 | + $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor( |
|
227 | + $message_type_label, |
|
228 | + $message_status, |
|
229 | + $messenger, |
|
230 | + $context, |
|
231 | + $number_in_set |
|
232 | + ); |
|
233 | + $cell_selector = MessagesPage::messagesActivityListTableCellSelectorFor( |
|
234 | + 'to', |
|
235 | + $message_type_label, |
|
236 | + $message_status, |
|
237 | + $messenger, |
|
238 | + $context, |
|
239 | + '', |
|
240 | + $number_in_set |
|
241 | + ); |
|
242 | + $this->actor()->scrollTo($cell_selector, 0, -30); |
|
243 | + $this->actor()->moveMouseOver( |
|
244 | + $cell_selector, |
|
245 | + 5, |
|
246 | + 5 |
|
247 | + ); |
|
248 | + $this->actor()->waitForElementVisible( |
|
249 | + $delete_action_selector |
|
250 | + ); |
|
251 | + $this->actor()->click( |
|
252 | + $delete_action_selector |
|
253 | + ); |
|
254 | + $this->actor()->waitForText('successfully deleted', 20); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
260 | + * list table, this will take care of validating the given text is in that window. |
|
261 | + * @param string $text_to_view |
|
262 | + */ |
|
263 | + public function seeTextInViewMessageModal($text_to_view, $should_not_see = false) |
|
264 | + { |
|
265 | + $this->actor()->wait(2); |
|
266 | + $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
267 | + $this->actor()->switchToIframe('message-view-window'); |
|
268 | + $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view); |
|
269 | + $this->actor()->switchToIframe(); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * This returns the value for the link at the given selector in the message modal. |
|
275 | + * @param string $selector (any selector string accepted by WebDriver) |
|
276 | + */ |
|
277 | + public function observeLinkAtSelectorInMessageModal($selector) |
|
278 | + { |
|
279 | + $this->actor()->wait(2); |
|
280 | + $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
281 | + $this->actor()->switchToIframe('message-view-window'); |
|
282 | + $link = $this->actor()->observeLinkUrlAt($selector); |
|
283 | + $this->actor()->switchToIframe(); |
|
284 | + return $link; |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
290 | + * list table, this will take care of validating the given text is NOT that window. |
|
291 | + * @param string $text_to_view |
|
292 | + */ |
|
293 | + public function dontSeeTextInViewMessageModal($text_to_view) |
|
294 | + { |
|
295 | + $this->seeTextInViewMessageModal($text_to_view, true); |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + public function dismissMessageModal() |
|
300 | + { |
|
301 | + $this->actor()->executeJs('window.dialogHelper.closeModal()'); |
|
302 | + } |
|
303 | 303 | } |
@@ -16,24 +16,24 @@ |
||
16 | 16 | */ |
17 | 17 | class AssetRegistrationException extends RuntimeException |
18 | 18 | { |
19 | - /** |
|
20 | - * @param $script_handle |
|
21 | - * @param string $message |
|
22 | - * @param int $code |
|
23 | - * @param Exception|null $previous |
|
24 | - */ |
|
25 | - public function __construct($script_handle, $message = '', $code = 0, Exception $previous = null) |
|
26 | - { |
|
27 | - if (empty($message)) { |
|
28 | - $message = sprintf( |
|
29 | - esc_html_x( |
|
30 | - 'The "%1$s" script could not be registered with WordPress core.', |
|
31 | - 'The "script-handle" script could not be registered with WordPress core.', |
|
32 | - 'event_espresso' |
|
33 | - ), |
|
34 | - $script_handle |
|
35 | - ); |
|
36 | - } |
|
37 | - parent::__construct($message, $code, $previous); |
|
38 | - } |
|
19 | + /** |
|
20 | + * @param $script_handle |
|
21 | + * @param string $message |
|
22 | + * @param int $code |
|
23 | + * @param Exception|null $previous |
|
24 | + */ |
|
25 | + public function __construct($script_handle, $message = '', $code = 0, Exception $previous = null) |
|
26 | + { |
|
27 | + if (empty($message)) { |
|
28 | + $message = sprintf( |
|
29 | + esc_html_x( |
|
30 | + 'The "%1$s" script could not be registered with WordPress core.', |
|
31 | + 'The "script-handle" script could not be registered with WordPress core.', |
|
32 | + 'event_espresso' |
|
33 | + ), |
|
34 | + $script_handle |
|
35 | + ); |
|
36 | + } |
|
37 | + parent::__construct($message, $code, $previous); |
|
38 | + } |
|
39 | 39 | } |
40 | 40 | \ No newline at end of file |
@@ -16,20 +16,20 @@ |
||
16 | 16 | interface PrivacyPolicyInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * Returns the translated name to display in this privacy policy's section's title |
|
21 | - * |
|
22 | - * @return string |
|
23 | - */ |
|
24 | - public function getName(); |
|
19 | + /** |
|
20 | + * Returns the translated name to display in this privacy policy's section's title |
|
21 | + * |
|
22 | + * @return string |
|
23 | + */ |
|
24 | + public function getName(); |
|
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * Returns the suggested privacy policy content for this plugin. May contain HTML |
|
29 | - * |
|
30 | - * @return string |
|
31 | - */ |
|
32 | - public function getContent(); |
|
27 | + /** |
|
28 | + * Returns the suggested privacy policy content for this plugin. May contain HTML |
|
29 | + * |
|
30 | + * @return string |
|
31 | + */ |
|
32 | + public function getContent(); |
|
33 | 33 | } |
34 | 34 | // End of file PrivacyPolicyInterface.php |
35 | 35 | // Location: EventEspresso\core\domain\services\admin/PrivacyPolicyInterface.php |
@@ -4,7 +4,6 @@ |
||
4 | 4 | |
5 | 5 | use EE_Registration; |
6 | 6 | use EE_Ticket; |
7 | -use EEM_Answer; |
|
8 | 7 | use EEM_Registration; |
9 | 8 | use EventEspresso\core\services\privacy\export\PersonalDataExporterInterface; |
10 | 9 |
@@ -18,133 +18,133 @@ |
||
18 | 18 | */ |
19 | 19 | class ExportRegistration implements PersonalDataExporterInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * @var EEM_Registration |
|
23 | - */ |
|
24 | - protected $registration_model; |
|
21 | + /** |
|
22 | + * @var EEM_Registration |
|
23 | + */ |
|
24 | + protected $registration_model; |
|
25 | 25 | |
26 | - /** |
|
27 | - * ExportRegistration constructor. |
|
28 | - * |
|
29 | - * @param EEM_Registration $registration_model |
|
30 | - */ |
|
31 | - public function __construct(EEM_Registration $registration_model) |
|
32 | - { |
|
33 | - $this->registration_model = $registration_model; |
|
34 | - } |
|
26 | + /** |
|
27 | + * ExportRegistration constructor. |
|
28 | + * |
|
29 | + * @param EEM_Registration $registration_model |
|
30 | + */ |
|
31 | + public function __construct(EEM_Registration $registration_model) |
|
32 | + { |
|
33 | + $this->registration_model = $registration_model; |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * Returns data for export. |
|
39 | - * |
|
40 | - * @param string $email_address , |
|
41 | - * @param int $page starts at 1, not 0 |
|
42 | - * @return array { |
|
43 | - * @type array $data { |
|
44 | - * @type array { |
|
45 | - * @type string $group_id (not translated, same for all exports) |
|
46 | - * @type string $group_label (translated string) |
|
47 | - * @type string|int $item_id |
|
48 | - * @type array $data { |
|
49 | - * @type array { |
|
50 | - * @type string $name what's shown in the left-column of the export row |
|
51 | - * @type string $value what's showin the right-column of the export row |
|
52 | - * } |
|
53 | - * } |
|
54 | - * } |
|
55 | - * } |
|
56 | - * } |
|
57 | - */ |
|
58 | - public function export($email_address, $page = 1) |
|
59 | - { |
|
60 | - $page_size = 10; |
|
61 | - $registrations = $this->registration_model->get_all( |
|
62 | - array( |
|
63 | - array( |
|
64 | - 'Attendee.ATT_email' => $email_address, |
|
65 | - ), |
|
66 | - 'limit' => array( |
|
67 | - ($page - 1) * $page_size, |
|
68 | - $page_size, |
|
69 | - ), |
|
70 | - ) |
|
71 | - ); |
|
72 | - $export_fields = array_intersect_key( |
|
73 | - $this->registration_model->field_settings(), |
|
74 | - array_flip( |
|
75 | - array( |
|
76 | - 'REG_code', |
|
77 | - 'REG_date', |
|
78 | - 'REG_final_price', |
|
79 | - 'REG_paid', |
|
80 | - 'REG_url_link', |
|
81 | - 'REG_count', |
|
82 | - 'REG_group_size', |
|
83 | - 'REG_att_is_going', |
|
84 | - ) |
|
85 | - ) |
|
86 | - ); |
|
87 | - $export_items = array(); |
|
88 | - $found_something = false; |
|
89 | - foreach ($registrations as $registration) { |
|
90 | - /** |
|
91 | - * @var $registration EE_Registration |
|
92 | - */ |
|
93 | - $found_something = true; |
|
94 | - $data = array(); |
|
95 | - foreach ($export_fields as $field_name => $field_obj) { |
|
96 | - $data[] = array( |
|
97 | - 'name' => $field_obj->get_nicename(), |
|
98 | - 'value' => $registration->get_pretty($field_name), |
|
99 | - ); |
|
100 | - } |
|
101 | - $answers = $registration->answers( |
|
102 | - array( |
|
103 | - 'force_join' => array( |
|
104 | - 'Question', |
|
105 | - ), |
|
106 | - ) |
|
107 | - ); |
|
108 | - foreach ($answers as $answer) { |
|
109 | - $data[] = array( |
|
110 | - 'name' => $answer->question()->display_text(), |
|
111 | - 'value' => $answer->pretty_value(), |
|
112 | - ); |
|
113 | - } |
|
114 | - $ticket = $registration->ticket(); |
|
115 | - if ($ticket instanceof EE_Ticket) { |
|
116 | - $data[] = array( |
|
117 | - 'name' => esc_html__('Ticket', 'event_espresso'), |
|
118 | - 'value' => $ticket->name_and_info(), |
|
119 | - ); |
|
120 | - $data[] = array( |
|
121 | - 'name' => esc_html__('Event', 'event_espresso'), |
|
122 | - 'value' => $ticket->get_event_name(), |
|
123 | - ); |
|
124 | - } |
|
37 | + /** |
|
38 | + * Returns data for export. |
|
39 | + * |
|
40 | + * @param string $email_address , |
|
41 | + * @param int $page starts at 1, not 0 |
|
42 | + * @return array { |
|
43 | + * @type array $data { |
|
44 | + * @type array { |
|
45 | + * @type string $group_id (not translated, same for all exports) |
|
46 | + * @type string $group_label (translated string) |
|
47 | + * @type string|int $item_id |
|
48 | + * @type array $data { |
|
49 | + * @type array { |
|
50 | + * @type string $name what's shown in the left-column of the export row |
|
51 | + * @type string $value what's showin the right-column of the export row |
|
52 | + * } |
|
53 | + * } |
|
54 | + * } |
|
55 | + * } |
|
56 | + * } |
|
57 | + */ |
|
58 | + public function export($email_address, $page = 1) |
|
59 | + { |
|
60 | + $page_size = 10; |
|
61 | + $registrations = $this->registration_model->get_all( |
|
62 | + array( |
|
63 | + array( |
|
64 | + 'Attendee.ATT_email' => $email_address, |
|
65 | + ), |
|
66 | + 'limit' => array( |
|
67 | + ($page - 1) * $page_size, |
|
68 | + $page_size, |
|
69 | + ), |
|
70 | + ) |
|
71 | + ); |
|
72 | + $export_fields = array_intersect_key( |
|
73 | + $this->registration_model->field_settings(), |
|
74 | + array_flip( |
|
75 | + array( |
|
76 | + 'REG_code', |
|
77 | + 'REG_date', |
|
78 | + 'REG_final_price', |
|
79 | + 'REG_paid', |
|
80 | + 'REG_url_link', |
|
81 | + 'REG_count', |
|
82 | + 'REG_group_size', |
|
83 | + 'REG_att_is_going', |
|
84 | + ) |
|
85 | + ) |
|
86 | + ); |
|
87 | + $export_items = array(); |
|
88 | + $found_something = false; |
|
89 | + foreach ($registrations as $registration) { |
|
90 | + /** |
|
91 | + * @var $registration EE_Registration |
|
92 | + */ |
|
93 | + $found_something = true; |
|
94 | + $data = array(); |
|
95 | + foreach ($export_fields as $field_name => $field_obj) { |
|
96 | + $data[] = array( |
|
97 | + 'name' => $field_obj->get_nicename(), |
|
98 | + 'value' => $registration->get_pretty($field_name), |
|
99 | + ); |
|
100 | + } |
|
101 | + $answers = $registration->answers( |
|
102 | + array( |
|
103 | + 'force_join' => array( |
|
104 | + 'Question', |
|
105 | + ), |
|
106 | + ) |
|
107 | + ); |
|
108 | + foreach ($answers as $answer) { |
|
109 | + $data[] = array( |
|
110 | + 'name' => $answer->question()->display_text(), |
|
111 | + 'value' => $answer->pretty_value(), |
|
112 | + ); |
|
113 | + } |
|
114 | + $ticket = $registration->ticket(); |
|
115 | + if ($ticket instanceof EE_Ticket) { |
|
116 | + $data[] = array( |
|
117 | + 'name' => esc_html__('Ticket', 'event_espresso'), |
|
118 | + 'value' => $ticket->name_and_info(), |
|
119 | + ); |
|
120 | + $data[] = array( |
|
121 | + 'name' => esc_html__('Event', 'event_espresso'), |
|
122 | + 'value' => $ticket->get_event_name(), |
|
123 | + ); |
|
124 | + } |
|
125 | 125 | |
126 | - $export_items[] = array( |
|
127 | - 'group_id' => 'registration', |
|
128 | - 'group_label' => esc_html__('Event Registrations', 'event_espresso'), |
|
129 | - 'item_id' => $registration->ID(), |
|
130 | - 'data' => $data, |
|
131 | - ); |
|
132 | - } |
|
133 | - return array( |
|
134 | - 'data' => $export_items, |
|
135 | - 'done' => ! $found_something, |
|
136 | - ); |
|
137 | - } |
|
126 | + $export_items[] = array( |
|
127 | + 'group_id' => 'registration', |
|
128 | + 'group_label' => esc_html__('Event Registrations', 'event_espresso'), |
|
129 | + 'item_id' => $registration->ID(), |
|
130 | + 'data' => $data, |
|
131 | + ); |
|
132 | + } |
|
133 | + return array( |
|
134 | + 'data' => $export_items, |
|
135 | + 'done' => ! $found_something, |
|
136 | + ); |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * Gets the Translated name of this exporter |
|
141 | - * |
|
142 | - * @return string |
|
143 | - */ |
|
144 | - public function name() |
|
145 | - { |
|
146 | - return esc_html__('Event Espresso Registration Data Exporter', 'event_espresso'); |
|
147 | - } |
|
139 | + /** |
|
140 | + * Gets the Translated name of this exporter |
|
141 | + * |
|
142 | + * @return string |
|
143 | + */ |
|
144 | + public function name() |
|
145 | + { |
|
146 | + return esc_html__('Event Espresso Registration Data Exporter', 'event_espresso'); |
|
147 | + } |
|
148 | 148 | } |
149 | 149 | // End of file ExportRegistration.php |
150 | 150 | // Location: EventEspresso\core\domain\services\admin\privacy\export/ExportRegistration.php |
@@ -15,106 +15,106 @@ |
||
15 | 15 | */ |
16 | 16 | class ExportTransaction implements PersonalDataExporterInterface |
17 | 17 | { |
18 | - /** |
|
19 | - * @var EEM_Transaction $transaction_model |
|
20 | - */ |
|
21 | - protected $transaction_model; |
|
18 | + /** |
|
19 | + * @var EEM_Transaction $transaction_model |
|
20 | + */ |
|
21 | + protected $transaction_model; |
|
22 | 22 | |
23 | - /** |
|
24 | - * ExportTransaction constructor. |
|
25 | - * |
|
26 | - * @param $transaction_model |
|
27 | - */ |
|
28 | - public function __construct(EEM_Transaction $transaction_model) |
|
29 | - { |
|
30 | - $this->transaction_model = $transaction_model; |
|
31 | - } |
|
23 | + /** |
|
24 | + * ExportTransaction constructor. |
|
25 | + * |
|
26 | + * @param $transaction_model |
|
27 | + */ |
|
28 | + public function __construct(EEM_Transaction $transaction_model) |
|
29 | + { |
|
30 | + $this->transaction_model = $transaction_model; |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * Returns data for export. |
|
36 | - * |
|
37 | - * @param string $email_address , |
|
38 | - * @param int $page starts at 1, not 0 |
|
39 | - * @return array { |
|
40 | - * @type array $data { |
|
41 | - * @type array { |
|
42 | - * @type string $group_id (not translated, same for all exports) |
|
43 | - * @type string $group_label (translated string) |
|
44 | - * @type string|int $item_id |
|
45 | - * @type array $data { |
|
46 | - * @type array { |
|
47 | - * @type string $name what's shown in the left-column of the export row |
|
48 | - * @type string $value what's showin the right-column of the export row |
|
49 | - * } |
|
50 | - * } |
|
51 | - * } |
|
52 | - * } |
|
53 | - * } |
|
54 | - */ |
|
55 | - public function export($email_address, $page = 1) |
|
56 | - { |
|
57 | - $page_size = 10; |
|
58 | - $transactions = $this->transaction_model->get_all( |
|
59 | - array( |
|
60 | - array( |
|
61 | - 'Registration.Attendee.ATT_email' => $email_address, |
|
62 | - ), |
|
63 | - 'limit' => array( |
|
64 | - ($page - 1) * $page_size, |
|
65 | - $page_size, |
|
66 | - ), |
|
67 | - ) |
|
68 | - ); |
|
69 | - $export_fields = array_intersect_key( |
|
70 | - EEM_Transaction::instance()->field_settings(), |
|
71 | - array_flip( |
|
72 | - array( |
|
73 | - 'TXN_timestamp', |
|
74 | - 'TXN_total', |
|
75 | - 'TXN_paid', |
|
76 | - 'TXN_session_data', |
|
77 | - ) |
|
78 | - ) |
|
79 | - ); |
|
80 | - $export_items = array(); |
|
81 | - $found_something = false; |
|
82 | - foreach ($transactions as $transaction) { |
|
83 | - $found_something = true; |
|
84 | - $data = array(); |
|
85 | - foreach ($export_fields as $field_name => $field_obj) { |
|
86 | - if ($field_name === 'TXN_session_data') { |
|
87 | - $value = $transaction->get_pretty($field_name, 'print_r'); |
|
88 | - } else { |
|
89 | - $value = $transaction->get_pretty($field_name); |
|
90 | - } |
|
91 | - $data[] = array( |
|
92 | - 'name' => $field_obj->get_nicename(), |
|
93 | - 'value' => $value, |
|
94 | - ); |
|
95 | - } |
|
96 | - $export_items[] = array( |
|
97 | - 'group_id' => 'transactions', |
|
98 | - 'group_label' => esc_html__('Transactions', 'event_espresso'), |
|
99 | - 'item_id' => $transaction->ID(), |
|
100 | - 'data' => $data, |
|
101 | - ); |
|
102 | - } |
|
103 | - return array( |
|
104 | - 'data' => $export_items, |
|
105 | - 'done' => ! $found_something, |
|
106 | - ); |
|
107 | - } |
|
34 | + /** |
|
35 | + * Returns data for export. |
|
36 | + * |
|
37 | + * @param string $email_address , |
|
38 | + * @param int $page starts at 1, not 0 |
|
39 | + * @return array { |
|
40 | + * @type array $data { |
|
41 | + * @type array { |
|
42 | + * @type string $group_id (not translated, same for all exports) |
|
43 | + * @type string $group_label (translated string) |
|
44 | + * @type string|int $item_id |
|
45 | + * @type array $data { |
|
46 | + * @type array { |
|
47 | + * @type string $name what's shown in the left-column of the export row |
|
48 | + * @type string $value what's showin the right-column of the export row |
|
49 | + * } |
|
50 | + * } |
|
51 | + * } |
|
52 | + * } |
|
53 | + * } |
|
54 | + */ |
|
55 | + public function export($email_address, $page = 1) |
|
56 | + { |
|
57 | + $page_size = 10; |
|
58 | + $transactions = $this->transaction_model->get_all( |
|
59 | + array( |
|
60 | + array( |
|
61 | + 'Registration.Attendee.ATT_email' => $email_address, |
|
62 | + ), |
|
63 | + 'limit' => array( |
|
64 | + ($page - 1) * $page_size, |
|
65 | + $page_size, |
|
66 | + ), |
|
67 | + ) |
|
68 | + ); |
|
69 | + $export_fields = array_intersect_key( |
|
70 | + EEM_Transaction::instance()->field_settings(), |
|
71 | + array_flip( |
|
72 | + array( |
|
73 | + 'TXN_timestamp', |
|
74 | + 'TXN_total', |
|
75 | + 'TXN_paid', |
|
76 | + 'TXN_session_data', |
|
77 | + ) |
|
78 | + ) |
|
79 | + ); |
|
80 | + $export_items = array(); |
|
81 | + $found_something = false; |
|
82 | + foreach ($transactions as $transaction) { |
|
83 | + $found_something = true; |
|
84 | + $data = array(); |
|
85 | + foreach ($export_fields as $field_name => $field_obj) { |
|
86 | + if ($field_name === 'TXN_session_data') { |
|
87 | + $value = $transaction->get_pretty($field_name, 'print_r'); |
|
88 | + } else { |
|
89 | + $value = $transaction->get_pretty($field_name); |
|
90 | + } |
|
91 | + $data[] = array( |
|
92 | + 'name' => $field_obj->get_nicename(), |
|
93 | + 'value' => $value, |
|
94 | + ); |
|
95 | + } |
|
96 | + $export_items[] = array( |
|
97 | + 'group_id' => 'transactions', |
|
98 | + 'group_label' => esc_html__('Transactions', 'event_espresso'), |
|
99 | + 'item_id' => $transaction->ID(), |
|
100 | + 'data' => $data, |
|
101 | + ); |
|
102 | + } |
|
103 | + return array( |
|
104 | + 'data' => $export_items, |
|
105 | + 'done' => ! $found_something, |
|
106 | + ); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Gets the Translated name of this exporter |
|
111 | - * |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - public function name() |
|
115 | - { |
|
116 | - return esc_html__('Event Espresso Transaction Exporter', 'event_espresso'); |
|
117 | - } |
|
109 | + /** |
|
110 | + * Gets the Translated name of this exporter |
|
111 | + * |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + public function name() |
|
115 | + { |
|
116 | + return esc_html__('Event Espresso Transaction Exporter', 'event_espresso'); |
|
117 | + } |
|
118 | 118 | } |
119 | 119 | // End of file ExportTransaction.php |
120 | 120 | // Location: EventEspresso\core\domain\services\admin\privacy\export/ExportTransaction.php |