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 Coupons

Coupon management

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

Methods summary

public
# __construct( )

Initialize Coupons

Initialize Coupons

Overrides

AppModel::__construct
public mixed
# getList( integer $company_id, integer $page = 1, string $order_by = array('code'=>"ASC") )

Fetches a list of all coupons for a given company

Fetches a list of all coupons for a given company

Parameters

$company_id
integer
$company_id The ID of the company to fetch coupons for
$page
integer
$page The page to return results for (optional, default 1)
$order_by
string
$order_by The sort and order conditions (e.g. array('sort_field'=>"ASC"), optional)

Returns

mixed
An array of stdClass objects representing coupons, false if no coupons found
public integer
# getListCount( integer $company_id )

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

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

Parameters

$company_id
integer
$company_id The ID of the company to fetch coupons for

Returns

integer
The total number of coupons

See

Coupons::getList()
public array
# getCouponAmounts( integer $coupon_id )

Fetches a list of currencies and amounts associated with a given coupon

Fetches a list of currencies and amounts associated with a given coupon

Parameters

$coupon_id
integer
$coupon_id The ID of the coupon whose amounts to fetch

Returns

array
An array of objects representing each coupon amount
public mixed
# get( integer $coupon_id )

Fetches a coupon using the given $coupon_id

Fetches a coupon using the given $coupon_id

Parameters

$coupon_id
integer
$coupon_id The ID of the coupon to fetch

Returns

mixed
A stdClass object representing the coupon, false if no such coupon exists
public mixed
# getByCode( string $code )

Retrieves a coupon by its code

Retrieves a coupon by its code

Parameters

$code
string
$code The coupon code representing the coupon to fetch

Returns

mixed
A stdClass object representing the coupon, or false if no such coupon exists
public mixed
# getForPackages( string $code = null, string $coupon_id = null, array $packages = null )

Fetches a coupon using the given code or coupon ID. Only returns coupons that are active and capable of being used for the current company.

Fetches a coupon using the given code or coupon ID. Only returns coupons that are active and capable of being used for the current company.

Parameters

$code
string
$code The coupon code to fetch
$coupon_id
string
$coupon_id The coupon ID to fetch
$packages
array
An array of package IDs to attempt to use with the coupon. If the coupon is inclusive all packages configured for the coupon must be present.

Returns

mixed
A stdClass object representing the coupon, false if no such coupon exists of the coupon is no longer valid
public mixed
# getRecurring( integer $coupon_id, string $currency, string $date )

Retrieves the given coupon and the recurring coupon amount iff it recurs and applies to the given currency at the given date

Retrieves the given coupon and the recurring coupon amount iff it recurs and applies to the given currency at the given date

Parameters

$coupon_id
integer
$coupon_id The ID of the coupon to fetch
$currency
string
$currency The ISO 4217 currency code
$date
string
$date The date at which to check that the coupon will apply

Returns

mixed
An stdClass object representing the coupon and the recurring amount, or false otherwise
public integer
# add( array $vars )

Creates a new coupon

Creates a new coupon

Parameters

$vars
array
$vars An array of coupon information including: - code The coupon code - company_id The company ID this coupon belongs to - used_qty The number of times this coupon has been used (optional, default 0) - max_qty The maximum number of times this coupon can be used (optional, default 0 for unlimited) - start_date The date this coupon goes into effect (optional) - end_date The date this coupon is no longer effective (optional) - status The status of the coupon, 'active' or 'inactive' (optional, default 'active') - type The type of coupon, 'inclusive' must order all packages in package for coupon to apply, 'exclusive' no restriction on coupon application (optional, default 'exclusive') - recurring Allows the coupon to be applied every time the service renews, restrictions on start_date/end_date/used_qty/max_qty/type do not apply. If the coupon was applied originally, it will continue to be applied so long as status is 'active' and the package is still tied to this coupon. - limit_recurring Allows the coupon to be used again every time a renewing service that uses it renews (1 to increase the used quantity each time a renewing service renews, 0 for renewing services to use this coupon only once. optional, default 0) - packages A numerically indexed array containing package IDs this coupon applies to: - amounts An array of discounts for this coupon containing (only one per currency): - currency The ISO 4217 currency code - amount The amount of the discount - type The type of discount 'amount' a currency amount, 'percent' a percentage (optional, default 'percent')

Returns

integer
The ID code for this coupon
public integer
# edit( integer $coupon_id, array $vars )

