$count);
}
-
+ /**
+ *
+ * @param array $images The image ids to move.
+ * @param Ansel_Gallery $gallery The gallery to move images into.
+ *
+ * @throws Ansel_Exception
+ * @throws Horde_Exception_PermissionDenied
+ * @return boolean
+ */
function moveImagesTo($images, $gallery)
{
if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
- return PEAR::raiseError(sprintf(_("Access denied moving photos to \"%s\"."), $newGallery->get('name')));
+ throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied moving photos to \"%s\"."), $newGallery->get('name')));
} elseif (!$this->_gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
- return PEAR::raiseError(sprintf(_("Access denied removing photos from \"%s\"."), $gallery->get('name')));
+ throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied removing photos from \"%s\"."), $gallery->get('name')));
}
/* Sanitize image ids, and see if we're removing our default image. */
}
$result = $this->_gallery->_shareOb->_write_db->exec('UPDATE ansel_images SET gallery_id = ' . $gallery->id . ' WHERE image_id IN (' . implode(',', $ids) . ')');
- if (is_a($result, 'PEAR_Error')) {
- return $result;
+ if ($result instanceof PEAR_Error) {
+ throw new Ansel_Exception($result->getMessage());
}
$this->_gallery->updateImageCount(count($ids), false);
return true;
}
+ /**
+ *
+ * @param integer | Ansel_Image $image The image id or object
+ * @param boolean $isStack This represents a stack image
+ *
+ * @return boolean
+ */
function removeImage($image, $isStack)
{
/* Make sure $image is an Ansel_Image; if not, try loading it. */
- if (!is_a($image, 'Ansel_Image')) {
+ if (!($image instanceof Ansel_Image)) {
$img = &$this->_gallery->getImage($image);
- if (is_a($img, 'PEAR_Error')) {
- return $img;
- }
$image = $img;
} else {
/* Make sure the image is in this gallery. */
private $_perPage;
/**
- * Contructor - just set some instance variables.
+ * Contructor.
+ *
+ * Also handles any actions from the view. TODO: These should be done with
+ * an init() or handle() method instead.
*
* @return Ansel_View_Results
*/
$this->_owner = Horde_Util::getFormData('owner', null);
$this->_search = Ansel_Tags::getSearch(null, $this->_owner);
$this->_page = Horde_Util::getFormData('page', 0);
-
$action = Horde_Util::getFormData('actionID', '');
$image_id = Horde_Util::getFormData('image');
$vars = Horde_Variables::getDefaultVariables();
- // Number perpage from prefs or config.
- $this->_perPage = min($prefs->getValue('tilesperpage'),
- $conf['thumbnail']['perpage']);
+ /* Number perpage from prefs or config. */
+ $this->_perPage = min($prefs->getValue('tilesperpage'), $conf['thumbnail']['perpage']);
switch ($action) {
- // Image related actions
+ /* Image related actions */
case 'delete':
if (is_array($image_id)) {
$images = array_keys($image_id);
}
foreach ($images as $image) {
- // Need a gallery object to delete the image, but need
- // the image object to get the gallery.
$img = $ansel_storage->getImage($image);
$gallery = $ansel_storage->getgallery($img->gallery);
if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
$notification->push(
- sprintf(_("Access denied deleting photos from \"%s\"."), $image),
- 'horde.error');
+ sprintf(_("Access denied deleting photos from \"%s\"."), $image), 'horde.error');
} else {
- $result = $gallery->removeImage($image);
- if (is_a($result, 'PEAR_Error')) {
+ try {
+ $result = $gallery->removeImage($image);
+ $notification->push(_("Deleted the photo."), 'horde.success');
+ Ansel_Tags::clearCache();
+ } catch (Ansel_Exception $e) {
$notification->push(
- sprintf(_("There was a problem deleting photos: %s"), $result->getMessage()), 'horde.error');
- } else {
- $notification->push(_("Deleted the photo."), 'horde.success');
- Ansel_Tags::clearCache();
- }
+ sprintf(_("There was a problem deleting photos: %s"), $e->getMessage()), 'horde.error');
+ }
}
}
- // Reload the browse view again to get notifications.
header('Location: ' . Ansel::getUrlFor('view',
array('view' => 'Results'),
true));
// valid image ID.
$newGallery = Horde_Util::getFormData('new_gallery');
if ($images && $newGallery) {
- $newGallery = $ansel_storage->getGallery($newGallery);
- if (is_a($newGallery, 'PEAR_Error')) {
- $notification->push(_("Bad input."), 'horde.error');
- } else {
+ try {
+ $newGallery = $ansel_storage->getGallery($newGallery);
// Group by gallery first, then process in bulk by gallery.
$galleries = array();
foreach ($images as $image) {
}
foreach ($galleries as $gallery_id => $images) {
$gallery = $ansel_storage->getGallery($gallery_id);
- $result = $gallery->moveImagesTo($images, $newGallery);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result, 'horde.error');
- } else {
+ try {
+ $result = $gallery->moveImagesTo($images, $newGallery);
$notification->push(
sprintf(ngettext("Moved %d photo from \"%s\" to \"%s\"",
"Moved %d photos from \"%s\" to \"%s\"",
count($images), $gallery->get('name'),
$newGallery->get('name')),
'horde.success');
+ } catch (Exception $e) {
+ $notification->push($e->getMessage(), 'horde.error');
}
}
+ } catch (Ansel_Exception $e) {
+ $notification->push(_("Bad input."), 'horde.error');
}
}
-
- // Return to the image list.
- $imageurl = Horde_Util::addParameter('view.php',
- array('view' => 'Results'));
header('Location: ' . Ansel::getUrlFor('view',
array('view' => 'Results'),
true));
$images = array($image_id);
}
- // Move the images if we're provided with at least one
- // valid image ID.
$newGallery = Horde_Util::getFormData('new_gallery');
if ($images && $newGallery) {
- $newGallery = $ansel_storage->getGallery($newGallery);
- if (is_a($newGallery, 'PEAR_Error')) {
- $notification->push(_("Bad input."), 'horde.error');
- } else {
- // Group by gallery first, then process in bulk by gallery.
+ try {
+ /* Group by gallery first, then process in bulk by gallery. */
+ $newGallery = $ansel_storage->getGallery($newGallery);
$galleries = array();
foreach ($images as $image) {
$img = $ansel_storage->getImage($image);
}
foreach ($galleries as $gallery_id => $images) {
$gallery = $ansel_storage->getGallery($gallery_id);
- $result = $gallery->copyImagesTo($images, $newGallery);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result, 'horde.error');
- } else {
+ try {
+ $result = $gallery->copyImagesTo($images, $newGallery);
$notification->push(
sprintf(ngettext("Copied %d photo from %s to %s",
"Copied %d photos from %s to %s",
count($images), $gallery->get('name'),
$newGallery->get('name')),
'horde.success');
+ } catch (Exception $e) {
+ $notification->push($e->getMessage(), 'horde.error');
}
}
+ } catch (Ansel_Exception $e) {
+ $notification->push(_("Bad input."), 'horde.error');
}
}
-
- // Return to the image list.
- $imageurl = Horde_Util::addParameter('view.php',
- array('view' => 'Results'));
- header('Location: ' . Horde::applicationUrl($imageurl, true));
+ header('Location: ' . Ansel::getUrlFor('view', array('view' => 'Results'), true));
exit;
- // Tag related actions
+ /* Tag related actions */
case 'remove':
$tag = Horde_Util::getFormData('tag');
if (isset($tag)) {
break;
}
- // Check for empty tag search and redirect if empty
+ /* Check for empty tag search and redirect if empty */
if ($this->_search->tagCount() < 1) {
header('Location: ' . Horde::applicationUrl('browse.php', true));
exit;
*/
public function html()
{
- global $conf, $prefs, $registry, $ansel_storage;
+ global $conf, $prefs, $ansel_storage;
// Get the slice of galleries/images to view on this page.
$results = $this->_search->getSlice($this->_page, $this->_perPage);