Process fields.

@param array $fields
An array of fields.
@param array $results
The results array on which to append inputs too.

@return array
An array of the field results.
181009
protected function processFields(array $fields, array $results = [])
    {
        $input = $this->input;
        $output = $this->output;
        $helper = $this->helperSet->get('question');

        foreach ($fields as $field) {
            if (!$field instanceof FieldDefinitionInterface) {
                continue;
            }
            $field_name = $field->getName();

            if (isset($results[$field_name])) {
                continue;
            }

            if (!$field instanceof FieldGroup) {
                if ($field->hasCondition()
                    && !$this->fieldConditionMet($field, $results)) {
                    continue;
                }

                if ($field->hasFieldCallback()) {
                    $field->onFieldCallback($results);
                }

                if ($input->isInteractive()) {
                    try {
                        $value = $helper->ask($input, $output, $field->asQuestion());

                        if ($field->hasSubform()) {
                            $subform = new static();
                            $field->onSubformProcess($subform, $value);

                            $results[$field_name] = $subform
                                ->setInput($input)
                                ->setOutput($output)
                                ->setHelperSet($this->helperSet)
                                ->process()
                                ->getResults();
                        } else {
                            $results[$field_name] = $field->formattedValue($value);
                        }
                    } catch (\Exception $e) {
                        throw new FormException(trim($e->getMessage()));
                    }
                }
            } else {
                $groups = [];

                do {
                    $result = $this->processFields(
                        $field->getGroupFields()
                    );
                    $continue = false;

                    if ($field->hasLoopUntil()) {
                        $continue = $field->loopUntil([$result]);
                        if ($continue) {
                            $groups[] = $result;
                        }
                    } else {
                        $groups[] = $result;
                    }
                } while ($continue);

                $results[$field_name] = $groups;
            }
        }

        return $results;
    }
589494
public function setResults($results)
    {
        // hydrate model
        foreach ($results as $entry) {
            /** @var EntityDataModel $model */
            $model = $this->getModel();
            $model->setEntityManager($this->getEntityManager());

            // check for json
            if (array_key_exists('[json]', $entry)) {
                $entry = json_decode($entry['[json]']);
            }

            $model = $this->populate($entry, $model);

            $this->collection[] = $model;
        }

        $this->setCount(count($this->collection));

        return $this;
    }
1297207
protected function getEagerModelKeys(array $results)
    {
        $keys = [];

        // First we need to gather all of the keys from the result set so we know what
        // to query for via the eager loading query. We will add them to an array then
        // execute a "where in" statement to gather up all of those related records.
        foreach ($results as $result) {
            if (array_key_exists($this->foreignKey, $result) && !is_null($value = $result[$this->foreignKey])) {
                $keys[] = $value;
            }
        }

        // If there are no keys that were not null we will just return an array with 0 in
        // it so the query doesn't fail, but will not return any results, which should
        // be what this developer is expecting in a case where this happens to them.
        if (count($keys) == 0) {
            return [0];
        }

        return array_values(array_unique($keys));
    }
112759
private function iteratorFromResults(array $results)
    {
        $values = [];

        foreach ($results as $pair) {
            $entry = new IndexEntry();

            $entry->indexKey  = $pair->key;
            $entry->objectKey = $pair->value;

            $values[] = $entry;
        }

        return new ArrayIterator($values);
    }
253061
protected function processI(array $result) {
		$entity = df_ic($this->entityC(), O::class, $result); /** @var O $entity */
		$entity->validate();
		return $result;
	}
1283409
protected function processQueryFields($data, array $fields = array())
    {
        $base = new stdClass();

        if (count($fields) === 0) {
            return $base;
        }

        foreach ($fields as $key => $field) {

            $this->verifyFieldDefined($key, $field);

            if (in_array($field['name'], $this->customfieldgroups)
                || $field['type'] === 'customfield'
            ) {
            } else {
                $base->$field['name'] = $this->processQueryField($data, $field);
            }
        }

        return $this->sortObject($base);
    }
390787
protected function processResults($results)
    {
        $json = array();
        foreach($results as $result) {
            $name = $result->{$this->labelField};

            $json[$result->ID] = array(
                'name' => $name,
                'currentString' => $this->getCurrentItemText($result)
            );
        }

        return $json;
    }
