AdminListBlockService.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /*
  3. * This file is part of the Sonata project.
  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\Block;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
  13. use Sonata\AdminBundle\Form\FormMapper;
  14. use Sonata\AdminBundle\Validator\ErrorElement;
  15. use Sonata\AdminBundle\Admin\Pool;
  16. use Sonata\BlockBundle\Model\BlockInterface;
  17. use Sonata\BlockBundle\Block\BaseBlockService;
  18. /**
  19. *
  20. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  21. */
  22. class AdminListBlockService extends BaseBlockService
  23. {
  24. protected $pool;
  25. /**
  26. * @param string $name
  27. * @param \Symfony\Bundle\FrameworkBundle\Templating\EngineInterface $templating
  28. * @param \Sonata\AdminBundle\Admin\Pool $pool
  29. */
  30. public function __construct($name, EngineInterface $templating, Pool $pool)
  31. {
  32. parent::__construct($name, $templating);
  33. $this->pool = $pool;
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function execute(BlockInterface $block, Response $response = null)
  39. {
  40. $settings = array_merge($this->getDefaultSettings(), $block->getSettings());
  41. $dashboardGroups = $this->pool->getDashboardGroups();
  42. $visibleGroups = array();
  43. foreach ($dashboardGroups as $name => $dashboardGroup) {
  44. if (!$settings['groups'] || in_array($name, $settings['groups'])) {
  45. $visibleGroups[] = $dashboardGroup;
  46. }
  47. }
  48. return $this->renderResponse('SonataAdminBundle:Block:block_admin_list.html.twig', array(
  49. 'block' => $block,
  50. 'settings' => $settings,
  51. 'admin_pool' => $this->pool,
  52. 'groups' => $visibleGroups
  53. ), $response);
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
  59. {
  60. // TODO: Implement validateBlock() method.
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
  66. {
  67. }
  68. /**
  69. * {@inheritdoc}
  70. */
  71. public function getName()
  72. {
  73. return 'Admin List';
  74. }
  75. /**
  76. * {@inheritdoc}
  77. */
  78. public function getDefaultSettings()
  79. {
  80. return array(
  81. 'groups' => false
  82. );
  83. }
  84. }