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.');
}
}

130
src/Entity/Category.php Normal file
View file

@ -0,0 +1,130 @@
<?php
namespace App\Entity;
use App\Repository\CategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: CategoryRepository::class)]
class Category
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $title = null;
/**
* @var Collection<int, Post>
*/
#[ORM\OneToMany(targetEntity: Post::class, mappedBy: 'category')]
private Collection $posts;
/**
* @var Collection<int, Photos>
*/
#[ORM\OneToMany(targetEntity: Photos::class, mappedBy: 'category')]
private Collection $photos;
public function __construct()
{
$this->posts = new ArrayCollection();
$this->photos = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
/**
* @return Collection<int, Post>
*/
public function getPosts(): Collection
{
return $this->posts;
}
public function addPost(Post $post): static
{
if (!$this->posts->contains($post)) {
$this->posts->add($post);
$post->setCategory($this);
}
return $this;
}
public function removePost(Post $post): static
{
if ($this->posts->removeElement($post)) {
// set the owning side to null (unless already changed)
if ($post->getCategory() === $this) {
$post->setCategory(null);
}
}
return $this;
}
/**
* @return Collection<int, Photos>
*/
public function getPhotos(): Collection
{
return $this->photos;
}
public function addPhoto(Photos $photo): static
{
if (!$this->photos->contains($photo)) {
$this->photos->add($photo);
$photo->setCategory($this);
}
return $this;
}
public function removePhoto(Photos $photo): static
{
if ($this->photos->removeElement($photo)) {
// set the owning side to null (unless already changed)
if ($photo->getCategory() === $this) {
$photo->setCategory(null);
}
}
return $this;
}
public function getCount() : int
{
return $this->posts->count() + $this->photos->count();
}
public function getUrlSafeTitle() : string
{
return strtolower(str_replace(' ', '-', $this->title));
}
public function getDisplaySafeTitle(string $urlSafeTitle) : string
{
return ucwords(str_replace('-', ' ', $urlSafeTitle));
}
}

81
src/Entity/Page.php Normal file
View file

@ -0,0 +1,81 @@
<?php
namespace App\Entity;
use App\Repository\PageRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PageRepository::class)]
class Page
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $title = null;
#[ORM\Column(type: Types::TEXT)]
private ?string $text = null;
#[ORM\Column(length: 255)]
private ?string $url = null;
#[ORM\Column]
private ?bool $published = null;
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
public function getText(): ?string
{
return $this->text;
}
public function setText(string $text): static
{
$this->text = $text;
return $this;
}
public function getUrl(): ?string
{
return $this->url;
}
public function setUrl(string $url): static
{
$this->url = $url;
return $this;
}
public function isPublished(): ?bool
{
return $this->published;
}
public function setPublished(bool $published): static
{
$this->published = $published;
return $this;
}
}

126
src/Entity/Photo.php Normal file
View file

@ -0,0 +1,126 @@
<?php
namespace App\Entity;
use App\Repository\PhotoRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PhotoRepository::class)]
class Photo
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $file = null;
#[ORM\Column(length: 255)]
private ?string $equipment = null;
#[ORM\Column(length: 255)]
private ?string $location = null;
#[ORM\Column(length: 255)]
private ?string $caption = null;
#[ORM\Column(type: Types::DATE_MUTABLE)]
private ?\DateTime $date = null;
#[ORM\ManyToOne(inversedBy: 'uploads')]
private ?Photos $photos = null;
#[ORM\Column(length: 255)]
private ?string $alt_text = null;
public function getId(): ?int
{
return $this->id;
}
public function getFile(): ?string
{
return $this->file;
}
public function setFile(string $file): static
{
$this->file = $file;
return $this;
}
public function getEquipment(): ?string
{
return $this->equipment;
}
public function setEquipment(string $equipment): static
{
$this->equipment = $equipment;
return $this;
}
public function getLocation(): ?string
{
return $this->location;
}
public function setLocation(string $location): static
{
$this->location = $location;
return $this;
}
public function getCaption(): ?string
{
return $this->caption;
}
public function setCaption(string $caption): static
{
$this->caption = $caption;
return $this;
}
public function getDate(): ?\DateTime
{
return $this->date;
}
public function setDate(\DateTime $date): static
{
$this->date = $date;
return $this;
}
public function getPhotos(): ?Photos
{
return $this->photos;
}
public function setPhotos(?Photos $photos): static
{
$this->photos = $photos;
return $this;
}
public function getAltText(): ?string
{
return $this->alt_text;
}
public function setAltText(string $alt_text): static
{
$this->alt_text = $alt_text;
return $this;
}
}

