/**
  * @see sfValidatorBase
  */
 protected function doClean($value)
 {
     $clean = array();
     $clean['value'] = $this->getOption('validator')->clean($value['value']);
     if ($this->getOption('is_edit_public_flag')) {
         if (!isset($value['public_flag'])) {
             throw new sfValidatorError($this, 'invalid');
         }
         $validator = new sfValidatorChoice(array('choices' => array_keys($this->profile->getPublicFlags())));
         $clean['public_flag'] = $validator->clean($value['public_flag']);
     }
     return $clean;
 }
 public function __construct($options = array(), $messages = array())
 {
     if (isset($options['choices'])) {
         $options['choices'] = array_merge($options['choices'], array_keys(dmWidgetFormChoiceEasing::$easing));
     } else {
         $options['choices'] = array_keys(dmWidgetFormChoiceEasing::$easing);
     }
     parent::__construct($options, $messages);
 }
 /**
  * @see sfValidatorBase
  */
 protected function doClean($value)
 {
     $clean = array();
     $clean['value'] = $this->getOption('validator')->clean($value['value']);
     if ($this->getOption('is_edit_public_flag')) {
         if (!isset($value['public_flag'])) {
             throw new sfValidatorError($this, 'invalid');
         }
         $validator = new sfValidatorChoice(array('choices' => array_keys($this->profile->getPublicFlags())));
         $clean['public_flag'] = $validator->clean($value['public_flag']);
     }
     if ($this->profile->getIsUnique() && in_array($this->profile->getFormType(), array('input', 'textarea'))) {
         $profileId = $this->profile->getId();
         $memberId = sfContext::getInstance()->getUser()->getMemberId();
         $isDuplicate = Doctrine::getTable('MemberProfile')->isDuplicatedProfileValue($profileId, $value['value'], $memberId);
         if ($isDuplicate) {
             throw new sfValidatorError($this, 'The inputted value is already exist.');
         }
     }
     return $clean;
 }
 protected function doClean($value)
 {
     $clean = (string) $value;
     parent::doClean($clean);
     $length = function_exists('mb_strlen') ? mb_strlen($clean, $this->getCharset()) : strlen($clean);
     if ($this->hasOption('required') && $length == 0) {
         throw new sfValidatorError($this, 'required', array('value' => $value, 'required' => $this->getOption('required')));
     }
     if ($this->hasOption('max_length') && $length > $this->getOption('max_length')) {
         throw new sfValidatorError($this, 'max_length', array('value' => $value, 'max_length' => $this->getOption('max_length')));
     }
     return $clean;
 }
 public function __construct($options = array(), $attributes = array())
 {
     $choices = array();
     $modules = array();
     foreach (dmContext::getInstance()->getModuleManager()->getModules() as $module) {
         $actions = $module->getActions();
         foreach ($actions as $action) {
             $choiceName = $module->getName() . '|' . $action['name'];
             $choices[$choiceName] = $choiceName;
         }
     }
     $options['choices'] = array_combine($choices, $choices);
     parent::__construct($options, $attributes);
 }
 /**
  * Configures the current validator.
  *
  * Available options:
  *
  *  * countries: An array of country codes to use (ISO 3166)
  *
  * @param array $options   An array of options
  * @param array $messages  An array of error messages
  *
  * @see sfValidatorChoice
  */
 protected function configure($options = array(), $messages = array())
 {
     parent::configure($options, $messages);
     $this->addOption('countries');
     // populate choices with all countries
     $countries = array_keys(sfCultureInfo::getInstance()->getCountries());
     // restrict countries to a sub-set
     if (isset($options['countries'])) {
         if ($problems = array_diff($options['countries'], $countries)) {
             throw new InvalidArgumentException(sprintf('The following countries do not exist: %s.', implode(', ', $problems)));
         }
         $countries = $options['countries'];
     }
     $this->setOption('choices', $countries);
 }
 /**
  * Configures the current validator.
  *
  * Available options:
  *
  *  * culture:   The culture to use for internationalized strings (required)
  *  * languages: An array of language codes to use (ISO 639-1)
  *
  * @param array $options   An array of options
  * @param array $messages  An array of error messages
  *
  * @see sfValidatorChoice
  */
 protected function configure($options = array(), $messages = array())
 {
     parent::configure($options, $messages);
     $this->addRequiredOption('culture');
     $this->addOption('languages');
     // populate choices with all languages
     $culture = isset($options['culture']) ? $options['culture'] : 'en';
     $cultureInfo = new sfCultureInfo($culture);
     $languages = array_keys($cultureInfo->getLanguages());
     // restrict languages to a sub-set
     if (isset($options['languages'])) {
         if ($problems = array_diff($options['languages'], $languages)) {
             throw new InvalidArgumentException(sprintf('The following languages do not exist: %s.', implode(', ', $problems)));
         }
         $languages = $options['languages'];
     }
     sort($languages);
     $this->setOption('choices', $languages);
 }
 /**
  * Configures the current validator.
  *
  * @param array $options   An array of options
  * @param array $messages  An array of error messages
  *
  * @see sfValidatorChoice
  */
 protected function configure($options = array(), $messages = array())
 {
     parent::configure($options, $messages);
     // populate choices with all cultures
     $choices = array();
     $cultures = sfCultureInfo::getCultures(sfCultureInfo::SPECIFIC);
     foreach ($cultures as $culture) {
         // skip en_US_POSIX
         if ($culture == "en_US_POSIX") {
             continue;
         }
         try {
             $choices[] = sfCultureInfo::getInstance($culture)->getName();
         } catch (sfException $e) {
         }
     }
     sort($choices);
     $this->setOption('choices', $choices);
 }
 protected function doClean($value)
 {
     $choices = $this->getOption('choices');
     if ($choices instanceof sfCallable) {
         $choices = $choices->call();
     }
     if ($this->getOption('multiple')) {
         if (!is_array($value)) {
             $value = array($value);
         }
         foreach ($value as $v) {
             if (sfValidatorChoice::inChoices($v, $choices)) {
                 throw new sfValidatorError($this, 'invalid', array('value' => $v));
             }
         }
     } else {
         if (sfValidatorChoice::inChoices($value, $choices)) {
             throw new sfValidatorError($this, 'invalid', array('value' => $value));
         }
     }
     return $value;
 }
 public function getChoices()
 {
     $page_filters_ids = array();
     $page = sfPlopPagePeer::retrieveByPK($this->getOption('page_id)'));
     $q = sfPlopPageQuery::create()->filterByTreeLevel($page->getLevel() + 1);
     $page_filters = $page->getBranch($q);
     foreach ($page_filters as $page_filter) {
         $page_filters_ids[] = $page_filter->getId();
     }
     $filters = sfPlopSlotConfigQuery::create()->innerJoinsfPlopSlot()->filterByPageId($page_filters_ids)->find();
     foreach ($filters as $i => $filter) {
         if (!$filter->getTemplate() != 'GoogleMapsFilter' && !$filter->getSlot()->ispublished()) {
             unset($filters[$i]);
         }
     }
     $options_for_filter = array('' => '');
     foreach ($filters as $filter_object) {
         $options_for_filter[$filter_object->getValue($this->getOption('page_culture)'))] = $filter_object->getValue($this->getOption('page_culture)'));
     }
     $this->setOption('choices', array_keys($options_for_filter));
     return parent::getChoices();
 }
示例#11
0
// choices as a callable
$t->diag('choices as a callable');
$v = new sfValidatorChoice(array('choices' => new sfCallable('choice_callable')));
$t->is($v->clean('2'), '2', '__construct() can take a sfCallable object as a choices option');
// see bug #4212
$v = new sfValidatorChoice(array('choices' => array(0, 1, 2)));
try {
    $v->clean('xxx');
    $t->fail('->clean() throws an sfValidatorError if the value is not strictly an expected value');
    $t->skip('', 1);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws an sfValidatorError if the value is not strictly an expected value');
    $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError');
}
// min/max options
$v = new sfValidatorChoice(array('multiple' => true, 'choices' => array(0, 1, 2, 3, 4, 5), 'min' => 2, 'max' => 3));
try {
    $v->clean(array(0));
    $t->fail('->clean() throws an sfValidatorError if the minimum number of values are not selected');
    $t->skip('', 1);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws an sfValidatorError if the minimum number of values are not selected');
    $t->is($e->getCode(), 'min', '->clean() throws a sfValidatorError');
}
try {
    $v->clean(array(0, 1, 2, 3));
    $t->fail('->clean() throws an sfValidatorError if more than the maximum number of values are selected');
    $t->skip('', 1);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws an sfValidatorError if more than the maximum number of values are selected');
    $t->is($e->getCode(), 'max', '->clean() throws a sfValidatorError');
 public function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     $array = sfPlop::get('sf_plop_googlemaps_zooms');
     $this->setOption('choices', $array);
 }
    $t->skip('', 1);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws an sfValidatorError if the value is not an expected value');
    $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError');
}
try {
    $v->clean(array('foobar', 'bar'));
    $t->fail('->clean() throws an sfValidatorError if the value is not an expected value');
    $t->skip('', 1);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws an sfValidatorError if the value is not an expected value');
    $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError');
}
function choice_callable()
{
    return array(1, 2, 3);
}
// choices as a callable
$t->diag('choices as a callable');
$v = new sfValidatorChoiceMany(array('choices' => new sfCallable('choice_callable')));
$t->is($v->clean(array('2')), array('2'), '__construct() can take a sfCallable object as a choices option');
// see bug #4212
$v = new sfValidatorChoice(array('choices' => array(0, 1, 2, 3, 4, 5)));
try {
    $v->clean(array('xxx', 'yyy'));
    $t->fail('->clean() throws an sfValidatorError if the values are not strictly the expected values');
    $t->skip('', 1);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws an sfValidatorError if the values are not strictly the expected values');
    $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError');
}
 public function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     $this->setOption('choices', array());
 }
 /**
  * Configures the current validator.
  *
  * @see sfValidatorChoice
  */
 protected function configure($options = array(), $messages = array())
 {
     parent::configure($options, $messages);
     $this->setOption('multiple', true);
 }
