/**
  * deleting an album also needs to delete imagesets and images.
  * @see PerchBase::delete()
  */
 public function delete()
 {
     //get imagesets for this album
     $PerchGallery_Images = new PerchGallery_Images();
     $images = $PerchGallery_Images->get_by_album_id($this->id());
     if (is_array($images)) {
         foreach ($images as $Image) {
             //call the delete method which also deletes any versions for this image
             $Image->delete();
         }
     }
     parent::delete();
     return true;
 }
Пример #2
0
/**
 * 
 * list albums, if return_image is set to true will also return an image for each album. 
 * This will be the first returned using the default sort order.
 * @param string $template
 * @param bool $return_image
 * @param bool $return
 */
function perch_gallery_albums($opts = array(), $return = false)
{
    $default_opts = array('template' => 'a_album.html', 'image' => false, 'skip-template' => false);
    $opts = array_merge($default_opts, $opts);
    if ($opts['skip-template']) {
        $return = true;
    }
    $API = new PerchAPI(1.0, 'perch_gallery');
    $Albums = new PerchGallery_Albums($API);
    $albums = $Albums->get_custom($opts);
    $Template = $API->get('Template');
    $Template->set('gallery/' . $opts['template'], 'gallery');
    if ($opts['image']) {
        $r = array();
        if (PerchUtil::count($albums) > 0) {
            $Images = new PerchGallery_Images($API);
            foreach ($albums as $details) {
                $FirstImage = $Images->get_by_album_id($details['albumID'], false, 1);
                if (is_object($FirstImage)) {
                    $details = array_merge($FirstImage->to_array(), $details);
                }
                $r[] = $details;
            }
        }
        if (!$opts['skip-template']) {
            $r = $Template->render_group($r, true);
        }
    } else {
        // just render basic album data
        if (!$opts['skip-template']) {
            $r = $Template->render_group($albums, true);
        }
    }
    if ($opts['skip-template']) {
        return $albums;
    }
    if ($return) {
        return $r;
    }
    echo $r;
}
                }
            }
            $message = $HTML->success_message('The selected images have been deleted.');
        }
    }
}
$SortForm = $API->get('Form');
$SortForm->set_name('sort');
if ($SortForm->submitted()) {
    if ($SortForm->submitted_via_ajax) {
        $postvars = array('order');
        $data = $Form->receive($postvars);
        $order = explode(',', $data['order']);
        if (PerchUtil::count($order)) {
            $i = 1;
            foreach ($order as $imageID) {
                $Image = $Images->find(trim($imageID));
                if (is_object($Image)) {
                    $new_order = array();
                    $new_order['imageOrder'] = $i;
                    $Image->update($new_order);
                }
                $i++;
            }
        }
        echo $SortForm->get_token();
        exit;
    }
}
$images = $Images->get_by_album_id($albumID, array('admin_thumb'));