Hello,
-0-
start implementing this, and it is not that difficult, below is good, compact code for doing what you need and ... more
--
and i give you this because we will be implementing this in a near future release,
(... we would need a good full day or more to implement this, debug, test various configuration scenarios, add languages strings, add email templating etc, etc, plus don't want to add this new feature now ...)
-1-
just note that FLEXIcontent implementation will be what we will see best at the time, but this is a good start for you
-2-
please !!CORRECT!! the below code it is only a draft
-3-
please don't discuss this further by posting long codes that you have written, i will not look at them, but i will answer you other questions, if you have
e.g. below i describe issuing notifications as the expiration time appoaches, PLUS after it has expired
You need:
1. Create a table (3 columns):
#__content_expired_notifications
!! KEY (item_id, days_notify) // so that replacing old record will work !!
(int) item_id,
(date) publish_down
(int) days_notify
30: WARNING for 1 month prior to expire
14: WARNING for 2 weeks prior to expire,
7 : WARNING for 1 week prior to expire,
0 : WARNING for that it has expired,
Code:
$days_intervals = array(30, 14, 7, 0);
foreach($days_intervals as $days) {
$query =
'SELECT i.id, i.publish_down, i.title ' // more cols ...
.' FROM #__content AS i'
// find previous notification record
(if any ... using LEFT join)
.' LEFT JOIN #__content_expired_notifications AS n
.' ON n.item_id=i.id'
.' WHERE'
// Send notifications only for published content
'. i.state IN (1,-5)'
// that have expired ($days=0), or are $days before expiration
.' AND i.publish_down > DATE_SUB(NOW(), INTERVAL '.$days.' DAY)'
// but the notification date differs,
// so no NEW notification was sent yet !!
.' AND n.publish_down!=i.publish_down'
;
$db->setQuery($query);
$notify_items_list = $db->loadObjectList();
// NOTE 1: last AND clause detects different published_down date for a re-published_item !! so next time it re-expires e.g. after a year we will re-send a new notification
// NOTE 2: if you use CRON, LOAD joomla framework (google to find how to this) or DO NOT load it and use PHP mysqli commands
foreach ($notify_items_list as $item) {
// 1. code to send notification email
// ...
// 2. Update notifications DB table, so that next run will not
$query = 'REPLACE INTO #__content_expired_notifications'
.' (item_id, publish_down, notify_days)'
.' VALUES('.
$item->id.', '.
$db->Quote($item->publish_down).', '.
$days
.')';
$db->setQuery($query);
$db->query();
// 3. create a log file or append to a log file
// ...
}
} // end of foreach days, note THAT the VERY FIRST run will send for unexpired item 4 notifications at once BECAUSE the notifications table is empty, final code will be handling this ...