Ejemplo n.º 1
0
 /**
  * @Route("/admin/organization_", name = "admin_organization_add")
  * @Template("LearningMainBundle:Admin:organization_.html.twig")
  */
 public function addAction()
 {
     $request = $this->getRequest();
     $organization = new Organization();
     if ($request->isMethod('POST')) {
         $em = $this->getDoctrine()->getManager();
         $organization->setTitle($request->request->get('title'));
         #$organization->setUrl($request->request->get('url'));
         #$organization->setKeywords($request->request->get('metaKey'));
         #$organization->setDescription($request->request->get('metaDesc'));
         $organization->setEnabled($request->request->get('enabled'));
         $organization->setBody($request->request->get('text'));
         $organization->setEmail($request->request->get('email'));
         $organization->setContact($request->request->get('contact'));
         $em->persist($organization);
         $em->flush();
         $em->refresh($organization);
         $organization->setUrl($organization->getId());
         $em->flush();
         $file = $request->files->get('fileImg');
         if ($file != NULL) {
             $origName = $file->getClientOriginalName();
             $format = substr($origName, strlen($origName) - 4);
             $name = substr($origName, 0, strlen($origName) - 4);
             //Извлекаем формат (бывает только PDF и FLV)
             $name .= '_' . time() . $format;
             if ($format != '.png' && $format != '.jpg') {
                 $error = 'Ошибка сохранения: необходимо загрузить картинку формата png или jpg';
                 return array('organization' => $organization, 'error' => $error);
             }
             $file->move('upload/company', $name);
             $organization->setImageFile($name);
         }
         $this->get('session')->getFlashBag()->add('popup', 'Добавлена');
         return $this->redirect($this->generateUrl('admin_organization_lists'));
     } else {
         return array();
     }
 }
Ejemplo n.º 2
0
 /**
  * @Route("/adm/event_", name = "admin_event_add")
  * @Template("LearningMainBundle:Admin:event_.html.twig")
  */
 public function addAction()
 {
     $request = $this->getRequest();
     $event = new Event();
     $country = $this->getDoctrine()->getRepository('LearningMainBundle:Country')->findOneById(1);
     $regions = $this->getDoctrine()->getRepository('LearningMainBundle:Region')->findByCountry($country);
     $cathedra = $this->getDoctrine()->getRepository('LearningMainBundle:Cathedra')->findAll();
     $university = $this->getDoctrine()->getRepository('LearningMainBundle:University')->findAll();
     $organizations = $this->getDoctrine()->getRepository('LearningMainBundle:Organization')->findAll();
     $specializations = $this->getDoctrine()->getRepository('LearningMainBundle:Specialization')->findAll();
     if ($request->isMethod('POST')) {
         $em = $this->getDoctrine()->getManager();
         $event->setTitle($request->request->get('title'));
         $event->setAuthor($this->getUser());
         $event->setCode($request->request->get('code'));
         $event->setPrice($request->request->get('price'));
         $event->setRegion($this->getDoctrine()->getRepository('LearningMainBundle:Region')->findOneById($request->request->get('region')));
         $event->setCity($this->getDoctrine()->getRepository('LearningMainBundle:City')->findOneById($request->request->get('city')));
         $event->setIsState($request->request->get('isState'));
         /* Для гос учреждений */
         $event->setUniversity($this->getDoctrine()->getRepository('LearningMainBundle:University')->findOneById($request->request->get('university')));
         $event->setCathedra($this->getDoctrine()->getRepository('LearningMainBundle:Cathedra')->findOneById($request->request->get('cathedra')));
         $event->setCountHour($request->request->get('countHour'));
         /* Для организаций */
         if ($request->request->get('organization') == 0) {
             $organization = new Organization();
             $organization->setTitle($request->request->get('newOrg'));
             $organization->addUser($this->getUser());
             $organization->setBody('');
             $em->persist($organization);
             $em->flush($organization);
             $em->refresh($organization);
             $event->setOrganization($organization);
         } else {
             $event->setOrganization($this->getDoctrine()->getRepository('LearningMainBundle:Organization')->findOneById($request->request->get('organization')));
         }
         /* -- */
         $event->setForm($request->request->get('form'));
         $event->setAuthor($this->getUser());
         $event->setTimes($request->request->get('times'));
         $event->setPlace($request->request->get('place'));
         $event->setBalls($request->request->get('balls'));
         $event->setEnabled($request->request->get('enabled'));
         $event->setKeywords($request->request->get('keywords'));
         $event->setDescription($request->request->get('description'));
         $event->setBody($request->request->get('text'));
         $event->setContacts($request->request->get('contacts'));
         $event->setContactsBid($request->request->get('contactsBid'));
         if ($request->request->get('diplom1')) {
             $diplom = '1';
         } else {
             $diplom = '0';
         }
         if ($request->request->get('diplom2')) {
             $diplom .= '1';
         } else {
             $diplom .= '0';
         }
         if ($request->request->get('diplom3')) {
             $diplom .= '1';
         } else {
             $diplom .= '0';
         }
         $event->setDiplom($diplom);
         $em->persist($event);
         $em->flush();
         $em->refresh($event);
         $this->setSpecialization($event, $request->request->get('specializations'));
         $em->flush();
         $starts = $request->request->get('starts');
         $ends = $request->request->get('ends');
         for ($i = 1; $i <= count($starts); $i++) {
             $date = new EventDate();
             $tmpStarts = new \DateTime($starts[$i]);
             $tmpEnds = new \DateTime($ends[$i]);
             $date->setEvent($event);
             $date->setStarts($tmpStarts);
             $date->setEnds($tmpEnds);
             $em->persist($date);
             $em->flush();
         }
         $files = $request->files->get('filedoc');
         if (!is_dir('upload/events')) {
             mkdir('upload/events', 0775);
         }
         $j = 1;
         foreach ($files as $file) {
             if ($file != NULL) {
                 $origName = $file->getClientOriginalName();
                 $format = substr($origName, strrpos($origName, '.'));
                 $name = substr($origName, 0, strlen($origName) - 4);
                 $name .= '_' . time() . $format;
                 if ($format != '.rar' && $format != '.zip' && $format != '.pdf' && $format != '.doc' && $format != '.docx' && $format != '.zip' && $format != '.jpg' && $format != '.png' && $format != '.xls' && $format != '.xlsx' && $format != '.jpeg') {
                     $error = 'Ошибка сохранения: недопустимое расширение файла (разрешены rar, zip, pdf, doc, docx, jpg, jpeg, png)';
                     return $this->redirect($this->generateUrl('admin_event_edit', array('eventId' => $event->getId(), 'error' => $error)));
                 }
                 $file->move('upload/events/', $name);
                 $EventFile = new File();
                 $EventFile->setEvent($event);
                 $EventFile->setFiledoc($name);
                 $EventFile->setTitle($request->request->get('filename')[$j]);
                 $em->persist($EventFile);
                 $em->flush();
             }
             $j++;
         }
         return $this->redirect($this->generateUrl('admin_event_edit', array('eventId' => $event->getId())));
     } else {
         return array('regions' => $regions, 'cathedra' => $cathedra, 'university' => $university, 'organizations' => $organizations, 'specializations' => $specializations);
     }
 }
