Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

266 rindas
8.7KB

  1. <?php
  2. namespace Lc\SovBundle\Controller;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
  5. use Knp\Component\Pager\PaginatorInterface;
  6. use Lc\SovBundle\Container\ComponentContainer;
  7. use Lc\SovBundle\Container\File\FileContainer;
  8. use Lc\SovBundle\Container\Newsletter\NewsletterContainer;
  9. use Lc\SovBundle\Container\Reminder\ReminderContainer;
  10. use Lc\SovBundle\Container\Setting\SiteSettingContainer;
  11. use Lc\SovBundle\Container\Site\NewsContainer;
  12. use Lc\SovBundle\Container\Site\PageContainer;
  13. use Lc\SovBundle\Container\Site\SiteContainer;
  14. use Lc\SovBundle\Container\Ticket\TicketContainer;
  15. use Lc\SovBundle\Container\Ticket\TicketMessageContainer;
  16. use Lc\SovBundle\Container\User\GroupUserContainer;
  17. use Lc\SovBundle\Container\User\UserContainer;
  18. use Lc\SovBundle\Field\Filter\FilterManager;
  19. use Lc\SovBundle\Repository\EntityRepository;
  20. use Lc\SovBundle\Solver\Setting\SettingSolver;
  21. use Lc\SovBundle\Translation\FlashBagTranslator;
  22. use Lc\SovBundle\Translation\TranslatorAdmin;
  23. use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
  24. use Psr\Log\LoggerInterface;
  25. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  26. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  27. use Symfony\Component\HttpFoundation\Request;
  28. use Symfony\Component\HttpFoundation\RequestStack;
  29. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  30. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  31. use Symfony\Component\Security\Core\Security;
  32. use Symfony\Contracts\Translation\TranslatorInterface;
  33. use Twig\Environment;
  34. trait ControllerTrait
  35. {
  36. public static function getSubscribedServices()
  37. {
  38. return array_merge(
  39. parent::getSubscribedServices(),
  40. [
  41. Environment::class => Environment::class,
  42. Security::class => Security::class,
  43. EntityManagerInterface::class => EntityManagerInterface::class,
  44. UrlGeneratorInterface::class => UrlGeneratorInterface::class,
  45. SessionInterface::class => SessionInterface::class,
  46. PaginatorInterface::class => PaginatorInterface::class,
  47. RequestStack::class => RequestStack::class,
  48. EventDispatcherInterface::class => EventDispatcherInterface::class,
  49. LoggerInterface::class => LoggerInterface::class,
  50. ParameterBagInterface::class => ParameterBagInterface::class,
  51. TranslatorInterface::class => TranslatorInterface::class,
  52. TranslatorAdmin::class => TranslatorAdmin::class,
  53. FilterManager::class => FilterManager::class,
  54. FlashBagTranslator::class => FlashBagTranslator::class,
  55. MailjetTransport::class => MailjetTransport::class,
  56. AdminUrlGenerator::class => AdminUrlGenerator::class,
  57. SettingSolver::class => SettingSolver::class,
  58. ComponentContainer::class => ComponentContainer::class,
  59. FileContainer::class => FileContainer::class,
  60. NewsletterContainer::class => NewsletterContainer::class,
  61. ReminderContainer::class => ReminderContainer::class,
  62. NewsContainer::class => NewsContainer::class,
  63. PageContainer::class => PageContainer::class,
  64. SiteContainer::class => SiteContainer::class,
  65. TicketContainer::class => TicketContainer::class,
  66. TicketMessageContainer::class => TicketMessageContainer::class,
  67. GroupUserContainer::class => GroupUserContainer::class,
  68. UserContainer::class => UserContainer::class,
  69. SiteSettingContainer::class => SiteSettingContainer::class,
  70. EntityRepository::class => EntityRepository::class,
  71. ]
  72. );
  73. }
  74. public function addFlashTranslator(
  75. string $type,
  76. $translationKeyName,
  77. $translationEntityName = null,
  78. $translationParam = array()
  79. ): void
  80. {
  81. if ($translationEntityName === null && method_exists($this, 'getTranslationEntityName')) {
  82. $translationEntityName = $this->getTranslationEntityName();
  83. }
  84. $this->get(FlashBagTranslator::class)->add(
  85. $type,
  86. $translationKeyName,
  87. $translationEntityName,
  88. $translationParam
  89. );
  90. }
  91. public function isInstanceOf(string $interfaceName): bool
  92. {
  93. return in_array($interfaceName, class_implements($this->getEntityFqcn()));
  94. }
  95. public function generateEaUrl(string $controller = null, string $action = null, int $entityId = null, array $extraParam = array()): string
  96. {
  97. $adminUrlGenerator = $this->get(AdminUrlGenerator::class);
  98. if ($controller) {
  99. $adminUrlGenerator->setController($controller);
  100. }
  101. if ($action) {
  102. $adminUrlGenerator->setAction($action);
  103. }
  104. if ($entityId) {
  105. $adminUrlGenerator->setEntityId($entityId);
  106. }
  107. if ($extraParam) {
  108. foreach ($extraParam as $key => $value) {
  109. $adminUrlGenerator->set($key, $value);
  110. }
  111. }
  112. return $adminUrlGenerator->generateUrl();
  113. }
  114. public function getReferer(Request $request): ?string
  115. {
  116. return $request->headers->get('referer');
  117. }
  118. public function getTemplating(): Environment
  119. {
  120. return $this->get(Environment::class);
  121. }
  122. public function getEntityManager(): EntityManagerInterface
  123. {
  124. return $this->get(EntityManagerInterface::class);
  125. }
  126. public function getRouter(): UrlGeneratorInterface
  127. {
  128. return $this->get(UrlGeneratorInterface::class);
  129. }
  130. public function getSession(): SessionInterface
  131. {
  132. return $this->get(SessionInterface::class);
  133. }
  134. public function getSecurity(): Security
  135. {
  136. return $this->get(Security::class);
  137. }
  138. public function getPaginator(): PaginatorInterface
  139. {
  140. return $this->get(PaginatorInterface::class);
  141. }
  142. public function getRequestStack(): RequestStack
  143. {
  144. return $this->get(RequestStack::class);
  145. }
  146. public function getEventDispatcher(): EventDispatcherInterface
  147. {
  148. return $this->get(EventDispatcherInterface::class);
  149. }
  150. public function getParameterBag(): ParameterBagInterface
  151. {
  152. return $this->get(ParameterBagInterface::class);
  153. }
  154. public function getTranslator(): TranslatorInterface
  155. {
  156. return $this->get(TranslatorInterface::class);
  157. }
  158. public function getTranslatorAdmin(): TranslatorAdmin
  159. {
  160. return $this->get(TranslatorAdmin::class);
  161. }
  162. public function getLogger(): LoggerInterface
  163. {
  164. return $this->get(LoggerInterface::class);
  165. }
  166. public function getMailjetTransport(): MailjetTransport
  167. {
  168. return $this->get(MailjetTransport::class);
  169. }
  170. public function getAdminUrlGenerator(): AdminUrlGenerator
  171. {
  172. return $this->get(AdminUrlGenerator::class);
  173. }
  174. public function getSettingSolver(): SettingSolver
  175. {
  176. return $this->get(SettingSolver::class);
  177. }
  178. public function getSettingValue($entity, $settingName)
  179. {
  180. return $this->getSettingSolver()->getSettingValue($entity, $settingName);
  181. }
  182. public function getComponentContainer(): ComponentContainer
  183. {
  184. return $this->get(ComponentContainer::class);
  185. }
  186. public function getFileContainer(): FileContainer
  187. {
  188. return $this->get(FileContainer::class);
  189. }
  190. public function getNewsletterContainer(): NewsletterContainer
  191. {
  192. return $this->get(NewsletterContainer::class);
  193. }
  194. public function getReminderContainer(): ReminderContainer
  195. {
  196. return $this->get(ReminderContainer::class);
  197. }
  198. public function getNewsContainer(): NewsContainer
  199. {
  200. return $this->get(NewsContainer::class);
  201. }
  202. public function getPageContainer(): PageContainer
  203. {
  204. return $this->get(PageContainer::class);
  205. }
  206. public function getSiteContainer(): SiteContainer
  207. {
  208. return $this->get(SiteContainer::class);
  209. }
  210. public function getTicketContainer(): TicketContainer
  211. {
  212. return $this->get(TicketContainer::class);
  213. }
  214. public function getTicketMessageContainer(): TicketMessageContainer
  215. {
  216. return $this->get(TicketMessageContainer::class);
  217. }
  218. public function getGroupUserContainer(): GroupUserContainer
  219. {
  220. return $this->get(GroupUserContainer::class);
  221. }
  222. public function getUserContainer(): UserContainer
  223. {
  224. return $this->get(UserContainer::class);
  225. }
  226. public function getSiteSettingContainer(): SiteSettingContainer
  227. {
  228. return $this->get(SiteSettingContainer::class);
  229. }
  230. }