contributions/usermanagement.notifications/behaviour/commands/notifications/mail.cmd.php
Go to the documentation of this file.00001 <?php 00002 /** 00003 * Send a notification mail, if necessary 00004 */ 00005 class MailNotificationsCommand extends CommandChain { 00006 protected function do_execute() { 00007 $ret = new Status(); 00008 $n = $this->get_instance(); 00009 Load::models('notificationssettings'); 00010 $settings = NotificationsSettings::get_for_user($n->id_user); 00011 if ($settings === false || $settings->should_notification_be_processed($n, NotificationsSettings::TYPE_MAIL)) { 00012 $this->append($this->create_mail_command($n)); 00013 $n->add_sent_as(Notifications::DELIVER_MAIL); 00014 $this->append(CommandsFactory::create_command($n, 'update', array())); 00015 } 00016 return $ret; 00017 } 00018 00019 protected function create_mail_command($notification) { 00020 Load::commands('generics/mail'); 00021 $templates = array( 00022 'notifications/mail/single_' . strtolower($notification->source), 00023 'notifications/mail/single' 00024 ); 00025 $cmd = new MailCommand( 00026 $notification->get_title(), 00027 $notification->get_user()->email, 00028 $templates, 00029 array( 00030 'notification' => $notification 00031 ) 00032 ); 00033 return $cmd; 00034 } 00035 }