Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Entity.php
1<?php
2
4
6
7class EntityTable extends Entity\DataManager
8{
9 const ENTITY_TYPE = 'ENTITY';
10 protected static array $entityCache = [];
11
12 public static function getFilePath(): string
13 {
14 return __FILE__;
15 }
16
17 public static function getTableName()
18 {
19 return 'b_seo_sitemap_entity';
20 }
21
22 public static function add(array $data)
23 {
24 $sitemapId = $data['SITEMAP_ID'];
25 $entityId = $data['ENTITY_ID'];
26 return parent::add(array(
27 'ENTITY_TYPE' => static::ENTITY_TYPE,
28 'ENTITY_ID' => $entityId,
29 'SITEMAP_ID' => $sitemapId,
30 ));
31 }
32
33 public static function getMap()
34 {
35 $fieldsMap = array(
36 'ID' => array(
37 'data_type' => 'integer',
38 'primary' => true,
39 'autocomplete' => true,
40 ),
41 'ENTITY_TYPE' => array(
42 'data_type' => 'string',
43 'required' => true,
44 ),
45 'ENTITY_ID' => array(
46 'data_type' => 'integer',
47 'required' => true,
48 ),
49 'SITEMAP_ID' => array(
50 'data_type' => 'integer',
51 'required' => true,
52 ),
53 'SITEMAP' => array(
54 'data_type' => 'Bitrix\Seo\Sitemap\Internals\SitemapTable',
55 'reference' => array('=this.SITEMAP_ID' => 'ref.ID'),
56 )
57 );
58
59 return $fieldsMap;
60 }
61
62 public static function getSitemapsByEntityId($entityId)
63 {
64 if (!isset(self::$entityCache[$entityId.'Sitemaps']))
65 {
66 self::$entityCache[$entityId] = array();
67
68 $dbRes = self::getList(array(
69 'filter' => array(
70 '=ENTITY_TYPE' => static::ENTITY_TYPE,
71 '=ENTITY_ID' => $entityId
72 ),
73 'select' => array(
74 'SITEMAP_ID',
75 'SITE_ID' => 'SITEMAP.SITE_ID',
76 'SITEMAP_SETTINGS' => 'SITEMAP.SETTINGS'
77 )
78 ));
79 $arSitemaps = array();
80 while($arRes = $dbRes->fetch())
81 {
82 $arRes["SITEMAP_SETTINGS"] = unserialize($arRes['SITEMAP_SETTINGS'], ['allowed_classes' => false]);
83 self::$entityCache[$entityId][] = $arRes;
84 if ($arRes["SITEMAP_SETTINGS"][static::ENTITY_TYPE."_ACTIVE"] &&
85 $arRes["SITEMAP_SETTINGS"][static::ENTITY_TYPE."_ACTIVE"][$entityId] == "Y")
86 {
87 $arSitemaps[] = array(
88 'SITEMAP_ID' => $arRes['SITEMAP_ID'],
89 'SITE_ID' => $arRes['SITE_ID'],
90 'PROTOCOL' => $arRes["SITEMAP_SETTINGS"]['PROTO'] == 1 ? 'https' : 'http',
91 'DOMAIN' => $arRes["SITEMAP_SETTINGS"]['DOMAIN'],
92 'ROBOTS' => $arRes["SITEMAP_SETTINGS"]['ROBOTS'],
93 'SITEMAP_DIR' => $arRes["SITEMAP_SETTINGS"]['DIR'],
94 'SITEMAP_FILE' => $arRes["SITEMAP_SETTINGS"]['FILENAME_INDEX'],
95 'SITEMAP_FILE_'.static::ENTITY_TYPE => $arRes["SITEMAP_SETTINGS"]['FILENAME_'.static::ENTITY_TYPE],
96 'SITEMAP_SETTINGS' => $arRes["SITEMAP_SETTINGS"]
97 );
98 }
99 }
100 self::$entityCache[$entityId.'Sitemaps'] = $arSitemaps;
101 }
102
103 return self::$entityCache[$entityId.'Sitemaps'];
104 }
105
106 public static function clearBySitemap($sitemapId)
107 {
108 $connection = \Bitrix\Main\Application::getConnection();
109 $connection->query("
110DELETE
111FROM ".self::getTableName()."
112WHERE SITEMAP_ID=".intval($sitemapId)." AND ENTITY_TYPE='".static::ENTITY_TYPE."'
113");
114 }
115}
static getSitemapsByEntityId($entityId)
Definition Entity.php:62