link to my blog post
[auerswald-callnotifier.git] / src / callnotifier / Logger / CallEcho.php
1 <?php
2 namespace callnotifier;
3
4 class Logger_CallEcho extends Logger_CallBase
5 {
6     public function log($type, $arData)
7     {
8         switch ($type) {
9         case 'startingCall':
10             $displayMethod = 'displayStart';
11             break;
12         case 'finishedCall':
13             $displayMethod = 'displayFinished';
14             break;
15         default:
16             return;
17         }
18
19         $call = $arData['call'];
20         if (!$this->hasValidType($call)) {
21             return;
22         }
23         if (!$this->hasValidMsn($call)) {
24             return;
25         }
26         $this->$displayMethod($arData['call']);
27     }
28
29
30     protected function displayStart(CallMonitor_Call $call)
31     {
32         $this->addUnsetVars($call);
33         echo 'Starting ' . $this->getTypeName($call)
34             . ' call from ' . trim($this->getNumberString($call, 'from'))
35             . ' to ' . trim($this->getNumberString($call, 'to')) . "\n";
36     }
37
38     protected function displayFinished(CallMonitor_Call $call)
39     {
40         $this->addUnsetVars($call);
41         echo 'Finished ' . $this->getTypeName($call)
42             . ' call from ' . trim($this->getNumberString($call, 'from'))
43             . ' to ' . trim($this->getNumberString($call, 'to'))
44             . ', length ' . date('H:i:s', $call->end - $call->start - 3600)
45             . "\n";
46     }
47
48     protected function getTypeName($call)
49     {
50         return $call->type == CallMonitor_Call::INCOMING
51             ? 'incoming' : 'outgoing';
52     }
53 }
54 ?>