1 | <?php |
||
23 | class DashboardController extends Controller { |
||
24 | |||
25 | /** |
||
26 | * Module basic path |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $moduleBasicRoute = 'admin.dashboard'; |
||
31 | |||
32 | /** |
||
33 | * View basic path |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $moduleBasicTemplatePath = 'admin.modules.user'; |
||
38 | |||
39 | /** |
||
40 | * Google analytics data |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $gaData = []; |
||
45 | |||
46 | /** |
||
47 | * Constructor |
||
48 | */ |
||
49 | public function __construct() { |
||
50 | |||
51 | /** |
||
52 | * Global template variables |
||
53 | */ |
||
54 | View::share('moduleBasicRoute', $this->moduleBasicRoute); |
||
55 | View::share('moduleBasicTemplatePath', $this->moduleBasicTemplatePath); |
||
56 | |||
57 | /** |
||
58 | * Module name for blade |
||
59 | */ |
||
60 | $temp = explode('.', $this->moduleBasicRoute); |
||
61 | View::share('moduleNameBlade', $temp[0] . "_module_" . $temp[1]); |
||
62 | |||
63 | |||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Main Dashboard function |
||
68 | * |
||
69 | * @return Response |
||
70 | */ |
||
71 | public function index() { |
||
72 | |||
73 | /** |
||
74 | * Get Google Analytics values if enabled |
||
75 | */ |
||
76 | if (env('ANALYTICS_ENABLED') == 1) { |
||
77 | |||
78 | $ga = $this->getGAValues(); |
||
79 | } else { |
||
80 | |||
81 | $ga = []; |
||
82 | } |
||
83 | |||
84 | $statistics = [ |
||
85 | 'ga' => $ga |
||
86 | ]; |
||
87 | |||
88 | return view('admin.modules.dashboard.index', ['statistics' => $statistics]); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Get visitors or pageviews from Google API |
||
93 | * |
||
94 | * @param integer $days |
||
95 | * @param string $type |
||
96 | * @return integer |
||
97 | */ |
||
98 | public function gaGetVisitorsPageviews($days = 7, $type = 'visitors') { |
||
116 | |||
117 | /** |
||
118 | * Get percent difference between values |
||
119 | * |
||
120 | * @param integer $lastValue |
||
121 | * @param integer $thisValue |
||
122 | * @param integer $round |
||
123 | * @return integer |
||
124 | */ |
||
125 | public function getPercentDifference($lastValue, $thisValue, $round = 2) { |
||
137 | |||
138 | /** |
||
139 | * Get Google Analytics values |
||
140 | * |
||
141 | * @return object |
||
142 | */ |
||
143 | public function getGAValues() { |
||
215 | } |
||
216 |