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.

WorkshopAdminController.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace Lc\PietroBundle\Controller\Workshop;
  3. use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
  4. use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
  5. use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
  6. use Lc\PietroBundle\Controller\AbstractAdminController;
  7. use Lc\PietroBundle\Model\Workshop\EntryInterface;
  8. use Lc\SovBundle\Generator\CsvGenerator;
  9. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  10. use Symfony\Component\HttpFoundation\Request;
  11. abstract class WorkshopAdminController extends AbstractAdminController
  12. {
  13. public function createEntity(string $entityFqcn)
  14. {
  15. return $this->getWorkshopContainer()->getFactory()->create();
  16. }
  17. public function getRepositoryQuery(): RepositoryQueryInterface
  18. {
  19. return $this->getWorkshopContainer()->getRepositoryQuery();
  20. }
  21. public function configureFields(string $pageName): iterable
  22. {
  23. return $this->getWorkshopContainer()->getFieldDefinition()->getFields($pageName);
  24. }
  25. public function configureActions(Actions $actions): Actions
  26. {
  27. parent::configureActions($actions);
  28. $export = Action::new('export', 'actions.export')
  29. ->setIcon('fa fa-download')
  30. ->linkToCrudAction('exportCsv')
  31. //->setCssClass('in-dropdown')
  32. ->setCssClass('btn btn-sm btn-secondary export-csv')
  33. ->createAsGlobalAction()
  34. ;
  35. return $actions->add(Crud::PAGE_INDEX, $export);
  36. }
  37. public function exportCsv(Request $request)
  38. {
  39. $csv = new CsvGenerator();
  40. $csv->enableConvertEncoding('ISO-8859-1');
  41. $csv->setTitle('Export_Adresses_Email', false);
  42. $columns = [
  43. 'lastname' => 'Nom',
  44. 'firstname' => 'Prénom',
  45. 'email' => 'Email',
  46. 'phone' => 'Téléphone',
  47. 'animator' => 'Animateur'
  48. ];
  49. $csv->setColumns($columns);
  50. $csv->emptyRow();
  51. $workshopArray = $this->getWorkshopContainer()->getStore()->get();
  52. foreach ($workshopArray as $workshop) {
  53. $data = [
  54. 'lastname' => '> '.$workshop->getTitle(),
  55. 'firstname' => '',
  56. 'email' => '',
  57. 'phone' => '',
  58. 'animator' => ''
  59. ];
  60. $csv->row($data);
  61. foreach($this->getWorkshopContainer()->getSolver()->getEntriesAnimators($workshop) as $entry) {
  62. $this->addEntryExportCsv($csv, $entry, true);
  63. }
  64. foreach($this->getWorkshopContainer()->getSolver()->getEntriesRegistered($workshop) as $entry) {
  65. $this->addEntryExportCsv($csv, $entry, false);
  66. }
  67. $csv->emptyRow();
  68. }
  69. return $csv->getReponse();
  70. }
  71. public function addEntryExportCsv($csv, EntryInterface $entry)
  72. {
  73. $data = [
  74. 'lastname' => $entry->getLastname(),
  75. 'firstname' => $entry->getFirstname(),
  76. 'email' => $entry->getEmail(),
  77. 'phone' => $entry->getPhone(),
  78. 'animator' => $entry->isAnimator() ? 'Oui' : ''
  79. ];
  80. $csv->row($data);
  81. }
  82. }