<?php

namespace Engine\Form\Input;

/**
 * base input time class
 * @author Lucian
 */
class Time extends \Engine\Form\Input\Text
{
	protected $class = "time";

	/**
	 * short/long date format variables are used as a workaround the 2 different date formats.
	 * It should handle automatic conversions between yyyy-mm-dd to Y-m-d for example
	 * @var String
	 */
	private $shortTimeFormat = "";

	/**
	 * short/long date format variables are used as a workaround the 2 different date formats.
	 * It should handle automatic conversions between yyyy-mm-dd to Y-m-d for example
	 * @var String
	 */
	private $longTimeFormat = "";

	/**
	 * Create a new date object
	 * @param $rowDescription
	 * @param $name
	 * @param $value
	 */
	public function __construct($label=null, $name=null, $value=null)
	{
		parent::__construct($label, $name, $value);

		$this->longTimeFormat = 	\dateHelper::appLongDatetimeFormat('time');
		$this->shortTimeFormat = 	\dateHelper::appShortDatetimeFormat('time');

		$this->defaultStyle['width'] = 115;
	}

	/**
	 * Rewrite the default value (if it is 00:00:00)
	 *
	 * @param Mixed $value
	 */
	public function setValue($value)
	{
		$this->value = $value;

		return $this;
	}

	/**
	 * (non-PHPdoc)
	 * @see \Engine\Form\Input\ElementAbstract::getTemplateParams()
	 */
	protected function getTemplateParams($templateClass = null, $parentElement = null)
	{
		$params = parent::getTemplateParams($templateClass, null);

		$params['shortTimeFormat'] = $this->shortTimeFormat;
		$params['longTimeFormat'] = $this->longTimeFormat;
		$time = '';

		if($params['value']){
			$ts = strtotime(TODAY_ISO." ".$params['value']);

			$time = date($this->shortTimeFormat, $ts);
		}

		$params['displayValue'] = $time;

		return $params;
	}

}
