public function configure()
 {
     unset($this['created_at'], $this['updated_at'], $this['file_id']);
     unset($this->widgetSchema['id']);
     $this->widgetSchema->setLabel('name', '%community% Name');
     $this->setValidator('name', new opValidatorString(array('max_length' => 64, 'trim' => true)));
     $isAllowMemberCommunity = 1 != sfContext::getInstance()->getUser()->getMemberId();
     $communityCategories = Doctrine::getTable('CommunityCategory')->getAllChildren($isAllowMemberCommunity);
     if (0 < count($communityCategories)) {
         $choices = array();
         foreach ($communityCategories as $category) {
             $choices[$category->id] = $category->name;
         }
         $currentCategoryId = $this->object->community_category_id;
         if (!is_null($currentCategoryId) && !isset($choices[$currentCategoryId])) {
             $choices[$currentCategoryId] = $this->object->CommunityCategory->name;
         }
         $this->setWidget('community_category_id', new sfWidgetFormChoice(array('choices' => array('' => '') + $choices)));
         $this->widgetSchema->setLabel('community_category_id', '%community% Category');
     } else {
         unset($this['community_category_id']);
     }
     $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('form_community');
     $uniqueValidator = new sfValidatorDoctrineUnique(array('model' => 'Community', 'column' => array('name')));
     $uniqueValidator->setMessage('invalid', 'An object with the same "name" already exist in other %community%.');
     $this->validatorSchema->setPostValidator($uniqueValidator);
     $this->mergePostValidator(new sfValidatorCallback(array('callback' => array($this, 'checkCreatable'))));
 }
 public function configure()
 {
     unset($this['created_at'], $this['updated_at'], $this['file_id']);
     unset($this->widgetSchema['id']);
     $this->widgetSchema->setLabel('name', '%community% Name');
     $this->setValidator('name', new sfValidatorString(array('max_length' => 64, 'trim' => true)));
     $q = Doctrine::getTable('CommunityCategory')->createQuery()->where('lft > 1');
     if (1 != sfContext::getInstance()->getUser()->getMemberId()) {
         $q->andWhere('is_allow_member_community = 1');
     }
     $this->setWidget('community_category_id', new sfWidgetFormDoctrineChoice(array('model' => 'CommunityCategory', 'add_empty' => false, 'query' => $q)));
     $this->widgetSchema->setLabel('community_category_id', '%community% Category');
     $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('form_community');
     $uniqueValidator = new sfValidatorDoctrineUnique(array('model' => 'Community', 'column' => array('name')));
     $uniqueValidator->setMessage('invalid', 'An object with the same "name" already exist in other %community%.');
     $this->validatorSchema->setPostValidator($uniqueValidator);
     $this->mergePostValidator(new sfValidatorCallback(array('callback' => array($this, 'checkCreatable'))));
 }
 public function doClean($values)
 {
     try {
         parent::doClean($values);
     } catch (sfValidatorErrorSchema $e) {
         $error = new sfValidatorError($this, 'invalid', array('column' => implode(', ', $this->getOption('column'))));
         throw new sfValidatorErrorSchema($this, array($error));
     }
 }
 /**
  * Подмешивает дополнительные поля и значения:
  *     знак у суммы и прочая требуха
  * @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;
     }
 }