<?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($ib3B9) { $this->addVariables(array('tags' => $ib3B9)); return $this; } public function serializeType($ib3B9) { $this->addVariables(array('serializeType' => $ib3B9)); return $this; } public function serializeAsColonSeparated() { $this->serializeType(self::SERIALIZE_TYPE_COLON_SEPARATED); return $this; } public function tagType($gJGJ7) { return self::tags($gJGJ7::getList()); } public function tagModel($Y2RbY, $MQulf = 'id', $nbb6p = 'title') { return $this->tags(ModelUtil::valueMap($Y2RbY, $MQulf, $nbb6p)); } public function tagModelField($Y2RbY, $jM2ZE = 'tag', $UzTVN = null) { goto vFBs8; MQeoB: return $this->tags($uhujs); goto jvUuV; vFBs8: $bP0d3 = ModelUtil::values($Y2RbY, $jM2ZE); goto PVZ8U; PVZ8U: $uhujs = array(); goto Sp1x7; Sp1x7: foreach ($bP0d3 as $ib3B9) { goto qoX7I; rxB4h: if (empty($qKCWy)) { continue; } goto ze315; oLmiF: switch ($UzTVN) { case self::SERIALIZE_TYPE_COLON_SEPARATED: $qKCWy = TagUtil::string2Array($ib3B9); break; default: $qKCWy = ConvertUtil::toArray($ib3B9); break; } goto rxB4h; ze315: foreach ($qKCWy as $JiRHR) { $uhujs[$JiRHR] = $JiRHR; } goto rrats; qoX7I: $qKCWy = null; goto oLmiF; rrats: } goto MQeoB; jvUuV: } public function unserializeValue($ib3B9, AbstractField $pu1ro) { if (null === $ib3B9) { return $ib3B9; } switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($ib3B9); default: return ConvertUtil::toArray($ib3B9); } } public function serializeValue($ib3B9, $nzuw7) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::array2String($ib3B9); default: return json_encode($ib3B9); } } public function prepareInput($ib3B9, $nzuw7) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($ib3B9); default: return ConvertUtil::toArray($ib3B9); } } }