<?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($Gttsd) { $this->addVariables(array('selectSearch' => $Gttsd)); return $this; } public function selectRemote($Gttsd) { $this->addVariables(array('selectRemote' => $Gttsd)); return $this; } public function options($nO0o6) { $this->addVariables(array('options' => $nO0o6)); return $this; } public function optionsValue($nO0o6) { $this->addVariables(array('options' => array_build($nO0o6, function ($RTHJ6, $F6Fus) { return array($F6Fus, $F6Fus); }))); return $this; } public function optionArray($nO0o6, $aHfow = 'id', $mgO1O = 'title') { $nO0o6 = array_build($nO0o6, function ($RTHJ6, $F6Fus) use($aHfow, $mgO1O) { return array($F6Fus[$aHfow], $F6Fus[$mgO1O]); }); return $this->options($nO0o6); } public function onValueChangeJsFunction($IzFKB) { $this->addVariables(array('onValueChangeJsFunction' => $IzFKB)); return $this; } public function optionType($PbprP) { return $this->options($PbprP::getList()); } public function optionModel($wt8xl, $AWXu8 = 'id', $mfJsz = 'name', $uxPm_ = array()) { return $this->options(ModelUtil::valueMap($wt8xl, $AWXu8, $mfJsz, $uxPm_)); } public function optionModelTree($wt8xl, $aHfow = 'id', $FWABY = 'pid', $mgO1O = 'title', $KpDOG = 'sort', $uxPm_ = array()) { goto z5Ly5; GXz8y: $GCp0X = TreeUtil::itemsMergeLevel($GCp0X, $aHfow, $FWABY, $KpDOG); goto bIElC; z5Ly5: $GCp0X = ModelUtil::autoModel($wt8xl)->where($uxPm_)->get(array($aHfow, $FWABY, $mgO1O, $KpDOG)); goto GXz8y; bIElC: return $this->optionItems($GCp0X, $aHfow, $mgO1O); goto CrE6O; CrE6O: } public function optionRepositoryTreeItems(TreeRepositoryInterface $pEs5l, $KWM89 = 0) { $GCp0X = $pEs5l->getTreeItems($this->context); return $this->optionItems($GCp0X, $pEs5l->getKeyName(), $pEs5l->getTreeTitleColumn(), $KWM89); } public function optionItems($GCp0X, $aHfow = 'id', $mgO1O = 'title', $KWM89 = 0) { goto DZ_Oy; RXgP9: $JLJEO = 0; goto YEFbv; DZ_Oy: $nO0o6 = array(); goto LmleY; Ng0E3: return $this->options($nO0o6); goto V6TZO; fEL6s: foreach ($GCp0X as $MqJHJ => $Xvngd) { goto bC6c1; V2is_: if ($Xvngd->_level > $JLJEO) { array_push($hCfxr, $Xvngd->{$mgO1O}); } else { goto hHOB_; N89FU: array_push($hCfxr, $Xvngd->{$mgO1O}); goto WjP7y; hHOB_: while ($Xvngd->_level < $JLJEO) { array_pop($hCfxr); $JLJEO--; } goto xE8GC; xE8GC: array_pop($hCfxr); goto N89FU; WjP7y: } goto DS9ZD; GV4nW: $nO0o6[$Xvngd->{$aHfow}] = array('label' => $HTQyg . $Xvngd->{$mgO1O}, 'title' => join('-', $hCfxr)); goto qRdZP; DS9ZD: $JLJEO = $Xvngd->_level; goto GV4nW; bC6c1: $HTQyg = TreeUtil::itemLevelPrefix($Xvngd->_level); goto V2is_; qRdZP: } goto Ng0E3; wG41Y: if ($KWM89 > 0) { $GCp0X = $GCp0X->filter(function ($Xvngd) use($KWM89) { return $Xvngd->_level <= $KWM89 - 1; }); } goto RXgP9; YEFbv: $hCfxr = array(); goto fEL6s; LmleY: $nO0o6[0] = L('Root'); goto wG41Y; V6TZO: } public static function optionRemoteHandleModel($wt8xl, $aioaA = 'id', $mWP70 = 'title', $qHLCM = array()) { goto oF0kF; qVF2A: if ($koASZ) { $sFfhd = $sFfhd->where($mWP70, 'like', '%' . $koASZ . '%'); } goto mg2Xf; T2tJa: foreach ($bcEDt as $tlo2Q) { $nO0o6[] = array('value' => $tlo2Q[$aioaA], 'label' => $tlo2Q[$mWP70]); } goto QQWc0; L4PI4: $koASZ = $kFc4w->getTrimString('keywords'); goto UnSxw; QQWc0: return Response::generateSuccessData(array('options' => $nO0o6)); goto LoTeM; friti: $nO0o6 = array(); goto T2tJa; m1bdW: $Gttsd = $kFc4w->getInteger('value'); goto L4PI4; VOe7c: if ($Gttsd) { $sFfhd = $sFfhd->where($aioaA, $Gttsd); } goto qVF2A; mg2Xf: $bcEDt = $sFfhd->orderBy($qHLCM['sort'][0], $qHLCM['sort'][1])->limit(10)->get(array($aioaA, $mWP70))->toArray(); goto friti; zk6BN: $kFc4w = InputPackage::buildFromInput(); goto m1bdW; UnSxw: $sFfhd = ModelUtil::model($wt8xl); goto VOe7c; oF0kF: if (!isset($qHLCM['sort'])) { $qHLCM['sort'] = array('id', 'desc'); } goto zk6BN; LoTeM: } public function render() { $this->addCascadeScript(); return parent::render(); } }