<?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($Bodfy) { $this->addVariables(array('options' => $Bodfy)); return $this; } public function serializeType($HDpl6) { $this->addVariables(array('serializeType' => $HDpl6)); return $this; } public function optionModel($wyCKK, $lwKEo = 'id', $vrWwY = 'name') { return $this->options(ModelUtil::valueMap($wyCKK, $lwKEo, $vrWwY)); } public function optionType($nYSke) { return $this->options($nYSke::getList()); } public function unserializeValue($HDpl6, AbstractField $E8QRJ) { if (null === $HDpl6) { return $HDpl6; } switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($HDpl6); default: return ConvertUtil::toArray($HDpl6); } } public function serializeValue($HDpl6, $xTADA) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::array2String($HDpl6); default: if (is_array($HDpl6)) { foreach ($HDpl6 as $pztz4 => $Q0rz2) { if (is_numeric($Q0rz2) && preg_match('/^\\d+$/', $Q0rz2)) { $HDpl6[$pztz4] = intval($Q0rz2); } } } return SerializeUtil::jsonEncode($HDpl6); } } public function prepareInput($HDpl6, $xTADA) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($HDpl6); default: return ConvertUtil::toArray($HDpl6, false); } } public function render() { $this->addCascadeScript(); return parent::render(); } }