<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Field; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Util\ConvertUtil; use ModStart\Core\Util\TagUtil; use ModStart\Field\Concern\CanCascadeFields; class Checkbox extends AbstractField { use CanCascadeFields; 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($nO0o6) { $this->addVariables(array('options' => $nO0o6)); return $this; } public function serializeType($Gttsd) { $this->addVariables(array('serializeType' => $Gttsd)); return $this; } public function optionModel($wt8xl, $AWXu8 = 'id', $mfJsz = 'name') { return $this->options(ModelUtil::valueMap($wt8xl, $AWXu8, $mfJsz)); } public function optionType($HAFOV) { return $this->options($HAFOV::getList()); } public function unserializeValue($Gttsd, AbstractField $acdQI) { if (null === $Gttsd) { return $Gttsd; } switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($Gttsd); default: return ConvertUtil::toArray($Gttsd); } } public function serializeValue($Gttsd, $BWo2e) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::array2String($Gttsd); default: if (is_array($Gttsd)) { foreach ($Gttsd as $RTHJ6 => $F6Fus) { if (is_numeric($F6Fus) && preg_match('/^\\d+$/', $F6Fus)) { $Gttsd[$RTHJ6] = intval($F6Fus); } } } return json_encode($Gttsd, JSON_UNESCAPED_UNICODE); } } public function prepareInput($Gttsd, $BWo2e) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($Gttsd); default: return ConvertUtil::toArray($Gttsd, false); } } public function render() { $this->addCascadeScript(); return parent::render(); } }