lithium\data\model\Query::export()

public method

Convert the query's properties to the data sources' syntax and return it as an array.

Parameters

  • \lithium\data\Source $source

    Instance of the data source to use for conversion.

  • array $options

    Options to use when exporting the data.

Returns

array

Returns an array containing a data source-specific representation of a query.

Source

	public function export(Source $source, array $options = []) {
		$defaults = ['keys' => []];
		$options += $defaults;

		if ($options['keys']) {
			$keys = array_flip($options['keys']);
		} else {
			$keys =& $this->_config;
		}
		list($copy, $apply) = Set::slice($keys, $source->methods());

		if (isset($keys['with'])) {
			$this->applyStrategy($source);
		}

		foreach ($apply as $item => $value) {
			$results[$item] = $source->{$item}($this->{$item}(), $this);
		}
		foreach ($copy as $item => $value) {
			$results[$item] = $this->_config[$item];
		}

		if (array_key_exists('data', $keys)) {
			$results['data'] = $this->_exportData();
		}
		if (array_key_exists('source', $keys)) {
			$results['source'] = $source->name($results['source']);
		}

		if (!isset($results['fields'])) {
			return $results;
		}
		$created = ['fields', 'values'];

		if (is_array($results['fields']) && array_keys($results['fields']) == $created) {
			$results = $results['fields'] + $results;
		}
		return $results;
	}