12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace FTTHBundle\Controller;
- use WorkflowBundle\Controller\CRUDController;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
- use Symfony\Component\Security\Core\Exception\AccessDeniedException;
- class ONUCRUDController extends CRUDController
- {
- /**
- * List action.
- *
- * @return Response
- *
- * @throws AccessDeniedException If access is not granted
- */
- public function listAction()
- {
- $request = $this->getRequest();
- $this->admin->checkAccess('list');
- $preResponse = $this->preList($request);
- if ($preResponse !== null) {
- return $preResponse;
- }
- if ($listMode = $request->get('_list_mode')) {
- $this->admin->setListMode($listMode);
- }
- $datagrid = $this->admin->getDatagrid();
- $clientsIds = array();
- foreach($datagrid->getResults() as $object) {
- if($object->getClientId())
- $clientsIds[$object->getClientId()] = $object->getClientId();
- }
- $_clients = array();
- if ($this->container->hasParameter('client') && $clientsIds) {
- $clientApi = $this->getParameter('client');
- $webservice = $this->get("webservice");
- $filters = array("qb-ids" => implode(",",$clientsIds), 'qb-criteria' => true);
- $clients = $webservice->getData($clientApi, $filters);
- if (is_array($clients) && !empty($clients)) {
- foreach ($clients as $client) {
- if (isset($client['externalId']) && isset($client['id']) && isset($client['name'])) {
- $_clients[$client['id']] = "{$client['externalId']} - {$client['name']} ({$client['id']})";
- } elseif (isset($client['id']) && isset($client['name'])) {
- $_clients[$client['id']] = "{$client['id']} - {$client['name']}";
- }
- }
- }
- }
- if($_clients) {
- foreach($datagrid->getResults() as $object) {
- if($object->getClientId() && isset($_clients[$object->getClientId()]))
- $object->setClientId($_clients[$object->getClientId()]);
- }
- }
-
- $formView = $datagrid->getForm()->createView();
- // set the theme for the current Admin Form
- $this->setFormTheme($formView, $this->admin->getFilterTheme());
- return $this->render($this->admin->getTemplate('list'), array(
- 'action' => 'list',
- 'form' => $formView,
- 'datagrid' => $datagrid,
- 'csrf_token' => $this->getCsrfToken('sonata.batch'),
- 'export_formats' => $this->has('sonata.admin.admin_exporter') ?
- $this->get('sonata.admin.admin_exporter')->getAvailableFormats($this->admin) :
- $this->admin->getExportFormats(),
- ), null);
- }
- }
|