/** * the singleton pattern * * @return Sipgate_Controller_Line */ public static function getInstance() { if (self::$_instance === NULL) { self::$_instance = new Sipgate_Controller_Line(); } return self::$_instance; }
/** * Takes the config from config.inc.php and creates an account with the associated lines * @param Zend_Console_Getopt $_opts */ public function take_config($_opts) { // resolve arguments $args = $this->_parseArgs($_opts, array()); $type = in_array('shared', $args['other']) ? 'shared' : 'private'; if (@isset(Tinebase_Core::getConfig()->sipgate)) { $conf = Tinebase_Core::getConfig()->sipgate; if (@isset($conf->api_username) && @isset($conf->api_password)) { echo 'Validate configuration from config.inc.php...' . PHP_EOL; $accountData = array('data' => array('accounttype' => @isset($conf->api_url) && $conf->api_url != 'https://samurai.sipgate.net/RPC2' ? 'team' : 'plus', 'description' => 'Created by update', 'username' => $conf->api_username, 'password' => $conf->api_password, 'type' => $type)); if (Sipgate_Controller_Account::getInstance()->validateAccount($accountData)) { echo 'Data from config.inc.php could be validated, creating account...' . PHP_EOL; try { $account = Sipgate_Controller_Account::getInstance()->create(new Sipgate_Model_Account($accountData['data'])); } catch (Tinebase_Exception_Duplicate $e) { echo 'An account with this credentials exists already! Did you use this script twice?' . PHP_EOL; die; } if ($account) { echo 'Account created. Trying to synchronize the lines..' . PHP_EOL; if (Sipgate_Controller_Line::getInstance()->syncAccount($account->getId())) { $opts = new Zend_Console_Getopt('abp:'); $args = array('initial', 'verbose'); if ($type == 'shared') { $args[] = 'shared'; } $opts->setArguments($args); echo 'Lines have been synchronized. Now syncing connections from the last two months, day per day. This could take some time.' . PHP_EOL; $this->sync_connections($opts); echo 'Connections has been synchronized. Now assign users to the line(s) to allow them to use the line(s)' . PHP_EOL; echo 'READY!' . PHP_EOL; } else { echo 'The lines for the account could not be created!' . PHP_EOL; } } else { echo 'The account could not be created!' . PHP_EOL; } } else { echo 'The credentials found in config.inc.php could not be validated!' . PHP_EOL; } } else { echo 'No username or password could be found in config.php.inc!' . PHP_EOL; } } else { echo 'No sipgate config could be found in config.php.inc!' . PHP_EOL; } }
/** * get Session Status * * @param string $sessionId * @param array $line * @return array */ public function getSessionStatus($sessionId, $line) { if (empty($sessionId)) { throw new Sipgate_Exception('You have to submit a valid Session-ID!'); } if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug('getting Status ' . $sessionId); } return Sipgate_Controller_Line::getInstance()->getSessionStatus($sessionId, $line); }
/** * Syncs all lines for the current user */ public function syncLines(Tinebase_DateTime $_from = NULL, Tinebase_DateTime $_to = NULL, $_shared = false, $verbose = false) { $filter = new Sipgate_Model_AccountFilter(array('field' => 'created_by', 'operator' => 'equals', 'value' => $_shared ? NULL : Tinebase_Core::getUser()->getId())); $pag = new Tinebase_Model_Pagination(); $accounts = Sipgate_Controller_Account::getInstance()->search($filter, $pag); foreach ($accounts->getIterator() as $account) { $filter = new Sipgate_Model_ConnectionFilter(array('field' => 'account_id', 'operator' => 'equals', 'value' => $account->getId())); $lines = Sipgate_Controller_Line::getInstance()->search($filter, $pag); foreach ($lines->getIterator() as $line) { $count = $count + $this->syncLine($line, $_from, $_to, $verbose); } } }
/** * inspects delete action * * @param array $_ids * @return array of ids to actually delete */ protected function _inspectDelete(array $_ids) { if (!is_array($_ids)) { $_ids = array($_ids); } $filter = new Sipgate_Model_LineFilter(array(), 'OR'); foreach ($_ids as $id) { $filter->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'account_id', 'operator' => 'equals', 'value' => $id))); } Sipgate_Controller_Line::getInstance()->deleteByFilter($filter); return $_ids; }
/** * get preference defaults if no default is found in the database * * @param string $_preferenceName * @param string|Tinebase_Model_User $_accountId * @param string $_accountType * @return Tinebase_Model_Preference */ public function getApplicationPreferenceDefaults($_preferenceName, $_accountId = NULL, $_accountType = Tinebase_Acl_Rights::ACCOUNT_TYPE_USER) { if ($_preferenceName == self::MOBILENUMBER) { $c = Addressbook_Controller_Contact::getInstance()->getContactByUserId(Tinebase_Core::getUser()->getId()); $possibleLines = array(); if (!empty($c->tel_cell)) { $possibleLines[] = array('id' => 'tel_cell', 'text' => $c->tel_cell); } if (!empty($c->tel_cell_private)) { $possibleLines[] = array('id' => 'tel_cell_private', 'text' => $c->tel_cell_private); } if (!empty($c->tel_other)) { $possibleLines[] = array('id' => 'tel_other', 'text' => $c->tel_other); } } elseif ($_preferenceName != self::INTERNATIONAL_PREFIX) { $possibleLines = Sipgate_Controller_Line::getInstance()->getUsableLines(); } switch ($_preferenceName) { case self::PHONEID: $pref = $this->getOptions($_preferenceName, $possibleLines); break; case self::FAXID: $pref = $this->getOptions($_preferenceName, $possibleLines); break; case self::MOBILENUMBER: $pref = $this->getOptions($_preferenceName, $possibleLines); break; case self::INTERNATIONAL_PREFIX: $pref = $this->getOptions($_preferenceName); break; default: throw new Tinebase_Exception_NotFound('Default preference with name ' . $_preferenceName . ' not found.'); } return $pref; }