public function editAction() { parent::editAction(); if ($this->getRequest()->isPost()) { try { $data = (object) $this->getRequest()->getPost(); $this->_setData($data); $this->_entity->save(); $this->__goBack(); } catch (Exception $e) { $this->view->showMessage($e); } } else { $this->__postContentFields(); $_POST['city_location'] = array('lat' => $this->_entity->getLocationLat(), 'lng' => $this->_entity->getLocationLng(), 'zoom' => $this->_entity->getLocationZoom()); } }
public function addAction() { $userNs = new Zend_Session_Namespace("members"); $this->view->title = "City - Add"; $this->view->headTitle(" - " . $this->view->title); $form = new Admin_Form_City(); $this->view->form = $form; $this->view->successMsg = ""; if ($this->getRequest()->isPost()) { $formData = $this->getRequest()->getPost(); if ($form->isValid($formData)) { $upload = new Zend_File_Transfer_Adapter_Http(); //---main image if ($upload->isValid('logo')) { $upload->setDestination("images/logo/"); try { $upload->receive('logo'); } catch (Zend_File_Transfer_Exception $e) { $msg = $e->getMessage(); } $upload->setOptions(array('useByteString' => false)); $id = time(); $file_name = $upload->getFileName('logo'); $cardImageTypeArr = explode(".", $file_name); $ext = strtolower($cardImageTypeArr[count($cardImageTypeArr) - 1]); $target_file_name = "logo_" . $id . ".{$ext}"; $targetPath = 'media/picture/city/logo/' . $target_file_name; $filterFileRename = new Zend_Filter_File_Rename(array('target' => $targetPath, 'overwrite' => true)); $filterFileRename->filter($file_name); $formData['logo'] = $target_file_name; /*--- Generate Thumbnail ---*/ $thumb = Base_Image_PhpThumbFactory::create($targetPath); $thumb->resize(100, 100); $thumb->save($targetPath = 'media/picture/city/logo/thumb_' . $target_file_name); } $usersNs = new Zend_Session_Namespace("members"); $formData['userId'] = $usersNs->userId; $this->view->warningMsg = ''; $model = new Application_Model_City($formData); $id = $model->save($model); $form->reset(); $this->view->successMsg = "City added successfully. City Id : {$id}"; } else { $form->populate($formData); } } }
public function poiAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); echo "<pre>"; $filename = "data/lonelyplanet-london-gapdaemon.xml"; $xml_parser = new Base_Xml_Parser(null, $filename); $destinationName = $xml_parser->Data['destination_name']; //----insert into continent $continent_id = 0; $continentM = new Application_Model_Continent(); $continent = $continentM->fetchRow("name='{$destinationName}'"); if (false !== $continent) { $continent_id = $continent->getId(); } //-------------------------- //----insert into country $country_id = 0; $countryM = new Application_Model_Country(); $country = $countryM->fetchRow("name='{$destinationName}'"); if (false !== $country) { $country_id = $country->getId(); } //------------------------------- ///------insert into city $city_id = 0; $cityM = new Application_Model_City(); $city = $cityM->fetchRow("name='{$destinationName}'"); if (false !== $city) { $city_id = $city->getId(); } //------------------------ if ($city_id > 0) { //it is city $locationType = "city"; $locationId = $city_id; } else { if ($country_id > 0) { //it is country $locationType = "country"; $locationId = $country_id; } else { if ($continent_id > 0) { //it is continent $locationType = "continent"; $locationId = $continent_id; } else { //create a place/city and get the reference id/location id ///------insert into city $city_id = 0; $cityM = new Application_Model_City(); $cityM->setName($destinationName); $cityM->setCountryId(0); $city_id = $cityM->save(); //------------------------ $locationType = "other"; $locationId = $city_id; } } } error_reporting(E_ALL & ~E_NOTICE); foreach ($xml_parser->Data['pois']['poi'] as $poi) { $poiM = new Application_Model_Poi(); $poiM->setLocationId($locationId)->setLocationType($locationType)->setName($poi['poi_name'])->setAddress(serialize($poi['address_parts']['address_part']))->setPostcode($poi['address_postcode'])->setTelfaxs(serialize($poi['telfaxs']['telfax']))->setEmail($poi['poi_email'])->setWeb($poi['poi_web'])->setTransportModes(serialize($poi['transport_modes']['transport_mode']))->setPriceRange($poi['price_range'])->setReviewFull($poi['review_full']['p'])->setReviewSummary($poi['review_summary']['p'])->setBookable($poi['bookable']['value'])->setXCoordinate($poi['feature_x_coord'])->setYCoordinate($poi['feature_y_coord'])->setFeatureId($poi['feature_id'])->setKeywords(serialize($poi['keywords']['keyword'])); $poiM->save(); } }
public function xmlAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); echo "<pre>"; $filename = "data/sample - Chiang Mai.xml"; $xml_parser = new Base_Xml_Parser(null, $filename); $continentName = $xml_parser->Data['identification']['geoTag1']; $countryName = $xml_parser->Data['identification']['geoTag2']; $cityName = $xml_parser->Data['identification']['geoTag3']; //----insert into continent $continent_id = 0; $continentM = new Application_Model_Continent(); $continent = $continentM->fetchRow("name='{$continentName}'"); if (false === $continent) { $continentM->setName($continentName); $continent_id = $continentM->save(); } else { $continent_id = $continent->getId(); } //-------------------------- //----insert into country $country_id = 0; $countryM = new Application_Model_Country(); $country = $countryM->fetchRow("name='{$countryName}' and continent_id='{$continent_id}'"); if (false === $country) { $countryM->setName($countryName); $countryM->setContinentId($continent_id); $country_id = $countryM->save(); } else { $country_id = $country->getId(); } //------------------------------- ///------insert into city $city_id = 0; $cityM = new Application_Model_City(); $city = $cityM->fetchRow("name='{$cityName}' and country_id='{$country_id}'"); if (false === $city) { $cityM->setName($cityName); $cityM->setCountryId($country_id); $city_id = $cityM->save(); } else { $city_id = $city->getId(); } //------------------------ if ($continent_id > 0 && $country_id > 0 && $city_id > 0) { //it is city $locationType = "city"; $locationId = $city_id; } else { if ($continent_id > 0 && $country_id > 0) { //it is country $locationType = "country"; $locationId = $country_id; } else { if ($continent_id > 0) { //it is continent $locationType = "continent"; $locationId = $continent_id; } } } $title = $xml_parser->Data['content']['title']; $introduction = $xml_parser->Data['content']['introduction']; $destinationM = new Application_Model_Destination(); $destinationM->setTitle($title); $destinationM->setIntroduction($introduction); $destinationM->setLocationId($locationId); $destinationM->setLocationType($locationType); $destination_id = $destinationM->save(); foreach ($xml_parser->Data['content']['experiences'] as $experiences) { foreach ($experiences as $_item) { //print_r($_item);die(); $experiencesM = new Application_Model_Experiences(); $experiencesM->setTitle($_item['title']); $experiencesM->setDestinationId($destination_id); $experiencesM->setCopy($_item['copy']); $experiencesM->save(); } } foreach ($xml_parser->Data['content']['practicalities'] as $practicalities) { foreach ($practicalities as $_item) { $practicalitiesM = new Application_Model_Practicalities(); $practicalitiesM->setTitle($_item['title']); $practicalitiesM->setDestinationId($destination_id); $practicalitiesM->setCopy($_item['copy']); $practicalitiesM->save(); } } foreach ($xml_parser->Data['content']['eatSleepDrink'] as $eatsleepdrink) { foreach ($eatsleepdrink as $_item) { //print_r($_item);die(); $EatSleepDrinkM = new Application_Model_EatSleepDrink(); $EatSleepDrinkM->setTitle($_item['title']); $EatSleepDrinkM->setDestinationId($destination_id); $EatSleepDrinkM->setBackPackerCopy($_item['backpackerCopy']); $EatSleepDrinkM->setLocalCopy($_item['localCopy']); $EatSleepDrinkM->save(); } } //print_r($xml_parser->Data); }