- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/delivery/restrictions/manager.php
- Класс: BitrixSaleDeliveryRestrictionsManager
- Вызов: Manager::getRestrictedIds
static function getRestrictedIds(BitrixSaleShipment $shipment = null, $restrictionMode)
{
$result = array();
static $dataPrepared = false;
static $idsGrouppedByRestrictions = array(); //performance
static $supportGroupFiltering = array(); //
if($dataPrepared === false)
{
self::init();
$filter = array(
'DELIVERY_SERVICE.ACTIVE' => 'Y'
);
$dbRes = ServiceRestrictionTable::getList(array(
'runtime' => array(
new BitrixMainEntityReferenceField(
'DELIVERY_SERVICE',
'BitrixSaleDeliveryServicesTable',
array(
'=this.SERVICE_ID' => 'ref.ID',
'=this.SERVICE_TYPE' => array('?', self::SERVICE_TYPE_SHIPMENT)
),
array('join_type' => 'inner')
)
),
'filter' => $filter,
'order' => array('SORT' =>'ASC')
));
$data = array();
$checkedGroupFiltering = array();
while($rstr = $dbRes->fetch())
{
if(!isset($data[$rstr["SERVICE_ID"]]))
$data[$rstr["SERVICE_ID"]] = array();
$data[$rstr["SERVICE_ID"]][$rstr['ID']] = $rstr;
if(!in_array($rstr['CLASS_NAME'], $checkedGroupFiltering))
{
$checkedGroupFiltering[] = $rstr['CLASS_NAME'];
if(method_exists($rstr['CLASS_NAME'], 'filterServicesArray'))
$supportGroupFiltering[] = $rstr['CLASS_NAME'];
}
if(in_array($rstr['CLASS_NAME'], $supportGroupFiltering))
{
if (!isset($idsGrouppedByRestrictions[$rstr['CLASS_NAME']]))
{
$idsGrouppedByRestrictions[$rstr['CLASS_NAME']] = [];
}
if (!in_array($rstr["SERVICE_ID"], $idsGrouppedByRestrictions[$rstr['CLASS_NAME']]))
{
$idsGrouppedByRestrictions[$rstr['CLASS_NAME']][$rstr["SERVICE_ID"]] = $rstr;
}
}
}
self::prepareData(array_keys($data), $data);
$dataPrepared = true;
}
else
{
$data = self::getCache(0, self::getServiceType());
}
$filterResult = array();
foreach($supportGroupFiltering as $rstrClass)
{
$passedServicesIds = $rstrClass::filterServicesArray($shipment, $idsGrouppedByRestrictions[$rstrClass]);
$notPassed = array_diff_key($idsGrouppedByRestrictions[$rstrClass], array_flip($passedServicesIds));
if($restrictionMode == self::MODE_MANAGER)
foreach($notPassed as $srvId => $rstr)
$filterResult[$srvId] = $rstrClass::getSeverity($restrictionMode);
$data = array_diff_key($data, $notPassed);
}
foreach($data as $serviceId => $serviceRestrictions)
{
$srvRes = self::SEVERITY_NONE;
if($shipment != null)
{
foreach($serviceRestrictions as $restrictionId => $rstr)
{
if(in_array($rstr['CLASS_NAME'], $supportGroupFiltering))
continue;
if(!self::isClassValid($rstr['CLASS_NAME']))
continue;
if(!$rstr['PARAMS'])
$rstr['PARAMS'] = array();
$res = $rstr['CLASS_NAME']::checkByEntity(
$shipment,
$rstr['PARAMS'],
$restrictionMode,
$serviceId
);
if($res == self::SEVERITY_STRICT)
continue 2;
if($res == self::SEVERITY_SOFT && $restrictionMode == self::MODE_CLIENT)
continue 2;
if($res == self::SEVERITY_SOFT && $srvRes == self::SEVERITY_NONE)
$srvRes = self::SEVERITY_SOFT;
}
}
$result[$serviceId] = $srvRes;
}
return $filterResult + $result;
}