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 Services

Service management

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

Initialize Services

Initialize Services

Overrides

AppModel::__construct()
public integer
# getStatusCount( integer $client_id, string $status = 'active', boolean $children = true, array $filters = [] )

Returns the number of results available for the given status

Returns the number of results available for the given status

Parameters

$client_id
The ID of the client to select status count values for
$status
The status value to select a count of ('active', 'canceled', 'pending', 'suspended')
$children

True to fetch all services, including child services, or false to fetch only services without a parent (optional, default true)

$filters

A list of parameters to filter by, including:

  • package_id The package ID (optional)
  • module_id The module ID on which to filter packages (optional)
  • package_name The (partial) name of the packages for which to fetch services (optional)
  • service_meta The (partial) value of meta data on which to filter services (optional)

Returns

integer
The number representing the total number of services for this client with that status
public array
# getList( integer $client_id = null, string $status = 'active', integer $page = 1, array $order_by = ['date_added' => 'DESC'], boolean $children = true, array $filters = [] )

Returns a list of services for the given client and status

Returns a list of services for the given client and status

Parameters

$client_id
The ID of the client to select services for
$status

The status to filter by (optional, default "active"), one of:

  • active All active services
  • canceled All canceled services
  • pending All pending services
  • suspended All suspended services
  • in_review All services that require manual review before they may become pending
  • scheduled_cancellation All services scheduled to be canceled
  • all All active/canceled/pending/suspended/in_review
$page
The page to return results for (optional, default 1)
$order_by
The sort and order conditions (e.g. array('sort_field'=>"ASC"), optional)
$children

True to fetch all services, including child services, or false to fetch only services without a parent (optional, default true)

$filters

A list of parameters to filter by, including:

  • client_id The client ID (optional)
  • package_id The package ID (optional)
  • module_id The module ID on which to filter packages (optional)
  • package_name The (partial) name of the packages for which to fetch services (optional)
  • service_meta The (partial) value of meta data on which to filter services (optional)
  • status The status type of the services to fetch (optional, default 'active'):
    • active All active services
    • canceled All canceled services
    • pending All pending services
    • suspended All suspended services
    • in_review All services that require manual review before they may become pending
    • scheduled_cancellation All services scheduled to be canceled
    • all All active/canceled/pending/suspended/in_review

Returns

array
An array of stdClass objects representing services
public array
# getSimpleList( integer $client_id = null, integer $page = 1 )

Retrieves a list of all services in the system

Retrieves a list of all services in the system

Parameters

$client_id
The ID of the client whose services to retrieve (optional)
$page
The page to return results for (optional, default 1)

Returns

array
An array of stdClass objects representing each service
public array
# getAllByClient( integer $client_id, string $status = 'active', array $order_by = ['date_added' => 'DESC'], boolean $children = true, integer $package_id = null )

Returns a list of services for the given client and status unpaged

Returns a list of services for the given client and status unpaged

Parameters

$client_id
The ID of the client to select services for
$status

The status to filter by (optional, default "active"), one of:

  • active All active services
  • canceled All canceled services
  • pending All pending services
  • suspended All suspended services
  • in_review All services that require manual review before they may become pending
  • scheduled_cancellation All services scheduled to be canceled
  • all All active/canceled/pending/suspended/in_review
$order_by
The sort and order conditions (e.g. array('sort_field'=>"ASC"), optional)
$children

True to fetch all services, including child services, or false to fetch only services without a parent (optional, default true)

$package_id
The ID of the package for which to select services (optional)

Returns

array
An array of stdClass objects representing services
public integer
# getListCount( integer $client_id, string $status = 'active', boolean $children = true, integer $package_id = null, array $filters = [] )

Returns the total number of services for a client, useful in constructing pagination for the getList() method.

Returns the total number of services for a client, useful in constructing pagination for the getList() method.

Parameters

$client_id
The client ID
$status

The status type of the services to fetch (optional, default 'active'), one of:

  • active All active services
  • canceled All canceled services
  • pending All pending services
  • suspended All suspended services
  • in_review All services that require manual review before they may become pending
  • scheduled_cancellation All services scheduled to be canceled
  • all All active/canceled/pending/suspended/in_review
