<?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($cBDsM) { $this->addVariables(array('tags' => $cBDsM)); return $this; } public function serializeType($cBDsM) { $this->addVariables(array('serializeType' => $cBDsM)); return $this; } public function serializeAsColonSeparated() { $this->serializeType(self::SERIALIZE_TYPE_COLON_SEPARATED); return $this; } public function tagType($BYzWI) { return self::tags($BYzWI::getList()); } public function tagModel($loNjC, $WoS8y = 'id', $tYSg7 = 'title') { return $this->tags(ModelUtil::valueMap($loNjC, $WoS8y, $tYSg7)); } public function tagModelField($loNjC, $DmgEj = 'tag', $KQb10 = null) { goto UmzR9; JkbPY: foreach ($aJd3g as $cBDsM) { goto OzbdN; Q7ohu: if (empty($eh8Bj)) { continue; } goto UToMs; OzbdN: $eh8Bj = null; goto ymNlH; UToMs: foreach ($eh8Bj as $knQyJ) { $DEha7[$knQyJ] = $knQyJ; } goto YSCfF; ymNlH: switch ($KQb10) { case self::SERIALIZE_TYPE_COLON_SEPARATED: $eh8Bj = TagUtil::string2Array($cBDsM); break; default: $eh8Bj = ConvertUtil::toArray($cBDsM); break; } goto Q7ohu; YSCfF: } goto geu8a; UmzR9: $aJd3g = ModelUtil::values($loNjC, $DmgEj); goto WlByS; geu8a: return $this->tags($DEha7); goto MwQJr; WlByS: $DEha7 = array(); goto JkbPY; MwQJr: } public function unserializeValue($cBDsM, AbstractField $Ldet7) { if (null === $cBDsM) { return $cBDsM; } switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($cBDsM); default: return ConvertUtil::toArray($cBDsM); } } public function serializeValue($cBDsM, $GMqtO) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::array2String($cBDsM); default: return SerializeUtil::jsonEncode($cBDsM); } } public function prepareInput($cBDsM, $GMqtO) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($cBDsM); default: return ConvertUtil::toArray($cBDsM); } } }