Skip to content

Commit

Permalink
MDL-73831 adminpresets: Display current/new value for settings
Browse files Browse the repository at this point in the history
Before applying a preset, the settings are displayed and, in some cases,
the Current/New value columns were empty.
This patch fixes it and guarantees this information is updated properly
every time the set_value() method is called.
  • Loading branch information
sarjona committed Feb 22, 2022
1 parent e941671 commit 49aef9f
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class adminpresets_admin_setting_configcheckbox extends adminpresets_setting {

protected function set_value($value) {
$this->value = clean_param($value, PARAM_BOOL);
$this->set_visiblevalue();

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ public function __construct(admin_setting $settingdata, $dbsettingvalue) {
*/
protected function set_visiblevalue() {
parent::set_visiblevalue();
$value = $this->attributesvalues[$this->attributes['adv']];
$this->visiblevalue .= $this->delegation->extra_set_visiblevalue($value, 'advanced');

if (!is_null($this->attributesvalues) && array_key_exists($this->attributes['adv'], $this->attributesvalues)) {
$value = $this->attributesvalues[$this->attributes['adv']];
$this->visiblevalue .= $this->delegation->extra_set_visiblevalue($value, 'advanced');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public function __construct(admin_setting $settingdata, $dbsettingvalue) {
*/
protected function set_visiblevalue() {
parent::set_visiblevalue();
$value = $this->attributesvalues[$this->attributes['locked']];
$this->visiblevalue .= $this->delegation->extra_set_visiblevalue($value, 'locked');
if (!is_null($this->attributesvalues) && array_key_exists($this->attributes['locked'], $this->attributesvalues)) {
$value = $this->attributesvalues[$this->attributes['locked']];
$this->visiblevalue .= $this->delegation->extra_set_visiblevalue($value, 'locked');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ protected function set_value($value) {
// Check ip format.
if ($this->settingdata->validate($value) !== true) {
$this->value = false;
$this->set_visiblevalue();
return false;
}

$this->value = $value;
$this->set_visiblevalue();

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,18 @@ protected function set_value($value) {

if ($key == $option) {
$this->value = $option;
$this->set_visiblevalue();
return true;
}
}
}

$value = implode(',', $options);
}

$this->value = $value;
$this->set_visiblevalue();

return true;
}

protected function set_visiblevalue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ protected function set_value($value) {

if ($key == $value) {
$this->value = $value;
$this->set_visiblevalue();
return true;
}
}
}

$this->value = false;
$this->set_visiblevalue();
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protected function set_value($value) {
} else {
$this->value = clean_param($this->value, constant($paramtype));
}
$this->set_visiblevalue();

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public function __construct(admin_setting $settingdata, $dbsettingvalue) {
*/
protected function set_visiblevalue() {
parent::set_visiblevalue();
$value = $this->attributesvalues[$this->attributes['fix']];
$this->visiblevalue .= $this->delegation->extra_set_visiblevalue($value, 'advanced');
if (!is_null($this->attributesvalues) && array_key_exists($this->attributes['fix'], $this->attributesvalues)) {
$value = $this->attributesvalues[$this->attributes['fix']];
$this->visiblevalue .= $this->delegation->extra_set_visiblevalue($value, 'advanced');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ protected function set_value($value) {
}

$this->value = $value;
$this->set_visiblevalue();
}

protected function set_visiblevalue() {
$this->visiblevalue = $this->value . ':' . $this->attributesvalues[$this->settingdata->name2];
if (!is_null($this->attributesvalues) && array_key_exists($this->settingdata->name2, $this->attributesvalues)) {
$this->visiblevalue = $this->value . ':' . $this->attributesvalues[$this->settingdata->name2];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ public function __construct(admin_setting $settingdata, $dbsettingvalue) {
protected function set_visiblevalue() {
parent::set_visiblevalue();

$flagvalue = $this->attributesvalues[$this->settingdata->name . '_flag'];
if (!is_null($this->attributesvalues) && array_key_exists($this->settingdata->name . '_flag', $this->attributesvalues)) {
$flagvalue = $this->attributesvalues[$this->settingdata->name . '_flag'];

if (isset($flagvalue)) {
$forcedvalue = (($flagvalue % 2) == 1);
$advancedvalue = ($flagvalue >= 2);
if (isset($flagvalue)) {
$forcedvalue = (($flagvalue % 2) == 1);
$advancedvalue = ($flagvalue >= 2);

$this->visiblevalue .= $this->delegation->extra_set_visiblevalue($forcedvalue, 'forced');
$this->visiblevalue .= $this->delegation->extra_set_visiblevalue($advancedvalue, 'advanced');
$this->visiblevalue .= $this->delegation->extra_set_visiblevalue($forcedvalue, 'forced');
$this->visiblevalue .= $this->delegation->extra_set_visiblevalue($advancedvalue, 'advanced');
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class adminpresets_admin_setting_special_backupdays extends adminpresets_setting

protected function set_value($value) {
$this->value = clean_param($value, PARAM_SEQUENCE);
$this->set_visiblevalue();
}

protected function set_visiblevalue() {
Expand Down
6 changes: 6 additions & 0 deletions admin/presets/classes/local/setting/adminpresets_setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ protected function apply_behaviors() {
}
}

/**
* Gets the setting value.
*
* @return mixed The setting value
*/
public function get_value() {
return $this->value;
}
Expand All @@ -127,6 +132,7 @@ public function get_value() {
*/
protected function set_value($value) {
$this->value = $value;
$this->set_visiblevalue();
}

public function get_visiblevalue() {
Expand Down
6 changes: 6 additions & 0 deletions admin/tool/admin_presets/tests/behat/apply_presets.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Feature: I can apply presets
And I should see "Calculated multichoice" in the "Setting changes" "table"
And I should see "Calculated simple" in the "Setting changes" "table"
And I should see "Chat" in the "Setting changes" "table"
And "Chat" row "Current value" column of "Setting changes" table should contain "Enabled"
And "Chat" row "New value" column of "Setting changes" table should contain "Disabled"
And I should see "Cohort sync" in the "Setting changes" "table"
And I should see "Comments" in the "Setting changes" "table"
And I should see "Course completion status" in the "Setting changes" "table"
Expand All @@ -51,6 +53,8 @@ Feature: I can apply presets
And I should see "Drag and drop onto image" in the "Setting changes" "table"
And I should see "Embedded answers (Cloze)" in the "Setting changes" "table"
And I should see "Enable badges" in the "Setting changes" "table"
And "Enable badges" row "Current value" column of "Setting changes" table should contain "Yes"
And "Enable badges" row "New value" column of "Setting changes" table should contain "No"
And I should see "Enable blogs" in the "Setting changes" "table"
And I should see "Enable comments" in the "Setting changes" "table"
And I should see "Enable competencies" in the "core_competency" "table_row"
Expand All @@ -70,6 +74,8 @@ Feature: I can apply presets
And I should see "Login" in the "Setting changes" "table"
And I should see "Main menu" in the "Setting changes" "table"
And I should see "Maximum number of attachments" in the "Setting changes" "table"
And "Maximum number of attachments" row "Current value" column of "Setting changes" table should contain "9"
And "Maximum number of attachments" row "New value" column of "Setting changes" table should contain "3"
And I should see "Mentees" in the "Setting changes" "table"
And I should see "Network servers" in the "Setting changes" "table"
And I should see "Numerical" in the "Setting changes" "table"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ protected function set_value($value): bool {
} else {
$this->value = clean_param($this->value, constant($paramtype));
}
$this->set_visiblevalue();

return true;
}
Expand Down

0 comments on commit 49aef9f

Please sign in to comment.