MOON
Server: Apache
System: Linux server1.studioinfinity.com.br 2.6.32-954.3.5.lve1.4.90.el6.x86_64 #1 SMP Tue Feb 21 12:26:30 UTC 2023 x86_64
User: artinside (517)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //home/artinside/public_html/finance/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\Post;
use Source\Models\Report\Online;
use Source\Models\Service;
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,

            "posts" => (object)[
                "count" => (new Post())->find()->count()
            ],
            "users" => (object)[
                "users" => (new User())->find("level  = 5")->count()
            ],
            "orders" => (new Orders())->find()->order("created_at DESC")->limit(5)->fetch(true),
            "online" => (new Online())->findByActive(),
            "onlineCount" => (new Online())->findByActive(true),
            "chart"=>$report,
            "percentualUsers"=> ceil((1 - $report->usersTotalB / $report->usersTotal)*100),
            "orderGraph" => $orderGraph
        ]);
    }


    /**
     * @param array|null $data
     * @throws \Exception
     */
    public function homeEcommerce(?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");
    }
}