<?php

class Agro_Validate_AreaSinistrada extends Zend_Validate_Abstract {
    const INVALID_AREA_SINISTRADA     = 'areaSinistradaInvalid';
    
    protected $_messageTemplates = array(
        self::INVALID_AREA_SINISTRADA    => "A área sinistrada não pode ser maior do que a área da quadra."
	);
	    
    public function isValid($value, $context = null) {
        $Model_ItensSegurados = new Seguro_Model_ItensSegurados();
        
        $this->_setValue($value);
 
        if (is_array($context)) {
            if (isset($context['id_item_segurado'])) {
                if($value >= 0.01 && $value <= $Model_ItensSegurados->getArea($context['id_item_segurado'])) {
                    return true;
                }
            }
        }
 
        $this->_error(self::INVALID_AREA_SINISTRADA);
        return false;        
    }
}
