コード例 #1
0
 /**
  * @param int $id
  *
  * @return Entity
  *
  * @throws \Exception
  */
 public function showEntityNameAction($id)
 {
     if ($entity = $this->entityRepository->find($id)) {
         return $entity->getName();
     }
     throw new \Exception();
 }
コード例 #2
0
 /**
  * {@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;
 }
コード例 #3
0
ファイル: DoctrineWriter.php プロジェクト: lmkhang/mcntw
 /**
  * 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;
 }
コード例 #4
0
 /**
  * {@inheritDoc}
  */
 public function find($id)
 {
     return $this->entityRepository->find($id);
 }
コード例 #5
0
 /**
  * Find one comment by its ID
  *
  * @return Comment or null
  **/
 public function findCommentById($id)
 {
     return $this->repository->find($id);
 }
コード例 #6
0
 /**
  * Get the CalendarEvent entity.
  * 
  * @param integer $id
  * @return CalendarEventInterface
  */
 public function getEvent($id)
 {
     return $this->repository->find($id);
 }
コード例 #7
0
 /**
  * {@inheritDoc}
  */
 public function findInvoiceById($id)
 {
     return $this->repository->find($id);
 }
コード例 #8
0
ファイル: OrderManager.php プロジェクト: hd-deman/Chewbacca
 /**
  * {@inheritdoc}
  */
 public function findOrder($id)
 {
     return $this->repository->find($id);
 }