Ejemplo n.º 3
0
 /**
  * @route("/organization-register", name="organization_register" )
  * @Template("LearningMainBundle:Auth:organization_register.html.twig")
  */
 public function organizationRegisterAction()
 {
     if ($this->get('security.context')->isGranted('ROLE_ORGANIZATION') && $this->getUser()->getOrganization() == null) {
         return $this->redirect($this->generateUrl('_index'));
     }
     $request = $this->getRequest();
     $organization = new Organization();
     if ($request->isMethod('POST')) {
         $em = $this->getDoctrine()->getManager();
         $organization->setTitle($request->request->get('title'));
         $organization->setEnabled($request->request->get('enabled'));
         $organization->setBody($request->request->get('text'));
         $organization->setEmail($request->request->get('email'));
         $organization->setContact($request->request->get('contact'));
         $em->persist($organization);
         $em->flush();
         $em->refresh($organization);
         $organization->setUrl($organization->getId());
         $em->flush();
         $file = $request->files->get('fileImg');
         if ($file != NULL) {
             $origName = $file->getClientOriginalName();
             $format = substr($origName, strlen($origName) - 4);
             $name = substr($origName, 0, strlen($origName) - 4);
             //Извлекаем формат (бывает только PDF и FLV)
             $name .= '_' . time() . $format;
             if ($format != '.png' && $format != '.jpg') {
                 $error = 'Ошибка сохранения: необходимо загрузить картинку формата png или jpg';
                 return array('organization' => $organization, 'error' => $error);
             }
             $file->move('upload/company', $name);
             $organization->setImageFile($name);
         }
         # Присоединяем человека к организации
         $this->getUser()->setOrganization($organization);
         $em->flush($this->getUser());
         # уведомление администраторов о регистрации организации
         $this->get('email.service')->send($this->container->getParameter('manager_emails'), array('LearningMainBundle:Email:registration_organization_notice.html.twig', array('user' => $this->getUser(), 'organization' => $organization)), 'Регистрация новой организации');
         return $this->redirect($this->generateUrl('_index'));
     } else {
         return array();
     }
 }