private function setModel($row) { $model = new Application_Model_CountryImages(); $model->setId($row->id)->setCountryId($row->country_id)->setCountryImage($row->country_image)->setSlideTitle($row->slide_title)->setAltText($row->alt_text)->setSlideLinkUrl($row->slide_link_url)->setSlideLinkTarget($row->slide_link_target)->setWeight($row->weight)->setStatus($row->status); return $model; }
public function editCountryImageAction() { $this->_helper->layout->disableLayout(); //get request variables $id = $this->_getParam("id"); $img_id = $this->_getParam("img_id"); $page = $this->_getParam("page"); $selTab = $this->_getParam("tab", "tabs-7"); $this->view->countryId = $id; //create image upload form $uploadForm = new Admin_Form_CityImages(); $elements = $uploadForm->getElements(); $uploadForm->clearDecorators(); foreach ($elements as $element) { $element->removeDecorator('label'); $element->removeDecorator('td'); $element->removeDecorator('tr'); $element->removeDecorator('row'); $element->removeDecorator('HtmlTag'); $element->removeDecorator('placement'); $element->removeDecorator('data'); } $uploadForm->getElement("cityImage")->setRequired(false); //get city image information to edit $model = new Application_Model_CountryImages(); $model = $model->find($img_id); $options['slideTitle'] = $model->getSlideTitle(); $options['altText'] = $model->getAltText(); $options['slideLinkUrl'] = $model->getSlideLinkUrl(); $options['slideLinkTarget'] = $model->getSlideLinkTarget(); $options['weight'] = $model->getWeight(); $uploadForm->populate($options); $this->view->countryImage = $model->getCountryImage(); $this->view->uploadForm = $uploadForm; $request = $this->getRequest(); if ($request->isPost()) { $options = $request->getPost(); if ($uploadForm->isValid($options)) { $target_file_name = $model->getCountryImage(); //Upload image start here $upload = new Zend_File_Transfer_Adapter_Http(); if ($upload->isValid()) { $upload->setDestination("media/picture/country/images/"); try { $upload->receive(); } catch (Zend_File_Transfer_Exception $e) { $msg = $e->getMessage(); } $upload->setOptions(array('useByteString' => false)); $file_name = $upload->getFileName('cityImage'); $cardImageTypeArr = explode(".", $file_name); $ext = strtolower($cardImageTypeArr[count($cardImageTypeArr) - 1]); //unlink existing image if ($ext != "" && $target_file_name != "") { if (file_exists("media/picture/country/images/" . $target_file_name)) { unlink("media/picture/country/images/" . $target_file_name); unlink("media/picture/country/images/thumbs/" . $target_file_name); } } $target_file_name = "country{$id}_" . time() . ".{$ext}"; $targetPath = "media/picture/country/images/" . $target_file_name; $targetPathThumb = "media/picture/country/images/thumbs/" . $target_file_name; $filterFileRename = new Zend_Filter_File_Rename(array('target' => $targetPath, 'overwrite' => true)); $filterFileRename->filter($file_name); $thumb = Base_Image_PhpThumbFactory::create($targetPath); $thumb->resize(623, 347); $thumb->save($targetPathThumb); } //upload image Ends here $params = $options; //set image $params['countryImage'] = $target_file_name; $params['status'] = 1; $params['id'] = $img_id; $model = new Application_Model_CountryImages($params); $res = $model->save(); if ($res) { $_SESSION['errorMsg'] = "Images has been saved successfully."; echo "<script>window.opener.location='/admin/featured-city/edit-country/id/{$id}/page/{$page}/tab/{$selTab}';</script>"; echo "<script>window.close();</script>"; } else { $this->view->errorMsg = "Error occured, please try again later."; } } else { $uploadForm->reset(); $uploadForm->populate($options); } } //end if $this->render("add-country-image"); }
function countryImagesAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); //Truncate or Empty image table first $db = Zend_Registry::get("db"); $db->query("TRUNCATE TABLE country_images"); //now fetch all images from lonely_planet_country and insert $lonelyM = new Application_Model_LonelyPlanetCountry(); $lonelyM = $lonelyM->fetchAll(NULL, "country_id ASC"); if (false !== $lonelyM) { foreach ($lonelyM as $country) { $countryId = $country->getCountryId(); $oldImageArr = unserialize($country->getImages()); for ($oCnt = 0; $oCnt < count($oldImageArr); $oCnt++) { $options = array(); $imgArr = $oldImageArr[$oCnt]; $options["countryId"] = $countryId; $options["countryImage"] = substr($imgArr["image_filename"], 8, strlen($imgArr["image_filename"])); $options["slideTitle"] = $imgArr["image_caption"]; $options["altText"] = $imgArr["image_caption"]; $options["slideLinkUrl"] = ""; $options["slideLinkTarget"] = ""; $options["weight"] = $oCnt + 1; $options["status"] = 1; //create Country image class object and insert $CountryImagesM = new Application_Model_CountryImages($options); $res = $CountryImagesM->save(); } //end for } //end foreach } //end if }