<?php

namespace App\Repository;

use App\Entity\Note;
use DateInterval;
use DateTime;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @extends ServiceEntityRepository<Note>
 */
class NoteRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, Note::class);
    }

    public function countWherePublishedOnDate(DateTime $date): int {
        $dateStr = substr($date->format('c'), 0, 10);

        $wherePublishedOnDate = $this->createQueryBuilder('n')
            ->andWhere('n.publishedDate = :date')
            ->setParameter('date', $dateStr)
            ->getQuery()
            ->execute();

        return count($wherePublishedOnDate);
    }

       /**
        * @return Note[] Returns an array of Note objects
        */
       public function findAllOrderedBySlugDesc(): array
       {
           return $this->createQueryBuilder('n')
               ->orderBy('n.slug', 'DESC')
               ->getQuery()
               ->getResult();
       }
}
