load call details on finished calls, too
[auerswald-callnotifier.git] / src / callnotifier / CallMonitor.php
index 428136fb5dff0df2757f249542e941677a95e9c0..4923967d793f767d4eac129a5b1e7b36e765e4d2 100644 (file)
@@ -13,12 +13,24 @@ class CallMonitor
 {
     protected $currentCalls = array();
 
+    /**
+     * Array of objects that are able to load details for a call
+     *
+     * @var array
+     */
+    protected $detaillers = array();
+
     public function __construct($config, $log)
     {
         $this->config = $config;
         $this->log = $log;
     }
 
+    public function addDetailler(CallMonitor_Detailler $detailler)
+    {
+        $this->detaillers[] = $detailler;
+    }
+
     public function handle(EDSS1_Message $msg)
     {
         $callId = $msg->callRef;
@@ -82,12 +94,16 @@ class CallMonitor
                     unset($this->currentCalls[$otherCallId]);
                 }
             }
+            $this->loadCallDetails($call);
             $this->log->log('startingCall', array('call' => $call));
             break;
 
         case EDSS1_Message::RELEASE:
         case EDSS1_Message::RELEASE_COMPLETE:
             $call->end = time();
+            //we need to load details here because they might not have been
+            //loaded yet, e.g. for calls to MSNs that have no phones.
+            $this->loadCallDetails($call);
             $this->log->log('finishedCall', array('call' => $call));
             unset($this->currentCalls[$callId]);
             break;
@@ -128,9 +144,24 @@ class CallMonitor
     {
         if ($type == EDSS1_Parameter_Names::NUMBER_NATIONAL) {
             return '0' . $number;
+        } else if ($type == EDSS1_Parameter_Names::NUMBER_INTERNATIONAL) {
+            return '+' . $number;
         }
         return $number;
     }
+
+    /**
+     * Load details for a call, e.g. the name of the calling person
+     * or the area
+     *
+     * @return void
+     */
+    protected function loadCallDetails($call)
+    {
+        foreach ($this->detaillers as $detailler) {
+            $detailler->loadCallDetails($call);
+        }
+    }
 }
 
 ?>