我在修改一個Concrete5插件,當用戶的訂閱即將到期時向用戶發送警告郵件。它的工作原理是先篩選出已通知的用戶,然後選擇截至今天的訂閱距離過期日期(expirationDate)爲給定天數(emailOnExpirationDays)的用戶。Concrete5 Filter SQL
我的問題是,我需要能夠通知用戶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, '!=');
}
}
謝謝你的真棒!現在要弄清楚如何測試它。應該很有趣哈哈 – CaitlinHavener