/**
  * @Route("/admin/course_/cath/{cathedraId}", name = "admin_course_add")
  * @Template("LearningMainBundle:Admin:course_.html.twig")
  */
 public function addAction($cathedraId = null)
 {
     $portal = $this->container->getParameter('portal');
     $request = $this->getRequest();
     $em = $this->getDoctrine()->getManager();
     $course = new Course();
     $specialty = $em->getRepository('LearningMainBundle:Specialty')->findAll();
     $cathedra = $em->getRepository('LearningMainBundle:Cathedra')->findAll();
     if ($request->isMethod('POST')) {
         $cathId = $request->request->get('cathedra');
         $cath = $em->getRepository('LearningMainBundle:Cathedra')->findOneById($cathId);
         $course->setTitle($request->request->get('title'));
         $file = $request->files->get('image');
         if ($file) {
             $file = $file->getPathName();
             $newPath = $_SERVER['DOCUMENT_ROOT'] . '/upload/course/' . time() . '.jpg';
             move_uploaded_file($file, $newPath);
             $course->setImage($this->getArrayToImg($newPath));
         } else {
             $course->setImage('N;');
         }
         $course->setCathedra($cath);
         $course->setTimeToLearn($request->request->get('timeToLearn'));
         $course->setEnabled($request->request->get('enabled'));
         $course->setPrice($request->request->get('price'));
         $course->setRecording($request->request->get('recording'));
         $course->setPriceRoh(0);
         if ($this->get('security.context')->isGranted('ROLE_ADMIN')) {
             $orgTmp = $this->getDoctrine()->getRepository('LearningMainBundle:Organization')->findOneById($request->request->get('organization'));
             if ($orgTmp != null) {
                 $course->setOrganization($orgTmp);
             }
         }
         $course->setText($request->request->get('text'));
         if ($request->request->get('ballsRoh')) {
             $course->setBallsRoh(0);
         } else {
             $course->setBallsRoh(0);
         }
         if ($this->get('security.context')->isGranted('ROLE_ADMIN')) {
             if ($request->request->get('user') == null || $request->request->get('user') == 'null') {
             } else {
                 $user = $this->getDoctrine()->getRepository('LearningMainBundle:User')->findOneById($request->request->get('user'));
                 $course->setAuthor($user);
             }
         } else {
             $course->setAuthor($this->getUser());
         }
         if ($this->get('security.context')->isGranted('ROLE_ORGANIZATION')) {
             $course->setOrganization($this->getUser()->getOrganization());
         }
         $em->persist($course);
         if ($request->request->has('university')) {
             $universityId = $request->request->get('university');
             $university = $em->getRepository('LearningMainBundle:University')->findOneById($universityId);
             $course->setUniversity($university);
         }
         if ($request->request->get('specialty')) {
             $this->setSpecialties($course, $request->request->get('specialty'));
         } elseif ($request->request->get('specialization')) {
             $this->setSpecializations($course, $request->request->get('specialization'));
         }
         $em->flush();
         $em->refresh($course);
         $message = \Swift_Message::newInstance()->setSubject('Новый курс')->setContentType('text/html')->setCharset('utf-8')->setFrom('*****@*****.**', "Уведомление {$portal}")->setTo($this->container->getParameter('manager_emails'))->setBody($this->renderView('LearningMainBundle:Email:new_course_notice.html.twig', array('user' => $this->getUser(), 'course' => $course, 'portal' => $portal)));
         $this->get('mailer')->send($message);
         $this->get('session')->getFlashBag()->add('popup', 'Добавлен');
         return $this->redirect($this->generateUrl('admin_course_edit', array('courseId' => $course->getId())));
     }
     $thisCathedra = $cathedraId ? $em->getRepository('LearningMainBundle:Cathedra')->findOneById($cathedraId) : null;
     if ($this->getUser()->getOrganization()) {
         $organizationId = $this->getUser()->getOrganization()->getId();
     } else {
         $organizationId = null;
     }
     $organization = $organizationId ? $em->getRepository('LearningMainBundle:Organization')->findOneById($organizationId) : $em->getRepository('LearningMainBundle:Organization')->findAll();
     $specialization = $em->getRepository('LearningMainBundle:Specialization')->findAll();
     $universities = $this->getDoctrine()->getRepository('LearningMainBundle:University')->findAll();
     $tUsers = $em->getRepository('LearningMainBundle:user')->findAll();
     $users = array();
     foreach ($tUsers as $tUser) {
         if (in_array('ROLE_ADMIN', $tUser->getRoles()) || in_array('ROLE_ORGANIZATION', $tUser->getRoles()) || in_array('ROLE_EDITOR', $tUser->getRoles()) || in_array('ROLE_CURATOR', $tUser->getRoles())) {
             $users[] = $tUser;
         }
     }
     return array('specialty' => $specialty, 'specialization' => $specialization, 'portal' => $portal, 'cathedra' => $cathedra, 'organization' => $organization, 'thisCathedra' => $thisCathedra, 'users' => $users, 'universities' => $universities);
 }
