<?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($gwXrh) { $this->addVariables(array('tags' => $gwXrh)); return $this; } public function serializeType($gwXrh) { $this->addVariables(array('serializeType' => $gwXrh)); return $this; } public function serializeAsColonSeparated() { $this->serializeType(self::SERIALIZE_TYPE_COLON_SEPARATED); return $this; } public function tagType($XcezL) { return self::tags($XcezL::getList()); } public function tagModel($Beeb4, $bZCgI = 'id', $sb8RM = 'title') { return $this->tags(ModelUtil::valueMap($Beeb4, $bZCgI, $sb8RM)); } public function tagModelField($Beeb4, $D2ab4 = 'tag', $yVew1 = null) { goto YZ2fU; Y7PJL: $UcFa2 = array(); goto qwxlT; YZ2fU: $i5Ynu = ModelUtil::values($Beeb4, $D2ab4); goto Y7PJL; nRmvx: return $this->tags($UcFa2); goto GWtyi; qwxlT: foreach ($i5Ynu as $gwXrh) { goto o9dos; x7WaV: foreach ($qv2N0 as $VFelt) { $UcFa2[$VFelt] = $VFelt; } goto qFBEl; o9dos: $qv2N0 = null; goto MP8Nr; MP8Nr: switch ($yVew1) { case self::SERIALIZE_TYPE_COLON_SEPARATED: $qv2N0 = TagUtil::string2Array($gwXrh); break; default: $qv2N0 = ConvertUtil::toArray($gwXrh); break; } goto A1Qtw; A1Qtw: if (empty($qv2N0)) { continue; } goto x7WaV; qFBEl: } goto nRmvx; GWtyi: } public function unserializeValue($gwXrh, AbstractField $VWt5t) { if (null === $gwXrh) { return $gwXrh; } switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($gwXrh); default: return ConvertUtil::toArray($gwXrh); } } public function serializeValue($gwXrh, $uV19D) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::array2String($gwXrh); default: return json_encode($gwXrh); } } public function prepareInput($gwXrh, $uV19D) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($gwXrh); default: return ConvertUtil::toArray($gwXrh); } } }