/** * carries out the specified album */ function perform() { // get the album id $albumId = $this->_request->getValue("albumId"); // load the resource $albums = new GalleryAlbums(); // create the view $this->_view = new AdminResourcesListView($this->_blogInfo); // fetch the resource albumm first, to get some info about it $album = $albums->getAlbum($albumId, $this->_blogInfo->getId(), false); if (!$album) { $this->_view->setErrorMessage($this->_locale->tr("error_fetching_album")); $this->setCommonData(); return false; } // notify of the "pre" delete event $this->notifyEvent(EVENT_PRE_ALBUM_DELETE, array("album" => &$album)); // // this album cannot be deleted if either: // 1) we have resources under it // 2) we have child albums under it // if ($album->getNumChildren() > 0 || $album->getNumResources() > 0) { $this->_view->setErrorMessage($this->_locale->pr("error_album_has_children", $album->getName())); } else { // otherwise, we can go ahead and remove it if ($albums->deleteAlbum($albumId, $this->_blogInfo->getId())) { $this->_view->setSuccessMessage($this->_locale->pr("album_deleted_ok", $album->getName())); $this->notifyEvent(EVENT_PRE_ALBUM_DELETE, array("album" => &$album)); // clear the cache CacheControl::resetBlogCache($this->_blogInfo->getId(), false); } else { $this->_view->setErrorMessage($this->_locale->pr("error_deleting_album", $album->getName())); } } // return the view $this->setCommonData(); // better to return true if everything fine return true; }
/** * deletes resources from the list */ function _deleteAlbums() { $albums = new GalleryAlbums(); // loop through the array of resource ids and // remove them all foreach ($this->_albumIds as $albumId => $value) { // fetch the resource first, to get some info about it $album = $albums->getAlbum($albumId, $this->_blogInfo->getId()); if (!$album) { $this->_errorMessage .= $this->_locale->pr("error_deleting_album2", $albumId) . "<br/>"; } else { if ($album->getNumChildren() > 0 || $album->getNumResources() > 0) { $this->_errorMessage .= $this->_locale->pr("error_album_has_children", $album->getName()); } else { $this->notifyEvent(EVENT_PRE_ALBUM_DELETE, array("album" => &$album)); // and now remove it $res = $albums->deleteAlbum($albumId, $this->_blogInfo->getId()); if ($res) { $this->_totalOk++; if ($this->_totalOk > 1) { $this->_successMessage = $this->_locale->pr("items_deleted_ok", $this->_totalOk); } else { $this->_successMessage = $this->_locale->pr("item_deleted_ok", $album->getName()); } $this->notifyEvent(EVENT_POST_ALBUM_DELETE, array("album" => &$album)); } else { $this->_errorMessage .= $this->_locale->pr("error_deleting_album", $album->getName()) . "<br/>"; } } } } return true; }