admin home stats
This commit is contained in:
102
core/lib/Thelia/Controller/Admin/HomeController.php
Normal file
102
core/lib/Thelia/Controller/Admin/HomeController.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* 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. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
use Thelia\Model\OrderQuery;
|
||||
|
||||
class HomeController extends BaseAdminController
|
||||
{
|
||||
const RESOURCE_CODE = "admin.home";
|
||||
|
||||
public function defaultAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(self::RESOURCE_CODE, AccessManager::VIEW)) return $response;
|
||||
|
||||
// Render the edition template.
|
||||
return $this->render('home');
|
||||
}
|
||||
|
||||
public function loadStatsAjaxAction()
|
||||
{
|
||||
$data = new \stdClass();
|
||||
|
||||
$data->title = "Stats on [...]";
|
||||
|
||||
/* sales */
|
||||
$saleSeries = new \stdClass();
|
||||
$saleSeries->color = $this->getRequest()->request->get('sales_color', '#adadad');
|
||||
$saleSeries->data = OrderQuery::getSaleStats(
|
||||
$this->getRequest()->request->get('month', date('m')),
|
||||
$this->getRequest()->request->get('year', date('Y'))
|
||||
);
|
||||
|
||||
/* new customers */
|
||||
$newCustomerSeries = new \stdClass();
|
||||
$newCustomerSeries->color = $this->getRequest()->request->get('customers_color', '#f39922');
|
||||
$newCustomerSeries->data = CustomerQuery::getNewCustomersStats(
|
||||
$this->getRequest()->request->get('month', date('m')),
|
||||
$this->getRequest()->request->get('year', date('Y'))
|
||||
);
|
||||
|
||||
/* orders */
|
||||
$orderSeries = new \stdClass();
|
||||
$orderSeries->color = $this->getRequest()->request->get('orders_color', '#5cb85c');
|
||||
$orderSeries->data = OrderQuery::getOrdersStats(
|
||||
$this->getRequest()->request->get('month', date('m')),
|
||||
$this->getRequest()->request->get('year', date('Y'))
|
||||
);
|
||||
|
||||
/* first order */
|
||||
$firstOrderSeries = new \stdClass();
|
||||
$firstOrderSeries->color = $this->getRequest()->request->get('first_orders_color', '#5bc0de');
|
||||
$firstOrderSeries->data = OrderQuery::getFirstOrdersStats(
|
||||
$this->getRequest()->request->get('month', date('m')),
|
||||
$this->getRequest()->request->get('year', date('Y'))
|
||||
);
|
||||
|
||||
/* cancelled orders */
|
||||
$cancelledOrderSeries = new \stdClass();
|
||||
$cancelledOrderSeries->color = $this->getRequest()->request->get('cancelled_orders_color', '#d9534f');
|
||||
$cancelledOrderSeries->data = OrderQuery::getOrdersStats(
|
||||
$this->getRequest()->request->get('month', date('m')),
|
||||
$this->getRequest()->request->get('year', date('Y')),
|
||||
array(5)
|
||||
);
|
||||
|
||||
|
||||
$data->series = array(
|
||||
$saleSeries,
|
||||
$newCustomerSeries,
|
||||
$orderSeries,
|
||||
$firstOrderSeries,
|
||||
$cancelledOrderSeries,
|
||||
);
|
||||
|
||||
$json = json_encode($data);
|
||||
|
||||
return $this->jsonResponse($json);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user