Added callback capability on course settings update for all plugins - refs #4796

skala
Yannick Warnier 14 years ago
parent e3282dccaa
commit 1794b211da
  1. 13
      main/inc/lib/plugin.class.php
  2. 45
      main/inc/lib/plugin.lib.php

@ -38,6 +38,11 @@ class Plugin {
);
*/
public $course_settings = array();
/**
* This indicates whether changing the setting should execute the callback
* function.
*/
public $course_settings_callback = false;
/**
* Default constructor for the plugin class. By default, it only sets
@ -360,4 +365,12 @@ class Plugin {
$this->uninstall_course_fields($row['id']);
}
}
/**
* Method to be extended when changing the setting in the course
* configuration should trigger the use of a callback method
* @param array Values sent back from the course configuration script
* @return void
*/
private function course_settings_updated($values = array()) {
}
}

@ -361,4 +361,47 @@ class AppPlugin {
}
}
}
}
/**
* When saving the plugin values in the course settings, check whether
* a callback method should be called and send it the updated settings
* @param array The new settings the user just saved
* @return void
*/
function save_course_settings($values) {
$plugin_list = $this->get_installed_plugins();
foreach ($plugin_list as $plugin_name) {
$settings = $this->get_plugin_course_settings($plugin_name);
$subvalues = array();
$i = 0;
foreach ($settings as $v) {
if (isset($values[$v])) {
$subvalues[$v] = $values[$v];
$i++;
}
}
if ($i>0) {
$plugin_info = $this->get_plugin_info($plugin_name);
$obj = $plugin_info['plugin_class']::create();
$obj->course_settings_updated($subvalues);
}
}
}
/**
* Gets a nice array of keys for just the plugin's course settings
* @param string The plugin ID
* @return array Nice array of keys for course settings
*/
public function get_plugin_course_settings($plugin_name) {
$settings = array();
if (empty($plugin_name)) { return $settings; }
$plugin_info = $this->get_plugin_info($plugin_name);
$obj = $plugin_info['plugin_class']::create();
if (is_array($obj->course_settings)) {
foreach ($obj->course_settings as $item) {
$settings[] = $item['name'];
}
}
unset($obj); unset($plugin_info);
return $settings;
}
}

Loading…
Cancel
Save