BcFreezeHelper::freezeControll PHP Method

freezeControll() public method

凍結時用のコントロールを取得する
public freezeControll ( string $fieldName, array $options, array $attributes = [] ) : string
$fieldName string フィールド文字列
$options array コントロールソース
$attributes array html属性
return string htmlタグ
    public function freezeControll($fieldName, $options, $attributes = array())
    {
        $attributes = array_merge(array('class' => ''), $attributes);
        unset($attributes["separator"]);
        if (preg_match_all("/\\./", $fieldName, $regs) == 2) {
            list($model, $field, $detail) = explode('.', $fieldName);
        } else {
            list($model, $field) = explode('.', $fieldName);
        }
        // 値を取得
        if (isset($attributes["value"])) {
            $value = $attributes["value"];
        } else {
            // HABTAM
            if (!empty($attributes["multiple"]) && $attributes["multiple"] !== 'checkbox') {
                $value = $this->request->data[$model];
            } else {
                if (!empty($this->request->data[$model][$field])) {
                    $value = $this->request->data[$model][$field];
                } else {
                    $value = null;
                }
            }
        }
        // optionsによるソース有 「0」は通す
        if ($options && $value !== '' && !is_null($value)) {
            // HABTAM
            if (!empty($attributes["multiple"]) && $attributes["multiple"] !== 'checkbox') {
                $_value = "";
                foreach ($value as $data) {
                    if (isset($options[$data['id']])) {
                        $_value .= sprintf($this->Html->_tags['li'], null, $options[$data['id']]);
                    }
                }
                $value = sprintf($this->Html->_tags['ul'], " " . $this->_parseAttributes($attributes, null, '', ' '), $_value);
                $out = parent::hidden($fieldName, $attributes) . $value;
                // マルチチェック
            } elseif (!empty($attributes["multiple"]) && $attributes["multiple"] === 'checkbox') {
                $_value = "";
                foreach ($value as $key => $data) {
                    if (isset($options[$data])) {
                        $_value .= sprintf($this->Html->_tags['li'], null, $options[$data]);
                    }
                }
                $out = sprintf($this->Html->_tags['ul'], " " . $this->_parseAttributes($attributes, null, '', ' '), $_value);
                $out .= $this->hidden($fieldName, array('value' => $value, 'multiple' => true));
                // 一般
            } elseif (empty($detail)) {
                if (isset($options[$value])) {
                    $value = $options[$value];
                } else {
                    $value = '';
                }
                $out = parent::hidden($fieldName, $attributes) . $value;
                // datetime
            } else {
                if ($value[$detail]) {
                    $value = $options[$value[$detail]];
                } else {
                    $value = "";
                }
                $out = parent::hidden($fieldName, $attributes) . $value;
            }
            // 値なし
        } else {
            if ($options) {
                if (!$value && !empty($options[0])) {
                    $value = $options[0];
                } else {
                    $value = "";
                }
            } elseif (empty($detail)) {
                if (!empty($value)) {
                    $value = $value;
                } else {
                    $value = null;
                }
            } elseif (is_array($value) && isset($value[$detail])) {
                $value = $value[$detail];
            }
            $out = parent::hidden($fieldName, $attributes) . $value;
        }
        return $out;
    }