Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Iblock.php
1<?php
2
4
6
7class IblockTable extends Entity\DataManager
8{
9 const ACTIVE = 'Y';
10 const INACTIVE = 'N';
11
12 const TYPE_ELEMENT = 'E';
13 const TYPE_SECTION = 'S';
14
15 protected static $iblockCache = array();
16
22 public static function getTableName()
23 {
24 return 'b_seo_sitemap_iblock';
25 }
26
32 public static function getMap()
33 {
34 $fieldsMap = array(
35 'ID' => array(
36 'data_type' => 'integer',
37 'primary' => true,
38 'autocomplete' => true,
39 ),
40 'SITEMAP_ID' => array(
41 'data_type' => 'integer',
42 'required' => true,
43 ),
44 'IBLOCK_ID' => array(
45 'data_type' => 'integer',
46 'required' => true,
47 ),
48 'SITEMAP' => array(
49 'data_type' => 'Bitrix\Seo\Sitemap\Internals\SitemapTable',
50 'reference' => array('=this.SITEMAP_ID' => 'ref.ID'),
51 ),
52 'IBLOCK' => array(
53 'data_type' => 'Bitrix\Iblock\IblockTable',
54 'reference' => array('=this.IBLOCK_ID' => 'ref.ID'),
55 ),
56 );
57
58 return $fieldsMap;
59 }
60
68 public static function clearBySitemap($sitemapId)
69 {
70 $connection = \Bitrix\Main\Application::getConnection();
71 $query = $connection->query("
72DELETE
73FROM ".self::getTableName()."
74WHERE SITEMAP_ID='".intval($sitemapId)."'
75");
76 }
77
87 public static function getByIblock($fields, $itemType)
88 {
89 $sitemaps = array();
90
91 if(!isset(self::$iblockCache[$fields['IBLOCK_ID']]))
92 {
93 self::$iblockCache[$fields['IBLOCK_ID']] = array();
94
95 $dbRes = self::getList(array(
96 'filter' => array(
97 'IBLOCK_ID' => $fields['IBLOCK_ID']
98 ),
99 'select' => array('SITEMAP_ID',
100 'SITE_ID' => 'SITEMAP.SITE_ID', 'SITEMAP_SETTINGS' => 'SITEMAP.SETTINGS',
101 'IBLOCK_CODE' => 'IBLOCK.CODE', 'IBLOCK_XML_ID' => 'IBLOCK.XML_ID',
102 'DETAIL_PAGE_URL' => 'IBLOCK.DETAIL_PAGE_URL',
103 'SECTION_PAGE_URL' => 'IBLOCK.SECTION_PAGE_URL',
104 ),
105 ));
106
107 while($res = $dbRes->fetch())
108 {
109 self::$iblockCache[$fields['IBLOCK_ID']][] = $res;
110 }
111 }
112
113 foreach(self::$iblockCache[$fields['IBLOCK_ID']] as $res)
114 {
115 $sitemapSettings = unserialize($res['SITEMAP_SETTINGS'], ['allowed_classes' => false]);
116
117 $add = false;
118
119 if($itemType == self::TYPE_SECTION)
120 {
121 $add = self::checkSection(
122 $fields['ID'],
123 $sitemapSettings['IBLOCK_SECTION_SECTION'][$fields['IBLOCK_ID']],
124 $sitemapSettings['IBLOCK_SECTION'][$fields['IBLOCK_ID']]
125 );
126 }
127 else
128 {
129 if(is_array($fields['IBLOCK_SECTION']) && count($fields['IBLOCK_SECTION']) > 0)
130 {
131 foreach($fields['IBLOCK_SECTION'] as $sectionId)
132 {
133 $add = self::checkSection(
134 $sectionId,
135 $sitemapSettings['IBLOCK_SECTION_ELEMENT'][$fields['IBLOCK_ID']],
136 $sitemapSettings['IBLOCK_ELEMENT'][$fields['IBLOCK_ID']]
137 );
138
139 if($add)
140 {
141 break;
142 }
143 }
144 }
145 else
146 {
147 $add = $sitemapSettings['IBLOCK_ELEMENT'][$fields['IBLOCK_ID']] == 'Y';
148 }
149 }
150
151 if($add)
152 {
153 $sitemaps[] = array(
154 'IBLOCK_CODE' => $res['IBLOCK_CODE'],
155 'IBLOCK_XML_ID' => $res['IBLOCK_XML_ID'],
156 'DETAIL_PAGE_URL' => $res['DETAIL_PAGE_URL'],
157 'SECTION_PAGE_URL' => $res['SECTION_PAGE_URL'],
158 'SITE_ID' => $res['SITE_ID'],
159 'PROTOCOL' => $sitemapSettings['PROTO'] == 1 ? 'https' : 'http',
160 'DOMAIN' => $sitemapSettings['DOMAIN'],
161 'ROBOTS' => $sitemapSettings['ROBOTS'],
162 'SITEMAP_DIR' => $sitemapSettings['DIR'],
163 'SITEMAP_FILE' => $sitemapSettings['FILENAME_INDEX'],
164 'SITEMAP_FILE_IBLOCK' => $sitemapSettings['FILENAME_IBLOCK'],
165 );
166 }
167 }
168
169 return $sitemaps;
170 }
171
181 public static function checkSection($sectionId, $sectionSettings, $defaultValue)
182 {
183 $value = $defaultValue;
184
185 if(is_array($sectionSettings) && count($sectionSettings) > 0)
186 {
187 while ($sectionId > 0)
188 {
189 if(isset($sectionSettings[$sectionId]))
190 {
191 $value = $sectionSettings[$sectionId];
192 break;
193 }
194
195 $dbRes = \CIBlockSection::getList(array(), array('ID' => $sectionId), false, array('ID', 'IBLOCK_SECTION_ID'));
196 $section = $dbRes->fetch();
197
198 $sectionId = $section["IBLOCK_SECTION_ID"];
199 }
200 }
201
202 return $value === 'Y';
203 }
204}
static getByIblock($fields, $itemType)
Definition Iblock.php:87
static checkSection($sectionId, $sectionSettings, $defaultValue)
Definition Iblock.php:181