Gets all element values set for a submission.
Description
This method queries all submission values that belong to the submission and parses them into an element values data array. It is an multi-dimensional associative array where the keys are element IDs and their inner keys field slugs belonging to the element with the actual value for the element and field combination as value.
The querying and parsing logic will only be executed once per submission and request, for performance reasons. On subsequent calls, the non-persistently cached value will be returned.
See also
Parameters
- $submission
-
(awsmug\Torro_Forms\DB_Objects\Submissions\Submission) (Required) Submission object to get element values for.
- $force
-
(bool) (Optional) Whether to force querying and parsing.
Default value: false
Return
(array) Element values data set for the submission.
Source
File: src/db-objects/submissions/submission-manager.php
public function get_element_values_data_for_submission( $submission, $force = false ) { if ( ! isset( $this->element_values[ $submission->id ] ) || $force ) { $this->element_values[ $submission->id ] = array(); foreach ( $submission->get_submission_values() as $submission_value ) { $element_id = $submission_value->element_id; $field = ! empty( $submission_value->field ) ? $submission_value->field : '_main'; if ( ! isset( $this->element_values[ $submission->id ][ $element_id ] ) ) { $this->element_values[ $submission->id ][ $element_id ] = array(); } if ( ! empty( $this->element_values[ $submission->id ][ $element_id ][ $field ] ) ) { $this->element_values[ $submission->id ][ $element_id ][ $field ] = (array) $this->element_values[ $submission->id ][ $element_id ][ $field ]; $this->element_values[ $submission->id ][ $element_id ][ $field ][] = $submission_value->value; } else { $this->element_values[ $submission->id ][ $element_id ][ $field ] = $submission_value->value; } } } return $this->element_values[ $submission->id ]; }
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |