<?php

/**
 * Gmaps
 *
 * @author Arkadiusz Rychlik <a.rychlik at eppe.com.pl>
 */
class Eppe_Form_Element_Gmaps extends Zend_Form_Element {

	public $helper = 'formGmaps';
	
	protected $_value = [
		'md'=>null, // marker D
		'me'=>null, // marker E
		'cd'=>null, // center D
		'ce'=>null, // center E
		'cz'=>null, // center Zoom
	];
	
	public function init() {
		$this->setAttrib('class', 'gmaps-input');
	}

	protected function fetchValue($context){
		$value = [];
		if(is_array($context)){
			foreach (array_keys($this->_value) as $k) {
				$key = $this->_name.$k;
				$val = array_key_exists($key, $context) ? $context[$key] : null;
				$value[$k] = $val;
			}			
		}
		else{
			foreach (array_keys($this->_value) as $k) {
				$value[$k] = null;
			}			
		}
		return $value;
	}
	
	public function isValid($value, $context = null) {
		$value = $this->fetchValue($context);
		return parent::isValid($value, $context);
	}


}
