Ansel_Gallery::copyImagesTo PHP Method

copyImagesTo() public method

Copy image and related data to specified gallery.
public copyImagesTo ( array $images, Ansel_Gallery $gallery ) : integer
$images array An array of image ids.
$gallery Ansel_Gallery The gallery to copy images to.
return integer The number of images copied
    public function copyImagesTo(array $images, Ansel_Gallery $gallery)
    {
        if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
            throw new Horde_Exception_PermissionDenied(_("Access denied copying photos to this gallery."));
        }
        $imgCnt = 0;
        foreach ($images as $imageId) {
            $img = $this->getImage($imageId);
            // Note that we don't pass the tags when adding the image..see below
            $newId = $gallery->addImage(array('image_caption' => $img->caption, 'data' => $img->raw(), 'image_filename' => $img->filename, 'image_type' => $img->getType(), 'image_uploaded_date' => $img->uploaded));
            /* Copy any tags */
            $tags = $img->getTags();
            $GLOBALS['injector']->getInstance('Ansel_Tagger')->tag($newId, $tags, $gallery->get('owner'), 'image');
            // Check that new image_id doesn't have existing attributes,
            // throw exception if it does.
            $newAttributes = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImageAttributes($newId);
            if (count($newAttributes)) {
                throw new Ansel_Exception(_("Image already has existing attributes."));
            }
            $exif = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImageAttributes($imageId);
            if (is_array($exif) && count($exif) > 0) {
                foreach ($exif as $name => $value) {
                    $GLOBALS['injector']->getInstance('Ansel_Storage')->saveImageAttribute($newId, $name, $value);
                }
            }
            ++$imgCnt;
        }
        return $imgCnt;
    }