Parcourir la source

First Part of Statistic Graph implemented

tags/v0.2
Marcel Völkel il y a 7 ans
Parent
révision
53825c3cbb

+ 12
- 4
Application/Data/Statistics/sternenkindsaga.php Voir le fichier

@@ -2,6 +2,7 @@
2 2
 
3 3
 use SCF\Core\DI;
4 4
 use SCF\Core\Database;
5
+use SCF\Core\StatsGenerator;
5 6
 
6 7
 $acl = DI::getInstance()->get('acl');
7 8
 
@@ -25,23 +26,30 @@ if($acl->acl('see_SKS') == 1) {
25 26
     $db_slave->execute();
26 27
     $Download['all'] = $db_slave->rowCount();
27 28
 
29
+    $db_slave->query("SELECT COUNT(guid) AS visit_count, DAY(FROM_UNIXTIME(`timestamp`)) as visit_day, MONTH(FROM_UNIXTIME(`timestamp`)) as visit_month, YEAR(FROM_UNIXTIME(`timestamp`)) AS visit_year FROM sks_unique_dls GROUP BY visit_year DESC, visit_month DESC, visit_day DESC LIMIT 10");
30
+    $downloadsPerDay = $db_slave->fetchArray();
31
+
28 32
     $db_slave->query("SELECT * FROM `sks_unique_user` WHERE `timestamp` != 0");
29 33
     $db_slave->execute();
30 34
     $allVistors = $db_slave->rowCount();
31 35
 
32
-        $db_slave->query("SELECT COUNT(guid) AS visit_count, DAY(FROM_UNIXTIME(`timestamp`)) as visit_day, MONTH(FROM_UNIXTIME(`timestamp`)) as visit_month, YEAR(FROM_UNIXTIME(`timestamp`)) AS visit_year FROM sks_unique_user GROUP BY visit_year DESC, visit_month DESC, visit_day DESC LIMIT 10");
33
-        $bla = $db_slave->fetchArray();
36
+    $db_slave->query("SELECT COUNT(guid) AS visit_count, DAY(FROM_UNIXTIME(`timestamp`)) as visit_day, MONTH(FROM_UNIXTIME(`timestamp`)) as visit_month, YEAR(FROM_UNIXTIME(`timestamp`)) AS visit_year FROM sks_unique_user GROUP BY visit_year DESC, visit_month DESC, visit_day DESC LIMIT 10");
37
+    $visitorsPerDay = $db_slave->fetchArray();
34 38
 
35 39
 
40
+    $stats = new StatsGenerator($db_slave);
36 41
 
37 42
     $genTraffic = round((($Download['all']*555008)/1024)/1024,2);
38 43
 
39 44
 
40
-    $tpl->assign('downloadArray', $Download);
45
+    $tpl->assign('downloadArray', $downloadsPerDay);
46
+    $tpl->assign('visitorArray', $visitorsPerDay);
41 47
     $tpl->assign('allVisitors', $allVistors);
48
+    $tpl->assign('allDownloads', $Download['all']);
42 49
     $tpl->assign('traffic', $genTraffic);
50
+    $tpl->assign('stats', $stats);
43 51
 
44
-    $tpl->assign('vardump', $bla);
52
+    //$tpl->assign('vardump', $stats);
45 53
     $tpl->display('Data/specific/sternenkindsaga.tpl');
46 54
 }
