2 namespace callnotifier;
5 * Logs finished calls into a file, latest on top.
6 * The date is also show on a extra line, grouping the following calls.
8 * Suitable for Dreambox display with CurlyTx
13 * 07:48 nach Herbert 00:00:03
14 * 08:13 von 02426140162 00:02:21
16 class Logger_CallFileTop extends Logger_CallBase
21 * Create a new file call logger.
23 * @param string $file Path to the file to log the calls in.
24 * @param string $callTypes Which types of call to log:
25 * - "i" - incoming calls only
26 * - "o" - outgoing calls only
27 * - "io" - both incoming and outgoing calls
28 * @param array $msns Array of MSN (Multi Subscriber Number) that
29 * calls to shall get logged.
30 * If the array is empty, calls to all MSNs get
33 public function __construct(
39 $this->callTypes = $callTypes;
40 $this->msns = (array)$msns;
42 $fileHdl = fopen($this->file, 'a');
45 'Cannot open call log file for writing: ' . $this->file
51 public function log($type, $arData)
53 if ($type != 'finishedCall') {
57 $call = $arData['call'];
58 if (!$this->hasValidType($call)) {
61 if (!$this->hasValidMsn($call)) {
65 list($logline, $date) = $this->createLogEntry($call);
66 $arLines = file($this->file);
67 if (isset($arLines[0]) && $arLines[0] == $date) {
68 //same date as previous log entry
69 $arLines = array_pad($arLines, -count($arLines) - 1, '');
71 $arLines = array_pad($arLines, -count($arLines) - 2, '');
74 $arLines[1] = $logline;
77 array_splice($arLines, 50);
79 file_put_contents($this->file, implode('', $arLines));
83 protected function createLogEntry(CallMonitor_Call $call)
85 $this->addUnsetVars($call);
86 $str = ' ' . date('H:i', $call->start);
87 if ($call->type == CallMonitor_Call::INCOMING) {
89 $numstr = $this->getNumberString($call, 'from');
92 $numstr = $this->getNumberString($call, 'to');
95 if ($this->callTypes == 'io') {
97 $str .= str_pad($numstr, 20);
99 $str .= ' ' . str_pad($numstr, 25);
102 $str .= ' ' . date('H:i:s', $call->end - $call->start - 3600);
104 setlocale(LC_TIME, 'de_DE.utf-8');
105 return array($str . "\n", strftime("%x, %A\n", $call->start));