Exemplo n.º 1
0
 public function createPaginatorResult(ManagedRepositoryInterface $repository, QueryBuilder $queryBuilder = null)
 {
     if ($queryBuilder === null) {
         $queryBuilder = $repository->createQueryBuilder();
     }
     return new PaginatorResult($repository, $queryBuilder);
 }
Exemplo n.º 2
0
 public function getRoot(ManagedRepositoryInterface $repository)
 {
     $className = $repository->getClassName();
     if (!isset($this->nodes[$className]) || !isset($this->nodes[$className]['_root'])) {
         throw new \InvalidArgumentException(sprintf('No root node exists for repository %s', $repository->getName()));
     }
     return $this->nodes[$className]['_root'];
 }
Exemplo n.º 3
0
 /**
  * Register a repository
  *
  * @param ManagedRepositoryInterface $repository
  * @return $this
  * @throws \LogicException
  */
 public function registerRepository(ManagedRepositoryInterface $repository)
 {
     $name = $repository->getName();
     if ($this->hasRepository($name)) {
         throw new \LogicException(sprintf('Repository %s is already registered.', $name));
     }
     $event = new ManagedRepositoryEvent($repository);
     $this->eventDispatcher->dispatch(ManagedRepositoryEvent::REGISTER, $event);
     $repository = $event->getRepository();
     $this->repositories[$name] = $repository;
     $this->classMap[$repository->getClassName()] = $name;
     return $repository;
 }
Exemplo n.º 4
0
 protected function getFormData(ManagedRepositoryInterface $repository, Request $request)
 {
     if (!($id = $request->get('id'))) {
         throw new HttpException(404, 'No ID was specified.');
     }
     if (!($entity = $repository->find($id))) {
         $humanName = $repository->queryMetadata('getEntityHumanName');
         $message = sprintf('No %s exists with ID %d.', $humanName, $id);
         throw new HttpException(404, $message);
     }
     $formData = new \stdClass();
     $formData->entity = $entity;
     return $formData;
 }
 public function __construct(ManagedRepositoryInterface $repository, UrlGeneratorInterface $urlGenerator, ControllerNodeInterface $currentControllerNode = null, $routeName = 'cms')
 {
     $rootNode = $repository->queryMetadata('getRootCmsNode');
     parent::__construct($rootNode, $routeName, $urlGenerator);
     $this->repository = $repository;
     $this->currentControllerNode = $currentControllerNode;
     $diff = $currentControllerNode === null ? [] : [$currentControllerNode->getActionName() => null];
     foreach (array_diff(['index', 'add'], array_keys($diff)) as $action) {
         if (!$this->hasChild($action) && $repository->queryMetadata('hasCmsNode', compact('action'))) {
             $node = $repository->queryMetadata('getCmsNode', compact('action'));
             $listNode = $this->createListNode($node);
             $this->wrapChild($listNode, $action, $node->getActionLabel(), false);
         }
     }
     $this->childNodes = array_diff_key($this->childNodes, $diff);
 }
Exemplo n.º 6
0
 /**
  * @param LifecycleEventArgs $event
  */
 public function postPersist(LifecycleEventArgs $event)
 {
     if (!($file = $this->getFile($event))) {
         return;
     }
     $file->getUploadedFile()->move($this->rootDir, $file->getPath());
     if (in_array($file->getMimeType(), $this->imageMimeTypes)) {
         $image = $this->imageRepository->createEntity();
         $image->__setFile($file);
         $size = getimagesize($this->rootDir . '/' . $file->getPath());
         $image->__setWidth($size[0]);
         $image->__setHeight($size[1]);
         $this->getImageRepository()->save($image);
     }
 }
Exemplo n.º 7
0
 protected function getFormData(ManagedRepositoryInterface $repository, Request $request)
 {
     $formData = new \stdClass();
     $formData->entity = $repository->createEntity();
     return $formData;
 }
Exemplo n.º 8
0
 /**
  * @return string
  */
 public function getLabel()
 {
     return sprintf('List %s', $this->repository->queryMetadata('getEntityHumanName', ['plural' => true]));
 }
Exemplo n.º 9
0
 /**
  * @param ManagedRepositoryInterface $repository
  * @param Request $request
  * @return \Doctrine\ORM\QueryBuilder
  */
 protected function createQueryBuilder(ManagedRepositoryInterface $repository, Request $request)
 {
     return $repository->createQueryBuilder($repository->getName());
 }
Exemplo n.º 10
0
 /**
  * @return int|mixed
  */
 public function getCount()
 {
     $alias = $this->repository->getName();
     return $this->queryBuilder->select("COUNT({$alias})")->getQuery()->getSingleScalarResult();
 }
Exemplo n.º 11
0
 public function isRepositoryEligible(ManagedRepositoryInterface $repository)
 {
     $crud = $repository->queryMetadata('getEntityCrud');
     $property = $this->isCreate() ? 'create' : 'update';
     return !empty($crud->{$property});
 }