Spaces:
No application file
No application file
File size: 1,645 Bytes
d2897cd |
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 |
<?php
namespace Mautic\EmailBundle\Entity;
use Mautic\CoreBundle\Entity\CommonRepository;
use Mautic\CoreBundle\Helper\DateTimeHelper;
/**
* @extends CommonRepository<StatDevice>
*/
class StatDeviceRepository extends CommonRepository
{
public function getDeviceStats($emailIds, \DateTime $fromDate = null, \DateTime $toDate = null): array
{
$qb = $this->getEntityManager()->getConnection()->createQueryBuilder();
$qb->select('count(es.id) as count, d.device as device, es.list_id')
->from(MAUTIC_TABLE_PREFIX.'email_stats_devices', 'ed')
->join('ed', MAUTIC_TABLE_PREFIX.'lead_devices', 'd', 'd.id = ed.device_id')
->join('ed', MAUTIC_TABLE_PREFIX.'email_stats', 'es', 'es.id = ed.stat_id');
if (null != $emailIds) {
if (!is_array($emailIds)) {
$emailIds = [(int) $emailIds];
}
$qb->where(
$qb->expr()->in('es.email_id', $emailIds)
);
}
$qb->groupBy('es.list_id, d.device');
if (null !== $fromDate) {
// make sure the date is UTC
$dt = new DateTimeHelper($fromDate);
$qb->andWhere(
$qb->expr()->gte('es.date_read', $qb->expr()->literal($dt->toUtcString()))
);
}
if (null !== $toDate) {
// make sure the date is UTC
$dt = new DateTimeHelper($toDate);
$qb->andWhere(
$qb->expr()->lte('es.date_read', $qb->expr()->literal($dt->toUtcString()))
);
}
return $qb->executeQuery()->fetchAllAssociative();
}
}
|