Actions extends AppModel
Actions
Table of Contents
Properties
| $action_to_location_map | |
| $location_to_action_map | |
| $locations |
Methods
| __construct() | Initialize the Actions model |
| add() | Creates a new action for navigation, widgets, or staff client areas |
| delete() | Deletes actions and associated navigation items for a plugin |
| edit() | Updates an existing action |
| get() | Retrieves an action by ID |
| getAll() | Retrieves all actions matching the specified filters |
| getByUrl() | Retrieves an action by URL and optional location/company filters |
| getList() | Retrieves a paginated list of actions matching the specified filters |
| getListCount() | Returns the total number of actions matching the filters |
| getLocationDescriptions() | Retrieves all action locations with detailed descriptions |
| getLocations() | Retrieves all valid action location identifiers with their display names |
| mapOldFields() | Maps deprecated pre-Blesta v5 field names to their current equivalents |
| formatAction() | Formats a single action object |
| formatActions() | Formats multiple action objects |
| getActionRecord() | Constructs a partial database query for searching actions |
| getRules() | Returns validation rules for adding or editing an action |
| translateAction() | Translates language identifiers in an action object |
Properties
$action_to_location_map
private
array<string|int, mixed>
$action_to_location_map
= ['nav_secondary_staff' => 'nav_staff', 'nav_primary_staff' => 'nav_staff', 'nav_secondary_client' => 'nav_client', 'nav_primary_client' => 'nav_client']
Mapping of deprecated pre-v5 action values to their equivalent location values
$location_to_action_map
private
array<string|int, mixed>
$location_to_action_map
= ['nav_staff' => 'nav_primary_staff', 'nav_client' => 'nav_primary_client', 'nav_public' => 'nav_primary_client']
Mapping of location values to their deprecated pre-v5 action equivalents for backward compatibility
$locations
private
array<string|int, mixed>
$locations
= ['nav_staff', 'nav_client', 'nav_public', 'widget_client_home', 'widget_staff_home', 'widget_staff_client', 'widget_staff_billing', 'action_staff_client']
Valid location identifiers for action placement in the interface
Methods
__construct()
Initialize the Actions model
public
__construct() : mixed
Loads required language files for action management.
add()
Creates a new action for navigation, widgets, or staff client areas
public
add(array<string|int, mixed> $vars) : int
Actions define menu items, widget placements, and other UI elements that can be added by plugins throughout the interface.
Parameters
- $vars : array<string|int, mixed>
-
Action data:
location(string) Location identifier (optional, default:nav_staff):nav_client,nav_staff,nav_public,widget_client_home,widget_staff_home,widget_staff_client,widget_staff_billing,action_staff_clienturl(string) Full or partial URL of the actionname(string) Language identifier or display text for the action labeloptions(array) Additional options for the action (optional)plugin_id(int) Plugin ID associated with this action (optional, default: null)company_id(int) Company ID to which this action belongseditable(int) Whether action can be updated via interface:0or1(optional, default: 1)enabled(int) Whether action is active in the interface:0or1(optional, default: 1)
Return values
int —The new action ID on success, void on validation error
delete()
Deletes actions and associated navigation items for a plugin
public
delete(int $plugin_id[, string|null $url = null ]) : void
Warning: This also deletes related navigation_items records.
Parameters
- $plugin_id : int
-
The plugin ID whose actions should be removed
- $url : string|null = null
-
Specific action URL to delete (optional). If null, deletes all actions for the plugin
edit()
Updates an existing action
public
edit(int $action_id, array<string|int, mixed> $vars) : int
Parameters
- $action_id : int
-
The action ID to update
- $vars : array<string|int, mixed>
-
Action data to update:
name(string) Language identifier or display text for the action labelurl(string) Full or partial URL of the actionoptions(array) Additional options for the action (optional)enabled(int) Whether action is active:0or1
Return values
int —The action ID on success, void on validation error
get()
Retrieves an action by ID
public
get(int $action_id[, bool $translate = true ]) : stdClass|false
Parameters
- $action_id : int
-
The action ID to fetch
- $translate : bool = true
-
Whether to translate language definitions (optional, default: true)
Return values
stdClass|false —Action object with properties if found, false otherwise:
id(int) Action IDlocation(string) Location identifierurl(string) Action URLname(string) Action name (translated if $translate is true)options(array|null) Unserialized optionsplugin_id(int|null) Associated plugin IDcompany_id(int) Company IDeditable(int) Whether editable via interfaceenabled(int) Whether enabledplugin_dir(string|null) Plugin directory nameuri(string) Deprecated alias forurlaction(string) Deprecated alias forlocationnav_items(array) Associated navigation items
getAll()
Retrieves all actions matching the specified filters
public
getAll([array<string|int, mixed> $filters = [] ][, bool $translate = true ]) : array<string|int, mixed>
Parameters
- $filters : array<string|int, mixed> = []
-
Filter criteria:
location(string) Location identifier (optional)plugin_id(int) Plugin ID (optional)company_id(int) Company ID (optional)enabled(int) Whether enabled:0or1(optional)editable(int) Whether editable:0or1(optional)
- $translate : bool = true
-
Whether to translate language definitions (optional, default: true)
Tags
Return values
array<string|int, mixed> —Array of stdClass action objects
getByUrl()
Retrieves an action by URL and optional location/company filters
public
getByUrl(string $url[, string|null $location = null ][, int|null $company_id = null ][, bool $translate = true ]) : stdClass|false
Parameters
- $url : string
-
The action URL to search for
- $location : string|null = null
-
Location identifier to filter by (optional):
nav_client,nav_staff,nav_public,widget_client_home,widget_staff_home,widget_staff_client,widget_staff_billing,action_staff_client - $company_id : int|null = null
-
Company ID to filter by (optional, defaults to current company)
- $translate : bool = true
-
Whether to translate language definitions (optional, default: true)
Tags
Return values
stdClass|false —Action object if found, false otherwise
getList()
Retrieves a paginated list of actions matching the specified filters
public
getList([array<string|int, mixed> $filters = [] ][, int $page = 1 ][, array<string|int, mixed> $order_by = ['id' => 'DESC'] ][, bool $translate = true ]) : array<string|int, mixed>
Parameters
- $filters : array<string|int, mixed> = []
-
Filter criteria:
location(string) Location identifier (optional)plugin_id(int) Plugin ID (optional)company_id(int) Company ID (optional)enabled(int) Whether enabled:0or1(optional)editable(int) Whether editable:0or1(optional)
- $page : int = 1
-
Page number to return (optional, default: 1)
- $order_by : array<string|int, mixed> = ['id' => 'DESC']
-
Sort conditions as array (e.g.,
['id' => 'DESC']) (optional, default:['id' => 'DESC']) - $translate : bool = true
-
Whether to translate language definitions (optional, default: true)
Tags
Return values
array<string|int, mixed> —Array of stdClass action objects for the specified page
getListCount()
Returns the total number of actions matching the filters
public
getListCount(array<string|int, mixed> $filters) : int
Used for constructing pagination with getList().
Parameters
- $filters : array<string|int, mixed>
-
Filter criteria (same as getList()):
location(string) Location identifier (optional)plugin_id(int) Plugin ID (optional)company_id(int) Company ID (optional)editable(int) Whether editable:0or1(optional)enabled(int) Whether enabled:0or1(optional)
Tags
Return values
int —Total count of matching actions
getLocationDescriptions()
Retrieves all action locations with detailed descriptions
public
getLocationDescriptions() : array<string|int, mixed>
Provides more detailed explanatory text than getLocations().
Return values
array<string|int, mixed> —Associative array of location identifiers => translated descriptions
getLocations()
Retrieves all valid action location identifiers with their display names
public
getLocations() : array<string|int, mixed>
Return values
array<string|int, mixed> —Associative array of location identifiers => translated display names
mapOldFields()
Maps deprecated pre-Blesta v5 field names to their current equivalents
public
mapOldFields(array<string|int, mixed> $vars) : array<string|int, mixed>
Converts uri to url and action to location for backward compatibility.
Parameters
- $vars : array<string|int, mixed>
-
Input variables that may contain deprecated field names
Return values
array<string|int, mixed> —The input variables with deprecated fields mapped to current names
formatAction()
Formats a single action object
private
formatAction(stdClass $action[, bool $translate = true ]) : stdClass
Performs the following transformations:
- Unserializes the
optionsfield - Translates the action name if requested
- Adds deprecated
urifield (alias forurl) - Adds deprecated
actionfield (alias forlocation) - Loads associated navigation items
Parameters
- $action : stdClass
-
The action object to format
- $translate : bool = true
-
Whether to translate language definitions (optional, default: true)
Return values
stdClass —The formatted action object
formatActions()
Formats multiple action objects
private
formatActions(array<string|int, mixed> $actions[, bool $translate = true ]) : array<string|int, mixed>
Unserializes options, translates names, and adds backward-compatible fields.
Parameters
- $actions : array<string|int, mixed>
-
Array of stdClass action objects to format
- $translate : bool = true
-
Whether to translate language definitions (optional, default: true)
Return values
array<string|int, mixed> —The formatted action objects
getActionRecord()
Constructs a partial database query for searching actions
private
getActionRecord(array<string|int, mixed> $filters) : Record
Parameters
- $filters : array<string|int, mixed>
-
Filter criteria:
id(int) Specific action ID (optional)url(string) Action URL (optional)location(string) Location identifier (optional)plugin_id(int) Plugin ID (optional)company_id(int) Company ID (optional)editable(int) Whether editable:0or1(optional)enabled(int) Whether enabled:0or1(optional)
Return values
Record —Partially constructed Record query object with actions and plugins joined
getRules()
Returns validation rules for adding or editing an action
private
getRules([array<string|int, mixed> $vars = [] ][, bool $edit = false ]) : array<string|int, mixed>
Parameters
- $vars : array<string|int, mixed> = []
-
Input data to validate (used for context in validation rules)
- $edit : bool = false
-
Whether validating for edit operation (optional, default: false). When true, removes validation for immutable fields (location, plugin_id, company_id, editable)
Return values
array<string|int, mixed> —Validation rules array for Input::setRules()
translateAction()
Translates language identifiers in an action object
private
translateAction(stdClass $action) : stdClass
Loads the plugin's language file if needed and translates the action name
from a language identifier (e.g., PluginName.action_name) to the translated text.
Parameters
- $action : stdClass
-
The action object whose name should be translated
Return values
stdClass —The action object with translated name