Updates an existing coupon

Updates an existing coupon

Parameters

$coupon_id
integer
$coupon_id The ID of the coupon to update
$vars
array
$vars An array of coupon information including: - code The coupon code - company_id The ID of the company this coupon belongs to - used_qty The number of times this coupon has been used (optional, default 0) - max_qty The maximum number of times this coupon can be used (optional, default 0 for unlimited) - start_date The date this coupon goes into effect (optional) - end_date The date this coupon is no longer effective (optional) - status The status of the coupon, 'active' or 'inactive' (optional, default 'active') - type The type of coupon, 'inclusive' must order all packages in package for coupon to apply, 'exclusive' no restriction on coupon application (optional, default 'exclusive') - recurring Allows the coupon to be applied every time the service renews, restrictions on start_date/end_date/used_qty/max_qty/type do not apply. If the coupon was applied originally, it will continue to be applied so long as status is 'active' and the package is still tied to this coupon. - limit_recurring Allows the coupon to be used again every time a renewing service that uses it renews (1 to increase the used quantity each time a renewing service renews, 0 for renewing services to use this coupon only once. optional, default 0) - packages A numerically indexed array containing package IDs this coupon applies to: - amounts An array of discounts for this coupon containing (only one per currency): - currency The ISO 4217 currency code - amount The amount of the discount - type The type of discount 'amount' a currency amount, 'percent' a percentage (optional, default 'percent')

Returns

integer
The ID code for this coupon
public
# delete( integer $coupon_id )

Permanently removes the coupon from the system

Permanently removes the coupon from the system

Parameters

$coupon_id
integer
$coupon_id The ID of the coupon to delete
public
# incrementUsage( integer $coupon_id )

Increments the used quantity on the given coupon

Increments the used quantity on the given coupon

Parameters

$coupon_id
integer
$coupon_id The ID of the coupon whose used quantity to increment
public array
# getTypes( )

Retrieves a list of coupon types

Retrieves a list of coupon types

Returns

array
Key=>value pairs of coupon types
public array
# getAmountTypes( )

Retrieves a list of coupon amount types

Retrieves a list of coupon amount types

Returns

array
Key=>value pairs of coupon amount types
public boolean
# validateStatus( string $status )

Validates a coupon's 'status' field

Validates a coupon's 'status' field

Parameters

$status
string
$status The status to check

Returns

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

Validates a coupon's 'type' field

Validates a coupon's 'type' field

Parameters

$type
string
$type The type to check

Returns

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

Validates a coupon amount's 'type' field

Validates a coupon amount's 'type' field

Parameters

$type
string
$type The type to check

Returns

boolean
True if validated, false otherwise
public boolean
# validateAmountDuplicates( array $vars )

Validates an array of coupon discounts to check for duplicate currencies.

Validates an array of coupon discounts to check for duplicate currencies.

Parameters

$vars
array
$vars An indexed array of discount options including: - currency The currency code as defined in ISO 4217 - type The type of discount ("amount" or "percent") - amount The numeric amount of this discount

Returns

boolean
True if each currency is unique, false otherwise
public boolean
# validateInclusiveRecurring( array $amounts, string $recurring, string $type )

Validates that inclusive recurring coupons of discount type "Amount" do not exist. This prohibits the possibility of amount discounts being applied to each service with a recurring coupon.

Validates that inclusive recurring coupons of discount type "Amount" do not exist. This prohibits the possibility of amount discounts being applied to each service with a recurring coupon.

Parameters

$amounts
array
$amounts An indexed array of discount options including: - currency The currency code as defined in ISO 4217 - type The type of discount ("amount" or "percent") - amount The numeric amount of this discount
$recurring
string
$recurring Whether this coupon is set to be recurring (1 or 0)
$type
string
$type The coupon type ("inclusive" or "exclusive")

Returns

boolean
True if this coupon is not set as an inclusive recurring coupon that contains any discounts of type "Amount", or false otherwise
public boolean
# validateUniqueCode( string $coupon_code, mixed $coupon_id = null )

Validates whether the given coupon code is currently in use

Validates whether the given coupon code is currently in use

Parameters

$coupon_code
string
$coupon_code The coupon code to validate
$coupon_id
mixed
$coupon_id The ID of the coupon the given coupon code must represent, or null to not require any

Returns

boolean
True if the given coupon code is unique, 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 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