<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Grid\Filter; use Illuminate\Support\Facades\View; use ModStart\Core\Exception\BizException; use ModStart\Core\Util\IdUtil; use ModStart\Grid\Filter; use ModStart\Grid\Filter\Field\Text; use ModStart\Grid\Grid; use ModStart\Grid\GridFilter; use ModStart\Support\Concern\HasFluentAttribute; abstract class AbstractFilter { use HasFluentAttribute; private $fluentAttributes = array('hookRendering'); private $hookRendering; private $grid; protected $id; protected $label; protected $column; protected $field; protected $defaultValue; protected $query = 'where'; private $tableFilter; private $autoHide = false; public function __construct($BlfaU, $Nvfoc = '') { goto iWQHp; r4CoV: $this->label = $Nvfoc; goto T_mZb; BS2kl: $this->field->label($this->label); goto sL8__; LtYKj: $this->column = $BlfaU; goto r4CoV; iWQHp: $this->id = IdUtil::generate('GridFilter'); goto LtYKj; T_mZb: $this->field = new Text($this); goto BS2kl; sL8__: } public function name() { $UfDw1 = explode('\\', get_called_class()); return lcfirst(end($UfDw1)); } public function setTableFilter(GridFilter $XYn5i) { $this->tableFilter = $XYn5i; } public function condition($ADVMQ) { if (isset($ADVMQ['eq']) && $ADVMQ['eq'] !== '') { return $this->buildCondition($this->column, '=', $ADVMQ['eq']); } return null; } public function field($HDpl6 = null) { goto UH6B_; ED_Sg: return $this; goto Yk6Ci; VP08d: $this->field = $HDpl6; goto ED_Sg; UH6B_: if (null === $HDpl6) { return $this->field; } goto VP08d; Yk6Ci: } public function defaultValue($HDpl6) { $this->defaultValue = $HDpl6; return $this; } public function autoHide($qe4LH = null) { goto XW2oP; tmjd_: return $this; goto ar0VW; XW2oP: if (null === $qe4LH) { return $this->autoHide; } goto a_TjB; a_TjB: $this->autoHide = $qe4LH; goto tmjd_; ar0VW: } public function column() { return $this->column; } protected function buildCondition() { goto MHUcE; suKit: if (count($BlfaU) == 1 || $this->grid->isDynamicModel()) { return array($this->query => func_get_args()); } goto l8wOg; MHUcE: $BlfaU = explode('.', $this->column); goto suKit; l8wOg: return call_user_func_array(array($this, 'buildRelationCondition'), func_get_args()); goto IS64r; IS64r: } protected function buildRelationCondition() { goto SrHcu; SrHcu: $oKQKj = func_get_args(); goto bnKIL; NVE3w: return array('whereHas' => array($zyWVS, function ($zyWVS) use($oKQKj) { call_user_func_array(array($zyWVS, $this->query), $oKQKj); })); goto bCoY_; bnKIL: list($zyWVS, $oKQKj[0]) = explode('.', $this->column); goto NVE3w; bCoY_: } public function variables() { goto NWxVf; NWxVf: $m9tbT = array('id' => $this->id, 'column' => $this->column, 'label' => $this->label, 'field' => $this->field, 'defaultValue' => $this->defaultValue, 'autoHide' => $this->autoHide); goto VUVAn; VUVAn: $m9tbT = array_merge($m9tbT, $this->field->variables()); goto ETRfv; ETRfv: return $m9tbT; goto yo2dA; yo2dA: } public function render() { goto MYXDu; TgAdl: $PnCPZ = explode('\\', get_class($this->field)); goto pTGPW; MYXDu: if ($this->hookRendering instanceof \Closure) { $Z5nZL = call_user_func($this->hookRendering, $this); if (null !== $Z5nZL) { return $Z5nZL; } } goto D3Gj5; pTGPW: $x0USf = 'modstart::core.grid.filter.' . lcfirst(end($UfDw1)) . '-' . lcfirst(end($PnCPZ)); goto S_Rfz; S_Rfz: return View::make($x0USf, $this->variables())->render(); goto RHcVC; D3Gj5: $UfDw1 = explode('\\', get_called_class()); goto TgAdl; RHcVC: } public function grid($cRz_h = null) { goto u_Cy2; YJMRK: return $this; goto t1LfX; j__a6: $this->grid = $cRz_h; goto YJMRK; u_Cy2: if (null === $cRz_h) { return $this->grid; } goto j__a6; t1LfX: } public function __call($f0dxO, $RSGSj) { if ($this->isFluentAttribute($f0dxO)) { return $this->fluentAttribute($f0dxO, $RSGSj); } throw new \Exception('AbstractFilter __call error : ' . $f0dxO); } }