| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
class ApplicationForm extends BaseApplicationForm |
|---|
| 9 |
{ |
|---|
| 10 |
|
|---|
| 11 |
* Form configuration |
|---|
| 12 |
* |
|---|
| 13 |
*/ |
|---|
| 14 |
public function configure() |
|---|
| 15 |
{ |
|---|
| 16 |
|
|---|
| 17 |
unset($this['created_at'], |
|---|
| 18 |
$this['updated_at'], |
|---|
| 19 |
$this['slug'], |
|---|
| 20 |
$this['is_featured'], |
|---|
| 21 |
$this['screenshot_path']); |
|---|
| 22 |
|
|---|
| 23 |
$this->initWidgets(); |
|---|
| 24 |
$this->initValidators(); |
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
parent::setDefaults(array('homepage' => 'http://', |
|---|
| 28 |
'feed_url' => 'http://', |
|---|
| 29 |
'released_at' => 'today', |
|---|
| 30 |
'is_featured' => null, |
|---|
| 31 |
'is_opensource' => null)); |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
* Overrides parent doSave method to save tags for current Application object |
|---|
| 36 |
* |
|---|
| 37 |
* @param Connection $con An optional Connection object |
|---|
| 38 |
* @see doSave |
|---|
| 39 |
*/ |
|---|
| 40 |
protected function doSave($con = null) |
|---|
| 41 |
{ |
|---|
| 42 |
parent::doSave($con); |
|---|
| 43 |
|
|---|
| 44 |
$values = $this->getValues(); |
|---|
| 45 |
|
|---|
| 46 |
if (isset($values['tags'])) |
|---|
| 47 |
{ |
|---|
| 48 |
$this->getObject()->setTags($values['tags']); |
|---|
| 49 |
$this->getObject()->save($con); |
|---|
| 50 |
} |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
* Intitialize widgets |
|---|
| 55 |
* |
|---|
| 56 |
*/ |
|---|
| 57 |
public function initWidgets() |
|---|
| 58 |
{ |
|---|
| 59 |
$this->widgetSchema['tags'] = new sfWidgetFormInput(); |
|---|
| 60 |
$this->widgetSchema['country'] = new ExtendedWidgetFormI18nSelectCountry(array('culture' => $this->culture, 'add_label_option' => __('Select a country'))); |
|---|
| 61 |
$this->widgetSchema['started_at'] = new sfWidgetFormI18nDate(array('culture' => $this->culture)); |
|---|
| 62 |
$this->widgetSchema['released_at'] = new sfWidgetFormI18nDate(array('culture' => $this->culture)); |
|---|
| 63 |
$this->widgetSchema['screenshot_file'] = new sfWidgetFormInputFile(); |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
* Initialize validators |
|---|
| 68 |
* |
|---|
| 69 |
*/ |
|---|
| 70 |
public function initValidators() |
|---|
| 71 |
{ |
|---|
| 72 |
$this->validatorSchema['tags'] = new sfValidatorTags(array('separator' => ',', 'required' => false)); |
|---|
| 73 |
$this->validatorSchema['country'] = new sfValidatorI18nChoiceCountry(array('culture' => $this->culture, 'required' => false)); |
|---|
| 74 |
$this->validatorSchema['started_at'] = new sfValidatorDate(array('required' => false)); |
|---|
| 75 |
$this->validatorSchema['ended_at'] = new sfValidatorDate(array('required' => false)); |
|---|
| 76 |
$this->validatorSchema['screenshot_file'] = new sfValidatorFile(array('max_size' => 512000, |
|---|
| 77 |
'mime_types' => 'web_images', |
|---|
| 78 |
'validated_file_class' => 'sfValidatedThumb', |
|---|
| 79 |
'required' => false)); |
|---|
| 80 |
$this->validatorSchema['homepage'] = new sfValidatorOr(array( |
|---|
| 81 |
new sfValidatorUrl(), |
|---|
| 82 |
new sfValidatorChoice(array('choices' => array('http://', ''))), |
|---|
| 83 |
), array(), array('invalid' => 'This url seems to be invalid')); |
|---|
| 84 |
|
|---|
| 85 |
$this->validatorSchema['feed_url'] = new sfValidatorOr(array( |
|---|
| 86 |
new sfValidatorUrl(), |
|---|
| 87 |
new sfValidatorChoice(array('choices' => array('http://', ''))), |
|---|
| 88 |
), array(), array('invalid' => 'This feed url seems to be invalid')); |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
$this->validatorSchema->setPostValidator(new sfValidatorAnd(array( |
|---|
| 92 |
new sfValidatorOr(array( |
|---|
| 93 |
new sfValidatorSchemaFilter('homepage', new sfValidatorChoice(array('choices' => array('http://', ''), 'required' => false))), |
|---|
| 94 |
new sfValidatorPropelUnique(array('model' => 'Application', 'column' => array('homepage'))), |
|---|
| 95 |
)), |
|---|
| 96 |
new sfValidatorSchemaTimeInterval('started_at', 'released_at', array('disallow_future_dates' => true, 'throw_global_error' => false)), |
|---|
| 97 |
new sfValidatorSchemaLicence(), |
|---|
| 98 |
))); |
|---|
| 99 |
} |
|---|
| 100 |
} |
|---|