- Модуль: sender
- Путь к файлу: ~/bitrix/modules/sender/lib/entity/campaign.php
- Класс: BitrixSenderEntityCampaign
- Вызов: Campaign::getDefaultId
static function getDefaultId($siteId = null)
{
if ($siteId !== null)
{
if (!SiteTable::getList([
'filter' => ['ACTIVE' => 'Y', 'LID' => $siteId],
'cache' => ['ttl' => 3600],
])->fetch())
{
$siteId = null;
}
}
if ($siteId === null)
{
if (!self::$defaultSiteId)
{
$defaultSite = SiteTable::getRow(['select' => ['ID'], 'filter' => ['=DEF' => 'Y']]);
self::$defaultSiteId = ($defaultSite ? $defaultSite['ID'] : SITE_ID);
}
$siteId = self::$defaultSiteId;
}
if (isset(self::$defaultId[$siteId]))
{
return self::$defaultId[$siteId];
}
$row = MailingTable::getRow(array(
'select' => array('ID'),
'filter' => array('=ACTIVE' => 'Y', '=IS_TRIGGER' => 'N', 'SITE_ID' => $siteId),
'limit' => 1,
'order' => array('ID' => 'DESC')
));
if ($row)
{
self::$defaultId[$siteId] = $row['ID'];
return self::$defaultId[$siteId];
}
$result = MailingTable::add(array(
'NAME' => Loc::getMessage('SENDER_ENTITY_CAMPAIGN_NAME_DEFAULT'),
'SITE_ID' => $siteId
));
if ($result->isSuccess())
{
self::$defaultId[$siteId] = $result->getId();
}
return self::$defaultId[$siteId];
}