CRUDController.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. <?php
  2. /*
  3. * This file is part of the Sonata package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\Controller;
  11. use Symfony\Component\HttpFoundation\RedirectResponse;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  14. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  15. use Symfony\Component\DependencyInjection\ContainerInterface;
  16. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  17. use Sonata\AdminBundle\Exception\ModelManagerException;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
  20. class CRUDController extends Controller
  21. {
  22. /**
  23. * The related Admin class
  24. *
  25. * @var \Sonata\AdminBundle\Admin\AdminInterface
  26. */
  27. protected $admin;
  28. /**
  29. * @param mixed $data
  30. * @param integer $status
  31. * @param array $headers
  32. *
  33. * @return Response with json encoded data
  34. */
  35. public function renderJson($data, $status = 200, $headers = array())
  36. {
  37. // fake content-type so browser does not show the download popup when this
  38. // response is rendered through an iframe (used by the jquery.form.js plugin)
  39. // => don't know yet if it is the best solution
  40. if ($this->get('request')->get('_xml_http_request')
  41. && strpos($this->get('request')->headers->get('Content-Type'), 'multipart/form-data') === 0) {
  42. $headers['Content-Type'] = 'text/plain';
  43. } else {
  44. $headers['Content-Type'] = 'application/json';
  45. }
  46. return new Response(json_encode($data), $status, $headers);
  47. }
  48. /**
  49. *
  50. * @return boolean true if the request is done by an ajax like query
  51. */
  52. public function isXmlHttpRequest()
  53. {
  54. return $this->get('request')->isXmlHttpRequest() || $this->get('request')->get('_xml_http_request');
  55. }
  56. /**
  57. * Returns the correct RESTful verb, given either by the request itself or
  58. * via the "_method" parameter.
  59. *
  60. * @return string HTTP method, either
  61. */
  62. protected function getRestMethod()
  63. {
  64. $request = $this->getRequest();
  65. if(Request::getHttpMethodParameterOverride() || !$request->request->has('_method')) {
  66. return $request->getMethod();
  67. }
  68. return $request->request->get('_method');
  69. }
  70. /**
  71. * Sets the Container associated with this Controller.
  72. *
  73. * @param ContainerInterface $container A ContainerInterface instance
  74. */
  75. public function setContainer(ContainerInterface $container = null)
  76. {
  77. $this->container = $container;
  78. $this->configure();
  79. }
  80. /**
  81. * Contextualize the admin class depends on the current request
  82. *
  83. * @throws \RuntimeException
  84. * @return void
  85. */
  86. public function configure()
  87. {
  88. $adminCode = $this->container->get('request')->get('_sonata_admin');
  89. if (!$adminCode) {
  90. throw new \RuntimeException(sprintf('There is no `_sonata_admin` defined for the controller `%s` and the current route `%s`', get_class($this), $this->container->get('request')->get('_route')));
  91. }
  92. $this->admin = $this->container->get('sonata.admin.pool')->getAdminByAdminCode($adminCode);
  93. if (!$this->admin) {
  94. throw new \RuntimeException(sprintf('Unable to find the admin class related to the current controller (%s)', get_class($this)));
  95. }
  96. $rootAdmin = $this->admin;
  97. if ($this->admin->isChild()) {
  98. $this->admin->setCurrentChild(true);
  99. $rootAdmin = $rootAdmin->getParent();
  100. }
  101. $request = $this->container->get('request');
  102. $rootAdmin->setRequest($request);
  103. if ($request->get('uniqid')) {
  104. $this->admin->setUniqid($request->get('uniqid'));
  105. }
  106. }
  107. /**
  108. * return the base template name
  109. *
  110. * @return string the template name
  111. */
  112. public function getBaseTemplate()
  113. {
  114. if ($this->isXmlHttpRequest()) {
  115. return $this->admin->getTemplate('ajax');
  116. }
  117. return $this->admin->getTemplate('layout');
  118. }
  119. /**
  120. * @param string $view
  121. * @param array $parameters
  122. * @param Response $response
  123. *
  124. * @return Response
  125. */
  126. public function render($view, array $parameters = array(), Response $response = null)
  127. {
  128. $parameters['admin'] = isset($parameters['admin']) ? $parameters['admin'] : $this->admin;
  129. $parameters['base_template'] = isset($parameters['base_template']) ? $parameters['base_template'] : $this->getBaseTemplate();
  130. $parameters['admin_pool'] = $this->get('sonata.admin.pool');
  131. return parent::render($view, $parameters);
  132. }
  133. /**
  134. * return the Response object associated to the list action
  135. *
  136. * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  137. *
  138. * @return Response
  139. */
  140. public function listAction()
  141. {
  142. if (false === $this->admin->isGranted('LIST')) {
  143. throw new AccessDeniedException();
  144. }
  145. $datagrid = $this->admin->getDatagrid();
  146. $formView = $datagrid->getForm()->createView();
  147. // set the theme for the current Admin Form
  148. $this->get('twig')->getExtension('form')->renderer->setTheme($formView, $this->admin->getFilterTheme());
  149. return $this->render($this->admin->getTemplate('list'), array(
  150. 'action' => 'list',
  151. 'form' => $formView,
  152. 'datagrid' => $datagrid
  153. ));
  154. }
  155. /**
  156. * execute a batch delete
  157. *
  158. * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  159. *
  160. * @param \Sonata\AdminBundle\Datagrid\ProxyQueryInterface $query
  161. *
  162. * @return \Symfony\Component\HttpFoundation\RedirectResponse
  163. */
  164. public function batchActionDelete(ProxyQueryInterface $query)
  165. {
  166. if (false === $this->admin->isGranted('DELETE')) {
  167. throw new AccessDeniedException();
  168. }
  169. $modelManager = $this->admin->getModelManager();
  170. try {
  171. $modelManager->batchDelete($this->admin->getClass(), $query);
  172. $this->get('session')->setFlash('sonata_flash_success', 'flash_batch_delete_success');
  173. } catch ( ModelManagerException $e ) {
  174. $this->get('session')->setFlash('sonata_flash_error', 'flash_batch_delete_error');
  175. }
  176. return new RedirectResponse($this->admin->generateUrl('list', array('filter' => $this->admin->getFilterParameters())));
  177. }
  178. /**
  179. * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException|\Symfony\Component\Security\Core\Exception\AccessDeniedException
  180. *
  181. * @param mixed $id
  182. *
  183. * @return Response|RedirectResponse
  184. */
  185. public function deleteAction($id)
  186. {
  187. $id = $this->get('request')->get($this->admin->getIdParameter());
  188. $object = $this->admin->getObject($id);
  189. if (!$object) {
  190. throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
  191. }
  192. if (false === $this->admin->isGranted('DELETE', $object)) {
  193. throw new AccessDeniedException();
  194. }
  195. if ($this->getRestMethod() == 'DELETE') {
  196. try {
  197. $this->admin->delete($object);
  198. $this->get('session')->setFlash('sonata_flash_success', 'flash_delete_success');
  199. } catch (ModelManagerException $e) {
  200. $this->get('session')->setFlash('sonata_flash_error', 'flash_delete_error');
  201. }
  202. return new RedirectResponse($this->admin->generateUrl('list'));
  203. }
  204. return $this->render($this->admin->getTemplate('delete'), array(
  205. 'object' => $object,
  206. 'action' => 'delete'
  207. ));
  208. }
  209. /**
  210. * return the Response object associated to the edit action
  211. *
  212. *
  213. * @param mixed $id
  214. *
  215. * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  216. * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  217. *
  218. * @return Response
  219. */
  220. public function editAction($id = null)
  221. {
  222. // the key used to lookup the template
  223. $templateKey = 'edit';
  224. $id = $this->get('request')->get($this->admin->getIdParameter());
  225. $object = $this->admin->getObject($id);
  226. if (!$object) {
  227. throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
  228. }
  229. if (false === $this->admin->isGranted('EDIT', $object)) {
  230. throw new AccessDeniedException();
  231. }
  232. $this->admin->setSubject($object);
  233. /** @var $form \Symfony\Component\Form\Form */
  234. $form = $this->admin->getForm();
  235. $form->setData($object);
  236. if ($this->get('request')->getMethod() == 'POST') {
  237. $form->bind($this->get('request'));
  238. $isFormValid = $form->isValid();
  239. // persist if the form was valid and if in preview mode the preview was approved
  240. if ($isFormValid && (!$this->isInPreviewMode() || $this->isPreviewApproved())) {
  241. $this->admin->update($object);
  242. $this->get('session')->setFlash('sonata_flash_success', 'flash_edit_success');
  243. if ($this->isXmlHttpRequest()) {
  244. return $this->renderJson(array(
  245. 'result' => 'ok',
  246. 'objectId' => $this->admin->getNormalizedIdentifier($object)
  247. ));
  248. }
  249. // redirect to edit mode
  250. return $this->redirectTo($object);
  251. }
  252. // show an error message if the form failed validation
  253. if (!$isFormValid) {
  254. if (!$this->isXmlHttpRequest()) {
  255. $this->get('session')->setFlash('sonata_flash_error', 'flash_edit_error');
  256. }
  257. } elseif ($this->isPreviewRequested()) {
  258. // enable the preview template if the form was valid and preview was requested
  259. $templateKey = 'preview';
  260. }
  261. }
  262. $view = $form->createView();
  263. // set the theme for the current Admin Form
  264. $this->get('twig')->getExtension('form')->renderer->setTheme($view, $this->admin->getFormTheme());
  265. return $this->render($this->admin->getTemplate($templateKey), array(
  266. 'action' => 'edit',
  267. 'form' => $view,
  268. 'object' => $object,
  269. ));
  270. }
  271. /**
  272. * redirect the user depend on this choice
  273. *
  274. * @param object $object
  275. *
  276. * @return Response
  277. */
  278. public function redirectTo($object)
  279. {
  280. $url = false;
  281. if ($this->get('request')->get('btn_update_and_list')) {
  282. $url = $this->admin->generateUrl('list');
  283. }
  284. if ($this->get('request')->get('btn_create_and_list')) {
  285. $url = $this->admin->generateUrl('list');
  286. }
  287. if ($this->get('request')->get('btn_create_and_create')) {
  288. $params = array();
  289. if ($this->admin->hasActiveSubClass()) {
  290. $params['subclass'] = $this->get('request')->get('subclass');
  291. }
  292. $url = $this->admin->generateUrl('create', $params);
  293. }
  294. if (!$url) {
  295. $url = $this->admin->generateObjectUrl('edit', $object);
  296. }
  297. return new RedirectResponse($url);
  298. }
  299. /**
  300. * return the Response object associated to the batch action
  301. *
  302. * @throws \RuntimeException
  303. * @return Response
  304. */
  305. public function batchAction()
  306. {
  307. if ($this->get('request')->getMethod() != 'POST') {
  308. throw new \RuntimeException('invalid request type, POST expected');
  309. }
  310. $confirmation = $this->get('request')->get('confirmation', false);
  311. if ($data = json_decode($this->get('request')->get('data'), true)) {
  312. $action = $data['action'];
  313. $idx = $data['idx'];
  314. $all_elements = $data['all_elements'];
  315. $this->get('request')->request->replace($data);
  316. } else {
  317. $this->get('request')->request->set('idx', $this->get('request')->get('idx', array()));
  318. $this->get('request')->request->set('all_elements', $this->get('request')->get('all_elements', false));
  319. $action = $this->get('request')->get('action');
  320. $idx = $this->get('request')->get('idx');
  321. $all_elements = $this->get('request')->get('all_elements');
  322. $data = $this->get('request')->request->all();
  323. }
  324. $batchActions = $this->admin->getBatchActions();
  325. if (!array_key_exists($action, $batchActions)) {
  326. throw new \RuntimeException(sprintf('The `%s` batch action is not defined', $action));
  327. }
  328. $camelizedAction = \Sonata\AdminBundle\Admin\BaseFieldDescription::camelize($action);
  329. $isRelevantAction = sprintf('batchAction%sIsRelevant', ucfirst($camelizedAction));
  330. if (method_exists($this, $isRelevantAction)) {
  331. $nonRelevantMessage = call_user_func(array($this, $isRelevantAction), $idx, $all_elements);
  332. } else {
  333. $nonRelevantMessage = count($idx) != 0 || $all_elements; // at least one item is selected
  334. }
  335. if (!$nonRelevantMessage) { // default non relevant message (if false of null)
  336. $nonRelevantMessage = 'flash_batch_empty';
  337. }
  338. $datagrid = $this->admin->getDatagrid();
  339. $datagrid->buildPager();
  340. if (true !== $nonRelevantMessage) {
  341. $this->get('session')->setFlash('sonata_flash_info', $nonRelevantMessage);
  342. return new RedirectResponse($this->admin->generateUrl('list', array('filter' => $this->admin->getFilterParameters())));
  343. }
  344. $askConfirmation = isset($batchActions[$action]['ask_confirmation']) ? $batchActions[$action]['ask_confirmation'] : true;
  345. if ($askConfirmation && $confirmation != 'ok') {
  346. $formView = $datagrid->getForm()->createView();
  347. return $this->render('SonataAdminBundle:CRUD:batch_confirmation.html.twig', array(
  348. 'action' => 'list',
  349. 'datagrid' => $datagrid,
  350. 'form' => $formView,
  351. 'data' => $data,
  352. ));
  353. }
  354. // execute the action, batchActionXxxxx
  355. $final_action = sprintf('batchAction%s', ucfirst($camelizedAction));
  356. if (!method_exists($this, $final_action)) {
  357. throw new \RuntimeException(sprintf('A `%s::%s` method must be created', get_class($this), $final_action));
  358. }
  359. $query = $datagrid->getQuery();
  360. $query->setFirstResult(null);
  361. $query->setMaxResults(null);
  362. if (count($idx) > 0) {
  363. $this->admin->getModelManager()->addIdentifiersToQuery($this->admin->getClass(), $query, $idx);
  364. } elseif (!$all_elements) {
  365. $query = null;
  366. }
  367. return call_user_func(array($this, $final_action), $query);
  368. }
  369. /**
  370. * return the Response object associated to the create action
  371. *
  372. * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  373. * @return Response
  374. */
  375. public function createAction()
  376. {
  377. // the key used to lookup the template
  378. $templateKey = 'edit';
  379. if (false === $this->admin->isGranted('CREATE')) {
  380. throw new AccessDeniedException();
  381. }
  382. $object = $this->admin->getNewInstance();
  383. $this->admin->setSubject($object);
  384. /** @var $form \Symfony\Component\Form\Form */
  385. $form = $this->admin->getForm();
  386. $form->setData($object);
  387. if ($this->get('request')->getMethod() == 'POST') {
  388. $form->bind($this->get('request'));
  389. $isFormValid = $form->isValid();
  390. // persist if the form was valid and if in preview mode the preview was approved
  391. if ($isFormValid && (!$this->isInPreviewMode() || $this->isPreviewApproved())) {
  392. $this->admin->create($object);
  393. if ($this->isXmlHttpRequest()) {
  394. return $this->renderJson(array(
  395. 'result' => 'ok',
  396. 'objectId' => $this->admin->getNormalizedIdentifier($object)
  397. ));
  398. }
  399. $this->get('session')->setFlash('sonata_flash_success','flash_create_success');
  400. // redirect to edit mode
  401. return $this->redirectTo($object);
  402. }
  403. // show an error message if the form failed validation
  404. if (!$isFormValid) {
  405. if (!$this->isXmlHttpRequest()) {
  406. $this->get('session')->setFlash('sonata_flash_error', 'flash_create_error');
  407. }
  408. } elseif ($this->isPreviewRequested()) {
  409. // pick the preview template if the form was valid and preview was requested
  410. $templateKey = 'preview';
  411. }
  412. }
  413. $view = $form->createView();
  414. // set the theme for the current Admin Form
  415. $this->get('twig')->getExtension('form')->renderer->setTheme($view, $this->admin->getFormTheme());
  416. return $this->render($this->admin->getTemplate($templateKey), array(
  417. 'action' => 'create',
  418. 'form' => $view,
  419. 'object' => $object,
  420. ));
  421. }
  422. /**
  423. * Returns true if the preview is requested to be shown
  424. *
  425. * @return boolean
  426. */
  427. protected function isPreviewRequested()
  428. {
  429. return ($this->get('request')->get('btn_preview') !== null);
  430. }
  431. /**
  432. * Returns true if the preview has been approved
  433. *
  434. * @return boolean
  435. */
  436. protected function isPreviewApproved()
  437. {
  438. return ($this->get('request')->get('btn_preview_approve') !== null);
  439. }
  440. /**
  441. * Returns true if the request is in the preview workflow
  442. *
  443. * That means either a preview is requested or the preview has already been shown
  444. * and it got approved/declined.
  445. *
  446. * @return boolean
  447. */
  448. protected function isInPreviewMode()
  449. {
  450. return $this->admin->supportsPreviewMode()
  451. && ($this->isPreviewRequested()
  452. || $this->isPreviewApproved()
  453. || $this->isPreviewDeclined());
  454. }
  455. /**
  456. * Returns true if the preview has been declined
  457. *
  458. * @return boolean
  459. */
  460. protected function isPreviewDeclined()
  461. {
  462. return ($this->get('request')->get('btn_preview_decline') !== null);
  463. }
  464. /**
  465. * return the Response object associated to the view action
  466. *
  467. * @param null $id
  468. *
  469. * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  470. * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  471. *
  472. * @return Response
  473. */
  474. public function showAction($id = null)
  475. {
  476. $id = $this->get('request')->get($this->admin->getIdParameter());
  477. $object = $this->admin->getObject($id);
  478. if (!$object) {
  479. throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
  480. }
  481. if (false === $this->admin->isGranted('VIEW', $object)) {
  482. throw new AccessDeniedException();
  483. }
  484. $this->admin->setSubject($object);
  485. return $this->render($this->admin->getTemplate('show'), array(
  486. 'action' => 'show',
  487. 'object' => $object,
  488. 'elements' => $this->admin->getShow(),
  489. ));
  490. }
  491. /**
  492. * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException|\Symfony\Component\Security\Core\Exception\AccessDeniedException
  493. *
  494. * @param mixed $id
  495. *
  496. * @return Response
  497. */
  498. public function historyAction($id = null)
  499. {
  500. if (false === $this->admin->isGranted('EDIT')) {
  501. throw new AccessDeniedException();
  502. }
  503. $id = $this->get('request')->get($this->admin->getIdParameter());
  504. $object = $this->admin->getObject($id);
  505. if (!$object) {
  506. throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
  507. }
  508. $manager = $this->get('sonata.admin.audit.manager');
  509. if (!$manager->hasReader($this->admin->getClass())) {
  510. throw new NotFoundHttpException(sprintf('unable to find the audit reader for class : %s', $this->admin->getClass()));
  511. }
  512. $reader = $manager->getReader($this->admin->getClass());
  513. $revisions = $reader->findRevisions($this->admin->getClass(), $id);
  514. return $this->render($this->admin->getTemplate('history'), array(
  515. 'action' => 'history',
  516. 'object' => $object,
  517. 'revisions' => $revisions,
  518. ));
  519. }
  520. /**
  521. * @param null $id
  522. * @param string $revision
  523. *
  524. * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  525. * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  526. *
  527. * @return Response
  528. */
  529. public function historyViewRevisionAction($id = null, $revision = null)
  530. {
  531. if (false === $this->admin->isGranted('EDIT')) {
  532. throw new AccessDeniedException();
  533. }
  534. $id = $this->get('request')->get($this->admin->getIdParameter());
  535. $object = $this->admin->getObject($id);
  536. if (!$object) {
  537. throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
  538. }
  539. $manager = $this->get('sonata.admin.audit.manager');
  540. if (!$manager->hasReader($this->admin->getClass())) {
  541. throw new NotFoundHttpException(sprintf('unable to find the audit reader for class : %s', $this->admin->getClass()));
  542. }
  543. $reader = $manager->getReader($this->admin->getClass());
  544. // retrieve the revisioned object
  545. $object = $reader->find($this->admin->getClass(), $id, $revision);
  546. if (!$object) {
  547. throw new NotFoundHttpException(sprintf('unable to find the targeted object `%s` from the revision `%s` with classname : `%s`', $id, $revision, $this->admin->getClass()));
  548. }
  549. $this->admin->setSubject($object);
  550. return $this->render($this->admin->getTemplate('show'), array(
  551. 'action' => 'show',
  552. 'object' => $object,
  553. 'elements' => $this->admin->getShow(),
  554. ));
  555. }
  556. /**
  557. * @param Request $request
  558. *
  559. * @throws \RuntimeException
  560. * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  561. *
  562. * @return Response
  563. */
  564. public function exportAction(Request $request)
  565. {
  566. if (false === $this->admin->isGranted('EXPORT')) {
  567. throw new AccessDeniedException();
  568. }
  569. $format = $request->get('format');
  570. $allowedExportFormats = (array) $this->admin->getExportFormats();
  571. if (!in_array($format, $allowedExportFormats) ) {
  572. throw new \RuntimeException(sprintf('Export in format `%s` is not allowed for class: `%s`. Allowed formats are: `%s`', $format, $this->admin->getClass(), implode(', ', $allowedExportFormats)));
  573. }
  574. $filename = sprintf('export_%s_%s.%s',
  575. strtolower(substr($this->admin->getClass(), strripos($this->admin->getClass(), '\\') + 1)),
  576. date('Y_m_d_H_i_s', strtotime('now')),
  577. $format
  578. );
  579. return $this->get('sonata.admin.exporter')->getResponse($format, $filename, $this->admin->getDataSourceIterator());
  580. }
  581. }