$children

True to fetch all services, including child services, or false to fetch only services without a parent (optional, default true)

$package_id
The ID of the package for which to select services (optional)
$filters

A list of parameters to filter by, including:

  • client_id The client ID (optional)
  • package_id The package ID (optional)
  • module_id The module ID on which to filter packages (optional)
  • package_name The (partial) name of the packages for which to fetch services (optional)
  • service_meta The (partial) value of meta data on which to filter services (optional)
  • status The status type of the services to fetch (optional, default 'active'):
    • active All active services
    • canceled All canceled services
    • pending All pending services
    • suspended All suspended services
    • in_review All services that require manual review before they may become pending
    • scheduled_cancellation All services scheduled to be canceled
    • all All active/canceled/pending/suspended/in_review

Returns

integer
The total number of services

See

Services::getList()
public array
# search( string $query, integer $page = 1, boolean $search_fields = false )

Search services

Search services

Parameters

$query
The value to search services for
$page
The page number of results to fetch (optional, default 1)
$search_fields
If true will also search service fields for the value

Returns

array
An array of services that match the search criteria
public integer
# getSearchCount( string $query, boolean $search_fields = false )

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

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

Parameters

$query
The value to search services for
$search_fields
True to search service fields for the given $query value, or false to not search them

Returns

integer
The number of results

See

Transactions::search()
public boolean
# hasParent( integer $service_id )

Determines whether a service has a parent services of the given status

Determines whether a service has a parent services of the given status

Parameters

$service_id
The ID of the service to check

Returns

boolean
True if the service has a parent, false otherwise
public boolean
# hasChildren( integer $service_id, string $status = null )

Determines whether a service has any child services of the given status

Determines whether a service has any child services of the given status

Parameters

$service_id
The ID of the service to check
$status

The status of any child services to filter on (e.g. "active", "canceled", "pending", "suspended", "in_review", or null for any status) (optional, default null)

Returns

boolean
True if the service has children, false otherwise
public array
# getAllChildren( integer $parent_service_id, string $status = 'all' )

Retrieves a list of all services that are child of the given parent service ID

Retrieves a list of all services that are child of the given parent service ID

Parameters

$parent_service_id
The ID of the parent service whose child services to fetch
$status

The status type of the services to fetch (optional, default 'all'):

  • active All active services
  • canceled All canceled services
  • pending All pending services
  • suspended All suspended services
  • in_review All services that require manual review before they may become pending
  • scheduled_cancellation All services scheduled to be canceled
  • all All active/canceled/pending/suspended/in_review

Returns

array
A list of stdClass objects representing each child service
public integer
# getAllChildrenCount( integer $parent_service_id, string $status = 'all' )

Retrieves the total number of add-on/children services for the given parent service ID

Retrieves the total number of add-on/children services for the given parent service ID

Parameters

$parent_service_id
The ID of the parent service whose add-on-children services to count
$status

The status type of the services to fetch (optional, default 'all'):

  • active All active services
  • canceled All canceled services
  • pending All pending services
  • suspended All suspended services
  • in_review All services that require manual review before they may become pending
  • scheduled_cancellation All services scheduled to be canceled
  • all All active/canceled/pending/suspended/in_review

Returns

integer
The total number of child services
public mixed
# getNextInvoiceDate( integer $service_id, string $format = 'Y-m-d H:i:s' )

Retrieves the date on which the next invoice is expected to be generated for a service

Retrieves the date on which the next invoice is expected to be generated for a service

Parameters

$service_id
The ID of the service whose next invoice date to fetch
$format
The date format to return the date in (optional, default 'Y-m-d H:i:s')

Returns

mixed
The next expected invoice date in UTC, or null if no further invoices are expected to be generated
public array
# getAllRenewing( integer $client_group_id )

Retrieves a list of services ready to be renewed for this client group

Retrieves a list of services ready to be renewed for this client group

Parameters

$client_group_id
The client group ID to fetch renewing services from

Returns

array
A list of stdClass objects representing services set ready to be renewed
public array
# getAllRenewablePaid( string $date )

Retrieves a list of renewable paid services

Retrieves a list of renewable paid services

