Hello folks,
is it possible to show a random picture from a certain album in drupal?

Let's say you have a user profile page in drupal and want to show a random picture from this user's gallery on the profil page. How could this be done?
Ok it is no big deal to show a random picture, but how do I tell gallery to use only a certain album?

Regards,
macco

Comments

macco’s picture

Status: Active » Closed (fixed)

I found a solution, that works for me. In case your are interested.
I wrote a function that I can use in the user-profile.tpl-file, it returns the random imagethumbnail as a link to original picture, as a parameter it needs a drupal $user-opbject.



function get_random_gallery_picture($user)
{
  // load gallery_user 
  $g2_user = gallery_user_info($user);
  print $g2_user['g2_id'];        
  // load itemId
  list ($ret, $albumId) = GalleryCoreApi::getPluginParameter('module', 'useralbum', 'albumId', $g2_user['g2_id']);  
  print $albumId;
  //load image_block 
  $params['blocks'] = 'randomImage';
  $params['show'] = 'none';
  $params['itemId'] = $albumId;
  list($ret, $content, $head) = GalleryEmbed::getImageBlock($params);
    if ($ret) {
      gallery_error(t('Unable to get Gallery image block'), $ret);
      return;
    } else {
      if ($content) {
        return $content;
      }
    }
  
 } 

I hope this helps, if I could do things more elegant or I missed something, please let me know.

Regards,
macco

macco’s picture

I'm sorry,
please delete the two print-statements, they where only for debugging purposes.

profix898’s picture

Using the latest development version of gallery.module 5.x-2.x-dev you can configure the block to use items from the useralbum only and include this block in the profile template. To include the first available image block (image-0) you would use the following snippet:

$block = module_invoke('gallery', 'block', 'view', 'image-0');
print $block['content'];