<?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($ib3B9) { $this->addVariables(array('selectSearch' => $ib3B9)); return $this; } public function selectRemote($ib3B9) { $this->addVariables(array('selectRemote' => $ib3B9)); return $this; } public function options($atZJ8) { $this->addVariables(array('options' => $atZJ8)); return $this; } public function optionsValue($atZJ8) { $this->addVariables(array('options' => array_build($atZJ8, function ($F_a6B, $JiRHR) { return array($JiRHR, $JiRHR); }))); return $this; } public function optionArray($atZJ8, $u3aKG = 'id', $RwQHi = 'title') { $atZJ8 = array_build($atZJ8, function ($F_a6B, $JiRHR) use($u3aKG, $RwQHi) { return array($JiRHR[$u3aKG], $JiRHR[$RwQHi]); }); return $this->options($atZJ8); } public function onValueChangeJsFunction($djjhN) { $this->addVariables(array('onValueChangeJsFunction' => $djjhN)); return $this; } public function optionType($lIzQw) { return $this->options($lIzQw::getList()); } public function optionModel($Y2RbY, $MQulf = 'id', $nbb6p = 'name', $hAsFN = array()) { return $this->options(ModelUtil::valueMap($Y2RbY, $MQulf, $nbb6p, $hAsFN)); } public function optionModelTree($Y2RbY, $u3aKG = 'id', $BnYoa = 'pid', $RwQHi = 'title', $BYNn7 = 'sort', $hAsFN = array()) { goto oYrNg; oYrNg: $FF843 = ModelUtil::autoModel($Y2RbY)->where($hAsFN)->get(array($u3aKG, $BnYoa, $RwQHi, $BYNn7)); goto VAoRR; VAoRR: $FF843 = TreeUtil::itemsMergeLevel($FF843, $u3aKG, $BnYoa, $BYNn7); goto heiAz; heiAz: return $this->optionItems($FF843, $u3aKG, $RwQHi); goto fB1UQ; fB1UQ: } public function optionRepositoryTreeItems(TreeRepositoryInterface $Qdgwn, $q7MtH = 0) { $FF843 = $Qdgwn->getTreeItems($this->context); return $this->optionItems($FF843, $Qdgwn->getKeyName(), $Qdgwn->getTreeTitleColumn(), $q7MtH); } public function optionItems($FF843, $u3aKG = 'id', $RwQHi = 'title', $q7MtH = 0) { goto yHmvy; SHpbh: foreach ($FF843 as $JhHfm => $V563N) { goto ezI0z; XuA0p: $atZJ8[$V563N->{$u3aKG}] = array('label' => $F1pdf . $V563N->{$RwQHi}, 'title' => join('-', $Bejmk)); goto xQciA; sURPe: if ($V563N->_level > $Xgyaf) { array_push($Bejmk, $V563N->{$RwQHi}); } else { goto r1sU3; r1sU3: while ($V563N->_level < $Xgyaf) { array_pop($Bejmk); $Xgyaf--; } goto G8a1B; G8a1B: array_pop($Bejmk); goto fLayE; fLayE: array_push($Bejmk, $V563N->{$RwQHi}); goto VuuWo; VuuWo: } goto VB5W9; VB5W9: $Xgyaf = $V563N->_level; goto XuA0p; ezI0z: $F1pdf = TreeUtil::itemLevelPrefix($V563N->_level); goto sURPe; xQciA: } goto wJvM3; tXrZK: $Bejmk = array(); goto SHpbh; mldqi: $atZJ8[0] = L('Root'); goto s6ruU; AF9rz: $Xgyaf = 0; goto tXrZK; s6ruU: if ($q7MtH > 0) { $FF843 = $FF843->filter(function ($V563N) use($q7MtH) { return $V563N->_level <= $q7MtH - 1; }); } goto AF9rz; yHmvy: $atZJ8 = array(); goto mldqi; wJvM3: return $this->options($atZJ8); goto ktSru; ktSru: } public static function optionRemoteHandleModel($Y2RbY, $xq04r = 'id', $gYbZ7 = 'title', $pmJAc = array()) { goto WdJiQ; nstvT: $laNjB = $xaAIg->orderBy($pmJAc['sort'][0], $pmJAc['sort'][1])->limit(10)->get(array($xq04r, $gYbZ7))->toArray(); goto tloOr; rHo6F: foreach ($laNjB as $H7gaA) { $atZJ8[] = array('value' => $H7gaA[$xq04r], 'label' => $H7gaA[$gYbZ7]); } goto norhI; D_XKp: if ($ib3B9) { $xaAIg = $xaAIg->where($xq04r, $ib3B9); } goto vV8YX; vV8YX: if ($ro4O3) { $xaAIg = $xaAIg->where($gYbZ7, 'like', '%' . $ro4O3 . '%'); } goto nstvT; nbOBR: $xaAIg = ModelUtil::model($Y2RbY); goto D_XKp; mBT6J: $ib3B9 = $do_OL->getInteger('value'); goto jbMrJ; norhI: return Response::generateSuccessData(array('options' => $atZJ8)); goto MHCso; g6PZs: $do_OL = InputPackage::buildFromInput(); goto mBT6J; jbMrJ: $ro4O3 = $do_OL->getTrimString('keywords'); goto nbOBR; tloOr: $atZJ8 = array(); goto rHo6F; WdJiQ: if (!isset($pmJAc['sort'])) { $pmJAc['sort'] = array('id', 'desc'); } goto g6PZs; MHCso: } public function render() { $this->addCascadeScript(); return parent::render(); } }