Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
paramphotogallery.php
1<?php
2
4
7
9{
10 protected $component;
11
12 public function __construct($params)
13 {
14 if (!empty($params['component']))
15 {
16 $this->component = $params['component'];
17 }
18 }
19
20 public function getComponent()
21 {
22 return $this->component;
23 }
24
25 public function preparePhotogalleryParams(&$componentParams): void
26 {
27 if (!ModuleManager::isModuleInstalled('photogallery'))
28 {
29 return;
30 }
31
32 Util::checkEmptyParamInteger($componentParams, 'PHOTO_COUNT', 6);
33 Util::checkEmptyParamInteger($componentParams, 'PHOTO_THUMBNAIL_SIZE', 48);
34
35 $folderUsers = $this->getComponent()->getPathInstance()->getFolderUsersValue();
36 $folderWorkgroups = $this->getComponent()->getPathInstance()->getFolderWorkgroupsValue();
37
38 Util::checkEmptyParamString($componentParams, 'PHOTO_USER_IBLOCK_TYPE', 'photos');
39
40 if (
41 (
42 !isset($componentParams['PHOTO_USER_IBLOCK_ID'])
43 || (int)$componentParams['PHOTO_USER_IBLOCK_ID'] <= 0
44 )
45 && Loader::includeModule('iblock')
46 )
47 {
48 $res = \CIBlock::getList(
49 [],
50 [
51 'SITE_ID' => SITE_ID,
52 '=CODE' => 'user_photogallery'
53 ]
54 );
55 if ($iblockFields = $res->fetch())
56 {
57 $componentParams['PHOTO_USER_IBLOCK_ID'] = $iblockFields['ID'];
58 }
59 }
60
61 if (
62 (
63 !isset($componentParams['PHOTO_FORUM_ID'])
64 || (int)$componentParams['PHOTO_FORUM_ID'] <= 0
65 )
66 && Loader::includeModule('forum')
67 )
68 {
69 $res = \CForumNew::getListEx(
70 [],
71 [
72 'SITE_ID' => SITE_ID,
73 'XML_ID' => 'PHOTOGALLERY_COMMENTS'
74 ]
75 );
76 if ($forumFields = $res->fetch())
77 {
78 $componentParams['PHOTO_FORUM_ID'] = $forumFields['ID'];
79 }
80 }
81
82 Util::checkEmptyParamString($componentParams, 'PATH_TO_USER_PHOTO', $folderUsers.'user/#user_id#/photo/');
83 Util::checkEmptyParamString($componentParams, 'PATH_TO_GROUP_PHOTO', $folderWorkgroups.'group/#group_id#/photo/');
84 Util::checkEmptyParamString($componentParams, 'PATH_TO_USER_PHOTO_SECTION', $folderUsers.'user/#user_id#/photo/album/#section_id#/');
85 Util::checkEmptyParamString($componentParams, 'PATH_TO_GROUP_PHOTO_SECTION', $folderWorkgroups.'group/#group_id#/photo/album/#section_id#/');
86 Util::checkEmptyParamString($componentParams, 'PATH_TO_USER_PHOTO_ELEMENT', $folderUsers.'user/#user_id#/photo/photo/#section_id#/#element_id#/');
87 Util::checkEmptyParamString($componentParams, 'PATH_TO_GROUP_PHOTO_ELEMENT', $folderWorkgroups.'group/#group_id#/photo/#section_id#/#element_id#/');
88 }
89
90 public function prepareParentPhotogalleryParams(&$componentParams): void
91 {
92 if (
93 (
94 (string)$componentParams['PHOTO_GROUP_IBLOCK_TYPE'] === ''
95 || (int)$componentParams['PHOTO_GROUP_IBLOCK_ID'] <= 0
96 )
97 && Loader::includeModule('iblock'))
98 {
99 $ttl = 60*60*24;
100 $cacheId = 'sonet_group_photo_iblock_'.SITE_ID;
101 $cacheDir = '/bitrix/sonet_group_photo_iblock';
102 $cache = new \CPHPCache;
103
104 if($cache->initCache($ttl, $cacheId, $cacheDir))
105 {
106 $cacheData = $cache->getVars();
107 $componentParams['PHOTO_GROUP_IBLOCK_TYPE'] = $cacheData['PHOTO_GROUP_IBLOCK_TYPE'];
108 $componentParams['PHOTO_GROUP_IBLOCK_ID'] = $cacheData['PHOTO_GROUP_IBLOCK_ID'];
109 unset($cacheData);
110 }
111 else
112 {
113 $res = \CIBlockType::getById('photos');
114 if ($IBlockTypeFields = $res->fetch())
115 {
116 $resIBlock = \CIBlock::getList(
117 [ 'SORT' => 'ASC' ],
118 [
119 'IBLOCK_TYPE' => $IBlockTypeFields['ID'],
120 'CODE' => [ 'group_photogallery', 'group_photogallery_'.SITE_ID ],
121 'ACTIVE' => 'Y',
122 'SITE_ID' => SITE_ID
123 ]
124 );
125 if ($IBlockFields = $resIBlock->fetch())
126 {
127 $componentParams['PHOTO_GROUP_IBLOCK_TYPE'] = $IBlockFields['IBLOCK_TYPE_ID'];
128 $componentParams['PHOTO_GROUP_IBLOCK_ID'] = $IBlockFields['ID'];
129 }
130 }
131
132 if ($cache->startDataCache())
133 {
134 $cache->endDataCache([
135 'PHOTO_GROUP_IBLOCK_TYPE' => $componentParams['PHOTO_GROUP_IBLOCK_TYPE'],
136 'PHOTO_GROUP_IBLOCK_ID' => $componentParams['PHOTO_GROUP_IBLOCK_ID']
137 ]);
138 }
139 }
140 unset($cache);
141 }
142 }
143}
static checkEmptyParamString(&$params, $paramName, $defaultValue)
Definition util.php:15
static checkEmptyParamInteger(&$params, $paramName, $defaultValue)
Definition util.php:10