Overview

Packages

  • blesta
    • app
      • controllers
      • models
    • components
      • auth
        • ldap
        • motp
        • oath
      • delivery
        • interfax
        • postal
          • methods
      • download
      • email
      • events
      • exchange
        • rates
          • currency
            • layer
          • fixer
          • open
            • exchange
              • rates
          • x
            • rates
      • gateway
        • payments
      • gateways
      • invoice
        • delivery
        • templates
          • perforated
            • invoice
          • quickbooks
            • invoice
          • templates
            • default
      • modules
      • net
        • amazon
          • s3
        • http
        • net
          • geo
            • ip
      • plugins
      • reports
        • aging
          • invoices
        • client
          • data
            • portability
        • custom
          • report
        • invoice
          • creation
        • package
          • revenue
        • tax
          • liability
        • transactions
          • applied
          • received
      • security
      • session
        • cart
      • settingscollection
      • upgrades
        • tasks
      • upload
      • vcard
    • core
      • Automation
        • Tasks
          • Common
          • Task
        • Type
          • Common
          • Cron
      • Pricing
        • ItemComparator
        • MetaItem
        • Modifier
          • Type
            • Description
              • Type
                • Discount
                • Option
                • Service
                • Tax
            • Discount
            • Price
            • Proration
        • Presenter
          • Build
            • Invoice
            • InvoiceData
            • Options
            • Service
            • ServiceChange
            • ServiceData
          • Collection
          • Format
            • Fields
            • Type
              • Discount
              • Item
              • Option
              • Options
              • Package
              • Pricing
              • Service
              • Tax
          • Items
            • Invoice
            • Service
          • Type
      • ServiceProviders
      • Util
        • Captcha
          • Captchas
          • Common
        • Common
          • Traits
        • Events
          • Common
          • Handlers
          • Observers
        • Filters
          • Common
        • GeoIp
        • Input
          • Fields
            • Common
        • Tax
        • Widgets
    • helpers
      • currency
        • format
      • data
        • structure
          • array
          • string
      • text
        • parser
      • widget
        • client
  • minPHP
    • helpers
      • color
      • data
        • structure
  • None
  • PHP

Classes

  • Accounts
  • Actions
  • ApiKeys
  • Backup
  • CalendarEvents
  • ClientGroups
  • Clients
  • Companies
  • Contacts
  • Countries
  • Coupons
  • CouponTerms
  • CronTasks
  • Currencies
  • EmailGroups
  • Emails
  • EmailVerifications
  • Encryption
  • GatewayManager
  • Invoices
  • InvoiceTemplateManager
  • Languages
  • Logs
  • Marketplace
  • MessageGroups
  • Messages
  • MessengerManager
  • ModuleClientMeta
  • ModuleManager
  • ModuleTypes
  • Navigation
  • PackageGroups
  • PackageOptionGroups
  • PackageOptions
  • Packages
  • Payments
  • Permissions
  • PluginManager
  • Pricings
  • ReportManager
  • ServiceChanges
  • ServiceInvoices
  • Services
  • Settings
  • Staff
  • StaffGroups
  • States
  • SystemEvents
  • Taxes
  • Themes
  • Transactions
  • Users
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated

Class PackageOptions

Package Option management

Model
Extended by AppModel uses Blesta\Core\Util\Common\Traits\Container
Extended by PackageOptions
Package: blesta\app\models
Copyright: Copyright (c) 2013, Phillips Data, Inc.
License: The Blesta License Agreement
Link: Blesta
Located at app/models/package_options.php
Methods summary
public
# __construct( )

Initialize PackageOptions

Initialize PackageOptions

Overrides

AppModel::__construct()
public array
# getValues( integer $option_id )

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

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

Parameters

$option_id
The ID of the option whose values to retrieve

Returns

array
A list of package option values, including package option pricings
public array
# getGroups( integer $option_id )

Fetches all package option groups associated with the given package option

Fetches all package option groups associated with the given package option

Parameters

$option_id
The ID of the option whose groups to retrieve

Returns

array
A list of package option groups this option value is assigned to
public mixed
# get( integer $option_id )

Fetches the package option

Fetches the package option

Parameters

$option_id
The ID of the package option to fetch

Returns

mixed
A stdClass object representing the package option, false if no such option exists
public array
# getByPackageId( integer $package_id )

