<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Grid; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Collection; use ModStart\Grid\Filter\AbstractFilter; use ModStart\Grid\Filter\Eq; use ModStart\Grid\Filter\Field\AbstractFilterField; use ModStart\Grid\Filter\Has; use ModStart\Grid\Filter\Like; use ModStart\Grid\Filter\Likes; use ModStart\Grid\Filter\Range; use ReflectionClass; class GridFilter { protected $model; protected $filters = array(); protected $supports = array('eq', 'like', 'likes', 'range', 'has'); private $field; private $search; private $scopes; public function __construct(Model $w5oww = null) { goto zMvdt; zMvdt: $this->model = $w5oww; goto i8Jc7; i8Jc7: $this->fixedScopes = collect(); goto KniKJ; KniKJ: $this->scopes = collect(); goto W0cqx; W0cqx: } public function setSearch(array $Qlle3) { $this->search = $Qlle3; return $this; } public function scope() { goto tXanY; Gx063: $this->scopes->push($Sy8c5); goto iqs1J; tXanY: $Sy8c5 = new GridFilterScope($this); goto Gx063; iqs1J: return $Sy8c5; goto cYQf3; cYQf3: } public function addFilter(AbstractFilter $udDBo) { $udDBo->setTableFilter($this); return $this->filters[] = $udDBo; } public function clearFilter() { $this->filters = array(); } public function deleteFilterByColumn($JJepM) { $this->filters = array_filter($this->filters, function ($udDBo) use($JJepM) { return $udDBo->column() != $JJepM; }); } public function filters() { return $this->filters; } public function hasAutoHideFilters() { foreach ($this->filters as $udDBo) { if ($udDBo->autoHide()) { return true; } } return false; } public function getConditions() { goto t25As; t25As: $dVSAj = array(); goto pIlf9; fEuVH: return array_filter($dVSAj); goto BL54C; pIlf9: $Qlle3 = $this->search; goto vcHO3; vcHO3: if (!empty($Qlle3)) { foreach ($Qlle3 as $t0MRv) { if (!is_array($t0MRv)) { continue; } foreach ($t0MRv as $XCk1G => $gH7nL) { foreach ($this->filters() as $udDBo) { if ($XCk1G === $udDBo->column() && isset($gH7nL[$udDBo->name()])) { $w4d2h = $udDBo->condition($gH7nL); if (!empty($w4d2h)) { $wUpSt = array_keys($w4d2h); if (count($wUpSt) > 1 || count($wUpSt) == 1 && $wUpSt[0] === 0) { $dVSAj = array_merge($dVSAj, $w4d2h); } else { $dVSAj[] = $w4d2h; } } } } } } } goto fEuVH; BL54C: } public function executeQueryConditions($hAzJ1) { goto jZZYw; kbtxq: foreach ($dVSAj as $w4d2h) { $hAzJ1 = call_user_func_array(array($hAzJ1, key($w4d2h)), current($w4d2h)); } goto gimlM; jZZYw: $dVSAj = array_merge($this->getScopeConditions(), $this->getConditions()); goto kbtxq; gimlM: return $hAzJ1; goto NJ3_H; NJ3_H: } public function executeQuery() { goto MSOMq; MSOMq: $dVSAj = array_merge($this->getScopeConditions(), $this->getConditions()); goto MqKGh; DJhd4: return $this->model->addConditions($dVSAj)->getConditionQuery(); goto yf28i; MqKGh: $this->model->clearQuery(); goto DJhd4; yf28i: } public function execute() { goto EuetD; ina7q: $this->model->clearQuery(); goto H5lyh; H5lyh: return $this->model->addConditions($dVSAj)->buildData(); goto Sv5P7; EuetD: $dVSAj = array_merge($this->getScopeConditions(), $this->getConditions()); goto ina7q; Sv5P7: } private function getScopeConditions() { return array(); } public function getSearch() { return $this->search; } public function __call($HkVnj, $nvZ9A) { if (in_array($HkVnj, $this->supports)) { goto PuGHW; PLWdf: return $this->addFilter($udDBo); goto HOt2P; RMmVI: $Rfo2B = new ReflectionClass($vtWM8); goto g322E; g322E: $udDBo = $Rfo2B->newInstanceArgs($nvZ9A); goto F4ACe; F4ACe: if ($this->model) { $udDBo->grid($this->model->grid()); } goto PLWdf; PuGHW: $vtWM8 = '\\ModStart\\Grid\\Filter\\' . ucfirst($HkVnj); goto RMmVI; HOt2P: } } }