Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
MailNotificator Class Reference
Inheritance diagram for MailNotificator:
Notificator

Public Member Functions

 createMail ()
 notify (Notification $notification)

Public Attributes

 $cacheTime = 3600
 $defaultEmails = array()
 $phpMailer = array()

Protected Member Functions

 validate ($recipient)

Detailed Description

Gentics Portal.Node PHP Author & Copyright (c) by Gentics Software GmbH sales.nosp@m.@gen.nosp@m.tics..nosp@m.com http://www.gentics.com Licenses can be found in the LICENSE.txt file in the root-folder of this installation You must not use this software without a valid license agreement.

Class for notification users via email

Definition at line 13 of file MailNotificator.php.

Member Function Documentation

MailNotificator::createMail ( )

Create instance of mail object

Returns
PHPMailer

Definition at line 35 of file MailNotificator.php.

Referenced by notify().

{
$mail = new PHPMailer(true);
foreach ($this->phpMailer as $prop => $value) {
$mail->$prop = $value;
}
return $mail;
}
MailNotificator::notify ( Notification  $notification)

Send notification to all recipients who is instance of EmailRecipient

Parameters
Notification$notificationoccurred notification
Returns
void

Reimplemented from Notificator.

Definition at line 73 of file MailNotificator.php.

References createMail(), and validate().

{
foreach ($notification->recipients as $recipient) {
if ($this->validate($recipient)) {
$mail = $this->createMail();
if ($recipient->from) {
$mail->SetFrom($recipient->from);
}
$mail->AddAddress($recipient->to);
$mail->Subject = $notification->subject;
$mail->MsgHTML($notification->message);
try {
$mail->Send();
Yii::trace("Mail sent success. Subject:{$notification->subject}. To:{$recipient->to}, From: {$recipient->from}", 'MailNotificator');
} catch (Exception $e) {
Yii::log($e->getMessage(), CLogger::LEVEL_ERROR);
Yii::trace("Mail sent FAIL. Subject:{$notification->subject}. To:{$recipient->to}, From: {$recipient->from}", 'MailNotificator');
}
}
}
}
MailNotificator::validate (   $recipient)
protected

Check if email recipient is allowed to get mails

Parameters
EmailRecipient$recipientrecipient
Returns
bool

Definition at line 51 of file MailNotificator.php.

References User\model().

Referenced by notify().

{
if ($recipient instanceof EmailRecipient) {
if (!$recipient->skipValidation && $userRecipient = User::model()->cache(Yii::app()->notificationManager->cacheTime)->with('profile')->findByAttributes(array('email' => $recipient->to))) {
if ($userRecipient->profile->send_me_notifications == false) {
Yii::trace("Email skipped {$recipient->to}", 'MailNotificator');
return false;
}
}
Yii::trace("Email approved {$recipient->to}", 'MailNotificator');
return true;
}
return false;
}

The documentation for this class was generated from the following file: