/** * Отображение конкретного курса * @Route("/course/{courseId}", name="course") * @Template("LearningMainBundle:Course:course.html.twig") */ public function courseAction(Request $request, $courseId) { $em = $this->getDoctrine()->getManager(); $course = $em->getRepository('LearningMainBundle:Course')->findOneById($courseId); if ($course->getEnabled() == false) { throw $this->createNotFoundException(); } $modules = $em->getRepository('LearningMainBundle:Course')->modulesOfCourse($courseId); $user = $this->getUser(); $now = new \DateTime('now'); if ($user && $user->getDurationCertificate() != null && $user->getDurationCertificate() > $now) { $isStudent = true; } else { $isStudent = false; } $params = array('course' => $course, 'modules' => $modules, 'isStudent' => $isStudent, 'title' => $course . ' | ' . ($course->getCathedra() != null ? $course->getCathedra() : ($course->getOrganization() != null ? $course->getOrganization() != null : ''))); $params['myRating'] = 0; if ($isStudent) { $params['userCourse'] = $em->getRepository('LearningMainBundle:UserCourse')->ofUserCourse($this->getUser()->getId(), $courseId); if ($params['userCourse'] != null) { $params['myRating'] = $params['userCourse']['rating']; } $comment = new CourseComment(); $comment->setAuthor($this->getUser()); $comment->setCourse($course); $form = $this->createForm(new CommentType(), $comment); $form->handleRequest($request); if ($form->isValid()) { $bbCodeParser = new \HTML_BBCodeParser2(); $bbCodeParser->addFilter('Basic'); $bbCodeParser->addFilter('Images'); $bbCodeParser->addFilter('Links'); $bbCodeParser->addFilter('Lists'); $comment->setText($bbCodeParser->qparse(strip_tags($comment->getText()))); $comment->setText(preg_replace('/\\[(\\w+)(?!\\w)[^\\]]*\\]((?:(?!\\[\\/\\1).)*?)\\[\\/\\1\\]/i', "", $comment->getText())); $comment->setText(nl2br($comment->getText())); $em->persist($comment); $em->flush(); $em->refresh($comment); $this->get('session')->getFlashBag()->add('notice', 'Спасибо за отзыв!'); return $this->redirect($this->generateUrl('course', array('courseId' => $course->getId())) . '#comment_' . $comment->getId()); } $params['form'] = $form->createView(); } $userRating = $em->getRepository('LearningMainBundle:UserCourse')->findRating($course->getId()); $rating = 0; foreach ($userRating as $rat) { $rating += $rat->getRating(); } if (count($userRating) != 0) { $rating = round($rating / count($userRating)); } else { $rating = 0; } $params['rating'] = $rating; return $params; }
/** * Студент закончил обучение - выводим свои поздравления и статистику впридачу * @Route("study-complete/{userCourseId}", name = "study_complete") * @Template("LearningMainBundle:Education:study_complete.html.twig") * @Secure(roles = "IS_AUTHENTICATED_REMEMBERED") */ public function studyCompleteAction(Request $request, $userCourseId) { $em = $this->getDoctrine()->getManager(); $userCourse = $em->getRepository('LearningMainBundle:UserCourse')->findOneById($userCourseId); if ($userCourse === null || $this->getUser()->getId() !== $userCourse->getUser()->getId() || $userCourse->getPassed() === null) { throw new AccessDeniedException('Извините, у вас нет доступа к этой части сайта'); } $course = $userCourse->getCourse(); $params = array('userCourse' => $userCourse); $comment = new CourseComment(); $comment->setCourse($course); $comment->setAuthor($this->getUser()); $form = $this->createForm(new CommentType(), $comment); $form->handleRequest($request); if ($form->isValid()) { $em->persist($comment); $em->flush(); $em->refresh($comment); /* отправляем админам сообщение, что курс пройден */ $this->get('email.service')->send($this->getAdminEmails($course), array('LearningMainBundle:Email:course_commented_notice.html.twig', array('comment' => $comment, 'user' => $this->getUser(), 'course' => $course, 'userCourse' => $userCourse)), 'Курсант оставил отзыв к курсу'); $this->get('session')->getFlashBag()->add('notice', 'Спасибо за отзыв!'); return $this->redirect($this->generateUrl('course', array('courseId' => $course->getId())) . '#comment_' . $comment->getId()); } # подсчет рейтинга курса $userRating = $em->getRepository('LearningMainBundle:UserCourse')->findRating($course->getId()); $rating = 0; foreach ($userRating as $rat) { $rating += $rat->getRating(); } if (count($userRating) != 0) { $rating = round($rating / count($userRating)); } else { $rating = 0; } $params['form'] = $form->createView(); $params['rating'] = $rating; $params['myRating'] = $userCourse->getRating(); return $params; }