My scenario is to let user create a album/gallery and then upload photos into the album/gallery.
What is the recommended solution for this?

I looked at some of the existing modules:
images, simplegallery, image_gallery etc

The big issue is that they rely on the Taxonomy for the album/gallery parent. This means having to expose the taxonomy admin if I want to allow users to create the albums.

One approach I was thinking of was to have a content type 'Albums' and then have image fields for the album. It may work - but how would i approach the issue of allowing multiple uploads?

I am sure this is a common issue.
(BTW: I want to avoid integration into Gallery2).

Comments

WorldFallz’s picture

when ported over to d6, the http://drupal.org/project/imagefield_import module should handle the multipe uploads you're looking for.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

nextpulse’s picture

"One approach I was thinking of was to have a content type 'Albums' and then have image fields for the album. It may work - but how would i approach the issue of allowing multiple uploads?"

It seems I can use 'unlimited' for the field.

So far, it seems to work - but is this the best approach?

dnewkerk’s picture

What that does is store each image inside the same imagefield. May or may not be what you want to do. There's an Imagefield gallery module I believe that can augment this method a bit. With this way images themselves aren't nodes, so depending on what functionality you want for the images, you won't be able to have that (e.g. commenting on individual images, images having their own page, images in a given Album "owned" by different users, etc).

One way I do it is to make an Album node, like you mentioned. However this node is "just" the album, not the photos (on the album node I just specify the title of the album, and maybe body text to introduce what the album is). Next I make a Photo CCK type. On that I add a Node Reference field called field_photo_album, and set the "Content types that can be referenced" option to just "Photo Album". Now, when a Photo node is uploaded, I can choose which Photo Album node I want to relate it to.

The last trick at that point is to get the Photos of a given album to show up on a given Photo Album node. For that I make a View that lists out "all" the Photos but has a Node Reference argument on it. I embed that View directly in my node-photo_album.tpl.php file.

Here's the photo_album View (Views 1... this may not work on Views 2):

  $view = new stdClass();
  $view->name = 'photo_album';
  $view->description = 'View embedded on Photo Album nodes, filtered by a nodereference argument the Photo Album node provides.';
  $view->access = array (
);
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = '';
  $view->page_header = '';
  $view->page_header_format = '1';
  $view->page_footer = '';
  $view->page_footer_format = '1';
  $view->page_empty = '';
  $view->page_empty_format = '1';
  $view->page_type = 'list';
  $view->url = '';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '4';
  $view->sort = array (
    array (
      'tablename' => 'node',
      'field' => 'created',
      'sortorder' => 'DESC',
      'options' => 'normal',
    ),
  );
  $view->argument = array (
    array (
      'type' => 'content: field_photo_album',
      'argdefault' => '2',
      'title' => '',
      'options' => '',
      'wildcard' => '',
      'wildcard_substitution' => '',
    ),
  );
  $view->field = array (
    array (
      'tablename' => 'node',
      'field' => 'title',
      'label' => '',
      'handler' => 'views_handler_field_nodelink',
      'options' => 'link',
    ),
    array (
      'tablename' => 'node_data_field_photo',
      'field' => 'field_photo_fid',
      'label' => '',
      'handler' => 'content_views_field_handler_ungroup',
      'options' => 'thickbox][photoalbum-small',
    ),
  );
  $view->filter = array (
  );
  $view->exposed_filter = array (
  );
  $view->requires = array(node, node_data_field_photo);
  $views[$view->name] = $view;

And here's what I put in node-photo_album.tpl.php to pull that View up and pass it the Node Reference so just the correct photos show:

<?php
    // load the context-node's 'metadata'
  global $current_view;
    // * define the context-node's NID as the argument
  $current_view->args[0]=$node->nid;
    // * select the name of the view to embed as $view1
  $albumview = views_get_view('photo_album');                     
    // send $args to the View's Argument Handler and display $view1 in the context-node
    print (views_build_view('embed', $albumview, $current_view->args, true, 24)); // paging = true, # = number of results per page
?>

