<?php
/*
 *
 * @package		ARI Smart Content
 * @author		ARI Soft
 * @copyright	Copyright (c) 2011 www.ari-soft.com. All rights reserved
 * @license		GNU/GPL (http://www.gnu.org/copyleft/gpl.html)
 * 
 */

defined('_JEXEC') or die;

require_once JPATH_ADMINISTRATOR . '/components/com_arismartcontent/kernel/class.AriKernel.php';

AriKernel::import('Parameters.ParametersHelper');
AriKernel::import('Application.ARISmartContent.Utils.ApplicationHelper');
AriKernel::import('Application.ARISmartContent.Providers.ProvidersHelper');
AriKernel::import('Web.JSON.JSON');
AriKernel::import('Document.DocumentHelper');

class AriSmartContentWidgetMediaGalleryFactory
{
	function createGallery($id, $params)
	{
		$inputFilter = JFilterInput::getInstance();
		
		$gallery = null;
		$galleryType = 'simple';//$params->get('galleryType', 'simple');
		$galleryType = ucfirst(strtolower($inputFilter->clean($galleryType, 'ALNUM')));

		if (empty($galleryType))
		{
			JError::raiseError(500, 'ARI Smart Content - Media Gallery: Gallery type is not specified.');
			return $gallery;
		}
		
		$galleryFile = dirname(__FILE__) . '/libs/mediagallery' . strtolower($galleryType) . '.php';
		$galleryClass = 'AriSmartContentWidgetMediaGallery' . $galleryType;
		
		$error = sprintf('ARI Smart Content - Media Gallery: "%1$s" type is not supported.',
			$galleryClass
		);
		
		if (!JFile::exists($galleryFile))
		{
			JError::raiseError(500, $error);
			return $gallery;
		}
		
		require_once $galleryFile;
		
		if (!class_exists($galleryClass))
		{
			JError::raiseError(500, $error);
			return $gallery;
		}
		
		$gallery = new $galleryClass($id, $params);
		
		return $gallery;
	}
}