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