1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* MikoPBX - free phone system for small business |
4
|
|
|
* Copyright (C) 2017-2020 Alexey Portnov and Nikolay Beketov |
5
|
|
|
* |
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU General Public License as published by |
8
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* This program is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU General Public License for more details. |
15
|
|
|
* |
16
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
17
|
|
|
* If not, see <https://www.gnu.org/licenses/>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace MikoPBX\Core\Asterisk; |
21
|
|
|
|
22
|
|
|
use Throwable; |
23
|
|
|
use MikoPBX\Core\System\{Util}; |
24
|
|
|
use Phalcon\Di; |
25
|
|
|
use SQLite3; |
26
|
|
|
|
27
|
|
|
class AstDB extends Di\Injectable |
28
|
|
|
{ |
29
|
|
|
private AsteriskManager $am; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* AstDB constructor. |
33
|
|
|
*/ |
34
|
|
|
public function __construct() |
35
|
|
|
{ |
36
|
|
|
$di = Di::getDefault(); |
37
|
|
|
if($di === null){ |
38
|
|
|
$this->am = Util::getAstManager('off'); |
39
|
|
|
return; |
40
|
|
|
} |
41
|
|
|
$this->am = Util::getAstManager('off'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Поместить значение в базу данных. |
46
|
|
|
* |
47
|
|
|
* @param $family |
48
|
|
|
* @param $key |
49
|
|
|
* @param $value |
50
|
|
|
* |
51
|
|
|
* @return bool |
52
|
|
|
*/ |
53
|
|
|
public function databasePut($family, $key, $value): bool |
54
|
|
|
{ |
55
|
|
|
$result = false; |
56
|
|
|
if ($this->am->loggedIn() ) { |
57
|
|
|
$result = $this->databasePutAmi($family, $key, $value); |
58
|
|
|
} |
59
|
|
|
return $result; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Поместить значение в базу данных через AMI. |
64
|
|
|
* |
65
|
|
|
* @param $family |
66
|
|
|
* @param $key |
67
|
|
|
* @param $value |
68
|
|
|
* |
69
|
|
|
* @return bool |
70
|
|
|
*/ |
71
|
|
|
private function databasePutAmi($family, $key, $value): bool |
72
|
|
|
{ |
73
|
|
|
$result = false; |
74
|
|
|
$res_data = $this->am->DBPut($family, $key, $value); |
75
|
|
|
$response = $res_data['Response'] ?? ''; |
76
|
|
|
if (is_array($res_data) && 'Success' === $response) { |
77
|
|
|
$result = true; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $result; |
81
|
|
|
} |
82
|
|
|
} |