Format expander.

@param string $field  field name
@param array  $column column configuration
164707
public function format_expander($field, $column)
    {
        if (!$this->current_row[$field]) {
            $this->current_row[$field] = $column['descr'];
        }

        // TODO:
        // reformat this using Button, once we have more advanced system to
        // bypass rendering of sub-elements.
        // $this->current_row[$field] = $this->add('Button',null,false)
        $key = $this->name.'_'.$field.'_';
        $id = $key.$this->app->normalizeName($this->model->id);
        $class = $key.'expander';

        $this->current_row_html[$field] =
            '<input type="checkbox" '.
                'class="'.$class.'" '.
                'id="'.$id.'" '.
                'rel="'.$this->app->url(
                    $column['page'] ?: './'.$field,
                    array(
                        'expander' => $field,
                        'expanded' => $this->name,
                        'cut_page' => 1,
                        // TODO: id is obsolete
                        //'id' => $this->model->id,
                        $this->columns[$field]['refid'].'_'.$this->model->id_field => $this->model->id,
                    )
                ).'" '.
            '/>'.
            '<label for="'.$id.'" style="cursor:pointer;"><a class="atk-button-small">'.
            $this->current_row[$field].'</a></label>';
    }
57236
public static function adjustColumnName($column)
    {
        if (isset(self::$columnsMap[$column])) {
            $column = self::$columnsMap[$column];
        }
        return $column;
    }
4510
public function format_float($field)
    {
        $precision = 2;
        $m = (float) $this->current_row[$field];
        $this->current_row[$field] =
            is_null($this->current_row[$field])
                ? '-'
                : number_format($m, $precision);
        $this->setTDParam($field, 'align', 'right');
        $this->setTDParam($field, 'style/white-space', 'nowrap');
    }
1090116
public function augmentColumns($gridField, &$columns)
    {
        $model = $gridField->getModelClass();
        $isModelVersioned = $model::has_extension(Versioned::class);

        // Skip if not versioned, or column already set
        if (!$isModelVersioned || $this->getColumn()) {
            return;
        }

        $matchedVersionedFields = array_intersect(
            $columns,
            $this->versionedLabelFields
        );

        if (count($matchedVersionedFields) > 0) {
            // Get first matched column
            $this->setColumn(reset($matchedVersionedFields));
        } elseif ($columns) {
            // Use first column if none of preferred matches
            $this->setColumn(reset($columns));
        }
    }
862577
private function build_fields( $fields, $columns ) {
		if ( ! isset( $fields ) ) {
			$fields = [ '*' ];
		}
		if ( is_string( $fields ) ) {
			$fields = [ $fields ];
		}
		if ( ! empty( $fields ) ) {
			foreach ( $fields as $k => $option ) {
				$key = $k;
				if ( is_int( $key ) ) {
					$key    = $option;
					$option = null;
				}
				if ( $key === '*' ) {
					if ( ! is_array( $option ) ) {
						unset ( $fields[ $k ] );
						$is_admin = is_admin() && ! $this->app->utility->doing_ajax();
						foreach ( $columns as $key => $column ) {
							if ( ! $is_admin && ! empty( $column['only_admin'] ) ) {
								continue;
							}
							$name     = $this->app->utility->array_get( $column, 'name' );
							$fields[] = $name === $key ? $name : $name . ' AS ' . $key;
						}
						continue;
					}
					$name = $key;
				} elseif ( isset( $columns[ $key ] ) ) {
					$name = $columns[ $key ]['name'];
				} else {
					$name = $key;
				}
				if ( is_array( $option ) ) {
					$group_func = $option[0];
					if ( strtoupper( $group_func ) == 'AS' ) {
						$fields[ $k ] = $name;
						if ( count( $option ) >= 2 ) {
							$fields[ $k ] .= ' AS ' . $option[1];
						}
					} else {
						$fields[ $k ] = "$group_func( $name )";
						if ( count( $option ) >= 2 ) {
							$fields[ $k ] .= ' AS ' . $option[1];
						}
					}
				} elseif ( ! isset( $option ) ) {
					$fields[ $k ] = $name === $key ? $name : $name . ' AS ' . $key;
				} else {
					$fields[ $k ] = $name . ' AS ' . $option;
				}
			}
		}
		if ( empty( $fields ) || ! is_array( $fields ) ) {
			$fields   = [];
			$is_admin = is_admin() && ! $this->app->utility->doing_ajax();
			foreach ( $columns as $key => $column ) {
				if ( ! $is_admin && ! empty( $column['only_admin'] ) ) {
					continue;
				}
				$name     = $this->app->utility->array_get( $column, 'name' );
				$fields[] = $name === $key ? $name : $name . ' AS ' . $key;
			}
		}
		empty( $fields ) and $fields = [ '*' ];
		$fields = implode( ', ', $fields );

		return $fields;
	}
