Hiding empty albums when browsing

james789

Joined: 2005-11-10
Posts: 96
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

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2007-02-01 15:48

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!

 
dalong

Joined: 2007-01-10
Posts: 11
Posted: Thu, 2007-02-01 16:00

I don't know about Drupal. But I looked at your gallery.
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 :-), for example move empty albums to such folder.

 
james789

Joined: 2005-11-10
Posts: 96
Posted: Thu, 2007-02-01 16:47

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

Quote:
{if ($child.descendentCount == 0)}
<!-- empty album omitted -->
{else}
......
{/if}

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!

 
james789

Joined: 2005-11-10
Posts: 96
Posted: Thu, 2007-02-01 17:04

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!

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2007-02-01 17:07

@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!

 
james789

Joined: 2005-11-10
Posts: 96
Posted: Thu, 2007-02-01 17:27

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.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2007-02-02 02:33
{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!

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2007-02-02 06:59

fwiw, useralbum module also has a setting where the album is created when first accessed, instead of when the user is created.

 
james789

Joined: 2005-11-10
Posts: 96
Posted: Fri, 2007-02-02 11:34

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 :-)

 
burt

Joined: 2007-06-20
Posts: 2
Posted: Wed, 2007-06-20 09:35

Many gallery website seemed to have this problem. An option should be added in the next version released.

----------------
burt

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2007-06-20 12:32

please file an official feature request.
see:
http://gallery.menalto.com/sfvote_help

--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage

 
Martiniano

Joined: 2007-05-14
Posts: 20
Posted: Tue, 2007-06-26 02:31

Burt,

Did you file an official feature request? Could someone post a link if anyone did? can't find it.

Thanks,
Martiniano

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Sun, 2007-09-16 11:48
321 wrote:
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

@321:

what's the point of copying another post from the same topic 1:1?

--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage

 
james789

Joined: 2005-11-10
Posts: 96
Posted: Sun, 2007-09-16 12:28

@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

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Sun, 2007-09-16 13:31

i haven't blocked user 321 for now, just marked his post as spam. thanks, and let's get back on topic.

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Sun, 2007-09-16 18:05

@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).

 
djpumpkin

Joined: 2006-12-06
Posts: 135
Posted: Sat, 2007-11-24 12:48

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.

 
valvoj

Joined: 2007-12-04
Posts: 4
Posted: Tue, 2007-12-04 04:12

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!

 
james789

Joined: 2005-11-10
Posts: 96
Posted: Tue, 2007-12-04 23:16

Find the loop that starts...

Quote:
{foreach from=$theme.children item=child}

and then add in the following conditional statement immediately after....

Quote:
{if $child.canContainChildren && $child.descendentCount == 0 && $child.ownerId != $user.id && !$user.isAdmin}
<!-- empty album omitted -->
{else}

followed by all the existing code, until you reach the end of the foreach loop, where you close the if statement with

Quote:
{/if}

immediately before the closing

Quote:
{/foreach}

Hope that makes sense. PM me an email address and I'll send you the whole file if required.

James

 
iamcanadian2222
iamcanadian2222's picture

Joined: 2007-01-17
Posts: 24
Posted: Tue, 2008-01-08 16:09

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!

 
iamcanadian2222
iamcanadian2222's picture

Joined: 2007-01-17
Posts: 24
Posted: Tue, 2008-01-08 16:49

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.

 
iamcanadian2222
iamcanadian2222's picture

Joined: 2007-01-17
Posts: 24
Posted: Tue, 2008-01-08 16:57

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).

 
ekakbe

Joined: 2008-01-08
Posts: 6
Posted: Wed, 2008-01-09 02:05

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

 
Talen

Joined: 2005-12-15
Posts: 9
Posted: Thu, 2008-05-15 12:47
 
Braineater
Braineater's picture

Joined: 2009-01-02
Posts: 1
Posted: Fri, 2009-01-02 04:54

Has anyone made any progress on this? This seems to be such a logical thing to have as an option... However I have been rummaging around in the code for hours and only getting more confused by the minute... I see it is not an easy thing to implement as a non-programmer.

 
redhawk07

Joined: 2009-05-14
Posts: 2
Posted: Thu, 2009-05-14 19:01

What about doing this in the permissions? Just disallow all users but admin and owner to view empty albums at all. Perhaps this could be configured with a parameter.

 
SKIER
SKIER's picture

Joined: 2009-06-19
Posts: 2
Posted: Tue, 2009-06-23 14:45

The issue could be solved in very simple way. Thanks iamcanadian2222 for idea.
No gallery code modifications needed at all! (useful for future upgrades)

Lets make the file, emty_mover.php for example. The code as follows:

<?php 
//// Put your data here from your config.php file
$hostname = "localhost";
$username = "your_user_name";
$password = "your_password";
$database = "your_database_name";
$tablePrefix = 'g2_';
$columnPrefix = 'g_';
//// end config data

$link = 'db_link';

$$link = mysql_connect($hostname, $username, $password);

if ($$link) mysql_select_db($database);

