<?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 $nzuw7 = null) { goto vwaxF; Gwkx6: $this->fixedScopes = collect(); goto B60g8; vwaxF: $this->model = $nzuw7; goto Gwkx6; B60g8: $this->scopes = collect(); goto ppwKL; ppwKL: } public function setSearch(array $HklG2) { $this->search = $HklG2; return $this; } public function scope() { goto bKQtK; bKQtK: $Tvguf = new GridFilterScope($this); goto p_MsA; p_MsA: $this->scopes->push($Tvguf); goto MCfwa; MCfwa: return $Tvguf; goto VyLCX; VyLCX: } public function addFilter(AbstractFilter $pvsQp) { $pvsQp->setTableFilter($this); return $this->filters[] = $pvsQp; } public function clearFilter() { $this->filters = array(); } public function deleteFilterByColumn($xiZoD) { $this->filters = array_filter($this->filters, function ($pvsQp) use($xiZoD) { return $pvsQp->column() != $xiZoD; }); } public function filters() { return $this->filters; } public function hasAutoHideFilters() { foreach ($this->filters as $pvsQp) { if ($pvsQp->autoHide()) { return true; } } return false; } public function getConditions() { goto X5ukj; HfHuA: return array_filter($yglGn); goto zoX4l; nPDVQ: $HklG2 = $this->search; goto SVtLB; X5ukj: $yglGn = array(); goto nPDVQ; SVtLB: if (!empty($HklG2)) { foreach ($HklG2 as $N03Ob) { if (!is_array($N03Ob)) { continue; } foreach ($N03Ob as $Ahdq2 => $vqmjo) { foreach ($this->filters() as $pvsQp) { if ($Ahdq2 === $pvsQp->column() && isset($vqmjo[$pvsQp->name()])) { $IpwOR = $pvsQp->condition($vqmjo); if (!empty($IpwOR)) { $m7u0j = array_keys($IpwOR); if (count($m7u0j) > 1 || count($m7u0j) == 1 && $m7u0j[0] === 0) { $yglGn = array_merge($yglGn, $IpwOR); } else { $yglGn[] = $IpwOR; } } } } } } } goto HfHuA; zoX4l: } public function executeQueryConditions($xaAIg) { goto N3a0N; N3a0N: $yglGn = array_merge($this->getScopeConditions(), $this->getConditions()); goto AljwJ; AljwJ: foreach ($yglGn as $IpwOR) { $xaAIg = call_user_func_array(array($xaAIg, key($IpwOR)), current($IpwOR)); } goto Tl3Aa; Tl3Aa: return $xaAIg; goto vFvDY; vFvDY: } public function executeQuery() { goto lR8h1; Km2B3: $this->model->clearQuery(); goto vjUGA; lR8h1: $yglGn = array_merge($this->getScopeConditions(), $this->getConditions()); goto Km2B3; vjUGA: return $this->model->addConditions($yglGn)->getConditionQuery(); goto vjkIG; vjkIG: } public function execute() { goto AA2KN; eln9A: return $this->model->addConditions($yglGn)->buildData(); goto g3hKd; AA2KN: $yglGn = array_merge($this->getScopeConditions(), $this->getConditions()); goto bca_v; bca_v: $this->model->clearQuery(); goto eln9A; g3hKd: } private function getScopeConditions() { return array(); } public function getSearch() { return $this->search; } public function __call($eNE35, $lUGZC) { if (in_array($eNE35, $this->supports)) { goto cc5zz; UWlF1: if ($this->model) { $pvsQp->grid($this->model->grid()); } goto pEyTg; cc5zz: $rXcrQ = '\\ModStart\\Grid\\Filter\\' . ucfirst($eNE35); goto XcY6I; pEyTg: return $this->addFilter($pvsQp); goto F1SBp; XcY6I: $EC1v_ = new ReflectionClass($rXcrQ); goto dfpTR; dfpTR: $pvsQp = $EC1v_->newInstanceArgs($lUGZC); goto UWlF1; F1SBp: } } }