2
// This file is part of Moodle - http://moodle.org/
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.
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/>.
18
* Progress handler that uses a standard Moodle progress bar to display
19
* progress. The Moodle progress bar cannot show indeterminate progress,
20
* so we do extra output in addition to the bar.
22
* @package core_backup
23
* @copyright 2013 The Open University
24
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
class core_backup_display_progress extends core_backup_progress {
28
* @var int Number of wibble states (state0...stateN-1 classes in CSS)
30
const WIBBLE_STATES = 13;
33
* @var progress_bar Current progress bar.
37
private $lastwibble, $currentstate = 0, $direction = 1;
40
* @var bool True to display names
42
protected $displaynames = false;
45
* Constructs the progress reporter. This will output HTML code for the
46
* progress bar, and an indeterminate wibbler below it.
48
* @param bool $startnow If true, outputs HTML immediately.
50
public function __construct($startnow = true) {
57
* By default, the progress section names do not display because (in backup)
58
* these are usually untranslated and incomprehensible. To make them
59
* display, call this method.
61
* @param bool $displaynames True to display names
63
public function set_display_names($displaynames = true) {
64
$this->displaynames = $displaynames;
68
* Starts to output progress.
70
* Called in constructor and in update_progress if required.
72
* @throws coding_exception If already started
74
public function start_html() {
76
throw new coding_exception('Already started');
78
$this->bar = new progress_bar();
80
echo html_writer::start_div('wibbler');
84
* Finishes output. (Progress can begin again later if there are more
85
* calls to update_progress.)
87
* Automatically called from update_progress when progress finishes.
89
public function end_html() {
90
// Finish progress bar.
91
$this->bar->update_full(100, '');
95
echo html_writer::end_div();
99
* When progress is updated, updates the bar.
101
* @see core_backup_progress::update_progress()
103
public function update_progress() {
105
if (!$this->is_in_progress_section()) {
113
// In case of indeterminate or small progress, update the wibbler
114
// (up to once per second).
115
if (time() != $this->lastwibble) {
116
$this->lastwibble = time();
117
echo html_writer::div('', 'wibble state' . $this->currentstate);
119
// Go on to next colour.
120
$this->currentstate += $this->direction;
121
if ($this->currentstate < 0 || $this->currentstate >= self::WIBBLE_STATES) {
122
$this->direction = -$this->direction;
123
$this->currentstate += 2 * $this->direction;
128
list ($min, $max) = $this->get_progress_proportion_range();
130
// Update progress bar.
132
if ($this->displaynames) {
133
$message = $this->get_current_description();
135
$this->bar->update_full($min * 100, $message);