2 namespace callnotifier;
4 class CallMonitor_Detailler_OpenGeoDb implements CallMonitor_Detailler
7 protected static $mobile = array(
9 '0152' => 'Vodafone D2',
13 '0162' => 'Vodafone D2',
15 '0164' => 'Cityruf (e*message)',
18 '0172' => 'Vodafone D2',
19 '0173' => 'Vodafone D2',
20 '0174' => 'Vodafone D2',
28 public function __construct()
31 'mysql:host=dojo;dbname=opengeodb',
35 \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
36 \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC
41 public function loadCallDetails(CallMonitor_Call $call)
43 if ($call->type == CallMonitor_Call::INCOMING) {
44 $call->fromLocation = $this->loadLocation($call->from);
46 $call->toLocation = $this->loadLocation($call->to);
50 protected function loadLocation($number)
52 if (substr($number, 0, 2) == '01') {
54 $prefix = substr($number, 0, 4);
55 if (isset(self::$mobile[$prefix])) {
56 return 'Handy: ' . self::$mobile[$prefix];
60 //area codes in germany can be 3 to 6 numbers
61 //FIXME: what about international numbers?
62 for ($n = 3; $n <= 6; $n++) {
63 $areacode = substr($number, 0, $n);
64 $name = $this->getNameForAreaCode($areacode);
73 protected function getNameForAreaCode($areacode)
75 $stm = $this->db->query(
76 'SELECT loc_id FROM geodb_textdata'
77 . ' WHERE text_type = "500400000"'//area code
78 . ' AND text_val = ' . $this->db->quote($areacode)
82 //area code does not exist
86 $locId = $res['loc_id'];
87 $stm = $this->db->query(
88 'SELECT text_val FROM geodb_textdata'
89 . ' WHERE text_type = "500100000"'//name
90 . ' AND loc_id = ' . $this->db->quote($locId)
97 return $res['text_val'];