root/trunk/lib/form/shared/BaseConnectionForm.class.php

Revision 75, 2.0 kB (checked in by nperriault, 5 months ago)

[1.1]:

  • Companies and people modules migrated, with according form classes and templates, and functional test suite
  • Enhanced SymfoniansTestBrowser?
Line 
1 <?php
2 /**
3  * Base form class to represent a connection between two resources. In the
4  * Symfonians app, these resources connection can be between:
5  *
6  *  - an Application and a Company
7  *  - an Application and a sfGuardUser
8  *  - a sfGuardUser and a Company
9  *
10  * Provided fields are:
11  *
12  *  - role:       the role of the resource which is connected to the other one
13  *  - started at: the date the connection started
14  *  - ended_at:   the date the connection stopped
15  *
16  * Typical use is to merge a new instance of this form object with one of your
17  * form, not by extending it. This way you'll have the provided widgets and
18  * validators available in your own form. By example:
19  *
20  *     class myForm extends sfForm
21  *     {
22  *       public function configure()
23  *       {
24  *         $this->mergeForm(new BaseConnectionForm());
25  *       }
26  *     }
27  *
28  * @package form
29  */
30 class BaseConnectionForm extends sfForm
31 {
32   /**
33    * Form configuration
34    *
35    */
36   public function setup()
37   {
38     $years = range(date('Y') - 5, date('Y'));
39     $years = array_combine($years, $years);
40     $dateConfig = array('culture' => sfContext::getInstance()->getUser()->getCulture(),
41                         'years'   => $years);
42
43     // Widgets
44     $this->setWidgets(array(
45       'role'        => new sfWidgetFormInput(),
46       'description' => new sfWidgetFormTextarea(),
47       'started_at'  => new sfWidgetFormI18nDate($dateConfig),
48       'ended_at'    => new sfWidgetFormI18nDate($dateConfig),
49     ));
50
51     // Validators
52     $this->setValidators(array(
53       'role'        => new sfValidatorString(array('max_length' => 255, 'required' => true)),
54       'description' => new sfValidatorString(array('max_length' => 65535, 'required' => false)),
55       'started_at'  => new sfValidatorDate(array('required' => false)),
56       'ended_at'    => new sfValidatorDate(array('required' => false)),
57     ));
58
59     $this->validatorSchema->setPostValidator(new sfValidatorSchemaTimeInterval('started_at', 'ended_at'));
60
61     $this->widgetSchema->setNameFormat('connection[%s]');
62   }
63 }
Note: See TracBrowser for help on using the browser.