- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/widget/funnelwidget.php
- Класс: Bitrix\Crm\Widget\FunnelWidget
- Вызов: FunnelWidget::prepareData
public function prepareData()
{
$totals = array();
if($this->entityTypeID === \CCrmOwnerType::Lead)
{
$source = new LeadStatusHistory(array(), $this->userID, $this->enablePermissionCheck);
$source->setFilterContextData($this->getFilterContextData());
$source->applyFilterContext($this->filter);
$statuses = \CCrmStatus::GetStatusList('STATUS');
foreach($statuses as $k => $v)
{
$semanticID = \CCrmLead::GetSemanticID($k);
if($semanticID === PhaseSemantics::FAILURE)
{
continue;
}
$totals[$k] = array('ID' => $k, 'NAME' => $v, 'TOTAL' => 0);
}
$this->filter->setExtraParam('isJunk', false);
}
elseif($this->entityTypeID === \CCrmOwnerType::Deal)
{
$source = new DealStageHistory(array(), $this->userID, $this->enablePermissionCheck);
$source->setFilterContextData($this->getFilterContextData());
$source->applyFilterContext($this->filter);
$dealCategoryID = $this->filter->getExtraParam('dealCategoryID', -1);
if($dealCategoryID < 0)
{
$dealCategoryID = $this->filter->getExtraParam('dealCategoryId', 0);
}
$stages = \CCrmDeal::GetAllStageNames($dealCategoryID);
foreach($stages as $k => $v)
{
$semanticID = \CCrmDeal::GetSemanticID($k, $dealCategoryID);
if($semanticID === PhaseSemantics::FAILURE)
{
continue;
}
$totals[$k] = array('ID' => $k, 'NAME' => $v, 'TOTAL' => 0);
}
$this->filter->setExtraParam('isLost', false);
}
elseif($this->entityTypeID === \CCrmOwnerType::Invoice)
{
$source = new InvoiceStatusHistory(array(), $this->userID, $this->enablePermissionCheck);
$source->setFilterContextData($this->getFilterContextData());
$source->applyFilterContext($this->filter);
$stages = \CCrmStatus::GetStatusList('INVOICE_STATUS');
foreach($stages as $k => $v)
{
$semanticID = \CCrmInvoice::GetSemanticID($k);
if($semanticID === PhaseSemantics::FAILURE)
{
continue;
}
$totals[$k] = array('ID' => $k, 'NAME' => $v, 'TOTAL' => 0);
}
$this->filter->setExtraParam('isJunk', false);
}
else
{
$entityTypeName = \CCrmOwnerType::ResolveName($this->entityTypeID);
throw new Main\NotSupportedException("The '{$entityTypeName}' is not supported in current context");
}
$values = $source->getList(array('filter' => $this->filter));
$this->prepareTotals($values, $totals);
$items = array();
foreach($totals as $total)
{
if($total['TOTAL'] > 0)
{
$items[] = $total;
}
}
return array('items' => $items, 'valueField' => 'TOTAL', 'titleField' => 'NAME');
}