_normalize

Normalizes the filters-array. This can be helpfull to use automated settings.

@param array $filters List of filters.
@param array $options Options
@return array
433631
protected function _normalize($filters, $options = [])
    {
        foreach ($filters as $key => $filter) {
            if ($filter['options']) {
                $filter['operator'] = '=';
                $filter['attributes']['empty'] = true;
            }
            if (is_null($filter['attributes']['placeholder'])) {
                $filter['attributes']['placeholder'] = $filter['column'];
            }

            $filters[$key] = $filter;
        }

        return $filters;
    }
345056
public function setFilters(array $filters)
    {
        if (empty($filters)) {
            return $this->clearFilters();
        }

        session()->put($this->getSessionKey(static::TYPE_FILTERS), $filters);

        return $this;
    }
283203
private static function validateFilters($filters, $settings)
    {
        if (!is_array($filters)) {
            $filters = [$filters];
        }

        // Each fitler.
        foreach ($filters as $index => &$filter) {

            // Check this item.
            $filter = self::validateFilterItem($filter, $settings);

            // Remove if invalid.
            if (empty($filter)) {
                unset($filters[$index]);
            }
        }

        return $filters;
    }
1174454
public function setFilters($filters)
    {
        if (!$this->hasFilterer()) {
            $this->setFilterer(configurator()->build('form.filterer.class'));
        }

        $this->getFilterer()->setFilters($filters);
        return $this;
    }
454061
private function format_filter($filters = array()) {
    $filters_merged = array();
    foreach ($filters as $ky => $vl) {
      $filters_merged[] = $ky . ':' . $vl;
    }

    return implode(',', $filters_merged);
  }
558309
public function set($filters)
    {
        if (! is_array($filters)) {
            $filters = func_get_args();
        }

        $this->clear();

        foreach ($filters as $filter) {
            $this->push($filter);
        }

        return $this->getDisplay();
    }
741805
public function deleteDocument($filters, array $options = [])
    {
        $data = [];

        if (is_string($filters)) {
            $data['_id'] = $filters;
            $action = 'delete';
        } else {
            $data['body'] = ['query' => (object)$filters];
            $action = 'deleteByQuery';
        }

        $response = $this->kuzzle->query(
            $this->buildQueryArgs('document', $action),
            $this->kuzzle->addHeaders($data, $this->headers),
            $options
        );

        return $action === 'delete' ? $response['result']['_id'] : $response['result']['ids'];
    }
435144
public function set_filter_values($filter, array $values = []) {
        $allvalues = (array) $this->get_config('filtervalues', []);
        $allvalues[$filter] = $values;

        return $this->set_config('filtervalues', $allvalues);
    }
360543
public function setFilters($filters = [])
    {
        foreach ($filters as $key => $value) {
            $this->addFilter($key, $value);
        }

        return $this;
    }
329698
protected function normalizeOptions(array $options)
    {
        return array_merge(parent::normalizeOptions($options), [
            'inverse'   => $this->inverse,
            'fixed'     => $this->fixed,
            'static'    => $this->static,
            'brand'     => $this->brand,
            'useForm'   => $this->useForm,
            'rightMenu' => $this->rightMenu,
            ], $options);
    }
715799
public function setFilters($filters)
    {
        if ($filters === null)
            $filters = [];
        else if (!is_array($filters))
            throw new \Exception('Filters should be null or array');

        foreach ($filters as $column => $filter) {
            $found = [];
            foreach ($this->getColumns() as $id => $params) {
                if ($id == $column) {
                    foreach ($filter as $name => $value) {
                        if (in_array($name, $params['filters']))
                            $found[$name] = $value;
                    }
                    break;
                }
            }

            if (count($found) > 0)
                $filters[$column] = $found;
            else
                unset($filters[$column]);
        }

        $this->filters = $filters;
        return $this;
    }
1295675
private function normalizeOptions(array $options)
    {
        $options += [
            'method' => 'GET',
            'cname' => self::DEFAULT_DOWNLOAD_HOST,
            'contentMd5' => null,
            'contentType' => null,
            'headers' => [],
            'saveAsName' => null,
            'responseDisposition' => null,
            'responseType' => null,
            'keyFile' => null,
            'keyFilePath' => null,
            'allowPost' => false,
            'forceOpenssl' => false,
            'queryParams' => [],
            'timestamp' => null
        ];

        $allowedMethods = ['GET', 'PUT', 'POST', 'DELETE'];
        $options['method'] = strtoupper($options['method']);
        if (!in_array($options['method'], $allowedMethods)) {
            throw new \InvalidArgumentException('$options.method must be one of `GET`, `PUT` or `DELETE`.');
        }

        if ($options['method'] === 'POST' && !$options['allowPost']) {
            throw new \InvalidArgumentException(
                'Invalid method. To create an upload URI, use StorageObject::signedUploadUrl().'
            );
        }
        unset($options['allowPost']);

        // For backwards compatibility, strip protocol from cname.
        $cnameParts = explode('//', $options['cname']);
        if (count($cnameParts) > 1) {
            $options['cname'] = $cnameParts[1];
        }

        $options['cname'] = trim($options['cname'], '/');

        // If a timestamp is provided, use it in place of `now` for v4 URLs only..
        // This option exists for testing purposes, and should not generally be provided by users.
        if ($options['timestamp']) {
            if (!($options['timestamp'] instanceof \DateTimeInterface)) {
                if (!is_string($options['timestamp'])) {
                    throw new \InvalidArgumentException(
                        'User-provided timestamps must be a string or instance of `\DateTimeInterface`.'
                    );
                }

                $options['timestamp'] = \DateTimeImmutable::createFromFormat(
                    self::V4_TIMESTAMP_FORMAT,
                    $options['timestamp'],
                    new \DateTimeZone('UTC')
                );

                if (!$options['timestamp']) {
                    throw new \InvalidArgumentException(
                        'Given timestamp string is in an invalid format. Provide timestamp formatted as follows: `' .
                        self::V4_TIMESTAMP_FORMAT .
                        '`. Note that timestamps MUST be in UTC.'
                    );
                }
            }
        } else {
            $options['timestamp'] = new \DateTimeImmutable('now', new \DateTimeZone('UTC'));
        }

        return $options;
    }
