<?php
/*
 * $RCSfile: GallerySortInterface_1_1.class,v $
 *
 * Gallery - a web based photo album viewer and editor
 * Copyright (C) 2000-2005 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.
 */
/**
 * @version $Revision: 1.5 $ $Date: 2005/08/23 03:49:03 $
 * @package Core
 * @author Alan Harder <alan.harder@sun.com>
 */

/**
 * This is an interface for adding custom sort orders for albums.
 *
 * @package Core
 * @subpackage Classes
 * @abstract
 */
class GallerySortInterface_1_1 {

    /**
     * Return information about this sort
     *
     * @return array object GalleryStatus a status code
     *               string localized name
     *               boolean true for presort
     */
    function getSortInfo() {
	return array(GalleryStatus::error(ERROR_UNIMPLEMENTED, __FILE__, __LINE__), null, null);
    }

    /**
     * Get the query fragments used to perform this sort.
     * Order by clause may contain %1%, %2% or %3% to reference the corresponding
     * items in the select clause.
     *
     * @param string either '' for ascending or ' DESC' for descending
     * @return array object GalleryStatus a status code
     *               string order by clause
     *               string select clause,
     *               string optional row matching condition
     *               string optional join clause
     */
    function getSortOrder($direction) {
	return array(GalleryStatus::error(ERROR_UNIMPLEMENTED, __FILE__, __LINE__),
		     null, null, null, null);
    }

    /**
     * Get information about available sort orders
     *
     * @param boolean (optional) false to omit "default sort order" selection
     * @return array object GalleryStatus a status code
     *               array of orderBy => localized name for sort orders
     *               array of orderBy => localized name for presorts
     *               array of orderDirection => localized name for direction
     * @static
     */
    function getAllSortOrders($includeDefault=true) {
	list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'core');
	if ($ret->isError()) {
	    return array($ret->wrap(__FILE__, __LINE__), null, null, null);
	}

	$orderByList = array(  '' => $module->translate('&laquo; default sort order &raquo;'),
		    'orderWeight' => $module->translate('Manual sort order'),
			  'title' => $module->translate('Title'),
			'summary' => $module->translate('Summary'),
	   'originationTimestamp' => $module->translate('Origination Date'),
	      'creationTimestamp' => $module->translate('Creation Date'),
	  'modificationTimestamp' => $module->translate('Last Changed Date'),
		    'description' => $module->translate('Description'),
		       'keywords' => $module->translate('Keywords'),
		  'pathComponent' => $module->translate('Name'),
		      'viewCount' => $module->translate('View Count'),
		         'random' => $module->translate('Random'));
	if (!$includeDefault) {
	    array_shift($orderByList);
	}

	$presortList = array(  '' => $module->translate('&laquo; no presort &raquo;'),
		    'albumsFirst' => $module->translate('Albums First'),
		    'viewedFirst' => $module->translate('Most Viewed First'));

	list ($ret, $implIds) =
	    GalleryCoreApi::getAllFactoryImplementationIds('GallerySortInterface_1_1');
	if ($ret->isError()) {
	    return array($ret->wrap(__FILE__, __LINE__), null, null, null);
	}

	foreach ($implIds as $sortId => $className) {
	    list ($ret, $sort) =
		GalleryCoreApi::newFactoryInstance('GallerySortInterface_1_1', $className);
	    if ($ret->isError()) {
		return array($ret->wrap(__FILE__, __LINE__), null, null, null);
	    }
	    list ($ret, $sortName, $isPresort) = $sort->getSortInfo();
	    if ($ret->isError()) {
		return array($ret->wrap(__FILE__, __LINE__), null, null, null);
	    }
	    if ($isPresort) {
		$presortList[$sortId] = $sortName;
	    } else {
		$orderByList[$sortId] = $sortName;
	    }
	}

	$orderDirectionList = array(
	     ORDER_ASCENDING => $module->translate('Ascending'),
	    ORDER_DESCENDING => $module->translate('Descending'));

	return array(GalleryStatus::success(), $orderByList, $presortList, $orderDirectionList);
    }
}
?>
