public function setup()
 {
     parent::setup();
     unset($this['id']);
     unset($this['community_id']);
     unset($this['member_id']);
     unset($this['created_at']);
     unset($this['updated_at']);
     unset($this['event_updated_at']);
     $dateParam = array('culture' => sfContext::getInstance()->getUser()->getCulture(), 'month_format' => 'number');
     $this->setWidget('name', new sfWidgetFormInput());
     $this->setWidget('open_date', new opWidgetFormDate($dateParam));
     $this->setWidget('application_deadline', new opWidgetFormDate(array_merge($dateParam, array('can_be_empty' => true))));
     $this->setWidget('open_date_comment', new sfWidgetFormInput());
     $this->setWidget('area', new sfWidgetFormInput());
     $this->setValidator('name', new opValidatorString(array('rtrim' => true)));
     $this->setValidator('body', new opValidatorString(array('rtrim' => true)));
     $this->setValidator('area', new opValidatorString(array('rtrim' => true)));
     $this->setValidator('open_date_comment', new sfValidatorString(array('required' => false)));
     $this->setValidator('application_deadline', new sfValidatorDate(array('required' => false, 'min' => strtotime(date('Y-m-d'))), array('min' => sfContext::getInstance()->getI18N()->__('The date must be after now.'))));
     $validatorOpenDate = new sfValidatorCallback(array('callback' => array($this, 'validateOpenDate')));
     $this->mergePostValidator($validatorOpenDate);
     $validatorApplicationDeadline = new sfValidatorCallback(array('callback' => array($this, 'validateApplicationDeadline')));
     $validatorApplicationDeadline->addMessage('invalid_application_deadline', sfContext::getInstance()->getI18N()->__('The application deadline must be before the open date.'));
     $this->mergePostValidator($validatorApplicationDeadline);
     $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('community_event_form');
 }
 public function checkUpload(sfValidatorCallback $validator, $values, $parameters = null)
 {
     // disabled temporarily, perhaps this feature will be implemented in a better way
     return $values;
     $filename = '';
     $validator->addMessage('unique', 'A file with that name already exists in the destinated directory.');
     if ($this->isNew()) {
         if ($values['hash'] instanceof sfValidatedFile) {
             $filename = $values['hash']->getOriginalName();
         }
     } else {
         $filename = $values['filename'];
     }
     if ($values['directory'] === null) {
         return $values;
     }
     $parent = Doctrine::getTable('sfFilebaseDirectory')->find($values['directory']);
     if ($parent->getNode()->hasChildren()) {
         foreach ($parent->getNode()->getChildren() as $file) {
             if ($file != $this->getObject() && $file->getFilename() == $filename) {
                 throw new sfValidatorError($validator, 'unique');
             }
         }
     }
     return $values;
 }
 public function checkUpload(sfValidatorCallback $validator, $values, $parameters = null)
 {
     $filename = $values['filename'];
     $validator->addMessage('unique', 'A file with that name already exists in the destinated directory.');
     $validator->addMessage('invalid', 'You are not allowed to move a directory into itself or one of its children.');
     if ($values['directory'] === null) {
         return $values;
     }
     $parent = Doctrine::getTable('sfFilebaseDirectory')->find($values['directory']);
     if ($parent->getNode()->hasChildren()) {
         foreach ($parent->getNode()->getChildren() as $file) {
             if ($file !== $this->getObject() && $file->getFilename() == $filename) {
                 throw new sfValidatorError($validator, 'unique');
             }
         }
     }
     while (true) {
         if ($parent === $this->getObject()) {
             throw new sfValidatorError($validator, 'invalid');
         }
         $parent = $parent->getNode()->getParent();
         if (!$parent) {
             break;
         }
     }
     return $values;
 }
 public function configure()
 {
     $this->setWidgets(array('user' => new sfWidgetFormInputText(), 'repository' => new sfWidgetFormInputText()));
     $this->setValidators(array('user' => new sfValidatorString(), 'repository' => new sfValidatorString()));
     $c = new sfValidatorCallback(array('callback' => array($this, 'doValidate')));
     $c->addOption('execute-if-passed', true);
     $this->validatorSchema->setPostValidator($c);
 }
 public function configure()
 {
     $this->setWidgets(array('url' => new sfWidgetFormInput()));
     $this->setValidators(array('url' => new ForgeValidatorGitHubUrl(array(), array('required' => 'Please provide an URL', 'invalid' => 'GitHub URL could not be parsed'))));
     $c = new sfValidatorCallback(array('callback' => array($this, 'doValidate')));
     $c->addOption('execute-if-passed', true);
     $this->validatorSchema->setPostValidator($c);
 }
 public function configure()
 {
     $this->setWidgets(array('id' => new sfWidgetFormInput()));
     $validatorCallback = new sfValidatorCallback(array('callback' => array($this, 'checkCommunityId')));
     $validatorCallback->addMessage('already_default', 'This community is already the default.');
     $validator = new sfValidatorAnd(array(new sfValidatorInteger(), $validatorCallback));
     $this->setValidators(array('id' => $validator));
     $this->widgetSchema->setNameFormat('community[%s]');
 }
 public function configure()
 {
     $this->setWidgets(array('author' => new sfWidgetFormInputText(), 'arbitrarySections' => new sfWidgetFormInputText(), 'stabletag' => new sfWidgetFormInputText(), 'screenshots' => new sfWidgetFormInputText(), 'category' => new sfWidgetFormInputText(), 'tags' => new sfWidgetFormInputText(), 'title' => new sfWidgetFormInputText(), 'screenshot' => new sfWidgetFormInputText(), 'docsurl' => new sfWidgetFormInputText(), 'demourl' => new sfWidgetFormInputText(), 'howtouse' => new sfWidgetFormInputText(), 'description' => new sfWidgetFormInputText()));
     $catsCriteria = new Criteria();
     $catsCriteria->add(TermPeer::CATEGORY, true);
     $this->setValidators(array('author' => sfConfig::get('sf_environment') == 'dev' ? new sfValidatorPass() : new sfValidatorPropelChoice(array('model' => 'Author', 'column' => 'username', 'required' => true), array('required' => 'The "author:" field in package.yml is required', 'invalid' => 'Please provide a valid username in the "author:" field of your package.yml')), 'arbitrarySections' => new sfValidatorPass(), 'stabletag' => new sfValidatorPass(), 'screenshots' => new sfValidatorPass(), 'gitTags' => new sfValidatorPass(), 'category' => new sfValidatorPropelChoice(array('model' => 'Term', 'criteria' => $catsCriteria, 'column' => 'title', 'required' => true), array('invalid' => '"%value%" is not a valid category. Please check your package.yml.')), 'tags' => new sfValidatorPass(), 'title' => new sfValidatorString(array('max_length' => 255, 'required' => true), array('required' => 'A plugin name is required. Check your package.yml for the \'name\' key')), 'screenshot' => new sfValidatorUrl(array('required' => false), array('invalid' => 'The <a href="%value%">screenshot</a> in README.md is not a valid URL')), 'docsurl' => new sfValidatorUrl(array('required' => false), array('invalid' => 'The "docs:" field in package.yml is not a valid URL')), 'demourl' => new sfValidatorUrl(array('required' => false), array('invalid' => 'The "demo:" field in package.yml is not a valid URL')), 'howtouse' => new sfValidatorString(array('required' => true), array('required' => 'A "How to Use" section is required in your README.md')), 'description' => new sfValidatorString(array('required' => true), array('required' => 'A description is required in your README.md'))));
     $c = new sfValidatorCallback(array('callback' => array($this, 'doValidate')));
     $c->addOption('execute-if-passed', true);
     $this->validatorSchema->setPostValidator($c);
 }
 /**
  * DOCUMENT ME
  */
 public function configure()
 {
     for ($i = 0; $i < aMediaTools::getOption('batch_max'); $i++) {
         $uploadImageForm = new aMediaUploadForm();
         $this->embedForm("item-{$i}", $uploadImageForm);
     }
     $this->widgetSchema->setNameFormat('a_media_items[%s]');
     $atLeastOne = new sfValidatorCallback(array('callback' => array($this, 'atLeastOne')));
     $atLeastOne->addMessage('at_least_one', 'You must upload at least one item.');
     $this->validatorSchema->setPostValidator($atLeastOne);
     $this->widgetSchema->setFormFormatterName('aAdmin');
     $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('apostrophe');
 }
 public function configure()
 {
     $this->disableLocalCSRFProtection();
     $this->setWidget('mail_address', new sfWidgetFormInputText());
     $this->setValidator('mail_address', new sfValidatorPass());
     $callback = new sfValidatorCallback(array('callback' => array($this, 'validate')));
     $callback->setMessage('invalid', 'invalid e-mail address');
     $this->validatorSchema->setPostValidator($callback);
     if (sfConfig::get('op_is_use_captcha', false)) {
         $this->embedForm('captcha', new opCaptchaForm());
     }
     $this->widgetSchema->setNameFormat('request_register_url[%s]');
 }
 public function configure()
 {
     $this->setWidget('mail_address', new sfWidgetFormInput());
     $this->setValidator('mail_address', new sfValidatorPass());
     if ($this->getOption('invited')) {
         $this->setWidget('message', new sfWidgetFormTextarea());
         $this->setValidator('message', new sfValidatorPass());
         $this->widgetSchema->setLabel('message', 'Message(Arbitrary)');
     }
     $callback = new sfValidatorCallback(array('callback' => array($this, 'validate')));
     $callback->setMessage('invalid', 'invalid e-mail address');
     $this->validatorSchema->setPostValidator($callback);
 }
 public function setup()
 {
     parent::setup();
     unset($this['id']);
     unset($this['community_id']);
     unset($this['member_id']);
     unset($this['created_at']);
     unset($this['updated_at']);
     unset($this['event_updated_at']);
     $dateParam = array('culture' => sfContext::getInstance()->getUser()->getCulture(), 'month_format' => 'number', 'can_be_empty' => true);
     $this->setWidget('name', new sfWidgetFormInput());
     $this->setWidget('open_date', new opWidgetFormDate($dateParam));
     $this->setWidget('application_deadline', new opWidgetFormDate($dateParam));
     $this->setWidget('open_date_comment', new sfWidgetFormInput());
     $this->setWidget('area', new sfWidgetFormInput());
     $this->setValidator('name', new opValidatorString(array('rtrim' => true)));
     $this->setValidator('body', new opValidatorString(array('rtrim' => true)));
     $this->setValidator('area', new opValidatorString(array('rtrim' => true)));
     $this->setValidator('open_date_comment', new sfValidatorString(array('required' => false)));
     $this->setValidator('application_deadline', new sfValidatorDate(array('required' => false, 'min' => strtotime(date('Y-m-d'))), array('min' => 'The date must be after now.')));
     $this->setValidator('capacity', new sfValidatorInteger(array('required' => false, 'max' => 2147483647, 'min' => 0), array('invalid' => 'Invalid.', 'max' => 'Invalid.', 'min' => 'Invalid.')));
     $validatorOpenDate = new sfValidatorCallback(array('callback' => array($this, 'validateOpenDate')));
     $this->mergePostValidator($validatorOpenDate);
     $validatorApplicationDeadline = new sfValidatorCallback(array('callback' => array($this, 'validateApplicationDeadline')));
     $validatorApplicationDeadline->addMessage('invalid_application_deadline', 'The application deadline must be before the open date.');
     $this->mergePostValidator($validatorApplicationDeadline);
     if (opMobileUserAgent::getInstance()->getMobile()->isNonMobile()) {
         $images = array();
         if (!$this->isNew()) {
             $images = $this->getObject()->getImages();
         }
         $max = (int) sfConfig::get('app_community_topic_max_image_file_num', 3);
         for ($i = 0; $i < $max; $i++) {
             $key = 'photo_' . ($i + 1);
             if (isset($images[$i])) {
                 $image = $images[$i];
             } else {
                 $image = new CommunityEventImage();
                 $image->setCommunityEvent($this->getObject());
                 $image->setNumber($i + 1);
             }
             $imageForm = new opCommunityTopicPluginImageForm($image);
             $imageForm->getWidgetSchema()->setFormFormatterName('list');
             $this->embedForm($key, $imageForm, '<ul id="community_event_' . $key . '">%content%</ul>');
         }
     }
     $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('community_event_form');
 }
