<?php

class KataoMemberDepositTransferSolForm extends BaseKataoMemberDepositForm {
    public function configure() {
        unset($this->validatorSchema['id'], $this->validatorSchema['katao_member_id'], $this->validatorSchema['comment'], $this->validatorSchema['currency'], $this->validatorSchema['payment_mode'], $this->validatorSchema['check_number'], $this->validatorSchema['check_bank'], $this->validatorSchema['check_deposit'], $this->validatorSchema['status'], $this->validatorSchema['valid_until'], $this->validatorSchema['created_at'], $this->validatorSchema['updated_at']);
        unset($this->widgetSchema['id'], $this->widgetSchema['katao_member_id'], $this->widgetSchema['comment'], $this->widgetSchema['currency'], $this->widgetSchema['payment_mode'], $this->widgetSchema['check_number'], $this->widgetSchema['check_bank'], $this->widgetSchema['check_deposit'], $this->widgetSchema['status'], $this->widgetSchema['valid_until'], $this->widgetSchema['created_at'], $this->widgetSchema['updated_at']);

        $sf_user = sfContext::getInstance()->getUser();
        if ($sf_user->isJustDelegate()) {
            $choices = KataoMemberPeer::getAll(false, false, $sf_user->getInstance()->getKataoMember()->getKataoNodeId());
        } else {
            $choices = KataoMemberPeer::getAllGroupedByNode();
        }
        $this->widgetSchema['katao_member_1_id'] = new sfWidgetFormSelect(array('choices' => $choices));
        $this->widgetSchema['katao_member_2_id'] = new sfWidgetFormSelect(array('choices' => $choices));
        $this->validatorSchema['katao_member_1_id'] = new sfValidatorPass();
        $this->validatorSchema['katao_member_2_id'] = new sfValidatorPass();

        $this->widgetSchema['amount'] = new sfWidgetFormInput(array(), array('style' => 'width: 50px; text-align: right'));
        $this->widgetSchema['comment'] = new sfWidgetFormTextarea(array(), array('style' => 'width: 250px; height: 100px'));

        $this->widgetSchema['valued_at'] = new wpWidgetFormRichDate();
        $this->validatorSchema['valued_at'] = new sfValidatorDateTime(array('required' => true, 'date_format' => '@(?P<day>\d{2}).(?P<month>\d{2}).(?P<year>\d{4})@'));

        $this->setDefault('valued_at', time());

        $this->widgetSchema->setLabels(array(
                'amount' => 'Montant',
                'katao_member_1_id' => 'De l\'adhérent',
                'katao_member_2_id' => 'Vers l\'adhérent',
                'valued_at' => 'Date',
                ));

        $this->validatorSchema->setPostValidator(new wpValidatorTransferSol());
    }
}