src/AdminBundle/Services/BaseService.php line 152

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\DependencyInjection\ContainerInterface;
  31. class BaseService
  32. {
  33. /**
  34. * @var UserManager
  35. */
  36. protected $manager;
  37. /**
  38. * @var \Symfony\Component\DependencyInjection\ContainerInterface
  39. */
  40. protected $container;
  41. /**
  42. * @var \AdminBundle\Repository\AreaRepository
  43. */
  44. protected $areaRepository;
  45. /**
  46. * @var \AdminBundle\Repository\CarTypeRepository
  47. */
  48. protected $carTypeRepository;
  49. /**
  50. * @var \AdminBundle\Repository\CarTypePriceRepository
  51. */
  52. protected $carTypePriceRepository;
  53. /**
  54. * @var \AdminBundle\Repository\CarTypeAreaPriceRepository
  55. */
  56. protected $carTypeAreaPriceRepository;
  57. /**
  58. * @var \AdminBundle\Repository\ZoneRepository
  59. */
  60. protected $zoneRepository;
  61. /**
  62. * @var \AdminBundle\Repository\BookingExtraRepository
  63. */
  64. protected $bookingExtraRepository;
  65. /**
  66. * @var \AdminBundle\Repository\UserRepository
  67. */
  68. protected $userRepository;
  69. /**
  70. * @var SettingsRepository
  71. */
  72. protected $settingsRepository;
  73. /**
  74. * @var PeriodSettingsRepository
  75. */
  76. protected $periodSettingsRepository;
  77. /**
  78. * @var ToursRepository
  79. */
  80. protected $toursRepository;
  81. /**
  82. * @var DriverRepository
  83. */
  84. protected $driverRepository;
  85. /**
  86. * @var BookingRepository
  87. */
  88. protected $bookingRepository;
  89. /**
  90. * @var BookingRequestRepository
  91. */
  92. protected $bookingRequestRepository;
  93. /**
  94. * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
  95. */
  96. public function __construct(ContainerInterface $container, UserManager $usermanager)
  97. {
  98. $this->container = $container;
  99. $this->manager = $usermanager;
  100. $this->areaRepository = $this->getRepo(Area::class);
  101. $this->bookingRepository = $this->getRepo(Booking::class);
  102. $this->bookingExtraRepository = $this->getRepo(BookingExtra::class);
  103. $this->bookingRequestRepository = $this->getRepo(BookingRequest::class);
  104. $this->carTypeRepository = $this->getRepo(CarType::class);
  105. $this->carTypeAreaPriceRepository = $this->getRepo(CarTypeAreaPrice::class);
  106. $this->carTypePriceRepository = $this->getRepo(CarTypePrice::class);
  107. $this->driverRepository = $this->getRepo(Driver::class);
  108. $this->periodSettingsRepository = $this->getRepo(PeriodSettings::class);
  109. $this->settingsRepository = $this->getRepo(Settings::class);
  110. $this->userRepository = $this->getRepo(User::class);
  111. $this->toursRepository = $this->getRepo(Tours::class);
  112. $this->zoneRepository = $this->getRepo(Zone::class);
  113. }
  114. public function getRepo($class) {
  115. $em = $this->get('doctrine')->getManager();
  116. return $em->getRepository($class);
  117. }
  118. protected function setKeyOfArray($array, $key)
  119. {
  120. $result = array();
  121. if (!empty($array)) {
  122. foreach ($array as $item) {
  123. $result[$item[$key]] = $item;
  124. }
  125. }
  126. return $result;
  127. }
  128. protected function getDoctrine()
  129. {
  130. return $this->container->get('doctrine');
  131. }
  132. public function get($service) {
  133. if ($service == 'sonata.user.user_manager') {
  134. return $this->manager;
  135. }
  136. return $this->container->get($service);
  137. }
  138. }