/** * dial number * * @param int $number phone number * @param string $phoneId phone id * @param string $lineId phone line id * @return array */ public function dialNumber($number, $phoneId, $lineId) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Dialing number {$number} with {$phoneId} (line {$lineId})"); } Phone_Controller::getInstance()->dialNumber($number, $phoneId, $lineId); return array('success' => TRUE); }
/** * Search for calls matching given arguments * * @param array $filter * @param array $paging * @return array */ public function searchCalls($filter, $paging) { $filter = new Phone_Model_CallFilter($filter); $pagination = new Tinebase_Model_Pagination($paging); $calls = Phone_Controller::getInstance()->searchCalls($filter, $pagination); // set timezone $calls->setTimezone(Tinebase_Core::get('userTimeZone')); return array('results' => $calls->toArray(), 'totalcount' => Phone_Controller::getInstance()->searchCallsCount($filter)); }
/** * keeps track of the call history * * the callId can be 3c3b966053be-phxdiv27t9gm or 7027a58643aeb25149e4861076f1b0a9@xxx.xxx.xxx.xxx * we strip everything after the @ character * * @param string $mac the mac address of the phone * @param string $event event can be connected, disconnected, incoming, outgoing, missed * @param string $callId the callid * @param string $local the username of the asterisk sip peer * @param string $remote the remote number * * @todo add correct line_id */ public function callHistory($mac, $event, $callId, $local, $remote) { // there is no need to start session for call history // it's a single shot request parent::_authenticate(); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Event: {$event} CallId: {$callId} Local: {$local} Remote: {$remote} "); } $phone = Voipmanager_Controller_Snom_Phone::getInstance()->getByMacAddress($mac); $controller = Phone_Controller::getInstance(); $pos = strpos($callId, '@'); if ($pos !== false) { $callId = substr($callId, 0, $pos); } $pos = strpos($local, '@'); if ($pos !== false) { $local = substr($local, 0, $pos); } $pos = strpos($remote, '@'); if ($pos !== false) { $remote = substr($remote, 0, $pos); } $call = new Phone_Model_Call(array('id' => substr($callId, 0, 40), 'phone_id' => $phone->getId(), 'line_id' => $local)); switch ($event) { case 'outgoing': $call->source = $local; $call->destination = $remote; $call->direction = Phone_Model_Call::TYPE_OUTGOING; $controller->callStarted($call); break; case 'incoming': $call->source = $local; $call->destination = $remote; $call->direction = Phone_Model_Call::TYPE_INCOMING; $controller->callStarted($call); break; case 'connected': $controller->callConnected($call); break; case 'disconnected': $controller->callDisconnected($call); break; } }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { parent::setUp(); $this->_json = new Phone_Frontend_Json(); $this->_adminUser = Tinebase_Core::getUser(); $this->_objects['location'] = new Voipmanager_Model_Snom_Location(array('id' => Tinebase_Record_Abstract::generateUID(), 'name' => 'phpunit test location', 'registrar' => 'registrar')); $this->_objects['software'] = new Voipmanager_Model_Snom_Software(array('id' => Tinebase_Record_Abstract::generateUID())); $this->_objects['setting'] = new Voipmanager_Model_Snom_Setting(array('id' => Tinebase_Record_Abstract::generateUID(), 'name' => 'test setting', 'description' => 'test setting')); $this->_objects['template'] = new Voipmanager_Model_Snom_Template(array('id' => Tinebase_Record_Abstract::generateUID(), 'name' => 'phpunit test location', 'model' => 'snom320', 'software_id' => $this->_objects['software']->getId(), 'setting_id' => $this->_objects['setting']->getId())); $this->_objects['phone'] = new Voipmanager_Model_Snom_Phone(array('id' => Tinebase_Record_Abstract::generateUID(), 'macaddress' => "1234567890cd", 'description' => 'user phone', 'location_id' => $this->_objects['location']->getId(), 'template_id' => $this->_objects['template']->getId(), 'current_model' => 'snom320', 'redirect_event' => 'none')); $this->_objects['phone1'] = new Voipmanager_Model_Snom_Phone(array('id' => Tinebase_Record_Abstract::generateUID(), 'macaddress' => "a234567890cd", 'description' => 'second user phone', 'location_id' => $this->_objects['location']->getId(), 'template_id' => $this->_objects['template']->getId(), 'current_model' => 'snom320', 'redirect_event' => 'none')); $this->_objects['phone2'] = new Voipmanager_Model_Snom_Phone(array('id' => Tinebase_Record_Abstract::generateUID(), 'macaddress' => "1a34567890cd", 'description' => 'jsmith phone', 'location_id' => $this->_objects['location']->getId(), 'template_id' => $this->_objects['template']->getId(), 'current_model' => 'snom320', 'redirect_event' => 'none')); $this->_objects['phonesetting'] = new Voipmanager_Model_Snom_PhoneSettings(array('phone_id' => $this->_objects['phone']->getId(), 'web_language' => 'English')); $this->_objects['phonesetting1'] = new Voipmanager_Model_Snom_PhoneSettings(array('phone_id' => $this->_objects['phone1']->getId(), 'web_language' => 'English')); $this->_objects['phonesetting2'] = new Voipmanager_Model_Snom_PhoneSettings(array('phone_id' => $this->_objects['phone2']->getId(), 'web_language' => 'English')); $this->_objects['phoneOwner'] = array('account_id' => $this->_adminUser->getId(), 'account_type' => 'user'); $this->_objects['phoneOwner2'] = array('account_id' => $this->_personas['jsmith']->getId(), 'account_type' => 'user'); $rights = new Tinebase_Record_RecordSet('Voipmanager_Model_Snom_PhoneRight', array($this->_objects['phoneOwner'])); $rights1 = new Tinebase_Record_RecordSet('Voipmanager_Model_Snom_PhoneRight', array($this->_objects['phoneOwner'])); $rights2 = new Tinebase_Record_RecordSet('Voipmanager_Model_Snom_PhoneRight', array($this->_objects['phoneOwner2'])); $this->_objects['phone']->rights = $rights; $this->_objects['phone1']->rights = $rights1; $this->_objects['phone2']->rights = $rights2; $this->_objects['context'] = new Voipmanager_Model_Asterisk_Context(array('id' => Tinebase_Record_Abstract::generateUID(), 'name' => 'test context', 'description' => 'test context')); $this->_objects['sippeer'] = new Voipmanager_Model_Asterisk_SipPeer(array('id' => Tinebase_Record_Abstract::generateUID(), 'context_id' => $this->_objects['context']->getId())); $this->_objects['sippeer1'] = new Voipmanager_Model_Asterisk_SipPeer(array('id' => Tinebase_Record_Abstract::generateUID(), 'context_id' => $this->_objects['context']->getId())); $this->_objects['sippeer2'] = new Voipmanager_Model_Asterisk_SipPeer(array('id' => Tinebase_Record_Abstract::generateUID(), 'context_id' => $this->_objects['context']->getId())); $this->_objects['line'] = new Voipmanager_Model_Snom_Line(array('id' => Tinebase_Record_Abstract::generateUID(), 'snomphone_id' => $this->_objects['phone']->getId(), 'asteriskline_id' => $this->_objects['sippeer']->getId(), 'linenumber' => 1, 'lineactive' => 1)); $this->_objects['line1'] = new Voipmanager_Model_Snom_Line(array('id' => Tinebase_Record_Abstract::generateUID(), 'snomphone_id' => $this->_objects['phone1']->getId(), 'asteriskline_id' => $this->_objects['sippeer1']->getId(), 'linenumber' => 1, 'lineactive' => 1)); $this->_objects['line2'] = new Voipmanager_Model_Snom_Line(array('id' => Tinebase_Record_Abstract::generateUID(), 'snomphone_id' => $this->_objects['phone2']->getId(), 'asteriskline_id' => $this->_objects['sippeer2']->getId(), 'linenumber' => 1, 'lineactive' => 1)); // create phone, location, template, rights $phoneBackend = new Voipmanager_Backend_Snom_Phone(array('modelName' => 'Phone_Model_MyPhone')); $snomLocationBackend = new Voipmanager_Backend_Snom_Location(); $snomSettingBackend = new Voipmanager_Backend_Snom_Setting(); $snomPhoneSettingBackend = new Voipmanager_Backend_Snom_PhoneSettings(); $snomTemplateBackend = new Voipmanager_Backend_Snom_Template(); $snomSoftwareBackend = new Voipmanager_Backend_Snom_Software(); $snomLineBackend = new Voipmanager_Backend_Snom_Line(); $asteriskSipPeerBackend = new Voipmanager_Backend_Asterisk_SipPeer(); $asteriskContextBackend = new Voipmanager_Backend_Asterisk_Context(); $snomSoftwareBackend->create($this->_objects['software']); $snomLocationBackend->create($this->_objects['location']); $snomSettingBackend->create($this->_objects['setting']); $snomTemplateBackend->create($this->_objects['template']); $phoneBackend->create($this->_objects['phone']); $phoneBackend->create($this->_objects['phone1']); $phoneBackend->create($this->_objects['phone2']); $phoneBackend->setPhoneRights($this->_objects['phone']); $phoneBackend->setPhoneRights($this->_objects['phone1']); $phoneBackend->setPhoneRights($this->_objects['phone2']); $asteriskContextBackend->create($this->_objects['context']); $asteriskSipPeerBackend->create($this->_objects['sippeer']); $asteriskSipPeerBackend->create($this->_objects['sippeer1']); $asteriskSipPeerBackend->create($this->_objects['sippeer2']); $snomLineBackend->create($this->_objects['line']); $snomLineBackend->create($this->_objects['line1']); $snomLineBackend->create($this->_objects['line2']); $snomPhoneSettingBackend->create($this->_objects['phonesetting']); $snomPhoneSettingBackend->create($this->_objects['phonesetting1']); $snomPhoneSettingBackend->create($this->_objects['phonesetting2']); /******************** call history *************************/ $phoneController = Phone_Controller::getInstance(); $this->_objects['call1'] = new Phone_Model_Call(array('id' => 'phpunitcallhistoryid1', 'line_id' => $this->_objects['line']->getId(), 'phone_id' => $this->_objects['phone']->getId(), 'direction' => Phone_Model_Call::TYPE_INCOMING, 'source' => '26', 'destination' => '0406437435')); $this->_objects['call2'] = new Phone_Model_Call(array('id' => 'phpunitcallhistoryid2', 'line_id' => $this->_objects['line']->getId(), 'phone_id' => $this->_objects['phone']->getId(), 'direction' => Phone_Model_Call::TYPE_INCOMING, 'source' => '26', 'destination' => '050364354')); $this->_objects['call2a'] = new Phone_Model_Call(array('id' => 'phpunitcallhistoryid2a', 'line_id' => $this->_objects['line1']->getId(), 'phone_id' => $this->_objects['phone1']->getId(), 'direction' => Phone_Model_Call::TYPE_INCOMING, 'source' => '27', 'destination' => '050364354')); $this->_objects['call3'] = new Phone_Model_Call(array('id' => 'phpunitcallhistoryid3', 'line_id' => $this->_objects['line2']->getId(), 'phone_id' => $this->_objects['phone2']->getId(), 'direction' => Phone_Model_Call::TYPE_INCOMING, 'source' => '78', 'destination' => '050998877')); $this->_objects['call4'] = new Phone_Model_Call(array('id' => 'phpunitcallhistoryid4', 'line_id' => $this->_objects['line2']->getId(), 'phone_id' => $this->_objects['phone2']->getId(), 'direction' => Phone_Model_Call::TYPE_INCOMING, 'source' => '78', 'destination' => '05036998877')); $this->_objects['paging'] = array('start' => 0, 'limit' => 50, 'sort' => 'start', 'dir' => 'ASC'); $this->_objects['filter1'] = array(array('field' => 'query', 'operator' => 'contains', 'value' => '')); $this->_objects['filter2'] = array(array('field' => 'query', 'operator' => 'contains', 'value' => '05036'), array('field' => 'phone_id', 'operator' => 'AND', 'value' => array(array('field' => ':id', 'operator' => 'equals', 'value' => $this->_objects['phone1']->getId())))); $this->_objects['filter2a'] = array(array('field' => 'query', 'operator' => 'contains', 'value' => '05036'), array('field' => 'phone_id', 'operator' => 'AND', 'value' => array(array('field' => ':id', 'operator' => 'equals', 'value' => $this->_objects['phone1']->getId())))); $this->_objects['filter2b'] = array(array('field' => 'destination', 'operator' => 'contains', 'value' => '05036')); $this->_objects['filter3'] = array(array('field' => 'phone_id', 'operator' => 'AND', 'value' => array(array('field' => ':id', 'operator' => 'equals', 'value' => $this->_objects['phone']->getId())))); $this->_objects['filter4'] = array(array('field' => 'phone_id', 'operator' => 'AND', 'value' => array(array('field' => ':id', 'operator' => 'equals', 'value' => $this->_objects['phone2']->getId())))); $this->_objects['filter5'] = array(array('field' => 'query', 'operator' => 'contains', 'value' => '998877')); // create calls $phoneController->callStarted($this->_objects['call1']); $phoneController->callStarted($this->_objects['call2']); $phoneController->callStarted($this->_objects['call2a']); $phoneController->callStarted($this->_objects['call3']); $phoneController->callStarted($this->_objects['call4']); }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $this->_backend = Phone_Controller::getInstance(); $this->_objects['call'] = new Phone_Model_Call(array('id' => 'phpunitcallid', 'line_id' => 'phpunitlineid', 'phone_id' => 'phpunitphoneid', 'direction' => Phone_Model_Call::TYPE_INCOMING, 'source' => '26', 'destination' => '0406437435')); }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $this->_json = new Phone_Frontend_Json(); $this->_objects['location'] = new Voipmanager_Model_Snom_Location(array('id' => 20001, 'name' => 'phpunit test location', 'registrar' => 'registrar')); $this->_objects['software'] = new Voipmanager_Model_Snom_Software(array('id' => 20003)); $this->_objects['setting'] = new Voipmanager_Model_Snom_Setting(array('id' => 20004, 'name' => 'test setting', 'description' => 'test setting')); $this->_objects['phonesetting'] = new Voipmanager_Model_Snom_PhoneSettings(array('phone_id' => 1001, 'web_language' => 'English')); $this->_objects['template'] = new Voipmanager_Model_Snom_Template(array('id' => 20002, 'name' => 'phpunit test location', 'model' => 'snom320', 'software_id' => $this->_objects['software']->getId(), 'setting_id' => $this->_objects['setting']->getId())); $this->_objects['phone'] = new Voipmanager_Model_Snom_Phone(array('id' => 1001, 'macaddress' => "1234567890cd", 'description' => 'user phone', 'location_id' => $this->_objects['location']->getId(), 'template_id' => $this->_objects['template']->getId(), 'current_model' => 'snom320', 'redirect_event' => 'none')); $this->_objects['phoneOwner'] = array('account_id' => Zend_Registry::get('currentAccount')->getId(), 'account_type' => 'user'); $rights = new Tinebase_Record_RecordSet('Voipmanager_Model_Snom_PhoneRight', array($this->_objects['phoneOwner'])); $this->_objects['phone']->rights = $rights; $this->_objects['line'] = new Voipmanager_Model_Snom_Line(array('id' => 1001, 'snomphone_id' => $this->_objects['phone']->getId(), 'asteriskline_id' => 1001, 'linenumber' => 1, 'lineactive' => 1)); $this->_objects['context'] = new Voipmanager_Model_Asterisk_Context(array('id' => 1001, 'name' => 'test context', 'description' => 'test context')); $this->_objects['sippeer'] = new Voipmanager_Model_Asterisk_SipPeer(array('id' => 1001, 'context_id' => 1001)); // create phone, location, template, rights $phoneBackend = new Voipmanager_Backend_Snom_Phone(array('modelName' => 'Phone_Model_MyPhone')); $snomLocationBackend = new Voipmanager_Backend_Snom_Location(); $snomSettingBackend = new Voipmanager_Backend_Snom_Setting(); $snomPhoneSettingBackend = new Voipmanager_Backend_Snom_PhoneSettings(); $snomTemplateBackend = new Voipmanager_Backend_Snom_Template(); $snomSoftwareBackend = new Voipmanager_Backend_Snom_Software(); $snomLineBackend = new Voipmanager_Backend_Snom_Line(); $asteriskSipPeerBackend = new Voipmanager_Backend_Asterisk_SipPeer(); $asteriskContextBackend = new Voipmanager_Backend_Asterisk_Context(); try { $snomSoftwareBackend->create($this->_objects['software']); } catch (Zend_Db_Statement_Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); } try { $snomLocationBackend->create($this->_objects['location']); } catch (Zend_Db_Statement_Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); } try { $snomSettingBackend->create($this->_objects['setting']); } catch (Zend_Db_Statement_Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); } try { $snomTemplateBackend->create($this->_objects['template']); } catch (Zend_Db_Statement_Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); } try { $phoneBackend->create($this->_objects['phone']); } catch (Zend_Db_Statement_Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); } try { $phoneBackend->setPhoneRights($this->_objects['phone']); } catch (Zend_Db_Statement_Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); } try { $asteriskContextBackend->create($this->_objects['context']); } catch (Zend_Db_Statement_Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); } try { $asteriskSipPeerBackend->create($this->_objects['sippeer']); } catch (Zend_Db_Statement_Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); } try { $snomLineBackend->create($this->_objects['line']); } catch (Zend_Db_Statement_Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); } try { $snomPhoneSettingBackend->create($this->_objects['phonesetting']); } catch (Zend_Db_Statement_Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); } /******************** call history *************************/ $phoneController = Phone_Controller::getInstance(); $this->_objects['call1'] = new Phone_Model_Call(array('id' => 'phpunitcallhistoryid1', 'line_id' => $this->_objects['line']->getId(), 'phone_id' => $this->_objects['phone']->getId(), 'direction' => Phone_Model_Call::TYPE_INCOMING, 'source' => '26', 'destination' => '0406437435')); $this->_objects['call2'] = new Phone_Model_Call(array('id' => 'phpunitcallhistoryid2', 'line_id' => $this->_objects['line']->getId(), 'phone_id' => $this->_objects['phone']->getId(), 'direction' => Phone_Model_Call::TYPE_INCOMING, 'source' => '26', 'destination' => '050364354')); $this->_objects['paging'] = array('start' => 0, 'limit' => 50, 'sort' => 'start', 'dir' => 'ASC'); $this->_objects['filter1'] = array(array('field' => 'query', 'operator' => 'contains', 'value' => '')); $this->_objects['filter2'] = array(array('field' => 'query', 'operator' => 'contains', 'value' => '050')); $this->_objects['filter3'] = array(array('field' => 'phone_id', 'operator' => 'equals', 'value' => $this->_objects['phone']->getId())); // create calls try { $call = $phoneController->callStarted($this->_objects['call1']); $call = $phoneController->callStarted($this->_objects['call2']); } catch (Zend_Db_Statement_Exception $e) { // exists //echo $e->getMessage(); } }