PackageOptionGroups extends AppModel
Package Option Group management
Table of Contents
Methods
| __construct() | Initialize PackageOptionGroups |
| add() | Adds a package option group for the given company |
| delete() | Permanently removes a package option group from the system |
| edit() | Updates a package option group |
| export() | Exports a option group, along with the assigned options and condition sets. |
| get() | Fetches the package option group |
| getAll() | Fetches all package option groups for a given company |
| getAllOptions() | Fetches all package options assigned to this package option group |
| getAllPackageIds() | Fetches the package IDs of all packages assigned to this package option group |
| getList() | Fetches a list of all package option groups for a given company |
| getListCount() | Returns the total number of package option groups returned from PackageOptionGroups::getList(), useful in constructing pagination for the getList() method. |
| import() | Imports a JSON file and creates a new package option group along its package options |
| orderOptions() | Save the package options for the given group in the provided order |
| validatePackage() | Validates that the given group is valid |
| getGroups() | Partially-constructs the Record object for fetching package option groups |
| getRules() | Retrieves the rules for adding/editing a package option group |
| removePackages() | Removes all package assignments from a package option group |
| setPackages() | Assigns packages to a package option group |
Methods
__construct()
Initialize PackageOptionGroups
public
__construct() : mixed
add()
Adds a package option group for the given company
public
add(array<string|int, mixed> $vars) : int
Parameters
- $vars : array<string|int, mixed>
-
An array of package option group info including:
- company_id The ID for the company under which to add the package option group
- name The package option group name
- description The description of the group
- packages A list of package IDs to assign to this option group (optional)
- hidden 1 if the option is hidden (optional)
- hide_options Whether options in this group disabled by option logic should be hidden (optional)
Return values
int —The package option group ID, void on error
delete()
Permanently removes a package option group from the system
public
delete(int $option_group_id) : mixed
Parameters
- $option_group_id : int
-
The package option group ID to delete
edit()
Updates a package option group
public
edit(int $option_group_id, array<string|int, mixed> $vars) : int
Parameters
- $option_group_id : int
-
The ID of the package option group to update
- $vars : array<string|int, mixed>
-
An array of package option group info including:
- name The package option group name
- description The description of the group
- packages A list of package IDs to assign to this option group (optional)
- hidden 1 if the option is hidden (optional)
- hide_options Whether options in this group disabled by option logic should be hidden (optional)
Return values
int —The package option group ID, void on error
export()
Exports a option group, along with the assigned options and condition sets.
public
export(int $option_group_id) : mixed
Parameters
- $option_group_id : int
-
The ID of the option group to export
Return values
mixed —A JSON-encoded object representing a option group, or void on error
get()
Fetches the package option group
public
get(int $option_group_id) : mixed
Parameters
- $option_group_id : int
-
The ID of the package option group to fetch
Return values
mixed —A stdClass object representing the package option group, false if no such group exists
getAll()
Fetches all package option groups for a given company
public
getAll(int $company_id[, array<string|int, mixed> $filters = [] ]) : array<string|int, mixed>
Parameters
- $company_id : int
-
The company ID
- $filters : array<string|int, mixed> = []
-
A list of package groups filters including:
- hidden Whether or nor to include the hidden package option groups
Return values
array<string|int, mixed> —An array of stdClass objects representing each package option group
getAllOptions()
Fetches all package options assigned to this package option group
public
getAllOptions(int $option_group_id[, array<string|int, mixed> $filters = [] ]) : array<string|int, mixed>
Parameters
- $option_group_id : int
-
The ID of the package option group whose package options to fetch
- $filters : array<string|int, mixed> = []
-
A list of package groups filters including:
- hidden Whether or nor to include the hidden package options
Return values
array<string|int, mixed> —An array of stdClass objects representing each package option group
getAllPackageIds()
Fetches the package IDs of all packages assigned to this package option group
public
getAllPackageIds(int $option_group_id) : array<string|int, mixed>
Parameters
- $option_group_id : int
-
The ID of the package option group whose assigned packages to fetch
Return values
array<string|int, mixed> —An array of stdClass objects representing
getList()
Fetches a list of all package option groups for a given company
public
getList(int $company_id[, int $page = 1 ][, 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 option groups for
- $page : int = 1
-
The page to return results for
- $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 option groups
Return values
array<string|int, mixed> —An array of objects, each representing a package option group
getListCount()
Returns the total number of package option groups returned from PackageOptionGroups::getList(), useful in constructing pagination for the getList() method.
public
getListCount(int $company_id[, array<string|int, mixed> $filters = [] ]) : int
Parameters
- $company_id : int
-
The company ID to fetch package option groups for
- $filters : array<string|int, mixed> = []
-
A list of package groups filters including:
- hidden Whether or nor to include the hidden package option groups
Tags
Return values
int —The total number of package option groups
import()
Imports a JSON file and creates a new package option group along its package options
public
import(array<string|int, mixed> $vars[, mixed $company_id = null ]) : bool
Parameters
- $vars : array<string|int, mixed>
-
An array containing:
- name The name of the package option group
- description The description of the package option group
- options A list of package options
- condition_sets A list of condition sets for the package options
- $company_id : mixed = null
Return values
bool —True if the file has been exported successfully, false otherwise
orderOptions()
Save the package options for the given group in the provided order
public
orderOptions(int $option_group_id, array<string|int, mixed> $option_ids) : mixed
Parameters
- $option_group_id : int
-
The ID of the group to order options for
- $option_ids : array<string|int, mixed>
-
A numerically indexed array of option IDs
validatePackage()
Validates that the given group is valid
public
validatePackage(int $package_id[, int $company_id = null ][, int $option_group_id = null ]) : bool
Parameters
- $package_id : int
-
The ID of the package to validate
- $company_id : int = null
-
The ID of the company the package should belong to (optional, required if $option_group_id not given, default null)
- $option_group_id : int = null
-
The ID of the option group that the package is to be assigned to (optional, required if $company_id not given, default null)
Return values
bool —True if the package option group is valid, or false otherwise
getGroups()
Partially-constructs the Record object for fetching package option groups
private
getGroups(int $company_id[, array<string|int, mixed> $filters = [] ]) : Record
Parameters
- $company_id : int
-
The company ID to filter package option groups
- $filters : array<string|int, mixed> = []
-
A list of package groups filters including:
- hidden Whether or nor to include the hidden package option groups
Return values
Record —A partially-constructed Record object
getRules()
Retrieves the rules for adding/editing a package option group
private
getRules(array<string|int, mixed> $vars[, bool $edit = false ]) : array<string|int, mixed>
Parameters
- $vars : array<string|int, mixed>
-
A list of input vars used in validation
- $edit : bool = false
-
True to fetch the edit rules, false for the add rules (optional, default false)
Return values
array<string|int, mixed> —A list of rules
removePackages()
Removes all package assignments from a package option group
private
removePackages(int $option_group_id) : mixed
Parameters
- $option_group_id : int
-
The package option group ID
setPackages()
Assigns packages to a package option group
private
setPackages(int $option_group_id, array<string|int, mixed> $packages) : mixed
Parameters
- $option_group_id : int
-
The package option group ID
- $packages : array<string|int, mixed>
-
A numerically-indexed list of package IDs to assign