Blesta
  • Package
  • Class
  • Tree
  • Deprecated

Packages

  • blesta
    • app
      • controllers
      • models
    • components
      • areyouahuman
      • auth
        • motp
        • oath
      • delivery
        • interfax
        • postal
          • methods
      • download
      • email
      • events
        • default
      • exchange
        • rates
          • google
            • finance
          • yahoo
            • finance
      • gateway
        • payments
      • gateways
      • invoice
        • delivery
        • templates
          • quickbooks
            • invoice
      • json
      • modules
      • net
        • amazon
          • s3
        • http
        • net
          • geo
            • ip
      • plugins
      • recaptcha
      • reports
        • aging
          • invoices
        • custom
          • report
        • invoice
          • creation
        • tax
          • liability
        • transactions
          • applied
          • received
      • security
      • session
        • cart
      • settingscollection
      • upgrades
        • tasks
      • upload
      • vcard
    • helpers
      • currency
        • format
      • data
        • structure
          • array
          • string
      • text
        • parser
      • widget
        • client
  • minPHP
    • components
      • input
      • record
    • helpers
      • color
      • data
        • structure
      • date
      • form
      • html
      • javascript
      • xml
    • lib
  • None
  • PHP

Classes

  • Accounts
  • ApiKeys
  • CalendarEvents
  • ClientGroups
  • Clients
  • Companies
  • Contacts
  • Countries
  • Coupons
  • CronTasks
  • Currencies
  • EmailGroups
  • Emails
  • Encryption
  • GatewayManager
  • Invoices
  • InvoiceTemplateManager
  • Languages
  • Logs
  • Marketplace
  • ModuleClientMeta
  • ModuleManager
  • Navigation
  • PackageGroups
  • PackageOptionGroups
  • PackageOptions
  • Packages
  • Payments
  • Permissions
  • PluginManager
  • Pricings
  • ReportManager
  • ServiceChanges
  • Services
  • Settings
  • Staff
  • StaffGroups
  • States
  • Taxes
  • Themes
  • Transactions
  • Users

Class Packages

Package management

Model
Extended by AppModel
Extended by Packages
Package: blesta\app\models
Copyright: Copyright (c) 2010, Phillips Data, Inc.
License: The Blesta License Agreement
Link: Blesta
Located at app/models/packages.php

Methods summary

public
# __construct( )

Initialize Packages

Initialize Packages

Overrides

AppModel::__construct
public integer
# add( array $vars )

Adds a new package to the system

Adds a new package to the system

Parameters

$vars
array
$vars An array of package information including: - module_id The ID of the module this package belongs to (optional, default NULL) - name The name of the package - description The description of the package (optional, default NULL) - description_html The HTML description of the package (optional, default NULL) - qty The maximum quantity available in this package, if any (optional, default NULL) - module_row The module row this package belongs to (optional, default 0) - module_group The module group this package belongs to (optional, default NULL) - taxable Whether or not this package is taxable (optional, default 0) - single_term Whether or not services derived from this package should be canceled at the end of term (optional, default 0) - status The status of this package, 'active', 'inactive', 'restricted' (optional, default 'active') - company_id The ID of the company this package belongs to - prorata_day The prorated day of the month (optional, default NULL) - prorata_cutoff The day of the month pro rata should cut off (optional, default NULL) - email_content A numerically indexed array of email content including: - lang The language of the email content - html The html content for the email (optional) - text The text content for the email, will be created automatically from html if not given (optional) - pricing A numerically indexed array of pricing info including: - term The term as an integer 1-65535 (period should be given if this is set; 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) - cancel_fee The cancelation fee for this package (optional, default 0.00) - currency The ISO 4217 currency code for this pricing - groups A numerically indexed array of package group assignments (optional) - option_groups A numerically indexed array of package option group assignments (optional) - * A set of miscellaneous fields to pass, in addition to the above fields, to the module when adding the package (optional)

Returns

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

Update an existing package ID with the data given

Update an existing package ID with the data given

Parameters

