Piwigo / piwigo-openstreetmap

OpenStreetMap integration for Piwigo
http://piwigo.org/ext/extension_view.php?eid=701
GNU General Public License v3.0
35 stars 35 forks source link

Support of subcategories #29

Closed GnunuX closed 9 years ago

GnunuX commented 10 years ago

If I select a category with subcategories, we has 0 item in osmmap.php. But I think that we should view photos inside subcategories in osmmap.php in this case.

GnunuX commented 10 years ago
--- osmmap.php.ori  2014-01-17 23:57:27.000000000 +0100
+++ osmmap.php  2014-08-14 14:43:57.722056703 +0200
@@ -69,23 +69,25 @@

 // Limit search by category, by tag, by smartalbum
 $LIMIT_SEARCH="";
+$INNER_JOIN="";
 if (isset($page['section']))
 {
    if ($page['section']='categories' and isset($page['category']) and isset($page['category']['id']) )
    {
-       $LIMIT_SEARCH = "`storage_category_id` = ".$page['category']['id']." AND ";
+       $LIMIT_SEARCH = "ic.storage_category_id = ".$page['category']['id']." AND ";
    }
    if ($page['section']='tags' and isset($page['tags']) and isset($page['tags'][0]['id']) )
    {
        $items = get_image_ids_for_tags( array($page['tags'][0]['id']) );
        if ( !empty($items) )
        {
-           $LIMIT_SEARCH = "image_id IN (".implode(',', $items).") AND ";
+           $LIMIT_SEARCH = "ic.image_id IN (".implode(',', $items).") AND ";
        }
    }
    if ($page['section']='tags' and isset($page['category']) and isset($page['category']['id']) )
    {
-       $LIMIT_SEARCH = "category_id=".$page['category']['id']." AND ";
+       $LIMIT_SEARCH = "FIND_IN_SET(".$page['category']['id'].", c.uppercats) AND ";
+       $INNER_JOIN = "INNER JOIN piwigo2_categories AS c ON ic.category_id = c.id";
    }
 }

@@ -93,6 +95,7 @@
 if (isset($_GET['min_lat']) and isset($_GET['max_lat']) and isset($_GET['min_lng']) and isset($_GET['max_lng']))
 {
    $LIMIT_SEARCH="";
+   $INNER_JOIN="";

    /* Delete all previous album */
    $query="SELECT `id` FROM ".CATEGORIES_TABLE." WHERE `name` = 'Locations' AND `comment` LIKE '%OSM plugin%';";
@@ -138,9 +141,9 @@
 $forbidden = get_sql_condition_FandF(
    array
    (
-       'forbidden_categories' => 'category_id',
-       'visible_categories' => 'category_id',
-       'visible_images' => 'id'
+       'forbidden_categories' => 'i.category_id',
+       'visible_categories' => 'i.category_id',
+       'visible_images' => 'i.id'
    ),
    "\n AND"
 );
@@ -151,27 +154,27 @@
 // SUBSTRING_INDEX(TRIM(LEADING '.' FROM `path`), '.', 1) full path without filename extension
 // SUBSTRING_INDEX(TRIM(LEADING '.' FROM `path`), '.', -1) full path with only filename extension

-$query="SELECT `latitude`, `longitude`, `name`, 
-IF(`representative_ext` IS NULL, 
-   CONCAT(SUBSTRING_INDEX(TRIM(LEADING '.' FROM `path`), '.', 1 ), '-sq.', SUBSTRING_INDEX(TRIM(LEADING '.' FROM `path`), '.', -1 )), 
+$query="SELECT i.latitude, i.longitude, i.name, 
+IF(i.representative_ext IS NULL, 
+   CONCAT(SUBSTRING_INDEX(TRIM(LEADING '.' FROM i.path), '.', 1 ), '-sq.', SUBSTRING_INDEX(TRIM(LEADING '.' FROM i.path), '.', -1 )), 
    TRIM(LEADING '.' FROM
-       REPLACE(`path`, `file`,
+       REPLACE(i.path, i.file,
                CONCAT('pwg_representative/',
                    CONCAT(
-                       TRIM(TRAILING '.' FROM SUBSTRING_INDEX(`file`, '.', 1 )),
-                       CONCAT('-sq.', `representative_ext`)
+                       TRIM(TRAILING '.' FROM SUBSTRING_INDEX(i.file, '.', 1 )),
+                       CONCAT('-sq.', i.representative_ext)
                    )
                )
            )
        )
 ) AS `pathurl`, 
-TRIM(TRAILING '/' FROM CONCAT( `id`, '/category/', IFNULL(`storage_category_id`, '') ) ) as `imgurl`, 
-IFNULL(`comment`, '') AS `comment`,
-IFNULL(`author`, '') AS `author`,
-`width`
+TRIM(TRAILING '/' FROM CONCAT( i.id, '/category/', IFNULL(i.storage_category_id, '') ) ) as `imgurl`, 
+IFNULL(i.comment, '') AS `comment`,
+IFNULL(i.author, '') AS `author`,
+i.width
    FROM ".IMAGES_TABLE." AS i
-       INNER JOIN ".IMAGE_CATEGORY_TABLE." AS ic ON id = ic.image_id
-       WHERE ".$LIMIT_SEARCH." `latitude` IS NOT NULL AND `longitude` IS NOT NULL ".$forbidden." group by `name`;";
+       INNER JOIN (".IMAGE_CATEGORY_TABLE." AS ic ".$INNER_JOIN.") ON i.id = ic.image_id
+       WHERE ".$LIMIT_SEARCH." i.latitude IS NOT NULL AND i.longitude IS NOT NULL ".$forbidden." group by `name`;";
 //echo $query;
 $php_data = array_from_query($query);
 //print_r($php_data);
xbgmsharp commented 10 years ago

Thanks for the feedback and the patch. Why do you use version1 layout? https://github.com/xbgmsharp/piwigo-openstreetmap/wiki#left-menu-configuration I believe the same will apply to osmap2.php. Could you do a pull request for both? Then I merge it and not copy your change over. There might be an issue on your patch, you should not specify the table as the prefix is dynamic.

$INNER_JOIN = "INNER JOIN piwigo2_categories AS c ON ic.category_id = c.id";

Should be

$INNER_JOIN = "INNER JOIN ".CATEGORIES_TABLE." AS c ON ic.category_id = c.id";
GnunuX commented 10 years ago

I want insert map directly in category (not open a full page) so I'm starting with osmmap.php code.

In fact, I think you should factoring code (osmmap.php, osmmap2.php and picture.inc.php) in a library. I trying to do that and I'll do some pull request.

I've a question with this code. I'm not very familar with php (and piwigo plugin) but I think there is a mistake in this line:

        if ($page['section']='categories' and isset($page['category']) and isset($page['category']['id']) )

I think this should be:

        if ($page['section'] === 'categories' and isset($page['category']) and isset($page['category']['id']) )

Is it right?

xbgmsharp commented 10 years ago

osmmap.php, osmmap2.php, osmmap3.php are different version of world map layout. I did not want them to share code between them as the feature list increase overtime. However you are right between osmmap*.php and picture.php they could be more code share.

It would cool to be able to display a map on category page. I will be more than happy to include your change.

Regarding the code bug, you seen to be right. The same apply for tags and categories. If you can fix and test and report with a pull request, it would be great.

Thanks.

xbgmsharp commented 9 years ago

Thanks for your input and your code. Closing as merge was done via commit 7e9763b11ea6a1374a7a1a857aee9236509e5e63 and b593596fd3ae9ef25c806ede640a9f1e1258a197