/** * @Template() * @ParamConverter("user", class="CoreUserBundle:User", options={"mapping":{"user_username" = "username"}}) * @ParamConverter("idea", class="AppBundle:Idea", options={"mapping":{"idea_slug" = "slug"}}) */ public function viewAction(Request $request, User $user, Idea $idea, $comment_id) { $doctrine = $this->getDoctrine(); $security = $this->get('security.authorization_checker'); $formService = $this->get('core.base.form'); $repository = $doctrine->getRepository('AppBundle:Comment'); $loggedUser = $security->isGranted('IS_AUTHENTICATED_FULLY') ? $this->getUser()->getId() : null; $hashUser = $formService->getUserHash($request); $comment = $repository->getById($comment_id, $loggedUser, $hashUser); $comment['comment_type'] = Comment::types[$comment['comment_type']]; if ($idea->getUserId() !== $user->getId() || $comment['idea_id'] !== $idea->getId()) { throw new $this->createNotFoundException(); } $viewData = []; $viewData['ideaUser'] = $user; $viewData['idea'] = $idea; $viewData['comment'] = $comment; $viewData['userHash'] = $hashUser; if ($comment['user_id'] && $this->getUser() && $comment['user_id'] == $this->getUser()->getId() || $security->isGranted('ROLE_MANAGER')) { $comment = $repository->find($comment['comment_id']); $formData = $request->request->get(CommentType::name); $responseData = $this->get('app.model.comment')->edit($formData, $comment); $viewData['commentForm'] = $responseData['form']->createView(); if ($responseData['valid']) { return $this->redirectToRoute('app_comment_view', ['user_username' => $user->getUsername(), 'idea_slug' => $idea->getSlug(), 'comment_id' => $responseData['embedded']['comment']['id']]); } } return $viewData; }
public function sendToUser($template, User $user, $parameters = []) { $template = $this->twig->loadTemplate($template); $parameters['user'] = $user; $subject = $template->renderBlock('subject', $parameters); $bodyHtml = $template->renderBlock('body_html', $parameters); $bodyText = $template->renderBlock('body_text', $parameters); return $this->send($subject, $bodyText, $bodyHtml, [$this->params['base.email'] => $this->params['base.contact']], [$user->getEmail() => $user->getUsername()]); }
public function equals(User $user) { if (!$user instanceof User) { return false; } if ($this->password !== $user->getPassword()) { return false; } if ($this->getSalt() !== $user->getSalt()) { return false; } if ($this->username !== $user->getUsername()) { return false; } if ($this->email !== $user->getEmail()) { return false; } return true; }
/** * @Template() * @ParamConverter("user", class="CoreUserBundle:User", options={"mapping":{"user_username" = "username"}}) * @ParamConverter("idea", class="AppBundle:Idea", options={"mapping":{"idea_slug" = "slug"}}) */ public function viewAction(Request $request, User $user, Idea $idea) { if ($idea->getUserId() !== $user->getId()) { throw $this->createNotFoundException(); } $security = $this->get('security.authorization_checker'); $formService = $this->get('core.base.form'); $doctrine = $this->getDoctrine(); $isOwner = false; $loggedUserId = null; $hashUser = $formService->getUserHash($request); if ($security->isGranted('IS_AUTHENTICATED_FULLY')) { $loggedUserId = $this->getUser()->getId(); $isOwner = $idea->getUserId() === $loggedUserId; } $viewData = []; $viewData['user'] = $user; $viewData['userHash'] = $hashUser; $viewData['idea'] = $idea->toArray($loggedUserId, ['user' => true]); $viewData['isOwner'] = $isOwner; /* IDEA */ ////////// if ($isOwner || $security->isGranted('ROLE_MANAGER')) { $formData = $request->request->get(IdeaType::name); $responseDataIdea = $this->get('app.model.idea')->edit($formData, $idea); $viewData['ideaForm'] = $responseDataIdea['form']->createView(); if ($responseDataIdea['valid']) { //$request->getSession()->getFlashBag()->add('success', "Idea were updated."); return $this->redirectToRoute('app_idea_view', ['user_username' => $user->getUsername(), 'idea_slug' => $responseDataIdea['embedded']['idea']['slug']]); } } /* COMMENT */ ///////////// $formData = $request->request->get(CommentGroupType::name); $responseDataComments = $this->get('app.model.comment')->createMultiple($idea, $formData, $hashUser); $viewData['commentGroupForm'] = $responseDataComments['form']->createView(); if ($responseDataComments['valid']) { $lastCommentId = end($responseDataComments['embedded']['comments'])['id']; $url = $this->generateUrl('app_idea_view', ['user_username' => $user->getUsername(), 'idea_slug' => $idea->getSlug()]); return $this->redirect($url . '#comment' . $lastCommentId); } $commentsByDate = $doctrine->getRepository('AppBundle:Comment')->getByIdea($idea, $loggedUserId, $hashUser); // Mise en forme des commentaires $viewData['commentsByUser'] = []; $viewData['commentsByType'] = []; $viewData['commentsTypes'] = []; foreach (Comment::types as $type) { $viewData['commentsByType'][$type] = []; $viewData['commentsTypes'][] = $type; } $commentTypes = []; foreach (array_values(Comment::types) as $type) { $commentTypes[$type] = []; } foreach ($commentsByDate as &$comment) { $comment['comment_type'] = Comment::types[$comment['comment_type']]; if (!isset($viewData['commentsByUser'][$comment['commentUser_username']])) { $viewData['commentsByUser'][$comment['commentUser_username']] = $commentTypes; } $viewData['commentsByUser'][$comment['commentUser_username']][$comment['comment_type']][] = $comment; $viewData['commentsByType'][$comment['comment_type']][] = $comment; } return $viewData; }