Announcement

  •  » Extensions
  •  » How to get a random picture for category and sub category

#1 2005-07-10 12:43:02

vbrille
Member
2005-07-10
9

How to get a random picture for category and sub category

By default phpwebgallery set one representative picture per category, but this representative picture is always the same...

This small modification permits to change the representative picture of a category each time a sub category is browsed.

Tested with phpwebgallery 1.4.1.

Code:

File to modify: ./include/category_subcats.inc.php

SEARCH and REPLACE:
SELECT id, name, date_last

WITH:
SELECT id, nb_images, name, date_last


THEN SEARCH AND ADD AFTER:
while ($row = mysql_fetch_array($result))
{

THIS:
  // Randomize the representative picture for categories with nb of images > 0
  if ($row['nb_images'] > 0) 
  {
    //Get the new reprentative picture of the category
    $get_new_representative_pic_id = '
    SELECT id
    FROM '.IMAGES_TABLE.'
    WHERE storage_category_id = '.$row['id'].'
    ORDER BY RAND()
    LIMIT 0,1';
    $new_representative_pic_id = pwg_query($get_new_representative_pic_id);
    $data_row = mysql_fetch_array($new_representative_pic_id);

    //Save the new representative picture category into the database
    $update = '
    UPDATE '.CATEGORIES_TABLE.' set representative_picture_id = '.$data_row['id'].' 
    WHERE id = '.$row['id'];      
    $res_update= pwg_query($update);
  }
  // End of modification for randomizing the representative pictuve of the categorie

Perhaps this modification can be improved, but it works fine wor me.
Any comments are welcome ;)
Vincent

Offline

 

#2 2005-07-10 23:00:44

Yann Dìnendal
Member
Bourgogne - France
2005-07-03
12

Re: How to get a random picture for category and sub category

Thank you very much ! The mod is very easy to put and seems to be working very well !

Merci beaucoup ! Mod très facile à installer et qui a l'air de marcher super bien !


Les Univers Fantastiques : News Harry Potter, Forum sur Harry Potter, le Seigneur des Anneaux, Star Wars, À la Croisée des Mondes, etc... et GALERIE

Offline

 

#3 2005-07-23 13:10:28

vbrille
Member
2005-07-10
9

Re: How to get a random picture for category and sub category

I have made a small improvment, so the representative picture of a category will be updated each time a sub-category AND the main category is browsed.

Tested with phpwebgallery 1.4.1.

1°) First: remove the first modification posted here, if you don't know how, just use the defaut (unmodified) ./include/category_subcats.inc.php file

2°) Then: modify the ./include/category_subcats.inc.php file as follow:

Code:

SEARCH AND ADD AFTER:
if (mysql_num_rows($result) > 0)
{
  $template->assign_block_vars('thumbnails', array());
  // first line
  $template->assign_block_vars('thumbnails.line', array());
  // current row displayed
  $row_number = 0;

THIS CODE:
  // VBR Randomize the representative picture for categories with nb of images > 0
  $get_all_cat = '
  SELECT id, nb_images
  FROM '.CATEGORIES_TABLE.'
  WHERE id_uppercat ';  
  $get_all_cat_res = pwg_query($get_all_cat);

  while ($get_all_cat_res_row = mysql_fetch_array($get_all_cat_res))
  {
    if ($get_all_cat_res_row['nb_images'] > 0) 
    {
      //Get the new reprentative picture of the category
      $get_new_representative_pic_id = '
      SELECT id
      FROM '.IMAGES_TABLE.'
      WHERE storage_category_id = '.$get_all_cat_res_row['id'].'
      ORDER BY RAND()
      LIMIT 0,1';
      $new_representative_pic_id = pwg_query($get_new_representative_pic_id);
      $data_row = mysql_fetch_array($new_representative_pic_id);

      //Save the new representative picture category into the database
      $update = '
      UPDATE '.CATEGORIES_TABLE.' set representative_picture_id = '.$data_row['id'].' 
      WHERE id = '.$get_all_cat_res_row['id'];      
      $res_update= pwg_query($update);
    }
  }
  // VBR End of modification for randomizing the representative picture of the categorie

Now you will always have a random picture displayed for all categories/sub-categories...

Note: This modification can be a problem if your website has a lot of categories/sub-categories AND a lot of visits, due to updates made on the database

Enjoy it :)

Any comments are welcomed ;)

Offline

 

#4 2005-07-23 16:57:29

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13791

Re: How to get a random picture for category and sub category

vbrille wrote:

Any comments are welcomed ;)

Why not make a real MOD ?

Offline

 

#5 2005-07-23 18:56:33

VDigital
Former Piwigo Team
Paris (FR)
2005-05-04
17680

Re: How to get a random picture for category and sub category

z0rglub wrote:

vbrille wrote:

Any comments are welcomed ;)

Why not make a real MOD ?

Yeh! A real MOD.


Comments:
Just an idea, what do you think about doing a test before the update to reduce them as much as possible (to be faster and reduce concurent update access on the db).
I don't know exactly how but saving a new representative picture should be done only time to time, do you agree?

"Guest users" and "odd seconds"
or
"Admin" and "User's name containg..."
or
"special users set with a specific option"
or
any idea


Piwigo.com: Start and run your own photo gallery. Signup and get 30 days to try for free, no commitment.
8-)

Offline

 

#6 2005-07-23 20:30:07

vbrille
Member
2005-07-10
9

