Add tag support
This commit is contained in:
parent
ce10245c51
commit
ae440be40c
24 changed files with 475 additions and 15 deletions
55
src/Controller/Brain/BrainCategoryController.php
Normal file
55
src/Controller/Brain/BrainCategoryController.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\Brain;
|
||||
|
||||
use App\Entity\Category;
|
||||
use App\Form\CategoryType;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
final class BrainCategoryController extends AbstractController
|
||||
{
|
||||
#[Route('/brain/category/list', name: 'brain_categories_list')]
|
||||
public function index(EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
|
||||
$categories = $entityManager->getRepository(Category::class)->findAll();
|
||||
return $this->render('brain/taxonomy/index.html.twig', [
|
||||
'taxonomy' => $categories,
|
||||
'type' => 'Category'
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/brain/category/new', name: 'brain_categories_new')]
|
||||
public function new(EntityManagerInterface $entityManager, Request $request): Response
|
||||
{
|
||||
|
||||
$form = $this->createForm(CategoryType::class);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted()) {
|
||||
$data = $form->getData();
|
||||
$category = new Category();
|
||||
|
||||
$category->setTitle($data->getTitle());
|
||||
|
||||
$entityManager->persist($category);
|
||||
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('brain_categories_list');
|
||||
}
|
||||
|
||||
return $this->render('brain/taxonomy/create.html.twig', [
|
||||
'action' => 'New',
|
||||
'form' => $form,
|
||||
'type' => 'Category'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -43,6 +43,10 @@ final class BrainPhotosController extends AbstractController
|
|||
$photos->setText($data->getText());
|
||||
$photos->setUrl($data->getUrl());
|
||||
|
||||
foreach ($data->getTags() as $tag) {
|
||||
$photos->addTag($tag);
|
||||
}
|
||||
|
||||
$tax = $request->request->all('photos');
|
||||
|
||||
if ($data->getCategory() == null) {
|
||||
|
|
|
|||
|
|
@ -53,6 +53,10 @@ final class BrainPostController extends AbstractController
|
|||
} else {
|
||||
$post->SetPublished(false);
|
||||
}
|
||||
|
||||
foreach ($data->getTags() as $tag) {
|
||||
$post->addTag($tag);
|
||||
}
|
||||
|
||||
$tax = $request->request->all('post');
|
||||
|
||||
|
|
|
|||
56
src/Controller/Brain/BrainTagController.php
Normal file
56
src/Controller/Brain/BrainTagController.php
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\Brain;
|
||||
|
||||
use App\Entity\Tag;
|
||||
use App\Form\TagType;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
final class BrainTagController extends AbstractController
|
||||
{
|
||||
#[Route('/brain/tag/list', name: 'brain_tags_list')]
|
||||
public function index(EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
|
||||
$tags = $entityManager->getRepository(Tag::class)->findAll();
|
||||
|
||||
return $this->render('brain/taxonomy/index.html.twig', [
|
||||
'taxonomy' => $tags,
|
||||
'type' => 'Tag'
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/brain/tag/new', name: 'brain_tags_new')]
|
||||
public function new(EntityManagerInterface $entityManager, Request $request): Response
|
||||
{
|
||||
|
||||
$form = $this->createForm(TagType::class);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted()) {
|
||||
$data = $form->getData();
|
||||
$Tag = new Tag();
|
||||
|
||||
$Tag->setTitle($data->getTitle());
|
||||
|
||||
$entityManager->persist($Tag);
|
||||
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('brain_tags_list');
|
||||
}
|
||||
|
||||
return $this->render('brain/taxonomy/create.html.twig', [
|
||||
'action' => 'New',
|
||||
'form' => $form,
|
||||
'type' => 'Tag'
|
||||
]);
|
||||
}
|
||||
}
|
||||
48
src/Controller/FrontEnd/TagController.php
Normal file
48
src/Controller/FrontEnd/TagController.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\FrontEnd;
|
||||
|
||||
use App\Entity\Tag;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
final class TagController extends AbstractController
|
||||
{
|
||||
#[Route('/tags', name: 'front_end_tag_list', priority: 1)]
|
||||
public function index(EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$tags = $entityManager->getRepository(Tag::class)->findAll();
|
||||
|
||||
$tagsDisplay = [];
|
||||
|
||||
foreach ($tags as $index => $tag) {
|
||||
$tagsDisplay[] = [
|
||||
'title' => $tag->getTitle(),
|
||||
'urlSafeTitle' => strtolower(str_replace(' ', '-', $tag->getTitle())),
|
||||
'count' => $tag->getCount(),
|
||||
];
|
||||
}
|
||||
|
||||
return $this->render('front/tag/index.html.twig', [
|
||||
'tags' => $tagsDisplay
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/tags/{tagTitle}', name: 'front_end_tag_detail')]
|
||||
public function detail(EntityManagerInterface $entityManager, string $tagTitle): Response
|
||||
{
|
||||
$formattedTitle = ucwords(str_replace('-', ' ', $tagTitle));
|
||||
$tag = $entityManager->getRepository(tag::class)->findOneBy(['title' => $formattedTitle]);
|
||||
|
||||
return $this->render('front/tag/detail.html.twig', [
|
||||
'title' => $tag->getTitle(),
|
||||
'posts' => $tag->getPosts(),
|
||||
'photos' => $tag->getPhotos(),
|
||||
'count' => $tag->getCount()
|
||||
]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue