<?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 $uV19D = null) { goto Q8fVo; gkRag: $this->scopes = collect(); goto O7zEp; NIYKE: $this->fixedScopes = collect(); goto gkRag; Q8fVo: $this->model = $uV19D; goto NIYKE; O7zEp: } public function setSearch(array $wu9QR) { $this->search = $wu9QR; return $this; } public function scope() { goto oEROl; oEROl: $Um96w = new GridFilterScope($this); goto r402p; r402p: $this->scopes->push($Um96w); goto a9Z5O; a9Z5O: return $Um96w; goto rXTX2; rXTX2: } public function addFilter(AbstractFilter $CJNWc) { $CJNWc->setTableFilter($this); return $this->filters[] = $CJNWc; } public function clearFilter() { $this->filters = array(); } public function deleteFilterByColumn($XrXh2) { $this->filters = array_filter($this->filters, function ($CJNWc) use($XrXh2) { return $CJNWc->column() != $XrXh2; }); } public function filters() { return $this->filters; } public function hasAutoHideFilters() { foreach ($this->filters as $CJNWc) { if ($CJNWc->autoHide()) { return true; } } return false; } public function getConditions() { goto YD_Ca; YD_Ca: $Z8Rhz = array(); goto zQmq_; Lz4b8: if (!empty($wu9QR)) { foreach ($wu9QR as $YiCbD) { if (!is_array($YiCbD)) { continue; } foreach ($YiCbD as $g84Fl => $CD1z5) { foreach ($this->filters() as $CJNWc) { if ($g84Fl === $CJNWc->column() && isset($CD1z5[$CJNWc->name()])) { $MgRLW = $CJNWc->condition($CD1z5); if (!empty($MgRLW)) { $DLlCL = array_keys($MgRLW); if (count($DLlCL) > 1 || count($DLlCL) == 1 && $DLlCL[0] === 0) { $Z8Rhz = array_merge($Z8Rhz, $MgRLW); } else { $Z8Rhz[] = $MgRLW; } } } } } } } goto lfbWI; zQmq_: $wu9QR = $this->search; goto Lz4b8; lfbWI: return array_filter($Z8Rhz); goto afkhB; afkhB: } public function executeQueryConditions($lpymm) { goto weTlM; qtQUv: return $lpymm; goto pO0B3; weTlM: $Z8Rhz = array_merge($this->getScopeConditions(), $this->getConditions()); goto Y5uNT; Y5uNT: foreach ($Z8Rhz as $MgRLW) { $lpymm = call_user_func_array(array($lpymm, key($MgRLW)), current($MgRLW)); } goto qtQUv; pO0B3: } public function executeQuery() { goto WI9a9; wGc8P: $this->model->clearQuery(); goto xvcQT; xvcQT: return $this->model->addConditions($Z8Rhz)->getConditionQuery(); goto bBnw1; WI9a9: $Z8Rhz = array_merge($this->getScopeConditions(), $this->getConditions()); goto wGc8P; bBnw1: } public function execute() { goto kUXv7; eKR7Y: $this->model->clearQuery(); goto ju5HS; ju5HS: return $this->model->addConditions($Z8Rhz)->buildData(); goto Bkq05; kUXv7: $Z8Rhz = array_merge($this->getScopeConditions(), $this->getConditions()); goto eKR7Y; Bkq05: } private function getScopeConditions() { return array(); } public function getSearch() { return $this->search; } public function __call($HxDDI, $CUZy6) { if (in_array($HxDDI, $this->supports)) { goto dRBiC; ZPIab: return $this->addFilter($CJNWc); goto AhS8k; Iv0PA: $DYRgm = new ReflectionClass($Bkn_0); goto ZxMbk; EAsoG: if ($this->model) { $CJNWc->grid($this->model->grid()); } goto ZPIab; ZxMbk: $CJNWc = $DYRgm->newInstanceArgs($CUZy6); goto EAsoG; dRBiC: $Bkn_0 = '\\ModStart\\Grid\\Filter\\' . ucfirst($HxDDI); goto Iv0PA; AhS8k: } } }