MessengerManager extends AppModel uses Container
Messenger manager.
Table of Contents
Properties
| $default_tags | An array of key/value pairs to be used as default tags for message templates |
Methods
| __construct() | Initialize MessengerManager |
| add() | Adds the messenger to the system, executing the Messenger::install() method |
| buildMessage() | Parses message text using the given data ($tags) |
| delete() | Permanently and completely removes the messenger from the database, along with all messenger records. Executes the Messenger::uninstall() method |
| get() | Fetches a single installed messenger including meta data |
| getAll() | Lists all installed messengers |
| getAvailable() | Lists all available messengers (those that exist on the file system) |
| getByDir() | Fetches a messenger for a given company, or all messengers installed in the system for the given messenger dir |
| getMeta() | Retrieves a list of messenger meta data for a given messenger ID |
| initMessenger() | Initializes the messenger if it has been installed and returns its instance |
| isInstalled() | Checks whether the given messenger is installed for the specified company |
| send() | Send a message for the given action |
| setMeta() | Updates the meta data for the given messenger, removing all existing data and replacing it with the given data |
| upgrade() | Runs the messenger's upgrade method to upgrade the messenger to match that of the messenger's file version. |
| getFromContainer() | Fetch an item from the container |
| formatRawMeta() | Formats an array of raw meta stdClass objects into a stdClass object whose public member variables represent meta keys and whose values are automatically decrypted and unserialized as necessary. |
| getMessengerInfo() | Fetch information about the given messenger object |
| loadMessenger() | Instantiates the given messenger and returns its instance |
| setFilters() | Sets filters on the parser |
| setVersion() | Updates all installed messengers with the version given |
Methods
__construct()
Initialize MessengerManager
public
__construct() : mixed
add()
Adds the messenger to the system, executing the Messenger::install() method
public
add(array<string|int, mixed> $vars) : int
Parameters
- $vars : array<string|int, mixed>
-
An array of messenger data including:
- company_id The company ID
- dir The messenger directory name
Return values
int —The ID of the messenger installed, void on error
buildMessage()
Parses message text using the given data ($tags)
public
buildMessage(string $text, int $company_id[, array<string|int, mixed> $tags = null ]) : string
Parameters
- $text : string
-
The initial text for a message to be parsed
- $company_id : int
-
The company ID to send this message under
- $tags : array<string|int, mixed> = null
-
An array of replacement tags containing the key/value pairs for the replacements where the key is the tag to replace and the value is the value to replace it with
Return values
string —The parsed message template
delete()
Permanently and completely removes the messenger from the database, along with all messenger records. Executes the Messenger::uninstall() method
public
delete(int $messenger_id) : mixed
Parameters
- $messenger_id : int
-
The ID of the messenger to permanently and completely remove
get()
Fetches a single installed messenger including meta data
public
get(int $messenger_id) : mixed
Parameters
- $messenger_id : int
-
The ID of the messenger to fetch
Return values
mixed —A stdClass object representing the installed messenger, false if no such messenger exists
getAll()
Lists all installed messengers
public
getAll(int $company_id[, string $sort_by = 'name' ][, string $order = 'asc' ]) : array<string|int, mixed>
Parameters
- $company_id : int
-
The company ID
- $sort_by : string = 'name'
-
The field to sort by
- $order : string = 'asc'
-
The direction to order results
Return values
array<string|int, mixed> —An array of stdClass objects representing installed messengers
getAvailable()
Lists all available messengers (those that exist on the file system)
public
getAvailable([int $company_id = null ]) : array<string|int, mixed>
Parameters
- $company_id : int = null
-
The ID of the company to get available messengers for
Return values
array<string|int, mixed> —An array of stdClass objects representing available messengers
getByDir()
Fetches a messenger for a given company, or all messengers installed in the system for the given messenger dir
public
getByDir(string $dir[, int $company_id = null ]) : array<string|int, mixed>
Parameters
- $dir : string
-
The dir name (in file_case)
- $company_id : int = null
-
The ID of the company to fetch messengers for (optional, default null for all)
Return values
array<string|int, mixed> —An array of stdClass objects, each representing an installed messenger record
getMeta()
Retrieves a list of messenger meta data for a given messenger ID
public
getMeta(int $messenger_id[, string $key = null ]) : stdClass
Parameters
- $messenger_id : int
-
The messenger ID
- $key : string = null
-
The messenger meta key representing a specific meta value (optional)
Return values
stdClass —An object representing all messenger meta info
initMessenger()
Initializes the messenger if it has been installed and returns its instance
public
initMessenger(int $messenger_id[, int $company_id = null ]) : Messenger
Parameters
- $messenger_id : int
-
The ID of the messenger to initialize
- $company_id : int = null
-
If set will check to ensure the messenger belongs to the given company_id
Return values
Messenger —An object of type Messenger if the requested messenger has been installed and exists, false otherwise
isInstalled()
Checks whether the given messenger is installed for the specified company
public
isInstalled(string $dir[, string $company_id = null ]) : bool
Parameters
- $dir : string
-
The messenger directory name (in file_case)
- $company_id : string = null
-
The ID of the company to fetch for (null checks if the messenger is installed across any company)
Return values
bool —True if the messenger is installed, false otherwise
send()
Send a message for the given action
public
send(string $action, array<string|int, mixed> $tags, array<string|int, mixed> $user_ids[, string $message_type = null ][, mixed $deliver_to = null ]) : mixed
Parameters
- $action : string
-
The action for which to send a message
- $tags : array<string|int, mixed>
-
A list of tags to include in the message
- $user_ids : array<string|int, mixed>
-
A list of IDs for the users that should receive this message
- $message_type : string = null
-
The type of the message to send, it can be 'sms' or null (null by default)
- $deliver_to : mixed = null
-
The destination of the message (null by default)
setMeta()
Updates the meta data for the given messenger, removing all existing data and replacing it with the given data
public
setMeta(int $messenger_id, array<string|int, mixed> $vars) : mixed
Parameters
- $messenger_id : int
-
The ID of the messenger to update
- $vars : array<string|int, mixed>
-
A numerically indexed array of meta data containing:
- key The key for this meta field
- value The value for this key
- encrypted Whether or not this field should be encrypted (default 0, not encrypted)
upgrade()
Runs the messenger's upgrade method to upgrade the messenger to match that of the messenger's file version.
public
upgrade(int $messenger_id) : mixed
Sets errors in MessengerManager::errors() if any errors are set by the messenger's upgrade method.
Parameters
- $messenger_id : int
-
The ID of the messenger to upgrade
Tags
getFromContainer()
Fetch an item from the container
protected
getFromContainer(string $service) : mixed
Parameters
- $service : string
-
The name of the service from the container to fetch
Return values
mixed —The service if found, otherwise null
formatRawMeta()
Formats an array of raw meta stdClass objects into a stdClass object whose public member variables represent meta keys and whose values are automatically decrypted and unserialized as necessary.
private
formatRawMeta(array<string|int, mixed> $raw_meta) : stdClass
Parameters
- $raw_meta : array<string|int, mixed>
-
An array of stdClass objects representing meta data
Return values
stdClass —An object containing the formatted meta data
getMessengerInfo()
Fetch information about the given messenger object
private
getMessengerInfo(Messenger $messenger, int $company_id) : array<string|int, mixed>
Parameters
- $messenger : Messenger
-
The messenger object to fetch info on
- $company_id : int
-
The ID of the company to fetch the messenger info for
Return values
array<string|int, mixed> —key=>value pairs of messenger info
loadMessenger()
Instantiates the given messenger and returns its instance
private
loadMessenger(string $dir) : Messenger
Parameters
- $dir : string
-
The name of the directory name in file_case to load
Return values
Messenger —An instance of the messenger specified
setFilters()
Sets filters on the parser
private
setFilters(object $parser, int $company_id) : mixed
Parameters
- $parser : object
-
The parser to set filters on
- $company_id : int
-
The company ID to set filters from
setVersion()
Updates all installed messengers with the version given
private
setVersion(string $dir, string $version) : mixed
Parameters
- $dir : string
-
The dir name of the messenger to update
- $version : string
-
The version number to set for each module instance