MDL-15402: when an instance is reaonly, the administrator cannot delete it but should be able to modify the name (only)

This commit is contained in:
jerome 2008-09-19 06:43:06 +00:00
parent ce2066a1c2
commit 1e97f196a4
2 changed files with 33 additions and 25 deletions

View File

@ -43,10 +43,6 @@ $return = true;
if (!empty($edit) || !empty($new)) {
if (!empty($edit)) {
$instance = repository_get_instance($edit);
//if you try to edit an instance set as readonly, display an error message
if ($instance->readonly) {
throw new repository_exception('readonlyinstance', 'repository');
}
$instancetype = repository_get_type_by_id($instance->typeid);
$classname = 'repository_' . $instancetype->get_typename();
$configs = $instance->get_instance_option_names();
@ -72,8 +68,10 @@ if (!empty($edit) || !empty($new)) {
if ($edit) {
$settings = array();
$settings['name'] = $fromform->name;
foreach($configs as $config) {
$settings[$config] = $fromform->$config;
if (!$instance->readonly) {
foreach($configs as $config) {
$settings[$config] = $fromform->$config;
}
}
$success = $instance->set_option($settings);
} else {

View File

@ -1248,26 +1248,36 @@ final class repository_instance_form extends moodleform {
$mform->addElement('text', 'name', get_string('name'), 'maxlength="100" size="30"');
$mform->addRule('name', $strrequired, 'required', null, 'client');
//add fields
if (!$this->instance) {
$result = repository_static_function($this->plugin, 'instance_config_form', $mform);
} else {
$result = $this->instance->instance_config_form($mform);
}
// and set the data if we have some.
if ($this->instance) {
$data = array();
$data['name'] = $this->instance->name;
foreach ($this->instance->get_instance_option_names() as $config) {
if (!empty($this->instance->$config)) {
$data[$config] = $this->instance->$config;
} else {
$data[$config] = '';
}
if (!$this->instance->readonly) {
//add fields
if (!$this->instance) {
$result = repository_static_function($this->plugin, 'instance_config_form', $mform);
} else {
$result = $this->instance->instance_config_form($mform);
}
// and set the data if we have some.
if ($this->instance) {
$data = array();
$data['name'] = $this->instance->name;
foreach ($this->instance->get_instance_option_names() as $config) {
if (!empty($this->instance->$config)) {
$data[$config] = $this->instance->$config;
} else {
$data[$config] = '';
}
}
$this->set_data($data);
}
$this->set_data($data);
}
else {
if ($this->instance) {
$data = array();
$data['name'] = $this->instance->name;
$this->set_data($data);
}
}
$this->add_action_buttons(true, get_string('save','repository'));
}
@ -1396,8 +1406,8 @@ function repository_display_instances_list($context, $typename = null) {
foreach ($instances as $i) {
$settings = '';
$delete = '';
$settings .= '<a href="' . $baseurl . '&amp;type='.$typename.'&amp;edit=' . $i->id . '">' . $settingsstr . '</a>' . "\n";
if (!$i->readonly) {
$settings .= '<a href="' . $baseurl . '&amp;type='.$typename.'&amp;edit=' . $i->id . '">' . $settingsstr . '</a>' . "\n";
$delete .= '<a href="' . $baseurl . '&amp;type='.$typename.'&amp;delete=' . $i->id . '">' . $deletestr . '</a>' . "\n";
}