154
src/Entity/Photos.php Normal file
View file

@ -0,0 +1,154 @@
<?php
namespace App\Entity;
use App\Repository\PhotosRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PhotosRepository::class)]
class Photos
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $title = null;
#[ORM\Column]
private ?\DateTime $date = null;
#[ORM\ManyToOne(inversedBy: 'photos')]
private ?Category $category = null;
/**
* @var Collection<int, Photo>
*/
#[ORM\OneToMany(targetEntity: Photo::class, mappedBy: 'photos', cascade: ['persist'])]
private Collection $uploads;
#[ORM\Column(type: Types::TEXT)]
private ?string $text = null;
#[ORM\Column(length: 255)]
private ?string $url = null;
#[ORM\Column(length: 255)]
private ?string $thumbnail = null;
public function __construct()
{
$this->uploads = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
public function getDate(): ?\DateTime
{
return $this->date;
}
public function setDate(\DateTime $date): static
{
$this->date = $date;
return $this;
}
public function getCategory(): ?Category
{
return $this->category;
}
public function setCategory(?Category $category): static
{
$this->category = $category;
return $this;
}
/**
* @return Collection<int, Photo>
*/
public function getUploads(): Collection
{
return $this->uploads;
}
public function addUpload(Photo $upload): static
{
if (!$this->uploads->contains($upload)) {
$this->uploads->add($upload);
$upload->setPhotos($this);
}
return $this;
}
public function removeUpload(Photo $upload): static
{
if ($this->uploads->removeElement($upload)) {
// set the owning side to null (unless already changed)
if ($upload->getPhotos() === $this) {
$upload->setPhotos(null);
}
}
return $this;
}
public function getText(): ?string
{
return $this->text;
}
public function setText(string $text): static
{
$this->text = $text;
return $this;
}
public function getUrl(): ?string
{
return $this->url;
}
public function setUrl(string $url): static
{
$this->url = $url;
return $this;
}
public function getThumbnail(): ?string
{
return $this->thumbnail;
}
public function setThumbnail(string $thumbnail): static
{
$this->thumbnail = $thumbnail;
return $this;
}
}

148
src/Entity/Post.php Normal file
View file

@ -0,0 +1,148 @@
<?php
namespace App\Entity;
use App\Repository\PostRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PostRepository::class)]
class Post
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $title = null;
#[ORM\Column]
private ?\DateTime $date = null;
#[ORM\Column(type: Types::TEXT)]
private ?string $text = null;
#[ORM\Column(length: 255)]
private ?string $url = null;
#[ORM\Column]
private ?bool $published = null;
#[ORM\ManyToOne(inversedBy: 'posts')]
private ?Category $category = null;
/**
* @var Collection<int, Tag>
*/
#[ORM\ManyToMany(targetEntity: Tag::class, inversedBy: 'posts')]
private Collection $tags;
public function __construct()
{
$this->tags = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
public function getDate(): ?\DateTime
{
return $this->date;
}
public function setDate(\DateTime $date): static
{
$this->date = $date;
return $this;
}
public function getText(): ?string
{
return $this->text;
}
public function setText(string $text): static
{
$this->text = $text;
return $this;
}
public function getUrl(): ?string
{
return $this->url;
}
public function setUrl(string $url): static
{
$this->url = $url;
return $this;
}
public function isPublished(): ?bool
{
return $this->published;
}
public function setPublished(bool $published): static
{
$this->published = $published;
return $this;
}
public function getCategory(): ?Category
{
return $this->category;
}
public function setCategory(?Category $category): static
{
$this->category = $category;
return $this;
}
/**
* @return Collection<int, Tag>
*/
public function getTags(): Collection
{
return $this->tags;
}
public function addTag(Tag $tag): static
{
if (!$this->tags->contains($tag)) {
$this->tags->add($tag);
}
return $this;
}
public function removeTag(Tag $tag): static
{
$this->tags->removeElement($tag);
return $this;
}
}

