/**
  * @param int $id
  * @param string $name
  * @param string $email
  * @param string $bio
  * @return string
  */
 public function update($id, $name, $email, $bio)
 {
     $user = $this->authService->getLoggedUser();
     try {
         if ($user->getId() != $id) {
             throw new InvalidArgumentException('Você não pode alterar os dados de outro usuário');
         }
         $user = $this->userManager->update($id, $name, $email, !empty($bio) ? $bio : null);
         return json_encode(array('data' => array('id' => $user->getId(), 'username' => $user->getDefaultProfile()->getUsername())));
     } catch (InvalidArgumentException $error) {
         return json_encode(array('error' => $error->getMessage()));
     } catch (PDOException $error) {
         return json_encode(array('error' => 'Não foi possível salvar os dados na camada de persistência'));
     } catch (Exception $error) {
         return json_encode(array('error' => 'Erro interno no processamento da requisição'));
     }
 }
 /**
  * @param int $id
  * @param boolean $verifyOwnership
  * @return string
  */
 public function getById($id, $verifyOwnership = true)
 {
     $talk = $this->talkManager->findById($id, $verifyOwnership ? $this->authService->getLoggedUser() : null);
     if ($talk === null) {
         $response = array('error' => 'Não foi possível encontrar a submissão de trabalho.');
     } else {
         $response = array('id' => $talk->getId(), 'title' => $talk->getTitle(), 'type' => array('id' => $talk->getType()->getId(), 'description' => $talk->getType()->getDescription()), 'shortDescription' => $talk->getShortDescription(), 'longDescription' => $talk->getLongDescription(), 'complexity' => $talk->getComplexity(), 'tags' => $talk->getTags(), 'approved' => $talk->getApproved(), 'creationTime' => $talk->getCreationTime()->format(\DateTime::RFC3339));
     }
     return json_encode($response);
 }
 /**
  * @param int $talkId
  * @param string $likes
  * @throws \InvalidArgumentException
  * @return string
  */
 public function create($talkId, $likes)
 {
     try {
         $user = $this->authService->getLoggedUser();
         $talk = $this->talkManager->findById($talkId);
         if ($talk === null) {
             throw new \InvalidArgumentException('Submissão não encontrada');
         }
         $opinion = $this->opinionManager->create($user, $talk, $likes);
         $likesCount = $this->opinionManager->getLikesCount($talk->getEvent(), $user);
         return json_encode(array('data' => array('id' => $opinion->getId(), 'likesCount' => $likesCount)));
     } catch (\InvalidArgumentException $error) {
         return json_encode(array('error' => $error->getMessage()));
     } catch (\PDOException $error) {
         return json_encode(array('error' => 'Não foi possível salvar os dados na camada de persistência.'));
     } catch (\Exception $error) {
         return json_encode(array('error' => 'Erro interno no processamento da requisição.'));
     }
 }
 /**
  * @param string $redirectTo
  * @return string
  */
 public function resendPayment($redirectTo)
 {
     return $this->handleExceptions(function (AttendeeRegistrationService $attendeeRegistrator, Event $event, User $user) use($redirectTo) {
         return $attendeeRegistrator->resendPayment($event, $user, $redirectTo);
     }, array($this->attendeeRegistrator, $this->eventManager->findCurrentEvent(), $this->authService->getLoggedUser()));
 }
 /**
  * @return boolean
  */
 private function isAdmin()
 {
     $user = $this->authService->getLoggedUser();
     return $user !== null && $user->isAdmin();
 }