5 seconds timeout
[auerswald-callnotifier.git] / src / callnotifier / Logger / CallNotifySend.php
1 <?php
2 namespace callnotifier;
3
4 class Logger_CallNotifySend extends Logger_CallBase
5 {
6     public function log($type, $arData)
7     {
8         switch ($type) {
9         case 'startingCall':
10             $this->displayStart($arData['call']);
11             break;
12         case 'finishedCall':
13             $this->displayFinished($arData['call']);
14             break;
15         }
16     }
17
18
19     protected function displayStart(CallMonitor_Call $call)
20     {
21         $this->addUnsetVars($call);
22         if ($call->type == CallMonitor_Call::INCOMING) {
23             $this->notify(
24                 trim($this->getNumberString($call, 'from')),
25                 'Incoming call'
26             );
27         } else {
28             $this->notify(
29                 trim($this->getNumberString($call, 'to')),
30                 'Outgoing call'
31             );
32         }
33     }
34
35     protected function displayFinished(CallMonitor_Call $call)
36     {
37         $this->addUnsetVars($call);
38         if ($call->type == CallMonitor_Call::INCOMING) {
39             $title = trim($this->getNumberString($call, 'from'));
40             $msg   = 'End of incoming call';
41         } else {
42             $title = trim($this->getNumberString($call, 'to'));
43             $msg   = 'End of outgoing call';
44         }
45         $this->notify(
46             $title,
47             $msg
48             . ', length ' . date('H:i:s', $call->end - $call->start - 3600)
49         );
50     }
51
52     protected function notify($title, $msg)
53     {
54         exec(
55             'notify-send'
56             . ' -u low'
57             . ' --expire-time=5000'
58             . ' -i phone'
59             . ' -c callmonitor'
60             . ' ' . escapeshellarg($title)
61             . ' ' . escapeshellarg($msg)
62         );
63     }
64 }
65 ?>