<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Field; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Util\ConvertUtil; use ModStart\Core\Util\TagUtil; class Checkbox extends AbstractField { const SERIALIZE_TYPE_DEFAULT = null; const SERIALIZE_TYPE_COLON_SEPARATED = 1; protected $value = array(); protected function setup() { $this->addVariables(array('options' => array(), 'serializeType' => null)); } public function options($X3Hkn) { $this->addVariables(array('options' => $X3Hkn)); return $this; } public function serializeType($FT9zA) { $this->addVariables(array('serializeType' => $FT9zA)); return $this; } public function optionModel($zWXdn, $ZL1Sk = 'id', $sOJld = 'name') { return $this->options(ModelUtil::valueMap($zWXdn, $ZL1Sk, $sOJld)); } public function optionType($anhu0) { return $this->options($anhu0::getList()); } 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: if (is_array($FT9zA)) { foreach ($FT9zA as $kh68j => $tHq0l) { if (is_numeric($tHq0l) && preg_match('/^\\d+$/', $tHq0l)) { $FT9zA[$kh68j] = intval($tHq0l); } } } return json_encode($FT9zA, JSON_UNESCAPED_UNICODE); } } public function prepareInput($FT9zA, $TAWWJ) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($FT9zA); default: return ConvertUtil::toArray($FT9zA); } } }