$package_id
integer
$package_id The ID of the package to update
$vars
array
$vars An array of package information including: - module_id The ID of the module this package belongs to (optional, default NULL) - name The name of the package - description The description of the package (optional, default NULL) - description_html The HTML description of the package (optional, default NULL) - qty The maximum quantity available in this package, if any (optional, default NULL) - module_row The module row this package belongs to (optional, default 0) - module_group The module group this package belongs to (optional, default NULL) - taxable Whether or not this package is taxable (optional, default 0) - single_term Whether or not services derived from this package should be canceled at the end of term (optional, default 0) - status The status of this package, 'active', 'inactive', 'restricted' (optional, default 'active') - company_id The ID of the company this package belongs to (optional) - prorata_day The prorated day of the month (optional) - prorata_cutoff The day of the month pro rata should cut off (optional) - email_content A numerically indexed array of email content including: - lang The language of the email content - html The html content for the email (optional) - text The text content for the email, will be created automatically from html if not given (optional) - pricing A numerically indexed array of pricing info including (required): - id The pricing ID (optional, required if an edit else will add as new) - term The term as an integer 1-65535 (period should be given if this is set; optional, default 1), if term is empty will remove this pricing option - 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) - cancel_fee The cancelation fee for this package (optional, default 0.00) - currency The ISO 4217 currency code for this pricing - groups A numerically indexed array of package group assignments (optional), if given will replace all package group assignments with those given - option_groups A numerically indexed array of package option group assignments (optional) - * A set of miscellaneous fields to pass, in addition to the above fields, to the module when adding the package (optional)
public
# delete( integer $package_id )

Permanently removes the given package from the system. Packages can only be deleted if no services exist for that package.

Permanently removes the given package from the system. Packages can only be deleted if no services exist for that package.

Parameters

$package_id
integer
$package_id The package ID to delete
public
# orderPackages( integer $package_group_id, array $package_ids )

Save the packages for the given group in the provided order

Save the packages for the given group in the provided order

Parameters

$package_group_id
integer
$package_group_id The ID of the package group to order packages for
$package_ids
array
$package_ids A numerically indexed array of package IDs
public mixed
# get( integer $package_id )

Fetches the given package

Fetches the given package

Parameters

$package_id
integer
$package_id The package ID to fetch

Returns

mixed
A stdClass object representing the package, false if no such package exists
public mixed
# getByPricingId( integer $package_pricing_id )

Fetches the given package by package pricing ID

Fetches the given package by package pricing ID

Parameters

$package_pricing_id
integer
$package_pricing_id The package pricing ID to use to fetch the package

Returns

mixed
A stdClass object representing the package, false if no such package exists
public array
# getAll( integer $company_id, array $order = array('name'=>"ASC"), string $status = null, string $type = null )

Fetch all packages belonging to the given company

Fetch all packages belonging to the given company

Parameters

$company_id
integer
$company_id The ID of the company to fetch pages for
$order
array
$order The sort order in key = value order, where 'key' is the field to sort on and 'value' is the order to sort (asc or desc)
$status
string
$status The status type of packages to retrieve ('active', 'inactive', 'restricted', default null for all)
$type
string
$type The type of packages to retrieve ('standard', 'addon', default null for all)

Returns

array
An array of stdClass objects each representing a package
public array
# getList( integer $page = 1, array $order_by = array('id_code'=>"asc"), string $status = null )

Fetches a list of all packages

Fetches a list of all packages

Parameters

$page
integer
$page The page to return results for (optional, default 1)
$order_by
array
$order_by The sort and order conditions (e.g. array('sort_field'=>"ASC"), optional)
$status
string
$status The status type of packages to retrieve ('active', 'inactive', 'restricted', default null for all)

Returns

array
An array of stdClass objects each representing a package
public array
# search( string $query, integer $page = 1 )

Search packages

Search packages

Parameters

$query
string
$query The value to search packages for
$page
integer
$page The page number of results to fetch (optional, default 1)

Returns

array
An array of packages that match the search criteria
public
# getSearchCount( string $query )

Return the total number of packages returned from Packages::search(), useful in constructing pagination

Return the total number of packages returned from Packages::search(), useful in constructing pagination

