<?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($C87JF) { $this->addVariables(array('options' => $C87JF)); return $this; } public function serializeType($gwXrh) { $this->addVariables(array('serializeType' => $gwXrh)); return $this; } public function optionModel($Beeb4, $bZCgI = 'id', $sb8RM = 'name') { return $this->options(ModelUtil::valueMap($Beeb4, $bZCgI, $sb8RM)); } public function optionType($sqwo8) { return $this->options($sqwo8::getList()); } 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: if (is_array($gwXrh)) { foreach ($gwXrh as $GBNIv => $VFelt) { if (is_numeric($VFelt) && preg_match('/^\\d+$/', $VFelt)) { $gwXrh[$GBNIv] = intval($VFelt); } } } return json_encode($gwXrh, JSON_UNESCAPED_UNICODE); } } public function prepareInput($gwXrh, $uV19D) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($gwXrh); default: return ConvertUtil::toArray($gwXrh, false); } } public function render() { $this->addCascadeScript(); return parent::render(); } }