75
src/Entity/Tag.php Normal file
View file

@ -0,0 +1,75 @@
<?php
namespace App\Entity;
use App\Repository\TagRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: TagRepository::class)]
class Tag
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $title = null;
/**
* @var Collection<int, Post>
*/
#[ORM\ManyToMany(targetEntity: Post::class, mappedBy: 'tags')]
private Collection $posts;
public function __construct()
{
$this->posts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
/**
* @return Collection<int, Post>
*/
public function getPosts(): Collection
{
return $this->posts;
}
public function addPost(Post $post): static
{
if (!$this->posts->contains($post)) {
$this->posts->add($post);
$post->addTag($this);
}
return $this;
}
public function removePost(Post $post): static
{
if ($this->posts->removeElement($post)) {
$post->removeTag($this);
}
return $this;
}
}

112
src/Entity/User.php Normal file
View file

@ -0,0 +1,112 @@
<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: '`user`')]
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_USERNAME', fields: ['username'])]
#[UniqueEntity(fields: ['username'], message: 'There is already an account with this username')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 180)]
private ?string $username = null;
/**
* @var list<string> The user roles
*/
#[ORM\Column]
private array $roles = [];
/**
* @var string The hashed password
*/
#[ORM\Column]
private ?string $password = null;
public function getId(): ?int
{
return $this->id;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): static
{
$this->username = $username;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->username;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
$roles[] = 'ROLE_ADMIN';
return array_unique($roles);
}
/**
* @param list<string> $roles
*/
public function setRoles(array $roles): static
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): static
{
$this->password = $password;
return $this;
}
/**
* Ensure the session doesn't contain actual password hashes by CRC32C-hashing them, as supported since Symfony 7.3.
*/
public function __serialize(): array
{
$data = (array) $this;
$data["\0".self::class."\0password"] = hash('crc32c', $this->password);
return $data;
}
}

View file

@ -0,0 +1,34 @@
<?php
namespace App\Form;
use App\Entity\Category;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\UX\Autocomplete\Form\AsEntityAutocompleteField;
use Symfony\UX\Autocomplete\Form\BaseEntityAutocompleteType;
#[AsEntityAutocompleteField]
class CategoryAutocompleteField extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'class' => Category::class,
'searchable_fields' => ['title'],
'label' => 'Category',
'choice_label' => 'title',
'multiple' => false,
'tom_select_options' => [
'create' => true,
]
]);
}
public function getParent(): string
{
return BaseEntityAutocompleteType::class;
}
}

View file

@ -0,0 +1,45 @@
<?php
namespace App\Form\DataTransformer;
use App\Entity\Photo;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\HttpFoundation\File\File;
class UploadDataTransformer implements DataTransformerInterface
{
public function __construct(private EntityManagerInterface $entityManager) {}
public function transform($photo) : string
{
if ($photo === null) {
return '';
}
return $photo;
}
public function reverseTransform($filename): ?File
{
if (!$filename) {
return null;
}
$photo = $this->entityManager->getRepository(Photo::class)->findOneBy(['file' => $filename]);
$directoryName = $photo->getPhotos()->getTitle();
$directoryName = 'photos/' . strtolower(str_replace(' ', '_', $directoryName));
$file = new File($directoryName . '/' . $filename);
if ($file === null) {
throw new TransformationFailedException(sprintf('Photo with the filename "%s" does not exist!', $filename));
}
return $file;
}
}

