- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/integration/landing/formlanding.php
- Класс: Bitrix\Crm\Integration\Landing\FormLanding
- Вызов: FormLanding::getSiteId
public function getSiteId(): ?int
{
if (!$this->canUse())
{
return null;
}
if ($this->siteId !== false)
{
return $this->siteId;
}
$this->siteId = null;
$storedSiteId = (int) Main\Config\Option::get(
'crm', $this::OPT_CODE_LANDINGS_SITE_ID
);
// site is not exist, create new one
if (!$storedSiteId)
{
Rights::setGlobalOff();
$res = \Bitrix\Landing\Site::add([
'TITLE' => 'CRM Forms',
'TYPE' => $this::SITE_TYPE,
'CODE' => \Bitrix\Landing\Site\Type::PSEUDO_SCOPE_CODE_FORMS,
'SPECIAL' => 'Y'
]);
Rights::setGlobalOn();
if ($res->isSuccess())
{
$this->siteId = (int) $res->getId();
Main\Config\Option::set(
'crm', $this::OPT_CODE_LANDINGS_SITE_ID, $this->siteId
);
return $this->siteId;
}
else
{
$this->setErrorMessage($res->getErrors()[0]);
}
}
if ($storedSiteId)
{
$this->siteId = $storedSiteId;
}
// check that exists
if ($this->siteId)
{
$res = \Bitrix\Landing\Site::getList([
'select' => [
'ID'
],
'filter' => [
'=ID' => $this->siteId,
'CHECK_PERMISSIONS' => 'N'
]
]);
if (!$res->fetch())
{
Main\Config\Option::set(
'crm', $this::OPT_CODE_LANDINGS_SITE_ID, 0
);
$this->siteId = false;
return $this->getSiteId();
}
}
return $this->siteId;
}