ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilBenchmarkTableGUI.php
Go to the documentation of this file.
1<?php
2
25{
26 protected string $mode;
28
29
33 public function __construct($a_parent_obj, $a_parent_cmd, $a_records, $a_mode = "chronological")
34 {
35 global $DIC;
36
37 $this->ctrl = $DIC->ctrl();
38 $this->lng = $DIC->language();
39 $this->access = $DIC->access();
40 $ilCtrl = $DIC->ctrl();
41 $lng = $DIC->language();
42 $ilAccess = $DIC->access();
43 $lng = $DIC->language();
44
45 parent::__construct($a_parent_obj, $a_parent_cmd);
46 $this->setLimit(9999);
47 $this->mode = $a_mode;
48
49 switch ($this->mode) {
50 case "slowest_first":
51 $this->setData(ilArrayUtil::sortArray($a_records, "time", "desc", true));
52 $this->setTitle($lng->txt("adm_db_bench_slowest_first"));
53 $this->addColumn($this->lng->txt("adm_time"));
54 $this->addColumn($this->lng->txt("adm_sql"));
55 break;
56
57 case "sorted_by_sql":
58 $this->setData(ilArrayUtil::sortArray($a_records, "sql", "asc"));
59 $this->setTitle($lng->txt("adm_db_bench_sorted_by_sql"));
60 $this->addColumn($this->lng->txt("adm_time"));
61 $this->addColumn($this->lng->txt("adm_sql"));
62 break;
63
64 case "by_first_table":
65 $this->setData($this->getDataByFirstTable($a_records));
66 $this->setTitle($lng->txt("adm_db_bench_by_first_table"));
67 $this->addColumn($this->lng->txt("adm_time"));
68 $this->addColumn($this->lng->txt("adm_nr_statements"));
69 $this->addColumn($this->lng->txt("adm_table"));
70 break;
71
72 default:
73 $this->setData($a_records);
74 $this->setTitle($lng->txt("adm_db_bench_chronological"));
75 $this->addColumn($this->lng->txt("adm_time"));
76 $this->addColumn($this->lng->txt("adm_sql"));
77 break;
78 }
79
80 $this->setEnableHeader(true);
81 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
82 $this->setRowTemplate("tpl.db_bench.html", "components/ILIAS/SystemFolder");
83 $this->disable("footer");
84 $this->setEnableTitle(true);
85
86 // $this->addMultiCommand("", $lng->txt(""));
87 // $this->addCommandButton("", $lng->txt(""));
88 }
89
96 public function getFirst($a_str, $a_needles)
97 {
98 $pos = 0;
99 foreach ($a_needles as $needle) {
100 $pos2 = strpos($a_str, $needle);
101
102 if ($pos2 > 0 && ($pos2 < $pos || $pos == 0)) {
103 $pos = $pos2;
104 }
105 }
106
107 return $pos;
108 }
109
116 public function extractFirstTableFromSQL($a_sql)
117 {
118 $pos1 = $this->getFirst(strtolower($a_sql), array("from ", "from\n", "from\t", "from\r"));
119
120 $table = "";
121 if ($pos1 > 0) {
122 $tablef = substr(strtolower($a_sql), $pos1 + 5);
123 $pos2 = $this->getFirst($tablef, array(" ", "\n", "\t", "\r"));
124 if ($pos2 > 0) {
125 $table = substr($tablef, 0, $pos2);
126 } else {
127 $table = $tablef;
128 }
129 }
130 if (trim($table) != "") {
131 return $table;
132 }
133
134 return "";
135 }
136
137
144 public function getDataByFirstTable($a_records)
145 {
146 $data = array();
147 foreach ($a_records as $r) {
148 $table = $this->extractFirstTableFromSQL($r["sql"]);
149 $data[$table]["table"] = $table;
150 $data[$table]["cnt"] = isset($data[$table]["cnt"]) ? $data[$table]["cnt"] + 1 : 1;
151 $data[$table]["time"] = isset($data[$table]["time"]) ? $data[$table]["time"] + $r["time"] : $r["time"];
152 }
153 if (count($data) > 0) {
154 $data = ilArrayUtil::sortArray($data, "time", "desc", true);
155 }
156
157 return $data;
158 }
159
163 protected function fillRow(array $a_set): void
164 {
166
167 switch ($this->mode) {
168 case "by_first_table":
169 $this->tpl->setCurrentBlock("td");
170 $this->tpl->setVariable("VAL", $a_set["table"]);
171 $this->tpl->parseCurrentBlock();
172 $this->tpl->setVariable("VAL1", $a_set["time"]);
173 $this->tpl->setVariable("VAL2", $a_set["cnt"]);
174 break;
175
176 case "slowest_first":
177 case "sorted_by_sql":
178 default:
179 $this->tpl->setVariable("VAL1", $a_set["time"]);
180 $this->tpl->setVariable("VAL2", $a_set["sql"]);
181 break;
182 }
183 }
184}
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct($a_parent_obj, $a_parent_cmd, $a_records, $a_mode="chronological")
Constructor.
extractFirstTableFromSQL($a_sql)
Extract first table from sql.
fillRow(array $a_set)
Fill table row.
getDataByFirstTable($a_records)
Get data by first table.
getFirst($a_str, $a_needles)
Get first occurence of string.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setLimit(int $a_limit=0, int $a_default_limit=0)
set max.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setEnableTitle(bool $a_enabletitle)
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setEnableHeader(bool $a_enableheader)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setData(array $a_data)
Set table data.
ilLanguage $lng
disable(string $a_module_name)
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26