Search module - Add user album id

Minhou

Joined: 2011-03-30
Posts: 3
Posted: Thu, 2011-03-31 01:03

Hi there,

I'm trying to populate the owner's user album id in the search module.
I would like it populate under the field Owner.
Having some difficulties here but I'm pretty sure I'm close to get it...

So here's what I did in the SearchScan.inc at line ~240 at the end just before:

Quote:
$template->javascript('modules/search/HighlightResults.js');

I added this:

Quote:
$SearchScan =& $template->getVariableByReference('SearchScan');
global $gallery;

foreach($SearchScan['searchResults'] as $id=>$item) {

// Serban: add a link to user's album
list ($ret, $albumId) =
GalleryCoreApi::getPluginParameter('module', 'useralbum', 'albumId', $item['itemId']['ownerId']);
if ($ret) { return array($ret, null); }
$SearchScan['searchResults'][$id]['ownerAlbum'] = $albumId;

}

I called this function in SearchScan.tpl after this:

Quote:
{foreach from=$result.fields item=field}
{if isset($field.value)}

<li>
<span class="ResultKey"><strong>{$field.key}:</strong></span>
<span class="ResultData">{$field.value|default:"&nbsp;"|markup}</span>
</li>
{/if}
{/foreach}

I added this:

Quote:
<li>{$results.ownerAlbum}</li>

The problem here is that I'm unable to find the appropriate code to generate the Array of user's ids

Quote:
$item['itemId']['ownerId']

For testing, I replaced it with a user id '6' and it worked but now how do I find the Array of all user's ids associated with the searched items? I know that you can find the user's id in the tpl with this code

Quote:
{$SearchScan.items.$itemId.ownerId}

but how to call it in the SearchScan.inc?

Your help is much appreciated :) Thanks!


Gallery version = 2.2.6 core 1.2.0.8
PHP version = 5.2.14 cgi-fcgi
Webserver = Apache
Database = mysqli 5.1.47-community-log, lock.system=flock
Toolkits = ArchiveUpload, Gd, NetPBM, Getid3, Thumbnail, Ffmpeg, Dcraw, Exif
Acceleration = partial/900, partial/900
Default theme = matrix
gettext = enabled
Locale = en_US

 
Dayo

Joined: 2005-11-04
Posts: 1642
Posted: Thu, 2011-03-31 20:04

$item->getOwnerId();

--
dakanji.com

 
Minhou

Joined: 2011-03-30
Posts: 3
Posted: Thu, 2011-03-31 20:18

Tried here:

Quote:
$SearchScan =& $template->getVariableByReference('SearchScan');
global $gallery;

foreach($SearchScan['searchResults'] as $id=>$item) {

// Serban: add a link to user's album
list ($ret, $albumId) =
GalleryCoreApi::getPluginParameter('module', 'useralbum', 'albumId', $item->getOwnerId());
if ($ret) { return array($ret, null); }
$SearchScan['searchResults'][$id]['ownerAlbum'] = $albumId;

}

Got this error:

Quote:
Fatal error: Call to a member function getOwnerId() on a non-object in SearchScan.inc on line 257

 
Dayo

Joined: 2005-11-04
Posts: 1642
Posted: Thu, 2011-03-31 22:33

The error means you don't have an Item object there.

I didn't look at the preceding code for validity and just gave you the answer to how to get the Owner Id in the inc file. Which is to call the getOwnerId method of an Item.
You need to have the Item in place in the first place.

--
dakanji.com

 
Minhou

Joined: 2011-03-30
Posts: 3
Posted: Sat, 2011-04-02 03:13

Solved! Thanks!
For those who are wondering how I did it. Here's the code I put in SearchScan.inc

Quote:
$SearchScan =& $template->getVariableByReference('SearchScan');
global $gallery;

foreach($itemList as $id=>$item) {
$items[$item->getId()] = $item;

// Serban: add a link to user's album
list ($ret, $albumId) =
GalleryCoreApi::getPluginParameter('module', 'useralbum', 'albumId', $item->getOwnerId());
if ($ret) { return array($ret, null); }
$SearchScan['items'][$item->getId()]['ownerAlbum'] = $albumId;

}

Call it in SearchScan.tpl:

Quote:
{$SearchScan.items.$itemId.ownerAlbum}

 
eliz82

Joined: 2009-11-06
Posts: 71
Posted: Sat, 2011-04-02 16:53

when i click advanced search it give me error

Quote:
phpBB Debug] PHP Notice: in file /home/fotonat/public_html/gallery/modules/search/SearchScan.inc on line 244: Invalid argument supplied for foreach()
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3810: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3184)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3812: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3184)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3813: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3184)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3814: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3184)

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sat, 2011-04-02 19:32

you should really perform a module availability check:

$SearchScan =& $template->getVariableByReference('SearchScan');
global $gallery;

foreach($itemList as $id=>$item) {
    $items[$item->getId()] = $item;
    list($ret, $modules) = GalleryCoreApi::fetchPluginStatus('module');
    if ($ret) {
        return array($ret, null);
    }
    if ($modules['useralbum']['active'] && $modules['useralbum']['available']) {
        // Serban: add a link to user's album
        list ($ret, $albumId) =
        GalleryCoreApi::getPluginParameter('module', 'useralbum', 'albumId', $item->getOwnerId());
        if ($ret){
            return array($ret, null);
        }
        $SearchScan['items'][$item->getId()]['ownerAlbum'] = $albumId;
    }
}

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2