<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Field; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Input\InputPackage; use ModStart\Core\Util\ConvertUtil; class ManyRelation extends AbstractField { const MODE_GROUP_TAGS = 'groupTags'; protected $isCustomField = true; protected $defaultValue = array(); protected function setup() { $this->addVariables(array('relationTable' => '', 'relationModelIdKey' => '', 'relationIdKey' => '', 'mode' => self::MODE_GROUP_TAGS, 'groupTags' => array(), 'groupTagsTitleKey' => 'title', 'groupTagsChildKey' => '_child')); $this->hookValueSaved(function ($ifioB, AbstractField $Mk6lP) { $TG2we = InputPackage::buildFromInput(); $QX8nj = $TG2we->getJson($Mk6lP->column, array()); ModelUtil::relationAssign($this->getVariable('relationTable'), $this->getVariable('relationModelIdKey'), $ifioB, $this->getVariable('relationIdKey'), $QX8nj); }); } public function mode($lZlEV) { $this->addVariables(array('mode' => $lZlEV)); return $this; } public function relationTable($tkusQ, $gDAsd, $icZ4M) { goto bgz1f; c6Wfo: $this->addVariables(array('relationIdKey' => $icZ4M)); goto txmvv; teLJB: $this->addVariables(array('relationModelIdKey' => $gDAsd)); goto c6Wfo; txmvv: return $this; goto JmP09; bgz1f: $this->addVariables(array('relationTable' => $tkusQ)); goto teLJB; JmP09: } public function groupTags($JXw2O, $P_D9V = 'title', $fBmcA = '_child') { goto J9nb0; mkZkj: $this->addVariables(array('groupTags' => $JXw2O, 'groupTagsTitleKey' => $P_D9V, 'groupTagsChildKey' => $fBmcA)); goto reDAq; J9nb0: $this->mode(self::MODE_GROUP_TAGS); goto mkZkj; reDAq: return $this; goto Oci0U; Oci0U: } public function renderView(AbstractField $Mk6lP, $yFnpO, $dtpXv = 0) { goto J0Rgn; zTvo5: if ($yFnpO) { goto JnVZY; hCjnH: $QX8nj = ModelUtil::values($FaD3p, $icZ4M, array($awm6i => $yFnpO->id)); goto Nhe26; YnPmr: $awm6i = $Mk6lP->getVariable('relationModelIdKey'); goto P5FkF; JnVZY: $FaD3p = $Mk6lP->getVariable('relationTable'); goto YnPmr; P5FkF: $icZ4M = $Mk6lP->getVariable('relationIdKey'); goto hCjnH; Nhe26: } goto HoSDV; J0Rgn: $QX8nj = array(); goto zTvo5; HoSDV: $this->value($QX8nj); goto UjB2H; UjB2H: return parent::renderView($Mk6lP, $yFnpO, $dtpXv); goto tHcSj; tHcSj: } 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); } }