Hiding empty albums when browsing
|
james789
Joined: 2005-11-10
Posts: 86 |
Posted: Thu, 2007-02-01 15:09
|
|
I have User Albums module enabled, with Gallery embedded in Drupal. It's essential for my site that every new user who registers gets their own album, but it does mean that there are lots of empty albums sitting in my main user album. I was wondering, is there any way of 'hiding' the empty albums from casual browsers to that album so they only get to see albums that currently have images in them? It would help if an album owner saw their album even if it was empty, but if that's not easy then they can always get to their album through their Drupal profile page. I am making the assumption that, like the hidden album module, you would still be able to see the album if you went directly to that URL? Thanks, James |
|
| Login or register to post comments |

Posts: 31976
there's no option, but you can edit your album.tpl to not list subalbums with a descendent-count of 0.
--------------
Enter the Gallery 2 Theme Contest today!
Posts: 11
I don't know about Drupal. But I looked at your gallery.
, for example move empty albums to such folder.
I had same issue. So I created an extra folder for registered users. Then define all user folders/albums should be stored there. After this you can clean up your main page
Posts: 86
dalong - I can't see your site so not quite sure I follow. But just to say I will *only* have images in user albums, not in any more general albums, so it doesn't sound like that will really be applicable.
valiant - thanks, that does sound ideal. I have placed the condition
around everything inside the {foreach from=$theme.children item=child} loop and it basically works - see http://www.whatsthatpicture.com/?q=gallery
There is a problem though that it still paginates the album based on the full number of child items. Where is the code that does the pagination?
I can also now see that it is essential to code it so it doesn't hide any empty albums owned by the logged in user. I've got round this in the top-level user album by putting a hint in the description to follow the 'your album' link, but the real deal-breaker is if the user creates a sub-album in their user album, if they don't immediately add items then when they browse to their album it has disappeared!
Posts: 86
Aghhh, of course I didn't test if the child was an album, so it's also omitting all the images!!!!!
I have tried wrapping this with {if ($child.canContainChildren)} but it's not working. For now I've had to revert to the old code to make sure my pictures are still visible!
Posts: 31976
@showing empty albums to their owner and to admins:
you can use {if $child.ownerId == $user.id OR $user.isAdmin}
see:
http://codex.gallery2.org/index.php/Gallery2:Tpl_Reference
-----
if you want to fix the pagination, you'll have to code quite some more.
right now, album.tpl calls {g->block type="core.Pager"} which is in modules/templates/blocks/Pager.tpl
your theme loads all data, then you render it in the .tpl file.
you'd have do the filtering of empty albums before Pager handles the paging data.
--------------
Enter the Gallery 2 Theme Contest today!
Posts: 86
Putting pagination aside (for now!) I have the logic sorted, but not the code!
The logic is.....
If it's an album
And it's empty
And the person looking isn't the owner or an admin
Then don't display the table cell and contents.
Sorry my technical skills aren't up to this - I've tried all sorts but to no avail.
Posts: 31976
{if $child.canContainChildren && $child.descendentCount == 0 && $child.ownerId != $user.id && !$user.isAdmin} <!-- empty album omitted --> {else} <!-- show item --> ... {/if}or:
{if !$child.canContainChildren || $child.descendentCount || $child.ownerId == $user.id || $user.isAdmin} <!-- show item --> ... {/if}--------------
Enter the Gallery 2 Theme Contest today!
Posts: 8598
fwiw, useralbum module also has a setting where the album is created when first accessed, instead of when the user is created.
Posts: 86
valiant - works a treat. I've just put it in album.tpl for now, but will look at digging a bit deeper and setting it up so it also sorts the pagination issue.
mindless - good point. It may also solve a problem I have been having where a gallery album is created as soon as they sign-up in Drupal, but I'd like it to delay until after they have verified - I now have albums for people who have never completed their membership. I just have to check how it all works embedded in Drupal and make sure they can still find their album OK when they first login.
As always guys, huge thanks for all your help
Posts: 2
Many gallery website seemed to have this problem. An option should be added in the next version released.
----------------
burt
Posts: 31976
please file an official feature request.
see:
http://gallery.menalto.com/sfvote_help
--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage
Posts: 20
Burt,
Did you file an official feature request? Could someone post a link if anyone did? can't find it.
Thanks,
Martiniano
Posts: 31976
@321:
what's the point of copying another post from the same topic 1:1?
--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage
Posts: 86
@valiant:
321 appears to be a spammer - I had two notification emails in my inbox, the second was for the published post that you have commented on, the first included links to some less savoury sites and must have got caught by the spam trap. I'm having the same problem myself, where notifications are sent out by Drupal *before* the spam trapper has analysed them. I must post something over on the Drupal boards. Meanwhile, do you have admin rights to suspend 321's account?
James
Posts: 31976
i haven't blocked user 321 for now, just marked his post as spam. thanks, and let's get back on topic.
Posts: 4965
@james789: I edited 321's posts, which is why you saw the two notification emails. It was 321's first post so I chose not to block him right away (maybe a bad call).
Posts: 103
This is a great mod. I'm using it in Ice theme where I found it was childs.tpl not album.tpl that needed tweaking.
Posts: 2
Could you post a copy of your code in album.tpl that was edited? I tried both options and it when testing the page was blank. I believe I'm entering the code in the wrong spot. Thanks in advance!
Posts: 86
Find the loop that starts...
and then add in the following conditional statement immediately after....
followed by all the existing code, until you reach the end of the foreach loop, where you close the if statement with
immediately before the closing
Hope that makes sense. PM me an email address and I'll send you the whole file if required.
James
Posts: 24
I've been thinking about the best way to handle this for about a month now - the code fix above is a layout rendering fix and not a data (array) fix. It's great that someone has chimed in and come up with a temporary fix, but it still has issues - like the pagination issue. For example, let say you have 10 albums total in your gallery with your setting at 5 items per page. The output could get rendered with one or two pictures on the first page, none on the second page, five on the third page, and three on the last page. This would be really confusing to your users as to why some pages have just a few albums on them, some have none, and some have a lot. For an example, take a look at James 789's link he posted: http://www.whatsthatpicture.com/?q=gallery and click through a few pages.
What if we change the useralbum code so that the creation date of new useralbums (and subsequently changed date of them) is set to a time in the distant past. That way, when you are sorted by change date, those empty albums will at least show up at the END of all the albums you have listed and your users wont be AS confused while clicking through pages. In my case, I would leave the empty albums as visible and just put them at the end pages - some of you might choose to hide them and display some informative text or something. Now, I just need to look into the useralbum code some to see what I can do.
If a dev could chime in with some help, that would be greatly appreciated!
Posts: 24
My thinking is this will probably need to be done in the UserAlbumHelper.class in /community/gallery2/modules/useralbum/classes/
Sometime after the UserAlbum is created, the creation date and/or changed date needs to be reset to a "historic" date.
--note-- (to self)
The timestamp should be after 1/1/1970 (unix style) based on reading other threads
The updateModificationTimestamp() function updated an item (based on it's id) with the CURRENT time link to documentation
There is a class for a mainenance class that sets the Origination Timestamp: SetOriginationTimestampTask
The updateModificationTimestamp function is part of the GalleryCoreApi.class in /module/core/classes/ around line 1205.
This function class a function with the same name from the GalleryEntityHelper_medium.class in /module/core/classes/helpers/ around line 205.
I might be able to take the code from above and put it directly into the useralbum code. To follow the G2 current standard, the better idea might be to put it into the medium class, then reference it in the CoreApi, then reference it in the UserAlbum module. On the other hand, that seems like a lot more little code changes to keep up with when gallery versions change.
Better yet, if I can figure out how to call the setModificationTimestamp directly, I would be better off just doing that.
Looks like it's in modules/core/classes/GalleryEntity.class around line 659.
Posts: 24
Looking at other code in the UserAlbumHelper.class it looks like they are referencing other functions from the GalleryEntityHelper_medium.class like "$album->getId()".
Could I then just reference the setModificationTimestamp like "$album->setModificationTimestamp($myspecialtimestamp)" within the current locks of the useralbum?
If so, what format should the timestamp be in?
Answered my own question. Looking at the code more it calls time() so I put this into an echo statement and saw the format resembled that of Unix timestamp. So I tested it in a function that converts Unix timestamps to timestamps I understand and it was the current time (as I assumed).
Posts: 6
wouldn't it be easier if there was just an option to sort by number of items in an album as this will be useful in the future anyway, and just sort the root album and then do the hack
Posts: 9
I've submitted a feature request detailing this, http://sourceforge.net/tracker/index.php?func=detail&aid=1964555&group_id=7130&atid=357130