Hi All,
I just start to think about how to integrate views with the new 6.x-3.x branch. I would like to start with the node_gallery_handler_field_gid.inc.
Maybe we should rename it to Node Gallery Cover Image. The GID we can just get via node->nid and our handler is allready delivering an image and no ID.
So if we want to show an image, we will have to solve two problems. At the moment we have a form (Specify Node Gallery Setting) that only allows us to "filter" one type of gallery not two or three at the same time.
I think we just can have the same result (filter by gallery_type settings) only filter via views standard node->type filter. So I would remove this option from the views handler and simply get the node object and then get the $gallery->config['gallery_type'] settings, call it via node_gallery_get_config($gallery->config['gallery_type']);
The advantage of this is: 1. Removed Filter that duplicates functionality and may confuse user, 2. have the possibility to get all node galleries in one view without breaking it.
Second Problem is that we are searching the db only for cover images. In node gallery it is not necesarry to have a cover image. So a gallery without cover image breaks our view again. I would like to make a second run on the db if there is no cover image.
What you guys think about this?
Comments
Comment #1
designwork commentedHi All,
Thinking more about the Node Gallery GID / cover image handler. I came to the conclusion, that I would prefer if I could choose the image size for my Gallery Images on the default Gallery View and they should be rendered by the same imagecache preset.
So I changed the handler
<?php
// $Id: node_gallery_handler_field_gid.inc,v 1.1.2.6 2010/01/13 02:48:44 justintime Exp $
/**
* @file node_gallery_handler_field_gid.inc
*
*
*/
class node_gallery_handler_field_gid extends views_handler_field {
function option_definition() {
$options = parent::option_definition();
$options['link_to_node'] = array('default' => TRUE);
$options['node_gallery_setting'] = $imagecaches;
return $options;
}
function options_form(&$form, &$form_state) {
//Get all imagecache presets here
if (empty($imagecaches)) {
foreach (imagecache_presets() as $id => $imagecache) {
$imagecaches[$imagecache['presetname']] = $imagecache['presetname'];
}
}
if (empty($imagecaches)) {
form_set_error('Node gallery config', t('There are no imagecache presets. You must create at least one preset.', array('@imagecache' => url('admin/build/imagecache/add'))));
}
/*$configs = node_gallery_get_config();
foreach ($configs as $gallery_type => $config) {
$options[$gallery_type] = $config['name'];
}*/
$options[$gallery_type] = $imagecaches;
parent::options_form($form, $form_state);
$form['link_to_node'] = array(
'#title' => t('Link this field to its node'),
'#description' => t('This will override any other link you have set.'),
'#type' => 'checkbox',
'#default_value' => $this->options['link_to_node'],
);
$form['node_gallery_setting'] = array(
'#title' => t('Specify Node Gallery Image Setting'),
'#description' => t('Specify which image size you want to have.'),
'#type' => 'select',
'#multiple' => TRUE,
'#default_value' => $this->options['node_gallery_setting'],
'#options' => $options,
);
}
function pre_render(&$values) {
foreach ($values as $value) {
//$fids[$this->field_alias] = $value->{$value->{$this->aliases[$this->additional_fields['fid']]}};
$gids[] = $value->{$this->field_alias};
}
if (!empty($gids)) {
$result = db_query(db_rewrite_sql("SELECT n.nid, ng.*, f.filepath, n.title FROM {node} n INNER JOIN {node_galleries} ng ON
n.nid = ng.gid INNER JOIN {files} f ON ng.fid = f.fid
WHERE ng.gid IN (". db_placeholders($gids) .") AND is_cover > 0"), $gids);
while ($r = db_fetch_array($result)) {
$items[$r['gid']] = $r;
}
// If nga is active, then fetch the access type and password from the db and merge it for use later in render()
if (module_exists('node_gallery_access')) {
$nids = array_keys($items);
$result = db_query("SELECT n.uid, n.nid, nga.access_type, nga.password FROM {node} n INNER JOIN {node_gallery_access} nga ON n.nid = nga.nid WHERE n.nid IN (". db_placeholders($nids) .")", $nids);
while ($r = db_fetch_array($result)) {
$items[$r['nid']] = array_merge((array)$items[$r['nid']], $r);
}
}
foreach ($values as $value) {
$new = array_merge((array)$value, $items[$value->{$this->field_alias}]);
$new_items[] = (object)$new;
}
$values = $new_items;
}
}
function render($value) {
//$config = node_gallery_get_config($this->options['node_gallery_setting']);
foreach ($this->options['node_gallery_setting'] as $val) {
$config = $val;
}
// if nga is there, and our gallery is password protected, show our protected image
if (module_exists('node_gallery_access')) {
if ($value->access_type == NODE_GALLERY_ACCESS_TYPE_PASSWORD) {
if (!node_gallery_access_check_access($value, 'gallery')) {
$value->filepath = node_gallery_access_default_pass_image();
}
}
}
//$image = theme('image_view', $config['image_size']['thumbnail'], $value);
$image = theme('imagecache', $val , $value->filepath, $value->title, $value->title);
if ($this->options['link_to_node']) {
return l($image, 'node/'. $value->{$this->field_alias}, array('html' => TRUE));
}
return $image;
}
}
Instead of choosing the "Gallery Settings" You may now chosse the imagecache preset to render your images. That also avoids different image sizes on the Gallery default view. And you may have Galleries with different settings but on this first default view all image sizes will be the same.
You even can make an extra preset for this view.
If someone wants to test this :) and share some ideas would be nice.
Dirk
PS I let the old code in just to compare the changes.
Comment #2
designwork commentedHi Jusintime, Kymoto
I changed two things in the handler.
The imagecache selct is not multiple any more. And the handler will even work if a gallery has no cover image.
So if you could test it would be great.
Comment #3
justintime commentedHi Dirk,
I have only a few minutes of time, and don't have any time to test this, but here's some thoughts on views and 3.x.
First, since we'll be using imagefield, all of the views code to deal with displaying the image should go away. Not only does imagecache + imagefield come with views integration, it also integrates with Lightbox2 and views seamlessly without any custom code. There's a very good chance that the purpose of having a separate node_gallery_lightbox2 module will completely go away (but I don't know for sure yet).
Also, the whole gallery GID views thing is completely confusing and worded wrong IMHO. The *only* reason a person would want a GID in a view, would be to use arguments with it. My second problem, is why call it a GID? No one knows what a GID. All it really is, is a node ID. A node ID that you should be able to get to by specifying a filter. If you have a ng_image, and want to get the node id of it's ng_gallery, then we should have a relationship to get that.
It's my opinion that making views for 3.x before we have imagefield working is putting the cart before the horse. Chances are likely that it will be easier and more productive to completely remove the current includes/*.inc files and start over fresh than it will be to make the existing code work. It will likely be much smaller, cleaner, and concise. Of course, all of this is just my opinion ;-)
All that being said, if your views code works now, then you've probably made code worth contributing to the 2.x branch. If someone has time to play with this, please post your thoughts.
I'm going to take a crack at getting imagefield into HEAD this week. I can't wait!
Comment #4
dbeall commentedI played with it for a few minutes and it is most certainly better.
Comment #5
designwork commentedHi justintime,
I agree all of your thoughts. Yes you are right we should wait until we have the imagefield integration. I would provide some of the views integration for the 3.x branch. As you could see I tryed to change as less as possible code on the handlers for now.
But I´m in a kind of hurry to get a quite stable version of the module on the 2.x branch. So I`m just providing as much as I can at the moment and I´m trying to make some basic UI thinkings wich we can, if you all agree, get as base for the 3.x branch.
Dirk
PS. I hope your son and your wife are fine.
more PS.. Thanks dbeall for testing all my code this is very nice.
Comment #6
justintime commented@Dirk - well, my son had RSV, flu, and a small pneumonia within the span of a week. Mom & Dad needed a date night after dealing with that - I think we're all back to normal now, and the entire family's health insurance deductible has been meet for the year ;-)
I'm committing this code into HEAD. I'll port back a patch to 2.x too.
Comment #8
ipwa commentedI don't want to comment on a close issue, but I think this is the most relevant. Before with 'node_galleries_gallery > gid' you had a formatter to show the cover image, I think this feature was great and I dearly miss it. You can do this now I think with relationships and arguments, but my problem is that I am already using arguments to show the image galleries as a block in the parent node (using node reference my parent node type is called topics). Before in 2.x I had the title and the 'node_galleries_gallery > gid' with the cover formatter and it worked great, now I can't do this :( - I only get the title to show up and I can add image count and last updated but no cover image
Comment #9
ipwa commentedI was able to solve it with a custom php field:
However two node_loads can't be good for performance
Comment #10
justintime commentedSo, in your view, you didn't say what the primary node type was, the image or the gallery.
If it's the image, then add a relationship of "Node Gallery: Gallery: Parent Gallery".
The rest needs to be done whether it's the gallery or the image:
Add a relationship of "Node Gallery: Gallery: Gallery Cover Image". If you added the relationship above, then on the next prompt select Parent Gallery from the list.
You now have your relationship links built. Now you can pull in *anything* from the cover image, not just the image. Add fields as you normally would, but select the Cover Image relationship when prompted.
Comment #11
sumit_drupal commentedhow to add image gallery in my existing node
Comment #12
justintime commentedsumit_drupal - please don't hijack issues. node_gallery 1.x is unsupported - I don't even personally know anyone that's ever used 1.x. If you need support, you're going to have to upgrade to at least 2.x, but I would recommend 3.x now.