• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/widget/graphwidget.php
  • Класс: Bitrix\Crm\Widget\GraphWidget
  • Вызов: GraphWidget::prepareData
public function prepareData()
{
	$result = array();
	$configCount = count($this->configs);
	if($this->maxGraphCount > 0 && $configCount > $this->maxGraphCount)
	{
		$configCount = $this->maxGraphCount;
	}

	for($i = 0; $i < $configCount; $i++)
	{
		$config = $this->configs[$i];

		/** @var WidgetConfig $config */
		$name = $config->getName();
		if($name === '')
		{
			$name = strval(count($result) + 1);
		}

		$title = $config->getTitle();
		if($title === '')
		{
			$title = $name;
		}

		$this->filter->setExtras($config->getFilterParams());

		$source = null;
		$sourceSettings = $config->getDataSourceSettings();
		if(DataSourceFactory::checkSettings($sourceSettings))
		{
			$source = DataSourceFactory::create($sourceSettings, $this->userID, $this->enablePermissionCheck);
			$source->setFilterContextData($this->getFilterContextData());
		}
		$selectField = $config->getSelectField();

		$aggregate = $config->getAggregate();
		$groupField = $config->getGroupField();
		if($groupField === '')
		{
			$groupField = $this->groupField;
		}

		if($source !== null)
		{
			$values = $source->getList(
				array(
					'filter' => $this->filter,
					'select' => array(array('name' => $selectField, 'aggregate' => $aggregate)),
					'group' => $groupField
				)
			);
		}
		else
		{
			$values = array();
		}

		$item = array(
			'name' => $name,
			'title' => $title,
			'values' => $values,
			'selectField' => $selectField,
			'groupField' => $groupField
		);

		$displayParams = $config->getDisplayParams();
		if(!empty($displayParams))
		{
			$item['display'] = $displayParams;
		}
		$result[] = $item;
	}

	$merge = array();
	$groupField = $this->groupField;
	$graphs = array();
	foreach($result as $item)
	{
		$name = $item['name'];
		$title = $item['title'];
		$selectField = $item['selectField'];
		if($selectField === '')
		{
			continue;
		}

		$valueKey = mb_strtoupper($name).'_'.$selectField;

		$graph = array(
			'name' => $name,
			'title' => $title,
			'selectField' => $valueKey
		);

		if(isset($item['display']))
		{
			$graph['display'] = $item['display'];
		}

		$graphs[] = $graph;
		$values = $item['values'];
		$addZeroValues = !$this->skipZeros;
		foreach($values as $value)
		{
			$key = isset($value[$groupField]) ? $value[$groupField] : '';
			if($key === '')
			{
				continue;
			}

			if($groupField == "USER" && isset($value["USER_ID"]))
			{
				$key = $value["USER_ID"];
				if (!isset($merge[$value["USER_ID"]]))
				{
					$merge[$key] = array(
						"USER" => $value["USER"],
						"USER_ID" => $value["USER_ID"],
						"USER_PHOTO" => $value["USER_PHOTO"]
					);
				}
			}
			else if(!isset($merge[$key]))
			{
				$merge[$key] = array($groupField => $key);
			}

			if(isset($value[$selectField]) && ($addZeroValues || $value[$selectField] != 0))
			{
				$merge[$key][$valueKey] = $value[$selectField];
			}
		}
	}
	ksort($merge, SORT_STRING);

	return array(
		'items' => array(
			array(
				'graphs' => $graphs,
				'groupField' => $groupField,
				'values' => array_values($merge)
			)
		),
		'dateFormat' => 'YYYY-MM-DD'
	);
}