Fetches the package options for the given package ID

Fetches the package options for the given package ID

Parameters

$package_id
The ID of the package to fetch options for

Returns

array
An array of stdClass objects, each representing a package option
public mixed
# getByPricingId( integer $option_pricing_id )

Fetches a package option for a specific option pricing ID. Only option pricing and values associated with the given option pricing ID will be retrieved.

Fetches a package option for a specific option pricing ID. Only option pricing and values associated with the given option pricing ID will be retrieved.

Parameters

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

Returns

mixed
An stdClass object representing the package option, or false if none exist
public array
# getAll( integer $company_id )

Fetches all package option for a given company

Fetches all package option for a given company

Parameters

$company_id
The company ID

Returns

array
An array of stdClass objects representing each package option
public array
# getList( integer $company_id, integer $page = 1, array $order_by = ['name' => 'asc'] )

Fetches a list of all package options for a given company

Fetches a list of all package options for a given company

Parameters

$company_id
The company ID to fetch package options from
$page
The page to return results for
$order_by
The sort and order conditions (e.g. array('sort_field'=>"ASC"), optional)

Returns

array
An array of objects, each representing a package option
public integer
# getListCount( integer $company_id )

Returns the total number of packages returned from PackageOptions::getList(), useful in constructing pagination for the getList() method.

Returns the total number of packages returned from PackageOptions::getList(), useful in constructing pagination for the getList() method.

Parameters

$company_id
The company ID to fetch package options from

Returns

integer
The total number of package options

See

PackageOptions::getList()
public integer
# add( array $vars )

Adds a package option for the given company

Adds a package option for the given company

Parameters

$vars

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
  • 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)

Returns

integer
The package option ID, void on error
public integer
# edit( integer $option_id, array $vars )

Updates a package option

Updates a package option

Parameters

$option_id
The ID of the package option to update
$vars

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
  • 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)

Returns

integer
The package option ID, void on error
public
# delete( integer $option_id )

Permanently removes a package option from the system

Permanently removes a package option from the system

Parameters

$option_id
The package option ID to delete
public
# deleteOptionValues( integer $option_id, integer $value_id = null )

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

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

Parameters

$option_id
The ID of the package option whose values and pricing to delete
$value_id
The ID of the package option value whose value and pricing to delete (optional)
public
# removeFromGroup( integer $option_id, array $option_groups )

Removes the given package option from the given package option groups

Removes the given package option from the given package option groups

Parameters

$option_id
The ID of the package option
$option_groups

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

public
# orderValues( integer $option_id, array $value_ids )

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

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

Parameters

$option_id
The ID of the option to order values for
$value_ids
A numerically indexed array of value IDs
public array
# getTypes( )

Retrieves a list of package option types and their language definitions

Retrieves a list of package option types and their language definitions

Returns

array
A key/value list of types and their language
public array
# getValueStatuses( )

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

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

Returns

array
A key/value list of statuses and their language
public array
# getPricingPeriods( boolean $plural = false )

Retrieves a list of package pricing periods

Retrieves a list of package pricing periods

Parameters

$plural
True to return language for plural periods, false for singular

Returns

array
Key=>value pairs of package pricing periods
public array
# getValuePricing( integer $value_id )

Fetch pricing for the given package option value

Fetch pricing for the given package option value

Parameters

$value_id
The ID of the value to fetch

Returns

array
An array of stdClass object each representing a pricing
public mixed
# getValuePricingById( integer $pricing_id )

Fetch pricing for the given package option pricing ID

Fetch pricing for the given package option pricing ID

Parameters

$pricing_id
The ID of option pricing

Returns

mixed
A stdClass object representing the value pricing, false otherwise
public mixed
# getValue( integer $option_id, string $value )

Fetches the value based on the given option_id and value

Fetches the value based on the given option_id and value

Parameters

$option_id
The ID of the option to fetch the value for
$value
The value to fetch

Returns

mixed
A stdClass object representing the value, false if not such value exists
public mixed
# getValuePrice( integer $value_id, integer $term, string $period, string $currency, string $convert_currency = null )

Fetches pricing for the given option with the given value

Fetches pricing for the given option with the given value

Parameters

$value_id
The ID of the option to fetch
$term
The term to fetch fields for
$period
The period to fetch fields for
$currency
The currency to fetch fields for
$convert_currency
The currency to convert to (optional)

