--- /dev/null
+<?php
+namespace callnotifier;
+
+/**
+ * Fetch caller names from a CSV file.
+ *
+ * The entries need to be separated by semicolons ";".
+ * The first line is interpreted as table head with column names.
+ *
+ * By default, column names "number" and "name" are used.
+ *
+ * Sets "toName" or "fromName", depending on call type.
+ */
+class CallMonitor_Detailler_CSV implements CallMonitor_Detailler
+{
+ protected $data = array();
+
+ /**
+ * Create new csv name resolver
+ *
+ * @param string $file Path to CSV file
+ * @param array $columns Names of the CSV columns that contain "number"
+ * and "name", e.g.
+ * array('number' => 'telephone', 'name' => 'name')
+ */
+ public function __construct($file, $columns = null)
+ {
+ if ($columns === null) {
+ $columns = array('number' => 'number', 'name' => 'name');
+ }
+ $columns = array_merge(
+ array('number' => 'number', 'name' => 'name'),
+ $columns
+ );
+ $this->loadFile($file, $columns);
+ }
+
+ protected function loadFile($file, $columns)
+ {
+ if (!is_readable($file)) {
+ throw new \Exception('CSV file not readable: ' . $file);
+ }
+ $handle = fopen($file, 'r');
+ if ($handle === false) {
+ throw new \Exception('Error opening CSV file: ' . $file);
+ }
+
+ $colPos = array();
+ $head = fgetcsv($handle, 1000, ';');
+ foreach ($columns as $key => $colName) {
+ $pos = array_search($colName, $head);
+ if ($pos === false) {
+ throw new \Exception(
+ 'CSV file does not have a colum with name: ' . $colName
+ );
+ }
+ $colPos[$key] = $pos;
+ }
+
+ while (($lineData = fgetcsv($handle, 1000, ';')) !== false) {
+ $this->data[$lineData[$colPos['number']]]
+ = $lineData[$colPos['name']];
+ }
+ }
+
+ public function loadCallDetails(CallMonitor_Call $call)
+ {
+ if ($call->type == CallMonitor_Call::INCOMING) {
+ $call->fromName = $this->loadName($call->from);
+ } else {
+ $call->toName = $this->loadName($call->to);
+ }
+ }
+
+ protected function loadName($number)
+ {
+ if (isset($this->data[$number])) {
+ return $this->data[$number];
+ }
+
+ return null;
+ }
+}
+
+?>
}
}
}
+
+
+ protected function getNumberString($call, $type)
+ {
+ $varNumber = $type;
+ $varName = $type . 'Name';
+ $varLocation = $type . 'Location';
+
+ if ($call->$varName !== null) {
+ return $call->$varName;
+ }
+
+ $str = $this->getNumber($call->$varNumber);
+ if ($call->$varLocation !== null) {
+ $str .= ' aus ' . $call->$varLocation;
+ }
+ return $str;
+ }
+
+ protected function getNumber($number)
+ {
+ if ($number == '') {
+ $number = '*anonym*';
+ }
+ return str_pad($number, 12, ' ', STR_PAD_RIGHT);
+ }
+
}
?>
<?php
namespace callnotifier;
-class Logger_CallEcho implements Logger
+class Logger_CallEcho extends Logger_CallBase
{
public function log($type, $arData)
{
protected function displayStart(CallMonitor_Call $call)
{
+ $this->addUnsetVars($call);
echo 'Starting ' . $this->getTypeName($call)
- . ' call from ' . $call->from
- . ' to ' . $call->to . "\n";
+ . ' call from ' . trim($this->getNumberString($call, 'from'))
+ . ' to ' . trim($this->getNumberString($call, 'to')) . "\n";
}
protected function displayFinished(CallMonitor_Call $call)
{
+ $this->addUnsetVars($call);
echo 'Finished ' . $this->getTypeName($call)
- . ' call from ' . $call->from
- . ' to ' . $call->to
+ . ' call from ' . trim($this->getNumberString($call, 'from'))
+ . ' to ' . trim($this->getNumberString($call, 'to'))
. ', length ' . date('H:i:s', $call->end - $call->start - 3600)
. "\n";
}
$str = date('Y-m-d H:i:s', $call->start);
if ($call->type == CallMonitor_Call::INCOMING) {
$str .= ' ' . $call->to
- . ' von ' . $call->fromName;
- if ($call->fromLocation) {
- $str .= ' aus ' . $call->fromLocation;
- }
- $str .= ' ' . $this->getNumber($call->from);
+ . ' von ' . $this->getNumberString($call, 'from');
} else {
$str .= ' ' . $call->from
- . ' nach ' . $call->toName;
- if ($call->toLocation) {
- $str .= ' aus ' . $call->toLocation;
- }
- $str .= ' ' . $this->getNumber($call->to);
+ . ' nach ' . $this->getNumberString($call, 'to');
}
$str .= ', Dauer ' . date('H:i:s', $call->end - $call->start - 3600);
return $str . "\n";
}
- protected function getNumber($number)
- {
- if ($number == '') {
- $number = '*anonym*';
- }
- return str_pad($number, 12, ' ', STR_PAD_RIGHT);
- }
-
}
?>