Ansel_Gallery::set PHP Method

set() public method

Sets an attribute value in this object.
public set ( string $attribute, mixed $value, boolean $update = false )
$attribute string The attribute to set.
$value mixed The value for $attribute.
$update boolean Commit only this change to storage.
    public function set($attribute, $value, $update = false)
    {
        if ($attribute == 'slug') {
            $this->_oldSlug = $this->get('slug');
        }
        /* Need to serialize the style object */
        if ($attribute == 'style') {
            $value = serialize($value);
        }
        if ($attribute == 'view_mode' && $this->get('view_mode') != $value) {
            //$mode = isset($attributes['attribute_view_mode']) ? $attributes['attribute_view_mode'] : 'Normal';
            $this->_setModeHelper($value);
        }
        try {
            $this->_share->set($attribute, $value, $update);
        } catch (Horde_Share_Exception $e) {
            throw new Ansel_Exception($e);
        }
    }

Usage Example

示例#1
0
 /**
  * Empties a gallery of all images.
  *
  * @param Ansel_Gallery $gallery  The ansel gallery to empty.
  *
  * @throws Ansel_Exception
  */
 public function emptyGallery(Ansel_Gallery $gallery)
 {
     $gallery->clearStacks();
     $images = $gallery->listImages();
     foreach ($images as $image) {
         // Pretend we are a stack so we don't update the images count
         // for every image deletion, since we know the end result will
         // be zero.
         try {
             $gallery->removeImage($image, true);
         } catch (Horde_Exception_NotFound $e) {
             // Don't worry about missing images since we are deleting them
             // anyway.
             Horde::log($e->getMessage(), 'ERR');
         }
     }
     $gallery->set('images', 0, true);
     // Clear the OtherGalleries widget cache
     if ($GLOBALS['conf']['ansel_cache']['usecache']) {
         $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_OtherGalleries' . $gallery->get('owner'));
         $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $gallery->id);
     }
 }