<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Field; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Util\ConvertUtil; use ModStart\Core\Util\SerializeUtil; use ModStart\Core\Util\TagUtil; class Tags extends AbstractField { const SERIALIZE_TYPE_DEFAULT = null; const SERIALIZE_TYPE_COLON_SEPARATED = 1; protected function setup() { $this->addVariables(array('tags' => array(), 'serializeType' => null)); } public function tags($HDpl6) { $this->addVariables(array('tags' => $HDpl6)); return $this; } public function serializeType($HDpl6) { $this->addVariables(array('serializeType' => $HDpl6)); return $this; } public function serializeAsColonSeparated() { $this->serializeType(self::SERIALIZE_TYPE_COLON_SEPARATED); return $this; } public function tagType($E1HRj) { return self::tags($E1HRj::getList()); } public function tagModel($wyCKK, $lwKEo = 'id', $vrWwY = 'title') { return $this->tags(ModelUtil::valueMap($wyCKK, $lwKEo, $vrWwY)); } public function tagModelField($wyCKK, $OPsU0 = 'tag', $VBrGA = null) { goto ypFeR; bQAls: $l7oqU = array(); goto fjNkS; zCzlK: return $this->tags($l7oqU); goto y9DzE; ypFeR: $c6Fiz = ModelUtil::values($wyCKK, $OPsU0); goto bQAls; fjNkS: foreach ($c6Fiz as $HDpl6) { goto X5fhT; BXf9x: if (empty($bByld)) { continue; } goto sdmX7; X5fhT: $bByld = null; goto sF7Z6; sF7Z6: switch ($VBrGA) { case self::SERIALIZE_TYPE_COLON_SEPARATED: $bByld = TagUtil::string2Array($HDpl6); break; default: $bByld = ConvertUtil::toArray($HDpl6); break; } goto BXf9x; sdmX7: foreach ($bByld as $Q0rz2) { $l7oqU[$Q0rz2] = $Q0rz2; } goto UnDeE; UnDeE: } goto zCzlK; y9DzE: } public function unserializeValue($HDpl6, AbstractField $E8QRJ) { if (null === $HDpl6) { return $HDpl6; } switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($HDpl6); default: return ConvertUtil::toArray($HDpl6); } } public function serializeValue($HDpl6, $xTADA) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::array2String($HDpl6); default: return SerializeUtil::jsonEncode($HDpl6); } } public function prepareInput($HDpl6, $xTADA) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($HDpl6); default: return ConvertUtil::toArray($HDpl6); } } }