0byt3m1n1
Path:
/
data
/
applications
/
aps
/
gallery
/
2.2-08
/
htdocs
/
modules
/
customfield
/
classes
/
[
Home
]
File: CustomFieldSearch.class
<?php /* * Gallery - a web based photo album viewer and editor * Copyright (C) 2000-2007 Bharat Mediratta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ GalleryCoreApi::requireOnce('modules/search/classes/GallerySearchInterface_1_0.class'); /** * This is an implementation of the search module's SearchInterface_1_0 * @package CustomField * @subpackage Classes * @author Alan Harder <alan.harder@sun.com> * @version $Revision: 15513 $ */ class CustomFieldSearch extends GallerySearchInterface_1_0 { /** * @see GallerySearchInterface_1_0::getSearchModuleInfo */ function getSearchModuleInfo() { global $gallery; list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'customfield'); if ($ret) { return array($ret, null); } $info = array('name' => $module->translate('Custom Fields'), 'description' => $module->translate('Custom Fields Module'), 'options' => array( 'customfield' => array( 'description' => $module->translate('Search custom fields'), 'enabled' => 1))); return array(null, $info); } /** * @see GallerySearchInterface_1_0::search */ function search($options, $criteria, $offset=0, $count=-1) { global $gallery; list ($ret, $aclIds) = GalleryCoreApi::fetchAccessListIds('core.view', $gallery->getActiveUserId()); if ($ret) { return array($ret, null); } if (empty($aclIds)) { return array(null, array('start' => 0, 'end' => '0', 'count' => 0, 'results' => array())); } $aclMarkers = GalleryUtilities::makeMarkers(count($aclIds)); $countQuery = sprintf(' SELECT COUNT([CustomFieldMap::itemId]) FROM [CustomFieldMap], [GalleryAccessSubscriberMap] WHERE [CustomFieldMap::itemId] = [GalleryAccessSubscriberMap::itemId] AND [GalleryAccessSubscriberMap::accessListId] IN (%s) AND [CustomFieldMap::value] LIKE ? ', $aclMarkers); $query = sprintf(' SELECT [CustomFieldMap::itemId], [CustomFieldMap::field], [CustomFieldMap::value] FROM [CustomFieldMap], [GalleryAccessSubscriberMap] WHERE [CustomFieldMap::itemId] = [GalleryAccessSubscriberMap::itemId] AND [GalleryAccessSubscriberMap::accessListId] IN (%s) AND [CustomFieldMap::value] LIKE ? ORDER BY [CustomFieldMap::itemId] DESC ', $aclMarkers); $data = $aclIds; $data[] = '%' . $criteria . '%'; /* Find the total */ list ($ret, $results) = $gallery->search($countQuery, $data); if ($ret) { return array($ret, null); } $result = $results->nextResult(); $numRows = (int)$result[0]; list ($ret, $results) = $gallery->search( $query, $data, array('limit' => array('offset' => $offset, 'count' => $count))); if ($ret) { return array($ret, null); } $searchResults = array(); while ($result = $results->nextResult()) { $searchResults[] = array('itemId' => (int)$result[0], 'fields' => array(array('key' => $result[1], 'value' => $result[2]))); } $data = array('start' => $numRows == 0 ? 0 : $offset+1, 'end' => $numRows == 0 ? 0 : $offset + sizeof($searchResults), 'count' => $numRows, 'results' => $searchResults); return array(null, $data); } } ?>