return data as an array of entities
@access public
@param $entity string
@return \Gcs\Framework\Core\Collection\Collection
@since 3.0
@package Gcs\Framework\Core\Sql
540829
public function data($entity = '') {
        $entities = [];

        foreach ($this->_data as $line) {
            if ($entity != '') {
                /** @var  $entityObject \Gcs\Framework\Core\Orm\Entity\Entity */
                $entityObject = self::Entity()->$entity();

                foreach ($line as $key => $field) {
                    $value = null;
                    $parent = '';

                    $key = str_replace('count_one_' . $entityObject->name() . '_', '', $key);
                    $key = str_replace('count_many_' . $entityObject->name() . '_', '', $key);
                    $key = str_replace($entityObject->name() . '_', '', $key);

                    if ($entityObject->getField($key) != null) {
                        if (in_array($entityObject->getField($key)->type, [Field::INCREMENT, Field::INT, Field::TEXT, Field::FLOAT, Field::STRING, Field::CHAR, Field::BOOL, Field::DATE, Field::DATETIME, Field::TIMESTAMP, Field::ENUM])) {
                            if ($entityObject->getField($key)->foreign == null) {
                                //If the field is a Datetime or Date or Timestamp we must convert it to \DateTime
                                switch ($entityObject->getField($key)->type) {
                                    case Field::DATETIME:
                                        $value = new \DateTime($field);
                                        break;

                                    case Field::DATE:
                                        $value = new \DateTime($field);
                                        break;

                                    case Field::TIMESTAMP:
                                        $value = new \DateTime($field);
                                        break;

                                    default:
                                        $value = $field;
                                        break;
                                }
                            }
                            elseif (in_array($entityObject->getField($key)->foreign->type(), [ForeignKey::ONE_TO_MANY, ForeignKey::MANY_TO_MANY])) {
                                $value = $field;
                            }
                            else {
                                foreach ($entityObject->fields() as $fieldIsRightForeign) {
                                    if ($fieldIsRightForeign->foreign != null) {
                                        $parent = $fieldIsRightForeign->name . '_';
                                        $value = $this->_getDataRelation($line, $entityObject->getField(str_replace($fieldIsRightForeign->name . '_', '', $key))->foreign, $parent);
                                    }
                                }
                            }
                        }
                        else {
                            switch ($entityObject->getField($key)->type) {
                                case Field::FILE :
                                    $file = new File('', '', '', '');
                                    $file->hydrate($field);
                                    $value = $file;
                                    break;
                            }
                        }

                        $fieldName = str_replace($parent, '', $key);
                        $entityObject->set($fieldName, $value);
                    }
                }
            }
            else {
                $entityObject = new Multiple($line);
            }

            array_push($entities, $entityObject);
        }

        return new Collection($entities);
    }
546477
public function load(Entity $entity)
    {
        /** @var \Slick\Orm\Sql\Select $sql */
        $sql = call_user_func_array(
            array($this->getRelatedEntity(), 'find'),
            []
        );
        $pmk = $this->getEntity()->getPrimaryKey();
        $table = Entity\Manager::getInstance()->get($this->getRelatedEntity())
            ->getEntity()->getTableName();
        $sql->where(
            [
                "{$table}.{$this->getForeignKey()} = :id" => [
                    ':id' => $this->getEntity()->$pmk
                ]
            ]
        );
        return $sql->first();
    }
1307293
public function getMapperFor($entity)
    {
        return  $this->mappers->containsKey($entity)
            ? $this->mappers->get($entity)
            : $this->createMapper($entity);
    }
254539
public function getEntityChangeSet($entity)
    {
        $oid = spl_object_hash($entity);

        if (isset($this->entityChangeSets[$oid])) {
            return $this->entityChangeSets[$oid];
        }

        return array();
    }
991110
public function getAttributes($entity)
    {
        if ($entity->has($this->idField)) {
            $hidden = array_merge($entity->getHidden(), [$this->idField]);
            $entity->setHidden($hidden);
        }

        $attributes = $entity->toArray();

        // remove associated data so it won't appear inside jsonapi `attributes`
        foreach ($this->_repository->associations() as $association) {
            $propertyName = $association->getProperty();

            if ($association->type() === Association::MANY_TO_ONE) {
                $foreignKey = $association->getForeignKey();
                unset($attributes[$foreignKey]);
            }

            unset($attributes[$propertyName]);
        }

        // dasherize attribute keys (like `created_by`) if need be
        if ($this->_view->viewVars['_inflect'] === 'dasherize') {
            foreach ($attributes as $key => $value) {
                $dasherizedKey = Inflector::dasherize($key);

                if (!array_key_exists($dasherizedKey, $attributes)) {
                    $attributes[$dasherizedKey] = $value;
                    unset($attributes[$key]);
                }
            }
        }

        return $attributes;
    }
1338686
public function transform($entity)
	{
        if (!$this->isMultiple())
		{
			if (is_null($entity) || ! $entity instanceof $this->entityClass)
			{
				return '';
			}

			return strval($entity->getId());
		}

		if (is_array($entity))
		    $entity = new ArrayCollection($entity);
		if (is_iterable($entity))
			if ($entity->count() == 0)
				return [];
			else
			{
				return $entity->toArray();
			}


		if (is_object($entity) && $entity instanceof $this->entityClass)
		    return $entity->getId();

        if (is_null($entity))
            return null;

		throw new \Exception('What to do with: ' . json_encode($entity) . ' for class ' . $this->entityClass);
	}
763407
public function duplicate(Entity $entity = null)
    {
        $entity = $this->getEntityIfEmpty($entity);

        $data = $this->toArray();
        if (isset($data['id'])) {
            unset($data['id']);
        }

        foreach ($data as $key => &$val) {
            if ($key && array_key_exists($key . '_x', $data) && array_key_exists($key . '_y', $data)) {
                $val = [
                    $data[$key . '_x'],
                    $data[$key . '_y'],
                ];
            }
        }

        $record = new static($data);
        $record->save($entity);

        return $record;
    }
1004778
public function getRepository(Entity $entity)
    {
        $repo = $this->getRepositories()[get_class($entity)];

        return $this->$repo;
    }
174779
public function load(Entity $entity)
    {
        $data = $entity->getRawData();
        if (!is_array($data) || !isset($data[$this->getForeignKey()])) {
            return null;
        }
        /** @var Select $sql */
        $sql = call_user_func_array(
            [$this->getRelatedEntity(), 'find'],
            []
        );
        $pmk = Entity\Manager::getInstance()->get($this->getRelatedEntity())
            ->getEntity()->getPrimaryKey();
        $table = Entity\Manager::getInstance()->get($this->getRelatedEntity())
            ->getEntity()->getTableName();
        $sql-> where(
            [
                "{$table}.{$pmk} = :id" => [
                    ':id' => $data[$this->getForeignKey()]
                ]
            ]
        );
        return $sql->first();
    }
1153357
public function getEntityClassFull($entity)
    {
        $entity = $this->toString($entity);

        if (isset($this->cache[$entity])) {
            return $entity;
        }

        if ($this->managed || $this->isManagedByDoctrine($entity)) {
            /** @var \Doctrine\Common\Persistence\Mapping\ClassMetadata $classMetaData */
            $classMetaData        = $this->entityManager->getClassMetadata($entity);
            $entity               = $classMetaData->getName();
            $this->cache[$entity] = ['metadata' => $classMetaData];
            $this->managed        = false;
        } else {
            $this->cache[$entity] = [];
        }

        return $entity;
    }
1022971
public function get($entity)
    {
        $name = is_object($entity) ? get_class($entity) : $entity;
        if (!isset($this->_entities[$name])) {
            $this->_entities[$name] = new Descriptor(['entity' => $entity]);
        }
        return $this->_entities[$name];
    }
361710
public function getEntityArrayValues($entity)
    {
        $values = [];
        $properties = $this->getEntityProperties($entity);
        $metadata = $this->em->getClassMetadata(get_class($entity));
        foreach ($properties as $property) {
            $values[$property] = $metadata->getFieldValue($entity, $property);
        }
        return $values;
    }
1065106
private function getMetadataForClass($entity)
    {
        foreach ($this->registry->getManagers() as $em) {
            $cmf = new DisconnectedClassMetadataFactory();
            $cmf->setEntityManager($em);

            if (! $cmf->isTransient($entity)) {
                return new ClassMetadataCollection([$cmf->getMetadataFor($entity)]);
            }
        }

        return new ClassMetadataCollection([]);
    }
965895
public function serialize($entity)
    {
        return array($this->getName().'.'.$this->_target_parent_key => $entity->get($this->_target_parent_key));
    }
454002
public static function toArray(IEntity $entity, int $type = self::RELATIONSHIP_AS_IS, int $recursionLevel = 0): array
	{
		$return = [];
		$metadata = $entity->getMetadata();

		foreach ($metadata->getProperties() as $name => $metadataProperty) {
			if (!$entity->hasValue($name)) {
				$value = null;
			} else {
				$value = $entity->getValue($name);
			}

			if ($value instanceof IEntity) {
				if ($type === self::RELATIONSHIP_AS_ID) {
					$value = $value->getValue('id');
				} elseif ($type === self::RELATIONSHIP_AS_ARRAY) {
					if ($recursionLevel + 1 >= static::$maxRecursionLevel) {
						$value = null;
					} else {
						$value = static::toArray($value, $type, $recursionLevel + 1);
					}
				}

			} elseif ($value instanceof IRelationshipCollection) {
				if ($type === self::RELATIONSHIP_AS_ID) {
					$collection = [];
					foreach ($value as $collectionEntity) {
						$collection[] = $collectionEntity->getValue('id');
					}
					$value = $collection;

				} elseif ($type === self::RELATIONSHIP_AS_ARRAY) {
					$collection = [];
					if ($recursionLevel + 1 < static::$maxRecursionLevel) {
						foreach ($value as $collectionEntity) {
							$collection[] = static::toArray($collectionEntity, $type, $recursionLevel + 1);
						}
					}
					$value = $collection;
				}
			}

			$return[$name] = $value;
		}

		return $return;
	}
92069
private static function makeObject($entity)
    {
        $methodsGet = get_class_methods($entity);
        $methodsGet = array_filter($methodsGet, function($value) {
            return (bool) preg_match('/^get.*$/', $value);
        });
        $std = new \stdClass();
        foreach ($methodsGet as $attribute) {
            $name = str_replace('get', '', $attribute);
            $name = lcfirst($name);
            $std->$name = $entity->$attribute();
        }
        return $std;
    }
148795
protected function retrieveModels(array $entity = [])
    {
        $models = [];
        foreach ((array) $entity as $node) {
            $models[] = $this->models->get($node);
        }

        if (empty($models)) {
            $models = $this->models->all();
        }

        return $models;
    }