public function executeSendAlerts()
 {
     $user_id = $this->getRequestParameter('user_id');
     $last_alert = $this->getRequestParameter('last_alert');
     $this->user = OppUserPeer::retrieveByPK($user_id);
     $this->sf_site_url = sfConfig::get('sf_site_url', 'openparlamento');
     $this->user_token = $this->user->getToken();
     $this->user_alerts = oppAlertingTools::getUserAlerts($this->user, sfConfig::get('app_alert_max_results', 50), $last_alert);
     $this->n_alerts = OppAlertUserPeer::countUserAlerts($this->user);
     $this->n_total_notifications = oppAlertingTools::countTotalAlertsNotifications($this->user_alerts);
     // do not send email if no news
     if ($this->n_alerts == 0) {
         return sfView::NONE;
     }
     // mail class initialization
     $mail = new sfMail();
     $mail->setCharset('utf-8');
     $mail->setContentType('text/html');
     // definition of the required parameters
     if ($this->user->isAdhoc()) {
         $mail->setSender(sfConfig::get('app_newsletter_pd_sender_address', '*****@*****.**'), sfConfig::get('app_newsletter_pd_from_tag', 'political desk'));
         $mail->setFrom(sfConfig::get('app_newsletter_pd_from_address', '*****@*****.**'), sfConfig::get('app_newsletter_pd_from_tag', 'political desk'));
     } else {
         $mail->setSender(sfConfig::get('app_newsletter_sender_address', '*****@*****.**'), sfConfig::get('app_newsletter_from_tag', 'openparlamento'));
         $mail->setFrom(sfConfig::get('app_newsletter_from_address', '*****@*****.**'), sfConfig::get('app_newsletter_from_tag', 'openparlamento'));
     }
     $mail->addAddress($this->user->getEmail());
     // invia tutte le mail in BCC a un indirizzo di servizio
     if ($this->user->isAdhoc()) {
         $mail->addBcc('*****@*****.**');
     }
     // alert utente espansi per il subject della mail
     $user_alerts_expanded = join(", ", array_map('extractTerm', array_slice($this->user_alerts, 0, 3))) . ($this->n_alerts > 3 ? ',...' : '');
     $subj = sprintf("%d %s per %s che stai monitorando (%s) ", $this->n_total_notifications, $this->n_total_notifications == 1 ? 'avviso' : 'avvisi', $this->n_alerts == 1 ? 'il termine' : 'i ' . $this->n_alerts . ' termini', $user_alerts_expanded);
     $mail->setSubject($subj);
     $this->mail = $mail;
 }
/**
 * fetch today's alert regarding terms monitored by the user
 *
 * @param string $user - OppUser object
 * @return void
 * @author Guglielmo Celata
 */
function opp_test_single_user_alerts($user, $last_alert)
{
    $start_time = microtime(true);
    $df = new sfDateFormat('it_IT');
    echo pakeColor::colorize(sprintf("Processo l'utente %s (%s)...\n", $user, $user->getToken()), array('bold' => true));
    echo pakeColor::colorize(sprintf("Ultimo alert: %s\n", $last_alert));
    $user_alerts = oppAlertingTools::getUserAlerts($user, sfConfig::get('app_alert_max_results', 50), $last_alert);
    $n_alerts = OppAlertUserPeer::countUserAlerts($user);
    $n_total_notifications = oppAlertingTools::countTotalAlertsNotifications($user_alerts);
    if ($n_total_notifications > 0) {
        $user_alerts_expanded = join(", ", array_map('extractTerm', array_slice($user_alerts, 0, 5))) . ($n_alerts > 5 ? ',...' : '');
        echo pakeColor::colorize(sprintf("%d %s per %s (%s)\n\n", $n_total_notifications, $n_total_notifications == 1 ? 'avviso' : 'avvisi', $n_alerts == 1 ? 'un termine' : $n_alerts . ' termini', $user_alerts_expanded));
        echo pakeTaskUserAlerts($user_alerts);
    } else {
        echo pakeColor::colorize(sprintf(" (nessun avviso)\n\n"));
    }
    $execution_time = microtime(true) - $start_time;
}