This repository was archived by the owner on Jun 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApiLogQuery.php
More file actions
65 lines (57 loc) · 1.49 KB
/
ApiLogQuery.php
File metadata and controls
65 lines (57 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace Chaplean\Bundle\ApiClientBundle\Query;
use Chaplean\Bundle\ApiClientBundle\Entity\ApiLog;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Query;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bridge\Doctrine\RegistryInterface;
/**
* Class ApiLogQuery.
*
* @package Chaplean\Bundle\ApiClientBundle\Query
* @author Hugo - Chaplean <hugo@chaplean.coop>
* @copyright 2014 - 2018 Chaplean (http://www.chaplean.coop)
*/
class ApiLogQuery
{
/**
* @var EntityManager
*/
protected $em;
/**
* ApiLogQuery constructor.
*
* @param RegistryInterface|ManagerRegistry $registry
*/
public function __construct(/** ManagerRegistry */$registry)
{
$this->em = $registry->getManager();
}
/**
* @param \DateTime $dateTime
*
* @return Query
*/
public function createFindIdsMostRecentThan(\DateTime $dateTime)
{
$qb = $this->em->createQueryBuilder();
return $qb->select('log.id')
->from(ApiLog::class, 'log')
->where('log.dateAdd < :dateLimit')
->setParameter('dateLimit', $dateTime->format('Y-m-d'))
->getQuery();
}
/**
* @param integer $id
*
* @return Query|null
*/
public function createDeleteById($id)
{
$qb = $this->em->createQueryBuilder();
return $qb->delete(ApiLog::class, 'log')
->where('log.id = :id')
->setParameter('id', $id)
->getQuery();
}
}