File: //home/artinside/www/sabbry/source/App/Admin/Dash.php
<?php
namespace Source\App\Admin;
use Source\Models\Auth;
use Source\Models\Category;
use Source\Models\Ecommerce\Orders;
use Source\Models\Ecommerce\Product;
use Source\Models\Report\Online;
use Source\Models\User;
/**
* Class Dash
* @package Source\App\Admin
*/
class Dash extends Admin
{
/**
* Dash constructor.
*/
public function __construct($router)
{
parent::__construct();
$this->view->addData("router", $router);
}
/**
*
*/
public function dash(): void
{
redirect("/admin/dash/home");
}
/**
* @param array|null $data
* @throws \Exception
*/
public function home(?array $data): void
{
//real time access
if (!empty($data["refresh"])) {
$list = null;
$items = (new Online())->findByActive();
if ($items) {
$list = $this->view->render("views/fragments/online-users", ["online" => $items]);
}
echo json_encode([
"count" => (new Online())->findByActive(true),
"list" => $list
]);
return;
}
$report = $this->reportAccess();
$orderGraph = $this->orderGraph(5);
$head = $this->seo->render(
CONF_SITE_NAME . " | Dashboard",
CONF_SITE_DESC,
url("/admin"),
theme("/assets/images/image.jpg", CONF_VIEW_ADMIN),
false
);
echo $this->view->render("widgets/dash/home", [
"app" => "dash",
"head" => $head,
"products" => (object)[
"count" => (new Product())->find("status = 'post'")->count(),
"categories" => (new Category())->find("type = 'product'")->count()
],
"users" => (object)[
"users" => (new User())->find("level = 1")->count()
],
"online" => (new Online())->findByActive(),
"onlineCount" => (new Online())->findByActive(true),
"ordersCount" => (new Orders())->find("status = 'paid' AND shipment_code = 'Aguardando Entrega'")->count(),
"orders" => (new Orders())->find("(status = 'paid' OR status = 'authorized' OR status = 'processing' OR status = 'waiting_payment') AND shipment_code = 'Aguardando Entrega'")->order("created_at ASC")->fetch(true),
"chart"=>$report,
"percentualUsers"=> ceil((1 - $report->usersTotalB / $report->usersTotal)*100),
"orderGraph" => $orderGraph
]);
}
/**
*
*/
public function logoff(): void
{
$this->message->success("VocĂȘ saiu com sucesso {$this->user->first_name}.")->flash();
Auth::logout();
redirect("/admin/login");
}
}