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 Clients

Client management

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

Methods summary

public
# __construct( )

Initialize Clients

Initialize Clients

Overrides

AppModel::__construct
public stdClass
# create( array $vars )

Creates a client account including user login, and contact. Sends client welcome email if configured to do so.

Creates a client account including user login, and contact. Sends client welcome email if configured to do so.

Returns

stdClass
A stdClass object representing the client, void on error

See

Users::add()
Clients::add()
Contacts::add()

Vars

An array of client info including: - username The username for this user. Must be unique across all companies for this installation. - new_password The password for this user - confirm_password The password for this user - client_group_id The client group this user belongs to - status The status of this client ('active', 'inactive',' 'fraud') (optional, default active) - first_name The first name of this contact - last_name The last name of this contact - title The business title for this contact (optional) - company The company/organization this contact belongs to (optional) - email This contact's email address - address1 This contact's address (optional) - address2 This contact's address line two (optional) - city This contact's city (optional) - state The 3-character ISO 3166-2 subdivision code, requires country (optional) - zip The zip/postal code for this contact (optional) - country The 3-character ISO 3166-1 country code, required if state is given (optional) - numbers An array of number data including (optional): - number The phone number to add - type The type of phone number 'phone', 'fax' (optional, default 'phone') - location The location of this phone line 'home', 'work', 'mobile' (optional, default 'home') - custom An array of custom fields in key/value format where each key is the custom field ID and each value is the value - settings An array of client settings including: - default_currency - language - username_type - tax_id - tax_exempt - send_registration_email 'true' to send client welcome email (default), 'false' otherwise
public integer
# add( array $vars )

Add a client to the clients table

Add a client to the clients table

Parameters

$vars
array
$vars An array of client info including: - id_code The client's reference ID code (for display purposes) - user_id The client's user ID - client_group_id The client group this user belongs to - status The status of this client ('active', 'inactive',' 'fraud') (optional, default active)

Returns

integer
The client ID, or void on faliure
public
# edit( integer $client_id, array $vars )

Edit a client from the clients table

Edit a client from the clients table

Parameters

$client_id
integer
$client_id The client's ID
$vars
array
$vars An array of client info (all fields optional) including: - id_code The client's reference ID code (for display purposes) - user_id The client's user ID - client_group_id The client group this user belongs to - status The status of this client ('active', 'inactive',' 'fraud')
public
# delete( integer $client_id )

Permanently removes a client from the clients table. CAUTION: Deleting a client will cause all invoices, services, transactions, etc. attached to that client to become inaccessible.

Permanently removes a client from the clients table. CAUTION: Deleting a client will cause all invoices, services, transactions, etc. attached to that client to become inaccessible.

Parameters

$client_id
integer
$client_id The client ID to permanently remove from the system
public integer
# addCustomField( array $vars )

Add custom client field

Add custom client field

Parameters

$vars
array
An array of custom field info including: - client_group_id The client group ID the field will belong to (optional, default null) - name The name of the custom field - is_lang Whether or not 'name' is a language definition (optional, default 0) - type The type of field ('text','checkbox','select','textarea') (optional, default 'text') - values Values for the field (comma separated for select menus) - regex Custom regex required by this field (optional, default null) - show_client Whether or not to allow the client to updated this field (optional, default 0) - read_only Whether or not the field is read only (optional, default 0) - encrypted Whether or not to encrypt values associated with this custom field (optional, default 0)

Returns

integer
The custom field ID, void on failure
public integer
# editCustomField( integer $field_id, array $vars )

Edit custom client field

Edit custom client field

Parameters

$field_id
integer
$field_id The ID of the custom field to update
$vars
array
An array of custom field info (all optional) including: - client_group_id The client group ID the field will belong to - name The name of the custom field - is_lang Whether or not 'name' is a language definition - type The type of field ('text','checkbox','select','textarea') - values Values for the field. If type is 'select', values must be a key=>value array of option=>value - regex Custom regex required by this field (optional, default null) - show_client Whether or not to allow the client to updated this field - read_only Whether or not the field is read only (optional, default 0) - encrypted Whether or not to encrypt values associated with this custom field (optional, default 0)

Returns

integer
The custom field ID, void on failure
public
# deleteCustomField( integer $field_id )

Permanently removes a custom client field and all entries for that field

Permanently removes a custom client field and all entries for that field

Parameters

$field_id
integer
$field_id The ID of the custom field to delete
public array
# getCustomFieldTypes( )

Retrieve a list of all custom field types

Retrieve a list of all custom field types

Returns

array
A key=>value array of custom field types
public mixed
# getCustomFields( integer $company_id, integer $client_group_id = null, array $options = null )

Retrieves a list of all custom client fields by company

Retrieves a list of all custom client fields by company

Parameters

$company_id
integer
$company_id The company ID
$client_group_id
integer
$client_group_id The client group ID of fields to fetch (optional, default null for all)
$options
array
$options An array of options to filter results on including: - show_client (1 to return only fields shown to clients, 0 to return all fields not shown to clients) - read_only (1 to show only fields set to read-only, 0 to return only fields not set to read-only)

Returns

mixed
An array of stdClass custom field objects, false if no custom fields exist
public mixed
# getCustomField( integer $field_id, integer $company_id = null )

Retrieves a single custom field

Retrieves a single custom field

Parameters

$field_id
integer
$field_id The custom field ID to fetch
$company_id
integer
$company_id The company ID (optional, default null)

Returns

mixed
An stdClass of key=>value pairs, or false if the custom field does not exist
public
# setCustomField( integer $field_id, integer $client_id, string $value )

Sets the given value for the given custom client field

Sets the given value for the given custom client field

Parameters

$field_id
integer
$field_id The ID of the custom client field
$client_id
integer
$client_id The client ID the custom field value belongs to
$value
string
$value The value to assign to this client
public
# deleteCustomFieldValue( integer $client_field_id, integer $client_id )

Deletes a given client field value

Deletes a given client field value

Parameters

$client_field_id
integer
$client_field_id The ID of the custom client field
$client_id
integer
$client_id The client ID the custom field value belongs to
public mixed
# getCustomFieldValues( integer $client_id )

Fetches all custom field values assigned to a given client

Fetches all custom field values assigned to a given client

Parameters

$client_id
integer
$client_id The client ID

Returns

mixed
An array of stdClass objects representing each custom field, or false if none exist
public
# setRestrictedPackages( integer $client_id, array $package_ids )

Sets restricted package access for a client

Sets restricted package access for a client

Parameters

$client_id
integer
$client_id The ID of the client whose restricted package access to set
$package_ids
array
A list of package IDs to assign to this client
public
# deleteRestrictedPackages( integer $client_id )

Removes all restricted package access for the given client

Removes all restricted package access for the given client

Parameters

$client_id
integer
$client_id The ID of the client whose package access to remove
public array
# getRestrictedPackages( integer $client_id )

Fetches all restricted package IDs accessible by the given client

Fetches all restricted package IDs accessible by the given client

Parameters

$client_id
integer
$client_id The ID of the client whose restricted packages to fetch

Returns

array
A list of stdClass objects each representing a restricted package ID
public boolean
# validatePackages( array $package_ids )

Validates that the given packages exist

Validates that the given packages exist

Parameters

$package_ids
array
$package_ids The IDs of the packages to check

Returns

boolean
True if the given packages exist, false otherwise
public integer
# addNote( integer $client_id, integer $staff_id, array $vars )

Add a note for the given client

Add a note for the given client

Parameters

$client_id
integer
$client_id The ID of the client to attach the note to
$staff_id
integer
$staff_id The ID of the staff member attempting to create the note, null for system
$vars
array
$vars An array of note info including: - title The title of the note - description The description of the note - stickied Whether this note is sticked or not (1 or 0, optional, default 0)

Returns

integer
The ID for this note, void on failure
public
# editNote( integer $note_id, array $vars )

Edit an existing note for a client

Edit an existing note for a client

Parameters

$note_id
integer
$note_id The ID of the note
$vars
array
$vars An array of note info (all optional) including: - title The title of the note - description The description of the note - stickied Whether this note is sticked or not (1 or 0, optional, default 0)
public
# unstickyNote( integer $note_id )

Sets the given note as unstickied

Sets the given note as unstickied

Parameters

$note_id
integer
$note_id The note ID
public
# deleteNote( integer $note_id )

Delete the given client note

Delete the given client note

Parameters

$note_id
integer
$note_id The ID of the note to delete
public mixed
# getNoteList( integer $client_id, integer $page = 1, array $order_by = array('date_added'=>"DESC") )

Returns all notes attached to a client

Returns all notes attached to a client

Parameters

$client_id
integer
$client_id The client to fetch notes 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 note objects, false if no notes exist
public integer
# getNoteListCount( integer $client_id )

Returns the count of all notes attached to a client

Returns the count of all notes attached to a client

Parameters

$client_id
integer
$client_id The client ID

Returns

integer
The number of notes belonging to this client

See

Clients::getNotes()
public array
# getAllStickyNotes( integer $client_id, integer $max_limit = null )

Retrieves a list of all sticked notes attached to this client

Retrieves a list of all sticked notes attached to this client

Parameters

$client_id
integer
$client_id The client ID
$max_limit
integer
$max_limit The maximum number of recent stickied notes to retrieve (optional, default all)

Returns

array
A list of stdClass objects representing each note
public mixed
# getNote( integer $note_id )

Returns the note specified

Returns the note specified

Parameters

$note_id
integer
$note_id The ID of the note to fetch

Returns

mixed
A stdClass object representing the note, false if the note does not exist
public mixed
# getDebitAccount( integer $client_id )

Retrieves the client debit account

Retrieves the client debit account

Parameters

$client_id
integer
$client_id The ID of the client whose debit account to get

Returns

mixed
A stdClass object representing the client account type, or false if none exist
public
# addDebitAccount( integer $client_id, array $vars )

Adds a client debit account type NOTE: if a debit account already exists for this client, it will be overwritten

Adds a client debit account type NOTE: if a debit account already exists for this client, it will be overwritten

Parameters

$client_id
integer
$client_id The ID of the client whose debit account to add a debit account to
$vars
array
$vars A list of client account types including: - account_id The ID of the account to add - type The type of account to add ('cc' or 'ach')
public boolean
# deleteDebitAccount( integer $client_id )

Deletes a client debit account type

Deletes a client debit account type

Parameters

$client_id
integer
$client_id The ID of the client whose debit account to delete

Returns

boolean
True if the debit account was deleted, false otherwise
public
# setDebitAccountFailure( integer $client_id, string $type = null, integer $account_id = null )

Increments the debit account failure count for the given client's debit account. Removes the debit account if it exceeds the threshold for failures based on the "autodebit_attempts" setting.

Increments the debit account failure count for the given client's debit account. Removes the debit account if it exceeds the threshold for failures based on the "autodebit_attempts" setting.

Parameters

$client_id
integer
$client_id The ID of the client to set autodebit failure
$type
string
$type The payment account type (ach, cc)
$account_id
integer
$account_id The payment account ID
public
# resetDebitAccountFailure( integer $client_id, string $type = null, integer $account_id = null )

Resets the debit account failure count for the given client's debit account.

Resets the debit account failure count for the given client's debit account.

Parameters

$client_id
integer
$client_id The ID of the client to reset autodebit failure
$type
string
$type The payment account type (ach, cc)
$account_id
integer
$account_id The payment account ID
public
# setClientSettings( integer $client_id, array $vars )

Add multiple client settings, with rule validation. If duplicate key, update the setting

Add multiple client settings, with rule validation. If duplicate key, update the setting

Parameters

$client_id
integer
$client_id The ID for the specified client
$vars
array
$vars A single dimensional array of key/value pairs of settings
public
# setSettings( integer $client_id, array $vars, array $value_keys = null )

Add multiple client settings, if duplicate key update the setting

Add multiple client settings, if duplicate key update the setting

Parameters

$client_id
integer
$client_id The ID for the specified client
$vars
array
$vars A single dimensional array of key/value pairs of settings
$value_keys
array
$value_keys An array of key values to accept as valid fields
public
# setSetting( integer $client_id, string $key, string $value, mixed $encrypted = null )

Add a client setting, if duplicate key update the setting

Add a client setting, if duplicate key update the setting

Parameters

$client_id
integer
$client_id The ID for the specified client
$key
string
$key The key for this client setting
$value
string
$value The value for this individual client setting
$encrypted
mixed
$encrypted True to encrypt $value, false to store unencrypted, null to encrypt if currently set to encrypt
public
# unsetSetting( integer $client_id, string $key )

Delete a client setting

Delete a client setting

Parameters

$client_id
integer
$client_id The ID for the specified client
$key
string
$key The key for this client setting
public mixed
# getSettings( integer $client_id )

Fetch all settings that may apply to this client. Settings are inherited in the order of client_settings -> client_group_settings -> company_settings -> settings where "->" represents the left item inheriting (and overwriting in the case of duplicates) values found in the right item.

Fetch all settings that may apply to this client. Settings are inherited in the order of client_settings -> client_group_settings -> company_settings -> settings where "->" represents the left item inheriting (and overwriting in the case of duplicates) values found in the right item.

Parameters

$client_id
integer
$client_id The client ID to retrieve settings for

Returns

mixed
An array of objects containg key/values for the settings, false if no records found
public mixed
# getSetting( integer $client_id, mixed $key )

Fetch a specific setting that may apply to this client. Settings are inherited in the order of client_settings -> client_group_settings -> company_settings -> settings where "->" represents the left item inheriting (and overwriting in the case of duplicates) values found in the right item.

Fetch a specific setting that may apply to this client. Settings are inherited in the order of client_settings -> client_group_settings -> company_settings -> settings where "->" represents the left item inheriting (and overwriting in the case of duplicates) values found in the right item.

Parameters

$client_id
integer
$client_id The client ID to retrieve settings for
$key

Returns

mixed
A stdClass object containg key/values for the settings, false if no record found
public mixed
# get( integer $client_id, boolean $get_settings = true )

Fetches a client with contact details of the primary account holder

Fetches a client with contact details of the primary account holder

Parameters

$client_id
integer
$client_id The client ID to fetch
$get_settings
boolean
$get_settings True to fetch settings for this client (default), false otherwise

Returns

mixed
An object containing client fields, false if the client does not exist.

See

Contacts::get(), Clients::getByUserId()
public mixed
# getByUserId( integer $user_id, boolean $get_settings = false )

Fetches a client with contact details of the primary account holder

Fetches a client with contact details of the primary account holder

Parameters

$user_id
integer
$user_id The ID of the user
$get_settings
boolean
$get_settings True to fetch settings for this client, false otherwise

Returns

mixed
An object containing client fields, false if the client does not exist.

See

Contacts::get(), Clients::getByUserId()
public array
# getList( string $status = null, integer $page = 1, string $order_by = array('id_code'=>"ASC") )

Fetches a list of all clients

Fetches a list of all clients

Parameters

$status
string
$status The status type of the clients to fetch ('active', 'inactive', 'fraud', default null for all)
$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

array
An array of stdClass objects representing each client, or false if no results
public integer
# getListCount( string $status = null )

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

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

Parameters

$status
string
$status The status type of the clients to fetch ('active', 'inactive', 'fraud', default null for all)

Returns

integer
The total number of clients

See

Clients::getList()
public array
# getAll( string $status = null, integer $client_group_id = null )

Fetches all clients

Fetches all clients

Parameters

$status
string
$status The status type of the clients to fetch ('active', 'inactive', 'fraud', default null for all)
$client_group_id
integer
$client_group_id The ID of the client group whose clients to fetch (optional, default null for all)

Returns

array
An array of stdClass objects representing each client, or false if no results
public array
# search( string $query, integer $page = 1 )

Search clients

Search clients

Parameters

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

Returns

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

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

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

Parameters

$query
string
$query The value to search clients for

See

Clients::search()
public mixed
# getMailLogEntry( integer $client_id, integer $email_log_id )

Fetches a specific email from the log for a given client

Fetches a specific email from the log for a given client

Parameters

$client_id
integer
$client_id The client ID
$email_log_id
integer
$email_log_id The email log ID of the email

Returns

mixed
An stdClass object representing the email log, or false if it doesn't exist
public mixed
# getMailLogList( integer $client_id, integer $page = 1, array $order_by = array('date_sent'=>"DESC") )

Fetches the mail logs for a given client

Fetches the mail logs for a given client

Parameters

$client_id
integer
$client_id The client ID
$page
integer
$page The page of results to fetch
$order_by
array
$order_by The sort and order conditions (e.g. array("sort_field"=>"ASC"), optional)

Returns

mixed
An array of stdClass objects representing client mail logs, or false if none exist
public integer
# getMailLogListCount( integer $client_id )

Retrieves the number of sent emails contained in the mail log

Retrieves the number of sent emails contained in the mail log

Parameters

$client_id
integer
$client_id The client ID

Returns

integer
The number of emails contained in the log
public array
# usedCurrencies( integer $client_id )

Retrieves a list of ISO 4217 currency codes used by the given client

Retrieves a list of ISO 4217 currency codes used by the given client

Parameters

$client_id
integer
$client_id The ID of the client whose used currencies to fetch

Returns

array
A list of ISO 4217 currency codes
public integer
# getStatusCount( string $status = "active" )

Retrieves the number of clients given a client status

Retrieves the number of clients given a client status

Parameters

$status
string
$status The client status type (optional, default 'active')

Returns

integer
The number of clients of type $status
public array
# getStatusTypes( )

Retrieves a list of client status types

Retrieves a list of client status types

Returns

array
Key=>value pairs of client status types
public boolean
# validateRegex( string $regex )

Determines whether the given regular expression is a valid PCRE

Determines whether the given regular expression is a valid PCRE

Parameters

$regex
string
$regex The regular expression to check

Returns

boolean
True if the regular expression is valid, false otherwise
public
# validateBillingContact( integer $contact_id, integer $client_id )

Validates that the given contact ID is a primary or billing contact for the given client

Validates that the given contact ID is a primary or billing contact for the given client

Parameters

$contact_id
integer
$contact_id The contact ID
$client_id
integer
$client_id The client ID
public boolean
# validateClientDeleteable( integer $client_id )

Validates that the given client can be deleted

Validates that the given client can be deleted

Parameters

$client_id
integer
$client_id The ID of the client to delete

Returns

boolean
True if the client may be deleted, false otherwise
public boolean
# validateCurrencyExists( string $code, integer $company_id )

Validates a currency exists

Validates a currency exists

Parameters

$code
string
$code The currency code
$company_id
integer
$company_id The company ID

Returns

boolean
True if the currency exists, false otherwise
public boolean
# validateClientSettingIsEditable( string $value, string $key, integer $client_id )

Validates that the given setting is editable by a client

Validates that the given setting is editable by a client

Parameters

$value
string
$value The value of the setting
$key
string
$key The setting key (one of "client_set_currency", "client_set_invoice", or "client_set_lang")
$client_id
integer
$client_id The ID of the client to validate against

Returns

boolean
True if the client may update the given setting, false otherwise
public
# validateLanguageExists( string $code, integer $company_id )

Validates that the given language code exists for this company

Validates that the given language code exists for this company

Parameters

$code
string
$code The language code in ISO 639-1 ISO 3166-1 alpha-2 concatenated format (i.e. "en_us")
$company_id
integer
$company_id The company ID
public boolean
# validateValues( mixed $values, string $type )

Validates client custom field values

Validates client custom field values

Parameters

$values
mixed
$values The values of the custom field
$type
string
$type The type of custom field this is ('text', 'checkbox', 'select', 'textarea')

Returns

boolean
True if values are in the expected format, false otherwise
public boolean
# validateStatus( string $status )

Validates the client's 'status' field

Validates the client's 'status' field

Parameters

$status
string
$status The status to check

Returns

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

Validates the client's 'primary_account_type' field

Validates the client's 'primary_account_type' field

Parameters

$type
string
$type The primary account type

Returns

boolean
True if validated, false otherwise
public boolean
# validateUserId( integer $user_id, integer $client_id )

Validates the user ID belongs to $client_id

Validates the user ID belongs to $client_id

Parameters

$user_id
integer
$user_id The client's user ID
$client_id
integer
$client_id The client ID

Returns

boolean
True if $user_id belongs to $client_id, false otherwise
public boolean
# validateFieldType( string $type )

Validates the client custom field type

Validates the client custom field type

Parameters

$type
string
$type The custom field type

Returns

boolean
True if validated, false otherwise
public boolean
# validateFieldCompany( integer $field_id, integer $client_id )

Validates that the given field belongs to the same company as the client

Validates that the given field belongs to the same company as the client

Parameters

$field_id
integer
$field_id The custom client field ID
$client_id
integer
$client_id The client ID

Returns

boolean
True if the custom field ID company matches the client's company ID, false otherwise
public
# 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

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