Pricings extends AppModel
Pricing management
Table of Contents
Methods
| __construct() | Initialize Pricings |
| add() | Adds a pricing for the given company |
| checkInUse() | Checks if the pricing it's in use |
| delete() | Permanently removes a pricing from the system. |
| edit() | Updates a pricing |
| formatTerm() | Formats the pricing term |
| get() | Fetches the pricing |
| getAll() | Fetches all pricing for a given company |
| getList() | Fetches a list of pricing for a given company |
| getListCount() | Return the total number of pricings returned from Pricings::getList(), useful in constructing pagination for the getList() method. |
| getPeriods() | Retrieves a list of pricing periods |
| validatePeriod() | Validates the pricing 'period' field type |
| validateTerm() | Validates that the term is valid for the period. That is, the term must be > 0 if the period is something other than "onetime". |
| getRules() | Fetches the rules for adding/editing pricing |
Methods
__construct()
Initialize Pricings
public
__construct() : mixed
add()
Adds a pricing for the given company
public
add(array<string|int, mixed> $vars) : int
Parameters
- $vars : array<string|int, mixed>
-
An array of pricing info including:
- company_id The ID of the company to add the pricing for
- 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)
- price_renews The renewal price of this term (optional, default null)
- price_transfer The transfer price of this term (optional, default null)
- setup_fee The setup fee for this pricing (optional, default 0.00)
- cancel_fee The cancelation fee for this pricing (optional, default 0.00)
- currency The ISO 4217 currency code for this pricing (optional, default USD)
Return values
int —The ID of the pricing record added, void on error
checkInUse()
Checks if the pricing it's in use
public
checkInUse(mixed $value, string $var, int $pricing_id) : mixed
Parameters
- $value : mixed
-
The value of the variable to validate
- $var : string
-
The name of the variable to validate
- $pricing_id : int
delete()
Permanently removes a pricing from the system.
public
delete(int $pricing_id) : mixed
Parameters
- $pricing_id : int
-
The pricing ID to delete
edit()
Updates a pricing
public
edit(int $pricing_id, array<string|int, mixed> $vars) : mixed
Parameters
- $pricing_id : int
-
The ID of the pricing to edit
- $vars : array<string|int, mixed>
-
An 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)
- price_renews The renewal price of this term (optional, default null)
- price_transfer The transfer price of this term (optional, default null)
- setup_fee The setup fee for this pricing (optional, default 0.00)
- cancel_fee The cancelation fee for this pricing (optional, default 0.00)
- currency The ISO 4217 currency code for this pricing (optional, default USD)
formatTerm()
Formats the pricing term
public
formatTerm(int $term, string $period) : mixed
Parameters
- $term : int
-
The term length
- $period : string
-
The period of this term
Return values
mixed —The term formatted in accordance to the period, if possible
get()
Fetches the pricing
public
get(int $pricing_id) : mixed
Parameters
- $pricing_id : int
-
The ID of the pricing to fetch
Return values
mixed —A stdClass object representing the pricing, false if no such pricing exists
getAll()
Fetches all pricing for a given company
public
getAll(int $company_id) : array<string|int, mixed>
Parameters
- $company_id : int
-
The company ID
Return values
array<string|int, mixed> —An array of stdClass objects representing each pricing
getList()
Fetches a list of pricing for a given company
public
getList(int $company_id[, int $page = 1 ][, array<string|int, mixed> $order_by = ['period' => 'asc', 'term' => 'asc'] ]) : array<string|int, mixed>
Parameters
- $company_id : int
-
The company ID to fetch pricing for
- $page : int = 1
-
The page to return results for
- $order_by : array<string|int, mixed> = ['period' => 'asc', 'term' => 'asc']
-
The sort and order conditions (e.g. array('sort_field'=>"ASC"), optional)
Return values
array<string|int, mixed> —An array of objects, each representing a pricing
getListCount()
Return the total number of pricings returned from Pricings::getList(), useful in constructing pagination for the getList() method.
public
getListCount(int $company_id) : int
Parameters
- $company_id : int
-
The company ID to fetch pricings for
Tags
Return values
int —The total number of pricings
getPeriods()
Retrieves a list of pricing periods
public
getPeriods([bool $plural = false ]) : array<string|int, mixed>
Parameters
- $plural : bool = false
-
True to return language for plural periods, false for singular
Return values
array<string|int, mixed> —Key=>value pairs of pricing periods
validatePeriod()
Validates the pricing 'period' field type
public
validatePeriod(string $period) : bool
Parameters
- $period : string
-
The period type
Return values
bool —True if validated, false otherwise
validateTerm()
Validates that the term is valid for the period. That is, the term must be > 0 if the period is something other than "onetime".
public
validateTerm(int $term, string $period) : bool
Parameters
- $term : int
-
The Term to validate
- $period : string
-
The period to validate the term against
Return values
bool —True if validated, false otherwise
getRules()
Fetches the rules for adding/editing pricing
private
getRules(array<string|int, mixed> $vars[, bool $edit = false ][, int $pricing_id = null ]) : array<string|int, mixed>
Parameters
- $vars : array<string|int, mixed>
-
The input vars
- $edit : bool = false
-
True to fetch the edit rules, or false for the add rules
- $pricing_id : int = null
-
The ID of the pricing being updated (on edit)
Return values
array<string|int, mixed> —The pricing rules