MDL-45274 mod_feedback: show heading on non-respondents page
[moodle.git] / report / performance / locallib.php
blob6ff7ea4fa282c9c9d269d54a1f6f6b2f0a3c5825
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * This file contains classes for report_performance
20 * @package report_performance
21 * @copyright 2013 Rajesh Taneja
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die;
27 /**
28 * Class defining issue result.
30 * @package report_performance
31 * @copyright 2013 Rajesh Taneja
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 class report_performance_issue {
35 /** @var string issue identifier */
36 public $issue;
37 /** @var string issue name */
38 public $name;
39 /** @var string shown as status */
40 public $statusstr;
41 /** @var string string defines issue status */
42 public $status;
43 /** @var string shown as comment */
44 public $comment;
45 /** @var string details aboout issue*/
46 public $details;
47 /** @var string link pointing to configuration */
48 public $configlink;
51 /**
52 * This contains functions to get list of issues and there results.
54 * @package report_performance
55 * @copyright 2013 Rajesh Taneja
56 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
58 class report_performance {
59 /**
60 * This is used when issue is ok and there is no impact on performance.
62 const REPORT_PERFORMANCE_OK = 'ok';
64 /**
65 * This is used to notify that issue might impact performance.
67 const REPORT_PERFORMANCE_WARNING = 'warning';
69 /**
70 * This is used to notify if issue is serious and will impact performance.
72 const REPORT_PERFORMANCE_SERIOUS = 'serious';
74 /**
75 * This is used to notify if issue is critical and will significantly impact performance.
77 const REPORT_PERFORMANCE_CRITICAL = 'critical';
79 /**
80 * Return list of performance check function list.
82 * @return array list of performance issues.
84 public function get_issue_list() {
85 return array(
86 'report_performance_check_themedesignermode',
87 'report_performance_check_cachejs',
88 'report_performance_check_debugmsg',
89 'report_performance_check_automatic_backup',
90 'report_performance_check_enablestats'
94 /**
95 * Returns document link for performance issue
97 * @param string $issue string describing issue
98 * @param string $name name of issue
99 * @return string issue link pointing to docs page.
101 public function doc_link($issue, $name) {
102 global $CFG, $OUTPUT;
104 if (empty($CFG->docroot)) {
105 return $name;
108 return $OUTPUT->doc_link('report/performance/'.$issue, $name);
112 * Helper function to add issue details to table.
114 * @param html_table $table table in which issue details should be added
115 * @param report_performance_issues $issueresult issue result to be added
116 * @param bool $detail true if issue if displayed in detail.
118 public function add_issue_to_table(&$table, $issueresult, $detailed = false) {
119 global $OUTPUT;
120 $statusarr = array(self::REPORT_PERFORMANCE_OK => 'statusok',
121 self::REPORT_PERFORMANCE_WARNING => 'statuswarning',
122 self::REPORT_PERFORMANCE_SERIOUS => 'statusserious',
123 self::REPORT_PERFORMANCE_CRITICAL => 'statuscritical');
125 $row = array();
126 if ($detailed) {
127 $row[0] = $this->doc_link($issueresult->issue, $issueresult->name);
128 } else {
129 $url = new moodle_url('/report/performance/index.php', array('issue' => $issueresult->issue));
130 $row[0] = html_writer::link($url, $issueresult->name);
132 $row[1] = html_writer::tag('span', $issueresult->statusstr, array('class' => $statusarr[$issueresult->status]));
133 $row[2] = $issueresult->comment;
134 if (!empty($issueresult->configlink)) {
135 $editicon = html_writer::empty_tag('img', array('alt' => $issueresult->issue, 'class' => 'icon',
136 'src' => $OUTPUT->pix_url('i/settings')));
137 $row[3] = $OUTPUT->action_link($issueresult->configlink, $editicon);
138 } else {
139 $row[3] = '';
142 $table->data[] = $row;
146 * Verifies if theme designer mode is enabled.
148 * @return report_performance_issue result of themedesigner issue.
150 public static function report_performance_check_themedesignermode() {
151 global $CFG;
152 $issueresult = new report_performance_issue();
153 $issueresult->issue = 'report_performance_check_themedesignermode';
154 $issueresult->name = get_string('themedesignermode', 'admin');
156 if (empty($CFG->themedesignermode)) {
157 $issueresult->statusstr = get_string('disabled', 'report_performance');
158 $issueresult->status = self::REPORT_PERFORMANCE_OK;
159 $issueresult->comment = get_string('check_themedesignermode_comment_disable', 'report_performance');
160 } else {
161 $issueresult->statusstr = get_string('enabled', 'report_performance');
162 $issueresult->status = self::REPORT_PERFORMANCE_CRITICAL;
163 $issueresult->comment = get_string('check_themedesignermode_comment_enable', 'report_performance');
166 $issueresult->details = get_string('check_themedesignermode_details', 'report_performance');
167 $issueresult->configlink = new moodle_url('/admin/search.php', array('query' => 'themedesignermode'));
168 return $issueresult;
172 * Checks if javascript is cached.
174 * @return report_performance_issue result of cachejs issue.
176 public static function report_performance_check_cachejs() {
177 global $CFG;
178 $issueresult = new report_performance_issue();
179 $issueresult->issue = 'report_performance_check_cachejs';
180 $issueresult->name = get_string('cachejs', 'admin');
182 if (empty($CFG->cachejs)) {
183 $issueresult->statusstr = get_string('disabled', 'report_performance');
184 $issueresult->status = self::REPORT_PERFORMANCE_CRITICAL;
185 $issueresult->comment = get_string('check_cachejs_comment_disable', 'report_performance');
186 } else {
187 $issueresult->statusstr = get_string('enabled', 'report_performance');
188 $issueresult->status = self::REPORT_PERFORMANCE_OK;
189 $issueresult->comment = get_string('check_cachejs_comment_enable', 'report_performance');
192 $issueresult->details = get_string('check_cachejs_details', 'report_performance');
193 $issueresult->configlink = new moodle_url('/admin/search.php', array('query' => 'cachejs'));
194 return $issueresult;
198 * Checks debug config.
200 * @return report_performance_issue result of debugmsg issue.
202 public static function report_performance_check_debugmsg() {
203 global $CFG;
204 $issueresult = new report_performance_issue();
205 $issueresult->issue = 'report_performance_check_debugmsg';
206 $issueresult->name = get_string('debug', 'admin');
207 $debugchoices = array(DEBUG_NONE => 'debugnone',
208 DEBUG_MINIMAL => 'debugminimal',
209 DEBUG_NORMAL => 'debugnormal',
210 DEBUG_ALL => 'debugall',
211 DEBUG_DEVELOPER => 'debugdeveloper');
213 $issueresult->statusstr = get_string($debugchoices[$CFG->debug], 'admin');
214 if (!$CFG->debugdeveloper) {
215 $issueresult->status = self::REPORT_PERFORMANCE_OK;
216 $issueresult->comment = get_string('check_debugmsg_comment_nodeveloper', 'report_performance');
217 } else {
218 $issueresult->status = self::REPORT_PERFORMANCE_WARNING;
219 $issueresult->comment = get_string('check_debugmsg_comment_developer', 'report_performance');
222 $issueresult->details = get_string('check_debugmsg_details', 'report_performance');
224 $issueresult->configlink = new moodle_url('/admin/settings.php', array('section' => 'debugging'));
225 return $issueresult;
229 * Checks automatic backup config.
231 * @return report_performance_issue result of automatic backup issue.
233 public static function report_performance_check_automatic_backup() {
234 global $CFG;
235 require_once($CFG->dirroot . '/backup/util/helper/backup_cron_helper.class.php');
237 $issueresult = new report_performance_issue();
238 $issueresult->issue = 'report_performance_check_automatic_backup';
239 $issueresult->name = get_string('check_backup', 'report_performance');
241 $automatedbackupsenabled = get_config('backup', 'backup_auto_active');
242 if ($automatedbackupsenabled == backup_cron_automated_helper::AUTO_BACKUP_ENABLED) {
243 $issueresult->statusstr = get_string('autoactiveenabled', 'backup');
244 $issueresult->status = self::REPORT_PERFORMANCE_WARNING;
245 $issueresult->comment = get_string('check_backup_comment_enable', 'report_performance');
246 } else {
247 if ($automatedbackupsenabled == backup_cron_automated_helper::AUTO_BACKUP_DISABLED) {
248 $issueresult->statusstr = get_string('autoactivedisabled', 'backup');
249 } else {
250 $issueresult->statusstr = get_string('autoactivemanual', 'backup');
252 $issueresult->status = self::REPORT_PERFORMANCE_OK;
253 $issueresult->comment = get_string('check_backup_comment_disable', 'report_performance');
256 $issueresult->details = get_string('check_backup_details', 'report_performance');
257 $issueresult->configlink = new moodle_url('/admin/search.php', array('query' => 'backup_auto_active'));
258 return $issueresult;
262 * Checks if stats are enabled.
264 public static function report_performance_check_enablestats() {
265 global $CFG;
266 $issueresult = new report_performance_issue();
267 $issueresult->issue = 'report_performance_check_enablestats';
268 $issueresult->name = get_string('enablestats', 'admin');
270 if (!empty($CFG->enablestats)) {
271 $issueresult->statusstr = get_string('enabled', 'report_performance');
272 $issueresult->status = self::REPORT_PERFORMANCE_WARNING;
273 $issueresult->comment = get_string('check_enablestats_comment_enable', 'report_performance');
274 } else {
275 $issueresult->statusstr = get_string('disabled', 'report_performance');
276 $issueresult->status = self::REPORT_PERFORMANCE_OK;
277 $issueresult->comment = get_string('check_enablestats_comment_disable', 'report_performance');
280 $issueresult->details = get_string('check_enablestats_details', 'report_performance');
281 $issueresult->configlink = new moodle_url('/admin/search.php', array('query' => 'enablestats'));
282 return $issueresult;