Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
user.php
1<?
3
8
9Loc::loadMessages(__FILE__);
10
12{
13 protected static $moduleId = "forum";
14 private static $limit = 10;
15
16 public static function getTitle()
17 {
18 return 'User statistic calculation';
19 }
20
21 public function execute(array &$option)
22 {
23 $option["steps"] = 1;
24 $option["count"] = 1;
25 if (self::do() > 0)
26 {
28 }
30 }
31
32 private static function do()
33 {
34 $limit = self::$limit;
35 $dbRes = Main\Application::getConnection()->query(<<<SQL
36SELECT ID, ENTITY_ID
37FROM b_forum_service_statistic_queue
38WHERE ENTITY_TYPE='USER'
39ORDER BY ID ASC
40LIMIT {$limit}
41SQL
42 );
43
44 $last = null;
45 while (($res = $dbRes->fetch()))
46 {
47 if ($usr = Forum\User::getById($res['ENTITY_ID']))
48 {
49 $usr->calculateStatistic();
50 }
51 $last = $res;
52 }
53
54 if ($last)
55 {
56 Main\Application::getConnection()->queryExecute(<<<SQL
57DELETE FROM b_forum_service_statistic_queue WHERE ID >= {$last['ID']} AND ENTITY_TYPE='USER'
58SQL
59 );
60 }
61 return $limit;
62 }
63
64 public static function runForTopic(int $topicId)
65 {
66 Main\Application::getConnection()->queryExecute(<<<SQL
67INSERT IGNORE INTO b_forum_service_statistic_queue (ENTITY_TYPE, ENTITY_ID)
68SELECT 'USER', AUTHOR_ID
69FROM b_forum_message
70WHERE TOPIC_ID = {$topicId} AND AUTHOR_ID > 0 AND APPROVED='Y'
71GROUP BY AUTHOR_ID
72SQL
73 );
74 self::bind(0);
75 }
76
77 public static function calcForTopics(array $topicIds)
78 {
79 $topicIds = implode(', ', array_map('intval', $topicIds));
80 if ($topicIds === '')
81 {
82 return;
83 }
84 Main\Application::getConnection()->queryExecute(<<<SQL
85INSERT IGNORE INTO b_forum_service_statistic_queue (ENTITY_TYPE, ENTITY_ID)
86SELECT 'USER', AUTHOR_ID
87FROM b_forum_message
88WHERE TOPIC_ID IN ({$topicIds}) AND AUTHOR_ID > 0 AND APPROVED='Y'
89GROUP BY AUTHOR_ID
90SQL
91 );
92 self::bind(300);
93 }
94}
static runForTopic(int $topicId)
Definition user.php:64
static calcForTopics(array $topicIds)
Definition user.php:77
execute(array &$option)
Definition user.php:21
static loadMessages($file)
Definition loc.php:64