本文整理匯總了PHP中OpenVBX::getAccounts方法的典型用法代碼示例。如果您正苦於以下問題:PHP OpenVBX::getAccounts方法的具體用法?PHP OpenVBX::getAccounts怎麽用?PHP OpenVBX::getAccounts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類OpenVBX
的用法示例。
在下文中一共展示了OpenVBX::getAccounts方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: add_tenant
private function add_tenant()
{
$tenant = $this->input->post('tenant');
if (empty($tenant['url_prefix'])) {
$data['error'] = true;
$data['message'] = 'A valid tenant name is required';
$this->session->set_flashdata('error', 'Failed to add new tenant: ' . $data['message']);
}
if (empty($tenant['admin_email']) || !filter_var($tenant['admin_email'], FILTER_VALIDATE_EMAIL)) {
$data['error'] = true;
$data['message'] = 'A valid admin email address is required';
$this->session->set_flashdata('error', 'Failed to add new tenant: ' . $data['message']);
}
if (!empty($tenant) && empty($data['error'])) {
try {
$data['id'] = $this->settings->tenant($tenant['url_prefix'], urlencode($tenant['url_prefix']), '');
$this->db->trans_start();
$user = new VBX_User();
$user->fields[] = 'tenant_id';
// monkey patching to override tenant_id
$user->first_name = '';
$user->last_name = '';
$user->password = '';
$user->values['tenant_id'] = $data['id'];
// hidden field not in ORM
$user->email = $tenant['admin_email'];
$user->is_active = TRUE;
$user->is_admin = TRUE;
$user->auth_type = 1;
try {
$user->save();
} catch (VBX_UserException $e) {
throw new VBX_SettingsException($e->getMessage());
}
foreach ($this->settings->setting_options as $param) {
$this->settings->add($param, '', $data['id']);
}
$this->settings->set('from_email', $tenant['admin_email'], $data['id']);
$friendlyName = substr($tenant['url_prefix'] . ' - ' . $tenant['admin_email'], 0, 32);
switch ($this->input->post('auth_type')) {
case 'connect':
$auth_type = VBX_Settings::AUTH_TYPE_CONNECT;
break;
case 'subaccount':
default:
$auth_type = VBX_Settings::AUTH_TYPE_SUBACCOUNT;
break;
}
/**
* Only do app setup for sub-accounts.
* Connect tenants will get set up after going through the connect process.
*/
if ($auth_type === VBX_Settings::AUTH_TYPE_SUBACCOUNT) {
try {
/** @var Services_Twilio_Rest_Accounts $accounts */
$accounts = OpenVBX::getAccounts();
// default, sub-account
$sub_account = $accounts->create(array('FriendlyName' => $friendlyName));
$tenant_sid = $sub_account->sid;
$tenant_token = $sub_account->auth_token;
$this->settings->add('twilio_sid', $tenant_sid, $data['id']);
$this->settings->add('twilio_token', $tenant_token, $data['id']);
$app_sid = $this->create_application_for_subaccount($data['id'], $tenant['url_prefix'], $tenant_sid);
$this->settings->add('application_sid', $app_sid, $data['id']);
} catch (Exception $e) {
throw new VBX_SettingsException($e->getMessage());
}
} elseif ($auth_type === VBX_Settings::AUTH_TYPE_CONNECT) {
// when using connect, we won't get a sid, token, or
// app_sid until user first login
$tenant_id = $tenant_token = $app_sid = null;
$this->settings->add('tenant_first_run', 1, $data['id']);
} else {
throw new VBX_SettingsException('Unknown auth-type encountered during ' . 'tenant creation');
}
$this->settings->update_tenant(array('id' => $data['id'], 'type' => $auth_type));
$tenant_defaults = array('transcriptions' => 1, 'voice' => 'man', 'voice_language' => 'en', 'numbers_country' => 'US', 'gravatars' => 0, 'dial_timeout' => 15);
foreach ($tenant_defaults as $key => $value) {
$this->settings->set($key, $value, $data['id']);
}
$this->db->trans_complete();
$this->session->set_flashdata('error', 'Added new tenant');
$user->send_new_user_notification();
if (isset($data['id'])) {
return redirect('settings/site/tenant/' . $data['id']);
}
} catch (VBX_SettingsException $e) {
error_log($e->getMessage());
$this->db->trans_rollback();
// TODO: rollback in twilio.
$this->session->set_flashdata('error', 'Failed to add new tenant: ' . $e->getMessage());
$data['error'] = true;
$data['message'] = $e->getMessage();
}
}
if ($this->response_type == 'html') {
redirect('settings/site');
}
$this->respond('', 'settings/site', $data);
}