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(
21 $dsn, $username, $password,
22 $callTypes = 'i', $msns = array()
24 parent::__construct($callTypes, $msns);
26 $dsn, $username, $password,
28 \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
29 \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC
32 $this->stmt = $this->db->prepare(
33 'INSERT INTO finished ('
39 . ', call_from_location'
42 . ', call_to_location'
50 . ', :call_from_location'
53 . ', :call_to_location'
59 public function log($type, $arData)
61 if ($type != 'finishedCall') {
65 $call = $arData['call'];
66 if (!$this->hasValidType($call)) {
69 if (!$this->hasValidMsn($call)) {
73 $this->addUnsetVars($call);
75 $ret = $this->stmt->execute(
77 'call_start' => date('Y-m-d H:i:s', $call->start),
78 'call_end' => date('Y-m-d H:i:s', $call->end),
79 'call_type' => $call->type,
80 'call_from' => $call->from,
81 'call_from_name' => $call->fromName,
82 'call_from_location' => $call->fromLocation,
83 'call_to' => $call->to,
84 'call_to_name' => $call->toName,
85 'call_to_location' => $call->toLocation,
86 'call_length' => $call->end - $call->start
91 'Error logging call to database: '
92 . implode(' / ', $this->stmt->errorInfo())