Пример #1
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;
}