<?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 plgArismartcontentOrggchart extends AriSmartContentPluginContent
{
	var $_optionsMapping = array(
		'allowCollapse' => 'chart_allowCollapse',
		'allowHtml' => 'chart_allowHtml',
		'nodeClass' => 'chart_nodeClass',
		'selectedNodeClass' => 'chart_selectedNodeClass',
		'size' => 'chart_size'
	);

	function __construct(&$subject, $config)
	{
		parent::__construct($subject, $config); 

		$this->loadLanguage('', JPATH_ADMINISTRATOR);
	}

	function getTag()
	{
		return 'orggchart';
	}

	function contentPluginHandler($params, $content, $sourceContent) 
	{
		AriKernel::import('Application.ARISmartContent.Plugin.NodeListPlugin');
		AriKernel::import('Application.ARISmartContent.Plugin.SimpleContentPlugin');
		
		$nodeListPlg = new AriSmartContentNodeListPlugin('node', true);
		$nodeList = $nodeListPlg->getNodeList($content);
		
		jimport('arismartcontent.orggchart.orggchart');
		
		$id = AriUtils::getParam($params, 'id');
		if (empty($id))
			$id = uniqid('orggchart_', false);

		$chart = new AriSmartContentWidgetOrgGChart($id, $this->getMergedParams($params));

		$output = $chart->getOutput('renderItems', $nodeList);

		$stylesPlg = new AriSmartContentPluginSimpleContent('styles');
		$styles = $stylesPlg->getContent($content);

		if (!empty($styles))
		{
			$doc = JFactory::getDocument();
			$doc->addStyleDeclaration($styles);
		}

		return $output;
	}
}