The display() method in backup/restore UI returns the HTML rather then echoing it

This implementation uses a hacky trick with the output buffer unless
someone finds a time to add support for returning the HTML from
quickforms.
This commit is contained in:
David Mudrak 2011-05-18 00:50:26 +02:00
parent 383f6f63c7
commit 4eb2a097c5
3 changed files with 23 additions and 11 deletions

View file

@ -140,16 +140,14 @@ abstract class base_ui {
/**
* Displays the UI for the backup!
*
* Note: The UI makes use of mforms (ewww!) thus it will automatically print
* out the result rather than returning a string of HTML like other parts of Moodle
*
* @return bool
* @throws base_ui_exception
* @return string HTML code
*/
public function display() {
if ($this->progress < self::PROGRESS_SAVED) {
throw new base_ui_exception('backupsavebeforedisplay');
}
$this->stage->display();
return $this->stage->display();
}
/**
* Gets all backup tasks from the controller

View file

@ -108,17 +108,29 @@ abstract class base_ui_stage {
final public function get_uniqueid() {
return $this->ui->get_uniqueid();
}
/**
* Displays the stage.
*
* By default this involves instantiating the form for the stage and the calling
* it to display. Remember this is a moodleform instance so it will print
* rather than return.
* it to display.
*
* @return string HTML code to display
*/
public function display() {
$form = $this->initialise_stage_form();
// a nasty hack follows to work around the sad fact that moodle quickforms
// do not allow to actually return the HTML content, just to echo it
flush();
ob_start();
$form->display();
$output = ob_get_contents();
ob_end_clean();
return $output;
}
/**
* Processes the stage.
*

View file

@ -252,13 +252,15 @@ class restore_ui extends base_ui {
}
/**
* Displays this stage
*
* @param core_backup_renderer $renderer
* @return string HTML code to echo
*/
public function display($renderer) {
if ($this->progress < self::PROGRESS_SAVED) {
throw new base_ui_exception('backupsavebeforedisplay');
}
$this->stage->display($renderer);
return $this->stage->display($renderer);
}
}