aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2012-08-04 23:26:16 +0200
committerChristian Weiske <cweiske@cweiske.de>2012-08-04 23:26:16 +0200
commit29ff32499e239e6189b80ef3b9e76384920205a7 (patch)
treebce5a98c6bae87490b1ef863acf0f08485b80675 /src
parentb8217d4cb0bdfea171cde633b0a196fc7dfd4a9d (diff)
downloadauerswald-callnotifier-29ff32499e239e6189b80ef3b9e76384920205a7.tar.gz
auerswald-callnotifier-29ff32499e239e6189b80ef3b9e76384920205a7.zip
begin work on call detaillers (load name from ldap, load location from opengeodb)
Diffstat (limited to 'src')
-rw-r--r--src/callnotifier/CLI.php2
-rw-r--r--src/callnotifier/CallMonitor.php26
-rw-r--r--src/callnotifier/CallMonitor/Detailler.php16
-rw-r--r--src/callnotifier/CallMonitor/Detailler/LDAP.php26
-rw-r--r--src/callnotifier/CallMonitor/Detailler/OpenGeoDb.php74
5 files changed, 144 insertions, 0 deletions
diff --git a/src/callnotifier/CLI.php b/src/callnotifier/CLI.php
index 2a6d3ca..8958f78 100644
--- a/src/callnotifier/CLI.php
+++ b/src/callnotifier/CLI.php
@@ -36,6 +36,8 @@ class CLI
);
$callMonitor = new CallMonitor($this->config, $log);
+ $callMonitor->addDetailler(new CallMonitor_Detailler_LDAP());
+ $callMonitor->addDetailler(new CallMonitor_Detailler_OpenGeoDb());
$handler = new MessageHandler($this->config, $log, $callMonitor);
diff --git a/src/callnotifier/CallMonitor.php b/src/callnotifier/CallMonitor.php
index 428136f..7c6168c 100644
--- a/src/callnotifier/CallMonitor.php
+++ b/src/callnotifier/CallMonitor.php
@@ -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,6 +94,7 @@ class CallMonitor
unset($this->currentCalls[$otherCallId]);
}
}
+ $this->loadCallDetails($call);
$this->log->log('startingCall', array('call' => $call));
break;
@@ -131,6 +144,19 @@ class CallMonitor
}
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);
+ }
+ }
}
?>
diff --git a/src/callnotifier/CallMonitor/Detailler.php b/src/callnotifier/CallMonitor/Detailler.php
new file mode 100644
index 0000000..188e765
--- /dev/null
+++ b/src/callnotifier/CallMonitor/Detailler.php
@@ -0,0 +1,16 @@
+<?php
+namespace callnotifier;
+
+interface CallMonitor_Detailler
+{
+ /**
+ * Loads additional data into the call, e.g. name of the caller
+ *
+ * @param CallMonitor_Call $call Call to update
+ *
+ * @return void
+ */
+ public function loadCallDetails(CallMonitor_Call $call);
+}
+
+?>
diff --git a/src/callnotifier/CallMonitor/Detailler/LDAP.php b/src/callnotifier/CallMonitor/Detailler/LDAP.php
new file mode 100644
index 0000000..833fd46
--- /dev/null
+++ b/src/callnotifier/CallMonitor/Detailler/LDAP.php
@@ -0,0 +1,26 @@
+<?php
+namespace callnotifier;
+
+class CallMonitor_Detailler_LDAP implements CallMonitor_Detailler
+{
+ public function __construct()
+ {
+ }
+
+ public function loadCallDetails(CallMonitor_Call $call)
+ {
+ if ($call->type == CallMonitor_Call::INCOMING) {
+ $call->fromName = $this->loadName($call->from);
+ } else {
+ $call->toName = $this->loadName($call->to);
+ }
+ }
+
+ protected function loadName($number)
+ {
+ return 'foo';
+ }
+
+}
+
+?>
diff --git a/src/callnotifier/CallMonitor/Detailler/OpenGeoDb.php b/src/callnotifier/CallMonitor/Detailler/OpenGeoDb.php
new file mode 100644
index 0000000..1260438
--- /dev/null
+++ b/src/callnotifier/CallMonitor/Detailler/OpenGeoDb.php
@@ -0,0 +1,74 @@
+<?php
+namespace callnotifier;
+
+class CallMonitor_Detailler_OpenGeoDb implements CallMonitor_Detailler
+{
+ protected $db;
+
+ public function __construct()
+ {
+ $this->db = new \PDO(
+ 'mysql:host=dojo;dbname=opengeodb',
+ 'opengeodb-read',
+ 'opengeodb',
+ array(
+ \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
+ \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC
+ )
+ );
+ }
+
+ public function loadCallDetails(CallMonitor_Call $call)
+ {
+ if ($call->type == CallMonitor_Call::INCOMING) {
+ $call->fromLocation = $this->loadLocation($call->from);
+ } else {
+ $call->toLocation = $this->loadLocation($call->to);
+ }
+ }
+
+ protected function loadLocation($number)
+ {
+ //area codes in germany can be 3 to 6 numbers
+ //FIXME: what about international numbers?
+ for ($n = 3; $n <= 6; $n++) {
+ $areacode = substr($number, 0, $n);
+ $name = $this->getNameForAreaCode($areacode);
+ if ($name !== null) {
+ return $name;
+ }
+ }
+
+ return null;
+ }
+
+ protected function getNameForAreaCode($areacode)
+ {
+ $stm = $this->db->query(
+ 'SELECT loc_id FROM geodb_textdata'
+ . ' WHERE text_type = "500400000"'//area code
+ . ' AND text_val = ' . $this->db->quote($areacode)
+ );
+ $res = $stm->fetch();
+ if ($res === false) {
+ //area code does not exist
+ return null;
+ }
+
+ $locId = $res['loc_id'];
+ $stm = $this->db->query(
+ 'SELECT text_val FROM geodb_textdata'
+ . ' WHERE text_type = "500100000"'//name
+ . ' AND loc_id = ' . $this->db->quote($locId)
+ );
+ $res = $stm->fetch();
+ if ($res === false) {
+ return null;
+ }
+
+ return $res['text_val'];
+ }
+
+}
+
+?>