public function profIndexAction(Request $request) { $professor = $this->getUser(); $course = new Course(); $course->setProfessor($professor); $form = $this->createForm(new CourseType($professor), $course); $form->handleRequest($request); if ($form->isValid()) { $generator = new SecureRandom(); $random = $generator->nextBytes(10); $random = bin2hex($random); $course->setHash($random); $em = $this->getDoctrine()->getManager(); $em->persist($course); $em->flush(); // Send email $mailer = $this->get('mathsup.course.mailer'); $mailer->sendCourseNotificationMail($course); $request->getSession()->getFlashBag()->add('success', 'course.flash.created'); $url = $this->generateUrl('mathsup_course'); return $this->redirect($url); } $courseRepo = $this->getDoctrine()->getRepository('MathsupCouponBundle:Course'); return $this->render('MathsupCouponBundle:Course:index.html.twig', array('new_form' => $form->createView(), 'last_not_validated_courses' => $courseRepo->findProfessorLastNotValidatedCourses($professor), 'last_courses' => $courseRepo->findProfessorLastValidatedCourses($professor))); }
public function sendCourseValidationMail(Course $course) { $url = $this->router->generate('mathsup_course', array(), true); $rendered = $this->getTemplating()->render($this->parameters['validation_email_template'], array('url' => $url)); $this->sendEmailMessage($rendered, $this->parameters['from_email'], $course->getProfessor()->getEmail()); }