Element_Type::format_values_for_export( array $values, awsmug\Torro_Forms\DB_Objects\Elements\Element $element, string $export_format )

Formats values for an export.

Description

See also

Parameters

$values

(array) (Required) Associative array of $field => $value pairs, with the main element field having the key '_main'.

$element

(awsmug\Torro_Forms\DB_Objects\Elements\Element) (Required) Element the values belong to.

$export_format

(string) (Required) Export format identifier. May be 'xls', 'csv', 'json', 'xml' or 'html'.

Return

(array) Associative array of <code>$column_slug => $column_value</code> pairs. The number of items and the column slugs must match those returned from the get_export_columns() method.

Source

File: src/db-objects/elements/element-types/element-type.php

	public function format_values_for_export( $values, $element, $export_format ) {
		if ( is_a( $this, Choice_Element_Type_Interface::class ) && ! $this->use_single_export_column_for_choices( $element ) ) {
			$value  = isset( $values['_main'] ) ? (array) $values['_main'] : array();
			$yes_no = $this->get_export_column_choices_yes_no( $element );

			$columns = array();

			foreach ( $element->get_element_choices() as $element_choice ) {
				$choice_slug = sanitize_title( $element_choice->value );

				$columns[ 'element_' . $element->id . '__main_' . $choice_slug ] = in_array( $element_choice->value, $value ) ? $yes_no[0] : $yes_no[1];
			}

			return $columns;
		}

		$value = isset( $values['_main'] ) ? $values['_main'] : '';

		if ( is_array( $value ) ) {
			$value = implode( ', ', $value );
		}

		return array(
			'element_' . $element->id . '__main' => $this->escape_single_value_for_export( $value, $export_format ),
		);
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.