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())), 'Заявка на курс одобрена'); } }
/** Если текущий пользователь не тот, который подписан на курс - выкидываем ошибку */ private function checkAccessUserCourse(UserCourse $userCourse) { $user = $this->getUser(); if (!$user || $user->getId() != $userCourse->getUser()->getId()) { throw new AccessDeniedException('Извините, у вас нет доступа к этой части сайта'); } }
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); }