Files
piratepoet/lib/Models/StatisticsClicks.php
Rodrigo Primo 8b7815caf8 Use Doctrine for the opens and clicks exporters
This commit refactors the code that handles exporting e-mails opens and
clicks when generating the personal data file to use Doctrine instead of
Paris. I opted to do this in this task as opens and clicks code share
some functionality, and I didn't want to add more code that relies on
Paris, as we are eventually going to remove it.

[MAILPOET-3738]
2021-08-25 17:01:33 +02:00

38 lines
1.0 KiB
PHP

<?php
namespace MailPoet\Models;
use DateTimeInterface;
/**
* @property int $newsletterId
* @property int $subscriberId
* @property int $queueId
* @property int $linkId
* @property int $count
*/
class StatisticsClicks extends Model {
public static $_table = MP_STATISTICS_CLICKS_TABLE; // phpcs:ignore PSR2.Classes.PropertyDeclaration
public static function findLatestPerNewsletterBySubscriber(Subscriber $subscriber, DateTimeInterface $from, DateTimeInterface $to) {
// subquery to find latest click IDs for each newsletter
$table = self::$_table;
$latestClickIdsPerNewsletterQuery = "
SELECT MAX(id)
FROM $table
WHERE subscriber_id = :subscriber_id
AND updated_at > :from
AND updated_at < :to
GROUP BY newsletter_id
";
return static::tableAlias('clicks')
->whereRaw("clicks.id IN ($latestClickIdsPerNewsletterQuery)", [
'subscriber_id' => $subscriber->id,
'from' => $from->format('Y-m-d H:i:s'),
'to' => $to->format('Y-m-d H:i:s'),
])
->findMany();
}
}