'Joe Carstairs', 'description' => 'Joe Carstairs\' personal website', ]; } #[Route('/notes', name: 'notes')] #[Template('/notes.html.twig')] public function notes( EntityManagerInterface $entityManager, ): array { $notes = $entityManager->getRepository(Note::class)->findAllOrderedBySlugDesc(); return [ 'title' => 'Joe Carstairs\' notes', 'description' => 'Joe Carstairs\' notes', 'notes' => $notes, ]; } #[IsGranted('ROLE_EDITOR')] #[Route('/notes/write')] #[Template('/write_note.html.twig')] public function writeNote( EntityManagerInterface $entityManager, Request $request, ): Response { $note = new Note(); $form = $this->createForm(NoteType::class, $note); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $note = $form->getData(); $now = new DateTime('now'); $note->setPublishedDate($now); $num_existing_notes_today = $entityManager->getRepository(Note::class)->countWherePublishedOnDate($now); $note->getPublishedDate()->setTimezone(new DateTimeZone('Europe/London')); $slug = $note->getPublishedDate()->format('Y-m-d'); if ($num_existing_notes_today > 0) { $slug = $slug . '-' . $num_existing_notes_today; } $note->setSlug($slug); $entityManager->persist($note); $entityManager->flush(); return $this->redirectToRoute('note', ['slug' => $slug]); } return $this->render('/write_note.html.twig', [ 'title' => 'Write for Joe Carstairs', 'description' => 'The authoring page for Joe Carstairs\' personal website', 'form' => $form, ]); } /** * @return array */ #[Route('/notes/{slug}', name: 'note')] #[Template('/note.html.twig')] public function note( EntityManagerInterface $entityManager, string $slug, ): array { $repository = $entityManager->getRepository(Note::class); $note = $repository->findOneBy(['slug' => $slug]); return [ 'title' => 'Joe Carstairs\' notes', 'description' => 'Joe Carstairs\' notes', 'note' => $note, 'slug' => $slug, ]; } }