Blesta Source Documentation

PackageOptions extends AppModel

Package Option management

Table of Contents

Methods

__construct() Initialize PackageOptions
add() Adds a package option for the given company
delete() Permanently removes a package option from the system
deleteOptionValues() Deletes all package option values and associated pricing for the given package option
edit() Updates a package option
formatOptions() Formats options into key/value named pairs where each key is the option field name from a key/value pair array where each key is the option ID.
formatPricingTerm() Formats the pricing term
formatServiceOptions() Formats options into configoption array elements where each key is the option ID and each value is the option's selected value
get() Fetches the package option
getAll() Fetches all package option for a given company
getAllByPackageId() Retrieves all package options for a package given its term, period, and currency
getByPackageId() Fetches the package options for the given package ID
getByPackageOptionGroupId() Returns all the package options by the package option group id.
getByPricingId() Fetches a package option for a specific option pricing ID.
getFields() Get option fields
getGroups() Fetches all package option groups associated with the given package option
getList() Fetches a list of all package options for a given company
getListCount() Returns the total number of packages returned from PackageOptions::getList(), useful in constructing pagination for the getList() method.
getPricingPeriods() Retrieves a list of package pricing periods
getTypes() Retrieves a list of package option types and their language definitions
getValue() Fetches the value based on the given option_id and value
getValuePrice() Fetches pricing for the given option with the given value
getValuePricing() Fetch pricing for the given package option value
getValuePricingById() Fetch pricing for the given package option pricing ID
getValueProrateAmount() Fetches prorated pricing for the given option with the given value
getValues() Fetches all package option values (and subsequent pricing) for the given package option
getValueStatuses() Retrieves a list of package option value statuses and their language definitions
orderValues() Save the package options values for the given option in the provided order
removeFromGroup() Removes the given package option from the given package option groups
validateGroupIds() Validates whether all of the given package option group IDs exist and belong to the given company
validateOptionValueLimit() Validates whether the number of package option values is valid for the given package option type
validatePricingPeriod() Validates the pricing 'period' field type
validatePricingTerm() Validates that the term is valid for the period. That is, the term must be > 0 if the period is something other than "onetime".
validateSelectTypeValues() Validates whether any of the given package option values contains invalid special characters for options of the 'select' type. An invalid character is determined to be one that is not equivalent to its HTML encoded version
validateValueMax() Validates whether the given package option value given has a valid maximum value
validateValueMin() Validates whether the given package option value given has a valid minimum value
validateValueStep() Validates whether the given package option value given has a valid step set
addOptionGroups() Associates the given package option with all of the given package option groups
addOptionPricing() Adds/updates/deletes package option pricing for a specific package option value
addOptionValues() Adds/updates/deletes package option values (and subsequent pricing) for a package option
canDeleteValue() Determines whether an option value is deletable
canDeleteValuePrice() Determines whether an option value pricing is deletable
canEditValue() Determines whether an option value is editable
deleteOptionPricing() Deletes a single package option pricing
formatValues() Formats option values
getOption() Retrieves the package option by ID
getOptions() Partially-constructs the Record object for fetching package options
getRules() Retrieves a list of rules for adding/editing package options
getValueById() Retrieves the package option value by ID
removeOptionVars() Removes data from input vars that may have adverse effects on adding/editing data
validateUniqueValues() Validates that no duplicate package option values were submitted
zeroPricing() Zeros out all pricing values when disable_pricing is enabled
Methods

__construct()

Initialize PackageOptions

public __construct() : mixed

add()

Adds a package option for the given company

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

An array of package option info including:

  • company_id The ID of the company to assign the option to
  • label The label displayed for this option
  • name The field name for this option
  • type The field type for this option, one of:
    • select
    • checkbox
    • radio
    • quantity
    • text
    • textarea
    • password
  • addable 1 if the option is addable by a client
  • editable 1 if the option is editable by a client
  • hidden 1 if the option is hidden
  • values A numerically indexed array of value info including:
    • name The name of the package option value (display name)
    • value The value of the package option (optional, default null)
    • default 1 or 0, whether or not this value is the default value (optional, default 0) Only one value may be set as the default value for the option For options of the 'quantity' type, the default may be set to the quantity
    • status The status of the package option value (optional, default 'active') Only 'select' and 'radio' option types may be 'inactive'
    • min The minimum value if type is 'quantity'
    • max The maximum value if type is 'quantity', null for unlimited quantity
    • step The step value if type is 'quantity'
    • pricing A numerically indexed array of pricing info including:
      • term The term as an integer 1-65535 (optional, default 1)
      • period The period, 'day', 'week', 'month', 'year', 'onetime' (optional, default 'month')
      • price The price of this term (optional, default 0.00)
      • setup_fee The setup fee for this package (optional, default 0.00)
      • currency The ISO 4217 currency code for this pricing (optional, default USD)
  • groups An array of package option group IDs that the option belongs to (optional)
