예제 #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     ini_set('memory_limit', -1);
     $output->writeln('+++ roh:events started!');
     $container = $this->getContainer();
     $em = $container->get('doctrine')->getManager();
     //$pdo  = $this->getConnection();
     $pdo = $this->getConnection('root', 'Evrika-group');
     $stmt = $pdo->prepare("SELECT e.* FROM event e JOIN event_specialty es ON es.event_id = e.id WHERE es.specialty_id = 37");
     $stmt->execute();
     $results = $stmt->fetchAll();
     foreach ($results as $r) {
         $code = 'evrika-' . $r['id'];
         $event = $em->getRepository('LearningMainBundle:Event')->findOneByCode($code);
         if (!$event) {
             $event = new Event();
             $eventDate = new EventDate();
             $eventDate->setEvent($event);
             $eventDate->setStarts(new \DateTime($r['starts']));
             if (empty($r['ends'])) {
                 $starts = new \DateTime($r['starts']);
                 $eventDate->setEnds($starts->modify('+1 day'));
             } else {
                 $eventDate->setEnds(new \DateTime($r['ends']));
             }
             $event->setTitle($r['title']);
             $event->setBody($r['body']);
             $event->setCode($code);
             $em->persist($event);
             $em->persist($eventDate);
             $em->flush();
         }
     }
     $output->writeln('--- roh:events completed');
 }
예제 #2
0
 /**
  * @Route("/adm/event-preview" , name="admin_event_preview")
  * @Template("LearningMainBundle:Admin:event_preview.html.twig")
  */
 public function previewAction()
 {
     $request = $this->getRequest();
     $event = new Event();
     if ($request->isMethod('POST')) {
         $em = $this->getDoctrine()->getManager();
         $event->setTitle($request->request->get('title'));
         $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'));
         /* Для организаций */
         $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);
         $repo = $em->getRepository('LearningMainBundle:Specialization');
         $specialization = $request->request->get('specializations');
         $specializations = array();
         foreach ($specialization as $specId) {
             $specializations[] = $repo->findOneById($specId);
         }
         $starts = $request->request->get('starts');
         $ends = $request->request->get('ends');
         $dates = array();
         for ($i = 1; $i <= count($starts); $i++) {
             $date = new EventDate();
             $tmpStarts = new \DateTime($starts[$i]);
             $tmpEnds = new \DateTime($ends[$i]);
             $date->setStarts($tmpStarts);
             $date->setEnds($tmpEnds);
             $dates[] = $date;
         }
         if (!is_dir('upload/events')) {
             mkdir('upload/events', 0775);
         }
         $j = 1;
         $files = $request->files->get('filedoc');
         $filesT = array();
         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 != '.pdf' && $format != '.doc' && $format != '.docx' && $format != '.zip' && $format != '.jpg' && $format != '.png' && $format != '.jpeg') {
                 }
                 $file->move('upload/events/', $name);
                 $EventFile = new File();
                 $EventFile->setFiledoc($name);
                 $EventFile->setTitle($request->request->get('filename')[$j]);
                 $filesT[] = $EventFile;
             }
             $j++;
         }
         return array('event' => $event, 'dates' => $dates, 'files' => $filesT, 'specializations' => $specializations);
     } else {
         return array();
     }
 }