Admin_LogController::showAction PHP Метод

showAction() публичный Метод

public showAction ( )
    public function showAction()
    {
        $offset = $this->getParam("start");
        $limit = $this->getParam("limit");
        $orderby = "ORDER BY id DESC";
        $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams());
        if ($sortingSettings['orderKey']) {
            $orderby = "ORDER BY " . $sortingSettings['orderKey'] . " " . $sortingSettings['order'];
        }
        $queryString = " WHERE 1=1";
        if ($this->getParam("priority") != "-1" && ($this->getParam("priority") == "0" || $this->getParam("priority"))) {
            $levels = [];
            foreach (["emergency", "alert", "critical", "error", "warning", "notice", "info", "debug"] as $level) {
                $levels[] = "priority = '" . $level . "'";
                if ($this->getParam("priority") == $level) {
                    break;
                }
            }
            $queryString .= " AND (" . implode(" OR ", $levels) . ")";
        }
        if ($this->getParam("fromDate")) {
            $datetime = $this->getParam("fromDate");
            if ($this->getParam("fromTime")) {
                $datetime = substr($datetime, 0, 11) . substr($this->getParam("fromTime"), strpos($this->getParam("fromTime"), 'T') + 1, strlen($this->getParam("fromTime")));
            }
            $queryString .= " AND timestamp >= '" . $datetime . "'";
        }
        if ($this->getParam("toDate")) {
            $datetime = $this->getParam("toDate");
            if ($this->getParam("toTime")) {
                $datetime = substr($datetime, 0, 11) . substr($this->getParam("toTime"), strpos($this->getParam("toTime"), 'T') + 1, strlen($this->getParam("toTime")));
            }
            $queryString .= " AND timestamp <= '" . $datetime . "'";
        }
        if ($this->getParam("component")) {
            $queryString .= " AND component =  '" . $this->getParam("component") . "'";
        }
        if ($this->getParam("relatedobject")) {
            $queryString .= " AND relatedobject = " . $this->getParam("relatedobject");
        }
        if ($this->getParam("message")) {
            $queryString .= " AND message like '%" . $this->getParam("message") . "%'";
        }
        $db = Db::get();
        $count = $db->fetchCol("SELECT count(*) FROM " . \Pimcore\Log\Handler\ApplicationLoggerDb::TABLE_NAME . $queryString);
        $total = $count[0];
        $result = $db->fetchAll("SELECT * FROM " . \Pimcore\Log\Handler\ApplicationLoggerDb::TABLE_NAME . $queryString . " {$orderby} LIMIT {$offset}, {$limit}");
        $errorDataList = [];
        if (!empty($result)) {
            foreach ($result as $r) {
                $parts = explode("/", $r['filelink']);
                $filename = $parts[count($parts) - 1];
                $fileobject = str_replace(PIMCORE_DOCUMENT_ROOT, "", $r['fileobject']);
                $errorData = ["id" => $r['id'], "pid" => $r['pid'], "message" => $r['message'], "timestamp" => $r['timestamp'], "priority" => $this->getPriorityName($r['priority']), "filename" => $filename, "fileobject" => $fileobject, "relatedobject" => $r['relatedobject'], "component" => $r['component'], "source" => $r['source']];
                $errorDataList[] = $errorData;
            }
        }
        $results = ["p_totalCount" => $total, "p_results" => $errorDataList];
        $this->_helper->json($results);
    }