/** * Returns list of identities belonging to user. * * @param int $IdUser Identifier of user that contains identities to get. * * @return array|bool */ public function getUserIdentities($IdUser) { $aIdentities = false; if ($this->oConnection->Execute($this->oCommandCreator->getUserIdentitiesQuery($IdUser))) { $aIdentities = array(); $oRow = null; while (false !== ($oRow = $this->oConnection->GetNextRecord())) { $oIdentity = new CIdentity(); $oIdentity->InitByDbRow($oRow); $aIdentities[] = $oIdentity; } } $this->throwDbExceptionIfExist(); return $aIdentities; }
/** * Saves changes made to the identity. * * @api * * @param CIdentity &$oIdentity Identity object containing data to be saved. * * @return bool */ public function updateIdentity(CIdentity &$oIdentity) { $bResult = false; try { if ($oIdentity->isValid()) { $bUseOnlyHookUpdate = false; CApi::Plugin()->RunHook('api-update-identity', array(&$oIdentity, &$bUseOnlyHookUpdate)); if ($bUseOnlyHookUpdate) { } else { if ($oIdentity->Virtual) { $oAccount = $this->getAccountById($oIdentity->IdAccount); if ($oAccount && $oIdentity->IdUser === $oAccount->IdUser) { $oAccount->FriendlyName = $oIdentity->FriendlyName; $oAccount->Signature = $oIdentity->Signature; $oAccount->SignatureType = $oIdentity->SignatureType; $oAccount->SignatureOptions = $oIdentity->UseSignature ? EAccountSignatureOptions::AddToAll : EAccountSignatureOptions::DontAdd; $bResult = $this->updateAccount($oAccount); } } else { if ($this->oStorage->updateIdentity($oIdentity)) { if ($oIdentity->Default) { $this->oStorage->updateIdentitiesDefaults($oIdentity->IdIdentity, $oIdentity->IdAccount); } } else { $this->moveStorageExceptionToManager(); throw new CApiManagerException(Errs::UserManager_IdentityUpdateFailed); } } } } $bResult = true; } catch (CApiBaseException $oException) { $bResult = false; $this->setLastException($oException); } return $bResult; }
/** * @param CAccount $oAccount * @return string */ public function GetIdentitiesByUserID($oAccount) { $aMap = api_AContainer::DbReadKeys(CIdentity::GetStaticMap()); $aMap = array_map(array($this, 'escapeColumn'), $aMap); $sSql = 'SELECT %s FROM %sawm_identities WHERE id_user = %d'; return sprintf($sSql, implode(', ', $aMap), $this->Prefix(), $oAccount->IdUser); }
/** * Returns query-string for obtaining list of identities belonging to user. * * @param int $IdUser Identifier of user that contains identities to get. * * @return string */ public function getUserIdentitiesQuery($IdUser) { $aMap = api_AContainer::DbReadKeys(CIdentity::getStaticMap()); $aMap = array_map(array($this, 'escapeColumn'), $aMap); $sSql = 'SELECT %s FROM %sawm_identities WHERE id_user = %d'; return sprintf($sSql, implode(', ', $aMap), $this->prefix(), $IdUser); }