<?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($Mczr_) { $this->addVariables(array('tags' => $Mczr_)); return $this; } public function serializeType($Mczr_) { $this->addVariables(array('serializeType' => $Mczr_)); return $this; } public function serializeAsColonSeparated() { $this->serializeType(self::SERIALIZE_TYPE_COLON_SEPARATED); return $this; } public function tagType($pW0Nz) { return self::tags($pW0Nz::getList()); } public function tagModel($AD05J, $eAE99 = 'id', $Qduwq = 'title') { return $this->tags(ModelUtil::valueMap($AD05J, $eAE99, $Qduwq)); } public function tagModelField($AD05J, $Ah7Do = 'tag', $earrS = null) { goto Nr4le; Nr4le: $rTniN = ModelUtil::values($AD05J, $Ah7Do); goto ftK1H; IXONp: return $this->tags($GcUxl); goto M6Xi2; ftK1H: $GcUxl = array(); goto MnZbi; MnZbi: foreach ($rTniN as $Mczr_) { goto e7SYY; l8wjJ: switch ($earrS) { case self::SERIALIZE_TYPE_COLON_SEPARATED: $ubwvs = TagUtil::string2Array($Mczr_); break; default: $ubwvs = ConvertUtil::toArray($Mczr_); break; } goto GX42E; GX42E: if (empty($ubwvs)) { continue; } goto eMELv; eMELv: foreach ($ubwvs as $Xz28r) { $GcUxl[$Xz28r] = $Xz28r; } goto F4wFN; e7SYY: $ubwvs = null; goto l8wjJ; F4wFN: } goto IXONp; M6Xi2: } public function unserializeValue($Mczr_, AbstractField $rZfgs) { if (null === $Mczr_) { return $Mczr_; } switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($Mczr_); default: return ConvertUtil::toArray($Mczr_); } } public function serializeValue($Mczr_, $vn_cr) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::array2String($Mczr_); default: return SerializeUtil::jsonEncode($Mczr_); } } public function prepareInput($Mczr_, $vn_cr) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($Mczr_); default: return ConvertUtil::toArray($Mczr_); } } }