<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Field; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Input\InputPackage; use ModStart\Core\Input\Response; use ModStart\Core\Util\TreeUtil; use ModStart\Field\Concern\CanCascadeFields; use ModStart\Repository\TreeRepositoryInterface; class Select extends AbstractField { use CanCascadeFields; protected function setup() { $this->addVariables(array('options' => array(), 'onValueChangeJsFunction' => '', 'selectSearch' => false, 'selectRemote' => null)); } public function selectSearch($gwXrh) { $this->addVariables(array('selectSearch' => $gwXrh)); return $this; } public function selectRemote($gwXrh) { $this->addVariables(array('selectRemote' => $gwXrh)); return $this; } public function options($C87JF) { $this->addVariables(array('options' => $C87JF)); return $this; } public function optionsValue($C87JF) { $this->addVariables(array('options' => array_build($C87JF, function ($GBNIv, $VFelt) { return array($VFelt, $VFelt); }))); return $this; } public function optionArray($C87JF, $ifxZk = 'id', $W20BA = 'title') { $C87JF = array_build($C87JF, function ($GBNIv, $VFelt) use($ifxZk, $W20BA) { return array($VFelt[$ifxZk], $VFelt[$W20BA]); }); return $this->options($C87JF); } public function onValueChangeJsFunction($ENLfr) { $this->addVariables(array('onValueChangeJsFunction' => $ENLfr)); return $this; } public function optionType($nsF6n) { return $this->options($nsF6n::getList()); } public function optionModel($Beeb4, $bZCgI = 'id', $sb8RM = 'name', $nDJ06 = array()) { return $this->options(ModelUtil::valueMap($Beeb4, $bZCgI, $sb8RM, $nDJ06)); } public function optionModelTree($Beeb4, $ifxZk = 'id', $dbsFT = 'pid', $W20BA = 'title', $FrsLu = 'sort', $nDJ06 = array()) { goto xiQGt; k4sxs: return $this->optionItems($NXm6t, $ifxZk, $W20BA); goto GWhXn; mwzsM: $NXm6t = TreeUtil::itemsMergeLevel($NXm6t, $ifxZk, $dbsFT, $FrsLu); goto k4sxs; xiQGt: $NXm6t = ModelUtil::autoModel($Beeb4)->where($nDJ06)->get(array($ifxZk, $dbsFT, $W20BA, $FrsLu)); goto mwzsM; GWhXn: } public function optionRepositoryTreeItems(TreeRepositoryInterface $WLLL5, $qNbNl = 0) { $NXm6t = $WLLL5->getTreeItems($this->context); return $this->optionItems($NXm6t, $WLLL5->getKeyName(), $WLLL5->getTreeTitleColumn(), $qNbNl); } public function optionItems($NXm6t, $ifxZk = 'id', $W20BA = 'title', $qNbNl = 0) { goto qR5G3; RBG81: $J_OVa = 0; goto XKPBe; ISL9v: return $this->options($C87JF); goto FeANV; qR5G3: $C87JF = array(); goto zOzLL; ao4IG: if ($qNbNl > 0) { $NXm6t = $NXm6t->filter(function ($nsWl0) use($qNbNl) { return $nsWl0->_level <= $qNbNl - 1; }); } goto RBG81; zOzLL: $C87JF[0] = L('Root'); goto ao4IG; XKPBe: $BDska = array(); goto LZQsP; LZQsP: foreach ($NXm6t as $VJ5vg => $nsWl0) { goto qiAUB; wtEor: $C87JF[$nsWl0->{$ifxZk}] = array('label' => $cxyYM . $nsWl0->{$W20BA}, 'title' => join('-', $BDska)); goto VVJPw; h_Rt4: $J_OVa = $nsWl0->_level; goto wtEor; qiAUB: $cxyYM = TreeUtil::itemLevelPrefix($nsWl0->_level); goto QuZ0y; QuZ0y: if ($nsWl0->_level > $J_OVa) { array_push($BDska, $nsWl0->{$W20BA}); } else { goto t_ECd; vMKNj: array_push($BDska, $nsWl0->{$W20BA}); goto CJLtJ; t_ECd: while ($nsWl0->_level < $J_OVa) { array_pop($BDska); $J_OVa--; } goto aE_aR; aE_aR: array_pop($BDska); goto vMKNj; CJLtJ: } goto h_Rt4; VVJPw: } goto ISL9v; FeANV: } public static function optionRemoteHandleModel($Beeb4, $Hd3GJ = 'id', $GQmMQ = 'title', $zlK8N = array()) { goto wVbfl; FYI5q: $lpymm = ModelUtil::model($Beeb4); goto yq8PI; xkAUv: if ($LDRBW) { $lpymm = $lpymm->where($GQmMQ, 'like', '%' . $LDRBW . '%'); } goto CgdKp; f4e9T: return Response::generateSuccessData(array('options' => $C87JF)); goto osS4_; GWx7S: $C87JF = array(); goto A3a0F; ou0uK: $Zxpx_ = InputPackage::buildFromInput(); goto ctNEW; A3a0F: foreach ($feJuE as $Jd1Wg) { $C87JF[] = array('value' => $Jd1Wg[$Hd3GJ], 'label' => $Jd1Wg[$GQmMQ]); } goto f4e9T; ctNEW: $gwXrh = $Zxpx_->getInteger('value'); goto qxCdE; wVbfl: if (!isset($zlK8N['sort'])) { $zlK8N['sort'] = array('id', 'desc'); } goto ou0uK; qxCdE: $LDRBW = $Zxpx_->getTrimString('keywords'); goto FYI5q; yq8PI: if ($gwXrh) { $lpymm = $lpymm->where($Hd3GJ, $gwXrh); } goto xkAUv; CgdKp: $feJuE = $lpymm->orderBy($zlK8N['sort'][0], $zlK8N['sort'][1])->limit(10)->get(array($Hd3GJ, $GQmMQ))->toArray(); goto GWx7S; osS4_: } public function render() { $this->addCascadeScript(); return parent::render(); } }