$query	= "UPDATE ((".$tablePrefix."Item it) 
left join ".$tablePrefix."ItemAttributesMap itam 
on itam.".$columnPrefix."itemId = it.".$columnPrefix."id) 
left join ".$tablePrefix."DescendentCountsMap des 
on it.".$columnPrefix."id = des.".$columnPrefix."itemId 
SET it.".$columnPrefix."originationTimestamp = 1000000000 
where  it.".$columnPrefix."canContainChildren = 1 
and des.".$columnPrefix."descendentCount = 0";

$result = mysql_query($query, $$link) 
or die(mysql_errno().' - '.mysql_error().'<br><br>'.$query);

print '<font color="red"><b>' .$result;

mysql_close($$link);
exit;
?>

Change the config section of file to your working settings.
Put the file to any place on your server.
Type in your browser: http://your_site/path_to_file/emty_mover.php
This will change the originating date of empty albums to 1000000000.
Gallery root album should use sorting by originating date to see the changes.
Together with above mentioned changes in album.tpl this will make your gallery main page much more user friendly :)

You will need to run this file from time to time, when new empty user albums will be added.

Or, even better, you can run it every night (or other time period) automatically by placing following 2 strings in /etc/crontab:


# Daily emty albums origin_timestamp changing at 02:01AM
1 2 * * * root php /usr/web/exact_path_to_file/emty_mover.php > /dev/null 2>&1

PS: don't forget to buckup your database before using this script in first time...

----------------------------------
www.skier.com.ua (Russian inside)

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Sat, 2009-06-27 02:46

I'm sorry, this is going to offend. That's just a really stupid solution. Changing the date stamps on the empty albums? WTF, I mean really WTF! What happens when someone adds photos to the albums? What happens if you want to sort your albums by something other than origination dates.

It's easier and more user friendly to simply edit album.tpl to look at album entities and see if the albums contain any entities. Valiant's mod, is easier, faster and fewer lines of code to implement. You also don't need to run it over and over to "fix" empty albums or "fix" albums that are no longer empty.

http://gallery.menalto.com/node/60098#comment-219517

Your hack is many times more complex than this needs to be. And the empty albums are still displayed....
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Sat, 2009-06-27 03:47

o.k. I over reacted to just reading your comment (it's been a long day). I've read the entire thread. I think if you implement both solutions if you don't want to have empty spaces, then it would work for both worlds. Empty albums are not displayed and those that want stuff organized nicely can have that.

Though, I would recommend trying to do your modifications using Gallery's api, not that it matters much since G2's api is likely to never change again.
http://codex.gallery2.org/Gallery2:How_To_Write_Scripts

____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
SKIER
SKIER's picture

Joined: 2009-06-19
Posts: 2
Posted: Tue, 2009-06-30 11:27
nivekiam wrote:
o.k. I over reacted to just reading your comment (it's been a long day)...

No problem :)

I just made the working solution and shared it for others. It works for embedded gallery. In my case:
- main site has about 10000 users, engine isn't trivial
- I've wrote the embedding script.
- for all registered users useralbum is created automatically on first gallery visit. It's useful for them to see link to own album, encourage them to put photos.
- but, so many empty albums on every page. album.tpl code modification is not enough because sometimes you will see no albums at all on first (main) page. (in case of many new visits and no new photos). We want to avoid such confusion of site visitor :)

Using my script and album.tpl code modification the problem is solved. It's simple utility. It is not a "final" and "graceful" solution because pagination is not fixed. But, pages with hidden emty albums will be located always on last pages. I think it's much better :)

================================
www.skier.com.ua (Russian inside)

 
redhawk07

Joined: 2009-05-14
Posts: 2
Posted: Tue, 2009-06-30 12:51

Hi all,

is it really a big problem to do this by the help of permissions as I wrote a few weeks ago?

redhawk07 wrote:
What about doing this in the permissions? Just disallow all users but admin and owner to view empty albums at all. Perhaps this could be developed with a configurable parameter.

This would also solve the problem with the page-counter.

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Tue, 2009-06-30 13:21
Quote:
is it really a big problem to do this by the help of permissions as I wrote a few weeks ago?

Yes.

First, G2 development is stopped. Gallery devs are working on G3. That's one reason.

Second, what about the album owners? If only site admin can view the albums, then that person has to add an item to the album before the album owner can do that unless they know the name of the album.

Third, permissions in G2 are inefficient and the more you have the slower Gallery will get:
http://codex.gallery2.org/Gallery2:ACL_Performance

The entire system needs to be re-worked, but won't since G3 is what's being worked on.

I suppose you could write a script to see if albums are empty and change the permissions on them
http://codex.gallery2.org/Gallery2:How_To_Write_Scripts

Of course, as I've already said, the more permissions you set, the slower Gallery will get. You may not notice it depending on the size of your Gallery or the number of items. But large installs and those with lots of traffic will notice.

____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
WebTrooper
WebTrooper's picture

Joined: 2004-08-19
Posts: 5
Posted: Fri, 2009-08-07 14:45

I'm not a coder, but I really need a solution to the pagination issue. The solution using if/then in the {foreach..} loop works great for hiding empty albums, and it seems the same solution could somehow be applied to the paginating code.

Where is the code for pagination? I'd like to try an see if I can figure it out.

Thanks =)

~ Web Trooper ~

"If at first you don't suced... d'oh!"