Passed
Push — develop ( e79a78...434ad3 )
by Портнов
04:56
created

ExtensionsAnnonceRecording::getPathAnnonceFile()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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