Beispiel #1
0
 /**
  * Load data fixtures with the passed EntityManager
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $rm = $this->container->get('core_rest.resource_manager');
     //On récupère les groupes "utilisateurs"
     //$adminGroup = $this->getReference('admin-group');
     //$individualGroup = $this->getReference('individual-group');
     //$agencyGroup = $this->getReference('agency-group');
     //$builderGroup = $this->getReference('builder-group');
     //$developerGroup = $this->getReference('developer-group');
     //$instigatorGroup = $this->getReference('instigator-group');
     //On crée des nouveaux utilisateurs
     $userAdmin = new User();
     $userAdmin->setEmail('*****@*****.**');
     $userAdmin->setFirstName("Michel");
     $userAdmin->setLastName("Admin");
     $userAdmin->setPlainPassword('admin');
     $particulier = new User();
     $particulier->setEmail('*****@*****.**');
     $particulier->setFirstName("Josette");
     $particulier->setLastName("Salle");
     $particulier->setPlainPassword("particulier");
     //On affecte les groupes aux utilisateurs
     //$userAdmin->addGroup($adminGroup);
     //$particulier->addGroup($individualGroup);
     //UserBundle
     $userAdmin->addRole('ROLE_NOTIFICATION_DELETE');
     $userAdmin->addRole('ROLE_NOTIFICATION_UPDATE');
     $rm->create($userAdmin);
     $this->addReference('userAdmin', $userAdmin);
 }
Beispiel #2
0
 /**
  * @ParamConverter("user", class="CoreUserBundle:User", options={"mapping":{"user_username" = "username"}})
  * @ParamConverter("idea", class="AppBundle:Idea", options={"mapping":{"idea_slug" = "slug"}})
  * @ParamConverter("comment", class="AppBundle:Comment", options={"mapping":{"comment_id" = "id"}})
  */
 public function addAction(Request $request, User $user, Idea $idea, Comment $comment)
 {
     if ($idea->getUserId() !== $user->getId() || $comment->getIdeaId() !== $idea->getId()) {
         throw new $this->createNotFoundException();
     }
     $doctrine = $this->getDoctrine();
     $manager = $doctrine->getManager();
     $voteUser = $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY') ? $this->getUser() : null;
     $hash = $voteUser ? null : $this->get('core.base.form')->getUserHash($request);
     if ($voteUser && $voteUser->getId() === $comment->getUserId()) {
         $this->get('session')->getFlashBag()->add('error', "You can't vote for your own idea.");
     } else {
         $exist = $doctrine->getRepository('AppBundle:Vote')->findOneBy(['user' => $voteUser, 'hash' => $hash, 'comment' => $comment]);
         if ($exist) {
             $this->get('session')->getFlashBag()->add('error', 'You have already voted for this comment.');
         } else {
             $vote = new Vote();
             $vote->setComment($comment);
             if ($voteUser) {
                 $vote->setUser($voteUser);
             } else {
                 $vote->setHash($hash);
             }
             $manager->persist($vote);
             $manager->flush();
         }
     }
     return $this->end($request, $user, $idea, $comment);
 }
