/** * @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.')); } }