<?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') && defined('ARI_FRAMEWORK_LOADED')) or die;

AriKernel::import('Joomla.Tables.Table');

class AriSmartContentTableProvidersourcetype extends AriTable
{
	var $SourceTypeId;
	var $Name = '';
	var $SystemName = '';
	var $ProviderId;
	var $SettingsGroupId;

	function __construct(&$db) 
	{
		parent::__construct('#__arismartcontent_provider_source_types', 'SourceTypeId', $db);
	}

	function getProviderName()
	{
		$name = explode('_', $this->SystemName);

		return count($name) > 0 ? $name[0] : null;
	}
	
	function getPostfix()
	{
		return str_replace(' ', '', ucwords(str_replace('_', ' ', $this->SystemName)));
	}
	
	function loadBySystemName($name)
	{
		return $this->customLoad(array(&$this, '_loadBySystemName'), array($name), 0, 1);
	}
	
	function _loadBySystemName($query, $queryParams, $name)
	{
		$db = $this->getDBO();
		$tblAlias = $queryParams['tblAlias'];

		$query->where(
			sprintf(
				'`%1$s`.SystemName = %2$s',
				$tblAlias,
				$db->Quote($name)
			)
		);

		return $query;
	}
}