Beispiel #3
0
 /**
  * @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;
 }
Beispiel #4
0
 public function getIdeasByCommentUser(User $user)
 {
     $query = $this->getAll();
     $query = IdeaRepository::get($query);
     $query = UserRepository::get($query, 'i');
     return $query->andWhere('c.user_id = :user')->andWhere('i.user_id != :user')->setParameter('user', $user->getId())->andWhere('c.dateUpdate = (SELECT MAX(c2.dateUpdate) FROM AppBundle:Comment c2 WHERE c2.idea_id = i.id)')->addOrderBy('c.dateUpdate', 'DESC')->getQuery()->getArrayResult();
 }
Beispiel #5
0
 public function load(ObjectManager $manager)
 {
     $factory = $this->container->get('security.encoder_factory');
     $user = new User();
     $encoder = $factory->getEncoder($user);
     $user = new User();
     $user->setUsername('*****@*****.**');
     $user->setPassword($encoder->encodePassword($this->container->getParameter('user_password'), $user->getSalt()));
     $manager->persist($user);
     $address = new Address();
     $address->setAddress1('9 Place du Docteur Michel');
     $address->setCity('Foulain');
     $address->setZip('52800');
     $address->setCountry('France');
     $manager->persist($address);
     $client = new Client();
     $client->setFirstName('Delphine');
     $client->setLastName('Achini');
     $client->setEmail('*****@*****.**');
     $client->setPhone('0679402652');
     $client->setAddress($address);
     $client->setUser($user);
     $manager->persist($client);
     $manager->flush();
 }
Beispiel #6
0
 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()]);
 }
Beispiel #7
0
 /**
  * @Template()
  * @ParamConverter("user", class="CoreUserBundle:User", options={"mapping":{"user_username" = "username"}})
  */
 public function profileAction(Request $request, User $user)
 {
     $doctrine = $this->getDoctrine();
     $viewData = [];
     $viewData['user'] = $user->toArray($this->getUser()->getId());
     $viewData['ownerIdeas'] = $doctrine->getRepository('AppBundle:Idea')->getByUser($user);
     $viewData['commentedIdeas'] = $doctrine->getRepository('AppBundle:Comment')->getIdeasByCommentUser($user);
     $viewData['isOwner'] = $this->getUser() && $this->getUser()->getUsername() == $user->getUsername();
     return $viewData;
 }
 /**
  * @Method({"GET"})
  * @Template()
  */
 public function loginAction(Request $request)
 {
     $viewData = [];
     $authenticationUtils = $this->get('security.authentication_utils');
     $user = new User();
     $user->setUsername($authenticationUtils->getLastUsername());
     $userForm = $this->get('form.factory')->create(LoginType::class, $user);
     $viewData['form'] = $userForm->createView();
     return $viewData;
 }
 public function retrieveUserFilesAccess(\Core\UserBundle\Entity\User $user)
 {
     $qb = $this->getEntityManager()->createQuery("SELECT p, f FROM CoreFileServerBundle:Permissions p LEFT JOIN p.file f WHERE p.user = :user AND p.permission >= :permissions")->setParameter('user', $user->getId())->setParameter('permissions', 4);
     $result = $qb->getResult();
     $result = $this->getEntityManager()->getRepository('CoreFileServerBundle:File')->findAll();
     $return = array();
     return $result;
     foreach ($result as $r) {
         array_push($return, $r->getFile());
     }
     return $return;
 }
Beispiel #10
0
 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;
 }
Beispiel #11
0
 public function load(ObjectManager $manager)
 {
     $factory = $this->container->get('security.encoder_factory');
     $user = new User();
     $encoder = $factory->getEncoder($user);
     $user = new User();
     $user->setUsername('*****@*****.**');
     $user->setPassword($encoder->encodePassword($this->container->getParameter('user_password'), $user->getSalt()));
     $user->setRoles(array('ROLE_ADMIN'));
     $manager->persist($user);
     $manager->flush();
 }
Beispiel #12
0
 public function forceRegister($email, $username = null, $password = null)
 {
     if (!$username) {
         $username = $email;
     }
     if (!$password) {
         $password = $this->builder->randomPassword();
     }
     $user = new User();
     $user->setEmail($email);
     $user->setUsername($username);
     $user->setPlainPassword($password);
     $user->setPassword($this->encoder->encodePassword($user, $user->getPlainPassword()));
     $user->setLocale($this->params['locale']);
     $user->setActive(User::ACTIVE);
     $this->em->persist($user);
     $this->em->flush();
     return $user;
 }
Beispiel #13
0
 public function getByUser(User $user, $status = Idea::ACTIVE)
 {
     return $this->getAll($status)->andWhere('i.user_id = :user')->setParameter('user', $user->getId())->getQuery()->getArrayResult();
 }
Beispiel #14
0
 /**
  * @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;
 }