/**
  * Setup the form.  To overload, you should use ->configure()
  */
 public function setup()
 {
     $widgetSchema = new sfWidgetFormSchema(array('query' => new sfWidgetFormInput()), array(), array(), array(), array());
     $widgetSchema->addFormFormatter('sfLuceneSimple', new sfLuceneWidgetFormatterSimple($widgetSchema));
     $widgetSchema->setFormFormatterName('sfLuceneSimple');
     $widgetSchema->setNameFormat('form[%s]');
     $validatorSchema = new sfValidatorSchema(array('query' => new sfValidatorString(array('required' => true)), 'page' => new sfValidatorInteger(array('required' => false, 'empty_value' => 1))), array(), array());
     if ($this->hasCategories()) {
         $widgetSchema['category'] = new sfWidgetFormSelect(array('choices' => $this->getCategories(), 'multiple' => false));
         $validatorSchema['category'] = new sfValidatorChoice(array('required' => false, 'choices' => $this->getCategories()));
     }
     $this->setWidgetSchema($widgetSchema);
     $this->setValidatorSchema($validatorSchema);
 }
 public function setup()
 {
     $this->enablePlugins('sfPropelORMPlugin');
     $this->enablePlugins('sfGuardPlugin');
     $this->enablePlugins('sfLESSPlugin');
     sfWidgetFormSchema::setDefaultFormFormatterName('div');
 }
  public function configure()
  {

    // SET DEFAULT FORM-FORMATTER
    sfWidgetFormSchema::setDefaultFormFormatterName('bootstrap');
    
  }
 public function execute($filterChain)
 {
     $context = $this->getContext();
     $request = $context->getRequest();
     if (jfPortableDevice::isPortableDevice()) {
         $layout = isset(self::$_layout) ? self::$_layout : $this->getParameter('layout');
         $context->getActionStack()->getFirstEntry()->getActionInstance()->setLayout($layout);
         if (class_exists('sfWidgetFormSchema')) {
             // compatibility with symfony 1.0
             sfWidgetFormSchema::setDefaultFormFormatterName($this->getParameter('defaultFormFormatterName', 'jfPD'));
         }
         jfPortableDevice::setPageAttribute('data-url', $request->getUri());
     }
     $filterChain->execute();
     if (jfPortableDevice::isPortableDevice()) {
         if (jfPortableDevice::getConfig('lazyLoadImages')) {
             $response = $context->getResponse();
             $content = $response->getContent();
             $content = preg_replace('/(<img.*)(src=)([\'|\\"].*>)/', '$1data-jfPD-src=$3', $content);
             $response->setContent($content);
         }
         if (jfPortableDevice::isNativeApp()) {
             sfConfig::set('sf_web_debug', false);
         }
     }
 }
 public function setup()
 {
     $this->enablePlugins('sfDoctrinePlugin');
     $this->enablePlugins('sfThumbnailPlugin');
     $this->enablePlugins('sfImageTransformPlugin');
     $this->enablePlugins('sfFormExtraPlugin');
     sfWidgetFormSchema::setDefaultFormFormatterName('list');
 }
 public function configure()
 {
     // Cookie settings for increased security
     ini_set('session.use_only_cookies', "1");
     ini_set('session.cookie_httponly', "1");
     ProjectConfiguration::getActive()->loadHelpers(array('I18N', 'OrangeDate', 'Orange', 'Url'));
     sfWidgetFormSchema::setDefaultFormFormatterName('Default');
 }
 public function setup()
 {
     sfWidgetFormSchema::setDefaultFormFormatterName('list');
     $this->culture = $this->getOption('culture', sfConfig::get('sf_default_culture'));
     $this->JQueryDateOptions['culture'] = substr($this->culture, 0, 2);
     $this->JQueryDateOptions['image'] = $this->getImagePath('icons/calendar.png');
     $startYear = sfConfig::get('app_year_range_start', date('Y') - 5);
     $years = range($startYear, date('Y') + 5);
     $this->JQueryDateOptions['years'] = array_combine($years, $years);
 }
 public function initialize()
 {
     parent::initialize();
     if (!opMobileUserAgent::getInstance()->isCookie()) {
         ini_set('session.use_only_cookies', 0);
         ini_set('session.use_cookies', 0);
         ini_set('session.use_trans_sid', 1);
     }
     sfWidgetFormSchema::setDefaultFormFormatterName('mobile');
 }
  public function configure()
  {

    // SET DEFAULT FORM-FORMATTER
    /* sfWidgetFormSchema::setDefaultFormFormatterName('bootstrap'); */    
    sfWidgetFormSchema::setDefaultFormFormatterName('foundation');

    ProjectConfiguration::getActive()->loadHelpers( array('I18N') ); 

  }
 public function setup()
 {
     $this->enablePlugins('sfDoctrinePlugin');
     $this->enablePlugins('sfDoctrineGuardPlugin');
     $this->enablePlugins('ioMenuPlugin');
     $this->enablePlugins('sfFormExtraPlugin');
     $this->enablePlugins('sfDoctrineApplyPlugin');
     $this->enablePlugins('sfTCPDFPlugin');
     $this->enablePlugins('sfTaskExtraPlugin');
     $this->enablePlugins('sfZurbFoundationPlugin');
     //// changing webDir if on donax
     if (@$_SERVER['HTTP_HOST'] == 'otokou.donax.ch') {
         $this->setWebDir($this->getRootDir() . '/..');
     }
     $this->enablePlugins('sfJqueryReloadedPlugin');
     // defines the default schema formatter for forms
     sfWidgetFormSchema::setDefaultFormFormatterName('otokou');
 }
 /**
  * Setup the form.  To overload, you should use ->configure()
  */
 public function setup()
 {
     $widgetSchema = new sfWidgetFormSchema(array('keywords' => new sfWidgetFormInput(), 'musthave' => new sfWidgetFormInput(), 'mustnothave' => new sfWidgetFormInput(), 'hasphrase' => new sfWidgetFormInput()), array(), array(), array('keywords' => 'May contain keywords', 'musthave' => 'Must contain keywords', 'mustnothave' => 'Must exclude keywords', 'hasphrase' => 'Contains exact phrase'), array());
     $widgetSchema->addFormFormatter('sfLuceneAdvanced', new sfLuceneWidgetFormatterAdvanced($widgetSchema));
     $widgetSchema->setFormFormatterName('sfLuceneAdvanced');
     $widgetSchema->setNameFormat('form[%s]');
     $validatorSchema = new sfValidatorSchema(array('keywords' => new sfValidatorString(array('required' => false)), 'musthave' => new sfValidatorString(array('required' => false)), 'mustnothave' => new sfValidatorString(array('required' => false)), 'hasphrase' => new sfValidatorString(array('required' => false))), array(), array());
     if ($this->hasCategories()) {
         $widgetSchema['category'] = new sfWidgetFormSelect(array('choices' => $this->getCategories(), 'multiple' => false));
         $widgetSchema->setLabel('category', 'Must be in category');
         $validatorSchema['category'] = new sfValidatorChoice(array('required' => false, 'choices' => $this->getCategories()));
     }
     $this->setWidgetSchema($widgetSchema);
     $this->setValidatorSchema($validatorSchema);
 }
 /**
  * Constructor.
  *
  * @param sfWidgetFormSchema $widget      An sfWidgetFormSchema instance
  * @param integer            $count       The number of times to duplicate the widget
  * @param array              $options     An array of options
  * @param array              $attributes  An array of default HTML attributes
  * @param array              $labels      An array of HTML labels
  *
  * @see sfWidgetFormSchema
  */
 public function __construct(sfWidgetFormSchema $widget, $count, $options = array(), $attributes = array(), $labels = array())
 {
     parent::__construct(array_fill(0, $count, $widget), $options, $attributes, $labels);
 }
 /**
  * Constructor.
  *
  * @param sfWidgetFormSchema $widget     A sfWidgetFormSchema instance
  * @param string             $decorator  A decorator string
  *
  * @see sfWidgetFormSchema
  */
 public function __construct(sfWidgetFormSchema $widget, $decorator)
 {
     $this->widget = $widget;
     $this->decorator = $decorator;
     parent::__construct();
 }
 public function configure()
 {
     ProjectConfiguration::getActive()->loadHelpers(array('I18N', 'OrangeDate', 'Orange', 'Url'));
     sfWidgetFormSchema::setDefaultFormFormatterName('Default');
 }
