Passed
Push — develop ( d5179e...bede24 )
by Портнов
05:56 queued 11s
created

ActionMeetmeDial   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 21
c 1
b 0
f 0
dl 0
loc 40
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 33 5
1
<?php
2
/*
3
 * MikoPBX - free phone system for small business
4
 * Copyright © 2017-2021 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\Workers\Libs\WorkerCallEvents;
21
22
23
use MikoPBX\Common\Models\CallDetailRecordsTmp;
24
use MikoPBX\Core\Workers\WorkerCallEvents;
25
26
class ActionMeetmeDial
27
{
28
    /**
29
     * Событие входа в конференцкомнату.
30
     * @param $worker
31
     * @param $data
32
     */
33
    public static function execute(WorkerCallEvents $worker, $data):void
34
    {
35
        $worker->StopMixMonitor($data['src_chan']);
36
37
        if (strpos($data['src_chan'], 'internal-originate') !== false) {
38
            // Уточним канал и ID записи;
39
            $filter = [
40
                'linkedid=:linkedid: AND src_num=:src_num:',
41
                'bind' => [
42
                    'linkedid' => $data['linkedid'],
43
                    'src_num'  => $data['src_num'],
44
                ],
45
            ];
46
            /** @var CallDetailRecordsTmp $m_data */
47
            /** @var CallDetailRecordsTmp $row */
48
            $m_data = CallDetailRecordsTmp::findFirst($filter);
49
            if ($m_data !== null) {
50
                $data['src_chan'] = $m_data->src_chan;
51
                $m_data->UNIQUEID = $data['UNIQUEID'];
52
53
                $f_list = $m_data->toArray();
54
                foreach ($data as $attribute => $value) {
55
                    if ( ! array_key_exists($attribute, $f_list)) {
56
                        continue;
57
                    }
58
                    $m_data->writeAttribute($attribute, $value);
59
                }
60
                // Переопределяем идентификатор, это Originate на конференцию.
61
                $m_data->save();
62
            }
63
        } else {
64
            InsertDataToDB::execute($data);
65
            ActionAppEnd::execute($worker, $data);
66
        }
67
    }
68
69
}