Commit 5922a558 authored by Valerii Kuznetsov's avatar Valerii Kuznetsov

Change to mahara required by chat module (Bug #547932)

Change-Id: I5558449a0d5c4911bfaec166d185ebd1da863f1c
Signed-off-by: default avatarValerii Kuznetsov <valerii.kuznetsov@totaralms.com>
parent 7d1f73b8
......@@ -100,6 +100,9 @@ $elements['accountoptionsdesc'] = array(
// Add general account options
$elements = array_merge($elements, general_account_prefs_form_elements($prefs));
// Add plugins account options.
$elements = array_merge($elements, plugin_account_prefs_form_elements($prefs));
$blogcount = count_records('artefact', 'artefacttype', 'blog', 'owner', $USER->get('id')) ;
if ($blogcount != 1 && $prefs->multipleblogs == 1) {
$elements['multipleblogs']['readonly'] = true;
......@@ -173,6 +176,8 @@ function accountprefs_validate(Pieform $form, $values) {
}
}
}
plugin_account_prefs_validate($form, $values);
}
function accountprefs_submit(Pieform $form, $values) {
......@@ -228,6 +233,7 @@ function accountprefs_submit(Pieform $form, $values) {
$returndata['username'] = $values['username'];
}
$reload = false;
if (get_config('cleanurls') && isset($values['urlid']) && $values['urlid'] != $USER->get('urlid')) {
$USER->urlid = $values['urlid'];
$USER->commit();
......@@ -251,6 +257,8 @@ function accountprefs_submit(Pieform $form, $values) {
$reload = true;
}
$reload = plugin_account_prefs_submit($form, $values) || $reload;
if (!empty($reload)) {
// Use PIEFORM_CANCEL here to force a page reload and show the new language.
$returndata['location'] = get_config('wwwroot') . 'account/index.php';
......
......@@ -541,6 +541,29 @@ if ($institution || $add) {
. '</th></tr>'
);
// Check for active plugins institution settings.
$elements['pluginsfields'] = array(
'type' => 'fieldset',
'legend' => get_string('pluginsfields', 'admin'),
'collapsible' => true,
'collapsed' => true,
'elements' => array(),
);
// Get plugins institution settings.
$instobj = null;
if (!$add && $institution != '') {
$instobj = new Institution();
$instobj->findByName($institution);
}
$elements['pluginsfields']['elements'] = array_merge($elements['pluginsfields']['elements'],
plugin_institution_prefs_form_elements($instobj));
// Remove plugin fieldset if no fields.
if (empty($elements['pluginsfields']['elements'])) {
unset($elements['pluginsfields']);
}
$elements['submit'] = array(
'type' => 'submitcancel',
'value' => array(get_string('submit'), get_string('cancel'))
......@@ -654,6 +677,9 @@ function institution_validate(Pieform $form, $values) {
if (!empty($values['lang']) && $values['lang'] != 'sitedefault' && !array_key_exists($values['lang'], get_languages())) {
$form->set_error('lang', get_string('institutionlanginvalid', 'admin'));
}
// Validate plugins settings.
plugin_institution_prefs_validate($form, $values);
}
function institution_submit(Pieform $form, $values) {
......@@ -802,6 +828,9 @@ function institution_submit(Pieform $form, $values) {
}
}
// Store plugin settings.
plugin_institution_prefs_submit($form, $values, $newinstitution);
// Save the changes to the DB
$newinstitution->commit();
......
......@@ -771,6 +771,11 @@ function auth_check_required_fields() {
$changepassword = false;
}
// Do not force password change on JSON request.
if (defined('JSON') && JSON == true) {
$changepassword = false;
}
if ($changepassword) {
$authobj = AuthFactory::create($USER->authinstance);
......
......@@ -398,6 +398,16 @@ else {
$SESSION->set('tablet', false);
}
// Run modules bootstrap code.
if (get_config('installed')) {
if ($plugins = plugins_installed('module')) {
foreach ($plugins as &$plugin) {
if (safe_require_plugin('module', $plugin->name)) {
call_static_method(generate_class_name('module', $plugin->name), 'bootstrap');
}
}
}
}
/*
* Initializes our performance info early.
*
......
......@@ -132,6 +132,7 @@ $string['institutionviews'] = 'Institution pages';
$string['institutionviewsdescription'] = 'Create and administer pages and page templates for an institution';
$string['institutionfiles'] = 'Institution files';
$string['institutionfilesdescription'] = 'Upload and manage files for use in institution pages';
$string['pluginsfields'] = 'Plugins settings';
$string['pluginadmin'] = 'Plugin administration';
$string['pluginadmindescription'] = 'Install and configure plugins';
......
......@@ -156,7 +156,7 @@ class Institution {
// A NULL here means you should drop the config from the DB
$existingvalue = array_key_exists($name, $this->configs) ? $this->configs[$name] : NULL;
if ($value != $existingvalue) {
if ($value !== $existingvalue) {
$this->configs[$name] = $value;
$this->dirtyconfigs[$name] = true;
}
......@@ -985,3 +985,58 @@ function institution_display_name($name) {
function extract_institution_user_id($input) {
return $input->id;
}
/**
* Get institution settings elements from artefact plugins.
*
* @param Institution $institution
* @return array
*/
function plugin_institution_prefs_form_elements(Institution $institution = null) {
$elements = array();
$installed = plugin_all_installed();
foreach ($installed as $i) {
if (!safe_require_plugin($i->plugintype, $i->name)) {
continue;
}
$elements = array_merge($elements, call_static_method(generate_class_name($i->plugintype, $i->name),
'get_institutionprefs_elements', $institution));
}
return $elements;
}
/**
* Validate plugin institution form values.
*
* @param Pieform $form
* @param array $values
*/
function plugin_institution_prefs_validate(Pieform $form, $values) {
$elements = array();
$installed = plugin_all_installed();
foreach ($installed as $i) {
if (!safe_require_plugin($i->plugintype, $i->name)) {
continue;
}
call_static_method(generate_class_name($i->plugintype, $i->name), 'institutionprefs_validate', $form, $values);
}
}
/**
* Submit plugin institution form values.
*
* @param Pieform $form
* @param array $values
* @param Institution $institution
* @return bool is page need to be refreshed
*/
function plugin_institution_prefs_submit(Pieform $form, $values, Institution $institution) {
$elements = array();
$installed = plugin_all_installed();
foreach ($installed as $i) {
if (!safe_require_plugin($i->plugintype, $i->name)) {
continue;
}
call_static_method(generate_class_name($i->plugintype, $i->name), 'institutionprefs_submit', $form, $values, $institution);
}
}
......@@ -1520,10 +1520,11 @@ function plugin_types_installed() {
}
/**
* This return returns the names of plugins installed
* This returns the names of plugins installed
* for the given plugin type.
*
* @param string $plugintype type of plugin
* @param bool $all - return all (true) or only active (false) plugins
* @return array of objects with fields (version (int), release (str), active (bool), name (str))
*/
function plugins_installed($plugintype, $all=false) {
......@@ -1551,6 +1552,27 @@ function plugins_installed($plugintype, $all=false) {
return $records[$plugintype][$all];
}
/**
* This returns the names of plugins installed
* for all plugin types.
*
* @param bool $all - return all (true) or only active (false) plugins
* @return array of objects with fields (version (int), release (str), active (bool), name (str))
*/
function plugin_all_installed($all=false) {
$plugintypes = plugin_types_installed();
$result = array();
foreach ($plugintypes as $plugintype) {
$plugins = plugins_installed($plugintype, $all);
foreach ($plugins as $plugin) {
$plugin->plugintype = $plugintype;
$result[] = $plugin;
}
}
return $result;
}
/**
* Helper to call a static method when you do not know the name of the class
* you want to call the method on. PHP5 does not support $class::method().
......@@ -1888,6 +1910,62 @@ abstract class Plugin {
public static function get_theme_path($pluginname) {
return static::get_plugintype_name() . '/' . $pluginname;
}
/**
* Get institution preference page settings for current artefact.
* @param Institution $institution
* @return array of form elements
*/
public static function get_institutionprefs_elements(Institution $institution = null) {
return array();
}
/**
* Validate institution settings values.
* @param Pieform $form
* @param array $values
*/
public static function institutionprefs_validate(Pieform $form, $values) {
return;
}
/**
* Submit institution settings values.
* @param Pieform $form
* @param array $values
* @param Institution $institution
*/
public static function institutionprefs_submit(Pieform $form, $values, Institution $institution) {
return;
}
/**
* Get user preference page settings for current artefact.
* @param stdClass $prefs Saved preferences
* @return array of form elements
*/
public static function get_accountprefs_elements(stdClass $prefs) {
return array();
}
/**
* Validate account settings values.
* @param Pieform $form
* @param array $values
*/
public static function accountprefs_validate(Pieform $form, $values) {
return;
}
/**
* Submit account settings values.
* @param Pieform $form
* @param array $values
*/
public static function accountprefs_submit(Pieform $form, $values) {
return;
}
}
/**
......
......@@ -414,6 +414,62 @@ function general_account_prefs_form_elements($prefs) {
return $elements;
}
/**
* Get account settings elements from plugins.
*
* @param stdClass $prefs
* @return array
*/
function plugin_account_prefs_form_elements(stdClass $prefs) {
$elements = array();
$installed = plugin_all_installed();
foreach ($installed as $i) {
if (!safe_require_plugin($i->plugintype, $i->name)) {
continue;
}
$elements = array_merge($elements, call_static_method(generate_class_name($i->plugintype, $i->name),
'get_accountprefs_elements', $prefs));
}
return $elements;
}
/**
* Validate plugin account form values.
*
* @param Pieform $form
* @param array $values
*/
function plugin_account_prefs_validate(Pieform $form, $values) {
$elements = array();
$installed = plugin_all_installed();
foreach ($installed as $i) {
if (!safe_require_plugin($i->plugintype, $i->name)) {
continue;
}
call_static_method(generate_class_name($i->plugintype, $i->name), 'accountprefs_validate', $form, $values);
}
}
/**
* Submit plugin account form values.
*
* @param Pieform $form
* @param array $values
* @return bool is page need to be refreshed
*/
function plugin_account_prefs_submit(Pieform $form, $values) {
$reload = false;
$elements = array();
$installed = plugin_all_installed();
foreach ($installed as $i) {
if (!safe_require_plugin($i->plugintype, $i->name)) {
continue;
}
$reload = call_static_method(generate_class_name($i->plugintype, $i->name), 'accountprefs_submit', $form, $values) || $reload;
}
return $reload;
}
function set_profile_field($userid, $field, $value) {
safe_require('artefact', 'internal');
......
......@@ -2685,22 +2685,15 @@ function right_nav() {
);
// enable plugins to augment the menu structure
if ($plugins = plugins_installed('artefact')) {
foreach ($plugins as &$plugin) {
safe_require('artefact', $plugin->name);
$plugin_menu = call_static_method(generate_class_name('artefact',$plugin->name), 'menu_items');
$menu = array_merge($menu, $plugin_menu);
}
}
if ($plugins = plugins_installed('interaction')) {
foreach ($plugins as &$plugin) {
safe_require('interaction', $plugin->name);
$plugin_menu = call_static_method(generate_class_name('interaction',$plugin->name), 'menu_items');
$menu = array_merge($menu, $plugin_menu);
foreach (array('artefact', 'interaction', 'module') as $plugintype) {
if ($plugins = plugins_installed($plugintype)) {
foreach ($plugins as &$plugin) {
safe_require($plugintype, $plugin->name);
$plugin_menu = call_static_method(generate_class_name($plugintype,$plugin->name), 'menu_items');
$menu = array_merge($menu, $plugin_menu);
}
}
}
// local_right_nav_update allows sites to customise the menu by munging the $menu array.
if (function_exists('local_right_nav_update')) {
local_right_nav_update($menu);
......
......@@ -18,4 +18,10 @@ abstract class PluginModule extends Plugin {
public static function get_plugintype_name() {
return 'module';
}
/**
* Run initialisation code
*/
public static function bootstrap() {
}
}
......@@ -4,7 +4,11 @@
{if $LOGGEDIN} <li class="identity"><a href="{profile_url($USER)}">{$USER|display_default_name}</a></li>{/if}
{if $RIGHTNAV}
{foreach from=$RIGHTNAV item=item}
<li class="{$item.path}{if $item.selected}{assign var=MAINNAVSELECTED value=$item} selected{/if} bar-before"><a href="{if $item.wwwroot}{$item.wwwroot}{else}{$WWWROOT}{/if}{$item.url}">{if $item.title}{$item.title}{/if}{if $item.icon}<img src="{$item.icon}" alt="{$item.alt}">{if isset($item.count)}<span class="navcount{if $item.countclass} {$item.countclass}{/if}">{$item.count}</span>{/if}</a></li>
<li class="{$item.path}{if $item.selected}{assign var=MAINNAVSELECTED value=$item} selected{/if}{if $item.class} {$item.class}{/if} bar-before">
<a {if $item.accesskey}accesskey="{$item.accesskey}" {/if}{if $item.aria}{foreach $item.aria key=key item=value}aria-{$key}="{$value}" {/foreach}{/if}href="{if $item.wwwroot}{$item.wwwroot}{else}{$WWWROOT}{/if}{$item.url}">
{if $item.title}{$item.title}{/if}{if $item.icon}<img src="{$item.icon}" alt="{$item.alt}">{if isset($item.count)}<span class="navcount{if $item.countclass} {$item.countclass}{/if}">{$item.count}</span>{/if}
</a>
</li>
{/foreach}
<li class="btn-logout bar-before"><a href="{$WWWROOT}?logout" accesskey="l">{str tag="logout"}</a></li>
{/if}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment