예제 #1
0
 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())), 'Заявка на курс одобрена');
     }
 }
예제 #2
0
 /**
  * Сюда попадаем после оплаты если успешно
  * @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'));
     }
 }
예제 #3
0
 /**
  * Проверка теста
  * @Route("/demo_check_test/{moduleId}", name = "demo_check_test")
  * @Template("LearningMainBundle:Education:demo_test_failed.html.twig")
  */
 public function demo_check_test(Request $request, $moduleId)
 {
     if ($request->getMethod() != 'POST') {
         throw $this->createNotFoundException();
     }
     $em = $this->getDoctrine()->getManager();
     #$userCourse = $em->getRepository('LearningMainBundle:UserCourse')->findOneById(36);
     $data = new \DateTime();
     $userCourse = new UserCourse();
     $userCourse->setBallsRoh(0);
     $userCourse->setCourse($this->getDoctrine()->getRepository('LearningMainBundle:Course')->findOneById(47));
     $userCourse->setModules(array(0 => 71, 1 => 80));
     $userCourse->setCountModules(2);
     $userCourse->setPosition(2);
     $userCourse->setBallsRoh(0);
     $userCourse->setPassed(false);
     $userCourse->setStarts(new \DateTime());
     $userCourse->setEnds(new \DateTime('+ 1 Month'));
     #$this->checkAccessUserCourse($userCourse);
     $module = $em->getRepository('LearningMainBundle:CourseModule')->findOneById($moduleId);
     $questioned = $em->getRepository('LearningMainBundle:CourseModule')->countQuestions($moduleId);
     $repo = $em->getRepository('LearningMainBundle:CourseAnswer');
     $questions = $request->request->get('questions');
     if ($questioned != count($questions)) {
         # если студент сжульничал и удалил часть вопросов перед отправкой
         $referer = $request->headers->get('referer');
         return new RedirectResponse($referer);
     }
     # выясняем, на сколько вопросов студент ответил и на сколько не ответил
     $answered = $failed = 0;
     foreach ($questions as $questionId => $answers) {
         $answersPost = array_keys($answers);
         $answersCorrect = $repo->correctIdsOfQuestion($questionId);
         $diff = array_diff($answersPost, $answersCorrect);
         if (empty($diff)) {
             $answered++;
         } else {
             $failed++;
         }
     }
     # эффективность прохождения теста
     $evaluation = $answered / $questioned * 100;
     $userTest = new UserTest();
     $userTest->setUserCourse($userCourse);
     $userTest->setModule($module);
     $userTest->setQuestioned($questioned);
     $userTest->setAnswered($answered);
     $userTest->setFailed($failed);
     $userTest->setEvaluation($evaluation);
     # надо так же указать, какой раз проходится этот тест
     #$tries = $em->getRepository('LearningMainBundle:UserTest')->countTries($userCourseId, $moduleId);
     #$userTest->setTries($tries + 1);
     if ($failed > $module->getWrong()) {
         # не прошел
         return array('userCourse' => $userCourse, 'userTest' => $userTest, 'module' => $module);
     } else {
         # прошел тест
         $userTest->setPassed(new \DateTime());
         $userCourse->addPassedTests();
         $userCourse->addEvaluation($evaluation);
         return $this->render('LearningMainBundle:Education:demo_success.html.twig');
     }
 }
예제 #4
0
 /**
  * Сюда попадаем после оплаты если успешно
  * @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'));
     }
 }
예제 #5
0
 /**
  * @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)));
 }
예제 #6
0
 /**
  * @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);
 }
예제 #7
0
 /**
  * @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');
 }