<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/


class HTML_LabData_Renderer_LabSmarty extends HTML_QuickForm2_Renderer
{
	private $form;
	protected function exportMethods()
	{
		return array(
			'getErrors',
			'getHidden',
			'getHiddenString',
			'getJSLibs',
			'getJS',
			'getAttributes',
			'getElements',
			'getElementById',
			'getType',
			'toString'
		);
	}
	public function getType()
	{
		return $this->form->getType();
	}

	public function getAttributes($asString = false)
	{
		return $this->form->getAttributes($asString);
	}

	public function getElements()
	{
		return $this->form->getElements();
	}

	public function getElementById($id)
	{
		return $this->form->getElementById($id);
	}

	public function __toString()
	{
		return $this->form->__toString();
	}

	public function renderElement(HTML_QuickForm2_Node $element)
	{
		if ($this->options['group_errors'] && ($error = $element->getError())) {
			$this->errors[$element->getId()] = $error;
		}
	}

	public function renderHidden(HTML_QuickForm2_Node $element)
	{
		if ($this->options['group_hiddens']) {
			$this->hidden[] = $element->__toString();
		}
	}

	public function getJS()
	{
		return $this->getJavascriptBuilder()->getFormJavascript($this->form->getId());
	}

	public function getJSLibs($inline = false, $addScriptTags = true)
	{
		return $this->getJavascriptBuilder()->getLibraries($inline, $addScriptTags);
	}

	public function getErrors()
	{
		return $this->errors;
	}

	public function getHidden()
	{
		return $this->hidden;
	}

	public function getHiddenString()
	{
		return implode($this->hidden, '');
	}

	public function reset()
	{
		$this->errors   = array();
		$this->hidden   = array();
		$this->required = false;

		return $this;
	}

	public function startForm(HTML_QuickForm2_Node $form)
	{
		$this->reset();
	}

	public function finishForm(HTML_QuickForm2_Node $form)
	{
		$this->renderElement($form);
		$this->form=$form;
	}

	public function startContainer(HTML_QuickForm2_Node $container)
	{
	}

	public function finishContainer(HTML_QuickForm2_Node $container)
	{
		$this->renderElement($container);
	}

	public function startGroup(HTML_QuickForm2_Node $group)
	{
	}

	public function finishGroup(HTML_QuickForm2_Node $group)
	{
		$this->renderElement($group);
	}
}