Skip to content

Instantly share code, notes, and snippets.

@sartas
Created December 11, 2013 10:04
Show Gist options
  • Select an option

  • Save sartas/7907904 to your computer and use it in GitHub Desktop.

Select an option

Save sartas/7907904 to your computer and use it in GitHub Desktop.
bitrix group by
<?php
//$useCache = true;
$useCache = false;
$cacheValid = false;
$this_iblock_id = (int)$this_iblock_id;
if ($useCache)
{
$cachedResult = new CPHPCache();
$cacheId = "";
foreach ($_GET as $key => $val)
{
$cacheId .= $key . $val;
}
$cacheValid = $cachedResult->InitCache(3600, $cacheId, "/rktv_news_filter");
if ($cacheValid)
{
$rktvFilterMenu = $cachedResult->GetVars();
}
}
if (!$useCache || !$cacheValid) // либо кэш отключен, либо нет действительного кэша
{
global $DB;
//$DB->ForSql();
//года
$years = array();
$results = $DB->Query('SELECT YEAR(ACTIVE_FROM) as years FROM b_iblock_element WHERE IBLOCK_ID = \'' . $this_iblock_id . '\' AND ACTIVE = \'Y\' GROUP BY YEAR(ACTIVE_FROM)');
while ($row = $results->Fetch())
{
$years[] = $row['years'];
}
//print_r($_GET);
$where_year = (int)isset($_GET['year']) ? $_GET['year'] : date('Y');
//месяцы
$months = array();
$results = $DB->Query('SELECT YEAR(ACTIVE_FROM) as months_year, MONTH(ACTIVE_FROM) as months FROM b_iblock_element WHERE IBLOCK_ID = \'' . $this_iblock_id . '\' AND ACTIVE = \'Y\' AND YEAR(ACTIVE_FROM) = \'' . $where_year . '\' GROUP BY MONTH(ACTIVE_FROM)');
while ($row = $results->Fetch())
{
// print_r($row);
$months[] = array(
'year' => $row['months_year'],
'month' => $row['months']);
}
$rktvFilterMenu = array(
'years' => $years,
'months' => $months
);
if ($useCache)
{
// сохранить в кэше массив $arResult
$cachedResult->StartDataCache();
$cachedResult->EndDataCache($rktvFilterMenu);
}
}
//print_r($rktvFilterMenu);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment