Created
December 11, 2013 10:04
-
-
Save sartas/7907904 to your computer and use it in GitHub Desktop.
bitrix group by
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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