<?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 ($a_uup, AbstractField $rZfgs) { $vrSVj = InputPackage::buildFromInput(); $rTniN = $vrSVj->getJson($rZfgs->column, array()); ModelUtil::relationAssign($this->getVariable('relationTable'), $this->getVariable('relationModelIdKey'), $a_uup, $this->getVariable('relationIdKey'), $rTniN); }); } public function mode($qAUbs) { $this->addVariables(array('mode' => $qAUbs)); return $this; } public function relationTable($AD05J, $JFea0, $je0se) { goto ykozp; XG3gG: $this->addVariables(array('relationIdKey' => $je0se)); goto GCzs6; GCzs6: return $this; goto iD62L; ykozp: $this->addVariables(array('relationTable' => $AD05J)); goto fhKjr; fhKjr: $this->addVariables(array('relationModelIdKey' => $JFea0)); goto XG3gG; iD62L: } public function groupTags($Dces3, $JqOyS = 'title', $rlxNh = '_child') { goto gPy3L; CO2su: $this->addVariables(array('groupTags' => $Dces3, 'groupTagsTitleKey' => $JqOyS, 'groupTagsChildKey' => $rlxNh)); goto yJa_o; gPy3L: $this->mode(self::MODE_GROUP_TAGS); goto CO2su; yJa_o: return $this; goto UM0kD; UM0kD: } public function renderView(AbstractField $rZfgs, $Esk0p, $EqYVi = 0) { goto xXijt; icdpX: if ($Esk0p) { goto DX3N3; qjrhk: $LfuzW = $rZfgs->getVariable('relationModelIdKey'); goto oHWpo; qgaWx: $rTniN = ModelUtil::values($DcDhg, $je0se, array($LfuzW => $Esk0p->id)); goto yTU61; DX3N3: $DcDhg = $rZfgs->getVariable('relationTable'); goto qjrhk; oHWpo: $je0se = $rZfgs->getVariable('relationIdKey'); goto qgaWx; yTU61: } goto yluw_; ukZnz: return parent::renderView($rZfgs, $Esk0p, $EqYVi); goto cSTMR; yluw_: $this->value($rTniN); goto ukZnz; xXijt: $rTniN = array(); goto icdpX; cSTMR: } 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_); } }