<?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($atZJ8) { $this->addVariables(array('options' => $atZJ8)); return $this; } public function serializeType($ib3B9) { $this->addVariables(array('serializeType' => $ib3B9)); return $this; } public function optionModel($Y2RbY, $MQulf = 'id', $nbb6p = 'name') { return $this->options(ModelUtil::valueMap($Y2RbY, $MQulf, $nbb6p)); } public function optionType($f6h3S) { return $this->options($f6h3S::getList()); } public function unserializeValue($ib3B9, AbstractField $pu1ro) { if (null === $ib3B9) { return $ib3B9; } switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($ib3B9); default: return ConvertUtil::toArray($ib3B9); } } public function serializeValue($ib3B9, $nzuw7) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::array2String($ib3B9); default: if (is_array($ib3B9)) { foreach ($ib3B9 as $F_a6B => $JiRHR) { if (is_numeric($JiRHR) && preg_match('/^\\d+$/', $JiRHR)) { $ib3B9[$F_a6B] = intval($JiRHR); } } } return json_encode($ib3B9, JSON_UNESCAPED_UNICODE); } } public function prepareInput($ib3B9, $nzuw7) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($ib3B9); default: return ConvertUtil::toArray($ib3B9, false); } } public function render() { $this->addCascadeScript(); return parent::render(); } }