2 namespace callnotifier;
4 class Logger_CallFile extends Logger_CallBase
12 * Create a new file call logger. It logs finished calls into a file.
14 * @param string $file Path to the file to log the calls in.
15 * @param string $callTypes Which types of call to log:
16 * - "i" - incoming calls only
17 * - "o" - outgoing calls only
18 * - "io" - both incoming and outgoing calls
19 * @param array $msns Array of MSN (Multi Subscriber Number) that
20 * calls to shall get logged.
21 * If the array is empty, calls to all MSNs get
24 public function __construct(
30 $this->callTypes = $callTypes;
31 $this->msns = (array)$msns;
33 $this->fileHdl = fopen($this->file, 'a');
34 if (!$this->fileHdl) {
36 'Cannot open call log file for writing: ' . $this->file
41 public function log($type, $arData)
43 if ($type != 'finishedCall') {
47 $call = $arData['call'];
49 //check if call type matches
50 if ($call->type == CallMonitor_Call::INCOMING && $this->callTypes == 'o') {
53 if ($call->type == CallMonitor_Call::OUTGOING && $this->callTypes == 'i') {
57 if ($call->type == CallMonitor_Call::INCOMING) {
62 if (count($this->msns) > 0 && !in_array($msn, $this->msns)) {
63 //msn shall not be logged
67 fwrite($this->fileHdl, $this->createLogEntry($call));
71 protected function createLogEntry(CallMonitor_Call $call)
73 $this->addUnsetVars($call);
74 $str = date('Y-m-d H:i:s', $call->start);
75 if ($call->type == CallMonitor_Call::INCOMING) {
76 $str .= ' ' . $call->to
77 . ' von ' . $call->fromName;
78 if ($call->fromLocation) {
79 $str .= ' aus ' . $call->fromLocation;
81 $str .= ' ' . $this->getNumber($call->from);
83 $str .= ' ' . $call->from
84 . ' nach ' . $call->toName;
85 if ($call->toLocation) {
86 $str .= ' aus ' . $call->toLocation;
88 $str .= ' ' . $this->getNumber($call->to);
91 $str .= ', Dauer ' . date('H:i:s', $call->end - $call->start - 3600);
96 protected function getNumber($number)
101 return str_pad($number, 12, ' ', STR_PAD_RIGHT);