public function editdestinationAction(Request $request)
 {
     /****** Admin session checking**********/
     $response = $this->checkAdmin($request->getSession());
     if ($response) {
         return $response;
     }
     $em = $this->getDoctrine()->getManager();
     $lan = $this->container->get('request')->get('lan');
     $id = $this->container->get('request')->get('id');
     $checkquery = $em->createQuery("SELECT p FROM MytripAdminBundle:Language  p WHERE p.lanCode='" . $lan . "'");
     $checklanguage = $checkquery->getArrayResult();
     if (empty($checklanguage)) {
         return $this->redirect($this->generateUrl('mytrip_admin_editdestination', array('id' => $id, 'lan' => 'en')));
     }
     if ($request->getMethod() == "POST") {
         if ($lan == "en") {
             $page_link = strtolower(str_replace(' ', '_', preg_replace('/[^a-zA-Z0-9_ -]/s', ' ', $request->request->get('name'))));
             if ($page_link == '') {
                 $page_link = strtolower(str_replace(array(' ', '\''), array('_', '-'), $request->request->get('name')));
             }
             $em = $this->getDoctrine()->getManager();
             /********Checking duplicate destination***********/
             $check = $em->createQuery("SELECT d FROM MytripAdminBundle:Destination d WHERE  d.url='" . $page_link . "' AND d.destinationId NOT IN ({$id}) AND  d.status NOT IN ('Trash')");
             $check_destination = $check->getArrayResult();
             if (empty($check_destination)) {
                 /***Destination english language update***/
                 $repository = $em->getRepository('MytripAdminBundle:Destination');
                 $destination = $repository->findOneByDestinationId($id);
                 $country_query = $em->createQuery("SELECT c FROM MytripAdminBundle:Country c WHERE c.cid='" . $request->request->get('country') . "'");
                 $country = $country_query->getArrayResult();
                 $state_query = $em->createQuery("SELECT s FROM MytripAdminBundle:States s WHERE s.sid='" . $request->request->get('province') . "'");
                 $state = $state_query->getArrayResult();
                 $address = $request->request->get('name') . "," . $state[0]['state'] . "," . $country[0]['country'];
                 $position = $this->getBoundLatitude_longitude($address);
                 $destination->setName($request->request->get('name'));
                 $destination->setUrl($page_link);
                 $destination->setVideo($request->request->get('svdesc'));
                 $destination->setTripadvisor($request->request->get('tripadvisor'));
                 $destination->setCountry($this->getDoctrine()->getRepository('MytripAdminBundle:Country')->find($request->request->get('country')));
                 $destination->setProvince($this->getDoctrine()->getRepository('MytripAdminBundle:States')->find($request->request->get('province')));
                 $destination->setLongitude($position['longitude']);
                 $destination->setLatitude($position['latitude']);
                 $destination->setStatus('Active');
                 $destination->setModifyDate(new \DateTime(date('Y-m-d H:i:s')));
             } else {
                 $this->get('session')->getFlashBag()->add('error', '<div class="success msg">Destination already exists</div>');
                 return $this->redirect($this->generateUrl('mytrip_admin_destination', array('id' => $id, 'lan' => $lan)));
             }
         }
         /******Destination content update with corresponding lanugage******/
         $em = $this->getDoctrine()->getManager();
         $check = $em->createQuery("SELECT p FROM MytripAdminBundle:DestinationContent p WHERE p.destination=" . $id . " AND p.lan='" . $lan . "'");
         $check_content = $check->getArrayResult();
         //print_r($check_content); echo $check_content['0']['destinationContentId'];exit;
         if ($lan == "en") {
             $address = $request->request->get('name') . "," . $state[0]['state'] . "," . $country[0]['country'];
         } else {
             $address = $request->request->get('name') . "," . $request->request->get('province') . "," . $request->request->get('country');
         }
         if (!empty($check_content)) {
             $repository_content = $em->getRepository('MytripAdminBundle:DestinationContent');
             $check_contents = $repository_content->findOneByDestinationContentId($check_content['0']['destinationContentId']);
             $check_contents->setName($request->request->get('name'));
             $check_contents->setDestination($this->getDoctrine()->getRepository('MytripAdminBundle:Destination')->find($id));
             $check_contents->setDescription($request->request->get('description'));
             $check_contents->setLocationDesc($request->request->get('location_desc'));
             $check_contents->setAddress($address);
             $check_contents->setCity($request->request->get('name'));
             if ($lan == "en") {
                 $check_contents->setProvince($state[0]['state']);
                 $check_contents->setCountry($country[0]['country']);
             } else {
                 $check_contents->setProvince($request->request->get('province'));
                 $check_contents->setCountry($request->request->get('country'));
             }
             $check_contents->setMetaTitle($request->request->get('metatitle'));
             $check_contents->setMetaDescription($request->request->get('metadescription'));
             $check_contents->setMetaKeyword($request->request->get('metakeyword'));
         } else {
             $destination_content = new DestinationContent();
             $destination_content->setName($request->request->get('name'));
             $destination_content->setDestination($this->getDoctrine()->getRepository('MytripAdminBundle:Destination')->find($id));
             $destination_content->setDescription($request->request->get('description'));
             $destination_content->setLocationDesc($request->request->get('location_desc'));
             $destination_content->setAddress($address);
             $destination_content->setCity($request->request->get('name'));
             $destination_content->setProvince($request->request->get('province'));
             $destination_content->setCountry($request->request->get('country'));
             $destination_content->setMetaTitle($request->request->get('metatitle'));
             $destination_content->setMetaDescription($request->request->get('metadescription'));
             $destination_content->setMetaKeyword($request->request->get('metakeyword'));
             $destination_content->setLan($lan);
             $em->persist($destination_content);
         }
         $em->flush();
         $em = $this->getDoctrine()->getManager();
         /******Destination feature update******/
         if ($request->request->get('feature') != '') {
             $em->createQuery("DELETE FROM MytripAdminBundle:DestinationFeature b WHERE b.destination ={$id}")->execute();
             $d_feature = $request->request->get('feature');
             foreach ($d_feature as $features) {
                 $em = $this->getDoctrine()->getManager();
                 $destination_feature = new DestinationFeature();
                 $destination_feature->setDestination($this->getDoctrine()->getRepository('MytripAdminBundle:Destination')->find($id));
                 $destination_feature->setFeature($this->getDoctrine()->getRepository('MytripAdminBundle:Feature')->find($features));
                 $destination_feature->setCreatedDate(new \DateTime(date('Y-m-d H:i:s')));
                 $em->persist($destination_feature);
                 $em->flush();
                 unset($destination_feature);
             }
         }
         /**********Destination Image update********/
         if ($request->files->get('image') != '') {
             $destination_image = new DestinationImage();
             $em = $this->getDoctrine()->getManager();
             $checkimage_query = $em->createQuery("SELECT p FROM MytripAdminBundle:DestinationImage p WHERE p.destination=" . $id);
             $checkimage = $checkimage_query->getArrayResult();
             $awsAccessKey = $this->container->get('mytrip_admin.helper.amazon')->getOption('awsAccessKey');
             $awsSecretKey = $this->container->get('mytrip_admin.helper.amazon')->getOption('awsSecretKey');
             $bucket = $this->container->get('mytrip_admin.helper.amazon')->getOption('bucket');
             \S3::setAuth($awsAccessKey, $awsSecretKey);
             if (!empty($checkimage)) {
                 $deleteobject = \S3::deleteObject($bucket, $checkimage[0]['image']);
                 /*$file_path="img/destination/".$checkimage[0]['image'];
                 		if($checkimage[0]['image']!='' && file_exists($file_path)){
                 			unlink($file_path);
                 		}*/
                 $em->createQuery("DELETE FROM MytripAdminBundle:DestinationImage b WHERE b.destination ={$id}")->execute();
             }
             $destination_image->setDestination($this->getDoctrine()->getRepository('MytripAdminBundle:Destination')->find($id));
             $ext = $request->files->get('image')->getClientOriginalExtension();
             $filename = $this->str_rand(8, "alphanum") . "." . $ext;
             //$request->files->get('image')->move("img/destination",$filename);
             $tmpfile = $request->files->get('image')->getPathName();
             $putobject = \S3::putObjectFile($tmpfile, $bucket, $filename, \S3::ACL_PUBLIC_READ);
             if ($putobject) {
                 $destination_image->setImage($filename);
                 $destination_image->setCreatedDate(new \DateTime(date('Y-m-d H:i:s')));
                 $em->persist($destination_image);
                 $em->flush();
             }
         }
         $this->get('session')->getFlashBag()->add('error', '<div class="success msg">Destination successfully updated</div>');
         return $this->redirect($this->generateUrl('mytrip_admin_editdestination', array('id' => $id, 'lan' => $lan)));
     }
     /******Fetch language********/
     $query = $em->createQuery("SELECT p FROM MytripAdminBundle:Language  p ");
     $language = $query->getArrayResult();
     /*******Fetch destination details*****/
     $destination_query = $em->createQuery("SELECT p,IDENTITY(p.country) AS country,IDENTITY(p.province) AS province FROM MytripAdminBundle:Destination  p WHERE p.destinationId=" . $id);
     $destination = $destination_query->getArrayResult();
     if (empty($destination)) {
         return $this->redirect($this->generateUrl('mytrip_admin_destination'));
     }
     /*******Fetch Destination content details*****/
     $destination_content_query = $em->createQuery("SELECT d FROM MytripAdminBundle:DestinationContent d WHERE d.destination=" . $id . " AND d.lan='" . $lan . "'");
     $destination_content = $destination_content_query->getArrayResult();
     if (empty($destination_content)) {
         $destination_content_query = $em->createQuery("SELECT d FROM MytripAdminBundle:DestinationContent d WHERE d.destination=" . $id . " AND d.lan='en'");
         $destination_content = $destination_content_query->getArrayResult();
     }
     $feature_query = $em->createQuery("SELECT f FROM MytripAdminBundle:Feature f");
     $feature = $feature_query->getArrayResult();
     $country_query = $em->createQuery("SELECT c FROM MytripAdminBundle:Country c");
     $country = $country_query->getArrayResult();
     $state_query = $em->createQuery("SELECT c FROM MytripAdminBundle:States c WHERE c.cid=" . $destination['0']['country']);
     $state = $state_query->getArrayResult();
     $destination_image_query = $em->createQuery("SELECT d FROM MytripAdminBundle:DestinationImage d WHERE d.destination='" . $destination[0][0]['destinationId'] . "'");
     $destination_image = $destination_image_query->getArrayResult();
     $destination_feature_query = $em->createQuery("SELECT IDENTITY(f.feature) AS feature FROM MytripAdminBundle:DestinationFeature f WHERE f.destination={$id}");
     $destination_feature = $destination_feature_query->getArrayResult();
     return $this->render('MytripAdminBundle:Default:editdestination.html.php', array('language' => $language, 'destination' => $destination, 'destination_content' => $destination_content, 'feature' => $feature, 'country' => $country, 'destination_image' => $destination_image, 'destination_feature' => $destination_feature, 'state' => $state));
 }
 /**
  * {@inheritDoc}
  */
 public function setImage($image)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setImage', array($image));
     return parent::setImage($image);
 }