fixed search
This commit is contained in:
		
							parent
							
								
									3d55e50750
								
							
						
					
					
						commit
						36800804e4
					
				| @ -13,22 +13,26 @@ use GuzzleHttp\Client; | |||||||
| class SearchController extends AbstractController | class SearchController extends AbstractController | ||||||
| { | { | ||||||
| 
 | 
 | ||||||
|     private static function addFruitToAlbums(array $releases,string $fruit,EntityManagerInterface $entityManager):void{ |     private static function addFruitToAlbums(array $releases, string $fruit, EntityManagerInterface $entityManager): void | ||||||
|         foreach($releases as $release){ |     { | ||||||
|  |         foreach ($releases as $release) { | ||||||
|             $id = $release["id"]; |             $id = $release["id"]; | ||||||
|             $album = $entityManager->getRepository(Album::class)->findBy( |             $album = $entityManager->getRepository(Album::class)->findBy( | ||||||
|                 ['album_id' => $id] |                 ['album_id' => $id] | ||||||
|             ); |             ); | ||||||
|             if (!$album) { | 
 | ||||||
|  |             if (count($album) == 0) { | ||||||
|                 $album = new Album(); |                 $album = new Album(); | ||||||
|                 $album->setAlbumId($id); |                 $album->setAlbumId($id); | ||||||
|                 //https://symfony.com/doc/current/doctrine.html#persisting-objects-to-the-database
 |                 //https://symfony.com/doc/current/doctrine.html#persisting-objects-to-the-database
 | ||||||
|                 $entityManager->persist($album); |                 $entityManager->persist($album); | ||||||
|                 $entityManager->flush(); |                 $entityManager->flush(); | ||||||
|  |             } else { | ||||||
|  |                 $album = $album[0]; | ||||||
|             } |             } | ||||||
|             $album_fruit = $album->getFruits(); |             $album_fruit = $album->getFruits(); | ||||||
|             if (!str_contains($album_fruit, $fruit)){ |             if (!str_contains($album_fruit, $fruit)) { | ||||||
|                 $album->setFruits($album_fruit.$fruit); |                 $album->setFruits($album_fruit . $fruit); | ||||||
|                 //https://symfony.com/doc/current/doctrine.html#persisting-objects-to-the-database
 |                 //https://symfony.com/doc/current/doctrine.html#persisting-objects-to-the-database
 | ||||||
|                 $entityManager->persist($album); |                 $entityManager->persist($album); | ||||||
|                 $entityManager->flush(); |                 $entityManager->flush(); | ||||||
| @ -36,8 +40,9 @@ class SearchController extends AbstractController | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private static function getEmojiName(string $emoji) : string { |     private static function getEmojiName(string $emoji): string | ||||||
|         switch ($emoji){ |     { | ||||||
|  |         switch ($emoji) { | ||||||
|             case "🍎": |             case "🍎": | ||||||
|                 return "apple"; |                 return "apple"; | ||||||
|             case "🍐": |             case "🍐": | ||||||
| @ -119,7 +124,7 @@ class SearchController extends AbstractController | |||||||
|             "per_page" => "15", |             "per_page" => "15", | ||||||
|         ]); |         ]); | ||||||
| 
 | 
 | ||||||
|         SearchController::addFruitToAlbums($result["results"],$fruit,$entityManager); |         SearchController::addFruitToAlbums($result["results"], $fruit, $entityManager); | ||||||
| 
 | 
 | ||||||
|         return $this->render('search/search.html.twig', [ |         return $this->render('search/search.html.twig', [ | ||||||
|             'controller_name' => 'SearchController', |             'controller_name' => 'SearchController', | ||||||
|  | |||||||
| @ -9,7 +9,7 @@ | |||||||
| </style> | </style> | ||||||
| 
 | 
 | ||||||
| <div class="example-wrapper"> | <div class="example-wrapper"> | ||||||
|     <h1>results for {{ query }} with {{fruit_emoji}} ✅</h1> |     <h1>Results for "{{ query }}" with {{fruit_emoji}}:</h1> | ||||||
|     {% for result in results %} |     {% for result in results %} | ||||||
|         {% set array = result['title']|split('-') %} |         {% set array = result['title']|split('-') %} | ||||||
|         {% set artist = array[0] %} |         {% set artist = array[0] %} | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user