4
4
use XdebugDotOrg \Core \HtmlResponse ;
5
5
6
6
use XdebugDotOrg \Model \SupportLog ;
7
+ use XdebugDotOrg \Model \SupportLogDayReport ;
8
+ use XdebugDotOrg \Model \SupportLogMonthReport ;
7
9
8
10
class SupportController
9
11
{
@@ -19,55 +21,59 @@ public static function reporting_bugs() : HtmlResponse
19
21
20
22
public static function log () : HtmlResponse
21
23
{
22
- $ d = Dir ( 'reports ' );
24
+ return new HtmlResponse (
25
+ \XdebugDotOrg \Core \ContentsCache::fetchModel (
26
+ SupportLog::class,
27
+ function () : SupportLog {
28
+ return self ::getLogModel ();
29
+ },
30
+ 'log '
31
+ ),
32
+ 'support/log.php '
33
+ );
34
+ }
35
+
36
+ public static function getLogModel () : SupportLog
37
+ {
38
+ $ d = \dir ( 'reports ' );
39
+
40
+ $ files = [];
23
41
24
- $ files = array ();
25
- while ( false !== ( $ entry = $ d ->read () ) )
26
- {
42
+ while ( false !== ( $ entry = $ d ->read () ) ) {
27
43
if (preg_match ( '@^20[0-9][0-9]-[01][0-9]\.txt$@ ' , $ entry , $ m )) {
28
44
$ files [] = $ entry ;
29
45
}
30
46
}
31
47
32
- rsort ($ files );
48
+ \ rsort ($ files );
33
49
34
-
35
-
36
- return new HtmlResponse (
37
- new SupportLog ($ files , self ::get_supporters ()),
38
- 'support/log.php '
50
+ return new SupportLog (
51
+ array_map (
52
+ function ($ file ) {
53
+ return self ::getMonthReport ($ file );
54
+ },
55
+ $ files
56
+ ),
57
+ self ::get_supporters ()
39
58
);
40
59
}
41
60
42
- public static function get_report ( string $ file ) : string
61
+ private static function getMonthReport ( string $ file ) : SupportLogMonthReport
43
62
{
44
63
$ f = file ( 'reports/ ' . $ file );
45
64
$ summary = array_shift ($ f );
46
65
47
66
preg_match ( '/[0-9]{4}-[0-9]{2}/ ' , $ file , $ matches );
48
67
$ d = new \DateTimeImmutable ( "{$ matches [0 ]}-01 " );
49
68
50
- $ html = "<h2> " . $ d ->format ( "F Y " ) . "</h2> \n" ;
51
-
52
- // var_dump( $summary, $f );
53
-
54
- list ( $ patreon , $ basic , $ company , $ others ) = explode ( "\t" , trim ( $ summary ) );
69
+ list ($ patreon , $ basic , $ company , $ others ) = explode ("\t" , trim ($ summary ));
55
70
$ total = (int ) $ patreon + (int ) $ basic + (int ) $ company + (int ) $ others ;
56
71
57
- $ html .= "
58
- <div class='funding'>
59
- <div class='others' style='width: {$ others }%'></div>
60
- <div class='company' style='width: {$ company }%'></div>
61
- <div class='basic' style='width: {$ basic }%'></div>
62
- <div class='patreon' style='width: {$ patreon }%'></div>
63
- <div class='comment'>Time Funded</div>
64
- </div> " ;
65
-
66
72
$ totalHours = [];
67
- $ logTable = " <table class='log'> \n" ;
68
- $ logTable .= " <tr><th class='day'>Day</th><th class='type'>Type</th><th class='description'>Description</th><th class='hours'>Hours</th></tr> \n" ;
69
- foreach ( $ f as $ line )
70
- {
73
+
74
+ $ days = [] ;
75
+
76
+ foreach ( $ f as $ line ) {
71
77
$ line = trim ( $ line );
72
78
if ( $ line == '' ) {
73
79
continue ;
@@ -81,33 +87,28 @@ public static function get_report( string $file ) : string
81
87
$ type = 'generic ' ;
82
88
};
83
89
84
- $ logTable .= "<tr><td class='day'> {$ day }</td><td class='type'><div class='type- {$ type }'> {$ type }</div></td><td> {$ description }</td><td class='hours'> {$ hours }</td></tr> \n" ;
90
+ $ days [] = new SupportLogDayReport (
91
+ $ day ,
92
+ $ type ,
93
+ $ description ,
94
+ $ hours
95
+ );
85
96
86
97
$ totalHours [$ type ] += $ hours ;
87
- }
88
- $ logTable .= "</table> \n" ;
89
-
90
- krsort ( $ totalHours );
91
- $ spendBar = "<div class='spend'> \n" ;
92
- foreach ( $ totalHours as $ type => $ value )
93
- {
94
- $ spendBar .= "<div class='type- {$ type }' style='width: {$ value }%'></div> \n" ;
95
- }
96
- $ spendBar .= "<div class='comment'>Time Spent</div> \n" ;
97
- $ spendBar .= "</div> \n" ;
98
-
99
- $ html .= $ spendBar ;
100
- $ html .= $ logTable ;
101
-
102
- $ url = strtolower ( $ d ->format ( 'F-Y ' ) );
103
-
104
- $ from = $ d ->modify ( '+40 days ' );
105
- if (new \DateTimeImmutable () > $ from )
106
- {
107
- $ html .="<p>For additional information, please see the <a href='https://derickrethans.nl/xdebug-update- {$ url }.html'>monthly</a> report.</p> \n" ;
108
- }
109
-
110
- return $ html ;
98
+ };
99
+
100
+ krsort ($ totalHours );
101
+
102
+ return new SupportLogMonthReport (
103
+ $ d ,
104
+ $ others ,
105
+ $ company ,
106
+ $ basic ,
107
+ $ patreon ,
108
+ $ days ,
109
+ $ totalHours ,
110
+ new \DateTimeImmutable () > $ d ->modify ( '+40 days ' ) ? strtolower ($ d ->format ( 'F-Y ' )) : null
111
+ );
111
112
}
112
113
113
114
/**
0 commit comments