Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function findAll()
 {
     $targets = MappingProviderInterface::PERSON;
     $mapping = $this->mapper->getMappingKeys($targets);
     $personData = $this->connection->createQueryBuilder()->select($mapping)->from('vbee_person')->execute()->fetchAll(\PDO::FETCH_NUM);
     return $personData !== false ? $this->hydrator->hydrate($personData, $targets, 'vbee_person') : null;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function findAll(array $options = [])
 {
     $targets = MappingProviderInterface::STUDY;
     $mapping = $this->mapper->getMappingKeys($targets);
     $studyData = $this->connection->createQueryBuilder()->select($mapping)->from('vbee_study')->execute()->fetchAll(\PDO::FETCH_NUM);
     return $studyData !== false ? $this->hydrator->hydrate($studyData, $targets, 'vbee_study') : null;
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function hydrate(array $data, $targets, $from)
 {
     $mappingPosition = $this->provider->getReversedMapping($targets);
     $mapping = $this->provider->getMapping($targets);
     $entityPool = [];
     $idsPool = [];
     // Extract objects
     foreach ($mappingPosition as $mappedValue => $position) {
         $entity = explode('.', $mappedValue)[0];
         $attribute = explode('.', $mappedValue)[1];
         // If the entity doesn't exist in the pool.
         if (!isset($entityPool[$entity])) {
             $entityPool[$entity] = [];
             $idsPool[$entity] = [];
         }
         foreach ($data as $index => $row) {
             $value = $this->extractValue($row, $mappingPosition, $mappedValue, $mapping[$mappedValue]['type']);
             if ($mapping[$mappedValue]['type'] === 'id') {
                 // If this object id doesn't exist in the entity pool.
                 if (!isset($entityPool[$entity][$value])) {
                     $entityPool[$entity][$value] = [];
                 }
                 // Save the id at the current cursor position
                 $idsPool[$entity][$index] = $value;
             }
             $entityPool[$entity][$idsPool[$entity][$index]][$attribute] = $value;
         }
     }
     // Build relations
     foreach ($mapping as $property => $propertyMapping) {
         $entity = explode('.', $property)[0];
         $attribute = explode('.', $property)[1];
         if ($propertyMapping['type'] !== 'relation') {
             continue;
         }
         foreach ($entityPool[$entity] as $id => $data) {
             if ($propertyMapping['owner']) {
                 $entityPool[$entity][$id][$propertyMapping['field']] =& $entityPool[$propertyMapping['entity']][$data[$attribute]];
             } else {
                 if (!isset($entityPool[$propertyMapping['entity']][$data[$attribute]][$propertyMapping['field']])) {
                     $entityPool[$propertyMapping['entity']][$data[$attribute]][$propertyMapping['field']] = [];
                 }
                 $entityPool[$propertyMapping['entity']][$data[$attribute]][$propertyMapping['field']][] =& $entityPool[$entity][$id];
             }
         }
     }
     foreach ($entityPool[$from] as $id => $entity) {
         $entityPool[$from][$id] = $this->getHydrator($from)->hydrate($entity);
     }
     return $entityPool[$from];
 }