@@ -36,27 +36,27 @@ discard block |
||
36 | 36 | |
37 | 37 | class ArticleController extends AbstractController { |
38 | 38 | |
39 | - private FormFactoryInterface $formFactory; |
|
40 | - private RouteProviderInterface $routeProvider; // swp.provider.route |
|
41 | - private ArticleRepositoryInterface $articleRepository; //swp.repository.article |
|
42 | - private ArticleProviderInterface $articleProvider; //swp.provider.article |
|
43 | - private EventDispatcherInterface $eventDispatcher; |
|
44 | - private EntityManagerInterface $entityManager; // swp.object_manager.article |
|
45 | - private ArticleServiceInterface $articleService; // swp.service.article |
|
46 | - |
|
47 | - /** |
|
48 | - * @param FormFactoryInterface $formFactory |
|
49 | - * @param RouteProviderInterface $routeProvider |
|
50 | - * @param ArticleRepositoryInterface $articleRepository |
|
51 | - * @param ArticleProviderInterface $articleProvider |
|
52 | - * @param EventDispatcherInterface $eventDispatcher |
|
53 | - * @param EntityManagerInterface $entityManager |
|
54 | - * @param ArticleServiceInterface $articleService |
|
55 | - */ |
|
56 | - public function __construct(FormFactoryInterface $formFactory, RouteProviderInterface $routeProvider, |
|
57 | - ArticleRepositoryInterface $articleRepository, ArticleProviderInterface $articleProvider, |
|
58 | - EventDispatcherInterface $eventDispatcher, EntityManagerInterface $entityManager, |
|
59 | - ArticleServiceInterface $articleService) { |
|
39 | + private FormFactoryInterface $formFactory; |
|
40 | + private RouteProviderInterface $routeProvider; // swp.provider.route |
|
41 | + private ArticleRepositoryInterface $articleRepository; //swp.repository.article |
|
42 | + private ArticleProviderInterface $articleProvider; //swp.provider.article |
|
43 | + private EventDispatcherInterface $eventDispatcher; |
|
44 | + private EntityManagerInterface $entityManager; // swp.object_manager.article |
|
45 | + private ArticleServiceInterface $articleService; // swp.service.article |
|
46 | + |
|
47 | + /** |
|
48 | + * @param FormFactoryInterface $formFactory |
|
49 | + * @param RouteProviderInterface $routeProvider |
|
50 | + * @param ArticleRepositoryInterface $articleRepository |
|
51 | + * @param ArticleProviderInterface $articleProvider |
|
52 | + * @param EventDispatcherInterface $eventDispatcher |
|
53 | + * @param EntityManagerInterface $entityManager |
|
54 | + * @param ArticleServiceInterface $articleService |
|
55 | + */ |
|
56 | + public function __construct(FormFactoryInterface $formFactory, RouteProviderInterface $routeProvider, |
|
57 | + ArticleRepositoryInterface $articleRepository, ArticleProviderInterface $articleProvider, |
|
58 | + EventDispatcherInterface $eventDispatcher, EntityManagerInterface $entityManager, |
|
59 | + ArticleServiceInterface $articleService) { |
|
60 | 60 | $this->formFactory = $formFactory; |
61 | 61 | $this->routeProvider = $routeProvider; |
62 | 62 | $this->articleRepository = $articleRepository; |
@@ -64,30 +64,30 @@ discard block |
||
64 | 64 | $this->eventDispatcher = $eventDispatcher; |
65 | 65 | $this->entityManager = $entityManager; |
66 | 66 | $this->articleService = $articleService; |
67 | - } |
|
67 | + } |
|
68 | 68 | |
69 | 69 | |
70 | - /** |
|
71 | - * @Route("/api/{version}/content/articles/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_list_articles") |
|
72 | - * |
|
73 | - * @throws \Exception |
|
74 | - */ |
|
75 | - public function listAction(Request $request): ResourcesListResponseInterface { |
|
70 | + /** |
|
71 | + * @Route("/api/{version}/content/articles/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_list_articles") |
|
72 | + * |
|
73 | + * @throws \Exception |
|
74 | + */ |
|
75 | + public function listAction(Request $request): ResourcesListResponseInterface { |
|
76 | 76 | $authors = ''; |
77 | 77 | if (null !== $request->query->get('author', null)) { |
78 | - $authors = explode(', ', $request->query->get('author')); |
|
78 | + $authors = explode(', ', $request->query->get('author')); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | if ($request->query->get('route', false) && $request->query->get('includeSubRoutes', false)) { |
82 | - $routeObject = $this->routeProvider->getOneById($request->query->get('route')); |
|
82 | + $routeObject = $this->routeProvider->getOneById($request->query->get('route')); |
|
83 | 83 | |
84 | - if (null !== $routeObject) { |
|
84 | + if (null !== $routeObject) { |
|
85 | 85 | $ids = [$routeObject->getId()]; |
86 | 86 | foreach ($routeObject->getChildren() as $child) { |
87 | - $ids[] = $child->getId(); |
|
87 | + $ids[] = $child->getId(); |
|
88 | 88 | } |
89 | 89 | $request->query->set('route', $ids); |
90 | - } |
|
90 | + } |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | $articles = $this->articleRepository |
@@ -102,25 +102,25 @@ discard block |
||
102 | 102 | ]), $request->query->all('sorting'), new PaginationData($request)); |
103 | 103 | |
104 | 104 | return new ResourcesListResponse($articles); |
105 | - } |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * @Route("/api/{version}/content/articles/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles", requirements={"id"=".+"}) |
|
109 | - */ |
|
110 | - public function getAction($id): SingleResourceResponseInterface { |
|
107 | + /** |
|
108 | + * @Route("/api/{version}/content/articles/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles", requirements={"id"=".+"}) |
|
109 | + */ |
|
110 | + public function getAction($id): SingleResourceResponseInterface { |
|
111 | 111 | $article = $this->articleProvider->getOneById($id); |
112 | 112 | |
113 | 113 | if (null === $article) { |
114 | - throw new NotFoundHttpException('Article was not found.'); |
|
114 | + throw new NotFoundHttpException('Article was not found.'); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | return new SingleResourceResponse($article); |
118 | - } |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @Route("/api/{version}/content/articles/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_update_articles", requirements={"id"=".+"}) |
|
122 | - */ |
|
123 | - public function updateAction(Request $request, $id): SingleResourceResponseInterface { |
|
120 | + /** |
|
121 | + * @Route("/api/{version}/content/articles/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_update_articles", requirements={"id"=".+"}) |
|
122 | + */ |
|
123 | + public function updateAction(Request $request, $id): SingleResourceResponseInterface { |
|
124 | 124 | $objectManager = $this->entityManager; |
125 | 125 | $article = $this->findOr404($id); |
126 | 126 | $originalArticleStatus = $article->getStatus(); |
@@ -129,32 +129,32 @@ discard block |
||
129 | 129 | |
130 | 130 | $form->handleRequest($request); |
131 | 131 | if ($form->isSubmitted() && $form->isValid()) { |
132 | - $this->articleService->reactOnStatusChange($originalArticleStatus, $article); |
|
133 | - $objectManager->flush(); |
|
134 | - $objectManager->refresh($article); |
|
132 | + $this->articleService->reactOnStatusChange($originalArticleStatus, $article); |
|
133 | + $objectManager->flush(); |
|
134 | + $objectManager->refresh($article); |
|
135 | 135 | |
136 | - return new SingleResourceResponse($article); |
|
136 | + return new SingleResourceResponse($article); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return new SingleResourceResponse($form, new ResponseContext(500)); |
140 | - } |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * @Route("/api/{version}/content/articles/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_delete_articles", requirements={"id"=".+"}) |
|
144 | - */ |
|
145 | - public function deleteAction($id): SingleResourceResponseInterface { |
|
142 | + /** |
|
143 | + * @Route("/api/{version}/content/articles/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_delete_articles", requirements={"id"=".+"}) |
|
144 | + */ |
|
145 | + public function deleteAction($id): SingleResourceResponseInterface { |
|
146 | 146 | $objectManager = $this->entityManager; |
147 | 147 | $objectManager->remove($this->findOr404($id)); |
148 | 148 | $objectManager->flush(); |
149 | 149 | |
150 | 150 | return new SingleResourceResponse(null, new ResponseContext(204)); |
151 | - } |
|
151 | + } |
|
152 | 152 | |
153 | - private function findOr404($id) { |
|
153 | + private function findOr404($id) { |
|
154 | 154 | if (null === $article = $this->articleProvider->getOneById($id)) { |
155 | - throw new NotFoundHttpException('Article was not found.'); |
|
155 | + throw new NotFoundHttpException('Article was not found.'); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | return $article; |
159 | - } |
|
159 | + } |
|
160 | 160 | } |
@@ -32,59 +32,59 @@ |
||
32 | 32 | use Symfony\Component\HttpFoundation\Request; |
33 | 33 | |
34 | 34 | abstract class AbstractAPIController extends Controller { |
35 | - public function listWebhooks(EventDispatcherInterface $eventDispatcher, RepositoryInterface $repository, |
|
36 | - Request $request): ResourcesListResponse { |
|
35 | + public function listWebhooks(EventDispatcherInterface $eventDispatcher, RepositoryInterface $repository, |
|
36 | + Request $request): ResourcesListResponse { |
|
37 | 37 | $webhooks = $repository->getPaginatedByCriteria($eventDispatcher, new Criteria(), $request->query->all('sorting',), new PaginationData($request)); |
38 | 38 | |
39 | 39 | return new ResourcesListResponse($webhooks); |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | - public function getSingleWebhook(WebhookInterface $webhook): SingleResourceResponse { |
|
42 | + public function getSingleWebhook(WebhookInterface $webhook): SingleResourceResponse { |
|
43 | 43 | return new SingleResourceResponse($webhook); |
44 | - } |
|
45 | - |
|
46 | - public function createWebhook( |
|
47 | - RepositoryInterface $ruleRepository, |
|
48 | - FactoryInterface $ruleFactory, |
|
49 | - Request $request, |
|
50 | - FormFactoryInterface $formFactory |
|
51 | - ): SingleResourceResponse { |
|
44 | + } |
|
45 | + |
|
46 | + public function createWebhook( |
|
47 | + RepositoryInterface $ruleRepository, |
|
48 | + FactoryInterface $ruleFactory, |
|
49 | + Request $request, |
|
50 | + FormFactoryInterface $formFactory |
|
51 | + ): SingleResourceResponse { |
|
52 | 52 | $webhook = $ruleFactory->create(); |
53 | 53 | $form = $formFactory->createNamed('', WebhookType::class, $webhook); |
54 | 54 | $form->handleRequest($request); |
55 | 55 | |
56 | 56 | if ($form->isSubmitted() && $form->isValid()) { |
57 | - $ruleRepository->add($webhook); |
|
57 | + $ruleRepository->add($webhook); |
|
58 | 58 | |
59 | - return new SingleResourceResponse($webhook, new ResponseContext(201)); |
|
59 | + return new SingleResourceResponse($webhook, new ResponseContext(201)); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | return new SingleResourceResponse($form, new ResponseContext(400)); |
63 | - } |
|
63 | + } |
|
64 | 64 | |
65 | - public function deleteWebhook(RepositoryInterface $webhookRepository, |
|
65 | + public function deleteWebhook(RepositoryInterface $webhookRepository, |
|
66 | 66 | WebhookInterface $webhook): SingleResourceResponse { |
67 | 67 | $webhookRepository->remove($webhook); |
68 | 68 | |
69 | 69 | return new SingleResourceResponse(null, new ResponseContext(204)); |
70 | - } |
|
71 | - |
|
72 | - public function updateWebhook( |
|
73 | - ObjectManager $objectManager, |
|
74 | - Request $request, |
|
75 | - WebhookInterface $webhook, |
|
76 | - FormFactoryInterface $formFactory |
|
77 | - ): SingleResourceResponse { |
|
70 | + } |
|
71 | + |
|
72 | + public function updateWebhook( |
|
73 | + ObjectManager $objectManager, |
|
74 | + Request $request, |
|
75 | + WebhookInterface $webhook, |
|
76 | + FormFactoryInterface $formFactory |
|
77 | + ): SingleResourceResponse { |
|
78 | 78 | $form = $formFactory->createNamed('', WebhookType::class, $webhook, ['method' => $request->getMethod()]); |
79 | 79 | |
80 | 80 | $form->handleRequest($request); |
81 | 81 | if ($form->isSubmitted() && $form->isValid()) { |
82 | - $objectManager->flush(); |
|
83 | - $objectManager->refresh($webhook); |
|
82 | + $objectManager->flush(); |
|
83 | + $objectManager->refresh($webhook); |
|
84 | 84 | |
85 | - return new SingleResourceResponse($webhook); |
|
85 | + return new SingleResourceResponse($webhook); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | return new SingleResourceResponse($form, new ResponseContext(400)); |
89 | - } |
|
89 | + } |
|
90 | 90 | } |
@@ -32,122 +32,122 @@ |
||
32 | 32 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
33 | 33 | |
34 | 34 | class ContentListsItemLoader extends PaginatedLoader implements LoaderInterface { |
35 | - protected ContentListRepositoryInterface $contentListRepository; |
|
36 | - protected ContentListItemRepositoryInterface $contentListItemsRepository; |
|
37 | - protected MetaFactoryInterface $metaFactory; |
|
38 | - private CacheBlockTagsCollectorInterface $cacheBlocksTagsCollector; |
|
39 | - private EventDispatcherInterface $eventDispatcher; |
|
40 | - |
|
41 | - public function __construct( |
|
42 | - ContentListRepositoryInterface $contentListRepository, |
|
43 | - ContentListItemRepositoryInterface $contentListItemRepository, |
|
44 | - MetaFactoryInterface $metaFactory, |
|
45 | - CacheBlockTagsCollectorInterface $cacheBlocksTagsCollector, |
|
46 | - EventDispatcherInterface $eventDispatcher |
|
47 | - ) { |
|
35 | + protected ContentListRepositoryInterface $contentListRepository; |
|
36 | + protected ContentListItemRepositoryInterface $contentListItemsRepository; |
|
37 | + protected MetaFactoryInterface $metaFactory; |
|
38 | + private CacheBlockTagsCollectorInterface $cacheBlocksTagsCollector; |
|
39 | + private EventDispatcherInterface $eventDispatcher; |
|
40 | + |
|
41 | + public function __construct( |
|
42 | + ContentListRepositoryInterface $contentListRepository, |
|
43 | + ContentListItemRepositoryInterface $contentListItemRepository, |
|
44 | + MetaFactoryInterface $metaFactory, |
|
45 | + CacheBlockTagsCollectorInterface $cacheBlocksTagsCollector, |
|
46 | + EventDispatcherInterface $eventDispatcher |
|
47 | + ) { |
|
48 | 48 | $this->contentListRepository = $contentListRepository; |
49 | 49 | $this->contentListItemsRepository = $contentListItemRepository; |
50 | 50 | $this->metaFactory = $metaFactory; |
51 | 51 | $this->cacheBlocksTagsCollector = $cacheBlocksTagsCollector; |
52 | 52 | $this->eventDispatcher = $eventDispatcher; |
53 | - } |
|
53 | + } |
|
54 | 54 | |
55 | - public function load($type, $parameters = [], $withoutParameters = [], $responseType = LoaderInterface::SINGLE) { |
|
55 | + public function load($type, $parameters = [], $withoutParameters = [], $responseType = LoaderInterface::SINGLE) { |
|
56 | 56 | $criteria = new Criteria(); |
57 | 57 | if (LoaderInterface::COLLECTION === $responseType) { |
58 | - if (array_key_exists('contentListId', $parameters) && is_numeric($parameters['contentListId'])) { |
|
58 | + if (array_key_exists('contentListId', $parameters) && is_numeric($parameters['contentListId'])) { |
|
59 | 59 | $contentList = $this->contentListRepository->findOneBy(['id' => $parameters['contentListId']]); |
60 | 60 | $criteria->set('contentList', $contentList); |
61 | - } elseif (array_key_exists('contentListName', $parameters) && is_string($parameters['contentListName'])) { |
|
61 | + } elseif (array_key_exists('contentListName', $parameters) && is_string($parameters['contentListName'])) { |
|
62 | 62 | $contentList = $this->contentListRepository->findOneBy(['name' => $parameters['contentListName']]); |
63 | 63 | $criteria->set('contentList', $contentList); |
64 | - } elseif ( |
|
65 | - array_key_exists('contentList', $parameters) && |
|
64 | + } elseif ( |
|
65 | + array_key_exists('contentList', $parameters) && |
|
66 | 66 | $parameters['contentList'] instanceof Meta && |
67 | 67 | $parameters['contentList']->getValues() instanceof ContentListInterface |
68 | - ) { |
|
68 | + ) { |
|
69 | 69 | $criteria->set('contentList', $parameters['contentList']->getValues()); |
70 | - } |
|
70 | + } |
|
71 | 71 | |
72 | - if (!$criteria->has('contentList')) { |
|
72 | + if (!$criteria->has('contentList')) { |
|
73 | 73 | return false; |
74 | - } |
|
74 | + } |
|
75 | 75 | |
76 | - if (array_key_exists('sticky', $parameters) && is_bool($parameters['sticky'])) { |
|
76 | + if (array_key_exists('sticky', $parameters) && is_bool($parameters['sticky'])) { |
|
77 | 77 | $criteria->set('sticky', $parameters['sticky']); |
78 | - } |
|
78 | + } |
|
79 | 79 | |
80 | - if (isset($withoutParameters['content']) && !empty($withoutParameters['content'])) { |
|
80 | + if (isset($withoutParameters['content']) && !empty($withoutParameters['content'])) { |
|
81 | 81 | $criteria->set('exclude_content', $withoutParameters['content']); |
82 | - } |
|
83 | - |
|
84 | - $criteria = $this->applyPaginationToCriteria($criteria, $parameters); |
|
85 | - $contentListItems = $this->contentListItemsRepository->getPaginatedByCriteria($this->eventDispatcher, $criteria, $criteria->get('order', [ |
|
86 | - 'sticky' => 'desc', |
|
87 | - ])); |
|
88 | - $itemsCollection = new ArrayCollection($contentListItems->getItems()); |
|
89 | - if ($itemsCollection->count() > 0) { |
|
82 | + } |
|
83 | + |
|
84 | + $criteria = $this->applyPaginationToCriteria($criteria, $parameters); |
|
85 | + $contentListItems = $this->contentListItemsRepository->getPaginatedByCriteria($this->eventDispatcher, $criteria, $criteria->get('order', [ |
|
86 | + 'sticky' => 'desc', |
|
87 | + ])); |
|
88 | + $itemsCollection = new ArrayCollection($contentListItems->getItems()); |
|
89 | + if ($itemsCollection->count() > 0) { |
|
90 | 90 | $metaCollection = new MetaCollection(); |
91 | 91 | $metaCollection->setTotalItemsCount($contentListItems->getTotalItemCount()); |
92 | 92 | foreach ($itemsCollection as $item) { |
93 | - $itemMeta = $this->getItemMeta($item); |
|
94 | - if (null !== $itemMeta) { |
|
93 | + $itemMeta = $this->getItemMeta($item); |
|
94 | + if (null !== $itemMeta) { |
|
95 | 95 | $metaCollection->add($itemMeta); |
96 | - } |
|
96 | + } |
|
97 | 97 | } |
98 | 98 | unset($itemsCollection, $criteria); |
99 | 99 | |
100 | 100 | return $metaCollection; |
101 | - } |
|
101 | + } |
|
102 | 102 | } elseif (LoaderInterface::SINGLE === $responseType) { |
103 | - if (array_key_exists('contentListName', $parameters) && is_string($parameters['contentListName'])) { |
|
103 | + if (array_key_exists('contentListName', $parameters) && is_string($parameters['contentListName'])) { |
|
104 | 104 | $contentList = $this->contentListRepository->findOneBy(['name' => $parameters['contentListName']]); |
105 | 105 | $criteria->set('contentList', $contentList); |
106 | - } elseif ( |
|
107 | - array_key_exists('contentList', $parameters) && |
|
106 | + } elseif ( |
|
107 | + array_key_exists('contentList', $parameters) && |
|
108 | 108 | $parameters['contentList'] instanceof Meta && |
109 | 109 | $parameters['contentList']->getValues() instanceof ContentListInterface |
110 | - ) { |
|
110 | + ) { |
|
111 | 111 | $criteria->set('contentList', $parameters['contentList']->getValues()); |
112 | - } |
|
112 | + } |
|
113 | 113 | |
114 | - if ( |
|
115 | - isset($contentList) |
|
114 | + if ( |
|
115 | + isset($contentList) |
|
116 | 116 | && array_key_exists('article', $parameters) |
117 | 117 | && $parameters['article'] instanceof Meta |
118 | 118 | && $parameters['article']->getValues() instanceof ArticleInterface |
119 | - ) { |
|
119 | + ) { |
|
120 | 120 | /** @var ContentListItemInterface $currentContentListItem */ |
121 | 121 | $currentContentListItem = $this->contentListItemsRepository->getQueryByCriteria(new Criteria([ |
122 | 122 | 'contentList' => $contentList, |
123 | 123 | 'content' => $parameters['article']->getValues(), |
124 | 124 | ]), [], 'n')->getQuery()->getOneOrNullResult(); |
125 | 125 | $position = $currentContentListItem->getPosition(); |
126 | - } |
|
126 | + } |
|
127 | 127 | |
128 | - if (isset($position) && array_key_exists('prev', $parameters) && true === $parameters['prev']) { |
|
128 | + if (isset($position) && array_key_exists('prev', $parameters) && true === $parameters['prev']) { |
|
129 | 129 | ++$position; |
130 | - } elseif (isset($position) && array_key_exists('next', $parameters) && true === $parameters['next']) { |
|
130 | + } elseif (isset($position) && array_key_exists('next', $parameters) && true === $parameters['next']) { |
|
131 | 131 | --$position; |
132 | - } else { |
|
132 | + } else { |
|
133 | 133 | return null; |
134 | - } |
|
134 | + } |
|
135 | 135 | |
136 | - return $this->getItemMeta($this->contentListItemsRepository->getOneOrNullByPosition($criteria, $position)); |
|
136 | + return $this->getItemMeta($this->contentListItemsRepository->getOneOrNullByPosition($criteria, $position)); |
|
137 | + } |
|
137 | 138 | } |
138 | - } |
|
139 | 139 | |
140 | - public function isSupported(string $type): bool { |
|
140 | + public function isSupported(string $type): bool { |
|
141 | 141 | return in_array($type, ['contentListItems', 'contentListItem']); |
142 | - } |
|
142 | + } |
|
143 | 143 | |
144 | - private function getItemMeta($item) { |
|
144 | + private function getItemMeta($item) { |
|
145 | 145 | if (null !== $item) { |
146 | - if ($item instanceof ContentListItemInterface) { |
|
146 | + if ($item instanceof ContentListItemInterface) { |
|
147 | 147 | $this->cacheBlocksTagsCollector->addTagToCurrentCacheBlock('a-' . $item->getContent()->getId()); |
148 | - } |
|
148 | + } |
|
149 | 149 | |
150 | - return $this->metaFactory->create($item); |
|
150 | + return $this->metaFactory->create($item); |
|
151 | + } |
|
151 | 152 | } |
152 | - } |
|
153 | 153 | } |
@@ -32,44 +32,44 @@ discard block |
||
32 | 32 | |
33 | 33 | class ProfileController extends AbstractController { |
34 | 34 | |
35 | - private EntityManagerInterface $entityManager; |
|
36 | - private AuthorizationCheckerInterface $authorizationChecker; |
|
37 | - private UserRepository $userRepository; |
|
38 | - |
|
39 | - /** |
|
40 | - * @param EntityManagerInterface $entityManager |
|
41 | - * @param AuthorizationCheckerInterface $authorizationChecker |
|
42 | - * @param UserRepository $userRepository |
|
43 | - */ |
|
44 | - public function __construct(EntityManagerInterface $entityManager, |
|
45 | - AuthorizationCheckerInterface $authorizationChecker, UserRepository $userRepository) { |
|
35 | + private EntityManagerInterface $entityManager; |
|
36 | + private AuthorizationCheckerInterface $authorizationChecker; |
|
37 | + private UserRepository $userRepository; |
|
38 | + |
|
39 | + /** |
|
40 | + * @param EntityManagerInterface $entityManager |
|
41 | + * @param AuthorizationCheckerInterface $authorizationChecker |
|
42 | + * @param UserRepository $userRepository |
|
43 | + */ |
|
44 | + public function __construct(EntityManagerInterface $entityManager, |
|
45 | + AuthorizationCheckerInterface $authorizationChecker, UserRepository $userRepository) { |
|
46 | 46 | $this->entityManager = $entityManager; |
47 | 47 | $this->authorizationChecker = $authorizationChecker; |
48 | 48 | $this->userRepository = $userRepository; |
49 | - } |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * @Route("/api/{version}/users/profile/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_user_get_user_profile") |
|
54 | - */ |
|
55 | - public function getAction($id) { |
|
52 | + /** |
|
53 | + * @Route("/api/{version}/users/profile/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_user_get_user_profile") |
|
54 | + */ |
|
55 | + public function getAction($id) { |
|
56 | 56 | $requestedUser = $this->userRepository->find($id); |
57 | 57 | if (!is_object($requestedUser) || !$requestedUser instanceof UserInterface) { |
58 | - throw new NotFoundHttpException('Requested user don\'t exists'); |
|
58 | + throw new NotFoundHttpException('Requested user don\'t exists'); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | $this->checkIfCanAccess($requestedUser); |
62 | 62 | |
63 | 63 | return new SingleResourceResponse($requestedUser); |
64 | - } |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @Route("/api/{version}/users/profile/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_user_edit_user_profile") |
|
68 | - */ |
|
69 | - public function editAction(Request $request, $id, UserPasswordEncoderInterface $passwordEncoder) { |
|
66 | + /** |
|
67 | + * @Route("/api/{version}/users/profile/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_user_edit_user_profile") |
|
68 | + */ |
|
69 | + public function editAction(Request $request, $id, UserPasswordEncoderInterface $passwordEncoder) { |
|
70 | 70 | $requestedUser = $this->userRepository->find($id); |
71 | 71 | if (!is_object($requestedUser) || !$requestedUser instanceof UserInterface) { |
72 | - throw new NotFoundHttpException('Requested user don\'t exists'); |
|
72 | + throw new NotFoundHttpException('Requested user don\'t exists'); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | $this->checkIfCanAccess($requestedUser); |
@@ -80,32 +80,32 @@ discard block |
||
80 | 80 | $form->handleRequest($request); |
81 | 81 | |
82 | 82 | if ($form->isSubmitted() && $form->isValid()) { |
83 | - if (!empty($form->get('plainPassword')->getData())) { |
|
83 | + if (!empty($form->get('plainPassword')->getData())) { |
|
84 | 84 | $requestedUser->setPassword( |
85 | 85 | $passwordEncoder->encodePassword( |
86 | 86 | $requestedUser, |
87 | 87 | $form->get('plainPassword')->getData() |
88 | 88 | ) |
89 | 89 | ); |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | - $entityManager = $this->entityManager; |
|
93 | - $entityManager->flush(); |
|
92 | + $entityManager = $this->entityManager; |
|
93 | + $entityManager->flush(); |
|
94 | 94 | |
95 | - return new SingleResourceResponse($requestedUser); |
|
95 | + return new SingleResourceResponse($requestedUser); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | return new SingleResourceResponse($form, new ResponseContext(400)); |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - private function checkIfCanAccess($requestedUser) { |
|
101 | + private function checkIfCanAccess($requestedUser) { |
|
102 | 102 | /** @var UserInterface $currentUser */ |
103 | 103 | $currentUser = $this->getUser(); |
104 | 104 | if ( |
105 | 105 | !$this->authorizationChecker->isGranted('ROLE_ADMIN') && |
106 | 106 | $requestedUser->getId() !== $currentUser->getId() |
107 | 107 | ) { |
108 | - throw new AccessDeniedException('This user does not have access to this section. profile'); |
|
108 | + throw new AccessDeniedException('This user does not have access to this section. profile'); |
|
109 | + } |
|
109 | 110 | } |
110 | - } |
|
111 | 111 | } |
@@ -24,33 +24,33 @@ discard block |
||
24 | 24 | * Class OrganizationAwareThemeUploader. |
25 | 25 | */ |
26 | 26 | final class OrganizationAwareThemeUploader implements ThemeUploaderInterface { |
27 | - /** |
|
28 | - * @var TenantContextInterface |
|
29 | - */ |
|
30 | - private $tenantContext; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - private $baseDir; |
|
36 | - |
|
37 | - /** |
|
38 | - * OrganizationAwareThemeUploader constructor. |
|
39 | - * |
|
40 | - * @param TenantContextInterface $tenantContext |
|
41 | - * @param string $baseDir |
|
42 | - */ |
|
43 | - public function __construct(TenantContextInterface $tenantContext, string $baseDir) { |
|
27 | + /** |
|
28 | + * @var TenantContextInterface |
|
29 | + */ |
|
30 | + private $tenantContext; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + private $baseDir; |
|
36 | + |
|
37 | + /** |
|
38 | + * OrganizationAwareThemeUploader constructor. |
|
39 | + * |
|
40 | + * @param TenantContextInterface $tenantContext |
|
41 | + * @param string $baseDir |
|
42 | + */ |
|
43 | + public function __construct(TenantContextInterface $tenantContext, string $baseDir) { |
|
44 | 44 | $this->tenantContext = $tenantContext; |
45 | 45 | $this->baseDir = $baseDir; |
46 | - } |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * {@inheritdoc} |
|
50 | - */ |
|
51 | - public function upload(UploadedFile $file) { |
|
48 | + /** |
|
49 | + * {@inheritdoc} |
|
50 | + */ |
|
51 | + public function upload(UploadedFile $file) { |
|
52 | 52 | if (null === $this->tenantContext->getTenant()) { |
53 | - throw new \Exception('Tenant was not found in context!'); |
|
53 | + throw new \Exception('Tenant was not found in context!'); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | $destinationFolder = $this->getAvailableThemesPath(); |
@@ -59,48 +59,48 @@ discard block |
||
59 | 59 | |
60 | 60 | $zip = new \ZipArchive(); |
61 | 61 | if (true === $zip->open($filePath)) { |
62 | - if (!$filesystem->exists($destinationFolder)) { |
|
62 | + if (!$filesystem->exists($destinationFolder)) { |
|
63 | 63 | $filesystem->mkdir($destinationFolder); |
64 | - } |
|
65 | - $pathInArray = explode('/', $zip->getNameIndex(0)); |
|
66 | - $themeDirInZip = array_shift($pathInArray); |
|
64 | + } |
|
65 | + $pathInArray = explode('/', $zip->getNameIndex(0)); |
|
66 | + $themeDirInZip = array_shift($pathInArray); |
|
67 | 67 | |
68 | - $themeConfiguration = $zip->getFromName($themeDirInZip . DIRECTORY_SEPARATOR . 'theme.json'); |
|
69 | - if (false === $themeConfiguration) { |
|
68 | + $themeConfiguration = $zip->getFromName($themeDirInZip . DIRECTORY_SEPARATOR . 'theme.json'); |
|
69 | + if (false === $themeConfiguration) { |
|
70 | 70 | throw new \Exception('In ZIP file we expect one directory and theme.json file inside'); |
71 | - } |
|
71 | + } |
|
72 | 72 | |
73 | - $themeConfiguration = \json_decode($themeConfiguration, true); |
|
74 | - if (\JSON_ERROR_NONE !== json_last_error()) { |
|
73 | + $themeConfiguration = \json_decode($themeConfiguration, true); |
|
74 | + if (\JSON_ERROR_NONE !== json_last_error()) { |
|
75 | 75 | throw new \Exception('Theme configuration is not valid. Syntax error in theme.json'); |
76 | - } |
|
76 | + } |
|
77 | 77 | |
78 | - $themeName = $themeConfiguration['name']; |
|
79 | - $unpackedThemePath = $destinationFolder . DIRECTORY_SEPARATOR . $themeDirInZip; |
|
78 | + $themeName = $themeConfiguration['name']; |
|
79 | + $unpackedThemePath = $destinationFolder . DIRECTORY_SEPARATOR . $themeDirInZip; |
|
80 | 80 | |
81 | - if ($filesystem->exists($unpackedThemePath)) { |
|
81 | + if ($filesystem->exists($unpackedThemePath)) { |
|
82 | 82 | $filesystem->remove($unpackedThemePath); |
83 | - } |
|
83 | + } |
|
84 | 84 | |
85 | - $zip->extractTo($destinationFolder); |
|
86 | - $zip->close(); |
|
85 | + $zip->extractTo($destinationFolder); |
|
86 | + $zip->close(); |
|
87 | 87 | |
88 | - $finalPath = $destinationFolder . DIRECTORY_SEPARATOR . str_replace('/', '__', $themeName); |
|
89 | - $filesystem->rename($unpackedThemePath, $finalPath, true); |
|
88 | + $finalPath = $destinationFolder . DIRECTORY_SEPARATOR . str_replace('/', '__', $themeName); |
|
89 | + $filesystem->rename($unpackedThemePath, $finalPath, true); |
|
90 | 90 | |
91 | - return $finalPath; |
|
91 | + return $finalPath; |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | return false; |
95 | - } |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - public function getAvailableThemesPath() { |
|
97 | + /** |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + public function getAvailableThemesPath() { |
|
101 | 101 | $tenant = $this->tenantContext->getTenant(); |
102 | 102 | $organization = $tenant->getOrganization(); |
103 | 103 | $organizationCode = $organization->getCode(); |
104 | 104 | return sprintf($this->baseDir . DIRECTORY_SEPARATOR . ThemeUploaderInterface::AVAILABLE_THEMES_PATH, $organizationCode); |
105 | - } |
|
105 | + } |
|
106 | 106 | } |
@@ -22,10 +22,10 @@ |
||
22 | 22 | class ContentController extends AbstractController |
23 | 23 | { |
24 | 24 | |
25 | - public function __construct() { |
|
26 | - } |
|
25 | + public function __construct() { |
|
26 | + } |
|
27 | 27 | |
28 | - public function renderPageAction(string $contentTemplate): Response |
|
28 | + public function renderPageAction(string $contentTemplate): Response |
|
29 | 29 | { |
30 | 30 | $response = new Response(); |
31 | 31 | $response->headers->set('Content-Type', 'text/html; charset=UTF-8'); |
@@ -28,25 +28,25 @@ discard block |
||
28 | 28 | use FOS\RestBundle\Controller\Annotations\Route; |
29 | 29 | |
30 | 30 | class ArticleSearchController extends AbstractController { |
31 | - private $extraFields; // |
|
32 | - private CachedTenantContext $cachedTenantContext; // swp_multi_tenancy.tenant_context |
|
33 | - private PaginatorInterface $paginator; // knp_paginator |
|
34 | - |
|
35 | - /** |
|
36 | - * @param $extraFields |
|
37 | - * @param CachedTenantContext $cachedTenantContext |
|
38 | - * @param PaginatorInterface $paginator |
|
39 | - */ |
|
40 | - public function __construct($extraFields, CachedTenantContext $cachedTenantContext, PaginatorInterface $paginator) { |
|
31 | + private $extraFields; // |
|
32 | + private CachedTenantContext $cachedTenantContext; // swp_multi_tenancy.tenant_context |
|
33 | + private PaginatorInterface $paginator; // knp_paginator |
|
34 | + |
|
35 | + /** |
|
36 | + * @param $extraFields |
|
37 | + * @param CachedTenantContext $cachedTenantContext |
|
38 | + * @param PaginatorInterface $paginator |
|
39 | + */ |
|
40 | + public function __construct($extraFields, CachedTenantContext $cachedTenantContext, PaginatorInterface $paginator) { |
|
41 | 41 | $this->extraFields = $extraFields; |
42 | 42 | $this->cachedTenantContext = $cachedTenantContext; |
43 | 43 | $this->paginator = $paginator; |
44 | - } |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @Route("/api/{version}/content/articles/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_list_articles") |
|
48 | - */ |
|
49 | - public function searchAction(Request $request, RepositoryManagerInterface $repositoryManager) { |
|
46 | + /** |
|
47 | + * @Route("/api/{version}/content/articles/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_list_articles") |
|
48 | + */ |
|
49 | + public function searchAction(Request $request, RepositoryManagerInterface $repositoryManager) { |
|
50 | 50 | $criteria = $this->createCriteriaFrom($request); |
51 | 51 | $extraFields = $this->extraFields; |
52 | 52 | |
@@ -69,16 +69,16 @@ discard block |
||
69 | 69 | $responseContext->setSerializationGroups($this->getSerializationGroups()); |
70 | 70 | |
71 | 71 | return new ResourcesListResponse($pagination, $responseContext); |
72 | - } |
|
72 | + } |
|
73 | 73 | |
74 | - private function createCriteriaFrom(Request $request): Criteria { |
|
74 | + private function createCriteriaFrom(Request $request): Criteria { |
|
75 | 75 | return Criteria::fromQueryParameters( |
76 | 76 | $request->query->get('term', ''), |
77 | 77 | array_merge($this->createDefaultCriteria($request), $this->createAdditionalCriteria($request) |
78 | 78 | )); |
79 | - } |
|
79 | + } |
|
80 | 80 | |
81 | - private function createDefaultCriteria(Request $request): array { |
|
81 | + private function createDefaultCriteria(Request $request): array { |
|
82 | 82 | $currentTenant = $this->cachedTenantContext->getTenant(); |
83 | 83 | |
84 | 84 | return [ |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | 'limit' => $request->query->get('limit', 10), |
88 | 88 | 'tenantCode' => $currentTenant->getCode(), |
89 | 89 | ]; |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | - protected function getSerializationGroups(): array { |
|
92 | + protected function getSerializationGroups(): array { |
|
93 | 93 | return [ |
94 | 94 | 'Default', |
95 | 95 | 'api_articles_list', |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | 'api_tenant_list', |
103 | 103 | 'api_articles_statistics_list', |
104 | 104 | ]; |
105 | - } |
|
105 | + } |
|
106 | 106 | |
107 | - protected function createAdditionalCriteria(Request $request): array { |
|
107 | + protected function createAdditionalCriteria(Request $request): array { |
|
108 | 108 | return [ |
109 | 109 | 'routes' => array_filter((array)$request->query->get('route', [])), |
110 | 110 | 'statuses' => array_filter((array)$request->query->get('status', [])), |
@@ -116,5 +116,5 @@ discard block |
||
116 | 116 | 'metadata' => array_filter((array)$request->query->get('metadata', [])), |
117 | 117 | 'keywords' => array_filter((array)$request->query->get('keywords', [])), |
118 | 118 | ]; |
119 | - } |
|
119 | + } |
|
120 | 120 | } |
@@ -26,27 +26,27 @@ discard block |
||
26 | 26 | use FOS\RestBundle\Controller\Annotations\Route; |
27 | 27 | |
28 | 28 | class AuthorSearchController extends AbstractController { |
29 | - private RepositoryManagerInterface $repositoryManager; |
|
30 | - private PaginatorInterface $paginator; |
|
31 | - private string $authorClassName; |
|
29 | + private RepositoryManagerInterface $repositoryManager; |
|
30 | + private PaginatorInterface $paginator; |
|
31 | + private string $authorClassName; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @param RepositoryManagerInterface $repositoryManager |
|
35 | - * @param PaginatorInterface $paginator |
|
36 | - * @param string $authorClassName |
|
37 | - */ |
|
38 | - public function __construct(RepositoryManagerInterface $repositoryManager, PaginatorInterface $paginator, |
|
39 | - string $authorClassName) { |
|
33 | + /** |
|
34 | + * @param RepositoryManagerInterface $repositoryManager |
|
35 | + * @param PaginatorInterface $paginator |
|
36 | + * @param string $authorClassName |
|
37 | + */ |
|
38 | + public function __construct(RepositoryManagerInterface $repositoryManager, PaginatorInterface $paginator, |
|
39 | + string $authorClassName) { |
|
40 | 40 | $this->repositoryManager = $repositoryManager; |
41 | 41 | $this->paginator = $paginator; |
42 | 42 | $this->authorClassName = $authorClassName; |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * @Route("/api/{version}/authors/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_authors") |
|
48 | - */ |
|
49 | - public function searchAction(Request $request): ResourcesListResponse { |
|
46 | + /** |
|
47 | + * @Route("/api/{version}/authors/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_authors") |
|
48 | + */ |
|
49 | + public function searchAction(Request $request): ResourcesListResponse { |
|
50 | 50 | $criteria = Criteria::fromQueryParameters( |
51 | 51 | $request->query->get('term', ''), |
52 | 52 | [ |
@@ -87,5 +87,5 @@ discard block |
||
87 | 87 | ); |
88 | 88 | |
89 | 89 | return new ResourcesListResponse($pagination, $responseContext); |
90 | - } |
|
90 | + } |
|
91 | 91 | } |
@@ -51,33 +51,33 @@ discard block |
||
51 | 51 | |
52 | 52 | class AnalyticsExportController extends AbstractController { |
53 | 53 | |
54 | - protected CacheInterface $cacheProvider; |
|
55 | - protected RepositoryInterface $analyticsReportRepository; |
|
56 | - protected Filesystem $filesystem; |
|
57 | - protected CsvReportFileLocationResolver $csvReportFileLocationResolver; |
|
58 | - protected CachedTenantContextInterface $cachedTenantContext; |
|
59 | - protected RouteRepositoryInterface $routeRepository; |
|
60 | - private MessageBusInterface $messageBus; |
|
61 | - private FormFactoryInterface $formFactory; |
|
62 | - private EventDispatcherInterface $eventDispatcher; |
|
63 | - |
|
64 | - /** |
|
65 | - * @param CacheInterface $cacheProvider |
|
66 | - * @param RepositoryInterface $analyticsReportRepository |
|
67 | - * @param Filesystem $filesystem |
|
68 | - * @param CsvReportFileLocationResolver $csvReportFileLocationResolver |
|
69 | - * @param CachedTenantContextInterface $cachedTenantContext |
|
70 | - * @param RouteRepositoryInterface $routeRepository |
|
71 | - * @param MessageBusInterface $messageBus |
|
72 | - * @param FormFactoryInterface $formFactory |
|
73 | - * @param EventDispatcherInterface $eventDispatcher |
|
74 | - */ |
|
75 | - public function __construct(CacheInterface $cacheProvider, |
|
76 | - RepositoryInterface $analyticsReportRepository, Filesystem $filesystem, |
|
77 | - CsvReportFileLocationResolver $csvReportFileLocationResolver, |
|
78 | - CachedTenantContextInterface $cachedTenantContext, |
|
79 | - RouteRepositoryInterface $routeRepository, MessageBusInterface $messageBus, |
|
80 | - FormFactoryInterface $formFactory, EventDispatcherInterface $eventDispatcher) { |
|
54 | + protected CacheInterface $cacheProvider; |
|
55 | + protected RepositoryInterface $analyticsReportRepository; |
|
56 | + protected Filesystem $filesystem; |
|
57 | + protected CsvReportFileLocationResolver $csvReportFileLocationResolver; |
|
58 | + protected CachedTenantContextInterface $cachedTenantContext; |
|
59 | + protected RouteRepositoryInterface $routeRepository; |
|
60 | + private MessageBusInterface $messageBus; |
|
61 | + private FormFactoryInterface $formFactory; |
|
62 | + private EventDispatcherInterface $eventDispatcher; |
|
63 | + |
|
64 | + /** |
|
65 | + * @param CacheInterface $cacheProvider |
|
66 | + * @param RepositoryInterface $analyticsReportRepository |
|
67 | + * @param Filesystem $filesystem |
|
68 | + * @param CsvReportFileLocationResolver $csvReportFileLocationResolver |
|
69 | + * @param CachedTenantContextInterface $cachedTenantContext |
|
70 | + * @param RouteRepositoryInterface $routeRepository |
|
71 | + * @param MessageBusInterface $messageBus |
|
72 | + * @param FormFactoryInterface $formFactory |
|
73 | + * @param EventDispatcherInterface $eventDispatcher |
|
74 | + */ |
|
75 | + public function __construct(CacheInterface $cacheProvider, |
|
76 | + RepositoryInterface $analyticsReportRepository, Filesystem $filesystem, |
|
77 | + CsvReportFileLocationResolver $csvReportFileLocationResolver, |
|
78 | + CachedTenantContextInterface $cachedTenantContext, |
|
79 | + RouteRepositoryInterface $routeRepository, MessageBusInterface $messageBus, |
|
80 | + FormFactoryInterface $formFactory, EventDispatcherInterface $eventDispatcher) { |
|
81 | 81 | $this->cacheProvider = $cacheProvider; |
82 | 82 | $this->analyticsReportRepository = $analyticsReportRepository; |
83 | 83 | $this->filesystem = $filesystem; |
@@ -87,15 +87,15 @@ discard block |
||
87 | 87 | $this->messageBus = $messageBus; |
88 | 88 | $this->formFactory = $formFactory; |
89 | 89 | $this->eventDispatcher = $eventDispatcher; |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * @FosRoute("/api/{version}/export/analytics/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_analytics_export_post") |
|
95 | - * |
|
96 | - * @throws \Exception |
|
97 | - */ |
|
98 | - public function post(Request $request): SingleResourceResponseInterface { |
|
93 | + /** |
|
94 | + * @FosRoute("/api/{version}/export/analytics/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_analytics_export_post") |
|
95 | + * |
|
96 | + * @throws \Exception |
|
97 | + */ |
|
98 | + public function post(Request $request): SingleResourceResponseInterface { |
|
99 | 99 | /** @var UserInterface $currentlyLoggedInUser */ |
100 | 100 | $currentlyLoggedInUser = $this->getUser(); |
101 | 101 | |
@@ -106,46 +106,46 @@ discard block |
||
106 | 106 | $form->handleRequest($request); |
107 | 107 | |
108 | 108 | if ($form->isSubmitted() && $form->isValid()) { |
109 | - $data = $form->getData(); |
|
109 | + $data = $form->getData(); |
|
110 | 110 | |
111 | - $analyticsReport = new AnalyticsReport(); |
|
112 | - $analyticsReport->setAssetId($fileName); |
|
113 | - $analyticsReport->setFileExtension('csv'); |
|
114 | - $analyticsReport->setUser($currentlyLoggedInUser); |
|
111 | + $analyticsReport = new AnalyticsReport(); |
|
112 | + $analyticsReport->setAssetId($fileName); |
|
113 | + $analyticsReport->setFileExtension('csv'); |
|
114 | + $analyticsReport->setUser($currentlyLoggedInUser); |
|
115 | 115 | |
116 | - $exportAnalytics = new ExportAnalytics( |
|
117 | - $data['start'], |
|
118 | - $data['end'], |
|
119 | - $this->cachedTenantContext->getTenant()->getCode(), |
|
120 | - $fileName, |
|
121 | - $currentlyLoggedInUser->getEmail(), |
|
122 | - !empty($data['routes']) ? $this->toIds($data['routes']) : [], |
|
123 | - !empty($data['authors']) ? $this->toIds($data['authors']) : [], |
|
124 | - $data['term'] ?? '' |
|
125 | - ); |
|
116 | + $exportAnalytics = new ExportAnalytics( |
|
117 | + $data['start'], |
|
118 | + $data['end'], |
|
119 | + $this->cachedTenantContext->getTenant()->getCode(), |
|
120 | + $fileName, |
|
121 | + $currentlyLoggedInUser->getEmail(), |
|
122 | + !empty($data['routes']) ? $this->toIds($data['routes']) : [], |
|
123 | + !empty($data['authors']) ? $this->toIds($data['authors']) : [], |
|
124 | + $data['term'] ?? '' |
|
125 | + ); |
|
126 | 126 | |
127 | - $filters = $this->processFilters( |
|
128 | - $exportAnalytics->getFilters(), |
|
129 | - !empty($data['routes']) ? $data['routes'] : [], |
|
130 | - !empty($data['authors']) ? $data['authors'] : [] |
|
131 | - ); |
|
127 | + $filters = $this->processFilters( |
|
128 | + $exportAnalytics->getFilters(), |
|
129 | + !empty($data['routes']) ? $data['routes'] : [], |
|
130 | + !empty($data['authors']) ? $data['authors'] : [] |
|
131 | + ); |
|
132 | 132 | |
133 | - $analyticsReport->setFilters($filters); |
|
133 | + $analyticsReport->setFilters($filters); |
|
134 | 134 | |
135 | - $this->analyticsReportRepository->add($analyticsReport); |
|
135 | + $this->analyticsReportRepository->add($analyticsReport); |
|
136 | 136 | |
137 | - $this->messageBus->dispatch($exportAnalytics); |
|
137 | + $this->messageBus->dispatch($exportAnalytics); |
|
138 | 138 | |
139 | - return new SingleResourceResponse(['status' => 'OK'], new ResponseContext(201)); |
|
139 | + return new SingleResourceResponse(['status' => 'OK'], new ResponseContext(201)); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | return new SingleResourceResponse($form, new ResponseContext(400)); |
143 | - } |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * @FosRoute("/api/{version}/export/analytics/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_analytics_reports") |
|
147 | - */ |
|
148 | - public function listAction(Request $request): ResourcesListResponseInterface { |
|
145 | + /** |
|
146 | + * @FosRoute("/api/{version}/export/analytics/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_analytics_reports") |
|
147 | + */ |
|
148 | + public function listAction(Request $request): ResourcesListResponseInterface { |
|
149 | 149 | $sorting = $request->query->all('sorting'); |
150 | 150 | $reports = $this->analyticsReportRepository->getPaginatedByCriteria( |
151 | 151 | $this->eventDispatcher, |
@@ -155,21 +155,21 @@ discard block |
||
155 | 155 | ); |
156 | 156 | |
157 | 157 | return new ResourcesListResponse($reports); |
158 | - } |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * @Route("/analytics/export/{fileName}", methods={"GET"}, options={"expose"=true}, requirements={"mediaId"=".+"}, name="swp_export_analytics_download") |
|
162 | - */ |
|
163 | - public function downloadFile(string $fileName): Response { |
|
160 | + /** |
|
161 | + * @Route("/analytics/export/{fileName}", methods={"GET"}, options={"expose"=true}, requirements={"mediaId"=".+"}, name="swp_export_analytics_download") |
|
162 | + */ |
|
163 | + public function downloadFile(string $fileName): Response { |
|
164 | 164 | $cacheKey = md5(serialize(['analytics_report', $fileName])); |
165 | 165 | |
166 | 166 | $analyticsReport = $this->cacheProvider->get($cacheKey, function () use ($fileName) { |
167 | - /* @var AnalyticsReportInterface|null $analyticsReport */ |
|
168 | - return $this->analyticsReportRepository->findOneBy(['assetId' => $fileName]); |
|
167 | + /* @var AnalyticsReportInterface|null $analyticsReport */ |
|
168 | + return $this->analyticsReportRepository->findOneBy(['assetId' => $fileName]); |
|
169 | 169 | }); |
170 | 170 | |
171 | 171 | if (null === $analyticsReport) { |
172 | - throw new NotFoundHttpException('Report file was not found.'); |
|
172 | + throw new NotFoundHttpException('Report file was not found.'); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | $response = new Response(); |
@@ -188,30 +188,30 @@ discard block |
||
188 | 188 | $response->setContent($this->filesystem->read($this->csvReportFileLocationResolver->getMediaBasePath() . '/' . $analyticsReport->getAssetId())); |
189 | 189 | |
190 | 190 | return $response; |
191 | - } |
|
191 | + } |
|
192 | 192 | |
193 | - private function toIds(array $items): array { |
|
193 | + private function toIds(array $items): array { |
|
194 | 194 | $ids = []; |
195 | 195 | foreach ($items as $item) { |
196 | - foreach ($item as $entity) { |
|
196 | + foreach ($item as $entity) { |
|
197 | 197 | if (!$entity instanceof PersistableInterface) { |
198 | - continue; |
|
198 | + continue; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | $ids[] = $entity->getId(); |
202 | - } |
|
202 | + } |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | return $ids; |
206 | - } |
|
206 | + } |
|
207 | 207 | |
208 | - private function processFilters(array $filters, array $routes, array $authors): array { |
|
208 | + private function processFilters(array $filters, array $routes, array $authors): array { |
|
209 | 209 | $routeNames = []; |
210 | 210 | |
211 | 211 | foreach ($routes as $route) { |
212 | - foreach ($route as $entity) { |
|
212 | + foreach ($route as $entity) { |
|
213 | 213 | $routeNames[] = $entity->getName(); |
214 | - } |
|
214 | + } |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | $filters['routes'] = $routeNames; |
@@ -219,13 +219,13 @@ discard block |
||
219 | 219 | $authorNames = []; |
220 | 220 | /** @var ArticleAuthorInterface $author */ |
221 | 221 | foreach ($authors as $author) { |
222 | - foreach ($author as $entity) { |
|
222 | + foreach ($author as $entity) { |
|
223 | 223 | $authorNames[] = $entity->getName(); |
224 | - } |
|
224 | + } |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | $filters['authors'] = $authorNames; |
228 | 228 | |
229 | 229 | return $filters; |
230 | - } |
|
230 | + } |
|
231 | 231 | } |