Search by Owner Name

kehlers

Joined: 2007-08-03
Posts: 15
Posted: Thu, 2007-09-20 01:19

Can anyone give me a road map to adding a "search by owner name" to the Gallery Search? Basically, I want to be able to type an owner id (ex: kehlers) in the 'Search the Gallery' box, then have all times which are owned by kehlers to show as search results. I've looked at the GalleryCoreSearch.class, but the things I tried haven't worked so far.

Gallery version = 2.2.2 core 1.2.0.4
PHP version = 5.2.0 cgi-fcgi
Webserver = Apache/1.3.37 (Unix) mod_fastcgi/2.4.2 mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635.SR1.2 mod_ssl/2.8.28 OpenSSL/0.9.7a PHP-CGI/0.1b
Database = mysqli 5.0.37-standard-log, lock.system=flock
Toolkits = Gd
Acceleration = none, none
Operating system = Linux box251.bluehost.com 2.6.22-6_3.BHsmp #1 SMP Mon Sep 10 10:38:33 MDT 2007 x86_64
Default theme = dixie
gettext = enabled

Login or register to post comments
kehlers

Joined: 2007-08-03
Posts: 15
Posted: Mon, 2008-01-07 22:26

Okey-dokey - I did figure this out, and it was simple when I finally figured it out. So, I'll post the code I used. Cautionary note: this does require altering source code, and thus when you apply upgrades, your changes may be overwritten. I couldn't find another way to do this, so I went ahead. The result of these modifications is that when a user types a keyword in Gallery Search, the item owner field will be searched also. Thus, you can search for all gallery items owned by x, where 'x' is what the user types.

In the file /gallery/modules/core/classes/GalleryCoreSearch.class, you must add/alter two sections.

1) Just before the $storage =& $gallery->getStorage(); at around line 85, ADD
$whereList[] = "[GalleryUser::userName] LIKE ?";
$whereData[]= '%' . $criteria . '%';

2) Modify the $countquery, around line 104, as shown below:
$countQuery = sprintf('
SELECT
COUNT([GalleryItem::id])
FROM
[GalleryItem], [GalleryAccessSubscriberMap], [GalleryUser]
WHERE
(' . implode(' OR ', $whereList) . ')
AND
[GalleryItem::id] = [GalleryAccessSubscriberMap::itemId]
AND
[GalleryUser::id] = [GalleryItem::ownerId]

AND
[GalleryAccessSubscriberMap::accessListId] IN (%s)
', $aclMarkers);

Login or register to post comments
saidts

Joined: 2007-03-27
Posts: 44
Posted: Sat, 2008-03-01 15:25

Thanks kehlers!!!

To search by Id, just do the following:

In the file /gallery/modules/core/classes/GalleryCoreSearch.class, you must add, just before the $storage =& $gallery->getStorage(); at around line 90:

$whereList[] = "[GalleryItem::Id] LIKE ?";
$whereData[]= '%' . $criteria . '%';

Login or register to post comments
Another_Matt

Joined: 2009-08-20
Posts: 34
Posted: Tue, 2009-09-29 13:47

I used this mod but I needed to limit my searches to only image owners. Kehlers code above includes the owner field in every search. So I replaced the "Search Summaries" check box with a "Search Photographers" check box. Here's what I changed in GalleryCoreSearch.class

Line 51 Changed

Quote:
'summaries' => array(
'description' => $module->translate('Search summaries'),
'enabled' => 1),

to

Quote:
'owner' => array(
'description' => $module->translate('Search photographers'),
'enabled' => 1),

Line 70 Changed

Quote:
'summaries' => '[GalleryItem::summary]',

to

Quote:
'owner' => '[GalleryUser::userName]',

Added to the $acountQuery (Kehler's second step) around line 104

Quote:
$countQuery = sprintf('
SELECT
COUNT([GalleryItem::id])
FROM
[GalleryItem], [GalleryAccessSubscriberMap], [GalleryUser]
WHERE
(' . implode(' OR ', $whereList) . ')
AND
[GalleryItem::id] = [GalleryAccessSubscriberMap::itemId]
AND
[GalleryUser::id] = [GalleryItem::ownerId]

AND
[GalleryAccessSubscriberMap::accessListId] IN (%s)
', $aclMarkers);

Finally replaced 'summary' call on line 173 to 'owner' listed in bold

Quote:
foreach (array('[GalleryItem::title]' => $text['title'],
'[GalleryItem::ownerId]' => $text['owner'],
'[GalleryItem::keywords]' => $text['keywords'],
'[GalleryItem::description]' => $text['description'])
as $columnName => $fieldText) {

It will now search the last name of the owner when "Search Photographers" is checked. Enjoy.

Login or register to post comments
kehlers

Joined: 2007-08-03
Posts: 15
Posted: Tue, 2009-09-29 20:01

Great addition! Thx.

Login or register to post comments