<?php

/**
 * Goweb Sitemanager 5 Framework
 * 
 * @version    5.0.0
 * @category   Goweb
 * @package    Goweb_Validate
 * @author     I&D <dev@goweb.pt>, Pedro Pinto <ppinto@goweb.pt>
 * @copyright  2009 (c) Goweb (http://www.goweb.pt)
 */

/**
 * Goweb_Validate
 */
Goweb::loadClass('Zend_Validate_Identical');

/**
 * Classe para validar campos obrigaterios
 *
 * @version    5.0.10
 * @category   Goweb
 * @package    Goweb_Validate
 * @author     I&D <dev@goweb.pt>, Pedro Pinto <ppinto@goweb.pt>
 * @copyright  2009 (c) Goweb (http://www.goweb.pt)
 */
class Goweb_Validate_NotEqual extends Zend_Validate_Identical {
    /**
     * Constructor
     *
     * @param  string  $errorMessage
     */
    /**
     * Nome do elemento a comparar
     *
     * @var String
     */
    protected $_element = null;
    
    /**
     * Constructor
     *
     * @param  string  $errorMessage
     * @param  array   $params        Paremetro "element" do formul&aacute;rio
     */
    public function __construct($errorMessage, $params) {
        if (!isset($params['element'])){
            throw new Goweb_Exception('O parâmetro "element" é obrigatório.');
        }
        $this->_element = $params['element'];
        parent::__construct(isset($_POST[$params['element']]) ? $_POST[$params['element']] : '');
        foreach (array_keys($this->_messageTemplates) as $key) $this->setMessage($errorMessage, $key);
    }
    
    public function getElement(){
        return $this->_element;
    }
    
    public function isValid($value){
        return !(parent::isValid($value));
    }
    
}