Blesta Source Documentation

ModuleManager extends AppModel uses Container

Module manager. Handles installing/uninstalling and configuring modules.

Table of Contents

Methods

__construct() Initialize ModuleManager
add() Adds the module to the system, executing the Module::install() method
addGroup() Adds a module group to the system
addRow() Adds a new module row for the given module
delete() Permanently and completely removes the module from the database, along with all module records. Executes the Modules::uninstall() method
deleteGroup() Permanently removes the module group if safe to do so.
deleteRow() Permanently removes a module row and its related meta data if safe to do so.
editGroup() Updates a module group to the system
editRow() Edits a module row
get() Fetches a single installed module including all of its module rows and meta data
getAll() Lists all installed modules
getAvailable() Lists all available modules (those that exist on the file system)
getByClass() Fetches a module for a given company, or all modules installed in the system for the given module class
getGroup() Retrieves a specific module group
getGroups() Retrieves a list of module groups for this given module ID
getInstalled() Fetches all modules installed in the system
getMeta() Retrieves a list of module meta data for a given module ID
getRow() Retrieves a module row, including meta data
getRowMeta() Retrieves a list of module row meta data for a given module row ID
getRows() Retrieves a list of module rows for a given module ID, including meta data
initModule() Initializes the module if it has been installed and returns its instance
isInstalled() Checks whether the given module is installed for the specified company
moduleRpc() Invokes the given method with the given parameters on the give module, returning the result from the module.
setMeta() Updates the meta data for the given module, removing all existing data and replacing it with the given data
translate() Retrieves the translated definition of the given term for the given module class.
upgrade() Runs the module's upgrade method to upgrade the module to match that of the module's file version.
validateAssignedToPackage() Validates that the given module
validateAssignedToService() Validates that the given module row ID, or module ID, is not assigned to any service
validateBelongsToModule() Validates that the given module row ID belongs to the given module ID
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.
getGroupRules() Returns the rule set for adding/editing module groups
getModule() Partially constructs the query required by both ModuleManager::get(), ModuleManager::getByClass() and ModuleManager::getAll()
getModuleInfo() Fetch information about the given module object
loadModule() Instantiates the given module and returns its instance
setGroupAssignment() Sets the group assignment for the given module group and set of rows
setType() Updates all installed modules with the type given
setVersion() Updates all installed modules with the version given
Methods

__construct()

Initialize ModuleManager

public __construct() : mixed

add()

Adds the module to the system, executing the Module::install() method

public add(array<string|int, mixed> $vars) : int
Parameters
$vars : array<string|int, mixed>

An array of module data including:

  • company_id The company ID
  • class The module class name
Return values
int

The ID of the module installed, void on error

addGroup()

Adds a module group to the system

public addGroup(int $module_id, array<string|int, mixed> $vars) : int
Parameters
$module_id : int

The ID of the module to add the group under

$vars : array<string|int, mixed>
Return values
int

The module group ID, void if error

addRow()

Adds a new module row for the given module

public addRow(int $module_id, array<string|int, mixed> $vars) : int
Parameters
$module_id : int

The ID of the module to add a row to

$vars : array<string|int, mixed>

An array of key/value pairs to be sent to the module for conversion into module row meta data

Tags
see
ModuleManager::errors()
Return values
int

The module Row ID, void on error

delete()

Permanently and completely removes the module from the database, along with all module records. Executes the Modules::uninstall() method

public delete(int $module_id) : mixed
Parameters
$module_id : int

The ID of the module to permanently and completely remove

deleteGroup()

Permanently removes the module group if safe to do so.

public deleteGroup(int $module_group_id) : mixed
Parameters
$module_group_id : int

The ID of the module group to remove

Tags
see
ModuleManager::errors()

deleteRow()

Permanently removes a module row and its related meta data if safe to do so.

public deleteRow(int $module_row_id) : mixed
Parameters
$module_row_id : int

The ID of the module row to remove

Tags
see
ModuleManager::errors()

editGroup()

Updates a module group to the system

public editGroup(int $module_group_id, array<string|int, mixed> $vars) : mixed
Parameters
$module_group_id : int

The ID of the module group to update

$vars : array<string|int, mixed>

editRow()

Edits a module row

public editRow(int $module_row_id, array<string|int, mixed> $vars) : int
Parameters
$module_row_id : int

The ID of the module row to update

$vars : array<string|int, mixed>

An array of key/value pairs to be sent to the module for conversion into module row meta data

Tags
see
ModuleManager::errors()
Return values
int

