/** * @param int $id * * @return Entity * * @throws \Exception */ public function showEntityNameAction($id) { if ($entity = $this->entityRepository->find($id)) { return $entity->getName(); } throw new \Exception(); }
/** * {@inheritdoc} */ public function writeItem(array $item) { $this->counter++; $entity = null; // If the table was not truncated to begin with, find current entities // first if (false === $this->truncate) { if ($this->index) { // If the table has a composite key if (!empty($this->compositeKey) && is_array($this->compositeKey)) { $composite = ''; foreach ($this->compositeKey as $key => $index) { $composite .= $item[$index]; } $value = $composite; } else { $value = $item[$this->index]; } $entity = $this->entityRepository->findOneBy(array($this->index => $value)); } else { $entity = $this->entityRepository->find(current($item)); } } if (!$entity) { $entity = $this->getNewInstance(); } $fieldNames = array_merge($this->entityMetadata->getFieldNames(), $this->entityMetadata->getAssociationNames()); foreach ($fieldNames as $fieldName) { $value = null; if (isset($item[$fieldName])) { $value = $item[$fieldName]; } elseif (method_exists($item, 'get' . ucfirst($fieldName))) { $value = $item->{'get' . ucfirst($fieldName)}; } if (null === $value) { continue; } if (!$value instanceof \DateTime || $value != $this->entityMetadata->getFieldValue($entity, $fieldName)) { $setter = 'set' . ucfirst($fieldName); $this->setValue($entity, $value, $setter); } } $this->entityManager->persist($entity); if ($this->counter % $this->batchSize == 0) { $this->entityManager->flush(); $this->entityManager->clear($this->entityName); } return $this; }
/** * Finds existing entity or create a new instance */ protected function findOrCreateItem(array $item) { $entity = null; // If the table was not truncated to begin with, find current entity // first if (false === $this->truncate) { if ($this->lookupFields) { $lookupConditions = array(); foreach ($this->lookupFields as $fieldName) { $lookupConditions[$fieldName] = $item[$fieldName]; } $entity = $this->entityRepository->findOneBy($lookupConditions); } else { $entity = $this->entityRepository->find(current($item)); } } if (!$entity) { return $this->getNewInstance(); } return $entity; }
/** * {@inheritDoc} */ public function find($id) { return $this->entityRepository->find($id); }
/** * Find one comment by its ID * * @return Comment or null **/ public function findCommentById($id) { return $this->repository->find($id); }
/** * Get the CalendarEvent entity. * * @param integer $id * @return CalendarEventInterface */ public function getEvent($id) { return $this->repository->find($id); }
/** * {@inheritDoc} */ public function findInvoiceById($id) { return $this->repository->find($id); }
/** * {@inheritdoc} */ public function findOrder($id) { return $this->repository->find($id); }