Licitator 1.0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

246 lines
9.1 KiB

<?php
declare(strict_types=1);
namespace App\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\Form\Type\DatePickerType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\LocaleType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Vich\UploaderBundle\Form\Type\VichImageType;
final class ServicioAdmin extends UserAdmin
{
public function getExportFields()
{
$exportFields = [
'ID' => 'id',
$this->trans('label.exportar.name') => 'getNombreCompleto',
$this->trans('label.exportar.company_name') => 'company_name',
$this->trans('label.exportar.email') => 'email',
$this->trans('label.exportar.phone') => 'phone',
$this->trans('label.exportar.address') => 'address',
$this->trans('label.exportar.country') => 'getCountryFromLocale',
$this->trans('label.exportar.website') => 'website',
$this->trans('label.exportar.legal_status') => 'legal_status',
$this->trans('label.exportar.convocatorias') => 'getConvocatoriasAsString',
$this->trans('label.exportar.trainers') => 'getTrainersAsString'
];
return $exportFields;
}
public function getExportFormats(): array
{
return ['csv', 'json','xls'];
}
protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
{
$datagridMapper
->add('firstname')
->add('lastname')
->add('username')
->add('company_name')
->add('email')
->add('phone')
->add('website')
->add('legal_status')
->add('activities')
->add('convocatoria')
->add('trainer')
->add('enabled')
;
}
protected function configureListFields(ListMapper $listMapper): void
{
$authChecker = $this->getConfigurationPool()->getContainer()->get('security.authorization_checker');
if($authChecker->isGranted('ROLE_EDITOR')){
$listMapper
->add('locale');
}
$listMapper
->add('nombreCompleto')
->add('company_name')
->add('email')
->add('phone')
->add('website')
->add('legal_status')
->add('enabled',null, array('editable' => true))
->add('_action', null, [
'actions' => [
// 'show' => [],
'edit' => [],
'delete' => [],
],
]);
if ($this->isGranted('ROLE_ALLOWED_TO_SWITCH')) {
$listMapper
->add('impersonating', 'string', ['template' => '@SonataUser/Admin/Field/impersonating.html.twig'])
;
}
}
private function getLegalStatusList()
{
return [
'Public Institution'=>'public',
'Private Company'=>'private',
'Non-profit Organization'=>'ong',
];
}
public function getActivitiesList(){
return [
'Business Model Development'=>'bmd',
'Business Plan Development'=>'bpd',
'Mentoring and coaching'=>'mentor',
'Technical Assistance'=>'tech',
'Incubation'=>'incubation',
'Acceleration'=>'acceleration',
'Network development'=>'network',
'Access to Market Support'=>'ams',
'Access to Finance Support'=>'afs',
'Financing and Investment'=>'finance',
'Pursue enabling policies'=>'policies',
];
}
protected function configureFormFields(FormMapper $formMapper): void
{
$now = new \DateTime();
$genderOptions = [
'choices' => $this->subject->getGenderList(),
'translation_domain' => 'registration',
];
$legalStatus = [
'label'=>'Legal Status',
'choices' => $this->getLegalStatusList(),
'required' => true,
'translation_domain' => 'registration',
];
$activities= [
'label'=>'Main activities in support of entrepreneurs',
'choices' => $this->getActivitiesList(),
'required' => true,
'multiple'=>true,
'translation_domain' => 'registration',
];
$formMapper
->with('Bussiness Data', ['class' => 'col-md-4', 'translation_domain' => 'registration'])
->add('company_name', null, [
'label' => 'Name of the organization',
'translation_domain' => 'registration'
])
->add('locale', CountryType::class, [
'label' => 'Country',
'translation_domain' => 'registration'
])
->add('address', null, [
'label' => 'Address',
'translation_domain' => 'registration'
])
->add('website', null, [
'label' => 'Website',
'translation_domain' => 'registration'
])
->add('legal_status', ChoiceType::class, $legalStatus)
/* ->add('dateOfBirth', DatePickerType::class, [
'label' => 'bussines.creation.date',
'years' => range(1900, $now->format('Y')),
'dp_min_date' => '1-1-1900',
'dp_max_date' => $now->format('c'),
'required' => false,
'translation_domain' => 'registration'
])*/
->end()
->with('Contact Data', ['class' => 'col-md-4', 'translation_domain' => 'registration'])
->add('firstname', TextType::class, [
'label' => 'form.firstname',
'invalid_message' => 'Solo se permite letras en este campo.',
'attr' => [
'pattern' => '(^[0-9A-Za-zÀ-ÿ\u0027\u00f1\u00d1\s]+$)',
'title'=>'Solo se permite letras'
],
'translation_domain' => 'registration'
])
->add('lastname', TextType::class, [
'label' => 'form.lastname',
'invalid_message' => 'Solo se permite letras en este campo.',
'attr' => [
'pattern' => '(^[0-9A-Za-zÀ-ÿ\u0027\u00f1\u00d1\s]+$)',
'title'=>'Solo se permite letras'
],
'translation_domain' => 'registration'
])
->add('phone', TelType::class, [
'required' => false,
'help' => 'help.form.phone',
'translation_domain' => 'registration',
'attr' => [
'pattern' => '([0-9]+)',
'title'=>'help.form.phone'
]
]
)
->add('activities', ChoiceType::class, $activities)
->add('specific_programs',null , ['label'=>'The organization has specific programmes/activities for sustainable entrepreneurship', 'translation_domain' => 'registration'])
->end()
->with('User Data', ['class' => 'col-md-4', 'translation_domain' => 'registration'])
->add('username', TextType::class, [
'label' => 'form.username',
'translation_domain' => 'registration'
])
->add('photoFile', VichImageType::class, [
'download_label' => false,
'required' => (!$this->getSubject() || null === $this->getSubject()->getId()),
'translation_domain' => 'registration'
])
->add('email',EmailType::class, [
'label' => 'form.email',
'translation_domain' => 'registration'
])
->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'invalid_message' => 'The password fields must match.',
'options' => [
'attr' => ['class' => 'password-field'],
],
'required' => (!$this->getSubject() || null === $this->getSubject()->getId()),
'first_options' => [
'label' => 'form.password',
'translation_domain' => 'registration'
],
'second_options' => [
'label' => 'form.password.repeat',
'translation_domain' => 'registration'
]
])
;
}
protected function configureShowFields(ShowMapper $showMapper): void
{
$showMapper
->add('company_name')
->add('email')
->add('legal_status')
;
}
}