示例#16
0
}
$v = new sfValidatorChoice(array('choices' => array('foo', 'bar')));
// ->clean()
$t->diag('->clean()');
$t->is($v->clean('foo'), 'foo', '->clean() checks that the value is an expected value');
$t->is($v->clean('bar'), 'bar', '->clean() checks that the value is an expected value');
try {
    $v->clean('foobar');
    $t->fail('->clean() throws an sfValidatorError if the value is not an expected value');
    $t->skip('', 1);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws an sfValidatorError if the value is not an expected value');
    $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError');
}
// ->asString()
$t->diag('->asString()');
$t->is($v->asString(), 'Choice({ choices: [foo, bar] })', '->asString() returns a string representation of the validator');
// choices as a callable
$t->diag('choices as a callable');
$v = new sfValidatorChoice(array('choices' => new sfCallable('choice_callable')));
$t->is($v->clean('2'), '2', '__construct() can take a sfCallable object as a choices option');
// see bug #4212
$v = new sfValidatorChoice(array('choices' => array(0, 1, 2)));
try {
    $v->clean('xxx');
    $t->fail('->clean() throws an sfValidatorError if the value is not strictly an expected value');
    $t->skip('', 1);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws an sfValidatorError if the value is not strictly an expected value');
    $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError');
}
 public function __construct($options = array(), $attributes = array())
 {
     $modules = dmContext::getInstance()->getModuleManager()->getModules();
     $options['choices'] = array_combine($modules, $modules);
     parent::__construct($options, $attributes);
 }
 /**
  * Configures the current validator.
  *
  * Available options:
  *
  * @param array $options   An array of options
  * @param array $messages  An array of error messages
  *
  * @see sfValidatorChoice
  */
 protected function configure($options = array(), $messages = array())
 {
     parent::configure($options, $messages);
     $this->setOption('choices', array_keys(sfCultureInfo::getInstance()->getTimeZones()));
 }
 protected function doClean($values)
 {
     $values = parent::doClean($values);
     return implode($this->getOption('glue'), $values);
 }