Php Concrete5过滤器SQL

Php Concrete5过滤器SQL,php,mysql,sql,concrete5,Php,Mysql,Sql,Concrete5,我试图修改一个Concrete5插件,当用户的订阅即将到期时,它会向用户发送一封警告电子邮件。它的工作原理是先过滤出已经收到通知的用户,然后选择截止到今天的订阅距离到期日期(expirationDate)有给定天数(EmailOneExpirationDays)的用户 我的问题是,我需要能够通知用户3次,而不是一次。我想提前30天、5天和1天通知他们。我的第一个障碍是只过滤出在5天内收到通知的用户(25天前没有特意通知)。如何修改下面的PHP和SQL来实现这一点?注释掉的代码是我尝试过的东西。有

我试图修改一个Concrete5插件,当用户的订阅即将到期时,它会向用户发送一封警告电子邮件。它的工作原理是先过滤出已经收到通知的用户,然后选择截止到今天的订阅距离到期日期(expirationDate)有给定天数(EmailOneExpirationDays)的用户

我的问题是,我需要能够通知用户3次,而不是一次。我想提前30天、5天和1天通知他们。我的第一个障碍是只过滤出在5天内收到通知的用户(25天前没有特意通知)。如何修改下面的PHP和SQL来实现这一点?注释掉的代码是我尝试过的东西。有关过滤器功能的信息如下所示

集合在此处实例化:

$expiringTxns = new LMemTxnList();
$expiringTxns->filterByProductWithExpirationEmailsThatShouldBeWarned();

public function filterByProductWithExpirationEmailsThatShouldBeWarned() {
    $this->setupProductExpirationQueries();//displays all with account

    //we haven't already sent out an expiration warning or, for that matter, a notice
    $this->filter('notifiedDate', null);
    $this->filter('warnedDate', null); //Caitlin commented out to allow more than one warning
    //$this->filter('warnedDate', '!= BETWEEN DATE_SUB(NOW(), INTERVAL 5 DAY) AND NOW()');


    // the emailOnExpirationDays has been properly configured
    $this->filter('emailOnExpirationDays', null, '!=');
    $this->filter('emailOnExpirationDays', 0, '>');

    //the expirationDate - warning is between 5 days ago (don't want to send a bunch of emails) and now
    //  the warning code should be getting run after the notice code, so we shouldn't have to worry about 3 day warnings and sending warning and notice at the same time
    $this->filter(null, 'DATE_SUB(expirationDate, INTERVAL emailOnExpirationDays DAY) BETWEEN DATE_SUB(NOW(), INTERVAL 5 DAY) AND NOW()');
  //$this->filter(null, 'DATE_SUB(expirationDate, INTERVAL 30 DAY) BETWEEN DATE_SUB(NOW(), INTERVAL 5 DAY) AND NOW()');

}


protected function setupProductExpirationQueries() {
    $this->addToQuery(' INNER JOIN LMemProducts ON txns.productID = LMemProducts.ID');

    // the expiration date exists (some products don't expire)
    $this->filter('expirationDate', null, '!=');

    // we're supposed to send emails
    $this->filter('emailOnExpiration', true);

    $this->filter('emailOnExpirationDays', null, '!=');
    $this->filter('emailOnExpirationDays', 0, '!=');
}
}以下SQL应该适合您:

(
    (DATE_SUB(expirationDate, 30 DAYS) BETWEEN DATE_SUB(NOW(), 3 DAYS) AND NOW())
    OR
    (DATE_SUB(expirationDate, 5 DAYS) BETWEEN DATE_SUB(NOW(), 3 DAYS) AND NOW())
    OR
    (DATE_SUB(expirationDate, 1 DAYS) BETWEEN DATE_SUB(NOW(), 3 DAYS) AND NOW())
)
AND
(DATE_ADD(warnedDate, 4 DAYS) <= NOW())

谢谢你的真棒!现在来看看如何测试它。应该很有趣,哈哈
$this->filter(null, "(
    (DATE_SUB(expirationDate, 30 DAYS) BETWEEN DATE_SUB(NOW(), 3 DAYS) AND NOW())
    OR
    (DATE_SUB(expirationDate, 5 DAYS) BETWEEN DATE_SUB(NOW(), 3 DAYS) AND NOW())
    OR
    (DATE_SUB(expirationDate, 1 DAYS) BETWEEN DATE_SUB(NOW(), 3 DAYS) AND NOW())
)
AND
(DATE_ADD(warnedDate, 4 DAYS) <= NOW())");