267590
private function formatColumn($column)
    {
        $column = trim($column);
        /*调用系统函数时不处理*/
        if (strpos($column, '(') !== false) {
            return $column;
        }
        if (strpos($column, '.') !== false) {
            list($table, $column) = explode('.', $column);
            $table = '`' . $table . '`.';
        } else {
            $table = '';
        }
        if ($column == '*') {
            return $table . $column;
        }
        if (strpos($column, ' ') === false) {
            return $table . '`' . $column . '`';
        }
        $column = preg_replace('/[ ]+/', ' ', $column);
        $columns = explode(' ', $column);
        if (count($columns) == 3) {
            list($column, $as, $alias) = $columns;
        } else {
            list($column, $alias) = $columns;
        }
        return $table . '`' . $column . '` as `' . $alias . '`';
    }
235834
protected function normalizeFieldTypes(array &$fields)
    {
        foreach ($fields as $rkey => &$value) {
            $value['fieldname'] = $rkey;

            if ($value['type'] === 'select' && isset($value['multiple']) && $value['multiple'] === true) {
                $value['type'] = 'selectmultiple';
            }

            if (isset($this->typemap[$value['type']])) {
                $value['fieldtype'] = $this->typemap[$value['type']];
            } else {
                $value['fieldtype'] = $this->typemap['text'];
            }
        }
    }
1229188
public function formatUpdateFields(array $fields, $alias = null) {
        $columns = [];

        if ($alias) {
            $alias = $this->quote($alias) . '.';
        }

        foreach ($fields as $key => $value) {
            if ($value instanceof Expr) {
                $columns[] = $alias . $this->quote($key) . ' = ' . $this->formatExpression($value);

            } else {
                $columns[] = $alias . $this->quote($key) . ' = ?';
            }
        }

        return $columns;
    }
196447
protected function formatColumnName($column)
    {
        if (false === strpos($column, '.'))
        {
            $column = $this->_objectName . '.' . $column;
        }

        return $column;
    }
171070
private function prepareColumn(array $column)
    {
        if ($column['sql'] instanceof self) {
            [$sql, $params] = $column['sql']->toSql();

            $column['sql'] = '(' . $sql . ')';

            $column['params'] = $params;
        }

        return $column;
    }
1081118
public function format_checkbox($field)
    {
        $this->current_row_html[$field] =
            '<input type="checkbox" '.
                'id="cb_'.$this->current_id.'" '.
                'name="cb_'.$this->current_id.'" '.
                'value="'.$this->current_id.'" '.
                ($this->current_row['selected'] == 'Y'
                    ? 'checked '
                    : ''
                ).
            '/>';
        $this->setTDParam($field, 'width', '10');
        $this->setTDParam($field, 'align', 'center');
    }
