Passed
Push — develop ( 9ad4d7...e79a78 )
by Портнов
04:33
created

ExtensionsAnnonceRecording::extensionGenContexts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 11
rs 9.9666
cc 1
nc 1
nop 0
1
<?php
2
//
3
4
5
namespace MikoPBX\Core\Asterisk\Configs;
6
7
use MikoPBX\Common\Models\OutWorkTimes;
8
use MikoPBX\Common\Models\SoundFiles;
9
use MikoPBX\Core\System\Util;
10
11
class ExtensionsAnnonceRecording extends CoreConfigClass
12
{
13
    /**
14
     * Генератор extensions, дополнительные контексты.
15
     * @return string
16
     */
17
    public function extensionGenContexts(): string
18
    {
19
        return  '[annonce-spy]'. PHP_EOL.
20
                'exten => _.!,1,ExecIf($[ "${EXTEN}" == "h" ]?Hangup()'. PHP_EOL."\t".
21
	            'same => n,ExecIf($["${CHANNELS(PJSIP/${EXTEN})}x" != "x" && "${PBX_REC_ANNONCE}x" != "x"]?Chanspy(PJSIP/${EXTEN},uBq))'. PHP_EOL."\t".
22
                'same => n,Hangup()'.PHP_EOL
23
                .PHP_EOL.
24
                '[annonce-playback]'.PHP_EOL.
25
                'exten => annonce,1,Answer()'.PHP_EOL."\t".
26
	            'same => n,ExecIf("${PBX_REC_ANNONCE}x" != "x"]?Playback(${PBX_REC_ANNONCE}))'.PHP_EOL."\t".
27
                'same => n,Hangup()'.PHP_EOL;
28
    }
29
30
    /**
31
     * Prepares additional parameters for [globals] section in the extensions.conf file
32
     *
33
     * @return string
34
     */
35
    public function extensionGlobals(): string
36
    {
37
        $filename = '';
38
        $id = $this->generalSettings['PBXRecordAnnouncement'];
39
        if(!empty($id)){
40
            /** @var SoundFiles $fileData */
41
            $fileData = SoundFiles::findFirst($id);
42
            if($fileData){
0 ignored issues
show
introduced by
$fileData is of type MikoPBX\Common\Models\SoundFiles, thus it always evaluated to true.
Loading history...
43
                $filename = Util::trimExtensionForFile($fileData->path);
44
            }
45
        }
46
47
        return "PBX_REC_ANNONCE={$filename}".PHP_EOL;
48
    }
49
50
    /**
51
     * Prepares additional parameters for each outgoing route context
52
     * before dial call in the extensions.conf file
53
     *
54
     * @param array $rout
55
     *
56
     * @return string
57
     */
58
    public function generateOutRoutContext(array $rout): string
59
    {
60
        return 'same => n,Set(_OUT_NEED_ANNONCE=1)' . "\n\t";
61
    }
62
63
    /**
64
     * Prepares additional parameters for each incoming context for each incoming route before dial in the
65
     * extensions.conf file
66
     *
67
     * @param string $rout_number
68
     *
69
     * @return string
70
     */
71
    public function generateIncomingRoutBeforeDial(string $rout_number): string
72
    {
73
        return 'same => n,Set(IN_NEED_ANNONCE=1)' . "\n\t";
74
    }
75
76
}