/** * @return array */ public function AjaxSocialCreate() { $oAccount = $this->GetDefaultAccount(); $mResult = false; if ($oAccount) { $sType = trim($this->getParamValue('Type', '')); $sAccessToken = trim($this->getParamValue('AccessToken', '')); if ('' !== $sType && !empty($sAccessToken)) { $oTenant = null; if ($this->oApiTenants) { $oTenant = 0 < $oAccount->IdTenant ? $this->oApiTenants->GetTenantById($oAccount->IdTenant) : $this->oApiTenants->GetDefaultGlobalTenant(); } $oUserInfo = null; if ('google' === $sType && $oTenant) { $oSocial = $oTenant->GetSocialByName('google'); if ($oSocial) { $oUserInfo = \api_Utils::GetGoogleUserInfo($oSocial->SocialApiKey, $sAccessToken); } } if ($oUserInfo) { $oApiSocial = \CApi::Manager('social'); $oSocial = new \CSocial(); $oSocial->IdAccount = $oAccount->IdAccount; $oSocial->TypeStr = $sType; $oSocial->IdSocial = $oUserInfo->id; $oSocial->Name = $oUserInfo->name; $mResult = $oApiSocial->CreateSocial($oSocial); } } } return $this->DefaultResponse(null, __FUNCTION__, $mResult); }
/** * @return array */ public function AjaxSocialCreate() { $oAccount = $this->GetDefaultAccount(); $mResult = false; if ($oAccount) { $iType = (int) trim($this->getParamValue('Type', \ESocialType::Unknown)); $sAccessToken = trim($this->getParamValue('AccessToken', '')); if (\ESocialType::Unknown !== $iType && !empty($sAccessToken)) { $oTenant = null; if ($this->oApiTenants) { $oTenant = (0 < $oAccount->IdTenant) ? $this->oApiTenants->GetTenantById($oAccount->IdTenant) : $this->oApiTenants->GetDefaultGlobalTenant(); } $oUserInfo = null; if (\ESocialType::Google === $iType && $oTenant) { $oUserInfo = \api_Utils::GetGoogleUserInfo($oTenant->SocialGoogleApiKey, $sAccessToken); } if ($oUserInfo) { $oApiSocial = /* @var $oApiSocial \CApiSocialManager */ \CApi::Manager('social'); $oSocial = new \CSocial(); $oSocial->IdAccount = $oAccount->IdAccount; $oSocial->Type = $iType; $oSocial->IdSocial = $oUserInfo->id; $oSocial->Name = $oUserInfo->name; $mResult = $oApiSocial->CreateSocial($oSocial); } } } return $this->DefaultResponse(null, __FUNCTION__, $mResult); }