<?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($Tpa5t) { $this->addVariables(array('options' => $Tpa5t)); return $this; } public function serializeType($mdHu1) { $this->addVariables(array('serializeType' => $mdHu1)); return $this; } public function optionModel($tkusQ, $CnFib = 'id', $paeUa = 'name') { return $this->options(ModelUtil::valueMap($tkusQ, $CnFib, $paeUa)); } public function optionType($EtM72) { return $this->options($EtM72::getList()); } public function unserializeValue($mdHu1, AbstractField $Mk6lP) { if (null === $mdHu1) { return $mdHu1; } switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($mdHu1); default: return ConvertUtil::toArray($mdHu1); } } public function serializeValue($mdHu1, $DRh9Q) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::array2String($mdHu1); default: if (is_array($mdHu1)) { foreach ($mdHu1 as $Fkd1C => $pk5fc) { if (is_numeric($pk5fc) && preg_match('/^\\d+$/', $pk5fc)) { $mdHu1[$Fkd1C] = intval($pk5fc); } } } return json_encode($mdHu1, JSON_UNESCAPED_UNICODE); } } public function prepareInput($mdHu1, $DRh9Q) { switch ($this->getVariable('serializeType')) { case self::SERIALIZE_TYPE_COLON_SEPARATED: return TagUtil::string2Array($mdHu1); default: return ConvertUtil::toArray($mdHu1, false); } } public function render() { $this->addCascadeScript(); return parent::render(); } }