178573
public function setFilters($filters)
    {
        $this->filters = Collection::make($filters);
        foreach ($this->filters as $filterConfig) {
            $filterConfig->attach($this);
        }

        return $this;
    }
890138
public function setFilters(array $filters)
    {
        $this->filters = $filters;

        $this->updateInternalState();

        $this->handleChangedParameters();

        return $this;
    }
823455
public function filter(array $filters)
	{
		/**
		 * First, save all filter values to array
		 */
		foreach ($filters as $filter) {
			if ($filter->isValueSet() && !$filter->hasConditionCallback()) {
				$this->filter[$filter->getKey()] = $filter->getCondition();
			}
		}

		/**
		 * Download filtered data
		 */
		$this->data = $this->getData();

		/**
		 * Apply possible user filter callbacks
		 */
		foreach ($filters as $filter) {
			if ($filter->isValueSet() && $filter->hasConditionCallback()) {
				$this->data = (array) call_user_func_array(
					$filter->getConditionCallback(),
					[$this->data, $filter->getValue()]
				);
			}
		}

		return $this;
	}
1077917
protected function mergeOptions(array $options)
    {
        $defaults = $options + $this->defaultOptions;
        $defaults['params'] = [];
        if (!$defaults['filter_action'] || $this->application->input->{$defaults['method']}($defaults['action']) === $defaults['filter_action']) {
            //Action filter
            //cleaning post/get data
            foreach ($defaults['filters'] as $params => $column) {
                switch ($defaults['method']) {
                    case 'get':
                        if (isset($_GET[$params])) {
                            if (is_array($_GET[$params])) {
                                $_GET[$params] = array_filter(
                                    $_GET[$params],
                                    function ($value) {
                                        return (trim($value) !== '');
                                    }
                                );
                                if (empty($_GET[$params])) {
                                    unset($_GET[$params]);
                                }
                            } elseif (trim($_GET[$params]) === '') {
                                unset($_GET[$params]);
                            }
                        }
                        break;
                    case 'post':
                        if (isset($_POST[$params]) && trim($_POST[$params]) === '') {
                            if (is_array($_POST[$params])) {
                                $_POST[$params] = array_filter(
                                    $_POST[$params],
                                    function ($value) {
                                        return (trim($value) !== '');
                                    }
                                );
                                if (empty($_POST[$params])) {
                                    unset($_POST[$params]);
                                }
                            } elseif (trim($_POST[$params]) === '') {
                                unset($_POST[$params]);
                            }
                            unset($_POST[$params]);
                        }
                        break;
                }
            }
            $defaults['params'] = array_intersect_key($this->application->input->{$defaults['method']}(), $defaults['filters']);
        } elseif ($this->application->input->{$defaults['method']}($defaults['action']) === $defaults['reset_action']) {
            foreach ($defaults['filters'] as $params => $callback) {
                switch ($defaults['method']) {
                    case 'get':
                        unset($_GET[$params]);
                        break;
                    case 'post':
                        unset($_POST[$params]);
                        break;
                }
            }
            //Reset action
            $defaults['params'] = $defaults['default_filters'];
        } elseif ($defaults['save']) {
            $defaults['params'] = $this->application->session->userdata($options['save']);
        }

        // Si aucun filtre n'a été soumis (session non initialisé, filtre par défaut
        $session_exist = false;
        if ($defaults['save']) {
            $session_exist =  $this->application->session->has_userdata($options['save']);
        }
        if (empty($defaults['params']) && !$session_exist) {
             $defaults['params'] = $defaults['default_filters'];
        }
        return $defaults;
    }
799260
public static function parseFilters(array $filters)
    {
        $parsed = [];
        foreach ($filters as $property => $value) {
            // don't keep empty filters
            if ('' !== $value) {
                if (null !== $value) {
                    // parse filter value
                    if (is_numeric($value)) {
                        // convert numbers
                        $value = floatval($value);
                    } else {
                        // convert booleans
                        $booleanValue = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
                        if (null !== $booleanValue) {
                            $value = $booleanValue;
                        }
                    }
                }

                $parsed[$property] = $value;
            }
        }

        return $parsed;
    }