backup MDL-22761 improvement to allow backup ui to maintain custom params across stages
This commit is contained in:
@@ -78,13 +78,18 @@ abstract class backup_moodleform extends moodleform {
|
||||
$mform = $this->_form;
|
||||
$stage = $mform->addElement('hidden', 'stage', $this->uistage->get_stage());
|
||||
$stage = $mform->addElement('hidden', 'backup', $this->uistage->get_backupid());
|
||||
$params = $this->uistage->get_params();
|
||||
if (is_array($params) && count($params) > 0) {
|
||||
foreach ($params as $name=>$value) {
|
||||
$stage = $mform->addElement('hidden', $name, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Definition applied after the data is organised.. why's it here? because I want
|
||||
* to add elements on the fly.
|
||||
*/
|
||||
function definition_after_data() {
|
||||
|
||||
$buttonarray=array();
|
||||
if ($this->uistage->get_stage() > backup_ui::STAGE_INITIAL) {
|
||||
$buttonarray[] = $this->_form->createElement('submit', 'previous', get_string('previousstage','backup'));
|
||||
|
||||
@@ -73,10 +73,10 @@ class backup_ui {
|
||||
* Yay for constructors
|
||||
* @param backup_controller $controller
|
||||
*/
|
||||
public function __construct(backup_controller $controller) {
|
||||
public function __construct(backup_controller $controller, array $params=null) {
|
||||
$this->controller = $controller;
|
||||
$this->progress = self::PROGRESS_INTIAL;
|
||||
$this->stage = $this->initialise_stage();
|
||||
$this->stage = $this->initialise_stage(null, $params);
|
||||
// Process UI event before to be safe
|
||||
$this->controller->process_ui_event();
|
||||
}
|
||||
@@ -87,22 +87,22 @@ class backup_ui {
|
||||
* @param int|null $stage The desired stage to intialise or null for the default
|
||||
* @return backup_ui_stage_initial|backup_ui_stage_schema|backup_ui_stage_confirmation|backup_ui_stage_final
|
||||
*/
|
||||
protected function initialise_stage($stage = null) {
|
||||
protected function initialise_stage($stage = null, array $params=null) {
|
||||
if ($stage == null) {
|
||||
$stage = optional_param('stage', self::STAGE_INITIAL, PARAM_INT);
|
||||
}
|
||||
switch ($stage) {
|
||||
case backup_ui::STAGE_INITIAL:
|
||||
$stage = new backup_ui_stage_initial($this);
|
||||
$stage = new backup_ui_stage_initial($this, $params);
|
||||
break;
|
||||
case backup_ui::STAGE_SCHEMA:
|
||||
$stage = new backup_ui_stage_schema($this);
|
||||
$stage = new backup_ui_stage_schema($this, $params);
|
||||
break;
|
||||
case backup_ui::STAGE_CONFIRMATION:
|
||||
$stage = new backup_ui_stage_confirmation($this);
|
||||
$stage = new backup_ui_stage_confirmation($this, $params);
|
||||
break;
|
||||
case backup_ui::STAGE_FINAL:
|
||||
$stage = new backup_ui_stage_final($this);
|
||||
$stage = new backup_ui_stage_final($this, $params);
|
||||
break;
|
||||
default:
|
||||
$stage = false;
|
||||
@@ -121,7 +121,7 @@ class backup_ui {
|
||||
$this->progress = self::PROGRESS_PROCESSED;
|
||||
|
||||
if (optional_param('previous', false, PARAM_BOOL) && $this->stage->get_stage() > self::STAGE_INITIAL) {
|
||||
$this->stage = $this->initialise_stage($this->stage->get_prev_stage());
|
||||
$this->stage = $this->initialise_stage($this->stage->get_prev_stage(), $this->stage->get_params());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ class backup_ui {
|
||||
$processoutcome = $this->stage->process();
|
||||
|
||||
if ($processoutcome !== false) {
|
||||
$this->stage = $this->initialise_stage($this->stage->get_next_stage());
|
||||
$this->stage = $this->initialise_stage($this->stage->get_next_stage(), $this->stage->get_params());
|
||||
}
|
||||
|
||||
// Process UI event after to check changes are valid
|
||||
@@ -214,7 +214,7 @@ class backup_ui {
|
||||
$this->progress = self::PROGRESS_EXECUTED;
|
||||
$this->controller->finish_ui();
|
||||
$this->controller->execute_plan();
|
||||
$this->stage = new backup_ui_stage_complete($this, $this->controller->get_results());
|
||||
$this->stage = new backup_ui_stage_complete($this, $this->stage->get_params(), $this->controller->get_results());
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -54,12 +54,24 @@ abstract class backup_ui_stage {
|
||||
* @var backup_moodleform
|
||||
*/
|
||||
protected $stageform = null;
|
||||
/**
|
||||
* Custom form params that will be added as hidden inputs
|
||||
*/
|
||||
protected $params = null;
|
||||
/**
|
||||
*
|
||||
* @param backup_ui $ui
|
||||
*/
|
||||
public function __construct(backup_ui $ui) {
|
||||
public function __construct(backup_ui $ui, array $params=null) {
|
||||
$this->ui = $ui;
|
||||
$this->params = $params;
|
||||
}
|
||||
/**
|
||||
* Returns the custom params for this stage
|
||||
* @return array|null
|
||||
*/
|
||||
final public function get_params() {
|
||||
return $this->params;
|
||||
}
|
||||
/**
|
||||
* The current stage
|
||||
@@ -140,9 +152,9 @@ class backup_ui_stage_initial extends backup_ui_stage {
|
||||
* Initial backup stage constructor
|
||||
* @param backup_ui $ui
|
||||
*/
|
||||
public function __construct(backup_ui $ui) {
|
||||
public function __construct(backup_ui $ui, array $params=null) {
|
||||
$this->stage = backup_ui::STAGE_INITIAL;
|
||||
parent::__construct($ui);
|
||||
parent::__construct($ui, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,9 +252,9 @@ class backup_ui_stage_schema extends backup_ui_stage {
|
||||
* Schema stage constructor
|
||||
* @param backup_moodleform $ui
|
||||
*/
|
||||
public function __construct(backup_ui $ui) {
|
||||
public function __construct(backup_ui $ui, array $params=null) {
|
||||
$this->stage = backup_ui::STAGE_SCHEMA;
|
||||
parent::__construct($ui);
|
||||
parent::__construct($ui, $params);
|
||||
}
|
||||
/**
|
||||
* Processes the schema stage
|
||||
@@ -348,9 +360,9 @@ class backup_ui_stage_confirmation extends backup_ui_stage {
|
||||
* Constructs the stage
|
||||
* @param backup_ui $ui
|
||||
*/
|
||||
public function __construct($ui) {
|
||||
public function __construct($ui, array $params=null) {
|
||||
$this->stage = backup_ui::STAGE_CONFIRMATION;
|
||||
parent::__construct($ui);
|
||||
parent::__construct($ui, $params);
|
||||
}
|
||||
/**
|
||||
* Processes the confirmation stage
|
||||
@@ -460,9 +472,9 @@ class backup_ui_stage_final extends backup_ui_stage {
|
||||
* Constructs the final stage
|
||||
* @param backup_ui $ui
|
||||
*/
|
||||
public function __construct(backup_ui $ui) {
|
||||
public function __construct(backup_ui $ui, array $params=null) {
|
||||
$this->stage = backup_ui::STAGE_FINAL;
|
||||
parent::__construct($ui);
|
||||
parent::__construct($ui, $params);
|
||||
}
|
||||
/**
|
||||
* Processes the final stage.
|
||||
@@ -504,11 +516,12 @@ class backup_ui_stage_complete extends backup_ui_stage_final {
|
||||
/**
|
||||
* Constructs the complete backup stage
|
||||
* @param backup_ui $ui
|
||||
* @param array|null $params
|
||||
* @param array $results
|
||||
*/
|
||||
public function __construct(backup_ui $ui, $results) {
|
||||
public function __construct(backup_ui $ui, array $params=null, array $results=null) {
|
||||
$this->results = $results;
|
||||
parent::__construct($ui);
|
||||
parent::__construct($ui, $params);
|
||||
$this->stage = backup_ui::STAGE_COMPLETE;
|
||||
}
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user