<?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 ($qEXc1, AbstractField $Lgjfa) { $HoUFw = InputPackage::buildFromInput(); $kB0Us = $HoUFw->getJson($Lgjfa->column, array()); ModelUtil::relationAssign($this->getVariable('relationTable'), $this->getVariable('relationModelIdKey'), $qEXc1, $this->getVariable('relationIdKey'), $kB0Us); }); } public function mode($DtzzY) { $this->addVariables(array('mode' => $DtzzY)); return $this; } public function relationTable($oAD_e, $cu1Yn, $f2D4E) { goto Fjybs; Fjybs: $this->addVariables(array('relationTable' => $oAD_e)); goto qb3hE; CRk0V: $this->addVariables(array('relationIdKey' => $f2D4E)); goto CWLmy; qb3hE: $this->addVariables(array('relationModelIdKey' => $cu1Yn)); goto CRk0V; CWLmy: return $this; goto sTu9L; sTu9L: } public function groupTags($INaoo, $y_m2B = 'title', $rG3Uy = '_child') { goto iLPpU; iLPpU: $this->mode(self::MODE_GROUP_TAGS); goto oXPMs; jSY5x: return $this; goto qHWYZ; oXPMs: $this->addVariables(array('groupTags' => $INaoo, 'groupTagsTitleKey' => $y_m2B, 'groupTagsChildKey' => $rG3Uy)); goto jSY5x; qHWYZ: } public function renderView(AbstractField $Lgjfa, $ZpLX1, $ouMWs = 0) { goto yypF0; O_9te: if ($ZpLX1) { goto BMaum; hQnkf: $dVwqn = $Lgjfa->getVariable('relationModelIdKey'); goto bqu2e; BMaum: $NFqr7 = $Lgjfa->getVariable('relationTable'); goto hQnkf; xB9UP: $kB0Us = ModelUtil::values($NFqr7, $f2D4E, array($dVwqn => $ZpLX1->id)); goto StnLk; bqu2e: $f2D4E = $Lgjfa->getVariable('relationIdKey'); goto xB9UP; StnLk: } goto ogx2w; ogx2w: $this->value($kB0Us); goto GGxEe; yypF0: $kB0Us = array(); goto O_9te; GGxEe: return parent::renderView($Lgjfa, $ZpLX1, $ouMWs); goto YCbBH; YCbBH: } public function unserializeValue($wvO30, AbstractField $Lgjfa) { if (null === $wvO30) { return $wvO30; } return ConvertUtil::toArray($wvO30); } public function serializeValue($wvO30, $w5oww) { return json_encode($wvO30); } public function prepareInput($wvO30, $w5oww) { return ConvertUtil::toArray($wvO30); } }