Optimise Hint processing

Remove hint processing from __Construct and place in getbuttons, only place where used
Return hint information in correct format from ami, to avoid second formatting
Optimise db calls for hints to speed loading of add/edit device.
This commit is contained in:
stevenA 2022-01-16 15:46:05 +01:00
parent ce383089b8
commit 2229eef432
6 changed files with 50 additions and 44 deletions

View file

@ -429,6 +429,12 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
break; break;
case 'monitor': case 'monitor':
$hint = $this->aminterface->core_list_hints();
foreach ($hint as $key => $value) {
if ($this->hint_context['default'] != $value) {
$this->hint_context[$key] = $value;
}
}
$btn_t = 'speeddial'; $btn_t = 'speeddial';
$btn_opt = (string) $get_settings["button${it}_line"]; $btn_opt = (string) $get_settings["button${it}_line"];
$db_res = $this->dbinterface->getSccpDeviceTableData('SccpExtension', array('name' => $btn_opt)); $db_res = $this->dbinterface->getSccpDeviceTableData('SccpExtension', array('name' => $btn_opt));
@ -711,13 +717,14 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
} }
} }
} }
/*
$hint = $this->aminterface->core_list_hints(); $hint = $this->aminterface->core_list_hints();
foreach ($hint as $key => $value) { foreach ($hint as $key => $value) {
if ($this->hint_context['default'] != $value) { if ($this->hint_context['default'] != $value) {
$this->hint_context[$key] = $value; $this->hint_context[$key] = $value;
} }
} }
*/
} }
/* /*
@ -1055,34 +1062,35 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
return $modelList; return $modelList;
} }
function getHintInformation($sort = true, $filter = array()) { function getHintInformation($filter = array()) {
$res = array(); $res = array();
$default_hint = '@ext-local'; $default_hint = '@ext-local';
if (empty($res)) { //if (empty($res)) {
// Old Req get all hints // Old Req get all hints
$tmp_data = $this->aminterface->core_list_all_hints(); // Avoid post processing - return dat in required format.
foreach ($tmp_data as $value) { $res = $this->aminterface->core_list_all_hints();
$res[$value] = array('key' => $value, 'exten' => $this->before('@', $value), 'label' => $value); //foreach ($tmp_data as $value) {
} //$res[$value] = array('key' => $value, 'exten' => $this->before('@', $value), 'label' => $value);
} //}
//dbug($res);
//}
// Update info from sccp_db // Update info from sccp_db
$tmp_data = $this->dbinterface->getSccpDeviceTableData('SccpExtension'); foreach ($this->dbinterface->getSccpDeviceTableData('sccpHints') as $key => $value) {
foreach ($tmp_data as $value) { if (!empty($res[$key . $default_hint])) {
$name_l = $value['name']; $res[$key . $default_hint]['exten'] = $key;
if (!empty($res[$name_l . $default_hint])) { $res[$key . $default_hint]['label'] = $value['label'];
$res[$name_l . $default_hint]['exten'] = $name_l;
$res[$name_l . $default_hint]['label'] = $value['label'];
} else { } else {
// if not exist in system hints ..... ??????? // if not exist in system hints ..... ???????
$res[$name_l . $default_hint] = array('key' => $name_l . $default_hint, 'exten' => $name_l, 'label' => $value['label']); $res[$key . $default_hint] = array('key' => $key . $default_hint, 'exten' => $key, 'label' => $value['label']);
} }
} }
if (!$sort) { // Hints returned from db are already sorted by name
return $res; //if (!$sort) {
} return $res;
//}
/*
foreach ($res as $key => $value) { foreach ($res as $key => $value) {
$data_sort[$value['exten']] = $key; $data_sort[$value['exten']] = $key;
} }
@ -1090,10 +1098,11 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
foreach ($data_sort as $key => $value) { foreach ($data_sort as $key => $value) {
$res_sort[$value] = $res[$value]; $res_sort[$value] = $res[$value];
} }
*/
// Update info from sip DB // Update info from sip DB
/* !TODO!: Update Hint info from sip DB ??? */ /* !TODO!: Update Hint info from sip DB ??? */
return $res_sort; //return $res_sort;
} }
} }
?> ?>

View file

@ -1,13 +1,5 @@
<?php <?php
/**
*
* Core Comsnd Interface
*
* https://www.voip-info.org/asterisk-manager-example-php/
*/
/* !TODO!: Re-Indent this file. -TODO-: What do you mean? coreaccessinterface ?? */
namespace FreePBX\modules\Sccp_manager\aminterface; namespace FreePBX\modules\Sccp_manager\aminterface;
// ************************************************************************** Event ********************************************* // ************************************************************************** Event *********************************************
@ -94,7 +86,7 @@ class SCCPDeviceEntry_Event extends Event
{ {
// This is a list of tables, each table is an entry // This is a list of tables, each table is an entry
} }
/*
class SCCPShowDevice_Event extends Event class SCCPShowDevice_Event extends Event
{ {
// This is a list of tables // This is a list of tables
@ -109,7 +101,8 @@ class SCCPShowDevice_Event extends Event
} }
return $ret; return $ret;
} }
*/
/*
public function getCodecsPreference() public function getCodecsPreference()
{ {
// TODO unused method - to be deleted? // TODO unused method - to be deleted?
@ -121,7 +114,8 @@ class SCCPShowDevice_Event extends Event
} }
return $ret; return $ret;
} }
} */
//}
class SCCPDeviceButtonEntry_Event extends Event class SCCPDeviceButtonEntry_Event extends Event
{ {
} }