Example #12
0
 public function configure()
 {
     $this->setWidget('mail_address', new sfWidgetFormInputText());
     $this->setValidator('mail_address', new sfValidatorPass());
     if ($this->getOption('invited')) {
         $this->setWidget('message', new sfWidgetFormTextarea());
         $this->setValidator('message', new sfValidatorPass());
         $this->widgetSchema->setLabel('message', 'Message(Arbitrary)');
     }
     $callback = new sfValidatorCallback(array('callback' => array($this, 'validate')));
     $callback->setMessage('invalid', 'invalid e-mail address');
     $this->validatorSchema->setPostValidator($callback);
     if (sfConfig::get('op_is_use_captcha', false)) {
         $this->embedForm('captcha', new opCaptchaForm());
     }
     if ('mobile_frontend' === sfConfig::get('sf_app')) {
         opToolkit::appendMobileInputModeAttributesForFormWidget($this->getWidget('mail_address'), 'alphabet');
     }
 }
}
// __construct()
$t->diag('__construct()');
try {
    new sfValidatorCallback();
    $t->fail('__construct() throws an RuntimeException if you don\'t pass a callback option');
} catch (RuntimeException $e) {
    $t->pass('__construct() throws an RuntimeException if you don\'t pass a callback option');
}
$v = new sfValidatorCallback(array('callback' => 'clean_test'));
// ->configure()
$t->diag('->configure()');
$t->is($v->clean(''), null, '->configure() switch required to false by default');
// ->clean()
$t->diag('->clean()');
$t->is($v->clean('foo'), '*foo*', '->clean() calls our validator callback');
try {
    $v->clean('bar');
    $t->fail('->clean() throws a sfValidatorError');
    $t->skip('', 1);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws a sfValidatorError');
    $t->is($e->getCode(), 'must_be_foo', '->clean() throws a sfValidatorError');
}
$t->diag('callback with arguments');
$v = new sfValidatorCallback(array('callback' => 'clean_test', 'arguments' => array('fabien', 'symfony')));
$t->is($v->clean('foo'), '*foo*fabien-symfony', '->configure() can take an arguments option');
// ->asString()
$t->diag('->asString()');
$v = new sfValidatorCallback(array('callback' => 'clean_test'));
$t->is($v->asString(), 'Callback({ callback: clean_test })', '->asString() returns a string representation of the validator');