Order formatter helper method

@param  string|array $fields The fields.
@return string       Formatted fields.
494492
protected function _order($fields)
    {
        $direction = 'ASC';

        $result = [];
        foreach ($fields as $field => $value) {
            if (!is_int($field)) {
                $result[$field] = $value;
                continue;
            }
            if (preg_match('/^(.*?)\s+((?:a|de)sc)$/i', $value, $match)) {
                $value = $match[1];
                $dir = $match[2];
            } else {
                $dir = $direction;
            }
            $result[$value] = $dir;
        }
        return $result;
    }
137416
public function order($field, $order = null, $intSort = true)
    {
        return $this->sort(function ($a, $b) use ($field, $order, $intSort) {
            $fieldA = isset($a[$field]) ? $a[$field] : null;
            $fieldB = isset($b[$field]) ? $b[$field] : null;

            if ($intSort) {
                return 'desc' == strtolower($order) ? $fieldB >= $fieldA : $fieldA >= $fieldB;
            } else {
                return 'desc' == strtolower($order) ? strcmp($fieldB, $fieldA) : strcmp($fieldA, $fieldB);
            }
        });
    }
71618
public static function fieldListToValuesString($fields)
    {
        $formattedFields = [];
        foreach ($fields as $field) {
            $fieldWithColonPrefix = ':' . $field;
            $formattedFields[] = $fieldWithColonPrefix;
        }

        return ' value (' . implode(', ', $formattedFields) . ')';
    }
942680
public function fields( $fields )
	{
		if ( !is_array( $fields ) && !is_null( $fields ) )
		{
			$fields = array( $fields );
		}
		
		// do nothing if we get nothing
		if ( empty( $fields ) || $fields == array( '*' ) )
		{
			$this->fields = array(); return $this;
		}
		
		$this->fields = $fields;

		// return self so we can continue running the next function
		return $this;
	}
283647
protected function _OrderUrl($Field) {
      $Get = Gdn::Request()->Get();
      $Get['order'] = $Field;
      return '/dashboard/user?'.http_build_query($Get);
   }
90676
protected function prepare_form_fields(array $fields) {

        $formdata = new stdclass();
        $key = 0;
        foreach ($fields as $field) {
            $formdata->{'dimensionid__idx_' . $key}             = $field->id;
            $formdata->{'description__idx_' . $key}             = $field->description;
            $formdata->{'description__idx_' . $key.'format'}    = $field->descriptionformat;
            $formdata->{'numoflevels__idx_' . $key}             = count($field->levels);
            $lev = 0;
            foreach ($field->levels as $level) {
                $formdata->{'levelid__idx_' . $key . '__idy_' . $lev} = $level->id;
                $formdata->{'grade__idx_' . $key . '__idy_' . $lev} = $level->grade;
                $formdata->{'definition__idx_' . $key . '__idy_' . $lev} = $level->definition;
                $formdata->{'definition__idx_' . $key . '__idy_' . $lev . 'format'} = $level->definitionformat;
                $lev++;
            }
            $key++;
        }
        return $formdata;
    }
110319
public function orderField($field, array $values = [], $order = '')
    {
        if (!empty($values)) {
            $values['sort'] = $order;

            $this->options['order'][$field] = $values;
        }

        return $this;
    }
1135202
public function tableHeadings($fields)
    {
        $output = '';
        foreach ($fields as $f) {
            $field = $this->humanReadableField($f);
            $output .= '<th>'.$field.'</th>';
        }

        return $output;
    }
57101
public function orderBy($fields, $defaultDirection = 'ASC')
    {
        if (!is_array($fields)) {
            $fields = array($fields);
        }

        foreach ($fields as $key => $value) {
            $field = $key;
            $type = $value;
            if (is_int($key)) {
                $field = $value;
                $type = $defaultDirection;
            }
            if (!$field instanceof Raw) {
                $field = $this->addTablePrefix($field);
            }
            $this->statements['orderBys'][] = compact('field', 'type');
        }

        return $this;
    }
1270232
protected function fields(array $fields) {
        if (!empty($fields)) {
            if (!is_numeric(key($fields))) {
                $fields = array_keys($fields);
            }
            $this->insertFields = $fields;
        }
        return $this;
    }
1173093
private function fieldPrefixer(array &$fields)
    {
        foreach ($fields as $index => $property) {
            if (0 === \strpos($property, $this->source . '.')
                || !$this->fieldExists($property)
            ) {
                continue;
            }

            $fields[$index] = $this->source . '.' . $property;
        }
    }
191335
public function createFields($fields = null): string
    {
        // 如果未指定字段,则,全部字段
        if (!$fields) {
            return '*';
        }

        $ret = $this->formatFields($fields);

        // 返回逗号分隔的列表
        return implode(',', $ret);
    }
631902
public function buildOrderBy(array $fields)
    {
        $this->parseSelectPath();
        foreach ($fields as $field) {
            if (!is_array($field)) {
                $field = [$field];
            }
            $property = array_shift($field);
            if (!in_array($property, $this->aliasMapping) && isset($this->aliasMapping[$property])) {
                $property = $this->aliasMapping[$property];
            }
            $direction = $field ? array_shift($field) : 'ASC';
            $function = $field ? array_shift($field) : null;
            if ($function) {
                $property = sprintf("%s(%s)", $function, $property);
            }
            $this->addOrderBy($property, $direction);
        }

        return $this;
    }
596913
public static function cleanFields($fields)
    {
        $fields = parent::cleanFields($fields);

        //If config is requested add id and type as they are need to pull config.
        if (in_array('config', $fields)) {
            $fields[] = 'id';
            $fields[] = 'type';
        }

        //Removing config from field list as it is not a real column in the table.
        if (in_array('config', $fields)) {
            $key = array_keys($fields, 'config');
            unset($fields[$key[0]]);
        }

        return $fields;
    }
699001
public function orderBy($field, $order = 'ASC')
    {
        if(is_string($field) && trim($field) != '') {
            $field = trim($field);
            $field = ltrim($field, 'ORDER BY ');
            $this->order = ' ORDER BY `'.$field.'`'.(($order == 'DESC') ? ' DESC' : ' ASC');
        }
        return $this;
    }
1236840
public function formatOrderBy(array $orderBy) {
        if ($orderBy) {
            $output = [];

            foreach ($orderBy as $field => $direction) {
                if ($direction instanceof Func) {
                    $output[] = $this->formatFunction($direction);
                } else {
                    $output[] = $this->quote($field) . ' ' . $this->getKeyword($direction);
                }
            }

            return sprintf($this->getClause(self::ORDER_BY), implode(', ', $output));
        }

        return '';
    }
484049
public function fields($fields)
    {
        if (is_array($fields) || $fields === null) {
            $this->fields = $fields;
        } else {
            $this->fields = func_get_args();
        }
        return $this;
    }