Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
logview.php
1<?php
9
10use Bitrix\Main;
14
15Loc::loadMessages(__FILE__);
16
33class LogViewTable extends Entity\DataManager
34{
35 public static function getTableName()
36 {
37 return 'b_sonet_log_view';
38 }
39
40 public static function getMap()
41 {
42 return [
43 'USER_ID' => [
44 'data_type' => 'integer',
45 'primary' => true,
46 ],
47 'EVENT_ID' => [
48 'data_type' => 'string',
49 'primary' => true,
50 ],
51 'TYPE' => [
52 'data_type' => 'boolean',
53 'values' => [ 'N', 'Y' ],
54 ],
55 ];
56 }
57
58 public static function getDefaultValue($eventId, $full = false)
59 {
60 $result = 'Y';
61
62 $eventId = trim($eventId);
63 if($eventId !== '')
64 {
65 throw new Main\SystemException('Empty eventId.');
66 }
67 if (!$full)
68 {
69 $eventId = \CSocNetLogTools::findFullSetByEventID($eventId);
70 }
71
72 $res = self::getList([
73 'order' => [],
74 'filter' => [
75 '=USER_ID' => 0,
76 '=EVENT_ID' => \Bitrix\Main\Application::getConnection()->getSqlHelper()->forSql($eventId),
77 ],
78 'select' => [ 'TYPE' ],
79 ]);
80
81 if ($row = $res->fetch())
82 {
83 $result = $row['TYPE'];
84 }
85
86 return $result;
87 }
88
89 public static function set($userId, $eventId, $type): void
90 {
91 $userId = (int)$userId;
92 $type = ($type === 'Y' ? 'Y' : 'N');
93 $eventId = trim($eventId);
94 if ($eventId === '')
95 {
96 throw new Main\SystemException('Empty eventId.');
97 }
98 $eventId = \CSocNetLogTools::findFullSetByEventID($eventId);
99
100 $connection = \Bitrix\Main\Application::getConnection();
101 $helper = $connection->getSqlHelper();
102
103 foreach ($eventId as $val)
104 {
105 $insertFields = [
106 'USER_ID' => $userId,
107 'TYPE' => $type,
108 'EVENT_ID' => $helper->forSql($val),
109 ];
110
111 $updateFields = [
112 'TYPE' => $type,
113 ];
114
115 $merge = $helper->prepareMerge(
116 static::getTableName(),
117 [ 'USER_ID', 'EVENT_ID' ],
118 $insertFields,
119 $updateFields
120 );
121
122 if ($merge[0] !== '')
123 {
124 $connection->query($merge[0]);
125 }
126 }
127 }
128
129 public static function checkExpertModeAuto($userId, $tasksNum, $pageSize): bool
130 {
131 $result = false;
132
133 $userId = (int)$userId;
134 $tasksNum = (int)$tasksNum;
135 $pageSize = (int)$pageSize;
136
137 if (
138 $userId <= 0
139 || $pageSize <= 0
140 )
141 {
142 return false;
143 }
144
145 if (
146 $tasksNum >= 5
147 && ($tasksNum / $pageSize) >= 0.25
148 )
149 {
150 $isAlreadyChecked = \CUserOptions::getOption('socialnetwork', '~log_expertmode_checked', 'N', $userId);
151 if ($isAlreadyChecked !== 'Y')
152 {
153 self::set($userId, 'tasks', 'N');
154 \CUserOptions::setOption('socialnetwork', '~log_expertmode_checked', 'Y', false, $userId);
155 $result = true;
156 }
157 }
158
159 return $result;
160 }
161
162 public static function add(array $data)
163 {
164 throw new NotImplementedException('Use set() method of the class.');
165 }
166
167 public static function update($primary, array $data)
168 {
169 throw new NotImplementedException('Use set() method of the class.');
170 }
171}
static getConnection($name="")
static loadMessages($file)
Definition loc.php:64
static set($userId, $eventId, $type)
Definition logview.php:89
static checkExpertModeAuto($userId, $tasksNum, $pageSize)
Definition logview.php:129
static getDefaultValue($eventId, $full=false)
Definition logview.php:58
static update($primary, array $data)
Definition logview.php:167