Random album cover

knorde

Joined: 2010-02-02
Posts: 64
Posted: Fri, 2012-05-25 11:14

Hi,

On this forum i found the code to use random album covers.
I have changed the code a little because i have coded automatic resolution detection.

Anyway the random album covers works fine only if in the subalbum are pictures.

If in the album only subalbums (and in the subalbums are pictures) the album pictures will not random.
You can test it on www.mydigitalworld.nl (as example the uitjes and vakantie folder).
How do I set it so that the thumbnail image for the album is a random image selected from all the images in all the sub-albums of that parent album?

The code i used (in album.html.php) is:

<?= $theme->thumb_top($child) ?>                                                                            
<? if ($child->is_album() && ($rnd = item::random_query()->where("parent_id", "=", $child->id)->find()) && $rnd->loaded()): ?>    
<a href="<?= $child->url() ?>">                                                                               
<? if ($rnd->has_thumb()): ?>      
  <? if ($rnd->thumb_height >= $rnd->thumb_width): ?>                                                                       
<?= $rnd->thumb_img(array("class" => "g-thumbnail")) ?>
  <? else: ?>
      <?= $rnd->thumb_img(array("class" => "g-thumbnail2")) ?>
      <? endif ?>
<? endif ?>                                                                                               
</a> 
      <? else: ?> 
    <a href="<?= $child->url() ?>">
      <? if ($child->has_thumb()): ?>
  <? if ($child->thumb_height >= $child->thumb_width): ?>
      <?= $child->thumb_img(array("class" => "g-thumbnail")) ?>
  <? else: ?>
      <?= $child->thumb_img(array("class" => "g-thumbnail2")) ?>
      <? endif ?>
      <? endif ?>
<? endif ?>
    </a>

On this moment only the subalbums will have random album covers.
Is there an option to code so that the album with only subalbums (and pictures in the subalbums) will random the album cover?

Greets Kees.

 
knorde

Joined: 2010-02-02
Posts: 64
Posted: Sat, 2012-05-26 11:25

No one?

 
shug17

Joined: 2009-01-10
Posts: 76
Posted: Sat, 2012-05-26 15:24

Nice work - looking for something like this myself.

how often does the random image change?

 
knorde

Joined: 2010-02-02
Posts: 64
Posted: Mon, 2012-05-28 13:04
shug17 wrote:
Nice work - looking for something like this myself.

how often does the random image change?

Every time on page reloading.

 
knorde

Joined: 2010-02-02
Posts: 64
Posted: Mon, 2012-05-28 13:05

Any one any idea?

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Mon, 2012-05-28 19:30

So you are looking to get a random item from all items in a album including the children and grandchildren of a particular album?
I'm not good with SQL queries but should be able to check for all items that have left and right pointers of related values.

->where("left_ptr", ">", $this->left_ptr)
->where("right_ptr", "<", $this->right_ptr)

I'm sure there is some other module that gathers similar info.

I'll see what I can find later tonight.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
knorde

Joined: 2010-02-02
Posts: 64
Posted: Mon, 2012-05-28 21:33
floridave wrote:
So you are looking to get a random item from all items in a album including the children and grandchildren of a particular album?
I'm not good with SQL queries but should be able to check for all items that have left and right pointers of related values.

->where("left_ptr", ">", $this->left_ptr)
->where("right_ptr", "<", $this->right_ptr)

I'm sure there is some other module that gathers similar info.

I'll see what I can find later tonight.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

Thanks for the reply :)

When i use:

if ($child->is_album() && ($rnd = item::random_query()->where("left_ptr", ">", $child->left_ptr)->find()) && $rnd->loaded()): 

or

if ($child->is_album() && ($rnd = item::random_query()->where("right_ptr", "<", $child->right_ptr)->find()) && $rnd->loaded()): 

it randomize the whole album (not only the subalbums in the album (as example) vakantie).

I mean that the thumbnail image for the album is a random image selected from all the images in the sub-albums of that parent album :)

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Tue, 2012-05-29 00:26

You will need to look at the DB for the left and right pointers perhaps you need to be => or =< and not just > or <.
or you may need to search for the parent left and right pointers of the parent and not the child.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team