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 141a07b696SMichael Große protected $config; 151a07b696SMichael Große 1600f6af48SAndreas Gohr protected $dynamicParameters; 1700f6af48SAndreas Gohr 185511bd5bSAndreas Gohr /** 195511bd5bSAndreas Gohr * SearchConfig constructor. 2000f6af48SAndreas Gohr * @param array $config The parsed configuration for this search 215511bd5bSAndreas Gohr */ 225511bd5bSAndreas Gohr public function __construct($config) { 231a07b696SMichael Große $this->config = $config; 241a07b696SMichael Große 255511bd5bSAndreas Gohr parent::__construct(); 265511bd5bSAndreas Gohr 2700f6af48SAndreas Gohr // apply dynamic paramters 2800f6af48SAndreas Gohr $this->dynamicParameters = new SearchConfigParameters($this); 2900f6af48SAndreas Gohr $this->config = $this->dynamicParameters->updateConfig($config); 3000f6af48SAndreas Gohr 3100f6af48SAndreas Gohr // configure search from configuration 325511bd5bSAndreas Gohr foreach($config['schemas'] as $schema) { 335511bd5bSAndreas Gohr $this->addSchema($schema[0], $schema[1]); 345511bd5bSAndreas Gohr } 355511bd5bSAndreas Gohr 365511bd5bSAndreas Gohr foreach($config['cols'] as $col) { 375511bd5bSAndreas Gohr $this->addColumn($col); 385511bd5bSAndreas Gohr } 395511bd5bSAndreas Gohr 4000f6af48SAndreas Gohr if(!empty($config['filter'])) foreach($config['filter'] as $filter) { 415511bd5bSAndreas Gohr $this->addFilter($filter[0], $filter[2], $filter[1], $filter[3]); 425511bd5bSAndreas Gohr } 4300f6af48SAndreas Gohr 4400f6af48SAndreas Gohr if(!empty($config['sort'])) foreach($config['sort'] as $sort) { 4500f6af48SAndreas Gohr $this->addSort($sort[0], $sort[1] === 'ASC'); 461a07b696SMichael Große } 471a07b696SMichael Große 481a07b696SMichael Große if(!empty($config['limit'])) { 491a07b696SMichael Große $this->setLimit($config['limit']); 501a07b696SMichael Große } 5100f6af48SAndreas Gohr 5200f6af48SAndreas Gohr if(!empty($config['offset'])) { 5300f6af48SAndreas Gohr $this->setLimit($config['offset']); 5400f6af48SAndreas Gohr } 551a07b696SMichael Große } 565511bd5bSAndreas Gohr 5700f6af48SAndreas Gohr /** 5800f6af48SAndreas Gohr * Access the dynamic paramters of this search 5900f6af48SAndreas Gohr * 6000f6af48SAndreas Gohr * Note: This call retruns a clone of the parameters as they were initialized 6100f6af48SAndreas Gohr * 6200f6af48SAndreas Gohr * @return SearchConfigParameters 6300f6af48SAndreas Gohr */ 6400f6af48SAndreas Gohr public function getDynamicParameters() { 6500f6af48SAndreas Gohr return clone $this->dynamicParameters; 665511bd5bSAndreas Gohr } 675511bd5bSAndreas Gohr 6800f6af48SAndreas Gohr /** 69*07993756SAndreas Gohr * @return array the current config 7000f6af48SAndreas Gohr */ 71*07993756SAndreas Gohr public function getConf() { 721a07b696SMichael Große return $this->config; 731a07b696SMichael Große } 741a07b696SMichael Große 755511bd5bSAndreas Gohr} 76