Parameters

$query
string
$query The value to search services for

See

Packages::search()
public array
# getPricingPeriods( boolean $plural = false )

Retrieves a list of package pricing periods

Retrieves a list of package pricing periods

Parameters

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

Returns

array
Key=>value pairs of package pricing periods
public array
# getStatusTypes( )

Retrieves a list of package status types

Retrieves a list of package status types

Returns

array
Key=>value pairs of package status types
public array
# getProrataDays( )

Retrieves a list of acceptable pro rata day options

Retrieves a list of acceptable pro rata day options

Returns

array
A set of key=>value pairs of pro rata days
public boolean
# isDateAfterProrataCutoff( string $date, integer $cutoff_day )

Determines whether the pro rata cutoff day has passed

Determines whether the pro rata cutoff day has passed

Parameters

$date
string
$date The date to check
$cutoff_day
integer
$cutoff_day The day of the month representing the cutoff day

Returns

boolean
True if the given date is after the pro rata cutoff day, or false otherwise
public mixed
# getProrateDate( string $start_date, string $period, integer $pro_rata_day )

Retrieves the date to prorate a service to

Retrieves the date to prorate a service to

Parameters

$start_date
string
$start_date The date to start from
$period
string
$period The period associated with the service
$pro_rata_day
integer
$pro_rata_day The day of the month to prorate to

Returns

mixed
The prorated UTC end date; null if not prorating; or boolean false if it cannot be determined
public boolean
# isProrataDay( string $start_date, integer $pro_rata_day )

Determines whether the given start date is on the pro rata day

Determines whether the given start date is on the pro rata day

Parameters

$start_date
string
$start_date The start date
$pro_rata_day
integer
$pro_rata_day The pro rata day of the month

Returns

boolean
True if the given start date is the current pro rata day for the company's timezone, or false otherwise
public mixed
# getDaysToProrate( string $start_date, string $period, integer $pro_rata_day )

Retrieves the number of days to prorate a service

Retrieves the number of days to prorate a service

Parameters

$start_date
string
$start_date The date to start from
$period
string
$period The period associated with the service
$pro_rata_day
integer
$pro_rata_day The day of the month to prorate to

Returns

mixed
The number of days to prorate, or boolean false if it cannot be determined
public integer
# getDaysToProrateBetween( string $start_date, string $end_date )

Retrieves the number of days between the two given dates

Retrieves the number of days between the two given dates

Deprecated

since 3.5.0

Parameters

$start_date
string
$start_date The start date
$end_date
string
$end_date The end date

Returns

integer
The number of days between the dates
public float
# getProrateAmount( float $amount, integer $prorate_days, integer $term, string $period, boolean $allow_all_recurring_periods = false )

Retrieves the amount to prorate a value given the number of days to prorate it

Retrieves the amount to prorate a value given the number of days to prorate it

Deprecated

since 3.5.0

Parameters

$amount
float
$amount The total cost for the given term and period
$prorate_days
integer
$prorate_days The number of days to prorate the amount for
$term
integer
$term The term length
$period
string
$period The period type (one of "month", "year", unless $allow_all_periods is true)
$allow_all_recurring_periods
boolean
$allow_all_recurring_periods True to allow all recurring periods, or false to limit to "month" and "year" only (optional, default false)

Returns

float
The prorate amount

See

Packages::getProratePrice()
public float
# getProratePrice( float $amount, string $start_date, integer $term, string $period, integer $pro_rata_day, boolean $allow_all_recurring_periods = false, string $prorate_date = null )

Retrieves the price to prorate a value given the date, term, and period to prorate from

Retrieves the price to prorate a value given the date, term, and period to prorate from

Parameters

$amount
float
$amount The total cost for the given term and period
$start_date
string
$start_date The start date to calculate the price from
$term
integer
$term The term length
$period
string
$period The period type (e.g. "month", "year")
$pro_rata_day
integer
$pro_rata_day The day of the month to prorate to
$allow_all_recurring_periods
boolean
$allow_all_recurring_periods True to allow all recurring periods, or false to limit to "month" and "year" only (optional, default false)
$prorate_date
string
$prorate_date The date to prorate to. Setting this value will ignore the $pro_rata_day (optional)

