<?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($mdHu1) { $this->columnNames['id'] = $mdHu1; return $this; } public function columnNameTitle($mdHu1) { $this->columnNames['title'] = $mdHu1; return $this; } public function columnNameChildren($mdHu1) { $this->columnNames['children'] = $mdHu1; return $this; } public function spread($mdHu1) { $this->addVariables(array('spread' => $mdHu1)); return $this; } public function unserializeValue($mdHu1, AbstractField $Mk6lP) { if (null === $mdHu1) { return $mdHu1; } return ConvertUtil::toArray($mdHu1); } public function serializeValue($mdHu1, $DRh9Q) { return json_encode($mdHu1); } public function prepareInput($mdHu1, $DRh9Q) { return ConvertUtil::toArray($mdHu1); } public function tree($fYsoz) { goto t2swZ; t2swZ: if ($fYsoz instanceof \Closure) { $fYsoz = $fYsoz($this); } goto lA3Bu; lA3Bu: $this->addVariables(array('nodes' => $this->formatNodes($fYsoz))); goto MecXj; MecXj: return $this; goto SK3Yp; SK3Yp: } private function formatNodes($fYsoz) { goto C0dMW; L_cUK: return $u5cUO; goto G2D5l; C0dMW: $u5cUO = array(); goto srqwG; srqwG: foreach ($fYsoz as $yFnpO) { goto NR_P8; v_46p: $khyGW['spread'] = $this->getVariable('spread', true); goto ZbpDS; NR_P8: $khyGW = array(); goto v_46p; kB551: if (!empty($yFnpO[$this->columnNames['children']])) { $khyGW['children'] = $this->formatNodes($yFnpO[$this->columnNames['children']]); } goto TzPsw; TzPsw: $u5cUO[] = $khyGW; goto VTwvf; SacmK: $khyGW['title'] = $yFnpO[$this->columnNames['title']]; goto kB551; ZbpDS: $khyGW['id'] = $yFnpO[$this->columnNames['id']]; goto SacmK; VTwvf: } goto L_cUK; G2D5l: } }