ONUCRUDController.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace FTTHBundle\Controller;
  3. use WorkflowBundle\Controller\CRUDController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  6. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  7. class ONUCRUDController extends CRUDController
  8. {
  9. /**
  10. * List action.
  11. *
  12. * @return Response
  13. *
  14. * @throws AccessDeniedException If access is not granted
  15. */
  16. public function listAction()
  17. {
  18. $request = $this->getRequest();
  19. $this->admin->checkAccess('list');
  20. $preResponse = $this->preList($request);
  21. if ($preResponse !== null) {
  22. return $preResponse;
  23. }
  24. if ($listMode = $request->get('_list_mode')) {
  25. $this->admin->setListMode($listMode);
  26. }
  27. $datagrid = $this->admin->getDatagrid();
  28. $clientsIds = array();
  29. foreach($datagrid->getResults() as $object) {
  30. if($object->getClientId())
  31. $clientsIds[$object->getClientId()] = $object->getClientId();
  32. }
  33. $_clients = array();
  34. if ($this->container->hasParameter('client') && $clientsIds) {
  35. $clientApi = $this->getParameter('client');
  36. $webservice = $this->get("webservice");
  37. $filters = array("qb-ids" => implode(",",$clientsIds), 'qb-criteria' => true);
  38. $clients = $webservice->getData($clientApi, $filters);
  39. if (is_array($clients) && !empty($clients)) {
  40. foreach ($clients as $client) {
  41. if (isset($client['externalId']) && isset($client['id']) && isset($client['name'])) {
  42. $_clients[$client['id']] = "{$client['externalId']} - {$client['name']} ({$client['id']})";
  43. } elseif (isset($client['id']) && isset($client['name'])) {
  44. $_clients[$client['id']] = "{$client['id']} - {$client['name']}";
  45. }
  46. }
  47. }
  48. }
  49. if($_clients) {
  50. foreach($datagrid->getResults() as $object) {
  51. if($object->getClientId() && isset($_clients[$object->getClientId()]))
  52. $object->setClientId($_clients[$object->getClientId()]);
  53. }
  54. }
  55. $formView = $datagrid->getForm()->createView();
  56. // set the theme for the current Admin Form
  57. $this->setFormTheme($formView, $this->admin->getFilterTheme());
  58. return $this->render($this->admin->getTemplate('list'), array(
  59. 'action' => 'list',
  60. 'form' => $formView,
  61. 'datagrid' => $datagrid,
  62. 'csrf_token' => $this->getCsrfToken('sonata.batch'),
  63. 'export_formats' => $this->has('sonata.admin.admin_exporter') ?
  64. $this->get('sonata.admin.admin_exporter')->getAvailableFormats($this->admin) :
  65. $this->admin->getExportFormats(),
  66. ), null);
  67. }
  68. }