Parse field parameter.

@param array $fields Array of fields to include. It must be an array
whose keys are resource types and values a string
of the fields to return, separated by a comma

@return $this
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;
    }
216730
public function addFields(array $fields)
    {
        foreach ($fields as $name => $attrs) {
            $this->addField($name, $attrs);
        }

        return $this;
    }
20990
public function fields(array $fields)
    {
        $newFields = array();
        $this->fields = '';
        $this->fieldsArguments = array();

        foreach ($fields as $field) {
            if (is_scalar($field)) {
                $newFields[] = '?f:alias:.?f';
                $this->fieldsArguments[] = $field;
            } else {
                if (!isset($field[0]) or !isset($field[1]) or !is_array($field[1])) {
                    throw new \BadMethodCallException('Must be exist 0 and 1 index in array and second one must be an array');
                }
                $newFields[] = $field[0];
                $this->fieldsArguments = array_merge($this->fieldsArguments, $field[1]);
            }
        }

        $this->fields = implode(', ', $newFields);

        return $this;
    }
106289
protected static function hash($fields)
    {
        foreach ($fields as $key => $value) {
            if (in_array($key, self::$fields)) {
                $fields[$key] = Hash::make($value);
            }
        }

        return $fields;
    }
1328816
public function setFields(array $fields)
    {
        foreach ($fields as $name => $value) {
            $this->setField($name, $value);
        }

        $this->prepareQuery();

        return $this;
    }
691193
public function includeFields(array $fields)
    {
        foreach ($fields as $fieldName) {
            $this->field($fieldName)->expression(true);
        }

        return $this;
    }
763383
protected function parseFields($fields, $name) {
		if(is_array($fields)) {
			return new self(
				$fields,
				$name,
				(isset($this->data[$name]) ? $this->data[$name]:[]),
				$this
			);
		}
		elseif($fields instanceof Field) {
			$field = $fields;
			$field->setName($name);
			$field->setParent($this);

			if(isset($this->data[$name]))
				$field->setValue($this->data[$name]);

			return $field;
		}
		elseif($fields instanceof self) {
			$group = $fields;
			$group->setName($name);
			$group->setParent($this);
			$group->setData(
				(isset($this->data[$name]) ? $this->data[$name]:[])
			);

			return $group;
		}
	}
158221
public function setUserFields(array $fields) {
        $clean = array();

        foreach ($fields as $base => $field) {
            if (is_numeric($base)) {
                $base = $field;
            }

            $clean[$base] = $field;
        }

        $this->userFields = $clean;

        return $this;
    }
592066
public function fields(array $fields = null) {
        if ($fields === null) {
            return $this->fields;
        }

        $this->fields = $fields;

        return $this;
    }
1333071
public function returnedFields($fields) {
		if(empty($this->data['returnedFields'])) {
			$this->data['returnedFields'] = array();
		}
		$this->data['returnedFields'] = array_unique(array_merge($this->data['returnedFields'], (array)$fields));
		return $this;
	}
113602
public function fields($fields) {
        if (!is_array($fields)) {
            $fields = func_get_args();
        }

        $this->_fields = $fields;

        return $this;
    }
1358694
public function setMapping(array $fields = [])
    {
        $allowedFields = ['backend', 'page', 'navigation', 'date', 'forward', 'custom1', 'custom2', 'custom3', 'custom4', 'custom5'];
        foreach ($fields as $field => $value) {
            if (!$value || !in_array($field, $allowedFields)) {
                continue;
            }
            if ($field === 'date' && is_string($value)) {
                $value = new \DateTime($value);
            }
            $this->$field = $value;
        }

        return $this;
    }
1348214
protected function addValues($fields)
    {
        $values_array = [];
        foreach ($fields as $values) {
            $values_array[] = '(' . $this->_addValue($values) . ')';
        }

        return implode(',', $values_array);
    }
716152
private function parametrize($fields = [])
    {
        return (string) implode(', ', array_map(function ($field) {
            return Dumper::export($field);
        }, $fields));
    }
889486
public function groupBy($fields)
    {
        if (!is_array($fields)) {
            $fields = $this->splitParts($fields);
        }

        foreach ($fields as $k => $field) {
            $fields[$k] = $this->db->quoteColumn($field);
        }

        $this->query['group'] = implode(',', $fields);

        return $this;
    }
1195643
public function fields($fields)
    {
        // we always have to reset the fields
        $this->fields = array();

        // when a string is given
        if (is_string($fields)) 
        {
            $fields = $this->stringArgumentToArray($fields);
        }
        // it also could be an object
        elseif (is_object($fields))
        {
            return $this->addField($fields);
        }

        // do nothing if we get nothing
        if (empty($fields) || $fields === array('*') || $fields === array('')) { return $this; }

        // add the fields
        foreach($fields as $key => $field)
        {
            // when we have a string as key we have an alias definition
            if (is_string($key))
            {
                $this->addField($key, $field);
            } else {
                $this->addField($field);
            }
        }

        return $this;
    }
1230166
public function select(Array $fields = null)
    {
        $this->_fields = empty($fields) ? '*' : implode(',', $fields);
        return $this;
    }