<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Field; use ModStart\Core\Util\ConvertUtil; 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, 'nodes' => array())); } public function columnNameId($gwXrh) { $this->columnNames['id'] = $gwXrh; return $this; } public function columnNameTitle($gwXrh) { $this->columnNames['title'] = $gwXrh; return $this; } public function columnNameChildren($gwXrh) { $this->columnNames['children'] = $gwXrh; return $this; } public function spread($gwXrh) { $this->addVariables(array('spread' => $gwXrh)); return $this; } public function unserializeValue($gwXrh, AbstractField $VWt5t) { if (null === $gwXrh) { return $gwXrh; } return ConvertUtil::toArray($gwXrh); } public function serializeValue($gwXrh, $uV19D) { return json_encode($gwXrh); } public function prepareInput($gwXrh, $uV19D) { return ConvertUtil::toArray($gwXrh); } public function tree($FS2LC) { goto nfSa5; nfSa5: if ($FS2LC instanceof \Closure) { $FS2LC = $FS2LC($this); } goto yYQQO; PKaTI: return $this; goto hCqVU; yYQQO: $this->addVariables(array('nodes' => $this->formatNodes($FS2LC))); goto PKaTI; hCqVU: } private function formatNodes($FS2LC) { goto l3E7u; W1KU1: foreach ($FS2LC as $nsWl0) { goto zWHvl; GmdDC: $ss2rF['id'] = $nsWl0[$this->columnNames['id']]; goto jlWok; HpZDY: $ss2rF['spread'] = $this->getVariable('spread', true); goto GmdDC; SQ54z: if (!empty($nsWl0[$this->columnNames['children']])) { $ss2rF['children'] = $this->formatNodes($nsWl0[$this->columnNames['children']]); } goto ZbTuC; jlWok: $ss2rF['title'] = $nsWl0[$this->columnNames['title']]; goto SQ54z; ZbTuC: $UAm9P[] = $ss2rF; goto WYXuz; zWHvl: $ss2rF = array(); goto HpZDY; WYXuz: } goto FyPNi; l3E7u: $UAm9P = array(); goto W1KU1; FyPNi: return $UAm9P; goto VX6ZA; VX6ZA: } }