public function edithostalAction(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_edithostal', 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 hostal***********/
             $check = $em->createQuery("SELECT d FROM MytripAdminBundle:Hostal d WHERE  d.url='" . $page_link . "' AND d.status NOT IN ('Trash') AND d.hostalId NOT IN ({$id})  AND d.destination NOT IN (" . $request->request->get('destination') . ")");
             $check_hostal = $check->getArrayResult();
             if (empty($check_hostal)) {
                 /***Hostal english language update***/
                 $repository = $em->getRepository('MytripAdminBundle:Hostal');
                 $hostal = $repository->findOneByHostalId($id);
                 $destination_query = $em->createQuery("SELECT d,IDENTITY(d.country) AS country, IDENTITY(d.province) AS province FROM MytripAdminBundle:Destination d WHERE d.destinationId='" . $request->request->get('destination') . "'");
                 $destination = $destination_query->getArrayResult();
                 $country_query = $em->createQuery("SELECT c FROM MytripAdminBundle:Country c WHERE c.cid='" . $destination['0']['country'] . "'");
                 $country = $country_query->getArrayResult();
                 $state_query = $em->createQuery("SELECT s FROM MytripAdminBundle:States s WHERE s.sid='" . $destination['0']['province'] . "'");
                 $state = $state_query->getArrayResult();
                 $destination[0] = $destination[0][0];
                 $address = $request->request->get('address') . "," . $country[0]['country'];
                 $position = $this->getBoundLatitude_longitude($address);
                 if (empty($position)) {
                     $longitude = $destination['0']['longitude'];
                     $latitude = $destination['0']['latitude'];
                 } else {
                     $longitude = $position['longitude'];
                     $latitude = $position['latitude'];
                 }
                 $hostal->setName($request->request->get('name'));
                 $hostal->setDestination($this->getDoctrine()->getRepository('MytripAdminBundle:Destination')->find($request->request->get('destination')));
                 $hostal->setUrl($page_link);
                 $hostal->setOwnerEmail($request->request->get('owneremail'));
                 $hostal->setCccode($request->request->get('cccode'));
                 $hostal->setPhone($request->request->get('phone'));
                 $hostal->setCmcode($request->request->get('cmcode'));
                 $hostal->setMobile($request->request->get('mobile'));
                 $hostal->setVideo($request->request->get('svdesc'));
                 $hostal->setTripadvisor($request->request->get('tripadvisor'));
                 $hostal->setLongitude($longitude);
                 $hostal->setLatitude($latitude);
                 $hostal->setStatus('Active');
                 $hostal->setModifyDate(new \DateTime(date('Y-m-d H:i:s')));
             } else {
                 $this->get('session')->getFlashBag()->add('error', '<div class="success msg">Hostal already exists</div>');
                 return $this->redirect($this->generateUrl('mytrip_admin_edithostal', array('id' => $id, 'lan' => $lan)));
             }
         }
         /******Hostal content update with corresponding lanugage******/
         $em = $this->getDoctrine()->getManager();
         $check = $em->createQuery("SELECT p FROM MytripAdminBundle:HostalContent p WHERE p.hostal=" . $id . " AND p.lan='" . $lan . "'");
         $check_content = $check->getArrayResult();
         $hostalinfos = $em->createQuery("SELECT p,IDENTITY(p.destination) AS destination FROM MytripAdminBundle:Hostal p WHERE p.hostalId=" . $id);
         $hostalinfo = $hostalinfos->getArrayResult();
         $destination_content_query = $em->createQuery("SELECT p FROM MytripAdminBundle:DestinationContent p WHERE p.destination=" . $hostalinfo['0']['destination'] . " AND p.lan='" . $lan . "'");
         $destination_content = $destination_content_query->getArrayResult();
         if (empty($destination_content)) {
             $destination_content_query = $em->createQuery("SELECT p FROM MytripAdminBundle:DestinationContent p WHERE p.destination=" . $hostalinfo['0']['destination'] . " AND p.lan='en'");
             $destination_content = $destination_content_query->getArrayResult();
         }
         if (!empty($check_content)) {
             $repository_content = $em->getRepository('MytripAdminBundle:HostalContent');
             $hostal_content = $repository_content->findOneByHostalContentId($check_content['0']['hostalContentId']);
             $hostal_content->setName($request->request->get('name'));
             $hostal_content->setHostal($this->getDoctrine()->getRepository('MytripAdminBundle:Hostal')->find($id));
             $hostal_content->setSmallDesc($request->request->get('smalldescription'));
             $hostal_content->setDescription($request->request->get('description'));
             $hostal_content->setLocationDesc($request->request->get('location_desc'));
             $hostal_content->setAddress($request->request->get('address'));
             $hostal_content->setOwnerName($request->request->get('ownername'));
             if ($lan == "en") {
                 $hostal_content->setCity($destination[0]['name']);
                 $hostal_content->setProvince($state[0]['state']);
                 $hostal_content->setCountry($country[0]['country']);
             } else {
                 $hostal_content->setCity($destination_content[0]['city']);
                 $hostal_content->setProvince($destination_content[0]['province']);
                 $hostal_content->setCountry($destination_content[0]['country']);
             }
             $hostal_content->setMetaTitle($request->request->get('metatitle'));
             $hostal_content->setMetaDescription($request->request->get('metadescription'));
             $hostal_content->setMetaKeyword($request->request->get('metakeyword'));
             $hostal_content->setLan($lan);
         } else {
             $hostal_content = new HostalContent();
             $hostal_content->setName($request->request->get('name'));
             $hostal_content->setHostal($this->getDoctrine()->getRepository('MytripAdminBundle:Hostal')->find($id));
             $hostal_content->setSmallDesc($request->request->get('smalldescription'));
             $hostal_content->setDescription($request->request->get('description'));
             $hostal_content->setLocationDesc($request->request->get('location_desc'));
             $hostal_content->setAddress($request->request->get('address'));
             $hostal_content->setOwnerName($request->request->get('ownername'));
             $hostal_content->setCity($destination_content[0]['city']);
             $hostal_content->setProvince($destination_content[0]['province']);
             $hostal_content->setCountry($destination_content[0]['country']);
             $hostal_content->setMetaTitle($request->request->get('metatitle'));
             $hostal_content->setMetaDescription($request->request->get('metadescription'));
             $hostal_content->setMetaKeyword($request->request->get('metakeyword'));
             $hostal_content->setLan($lan);
             $em->persist($hostal_content);
         }
         $em->flush();
         // if($lan=="en"){
         // 	$em =  $this->getDoctrine()->getManager();
         // 	$checkroom_query=$em->createQuery("SELECT p FROM MytripAdminBundle:HostalRooms p WHERE p.hostal=".$id);
         // 	$checkroom = $checkroom_query->getArrayResult();
         // 	if(!empty($checkroom)){
         // 		$repository_rooms = $em->getRepository('MytripAdminBundle:HostalRooms');
         // 		$hostal_rooms=$repository_rooms->findOneByRoomId($checkroom['0']['roomId']);
         // 	}else{
         // 		$hostal_rooms = new HostalRooms();
         // 	}
         // 	$hostal_rooms->setHostal($this->getDoctrine()->getRepository('MytripAdminBundle:Hostal')->find($id));
         // 	$hostal_rooms->setRooms($request->request->get('rooms'));
         // 	$hostal_rooms->setRoomtype($request->request->get('roomtype'));
         // 	$hostal_rooms->setGuests($request->request->get('guests'));
         // 	$hostal_rooms->setAdults($request->request->get('adults'));
         // 	$hostal_rooms->setChild($request->request->get('child'));
         // 	$hostal_rooms->setPrice($request->request->get('price'));
         // 	if(empty($checkimage)){
         // 		$em->persist($hostal_rooms);
         // 	}
         // 	$em->flush();
         // }
         $em = $this->getDoctrine()->getManager();
         /******Destination feature update******/
         if ($request->request->get('feature') != '') {
             $em->createQuery("DELETE FROM MytripAdminBundle:HostalFeature b WHERE b.hostal ={$id}")->execute();
             $d_feature = $request->request->get('feature');
             foreach ($d_feature as $features) {
                 $em = $this->getDoctrine()->getManager();
                 $hostal_feature = new HostalFeature();
                 $hostal_feature->setHostal($this->getDoctrine()->getRepository('MytripAdminBundle:Hostal')->find($id));
                 $hostal_feature->setFeature($this->getDoctrine()->getRepository('MytripAdminBundle:Feature')->find($features));
                 $hostal_feature->setCreatedDate(new \DateTime(date('Y-m-d H:i:s')));
                 $em->persist($hostal_feature);
                 $em->flush();
                 unset($hostal_feature);
             }
         }
         /**********Hostal Image update********/
         if ($request->files->get('image') != '') {
             $hostal_image = new HostalImage();
             $em = $this->getDoctrine()->getManager();
             $checkimage_query = $em->createQuery("SELECT p FROM MytripAdminBundle:HostalImage p WHERE p.hostal=" . $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/hostal/".$checkimage[0]['image'];
                 		if($checkimage[0]['image']!='' && file_exists($file_path)){
                 			unlink($file_path);
                 		}*/
                 $em->createQuery("DELETE FROM MytripAdminBundle:HostalImage b WHERE b.hostal ={$id}")->execute();
             }
             $hostal_image->setHostal($this->getDoctrine()->getRepository('MytripAdminBundle:Hostal')->find($id));
             $ext = $request->files->get('image')->getClientOriginalExtension();
             $filename = $this->str_rand(8, "alphanum") . "." . $ext;
             //$request->files->get('image')->move("img/hostal",$filename);
             $tmpfile = $request->files->get('image')->getPathName();
             $putobject = \S3::putObjectFile($tmpfile, $bucket, $filename, \S3::ACL_PUBLIC_READ);
             if ($putobject) {
                 $hostal_image->setImage($filename);
                 $hostal_image->setCreatedDate(new \DateTime(date('Y-m-d H:i:s')));
                 $em->persist($hostal_image);
                 $em->flush();
             }
         }
         $this->get('session')->getFlashBag()->add('error', '<div class="success msg">Hostal successfully updated</div>');
         return $this->redirect($this->generateUrl('mytrip_admin_edithostal', array('id' => $id, 'lan' => $lan)));
     }
     /******Fetch language********/
     $query = $em->createQuery("SELECT p FROM MytripAdminBundle:Language  p ");
     $language = $query->getArrayResult();
     /*******Fetch hostal details*****/
     $hostal_query = $em->createQuery("SELECT p,IDENTITY(p.destination) AS destination FROM MytripAdminBundle:Hostal  p WHERE p.hostalId=" . $id);
     $hostal = $hostal_query->getArrayResult();
     if (empty($hostal)) {
         return $this->redirect($this->generateUrl('mytrip_admin_hostal'));
     }
     /*******Fetch Hostal content details*****/
     $hostal_content_query = $em->createQuery("SELECT d FROM MytripAdminBundle:HostalContent d WHERE d.hostal=" . $id . " AND d.lan='" . $lan . "'");
     $hostal_content = $hostal_content_query->getArrayResult();
     if (empty($hostal_content)) {
         $hostal_content_query = $em->createQuery("SELECT d FROM MytripAdminBundle:HostalContent d WHERE d.hostal=" . $id . " AND d.lan='en'");
         $hostal_content = $hostal_content_query->getArrayResult();
     }
     $feature_query = $em->createQuery("SELECT f FROM MytripAdminBundle:Feature f");
     $feature = $feature_query->getArrayResult();
     $hostal_image_query = $em->createQuery("SELECT d FROM MytripAdminBundle:HostalImage d WHERE d.hostal=" . $id);
     $hostal_image = $hostal_image_query->getArrayResult();
     $hostal_feature_query = $em->createQuery("SELECT IDENTITY(f.feature) AS feature FROM MytripAdminBundle:HostalFeature f WHERE f.hostal=" . $id);
     $hostal_feature = $hostal_feature_query->getArrayResult();
     $hostal_rooms_query = $em->createQuery("SELECT d FROM MytripAdminBundle:HostalRooms d WHERE d.hostal=" . $id);
     $hostal_rooms = $hostal_rooms_query->getArrayResult();
     $destination_query = $em->createQuery("SELECT f FROM MytripAdminBundle:Destination f WHERE f.status NOT IN ('Trash')");
     $destination = $destination_query->getArrayResult();
     return $this->render('MytripAdminBundle:Default:edithostal.html.php', array('language' => $language, 'hostal' => $hostal, 'hostal_content' => $hostal_content, 'feature' => $feature, 'hostal_image' => $hostal_image, 'hostal_feature' => $hostal_feature, 'hostal_rooms' => $hostal_rooms, 'destination' => $destination));
 }
 /**
  * {@inheritDoc}
  */
 public function setHostal(\Mytrip\AdminBundle\Entity\Hostal $hostal = NULL)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setHostal', array($hostal));
     return parent::setHostal($hostal);
 }