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/sites.artinside.com.br/mainpro/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\Enrolment;
use Source\Models\Newsletter;
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),
            "enrolmentCount" => (new Enrolment())->find("status = 0")->count(),
            "newsletterCount" => (new Enrolment())->find("status = 5")->count(),
            "enrolment" => (new Enrolment())->find("status = 0 ")->order("created_at ASC")->order("id DESC")->fetch(true),
            "newsletter" => (new Enrolment())->find("status = 5 ")->order("created_at ASC")->order("id DESC")->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");
    }
}