2 namespace callnotifier;
5 * Logs finished calls into a SQL database.
7 * To use this, setup the database table using the script
8 * in docs/create-call-log.sql
10 class Logger_CallDb extends Logger_CallBase
13 * Create new detailler object
15 * @param string $dsn PDO connection string, for example
16 * 'mysql:host=dojo;dbname=opengeodb'
17 * @param string $username Database username
18 * @param string $password Database password
20 public function __construct($dsn, $username, $password)
23 $dsn, $username, $password,
25 \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
26 \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC
29 $this->stmt = $this->db->prepare(
30 'INSERT INTO finished ('
36 . ', call_from_location'
39 . ', call_to_location'
47 . ', :call_from_location'
50 . ', :call_to_location'
56 public function log($type, $arData)
58 if ($type != 'finishedCall') {
62 $call = $arData['call'];
63 $this->addUnsetVars($call);
65 $ret = $this->stmt->execute(
67 'call_start' => date('Y-m-d H:i:s', $call->start),
68 'call_end' => date('Y-m-d H:i:s', $call->end),
69 'call_type' => $call->type,
70 'call_from' => $call->from,
71 'call_from_name' => $call->fromName,
72 'call_from_location' => $call->fromLocation,
73 'call_to' => $call->to,
74 'call_to_name' => $call->toName,
75 'call_to_location' => $call->toLocation,
76 'call_length' => $call->end - $call->start
81 'Error logging call to database: '
82 . implode(' / ', $this->stmt->errorInfo())