<?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;

class plgArismartcontentDatatable extends AriSmartContentPluginContent
{
	var $_optionsMapping = array(
		'saveState' => 'datatable_stateSave',
		'cookieDuration' => 'datatable_stateDuration',
		'paginate' => 'datatable_paging',
		'paginationType' => 'datatable_pagingType',
		'lengthChange' => 'datatable_bLengthChange',
		'useFilter' => 'datatable_searching',
		'sort' => 'datatable_ordering',
		'showInfo' => 'datatable_info',
		'showProcessing' => 'datatable_processing',
		'autoWidth' => 'datatable_autoWidth',
		'pageSize' => 'datatable_pageLength',
		'sDom' => 'datatable_dom',
		'stripClasses' => 'datatable_stripeClasses',
		'scrollHeight' => 'datatable_scrollY',
		'scrollWidth' => 'datatable_scrollX',
		'searchText' => 'datatable_search_search',
		'showExportButtons' => 'datatable_showExportButtons',
		'fixedLeftColumns' => 'datatable_fixedcols_leftColumns',
		'fixedRightColumns' => 'datatable_fixedcols_rightColumns',
		'fixedHeightMatch' => 'datatable_fixedcols_heightMatch',
	);

	function getTag()
	{
		return 'datatable';
	}

	function contentPluginHandler($params, $content, $sourceContent) 
	{
		jimport('arismartcontent.datatable.datatable');

		$id = AriUtils::getParam($params, 'id');
		if (empty($id))
			$id = uniqid('dt_', false);

        $output = '';
        if (!empty($params['source']))
        {
            AriKernel::import('Parameters.ParametersHelper');

            $paramsTree = AriParametersHelper::flatParametersToArray($params);
            $srcParams = AriUtils::getParam($paramsTree, 'source', array());

            $dataTable = new AriSmartContentWidgetDatatable($id, $this->getMergedParams($params));
            $output = $dataTable->getOutput('render', $srcParams);
        }
        else
        {
            $dataTable = new AriSmartContentWidgetDatatable($id, $this->getMergedParams($params));
            $output = $dataTable->getOutput('renderInline', $content);
        }

        return $output;
	}
}