component.php
1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?
use \Cpeople\Classes\Block;
if ($this->StartResultCache(COMPONENTS_CACHE_TTL))
{
/** @var $item \SH\Entities\Partner */
/** @var $type \SH\Entities\PartnerType */
$arResult['ITEMS'] = Block\Getter::instance()
->setFilter(array('IBLOCK_ID' => IBLOCK_PARTNERS, 'ACTIVE' => 'Y'))
->setOrder(array('SORT' => 'ASC', 'NAME' => 'ASC'))
->setClassName('\SH\Entities\Partner')
->get();
$arResult['TYPES'] = Block\Getter::instance()
->setFilter(array('IBLOCK_ID' => IBLOCK_PARTNERS_TYPE, 'ACTIVE' => 'Y'))
->setOrder(array('SORT' => 'ASC', 'NAME' => 'ASC'))
->setClassName('\SH\Entities\PartnerType')
->get();
$arResult['SEPARATE'] = array();
$arResult['SEPARATE_BY_ID'] = array();
foreach($arResult['TYPES'] as $i => $type) {
if(!$type->isSeparate()) continue;
$arResult['SEPARATE_BY_ID'][$type->ID] = $arResult['TYPES'][$i];
$arResult['SEPARATE'][] = $arResult['SEPARATE_BY_ID'][$type->ID];
$arResult['SEPARATE_BY_ID'][$type->ID]->items = array();
unset($arResult['TYPES'][$i]);
}
foreach($arResult['ITEMS'] as $i => $item) {
$item->typesId = $item->getPartnersTypeIds();
$isSeparated = false;
foreach($item->typesId as $j => $typeId) {
if(!isset($arResult['SEPARATE_BY_ID'][$typeId])) continue;
$arResult['SEPARATE_BY_ID'][$typeId]->items[] = $arResult['ITEMS'][$i];
unset($item->typesId[$j]);
$isSeparated = true;
}
if(!$item->typesId) {
if($isSeparated) {
unset($arResult['ITEMS'][$i]);
} else {
$item->typesId = array(0);
}
}
}
$arResult['ITEMS'] = array_values($arResult['ITEMS']);
$this->SetResultCacheKeys(array());
$this->IncludeComponentTemplate();
}
$APPLICATION->SetPageProperty('CONTAINER_EXTRA_CLASS', '_gray');