/** * Отображение конкретного курса * @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("/route-commented/{route}", name="route_commented") */ public function routeCommentedAction(Request $request, $route) { $referer = $request->headers->get('referer'); if (!$request->isMethod('POST')) { return $this->redirect($referer); } $em = $this->getDoctrine()->getManager(); $security = $this->get('security.context'); $isDoctor = $security->isGranted('ROLE_DOCTOR') || $security->isGranted('ROLE_STUDENT'); $comment = new RouteComment(); $comment->setRoute($route); $commentForm = $this->createForm(new CommentType(), $comment, array('em' => $em, 'anonymus' => !$isDoctor)); $commentForm->bind($request); if (!$commentForm->isValid()) { if (!$isDoctor) { $this->get('session')->getFlashbag()->add('captcha_fail', 'Неверно введен код с изображения'); } return $this->redirect($referer); } $postedComment = $commentForm->getData(); if ($user = $this->getUser()) { $postedComment->setAuthor($user); } $bbCodeParser = new \HTML_BBCodeParser2(); $bbCodeParser->addFilter('Basic'); $bbCodeParser->addFilter('Images'); $bbCodeParser->addFilter('Links'); $bbCodeParser->addFilter('Lists'); $postedComment->setText($bbCodeParser->qparse(strip_tags($postedComment->getText()))); $postedComment->setText(preg_replace('/\\[(\\w+)(?!\\w)[^\\]]*\\]((?:(?!\\[\\/\\1).)*?)\\[\\/\\1\\]/i', "", $postedComment->getText())); $postedComment->setText(nl2br($postedComment->getText())); if ($request->request->get('iBot') != 'Я точно не бот') { $refferer = $request->headers->get('referer'); return $this->redirect($refferer); } $em->persist($postedComment); $em->flush(); $em->refresh($postedComment); # уведомление редакторов о добавленном комментарии $message = \Swift_Message::newInstance()->setSubject('Новый комментарий')->setContentType('text/html')->setCharset('utf-8')->setFrom('*****@*****.**', 'Уведомление «Evrika.ru»')->setTo($this->container->getParameter('editor_emails'))->setBody($this->renderView('EvrikaMainBundle:Email:route_comment_notice.html.twig', array('comment' => $postedComment))); //$this->get('mailer')->send($message); # перенаправляем на комментарий, если он сохранен return $this->redirect($postedComment->getRoute() . '#comment_' . $postedComment->getId()); }
/** @Route("/vebinar/vstrecha", name="vebinar_vstrecha") */ public function vebinarVstrechaAction(Request $request) { $security = $this->get('security.context'); $isDoctor = $security->isGranted('ROLE_DOCTOR') || $security->isGranted('ROLE_STUDENT'); $em = $this->getDoctrine()->getManager(); $comment = new PublicationComment(); $publication = $this->getDoctrine()->getRepository('EvrikaMainBundle:Publication')->findOneById(11767); // 'publication' => $this->getDoctrine()->getRepository('EvrikaMainBundle:Publication')->findOneById(), $commentForm = $this->createForm(new CommentType(), $comment, array('em' => $em, 'anonymus' => !$isDoctor)); if ($request->isMethod('POST')) { $commentForm->bind($request); $now = new \DateTime(); if ($commentForm->isValid()) { $postedComment = $commentForm->getData(); $bbCodeParser = new \HTML_BBCodeParser2(); $bbCodeParser->addFilter('Basic'); $bbCodeParser->addFilter('Images'); $bbCodeParser->addFilter('Links'); $bbCodeParser->addFilter('Lists'); $postedComment->setText($bbCodeParser->qparse(strip_tags($postedComment->getText()))); $postedComment->setPublication($publication); $postedComment->setText(preg_replace('/\\[(\\w+)(?!\\w)[^\\]]*\\]((?:(?!\\[\\/\\1).)*?)\\[\\/\\1\\]/i', "", $postedComment->getText())); $postedComment->setText(nl2br($postedComment->getText())); $em->persist($postedComment); $em->flush(); $em->refresh($postedComment); } } $publication = $this->getDoctrine()->getRepository('EvrikaMainBundle:Publication')->findOneById(11767); $params = array('publication' => $publication, 'title' => 'Можно ли сохранить качество жизни пациенту, выбирая ингибитор протеазы?', 'comment_form' => $commentForm->createView(), 'category' => $publication->getCategory(), 'translation' => true); return $this->render('EvrikaMainBundle:Vebinar:vebinar_vstrecha.html.twig', $params); }
/** * Выводит информацию о компании * @Route("/about/{category}/{partnerId}", name = "about", defaults = {"category" = "about", "partnerId" = 0}) */ public function aboutAction($category = "about", $partnerId = 0) { $parameters = array('category' => $category); if ($category == 'partners') { $repository = $this->getDoctrine()->getManager()->getRepository('EvrikaMainBundle:Partner'); if ($partnerId) { $parameters['partner'] = $repository->find($partnerId); } else { $parameters['partners'] = $repository->findBy(array(), array('position' => 'ASC')); } } elseif ($category == 'news' and $partnerId == 0) { $parameters['publications'] = $this->getDoctrine()->getManager()->getRepository('EvrikaMainBundle:Publication')->orderPublications('21'); $parameters['bookmarks'] = $this->get('evrika.session_manager')->getBookmarks(); $parameters['feedType'] = 'fresh_feed'; } elseif ($category == 'news' and $partnerId != 0) { $parameters['publication'] = $this->getDoctrine()->getManager()->getRepository('EvrikaMainBundle:Publication')->findOneById($partnerId); $parameters['bookmarks'] = $this->get('evrika.session_manager')->getBookmarks(); $parameters['feedType'] = 'fresh_feed'; $em = $this->getDoctrine()->getManager(); $security = $this->get('security.context'); if ($security->isGranted('IS_AUTHENTICATED_REMEMBERED')) { $isDoctor = $security->isGranted('ROLE_DOCTOR') || $security->isGranted('ROLE_STUDENT'); $comment = new PublicationComment(); $comment->setPublication($parameters['publication']); $commentForm = $this->createForm(new CommentType(), $comment, array('em' => $em, 'anonymus' => !$isDoctor)); $request = $this->getRequest(); if ($request->isMethod('POST')) { $commentForm->bind($request); if ($commentForm->isValid()) { $postedComment = $commentForm->getData(); $bbCodeParser = new \HTML_BBCodeParser2(); $bbCodeParser->addFilter('Basic'); $bbCodeParser->addFilter('Images'); $bbCodeParser->addFilter('Links'); $bbCodeParser->addFilter('Lists'); $postedComment->setText($bbCodeParser->qparse(strip_tags($postedComment->getText()))); $postedComment->setText(preg_replace('/\\[(\\w+)(?!\\w)[^\\]]*\\]((?:(?!\\[\\/\\1).)*?)\\[\\/\\1\\]/i', "", $postedComment->getText())); $postedComment->setText(nl2br($postedComment->getText())); # посчитать комментарий у публикации if ($parameters['publication'] instanceof Publication) { $parameters['publication']->countComment(); } $em->persist($postedComment); $em->flush(); # уведомление редакторов о добавленном комментарии $message = \Swift_Message::newInstance()->setSubject('Новый комментарий')->setContentType('text/html')->setCharset('utf-8')->setFrom('*****@*****.**', 'Уведомление «Evrika.ru»')->setTo($this->container->getParameter('editor_emails'))->setBody($this->renderView('EvrikaMainBundle:Email:comment_notice.html.twig', array('comment' => $postedComment))); $this->get('mailer')->send($message); # уведомление пользователю, кому ответили (если тот подписан на эти уведомления) if ($parentComment = $postedComment->getParentComment()) { if ($quotedUser = $parentComment->getAuthor()) { if ($quotedUser->getCommentSubscribed()) { $message = \Swift_Message::newInstance()->setSubject('На ваш комментарий ответили')->setContentType('text/html')->setCharset('utf-8')->setFrom('*****@*****.**', 'Уведомление «Evrika.ru»')->setTo($quotedUser->getUsername())->setBody($this->renderView('EvrikaMainBundle:Email:comment_replied.html.twig', array('comment' => $postedComment, 'parentComment' => $parentComment))); $this->get('mailer')->send($message); } } } $url = $this->generateUrl('about', array('category' => $category, 'partnerId' => $partnerId)) . '#comment_' . $postedComment->getId(); return $this->redirect($url); } } $parameters['comment_form'] = $commentForm->createView(); } } $parameters['partnerId'] = $partnerId; return $this->render('EvrikaMainBundle:Info:about.html.twig', $parameters); }