-
Notifications
You must be signed in to change notification settings - Fork 3
/
statistics.php
213 lines (188 loc) · 8.08 KB
/
statistics.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
declare(strict_types=1);
/*
You may not change or alter any portion of this comment or credits
of supporting developers from this source code or any supporting source code
which is considered copyrighted (c) material of the original comment or credit authors.
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.
*/
/**
* wgDiaries module for xoops
*
* @copyright 2020 XOOPS Project (https://xooops.org)
* @license GPL 2.0 or later
* @package wgdiaries
* @since 1.0
* @min_xoops 2.5.9
* @author wedega - Email:<[email protected]> - Website:<https://xoops.wedega.com>
*/
use Xmf\Request;
use XoopsModules\Wgdiaries\Filterhandler;
require __DIR__ . '/header.php';
$GLOBALS['xoopsOption']['template_main'] = 'wgdiaries_statistics.tpl';
require_once \XOOPS_ROOT_PATH . '/header.php';
if (!$permissionsHandler->getPermStatisticsView()) {
\redirect_header('index.php?op=list', 3, \_NOPERM);
}
// Define Stylesheet
$GLOBALS['xoTheme']->addStylesheet($style, null);
// Breadcrumbs
$xoBreadcrumbs[] = ['title' => \_MA_WGDIARIES_STATISTICS];
$uid = \is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->uid() : 0;
$year = Request::getInt('year', (int) date('Y'));
$month = Request::getInt('month', (int) date('n'));
$yearStart = \mktime(0, 0, 0, 1, 1, $year);
$yearEnd = \mktime(23, 59, 59, 12, 31, $year) ;
$monthStart = \mktime(0, 0, 0, $month, 1, $year);
$lastday = (int) date('t', $monthStart);
$monthEnd = \mktime(23, 59, 59, $month, $lastday, $year);
$filterHandler = new Filterhandler();
$filterHandler->filterMonth = $month;
$filterHandler->filterYear = $year;
$formFilter = $filterHandler->getFormFilterStatistics();
$GLOBALS['xoopsTpl']->assign('formFilter', $formFilter->render());
/*
echo '<br>yearStart:'. date('Y-m-d H:i:s', $yearStart);
echo '<br>yearEnd:'. date('Y-m-d H:i:s', $yearEnd);
echo '<br>monthStart:'. date('Y-m-d H:i:s', $monthStart);
echo '<br>monthEnd:'. date('Y-m-d H:i:s', $monthEnd);
*/
if ($uid > 0) {
// own items
// current year
$itemsOwn = [];
$items = $itemsHandler->getItems($uid, 0, 0, $yearStart, $yearEnd);
if (\is_array($items)) {
$itemsOwn['year']['count'] = \count($items);
$itemsOwn['year']['fromto'] = \sprintf(\_MA_WGDIARIES_STATS_PERIOD_FROMTO, date('Y-m-d H:i:s', $yearStart), date('Y-m-d H:i:s', $yearEnd));
$diff = 0;
foreach ($items as $item) {
$diff += ((int)$item['item_dateto'] - (int)$item['item_datefrom']);
}
$hoursTotal = \round($diff / (60 * 60), 2);
$daysTotal = (int)($hoursTotal / 24);
if ($daysTotal > 0) {
$itemsOwnHours = \sprintf(\_MA_WGDIARIES_STATS_DAYSHOURS, $hoursTotal, $daysTotal, $hoursTotal - ($daysTotal * 24));
} else {
$itemsOwnHours = $hoursTotal;
}
$itemsOwn['year']['hours'] = $itemsOwnHours;
}
unset($items);
// current month
$items = $itemsHandler->getItems($uid, 0, 0, $monthStart, $monthEnd);
if (\is_array($items)) {
$itemsOwn['month']['count'] = \count($items);
$itemsOwn['month']['fromto'] = \sprintf(\_MA_WGDIARIES_STATS_PERIOD_FROMTO, date('Y-m-d H:i:s', $monthStart), date('Y-m-d H:i:s', $monthEnd));
$diff = 0;
foreach ($items as $item) {
$diff += ((int)$item['item_dateto'] - (int)$item['item_datefrom']);
}
$hoursTotal = \round($diff / (60 * 60), 2);
$daysTotal = (int)($hoursTotal / 24);
if ($daysTotal > 0) {
$itemsOwnHours = \sprintf(\_MA_WGDIARIES_STATS_DAYSHOURS, $hoursTotal, $daysTotal, $hoursTotal - ($daysTotal * 24));
} else {
$itemsOwnHours = $hoursTotal;
}
$itemsOwn['month']['hours'] = $itemsOwnHours;
}
unset($items);
$GLOBALS['xoopsTpl']->assign('itemsOwn', $itemsOwn);
}
if ($permissionsHandler->getPermItemsGroupView()) {
// items of my group
// current year
$itemsGroup = [];
$items = $itemsHandler->getItems(0, 0, 0, $yearStart, $yearEnd, true);
if (\is_array($items)) {
$itemsGroup['year']['count'] = \count($items);
$fromto = \sprintf(\_MA_WGDIARIES_STATS_PERIOD_FROMTO, date('Y-m-d H:i:s', $yearStart), date('Y-m-d H:i:s', $yearEnd));
$itemsGroup['year']['fromto'] = $fromto;
$diff = 0;
$diffusers = [];
foreach ($items as $item) {
$diff += ((int)$item['item_dateto'] - (int)$item['item_datefrom']);
$key = $item['item_submitter'];
if (\array_key_exists($key, $diffusers)) {
$diffusers[$key]['count']++;
$diffusers[$key]['diff'] += ((int)$item['item_dateto'] - (int)$item['item_datefrom']);
} else {
$diffusers[$key]['name'] = $item['submitter'];
$diffusers[$key]['count'] = 1;
$diffusers[$key]['diff'] = ((int)$item['item_dateto'] - (int)$item['item_datefrom']);
}
}
$hoursTotal = \round($diff / (60 * 60), 2);
$daysTotal = (int)($hoursTotal / 24);
if ($daysTotal > 0) {
$itemsGroupHours = \sprintf(\_MA_WGDIARIES_STATS_DAYSHOURS, $hoursTotal, $daysTotal, $hoursTotal - ($daysTotal * 24));
} else {
$itemsGroupHours = $hoursTotal;
}
foreach ($diffusers as $key => $diffuser) {
$result = createDaysHoursMinutes($diffuser['diff']);
$diffusers[$key]['hours'] = $result['hours'];
$diffusers[$key]['days'] = $result['days'];
$diffusers[$key]['hoursdesc'] = $result['hoursdesc'];
}
$itemsGroup['year']['hours'] = $itemsGroupHours;
$itemsGroup['year']['users'] = $diffusers;
}
unset($items);
// current month
$items = $itemsHandler->getItems(0, 0, 0, $monthStart, $monthEnd, true);
if (\is_array($items)) {
$itemsGroup['month']['count'] = \count($items);
$itemsGroup['month']['fromto'] = \sprintf(\_MA_WGDIARIES_STATS_PERIOD_FROMTO, date('Y-m-d H:i:s', $monthStart), date('Y-m-d H:i:s', $monthEnd));
$diff = 0;
$diffusers = [];
foreach ($items as $item) {
$diff += ((int)$item['item_dateto'] - (int)$item['item_datefrom']);
$key = $item['item_submitter'];
if (\array_key_exists($key, $diffusers)) {
$diffusers[$key]['count']++;
$diffusers[$key]['diff'] += ((int)$item['item_dateto'] - (int)$item['item_datefrom']);
} else {
$diffusers[$key]['name'] = $item['submitter'];
$diffusers[$key]['count'] = 1;
$diffusers[$key]['diff'] = ((int)$item['item_dateto'] - (int)$item['item_datefrom']);
}
}
foreach ($diffusers as $key => $diffuser) {
$result = createDaysHoursMinutes($diffuser['diff']);
$diffusers[$key]['hours'] = $result['hours'];
$diffusers[$key]['days'] = $result['days'];
$diffusers[$key]['hoursdesc'] = $result['hoursdesc'];
}
$itemsGroup['month']['hours'] = $itemsGroupHours;
$itemsGroup['month']['users'] = $diffusers;
}
unset($items);
$GLOBALS['xoopsTpl']->assign('itemsGroup', $itemsGroup);
}
// Description
wgdiariesMetaDescription(\_MA_WGDIARIES_STATISTICS);
$GLOBALS['xoopsTpl']->assign('xoops_mpageurl', \WGDIARIES_URL.'/index.php');
$GLOBALS['xoopsTpl']->assign('xoops_icons32_url', \XOOPS_ICONS32_URL);
$GLOBALS['xoopsTpl']->assign('wgdiaries_upload_url', \WGDIARIES_UPLOAD_URL);
require __DIR__ . '/footer.php';
/**
* @public function to get params of seconds
* @param $seconds
* @return array
*/
function createDaysHoursMinutes($seconds) {
$ret = [];
$hoursTotal = \round($seconds / (60 * 60), 2);
$ret['hours'] = $hoursTotal;
$daysTotal = (int)($hoursTotal / 24);
$ret['days'] = $daysTotal;
$dtF = new \DateTime('@0');
$dtT = new \DateTime("@$seconds");
$formatText = \str_replace('%s', (string)$hoursTotal, \_MA_WGDIARIES_STATS_DAYSHOURSMINUTES);
$ret['hoursdesc'] = $dtF->diff($dtT)->format($formatText);
return $ret;
}