Passed
Push — develop ( cbb8ee...d8e961 )
by Портнов
05:39
created

ExternalPhonesConf::getSettings()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 13
rs 10
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * Copyright © MIKO LLC - All Rights Reserved
4
 * Unauthorized copying of this file, via any medium is strictly prohibited
5
 * Proprietary and confidential
6
 * Written by Alexey Portnov, 2 2020
7
 */
8
9
namespace MikoPBX\Core\Asterisk\Configs;
10
11
use MikoPBX\Common\Models\ExternalPhones;
12
use MikoPBX\Modules\Config\ConfigClass;
13
14
class ExternalPhonesConf extends ConfigClass
15
{
16
    private $arrExternalPhones;
17
18
    /**
19
     * Получение настроек с АТС.
20
     */
21
    public function getSettings(): void
22
    {
23
        $ext_data   = [];
24
        $ext_phones = ExternalPhones::find("disabled = '0' OR disabled IS NULL");
25
26
        foreach ($ext_phones as $ext_phone) {
27
            $ext_data[] = [
28
                'extension'  => $ext_phone->extension,
29
                'dialstring' => $ext_phone->dialstring,
30
            ];
31
        }
32
33
        $this->arrExternalPhones = $ext_data;
34
    }
35
36
    /**
37
     * Генерация внутреннего номерного плана.
38
     *
39
     * @return string
40
     */
41
    public function extensionGenInternal(): string
42
    {
43
        if ($this->arrExternalPhones===null){
44
            $this->getSettings();
45
        }
46
        $conf = '';
47
        foreach ($this->arrExternalPhones as $external) {
48
            $conf .= "exten => _{$external['extension']},1,Set(EXTERNALPHONE=" . $external['dialstring'] . ")\n\t";
49
            $conf .= "same => n,Goto(outgoing,{$external['dialstring']},1)\n\t";
50
            $conf .= "same => n,AGI(check_redirect.php,\${BLINDTRANSFER})\n";
51
        }
52
        $conf .= "\n";
53
54
        return $conf;
55
    }
56
57
    /**
58
     * @return string
59
     */
60
    public function extensionGenInternalTransfer(): string
61
    {
62
        if ($this->arrExternalPhones===null){
63
            $this->getSettings();
64
        }
65
        $conf = '';
66
        foreach ($this->arrExternalPhones as $external) {
67
            $conf .= 'exten => _' . $external['extension'] . ',1,Set(__ISTRANSFER=transfer_)' . " \n\t";
68
            $conf .= 'same => n,Goto(internal,${EXTEN},1)' . " \n";
69
        }
70
        $conf .= "\n";
71
72
        return $conf;
73
    }
74
75
    /**
76
     *
77
     * @return array
78
     */
79
    public function dependenceModels(): array
80
    {
81
        return [ExternalPhones::class];
82
    }
83
84
}
85