Use Newsletter Link Entity in Stats Notifications

[MAILPOET-2439]
This commit is contained in:
Pavel Dohnal
2019-10-28 09:37:01 +01:00
committed by Jack Kitterhing
parent 4c960a1a44
commit ad6e6009d2
7 changed files with 202 additions and 29 deletions

View File

@ -12,27 +12,4 @@ namespace MailPoet\Models;
class NewsletterLink extends Model {
public static $_table = MP_NEWSLETTER_LINKS_TABLE;
const UNSUBSCRIBE_LINK_SHORT_CODE = '[link:subscription_unsubscribe_url]';
/**
* @param Newsletter $newsletter
* @return NewsletterLink|null
*/
static function findTopLinkForNewsletter(Newsletter $newsletter) {
$link = self::selectExpr('links.*')
->selectExpr('count(*)', 'clicksCount')
->tableAlias('links')
->innerJoin(StatisticsClicks::$_table,
['clicks.link_id', '=', 'links.id'],
'clicks')
->where('newsletter_id', $newsletter->id())
->groupBy('links.id')
->orderByDesc('clicksCount')
->limit(1)
->findOne();
if (!$link) {
return null;
}
return $link;
}
}