47 55
 else {

+ 177
- 0
Application/scf/Core/StatsGenerator.php Voir le fichier

@@ -0,0 +1,177 @@
1
+<?php
2
+
3
+namespace SCF\Core;
4
+
5
+use SCF\Core\Database;
6
+
7
+class StatsGenerator {
8
+
9
+    /**
10
+     * @var \SCF\Core\Database
11
+     */
12
+    private $_db;
13
+
14
+    /**
15
+     * @var array
16
+     */
17
+    private $statValues = [];
18
+
19
+    /**
20
+     * @var array
21
+     */
22
+    private $dateLabels = [];
23
+
24
+    /**
25
+     * @var array
26
+     */
27
+    private $dateRows = [];
28
+
29
+    /**
30
+     * StatsGenerator constructor.
31
+     * @param \SCF\Core\Database $db
32
+     */
33
+    public function __construct(Database $db)
34
+    {
35
+        $this->_db = $db;
36
+
37
+        $this->readDatabaseToArray();
38
+        $this->setDateLabels(25,12,2014,10);
39
+        $this->setDateRows(25,12,2014,10);
40
+
41
+    }
42
+
43
+    /**
44
+     * @return array
45
+     */
46
+    private function readDatabaseToArray()
47
+    {
48
+        $this->_db->query("SELECT COUNT(guid) AS visit_count, DAY(FROM_UNIXTIME(`timestamp`)) as visit_day, MONTH(FROM_UNIXTIME(`timestamp`)) as visit_month, YEAR(FROM_UNIXTIME(`timestamp`)) AS visit_year FROM sks_unique_user GROUP BY visit_year DESC, visit_month DESC, visit_day DESC");
49
+        $visitorsPerDay = $this->_db->fetchArray();
50
+
51
+        foreach ($visitorsPerDay as $key => $value) {
52
+            $day = ($value['visit_day'] < 10 ? '0'.$value['visit_day'] : $value['visit_day']);
53
+            $month = ($value['visit_month'] < 10 ? '0'.$value['visit_month'] : $value['visit_month']);
54
+            $year = $value['visit_year'];
55
+            $this->statValues[$day.'.'.$month.'.'.$year] = (int) $value['visit_count'];
56
+        }
57
+
58
+
59
+       return $this->statValues;
60
+    }
61
+
62
+    /**
63
+     * @param string $day
64
+     * @param string $month
65
+     * @param string $year
66
+     * @param string $range
67
+     * @return array
68
+     */
69
+    private function generateLabels($day = "", $month="", $year="", $range="")
70
+    {
71
+        $genDates = [];
72
+        $dateValue = $day.'.'.$month.'.'.$year;
73
+
74
+        $genStart = new \DateTime($dateValue);
75
+        $interval = new \DateInterval('P1D');
76
+        if(is_numeric($range)) {
77
+            $range = ($range > 30 ? 30 : $range);
78
+            $genStart = $genStart->modify("-" . $range . " days");
79
+            $genEnd = clone $genStart;
80
+            $genEnd = $genEnd->modify("+" . ($range * 2) . " days");
81
+        } else {
82
+            $genEnd = clone $genStart;
83
+            $genEnd->add(new \DateInterval("P1M"));
84
+        }
85
+
86
+        $dateRange = new \DatePeriod($genStart,$interval,$genEnd);
87
+
88
+        foreach ($dateRange as $date) {
89
+            $genDates[] = $date->format("d.m.Y");
90
+        }
91
+
92
+        return $genDates;
93
+
94
+    }
95
+
96
+    /**
97
+     * @param string $day
98
+     * @param string $month
99
+     * @param string $year
100
+     * @param string $range
101
+     * @return array
102
+     */
103
+    private function generateRows($day = "", $month="", $year="", $range="")
104
+    {
105
+        $rowArray = $this->statValues;
106
+        $genRows = [];
107
+        $dateValue = $day.'.'.$month.'.'.$year;
108
+
109
+        $genStart = new \DateTime($dateValue);
110
+        $interval = new \DateInterval('P1D');
111
+        if(is_numeric($range)) {
112
+            $range = ($range > 30 ? 30 : $range);
113
+            $genStart = $genStart->modify("-" . $range . " days");
114
+            $genEnd = clone $genStart;
115
+            $genEnd = $genEnd->modify("+" . ($range * 2) . " days");
116
+        } else {
117
+            $genEnd = clone $genStart;
118
+            $genEnd->add(new \DateInterval("P1M"));
119
+        }
120
+
121
+        $dateRange = new \DatePeriod($genStart,$interval,$genEnd);
122
+
123
+        $genEnd = clone $genStart;
124
+        $genEnd->add(new \DateInterval("P1M"));
125
+
126
+        foreach ($dateRange as $date) {
127
+            $realDate = $date->format("d.m.Y");
128
+            if(array_key_exists($realDate, $rowArray))
129
+            {
130
+                $genRows[] = $rowArray[$realDate];
131
+            } else {
132
+                $genRows[] = 0;
133
+            }
134
+            //var_dump($rowArray);
135
+        }
136
+
137
+        return $genRows;
138
+    }
139
+
140
+    /**
141
+     * @param string $day
142
+     * @param string $month
143
+     * @param string $year
144
+     * @param string $range
145
+     */
146
+    public function setDateLabels($day = "", $month="", $year="", $range="")
147
+    {
148
+        $this->dateLabels = $this->generateLabels($day,$month,$year,$range);
149
+    }
150
+
151
+    /**
152
+     * @return array
153
+     */
154
+    public function getDateLabels()
155
+    {
156
+        return json_encode($this->dateLabels);
157
+    }
158
+
159
+    /**
160
+     * @param string $day
161
+     * @param string $month
162
+     * @param string $year
163
+     * @param string $range
164
+     */
165
+    public function setDateRows($day = "", $month="", $year="", $range="")
166
+    {
167
+        $this->dateRows = $this->generateRows($day,$month,$year,$range);
168
+    }
169
+
170
+    /**
171
+     * @return array
172
+     */
173
+    public function getDateRows()
174
+    {
175
+        return json_encode($this->dateRows);
176
+    }
177
+}

+ 123
- 2
Application/templates/SmartAdmin/Data/specific/sternenkindsaga.tpl Voir le fichier

@@ -1,11 +1,132 @@
1 1
 {extends "Data/statistics.tpl"}
2 2
 {block name="minifiedStats"}
3 3
     <li class="sparks-info">
4
-        <h5> Site Traffic <span class="txt-color-purple"><i class="fa fa-arrow-circle-up"></i>&nbsp;45%</span></h5>
4
+        <h5> Downloads <span class="txt-color-purple"><i class="fa fa-download"></i>&nbsp;{$allDownloads}</span></h5>
5 5
         <div class="sparkline txt-color-purple hidden-mobile hidden-md hidden-sm">
6 6
             {foreach item=dl from=$downloadArray name=downloads}
7
-                {$dl}{if $smarty.foreach.downloads.last}{else},{/if}
7
+                {$dl.visit_count}{if $smarty.foreach.downloads.last}{else},{/if}
8 8
             {/foreach}
9 9
         </div>
10 10
     </li>
11
+    <li class="sparks-info">
12
+        <h5> Besucher <span class="txt-color-green"><i class="fa fa-users"></i>&nbsp;{$allVisitors}</span></h5>
13
+        <div class="sparkline txt-color-green hidden-mobile hidden-md hidden-sm">
14
+            {foreach item=visit from=$visitorArray name=visitors}
15
+                {$visit.visit_count}{if $smarty.foreach.visitors.last}{else},{/if}
16
+            {/foreach}
17
+        </div>
18
+    </li>
19
+{/block}
20
+{block name="body"}
21
+
22
+
23
+
24
+    <!-- widget grid -->
25
+    <section id="widget-grid" class="">
26
+
27
+        <!-- row -->
28
+        <div class="row">
29
+            <div class="container">
30
+                <article class="col-sm-12">
31
+                    <!-- new widget -->
32
+                    <div class="jarviswidget jarviswidget-color-blueLight" id="wid-id-0" data-widget-togglebutton="false" data-widget-editbutton="false" data-widget-fullscreenbutton="false" data-widget-colorbutton="false" data-widget-deletebutton="false">
33
+                        <!-- widget options:
34
+                        usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">
35
+
36
+                        data-widget-colorbutton="false"
37
+                        data-widget-editbutton="false"
38
+                        data-widget-togglebutton="false"
39
+                        data-widget-deletebutton="false"
40
+                        data-widget-fullscreenbutton="false"
41
+                        data-widget-custombutton="false"
42
+                        data-widget-collapsed="true"
43
+                        data-widget-sortable="false"
44
+
45
+                        -->
46
+                        <header>
47
+                            <span class="widget-icon"> <i class="fa fa-info-circle txt-color-darken"></i> </span>
48
+                            <h2>Statistik</h2>
49
+                        </header>
50
+
51
+                        <div class="no-padding">
52
+
53
+                            <div class="widget-body">
54
+                                <canvas id="lineChart" style="height:250px"></canvas>
55
+
56
+                            </div>
57
+                        </div>
58
+                    </div>
59
+                </article>
60
+            </div>
61
+        </div>
62
+    </section>
63
+{/block}
64
+{block name="additionalJSFiles"}
65
+    <script src="lib/SmartAdmin/js/plugin/chartjs/chart.min.js"></script>
66
+{/block}
67
+{block name="additionalJSCode"}
68
+
69
+var areaChartData = {
70
+    type: "line",
71
+labels: {$stats->getDateLabels()},
72
+datasets: [
73
+{
74
+label: "Users Per Day",
75
+fillColor: "rgba(60,141,188,0.9)",
76
+strokeColor: "rgba(60,141,188,0.8)",
77
+pointColor: "#3b8bba",
78
+pointStrokeColor: "rgba(60,141,188,1)",
79
+pointHighlightFill: "#fff",
80
+pointHighlightStroke: "rgba(60,141,188,1)",
81
+data: {$stats->getDateRows()}
82
+}
83
+]
84
+};
85
+
86
+
87
+var areaChartOptions = {
88
+//Boolean - If we should show the scale at all
89
+showScale: true,
90
+//Boolean - Whether grid lines are shown across the chart
91
+scaleShowGridLines: false,
92
+//String - Colour of the grid lines
93
+scaleGridLineColor: "rgba(0,0,0,.05)",
94
+//Number - Width of the grid lines
95
+scaleGridLineWidth: 1,
96
+//Boolean - Whether to show horizontal lines (except X axis)
97
+scaleShowHorizontalLines: true,
98
+//Boolean - Whether to show vertical lines (except Y axis)
99
+scaleShowVerticalLines: true,
100
+//Boolean - Whether the line is curved between points
101
+bezierCurve: true,
102
+//Number - Tension of the bezier curve between points
103
+bezierCurveTension: 0.3,
104
+//Boolean - Whether to show a dot for each point
105
+pointDot: true,
106
+//Number - Radius of each point dot in pixels
107
+pointDotRadius: 2.5,
108
+//Number - Pixel width of point dot stroke
109
+pointDotStrokeWidth: 1,
110
+//Number - amount extra to add to the radius to cater for hit detection outside the drawn point
111
+pointHitDetectionRadius: 2,
112
+//Boolean - Whether to show a stroke for datasets
113
+datasetStroke: true,
114
+//Number - Pixel width of dataset stroke
115
+datasetStrokeWidth: 2,
116
+//Boolean - Whether to fill the dataset with a color
117
+datasetFill: true,
118
+//String - A legend template
119
+{literal}
120
+legendTemplate: "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].lineColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>",
121
+//Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container
122
+maintainAspectRatio: true,
123
+//Boolean - whether to make the chart responsive to window resizing
124
+responsive: true
125
+};
126
+var lineChartCanvas = $("#lineChart").get(0).getContext("2d");
127
+var lineChart = new Chart(lineChartCanvas);
128
+var lineChartOptions = areaChartOptions;
129
+lineChartOptions.datasetFill = false;
130
+lineChart.Line(areaChartData, lineChartOptions);{/literal}
131
+
11 132
 {/block}

+ 1
- 1
Application/templates/SmartAdmin/Data/statistics.tpl Voir le fichier

@@ -1,4 +1,4 @@
1 1
 {include file="header.tpl"}
2 2
 {block name="body"}{/block}
3
-{$vardump|var_dump}
3
+<!--{$vardump|var_dump}-->
4 4
 {include file="footer.tpl"}

+ 5
- 69
Application/templates/SmartAdmin/meta/htmlFooter.tpl Voir le fichier

@@ -22,9 +22,6 @@
22 22
 <!-- JARVIS WIDGETS -->
23 23
 <script src="lib/SmartAdmin/js/smartwidgets/jarvis.widget.min.js"></script>
24 24
 
25
-<!-- EASY PIE CHARTS -->
26
-<script src="lib/SmartAdmin/js/plugin/easy-pie-chart/jquery.easy-pie-chart.min.js"></script>
27
-
28 25
 <!-- SPARKLINES -->
29 26
 <script src="lib/SmartAdmin/js/plugin/sparkline/jquery.sparkline.min.js"></script>
30 27
 
@@ -45,6 +42,7 @@
45 42
 
46 43
 <!-- FastClick: For mobile devices -->
47 44
 <script src="lib/SmartAdmin/js/plugin/fastclick/fastclick.min.js"></script>
45
+{block name="additionalJSFiles"}{/block}
48 46
 
49 47
 <!--[if IE 8]>
50 48
 
@@ -63,22 +61,11 @@
63 61
 <script src="lib/SmartAdmin/js/smart-chat-ui/smart.chat.ui.min.js"></script>
64 62
 <script src="lib/SmartAdmin/js/smart-chat-ui/smart.chat.manager.min.js"></script>
65 63
 
66
-<!-- PAGE RELATED PLUGIN(S) -->
67
-
68
-<!-- Flot Chart Plugin: Flot Engine, Flot Resizer, Flot Tooltip -->
69
-<script src="lib/SmartAdmin/js/plugin/flot/jquery.flot.cust.min.js"></script>
70
-<script src="lib/SmartAdmin/js/plugin/flot/jquery.flot.resize.min.js"></script>
71
-<script src="lib/SmartAdmin/js/plugin/flot/jquery.flot.time.min.js"></script>
72
-<script src="lib/SmartAdmin/js/plugin/flot/jquery.flot.tooltip.min.js"></script>
73
-
74
-<!-- Vector Maps Plugin: Vectormap engine, Vectormap language -->
75
-<script src="lib/SmartAdmin/js/plugin/vectormap/jquery-jvectormap-1.2.2.min.js"></script>
76
-<script src="lib/SmartAdmin/js/plugin/vectormap/jquery-jvectormap-world-mill-en.js"></script>
77 64
 
78 65
 <!-- Full Calendar -->
79 66
 <script src="lib/SmartAdmin/js/plugin/moment/moment.min.js"></script>
80 67
 <script src="lib/SmartAdmin/js/plugin/fullcalendar/jquery.fullcalendar.min.js"></script>
81
-
68
+{block name="additionalJSFiles"}{/block}
82 69
 <script>
83 70
     {literal}
84 71
     $(document).ready(function() {
@@ -180,60 +167,9 @@
180 167
         $('#td').click(function() {
181 168
             $('#calendar').fullCalendar('changeView', 'agendaDay');
182 169
         });
183
-
184
-        /*
185
-         * CHAT
186
-         */
187
-
188
-        $.filter_input = $('#filter-chat-list');
189
-        $.chat_users_container = $('#chat-container > .chat-list-body')
190
-        $.chat_users = $('#chat-users')
191
-        $.chat_list_btn = $('#chat-container > .chat-list-open-close');
192
-        $.chat_body = $('#chat-body');
193
-
194
-        /*
195
-        * LIST FILTER (CHAT)
196
-        */
197
-
198
-        // custom css expression for a case-insensitive contains()
199
-        jQuery.expr[':'].Contains = function(a, i, m) {
200
-            return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
201
-        };
202
-
203
-        function listFilter(list) {// header is any element, list is an unordered list
204
-            // create and add the filter form to the header
205
-
206
-            $.filter_input.change(function() {
207
-                var filter = $(this).val();
208
-                if (filter) {
209
-                    // this finds all links in a list that contain the input,
210
-                    // and hide the ones not containing the input while showing the ones that do
211
-                    $.chat_users.find("a:not(:Contains(" + filter + "))").parent().slideUp();
212
-                    $.chat_users.find("a:Contains(" + filter + ")").parent().slideDown();
213
-                } else {
214
-                    $.chat_users.find("li").slideDown();
215
-                }
216
-                return false;
217
-            }).keyup(function() {
218
-                // fire the above change event after every letter
219
-                $(this).change();
220
-
221
-            });
222
-
223
-        }
224
-
225
-        // on dom ready
226
-        listFilter($.chat_users);
227
-
228
-        // open chat list
229
-        $.chat_list_btn.click(function() {
230
-            $(this).parent('#chat-container').toggleClass('open');
231
-        })
232
-
233
-        $.chat_body.animate({
234
-            scrollTop : $.chat_body[0].scrollHeight
235
-        }, 500);
236
-
170
+        {/literal}
171
+        {block name="additionalJSCode"}{/block}
172
+        {literal}
237 173
     });
238 174
     {/literal}
239 175
 </script>

+ 1
- 1
Application/templates/SmartAdmin/misc/contentHeader.tpl Voir le fichier

@@ -1,6 +1,6 @@
1 1
 <div class="row">
2 2
     <div class="col-xs-12 col-sm-7 col-md-7 col-lg-4">
3
-        <h1 class="page-title txt-color-blueDark"><i class="fa-fw fa fa-home"></i> {$pageHeader.pageTitle} {if $paheHeader.subTitle}<span>> {$pageHeader.subTitle}</span>{/if}</h1>
3
+        <h1 class="page-title txt-color-blueDark"><i class="fa-fw fa fa-home"></i> {$pageHeader.pageTitle} {if $pageHeader.subTitle}<span>> {$pageHeader.subTitle}</span>{/if}</h1>
4 4
     </div>
5 5
     <div class="col-xs-12 col-sm-5 col-md-5 col-lg-8">
6 6
 

Chargement…
Annuler
Enregistrer