<?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 $vn_cr = null) { goto V7CFh; mk7T9: $this->scopes = collect(); goto gYpM2; V7CFh: $this->model = $vn_cr; goto v526b; v526b: $this->fixedScopes = collect(); goto mk7T9; gYpM2: } public function setSearch(array $XnKlU) { $this->search = $XnKlU; return $this; } public function scope() { goto bvUuG; bvUuG: $q_SZe = new GridFilterScope($this); goto Yfpj1; wZmUE: return $q_SZe; goto WsmDs; Yfpj1: $this->scopes->push($q_SZe); goto wZmUE; WsmDs: } public function addFilter(AbstractFilter $Nxn6E) { $Nxn6E->setTableFilter($this); return $this->filters[] = $Nxn6E; } public function clearFilter() { $this->filters = array(); } public function deleteFilterByColumn($t_tdX) { $this->filters = array_filter($this->filters, function ($Nxn6E) use($t_tdX) { return $Nxn6E->column() != $t_tdX; }); } public function filters() { return $this->filters; } public function hasAutoHideFilters() { foreach ($this->filters as $Nxn6E) { if ($Nxn6E->autoHide()) { return true; } } return false; } public function getConditions() { goto yfjpR; dOLOl: $XnKlU = $this->search; goto GYW3d; yfjpR: $Ep7JA = array(); goto dOLOl; DnVpU: return array_filter($Ep7JA); goto nJbTj; GYW3d: if (!empty($XnKlU)) { foreach ($XnKlU as $EQR8J) { if (!is_array($EQR8J)) { continue; } foreach ($EQR8J as $WLkPV => $ILSLv) { foreach ($this->filters() as $Nxn6E) { if ($WLkPV === $Nxn6E->column() && isset($ILSLv[$Nxn6E->name()])) { $i7RgZ = $Nxn6E->condition($ILSLv); if (!empty($i7RgZ)) { $rBDWA = array_keys($i7RgZ); if (count($rBDWA) > 1 || count($rBDWA) == 1 && $rBDWA[0] === 0) { $Ep7JA = array_merge($Ep7JA, $i7RgZ); } else { $Ep7JA[] = $i7RgZ; } } } } } } } goto DnVpU; nJbTj: } public function executeQueryConditions($LBO09) { goto xZlCc; Tvues: foreach ($Ep7JA as $i7RgZ) { $LBO09 = call_user_func_array(array($LBO09, key($i7RgZ)), current($i7RgZ)); } goto tj1Rs; tj1Rs: return $LBO09; goto gEgTY; xZlCc: $Ep7JA = array_merge($this->getScopeConditions(), $this->getConditions()); goto Tvues; gEgTY: } public function executeQuery() { goto uk9oR; uk9oR: $Ep7JA = array_merge($this->getScopeConditions(), $this->getConditions()); goto Mgbun; Mplqr: return $this->model->addConditions($Ep7JA)->getConditionQuery(); goto xhCx9; Mgbun: $this->model->clearQuery(); goto Mplqr; xhCx9: } public function execute() { goto NDpXM; NDpXM: $Ep7JA = array_merge($this->getScopeConditions(), $this->getConditions()); goto A9YIb; A9YIb: $this->model->clearQuery(); goto JnYH3; JnYH3: return $this->model->addConditions($Ep7JA)->buildData(); goto yZeIj; yZeIj: } private function getScopeConditions() { return array(); } public function getSearch() { return $this->search; } public function __call($pK00s, $rxS2C) { if (in_array($pK00s, $this->supports)) { goto Hor1d; Hor1d: $qlsz_ = '\\ModStart\\Grid\\Filter\\' . ucfirst($pK00s); goto X54ys; X54ys: $WtA8z = new ReflectionClass($qlsz_); goto G0iLe; G0iLe: $Nxn6E = $WtA8z->newInstanceArgs($rxS2C); goto c_PYt; XPcPW: return $this->addFilter($Nxn6E); goto mmeJk; c_PYt: if ($this->model) { $Nxn6E->grid($this->model->grid()); } goto XPcPW; mmeJk: } } }