/** * Gets the calculated fields for the response * * @param \EEM_Base $model * @param array $wpdb_row * @param \WP_REST_Request $rest_request * @return array the _calculations item in the entity */ protected function _get_entity_calculations($model, $wpdb_row, $rest_request) { $calculated_fields = $this->explode_and_get_items_prefixed_with($rest_request->get_param('calculate'), ''); //note: setting calculate=* doesn't do anything $calculated_fields_to_return = new \stdClass(); foreach ($calculated_fields as $field_to_calculate) { try { $calculated_fields_to_return->{$field_to_calculate} = Model_Data_Translator::prepare_field_value_for_json(null, $this->_fields_calculator->retrieve_calculated_field_value($model, $field_to_calculate, $wpdb_row, $rest_request, $this), $this->get_model_version_info()->requested_version()); } catch (Rest_Exception $e) { //if we don't have permission to read it, just leave it out. but let devs know about the problem $this->_set_response_header('Notices-Field-Calculation-Errors[' . $e->get_string_code() . '][' . $model->get_this_model_name() . '][' . $field_to_calculate . ']', $e->getMessage(), true); } } return $calculated_fields_to_return; }
/** * Gets the query params that can be used when request one or many * @param EEM_Base $model * @param string $version * @return array */ protected function _get_response_selection_query_params(\EEM_Base $model, $version) { return apply_filters('FHEE__EED_Core_Rest_Api___get_response_selection_query_params', array('include' => array('required' => false, 'default' => '*'), 'calculate' => array('required' => false, 'default' => '', 'enum' => self::$_field_calculator->retrieve_calculated_fields_for_model($model))), $model, $version); }