Commit 22fbfe3c authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Don't query a blocktype's artefact plugin multiple times


Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent f3590035
......@@ -14,7 +14,7 @@ class Dwoo_Template_Mahara_Blocktype extends Dwoo_Template_Mahara
global $THEME;
if (!isset(self::$_filePaths[$name[0]][$name[1]])) {
$artefactplugin = get_field('blocktype_installed', 'artefactplugin', 'name', $name[0]);
$artefactplugin = blocktype_artefactplugin($name[0]);
$template_path = $name[1];
$basedir = get_config('docroot');
......
......@@ -1057,7 +1057,7 @@ function safe_require($plugintype, $pluginname, $filename='lib.php', $function='
}
else {
try {
if ($artefactplugin = get_field('blocktype_installed', 'artefactplugin', 'name', $pluginname)) {
if ($artefactplugin = blocktype_artefactplugin($pluginname)) {
$fullpath = get_config('docroot') . 'artefact/' . $artefactplugin . '/blocktype/' . $pluginname . '/'. $filename;
}
}
......@@ -1139,14 +1139,21 @@ function plugin_types_installed() {
* @param string $plugintype type of plugin
*/
function plugins_installed($plugintype, $all=false) {
$sort = 'name';
if ($plugintype == 'blocktype') {
$sort = 'artefactplugin,name';
}
if ($all) {
return get_records_array($plugintype . '_installed', '', '', $sort);
static $records = array();
if (defined('INSTALLER') || !isset($records[$plugintype][true])) {
$sort = $plugintype == 'blocktype' ? 'artefactplugin,name' : 'name';
$records[$plugintype][true] = get_records_assoc($plugintype . '_installed', '', '', $sort);
foreach ($records[$plugintype][true] as $r) {
if ($r->active) {
$records[$plugintype][false][$r->name] = $r;
}
}
}
return get_records_array($plugintype . '_installed', 'active', 1, $sort);
return $records[$plugintype][$all];
}
/**
......@@ -1214,6 +1221,15 @@ function blocktype_name_to_namespaced($blocktype) {
return $resultcache[$blocktype];
}
/* Get the name of the artefact plugin that provides a given blocktype */
function blocktype_artefactplugin($blocktype) {
$installed = plugins_installed('blocktype');
if (isset($installed[$blocktype])) {
return $installed[$blocktype]->artefactplugin;
}
return false;
}
/**
* Fires an event which can be handled by different parts of the system
......
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