<?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($wvO30) { $this->addVariables(array('tags' => $wvO30)); return $this; } public function serializeType($wvO30) { $this->addVariables(array('serializeType' => $wvO30)); return $this; } public function serializeAsColonSeparated() { $this->serializeType(self::SERIALIZE_TYPE_COLON_SEPARATED); return $this; } public function tagType($FDNZs) { return self::tags($FDNZs::getList()); } public function tagModel($oAD_e, $aKi50 = 'id', $TcL6O = 'title') { return $this->tags(ModelUtil::valueMap($oAD_e, $aKi50, $TcL6O)); } public function tagModelField($oAD_e, $e5_gx = 'tag', $e7uEj = null) { goto KEuvL; p3E2x: $rtKBf = array(); goto pH1b2; KEuvL: $kB0Us = ModelUtil::values($oAD_e, $e5_gx); goto p3E2x; uQ354: return $this->tags($rtKBf); goto mthz8; pH1b2: foreach ($kB0Us as $wvO30) { goto S5zzX; S5zzX: $x6tf1 = null; goto yw1LF; i1FzC: foreach ($x6tf1 as $uTz0e) { $rtKBf[$uTz0e] = $uTz0e; } goto hIvIT; yw1LF: switch ($e7uEj) { case self::SERIALIZE_TYPE_COLON_SEPARATED: $x6tf1 = TagUtil::string2Array($wvO30); break; default: $x6tf1 = ConvertUtil::toArray($wvO30); break; } goto LfKHQ; LfKHQ: if (empty($x6tf1)) { continue; } goto i1FzC; hIvIT: } goto uQ354; mthz8: } public function unserializeValue($wvO30, AbstractField $Lgjfa) { if (null === $wvO30) { return $wvO30; } switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($wvO30); default: return ConvertUtil::toArray($wvO30); } } public function serializeValue($wvO30, $w5oww) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::array2String($wvO30); default: return json_encode($wvO30); } } public function prepareInput($wvO30, $w5oww) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($wvO30); default: return ConvertUtil::toArray($wvO30); } } }