Пример #1
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;
 }
 /**
  * Dispatch an incoming event to the appropriate method
  *
  * Marshals arguments from the event parameters.
  *
  * @param  ResourceEvent $event
  * @return mixed
  */
 public function dispatch(ResourceEvent $event)
 {
     $this->event = $event;
     switch ($event->getName()) {
         case 'create':
             $data = $event->getParam('data', []);
             return $this->create($data);
         case 'delete':
             $id = $event->getParam('id', null);
             return $this->delete($id);
         case 'deleteList':
             $data = $event->getParam('data', []);
             return $this->deleteList($data);
         case 'fetch':
             $id = $event->getParam('id', null);
             return $this->fetch($id);
         case 'fetchAll':
             $queryParams = $event->getQueryParams() ?: [];
             return $this->fetchAll($queryParams);
         case 'patch':
             $id = $event->getParam('id', null);
             $data = $event->getParam('data', []);
             return $this->patch($id, $data);
         case 'patchList':
             $data = $event->getParam('data', []);
             return $this->patchList($data);
         case 'replaceList':
             $data = $event->getParam('data', []);
             return $this->replaceList($data);
         case 'update':
             $id = $event->getParam('id', null);
             $data = $event->getParam('data', []);
             return $this->update($id, $data);
         default:
             throw new Exception\RuntimeException(sprintf('%s has not been setup to handle the event "%s"', __METHOD__, $event->getName()));
     }
 }
 /**
  * @param ResourceEvent $event
  * @return array
  */
 protected function getBodyParams(ResourceEvent $event)
 {
     $params = (array) $event->getParam('data', array());
     return $params;
 }