<?php
/*
 * $RCSfile: ExifPropertiesMap.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:42 $
 * @package Exif
 * @author Bharat Mediratta <bharat@menalto.com>
 */

/**
 * A mapping of items to specific named attributes (eg, view count and order
 * weight).  We don't want to put these attributes inside the entity itself
 * because we want to be able to modify many of them at once without worrying
 * about versioning.  These values are also non-essential to the integrity of
 * the entity itself.
 *
 * @g2 <class-name>ExifPropertiesMap</class-name>
 * @g2 <schema>
 * @g2   <schema-major>1</schema-major>
 * @g2   <schema-minor>0</schema-minor>
 * @g2 </schema>
 *
 * @package Exif
 * @subpackage Classes
 */

class ExifPropertiesMap_core {

    /**
     * @g2 <map>
     * @g2   <member>
     * @g2     <member-name>property</member-name>
     * @g2     <member-type>STRING</member-type>
     * @g2     <member-size>MEDIUM</member-size>
     * @g2   </member>
     * @g2   <member>
     * @g2     <member-name>viewMode</member-name>
     * @g2     <member-type>INTEGER</member-type>
     * @g2     <member-size>LARGE</member-size>
     * @g2   </member>
     * @g2   <member>
     * @g2     <member-name>sequence</member-name>
     * @g2     <member-type>INTEGER</member-type>
     * @g2     <member-size>LARGE</member-size>
     * @g2   </member>
     * @g2   <key>
     * @g2     <member-name>property</member-name>
     * @g2     <member-name>viewMode</member-name>
     * @g2   </key>
     * @g2 </map>
     */

    /**
     * Return the target properties for the given view mode
     *
     * @param int the view mode (EXIF_SUMMARY, etc)
     * @return array object GalleryStatus a status code
     *               array logical exif property names
     * @static
     */
    function getProperties($viewMode) {
	global $gallery;

	$query = '
        SELECT
          [ExifPropertiesMap::property], [ExifPropertiesMap::viewMode], [ExifPropertiesMap::sequence]
        FROM
          [ExifPropertiesMap]
        WHERE
          [ExifPropertiesMap::viewMode] = ?
        ORDER BY
          [ExifPropertiesMap::sequence] ASC';
	list ($ret, $searchResults) = $gallery->search($query, array($viewMode));
	if ($ret->isError()) {
	    return array($ret->wrap(__FILE__, __LINE__), null);
	}

	$data = array();
	while ($result = $searchResults->nextResult()) {
	    $data[] = $result[0];
	}

	return array(GalleryStatus::success(), $data);
    }

    /**
     * Set the target properties for the given view mode
     *
     * @param int the view mode (EXIF_SUMMARY, etc)
     * @param array logical property key/value pairs
     * @return object GalleryStatus a status code
     * @static
     */
    function setProperties($viewMode, $properties) {

	/* Remove all old map entries */
	$ret = ExifPropertiesMap::removeMapEntry(array('viewMode' => $viewMode));
	if ($ret->isError()) {
	    return $ret->wrap(__FILE__, __LINE__);
	}

	for ($i = 0; $i < sizeof($properties); $i++) {
	    $ret = ExifPropertiesMap::addMapEntry(array('property' => $properties[$i],
							'viewMode' => $viewMode,
							'sequence' => $i));
	    if ($ret->isError()) {
		return $ret->wrap(__FILE__, __LINE__);
	    }
	}

	return GalleryStatus::success();
    }
}

include(dirname(__FILE__) . '/interfaces/ExifPropertiesMap.inc');
?>
