PHP Class EmailTemplate, vanilla

ファイルを表示 Open project: vanilla/vanilla Class Usage Examples

Protected Properties

Property Type Description
$backgroundColor The hex color code of the background, must include the leading '#'.
$button An array representing a button with the following keys: 'url' => The href value of the button. 'text' => The button text. 'textColor' => The hex color code of the button text, must include the leading '#'. 'backgroundColor' => The hex color code of the button background, must include the leading '#'.
$containerBackgroundColor The hex color code of the container background, must include the leading '#'.
$defaultButtonBackgroundColor The default hex color code of the button background, must include the leading '#'.
$defaultButtonTextColor The default hex color code of the button text, must include the leading '#'.
$footer An array representing a footer with the following keys: 'text' => The HTML-formatted footer text. 'textColor' => The hex color code of the footer text, must include the leading '#'. 'backgroundColor' => The hex color code of the footer background, must include the leading '#'.
$image An array representing an image with the following keys: 'source' => The image source url. 'link' => The href value of the image wrapper. 'alt' => The alt value of the image tag.
$lead The HTML formatted email lead (sub-title, appears under title).
$message The HTML formatted email message (the body of the email).
$plaintext Whether to render in plaintext.
$textColor The hex color code of the text, must include the leading '#'.
$title The HTML formatted email title.
$view The path to the email view.

Public Methods

Method Description
__construct ( string $message = '', string $title = '', string $lead = '', string $view = 'email-basic' )
getBackgroundColor ( ) : string
getContainerBackgroundColor ( ) : string
getDefaultButtonBackgroundColor ( ) : string
getDefaultButtonTextColor ( ) : string
getDefaultEmailImage ( ) : array Retrieves default values for the email image.
getFooter ( ) : string
getImage ( ) : array
getLead ( ) : string
getMessage ( ) : string
getTextColor ( ) : string
getTitle ( ) : string
isPlaintext ( ) : boolean
removeButton ( ) : EmailTemplate Remove the button.
setBackgroundColor ( string $color ) : EmailTemplate
setButton ( string $url, string $text, string $textColor = '', string $backgroundColor = '' ) : EmailTemplate Set the button property.
setContainerBackgroundColor ( string $color ) : EmailTemplate
setDefaultButtonBackgroundColor ( string $color ) : EmailTemplate Sets the default color for the button background.
setDefaultButtonTextColor ( string $color ) : EmailTemplate Sets the default color for the button text.
setFooter ( string $text, string $textColor = '', string $backgroundColor = '' ) : EmailTemplate Sets the footer. The footer background and text colors default to the button background and text colors.
setImage ( string $sourceUrl = '', string $linkUrl = '', string $alt = '' ) : EmailTemplate Set the image property.
setImageArray ( $image ) : EmailTemplate Set the image property using an array with the following keys: 'source' => The image source url.
setLead ( string $lead ) : EmailTemplate
setMessage ( string $message, boolean $convertNewlines = false, boolean $filter = false ) : EmailTemplate
setPlaintext ( boolean $plainText )
setTextColor ( string $color ) : EmailTemplate
setTitle ( string $title ) : EmailTemplate
setView ( string $view, string $controllerName = 'email', string $applicationFolder = 'dashboard' ) : EmailTemplate
toString ( ) : string Render the email.

Protected Methods

Method Description
formatContent ( string $html, boolean $convertNewlines = false, boolean $filter = false ) : string Filters an unsafe HTML string and returns it.
objectToArray ( EmailTemplate $email ) : array Copies the email object to an array. A simple (array) typecast won't work, since the properties are protected and as such, add unwanted information to the array keys.
plainTextEmail ( ) : string Renders a plaintext email.
setDefaultEmailImage ( ) Sets the default image for the email template.

Method Details

__construct() public method

public __construct ( string $message = '', string $title = '', string $lead = '', string $view = 'email-basic' )
$message string HTML formatted email message (the body of the email).
$title string HTML formatted email title.
$lead string HTML formatted email lead (sub-title, appears under title).
$view string

formatContent() protected method

Filters an unsafe HTML string and returns it.
protected formatContent ( string $html, boolean $convertNewlines = false, boolean $filter = false ) : string
$html string The HTML to filter.
$convertNewlines boolean Whether to convert new lines to html br tags.
$filter boolean Whether to escape HTML or not.
return string The filtered HTML string.

getBackgroundColor() public method

public getBackgroundColor ( ) : string
return string The hex color code of the background.

getContainerBackgroundColor() public method

public getContainerBackgroundColor ( ) : string
return string The hex color code of the container background.

getDefaultButtonBackgroundColor() public method

public getDefaultButtonBackgroundColor ( ) : string
return string The default hex color code of the button background, must include the leading '#'.

getDefaultButtonTextColor() public method

public getDefaultButtonTextColor ( ) : string
return string The default hex color code of the button text, must include the leading '#'.

getDefaultEmailImage() public method

Retrieves default values for the email image.
public getDefaultEmailImage ( ) : array
return array An array representing an image.

getFooter() public method

public getFooter ( ) : string
return string The HTML formatted email footer.

getImage() public method

public getImage ( ) : array
return array An array representing an image with the following keys: 'source' => The image source url. 'link' => The href value of the image wrapper. 'alt' => The alt value of the image tag.

getLead() public method

public getLead ( ) : string
return string The HTML formatted email lead (sub-title, appears under title).

getMessage() public method

public getMessage ( ) : string
return string The HTML formatted email message (the body of the email).

getTextColor() public method

public getTextColor ( ) : string
return string The hex color code of the text.

getTitle() public method

public getTitle ( ) : string
return string The HTML formatted email title.

isPlaintext() public method

