<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Field; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Input\InputPackage; use ModStart\Core\Util\ConvertUtil; use ModStart\Core\Util\SerializeUtil; 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 ($qZPOw, AbstractField $Ldet7) { $vfMTB = InputPackage::buildFromInput(); $aJd3g = $vfMTB->getJson($Ldet7->column, array()); ModelUtil::relationAssign($this->getVariable('relationTable'), $this->getVariable('relationModelIdKey'), $qZPOw, $this->getVariable('relationIdKey'), $aJd3g); }); } public function mode($qOE89) { $this->addVariables(array('mode' => $qOE89)); return $this; } public function relationTable($loNjC, $eg1hx, $sBeOR) { goto NwCfB; NwCfB: $this->addVariables(array('relationTable' => $loNjC)); goto Z0NaI; orLYo: $this->addVariables(array('relationIdKey' => $sBeOR)); goto l78qL; l78qL: return $this; goto lHQB2; Z0NaI: $this->addVariables(array('relationModelIdKey' => $eg1hx)); goto orLYo; lHQB2: } public function groupTags($t0i8a, $n53f8 = 'title', $aqPG3 = '_child') { goto bMD2a; G3kow: return $this; goto QwDD_; yBtiX: $this->addVariables(array('groupTags' => $t0i8a, 'groupTagsTitleKey' => $n53f8, 'groupTagsChildKey' => $aqPG3)); goto G3kow; bMD2a: $this->mode(self::MODE_GROUP_TAGS); goto yBtiX; QwDD_: } public function renderView(AbstractField $Ldet7, $P1uVJ, $C6OV7 = 0) { goto AlR33; bN6Er: if ($P1uVJ) { goto i0eVo; qQPHN: $cdJac = $Ldet7->getVariable('relationModelIdKey'); goto O20JB; O20JB: $sBeOR = $Ldet7->getVariable('relationIdKey'); goto pB5t5; pB5t5: $aJd3g = ModelUtil::values($W3Mx6, $sBeOR, array($cdJac => $P1uVJ->id)); goto RObBi; i0eVo: $W3Mx6 = $Ldet7->getVariable('relationTable'); goto qQPHN; RObBi: } goto HY1ck; HY1ck: $this->value($aJd3g); goto QP00u; AlR33: $aJd3g = array(); goto bN6Er; QP00u: return parent::renderView($Ldet7, $P1uVJ, $C6OV7); goto lYFi1; lYFi1: } public function unserializeValue($cBDsM, AbstractField $Ldet7) { if (null === $cBDsM) { return $cBDsM; } return ConvertUtil::toArray($cBDsM); } public function serializeValue($cBDsM, $GMqtO) { return SerializeUtil::jsonEncode($cBDsM); } public function prepareInput($cBDsM, $GMqtO) { return ConvertUtil::toArray($cBDsM); } }