1180014
public function setFormatter($field, $formatter, $options = null)
    {
        // support for field names as array
        if (is_array($field)) {
            foreach ($field as $f) {
                $this->setFormatter($f, $formatter, $options);
            }

            return $this;
        }

        if (!isset($this->columns[$field])) {
            throw new BaseException('Cannot format nonexistant field '.$field);
        }

        $this->columns[$field]['type'] = '';
        $this->addFormatter($field, $formatter, $options);
        $this->last_column = $field;

        return $this;
    }
571664
public function addFormatter($field, $formatter, $options = null)
    {
        // support for field names as array
        if (is_array($field)) {
            foreach ($field as $f) {
                $this->setFormatter($f, $formatter, $options);
            }

            return $this;
        }

        if (!isset($this->columns[$field])) {
            throw new BaseException('Cannot format nonexistant field '.$field);
        }

        if ($formatter instanceof Closure) {
            $m_name = uniqid();
            $this->addMethod('format_'.$m_name, $formatter);
            $formatter = $m_name;
        }

        if ($this->columns[$field]['type']) {
            $this->columns[$field]['type'] .= ','.$formatter;
        } else {
            $this->columns[$field]['type'] = $formatter;
        }

        if ($options) {
            $this->columns[$field] = array_merge($this->columns[$field], $options);
        }
        $descr = $this->columns[$field];

        if (strpos($formatter, '\\') || strpos($formatter, '/')) {
            // add-on functionality:
            // http://agiletoolkit.org/codepad/gui/grid#codepad_gui_grid_view_example_7_ex
            if (!$this->elements[$formatter.'_'.$field]) {
                $addon = $this->app->normalizeClassName($formatter, 'Controller_Grid_Format');
                $this->elements[$formatter.'_'.$field] = $this->add($addon, $formatter);
            }

            $addon = $this->getElement($formatter.'_'.$field);
            if (!$addon instanceof Controller_Grid_Format) {
                throw $this->exception('Grid formatter class should extend Controller_Grid_Format class')
                    ->addMoreInfo('formater', $formatter);
            }
            $addon->initField($field, $descr);

            return $addon;
        } elseif ($this->hasMethod($m = 'init_'.$formatter)) {
            // execute formatter
            $this->$m($field, $descr);
        }

        return $this;
    }
260264
public static function formatter(Field $field)
    {
        $result = '';
        $options = [];

        if (!empty($field->metadata->settings['options'])) {
            foreach (explode("\n", $field->metadata->settings['options']) as $option) {
                $option = explode('|', $option);
                $value = $option[0];
                $label = isset($option[1]) ? $option[1] : $option[0];
                $options[$value] = $label;
            }
        }

        if (is_string($field->extra)) {
            $selectedOptions = [$field->extra];
        } else {
            $selectedOptions = (array)$field->extra;
        }

        foreach ($selectedOptions as $key) {
            switch ($field->viewModeSettings['formatter']) {
                case 'key':
                    $result .= "{$key}<br />";
                    break;

                case 'default':
                default:
                    if (!empty($options[$key])) {
                        $result .= "{$options[$key]}<br />";
                    }
                    break;
            }
        }

        return $result;
    }
677341
public function setFilterDateRange(
        string $field,
        string $string = '',
        bool $active = true,
        string $format = null,
        string $class = '',
        string $style = '',
        string $placeholder = ''
    ): ColumnInterface {
        $this->setDateActive($active);
        if ($format) {
            $this->setDateFormat($format);
        }

        return $this->setFilter($field, $string, self::FILTER_TYPE_DATE_RANGE, [], $class, $style, $placeholder);
    }
1038431
public function augmentColumns($gridField, &$columns)
    {
        if (Config::inst()->get(__CLASS__, 'prepend_column')) {
		    array_unshift($columns, self::CHECKBOX_COLUMN);
        } else {
		    $columns[] = self::CHECKBOX_COLUMN;
        }
    }
628864
public function format_object($field)
    {
        $this->current_row[$field] = (string) $this->current_row[$field];

        return $this->format_shorttext($field);
    }