<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Field; use ModStart\Core\Util\ConvertUtil; use ModStart\Core\Util\SerializeUtil; use ModStart\Field\Type\FieldRenderMode; class Tree extends AbstractField { private $columnNames = array('id' => 'id', 'title' => 'title', 'children' => '_child'); protected function setup() { $this->addVariables(array('spread' => true, 'independentEnable' => false, 'nodes' => array())); } public function columnNameId($cBDsM) { $this->columnNames['id'] = $cBDsM; return $this; } public function columnNameTitle($cBDsM) { $this->columnNames['title'] = $cBDsM; return $this; } public function columnNameChildren($cBDsM) { $this->columnNames['children'] = $cBDsM; return $this; } public function spread($cBDsM) { $this->addVariables(array('spread' => $cBDsM)); return $this; } public function independentEnable($uQg0u) { $this->addVariables(array('independentEnable' => $uQg0u)); return $this; } public function unserializeValue($cBDsM, AbstractField $Ldet7) { if (null === $cBDsM) { return $cBDsM; } return ConvertUtil::toArray($cBDsM); } public function serializeValue($cBDsM, $GMqtO) { return SerializeUtil::jsonEncode($cBDsM); } public function prepareInput($cBDsM, $GMqtO) { return ConvertUtil::toArray($cBDsM); } public function tree($wAGIP) { goto H7xjM; TsY1g: return $this; goto KgOpH; k0BOU: $this->addVariables(array('nodes' => $this->formatNodes($wAGIP))); goto TsY1g; H7xjM: if ($wAGIP instanceof \Closure) { $wAGIP = $wAGIP($this); } goto k0BOU; KgOpH: } private function formatNodes($wAGIP) { goto rdniS; DspAY: foreach ($wAGIP as $P1uVJ) { goto dROuv; FgbLB: $XZE7S['title'] = $P1uVJ[$this->columnNames['title']]; goto YN4KK; DPyHu: $XZE7S['id'] = $P1uVJ[$this->columnNames['id']]; goto FgbLB; YN4KK: if (!empty($P1uVJ[$this->columnNames['children']])) { $XZE7S['children'] = $this->formatNodes($P1uVJ[$this->columnNames['children']]); } goto K6f9g; K6f9g: $foy7G[] = $XZE7S; goto xmahL; dROuv: $XZE7S = array(); goto WxhBu; WxhBu: $XZE7S['spread'] = $this->getVariable('spread', true); goto DPyHu; xmahL: } goto X3bhu; rdniS: $foy7G = array(); goto DspAY; X3bhu: return $foy7G; goto fqnFO; fqnFO: } }