Parameters

$date
The date after which to fetch paid renewable services

Returns

array
A list of services that have been paid and may be processed
public array
# getAllPaidPending( integer $client_group_id )

Retrieves a list of paid pending services

Retrieves a list of paid pending services

Parameters

$client_group_id
The ID of the client group whose paid pending invoices to fetch

Returns

array
A list of services that have been paid and are still pending
public array
# getAllPendingSuspension( integer $client_group_id, string $suspension_date )

Retrieves a list of services ready to be suspended

Retrieves a list of services ready to be suspended

Parameters

$client_group_id
The ID of the client group
$suspension_date
The date before which service would be considered suspended

Returns

array
A list of stdClass objects representing services pending suspension
public array
# getAllPendingUnsuspension( integer $client_group_id )

Retrieves a list of paid suspended services ready to be unsuspended. Will only return services that were automatically suspended (not manually suspended by a staff member).

Retrieves a list of paid suspended services ready to be unsuspended. Will only return services that were automatically suspended (not manually suspended by a staff member).

Parameters

$client_group_id
The ID of the client group

Returns

array
A list of stdClass objects representing services pending unsuspension
public array
# getAllPendingCancelation( )

Retrieves a list of services ready to be canceled

Retrieves a list of services ready to be canceled

Returns

array
A list of stdClass objects representing services pending cancelation
public array
# searchServiceFields( integer $module_id, string $key, string $value )

Searches services of the given module that contains the given service field key/value pair.

Searches services of the given module that contains the given service field key/value pair.

Parameters

$module_id
The ID of the module to search services on
$key
They service field key to search
$value
The service field value to search

Returns

array
An array of stdClass objects, each containing a service
public mixed
# getPricingInfo( integer $service_id, string $currency_code = null )

Fetches the pricing information for a service

Fetches the pricing information for a service

Parameters

$service_id
The ID of the service whose pricing info te fetch
$currency_code

