src/AdminBundle/Services/BaseService.php line 161

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Services;
  3. use AdminBundle\Entity\Area;
  4. use AdminBundle\Entity\Booking;
  5. use AdminBundle\Entity\BookingExtra;
  6. use AdminBundle\Entity\BookingRequest;
  7. use AdminBundle\Entity\CarType;
  8. use AdminBundle\Entity\CarTypeAreaPrice;
  9. use AdminBundle\Entity\CarTypePrice;
  10. use AdminBundle\Entity\Driver;
  11. use AdminBundle\Entity\PeriodSettings;
  12. use AdminBundle\Entity\Settings;
  13. use AdminBundle\Entity\User;
  14. use AdminBundle\Entity\Tours;
  15. use AdminBundle\Entity\Zone;
  16. use AdminBundle\Repository\AreaRepository;
  17. use AdminBundle\Repository\BookingExtraRepository;
  18. use AdminBundle\Repository\BookingRepository;
  19. use AdminBundle\Repository\BookingRequestRepository;
  20. use AdminBundle\Repository\CarTypeAreaPriceRepository;
  21. use AdminBundle\Repository\CarTypeRepository;
  22. use AdminBundle\Repository\CarTypePriceRepository;
  23. use AdminBundle\Repository\DriverRepository;
  24. use AdminBundle\Repository\PeriodSettingsRepository;
  25. use AdminBundle\Repository\SettingsRepository;
  26. use AdminBundle\Repository\UserRepository;
  27. use AdminBundle\Repository\ZoneRepository;
  28. use AdminBundle\Repository\ToursRepository;
  29. use Sonata\UserBundle\Entity\UserManager;
  30. use Symfony\Component\Asset\UrlPackage;
  31. use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
  32. use Symfony\Component\DependencyInjection\ContainerInterface;
  33. class BaseService
  34. {
  35. /**
  36. * @var UserManager
  37. */
  38. protected $manager;
  39. /**
  40. * @var \Symfony\Component\DependencyInjection\ContainerInterface
  41. */
  42. protected $container;
  43. /**
  44. * @var \AdminBundle\Repository\AreaRepository
  45. */
  46. protected $areaRepository;
  47. /**
  48. * @var \AdminBundle\Repository\CarTypeRepository
  49. */
  50. protected $carTypeRepository;
  51. /**
  52. * @var \AdminBundle\Repository\CarTypePriceRepository
  53. */
  54. protected $carTypePriceRepository;
  55. /**
  56. * @var \AdminBundle\Repository\CarTypeAreaPriceRepository
  57. */
  58. protected $carTypeAreaPriceRepository;
  59. /**
  60. * @var \AdminBundle\Repository\ZoneRepository
  61. */
  62. protected $zoneRepository;
  63. /**
  64. * @var \AdminBundle\Repository\BookingExtraRepository
  65. */
  66. protected $bookingExtraRepository;
  67. /**
  68. * @var \AdminBundle\Repository\UserRepository
  69. */
  70. protected $userRepository;
  71. /**
  72. * @var SettingsRepository
  73. */
  74. protected $settingsRepository;
  75. /**
  76. * @var PeriodSettingsRepository
  77. */
  78. protected $periodSettingsRepository;
  79. /**
  80. * @var ToursRepository
  81. */
  82. protected $toursRepository;
  83. /**
  84. * @var DriverRepository
  85. */
  86. protected $driverRepository;
  87. /**
  88. * @var BookingRepository
  89. */
  90. protected $bookingRepository;
  91. /**
  92. * @var BookingRequestRepository
  93. */
  94. protected $bookingRequestRepository;
  95. /**
  96. * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
  97. */
  98. public function __construct(ContainerInterface $container, UserManager $usermanager)
  99. {
  100. $this->container = $container;
  101. $this->manager = $usermanager;
  102. $this->areaRepository = $this->getRepo(Area::class);
  103. $this->bookingRepository = $this->getRepo(Booking::class);
  104. $this->bookingExtraRepository = $this->getRepo(BookingExtra::class);
  105. $this->bookingRequestRepository = $this->getRepo(BookingRequest::class);
  106. $this->carTypeRepository = $this->getRepo(CarType::class);
  107. $this->carTypeAreaPriceRepository = $this->getRepo(CarTypeAreaPrice::class);
  108. $this->carTypePriceRepository = $this->getRepo(CarTypePrice::class);
  109. $this->driverRepository = $this->getRepo(Driver::class);
  110. $this->periodSettingsRepository = $this->getRepo(PeriodSettings::class);
  111. $this->settingsRepository = $container->get('settings_repo');
  112. $this->userRepository = $this->getRepo(User::class);
  113. $this->toursRepository = $this->getRepo(Tours::class);
  114. $this->zoneRepository = $this->getRepo(Zone::class);
  115. }
  116. public function getRepo($class) {
  117. $em = $this->get('doctrine')->getManager();
  118. return $em->getRepository($class);
  119. }
  120. protected function setKeyOfArray($array, $key)
  121. {
  122. $result = array();
  123. if (!empty($array)) {
  124. foreach ($array as $item) {
  125. $result[$item[$key]] = $item;
  126. }
  127. }
  128. return $result;
  129. }
  130. protected function getDoctrine()
  131. {
  132. return $this->container->get('doctrine');
  133. }
  134. public function assetsManager() {
  135. return new UrlPackage(
  136. $this->container->getParameter('assets_base_url'),
  137. new EmptyVersionStrategy()
  138. );
  139. }
  140. public function get($service) {
  141. if ($service == 'sonata.user.user_manager') {
  142. return $this->manager;
  143. }
  144. return $this->container->get($service);
  145. }
  146. }