-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Events.php
102 lines (73 loc) · 3.21 KB
/
Events.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* Peter Zieseniss
* Copyright (C) 2022
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace humhub\modules\social_stats;
use Yii;
use yii\helpers\Url;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\admin\widgets\AdminMenu;
use humhub\modules\admin\permissions\ManageModules;
use yii\db;
use yii\db\Connection;
use yii\db\Query;
use yii\db\Command;
class Events extends \yii\base\BaseObject{
public static function onAdminMenuInit($event){
if (!Yii::$app->user->can(ManageModules::class)) {
return;
}
/** @var AdminMenu $menu */
$menu = $event->sender;
$menu->addEntry(new MenuLink([
'label' => Yii::t('SocialStatsModule.base', 'Social Stats'),
'url' => Url::to(['/social_stats/main/index']),
//'group' => 'manage',
'icon' => 'bar-chart',
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'social_stats' && Yii::$app->controller->id == 'admin'),
'sortOrder' => 700,
]));
}
public static function onDailyCronRun(){
$TodaysDate=date("Y-m-d");
// Logins, Posts, Comments, Likes, Follows
$ReadLogins=Yii::$app->db->createCommand("SELECT COUNT(last_login) AS Logins
FROM user
WHERE (last_login >= (NOW() - INTERVAL 1 DAY));")->queryScalar();
$ReadPosts=Yii::$app->db->createCommand("SELECT COUNT(updated_at) AS Posts
FROM post
WHERE (updated_at >= (NOW() - INTERVAL 1 DAY));")->queryScalar();
$ReadComments=Yii::$app->db->createCommand("SELECT COUNT(updated_at) AS Comments
FROM comment
WHERE (updated_at >= (NOW() - INTERVAL 1 DAY));")->queryScalar();
$ReadLikes=Yii::$app->db->createCommand("SELECT COUNT(updated_at) AS Likes
FROM `like`
WHERE (updated_at >= (NOW() - INTERVAL 1 DAY));")->queryScalar();
$ReadFollows=Yii::$app->db->createCommand("SELECT COUNT(created_at) AS Follows
FROM notification
WHERE (created_at >= (NOW() - INTERVAL 1 DAY) AND source_class=\"humhub\\\\modules\\\\user\\\\models\\\\Follow\");")->queryScalar();
/* {x:'2022-09-08', y:360}, */
$DailyDataUpdate_cmd=Yii::$app->db->createCommand("INSERT INTO social_stats(x_value, y_value, category) VALUES
(:Xval,:Yval,:Categ);");
/* Logins */
$DailyDataUpdate_cmd->bindValues([':Xval'=>$TodaysDate,':Yval'=>$ReadLogins,':Categ'=>'Logins'])->query();
/* Posts */
$DailyDataUpdate_cmd->bindValues([':Xval'=>$TodaysDate,':Yval'=>$ReadPosts,':Categ'=>'Posts'])->query();
/* Comments */
$DailyDataUpdate_cmd->bindValues([':Xval'=>$TodaysDate,':Yval'=>$ReadComments,':Categ'=>'Comments'])->query();
/* Likes */
$DailyDataUpdate_cmd->bindValues([':Xval'=>$TodaysDate,':Yval'=>$ReadLikes,':Categ'=>'Likes'])->query();
/* Follows */
$DailyDataUpdate_cmd->bindValues([':Xval'=>$TodaysDate,':Yval'=>$ReadFollows,':Categ'=>'Follows'])->query();
}
}