Access Controls, Bridges, Call Block, Call Flows: Class toggle method adjustments.

This commit is contained in:
Nate
2019-10-29 10:11:18 -06:00
parent 90e6ad93e7
commit f99005427c
4 changed files with 19 additions and 15 deletions
@@ -17,7 +17,6 @@ if (!class_exists('access_controls')) {
private $list_page; private $list_page;
private $table; private $table;
private $uuid_prefix; private $uuid_prefix;
private $enabled_prefix;
/** /**
* called when the object is created * called when the object is created
@@ -31,7 +30,6 @@ if (!class_exists('access_controls')) {
$this->list_page = 'access_controls.php'; $this->list_page = 'access_controls.php';
$this->table = 'access_controls'; $this->table = 'access_controls';
$this->uuid_prefix = 'access_control_'; $this->uuid_prefix = 'access_control_';
$this->enabled_prefix = 'access_control_';
} }
+8 -6
View File
@@ -17,7 +17,8 @@ if (!class_exists('bridges')) {
private $list_page; private $list_page;
private $table; private $table;
private $uuid_prefix; private $uuid_prefix;
private $enabled_prefix; private $toggle_field;
private $toggle_values;
/** /**
* called when the object is created * called when the object is created
@@ -31,7 +32,8 @@ if (!class_exists('bridges')) {
$this->list_page = 'bridges.php'; $this->list_page = 'bridges.php';
$this->table = 'bridges'; $this->table = 'bridges';
$this->uuid_prefix = 'bridge_'; $this->uuid_prefix = 'bridge_';
$this->enabled_prefix = 'bridge_'; $this->toggle_field = 'bridge_enabled';
$this->toggle_values = ['true','false'];
} }
@@ -113,14 +115,14 @@ if (!class_exists('bridges')) {
//toggle the checked records //toggle the checked records
if (is_array($records) && @sizeof($records) != 0) { if (is_array($records) && @sizeof($records) != 0) {
//get current enabled state //get current toggle state
foreach($records as $x => $record) { foreach($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'"; $record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'";
} }
} }
if (is_array($record_uuids) && @sizeof($record_uuids) != 0) { if (is_array($record_uuids) && @sizeof($record_uuids) != 0) {
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->enabled_prefix."enabled as enabled from v_".$this->table." "; $sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) "; $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$sql .= "and ( ".implode(' or ', $record_uuids)." ) "; $sql .= "and ( ".implode(' or ', $record_uuids)." ) ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
@@ -128,7 +130,7 @@ if (!class_exists('bridges')) {
$rows = $database->select($sql, $parameters, 'all'); $rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) { if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) { foreach ($rows as $row) {
$states[$row['uuid']] = $row['enabled']; $states[$row['uuid']] = $row['toggle'];
} }
} }
unset($sql, $parameters, $rows, $row); unset($sql, $parameters, $rows, $row);
@@ -138,7 +140,7 @@ if (!class_exists('bridges')) {
$x = 0; $x = 0;
foreach($states as $uuid => $state) { foreach($states as $uuid => $state) {
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid; $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
$array[$this->table][$x][$this->enabled_prefix.'enabled'] = $state == 'true' ? 'false' : 'true'; $array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
$x++; $x++;
} }
@@ -17,7 +17,8 @@ if (!class_exists('call_block')) {
private $list_page; private $list_page;
private $table; private $table;
private $uuid_prefix; private $uuid_prefix;
private $enabled_prefix; private $toggle_field;
private $toggle_values;
/** /**
* called when the object is created * called when the object is created
@@ -31,7 +32,8 @@ if (!class_exists('call_block')) {
$this->list_page = 'call_block.php'; $this->list_page = 'call_block.php';
$this->table = 'call_block'; $this->table = 'call_block';
$this->uuid_prefix = 'call_block_'; $this->uuid_prefix = 'call_block_';
$this->enabled_prefix = 'call_block_'; $this->toggle_field = 'call_block_enabled';
$this->toggle_values = ['true','false'];
} }
@@ -113,14 +115,14 @@ if (!class_exists('call_block')) {
//toggle the checked records //toggle the checked records
if (is_array($records) && @sizeof($records) != 0) { if (is_array($records) && @sizeof($records) != 0) {
//get current enabled state //get current toggle state
foreach($records as $x => $record) { foreach($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'"; $record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'";
} }
} }
if (is_array($record_uuids) && @sizeof($record_uuids) != 0) { if (is_array($record_uuids) && @sizeof($record_uuids) != 0) {
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->enabled_prefix."enabled as enabled from v_".$this->table." "; $sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) "; $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$sql .= "and ( ".implode(' or ', $record_uuids)." ) "; $sql .= "and ( ".implode(' or ', $record_uuids)." ) ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
@@ -128,7 +130,7 @@ if (!class_exists('call_block')) {
$rows = $database->select($sql, $parameters, 'all'); $rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) { if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) { foreach ($rows as $row) {
$states[$row['uuid']] = $row['enabled']; $states[$row['uuid']] = $row['toggle'];
} }
} }
unset($sql, $parameters, $rows, $row); unset($sql, $parameters, $rows, $row);
@@ -138,7 +140,7 @@ if (!class_exists('call_block')) {
$x = 0; $x = 0;
foreach($states as $uuid => $state) { foreach($states as $uuid => $state) {
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid; $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
$array[$this->table][$x][$this->enabled_prefix.'enabled'] = $state == 'true' ? 'false' : 'true'; $array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
$x++; $x++;
} }
@@ -18,6 +18,7 @@ if (!class_exists('call_flows')) {
private $table; private $table;
private $uuid_prefix; private $uuid_prefix;
private $toggle_field; private $toggle_field;
private $toggle_values;
/** /**
* called when the object is created * called when the object is created
@@ -32,6 +33,7 @@ if (!class_exists('call_flows')) {
$this->table = 'call_flows'; $this->table = 'call_flows';
$this->uuid_prefix = 'call_flow_'; $this->uuid_prefix = 'call_flow_';
$this->toggle_field = 'call_flow_status'; $this->toggle_field = 'call_flow_status';
$this->toggle_values = ['true','false'];
} }
@@ -138,7 +140,7 @@ if (!class_exists('call_flows')) {
$x = 0; $x = 0;
foreach($states as $uuid => $state) { foreach($states as $uuid => $state) {
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid; $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
$array[$this->table][$x][$this->toggle_field] = $state == 'true' ? 'false' : 'true'; $array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
$x++; $x++;
} }