Currently, the image that represents a gallery is always the newest one, no matter which Image display sort order is set. This is correct for Create date, newest first, but not for the other sort orders.
The attached patch uses the same sort order for determining the "latest" image as it does for ordering the images within the gallery, so the first (top left) image will always represent the gallery.
This is a necessary first step, but one issue still remains: if we have a gallery of galleries, then that same algorithm is used to pick the image that represents the container gallery. This is wrong. The container gallery should display the image of the first contained gallery that has an image, and the order of the contained galleries is determined by their weights and titles.
I'm afraid this cannot be determined through a clever query, but it will require a recursive search in the gallery tree structure.
Also, I'm not sure how to treat galleries that have sub-galleries as well as images. Should they be represented by their first image or by the image of their first sub-gallery? Or does the sort order decide between those two?
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | image-HEAD.gallery-front-image.patch | 4.45 KB | sun |
| image_gallery.patch | 4.19 KB | salvis |
Comments
Comment #1
drewish commentedI'm not really so into the way those queries are built. I'd almost rather duplicate queries than have the $join in there. I much prefer way the old code builds the queries in the switch().
Comment #2
salvisI'll rewrite this if you really want to have it that way, but do you realize that the same pieces go into two queries, i.e. there would be two bulky and almost identical switch statements?
Comment #3
drewish commentedi don't see why both queries can't be build in one case statement...
Comment #4
salvisNo, this doesn't work well.
The query that selects the "latest" picture is inside a loop. It needs to be re-assembled for every loop iteration (
IN (". implode(',', $descendant_tids) .")). So, that switch would need to go inside the loop.However, the loop body is not guaranteed to be executed, so the other switch needs to go outside the loop (and you wouldn't want to assemble the second query umpteen times for nothing, would you?).
Comment #5
salvis@drewish: Please review this again in the light of my comment above.
Comment #6
sunComment #7
salvisYes, this works fine for the first step. Thanks!
Comment #8
joachim commented> if we have a gallery of galleries, then that same algorithm is used to pick the image that represents the container gallery. This is wrong. The container gallery should display the image of the first contained gallery that has an image, and the order of the contained galleries is determined by their weights and titles.
I'm not sure I follow.
If the gallery we are trying to pick a front image for is called A, and has child galleries B, C, D, then what do we want to be the front?
Is it:
- the image that satisfies the sort condition out of the pool of all images in A, B, C, D,
or
- the image that satisfies the sort condition from A, and if no images in A, out of the first gallery that has images?
The first would be simpler to do in a query.
Add to the mix the fact that I would like to implement all this in views... the first rule will definitely be easier, as it's just a question of feeding views a list of child term IDs to filter on!
Comment #9
sunDoes this work recursively? I don't know. Should this work recursively? I'm inclined to say no. When I view gallery X, then I should see the front image of gallery X (respecting the sort order). If there are no images in gallery X, then I won't see a front image. At least, that's what I would expect?
I see that my comment for that patch ended up in nirvana. IIRC, I just agreed that a dynamically enhanced query certainly is a bit harder to understand, but compared to the alternative of rebuilding the query all over again and ensuring all queries actually and really do the same, it is easier to maintain.
Comment #10
salvisNo! Throwing all directly and indirectly contained images into one bucket and picking, say, the most recent one, will result in seemingly random behavior — it could be the top image of any of A, B, C, or D that would get selected.
Yes, that's what I meant. "First gallery" is determined by weight and alphabetical sort order (if the weight is the same), not by age or any of the other criteria used to sort the images.
And yes, it should definitely work recursively. If gallery X has no images, but it contains galleries Y and Z then it would be nice to see Y's front image as the front image of X (or Z's if Y has no images). If a gallery says "There are 123 images in this gallery" it ought to be able to display a front image, no?
My use case is a multi-level gallery of events. It contains a gallery for 2007, one for 2008, and one for 2009. Those in turn contain one gallery per event. Something like
Events
-- 2009
-- -- Spring event (images)
-- 2008
-- -- Fall event (images)
-- -- Summer event (images)
-- -- Spring event (images)
-- 2007
-- -- Fall event (images)
Members
Club House
I'd like to see the Fall 2008 front image as the front image of the 2008 gallery. We add events at the top of their year (using weights), so the 2009 front image should be the front image of the latest event throughout 2009, and the front image of Events should always be the front image of the latest event overall, so that it changes after every event. Having no front image for Events and 2009/2008/2007 would be a pity...
In reality there are not three events per year but about 80. Having to manually duplicate front images into 2009 and Events would be quite a chore, and requiring a lone image just to have a front image would mess up the clean look of the gallery of galleries pages.
(Because we have about 80 events, we actually have to introduce another intermediary level, because the weight is limited to the -10..10 range, which is not enough to enforce the correct order.)
BTW, sun, there was no ASC on the original f.filepath case.
Comment #11
joachim commented> Throwing all directly and indirectly contained images into one bucket and picking, say, the most recent one, will result in seemingly random behavior — it could be the top image of any of A, B, C, or D that would get selected.
Sure. But when I say 'gimme the most recent thing in this folder', I expect that to include contents of subfolders too. That's not just limited to technically-minded people -- most people would agree that the most recent piece in the museum wing is the most recent piece in all galleries in that wing ;)
Realistically though, I don't think we're going to implement that kind of recursion. Though take a look at the gallery handlers I'm working on here: http://drupal.org/node/405456
I plan to create two possible relationships to get the 'front image' of a gallery -- most recent, and gallery sort order. A recursive sort order probably won't work on a relationship, but you could use my original field approach and run whatever queries you want in the handler :)
Comment #12
salvisYes, that works reasonably well if your sort order happens to be most-recent-first. However, you're offering three other sort orders, and it won't work so well with those others. For example, I use the oldest-first order. The people who fill my galleries can't manage to load pictures in reverse order. They load the first picture first, then the second, etc. So we want oldest-first in each gallery, but the most recent gallery at the top and on the containing gallery.
This means in my example in #10, that the Events gallery will keep displaying the top image of the Fall 2007 gallery as its front image forever! You can't seriously claim that this is how it should work...
Comment #13
Hetta commented#12: What happens if you make the front pic of the most recent gallery sticky (and unstick any others)?
Comment #14
salvisAh, yes, sticky brings the desired picture into the front position and onto the outer gallery pages. However, it has two disadvantages:
1. it puts the picture into a box inside its gallery, messing up the table layout of the gallery (is this a bug or a feature?), and
2. it requires a manual intervention to achieve what should be normal behavior.
Comment #15
joachim commentedI'm making good progress with implementing galleries as views.
The cover image for a gallery is going to be provided with a relationship from term (the gallery) to node (the cover image). I'll be posting a patch soon that provides latest and oldest image from the gallery (without including child galleries at present.)
The beauty of doing this with views is that you can implement your own relationship with your own subquery or PHP code, as complex as you like, as long as it returns a nid.
See http://drupal.org/node/405456.
Comment #16
sunI agree with salvis here: sticky should be used to manually _force_ a certain image to be the front image only. Bear in mind that regular users do not have access to the sticky option.
Comment #17
salvis@joachim: I'm a bit confused about "galleries as views". Is that intended to officially replace the current image_gallery.module? I've had a very very bad experience with galleries as views under D5. Obviously, Views2 is completely different, and it's certainly an interesting project, but we're talking about fixing image_gallery.module here (unless it's already doomed to be replaced). Just as a side note: I'm using Thickbox, and there are a number of similar modules in use. It works very well with image_gallery.module, and "galleries as views" cannot fly until it's supported by those modules.
@sun: What do you mean with CNR? Your patch is fine as far as it goes and it's definitely an improvement. Are you looking for more reviews (which will not extend the functionality), or did you mean to set it CNW to work on the recursive front image?
Yes, sticky is only available with administer nodes, which I'm not willing to give to the people who maintain the galleries. That'd be objection #3, a killer...
Comment #18
sunI have
- 1 response for needs work
- 1 response for RTBC
- countless follow-ups, which are related to the functionality, but do not give a clue about the patch
Comment #19
joachim commented@salvis: whether galleries as views works alongside the current hardcode, or replaces it, is a matter for discussion, for which I need to open an issue.
My opinion is that it should replace the hardcode. This module as a lot of users, all of whom want different sort orders and display options for galleries, and the more options we add the more bloaty the module becomes. Views is a much better way to allow everyone all the customization they want.
Getting *box modules to work is simply a matter of giving them the right classes to work on, no? That's just theming the view.
What problems did you have with gallery views on D5? Have you filed issue reports?
Comment #20
salvisNo idea...
Yes, of course. There are a bunch of issues about that in the queue and I don't think any have been solved. But I have moved on to D6 and lost interest in D5.
Comment #21
joachim commentedI think the problem you had was this: http://drupal.org/node/207371
It's now resolved.
Comment #22
joachim commentedI want to move galleries over to being made with views. This will give much more control over how they are generated and themed.
See http://drupal.org/node/405456 for a patch. Help testing this would be welcome if you are able.
Comment #23
salvisNo, let's not drop image_gallery.module — people use it. As long as #405456: Galleries made with views isn't completed and hasn't been shown to do everything that image_gallery.module does and more, we must not drop image_gallery.module.
Also, quoting http://drupal.org/patch/review:
I've just verified that the patch in #6 still works. It represents a definitive improvement, even if we may wish to pursue this further and discuss recursion in a followup issue. Please commit the patch in #6.
Comment #24
joachim commented#405456: Galleries made with views needs testing and can do everything current code galleries can do -- even cover image from gallery sort.
Comment #25
salvisI'm aware that it needs testing, but interest seems limited at best. You're not trying to force people into testing/adapting a new unknown module by killing a well-known one that has been working fine for years, are you?
Views is not exactly a slim module. I run gallery sites that don't have Views installed, but I do have image_gallery_access and thickbox, and they work just fine with image_gallery. If you don't want to support image_gallery any longer, then let's move it out of image.
Comment #26
sunYes. Your proposal is 100% in line with the roadmap of Image module. So you volunteered to create and maintain that new image_gallery_legacy module? :)
The split/branch point for this will be 6.x-3.x (there won't be a 6.x-2.x).
Before creating the new project/module, let's get a final discussion and rounded up plan in #513096: The Future of Image in Drupal 7 going, please.
Comment #27
joachim commentedThere is limited interest in most things to do with this module: #486546: Image 1.0
We appear to be a module that has a lot of users but hardly any testers.
Image is going to get a complete revamp for 7, so what we do with galleries at that point is open for debate.
As for 6, it might be quicker to simply release a new module for views support, since the patch testing is going nowhere.
The main reason for adding views support is that everyone seems to want more options for image galleries -- this issue is a case in point -- and the more options there are, the harder it will be to maintain.
Using views gives us a sound base to work on and a lot of the work is already done for us.
Comment #28
sunThanks for reporting, reviewing, and testing! Committed to 6.x-1.x.
A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.