QueryStringBuilder.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project 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\Route;
  11. use Sonata\AdminBundle\Admin\AdminInterface;
  12. use Sonata\AdminBundle\Builder\RouteBuilderInterface;
  13. use Sonata\AdminBundle\Model\AuditManagerInterface;
  14. /**
  15. * Class QueryStringBuilder.
  16. *
  17. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  18. */
  19. class QueryStringBuilder implements RouteBuilderInterface
  20. {
  21. protected $manager;
  22. /**
  23. * @param \Sonata\AdminBundle\Model\AuditManagerInterface $manager
  24. */
  25. public function __construct(AuditManagerInterface $manager)
  26. {
  27. $this->manager = $manager;
  28. }
  29. /**
  30. * @param \Sonata\AdminBundle\Admin\AdminInterface $admin
  31. * @param \Sonata\AdminBundle\Route\RouteCollection $collection
  32. */
  33. public function build(AdminInterface $admin, RouteCollection $collection)
  34. {
  35. $collection->add('list');
  36. $collection->add('create');
  37. $collection->add('batch');
  38. $collection->add('edit');
  39. $collection->add('delete');
  40. $collection->add('show');
  41. $collection->add('export');
  42. if ($this->manager->hasReader($admin->getClass())) {
  43. $collection->add('history', '/audit-history');
  44. $collection->add('history_view_revision', '/audit-history-view');
  45. $collection->add('history_compare_revisions', '/audit-history-compare');
  46. }
  47. if ($admin->isAclEnabled()) {
  48. $collection->add('acl', $admin->getRouterIdParameter().'/acl');
  49. }
  50. // an admin can have only one level of nested child
  51. if ($admin->getParent()) {
  52. return;
  53. }
  54. // add children urls
  55. foreach ($admin->getChildren() as $children) {
  56. $collection->addCollection($children->getRoutes());
  57. }
  58. }
  59. }