protected function NewsletterAutomated::updateStats in Newsletter 7
Same name and namespace in other branches
- 7.2 includes/newsletter.automated.inc \NewsletterAutomated::updateStats()
Updates newsletter list after it is sent.
Parameters
$times_sent: The number of subscribers the newsletter was sent to.
Return value
Boolean depending on whether the update succeeded or not.
1 call to NewsletterAutomated::updateStats()
- NewsletterAutomated::send in includes/
newsletter.automated.inc - Replaces tokens and sends the current newsletter.
File
- includes/
newsletter.automated.inc, line 191 - Contains NewsletterMail and NewsletterCustom that extend NewsletterBasic.
Class
- NewsletterAutomated
- Newsletter class that sends automated, non-custom newsletters with dynamic content based on taxonomy terms.
Code
protected function updateStats($times_sent) {
switch ($this->list->send_rate) {
case 'Daily':
$send_again = date('Y-m-d', strtotime('+1 day'));
break;
case 'Weekly':
$send_again = date('Y-m-d', strtotime('+1 week'));
break;
case 'Monthly':
$send_again = date('Y-m-d', strtotime('+1 month'));
break;
default:
$send_again = NULL;
}
$updated_list = db_update('newsletter_list')
->fields(array(
'last_sent' => REQUEST_TIME,
'send_again' => $send_again,
))
->condition('nlid', $this->list->nlid)
->execute();
$sent_so_far = db_query('SELECT subscribers_sent
FROM {newsletter_newsletter} WHERE nnid = :id', array(
':id' => $this->newsletter->nnid,
))
->fetchField();
$subscribers_sent = isset($sent_so_far) ? $sent_so_far + $times_sent : $times_sent;
$updated_stats = db_update('newsletter_newsletter')
->fields(array(
'last_sent' => REQUEST_TIME,
'subscribers_sent' => $subscribers_sent,
))
->condition('nnid', $this->newsletter->nnid)
->execute();
return isset($updated_list) && isset($updated_stats) ? TRUE : FALSE;
}