| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * This file is part of the Superdesk Web Publisher ElasticSearch Bundle. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * Copyright 2017 Sourcefabric z.ú. and contributors. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * For the full copyright and license information, please see the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * AUTHORS and LICENSE files distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @copyright 2017 Sourcefabric z.ú | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @license http://www.superdesk.org/license | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | namespace SWP\Bundle\ElasticSearchBundle\Controller\Api; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use FOS\ElasticaBundle\Manager\RepositoryManagerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use SWP\Bundle\ElasticSearchBundle\Criteria\Criteria; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use SWP\Component\Common\Response\ResourcesListResponse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use SWP\Component\Common\Response\ResponseContext; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use Symfony\Component\HttpFoundation\Request; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 25 |  |  | use Symfony\Component\Routing\Annotation\Route; | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  | class AuthorSearchController extends AbstractController | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     private RepositoryManagerInterface $repositoryManager; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     private string $authorClassName; | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     public function __construct(RepositoryManagerInterface $repositoryManager, string $authorClassName) | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |         $this->repositoryManager = $repositoryManager; | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |         $this->authorClassName = $authorClassName; | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |      * @Route("/api/{version}/authors/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_authors") | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |     public function searchAction(Request $request): ResourcesListResponse | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |         $criteria = Criteria::fromQueryParameters( | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |             $request->query->get('term', ''), | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |             [ | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |                 'page' => $request->query->get('page'), | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |                 'sort' => $request->query->get('sorting'), | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |                 'limit' => $request->query->get('limit', 10), | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |             ] | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |         $result = $this->repositoryManager | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |             ->getRepository($this->authorClassName) | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |             ->findByCriteria($criteria); | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |         $pagination = $this->get('knp_paginator')->paginate( | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |             $result, | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |             $request->query->get('page', 1), | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |             $criteria->getPagination()->getItemsPerPage() | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |         $responseContext = new ResponseContext(); | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |         $responseContext->setSerializationGroups( | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |             [ | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |                 'Default', | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |                 'api_packages_list', | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |                 'api_packages_items_list', | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |                 'api_tenant_list', | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |                 'api_articles_list', | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |                 'api_articles_slideshows', | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |                 'api_articles_featuremedia', | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |                 'api_articles_statistics_list', | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |                 'api_article_authors', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                 'api_article_media_list', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |                 'api_article_media_renditions', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |                 'api_image_details', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                 'api_groups_list', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |                 'api_routes_list', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         return new ResourcesListResponse($pagination, $responseContext); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 85 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 86 |  |  |  |