public function initialize(IIdentity $identity)
 {
     if ($identity instanceof EntityIdentity && !$identity->isLoaded()) {
         $identity->load($this->em->getDao($identity->getEntityClass()));
     }
     return $identity;
 }
 public function handle($name, array $options, ClassMetadata $classMetadata, Configuration $configuration)
 {
     if (!empty($options['control'])) {
         return NULL;
     }
     if (!($mapping = MetadataHelpers::getAssociationMapping($classMetadata, $name, ClassMetadata::ONE_TO_ONE))) {
         return NULL;
     }
     $targetMetadata = $this->entityManager->getDao($mapping['targetEntity'])->getClassMetadata();
     return new ContainerBuilder($targetMetadata, new Container(), $configuration);
 }
Beispiel #3
0
 /**
  * Get event
  * @param integer $eventId
  * @return Event
  */
 public function getEvent($eventId)
 {
     // Má právo na editaci? (výchozí: ano)
     $canAccess = FALSE;
     $hasAccess = FALSE;
     $hasShare = FALSE;
     /** @var null|Event $event */
     $event = $this->eventDao->find($eventId);
     if ($event->isDeleted()) {
         throw new Nette\Application\BadRequestException($this->translator->translate('event.general.noId'));
     }
     // Is this api call?
     if ($this->user->getId() === 0) {
         $canAccess = TRUE;
     } else {
         /** @var \App\Model\Entity\User $userEntity */
         $userEntity = $this->em->getDao('\\App\\Model\\Entity\\User')->find($this->user->getId());
         /** @var \App\Model\Entity\Client $client */
         $client = $userEntity->getClient();
         // je uživatel ADMIN?
         if (($this->user->isInRole('ADMIN') || $this->user->isInRole('ACCOUNTANT')) && $this->isClientsEvent($event, $client)) {
             $canAccess = TRUE;
         } elseif (($this->user->isInRole('USER') || $this->user->isInRole('ACCOUNTANT')) && $this->isClientsEvent($event, $client)) {
             //požadavek klienta, aby šel
             $canAccess = TRUE;
         } else {
             // pokud nemá přiřazené oprávnění, má přidělené sdílení?
             if ($event->getShares() !== NULL) {
                 $hasShare = FALSE;
                 foreach ($event->getShares() as $clientShare) {
                     if ($client->getId() == $clientShare->getClient()->getId()) {
                         $hasShare = TRUE;
                         break;
                     }
                 }
             }
             // pokud ano, má přiřazená oprávnění pro event?
             if ($event->getAccesses() !== NULL) {
                 foreach ($event->getAccesses() as $clientAccess) {
                     $hasAccess = FALSE;
                     if ($client->getId() == $clientAccess->getReceiver()->getId() || $client->getId() == $clientAccess->getCreator()->getId()) {
                         $hasAccess = TRUE;
                         break;
                     }
                 }
             }
             // pokud ne, patří událost klientovi nebo sdílení, anebo přístup?
             if ($hasAccess || $hasShare) {
                 $canAccess = TRUE;
             }
         }
     }
     if ($canAccess) {
         // má přístup do události?
         return $event;
     } else {
         // jinak je přesměrován na dashboard s tím, že je upozorněn na to, že nemá oprávnění
         throw new Nette\Application\ForbiddenRequestException($this->translator->translate('event.general.noRights'));
     }
 }
 public function handle($name, array $options, ClassMetadata $classMetadata, Configuration $configuration)
 {
     if (!($mapping = MetadataHelpers::getAssociationMapping($classMetadata, $name, ClassMetadata::ONE_TO_MANY))) {
         return NULL;
     }
     $options += ['createDefault' => 0];
     $dao = $this->entityManager->getDao($mapping['targetEntity']);
     $containerPrototype = new Container();
     $replicator = new ClonnableReplicator(function (Container $container) use($containerPrototype) {
         $clone = function (Container $targetContainer, Container $sourceContainer) use(&$clone) {
             /** @var IComponent $component */
             foreach ($sourceContainer->getComponents() as $component) {
                 if ($component instanceof Container && !$component instanceof ClonnableReplicator) {
                     /** @var Container $component */
                     $container = new Container();
                     $container->setCurrentGroup($component->getCurrentGroup());
                     $container->onValidate = $component->onValidate;
                     $targetContainer[$component->getName()] = $container;
                     $clone($container, $component);
                 } else {
                     $targetContainer[$component->getName()] = $control = clone $component;
                     if ($control instanceof BaseControl) {
                         $clonner = function () {
                             /** @var BaseControl $this */
                             $this->control = clone $this->control;
                             $this->label = clone $this->label;
                         };
                         $clonner = $clonner->bindTo($control, $control);
                         $clonner();
                     }
                 }
             }
         };
         $clone($container, $containerPrototype);
     }, $options['createDefault']);
     return new ReplicatorBuilder($dao->getClassMetadata(), $replicator, $configuration, $containerPrototype);
 }
Beispiel #5
0
 /**
  * @param $entityName
  * @param EntityManager $entityManager
  * @return \Kdyby\Doctrine\EntityDao
  */
 public static function create($entityName, EntityManager $entityManager)
 {
     return $entityManager->getDao($entityName);
 }
Beispiel #6
0
 /**
  * @param Relation $relation
  * @param $entityName
  * @return array
  */
 public function fetchPairs(Relation $relation, $entityName)
 {
     $criteria = array();
     return $this->entityManager->getDao($entityName)->findPairs($criteria, $relation->getSelectedBy());
 }