Ansel_Gallery::addImageObject PHP Method

addImageObject() public method

Adds an Ansel_Image object to this gallery.
public addImageObject ( Ansel_Image $image, boolean $default = false ) : integer
$image Ansel_Image The ansel image object to add
$default boolean Set this image as the gallery's key image.
return integer The new image id
    public function addImageObject(Ansel_Image $image, $default = false)
    {
        // Normal is the only view mode that can accurately update counts
        $vMode = $this->get('view_mode');
        if ($vMode != 'Normal') {
            $this->_setModeHelper('Normal');
        }
        // Make sure it's taken as a new image
        $image->id = null;
        $image->gallery = $this->id;
        $image->sort = $this->countImages();
        $image->save();
        $this->updateImageCount(1);
        // Should this be the key image?
        if ($default) {
            $this->set('default', $image->id);
            $this->clearStacks();
        }
        /* Save all changes to the gallery */
        $this->save();
        // Return to the proper view mode
        if ($vMode != 'Normal') {
            $this->_setModeHelper($vMode);
        }
        return $image->id;
    }