<?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($HDpl6) { $this->addVariables(array('selectSearch' => $HDpl6)); return $this; } public function selectRemote($HDpl6) { $this->addVariables(array('selectRemote' => $HDpl6)); return $this; } public function options($Bodfy) { $this->addVariables(array('options' => $Bodfy)); return $this; } public function optionsValue($Bodfy) { $this->addVariables(array('options' => array_build($Bodfy, function ($pztz4, $Q0rz2) { return array($Q0rz2, $Q0rz2); }))); return $this; } public function optionArray($Bodfy, $nb7Km = 'id', $FHLJ4 = 'title') { $Bodfy = array_build($Bodfy, function ($pztz4, $Q0rz2) use($nb7Km, $FHLJ4) { return array($Q0rz2[$nb7Km], $Q0rz2[$FHLJ4]); }); return $this->options($Bodfy); } public function onValueChangeJsFunction($VGNYD) { $this->addVariables(array('onValueChangeJsFunction' => $VGNYD)); return $this; } public function optionType($ottBC) { return $this->options($ottBC::getList()); } public function optionModel($wyCKK, $lwKEo = 'id', $vrWwY = 'name', $B1h5X = array()) { return $this->options(ModelUtil::valueMap($wyCKK, $lwKEo, $vrWwY, $B1h5X)); } public function optionModelTree($wyCKK, $nb7Km = 'id', $pD9GE = 'pid', $FHLJ4 = 'title', $M6Epp = 'sort', $B1h5X = array()) { goto BN8pw; bVb1N: $NewRh = TreeUtil::itemsMergeLevel($NewRh, $nb7Km, $pD9GE, $M6Epp); goto uGx9u; BN8pw: $NewRh = ModelUtil::autoModel($wyCKK)->where($B1h5X)->get(array($nb7Km, $pD9GE, $FHLJ4, $M6Epp)); goto bVb1N; uGx9u: return $this->optionItems($NewRh, $nb7Km, $FHLJ4); goto m6qpG; m6qpG: } public function optionRepositoryTreeItems(TreeRepositoryInterface $kZXWm, $cnLVC = 0) { $NewRh = $kZXWm->getTreeItems($this->context); return $this->optionItems($NewRh, $kZXWm->getKeyName(), $kZXWm->getTreeTitleColumn(), $cnLVC); } public function optionItems($NewRh, $nb7Km = 'id', $FHLJ4 = 'title', $cnLVC = 0) { goto Wh65j; g2DS0: $Bodfy[0] = L('Root'); goto POLqq; AvDFl: $DVBAT = array(); goto m9pBe; Wh65j: $Bodfy = array(); goto g2DS0; POLqq: if ($cnLVC > 0) { $NewRh = $NewRh->filter(function ($OV1o4) use($cnLVC) { return $OV1o4->_level <= $cnLVC - 1; }); } goto NhS4F; m9pBe: foreach ($NewRh as $tMyPy => $OV1o4) { goto cPMq2; ZWaGP: if ($OV1o4->_level > $g3l4O) { array_push($DVBAT, $OV1o4->{$FHLJ4}); } else { goto wI_21; SJdlX: array_push($DVBAT, $OV1o4->{$FHLJ4}); goto CJ1AZ; wI_21: while ($OV1o4->_level < $g3l4O) { array_pop($DVBAT); $g3l4O--; } goto YnjVk; YnjVk: array_pop($DVBAT); goto SJdlX; CJ1AZ: } goto N5Kdb; cPMq2: $BSuqj = TreeUtil::itemLevelPrefix($OV1o4->_level); goto ZWaGP; y_jRN: $Bodfy[$OV1o4->{$nb7Km}] = array('label' => $BSuqj . $OV1o4->{$FHLJ4}, 'title' => join('-', $DVBAT)); goto g30eQ; N5Kdb: $g3l4O = $OV1o4->_level; goto y_jRN; g30eQ: } goto mVLAq; NhS4F: $g3l4O = 0; goto AvDFl; mVLAq: return $this->options($Bodfy); goto JdwHy; JdwHy: } public static function optionRemoteHandleModel($wyCKK, $ic5c_ = 'id', $vWMJh = 'title', $AXgEz = array()) { goto SK2vp; SDD1t: $DtcC9 = $sYsuI->getTrimString('keywords'); goto RPzd7; TNpeW: $HDpl6 = $sYsuI->getInteger('value'); goto SDD1t; WJHTJ: $lz_pk = $vw3jY->orderBy($AXgEz['sort'][0], $AXgEz['sort'][1])->limit(10)->get(array($ic5c_, $vWMJh))->toArray(); goto kHQ1H; SK2vp: if (!isset($AXgEz['sort'])) { $AXgEz['sort'] = array('id', 'desc'); } goto raAtu; ujUYo: if ($DtcC9) { $vw3jY = $vw3jY->where($vWMJh, 'like', '%' . $DtcC9 . '%'); } goto WJHTJ; Yq5e2: return Response::generateSuccessData(array('options' => $Bodfy)); goto D20y0; raAtu: $sYsuI = InputPackage::buildFromInput(); goto TNpeW; CyTkm: if ($HDpl6) { $vw3jY = $vw3jY->where($ic5c_, $HDpl6); } goto ujUYo; RPzd7: $vw3jY = ModelUtil::model($wyCKK); goto CyTkm; kHQ1H: $Bodfy = array(); goto UnZrD; UnZrD: foreach ($lz_pk as $kwA4W) { $Bodfy[] = array('value' => $kwA4W[$ic5c_], 'label' => $kwA4W[$vWMJh]); } goto Yq5e2; D20y0: } public function render() { $this->addCascadeScript(); return parent::render(); } }