PackageGroups extends AppModel
Package Group management
Table of Contents
Methods
| __construct() | Initialize PackageGroups |
| add() | Adds a package group for the given company |
| delete() | Permanently removes a package group from the system. |
| edit() | Updates a package group |
| get() | Returns a package group |
| getAll() | Fetches all package groups for a given company |
| getList() | Fetches a list of all package groups for a given company |
| getListCount() | Return the total number of package groups returned from PackageGroups::getList(), useful in constructing pagination for the getList() method. |
| getTypeCount() | Retrieves the number of package groups of a given type |
| getTypes() | Returns a list of supported package group types |
| validateGroupParents() | Checks to ensure that every group parent consists of valid data |
| validateType() | Validates that the given type is a valid package group type |
| appendGroupNamesDescriptions() | Updates the given package group to set names and descriptions |
| format() | Formats the given package group |
| getPackageGroupDescriptions() | Fetches all descriptions created for the given package group |
| getPackageGroupNames() | Fetches all names created for the given package group |
| getPackageGroups() | Partially constructs the query required by both PackageGroups::getList() and PackageGroups::getListCount() |
| getRules() | Returns the rules for adding/editing package groups |
| getSelectFieldList() | Gets a list a fields to fetch for package groups |
| setDescriptions() | Sets the multilingual package group descriptions |
| setNames() | Sets the multilingual package group names |
Methods
__construct()
Initialize PackageGroups
public
__construct() : mixed
add()
Adds a package group for the given company
public
add(array<string|int, mixed> $vars) : int
Parameters
- $vars : array<string|int, mixed>
-
An array of package group info including:
- company_id The ID for the company under which to add the package group
- names A list of names for the package group in different languages, each including:
- lang The language in ISO 636-1 2-char + "_" + ISO 3166-1 2-char (e.g. en_us)
- name The name in the specified language
- type The package group type, ('standard', or 'addon', optional, default 'standard')
- descriptions A list of descriptions for this package group in different languages (optional)
- lang The language in ISO 636-1 2-char + "_" + ISO 3166-1 2-char (e.g. en_us)
- description The description in the specified language (optional, default null)
- parents If type is 'addon', an array of 'standard' package groups this group belongs to
- hidden Whether or not to hide this package group in the interface
- 1 = true, 0 = false (optional, default 0)
- allow_upgrades Whether or not packages within this group can be changed:
- 1 = true, 0 = false (optional, default 1)
Return values
int —The package group ID, void on error
delete()
Permanently removes a package group from the system.
public
delete(int $package_group_id) : mixed
Parameters
- $package_group_id : int
-
The package group ID to delete
edit()
Updates a package group
public
edit(int $package_group_id, array<string|int, mixed> $vars) : mixed
Parameters
- $package_group_id : int
-
The package group ID to update
- $vars : array<string|int, mixed>
-
An array of package group info including:
- company_id The ID for the company to which this package group belongs
- names A list of names for the package group in different languages
- lang The language in ISO 636-1 2-char + "_" + ISO 3166-1 2-char (e.g. en_us)
- name The name in the specified language
- type The package group type, 'standard', or 'addon' (optional, default standard)
- descriptions A list of descriptions for this package group in different languages (optional)
- lang The language in ISO 636-1 2-char + "_" + ISO 3166-1 2-char (e.g. en_us)
- description The description in the specified language (optional, default null)
- parents If type is 'addon', a numerically indexed array of 'standard' package groups this group belongs to
- hidden Whether or not to hide this package group in the interface
- 1 = true, 0 = false (optional, default 0)
- allow_upgrades Whether or not packages within this group can be changed
- 1 = true, 0 = false (optional, default 1)
get()
Returns a package group
public
get(int $package_group_id) : mixed
Parameters
- $package_group_id : int
-
The package group ID
Return values
mixed —An stdClass object representing the package group, or false if the package group does not exist
getAll()
Fetches all package groups for a given company
public
getAll(int $company_id[, string $type = null ][, array<string|int, mixed> $order_by = ['name' => 'asc'] ]) : array<string|int, mixed>
Parameters
- $company_id : int
-
The company ID
- $type : string = null
-
The type of package group to get ('standard' or 'addon', optional, default both)
- $order_by : array<string|int, mixed> = ['name' => 'asc']
-
The sort and order conditions (e.g. array('sort_field'=>"ASC"), optional)
Return values
array<string|int, mixed> —An array of stdClass objects representing each package group
getList()
Fetches a list of all package groups for a given company
public
getList(int $company_id[, int $page = 1 ][, string $type = null ][, array<string|int, mixed> $order_by = ['name' => 'asc'] ][, array<string|int, mixed> $filters = [] ]) : array<string|int, mixed>
Parameters
- $company_id : int
-
The company ID to fetch package groups for
- $page : int = 1
-
The page to return results for
- $type : string = null
-
The type of package group to get ("standard" or "addon", null for both)
- $order_by : array<string|int, mixed> = ['name' => 'asc']
-
The sort and order conditions (e.g. array('sort_field'=>"ASC"), optional)
- $filters : array<string|int, mixed> = []
-
A list of package groups filters including:
- hidden Whether or nor to include the hidden package groups
Return values
array<string|int, mixed> —An array of objects, each representing a package group
getListCount()
Return the total number of package groups returned from PackageGroups::getList(), useful in constructing pagination for the getList() method.
public
getListCount(int $company_id[, string $type = null ][, array<string|int, mixed> $filters = [] ]) : int
Parameters
- $company_id : int
-
The company ID to fetch package groups for
- $type : string = null
-
The type of package group to get ("standard" or "addon", null for both)
- $filters : array<string|int, mixed> = []
-
A list of package groups filters including:
- hidden Whether or nor to include the hidden package groups
Tags
Return values
int —The total number of package groups
getTypeCount()
Retrieves the number of package groups of a given type
public
getTypeCount(int $company_id[, string $type = 'standard' ][, array<string|int, mixed> $filters = [] ]) : int
Parameters
- $company_id : int
-
The ID of the company whose package groups to count
- $type : string = 'standard'
-
The type of package groups to count ("standard" or "addon", default "standard")
- $filters : array<string|int, mixed> = []
-
A list of package groups filters including:
- hidden Whether or nor to include the hidden package groups
Return values
int —The number of package groups of the given type
getTypes()
Returns a list of supported package group types
public
getTypes() : array<string|int, mixed>
Return values
array<string|int, mixed> —A list of package group types and their language name
validateGroupParents()
Checks to ensure that every group parent consists of valid data
public
validateGroupParents(array<string|int, mixed> $parents, int $company_id, string $type) : bool
Parameters
- $parents : array<string|int, mixed>
-
A numerically-indexed array of parent group IDs
- $company_id : int
-
The company ID to which this group belongs
- $type : string
-
The type of group
Return values
bool —True if every group parent consists of valid data, false otherwise
validateType()
Validates that the given type is a valid package group type
public
validateType(string $type) : bool
Parameters
- $type : string
-
The package group type
Return values
bool —True if the package group type is valid, false otherwise
appendGroupNamesDescriptions()
Updates the given package group to set names and descriptions
private
appendGroupNamesDescriptions(stdClass $package_group) : stdClass
Parameters
- $package_group : stdClass
-
The package_group to update, containing at minimum:
- id The package group ID
Return values
stdClass —The updated package group
format()
Formats the given package group
private
format(stdClass $group) : stdClass
Parameters
- $group : stdClass
-
An stdClass object representing a single package group
Return values
stdClass —The given package group with formatted attributes
getPackageGroupDescriptions()
Fetches all descriptions created for the given package group
private
getPackageGroupDescriptions(int $package_group_id) : array<string|int, mixed>
Parameters
- $package_group_id : int
-
The package group ID to fetch descriptions for
Return values
array<string|int, mixed> —An array of stdClass objects representing descriptions
getPackageGroupNames()
Fetches all names created for the given package group
private
getPackageGroupNames(int $package_group_id) : array<string|int, mixed>
Parameters
- $package_group_id : int
-
The package group ID to fetch names for
Return values
array<string|int, mixed> —An array of stdClass objects representing names
getPackageGroups()
Partially constructs the query required by both PackageGroups::getList() and PackageGroups::getListCount()
private
getPackageGroups(int $company_id[, string $type = null ][, array<string|int, mixed> $filters = [] ]) : Record
Parameters
- $company_id : int
-
The company ID to fetch package groups for
- $type : string = null
-
The type of package group to get ("standard" or "addon", null for both)
- $filters : array<string|int, mixed> = []
-
A list of package groups filters including:
- hidden Whether or nor to include the hidden package groups
Return values
Record —The partially constructed query Record object
getRules()
Returns the rules for adding/editing package groups
private
getRules(array<string|int, mixed> $vars[, bool $edit = false ]) : array<string|int, mixed>
Parameters
- $vars : array<string|int, mixed>
-
Key/value pairs of data to replace in language
- $edit : bool = false
-
True to fetch the edit rules, or false for the add rules (optional, default false)
Return values
array<string|int, mixed> —The package group rules
getSelectFieldList()
Gets a list a fields to fetch for package groups
private
getSelectFieldList() : array<string|int, mixed>
Return values
array<string|int, mixed> —A list a fields to fetch for package groups
setDescriptions()
Sets the multilingual package group descriptions
private
setDescriptions(int $package_group_id, array<string|int, mixed> $descriptions) : mixed
Parameters
- $package_group_id : int
-
The ID of the package group to set the descriptions for
- $descriptions : array<string|int, mixed>
-
An array of descriptions including:
- lang The language code (e.g. 'en_us')
- description The description in the specified language (optional, default null)
setNames()
Sets the multilingual package group names
private
setNames(int $package_group_id, array<string|int, mixed> $names) : mixed
Parameters
- $package_group_id : int
-
The ID of the package group to set the names for
- $names : array<string|int, mixed>
-
An array of names including:
- lang The language code (e.g. 'en_us')
- name The name in the specified language