本文整理汇总了PHP中CApi::GetManager方法的典型用法代码示例。如果您正苦于以下问题:PHP CApi::GetManager方法的具体用法?PHP CApi::GetManager怎么用?PHP CApi::GetManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CApi
的用法示例。
在下文中一共展示了CApi::GetManager方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: CreateAccountProcess
/**
* @param string $sEmail
* @param string $sPassword
* @param string $sChangeLang = ''
* @param array $aExtValues = null
* @param bool $bAllowInternalOnly = false
* @return CAccount | false
*/
public function CreateAccountProcess($sEmail, $sPassword, $sChangeLang = '', $aExtValues = null, $bAllowInternalOnly = false)
{
$mResult = false;
try {
/* @var $oApiDomainsManager CApiDomainsManager */
$oApiDomainsManager = CApi::Manager('domains');
/* @var $oApiUsersManager CApiUsersManager */
$oApiUsersManager = CApi::Manager('users');
$sDomainName = api_Utils::GetDomainFromEmail($sEmail);
$oDomain = $oApiDomainsManager->GetDomainByName($sDomainName);
if (!$oDomain) {
$oDomain = $oApiDomainsManager->GetDefaultDomain();
}
$bApiIntegratorLoginToAccountResult = isset($aExtValues['ApiIntegratorLoginToAccountResult']) ? $aExtValues['ApiIntegratorLoginToAccountResult'] : false;
if ($oDomain && ($bApiIntegratorLoginToAccountResult || $oDomain->AllowNewUsersRegister || $oDomain->IsInternal && $bAllowInternalOnly || 'nodb' === CApi::GetManager()->GetStorageByType('webmail'))) {
/*if ($oDomain && !$oDomain->AllowWebMail)
{
throw new CApiManagerException(Errs::WebMailManager_AccountWebmailDisabled);
}
else */
if ($oDomain && $oDomain->IsInternal && !$bAllowInternalOnly) {
throw new CApiManagerException(Errs::WebMailManager_NewUserRegistrationDisabled);
} else {
if ($oDomain && $bAllowInternalOnly && (!$oDomain->IsInternal || $oDomain->IsDefaultDomain)) {
throw new CApiManagerException(Errs::WebMailManager_NewUserRegistrationDisabled);
} else {
if ($oDomain) {
$oAccountToCreate = new CAccount($oDomain);
$oAccountToCreate->Email = $sEmail;
// $oAccountToCreate->IncomingMailLogin = (isset($aExtValues['Login'])) ? $aExtValues['Login'] :
// (($this->oSettings->GetConf('WebMail/UseLoginWithoutDomain'))
// ? api_Utils::GetAccountNameFromEmail($sEmail) : $sEmail);
$oAccountToCreate->IncomingMailLogin = isset($aExtValues['Login']) ? $aExtValues['Login'] : $sEmail;
if ($this->oSettings->GetConf('WebMail/UseLoginWithoutDomain')) {
$oAccountToCreate->IncomingMailLogin = api_Utils::GetAccountNameFromEmail($oAccountToCreate->IncomingMailLogin);
}
$oAccountToCreate->IncomingMailPassword = $sPassword;
if (0 < strlen($sChangeLang) && $sChangeLang !== $oAccountToCreate->User->DefaultLanguage) {
$oAccountToCreate->User->DefaultLanguage = $sChangeLang;
}
if ($oDomain->IsDefaultDomain && isset($aExtValues['IncProtocol'], $aExtValues['IncHost'], $aExtValues['IncPort'], $aExtValues['OutHost'], $aExtValues['OutPort'], $aExtValues['OutAuth'])) {
$oAccountToCreate->IncomingMailProtocol = (int) $aExtValues['IncProtocol'];
$oAccountToCreate->IncomingMailServer = trim($aExtValues['IncHost']);
$oAccountToCreate->IncomingMailPort = (int) trim($aExtValues['IncPort']);
$oAccountToCreate->OutgoingMailServer = trim($aExtValues['OutHost']);
$oAccountToCreate->OutgoingMailPort = (int) trim($aExtValues['OutPort']);
$oAccountToCreate->OutgoingMailAuth = (bool) $aExtValues['OutAuth'] ? ESMTPAuthType::AuthCurrentUser : ESMTPAuthType::NoAuth;
// TODO
$oAccountToCreate->IncomingMailUseSSL = in_array($oAccountToCreate->IncomingMailPort, array(993, 995));
$oAccountToCreate->OutgoingMailUseSSL = in_array($oAccountToCreate->OutgoingMailPort, array(465));
}
CApi::Plugin()->RunHook('api-pre-create-account-process-call', array(&$oAccountToCreate));
if (isset($aExtValues['FriendlyName'])) {
$oAccountToCreate->FriendlyName = $aExtValues['FriendlyName'];
}
if (isset($aExtValues['Question1'])) {
$oAccountToCreate->User->Question1 = $aExtValues['Question1'];
}
if (isset($aExtValues['Question2'])) {
$oAccountToCreate->User->Question2 = $aExtValues['Question2'];
}
if (isset($aExtValues['Answer1'])) {
$oAccountToCreate->User->Answer1 = $aExtValues['Answer1'];
}
if (isset($aExtValues['Answer2'])) {
$oAccountToCreate->User->Answer2 = $aExtValues['Answer2'];
}
if ($oApiUsersManager->CreateAccount($oAccountToCreate, !($oAccountToCreate->IsInternal || !$oAccountToCreate->Domain->AllowWebMail || $bApiIntegratorLoginToAccountResult))) {
CApi::Plugin()->RunHook('api-success-post-create-account-process-call', array(&$oAccountToCreate));
$mResult = $oAccountToCreate;
} else {
$oException = $oApiUsersManager->GetLastException();
CApi::Plugin()->RunHook('api-error-post-create-account-process-call', array(&$oAccountToCreate, &$oException));
throw is_object($oException) ? $oException : new CApiManagerException(Errs::WebMailManager_AccountCreateOnLogin);
}
} else {
throw new CApiManagerException(Errs::WebMailManager_DomainDoesNotExist);
}
}
}
} else {
throw new CApiManagerException(Errs::WebMailManager_NewUserRegistrationDisabled);
}
} catch (CApiBaseException $oException) {
$mResult = false;
$this->setLastException($oException);
}
return $mResult;
}
示例2: removeContactsFromGroup
/**
* The method deletes one or multiple contacts from the group.
*
* @param CGroup $oGroup Group object to be used
* @param array $aContactIds List of contact IDs to be deleted
*
* @return bool
*/
public function removeContactsFromGroup($oGroup, $aContactIds)
{
$res1 = $res2 = false;
$aContactsStrIds = array();
foreach ($aContactIds as $iContactId) {
$oContact = $this->oApiContactsMainManager->getContactById($oGroup->IdUser, $iContactId);
if ($oContact) {
$aContactsStrIds[] = $oContact->IdContactStr;
}
}
$res1 = $this->oApiContactsMainManager->removeContactsFromGroup($oGroup, $aContactIds);
if ('sabredav' !== CApi::GetManager()->GetStorageByType('contacts')) {
$res2 = $this->oApiContactsMainManagerDAV->removeContactsFromGroup($oGroup, $aContactsStrIds);
} else {
$res2 = true;
}
return $res1 && $res2;
}
示例3: afterWriteContent
function afterWriteContent($path, \Sabre\DAV\IFile $node)
{
if ('sabredav' !== \CApi::GetManager()->GetStorageByType('contacts')) {
if ($node instanceof \Sabre\CardDAV\ICard) {
$oAccount = $this->server->getAccount();
if (isset($oAccount)) {
$iUserId = $oAccount->IdUser;
$iTenantId = $node instanceof \afterlogic\DAV\CardDAV\SharedCard ? $oAccount->IdTenant : null;
$sFileName = $node->getName();
$oContactDb = $this->oApiContactsManager->GetContactByStrId($iUserId, $sFileName, $iTenantId);
$oContact = new \CContact();
$oContact->InitFromVCardStr($iUserId, $node->get());
$oContact->IdContact = $oContactDb->IdContact;
$oContact->SharedToAll = !!$oContactDb->SharedToAll;
$bResult = $this->oApiContactsManager->UpdateContact($oContact);
// \CApi::LogObject($bResult, \ELogLevel::Full, 'contacts-');
}
}
}
}
示例4: createAccount
/**
* Creates WebMail account. In most cases, using simpler loginToAccount wrapper is recommended.
*
* @api
*
* @param CAccount &$oAccount Object instance with prepopulated account properties.
* @param bool $bWithMailConnection Default value is **true**. Defines whether account credentials should be verified against mail server.
*
* @return bool
*/
public function createAccount(CAccount &$oAccount, $bWithMailConnection = true)
{
$bResult = false;
try {
if ($oAccount->isValid()) {
if (!$this->accountExists($oAccount)) {
/* @var $oApiLicensingManager CApiLicensingManager */
$oApiLicensingManager = CApi::Manager('licensing');
if ($oApiLicensingManager) {
$isValidKey = $oApiLicensingManager->IsValidKey();
if (!$isValidKey && in_array($oApiLicensingManager->GetLicenseType(), array(11, 13, 14))) {
throw new CApiManagerException(Errs::UserManager_LicenseKeyIsOutdated);
} else {
if (!$isValidKey) {
throw new CApiManagerException(Errs::UserManager_LicenseKeyInvalid);
}
}
if ($oAccount->IsDefaultAccount && !$oApiLicensingManager->IsValidLimit(true)) {
throw new CApiManagerException(Errs::UserManager_AccountCreateUserLimitReached);
}
}
if (0 < $oAccount->Domain->IdTenant && CApi::GetConf('tenant', false)) {
/* @var $oTenantsApi CApiTenantsManager */
$oTenantsApi = CApi::Manager('tenants');
if ($oTenantsApi) {
/* @var $oTenant CTenant */
$oTenant = $oTenantsApi->getTenantById($oAccount->Domain->IdTenant);
if (!$oTenant) {
throw new CApiManagerException(Errs::TenantsManager_TenantDoesNotExist);
} else {
if (0 < $oTenant->UserCountLimit && $oTenant->UserCountLimit <= $oTenant->getUserCount()) {
throw new CApiManagerException(Errs::TenantsManager_AccountCreateUserLimitReached);
}
$this->_validateAccountSubscriptionLimits($oAccount, $oTenant, true);
}
if (0 < $oTenant->QuotaInMB) {
$iSize = $oTenantsApi->getTenantAllocatedSize($oTenant->IdTenant);
if ((int) ($oAccount->getRealQuotaSize() / 1024) + $iSize > $oTenant->QuotaInMB) {
throw new CApiManagerException(Errs::TenantsManager_QuotaLimitExided);
}
}
}
}
$bConnectValid = true;
$aConnectErrors = array(false, false);
if ($bWithMailConnection && !$oAccount->IsMailingList && !$oAccount->IsInternal && !$oAccount->Domain->IsDefaultTenantDomain) {
$bConnectValid = false;
$iConnectTimeOut = CApi::GetConf('socket.connect-timeout', 10);
$iSocketTimeOut = CApi::GetConf('socket.get-timeout', 20);
CApi::Plugin()->RunHook('webmail-imap-update-socket-timeouts', array(&$iConnectTimeOut, &$iSocketTimeOut));
try {
$oImapClient = \MailSo\Imap\ImapClient::NewInstance();
$oImapClient->SetTimeOuts($iConnectTimeOut, $iSocketTimeOut);
$oImapClient->SetLogger(\CApi::MailSoLogger());
$oImapClient->Connect($oAccount->IncomingMailServer, $oAccount->IncomingMailPort, $oAccount->IncomingMailUseSSL ? \MailSo\Net\Enumerations\ConnectionSecurityType::SSL : \MailSo\Net\Enumerations\ConnectionSecurityType::NONE);
$aConnectErrors[0] = true;
$sProxyAuthUser = !empty($oAccount->CustomFields['ProxyAuthUser']) ? $oAccount->CustomFields['ProxyAuthUser'] : '';
$oImapClient->Login($oAccount->IncomingMailLogin, $oAccount->IncomingMailPassword, $sProxyAuthUser);
$aConnectErrors[1] = true;
$bConnectValid = true;
$oImapClient->LogoutAndDisconnect();
} catch (\Exception $oExceprion) {
}
}
if ($bConnectValid) {
if (!$this->oStorage->createAccount($oAccount)) {
throw new CApiManagerException(Errs::UserManager_AccountCreateFailed);
}
if ($oAccount && $oAccount->IsDefaultAccount) {
/* @var $oApiContactsManager CApiContactsManager */
$oApiContactsManager = CApi::Manager('contactsmain');
if ($oApiContactsManager && 'db' === CApi::GetManager()->GetStorageByType('contactsmain')) {
$oContact = $oApiContactsManager->createContactObject();
$oContact->BusinessEmail = $oAccount->Email;
$oContact->PrimaryEmail = EPrimaryEmailType::Business;
$oContact->FullName = $oAccount->FriendlyName;
$oContact->Type = EContactType::GlobalAccounts;
$oContact->IdTypeLink = $oAccount->IdUser;
$oContact->IdDomain = 0 < $oAccount->IdDomain ? $oAccount->IdDomain : 0;
$oContact->IdTenant = $oAccount->Domain ? $oAccount->Domain->IdTenant : 0;
$oApiContactsManager->createContact($oContact);
}
}
CApi::Plugin()->RunHook('statistics.signup', array(&$oAccount));
} else {
if ($aConnectErrors[0]) {
throw new CApiManagerException(Errs::UserManager_AccountAuthenticationFailed);
} else {
throw new CApiManagerException(Errs::UserManager_AccountConnectToMailServerFailed);
}
//.........这里部分代码省略.........
示例5: afterWriteContent
function afterWriteContent($path, \Sabre\DAV\IFile $node)
{
if ('sabredav' !== \CApi::GetManager()->GetStorageByType('contacts')) {
if ($node instanceof \Sabre\CardDAV\ICard) {
$oAccount = $this->server->getAccount();
if (isset($oAccount)) {
$iUserId = $oAccount->IdUser;
$iTenantId = $node instanceof \afterlogic\DAV\CardDAV\SharedCard ? $oAccount->IdTenant : null;
$sContactFileName = $node->getName();
$oContactDb = $this->oApiContactsManager->GetContactByStrId($iUserId, $sContactFileName, $iTenantId);
if (!isset($oContactDb)) {
$oDavManager = \CApi::Manager('dav');
$oVCard = $oDavManager ? $oDavManager->VObjectReaderRead($node->get()) : null;
if ($oVCard && $oVCard->UID) {
$oContactDb = $this->oApiContactsManager->GetContactByStrId($iUserId, (string) $oVCard->UID . '.vcf', $iTenantId);
}
}
$oContact = new \CContact();
$oContact->InitFromVCardStr($iUserId, $node->get());
$oContact->IdContactStr = $sContactFileName;
$oContact->IdTenant = $iTenantId;
if (isset($oContactDb)) {
$oContact->IdContact = $oContactDb->IdContact;
$oContact->IdDomain = $oContactDb->IdDomain;
$oContact->SharedToAll = !!$oContactDb->SharedToAll;
$this->oApiContactsManager->UpdateContact($oContact);
} else {
$this->oApiContactsManager->CreateContact($oContact);
}
}
}
}
}