| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the ONGR package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) NFQ Technologies UAB <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace ONGR\SettingsBundle\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use ONGR\ElasticsearchBundle\Result\DocumentIterator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use ONGR\ElasticsearchBundle\Service\Repository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use ONGR\ElasticsearchDSL\Aggregation\TermsAggregation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use ONGR\ElasticsearchDSL\Aggregation\TopHitsAggregation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use ONGR\ElasticsearchDSL\Search; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use ONGR\ElasticsearchBundle\Result\Aggregation\AggregationValue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use ONGR\SettingsBundle\Document\Setting; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use ONGR\SettingsBundle\Service\SettingsManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Symfony\Component\HttpFoundation\JsonResponse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use Symfony\Component\HttpFoundation\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use Symfony\Component\HttpFoundation\Response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * Class ProfileController. Placeholder for settings bundle profiles page. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | class ProfilesController extends Controller | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * Renders profiles page. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @param Request $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @return Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     public function listAction(Request $request) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         return $this->render( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             'ONGRSettingsBundle:Profiles:list.html.twig', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             [] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * Returns a json list of profiles | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * @param Request $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * @return Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     public function getAllProfilesAction(Request $request) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $profiles = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $repo = $this->get($this->getParameter('ongr_settings.repo')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         /** @var DocumentIterator $result */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $result = $repo->execute( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             (new Search())->addAggregation(new TermsAggregation('profiles', 'profile')) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         /** @var AggregationValue $agg */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         foreach ($result->getAggregation('profiles') as $agg) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             $profiles[] = $agg->getValue('key'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         if (empty($profiles) || !in_array('default', $profiles)) array_unshift($profiles, 'default'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         return new JsonResponse($profiles); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * Returns a json list of profiles | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @return Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     public function getFullProfilesAction() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $profiles = $this->get('ongr_settings.settings_manager')->getAllProfiles(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         return new JsonResponse( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             ['count' => count($profiles), 'documents' => $profiles] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 87 |  |  |     public function toggleProfileAction(Request $request) | 
            
                                                        
            
                                    
            
            
                | 88 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |         $setting = $this->get('ongr_settings.settings_manager') | 
            
                                                        
            
                                    
            
            
                | 90 |  |  |             ->get($this->getParameter('ongr_settings.active_profiles')); | 
            
                                                        
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 92 |  |  |         $name = $request->get('name'); | 
            
                                                        
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 94 |  |  |         if ($setting) { | 
            
                                                        
            
                                    
            
            
                | 95 |  |  |             $activeProfiles = $setting->getValue(); | 
            
                                                        
            
                                    
            
            
                | 96 |  |  |         } else { | 
            
                                                        
            
                                    
            
            
                | 97 |  |  |             $activeProfiles = []; | 
            
                                                        
            
                                    
            
            
                | 98 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 100 |  |  |         $key = array_search($name, $activeProfiles); | 
            
                                                        
            
                                    
            
            
                | 101 |  |  |         if ($key === false) { | 
            
                                                        
            
                                    
            
            
                | 102 |  |  |             $activeProfiles[] = $name; | 
            
                                                        
            
                                    
            
            
                | 103 |  |  |         } else { | 
            
                                                        
            
                                    
            
            
                | 104 |  |  |             unset($activeProfiles[$key]); | 
            
                                                        
            
                                    
            
            
                | 105 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 107 |  |  |         $this->get('ongr_settings.settings_manager')->update($this->getParameter('ongr_settings.active_profiles'), [ | 
            
                                                        
            
                                    
            
            
                | 108 |  |  |             'value' => $activeProfiles | 
            
                                                        
            
                                    
            
            
                | 109 |  |  |         ]); | 
            
                                                        
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 111 |  |  |         $this->get('ong_settings.cache_provider')->deleteAll(); | 
            
                                                        
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 113 |  |  |         return new JsonResponse(['error' => false]); | 
            
                                                        
            
                                    
            
            
                | 114 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 115 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 116 |  |  |  | 
            
                        
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.