<?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 $BWo2e = null) { goto Kc6gy; Kc6gy: $this->model = $BWo2e; goto bhoiz; BJQSF: $this->scopes = collect(); goto WzD9U; bhoiz: $this->fixedScopes = collect(); goto BJQSF; WzD9U: } public function setSearch(array $Suzww) { $this->search = $Suzww; return $this; } public function scope() { goto b2op1; goniW: return $j5svu; goto hhLqT; eoREY: $this->scopes->push($j5svu); goto goniW; b2op1: $j5svu = new GridFilterScope($this); goto eoREY; hhLqT: } public function addFilter(AbstractFilter $z8oGH) { $z8oGH->setTableFilter($this); return $this->filters[] = $z8oGH; } public function clearFilter() { $this->filters = array(); } public function deleteFilterByColumn($VDtGk) { $this->filters = array_filter($this->filters, function ($z8oGH) use($VDtGk) { return $z8oGH->column() != $VDtGk; }); } public function filters() { return $this->filters; } public function hasAutoHideFilters() { foreach ($this->filters as $z8oGH) { if ($z8oGH->autoHide()) { return true; } } return false; } public function getConditions() { goto KEo6g; LGJ3D: $Suzww = $this->search; goto yrKcQ; yrKcQ: if (!empty($Suzww)) { foreach ($Suzww as $Usud7) { if (!is_array($Usud7)) { continue; } foreach ($Usud7 as $WO0KA => $VBTMH) { foreach ($this->filters() as $z8oGH) { if ($WO0KA === $z8oGH->column() && isset($VBTMH[$z8oGH->name()])) { $oVmwo = $z8oGH->condition($VBTMH); if (!empty($oVmwo)) { $v0WGh = array_keys($oVmwo); if (count($v0WGh) > 1 || count($v0WGh) == 1 && $v0WGh[0] === 0) { $bjWed = array_merge($bjWed, $oVmwo); } else { $bjWed[] = $oVmwo; } } } } } } } goto vRwNu; KEo6g: $bjWed = array(); goto LGJ3D; vRwNu: return array_filter($bjWed); goto gcygx; gcygx: } public function executeQueryConditions($sFfhd) { goto mJArW; mJArW: $bjWed = array_merge($this->getScopeConditions(), $this->getConditions()); goto Wg20T; Lduad: return $sFfhd; goto H0dz7; Wg20T: foreach ($bjWed as $oVmwo) { $sFfhd = call_user_func_array(array($sFfhd, key($oVmwo)), current($oVmwo)); } goto Lduad; H0dz7: } public function executeQuery() { goto x6xnf; xihzx: $this->model->clearQuery(); goto fgvn3; fgvn3: return $this->model->addConditions($bjWed)->getConditionQuery(); goto h09Wt; x6xnf: $bjWed = array_merge($this->getScopeConditions(), $this->getConditions()); goto xihzx; h09Wt: } public function execute() { goto hSqf0; hSqf0: $bjWed = array_merge($this->getScopeConditions(), $this->getConditions()); goto IDYVH; IDYVH: $this->model->clearQuery(); goto YaXaF; YaXaF: return $this->model->addConditions($bjWed)->buildData(); goto ZQa2C; ZQa2C: } private function getScopeConditions() { return array(); } public function getSearch() { return $this->search; } public function __call($fSCUf, $g59Hh) { if (in_array($fSCUf, $this->supports)) { goto CxtXd; wC2W3: $FD_lk = new ReflectionClass($uS8I4); goto ZBOmL; CxtXd: $uS8I4 = '\\ModStart\\Grid\\Filter\\' . ucfirst($fSCUf); goto wC2W3; ZBOmL: $z8oGH = $FD_lk->newInstanceArgs($g59Hh); goto JsnOj; ucVQZ: return $this->addFilter($z8oGH); goto sgj9S; JsnOj: if ($this->model) { $z8oGH->grid($this->model->grid()); } goto ucVQZ; sgj9S: } } }