The module Row ID, void on error

get()

Fetches a single installed module including all of its module rows and meta data

public get(int $module_id[, bool $rows = true ][, bool $groups = true ]) : mixed
Parameters
$module_id : int

The ID of the module to fetch

$rows : bool = true

True to fetch all module rows with this entry, false otherwise

$groups : bool = true

True to fetch all module groups with this entry, false otherwise

Return values
mixed

A stdClass object representing the installed module, false if no such module exists

getAll()

Lists all installed modules

public getAll(int $company_id[, string $sort_by = 'name' ][, string $order = 'asc' ][, array<string|int, mixed> $filters = [] ]) : 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

$filters : array<string|int, mixed> = []

A list of parameters to filter by, including:

  • type The type of module to filter on, null to get all types of modules
Return values
array<string|int, mixed>

An array of stdClass objects representing installed modules

getAvailable()

Lists all available modules (those that exist on the file system)

public getAvailable([int $company_id = null ][, string $type = null ]) : array<string|int, mixed>
Parameters
$company_id : int = null

The ID of the company to get available modules for

$type : string = null

A module type on which to filter

Return values
array<string|int, mixed>

An array of stdClass objects representing available modules

getByClass()

Fetches a module for a given company, or all modules installed in the system for the given module class

public getByClass(string $class[, int $company_id = null ]) : array<string|int, mixed>
Parameters
$class : string

The class name (in file_case)

$company_id : int = null

The ID of the company to fetch modules for (optional, default null for all)

Return values
array<string|int, mixed>

An array of stdClass objects, each representing an installed module record

getGroup()

Retrieves a specific module group

public getGroup(int $module_group_id) : stdClass
Parameters
$module_group_id : int

The ID of the module group to fetch

Return values
stdClass

A stdClass objects representing the module group

getGroups()

Retrieves a list of module groups for this given module ID

public getGroups(int $module_id) : array<string|int, mixed>
Parameters
$module_id : int

The ID of the module to fetch groups for

Return values
array<string|int, mixed>

An array of stdClass objects representing module groups

getInstalled()

Fetches all modules installed in the system

public getInstalled([array<string|int, mixed> $filters = [] ]) : array<string|int, mixed>
Parameters
$filters : array<string|int, mixed> = []

A list of parameters to filter by, including:

  • type The type of module to filter on, null to get all types of modules
Return values
array<string|int, mixed>

An array of stdClass objects, each representing an installed module record

getMeta()

Retrieves a list of module meta data for a given module ID

public getMeta(int $module_id[, string $key = null ]) : An
Parameters
$module_id : int

The module ID

$key : string = null

The module meta key representing a specific meta value (optional)

Return values
An

array of stdClass objects reperesenting all module meta info for this module

getRow()

Retrieves a module row, including meta data

public getRow(int $module_row_id) : stdClass
Parameters
$module_row_id : int

The ID of the module row to fetch

Return values
stdClass

A stdClass object representing a module row

getRowMeta()

Retrieves a list of module row meta data for a given module row ID

public getRowMeta(int $module_row_id[, string $key = null ]) : An
Parameters
$module_row_id : int

The module row ID

$key : string = null

The module row key representing a specific meta value (optional)

Return values
An

array of stdClass objects reperesenting all module rows for this module

getRows()

Retrieves a list of module rows for a given module ID, including meta data

public getRows(int $module_id[, int $module_group_id = null ]) : array<string|int, mixed>
Parameters
$module_id : int

The module ID

$module_group_id : int = null

The ID of the module group to filter on (optional)

Return values
array<string|int, mixed>

An array of stdClass objects representing all module rows for this module

initModule()

Initializes the module if it has been installed and returns its instance

public initModule(int $module_id[, int $company_id = null ]) : Module
Parameters
$module_id : int

The ID of the module to initialize

$company_id : int = null

If set will check to ensure the module belongs to the given company_id

Return values
Module

An object of type Module if the requested module has been installed and exists, false otherwise

isInstalled()

Checks whether the given module is installed for the specified company

public isInstalled(string $class[, string $company_id = null ]) : bool
Parameters
$class : string

The module class (in file_case)

$company_id : string = null

The ID of hte company to fetch for (null checks if the module is installed across any company)

Return values
bool

True if the module is installed, false otherwise

moduleRpc()

Invokes the given method with the given parameters on the give module, returning the result from the module.

public moduleRpc(int $module_id, string $method[, array<string|int, mixed> $params = null ][, int $module_row_id = null ]) : mixed
Parameters
$module_id : int

