xref: /plugin/struct/meta/SearchConfig.php (revision 1a07b69644a74cb7c512c56dff6a8a500d61eef7)
15511bd5bSAndreas Gohr<?php
25511bd5bSAndreas Gohr
35511bd5bSAndreas Gohrnamespace plugin\struct\meta;
45511bd5bSAndreas Gohr
55511bd5bSAndreas Gohr/**
65511bd5bSAndreas Gohr * Class SearchConfig
75511bd5bSAndreas Gohr *
85511bd5bSAndreas Gohr * The same as @see Search but can be initialized by a configuration array
95511bd5bSAndreas Gohr *
105511bd5bSAndreas Gohr * @package plugin\struct\meta
115511bd5bSAndreas Gohr */
125511bd5bSAndreas Gohrclass SearchConfig extends Search {
135511bd5bSAndreas Gohr
14*1a07b696SMichael Große    protected $config;
15*1a07b696SMichael Große
165511bd5bSAndreas Gohr    /**
175511bd5bSAndreas Gohr     * SearchConfig constructor.
185511bd5bSAndreas Gohr     * @param $config
195511bd5bSAndreas Gohr     */
205511bd5bSAndreas Gohr    public function __construct($config) {
21*1a07b696SMichael Große        global $INPUT;
22*1a07b696SMichael Große        /** @var \helper_plugin_struct_config $confHlp */
23*1a07b696SMichael Große        $confHlp = plugin_load('helper','struct_config');
24*1a07b696SMichael Große        $this->config = $config;
25*1a07b696SMichael Große        $this->config['current_params'] = array();
26*1a07b696SMichael Große
275511bd5bSAndreas Gohr        parent::__construct();
285511bd5bSAndreas Gohr
295511bd5bSAndreas Gohr        foreach($config['schemas'] as $schema) {
305511bd5bSAndreas Gohr            $this->addSchema($schema[0], $schema[1]);
315511bd5bSAndreas Gohr        }
325511bd5bSAndreas Gohr
335511bd5bSAndreas Gohr        foreach($config['cols'] as $col) {
345511bd5bSAndreas Gohr            $this->addColumn($col);
355511bd5bSAndreas Gohr        }
365511bd5bSAndreas Gohr
37*1a07b696SMichael Große        if ($INPUT->has('datasrt')) {
38*1a07b696SMichael Große            list($colname, $sort) = $confHlp->parseSort($INPUT->str('datasrt'));
39*1a07b696SMichael Große            $this->addSort($colname, $sort === 'ASC');
40*1a07b696SMichael Große            $this->config['sort'] = array($colname, $sort);
41*1a07b696SMichael Große            $this->config['current_params']['datasrt'] = $INPUT->str('datasrt');
42*1a07b696SMichael Große        } elseif ($config['sort'][0] != '') {
4361809d19SMichael Große            $this->addSort($config['sort'][0], $config['sort'][1] === 'ASC');
4461809d19SMichael Große        }
4561809d19SMichael Große
465511bd5bSAndreas Gohr        foreach($config['filter'] as $filter) {
475511bd5bSAndreas Gohr            $this->addFilter($filter[0], $filter[2], $filter[1], $filter[3]);
485511bd5bSAndreas Gohr        }
49*1a07b696SMichael Große        if ($INPUT->has('dataflt')) {
50*1a07b696SMichael Große            foreach ($INPUT->arr('dataflt') as $colcomp => $filter) {
51*1a07b696SMichael Große                list($colname, $comp, $value, $logic) = $confHlp->parseFilterLine('AND', $colcomp . $filter);
52*1a07b696SMichael Große                $this->addFilter($colname, $value, $comp, $logic);
53*1a07b696SMichael Große                $this->config['filter'][] = array($colname, $comp, $value, $logic);
54*1a07b696SMichael Große                $this->config['current_params']['dataflt'] = $INPUT->arr('dataflt');
55*1a07b696SMichael Große            }
56*1a07b696SMichael Große        }
57*1a07b696SMichael Große
58*1a07b696SMichael Große        if (!empty($config['limit'])) {
59*1a07b696SMichael Große            $this->setLimit($config['limit']);
60*1a07b696SMichael Große        }
61*1a07b696SMichael Große        if ($INPUT->has('dataofs')) {
62*1a07b696SMichael Große            $this->setOffset($INPUT->int('dataofs'));
63*1a07b696SMichael Große            $this->config['current_params']['dataofs'] = $INPUT->int('dataofs');
64*1a07b696SMichael Große        }
655511bd5bSAndreas Gohr
665511bd5bSAndreas Gohr        // FIXME add additional stuff
675511bd5bSAndreas Gohr
685511bd5bSAndreas Gohr    }
695511bd5bSAndreas Gohr
70*1a07b696SMichael Große    public function getConf() {
71*1a07b696SMichael Große        return $this->config;
72*1a07b696SMichael Große    }
73*1a07b696SMichael Große
745511bd5bSAndreas Gohr}
75