【问题标题】:Concrete5 Filter SQL具体5过滤SQL
【发布时间】:2014-02-14 09:22:37
【问题描述】:

我正在尝试修改 Concrete5 插件,该插件会在用户订阅即将到期时向用户发送警告电子邮件。它的工作原理是首先过滤掉已经收到通知的用户,然后选择截至今天订阅距到期日期 (expirationDate) 给定天数 (emailOnExpirationDays) 的用户。

我的问题是我需要能够通知用户 3 次而不是一次。我想提前 30 天、5 天和 1 天通知他们。我的第一个障碍是只过滤掉 5 天内通知的用户(25 天前没有故意通知)。如何修改下面的 PHP 和 SQL 来完成此操作?注释掉的代码是我尝试过的东西。过滤功能信息为here。

集合在这里被实例化:

$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, '!=');
}

}

【问题讨论】:

    标签: php mysql sql concrete5


    【解决方案1】:

    以下 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())
    

    基本上,您检查的是到期日期减去警告期是否介于 3 天前和现在之间。这允许在工作中出现小(3 天)光点而不运行。具体来说,如果到期日期是 3 月 15 日,它将在 2 月 15 日(假设是 30 天)和 2 月 18 日之间返回 true。但是我们不想在此期间多次发送它(如果作业可能每天运行一次以上,这将是一个潜在的问题),因此您还要检查 warnDate 是否至少在 4 天前。这很适合您的 30/5/1 周期。

    要将其放入 filterBy...Warned() 函数,您将删除 $this-&gt;filter('warnedDate', null); 行,然后删除 DATE_SUB 行,然后“直接”添加 SQL:

    $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())");
    

    【讨论】:

    • 谢谢你的真棒!现在想知道如何测试它。应该很有趣哈哈
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-31
    • 2019-11-23
    • 1970-01-01
    • 2021-07-09
    • 1970-01-01
    相关资源
    最近更新 更多