Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
block.php
1<?php
3
4use \Bitrix\Landing\Site;
5use \Bitrix\Landing\Internals;
6use \Bitrix\Landing\Site\Type;
7use \Bitrix\Bitrix24\Feature;
8use \Bitrix\Main\Application;
9
10class Block
11{
18 public static function isDynamicEnabled(string $code, array $params): bool
19 {
20 if (!\Bitrix\Main\Loader::includeModule('bitrix24'))
21 {
22 return true;
23 }
24
25 // @todo: make more useful in future
26 $scope = Site\Type::getCurrentScopeId();
27 if (
28 $scope == Type::SCOPE_CODE_KNOWLEDGE ||
29 $scope == Type::SCOPE_CODE_GROUP
30 )
31 {
32 return true;
33 }
34 $availableCount = Feature::getVariable(
35 'landing_dynamic_blocks'
36 );
37 if ($availableCount <= 0)
38 {
39 return true;
40 }
41
42 static $dynamicBlocks = null;
43 $targetBlockId = isset($params['targetBlockId'])
44 ? intval($params['targetBlockId'])
45 : 0;
46
47 // gets actual dynamic blocks
48 if ($dynamicBlocks === null)
49 {
50 $dynamicBlocks = [];
51 // plain sql, reason for this described in task 186683
52 $sql = '
53 SELECT
54 B.ID as ID,
55 B.PARENT_ID as PARENT_ID,
56 B.DATE_MODIFY as DATE_MODIFY,
57 S.ID as SID,
58 L.DELETED
59 FROM
60 ' . Internals\FilterBlockTable::getTableName() . ' FB
61 LEFT JOIN
62 ' . Internals\BlockTable::getTableName() . ' B
63 ON
64 FB.BLOCK_ID = B.ID
65 LEFT JOIN
66 ' . Internals\LandingTable::getTableName() . ' L
67 ON
68 B.LID = L.ID
69 LEFT JOIN
70 ' . Internals\SiteTable::getTableName() . ' S
71 ON
72 L.SITE_ID = S.ID
73 WHERE
74 B.DELETED = \'N\' AND
75 L.DELETED = \'N\' AND
76 S.DELETED = \'N\' AND
77 S.TYPE NOT IN (\'KNOWLEDGE\', \'GROUP\')
78 GROUP BY B.ID, S.ID, FB.BLOCK_ID, L.DELETED
79 ORDER BY B.DATE_MODIFY ASC;';
80 $res = Application::getConnection()->query($sql);
81 while ($row = $res->fetch())
82 {
83 $dynamicBlocks[$row['ID']] = $row;
84 }
85 // remove public blocks
86 foreach ($dynamicBlocks as $dynamicBlock)
87 {
88 if (
89 $dynamicBlock['PARENT_ID'] &&
90 isset($dynamicBlocks[$dynamicBlock['PARENT_ID']])
91 )
92 {
93 unset($dynamicBlocks[$dynamicBlock['PARENT_ID']]);
94 }
95 }
96 }
97
98 // allow only first $availableCount dynamic blocks
99 $dynamicBlocks = array_slice($dynamicBlocks, 0, $availableCount, true);
100 foreach ($dynamicBlocks as $dynamicBlock)
101 {
102 if (
103 $dynamicBlock['ID'] == $targetBlockId ||
104 $dynamicBlock['PARENT_ID'] == $targetBlockId
105 )
106 {
107 return true;
108 }
109 }
110
111 return false;
112 }
113
118 public static function isDesignerAllowed(): bool
119 {
120 if (\Bitrix\Main\Loader::includeModule('bitrix24'))
121 {
122 return Feature::isFeatureEnabled('landing_designerblock');
123 }
124
125 return true;
126 }
127}
static isDynamicEnabled(string $code, array $params)
Definition block.php:18
static getConnection($name="")