Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

Stats method for loading dashboard sales and users stats

givanzd00662d38160
diff --git a/admin/controller/index.php b/admin/controller/index.php
index c6a2801..c9c0e82 100755
--- a/admin/controller/index.php
+++ b/admin/controller/index.php
@@ -22,10 +22,67 @@
namespace Vvveb\Controller;
+use Vvveb\Sql\StatSQL;
+
class Index extends Base {
function index() {
}
+ function stats() {
+ $options = [];
+ $stats = new StatSQL();
+
+ if (isset($this->request->get['end_date'])) {
+ $options['end_date'] = $this->request->get['end_date'];
+ } else {
+ $options['end_date'] = date('Y-m-d');
+ }
+
+ if (isset($this->request->get['start_date'])) {
+ $options['start_date'] = $this->request->get['start_date'];
+ } else {
+ $options['start_date'] = date('Y-m-d');
+ }
+
+ $users = filter_var(($this->request->get['users'] ?? 'false'), FILTER_VALIDATE_BOOLEAN);
+ $orders = filter_var(($this->request->get['sales'] ?? 'false'), FILTER_VALIDATE_BOOLEAN);
+
+ $results = $stats->getStats($options + $this->global);
+ $data = [];
+
+ foreach ($results['orders'] as $order) {
+ $data[$order['date']]['orders'] = $order['orders'];
+ }
+
+ foreach ($results['users'] as $order) {
+ $data[$order['date']]['users'] = $order['users'];
+ }
+
+ ksort($data);
+ $labels = array_keys($data);
+
+ $usersData = [];
+ $ordersData = [];
+
+ foreach ($data as $date => $stat) {
+ $usersData[] = $stat['users'] ?? 0;
+ $ordersData[] = $stat['orders'] ?? 0;
+ }
+
+ $output = ['labels' => $labels];
+
+ if ($users) {
+ $output['users'] = $usersData;
+ }
+
+ if ($orders) {
+ $output['orders'] = $ordersData;
+ }
+
+ $this->response->setType('json');
+ $this->response->output($output);
+ }
+
function heartbeat() {
die('ok');
}