<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Field; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Util\ConvertUtil; use ModStart\Core\Util\SerializeUtil; 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($RKwZR) { $this->addVariables(array('options' => $RKwZR)); return $this; } public function serializeType($Mczr_) { $this->addVariables(array('serializeType' => $Mczr_)); return $this; } public function optionModel($AD05J, $eAE99 = 'id', $Qduwq = 'name') { return $this->options(ModelUtil::valueMap($AD05J, $eAE99, $Qduwq)); } public function optionType($Cs86S) { return $this->options($Cs86S::getList()); } public function unserializeValue($Mczr_, AbstractField $rZfgs) { if (null === $Mczr_) { return $Mczr_; } switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($Mczr_); default: return ConvertUtil::toArray($Mczr_); } } public function serializeValue($Mczr_, $vn_cr) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::array2String($Mczr_); default: if (is_array($Mczr_)) { foreach ($Mczr_ as $B34tD => $Xz28r) { if (is_numeric($Xz28r) && preg_match('/^\\d+$/', $Xz28r)) { $Mczr_[$B34tD] = intval($Xz28r); } } } return SerializeUtil::jsonEncode($Mczr_); } } public function prepareInput($Mczr_, $vn_cr) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($Mczr_); default: return ConvertUtil::toArray($Mczr_, false); } } public function render() { $this->addCascadeScript(); return parent::render(); } }