Applies sorting on Iterator.

@param array $fields

@return $this
1447
public function order($fields)
    {
        $data = $this->get();

        // prepare arguments for array_multisort()
        $args = [];
        foreach ($fields as list($field, $desc)) {
            $args[] = array_column($data, $field);
            $args[] = $desc ? SORT_DESC : SORT_ASC;
            //$args[] = SORT_STRING; // SORT_STRING | SORT_NUMERIC | SORT_REGULAR
        }
        $args[] = &$data;

        // call sorting
        call_user_func_array('array_multisort', $args);

        // put data back in generator
        $this->generator = new \ArrayIterator(array_pop($args));

        return $this;
    }
1270678
public function setFields($fields)
    {
        $this->fields = $fields; 
        $this->raw_fields = array_merge($this->raw_fields, $fields);   
        parent::setFields($fields);  
		return $this;
    }
290623
public function optimizeFields(array $fields)
	{
		$this->fields = $fields;
		foreach ($this->fields as $field)
		{
			foreach ($field as $source => $ids)
			{
				if ( ! isset($this->requests[$source]))
				{
					$this->requests[$source] = [];
				}
				foreach ($ids as $id)
				{
					$this->requests[$source][] = $id;
				}
				$this->requests[$source] = array_unique($this->requests[$source]);
			}
		}

		return $this;
	}
588361
public function addOrder(array $pFields)
    {
        if (in_array(DbInterface::ORDER_RAND, $pFields)) {
            $this->_order[DbInterface::ORDER_RAND] = true;
            return $this;
        }

        $orders = array(
            Db::ORDER_ASC,
            Db::ORDER_DESC
        );

        $fields = $this->_prefixFields($pFields);
        foreach ($fields as $field => $order) {
            if ((! is_string($order) and ! is_int($order)) or ! in_array($order, $orders)) {
                continue;
            }

            $this->_order[$field] = $order;
        }

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

        $this->graphNode->fields($fields);

        return $this;
    }
90594
public function show(array $fields) 
	{
		$this->show = array();
		
		foreach($fields as $field) {
			$this->show[$field] = true;
		}
		
		return $this;
	}
1336323
public function excludeFields(array $fields)
    {
        foreach ($fields as $fieldName) {
            $this->field($fieldName)->expression(false);
        }

        return $this;
    }
553390
public function fields($fields)
    {
        $fields = is_array($fields) && func_num_args() === 1 ? $fields : func_get_args();
        $this->_parts['fields'] = Set::merge($this->_parts['fields'], $fields);
        return $this;
    }
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;
    }
292125
public function alsoLoad($fields)
    {
        if(!is_array($fields))
        {
            $fields = [$fields];
        }

        foreach($fields as $field)
        {
            $this->mapping['alsoLoadFields'][] = $field;
        }

        return $this;
    }
1275615
public function setFields(array $fields)
    {
        foreach ($fields as $key => $field) {
            $this->setField($key, $field);
        }

        return $this;
    }
233225
public function fields($fields = [])
    {
        $this->builder->select([]);
        $this->casts = [];

        if (empty($fields)) {
            foreach ($this->model->fields() as $field) {
                $this->assignField($field);
            }

            return $this;
        }

        foreach ($fields as $field) {
            $this->assignField($this->model->field($field));
        }

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

        $this->prepareQuery();

        return $this;
    }
1002272
public function setFields(array $fields)
    {
        $this->clearFields();

        foreach ($fields as $field) {
            $this->addField($field);
        }

        return $this;
    }
797901
public static function sort(array $records, array $fields) {
        $records = new coursecat_sortable_records($records);
        $records->sortfields = $fields;
        $records->uasort(array($records, 'sort_by_many_fields'));
        return $records->getArrayCopy();
    }