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:
FusionPBX 2025-01-07 22:20:57 -07:00 committed by markjcrane
parent 9ed10a4dec
commit 28040957bd
1 changed files with 39 additions and 12 deletions

View File

@ -36,11 +36,32 @@ if (!class_exists('registrations')) {
private $permission_prefix;
private $list_page;
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
*/
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
$this->app_name = 'registrations';
@ -49,6 +70,14 @@ if (!class_exists('registrations')) {
$this->list_page = 'registrations.php';
$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;
}
$sql .= "and sip_profile_enabled = 'true' ";
$database = new database;
$sip_profiles = $database->select($sql, $parameters ?? null, 'all');
$sip_profiles = $this->database->select($sql, $parameters ?? null, 'all');
if (!empty($sip_profiles) && @sizeof($sip_profiles) != 0) {
foreach ($sip_profiles as $field) {
@ -180,8 +208,8 @@ if (!class_exists('registrations')) {
//remove unrelated domains
if (!permission_exists('registration_all') || $this->show != 'all') {
if ($registrations[$id]['sip-auth-realm'] == $_SESSION['domain_name']) {}
else if ($user_array[1] == $_SESSION['domain_name']) {}
if ($registrations[$id]['sip-auth-realm'] == $this->domain_name) {}
else if ($user_array[1] == $this->domain_name) {}
else {
unset($registrations[$id]);
}
@ -269,8 +297,7 @@ if (!class_exists('registrations')) {
//retrieve sip profiles list
$sql = "select sip_profile_name as name from v_sip_profiles ";
$database = new database;
$sip_profiles = $database->select($sql, null, 'all');
$sip_profiles = $this->database->select($sql, null, 'all');
unset($sql);
//create the event socket connection