protected function execute(InputInterface $input, OutputInterface $output) { $container = $this->getContainer(); $em = $container->get('doctrine')->getManager(); $project = $em->getRepository('LearningMainBundle:Project')->findOneById(1); $course = $em->getRepository('LearningMainBundle:Course')->findOneById(43); $modulesIds = $em->getRepository('LearningMainBundle:Course')->modulesIdsOfCourse($course->getId()); // var_dump($project->getUserAccess()); // exit; foreach ($project->getUserAccess() as $userId) { if ($userId->getId() != 995) { continue; } $user = $em->getRepository('LearningMainBundle:User')->findOneById($userId->getId()); $output->writeln('Курс добавлен к ' . $user->getUsername()); $userCourse = new UserCourse(); $userCourse->setUser($user); $userCourse->setCourse($course); $userCourse->setBallsRoh(0); $userCourse->setCountModules(count($modulesIds)); $userCourse->setModules($modulesIds); // em->persist($userCourse); // $em->flush(); $user = $userCourse->getUser(); $container->get('email.service')->send($user->getUsername(), array('LearningMainBundle:Email:course_approved.html.twig', array('user' => $user, 'userCourse' => $userCourse, 'course' => $userCourse->getCourse())), 'Заявка на курс одобрена'); } }
/** * Сюда попадаем после оплаты если успешно * @Route("/course/payment/success", name="payment_course_success") * @Template("LearningMainBundle:Assist:payment.html.twig") */ public function successPaymentAction(Request $request) { $orderId = $request->query->get('shp_order'); // $orderId = $request->query->get('shp_order'); $price = floor($request->query->get('OutSum')); mail('*****@*****.**', 'оплата в РОХ', "orderId: {$orderId}, price: {$price}"); $em = $this->getDoctrine()->getManager(); $order = $this->getDoctrine()->getRepository('LearningMainBundle:Payment')->findOneById($orderId); // var_dump($order); // exit; $success = false; if ($order != null && $order->getPrice() == $price) { $course = $order->getCourse(); $order->setSuccess(true); $courseId = $course->getId(); $order->setBillnumber(true); $userCourse = $this->getDoctrine()->getManager()->createQuery("\n\t\t\tSELECT uc\n\t\t\tFROM LearningMainBundle:UserCourse uc\n\t\t\tWHERE uc.course = :courseId AND uc.user = :userId\n\t\t")->setParameters(array('courseId' => $courseId, 'userId' => $order->getUser()->getId()))->getResult(); if (!empty($userCourse)) { $userCourse = $userCourse[0]; } // if ($userCourse != null AND $userCourse->getReject() == 0) { // $referer = $request->headers->get('referer'); // return new RedirectResponse($referer); // } $user = $order->getUser(); $course = $em->getRepository('LearningMainBundle:Course')->findOneById($courseId); $modulesIds = $em->getRepository('LearningMainBundle:Course')->modulesIdsOfCourse($courseId); if (empty($userCourse)) { $userCourse = new UserCourse(); } $userCourse->setUser($user); $userCourse->setCourse($course); $userCourse->setBallsRoh($course->getBallsRoh()); $userCourse->setCountModules(count($modulesIds)); $userCourse->setModules($modulesIds); $tmpDate = new \DateTime('+' . $course->getRecording() . ' day'); $userCourse->setEnds($tmpDate); $userCourse->setStarts(new \DateTime()); $userCourse->setEnabledBy($order->getUser()); $userCourse->setEnabledDate(new \DateTime()); $userCourse->setEnabled(true); $em->persist($userCourse); $em->flush(); $em->refresh($userCourse); # надо оповестить о записи на курс админов и кураторов $this->get('email.service')->send($this->getAdminEmails($course), array('LearningMainBundle:Email:course_signup_notice.html.twig', array('user' => $user, 'course' => $course, 'userCourse' => $userCourse)), 'Курсант оставил заявку на курс'); #$this->get('session')->getFlashBag()->add('popup', 'Курс куплен'); $em->flush(); $success = true; // return array( // 'success' => $success, // 'order' => $order, // 'course' =>$course, // 'ucId' => $userCourse->getId() // // ); echo 'OK' . $orderId; exit; } else { return $this->redirect($this->generateUrl('payment_course_error')); } }
/** Если текущий пользователь не тот, который подписан на курс - выкидываем ошибку */ private function checkAccessUserCourse(UserCourse $userCourse) { $user = $this->getUser(); if (!$user || $user->getId() != $userCourse->getUser()->getId()) { throw new AccessDeniedException('Извините, у вас нет доступа к этой части сайта'); } }
/** * Сюда попадаем после оплаты если успешно * @Route("/course/payment/success", name="payment_course_success") * @Template("LearningMainBundle:Assist:payment.html.twig") */ public function successPaymentAction(Request $request) { $orderId = $request->query->get('shp_order'); $price = floor($request->query->get('OutSum')); mail('*****@*****.**', 'оплата в РНМОТ', "orderId: {$orderId}, price: {$price}"); $em = $this->getDoctrine()->getManager(); $order = $this->getDoctrine()->getRepository('LearningMainBundle:Payment')->findOneById($orderId); $success = false; if ($order != null && $order->getPrice() == $price) { if ($order->getTypePayment() == "account") { $userCourse = $this->getDoctrine()->getManager()->createQuery("\n SELECT uc\n FROM LearningMainBundle:User uc\n WHERE uc.id = :userId\n ")->setParameters(array('userId' => $order->getUser()->getId()))->getResult(); $userCourse->setActivateWithPay(1); $em->persist($userCourse); $em->flush(); $em->refresh($userCourse); # надо оповестить о записи на курс админов и кураторов $this->get('email.service')->send($this->getAdminEmails($course), array('LearningMainBundle:Email:course_signup_notice.html.twig', array('user' => $user, 'course' => $course, 'userCourse' => $userCourse)), 'Курсант оставил заявку на курс'); $em->flush(); $success = true; echo 'OK' . $orderId; exit; } else { $course = $order->getCourse(); $order->setSuccess(true); $courseId = $course->getId(); $order->setBillnumber(true); $userCourse = $this->getDoctrine()->getManager()->createQuery("\n \t\t\tSELECT uc\n \t\t\tFROM LearningMainBundle:UserCourse uc\n \t\t\tWHERE uc.course = :courseId AND uc.user = :userId\n \t\t")->setParameters(array('courseId' => $courseId, 'userId' => $order->getUser()->getId()))->getResult(); if (!empty($userCourse)) { $userCourse = $userCourse[0]; } $user = $order->getUser(); $course = $em->getRepository('LearningMainBundle:Course')->findOneById($courseId); $modulesIds = $em->getRepository('LearningMainBundle:Course')->modulesIdsOfCourse($courseId); if (empty($userCourse)) { $userCourse = new UserCourse(); } $userCourse->setUser($user); $userCourse->setCourse($course); //$userCourse->setBallsRoh($course->getBallsRoh()); $userCourse->setCountModules(count($modulesIds)); $userCourse->setModules($modulesIds); $tmpDate = new \DateTime('+' . $course->getRecording() . ' day'); $userCourse->setEnds($tmpDate); $userCourse->setStarts(new \DateTime()); $userCourse->setEnabledBy($order->getUser()); $userCourse->setEnabledDate(new \DateTime()); $userCourse->setEnabled(true); $em->persist($userCourse); $em->flush(); $em->refresh($userCourse); # надо оповестить о записи на курс админов и кураторов $this->get('email.service')->send($this->getAdminEmails($course), array('LearningMainBundle:Email:course_signup_notice.html.twig', array('user' => $user, 'course' => $course, 'userCourse' => $userCourse)), 'Курсант оставил заявку на курс'); $em->flush(); $success = true; echo 'OK' . $orderId; exit; } } else { return $this->redirect($this->generateUrl('payment_course_error')); } }
/** * @TODO OLD Подписывает пользователя на курс (потом должен одобрить куратор) * @TODO NEW Подписывает пользователя на бесплатный курс. Если что то не так то потом должен одобрить куратор * @Route("/signup/{courseId}", name = "signup") * @Secure(roles = "ROLE_STUDENT") */ public function signupAction(Request $request, $courseId) { $em = $this->getDoctrine()->getManager(); # если уже подписан на этот курс - возвращаемся /** @TODO Зачем так ? переделать */ $userCourse = $this->getDoctrine()->getManager()->createQuery("\n\t\t\tSELECT uc\n\t\t\tFROM LearningMainBundle:UserCourse uc\n\t\t\tWHERE uc.course = :courseId AND uc.user = :userId\n\t\t")->setParameters(array('courseId' => $courseId, 'userId' => $this->getUser()->getId()))->getResult(); if (!empty($userCourse)) { $userCourse = $userCourse[0]; } // if ($userCourse != null AND $userCourse->getReject() == 0) { // $referer = $request->headers->get('referer'); // return new RedirectResponse($referer); // } $user = $this->getUser(); $course = $em->getRepository('LearningMainBundle:Course')->findOneById($courseId); $modulesIds = $em->getRepository('LearningMainBundle:Course')->modulesIdsOfCourse($courseId); if (empty($userCourse)) { if ($course->getPriceRoh() == 0 and $this->getUser()->getRohId() != '' and $this->getUser()->getRohId() != null or $course->getPriceRoh() == 0) { $userCourse = new UserCourse(); $userCourse->setUser($user); $userCourse->setCourse($course); $userCourse->setBallsRoh($course->getBallsRoh()); $userCourse->setCountModules(count($modulesIds)); $userCourse->setModules($modulesIds); $tmpDate = new \DateTime('+' . $course->getRecording() . ' day'); $userCourse->setEnds($tmpDate); $userCourse->setStarts(new \DateTime()); $userCourse->setEnabledBy($this->getUser()); $userCourse->setEnabledDate(new \DateTime()); $userCourse->setEnabled(true); $em->persist($userCourse); $em->flush(); } else { $userCourse = new UserCourse(); $userCourse->setUser($user); $userCourse->setCourse($course); $userCourse->setBallsRoh($course->getBallsRoh()); $userCourse->setCountModules(count($modulesIds)); $userCourse->setModules($modulesIds); $em->persist($userCourse); $em->flush(); } } else { if ($userCourse->getReject() == 1) { $userCourse->setCountModules(count($modulesIds)); $userCourse->setModules($modulesIds); $userCourse->setReject(0); $userCourse->setEnds(null); $userCourse->setEnabled(0); $em->flush(); } if ($userCourse->getEnds() < new \DateTime('now')) { $userCourse->setCountModules(count($modulesIds)); $userCourse->setModules($modulesIds); $userCourse->setReject(0); $userCourse->setEnds(new \DateTime('+' . $course->getRecording() . ' days')); $userCourse->setEnabled(1); $em->flush(); } } # надо оповестить о записи на курс админов и кураторов $this->get('email.service')->send($this->getAdminEmails($course), array('LearningMainBundle:Email:course_signup_notice.html.twig', array('user' => $user, 'course' => $course, 'userCourse' => $userCourse)), 'Курсант оставил заявку на курс'); $this->get('session')->getFlashBag()->add('popup', 'Вы записались'); return $this->redirect($this->generateUrl('course', array('courseId' => $courseId))); }
public function getSertificate(UserCourse $userCourse) { $userCourse->setBallsRoh(24); $user = $userCourse->getUser(); $course = $userCourse->getCourse(); $rest = $userCourse->getBallsRoh() ? $userCourse->getBallsRoh() % 10 : 0; if (in_array($userCourse->getBallsRoh(), array(11, 12, 13, 14, 15, 16, 17, 18, 19))) { $ballsRohString = 'баллов'; } else { switch ($rest) { case 1: $ballsRohString = 'балл'; break; case 2: case 3: case 4: $ballsRohString = 'балла'; break; default: $ballsRohString = 'баллов'; break; } } switch ($userCourse->getPassed()->format('m')) { case 1: $month = 'января'; break; case 2: $month = 'февраля'; break; case 3: $month = 'марта'; break; case 4: $month = 'апреля'; break; case 5: $month = 'мая'; break; case 6: $month = 'июня'; break; case 7: $month = 'июля'; break; case 8: $month = 'августа'; break; case 9: $month = 'сентября'; break; case 10: $month = 'октября'; break; case 11: $month = 'ноября'; break; case 12: $month = 'декабря'; break; } $date = $userCourse->getPassed()->format('d') . ' ' . $month . ' ' . $userCourse->getPassed()->format('Y'); // $mpdfService = $this->$mpdf; $mpdfService = $this->container->get('tfox.mpdfport'); $engine = $this->container->get('templating'); $html = $engine->render('LearningMainBundle::certificate.html.twig', array('user' => $user, 'course' => $course, 'userCourse' => $userCourse, 'ballsRohString' => $ballsRohString, 'date' => $date)); $arguments = array('constructorArgs' => array('utf-8', 'A4-L', 5, 5, 5, 5, 5), 'writeHtmlMode' => null, 'writeHtmlInitialise' => null, 'writeHtmlClose' => null, 'outputFilename' => null, 'outputDest' => null); $mpdfService->generatePdfResponse($html, $arguments); }
/** * @Route("/admin/project/share-add-user/{projectId}", name = "project_user_add", options = {"expose" = true}) * @Secure(roles = "ROLE_MEDREP_ADMIN") */ public function projectAddUserAction(Request $request, $projectId) { $em = $this->getDoctrine()->getManager(); $project = $this->getDoctrine()->getRepository('LearningMainBundle:Project')->findOneById($projectId); $user = $this->getDoctrine()->getRepository('LearningMainBundle:User')->findOneById($request->request->get('id')); if ($user->isProjectSuccess($project)) { $user->removeProjectSuccess($project); foreach ($project->getCourses() as $course) { $userCourse = $this->getDoctrine()->getRepository('LearningMainBundle:UserCourse')->findOneBy(array('user' => $user, 'course' => $course)); if ($userCourse && $userCourse->getPassed() == null) { $em->remove($userCourse); } } $em->flush(); $txt = 'remove'; } else { $user->addProjectSuccess($project); foreach ($project->getCourses() as $course) { $userCourse = $this->getDoctrine()->getRepository('LearningMainBundle:UserCourse')->findBy(array('user' => $user, 'course' => $course)); if (!$userCourse) { $modulesIds = $em->getRepository('LearningMainBundle:Course')->modulesIdsOfCourse($course->getId()); if (empty($userCourse)) { if ($course->getPriceRoh() == 0 and $this->getUser()->getRohId() != '' and $this->getUser()->getRohId() != null or $course->getPriceRoh() == 0) { $userCourse = new UserCourse(); $userCourse->setUser($user); $userCourse->setCourse($course); $userCourse->setBallsRoh($course->getBallsRoh()); $userCourse->setCountModules(count($modulesIds)); $userCourse->setModules($modulesIds); $tmpDate = new \DateTime('+' . $course->getRecording() . ' day'); $userCourse->setEnds($tmpDate); $userCourse->setStarts(new \DateTime()); $userCourse->setEnabledBy($this->getUser()); $userCourse->setEnabledDate(new \DateTime()); $userCourse->setEnabled(true); $em->persist($userCourse); $em->flush(); } else { $userCourse = new UserCourse(); $userCourse->setUser($user); $userCourse->setCourse($course); $userCourse->setBallsRoh($course->getBallsRoh()); $userCourse->setCountModules(count($modulesIds)); $userCourse->setModules($modulesIds); $em->persist($userCourse); $em->flush(); } } else { if ($userCourse->getReject() == 1) { $userCourse->setCountModules(count($modulesIds)); $userCourse->setModules($modulesIds); $userCourse->setReject(0); $userCourse->setEnds(null); $userCourse->setEnabled(0); $em->flush(); } if ($userCourse->getEnds() < new \DateTime('now')) { $userCourse->setCountModules(count($modulesIds)); $userCourse->setModules($modulesIds); $userCourse->setReject(0); $userCourse->setEnds(new \DateTime('+' . $course->getRecording() . ' days')); $userCourse->setEnabled(1); $em->flush(); } } } } $em->flush(); $txt = 'add'; } $em->flush(); return new Response($txt); }
/** * @Route("/admin/course-refresh/{courseId}", name = "admin_course_refresh") */ public function refreshCourseAction(Request $request, $courseId) { $em = $this->getDoctrine()->getManager(); $course = $this->getDoctrine()->getRepository('LearningMainBundle:Course')->findOneById($courseId); $project = $course->getproject(); $users = $project->getUserAccess(); foreach ($users as $user) { $userCourse = $this->getDoctrine()->getRepository('LearningMainBundle:UserCourse')->findBy(array('user' => $user, 'course' => $course)); if (!$userCourse) { $modulesIds = $em->getRepository('LearningMainBundle:Course')->modulesIdsOfCourse($course->getId()); if (empty($userCourse)) { if ($course->getPriceRoh() == 0 and $this->getUser()->getRohId() != '' and $this->getUser()->getRohId() != null or $course->getPriceRoh() == 0) { $userCourse = new UserCourse(); $userCourse->setUser($user); $userCourse->setCourse($course); $userCourse->setBallsRoh($course->getBallsRoh()); $userCourse->setCountModules(count($modulesIds)); $userCourse->setModules($modulesIds); $tmpDate = new \DateTime('+' . $course->getRecording() . ' day'); $userCourse->setEnds($tmpDate); $userCourse->setStarts(new \DateTime()); $userCourse->setEnabledBy($this->getUser()); $userCourse->setEnabledDate(new \DateTime()); $userCourse->setEnabled(true); $em->persist($userCourse); $em->flush(); } else { $userCourse = new UserCourse(); $userCourse->setUser($user); $userCourse->setCourse($course); $userCourse->setBallsRoh($course->getBallsRoh()); $userCourse->setCountModules(count($modulesIds)); $userCourse->setModules($modulesIds); $em->persist($userCourse); $em->flush(); } } else { if ($userCourse->getReject() == 1) { $userCourse->setCountModules(count($modulesIds)); $userCourse->setModules($modulesIds); $userCourse->setReject(0); $userCourse->setEnds(null); $userCourse->setEnabled(0); $em->flush(); } if ($userCourse->getEnds() < new \DateTime('now')) { $userCourse->setCountModules(count($modulesIds)); $userCourse->setModules($modulesIds); $userCourse->setReject(0); $userCourse->setEnds(new \DateTime('+' . $course->getRecording() . ' days')); $userCourse->setEnabled(1); $em->flush(); } } } } $em->flush(); return new Response('Refresh: true'); }