<?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 $value = array(); protected function setup() { $this->addVariables(array('tags' => array(), 'serializeType' => null)); } public function tags($FT9zA) { $this->addVariables(array('tags' => $FT9zA)); return $this; } public function serializeType($FT9zA) { $this->addVariables(array('serializeType' => $FT9zA)); return $this; } public function serializeAsColonSeparated() { $this->serializeType(self::SERIALIZE_TYPE_COLON_SEPARATED); return $this; } public function tagType($bOB5d) { return self::tags($bOB5d::getList()); } public function tagModel($zWXdn, $ZL1Sk = 'id', $sOJld = 'title') { return $this->tags(ModelUtil::valueMap($zWXdn, $ZL1Sk, $sOJld)); } public function tagModelField($zWXdn, $sewZB = 'tag', $FLdDg = null) { goto UqNgt; wDanm: return $this->tags($Cntbg); goto x_GgF; UqNgt: $FO5qv = ModelUtil::values($zWXdn, $sewZB); goto jmHJC; bOj_R: foreach ($FO5qv as $FT9zA) { goto k4coE; oSEY2: switch ($FLdDg) { case self::SERIALIZE_TYPE_COLON_SEPARATED: $mrsP_ = TagUtil::string2Array($FT9zA); break; default: $mrsP_ = ConvertUtil::toArray($FT9zA); break; } goto okiVR; rzzCn: foreach ($mrsP_ as $tHq0l) { $Cntbg[$tHq0l] = $tHq0l; } goto XlAbL; k4coE: $mrsP_ = null; goto oSEY2; okiVR: if (empty($mrsP_)) { continue; } goto rzzCn; XlAbL: } goto wDanm; jmHJC: $Cntbg = array(); goto bOj_R; x_GgF: } public function unserializeValue($FT9zA, AbstractField $SQ6_6) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($FT9zA); default: return ConvertUtil::toArray($FT9zA); } } public function serializeValue($FT9zA, $TAWWJ) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::array2String($FT9zA); default: return json_encode($FT9zA); } } public function prepareInput($FT9zA, $TAWWJ) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($FT9zA); default: return ConvertUtil::toArray($FT9zA); } } }