MDL-15833 - provide helper functions to determine expected time, and allow admins to set thresholds.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php //$Id$
|
||||
|
||||
if ($hassiteconfig) {
|
||||
if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext)) {
|
||||
|
||||
$ADMIN->add('modules', new admin_category('modsettings', get_string('activitymodules')));
|
||||
$ADMIN->add('modsettings', new admin_page_managemods());
|
||||
@@ -154,7 +154,33 @@ if ($hassiteconfig) {
|
||||
|
||||
// jump through hoops to do what we want
|
||||
$temp = new admin_settingpage('manageportfolios', get_string('manageportfolios', 'portfolio'));
|
||||
$temp->add(new admin_setting_heading('manageportfolios', get_string('activeportfolios', 'portfolio'), ''));
|
||||
$temp->add(new admin_setting_manageportfolio());
|
||||
$temp->add(new admin_setting_heading('manageportfolioscommon', get_string('commonsettings', 'admin'), get_string('commonsettingsdesc', 'portfolio')));
|
||||
$fileinfo = portfolio_filesize_info(); // make sure this is defined in one place since its used inside portfolio too to detect insane settings
|
||||
$fileoptions = $fileinfo['options'];
|
||||
$temp->add(new admin_setting_configselect(
|
||||
'portfolio_moderate_filesize_threshold',
|
||||
get_string('moderatefilesizethreshold', 'portfolio'),
|
||||
get_string('moderatefilesizethresholddesc', 'portfolio'),
|
||||
$fileinfo['moderate'], $fileoptions));
|
||||
$temp->add(new admin_setting_configselect(
|
||||
'portfolio_high_filesize_threshold',
|
||||
get_string('highfilesizethreshold', 'portfolio'),
|
||||
get_string('highfilesizethresholddesc', 'portfolio'),
|
||||
$fileinfo['high'], $fileoptions));
|
||||
|
||||
$temp->add(new admin_setting_configtext(
|
||||
'portfolio_moderate_db_threshold',
|
||||
get_string('moderatedbsizethreshold', 'portfolio'),
|
||||
get_string('moderatedbsizethresholddesc', 'portfolio'),
|
||||
20, PARAM_INTEGER, 3));
|
||||
|
||||
$temp->add(new admin_setting_configtext(
|
||||
'portfolio_high_db_threshold',
|
||||
get_string('highdbsizethreshold', 'portfolio'),
|
||||
get_string('highdbsizethresholddesc', 'portfolio'),
|
||||
50, PARAM_INTEGER, 3));
|
||||
|
||||
$ADMIN->add('portfoliosettings', $temp);
|
||||
$ADMIN->add('portfoliosettings', new admin_externalpage('portfolionew', get_string('addnewportfolio', 'portfolio'), $url, 'moodle/site:config', true), '', $url);
|
||||
@@ -219,4 +245,21 @@ if ($hassiteconfig) {
|
||||
'moodle/site:config');
|
||||
}
|
||||
}
|
||||
|
||||
// Question type settings.
|
||||
$ADMIN->add('modules', new admin_category('qtypesettings', get_string('questiontypes', 'admin')));
|
||||
$ADMIN->add('qtypesettings', new admin_page_manageqtypes());
|
||||
require_once($CFG->libdir . '/questionlib.php');
|
||||
global $QTYPES;
|
||||
foreach ($QTYPES as $qtype) {
|
||||
$settingsfile = $qtype->plugin_dir() . '/settings.php';
|
||||
if (file_exists($settingsfile)) {
|
||||
$settings = new admin_settingpage('qtypesetting' . $qtype->name(),
|
||||
$qtype->local_name(), 'moodle/question:config');
|
||||
if ($ADMIN->fulltree) {
|
||||
include($settingsfile);
|
||||
}
|
||||
$ADMIN->add('qtypesettings', $settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+37
-2
@@ -4281,6 +4281,42 @@ class admin_page_manageblocks extends admin_externalpage {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Question type manage page
|
||||
*/
|
||||
class admin_page_manageqtypes extends admin_externalpage {
|
||||
function __construct() {
|
||||
global $CFG;
|
||||
parent::__construct('manageqtypes', get_string('manageqtypes', 'admin'), "$CFG->wwwroot/$CFG->admin/qtypes.php");
|
||||
}
|
||||
|
||||
function search($query) {
|
||||
global $CFG;
|
||||
if ($result = parent::search($query)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$found = false;
|
||||
$textlib = textlib_get_instance();
|
||||
require_once($CFG->libdir . '/questionlib.php');
|
||||
global $QTYPES;
|
||||
foreach ($QTYPES as $qtype) {
|
||||
if (strpos($textlib->strtolower($qtype->local_name()), $query) !== false) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($found) {
|
||||
$result = new object();
|
||||
$result->page = $this;
|
||||
$result->settings = array();
|
||||
return array($this->name => $result);
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Special class for authentication administration.
|
||||
*/
|
||||
@@ -4707,7 +4743,7 @@ class admin_setting_manageportfolio extends admin_setting {
|
||||
|
||||
$output .= print_table($table, true);
|
||||
|
||||
$instancehtml = '<br /><br />' . get_string('addnewportfolio', 'portfolio') . ': <br />';
|
||||
$instancehtml = '<br /><br />' . get_string('addnewportfolio', 'portfolio') . ': <br /><br />';
|
||||
$addable = 0;
|
||||
foreach ($plugins as $p) {
|
||||
if (!portfolio_static_function($p, 'allows_multiple') && in_array($p, $alreadyplugins)) {
|
||||
@@ -4731,7 +4767,6 @@ class admin_setting_manageportfolio extends admin_setting {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialise admin page - this function does require login and permission
|
||||
* checks specified in page definition.
|
||||
|
||||
@@ -615,5 +615,92 @@ function portfolio_export_rethrow_exception($exporter, $exception) {
|
||||
throw new portfolio_export_exception($exporter, $exception->errorcode, $exception->module, $exception->link, $exception->a);
|
||||
}
|
||||
|
||||
/**
|
||||
* try and determine expected_time for purely file based exports
|
||||
* or exports that might include large file attachments.
|
||||
*
|
||||
* @param mixed $totest - either an array of stored_file objects or a single stored_file object
|
||||
*
|
||||
* @return constant PORTFOLIO_TIME_XXX
|
||||
*/
|
||||
function portfolio_expected_time_file($totest) {
|
||||
global $CFG;
|
||||
if ($totest instanceof stored_file) {
|
||||
$totest = array($totest);
|
||||
}
|
||||
$size = 0;
|
||||
foreach ($totest as $file) {
|
||||
if (!($file instanceof stored_file)) {
|
||||
debugging('something weird passed to portfolio_expected_time_file - not stored_file object');
|
||||
debugging(print_r($file, true));
|
||||
continue;
|
||||
}
|
||||
$size += $file->get_filesize();
|
||||
}
|
||||
|
||||
$fileinfo = portfolio_filesize_info();
|
||||
|
||||
$moderate = $high = 0; // avoid warnings
|
||||
|
||||
foreach (array('moderate', 'high') as $setting) {
|
||||
$settingname = 'portfolio_' . $setting . '_filesize_threshold';
|
||||
if (empty($CFG->{$settingname}) || !array_key_exists($CFG->{$settingname}, $fileinfo['options'])) {
|
||||
debugging("weird or unset admin value for $settingname, using default instead");
|
||||
$$setting = $fileinfo[$setting];
|
||||
} else {
|
||||
$$setting = $CFG->{$settingname};
|
||||
}
|
||||
}
|
||||
|
||||
if ($size < $moderate) {
|
||||
return PORTFOLIO_TIME_LOW;
|
||||
} else if ($size < $high) {
|
||||
return PORTFOLIO_TIME_MODERATE;
|
||||
}
|
||||
return PORTFOLIO_TIME_HIGH;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* the default filesizes and threshold information for file based transfers
|
||||
* this shouldn't need to be used outside the admin pages and the portfolio code
|
||||
*/
|
||||
function portfolio_filesize_info() {
|
||||
$filesizes = array();
|
||||
$sizelist = array(10240, 51200, 102400, 512000, 1048576, 2097152, 5242880, 10485760, 20971520, 52428800);
|
||||
foreach ($sizelist as $size) {
|
||||
$filesizes[$size] = display_size($size);
|
||||
}
|
||||
return array(
|
||||
'options' => $filesizes,
|
||||
'moderate' => 1048576,
|
||||
'high' => 5242880,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* try and determine expected_time for purely database based exports
|
||||
* or exports that might include large parts of a database
|
||||
*
|
||||
* @param integer $recordcount - number of records trying to export
|
||||
*
|
||||
* @return constant PORTFOLIO_TIME_XXX
|
||||
*/
|
||||
function portfolio_expected_time_db($recordcount) {
|
||||
global $CFG;
|
||||
|
||||
if (empty($CFG->portfolio_moderate_dbsize_threshold)) {
|
||||
set_config('portfolio_moderate_dbsize_threshold', 10);
|
||||
}
|
||||
if (empty($CFG->portfolio_high_dbsize_threshold)) {
|
||||
set_config('portfolio_high_dbsize_threshold', 50);
|
||||
}
|
||||
if ($recordcount < $CFG->portfolio_moderate_dbsize_threshold) {
|
||||
return PORTFOLIO_TIME_LOW;
|
||||
} else if ($recordcount < $CFG->portfolio_high_dbsize_threshold) {
|
||||
return PORTFOLIO_TIME_MODERATE;
|
||||
}
|
||||
return PORTFOLIO_TIME_HIGH;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user