2 namespace callnotifier;
4 abstract class Logger_CallBase implements Logger
11 * Create a new call logger.
13 * @param string $callTypes Which types of call to log:
14 * - "i" - incoming calls only
15 * - "o" - outgoing calls only
16 * - "io" - both incoming and outgoing calls
17 * @param array $msns Array of MSN (Multi Subscriber Number) that
18 * calls to shall get logged.
19 * If the array is empty, calls to all MSNs get
22 public function __construct($callTypes = 'io', $msns = array())
24 $this->callTypes = $callTypes;
25 $this->msns = (array)$msns;
29 * Check if the call type (incoming or outgoing) shall be logged.
31 * @return boolean True if it should be logged, false if not
33 protected function hasValidType($call)
35 if ($call->type == CallMonitor_Call::INCOMING && $this->callTypes == 'o') {
38 if ($call->type == CallMonitor_Call::OUTGOING && $this->callTypes == 'i') {
46 * Check if the MSN shall be logged
48 * @return boolean True if it should be logged, false if not
50 protected function hasValidMsn($call)
52 if ($call->type == CallMonitor_Call::INCOMING) {
57 if (count($this->msns) > 0 && !in_array($msn, $this->msns)) {
58 //msn shall not be logged
65 protected function addUnsetVars($call)
67 static $expectedVars = array(
68 'toName', 'fromName', 'toLocation', 'fromLocation'
70 foreach ($expectedVars as $varName) {
71 if (!isset($call->$varName)) {
72 $call->$varName = null;
78 protected function getNumberString($call, $type)
81 $varName = $type . 'Name';
82 $varLocation = $type . 'Location';
84 if ($call->$varName !== null) {
85 return $call->$varName;
88 $str = $this->getNumber($call->$varNumber);
89 if ($call->$varLocation !== null) {
90 $str .= ' aus ' . $call->$varLocation;
95 protected function getNumber($number)
100 return str_pad($number, 12, ' ', STR_PAD_RIGHT);