Skip to content

Commit

Permalink
set default operators for strings and date & datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
cnizzardini committed May 7, 2019
1 parent ee1def6 commit 298824a
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/Service/YummySearch/ViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ private function getYummyMetaColumns(array $model, string $camelName, Request $r
{
$selectOptions = [];


foreach ($model['columns'] as $column => $field) {

$humanName = $model['humanName'];

$meta = $this->getYummyMeta($camelName, $field['column']);
$meta = $this->getYummyMeta($camelName, $field);

$element = [
'text' => ($meta['niceName'] !== false) ? $meta['niceName'] : $field['text'],
Expand All @@ -83,10 +84,10 @@ private function getYummyMetaColumns(array $model, string $camelName, Request $r
* Returns yummy meta data for a column
*
* @param string $model
* @param string $column
* @param array $field
* @return array
*/
private function getYummyMeta(string $model, string $column) : array
private function getYummyMeta(string $model, array $field) : array
{
$meta = [
'options' => false,
Expand All @@ -95,6 +96,7 @@ private function getYummyMeta(string $model, string $column) : array
];

$config = $this->config;
$column = $field['column'];

if (!isset($config['allow']["$model.$column"])) {
return $meta;
Expand All @@ -107,13 +109,32 @@ private function getYummyMeta(string $model, string $column) : array
return [
'niceName' => isset($options['name']) ? $options['name'] : $defaultName,
'options' => isset($options['select']) ? $options['select'] : [],
'operators' => isset($options['operators']) ? $options['operators'] : [],
'operators' => $this->getOperators($field, $options),
'default' => false,
'sortOrder' => array_search("$model.$column", $keys),
'group' => isset($options['group']) ? $options['group'] : false
];
}

private function getOperators(array $field, array $options) : array
{
if (isset($options['operators'])) {
return $options['operators'];
}

switch (strtolower($field['type'])) {
case 'string':
return ['like','not_like','eq','not_eq'];
break;
case 'date':
case 'datetime':
return ['eq','not_eq','qt','lt','qt_eq','lt_eq'];
break;
default:
return [];
}
}

/**
* Gets array of html select compatible options as either options, optgroups, or custom optgroups depending
* on configuration
Expand Down

0 comments on commit 298824a

Please sign in to comment.