Parse coordinats and bounds.

@param AddressBuilder $builder
@param $result
324342
private function parseCoordinates(AddressBuilder $builder, $result)
    {
        $coordinates = $result->geometry->location;
        $builder->setCoordinates($coordinates->lat, $coordinates->lng);

        if (isset($result->geometry->bounds)) {
            $builder->setBounds(
                $result->geometry->bounds->southwest->lat,
                $result->geometry->bounds->southwest->lng,
                $result->geometry->bounds->northeast->lat,
                $result->geometry->bounds->northeast->lng
            );
        } elseif (isset($result->geometry->viewport)) {
            $builder->setBounds(
                $result->geometry->viewport->southwest->lat,
                $result->geometry->viewport->southwest->lng,
                $result->geometry->viewport->northeast->lat,
                $result->geometry->viewport->northeast->lng
            );
        } elseif ('ROOFTOP' === $result->geometry->location_type) {
            // Fake bounds
            $builder->setBounds(
                $coordinates->lat,
                $coordinates->lng,
                $coordinates->lat,
                $coordinates->lng
            );
        }
    }
1055216
protected static function parseIntegerType(&$data, &$result)
    {
        $dataI = self::parseCommon($data, $integerData);
        if (self::$len == 16) {
            $result[] = [
                'integer(' . self::$len . ')',
                $integerData, ];
        } else {
            $value = 0;
            if (self::$len <= 4) {
                // metodo funciona bem para inteiros pequenos
                for ($i = 0; $i < strlen($integerData); $i++) {
                    $value = ($value << 8) | ord($integerData[$i]);
                }
            } else {
                // metodo trabalha com inteiros arbritrários
                if (extension_loaded('bcmath')) {
                    for ($i = 0; $i < strlen($integerData); $i++) {
                        $value = bcadd(bcmul($value, 256), ord($integerData[$i]));
                    }
                } else {
                    $value = -1;
                }
            }
            $result[] = ['integer(' . self::$len . ')', $value];
        }
        $data = $dataI;
    }
840972
public function scopePimp(Builder $builder, $query = [], $sort = [], $relations = [])
    {
        $query = $query ?: array_except(Input::all(), [$this->sortParameterName, $this->withParameterName]);
        $builder->filtered($query)->sorted($sort)->withRelations($relations);
    }
508435
public function mergeTranslatedFields($result) {
        if (!isset($result->{self::I18N_MODEL_BINDING_ALIAS})) {
            return;
        }
        $translationRecordList = $result->{self::I18N_MODEL_BINDING_ALIAS};
        if ($translationRecordList instanceof Zend_Db_Table_Rowset_Abstract) {
            $translationRecordList = $translationRecordList->toArray();
        }
        $translatedFields = array();
        $allLocales = Garp_I18n::getLocales();
        foreach ($this->_translatableFields as $translatableField) {
            // provide default values
            foreach ($allLocales as $locale) {
                $translatedFields[$translatableField][$locale] = null;
            }
            foreach ($translationRecordList as $translationRecord) {
                $lang = $translationRecord[self::LANG_COLUMN];
                $translatedFields[$translatableField][$lang]
                    = $translationRecord[$translatableField];
            }
            $result->setVirtual($translatableField, $translatedFields[$translatableField]);
                //$lang] = $translationRecord[$translatableField];
        }
        // We now have a $translatedFields array like this:
        // array(
        //   "name" => array(
        //     "nl" => "Schaap",
        //     "en" => "Sheep"
        //   )
        // )
        //$result->setFromArray($translatedFields);
        unset($result->{self::I18N_MODEL_BINDING_ALIAS});
    }
427479
private function remapBuilderColumns(Builder $builder): void {
    if($builder->aggregate === null) {
      if($builder->columns === ['*']) {
        $builder->columns = array_keys($this->to_db);
      }

      if(is_string($builder->columns)) {
        $builder->columns = [$builder->columns];
      }

      $this->remapColumns($builder->columns);
    } else {
      if($builder->aggregate['columns'] == ['*']) {
        return;
      }

      $this->remapColumns($builder->aggregate['columns'], false);
    }
  }
872328
public function read(&$result)
    {
        $relations = [];
        $conditions = [];

        foreach ($result as $i => $entity) {
            $container = $this->accessor->getPropertyValue($entity, $this->definition->container());
            if (empty($container)) {
                $this->accessor->setPropertyValue($entity, $this->definition->container(), []);
            }

            foreach ($this->definition->keys() as $local => $refer) {
                $conditions[$refer][] = $this->accessor->getPropertyValue($entity, $local);
            }

            $relations[$this->buildLocalKey($entity, $this->definition->keys())][] = &$result[$i];
        }

        $collection = $this->fetch($this->definition->entity(), $conditions, true);

        foreach ($collection as $relEntity) {
            $key = $this->buildForeignKey($relEntity, $this->definition->keys());

            if (!isset($relations[$key])) {
                continue;
            }

            foreach ($relations[$key] as &$entity) {
                $this->accessor->addPropertyValue($entity, $this->definition->container(), $relEntity);
                unset($entity);
            }
        }

        return $result;
    }
