Plugin API » 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() sets a key/value pair into your plugin. You can do this from within a Page, Applet UI and TwiML.
| 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() |
None
PluginData::set("mykey", "value");
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);
If default is specified, a default return value will be returned when key is not found in PluginData.
| 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. |
$value = PluginData::get("mykey");
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);
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'));
array(3) {
[0]=>
string(4) "cars"
[1]=>
string(5) "tires"
[2]=>
string(5) "bikes"
}
Use this method to delete a key/value pair from your key/value store.
| Name | Type | Description |
|---|---|---|
| $key | string | The key you want to delete from the key/value store. |
PluginData::delete("my-key");
Use this to run a sql query on the OpenVBX database.
| Name | Type | Description |
|---|---|---|
| $sql | string | Valid MySQL statement |
$results = PluginData::sqlQuery("SELECT * FROM users");
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);
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"
}
}