示例#1
0
 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'))));
 }