<?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($Mczr_) { $this->addVariables(array('selectSearch' => $Mczr_)); return $this; } public function selectRemote($Mczr_) { $this->addVariables(array('selectRemote' => $Mczr_)); return $this; } public function options($RKwZR) { $this->addVariables(array('options' => $RKwZR)); return $this; } public function optionsValue($RKwZR) { $this->addVariables(array('options' => array_build($RKwZR, function ($B34tD, $Xz28r) { return array($Xz28r, $Xz28r); }))); return $this; } public function optionArray($RKwZR, $McuFj = 'id', $Xh0Br = 'title') { $RKwZR = array_build($RKwZR, function ($B34tD, $Xz28r) use($McuFj, $Xh0Br) { return array($Xz28r[$McuFj], $Xz28r[$Xh0Br]); }); return $this->options($RKwZR); } public function onValueChangeJsFunction($xJom4) { $this->addVariables(array('onValueChangeJsFunction' => $xJom4)); return $this; } public function optionType($qeBS4) { return $this->options($qeBS4::getList()); } public function optionModel($AD05J, $eAE99 = 'id', $Qduwq = 'name', $Svako = array()) { return $this->options(ModelUtil::valueMap($AD05J, $eAE99, $Qduwq, $Svako)); } public function optionModelTree($AD05J, $McuFj = 'id', $obDAG = 'pid', $Xh0Br = 'title', $lRvVf = 'sort', $Svako = array()) { goto VCaMX; LshBL: $BA7mb = TreeUtil::itemsMergeLevel($BA7mb, $McuFj, $obDAG, $lRvVf); goto Dghgr; Dghgr: return $this->optionItems($BA7mb, $McuFj, $Xh0Br); goto deh_o; VCaMX: $BA7mb = ModelUtil::autoModel($AD05J)->where($Svako)->get(array($McuFj, $obDAG, $Xh0Br, $lRvVf)); goto LshBL; deh_o: } public function optionRepositoryTreeItems(TreeRepositoryInterface $w7Oqz, $xXDd8 = 0) { $BA7mb = $w7Oqz->getTreeItems($this->context); return $this->optionItems($BA7mb, $w7Oqz->getKeyName(), $w7Oqz->getTreeTitleColumn(), $xXDd8); } public function optionItems($BA7mb, $McuFj = 'id', $Xh0Br = 'title', $xXDd8 = 0) { goto spR6M; spR6M: $RKwZR = array(); goto rFDEL; O0rwS: return $this->options($RKwZR); goto UiwAg; wTX5e: if ($xXDd8 > 0) { $BA7mb = $BA7mb->filter(function ($Esk0p) use($xXDd8) { return $Esk0p->_level <= $xXDd8 - 1; }); } goto NLD9R; fsvJ_: foreach ($BA7mb as $kM8qX => $Esk0p) { goto bUmov; bUmov: $Tx0ze = TreeUtil::itemLevelPrefix($Esk0p->_level); goto dHkjE; dHkjE: if ($Esk0p->_level > $DnQMI) { array_push($lqIIM, $Esk0p->{$Xh0Br}); } else { goto vP4Fd; lRCL7: array_pop($lqIIM); goto L1u3r; L1u3r: array_push($lqIIM, $Esk0p->{$Xh0Br}); goto pcztW; vP4Fd: while ($Esk0p->_level < $DnQMI) { array_pop($lqIIM); $DnQMI--; } goto lRCL7; pcztW: } goto PCBpa; Cb5Fd: $RKwZR[$Esk0p->{$McuFj}] = array('label' => $Tx0ze . $Esk0p->{$Xh0Br}, 'title' => join('-', $lqIIM)); goto GB0yV; PCBpa: $DnQMI = $Esk0p->_level; goto Cb5Fd; GB0yV: } goto O0rwS; ge1ZH: $lqIIM = array(); goto fsvJ_; NLD9R: $DnQMI = 0; goto ge1ZH; rFDEL: $RKwZR[0] = L('Root'); goto wTX5e; UiwAg: } public static function optionRemoteHandleModel($AD05J, $zIeSf = 'id', $wEvc0 = 'title', $ACVUe = array()) { goto LhjEC; UGCgz: $CChUV = $vrSVj->getTrimString('keywords'); goto tn7g7; wotv0: $vrSVj = InputPackage::buildFromInput(); goto C06oa; adYe3: if ($Mczr_) { $LBO09 = $LBO09->where($zIeSf, $Mczr_); } goto S0oNk; C06oa: $Mczr_ = $vrSVj->getInteger('value'); goto UGCgz; LaZ32: $YDsPC = $LBO09->orderBy($ACVUe['sort'][0], $ACVUe['sort'][1])->limit(10)->get(array($zIeSf, $wEvc0))->toArray(); goto az4N0; LhjEC: if (!isset($ACVUe['sort'])) { $ACVUe['sort'] = array('id', 'desc'); } goto wotv0; dRS3Q: return Response::generateSuccessData(array('options' => $RKwZR)); goto vJYeK; hLblj: foreach ($YDsPC as $X8gVP) { $RKwZR[] = array('value' => $X8gVP[$zIeSf], 'label' => $X8gVP[$wEvc0]); } goto dRS3Q; S0oNk: if ($CChUV) { $LBO09 = $LBO09->where($wEvc0, 'like', '%' . $CChUV . '%'); } goto LaZ32; az4N0: $RKwZR = array(); goto hLblj; tn7g7: $LBO09 = ModelUtil::model($AD05J); goto adYe3; vJYeK: } public function render() { $this->addCascadeScript(); return parent::render(); } }