The ID of the module to initialize

$method : string

The name of the method to invoke on the module

$params : array<string|int, mixed> = null

An array of parameters to pass to the method to be invoked

$module_row_id : int = null

The module row ID to initialize with

Tags
see
ModuleManager::errors()
Return values
mixed

The value returned from the module for the requested method

setMeta()

Updates the meta data for the given module, removing all existing data and replacing it with the given data

public setMeta(int $module_id, array<string|int, mixed> $vars) : mixed
Parameters
$module_id : int

The ID of the module 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)

translate()

Retrieves the translated definition of the given term for the given module class.

public translate(string $class, string $term) : string

This assumes the module language file is the $class name

Parameters
$class : string

The class name (in file_case)

$term : string

The language term from the module to translate

Return values
string

The translated term, if found

upgrade()

Runs the module's upgrade method to upgrade the module to match that of the module's file version.

public upgrade(int $module_id) : mixed

Sets errors in ModuleManager::errors() if any errors are set by the module's upgrade method.

Parameters
$module_id : int

The ID of the module to upgrade

Tags
see
ModuleManager::errors()

validateAssignedToPackage()

Validates that the given module

public validateAssignedToPackage(int $module_id[, mixed $status = null ]) : bool
Parameters
$module_id : int

The ID of the module to check

$status : mixed = null
Return values
bool

True if the module_id is not assigned to any packages, false if it is

validateAssignedToService()

Validates that the given module row ID, or module ID, is not assigned to any service

public validateAssignedToService([int $module_row_id = null ][, int $module_id = null ][, mixed $status = null ]) : bool
Parameters
$module_row_id : int = null

The ID of the module row to check

$module_id : int = null

The ID of the module to check

$status : mixed = null
Return values
bool

True if the module row is not assigned to any active service, false if it is

validateBelongsToModule()

Validates that the given module row ID belongs to the given module ID

public validateBelongsToModule(mixed $module_row_id, mixed $module_id) : bool
Parameters
$module_row_id : mixed

The ID of the module row to check

$module_id : mixed

The ID of the module to check against the module row ID

Return values
bool

True if the module row ID belongs to the module or is empty, false otherwise.

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) : mixed
Parameters
$raw_meta : array<string|int, mixed>

An array of stdClass objects representing meta data

getGroupRules()

Returns the rule set for adding/editing module groups

private getGroupRules(array<string|int, mixed> $vars) : array<string|int, mixed>
Parameters
$vars : array<string|int, mixed>

The key/value pairs of vars

Return values
array<string|int, mixed>

ModuleGroup rules

getModule()

Partially constructs the query required by both ModuleManager::get(), ModuleManager::getByClass() and ModuleManager::getAll()

private getModule([array<string|int, mixed> $filters = [] ]) : Record
Parameters
$filters : array<string|int, mixed> = []

A list of package filters including:

  • module_id The module ID
  • type The type of module to filter on, null to get all types of modules
  • class The class name to filter modules on
  • company_id The company ID to filter modules on
Tags
see
ModuleManager::get()
see
ModuleManager::getByClass()
see
ModuleManager::getAll()
Return values
Record

The partially constructed query Record object

getModuleInfo()

Fetch information about the given module object

private getModuleInfo(object $module, int $company_id) : array<string|int, mixed>
Parameters
$module : object

The module object to fetch info on

$company_id : int

The ID of the company to fetch the module info for

Return values
array<string|int, mixed>

key=>value pairs of module info

loadModule()

Instantiates the given module and returns its instance

private loadModule(string $class) : An
Parameters
$class : string

The name of the class in file_case to load

Return values
An

instance of the module specified

setGroupAssignment()

Sets the group assignment for the given module group and set of rows

private setGroupAssignment(int $module_group_id, array<string|int, mixed> $module_rows) : mixed
Parameters
$module_group_id : int

The ID of the module group to record row group assignments on

$module_rows : array<string|int, mixed>

A numerically indexed array of module row ID's to assign to this group

setType()

Updates all installed modules with the type given

private setType(string $class, string $type) : mixed
Parameters
$class : string

The class name of the module to update

$type : string

The module type to set for each module instance

setVersion()

Updates all installed modules with the version given

private setVersion(string $class, string $version) : mixed
Parameters
$class : string

The class name of the module to update

$version : string

The version number to set for each module instance

Tags
subpackage

app.models

copyright

Copyright (c) 2010, Phillips Data, Inc.

license

http://www.blesta.com/license/ The Blesta License Agreement

link

Blesta


        
On this page

Search results