31
src/Form/PageType.php Normal file
View file

@ -0,0 +1,31 @@
<?php
namespace App\Form;
use App\Entity\Page;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
class PageType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('title')
->add('text')
->add('url')
->add('published')
->add('save', SubmitType::class, ['label' => 'Save'])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Page::class,
]);
}
}

43
src/Form/PhotoType.php Normal file
View file

@ -0,0 +1,43 @@
<?php
namespace App\Form;
use App\Entity\Photo;
use App\Form\DataTransformer\UploadDataTransformer;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints as Assert;
class PhotoType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('file', FileType::class, [
'label' => 'Photo',
'constraints' => [
new Assert\File(
maxSize: '8192k',
extensions: ['jpg', 'png'],
),
],
])
->add('alt_text')
->add('date')
->add('equipment')
->add('location')
->add('caption')
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Photo::class,
]);
}
}

52
src/Form/PhotosType.php Normal file
View file

@ -0,0 +1,52 @@
<?php
namespace App\Form;
use App\Entity\Photos;
use App\Form\CategoryAutocompleteField;
use App\Form\PhotoType;
use App\Form\DataTransformer\UploadDataTransformer;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class PhotosType extends AbstractType
{
public function __construct(private UploadDataTransformer $transformer){}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('title')
->add('date', DateType::class)
->add('category', CategoryAutocompleteField::class)
->add('text')
->add('thumbnail', FileType::class, [
'label' => 'Thumbnail',
])
->add('uploads', CollectionType::class, [
'entry_type' => PhotoType::class,
'entry_options' => ['label' => false],
'allow_add' => true,
'by_reference' => false,
])
->add('url')
->add('save', SubmitType::class, ['label' => 'Save'])
;
//$builder->get('uploads')->addModelTransformer($this->transformer);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Photos::class,
]);
}
}

48
src/Form/PostType.php Normal file
View file

@ -0,0 +1,48 @@
<?php
namespace App\Form;
use App\Entity\Post;
use App\Form\CategoryAutocompleteField;
use App\Form\TagAutocompleteField;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
class PostType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('title', TextType::class)
->add('date', DateType::class)
->add('text', TextareaType::class)
->add('category', CategoryAutocompleteField::class)
//->add('tags', TagAutocompleteField::class, ['required' => false])
->add('url', TextType::class)
->add('published')
->add('save', SubmitType::class, ['label' => 'Save'])
;
//$builder->get('tags')->resetViewTransformers();
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Post::class,
'validation_groups' => false,
]);
}
}

View file

@ -0,0 +1,47 @@
<?php
namespace App\Form;
use App\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
class RegistrationFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('username')
->add('plainPassword', PasswordType::class, [
// instead of being set onto the object directly,
// this is read and encoded in the controller
'mapped' => false,
'attr' => ['autocomplete' => 'new-password'],
'constraints' => [
new NotBlank(
message: 'Please enter a password',
),
new Length(
min: 6,
minMessage: 'Your password should be at least {{ limit }} characters',
// max length allowed by Symfony for security reasons
max: 4096,
),
],
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}

View file

@ -0,0 +1,39 @@
<?php
namespace App\Form;
use App\Entity\Tag;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Count;
use Symfony\UX\Autocomplete\Form\AsEntityAutocompleteField;
use Symfony\UX\Autocomplete\Form\BaseEntityAutocompleteType;
#[AsEntityAutocompleteField]
class TagAutocompleteField extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'class' => Tag::class,
'searchable_fields' => ['title'],
'label' => 'Tag',
'choice_label' => 'title',
'multiple' => true,
'required' => false,
/* TODO this isn't natively supported collections/choice type
so we're going to manually do it for now
*/
/*'tom_select_options' => [
'create' => true,
] */
]);
}
public function getParent(): string
{
return BaseEntityAutocompleteType::class;
}
}

