Creates a colection of messages out of a given fields collection.

@param array $fields

@return array
973652
public static function getLanguageItems(array $fields)
    {
        $items = [];

        foreach ($fields as $field) {
            foreach ($field->getLabels() as $label) {
                if (!$label->isPlain) {
                    $items[$label->lang][] = $label;
                }
            }

            foreach ($field->getPlaceholders() as $label) {
                if (!$label->isPlain) {
                    $items[$label->lang][] = $label;
                }
            }

            foreach ($field->getOptions() as $lang => $labels) {
                foreach ($labels as $label) {
                    if (!$label->isPlain) {
                        $items[$label->lang][] = $label;
                    }
                }
            }
        }

        return $items;
    }
359024
protected function upsertDeletedAt(array $fields)
    {
        foreach ($fields as $field) {
            if ($field->isAutoManagedOnDelete()) {
                return $fields;
            }
        }

        $fields[] = $this->getNewDeletedAtField();

        return $fields;
    }
932440
public function addFields(array $fields)
    {
        collect($fields)->each(function ($field, $key) {
            if (! $field instanceof AttachmentField) {
                $field = [$key => $field];
            }

            $this->addField($field);
        });

        return $this;
    }
815821
protected function extractImportsFromFields(array $fields)
    {
        $imports = [];

        foreach ($fields as $field) {
            $options = $field->getLanguage(static::LANGUAGE);
            $imports = array_merge($imports, explode(PHP_EOL, $options->get('imports')));

            if ($field->getFormat()) {
                $imports[] = 'use Gdbots\Pbj\Enum\Format;';
            }

            switch ($field->getType()->getTypeName()->getValue()) {
                case TypeName::INT_ENUM;
                case TypeName::STRING_ENUM;
                    $enum = $field->getEnum();
                    $imports[] = sprintf(
                        'use %s\%s;',
                        $this->enumToNativeNamespace($enum),
                        $this->enumToClassName($enum)
                    );
                    break;

                case TypeName::MESSAGE;
                    $anyOfs = $field->getAnyOf() ?: [];
                    foreach ($anyOfs as $anyOf) {
                        $imports[] = sprintf(
                            'use %s\%s as %s;',
                            $this->schemaToNativeNamespace($anyOf),
                            $this->schemaToClassName($anyOf),
                            $this->schemaToFqClassName($anyOf)
                        );
                    }
                    break;

                default:
                    break;
            }
        }

        return $imports;
    }
117500
protected function objectifyFields($fields) {
        $new = array();
        foreach($fields as $name => $field) {
            if (is_object($field)) {
                $new[] = $field;
            } else {
                $new[] = new EntryField($name, $field);
            }
        }
        return $new;
    }
174803
public function setFields(array $fields)
    {
        $this->fields = [];

        foreach ($fields as $type => $field) {
            //Remove empty and repeated fields
            $this->fields[$type] = array_unique(array_filter(explode(',', $field)));
        }

        return $this;
    }
293421
public function prepareSort(array $fields) : array
    {
        $sortFields = [];

        foreach ($fields as $key => $value) {
            if (is_array($value)) {
                $sortFields[$this->prepareFieldName($key)] = $value;
            } else {
                $sortFields[$this->prepareFieldName($key)] = $this->getSortDirection($value);
            }
        }

        return $sortFields;
    }
1371320
public function mapFormFields($fields)
    {
        $_fields = [];

        foreach ($fields as $key => $options) {
            $_options = $this->config('formFieldOptions');

            if (is_array($options)) {
                $_fields[$key] = array_merge($_options, $options);
            } else {
                $_fields[$options] = $_options;
            }
        }

        return $_fields;
    }
591113
public function buildSelectFields($fields)
    {
        $selectFields = [];
        foreach ((array)$fields as $key => $value) {
            if (is_int($key)) {
                $selectFields[$value] = true;
            } else {
                $selectFields[$key] = is_scalar($value) ? (bool)$value : $value;
            }
        }
        return $selectFields;
    }
1310533
public function mget(array $fields)
    {
        $result = array();

        foreach ($fields as $field) {
            $result[$field] = $this->get($field);
        }

        return $result;
    }
592395
protected function getMergeFieldsMap($fields = [])
    {
        $data = ArrayData::create([]);

        foreach ($fields as $field) {
            $data->setField($field->Name, DBField::create_field('Text', $field->Value));
        }

        return $data;
    }
241514
public static function collapse(array $fields): Collapse
    {
        return new class($fields) extends Collapse {
            /**
             * @var array
             */
            private $fields;

            /**
             *  constructor.
             *
             * @param array $fields
             */
            public function __construct(array $fields)
            {
                $this->fields = $fields;
            }

            /**
             * @return array
             */
            public function fields(): array
            {
                return $this->fields;
            }
        };
    }
51326
protected function formatFieldList($fields) {
		if( !is_array($fields) ) {
			return $fields;
		}
		$string	= '';
		foreach( $fields as $key => $value ) {
			$string .= ($string ? ', ' : '').$this->escapeIdentifier($key).'='.$this->formatValue($value);
		}
		return $string;
	}
408518
public function fields($fields) {

        if ( is_array($fields) ) {
            $this->fields = '`'.implode("`, `", $fields).'`';
        } else if ( is_string($fields) ) {
            $this->fields = $fields;
        } else {
            $this->fields = '*';
        }
        return $this;
    }
382871
public function encodeValues(array $fields)
    {
        $output = [];

        foreach ($fields as $key => $val) {
            $output[$key] = $this->encodeValue($val);
        }

        return $output;
    }
113602
public function fields($fields) {
        if (!is_array($fields)) {
            $fields = func_get_args();
        }

        $this->_fields = $fields;

        return $this;
    }
243401
public static function quoteFields($fields) {
        $fieldArr = is_array($fields) ? $fields : explode(',', $fields);
        $resultFieldArr = array();
        foreach ($fieldArr as $field) {
            $resultFieldArr[] = self::quoteField($field);
        }

        return implode(', ', $resultFieldArr);
    }