Modifies the results from a table find in order to merge full translation records
into each entity under the `_translations` key

@param \Cake\Datasource\ResultSetInterface $results Results to modify.
@return \Cake\Collection\CollectionInterface
514361
public function groupTranslations($results)
    {
        return $results->map(function ($row) {
            $translations = (array)$row['_i18n'];
            if (count($translations) === 0 && $row->get('_translations')) {
                return $row;
            }

            $result = [];
            foreach ($translations as $translation) {
                unset($translation['id']);
                $result[$translation['locale']] = $translation;
            }

            $row['_translations'] = $result;
            unset($row['_i18n']);
            if ($row instanceof EntityInterface) {
                $row->clean();
            }

            return $row;
        });
    }
884863
private function presentUsersToSelect($results)
    {
        $this->info($results->count() . ' result(s) were returned');

        if ($results->count() < 1) {
            die();
        }

        if ($results->count() == 1) {
            $detail = [];
            $keys = array_keys($results->toArray()[0]);
            foreach ($keys as $key) {
                $detail[] = $key .':'. $results->first()->{$key};
            }
            $this->info("[".$results->first()->id."] : " . implode(', ', $detail));

            $this->info("User selected: [".$results->first()->id."]");
            $this->selectedUser = $results->first()->id;
        }
        
        if ($results->count() > 1) {
            $ids = $results->pluck('id')->toArray();
            $keys = array_keys($results->toArray()[0]);

            foreach($results as $result) {
                $detail = [];
                foreach ($keys as $key) {
                    $detail[] = $key .':'. $result->{$key};
                }

                $this->info("[$result->id] : " . implode(', ', $detail));
            }

            while($this->selectedUser == 0) {
                $selectUser = $this->ask('Which user do you wish to update?');
                if (in_array($selectUser, $ids)) {
                    $this->info("User selected: [".$selectUser."]");
                    $this->selectedUser = $selectUser;
                }
            }
        }
    }
437099
protected function buildDictionary($results)
    {
        foreach ($results as $result) {
            if ($result[$this->morphType]) {
                $this->dictionary[$result[$this->morphType]][$result[$this->foreignKey]][] = $result;
            }
        }
    }
1223902
private function getFormattedResults(&$results) {
    return implode('', array(
        $this->getReportInfo($results),
        $this->getPaginationInfo($results),
        $this->getProfileInformation($results),
        $this->getQueryParameters($results),
        $this->getColumnHeaders($results),
        $this->getTotalsForAllResults($results),
        $this->getRows($results)
    ));
    
  }
204708
protected function collectionFromResult($result)
    {
        // If we have one result which is not an assoc array, make it the first element of an array for the
        // collectionFromResult function so we always return a collection from filter
        if ((bool) count(array_filter(array_keys($result), 'is_string'))) {
            $result = [$result];
        }

        $class = $this->class;
        $collection = [];

        foreach ($result as $r) {
            $collection[] = new $class($this->connection, $r);
        }

        return $collection;
    }
571322
protected function respondWithModels(ResultsetInterface $models)
  {

    if (count($models) == 0)
    {
      $this->response->data = [];
    }
    else
    {
      foreach ($models as $model)
      {
        $this->response->data[] = (object)$model->toArray();
      }
      $this->response->getMeta()->count = count($models);
    }

    return $this->response;
  }
1370920
public function add(array $results)
    {
        $cachedResults = [];

        $keyColumn = $this->entityMap->getKeyName();

        foreach ($results as $result) {
            $id = $result[$keyColumn];

            // Forget the ID field from the cache attributes
            // to prevent any side effect.
            // TODO : remove primary key check from dirty attributes parsing
            //unset($result[$keyColumn]);
            $cachedResults[$id] = $this->rawResult($result);
        }

        if (empty($this->cache)) {
            $this->cache = $cachedResults;
        } else {
            $this->mergeCacheResults($cachedResults);
        }
    }
1062769
protected function loadIncludes(array $results): void
	{
		$includes = $this->parseIncludes();

		foreach($includes['this'] as $include => $criteria)
		{
			$forward = $includes['forward'][$include] ?? [];

			$results[0]->$include()->eagerLoad($results, $include, $criteria, $forward);
		}
	}
443505
public function createSearchResults(array $results)
    {
        $created = array();
        foreach ($results as $key => $result) {
            $created[$key] = $this->createResult('Packagist\Api\Result\Result', $result);
        }

        return $created;
    }
