/**
  * @inheritdoc
  */
 public function transform($value)
 {
     if (null === $value) {
         return [];
     }
     $text = is_null($this->property) ? (string) $value : $this->propertyAccessor->getValue($value, $this->property);
     $identifier = $this->propertyAccessor->getValue($value, $this->metadata->getIdentifier()[0]);
     return [$identifier ?: $text => $text];
 }
Exemple #2
0
 /**
  * @param object $entity
  * @return object
  */
 public function refresh($entity)
 {
     $column = $this->metaData->getIdentifier()[0];
     $queryResult = $this->em->createQueryBuilder()->select('*')->from($this->metaData->getTableName())->where($column . ' = :id')->setParameter('id', $entity->{$column})->execute()->fetch();
     if (!$queryResult) {
         throw new RuntimeException('Cannot refresh entity with ' . $column . ' = ' . $entity->{$column});
     }
     return $this->hydrate($entity, $queryResult);
 }
Exemple #3
0
 /**
  * Insert one new record using the Entity class.
  */
 public function execute(ObjectManager $manager, $insertedEntities, $generateId = false)
 {
     $obj = $this->class->newInstance();
     $this->fillColumns($obj, $insertedEntities);
     $this->callMethods($obj, $insertedEntities);
     if ($generateId) {
         $idsName = $this->class->getIdentifier();
         foreach ($idsName as $idName) {
             $id = $this->generateId($obj, $idName, $manager);
             $this->class->reflFields[$idName]->setValue($obj, $id);
         }
     }
     $manager->persist($obj);
     return $obj;
 }
 /**
  * Insert one new record using the Entity class.
  */
 public function execute(ObjectManager $manager, $insertedEntities, $generateId = false)
 {
     $obj = $this->class->newInstance();
     $this->fillColumns($obj, $insertedEntities);
     $this->callMethods($obj, $insertedEntities);
     if ($generateId) {
         $ids = $this->class->getIdentifier();
         for ($i = 0; $i < count($ids); $i++) {
             // foreach ($idsName as $idName) {
             $generateId = $this->generateId($obj, $ids[$i], $manager);
             $this->class->reflFields[$ids[$i]]->setValue($obj, $generateId);
         }
     }
     //echo "Wykonuję persist";
     $manager->persist($obj);
     $manager->flush($obj);
     return $obj;
 }
 /**
  * @param ClassMetadata $metadata
  *
  * @return string
  * @throws LogicException
  */
 protected function getIdentifier(ClassMetadata $metadata)
 {
     if ($metadata->isIdentifierComposite) {
         throw new \LogicException('Composite identifiers are not supported.');
     }
     return $metadata->getIdentifier()[0];
 }