blob: 12a5b08f2548eb128a3638a719a4a7b4b0f84188 (
plain)
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
69
70
71
72
73
74
75
76
|
<?php
namespace callnotifier;
class Logger_CallFile extends Logger_CallBase
{
protected $file;
protected $fileHdl;
/**
* Create a new file call logger. It logs finished calls into a file.
*
* @param string $file Path to the file to log the calls in.
* @param string $callTypes Which types of call to log:
* - "i" - incoming calls only
* - "o" - outgoing calls only
* - "io" - both incoming and outgoing calls
* @param array $msns Array of MSN (Multi Subscriber Number) that
* calls to shall get logged.
* If the array is empty, calls to all MSNs get
* logged.
*/
public function __construct(
$file,
$callTypes = 'io',
$msns = array()
) {
$this->file = $file;
$this->callTypes = $callTypes;
$this->msns = (array)$msns;
$this->fileHdl = fopen($this->file, 'a');
if (!$this->fileHdl) {
throw new \Exception(
'Cannot open call log file for writing: ' . $this->file
);
}
}
public function log($type, $arData)
{
if ($type != 'finishedCall') {
return;
}
$call = $arData['call'];
if (!$this->hasValidType($call)) {
return;
}
if (!$this->hasValidMsn($call)) {
return;
}
fwrite($this->fileHdl, $this->createLogEntry($call));
}
protected function createLogEntry(CallMonitor_Call $call)
{
$this->addUnsetVars($call);
$str = date('Y-m-d H:i:s', $call->start);
if ($call->type == CallMonitor_Call::INCOMING) {
$str .= ' ' . $call->to
. ' von ' . $this->getNumberString($call, 'from');
} else {
$str .= ' ' . $call->from
. ' nach ' . $this->getNumberString($call, 'to');
}
$str .= ', Dauer ' . date('H:i:s', $call->end - $call->start - 3600);
return $str . "\n";
}
}
?>
|