Staff extends AppModel
Staff management
Table of Contents
Methods
| __construct() | Initialize Staff |
| add() | Add a staff member |
| addNotice() | Adds a staff email notice |
| addNotices() | Adds multiple staff email notices |
| addQuickLink() | Adds a quicklink for a staff member |
| assignGroup() | Assigns the given staff ID to the given staff group ID |
| delete() | Permanently removes the staff member from the system |
| deleteNotice() | Deletes the given staff group notice |
| deleteQuickLink() | Removes a quicklink for a staff member |
| edit() | Updates the given staff member with only the values given in $vars |
| get() | Fetches a staff member and all associated staff settings and staff groups |
| getAll() | Returns a list of all staff members |
| getAllByEmailAction() | Fetches all staff members that can be sent the email corresponding to the given email group action |
| getBillingWidgetsState() | Fetch the current state of the billing (dashboard) widget boxes |
| getByUserId() | Fetches a staff member and all associated staff settings and staff groups |
| getClientsWidgetsState() | Fetch the current state of the clients widget boxes |
| getHomeWidgetsState() | Fetch the current state of the home (dashboard) widget boxes |
| getList() | Fetches a list of all staff members |
| getListCount() | Returns the total number of staff members returned from Staff::getList(), useful in constructing pagination for the getList() method. |
| getNotices() | Fetches all staff group notices |
| getQuickLinks() | Retrieves all quicklinks for a given staff member |
| getSetting() | Fetch a single setting by key name |
| getSettings() | Fetch all settings that may apply to this staff member. Settings are inherited in the order of staff_settings -> company_settings -> settings where "->" represents the left item inheriting (and overwriting in the case of duplicates) values found in the right item. |
| saveBillingWidgetsState() | Saves the current state of the billing (dashboard) widget boxes |
| saveClientsWidgetsState() | Saves the current state of the clients widget boxes |
| saveHomeWidgetsState() | Saves the current state of the home (dashboard) widget boxes |
| sendNotificationEmail() | Sends the notification email matching the given action to all staff members that should receive it. |
| setSetting() | Add a staff setting, if duplicate key update the setting |
| setSettings() | Add multiple staff settings, if duplicate key update the setting |
| unsetSetting() | Delets a staff setting |
| validateNoticeActionExists() | Validates that the given action is available for this staff group |
| validateStatus() | Validates the staff's 'status' field |
| validateUniqueCompanies() | Validates that none of the staff group IDs given belong to the same company |
| deleteStaffNotices() | Deletes the staff notices |
| getNoticeRules() | Fetches the rules for adding/editing a staff notice |
| getRules() | Returns the rule set for adding and editing staff |
| getStaff() | Partially constructs the query required by both Staff::getList() and Staff::getListCount() |
Methods
__construct()
Initialize Staff
public
__construct() : mixed
add()
Add a staff member
public
add(array<string|int, mixed> $vars) : int
Parameters
- $vars : array<string|int, mixed>
-
An array of staff member info including:
- user_id The user ID belonging to this staff member
- first_name The first name of this staff member
- last_name The last name of this staff member
- email The email address of this staff member
- email_mobile The mobile email address of this staff member (optional)
- number_mobile The mobile phone number of this staff member (optional)
- status The status of this staff member 'active', 'inactive' (optional, default active)
- groups An array of staff group IDs this staff member belongs to
Return values
int —The ID of the staff member added, void on error
addNotice()
Adds a staff email notice
public
addNotice(array<string|int, mixed> $vars) : mixed
Parameters
- $vars : array<string|int, mixed>
-
An array of staff notice information including:
- staff_group_id The ID of the staff group this notice will be added to
- staff_id The ID of the staff member
- action The email group action
addNotices()
Adds multiple staff email notices
public
addNotices(mixed $staff_id, mixed $staff_group_id, array<string|int, mixed> $actions) : mixed
Parameters
- $staff_id : mixed
-
The ID of the staff member
- $staff_group_id : mixed
-
The ID of the staff group these notices will be added to
- $actions : array<string|int, mixed>
-
A list of staff notices, each containing:
- action The email group action
addQuickLink()
Adds a quicklink for a staff member
public
addQuickLink(int $staff_id, int $company_id, array<string|int, mixed> $vars) : mixed
Parameters
- $staff_id : int
-
The staff ID of this staff member
- $company_id : int
-
The company ID of this staff member
- $vars : array<string|int, mixed>
-
An array of quicklink info including:
- uri The URI of the link to save
- title The title of this quicklink
- order The sort order of this quicklink (optional, default 0)
assignGroup()
Assigns the given staff ID to the given staff group ID
public
assignGroup(int $staff_id, int $staff_group_id) : mixed
Parameters
- $staff_id : int
-
The ID of the staff member to assign to the given group
- $staff_group_id : int
-
The ID of the staff group to assign to the given staff member
delete()
Permanently removes the staff member from the system
public
delete(int $staff_id) : mixed
since version 4.1.0
Parameters
- $staff_id : int
-
The ID of the staff member to remove from the system
deleteNotice()
Deletes the given staff group notice
public
deleteNotice(int $staff_id, int $staff_group_id[, string $action = null ]) : mixed
Parameters
- $staff_id : int
-
The ID of the staff member
- $staff_group_id : int
-
The ID of the staff group the notice belongs to
- $action : string = null
-
The email group action to remove (optional, default null to delete all notices)
deleteQuickLink()
Removes a quicklink for a staff member
public
deleteQuickLink(int $staff_id, int $company_id, string $uri) : mixed
Parameters
- $staff_id : int
-
The staff ID of this staff member
- $company_id : int
-
The company ID of this staff member
- $uri : string
-
The URI of the link to remove
edit()
Updates the given staff member with only the values given in $vars
public
edit(int $staff_id, array<string|int, mixed> $vars) : mixed
Parameters
- $staff_id : int
-
The ID of the staff member to update
- $vars : array<string|int, mixed>
-
An array of staff member info including:
- first_name The first name of this staff member (optional)
- last_name The last name of this staff member (optional)
- email The email address of this staff member (optional)
- email_mobile The mobile email address of this staff member (optional)
- number_mobile The mobile phone number of this staff member (optional)
- status The status of this staff member 'active', 'inactive' (optional, default 'active')
- groups An array of staff group IDs this staff member belongs to (optional)
get()
Fetches a staff member and all associated staff settings and staff groups
public
get(int $staff_id[, int $company_id = null ]) : mixed
Parameters
- $staff_id : int
-
The ID of the staff member
- $company_id : int = null
-
The ID of the company to set staff settings for (optional, if null, no settings will be set)
Tags
Return values
mixed —An array of objects or false if no results.
getAll()
Returns a list of all staff members
public
getAll([int $company_id = null ][, string $status = null ][, int $staff_group_id = null ]) : array<string|int, mixed>
Parameters
- $company_id : int = null
-
The ID of the company from which to fetch staff (optional)
- $status : string = null
-
The status of the staff to fetch ('active' or 'inactive', null for all)
- $staff_group_id : int = null
-
The ID of the client group that the staff must belong to (optional)
Return values
array<string|int, mixed> —A list of stdClass objects each representing a staff member
getAllByEmailAction()
Fetches all staff members that can be sent the email corresponding to the given email group action
public
getAllByEmailAction(string $action, int $company_id[, string $notice_type = 'all' ][, string $status = null ]) : array<string|int, mixed>
Parameters
- $action : string
-
The email group action representing an email type
- $company_id : int
-
The ID of the company whose staff members to fetch from
- $notice_type : string = 'all'
-
The type of email notice to fetch (optional) one of:
- all Any email notice type
- null Notice types that are not set
- bcc BCC notice types
- to To notice types
- $status : string = null
-
The status of the staff member ("active", "inactive", or null for all; optional, default null)
Return values
array<string|int, mixed> —A list of stdClass objects, each representing a staff member
getBillingWidgetsState()
Fetch the current state of the billing (dashboard) widget boxes
public
getBillingWidgetsState(int $staff_id, int $company_id) : array<string|int, mixed>
Parameters
- $staff_id : int
-
The ID of the staff member to fetch the widget box state for
- $company_id : int
-
The ID of the company to fetch the widget box state for (in combination with $staff_id)
Return values
array<string|int, mixed> —An array of widget box state data
getByUserId()
Fetches a staff member and all associated staff settings and staff groups
public
getByUserId(int $user_id[, int $company_id = null ]) : mixed
Parameters
- $user_id : int
-
The ID of the user
- $company_id : int = null
-
The ID of the company to set staff settings for (optional, if null, no settings will be set)
Tags
Return values
mixed —An array of objects or false if no results.
getClientsWidgetsState()
Fetch the current state of the clients widget boxes
public
getClientsWidgetsState(int $staff_id, int $company_id) : array<string|int, mixed>
Parameters
- $staff_id : int
-
The ID of the staff member to fetch the widget box state for
- $company_id : int
-
The ID of the company to fetch the widget box state for (in combination with $staff_id)
Return values
array<string|int, mixed> —An array of widget box state data
getHomeWidgetsState()
Fetch the current state of the home (dashboard) widget boxes
public
getHomeWidgetsState(int $staff_id, int $company_id) : array<string|int, mixed>
Parameters
- $staff_id : int
-
The ID of the staff member to fetch the widget box state for
- $company_id : int
-
The ID of the company to fetch the widget box state for (in combination with $staff_id)
Return values
array<string|int, mixed> —An array of widget box state data
getList()
Fetches a list of all staff members
public
getList([int $company_id = null ][, string $status = null ][, int $page = 1 ][, string $order_by = ['id' => 'ASC'] ]) : mixed
Parameters
- $company_id : int = null
-
The company ID to fetch (optional, default null)
- $status : string = null
-
The status of the staff member to retrieve ('active', 'inactive', default null for all)
- $page : int = 1
-
The page to return results for
- $order_by : string = ['id' => 'ASC']
-
The sort and order conditions (e.g. array('sort_field'=>"ASC"), optional)
Return values
mixed —An array of objects when $count is false, an integer when $count is true, or false if no results.
getListCount()
Returns the total number of staff members returned from Staff::getList(), useful in constructing pagination for the getList() method.
public
getListCount([int $company_id = null ][, string $status = null ]) : int
Parameters
- $company_id : int = null
-
The company ID to fetch (optional, default null)
- $status : string = null
-
The status of the staff member to retrieve ('active', 'inactive', default null for all)
Tags
Return values
int —The total number of staff members
getNotices()
Fetches all staff group notices
public
getNotices(int $staff_id[, int $staff_group_id = null ][, bool $group_by_action = true ]) : array<string|int, mixed>
Parameters
- $staff_id : int
-
The ID of the staff member
- $staff_group_id : int = null
-
The ID of the staff group (optional, default null for all)
- $group_by_action : bool = true
-
True to group by the action, false otherwise (optional, default true)
Return values
array<string|int, mixed> —A list of all staff group notices
getQuickLinks()
Retrieves all quicklinks for a given staff member
public
getQuickLinks(int $staff_id, int $company_id) : mixed
Parameters
- $staff_id : int
-
The staff ID of this staff member
- $company_id : int
-
The company ID of this staff member
Return values
mixed —An array of objects representing the quicklinks, or false if none exist
getSetting()
Fetch a single setting by key name
public
getSetting(int $staff_id, string $key[, int $company_id = null ]) : mixed
Parameters
- $staff_id : int
-
The ID of the staff member to fetch the setting for
- $key : string
-
The key name of the setting to fetch
- $company_id : int = null
-
The ID of the company to inherit settings from
Return values
mixed —An stdObject containg the key and value, false if no such key exists
getSettings()
Fetch all settings that may apply to this staff member. Settings are inherited in the order of staff_settings -> company_settings -> settings where "->" represents the left item inheriting (and overwriting in the case of duplicates) values found in the right item.
public
getSettings(int $staff_id, int $company_id) : mixed
Parameters
- $staff_id : int
-
The staff ID to retrieve settings for
- $company_id : int
-
The company ID to retrieve settings for
Return values
mixed —An array of objects containg key/values for the settings, false if no records found
saveBillingWidgetsState()
Saves the current state of the billing (dashboard) widget boxes
public
saveBillingWidgetsState(int $staff_id, int $company_id, array<string|int, mixed> $widgets) : mixed
Parameters
- $staff_id : int
-
The ID of the staff member to save the widget box state for
- $company_id : int
-
The ID of the company to save the widget box state for (in combination with $staff_id)
- $widgets : array<string|int, mixed>
-
An array of widget state information keyed by widget name including:
- open Whether or not the box is open (true/false)
saveClientsWidgetsState()
Saves the current state of the clients widget boxes
public
saveClientsWidgetsState(int $staff_id, int $company_id, array<string|int, mixed> $widgets) : mixed
Parameters
- $staff_id : int
-
The ID of the staff member to save the widget box state for
- $company_id : int
-
The ID of the company to save the widget box state for (in combination with $staff_id)
- $widgets : array<string|int, mixed>
-
An array of widget state information keyed by widget name including:
- open Whether or not the box is open (true/false)
saveHomeWidgetsState()
Saves the current state of the home (dashboard) widget boxes
public
saveHomeWidgetsState(int $staff_id, int $company_id, array<string|int, mixed> $widgets) : mixed
Parameters
- $staff_id : int
-
The ID of the staff member to save the widget box state for
- $company_id : int
-
The ID of the company to save the widget box state for (in combination with $staff_id)
- $widgets : array<string|int, mixed>
-
An array of widget state information keyed by widget name including:
- open Whether or not the box is open (true/false)
sendNotificationEmail()
Sends the notification email matching the given action to all staff members that should receive it.
public
sendNotificationEmail(string $action, int $company_id[, array<string|int, mixed> $tags = null ][, mixed $cc = null ][, mixed $bcc = null ][, array<string|int, mixed> $attachments = null ][, array<string|int, mixed> $options = null ]) : mixed
Sets Input errors on error
Parameters
- $action : string
-
The action that specifies the email group to use
- $company_id : int
-
The company ID to send this email 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 (optional; A 'staff' tag will automatically be set)
- $cc : mixed = null
-
The CC address(es) to send to. A string, or an array of email addresses
- $bcc : mixed = null
-
The BCC address(es) to send to. A string, or an array of email addresses
- $attachments : array<string|int, mixed> = null
-
A multi-dimensional array of attachments containing:
- path The path to the attachment on the file system
- name The name of the attachment (optional, default '')
- encoding The file encoding (optional, default 'base64')
- type The type of attachment (optional, default 'application/octet-stream')
- $options : array<string|int, mixed> = null
-
An array of options including:
- to_client_id The ID of the client the message was sent to
- from_staff_id The ID of the staff member the message was sent from
- from The from address
- from_name The from name
- reply_to The reply to address
setSetting()
Add a staff setting, if duplicate key update the setting
public
setSetting(int $staff_id, string $key, string $value) : mixed
Parameters
- $staff_id : int
-
The ID for the specified staff member
- $key : string
-
The key for this staff setting
- $value : string
-
The value for this staff setting
setSettings()
Add multiple staff settings, if duplicate key update the setting
public
setSettings(int $staff_id, array<string|int, mixed> $vars) : mixed
Parameters
- $staff_id : int
-
The ID for the specified staff member
- $vars : array<string|int, mixed>
-
A single dimensional array of key/value pairs of settings
unsetSetting()
Delets a staff setting
public
unsetSetting(int $staff_id, string $key) : mixed
Parameters
- $staff_id : int
-
The ID for the specified staff member
- $key : string
-
The key for this staff setting
validateNoticeActionExists()
Validates that the given action is available for this staff group
public
validateNoticeActionExists(string $action, int $staff_group_id) : bool
Parameters
- $action : string
-
The email group action
- $staff_group_id : int
-
The ID of the staff group to check
Return values
bool —True if the staff group has the action available, false otherwise
validateStatus()
Validates the staff's 'status' field
public
validateStatus(string $status) : bool
Parameters
- $status : string
-
The status to check
Return values
bool —True if validated, false otherwise
validateUniqueCompanies()
Validates that none of the staff group IDs given belong to the same company
public
validateUniqueCompanies(array<string|int, mixed> $group_ids) : bool
Parameters
- $group_ids : array<string|int, mixed>
-
An array of staff group IDs
Return values
bool —True if none of the staff group IDs belong to the same company, false otherwise
deleteStaffNotices()
Deletes the staff notices
private
deleteStaffNotices(int $staff_id, int $staff_group_id[, string $action = null ]) : mixed
Parameters
- $staff_id : int
-
The ID of the staff member
- $staff_group_id : int
-
The ID of the staff group
- $action : string = null
-
The email group action (optional)
getNoticeRules()
Fetches the rules for adding/editing a staff notice
private
getNoticeRules(array<string|int, mixed> $vars) : array<string|int, mixed>
Parameters
- $vars : array<string|int, mixed>
-
A list of input vars
Return values
array<string|int, mixed> —The staff notice rules
getRules()
Returns the rule set for adding and editing staff
private
getRules(array<string|int, mixed> $vars[, bool $edit = false ]) : array<string|int, mixed>
Parameters
- $vars : array<string|int, mixed>
-
Input vars
- $edit : bool = false
-
Whether the staff is being edited (optional)
Return values
array<string|int, mixed> —The rules
getStaff()
Partially constructs the query required by both Staff::getList() and Staff::getListCount()
private
getStaff([int $company_id = null ][, string $status = null ][, int $staff_group_id = null ]) : Record
Parameters
- $company_id : int = null
-
The ID of the company from which to fetch staff (optional)
- $status : string = null
-
The status of the staff to fetch ('active' or 'inactive', null for all)
- $staff_group_id : int = null
-
The ID of the client group that the staff must belong to (optional)
Return values
Record —The partially constructed query Record object