Esempio n. 15
0
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new lime_test(31);
// widgets
$authorSchema = new sfWidgetFormSchema(array('id' => new sfWidgetFormInputHidden(), 'name' => $nameWidget = new sfWidgetFormInputText()));
$authorSchema->setNameFormat('article[author][%s]');
$schema = new sfWidgetFormSchema(array('title' => $titleWidget = new sfWidgetFormInputText(), 'author' => $authorSchema));
$schema->setNameFormat('article[%s]');
// errors
$authorErrorSchema = new sfValidatorErrorSchema(new sfValidatorString());
$authorErrorSchema->addError(new sfValidatorError(new sfValidatorString(), 'name error'), 'name');
$articleErrorSchema = new sfValidatorErrorSchema(new sfValidatorString());
$articleErrorSchema->addError($titleError = new sfValidatorError(new sfValidatorString(), 'title error'), 'title');
$articleErrorSchema->addError($authorErrorSchema, 'author');
$parent = new sfFormFieldSchema($schema, null, 'article', array('title' => 'symfony', 'author' => array('name' => 'Fabien')), $articleErrorSchema);
$f = $parent['title'];
$child = $parent['author'];
// ->getValue() ->getWidget() ->getParent() ->getError() ->hasError()
$t->diag('->getValue() ->getName() ->getWidget() ->getParent() ->getError() ->hasError()');
$t->ok($f->getWidget() == $titleWidget, '->getWidget() returns the form field widget');
$t->is($f->getName(), 'title', '->getName() returns the form field name');
$t->is($f->getValue(), 'symfony', '->getValue() returns the form field value');
$t->is($f->getParent(), $parent, '->getParent() returns the form field parent');
try {
    $f->setTranslationCallable('foo');
    $t->fail('setTranslationCallable() does not throw InvalidException when i18n callable is invalid');
} catch (InvalidArgumentException $e) {
    $t->pass('setTranslationCallable() throws InvalidException if i18n callable is not a valid callable');
} catch (Exception $e) {
    $t->fail('setTranslationCallable() throws unexpected exception');
}
$t->diag('->translate()');
$f = new MyFormatter(new sfWidgetFormSchema());
$t->is($f->translate('label'), '[label]', 'translate() call i18n sfCallable as expected');
MyFormatter::setTranslationCallable(array('myI18n', '__'));
$t->is($f->translate('label'), '[label]', 'translate() call i18n callable as expected');
$t->diag('->generateLabel() ->generateLabelName() ->setLabel() ->setLabels()');
MyFormatter::dropTranslationCallable();
$w = new sfWidgetFormSchema(array('author_id' => new sfWidgetFormInputText(), 'first_name' => new sfWidgetFormInputText(), 'last_name' => new sfWidgetFormInputText()));
$f = new MyFormatter($w);
$t->is($f->generateLabelName('first_name'), 'First Name', '->generateLabelName() generates a label value from a label name');
$t->is($f->generateLabelName('author_id'), 'Author', '->generateLabelName() removes _id from auto-generated labels');
$w->setLabels(array('first_name' => 'The first name'));
$t->is($f->generateLabelName('first_name'), 'The first name', '->setLabels() changes all current labels');
$w->setLabel('first_name', 'A first name');
$t->is($f->generateLabelName('first_name'), 'A first name', '->setLabel() sets a label value');
$w->setLabel('first_name', false);
$t->is($f->generateLabel('first_name'), '', '->generateLabel() returns an empty string if the label is false');
$w->setLabel('first_name', 'Your First Name');
$t->is($f->generateLabel('first_name'), '<label for="first_name">Your First Name</label>', '->generateLabelName() returns a label tag');
$t->is($f->generateLabel('first_name', array('class' => 'foo')), '<label class="foo" for="first_name">Your First Name</label>', '->generateLabelName() returns a label tag with optional HTML attributes');
$t->is($f->generateLabel('first_name', array('for' => 'myid')), '<label for="myid">Your First Name</label>', '->generateLabelName() returns a label tag with specified for-id');
$w->setLabel('last_name', 'Your Last Name');
$t->is($f->generateLabel('last_name'), '<label for="last_name">Your Last Name</label>', '->generateLabelName() returns a label tag');
{
    public $translateSubjects = array();
    public function __construct()
    {
    }
    public function translate($subject, $parameters = array())
    {
        $this->translateSubjects[] = $subject;
        return sprintf('translation[%s]', $subject);
    }
}
class WidgetFormStub extends sfWidget
{
    public function __construct()
    {
    }
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        return sprintf('##%s##', __CLASS__);
    }
}
$t = new lime_test(2);
// ->render()
$t->diag('->render()');
$ws = new sfWidgetFormSchema();
$ws->addFormFormatter('stub', $formatter = new FormFormatterMock());
$ws->setFormFormatterName('stub');
$w = new sfWidgetFormDateRange(array('from_date' => new WidgetFormStub(), 'to_date' => new WidgetFormStub()));
$w->setParent($ws);
$t->is($w->render('foo'), 'translation[from ##WidgetFormStub## to ##WidgetFormStub##]', '->render() remplaces %from_date% and %to_date%');
$t->is($formatter->translateSubjects, array('from %from_date% to %to_date%'), '->render() translates the template option');
Esempio n. 18
0
}
try {
    $parent['title'] = null;
    $t->fail('sfFormField implements the ArrayAccess interface but in read-only mode');
} catch (LogicException $e) {
    $t->pass('sfFormField implements the ArrayAccess interface but in read-only mode');
}
try {
    $parent['title1'];
    $t->fail('sfFormField implements the ArrayAccess interface but in read-only mode');
} catch (LogicException $e) {
    $t->pass('sfFormField implements the ArrayAccess interface but in read-only mode');
}
// implements Countable
$t->diag('implements Countable');
$widgetSchema = new sfWidgetFormSchema(array('w1' => $w1 = new sfWidgetFormInputText(), 'w2' => $w2 = new sfWidgetFormInputText()));
$f = new sfFormFieldSchema($widgetSchema, null, 'article', array());
$t->is(count($f), 2, 'sfFormFieldSchema implements the Countable interface');
// implements Iterator
$t->diag('implements Iterator');
$f = new sfFormFieldSchema($widgetSchema, null, 'article', array());
$values = array();
foreach ($f as $name => $value) {
    $values[$name] = $value;
}
$t->is(isset($values['w1']), true, 'sfFormFieldSchema implements the Iterator interface');
$t->is(isset($values['w2']), true, 'sfFormFieldSchema implements the Iterator interface');
$t->is(count($values), 2, 'sfFormFieldSchema implements the Iterator interface');
$t->diag('implements Iterator respecting the order of fields');
$widgetSchema->moveField('w2', 'first');
$f = new sfFormFieldSchema($widgetSchema, null, 'article', array());
Esempio n. 19
0
// ->render()
$t->diag('->render()');
$w = new sfWidgetFormChoice(array('choices' => array('foo' => 'bar')));
$t->like($w->render('foo'), '/<select name="foo" id="foo">/', '->render() renders a select tag by default');
$w->setIdFormat('barID_%s');
$t->like($w->render('foo'), '/<select name="foo" id="barID_foo">/', '->render() uses the id format specified');
$w->setIdFormat('%s');
$w->setOption('multiple', true);
$t->like($w->render('foo'), '/<select name="foo\\[\\]" multiple="multiple" id="foo">/', '->render() adds a multiple attribute for multiple selects');
$w->setOption('expanded', true);
$t->like($w->render('foo'), '/<ul class="checkbox_list">/', '->render() uses a checkbox list when expanded and multiple are true');
$w->setOption('multiple', false);
$t->like($w->render('foo'), '/<ul class="radio_list">/', '->render() uses a checkbox list when expanded is true and multiple is false');
// choices are translated
$t->diag('choices are translated');
$ws = new sfWidgetFormSchema();
$ws->addFormFormatter('stub', new FormFormatterStub());
$ws->setFormFormatterName('stub');
$w = new sfWidgetFormChoice(array('choices' => array('foo' => 'bar', 'foobar' => 'foo')));
$w->setParent($ws);
$dom->loadHTML($w->render('foo'));
$css = new sfDomCssSelector($dom);
$t->is($css->matchSingle('#foo option[value="foo"]')->getValue(), 'translation[bar]', '->render() translates the options');
$t->is($css->matchSingle('#foo option[value="foobar"]')->getValue(), 'translation[foo]', '->render() translates the options');
// ->getJavaScripts() ->getStylesheets()
$t->diag('->getJavaScripts() ->getStylesheets()');
$w = new sfWidgetFormChoice(array('choices' => array()));
$w->setOption('renderer_class', 'MyWidget');
$t->is($w->getJavaScripts(), array('/path/to/a/file.js'), '->getJavaScripts() returns the stylesheets of the renderer widget');
$t->is($w->getStylesheets(), array('/path/to/a/file.css' => 'all'), '->getStylesheets() returns the JavaScripts of the renderer widget');
// __clone()
Esempio n. 20
0
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new lime_test(26, new lime_output_color());
// widgets
$authorSchema = new sfWidgetFormSchema(array('id' => new sfWidgetFormInputHidden(), 'name' => $nameWidget = new sfWidgetFormInput()));
$authorSchema->setNameFormat('article[author][%s]');
$schema = new sfWidgetFormSchema(array('title' => $titleWidget = new sfWidgetFormInput(), 'author' => $authorSchema));
$schema->setNameFormat('article[%s]');
// errors
$authorErrorSchema = new sfValidatorErrorSchema(new sfValidatorString());
$authorErrorSchema->addError(new sfValidatorError(new sfValidatorString(), 'name error'), 'name');
$articleErrorSchema = new sfValidatorErrorSchema(new sfValidatorString());
$articleErrorSchema->addError($titleError = new sfValidatorError(new sfValidatorString(), 'title error'), 'title');
$articleErrorSchema->addError($authorErrorSchema, 'author');
$parent = new sfFormFieldSchema($schema, null, 'article', array('title' => 'symfony', 'author' => array('name' => 'Fabien')), $articleErrorSchema);
$f = $parent['title'];
$child = $parent['author'];
// ->getValue() ->getWidget() ->getParent() ->getError() ->hasError()
$t->diag('->getValue() ->getName() ->getWidget() ->getParent() ->getError() ->hasError()');
$t->ok($f->getWidget() == $titleWidget, '->getWidget() returns the form field widget');
$t->is($f->getName(), 'title', '->getName() returns the form field name');
$t->is($f->getValue(), 'symfony', '->getValue() returns the form field value');
$t->is($f->getParent(), $parent, '->getParent() returns the form field parent');
 public function configure()
 {
     sfWidgetFormSchema::setDefaultFormFormatterName('TwitterBootstrap');
 }
 public function configure()
 {
     $this->with_group = false;
     $this->useFields(array('gtu_code', 'gtu_from_date', 'gtu_to_date', 'taxon_level_ref', 'litho_name', 'litho_level_ref', 'litho_level_name', 'chrono_name', 'chrono_level_ref', 'chrono_level_name', 'lithology_name', 'lithology_level_ref', 'lithology_level_name', 'mineral_name', 'mineral_level_ref', 'mineral_level_name', 'ig_num', 'acquisition_category', 'acquisition_date'));
     $this->addPagerItems();
     $this->widgetSchema['gtu_code'] = new sfWidgetFormInputText();
     $this->widgetSchema['expedition_name'] = new sfWidgetFormInputText(array(), array('class' => 'medium_size'));
     $this->widgetSchema['taxon_name'] = new sfWidgetFormInputText(array(), array('class' => 'medium_size taxon_name'));
     $this->widgetSchema['taxon_level_ref'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'CatalogueLevels', 'table_method' => array('method' => 'getLevelsByTypes', 'parameters' => array(array('table' => 'taxonomy'))), 'add_empty' => $this->getI18N()->__('All')), array('class' => 'taxon_name'));
     $rel = array('child' => 'Is a Child Of', 'direct_child' => 'Is a Direct Child', 'synonym' => 'Is a Synonym Of', 'equal' => 'Is strictly equal to');
     $this->widgetSchema['taxon_relation'] = new sfWidgetFormChoice(array('choices' => $rel, 'expanded' => true));
     $this->widgetSchema['taxon_relation']->setDefault('child');
     $this->widgetSchema['taxon_item_ref'] = new widgetFormCompleteButtonRef(array('model' => 'Taxonomy', 'method' => 'getName', 'link_url' => 'taxonomy/choose', 'box_title' => $this->getI18N()->__('Choose Taxon'), 'button_is_hidden' => true, 'complete_url' => 'catalogue/completeName?table=taxonomy&level=1', 'nullable' => true, 'field_to_clean_class' => 'taxon_name'), array('class' => 'taxon_autocomplete'));
     $this->widgetSchema['taxon_child_syn_included'] = new WidgetFormInputCheckboxDarwin();
     $this->widgetSchema['taxon_child_syn_included']->setOption('label', 'Syn. included ?');
     $this->validatorSchema['taxon_item_ref'] = new sfValidatorInteger(array('required' => false));
     $this->validatorSchema['taxon_relation'] = new sfValidatorChoice(array('required' => false, 'choices' => array_keys($rel)));
     $this->validatorSchema['taxon_child_syn_included'] = new sfValidatorBoolean();
     $this->widgetSchema['lithology_relation'] = new sfWidgetFormChoice(array('choices' => $rel, 'expanded' => true));
     $this->widgetSchema['lithology_relation']->setDefault('child');
     $this->widgetSchema['lithology_item_ref'] = new widgetFormCompleteButtonRef(array('model' => 'Lithology', 'link_url' => 'lithology/choose', 'method' => 'getName', 'box_title' => $this->getI18N()->__('Choose Lithologic unit'), 'button_is_hidden' => true, 'complete_url' => 'catalogue/completeName?table=lithology', 'nullable' => true, 'field_to_clean_class' => 'lithology_name'), array('class' => 'lithology_autocomplete'));
     $this->widgetSchema['lithology_child_syn_included'] = new WidgetFormInputCheckboxDarwin();
     $this->widgetSchema['lithology_child_syn_included']->setOption('label', 'Syn. included ?');
     $this->validatorSchema['lithology_item_ref'] = new sfValidatorInteger(array('required' => false));
     $this->validatorSchema['lithology_relation'] = new sfValidatorChoice(array('required' => false, 'choices' => array_keys($rel)));
     $this->validatorSchema['lithology_child_syn_included'] = new sfValidatorBoolean();
     $this->widgetSchema['lithology_name'] = new sfWidgetFormInputText(array(), array('class' => 'medium_size lithology_name'));
     $this->widgetSchema['lithology_level_ref'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'CatalogueLevels', 'table_method' => array('method' => 'getLevelsByTypes', 'parameters' => array(array('table' => 'lithology'))), 'add_empty' => $this->getI18N()->__('All')), array('class' => 'lithology_name'));
     $this->widgetSchema['litho_name'] = new sfWidgetFormInputText(array(), array('class' => 'medium_size litho_name'));
     $this->widgetSchema['litho_level_ref'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'CatalogueLevels', 'table_method' => array('method' => 'getLevelsByTypes', 'parameters' => array(array('table' => 'lithostratigraphy'))), 'add_empty' => $this->getI18N()->__('All')), array('class' => 'litho_name'));
     $this->widgetSchema['litho_relation'] = new sfWidgetFormChoice(array('choices' => $rel, 'expanded' => true));
     $this->widgetSchema['litho_relation']->setDefault('child');
     $this->widgetSchema['litho_item_ref'] = new widgetFormCompleteButtonRef(array('model' => 'Lithostratigraphy', 'link_url' => 'lithostratigraphy/choose', 'method' => 'getName', 'box_title' => $this->getI18N()->__('Choose Lithostratigraphic unit'), 'button_is_hidden' => true, 'complete_url' => 'catalogue/completeName?table=lithostratigraphy', 'nullable' => true, 'field_to_clean_class' => 'litho_name'), array('class' => 'litho_autocomplete'));
     $this->widgetSchema['litho_child_syn_included'] = new WidgetFormInputCheckboxDarwin();
     $this->widgetSchema['litho_child_syn_included']->setOption('label', 'Syn. included ?');
     $this->validatorSchema['litho_item_ref'] = new sfValidatorInteger(array('required' => false));
     $this->validatorSchema['litho_relation'] = new sfValidatorChoice(array('required' => false, 'choices' => array_keys($rel)));
     $this->validatorSchema['litho_child_syn_included'] = new sfValidatorBoolean();
     $this->widgetSchema['chrono_name'] = new sfWidgetFormInputText(array(), array('class' => 'medium_size chrono_name'));
     $this->widgetSchema['chrono_level_ref'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'CatalogueLevels', 'table_method' => array('method' => 'getLevelsByTypes', 'parameters' => array(array('table' => 'chronostratigraphy'))), 'add_empty' => $this->getI18N()->__('All')), array('class' => 'chrono_name'));
     $this->widgetSchema['chrono_relation'] = new sfWidgetFormChoice(array('choices' => $rel, 'expanded' => true));
     $this->widgetSchema['chrono_relation']->setDefault('child');
     $this->widgetSchema['chrono_item_ref'] = new widgetFormCompleteButtonRef(array('model' => 'Chronostratigraphy', 'link_url' => 'chronostratigraphy/choose', 'method' => 'getName', 'box_title' => $this->getI18N()->__('Choose Chronostratigraphic unit'), 'nullable' => true, 'button_is_hidden' => true, 'complete_url' => 'catalogue/completeName?table=chronostratigraphy', 'button_class' => '', 'field_to_clean_class' => 'chrono_name'), array('class' => 'chrono_autocomplete'));
     $this->widgetSchema['chrono_child_syn_included'] = new WidgetFormInputCheckboxDarwin();
     $this->widgetSchema['chrono_child_syn_included']->setOption('label', 'Syn. included ?');
     $this->validatorSchema['chrono_item_ref'] = new sfValidatorInteger(array('required' => false));
     $this->validatorSchema['chrono_relation'] = new sfValidatorChoice(array('required' => false, 'choices' => array_keys($rel)));
     $this->validatorSchema['chrono_child_syn_included'] = new sfValidatorBoolean();
     $this->widgetSchema['mineral_name'] = new sfWidgetFormInputText(array(), array('class' => 'medium_size mineral_name'));
     $this->widgetSchema['mineral_level_ref'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'CatalogueLevels', 'table_method' => array('method' => 'getLevelsByTypes', 'parameters' => array(array('table' => 'mineralogy'))), 'add_empty' => $this->getI18N()->__('All')), array('class' => 'mineral_name'));
     $this->widgetSchema['mineral_item_ref'] = new widgetFormCompleteButtonRef(array('model' => 'Mineralogy', 'link_url' => 'mineralogy/choose', 'method' => 'getName', 'box_title' => $this->getI18N()->__('Choose Mineralogic unit'), 'nullable' => true, 'button_is_hidden' => true, 'complete_url' => 'catalogue/completeName?table=mineralogy', 'button_class' => '', 'field_to_clean_class' => 'mineral_name'), array('class' => 'mineral_autocomplete'));
     $this->widgetSchema['mineral_child_syn_included'] = new WidgetFormInputCheckboxDarwin();
     $this->widgetSchema['mineral_child_syn_included']->setOption('label', 'Syn. included ?');
     $this->widgetSchema['mineral_relation'] = new sfWidgetFormChoice(array('choices' => $rel, 'expanded' => true));
     $this->widgetSchema['mineral_relation']->setDefault('child');
     $this->validatorSchema['mineral_item_ref'] = new sfValidatorInteger(array('required' => false));
     $this->validatorSchema['mineral_relation'] = new sfValidatorChoice(array('required' => false, 'choices' => array_keys($rel)));
     $this->validatorSchema['mineral_child_syn_included'] = new sfValidatorBoolean();
     $minDate = new FuzzyDateTime(strval(min(range(intval(sfConfig::get('dw_yearRangeMin')), intval(sfConfig::get('dw_yearRangeMax')))) . '/01/01'));
     $maxDate = new FuzzyDateTime(strval(max(range(intval(sfConfig::get('dw_yearRangeMin')), intval(sfConfig::get('dw_yearRangeMax')))) . '/12/31'));
     $maxDate->setStart(false);
     $dateLowerBound = new FuzzyDateTime(sfConfig::get('dw_dateLowerBound'));
     $dateUpperBound = new FuzzyDateTime(sfConfig::get('dw_dateUpperBound'));
     $this->widgetSchema['ig_num'] = new sfWidgetFormInputText();
     $this->widgetSchema['ig_from_date'] = new widgetFormJQueryFuzzyDate($this->getDateItemOptions(), array('class' => 'from_date'));
     $this->widgetSchema['ig_to_date'] = new widgetFormJQueryFuzzyDate($this->getDateItemOptions(), array('class' => 'to_date'));
     $this->widgetSchema['ig_num']->setAttributes(array('class' => 'small_size'));
     $this->validatorSchema['ig_num'] = new sfValidatorString(array('required' => false, 'trim' => true));
     $this->validatorSchema['ig_from_date'] = new fuzzyDateValidator(array('required' => false, 'from_date' => true, 'min' => $minDate, 'max' => $maxDate, 'empty_value' => $dateLowerBound), array('invalid' => 'Date provided is not valid'));
     $this->validatorSchema['ig_to_date'] = new fuzzyDateValidator(array('required' => false, 'from_date' => false, 'min' => $minDate, 'max' => $maxDate, 'empty_value' => $dateUpperBound), array('invalid' => 'Date provided is not valid'));
     $this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare('ig_from_date', '<=', 'ig_to_date', array('throw_global_error' => true), array('invalid' => 'The "begin" date cannot be above the "end" date.')));
     $this->widgetSchema['col_fields'] = new sfWidgetFormInputHidden();
     $this->widgetSchema['collection_ref'] = new sfWidgetCollectionList(array('choices' => array()));
     $this->widgetSchema['collection_ref']->addOption('public_only', false);
     $this->validatorSchema['collection_ref'] = new sfValidatorPass();
     //Avoid duplicate the query
     $this->widgetSchema['spec_ids'] = new sfWidgetFormTextarea(array('label' => "#ID list separated by ',' "));
     $this->validatorSchema['spec_ids'] = new sfValidatorString(array('required' => false, 'trim' => true));
     $this->validatorSchema['col_fields'] = new sfValidatorString(array('required' => false, 'trim' => true));
     $this->validatorSchema['gtu_code'] = new sfValidatorString(array('required' => false, 'trim' => true));
     $this->validatorSchema['expedition_name'] = new sfValidatorString(array('required' => false, 'trim' => true));
     $this->validatorSchema['taxon_name'] = new sfValidatorString(array('required' => false, 'trim' => true));
     $this->validatorSchema['taxon_level_ref'] = new sfValidatorInteger(array('required' => false));
     $this->validatorSchema['chrono_name'] = new sfValidatorString(array('required' => false, 'trim' => true));
     $this->validatorSchema['chrono_level_ref'] = new sfValidatorInteger(array('required' => false));
     $this->validatorSchema['litho_name'] = new sfValidatorString(array('required' => false, 'trim' => true));
     $this->validatorSchema['litho_level_ref'] = new sfValidatorInteger(array('required' => false));
     $this->validatorSchema['lithology_name'] = new sfValidatorString(array('required' => false, 'trim' => true));
     $this->validatorSchema['lithology_level_ref'] = new sfValidatorInteger(array('required' => false));
     $this->validatorSchema['mineral_name'] = new sfValidatorString(array('required' => false, 'trim' => true));
     $this->validatorSchema['mineral_level_ref'] = new sfValidatorInteger(array('required' => false));
     $minDate = new FuzzyDateTime(strval(min(range(intval(sfConfig::get('dw_yearRangeMin')), intval(sfConfig::get('dw_yearRangeMax')))) . '/01/01'));
     $maxDate = new FuzzyDateTime(strval(max(range(intval(sfConfig::get('dw_yearRangeMin')), intval(sfConfig::get('dw_yearRangeMax')))) . '/12/31'));
     $maxDate->setStart(false);
     $dateLowerBound = new FuzzyDateTime(sfConfig::get('dw_dateLowerBound'));
     $dateUpperBound = new FuzzyDateTime(sfConfig::get('dw_dateUpperBound'));
     $this->widgetSchema['tags'] = new sfWidgetFormInputText();
     $this->widgetSchema['gtu_from_date'] = new widgetFormJQueryFuzzyDate($this->getDateItemOptions(), array('class' => 'from_date'));
     $this->widgetSchema['gtu_to_date'] = new widgetFormJQueryFuzzyDate($this->getDateItemOptions(), array('class' => 'to_date'));
     $this->validatorSchema['tags'] = new sfValidatorString(array('required' => false, 'trim' => true));
     $this->validatorSchema['gtu_from_date'] = new fuzzyDateValidator(array('required' => false, 'from_date' => true, 'min' => $minDate, 'max' => $maxDate, 'empty_value' => $dateLowerBound), array('invalid' => 'Date provided is not valid'));
     $this->validatorSchema['gtu_to_date'] = new fuzzyDateValidator(array('required' => false, 'from_date' => false, 'min' => $minDate, 'max' => $maxDate, 'empty_value' => $dateUpperBound), array('invalid' => 'Date provided is not valid'));
     $subForm = new sfForm();
     $this->embedForm('Tags', $subForm);
     $this->widgetSchema['tools'] = new widgetFormSelectDoubleListFilterable(array('choices' => new sfCallable(array(Doctrine::getTable('CollectingTools'), 'fetchTools')), 'label_associated' => $this->getI18N()->__('Selected'), 'label_unassociated' => $this->getI18N()->__('Available')));
     $this->widgetSchema['methods'] = new widgetFormSelectDoubleListFilterable(array('choices' => new sfCallable(array(Doctrine::getTable('CollectingMethods'), 'fetchMethods')), 'label_associated' => $this->getI18N()->__('Selected'), 'label_unassociated' => $this->getI18N()->__('Available')));
     $this->validatorSchema['methods'] = new sfValidatorPass();
     $this->validatorSchema['tools'] = new sfValidatorPass();
     $this->widgetSchema['with_multimedia'] = new sfWidgetFormInputCheckbox();
     $this->validatorSchema['with_multimedia'] = new sfValidatorPass();
     //people widget
     $this->widgetSchema['people_ref'] = new widgetFormButtonRef(array('model' => 'People', 'link_url' => 'people/searchBoth', 'box_title' => $this->getI18N()->__('Choose people role'), 'nullable' => true, 'button_class' => ''), array('class' => 'inline'));
     $fields_to_search = array('spec_coll_ids' => $this->getI18N()->__('Collector'), 'spec_don_sel_ids' => $this->getI18N()->__('Donator or seller'), 'ident_ids' => $this->getI18N()->__('Identifier'));
     $this->widgetSchema['role_ref'] = new sfWidgetFormChoice(array('choices' => $fields_to_search, 'multiple' => true, 'expanded' => true));
     $this->validatorSchema['people_ref'] = new sfValidatorInteger(array('required' => false));
     $this->validatorSchema['role_ref'] = new sfValidatorChoice(array('choices' => array_keys($fields_to_search), 'required' => false));
     $this->validatorSchema['role_ref'] = new sfValidatorPass();
     /* Acquisition categories */
     $this->widgetSchema['acquisition_category'] = new sfWidgetFormChoice(array('choices' => array_merge(array('' => ''), SpecimensTable::getDistinctCategories())));
     $this->widgetSchema['acquisition_from_date'] = new widgetFormJQueryFuzzyDate($this->getDateItemOptions(), array('class' => 'from_date'));
     $this->widgetSchema['acquisition_to_date'] = new widgetFormJQueryFuzzyDate($this->getDateItemOptions(), array('class' => 'to_date'));
     $this->validatorSchema['acquisition_from_date'] = new fuzzyDateValidator(array('required' => false, 'from_date' => true, 'min' => $minDate, 'max' => $maxDate, 'empty_value' => $dateLowerBound), array('invalid' => 'Date provided is not valid'));
     $this->validatorSchema['acquisition_to_date'] = new fuzzyDateValidator(array('required' => false, 'min' => $minDate, 'from_date' => false, 'max' => $maxDate, 'empty_value' => $dateUpperBound), array('invalid' => 'Date provided is not valid'));
     /**
      * Individuals Fields
      */
     $this->widgetSchema['type'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'Specimens', 'table_method' => 'getDistinctTypeGroups', 'multiple' => true, 'expanded' => true, 'add_empty' => false));
     $this->validatorSchema['type'] = new sfValidatorPass();
     $this->widgetSchema['sex'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'Specimens', 'table_method' => 'getDistinctSexes', 'multiple' => true, 'expanded' => true, 'add_empty' => false));
     $this->validatorSchema['sex'] = new sfValidatorPass();
     $this->widgetSchema['stage'] = new widgetFormSelectDoubleListFilterable(array('choices' => new sfCallable(array(Doctrine::getTable('Specimens'), 'getDistinctStages')), 'label_associated' => $this->getI18N()->__('Selected'), 'label_unassociated' => $this->getI18N()->__('Available')));
     $this->validatorSchema['stage'] = new sfValidatorPass();
     $this->widgetSchema['status'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'Specimens', 'table_method' => 'getDistinctStates', 'multiple' => true, 'expanded' => true, 'add_empty' => false));
     $this->validatorSchema['status'] = new sfValidatorPass();
     $this->widgetSchema['specimen_status'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'Specimens', 'table_method' => 'getDistinctSpecimenStatus', 'multiple' => false, 'expanded' => false, 'add_empty' => true));
     $this->validatorSchema['specimen_status'] = new sfValidatorPass();
     $this->widgetSchema['social'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'Specimens', 'table_method' => 'getDistinctSocialStatuses', 'multiple' => true, 'expanded' => true, 'add_empty' => false));
     $this->validatorSchema['social'] = new sfValidatorPass();
     $this->widgetSchema['rockform'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'Specimens', 'table_method' => 'getDistinctRockForms', 'multiple' => true, 'expanded' => true, 'add_empty' => false));
     $this->validatorSchema['rockform'] = new sfValidatorPass();
     $this->widgetSchema['count'] = new sfWidgetFormInput();
     $this->widgetSchema['count']->setAttributes(array('class' => 'vsmall_size'));
     $this->validatorSchema['count'] = new sfValidatorString(array('required' => false));
     $operators = array('' => '', 'e' => '=', 'l' => '<=', 'g' => '>=');
     $this->widgetSchema['count_operator'] = new sfWidgetFormChoice(array('choices' => $operators));
     $this->validatorSchema['count_operator'] = new sfValidatorChoice(array('required' => false, 'choices' => array_keys($operators)));
     $this->widgetSchema['container'] = new sfWidgetFormInput();
     $this->validatorSchema['container'] = new sfValidatorString(array('required' => false));
     $this->widgetSchema['sub_container'] = new sfWidgetFormInput();
     $this->validatorSchema['sub_container'] = new sfValidatorString(array('required' => false));
     $this->validatorSchema['part'] = new sfValidatorString(array('required' => false));
     $this->widgetSchema['part'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'Specimens', 'table_method' => 'getDistinctParts', 'add_empty' => true));
     $this->widgetSchema['object_name'] = new sfWidgetFormInput();
     $this->validatorSchema['object_name'] = new sfValidatorString(array('required' => false));
     $this->validatorSchema['floor'] = new sfValidatorString(array('required' => false));
     $this->widgetSchema['institution_ref'] = new widgetFormButtonRef(array('model' => 'Institutions', 'link_url' => 'institution/choose?with_js=1', 'method' => 'getFamilyName', 'box_title' => $this->getI18N()->__('Choose Institution'), 'nullable' => true));
     $this->widgetSchema['institution_ref']->setLabel('Institution');
     $this->validatorSchema['institution_ref'] = new sfValidatorInteger(array('required' => false));
     $this->widgetSchema['building'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'Specimens', 'table_method' => 'getDistinctBuildings', 'add_empty' => true));
     $this->validatorSchema['building'] = new sfValidatorString(array('required' => false));
     $this->widgetSchema['floor'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'Specimens', 'table_method' => 'getDistinctFloors', 'add_empty' => true));
     $this->validatorSchema['floor'] = new sfValidatorString(array('required' => false));
     $this->widgetSchema['row'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'Specimens', 'table_method' => 'getDistinctRows', 'add_empty' => true));
     $this->validatorSchema['row'] = new sfValidatorString(array('required' => false));
     $this->widgetSchema['col'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'Specimens', 'table_method' => 'getDistinctCols', 'add_empty' => true));
     $this->validatorSchema['col'] = new sfValidatorString(array('required' => false));
     $this->widgetSchema['room'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'Specimens', 'table_method' => 'getDistinctRooms', 'add_empty' => true));
     $this->validatorSchema['room'] = new sfValidatorString(array('required' => false));
     $this->widgetSchema['shelf'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'Specimens', 'table_method' => 'getDistinctShelfs', 'add_empty' => true));
     $this->validatorSchema['shelf'] = new sfValidatorString(array('required' => false));
     $this->widgetSchema['property_type'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'Properties', 'table_method' => array('method' => 'getDistinctType', 'parameters' => array('specimens')), 'add_empty' => $this->getI18N()->__('All')));
     $this->validatorSchema['property_type'] = new sfValidatorString(array('required' => false));
     $this->widgetSchema['property_applies_to'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'Properties', 'table_method' => array('method' => 'getDistinctApplies', 'parameters' => array()), 'add_empty' => $this->getI18N()->__('All')));
     $this->validatorSchema['property_applies_to'] = new sfValidatorString(array('required' => false));
     $this->widgetSchema['property_value_from'] = new sfWidgetFormInput();
     $this->validatorSchema['property_value_from'] = new sfValidatorString(array('required' => false));
     $this->widgetSchema['property_value_to'] = new sfWidgetFormInput();
     $this->validatorSchema['property_value_to'] = new sfValidatorString(array('required' => false));
     $this->widgetSchema['property_units'] = new sfWidgetFormDarwinDoctrineChoice(array('model' => 'Properties', 'table_method' => array('method' => 'getDistinctUnit', 'parameters' => array()), 'add_empty' => true));
     $this->validatorSchema['property_units'] = new sfValidatorString(array('required' => false));
     $this->widgetSchema['comment'] = new sfWidgetFormInput();
     $this->validatorSchema['comment'] = new sfValidatorString(array('required' => false));
     $comment_choices = array('' => '');
     $comment_choices = $comment_choices + CommentsTable::getNotionsFor('specimens');
     $this->widgetSchema['comment_notion_concerned'] = new sfWidgetFormChoice(array('choices' => $comment_choices));
     $this->validatorSchema['comment_notion_concerned'] = new sfValidatorChoice(array('required' => false, 'choices' => array_keys($comment_choices)));
     $subForm = new sfForm();
     $this->embedForm('Codes', $subForm);
     // LAT LON
     $this->widgetSchema['lat_from'] = new sfWidgetForminput();
     $this->widgetSchema['lat_from']->setLabel('Latitude');
     $this->widgetSchema['lat_from']->setAttributes(array('class' => 'medium_small_size'));
     $this->widgetSchema['lat_to'] = new sfWidgetForminput();
     $this->widgetSchema['lat_to']->setAttributes(array('class' => 'medium_small_size'));
     $this->widgetSchema['lon_from'] = new sfWidgetForminput();
     $this->widgetSchema['lon_from']->setLabel('Longitude');
     $this->widgetSchema['lon_from']->setAttributes(array('class' => 'medium_small_size'));
     $this->widgetSchema['lon_to'] = new sfWidgetForminput();
     $this->widgetSchema['lon_to']->setAttributes(array('class' => 'medium_small_size'));
     $this->validatorSchema['lat_from'] = new sfValidatorNumber(array('required' => false, 'min' => '-180', 'max' => '180'));
     $this->validatorSchema['lon_from'] = new sfValidatorNumber(array('required' => false, 'min' => '-360', 'max' => '360'));
     $this->validatorSchema['lat_to'] = new sfValidatorNumber(array('required' => false, 'min' => '-180', 'max' => '180'));
     $this->validatorSchema['lon_to'] = new sfValidatorNumber(array('required' => false, 'min' => '-360', 'max' => '360'));
     sfWidgetFormSchema::setDefaultFormFormatterName('list');
     $this->widgetSchema->setNameFormat('specimen_search_filters[%s]');
     /* Labels */
     $this->widgetSchema->setLabels(array('rockform' => 'Rock form', 'gtu_code' => 'Sampling Location code', 'taxon_name' => 'Taxon text search', 'litho_name' => 'Litho text search', 'lithology_name' => 'Lithology text search', 'chrono_name' => 'Chrono text search', 'mineral_name' => 'Mineralo text search', 'taxon_level_ref' => 'Level', 'code_ref_relation' => 'Code of', 'people_ref' => 'Whom are you looking for', 'role_ref' => 'Which role', 'with_multimedia' => 'Search Only objects with multimedia files', 'gtu_from_date' => 'Between', 'gtu_to_date' => 'and', 'acquisition_from_date' => 'Between', 'acquisition_to_date' => 'and', 'ig_from_date' => 'Between', 'ig_to_date' => 'and', 'ig_num' => 'I.G. unit', 'property_type' => 'Type', 'property_applies_to' => 'Applies to', 'property_value_from' => 'From', 'property_value_to' => 'To', 'property_units' => 'Unit', 'comment_notion_concerned' => 'Notion concerned'));
     // For compat only with old saved search
     // might be removed with a migration
     $this->validatorSchema['what_searched'] = new sfValidatorPass();
 }
 public function setup()
 {
     sfWidgetFormSchema::setDefaultFormFormatterName('div');
 }