Return values
int

The package option ID, void on error

delete()

Permanently removes a package option from the system

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

The package option ID to delete

deleteOptionValues()

Deletes all package option values and associated pricing for the given package option

public deleteOptionValues(int $option_id[, int $value_id = null ]) : mixed
Parameters
$option_id : int

The ID of the package option whose values and pricing to delete

$value_id : int = null

The ID of the package option value whose value and pricing to delete (optional)

edit()

Updates a package option

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

The ID of the package option to update

$vars : array<string|int, mixed>

An array of package option info including:

  • label The label displayed for this option
  • name The field name for this option
  • type The field type for this option, one of:
    • select
    • checkbox
    • radio
    • quantity
    • text
    • textarea
    • password
  • addable 1 if the option is addable by a client
  • editable 1 if the option is editable by a client
  • hidden 1 if the option is hidden
  • values A numerically indexed array of value info including:
    • id The ID of the package option value to update. If the ID is not given, the option value will be added. (optional, required for edit)
    • name The name of the package option value (display name). If the 'name' is empty or not given, the option value will be deleted
    • value The value of the package option (optional, default null)
    • default 1 or 0, whether or not this value is the default value (optional, default 0) Only one value may be set as the default value for the option. For options of the 'quantity' type, the default may be set to the quantity
    • status The status of the package option value (optional, default 'active') Only 'select' and 'radio' option types may be 'inactive'
    • min The minimum value if type is 'quantity'
    • max The maximum value if type is 'quantity', null for unlimited quantity
    • step The step value if type is 'quantity'
    • pricing A numerically indexed array of pricing info including:
      • id The package option pricing ID to update. If the ID is not given, the pricing will be added. (optional, required for edit)
      • term The term as an integer 1-65535 (optional, default 1). If the term is not given along with an ID, the pricing will be deleted
      • period The period, 'day', 'week', 'month', 'year', 'onetime' (optional, default 'month')
      • price The price of this term (optional, default 0.00)
      • setup_fee The setup fee for this package (optional, default 0.00)
      • currency The ISO 4217 currency code for this pricing (optional, default USD)
  • groups An array of package option group IDs that the option belongs to (optional)
Return values
int

The package option ID, void on error

formatOptions()

Formats options into key/value named pairs where each key is the option field name from a key/value pair array where each key is the option ID.

public formatOptions(array<string|int, mixed> $options) : mixed
Parameters
$options : array<string|int, mixed>

A key/value pair array where each key is the option ID

formatPricingTerm()

Formats the pricing term

public formatPricingTerm(int $term, string $period) : mixed
Parameters
$term : int

The term length

$period : string

The period of this term

Return values
mixed

The term formatted in accordance to the period, if possible

formatServiceOptions()

Formats options into configoption array elements where each key is the option ID and each value is the option's selected value

public formatServiceOptions(array<string|int, mixed> $options) : array<string|int, mixed>
Parameters
$options : array<string|int, mixed>

An array of stdClass objects, each representing a service option and its value

Return values
array<string|int, mixed>

An array that contains configoptions and key/value pairs of option ID and the option's selected value

get()

Fetches the package option

public get(int $option_id) : mixed
Parameters
$option_id : int

The ID of the package option to fetch

Return values
mixed

A stdClass object representing the package option, false if no such option exists

getAll()

Fetches all package option 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 options
Return values
array<string|int, mixed>

An array of stdClass objects representing each package option

getAllByPackageId()

Retrieves all package options for a package given its term, period, and currency

public getAllByPackageId(int $package_id, int $term, string $period, string $currency[, string $convert_currency = null ][, array<string|int, mixed> $options = null ]) : array<string|int, mixed>
Parameters
$package_id : int

The ID of the package

$term : int

The package term

$period : string

The package period

$currency : string

The pricing currency

$convert_currency : string = null

The currency to convert to (optional, default null)

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

An array of key/value pairs for filtering options (optional, default null). May include:

  • addable Set to 1 to only include options that are addable by clients; 0 to only include options that are NOT addable by clients; otherwise every option is included
  • editable Set to 1 to only include options that are editable by clients; 0 to only include options that are NOT editable by clients; otherwise every option is included
  • allow An array of option IDs to include (i.e. white-list). An empty array would return no options. Not setting this 'option_ids' key will allow any option
  • disallow An array of option IDs not to include (i.e. black-list). An empty array would allow all options.
  • configoptions An array of key/value pairs currently in use where each key is the package option ID and each value is the option value
Return values
array<string|int, mixed>

An array of package options including their values and pricing

getByPackageId()

Fetches the package options for the given package ID

public getByPackageId(int $package_id) : array<string|int, mixed>
Parameters
$package_id : int

The ID of the package to fetch options for

Return values
array<string|int, mixed>

An array of stdClass objects, each representing a package option

getByPackageOptionGroupId()

Returns all the package options by the package option group id.

public getByPackageOptionGroupId(int $package_option_group_id) : array<string|int, mixed>
Parameters
$package_option_group_id : int

The ID of the package option group to fetch the options

Return values
array<string|int, mixed>

A list of all the options for the given package option group

getByPricingId()

Fetches a package option for a specific option pricing ID.

public getByPricingId(int $option_pricing_id) : mixed

Only option pricing and values associated with the given option pricing ID will be retrieved.

Parameters
$option_pricing_id : int

The ID of the package option pricing value whose package option to fetch

Return values
mixed

An stdClass object representing the package option, or false if none exist

getFields()

Get option fields

public getFields(int $package_id, int $term, string $period, string $currency[, stdClass $vars = null ][, string $convert_currency = null ][, array<string|int, mixed> $options = null ]) : ModuleFields
Parameters
$package_id : int

The ID of the package to fetch fields for

$term : int

The term to fetch fields for

$period : string

The period to fetch fields for

$currency : string

The currency to fetch fields for

$vars : stdClass = null

An stdClass object representing a set of post fields (optional, default null)

$convert_currency : string = null

The currency to convert to (optional, default null)

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

An array of key/value pairs for filtering options (optional, default null). May include:

  • addable Set to 1 to only include options that are addable by clients; 0 to only include options that are NOT addable by clients; otherwise every option is included
  • editable Set to 1 to only include options that are editable by clients; 0 to only include options that are NOT editable by clients; otherwise every option is included
  • allow An array of option IDs to include (i.e. white-list). An empty array would return no fields. Not setting this 'option_ids' key will allow any option
  • disallow An array of option IDs not to include (i.e. black-list). An empty array would allow all options.
  • configoptions An array of key/value pairs currently in use where each key is the package option ID and each value is the option value
  • new Set to 1 if this is for a new package, or 0 if this is for an existing package (default 1)
Return values
ModuleFields

A ModuleFields object, containg the fields to render

getGroups()

Fetches all package option groups associated with the given package option

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

The ID of the option whose groups to retrieve

Return values
array<string|int, mixed>

A list of package option groups this option value is assigned to

getList()

Fetches a list of all package options 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 options from

$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 options
Return values
array<string|int, mixed>

An array of objects, each representing a package option

getListCount()

Returns the total number of packages returned from PackageOptions::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 options from

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

A list of package groups filters including:

  • hidden Whether or nor to include the hidden package options
Tags
see
PackageOptions::getList()
Return values
int

The total number of package options

getPricingPeriods()

Retrieves a list of package pricing periods

public getPricingPeriods([bool $plural = false ]) : array<string|int, mixed>
Parameters
$plural : bool = false

True to return language for plural periods, false for singular

Return values
array<string|int, mixed>

Key=>value pairs of package pricing periods

getTypes()

Retrieves a list of package option types and their language definitions

public getTypes() : array<string|int, mixed>
Return values
array<string|int, mixed>

A key/value list of types and their language

getValue()

Fetches the value based on the given option_id and value

public getValue(int $option_id, string $value) : mixed
Parameters
$option_id : int

The ID of the option to fetch the value for

$value : string

The value to fetch

Return values
mixed

A stdClass object representing the value, false if not such value exists

getValuePrice()

Fetches pricing for the given option with the given value

public getValuePrice(int $value_id, int $term, string $period, string $currency[, string $convert_currency = null ]) : mixed
Parameters
$value_id : int

The ID of the option to fetch

$term : int

The term to fetch fields for

$period : string

The period to fetch fields for

$currency : string

The currency to fetch fields for

$convert_currency : string = null

The currency to convert to (optional)

Return values
mixed

A stdClass object representing the value pricing, false if no such pricing exists

getValuePricing()

Fetch pricing for the given package option value

public getValuePricing(int $value_id) : array<string|int, mixed>
Parameters
$value_id : int

The ID of the value to fetch

Return values
array<string|int, mixed>

An array of stdClass object each representing a pricing

getValuePricingById()

Fetch pricing for the given package option pricing ID

public getValuePricingById(int $pricing_id) : mixed
Parameters
$pricing_id : int

The ID of option pricing

Return values
mixed

A stdClass object representing the value pricing, false otherwise

getValueProrateAmount()

Fetches prorated pricing for the given option with the given value

public getValueProrateAmount(int $value_id, string $start_date, int $term, string $period, int $pro_rata_day, string $currency[, string $convert_currency = null ]) : mixed
Parameters
$value_id : int

The ID of the option to fetch

$start_date : string

The start date to prorate the price from

$term : int

The term to fetch fields for

$period : string

The period to fetch fields for

$pro_rata_day : int

The day of the month to prorate to

$currency : string

The currency to fetch fields for

$convert_currency : string = null

The currency to convert to (optional)

Return values
mixed

A stdClass object representing the value pricing, false if no such pricing exists

getValues()

Fetches all package option values (and subsequent pricing) for the given package option

public getValues(int $option_id) : array<string|int, mixed>
Parameters
$option_id : int

The ID of the option whose values to retrieve

Return values
array<string|int, mixed>

A list of package option values, including package option pricings

getValueStatuses()

Retrieves a list of package option value statuses and their language definitions

public getValueStatuses() : array<string|int, mixed>
Return values
array<string|int, mixed>

A key/value list of statuses and their language

orderValues()

Save the package options values for the given option in the provided order

public orderValues(int $option_id, array<string|int, mixed> $value_ids) : mixed
Parameters
$option_id : int

The ID of the option to order values for

$value_ids : array<string|int, mixed>

A numerically indexed array of value IDs

removeFromGroup()

Removes the given package option from the given package option groups

public removeFromGroup(int $option_id, array<string|int, mixed> $option_groups) : mixed
Parameters
$option_id : int

The ID of the package option

$option_groups : array<string|int, mixed>

A numerically-indexed array of package option group IDs of the package option groups that this option should no longer be assigned to

validateGroupIds()

Validates whether all of the given package option group IDs exist and belong to the given company

public validateGroupIds(array<string|int, mixed> $groups[, int $company_id = null ]) : bool
Parameters
$groups : array<string|int, mixed>

An array of package option group IDs

$company_id : int = null

The ID of the company the groups must belong to (optional, default null)

Return values
bool

True if all of the given package option groups exist and belong to the given company, or false otherwise

validateOptionValueLimit()

Validates whether the number of package option values is valid for the given package option type

public validateOptionValueLimit(array<string|int, mixed> $values, string $type) : bool
Parameters
$values : array<string|int, mixed>

A numerically-indexed array of package option values

$type : string

The package option type

Return values
bool

True if the number of package option values is valid for the given package option type, or false otherwise

validatePricingPeriod()

Validates the pricing 'period' field type

public validatePricingPeriod(string $period) : bool
Parameters
$period : string

The period type

Return values
bool

True if validated, false otherwise

validatePricingTerm()

Validates that the term is valid for the period. That is, the term must be > 0 if the period is something other than "onetime".

public validatePricingTerm(int $term, string $period) : bool
Parameters
$term : int

The Term to validate

$period : string

The period to validate the term against

Return values
bool

True if validated, false otherwise

validateSelectTypeValues()

Validates whether any of the given package option values contains invalid special characters for options of the 'select' type. An invalid character is determined to be one that is not equivalent to its HTML encoded version

public validateSelectTypeValues(array<string|int, mixed> $values, string $type) : bool
Parameters
$values : array<string|int, mixed>

A numerically-indexed array of package option values

$type : string

The package option type

Return values
bool

True if all package option values contain valid characters, or false otherwise

validateValueMax()

Validates whether the given package option value given has a valid maximum value

public validateValueMax(string $max, string $type) : bool
Parameters
$max : string

The package option maximum value

$type : string

The package option type

Return values
bool

True if the package option value has a valid maximum value set, or false otherwise

validateValueMin()

Validates whether the given package option value given has a valid minimum value

public validateValueMin(string $min, string $type) : bool
Parameters
$min : string

The package option minimum value

$type : string

The package option type

Return values
bool

True if the package option value has a valid minimum value set, or false otherwise

validateValueStep()

