<?php
namespace App\Controller;
use App\Entity\Form;
use App\Service\CsvExporter;
use Doctrine\Common\Collections\ArrayCollection;
use Sonata\AdminBundle\Controller\CRUDController;
class FormAdminController extends CRUDController
{
/**
* @var CsvExporter
*/
private $csvExporter;
public function __construct(CsvExporter $csvExporter)
{
$this->csvExporter = $csvExporter;
}
/**
* @param $id
* @return \Symfony\Component\HttpFoundation\StreamedResponse
*/
public function customExportAction($id)
{
/** @var Form $object */
$object = $this->admin->getObject($id);
$entities = new ArrayCollection($object->getFormInputs()->toArray());
return $this->csvExporter->export($entities, $object->getEvent()->getName());
}
}