예제 #1
0
 public function addAction()
 {
     $request = $this->getRequest();
     $id = $this->params()->fromRoute('id');
     //insert
     if ($id == '') {
         $event = new Event();
         $configForm = new eventForm();
         if ($request->isPost()) {
             $data = $this->params()->fromPost();
             $event->setName($data['name']);
             $event->setValue($data['value']);
             $event->setType($data['type']);
             $event->getIsdelete(0);
             $this->modelEvent->insert($event);
         }
         return new ViewModel(array('data' => $event, 'title' => 'Edit event: ' . $event->getName(), 'form' => $configForm));
     } else {
         $event = $this->modelEvent->findOneBy(array('id' => $id));
         $configForm = new eventForm();
         $configForm->setAttribute('action', '/admin/event/add/' . $id);
         $configForm->get('id')->setValue($event->getId());
         $configForm->get('name')->setValue($event->getName());
         $configForm->get('value')->setValue($event->getValue());
         $configForm->get('type')->setValue($event->getType());
         if ($request->isPost()) {
             $data = $this->params()->fromPost();
             $value = $event->getValue();
             $idFormPost = $this->params()->fromPost('id');
             $event = $this->modelEvent->findOneBy(array('id' => $idFormPost));
             $event->setType($data['type']);
             $event->setValue($data['value']);
             $event->setName($data['name']);
             $this->modelEvent->edit($event);
             //update form
             $configForm->get('name')->setValue($event->getName());
             $configForm->get('value')->setValue($event->getValue());
             $configForm->get('type')->setValue($event->getType());
         }
         return new ViewModel(array('data' => $event, 'title' => 'Edit event: ' . $event->getName(), 'form' => $configForm));
     }
 }
