<?php
/**
 * This file is part of the transcoding library. It contains the
 * definition of the {@link TranscodingActionSwitchTemplate} class.
 * 
 * @author Sylvain Lequeux
 * @author Francois Daoust <fd@w3.org>
 * @package TransPythia
 * @version $Revision: 1.15 $
 * @license http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231.html W3C Software Notice and License
 * @copyright Copyright (c) 2009, W3C (MIT, ERCIM, Keio)
 */


/**
 * Include the {@link TranscodingAction} base class definition.
 */
require_once(dirname(__FILE__) . '/transcodingaction.php');


/**
 * Transcoding action that switches the template to a mobile-friendly template
 * whenever the requesting device is a "mobile" device.
 * 
 * A few options may be set through a call to
 * {@link TranscodingAction::setOption()} if needed:
 * - mobile_device: contains the DDR property reference that the transcoding
 *   must use to tell whether the requesting device is mobile or not. The action
 *   uses the is_wireless_device property of the WURFL namespace when the option
 *   is not set.
 * - default: contains the name of the non-mobile template. "default" is used
 *   when the option is not set.
 * - mobile: contains the name of the mobile-friendly template. "mobile" is used
 *   when the option is not set.
 * 
 * This transcoding action is not a normal transcoding action in the sense that
 * it does not apply to content. It merely returns the name of the template that
 * best matches the capabilities of the requesting device, regardless of the
 * content it is fed with.
 * 
 * @author Sylvain Lequeux
 * @author Francois Daoust <fd@w3.org>
 * @package TransPythia
 * @version $Revision: 1.15 $
 * @license http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231.html W3C Software Notice and License
 * @copyright Copyright (c) 2009, W3C (MIT, ERCIM, Keio)
 */
class TranscodingActionSwitchTemplate extends TranscodingAction{
	
	/**
	 * Checks the requesting device and returns the template that best matches
	 * its capabilities. 
	 * 
	 * @param string $content Unused.
	 * @return string The template name to use.
	 */
	public function apply($content, $evidence){
		$this->initPropertyValues($evidence);
		
		$this->initproperty('mobile_device',
			TranscodingAction::$WURFL_MOBILE_DEVICE,
			TranscodingAction::$WURFL_VOCABULARY,
			TranscodingAction::$WURFL_DEFAULT_ASPECT);
		
		$this->initOption('default', 'string', 'default');
		$this->initOption('mobile', 'string', 'mobile');
		
		$property = $this->getOption('mobile_device');
		$is_mobile_device = $this->getPropertyValuePr($property);
		
		if(!isset($is_mobile_device) || !$is_mobile_device->getBoolean()){
		  	$theme = $this->getOption('default');
		}
		else{
			$theme = $this->getOption('mobile');
		}
		
		return $theme;
	}
}

?>