Skip to content

Commit

Permalink
Merge branch 'MDL-37459-master-fix2' of git://github.com/damyon/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Jun 12, 2013
2 parents bdce4a9 + c303711 commit 128e931
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 24 deletions.
90 changes: 67 additions & 23 deletions course/moodleform_mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ abstract class moodleform_mod extends moodleform {
/** a flag indicating whether outcomes are being used*/
protected $_outcomesused;

/**
* @var bool A flag used to indicate that this module should lock settings
* based on admin settings flags in definition_after_data.
*/
protected $applyadminlockedflags = false;

function moodleform_mod($current, $section, $cm, $course) {
$this->current = $current;
$this->_instance = $current->instance;
Expand Down Expand Up @@ -278,6 +284,9 @@ function definition_after_data() {
}
}
}

// Freeze admin defaults if required (and not different from default)
$this->apply_admin_locked_flags();
}

// form verification
Expand Down Expand Up @@ -866,54 +875,89 @@ function add_action_buttons($cancel=true, $submitlabel=null, $submit2label=null)
}

/**
* Get the list of admin settings for this module and apply any defaults/advanced/locked settings.
* Get the list of admin settings for this module and apply any locked settings.
* This cannot happen in apply_admin_defaults because we do not the current values of the settings
* in that function because set_data has not been called yet.
*
* @param $datetimeoffsets array - If passed, this is an array of fieldnames => times that the
* default date/time value should be relative to. If not passed, all
* date/time fields are set relative to the users current midnight.
* @return void
*/
function apply_admin_defaults($datetimeoffsets = array()) {
protected function apply_admin_locked_flags() {
global $OUTPUT;

if (!$this->applyadminlockedflags) {
return;
}

$settings = get_config($this->_modname);
$mform = $this->_form;
$lockedicon = html_writer::tag('span',
$OUTPUT->pix_icon('t/locked', get_string('locked', 'admin')),
array('class' => 'action-icon'));

foreach ($settings as $name => $value) {
if (strpos('_', $name) !== false) {
continue;
}
if ($mform->elementExists($name)) {
$element = $mform->getElement($name);
$lockedsetting = $name . '_locked';
if (!empty($settings->$lockedsetting)) {
$value = $mform->getElement($name)->getValue();
$value = reset($value);
if ($value == $settings->$name) {
$mform->setConstant($name, $settings->$name);
$element->setLabel($element->getLabel() . $lockedicon);
// Do not use hardfreeze because we need the hidden input to check dependencies.
$element->freeze();
}
}
}
}
}

/**
* Get the list of admin settings for this module and apply any defaults/advanced/locked settings.
*
* @param $datetimeoffsets array - If passed, this is an array of fieldnames => times that the
* default date/time value should be relative to. If not passed, all
* date/time fields are set relative to the users current midnight.
* @return void
*/
public function apply_admin_defaults($datetimeoffsets = array()) {
// This flag triggers the settings to be locked in apply_admin_locked_flags().
$this->applyadminlockedflags = true;

$settings = get_config($this->_modname);
$mform = $this->_form;
$usermidnight = usergetmidnight(time());
$isupdate = !empty($this->_cm);

foreach ($settings as $name => $value) {
if (strpos('_', $name) !== false) {
continue;
}
if ($mform->elementExists($name)) {
$element = $mform->getElement($name);
if ($element->getType() == 'date_time_selector') {
$enabledsetting = $name . '_enabled';
if (empty($settings->$enabledsetting)) {
$mform->setDefault($name, 0);
} else {
$relativetime = $usermidnight;
if (isset($datetimeoffsets[$name])) {
$relativetime = $datetimeoffsets[$name];
if (!$isupdate) {
if ($element->getType() == 'date_time_selector') {
$enabledsetting = $name . '_enabled';
if (empty($settings->$enabledsetting)) {
$mform->setDefault($name, 0);
} else {
$relativetime = $usermidnight;
if (isset($datetimeoffsets[$name])) {
$relativetime = $datetimeoffsets[$name];
}
$mform->setDefault($name, $relativetime + $settings->$name);
}
$mform->setDefault($name, $relativetime + $settings->$name);
} else {
$mform->setDefault($name, $settings->$name);
}
} else {
$mform->setDefault($name, $settings->$name);
}
$advancedsetting = $name . '_adv';
if (!empty($settings->$advancedsetting)) {
$mform->setAdvanced($name);
}
$lockedsetting = $name . '_locked';
if (!empty($settings->$lockedsetting)) {
$mform->setConstant($name, $settings->$name);
$element->setLabel($element->getLabel() . $lockedicon);
// Do not use hardfreeze because we need the hidden input to check dependencies.
$element->freeze();
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,9 @@ public function output_setting_flags() {
}
}

if (!empty($output)) {
return html_writer::tag('span', $output, array('class' => 'adminsettingsflags'));
}
return $output;
}

Expand Down
6 changes: 6 additions & 0 deletions theme/base/style/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@
.admin_colourpicker .previewcolour {border:1px solid #000;margin-left:301px;}
.admin_colourpicker .currentcolour {border:1px solid #000;margin-left:301px;border-top-width:0;}

/* Styles for flags on admin settings */
.adminsettingsflags { float: right; }
.dir-rtl .adminsettingsflags { float: left; }
.adminsettingsflags label { margin-right: 7px; }
.dir-rtl .adminsettingsflags label { margin-left: 7px; }

/** Overide for RTL layout **/
.dir-rtl #adminsettings .form-item .form-setting,
.dir-rtl #adminsettings .form-item .form-label,
Expand Down
25 changes: 25 additions & 0 deletions theme/bootstrapbase/less/moodle/admin.less
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,31 @@ img.iconsmall {
direction: ltr;
}

/* Styles for flags on admin settings */
.adminsettingsflags {
float: right;
}

.dir-rtl .adminsettingsflags {
float: left;
}

.adminsettingsflags label {
margin-right: 7px;
}

.dir-rtl .adminsettingsflags label {
margin-left: 7px;
}

.form-description {
clear: right;
}

.dir-rtl .form-description {
clear: left;
}

.form-item .form-setting .form-htmlarea {
width: 640px;
display: inline;
Expand Down
2 changes: 1 addition & 1 deletion theme/bootstrapbase/style/moodle.css

Large diffs are not rendered by default.

0 comments on commit 128e931

Please sign in to comment.