<?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, 'nodes' => array())); } public function columnNameId($Mczr_) { $this->columnNames['id'] = $Mczr_; return $this; } public function columnNameTitle($Mczr_) { $this->columnNames['title'] = $Mczr_; return $this; } public function columnNameChildren($Mczr_) { $this->columnNames['children'] = $Mczr_; return $this; } public function spread($Mczr_) { $this->addVariables(array('spread' => $Mczr_)); return $this; } public function unserializeValue($Mczr_, AbstractField $rZfgs) { if (null === $Mczr_) { return $Mczr_; } return ConvertUtil::toArray($Mczr_); } public function serializeValue($Mczr_, $vn_cr) { return SerializeUtil::jsonEncode($Mczr_); } public function prepareInput($Mczr_, $vn_cr) { return ConvertUtil::toArray($Mczr_); } public function tree($o1nCG) { goto X7gvE; w_EQA: return $this; goto nCnza; X7gvE: if ($o1nCG instanceof \Closure) { $o1nCG = $o1nCG($this); } goto pfj2i; pfj2i: $this->addVariables(array('nodes' => $this->formatNodes($o1nCG))); goto w_EQA; nCnza: } private function formatNodes($o1nCG) { goto HvACZ; HTFCk: foreach ($o1nCG as $Esk0p) { goto ngokq; Ds1wX: $SLm7t[] = $j_SUx; goto QikRc; tEI50: $j_SUx['spread'] = $this->getVariable('spread', true); goto CvG7T; CvG7T: $j_SUx['id'] = $Esk0p[$this->columnNames['id']]; goto SVYj5; S6HhY: if (!empty($Esk0p[$this->columnNames['children']])) { $j_SUx['children'] = $this->formatNodes($Esk0p[$this->columnNames['children']]); } goto Ds1wX; ngokq: $j_SUx = array(); goto tEI50; SVYj5: $j_SUx['title'] = $Esk0p[$this->columnNames['title']]; goto S6HhY; QikRc: } goto rjyKl; rjyKl: return $SLm7t; goto TNhuy; HvACZ: $SLm7t = array(); goto HTFCk; TNhuy: } }