The ISO 4217 currency code to convert pricing to (optional, defaults to service's currency)

Returns

mixed
An stdClass object representing service pricing fields, or false if none exist
public mixed
# get( integer $service_id )

Fetch a single service, including service field data

Fetch a single service, including service field data

Parameters

$service_id
The ID of the service to fetch

Returns

mixed
A stdClass object representing the service, false if no such service exists
public mixed
# getPackagePricing( integer $pricing_id )

Get package pricing

Get package pricing

Parameters

$pricing_id

Returns

mixed
stdClass object representing the package pricing, false otherwise
public integer
# add( array $vars, array $packages = null, boolean $notify = false )

Adds a new service to the system

Adds a new service to the system

Parameters

$vars

An array of service info including:

  • parent_service_id The ID of the service this service is a child of (optional)
  • package_group_id The ID of the package group this service was added from (optional)
  • pricing_id The package pricing schedule ID for this service
  • client_id The ID of the client to add the service under
  • module_row_id The module row to add the service under (optional, default module will decide)
  • coupon_id The ID of the coupon used for this service (optional)
  • qty The quanity consumed by this service (optional, default 1)
  • override_price The price to set for this service, overriding the package pricing value for the selected term (optional, default null)
  • override_currency The currency to set for this service, overriding the package pricing value for the selected term (optional, default null)
  • status The status of this service (optional, default 'pending'):
    • active
    • canceled
    • pending
    • suspended
    • in_review
  • suspension_reason The reason a service is being suspended
  • date_added The date this service is added (default to today's date UTC)
  • date_renews The date the service renews (optional, default calculated by package term)
  • date_last_renewed The date the service last renewed (optional)
  • date_suspended The date the service was last suspended (optional)
  • date_canceled The date the service was last canceled (optional)
  • use_module Whether or not to use the module when creating the service ('true','false', default 'true', forced 'false' if status is 'pending' or 'in_review')
  • configoptions An array of key/value pairs of package options where the key is the package option ID and the value is the option value (optional)
    • Any other service field data to pass to the module
$packages

An array of packages ordered along with this service to determine if the given coupon may be applied given in one of the following formats:

  • A numerically indexed array of package IDs
  • An array of package IDs and pricing IDs [packageID => pricingID]
$notify

True to notify the client by email regarding this service creation, false to not send any notification (optional, default false)

Returns

integer
The ID of this service, void if error
public integer
# edit( integer $service_id, array $vars, boolean $bypass_module = false, boolean $notify = false )

Edits a service. Only one module action may be performend at a time. For example, you can't change the pricing_id and edit the module service fields in a single request.

Edits a service. Only one module action may be performend at a time. For example, you can't change the pricing_id and edit the module service fields in a single request.

Parameters

$service_id
The ID of the service to edit
$vars

An array of service info:

  • parent_service_id The ID of the service this service is a child of
  • package_group_id The ID of the package group this service was added from
  • pricing_id The package pricing schedule ID for this service
  • client_id The ID of the client this service belongs to
  • module_row_id The module row to add the service under
  • coupon_id The ID of the coupon used for this service
  • qty The quanity consumed by this service
  • override_price The price to set for this service, overriding the package pricing value for the selected term (optional, default null)
  • override_currency The currency to set for this service, overriding the package pricing value for the selected term (optional, default null)
  • status The status of this service:
    • active
    • canceled
    • pending
    • suspended
    • in_review
  • suspension_reason The reason a service is being suspended
  • date_added The date this service is added
  • date_renews The date the service renews
  • date_last_renewed The date the service last renewed
  • date_suspended The date the service was last suspended
  • date_canceled The date the service was last canceled
  • use_module Whether or not to use the module for this request ('true','false', default 'true')
  • configoptions An array of key/value pairs of package options where the key is the package option ID and the value is the option value. Defining the 'configoptions' key will update all config options. Always include all config options if setting any, or changing the pricing_id. (optional)
    • Any other service field data to pass to the module
$bypass_module

$vars['use_module'] notifies the module of whether or not it should internally use its module connection to process the request, however in some instances it may be necessary to prevent the module from being notified of the request altogether. If true, this will prevent the module from being notified of the request.

$notify
If true and the service is set to active will send the service activation notification

Returns

integer
The ID of this service, void if error
public
# delete( integer $service_id, integer $validate = true )

Permanently deletes a pending service from the system

Permanently deletes a pending service from the system

Parameters

$service_id
The ID of the pending service to delete
$validate

True to validate whether the service is capable of being deleted, or false to permanently delete its record regardless (optional, default true)

public
# cancel( integer $service_id, array $vars )

Schedule a service for cancellation. All cancellations requests are processed by the cron.

Schedule a service for cancellation. All cancellations requests are processed by the cron.

Parameters

$service_id
The ID of the service to schedule cancellation
$vars

An array of service info including:

  • date_canceled The date the service is to be canceled. Possible values:
    • 'end_of_term' Will schedule the service to be canceled at the end of the current term
    • date greater than now will schedule the service to be canceled on that date
    • date less than now will immediately cancel the service
  • use_module Whether or not to use the module when canceling the service, if canceling now ('true','false', default 'true')
  • reapply_payments True or false, default true. When the service is canceled, line items may be removed from related invoice(s). Any payments already applied to these invoices will be unapplied and then reapplied to cover the cost of the remaining line items.
  • notify_cancel 'true' to notify the client by email regarding this service cancellation, 'false' to not send any notification
  • cancellation_reason The reason for the service cancellation
public
# unCancel( integer $service_id )

Removes the scheduled cancellation for the given service

Removes the scheduled cancellation for the given service

Parameters

$service_id
The ID of the service to remove scheduled cancellation from
public
# suspend( integer $service_id, array $vars = [] )

Suspends a service

Suspends a service

Parameters

$service_id
The ID of the service to suspend
$vars

An array of info including:

  • use_module Whether or not to use the module when suspending the service ('true','false', default 'true')
  • staff_id The ID of the staff member that issued the service suspension
  • suspension_reason The reason for the service suspension
public
# unsuspend( integer $service_id, array $vars = [] )

Unsuspends a service

Unsuspends a service

Parameters

$service_id
The ID of the service to unsuspend
$vars

An array of info including:

  • use_module Whether or not to use the module when unsuspending the service ('true','false', default 'true')
  • staff_id The ID of the staff member that issued the service unsuspension
public
# renew( integer $service_id )

Processes the renewal for the given service by contacting the module (if supported by the module), to let it know that the service should be renewed. Note: This method does not affect the renew date of the service in Blesta, it merely notifies the module; this action takes place after a service has been paid not when its renew date is bumped.

Processes the renewal for the given service by contacting the module (if supported by the module), to let it know that the service should be renewed. Note: This method does not affect the renew date of the service in Blesta, it merely notifies the module; this action takes place after a service has been paid not when its renew date is bumped.

Parameters

$service_id
The ID of the service to process the renewal for
public array
# getStatusTypes( )

Retrieves a list of service status types

Retrieves a list of service status types

Returns

array
Key=>value pairs of status types
public array
# getActions( string $current_status = null )

Returns all action options that can be performed for a service.

Returns all action options that can be performed for a service.

Parameters

$current_status

Set to filter actions that may be performed if the service is in the given state options include:

  • active
  • suspended
  • canceled

Returns

array

An array of key/value pairs where each key is the action that may be performed and the value is the friendly name for the action

public
# setFields( integer $service_id, array $vars )

Updates the field data for the given service, removing all existing data and replacing it with the given data

Updates the field data for the given service, removing all existing data and replacing it with the given data

Parameters

$service_id
The ID of the service to set fields on
$vars

A numerically indexed array of field data containing:

  • key The key for this field
  • value The value for this key
  • encrypted Whether or not this field should be encrypted ('true', 'false', default 'false')
public
# addField( integer $service_id, array $vars )

Adds a service field for a particular service

Adds a service field for a particular service

Parameters

$service_id
The ID of the service to add to
$vars

An array of service field info including:

  • key The name of the value to add
  • value The value to add
  • encrypted Whether or not to encrypt the value when storing ('true', 'false', default 'false')
public
# editField( integer $service_id, array $vars )

Edit a service field for a particular service

Edit a service field for a particular service

Parameters

$service_id
The ID of the service to edit
$vars

An array of service field info including:

  • key The name of the value to edit
  • value The value to update with
  • encrypted Whether or not to encrypt the value when storing ('true', 'false', default 'false')
public array
# getOptions( integer $service_id )

Returns the configurable options for the service

Returns the configurable options for the service

Parameters

$service_id

Returns

array
An array of stdClass objects, each representing a service option
public array
# getWelcomeEmailTags( )

Returns all default welcome email tags, which are set into the email that is delivered when a service is provisioned.

Returns all default welcome email tags, which are set into the email that is delivered when a service is provisioned.

Returns

array

A multi-dimensional array of tags where the first dimension is the category and the second is a numeric array of tags

public string
# getNextRenewDate( string $last_renew_date, integer $term, string $period, string $format = 'Y-m-d H:i:s', integer $pro_rata_day = null )

Calculates the next renew date using a given date, term, and period

Calculates the next renew date using a given date, term, and period

Parameters

$last_renew_date

The date the service last renewed. If never renewed this should be the service add date

$term
The term value relating to the given period
$period
The period (day, week, month, year, onetime)
$format
The date format to return the date in (optional, default 'Y-m-d H:i:s')
$pro_rata_day

The day of the month to prorate to. Only set this value to fetch the prorated renew date. Only used for month/year periods. Ignored if the $last_renew_date is on the $pro_rata_day. (optional, default null)

Returns

string

The date the service renews in UTC. In the event that the service does not renew or the renew date can not be calculated null is returned

public array
# buildServiceCouponLineItems( array $services, string $default_currency, array & $coupons, boolean $services_renew = false, array $line_items = [] )

Retrieves a list of coupons to be applied to an invoice for services, assuming the services given are for a single client only

Retrieves a list of coupons to be applied to an invoice for services, assuming the services given are for a single client only

Parameters

$services
An array of stdClass objects, each representing a service
$default_currency
The ISO 4217 currency code for the client
$coupons
A reference to coupons that will need to be incremented
$services_renew

True if all of the given $services are renewing services, or false if all $services are new services (optional, default false)

$line_items

An array of line items that the coupon will be applying toward (optional but highly recommended):

  • service_id The ID of the service, matching one of the given $services
  • description The line item description
  • qty The line item quantity
  • amount The line item amount
  • tax Whether or not the line item is taxable
  • service_option_id The ID of the service option the line item represents, if any
  • setup_fee Whether or not the line item is a setup fee
  • after_cutoff Whether or not the line item is after the cutoff date

Returns

array
An array of coupon line items to append to an invoice
public boolean|Blesta\Core\Pricing\Presenter\Type\ServicePresenter
# getPresenter( integer $service_id, array $options )

Retrieves a presenter representing a set of items, discounts, and taxes for the service

Retrieves a presenter representing a set of items, discounts, and taxes for the service

Parameters

$service_id
The ID of the service whose renewal pricing to fetch
$options
An array of options used to construct the presenter

Returns

boolean|Blesta\Core\Pricing\Presenter\Type\ServicePresenter
The presenter, otherwise false
public boolean|Blesta\Core\Pricing\Presenter\Type\ServiceDataPresenter
# getDataPresenter( integer $client_id, array $vars, array $options )

Retrieves a presenter representing a set of items, discounts, and taxes for service data

Retrieves a presenter representing a set of items, discounts, and taxes for service data

Parameters

$client_id
The ID of the client the service data is for
$vars

An array of input representing the new service data:

  • configoptions An array of key/value pairs where each key is an option ID and each value is the selected value
  • pricing_id The ID of the new pricing selected
  • qty The service quantity
  • coupon_code A new coupon code to use
  • parent_service_id The ID of this service's parent
$options
An array of options used to construct the presenter

Returns

boolean|Blesta\Core\Pricing\Presenter\Type\ServiceDataPresenter
The presenter, otherwise false
public array
# getServiceItems( array $vars, array $options, array & $line_totals, string $currency = null, string $from_currency = null )

Gets a list of items based on the service data given and updates line totals accordingly

Gets a list of items based on the service data given and updates line totals accordingly

Parameters

$vars

A list of service data:

  • client_id The ID of the client this service is for
  • configoptions An array of key/value pairs where each key is an option ID and each value is the selected value
  • pricing_id The ID of the new pricing selected
  • qty The service quantity
  • coupon_code A new coupon code to use
  • parent_service_id The ID of this service's parent
$options

A list of options for the pricing presenter:

  • recur Boolean true/false. Whether the pricing items are recurring, or if they are being added for the first time (default false)
  • includeSetupFees Whether to include applicable setup fees
  • prorateStartDate Will prorate the service from this date to the prorateEndDate
  • prorateEndDate Will override the otherwise calculated prorate end date
$line_totals

A list of totals to be updated:

  • subtotal
  • total
  • total_without_exclusive_tax
  • tax A list of applicable tax totals
  • discount
$currency
The currency to convert the total to
$from_currency
The currency to convert the total from

Returns

array
A list of invoice items for the service
public float
# getRenewalPrice( integer $service_id, string $currency = null )

Retrieves the next expected renewal price of a service based on its current configuration, options, and pricing

Retrieves the next expected renewal price of a service based on its current configuration, options, and pricing

Parameters

$service_id
The ID of the service whose renewal pricing to fetch
$currency
The ISO 4217 3-character currency code to convert the total to

Returns

float
The next expected renewal price
protected array
# getFields( integer $service_id )

Return all field data for the given service, decrypting fields where neccessary

Return all field data for the given service, decrypting fields where neccessary

Parameters

$service_id
The ID of the service to fetch fields for

Returns

array

An array of stdClass objects representing fields, containing:

  • key The service field name
  • value The value for this service field
  • encrypted Whether or not this field was originally encrypted (1 true, 0 false)
public boolean
# validateStatus( string $status )

Validates a service's 'status' field

Validates a service's 'status' field

Parameters

$status
The status type

Returns

boolean
True if $status is valid, false otherwise
public boolean
# validateUseModule( string $use_module )

Validates whether to use a module when adding/editing a service

Validates whether to use a module when adding/editing a service

Parameters

$use_module

Returns

boolean
True if validated, false otherwise
public
# validateEncrypted( string $encrypted )

Validates a service field's 'encrypted' field

Validates a service field's 'encrypted' field

Parameters

$encrypted
Whether or not to encrypt
public boolean
# validateHasChildren( integer $service_id, string $status = null )

Validates whether the given service has children NOT of the given status

Validates whether the given service has children NOT of the given status

Parameters

$service_id
The ID of the parent service to validate
$status

The status of children services to ignore (e.g. "canceled") (optional, default null to not ignore any child services)

Returns

boolean
True if the service has children not of the given status, false otherwise
public array
# getFieldRules( )

Retrieves the rule set for adding/editing service fields

Retrieves the rule set for adding/editing service fields

Returns

array
The rules
public boolean
# canSyncToParent( stdClass $pricing, stdClass $parent_pricing, integer $client_group_id )

Determines if a service should be prorated to match its parent

Determines if a service should be prorated to match its parent

Parameters

$pricing
The new service pricing
$parent_pricing
The parent service pricing
$client_group_id
The ID of the client group this service is under

Returns

boolean
Whether to synchronize a service with its parent
public string
# getChildRenewDate( stdClass $pricing, stdClass $parent_pricing, integer $client_group_id )

Determines the date a service should be prorated to so it matches its parent

Determines the date a service should be prorated to so it matches its parent

Parameters

$pricing
The new service pricing
$parent_pricing
The parent service pricing
$client_group_id
The ID of the client group this service is under

Returns

string
The expected renew date of the new service, or false if not being synchronized
public boolean
# isServiceOptionValueInUse( integer $option_value_id, integer $option_pricing_id = null )

Determines whether the given option value is currently in use by any non-cancelled service

Determines whether the given option value is currently in use by any non-cancelled service

Parameters

$option_value_id
The package option value ID
$option_pricing_id
The package option pricing ID

Returns

boolean
True if the service option value is in use by at least one service, or false otherwise
public boolean
# isInstanceOf( mixed $field, mixed $class )

Checks if the given $field is a reference of $class

Checks if the given $field is a reference of $class

Parameters

$field
The field whose instance to check
$class
The class or instance to check against

Returns

boolean
True if the $field is an instance of $class, otherwise false
public array
# validate( array $vars, array $packages = null )

Performs all validation necessary before adding a service

Performs all validation necessary before adding a service

Parameters

$vars

An array of service info including:

  • parent_service_id The ID of the service this service is a child of (optional)
  • package_group_id The ID of the package group this service was added from (optional)
  • pricing_id The package pricing schedule ID for this service
  • client_id The ID of the client to add the service under
  • module_row_id The module row to add the service under (optional, default is first available)
  • coupon_id The ID of the coupon used for this service (optional)
  • qty The quanity consumed by this service (optional, default 1)
  • status The status of this service ('active','canceled','pending','suspended', default 'pending')
  • date_added The date this service is added (default to today's date UTC)
  • date_renews The date the service renews (optional, default calculated by package term)
  • date_last_renewed The date the service last renewed (optional)
  • date_suspended The date the service was last suspended (optional)
  • date_canceled The date the service was last canceled (optional)
  • use_module Whether or not to use the module when creating the service ('true','false', default 'true')
  • configoptions An array of key/value pairs of package options where the key is the package option ID and the value is the option value (optional)
    • Any other service field data to pass to the module
$packages

An array of packages ordered along with this service to determine if the given coupon may be applied given in one of the following formats:

  • A numerically indexed array of package IDs
  • An array of package IDs and pricing IDs [packageID => pricingID]

Returns

array
$vars An array of $vars, modified by error checking

See

Services::validateService()
public
# validateService( stdClass $package, array $vars )

Validates service info, including module options, for creating a service. An alternative to Services::validate() Sets Input errors on failure

Validates service info, including module options, for creating a service. An alternative to Services::validate() Sets Input errors on failure

Parameters

$package
A stdClass object representing the package for the service
$vars

An array of values to be evaluated, including:

  • invoice_method The invoice method to use when creating the service, options are:
    • create Will create a new invoice when adding this service
    • append Will append this service to an existing invoice (see 'invoice_id')
    • none Will not create any invoice
  • invoice_id The ID of the invoice to append to if invoice_method is set to 'append'
  • pricing_id The ID of the package pricing to use for this service
  • configoptions An array of key/value pairs of package options where the key is the package option ID and the value is the option value (optional)
    • Any other service field data to pass to the module

See

Services::validate()
public
# validateServiceEdit( integer $service_id, array $vars, boolean $bypass_module = false )

Performs all validation necessary for updating a service. Sets Input errors on failure

Performs all validation necessary for updating a service. Sets Input errors on failure

Parameters

$service_id
The ID of the service to validate
$vars

An array of key/value pairs to be evaluated:

  • configoptions An array of key/value pairs of package options where the key is the package option ID and the value is the option value (optional)
$bypass_module
Whether or not to ignore the module service edit validation
public boolean
# validateCoupon( integer $coupon_id, array $packages = null )

Verifies if the given coupon ID can be applied to the requested packages

Verifies if the given coupon ID can be applied to the requested packages

Parameters

$coupon_id
The ID of the coupon to validate
$packages

An array of pacakges to confirm the coupon can be applied given in one of the following formats:

  • A numerically indexed array of package IDs
  • An array of package IDs and pricing IDs [packageID => pricingID]

Returns

boolean
True if the coupon can be applied, false otherwise
public boolean
# validateDateCanceled( string $date )

Verifies that the given date value is valid for a cancel date

Verifies that the given date value is valid for a cancel date

Parameters

$date
The date to cancel a service or "end_of_term" to cancel at the end of the term

Returns

boolean
True if $date is valid, false otherwise
public boolean
# validateDateRenews( string $renew_date, string $last_renew_date = null )

Verifies that the given renew date is greater than the last renew date (if available)

Verifies that the given renew date is greater than the last renew date (if available)

Parameters

$renew_date
The date a service should renew
$last_renew_date
The date a service last renewed

Returns

boolean
True if renew date is valid, false otherwise
public boolean
# validatePriceOverride( float $price )

Verifies that the given price override is in a valid format

Verifies that the given price override is in a valid format

Parameters

$price
The price override

Returns

boolean
True if the price is valid, false otherwise
public boolean
# validateOverrideFields( mixed $price, mixed $currency )

Verifies that the given price and currency fields have been set together

Verifies that the given price and currency fields have been set together

Parameters

$price
The price override, or null
$currency
The currency override, or null

Returns

boolean
True if the price and currency have been set properly together, or false otherwise
public boolean
# validatePricingWithOverrides( integer $pricing_id, integer $service_id, float $price, string $currency )

Verifies that the given service and pricing ID are valid with price overrides

Verifies that the given service and pricing ID are valid with price overrides

Parameters

$pricing_id
The ID of the pricing term
$service_id
The ID of the service being updated
$price
The price override amount
$currency
The price override currency

Returns

boolean
True if the pricing ID may be set for this service given the price overrides, or false otherwise
public boolean
# validateAllowed( integer $client_id, integer $pricing_id )

Verifies that the client has access to the package for the given pricing ID

Verifies that the client has access to the package for the given pricing ID

Parameters

$client_id
The ID of the client
$pricing_id
The ID of the package pricing

Returns

boolean
True if the client can add the package, false otherwise
public boolean
# validateConfigOptions( array $config_options, integer $pricing_id, array $current_options = [] )

Verifies that the given package options are valid

Verifies that the given package options are valid

Parameters

$config_options

An array of key/value pairs where each key is the package option ID and each value is the option value

$pricing_id
The package pricing ID
$current_options

An array of key/value pairs currently on the service where each key is the package option ID and each value is the option value

Returns

boolean
True if valid, false otherwise
public boolean
# decrementQuantity( integer $quantity, integer $pricing_id, boolean $check_only = true, mixed $current_qty = null )

Decrements the package quantity if $check_only is false, otherwise only validates the quantity could be decremented.

Decrements the package quantity if $check_only is false, otherwise only validates the quantity could be decremented.

Parameters

$quantity
The quantity requested
$pricing_id
The pricing ID
$check_only
True to only verify the quantity could be decremented, false otherwise
$current_qty
The currenty quantity being consumed by the service

Returns

boolean
true if the quantity could be (not necessarily has been) consumed, 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