1<?php 2 3namespace plugin\struct\meta; 4 5/** 6 * Class SearchConfig 7 * 8 * The same as @see Search but can be initialized by a configuration array 9 * 10 * @package plugin\struct\meta 11 */ 12class SearchConfig extends Search { 13 14 protected $config; 15 16 /** 17 * SearchConfig constructor. 18 * @param $config 19 */ 20 public function __construct($config) { 21 global $INPUT; 22 /** @var \helper_plugin_struct_config $confHlp */ 23 $confHlp = plugin_load('helper','struct_config'); 24 $this->config = $config; 25 $this->config['current_params'] = array(); 26 27 parent::__construct(); 28 29 foreach($config['schemas'] as $schema) { 30 $this->addSchema($schema[0], $schema[1]); 31 } 32 33 foreach($config['cols'] as $col) { 34 $this->addColumn($col); 35 } 36 37 if ($INPUT->has('datasrt')) { 38 list($colname, $sort) = $confHlp->parseSort($INPUT->str('datasrt')); 39 $this->addSort($colname, $sort === 'ASC'); 40 $this->config['sort'] = array($colname, $sort); 41 $this->config['current_params']['datasrt'] = $INPUT->str('datasrt'); 42 } elseif ($config['sort'][0] != '') { 43 $this->addSort($config['sort'][0], $config['sort'][1] === 'ASC'); 44 } 45 46 foreach($config['filter'] as $filter) { 47 $this->addFilter($filter[0], $filter[2], $filter[1], $filter[3]); 48 } 49 if ($INPUT->has('dataflt')) { 50 foreach ($INPUT->arr('dataflt') as $colcomp => $filter) { 51 list($colname, $comp, $value, $logic) = $confHlp->parseFilterLine('AND', $colcomp . $filter); 52 $this->addFilter($colname, $value, $comp, $logic); 53 $this->config['filter'][] = array($colname, $comp, $value, $logic); 54 $this->config['current_params']['dataflt'] = $INPUT->arr('dataflt'); 55 } 56 } 57 58 if (!empty($config['limit'])) { 59 $this->setLimit($config['limit']); 60 } 61 if ($INPUT->has('dataofs')) { 62 $this->setOffset($INPUT->int('dataofs')); 63 $this->config['current_params']['dataofs'] = $INPUT->int('dataofs'); 64 } 65 66 // FIXME add additional stuff 67 68 } 69 70 public function getConf() { 71 return $this->config; 72 } 73 74} 75