methods() public method

Returns the list of methods which format values imported from Query objects. Should be overridden in subclasses.
See also: lithium\data\model\Query
public methods ( ) : array
return array
Example #1
0
 /**
  * Convert the query's properties to the data sources' syntax and return it as an array.
  *
  * @param object $source Instance of the data source (`lithium\data\Source`) to use for
  *        conversion.
  * @param array $options Options to use when exporting the data.
  * @return array Returns an array containing a data source-specific representation of a query.
  */
 public function export(Source $source, array $options = array())
 {
     $defaults = array('keys' => array());
     $options += $defaults;
     if ($options['keys']) {
         $keys = array_flip($options['keys']);
     } else {
         $keys =& $this->_config;
     }
     $results = array('type' => $this->_type);
     $apply = array_intersect_key($keys, array_flip($source->methods()));
     $copy = array_diff_key($keys, $apply);
     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 = array('fields', 'values');
     if (is_array($results['fields']) && array_keys($results['fields']) == $created) {
         $results = $results['fields'] + $results;
     }
     return $results;
 }
Example #2
0
 /**
  * Convert the query's properties to the data sources' syntax and return it as an array.
  *
  * @param object $dataSource Instance of `lithium\data\Source` to use for conversion.
  * @param array $options Options to use when exporting the data.
  * @return array Returns an array containing a data source-specific representation of a query.
  */
 public function export(Source $dataSource, array $options = array())
 {
     $defaults = array('keys' => array());
     $options += $defaults;
     $keys = $options['keys'] ?: array_keys($this->_config);
     $methods = $dataSource->methods();
     $results = array('type' => $this->_type);
     $apply = array_intersect($keys, $methods);
     $copy = array_diff($keys, $apply);
     foreach ($apply as $item) {
         $results[$item] = $dataSource->{$item}($this->{$item}(), $this);
     }
     foreach ($copy as $item) {
         if (in_array($item, $keys)) {
             $results[$item] = $this->_config[$item];
         }
     }
     if (in_array('data', $keys)) {
         $results['data'] = $this->_exportData();
     }
     if (isset($results['source'])) {
         $results['source'] = $dataSource->name($results['source']);
     }
     if (!isset($results['fields'])) {
         return $results;
     }
     $created = array('fields', 'values');
     if (is_array($results['fields']) && array_keys($results['fields']) == $created) {
         $results = $results['fields'] + $results;
     }
     return $results;
 }
Example #3
0
 /**
  * Determines the set of methods to be used when exporting query values.
  *
  * @return array
  */
 public function methods()
 {
     $result = parent::methods();
     unset($result[array_search('schema', $result)]);
     return $result;
 }
Example #4
0
 /**
  * Convert the query's properties to the data sources' syntax and return it as an array.
  *
  * @param object $dataSource Instance of the data source to use for conversion.
  * @param array $options Options to use when exporting the data.
  * @return array Returns an array containing a data source-specific representation of a query.
  */
 public function export(Source $dataSource, array $options = array())
 {
     $defaults = array('data' => array());
     $options += $defaults;
     $keys = array_keys($this->_config);
     $methods = $dataSource->methods();
     $results = array();
     $apply = array_intersect($keys, $methods);
     $copy = array_diff($keys, $apply);
     foreach ($apply as $item) {
         $results[$item] = $dataSource->{$item}($this->{$item}(), $this);
     }
     foreach ($copy as $item) {
         $results[$item] = $this->_config[$item];
     }
     $entity =& $this->_entity;
     $data = $entity ? $entity->export($dataSource, $options['data']) : $this->_data;
     $data = ($list = $this->_config['whitelist']) ? array_intersect_key($data, $list) : $data;
     $results += compact('data');
     $results['source'] = $dataSource->name($this->_config['source']);
     $created = array('fields', 'values');
     if (is_array($results['fields']) && array_keys($results['fields']) == $created) {
         $results = $results['fields'] + $results;
     }
     return $results;
 }