Returns

float
The prorate price
public array
# getPackageItems( array $package_pricings, integer $client_id = null, string $currency = null )

Retrieves a list of all package items and config options (including prorated items) from those given

Retrieves a list of all package items and config options (including prorated items) from those given

Parameters

$package_pricings
array
$package_pricings A numerical array of package pricing and quantity values of the form: - pricing_id The package pricing ID - qty The qty being purchased for the package pricing ID - fees A numerical array of fee types to include in the pricing calculations, including: - setup - cancel - configoptions An array of key/value pairs where each key is the package option ID and each value is the package option value
$client_id
integer
$client_id The ID of the client to which the pricings are to be applied (optional)
$currency
string
$currency The ISO 4217 currency code to calculate totals in (null defaults to default client or company currency)

Returns

array
A numerically-indexed array of all package items with any config options
public array
# calcLineTotals( integer $client_id, array $package_pricings, string $coupon_code = null, array $tax_rules = null, integer $client_group_id = null, string $currency = null )

Caclulates the cost in one or more package pricings for a client with the given coupon. Tax is only applied if the package is configured as taxable and there exists tax rules that apply to the given client.

Caclulates the cost in one or more package pricings for a client with the given coupon. Tax is only applied if the package is configured as taxable and there exists tax rules that apply to the given client.

Parameters

$client_id
integer
$client_id The ID of the client to which the pricings are to be applied
$package_pricings
array
$package_pricings A numerical array of package pricing and quantity values of the form: - pricing_id The package pricing ID - qty The qty being purchased for the package pricing ID - fees A numerical array of fee types to include in the pricing calculations, including: - setup - cancel - configoptions An array of key/value pairs where each key is the package option ID and each value is the package option value
$coupon_code
string
$coupon_code The coupon code to apply to each package pricing ID
$tax_rules
array
$tax_rules A numerically indexed array of stdClass objects each representing a tax rule to apply to this client or client group. Must be provided if $client_id not specified
$client_group_id
integer
$client_group_id The ID of the client group to calculate line totals for
$currency
string
$currency The ISO 4217 currency code to calculate totals in (null defaults to default client or client group currency)

Returns

array
An array of pricing information including: - subtotal The total before discount, fees, and tax - discount The total savings - fees An array of fees requested including: - setup The setup fee - cancel The cancel fee - total The total after discount, fees, but before tax - total_w_tax The total after discount, fees, and tax - tax The total tax
public mixed
# convertPricing( stdClass $pricing, string $currency, boolean $allow_conversion )

Convert pricing to the given currency if allowed

Convert pricing to the given currency if allowed

Parameters

$pricing
stdClass
$pricing A stdClass object representing a package pricing
$currency
string
$currency The ISO 4217 currency code to convert to
$allow_conversion
boolean
$allow_conversion True to allow converion, false otherwise

Returns

mixed
The stdClass object representing the converted pricing (if conversion allowed), null otherwise
public integer
# getListCount( string $status = null )

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

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

Parameters

$status
string
$status The status type of packages to retrieve ('active', 'inactive', 'restricted', default null for all)

Returns

integer
The total number of packages

See

Packages::getList()
public mixed
# getAllGroups( integer $company_id, integer $package_id = null, string $type = null )

Fetches all package groups belonging to a company, or optionally, all package groups belonging to a specific package

Fetches all package groups belonging to a company, or optionally, all package groups belonging to a specific package

Parameters

$company_id
integer
$company_id The company ID
$package_id
integer
$package_id The package ID to fetch groups of (optional, default null)
$type
string
$type The type of group to fetch (null, standard, addon)

Returns

mixed
An array of stdClass objects representing package groups, or false if none found
public array
# getAllAddonGroups( integer $parent_group_id )

Returns all addon package groups for the given package group.

Returns all addon package groups for the given package group.

Parameters

$parent_group_id
integer
$parent_group_id The ID of the parent package group

Returns

