Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
view.php
1<?php
3
5use \Bitrix\Main\Entity;
6use \Bitrix\Main\Type\DateTime;
7use \Bitrix\Landing\Manager;
8use \Bitrix\Landing\Landing;
9use \Bitrix\Landing\Rights;
10use \Bitrix\Landing\Internals\ViewTable;
11use \Bitrix\Landing\Controller;
12
13class View
14{
18 const SESSION_VIEWS_KEY = 'LANDING_VIEWS';
19
25 protected static function incViewsPage($lid)
26 {
27 $lid = (int)$lid;
28 $res = ViewTable::getList([
29 'select' => [
30 'SUM'
31 ],
32 'filter' => [
33 'LID' => $lid
34 ],
35 'runtime' => [
37 'SUM', 'SUM(%s)', ['VIEWS']
38 )
39 ]
40 ]);
41 if ($row = $res->fetch())
42 {
44 Landing::update($lid, [
45 'VIEWS' => $row['SUM'],
46 'DATE_MODIFY' => false
47 ]);
49 }
50 }
51
58 public static function inc($lid, $uid = null)
59 {
60 if (!$uid)
61 {
62 $uid = Manager::getUserId();
63 }
64 $lid = (int)$lid;
65 $uid = (int)$uid;
66 $date = new DateTime;
67
68 if ($uid <= 0)
69 {
70 return;
71 }
72 if (!isset($_SESSION[self::SESSION_VIEWS_KEY]))
73 {
74 $_SESSION[self::SESSION_VIEWS_KEY] = [];
75 }
76
77 if (!in_array($lid, $_SESSION[self::SESSION_VIEWS_KEY]))
78 {
79 $res = ViewTable::getList([
80 'select' => [
81 'ID', 'VIEWS'
82 ],
83 'filter' => [
84 'LID' => $lid,
85 'USER_ID' => $uid
86 ]
87 ]);
88 if ($row = $res->fetch())
89 {
90 $result = ViewTable::update($row['ID'], [
91 'VIEWS' => $row['VIEWS'] + 1,
92 'LAST_VIEW' => $date
93 ]);
94 }
95 else
96 {
97 $result = ViewTable::add([
98 'VIEWS' => 1,
99 'LID' => $lid,
100 'USER_ID' => $uid,
101 'FIRST_VIEW' => $date,
102 'LAST_VIEW' => $date,
103 ]);
104 }
105 if ($result->isSuccess())
106 {
107 self::incViewsPage($lid);
108 $_SESSION[self::SESSION_VIEWS_KEY][] = $lid;
109 }
110 }
111 }
112
113 public static function getNumberUniqueViews(int $lid): int
114 {
115 $lid = (int)$lid;
116 $res = ViewTable::getList([
117 'select' => [
118 'COUNT'
119 ],
120 'filter' => [
121 'LID' => $lid
122 ],
123 'runtime' => [
125 'COUNT', 'COUNT(*)'
126 )
127 ]
128 ]);
129
130 if ($row = $res->fetch())
131 {
132 $views = (int)$row['COUNT'];
133 }
134
135 if (isset($views) && is_int($views))
136 {
137 return $views;
138 }
139
140 return 0;
141 }
142
143 public static function getUniqueUserData(int $lid): array
144 {
145 $res = ViewTable::getList([
146 'select' => [
147 'USER_ID'
148 ],
149 'filter' => [
150 'LID' => $lid
151 ]
152 ]);
153 $data = [];
154 while ($row = $res->fetch())
155 {
156 $data['id'][] = $row['USER_ID'];
157 }
158 $usersInfo = Controller\User::getUsersInfoAction($data['id']);
159 $data['name'] = $usersInfo['name'];
160 $countUsers = count($usersInfo['name']);
161 for ($i = 0; $i < $countUsers; $i++)
162 {
163 if ($usersInfo['personalPhoto'][$i])
164 {
165 $avatar = \CFile::ResizeImageGet(
166 $usersInfo['personalPhoto'][$i],
167 ['width' => 58, 'height' => 58],
168 BX_RESIZE_IMAGE_EXACT
169 );
170 }
171 if (isset($avatar['src']))
172 {
173 $data['avatar'][] = $avatar['src'];
174 }
175 else
176 {
177 $data['avatar'][] = '';
178 }
179 unset($avatar);
180 }
181
182 return $data;
183 }
184}
static getUniqueUserData(int $lid)
Definition view.php:143
static incViewsPage($lid)
Definition view.php:25
static getNumberUniqueViews(int $lid)
Definition view.php:113
static inc($lid, $uid=null)
Definition view.php:58
static update($id, $fields=array())
Definition landing.php:3110