-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcel.php
More file actions
68 lines (54 loc) · 1.68 KB
/
cel.php
File metadata and controls
68 lines (54 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
// execute like this:
// php cel.php | tee calls-info.csv
include 'classes/CEL_Call.php';
include 'classes/CEL_Event.php';
include 'classes/CEL_Events_Collection.php';
include 'classes/MPA_CEL_Call.php';
include 'classes/safemysql.class.php';
$db_options = array(
'user' => 'user',
'pass' => 'pass',
'db' => 'asteriskcdrdb',
'charset' => 'utf8'
);
// prepare calls.txt file with linkedids
// for example, using SQL:
// select linkedid from cel where eventtime >= '2019-09-01 00:00:00' and eventtype='LINKEDID_END' into outfile 'calls.txt';
$calls_arr = file('calls.txt', FILE_IGNORE_NEW_LINES);
$fields = [
'linkedid',
'start',
'weekday',
'worktime',
'answered',
'holdtime',
'direction',
'cid',
'did',
'source_peer',
'bridged_peer',
];
echo implode(',', $fields) . PHP_EOL;
foreach ($calls_arr as $linkedid) {
// you can extend CEL_Call or MPA_CEL_Call classes with your own business logic
// (for example, you can check call direction based on DID length or work time with your own schedule)
// MPA_CEL_Call is just one of many possible logic implementations, special for each PBX installation
$call = new MPA_CEL_Call($linkedid, $db_options);
// loads CEL events of given linkedid from DB
$call->load();
$csv = [
$linkedid,
$call->getStartTimestamp()->format('Y-m-d H:i:s'),
$call->getStartTimestamp()->format('D'),
$call->isWorkTime() ? '1' : '0',
$call->isAnswered() ? '1' : '0',
$call->getTimeBeforeHumanAnswer(),
$call->getDirection(),
$call->getCID(),
$call->getDID(),
$call->getSourcePeer(),
$call->getBridgedPeer(),
];
echo implode(',', $csv) . PHP_EOL;
}