722861
protected function runGroupSort($results)
    {
        if (!$results instanceof QueryResultset) {
            return $results;
        }
        $grouped = [];
        $resultTaxOrders = [];
        foreach ($results as $result) {
            $taxGroup = null;
            foreach ($result->getTaxonomy() as $taxonomy) {
                if (in_array($taxonomy->getTaxonomytype(), $result->getTaxonomy()->getGroupingTaxonomies())) {
                    $taxGroup = $taxonomy->getSlug();
                    $taxOrder = $taxonomy->getSortorder();
                    $resultTaxOrders[$result->getId()] = $taxOrder;
                }
            }
            if ($taxGroup !== null) {
                $grouped[$taxGroup][] = $result;
            } else {
                $grouped['ungrouped'][] = $result;
            }
        }

        if (!count($grouped)) {
            return $results;
        }
        if (isset($taxGroup) && $taxGroup !== null) {
            foreach ($grouped as &$group) {
                usort($group, function ($a, $b) use ($resultTaxOrders) {
                    $aOrder = isset($resultTaxOrders[$a->getId()]) ? $resultTaxOrders[$a->getId()] : 0;
                    $bOrder = isset($resultTaxOrders[$b->getId()]) ? $resultTaxOrders[$b->getId()] : 0;

                    return $aOrder - $bOrder;
                });
            }
        }

        return call_user_func_array('array_merge', $grouped);
    }
315332
public function prepend($items)
    {
        return new ResultScan(array_merge($this->parseItems($items), $this->buffered()->toArray()));
    }
111564
protected function buildDictionary(array $results)
    {
        // First we will build a dictionary of child models keyed by the foreign key
        // of the relation so that we will easily and quickly match them to their
        // parents without having a possibly slow inner loops for every models.
        $dictionary = [];

        foreach ($results as $result) {
            $dictionary[$result->pivot->{$this->foreignKey}][] = $result;
        }

        return $dictionary;
    }
482343
public function process($results)
    {
        // Normalize entries. Get entries returns false on failure.
        // We'll always want an array in this situation.
        $entries = $this->connection->getEntries($results) ?: [];

        if ($this->builder->isRaw()) {
            // If the builder is asking for a raw
            // LDAP result, we can return here.
            return $entries;
        }

        $models = [];

        if (Arr::has($entries, 'count')) {
            for ($i = 0; $i < $entries['count']; $i++) {
                // We'll go through each entry and construct a new
                // model instance with the raw LDAP attributes.
                $models[] = $this->newLdapEntry($entries[$i]);
            }
        }

        // If the query contains paginated results, we'll return them here.
        if ($this->builder->isPaginated()) {
            return $models;
        }

        // If the query is requested to be sorted, we'll perform
        // that here and return the resulting collection.
        if ($this->builder->isSorted()) {
            return $this->processSort($models);
        }

        // Otherwise, we'll return a regular unsorted collection.
        return $this->newCollection($models);
    }
804743
public function match(array $models, Collection $results, $relation)
    {
        $foreign = $this->foreignKey;

        $other = $this->otherKey;

        $dictionary = array();

        foreach ($results as $result) {
            $dictionary[$result->getAttribute($other)] = $result;
        }

        foreach ($models as $model) {
            if (isset($dictionary[$model->$foreign])) {
                $model->setRelation($relation, $dictionary[$model->$foreign]);
            }
        }

        return $models;
    }
120962
public function processColumnListing($results)
    {
        return array_values(array_map(function ($result)
        {
            $result = (object) $result;

            return $result->name;

        }, $results));
    }
1099998
protected function toEntityCollection($result)
    {
        switch (true) {

            // already a collection ?
            case is_object($result) && is_subclass_of($result, $this->collectionClass) :
                $collection = $result;
                break;

            // already a collection ?
            case $result instanceof Collection :
                $collection = new $this->collectionClass($result->toArray());
                break;

            // simple related entity ?
            case is_object($result) && is_subclass_of($result, $this->entityClass) :
                $collection = new $this->collectionClass(array($result));
                break;

            // simple array ?
            case is_array($result) :
                $collection = new $this->collectionClass($result);
                break;

            default:
                $collection = new $this->collectionClass();
                break;
        }

        if (is_callable(array($this, 'onLoad'))) {
            @trigger_error(
                sprintf('%s::onLoad() call is deprecated and will be removed in 2.0. Make "%s" invokable instead if you require to custom every "%s" loaded by ORM.',
                    static::class,
                    static::class,
                    $this->entityClass
                ),
                E_USER_DEPRECATED
            );

            return $this->onLoad($collection);
        }

        return $collection;
    }
909250
private function process(Statement $results)
    {
        return $this->manager
            ->getResultProcessor()
            ->processRecords(
                $this->entity,
                $this->with,
                $this->fetchResults(
                    $results,
                    $this->entity->getPrimaryKey()
                ),
                $this->readOnly
            );
    }