Validates whether the given package option value given has a valid step set

public validateValueStep(string $step, string $type) : bool
Parameters
$step : string

The package option step value

$type : string

The package option type

Return values
bool

True if the package option value has a valid step set, or false otherwise

addOptionGroups()

Associates the given package option with all of the given package option groups

private addOptionGroups(int $option_id, array<string|int, mixed> $option_groups) : mixed
Parameters
$option_id : int

The ID of the package option

$option_groups : array<string|int, mixed>

A list of package option group IDs to associate with this option

Tags
see

PackageOptions::add(), PackageOptions::edit()

addOptionPricing()

Adds/updates/deletes package option pricing for a specific package option value

private addOptionPricing(int $option_value_id, int $company_id, array<string|int, mixed> $pricing) : mixed
Parameters
$option_value_id : int

The ID of the package option value to add pricing to

$company_id : int

The ID of the company the groups must belong to

$pricing : array<string|int, mixed>

A list of pricing to add to the option value

Tags
see

PackageOptions::add(), PackageOptions::edit(), PackageOptions::addOptionValues()

addOptionValues()

Adds/updates/deletes package option values (and subsequent pricing) for a package option

private addOptionValues(int $option_id, int $company_id, array<string|int, mixed> $values, string $type) : mixed
Parameters
$option_id : int

The ID of the package option to add the values to

$company_id : int

The ID of the company the groups must belong to

$values : array<string|int, mixed>

A list of option values and pricing

$type : string

The option type

Tags
see

PackageOptions::add(), PackageOptions::edit()

canDeleteValue()

Determines whether an option value is deletable

private canDeleteValue(array<string|int, mixed> $value, string $option_type) : bool
Parameters
$value : array<string|int, mixed>

The package option value

$option_type : string

The package option type

Tags
see
PackageOptions::add
see
PackageOptions::edit
Return values
bool

True if the package option value is deletable, otherwise false

canDeleteValuePrice()

Determines whether an option value pricing is deletable

private canDeleteValuePrice(array<string|int, mixed> $pricing) : bool
Parameters
$pricing : array<string|int, mixed>

An array of pricing for an option value

  • id The option pricing ID
  • term The option pricing term (optional)
Tags
see
PackageOptions::add
see
PackageOptions::edit
Return values
bool

True if the option value pricing is deletable, otherwise false

canEditValue()

Determines whether an option value is editable

private canEditValue(int $value_id) : bool
Parameters
$value_id : int

The ID of the package option value

Tags
see
PackageOptions::add
see
PackageOptions::edit
Return values
bool

True if the package option is editable, otherwise false

deleteOptionPricing()

Deletes a single package option pricing

private deleteOptionPricing(int $pricing_id) : mixed
Parameters
$pricing_id : int

The package option pricing ID to delete

formatValues()

Formats option values

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

An array of input containing:

  • type The type of package option
  • values An array of option values and pricing
Return values
array<string|int, mixed>

An array of all given option values

getOption()

Retrieves the package option by ID

private getOption(int $option_id) : mixed
Parameters
$option_id : int

The ID of the package option to fetch

Return values
mixed

A stdClass object representing the package option, or false if no such option exists

getOptions()

Partially-constructs the Record object for fetching package options

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

The company ID to fetch package options from

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

A list of package groups filters including:

  • hidden Whether or nor to include the hidden package options
Return values
Record

A partially-constructed Record object

getRules()

Retrieves a list of rules for adding/editing package options

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

getValueById()

Retrieves the package option value by ID

private getValueById(int $option_value_id) : false|stdClass
Parameters
$option_value_id : int

The ID of the package option value to fetch

Return values
false|stdClass

An stdClass object representing the package option value if found, otherwise false

removeOptionVars()

Removes data from input vars that may have adverse effects on adding/editing data

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

An array of package option info

Return values
array<string|int, mixed>

An array of package option info without fields that are not to be set

validateUniqueValues()

Validates that no duplicate package option values were submitted

private validateUniqueValues(array<string|int, mixed> $values) : bool
Parameters
$values : array<string|int, mixed>

A numerically-indexed array of package option values

Return values
bool

False if all package option values contain duplicates, or true otherwise

zeroPricing()

Zeros out all pricing values when disable_pricing is enabled

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

The input variables containing option values

Return values
array<string|int, mixed>

The modified variables with zeroed pricing

Tags
subpackage

app.models

copyright

Copyright (c) 2013, Phillips Data, Inc.

license

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

link

Blesta


        
On this page

Search results