Example #1
0
 public function editPhotoAction()
 {
     $id = $this->_request->getParam('photo_id');
     $form = new Application_Form_GalleryForm();
     $this->view->photo_id = $id;
     if (isset($id)) {
         $this->user_session->photo_id = $id;
     }
     if (isset($id) || isset($this->user_session->photo_id)) {
         $result = $this->photos->getPhoto($this->user_session->photo_id);
         //var_dump($result);
         //return;
         $this->view->photo_id = $result->photo_id;
         $this->view->photo_name = $result->photo_name;
         $form->photo_name->setValue($result->photo_name);
         $this->user_session->photo_name = $result->photo_name;
         $this->view->form = $form;
     }
     if (!$this->_request->isPost()) {
         $this->view->form = $form;
         return;
     }
     $formData = $this->_request->getPost();
     if (!$form->isValid($formData)) {
         $this->view->form = $form;
         return;
     }
     //For Image upload
     $file_name = NULL;
     $photo_name = $_FILES["photo_name"]["name"];
     if (isset($photo_name) && strlen($photo_name) > 0) {
         try {
             if (isset($this->user_session->photo_name)) {
                 unlink(SYSTEM_PATH . "/images/gallery-images/originals/" . $result->photo_name);
                 unlink(SYSTEM_PATH . "/images/gallery-images/200X200/" . $result->photo_name);
                 unlink(SYSTEM_PATH . "/images/gallery-images/500X500/" . $result->photo_name);
             }
             $photo_name = $_FILES['photo_name']['name'];
             $random = rand(10, 10000);
             $time = time() + 7 * 24 * 60 * 60;
             $file_name = $time . $random . $photo_name;
             $formData["photo_name"] = $file_name;
             move_uploaded_file($_FILES["photo_name"]['tmp_name'], SYSTEM_PATH . "/images/gallery-images/originals/" . $file_name);
             $thumb = new Application_Model_Thumbnail(SYSTEM_PATH . "/images/gallery-images/originals/" . $file_name);
             $thumb->resize(500, 500);
             $thumb->save(SYSTEM_PATH . '/images/gallery-images/500X500/' . $file_name);
             $thumb->resize(200, 200);
             $thumb->save(SYSTEM_PATH . '/images/gallery-images/200X200/' . $file_name);
         } catch (Zend_File_Transfer_Exception $e) {
             throw new Exception('Bad data: ' . $e->getMessage());
         }
     } else {
         $formData['photo_name'] = $this->user_session->photo_name;
     }
     $formData['photo_id'] = $this->user_session->photo_id;
     $result = $this->photos->editPhoto($formData);
     $this->_redirect("/admin/gallery/photo-list");
 }
 public function editPhotoAction()
 {
     $id = $this->_request->getParam('id');
     if (!isset($id)) {
         $this->_redirect('admin/gallery/index');
     }
     $form = new Application_Form_GalleryForm();
     // get photo data from photos table
     $result = $this->photos->getPhotoByID($id);
     $this->view->id = $result->photo_id;
     $form->photo_name->setValue($result->photo_name);
     $this->view->photo = $result->photo_name;
     $form->link->setValue($result->link);
     $form->caption->setValue($result->caption);
     $form->category->setValue($result->pg_cat_id);
     $form->description->setValue($result->description);
     $this->view->form = $form;
     if (!$this->_request->isPost()) {
         return;
     }
     $formData = $this->_request->getPost();
     if (!$form->isValid($formData)) {
         return;
     }
     //For Image upload
     $file_name = NULL;
     $image_name = $_FILES["photo_name"]["name"];
     if (isset($image_name) && strlen($image_name) > 0) {
         try {
             if (isset($result->photo_name)) {
                 $image_file = SYSTEM_PATH . "/images/user/photo_gallery/500X500/" . $result->photo_name;
                 if (file_exists($image_file)) {
                     unlink(SYSTEM_PATH . "/images/user/photo_gallery/" . $result->photo_name);
                 }
                 if (file_exists($image_file)) {
                     unlink(SYSTEM_PATH . "/images/user/photo_gallery/200X200/" . $result->photo_name);
                 }
                 if (file_exists($image_file)) {
                     unlink(SYSTEM_PATH . "/images/user/photo_gallery/500X500/" . $result->photo_name);
                 }
             }
             $photo_name = $_FILES['photo_name']['name'];
             $random = rand(9, 999999);
             $file_name = $random . $photo_name;
             $formData["photo_name"] = $file_name;
             move_uploaded_file($_FILES["photo_name"]['tmp_name'], SYSTEM_PATH . "images/user/photo_gallery/" . $file_name);
             $thumb = new Application_Model_Thumbnail(SYSTEM_PATH . "images/user/photo_gallery/" . $file_name);
             $thumb->resize(500, 500);
             $thumb->save(SYSTEM_PATH . "images/user/photo_gallery/500X500/" . $file_name);
             $thumb->resize(200, 200);
             $thumb->save(SYSTEM_PATH . "images/user/photo_gallery/200X200/" . $file_name);
         } catch (Zend_File_Transfer_Exception $e) {
             throw new Exception('Bad data: ' . $e->getMessage());
         }
     } else {
         $formData['photo_name'] = $result->photo_name;
     }
     $formData['photo_id'] = $id;
     $result = $this->photos->editPhoto($formData);
     $this->view->msg = $result;
     $this->_redirect("/admin/gallery/edit-photo/id/" . $id);
 }