|
- <?php
-
- namespace Lc\PietroBundle\Controller\Workshop;
-
- use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
- use Lc\PietroBundle\Controller\AbstractAdminController;
- use Lc\PietroBundle\Model\Workshop\EntryInterface;
- use Lc\SovBundle\Generator\CsvGenerator;
- use Lc\SovBundle\Repository\RepositoryQueryInterface;
- use Symfony\Component\HttpFoundation\Request;
-
- abstract class WorkshopAdminController extends AbstractAdminController
- {
- public function createEntity(string $entityFqcn)
- {
- return $this->getWorkshopContainer()->getFactory()->create();
- }
-
- public function getRepositoryQuery(): RepositoryQueryInterface
- {
- return $this->getWorkshopContainer()->getRepositoryQuery();
- }
-
- public function configureFields(string $pageName): iterable
- {
- return $this->getWorkshopContainer()->getFieldDefinition()->getFields($pageName);
- }
-
- public function configureActions(Actions $actions): Actions
- {
- parent::configureActions($actions);
-
- $export = Action::new('export', 'actions.export')
- ->setIcon('fa fa-download')
- ->linkToCrudAction('exportCsv')
- //->setCssClass('in-dropdown')
- ->setCssClass('btn btn-sm btn-secondary export-csv')
- ->createAsGlobalAction()
- ;
-
- return $actions->add(Crud::PAGE_INDEX, $export);
- }
-
- public function exportCsv(Request $request)
- {
- $csv = new CsvGenerator();
- $csv->enableConvertEncoding('ISO-8859-1');
- $csv->setTitle('Export_Adresses_Email', false);
-
- $columns = [
- 'lastname' => 'Nom',
- 'firstname' => 'Prénom',
- 'email' => 'Email',
- 'phone' => 'Téléphone',
- 'animator' => 'Animateur'
- ];
- $csv->setColumns($columns);
- $csv->emptyRow();
-
- $workshopArray = $this->getWorkshopContainer()->getStore()->get();
-
- foreach ($workshopArray as $workshop) {
- $data = [
- 'lastname' => '> '.$workshop->getTitle(),
- 'firstname' => '',
- 'email' => '',
- 'phone' => '',
- 'animator' => ''
- ];
- $csv->row($data);
-
- foreach($this->getWorkshopContainer()->getSolver()->getEntriesAnimators($workshop) as $entry) {
- $this->addEntryExportCsv($csv, $entry, true);
- }
-
- foreach($this->getWorkshopContainer()->getSolver()->getEntriesRegistered($workshop) as $entry) {
- $this->addEntryExportCsv($csv, $entry, false);
- }
-
- $csv->emptyRow();
- }
-
- return $csv->getReponse();
- }
-
- public function addEntryExportCsv($csv, EntryInterface $entry)
- {
- $data = [
- 'lastname' => $entry->getLastname(),
- 'firstname' => $entry->getFirstname(),
- 'email' => $entry->getEmail(),
- 'phone' => $entry->getPhone(),
- 'animator' => $entry->isAnimator() ? 'Oui' : ''
- ];
-
- $csv->row($data);
- }
- }
|