Exemplo n.º 1
0
 /**
  * @param string $entityClass
  * @param array  $data
  *
  * @return array
  */
 public function filter(ResourceEvent $event, $entityClass, $data)
 {
     $validate = $this->validateOAuth2();
     if ($validate instanceof ApiProblem) {
         return $validate;
     }
     $request = $event->getRequest()->getQuery()->toArray();
     $identity = $event->getIdentity()->getAuthenticationIdentity();
     $data->user = $identity['user_id'];
     return $data;
 }
Exemplo n.º 2
0
 /**
  * @param ResourceEvent $event
  * @param string $entityClass
  * @param array  $parameters
  *
  * @return QueryBuilder
  */
 public function createQuery(ResourceEvent $event, $entityClass, $parameters)
 {
     $noteId = $event->getParam('id');
     /** @var Entity\Repository\User $userRepository */
     $userRepository = $this->getObjectManager()->getRepository('Secretary\\Entity\\User');
     /** @var Entity\User $user */
     $user = $userRepository->findOneBy(array('email' => $event->getIdentity()->getName()));
     /** @var Entity\Repository\Note $noteRepository */
     $noteRepository = $this->getObjectManager()->getRepository($entityClass);
     $queryBuilder = $noteRepository->fetchNoteWithUserDataQuery($noteId, $user->getId());
     return $queryBuilder;
 }
Exemplo n.º 3
0
 public function createQuery(ResourceEvent $event, $entityClass, $parameters)
 {
     $validate = $this->validateOAuth2(null);
     if ($validate instanceof ApiProblem) {
         return $validate;
     }
     $identity = $event->getIdentity()->getAuthenticationIdentity();
     $userId = $identity['user_id'];
     $user = $this->getObjectManager()->getRepository('RollNApi\\Entity\\User')->find($userId);
     $queryBuilder = $this->getObjectManager()->createQueryBuilder();
     $queryBuilder->select('row')->from($entityClass, 'row')->andwhere('row.user = :user')->setParameter('user', $user);
     return $queryBuilder;
 }
Exemplo n.º 4
0
 public function createQuery(ResourceEvent $event, $entityClass, $parameters)
 {
     $validate = $this->validateOAuth2(null);
     if ($validate instanceof ApiProblem) {
         return $validate;
     }
     $request = $this->getServiceLocator()->getServiceLocator()->get('Request')->getQuery()->toArray();
     $identity = $event->getIdentity()->getAuthenticationIdentity();
     $userId = $identity['user_id'];
     $user = $this->getObjectManager()->getRepository('RollNApi\\Entity\\User')->find($userId);
     $queryBuilder = $this->getObjectManager()->createQueryBuilder();
     $queryBuilder->select('row')->from($entityClass, 'row')->andwhere('row.user = :user')->setParameter('user', $user);
     if (isset($request['filter'])) {
         $metadata = $this->getObjectManager()->getMetadataFactory()->getAllMetadata();
         $filterManager = $this->getServiceLocator()->getServiceLocator()->get('ZfDoctrineQueryBuilderFilterManagerOrm');
         $filterManager->filter($queryBuilder, $metadata[0], $request['filter']);
     }
     if (isset($request['order-by'])) {
         $metadata = $this->getObjectManager()->getMetadataFactory()->getAllMetadata();
         $orderByManager = $this->getServiceLocator()->getServiceLocator()->get('ZfDoctrineQueryBuilderOrderByManagerOrm');
         $orderByManager->orderBy($queryBuilder, $metadata[0], $request['order-by']);
     }
     return $queryBuilder;
 }