array
A list of addon package groups
public mixed
# getAllPackagesByGroup( integer $package_group_id, string $status = null )

Fetches all packages belonging to a specific package group

Fetches all packages belonging to a specific package group

Parameters

$package_group_id
integer
$package_group_id The ID of the package group
$status
string
$status The status type of packages to retrieve ('active', 'inactive', 'restricted', default null for all)

Returns

mixed
An array of stdClass objects representing packages, or false if none exist
public array
# getCompatiblePackages( integer $package_id, integer $module_id, string $type )

Get all compatible packages

Get all compatible packages

Parameters

$package_id
integer
$package_id The ID of the package to fetch all compatible packages for
$module_id
integer
$module_id The ID of the module to include compatible packages for
$type
string
$type The type of package group to include ("standard", "addon")

Returns

array
An array of stdClass objects, each representing a compatible package and its pricing
public boolean
# validateServiceExists( integer $package_id )

Checks whether a service exists for a specific package ID

Checks whether a service exists for a specific package ID

Parameters

$package_id
integer
$package_id The package ID to check

Returns

boolean
True if a service exists for this package, false otherwise
public boolean
# validateStatus( string $status )

Validates the package 'status' field type

Validates the package 'status' field type

Parameters

$status
string
$status The status type

Returns

boolean
True if validated, false otherwise
public boolean
# validateTerm( 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
integer
$term The Term to validate
$period
string
$period The period to validate the term against

Returns

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

Validates the pricing 'period' field type

Validates the pricing 'period' field type

Parameters

$period
string
$period The period type

Returns

boolean
True if validated, false otherwise
public boolean
# validateGroup( integer $group_id, integer $company_id )

Validates that the given group belongs to the given company ID

Validates that the given group belongs to the given company ID

Parameters

$group_id
integer
$group_id The ID of the group to test
$company_id
integer
$company_id The ID of the company to validate exists for the given group

Returns

boolean
True if validated, false otherwise
public boolean
# validateOptionGroup( integer $option_group_id, mixed $company_id )

Validates that the given group is valid

Validates that the given group is valid

Parameters

$option_group_id
integer
$option_group_id The ID of the package option group to validate
$company_id

Returns

boolean
True if the package option group is valid, or false otherwise
public boolean
# validatePriceInUse( string $term, integer $pricing_id )

Validates that the given price is in use

Validates that the given price is in use

Parameters

$term
string
$term The term of the price point, if non-empty no check is performed.
$pricing_id
integer
$pricing_id The package pricing ID

Returns

boolean
True if the price is in use, false otherwise
public boolean
# validateCurrency( string $currency, string $term, mixed $period )

Validates that the given currency is valid for adding/editing a package

Validates that the given currency is valid for adding/editing a package

Parameters

$currency
string
$currency The ISO 4217 currency code for this pricing option
$term
string
$term The term for this pricing option
$period

Returns

boolean
True if the currency is valid, or false otherwise
public
# validateParse( array $email_content )

Validate that the given email content parses template parsing

Validate that the given email content parses template parsing

Parameters

$email_content
array
A numerically-indexed array of template data to parse, containing: - html The HTML version of the email content - text The text version of the email content
public mixed
# formatPricingTerm( integer $term, string $period )

Formats the pricing term

Formats the pricing term

Parameters

$term
integer
$term The term length
$period
string
$period The period of this term

Returns

mixed
The term formatted in accordance to the period, if possible

Methods inherited from AppModel

_(), boolToInt(), currencyToDecimal(), dateToUtc(), errors(), getPerPage(), ifSet(), loadCrypto(), setDefaultIfEmpty(), setPerPage(), setRulesIfSet(), strToBool(), systemDecrypt(), systemEncrypt(), systemHash(), truncateDecimal(), validateExists(), validateStateCountry()

Methods inherited from Model

affectedRows(), begin(), commit(), getConnection(), lastInsertId(), makeDSN(), prepare(), query(), rollBack(), setAttribute(), setFetchMode()

Magic methods summary

Properties summary

Properties inherited from AppModel

$replacement_keys

Blesta API documentation generated by ApiGen 2.8.0