/**
  * {@inheritdoc}
  */
 public function reverseTransform($value)
 {
     if (!$value) {
         return null;
     }
     $entity = $this->repository->findOneBy(array($this->identifier => $value));
     if (null === $entity) {
         throw new TransformationFailedException(sprintf('Entity "%s" with identifier "%s"="%s" does not exist.', $this->repository->getClassName(), $this->identifier, $value));
     }
     return $entity;
 }
示例#2
0
 /**
  * @param mixed $value
  *
  * @throws BadRequestException
  *
  * @return object
  */
 public function filterIn($value)
 {
     if (!is_object($value)) {
         $entity = $this->repository->find($value);
     } elseif ($value instanceof QueryInterface) {
         $entity = $value->getEntity($this->repository);
     }
     $class = $this->repository->getClassName();
     if (!$entity instanceof $class) {
         throw new BadRequestException('Desired entity of type \'' . $this->repository->getClassName() . '\' could not be found.');
     }
     return $entity;
 }
示例#3
0
 public function findOneFolderByPath($path)
 {
     //Find a folder entity in db
     $folder = $this->folderRepo->findOneByPath($path);
     if (!$folder) {
         $class = $this->folderRepo->getClassName();
         $folder = new $class();
         $folder->setName(basename($path));
         $folder->setPath($path);
         $this->em->persist($folder);
     }
     return $folder;
 }
 /**
  * @param mixed $entity
  * @return mixed|null
  */
 public function transform($entity)
 {
     if (null === $entity) {
         return null;
     }
     $className = $this->repository->getClassName();
     if (!$entity instanceof $className) {
         throw new TransformationFailedException(sprintf('Object must be instance of %s, instance of %s has given.', $className, get_class($entity)));
     }
     $methodName = 'get' . ucfirst($this->property);
     if (!method_exists($entity, $methodName)) {
         throw new InvalidConfigurationException(sprintf('There is no getter for property "%s" in class "%s".', $this->property, $this->class));
     }
     return $entity->{$methodName}();
 }
示例#5
0
 public function total()
 {
     $metadata = $this->em->getClassMetadata($this->repository->getClassName());
     $identifiers = $metadata->getIdentifierFieldNames();
     $id = $identifiers[0];
     return $this->repository->createQueryBuilder("q")->select("COUNT(q.{$id})")->getQuery()->getSingleScalarResult();
 }
示例#6
0
 /**
  * Returns OrderType entity with given id.
  *
  * @param int $typeId
  *
  * @throws EntityNotFoundException
  *
  * @return null|OrderType
  */
 public function getOrderTypeEntityById($typeId)
 {
     // Get desired status.
     $typeEntity = $this->orderTypeRepository->find($typeId);
     if (!$typeEntity) {
         throw new EntityNotFoundException($this->orderTypeRepository->getClassName(), $typeId);
     }
     return $typeEntity;
 }
示例#7
0
 /**
  * @return mixed
  */
 public function create()
 {
     $className = $this->source->getClassName();
     return new $className();
 }
 /**
  * @return string
  */
 public function getClassName()
 {
     return parent::getClassName();
 }
示例#9
0
 public function __construct(EntityRepository $repository)
 {
     $this->repository = $repository;
     $this->entity = $repository->getClassName();
 }
 /**
  * @param $entities
  * @param $params
  * @param $method
  * @return bool
  */
 public function batchUpdate($entities, $params, $method)
 {
     $className = $this->repository->getClassName();
     return $this->formHandler->batchProcessForm(new EntitiesHolder($entities), ['entities' => $params], $method, new $className());
 }
 /**
  * Returns the class name of the object managed by the repository.
  *
  * @return string
  */
 public function getClassName()
 {
     return $this->repository->getClassName();
 }
示例#12
0
 /**
  * @param int $id
  * @param EntityRepository $repository
  *
  * @param null $label
  *
  * @return bool
  * @throws \Doctrine\ORM\NoResultException
  * @throws \Doctrine\ORM\NonUniqueResultException
  */
 public function addElement($id = 0, EntityRepository $repository, $label = NULL)
 {
     $em = $this->getEntityManager();
     $qb = $repository->createQueryBuilder('a');
     $class = $repository->getClassName();
     /* @var TreeInterface $entry */
     $entry = new $class();
     if (!empty($label)) {
         $entry->setLabel($label);
     }
     if ($id == 0) {
         // get max_right
         $query = $qb->select('MAX(a.rgt) as max_rgt')->getQuery()->getSingleResult();
         if (isset($query['max_rgt'])) {
             $lft = $query['max_rgt'];
             $rgt = $lft + 1;
             /* @var TreeInterface $entry */
             $entry->setLft($lft)->setRgt($rgt)->setDepth(1);
             $em->persist($entry);
             $em->flush();
             return $entry->getId();
         }
         // add to parent
     } else {
         /* @var TreeInterface|NULL $parent */
         $parent = $repository->find($id);
         //dump($parent);
         if ($parent !== NULL) {
             $lft = $parent->getRgt();
             $rgt = $lft + 1;
             $queries = array();
             // update rgt
             $queries[] = $qb->update()->set('a.rgt', 'a.rgt + 2')->where('a.rgt >= :lft')->setParameter('lft', $lft)->getQuery()->getResult();
             // update lft
             $queries[] = $qb->update()->set('a.lft', 'a.lft + 2')->where('a.lft > :lft')->setParameter('lft', $lft)->getQuery()->getResult();
             // set entry
             $entry->setLft($lft)->setRgt($rgt)->setParent($parent)->setDepth($parent->getDepth() + 1);
             $em->persist($entry);
             $em->flush();
             return $entry->getId();
         }
     }
     return false;
 }
 /**
  * Deletes the translatable entities for locale
  *
  * @param EntityRepository $repository
  * @param LocaleInterface  $locale
  * @param OutputInterface  $output
  */
 protected function deleteTranslatableEntities(EntityRepository $repository, LocaleInterface $locale, OutputInterface $output)
 {
     $entityManager = $this->getDoctrineHelper()->getEntityManager();
     $criteria = new Criteria();
     $criteria->where($criteria->expr()->eq('locale', $locale->getCode()));
     $collection = $repository->matching($criteria);
     $collection->map(function (LocaleAwareInterface $entity) use($entityManager) {
         $entityManager->remove($entity);
     });
     $output->write(sprintf('Deleted <info>%s</info> entities <info>%s</info>', $collection->count(), $repository->getClassName()), true);
 }
 protected function truncate(EntityRepository $repository)
 {
     $classMetaData = $this->entityManager->getClassMetadata($repository->getClassName());
     $connection = $this->entityManager->getConnection();
     $dbPlatform = $connection->getDatabasePlatform();
     $sql = $dbPlatform->getTruncateTableSql($classMetaData->getTableName());
     $connection->executeUpdate($sql);
 }