Build a result set keyed by PK.

@param array   $results
@param string. $primaryKey

@return array
1840
protected function buildKeyedResultSet(array $results, string $primaryKey) : array
    {
        $builder = new EntityBuilder($this->mapper, array_keys($this->eagerLoads), $this->useCache);

        $keys = array_map(function ($item) use ($primaryKey) {
            return $item[$primaryKey];
        }, $results);

        return array_combine($keys, array_map(function ($item) use ($builder) {
            return $builder->build($item);
        }, $results));
    }
655282
protected function buildWhereForArray($primaryKeyValue)
    {
        $where = [];
        foreach ($primaryKeyValue as $key => $value) {
            $where[] = "{$key}='{$value}'";
        }

        return implode(' AND ', $where);
    }
669185
function getPrimaryKeyValues() {
		$arr = array();
		$pks = static::$_primaryKeys;

		foreach ($pks as &$pk) {
			$arr[] = $this->{"get$pk"}();
		}

		return $arr;
	}
437099
protected function buildDictionary($results)
    {
        foreach ($results as $result) {
            if ($result[$this->morphType]) {
                $this->dictionary[$result[$this->morphType]][$result[$this->foreignKey]][] = $result;
            }
        }
    }
6871
protected function getGenericPrimaryKey(array $primaryKey)
    {
        $genericPrimaryKey = new PrimaryKey($primaryKey[0]['name']);

        foreach ($primaryKey as $primaryKeyColumn) {
            $genericPrimaryKey->addColumnName($primaryKeyColumn['column_name']);
        }

        return $genericPrimaryKey;
    }
1231277
public function findByKeys($primaryKeys)
    {
        $data = $this->newDataInstance(null, false);

        if (!is_array($primaryKeys)) {
            throw new \UnexpectedValueException(__METHOD__ . '|$primaryKeys must be an array !');
        }

        //~ Set values before cache
        foreach ($primaryKeys as $field => $value) {
            $this->setDataValue($data, $field, $value);
        }

        $data = $this->getCache($data);

        if ($data === false) {

            foreach ($primaryKeys as $field => $value) {
                $this->addWhere($field, $value);
            }

            $data = $this->selectOne();

            //~ Clear & set in cache
            $this->clear();
            $this->setCache($data);
        }

        return $data;
    }
493764
protected function buildDictionary(EntityCollection $results)
    {
        $dictionary = [];

        $foreign = $this->getPlainForeignKey();

        // First we will create a dictionary of models keyed by the foreign key of the
        // relationship as this will allow us to quickly access all of the related
        // models without having to do nested looping which will be quite slow.
        foreach ($results as $result) {
            $dictionary[$result->{$foreign}][] = $result;
        }

        return $dictionary;
    }
149756
protected function from_db_records(array $results) {
        $entityfactory = $this->get_entity_factory();

        return array_map(function(array $result) use ($entityfactory) {
            [
                'discussion' => $discussion,
                'firstpost' => $firstpost,
                'firstpostauthor' => $firstpostauthor,
                'latestpostauthor' => $latestpostauthor,
            ] = $result;
            return $entityfactory->get_discussion_summary_from_stdclass(
                $discussion,
                $firstpost,
                $firstpostauthor,
                $latestpostauthor
            );
        }, $results);
    }
784259
protected function fetchPrimaryKeys(): array
    {
        $query = "SHOW INDEXES FROM {$this->driver->identifier($this->getName())}";

        $primaryKeys = [];
        foreach ($this->driver->query($query) as $index) {
            if ($index['Key_name'] == 'PRIMARY') {
                $primaryKeys[] = $index['Column_name'];
            }
        }

        return $primaryKeys;
    }
1076486
protected function buildUnkeyedResultSet(array $results) : array
    {
        $builder = new EntityBuilder($this->mapper, array_keys($this->eagerLoads), $this->useCache);

        return array_map(function ($item) use ($builder) {
            return $builder->build($item);
        }, $results);
    }
595239
public static function keyPair(array $result): array
    {
        $firstRow = current($result);
        if (empty($firstRow)) {
            return $result;
        }

        list($keyName, $valueName) = array_keys($firstRow);

        return array_combine(
            array_column($result, $keyName),
            array_column($result, $valueName)
        );
    }
424214
public function comparePrimaryKeys(PrimaryKey $oldPrimaryKey, PrimaryKey $newPrimaryKey)
    {
        return ($oldPrimaryKey->getName() !== $newPrimaryKey->getName())
            || ($oldPrimaryKey->getColumnNames() !== $newPrimaryKey->getColumnNames());
    }
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));
    }
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);
    }
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);
    }
523752
private function buildResults($results)
    {
        return array_map(function ($result) {
            $coordinates = $result['geometry']['location'];
            $data = [
                'address' => $result['formatted_address'],
                'latitude' => $coordinates['lat'],
                'longitude' => $coordinates['lng'],
                'place_id' => $result['place_id'],
                'types' => $result['types'],
                'address_components' => $this->buildAddressComponents($result)
            ];

            if (isset($result['geometry']['bounds'])) {
                $bounds = $result['geometry']['bounds'];
                $data['bounds'] = [
                    'northeast' => [
                        'latitude' => $bounds['northeast']['lat'],
                        'longitude' => $bounds['northeast']['lng'],
                    ],
                    'southwest' => [
                        'latitude' => $bounds['southwest']['lat'],
                        'longitude' => $bounds['southwest']['lng'],
                    ]
                ];
            }

            return $data;
        }, $results);
    }
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;
                }
            }
        }
    }