Last active
August 29, 2015 14:07
-
-
Save mlimaloureiro/096782619b63c3373e1b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
namespace Uniplaces\AccommodationBundle\AccommodationProvider\Form; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | |
/** | |
* AccommodationProviderLinkContactType | |
*/ | |
class AccommodationProviderLinkContactType extends AbstractType | |
{ | |
const CONTACT_PREFERRED_METHOD_EMAIL = 'email'; | |
const CONTACT_PREFERRED_METHOD_PHONE = 'phone'; | |
const CONTACT_PREFERRED_METHOD_SKYPE = 'skype'; | |
const CONTACT_PREFERRED_TIME_WORK_HOURS = 'work_hours'; | |
const CONTACT_PREFERRED_TIME_WEEKDAYS = 'weekdays'; | |
const CONTACT_PREFERRED_TIME_WEEKDAYS_EVENINGS = 'weekday_evenings'; | |
const CONTACT_PREFERRED_TIME_WEEKEND = 'weekend'; | |
const CONTACT_PREFERRED_TIME_HOLIDAYS = 'holidays'; | |
const CONTACT_REASON_ACCOUNTING = 'accounting'; | |
const CONTACT_REASON_SALES = 'sales'; | |
const CONTACT_REASON_BOOKINGS = 'bookings'; | |
const CONTACT_REASON_LISTINGS = 'listings'; | |
/** | |
* {@inheritdoc} | |
* | |
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | |
*/ | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$builder | |
->add( | |
'id', | |
'text', | |
[ | |
'label' => 'accommodation_provider.labels.link_contacts.id' | |
] | |
) | |
->add( | |
'preferred_methods', | |
'collection', | |
[ | |
'type' => 'choice', | |
'label' => 'accommodation_provider.labels.link_contacts.preferred_methods', | |
'property_path' => 'preferredMethods', | |
'allow_add' => true, | |
'allow_delete' => true, | |
'options' => [ | |
'choices' => $this->getStaticOptions('preferred_methods'), | |
'expanded' => true, | |
'multiple' => true | |
] | |
] | |
) | |
->add( | |
'preferred_times', | |
'collection', | |
[ | |
'type' => 'choice', | |
'label' => 'accommodation_provider.labels.link_contacts.preferred_times', | |
'property_path' => 'preferredTimes', | |
'allow_add' => true, | |
'allow_delete' => true, | |
'options' => [ | |
'choices' => $this->getStaticOptions('preferred_times'), | |
] | |
] | |
) | |
->add( | |
'reasons', | |
'collection', | |
[ | |
'type' => 'choice', | |
'label' => 'accommodation_provider.labels.link_contacts.reasons', | |
'allow_add' => true, | |
'allow_delete' => true, | |
'property_path' => 'reasons', | |
'options' => [ | |
'choices' => $this->getStaticOptions('reasons'), | |
] | |
] | |
); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function setDefaultOptions(OptionsResolverInterface $resolver) | |
{ | |
// @codingStandardsIgnoreStart | |
$resolver->setDefaults( | |
[ | |
'data_class' => 'Uniplaces\AccommodationBundle\AccommodationProvider\TransferObject\AccommodationProviderLinkContactTransferObject' | |
] | |
); | |
// @codingStandardsIgnoreEnd | |
} | |
/** | |
* @param $type | |
* | |
* @return array | |
*/ | |
private function getStaticOptions($type) | |
{ | |
$choices['preferred_methods'] = [ | |
self::CONTACT_PREFERRED_METHOD_EMAIL => 'accommodation_provider.labels.preferred_contact_methods.email', | |
self::CONTACT_PREFERRED_METHOD_PHONE => 'accommodation_provider.labels.preferred_contact_methods.phone', | |
self::CONTACT_PREFERRED_METHOD_SKYPE => 'accommodation_provider.labels.preferred_contact_methods.skype' | |
]; | |
$choices['preferred_times'] = [ | |
self::CONTACT_PREFERRED_TIME_WORK_HOURS => | |
'accommodation_provider.labels.preferred_contact_times.work_hours', | |
self::CONTACT_PREFERRED_TIME_WEEKDAYS => 'accommodation_provider.labels.preferred_contact_times.weekdays', | |
self::CONTACT_PREFERRED_TIME_WEEKDAYS_EVENINGS => | |
'accommodation_provider.labels.preferred_contact_times.weekdays_evenings', | |
self::CONTACT_PREFERRED_TIME_WEEKEND => 'accommodation_provider.labels.preferred_contact_times.weekend', | |
self::CONTACT_PREFERRED_TIME_HOLIDAYS => 'accommodation_provider.labels.preferred_contact_times.holidays' | |
]; | |
$choices['reasons'] = [ | |
self::CONTACT_REASON_ACCOUNTING => 'accommodation_provider.labels.reasons.accounting', | |
self::CONTACT_REASON_SALES => 'accommodation_provider.labels.reasons.sales', | |
self::CONTACT_REASON_BOOKINGS => 'accommodation_provider.labels.reasons.bookings', | |
self::CONTACT_REASON_LISTINGS => 'accommodation_provider.labels.reasons.listings' | |
]; | |
return $choices[$type]; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getName() | |
{ | |
return 'accommodation_provider_link_contact'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment