dreamStore = $dreamStore; $this->revoltStore = $revoltStore; $this->projectBoostStore = $projectBoostStore; $this->projectInspiringStore = $projectInspiringStore; } public function createEntity(string $entityFqcn) { return $this->getIndividualDataContainer()->getFactory()->create(); } public function configureFields(string $pageName): iterable { return $this->getIndividualDataContainer() ->getFieldDefinition() ->getFields($pageName); } public function getRepositoryQuery(): RepositoryQueryInterface { return $this->getIndividualDataContainer()->getRepositoryQuery(); } public function createIndexRepositoryQuery( SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters ): RepositoryQueryInterface { $repositoryQuery = parent::createIndexRepositoryQuery($searchDto, $entityDto, $fields, $filters); $status = $searchDto->getRequest()->get('status'); if ($status || $status === 0) { $repositoryQuery->filterByStatus($searchDto->getRequest()->get('status')); } return $repositoryQuery; } public function configureActions(Actions $actions): Actions { parent::configureActions($actions); $export = Action::new('export', 'actions.export') ->setIcon('fa fa-download') ->linkToCrudAction('exportCsv') ->setCssClass('btn btn-sm btn-primary 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_Liste_Individuel', true); $columns = [ 'category' => 'Catégorie', 'thematic' => 'Thématique', 'subthematic' => 'Contribution', 'territory' => 'Lieu', 'description' => 'Description' ]; $csv->setColumns($columns); $resultArray = $this->generateAllResultArray(); $csv = $this->generateCsvData($csv, $resultArray); return $csv->getReponse(); } private function generateAllResultArray(): array { $dreamArray = $this->dreamStore->get(); $revoltArray = $this->revoltStore->get(); $projectBoostArray = $this->projectBoostStore->get(); $projectInspiringArray = $this->projectInspiringStore->get(); return array_merge($dreamArray, $revoltArray, $projectBoostArray, $projectInspiringArray); } private function generateCsvData($csv, $resultArray) { foreach ($resultArray as $result) { $territory = $subthematic = $thematic = ""; if ($result->getIndividualData()) { $territory = $result->getIndividualData()->getTerritory()->getName(); if ($result->getSubthematic()) { $subthematic = $result->getSubthematic()->getName(); } if ($result->getThematic()) { $thematic = $result->getThematic()->getName(); } $data = [ 'category' => $result->__toString(), 'thematic' => $thematic, 'subthematic' => $subthematic, 'territory' => $territory, 'description' => $result->getDescription() ]; $csv->row($data); } } return $csv; } }