Plugin API » Data

Plugin Data

PluginData contains helpers to set key/value pairs scoped to your own plugin and run sql queries directly on the OpenVBX database.

Use PluginData::set() to store values, PluginData::get() to retrieve, and PluginData::delete() to remove.

PluginData::set( $key, $value )

PluginData::set() sets a key/value pair into your plugin. You can do this from within a Page, Applet UI and TwiML.

Arguments

Name Type Description
$key string Key of your key value pair.
$value mixed This can be any type of variable. Whatever you store is what should come out when you use Plugin::get()

Returns

  • None

Usage

PluginData::set("mykey", "value");

Examples

Set some values in an array and store in the PluginData.

PluginData::set("my-array", array(1,2,3,4));

Store a newly created object in the PluginData.

$obj = new stdClass();
$obj->property = 'test';
PluginData::set("my-object", $obj);

PluginData::get( $key, $default = null )

If default is specified, a default return value will be returned when key is not found in PluginData.

Arguments

Name Type Description
$key string The key of the data you want to fetch. Must be a string value.
$default mixed $default is returned when the key is not set. Can be any type of php variable.

Returns

  • mixed — value stored in PluginData by $key

Usage

$value = PluginData::get("mykey");

Examples

Get some values in an array and store in the PluginData, retrieve them and list them out.

PluginData::set("my-array", array(1,2,3,4));
$value = PluginData::get("my-array");
print_r($value);

Output

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
)

Get a list of strings from the garage key.

PluginData::set('garage', array('cars', 'tires', 'bikes'));
var_dump(PluginData::get('garage'));

Output

array(3) {
    [0]=>
    string(4) "cars"
    [1]=>
    string(5) "tires"
    [2]=>
    string(5) "bikes"
}

PluginData::delete( $key )

Use this method to delete a key/value pair from your key/value store.

Arguments

Name Type Description
$key string The key you want to delete from the key/value store.

Returns

  • void

Usage

PluginData::delete("my-key");

PluginData::sqlQuery( $sql )

Use this to run a sql query on the OpenVBX database.

Arguments

Name Type Description
$sql string Valid MySQL statement

Returns

  • Array of row results
  • Empty Array if empty row result

Usage

$results = PluginData::sqlQuery("SELECT * FROM users");

Examples

Get a user from the users table

$user = OpenVBX::getCurrentUser();
$user_id = intval($user->id);
$result = PluginData::sqlQuery("SELECT * FROM users WHERE id=$user_id");

var_dump($result);

Output

array(1) {
  [0]=>
  array(15) {
    ["id"]=>
    string(1) "1"
    ["is_admin"]=>
    string(1) "1"
    ["is_active"]=>
    string(1) "1"
    ["first_name"]=>
    string(4) "Adam"
    ["last_name"]=>
    string(0) ""
    ["password"]=>
    string(40) "0ff27dad6c53367331acd54b3d0dbc0f9ca4eab0"
    ["invite_code"]=>
    NULL
    ["email"]=>
    string(15) "adam@twilio.com"
    ["pin"]=>
    NULL
    ["notification"]=>
    NULL
    ["auth_type"]=>
    string(1) "1"
    ["voicemail"]=>
    string(38) "Please leave a message after the beep."
    ["tenant_id"]=>
    string(1) "1"
    ["last_seen"]=>
    string(19) "2010-06-15 10:22:23"
    ["last_login"]=>
    string(19) "2010-06-15 07:38:40"
  }
}