|
| 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. |
| 13 | +// |
| 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/>. |
| 16 | + |
| 17 | +/** |
| 18 | + * Check env refresh age |
| 19 | + * |
| 20 | + * @package tool_task |
| 21 | + * @author 2021 Brendan Heywood ([email protected]) |
| 22 | + * @copyright Catalyst IT Pty Ltd |
| 23 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 24 | + */ |
| 25 | + |
| 26 | +namespace local_envbar\check; |
| 27 | + |
| 28 | +defined('MOODLE_INTERNAL') || die(); |
| 29 | + |
| 30 | +use core\check\check; |
| 31 | +use core\check\result; |
| 32 | +use local_envbar\local\envbarlib; |
| 33 | + |
| 34 | +/** |
| 35 | + * Check env refresh age |
| 36 | + * |
| 37 | + * @package tool_task |
| 38 | + * @author 2021 Brendan Heywood ([email protected]) |
| 39 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 40 | + */ |
| 41 | +class envage extends check { |
| 42 | + |
| 43 | + /** |
| 44 | + * Constructor |
| 45 | + */ |
| 46 | + public function __construct() { |
| 47 | + global $CFG; |
| 48 | + $this->id = 'envage'; |
| 49 | + $this->name = get_string('checkenvage', 'local_envbar'); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * A link to a place to action this |
| 54 | + * |
| 55 | + * @return action_link|null |
| 56 | + */ |
| 57 | + public function get_action_link(): ?\action_link { |
| 58 | + return new \action_link( |
| 59 | + new \moodle_url('/local/envbar/index.php'), |
| 60 | + get_string('menuenvsettings', 'local_envbar')); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Return result |
| 65 | + * @return result |
| 66 | + */ |
| 67 | + public function get_result() : result { |
| 68 | + global $CFG; |
| 69 | + |
| 70 | + if (envbarlib::getprodwwwroot() === $CFG->wwwroot) { |
| 71 | + return new result(result::NA, get_string('prodwwwroottext', 'local_envbar'), ''); |
| 72 | + } |
| 73 | + |
| 74 | + $lastrefresh = get_config('local_envbar', 'prodlastcheck'); |
| 75 | + |
| 76 | + if ($lastrefresh && $lastrefresh > 0) { |
| 77 | + $format = get_string('strftimedatemonthabbr', 'langconfig'); |
| 78 | + $summary = userdate($lastrefresh, get_string('strftimedaydate', 'langconfig')); |
| 79 | + |
| 80 | + $show = format_time(time() - $lastrefresh); |
| 81 | + $num = strtok($show, ' '); |
| 82 | + $unit = strtok(' '); |
| 83 | + $show = "$num $unit"; |
| 84 | + $summary .= ' - ' . get_string('refreshedago', 'local_envbar', $show); |
| 85 | + } else { |
| 86 | + $summary = get_string('refreshednever', 'local_envbar'); |
| 87 | + } |
| 88 | + |
| 89 | + return new result(result::INFO, $summary, ''); |
| 90 | + } |
| 91 | +} |
| 92 | + |
0 commit comments