From 8e42bcadf70dffd3e6cdf52c5582ce7fd0dce868 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 2 Aug 2012 07:39:00 +0200 Subject: [PATCH] add incoming/outgoing type to calls --- src/callnotifier/CLI.php | 2 +- src/callnotifier/CallMonitor.php | 8 +++++++- src/callnotifier/CallMonitor/Call.php | 11 +++++++++++ src/callnotifier/Log.php | 2 +- src/callnotifier/Logger/CallEcho.php | 18 +++++++++++++----- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/callnotifier/CLI.php b/src/callnotifier/CLI.php index 6ec9a7e..2a6d3ca 100644 --- a/src/callnotifier/CLI.php +++ b/src/callnotifier/CLI.php @@ -32,7 +32,7 @@ class CLI } } $log->addLogger( - new Logger_CallEcho(), array('incomingCall', 'finishedCall') + new Logger_CallEcho(), array('startingCall', 'finishedCall') ); $callMonitor = new CallMonitor($this->config, $log); diff --git a/src/callnotifier/CallMonitor.php b/src/callnotifier/CallMonitor.php index af72e0a..29ee5a2 100644 --- a/src/callnotifier/CallMonitor.php +++ b/src/callnotifier/CallMonitor.php @@ -43,6 +43,12 @@ class CallMonitor { $call = $this->currentCalls[$callId]; $call->start = time(); + if ($msg->tei == 127) { + $call->type = CallMonitor_Call::INCOMING; + } else { + $call->type = CallMonitor_Call::OUTGOING; + } + $this->handleParams($call, $msg); } @@ -56,7 +62,7 @@ class CallMonitor $this->handleParams($call, $msg); break; case EDSS1_Message::CALL_PROCEEDING: - $this->log->log('incomingCall', array('call' => $call)); + $this->log->log('startingCall', array('call' => $call)); break; case EDSS1_Message::RELEASE: diff --git a/src/callnotifier/CallMonitor/Call.php b/src/callnotifier/CallMonitor/Call.php index 3ebd251..0f16ead 100644 --- a/src/callnotifier/CallMonitor/Call.php +++ b/src/callnotifier/CallMonitor/Call.php @@ -3,6 +3,17 @@ namespace callnotifier; class CallMonitor_Call { + const INCOMING = 'i'; + const OUTGOING = 'o'; + + /** + * Type of call: "i"ncoming or "o"utgoing + * + * @var string + */ + public $type; + + /** * Telephone number of caller * diff --git a/src/callnotifier/Log.php b/src/callnotifier/Log.php index 8a6b79a..d2ee0c8 100644 --- a/src/callnotifier/Log.php +++ b/src/callnotifier/Log.php @@ -13,7 +13,7 @@ class Log protected $logger = array( 'msgData' => array(), 'edss1msg' => array(), - 'incomingCall' => array(), + 'startingCall' => array(), 'finishedCall' => array(), ); diff --git a/src/callnotifier/Logger/CallEcho.php b/src/callnotifier/Logger/CallEcho.php index fe8b9b4..825bc24 100644 --- a/src/callnotifier/Logger/CallEcho.php +++ b/src/callnotifier/Logger/CallEcho.php @@ -6,8 +6,8 @@ class Logger_CallEcho implements Logger public function log($type, $arData) { switch ($type) { - case 'incomingCall': - $this->displayIncoming($arData['call']); + case 'startingCall': + $this->displayStart($arData['call']); break; case 'finishedCall': $this->displayFinished($arData['call']); @@ -16,18 +16,26 @@ class Logger_CallEcho implements Logger } - protected function displayIncoming(CallMonitor_Call $call) + protected function displayStart(CallMonitor_Call $call) { - echo 'Incoming call from ' . $call->from + echo 'Starting ' . $this->getTypeName($call) + . ' call from ' . $call->from . ' to ' . $call->to . "\n"; } protected function displayFinished(CallMonitor_Call $call) { - echo 'Finished call from ' . $call->from + echo 'Finished ' . $this->getTypeName($call) + . ' call from ' . $call->from . ' to ' . $call->to . ', length ' . date('H:i:s', $call->end - $call->start - 3600) . "\n"; } + + protected function getTypeName($call) + { + return $call->type == CallMonitor_Call::INCOMING + ? 'incoming' : 'outgoing'; + } } ?> -- 2.30.2