@@ -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,32 +102,32 @@ 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/article/search-code", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles_by_code", requirements={"code"=".+"}) |
|
122 | - */ |
|
123 | - public function getByCodeAction(Request $request): SingleResourceResponseInterface { |
|
120 | + /** |
|
121 | + * @Route("/api/{version}/content/article/search-code", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles_by_code", requirements={"code"=".+"}) |
|
122 | + */ |
|
123 | + public function getByCodeAction(Request $request): SingleResourceResponseInterface { |
|
124 | 124 | // Extract parameters from the request |
125 | 125 | $code = $request->query->get('code', ''); |
126 | 126 | $article = $this->entityManager->getRepository('SWP\Bundle\ContentBundle\Model\Article') |
127 | 127 | ->findOneBy(['code' => $code]); |
128 | 128 | |
129 | 129 | if (null === $article) { |
130 | - throw new NotFoundHttpException('Article was not found'); |
|
130 | + throw new NotFoundHttpException('Article was not found'); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | $article->setStatus('new'); |
@@ -139,10 +139,10 @@ discard block |
||
139 | 139 | // Find the swp_package associated with the article |
140 | 140 | $qb = $this->entityManager->createQueryBuilder(); |
141 | 141 | $qb->select('p') |
142 | - ->from('SWP\Bundle\CoreBundle\Model\Package', 'p') |
|
143 | - ->innerJoin('SWP\Bundle\CoreBundle\Model\Article', 'a', 'WITH', 'a.package = p') |
|
144 | - ->where('a.id = :articleId') |
|
145 | - ->setParameter('articleId', $article->getId()); |
|
142 | + ->from('SWP\Bundle\CoreBundle\Model\Package', 'p') |
|
143 | + ->innerJoin('SWP\Bundle\CoreBundle\Model\Article', 'a', 'WITH', 'a.package = p') |
|
144 | + ->where('a.id = :articleId') |
|
145 | + ->setParameter('articleId', $article->getId()); |
|
146 | 146 | |
147 | 147 | $swpPackage = $qb->getQuery()->getOneOrNullResult(); |
148 | 148 | |
@@ -155,12 +155,12 @@ discard block |
||
155 | 155 | } |
156 | 156 | |
157 | 157 | return new SingleResourceResponse($article); |
158 | - } |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * @Route("/api/{version}/content/articles/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_update_articles", requirements={"id"=".+"}) |
|
162 | - */ |
|
163 | - public function updateAction(Request $request, $id): SingleResourceResponseInterface { |
|
160 | + /** |
|
161 | + * @Route("/api/{version}/content/articles/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_update_articles", requirements={"id"=".+"}) |
|
162 | + */ |
|
163 | + public function updateAction(Request $request, $id): SingleResourceResponseInterface { |
|
164 | 164 | $objectManager = $this->entityManager; |
165 | 165 | $article = $this->findOr404($id); |
166 | 166 | $originalArticleStatus = $article->getStatus(); |
@@ -169,32 +169,32 @@ discard block |
||
169 | 169 | |
170 | 170 | $form->handleRequest($request); |
171 | 171 | if ($form->isSubmitted() && $form->isValid()) { |
172 | - $this->articleService->reactOnStatusChange($originalArticleStatus, $article); |
|
173 | - $objectManager->flush(); |
|
174 | - $objectManager->refresh($article); |
|
172 | + $this->articleService->reactOnStatusChange($originalArticleStatus, $article); |
|
173 | + $objectManager->flush(); |
|
174 | + $objectManager->refresh($article); |
|
175 | 175 | |
176 | - return new SingleResourceResponse($article); |
|
176 | + return new SingleResourceResponse($article); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | return new SingleResourceResponse($form, new ResponseContext(500)); |
180 | - } |
|
180 | + } |
|
181 | 181 | |
182 | - /** |
|
183 | - * @Route("/api/{version}/content/articles/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_delete_articles", requirements={"id"=".+"}) |
|
184 | - */ |
|
185 | - public function deleteAction($id): SingleResourceResponseInterface { |
|
182 | + /** |
|
183 | + * @Route("/api/{version}/content/articles/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_delete_articles", requirements={"id"=".+"}) |
|
184 | + */ |
|
185 | + public function deleteAction($id): SingleResourceResponseInterface { |
|
186 | 186 | $objectManager = $this->entityManager; |
187 | 187 | $objectManager->remove($this->findOr404($id)); |
188 | 188 | $objectManager->flush(); |
189 | 189 | |
190 | 190 | return new SingleResourceResponse(null, new ResponseContext(204)); |
191 | - } |
|
191 | + } |
|
192 | 192 | |
193 | - private function findOr404($id) { |
|
193 | + private function findOr404($id) { |
|
194 | 194 | if (null === $article = $this->articleProvider->getOneById($id)) { |
195 | - throw new NotFoundHttpException('Article was not found.'); |
|
195 | + throw new NotFoundHttpException('Article was not found.'); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | return $article; |
199 | - } |
|
199 | + } |
|
200 | 200 | } |