Returns

mixed
A stdClass object representing the value pricing, false if no such pricing exists
public mixed
# getValueProrateAmount( integer $value_id, string $start_date, integer $term, string $period, integer $pro_rata_day, string $currency, string $convert_currency = null )

Fetches prorated pricing for the given option with the given value

Fetches prorated pricing for the given option with the given value

Parameters

$value_id
The ID of the option to fetch
$start_date
The start date to prorate the price from
$term
The term to fetch fields for
$period
The period to fetch fields for
$pro_rata_day
The day of the month to prorate to
$currency
The currency to fetch fields for
$convert_currency
The currency to convert to (optional)

Returns

mixed
A stdClass object representing the value pricing, false if no such pricing exists
public array
# getAllByPackageId( integer $package_id, integer $term, string $period, string $currency, string $convert_currency = null, array $options = null )

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

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

Parameters

$package_id
The ID of the package
$term
The package term
$period
The package period
$currency
The pricing currency
$convert_currency
The currency to convert to (optional, default null)
$options

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

Returns

array
An array of package options including their values and pricing
public ModuleFields
# getFields( integer $package_id, integer $term, string $period, string $currency, stdClass $vars = null, string $convert_currency = null, array $options = null )

Get option fields

Get option fields

Parameters

$package_id
The ID of the package to fetch fields for
$term
The term to fetch fields for
$period
The period to fetch fields for
$currency
The currency to fetch fields for
$vars
An stdClass object representing a set of post fields (optional, default null)
$convert_currency
The currency to convert to (optional, default null)
$options

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)

Returns

ModuleFields
A ModuleFields object, containg the fields to render
public mixed
# formatPricingTerm( integer $term, string $period )

Formats the pricing term

Formats the pricing term

Parameters

$term
The term length
$period
The period of this term

Returns

mixed
The term formatted in accordance to the period, if possible
public
# formatOptions( array $options )

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.

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.

Parameters

$options
A key/value pair array where each key is the option ID
public array
# formatServiceOptions( array $options )

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

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

Parameters

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

Returns

array

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

public boolean
# validatePricingTerm( integer $term, string $period )

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

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

Parameters

$term
The Term to validate
$period
The period to validate the term against

Returns

boolean
True if validated, false otherwise
public boolean
# validatePricingPeriod( string $period )

Validates the pricing 'period' field type

Validates the pricing 'period' field type

Parameters

$period
The period type

Returns

boolean
True if validated, false otherwise
public boolean
# validateValueStep( string $step, string $type )

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

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

Parameters

$step
The package option step value
$type
The package option type

Returns

boolean
True if the package option value has a valid step set, or false otherwise
public boolean
# validateValueMin( string $min, string $type )

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

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

Parameters

$min
The package option minimum value
$type
The package option type

Returns

boolean
True if the package option value has a valid minimum value set, or false otherwise
public boolean
# validateValueMax( string $max, string $type )

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

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

Parameters

$max
The package option maximum value
$type
The package option type

Returns

boolean
True if the package option value has a valid maximum value set, or false otherwise
public boolean
# validateOptionValueLimit( array $values, string $type )

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

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

Parameters

$values
A numerically-indexed array of package option values
$type
The package option type

Returns

boolean

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

public boolean
# validateSelectTypeValues( array $values, string $type )

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

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

Parameters

$values
A numerically-indexed array of package option values
$type
The package option type

Returns

boolean
True if all package option values contain valid characters, or false otherwise
public boolean
# validateGroupIds( array $groups, integer $company_id = null )

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

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

Parameters

$groups
An array of package option group IDs
$company_id
The ID of the company the groups must belong to (optional, default null)

Returns

boolean

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

Methods inherited from AppModel
_(), boolToInt(), currencyToDecimal(), dateToUtc(), errors(), getPerPage(), ifSet(), loadCrypto(), setDefaultIfEmpty(), setPerPage(), setRulesIfSet(), strToBool(), systemDecrypt(), systemEncrypt(), systemHash(), truncateDecimal(), validateExists(), validateStateCountry()
Methods used from Blesta\Core\Util\Common\Traits\Container
getFromContainer()
Properties inherited from AppModel
$logger, $replacement_keys
Blesta API documentation generated by ApiGen