1201692
public function mapResult(ResultIterator $result) {
		//check numer of rows returned
		if ($result->countRows() == 0)
			return null;
	
		//get result column types
		$this->columnTypes = $result->getColumnTypes();
		
		//build type handler list
		if ($this->defaultClass != 'stdClass' || !is_null($this->resultMap))
			$this->buildTypeHandlerList();
		
		//get row as an object and map using its model
		return $this->map($result->fetchObject());
	}
358349
public function setResult(&$result) {
        if (!is_null($result) &&
            !$result instanceof Garp_Db_Table_Row &&
            !$result instanceof Garp_Db_Table_Rowset) {
                throw new InvalidArgumentException(__METHOD__.' expects parameter 1 to be a'.
                    'Garp_Db_Table_Row or Garp_Db_Table_Rowset. '.gettype($result).' given.');
        }
        $this->_result = $result;
    }
693153
protected function getCachedRelationship(string $relation, $result, Relationship $relationship)
    {
        $pivotColumns = $relationship->getPivotAttributes();

        if (!array_key_exists($relation, $this->pivotAttributes)) {
            $this->pivotAttributes[$relation] = $pivotColumns;
        }

        $wrapper = $this->factory->make($result);

        $hash = $wrapper->getEntityHash();

        if (count($pivotColumns) > 0) {
            $pivotAttributes = [];
            foreach ($pivotColumns as $column) {
                $pivot = $wrapper->getEntityAttribute('pivot');

                $pivotWrapper = $this->factory->make($pivot);

                $pivotAttributes[$column] = $pivotWrapper->getEntityAttribute($column);
            }

            $cachedRelationship = new CachedRelationship($hash, $pivotAttributes);
        } else {
            $cachedRelationship = new CachedRelationship($hash);
        }

        return $cachedRelationship;
    }
147585
protected function getConstraints(Builder $builder, array $query)
    {
        $constraints = [];
        foreach ($query as $field => $values) {
            if ($this->isFieldSearchable($builder, $field)) {
                $constraints[$field] = $this->buildConstraints($values);
            }
        }

        return $constraints;
    }
125425
protected function addFooters($result)
    {
        return ltrim($result, PHP_EOL)
                .PHP_EOL.implode(PHP_EOL, array_reverse($this->footer));
    }
1166397
protected static function parseIA5String(&$data, &$result)
    {
        // Character string type
        $data = self::parseCommon($data, $stringData);
        $result[] = [
            'IA5 String (' . self::$len . ')',
            $stringData, ];
    }
1154505
protected function processChannels($data, Result &$result)
    {

        // Create a buffer
        $buffer = new Buffer($data);

        // The first line holds the column names, data returned is in column/row format
        $columns = explode("\t", trim($buffer->readString("\n")), 9);

        // Loop through the rows until we run out of information
        while ($buffer->getLength()) {
            // Grab the row, which is a tabbed list of items
            $row = trim($buffer->readString("\n"));

            // Explode and merge the data with the columns, then parse
            $data = array_combine($columns, explode("\t", $row, 9));

            foreach ($data as $key => $value) {
                // Now add the data to the result
                $result->addTeam($key, utf8_encode($value));
            }
        }

        unset($data, $buffer, $row, $columns, $key, $value);
    }
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);
    }
582203
private function preBuild($result)
    {
        $container = $this->preBuild->handle(new BuilderContainer($this, $result));

        if ($container instanceof BuilderContainer) {
            return $container->getValue();
        }

        throw new \RuntimeException();
    }
862424
public static function buildMessage(ResultException $result)
    {
        $translateKey = self::TRANSLATE_KEY_PREFIX . $result->globalCode;
        $message = self::translate($translateKey);

        return empty($message) ? $result->getAlias() : $message;
    }
461813
public static function parseRelationShips(string $relationships, &$results): array
    {
        $relationships = explode(',', $relationships);

        $newResults = [];

        //if its a list
        if ($results instanceof ResultsetInterface && count($results) >= 1) {
            foreach ($results as $key => $result) {
                //clean records conver to array
            $newResults[$key] = $result->toArray();
                foreach ($relationships as $relationship) {
                    if ($results[$key]->$relationship) {
                        $newResults[$key][$relationship] = $results[$key]->$relationship;
                    }
                }
            }
        } else {
            //if its only 1 record
            if ($results instanceof Model) {
                $newResults = $results->toArray();
                foreach ($relationships as $relationship) {
                    if ($results->$relationship) {
                        $newResults[$relationship] = $results->$relationship;
                    }
                }
            }
        }

        unset($results);
        return $newResults;
    }