ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilBenchmarkTableGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/Table/classes/class.ilTable2GUI.php");
5
15{
19 protected $access;
20
21
25 public function __construct($a_parent_obj, $a_parent_cmd, $a_records, $a_mode = "chronological")
26 {
27 global $DIC;
28
29 $this->ctrl = $DIC->ctrl();
30 $this->lng = $DIC->language();
31 $this->access = $DIC->access();
32 $ilCtrl = $DIC->ctrl();
33 $lng = $DIC->language();
34 $ilAccess = $DIC->access();
35 $lng = $DIC->language();
36
37 parent::__construct($a_parent_obj, $a_parent_cmd);
38 $this->setLimit(9999);
39 $this->mode = $a_mode;
40
41 switch ($this->mode) {
42 case "slowest_first":
43 $this->setData(ilUtil::sortArray($a_records, "time", "desc", true));
44 $this->setTitle($lng->txt("adm_db_bench_slowest_first"));
45 $this->addColumn($this->lng->txt("adm_time"));
46 $this->addColumn($this->lng->txt("adm_sql"));
47 break;
48
49 case "sorted_by_sql":
50 $this->setData(ilUtil::sortArray($a_records, "sql", "asc"));
51 $this->setTitle($lng->txt("adm_db_bench_sorted_by_sql"));
52 $this->addColumn($this->lng->txt("adm_time"));
53 $this->addColumn($this->lng->txt("adm_sql"));
54 break;
55
56 case "by_first_table":
57 $this->setData($this->getDataByFirstTable($a_records));
58 $this->setTitle($lng->txt("adm_db_bench_by_first_table"));
59 $this->addColumn($this->lng->txt("adm_time"));
60 $this->addColumn($this->lng->txt("adm_nr_statements"));
61 $this->addColumn($this->lng->txt("adm_table"));
62 break;
63
64 default:
65 $this->setData($a_records);
66 $this->setTitle($lng->txt("adm_db_bench_chronological"));
67 $this->addColumn($this->lng->txt("adm_time"));
68 $this->addColumn($this->lng->txt("adm_sql"));
69 break;
70
71 }
72
73 $this->setEnableHeader(true);
74 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
75 $this->setRowTemplate("tpl.db_bench.html", "Modules/SystemFolder");
76 $this->disable("footer");
77 $this->setEnableTitle(true);
78
79 // $this->addMultiCommand("", $lng->txt(""));
80// $this->addCommandButton("", $lng->txt(""));
81 }
82
89 public function getFirst($a_str, $a_needles)
90 {
91 $pos = 0;
92 foreach ($a_needles as $needle) {
93 $pos2 = strpos($a_str, $needle);
94
95 if ($pos2 > 0 && ($pos2 < $pos || $pos == 0)) {
96 $pos = $pos2;
97 }
98 }
99
100 return $pos;
101 }
102
109 public function extractFirstTableFromSQL($a_sql)
110 {
111 $pos1 = $this->getFirst(strtolower($a_sql), array("from ", "from\n", "from\t", "from\r"));
112
113 $table = "";
114 if ($pos1 > 0) {
115 $tablef = substr(strtolower($a_sql), $pos1 + 5);
116 $pos2 = $this->getFirst($tablef, array(" ", "\n", "\t", "\r"));
117 if ($pos2 > 0) {
118 $table = substr($tablef, 0, $pos2);
119 } else {
120 $table = $tablef;
121 }
122 }
123 if (trim($table) != "") {
124 return $table;
125 }
126
127 return "";
128 }
129
130
137 public function getDataByFirstTable($a_records)
138 {
139 $data = array();
140 foreach ($a_records as $r) {
141 $table = $this->extractFirstTableFromSQL($r["sql"]);
142 $data[$table]["table"] = $table;
143 $data[$table]["cnt"]++;
144 $data[$table]["time"] += $r["time"];
145 }
146 if (count($data) > 0) {
147 $data = ilUtil::sortArray($data, "time", "desc", true);
148 }
149
150 return $data;
151 }
152
156 protected function fillRow($a_set)
157 {
159
160 switch ($this->mode) {
161 case "by_first_table":
162 $this->tpl->setCurrentBlock("td");
163 $this->tpl->setVariable("VAL", $a_set["table"]);
164 $this->tpl->parseCurrentBlock();
165 $this->tpl->setVariable("VAL1", $a_set["time"]);
166 $this->tpl->setVariable("VAL2", $a_set["cnt"]);
167 break;
168
169 case "slowest_first":
170 case "sorted_by_sql":
171 default:
172 $this->tpl->setVariable("VAL1", $a_set["time"]);
173 $this->tpl->setVariable("VAL2", $a_set["sql"]);
174 break;
175 }
176 }
177}
An exception for terminatinating execution or to throw for unit testing.
__construct($a_parent_obj, $a_parent_cmd, $a_records, $a_mode="chronological")
Constructor.
extractFirstTableFromSQL($a_sql)
Extract first table from sql.
getDataByFirstTable($a_records)
Get data by first table.
getFirst($a_str, $a_needles)
Get first occurence of string.
fillRow($a_set)
Fill table row.
Class ilTable2GUI.
setEnableHeader($a_enableheader)
Set Enable Header.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
setData($a_data)
set table data @access public
setEnableTitle($a_enabletitle)
Set Enable Title.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
setLimit($a_limit=0, $a_default_limit=0)
set max.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
disable($a_module_name)
diesables particular modules of table
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
$r
Definition: example_031.php:79
global $ilCtrl
Definition: ilias.php:18
if(empty($password)) $table
Definition: pwgen.php:24
global $DIC
Definition: saml.php:7