abstract class Logger_CallBase implements Logger
{
+ protected $callTypes;
+ protected $msns;
+
+
+ /**
+ * Create a new call logger.
+ *
+ * @param string $callTypes Which types of call to log:
+ * - "i" - incoming calls only
+ * - "o" - outgoing calls only
+ * - "io" - both incoming and outgoing calls
+ * @param array $msns Array of MSN (Multi Subscriber Number) that
+ * calls to shall get logged.
+ * If the array is empty, calls to all MSNs get
+ * logged.
+ */
+ public function __construct($callTypes = 'io', $msns = array())
+ {
+ $this->callTypes = $callTypes;
+ $this->msns = (array)$msns;
+ }
+
+ /**
+ * Check if the call type (incoming or outgoing) shall be logged.
+ *
+ * @return boolean True if it should be logged, false if not
+ */
+ protected function hasValidType($call)
+ {
+ if ($call->type == CallMonitor_Call::INCOMING && $this->callTypes == 'o') {
+ return false;
+ }
+ if ($call->type == CallMonitor_Call::OUTGOING && $this->callTypes == 'i') {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Check if the MSN shall be logged
+ *
+ * @return boolean True if it should be logged, false if not
+ */
+ protected function hasValidMsn($call)
+ {
+ if ($call->type == CallMonitor_Call::INCOMING) {
+ $msn = $call->to;
+ } else {
+ $msn = $call->from;
+ }
+ if (count($this->msns) > 0 && !in_array($msn, $this->msns)) {
+ //msn shall not be logged
+ return false;
+ }
+
+ return true;
+ }
+
protected function addUnsetVars($call)
{
static $expectedVars = array(
* @param string $username Database username
* @param string $password Database password
*/
- public function __construct($dsn, $username, $password)
- {
+ public function __construct(
+ $dsn, $username, $password,
+ $callTypes = 'i', $msns = array()
+ ) {
+ parent::__construct($callTypes, $msns);
$this->db = new \PDO(
$dsn, $username, $password,
array(
}
$call = $arData['call'];
+ if (!$this->hasValidType($call)) {
+ return;
+ }
+ if (!$this->hasValidMsn($call)) {
+ return;
+ }
+
$this->addUnsetVars($call);
$ret = $this->stmt->execute(
{
protected $host;
- public function __construct($host)
+ public function __construct($host, $callTypes = 'i', $msns = array())
{
+ parent::__construct($callTypes, $msns);
$this->host = $host;
}
public function log($type, $arData)
{
- switch ($type) {
- case 'startingCall':
- $this->displayStart($arData['call']);
- break;
+ if ($type != 'startingCall') {
+ return;
+ }
+
+ $call = $arData['call'];
+ if (!$this->hasValidType($call)) {
+ return;
+ }
+ if (!$this->hasValidMsn($call)) {
+ return;
}
+ $this->displayStart($call);
}
{
switch ($type) {
case 'startingCall':
- $this->displayStart($arData['call']);
+ $displayMethod = 'displayStart';
break;
case 'finishedCall':
- $this->displayFinished($arData['call']);
+ $displayMethod = 'displayFinished';
break;
+ default:
+ return;
}
+
+ $call = $arData['call'];
+ if (!$this->hasValidType($call)) {
+ return;
+ }
+ if (!$this->hasValidMsn($call)) {
+ return;
+ }
+ $this->$displayMethod($arData['call']);
}
{
protected $file;
protected $fileHdl;
- protected $callTypes;
- protected $msns;
/**
* Create a new file call logger. It logs finished calls into a file.
}
$call = $arData['call'];
-
- //check if call type matches
- if ($call->type == CallMonitor_Call::INCOMING && $this->callTypes == 'o') {
- return;
- }
- if ($call->type == CallMonitor_Call::OUTGOING && $this->callTypes == 'i') {
+ if (!$this->hasValidType($call)) {
return;
}
-
- if ($call->type == CallMonitor_Call::INCOMING) {
- $msn = $call->to;
- } else {
- $msn = $call->from;
- }
- if (count($this->msns) > 0 && !in_array($msn, $this->msns)) {
- //msn shall not be logged
+ if (!$this->hasValidMsn($call)) {
return;
}
{
switch ($type) {
case 'startingCall':
- $this->displayStart($arData['call']);
+ $displayMethod = 'displayStart';
break;
case 'finishedCall':
- $this->displayFinished($arData['call']);
+ $displayMethod = 'displayFinished';
break;
+ default:
+ return;
}
+
+ $call = $arData['call'];
+ if (!$this->hasValidType($call)) {
+ return;
+ }
+ if (!$this->hasValidMsn($call)) {
+ return;
+ }
+ $this->$displayMethod($arData['call']);
}