Skip to content
Permalink
Browse files

MDL-48510 inbound: Support disabling of expiration changes in UI

  • Loading branch information...
ankitagarwal authored and danpoltawski committed Dec 25, 2014
1 parent 0a4ce3f commit 017de890cbbc65f5c758edc0f91360a2bb7c9927
@@ -66,15 +66,24 @@ public function definition() {
// Items which can be configured.
$mform->addElement('header', 'configuration', get_string('configuration'));
$options = array(
HOURSECS => get_string('onehour', 'tool_messageinbound'),
DAYSECS => get_string('oneday', 'tool_messageinbound'),
WEEKSECS => get_string('oneweek', 'tool_messageinbound'),
YEARSECS => get_string('oneyear', 'tool_messageinbound'),
0 => get_string('noexpiry', 'tool_messageinbound'),
);
$mform->addElement('select', 'defaultexpiration', get_string('defaultexpiration', 'tool_messageinbound'), $options);
$mform->addHelpButton('defaultexpiration', 'defaultexpiration', 'tool_messageinbound');
if ($handler->can_change_defaultexpiration()) {
// Show option to change expiry only if the handler supports it.
$options = array(
HOURSECS => get_string('onehour', 'tool_messageinbound'),
DAYSECS => get_string('oneday', 'tool_messageinbound'),
WEEKSECS => get_string('oneweek', 'tool_messageinbound'),
YEARSECS => get_string('oneyear', 'tool_messageinbound'),
0 => get_string('noexpiry', 'tool_messageinbound'),
);
$mform->addElement('select', 'defaultexpiration', get_string('defaultexpiration', 'tool_messageinbound'), $options);
$mform->addHelpButton('defaultexpiration', 'defaultexpiration', 'tool_messageinbound');
} else {
$text = $this->get_defaultexpiration_text($handler);
$mform->addElement('static', 'defaultexpiration_fake', get_string('defaultexpiration', 'tool_messageinbound'), $text);
$mform->addElement('hidden', 'defaultexpiration');
$mform->addHelpButton('defaultexpiration_fake', 'defaultexpiration', 'tool_messageinbound');
$mform->setType('defaultexpiration', PARAM_INT);
}
if ($handler->can_change_validateaddress()) {
$mform->addElement('checkbox', 'validateaddress', get_string('requirevalidation', 'tool_messageinbound'));
@@ -107,4 +116,28 @@ public function definition() {
$this->add_action_buttons(true, get_string('savechanges'));
}
/**
* Return a text string representing the selected default expiration for the handler.
*
* @param \core\message\inbound\handler $handler handler instance.
*
* @return string localised text string.
*/
protected function get_defaultexpiration_text(\core\message\inbound\handler $handler) {
switch($handler->defaultexpiration) {
case HOURSECS :
return get_string('onehour', 'tool_messageinbound');
case DAYSECS :
return get_string('oneday', 'tool_messageinbound');
case WEEKSECS :
return get_string('oneweek', 'tool_messageinbound');
case YEARSECS :
return get_string('oneyear', 'tool_messageinbound');
case 0:
return get_string('noexpiry', 'tool_messageinbound');
default:
return ''; // Should never happen.
}
}
}
@@ -58,8 +58,11 @@
if ($mform->is_cancelled()) {
redirect($PAGE->url);
} else if ($data = $mform->get_data()) {
// Update the record from the form.
$record->defaultexpiration = (int) $data->defaultexpiration;
if ($handler->can_change_defaultexpiration()) {
$record->defaultexpiration = (int) $data->defaultexpiration;
}
if ($handler->can_change_validateaddress()) {
$record->validateaddress = !empty($data->validateaddress);
@@ -140,6 +140,18 @@ public function set_validateaddress($validateaddress) {
return $this->validateaddress = $validateaddress;
}
/**
* Whether the current handler allows changes to expiry of the generated email address.
*
* By default this will return true, but for some handlers it may be
* necessary to disallow such changes.
*
* @return boolean
*/
public function can_change_defaultexpiration() {
return true;
}
/**
* Whether this handler can be disabled (or enabled).
*
@@ -35,6 +35,15 @@
*/
class private_files_handler extends handler {
/**
* Email generated by this handler should not expire.
*
* @return bool
*/
public function can_change_defaultexpiration() {
return false;
}
/**
* Return a description for the current handler.
*

0 comments on commit 017de89

Please sign in to comment.
You can’t perform that action at this time.