<?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($X3Hkn) { $this->addVariables(array('options' => $X3Hkn)); return $this; } public function optionsValue($X3Hkn) { $this->addVariables(array('options' => array_build($X3Hkn, function ($kh68j, $tHq0l) { return array($tHq0l, $tHq0l); }))); return $this; } public function optionArray($X3Hkn, $vxAjc = 'id', $sDsFk = 'title') { $X3Hkn = array_build($X3Hkn, function ($kh68j, $tHq0l) use($vxAjc, $sDsFk) { return array($tHq0l[$vxAjc], $tHq0l[$sDsFk]); }); return $this->options($X3Hkn); } public function onValueChangeJsFunction($v5rbI) { $this->addVariables(array('onValueChangeJsFunction' => $v5rbI)); return $this; } public function optionType($ac3f3) { return $this->options($ac3f3::getList()); } public function optionModel($zWXdn, $ZL1Sk = 'id', $sOJld = 'name', $g09Lt = array()) { return $this->options(ModelUtil::valueMap($zWXdn, $ZL1Sk, $sOJld, $g09Lt)); } public function optionModelTree($zWXdn, $vxAjc = 'id', $abtJP = 'pid', $sDsFk = 'title', $e908H = 'sort', $g09Lt = array()) { goto s2fDr; s2fDr: $H8W5c = ModelUtil::model($zWXdn)->where($g09Lt)->get(array($vxAjc, $abtJP, $sDsFk, $e908H)); goto p_Dw3; p_Dw3: $H8W5c = TreeUtil::itemsMergeLevel($H8W5c, $vxAjc, $abtJP, $e908H); goto IyfaJ; IyfaJ: return $this->optionItems($H8W5c, $vxAjc, $sDsFk); goto LDAFs; LDAFs: } public function optionRepositoryTreeItems(TreeRepositoryInterface $lZ6bd, $uzlmR = 0) { $H8W5c = $lZ6bd->getTreeItems($this->context); return $this->optionItems($H8W5c, $lZ6bd->getKeyName(), $lZ6bd->getTreeTitleColumn(), $uzlmR); } public function optionItems($H8W5c, $vxAjc = 'id', $sDsFk = 'title', $uzlmR = 0) { goto lgJZK; sCa9W: $X3Hkn[0] = L('Root'); goto LafXq; GRmXp: return $this->options($X3Hkn); goto zJqPr; LafXq: foreach ($H8W5c as $eQWJY => $El_MH) { if ($uzlmR > 0) { if ($El_MH->_level > $uzlmR - 1) { continue; } } $X3Hkn[$El_MH->{$vxAjc}] = str_repeat('├', $El_MH->_level) . $El_MH->{$sDsFk}; } goto GRmXp; lgJZK: $X3Hkn = array(); goto sCa9W; zJqPr: } public function render() { $this->addCascadeScript(); return parent::render(); } }