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! * Displays the UI for the backup!
* *
* Note: The UI makes use of mforms (ewww!) thus it will automatically print * @throws base_ui_exception
* out the result rather than returning a string of HTML like other parts of Moodle * @return string HTML code
*
* @return bool
*/ */
public function display() { public function display() {
if ($this->progress < self::PROGRESS_SAVED) { if ($this->progress < self::PROGRESS_SAVED) {
throw new base_ui_exception('backupsavebeforedisplay'); throw new base_ui_exception('backupsavebeforedisplay');
} }
$this->stage->display(); return $this->stage->display();
} }
/** /**
* Gets all backup tasks from the controller * 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 * Backup user interface exception. Modelled off the backup_exception class
*/ */
class base_ui_exception extends backup_exception {} class base_ui_exception extends backup_exception {}

View file

@ -108,17 +108,29 @@ abstract class base_ui_stage {
final public function get_uniqueid() { final public function get_uniqueid() {
return $this->ui->get_uniqueid(); return $this->ui->get_uniqueid();
} }
/** /**
* Displays the stage. * Displays the stage.
* *
* By default this involves instantiating the form for the stage and the calling * 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 * it to display.
* rather than return. *
* @return string HTML code to display
*/ */
public function display() { public function display() {
$form = $this->initialise_stage_form(); $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(); $form->display();
$output = ob_get_contents();
ob_end_clean();
return $output;
} }
/** /**
* Processes the stage. * Processes the stage.
* *
@ -144,4 +156,4 @@ abstract class base_ui_stage {
public function is_first_stage() { public function is_first_stage() {
return $this->stage == 1; return $this->stage == 1;
} }
} }

View file

@ -252,17 +252,19 @@ class restore_ui extends base_ui {
} }
/** /**
* Displays this stage * Displays this stage
*
* @param core_backup_renderer $renderer * @param core_backup_renderer $renderer
* @return string HTML code to echo
*/ */
public function display($renderer) { public function display($renderer) {
if ($this->progress < self::PROGRESS_SAVED) { if ($this->progress < self::PROGRESS_SAVED) {
throw new base_ui_exception('backupsavebeforedisplay'); 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 * restore user interface exception. Modelled off the restore_exception class
*/ */
class restore_ui_exception extends base_ui_exception {} class restore_ui_exception extends base_ui_exception {}