- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/compatible/compatible.php
- Класс: BitrixSaleCompatibleOrderQuery
- Вызов: OrderQuery::prepare
public function prepare(array $order, array $filter, $group, array $select)
{
// Do not remove!!!
// file_put_contents('/var/www/log'
// , spl_object_hash($this)."n"
// . 'Order: '.print_r($order,true)
// . 'Filter: '.print_r($filter,true)
// . 'Group: '.print_r($group,true)
// . 'Select: '.print_r($select,true)
// ."nnn"
// , FILE_APPEND);
static $aggregates = array('COUNT'=>1, 'AVG'=>1, 'MIN'=>1, 'MAX'=>1, 'SUM'=>1);
foreach ($filter as $key => $value)
{
$key = $this->mapLocationRuntimeField($key, true);
$this->compatibleAddFilter($key, $value);
}
if (is_array($group))
{
if (empty($group))
{
$this->counted = true;
return;
}
else
{
foreach ($group as $key => $alias)
{
if ($name = $this->getAliasName($alias))
{
if (is_string($key) && ($aggregate = ToUpper($key)) && $aggregates[$aggregate])
{
$this->addAggregatedSelect($alias, $aggregate, $name);
}
else
{
$this->grouped = true;
$this->addGroup($name);
$this->addSelect($name, $alias);
}
}
}
if ($this->grouped)
{
$this->addAggregatedSelect('CNT', 'COUNT(*)');
// TODO Maybe? "COUNT(%%_DISTINCT_%% ".$arFields[$arFieldsKeys[0]]["FIELD"].") as CNT ";
}
}
}
else
{
if (empty($select) || $select == array('*'))
{
$this->allSelected = true;
foreach ($this->getAliases() as $alias => $field)
{
$field = $this->mapLocationRuntimeField($field);
$this->addAliasSelect($alias);
}
}
else
{
foreach ($select as $key => $alias)
{
$alias = $this->mapLocationRuntimeField($alias);
if ($name = $this->getAliasName($alias))
{
if (is_string($key) && ($aggregate = ToUpper($key)) && $aggregates[$aggregate])
{
$this->addAggregatedSelect($alias, $aggregate, $name);
}
else
{
$this->addSelect($name, $alias);
}
}
}
}
}
foreach ($order as $alias => $value)
{
$alias = $this->mapLocationRuntimeField($alias);
$this->addAliasOrder($alias, $value);
}
}