public function deleteAlbumAction() { $this->_helper->layout()->disableLayout(); $albumId = $this->_getParam('id'); $objModelAlbum = new Album_Model_Album(); $objModelAlbumPhoto = new Album_Model_AlbumPhoto(); $objModelAlbumTag = new Album_Model_AlbumTag(); $objModelAlbumPhotoTag = new Album_Model_AlbumPhotoTag(); $objModelPhotoTag = new Album_Model_PhotoTag(); $objModelComment = new Application_Model_Comment(); // Remove all comment for album $whereAlbumComment = "item_type='album_comment' AND item_id='{$albumId}'"; $objModelComment->delete($whereAlbumComment); // Remove all album tag $whereAlbumTag = "album_id='{$albumId}'"; $objModelAlbumTag->delete($whereAlbumTag); // Fetch all photo of album $whereAlbumPhoto = "album_id='{$albumId}'"; $arrPhoto = $objModelAlbumPhoto->fetchAll($whereAlbumPhoto); if (count($arrPhoto) > 0) { foreach ($arrPhoto as $photo) { $photoId = $photo->id; $photoName = $photo->image; $imagePathT = PUBLIC_PATH . "/media/album/thumb/" . $photoName; $imagePathC = PUBLIC_PATH . "/media/album/custom/" . $photoName; $imagePathD = PUBLIC_PATH . "/media/album/default/" . $photoName; unlink($imagePathT); // Remove image from thumb folder unlink($imagePathC); // Remove image from custom folder unlink($imagePathD); // Remove image from default folder // Remove photo comment $wherePhotoComment = "item_type='photo_comment' AND item_id='{$photoId}'"; $objModelComment->delete($wherePhotoComment); // Remove tagged photo $whereTaggedPhoto = "photo_id='{$photoId}'"; $objModelPhotoTag->delete($whereTaggedPhoto); // Remove photo tag $whereAlbumPhotoTag = "photo_id='{$photoId}'"; $objModelAlbumPhotoTag->delete($whereAlbumPhotoTag); } } // Remove all photo $whereAlbumPhoto = "album_id='{$albumId}'"; $objModelAlbumPhoto->delete($whereAlbumPhoto); // Remove Album $whereAlbum = "id='{$albumId}'"; $objModelAlbum->delete($whereAlbum); $this->_redirect('/album/my-photos'); $this->_helper->viewRenderer->setNoRender(true); }
public function albumPhotoDeleteAction() { $this->_helper->layout()->disableLayout(); $objModelAlbumPhotoTag = new Album_Model_AlbumPhotoTag(); $objModelAlbumPhoto = new Album_Model_AlbumPhoto(); $objModelVote = new Application_Model_Vote(); $objModelComment = new Application_Model_Comment(); $arrPostVal = $this->getRequest()->getParams(); $photoId = $arrPostVal['photoId']; $albumId = !empty($arrPostVal['id']) ? $arrPostVal['id'] : ""; $page = !empty($arrPostVal['page']) ? $arrPostVal['page'] : ""; /*----------------- GET PHOTO NAME --------------------------------*/ $valPhoto = $objModelAlbumPhoto->find($photoId); $photoName = $valPhoto->getName(); /*----------------- REMOVE PHOTO DETAIL ---------------------------*/ $whereAlbumPhotoTag = "photo_id='{$photoId}'"; $whereComment = "item_type='photo_comment' AND item_id='{$photoId}'"; $whereVote = "item_type='album_photo' AND item_id='{$photoId}'"; $whereAlbumPhoto = "id='{$photoId}'"; $objModelAlbumPhotoTag->delete($whereAlbumPhotoTag); $objModelComment->delete($whereComment); $objModelVote->delete($whereVote); $objModelAlbumPhoto->delete($whereAlbumPhoto); /*---------------------- REMOVE PHOTO FROM FILE --------------------------------*/ unlink(PUBLIC_PATH . "/images/album/thumb/{$photoName}"); // Remove thumb image unlink(PUBLIC_PATH . "/images/album/custom/{$photoName}"); // Remove resized image unlink(PUBLIC_PATH . "/images/album/default/{$photoName}"); // Remove default image /*------------------------------------------------------------------------------*/ if ($albumId != "" && $page != "") { header("location:/album/my-photos/review-edit-image/id/{$albumId}/page/{$page}"); } exit; }