This is a bit much to wrap one's mind around I know haha... but it works nicely once it's done, and requires no taxonomy.
Getting it to work quite like this will take more explanation, but here's an example: http://www.firehousekidz.com/media/photos
The way to embed a View in Views 2 is different now... I have a bit of help on that here: http://www.davidnewkerk.com/book/8

-- David
absolutecross.com
[new guide/lesson in progress: Creating a CCK and Views powered Drupal site - feedback welcome]

nextpulse’s picture

Found this (similar to what I suggested):

http://www.primalmedia.com/blog/building-better-drupal-photo-gallery

But I think your suggestion makes more sense - treating each photo as a node.
'Photo CCK type' - does this have to be custom developed?

dnewkerk’s picture

Thanks for the link, I'll check it out.

'Photo CCK type' - does this have to be custom developed?

No, simply install CCK (ensure Node Reference is selected as well). Create a new Content Type as you would normally, but you are now able to add custom fields. Add a field to the Photo content type and for the type, choose Node Reference. You'll also need to install Imagefield and Imagecache (as well as their dependencies like Filefield and ImageAPI).

-- David
absolutecross.com
[new guide/lesson in progress: Creating a CCK and Views powered Drupal site - feedback welcome]

Manamarak’s picture

Posted in wrong place, sorry.

nextpulse’s picture

Here it is:

http://drupal.org/project/photos

'Almost' what i needed.

dnewkerk’s picture

Tried out the demo... hard to understand since it's not in English. I'll download/install and try it out when I get the chance.
A downside of this kind of pre-packaged method is that while it's usually easier to set up initially, you end up limited/boxed in to what that module offers. Drupal these days is becoming "double" modular so to speak, making things a bit more complicated, but a lot more powerful/flexible (as in, modules themselves are being broken into more granular reusable building blocks that can be put together in many ways to create exactly what you want... at the heart of a lot of it is of course CCK and Views). In the future it's hoped that there will be modules created who's purpose will be just to "custom assemble" other component modules to create a single full set of functionality (e.g. automate all of the setup). There's "installation profiles" right now for Drupal, but that's for initially setting up a customized site from the start, not adding functionality to a pre-existing site.

-- David
absolutecross.com
[new guide/lesson in progress: Creating a CCK and Views powered Drupal site - feedback welcome]

Manamarak’s picture

Thanks for this, Keyz,

It is a very elegant solution. It means I don't have to install new modules, which are resource hungry and, as you pointed out, leaves both the images and albums as nodes, which means I can make use of views to create displays of images.

You don't know how long I have been struggling to achieve just this.

I am now trying to recreate what you have done in Views 2, but unfortunately I am struggling a bit to get my head around the whole thing.

I have created two content types, one called photos, the other called albums.

My photo content type has a 'Node Reference Field' from where I can select albums (it is called 'field_album').

Then we come to views.

In Views I have created a view called Album Contents.

Album Contents, default view, filters content by type: photos.

So far so good.

From here on in, I am a little uncertain.

I then add an argument: 'Content: Album - (field_album)'. I leave all the settings as default and save the view.

I then edit node-album.tpl.php to include

  			$view = views_get_view('album_content');
  			print $view->preview('default');
			

But when I click a link to the album, a list of all the photos on the site appears, and not just the ones in the particular album. This may be because Action to take if argument is not present: is set to Display all values but that would mean that the argument is not being passed to the view and I don't know how to do that.

I have also experimented with adding a relationship (Content: Album - (field_album)) but it makes no difference.

Any ideas on what I am doing wrong will be deeply appreciated.

dnewkerk’s picture

I'll post some exports of my Views 2 version of this as well as the custom templates as soon as possible.

-- David
davidnewkerk.com | absolutecross.com
View my Drupal lessons & guides

Manamarak’s picture

Thanks for the quick reply.

This would still be helpful though, as I still have loads of questions about how you achieved this.

Manamarak’s picture

And then the moment I clicked post I found the answer.

I think the fact that I set everything out step by step here helped me understand what I was doing wrong.

I only had to change the setting for the argument from Action to take if argument is not present: Display all values to Provide default argument

And then set Default argument type: to Node ID from URL.

I will maybe ask you a few questions again in the future, not least of which how you managed to expose the image thumbnails to the view, but I'll get back to you.

Thanks