<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Field; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Util\ConvertUtil; 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($Gttsd) { $this->addVariables(array('tags' => $Gttsd)); return $this; } public function serializeType($Gttsd) { $this->addVariables(array('serializeType' => $Gttsd)); return $this; } public function serializeAsColonSeparated() { $this->serializeType(self::SERIALIZE_TYPE_COLON_SEPARATED); return $this; } public function tagType($aHcWY) { return self::tags($aHcWY::getList()); } public function tagModel($wt8xl, $AWXu8 = 'id', $mfJsz = 'title') { return $this->tags(ModelUtil::valueMap($wt8xl, $AWXu8, $mfJsz)); } public function tagModelField($wt8xl, $PsC5y = 'tag', $ECjl5 = null) { goto dFB44; dFB44: $q2nIJ = ModelUtil::values($wt8xl, $PsC5y); goto RhP3N; JVcKO: return $this->tags($Cl9Wv); goto ADJdj; OdUdr: foreach ($q2nIJ as $Gttsd) { goto sX0oc; RqHH0: foreach ($o_5Z8 as $F6Fus) { $Cl9Wv[$F6Fus] = $F6Fus; } goto k3zJV; sX0oc: $o_5Z8 = null; goto EG0iL; I10Fm: if (empty($o_5Z8)) { continue; } goto RqHH0; EG0iL: switch ($ECjl5) { case self::SERIALIZE_TYPE_COLON_SEPARATED: $o_5Z8 = TagUtil::string2Array($Gttsd); break; default: $o_5Z8 = ConvertUtil::toArray($Gttsd); break; } goto I10Fm; k3zJV: } goto JVcKO; RhP3N: $Cl9Wv = array(); goto OdUdr; ADJdj: } public function unserializeValue($Gttsd, AbstractField $acdQI) { if (null === $Gttsd) { return $Gttsd; } switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($Gttsd); default: return ConvertUtil::toArray($Gttsd); } } public function serializeValue($Gttsd, $BWo2e) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::array2String($Gttsd); default: return json_encode($Gttsd); } } public function prepareInput($Gttsd, $BWo2e) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($Gttsd); default: return ConvertUtil::toArray($Gttsd); } } }