Esempio n. 24
0
 /**
  * @param array $parameters
  * @return array
  */
 private function createBuildWidgetValidator($parameters)
 {
     $extraParametersWidgets = array();
     $extraParametersValidators = array();
     foreach ($parameters as $name => $parameter) {
         if (is_array($parameter['choices'])) {
             $extraParametersWidgets[$name] = new sfWidgetFormChoice(array('choices' => $this->combine($parameter['choices']), 'default' => $parameter['default']), array('label' => strlen($parameter['description']) > 0 ? $parameter['description'] : $name));
             $extraParametersValidators[$name] = new sfValidatorChoice(array('choices' => $parameter['choices']));
         } else {
             $extraParametersWidgets[$name] = new sfWidgetFormInput(array('default' => $parameter['default']), array('label' => strlen($parameter['description']) > 0 ? $parameter['description'] : $name));
             $extraParametersValidators[$name] = new sfValidatorString(array('required' => false));
         }
     }
     $widget = new sfWidgetFormSchema($extraParametersWidgets, array('label' => 'Parameters'));
     $widget->setDefaultFormFormatterName('jobParameter');
     foreach ($parameters as $name => $parameter) {
         if ($parameter['description']) {
             $widget->setHelp($name, $parameter['description']);
         }
     }
     $validator = new sfValidatorSchema($extraParametersValidators);
     return array($widget, $validator);
 }
 /**
  * Sets the generic default formatter name used by the class. If you want all
  * of your forms to be generated with the <code>list</code> format, you can
  * do it in a project or application configuration class:
  *
  * <pre>
  * class ProjectConfiguration extends sfProjectConfiguration
  * {
  *   public function setup()
  *   {
  *     sfWidgetFormSchema::setDefaultFormFormatterName('list');
  *   }
  * }
  * </pre>
  *
  * @param string $name  New default formatter name
  */
 public static function setDefaultFormFormatterName($name)
 {
     self::$defaultFormatterName = $name;
 }