public isPlaintext ( ) : boolean
return boolean Whether to render in plaintext.

objectToArray() protected method

Copies the email object to an array. A simple (array) typecast won't work, since the properties are protected and as such, add unwanted information to the array keys.
protected objectToArray ( EmailTemplate $email ) : array
$email EmailTemplate The email object.
return array Copy of email object in an array format for output.

plainTextEmail() protected method

Renders a plaintext email.
protected plainTextEmail ( ) : string
return string A plaintext email.

removeButton() public method

Remove the button.
public removeButton ( ) : EmailTemplate
return EmailTemplate $this The calling object.

setBackgroundColor() public method

public setBackgroundColor ( string $color ) : EmailTemplate
$color string The hex color code of the background, must include the leading '#'.
return EmailTemplate $this The calling object.

setButton() public method

Set the button property.
public setButton ( string $url, string $text, string $textColor = '', string $backgroundColor = '' ) : EmailTemplate
$url string The href value of the button.
$text string The button text.
$textColor string The hex color code of the button text, must include the leading '#'.
$backgroundColor string The hex color code of the button background, must include the leading '#'.
return EmailTemplate $this The calling object.

setContainerBackgroundColor() public method

public setContainerBackgroundColor ( string $color ) : EmailTemplate
$color string The hex color code of the container background, must include the leading '#'.
return EmailTemplate $this The calling object.

setDefaultButtonBackgroundColor() public method

The background color of the EmailTemplate's button property can be overridden by setting $button['backgroundColor']
public setDefaultButtonBackgroundColor ( string $color ) : EmailTemplate
$color string The default hex color code of the button background, must include the leading '#'.
return EmailTemplate $this The calling object.

setDefaultButtonTextColor() public method

The text color of the EmailTemplate's button property can be overridden by setting $button['textColor']
public setDefaultButtonTextColor ( string $color ) : EmailTemplate
$color string The default hex color code of the button text, must include the leading '#'.
return EmailTemplate $this The calling object.

setDefaultEmailImage() protected method

Sets the default image for the email template.
protected setDefaultEmailImage ( )

setFooter() public method

Sets the footer. The footer background and text colors default to the button background and text colors.
public setFooter ( string $text, string $textColor = '', string $backgroundColor = '' ) : EmailTemplate
$text string The HTML formatted email footer text.
$textColor string The hex color code of the footer text, must include the leading '#'.
$backgroundColor string The hex color code of the footer background, must include the leading '#'.
return EmailTemplate $this The calling object.

setImage() public method

Set the image property.
public setImage ( string $sourceUrl = '', string $linkUrl = '', string $alt = '' ) : EmailTemplate
$sourceUrl string The image source url.
$linkUrl string The href value of the image wrapper.
$alt string The alt value of the img tag.
return EmailTemplate $this The calling object.

setImageArray() public method

'link' => The href value of the image wrapper. 'alt' => The alt value of the img tag.
public setImageArray ( $image ) : EmailTemplate
return EmailTemplate $this The calling object.

setLead() public method

public setLead ( string $lead ) : EmailTemplate
$lead string The HTML formatted email lead (sub-title, appears under title).
return EmailTemplate $this The calling object.

setMessage() public method

public setMessage ( string $message, boolean $convertNewlines = false, boolean $filter = false ) : EmailTemplate
$message string The HTML formatted email message (the body of the email).
$convertNewlines boolean Whether to convert new lines to html br tags.
$filter boolean Whether to filter HTML or not.
return EmailTemplate $this The calling object.

setPlaintext() public method

public setPlaintext ( boolean $plainText )
$plainText boolean Whether to render in plaintext.

setTextColor() public method

public setTextColor ( string $color ) : EmailTemplate
$color string The hex color code of the text, must include the leading '#'.
return EmailTemplate $this The calling object.

setTitle() public method

public setTitle ( string $title ) : EmailTemplate
$title string The HTML formatted email title.
return EmailTemplate $this The calling object.

setView() public method

public setView ( string $view, string $controllerName = 'email', string $applicationFolder = 'dashboard' ) : EmailTemplate
$view string The view name.
$controllerName string The controller name for the view.
$applicationFolder string The application folder for the view.
return EmailTemplate $this The calling object.

toString() public method

Render the email.
public toString ( ) : string
return string The rendered email.

Property Details

$backgroundColor protected_oe property

The hex color code of the background, must include the leading '#'.
protected $backgroundColor

$button protected_oe property

An array representing a button with the following keys: 'url' => The href value of the button. 'text' => The button text. 'textColor' => The hex color code of the button text, must include the leading '#'. 'backgroundColor' => The hex color code of the button background, must include the leading '#'.
protected $button

$containerBackgroundColor protected_oe property

The hex color code of the container background, must include the leading '#'.
protected $containerBackgroundColor

$defaultButtonBackgroundColor protected_oe property

The default hex color code of the button background, must include the leading '#'.
protected $defaultButtonBackgroundColor

$defaultButtonTextColor protected_oe property

The default hex color code of the button text, must include the leading '#'.
protected $defaultButtonTextColor

$image protected_oe property

An array representing an image with the following keys: 'source' => The image source url. 'link' => The href value of the image wrapper. 'alt' => The alt value of the image tag.
protected $image

$lead protected_oe property

The HTML formatted email lead (sub-title, appears under title).
protected $lead

$message protected_oe property

The HTML formatted email message (the body of the email).
protected $message

$plaintext protected_oe property

Whether to render in plaintext.
protected $plaintext

$textColor protected_oe property

The hex color code of the text, must include the leading '#'.
protected $textColor

$title protected_oe property

The HTML formatted email title.
protected $title

$view protected_oe property

The path to the email view.
protected $view