<?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 $xTADA = null) { goto WMwOK; WMwOK: $this->model = $xTADA; goto KN2fo; OIn3P: $this->scopes = collect(); goto G4e48; KN2fo: $this->fixedScopes = collect(); goto OIn3P; G4e48: } public function setSearch(array $ZhR0b) { $this->search = $ZhR0b; return $this; } public function scope() { goto bSHyr; wAG2z: return $y28z9; goto ch7Rh; pfTq8: $this->scopes->push($y28z9); goto wAG2z; bSHyr: $y28z9 = new GridFilterScope($this); goto pfTq8; ch7Rh: } public function addFilter(AbstractFilter $XYn5i) { $XYn5i->setTableFilter($this); return $this->filters[] = $XYn5i; } public function clearFilter() { $this->filters = array(); } public function deleteFilterByColumn($BlfaU) { $this->filters = array_filter($this->filters, function ($XYn5i) use($BlfaU) { return $XYn5i->column() != $BlfaU; }); } public function filters() { return $this->filters; } public function hasAutoHideFilters() { foreach ($this->filters as $XYn5i) { if ($XYn5i->autoHide()) { return true; } } return false; } public function getConditions() { goto N1xFQ; N_B9o: $ZhR0b = $this->search; goto HUTRg; QJtKR: return array_filter($xn5uK); goto M3plG; HUTRg: if (!empty($ZhR0b)) { foreach ($ZhR0b as $ppRIa) { if (!is_array($ppRIa)) { continue; } foreach ($ppRIa as $zv3iL => $T1O2h) { foreach ($this->filters() as $XYn5i) { if ($zv3iL === $XYn5i->column() && isset($T1O2h[$XYn5i->name()])) { $b43W9 = $XYn5i->condition($T1O2h); if (!empty($b43W9)) { $UtHxd = array_keys($b43W9); if (count($UtHxd) > 1 || count($UtHxd) == 1 && $UtHxd[0] === 0) { $xn5uK = array_merge($xn5uK, $b43W9); } else { $xn5uK[] = $b43W9; } } } } } } } goto QJtKR; N1xFQ: $xn5uK = array(); goto N_B9o; M3plG: } public function executeQueryConditions($vw3jY) { goto bckJV; OCmGp: foreach ($xn5uK as $b43W9) { $vw3jY = call_user_func_array(array($vw3jY, key($b43W9)), current($b43W9)); } goto sKdNl; bckJV: $xn5uK = array_merge($this->getScopeConditions(), $this->getConditions()); goto OCmGp; sKdNl: return $vw3jY; goto n3EY3; n3EY3: } public function executeQuery() { goto MY7ml; V5ce2: return $this->model->addConditions($xn5uK)->getConditionQuery(); goto ijznZ; BLYJ1: $this->model->clearQuery(); goto V5ce2; MY7ml: $xn5uK = array_merge($this->getScopeConditions(), $this->getConditions()); goto BLYJ1; ijznZ: } public function execute() { goto H0fQG; wARXB: return $this->model->addConditions($xn5uK)->buildData(); goto vnZU0; H0fQG: $xn5uK = array_merge($this->getScopeConditions(), $this->getConditions()); goto Wr2Lg; Wr2Lg: $this->model->clearQuery(); goto wARXB; vnZU0: } private function getScopeConditions() { return array(); } public function getSearch() { return $this->search; } public function __call($fVu6a, $RSGSj) { if (in_array($fVu6a, $this->supports)) { goto vXniM; RB0nY: $XYn5i = $plKTy->newInstanceArgs($RSGSj); goto y4k_i; y4k_i: if ($this->model) { $XYn5i->grid($this->model->grid()); } goto FBmHX; FBmHX: return $this->addFilter($XYn5i); goto ggeAY; vXniM: $S0esq = '\\ModStart\\Grid\\Filter\\' . ucfirst($fVu6a); goto PTg17; PTg17: $plKTy = new ReflectionClass($S0esq); goto RB0nY; ggeAY: } } }