Files
piratepoet/lib/Form/FormsRepository.php
Rodrigo Primo e054f05222 Refactor Forms::trash() to use Doctrine
[MAILPOET-3039]
2021-04-12 13:35:14 +02:00

45 lines
956 B
PHP

<?php
namespace MailPoet\Form;
use MailPoet\Doctrine\Repository;
use MailPoet\Entities\FormEntity;
use MailPoetVendor\Carbon\Carbon;
/**
* @extends Repository<FormEntity>
*/
class FormsRepository extends Repository {
protected function getEntityClassName() {
return FormEntity::class;
}
/**
* @return FormEntity[]
*/
public function findAllNotDeleted(): array {
return $this->entityManager
->createQueryBuilder()
->select('f')
->from(FormEntity::class, 'f')
->where('f.deletedAt IS NULL')
->orderBy('f.updatedAt', 'desc')
->getQuery()
->getResult();
}
public function count(): int {
return (int)$this->doctrineRepository
->createQueryBuilder('f')
->select('count(f.id)')
->getQuery()
->getSingleScalarResult();
}
public function trash(FormEntity $form) {
$form->setDeletedAt(Carbon::now());
$this->persist($form);
$this->flush();
}
}