<?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($mdHu1) { $this->addVariables(array('tags' => $mdHu1)); return $this; } public function serializeType($mdHu1) { $this->addVariables(array('serializeType' => $mdHu1)); return $this; } public function serializeAsColonSeparated() { $this->serializeType(self::SERIALIZE_TYPE_COLON_SEPARATED); return $this; } public function tagType($F28aA) { return self::tags($F28aA::getList()); } public function tagModel($tkusQ, $CnFib = 'id', $paeUa = 'title') { return $this->tags(ModelUtil::valueMap($tkusQ, $CnFib, $paeUa)); } public function tagModelField($tkusQ, $Y9cYY = 'tag', $ZX6kD = null) { goto aMTXf; Kc4Zd: return $this->tags($igZ39); goto BAMDJ; aMTXf: $QX8nj = ModelUtil::values($tkusQ, $Y9cYY); goto wJYOx; pBe7D: foreach ($QX8nj as $mdHu1) { goto FLCUU; kRADg: switch ($ZX6kD) { case self::SERIALIZE_TYPE_COLON_SEPARATED: $MzwTh = TagUtil::string2Array($mdHu1); break; default: $MzwTh = ConvertUtil::toArray($mdHu1); break; } goto dkMFJ; rBhvf: foreach ($MzwTh as $pk5fc) { $igZ39[$pk5fc] = $pk5fc; } goto npFUE; dkMFJ: if (empty($MzwTh)) { continue; } goto rBhvf; FLCUU: $MzwTh = null; goto kRADg; npFUE: } goto Kc4Zd; wJYOx: $igZ39 = array(); goto pBe7D; BAMDJ: } public function unserializeValue($mdHu1, AbstractField $Mk6lP) { if (null === $mdHu1) { return $mdHu1; } switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($mdHu1); default: return ConvertUtil::toArray($mdHu1); } } public function serializeValue($mdHu1, $DRh9Q) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::array2String($mdHu1); default: return json_encode($mdHu1); } } public function prepareInput($mdHu1, $DRh9Q) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($mdHu1); default: return ConvertUtil::toArray($mdHu1); } } }