search + fix

pull/26/head
remrem 10 months ago
parent 8f9c4a6d9f
commit 3c5724cbab

@ -1,5 +1,11 @@
.form-container { .form-container {
&.form-row {
display: flex;
flex-direction: row;
align-items: center;
}
.form-group { .form-group {
display: flex; display: flex;
flex-direction: column; flex-direction: column;

@ -0,0 +1,31 @@
.wrapper {
display: flex;
flex-direction: column;
width: 70%;
background-color: #f2f2f7;
margin: 0 auto;
padding: 20px;
border-radius: 1rem;
margin-top: 5vh;
border: 3px solid black;
gap: 1rem;
.form-container {
#simple_search {
display: flex;
flex-direction: row;
align-items: center;
gap: 2rem;
justify-content: space-between;
:first-child {
width: 100%;
}
#simple_search_search {
display: flex;
flex-grow: 1;
}
}
}
}

@ -10,6 +10,7 @@ use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Post; use App\Entity\Post;
use App\Form\Type\PostType; use App\Form\Type\PostType;
use App\Form\Type\CommentType; use App\Form\Type\CommentType;
use App\Form\Type\SimpleSearchType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class PostController extends AbstractController class PostController extends AbstractController
@ -28,7 +29,7 @@ class PostController extends AbstractController
$posts = $this->em->getRepository(Post::class)->findAll(); $posts = $this->em->getRepository(Post::class)->findAll();
return $this->render('post/all.html.twig', [ return $this->render('post/all.html.twig', [
"posts" => $posts, "posts" => array_reverse($posts),
"title" => "Derniers Posts" "title" => "Derniers Posts"
]); ]);
} }
@ -135,4 +136,27 @@ class PostController extends AbstractController
'form' => $form, 'form' => $form,
]); ]);
} }
#[Route('/post/search', name: 'search_post', methods: ['GET', 'POST'])]
public function searchPost(Request $request): Response
{
$form = $this->createForm(SimpleSearchType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$searchString = $form->get('search')->getData();
$posts = $this->em->getRepository(Post::class)->searchByTitleOrText($searchString);
return $this->render('post/search.html.twig', [
'posts' => $posts,
'form' => $this->createForm(SimpleSearchType::class)
]);
// return new Response(print_r($posts, true));
}
return $this->render('post/search.html.twig', [
'form' => $form
]);
}
} }

@ -0,0 +1,23 @@
<?php
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
class SimpleSearchType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('search', TextType::class, [
'label' => false
])
->add('submit', SubmitType::class, [
'label' => 'Search'
])
;
}
}

@ -33,13 +33,13 @@ class PostRepository extends ServiceEntityRepository
; ;
} }
// public function findOneBySomeField($value): ?Post public function searchByTitleOrText(string $searchString): array
// { {
// return $this->createQueryBuilder('p') return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val') ->where('p.title LIKE :searchTerm')
// ->setParameter('val', $value) ->orWhere('p.text LIKE :searchTerm')
// ->getQuery() ->setParameter('searchTerm', '%'.$searchString.'%')
// ->getOneOrNullResult() ->getQuery()
// ; ->getResult();
// } }
} }

@ -23,6 +23,7 @@
<a class="nav-link {{ nightmare|default('') }}" href="/"><h1>Fukafukashita</h1></a> <a class="nav-link {{ nightmare|default('') }}" href="/"><h1>Fukafukashita</h1></a>
</div> </div>
<div class="nav-links"> <div class="nav-links">
<a href="/post/search" class="nav-link {{ nightmare|default('') }}">Search</a>
{% if is_granted('ROLE_USER') %} {% if is_granted('ROLE_USER') %}
<a href="/profil/post/follow" class="nav-link {{ nightmare|default('') }}">Feed</a> <a href="/profil/post/follow" class="nav-link {{ nightmare|default('') }}">Feed</a>
<a href="/profil" class="nav-link {{ nightmare|default('') }}">Profile</a> <a href="/profil" class="nav-link {{ nightmare|default('') }}">Profile</a>

@ -0,0 +1,24 @@
{% extends 'base.html.twig' %}
{% block stylesheets %}
<link rel="stylesheet" href="{{ asset('css/components/form.css') }}">
<link rel="stylesheet" href="{{ asset('css/components/post_mini.css') }}">
<link rel="stylesheet" href="{{ asset('css/components/search.css') }}">
{% endblock %}
{% block body %}
<div class="wrapper">
<div class="form-container">
{{ form(form) }}
</div>
<hr>
{% if posts is defined %}
{% for post in posts %}
{% include 'post/post_mini.html.twig' with { 'post': post} %}
{% endfor %}
{% endif %}
</div>
{% endblock %}

Binary file not shown.
Loading…
Cancel
Save