forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-60851 backup: coding style fixes
- Loading branch information
Damyon Wiese
committed
May 1, 2019
1 parent
a1bda6b
commit 1721176
Showing
2 changed files
with
81 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
<?php | ||
|
||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
|
@@ -82,7 +81,7 @@ public function __construct(base_setting $setting, base_setting $dependentsettin | |
* Destroy all circular references. It helps PHP 5.2 a lot! | ||
*/ | ||
public function destroy() { | ||
// No need to destroy anything recursively here, direct reset | ||
// No need to destroy anything recursively here, direct reset. | ||
$this->setting = null; | ||
$this->dependentsetting = null; | ||
} | ||
|
@@ -94,16 +93,19 @@ public function destroy() { | |
* @return bool | ||
*/ | ||
final public function process_change($changetype, $oldvalue) { | ||
// Check the type of change requested | ||
// Check the type of change requested. | ||
switch ($changetype) { | ||
// Process a status change | ||
case base_setting::CHANGED_STATUS: return $this->process_status_change($oldvalue); | ||
// Process a visibility change | ||
case base_setting::CHANGED_VISIBILITY: return $this->process_visibility_change($oldvalue); | ||
// Process a value change | ||
case base_setting::CHANGED_VALUE: return $this->process_value_change($oldvalue); | ||
// Process a status change. | ||
case base_setting::CHANGED_STATUS: | ||
return $this->process_status_change($oldvalue); | ||
// Process a visibility change. | ||
case base_setting::CHANGED_VISIBILITY: | ||
return $this->process_visibility_change($oldvalue); | ||
// Process a value change. | ||
case base_setting::CHANGED_VALUE: | ||
return $this->process_value_change($oldvalue); | ||
} | ||
// Throw an exception if we get this far | ||
// Throw an exception if we get this far. | ||
throw new backup_ui_exception('unknownchangetype'); | ||
} | ||
/** | ||
|
@@ -112,11 +114,11 @@ final public function process_change($changetype, $oldvalue) { | |
* @return bool | ||
*/ | ||
protected function process_visibility_change($oldvisibility) { | ||
// Store the current dependent settings visibility for comparison | ||
// Store the current dependent settings visibility for comparison. | ||
$prevalue = $this->dependentsetting->get_visibility(); | ||
// Set it regardless of whether we need to | ||
// Set it regardless of whether we need to. | ||
$this->dependentsetting->set_visibility($this->setting->get_visibility()); | ||
// Return true if it changed | ||
// Return true if it changed. | ||
return ($prevalue != $this->dependentsetting->get_visibility()); | ||
} | ||
/** | ||
|
@@ -182,15 +184,16 @@ class setting_dependency_disabledif_equals extends setting_dependency { | |
*/ | ||
public function __construct(base_setting $setting, base_setting $dependentsetting, $value, $defaultvalue = false) { | ||
parent::__construct($setting, $dependentsetting, $defaultvalue); | ||
$this->value = ($value)?(string)$value:0; | ||
$this->value = ($value) ? (string)$value : 0; | ||
} | ||
/** | ||
* Returns true if the dependent setting is locked by this setting_dependency. | ||
* @return bool | ||
*/ | ||
public function is_locked() { | ||
// If the setting is locked or the dependent setting should be locked then return true. | ||
if ($this->setting->get_status() !== base_setting::NOT_LOCKED || $this->evaluate_disabled_condition($this->setting->get_value())) { | ||
if ($this->setting->get_status() !== base_setting::NOT_LOCKED || | ||
$this->evaluate_disabled_condition($this->setting->get_value())) { | ||
return true; | ||
} | ||
// Else the dependent setting is not locked by this setting_dependency. | ||
|
@@ -223,10 +226,10 @@ protected function process_value_change($oldvalue) { | |
$this->dependentsetting->set_value($this->defaultvalue); | ||
} | ||
} else if ($this->dependentsetting->get_status() == base_setting::LOCKED_BY_HIERARCHY) { | ||
// We can unlock the dependent setting | ||
// We can unlock the dependent setting. | ||
$this->dependentsetting->set_status(base_setting::NOT_LOCKED); | ||
} | ||
// Return true if the value has changed for the dependent setting | ||
// Return true if the value has changed for the dependent setting. | ||
return ($prevalue != $this->dependentsetting->get_value()); | ||
} | ||
/** | ||
|
@@ -235,17 +238,18 @@ protected function process_value_change($oldvalue) { | |
* @return bool | ||
*/ | ||
protected function process_status_change($oldstatus) { | ||
// Store the dependent status | ||
// Store the dependent status. | ||
$prevalue = $this->dependentsetting->get_status(); | ||
// Store the current status | ||
// Store the current status. | ||
$currentstatus = $this->setting->get_status(); | ||
if ($currentstatus == base_setting::NOT_LOCKED) { | ||
if ($prevalue == base_setting::LOCKED_BY_HIERARCHY && !$this->evaluate_disabled_condition($this->setting->get_value())) { | ||
if ($prevalue == base_setting::LOCKED_BY_HIERARCHY && | ||
!$this->evaluate_disabled_condition($this->setting->get_value())) { | ||
// Dependency has changes, is not fine, unlock the dependent setting. | ||
$this->dependentsetting->set_status(base_setting::NOT_LOCKED); | ||
} | ||
} else { | ||
// Make sure the dependent setting is also locked, in this case by hierarchy | ||
// Make sure the dependent setting is also locked, in this case by hierarchy. | ||
$this->dependentsetting->set_status(base_setting::LOCKED_BY_HIERARCHY); | ||
} | ||
// Return true if the dependent setting has changed. | ||
|
@@ -256,17 +260,17 @@ protected function process_status_change($oldstatus) { | |
* @return bool True if there were changes | ||
*/ | ||
public function enforce() { | ||
// This will be set to true if ANYTHING changes | ||
// This will be set to true if ANYTHING changes. | ||
$changes = false; | ||
// First process any value changes | ||
// First process any value changes. | ||
if ($this->process_value_change($this->setting->get_value())) { | ||
$changes = true; | ||
} | ||
// Second process any status changes | ||
// Second process any status changes. | ||
if ($this->process_status_change($this->setting->get_status())) { | ||
$changes = true; | ||
} | ||
// Finally process visibility changes | ||
// Finally process visibility changes. | ||
if ($this->process_visibility_change($this->setting->get_visibility())) { | ||
$changes = true; | ||
} | ||
|
@@ -279,10 +283,10 @@ public function enforce() { | |
*/ | ||
public function get_moodleform_properties() { | ||
return array( | ||
'setting'=>$this->dependentsetting->get_ui_name(), | ||
'dependenton'=>$this->setting->get_ui_name(), | ||
'condition'=>'eq', | ||
'value'=>$this->value | ||
'setting' => $this->dependentsetting->get_ui_name(), | ||
'dependenton' => $this->setting->get_ui_name(), | ||
'condition' => 'eq', | ||
'value' => $this->value | ||
); | ||
} | ||
|
||
|
@@ -299,12 +303,12 @@ protected function evaluate_disabled_condition($value) { | |
} | ||
|
||
/** | ||
* A dependency that disables the secondary setting if the primary setting is | ||
* not equal to the provided value | ||
* | ||
* @copyright 2011 Darko Miletic <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
* A dependency that disables the secondary setting if the primary setting is | ||
* not equal to the provided value | ||
* | ||
* @copyright 2011 Darko Miletic <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class setting_dependency_disabledif_not_equals extends setting_dependency_disabledif_equals { | ||
|
||
/** | ||
|
@@ -317,20 +321,23 @@ protected function evaluate_disabled_condition($value) { | |
} | ||
|
||
/** | ||
* Returns an array of properties suitable to be used to define a moodleforms | ||
* disabled command | ||
* @return array | ||
*/ | ||
* Returns an array of properties suitable to be used to define a moodleforms | ||
* disabled command | ||
* @return array | ||
*/ | ||
public function get_moodleform_properties() { | ||
return array( | ||
'setting'=>$this->dependentsetting->get_ui_name(), | ||
'dependenton'=>$this->setting->get_ui_name(), | ||
'condition'=>'notequal', | ||
'value'=>$this->value | ||
'setting' => $this->dependentsetting->get_ui_name(), | ||
'dependenton' => $this->setting->get_ui_name(), | ||
'condition' => 'notequal', | ||
'value' => $this->value | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Disable if a value is in a list. | ||
*/ | ||
class setting_dependency_disabledif_in_array extends setting_dependency_disabledif_equals { | ||
|
||
/** | ||
|
@@ -349,16 +356,17 @@ protected function evaluate_disabled_condition($value) { | |
*/ | ||
public function get_moodleform_properties() { | ||
return array( | ||
'setting'=>$this->dependentsetting->get_ui_name(), | ||
'dependenton'=>$this->setting->get_ui_name(), | ||
'condition'=>'eq', | ||
'value'=>$this->value | ||
'setting' => $this->dependentsetting->get_ui_name(), | ||
'dependenton' => $this->setting->get_ui_name(), | ||
'condition' => 'eq', | ||
'value' => $this->value | ||
); | ||
} | ||
|
||
} | ||
|
||
// This class is here for backwards compatibility (terrible name). | ||
/** | ||
* This class is here for backwards compatibility (terrible name). | ||
*/ | ||
class setting_dependency_disabledif_equals2 extends setting_dependency_disabledif_in_array { | ||
} | ||
|
||
|
@@ -381,9 +389,9 @@ public function __construct(base_setting $setting, base_setting $dependentsettin | |
*/ | ||
public function get_moodleform_properties() { | ||
return array( | ||
'setting'=>$this->dependentsetting->get_ui_name(), | ||
'dependenton'=>$this->setting->get_ui_name(), | ||
'condition'=>'checked' | ||
'setting' => $this->dependentsetting->get_ui_name(), | ||
'dependenton' => $this->setting->get_ui_name(), | ||
'condition' => 'checked' | ||
); | ||
} | ||
} | ||
|
@@ -407,9 +415,9 @@ public function __construct(base_setting $setting, base_setting $dependentsettin | |
*/ | ||
public function get_moodleform_properties() { | ||
return array( | ||
'setting'=>$this->dependentsetting->get_ui_name(), | ||
'dependenton'=>$this->setting->get_ui_name(), | ||
'condition'=>'notchecked' | ||
'setting' => $this->dependentsetting->get_ui_name(), | ||
'dependenton' => $this->setting->get_ui_name(), | ||
'condition' => 'notchecked' | ||
); | ||
} | ||
} | ||
|
@@ -443,10 +451,10 @@ protected function evaluate_disabled_condition($value) { | |
*/ | ||
public function get_moodleform_properties() { | ||
return array( | ||
'setting'=>$this->dependentsetting->get_ui_name(), | ||
'dependenton'=>$this->setting->get_ui_name(), | ||
'condition'=>'notequal', | ||
'value'=>'' | ||
'setting' => $this->dependentsetting->get_ui_name(), | ||
'dependenton' => $this->setting->get_ui_name(), | ||
'condition' => 'notequal', | ||
'value' => '' | ||
); | ||
} | ||
} | ||
|
@@ -480,10 +488,10 @@ protected function evaluate_disabled_condition($value) { | |
*/ | ||
public function get_moodleform_properties() { | ||
return array( | ||
'setting'=>$this->dependentsetting->get_ui_name(), | ||
'dependenton'=>$this->setting->get_ui_name(), | ||
'condition'=>'notequal', | ||
'value'=>'' | ||
'setting' => $this->dependentsetting->get_ui_name(), | ||
'dependenton' => $this->setting->get_ui_name(), | ||
'condition' => 'notequal', | ||
'value' => '' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters