Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
limit.php
1<?php
2namespace Bitrix\Im;
3
4class Limit
5{
6 const COUNTER_CALL_SUCCESS = 'counter_call_success';
7 const CALL_SCREEN_SHARING = 'call_screen_sharing';
8 const CALL_RECORD = 'call_record';
9 const CALL_BACKGROUND = 'call_background';
10 const CALL_BLUR_BACKGROUND = 'call_blur_background';
11
13
14 public static function getTypes()
15 {
16 $list = [];
17
19 $list[] = self::getTypeCallRecord();
22
23 return $list;
24 }
25
26 public static function getTypesForJs()
27 {
28 $result = [];
29
30 $list = self::getTypes();
31 foreach ($list as $limit)
32 {
33 $result[] = [
34 'id' => $limit['ID'],
35 'articleCode' => $limit['ARTICLE_CODE'],
36 'active' => $limit['ACTIVE'],
37 ];
38 }
39
40 return $result;
41 }
42
43 public static function getTypeCallScreenSharing()
44 {
45 return [
47 'ACTIVE' => !self::isActiveCallExtension(),
48 'ARTICLE_CODE' => 'limit_video_conference_screen_demonstration',
49 ];
50 }
51
52 public static function getTypeCallRecord()
53 {
54 return [
55 'ID' => self::CALL_RECORD,
56 'ACTIVE' => !self::isActiveCallExtension(),
57 'ARTICLE_CODE' => 'limit_video_conference_record',
58 ];
59 }
60
61 public static function getTypeCallBackground()
62 {
63 return [
65 'ACTIVE' => !self::isActiveCallExtension(),
66 'ARTICLE_CODE' => 'limit_video_own_background',
67 ];
68 }
69
70 public static function getTypeCallBlurBackground()
71 {
72 return [
74 'ACTIVE' => !self::isActiveCallExtension(),
75 'ARTICLE_CODE' => 'limit_video_blur_background',
76 ];
77 }
78
79 public static function isActiveCallExtension()
80 {
81 if (!is_null(static::$isActiveCallExtension))
82 {
83 return static::$isActiveCallExtension;
84 }
85
86 if (!\Bitrix\Main\Loader::includeModule('bitrix24'))
87 {
88 static::$isActiveCallExtension = true;
89 return true;
90 }
91
92 $value = (int)\Bitrix\Bitrix24\Feature::getVariable('im_call_extensions_limit');
93 if ($value === 0)
94 {
95 static::$isActiveCallExtension = true;
96 return true;
97 }
98
99 $calls = self::getCounter(self::COUNTER_CALL_SUCCESS);
100 if ($calls >= $value)
101 {
102 static::$isActiveCallExtension = false;
103 return false;
104 }
105
106 static::$isActiveCallExtension = true;
107 return true;
108 }
109
110
111 public static function getCounter(string $code)
112 {
113 $code = mb_strtolower($code);
114 return \CGlobalCounter::GetValue('im_limit_'.$code, \CGlobalCounter::ALL_SITES);
115 }
116
117 public static function setCounter(string $code, int $value)
118 {
119 if ($code === self::COUNTER_CALL_SUCCESS)
120 {
121 static::$isActiveCallExtension = null;
122 }
123
124 $code = mb_strtolower($code);
125 return \CGlobalCounter::Set('im_limit_'.$code, $value, \CGlobalCounter::ALL_SITES, '', false);
126 }
127
128 public static function incrementCounter(string $code)
129 {
130 if ($code === self::COUNTER_CALL_SUCCESS)
131 {
132 static::$isActiveCallExtension = null;
133 }
134
135 $code = mb_strtolower($code);
136 return \CGlobalCounter::Increment('im_limit_'.$code, \CGlobalCounter::ALL_SITES, false);
137 }
138}
const CALL_BLUR_BACKGROUND
Definition limit.php:10
static getTypes()
Definition limit.php:14
static getTypeCallBlurBackground()
Definition limit.php:70
static getTypeCallRecord()
Definition limit.php:52
static incrementCounter(string $code)
Definition limit.php:128
const CALL_RECORD
Definition limit.php:8
const CALL_BACKGROUND
Definition limit.php:9
const COUNTER_CALL_SUCCESS
Definition limit.php:6
static setCounter(string $code, int $value)
Definition limit.php:117
static getTypeCallScreenSharing()
Definition limit.php:43
static $isActiveCallExtension
Definition limit.php:12
const CALL_SCREEN_SHARING
Definition limit.php:7
static getTypesForJs()
Definition limit.php:26
static isActiveCallExtension()
Definition limit.php:79
static getCounter(string $code)
Definition limit.php:111
static getTypeCallBackground()
Definition limit.php:61