Example #1
0
 /**
  * Checks if course was finished by given profile
  * 
  * @param \Calculus\BaranekBundle\Entity\Course $course
  * @param \Calculus\UserBundle\Entity\Profile $profile
  * @return boolean
  */
 private function isFinished(\Calculus\BaranekBundle\Entity\Course $course, \Calculus\UserBundle\Entity\Profile $profile) : bool
 {
     $finished = $profile->getCoursesFinished();
     return $finished->contains($course);
 }
 /**
  * Creates user from preuser
  * 
  * @param string $username
  * @param int $user_id
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundException if preuser, avatar or title don't exist
  * @return \Symfony\Component\HttpFoundation\Response
  * 
  * @Route("/Rejestracja/Potwierdzenie/{username}/{user_id}" , name="registration_confirm")
  * @Template()
  */
 public function confirmAction(string $username, int $user_id)
 {
     $preuser_rep = $this->getDoctrine()->getRepository('UserBundle:Preuser');
     $avatar_rep = $this->getDoctrine()->getRepository('CalculusUserAddsBundle:Avatar');
     $title_rep = $this->getDoctrine()->getRepository('BaranekBundle:Title');
     $profile = new Profile();
     $user = new User();
     $em = $this->getDoctrine()->getEntityManager();
     $avatar = $avatar_rep->findOneByName('muser.png');
     $title = $title_rep->findOneByName('Baranek');
     $preuser = $preuser_rep->findBy(array('username' => $username, 'id' => $user_id));
     if (!$title || !$preuser || !$avatar) {
         throw $this->createNotFoundException('Podany adres nie istnieje.');
     }
     $profile->setAvatar($avatar)->setActiveTitle($title)->addTitle($title);
     $encoderFactory = $this->get('security.encoder_factory');
     $encoder = $encoderFactory->getEncoder($user);
     $password = $encoder->encodePassword($preuser[0]->getPassword(), $user->getSalt());
     $user->setUsername($preuser[0]->getUsername())->setEmail($preuser[0]->getEmail())->setProfile($profile)->setPassword($password);
     $em->persist($profile);
     $em->persist($user);
     $em->remove($preuser[0]);
     $em->flush();
     return array('username' => $username);
 }