notes index
This commit is contained in:
@@ -11,11 +11,12 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use function Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class GuiController extends AbstractController {
|
||||
#[Route('/')]
|
||||
#[Template('/index.html.twig')]
|
||||
public function index(): Array {
|
||||
public function index(): array {
|
||||
return [
|
||||
'title' => 'Joe Carstairs',
|
||||
'description' => 'Joe Carstairs\' personal website',
|
||||
@@ -24,27 +25,15 @@ class GuiController extends AbstractController {
|
||||
|
||||
#[Route('/notes', name: 'notes')]
|
||||
#[Template('/notes.html.twig')]
|
||||
public function notes(): Array {
|
||||
return [
|
||||
'title' => 'Joe Carstairs\' notes',
|
||||
'description' => 'Joe Carstairs\' notes',
|
||||
];
|
||||
}
|
||||
|
||||
#[Route('/note/{slug}', name: 'note')]
|
||||
#[Template('/note.html.twig')]
|
||||
public function note(
|
||||
public function notes(
|
||||
EntityManagerInterface $entityManager,
|
||||
string $slug,
|
||||
): array {
|
||||
$repository = $entityManager->getRepository(Note::class);
|
||||
$note = $repository->findOneBy(['slug' => $slug]);
|
||||
$notes = $entityManager->getRepository(Note::class)->findAll();
|
||||
|
||||
return [
|
||||
'title' => 'Joe Carstairs\' notes',
|
||||
'description' => 'Joe Carstairs\' notes',
|
||||
'note' => $note,
|
||||
'slug' => $slug,
|
||||
'notes' => $notes,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -84,4 +73,24 @@ class GuiController extends AbstractController {
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
#[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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,20 +19,15 @@ class NoteRepository extends ServiceEntityRepository
|
||||
}
|
||||
|
||||
public function countWherePublishedOnDate(DateTime $date): int {
|
||||
$min = new DateTime($date->format('c'));
|
||||
$min->setTime(0, 0, 0, 0);
|
||||
$max = new DateTime($min->format('c'));
|
||||
$max->add(DateInterval::createFromDateString('1 day'));
|
||||
$dateStr = substr($date->format('c'), 0, 10);
|
||||
|
||||
$wherePublishedOnDate = $this->createQueryBuilder('n')
|
||||
->andWhere('n.publishedDate >= :min')
|
||||
->andWhere('n.publishedDate < :max')
|
||||
->setParameter('min', $min)
|
||||
->setParameter('max', $max)
|
||||
->andWhere('n.publishedDate = :date')
|
||||
->setParameter('date', $dateStr)
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
return count($wherePublishedOnDate);
|
||||
return count($wherePublishedOnDate);
|
||||
}
|
||||
|
||||
// /**
|
||||
|
||||
@@ -3,5 +3,12 @@
|
||||
{% block content %}
|
||||
<section>
|
||||
<h1>Notes</h1>
|
||||
|
||||
{% for note in notes %}
|
||||
<h2><a href="/notes/{{ note.slug }}">Note {{ note.slug }}</a></h2>
|
||||
<p>{{ note.content }}</p>
|
||||
{% else %}
|
||||
<p>I have no notes.</p>
|
||||
{% endfor %}
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user