Esempio n. 26
0
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new lime_test(31);
// widgets
$authorSchema = new sfWidgetFormSchema(array('id' => new sfWidgetFormInputHidden(), 'name' => $nameWidget = new sfWidgetFormInputText()));
$authorSchema->setNameFormat('article[author][%s]');
$schema = new sfWidgetFormSchema(array('title' => $titleWidget = new sfWidgetFormInputText(), 'author' => $authorSchema));
$schema->setNameFormat('article[%s]');
$titleWidget->setParent($schema);
// errors
$authorErrorSchema = new sfValidatorErrorSchema(new sfValidatorString());
$authorErrorSchema->addError(new sfValidatorError(new sfValidatorString(), 'name error'), 'name');
$articleErrorSchema = new sfValidatorErrorSchema(new sfValidatorString());
$articleErrorSchema->addError($titleError = new sfValidatorError(new sfValidatorString(), 'title error'), 'title');
$articleErrorSchema->addError($authorErrorSchema, 'author');
$parent = new sfFormFieldSchema($schema, null, 'article', array('title' => 'symfony', 'author' => array('name' => 'Fabien')), $articleErrorSchema);
$f = $parent['title'];
$child = $parent['author'];
// ->getValue() ->getWidget() ->getParent() ->getError() ->hasError()
$t->diag('->getValue() ->getName() ->getWidget() ->getParent() ->getError() ->hasError()');
$t->ok($f->getWidget() == $titleWidget, '->getWidget() returns the form field widget');
$t->is($f->getName(), 'title', '->getName() returns the form field name');
$t->is($f->getValue(), 'symfony', '->getValue() returns the form field value');
 /**
  * Config
  */
 public function configure()
 {
     sfWidgetFormSchema::setDefaultFormFormatterName('myList');
 }
// setDefaultFormFormatterName()
$t->diag('setDefaultFormFormatterName()');
$w = new sfWidgetFormSchema(array('w1' => $w1, 'w2' => $w2));
$t->isa_ok($w->getFormFormatter(), 'sfWidgetFormSchemaFormatterTable', 'setDefaultFormFormatterName() has the "sfWidgetFormSchemaFormatterTable" form formatter by default');
sfWidgetFormSchema::setDefaultFormFormatterName('list');
$w = new sfWidgetFormSchema(array('w1' => $w1, 'w2' => $w2));
$t->isa_ok($w->getFormFormatter(), 'sfWidgetFormSchemaFormatterList', 'setDefaultFormFormatterName() changes the default form formatter name correctly');
class MyWidget extends sfWidgetForm
{
    protected function configure($options = array(), $attributes = array())
    {
        $this->addRequiredOption('name');
    }
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        return null;
    }
    public function getJavaScripts()
    {
        return array('/path/to/a/' . $this->getOption('name') . '.js', '/path/to/foo.js');
    }
    public function getStylesheets()
    {
        return array('/path/to/a/' . $this->getOption('name') . '.css' => 'all', '/path/to/foo.css' => 'all');
    }
}
// ->getJavaScripts() ->getStylesheets()
$t->diag('->getJavaScripts() ->getStylesheets()');
$w = new sfWidgetFormSchema(array('foo' => new MyWidget(array('name' => 'foo')), 'bar' => new MyWidget(array('name' => 'bar'))));
$t->is($w->getJavaScripts(), array('/path/to/a/foo.js', '/path/to/foo.js', '/path/to/a/bar.js'), '->getJavaScripts() returns an array of stylesheets');
$t->is($w->getStylesheets(), array('/path/to/a/foo.css' => 'all', '/path/to/foo.css' => 'all', '/path/to/a/bar.css' => 'all'), '->getStylesheets() returns an array of JavaScripts');
 public function configure()
 {
     sfWidgetFormSchema::setDefaultFormFormatterName('list');
     $this->widgetSchema->setNameFormat('mass_action[%s]');
     $this->widgetSchema['field_action'] = new sfWidgetFormSelectCheckbox(array('choices' => self::getPossibleActions(), 'template' => '<div class="group_%group% fld_group"><label>%group%</label> %options%</div>'));
     $this->validatorSchema['field_action'] = new sfValidatorPass();
     $this->widgetSchema['item_list'] = new sfWidgetFormChoice(array('choices' => array()));
     $this->validatorSchema['item_list'] = new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Specimens', 'min' => 0));
     $subForm = new sfForm();
     $this->embedForm('MassActionForm', $subForm);
 }
 public function initialize()
 {
     parent::initialize();
     sfWidgetFormSchema::setDefaultFormFormatterName('pc');
 }