@@ -23,43 +23,43 @@ |
||
23 | 23 | class Attendee extends Calculations_Base |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @since $VID:$ |
|
28 | - * @param $wpdb_row |
|
29 | - * @return EE_Attendee|\EE_Base_Class |
|
30 | - * @throws EE_Error |
|
31 | - * @throws InvalidArgumentException |
|
32 | - * @throws InvalidDataTypeException |
|
33 | - * @throws InvalidInterfaceException |
|
34 | - */ |
|
35 | - private static function getAttendeeObject($wpdb_row) |
|
36 | - { |
|
37 | - $attendee = null; |
|
38 | - if (is_array($wpdb_row) && isset($wpdb_row['Attendee_CPT.ID']) && absint($wpdb_row['Attendee_CPT.ID'])) { |
|
39 | - $attendee = EEM_Attendee::instance()->get_one_by_ID($wpdb_row['Attendee_CPT.ID']); |
|
40 | - } |
|
41 | - return $attendee; |
|
42 | - } |
|
26 | + /** |
|
27 | + * @since $VID:$ |
|
28 | + * @param $wpdb_row |
|
29 | + * @return EE_Attendee|\EE_Base_Class |
|
30 | + * @throws EE_Error |
|
31 | + * @throws InvalidArgumentException |
|
32 | + * @throws InvalidDataTypeException |
|
33 | + * @throws InvalidInterfaceException |
|
34 | + */ |
|
35 | + private static function getAttendeeObject($wpdb_row) |
|
36 | + { |
|
37 | + $attendee = null; |
|
38 | + if (is_array($wpdb_row) && isset($wpdb_row['Attendee_CPT.ID']) && absint($wpdb_row['Attendee_CPT.ID'])) { |
|
39 | + $attendee = EEM_Attendee::instance()->get_one_by_ID($wpdb_row['Attendee_CPT.ID']); |
|
40 | + } |
|
41 | + return $attendee; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * @param array $wpdb_row |
|
47 | - * @param WP_REST_Request $request |
|
48 | - * @param Base $controller |
|
49 | - * @since $VID:$ |
|
50 | - * @return string |
|
51 | - * @throws EE_Error |
|
52 | - * @throws InvalidArgumentException |
|
53 | - * @throws InvalidDataTypeException |
|
54 | - * @throws InvalidInterfaceException |
|
55 | - */ |
|
56 | - public static function userAvatar(array $wpdb_row, WP_REST_Request $request, Base $controller) |
|
57 | - { |
|
58 | - $attendee = Attendee::getAttendeeObject($wpdb_row); |
|
59 | - if (! $attendee instanceof EE_Attendee) { |
|
60 | - return ''; |
|
61 | - } |
|
62 | - $avatar = get_avatar_url($attendee->email()); |
|
63 | - return $avatar ? $avatar : ''; |
|
64 | - } |
|
45 | + /** |
|
46 | + * @param array $wpdb_row |
|
47 | + * @param WP_REST_Request $request |
|
48 | + * @param Base $controller |
|
49 | + * @since $VID:$ |
|
50 | + * @return string |
|
51 | + * @throws EE_Error |
|
52 | + * @throws InvalidArgumentException |
|
53 | + * @throws InvalidDataTypeException |
|
54 | + * @throws InvalidInterfaceException |
|
55 | + */ |
|
56 | + public static function userAvatar(array $wpdb_row, WP_REST_Request $request, Base $controller) |
|
57 | + { |
|
58 | + $attendee = Attendee::getAttendeeObject($wpdb_row); |
|
59 | + if (! $attendee instanceof EE_Attendee) { |
|
60 | + return ''; |
|
61 | + } |
|
62 | + $avatar = get_avatar_url($attendee->email()); |
|
63 | + return $avatar ? $avatar : ''; |
|
64 | + } |
|
65 | 65 | } |
@@ -56,7 +56,7 @@ |
||
56 | 56 | public static function userAvatar(array $wpdb_row, WP_REST_Request $request, Base $controller) |
57 | 57 | { |
58 | 58 | $attendee = Attendee::getAttendeeObject($wpdb_row); |
59 | - if (! $attendee instanceof EE_Attendee) { |
|
59 | + if ( ! $attendee instanceof EE_Attendee) { |
|
60 | 60 | return ''; |
61 | 61 | } |
62 | 62 | $avatar = get_avatar_url($attendee->email()); |
@@ -19,128 +19,128 @@ |
||
19 | 19 | class CalculatedModelFields |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - protected $mapping; |
|
22 | + /** |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + protected $mapping; |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * @param bool $refresh |
|
30 | - * @return array top-level-keys are model names (eg "Event") |
|
31 | - * next-level are the calculated field names AND method names on classes |
|
32 | - * which perform calculations, values are the fully qualified classnames which do the calculations |
|
33 | - * These callbacks should accept as arguments: |
|
34 | - * the wpdb row results, |
|
35 | - * the WP_Request object, |
|
36 | - * the controller object |
|
37 | - */ |
|
38 | - public function mapping($refresh = false) |
|
39 | - { |
|
40 | - if (! $this->mapping || $refresh) { |
|
41 | - $this->mapping = $this->generateNewMapping(); |
|
42 | - } |
|
43 | - return $this->mapping; |
|
44 | - } |
|
28 | + /** |
|
29 | + * @param bool $refresh |
|
30 | + * @return array top-level-keys are model names (eg "Event") |
|
31 | + * next-level are the calculated field names AND method names on classes |
|
32 | + * which perform calculations, values are the fully qualified classnames which do the calculations |
|
33 | + * These callbacks should accept as arguments: |
|
34 | + * the wpdb row results, |
|
35 | + * the WP_Request object, |
|
36 | + * the controller object |
|
37 | + */ |
|
38 | + public function mapping($refresh = false) |
|
39 | + { |
|
40 | + if (! $this->mapping || $refresh) { |
|
41 | + $this->mapping = $this->generateNewMapping(); |
|
42 | + } |
|
43 | + return $this->mapping; |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * Generates anew mapping between model calculated fields and their callbacks |
|
49 | - * |
|
50 | - * @return array |
|
51 | - */ |
|
52 | - protected function generateNewMapping() |
|
53 | - { |
|
54 | - $rest_api_calculations_namespace = 'EventEspresso\core\libraries\rest_api\calculations\\'; |
|
55 | - $event_calculations_class = $rest_api_calculations_namespace . 'Event'; |
|
56 | - $datetime_calculations_class = $rest_api_calculations_namespace . 'Datetime'; |
|
57 | - $registration_class = $rest_api_calculations_namespace . 'Registration'; |
|
58 | - $attendee_class = $rest_api_calculations_namespace . 'Attendee'; |
|
59 | - return apply_filters( |
|
60 | - 'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping', |
|
61 | - array( |
|
62 | - 'Event' => array( |
|
63 | - 'optimum_sales_at_start' => $event_calculations_class, |
|
64 | - 'optimum_sales_now' => $event_calculations_class, |
|
65 | - 'spots_taken' => $event_calculations_class, |
|
66 | - 'spots_taken_pending_payment' => $event_calculations_class, |
|
67 | - 'spaces_remaining' => $event_calculations_class, |
|
68 | - 'registrations_checked_in_count' => $event_calculations_class, |
|
69 | - 'registrations_checked_out_count' => $event_calculations_class, |
|
70 | - 'image_thumbnail' => $event_calculations_class, |
|
71 | - 'image_medium' => $event_calculations_class, |
|
72 | - 'image_medium_large' => $event_calculations_class, |
|
73 | - 'image_large' => $event_calculations_class, |
|
74 | - 'image_post_thumbnail' => $event_calculations_class, |
|
75 | - 'image_full' => $event_calculations_class, |
|
76 | - ), |
|
77 | - 'Datetime' => array( |
|
78 | - 'spaces_remaining_considering_tickets' => $datetime_calculations_class, |
|
79 | - 'registrations_checked_in_count' => $datetime_calculations_class, |
|
80 | - 'registrations_checked_out_count' => $datetime_calculations_class, |
|
81 | - 'spots_taken_pending_payment' => $datetime_calculations_class, |
|
82 | - ), |
|
83 | - 'Registration' => array( |
|
84 | - 'datetime_checkin_stati' => $registration_class, |
|
85 | - ), |
|
86 | - 'Attendee' => array( |
|
87 | - 'userAvatar' => $attendee_class, |
|
88 | - ), |
|
89 | - ) |
|
90 | - ); |
|
91 | - } |
|
47 | + /** |
|
48 | + * Generates anew mapping between model calculated fields and their callbacks |
|
49 | + * |
|
50 | + * @return array |
|
51 | + */ |
|
52 | + protected function generateNewMapping() |
|
53 | + { |
|
54 | + $rest_api_calculations_namespace = 'EventEspresso\core\libraries\rest_api\calculations\\'; |
|
55 | + $event_calculations_class = $rest_api_calculations_namespace . 'Event'; |
|
56 | + $datetime_calculations_class = $rest_api_calculations_namespace . 'Datetime'; |
|
57 | + $registration_class = $rest_api_calculations_namespace . 'Registration'; |
|
58 | + $attendee_class = $rest_api_calculations_namespace . 'Attendee'; |
|
59 | + return apply_filters( |
|
60 | + 'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping', |
|
61 | + array( |
|
62 | + 'Event' => array( |
|
63 | + 'optimum_sales_at_start' => $event_calculations_class, |
|
64 | + 'optimum_sales_now' => $event_calculations_class, |
|
65 | + 'spots_taken' => $event_calculations_class, |
|
66 | + 'spots_taken_pending_payment' => $event_calculations_class, |
|
67 | + 'spaces_remaining' => $event_calculations_class, |
|
68 | + 'registrations_checked_in_count' => $event_calculations_class, |
|
69 | + 'registrations_checked_out_count' => $event_calculations_class, |
|
70 | + 'image_thumbnail' => $event_calculations_class, |
|
71 | + 'image_medium' => $event_calculations_class, |
|
72 | + 'image_medium_large' => $event_calculations_class, |
|
73 | + 'image_large' => $event_calculations_class, |
|
74 | + 'image_post_thumbnail' => $event_calculations_class, |
|
75 | + 'image_full' => $event_calculations_class, |
|
76 | + ), |
|
77 | + 'Datetime' => array( |
|
78 | + 'spaces_remaining_considering_tickets' => $datetime_calculations_class, |
|
79 | + 'registrations_checked_in_count' => $datetime_calculations_class, |
|
80 | + 'registrations_checked_out_count' => $datetime_calculations_class, |
|
81 | + 'spots_taken_pending_payment' => $datetime_calculations_class, |
|
82 | + ), |
|
83 | + 'Registration' => array( |
|
84 | + 'datetime_checkin_stati' => $registration_class, |
|
85 | + ), |
|
86 | + 'Attendee' => array( |
|
87 | + 'userAvatar' => $attendee_class, |
|
88 | + ), |
|
89 | + ) |
|
90 | + ); |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - /** |
|
95 | - * Gets the known calculated fields for model |
|
96 | - * |
|
97 | - * @param EEM_Base $model |
|
98 | - * @return array allowable values for this field |
|
99 | - */ |
|
100 | - public function retrieveCalculatedFieldsForModel(EEM_Base $model) |
|
101 | - { |
|
102 | - $mapping = $this->mapping(); |
|
103 | - if (isset($mapping[ $model->get_this_model_name() ])) { |
|
104 | - return array_keys($mapping[ $model->get_this_model_name() ]); |
|
105 | - } else { |
|
106 | - return array(); |
|
107 | - } |
|
108 | - } |
|
94 | + /** |
|
95 | + * Gets the known calculated fields for model |
|
96 | + * |
|
97 | + * @param EEM_Base $model |
|
98 | + * @return array allowable values for this field |
|
99 | + */ |
|
100 | + public function retrieveCalculatedFieldsForModel(EEM_Base $model) |
|
101 | + { |
|
102 | + $mapping = $this->mapping(); |
|
103 | + if (isset($mapping[ $model->get_this_model_name() ])) { |
|
104 | + return array_keys($mapping[ $model->get_this_model_name() ]); |
|
105 | + } else { |
|
106 | + return array(); |
|
107 | + } |
|
108 | + } |
|
109 | 109 | |
110 | 110 | |
111 | - /** |
|
112 | - * Retrieves the value for this calculation |
|
113 | - * |
|
114 | - * @param EEM_Base $model |
|
115 | - * @param string $field_name |
|
116 | - * @param array $wpdb_row |
|
117 | - * @param \WP_REST_Request |
|
118 | - * @param \EventEspresso\core\libraries\rest_api\controllers\Base $controller |
|
119 | - * @return mixed|null |
|
120 | - * @throws \EE_Error |
|
121 | - */ |
|
122 | - public function retrieveCalculatedFieldValue( |
|
123 | - EEM_Base $model, |
|
124 | - $field_name, |
|
125 | - $wpdb_row, |
|
126 | - $rest_request, |
|
127 | - Base $controller |
|
128 | - ) { |
|
129 | - $mapping = $this->mapping(); |
|
130 | - if (isset($mapping[ $model->get_this_model_name() ]) |
|
131 | - && isset($mapping[ $model->get_this_model_name() ][ $field_name ]) |
|
132 | - ) { |
|
133 | - $classname = $mapping[ $model->get_this_model_name() ][ $field_name ]; |
|
134 | - $class_method_name = EEH_Inflector::camelize_all_but_first($field_name); |
|
135 | - return call_user_func(array($classname, $class_method_name), $wpdb_row, $rest_request, $controller); |
|
136 | - } |
|
137 | - throw new RestException( |
|
138 | - 'calculated_field_does_not_exist', |
|
139 | - sprintf( |
|
140 | - __('There is no calculated field %1$s on resource %2$s', 'event_espresso'), |
|
141 | - $field_name, |
|
142 | - $model->get_this_model_name() |
|
143 | - ) |
|
144 | - ); |
|
145 | - } |
|
111 | + /** |
|
112 | + * Retrieves the value for this calculation |
|
113 | + * |
|
114 | + * @param EEM_Base $model |
|
115 | + * @param string $field_name |
|
116 | + * @param array $wpdb_row |
|
117 | + * @param \WP_REST_Request |
|
118 | + * @param \EventEspresso\core\libraries\rest_api\controllers\Base $controller |
|
119 | + * @return mixed|null |
|
120 | + * @throws \EE_Error |
|
121 | + */ |
|
122 | + public function retrieveCalculatedFieldValue( |
|
123 | + EEM_Base $model, |
|
124 | + $field_name, |
|
125 | + $wpdb_row, |
|
126 | + $rest_request, |
|
127 | + Base $controller |
|
128 | + ) { |
|
129 | + $mapping = $this->mapping(); |
|
130 | + if (isset($mapping[ $model->get_this_model_name() ]) |
|
131 | + && isset($mapping[ $model->get_this_model_name() ][ $field_name ]) |
|
132 | + ) { |
|
133 | + $classname = $mapping[ $model->get_this_model_name() ][ $field_name ]; |
|
134 | + $class_method_name = EEH_Inflector::camelize_all_but_first($field_name); |
|
135 | + return call_user_func(array($classname, $class_method_name), $wpdb_row, $rest_request, $controller); |
|
136 | + } |
|
137 | + throw new RestException( |
|
138 | + 'calculated_field_does_not_exist', |
|
139 | + sprintf( |
|
140 | + __('There is no calculated field %1$s on resource %2$s', 'event_espresso'), |
|
141 | + $field_name, |
|
142 | + $model->get_this_model_name() |
|
143 | + ) |
|
144 | + ); |
|
145 | + } |
|
146 | 146 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function mapping($refresh = false) |
39 | 39 | { |
40 | - if (! $this->mapping || $refresh) { |
|
40 | + if ( ! $this->mapping || $refresh) { |
|
41 | 41 | $this->mapping = $this->generateNewMapping(); |
42 | 42 | } |
43 | 43 | return $this->mapping; |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | protected function generateNewMapping() |
53 | 53 | { |
54 | 54 | $rest_api_calculations_namespace = 'EventEspresso\core\libraries\rest_api\calculations\\'; |
55 | - $event_calculations_class = $rest_api_calculations_namespace . 'Event'; |
|
56 | - $datetime_calculations_class = $rest_api_calculations_namespace . 'Datetime'; |
|
57 | - $registration_class = $rest_api_calculations_namespace . 'Registration'; |
|
58 | - $attendee_class = $rest_api_calculations_namespace . 'Attendee'; |
|
55 | + $event_calculations_class = $rest_api_calculations_namespace.'Event'; |
|
56 | + $datetime_calculations_class = $rest_api_calculations_namespace.'Datetime'; |
|
57 | + $registration_class = $rest_api_calculations_namespace.'Registration'; |
|
58 | + $attendee_class = $rest_api_calculations_namespace.'Attendee'; |
|
59 | 59 | return apply_filters( |
60 | 60 | 'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping', |
61 | 61 | array( |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | public function retrieveCalculatedFieldsForModel(EEM_Base $model) |
101 | 101 | { |
102 | 102 | $mapping = $this->mapping(); |
103 | - if (isset($mapping[ $model->get_this_model_name() ])) { |
|
104 | - return array_keys($mapping[ $model->get_this_model_name() ]); |
|
103 | + if (isset($mapping[$model->get_this_model_name()])) { |
|
104 | + return array_keys($mapping[$model->get_this_model_name()]); |
|
105 | 105 | } else { |
106 | 106 | return array(); |
107 | 107 | } |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | Base $controller |
128 | 128 | ) { |
129 | 129 | $mapping = $this->mapping(); |
130 | - if (isset($mapping[ $model->get_this_model_name() ]) |
|
131 | - && isset($mapping[ $model->get_this_model_name() ][ $field_name ]) |
|
130 | + if (isset($mapping[$model->get_this_model_name()]) |
|
131 | + && isset($mapping[$model->get_this_model_name()][$field_name]) |
|
132 | 132 | ) { |
133 | - $classname = $mapping[ $model->get_this_model_name() ][ $field_name ]; |
|
133 | + $classname = $mapping[$model->get_this_model_name()][$field_name]; |
|
134 | 134 | $class_method_name = EEH_Inflector::camelize_all_but_first($field_name); |
135 | 135 | return call_user_func(array($classname, $class_method_name), $wpdb_row, $rest_request, $controller); |
136 | 136 | } |