[Tags] AND / OR dynamic albums implemented (sorta)!

mikeage
mikeage's picture

Joined: 2005-01-23
Posts: 138
Posted: Tue, 2008-08-26 14:55

I hacked together a slightly modified version of the Tags module (based on 1.3.6) that allows viewing of a dynamic album consisting of either (tag1 OR tag2 OR tag3) or (tag1 AND tag2 AND tag3). I'm not claiming this is ready for release, but hopefully someone with better SQL skills can take this and use it to help implement full support (such as tag1 && (tag2 || tag3) ).

Replace the file /path/to/gallery/modules/tags/VirtualAlbum.inc with the attached file. To view a combined album, browse to /gallery/tag/tag1,tag2,tag3 for OR, or /gallery/tag/tag1;tag2;tag3 for AND. I picked these two characters since, by definition, they cannot appear in a tag (of course, if you're not using URL rewriting, you're on your own here).

Please take, mangle, spindle, improve, and re-release!

AttachmentSize
VirtualAlbum.zip2.39 KB
 
mikeage
mikeage's picture

Joined: 2005-01-23
Posts: 138
Posted: Tue, 2008-08-26 14:56

If you want to try this, feel free to browse my gallery at http://mikeage.net/content/gallery/

 
mikeage
mikeage's picture

Joined: 2005-01-23
Posts: 138
Posted: Wed, 2008-08-27 03:53

[duplicate, due to network issues. Deleted]

 
mikeage
mikeage's picture

Joined: 2005-01-23
Posts: 138
Posted: Wed, 2008-08-27 03:53

Ok, I may have spoken too soon. There are two major bugs in the code above
1. Single tags don't work properly! Updated version is attached.
2. Clicking on a photo in an album which was generated from a tag other than the first doesn't work (i.e., any AND album, or an OR where the matching tag was != the first tag); it gives the following error:

Error Detail  -
Error (ERROR_MISSING_OBJECT, ERROR_PERMISSION_DENIED) : Missing object for 0

    * in modules/core/classes/GalleryStorage/GalleryStorageExtras.class at line 2074 (GalleryCoreApi::error)
    * in modules/core/classes/GalleryStorage/GalleryStorageExtras.class at line 97 (GalleryStorageExtras::_identifyEntities)
    * in modules/core/classes/GalleryStorage.class at line 298 (GalleryStorageExtras::loadEntities)
    * in modules/core/classes/helpers/GalleryEntityHelper_simple.class at line 71 (GalleryStorage::loadEntities)
    * in modules/core/classes/GalleryCoreApi.class at line 2259 (GalleryEntityHelper_simple::loadEntitiesById)
    * in modules/core/classes/GalleryTheme.class at line 1285 (GalleryCoreApi::loadEntitiesById)
    * in themes/mikeage/theme.inc at line 176 (GalleryTheme::loadCommonTemplateData)
    * in modules/core/classes/GalleryTheme.class at line 932 (MikeageTheme::showPhotoPage)
    * in modules/core/classes/GalleryView.class at line 308 (GalleryTheme::loadTemplate)
    * in main.php at line 445 (GalleryView::doLoadTemplate)
    * in main.php at line 94
    * in main.php at line 83
    * in main.php at line 3

This appears to be due to code in GalleryTheme.class, which reads:

                if (isset($dataItemIndex)) {
                    if ($dataItemIndex > 0) {
                        $navigator['first'] = $peerDataItemIds[0];
                        $navigator['back'] = $peerDataItemIds[$dataItemIndex - 1];
                    }
                    $lastIndex = count($peerDataItemIds) - 1;
                    if ($dataItemIndex < $lastIndex) {
                        $navigator['next'] = $peerDataItemIds[$dataItemIndex + 1];
                        $navigator['last'] = $peerDataItemIds[$lastIndex];
                    }
                    foreach ($navigator as $id) {
                        $ids[$id] = true;
                    }
                }

For some reason (which I haven't yet found), $peerDataItemIds is not containing values at the indexes specified, resulting in $id being 0 in the foreach.

 
mikeage
mikeage's picture

Joined: 2005-01-23
Posts: 138
Posted: Thu, 2008-08-28 08:25

Ok, fixed!

I had to replace the array_unique($itemIds) at the end of VirtualAlbum.inc with array_keys(array_count_values($itemIds)). Using array_unique, it wasn't re-indexing the keys.

I'm a little worried, however, that this may not preserve sort order.

So, does anyone with more SQL / Gallery knowledge want to help with this? It was seems to be a popular request... I know I'm begging here, but please....

 
Zeno

Joined: 2009-03-02
Posts: 3
Posted: Thu, 2009-03-12 20:39

This is great for me. I've been working on a frontend GUI to allow users to search tags AND/OR: http://www.biyg.org/ffxi/main.php
Once you get into tag results, & and | will show up representing further tag selection you can do.

I should look into coding to allow & and | at the same time.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Sat, 2009-03-14 04:10

Looking forward to continued community involvement on this module.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
scrampy

Joined: 2008-10-17
Posts: 1
Posted: Mon, 2009-04-06 17:26

Wow, I'm glad I searched the forums today!

I moved to Gallery for the only reason that I needed tags, and assumed multi-tag search "worked". Boy was I pleasantly surprised to see how much more I could do with my photos once I made the transition, but the lack of multi-tag search (I only really care about AND) still nags me.

I've never done any serious PHP development, but I can handle myself in SQL - is this AND/OR functionality something can can be easily extended to the search box based on Mikeage's work?

I'd be happy to try and help if steered in the right direction on where the search handler is.

Scrampy