2 namespace callnotifier;
5 * Fetch location name from OpenGeoDb.
6 * In case of mobile phone numbers, the provider is named.
8 * It uses a custom table "my_orte" that can be created with
9 * docs/opengeodb-create-my_orte.sql
11 * Sets "toLocation" or "fromLocation", depending on call type
13 * @link http://opengeodb.org/
15 class CallMonitor_Detailler_OpenGeoDb implements CallMonitor_Detailler
18 protected static $mobile = array(
20 '0152' => 'Vodafone D2',
24 '0162' => 'Vodafone D2',
26 '0164' => 'Cityruf (e*message)',
29 '0172' => 'Vodafone D2',
30 '0173' => 'Vodafone D2',
31 '0174' => 'Vodafone D2',
40 * Create new detailler object
42 * @param string $dsn PDO connection string, for example
43 * 'mysql:host=dojo;dbname=opengeodb'
44 * @param string $username Database username
45 * @param string $password Database password
47 public function __construct($dsn, $username, $password)
50 $dsn, $username, $password,
52 \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
53 \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC
58 public function loadCallDetails(CallMonitor_Call $call)
60 if ($call->type == CallMonitor_Call::INCOMING) {
61 $call->fromLocation = $this->loadLocation($call->from);
63 $call->toLocation = $this->loadLocation($call->to);
67 protected function loadLocation($number)
69 if (substr($number, 0, 2) == '01') {
71 $prefix = substr($number, 0, 4);
72 if (isset(self::$mobile[$prefix])) {
73 return 'Handy: ' . self::$mobile[$prefix];
78 //FIXME: what about international numbers?
79 //area codes in germany can be 3 to 6 numbers
80 $stm = $this->db->query(
81 'SELECT name FROM my_orte'
82 . ' WHERE vorwahl = ' . $this->db->quote(substr($number, 0, 3))
83 . ' OR vorwahl = ' . $this->db->quote(substr($number, 0, 4))
84 . ' OR vorwahl = ' . $this->db->quote(substr($number, 0, 5))
85 . ' OR vorwahl = ' . $this->db->quote(substr($number, 0, 6))
86 . ' ORDER BY einwohner DESC'
90 implode(' - ', $this->db->errorInfo())