/** * Подмешивает дополнительные поля и значения: * знак у суммы и прочая требуха * @see sfForm */ protected function doBind(array $values) { // не используем поля в зависимости от типа операции switch ($values['type']) { case Operation::TYPE_BALANCE: unset($this['date'], $this['transfer_account_id'], $this['transfer_amount']); $values['accepted'] = true; if (!empty($values['id'])) { $validator = new sfValidatorDoctrineUnique(array('model' => 'Operation', 'column' => array('account_id', 'type')), array('invalid' => sprintf('Duplicate balance operations for account %s', $values['account_id']))); $validator->clean($values); } break; case Operation::TYPE_TRANSFER: unset($this['category_id']); break; default: unset($this['transfer_account_id'], $this['transfer_amount']); break; } // в зависимости от подтвержденности операции отключаем необходимости полей if (!$values['accepted']) { $this->setDraftValidation(); } parent::doBind($values); switch ($this->values['type']) { case Operation::TYPE_TRANSFER: $this->values['amount'] = -abs($this->values['amount']); $this->values['transfer_amount'] = abs($this->values['transfer_amount']); break; case Operation::TYPE_EXPENSE: $this->values['amount'] = -abs($this->values['amount']); break; case Operation::TYPE_BALANCE: $this->values['comment'] = "Начальный остаток"; break; default: $this->values['amount'] = abs($this->values['amount']); break; } }