From 4eb2a097c50aeb5310d675a07a0663fc0c80a3f2 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Wed, 18 May 2011 00:50:26 +0200 Subject: [PATCH] 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. --- backup/util/ui/base_ui.class.php | 10 ++++------ backup/util/ui/base_ui_stage.class.php | 18 +++++++++++++++--- backup/util/ui/restore_ui.class.php | 6 ++++-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/backup/util/ui/base_ui.class.php b/backup/util/ui/base_ui.class.php index 7be6b0464fe..7daf0f00d42 100644 --- a/backup/util/ui/base_ui.class.php +++ b/backup/util/ui/base_ui.class.php @@ -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 @@ -306,4 +304,4 @@ abstract class base_ui { /** * Backup user interface exception. Modelled off the backup_exception class */ -class base_ui_exception extends backup_exception {} \ No newline at end of file +class base_ui_exception extends backup_exception {} diff --git a/backup/util/ui/base_ui_stage.class.php b/backup/util/ui/base_ui_stage.class.php index d56880bdac1..ef99dca7a2a 100644 --- a/backup/util/ui/base_ui_stage.class.php +++ b/backup/util/ui/base_ui_stage.class.php @@ -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. * @@ -144,4 +156,4 @@ abstract class base_ui_stage { public function is_first_stage() { return $this->stage == 1; } -} \ No newline at end of file +} diff --git a/backup/util/ui/restore_ui.class.php b/backup/util/ui/restore_ui.class.php index a4f726142cd..220cc232ec2 100644 --- a/backup/util/ui/restore_ui.class.php +++ b/backup/util/ui/restore_ui.class.php @@ -252,17 +252,19 @@ 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); } } /** * restore user interface exception. Modelled off the restore_exception class */ -class restore_ui_exception extends base_ui_exception {} \ No newline at end of file +class restore_ui_exception extends base_ui_exception {}