[MAILPOET-1571]
This commit is contained in:
Pavel Dohnal
2019-01-10 11:04:51 +01:00
parent 96f2f79d48
commit ef5eba31d1
7 changed files with 709 additions and 23 deletions

View File

@@ -5,4 +5,19 @@ if(!defined('ABSPATH')) exit;
class NewsletterLink extends Model {
public static $_table = MP_NEWSLETTER_LINKS_TABLE;
static function findTopLinkForNewsletter(Newsletter $newsletter) {
return self::selectExpr('links.*')
->selectExpr('count(*)', 'clicksCount')
->tableAlias('links')
->innerJoin(StatisticsClicks::$_table,
array('clicks.link_id', '=', 'links.id'),
'clicks')
->where('newsletter_id', $newsletter->id())
->groupBy('links.id')
->orderByDesc('clicksCount')
->limit(1)
->findOne();
}
}

View File

@@ -32,6 +32,15 @@ class ScheduledTask extends Model {
);
}
/** @return StatsNotification */
function statsNotification() {
return $this->hasOne(
StatsNotification::class,
'task_id',
'id'
);
}
function pause() {
$this->set('status', self::STATUS_PAUSED);
$this->save();

View File

@@ -5,6 +5,15 @@ namespace MailPoet\Models;
class StatsNotification extends Model {
public static $_table = MP_STATS_NOTIFICATIONS_TABLE;
/** @return Newsletter */
public function newsletter() {
return $this->hasOne(
Newsletter::class,
'id',
'newsletter_id'
);
}
/** @return StatsNotification */
static function createOrUpdate($data = array()) {
$model = null;