예제 #2
0
 /**
  * This function is used for add event. 
  * @Author Vinod Kandwal
  */
 public function addAction()
 {
     $this->layout()->pageTitle = 'Add Event';
     /* Setting page title */
     $em = $this->getEntityManager();
     /* Call Entity Manager */
     /* Check with passed password exist in DB */
     $objCategories = $em->getRepository('Admin\\Entity\\Categories')->findBy(array('status' => 1));
     $objCountries = $em->getRepository('Admin\\Entity\\Countries')->findBy(array('countryExist' => 1));
     $objLayout = $em->getRepository('Admin\\Entity\\Layout')->findBy(array());
     $objOption = $em->getRepository('Admin\\Entity\\MainOptions')->findBy(array());
     $layout_id = $this->getEvent()->getRouteMatch()->getParam('layout_id') ? $this->getEvent()->getRouteMatch()->getParam('layout_id') : 1;
     $dataEvent = array('event_image_big' => '', 'event_image_medium' => '', 'event_image_small' => '', 'event_image_banner' => '');
     $request = $this->getRequest();
     /* Fetching Request */
     if ($request->isPost()) {
         $data = $request->getPost();
         $txtlayout = $data['txtlayout'];
         $txttitle = $data['txttitle'];
         $txtperfcode = $data['txtperfcode'];
         $txtdesc = $data['txtdesc'];
         $txtartist = $data['txtartist'];
         $txtaddress = $data['txtaddress'];
         $txtcountry = $data['txtcountry'];
         $txtcity = $data['txtcity'];
         $txtzipcode = $data['txtzipcode'];
         $txtvenue_title = $data['txtvenue_title'];
         $txtlink = $data['txtlink'];
         $txtdate = $data['txtdate'];
         $txttime = $data['txttime'];
         $txtcategory = $data['txtcategory'];
         $txt_check_feature = $data['txt_check_feature'];
         $txtimage_big = $data['txtimage_big'];
         $txtimage_medium = $data['txtimage_medium'];
         $txtimage_small = $data['txtimage_small'];
         $txtimage_banner = $data['txtimage_banner'];
         $txtoption = $data['txtoption'];
         $datetimeCountHiddenValue = $data['datetimeCountHiddenValue'];
         $uploadsDir = getcwd() . '/public/uploads';
         if (!file_exists($uploadsDir)) {
             mkdir($uploadsDir, 0777, true);
         }
         $uploadsDirPath = getcwd() . '/public/uploads/event/';
         if (!file_exists($uploadsDirPath)) {
             mkdir($uploadsDirPath, 0777, true);
         }
         try {
             $fileName = '';
             $upload = new \Zend\File\Transfer\Adapter\Http();
             $upload->setDestination($uploadsDirPath);
             $files = $upload->getFileInfo();
             // $upload->addValidator('FilesSize', false, array('min' => '10kB', 'max' => '4MB'));
             // $upload->addValidator('Extension', false, array('jpg', 'png','jpeg','gif'));
             // echo '<pre>'; print_r($files); die;
             if (count($files) > 0) {
                 foreach ($files as $file => $info) {
                     $fileName = uniqid() . date("ymd_his") . '_' . $info['name'];
                     if ($file == 'txtimage_big') {
                         $dataEvent['event_image_big'] = $fileName;
                     }
                     if ($file == 'txtimage_medium') {
                         $dataEvent['event_image_medium'] = $fileName;
                     }
                     if ($file == 'txtimage_small') {
                         $dataEvent['event_image_small'] = $fileName;
                     }
                     if ($file == 'txtimage_banner') {
                         $dataEvent['event_image_banner'] = $fileName;
                     }
                     if ($file == 'txtvenue_icon') {
                         $fileName = 'v_' . uniqid() . date("his") . '_' . $info['name'];
                         $dataEvent['event_venue_icon'] = $fileName;
                     }
                     $upload->addFilter('Rename', array('target' => $uploadsDirPath . $fileName, 'overwrite' => true));
                     if ($upload->isValid($file)) {
                         $upload->receive($file);
                     }
                 }
             }
         } catch (Zend_File_Transfer_Exception $e) {
             echo $e->getMessage();
             exit;
         }
         try {
             $currentDate = date_create(date('Y-m-d H:i:s'));
             $objLayoutId = $em->getRepository('Admin\\Entity\\Layout')->find($txtlayout);
             $objCategoriesId = $em->getRepository('Admin\\Entity\\Categories')->find($txtcategory);
             $objCountryId = $em->getRepository('Admin\\Entity\\Countries')->find($txtcountry);
             $objCityId = $em->getRepository('Admin\\Entity\\City')->find($txtcity);
             $latitude = $longitude = '';
             //$address = $txtaddress . ", " . $txtcity . ", " . $txtcountry . ", " . $txtzipcode;
             $address = $txtaddress . ", " . $txtzipcode . ", " . $objCityId->getCityName() . ", " . $objCountryId->getCountryName();
             $address = urlencode($address);
             $request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=" . $address . "&sensor=true";
             $xml = simplexml_load_file($request_url);
             // or die("url not loading");
             if (!empty($xml)) {
                 $status = $xml->status;
                 if ($status == "OK") {
                     $latitude = $xml->result->geometry->location->lat;
                     $longitude = $xml->result->geometry->location->lng;
                 }
             }
             // Save Event details
             $eventObj = new Entities\Event();
             $eventObj->setEventName($txttitle);
             $eventObj->setPerfCode($txtperfcode);
             //Added by Yesh - 2015-12-31
             $eventObj->setEventDesc($txtdesc);
             $eventObj->setEventArtist($txtartist);
             $eventObj->setEventCountry($objCountryId);
             $eventObj->setEventCity($objCityId);
             $eventObj->setEventAddress($txtaddress);
             $eventObj->setEventZip($txtzipcode);
             $eventObj->setEventVenueTitle($txtvenue_title);
             $eventObj->setEventVenueIcon($dataEvent['event_venue_icon']);
             $eventObj->setEventImageBig($dataEvent['event_image_big']);
             $eventObj->setEventImageMedium($dataEvent['event_image_medium']);
             $eventObj->setEventImageSmall($dataEvent['event_image_small']);
             $eventObj->setEventImageBanner($dataEvent['event_image_banner']);
             $eventObj->setEventLink($txtlink);
             $eventObj->setLongitude($longitude);
             $eventObj->setLatitude($latitude);
             $eventObj->setLayout($objLayoutId);
             $eventObj->setCategory($objCategoriesId);
             $eventObj->setFeatured($txt_check_feature);
             $eventObj->setStatus(0);
             $eventObj->setCreatedDate($currentDate);
             $em->persist($eventObj);
             $em->flush();
         } catch (Zend_Exception $e) {
             echo "Caught exception: " . get_class($e) . "\n";
             echo "Message: Event Entity" . $e->getMessage() . "\n";
             exit;
         }
         try {
             // Save Event allow options
             if (count($txtoption) > 0) {
                 foreach ($txtoption as $optionId) {
                     $objOptionId = $em->getRepository('Admin\\Entity\\MainOptions')->find($optionId);
                     $eventOptionObj = new Entities\EventOption();
                     $eventOptionObj->setEvent($eventObj);
                     $eventOptionObj->setOption($objOptionId);
                     $eventOptionObj->setCreatedDate($currentDate);
                     $eventOptionObj->setIsDeleted(0);
                     $em->persist($eventOptionObj);
                     $em->flush();
                 }
             }
         } catch (Zend_Exception $e) {
             echo "Caught exception: " . get_class($e) . "\n";
             echo "Message: Event Option Entity" . $e->getMessage() . "\n";
             exit;
         }
         try {
             // Save Event Scheduling
             for ($i = 1; $i <= $datetimeCountHiddenValue; $i++) {
                 $arrdate = explode('/', $data['txtdate' . $i]);
                 $eventdate = date_create($arrdate[2] . '-' . $arrdate[0] . '-' . $arrdate[1]);
                 $event_time = date_create(date('H:i:s', strtotime($data['txttime' . $i])));
                 $eventScheduleObj = new Entities\EventSchedule();
                 $eventScheduleObj->setEvent($eventObj);
                 $eventScheduleObj->setEventDate($eventdate);
                 $eventScheduleObj->setEventTime($event_time);
                 $eventScheduleObj->setCreatedDate($currentDate);
                 $eventScheduleObj->setIsDeleted(0);
                 $em->persist($eventScheduleObj);
                 $em->flush();
             }
             $eventId = $eventObj->getId();
             $layoutId = $objLayoutId->getId();
             return $this->redirect()->toRoute('layout', array('event_id' => $eventId, 'layout_id' => $layoutId));
         } catch (Zend_Exception $e) {
             echo "Caught exception: " . get_class($e) . "\n";
             echo "Message: Event Schedule Entity" . $e->getMessage() . "\n";
             exit;
         }
     }
     return new ViewModel(array('dataCategories' => $objCategories, 'dataCountries' => $objCountries, 'dataLayout' => $objLayout, 'dataOption' => $objOption, 'layout_id' => $layout_id));
 }