Merge branch 'main' of gitpro:ThomasRubini/ProjetSymfony
This commit is contained in:
commit
b3e8ec540a
@ -155,6 +155,10 @@ main:is(#searchResults, #favorites) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main#favorites > div.results > :not(section.fav) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
section.album {
|
section.album {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@ -167,8 +171,20 @@ section.album {
|
|||||||
transition: all ease-out 0.15s;
|
transition: all ease-out 0.15s;
|
||||||
box-shadow: var(--shadow);
|
box-shadow: var(--shadow);
|
||||||
border-radius: var(--radius);
|
border-radius: var(--radius);
|
||||||
|
& > button.toFav {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
& > p.alreadyFav {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
&.fav {
|
&.fav {
|
||||||
transform: rotate(-1deg);
|
transform: rotate(-1deg);
|
||||||
|
& > p.alreadyFav {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
& > button.toFav {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
&:hover {
|
&:hover {
|
||||||
transform: scale(1.01);
|
transform: scale(1.01);
|
||||||
|
|||||||
@ -8,13 +8,13 @@ use Symfony\Component\HttpFoundation\Response;
|
|||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
Use App\Utils;
|
use App\Utils;
|
||||||
|
|
||||||
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(
|
||||||
@ -37,7 +37,8 @@ class SearchController extends AbstractController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getEmojiName(string | null $emoji) : string | null {
|
private static function getEmojiName(string | null $emoji): string | null
|
||||||
|
{
|
||||||
return match ($emoji) {
|
return match ($emoji) {
|
||||||
"🍎" => "apple",
|
"🍎" => "apple",
|
||||||
"🍐" => "pear",
|
"🍐" => "pear",
|
||||||
@ -62,18 +63,18 @@ class SearchController extends AbstractController
|
|||||||
public function index(Request $request, EntityManagerInterface $entityManager): Response
|
public function index(Request $request, EntityManagerInterface $entityManager): Response
|
||||||
{
|
{
|
||||||
$page = $request->query->get('page');
|
$page = $request->query->get('page');
|
||||||
if ($page== null) $page = 1;
|
if ($page == null) $page = 1;
|
||||||
$fruit = $request->query->get('fruit');
|
$fruit = $request->query->get('fruit');
|
||||||
$user_query = $request->query->get('q');
|
$user_query = $request->query->get('q');
|
||||||
|
|
||||||
$fruit_emoji = SearchController::getEmojiName($fruit);
|
$fruit_name = SearchController::getEmojiName($fruit);
|
||||||
if ($fruit_emoji == null) {
|
if ($fruit_name == null) {
|
||||||
// We do not support requests without a fruit or with an invalid one
|
// We do not support requests without a fruit or with an invalid one
|
||||||
// Redirect to the homepage in this case
|
// Redirect to the homepage in this case
|
||||||
return $this->redirect('/');
|
return $this->redirect('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
$fruit_query = $user_query . " " . $fruit_emoji;
|
$fruit_query = $user_query . " " . $fruit_name;
|
||||||
$page_str = strval($page);
|
$page_str = strval($page);
|
||||||
$response = Utils::makeRequest("GET", "/database/search", [
|
$response = Utils::makeRequest("GET", "/database/search", [
|
||||||
"q" => $fruit_query,
|
"q" => $fruit_query,
|
||||||
@ -86,30 +87,30 @@ class SearchController extends AbstractController
|
|||||||
SearchController::addFruitToAlbums($results, $fruit, $entityManager);
|
SearchController::addFruitToAlbums($results, $fruit, $entityManager);
|
||||||
$user = $this->getUser();
|
$user = $this->getUser();
|
||||||
$array_id = array();
|
$array_id = array();
|
||||||
foreach($user->getLiked() as $like){
|
foreach ($user->getLiked() as $like) {
|
||||||
array_push(
|
array_push(
|
||||||
$array_id,
|
$array_id,
|
||||||
$like->getAlbumId()
|
$like->getAlbumId()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$true_results = array();
|
$true_results = array();
|
||||||
foreach($results as $result){
|
foreach ($results as $result) {
|
||||||
|
|
||||||
|
$isLiked = in_array($result["id"], $array_id);
|
||||||
|
|
||||||
$isLiked = in_array($result["id"],$array_id);
|
|
||||||
|
|
||||||
$result = array_merge(
|
$result = array_merge(
|
||||||
$result,
|
$result,
|
||||||
["isLiked" => $isLiked? "true": "false"]
|
["isLiked" => $isLiked ? "true" : "false"]
|
||||||
);
|
);
|
||||||
array_push($true_results,$result);
|
array_push($true_results, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
$results = $true_results;
|
$results = $true_results;
|
||||||
|
|
||||||
return $this->render('search/search.html.twig', [
|
return $this->render('search/search.html.twig', [
|
||||||
'controller_name' => 'SearchController',
|
'controller_name' => 'SearchController',
|
||||||
'query' => $user_query,
|
'query' => $user_query,
|
||||||
'fruit_emoji' => $fruit_emoji,
|
'fruit_emoji' => $fruit,
|
||||||
'fruit_name' => SearchController::getEmojiName($fruit),
|
'fruit_name' => SearchController::getEmojiName($fruit),
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
'all_page' => $response["pagination"]["pages"],
|
'all_page' => $response["pagination"]["pages"],
|
||||||
|
|||||||
@ -10,7 +10,6 @@
|
|||||||
fetch("/favorite/remove/" + id).then((data) => {
|
fetch("/favorite/remove/" + id).then((data) => {
|
||||||
if (data.status == 200) {
|
if (data.status == 200) {
|
||||||
document.querySelector("#id" + id).classList.remove("fav");
|
document.querySelector("#id" + id).classList.remove("fav");
|
||||||
alert("Removed from favs");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -21,8 +20,10 @@
|
|||||||
{% set main_artist = album_liked["artists_sort"] %}
|
{% set main_artist = album_liked["artists_sort"] %}
|
||||||
{% set artists = album_liked["artists"] %}
|
{% set artists = album_liked["artists"] %}
|
||||||
{% set album = album_liked["title"] %}
|
{% set album = album_liked["title"] %}
|
||||||
<section class="album fav">
|
{% set fruit = album_liked["fruit"] %}
|
||||||
|
<section class="album fav" id="id{{album_liked['id']}}">
|
||||||
<span>
|
<span>
|
||||||
|
<h1>{{fruit}}</h1>
|
||||||
<h2>{{album}}</h2>
|
<h2>{{album}}</h2>
|
||||||
by
|
by
|
||||||
{% for artist in artists %}
|
{% for artist in artists %}
|
||||||
|
|||||||
@ -7,7 +7,6 @@ endblock %} {% block body %}
|
|||||||
fetch("/favorite/add/" + id).then((data) => {
|
fetch("/favorite/add/" + id).then((data) => {
|
||||||
if (data.status == 200) {
|
if (data.status == 200) {
|
||||||
document.querySelector("#id" + id).classList.add("fav");
|
document.querySelector("#id" + id).classList.add("fav");
|
||||||
alert("Added to favs");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -31,16 +30,13 @@ endblock %} {% block body %}
|
|||||||
src="{{result['cover_image']}}"
|
src="{{result['cover_image']}}"
|
||||||
alt="{{album ~ ' by ' ~ artist}}"
|
alt="{{album ~ ' by ' ~ artist}}"
|
||||||
/>
|
/>
|
||||||
{% if result['isLiked'] == 'true' %}
|
<p class="alreadyFav">
|
||||||
<p>
|
|
||||||
<b>Already fav</b>, go to
|
<b>Already fav</b>, go to
|
||||||
<a href="{{url('app_favorite')}}">favorites</a>
|
<a href="{{url('app_favorite')}}">favorites</a>
|
||||||
</p>
|
</p>
|
||||||
{% else %}
|
<button class="toFav" onclick="addToFavs({{result['id']}})">
|
||||||
<button onclick="addToFavs({{result['id']}})">
|
|
||||||
Add to favorites
|
Add to favorites
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
|
||||||
</section>
|
</section>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user