Add the settings_array to the class constructor
- More efficient to pass in the database object - Added an option to pass in the domain_name
This commit is contained in:
@@ -36,18 +36,47 @@ if (!class_exists('registrations')) {
|
|||||||
private $permission_prefix;
|
private $permission_prefix;
|
||||||
private $list_page;
|
private $list_page;
|
||||||
public $show;
|
public $show;
|
||||||
|
private $domain_name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set in the constructor. Must be a database object and cannot be null.
|
||||||
|
* @var database Database Object
|
||||||
|
*/
|
||||||
|
private $database;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* called when the object is created
|
* called when the object is created
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct($setting_array = []) {
|
||||||
|
|
||||||
|
//open a database connection
|
||||||
|
if (empty($setting_array['database'])) {
|
||||||
|
$this->database = database::new();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->database = $setting_array['database'];
|
||||||
|
}
|
||||||
|
|
||||||
|
//trap passing a PDO object instead of the required database object
|
||||||
|
if (!($this->database instanceof database)) {
|
||||||
|
//should never happen but will trap it here just-in-case
|
||||||
|
throw new \InvalidArgumentException("Database object passed in settings class constructor is not a valid database object");
|
||||||
|
}
|
||||||
|
|
||||||
//assign private variables
|
//assign private variables
|
||||||
$this->app_name = 'registrations';
|
$this->app_name = 'registrations';
|
||||||
$this->app_uuid = '5d9e7cd7-629e-3553-4cf5-f26e39fefa39';
|
$this->app_uuid = '5d9e7cd7-629e-3553-4cf5-f26e39fefa39';
|
||||||
$this->permission_prefix = 'registration_';
|
$this->permission_prefix = 'registration_';
|
||||||
$this->list_page = 'registrations.php';
|
$this->list_page = 'registrations.php';
|
||||||
$this->show = 'local';
|
$this->show = 'local';
|
||||||
|
|
||||||
|
//get the domain_name
|
||||||
|
if (empty($setting_array['domain_name'])) {
|
||||||
|
$this->domain_name = $_SESSION['domain_name'];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->domain_name = $setting_array['domain_name'];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,8 +99,7 @@ if (!class_exists('registrations')) {
|
|||||||
$parameters['sip_profile_name'] = $profile;
|
$parameters['sip_profile_name'] = $profile;
|
||||||
}
|
}
|
||||||
$sql .= "and sip_profile_enabled = 'true' ";
|
$sql .= "and sip_profile_enabled = 'true' ";
|
||||||
$database = new database;
|
$sip_profiles = $this->database->select($sql, $parameters ?? null, 'all');
|
||||||
$sip_profiles = $database->select($sql, $parameters ?? null, 'all');
|
|
||||||
if (!empty($sip_profiles) && @sizeof($sip_profiles) != 0) {
|
if (!empty($sip_profiles) && @sizeof($sip_profiles) != 0) {
|
||||||
foreach ($sip_profiles as $field) {
|
foreach ($sip_profiles as $field) {
|
||||||
|
|
||||||
@@ -180,8 +208,8 @@ if (!class_exists('registrations')) {
|
|||||||
|
|
||||||
//remove unrelated domains
|
//remove unrelated domains
|
||||||
if (!permission_exists('registration_all') || $this->show != 'all') {
|
if (!permission_exists('registration_all') || $this->show != 'all') {
|
||||||
if ($registrations[$id]['sip-auth-realm'] == $_SESSION['domain_name']) {}
|
if ($registrations[$id]['sip-auth-realm'] == $this->domain_name) {}
|
||||||
else if ($user_array[1] == $_SESSION['domain_name']) {}
|
else if ($user_array[1] == $this->domain_name) {}
|
||||||
else {
|
else {
|
||||||
unset($registrations[$id]);
|
unset($registrations[$id]);
|
||||||
}
|
}
|
||||||
@@ -269,8 +297,7 @@ if (!class_exists('registrations')) {
|
|||||||
|
|
||||||
//retrieve sip profiles list
|
//retrieve sip profiles list
|
||||||
$sql = "select sip_profile_name as name from v_sip_profiles ";
|
$sql = "select sip_profile_name as name from v_sip_profiles ";
|
||||||
$database = new database;
|
$sip_profiles = $this->database->select($sql, null, 'all');
|
||||||
$sip_profiles = $database->select($sql, null, 'all');
|
|
||||||
unset($sql);
|
unset($sql);
|
||||||
|
|
||||||
//create the event socket connection
|
//create the event socket connection
|
||||||
|
|||||||
Reference in New Issue
Block a user