<?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($gnky8, $LfcEJ = '') { goto wspxs; wspxs: $this->id = IdUtil::generate('GridFilter'); goto uF2Ia; uF2Ia: $this->column = $gnky8; goto aHiXo; A4pwo: $this->field = new Text($this); goto mV3HN; mV3HN: $this->field->label($this->label); goto pLKc4; aHiXo: $this->label = $LfcEJ; goto A4pwo; pLKc4: } public function name() { $KrsM3 = explode('\\', get_called_class()); return lcfirst(end($KrsM3)); } public function setTableFilter(GridFilter $JCV6U) { $this->tableFilter = $JCV6U; } public function condition($d7NKF) { if (isset($d7NKF['eq']) && $d7NKF['eq'] !== '') { return $this->buildCondition($this->column, '=', $d7NKF['eq']); } return null; } public function field($FT9zA = null) { if (null === $FT9zA) { return $this->field; } $this->field = $FT9zA; } public function defaultValue($FT9zA) { $this->defaultValue = $FT9zA; return $this; } public function autoHide($Th2Is = null) { goto EyS2b; INXEr: $this->autoHide = $Th2Is; goto b_TqR; b_TqR: return $this; goto rXbrO; EyS2b: if (null === $Th2Is) { return $this->autoHide; } goto INXEr; rXbrO: } public function column() { return $this->column; } protected function buildCondition() { goto t427Q; hkZPp: return call_user_func_array(array($this, 'buildRelationCondition'), func_get_args()); goto C4Vj6; JdT51: if (count($gnky8) == 1 || $this->grid->isDynamicModel()) { return array($this->query => func_get_args()); } goto hkZPp; t427Q: $gnky8 = explode('.', $this->column); goto JdT51; C4Vj6: } protected function buildRelationCondition() { goto Ozk1_; Ozk1_: $neKx3 = func_get_args(); goto o1ttQ; YKcaY: return array('whereHas' => array($te8Mv, function ($te8Mv) use($neKx3) { call_user_func_array(array($te8Mv, $this->query), $neKx3); })); goto UzFoO; o1ttQ: list($te8Mv, $neKx3[0]) = explode('.', $this->column); goto YKcaY; UzFoO: } public function variables() { goto YAJPH; Sh0rX: if (method_exists($this->field, 'variables')) { $vxnWf = array_merge($vxnWf, $this->field()->variables()); } goto fk_By; YAJPH: $vxnWf = array('id' => $this->id, 'column' => $this->column, 'label' => $this->label, 'field' => $this->field, 'defaultValue' => $this->defaultValue, 'autoHide' => $this->autoHide); goto Sh0rX; fk_By: return $vxnWf; goto Z405b; Z405b: } public function render() { goto AsSWP; VdCPm: $r7m3R = 'modstart::core.grid.filter.' . lcfirst(end($KrsM3)) . '-' . lcfirst(end($uazwh)); goto rX_Qa; AsSWP: if ($this->hookRendering instanceof \Closure) { $JOw_A = call_user_func($this->hookRendering, $this); if (null !== $JOw_A) { return $JOw_A; } } goto J30Ic; rX_Qa: return View::make($r7m3R, $this->variables())->render(); goto IsPfq; J30Ic: $KrsM3 = explode('\\', get_called_class()); goto sIml2; sIml2: $uazwh = explode('\\', get_class($this->field)); goto VdCPm; IsPfq: } public function grid($aGu71 = null) { goto sq_BA; fyHHf: return $this; goto WNjZo; sq_BA: if (null === $aGu71) { return $this->grid; } goto mlKlZ; mlKlZ: $this->grid = $aGu71; goto fyHHf; WNjZo: } public function __call($rPkIY, $HPXJC) { if ($this->isFluentAttribute($rPkIY)) { return $this->fluentAttribute($rPkIY, $HPXJC); } throw new \Exception('AbstractFilter __call error : ' . $rPkIY); } }