1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* MikoPBX - free phone system for small business |
4
|
|
|
* Copyright © 2017-2023 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\PBXCoreREST\Lib\Extensions; |
21
|
|
|
|
22
|
|
|
use MikoPBX\Common\Models\Extensions; |
23
|
|
|
use MikoPBX\Common\Models\ExternalPhones; |
24
|
|
|
use MikoPBX\Common\Models\Sip; |
25
|
|
|
|
26
|
|
|
class DataStructure { |
27
|
|
|
|
28
|
|
|
public ?string $id; |
29
|
|
|
|
30
|
|
|
public string $type = Extensions::TYPE_SIP; |
31
|
|
|
|
32
|
|
|
public string $show_in_phonebook = '1'; |
33
|
|
|
public string $is_general_user_number = '1'; |
34
|
|
|
public string $public_access = '0'; |
35
|
|
|
|
36
|
|
|
public string $number=''; |
37
|
|
|
|
38
|
|
|
public ?string $user_id=''; |
39
|
|
|
public string $user_avatar=''; |
40
|
|
|
public string $user_username=''; |
41
|
|
|
public string $user_email=''; |
42
|
|
|
public string $mobile_uniqid=''; |
43
|
|
|
public string $mobile_number=''; |
44
|
|
|
public string $mobile_dialstring=''; |
45
|
|
|
public ?string $sip_uniqid=''; |
46
|
|
|
|
47
|
|
|
public string $sip_secret=''; |
48
|
|
|
public string $sip_type = 'peer'; |
49
|
|
|
public string $sip_qualify = '1'; |
50
|
|
|
public int $sip_qualifyfreq = 60; |
51
|
|
|
public string $sip_enableRecording='1'; |
52
|
|
|
public string $sip_dtmfmode='auto'; |
53
|
|
|
public string $sip_transport = ' '; |
54
|
|
|
public string $sip_networkfilterid = 'none'; |
55
|
|
|
public string $sip_manualattributes=''; |
56
|
|
|
public string $fwd_ringlength='45'; |
57
|
|
|
public string $fwd_forwarding=''; |
58
|
|
|
public string $fwd_forwardingonbusy=''; |
59
|
|
|
public string $fwd_forwardingonunavailable=''; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* DataStructure constructor. |
63
|
|
|
* |
64
|
|
|
* Initializes a DataStructure instance with provided data. |
65
|
|
|
* If certain properties are empty, it assigns default values. |
66
|
|
|
* |
67
|
|
|
* @param array $data The input data to initialize the DataStructure. |
68
|
|
|
*/ |
69
|
|
|
public function __construct(array $data) { |
70
|
|
|
foreach ($data as $key => $value) { |
71
|
|
|
if (!property_exists($this, $key)) { |
72
|
|
|
continue; |
73
|
|
|
} |
74
|
|
|
// If value empty remain default value from property definition |
75
|
|
|
$this->$key = $value ?? $this->$key; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
if (empty($this->number)){ |
79
|
|
|
$this->number = Extensions::getNextInternalNumber(); |
80
|
|
|
} |
81
|
|
|
if (empty($this->sip_uniqid)){ |
82
|
|
|
$this->sip_uniqid = Sip::generateUniqueID(); |
83
|
|
|
} |
84
|
|
|
if (empty($this->sip_secret)){ |
85
|
|
|
$this->sip_secret = Sip::generateSipPassword(); |
86
|
|
|
} |
87
|
|
|
if (empty($this->mobile_uniqid)){ |
88
|
|
|
$this->mobile_uniqid = ExternalPhones::generateUniqueID(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Convert the DataStructure object to an associative array. |
95
|
|
|
* |
96
|
|
|
* @return array The DataStructure object as an associative array. |
97
|
|
|
*/ |
98
|
|
|
public function toArray(): array |
99
|
|
|
{ |
100
|
|
|
return get_object_vars($this); |
101
|
|
|
} |
102
|
|
|
} |