Initial Build
This commit is contained in:
parent
71cd3acccd
commit
6c0d9a3f98
140 changed files with 9802 additions and 2403 deletions
18
src/Controller/Brain/BrainController.php
Normal file
18
src/Controller/Brain/BrainController.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\Brain;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
final class BrainController extends AbstractController
|
||||
{
|
||||
#[Route('/brain', name: 'brain_home')]
|
||||
public function index(): Response
|
||||
{
|
||||
return $this->render('brain/home/index.html.twig', [
|
||||
|
||||
]);
|
||||
}
|
||||
}
|
||||
95
src/Controller/Brain/BrainPageController.php
Normal file
95
src/Controller/Brain/BrainPageController.php
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\Brain;
|
||||
|
||||
use App\Entity\Page;
|
||||
use App\Form\PageType;
|
||||
|
||||
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 BrainPageController extends AbstractController
|
||||
{
|
||||
#[Route('/brain/page/list', name: 'brain_page_list')]
|
||||
public function index(EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$pages = $entityManager->getRepository(Page::class)->findAll();
|
||||
|
||||
return $this->render('brain/page/index.html.twig', [
|
||||
'pages' => $pages
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/brain/page/new', name: 'brain_page_new')]
|
||||
public function new(EntityManagerInterface $entityManager, Request $request): Response
|
||||
{
|
||||
|
||||
$form = $this->createForm(PageType::class);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted()) {
|
||||
$data = $form->getData();
|
||||
$page = new Page();
|
||||
|
||||
$page->setTitle($data->getTitle());
|
||||
$page->setText($data->getText());
|
||||
$page->setUrl($data->getUrl());
|
||||
|
||||
if ($data->isPublished()) {
|
||||
$page->setPublished(true);
|
||||
} else {
|
||||
$page->setPublished(false);
|
||||
}
|
||||
|
||||
$entityManager->persist($page);
|
||||
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('brain_page_list');
|
||||
}
|
||||
|
||||
return $this->render('brain/page/create.html.twig', [
|
||||
'action' => 'New',
|
||||
'form' => $form
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/brain/page/edit/{id}', name: 'brain_page_edit')]
|
||||
public function edit(EntityManagerInterface $entityManager, string $id, Request $request): Response
|
||||
{
|
||||
|
||||
$page = $entityManager->getRepository(Page::class)->findOneBy(['id' => $id]);
|
||||
|
||||
$form = $this->createForm(PageType::class, $page);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted()) {
|
||||
$data = $form->getData();
|
||||
|
||||
$page->setTitle($data->getTitle());
|
||||
$page->setText($data->getText());
|
||||
$page->setUrl($data->getUrl());
|
||||
|
||||
if ($data->isPublished()) {
|
||||
$page->setPublished(true);
|
||||
} else {
|
||||
$page->setPublished(false);
|
||||
}
|
||||
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('brain_page_list');
|
||||
}
|
||||
|
||||
return $this->render('brain/page/create.html.twig', [
|
||||
'action' => 'Edit',
|
||||
'form' => $form
|
||||
]);
|
||||
}
|
||||
}
|
||||
140
src/Controller/Brain/BrainPhotosController.php
Normal file
140
src/Controller/Brain/BrainPhotosController.php
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\Brain;
|
||||
|
||||
use App\Entity\Category;
|
||||
use App\Entity\Photos;
|
||||
use App\Form\PhotosType;
|
||||
use App\Service\PhotoUploader;
|
||||
|
||||
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 BrainPhotosController extends AbstractController
|
||||
{
|
||||
#[Route('/brain/photos/list', name: 'brain_photos_list')]
|
||||
public function index(EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$photos = $entityManager->getRepository(Photos::class)->findAllOrderByLatest();
|
||||
|
||||
return $this->render('brain/photos/index.html.twig', [
|
||||
'photos' => $photos
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/brain/photos/new', name: 'brain_photos_new')]
|
||||
public function new(EntityManagerInterface $entityManager, Request $request, PhotoUploader $photoUploader): Response
|
||||
{
|
||||
$form = $this->createForm(PhotosType::class);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted()) {
|
||||
$data = $form->getData();
|
||||
$photos = new Photos();
|
||||
$fileNames = [];
|
||||
|
||||
$photos->setTitle($data->getTitle());
|
||||
$photos->setDate($data->getDate());
|
||||
$photos->setText($data->getText());
|
||||
$photos->setUrl($data->getUrl());
|
||||
|
||||
$tax = $request->request->all('photos');
|
||||
|
||||
if ($data->getCategory() == null) {
|
||||
$cat = $tax['category'];
|
||||
|
||||
if ($cat !== null) {
|
||||
$categoryToAdd = new Category()->setTitle($cat);
|
||||
$photos->setCategory($categoryToAdd);
|
||||
|
||||
$entityManager->persist($categoryToAdd);
|
||||
}
|
||||
} else {
|
||||
$photos->setCategory($data->getCategory());
|
||||
}
|
||||
|
||||
$thumbnail = $request->files->get('photos')['thumbnail'];
|
||||
|
||||
$fileName = $photoUploader->upload($thumbnail, $photos->getTitle());
|
||||
$photos->setThumbnail($fileName);
|
||||
|
||||
$uploadedPhotos = $request->files->get('photos')['uploads'];
|
||||
|
||||
foreach ($uploadedPhotos as $upload) {
|
||||
$filenames[] = $photoUploader->upload($upload['file'], $photos->getTitle());
|
||||
}
|
||||
|
||||
foreach ($data->getUploads() as $index => $photo) {
|
||||
$photo->setFile($filenames[$index]);
|
||||
$photos->addUpload($photo);
|
||||
}
|
||||
|
||||
$entityManager->persist($photos);
|
||||
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('brain_photos_list');
|
||||
}
|
||||
|
||||
return $this->render('brain/photos/create.html.twig', [
|
||||
'action' => 'New',
|
||||
'form' => $form
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/brain/photos/edit/{id}', name: 'brain_photos_edit')]
|
||||
public function edit(EntityManagerInterface $entityManager, string $id, Request $request, PhotoUploader $photoUploader): Response
|
||||
{
|
||||
|
||||
$photos = $entityManager->getRepository(Photos::class)->findOneBy(['id' => $id]);
|
||||
|
||||
$form = $this->createForm(PhotosType::class, $photos);
|
||||
|
||||
$form->handleRequest($request);
|
||||
/* TODO handle editing! */
|
||||
/*if (!$form->isSubmitted() && $photos->getUploads()) {
|
||||
$dirName = 'uploads/' . strtolower(str_replace(' ', '_', $photos->getTitle()));
|
||||
$form->setData(['uploads' => $dirName . '/' . $photos->getUploads()[0]->getFile()]);
|
||||
} */
|
||||
|
||||
if ($form->isSubmitted()) {
|
||||
$data = $form->getData();
|
||||
$photos = new Photos();
|
||||
$fileNames = [];
|
||||
|
||||
$photos->setTitle($data->getTitle());
|
||||
|
||||
$uploadedPhotos = $request->files->get('photos')['uploads'];
|
||||
|
||||
foreach ($uploadedPhotos as $upload) {
|
||||
$filenames[] = $photoUploader->upload($upload['file'], $photos->getTitle());
|
||||
}
|
||||
|
||||
foreach ($data->getUploads() as $index => $photo) {
|
||||
$photo->setFile($filenames[$index]);
|
||||
}
|
||||
|
||||
//$entityManager->persist($data);
|
||||
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('brain_photos_list');
|
||||
}
|
||||
|
||||
return $this->render('brain/photos/create.html.twig', [
|
||||
'action' => 'Edit',
|
||||
'form' => $form
|
||||
]);
|
||||
}
|
||||
|
||||
private function handleFilenameToFileConversion(string $directory, array $uploads)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
138
src/Controller/Brain/BrainPostController.php
Normal file
138
src/Controller/Brain/BrainPostController.php
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\Brain;
|
||||
|
||||
use App\Entity\Category;
|
||||
use App\Entity\Tag;
|
||||
use App\Form\PostType;
|
||||
use App\Entity\Post;
|
||||
|
||||
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 BrainPostController extends AbstractController
|
||||
{
|
||||
#[Route('/brain/post/list', name: 'brain_post_list')]
|
||||
public function index(EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$posts = $entityManager->getRepository(Post::class)->findAllOrderByLatest();
|
||||
|
||||
return $this->render('brain/post/index.html.twig', [
|
||||
'posts' => $posts
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/brain/post/new', name: 'brain_post_new')]
|
||||
public function new(EntityManagerInterface $entityManager, Request $request): Response
|
||||
{
|
||||
$form = $this->createForm(PostType::class);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted()) {
|
||||
$data = $form->getData();
|
||||
$post = new Post();
|
||||
|
||||
$post->setTitle($data->getTitle());
|
||||
$post->setDate($data->getDate());
|
||||
$post->setText($data->getText());
|
||||
$post->setUrl($data->getUrl());
|
||||
|
||||
foreach ($data->getTags() as $tag) {
|
||||
$post->addTag($tag);
|
||||
}
|
||||
|
||||
if ($data->isPublished()) {
|
||||
$post->setPublished(true);
|
||||
} else {
|
||||
$post->SetPublished(false);
|
||||
}
|
||||
|
||||
$tax = $request->request->all('post');
|
||||
|
||||
if ($data->getCategory() == null) {
|
||||
$cat = $tax['category'];
|
||||
|
||||
if ($cat !== null) {
|
||||
$categoryToAdd = new Category()->setTitle($cat);
|
||||
$post->setCategory($categoryToAdd);
|
||||
|
||||
$entityManager->persist($categoryToAdd);
|
||||
}
|
||||
} else {
|
||||
$post->setCategory($data->getCategory());
|
||||
}
|
||||
|
||||
$entityManager->persist($post);
|
||||
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('brain_post_list');
|
||||
}
|
||||
|
||||
return $this->render('brain/post/create.html.twig', [
|
||||
'action' => 'new',
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/brain/post/edit/{id}', name: 'brain_post_edit')]
|
||||
public function edit(EntityManagerInterface $entityManager, string $id, Request $request): Response
|
||||
{
|
||||
$post = $entityManager->getRepository(Post::class)->findOneBy(['id' => $id]);
|
||||
|
||||
$form = $this->createForm(PostType::class, $post);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted()) {
|
||||
$data = $form->getData();
|
||||
//$post = new Post();
|
||||
|
||||
|
||||
$post->setTitle($data->getTitle());
|
||||
$post->setDate($data->getDate());
|
||||
$post->setText($data->getText());
|
||||
$post->setUrl($data->getUrl());
|
||||
|
||||
foreach ($data->getTags() as $tag) {
|
||||
$post->addTag($tag);
|
||||
}
|
||||
|
||||
if ($data->isPublished()) {
|
||||
$post->setPublished(true);
|
||||
} else {
|
||||
$post->SetPublished(false);
|
||||
}
|
||||
|
||||
$tax = $request->request->all('post');
|
||||
|
||||
if ($data->getCategory() == null) {
|
||||
$cat = $tax['category'];
|
||||
|
||||
if ($cat !== null) {
|
||||
$categoryToAdd = new Category()->setTitle($cat);
|
||||
$post->setCategory($categoryToAdd);
|
||||
|
||||
$entityManager->persist($categoryToAdd);
|
||||
}
|
||||
} else {
|
||||
$post->setCategory($data->getCategory());
|
||||
}
|
||||
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('brain_post_list');
|
||||
}
|
||||
return $this->render('brain/post/create.html.twig', [
|
||||
'action' => 'edit',
|
||||
'form' => $form
|
||||
]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue