<?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($cBDsM) { $this->addVariables(array('selectSearch' => $cBDsM)); return $this; } public function selectRemote($cBDsM) { $this->addVariables(array('selectRemote' => $cBDsM)); return $this; } public function options($Ho5Xg) { $this->addVariables(array('options' => $Ho5Xg)); return $this; } public function optionsValue($Ho5Xg) { $this->addVariables(array('options' => array_build($Ho5Xg, function ($lxIPA, $knQyJ) { return array($knQyJ, $knQyJ); }))); return $this; } public function optionArray($Ho5Xg, $dH2vW = 'id', $dqafu = 'title') { $Ho5Xg = array_build($Ho5Xg, function ($lxIPA, $knQyJ) use($dH2vW, $dqafu) { return array($knQyJ[$dH2vW], $knQyJ[$dqafu]); }); return $this->options($Ho5Xg); } public function onValueChangeJsFunction($TMgD3) { $this->addVariables(array('onValueChangeJsFunction' => $TMgD3)); return $this; } public function optionType($cxdWJ) { return $this->options($cxdWJ::getList()); } public function optionModel($loNjC, $WoS8y = 'id', $tYSg7 = 'name', $s1Lo4 = array()) { return $this->options(ModelUtil::valueMap($loNjC, $WoS8y, $tYSg7, $s1Lo4)); } public function optionModelTree($loNjC, $dH2vW = 'id', $FfN9V = 'pid', $dqafu = 'title', $s3LKR = 'sort', $s1Lo4 = array()) { goto aLgo6; L08EE: $l3jpm = TreeUtil::itemsMergeLevel($l3jpm, $dH2vW, $FfN9V, $s3LKR); goto dYCGo; dYCGo: return $this->optionItems($l3jpm, $dH2vW, $dqafu); goto PTnAU; aLgo6: $l3jpm = ModelUtil::autoModel($loNjC)->where($s1Lo4)->get(array($dH2vW, $FfN9V, $dqafu, $s3LKR)); goto L08EE; PTnAU: } public function optionRepositoryTreeItems(TreeRepositoryInterface $UgPp_, $GF9F8 = 0) { $l3jpm = $UgPp_->getTreeItems($this->context); return $this->optionItems($l3jpm, $UgPp_->getKeyName(), $UgPp_->getTreeTitleColumn(), $GF9F8); } public function optionItems($l3jpm, $dH2vW = 'id', $dqafu = 'title', $GF9F8 = 0) { goto hTJgU; zlzTG: if ($GF9F8 > 0) { $l3jpm = $l3jpm->filter(function ($P1uVJ) use($GF9F8) { return $P1uVJ->_level <= $GF9F8 - 1; }); } goto NPiz7; tt60H: return $this->options($Ho5Xg); goto fvwSd; USOfj: foreach ($l3jpm as $jqibn => $P1uVJ) { goto Mt8xn; ypxaa: $Ho5Xg[$P1uVJ->{$dH2vW}] = array('label' => $hyTx0 . $P1uVJ->{$dqafu}, 'title' => join('-', $O6YhQ)); goto CYZcE; Mt8xn: $hyTx0 = TreeUtil::itemLevelPrefix($P1uVJ->_level); goto WmJgx; wFu2e: $n7Ldu = $P1uVJ->_level; goto ypxaa; WmJgx: if ($P1uVJ->_level > $n7Ldu) { array_push($O6YhQ, $P1uVJ->{$dqafu}); } else { goto YDJrZ; YDJrZ: while ($P1uVJ->_level < $n7Ldu) { array_pop($O6YhQ); $n7Ldu--; } goto yDrzj; yDrzj: array_pop($O6YhQ); goto cH1Ts; cH1Ts: array_push($O6YhQ, $P1uVJ->{$dqafu}); goto OFY_Q; OFY_Q: } goto wFu2e; CYZcE: } goto tt60H; d2dp8: $Ho5Xg[0] = L('Root'); goto zlzTG; hTJgU: $Ho5Xg = array(); goto d2dp8; zkarZ: $O6YhQ = array(); goto USOfj; NPiz7: $n7Ldu = 0; goto zkarZ; fvwSd: } public static function optionRemoteHandleModel($loNjC, $youLk = 'id', $JBEUQ = 'title', $mattM = array()) { goto D8vW5; g9W6t: foreach ($d5ixK as $IgPyb) { $Ho5Xg[] = array('value' => $IgPyb[$youLk], 'label' => $IgPyb[$JBEUQ]); } goto UFDjP; Sx2sA: $cBDsM = $vfMTB->getInteger('value'); goto r_xuI; yxp0Q: $d5ixK = $nYIOS->orderBy($mattM['sort'][0], $mattM['sort'][1])->limit(10)->get(array($youLk, $JBEUQ))->toArray(); goto yMW_g; livp3: $vfMTB = InputPackage::buildFromInput(); goto Sx2sA; yMW_g: $Ho5Xg = array(); goto g9W6t; ykyLO: if ($cBDsM) { $nYIOS = $nYIOS->where($youLk, $cBDsM); } goto pvl2G; D8vW5: if (!isset($mattM['sort'])) { $mattM['sort'] = array('id', 'desc'); } goto livp3; r_xuI: $R5QVI = $vfMTB->getTrimString('keywords'); goto qpzu7; UFDjP: return Response::generateSuccessData(array('options' => $Ho5Xg)); goto w5ty1; qpzu7: $nYIOS = ModelUtil::model($loNjC); goto ykyLO; pvl2G: if ($R5QVI) { $nYIOS = $nYIOS->where($JBEUQ, 'like', '%' . $R5QVI . '%'); } goto yxp0Q; w5ty1: } public function render() { $this->addCascadeScript(); return parent::render(); } }