<?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($ZNmAK) { $this->addVariables(array('options' => $ZNmAK)); return $this; } public function serializeType($wvO30) { $this->addVariables(array('serializeType' => $wvO30)); return $this; } public function optionModel($oAD_e, $aKi50 = 'id', $TcL6O = 'name') { return $this->options(ModelUtil::valueMap($oAD_e, $aKi50, $TcL6O)); } public function optionType($msr_l) { return $this->options($msr_l::getList()); } public function unserializeValue($wvO30, AbstractField $Lgjfa) { if (null === $wvO30) { return $wvO30; } switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($wvO30); default: return ConvertUtil::toArray($wvO30); } } public function serializeValue($wvO30, $w5oww) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::array2String($wvO30); default: if (is_array($wvO30)) { foreach ($wvO30 as $plrwN => $uTz0e) { if (is_numeric($uTz0e) && preg_match('/^\\d+$/', $uTz0e)) { $wvO30[$plrwN] = intval($uTz0e); } } } return json_encode($wvO30, JSON_UNESCAPED_UNICODE); } } public function prepareInput($wvO30, $w5oww) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($wvO30); default: return ConvertUtil::toArray($wvO30, false); } } public function render() { $this->addCascadeScript(); return parent::render(); } }