diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2012-08-07 15:07:05 +0200 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2012-08-07 15:07:05 +0200 |
| commit | 67eb8026d25dd261358ef5de1c8a5a6111a8e282 (patch) | |
| tree | 16758caaa50b7e60f49757ebcef85e00375f2ef4 /src/callnotifier/Logger/CallDb.php | |
| parent | f4bd5ef0c711aa9a3d0f6b468370a8c14c0e247a (diff) | |
| download | auerswald-callnotifier-67eb8026d25dd261358ef5de1c8a5a6111a8e282.tar.gz auerswald-callnotifier-67eb8026d25dd261358ef5de1c8a5a6111a8e282.zip | |
call logging to database
Diffstat (limited to 'src/callnotifier/Logger/CallDb.php')
| -rw-r--r-- | src/callnotifier/Logger/CallDb.php | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/callnotifier/Logger/CallDb.php b/src/callnotifier/Logger/CallDb.php new file mode 100644 index 0000000..110e963 --- /dev/null +++ b/src/callnotifier/Logger/CallDb.php @@ -0,0 +1,83 @@ +<?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()) + ); + } + } + +} + +?> |
