I'm using imagecache, imagefield, views and taxonomy to create image galleries by album. I love the flexibility of this setup, however, I need to create a summary page of all of my albums (vocab terms) ordered by date of creation. (I use a free tagging vocabulary to create the albums and assign this to a group of images using imagefield_import). After following several other threads, I came across the suggestion at http://lasqueti.ca/books/design-notes/image-gallery-summary-view. Although this works beautifully to create a summary of my albums, I can only sort the albums alphabetically and not by created date. It seems that this might be impossible to do using my current setup.

If that is the case, I am more than willing to try another solution. Does anyone know of a setup (image_gallery, acidfree, brilliant_gallery, etc.) where I can create image galleries by album, present a summary of my albums, and have this summary sorted by the creation date of the album? In addition, I need some way to bulk import images (something similar to imagefield_import).

I appreciate your suggestions!

Comments

jasonkotter’s picture

I've modified the code at http://lasqueti.ca/books/design-notes/image-gallery-summary-view to sort by date by creating

$sortby=array()

before

foreach ($nodes as $query) {

and then replacing the end of the loop (I've kept the first line the same so that you can easily reference where to insert this) with the following code:

$linkText = $imgTag .' '. $title;
// Create an array with the created date as keys and the themed output as values
$content2 = _theme_gallery_summary($imgTag, $url, $title, $query->num_nodes, $modDate, $description);
$sortdate[$modDate] = $content2;
// sort by date, newest to oldest
krsort($sortdate);
}
foreach ($sortdate as $value) {
$content .= $value;
}

Hopefully this is helpful to someone! One final question to bounce off of anyone who reads this - this code limits the number of summary galleries to the number of images I have set to display per page in my view. For example, I have set in my view to display 12 photos per page with a pager; consequently, only the 12 most recent albums show on my summary album page - there is no pager on this page.

I thought that I might could fix this by changing the false to true in

$result = views_build_view('items', $view, array($arg), false, 1);

but this only messed things up. Any ideas how I could add a pager so that my summary album page will show all of my albums?

jasonkotter’s picture

Previously I was able to create a themed album summary view ordered by date by modifying the above code. However, it was difficult to add pagers to this summary view, so I have rewritten the code using SQL. I'm not an expert on SQL, so I would appreciate you looking at my code for a moment and letting me know if it looks reasonably efficient (or if there are any glaring efficiency problems).

Given the lack of response on this thread, I don't have much hope that anyone will read this . . . but it's worth a shot.

function theme_summary_view_image_gallery($view, $type, $level, $nodes, $args) {
  // This is the name of the imagecache preset to use for the thumbnail 
  //  image shown on the summary gallery listing.
  $preset = 'image_thumb';

  $baseUrl = $view->url;
  $content .= '<ul class="galleries">';
  // Build a query to pull a list of albums (vid=1), a cover photo for
  // each album, and sort the albums from newest to oldest.
    $sql = 'SELECT name , description, count , created , filepath '
        . ' FROM term_data AS a , ( select tid , min( nid ) as nid , count( nid ) as count '
        . ' from term_node group by tid ) as b , files as c , node as d '
        . ' WHERE a.tid = b.tid '
        . ' AND a.vid = 1 '
        . ' AND b.nid = c.nid '
        . ' AND c.nid = d.nid '
        . ' ORDER BY created desc';
    //  Add pages to the resulting albums.  $num_per_page is set to be the number of albums per page
    $num_per_page = 4;
    $result_set = pager_query($sql,$num_per_page);

    while ($obj = db_fetch_object($result_set)){
        // Theme the image tag using the hard-coded imagecache preset
       $imgTag = theme('imagecache', $preset, $obj->filepath, 'Latest image from gallery', $obj->name);
       // Add link to the album.  Note that the taxonomy name is the path to follow to reach the album.
       $url= $baseUrl .'/'. $arg .$obj->name;
       // Theme the list of albums
       $content .= _theme_gallery_summary($imgTag, $url, $obj->name, $obj->count, $obj->created, $obj->description);
   }
    $content .= "</ul>\n";
return $content;
}

Thanks!