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