2 namespace callnotifier;
4 abstract class Logger_CallBase implements Logger
12 * Create a new call logger.
14 * @param string $callTypes Which types of call to log:
15 * - "i" - incoming calls only
16 * - "o" - outgoing calls only
17 * - "io" - both incoming and outgoing calls
18 * @param array $msns Array of MSN (Multi Subscriber Number) that
19 * calls to shall get logged.
20 * If the array is empty, calls to all MSNs get
23 public function __construct($callTypes = 'io', $msns = array())
25 $this->callTypes = $callTypes;
26 $this->msns = (array)$msns;
30 * Check if the call type (incoming or outgoing) shall be logged.
32 * @return boolean True if it should be logged, false if not
34 protected function hasValidType($call)
36 if ($call->type == CallMonitor_Call::INCOMING && $this->callTypes == 'o') {
37 $this->debug('No valid call type (requested: o)');
40 if ($call->type == CallMonitor_Call::OUTGOING && $this->callTypes == 'i') {
41 $this->debug('No valid call type (requested: i)');
49 * Check if the MSN shall be logged
51 * @return boolean True if it should be logged, false if not
53 protected function hasValidMsn($call)
55 if ($call->type == CallMonitor_Call::INCOMING) {
60 if (count($this->msns) > 0 && !in_array($msn, $this->msns)) {
61 //msn shall not be logged
62 $this->debug('No valid MSN (requested: ' . $msn . ')');
69 protected function addUnsetVars($call)
71 static $expectedVars = array(
72 'toName', 'fromName', 'toLocation', 'fromLocation'
74 foreach ($expectedVars as $varName) {
75 if (!isset($call->$varName)) {
76 $call->$varName = null;
82 protected function getNumberString($call, $type)
85 $varName = $type . 'Name';
86 $varLocation = $type . 'Location';
88 if ($call->$varName !== null) {
89 return $call->$varName;
92 $str = $this->getNumber($call->$varNumber);
93 if ($call->$varLocation !== null) {
94 $str .= ' aus ' . $call->$varLocation;
99 protected function getNumber($number)
102 $number = '*anonym*';
104 return str_pad($number, 12, ' ', STR_PAD_RIGHT);
107 protected function debug($msg)