786494
protected function from_db_records(array $results) {
        $entityfactory = $this->get_entity_factory();
        $records = array_map(function($result) {
            return $result['record'];
        }, $results);

        return $entityfactory->get_post_read_receipt_collection_from_stdclasses($records);
    }
909250
private function process(Statement $results)
    {
        return $this->manager
            ->getResultProcessor()
            ->processRecords(
                $this->entity,
                $this->with,
                $this->fetchResults(
                    $results,
                    $this->entity->getPrimaryKey()
                ),
                $this->readOnly
            );
    }
1318081
public function addFields(array $fields)
    {
        $oldFields = $this->_queryBuilder->getFields() ? $this->_queryBuilder->getFields() : array();
        $newFields = array_merge($oldFields, $fields);
        $this->setFields($newFields);
        return $this;
    }
354760
protected function processExportData($columns, $results, $options)
    {
        /*
         * Validate
         */
        if (!$results) {
            throw new ApplicationException(Lang::get('backend::lang.import_export.empty_error'));
        }

        /*
         * Parse options
         */
        $defaultOptions = [
            'firstRowTitles' => true,
            'useOutput' => false,
            'fileName' => 'export.csv',
            'delimiter' => null,
            'enclosure' => null,
            'escape' => null
        ];

        $options = array_merge($defaultOptions, $options);
        $columns = $this->exportExtendColumns($columns);

        /*
         * Prepare CSV
         */
        $csv = CsvWriter::createFromFileObject(new SplTempFileObject);
        
        $csv->setOutputBOM(CsvWriter::BOM_UTF8);

        if ($options['delimiter'] !== null) {
            $csv->setDelimiter($options['delimiter']);
        }

        if ($options['enclosure'] !== null) {
            $csv->setEnclosure($options['enclosure']);
        }

        if ($options['escape'] !== null) {
            $csv->setEscape($options['escape']);
        }

        /*
         * Add headers
         */
        if ($options['firstRowTitles']) {
            $headers = $this->getColumnHeaders($columns);
            $csv->insertOne($headers);
        }

        /*
         * Add records
         */
        foreach ($results as $result) {
            $data = $this->matchDataToColumns($result, $columns);
            $csv->insertOne($data);
        }

        /*
         * Output
         */
        if ($options['useOutput']) {
            $csv->output($options['fileName']);
        }

        /*
         * Save for download
         */
        $csvName = uniqid('oc');
        $csvPath = temp_path().'/'.$csvName;
        $output = $csv->__toString();

        File::put($csvPath, $output);

        return $csvName;
    }
1200013
protected function mergeCacheResults(array $results)
    {
        foreach ($results as $key => $entity) {
            $this->cache[$key] = $entity;
        }
    }
866516
protected function fields(array $fields)
    {
        $result = array();
        foreach ($fields as $id => $field) {
            if (!isset($field['id'])) {
                $field['id'] = $id;
            }
            if (!isset($field['name'])) {
                $field['name'] = $id;
            }
            $result[$id] = $this->field($field);
        }
        return $result;
    }
42124
public function process($fields)
    {
        $data = array();
        foreach ($fields as $model) {
            $data[] = $this->row($model);
        }
        header('Content-Type: text/json');

        echo json_encode(array('data' => $data));
        die();
    }
1205692
private function finalResultPages(array $fields, array $resultPage)
    {
        return array_map(
            function ($resultRows) use ($fields) {
                return $this->getRows($resultRows, $fields);
            },
            $resultPage
        );
    }
381452
private function iteratorFromResults(array $results)
    {
        $values = [];

        foreach ($results as $item) {
            $entry = new IndexEntry();

            $entry->indexKey  = key($item);
            $entry->objectKey = reset($item);

            $values[] = $entry;
        }

        return new ArrayIterator($values);
    }
1364771
protected function handleResult(array $result)
    {
        if ($this->onlyCount && isset($result[0]) && is_array($result[0])) {
            return (int)current($result[0]);
        }

        $entities = [];
        foreach ($result as $row) {
            $model = clone $this->getModel();
            $model->populate($row);
            $entities[] = $model;
        }
        return $entities;
    }