Example #2
0
 /**
  * @Route("/admin/course-add/{cathedraId}/{projectId}", name = "admin_course_add", defaults = {"cathedraId" = null, "projectId" = null})
  * @Template("LearningMainBundle:Admin:course_.html.twig")
  */
 public function addAction($cathedraId = null, $projectId = null)
 {
     $portal = $this->container->getParameter('portal');
     $request = $this->getRequest();
     $em = $this->getDoctrine()->getManager();
     $course = new Course();
     $specialty = $em->getRepository('LearningMainBundle:Specialty')->findAll();
     $cathedra = $em->getRepository('LearningMainBundle:Cathedra')->findAll();
     if ($request->isMethod('POST')) {
         $cathId = $request->request->get('cathedra');
         $cath = $em->getRepository('LearningMainBundle:Cathedra')->findOneById($cathId);
         $course->setTitle($request->request->get('title'));
         $course->setCathedra($cath);
         $course->setTimeToLearn($request->request->get('timeToLearn'));
         $course->setEnabled($request->request->get('enabled'));
         $course->setPrice($request->request->get('price'));
         $course->setRecording($request->request->get('recording'));
         $course->setPriceRoh($request->request->get('priceRoh'));
         if ($this->get('security.context')->isGranted('ROLE_ADMIN')) {
             $orgTmp = $this->getDoctrine()->getRepository('LearningMainBundle:Organization')->findOneById($request->request->get('organization'));
             if ($orgTmp != null) {
                 $course->setOrganization($orgTmp);
             }
         }
         $course->setText($request->request->get('text'));
         if ($request->request->get('ballsRoh')) {
             $course->setBallsRoh($request->request->get('ballsRoh'));
         } else {
             $course->setBallsRoh(0);
         }
         if ($this->get('security.context')->isGranted('ROLE_ADMIN')) {
             if ($request->request->get('user') == null || $request->request->get('user') == 'null') {
             } else {
                 $user = $this->getDoctrine()->getRepository('LearningMainBundle:User')->findOneById($request->request->get('user'));
                 $course->setAuthor($user);
             }
         } else {
             $course->setAuthor($this->getUser());
         }
         if ($this->get('security.context')->isGranted('ROLE_ORGANIZATION')) {
             $course->setOrganization($this->getUser()->getOrganization());
         }
         $em->persist($course);
         if ($request->request->has('university')) {
             $universityId = $request->request->get('university');
             $university = $em->getRepository('LearningMainBundle:University')->findOneById($universityId);
             $course->setUniversity($university);
         }
         if ($request->request->get('specialty')) {
             $this->setSpecialties($course, $request->request->get('specialty'));
         } elseif ($request->request->get('specialization')) {
             $this->setSpecializations($course, $request->request->get('specialization'));
         }
         $em->flush();
         $em->refresh($course);
         $message = \Swift_Message::newInstance()->setSubject('Новый курс')->setContentType('text/html')->setCharset('utf-8')->setFrom('*****@*****.**', "Уведомление {$portal}")->setTo($this->container->getParameter('manager_emails'))->setBody($this->renderView('LearningMainBundle:Email:new_course_notice.html.twig', array('user' => $this->getUser(), 'course' => $course, 'portal' => $portal)));
         $this->get('mailer')->send($message);
         $this->get('session')->getFlashBag()->add('popup', 'Добавлен');
         /*
          * А теперь работа с проектом
          */
         /**
          * Тут подпись на курс
          */
         if ($request->request->get('project')) {
             $project = $this->getDoctrine()->getRepository('LearningMainBundle:Project')->findOneById($request->request->get('project'));
             $course->setProject($project);
             $em->flush();
             $em->refresh($course);
             $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 $this->redirect($this->generateUrl('admin_course_edit', array('courseId' => $course->getId())));
     }
     $thisCathedra = $cathedraId ? $em->getRepository('LearningMainBundle:Cathedra')->findOneById($cathedraId) : null;
     if ($this->getUser()->getOrganization()) {
         $organizationId = $this->getUser()->getOrganization()->getId();
     } else {
         $organizationId = null;
     }
     $organization = $organizationId ? $em->getRepository('LearningMainBundle:Organization')->findOneById($organizationId) : $em->getRepository('LearningMainBundle:Organization')->findAll();
     $specialization = $em->getRepository('LearningMainBundle:Specialization')->findAll();
     $universities = $this->getDoctrine()->getRepository('LearningMainBundle:University')->findAll();
     $tUsers = $em->getRepository('LearningMainBundle:user')->findAll();
     $users = array();
     foreach ($tUsers as $tUser) {
         if (in_array('ROLE_ADMIN', $tUser->getRoles()) || in_array('ROLE_ORGANIZATION', $tUser->getRoles()) || in_array('ROLE_EDITOR', $tUser->getRoles()) || in_array('ROLE_CURATOR', $tUser->getRoles())) {
             $users[] = $tUser;
         }
     }
     $user = $this->getUser();
     $isAdmin = $this->get('security.context')->isGranted('ROLE_ADMIN');
     if ($isAdmin) {
         $projects = $this->getDoctrine()->getRepository('LearningMainBundle:Project')->findAll();
     } else {
         $projects = $this->getDoctrine()->getRepository('LearningMainBundle:Project')->findByAuthor($user);
     }
     return array('specialty' => $specialty, 'specialization' => $specialization, 'portal' => $portal, 'cathedra' => $cathedra, 'organization' => $organization, 'thisCathedra' => $thisCathedra, 'users' => $users, 'universities' => $universities, 'projectId' => $projectId, 'projects' => $projects);
 }