Update the gallery image count.
public updateImageCount ( integer $images, boolean $add = true ) | ||
$images | integer | Number of images in action |
$add | boolean | True if adding, false if removing |
/** * Moves images from one gallery to another. Since we're viewing by date * some images might belong to a subgallery so we need to take care to * udate the appropriate gallery data. * * @param array $images An array of image_ids to move. * @param Ansel_Gallery $gallery The Ansel_Gallery to move them to. * * @return boolean */ public function moveImagesTo($images, $gallery) { if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) { throw new Horde_Exception_PermissionDenied(_("Access denied moving photos to this gallery.")); } elseif (!$this->_gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) { throw new Horde_Exception_PermissionDenied(_("Access denied removing photos from this gallery.")); } /* Sanitize image ids, and see if we're removing our key image. */ $ids = array(); foreach ($images as $imageId) { $ids[] = (int) $imageId; if ($imageId == $this->_gallery->get('default')) { $this->_gallery->set('default', null, true); } } /* If we have subgalleries, we need to go the more expensive route. Note * we can't use $gallery->hasSubgalleries() since that would be * overridden here since we are in date mode and thus would return false */ if ($this->_gallery->get('has_subgalleries')) { $gallery_ids = array(); $images = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImages(array('ids' => $ids)); foreach ($images as $image) { if (empty($gallery_ids[$image->gallery])) { $gallery_ids[$image->gallery] = 1; } else { $gallery_ids[$image->gallery]++; } } } /* Bulk update the images to their new gallery_id */ $GLOBALS['injector']->getInstance('Ansel_Storage')->setImagesGallery($ids, $gallery->id); /* Update the gallery counts for each affected gallery */ if ($this->_gallery->get('has_subgalleries')) { foreach ($gallery_ids as $id => $count) { $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($id)->updateImageCount($count, false); } } else { $this->_gallery->updateImageCount(count($ids), false); } $gallery->updateImageCount(count($ids), true); /* Expire the cache since we have no reason to save() the gallery */ if ($GLOBALS['conf']['ansel_cache']['usecache']) { $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $gallery->id); $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $this->_gallery->id); } return count($ids); }
/** * Move images from this gallery to another. * * @param array $images The image ids to move. * @param Ansel_Gallery $gallery The gallery to move images into. * * @return boolean * @throws Ansel_Exception * @throws Horde_Exception_PermissionDenied */ public function moveImagesTo($images, $gallery) { if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) { throw new Horde_Exception_PermissionDenied("Access denied moving photos to this gallery."); } elseif (!$this->_gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) { throw new Horde_Exception_PermissionDenied(_("Access denied removing photos from this gallery.")); } /* Sanitize image ids, and see if we're removing our key image. */ $ids = array(); foreach ($images as $imageId) { $ids[] = (int) $imageId; if ($imageId == $this->_gallery->get('default')) { $this->_gallery->set('default', null, true); } } $GLOBALS['injector']->getInstance('Ansel_Storage')->setImagesGallery($ids, $gallery->id); $this->_gallery->updateImageCount(count($ids), false); $gallery->updateImageCount(count($ids), true); /* Expire the cache since we have no reason to save() the gallery */ if ($GLOBALS['conf']['ansel_cache']['usecache']) { $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $gallery->id); $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $this->_gallery->id); } return count($ids); }