--- /dev/null
+CREATE TABLE `finished` (
+ `call_id` int(11) NOT NULL AUTO_INCREMENT,
+ `call_start` datetime NOT NULL,
+ `call_end` datetime NOT NULL,
+ `call_type` varchar(1) NOT NULL,
+ `call_from` varchar(32) DEFAULT NULL,
+ `call_from_name` varchar(32) DEFAULT NULL,
+ `call_from_location` varchar(32) DEFAULT NULL,
+ `call_to` varchar(32) DEFAULT NULL,
+ `call_to_name` varchar(32) DEFAULT NULL,
+ `call_to_location` varchar(32) DEFAULT NULL,
+ `call_length` int(11) NOT NULL,
+ PRIMARY KEY (`call_id`)
+) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COMMENT='finished calls';
--- /dev/null
+#!/bin/sh
+cd "`dirname "$0"`"
+
+mysqldump -ucallnotifier -pcallnotifier callnotifier\
+ -d --skip-add-drop-table --skip-comments\
+ | grep -v '/*!'\
+ | grep -v '^$'\
+ > ../docs/call-log.sql
\ No newline at end of file
new Logger_CallFile('all.log'),
array('finishedCall')
);
+ $log->addLogger(
+ new Logger_CallDb(
+ 'mysql:host=localhost;dbname=callnotifier',
+ 'callnotifier',
+ 'callnotifier'
+ ),
+ array('finishedCall')
+ );
$handler = new MessageHandler($this->config, $log, $callMonitor);
--- /dev/null
+<?php
+namespace callnotifier;
+
+abstract class Logger_CallBase implements Logger
+{
+ protected function addUnsetVars($call)
+ {
+ static $expectedVars = array(
+ 'toName', 'fromName', 'toLocation', 'fromLocation'
+ );
+ foreach ($expectedVars as $varName) {
+ if (!isset($call->$varName)) {
+ $call->$varName = null;
+ }
+ }
+ }
+}
+
+?>
--- /dev/null
+<?php
+namespace callnotifier;
+
+class Logger_CallDb extends Logger_CallBase
+{
+ /**
+ * Create new detailler object
+ *
+ * @param string $dsn PDO connection string, for example
+ * 'mysql:host=dojo;dbname=opengeodb'
+ * @param string $username Database username
+ * @param string $password Database password
+ */
+ public function __construct($dsn, $username, $password)
+ {
+ $this->db = new \PDO(
+ $dsn, $username, $password,
+ array(
+ \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
+ \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC
+ )
+ );
+ $this->stmt = $this->db->prepare(
+ 'INSERT INTO finished ('
+ . ' call_start'
+ . ', call_end'
+ . ', call_type'
+ . ', call_from'
+ . ', call_from_name'
+ . ', call_from_location'
+ . ', call_to'
+ . ', call_to_name'
+ . ', call_to_location'
+ . ', call_length'
+ . ') VALUES ('
+ . ' :call_start'
+ . ', :call_end'
+ . ', :call_type'
+ . ', :call_from'
+ . ', :call_from_name'
+ . ', :call_from_location'
+ . ', :call_to'
+ . ', :call_to_name'
+ . ', :call_to_location'
+ . ', :call_length'
+ . ')'
+ );
+ }
+
+ public function log($type, $arData)
+ {
+ if ($type != 'finishedCall') {
+ return;
+ }
+
+ $call = $arData['call'];
+ $this->addUnsetVars($call);
+
+ $ret = $this->stmt->execute(
+ array(
+ 'call_start' => date('Y-m-d H:i:s', $call->start),
+ 'call_end' => date('Y-m-d H:i:s', $call->end),
+ 'call_type' => $call->type,
+ 'call_from' => $call->from,
+ 'call_from_name' => $call->fromName,
+ 'call_from_location' => $call->fromLocation,
+ 'call_to' => $call->to,
+ 'call_to_name' => $call->toName,
+ 'call_to_location' => $call->toLocation,
+ 'call_length' => $call->end - $call->start
+ )
+ );
+ if ($ret === false) {
+ throw new \Exception(
+ 'Error logging call to database: '
+ . implode(' / ', $this->stmt->errorInfo())
+ );
+ }
+ }
+
+}
+
+?>
<?php
namespace callnotifier;
-class Logger_CallFile implements Logger
+class Logger_CallFile extends Logger_CallBase
{
protected $file;
protected $fileHdl;
return str_pad($number, 12, ' ', STR_PAD_RIGHT);
}
- protected function addUnsetVars($call)
- {
- static $expectedVars = array(
- 'toName', 'fromName', 'toLocation', 'fromLocation'
- );
- foreach ($expectedVars as $varName) {
- if (!isset($call->$varName)) {
- $call->$varName = null;
- }
- }
- }
-
}
?>