Re: How to get a random picture for category and sub category

Ok ok guys, I will make a real MOD for the next release ;)
I think it could be possible to calculate the category random representative picture on the fly, each time someone is browsing a category or a sub category. By the way, no more updates onto the database ;)
I will try to do it, when I will have some time to spend on it :p

Thank you for your remarks.

Offline

 

#7 2005-07-24 20:28:54

vbrille
Member
2005-07-10
9

Re: How to get a random picture for category and sub category

Here is the version 1.0.2 of this phpwebgallery modification.

##############################################################
## Author Notes:
##
##    ### English ###
##
##    This MOD permits to get on the fly a random representative picture for a category or a sub category each time
##    a user is browsing the main category or a sub category.
##
##    If you haven't modifiy the file category_subcats.inc.php, you can just replace the
##    file ./include/category_subcats.inc.php of your phpwebgallery website by the one included
##    in the './Modified category_subcats.inc.php/' directory of this package.   
##
##    You can also find the original (unmodified) file in the directory './Original category_subcats.inc.php file/'.
##
##############################################################
## MOD History:
##
##   2005-07-24 - version 1.0.2
##    - Fix to get the representative picture on the fly, no more updates onto the database :)
##
##   2005-07-23 - Version 1.0.1
##      - Fix the mod to get a random representative picture also while browsing a main category
##
##   2005-07-10 - Version 1.0.0
##      - Initial Release
##
##############################################################


You can get it there: http://vincent.brille.free.fr/pwg_MOD_r … icture.rar

As usual, any comments are welcomed :)

Offline

 

#8 2005-07-31 02:55:43

Yann Dìnendal
Member
Bourgogne - France
2005-07-03
12

Re: How to get a random picture for category and sub category

:(
le mod marche plus ! quand on va dans certaines catégories on reçoit un message comme :

SELECT path, tn_ext FROM phpwebgallery_categories AS c INNER JOIN phpwebgallery_images AS i ON i.id = ORDER BY RAND() LIMIT 0,1 ; [mysql error 1064] You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY RAND() LIMIT 0,1' at line 4

ou

SELECT path, tn_ext
  FROM phpwebgallery_categories AS c INNER JOIN phpwebgallery_images AS i
    ON i.id =
    AND c.id NOT IN (1,215,213,21,22,25,235,234,214,159,216)
  ORDER BY RAND()
  LIMIT 0,1
;
[mysql error 1064] You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND c.id NOT IN (1,215,213,21,22,25,235,234,214,159,216)
  ORDE


je remis le fichier category_subcats.inc.php original donc ya plus le problème... Je crois que c'est dans les catégories où il y a des sous-catégories virtuelles... Mais je sais pas trop c'est bizarre !


Les Univers Fantastiques : News Harry Potter, Forum sur Harry Potter, le Seigneur des Anneaux, Star Wars, À la Croisée des Mondes, etc... et GALERIE

Offline

 

#9 2005-07-31 09:49:40

vbrille
Member
2005-07-10
9

Re: How to get a random picture for category and sub category

Hello Yann,

I've found something wrong, if a category doesn't have any image... (this could occur if you create a new directory without synchronizing images)
I've made the correction and tested also with virtual category, it seems to be ok now...

You can get the last version 1.0.3 of this MOD here: http://vincent.brille.free.fr/pwg_MOD_r … icture.rar

Can you tell me if it's ok for you now ?

Thank you :)

Offline

 

#10 2005-08-08 03:45:30

Yann Dìnendal
Member
Bourgogne - France
2005-07-03
12

Re: How to get a random picture for category and sub category

thank you very much ! This work very well : http://yanndinendal.free.fr/phpwebgallery


Les Univers Fantastiques : News Harry Potter, Forum sur Harry Potter, le Seigneur des Anneaux, Star Wars, À la Croisée des Mondes, etc... et GALERIE

Offline

 

#11 2005-08-08 22:46:09

vbrille
Member
2005-07-10
9

Re: How to get a random picture for category and sub category

Gooood!
and nice gallery ;)

Thank you,
Vincent

Offline

 

#12 2005-08-24 23:27:59

photorallye.com
Guest

Re: How to get a random picture for category and sub category

Pour moi ca ne marche pas vraiment à moins que j'ai fait une mauvaise manip, mais cela va me piocher des images un peu n'importe ou pour les mettre en représentation d'une catégorie.
C'est à dire que l'image representative ne vient pas forcément de la categorie concernée!
D'autres ont ils eu ce probleme?

 

#13 2005-08-29 15:19:41

vbrille
Member
2005-07-10
9

Re: How to get a random picture for category and sub category

Salut,

Si tu as fais un mauvaise manip et si tu n'as jamais modifié le fichier category_subcats.inc.php le plus simple est de copier directement le fichier modifié contenu dans le repertoire './Modified category_subcats.inc.php/'.

La modification va chercher une image au pif contenu dans le repertoire (dans la categorie) en question.

Tiens moi au courant...
A+
Vincent

Offline

 

#14 2006-06-09 07:48:13

VDigital
Former Piwigo Team
Paris (FR)
2005-05-04
17680

Re: How to get a random picture for category and sub category

??? What are you speaking about? Here it's an English forum.


Piwigo.com: Start and run your own photo gallery. Signup and get 30 days to try for free, no commitment.
8-)

Offline

 
  •  » Extensions
  •  » How to get a random picture for category and sub category

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact