*
* @param integer $images Number of images in action
* @param boolean $add True if adding, false if removing
- * @param integer $gallery_id Gallery id to update images for, if not self
*
* @return boolean true on success
* @throws Ansel_Exception
*/
- public function updateImageCount($images, $add = true, $gallery_id = null)
+ public function updateImageCount($images, $add = true)
{
- if (is_null($gallery_id) || $gallery_id === $this->id) {
- /* Updating self */
- if ($add) {
- $this->data['attribute_images'] += $images;
- } else {
- $this->data['attribute_images'] -= $images;
- }
- try {
- $this->save();
- } catch (Horde_Share_Exception $e) {
- Horde::logMessage($e->getMessage, 'ERR');
- throw Ansel_Exception($e);
- }
+ /* Updating self */
+ if ($add) {
+ $this->data['attribute_images'] += $images;
} else {
- /* Updating other gallery */
- $g = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($gallery_id);
- $count = $g->get('images');
- if ($add) {
- $count += $images;
- } else {
- $count['attribute_images'] -= $images;
- }
- try {
- $g->save();
- } catch (Horde_Share_Exception $e) {
- Horde::logMessage($e->getMessage, 'ERR');
- throw Ansel_Exception($e);
- }
+ $this->data['attribute_images'] -= $images;
+ }
+ try {
+ $this->save();
+ } catch (Horde_Share_Exception $e) {
+ Horde::logMessage($e->getMessage, 'ERR');
+ throw Ansel_Exception($e);
}
/* Need to expire the cache for the gallery that was changed */
if ($GLOBALS['conf']['ansel_cache']['usecache']) {
- $id = (is_null($gallery_id) ? $this->id : $gallery_id);
- $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $id);
+ $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $this->id);
}
return true;
/* Update the gallery counts for each affected gallery */
if ($this->_gallery->get('has_subgalleries')) {
foreach ($gallery_ids as $id => $count) {
- $this->_gallery->updateImageCount($count, false, $id);
+ $g = $GLOBALS['injector']->getInstance('Ansel_Storage')-getScope()->getGallery($id);
+ $g->updateImageCount($count, false);
}
} else {
$this->_gallery->updateImageCount(count($ids), false);
}
- $this->_gallery->updateImageCount(count($ids), true, $gallery->id);
+ $gallery->updateImageCount(count($ids), true);
/* Expire the cache since we have no reason to save() the gallery */
if ($GLOBALS['conf']['ansel_cache']['usecache']) {
$this->_gallery->getShareOb()->getWriteDb()->exec('DELETE FROM ansel_image_attributes WHERE image_id = ' . (int)$image->id);
if (!$isStack) {
- $this->_gallery->updateImageCount(1, false, $image_gallery);
+ $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()
+ ->getGallery($image_gallery)
+ ->updateImageCount(1, false);
}
/* Update the modified flag if we are not a stack image */
/**
* The Ansel_View_Abstract:: Parent class for the various Ansel_View classes
*
+ * Copyright 2008-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
* @author Chuck Hagenbuch <chuck@horde.org>
* @author Michael J. Rubinsky <mrubinsk@horde.org>
* @package Ansel