View file

@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\BrainPage;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<BrainPage>
*/
class BrainPageRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, BrainPage::class);
}
// /**
// * @return BrainPage[] Returns an array of BrainPage objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('b')
// ->andWhere('b.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('b.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?BrainPage
// {
// return $this->createQueryBuilder('b')
// ->andWhere('b.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View file

@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\Category;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Category>
*/
class CategoryRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Category::class);
}
// /**
// * @return Category[] Returns an array of Category objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('c')
// ->andWhere('c.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('c.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Category
// {
// return $this->createQueryBuilder('c')
// ->andWhere('c.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View file

@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\Page;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Page>
*/
class PageRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Page::class);
}
// /**
// * @return Page[] Returns an array of Page objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('p.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Page
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View file

@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\Photo;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Photo>
*/
class PhotoRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Photo::class);
}
// /**
// * @return Photo[] Returns an array of Photo objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('p.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Photo
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View file

@ -0,0 +1,50 @@
<?php
namespace App\Repository;
use App\Entity\Photos;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Photos>
*/
class PhotosRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Photos::class);
}
public function findAllOrderByLatest(): ?array {
return $this->createQueryBuilder('photos')
->orderBy('photos.date', 'DESC')
->getQuery()
->getResult();
}
// /**
// * @return Photos[] Returns an array of Photos objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('p.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Photos
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View file

@ -0,0 +1,49 @@
<?php
namespace App\Repository;
use App\Entity\Post;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Post>
*/
class PostRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Post::class);
}
public function findAllOrderByLatest(): array {
return $this->createQueryBuilder('post')
->orderBy('post.date', 'DESC')
->getQuery()
->getResult();
}
// /**
// * @return Post[] Returns an array of Post objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('p.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Post
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View file

@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\Tag;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Tag>
*/
class TagRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Tag::class);
}
// /**
// * @return Tag[] Returns an array of Tag objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('t')
// ->andWhere('t.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('t.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Tag
// {
// return $this->createQueryBuilder('t')
// ->andWhere('t.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View file

@ -0,0 +1,60 @@
<?php
namespace App\Repository;
use App\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
/**
* @extends ServiceEntityRepository<User>
*/
class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, User::class);
}
/**
* Used to upgrade (rehash) the user's password automatically over time.
*/
public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void
{
if (!$user instanceof User) {
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $user::class));
}
$user->setPassword($newHashedPassword);
$this->getEntityManager()->persist($user);
$this->getEntityManager()->flush();
}
// /**
// * @return User[] Returns an array of User objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('u')
// ->andWhere('u.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('u.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?User
// {
// return $this->createQueryBuilder('u')
// ->andWhere('u.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View file

@ -0,0 +1,37 @@
<?php
namespace App\Service;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\String\Slugger\SluggerInterface;
class PhotoUploader {
public function __construct(
private string $targetDirectory,
private SluggerInterface $slugger,
){}
public function upload(UploadedFile $file, string $galleryName) : string {
$this->setTargetDirectory('photos/' . strtolower(str_replace(' ', '_', $galleryName)));
$originalFilename = pathInfo($file->getClientOriginalName(), PATHINFO_FILENAME);
$safeFilename = $this->slugger->slug($originalFilename);
$filename = $safeFilename . '.' . $file->guessExtension();
try {
$file->move($this->getTargetDirectory(), $filename);
} catch (FileException $e) {
//todo
}
return $filename;
}
public function getTargetDirectory() : string {
return $this->targetDirectory;
}
public function setTargetDirectory(string $directory) : void {
$this->targetDirectory = $directory;
}
}