NewsletterLib
in package
Class newsletter library
Newsletter module class
Tags
Table of Contents
Constants
- RECIPIENT_CONSENT_GIVEN = 2
- Flag to match only recipients of which consent has been given
- RECIPIENT_CONSENT_IGNORE = 0
- Flag to ignore the consent state of recipients
- RECIPIENT_CONSENT_PENDING = 1
- Flag to match only recipients of which consent has not yet been given
- UNSUBSCRIBE_BEHAVIOR_AUTOMATIC = 'automatic'
- UNSUBSCRIBE_BEHAVIOR_MANUAL = 'manual'
- USER_TYPE_ACCESS = 'access'
- USER_TYPE_CORE = 'core'
- USER_TYPE_CRM = 'crm'
- USER_TYPE_NEWSLETTER = 'newsletter'
Properties
- $_arrRecipientTitles : mixed
- $arrLists : array<string|int, mixed>
- List of present Lists
Methods
- _addList() : bool
- Add a list with the given name and status
- _addRecipient() : bool
- Add a recipient with the given parameter values and subscribe to the lists with their ID present in $arrLists
- _addRecipientTitle() : mixed
- _createDatesDropdown() : mixed
- Create and select the date dropdowns for choosing the birthday
- _emailCode() : mixed
- _getAssociatedListsOfRecipient() : array<string|int, mixed>
- Returns an array of List IDs to which the recipient with the given ID is subscribed
- _getHTML() : mixed
- _getRecipientTitleMenu() : mixed
- _getRecipientTitles() : mixed
- _getSettings() : mixed
- This is a workaround for PHP 7 compatability.
- _initRecipientTitles() : mixed
- _isUniqueRecipientEmail() : mixed
- _setRecipientLists() : bool
- Add the recipient with the given ID to all the lists with their IDs present in the array
- _updateRecipient() : mixed
- _validateRecipientAttributes() : mixed
- autoCleanRegisters() : mixed
- Auto clean a registers
- getListIdByName() : int
- Returns the ID of the list specified by its name
- getListNameById() : mixed
- Get newsletter list name by given id
- getLists() : array<string|int, mixed>
- Returns an array of all Newsletter lists
- GetProfileURL() : mixed
- Return link to the profile of a user
- getRecipientLocaleIdByRecipientId() : int
- Returns the Language ID for a newsletter recipient
- getSettings() : mixed
- This is a workaround for PHP 7 compatability.
- GetUnsubscribeURL() : mixed
- Get the URL to the page to unsubscribe
- getUsersPreferredLanguageId() : int
- Returns the Language ID for a newsletter user
- parseConsentView() : string
- Parses the consent icons
- sendConsentConfirmationMail() : bool
- Send a consent confirmation mail to users based on mailing list
- updateRecipientConsent() : bool
- Updates recipient consent status in the newsletter_user table.
- _deleteRecipient() : bool
- Drop recipient from database
- _getGroups() : array<string|int, mixed>
- Return the access user groups
- getCountryMenu() : mixed
- getListRecipientCount() : int
- Returns the total number of recipients for a given recipient list.
- getRecipientListAssociation() : array<string|int, mixed>
- Get the list associations for all recipients.
- getSetting() : string|bool
- Return a setting from the settings table
- getUserDateTime() : string
- Get a user dateTime in H:i:s d.m.Y format from db data
- prepareForRegExp() : mixed
- prepareNewsletterLinksForSend() : mixed
Constants
RECIPIENT_CONSENT_GIVEN
Flag to match only recipients of which consent has been given
public
int
RECIPIENT_CONSENT_GIVEN
= 2
RECIPIENT_CONSENT_IGNORE
Flag to ignore the consent state of recipients
public
int
RECIPIENT_CONSENT_IGNORE
= 0
RECIPIENT_CONSENT_PENDING
Flag to match only recipients of which consent has not yet been given
public
int
RECIPIENT_CONSENT_PENDING
= 1
UNSUBSCRIBE_BEHAVIOR_AUTOMATIC
public
mixed
UNSUBSCRIBE_BEHAVIOR_AUTOMATIC
= 'automatic'
UNSUBSCRIBE_BEHAVIOR_MANUAL
public
mixed
UNSUBSCRIBE_BEHAVIOR_MANUAL
= 'manual'
USER_TYPE_ACCESS
public
mixed
USER_TYPE_ACCESS
= 'access'
USER_TYPE_CORE
public
mixed
USER_TYPE_CORE
= 'core'
USER_TYPE_CRM
public
mixed
USER_TYPE_CRM
= 'crm'
USER_TYPE_NEWSLETTER
public
mixed
USER_TYPE_NEWSLETTER
= 'newsletter'
Properties
$_arrRecipientTitles
public
mixed
$_arrRecipientTitles
= null
$arrLists
List of present Lists
private
static array<string|int, mixed>
$arrLists
= null
Tags
Methods
_addList()
Add a list with the given name and status
public
static _addList(string $listName[, bool $listStatus = false ][, mixed $notificationMail = '' ]) : bool
Upon successfully adding a new list, resets the $arrLists class variable to null.
Parameters
- $listName : string
-
The new list name
- $listStatus : bool = false
-
The new list status, defaults to false for inactive
- $notificationMail : mixed = ''
Tags
Return values
bool —True on success, false otherwise
_addRecipient()
Add a recipient with the given parameter values and subscribe to the lists with their ID present in $arrLists
public
static _addRecipient(string $email, string $uri, string $sex, mixed $salutation, string $title, string $lastname, string $firstname, mixed $position, string $company, mixed $industry_sector, string $address, string $zip, string $city, string $country, mixed $phone_office, mixed $phone_private, mixed $phone_mobile, mixed $fax, mixed $notes, string $birthday, string $status, array<string|int, mixed> $arrLists, int $language, mixed $source) : bool
Parameters
- $email : string
-
The e-mail address
- $uri : string
-
The website URL
- $sex : string
-
The sex
- $salutation : mixed
- $title : string
-
The title
- $lastname : string
-
The last name
- $firstname : string
-
The first name
- $position : mixed
- $company : string
-
The company name
- $industry_sector : mixed
- $address : string
-
The address address
- $zip : string
-
The ZIP
- $city : string
-
The city
- $country : string
-
The country ID
- $phone_office : mixed
- $phone_private : mixed
- $phone_mobile : mixed
- $fax : mixed
- $notes : mixed
- $birthday : string
-
The birth date
- $status : string
-
The active status
- $arrLists : array<string|int, mixed>
-
The array of subscribed list IDs
- $language : int
-
The preferred language ID
- $source : mixed
Tags
Return values
bool —True on success, false otherwise
_addRecipientTitle()
public
_addRecipientTitle(mixed $title) : mixed
Parameters
- $title : mixed
_createDatesDropdown()
Create and select the date dropdowns for choosing the birthday
public
_createDatesDropdown([array<string|int, mixed>|string $birthday = '' ]) : mixed
Parameters
- $birthday : array<string|int, mixed>|string = ''
_emailCode()
public
static _emailCode() : mixed
_getAssociatedListsOfRecipient()
Returns an array of List IDs to which the recipient with the given ID is subscribed
public
static _getAssociatedListsOfRecipient(int $recipientId[, bool $onlyActiveLists = true ]) : array<string|int, mixed>
On failure, or if the ID is invalid or empty, the empty array is returned.
Parameters
- $recipientId : int
-
The recipient ID
- $onlyActiveLists : bool = true
-
Return all lists if false, all lists otherwise. Defaults to true
Tags
Return values
array<string|int, mixed> —The array of subscribed List IDs on success, the empty array otherwise
_getHTML()
public
_getHTML([mixed $onlyId = false ]) : mixed
Parameters
- $onlyId : mixed = false
_getRecipientTitleMenu()
public
_getRecipientTitleMenu([mixed $selected = 0 ][, mixed $attrs = '' ]) : mixed
Parameters
- $selected : mixed = 0
- $attrs : mixed = ''
_getRecipientTitles()
public
_getRecipientTitles() : mixed
_getSettings()
This is a workaround for PHP 7 compatability.
public
_getSettings() : mixed
As the method _getSettings was used in mixed scope.
Tags
_initRecipientTitles()
public
_initRecipientTitles() : mixed
_isUniqueRecipientEmail()
public
_isUniqueRecipientEmail(mixed $email, mixed $recipientId[, mixed $copy = false ]) : mixed
Parameters
- $email : mixed
- $recipientId : mixed
- $copy : mixed = false
_setRecipientLists()
Add the recipient with the given ID to all the lists with their IDs present in the array
public
static _setRecipientLists(int $recipientId, array<string|int, mixed> $arrLists, string $source[, bool $setTime = false ]) : bool
Parameters
- $recipientId : int
-
The recipient ID
- $arrLists : array<string|int, mixed>
-
The array of list IDs to subscribe
- $source : string
-
One of "opt-in", "backend", "api"
- $setTime : bool = false
-
(optional) if set to true, consent is stored as confirmed
Tags
Return values
bool —True on success, false otherwise
_updateRecipient()
public
_updateRecipient(mixed $recipientAttributeStatus, mixed $id, mixed $email, mixed $uri, mixed $sex, mixed $salutation, mixed $title, mixed $lastname, mixed $firstname, mixed $position, mixed $company, mixed $industry_sector, mixed $address, mixed $zip, mixed $city, mixed $country, mixed $phone_office, mixed $phone_private, mixed $phone_mobile, mixed $fax, mixed $notes, mixed $birthday, mixed $status, mixed $arrLists, mixed $language, mixed $source[, mixed $setTime = false ]) : mixed
Parameters
- $recipientAttributeStatus : mixed
- $id : mixed
- $email : mixed
- $uri : mixed
- $sex : mixed
- $salutation : mixed
- $title : mixed
- $lastname : mixed
- $firstname : mixed
- $position : mixed
- $company : mixed
- $industry_sector : mixed
- $address : mixed
- $zip : mixed
- $city : mixed
- $country : mixed
- $phone_office : mixed
- $phone_private : mixed
- $phone_mobile : mixed
- $fax : mixed
- $notes : mixed
- $birthday : mixed
- $status : mixed
- $arrLists : mixed
- $language : mixed
- $source : mixed
- $setTime : mixed = false
_validateRecipientAttributes()
public
_validateRecipientAttributes(mixed $recipientAttributeStatus, mixed $recipient_website, mixed $recipient_sex, mixed $recipient_salutation, mixed $recipient_title, mixed $recipient_lastname, mixed $recipient_firstname, mixed $recipient_position, mixed $recipient_company, mixed $recipient_industry, mixed $recipient_address, mixed $recipient_zip, mixed $recipient_city, mixed $recipient_country, mixed $recipient_phone, mixed $recipient_private, mixed $recipient_mobile, mixed $recipient_fax, mixed $recipient_birthday) : mixed
Parameters
- $recipientAttributeStatus : mixed
- $recipient_website : mixed
- $recipient_sex : mixed
- $recipient_salutation : mixed
- $recipient_title : mixed
- $recipient_lastname : mixed
- $recipient_firstname : mixed
- $recipient_position : mixed
- $recipient_company : mixed
- $recipient_industry : mixed
- $recipient_address : mixed
- $recipient_zip : mixed
- $recipient_city : mixed
- $recipient_country : mixed
- $recipient_phone : mixed
- $recipient_private : mixed
- $recipient_mobile : mixed
- $recipient_fax : mixed
- $recipient_birthday : mixed
autoCleanRegisters()
Auto clean a registers
public
autoCleanRegisters() : mixed
getListIdByName()
Returns the ID of the list specified by its name
public
static getListIdByName(string $list_name) : int
Used for importing/setting up User-List relations
Parameters
- $list_name : string
-
The List name
Return values
int —The matching list ID if found, null otherwise
getListNameById()
Get newsletter list name by given id
public
getListNameById(int $listId) : mixed
Parameters
- $listId : int
-
List id
Return values
mixed —string or null
getLists()
Returns an array of all Newsletter lists
public
static getLists([mixed $excludeHiddenLists = false ][, mixed $extendedInfo = false ]) : array<string|int, mixed>
Parameters
- $excludeHiddenLists : mixed = false
- $extendedInfo : mixed = false
Tags
Return values
array<string|int, mixed> —The array of Newsletter lists
GetProfileURL()
Return link to the profile of a user
public
GetProfileURL(mixed $code, mixed $email[, mixed $type = self::USER_TYPE_NEWSLETTER ][, mixed $htmlTag = true ]) : mixed
Parameters
- $code : mixed
- $email : mixed
- $type : mixed = self::USER_TYPE_NEWSLETTER
- $htmlTag : mixed = true
getRecipientLocaleIdByRecipientId()
Returns the Language ID for a newsletter recipient
public
getRecipientLocaleIdByRecipientId(int $id, string $type) : int
If the recipients's preferred language can not be found, the default language ID is returned.
Parameters
- $id : int
-
id of the recipient or the linked access/crm user
- $type : string
-
User type (see constants)
Return values
int —Language ID
getSettings()
This is a workaround for PHP 7 compatability.
public
static getSettings() : mixed
As the method _getSettings was used in mixed scope.
Tags
GetUnsubscribeURL()
Get the URL to the page to unsubscribe
public
GetUnsubscribeURL(mixed $code, mixed $email[, mixed $type = self::USER_TYPE_NEWSLETTER ][, mixed $htmlTag = true ]) : mixed
Parameters
- $code : mixed
- $email : mixed
- $type : mixed = self::USER_TYPE_NEWSLETTER
- $htmlTag : mixed = true
getUsersPreferredLanguageId()
Returns the Language ID for a newsletter user
public
static getUsersPreferredLanguageId(string $email, string $type) : int
If the user's preferred language can not be found, the default language ID is returned. For crm email addresses this will be the system default language by now
Parameters
- $email : string
-
E-mail address of the user
- $type : string
-
User type (see constants)
Return values
int —Language ID
parseConsentView()
Parses the consent icons
public
static parseConsentView(string $source, string $consent) : string
Parameters
- $source : string
-
Either "backend", "api", "opt-in", "undefined"
- $consent : string
-
Date parseable by DateTime or empty string
Return values
string —HTML content
sendConsentConfirmationMail()
Send a consent confirmation mail to users based on mailing list
public
sendConsentConfirmationMail(array<string|int, mixed> $categoryIds[, string $email = '' ]) : bool
Parameters
- $categoryIds : array<string|int, mixed>
-
Category to send mail for
- $email : string = ''
-
(optional) Only sends the mail to this user
Return values
bool —False if something went wrong, true otherwise
updateRecipientConsent()
Updates recipient consent status in the newsletter_user table.
public
static updateRecipientConsent(string $email, string $source[, bool $setTime = false ]) : bool
This method updates the source and consent fields in the newsletter_user table for a given email address if the current source is different from the provided source and the consent field is NULL. Optionally, it sets the current date and time as the consent value if $setTime is set to true.
Parameters
- $email : string
-
The recipient's email address.
- $source : string
-
The new source of the recipient's consent.
- $setTime : bool = false
-
If true, sets the consent field to the current date and time. Default is false.
Return values
bool —Returns true if the update was successful, otherwise false.
_deleteRecipient()
Drop recipient from database
protected
_deleteRecipient(int $id, string $type) : bool
If $type
is set to static::USER_TYPE_ACCESS, then only the list
associations as well as campaign sending stats associated to that
recipient are dropped. The user itself is not dropped.
Parameters
- $id : int
-
ID of recipient to remove.
- $type : string
-
Either one of static::USER_TYPE_NEWSLETTER or static::USER_TYPE_ACCESS
Return values
bool —true
on success, otherwise false
. false
is also
returned in case recipient is invalid.
_getGroups()
Return the access user groups
protected
_getGroups([string $orderBy = "`group_name`" ]) : array<string|int, mixed>
Parameters
- $orderBy : string = "`group_name`"
Tags
Return values
array<string|int, mixed>getCountryMenu()
protected
getCountryMenu([mixed $selectedCountry = 0 ][, mixed $mantatory = false ]) : mixed
Parameters
- $selectedCountry : mixed = 0
- $mantatory : mixed = false
getListRecipientCount()
Returns the total number of recipients for a given recipient list.
protected
static getListRecipientCount(int $id[, int $consent = self::RECIPIENT_CONSENT_IGNORE ]) : int
This method counts unique email addresses from both newsletter and access users linked to the specified recipient list. The count can be filtered based on consent status:
RECIPIENT_CONSENT_IGNORE
: Include all with consent or non-opt-in sources.RECIPIENT_CONSENT_PENDING
: Only users from non-opt-in sources without consent.RECIPIENT_CONSENT_GIVEN
: Only users who have explicitly given consent.
Parameters
- $id : int
-
ID of the recipient list to query recipients for
- $consent : int = self::RECIPIENT_CONSENT_IGNORE
-
Consent filter constant (one of the RECIPIENT_CONSENT_* values)
Tags
Return values
int —Number of matching recipients
getRecipientListAssociation()
Get the list associations for all recipients.
protected
getRecipientListAssociation() : array<string|int, mixed>
This method does return all recipients and their list associations as they are found in the database. This means that also inactive and non-confirmed recipients are returned. Further it will return all list associations, irrespective of the recipients consent state.
Return values
array<string|int, mixed> —The returned array will have the following structure:
[
'newsletter_user' => [
<recipient_id> => [
<list_id>,
...
],
...
],
'access_user' => [
<recipient_id> => [
<list_id>,
...
],
...
]
]
Note that the recipients are grouped by source type. newsletter_user
refers
to recipients managed directly by the Newsletter component. access_users
are recipients managed by the Access component.
getSetting()
Return a setting from the settings table
protected
getSetting(string $name) : string|bool
Parameters
- $name : string
Tags
Return values
string|boolgetUserDateTime()
Get a user dateTime in H:i:s d.m.Y format from db data
protected
static getUserDateTime(string $userDateTime) : string
Parameters
- $userDateTime : string
-
DateTime from a db
Return values
string —Return a formatted dateTime as string
prepareForRegExp()
protected
static prepareForRegExp(mixed $Text) : mixed
Parameters
- $Text : mixed
prepareNewsletterLinksForSend()
protected
static prepareNewsletterLinksForSend(mixed $MailId, mixed $MailHtmlContent, mixed $UserId, mixed $recipientType[, mixed $langId = null ]) : mixed
Parameters
- $MailId : mixed
- $MailHtmlContent : mixed
- $UserId : mixed
- $recipientType : mixed
- $langId : mixed = null