Created
October 26, 2010 14:16
-
-
Save tyx/646970 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ValidatePlaceNumberCollectionForm extends sfForm | |
{ | |
/** | |
* @see sfForm | |
*/ | |
public function configure() | |
{ | |
if (!$place = $this->getOption('place')) | |
{ | |
throw new InvalidArgumentException('You must provide a place object.'); | |
} | |
$required = $this->getOption('required'); | |
// Init | |
$defaultTypeNumber = array(1,1,3); | |
$numbers = array( | |
new PlaceNumber, | |
new PlaceNumber, | |
new PlaceNumber | |
); | |
// Hydrate with current values | |
$accueilNumbers = $place->getAllAccueilTel(); | |
if (isset($accueilNumbers[0])) | |
{ | |
$numbers[0] = $accueilNumbers[0]; | |
} | |
if (isset($accueilNumbers[1])) | |
{ | |
$numbers[1] = $accueilNumbers[1]; | |
} | |
$fax = $place->getFirstAccueilFax(); | |
if (null != $fax) | |
{ | |
$numbers[2] = $fax; | |
} | |
// Embedding forms | |
foreach ($numbers as $i => $n) | |
{ | |
$n->Place = $place; | |
$nForm = new ValidatePlaceNumberForm($n); | |
$nForm->setDefault('type_number_id', $defaultTypeNumber[$i]); | |
if (null !== $required && in_array($i, $required)) | |
{ | |
$nForm->validatorSchema['number']->setOption('required', true); | |
} | |
$this->embedForm($i, $nForm); | |
} | |
$this->mergePostValidator(new PlaceNumberValidatorSchema()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ValidatePlaceNumberForm extends PlaceNumberForm | |
{ | |
/** | |
* @see sfForm | |
*/ | |
public function configure() | |
{ | |
parent::configure(); | |
$this->widgetSchema['private'] = new sfWidgetFormInputHidden(); | |
$this->widgetSchema['type_number_id'] = new sfWidgetFormInputHidden(); | |
$this->widgetSchema['place_id'] = new sfWidgetFormInputText(); | |
$this->useFields(array( | |
'number', | |
'type_number_id', | |
'private' | |
)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ValidatePlaceTempForm extends PlaceForm | |
{ | |
/** | |
* @see sfForm | |
*/ | |
public function configure() | |
{ | |
parent::configure(); | |
$this->useFields(array( | |
'name', | |
'types_list', | |
'website_url', | |
'capacity', | |
'type_deposit_id', | |
'deposit_amount', | |
'comment', | |
'price' | |
)); | |
// Widgets Init | |
$this->widgetSchema['types_list'] = new sfWidgetFormDoctrineChoice(array( | |
'model' => 'TypePlace', | |
'table_method' => 'getPrincipal', | |
'add_empty' => true | |
)); | |
// Embed Forms | |
$formNumbers = new ValidatePlaceNumberCollectionForm(null, array( | |
'place' => $this->getObject() | |
)); | |
$this->embedForm('PlaceNumber', $formNumbers); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AdminPlaceTempForm extends PlaceTempForm | |
{ | |
/** | |
* @see sfForm | |
*/ | |
public function configure() | |
{ | |
parent::configure(); | |
if (!$embedClass = $this->getOption('embed')) | |
{ | |
$embedClass = 'ValidatePlaceTempForm'; | |
} | |
$this->object->Place = $this->object->getLinkPlace(); | |
$formPlace = new $embedClass($this->object->Place); | |
$this->embedForm('Place', $formPlace); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment