<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Field; use ModStart\Core\Dao\ModelUtil; 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' => '')); } public function options($H02oa) { $this->addVariables(array('options' => $H02oa)); return $this; } public function optionArray($H02oa, $W6kMz = 'id', $R93Q2 = 'title') { $H02oa = array_build($H02oa, function ($U9AsU, $ohYVl) use($W6kMz, $R93Q2) { return array($ohYVl[$W6kMz], $ohYVl[$R93Q2]); }); return $this->options($H02oa); } public function onValueChangeJsFunction($Zb8sp) { $this->addVariables(array('onValueChangeJsFunction' => $Zb8sp)); return $this; } public function optionType($c37e9) { return $this->options($c37e9::getList()); } public function optionModel($I1hTb, $kkQsP = 'id', $Zmb65 = 'name', $ArzOE = array()) { return $this->options(ModelUtil::valueMap($I1hTb, $kkQsP, $Zmb65, $ArzOE)); } public function optionModelTree($I1hTb, $W6kMz = 'id', $xwwNA = 'pid', $R93Q2 = 'title', $n6_tY = 'sort', $ArzOE = array()) { goto a0OgD; a0OgD: $Ayu2S = ModelUtil::model($I1hTb)->where($ArzOE)->get(array($W6kMz, $xwwNA, $R93Q2, $n6_tY)); goto Hy8O2; Hy8O2: $Ayu2S = TreeUtil::itemsMergeLevel($Ayu2S, $W6kMz, $xwwNA, $n6_tY); goto ODTXp; ODTXp: return $this->optionItems($Ayu2S, $W6kMz, $R93Q2); goto XjIla; XjIla: } public function optionRepositoryTreeItems(TreeRepositoryInterface $a_UAg, $uVezX = 0) { $Ayu2S = $a_UAg->getTreeItems(); return $this->optionItems($Ayu2S, $a_UAg->getKeyName(), $a_UAg->getTreeTitleColumn(), $uVezX); } public function optionItems($Ayu2S, $W6kMz = 'id', $R93Q2 = 'title', $uVezX = 0) { goto Up2o0; Up2o0: $H02oa = array(); goto VuBSl; VuBSl: $H02oa[0] = L('Root'); goto TDr31; nL5sI: return $this->options($H02oa); goto RGe1K; TDr31: foreach ($Ayu2S as $K3Ni_ => $Nrp0b) { if ($uVezX > 0) { if ($Nrp0b->_level > $uVezX - 1) { continue; } } $H02oa[$Nrp0b->{$W6kMz}] = str_repeat('├', $Nrp0b->_level) . $Nrp0b->{$R93Q2}; } goto nL5sI; RGe1K: } public function render() { $this->addCascadeScript(); return parent::render(); } }