<?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($mdHu1) { $this->addVariables(array('selectSearch' => $mdHu1)); return $this; } public function selectRemote($mdHu1) { $this->addVariables(array('selectRemote' => $mdHu1)); return $this; } public function options($Tpa5t) { $this->addVariables(array('options' => $Tpa5t)); return $this; } public function optionsValue($Tpa5t) { $this->addVariables(array('options' => array_build($Tpa5t, function ($Fkd1C, $pk5fc) { return array($pk5fc, $pk5fc); }))); return $this; } public function optionArray($Tpa5t, $Elwu5 = 'id', $ti9Nw = 'title') { $Tpa5t = array_build($Tpa5t, function ($Fkd1C, $pk5fc) use($Elwu5, $ti9Nw) { return array($pk5fc[$Elwu5], $pk5fc[$ti9Nw]); }); return $this->options($Tpa5t); } public function onValueChangeJsFunction($Yw8oE) { $this->addVariables(array('onValueChangeJsFunction' => $Yw8oE)); return $this; } public function optionType($fUMA5) { return $this->options($fUMA5::getList()); } public function optionModel($tkusQ, $CnFib = 'id', $paeUa = 'name', $JRjnb = array()) { return $this->options(ModelUtil::valueMap($tkusQ, $CnFib, $paeUa, $JRjnb)); } public function optionModelTree($tkusQ, $Elwu5 = 'id', $RyxSz = 'pid', $ti9Nw = 'title', $oht67 = 'sort', $JRjnb = array()) { goto xMlEo; xMlEo: $dhsbx = ModelUtil::autoModel($tkusQ)->where($JRjnb)->get(array($Elwu5, $RyxSz, $ti9Nw, $oht67)); goto jVsYe; wPYiv: return $this->optionItems($dhsbx, $Elwu5, $ti9Nw); goto nWRcF; jVsYe: $dhsbx = TreeUtil::itemsMergeLevel($dhsbx, $Elwu5, $RyxSz, $oht67); goto wPYiv; nWRcF: } public function optionRepositoryTreeItems(TreeRepositoryInterface $kEh5R, $XboOM = 0) { $dhsbx = $kEh5R->getTreeItems($this->context); return $this->optionItems($dhsbx, $kEh5R->getKeyName(), $kEh5R->getTreeTitleColumn(), $XboOM); } public function optionItems($dhsbx, $Elwu5 = 'id', $ti9Nw = 'title', $XboOM = 0) { goto UVa5C; ajwtS: return $this->options($Tpa5t); goto kyDBE; NyuFh: $ouDm1 = 0; goto cOO53; XdEYk: if ($XboOM > 0) { $dhsbx = $dhsbx->filter(function ($yFnpO) use($XboOM) { return $yFnpO->_level <= $XboOM - 1; }); } goto NyuFh; I_dkM: $Tpa5t[0] = L('Root'); goto XdEYk; UVa5C: $Tpa5t = array(); goto I_dkM; drLN8: foreach ($dhsbx as $Xn_Rr => $yFnpO) { goto mdiVL; dd_ns: if ($yFnpO->_level > $ouDm1) { array_push($VauQt, $yFnpO->{$ti9Nw}); } else { goto tiM3d; s4vOX: array_push($VauQt, $yFnpO->{$ti9Nw}); goto WukVn; tiM3d: while ($yFnpO->_level < $ouDm1) { array_pop($VauQt); $ouDm1--; } goto Zy6dt; Zy6dt: array_pop($VauQt); goto s4vOX; WukVn: } goto F93cE; mdiVL: $bD3WW = TreeUtil::itemLevelPrefix($yFnpO->_level); goto dd_ns; F93cE: $ouDm1 = $yFnpO->_level; goto HDTu1; HDTu1: $Tpa5t[$yFnpO->{$Elwu5}] = array('label' => $bD3WW . $yFnpO->{$ti9Nw}, 'title' => join('-', $VauQt)); goto alu0h; alu0h: } goto ajwtS; cOO53: $VauQt = array(); goto drLN8; kyDBE: } public static function optionRemoteHandleModel($tkusQ, $Hx0sQ = 'id', $zafNU = 'title', $pFM9U = array()) { goto QqRvx; QYJlY: foreach ($PcG4B as $ZMPsd) { $Tpa5t[] = array('value' => $ZMPsd[$Hx0sQ], 'label' => $ZMPsd[$zafNU]); } goto zIc8G; MWo9s: if ($mdHu1) { $qeoqS = $qeoqS->where($Hx0sQ, $mdHu1); } goto XgsYL; SA630: $mdHu1 = $TG2we->getInteger('value'); goto SJcyg; QqRvx: if (!isset($pFM9U['sort'])) { $pFM9U['sort'] = array('id', 'desc'); } goto OOKI5; zIc8G: return Response::generateSuccessData(array('options' => $Tpa5t)); goto E0_Rp; qz_27: $qeoqS = ModelUtil::model($tkusQ); goto MWo9s; SEA86: $PcG4B = $qeoqS->orderBy($pFM9U['sort'][0], $pFM9U['sort'][1])->limit(10)->get(array($Hx0sQ, $zafNU))->toArray(); goto RkWP0; RkWP0: $Tpa5t = array(); goto QYJlY; SJcyg: $l15kG = $TG2we->getTrimString('keywords'); goto qz_27; XgsYL: if ($l15kG) { $qeoqS = $qeoqS->where($zafNU, 'like', '%' . $l15kG . '%'); } goto SEA86; OOKI5: $TG2we = InputPackage::buildFromInput(); goto SA630; E0_Rp: } public function render() { $this->addCascadeScript(); return parent::render(); } }