View file

@ -17,7 +17,6 @@ class AMIException extends \Exception
abstract class Message abstract class Message
{ {
const EOL = "\r\n"; const EOL = "\r\n";
const EOM = "\r\n\r\n"; const EOM = "\r\n\r\n";
@ -360,8 +359,8 @@ class ExtensionStateListAction extends ActionMessage
public function __construct() public function __construct()
{ {
parent::__construct('ExtensionStateList'); parent::__construct('ExtensionStateList');
$this->setKey('Segment', 'general'); //$this->setKey('Segment', 'general');
$this->setKey('ResultFormat', 'command'); //$this->setKey('ResultFormat', 'command');
$this->setResponseHandler("ExtensionStateList"); $this->setResponseHandler("ExtensionStateList");
} }
} }
@ -379,8 +378,8 @@ class SCCPShowSoftkeySetsAction extends ActionMessage
public function __construct() public function __construct()
{ {
parent::__construct('SCCPShowSoftkeySets'); parent::__construct('SCCPShowSoftkeySets');
$this->setKey('Segment', 'general'); //$this->setKey('Segment', 'general');
$this->setKey('ResultFormat', 'command'); //$this->setKey('ResultFormat', 'command');
$this->setResponseHandler("SCCPShowSoftkeySets"); $this->setResponseHandler("SCCPShowSoftkeySets");
} }
} }
@ -391,8 +390,8 @@ class SCCPShowDeviceAction extends ActionMessage
public function __construct($devicename) public function __construct($devicename)
{ {
parent::__construct('SCCPShowDevice'); parent::__construct('SCCPShowDevice');
$this->setKey('Segment', 'general'); //$this->setKey('Segment', 'general');
$this->setKey('ResultFormat', 'command'); //$this->setKey('ResultFormat', 'command');
$this->setKey('DeviceName', $devicename); $this->setKey('DeviceName', $devicename);
$this->setResponseHandler("SCCPShowDevice"); $this->setResponseHandler("SCCPShowDevice");
} }
@ -404,8 +403,8 @@ class SCCPShowDevicesAction extends ActionMessage
public function __construct() public function __construct()
{ {
parent::__construct('SCCPShowDevices'); parent::__construct('SCCPShowDevices');
$this->setKey('Segment', 'general'); //$this->setKey('Segment', 'general');
$this->setKey('ResultFormat', 'command'); //$this->setKey('ResultFormat', 'command');
$this->setResponseHandler("SCCPShowDevices"); $this->setResponseHandler("SCCPShowDevices");
} }
} }

View file

@ -348,7 +348,8 @@ class aminterface
$_res = $this->send($_action)->getResult(); $_res = $this->send($_action)->getResult();
foreach ($_res as $key => $value) { foreach ($_res as $key => $value) {
foreach ($value as $key2 => $value2) { foreach ($value as $key2 => $value2) {
$result[$key.'@'.$key2] = $key.'@'.$key2; //$result[$key.'@'.$key2] = $key.'@'.$key2;
$result[$key.'@'.$key2] = ['key' => $key.'@'.$key2, 'exten' => $key, 'label' => $key.'@'.$key2];
} }
} }
} }

View file

@ -66,6 +66,9 @@ class dbinterface
$stmts->bindParam(':name', $data['name'],\PDO::PARAM_STR); $stmts->bindParam(':name', $data['name'],\PDO::PARAM_STR);
} }
break; break;
case 'sccpHints':
$stmtU = $this->db->prepare('SELECT name, name, label FROM sccpline ORDER BY name');
break;
case 'phoneGrid': case 'phoneGrid':
switch ($data['type']) { switch ($data['type']) {
case "cisco-sip": case "cisco-sip":

View file

@ -19,8 +19,8 @@ if ($_REQUEST['tech_hardware'] === 'cisco') {
} else { } else {
$lines_list = $this->dbinterface->getSipTableData('extensionList'); $lines_list = $this->dbinterface->getSipTableData('extensionList');
} }
// TODO: actually returning all hints - the filter is currently ignored.
$hint_list = $this->getHintInformation(true, array('context'=>'park-hints')); $hint_list = $this->getHintInformation(array('context'=>'park-hints'));
$line_id =0; $line_id =0;
$max_buttons =56; //Don't know hardware type so set a maximum. On save, this is set to actual max buttons $max_buttons =56; //Don't know hardware type so set a maximum. On save, this is set to actual max buttons