Companies extends AppModel
Company management
Table of Contents
Methods
| __construct() | Initialize Companies |
| add() | Add a company |
| delete() | Delete an existing company. Only companies no longer in use may be removed. |
| edit() | Edit an existing company |
| generateKeyPair() | Generates a new public/private key pair for the company and stores it in the database. |
| get() | Fetches a company with the given ID |
| getAll() | Fetches all companies |
| getAllAvailable() | Fetches all companies available to the given staff ID |
| getByHostname() | Retrieves the company configured for the given hostname. Looks for hostname and www.hostname |
| getList() | Fetches a list of all companies |
| getListCount() | Return the total number of client groups returned from Companies::getList(), useful in constructing pagination for the getList() method. |
| getSetting() | Fetch a specific setting that may apply to this company. Settings are inherited in the order of company_settings -> settings where "->" represents the left item inheriting (and overwriting in the case of duplicates) values found in the right item. |
| getSettings() | Fetch all settings that may apply to this company. Settings are inherited in the order of company_settings -> settings where "->" represents the left item inheriting (and overwriting in the case of duplicates) values found in the right item. |
| getViewDirs() | Fetches data about each installed view directory |
| setSetting() | Sets a company settings |
| setSettings() | Sets a group of company settings |
| unsetSetting() | Unsets a setting from the company settings. CAUTION: This method will physically remove the setting from the system, and could have dire consequences. |
| validateAddAllowed() | Verifies that the company can be added |
| validateCustomization() | Validates Invoice customization settings |
| validateHostnameUnique() | Checks whether the given hostname is unique or not |
| getCompanies() | Partially constructs the query required by both Companies::getList() and Companies::getListCount() |
| getRules() | Returns the rule set for adding/editing companies |
Methods
__construct()
Initialize Companies
public
__construct() : mixed
add()
Add a company
public
add(array<string|int, mixed> $vars) : int
Parameters
- $vars : array<string|int, mixed>
-
An array of company info including:
- company_id The ID of the company whose settings to import from
- name The name of the company
- hostname The hostname of the company
- address The address of the company (whole postal address)
- phone The phone number of the company
- fax The fax number of the company
Return values
int —The company ID added, void on error
delete()
Delete an existing company. Only companies no longer in use may be removed.
public
delete(int $company_id) : mixed
Parameters
- $company_id : int
-
The company ID to remove from the system
edit()
Edit an existing company
public
edit(int $company_id, array<string|int, mixed> $vars) : mixed
Parameters
- $company_id : int
-
The ID of the company to update
- $vars : array<string|int, mixed>
-
An array of company info including:
- name The name of the company
- hostname The hostname of the company
- address The address of the company (whole postal address)
- phone The phone number of the company
- fax The fax number of the company
generateKeyPair()
Generates a new public/private key pair for the company and stores it in the database.
public
generateKeyPair(int $company_id, int $bits[, string $passphrase = null ]) : mixed
Will not overwrite any existing key pair for the same company.
Parameters
- $company_id : int
-
The ID of the company to generate the key pair for
- $bits : int
-
The number of bits (i.e. 1024) for the key length
- $passphrase : string = null
-
The (optional) passphrase to use to encrypt the private key with. Only set if you want super high security (and don't even trust Blesta to decrypt things by itself)
Return values
mixed —An array containing both parts of the key pair on success, false if the key is already set for this company
get()
Fetches a company with the given ID
public
get(int $company_id) : mixed
Parameters
- $company_id : int
-
The ID of the company to fetch
Return values
mixed —A stdClass object representing the company, false if no such company exists
getAll()
Fetches all companies
public
getAll() : mixed
Return values
mixed —An array of stdClass objects representing each company, or false if none exist
getAllAvailable()
Fetches all companies available to the given staff ID
public
getAllAvailable(int $staff_id) : array<string|int, mixed>
Parameters
- $staff_id : int
-
The ID of the staff member
Return values
array<string|int, mixed> —An array of stdClass objects each representing a company
getByHostname()
Retrieves the company configured for the given hostname. Looks for hostname and www.hostname
public
getByHostname(string $hostname) : stdClass
Parameters
- $hostname : string
-
The hostname to fetch on (also looks at www.hostname)
Return values
stdClass —A stdClass object representing the company if it exists, false otherwise
getList()
Fetches a list of all companies
public
getList([int $page = 1 ][, string $order_by = ['id' => 'ASC'] ]) : mixed
Parameters
- $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 or false if no results.
getListCount()
Return the total number of client groups returned from Companies::getList(), useful in constructing pagination for the getList() method.
public
getListCount() : int
Tags
Return values
int —The total number of clients
getSetting()
Fetch a specific setting that may apply to this company. Settings are inherited in the order of company_settings -> settings where "->" represents the left item inheriting (and overwriting in the case of duplicates) values found in the right item.
public
getSetting(int $company_id, string $key) : mixed
Parameters
- $company_id : int
-
The company ID to retrieve a setting for
- $key : string
-
The key name of the setting to fetch
Return values
mixed —A stdObject containg the key and value, false if no such key exists
getSettings()
Fetch all settings that may apply to this company. Settings are inherited in the order of 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 $company_id[, bool $ignore_inheritence = false ]) : mixed
Parameters
- $company_id : int
-
The company ID to retrieve settings for
- $ignore_inheritence : bool = false
-
True to only retrieve company settings, false to get all inherited settings (default false)
Return values
mixed —An array of objects containg key/values for the settings, false if no records found
getViewDirs()
Fetches data about each installed view directory
public
getViewDirs([string $type = 'client' ]) : array<string|int, mixed>
Parameters
- $type : string = 'client'
-
The type of view directory to scan
Return values
array<string|int, mixed> —An array of view dirs
setSetting()
Sets a company settings
public
setSetting(int $company_id, string $key, string $value[, mixed $encrypted = null ][, int $inherit = null ]) : mixed
Parameters
- $company_id : int
-
The company ID
- $key : string
-
The setting key (i.e. name)
- $value : string
-
The value to set for this setting
- $encrypted : mixed = null
-
True to encrypt $value, false to store unencrypted, null to encrypt if currently set to encrypt
- $inherit : int = null
-
Whether or not the setting should be inheritable
setSettings()
Sets a group of company settings
public
setSettings(int $company_id, array<string|int, mixed> $settings[, array<string|int, mixed> $value_keys = null ]) : mixed
Parameters
- $company_id : int
-
The company ID
- $settings : array<string|int, mixed>
-
Settings to set as key/value pairs
- $value_keys : array<string|int, mixed> = null
-
An array of key values to accept as valid fields
unsetSetting()
Unsets a setting from the company settings. CAUTION: This method will physically remove the setting from the system, and could have dire consequences.
public
unsetSetting(int $company_id, string $key) : mixed
You should never use this method, except when attempting to remove a setting created by Companies::setSettings() or Companies::setSetting() that did not previously exist for this installation.
Parameters
- $company_id : int
-
The ID of the company whose setting to unset
- $key : string
-
The setting to unset
validateAddAllowed()
Verifies that the company can be added
public
validateAddAllowed() : bool
Return values
bool —True if the company can be added, false otherwise
validateCustomization()
Validates Invoice customization settings
public
validateCustomization(array<string|int, mixed> $vars) : mixed
Parameters
- $vars : array<string|int, mixed>
-
An array of key/value pairs of invoice customization settings to validate
validateHostnameUnique()
Checks whether the given hostname is unique or not
public
validateHostnameUnique(string $hostname[, int $company_id = null ]) : bool
Parameters
- $hostname : string
-
The hostname to check
- $company_id : int = null
-
The company ID to exclude from the unique check (ie itself, optional, default null)
Return values
bool —True if the given hostname is unique, false otherwise
getCompanies()
Partially constructs the query required by both Companies::getList() and Companies::getListCount()
private
getCompanies() : Record
Return values
Record —The partially constructed query Record object
getRules()
Returns the rule set for adding/editing companies
private
getRules(array<string|int, mixed> $vars[, bool $edit = false ]) : array<string|int, mixed>
Parameters
- $vars : array<string|int, mixed>
-
A list of vars to be validated
- $edit : bool = false
-
True when editing a company, false otherwise
Tags
Return values
array<string|int, mixed> —Company rules