<?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($wvO30) { $this->addVariables(array('selectSearch' => $wvO30)); return $this; } public function selectRemote($wvO30) { $this->addVariables(array('selectRemote' => $wvO30)); return $this; } public function options($ZNmAK) { $this->addVariables(array('options' => $ZNmAK)); return $this; } public function optionsValue($ZNmAK) { $this->addVariables(array('options' => array_build($ZNmAK, function ($plrwN, $uTz0e) { return array($uTz0e, $uTz0e); }))); return $this; } public function optionArray($ZNmAK, $KgjGp = 'id', $Xm9M0 = 'title') { $ZNmAK = array_build($ZNmAK, function ($plrwN, $uTz0e) use($KgjGp, $Xm9M0) { return array($uTz0e[$KgjGp], $uTz0e[$Xm9M0]); }); return $this->options($ZNmAK); } public function onValueChangeJsFunction($Ss4zK) { $this->addVariables(array('onValueChangeJsFunction' => $Ss4zK)); return $this; } public function optionType($q5sLX) { return $this->options($q5sLX::getList()); } public function optionModel($oAD_e, $aKi50 = 'id', $TcL6O = 'name', $AMnOB = array()) { return $this->options(ModelUtil::valueMap($oAD_e, $aKi50, $TcL6O, $AMnOB)); } public function optionModelTree($oAD_e, $KgjGp = 'id', $gFVW4 = 'pid', $Xm9M0 = 'title', $uHXOC = 'sort', $AMnOB = array()) { goto of1Y7; of1Y7: $aSut7 = ModelUtil::autoModel($oAD_e)->where($AMnOB)->get(array($KgjGp, $gFVW4, $Xm9M0, $uHXOC)); goto gx7jI; gx7jI: $aSut7 = TreeUtil::itemsMergeLevel($aSut7, $KgjGp, $gFVW4, $uHXOC); goto ZF0z1; ZF0z1: return $this->optionItems($aSut7, $KgjGp, $Xm9M0); goto UW_LG; UW_LG: } public function optionRepositoryTreeItems(TreeRepositoryInterface $quOXO, $OSZqq = 0) { $aSut7 = $quOXO->getTreeItems($this->context); return $this->optionItems($aSut7, $quOXO->getKeyName(), $quOXO->getTreeTitleColumn(), $OSZqq); } public function optionItems($aSut7, $KgjGp = 'id', $Xm9M0 = 'title', $OSZqq = 0) { goto u37tw; AcF__: $IY5T6 = 0; goto s7Oo_; s7Oo_: $Zbk3F = array(); goto ajYXd; u37tw: $ZNmAK = array(); goto i_iQE; i_iQE: $ZNmAK[0] = L('Root'); goto FSzat; ajYXd: foreach ($aSut7 as $UCcmA => $ZpLX1) { goto WIWbe; N_NXq: $IY5T6 = $ZpLX1->_level; goto zx3lP; zx3lP: $ZNmAK[$ZpLX1->{$KgjGp}] = array('label' => $sGiaY . $ZpLX1->{$Xm9M0}, 'title' => join('-', $Zbk3F)); goto yzQTN; DWOB_: if ($ZpLX1->_level > $IY5T6) { array_push($Zbk3F, $ZpLX1->{$Xm9M0}); } else { goto qf3YB; qf3YB: while ($ZpLX1->_level < $IY5T6) { array_pop($Zbk3F); $IY5T6--; } goto DlS4i; DlS4i: array_pop($Zbk3F); goto jgoSb; jgoSb: array_push($Zbk3F, $ZpLX1->{$Xm9M0}); goto FZnB_; FZnB_: } goto N_NXq; WIWbe: $sGiaY = TreeUtil::itemLevelPrefix($ZpLX1->_level); goto DWOB_; yzQTN: } goto Zfhl_; Zfhl_: return $this->options($ZNmAK); goto epIBp; FSzat: if ($OSZqq > 0) { $aSut7 = $aSut7->filter(function ($ZpLX1) use($OSZqq) { return $ZpLX1->_level <= $OSZqq - 1; }); } goto AcF__; epIBp: } public static function optionRemoteHandleModel($oAD_e, $tPnOV = 'id', $rK_k5 = 'title', $oK4I3 = array()) { goto lEu18; mVEd5: if ($hnXpY) { $hAzJ1 = $hAzJ1->where($rK_k5, 'like', '%' . $hnXpY . '%'); } goto POaR5; ECAHp: return Response::generateSuccessData(array('options' => $ZNmAK)); goto AwqHX; P_hnO: $wvO30 = $HoUFw->getInteger('value'); goto LCPrf; POaR5: $J2nWJ = $hAzJ1->orderBy($oK4I3['sort'][0], $oK4I3['sort'][1])->limit(10)->get(array($tPnOV, $rK_k5))->toArray(); goto Qm2e_; PjPp7: foreach ($J2nWJ as $FN3l1) { $ZNmAK[] = array('value' => $FN3l1[$tPnOV], 'label' => $FN3l1[$rK_k5]); } goto ECAHp; JbsDm: if ($wvO30) { $hAzJ1 = $hAzJ1->where($tPnOV, $wvO30); } goto mVEd5; Qm2e_: $ZNmAK = array(); goto PjPp7; C0xv5: $HoUFw = InputPackage::buildFromInput(); goto P_hnO; yx326: $hAzJ1 = ModelUtil::model($oAD_e); goto JbsDm; LCPrf: $hnXpY = $HoUFw->getTrimString('keywords'); goto yx326; lEu18: if (!isset($oK4I3['sort'])) { $oK4I3['sort'] = array('id', 'desc'); } goto C0xv5; AwqHX: } public function render() { $this->addCascadeScript(); return parent::render(); } }