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

5 years ago
5 years ago
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Admin;
  4. use Sonata\AdminBundle\Admin\AbstractAdmin;
  5. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  6. use Sonata\AdminBundle\Datagrid\ListMapper;
  7. use Sonata\AdminBundle\Form\FormMapper;
  8. use Sonata\AdminBundle\Show\ShowMapper;
  9. use Sonata\Form\Type\DatePickerType;
  10. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  11. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  12. use Symfony\Component\Form\Extension\Core\Type\CountryType;
  13. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  14. use Symfony\Component\Form\Extension\Core\Type\LocaleType;
  15. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  16. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  17. use Symfony\Component\Form\Extension\Core\Type\TelType;
  18. use Symfony\Component\Form\Extension\Core\Type\TextType;
  19. use Vich\UploaderBundle\Form\Type\VichImageType;
  20. final class ServicioAdmin extends UserAdmin
  21. {
  22. public function getExportFields()
  23. {
  24. $exportFields = [
  25. 'ID' => 'id',
  26. $this->trans('label.exportar.name') => 'getNombreCompleto',
  27. $this->trans('label.exportar.company_name') => 'company_name',
  28. $this->trans('label.exportar.email') => 'email',
  29. $this->trans('label.exportar.phone') => 'phone',
  30. $this->trans('label.exportar.address') => 'address',
  31. $this->trans('label.exportar.country') => 'getCountryFromLocale',
  32. $this->trans('label.exportar.website') => 'website',
  33. $this->trans('label.exportar.legal_status') => 'legal_status',
  34. $this->trans('label.exportar.convocatorias') => 'getConvocatoriasAsString',
  35. $this->trans('label.exportar.trainers') => 'getTrainersAsString'
  36. ];
  37. return $exportFields;
  38. }
  39. public function getExportFormats(): array
  40. {
  41. return ['csv', 'json','xls'];
  42. }
  43. protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
  44. {
  45. $datagridMapper
  46. ->add('firstname')
  47. ->add('lastname')
  48. ->add('username')
  49. ->add('company_name')
  50. ->add('email')
  51. ->add('phone')
  52. ->add('website')
  53. ->add('legal_status')
  54. ->add('activities')
  55. ->add('convocatoria')
  56. ->add('trainer')
  57. ->add('enabled')
  58. ;
  59. }
  60. protected function configureListFields(ListMapper $listMapper): void
  61. {
  62. $authChecker = $this->getConfigurationPool()->getContainer()->get('security.authorization_checker');
  63. if($authChecker->isGranted('ROLE_EDITOR')){
  64. $listMapper
  65. ->add('locale');
  66. }
  67. $listMapper
  68. ->add('nombreCompleto')
  69. ->add('company_name')
  70. ->add('email')
  71. ->add('phone')
  72. ->add('website')
  73. ->add('legal_status')
  74. ->add('enabled',null, array('editable' => true))
  75. ->add('_action', null, [
  76. 'actions' => [
  77. // 'show' => [],
  78. 'edit' => [],
  79. 'delete' => [],
  80. ],
  81. ]);
  82. if ($this->isGranted('ROLE_ALLOWED_TO_SWITCH')) {
  83. $listMapper
  84. ->add('impersonating', 'string', ['template' => '@SonataUser/Admin/Field/impersonating.html.twig'])
  85. ;
  86. }
  87. }
  88. private function getLegalStatusList()
  89. {
  90. return [
  91. 'Public Institution'=>'public',
  92. 'Private Company'=>'private',
  93. 'Non-profit Organization'=>'ong',
  94. ];
  95. }
  96. public function getActivitiesList(){
  97. return [
  98. 'Business Model Development'=>'bmd',
  99. 'Business Plan Development'=>'bpd',
  100. 'Mentoring and coaching'=>'mentor',
  101. 'Technical Assistance'=>'tech',
  102. 'Incubation'=>'incubation',
  103. 'Acceleration'=>'acceleration',
  104. 'Network development'=>'network',
  105. 'Access to Market Support'=>'ams',
  106. 'Access to Finance Support'=>'afs',
  107. 'Financing and Investment'=>'finance',
  108. 'Pursue enabling policies'=>'policies',
  109. ];
  110. }
  111. protected function configureFormFields(FormMapper $formMapper): void
  112. {
  113. $now = new \DateTime();
  114. $genderOptions = [
  115. 'choices' => $this->subject->getGenderList(),
  116. 'translation_domain' => 'registration',
  117. ];
  118. $legalStatus = [
  119. 'label'=>'Legal Status',
  120. 'choices' => $this->getLegalStatusList(),
  121. 'required' => true,
  122. 'translation_domain' => 'registration',
  123. ];
  124. $activities= [
  125. 'label'=>'Main activities in support of entrepreneurs',
  126. 'choices' => $this->getActivitiesList(),
  127. 'required' => true,
  128. 'multiple'=>true,
  129. 'translation_domain' => 'registration',
  130. ];
  131. $formMapper
  132. ->with('Bussiness Data', ['class' => 'col-md-4', 'translation_domain' => 'registration'])
  133. ->add('company_name', null, [
  134. 'label' => 'Name of the organization',
  135. 'translation_domain' => 'registration'
  136. ])
  137. ->add('locale', CountryType::class, [
  138. 'label' => 'Country',
  139. 'translation_domain' => 'registration'
  140. ])
  141. ->add('address', null, [
  142. 'label' => 'Address',
  143. 'translation_domain' => 'registration'
  144. ])
  145. ->add('website', null, [
  146. 'label' => 'Website',
  147. 'translation_domain' => 'registration'
  148. ])
  149. ->add('legal_status', ChoiceType::class, $legalStatus)
  150. /* ->add('dateOfBirth', DatePickerType::class, [
  151. 'label' => 'bussines.creation.date',
  152. 'years' => range(1900, $now->format('Y')),
  153. 'dp_min_date' => '1-1-1900',
  154. 'dp_max_date' => $now->format('c'),
  155. 'required' => false,
  156. 'translation_domain' => 'registration'
  157. ])*/
  158. ->end()
  159. ->with('Contact Data', ['class' => 'col-md-4', 'translation_domain' => 'registration'])
  160. ->add('firstname', TextType::class, [
  161. 'label' => 'form.firstname',
  162. 'invalid_message' => 'Solo se permite letras en este campo.',
  163. 'attr' => [
  164. 'pattern' => '(^[0-9A-Za-zÀ-ÿ\u0027\u00f1\u00d1\s]+$)',
  165. 'title'=>'Solo se permite letras'
  166. ],
  167. 'translation_domain' => 'registration'
  168. ])
  169. ->add('lastname', TextType::class, [
  170. 'label' => 'form.lastname',
  171. 'invalid_message' => 'Solo se permite letras en este campo.',
  172. 'attr' => [
  173. 'pattern' => '(^[0-9A-Za-zÀ-ÿ\u0027\u00f1\u00d1\s]+$)',
  174. 'title'=>'Solo se permite letras'
  175. ],
  176. 'translation_domain' => 'registration'
  177. ])
  178. ->add('phone', TelType::class, [
  179. 'required' => false,
  180. 'help' => 'help.form.phone',
  181. 'translation_domain' => 'registration',
  182. 'attr' => [
  183. 'pattern' => '([0-9]+)',
  184. 'title'=>'help.form.phone'
  185. ]
  186. ]
  187. )
  188. ->add('activities', ChoiceType::class, $activities)
  189. ->add('specific_programs',null , ['label'=>'The organization has specific programmes/activities for sustainable entrepreneurship', 'translation_domain' => 'registration'])
  190. ->end()
  191. ->with('User Data', ['class' => 'col-md-4', 'translation_domain' => 'registration'])
  192. ->add('username', TextType::class, [
  193. 'label' => 'form.username',
  194. 'translation_domain' => 'registration'
  195. ])
  196. ->add('photoFile', VichImageType::class, [
  197. 'download_label' => false,
  198. 'required' => (!$this->getSubject() || null === $this->getSubject()->getId()),
  199. 'translation_domain' => 'registration'
  200. ])
  201. ->add('email',EmailType::class, [
  202. 'label' => 'form.email',
  203. 'translation_domain' => 'registration'
  204. ])
  205. ->add('plainPassword', RepeatedType::class, [
  206. 'type' => PasswordType::class,
  207. 'invalid_message' => 'The password fields must match.',
  208. 'options' => [
  209. 'attr' => ['class' => 'password-field'],
  210. ],
  211. 'required' => (!$this->getSubject() || null === $this->getSubject()->getId()),
  212. 'first_options' => [
  213. 'label' => 'form.password',
  214. 'translation_domain' => 'registration'
  215. ],
  216. 'second_options' => [
  217. 'label' => 'form.password.repeat',
  218. 'translation_domain' => 'registration'
  219. ]
  220. ])
  221. ;
  222. }
  223. protected function configureShowFields(ShowMapper $showMapper): void
  224. {
  225. $showMapper
  226. ->add('company_name')
  227. ->add('email')
  228. ->add('legal_status')
  229. ;
  230. }
  231. }