Initial Build

This commit is contained in:
Alex 2026-06-03 17:18:50 -07:00
parent 71cd3acccd
commit 6c0d9a3f98
140 changed files with 9802 additions and 2403 deletions

View 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', [
]);
}
}

View 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
]);
}
}

View 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)
{
}
}

View 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
]);
}
}

View file

@ -0,0 +1,47 @@
<?php
namespace App\Controller\FrontEnd;
use App\Entity\Category;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
final class CategoryController extends AbstractController
{
#[Route('/categories', name: 'front_end_category_list', priority: 1)]
public function index(EntityManagerInterface $entityManager): Response
{
$categories = $entityManager->getRepository(Category::class)->findAll();
$categoriesDisplay = [];
foreach ($categories as $index => $category) {
$categoriesDisplay[] = [
'title' => $category->getTitle(),
'urlSafeTitle' => strtolower(str_replace(' ', '-', $category->getTitle())),
'count' => $category->getCount(),
];
}
return $this->render('front/category/index.html.twig', [
'categories' => $categoriesDisplay
]);
}
#[Route('/categories/{categoryTitle}', name: 'front_end_category_detail')]
public function detail(EntityManagerInterface $entityManager, string $categoryTitle): Response
{
$formattedTitle = ucwords(str_replace('-', ' ', $categoryTitle));
$category = $entityManager->getRepository(Category::class)->findOneBy(['title' => $formattedTitle]);
return $this->render('front/category/detail.html.twig', [
'title' => $category->getTitle(),
'posts' => $category->getPosts(),
'photos' => $category->getPhotos(),
'count' => $category->getCount()
]);
}
}

View file

@ -0,0 +1,25 @@
<?php
namespace App\Controller\FrontEnd;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
final class FrontController extends AbstractController
{
/**TODO Update so this is it's own type so i don't have to hardcode anything */
#[Route('/', name: 'front_end_home')]
public function index(): Response
{
return $this->render('front/home/index.html.twig', [
]);
}
#[Route('/secret/styleguide', name: 'front_end_styleguide')]
public function styleGuide(): Response
{
return $this->render('front/styleguide/styleguide.html.twig',[]);
}
}

View file

@ -0,0 +1,24 @@
<?php
namespace App\Controller\FrontEnd;
use App\Entity\Page;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
final class PageController extends AbstractController
{
#[Route('/{url:page}', name: 'front_end_page')]
public function index(Page $page): Response
{
if ($page->isPublished()) {
return $this->render('front/page/index.html.twig', [
'page' => $page
]);
}
return new Response('<h1>Page not found</h1>');
}
}

View file

@ -0,0 +1,69 @@
<?php
namespace App\Controller\FrontEnd;
use App\Entity\Photos;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Doctrine\ORM\EntityManagerInterface;
final class PhotosController extends AbstractController
{
#[Route('/photos', name: 'front_end_photos_list', priority: 1)]
public function index(EntityManagerInterface $entityManager): Response
{
$photos = $entityManager->getRepository(Photos::class)->findAllOrderByLatest();
$albums = [];
foreach ($photos as $index => $photo) {
$albums[] = [
'title' => $photo->getTitle(),
'date' => $photo->getDate(),
'category' => $photo->getCategory()->getTitle(),
'thumbnail' => 'photos/' . strtolower(str_replace(' ', '_', $photo->getTitle())) . '/' . $photo->getThumbnail(),
'url' => $photo->getUrl(),
];
}
return $this->render('front/photos/index.html.twig', [
'photos' => $albums
]);
}
#[Route('/photos/{url:photos}', name: 'front_end_photos_detail')]
public function detail(Photos $photos): Response
{
$album = [];
$uploads = $photos->getUploads();
$album = [
'title' => $photos->getTitle(),
'category' => $photos->getCategory()->getTitle(),
'urlSafeCategory' => $photos->getCategory()->getUrlSafeTitle(),
'text' => $photos->getText(),
'date' => $photos->getDate()
];
foreach ($uploads as $index => $upload) {
$filePath = 'photos/' . strtolower(str_replace(' ', '_', $album['title'])) . '/' . $upload->getFile();
$album['uploads'][] = [
'file' => $filePath,
'alt' => $upload->getAltText(),
'equipment' => $upload->getEquipment(),
'caption' => $upload->getCaption(),
'location' => $upload->getLocation(),
'date' => $upload->getDate()
];
}
return $this->render('front/photos/detail.html.twig', [
'photos' => $album
]);
}
}

View file

@ -0,0 +1,50 @@
<?php
namespace App\Controller\FrontEnd;
use App\Entity\Post;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
final class PostController extends AbstractController
{
/**TODO Update so this is it's own type so i don't have to hardcode anything */
#[Route('/words', name: 'front_end_post_list', priority: 1)]
public function index(EntityManagerInterface $entityManager): Response
{
$posts = $entityManager->getRepository(Post::class)->findAllOrderByLatest();
$formattedPosts = [];
foreach ($posts as $index => $post) {
$formattedPosts [] = [
'title' => $post->getTitle(),
'category' => $post->getCategory()->getTitle(),
'urlSafeCategory' => $post->getCategory()->getUrlSafeTitle(),
'date' => $post->getDate(),
'url' => $post->getUrl()
];
}
return $this->render('front/post/index.html.twig', [
'posts' => $formattedPosts
]);
}
#[Route('/words/{url:post}', name: 'front_end_post_detail')]
public function post(Post $post): Response
{
if ($post->isPublished()) {
return $this->render('front/post/detail.html.twig', [
'post' => $post,
'urlSafeCategory' => $post->getCategory()->getUrlSafeTitle()
]);
}
return new Response('<h1>Page not found</h1>');
}
}

View file

@ -0,0 +1,42 @@
<?php
namespace App\Controller;
use App\Entity\User;
use App\Form\RegistrationFormType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Attribute\Route;
class RegistrationController extends AbstractController
{
#[Route('/letmein/register', name: 'app_register')]
public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager): Response
{
$user = new User();
$form = $this->createForm(RegistrationFormType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
/** @var string $plainPassword */
$plainPassword = $form->get('plainPassword')->getData();
// encode the plain password
$user->setPassword($userPasswordHasher->hashPassword($user, $plainPassword));
$entityManager->persist($user);
$entityManager->flush();
// do anything else you need here, like send an email
return $this->redirectToRoute('brain_home');
}
return $this->render('registration/register.html.twig', [
'registrationForm' => $form,
]);
}
}

View file

@ -0,0 +1,32 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
#[Route(path: '/letmein', name: 'brain_login', priority: 1)]
public function login(AuthenticationUtils $authenticationUtils): Response
{
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
]);
}
#[Route(path: '/letmeout', name: 'brain_logout', priority: 1)]
public function logout(): void
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}