<?php

class wpValidatorTransferSol extends sfValidatorBase {
    public function configure($options = array(), $messages = array()) {
        $this->addMessage('identical', 'Merci de sélectionner des adhérents différents');
        $this->addMessage('not_enough_sol', 'Le compte ' . wpConfig::getAdditionalCurrencyName() . ' de cet adhérent (%amount%) n\'est pas suffisant pour effectuer ce transfert');
    }

    protected function doClean($values) {
        if ($values['katao_member_2_id'] == $values['katao_member_1_id']) {
            throw new sfValidatorErrorSchema($this, array('katao_member_2_id' => new sfValidatorError($this, 'identical')));
        }

        $katao_member = KataoMemberPeer::retrieveByPK($values['katao_member_1_id']);
        if ($katao_member && $values['amount'] > $katao_member->getCurrentAmountSol()) {
            throw new sfValidatorErrorSchema($this, array('katao_member_2_id' => new sfValidatorError($this, 'not_enough_sol', array('amount' => $katao_member->getCurrentAmountSolStr()))));
        }

        return $values;
    }
}